@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/dist/agent/builtin-commands.d.ts +19 -0
  2. package/dist/agent/builtin-commands.js +80 -0
  3. package/dist/agent/channel-runner.d.ts +20 -208
  4. package/dist/agent/channel-runner.js +167 -1188
  5. package/dist/agent/maintenance-context.d.ts +1 -1
  6. package/dist/agent/maintenance-context.js +1 -1
  7. package/dist/agent/prompt/manifest.d.ts +6 -1
  8. package/dist/agent/prompt/manifest.js +45 -64
  9. package/dist/agent/prompt/resources.d.ts +3 -0
  10. package/dist/agent/prompt/resources.js +11 -2
  11. package/dist/agent/runner-factory.d.ts +1 -43
  12. package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
  13. package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
  14. package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
  15. package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
  16. package/dist/agent/session/model-selection.d.ts +47 -0
  17. package/dist/agent/session/model-selection.js +99 -0
  18. package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
  19. package/dist/agent/session/session-adapter.js +159 -0
  20. package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
  21. package/dist/agent/{session-events.js → session/session-events.js} +24 -13
  22. package/dist/agent/session/session-host.d.ts +200 -0
  23. package/dist/agent/session/session-host.js +621 -0
  24. package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
  25. package/dist/agent/status-render.d.ts +0 -1
  26. package/dist/agent/status-render.js +4 -16
  27. package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
  28. package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
  29. package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
  30. package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
  31. package/dist/{memory → agent/turn}/task-digest.js +4 -4
  32. package/dist/agent/turn/turn-context.d.ts +14 -0
  33. package/dist/agent/turn/turn-context.js +64 -0
  34. package/dist/agent/turn/turn-error.d.ts +31 -0
  35. package/dist/agent/turn/turn-error.js +68 -0
  36. package/dist/agent/turn/turn-finish.d.ts +50 -0
  37. package/dist/agent/turn/turn-finish.js +188 -0
  38. package/dist/agent/turn/turn-input.d.ts +43 -0
  39. package/dist/agent/turn/turn-input.js +79 -0
  40. package/dist/agent/turn/turn-pipeline.d.ts +68 -0
  41. package/dist/agent/turn/turn-pipeline.js +257 -0
  42. package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
  43. package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
  44. package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
  45. package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
  46. package/dist/agent/types.d.ts +43 -2
  47. package/dist/agent/types.js +1 -1
  48. package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
  49. package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
  50. package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
  51. package/dist/{runtime/app-home.js → app/home.js} +22 -75
  52. package/dist/{runtime → app}/proxy.js +4 -2
  53. package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
  54. package/dist/{app-services.js → app/services.js} +17 -14
  55. package/dist/channel/channel-context.d.ts +12 -2
  56. package/dist/channel/channel-context.js +29 -2
  57. package/dist/channel/channel-event.d.ts +10 -2
  58. package/dist/channel/channel-event.js +1 -1
  59. package/dist/channel/channel-index.js +4 -1
  60. package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
  61. package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
  62. package/dist/channel/project-scope-store.js +1 -1
  63. package/dist/channel/store.js +4 -0
  64. package/dist/commands/catalog.d.ts +24 -7
  65. package/dist/commands/catalog.js +91 -44
  66. package/dist/commands/reply-limits.d.ts +6 -0
  67. package/dist/commands/reply-limits.js +24 -0
  68. package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
  69. package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
  70. package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
  71. package/dist/{settings.js → config/settings.js} +11 -11
  72. package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
  73. package/dist/{tools/config.js → config/tools.js} +5 -2
  74. package/dist/dingtalk/access-token.d.ts +12 -0
  75. package/dist/dingtalk/access-token.js +51 -0
  76. package/dist/dingtalk/api.d.ts +19 -0
  77. package/dist/dingtalk/api.js +67 -0
  78. package/dist/dingtalk/bot.d.ts +97 -0
  79. package/dist/dingtalk/bot.js +389 -0
  80. package/dist/dingtalk/cards.d.ts +56 -0
  81. package/dist/dingtalk/cards.js +318 -0
  82. package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
  83. package/dist/dingtalk/config.d.ts +19 -0
  84. package/dist/dingtalk/config.js +95 -0
  85. package/dist/dingtalk/connection.d.ts +57 -0
  86. package/dist/dingtalk/connection.js +356 -0
  87. package/dist/dingtalk/conversation-meta.d.ts +16 -0
  88. package/dist/dingtalk/conversation-meta.js +77 -0
  89. package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
  90. package/dist/{runtime → dingtalk}/delivery.js +29 -15
  91. package/dist/dingtalk/handler.d.ts +90 -0
  92. package/dist/dingtalk/handler.js +1 -0
  93. package/dist/dingtalk/inbound.d.ts +66 -0
  94. package/dist/dingtalk/inbound.js +137 -0
  95. package/dist/dingtalk/media.d.ts +66 -0
  96. package/dist/dingtalk/media.js +214 -0
  97. package/dist/events/{event-commands.js → commands.js} +99 -45
  98. package/dist/events/parse.d.ts +14 -0
  99. package/dist/events/parse.js +114 -0
  100. package/dist/events/types.d.ts +93 -0
  101. package/dist/events/types.js +1 -0
  102. package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
  103. package/dist/events/{event-validation.js → validation.js} +17 -9
  104. package/dist/events/watcher.d.ts +67 -0
  105. package/dist/events/{events.js → watcher.js} +63 -121
  106. package/dist/executor.js +2 -2
  107. package/dist/index.d.ts +6 -4
  108. package/dist/index.js +2 -2
  109. package/dist/jobs/launch.d.ts +42 -0
  110. package/dist/jobs/launch.js +118 -0
  111. package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
  112. package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
  113. package/dist/jobs/record.d.ts +55 -0
  114. package/dist/jobs/record.js +36 -0
  115. package/dist/log.d.ts +12 -2
  116. package/dist/log.js +26 -34
  117. package/dist/main.js +3 -3
  118. package/dist/memory/commands.js +29 -23
  119. package/dist/memory/lifecycle.js +26 -5
  120. package/dist/memory/maintenance-gates.d.ts +2 -2
  121. package/dist/memory/maintenance-state.js +4 -1
  122. package/dist/memory/maintenance-tuning.d.ts +15 -0
  123. package/dist/memory/maintenance-tuning.js +3 -0
  124. package/dist/memory/reflect-job.d.ts +2 -2
  125. package/dist/memory/reflect-job.js +4 -2
  126. package/dist/memory/scheduler.d.ts +3 -3
  127. package/dist/memory/scheduler.js +5 -2
  128. package/dist/memory/sidecar-worker.js +1 -1
  129. package/dist/memory/transcript.js +1 -1
  130. package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
  131. package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
  132. package/dist/models/login-identity.d.ts +2 -0
  133. package/dist/models/login-identity.js +83 -0
  134. package/dist/models/provider-login.d.ts +3 -1
  135. package/dist/models/provider-login.js +8 -2
  136. package/dist/models/reference.d.ts +20 -0
  137. package/dist/models/{utils.js → reference.js} +0 -48
  138. package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
  139. package/dist/models/runtime.js +52 -0
  140. package/dist/paths.d.ts +2 -0
  141. package/dist/paths.js +9 -0
  142. package/dist/playbooks/agent-delegation.md +2 -2
  143. package/dist/playbooks/catalog.d.ts +6 -2
  144. package/dist/playbooks/catalog.js +9 -6
  145. package/dist/runtime/bootstrap.d.ts +7 -17
  146. package/dist/runtime/bootstrap.js +70 -659
  147. package/dist/runtime/durable-dispatch.d.ts +43 -4
  148. package/dist/runtime/durable-dispatch.js +153 -3
  149. package/dist/runtime/inbound-images.d.ts +18 -0
  150. package/dist/runtime/inbound-images.js +51 -0
  151. package/dist/runtime/shutdown.d.ts +39 -0
  152. package/dist/runtime/shutdown.js +120 -0
  153. package/dist/runtime/stop-watchdog.d.ts +16 -0
  154. package/dist/runtime/stop-watchdog.js +32 -0
  155. package/dist/runtime/task-driver.d.ts +6 -4
  156. package/dist/runtime/task-driver.js +58 -23
  157. package/dist/runtime/task-migration.js +25 -8
  158. package/dist/runtime/task-spawn.d.ts +1 -1
  159. package/dist/runtime/task-spawn.js +13 -6
  160. package/dist/runtime/turn-handler.d.ts +47 -0
  161. package/dist/runtime/turn-handler.js +318 -0
  162. package/dist/runtime/turn-run.d.ts +52 -0
  163. package/dist/runtime/turn-run.js +318 -0
  164. package/dist/runtime/wake-coalescing.d.ts +18 -0
  165. package/dist/runtime/wake-coalescing.js +29 -0
  166. package/dist/security/block-message.d.ts +22 -1
  167. package/dist/security/block-message.js +66 -1
  168. package/dist/security/command-guard.js +4 -0
  169. package/dist/security/network.d.ts +2 -1
  170. package/dist/security/network.js +7 -2
  171. package/dist/security/path-guard-check.js +2 -2
  172. package/dist/security/path-guard.js +4 -0
  173. package/dist/security/types.d.ts +1 -2
  174. package/dist/security/types.js +1 -2
  175. package/dist/shared/exact-keys.d.ts +1 -1
  176. package/dist/shared/format.d.ts +12 -0
  177. package/dist/shared/format.js +37 -0
  178. package/dist/shared/host-process.js +16 -4
  179. package/dist/shared/wake-claim.d.ts +1 -1
  180. package/dist/shared/with-timeout.d.ts +3 -2
  181. package/dist/shared/with-timeout.js +14 -3
  182. package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
  183. package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
  184. package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
  185. package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
  186. package/dist/skills/workspace.d.ts +33 -0
  187. package/dist/skills/workspace.js +116 -0
  188. package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
  189. package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
  190. package/dist/subagents/completion-wake.d.ts +17 -0
  191. package/dist/subagents/completion-wake.js +76 -0
  192. package/dist/subagents/detached-discovery.js +1 -1
  193. package/dist/subagents/discovery.d.ts +1 -1
  194. package/dist/subagents/discovery.js +2 -2
  195. package/dist/subagents/dispatch.d.ts +33 -0
  196. package/dist/subagents/dispatch.js +190 -0
  197. package/dist/subagents/external/claude-code.js +23 -1
  198. package/dist/subagents/external/dispatch.d.ts +25 -0
  199. package/dist/subagents/external/dispatch.js +90 -0
  200. package/dist/subagents/external/harness.d.ts +1 -1
  201. package/dist/subagents/external/progress-tail.d.ts +18 -1
  202. package/dist/subagents/external/progress-tail.js +64 -17
  203. package/dist/subagents/external/run.d.ts +5 -1
  204. package/dist/subagents/external/run.js +23 -9
  205. package/dist/subagents/external/settlement.d.ts +4 -1
  206. package/dist/subagents/external/settlement.js +1 -1
  207. package/dist/subagents/format.d.ts +1 -1
  208. package/dist/subagents/grace.d.ts +24 -0
  209. package/dist/subagents/grace.js +57 -0
  210. package/dist/subagents/internal/outcome.d.ts +24 -0
  211. package/dist/subagents/internal/outcome.js +149 -0
  212. package/dist/subagents/internal/provider-retry.d.ts +19 -0
  213. package/dist/subagents/internal/provider-retry.js +83 -0
  214. package/dist/subagents/internal/run.d.ts +31 -0
  215. package/dist/subagents/internal/run.js +240 -0
  216. package/dist/subagents/internal/state.d.ts +43 -0
  217. package/dist/subagents/internal/state.js +48 -0
  218. package/dist/subagents/internal/worker.d.ts +51 -0
  219. package/dist/subagents/internal/worker.js +167 -0
  220. package/dist/subagents/result.d.ts +62 -0
  221. package/dist/subagents/result.js +103 -0
  222. package/dist/subagents/run-record.d.ts +222 -0
  223. package/dist/subagents/run-record.js +101 -0
  224. package/dist/subagents/run-registry.d.ts +9 -0
  225. package/dist/subagents/run-registry.js +125 -0
  226. package/dist/subagents/runs.d.ts +16 -232
  227. package/dist/subagents/runs.js +132 -310
  228. package/dist/subagents/task-envelope.d.ts +36 -0
  229. package/dist/subagents/task-envelope.js +168 -0
  230. package/dist/subagents/types.d.ts +154 -0
  231. package/dist/subagents/types.js +1 -0
  232. package/dist/subagents/verification-outcome.d.ts +1 -1
  233. package/dist/subagents/workspace-summary.d.ts +16 -4
  234. package/dist/subagents/workspace-summary.js +74 -18
  235. package/dist/tasks/board.d.ts +10 -3
  236. package/dist/tasks/board.js +38 -3
  237. package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
  238. package/dist/tasks/{work-log.js → bound-work.js} +1 -1
  239. package/dist/tasks/brief.js +1 -1
  240. package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
  241. package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
  242. package/dist/tasks/contract-input.d.ts +1 -1
  243. package/dist/tasks/contract-input.js +1 -1
  244. package/dist/tasks/create.js +1 -1
  245. package/dist/tasks/frontmatter.d.ts +5 -0
  246. package/dist/tasks/frontmatter.js +8 -0
  247. package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
  248. package/dist/tasks/{log.js → loop-log.js} +59 -3
  249. package/dist/tasks/mutation-lock.js +1 -1
  250. package/dist/tasks/session-path.js +1 -1
  251. package/dist/tasks/steer.js +1 -1
  252. package/dist/tasks/store.js +6 -4
  253. package/dist/tasks/ticket.d.ts +3 -1
  254. package/dist/tasks/ticket.js +19 -1
  255. package/dist/tools/bash.d.ts +1 -1
  256. package/dist/tools/bash.js +2 -2
  257. package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
  258. package/dist/tools/{tool-details.js → contract/details.js} +42 -5
  259. package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
  260. package/dist/tools/event-manage.d.ts +1 -1
  261. package/dist/tools/event-manage.js +4 -4
  262. package/dist/tools/index.d.ts +5 -3
  263. package/dist/tools/index.js +8 -6
  264. package/dist/tools/job.d.ts +1 -1
  265. package/dist/tools/memory-manage.js +4 -1
  266. package/dist/tools/registry.d.ts +7 -7
  267. package/dist/tools/registry.js +6 -6
  268. package/dist/tools/session-search.d.ts +1 -1
  269. package/dist/tools/skill.d.ts +2 -34
  270. package/dist/tools/skill.js +8 -116
  271. package/dist/tools/subagent-manage.d.ts +1 -1
  272. package/dist/tools/subagent-manage.js +19 -13
  273. package/dist/tools/subagent.d.ts +46 -0
  274. package/dist/tools/subagent.js +127 -0
  275. package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
  276. package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
  277. package/dist/tools/task-manage/lifecycle.js +2 -2
  278. package/dist/tools/task-manage/log-view.js +2 -2
  279. package/dist/tools/task-manage/shared.js +3 -3
  280. package/dist/tools/task-manage/step-end.js +7 -4
  281. package/dist/tools/task-manage/types.d.ts +1 -1
  282. package/dist/tools/web-fetch.d.ts +1 -1
  283. package/dist/tools/web-search.d.ts +1 -1
  284. package/dist/tui/app.d.ts +1 -1
  285. package/dist/tui/app.js +6 -6
  286. package/dist/tui/cli.d.ts +1 -1
  287. package/dist/tui/cli.js +3 -3
  288. package/dist/tui/commands.js +4 -4
  289. package/dist/tui/frontend.d.ts +44 -0
  290. package/dist/tui/frontend.js +13 -0
  291. package/dist/tui/pitui-frontend.d.ts +1 -1
  292. package/dist/tui/pitui-frontend.js +1 -1
  293. package/dist/tui/plain-frontend.d.ts +1 -1
  294. package/dist/tui/renderer.d.ts +3 -42
  295. package/dist/tui/renderer.js +3 -2
  296. package/dist/tui/terminal-context.d.ts +2 -2
  297. package/dist/tui/terminal-media-sender.d.ts +1 -1
  298. package/dist/tui/turn-controller.d.ts +3 -1
  299. package/dist/tui/turn-controller.js +36 -21
  300. package/dist/usage/ledger.js +7 -1
  301. package/dist/usage/render.js +3 -1
  302. package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
  303. package/dist/web/client.d.ts +5 -1
  304. package/dist/web/client.js +4 -0
  305. package/dist/web/config.d.ts +1 -1
  306. package/dist/web/fetch.d.ts +1 -1
  307. package/dist/web/search-providers.d.ts +1 -1
  308. package/dist/web/search.d.ts +1 -1
  309. package/package.json +9 -7
  310. package/dist/agent/session-adapter.js +0 -77
  311. package/dist/events/events.d.ts +0 -159
  312. package/dist/runtime/dingtalk.d.ts +0 -272
  313. package/dist/runtime/dingtalk.js +0 -1416
  314. package/dist/subagents/tool.d.ts +0 -206
  315. package/dist/subagents/tool.js +0 -1088
  316. /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
  317. /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
  318. /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
  319. /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
  320. /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
  321. /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
  322. /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
  323. /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
  324. /package/dist/{runtime → app}/proxy.d.ts +0 -0
  325. /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
  326. /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
  327. /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
  328. /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
  329. /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
  330. /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
  331. /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
  332. /package/dist/tasks/{ledger.js → contract.js} +0 -0
  333. /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
  334. /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
  335. /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
  336. /package/dist/{shared/types.js → usage/totals.js} +0 -0
@@ -4,7 +4,7 @@ import { promisify } from "node:util";
4
4
  * Stateless host-process operations shared by background jobs and external delegation runs
5
5
  * (spec 040, D1): a liveness probe and a process-group kill. Nothing here is job- or run-specific
6
6
  * — both callers bring their own persisted pid and decide what "gone" means for their own state
7
- * machine. `job-manager.ts` still probes through its shell `Executor` (its jobs are shell
7
+ * machine. `jobs/manager.ts` still probes through its shell `Executor` (its jobs are shell
8
8
  * children); this is for callers that spawn argv-direct, detached children of their own (D3/D4).
9
9
  */
10
10
  const execFileAsync = promisify(execFile);
@@ -26,6 +26,8 @@ export async function readProcessStartTime(pid) {
26
26
  }
27
27
  const CLI_VERSION_PROBE_TIMEOUT_MS = 1_000;
28
28
  const CLI_VERSION_MAX_CHARS = 200;
29
+ const CLI_VERSION_CACHE_TTL_MS = 10 * 60_000;
30
+ const cliVersionCache = new Map();
29
31
  /**
30
32
  * Best-effort `<executable> --version`, so a run persists which build of the target CLI it ran
31
33
  * against (spec 042 D12) — the other half of `parserVersion`'s "adapter drift vs. agent failure"
@@ -33,14 +35,24 @@ const CLI_VERSION_MAX_CHARS = 200;
33
35
  * a CLI that does not support `--version`, is slow to start, or fails outright.
34
36
  */
35
37
  export async function probeCliVersion(executable) {
38
+ // A CLI's version changes only when someone upgrades it, while a busy channel dispatches the
39
+ // same executable many times an hour — re-spawning `<cli> --version` (a cold Node start for
40
+ // claude/codex) per dispatch bought nothing. A short TTL keeps an upgrade visible soon after.
41
+ const cached = cliVersionCache.get(executable);
42
+ if (cached && Date.now() - cached.at < CLI_VERSION_CACHE_TTL_MS)
43
+ return cached.value;
44
+ let value;
36
45
  try {
37
46
  const { stdout } = await execFileAsync(executable, ["--version"], { timeout: CLI_VERSION_PROBE_TIMEOUT_MS });
38
- const value = stdout.trim().split("\n")[0]?.slice(0, CLI_VERSION_MAX_CHARS);
39
- return value || undefined;
47
+ value = stdout.trim().split("\n")[0]?.slice(0, CLI_VERSION_MAX_CHARS) || undefined;
40
48
  }
41
49
  catch {
42
- return undefined;
50
+ value = undefined;
43
51
  }
52
+ // Only a real answer is cached: a timeout on a cold start should not hide the version for the TTL.
53
+ if (value)
54
+ cliVersionCache.set(executable, { value, at: Date.now() });
55
+ return value;
44
56
  }
45
57
  /** True if `pid` names a live process this user can at least see, without sending a real signal. */
46
58
  export function isProcessAlive(pid) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The two-phase "claim, then finish" decision shared by `job-manager.ts` and `subagents/runs.ts`
2
+ * The two-phase "claim, then finish" decision shared by `jobs/manager.ts` and `subagents/runs.ts`
3
3
  * for reserving a completion wake exactly once (spec 040, D7/T9). Both managers persist a
4
4
  * `RunRecord`/`JobRecord` differently and gate eligibility on a different terminal condition
5
5
  * (job: `status !== "running"`; run: `settledAt` set), so only the claim/consume decision on the
@@ -12,6 +12,7 @@ export declare class OperationTimeoutError extends Error {
12
12
  constructor(operation: string, timeoutMs: number);
13
13
  }
14
14
  /** A delay that never keeps the process alive on its own — every background-loop backoff and
15
- * budget wait in the codebase wants this, not a bare `setTimeout` promise. */
16
- export declare function sleepUnref(ms: number): Promise<void>;
15
+ * budget wait in the codebase wants this, not a bare `setTimeout` promise. An aborted `signal`
16
+ * ends the wait early (it still resolves; callers re-check whatever aborted it). */
17
+ export declare function sleepUnref(ms: number, signal?: AbortSignal): Promise<void>;
17
18
  export declare function withTimeout<T>(operation: string, timeoutMs: number, run: () => Promise<T>): Promise<T>;
@@ -15,11 +15,22 @@ export class OperationTimeoutError extends Error {
15
15
  }
16
16
  }
17
17
  /** A delay that never keeps the process alive on its own — every background-loop backoff and
18
- * budget wait in the codebase wants this, not a bare `setTimeout` promise. */
19
- export function sleepUnref(ms) {
18
+ * budget wait in the codebase wants this, not a bare `setTimeout` promise. An aborted `signal`
19
+ * ends the wait early (it still resolves; callers re-check whatever aborted it). */
20
+ export function sleepUnref(ms, signal) {
20
21
  return new Promise((resolve) => {
21
- const timer = setTimeout(resolve, ms);
22
+ if (signal?.aborted) {
23
+ resolve();
24
+ return;
25
+ }
26
+ const done = () => {
27
+ clearTimeout(timer);
28
+ signal?.removeEventListener("abort", done);
29
+ resolve();
30
+ };
31
+ const timer = setTimeout(done, ms);
22
32
  timer.unref?.();
33
+ signal?.addEventListener("abort", done, { once: true });
23
34
  });
24
35
  }
25
36
  export async function withTimeout(operation, timeoutMs, run) {
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * `/skills` — the human control path for a workspace's skill catalog (spec 045's read-only
3
- * `skill` tool has no channel-command counterpart until now). Mirrors `project-commands.ts`'s
3
+ * `skill` tool has no channel-command counterpart until now). Mirrors `channel/commands.ts`'s
4
4
  * shape: pure-ish functions returning markdown, no bot/event coupling.
5
5
  *
6
6
  * Deliberately a disk scan via `listWorkspaceSkills`, not the live `ChannelRunner`'s already-
7
7
  * loaded catalog: that keeps `/skills` usable while a turn is streaming and for a channel with no
8
8
  * active runner, and — the whole reason this exists rather than reusing `/help`'s discovery tail
9
9
  * — it is the only place that shows a skill that failed the content scan and was silently dropped
10
- * from `<available_skills>` (`src/agent/workspace-resources.ts`).
10
+ * from the prompt's skill list (`src/skills/loader.ts`).
11
11
  */
12
12
  export interface HandleSkillsCommandOptions {
13
13
  args: string;
@@ -1,8 +1,10 @@
1
1
  import { renderSubcommandUsage } from "../commands/catalog.js";
2
- import { capReply } from "../commands/reply-limits.js";
2
+ import { capReply, flattenMarkdownForChat } from "../commands/reply-limits.js";
3
+ import { GuardBlockedError, renderGuardBlockForUser } from "../security/block-message.js";
3
4
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
5
+ import { RecoverableToolError } from "../shared/recoverable-error.js";
4
6
  import { errorMessage } from "../shared/text-utils.js";
5
- import { listWorkspaceSkills, loadWorkspaceSkillFile } from "../tools/skill.js";
7
+ import { listWorkspaceSkills, loadWorkspaceSkillFile } from "./workspace.js";
6
8
  function usage() {
7
9
  return renderSubcommandUsage("skills");
8
10
  }
@@ -17,25 +19,25 @@ export function parseSkillsCommand(args) {
17
19
  throw new Error("用法:/skills show <name>");
18
20
  return { action: "show", name: parts[1] };
19
21
  }
20
- throw new Error(`未知的 /skills 子命令:${parts[0]}`);
22
+ throw new Error(`未知子命令 \`${parts[0]}\`。`);
21
23
  }
22
24
  async function listSkills(workspaceDir) {
23
25
  const skills = await listWorkspaceSkills({ workspaceDir });
24
26
  if (skills.length === 0) {
25
- return (`**Workspace skills**\n\n暂无工作区 skill(\`${workspaceDir}/skills/\` 下没有)。\n\n` +
26
- "用 write/edit 在 `workspace/skills/<name>/SKILL.md` 直接创建,frontmatter 需要非空的 `name`(与目录名一致)和 `description`。");
27
+ return ("暂无工作区 skill。\n" +
28
+ `让我帮你创建,或手动放到 \`${workspaceDir}/skills/<name>/SKILL.md\`(文件头需要非空的 \`name\`,与目录名一致,以及 \`description\`)。`);
27
29
  }
28
30
  const loaded = skills.filter((skill) => !skill.warning);
29
31
  const rejected = skills.filter((skill) => skill.warning);
30
- const lines = [`**Workspace skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
32
+ const lines = [`**工作区 skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
31
33
  if (loaded.length > 0) {
32
- lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "(无 description)"}`));
34
+ lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "(无 description)"}`));
33
35
  }
34
36
  else {
35
37
  lines.push("(全部未通过加载,见下)");
36
38
  }
37
39
  if (rejected.length > 0) {
38
- lines.push("", "⚠ 未加载(不在 `<available_skills>` 中,也无法通过 `/skill:名称` 调用)", "");
40
+ lines.push("", "⚠️ 未加载(助手看不到,也无法用 `/skill:名称` 调用)", "");
39
41
  lines.push(...rejected.map((skill) => `- \`${skill.name}\` — ${skill.warning}`));
40
42
  }
41
43
  return capReply(lines.join("\n"), { nextStepHint: "用 `/skills show <name>` 查看单个 skill 的完整正文" }).text;
@@ -48,11 +50,16 @@ async function showSkill(options, name) {
48
50
  securityConfig,
49
51
  channelId: options.channelId,
50
52
  }, name);
51
- const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${file.content}`;
52
- return capReply(body, { nextStepHint: `用 read 工具打开 ${file.path} 继续查看` }).text;
53
+ const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${flattenMarkdownForChat(file.content)}`;
54
+ return capReply(body, { nextStepHint: `完整内容在 \`${file.path}\`` }).text;
53
55
  }
54
56
  catch (error) {
55
- return `无法查看 skill:${errorMessage(error)}`;
57
+ // The loader's errors are written for the model (`Use action "list"…`); say it in the user's terms.
58
+ if (error instanceof RecoverableToolError)
59
+ return `未找到 skill \`${name}\`。用 \`/skills\` 查看可用的 skill。`;
60
+ if (error instanceof GuardBlockedError)
61
+ return renderGuardBlockForUser(error.blocked);
62
+ return `无法读取 skill \`${name}\`:${errorMessage(error)}`;
56
63
  }
57
64
  }
58
65
  export async function handleSkillsCommand(options) {
@@ -7,7 +7,7 @@
7
7
  import { readFileSync } from "node:fs";
8
8
  import { loadSkillsFromDir } from "@earendil-works/pi-coding-agent";
9
9
  import { join } from "path";
10
- import { scanSkillContent } from "../tools/skill-security.js";
10
+ import { scanSkillContent } from "./validation.js";
11
11
  /**
12
12
  * Content scanning moved here from the old `skill_manage` write path (spec 045): `skill` is now
13
13
  * read-only and workspace skills are authored through the generic `write`/`edit` tools, which have
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Validation of workspace skills: names, frontmatter, content scanning, and confinement of a skill's
3
+ * path to `workspace/skills/`.
4
+ */
1
5
  import { resolve } from "node:path";
2
6
  const SKILL_NAME_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
3
7
  const FRONTMATTER_REGEX = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
@@ -0,0 +1,33 @@
1
+ import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
2
+ export interface WorkspaceSkillSummary {
3
+ name: string;
4
+ description: string;
5
+ path: string;
6
+ warning?: string;
7
+ }
8
+ export interface WorkspaceSkillOptions {
9
+ workspaceDir: string;
10
+ securityConfig?: SecurityConfig;
11
+ securityContext?: SecurityRuntimeContext;
12
+ channelId?: string;
13
+ }
14
+ export declare function listWorkspaceSkills(options: {
15
+ workspaceDir: string;
16
+ securityConfig?: SecurityConfig;
17
+ securityContext?: SecurityRuntimeContext;
18
+ }): Promise<WorkspaceSkillSummary[]>;
19
+ export interface WorkspaceSkillFile {
20
+ name: string;
21
+ /** The guard-resolved path actually opened — never the raw pre-guard path. */
22
+ path: string;
23
+ /** The whole file; callers that need a size cap (the `skill` tool) apply it themselves. */
24
+ content: string;
25
+ }
26
+ /**
27
+ * Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
28
+ * through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
29
+ * (`skills/commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
30
+ * `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
31
+ * confines that) is caught here in both callers instead of being read verbatim.
32
+ */
33
+ export declare function loadWorkspaceSkillFile(options: WorkspaceSkillOptions, name: string): Promise<WorkspaceSkillFile>;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Workspace skill catalog access: list the skills under `workspace/skills/` and load one
3
+ * `SKILL.md`, both through the path guard. The `skill` tool and `/skills` are thin adapters over
4
+ * this file (spec 054 D8/D10).
5
+ */
6
+ import { existsSync } from "node:fs";
7
+ import { readdir, readFile, stat } from "node:fs/promises";
8
+ import { join } from "node:path";
9
+ import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
10
+ import { checkPathGuard } from "../security/path-guard-check.js";
11
+ import { readGuardAllows } from "../security/path-guard-filter.js";
12
+ import { isNodeError } from "../shared/os.js";
13
+ import { RecoverableToolError } from "../shared/recoverable-error.js";
14
+ import { resolveSkillPath, scanSkillContent, validateSkillFrontmatter, validateSkillName } from "./validation.js";
15
+ function extractDescription(content) {
16
+ const match = content.replace(/\r\n/g, "\n").match(/^---\n([\s\S]*?)\n---/);
17
+ if (!match) {
18
+ return "";
19
+ }
20
+ for (const line of (match[1] ?? "").split("\n")) {
21
+ const fieldMatch = line.match(/^description:\s*(.*)$/);
22
+ if (fieldMatch) {
23
+ return fieldMatch[1].replace(/^["']|["']$/g, "").trim();
24
+ }
25
+ }
26
+ return "";
27
+ }
28
+ export async function listWorkspaceSkills(options) {
29
+ const skillsDir = join(options.workspaceDir, "skills");
30
+ // `skill read` runs each SKILL.md through the path guard (`loadWorkspaceSkillFile`); `list`
31
+ // must apply the same guard so a skill whose SKILL.md is a symlink out of `workspace/skills/`
32
+ // is silently omitted here too, rather than being advertised and then refused on read.
33
+ const guardConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
34
+ const guardContext = options.securityContext ?? {
35
+ agentWorkspaceDir: options.workspaceDir,
36
+ projectRoot: options.workspaceDir,
37
+ };
38
+ let names;
39
+ try {
40
+ names = await readdir(skillsDir);
41
+ }
42
+ catch (error) {
43
+ if (isNodeError(error) && error.code === "ENOENT") {
44
+ return [];
45
+ }
46
+ throw error;
47
+ }
48
+ const summaries = [];
49
+ for (const name of names.sort()) {
50
+ const nameValidation = validateSkillName(name);
51
+ if (!nameValidation.ok) {
52
+ continue;
53
+ }
54
+ const skillDir = join(skillsDir, name);
55
+ const skillStats = await stat(skillDir).catch(() => null);
56
+ if (!skillStats?.isDirectory()) {
57
+ continue;
58
+ }
59
+ const skillPath = join(skillDir, "SKILL.md");
60
+ if (!readGuardAllows(skillPath, guardConfig, guardContext)) {
61
+ continue;
62
+ }
63
+ let content;
64
+ try {
65
+ const skillFileStats = await stat(skillPath);
66
+ if (!skillFileStats.isFile()) {
67
+ continue;
68
+ }
69
+ content = await readFile(skillPath, "utf-8");
70
+ }
71
+ catch (error) {
72
+ if (isNodeError(error) && error.code === "ENOENT") {
73
+ continue;
74
+ }
75
+ throw error;
76
+ }
77
+ const validation = validateSkillFrontmatter(content, name);
78
+ const scan = validation.ok ? scanSkillContent(content) : validation;
79
+ summaries.push({
80
+ name,
81
+ description: extractDescription(content),
82
+ path: `${options.workspaceDir}/skills/${name}/SKILL.md`,
83
+ warning: scan.ok ? undefined : scan.error,
84
+ });
85
+ }
86
+ return summaries;
87
+ }
88
+ /**
89
+ * Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
90
+ * through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
91
+ * (`skills/commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
92
+ * `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
93
+ * confines that) is caught here in both callers instead of being read verbatim.
94
+ */
95
+ export async function loadWorkspaceSkillFile(options, name) {
96
+ const nameValidation = validateSkillName(name);
97
+ if (!nameValidation.ok) {
98
+ throw new RecoverableToolError(nameValidation.error ?? `Invalid skill name "${name}".`);
99
+ }
100
+ const skillDir = resolveSkillPath(options.workspaceDir, name);
101
+ const rawPath = join(skillDir, "SKILL.md");
102
+ if (!existsSync(rawPath)) {
103
+ throw new RecoverableToolError(`Workspace skill "${name}" does not exist. Use action "list" to see what's available.`);
104
+ }
105
+ const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
106
+ const securityContext = options.securityContext ?? {
107
+ agentWorkspaceDir: options.workspaceDir,
108
+ projectRoot: options.workspaceDir,
109
+ };
110
+ const target = await checkPathGuard(rawPath, "read", securityConfig, securityContext, {
111
+ tool: "skill",
112
+ channelId: options.channelId,
113
+ });
114
+ const content = await readFile(target, "utf-8");
115
+ return { name, path: target, content };
116
+ }
@@ -1,8 +1,9 @@
1
- import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
2
- import type { RunNotice, SubAgentRunManager } from "../subagents/runs.js";
1
+ import type { SubAgentDiscoveryResult } from "./discovery.js";
2
+ import type { RunNotice } from "./run-record.js";
3
+ import type { SubAgentRunManager } from "./runs.js";
3
4
  /**
4
5
  * `/subagents` — the human control path that does not depend on the model (spec 040 D6, polished
5
- * by spec 041). Mirrors `task-commands.ts`'s shape: pure functions returning markdown, no
6
+ * by spec 041). Mirrors `tasks/commands.ts`'s shape: pure functions returning markdown, no
6
7
  * bot/event coupling.
7
8
  */
8
9
  export interface HandleSubagentsCommandOptions {
@@ -37,10 +38,11 @@ type SubagentsCommand = {
37
38
  export declare function parseSubagentsCommand(args: string): SubagentsCommand;
38
39
  export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
39
40
  /**
40
- * Render a `RunNotice` (P0-1/P1a) as a one-line reply — a confirmation, per the command reply
41
- * conventions. `notices: "off"` is enforced by the caller not invoking this at all; a `"settled"`
42
- * caller filters `kind: "progress"` out before calling. Returns `undefined` for a notice with
43
- * nothing worth showing (a progress step that never resolved to a label).
41
+ * Render a `RunNotice` (P0-1/P1a) as a runtime push (spec 053, D6): one marker, the run id the
42
+ * user can act on, and — for a failure — the command that shows why. `notices: "off"` is enforced
43
+ * by the caller not invoking this at all; a `"settled"` caller filters `kind: "progress"` out
44
+ * before calling (a `"stalled"` warning needs attention, so it passes both levels). Returns `undefined` for a notice with nothing worth showing (a progress step
45
+ * that never resolved to a label).
44
46
  */
45
47
  export declare function renderRunNotice(notice: RunNotice): string | undefined;
46
48
  export {};