@zhushanwen/subagent-core 0.2.0 → 0.5.1

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 (347) hide show
  1. package/README.md +45 -2
  2. package/agents/analyst.md +60 -0
  3. package/agents/coder.md +69 -0
  4. package/agents/debugger.md +66 -0
  5. package/agents/doc-reviewer.md +49 -0
  6. package/agents/explorer.md +63 -0
  7. package/agents/general-purpose.md +32 -0
  8. package/agents/orchestrator.md +61 -0
  9. package/agents/planner.md +53 -0
  10. package/agents/researcher.md +67 -0
  11. package/agents/reviewer.md +73 -0
  12. package/dist/chunk-43ONBFZX.js +240 -0
  13. package/dist/chunk-APZY4IME.js +27 -0
  14. package/dist/chunk-V3VHZ2VX.js +59 -0
  15. package/dist/execution/engine/engines/zcode/constants.cjs +62 -9
  16. package/dist/execution/engine/engines/zcode/constants.d.cts +116 -12
  17. package/dist/execution/engine/engines/zcode/constants.d.ts +116 -12
  18. package/dist/execution/engine/engines/zcode/constants.js +39 -7
  19. package/dist/execution/engine/engines/zcode/reader.d.cts +2 -1
  20. package/dist/execution/engine/engines/zcode/reader.d.ts +2 -1
  21. package/dist/execution/engine/engines/zcode/reader.js +4 -234
  22. package/dist/execution/engine/paths.js +7 -19
  23. package/dist/index.cjs +18234 -1277
  24. package/dist/index.d.cts +5646 -673
  25. package/dist/index.d.ts +5646 -673
  26. package/dist/index.js +17828 -1277
  27. package/dist/{types-BxyAidGf.d.cts → types-Dv4QhSJ_.d.cts} +678 -112
  28. package/dist/{types-BxyAidGf.d.ts → types-Dv4QhSJ_.d.ts} +678 -112
  29. package/package.json +7 -4
  30. package/src/__tests__/agent-opts-resolver-schema-prompt.test.ts +0 -1
  31. package/src/__tests__/append-system-prompt-assembly.test.ts +8 -7
  32. package/src/__tests__/fr4-get-state-handshake.test.ts +2 -2
  33. package/src/__tests__/m2-append-content-probe.test.ts +0 -1
  34. package/src/__tests__/manifest-store.test.ts +10 -9
  35. package/src/__tests__/record-store-cache.test.ts +0 -2
  36. package/src/__tests__/record-store-index.test.ts +1 -2
  37. package/src/__tests__/review-fix-loop-script.test.ts +93 -3
  38. package/src/__tests__/review-fix-loop-utils.test.ts +31 -10
  39. package/src/__tests__/robustness-low-batch1.test.ts +6 -5
  40. package/src/__tests__/robustness-medium-batch1.test.ts +2 -2
  41. package/src/__tests__/robustness-medium-batch2.test.ts +17 -6
  42. package/src/__tests__/robustness-medium-batch4.test.ts +2 -2
  43. package/src/__tests__/session-runner.test.ts +1 -1
  44. package/src/__tests__/smoke.test.ts +9 -2
  45. package/src/core/__tests__/host-services.test.ts +2 -2
  46. package/src/core/__tests__/logger.test.ts +1 -1
  47. package/src/core/error-message.ts +9 -0
  48. package/src/core/host-services.ts +21 -5
  49. package/src/core/notify-ports.ts +18 -5
  50. package/src/execution/__tests__/agent-profile.test.ts +232 -0
  51. package/src/execution/__tests__/agent-registry.test.ts +370 -0
  52. package/src/execution/__tests__/agent-result-mapper.test.ts +18 -2
  53. package/src/execution/__tests__/agents-assembly.test.ts +219 -0
  54. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +6 -6
  55. package/src/execution/__tests__/chat-engine-routing.test.ts +136 -30
  56. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +5 -4
  57. package/src/execution/__tests__/cold-resurrect.test.ts +283 -0
  58. package/src/execution/__tests__/create-concurrency-pool.test.ts +194 -0
  59. package/src/execution/__tests__/delivery-methods.test.ts +77 -62
  60. package/src/execution/__tests__/descendant-sweep-guards.test.ts +220 -0
  61. package/src/execution/__tests__/descendant-sweep.test.ts +269 -0
  62. package/src/execution/__tests__/dialog-queue.test.ts +199 -1
  63. package/src/execution/__tests__/engine-model-validation.test.ts +741 -0
  64. package/src/execution/__tests__/epipe-fallback.test.ts +31 -24
  65. package/src/execution/__tests__/execute-and-await-worktree.test.ts +21 -91
  66. package/src/execution/__tests__/execute-nesting.test.ts +34 -188
  67. package/src/execution/__tests__/execution-record.test.ts +217 -60
  68. package/src/execution/__tests__/execution-runtime-face.test.ts +272 -0
  69. package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +3 -3
  70. package/src/execution/__tests__/finalize-record.test.ts +278 -16
  71. package/src/execution/__tests__/gc-timer.test.ts +57 -2
  72. package/src/execution/__tests__/get-record-for-action-restart.test.ts +14 -12
  73. package/src/execution/__tests__/get-state-handshake.test.ts +127 -0
  74. package/src/execution/__tests__/helpers/mock-extension-api.ts +1 -1
  75. package/src/execution/__tests__/helpers/session-runner-mocks.ts +113 -0
  76. package/src/execution/__tests__/helpers/spawn-mock.ts +150 -3
  77. package/src/execution/__tests__/helpers/subagent-service-mocks.ts +137 -0
  78. package/src/execution/__tests__/keep-alive-no-progress.test.ts +280 -0
  79. package/src/execution/__tests__/kill-all-escalation.test.ts +196 -0
  80. package/src/execution/__tests__/lifecycle-manager-idle-timer-identity.test.ts +117 -0
  81. package/src/execution/__tests__/lifecycle-manager.test.ts +39 -0
  82. package/src/execution/__tests__/lifecycle-predicates.test.ts +1 -2
  83. package/src/execution/__tests__/manifest-parentid.test.ts +4 -4
  84. package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +99 -0
  85. package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +113 -0
  86. package/src/execution/__tests__/model-resolver.test.ts +2 -2
  87. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +23 -121
  88. package/src/execution/__tests__/nested-visibility.test.ts +2 -0
  89. package/src/execution/__tests__/notify-ledger.test.ts +1249 -0
  90. package/src/execution/__tests__/output-collector.test.ts +117 -6
  91. package/src/execution/__tests__/pi-invocation.test.ts +1 -1
  92. package/src/execution/__tests__/record-store-orphan-revive.test.ts +159 -0
  93. package/src/execution/__tests__/record-store.test.ts +89 -5
  94. package/src/execution/__tests__/records-cwd-isolation.test.ts +2 -2
  95. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +29 -132
  96. package/src/execution/__tests__/recursive-visibility-env.test.ts +55 -179
  97. package/src/execution/__tests__/rpc-mode.test.ts +2 -2
  98. package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +387 -0
  99. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +19 -9
  100. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +5 -4
  101. package/src/execution/__tests__/run-spawn-edges.test.ts +418 -26
  102. package/src/execution/__tests__/run-spawn-integration.test.ts +3 -3
  103. package/src/execution/__tests__/run-spawn-resume.test.ts +2 -2
  104. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +2 -2
  105. package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +16 -8
  106. package/src/execution/__tests__/service-kill-escalation.test.ts +91 -0
  107. package/src/execution/__tests__/session-context-resolver.test.ts +0 -2
  108. package/src/execution/__tests__/session-file-gc.test.ts +35 -0
  109. package/src/execution/__tests__/session-pending.test.ts +471 -0
  110. package/src/execution/__tests__/session-reconstructor.test.ts +366 -15
  111. package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +110 -0
  112. package/src/execution/__tests__/session-runner-close-prune.test.ts +181 -0
  113. package/src/execution/__tests__/session-runner-dispatch.test.ts +489 -0
  114. package/src/execution/__tests__/session-runner-epipe.test.ts +4 -3
  115. package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +227 -0
  116. package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +290 -0
  117. package/src/execution/__tests__/session-runner-schema-env.test.ts +7 -5
  118. package/src/execution/__tests__/settled-watchdog.test.ts +524 -0
  119. package/src/execution/__tests__/spawn-args.test.ts +11 -10
  120. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +26 -23
  121. package/src/execution/__tests__/spawn-event-adapter.test.ts +1 -1
  122. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +5 -4
  123. package/src/execution/__tests__/spawned-children.test.ts +155 -11
  124. package/src/execution/__tests__/start-sync-model-guard.test.ts +4 -4
  125. package/src/execution/__tests__/stdin-writer.test.ts +6 -4
  126. package/src/execution/__tests__/stream-sink-retirement.test.ts +6 -6
  127. package/src/execution/__tests__/subagent-actions-core.test.ts +1017 -0
  128. package/src/execution/__tests__/subagent-service-message-close.test.ts +99 -35
  129. package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +174 -0
  130. package/src/execution/__tests__/subagent-service-notify-gate.test.ts +271 -0
  131. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +33 -29
  132. package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +341 -0
  133. package/src/execution/__tests__/subagent-service.test.ts +37 -30
  134. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +88 -12
  135. package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +75 -0
  136. package/src/execution/__tests__/subprocess-agent-runner.test.ts +22 -20
  137. package/src/execution/__tests__/temp-prompt.test.ts +1 -1
  138. package/src/execution/__tests__/timeout-integration.test.ts +13 -12
  139. package/src/execution/__tests__/turn-limiter-semantics.test.ts +1 -1
  140. package/src/execution/__tests__/turn-limiter.test.ts +1 -1
  141. package/src/execution/__tests__/ui-request-handler-factory.test.ts +107 -7
  142. package/src/execution/__tests__/ui-request-handler.test.ts +4 -3
  143. package/src/execution/__tests__/ui-request-queue.test.ts +167 -2
  144. package/src/execution/__tests__/worktree-git-ops.test.ts +571 -0
  145. package/src/execution/__tests__/worktree-manager.test.ts +14 -5
  146. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +4 -3
  147. package/src/execution/__tests__/worktree-reconcile-aging.test.ts +204 -0
  148. package/src/execution/agent-registry.ts +298 -30
  149. package/src/execution/agent-result-mapper.ts +3 -0
  150. package/src/execution/agents-assembly.ts +88 -0
  151. package/src/execution/cold-resurrect.ts +199 -0
  152. package/src/execution/concurrency-pool.ts +71 -9
  153. package/src/execution/dialog-queue.ts +101 -3
  154. package/src/execution/engine/__tests__/common/capability-gate.test.ts +91 -0
  155. package/src/execution/engine/__tests__/common/data-dir.test.ts +1 -1
  156. package/src/execution/engine/__tests__/common/journal-wiring.test.ts +84 -0
  157. package/src/execution/engine/__tests__/common/kill-chain.test.ts +34 -7
  158. package/src/execution/engine/__tests__/common/persona-router.test.ts +4 -5
  159. package/src/execution/engine/__tests__/common/pool-manager.test.ts +211 -51
  160. package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +149 -0
  161. package/src/execution/engine/__tests__/common/session-view-service.test.ts +499 -0
  162. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +56 -99
  163. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +88 -15
  164. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +33 -7
  165. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +1 -1
  166. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +75 -54
  167. package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +128 -0
  168. package/src/execution/engine/__tests__/engine-discovery.test.ts +15 -3
  169. package/src/execution/engine/__tests__/model-prompt.test.ts +15 -3
  170. package/src/execution/engine/__tests__/registry.test.ts +94 -3
  171. package/src/execution/engine/__tests__/routing.test.ts +115 -6
  172. package/src/execution/engine/common/capability-gate.ts +92 -0
  173. package/src/execution/engine/common/journal-wiring.ts +97 -0
  174. package/src/execution/engine/common/kill-chain.ts +42 -10
  175. package/src/execution/engine/common/nesting-guard.ts +66 -0
  176. package/src/execution/engine/common/persona-router.ts +18 -8
  177. package/src/execution/engine/common/pool-manager.ts +332 -78
  178. package/src/execution/engine/common/session-view-service.ts +506 -0
  179. package/src/execution/engine/common/session-view-types.ts +125 -0
  180. package/src/execution/engine/engine-discovery.ts +12 -16
  181. package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +174 -28
  182. package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +257 -0
  183. package/src/execution/{argv-mirror.ts → engine/engines/pi/argv-mirror.ts} +43 -21
  184. package/src/execution/{get-state-handshake.ts → engine/engines/pi/get-state-handshake.ts} +86 -11
  185. package/src/execution/{output-collector.ts → engine/engines/pi/output-collector.ts} +108 -19
  186. package/src/execution/engine/engines/pi/pi-engine.ts +434 -38
  187. package/src/execution/{pi-invocation.ts → engine/engines/pi/pi-invocation.ts} +2 -2
  188. package/src/execution/engine/engines/pi/reader.ts +11 -0
  189. package/src/execution/engine/engines/pi/registration.ts +4 -2
  190. package/src/execution/engine/engines/pi/session-runner.ts +2840 -0
  191. package/src/execution/{spawn-event-adapter.ts → engine/engines/pi/spawn-event-adapter.ts} +75 -34
  192. package/src/execution/{stdin-writer.ts → engine/engines/pi/stdin-writer.ts} +10 -9
  193. package/src/execution/{temp-prompt.ts → engine/engines/pi/temp-prompt.ts} +2 -2
  194. package/src/execution/{turn-limiter.ts → engine/engines/pi/turn-limiter.ts} +1 -1
  195. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +301 -0
  196. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +36 -0
  197. package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +321 -0
  198. package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +473 -0
  199. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +7 -210
  200. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +6 -110
  201. package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +247 -0
  202. package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +451 -0
  203. package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +792 -0
  204. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +782 -0
  205. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +168 -0
  206. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +210 -0
  207. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +353 -0
  208. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +282 -0
  209. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +372 -0
  210. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +65 -47
  211. package/src/execution/engine/engines/zcode/appserver-launcher.ts +167 -0
  212. package/src/execution/engine/engines/zcode/connection.ts +598 -0
  213. package/src/execution/engine/engines/zcode/constants.ts +147 -14
  214. package/src/execution/engine/engines/zcode/golden-sample.ts +42 -34
  215. package/src/execution/engine/engines/zcode/parser.ts +12 -346
  216. package/src/execution/engine/engines/zcode/preparer.ts +22 -150
  217. package/src/execution/engine/engines/zcode/session-channel.ts +968 -0
  218. package/src/execution/engine/engines/zcode/zcode-engine.ts +1023 -250
  219. package/src/execution/engine/host-task-spec.ts +32 -36
  220. package/src/execution/engine/model-validation.ts +177 -0
  221. package/src/execution/engine/port.ts +65 -7
  222. package/src/execution/engine/registry.ts +53 -0
  223. package/src/execution/engine/routing.ts +75 -1
  224. package/src/execution/engine/types.ts +30 -103
  225. package/src/execution/execution-record.ts +222 -144
  226. package/src/execution/finalize-record.ts +181 -85
  227. package/src/execution/idle-gc.ts +28 -0
  228. package/src/execution/lifecycle-manager.ts +27 -3
  229. package/src/execution/lifecycle-predicates.ts +1 -1
  230. package/src/execution/manifest-store.ts +53 -62
  231. package/src/execution/notifier.ts +10 -10
  232. package/src/execution/notify-host.ts +212 -0
  233. package/src/execution/notify-ledger.ts +117 -16
  234. package/src/execution/record-entry.ts +8 -2
  235. package/src/execution/record-store.ts +148 -88
  236. package/src/execution/round-settlement.ts +93 -0
  237. package/src/execution/session-file-gc.ts +96 -62
  238. package/src/execution/session-pending.ts +213 -62
  239. package/src/execution/session-reconstructor.ts +256 -143
  240. package/src/execution/sessions-index.ts +127 -102
  241. package/src/execution/settled-watchdog.ts +311 -0
  242. package/src/execution/subagent-actions-core.ts +686 -0
  243. package/src/execution/subagent-service.ts +1106 -907
  244. package/src/execution/subprocess-agent-runner.ts +144 -97
  245. package/src/execution/types.ts +9 -0
  246. package/src/execution/ui-request-handler-factory.ts +126 -75
  247. package/src/execution/ui-request-queue.ts +50 -19
  248. package/src/execution/worktree-git-ops.ts +397 -0
  249. package/src/execution/worktree-manager.ts +72 -10
  250. package/src/execution/worktree-registry.ts +6 -12
  251. package/src/index.ts +542 -9
  252. package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +42 -3
  253. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +3 -5
  254. package/src/orchestration/__tests__/agent-call-stream.test.ts +2 -2
  255. package/src/orchestration/__tests__/args-meta.test.ts +358 -0
  256. package/src/orchestration/__tests__/args-validator.test.ts +14 -0
  257. package/src/orchestration/__tests__/error-recovery-rebuild-failure.test.ts +312 -0
  258. package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +384 -0
  259. package/src/orchestration/__tests__/execute-agent-call.test.ts +151 -11
  260. package/src/orchestration/__tests__/file-run-store-prune.test.ts +168 -0
  261. package/src/orchestration/__tests__/file-run-store-throttle.test.ts +168 -0
  262. package/src/orchestration/__tests__/file-run-store.test.ts +390 -0
  263. package/src/orchestration/__tests__/helpers/flush-microtasks.ts +13 -0
  264. package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +34 -0
  265. package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +357 -0
  266. package/src/orchestration/__tests__/lifecycle-recover-crashed.test.ts +289 -0
  267. package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +3 -3
  268. package/src/orchestration/__tests__/lifecycle.test.ts +84 -5
  269. package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +1 -1
  270. package/src/orchestration/__tests__/run-snapshot.test.ts +356 -0
  271. package/src/orchestration/__tests__/script-generate.test.ts +314 -0
  272. package/src/orchestration/__tests__/script-lint.test.ts +17 -0
  273. package/src/orchestration/__tests__/test-mocks.ts +2 -0
  274. package/src/orchestration/__tests__/worker-exit-without-result.test.ts +7 -6
  275. package/src/orchestration/__tests__/worker-message-pump-finalize-run.test.ts +229 -0
  276. package/src/orchestration/__tests__/{error-recovery-handlers.test.ts → worker-message-pump-handlers.test.ts} +28 -27
  277. package/src/orchestration/__tests__/{error-recovery-postmessage-defense.test.ts → worker-message-pump-postmessage-defense.test.ts} +8 -8
  278. package/src/orchestration/__tests__/{error-recovery-serialize-failed-result.test.ts → worker-message-pump-serialize-failed-result.test.ts} +2 -2
  279. package/src/orchestration/__tests__/{error-recovery-workflow-call.test.ts → worker-message-pump-workflow-call.test.ts} +1 -1
  280. package/src/orchestration/__tests__/worker-pending-timeout-abort.test.ts +275 -0
  281. package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +78 -1
  282. package/src/orchestration/__tests__/worker-script-builder.test.ts +1 -1
  283. package/src/orchestration/__tests__/workflow-files.test.ts +186 -0
  284. package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +1 -1
  285. package/src/orchestration/__tests__/workflow-run-summary.test.ts +119 -0
  286. package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +124 -0
  287. package/src/orchestration/agent-opts-resolver.ts +8 -8
  288. package/src/orchestration/args-meta.ts +198 -0
  289. package/src/orchestration/args-validator.ts +53 -31
  290. package/src/orchestration/execute-agent-call.ts +25 -79
  291. package/src/orchestration/file-run-store.ts +327 -0
  292. package/src/orchestration/launcher.ts +160 -104
  293. package/src/orchestration/lifecycle.ts +371 -97
  294. package/src/orchestration/models/agent-call.ts +7 -7
  295. package/src/orchestration/models/budget.ts +5 -5
  296. package/src/orchestration/models/ports.ts +4 -4
  297. package/src/orchestration/models/run-runtime.ts +15 -15
  298. package/src/orchestration/models/trace.ts +9 -9
  299. package/src/orchestration/models/types.ts +111 -22
  300. package/src/orchestration/models/workflow-run.ts +28 -28
  301. package/src/orchestration/models/workflow-script.ts +4 -4
  302. package/src/orchestration/run-snapshot.ts +266 -0
  303. package/src/orchestration/script-generate.ts +154 -0
  304. package/src/orchestration/script-lint.ts +123 -90
  305. package/src/orchestration/worker-handle.ts +10 -10
  306. package/src/orchestration/worker-host.ts +10 -10
  307. package/src/orchestration/{error-recovery.ts → worker-message-pump.ts} +498 -221
  308. package/src/orchestration/worker-script-builder.ts +401 -346
  309. package/src/orchestration/workflow-files.ts +37 -11
  310. package/src/orchestration/workflow-run-summary.ts +69 -0
  311. package/src/orchestration/workflow-script-registry-impl.ts +31 -9
  312. package/src/shared/__tests__/agent-ref.test.ts +209 -2
  313. package/src/shared/__tests__/atomic-write.test.ts +267 -0
  314. package/src/shared/__tests__/bounded-serialize.test.ts +236 -0
  315. package/src/shared/__tests__/injection-render.test.ts +518 -0
  316. package/src/shared/__tests__/meta-parser.test.ts +151 -0
  317. package/src/shared/__tests__/resource-discovery-host-roots.test.ts +474 -0
  318. package/src/shared/__tests__/resource-discovery.test.ts +261 -217
  319. package/src/shared/agent-ref.ts +143 -2
  320. package/src/shared/atomic-write.ts +323 -0
  321. package/src/shared/bounded-serialize.ts +154 -0
  322. package/src/shared/injection-render.ts +279 -0
  323. package/src/shared/meta-parser.ts +182 -68
  324. package/src/shared/model-ref.ts +15 -2
  325. package/src/shared/resource-discovery.ts +97 -204
  326. package/src/shared/resource-meta.ts +14 -0
  327. package/src/shared/schema-jsonify.ts +1 -1
  328. package/src/shared/xml-injection.ts +9 -9
  329. package/workflows/README.md +9 -9
  330. package/workflows/chain.js +4 -2
  331. package/workflows/map-reduce.js +5 -3
  332. package/workflows/parallel.js +5 -3
  333. package/workflows/review-fix-loop-utils.cjs +165 -92
  334. package/workflows/review-fix-loop-utils.d.cts +287 -0
  335. package/workflows/review-fix-loop.js +18 -7
  336. package/workflows/scatter-gather.js +4 -2
  337. package/dist/chunk-3VOERJPJ.js +0 -22
  338. package/src/execution/__tests__/execute-options-mapper.test.ts +0 -200
  339. package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
  340. package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
  341. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
  342. package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
  343. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -580
  344. package/src/execution/engine/engines/zcode/launcher.ts +0 -161
  345. package/src/execution/execute-options-mapper.ts +0 -115
  346. package/src/execution/session-runner.ts +0 -1789
  347. package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -288
@@ -1,3 +1,69 @@
1
+ import { GuiRenderResult } from '@xyz-agent/extension-protocol';
2
+
3
+ /**
4
+ * ModelRegistry 的最小接口(duck-typed,测试可 mock)。
5
+ * 字段结构与 Pi SDK 的 ctx.modelRegistry 对齐。
6
+ */
7
+ interface ModelRegistryLike {
8
+ /** 返回所有已配置鉴权的可用模型。 */
9
+ getAvailable(): ModelInfo[];
10
+ /** 按 (provider, modelId) 查找。 */
11
+ find(provider: string, modelId: string): ModelInfo | undefined;
12
+ /** 校验模型鉴权是否就绪。 */
13
+ hasConfiguredAuth(model: unknown): boolean;
14
+ }
15
+ /**
16
+ * 模型信息(registry 返回元素 / ctx.model 鸭子类型兼容)。
17
+ * ctx.model(SDK Model<Api>)是此类型的超集,运行时直接当 ModelInfo 用。
18
+ */
19
+ interface ModelInfo {
20
+ id: string;
21
+ name: string;
22
+ provider: string;
23
+ reasoning: boolean;
24
+ thinkingLevelMap?: Record<string, unknown>;
25
+ contextWindow?: number;
26
+ }
27
+ /** agent .md frontmatter 解析结果。 */
28
+ interface AgentConfig {
29
+ /** agent 名(文件名 basename)。 */
30
+ name: string;
31
+ /** system prompt(markdown 正文)。 */
32
+ systemPrompt: string;
33
+ /** tool allowlist(三层过滤之一)。 */
34
+ tools?: string[];
35
+ /** 默认模型 override("provider/modelId")。agent 作者显式指定。 */
36
+ model?: string;
37
+ /** 默认 thinkingLevel override。 */
38
+ thinkingLevel?: string;
39
+ /** 默认 background 模式(true 时无显式 wait 走 background)。 */
40
+ defaultBackground?: boolean;
41
+ /**
42
+ * 执行引擎 id(agent .md frontmatter engine 字段,D9 per-agent 主通道)。
43
+ * 解析期已对注册表校验(未注册 id 在 agent-registry 抛 EngineNotFoundError);
44
+ * 执行侧(P4 路由层)按 调用参数 > 本字段 > 全局默认 三层取值。
45
+ */
46
+ engine?: string;
47
+ }
48
+ /** 解析结果(model 实例 + 生效的 thinkingLevel)。 */
49
+ interface ResolvedModel {
50
+ model: ModelInfo;
51
+ thinkingLevel: string | undefined;
52
+ }
53
+
54
+ /**
55
+ * 未显式指定 agent 时的兜底名。
56
+ *
57
+ * 必须是真实存在、可被 agentRegistry 发现的 agent(用户 agentDir 内置的通用 agent)。
58
+ * Service 层(resolveIdentity)与 TUI 层(extractAgentName)共用此常量,保证
59
+ * 「调用时显示的名」与「实际加载的 agent.md」一致。
60
+ *
61
+ * [HISTORICAL] 旧实现两处各硬编码:service 用 "default"(虚构名),format 用
62
+ * "worker"(真实但不是兜底语义,worker agent 已在 2026-08 agent 重构中删除)。
63
+ * 导致不传 agent 时,block 标题显示 worker,但实际执行兜底逻辑不一致。统一为
64
+ * general-purpose 后名实相符。
65
+ */
66
+ declare const DEFAULT_AGENT_NAME = "general-purpose";
1
67
  /**
2
68
  * 唯一执行状态。所有路径共用。v4 B-1 两态收敛:旧 idle 折入 running、
3
69
  * 旧 cancelled 折入 closed(closedReason='cancelled' 区分)。
@@ -28,6 +94,15 @@ type ExecutionStatus = "running" | "closed";
28
94
  * 不分),message/fork-from 据此给出可行动指引。
29
95
  */
30
96
  type ClosedReason = 'parent-shutdown' | 'parent-fork' | 'parent-new' | 'user-close' | 'cancelled' | 'gc' | 'disconnected';
97
+ /**
98
+ * [v8.5 D] 透明重生守卫拒绝专用错误:messageHandler 的 endedMessageGuard 必须原样
99
+ * 透传本类错误(自带完整行动语言),不得按 A1 分流规则改写——否则 worktree/异进程
100
+ * 占用文案会被「fork-from 指引」覆盖,误导 agent 走已被判死的通道。
101
+ */
102
+ declare class ResurrectDeniedError extends Error {
103
+ }
104
+ /** ClosedReason 全枚举值(运行时守卫用——防御性解析外部输入时校验成员资格)。 */
105
+ declare const CLOSED_REASONS: readonly ClosedReason[];
31
106
  /**
32
107
  * 终态三态对外语义(U3 C-outcome 一等披露)。
33
108
  *
@@ -40,6 +115,27 @@ type ClosedReason = 'parent-shutdown' | 'parent-fork' | 'parent-new' | 'user-clo
40
115
  * 「父进程关闭时子 agent 未完成即失败」,选定行为而非疏漏,勿当 bug 改回 cancelled。
41
116
  */
42
117
  type ExecutionOutcome = "completed" | "failed" | "cancelled";
118
+ /**
119
+ * 对外投影的 outcome 联合:含历史 record(outcome 字段诞生前的存量数据)兼容态。
120
+ * 投影层(projectOutcome 唯一出口)对无 outcome 字段的 closed record 按
121
+ * deriveOutcome(closedReason, error) 兜底派生;"closed-legacy" 预留给连派生输入都
122
+ * 不足以判读的存量形态,消费方必须处理该成员(不得因未知值崩溃)。
123
+ */
124
+ type ProjectedOutcome = ExecutionOutcome | "closed-legacy";
125
+ /**
126
+ * 对外四态(设计决策 10 细则 3):内部 ExecutionStatus(v4 B-1 两态)收敛为 agent
127
+ * 可理解的状态语义。真实映射只有两条:
128
+ * running → active / closed → ended(closed 统一终态,含 cancelled)。
129
+ * mapExternalState 不消费 ClosedReason——closed 恒映射 ended。
130
+ *
131
+ * waiting / error 是历史多态映射(idle→waiting / failed+crashed→error)的遗留声明:
132
+ * 对外四态联合契约不变,但当前状态机不产生这两个值。
133
+ *
134
+ * 原始 ExecutionStatus 进 list item 的 status 字段供调试;state 是对外主字段。
135
+ * 映射实现见 subagent-actions.ts mapExternalState——未来内部加态必须扩展该处,
136
+ * 漏加会在 default 分支编译报错,不影响对外契约。
137
+ */
138
+ type ExternalState = "active" | "waiting" | "ended" | "error";
43
139
  /** 执行模式。background = 调用方立即拿 handle 返回,子 agent 在 detached promise 里跑。 */
44
140
  type ExecutionMode = "background";
45
141
  /**
@@ -101,6 +197,39 @@ interface AgentUsageTotal extends AgentUsage$1 {
101
197
  /** 累计成本(USD,来自 SdkEvent.message.usage.cost.total 求和)。无成本数据时为 0。 */
102
198
  cost: number;
103
199
  }
200
+ /**
201
+ * eventLog 条目(getEventLog 派生产出的元素)。所有字段 readonly。
202
+ *
203
+ * text_output / thinking 类型已移除——它们是 100 字切片的碎片副产物,
204
+ * 现在完整内容收口在 record.turns[] 里,eventLog 只承载离散语义事件
205
+ * (tool 调用 / turn 边界 / error)。
206
+ */
207
+ interface AgentEventLogEntry {
208
+ readonly type: "tool_start" | "tool_end" | "turn_end" | "error";
209
+ readonly label: string;
210
+ /** 事件发生的墙钟时间戳(Date.now(),ms)。由 getEventLog 从 turns[] 派生时记录。 */
211
+ readonly ts: number;
212
+ readonly status?: "running" | "done" | "failed";
213
+ }
214
+ /**
215
+ * [STEP3] displayItem:从 turns[] 派生的展示项(对齐 nicobailon getDisplayItems)。
216
+ *
217
+ * 与 eventLog 的区别:eventLog 承载离散语义事件(tool_start/tool_end/turn_end),
218
+ * displayItem 承载「可渲染单元」(toolCall 含完整 name+args 供 formatToolCall 格式化;
219
+ * text 含 assistant 正文)。renderResult compact 分支改用 displayItems 后,
220
+ * 行格式与 nicobailon 完全一致(→ formatToolCall)。
221
+ */
222
+ interface DisplayItem {
223
+ readonly type: "toolCall" | "text";
224
+ /** toolCall:tool 名称(bash/read/edit...);text:无。 */
225
+ readonly name?: string;
226
+ /** toolCall:tool 原始 args(供 formatToolCall 提取路径/命令);text:无。 */
227
+ readonly args?: Record<string, unknown>;
228
+ /** toolCall:执行状态(running 时无✓/✗标记);text:正文文本。 */
229
+ readonly status?: "running" | "done" | "failed";
230
+ /** text:assistant 正文(compact 时取首行/截断)。 */
231
+ readonly text?: string;
232
+ }
104
233
  /** tool 调用结果(tool_execution_end 时累积,含 structured-output 的 details)。 */
105
234
  interface ToolCallResult {
106
235
  content?: unknown[];
@@ -167,6 +296,12 @@ interface AgentResult$1 {
167
296
  durationMs: number;
168
297
  success: boolean;
169
298
  error?: string;
299
+ /**
300
+ * [D5-③] 失败分诊结构化标签(类型 SSOT 在 orchestration/models/types.ts 的
301
+ * AgentFailureKind——消费语义「unknown=可重试」与其文档同源)。collectResult 对
302
+ * 最终 error 分类后写入;缺省 = unknown(可重试)。type-only 引用零运行时依赖。
303
+ */
304
+ failureKind?: AgentFailureKind;
170
305
  sessionId: string;
171
306
  toolCalls: ToolCall[];
172
307
  usage?: AgentUsageTotal;
@@ -188,6 +323,28 @@ interface WorktreeHandle {
188
323
  /** 主仓库根目录(cleanup/scan 需要,不再靠路径反推)。 */
189
324
  readonly mainCwd: string;
190
325
  }
326
+ /** alive marker:子进程存活标记,用于心跳检测和 crash 推断。 */
327
+ interface AliveMarker {
328
+ readonly pid: number;
329
+ readonly id: string;
330
+ readonly startedAt: number;
331
+ }
332
+ /** git diff patch 结果。 */
333
+ interface PatchResult {
334
+ readonly patchFile: string;
335
+ readonly failed: boolean;
336
+ /** patch 是否实际写入 patchFile。true=diff 非空且写盘成功;false=空 diff 或写失败。
337
+ * 调用方据此回填 record.patchFile,避免悬空路径(`git apply` 不存在的文件)。 */
338
+ readonly written: boolean;
339
+ }
340
+ /** fork depth 超限错误。 */
341
+ declare class ForkDepthExceededError extends Error {
342
+ constructor(message: string);
343
+ }
344
+ /** worktree 有未提交变更错误。 */
345
+ declare class DirtyWorktreeError extends Error {
346
+ constructor(message: string);
347
+ }
191
348
  /**
192
349
  * 所有执行路径的唯一状态源。
193
350
  *
@@ -354,6 +511,394 @@ interface ExecutionRecord {
354
511
  hadWorktree?: boolean;
355
512
  controller: AbortController | undefined;
356
513
  }
514
+ /**
515
+ * Tool 返回的 details(内层扁平结构)。
516
+ * 由 project(record) 唯一产出——sync/bg 两路径字段一致。
517
+ * 含 mode + sessionFile(供外层 SubagentToolResult 分组 + spinner 判断)。
518
+ *
519
+ * 分层(spec FR-3):此为**内层**,不感知 action/外层分组。
520
+ * 外层 SubagentToolResult 由 adapter 包裹产出(加 action/subagentId/sessionFile + 分组)。
521
+ */
522
+ interface SubagentToolDetails {
523
+ status: ExecutionStatus;
524
+ /**
525
+ * 终态三态对外语义(U3 C-outcome,projectOutcome 唯一出口)。running → undefined;
526
+ * 历史数据无 outcome 字段时兜底派生(见 ProjectedOutcome)。
527
+ */
528
+ outcome?: ProjectedOutcome;
529
+ mode: ExecutionMode;
530
+ agent: string;
531
+ model: string;
532
+ thinkingLevel: string | undefined;
533
+ /** 短标签(≤35 字符),来自 record.slug。旧 record 反序列化时为空串。 */
534
+ slug: string;
535
+ turns: number;
536
+ totalTokens: number;
537
+ elapsedSeconds: number;
538
+ eventLog: AgentEventLogEntry[];
539
+ /** [STEP3] 从 turns[] 派生的展示项(对齐 nicobailon getDisplayItems)。 */
540
+ displayItems: DisplayItem[];
541
+ result?: string;
542
+ error?: string;
543
+ /** running 时的当前活动行(tool/thinking/text 优先级)。 */
544
+ currentActivity?: {
545
+ type: "tool" | "text" | "thinking";
546
+ label: string;
547
+ };
548
+ /** schema 模式下,structured-output tool 的 result.details(对齐 workflow agent-pool)。 */
549
+ parsedOutput?: unknown;
550
+ /** session jsonl 文件名(不含目录)。窗口期内可能 undefined(session 尚未创建成功)。 */
551
+ sessionFile?: string;
552
+ /** [MF#3] worktree 模式下子 agent 改动的 patch 文件路径(worktree 外,供调用方应用)。 */
553
+ patchFile?: string;
554
+ }
555
+ /** Hub.execute 的入参(sync/bg 共用)。mode 由 Hub 内部判定,不暴露给调用方。 */
556
+ interface ExecuteOptions {
557
+ task: string;
558
+ /**
559
+ * 短标签(≤35 字符),简述本次执行用途,展示在 TUI。必填。
560
+ * workflow 内 agent() 调用时从 AgentCallOpts.description 透传而来。
561
+ */
562
+ slug: string;
563
+ agent?: string;
564
+ model?: string;
565
+ thinkingLevel?: string;
566
+ skillPath?: string;
567
+ appendSystemPrompt?: string[];
568
+ schema?: Record<string, unknown>;
569
+ /** D-A6 bridge: workflow schemaEnv 经 ExecuteOptions 透传到 runSpawn childEnv。 */
570
+ schemaEnv?: string;
571
+ /**
572
+ * Turn 上限 limiter。显式 0/负 = 显式不限:压过 SPAWN_WATCHDOG_ENV 兑底不挂
573
+ * watchdog(SP-6 参数 > env,U5);undefined 未传才由 env 兑底。
574
+ */
575
+ maxTurns?: number;
576
+ graceTurns?: number;
577
+ /** sync 模式来自 Pi tool 框架;background 模式 hub 忽略,自建 controller。 */
578
+ signal?: AbortSignal;
579
+ /** 主 agent 当前模型(模型解析第三层兼底)。execute 调用方从 ctx.model 传入。 */
580
+ ctxModel?: ModelInfo;
581
+ /** background 完成回调(sync 不调)。 */
582
+ onComplete?: (record: RecordSnapshot) => void;
583
+ /** 是否继承父会话上下文(fork 模式,只继承上下文)。 */
584
+ fork?: boolean;
585
+ /**
586
+ * [v8.5 B] fork-from 显式指定继承源 session 文件(非主 session)。
587
+ * 与 fork:true 的区别:fork:true 用主 session 作 --fork 源;本字段用任意已有
588
+ * session 文件(断联 subagent 接续场景)作源。优先级高于 fork;传了本字段时
589
+ * fork 取值不影响 spawn 参数。仅 pi 引擎支持(同 fork)。仅 background tool
590
+ * 层 fork-from action 使用;workflow / executeAndAwait 不消费。
591
+ */
592
+ forkFromSessionFile?: string;
593
+ /** 文件系统隔离:true=创建新 git worktree,WorktreeHandle=复用外部已创建的;undefined=不隔离(parent cwd)。 */
594
+ worktree?: boolean | WorktreeHandle;
595
+ /** 覆盖执行 cwd(默认 mainCwd)。 */
596
+ cwd?: string;
597
+ /**
598
+ * 可持续对话模式(决策 8:独立 chatMode 标志,不扩展 ExecutionMode)。
599
+ * true = record 标记 chatMode,轮次完成进 idle 态(保留 record + worktree,等待 message 续聊);
600
+ * undefined/false = 一次性模式(默认,行为完全不变)。service.execute 透传到 createRecordForMode。
601
+ */
602
+ conversation?: boolean;
603
+ /**
604
+ * 空闲超时毫秒数(仅 conversation 模式有意义)。覆盖默认 5min idle timeout。
605
+ * 优先级:参数 > env XYZ_SUBAGENT_IDLE_TIMEOUT_MS > 默认 300000ms。
606
+ * 显式传 0/负数 = 禁用 idle GC(不挂 timer;旧实现 0 会落成 setTimeout(0) 立即 kill)。
607
+ */
608
+ idleTimeoutMs?: number;
609
+ /**
610
+ * 实际执行引擎 id(P4 路由留痕):pi 引擎由 PiEngine.run 在还原 opts 时写入;
611
+ * 缺省(历史调用方不设)= pi 投影。createRecordForMode 读入 record identity。
612
+ */
613
+ engine?: string;
614
+ /**
615
+ * 引擎 fallback 留痕(D9①:probe 失败路由回默认引擎时由路由层写入)。
616
+ * from = 请求引擎 id,reason 恒 'engine_probe_failed'(GUI 警告条数据源)。
617
+ */
618
+ engineFallback?: {
619
+ from: string;
620
+ reason: string;
621
+ };
622
+ }
623
+ /**
624
+ * execute 返回值。
625
+ * background: { mode:"background", subagentId, sessionFile, details } —— 立即返回。
626
+ * subagentId 供后续 cancel/list 用;sessionFile 窗口期可能 undefined。
627
+ */
628
+ type ExecutionHandle = {
629
+ mode: "background";
630
+ subagentId: string;
631
+ sessionFile: string | undefined;
632
+ details: SubagentToolDetails;
633
+ };
634
+ /** list 的 item 结构。 */
635
+ interface SubagentListItem {
636
+ subagentId: string;
637
+ agent: string;
638
+ /** 短标签(≤35 字符),来自 record.slug。旧 record 反序列化时为空串。 */
639
+ slug: string;
640
+ /** 对外四态(决策 10 细则 3,主字段)。由 mapExternalState(status) 派生。 */
641
+ state: ExternalState;
642
+ /** 原始内部状态(调试用,供 details 展示)。 */
643
+ status: ExecutionStatus;
644
+ mode: ExecutionMode;
645
+ /** 运行秒数(running 态实时计算,终态 endedAt-startedAt)。 */
646
+ duration: number;
647
+ model: string;
648
+ totalTokens: number;
649
+ /** session jsonl 文件名(窗口期内可能 undefined)。 */
650
+ sessionFile?: string;
651
+ /** 直接父 subagent record ID(顶层 record 为 undefined)。[v4 A-6] 从
652
+ * record.parentRecordId 派生,配合 A-5 直接父守卫(message/close 仅作用于直接子)。 */
653
+ parent?: string;
654
+ /** 可冷路径 resume(running 且无活进程句柄)。[v4 A-6] B-1「可续聊」对外表达,
655
+ * agent 据 list 判断哪些 running subagent 实际可续聊(vs 正在忙)。 */
656
+ resumable?: boolean;
657
+ /**
658
+ * 终态三态对外语义(U3 C-outcome 一等披露,projectOutcome 唯一出口):
659
+ * completed / failed / cancelled,历史 record 无 outcome 字段时兜底派生,
660
+ * 不可判读的存量形态为 "closed-legacy"。GUI pane / agent 据此判读成败,
661
+ * 无需翻 error 字段原文(S5)。
662
+ */
663
+ outcome?: ProjectedOutcome;
664
+ }
665
+ /** background 启动的内层响应(挂在 SubagentToolResult.bgResponse)。 */
666
+ interface BgResponse {
667
+ status: "running";
668
+ mode: "background";
669
+ /** 启动提示文案("detached, will notify on completion")。 */
670
+ message: string;
671
+ /**
672
+ * 终态三态语义(U3 C-outcome 对外 JSON 契约完备位)。start 时点 record 尚未终态,
673
+ * 恒 undefined(JSON.stringify 落键省略);终态成败语义经 list items[].outcome
674
+ * 披露。旧字段 status/mode/message 原样保留(向后兼容)。
675
+ */
676
+ outcome?: ProjectedOutcome;
677
+ /**
678
+ * 通知投递契约回显位(U1 预置,U2 通知账本的契约声明)。恒值
679
+ * "ledger+at-least-once":主 agent 在当前 run 结束或有限延迟内收到完成通知,
680
+ * 送达保证为 at-least-once + notifyId 幂等可识别。字段与填充由 U1 负责,
681
+ * 值语义由 U2(execution/notify-ledger.ts)兑现。
682
+ */
683
+ notifyContract: "ledger+at-least-once";
684
+ }
685
+ /** list 的内层响应(挂在 SubagentToolResult.listResponse)。 */
686
+ interface ListResponse {
687
+ /** items 中 status==="running" 的计数(受 limit 截断如实反映,非全局总数)。 */
688
+ running: number;
689
+ items: SubagentListItem[];
690
+ }
691
+ /** cancel 的内层响应(挂在 SubagentToolResult.cancelResponse)。 */
692
+ interface CancelResponse {
693
+ cancelled: true;
694
+ }
695
+ /**
696
+ * message 的内层响应(挂在 SubagentToolResult.messageResponse,决策 10 瘦身)。
697
+ *
698
+ * [R1 删除记录] 旧 PendingMessage(在途消息缓存条目,消费确认制,设计决策 6 状态×
699
+ * interrupt 映射)已随 deliverToRunning 一并删除——SP-5 upgrade 后无生产调用方,
700
+ * 配套三段消费链(push / message_start shift / redeliverPending 补投)全部不可达。
701
+ * 详见 subagent-service.ts 的删除记录注释。
702
+ */
703
+ interface MessageResponse {
704
+ delivered: true;
705
+ }
706
+ /** close 的内层响应(挂在 SubagentToolResult.closeResponse,决策 10 瘦身)。 */
707
+ interface CloseResponse {
708
+ closed: true;
709
+ }
710
+ /**
711
+ * Tool 外层出参(renderResult + LLM content JSON 同源)。
712
+ * adapter 唯一产出:领域对象(bg/list/cancel/message/close 五选一)+ action/subagentId/sessionFile。
713
+ *
714
+ * - background 启动 → bgResponse(subagentId 有值;sessionFile 窗口期可能 undefined)
715
+ * - list → listResponse(最外层 subagentId/sessionFile 为 null,sessionFile 在各 item 内)
716
+ * - cancel → cancelResponse(subagentId 有值;sessionFile 无意义,可为 null)
717
+ * - message → messageResponse(subagentId 有值;sessionFile 无意义,可为 null)
718
+ * - close → closeResponse(subagentId 有值;sessionFile 无意义,可为 null)
719
+ */
720
+ type SubagentToolResult = {
721
+ action: "start";
722
+ subagentId: string;
723
+ sessionFile: string | null;
724
+ slug: string; /** registry 全等回显(U1):放行即与 registry 条目全等,"provider/id" 形态。 */
725
+ model: string;
726
+ bgResponse: BgResponse;
727
+ __gui__?: GuiRenderResult;
728
+ } | {
729
+ action: "list";
730
+ subagentId: null;
731
+ sessionFile: null;
732
+ listResponse: ListResponse;
733
+ __gui__?: GuiRenderResult;
734
+ } | {
735
+ action: "cancel";
736
+ subagentId: string;
737
+ sessionFile: null;
738
+ cancelResponse: CancelResponse;
739
+ __gui__?: GuiRenderResult;
740
+ } | {
741
+ action: "message";
742
+ subagentId: string;
743
+ sessionFile: null;
744
+ messageResponse: MessageResponse;
745
+ __gui__?: GuiRenderResult;
746
+ } | {
747
+ action: "close";
748
+ subagentId: string;
749
+ sessionFile: null;
750
+ closeResponse: CloseResponse;
751
+ __gui__?: GuiRenderResult;
752
+ } | {
753
+ action: "fork-from";
754
+ subagentId: string;
755
+ sessionFile: string | null;
756
+ forkFromResponse: ForkFromResponse;
757
+ __gui__?: GuiRenderResult;
758
+ };
759
+ /** fork-from 的内层响应:新 subagent id + 作为继承源的旧记录 session 文件。
760
+ * [v8.5 B] 断联恢复通道——新 subagent 以 --fork 方式继承旧会话历史,源文件只读
761
+ * 不续写(pi fork 建 branched session,copy-on-write)。 */
762
+ interface ForkFromResponse {
763
+ /** 新 subagent record id(接续对话用 action:'message')。 */
764
+ newSubagentId: string;
765
+ /** 作为继承源的旧 subagent session jsonl 绝对路径。 */
766
+ sourceSessionFile: string;
767
+ }
768
+ /** /subagents list 左列展示单元。来自内存(running) 或 session.jsonl 重建(终态)。 */
769
+ interface SubagentRecord {
770
+ id: string;
771
+ agent: string;
772
+ /** 任务提示词(详情面板置顶展示)。磁盘/内存源均有。 */
773
+ task: string;
774
+ /** 短标签(≤35 字符)。磁盘重建源旧文件可能缺失→兜底空串。 */
775
+ slug: string;
776
+ status: ExecutionStatus;
777
+ /** L2 关闭原因子枚举(仅 status="closed" 时有意义)。SP-1 新增。 */
778
+ closedReason?: ClosedReason;
779
+ /** 终态三态对外语义(U3 C-outcome)。磁盘重建源一等直读;无字段的存量兜底走 projectOutcome。 */
780
+ outcome?: ExecutionOutcome;
781
+ mode: ExecutionMode;
782
+ startedAt: number;
783
+ /** 根 Pi session ID(session 隔离过滤用)。递归链上所有层 record 同值。 */
784
+ rootSessionId: string | undefined;
785
+ /** 直接父 subagent record ID(层级树构建用)。顶层 record 为 undefined。 */
786
+ parentRecordId: string | undefined;
787
+ /** subagent 递归深度。顶层 =0,每层嵌套 +1。 */
788
+ depth: number;
789
+ endedAt: number | undefined;
790
+ turns: number;
791
+ totalTokens: number;
792
+ model: string;
793
+ thinkingLevel: string | undefined;
794
+ eventLog: AgentEventLogEntry[];
795
+ /** [STEP3] 从 turns[] 派生的展示项(对齐 nicobailon getDisplayItems)。 */
796
+ displayItems: DisplayItem[];
797
+ /** running 时的当前活动行(仅内存源;磁盘重建无此数据)。streaming 可观测性用。 */
798
+ currentActivity?: {
799
+ type: "tool" | "text" | "thinking";
800
+ label: string;
801
+ };
802
+ result?: string;
803
+ error?: string;
804
+ sessionFile?: string;
805
+ /** [MF#3] worktree 模式下子 agent 改动的 patch 文件路径(worktree 外,供调用方应用)。 */
806
+ patchFile?: string;
807
+ /**
808
+ * [review round2] 创建时启用 worktree 隔离(磁盘重建源从 session entry 恢复;内存源由
809
+ * recordToSubagent 从 worktreeHandle 投影)。getRecordForAction 跨重启重建时据此拒绝续聊。
810
+ */
811
+ worktree?: boolean;
812
+ /**
813
+ * 对话轮次计数(仅 chatMode idle record 有意义)。round 仅在内存维护(doFinalizeRoundToIdle
814
+ * 递增),跨重启不恢复(round 无磁盘持久化);非对话模式 / 非 idle record 为 undefined。内存源由 recordToSubagent 从
815
+ * ExecutionRecord.round 投影。
816
+ */
817
+ round?: number;
818
+ /**
819
+ * 对话模式标志(与 ExecutionRecord.chatMode 同义;投影给 GUI 侧 streaming/waiting/done
820
+ * 细分判据——one-shot 轮终(chatMode 非 true + result 有值)显示完成态,chat 轮终显示
821
+ * 等续聊。内存源由 recordToSubagent 投影,磁盘源经 subagent-record entry 重建)。
822
+ */
823
+ chatMode?: boolean;
824
+ /**
825
+ * 执行态信号(与 ExecutionRecord.resumable 同义):true = 无活进程驱动的 running
826
+ * (轮终 idle / 重建孤儿兜底),GUI 侧据此排除「真在跑」判定。
827
+ */
828
+ resumable?: boolean;
829
+ /** 外部 Pi 实例(进程隔离模式下由外部启动的子进程)。 */
830
+ externalInstance?: AliveMarker;
831
+ /** fork 模式下的 worktree handle。 */
832
+ worktreeHandle?: WorktreeHandle;
833
+ /**
834
+ * 实际执行引擎 id(P4 路由留痕)。缺省 = pi 投影(存量 record 零迁移);
835
+ * GUI 警告条/引擎标记的数据源之一。
836
+ */
837
+ engine?: string;
838
+ /** 引擎 fallback 留痕(D9①:probe 失败路由回默认引擎)。GUI 警告条数据源。 */
839
+ engineFallback?: {
840
+ from: string;
841
+ reason: string;
842
+ };
843
+ /**
844
+ * 引擎自描述定位符(U1:EngineHandleData 的持久化消费面子集,引擎无关——
845
+ * sessionRef 整体透传不枚举内部键)。read 降级链①②级的数据源(runtime
846
+ * subagent-engine-history);缺省 = pi(走 JSONL 直读链)。
847
+ */
848
+ engineHandle?: {
849
+ sessionRef: Record<string, string>;
850
+ journalPath?: string;
851
+ poolKey: string;
852
+ };
853
+ }
854
+ /**
855
+ * 全局配置(~/.pi/agent/subagents/config.json)。
856
+ *
857
+ * 模型解析已退化为「主 agent model 优先,仅 override 时查 registry」——
858
+ * 不再有 category/fallback/yolo 字段。config.json 只保留 maxConcurrent
859
+ * (pool 大小)。旧 config.json 中的 categories/fallback 等字段读取时忽略。
860
+ */
861
+ interface SubagentsGlobalConfig {
862
+ version: number;
863
+ maxConcurrent: number;
864
+ /**
865
+ * 全局默认执行引擎(D9 三层优先级的最底层:调用参数 > agent frontmatter > 本值)。
866
+ * 缺省 'pi'(P4 路由层 DEFAULT_ENGINE_ID)。加载期只做类型校验,注册表校验归路由层。
867
+ */
868
+ defaultEngine?: string;
869
+ /** 引擎路由策略(D9①):strict=true 时一切 probe 失败直接报错(不 fallback)。 */
870
+ engineRouting?: {
871
+ strict: boolean;
872
+ };
873
+ }
874
+ /**
875
+ * Record 的只读视图。store.snapshot() 返回。
876
+ * TUI 拿到此类型,保证不会回写 Core 状态。
877
+ *
878
+ * 不含 eventLog——snapshot 的消费点(cancel 判 mode/status、hasRunning 判 mode、
879
+ * toNotifyRecord 取 result/error)均不读 eventLog。需要 eventLog 的场景用 project()
880
+ * 投影的 SubagentToolDetails。需要完整内容用 record.turns[](Core 内部)。
881
+ */
882
+ interface RecordSnapshot {
883
+ readonly id: string;
884
+ readonly agent: string;
885
+ readonly model: string;
886
+ readonly thinkingLevel: string | undefined;
887
+ readonly mode: ExecutionMode;
888
+ readonly task: string;
889
+ /** 短标签(≤35 字符)。来自 record.slug。 */
890
+ readonly slug: string;
891
+ readonly status: ExecutionStatus;
892
+ /** 对话模式标志(与 ExecutionRecord.chatMode 同源)。cancel 别名判定用。 */
893
+ readonly chatMode?: boolean;
894
+ readonly turns: number;
895
+ readonly totalTokens: number;
896
+ readonly startedAt: number;
897
+ readonly endedAt: number | undefined;
898
+ readonly result: string | undefined;
899
+ readonly error: string | undefined;
900
+ readonly sessionFile: string | undefined;
901
+ }
357
902
 
358
903
  /**
359
904
  * Workflow Extension — Engine 共享类型
@@ -381,7 +926,36 @@ type RunStatus = "running" | "done";
381
926
  /** 终态原因。done 时必有(WorkflowRun 不变式)。 */
382
927
  type DoneReason = "completed" | "failed" | "aborted" | "budget_limited" | "time_limited" | "invalid_args";
383
928
  /**
384
- * 单次 agent 调用的输入选项。
929
+ * slug 最大长度(D6 合流迁入本文件,原权威定义在已删除的 execution/execute-options-mapper.ts)。
930
+ * 历史值 20 偏紧——描述性 slug 如 "audit-structured-output"(23)/ "fix-subagent-wf-tools"(21)
931
+ * 会撞上限,放宽到 35 兼顾「短到能塞进 TUI 标题行」与「容纳合理描述性 kebab-case 名」。
932
+ * 放本文件的原因:约束对象是 AgentCallOpts.description(slug 的源字段,见下方 slug 派生说明),
933
+ * 与字段同文件;worker-message-pump(live record slug 截断)与壳侧 tool schema maxLength 共享引用。
934
+ */
935
+ declare const SLUG_MAX_LENGTH = 35;
936
+ /**
937
+ * 单次 agent 调用的任务声明(D6 任务形状合流后的单一形状)。
938
+ *
939
+ * [D6 合流裁决] 本类型 = 原 AgentCallOpts(workflow 调用方声明,18 字段)与原
940
+ * AgentTaskSpec(engine 中立任务声明,已删除)的合流形态,从模型脚本 agent() API
941
+ * 到 EnginePort.run 直达 pi 边界一次映射——SAR 链路上的 ExecuteOptions/AgentTaskSpec
942
+ * 中间态消除(设计 docs/design/subagent-dual-track-convergence.md §3.3 D6 / 终态四)。
943
+ *
944
+ * 终态命名按变化轴裁定为 AgentCallOpts,理由:
945
+ * - 字段演进的首要驱动轴是「调用方要表达的任务语义」(agent() API 是唯一生产写入方,
946
+ * 合流字段中 prompt/description/skill/skillPath/schemaEnv/thinkingLevel 等多数派
947
+ * 已是调用方命名);
948
+ * - 原 AgentTaskSpec 的中立重命名层(task/slug/effort/persona)与调用方命名是
949
+ * 形式同构、语义同构的假差异(prompt≡task、slug=description 截断、effort≡thinkingLevel、
950
+ * persona≡skillPath+appendSystemPrompt 平铺),按「消假差异」原则并入调用方命名;
951
+ * - 持久化兼容反向锁定 prompt 形态:jsonl run 快照的 AgentCall.opts 与 worker 消息
952
+ * opts 均以 prompt 字段落盘,改名会破坏旧快照重水合。
953
+ *
954
+ * 引擎中立字段的并入方式(可选字段,原 AgentTaskSpec 独有字段去向):
955
+ * - graceTurns / conversation / idleTimeoutMs / denyTools / permissionMode:可选并入;
956
+ * - persona.agentRef:裁撤(无生产写入方、无消费者——pi 走 agent 字段解析身份);
957
+ * - requires:裁撤(P4 形状预留、无生产写入方;且并入需 import EngineCapabilities
958
+ * 形成 orchestration↔engine 类型环)。将来能力依赖声明下钻时在本形状上加回。
385
959
  *
386
960
  * D-12 仅重组执行编排,AgentCallOpts 形状保持兼容。
387
961
  */
@@ -417,14 +991,20 @@ interface AgentCallOpts {
417
991
  */
418
992
  timeoutMs?: number;
419
993
  /**
420
- * Turn 上限(turn limiter 用)。
421
- *
422
- * [预算语义对齐] 未传或 <=0 = 不限 turn;此时也不按 turns 估算 spawn watchdog——
423
- * 仅当 env XYZ_SUBAGENT_SPAWN_WATCHDOG_MS 设置时才按绝对时限挂 watchdog(见
424
- * session-runner.resolveSpawnWatchdogMs)。mapToExecuteOptions 原样透传到
425
- * ExecuteOptions.maxTurns 引擎 task-spec → runSpawn。
426
- */
994
+ * Turn 上限(turn limiter 用)。
995
+ *
996
+ * [预算语义对齐] 未传或 <=0 = 不限 turn;此时也不按 turns 估算 spawn watchdog——
997
+ * 仅当 env XYZ_SUBAGENT_SPAWN_WATCHDOG_MS 设置时才按绝对时限挂 watchdog(见
998
+ * session-runner.resolveSpawnWatchdogMs)。pi 边界直出为 ExecuteOptions.maxTurns
999
+ * → runSpawn(D6 合流后无中间映射层)。
1000
+ */
427
1001
  maxTurns?: number;
1002
+ /**
1003
+ * Turn limiter 的宽限轮数(原 AgentTaskSpec.graceTurns 并入):超 maxTurns 后
1004
+ * 允许继续的轮数(等待在途工具收尾)。pi 引擎消费;workflow agent() 无写入方,
1005
+ * chat 域(ExecuteOptions.graceTurns 同名透传)经 host-task-spec 填充。
1006
+ */
1007
+ graceTurns?: number;
428
1008
  /**
429
1009
  * Skill name to load (e.g. "code-review"). Resolved to SKILL.md path
430
1010
  * and injected via --skill flag in the subprocess.
@@ -445,18 +1025,18 @@ interface AgentCallOpts {
445
1025
  */
446
1026
  agent?: string;
447
1027
  /**
448
- * System prompt injection CONTENT (not file paths).
449
- * Set by agent-opts-resolver: schema structured-output instruction string.
450
- * Agent systemPrompt is NOT included here (handled by resolveIdentity/agentConfig).
451
- * mapToExecuteOptions passes this through to ExecuteOptions.appendSystemPrompt
452
- * (same name/semantics, transparent passthrough).
453
- */
1028
+ * System prompt injection CONTENT (not file paths).
1029
+ * Set by agent-opts-resolver: schema structured-output instruction string.
1030
+ * Agent systemPrompt is NOT included here (handled by resolveIdentity/agentConfig).
1031
+ * pi 边界直出为 ExecuteOptions.appendSystemPrompt(同名同义透传,D6 合流后无中间映射层)。
1032
+ */
454
1033
  appendSystemPrompt?: string[];
455
1034
  /**
456
- * Schema JSON for PI_WORKFLOW_SCHEMA env var.
457
- * Set by agent-opts-resolver when opts.schema is present; passed as env var
458
- * to activate the structured-output tool + hook.
459
- */
1035
+ * Schema JSON for PI_WORKFLOW_SCHEMA env var.
1036
+ * Set by agent-opts-resolver when opts.schema is present (值 = stringifySchemaCached
1037
+ * compact,与 schema 派生等值); passed as env var to activate the structured-output
1038
+ * tool + hook. pi 边界直出时 schema 派生优先、本字段兜底(解耦形态通道,生产不可达)。
1039
+ */
460
1040
  schemaEnv?: string;
461
1041
  /**
462
1042
  * Per-call 工作目录(ADR-029 决策 1)。传给 child_process.spawn 的 cwd option。
@@ -475,11 +1055,36 @@ interface AgentCallOpts {
475
1055
  * agent() → execute-agent-call → SAR 路由层。
476
1056
  */
477
1057
  engine?: string;
478
- /** Filesystem isolation: when true, creates a new git worktree for the agent. Independent of fork. */
479
- worktree?: boolean;
1058
+ /** Filesystem isolation: when true, creates a new git worktree for the agent. Independent of fork.
1059
+ * [D6 合流] 类型扩展为 boolean | WorktreeHandle(原 AgentTaskSpec.worktree 的超集)——
1060
+ * WorktreeHandle 形态仅在 chat 域(复用外部已创建的 worktree)出现,workflow agent()
1061
+ * 恒传 boolean。 */
1062
+ worktree?: boolean | WorktreeHandle;
480
1063
  /** When true, agent() resolves {value, sessionFile, worktreePath, error} instead of a bare value.
481
- * Worker-layer flag only — not forwarded to ExecuteOptions (mapToExecuteOptions drops it). */
1064
+ * Worker-layer flag only — not consumed by any engine (dropped at the pi boundary). */
482
1065
  returnMeta?: boolean;
1066
+ /**
1067
+ * 可持续对话模式(原 AgentTaskSpec.conversation 并入):true = record 标记 chatMode,
1068
+ * 轮次完成进 idle 态等待 message 续聊。chat 域(ExecuteOptions.conversation 同名)经
1069
+ * host-task-spec 填充;workflow agent() 无写入方。
1070
+ */
1071
+ conversation?: boolean;
1072
+ /**
1073
+ * 空闲超时毫秒数(原 AgentTaskSpec.idleTimeoutMs 并入,仅 conversation 模式有意义)。
1074
+ * 优先级:参数 > env XYZ_SUBAGENT_IDLE_TIMEOUT_MS > 默认 300000ms;显式 0/负 = 禁用
1075
+ * idle GC。chat 域经 host-task-spec 填充。
1076
+ */
1077
+ idleTimeoutMs?: number;
1078
+ /**
1079
+ * 工具 denylist(原 AgentTaskSpec.denyTools 并入,中立新增面):各引擎做语法映射
1080
+ * (zcode buildZcodeArgv 消费;pi 链路暂无对应面)。无 workflow 写入方,预留形状。
1081
+ */
1082
+ denyTools?: string[];
1083
+ /**
1084
+ * 中立权限模式(原 AgentTaskSpec.permissionMode 并入,预留形状):映射按各引擎
1085
+ * capabilities.permissionMode。无生产写入方/消费者。
1086
+ */
1087
+ permissionMode?: string;
483
1088
  }
484
1089
  /**
485
1090
  * 单次 agent 调用的资源用量(FR-7 跨 turn 累积)。
@@ -502,6 +1107,23 @@ interface ToolCallEntry {
502
1107
  /** Args preview string. */
503
1108
  input: string;
504
1109
  }
1110
+ /**
1111
+ * 失败分诊结构化标签(D5-③,r1 MF4 钉正语义)。
1112
+ *
1113
+ * - stale_context:pi session context 被 compact/cancel/替换——重试无意义(同 call
1114
+ * 再次失败),不重试。
1115
+ * - schema_deterministic:确定性 schema 失败(SO tool 从未调用 / gate 终止 /
1116
+ * 不可满足 schema)——同 schema 重试必同结果,不重试。
1117
+ * - unknown:其余一切失败(瞬态 provider 错误、spawn 失败等)——**默认可重试**。
1118
+ *
1119
+ * **语义守恒(最高优先约束)**:unknown(含字段缺省)= 可重试——保持收敛前的
1120
+ * 默认重试语义;仅 stale_context 与 schema_deterministic 两态维持不重试特判。
1121
+ * 词表归属(产出侧单点识别):stale_context / schema_deterministic 的识别词表
1122
+ * (stale 词表与确定性 schema 失败标记前缀)保留在产出侧
1123
+ * execution/engine/engines/pi/output-collector.ts 包内——词表漂移的失效模式是
1124
+ * failureKind=unknown → 保守重试(安全默认),不再是静默漏诊。
1125
+ */
1126
+ type AgentFailureKind = "stale_context" | "schema_deterministic" | "unknown";
505
1127
  /**
506
1128
  * 单次 agent 调用的结果(统一形态)。
507
1129
  *
@@ -512,6 +1134,16 @@ interface AgentResult {
512
1134
  /** Raw text output from the agent. */
513
1135
  content: string;
514
1136
  /**
1137
+ * [D5-③] 失败分诊结构化标签(AgentFailureKind)。产出侧唯一识别点 =
1138
+ * execution/engine/engines/pi/output-collector.ts(collectResult 对最终 error
1139
+ * 分类后写入,经 agent-result-mapper / AgentOutcome 透传到本形态);消费侧
1140
+ * execute-agent-call 读本字段分诊,不再扫 error 文案子串。
1141
+ *
1142
+ * 仅在 error !== undefined 时有意义(成功时缺省);缺省视为 unknown = 可重试
1143
+ * (语义守恒,见 AgentFailureKind)。
1144
+ */
1145
+ failureKind?: AgentFailureKind;
1146
+ /**
515
1147
  * Parsed structured output.
516
1148
  * Present when `schema` was provided and the output was valid JSON.
517
1149
  * Source: tool_execution_end.result.details(validated data object)。
@@ -606,95 +1238,6 @@ interface WorkerLogEntry {
606
1238
  message: string;
607
1239
  }
608
1240
 
609
- /** 人设(persona)注入规格:原 skillPath + appendSystemPrompt 收拢进一个语义单元(D2)。 */
610
- interface PersonaSpec {
611
- /**
612
- * agent 名/路径。与 AgentTaskSpec.agent 的分工:agent 是 resolveIdentity 的身份解析
613
- * 键(模型/系统提示等身份语义);agentRef 是 persona 注入通道的定位符——引擎按
614
- * capabilities.personaInjection 决定注入通道(file/flag/prompt)时用它定位人设。
615
- * pi 引擎不消费此字段(身份解析走 spec.agent),留给 flag/file 通道的引擎。
616
- */
617
- agentRef?: string;
618
- /**
619
- * 原 ExecuteOptions.skillPath。公共 persona 路由三策略(file/flag/prompt)的分流
620
- * 载体(D4)——超长 prompt 时优先 file/flag 通道分流的落点。
621
- */
622
- skillPath?: string;
623
- /** 追加系统提示内容数组(原样透传;schema 仿真段由公共降级层拼装后放入,P2)。 */
624
- appendSystemPrompt?: string[];
625
- }
626
- /**
627
- * 引擎无关的 agent 任务声明(= ExecuteOptions 泛化,字段逐条锚定设计 §3.3.5)。
628
- *
629
- * 与 ExecuteOptions 的差异(泛化点):
630
- * - thinkingLevel(pi 7 档枚举语义)→ effort?: string,各引擎自行映射或忽略;
631
- * - skillPath + appendSystemPrompt → persona(PersonaSpec);
632
- * - conversation/idleTimeoutMs 保留原名透传——属 interact 交互控制面的 task 标志(D1),
633
- * 不是 pi 专有语义的泄漏,而是「任务声明里声明交互模式」的中立表达;
634
- * - 删字段去向:signal/ctxModel/onComplete 是运行期句柄,移入 RunContext(port.ts);
635
- * schemaEnv 内化到 PiEngine(从 task.schema 派生,见 engines/pi/task-spec-mapper.ts)。
636
- *
637
- * 新增(为后续 wave 预留形状,P1 无生产写入方):
638
- * - denyTools:中立工具 denylist(附录 A 该行的载体);
639
- * - permissionMode:中立权限模式(映射按 capabilities.permissionMode)。
640
- */
641
- interface AgentTaskSpec {
642
- /** 原样(ExecuteOptions.task)。 */
643
- task: string;
644
- /** 原样(ExecuteOptions.slug,≤35 字符)。 */
645
- slug: string;
646
- /** 原样(ExecuteOptions.agent,resolveIdentity 的 agent ref)。 */
647
- agent?: string;
648
- /** 原样(ExecuteOptions.model;在引擎 provider 体系内解释,D9②)。 */
649
- model?: string;
650
- /**
651
- * 泛化:原 ExecuteOptions.thinkingLevel。引擎无关的推理投入档位字符串——
652
- * pi 引擎把它原值映射回 thinkingLevel 7 档;其他引擎自行映射(CC 5 档)或忽略
653
- * (kimi ❌)。不定义联合枚举:档位集合是引擎私有语义,中立层只透传字符串。
654
- */
655
- effort?: string;
656
- /** 泛化:原 skillPath + appendSystemPrompt 收拢(D2)。 */
657
- persona?: PersonaSpec;
658
- /**
659
- * 原样(ExecuteOptions.schema)。native/emulated 分流依据(D4 硬边界):pi 的
660
- * PI_WORKFLOW_SCHEMA env 注入链路按 native 直传,公共仿真层只服务 emulated 引擎。
661
- */
662
- schema?: Record<string, unknown>;
663
- /**
664
- * 原样(ExecuteOptions.maxTurns)。pi 引擎专属(turn limiter + spawn watchdog
665
- * 估算依赖 pi 的 turn_end 事件流);其他引擎 prepare 期显式拒绝(U4,同 fork 模式)。
666
- * 显式 0 压过 SPAWN_WATCHDOG_ENV 兑底(SP-6 参数 > env,U5);undefined 未传才由
667
- * env 兑底。
668
- */
669
- maxTurns?: number;
670
- /** 原样(ExecuteOptions.graceTurns)。 */
671
- graceTurns?: number;
672
- /** 原样(ExecuteOptions.fork)。pi 专属;其他引擎 prepare 期按 capabilities 拒绝。 */
673
- fork?: boolean;
674
- /**
675
- * 原样(ExecuteOptions.worktree)。公共层职责(worktree-manager),非引擎职责——
676
- * 引擎只把它当 spawn cwd 的来源之一。
677
- */
678
- worktree?: boolean | WorktreeHandle;
679
- /** 原样(ExecuteOptions.cwd)。 */
680
- cwd?: string;
681
- /** 原样(ExecuteOptions.conversation,interact 控制面的 task 标志,D1)。 */
682
- conversation?: boolean;
683
- /** 原样(ExecuteOptions.idleTimeoutMs,同上)。 */
684
- idleTimeoutMs?: number;
685
- /** 新增:中立工具 denylist。各引擎做语法映射(附录 A「工具 denylist」行的载体)。 */
686
- denyTools?: string[];
687
- /** 新增:中立权限模式。映射按 capabilities.permissionMode(kimi fixed auto = ignored)。 */
688
- permissionMode?: string;
689
- /**
690
- * [P4 形状预留,D9① 守卫 b 的独立载体] 任务对引擎能力的显式依赖声明。
691
- * 首期无生产写入方:守卫 b 与守卫 a 合流(显式 engine 即能力依赖声明)——调用方
692
- * 按引擎 id 表达依赖。下钻时机(AgentTaskSpec 泛化成熟后):调用方改按能力表达
693
- * (如 requires: { sandbox: 'native' }),路由层将本字段与各引擎 capabilities()
694
- * 对照,无引擎满足时报 engine_capability_unsupported(调用前拒绝,D11 处置三级)。
695
- */
696
- requires?: Partial<EngineCapabilities>;
697
- }
698
1241
  /**
699
1242
  * 一次引擎执行的终态。锚定 orchestration/models/types.ts 的 AgentResult(workflow
700
1243
  * 引擎消费的那份——content/parsedOutput/usage/error)并追加引擎层字段;见文件头消歧说明。
@@ -702,6 +1245,13 @@ interface AgentTaskSpec {
702
1245
  interface AgentOutcome {
703
1246
  /** 原样(AgentResult.content)。 */
704
1247
  content: string;
1248
+ /**
1249
+ * 原样(AgentResult.failureKind,D5-③ 失败分诊结构化标签)。产出侧唯一识别点 =
1250
+ * engines/pi/output-collector(collectResult 分类写入);缺省 = unknown = 可重试
1251
+ * (消费侧 executeAgentCall 只读字段分诊,不扫 error 文案)。非 pi 引擎不产出,
1252
+ * 恒缺省(unknown 语义)。
1253
+ */
1254
+ failureKind?: AgentFailureKind;
705
1255
  /**
706
1256
  * 原样(AgentResult.parsedOutput)。native 引擎直传 / 仿真层 ajv 产出(D4 硬分流:
707
1257
  * native 路径公共层不做二次校验、不改写其结果)。
@@ -826,6 +1376,15 @@ interface EngineCapabilities {
826
1376
  interrupt: "native" | "kill-only";
827
1377
  /** kimi headless 固定 auto = ignored;GUI 据此隐藏/提示。 */
828
1378
  permissionMode: "native" | "fixed" | "ignored";
1379
+ /**
1380
+ * [D3-④ r3 裁定] maxTurns 轮数上限的执行能力位(pi = true:turn limiter + spawn
1381
+ * watchdog 估算兑现;zcode = false:无 turn_end 语义,静默丢弃会造成「传了上限却
1382
+ * 失控」假象)。调用前预检(common/capability-gate)按本位拦「声明不支持的能力」
1383
+ * ——pi 不拦 maxTurns(已支持能力,由 turn-limiter 执行)、zcode 同步拒绝。
1384
+ * 现状 11 个能力位无可承载 maxTurns 的语义位(fork 拦截可借 session 分叉通道族判,
1385
+ * maxTurns 无可借位),故扩位而非保留引擎内硬编码 shape 检查。
1386
+ */
1387
+ maxTurns: boolean;
829
1388
  }
830
1389
  /** 引擎探针报告(probe() 返回)。探针在引擎 factory 初始化与版本变化检测时触发(P4 接线)。 */
831
1390
  interface ProbeReport {
@@ -848,9 +1407,16 @@ interface ProbeReport {
848
1407
  * interact 的 action(D1 交互控制面)。pi 首期原生实现(现有 chatMode 行为直通);
849
1408
  * 声明 conversation unsupported 的引擎调用前拒绝(engine_capability_unsupported)。
850
1409
  */
851
- type InteractAction = {
1410
+ type InteractAction =
1411
+ /**
1412
+ * interrupt:true = steer(抢占)/ false|缺省 = followUp(排队)——pi streamingBehavior
1413
+ * 语义的中立承载(D1 §3.3.5「后续 wave 如需抢占语义再扩展 InteractAction」的兑现,
1414
+ * chat 域投递经 engine.interact 接通时落地;不支持抢占的引擎忽略)。
1415
+ */
1416
+ {
852
1417
  kind: "message";
853
1418
  payload: string;
1419
+ interrupt?: boolean;
854
1420
  } | {
855
1421
  kind: "close";
856
1422
  payload?: {
@@ -872,4 +1438,4 @@ type InteractResult = {
872
1438
  message: string;
873
1439
  };
874
1440
 
875
- export type { AgentTaskSpec as A, DoneReason as D, EngineCapabilities as E, InteractAction as I, ProbeReport as P, RunStatus as R, SessionView as S, TracePatch as T, WorkerLogEntry as W, AgentEvent as a, EngineHandle as b, AgentOutcome as c, InteractResult as d, AgentUsage as e, AgentCallOpts as f, AgentResult as g, ExecutionTraceNode as h, EngineHandleData as i, PersonaSpec as j, ReplayedTurn as k };
1441
+ export { type SubagentToolResult as $, type AgentCallOpts as A, type DisplayItem as B, type ClosedReason as C, type DoneReason as D, type EngineCapabilities as E, type CancelResponse as F, type CloseResponse as G, type ForkFromResponse as H, type InteractAction as I, type MessageResponse as J, type BgResponse as K, type ListResponse as L, type ModelInfo as M, type ExternalState as N, type SubagentListItem as O, type ProbeReport as P, CLOSED_REASONS as Q, type RecordSnapshot as R, type SessionView as S, type ToolCall as T, DEFAULT_AGENT_NAME as U, DirtyWorktreeError as V, type WorktreeHandle as W, ForkDepthExceededError as X, type ReplayedTurn as Y, ResurrectDeniedError as Z, SLUG_MAX_LENGTH as _, type AgentEvent as a, type ToolCallEntry as a0, type EngineHandleData as b, type EngineHandle as c, type AgentOutcome as d, type InteractResult as e, type ExecutionRecord as f, type SubagentRecord as g, type ExecuteOptions as h, type AgentResult as i, type AgentConfig as j, type ResolvedModel as k, type AgentResult$1 as l, type ExecutionOutcome as m, type AgentEventLogEntry as n, type ExecutionStatus as o, type ProjectedOutcome as p, type SubagentsGlobalConfig as q, type ModelRegistryLike as r, type ExecutionHandle as s, type ExecutionMode as t, type PatchResult as u, type AgentUsage as v, type ExecutionTraceNode as w, type TracePatch as x, type RunStatus as y, type WorkerLogEntry as z };