@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,109 +0,0 @@
1
- import { renderSubcommandUsage } from "../commands/catalog.js";
2
- import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
3
- import { currentProjectSandboxStatus, isWithinAllowedRoots, resolveExistingDirectory, resolveProjectAccessPolicy, } from "../security/project-scope.js";
4
- import { errorMessage } from "../shared/text-utils.js";
5
- import { commitProjectSelection, readProjectSelection } from "./project-scope-store.js";
6
- function usage() {
7
- return renderSubcommandUsage("project");
8
- }
9
- /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
10
- export function parseProjectCommand(args) {
11
- const trimmed = args.trim();
12
- if (!trimmed)
13
- return { action: "show" };
14
- const parts = trimmed.split(/\s+/);
15
- if (parts[0] === "set") {
16
- if (!parts[1] || parts.length > 2)
17
- throw new Error("用法:/project set <absolute-path>");
18
- return { action: "set", path: parts[1] };
19
- }
20
- if (parts[0] === "reset") {
21
- if (parts.length > 1)
22
- throw new Error("用法:/project reset");
23
- return { action: "reset" };
24
- }
25
- throw new Error(`未知子命令 \`${parts[0]}\`。`);
26
- }
27
- function formatShow(options) {
28
- const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
29
- const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
30
- const sandbox = currentProjectSandboxStatus();
31
- const selection = readProjectSelection(options.channelDir);
32
- const lines = ["**项目目录**"];
33
- if (!selection) {
34
- lines.push(`- 当前:\`${resolution.policy.defaultRoot}\`(尚未选择过,下一条消息起采用默认目录)`);
35
- }
36
- else {
37
- const by = selection.updatedBy === "tui-command" ? "终端" : "钉钉";
38
- lines.push(`- 当前:\`${selection.projectRoot}\`(${by}中设置,更新于 ${selection.updatedAt})`);
39
- }
40
- lines.push(`- 访问范围:${resolution.configured ? "仅限项目目录(project)" : "不限制(unbounded,沿用全局文件权限)"}`);
41
- lines.push(`- 隔离级别:${sandbox.level}(${sandbox.summary})`);
42
- if (!resolution.configured) {
43
- lines.push("- `/project set` 不可用:请部署者在 `security.json` 中配置 `projectAccess` 后再用。");
44
- }
45
- else if (!resolution.mutable) {
46
- lines.push("- `projectAccess.defaultRoot` 配置有误,项目切换已被禁用;请部署者查看启动日志。");
47
- }
48
- else {
49
- lines.push(`- 允许的根目录:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
50
- }
51
- for (const diagnostic of resolution.diagnostics) {
52
- lines.push(`- ⚠️ ${diagnostic.message}`);
53
- }
54
- return lines.join("\n");
55
- }
56
- async function applyScopeChange(options, requestedPath, label) {
57
- const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
58
- const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
59
- if (!resolution.configured) {
60
- return "无法切换项目:未配置 `projectAccess`。请部署者在 `security.json` 中写入 `projectAccess`(`defaultRoot`、`allowedRoots`)后重试。";
61
- }
62
- if (!resolution.mutable) {
63
- return "无法切换项目:`projectAccess.defaultRoot` 配置有误,修复前项目切换已被禁用;请部署者查看启动日志。";
64
- }
65
- const real = resolveExistingDirectory(requestedPath);
66
- if (!real) {
67
- return `无法切换项目:\`${requestedPath}\` 不是一个存在的绝对目录。`;
68
- }
69
- if (!isWithinAllowedRoots(real, resolution.policy)) {
70
- return `无法切换项目:\`${real}\` 不在允许的根目录内。允许的根目录:${resolution.policy.allowedRoots
71
- .map((root) => `\`${root}\``)
72
- .join("、")}。`;
73
- }
74
- if (options.isBusy()) {
75
- return "无法切换项目:当前频道有回合正在进行。等它结束后重试,或先用 `/stop` 停止。";
76
- }
77
- const blockers = await options.listActiveBlockers();
78
- if (blockers.length > 0) {
79
- return `无法切换项目:\n${blockers.map((line) => `- ${line}`).join("\n")}\n\n结束或取消上述项后重试。`;
80
- }
81
- await commitProjectSelection(options.channelDir, real, options.actor);
82
- await options.onScopeChanged?.();
83
- return `${label}:\`${real}\`。下一条消息起在新的项目目录下运行。`;
84
- }
85
- export async function handleProjectCommand(options) {
86
- let command;
87
- try {
88
- command = parseProjectCommand(options.args);
89
- }
90
- catch (error) {
91
- return `${errorMessage(error)}\n\n${usage()}`;
92
- }
93
- try {
94
- switch (command.action) {
95
- case "show":
96
- return formatShow(options);
97
- case "set":
98
- return await applyScopeChange(options, command.path, "已切换项目");
99
- case "reset": {
100
- const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
101
- const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
102
- return await applyScopeChange(options, resolution.policy.defaultRoot, "已重置项目");
103
- }
104
- }
105
- }
106
- catch (error) {
107
- return `执行 /project ${command.action} 失败:${errorMessage(error)}`;
108
- }
109
- }
@@ -1,51 +0,0 @@
1
- import { type ProjectAccessPolicy, type ProjectScope } from "../security/project-scope.js";
2
- /** A channel's persisted project selection (D3.3). Never holds messages, only the choice itself. */
3
- export interface PersistedProjectSelectionV1 {
4
- version: 1;
5
- /** Realpath. */
6
- projectRoot: string;
7
- updatedAt: string;
8
- updatedBy: "migration" | "dingtalk-command" | "tui-command";
9
- }
10
- export declare function getProjectSelectionPath(channelDir: string): string;
11
- /**
12
- * `missing` (never selected — a plain default) and `corrupt` (a selection existed but the file
13
- * cannot be read back) must not collapse into the same "nothing here" signal (R7a):
14
- * `resolveProjectScope` used to treat both as "never selected" and silently overwrite a corrupt
15
- * file with the app default, which moved a channel to a different project root without the user
16
- * ever choosing that.
17
- */
18
- export type ReadProjectSelectionResult = {
19
- kind: "missing";
20
- } | {
21
- kind: "corrupt";
22
- } | {
23
- kind: "valid";
24
- selection: PersistedProjectSelectionV1;
25
- };
26
- export declare function readProjectSelectionResult(channelDir: string): ReadProjectSelectionResult;
27
- /** Collapses `corrupt` into `undefined` alongside `missing`, for display-only callers (`/project
28
- * show`) that already have their own "not chosen yet" wording and do not make a resolution
29
- * decision. `resolveProjectScope` uses {@link readProjectSelectionResult} directly instead,
30
- * because it must not conflate the two. */
31
- export declare function readProjectSelection(channelDir: string): PersistedProjectSelectionV1 | undefined;
32
- export declare function commitProjectSelection(channelDir: string, projectRoot: string, updatedBy: PersistedProjectSelectionV1["updatedBy"]): Promise<PersistedProjectSelectionV1>;
33
- export type ProjectScopeOutcome = {
34
- kind: "ready";
35
- scope: ProjectScope;
36
- selection: PersistedProjectSelectionV1;
37
- } | {
38
- kind: "blocked";
39
- reason: string;
40
- };
41
- /**
42
- * Resolves the effective `ProjectScope` for a channel: its persisted selection if present and
43
- * still valid, else the app default — materialized as the channel's first selection so a later
44
- * daemon restart from a different startup cwd cannot silently move the channel (D3.3). Never
45
- * falls back to a different root once one has been persisted (P7): a stale or now-disallowed
46
- * selection blocks instead of guessing.
47
- */
48
- export declare function resolveProjectScope(channelDir: string, resolution: {
49
- policy: ProjectAccessPolicy;
50
- configured: boolean;
51
- }): ProjectScopeOutcome;
@@ -1,112 +0,0 @@
1
- import { existsSync, readFileSync, realpathSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { currentProjectSandboxStatus, isWithinAllowedRoots, } from "../security/project-scope.js";
4
- import { writeFileAtomically, writeFileAtomicallySync } from "../shared/atomic-file.js";
5
- const SELECTION_FILENAME = "project.json";
6
- export function getProjectSelectionPath(channelDir) {
7
- return join(channelDir, SELECTION_FILENAME);
8
- }
9
- export function readProjectSelectionResult(channelDir) {
10
- const path = getProjectSelectionPath(channelDir);
11
- if (!existsSync(path)) {
12
- return { kind: "missing" };
13
- }
14
- let raw;
15
- try {
16
- raw = JSON.parse(readFileSync(path, "utf-8"));
17
- }
18
- catch {
19
- return { kind: "corrupt" };
20
- }
21
- if (!raw ||
22
- typeof raw !== "object" ||
23
- raw.version !== 1 ||
24
- typeof raw.projectRoot !== "string" ||
25
- typeof raw.updatedAt !== "string" ||
26
- typeof raw.updatedBy !== "string") {
27
- return { kind: "corrupt" };
28
- }
29
- return { kind: "valid", selection: raw };
30
- }
31
- /** Collapses `corrupt` into `undefined` alongside `missing`, for display-only callers (`/project
32
- * show`) that already have their own "not chosen yet" wording and do not make a resolution
33
- * decision. `resolveProjectScope` uses {@link readProjectSelectionResult} directly instead,
34
- * because it must not conflate the two. */
35
- export function readProjectSelection(channelDir) {
36
- const result = readProjectSelectionResult(channelDir);
37
- return result.kind === "valid" ? result.selection : undefined;
38
- }
39
- /** Used only for the one-time, in-constructor migration write (D3.3); every explicit mutation
40
- * (`/project set|reset`) goes through the async `writeFileAtomically` in `commitProjectSelection`
41
- * instead — that one is on a mutation path that can already afford to await. */
42
- function writeProjectSelectionSync(channelDir, selection) {
43
- writeFileAtomicallySync(getProjectSelectionPath(channelDir), `${JSON.stringify(selection, null, 2)}\n`);
44
- }
45
- export async function commitProjectSelection(channelDir, projectRoot, updatedBy) {
46
- const selection = {
47
- version: 1,
48
- projectRoot,
49
- updatedAt: new Date().toISOString(),
50
- updatedBy,
51
- };
52
- await writeFileAtomically(getProjectSelectionPath(channelDir), `${JSON.stringify(selection, null, 2)}\n`);
53
- return selection;
54
- }
55
- /**
56
- * Resolves the effective `ProjectScope` for a channel: its persisted selection if present and
57
- * still valid, else the app default — materialized as the channel's first selection so a later
58
- * daemon restart from a different startup cwd cannot silently move the channel (D3.3). Never
59
- * falls back to a different root once one has been persisted (P7): a stale or now-disallowed
60
- * selection blocks instead of guessing.
61
- */
62
- export function resolveProjectScope(channelDir, resolution) {
63
- const sandbox = currentProjectSandboxStatus();
64
- const boundary = resolution.configured ? "project" : "unbounded";
65
- const result = readProjectSelectionResult(channelDir);
66
- if (result.kind === "corrupt") {
67
- return {
68
- kind: "blocked",
69
- reason: `项目选择文件已损坏:${getProjectSelectionPath(channelDir)}。请检查该文件,或在频道空闲时执行 /project set <path> 或 /project reset 重新选择——不会自动回退到默认项目。`,
70
- };
71
- }
72
- if (result.kind === "missing") {
73
- const selection = {
74
- version: 1,
75
- projectRoot: resolution.policy.defaultRoot,
76
- updatedAt: new Date().toISOString(),
77
- updatedBy: "migration",
78
- };
79
- writeProjectSelectionSync(channelDir, selection);
80
- return { kind: "ready", scope: { projectRoot: resolution.policy.defaultRoot, boundary, sandbox }, selection };
81
- }
82
- const existing = result.selection;
83
- if (!existsSync(existing.projectRoot)) {
84
- return {
85
- kind: "blocked",
86
- reason: `项目目录已不存在:${existing.projectRoot}。请恢复该目录,或在频道空闲时执行 /project set <path> 或 /project reset。`,
87
- };
88
- }
89
- let real;
90
- try {
91
- real = realpathSync(existing.projectRoot);
92
- }
93
- catch {
94
- return {
95
- kind: "blocked",
96
- reason: `项目目录不可读:${existing.projectRoot}。请检查权限,或在频道空闲时执行 /project set <path>。`,
97
- };
98
- }
99
- if (real !== existing.projectRoot) {
100
- return {
101
- kind: "blocked",
102
- reason: `项目目录 ${existing.projectRoot} 现在指向 ${real}(symlink 已被重新指向),与上次选择不一致。请在频道空闲时执行 /project set <path> 确认新目标,或 /project reset。`,
103
- };
104
- }
105
- if (resolution.configured && !isWithinAllowedRoots(real, resolution.policy)) {
106
- return {
107
- kind: "blocked",
108
- reason: `项目目录 \`${real}\` 已不在允许的根目录内(security.json 的 projectAccess 已变更)。请在频道空闲时用 \`/project set <路径>\` 或 \`/project reset\` 重新选择。`,
109
- };
110
- }
111
- return { kind: "ready", scope: { projectRoot: real, boundary, sandbox }, selection: existing };
112
- }
@@ -1,19 +0,0 @@
1
- export type QueuedWork = () => Promise<void>;
2
- /**
3
- * The per-channel turn serialization point: a channel processes one inbound
4
- * message at a time; later arrivals wait here. This is runtime policy, not a
5
- * transport detail — DingTalk consumes it via `DingTalkBot`; busy-state itself
6
- * is owned by the runner's turn state machine (`AgentRunner.beginTurn`).
7
- */
8
- export declare class ChannelQueue {
9
- private queue;
10
- private processing;
11
- private stopped;
12
- enqueue(work: QueuedWork): void;
13
- size(): number;
14
- /** True only when no queued or in-flight work still owns this channel. */
15
- isIdle(): boolean;
16
- private processNext;
17
- stop(): void;
18
- clearPending(): number;
19
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * The contract between the DingTalk transport and the runtime that drives it: what the runtime
3
- * implements (`DingTalkHandler`) and the slice of the bot it may call back into (`DingTalkBotPort`).
4
- * Declared here, below `bot.ts`, so the bot and the runtime both depend on it and not on each other.
5
- */
6
- import type { FinalDelivery, ProgressStyle } from "../channel/channel-context.js";
7
- import type { ChannelEvent, InboundImage } from "../channel/channel-event.js";
8
- import type { ChannelObservation } from "../channel/channel-index.js";
9
- import type { RuntimeCommandName } from "../commands/catalog.js";
10
- import type { BusyMessageMode } from "./config.js";
11
- /**
12
- * `DingTalkEvent` is kept as the public name (spec 035 D4: `src/index.ts`'s barrel is a
13
- * compatibility promise, so exported names there stay stable). Internally the type now lives in
14
- * `channel-event.ts` as `ChannelEvent`: most producers of this shape are not DingTalk at all
15
- * (jobs/manager, task-driver, events, subagents/runs all synthesize wakes), so `ChannelEvent` is
16
- * what the rest of the runtime imports.
17
- */
18
- export type DingTalkEvent = ChannelEvent;
19
- export type BusyMessageResult = {
20
- kind: "handled";
21
- } | {
22
- kind: "requeue";
23
- text: string;
24
- };
25
- /**
26
- * What `/stop` actually did. Stopping a task-driven turn also pauses that task, which the user
27
- * has to be told: a disabled task is never picked up again until `/tasks resume <id>`, so silence
28
- * here reads as "the turn was interrupted" while the whole task has in fact gone quiet.
29
- */
30
- export interface StopOutcome {
31
- pausedTaskId?: string;
32
- }
33
- /**
34
- * The part of `DingTalkBot` that the runtime's handler and the delivery controller use. `DingTalkBot`
35
- * implements it; keeping it structural lets this contract stay free of an import cycle with the bot.
36
- */
37
- export interface DingTalkBotPort {
38
- readonly progressStyle: ProgressStyle;
39
- readonly finalDelivery: FinalDelivery;
40
- sendPlain(channelId: string, text: string, opts?: {
41
- title?: string;
42
- markdown?: boolean;
43
- }): Promise<boolean>;
44
- getCardGeneration(channelId: string): symbol;
45
- isCardGenerationCurrent(channelId: string, generation: symbol): boolean;
46
- replaceCard(channelId: string, content: string, finalize?: boolean, failed?: boolean, generation?: symbol): Promise<boolean>;
47
- appendToCard(channelId: string, content: string, finalize?: boolean, failed?: boolean, generation?: symbol): Promise<boolean>;
48
- finalizeCard(channelId: string, content: string, generation?: symbol): Promise<boolean>;
49
- finalizeExistingCard(channelId: string, content: string, generation?: symbol): Promise<boolean>;
50
- discardCard(channelId: string, generation?: symbol): void;
51
- clearPendingMessages(channelId: string): number;
52
- resetChannelQueue(channelId: string): number;
53
- }
54
- export interface DingTalkHandler {
55
- isRunning(channelId: string): boolean;
56
- /**
57
- * Note that a real person just wrote in this channel. Called once per accepted inbound
58
- * message, before any busy/command routing, and never for synthetic wakes — see the
59
- * maintenance contract in `channel-index.ts`. Must stay synchronous and cheap.
60
- */
61
- noteChannelActivity?(observation: ChannelObservation): void;
62
- /**
63
- * Synchronously reserve an inbound turn before the queued async body yields.
64
- * The transport calls this hook, when provided, immediately before `handleEvent`.
65
- */
66
- reserveEvent?(event: DingTalkEvent): void;
67
- handleEvent(event: DingTalkEvent, bot: DingTalkBotPort, isEvent?: boolean): Promise<void>;
68
- handleStop(channelId: string, bot: DingTalkBotPort): Promise<StopOutcome>;
69
- /** `/new` bypasses the old per-channel queue and live SDK session. */
70
- handleNewSession(event: DingTalkEvent, bot: DingTalkBotPort): Promise<void>;
71
- /**
72
- * Render one of the stateless report commands (events/tasks/status/usage/context/subagents) to
73
- * text. Single dispatch point shared by the busy-turn switch below and bootstrap's idle-turn
74
- * switch — both used to hand-copy the same six-case table.
75
- */
76
- runRuntimeCommand(event: DingTalkEvent, name: RuntimeCommandName, args: string): Promise<string>;
77
- handleBusyMessage(event: DingTalkEvent, bot: DingTalkBotPort, mode: BusyMessageMode, queueText: string): Promise<BusyMessageResult>;
78
- /**
79
- * Persist one downloaded inbound image under the channel's `inbox/` (spec 049). Owned by
80
- * bootstrap — it holds the workspace root — not the transport, which only knows how to fetch
81
- * bytes over the DingTalk API. `mimeType` is `null` when magic-byte sniffing did not recognize
82
- * a supported image format; the file is still persisted (for the archive/record) but the
83
- * transport excludes it from the model-facing text marker. Returns `null` on a local I/O
84
- * failure, surfaced to the user as "保存失败" — the rest of the message is still delivered.
85
- */
86
- persistInboundImage?(channelId: string, image: {
87
- data: Buffer;
88
- mimeType: string | null;
89
- }): Promise<InboundImage | null>;
90
- }
@@ -1,5 +0,0 @@
1
- export interface ChannelMemoryQueue {
2
- run<T>(channelId: string, job: () => Promise<T>): Promise<T>;
3
- }
4
- export declare function createChannelMemoryQueue(): ChannelMemoryQueue;
5
- export declare function getDefaultChannelMemoryQueue(): ChannelMemoryQueue;
@@ -1,8 +0,0 @@
1
- import { createSerialQueue } from "../shared/serial-queue.js";
2
- export function createChannelMemoryQueue() {
3
- return createSerialQueue();
4
- }
5
- const defaultChannelMemoryQueue = createChannelMemoryQueue();
6
- export function getDefaultChannelMemoryQueue() {
7
- return defaultChannelMemoryQueue;
8
- }
@@ -1,30 +0,0 @@
1
- interface V3Fields {
2
- status?: string;
3
- enabled?: boolean;
4
- schedule?: string;
5
- stopReason?: string;
6
- /** `control.stop` is present (with or without a usable reason). */
7
- stopped: boolean;
8
- /** A state key is present: skip this file, whether v4 or v5. */
9
- v5: boolean;
10
- }
11
- /** Minimal reader for the v3 frontmatter block; the only place that still understands it. */
12
- export declare function parseV3Frontmatter(content: string): V3Fields | undefined;
13
- /** Rename `## Plan` to `## Work Items` and drop the per-cycle sections, the two body changes v5 makes. */
14
- export declare function convertBody(body: string): string;
15
- interface TemplateOutcome {
16
- template?: Record<string, unknown>;
17
- reason?: string;
18
- }
19
- /**
20
- * Build the event template a recurring v3 task becomes. The original Manual and Verification text
21
- * is carried into the Goal (v5 has no such sections, and a recurring job's accumulated rules are
22
- * exactly what the template exists to keep), and every checkbox is reset.
23
- */
24
- export declare function buildTemplate(id: string, body: string): TemplateOutcome;
25
- /**
26
- * Convert every v3 task file in every known channel. Any failure leaves no marker, writes
27
- * `state/task-migration-v5.failed.json`, and throws so the caller does not start services.
28
- */
29
- export declare function migrateTasksToV5(workspaceDir: string, stateDir: string): Promise<void>;
30
- export {};