@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,99 @@
1
+ /**
2
+ * The channel plane's transport contract (spec 061, D4): what the runtime asks of a transport.
3
+ * A transport does two things — hand normalized inbound messages to the runtime's `Ingress`, and
4
+ * render the runtime's structured output in its own protocol. Everything after authorization
5
+ * (binding, commands, busy handling, queueing) is the runtime's, never a transport's.
6
+ */
7
+ import type { ConversationKind } from "../desk/types.js";
8
+ import type { ChannelContext } from "./channel-context.js";
9
+ import type { InboundImage } from "./channel-event.js";
10
+ import type { Ingress } from "./ingress.js";
11
+ export type TransportName = "dingtalk" | "webapi";
12
+ export interface TransportPolicy {
13
+ /** How a plain message is handled while its channel is busy. */
14
+ whenBusy: "steer" | "followUp" | "queue";
15
+ /** Whether the text `/stop`, `/steer` and `/followup` are accepted; a transport with its own control calls says false. */
16
+ textControlCommands: boolean;
17
+ }
18
+ /** What one turn is about; the transport needs it to find the right conversation to answer into. */
19
+ export interface TurnInfo {
20
+ channelId: string;
21
+ user: string;
22
+ userName?: string;
23
+ text: string;
24
+ images?: InboundImage[];
25
+ /** The transport's correlation reference (`InboundMessage.ref`); a wake has none. */
26
+ ref?: string;
27
+ ts: string;
28
+ context?: import("./turn-context.js").TurnContext;
29
+ }
30
+ export interface PushMessage {
31
+ text: string;
32
+ /** Names the message where the transport shows a title (DingTalk's conversation list). */
33
+ title?: string;
34
+ /** The text is already markdown (a command reply); a transport that would otherwise guess honours it. */
35
+ markdown?: boolean;
36
+ /** Answering this inbound message: the `ref` it carried. */
37
+ ref?: string;
38
+ }
39
+ /**
40
+ * A file the agent wants to push to a channel as a native attachment. Bytes travel in-band
41
+ * (`data`) so the sender is decoupled from where the file physically lives: the `send_media`
42
+ * tool reads it through its `Executor` (which may be remote) and hands over the bytes.
43
+ */
44
+ export interface OutboundMedia {
45
+ data: Buffer;
46
+ /** Display name shown to the recipient (e.g. "report.pdf"). */
47
+ fileName: string;
48
+ /** `image` renders inline; `file` is a downloadable attachment. */
49
+ kind: "image" | "file";
50
+ }
51
+ /** The `send_media` tool's exit: the channel's transport sends the file. */
52
+ export type SendMedia = (channelId: string, media: OutboundMedia) => Promise<MediaSendResult>;
53
+ export interface MediaSendResult {
54
+ ok: boolean;
55
+ /** Why it failed, written for the agent: it says what to do instead. */
56
+ error?: string;
57
+ }
58
+ export interface Transport {
59
+ readonly name: TransportName;
60
+ readonly policy: TransportPolicy;
61
+ /** Start receiving. `ingress` is the one place inbound messages go. */
62
+ start(ingress: Ingress): Promise<void>;
63
+ /**
64
+ * Shutdown, first half: take no new messages (`ingress` is not called afterwards), but keep
65
+ * delivering — turns already running still finish through `openTurn`/`push` while the runtime
66
+ * waits for them.
67
+ */
68
+ stopAccepting(): Promise<void>;
69
+ /** Shutdown, second half, once the turns are done: close every connection and release state. */
70
+ stop(): Promise<void>;
71
+ /**
72
+ * One turn's output port. A `quiet` turn shows no progress; only its answer is delivered.
73
+ * Every human message the ingress accepted (`started` or `queued`) gets exactly one `openTurn`
74
+ * and one `finish`, whether it runs the agent or only answers a command — unless it is
75
+ * `dropped` first, or the process ends.
76
+ */
77
+ openTurn(turn: TurnInfo, opts: {
78
+ quiet: boolean;
79
+ }): ChannelContext;
80
+ /** Outside any turn: command replies, receipts, task reports, wake-failure notices. Whether it was delivered. */
81
+ push(channelId: string, message: PushMessage): Promise<boolean>;
82
+ /**
83
+ * Messages that were queued behind a running turn were dropped without ever running (`/stop`,
84
+ * `/new`); `refs` are the `ref`s they carried. A transport that tracks each message to an end
85
+ * (the Web API's responses) closes them here; one that does not simply omits this.
86
+ */
87
+ dropped?(channelId: string, refs: string[]): void;
88
+ /**
89
+ * Whether the channel can receive files from `send_media`. Absent means it can; `false` keeps the
90
+ * tool (and its guidance) away from the model, rather than offering one that always fails.
91
+ */
92
+ readonly sendsMedia?: boolean;
93
+ /** The `send_media` tool's exit. */
94
+ sendMedia(channelId: string, media: OutboundMedia): Promise<MediaSendResult>;
95
+ /** How a user sees this channel in `/desk`, `/tasks`, `/events` and CHANNELS.md. */
96
+ describe(channelId: string, knownName?: string): string;
97
+ /** The conversation kind (`conversations/<kind>-<n>/`) this transport gives the channel; `undefined` if it is not its address. */
98
+ conversationKindOf(channelId: string): ConversationKind | undefined;
99
+ }
@@ -0,0 +1,23 @@
1
+ /** Structured input to one generation. History is context, never a sequence of new turns. */
2
+ export type ContextPart = {
3
+ type: "text";
4
+ text: string;
5
+ } | {
6
+ type: "image";
7
+ data: string;
8
+ mimeType: string;
9
+ };
10
+ export interface ContextMessage {
11
+ role: "user" | "assistant" | "system" | "developer";
12
+ content: ContextPart[];
13
+ phase?: "commentary" | "final_answer";
14
+ }
15
+ export interface TurnContext {
16
+ /**
17
+ * Imported before the generation, in place of a user prompt. Empty when the turn's own text and
18
+ * images are the input (a conversation's user message): it then runs as an ordinary channel turn.
19
+ */
20
+ messages: ContextMessage[];
21
+ /** Applies only to this generation, including its tool iterations. */
22
+ instructions?: string;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -3,8 +3,7 @@
3
3
  * examples, plus the parsing and usage/help rendering built on top of them.
4
4
  *
5
5
  * It lives in its own domain, not in `src/agent/`, because the catalog describes commands handled
6
- * in three different layers — the runtime (`/tasks`, `/events`, `/subagents`, `/project`,
7
- * `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
6
+ * in three different layers — the runtime (`/tasks`, `/events`, `/subagents`, `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
8
7
  * by all of them plus the TUI. Only the catalog and the reply shape are shared: each *handler*
9
8
  * still lives in the layer that owns the state it touches (`runtime/*-commands.ts`,
10
9
  * `memory/commands.ts`, `agent/session/command-extension.ts`). This file has no imports at all, so nothing
@@ -13,7 +12,7 @@
13
12
  * The user-facing copy conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
14
13
  * next to this file enforces rule 5 (the length budget).
15
14
  */
16
- export type BuiltInCommandName = "help" | "steer" | "followup" | "stop" | "events" | "tasks" | "status" | "usage" | "context" | "subagents" | "project" | "skills";
15
+ export type BuiltInCommandName = "help" | "steer" | "followup" | "stop" | "desk" | "events" | "tasks" | "status" | "usage" | "context" | "subagents" | "skills";
17
16
  /** The five transport commands handled by `ChannelRunner.handleBuiltinCommand`. */
18
17
  export type RunnerBuiltInCommandName = "help" | "stop" | "steer" | "followup" | "context";
19
18
  /**
@@ -64,7 +63,7 @@ export interface CommandSpec {
64
63
  /**
65
64
  * True for the built-ins `ChannelRunner.handleBuiltinCommand` handles directly (help/stop/
66
65
  * steer/followup/context); false for the stateless runtime reports (events/tasks/status/
67
- * usage/subagents/project) dispatched through `runRuntimeCommand`. Meaningful only within
66
+ * usage/subagents/skills) dispatched through `runRuntimeCommand`. Meaningful only within
68
67
  * `BUILT_IN_COMMANDS`.
69
68
  */
70
69
  runnerHandled?: boolean;
@@ -87,8 +86,6 @@ export declare const SESSION_COMMANDS: readonly CommandSpec[];
87
86
  /** Look up the shared description for a session command (used by the SDK extension). */
88
87
  export declare function sessionCommandDescription(name: string): string;
89
88
  export declare function isBuiltInCommandName(name: string): name is BuiltInCommandName;
90
- /** True for a session-layer command name (`/model`, `/compact`, …) — needs the idle session layer. */
91
- export declare function isSessionCommandName(name: string): boolean;
92
89
  /** Narrow a parsed built-in to one `ChannelRunner.handleBuiltinCommand` accepts. */
93
90
  export declare function isRunnerBuiltInCommand(command: BuiltInCommand): command is RunnerBuiltInCommand;
94
91
  /**
@@ -99,7 +96,7 @@ export declare function isRunnerBuiltInCommand(command: BuiltInCommand): command
99
96
  export declare function formatBusyHint(): string;
100
97
  /**
101
98
  * Renders a command's subcommand table as its `usage()` text — the single source `tasks/commands.ts`,
102
- * `events/commands.ts`, `subagents/commands.ts`, `channel/commands.ts`, and `memory/commands.ts` call
99
+ * `events/commands.ts`, `subagents/commands.ts`, and `memory/commands.ts` call
103
100
  * on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
104
101
  */
105
102
  export declare function renderSubcommandUsage(name: string): string;
@@ -3,8 +3,7 @@
3
3
  * examples, plus the parsing and usage/help rendering built on top of them.
4
4
  *
5
5
  * It lives in its own domain, not in `src/agent/`, because the catalog describes commands handled
6
- * in three different layers — the runtime (`/tasks`, `/events`, `/subagents`, `/project`,
7
- * `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
6
+ * in three different layers — the runtime (`/tasks`, `/events`, `/subagents`, `/skills`), the agent session (`/model`, `/compact`, `/new`) and memory (`/memory`) — and is read
8
7
  * by all of them plus the TUI. Only the catalog and the reply shape are shared: each *handler*
9
8
  * still lives in the layer that owns the state it touches (`runtime/*-commands.ts`,
10
9
  * `memory/commands.ts`, `agent/session/command-extension.ts`). This file has no imports at all, so nothing
@@ -37,7 +36,7 @@ export const BUILT_IN_COMMANDS = [
37
36
  argumentHint: "<消息>",
38
37
  description: "在当前工具调用结束后调整正在运行的回合",
39
38
  examples: ["/steer 改用上海时区,只汇总最新的更新"],
40
- note: "回合进行中直接发送的普通消息默认按 `/steer` 处理。部署者可以在 channel.json 把 `busyMessageDefault` 设为 `followUp`,改为排到当前回合之后执行;`responseMode` 控制答复的输出形态。",
39
+ note: "回合进行中直接发送的普通消息默认按 `/steer` 处理。部署者可以在 channel.json 的 `dingtalk` 段把 `busyMessageDefault` 设为 `followUp`,改为排到当前回合之后执行;`responseMode` 控制答复的输出形态。",
41
40
  availableWhileBusy: true,
42
41
  runnerHandled: true,
43
42
  },
@@ -49,6 +48,23 @@ export const BUILT_IN_COMMANDS = [
49
48
  availableWhileBusy: true,
50
49
  runnerHandled: true,
51
50
  },
51
+ {
52
+ name: "desk",
53
+ argumentHint: "[list|new <名字>|bind <名字>]",
54
+ description: "进阶:创建工位,或把本频道切换到另一个工位",
55
+ // list/new answer mid-turn; bind refuses by itself while this channel is busy (spec 058, D5).
56
+ availableWhileBusy: true,
57
+ subcommands: [
58
+ { name: "list", description: "列出所有工位和各自绑定的频道(默认动作,可省略)", example: "/desk" },
59
+ { name: "new", args: "<名字>", description: "创建一个空工位,不绑定任何频道", example: "/desk new research" },
60
+ {
61
+ name: "bind",
62
+ args: "<名字>",
63
+ description: "把本频道绑定到这个工位,同时解除原来的绑定;回合进行中不能执行",
64
+ example: "/desk bind research",
65
+ },
66
+ ],
67
+ },
52
68
  {
53
69
  name: "events",
54
70
  argumentHint: "<list|show|delete|history>",
@@ -74,10 +90,10 @@ export const BUILT_IN_COMMANDS = [
74
90
  {
75
91
  name: "tasks",
76
92
  argumentHint: "[show <id>|log <id>|steer <id> <内容>|reply <id> <内容>|pause <id>|resume <id> [+steps N|+usd X]|archive|doctor]",
77
- description: "查看、指挥并诊断本频道的长程任务;pause 只停止自动执行,保留等待条件",
93
+ description: "查看、指挥并诊断本工位的长程任务;pause 只停止自动执行,保留等待条件",
78
94
  availableWhileBusy: true,
79
95
  subcommands: [
80
- { name: "list", description: "列出本频道进行中的任务(默认动作,可省略)", example: "/tasks" },
96
+ { name: "list", description: "列出本工位进行中的任务(默认动作,可省略)", example: "/tasks" },
81
97
  {
82
98
  name: "show",
83
99
  args: "<id>",
@@ -127,7 +143,7 @@ export const BUILT_IN_COMMANDS = [
127
143
  {
128
144
  name: "usage",
129
145
  argumentHint: "[7d|month]",
130
- description: "显示本频道与全局的模型花费和 token,按类型与模型分解",
146
+ description: "显示本工位与全局的模型花费和 token,按类型与模型分解",
131
147
  examples: ["/usage", "/usage 7d", "/usage month"],
132
148
  availableWhileBusy: true,
133
149
  },
@@ -181,24 +197,6 @@ export const BUILT_IN_COMMANDS = [
181
197
  },
182
198
  ],
183
199
  },
184
- {
185
- name: "project",
186
- argumentHint: "[set <absolute-path>|reset]",
187
- description: "查看或切换本频道的项目目录(读写文件与执行命令的工作目录);set/reset 需频道空闲",
188
- // The read form answers like /status; set/reset validate idleness themselves and reply
189
- // with a plain error instead of blocking the built-in-command dispatch path.
190
- availableWhileBusy: true,
191
- subcommands: [
192
- { name: "show", description: "查看当前频道的项目目录与访问边界(默认动作,可省略)", example: "/project" },
193
- {
194
- name: "set",
195
- args: "<absolute-path>",
196
- description: "切换项目目录(需频道空闲,且目录在允许的根目录内)",
197
- example: "/project set /home/me/projects/foo",
198
- },
199
- { name: "reset", description: "切回默认项目目录", example: "/project reset" },
200
- ],
201
- },
202
200
  {
203
201
  name: "skills",
204
202
  argumentHint: "[list|show <name>]",
@@ -224,7 +222,7 @@ export const SESSION_COMMANDS = [
224
222
  {
225
223
  name: "memory",
226
224
  argumentHint: "[status|list [type]|show <name>|forget <name>|journal [date]]",
227
- description: "查看频道记忆、观察期条目与后台整理状态;不经过模型的记忆管理入口",
225
+ description: "查看本工位的记忆、观察期条目与后台整理状态;不经过模型的记忆管理入口",
228
226
  subcommands: [
229
227
  {
230
228
  name: "status",
@@ -301,11 +299,6 @@ export function sessionCommandDescription(name) {
301
299
  export function isBuiltInCommandName(name) {
302
300
  return BUILT_IN_NAMES.has(name);
303
301
  }
304
- const SESSION_COMMAND_NAMES = new Set(SESSION_COMMANDS.map((command) => command.name));
305
- /** True for a session-layer command name (`/model`, `/compact`, …) — needs the idle session layer. */
306
- export function isSessionCommandName(name) {
307
- return SESSION_COMMAND_NAMES.has(name);
308
- }
309
302
  const RUNNER_BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.filter((command) => command.runnerHandled).map((command) => command.name));
310
303
  /** Narrow a parsed built-in to one `ChannelRunner.handleBuiltinCommand` accepts. */
311
304
  export function isRunnerBuiltInCommand(command) {
@@ -326,7 +319,7 @@ export function formatBusyHint() {
326
319
  }
327
320
  /**
328
321
  * Renders a command's subcommand table as its `usage()` text — the single source `tasks/commands.ts`,
329
- * `events/commands.ts`, `subagents/commands.ts`, `channel/commands.ts`, and `memory/commands.ts` call
322
+ * `events/commands.ts`, `subagents/commands.ts`, and `memory/commands.ts` call
330
323
  * on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
331
324
  */
332
325
  export function renderSubcommandUsage(name) {
@@ -1,12 +1,14 @@
1
1
  import type { AgentRunner } from "../agent/types.js";
2
+ import type { ChannelDescription } from "../channel/channel-id.js";
3
+ import { type DeskCommandPort } from "../desk/commands.js";
4
+ import type { DeskConversation } from "../desk/types.js";
2
5
  import type { SubAgentRunManager } from "../subagents/runs.js";
3
6
  import type { RuntimeCommandName } from "./catalog.js";
4
7
  /**
5
- * The stateless report commands (`/events /tasks /status /usage /context /subagents /project
6
- * /skills`) as one transport-neutral handler. The DingTalk runtime and the terminal TUI both route
7
- * through it, so a report cannot behave differently depending on where it was typed; each
8
- * transport supplies only what is genuinely its own (how to find its runner, how to rebuild one
9
- * after `/project`, whether a task can be woken immediately).
8
+ * The stateless report commands (`/desk /events /tasks /status /usage /context /subagents /skills`) as
9
+ * one transport-neutral handler. The DingTalk runtime and the terminal TUI both route through it,
10
+ * so a report cannot behave differently depending on where it was typed; each transport supplies
11
+ * only what is genuinely its own (how to find its runner, whether a task can be woken immediately).
10
12
  */
11
13
  /** The path fields the reports read; structurally satisfied by the app's `BootstrapPaths`. */
12
14
  export interface ReportCommandPaths {
@@ -17,9 +19,13 @@ export interface ReportCommandPaths {
17
19
  modelsConfigPath: string;
18
20
  }
19
21
  export interface ReportCommandContext {
20
- channelId: string;
22
+ kind: "bound";
23
+ /** The asking channel's conversation in its desk. */
24
+ conversation: DeskConversation;
25
+ deskPort: DeskCommandPort;
21
26
  paths: ReportCommandPaths;
22
- actor: "dingtalk-command" | "tui-command";
27
+ /** Names a delivery channel and says whether it is still bound to this desk. */
28
+ describeChannel: (channelId: string) => ChannelDescription;
23
29
  version: string;
24
30
  startedAt: number;
25
31
  /** The channel's live runner, if one exists; never builds one. */
@@ -27,11 +33,16 @@ export interface ReportCommandContext {
27
33
  /** The channel's runner, built on demand (`/context` needs a session to report on). */
28
34
  getRunner: () => AgentRunner;
29
35
  runManager: SubAgentRunManager;
30
- /** One line per running background job, for `/project`'s "busy" check. */
31
- runningJobLines: () => string[];
32
- /** Drop the runner built under the old project scope so the next access rebuilds it. */
33
- onScopeChanged: () => Promise<void>;
34
36
  /** Immediate task wake for `/tasks run|reply`; absent where there is no durable dispatch (the TUI). */
35
37
  dispatchTask?: (taskId: string) => Promise<boolean>;
36
38
  }
37
- export declare function runReportCommand(context: ReportCommandContext, name: RuntimeCommandName, args: string): Promise<string>;
39
+ /**
40
+ * A channel with no usable desk (spec 060, D4): `/desk` is the one report it can run; every other
41
+ * name gets `refusal` — why there is no desk, and the next step.
42
+ */
43
+ export interface NoDeskCommandContext {
44
+ kind: "no-desk";
45
+ deskPort: DeskCommandPort;
46
+ refusal: string;
47
+ }
48
+ export declare function runReportCommand(context: ReportCommandContext | NoDeskCommandContext, name: RuntimeCommandName, args: string): Promise<string>;
@@ -1,6 +1,5 @@
1
1
  import { renderStatus } from "../agent/status-render.js";
2
- import { getChannelDir } from "../channel/channel-paths.js";
3
- import { handleProjectCommand } from "../channel/commands.js";
2
+ import { handleDeskCommand } from "../desk/commands.js";
4
3
  import { handleEventsCommand } from "../events/commands.js";
5
4
  import { handleSkillsCommand } from "../skills/commands.js";
6
5
  import { handleSubagentsCommand } from "../subagents/commands.js";
@@ -9,13 +8,29 @@ import { handleTasksCommand } from "../tasks/commands.js";
9
8
  import { getUsageLedger } from "../usage/ledger.js";
10
9
  import { parseUsageMode, renderUsageReport } from "../usage/render.js";
11
10
  export async function runReportCommand(context, name, args) {
12
- const { channelId, paths } = context;
13
- const channelDir = getChannelDir(paths.workspaceDir, channelId);
11
+ if (name === "desk")
12
+ return handleDeskCommand(args, context.deskPort);
13
+ if (context.kind === "no-desk")
14
+ return context.refusal;
15
+ const { conversation, paths } = context;
16
+ const { channelId, desk, deskDir } = conversation;
14
17
  switch (name) {
15
18
  case "events":
16
- return handleEventsCommand({ args, workspaceDir: paths.workspaceDir, historyPath: paths.eventHistoryPath });
19
+ return handleEventsCommand({
20
+ args,
21
+ desk,
22
+ deskDir,
23
+ historyPath: paths.eventHistoryPath,
24
+ describeChannel: context.describeChannel,
25
+ });
17
26
  case "tasks":
18
- return handleTasksCommand({ args, channelDir, dispatchTask: context.dispatchTask });
27
+ return handleTasksCommand({
28
+ args,
29
+ deskDir,
30
+ currentChannelId: channelId,
31
+ describeChannel: context.describeChannel,
32
+ dispatchTask: context.dispatchTask,
33
+ });
19
34
  case "status":
20
35
  return renderStatus({
21
36
  runner: context.peekRunner(),
@@ -23,7 +38,7 @@ export async function runReportCommand(context, name, args) {
23
38
  uptimeMs: Date.now() - context.startedAt,
24
39
  });
25
40
  case "usage":
26
- return renderUsageReport(getUsageLedger(), channelId, parseUsageMode(args), new Date());
41
+ return renderUsageReport(getUsageLedger(), { desk, channelId }, parseUsageMode(args), new Date());
27
42
  // Read-only prompt accounting; safe mid-turn.
28
43
  case "context":
29
44
  return context.getRunner().renderContextReport(args);
@@ -43,23 +58,6 @@ export async function runReportCommand(context, name, args) {
43
58
  modelsConfigPath: paths.modelsConfigPath,
44
59
  }),
45
60
  });
46
- case "project":
47
- return handleProjectCommand({
48
- args,
49
- channelId,
50
- channelDir,
51
- appHomeDir: paths.appHomeDir,
52
- actor: context.actor,
53
- isBusy: () => context.peekRunner()?.isBusy() ?? false,
54
- listActiveBlockers: () => [
55
- ...context.runManager
56
- .list()
57
- .filter((record) => record.status === "running")
58
- .map((record) => `委派 \`${record.runId}\`(${record.agent})仍在运行`),
59
- ...context.runningJobLines(),
60
- ],
61
- onScopeChanged: context.onScopeChanged,
62
- });
63
61
  case "skills":
64
62
  return handleSkillsCommand({
65
63
  args,
@@ -1,6 +1,5 @@
1
1
  /** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
2
2
  import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
3
- import type { ResponseMode } from "../channel/channel-context.js";
4
3
  import type { ConfigDiagnostic } from "../shared/config-diagnostic.js";
5
4
  type SettingsError = {
6
5
  scope: "global" | "project";
@@ -106,15 +105,17 @@ export interface PipiclawSettings {
106
105
  * here — both at `npm run typecheck`, not by trusting a human to update two places together.
107
106
  */
108
107
  export declare const SETTINGS_TOP_LEVEL_KEYS: readonly ["defaultProvider", "defaultModel", "defaultThinkingLevel", "fallbackModel", "subagentModel", "compaction", "retry", "memoryMaintenance", "sessionSearch", "logging", "tui", "delegation"];
108
+ /** The terminal's output presets; the same three names DingTalk's `responseMode` uses, interpreted by the TUI itself. */
109
+ export type TuiResponseMode = "full_progress_then_plain_final" | "rolling_progress_then_plain_final" | "final_card_only";
109
110
  export interface PipiclawTuiSettings {
110
111
  /**
111
- * Output shape for the terminal TUI, reusing the DingTalk response-mode
112
- * vocabulary: `full_progress_then_plain_final` (default) streams full progress
112
+ * Output shape for the terminal TUI, using the same vocabulary as the DingTalk
113
+ * channel's `responseMode`: `full_progress_then_plain_final` (default) streams full progress
113
114
  * then a plain final answer; `rolling_progress_then_plain_final` keeps only
114
115
  * recent progress; `final_card_only` hides progress. Independent of the
115
116
  * DingTalk channel's `responseMode` in `channel.json`.
116
117
  */
117
- responseMode: ResponseMode;
118
+ responseMode: TuiResponseMode;
118
119
  }
119
120
  export declare const TASK_DIGEST_SETTINGS: PipiclawTaskDigestSettings;
120
121
  export declare const TASK_DRIVER_SETTINGS: PipiclawTaskDriverSettings;
@@ -0,0 +1,6 @@
1
+ import type { BindingsFile } from "./types.js";
2
+ export declare function loadBindingsSync(workspaceDir: string): BindingsFile;
3
+ /** Publish an empty table exclusively. A racing initializer can never erase a first binding. */
4
+ export declare function initializeBindings(workspaceDir: string): BindingsFile;
5
+ export declare function loadBindings(workspaceDir: string): Promise<BindingsFile>;
6
+ export declare function writeBindings(workspaceDir: string, file: BindingsFile): Promise<void>;
@@ -0,0 +1,105 @@
1
+ /** The current binding format, shared by synchronous initialization and daemon reads. */
2
+ import { linkSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { createAtomicTempPath, syncDirectoryBestEffort, writeFileAtomically } from "../shared/atomic-file.js";
6
+ import { isPlainObject } from "../shared/type-guards.js";
7
+ import { getBindingsPath, isDeskEntry, isDeskName } from "./paths.js";
8
+ import { StartupRefusal } from "./startup-error.js";
9
+ function missing(error) {
10
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
11
+ }
12
+ function decode(text, path) {
13
+ const fail = (reason) => {
14
+ throw new StartupRefusal(`Desk bindings file ${path} ${reason}; fix or restore it before starting.`);
15
+ };
16
+ let value;
17
+ try {
18
+ value = JSON.parse(text);
19
+ }
20
+ catch {
21
+ return fail("is not valid JSON");
22
+ }
23
+ if (!isPlainObject(value) || value.version !== 1 || !isPlainObject(value.bindings)) {
24
+ return fail("has an unsupported shape or version");
25
+ }
26
+ const bindings = {};
27
+ for (const [channelId, entry] of Object.entries(value.bindings)) {
28
+ if (!isPlainObject(entry) ||
29
+ typeof entry.desk !== "string" ||
30
+ !isDeskName(entry.desk) ||
31
+ typeof entry.boundAt !== "string" ||
32
+ Object.keys(entry).some((key) => key !== "desk" && key !== "boundAt")) {
33
+ return fail(`has an invalid entry for ${channelId}`);
34
+ }
35
+ bindings[channelId] = { desk: entry.desk, boundAt: entry.boundAt };
36
+ }
37
+ return { version: 1, bindings };
38
+ }
39
+ export function loadBindingsSync(workspaceDir) {
40
+ const path = getBindingsPath(workspaceDir);
41
+ let text;
42
+ try {
43
+ text = readFileSync(path, "utf8");
44
+ }
45
+ catch (error) {
46
+ if (missing(error))
47
+ throw error;
48
+ throw new StartupRefusal(`Cannot read desk bindings file ${path}; check permissions before starting.`);
49
+ }
50
+ return decode(text, path);
51
+ }
52
+ /** Publish an empty table exclusively. A racing initializer can never erase a first binding. */
53
+ export function initializeBindings(workspaceDir) {
54
+ try {
55
+ return loadBindingsSync(workspaceDir);
56
+ }
57
+ catch (error) {
58
+ if (!missing(error))
59
+ throw error;
60
+ }
61
+ mkdirSync(workspaceDir, { recursive: true });
62
+ const hasDesks = readdirSync(workspaceDir, { withFileTypes: true }).some(isDeskEntry);
63
+ if (hasDesks) {
64
+ // Another process may have published both the table and a desk since the first read.
65
+ try {
66
+ return loadBindingsSync(workspaceDir);
67
+ }
68
+ catch (error) {
69
+ if (!missing(error))
70
+ throw error;
71
+ }
72
+ throw new StartupRefusal(`Desk bindings file ${getBindingsPath(workspaceDir)} is missing from an existing workspace; restore it before starting.`);
73
+ }
74
+ const path = getBindingsPath(workspaceDir);
75
+ const temporary = createAtomicTempPath(join(workspaceDir, ".desk-bindings-init"));
76
+ writeFileSync(temporary, `${JSON.stringify({ version: 1, bindings: {} }, null, "\t")}\n`, { flush: true });
77
+ try {
78
+ try {
79
+ linkSync(temporary, path);
80
+ syncDirectoryBestEffort(workspaceDir);
81
+ }
82
+ catch (error) {
83
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
84
+ throw error;
85
+ }
86
+ }
87
+ finally {
88
+ unlinkSync(temporary);
89
+ }
90
+ return loadBindingsSync(workspaceDir);
91
+ }
92
+ export async function loadBindings(workspaceDir) {
93
+ const path = getBindingsPath(workspaceDir);
94
+ let text;
95
+ try {
96
+ text = await readFile(path, "utf8");
97
+ }
98
+ catch {
99
+ throw new StartupRefusal(`Cannot read desk bindings file ${path}; check permissions or restore it before starting.`);
100
+ }
101
+ return decode(text, path);
102
+ }
103
+ export async function writeBindings(workspaceDir, file) {
104
+ await writeFileAtomically(getBindingsPath(workspaceDir), `${JSON.stringify(file, null, "\t")}\n`);
105
+ }
@@ -0,0 +1,81 @@
1
+ import type { BindingsFile, CreateDeskOutcome, DeskAvailability, DeskSummary } from "./types.js";
2
+ type DeskCommand = {
3
+ action: "list";
4
+ } | {
5
+ action: "new";
6
+ name: string;
7
+ } | {
8
+ action: "bind";
9
+ name: string;
10
+ };
11
+ /** One channel bound to a desk, as `/desk list` shows it. */
12
+ export interface DeskListChannel {
13
+ channelId: string;
14
+ /** Rendered by the caller (`channel/channel-id.ts`'s `formatChannelLabel`); desk never parses channel ids. */
15
+ label: string;
16
+ }
17
+ export interface DeskListItem {
18
+ name: string;
19
+ availability: DeskAvailability;
20
+ channels: DeskListChannel[];
21
+ /** The desk the asking channel is bound to (or, in the TUI, the desk it opened). */
22
+ current: boolean;
23
+ }
24
+ export type BindOutcome = {
25
+ kind: "bound";
26
+ desk: string;
27
+ previousDesk?: string;
28
+ /** The previous desk lost its last binding and went dormant. */
29
+ previousDeskDormant?: boolean;
30
+ /** Open tasks / events in the previous desk that deliver to this channel and are now suspended. */
31
+ suspendedTasks?: number;
32
+ suspendedEvents?: number;
33
+ } | {
34
+ kind: "same";
35
+ desk: string;
36
+ } | {
37
+ kind: "busy";
38
+ desk: string;
39
+ } | {
40
+ kind: "unknown";
41
+ desk: string;
42
+ } | {
43
+ kind: "unavailable";
44
+ desk: string;
45
+ } | {
46
+ kind: "invalid";
47
+ desk: string;
48
+ } | {
49
+ kind: "forbidden";
50
+ desk: string;
51
+ };
52
+ /**
53
+ * `/desk list`'s rows: every desk on disk, plus every desk a binding names that is no longer there
54
+ * (shown missing, D4), each with the channels bound to it. `label` names a channel (the caller
55
+ * owns channel ids); `current` is the asking channel's desk.
56
+ */
57
+ export declare function buildDeskList(desks: readonly DeskSummary[], bindings: BindingsFile["bindings"], current: string | undefined, label: (channelId: string) => string): DeskListItem[];
58
+ export interface DeskCommandPort {
59
+ list(): Promise<DeskListItem[]>;
60
+ /** Absolute path of `CHANNELS.md`, where a truncated `/desk list` sends the reader. */
61
+ channelIndexPath: string;
62
+ create(name: string): Promise<CreateDeskOutcome>;
63
+ /** Absent in the TUI, which never writes bindings (D18). */
64
+ bind?(name: string): Promise<BindOutcome>;
65
+ }
66
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
67
+ export declare function parseDeskCommand(args: string): DeskCommand;
68
+ /**
69
+ * Why a channel has no usable desk: it has no binding (the default desk could not take it in), or
70
+ * it is bound to a desk that is missing or broken on disk. Either way the user sees one thing.
71
+ */
72
+ export type NoDeskResolution = {
73
+ kind: "unbound";
74
+ } | {
75
+ kind: "unavailable";
76
+ desk: string;
77
+ };
78
+ /** The reply to anything but `/desk` and `/help` on a channel with no usable desk (D4). */
79
+ export declare function formatNoDeskReply(resolution: NoDeskResolution): string;
80
+ export declare function handleDeskCommand(args: string, port: DeskCommandPort): Promise<string>;
81
+ export {};