@oyasmi/pipiclaw 0.9.4 → 0.9.5-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 (405) hide show
  1. package/README.en.md +28 -22
  2. package/README.md +27 -21
  3. package/dist/agent/builtin-commands.d.ts +7 -2
  4. package/dist/agent/builtin-commands.js +19 -23
  5. package/dist/agent/channel-runner.d.ts +13 -13
  6. package/dist/agent/channel-runner.js +93 -76
  7. package/dist/agent/maintenance-context.d.ts +6 -5
  8. package/dist/agent/maintenance-context.js +15 -15
  9. package/dist/agent/prompt/manifest.js +1 -1
  10. package/dist/agent/prompt/resources.d.ts +1 -1
  11. package/dist/agent/prompt/resources.js +1 -1
  12. package/dist/agent/prompt/sections.js +4 -4
  13. package/dist/agent/runner-factory.d.ts +6 -6
  14. package/dist/agent/runner-factory.js +6 -7
  15. package/dist/agent/session/compaction-input.d.ts +6 -0
  16. package/dist/agent/session/compaction-input.js +75 -0
  17. package/dist/agent/session/compaction-snapshot.d.ts +30 -0
  18. package/dist/agent/session/compaction-snapshot.js +154 -0
  19. package/dist/agent/session/compaction-summary.d.ts +39 -0
  20. package/dist/agent/session/compaction-summary.js +158 -0
  21. package/dist/agent/session/compaction.d.ts +35 -0
  22. package/dist/agent/session/compaction.js +294 -0
  23. package/dist/agent/session/context-input.d.ts +15 -0
  24. package/dist/agent/session/context-input.js +82 -0
  25. package/dist/agent/session/context-snapshot.d.ts +11 -0
  26. package/dist/agent/session/context-snapshot.js +72 -0
  27. package/dist/agent/session/event-guards.d.ts +2 -0
  28. package/dist/agent/session/event-guards.js +4 -0
  29. package/dist/agent/session/request-tools.d.ts +3 -0
  30. package/dist/agent/session/request-tools.js +20 -0
  31. package/dist/agent/session/session-adapter.d.ts +2 -1
  32. package/dist/agent/session/session-adapter.js +6 -3
  33. package/dist/agent/session/session-events.d.ts +5 -4
  34. package/dist/agent/session/session-events.js +46 -59
  35. package/dist/agent/session/session-host.d.ts +29 -41
  36. package/dist/agent/session/session-host.js +86 -69
  37. package/dist/agent/session/settings-diagnostics.d.ts +5 -0
  38. package/dist/agent/session/settings-diagnostics.js +21 -0
  39. package/dist/agent/status-render.js +5 -2
  40. package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
  41. package/dist/{runtime → agent}/stop-watchdog.js +7 -3
  42. package/dist/agent/turn/progress-formatter.d.ts +1 -3
  43. package/dist/agent/turn/progress-formatter.js +3 -22
  44. package/dist/agent/turn/task-digest.d.ts +4 -2
  45. package/dist/agent/turn/task-digest.js +7 -4
  46. package/dist/agent/turn/turn-context.d.ts +11 -7
  47. package/dist/agent/turn/turn-context.js +26 -18
  48. package/dist/agent/turn/turn-finish.d.ts +17 -5
  49. package/dist/agent/turn/turn-finish.js +51 -77
  50. package/dist/agent/turn/turn-input.d.ts +2 -2
  51. package/dist/agent/turn/turn-input.js +4 -3
  52. package/dist/agent/turn/turn-output.d.ts +19 -0
  53. package/dist/agent/turn/turn-output.js +41 -0
  54. package/dist/agent/turn/turn-pipeline.d.ts +11 -8
  55. package/dist/agent/turn/turn-pipeline.js +54 -55
  56. package/dist/agent/turn/turn-prompt.d.ts +1 -1
  57. package/dist/agent/turn/turn-recovery.d.ts +11 -10
  58. package/dist/agent/turn/turn-recovery.js +14 -29
  59. package/dist/agent/types.d.ts +31 -12
  60. package/dist/agent/types.js +2 -1
  61. package/dist/app/auth-command.js +1 -1
  62. package/dist/app/home.js +31 -15
  63. package/dist/channel/active-session-store.d.ts +14 -12
  64. package/dist/channel/active-session-store.js +29 -25
  65. package/dist/channel/attachments.d.ts +25 -0
  66. package/dist/channel/attachments.js +56 -0
  67. package/dist/channel/channel-context.d.ts +87 -96
  68. package/dist/channel/channel-context.js +1 -66
  69. package/dist/channel/channel-event.d.ts +51 -41
  70. package/dist/channel/channel-event.js +6 -11
  71. package/dist/channel/channel-id.d.ts +22 -0
  72. package/dist/channel/channel-id.js +13 -0
  73. package/dist/channel/channel-index.d.ts +17 -34
  74. package/dist/channel/channel-index.js +41 -80
  75. package/dist/channel/config.d.ts +10 -0
  76. package/dist/channel/config.js +55 -0
  77. package/dist/channel/ingress.d.ts +101 -0
  78. package/dist/channel/ingress.js +5 -0
  79. package/dist/channel/store.d.ts +13 -15
  80. package/dist/channel/store.js +21 -25
  81. package/dist/channel/transport.d.ts +99 -0
  82. package/dist/channel/turn-context.d.ts +23 -0
  83. package/dist/channel/turn-context.js +1 -0
  84. package/dist/commands/catalog.d.ts +4 -7
  85. package/dist/commands/catalog.js +24 -31
  86. package/dist/commands/router.d.ts +23 -12
  87. package/dist/commands/router.js +22 -24
  88. package/dist/config/settings.d.ts +5 -4
  89. package/dist/desk/bindings.d.ts +6 -0
  90. package/dist/desk/bindings.js +105 -0
  91. package/dist/desk/commands.d.ts +81 -0
  92. package/dist/desk/commands.js +145 -0
  93. package/dist/desk/default.d.ts +4 -0
  94. package/dist/desk/default.js +11 -0
  95. package/dist/desk/paths.d.ts +41 -0
  96. package/dist/desk/paths.js +81 -0
  97. package/dist/desk/registry.d.ts +17 -0
  98. package/dist/desk/registry.js +191 -0
  99. package/dist/desk/startup-error.d.ts +4 -0
  100. package/dist/desk/startup-error.js +7 -0
  101. package/dist/desk/types.d.ts +72 -0
  102. package/dist/desk/types.js +7 -0
  103. package/dist/dingtalk/bot.d.ts +18 -35
  104. package/dist/dingtalk/bot.js +21 -204
  105. package/dist/dingtalk/channel-ids.d.ts +15 -0
  106. package/dist/dingtalk/channel-ids.js +39 -0
  107. package/dist/dingtalk/config.d.ts +6 -3
  108. package/dist/dingtalk/config.js +13 -25
  109. package/dist/dingtalk/connection.d.ts +1 -0
  110. package/dist/dingtalk/connection.js +5 -4
  111. package/dist/dingtalk/conversation-meta.d.ts +10 -5
  112. package/dist/dingtalk/conversation-meta.js +72 -50
  113. package/dist/dingtalk/delivery.d.ts +30 -14
  114. package/dist/dingtalk/delivery.js +189 -62
  115. package/dist/dingtalk/inbound-media.d.ts +2 -18
  116. package/dist/dingtalk/inbound-media.js +0 -53
  117. package/dist/dingtalk/inbound.d.ts +10 -11
  118. package/dist/dingtalk/inbound.js +12 -19
  119. package/dist/dingtalk/media.d.ts +9 -11
  120. package/dist/dingtalk/media.js +18 -31
  121. package/dist/dingtalk/progress.d.ts +8 -0
  122. package/dist/dingtalk/progress.js +20 -0
  123. package/dist/dingtalk/response-mode.d.ts +13 -0
  124. package/dist/dingtalk/response-mode.js +31 -0
  125. package/dist/dingtalk/transport.d.ts +47 -0
  126. package/dist/dingtalk/transport.js +71 -0
  127. package/dist/events/commands.d.ts +7 -2
  128. package/dist/events/commands.js +40 -22
  129. package/dist/events/pre-action-error.d.ts +10 -0
  130. package/dist/events/pre-action-error.js +10 -0
  131. package/dist/events/types.d.ts +20 -2
  132. package/dist/events/watcher.d.ts +14 -7
  133. package/dist/events/watcher.js +49 -26
  134. package/dist/index.d.ts +4 -2
  135. package/dist/jobs/completion-wake.d.ts +14 -0
  136. package/dist/jobs/completion-wake.js +36 -0
  137. package/dist/jobs/manager.d.ts +27 -22
  138. package/dist/jobs/manager.js +58 -91
  139. package/dist/jobs/record.d.ts +2 -0
  140. package/dist/jobs/record.js +2 -0
  141. package/dist/log.d.ts +0 -1
  142. package/dist/log.js +1 -1
  143. package/dist/main.js +10 -3
  144. package/dist/memory/boundary-work.d.ts +17 -0
  145. package/dist/memory/boundary-work.js +162 -0
  146. package/dist/memory/commands.d.ts +4 -3
  147. package/dist/memory/commands.js +16 -16
  148. package/dist/memory/desk-memory-queue.d.ts +18 -0
  149. package/dist/memory/desk-memory-queue.js +33 -0
  150. package/dist/memory/index-budget.d.ts +3 -3
  151. package/dist/memory/index-budget.js +3 -3
  152. package/dist/memory/journal.d.ts +6 -6
  153. package/dist/memory/journal.js +14 -14
  154. package/dist/memory/lifecycle.d.ts +14 -21
  155. package/dist/memory/lifecycle.js +73 -103
  156. package/dist/memory/maintenance-state.d.ts +14 -15
  157. package/dist/memory/maintenance-state.js +43 -42
  158. package/dist/memory/reflect-job.d.ts +5 -4
  159. package/dist/memory/reflect-job.js +21 -15
  160. package/dist/memory/reflect.d.ts +2 -1
  161. package/dist/memory/reflect.js +13 -12
  162. package/dist/memory/render.d.ts +1 -1
  163. package/dist/memory/render.js +2 -2
  164. package/dist/memory/review-log.d.ts +4 -4
  165. package/dist/memory/review-log.js +5 -5
  166. package/dist/memory/scheduler.d.ts +12 -19
  167. package/dist/memory/scheduler.js +28 -64
  168. package/dist/memory/session-corpus.d.ts +4 -1
  169. package/dist/memory/session-corpus.js +70 -29
  170. package/dist/memory/session-search.d.ts +11 -3
  171. package/dist/memory/session-search.js +14 -11
  172. package/dist/memory/sidecar-worker.d.ts +1 -0
  173. package/dist/memory/sidecar-worker.js +57 -76
  174. package/dist/memory/source-window.d.ts +0 -6
  175. package/dist/memory/source-window.js +0 -20
  176. package/dist/memory/store.d.ts +12 -12
  177. package/dist/memory/store.js +44 -44
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.js +2 -0
  180. package/dist/playbooks/agent-delegation.md +16 -16
  181. package/dist/playbooks/background-jobs.md +5 -3
  182. package/dist/playbooks/event-scheduling.md +7 -5
  183. package/dist/playbooks/memory-and-learning.md +16 -12
  184. package/dist/playbooks/outbound-media.md +1 -1
  185. package/dist/playbooks/runtime-orientation.md +35 -23
  186. package/dist/playbooks/task-lead.md +13 -11
  187. package/dist/runtime/bootstrap.d.ts +36 -13
  188. package/dist/runtime/bootstrap.js +310 -138
  189. package/dist/runtime/channel-queue.d.ts +23 -0
  190. package/dist/{dingtalk → runtime}/channel-queue.js +20 -9
  191. package/dist/runtime/daemon-lock.d.ts +12 -0
  192. package/dist/runtime/daemon-lock.js +28 -0
  193. package/dist/runtime/desk-runtime.d.ts +131 -0
  194. package/dist/runtime/desk-runtime.js +402 -0
  195. package/dist/runtime/durable-dispatch.d.ts +11 -5
  196. package/dist/runtime/durable-dispatch.js +20 -8
  197. package/dist/runtime/inbound-images.d.ts +32 -10
  198. package/dist/runtime/inbound-images.js +95 -21
  199. package/dist/runtime/ingress-busy.d.ts +26 -0
  200. package/dist/runtime/ingress-busy.js +211 -0
  201. package/dist/runtime/ingress-commands.d.ts +7 -0
  202. package/dist/runtime/ingress-commands.js +162 -0
  203. package/dist/runtime/ingress-deps.d.ts +62 -0
  204. package/dist/runtime/ingress-deps.js +1 -0
  205. package/dist/runtime/ingress.d.ts +22 -0
  206. package/dist/runtime/ingress.js +376 -0
  207. package/dist/runtime/request-execution.d.ts +19 -0
  208. package/dist/runtime/request-execution.js +88 -0
  209. package/dist/runtime/shutdown.d.ts +13 -5
  210. package/dist/runtime/shutdown.js +10 -4
  211. package/dist/runtime/task-driver.d.ts +38 -22
  212. package/dist/runtime/task-driver.js +142 -116
  213. package/dist/runtime/task-spawn.d.ts +4 -4
  214. package/dist/runtime/task-spawn.js +6 -5
  215. package/dist/runtime/task-wake.d.ts +6 -4
  216. package/dist/runtime/task-wake.js +7 -7
  217. package/dist/runtime/transports.d.ts +32 -0
  218. package/dist/runtime/transports.js +101 -0
  219. package/dist/runtime/turn-run.d.ts +18 -9
  220. package/dist/runtime/turn-run.js +302 -71
  221. package/dist/runtime/wake-coalescing.d.ts +11 -3
  222. package/dist/runtime/wake-coalescing.js +10 -0
  223. package/dist/security/config.js +5 -10
  224. package/dist/security/logger.js +1 -1
  225. package/dist/security/path-guard.js +7 -63
  226. package/dist/security/types.d.ts +27 -30
  227. package/dist/security/types.js +0 -1
  228. package/dist/shared/atomic-file.d.ts +2 -0
  229. package/dist/shared/atomic-file.js +14 -1
  230. package/dist/shared/file-lock.d.ts +35 -0
  231. package/dist/shared/file-lock.js +195 -0
  232. package/dist/shared/with-timeout.d.ts +2 -0
  233. package/dist/shared/with-timeout.js +21 -0
  234. package/dist/skills/loader.d.ts +1 -1
  235. package/dist/skills/loader.js +2 -2
  236. package/dist/skills/workspace.js +2 -2
  237. package/dist/subagents/completion-wake.d.ts +11 -2
  238. package/dist/subagents/completion-wake.js +22 -9
  239. package/dist/subagents/discovery.js +1 -1
  240. package/dist/subagents/dispatch.d.ts +0 -10
  241. package/dist/subagents/dispatch.js +10 -28
  242. package/dist/subagents/external/dispatch.js +1 -1
  243. package/dist/subagents/external/run.d.ts +1 -1
  244. package/dist/subagents/external/run.js +3 -3
  245. package/dist/subagents/internal/run.js +1 -1
  246. package/dist/subagents/internal/worker.js +6 -14
  247. package/dist/subagents/run-archive.d.ts +11 -0
  248. package/dist/subagents/run-archive.js +49 -0
  249. package/dist/subagents/run-record.d.ts +9 -8
  250. package/dist/subagents/run-record.js +3 -3
  251. package/dist/subagents/run-registry.d.ts +5 -3
  252. package/dist/subagents/run-registry.js +22 -45
  253. package/dist/subagents/runs.d.ts +23 -13
  254. package/dist/subagents/runs.js +75 -82
  255. package/dist/subagents/task-envelope.js +9 -11
  256. package/dist/subagents/types.d.ts +6 -5
  257. package/dist/tasks/board.d.ts +1 -1
  258. package/dist/tasks/board.js +2 -2
  259. package/dist/tasks/bound-work.d.ts +2 -2
  260. package/dist/tasks/bound-work.js +7 -7
  261. package/dist/tasks/brief.d.ts +1 -1
  262. package/dist/tasks/brief.js +9 -9
  263. package/dist/tasks/commands.d.ts +11 -2
  264. package/dist/tasks/commands.js +66 -41
  265. package/dist/tasks/contract.d.ts +0 -2
  266. package/dist/tasks/contract.js +1 -3
  267. package/dist/tasks/create.d.ts +3 -1
  268. package/dist/tasks/create.js +10 -4
  269. package/dist/tasks/frontmatter.d.ts +6 -2
  270. package/dist/tasks/frontmatter.js +10 -10
  271. package/dist/tasks/loop-log.d.ts +7 -13
  272. package/dist/tasks/loop-log.js +14 -17
  273. package/dist/tasks/mutation-lock.d.ts +7 -5
  274. package/dist/tasks/mutation-lock.js +32 -9
  275. package/dist/tasks/session-path.d.ts +3 -3
  276. package/dist/tasks/session-path.js +5 -5
  277. package/dist/tasks/steer.d.ts +5 -5
  278. package/dist/tasks/steer.js +42 -40
  279. package/dist/tasks/store.d.ts +11 -11
  280. package/dist/tasks/store.js +32 -29
  281. package/dist/tools/bash.d.ts +5 -5
  282. package/dist/tools/bash.js +19 -18
  283. package/dist/tools/contract/names.d.ts +7 -0
  284. package/dist/tools/contract/names.js +22 -0
  285. package/dist/tools/edit.js +1 -1
  286. package/dist/tools/event-manage.d.ts +3 -1
  287. package/dist/tools/event-manage.js +34 -33
  288. package/dist/tools/glob.js +5 -5
  289. package/dist/tools/grep.js +2 -2
  290. package/dist/tools/index.d.ts +9 -8
  291. package/dist/tools/index.js +12 -16
  292. package/dist/tools/job.d.ts +4 -2
  293. package/dist/tools/job.js +11 -8
  294. package/dist/tools/memory-manage.d.ts +5 -3
  295. package/dist/tools/memory-manage.js +24 -24
  296. package/dist/tools/read.js +1 -1
  297. package/dist/tools/registry.d.ts +12 -8
  298. package/dist/tools/registry.js +13 -9
  299. package/dist/tools/send-media.d.ts +2 -2
  300. package/dist/tools/send-media.js +3 -3
  301. package/dist/tools/session-search.d.ts +3 -1
  302. package/dist/tools/session-search.js +8 -6
  303. package/dist/tools/subagent-manage.d.ts +2 -8
  304. package/dist/tools/subagent-manage.js +19 -15
  305. package/dist/tools/subagent.js +1 -1
  306. package/dist/tools/task-manage/create.js +1 -1
  307. package/dist/tools/task-manage/factory.js +2 -2
  308. package/dist/tools/task-manage/lifecycle.js +3 -1
  309. package/dist/tools/task-manage/log-view.js +2 -2
  310. package/dist/tools/task-manage/shared.js +3 -3
  311. package/dist/tools/task-manage/step-end.js +3 -3
  312. package/dist/tools/task-manage/types.d.ts +8 -3
  313. package/dist/tools/web-cache.d.ts +3 -3
  314. package/dist/tools/web-cache.js +12 -12
  315. package/dist/tools/web-fetch.d.ts +2 -2
  316. package/dist/tools/web-fetch.js +7 -7
  317. package/dist/tools/write-content.js +1 -1
  318. package/dist/tui/cli.d.ts +17 -5
  319. package/dist/tui/cli.js +90 -27
  320. package/dist/tui/client.d.ts +26 -0
  321. package/dist/tui/client.js +157 -0
  322. package/dist/tui/colors.d.ts +0 -1
  323. package/dist/tui/colors.js +0 -1
  324. package/dist/tui/commands.d.ts +10 -51
  325. package/dist/tui/commands.js +16 -39
  326. package/dist/tui/frontend.d.ts +2 -2
  327. package/dist/tui/frontend.js +2 -2
  328. package/dist/tui/pitui-frontend.d.ts +0 -2
  329. package/dist/tui/pitui-frontend.js +1 -6
  330. package/dist/tui/render.d.ts +62 -0
  331. package/dist/tui/render.js +123 -0
  332. package/dist/tui/session.d.ts +92 -0
  333. package/dist/tui/session.js +317 -0
  334. package/dist/usage/ledger.d.ts +5 -0
  335. package/dist/usage/ledger.js +2 -0
  336. package/dist/usage/render.d.ts +6 -1
  337. package/dist/usage/render.js +18 -13
  338. package/dist/webapi/auth.d.ts +13 -0
  339. package/dist/webapi/auth.js +29 -0
  340. package/dist/webapi/config.d.ts +29 -0
  341. package/dist/webapi/config.js +100 -0
  342. package/dist/webapi/errors.d.ts +39 -0
  343. package/dist/webapi/errors.js +32 -0
  344. package/dist/webapi/http.d.ts +25 -0
  345. package/dist/webapi/http.js +4 -0
  346. package/dist/webapi/ids.d.ts +9 -0
  347. package/dist/webapi/ids.js +20 -0
  348. package/dist/webapi/input.d.ts +17 -0
  349. package/dist/webapi/input.js +229 -0
  350. package/dist/webapi/items.d.ts +37 -0
  351. package/dist/webapi/items.js +48 -0
  352. package/dist/webapi/key-command.d.ts +2 -0
  353. package/dist/webapi/key-command.js +110 -0
  354. package/dist/webapi/limits.d.ts +47 -0
  355. package/dist/webapi/limits.js +48 -0
  356. package/dist/webapi/request-policy.d.ts +17 -0
  357. package/dist/webapi/request-policy.js +160 -0
  358. package/dist/webapi/response-record.d.ts +68 -0
  359. package/dist/webapi/response-record.js +58 -0
  360. package/dist/webapi/response-state.d.ts +90 -0
  361. package/dist/webapi/response-state.js +347 -0
  362. package/dist/webapi/routes/conversations.d.ts +8 -0
  363. package/dist/webapi/routes/conversations.js +80 -0
  364. package/dist/webapi/routes/models.d.ts +3 -0
  365. package/dist/webapi/routes/models.js +12 -0
  366. package/dist/webapi/routes/responses.d.ts +8 -0
  367. package/dist/webapi/routes/responses.js +118 -0
  368. package/dist/webapi/routes/websocket.d.ts +9 -0
  369. package/dist/webapi/routes/websocket.js +328 -0
  370. package/dist/webapi/server.d.ts +24 -0
  371. package/dist/webapi/server.js +229 -0
  372. package/dist/webapi/service.d.ts +130 -0
  373. package/dist/webapi/service.js +588 -0
  374. package/dist/webapi/store.d.ts +46 -0
  375. package/dist/webapi/store.js +245 -0
  376. package/dist/webapi/stream.d.ts +13 -0
  377. package/dist/webapi/stream.js +76 -0
  378. package/dist/webapi/transport.d.ts +43 -0
  379. package/dist/webapi/transport.js +100 -0
  380. package/package.json +8 -2
  381. package/dist/channel/channel-paths.d.ts +0 -16
  382. package/dist/channel/channel-paths.js +0 -53
  383. package/dist/channel/commands.d.ts +0 -32
  384. package/dist/channel/commands.js +0 -109
  385. package/dist/channel/project-scope-store.d.ts +0 -51
  386. package/dist/channel/project-scope-store.js +0 -112
  387. package/dist/dingtalk/channel-queue.d.ts +0 -19
  388. package/dist/dingtalk/handler.d.ts +0 -90
  389. package/dist/memory/channel-maintenance-queue.d.ts +0 -5
  390. package/dist/memory/channel-maintenance-queue.js +0 -8
  391. package/dist/runtime/task-migration.d.ts +0 -30
  392. package/dist/runtime/task-migration.js +0 -465
  393. package/dist/runtime/turn-handler.d.ts +0 -47
  394. package/dist/runtime/turn-handler.js +0 -318
  395. package/dist/security/project-scope.d.ts +0 -45
  396. package/dist/security/project-scope.js +0 -105
  397. package/dist/tui/app.d.ts +0 -16
  398. package/dist/tui/app.js +0 -166
  399. package/dist/tui/terminal-context.d.ts +0 -27
  400. package/dist/tui/terminal-context.js +0 -84
  401. package/dist/tui/terminal-media-sender.d.ts +0 -9
  402. package/dist/tui/terminal-media-sender.js +0 -15
  403. package/dist/tui/turn-controller.d.ts +0 -64
  404. package/dist/tui/turn-controller.js +0 -311
  405. /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Where the Web API keeps what it has told its callers (spec 061, D23). It lives under the
3
+ * channel's own `state/webapi/`, not in a desk, so a conversation's history survives `/desk bind`.
4
+ *
5
+ * state/webapi/ 0700
6
+ * ├── responses.jsonl response id → conversation id, append-only, for operators
7
+ * └── conversations/<conv_id>/
8
+ * ├── conversation.json { id, created_at, metadata, owner }, written atomically
9
+ * └── responses.jsonl a snapshot per response when created and when ended; the last wins
10
+ *
11
+ * Everything is read into memory once at start. A response that never reached an end (the process
12
+ * died mid-turn) is marked failed then, once — it is never re-run, because its tools may already
13
+ * have had effects.
14
+ */
15
+ import { appendFile, chmod, mkdir, readdir, readFile, rm } from "node:fs/promises";
16
+ import { join } from "node:path";
17
+ import * as log from "../log.js";
18
+ import { writeFileAtomically } from "../shared/atomic-file.js";
19
+ import { createJsonlAppender } from "../shared/jsonl-appender.js";
20
+ import { errorMessage } from "../shared/text-utils.js";
21
+ import { isPlainObject } from "../shared/type-guards.js";
22
+ import { isConversationId, newId } from "./ids.js";
23
+ import { isTerminal, nowSeconds } from "./response-record.js";
24
+ const RESTART_MESSAGE = "服务重启,回合被中断。";
25
+ const MAX_SNAPSHOT_PENDING_BYTES = 128 * 1024 * 1024;
26
+ export class WebApiStore {
27
+ constructor(dir) {
28
+ this.dir = dir;
29
+ this.conversations = new Map();
30
+ this.responses = new Map();
31
+ /** Response ids per conversation, in the order they were created. */
32
+ this.order = new Map();
33
+ /** The tail of the disk writes `saveResponse` has queued. */
34
+ this.writes = Promise.resolve();
35
+ this.appender = createJsonlAppender({
36
+ pathFor: (_now, record) => record.path,
37
+ recordForWrite: (record) => record.record,
38
+ // A snapshot carries its input and its continuation, each able to hold the full set of
39
+ // base64 images a request may attach; the default 8 MiB would refuse a legitimate one.
40
+ maxPendingBytes: MAX_SNAPSHOT_PENDING_BYTES,
41
+ });
42
+ }
43
+ /** Open the store, reading everything and failing the responses a previous run left unfinished. */
44
+ static async open(stateDir) {
45
+ const store = new WebApiStore(stateDir);
46
+ await mkdir(join(stateDir, "conversations"), { recursive: true, mode: 0o700 });
47
+ // `mkdir -p` applies the mode to the leaf only; the whole tree must be private.
48
+ await chmod(stateDir, 0o700);
49
+ await chmod(join(stateDir, "conversations"), 0o700);
50
+ await store.load();
51
+ return store;
52
+ }
53
+ conversationDir(id) {
54
+ return join(this.dir, "conversations", id);
55
+ }
56
+ async load() {
57
+ let names = [];
58
+ try {
59
+ names = await readdir(join(this.dir, "conversations"));
60
+ }
61
+ catch {
62
+ return;
63
+ }
64
+ for (const name of names.filter(isConversationId).sort()) {
65
+ const conversation = await this.readConversation(name);
66
+ if (!conversation)
67
+ continue;
68
+ this.conversations.set(conversation.id, conversation);
69
+ await this.readResponses(conversation.id);
70
+ }
71
+ await this.readResponses();
72
+ let interrupted = 0;
73
+ for (const record of this.responses.values()) {
74
+ if (isTerminal(record.status))
75
+ continue;
76
+ interrupted++;
77
+ record.status = "failed";
78
+ record.error = { code: "server_error", message: RESTART_MESSAGE };
79
+ record.completed_at = nowSeconds();
80
+ await this.appendSnapshot(record);
81
+ }
82
+ if (interrupted > 0) {
83
+ log.logWarn("webapi.store.interrupted", "Responses left unfinished by a restart were marked failed", {
84
+ fields: { count: interrupted },
85
+ });
86
+ }
87
+ }
88
+ async readConversation(id) {
89
+ try {
90
+ const parsed = JSON.parse(await readFile(join(this.conversationDir(id), "conversation.json"), "utf-8"));
91
+ if (isPlainObject(parsed) &&
92
+ parsed.id === id &&
93
+ typeof parsed.created_at === "number" &&
94
+ typeof parsed.owner === "string") {
95
+ return {
96
+ id,
97
+ created_at: parsed.created_at,
98
+ owner: parsed.owner,
99
+ metadata: isPlainObject(parsed.metadata) ? parsed.metadata : null,
100
+ };
101
+ }
102
+ }
103
+ catch (error) {
104
+ log.logWarn("webapi.store.conversation_unreadable", "Conversation record skipped", {
105
+ reason: errorMessage(error),
106
+ fields: { conversationId: id },
107
+ });
108
+ }
109
+ return undefined;
110
+ }
111
+ async readResponses(conversationId) {
112
+ const path = conversationId
113
+ ? join(this.conversationDir(conversationId), "responses.jsonl")
114
+ : join(this.dir, "standalone.jsonl");
115
+ let text;
116
+ try {
117
+ text = await readFile(path, "utf-8");
118
+ }
119
+ catch {
120
+ return;
121
+ }
122
+ const ids = [];
123
+ // A crash can leave a partial last line; end it, or the next snapshot would be glued onto it and lost.
124
+ if (text.length > 0 && !text.endsWith("\n")) {
125
+ await appendFile(path, "\n");
126
+ }
127
+ for (const line of text.split("\n")) {
128
+ if (!line.trim())
129
+ continue;
130
+ try {
131
+ const record = JSON.parse(line);
132
+ if (!isPlainObject(record) ||
133
+ typeof record.id !== "string" ||
134
+ (conversationId ? record.conversation_id !== conversationId : record.request_scoped !== true)) {
135
+ throw new Error("not a response snapshot");
136
+ }
137
+ if (!this.responses.has(record.id))
138
+ ids.push(record.id);
139
+ this.responses.set(record.id, record);
140
+ }
141
+ catch (error) {
142
+ log.logWarn("webapi.store.line_skipped", "Unreadable response snapshot skipped", {
143
+ reason: errorMessage(error),
144
+ fields: { conversationId },
145
+ });
146
+ }
147
+ }
148
+ if (conversationId)
149
+ this.order.set(conversationId, ids);
150
+ }
151
+ // ---- conversations ---------------------------------------------------------------------
152
+ async createConversation(owner, metadata, id = newId("conv")) {
153
+ const record = { id, created_at: nowSeconds(), metadata, owner };
154
+ this.conversations.set(record.id, record);
155
+ this.order.set(record.id, []);
156
+ await this.writeConversation(record);
157
+ return record;
158
+ }
159
+ getConversation(id) {
160
+ return this.conversations.get(id);
161
+ }
162
+ async updateConversationMetadata(id, metadata) {
163
+ const existing = this.conversations.get(id);
164
+ if (!existing)
165
+ throw new Error(`Unknown conversation ${id}`);
166
+ const updated = { ...existing, metadata };
167
+ await this.writeConversation(updated);
168
+ this.conversations.set(id, updated);
169
+ return updated;
170
+ }
171
+ /**
172
+ * Forget a conversation and its responses, and remove its directory. The index line in
173
+ * `responses.jsonl` stays: it is the operator's record, and it names an id that no longer resolves.
174
+ */
175
+ async deleteConversation(id) {
176
+ for (const responseId of this.order.get(id) ?? [])
177
+ this.responses.delete(responseId);
178
+ this.order.delete(id);
179
+ this.conversations.delete(id);
180
+ // Snapshots queued before the delete must not recreate the directory afterwards.
181
+ await this.writes;
182
+ await rm(this.conversationDir(id), { recursive: true, force: true });
183
+ }
184
+ async writeConversation(record) {
185
+ await writeFileAtomically(join(this.conversationDir(record.id), "conversation.json"), `${JSON.stringify(record)}\n`);
186
+ }
187
+ // ---- responses -------------------------------------------------------------------------
188
+ getResponse(id) {
189
+ return this.responses.get(id);
190
+ }
191
+ /** A conversation's responses, oldest first. */
192
+ listResponses(conversationId) {
193
+ return (this.order.get(conversationId) ?? []).flatMap((id) => {
194
+ const record = this.responses.get(id);
195
+ return record ? [record] : [];
196
+ });
197
+ }
198
+ latestResponseId(conversationId) {
199
+ return this.order.get(conversationId)?.at(-1);
200
+ }
201
+ /**
202
+ * Record a response's current state: the first call for an id also registers it in the conversation.
203
+ * Registration is immediate; the disk writes happen in call order, so the last snapshot on disk is
204
+ * always the last one saved (the first save also writes the index line, which would otherwise let a
205
+ * later snapshot overtake it).
206
+ */
207
+ saveResponse(record) {
208
+ if (record.request_scoped && record.store === false)
209
+ return Promise.resolve();
210
+ // A late snapshot of a deleted conversation's response (one that was settling) is dropped.
211
+ if (!record.request_scoped && !this.conversations.has(record.conversation_id))
212
+ return Promise.resolve();
213
+ const isNew = !this.responses.has(record.id);
214
+ this.responses.set(record.id, record);
215
+ if (isNew && !record.request_scoped) {
216
+ const ids = this.order.get(record.conversation_id) ?? [];
217
+ ids.push(record.id);
218
+ this.order.set(record.conversation_id, ids);
219
+ }
220
+ const snapshot = structuredClone(record);
221
+ const written = this.writes.then(async () => {
222
+ if (isNew) {
223
+ await this.appender.appendStrict({
224
+ path: join(this.dir, "responses.jsonl"),
225
+ record: { id: snapshot.id, conversation_id: snapshot.conversation_id },
226
+ });
227
+ }
228
+ await this.appendSnapshot(snapshot);
229
+ });
230
+ this.writes = written.catch(() => undefined);
231
+ return written;
232
+ }
233
+ appendSnapshot(record) {
234
+ return this.appender.appendStrict({
235
+ path: record.request_scoped
236
+ ? join(this.dir, "standalone.jsonl")
237
+ : join(this.conversationDir(record.conversation_id), "responses.jsonl"),
238
+ record,
239
+ });
240
+ }
241
+ async close() {
242
+ await this.writes;
243
+ await this.appender.close();
244
+ }
245
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Server-sent events for a response (spec 061, D20): `event:` is the event's `type`, `data:` its
3
+ * JSON, no `id:` and no `[DONE]`. A stream is a cursor over the response's event log, so a late
4
+ * reader (a resumed background stream) sees the same events in the same order as the first.
5
+ */
6
+ import type { ServerResponse } from "node:http";
7
+ import type { LiveResponse } from "./response-state.js";
8
+ export declare function openEventStream(raw: ServerResponse): void;
9
+ /**
10
+ * Pump `live`'s events from `fromSequence` to `raw` until the response ends or the client goes.
11
+ * Returns whether the response ended (as opposed to the client leaving first).
12
+ */
13
+ export declare function pumpEvents(live: LiveResponse, fromSequence: number, raw: ServerResponse): Promise<boolean>;
@@ -0,0 +1,76 @@
1
+ export function openEventStream(raw) {
2
+ raw.writeHead(200, {
3
+ "content-type": "text/event-stream; charset=utf-8",
4
+ "cache-control": "no-cache, no-transform",
5
+ connection: "keep-alive",
6
+ "x-accel-buffering": "no",
7
+ });
8
+ raw.flushHeaders();
9
+ }
10
+ function frame(event) {
11
+ return `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`;
12
+ }
13
+ /** Write one chunk, waiting for the socket to drain if it is full; `false` once the client is gone. */
14
+ async function write(raw, chunk) {
15
+ if (raw.destroyed || raw.writableEnded)
16
+ return false;
17
+ if (raw.write(chunk))
18
+ return true;
19
+ return new Promise((resolve) => {
20
+ const done = (ok) => {
21
+ raw.off("drain", onDrain);
22
+ raw.off("close", onClose);
23
+ resolve(ok);
24
+ };
25
+ const onDrain = () => done(true);
26
+ const onClose = () => done(false);
27
+ raw.once("drain", onDrain);
28
+ raw.once("close", onClose);
29
+ });
30
+ }
31
+ /**
32
+ * Pump `live`'s events from `fromSequence` to `raw` until the response ends or the client goes.
33
+ * Returns whether the response ended (as opposed to the client leaving first).
34
+ */
35
+ export async function pumpEvents(live, fromSequence, raw) {
36
+ const queue = [];
37
+ let ended = false;
38
+ let gone = false;
39
+ let wake;
40
+ const nudge = () => wake?.();
41
+ const unsubscribe = live.subscribe(fromSequence, {
42
+ onEvent: (event) => {
43
+ queue.push(event);
44
+ nudge();
45
+ },
46
+ onEnd: () => {
47
+ ended = true;
48
+ nudge();
49
+ },
50
+ });
51
+ const onClose = () => {
52
+ gone = true;
53
+ nudge();
54
+ };
55
+ raw.once("close", onClose);
56
+ try {
57
+ for (;;) {
58
+ while (queue.length > 0) {
59
+ if (!(await write(raw, frame(queue.shift()))))
60
+ return false;
61
+ }
62
+ if (ended)
63
+ return true;
64
+ if (gone)
65
+ return false;
66
+ await new Promise((resolve) => {
67
+ wake = resolve;
68
+ });
69
+ wake = undefined;
70
+ }
71
+ }
72
+ finally {
73
+ unsubscribe();
74
+ raw.off("close", onClose);
75
+ }
76
+ }
@@ -0,0 +1,43 @@
1
+ import type { ChannelContext } from "../channel/channel-context.js";
2
+ import type { Ingress } from "../channel/ingress.js";
3
+ import type { MediaSendResult, PushMessage, Transport, TransportPolicy, TurnInfo } from "../channel/transport.js";
4
+ import type { ConversationKind } from "../desk/types.js";
5
+ import type { SecurityLogEvent } from "../security/types.js";
6
+ import type { WebApiConfig } from "./config.js";
7
+ export interface WebApiTransportDeps {
8
+ config: WebApiConfig;
9
+ /** `<app home>/state/webapi` */
10
+ stateDir: string;
11
+ /** Where requests and refused requests are recorded (the security audit log). */
12
+ audit: (event: SecurityLogEvent) => void;
13
+ /** Test overrides. */
14
+ maxWebSocketMs?: number;
15
+ replayTtlMs?: number;
16
+ }
17
+ export declare class WebApiTransport implements Transport {
18
+ private readonly deps;
19
+ readonly name: "webapi";
20
+ readonly policy: TransportPolicy;
21
+ private service;
22
+ private server;
23
+ constructor(deps: WebApiTransportDeps);
24
+ get socketPath(): string;
25
+ private requireService;
26
+ start(ingress: Ingress): Promise<void>;
27
+ /**
28
+ * New requests are refused from now on (503), while connections stay open: a running response
29
+ * keeps streaming to its caller until the runtime has let the turn finish.
30
+ */
31
+ stopAccepting(): Promise<void>;
32
+ stop(): Promise<void>;
33
+ openTurn(turn: TurnInfo, opts: {
34
+ quiet: boolean;
35
+ }): ChannelContext;
36
+ push(channelId: string, message: PushMessage): Promise<boolean>;
37
+ dropped(_channelId: string, refs: string[]): void;
38
+ /** No download endpoint exists for a produced file, so `send_media` is not offered here. */
39
+ readonly sendsMedia = false;
40
+ sendMedia(): Promise<MediaSendResult>;
41
+ describe(channelId: string): string;
42
+ conversationKindOf(channelId: string): ConversationKind | undefined;
43
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The Web API transport (spec 061, D4/D12): the `Transport` the runtime holds for the OpenAI
3
+ * Responses-shaped API. A conversation is a `webapi:conv_…` channel, a request is one message to
4
+ * the runtime's ingress, a Response is what that message turned into. The runtime never learns
5
+ * about HTTP; this file and its neighbours never learn what a command means.
6
+ */
7
+ import { join } from "node:path";
8
+ import { conversationIdOf } from "./ids.js";
9
+ import { WebApiServer } from "./server.js";
10
+ import { WebApiService } from "./service.js";
11
+ import { WebApiStore } from "./store.js";
12
+ /** The longest a unix socket path may be on Linux (108) with room to spare; macOS allows 104. */
13
+ const MAX_SOCKET_PATH_BYTES = 100;
14
+ export class WebApiTransport {
15
+ constructor(deps) {
16
+ this.deps = deps;
17
+ this.name = "webapi";
18
+ this.policy = { whenBusy: "queue", textControlCommands: false };
19
+ /** No download endpoint exists for a produced file, so `send_media` is not offered here. */
20
+ this.sendsMedia = false;
21
+ }
22
+ get socketPath() {
23
+ return join(this.deps.stateDir, "api.sock");
24
+ }
25
+ requireService() {
26
+ if (!this.service)
27
+ throw new Error("The Web API transport is not started");
28
+ return this.service;
29
+ }
30
+ async start(ingress) {
31
+ if (this.deps.config.socket && Buffer.byteLength(this.socketPath) > MAX_SOCKET_PATH_BYTES) {
32
+ throw new Error(`The Web API socket path ${this.socketPath} is too long for a unix socket; use a shorter PIPICLAW_HOME.`);
33
+ }
34
+ const store = await WebApiStore.open(this.deps.stateDir);
35
+ const service = new WebApiService({
36
+ store,
37
+ ...(this.deps.replayTtlMs ? { replayTtlMs: this.deps.replayTtlMs } : {}),
38
+ });
39
+ service.setIngress(ingress);
40
+ const server = new WebApiServer({
41
+ config: this.deps.config,
42
+ service,
43
+ socketPath: this.socketPath,
44
+ audit: this.deps.audit,
45
+ ...(this.deps.maxWebSocketMs ? { maxWebSocketMs: this.deps.maxWebSocketMs } : {}),
46
+ });
47
+ try {
48
+ await server.start();
49
+ }
50
+ catch (error) {
51
+ // Nothing is kept on `this`, so `stop()` could not reach these: release them here.
52
+ await service.shutdown().catch(() => undefined);
53
+ await store.close().catch(() => undefined);
54
+ throw error;
55
+ }
56
+ this.service = service;
57
+ this.server = server;
58
+ }
59
+ /**
60
+ * New requests are refused from now on (503), while connections stay open: a running response
61
+ * keeps streaming to its caller until the runtime has let the turn finish.
62
+ */
63
+ async stopAccepting() {
64
+ this.service?.stopAccepting();
65
+ }
66
+ async stop() {
67
+ const server = this.server;
68
+ const service = this.service;
69
+ this.server = undefined;
70
+ this.service = undefined;
71
+ await server?.stop();
72
+ await service?.shutdown();
73
+ await service?.store.close();
74
+ }
75
+ openTurn(turn, opts) {
76
+ return this.requireService().openTurn(turn, opts);
77
+ }
78
+ async push(channelId, message) {
79
+ return this.service?.push(channelId, message) ?? false;
80
+ }
81
+ dropped(_channelId, refs) {
82
+ this.service?.dropped(refs);
83
+ }
84
+ async sendMedia() {
85
+ return {
86
+ ok: false,
87
+ error: "This channel cannot receive attachments. Tell the user the file's path on the server instead.",
88
+ };
89
+ }
90
+ describe(channelId) {
91
+ const conversationId = conversationIdOf(channelId);
92
+ const owner = conversationId ? this.service?.store.getConversation(conversationId)?.owner : undefined;
93
+ if (owner === "local")
94
+ return "终端";
95
+ return owner ? `API「${owner}」` : "API 会话";
96
+ }
97
+ conversationKindOf(channelId) {
98
+ return conversationIdOf(channelId) ? "webapi" : undefined;
99
+ }
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.9.4",
3
+ "version": "0.9.5-beta.2",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -55,23 +55,29 @@
55
55
  "@earendil-works/pi-ai": "1.2.0",
56
56
  "@earendil-works/pi-coding-agent": "1.2.0",
57
57
  "@earendil-works/pi-tui": "1.2.0",
58
+ "@fastify/rate-limit": "11.2.1",
59
+ "@fastify/websocket": "11.3.4",
58
60
  "@mozilla/readability": "^0.6.0",
59
61
  "axios": "^1.7.0",
60
62
  "croner": "^9.1.0",
61
63
  "diff": "^8.0.2",
62
64
  "dingtalk-stream": "2.1.5",
65
+ "fastify": "5.12.5",
63
66
  "http-proxy-agent": "^7.0.2",
64
67
  "https-proxy-agent": "^7.0.6",
65
68
  "jsdom": "^26.1.0",
69
+ "openai": "7.32.0",
66
70
  "proxy-from-env": "^1.1.0",
67
71
  "socks-proxy-agent": "^8.0.5",
68
72
  "typebox": "^1.3.7",
69
- "undici": "^8.10.0"
73
+ "undici": "^8.10.0",
74
+ "ws": "8.22.0"
70
75
  },
71
76
  "devDependencies": {
72
77
  "@biomejs/biome": "2.3.5",
73
78
  "@types/jsdom": "^28.0.1",
74
79
  "@types/node": "^24.3.0",
80
+ "@types/ws": "8.18.2",
75
81
  "@vitest/coverage-v8": "^3.2.4",
76
82
  "knip": "^6.24.0",
77
83
  "typescript": "^5.7.3",
@@ -1,16 +0,0 @@
1
- export declare function isChannelId(value: string): boolean;
2
- export declare function getChannelDirName(channelId: string): string;
3
- export declare function getChannelDir(baseDir: string, channelId: string): string;
4
- /**
5
- * Collapse ids that name the same channel directory, keeping the first spelling offered.
6
- *
7
- * Background workers assemble their channel list from several sources, and only some of them
8
- * store a real id: `CHANNELS.md` and the live runner map do, while a directory listing (of the
9
- * workspace, or of the maintenance state dir) can only report the *escaped* name, which cannot
10
- * be turned back into the id it came from. Left alone, one channel then appears twice — once
11
- * under its real id and once under a spelling no transport can deliver to — and every unit of
12
- * work for it runs twice. Callers pass their sources most-authoritative-first; this keeps that
13
- * spelling and drops the rest.
14
- */
15
- export declare function dedupeChannelIdsByDirectory(channelIds: Iterable<string>): string[];
16
- export declare function ensureChannelDir(baseDir: string, channelId: string): string;
@@ -1,53 +0,0 @@
1
- import { mkdirSync } from "fs";
2
- import { join } from "path";
3
- /**
4
- * Every channel id is `dm_<staffId>` or `group_<conversationId>`.
5
- *
6
- * The remainder is deliberately unconstrained apart from path-safety: a DingTalk
7
- * conversation id is base64 and routinely contains `/` and `=`, so the charset allowlist this
8
- * check used to carry (`[A-Za-z0-9._:-]+`) rejected every real group. Anything that filtered
9
- * ids through it — workspace scans, the maintenance scheduler's known-channel filter — silently
10
- * dropped those channels.
11
- *
12
- * What still has to hold is that an id can never escape the directory it names. `getChannelDir`
13
- * folds `/` into `__`, but not every consumer escapes (the memory-maintenance state file
14
- * interpolates the id straight into a filename), so a `..` segment and the path separators that
15
- * survive escaping are rejected here, once, for everyone.
16
- */
17
- const CHANNEL_ID_PATTERN = /^(dm|group)_[^\0\\]+$/;
18
- export function isChannelId(value) {
19
- if (!CHANNEL_ID_PATTERN.test(value))
20
- return false;
21
- return !value.split("/").includes("..");
22
- }
23
- export function getChannelDirName(channelId) {
24
- return channelId.replaceAll("/", "__");
25
- }
26
- export function getChannelDir(baseDir, channelId) {
27
- return join(baseDir, getChannelDirName(channelId));
28
- }
29
- /**
30
- * Collapse ids that name the same channel directory, keeping the first spelling offered.
31
- *
32
- * Background workers assemble their channel list from several sources, and only some of them
33
- * store a real id: `CHANNELS.md` and the live runner map do, while a directory listing (of the
34
- * workspace, or of the maintenance state dir) can only report the *escaped* name, which cannot
35
- * be turned back into the id it came from. Left alone, one channel then appears twice — once
36
- * under its real id and once under a spelling no transport can deliver to — and every unit of
37
- * work for it runs twice. Callers pass their sources most-authoritative-first; this keeps that
38
- * spelling and drops the rest.
39
- */
40
- export function dedupeChannelIdsByDirectory(channelIds) {
41
- const byDirectory = new Map();
42
- for (const channelId of channelIds) {
43
- const dirName = getChannelDirName(channelId);
44
- if (!byDirectory.has(dirName))
45
- byDirectory.set(dirName, channelId);
46
- }
47
- return Array.from(byDirectory.values()).sort();
48
- }
49
- export function ensureChannelDir(baseDir, channelId) {
50
- const channelDir = getChannelDir(baseDir, channelId);
51
- mkdirSync(channelDir, { recursive: true });
52
- return channelDir;
53
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * `/project` — the human control path for a channel's project scope (spec 043, D7). Mirrors
3
- * `tasks/commands.ts`/`subagents/commands.ts`'s shape: pure-ish functions returning markdown, no
4
- * bot/event coupling. Mutations never reach the model.
5
- */
6
- type ProjectCommand = {
7
- action: "show";
8
- } | {
9
- action: "set";
10
- path: string;
11
- } | {
12
- action: "reset";
13
- };
14
- export interface HandleProjectCommandOptions {
15
- args: string;
16
- channelId: string;
17
- channelDir: string;
18
- appHomeDir: string;
19
- actor: "dingtalk-command" | "tui-command";
20
- /** True while a turn is in flight for this channel; blocks `set`/`reset` (D1.3/D4.2). */
21
- isBusy: () => boolean;
22
- /** Non-empty user-facing lines naming a running job/subagent that must finish or be cancelled
23
- * first (D4.3) — sleeping tasks are deliberately not included here. */
24
- listActiveBlockers: () => Promise<string[]> | string[];
25
- /** Runs after a successful commit so the caller can dispose its cached runner for this channel
26
- * and let the next access rebuild it under the new scope (D4.2). Not called on any failure path. */
27
- onScopeChanged?: () => Promise<void> | void;
28
- }
29
- /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
30
- export declare function parseProjectCommand(args: string): ProjectCommand;
31
- export declare function handleProjectCommand(options: HandleProjectCommandOptions): Promise<string>;
32
- export {};