@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
@@ -1,14 +1,13 @@
1
1
  /**
2
- * Inbound messages: acknowledge and deduplicate raw Stream frames, parse a robot message into a
3
- * `ChannelEvent`, apply the sender allow-list, resolve image attachments, and hand the event to the
4
- * bot's routing. The per-channel ingestion queue lives here so an attachment download can never be
5
- * overtaken by a later message on the same channel.
2
+ * Inbound messages: acknowledge and deduplicate raw Stream frames, parse a robot message, apply the
3
+ * sender allow-list, download image attachments, and hand the result to the runtime's ingress. The
4
+ * per-channel ingestion queue lives here so an attachment download can never be overtaken by a
5
+ * later message on the same channel.
6
6
  */
7
7
  import type { DWClientDownStream } from "dingtalk-stream";
8
- import type { InboundImage } from "../channel/channel-event.js";
8
+ import type { InboundAttachment, Ingress } from "../channel/ingress.js";
9
9
  import type { DingTalkConfig } from "./config.js";
10
10
  import type { ConversationMetaStore } from "./conversation-meta.js";
11
- import type { DingTalkEvent, DingTalkHandler } from "./handler.js";
12
11
  import { type ParsedInboundMessage } from "./inbound-media.js";
13
12
  interface DingTalkIncomingMessage {
14
13
  msgId?: string;
@@ -29,19 +28,19 @@ interface DingTalkIncomingMessage {
29
28
  downloadCode?: string;
30
29
  };
31
30
  }
31
+ /** What the DingTalk side needs from the runtime: the one door inbound messages go through. */
32
+ export type DingTalkIngress = Pick<Ingress, "receive">;
32
33
  export interface InboundMessagesDeps {
33
34
  config: DingTalkConfig;
34
- handler: DingTalkHandler;
35
+ ingress: DingTalkIngress;
35
36
  conversations: ConversationMetaStore;
36
37
  isStopped: () => boolean;
37
38
  /** Acknowledge a downstream frame to DingTalk. */
38
39
  ack: (messageId: string) => void;
39
- resolveInboundAttachments: (channelId: string, parsed: ParsedInboundMessage) => Promise<{
40
+ collectAttachments: (parsed: ParsedInboundMessage) => Promise<{
40
41
  text: string;
41
- images: InboundImage[];
42
+ attachments: InboundAttachment[];
42
43
  }>;
43
- /** Command / busy / `/new` routing for a built event (the bot's `routeInboundEvent`). */
44
- routeInboundEvent: (event: DingTalkEvent) => Promise<void>;
45
44
  }
46
45
  export declare class InboundMessages {
47
46
  private deps;
@@ -2,6 +2,7 @@ import * as log from "../log.js";
2
2
  import { createSerialQueue } from "../shared/serial-queue.js";
3
3
  import { errorMessage } from "../shared/text-utils.js";
4
4
  import { isRecord } from "../shared/type-guards.js";
5
+ import { dingtalkDmChannelId, dingtalkGroupChannelId } from "./channel-ids.js";
5
6
  import { parseInboundMessage } from "./inbound-media.js";
6
7
  export class InboundMessages {
7
8
  constructor(deps) {
@@ -64,7 +65,7 @@ export class InboundMessages {
64
65
  return { status: "SUCCESS", message: "OK" };
65
66
  }
66
67
  async onStreamMessage(data) {
67
- const { config, handler } = this.deps;
68
+ const { config, ingress } = this.deps;
68
69
  if (this.deps.isStopped()) {
69
70
  return;
70
71
  }
@@ -87,16 +88,15 @@ export class InboundMessages {
87
88
  }
88
89
  }
89
90
  // Determine channel ID
90
- const channelId = conversationType === "2" ? `group_${conversationId}` : `dm_${senderId}`;
91
- // Parsing above is free; resolving image attachments below is a real network round-trip.
92
- // Serialize the whole "resolve attachments → build event → route" unit per channel (spec
93
- // 049 D3): without this, a message needing a download can be overtaken, in delivery order,
94
- // by a later download-free message on the same channel — nothing upstream of
95
- // `enqueueStreamMessage` otherwise waits on anything asynchronous.
91
+ const channelId = conversationType === "2" ? dingtalkGroupChannelId(conversationId) : dingtalkDmChannelId(senderId);
92
+ // Parsing above is free; downloading image attachments below is a real network round-trip.
93
+ // Serialize the whole "download attachments → hand over" unit per channel (spec 049 D3):
94
+ // without this, a message needing a download can be overtaken, in delivery order, by a later
95
+ // download-free message on the same channel.
96
96
  this.pendingInboundIngestCount++;
97
97
  try {
98
98
  await this.inboundIngestQueue.run(channelId, async () => {
99
- const { text: content, images } = await this.deps.resolveInboundAttachments(channelId, parsed);
99
+ const { text: content, attachments } = await this.deps.collectAttachments(parsed);
100
100
  log.logEvent("info", "runtime.dingtalk.message_received", "Accepted incoming message", {
101
101
  ctx: { channelId, userName: senderName },
102
102
  fields: { messageType: conversationType === "2" ? "group" : "dm", messageLength: content.length },
@@ -111,23 +111,16 @@ export class InboundMessages {
111
111
  conversationType,
112
112
  senderId,
113
113
  });
114
- // The one place a real person's message is seen before command/busy routing splits
115
- // the path, so the channel index counts every human message and no synthetic wake.
116
- handler.noteChannelActivity?.({ channelId, name: channelName, at: Date.now() });
117
- // Build event
118
- const event = {
119
- type: conversationType === "2" ? "group" : "dm",
114
+ const message = {
120
115
  channelId,
121
- ts: Date.now().toString(),
122
116
  user: senderId,
123
117
  userName: senderName,
124
118
  text: content,
125
- conversationId,
126
- conversationType,
119
+ ts: Date.now().toString(),
127
120
  ...(channelName ? { channelName } : {}),
128
- ...(images.length > 0 ? { images } : {}),
121
+ ...(attachments.length > 0 ? { attachments } : {}),
129
122
  };
130
- await this.deps.routeInboundEvent(event);
123
+ await ingress.receive(message);
131
124
  });
132
125
  }
133
126
  finally {
@@ -1,12 +1,10 @@
1
- import type { MediaSendResult, OutboundMedia } from "../channel/channel-context.js";
2
- import type { InboundImage } from "../channel/channel-event.js";
1
+ import type { InboundAttachment } from "../channel/ingress.js";
2
+ import type { MediaSendResult, OutboundMedia } from "../channel/transport.js";
3
3
  import { type ConversationMeta } from "./api.js";
4
4
  import type { DingTalkConfig } from "./config.js";
5
- import type { DingTalkHandler } from "./handler.js";
6
5
  import { type ParsedInboundMessage } from "./inbound-media.js";
7
6
  export interface DingTalkMediaDeps {
8
7
  config: DingTalkConfig;
9
- handler: DingTalkHandler;
10
8
  getAccessToken: () => Promise<string | null>;
11
9
  getConversationMeta: (channelId: string) => ConversationMeta | null;
12
10
  sendRobotMessage: (meta: ConversationMeta, msgKey: string, msgParam: string) => Promise<boolean>;
@@ -50,17 +48,17 @@ export declare class DingTalkMedia {
50
48
  data: Buffer;
51
49
  } | null>;
52
50
  /**
53
- * Resolve one parsed message's image credentials into persisted `InboundImage`s and a text
54
- * with every `[图片N]` marker either left as-is (success) or replaced with a reason (spec 049
55
- * D8): a download failure, an unrecognized format, an oversized file, or a message that
56
- * simply carried more images than `MAX_INBOUND_IMAGES_PER_MESSAGE` allows. A failure on one
57
- * image never drops the rest of the message — only that one marker changes.
51
+ * Download one parsed message's images and say, in the text, what became of the ones that did
52
+ * not make it (spec 049 D8): a failed download, an oversized file, or more images than
53
+ * `MAX_INBOUND_IMAGES_PER_MESSAGE` allows. A failure on one image never drops the rest of the
54
+ * message — only that one `[图片N]` marker changes. The bytes of the others go to the runtime as
55
+ * attachments (it persists them under the bound desk and settles the remaining markers).
58
56
  *
59
57
  * No-op (no network call at all) when the message carries no image credentials, so a plain
60
58
  * text message never pays for this method's existence.
61
59
  */
62
- resolveInboundAttachments(channelId: string, parsed: ParsedInboundMessage): Promise<{
60
+ collectInboundAttachments(parsed: ParsedInboundMessage): Promise<{
63
61
  text: string;
64
- images: InboundImage[];
62
+ attachments: InboundAttachment[];
65
63
  }>;
66
64
  }
@@ -1,14 +1,15 @@
1
1
  /**
2
- * Media (image / file) for DingTalk: outbound delivery (`MediaSender` contract), and the two-step
3
- * inbound download plus the per-message attachment resolution built on it (spec 049).
2
+ * Media (image / file) for DingTalk: outbound delivery, and the two-step inbound download plus the
3
+ * per-message attachment collection built on it (spec 049).
4
4
  */
5
5
  import axios from "axios";
6
+ import { MAX_INBOUND_IMAGE_BYTES, MAX_INBOUND_IMAGES_PER_MESSAGE } from "../channel/attachments.js";
6
7
  import * as log from "../log.js";
7
8
  import { errorMessage } from "../shared/text-utils.js";
8
9
  import { isRecord } from "../shared/type-guards.js";
9
10
  import { formatSize } from "../tools/truncate.js";
10
11
  import { DINGTALK_API, DINGTALK_OAPI, http } from "./api.js";
11
- import { MAX_INBOUND_IMAGE_BYTES, MAX_INBOUND_IMAGES_PER_MESSAGE, MEDIA_DOWNLOAD_TIMEOUT_MS, sniffImageMimeType, } from "./inbound-media.js";
12
+ import { MEDIA_DOWNLOAD_TIMEOUT_MS } from "./inbound-media.js";
12
13
  // DingTalk caps robot image messages at 1MB and file messages at 20MB. We reject
13
14
  // oversized files before spending an upload round-trip on a request the API rejects.
14
15
  const MAX_IMAGE_BYTES = 1024 * 1024;
@@ -17,12 +18,12 @@ const MAX_FILE_BYTES = 20 * 1024 * 1024;
17
18
  const MEDIA_UPLOAD_TIMEOUT_MS = 60_000;
18
19
  // File extensions the `sampleFile` message type accepts (per DingTalk docs).
19
20
  const SUPPORTED_FILE_TYPES = new Set(["xlsx", "pdf", "zip", "rar", "doc", "docx", "ppt", "pptx", "csv", "txt"]);
20
- /** Lowercased extension without the dot ("Report.PDF" → "pdf"); "" when none. */
21
+ /** Lowercased extension without the desk ("Report.PDF" → "pdf"); "" when none. */
21
22
  function extractFileExtension(fileName) {
22
- const dot = fileName.lastIndexOf(".");
23
- if (dot < 0 || dot === fileName.length - 1)
23
+ const desk = fileName.lastIndexOf(".");
24
+ if (desk < 0 || desk === fileName.length - 1)
24
25
  return "";
25
- return fileName.slice(dot + 1).toLowerCase();
26
+ return fileName.slice(desk + 1).toLowerCase();
26
27
  }
27
28
  export class DingTalkMedia {
28
29
  constructor(deps) {
@@ -160,21 +161,21 @@ export class DingTalkMedia {
160
161
  }
161
162
  }
162
163
  /**
163
- * Resolve one parsed message's image credentials into persisted `InboundImage`s and a text
164
- * with every `[图片N]` marker either left as-is (success) or replaced with a reason (spec 049
165
- * D8): a download failure, an unrecognized format, an oversized file, or a message that
166
- * simply carried more images than `MAX_INBOUND_IMAGES_PER_MESSAGE` allows. A failure on one
167
- * image never drops the rest of the message — only that one marker changes.
164
+ * Download one parsed message's images and say, in the text, what became of the ones that did
165
+ * not make it (spec 049 D8): a failed download, an oversized file, or more images than
166
+ * `MAX_INBOUND_IMAGES_PER_MESSAGE` allows. A failure on one image never drops the rest of the
167
+ * message — only that one `[图片N]` marker changes. The bytes of the others go to the runtime as
168
+ * attachments (it persists them under the bound desk and settles the remaining markers).
168
169
  *
169
170
  * No-op (no network call at all) when the message carries no image credentials, so a plain
170
171
  * text message never pays for this method's existence.
171
172
  */
172
- async resolveInboundAttachments(channelId, parsed) {
173
+ async collectInboundAttachments(parsed) {
173
174
  if (parsed.downloadCodes.length === 0) {
174
- return { text: parsed.text, images: [] };
175
+ return { text: parsed.text, attachments: [] };
175
176
  }
176
177
  let text = parsed.text;
177
- const images = [];
178
+ const attachments = [];
178
179
  const replaceMarker = (index, replacement) => {
179
180
  text = text.replace(`[图片${index + 1}]`, replacement);
180
181
  };
@@ -193,22 +194,8 @@ export class DingTalkMedia {
193
194
  replaceMarker(index, `[图片${marker}:文件过大(${formatSize(downloaded.data.byteLength)}),已丢弃]`);
194
195
  return;
195
196
  }
196
- const mimeType = sniffImageMimeType(downloaded.data);
197
- const persisted = await this.deps.handler.persistInboundImage?.(channelId, {
198
- data: downloaded.data,
199
- mimeType,
200
- });
201
- if (!persisted) {
202
- replaceMarker(index, `[图片${marker}:保存失败]`);
203
- return;
204
- }
205
- if (!mimeType) {
206
- // Persisted for the record, but never handed to a model — see the handler
207
- // contract's doc comment on `persistInboundImage`.
208
- replaceMarker(index, `[图片${marker}:格式不支持,已保存]`);
209
- }
210
- images[index] = persisted;
197
+ attachments[index] = { kind: "image", index: marker, data: downloaded.data };
211
198
  }));
212
- return { text, images: images.filter((image) => image !== undefined) };
199
+ return { text, attachments: attachments.filter((attachment) => !!attachment) };
213
200
  }
214
201
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * How a turn's events read as a DingTalk progress card: one line per entry, prefixed by what kind
3
+ * of entry it is (`➜` a tool call, `✦` thinking, `✕` an error, plain text for the model's own
4
+ * words).
5
+ */
6
+ export type ProgressEntryKind = "tool" | "thinking" | "error" | "assistant";
7
+ /** `""` when there is nothing to show. */
8
+ export declare function formatProgressEntry(kind: ProgressEntryKind, text: string): string;
@@ -0,0 +1,20 @@
1
+ function sanitizeProgressText(text) {
2
+ return text.replace(//g, "").replace(/\r/g, "").trim();
3
+ }
4
+ /** `""` when there is nothing to show. */
5
+ export function formatProgressEntry(kind, text) {
6
+ const cleaned = sanitizeProgressText(text);
7
+ if (!cleaned)
8
+ return "";
9
+ const normalized = cleaned.replace(/\n+/g, " ").trim();
10
+ switch (kind) {
11
+ case "tool":
12
+ return `➜ ${normalized}`;
13
+ case "thinking":
14
+ return `✦ ${normalized}`;
15
+ case "error":
16
+ return `✕ ${normalized}`;
17
+ case "assistant":
18
+ return normalized;
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * DingTalk's delivery presets. `channel.json`'s `dingtalk.responseMode` picks how a turn is shown;
3
+ * the two derived settings below are all the delivery code ever branches on.
4
+ */
5
+ /** How progress is surfaced during a turn. */
6
+ export type ProgressStyle = "full" | "rolling" | "none";
7
+ /** How the final answer is delivered. */
8
+ export type FinalDelivery = "plain" | "card";
9
+ export type ResponseMode = "full_progress_then_plain_final" | "rolling_progress_then_plain_final" | "final_card_only";
10
+ export declare function progressStyleOf(mode: ResponseMode): ProgressStyle;
11
+ export declare function finalDeliveryOf(mode: ResponseMode): FinalDelivery;
12
+ export declare function isResponseModeConfig(value: unknown): value is ResponseMode;
13
+ export declare function normalizeResponseMode(value: unknown): ResponseMode;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * DingTalk's delivery presets. `channel.json`'s `dingtalk.responseMode` picks how a turn is shown;
3
+ * the two derived settings below are all the delivery code ever branches on.
4
+ */
5
+ const RESPONSE_MODE_VALUES = [
6
+ "full_progress_then_plain_final",
7
+ "rolling_progress_then_plain_final",
8
+ "final_card_only",
9
+ ];
10
+ export function progressStyleOf(mode) {
11
+ if (mode === "final_card_only")
12
+ return "none";
13
+ if (mode === "rolling_progress_then_plain_final")
14
+ return "rolling";
15
+ return "full";
16
+ }
17
+ export function finalDeliveryOf(mode) {
18
+ return mode === "final_card_only" ? "card" : "plain";
19
+ }
20
+ export function isResponseModeConfig(value) {
21
+ return typeof value === "string" && RESPONSE_MODE_VALUES.includes(value);
22
+ }
23
+ export function normalizeResponseMode(value) {
24
+ if (value === undefined) {
25
+ return "full_progress_then_plain_final";
26
+ }
27
+ if (isResponseModeConfig(value)) {
28
+ return value;
29
+ }
30
+ throw new Error('Invalid `responseMode`: expected "full_progress_then_plain_final", "rolling_progress_then_plain_final", or "final_card_only".');
31
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The DingTalk transport (spec 061, D4/D27): the `Transport` the runtime holds. It composes the
3
+ * Stream bot (connection, inbound, cards, media, plain sends) with the per-turn delivery, and
4
+ * decides nothing about what a message means — that is the runtime's `Ingress`.
5
+ */
6
+ import type { ChannelContext } from "../channel/channel-context.js";
7
+ import type { Ingress } from "../channel/ingress.js";
8
+ import type { MediaSendResult, OutboundMedia, PushMessage, Transport, TransportPolicy, TurnInfo } from "../channel/transport.js";
9
+ import type { ConversationKind } from "../desk/types.js";
10
+ import { DingTalkBot } from "./bot.js";
11
+ import type { DingTalkConfig } from "./config.js";
12
+ import { type ArchiveBotResponse } from "./delivery.js";
13
+ export interface DingTalkTransportDeps {
14
+ config: DingTalkConfig;
15
+ /** Records a delivered answer in the channel's conversation log (log.jsonl). */
16
+ archiveBotResponse: ArchiveBotResponse;
17
+ /** Tests replace the bot to run the real delivery against a fake DingTalk API. */
18
+ createBot?: (ingress: Pick<Ingress, "receive">, config: DingTalkConfig) => DingTalkBot;
19
+ }
20
+ export declare class DingTalkTransport implements Transport {
21
+ private readonly deps;
22
+ readonly name: "dingtalk";
23
+ readonly policy: TransportPolicy;
24
+ readonly bot: DingTalkBot;
25
+ private ingress;
26
+ private stopping;
27
+ constructor(deps: DingTalkTransportDeps);
28
+ private requireIngress;
29
+ /**
30
+ * Begin the Stream connection. Not awaited: the first connect has its own timeout and keeps
31
+ * retrying in the background, and a daemon whose DingTalk is briefly unreachable still boots.
32
+ */
33
+ start(ingress: Ingress): Promise<void>;
34
+ /**
35
+ * Inbound stops with the Stream connection. Cards and plain sends go over HTTP and keep working,
36
+ * so there is nothing left for `stop` to close.
37
+ */
38
+ stopAccepting(): Promise<void>;
39
+ stop(): Promise<void>;
40
+ openTurn(turn: TurnInfo, opts: {
41
+ quiet: boolean;
42
+ }): ChannelContext;
43
+ push(channelId: string, message: PushMessage): Promise<boolean>;
44
+ sendMedia(channelId: string, media: OutboundMedia): Promise<MediaSendResult>;
45
+ describe(channelId: string, knownName?: string): string;
46
+ conversationKindOf(channelId: string): ConversationKind | undefined;
47
+ }
@@ -0,0 +1,71 @@
1
+ import { DingTalkBot } from "./bot.js";
2
+ import { describeDingTalkChannel, parseDingTalkChannelId } from "./channel-ids.js";
3
+ import { createDingTalkContext } from "./delivery.js";
4
+ export class DingTalkTransport {
5
+ constructor(deps) {
6
+ this.deps = deps;
7
+ this.name = "dingtalk";
8
+ const ingress = {
9
+ receive: (message) => this.requireIngress().receive(message),
10
+ };
11
+ this.bot = deps.createBot ? deps.createBot(ingress, deps.config) : new DingTalkBot(ingress, deps.config);
12
+ this.policy = { whenBusy: this.bot.busyMessageDefault, textControlCommands: true };
13
+ }
14
+ requireIngress() {
15
+ if (!this.ingress)
16
+ throw new Error("DingTalk transport received a message before it was started");
17
+ return this.ingress;
18
+ }
19
+ /**
20
+ * Begin the Stream connection. Not awaited: the first connect has its own timeout and keeps
21
+ * retrying in the background, and a daemon whose DingTalk is briefly unreachable still boots.
22
+ */
23
+ async start(ingress) {
24
+ this.ingress = ingress;
25
+ void this.bot.start();
26
+ }
27
+ /**
28
+ * Inbound stops with the Stream connection. Cards and plain sends go over HTTP and keep working,
29
+ * so there is nothing left for `stop` to close.
30
+ */
31
+ stopAccepting() {
32
+ this.stopping ??= this.bot.stop();
33
+ return this.stopping;
34
+ }
35
+ stop() {
36
+ return this.stopAccepting();
37
+ }
38
+ openTurn(turn, opts) {
39
+ const releaseConnection = this.bot.holdConnection();
40
+ const inner = createDingTalkContext(turn, this.bot, this.deps.archiveBotResponse, opts.quiet);
41
+ return {
42
+ emit: (event) => inner.emit(event),
43
+ finish: async (outcome) => {
44
+ try {
45
+ await inner.finish(outcome);
46
+ }
47
+ finally {
48
+ releaseConnection();
49
+ }
50
+ },
51
+ };
52
+ }
53
+ push(channelId, message) {
54
+ const opts = message.title !== undefined || message.markdown !== undefined
55
+ ? {
56
+ ...(message.title !== undefined ? { title: message.title } : {}),
57
+ ...(message.markdown !== undefined ? { markdown: message.markdown } : {}),
58
+ }
59
+ : undefined;
60
+ return this.bot.sendPlain(channelId, message.text, opts);
61
+ }
62
+ sendMedia(channelId, media) {
63
+ return this.bot.sendMedia(channelId, media);
64
+ }
65
+ describe(channelId, knownName) {
66
+ return describeDingTalkChannel(channelId, knownName);
67
+ }
68
+ conversationKindOf(channelId) {
69
+ return parseDingTalkChannelId(channelId)?.kind;
70
+ }
71
+ }
@@ -1,7 +1,12 @@
1
+ import type { ChannelDescription } from "../channel/channel-id.js";
1
2
  export interface HandleEventsCommandOptions {
2
3
  args: string;
3
- workspaceDir: string;
4
+ /** The asking channel's desk: its `events/` and its history records are the whole scope. */
5
+ desk: string;
6
+ deskDir: string;
4
7
  historyPath: string;
8
+ /** Names a delivery channel and says whether it is still bound to this desk. */
9
+ describeChannel: (channelId: string) => ChannelDescription;
5
10
  }
6
11
  type EventsCommand = {
7
12
  action: "list";
@@ -18,7 +23,7 @@ type EventsCommand = {
18
23
  /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
19
24
  export declare function parseEventsCommand(args: string): EventsCommand;
20
25
  export declare function normalizeEventName(name: string): string;
21
- export declare function resolveEventPath(workspaceDir: string, name: string): {
26
+ export declare function resolveEventPath(deskDir: string, name: string): {
22
27
  eventName: string;
23
28
  eventPath: string;
24
29
  };
@@ -1,6 +1,6 @@
1
1
  /**
2
- * `/events`: list, show, delete and history of scheduled events, confined to `workspace/events/` and
3
- * the event history.
2
+ * `/events`: list, show, delete and history of one desk's scheduled events, confined to
3
+ * `<desk>/events/` and that desk's slice of the event history (spec 058, D14).
4
4
  */
5
5
  import { existsSync } from "fs";
6
6
  import { readdir, readFile, unlink } from "fs/promises";
@@ -44,8 +44,8 @@ export function parseEventsCommand(args) {
44
44
  }
45
45
  throw new Error(`未知子命令 \`${action}\`。`);
46
46
  }
47
- function eventsDir(workspaceDir) {
48
- return join(workspaceDir, "events");
47
+ function eventsDir(deskDir) {
48
+ return join(deskDir, "events");
49
49
  }
50
50
  const SAFE_ID_OPTIONS = { suffix: ".json", pattern: EVENT_NAME_PATTERN, label: "event name" };
51
51
  // English on purpose: shared with the model-facing `event_manage` tool (src/tools/event-manage.ts),
@@ -53,15 +53,20 @@ const SAFE_ID_OPTIONS = { suffix: ".json", pattern: EVENT_NAME_PATTERN, label: "
53
53
  export function normalizeEventName(name) {
54
54
  return normalizeSafeId(name, SAFE_ID_OPTIONS);
55
55
  }
56
- export function resolveEventPath(workspaceDir, name) {
57
- const { id: eventName, path: eventPath } = resolveSafeIdPath(eventsDir(workspaceDir), name, SAFE_ID_OPTIONS);
56
+ export function resolveEventPath(deskDir, name) {
57
+ const { id: eventName, path: eventPath } = resolveSafeIdPath(eventsDir(deskDir), name, SAFE_ID_OPTIONS);
58
58
  return { eventName, eventPath };
59
59
  }
60
60
  function clipText(text, maxChars = TEXT_PREVIEW_MAX_CHARS) {
61
61
  return sharedClipText(text, maxChars, { headRatio: 1, omitHint: "...", collapseWhitespace: true });
62
62
  }
63
- function formatEventSummary(name, event) {
64
- const lines = [`**${name}**`, `- 类型:${event.type}`, `- 频道(channelId):${event.channelId}`];
63
+ function formatEventSummary(name, event, describeChannel) {
64
+ const channel = describeChannel(event.channelId);
65
+ const lines = [
66
+ `**${name}**`,
67
+ `- 类型:${event.type}`,
68
+ `- 投递频道(channelId):${channel.label}${channel.boundHere ? "" : "(已暂停:投递频道未绑定到本工位)"}`,
69
+ ];
65
70
  if (event.type === "one-shot") {
66
71
  lines.push(`- 触发时间:${event.at}`);
67
72
  }
@@ -96,8 +101,8 @@ function describeEventProblem(error, name) {
96
101
  return `定义无效,用 \`/events show ${name}\` 查看`;
97
102
  }
98
103
  const EMPTY_EVENTS = "暂无定时事件。\n在对话里告诉我要定时做什么,我会创建事件。";
99
- async function listEvents(workspaceDir) {
100
- const dir = eventsDir(workspaceDir);
104
+ async function listEvents(options) {
105
+ const dir = eventsDir(options.deskDir);
101
106
  if (!existsSync(dir))
102
107
  return EMPTY_EVENTS;
103
108
  const filenames = (await readdir(dir)).filter((filename) => filename.endsWith(".json")).sort();
@@ -112,7 +117,7 @@ async function listEvents(workspaceDir) {
112
117
  // The same definition rules the watcher applies, so "listed as fine" means "will run".
113
118
  // The lead-time rule is creation-only (an overdue one-shot is a legitimate recovery).
114
119
  validateScheduledEvent(event, { enforceOneShotLead: false });
115
- blocks.push(formatEventSummary(name, event));
120
+ blocks.push(formatEventSummary(name, event, options.describeChannel));
116
121
  }
117
122
  catch (error) {
118
123
  blocks.push(`**${name}**\n- ⚠️ 无效:${describeEventProblem(error, name)}`);
@@ -125,8 +130,8 @@ async function listEvents(workspaceDir) {
125
130
  function eventNotFound(eventName) {
126
131
  return `未找到事件 \`${eventName}\`。用 \`/events list\` 查看。`;
127
132
  }
128
- async function showEvent(workspaceDir, name) {
129
- const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
133
+ async function showEvent(options, name) {
134
+ const { eventName, eventPath } = resolveEventPath(options.deskDir, name);
130
135
  if (!existsSync(eventPath))
131
136
  return eventNotFound(eventName);
132
137
  const raw = await readFile(eventPath, "utf-8");
@@ -138,12 +143,20 @@ async function showEvent(workspaceDir, name) {
138
143
  // Show the bytes as they are: an unparseable file is exactly the case the user needs to see.
139
144
  body = raw;
140
145
  }
141
- return capReply(`**事件 ${eventName}**\n\n\`\`\`json\n${body}\n\`\`\``, {
146
+ let status = "";
147
+ try {
148
+ const channel = options.describeChannel(parseScheduledEventContent(raw, `${eventName}.json`).channelId);
149
+ status = `- 投递频道:${channel.label}${channel.boundHere ? "" : "(已暂停:投递频道未绑定到本工位)"}\n\n`;
150
+ }
151
+ catch {
152
+ // An unparseable file has no channel to describe; the raw body below says why.
153
+ }
154
+ return capReply(`**事件 ${eventName}**\n\n${status}\`\`\`json\n${body}\n\`\`\``, {
142
155
  nextStepHint: `完整文件在 \`${eventPath}\``,
143
156
  }).text;
144
157
  }
145
- async function deleteEvent(workspaceDir, name) {
146
- const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
158
+ async function deleteEvent(options, name) {
159
+ const { eventName, eventPath } = resolveEventPath(options.deskDir, name);
147
160
  if (!existsSync(eventPath))
148
161
  return eventNotFound(eventName);
149
162
  // Read before deleting so the reply carries what was removed (review 2026-08-24 §3.4):
@@ -151,7 +164,7 @@ async function deleteEvent(workspaceDir, name) {
151
164
  let summary;
152
165
  try {
153
166
  const event = parseScheduledEventContent(await readFile(eventPath, "utf-8"), `${eventName}.json`);
154
- summary = formatEventSummary(eventName, event);
167
+ summary = formatEventSummary(eventName, event, options.describeChannel);
155
168
  }
156
169
  catch {
157
170
  // Unparseable content is still safe to delete; just skip the summary.
@@ -203,7 +216,11 @@ function formatHistoryRecord(record) {
203
216
  bits.push(`详情:\`${clipText(record.reason.replace(/`/g, "'"))}\``);
204
217
  return `- ${bits.join(" · ")}`;
205
218
  }
206
- async function showHistory(historyPath, name) {
219
+ function belongsToDesk(record, options) {
220
+ return record.desk === options.desk;
221
+ }
222
+ async function showHistory(options, name) {
223
+ const { historyPath } = options;
207
224
  const eventName = name ? normalizeEventName(name) : undefined;
208
225
  const empty = eventName
209
226
  ? `暂无事件 \`${eventName}\` 的触发记录。\n事件触发后会记录在这里。`
@@ -217,6 +234,7 @@ async function showHistory(historyPath, name) {
217
234
  .filter(Boolean)
218
235
  .map(parseHistoryLine)
219
236
  .filter((record) => !!record)
237
+ .filter((record) => belongsToDesk(record, options))
220
238
  .filter((record) => !eventName || record.eventName === eventName)
221
239
  .slice(-DEFAULT_HISTORY_LIMIT)
222
240
  .reverse();
@@ -239,13 +257,13 @@ export async function handleEventsCommand(options) {
239
257
  try {
240
258
  switch (command.action) {
241
259
  case "list":
242
- return await listEvents(options.workspaceDir);
260
+ return await listEvents(options);
243
261
  case "show":
244
- return await showEvent(options.workspaceDir, command.name);
262
+ return await showEvent(options, command.name);
245
263
  case "delete":
246
- return await deleteEvent(options.workspaceDir, command.name);
264
+ return await deleteEvent(options, command.name);
247
265
  case "history":
248
- return await showHistory(options.historyPath, command.name);
266
+ return await showHistory(options, command.name);
249
267
  }
250
268
  }
251
269
  catch (error) {
@@ -0,0 +1,10 @@
1
+ /** Why an event's pre-action gate did not let the occurrence through: it blocked it, or it failed. */
2
+ export declare class EventPreActionError extends Error {
3
+ readonly kind: "blocked" | "failed";
4
+ readonly exitCode?: number;
5
+ readonly durationMs?: number;
6
+ constructor(kind: "blocked" | "failed", message: string, options?: {
7
+ exitCode?: number;
8
+ durationMs?: number;
9
+ });
10
+ }
@@ -0,0 +1,10 @@
1
+ /** Why an event's pre-action gate did not let the occurrence through: it blocked it, or it failed. */
2
+ export class EventPreActionError extends Error {
3
+ constructor(kind, message, options = {}) {
4
+ super(message);
5
+ this.name = "EventPreActionError";
6
+ this.kind = kind;
7
+ this.exitCode = options.exitCode;
8
+ this.durationMs = options.durationMs;
9
+ }
10
+ }