@oyasmi/pipiclaw 0.9.4-beta.2 → 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 +9 -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,27 +0,0 @@
1
- /**
2
- * Terminal implementation of the `ChannelContext` delivery contract.
3
- *
4
- * The DingTalk delivery controller (`dingtalk/delivery.ts`) drives AI Card
5
- * streaming; the terminal has none of that protocol, so this controller is a
6
- * thin mapping from the contract onto a `TranscriptRenderer`. Archiving
7
- * semantics mirror `delivery.ts` so a channel produces the same conversation log
8
- * regardless of which surface it is driven from:
9
- * - `respond` / `respondPlain` archive when `shouldLog` is set;
10
- * - `replaceMessage` / `deleteMessage` do not archive (they only re-render).
11
- */
12
- import type { ChannelContext, FinalDelivery, ProgressStyle } from "../channel/channel-context.js";
13
- import type { ChannelStore } from "../channel/store.js";
14
- import type { TranscriptRenderer } from "./frontend.js";
15
- /** The minimal per-turn input the terminal context needs (no DingTalk types). */
16
- export interface TurnInput {
17
- text: string;
18
- user: string;
19
- userName?: string;
20
- channel: string;
21
- ts: string;
22
- }
23
- export interface DeliveryTraits {
24
- progressStyle: ProgressStyle;
25
- finalDelivery: FinalDelivery;
26
- }
27
- export declare function createTerminalContext(input: TurnInput, renderer: TranscriptRenderer, store: ChannelStore, traits: DeliveryTraits): ChannelContext;
@@ -1,84 +0,0 @@
1
- class TerminalDeliveryController {
2
- constructor(input, renderer, store, traits) {
3
- this.input = input;
4
- this.renderer = renderer;
5
- this.store = store;
6
- this.traits = traits;
7
- this.closed = false;
8
- this.finalDelivered = false;
9
- }
10
- buildContext() {
11
- const { text, user, userName, channel, ts } = this.input;
12
- return {
13
- message: { text, rawText: text, user, userName, channel, ts },
14
- channelName: channel,
15
- respond: async (progress, shouldLog = true) => this.appendProgress(progress, shouldLog),
16
- respondPlain: async (final, shouldLog = true) => this.sendFinal(final, shouldLog),
17
- replaceMessage: async (final) => this.replaceWithFinal(final),
18
- respondInThread: async (notice) => {
19
- if (notice.trim()) {
20
- this.renderer.showNotice(notice);
21
- }
22
- },
23
- setTyping: async () => { },
24
- setWorking: async (working) => {
25
- this.renderer.setWorking(working);
26
- },
27
- deleteMessage: async () => this.silence(),
28
- primeCard: () => { },
29
- flush: async () => { },
30
- close: async () => {
31
- this.closed = true;
32
- },
33
- progressStyle: this.traits.progressStyle,
34
- finalDelivery: this.traits.finalDelivery,
35
- };
36
- }
37
- appendProgress(text, shouldLog) {
38
- if (this.closed || this.finalDelivered || !text.trim())
39
- return;
40
- // final_card_only shows no progress; drop stray progress writes.
41
- if (this.traits.progressStyle === "none")
42
- return;
43
- this.renderer.appendProgress(text);
44
- if (shouldLog) {
45
- this.archive(text);
46
- }
47
- }
48
- sendFinal(text, shouldLog) {
49
- if (this.closed || this.finalDelivered)
50
- return this.finalDelivered;
51
- if (!text.trim())
52
- return false;
53
- this.renderer.showFinal(text);
54
- if (shouldLog) {
55
- this.archive(text);
56
- }
57
- this.finalDelivered = true;
58
- return true;
59
- }
60
- replaceWithFinal(text) {
61
- if (this.closed || this.finalDelivered)
62
- return;
63
- this.renderer.clearProgress();
64
- if (text.trim()) {
65
- this.renderer.showFinal(text);
66
- }
67
- this.finalDelivered = true;
68
- }
69
- silence() {
70
- if (this.closed || this.finalDelivered)
71
- return;
72
- this.renderer.clearProgress();
73
- this.finalDelivered = true;
74
- }
75
- archive(text) {
76
- void this.store.logBotResponse(this.input.channel, text, Date.now().toString()).catch(() => {
77
- // Best-effort: a failed archive must never break rendering. delivery.ts
78
- // logs a warning here; the TUI keeps quiet to avoid corrupting the view.
79
- });
80
- }
81
- }
82
- export function createTerminalContext(input, renderer, store, traits) {
83
- return new TerminalDeliveryController(input, renderer, store, traits).buildContext();
84
- }
@@ -1,9 +0,0 @@
1
- import type { BootstrapIO } from "../app/home.js";
2
- import type { MediaSender } from "../channel/channel-context.js";
3
- /**
4
- * Terminal implementation of the `MediaSender` port. There is no chat surface to
5
- * push a file to, and the bytes already came from a local file, so "sending" here
6
- * just surfaces a notice — keeping the `send_media` tool available and behaving
7
- * symmetrically across transports rather than being silently absent in the TUI.
8
- */
9
- export declare function createTerminalMediaSender(io: BootstrapIO): MediaSender;
@@ -1,15 +0,0 @@
1
- /**
2
- * Terminal implementation of the `MediaSender` port. There is no chat surface to
3
- * push a file to, and the bytes already came from a local file, so "sending" here
4
- * just surfaces a notice — keeping the `send_media` tool available and behaving
5
- * symmetrically across transports rather than being silently absent in the TUI.
6
- */
7
- export function createTerminalMediaSender(io) {
8
- return {
9
- async sendMedia(_channelId, media) {
10
- const sizeKb = (media.data.length / 1024).toFixed(1);
11
- io.log(`📎 [send_media] ${media.kind}: ${media.fileName} (${sizeKb}KB)`);
12
- return { ok: true };
13
- },
14
- };
15
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * The TUI run-state machine: one channel, one user, turns serialized while still
3
- * accepting steer / follow-up / stop mid-turn, two-stage Ctrl-C, and graceful
4
- * shutdown with a memory flush.
5
- *
6
- * Collaborators (runner, frontend, store) are injected so the machine can be
7
- * unit-tested with fakes and a fake clock. `app.ts` builds the real ones.
8
- */
9
- import type { AgentRunner } from "../agent/types.js";
10
- import type { ChannelStore } from "../channel/store.js";
11
- import { type DispatchDeps } from "./commands.js";
12
- import type { Frontend } from "./frontend.js";
13
- import { type DeliveryTraits } from "./terminal-context.js";
14
- export interface TurnControllerDeps {
15
- runner: AgentRunner;
16
- frontend: Frontend;
17
- store: ChannelStore;
18
- traits: DeliveryTraits;
19
- channelId: string;
20
- userName: string;
21
- /** Info commands that do not depend on run state. */
22
- renderHelp: (args?: string) => string;
23
- runReport: DispatchDeps["runReport"];
24
- }
25
- export declare class TurnController {
26
- private readonly deps;
27
- private readonly dispatchDeps;
28
- private currentTurn;
29
- private readonly followups;
30
- private submitChain;
31
- private exitArmed;
32
- private exiting;
33
- private exitResolve;
34
- private readonly exitPromise;
35
- constructor(deps: TurnControllerDeps);
36
- /** Interactive mode: wire input, run an optional first prompt, resolve on exit. */
37
- startInteractive(initialPrompt?: string): Promise<void>;
38
- /**
39
- * One-shot mode: run a single prompt (if any) then shut down.
40
- *
41
- * Routed through the same `dispatch()` as interactive input so built-in
42
- * slash commands (`/tasks`, `/events`, `/status`, ...) resolve zero-LLM here
43
- * too, instead of falling through to the model as a plain message.
44
- */
45
- runOnce(prompt?: string): Promise<void>;
46
- /** Test/observability hook. Turn state is owned by the runner. */
47
- isRunning(): boolean;
48
- submit(text: string): void;
49
- private processSubmit;
50
- /** A plain message or /steer: steer the in-flight turn, else start a fresh one. */
51
- private applyText;
52
- private applyFollowup;
53
- private beginTurn;
54
- private drainFollowups;
55
- private makeTurnInput;
56
- private archiveIncoming;
57
- private handleInterrupt;
58
- private requestExit;
59
- private buildWelcome;
60
- /** One word per state; `idle` and `ready` used to name the same one. */
61
- private runStateLabel;
62
- private updateStatus;
63
- private shutdown;
64
- }
@@ -1,311 +0,0 @@
1
- /**
2
- * The TUI run-state machine: one channel, one user, turns serialized while still
3
- * accepting steer / follow-up / stop mid-turn, two-stage Ctrl-C, and graceful
4
- * shutdown with a memory flush.
5
- *
6
- * Collaborators (runner, frontend, store) are injected so the machine can be
7
- * unit-tested with fakes and a fake clock. `app.ts` builds the real ones.
8
- */
9
- import { formatBusyHint, formatFollowupQueued, formatNoRunningTurn, formatSteerQueued, formatUnknownCommandMessage, isSessionCommandName, slashCommandName, } from "../commands/catalog.js";
10
- import * as log from "../log.js";
11
- import { formatLocalTime } from "../shared/local-time.js";
12
- import { errorMessage } from "../shared/text-utils.js";
13
- import { bold, dim } from "./colors.js";
14
- import { dispatch } from "./commands.js";
15
- import { createTerminalContext } from "./terminal-context.js";
16
- const SHUTDOWN_ABORT_WAIT_MS = 5000;
17
- // Cap the exit-time memory flush so a slow/stuck LLM consolidation can't trap
18
- // the user in a non-responsive process. Memory may be partially saved on timeout.
19
- const SHUTDOWN_FLUSH_WAIT_MS = 20_000;
20
- export class TurnController {
21
- constructor(deps) {
22
- this.currentTurn = Promise.resolve();
23
- this.followups = [];
24
- this.submitChain = Promise.resolve();
25
- this.exitArmed = false;
26
- this.exiting = false;
27
- this.exitPromise = new Promise((resolve) => {
28
- this.exitResolve = resolve;
29
- });
30
- this.deps = deps;
31
- this.dispatchDeps = { renderHelp: deps.renderHelp, runReport: deps.runReport };
32
- }
33
- /** Interactive mode: wire input, run an optional first prompt, resolve on exit. */
34
- startInteractive(initialPrompt) {
35
- this.deps.frontend.start({
36
- onSubmit: (text) => this.submit(text),
37
- onInterrupt: () => this.handleInterrupt(),
38
- onEof: () => this.requestExit(),
39
- });
40
- this.deps.frontend.showBanner(this.buildWelcome());
41
- this.updateStatus();
42
- if (initialPrompt?.trim())
43
- this.submit(initialPrompt);
44
- return this.exitPromise;
45
- }
46
- /**
47
- * One-shot mode: run a single prompt (if any) then shut down.
48
- *
49
- * Routed through the same `dispatch()` as interactive input so built-in
50
- * slash commands (`/tasks`, `/events`, `/status`, ...) resolve zero-LLM here
51
- * too, instead of falling through to the model as a plain message.
52
- */
53
- async runOnce(prompt) {
54
- const trimmed = prompt?.trim();
55
- if (trimmed) {
56
- await this.processSubmit(trimmed);
57
- await this.currentTurn;
58
- }
59
- await this.shutdown();
60
- }
61
- /** Test/observability hook. Turn state is owned by the runner. */
62
- isRunning() {
63
- return this.deps.runner.isBusy();
64
- }
65
- submit(text) {
66
- this.submitChain = this.submitChain
67
- .then(() => this.processSubmit(text))
68
- .catch((err) => {
69
- log.logWarn("tui.submit.failed", "Submit failed", {
70
- channelId: this.deps.channelId,
71
- reason: errorMessage(err),
72
- });
73
- });
74
- }
75
- async processSubmit(text) {
76
- if (this.exiting)
77
- return;
78
- // Any submitted line disarms a pending "press Ctrl-C again to exit".
79
- this.exitArmed = false;
80
- const outcome = await dispatch(text, this.dispatchDeps);
81
- switch (outcome.kind) {
82
- case "noop":
83
- if (outcome.text)
84
- this.deps.frontend.showNotice(outcome.text);
85
- return;
86
- case "reply":
87
- this.deps.frontend.showFinal(outcome.text);
88
- return;
89
- case "exit":
90
- this.requestExit();
91
- return;
92
- case "stop":
93
- if (this.deps.runner.isBusy()) {
94
- void this.deps.runner.abort();
95
- this.deps.frontend.showNotice("正在停止…");
96
- }
97
- else {
98
- this.deps.frontend.showNotice(formatNoRunningTurn("stop"));
99
- }
100
- return;
101
- case "followup":
102
- this.applyFollowup(outcome.text);
103
- return;
104
- case "steer":
105
- await this.applyText(outcome.text);
106
- return;
107
- case "run": {
108
- // Reject an unknown slash command rather than steering/running its raw
109
- // text. Session commands, skills, and prompt templates pass through.
110
- const name = outcome.text.trim().startsWith("/") ? slashCommandName(outcome.text) : null;
111
- if (name && !this.deps.runner.isKnownSlashCommand(outcome.text)) {
112
- this.deps.frontend.showFinal(formatUnknownCommandMessage(name));
113
- return;
114
- }
115
- // Session commands (`/model`, `/compact`, …) run inside the SDK command extension
116
- // and need the idle session layer — mid-turn they must be rejected outright, not
117
- // steered into the running turn as literal text (review 2026-08-24 §1.6; matches
118
- // the DingTalk busy refusal in dingtalk.ts).
119
- if (name && isSessionCommandName(name) && this.deps.runner.isBusy()) {
120
- this.deps.frontend.showFinal(formatBusyHint());
121
- return;
122
- }
123
- await this.applyText(outcome.text);
124
- return;
125
- }
126
- }
127
- }
128
- /** A plain message or /steer: steer the in-flight turn, else start a fresh one. */
129
- async applyText(text) {
130
- if (this.deps.runner.isBusy()) {
131
- try {
132
- await this.deps.runner.queueSteer(text, this.deps.userName);
133
- this.deps.frontend.showNotice(formatSteerQueued(false));
134
- return;
135
- }
136
- catch {
137
- // The busy window closed between dispatch and here; run it fresh.
138
- }
139
- }
140
- this.beginTurn(text);
141
- }
142
- applyFollowup(text) {
143
- if (this.deps.runner.isBusy()) {
144
- this.followups.push(text);
145
- this.deps.frontend.showNotice(formatFollowupQueued());
146
- return;
147
- }
148
- this.beginTurn(text);
149
- }
150
- beginTurn(text) {
151
- if (this.deps.runner.isBusy() || this.exiting)
152
- return;
153
- // Reserve the turn synchronously; the runner is the single owner of busy state.
154
- this.deps.runner.beginTurn(text);
155
- this.deps.frontend.setBusy(true);
156
- this.updateStatus();
157
- this.currentTurn = (async () => {
158
- const input = this.makeTurnInput(text);
159
- await this.archiveIncoming(input);
160
- const ctx = createTerminalContext(input, this.deps.frontend, this.deps.store, this.deps.traits);
161
- try {
162
- await this.deps.runner.run(ctx, this.deps.store);
163
- }
164
- catch (err) {
165
- this.deps.frontend.showNotice(`处理失败:${errorMessage(err)}`);
166
- }
167
- finally {
168
- await ctx.close();
169
- this.deps.runner.endTurn();
170
- this.deps.frontend.setBusy(false);
171
- this.updateStatus();
172
- }
173
- })();
174
- // The turn is over whether it settled or its finally threw (e.g. a frontend
175
- // method failing); drain either way and never leak an unhandled rejection.
176
- void this.currentTurn.then(() => this.drainFollowups(), (err) => {
177
- log.logWarn("tui.turn.finalizer_failed", "Turn finalizer failed", {
178
- channelId: this.deps.channelId,
179
- reason: errorMessage(err),
180
- });
181
- this.deps.runner.endTurn();
182
- this.drainFollowups();
183
- });
184
- }
185
- drainFollowups() {
186
- if (this.exiting || this.deps.runner.isBusy())
187
- return;
188
- const next = this.followups.shift();
189
- if (next !== undefined)
190
- this.beginTurn(next);
191
- }
192
- makeTurnInput(text) {
193
- return {
194
- text,
195
- user: "tui",
196
- userName: this.deps.userName,
197
- channel: this.deps.channelId,
198
- ts: Date.now().toString(),
199
- };
200
- }
201
- async archiveIncoming(input) {
202
- try {
203
- await this.deps.store.logMessage(this.deps.channelId, {
204
- date: formatLocalTime(),
205
- ts: input.ts,
206
- user: input.user,
207
- userName: input.userName,
208
- text: input.text,
209
- isBot: false,
210
- });
211
- }
212
- catch (err) {
213
- log.logWarn("channel.archive.write_failed", "User message archive failed", {
214
- channelId: this.deps.channelId,
215
- reason: errorMessage(err),
216
- });
217
- }
218
- }
219
- handleInterrupt() {
220
- if (this.deps.runner.isBusy()) {
221
- void this.deps.runner.abort();
222
- this.deps.frontend.showNotice("正在停止…");
223
- return;
224
- }
225
- // Idle: first Ctrl-C arms the exit prompt, the next one exits (no time
226
- // window — armed until the user submits something). Mirrors the Node REPL.
227
- if (this.exitArmed) {
228
- this.requestExit();
229
- return;
230
- }
231
- this.exitArmed = true;
232
- this.deps.frontend.showNotice("再按一次 Ctrl-C 退出。");
233
- }
234
- requestExit() {
235
- // shutdown() restores the terminal in a finally, so a rejection here means only
236
- // the memory-flush bookkeeping failed — log it rather than leak an unhandled
237
- // rejection that could abort the process before exitResolve runs.
238
- this.shutdown().catch((err) => {
239
- log.logWarn("tui.shutdown.failed", "Shutdown failed", {
240
- channelId: this.deps.channelId,
241
- reason: errorMessage(err),
242
- });
243
- this.exitResolve();
244
- });
245
- }
246
- buildWelcome() {
247
- let model = "";
248
- try {
249
- model = this.deps.runner.getStatusSnapshot().model;
250
- }
251
- catch {
252
- // Snapshot may be unavailable before the first turn; omit the model.
253
- }
254
- const meta = model ? `${this.deps.channelId} · ${model}` : this.deps.channelId;
255
- return [`${bold("pipiclaw")} ${dim("· 终端对话")}`, dim(meta), dim("输入消息开始;/help 查看命令。")].join("\n");
256
- }
257
- /** One word per state; `idle` and `ready` used to name the same one. */
258
- runStateLabel() {
259
- return this.deps.runner.isBusy() ? "运行中" : "空闲";
260
- }
261
- updateStatus() {
262
- try {
263
- const snapshot = this.deps.runner.getStatusSnapshot();
264
- let line = snapshot.model;
265
- if (snapshot.contextTokens !== undefined && snapshot.contextWindow > 0) {
266
- line += ` · 上下文 ${((snapshot.contextTokens / snapshot.contextWindow) * 100).toFixed(0)}%`;
267
- }
268
- line += ` · ${this.runStateLabel()}`;
269
- this.deps.frontend.setStatus(`${this.deps.channelId} · ${line}`);
270
- }
271
- catch {
272
- this.deps.frontend.setStatus(`${this.deps.channelId} · ${this.runStateLabel()}`);
273
- }
274
- }
275
- async shutdown() {
276
- if (this.exiting)
277
- return;
278
- this.exiting = true;
279
- if (this.deps.runner.isBusy()) {
280
- await this.deps.runner.abort().catch(() => { });
281
- // Never let a rejected turn (e.g. ctx.close() throwing in the turn's finally)
282
- // escape the race — that would skip frontend.stop() and strand the terminal in
283
- // raw mode. The turn already logs its own failures.
284
- await Promise.race([
285
- this.currentTurn.catch(() => { }),
286
- new Promise((resolve) => setTimeout(resolve, SHUTDOWN_ABORT_WAIT_MS)),
287
- ]);
288
- }
289
- try {
290
- // Tear the UI down first so the terminal is restored immediately — the
291
- // memory flush below can take a moment (LLM consolidation), and a frozen
292
- // full-screen frame feels like a hang. A short note on stderr explains the
293
- // pause without polluting stdout (which carries the answer in --print).
294
- // Guaranteed via finally: a flush failure must not leave the terminal raw.
295
- this.deps.frontend.stop();
296
- process.stderr.write("正在保存会话记忆…\n");
297
- await Promise.race([
298
- this.deps.runner.flushMemoryForShutdown().catch((err) => {
299
- log.logWarn("memory.flush.failed", "Memory flush on exit failed", {
300
- channelId: this.deps.channelId,
301
- reason: errorMessage(err),
302
- });
303
- }),
304
- new Promise((resolve) => setTimeout(resolve, SHUTDOWN_FLUSH_WAIT_MS)),
305
- ]);
306
- }
307
- finally {
308
- this.exitResolve();
309
- }
310
- }
311
- }