@oyasmi/pipiclaw 0.9.4 → 0.9.5-beta.3

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 (531) hide show
  1. package/README.en.md +35 -31
  2. package/README.md +34 -30
  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 +23 -35
  6. package/dist/agent/channel-runner.js +150 -89
  7. package/dist/agent/maintenance-context.d.ts +8 -5
  8. package/dist/agent/maintenance-context.js +30 -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 +11 -9
  13. package/dist/agent/prompt/types.d.ts +1 -1
  14. package/dist/agent/runner-factory.d.ts +6 -6
  15. package/dist/agent/runner-factory.js +7 -8
  16. package/dist/agent/session/command-extension.js +11 -0
  17. package/dist/agent/session/compaction-input.d.ts +6 -0
  18. package/dist/agent/session/compaction-input.js +75 -0
  19. package/dist/agent/session/compaction-snapshot.d.ts +30 -0
  20. package/dist/agent/session/compaction-snapshot.js +154 -0
  21. package/dist/agent/session/compaction-summary.d.ts +39 -0
  22. package/dist/agent/session/compaction-summary.js +162 -0
  23. package/dist/agent/session/compaction.d.ts +35 -0
  24. package/dist/agent/session/compaction.js +294 -0
  25. package/dist/agent/session/context-input.d.ts +15 -0
  26. package/dist/agent/session/context-input.js +82 -0
  27. package/dist/agent/session/context-snapshot.d.ts +11 -0
  28. package/dist/agent/session/context-snapshot.js +72 -0
  29. package/dist/agent/session/event-guards.d.ts +2 -0
  30. package/dist/agent/session/event-guards.js +4 -0
  31. package/dist/agent/session/execution-trace.d.ts +14 -0
  32. package/dist/agent/session/execution-trace.js +57 -0
  33. package/dist/agent/session/request-tools.d.ts +3 -0
  34. package/dist/agent/session/request-tools.js +20 -0
  35. package/dist/agent/session/session-adapter.d.ts +2 -1
  36. package/dist/agent/session/session-adapter.js +6 -3
  37. package/dist/agent/session/session-events.d.ts +4 -8
  38. package/dist/agent/session/session-events.js +80 -70
  39. package/dist/agent/session/session-host.d.ts +39 -61
  40. package/dist/agent/session/session-host.js +122 -124
  41. package/dist/agent/session/settings-diagnostics.d.ts +5 -0
  42. package/dist/agent/session/settings-diagnostics.js +21 -0
  43. package/dist/agent/status-render.js +5 -2
  44. package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
  45. package/dist/{runtime → agent}/stop-watchdog.js +7 -3
  46. package/dist/agent/turn/progress-formatter.d.ts +1 -3
  47. package/dist/agent/turn/progress-formatter.js +3 -22
  48. package/dist/agent/turn/task-digest.d.ts +5 -4
  49. package/dist/agent/turn/task-digest.js +37 -34
  50. package/dist/agent/turn/turn-context.d.ts +12 -8
  51. package/dist/agent/turn/turn-context.js +27 -19
  52. package/dist/agent/turn/turn-finish.d.ts +18 -6
  53. package/dist/agent/turn/turn-finish.js +52 -77
  54. package/dist/agent/turn/turn-input.d.ts +2 -2
  55. package/dist/agent/turn/turn-input.js +4 -3
  56. package/dist/agent/turn/turn-output.d.ts +19 -0
  57. package/dist/agent/turn/turn-output.js +41 -0
  58. package/dist/agent/turn/turn-pipeline.d.ts +15 -10
  59. package/dist/agent/turn/turn-pipeline.js +86 -59
  60. package/dist/agent/turn/turn-prompt.d.ts +1 -1
  61. package/dist/agent/turn/turn-recovery.d.ts +11 -10
  62. package/dist/agent/turn/turn-recovery.js +14 -29
  63. package/dist/agent/types.d.ts +93 -24
  64. package/dist/agent/types.js +5 -1
  65. package/dist/app/auth-command.js +1 -1
  66. package/dist/app/home.js +34 -19
  67. package/dist/channel/active-session-store.d.ts +14 -12
  68. package/dist/channel/active-session-store.js +29 -25
  69. package/dist/channel/attachments.d.ts +25 -0
  70. package/dist/channel/attachments.js +56 -0
  71. package/dist/channel/channel-context.d.ts +87 -96
  72. package/dist/channel/channel-context.js +1 -66
  73. package/dist/channel/channel-event.d.ts +49 -47
  74. package/dist/channel/channel-event.js +6 -11
  75. package/dist/channel/channel-id.d.ts +22 -0
  76. package/dist/channel/channel-id.js +13 -0
  77. package/dist/channel/channel-index.d.ts +17 -34
  78. package/dist/channel/channel-index.js +41 -80
  79. package/dist/channel/config.d.ts +10 -0
  80. package/dist/channel/config.js +55 -0
  81. package/dist/channel/ingress.d.ts +93 -0
  82. package/dist/channel/ingress.js +5 -0
  83. package/dist/channel/store.d.ts +14 -16
  84. package/dist/channel/store.js +21 -25
  85. package/dist/channel/transport.d.ts +99 -0
  86. package/dist/channel/turn-context.d.ts +23 -0
  87. package/dist/channel/turn-context.js +1 -0
  88. package/dist/commands/catalog.d.ts +4 -7
  89. package/dist/commands/catalog.js +48 -49
  90. package/dist/commands/router.d.ts +28 -14
  91. package/dist/commands/router.js +30 -27
  92. package/dist/config/settings.d.ts +8 -14
  93. package/dist/config/settings.js +0 -7
  94. package/dist/config/tools.d.ts +2 -2
  95. package/dist/config/tools.js +2 -2
  96. package/dist/desk/bindings.d.ts +6 -0
  97. package/dist/desk/bindings.js +105 -0
  98. package/dist/desk/commands.d.ts +81 -0
  99. package/dist/desk/commands.js +145 -0
  100. package/dist/desk/default.d.ts +4 -0
  101. package/dist/desk/default.js +11 -0
  102. package/dist/desk/paths.d.ts +41 -0
  103. package/dist/desk/paths.js +81 -0
  104. package/dist/desk/registry.d.ts +17 -0
  105. package/dist/desk/registry.js +191 -0
  106. package/dist/desk/startup-error.d.ts +4 -0
  107. package/dist/desk/startup-error.js +7 -0
  108. package/dist/desk/types.d.ts +72 -0
  109. package/dist/desk/types.js +7 -0
  110. package/dist/dingtalk/bot.d.ts +20 -35
  111. package/dist/dingtalk/bot.js +25 -204
  112. package/dist/dingtalk/cards.d.ts +7 -0
  113. package/dist/dingtalk/cards.js +32 -2
  114. package/dist/dingtalk/channel-ids.d.ts +15 -0
  115. package/dist/dingtalk/channel-ids.js +39 -0
  116. package/dist/dingtalk/config.d.ts +6 -3
  117. package/dist/dingtalk/config.js +13 -25
  118. package/dist/dingtalk/connection.d.ts +1 -0
  119. package/dist/dingtalk/connection.js +5 -4
  120. package/dist/dingtalk/conversation-meta.d.ts +10 -5
  121. package/dist/dingtalk/conversation-meta.js +72 -50
  122. package/dist/dingtalk/delivery.d.ts +34 -14
  123. package/dist/dingtalk/delivery.js +332 -190
  124. package/dist/dingtalk/inbound-media.d.ts +2 -18
  125. package/dist/dingtalk/inbound-media.js +0 -53
  126. package/dist/dingtalk/inbound.d.ts +10 -11
  127. package/dist/dingtalk/inbound.js +12 -19
  128. package/dist/dingtalk/media.d.ts +9 -11
  129. package/dist/dingtalk/media.js +18 -31
  130. package/dist/dingtalk/progress.d.ts +57 -0
  131. package/dist/dingtalk/progress.js +199 -0
  132. package/dist/dingtalk/response-mode.d.ts +13 -0
  133. package/dist/dingtalk/response-mode.js +31 -0
  134. package/dist/dingtalk/transport.d.ts +47 -0
  135. package/dist/dingtalk/transport.js +71 -0
  136. package/dist/events/commands.d.ts +7 -2
  137. package/dist/events/commands.js +40 -22
  138. package/dist/events/pre-action-error.d.ts +10 -0
  139. package/dist/events/pre-action-error.js +10 -0
  140. package/dist/events/types.d.ts +20 -2
  141. package/dist/events/watcher.d.ts +14 -7
  142. package/dist/events/watcher.js +49 -26
  143. package/dist/file-store.d.ts +4 -0
  144. package/dist/file-store.js +6 -1
  145. package/dist/index.d.ts +4 -2
  146. package/dist/jobs/completion-observer.d.ts +20 -0
  147. package/dist/jobs/completion-observer.js +107 -0
  148. package/dist/jobs/completion-signal.d.ts +9 -0
  149. package/dist/jobs/completion-signal.js +32 -0
  150. package/dist/jobs/completion-wake.d.ts +14 -0
  151. package/dist/jobs/completion-wake.js +25 -0
  152. package/dist/jobs/manager.d.ts +29 -42
  153. package/dist/jobs/manager.js +130 -236
  154. package/dist/jobs/probe.d.ts +3 -0
  155. package/dist/jobs/probe.js +42 -0
  156. package/dist/jobs/record.d.ts +5 -6
  157. package/dist/jobs/record.js +2 -0
  158. package/dist/jobs/runtime.d.ts +28 -0
  159. package/dist/jobs/runtime.js +69 -0
  160. package/dist/log.d.ts +0 -1
  161. package/dist/log.js +1 -1
  162. package/dist/main.js +10 -3
  163. package/dist/memory/boundary-work.d.ts +19 -0
  164. package/dist/memory/boundary-work.js +204 -0
  165. package/dist/memory/commands.d.ts +4 -3
  166. package/dist/memory/commands.js +20 -17
  167. package/dist/memory/desk-memory-queue.d.ts +18 -0
  168. package/dist/memory/desk-memory-queue.js +33 -0
  169. package/dist/memory/index-budget.d.ts +3 -3
  170. package/dist/memory/index-budget.js +21 -18
  171. package/dist/memory/journal.d.ts +6 -6
  172. package/dist/memory/journal.js +16 -15
  173. package/dist/memory/lifecycle.d.ts +17 -28
  174. package/dist/memory/lifecycle.js +87 -147
  175. package/dist/memory/maintenance-state.d.ts +14 -15
  176. package/dist/memory/maintenance-state.js +43 -42
  177. package/dist/memory/reflect-job.d.ts +5 -10
  178. package/dist/memory/reflect-job.js +29 -44
  179. package/dist/memory/reflect.d.ts +6 -1
  180. package/dist/memory/reflect.js +44 -16
  181. package/dist/memory/render.d.ts +1 -1
  182. package/dist/memory/render.js +2 -2
  183. package/dist/memory/review-log.d.ts +17 -4
  184. package/dist/memory/review-log.js +54 -5
  185. package/dist/memory/scheduler.d.ts +12 -19
  186. package/dist/memory/scheduler.js +28 -64
  187. package/dist/memory/search.js +7 -4
  188. package/dist/memory/session-corpus.d.ts +4 -1
  189. package/dist/memory/session-corpus.js +70 -29
  190. package/dist/memory/session-search.d.ts +11 -3
  191. package/dist/memory/session-search.js +14 -11
  192. package/dist/memory/sidecar-worker.d.ts +1 -0
  193. package/dist/memory/sidecar-worker.js +57 -76
  194. package/dist/memory/source-window.d.ts +18 -7
  195. package/dist/memory/source-window.js +59 -29
  196. package/dist/memory/store.d.ts +14 -12
  197. package/dist/memory/store.js +89 -57
  198. package/dist/paths.d.ts +2 -0
  199. package/dist/paths.js +2 -0
  200. package/dist/playbooks/agent-delegation.md +23 -17
  201. package/dist/playbooks/background-jobs.md +7 -5
  202. package/dist/playbooks/event-scheduling.md +9 -7
  203. package/dist/playbooks/memory-and-learning.md +18 -14
  204. package/dist/playbooks/outbound-media.md +3 -3
  205. package/dist/playbooks/runtime-orientation.md +39 -23
  206. package/dist/playbooks/task-lead.md +57 -34
  207. package/dist/runtime/bootstrap.d.ts +45 -35
  208. package/dist/runtime/bootstrap.js +372 -167
  209. package/dist/runtime/channel-queue.d.ts +25 -0
  210. package/dist/{dingtalk → runtime}/channel-queue.js +25 -10
  211. package/dist/runtime/daemon-lock.d.ts +12 -0
  212. package/dist/runtime/daemon-lock.js +28 -0
  213. package/dist/runtime/desk-runtime.d.ts +131 -0
  214. package/dist/runtime/desk-runtime.js +402 -0
  215. package/dist/runtime/durable-dispatch.d.ts +18 -5
  216. package/dist/runtime/durable-dispatch.js +85 -14
  217. package/dist/runtime/inbound-images.d.ts +32 -10
  218. package/dist/runtime/inbound-images.js +95 -21
  219. package/dist/runtime/ingress-busy.d.ts +25 -0
  220. package/dist/runtime/ingress-busy.js +178 -0
  221. package/dist/runtime/ingress-commands.d.ts +7 -0
  222. package/dist/runtime/ingress-commands.js +170 -0
  223. package/dist/runtime/ingress-deps.d.ts +59 -0
  224. package/dist/runtime/ingress-deps.js +1 -0
  225. package/dist/runtime/ingress.d.ts +22 -0
  226. package/dist/runtime/ingress.js +386 -0
  227. package/dist/runtime/request-execution.d.ts +19 -0
  228. package/dist/runtime/request-execution.js +88 -0
  229. package/dist/runtime/shutdown.d.ts +14 -6
  230. package/dist/runtime/shutdown.js +11 -5
  231. package/dist/runtime/task-close.d.ts +4 -0
  232. package/dist/runtime/task-close.js +102 -0
  233. package/dist/runtime/task-control.d.ts +34 -0
  234. package/dist/runtime/task-control.js +225 -0
  235. package/dist/runtime/task-input.d.ts +13 -0
  236. package/dist/runtime/task-input.js +129 -0
  237. package/dist/runtime/task-lane-types.d.ts +123 -0
  238. package/dist/runtime/task-lane-types.js +14 -0
  239. package/dist/runtime/task-lane.d.ts +99 -0
  240. package/dist/runtime/task-lane.js +703 -0
  241. package/dist/runtime/task-pending.d.ts +8 -0
  242. package/dist/runtime/task-pending.js +40 -0
  243. package/dist/runtime/task-spawn.d.ts +8 -8
  244. package/dist/runtime/task-spawn.js +10 -9
  245. package/dist/runtime/task-step.d.ts +32 -0
  246. package/dist/runtime/task-step.js +276 -0
  247. package/dist/runtime/transports.d.ts +32 -0
  248. package/dist/runtime/transports.js +101 -0
  249. package/dist/runtime/turn-run.d.ts +20 -23
  250. package/dist/runtime/turn-run.js +252 -159
  251. package/dist/runtime/wake-coalescing.d.ts +12 -6
  252. package/dist/runtime/wake-coalescing.js +12 -4
  253. package/dist/security/config.js +5 -10
  254. package/dist/security/logger.js +1 -1
  255. package/dist/security/path-guard.js +7 -63
  256. package/dist/security/types.d.ts +27 -30
  257. package/dist/security/types.js +0 -1
  258. package/dist/shared/atomic-file.d.ts +2 -0
  259. package/dist/shared/atomic-file.js +14 -1
  260. package/dist/shared/file-lock.d.ts +35 -0
  261. package/dist/shared/file-lock.js +195 -0
  262. package/dist/shared/format.d.ts +0 -6
  263. package/dist/shared/format.js +0 -17
  264. package/dist/shared/host-process.d.ts +2 -0
  265. package/dist/shared/host-process.js +16 -1
  266. package/dist/shared/jsonl-appender.d.ts +5 -0
  267. package/dist/shared/jsonl-appender.js +25 -2
  268. package/dist/shared/with-timeout.d.ts +2 -0
  269. package/dist/shared/with-timeout.js +21 -0
  270. package/dist/skills/catalog.d.ts +9 -0
  271. package/dist/skills/catalog.js +34 -0
  272. package/dist/skills/commands.d.ts +3 -12
  273. package/dist/skills/commands.js +36 -22
  274. package/dist/skills/loader.d.ts +2 -31
  275. package/dist/skills/loader.js +101 -68
  276. package/dist/skills/roots.d.ts +12 -0
  277. package/dist/skills/roots.js +18 -0
  278. package/dist/skills/types.d.ts +24 -0
  279. package/dist/skills/types.js +1 -0
  280. package/dist/subagents/completion-wake.d.ts +11 -2
  281. package/dist/subagents/completion-wake.js +21 -18
  282. package/dist/subagents/discovery.d.ts +1 -1
  283. package/dist/subagents/discovery.js +10 -16
  284. package/dist/subagents/dispatch.d.ts +0 -10
  285. package/dist/subagents/dispatch.js +18 -44
  286. package/dist/subagents/external/cursor-cli.d.ts +2 -0
  287. package/dist/subagents/external/cursor-cli.js +256 -0
  288. package/dist/subagents/external/dispatch.js +1 -1
  289. package/dist/subagents/external/harness.d.ts +5 -5
  290. package/dist/subagents/external/reconciliation.d.ts +7 -0
  291. package/dist/subagents/external/reconciliation.js +105 -0
  292. package/dist/subagents/external/recovery.d.ts +20 -0
  293. package/dist/subagents/external/recovery.js +71 -0
  294. package/dist/subagents/external/registry.js +2 -0
  295. package/dist/subagents/external/role-warnings.d.ts +17 -0
  296. package/dist/subagents/external/role-warnings.js +42 -0
  297. package/dist/subagents/external/run.d.ts +1 -1
  298. package/dist/subagents/external/run.js +21 -25
  299. package/dist/subagents/format.d.ts +1 -1
  300. package/dist/subagents/format.js +1 -1
  301. package/dist/subagents/grace.d.ts +2 -2
  302. package/dist/subagents/grace.js +3 -3
  303. package/dist/subagents/internal/run.js +8 -6
  304. package/dist/subagents/internal/worker.js +37 -16
  305. package/dist/subagents/result.js +2 -3
  306. package/dist/subagents/run-archive.d.ts +11 -0
  307. package/dist/subagents/run-archive.js +49 -0
  308. package/dist/subagents/run-record.d.ts +13 -15
  309. package/dist/subagents/run-record.js +5 -5
  310. package/dist/subagents/run-registry.d.ts +5 -3
  311. package/dist/subagents/run-registry.js +22 -45
  312. package/dist/subagents/runs.d.ts +51 -54
  313. package/dist/subagents/runs.js +178 -304
  314. package/dist/subagents/task-envelope.js +9 -11
  315. package/dist/subagents/task-settlement.d.ts +3 -0
  316. package/dist/subagents/task-settlement.js +20 -0
  317. package/dist/subagents/types.d.ts +7 -7
  318. package/dist/subagents/workspace-summary.js +5 -1
  319. package/dist/tasks/archive.d.ts +11 -0
  320. package/dist/tasks/archive.js +141 -0
  321. package/dist/tasks/board.d.ts +5 -12
  322. package/dist/tasks/board.js +4 -30
  323. package/dist/tasks/bound-work.d.ts +13 -7
  324. package/dist/tasks/bound-work.js +41 -28
  325. package/dist/tasks/brief.d.ts +39 -15
  326. package/dist/tasks/brief.js +131 -73
  327. package/dist/tasks/budget.d.ts +3 -3
  328. package/dist/tasks/budget.js +9 -4
  329. package/dist/tasks/commands.d.ts +24 -10
  330. package/dist/tasks/commands.js +225 -131
  331. package/dist/tasks/completion.d.ts +12 -0
  332. package/dist/tasks/completion.js +35 -0
  333. package/dist/tasks/contract.d.ts +8 -19
  334. package/dist/tasks/contract.js +41 -45
  335. package/dist/tasks/control.d.ts +138 -0
  336. package/dist/tasks/control.js +1 -0
  337. package/dist/tasks/create.d.ts +4 -2
  338. package/dist/tasks/create.js +13 -7
  339. package/dist/tasks/delivery.d.ts +24 -0
  340. package/dist/tasks/delivery.js +221 -0
  341. package/dist/tasks/file-mutation.d.ts +5 -0
  342. package/dist/tasks/file-mutation.js +38 -0
  343. package/dist/tasks/frontmatter.d.ts +46 -27
  344. package/dist/tasks/frontmatter.js +90 -47
  345. package/dist/tasks/input-receipts.d.ts +7 -0
  346. package/dist/tasks/input-receipts.js +60 -0
  347. package/dist/tasks/loop-log.d.ts +150 -37
  348. package/dist/tasks/loop-log.js +250 -42
  349. package/dist/tasks/mutation-lock.d.ts +7 -5
  350. package/dist/tasks/mutation-lock.js +32 -9
  351. package/dist/tasks/receipts.d.ts +19 -0
  352. package/dist/tasks/receipts.js +48 -0
  353. package/dist/tasks/session-path.d.ts +3 -3
  354. package/dist/tasks/session-path.js +5 -5
  355. package/dist/tasks/state.d.ts +93 -0
  356. package/dist/tasks/state.js +156 -0
  357. package/dist/tasks/store.d.ts +86 -54
  358. package/dist/tasks/store.js +256 -156
  359. package/dist/tools/bash.d.ts +8 -10
  360. package/dist/tools/bash.js +27 -40
  361. package/dist/tools/contract/details.d.ts +6 -6
  362. package/dist/tools/contract/details.js +6 -6
  363. package/dist/tools/contract/execution-trace.d.ts +4 -0
  364. package/dist/tools/contract/execution-trace.js +23 -0
  365. package/dist/tools/contract/names.d.ts +7 -0
  366. package/dist/tools/contract/names.js +22 -0
  367. package/dist/tools/contract/presentation.js +6 -2
  368. package/dist/tools/edit.d.ts +1 -0
  369. package/dist/tools/edit.js +46 -43
  370. package/dist/tools/event-manage.d.ts +3 -1
  371. package/dist/tools/event-manage.js +34 -33
  372. package/dist/tools/glob.js +5 -5
  373. package/dist/tools/grep.js +2 -2
  374. package/dist/tools/index.d.ts +17 -20
  375. package/dist/tools/index.js +28 -22
  376. package/dist/tools/job.d.ts +4 -2
  377. package/dist/tools/job.js +11 -8
  378. package/dist/tools/memory-manage.d.ts +5 -3
  379. package/dist/tools/memory-manage.js +32 -25
  380. package/dist/tools/read.js +1 -1
  381. package/dist/tools/registry.d.ts +19 -19
  382. package/dist/tools/registry.js +65 -34
  383. package/dist/tools/send-media.d.ts +2 -2
  384. package/dist/tools/send-media.js +3 -3
  385. package/dist/tools/session-search.d.ts +3 -1
  386. package/dist/tools/session-search.js +8 -6
  387. package/dist/tools/skill.d.ts +2 -2
  388. package/dist/tools/skill.js +24 -10
  389. package/dist/tools/subagent-manage.d.ts +2 -8
  390. package/dist/tools/subagent-manage.js +26 -19
  391. package/dist/tools/subagent.d.ts +0 -2
  392. package/dist/tools/subagent.js +3 -8
  393. package/dist/tools/task-manage/control-tools.d.ts +4 -0
  394. package/dist/tools/task-manage/control-tools.js +65 -0
  395. package/dist/tools/task-manage/create.js +3 -2
  396. package/dist/tools/task-manage/factory.d.ts +12 -6
  397. package/dist/tools/task-manage/factory.js +73 -58
  398. package/dist/tools/task-manage/lifecycle.d.ts +7 -12
  399. package/dist/tools/task-manage/lifecycle.js +119 -65
  400. package/dist/tools/task-manage/log-view.js +10 -7
  401. package/dist/tools/task-manage/schema.d.ts +21 -26
  402. package/dist/tools/task-manage/schema.js +29 -35
  403. package/dist/tools/task-manage/shared.d.ts +8 -39
  404. package/dist/tools/task-manage/shared.js +20 -69
  405. package/dist/tools/task-manage/step-tools.d.ts +5 -0
  406. package/dist/tools/task-manage/step-tools.js +103 -0
  407. package/dist/tools/task-manage/types.d.ts +33 -21
  408. package/dist/tools/web-cache.d.ts +3 -3
  409. package/dist/tools/web-cache.js +12 -12
  410. package/dist/tools/web-fetch.d.ts +2 -2
  411. package/dist/tools/web-fetch.js +7 -7
  412. package/dist/tools/write-content.d.ts +1 -0
  413. package/dist/tools/write-content.js +7 -2
  414. package/dist/tools/write.d.ts +1 -0
  415. package/dist/tools/write.js +1 -0
  416. package/dist/tui/cli.d.ts +17 -5
  417. package/dist/tui/cli.js +90 -27
  418. package/dist/tui/client.d.ts +26 -0
  419. package/dist/tui/client.js +157 -0
  420. package/dist/tui/colors.d.ts +0 -1
  421. package/dist/tui/colors.js +0 -1
  422. package/dist/tui/commands.d.ts +10 -51
  423. package/dist/tui/commands.js +16 -39
  424. package/dist/tui/frontend.d.ts +2 -2
  425. package/dist/tui/frontend.js +2 -2
  426. package/dist/tui/pitui-frontend.d.ts +0 -2
  427. package/dist/tui/pitui-frontend.js +1 -6
  428. package/dist/tui/render.d.ts +62 -0
  429. package/dist/tui/render.js +123 -0
  430. package/dist/tui/session.d.ts +92 -0
  431. package/dist/tui/session.js +317 -0
  432. package/dist/usage/ledger.d.ts +9 -4
  433. package/dist/usage/ledger.js +2 -0
  434. package/dist/usage/render.d.ts +6 -1
  435. package/dist/usage/render.js +20 -15
  436. package/dist/web/search-providers.js +0 -33
  437. package/dist/webapi/auth.d.ts +13 -0
  438. package/dist/webapi/auth.js +29 -0
  439. package/dist/webapi/config.d.ts +29 -0
  440. package/dist/webapi/config.js +100 -0
  441. package/dist/webapi/errors.d.ts +39 -0
  442. package/dist/webapi/errors.js +32 -0
  443. package/dist/webapi/http.d.ts +25 -0
  444. package/dist/webapi/http.js +4 -0
  445. package/dist/webapi/ids.d.ts +9 -0
  446. package/dist/webapi/ids.js +20 -0
  447. package/dist/webapi/input.d.ts +17 -0
  448. package/dist/webapi/input.js +229 -0
  449. package/dist/webapi/items.d.ts +37 -0
  450. package/dist/webapi/items.js +48 -0
  451. package/dist/webapi/key-command.d.ts +2 -0
  452. package/dist/webapi/key-command.js +110 -0
  453. package/dist/webapi/limits.d.ts +47 -0
  454. package/dist/webapi/limits.js +48 -0
  455. package/dist/webapi/request-policy.d.ts +17 -0
  456. package/dist/webapi/request-policy.js +160 -0
  457. package/dist/webapi/response-record.d.ts +68 -0
  458. package/dist/webapi/response-record.js +58 -0
  459. package/dist/webapi/response-state.d.ts +90 -0
  460. package/dist/webapi/response-state.js +347 -0
  461. package/dist/webapi/routes/conversations.d.ts +8 -0
  462. package/dist/webapi/routes/conversations.js +80 -0
  463. package/dist/webapi/routes/models.d.ts +3 -0
  464. package/dist/webapi/routes/models.js +12 -0
  465. package/dist/webapi/routes/responses.d.ts +8 -0
  466. package/dist/webapi/routes/responses.js +118 -0
  467. package/dist/webapi/routes/websocket.d.ts +9 -0
  468. package/dist/webapi/routes/websocket.js +328 -0
  469. package/dist/webapi/server.d.ts +24 -0
  470. package/dist/webapi/server.js +229 -0
  471. package/dist/webapi/service.d.ts +130 -0
  472. package/dist/webapi/service.js +588 -0
  473. package/dist/webapi/store.d.ts +46 -0
  474. package/dist/webapi/store.js +245 -0
  475. package/dist/webapi/stream.d.ts +13 -0
  476. package/dist/webapi/stream.js +76 -0
  477. package/dist/webapi/transport.d.ts +43 -0
  478. package/dist/webapi/transport.js +100 -0
  479. package/examples/sub-agents/README.md +23 -16
  480. package/examples/sub-agents/agents/claude-high.md +1 -1
  481. package/examples/sub-agents/agents/claude-main.md +1 -1
  482. package/examples/sub-agents/agents/codex-flash.md +1 -1
  483. package/examples/sub-agents/agents/codex-high.md +1 -1
  484. package/examples/sub-agents/agents/codex-main.md +4 -4
  485. package/examples/sub-agents/agents/cursor-high.md +22 -0
  486. package/examples/sub-agents/agents/cursor-main.md +22 -0
  487. package/examples/sub-agents/agents/glm-flash.md +1 -1
  488. package/examples/sub-agents/agents/glm-high.md +2 -2
  489. package/examples/sub-agents/agents/scout.md +30 -0
  490. package/package.json +13 -7
  491. package/dist/channel/channel-paths.d.ts +0 -16
  492. package/dist/channel/channel-paths.js +0 -53
  493. package/dist/channel/commands.d.ts +0 -32
  494. package/dist/channel/commands.js +0 -109
  495. package/dist/channel/project-scope-store.d.ts +0 -51
  496. package/dist/channel/project-scope-store.js +0 -112
  497. package/dist/dingtalk/channel-queue.d.ts +0 -19
  498. package/dist/dingtalk/handler.d.ts +0 -90
  499. package/dist/memory/channel-maintenance-queue.d.ts +0 -5
  500. package/dist/memory/channel-maintenance-queue.js +0 -8
  501. package/dist/runtime/task-driver.d.ts +0 -100
  502. package/dist/runtime/task-driver.js +0 -417
  503. package/dist/runtime/task-migration.d.ts +0 -30
  504. package/dist/runtime/task-migration.js +0 -465
  505. package/dist/runtime/task-wake.d.ts +0 -46
  506. package/dist/runtime/task-wake.js +0 -32
  507. package/dist/runtime/turn-handler.d.ts +0 -47
  508. package/dist/runtime/turn-handler.js +0 -318
  509. package/dist/security/project-scope.d.ts +0 -45
  510. package/dist/security/project-scope.js +0 -105
  511. package/dist/shared/wake-claim.d.ts +0 -23
  512. package/dist/shared/wake-claim.js +0 -26
  513. package/dist/skills/validation.d.ts +0 -8
  514. package/dist/skills/validation.js +0 -91
  515. package/dist/skills/workspace.d.ts +0 -33
  516. package/dist/skills/workspace.js +0 -116
  517. package/dist/tasks/steer.d.ts +0 -8
  518. package/dist/tasks/steer.js +0 -79
  519. package/dist/tasks/ticket.d.ts +0 -71
  520. package/dist/tasks/ticket.js +0 -138
  521. package/dist/tools/task-manage/step-end.d.ts +0 -11
  522. package/dist/tools/task-manage/step-end.js +0 -117
  523. package/dist/tui/app.d.ts +0 -16
  524. package/dist/tui/app.js +0 -166
  525. package/dist/tui/terminal-context.d.ts +0 -27
  526. package/dist/tui/terminal-context.js +0 -84
  527. package/dist/tui/terminal-media-sender.d.ts +0 -9
  528. package/dist/tui/terminal-media-sender.js +0 -15
  529. package/dist/tui/turn-controller.d.ts +0 -64
  530. package/dist/tui/turn-controller.js +0 -311
  531. /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
@@ -7,10 +7,8 @@
7
7
  */
8
8
  import { Agent } from "@earendil-works/pi-agent-core";
9
9
  import { streamSimple } from "@earendil-works/pi-ai/compat";
10
- import { AgentSession, AgentSessionRuntime, convertToLlm, DefaultResourceLoader, } from "@earendil-works/pi-coding-agent";
11
- import { mkdir } from "fs/promises";
12
- import { dirname, join } from "path";
13
- import { commitActiveSessionRef, resolveActiveSessionFile } from "../../channel/active-session-store.js";
10
+ import { AgentSession, AgentSessionRuntime, DefaultResourceLoader, } from "@earendil-works/pi-coding-agent";
11
+ import { commitActiveSessionRef } from "../../channel/active-session-store.js";
14
12
  import { loadToolsConfigWithDiagnostics } from "../../config/tools.js";
15
13
  import * as log from "../../log.js";
16
14
  import { handleMemoryCommand } from "../../memory/commands.js";
@@ -18,23 +16,28 @@ import { hasMemoryBootstrapBlock } from "../../memory/render.js";
18
16
  import { getApiKeyForModel } from "../../models/api-keys.js";
19
17
  import { findExactModelReferenceMatch, hasKnownModelPricing } from "../../models/reference.js";
20
18
  import { createModelRuntime, resolveInitialModel, wrapModelRegistry } from "../../models/runtime.js";
21
- import { formatConfigDiagnostic } from "../../shared/config-diagnostic.js";
22
19
  import { errorMessage } from "../../shared/text-utils.js";
23
20
  import { isRecord } from "../../shared/type-guards.js";
24
21
  import { withTimeout } from "../../shared/with-timeout.js";
25
- import { loadPipiclawSkills, resolvePipiclawSkills } from "../../skills/loader.js";
22
+ import { loadPipiclawSkills } from "../../skills/loader.js";
23
+ import { getSkillRoots } from "../../skills/roots.js";
26
24
  import { discoverSubAgents } from "../../subagents/discovery.js";
27
- import { TASK_SESSIONS_DIRNAME, taskSessionPath } from "../../tasks/session-path.js";
25
+ import { withExecutionTrace } from "../../tools/contract/execution-trace.js";
28
26
  import { createPipiclawTools } from "../../tools/index.js";
29
27
  import { buildPipiclawSystemPrompt } from "../prompt/builder.js";
30
28
  import { createPromptBoundaryExtension } from "../prompt/extension.js";
31
29
  import { measureToolSchemas, TOOL_SCHEMA_TARGET_UNITS, toolSchemaBudgetWarning } from "../prompt/manifest.js";
32
30
  import { loadPlaybooks, loadWorkspacePromptResources } from "../prompt/resources.js";
33
31
  import { createCommandExtension } from "./command-extension.js";
32
+ import { SessionCompaction } from "./compaction.js";
33
+ import { RequestContextInput } from "./context-input.js";
34
34
  import { getLastAssistantUsage, isAutoCompactionEndEvent } from "./event-guards.js";
35
+ import { SessionExecutionTrace } from "./execution-trace.js";
36
+ import { requestTools } from "./request-tools.js";
35
37
  import { asSdkSettingsManager, DEFAULT_MAIN_THINKING_LEVEL, initializeThinkingLevelCompat, setSessionBaseToolsOverride, } from "./session-adapter.js";
36
38
  import { handleSessionEvent } from "./session-events.js";
37
39
  import { SessionResourceGate } from "./session-resource-gate.js";
40
+ import { reportConfigDiagnostics, reportSettingsDiagnostics } from "./settings-diagnostics.js";
38
41
  const MODEL_REGISTRY_REFRESH_TIMEOUT_MS = 15_000;
39
42
  const SESSION_RELOAD_TIMEOUT_MS = 30_000;
40
43
  const CONTEXT_FAULT_MESSAGE = "会话上下文保存失败。请让部署者检查服务器存储后发送 /new 重新开启会话。";
@@ -48,23 +51,10 @@ function plainTextOf(content) {
48
51
  .map((part) => (isRecord(part) && part.type === "text" && typeof part.text === "string" ? part.text : ""))
49
52
  .join("\n");
50
53
  }
51
- /** Task sessions live under `<channelDir>/tasks/.sessions/`; nothing else may be mistaken for one. */
52
- function isTaskSessionPath(sessionFile) {
53
- return sessionFile?.replace(/\\/g, "/").includes(`/${TASK_SESSIONS_DIRNAME}/`) === true;
54
- }
55
- /** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
56
- export function reportSettingsDiagnostics(settingsManager, channelId, appHomeDir) {
57
- for (const { scope, error } of settingsManager.drainErrors()) {
58
- log.logWarn("config.settings.load_failed", "Settings load failed", {
59
- channelId,
60
- reason: error.message,
61
- fields: { scope, path: join(appHomeDir, "settings.json") },
62
- });
63
- }
64
- }
65
54
  export class SessionHost {
66
55
  constructor(deps) {
67
56
  this.deps = deps;
57
+ this.contextInput = new RequestContextInput();
68
58
  /**
69
59
  * Flips true only once `initializeSession` has fully assigned `this.session`
70
60
  * and loaded its resources. Synchronous dispatch-path callers (`isKnownSlashCommand`)
@@ -73,19 +63,29 @@ export class SessionHost {
73
63
  */
74
64
  this.sessionInitialized = false;
75
65
  this.currentTools = [];
66
+ this.retired = false;
76
67
  this.firstTurnMemoryBootstrapPending = true;
77
68
  /** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
78
69
  this.tasksEnabled = true;
79
70
  this.contextFaults = new WeakSet();
80
- this.channelId = deps.channelId;
81
- this.channelDir = deps.channelDir;
71
+ this.conversation = deps.conversation;
72
+ this.channelId = deps.conversation.channelId;
73
+ this.deskDir = deps.conversation.deskDir;
74
+ this.conversationDir = deps.conversation.conversationDir;
75
+ this.trace = new SessionExecutionTrace(deps.profile, () => ({
76
+ desk: this.conversation.desk,
77
+ channelId: this.channelId,
78
+ conversation: this.conversationDir,
79
+ session: this.session?.sessionManager.getSessionId(),
80
+ }));
82
81
  this.workspaceDir = deps.workspaceDir;
82
+ this.describeConversation = deps.describeConversation;
83
83
  this.appHomeDir = deps.appHomeDir;
84
84
  this.authConfigPath = deps.authConfigPath;
85
85
  this.modelsConfigPath = deps.modelsConfigPath;
86
86
  this.onSessionEvent = deps.onSessionEvent;
87
- this.mediaSender = deps.mediaSender;
88
- this.projectScope = deps.projectScope;
87
+ this.sendMedia = deps.sendMedia;
88
+ this.cwd = deps.cwd;
89
89
  this.settingsManager = deps.settingsManager;
90
90
  this.loadSecurityConfig = deps.loadSecurityConfig;
91
91
  this.executor = deps.executor;
@@ -96,6 +96,20 @@ export class SessionHost {
96
96
  this.models = deps.models;
97
97
  this.ledger = deps.ledger;
98
98
  this.currentSkills = deps.initialSkills;
99
+ this.compaction = new SessionCompaction({
100
+ conversation: this.conversation,
101
+ getSession: () => this.session,
102
+ getRuntime: () => this.modelRuntime,
103
+ preserveMemory: (event) => this.memoryLifecycle.prepareCompaction(event),
104
+ ledger: this.ledger,
105
+ getRunState: () => this.runState,
106
+ isEnabled: () => this.settingsManager.getCompactionEnabled(),
107
+ onPersistenceFault: (session, error) => this.markContextFault(session, error, "background-compaction"),
108
+ onAdopt: () => {
109
+ this.firstTurnMemoryBootstrapPending = true;
110
+ void this.memoryLifecycle.resumeBoundaryReflect();
111
+ },
112
+ });
99
113
  this.sessionResourceGate = new SessionResourceGate(async () => {
100
114
  await this.reloadSessionResources();
101
115
  });
@@ -106,6 +120,12 @@ export class SessionHost {
106
120
  get agent() {
107
121
  return this.session.agent;
108
122
  }
123
+ importContext(context) {
124
+ this.contextInput.import(this.session, context);
125
+ }
126
+ async promptContext(context, submit) {
127
+ await this.contextInput.prompt(this.session, context, submit ? "" : (this.lastPromptBuild?.footer ?? ""), submit);
128
+ }
109
129
  get sessionManager() {
110
130
  return this.session.sessionManager;
111
131
  }
@@ -113,12 +133,12 @@ export class SessionHost {
113
133
  start(sessionManager) {
114
134
  this.sessionReady = this.initializeSession(sessionManager);
115
135
  }
116
- markContextFault(session, error) {
136
+ markContextFault(session, error, stage = "fallback-context-edit") {
117
137
  this.contextFaults.add(session);
118
138
  log.logWarn("agent.session.context_failed", "Session context persistence failed", {
119
139
  channelId: this.channelId,
120
140
  reason: errorMessage(error),
121
- fields: { sessionId: session.sessionManager.getSessionId(), stage: "fallback-context-edit" },
141
+ fields: { sessionId: session.sessionManager.getSessionId(), stage },
122
142
  });
123
143
  return new Error(CONTEXT_FAULT_MESSAGE, { cause: error });
124
144
  }
@@ -135,9 +155,11 @@ export class SessionHost {
135
155
  }
136
156
  /** Stop listening to the live session and dispose it (no-op error handling is the caller's). */
137
157
  retireLiveSession() {
158
+ this.retired = true;
159
+ this.compaction.retire();
138
160
  this.sessionUnsubscribe?.();
139
161
  this.sessionUnsubscribe = undefined;
140
- this.session.dispose();
162
+ this.session?.dispose();
141
163
  }
142
164
  /**
143
165
  * Release the session once idle. Guards a dispose() racing construction: initializeSession
@@ -145,6 +167,7 @@ export class SessionHost {
145
167
  * not have one yet.
146
168
  */
147
169
  async disposeSession() {
170
+ this.compaction.retire();
148
171
  await this.sessionReady;
149
172
  this.sessionUnsubscribe?.();
150
173
  this.sessionUnsubscribe = undefined;
@@ -175,17 +198,23 @@ export class SessionHost {
175
198
  this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
176
199
  const initial = await this.createSessionRuntime(sessionManager);
177
200
  this.session = initial.session;
201
+ if (this.retired) {
202
+ this.session.dispose();
203
+ throw new Error("Session generation retired");
204
+ }
178
205
  this.sessionRuntime = new AgentSessionRuntime(this.session, this.createAgentSessionServices(initial.resourceLoader), async ({ sessionManager, sessionStartEvent }) => {
206
+ if (this.retired)
207
+ throw new Error("Session generation retired");
179
208
  // `/new`, fork, and switch already wrote the target session's durable header by
180
209
  // this point (the SDK does it synchronously before invoking this callback); commit
181
210
  // the pointer before we rebuild and rebind to it, so a crash between "SDK created
182
211
  // session" and "we finished rebinding" leaves the old ref (and old session)
183
212
  // authoritative rather than an orphaned new file (spec 043, D1.3).
184
- // A task session is not the channel's chat session: never repoint the active-session
185
- // ref at it, or `/new` and restart recovery would adopt a task's transcript as the
186
- // conversation (spec 051, D3).
187
- if (!isTaskSessionPath(sessionManager.getSessionFile())) {
188
- await commitActiveSessionRef(this.channelDir, sessionManager);
213
+ // Only a chat owns an active-session ref: a task session or a request must never
214
+ // repoint it, or `/new` and restart recovery would adopt their transcript as the
215
+ // conversation (spec 051, D3; spec 064, D13).
216
+ if (this.deps.profile.kind === "chat") {
217
+ await commitActiveSessionRef(this.conversationDir, sessionManager);
189
218
  }
190
219
  const next = await this.createSessionRuntime(sessionManager, sessionStartEvent);
191
220
  return {
@@ -196,6 +225,11 @@ export class SessionHost {
196
225
  };
197
226
  });
198
227
  this.sessionRuntime.setRebindSession(async (session) => {
228
+ this.compaction.cancel("session-rebind");
229
+ if (this.retired) {
230
+ session.dispose();
231
+ throw new Error("Session generation retired");
232
+ }
199
233
  this.session = session;
200
234
  await this.bindSessionExtensions();
201
235
  this.subscribeToSessionEvents();
@@ -210,11 +244,18 @@ export class SessionHost {
210
244
  this.sessionInitialized = true;
211
245
  }
212
246
  async reloadSessionResources() {
247
+ if (this.retired)
248
+ return;
213
249
  this.settingsManager.reload();
214
- this.reportSettingsDiagnostics();
215
- const skills = loadPipiclawSkills(this.channelDir);
216
- this.currentSkills = skills;
250
+ reportSettingsDiagnostics(this.settingsManager, this.channelId, this.appHomeDir);
251
+ this.currentSkills = loadPipiclawSkills({
252
+ workspaceDir: this.workspaceDir,
253
+ securityConfig: this.loadSecurityConfig().config,
254
+ securityContext: { agentWorkspaceDir: this.workspaceDir, cwd: this.cwd },
255
+ });
217
256
  this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
257
+ if (this.retired)
258
+ return;
218
259
  this.rebuildSessionTools();
219
260
  try {
220
261
  await withTimeout(`[${this.channelId}] session reload`, SESSION_RELOAD_TIMEOUT_MS, () => this.session.reload());
@@ -277,27 +318,7 @@ export class SessionHost {
277
318
  }
278
319
  return discovery;
279
320
  }
280
- reportSettingsDiagnostics() {
281
- reportSettingsDiagnostics(this.settingsManager, this.channelId, this.appHomeDir);
282
- }
283
- reportConfigDiagnostics(diagnostics) {
284
- for (const diagnostic of diagnostics) {
285
- log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), {
286
- channelId: this.channelId,
287
- fields: { path: diagnostic.path },
288
- });
289
- }
290
- }
291
- /**
292
- * Build the Pipiclaw-owned system prompt (spec 025). This replaces pi's default
293
- * base prompt entirely: identity, execution contract, hard invariants, the tool
294
- * catalog and the workspace files are ours. pi still appends its tail (skills,
295
- * date, cwd), and the boundary footer is appended after that by the prompt
296
- * extension.
297
- *
298
- * Nothing channel-specific enters this text — that is what lets two channels in
299
- * one workspace share a cached prompt prefix. Channel facts ride the turn.
300
- */
321
+ /** Build the shared Pipiclaw prompt; channel facts stay in turn context and pi appends its tail. */
301
322
  buildSystemPrompt() {
302
323
  const toolNames = this.currentTools.map((tool) => tool.name);
303
324
  const resources = loadWorkspacePromptResources(this.workspaceDir);
@@ -338,10 +359,11 @@ export class SessionHost {
338
359
  }
339
360
  createResourceLoader() {
340
361
  return new DefaultResourceLoader({
341
- cwd: this.projectScope.projectRoot,
362
+ cwd: this.cwd,
342
363
  agentDir: this.appHomeDir,
343
364
  settingsManager: asSdkSettingsManager(this.settingsManager),
344
365
  extensionFactories: [
366
+ this.compaction.createExtensionFactory(),
345
367
  this.memoryLifecycle.createExtensionFactory(),
346
368
  createPromptBoundaryExtension({
347
369
  getFooter: () => this.lastPromptBuild?.footer ?? "",
@@ -367,12 +389,9 @@ export class SessionHost {
367
389
  // Manual /model switch redefines the preferred model and clears fallback state.
368
390
  this.models.clearFallbackState();
369
391
  },
370
- refreshSessionResources: async () => {
371
- await this.refreshSessionResources();
372
- },
392
+ refreshSessionResources: () => this.refreshSessionResources(),
373
393
  runMemoryCommand: async (args) => handleMemoryCommand({
374
- channelId: this.channelId,
375
- channelDir: this.channelDir,
394
+ conversation: this.conversation,
376
395
  appHomeDir: this.appHomeDir,
377
396
  args,
378
397
  }),
@@ -385,24 +404,23 @@ export class SessionHost {
385
404
  // APPEND_SYSTEM.md, not a base append. SOUL/AGENTS are rendered as sections.
386
405
  appendSystemPromptOverride: () => [],
387
406
  agentsFilesOverride: () => ({ agentsFiles: [] }),
388
- // Skills stay in the ResourceLoader: they drive `/skill:name` and pi's
389
- // `<available_skills>` index together. Only the merge policy is ours.
390
- skillsOverride: (base) => {
391
- const merged = resolvePipiclawSkills(base, this.currentSkills);
392
- for (const diagnostic of merged.diagnostics) {
393
- log.logWarn("agent.skills.diagnostic", "Skill diagnostic", {
407
+ // SDK renders/expands skills; only our two-source catalog may enter the session.
408
+ noSkills: true,
409
+ skillsOverride: () => {
410
+ for (const diagnostic of this.currentSkills.diagnostics) {
411
+ log.logWarn("agent.skills.load", "Skill loading failed", {
394
412
  channelId: this.channelId,
395
413
  reason: diagnostic.message,
396
414
  fields: { type: diagnostic.type, path: diagnostic.path },
397
415
  });
398
416
  }
399
- return merged;
417
+ return this.currentSkills;
400
418
  },
401
419
  });
402
420
  }
403
421
  createAgentSessionServices(resourceLoader) {
404
422
  return {
405
- cwd: this.projectScope.projectRoot,
423
+ cwd: this.cwd,
406
424
  agentDir: this.appHomeDir,
407
425
  settingsManager: asSdkSettingsManager(this.settingsManager),
408
426
  modelRuntime: this.modelRuntime,
@@ -440,6 +458,8 @@ export class SessionHost {
440
458
  initializeThinkingLevelCompat(agent, model, sessionManager, this.settingsManager.getDefaultThinkingLevel());
441
459
  }
442
460
  async createSessionRuntime(sessionManager, sessionStartEvent) {
461
+ if (this.retired)
462
+ throw new Error("Session generation retired");
443
463
  const tools = this.buildRuntimeTools();
444
464
  const agent = new Agent({
445
465
  initialState: {
@@ -449,21 +469,26 @@ export class SessionHost {
449
469
  tools: [],
450
470
  messages: sessionManager.buildSessionContext().messages,
451
471
  },
452
- convertToLlm,
472
+ convertToLlm: (messages) => this.contextInput.convert(messages),
453
473
  getApiKey: async () => getApiKeyForModel(this.modelRegistry, this.models.activeModel),
454
- streamFn: streamSimple,
474
+ streamFn: (model, context, options) => {
475
+ this.trace.startRequest();
476
+ return streamSimple(model, context, options);
477
+ },
455
478
  });
456
479
  this.initializeThinkingLevel(agent, this.models.activeModel, sessionManager);
457
480
  const resourceLoader = this.createResourceLoader();
458
481
  // Must precede `new AgentSession`: the session snapshots the loader's extensions in its
459
482
  // constructor (see `loadSessionResources`).
460
483
  await this.loadSessionResources(resourceLoader);
484
+ if (this.retired)
485
+ throw new Error("Session generation retired");
461
486
  const sessionSettingsManager = asSdkSettingsManager(this.settingsManager);
462
487
  const session = new AgentSession({
463
488
  agent,
464
489
  sessionManager,
465
490
  settingsManager: sessionSettingsManager,
466
- cwd: this.projectScope.projectRoot,
491
+ cwd: this.cwd,
467
492
  modelRuntime: this.modelRuntime,
468
493
  resourceLoader,
469
494
  baseToolsOverride: Object.fromEntries(tools.map((tool) => [tool.name, tool])),
@@ -473,52 +498,26 @@ export class SessionHost {
473
498
  this.sessionSettingsManager = sessionSettingsManager;
474
499
  return { session, resourceLoader };
475
500
  }
476
- /**
477
- * Bind this runner to a task cycle's own session (spec 051, D3/INV-5).
478
- *
479
- * Task work must not accumulate in the channel's chat transcript: the one real channel on the
480
- * author's machine had grown to 7.4 MB and been compacted six times because chat and two daily
481
- * tasks shared it, so every compaction damaged all three at once. Swapping the bound session
482
- * per turn gives each task its own bounded context while leaving turn state, `/stop`, and
483
- * delivery exactly where they already are.
484
- */
485
- async bindTaskSession(taskId) {
486
- await this.sessionReady;
487
- const path = taskSessionPath(this.channelDir, taskId);
488
- await mkdir(dirname(path), { recursive: true });
489
- this.taskLoop = { taskId };
490
- await this.sessionRuntime.switchSession(path);
491
- this.syncMemoryBootstrapPendingFromSession();
492
- }
493
- /** Return to the channel's chat session after a task step. Safe to call when already bound. */
494
- async bindChatSession() {
495
- if (!this.taskLoop)
496
- return;
497
- this.taskLoop = undefined;
498
- await this.sessionRuntime.switchSession(join(this.channelDir, resolveActiveSessionFile(this.channelDir)));
499
- this.syncMemoryBootstrapPendingFromSession();
500
- }
501
501
  /** Bootstrap presence follows canonical context, including omissions and compaction.
502
- * Returning from a task or restarting must neither duplicate a visible bootstrap nor
503
- * mistake an omitted failed input for one. Raw messages remain available to memory/recovery.
502
+ * Restarting must neither duplicate a visible bootstrap nor mistake an omitted failed input for
503
+ * one. Raw messages remain available to memory/recovery.
504
504
  */
505
505
  syncMemoryBootstrapPendingFromSession() {
506
- const injected = this.sessionManager.buildSessionContext().messages.some((value) => {
506
+ this.firstTurnMemoryBootstrapPending = !this.contextIncludes((text) => hasMemoryBootstrapBlock(text));
507
+ }
508
+ /** Whether any user message of the session's canonical context satisfies `matches` (spec 064, D15). */
509
+ contextIncludes(matches) {
510
+ return this.sessionManager.buildSessionContext().messages.some((value) => {
507
511
  const message = value;
508
512
  if (!isRecord(message))
509
513
  return false;
510
- return message.role === "user" && hasMemoryBootstrapBlock(plainTextOf(message.content));
514
+ return message.role === "user" && matches(plainTextOf(message.content));
511
515
  });
512
- this.firstTurnMemoryBootstrapPending = !injected;
513
- }
514
- /** Which task loop this runner is currently bound to, if any. */
515
- getTaskLoop() {
516
- return this.taskLoop;
517
516
  }
518
517
  buildRuntimeTools() {
519
518
  const securityLoad = this.loadSecurityConfig();
520
519
  const toolsLoad = loadToolsConfigWithDiagnostics(this.appHomeDir);
521
- this.reportConfigDiagnostics([...securityLoad.diagnostics, ...toolsLoad.diagnostics]);
520
+ reportConfigDiagnostics([...securityLoad.diagnostics, ...toolsLoad.diagnostics], this.channelId);
522
521
  this.tasksEnabled = toolsLoad.config.tools.tasks.enabled;
523
522
  const tools = createPipiclawTools({
524
523
  jobManager: this.jobManager,
@@ -529,33 +528,33 @@ export class SessionHost {
529
528
  getAvailableModels: () => this.modelRegistry.getAvailable(),
530
529
  resolveApiKey: async (model) => getApiKeyForModel(this.modelRegistry, model),
531
530
  workspaceDir: this.workspaceDir,
532
- projectScope: this.projectScope,
533
- channelDir: this.channelDir,
531
+ cwd: this.cwd,
532
+ desk: this.conversation.desk,
533
+ deskDir: this.deskDir,
534
534
  channelId: this.channelId,
535
+ describeConversation: this.describeConversation,
535
536
  getSubAgentDiscovery: () => this.subAgentDiscovery,
536
537
  getSubAgentModelReference: () => this.settingsManager.getSubAgentModelReference(),
537
538
  resolveFallbackModel: () => this.models.resolveFallbackModel(),
538
539
  getSessionSearchSettings: () => this.settingsManager.getSessionSearchSettings(),
539
540
  securityConfig: securityLoad.config,
540
541
  toolsConfig: toolsLoad.config,
541
- mediaSender: this.mediaSender,
542
- taskLoop: this.taskLoop,
543
- getToolsUsed: () => this.runState.toolsUsed,
544
- // Assistant usage only: an internal sub-agent's cost is also in `totalUsage`, and a bound
545
- // one is already credited to the task when it settles.
546
- getStepCost: () => ({ usd: this.runState.assistantUsage.cost.total, estimated: !this.runState.costKnown }),
542
+ sendMedia: this.sendMedia,
543
+ ...(this.deps.profile.kind === "task" ? { taskSession: this.deps.profile.session } : {}),
544
+ ...(this.deps.profile.kind === "chat" ? { taskControl: this.deps.getTaskControl?.() } : {}),
547
545
  });
548
- this.currentTools = tools;
546
+ const active = this.deps.profile.kind === "request" ? requestTools(tools) : tools;
547
+ this.currentTools = active;
549
548
  // Tool schemas are billed with the system prompt and, unlike it, nothing trims them.
550
549
  // Warn where the prompt's own budget diagnostics are reported, once per tool rebuild.
551
- const schemas = measureToolSchemas(tools);
550
+ const schemas = measureToolSchemas(active);
552
551
  if (schemas.units > TOOL_SCHEMA_TARGET_UNITS) {
553
552
  log.logWarn("agent.tools.schema_over_budget", "Tool schemas over budget", {
554
553
  channelId: this.channelId,
555
554
  reason: toolSchemaBudgetWarning(schemas),
556
555
  });
557
556
  }
558
- return tools;
557
+ return active.map((tool) => withExecutionTrace(tool, () => this.trace.fields()));
559
558
  }
560
559
  rebuildSessionTools() {
561
560
  const tools = this.buildRuntimeTools();
@@ -577,6 +576,7 @@ export class SessionHost {
577
576
  reason: errorMessage(err),
578
577
  });
579
578
  }
579
+ this.trace.observe(event);
580
580
  if (isRecord(event) && event.type === "message_start") {
581
581
  this.deps.markStreaming();
582
582
  }
@@ -606,10 +606,8 @@ export class SessionHost {
606
606
  const model = findExactModelReferenceMatch(reference, this.modelRegistry.getAvailable()).match;
607
607
  return model ? hasKnownModelPricing(model) : false;
608
608
  },
609
- refreshSessionResources: async () => {
610
- await this.refreshSessionResources();
611
- },
612
- skillsDir: join(this.workspaceDir, "skills"),
609
+ refreshSessionResources: () => this.refreshSessionResources(),
610
+ skillsDirs: getSkillRoots(this.workspaceDir).map(({ dir }) => dir),
613
611
  }).catch((err) => {
614
612
  log.logWarn("agent.session.handler_failed", "Session event handler failed", {
615
613
  channelId: this.channelId,
@@ -0,0 +1,5 @@
1
+ import type { PipiclawSettingsManager } from "../../config/settings.js";
2
+ import { type ConfigDiagnostic } from "../../shared/config-diagnostic.js";
3
+ /** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
4
+ export declare function reportSettingsDiagnostics(settingsManager: PipiclawSettingsManager, channelId: string, appHomeDir: string): void;
5
+ export declare function reportConfigDiagnostics(diagnostics: ConfigDiagnostic[], channelId: string): void;
@@ -0,0 +1,21 @@
1
+ import { join } from "node:path";
2
+ import * as log from "../../log.js";
3
+ import { formatConfigDiagnostic } from "../../shared/config-diagnostic.js";
4
+ /** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
5
+ export function reportSettingsDiagnostics(settingsManager, channelId, appHomeDir) {
6
+ for (const { scope, error } of settingsManager.drainErrors()) {
7
+ log.logWarn("config.settings.load_failed", "Settings load failed", {
8
+ channelId,
9
+ reason: error.message,
10
+ fields: { scope, path: join(appHomeDir, "settings.json") },
11
+ });
12
+ }
13
+ }
14
+ export function reportConfigDiagnostics(diagnostics, channelId) {
15
+ for (const diagnostic of diagnostics) {
16
+ log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), {
17
+ channelId: channelId,
18
+ fields: { path: diagnostic.path },
19
+ });
20
+ }
21
+ }
@@ -24,9 +24,12 @@ export function renderStatus(options) {
24
24
  runState = "空闲";
25
25
  }
26
26
  const lines = [`**状态** · ${runState}`];
27
- if (runner) {
27
+ const snapshot = runner?.getStatusSnapshot();
28
+ if (runner && !snapshot) {
29
+ lines.push("- 模型:会话正在启动,稍后再试");
30
+ }
31
+ else if (runner && snapshot) {
28
32
  try {
29
- const snapshot = runner.getStatusSnapshot();
30
33
  let modelLine = `- 模型:\`${snapshot.model}\`(思考档位 \`${snapshot.thinkingLevel}\`)`;
31
34
  if (snapshot.fallback) {
32
35
  const until = new Date(snapshot.fallback.cooldownUntilMs);
@@ -2,7 +2,7 @@
2
2
  * The `/stop` watchdog: a stopped turn that never ends is force-released after a grace window, so
3
3
  * the channel does not keep reporting "a turn is already running".
4
4
  */
5
- import type { AgentRunner } from "../agent/types.js";
5
+ import type { AgentRunner } from "./types.js";
6
6
  /**
7
7
  * Watchdog for `/stop`: release the channel if the stopped turn has not ended
8
8
  * once the grace window elapses. Returns true when it had to force the release.
@@ -13,4 +13,6 @@ export declare function forceEndStuckTurnAfterStop(input: {
13
13
  graceMs?: number;
14
14
  pollMs?: number;
15
15
  notify?: (text: string) => Promise<unknown>;
16
+ isCurrent?: () => boolean;
17
+ recover?: () => void;
16
18
  }): Promise<boolean>;
@@ -9,7 +9,7 @@ import { sleepUnref } from "../shared/with-timeout.js";
9
9
  * epilogue (delivery drain, session-resource reload, memory flush) ignores both
10
10
  * and would otherwise keep the channel reporting "已有回合在运行" indefinitely.
11
11
  */
12
- const STOP_FORCE_END_GRACE_MS = 15_000;
12
+ const STOP_FORCE_END_GRACE_MS = 3_000;
13
13
  const STOP_FORCE_END_POLL_MS = 250;
14
14
  /**
15
15
  * Watchdog for `/stop`: release the channel if the stopped turn has not ended
@@ -19,14 +19,18 @@ export async function forceEndStuckTurnAfterStop(input) {
19
19
  const graceMs = input.graceMs ?? STOP_FORCE_END_GRACE_MS;
20
20
  const pollMs = input.pollMs ?? STOP_FORCE_END_POLL_MS;
21
21
  const deadline = Date.now() + graceMs;
22
- while (input.runner.isBusy() && Date.now() < deadline) {
22
+ const stopped = () => input.runner.isBusy() && input.runner.getTurnStatus().stopRequested && (input.isCurrent?.() ?? true);
23
+ while (stopped() && Date.now() < deadline) {
23
24
  await sleepUnref(Math.min(pollMs, Math.max(1, deadline - Date.now())));
24
25
  }
26
+ if (!stopped())
27
+ return false;
25
28
  if (!input.runner.forceEndTurn(`/stop did not take effect within ${graceMs}ms`)) {
26
29
  return false;
27
30
  }
31
+ input.recover?.();
28
32
  await input
29
- .notify?.(`⚠️ 上一个回合的收尾卡住了,已强制结束以释放会话(后台清理仍在继续)。现在可以正常发消息或使用 \`/new\`、\`/model\`。`)
33
+ .notify?.(`⚠️ 上一个回合未能及时停止,已隔离并恢复原会话。现在可以继续发消息,或使用 \`/new\`、\`/model\`。`)
30
34
  .catch(() => undefined);
31
35
  return true;
32
36
  }
@@ -1,7 +1,6 @@
1
1
  /**
2
- * Formatting helpers for turn progress entries and for clipping over-length user input.
2
+ * Helpers for clipping over-length user input and for reading a tool result as text.
3
3
  */
4
- import type { ProgressEntryKind } from "../types.js";
5
4
  /**
6
5
  * Head + tail of an over-length message, with the middle replaced by a marker.
7
6
  *
@@ -12,5 +11,4 @@ import type { ProgressEntryKind } from "../types.js";
12
11
  * in this runtime follows).
13
12
  */
14
13
  export declare function clipUserInput(text: string, maxChars: number, fullTextPath?: string): string;
15
- export declare function formatProgressEntry(kind: ProgressEntryKind, text: string): string;
16
14
  export declare function extractToolResultText(result: unknown): string;
@@ -1,9 +1,6 @@
1
- function sanitizeProgressText(text) {
2
- return text
3
- .replace(/\uFFFC/g, "")
4
- .replace(/\r/g, "")
5
- .trim();
6
- }
1
+ /**
2
+ * Helpers for clipping over-length user input and for reading a tool result as text.
3
+ */
7
4
  /**
8
5
  * Head + tail of an over-length message, with the middle replaced by a marker.
9
6
  *
@@ -25,22 +22,6 @@ export function clipUserInput(text, maxChars, fullTextPath) {
25
22
  : "";
26
23
  return `${normalized.slice(0, headChars)}\n\n[... omitted ${normalized.length - maxChars} chars${recovery} ...]\n\n${normalized.slice(-tailChars)}`;
27
24
  }
28
- export function formatProgressEntry(kind, text) {
29
- const cleaned = sanitizeProgressText(text);
30
- if (!cleaned)
31
- return "";
32
- const normalized = cleaned.replace(/\n+/g, " ").trim();
33
- switch (kind) {
34
- case "tool":
35
- return `➜ ${normalized}`;
36
- case "thinking":
37
- return `✦ ${normalized}`;
38
- case "error":
39
- return `✕ ${normalized}`;
40
- case "assistant":
41
- return normalized;
42
- }
43
- }
44
25
  export function extractToolResultText(result) {
45
26
  if (typeof result === "string") {
46
27
  return result;
@@ -10,17 +10,18 @@ export declare const TASK_AGENDA_MAX_UNITS = 600;
10
10
  * reference, not instruction, so it can never turn an unrelated user turn into task work.
11
11
  */
12
12
  export interface TaskDigestOptions {
13
- /** The channel directory; tasks live in `<channelDir>/tasks/`. */
14
- channelDir: string;
13
+ /** The desk directory; tasks live in `<deskDir>/tasks/`. */
14
+ deskDir: string;
15
+ /** The asking channel: a task delivering to another channel is marked, as it reports there. */
16
+ channelId?: string;
15
17
  maxTasks: number;
16
18
  maxChars: number;
17
19
  /** Runtime hard cap in prompt units (spec 026 §5.3); whichever of chars/units is hit first clips. */
18
20
  maxUnits?: number;
19
- now?: number;
20
21
  }
21
22
  /**
22
23
  * Render the in-flight task agenda, or `""` when there are no live tasks to show.
23
- * Parked and paused tasks stay visible so the model can distinguish dormant work from lost work
24
+ * Waiting and paused tasks stay visible so the model can distinguish dormant work from lost work
24
25
  * and tell the user what each one is waiting for.
25
26
  */
26
27
  export declare function buildTaskDigest(options: TaskDigestOptions): Promise<string>;