@zhushanwen/subagent-core 0.4.0 → 0.6.0

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 (309) hide show
  1. package/dist/{chunk-4KN4TTG7.js → chunk-43ONBFZX.js} +1 -1
  2. package/dist/{chunk-X7SZ5HLQ.js → chunk-V3VHZ2VX.js} +20 -27
  3. package/dist/execution/engine/engines/zcode/constants.cjs +29 -41
  4. package/dist/execution/engine/engines/zcode/constants.d.cts +65 -53
  5. package/dist/execution/engine/engines/zcode/constants.d.ts +65 -53
  6. package/dist/execution/engine/engines/zcode/constants.js +17 -27
  7. package/dist/execution/engine/engines/zcode/reader.d.cts +2 -1
  8. package/dist/execution/engine/engines/zcode/reader.d.ts +2 -1
  9. package/dist/execution/engine/engines/zcode/reader.js +2 -2
  10. package/dist/index.cjs +17100 -14082
  11. package/dist/index.d.cts +5336 -4033
  12. package/dist/index.d.ts +5336 -4033
  13. package/dist/index.js +17020 -14055
  14. package/dist/{types-DpUO16pj.d.cts → types-C3fE3R9x.d.cts} +280 -112
  15. package/dist/{types-DpUO16pj.d.ts → types-C3fE3R9x.d.ts} +280 -112
  16. package/dist.bundle/index.cjs +34933 -0
  17. package/package.json +3 -3
  18. package/src/__tests__/agent-opts-resolver-schema-prompt.test.ts +0 -1
  19. package/src/__tests__/append-system-prompt-assembly.test.ts +8 -7
  20. package/src/__tests__/fr4-get-state-handshake.test.ts +2 -2
  21. package/src/__tests__/m2-append-content-probe.test.ts +0 -1
  22. package/src/__tests__/manifest-store.test.ts +10 -9
  23. package/src/__tests__/record-store-cache.test.ts +0 -2
  24. package/src/__tests__/record-store-index.test.ts +1 -2
  25. package/src/__tests__/review-fix-loop-script.test.ts +4 -2
  26. package/src/__tests__/review-fix-loop-utils.test.ts +10 -10
  27. package/src/__tests__/robustness-low-batch1.test.ts +6 -5
  28. package/src/__tests__/robustness-medium-batch1.test.ts +2 -2
  29. package/src/__tests__/robustness-medium-batch2.test.ts +17 -6
  30. package/src/__tests__/robustness-medium-batch4.test.ts +2 -2
  31. package/src/__tests__/session-runner.test.ts +1 -1
  32. package/src/core/__tests__/host-services.test.ts +2 -2
  33. package/src/core/__tests__/logger.test.ts +1 -1
  34. package/src/core/error-message.ts +9 -0
  35. package/src/core/host-services.ts +21 -5
  36. package/src/core/notify-ports.ts +18 -5
  37. package/src/execution/__tests__/agent-profile.test.ts +4 -4
  38. package/src/execution/__tests__/agent-registry.test.ts +370 -0
  39. package/src/execution/__tests__/agent-result-mapper.test.ts +18 -2
  40. package/src/execution/__tests__/agents-assembly.test.ts +2 -2
  41. package/src/execution/__tests__/alive-store.test.ts +1 -1
  42. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +6 -6
  43. package/src/execution/__tests__/chat-engine-routing.test.ts +68 -33
  44. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +4 -4
  45. package/src/execution/__tests__/cold-resurrect.test.ts +283 -0
  46. package/src/execution/__tests__/collect-budget.test.ts +291 -0
  47. package/src/execution/__tests__/collect-coordinator-service.test.ts +327 -0
  48. package/src/execution/__tests__/collect-coordinator.test.ts +371 -0
  49. package/src/execution/__tests__/collect-mixed-dispatch.test.ts +262 -0
  50. package/src/execution/__tests__/config-collect-sync.test.ts +120 -0
  51. package/src/execution/__tests__/config.test.ts +1 -1
  52. package/src/execution/__tests__/delivery-methods.test.ts +75 -62
  53. package/src/execution/__tests__/descendant-sweep-guards.test.ts +220 -0
  54. package/src/execution/__tests__/descendant-sweep.test.ts +6 -6
  55. package/src/execution/__tests__/dialog-queue.test.ts +2 -2
  56. package/src/execution/__tests__/engine-model-validation.test.ts +741 -0
  57. package/src/execution/__tests__/epipe-fallback.test.ts +29 -24
  58. package/src/execution/__tests__/execute-and-await-worktree.test.ts +21 -91
  59. package/src/execution/__tests__/execute-nesting.test.ts +34 -188
  60. package/src/execution/__tests__/execution-record.test.ts +217 -60
  61. package/src/execution/__tests__/execution-runtime-face.test.ts +5 -5
  62. package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +4 -4
  63. package/src/execution/__tests__/finalize-record.test.ts +173 -17
  64. package/src/execution/__tests__/finalized-marker.test.ts +1 -1
  65. package/src/execution/__tests__/gc-timer.test.ts +56 -3
  66. package/src/execution/__tests__/get-record-for-action-restart.test.ts +12 -12
  67. package/src/execution/__tests__/get-state-handshake.test.ts +1 -1
  68. package/src/execution/__tests__/helpers/mock-extension-api.ts +1 -1
  69. package/src/execution/__tests__/helpers/session-runner-mocks.ts +113 -0
  70. package/src/execution/__tests__/helpers/spawn-mock.ts +150 -3
  71. package/src/execution/__tests__/helpers/subagent-service-mocks.ts +137 -0
  72. package/src/execution/__tests__/keep-alive-no-progress.test.ts +50 -148
  73. package/src/execution/__tests__/kill-all-escalation.test.ts +2 -2
  74. package/src/execution/__tests__/lifecycle-predicates.test.ts +1 -2
  75. package/src/execution/__tests__/manifest-parentid.test.ts +4 -4
  76. package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +1 -1
  77. package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +1 -1
  78. package/src/execution/__tests__/model-resolver.test.ts +2 -2
  79. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +23 -121
  80. package/src/execution/__tests__/nested-visibility.test.ts +2 -0
  81. package/src/execution/__tests__/notify-batch.test.ts +500 -0
  82. package/src/execution/__tests__/notify-ledger.test.ts +1000 -18
  83. package/src/execution/__tests__/output-collector.test.ts +117 -6
  84. package/src/execution/__tests__/pi-invocation.test.ts +36 -4
  85. package/src/execution/__tests__/record-entry-collect.test.ts +102 -0
  86. package/src/execution/__tests__/record-store.test.ts +10 -9
  87. package/src/execution/__tests__/records-cwd-isolation.test.ts +2 -2
  88. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +29 -132
  89. package/src/execution/__tests__/recursive-visibility-env.test.ts +55 -179
  90. package/src/execution/__tests__/relay-env.test.ts +12 -1
  91. package/src/execution/__tests__/rpc-mode.test.ts +2 -2
  92. package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +387 -0
  93. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +15 -9
  94. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +4 -4
  95. package/src/execution/__tests__/run-spawn-edges.test.ts +17 -15
  96. package/src/execution/__tests__/run-spawn-integration.test.ts +2 -2
  97. package/src/execution/__tests__/run-spawn-resume.test.ts +2 -2
  98. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +2 -2
  99. package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +4 -4
  100. package/src/execution/__tests__/service-kill-escalation.test.ts +7 -5
  101. package/src/execution/__tests__/session-context-resolver.test.ts +0 -2
  102. package/src/execution/__tests__/session-file-gc.test.ts +36 -1
  103. package/src/execution/__tests__/session-pending.test.ts +257 -14
  104. package/src/execution/__tests__/session-reconstructor.test.ts +366 -15
  105. package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +1 -1
  106. package/src/execution/__tests__/session-runner-close-prune.test.ts +2 -2
  107. package/src/execution/__tests__/session-runner-dispatch.test.ts +489 -0
  108. package/src/execution/__tests__/session-runner-epipe.test.ts +3 -3
  109. package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +5 -4
  110. package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +290 -0
  111. package/src/execution/__tests__/session-runner-schema-env.test.ts +7 -5
  112. package/src/execution/__tests__/settled-watchdog.test.ts +282 -47
  113. package/src/execution/__tests__/spawn-args.test.ts +11 -10
  114. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +26 -23
  115. package/src/execution/__tests__/spawn-event-adapter.test.ts +3 -3
  116. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +5 -4
  117. package/src/execution/__tests__/spawned-children.test.ts +2 -1
  118. package/src/execution/__tests__/start-collect-guard.test.ts +255 -0
  119. package/src/execution/__tests__/start-sync-model-guard.test.ts +5 -5
  120. package/src/execution/__tests__/stdin-writer.test.ts +6 -4
  121. package/src/execution/__tests__/stream-sink-retirement.test.ts +6 -6
  122. package/src/execution/__tests__/subagent-actions-core.test.ts +48 -22
  123. package/src/execution/__tests__/subagent-service-message-close.test.ts +29 -26
  124. package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +21 -8
  125. package/src/execution/__tests__/subagent-service-notify-gate.test.ts +27 -22
  126. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +30 -29
  127. package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +45 -20
  128. package/src/execution/__tests__/subagent-service.test.ts +37 -30
  129. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +88 -12
  130. package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +75 -0
  131. package/src/execution/__tests__/subprocess-agent-runner.test.ts +22 -20
  132. package/src/execution/__tests__/sync-collect-recovery.test.ts +1117 -0
  133. package/src/execution/__tests__/temp-prompt.test.ts +1 -1
  134. package/src/execution/__tests__/timeout-integration.test.ts +6 -5
  135. package/src/execution/__tests__/tombstone-store.test.ts +1 -1
  136. package/src/execution/__tests__/turn-limiter-semantics.test.ts +1 -1
  137. package/src/execution/__tests__/turn-limiter.test.ts +1 -1
  138. package/src/execution/__tests__/ui-request-handler-factory.test.ts +12 -6
  139. package/src/execution/__tests__/ui-request-handler.test.ts +4 -3
  140. package/src/execution/__tests__/ui-request-queue.test.ts +142 -2
  141. package/src/execution/__tests__/worktree-git-ops.test.ts +1 -1
  142. package/src/execution/__tests__/worktree-manager.test.ts +14 -5
  143. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +4 -3
  144. package/src/execution/__tests__/worktree-reconcile-aging.test.ts +2 -2
  145. package/src/execution/__tests__/worktree-reconcile.integration.test.ts +1 -1
  146. package/src/execution/__tests__/worktree-registry.test.ts +1 -1
  147. package/src/execution/agent-registry.ts +74 -30
  148. package/src/execution/agent-result-mapper.ts +3 -0
  149. package/src/execution/cold-resurrect.ts +199 -0
  150. package/src/execution/collect-coordinator.ts +200 -0
  151. package/src/execution/config.ts +77 -5
  152. package/src/execution/engine/__tests__/common/capability-gate.test.ts +91 -0
  153. package/src/execution/engine/__tests__/common/data-dir.test.ts +1 -1
  154. package/src/execution/engine/__tests__/common/event-journal.test.ts +1 -1
  155. package/src/execution/engine/__tests__/common/journal-wiring.test.ts +84 -0
  156. package/src/execution/engine/__tests__/common/kill-chain.test.ts +34 -7
  157. package/src/execution/engine/__tests__/common/persona-router.test.ts +4 -5
  158. package/src/execution/engine/__tests__/common/pool-manager.test.ts +213 -53
  159. package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +149 -0
  160. package/src/execution/engine/__tests__/common/session-view-service.test.ts +499 -0
  161. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +22 -112
  162. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +15 -28
  163. package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +1 -1
  164. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +12 -12
  165. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +2 -2
  166. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +21 -82
  167. package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +4 -7
  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 +4 -2
  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/engines/pi/__tests__/pi-engine.test.ts +174 -28
  181. package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +257 -0
  182. package/src/execution/{argv-mirror.ts → engine/engines/pi/argv-mirror.ts} +43 -21
  183. package/src/execution/{get-state-handshake.ts → engine/engines/pi/get-state-handshake.ts} +1 -1
  184. package/src/execution/{output-collector.ts → engine/engines/pi/output-collector.ts} +108 -19
  185. package/src/execution/engine/engines/pi/pi-engine.ts +434 -38
  186. package/src/execution/{pi-invocation.ts → engine/engines/pi/pi-invocation.ts} +2 -2
  187. package/src/execution/engine/engines/pi/reader.ts +11 -0
  188. package/src/execution/engine/engines/pi/registration.ts +4 -2
  189. package/src/execution/{session-runner.ts → engine/engines/pi/session-runner.ts} +617 -412
  190. package/src/execution/{spawn-event-adapter.ts → engine/engines/pi/spawn-event-adapter.ts} +75 -34
  191. package/src/execution/{stdin-writer.ts → engine/engines/pi/stdin-writer.ts} +10 -9
  192. package/src/execution/{temp-prompt.ts → engine/engines/pi/temp-prompt.ts} +2 -2
  193. package/src/execution/{turn-limiter.ts → engine/engines/pi/turn-limiter.ts} +1 -1
  194. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +54 -27
  195. package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +321 -0
  196. package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +13 -12
  197. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +7 -210
  198. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +6 -110
  199. package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +247 -0
  200. package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +451 -0
  201. package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +20 -8
  202. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +77 -110
  203. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +26 -320
  204. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +210 -0
  205. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +353 -0
  206. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +282 -0
  207. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +372 -0
  208. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +48 -148
  209. package/src/execution/engine/engines/zcode/appserver-launcher.ts +167 -0
  210. package/src/execution/engine/engines/zcode/connection.ts +24 -11
  211. package/src/execution/engine/engines/zcode/constants.ts +75 -71
  212. package/src/execution/engine/engines/zcode/golden-sample.ts +8 -46
  213. package/src/execution/engine/engines/zcode/parser.ts +12 -346
  214. package/src/execution/engine/engines/zcode/preparer.ts +12 -143
  215. package/src/execution/engine/engines/zcode/session-channel.ts +351 -39
  216. package/src/execution/engine/engines/zcode/zcode-engine.ts +665 -760
  217. package/src/execution/engine/host-task-spec.ts +32 -36
  218. package/src/execution/engine/model-validation.ts +177 -0
  219. package/src/execution/engine/port.ts +24 -6
  220. package/src/execution/engine/routing.ts +75 -1
  221. package/src/execution/engine/types.ts +30 -103
  222. package/src/execution/execution-record.ts +229 -144
  223. package/src/execution/finalize-record.ts +141 -99
  224. package/src/execution/idle-gc.ts +28 -0
  225. package/src/execution/lifecycle-predicates.ts +1 -1
  226. package/src/execution/notifier.ts +234 -25
  227. package/src/execution/notify-host.ts +232 -0
  228. package/src/execution/record-entry.ts +16 -0
  229. package/src/execution/record-store.ts +280 -103
  230. package/src/execution/round-settlement.ts +93 -0
  231. package/src/execution/session-file-gc.ts +96 -62
  232. package/src/execution/session-reconstructor.ts +256 -143
  233. package/src/execution/sessions-index.ts +117 -47
  234. package/src/execution/settled-watchdog.ts +264 -52
  235. package/src/execution/subagent-actions-core.ts +84 -28
  236. package/src/execution/subagent-service.ts +1225 -964
  237. package/src/execution/subprocess-agent-runner.ts +144 -97
  238. package/src/execution/sync-rebuild.ts +87 -0
  239. package/src/execution/types.ts +72 -0
  240. package/src/execution/ui-request-handler-factory.ts +102 -74
  241. package/src/execution/ui-request-queue.ts +50 -19
  242. package/src/index.ts +442 -316
  243. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +1 -1
  244. package/src/orchestration/__tests__/agent-call-stream.test.ts +2 -2
  245. package/src/orchestration/__tests__/args-validator.test.ts +14 -0
  246. package/src/orchestration/__tests__/config-loader.test.ts +1 -1
  247. package/src/orchestration/__tests__/error-recovery-rebuild-failure.test.ts +1 -1
  248. package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +11 -9
  249. package/src/orchestration/__tests__/execute-agent-call.test.ts +151 -11
  250. package/src/orchestration/__tests__/file-run-store-prune.test.ts +1 -1
  251. package/src/orchestration/__tests__/file-run-store-throttle.test.ts +1 -1
  252. package/src/orchestration/__tests__/file-run-store.test.ts +7 -6
  253. package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +2 -2
  254. package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +1 -1
  255. package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +3 -3
  256. package/src/orchestration/__tests__/lifecycle.test.ts +7 -5
  257. package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +1 -1
  258. package/src/orchestration/__tests__/review-fix-loop-scriptpath-failfast.test.ts +1 -1
  259. package/src/orchestration/__tests__/run-snapshot.test.ts +8 -5
  260. package/src/orchestration/__tests__/script-generate.test.ts +5 -5
  261. package/src/orchestration/__tests__/script-lint.test.ts +17 -0
  262. package/src/orchestration/__tests__/skill-discovery.test.ts +2 -2
  263. package/src/orchestration/__tests__/test-mocks.ts +2 -0
  264. package/src/orchestration/__tests__/worker-exit-without-result.test.ts +7 -6
  265. package/src/orchestration/__tests__/worker-message-pump-finalize-run.test.ts +229 -0
  266. package/src/orchestration/__tests__/{error-recovery-handlers.test.ts → worker-message-pump-handlers.test.ts} +27 -19
  267. package/src/orchestration/__tests__/{error-recovery-postmessage-defense.test.ts → worker-message-pump-postmessage-defense.test.ts} +8 -8
  268. package/src/orchestration/__tests__/{error-recovery-serialize-failed-result.test.ts → worker-message-pump-serialize-failed-result.test.ts} +2 -2
  269. package/src/orchestration/__tests__/{error-recovery-workflow-call.test.ts → worker-message-pump-workflow-call.test.ts} +1 -1
  270. package/src/orchestration/__tests__/worker-pending-timeout-abort.test.ts +1 -1
  271. package/src/orchestration/__tests__/worker-script-builder.test.ts +1 -1
  272. package/src/orchestration/__tests__/workflow-files.test.ts +10 -10
  273. package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +1 -1
  274. package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +1 -1
  275. package/src/orchestration/agent-opts-resolver.ts +1 -1
  276. package/src/orchestration/args-validator.ts +53 -31
  277. package/src/orchestration/execute-agent-call.ts +19 -73
  278. package/src/orchestration/launcher.ts +128 -81
  279. package/src/orchestration/lifecycle.ts +43 -45
  280. package/src/orchestration/models/ports.ts +4 -4
  281. package/src/orchestration/models/run-runtime.ts +2 -2
  282. package/src/orchestration/models/trace.ts +1 -1
  283. package/src/orchestration/models/types.ts +111 -22
  284. package/src/orchestration/models/workflow-run.ts +1 -1
  285. package/src/orchestration/script-lint.ts +91 -58
  286. package/src/orchestration/{error-recovery.ts → worker-message-pump.ts} +157 -150
  287. package/src/shared/__tests__/atomic-write.test.ts +1 -1
  288. package/src/shared/__tests__/meta-parser.test.ts +151 -0
  289. package/src/shared/__tests__/resource-discovery-host-roots.test.ts +5 -5
  290. package/src/shared/__tests__/resource-discovery.test.ts +258 -215
  291. package/src/shared/atomic-write.ts +12 -9
  292. package/src/shared/meta-parser.ts +158 -84
  293. package/src/shared/model-ref.ts +15 -2
  294. package/src/shared/resource-discovery.ts +9 -183
  295. package/src/shared/schema-jsonify.ts +1 -1
  296. package/workflows/review-fix-loop-utils.cjs +151 -89
  297. package/workflows/review-fix-loop-utils.d.cts +287 -0
  298. package/src/execution/__tests__/execute-options-mapper.test.ts +0 -200
  299. package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
  300. package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
  301. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
  302. package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
  303. package/src/execution/engine/engines/zcode/__tests__/preparer-appserver.test.ts +0 -387
  304. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -710
  305. package/src/execution/engine/engines/zcode/appserver-home.ts +0 -442
  306. package/src/execution/engine/engines/zcode/appserver-probe.ts +0 -141
  307. package/src/execution/engine/engines/zcode/launcher.ts +0 -161
  308. package/src/execution/execute-options-mapper.ts +0 -115
  309. package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -288
@@ -1,3 +1,5 @@
1
+ import { GuiRenderResult } from '@xyz-agent/extension-protocol';
2
+
1
3
  /**
2
4
  * ModelRegistry 的最小接口(duck-typed,测试可 mock)。
3
5
  * 字段结构与 Pi SDK 的 ctx.modelRegistry 对齐。
@@ -49,6 +51,19 @@ interface ResolvedModel {
49
51
  thinkingLevel: string | undefined;
50
52
  }
51
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";
52
67
  /**
53
68
  * 唯一执行状态。所有路径共用。v4 B-1 两态收敛:旧 idle 折入 running、
54
69
  * 旧 cancelled 折入 closed(closedReason='cancelled' 区分)。
@@ -86,6 +101,8 @@ type ClosedReason = 'parent-shutdown' | 'parent-fork' | 'parent-new' | 'user-clo
86
101
  */
87
102
  declare class ResurrectDeniedError extends Error {
88
103
  }
104
+ /** ClosedReason 全枚举值(运行时守卫用——防御性解析外部输入时校验成员资格)。 */
105
+ declare const CLOSED_REASONS: readonly ClosedReason[];
89
106
  /**
90
107
  * 终态三态对外语义(U3 C-outcome 一等披露)。
91
108
  *
@@ -279,6 +296,12 @@ interface AgentResult$1 {
279
296
  durationMs: number;
280
297
  success: boolean;
281
298
  error?: string;
299
+ /**
300
+ * [D5-③] 失败分诊结构化标签(类型 SSOT 在 orchestration/models/types.ts 的
301
+ * AgentFailureKind——消费语义「unknown=可重试」与其文档同源)。collectResult 对
302
+ * 最终 error 分类后写入;缺省 = unknown(可重试)。type-only 引用零运行时依赖。
303
+ */
304
+ failureKind?: AgentFailureKind;
282
305
  sessionId: string;
283
306
  toolCalls: ToolCall[];
284
307
  usage?: AgentUsageTotal;
@@ -306,6 +329,14 @@ interface AliveMarker {
306
329
  readonly id: string;
307
330
  readonly startedAt: number;
308
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
+ }
309
340
  /** fork depth 超限错误。 */
310
341
  declare class ForkDepthExceededError extends Error {
311
342
  constructor(message: string);
@@ -390,6 +421,14 @@ interface ExecutionRecord {
390
421
  journalPath?: string;
391
422
  poolKey: string;
392
423
  };
424
+ /**
425
+ * 同步收集模式标记(subagent-sync-collect 设计 §3.1.3,U1 foundation 契约)。
426
+ * 创建时确定不可变;undefined = async(缺省语义,旧记录零迁移)。持久化经
427
+ * subagent-record entry(record-entry.ts 序列化白名单,entry 唯一写点)。
428
+ * 消费方:U2 collectCoordinator 路由(sync→批缓冲)、U5 E1 重建投影。
429
+ * U2 接线点:service.createRecordForMode 从 ExecuteOptions.collect 读入 identity。
430
+ */
431
+ readonly collectMode?: "sync";
393
432
  status: ExecutionStatus;
394
433
  /** L2 关闭原因子枚举(仅 status="closed" 时有意义)。表达「为什么关闭」。
395
434
  * 由 tryTransition(record, "closed", reason) 写入;投影层按需派生对外语义。
@@ -401,6 +440,13 @@ interface ExecutionRecord {
401
440
  * record 无此字段,投影层按 projectOutcome 兜底(closed-legacy 语义)。
402
441
  */
403
442
  outcome?: ExecutionOutcome;
443
+ /**
444
+ * 离开批的终局标记(subagent-sync-collect 设计 §3.1.3,U1 foundation 契约)。
445
+ * 两出口统一落标:① 批闭合 flush 写账成功后;② E9 dispose 逐条转 async 写账后
446
+ * (均 appendEntry 持久化,U3/U5 写点)。undefined = 未离开批 / 旧记录零迁移。
447
+ * 消费方:U5 E1 重建扫描只收「collectMode=sync 且无本标记」的成员(防双重通知)。
448
+ */
449
+ batchFinalized?: boolean;
404
450
  /** 完整执行内容,按 turn 组织。createRecord 初始化为 [空 turn]。 */
405
451
  turns: Turn[];
406
452
  /** turn 计数(= turns.filter(closed).length,冗余存储供投影直接读)。 */
@@ -569,6 +615,17 @@ interface ExecuteOptions {
569
615
  * undefined/false = 一次性模式(默认,行为完全不变)。service.execute 透传到 createRecordForMode。
570
616
  */
571
617
  conversation?: boolean;
618
+ /**
619
+ * 同步收集模式(subagent-sync-collect 设计 §3.1.3,U1 foundation 契约)。
620
+ * undefined = config collectSync.default(缺省 "async",新 session 生效)。
621
+ * schema 层枚举限 "async"|"sync";运行时宽收 string 与 engine 字段同风格
622
+ * (非法值 ≠ "sync" 按 async 处理)。
623
+ * "sync" + conversation:true 组合在 startHandler E4 校验即拒
624
+ * (immediate throw,不产生半启动 record)。
625
+ * U2 接线点:service.createRecordForMode 读入 createRecord identity.collectMode
626
+ * (U1 打通类型与 startHandler 透传,record 落点归 U2)。
627
+ */
628
+ collect?: string;
572
629
  /**
573
630
  * 空闲超时毫秒数(仅 conversation 模式有意义)。覆盖默认 5min idle timeout。
574
631
  * 优先级:参数 > env XYZ_SUBAGENT_IDLE_TIMEOUT_MS > 默认 300000ms。
@@ -650,6 +707,16 @@ interface BgResponse {
650
707
  * 值语义由 U2(execution/notify-ledger.ts)兑现。
651
708
  */
652
709
  notifyContract: "ledger+at-least-once";
710
+ /**
711
+ * 同步收集登记回显段(subagent-sync-collect 设计 §3.1.1 交互样例,U1 foundation)。
712
+ * 仅 resolved 模式为 sync 时附带(async 响应字节零变化,G3):mode = 生效模式;
713
+ * pendingSyncCount = 当前未闭合批的 sync 成员总数(含本条;跨轮派发续累不重置,
714
+ * 与 D2 隐式批一致)。
715
+ */
716
+ collect?: {
717
+ mode: "sync";
718
+ pendingSyncCount: number;
719
+ };
653
720
  }
654
721
  /** list 的内层响应(挂在 SubagentToolResult.listResponse)。 */
655
722
  interface ListResponse {
@@ -676,6 +743,55 @@ interface MessageResponse {
676
743
  interface CloseResponse {
677
744
  closed: true;
678
745
  }
746
+ /**
747
+ * Tool 外层出参(renderResult + LLM content JSON 同源)。
748
+ * adapter 唯一产出:领域对象(bg/list/cancel/message/close 五选一)+ action/subagentId/sessionFile。
749
+ *
750
+ * - background 启动 → bgResponse(subagentId 有值;sessionFile 窗口期可能 undefined)
751
+ * - list → listResponse(最外层 subagentId/sessionFile 为 null,sessionFile 在各 item 内)
752
+ * - cancel → cancelResponse(subagentId 有值;sessionFile 无意义,可为 null)
753
+ * - message → messageResponse(subagentId 有值;sessionFile 无意义,可为 null)
754
+ * - close → closeResponse(subagentId 有值;sessionFile 无意义,可为 null)
755
+ */
756
+ type SubagentToolResult = {
757
+ action: "start";
758
+ subagentId: string;
759
+ sessionFile: string | null;
760
+ slug: string; /** registry 全等回显(U1):放行即与 registry 条目全等,"provider/id" 形态。 */
761
+ model: string;
762
+ bgResponse: BgResponse;
763
+ __gui__?: GuiRenderResult;
764
+ } | {
765
+ action: "list";
766
+ subagentId: null;
767
+ sessionFile: null;
768
+ listResponse: ListResponse;
769
+ __gui__?: GuiRenderResult;
770
+ } | {
771
+ action: "cancel";
772
+ subagentId: string;
773
+ sessionFile: null;
774
+ cancelResponse: CancelResponse;
775
+ __gui__?: GuiRenderResult;
776
+ } | {
777
+ action: "message";
778
+ subagentId: string;
779
+ sessionFile: null;
780
+ messageResponse: MessageResponse;
781
+ __gui__?: GuiRenderResult;
782
+ } | {
783
+ action: "close";
784
+ subagentId: string;
785
+ sessionFile: null;
786
+ closeResponse: CloseResponse;
787
+ __gui__?: GuiRenderResult;
788
+ } | {
789
+ action: "fork-from";
790
+ subagentId: string;
791
+ sessionFile: string | null;
792
+ forkFromResponse: ForkFromResponse;
793
+ __gui__?: GuiRenderResult;
794
+ };
679
795
  /** fork-from 的内层响应:新 subagent id + 作为继承源的旧记录 session 文件。
680
796
  * [v8.5 B] 断联恢复通道——新 subagent 以 --fork 方式继承旧会话历史,源文件只读
681
797
  * 不续写(pi fork 建 branched session,copy-on-write)。 */
@@ -696,6 +812,8 @@ interface SubagentRecord {
696
812
  status: ExecutionStatus;
697
813
  /** L2 关闭原因子枚举(仅 status="closed" 时有意义)。SP-1 新增。 */
698
814
  closedReason?: ClosedReason;
815
+ /** 终态三态对外语义(U3 C-outcome)。磁盘重建源一等直读;无字段的存量兜底走 projectOutcome。 */
816
+ outcome?: ExecutionOutcome;
699
817
  mode: ExecutionMode;
700
818
  startedAt: number;
701
819
  /** 根 Pi session ID(session 隔离过滤用)。递归链上所有层 record 同值。 */
@@ -768,6 +886,30 @@ interface SubagentRecord {
768
886
  journalPath?: string;
769
887
  poolKey: string;
770
888
  };
889
+ /**
890
+ * 同步收集模式标记(与 ExecutionRecord.collectMode 同源投影/重建,U1 foundation)。
891
+ * 缺省(存量 record)= async 投影,消费方零迁移。
892
+ */
893
+ collectMode?: "sync";
894
+ /**
895
+ * 离开批终局标记(与 ExecutionRecord.batchFinalized 同源投影/重建,U1 foundation)。
896
+ * 缺省 = 未离开批;U5 E1 重建扫描据此排除已离场成员。
897
+ */
898
+ batchFinalized?: boolean;
899
+ }
900
+ /**
901
+ * 同步收集(sync collect)配置节类型(subagent-sync-collect 设计 §3.1.3,U1 foundation)。
902
+ * 权威默认值在 config.ts DEFAULT_COLLECT_SYNC;坏值 sanitize 回默认不炸启动(E5,
903
+ * 与 maxConcurrent 同判)。类型定义于 types.ts(避免 config → types 反向依赖成环),
904
+ * config.ts re-export。
905
+ */
906
+ interface CollectSyncConfig {
907
+ /** start 未显式传 collect 时的缺省模式。新 session 生效(与 engine 配置时机一致)。 */
908
+ default: "async" | "sync";
909
+ /** 批通知单条目结果正文预算(字符):超出截断并接 session_read 指针行。flush 时热读。 */
910
+ perItemChars: number;
911
+ /** 批通知结果正文总量预算(字符):Σ 超限时统一收紧 effectivePerItem(U4 算法)。flush 时热读。 */
912
+ totalChars: number;
771
913
  }
772
914
  /**
773
915
  * 全局配置(~/.pi/agent/subagents/config.json)。
@@ -788,6 +930,11 @@ interface SubagentsGlobalConfig {
788
930
  engineRouting?: {
789
931
  strict: boolean;
790
932
  };
933
+ /**
934
+ * 同步收集配置节(subagent-sync-collect 设计 §3.1.3,U1 foundation)。
935
+ * 整节缺省 = DEFAULT_COLLECT_SYNC(config.ts);逐字段 sanitize 回默认(E5)。
936
+ */
937
+ collectSync?: CollectSyncConfig;
791
938
  }
792
939
  /**
793
940
  * Record 的只读视图。store.snapshot() 返回。
@@ -844,7 +991,36 @@ type RunStatus = "running" | "done";
844
991
  /** 终态原因。done 时必有(WorkflowRun 不变式)。 */
845
992
  type DoneReason = "completed" | "failed" | "aborted" | "budget_limited" | "time_limited" | "invalid_args";
846
993
  /**
847
- * 单次 agent 调用的输入选项。
994
+ * slug 最大长度(D6 合流迁入本文件,原权威定义在已删除的 execution/execute-options-mapper.ts)。
995
+ * 历史值 20 偏紧——描述性 slug 如 "audit-structured-output"(23)/ "fix-subagent-wf-tools"(21)
996
+ * 会撞上限,放宽到 35 兼顾「短到能塞进 TUI 标题行」与「容纳合理描述性 kebab-case 名」。
997
+ * 放本文件的原因:约束对象是 AgentCallOpts.description(slug 的源字段,见下方 slug 派生说明),
998
+ * 与字段同文件;worker-message-pump(live record slug 截断)与壳侧 tool schema maxLength 共享引用。
999
+ */
1000
+ declare const SLUG_MAX_LENGTH = 35;
1001
+ /**
1002
+ * 单次 agent 调用的任务声明(D6 任务形状合流后的单一形状)。
1003
+ *
1004
+ * [D6 合流裁决] 本类型 = 原 AgentCallOpts(workflow 调用方声明,18 字段)与原
1005
+ * AgentTaskSpec(engine 中立任务声明,已删除)的合流形态,从模型脚本 agent() API
1006
+ * 到 EnginePort.run 直达 pi 边界一次映射——SAR 链路上的 ExecuteOptions/AgentTaskSpec
1007
+ * 中间态消除(设计 docs/design/subagent-dual-track-convergence.md §3.3 D6 / 终态四)。
1008
+ *
1009
+ * 终态命名按变化轴裁定为 AgentCallOpts,理由:
1010
+ * - 字段演进的首要驱动轴是「调用方要表达的任务语义」(agent() API 是唯一生产写入方,
1011
+ * 合流字段中 prompt/description/skill/skillPath/schemaEnv/thinkingLevel 等多数派
1012
+ * 已是调用方命名);
1013
+ * - 原 AgentTaskSpec 的中立重命名层(task/slug/effort/persona)与调用方命名是
1014
+ * 形式同构、语义同构的假差异(prompt≡task、slug=description 截断、effort≡thinkingLevel、
1015
+ * persona≡skillPath+appendSystemPrompt 平铺),按「消假差异」原则并入调用方命名;
1016
+ * - 持久化兼容反向锁定 prompt 形态:jsonl run 快照的 AgentCall.opts 与 worker 消息
1017
+ * opts 均以 prompt 字段落盘,改名会破坏旧快照重水合。
1018
+ *
1019
+ * 引擎中立字段的并入方式(可选字段,原 AgentTaskSpec 独有字段去向):
1020
+ * - graceTurns / conversation / idleTimeoutMs / denyTools / permissionMode:可选并入;
1021
+ * - persona.agentRef:裁撤(无生产写入方、无消费者——pi 走 agent 字段解析身份);
1022
+ * - requires:裁撤(P4 形状预留、无生产写入方;且并入需 import EngineCapabilities
1023
+ * 形成 orchestration↔engine 类型环)。将来能力依赖声明下钻时在本形状上加回。
848
1024
  *
849
1025
  * D-12 仅重组执行编排,AgentCallOpts 形状保持兼容。
850
1026
  */
@@ -880,14 +1056,20 @@ interface AgentCallOpts {
880
1056
  */
881
1057
  timeoutMs?: number;
882
1058
  /**
883
- * Turn 上限(turn limiter 用)。
884
- *
885
- * [预算语义对齐] 未传或 <=0 = 不限 turn;此时也不按 turns 估算 spawn watchdog——
886
- * 仅当 env XYZ_SUBAGENT_SPAWN_WATCHDOG_MS 设置时才按绝对时限挂 watchdog(见
887
- * session-runner.resolveSpawnWatchdogMs)。mapToExecuteOptions 原样透传到
888
- * ExecuteOptions.maxTurns 引擎 task-spec → runSpawn。
889
- */
1059
+ * Turn 上限(turn limiter 用)。
1060
+ *
1061
+ * [预算语义对齐] 未传或 <=0 = 不限 turn;此时也不按 turns 估算 spawn watchdog——
1062
+ * 仅当 env XYZ_SUBAGENT_SPAWN_WATCHDOG_MS 设置时才按绝对时限挂 watchdog(见
1063
+ * session-runner.resolveSpawnWatchdogMs)。pi 边界直出为 ExecuteOptions.maxTurns
1064
+ * → runSpawn(D6 合流后无中间映射层)。
1065
+ */
890
1066
  maxTurns?: number;
1067
+ /**
1068
+ * Turn limiter 的宽限轮数(原 AgentTaskSpec.graceTurns 并入):超 maxTurns 后
1069
+ * 允许继续的轮数(等待在途工具收尾)。pi 引擎消费;workflow agent() 无写入方,
1070
+ * chat 域(ExecuteOptions.graceTurns 同名透传)经 host-task-spec 填充。
1071
+ */
1072
+ graceTurns?: number;
891
1073
  /**
892
1074
  * Skill name to load (e.g. "code-review"). Resolved to SKILL.md path
893
1075
  * and injected via --skill flag in the subprocess.
@@ -908,18 +1090,18 @@ interface AgentCallOpts {
908
1090
  */
909
1091
  agent?: string;
910
1092
  /**
911
- * System prompt injection CONTENT (not file paths).
912
- * Set by agent-opts-resolver: schema structured-output instruction string.
913
- * Agent systemPrompt is NOT included here (handled by resolveIdentity/agentConfig).
914
- * mapToExecuteOptions passes this through to ExecuteOptions.appendSystemPrompt
915
- * (same name/semantics, transparent passthrough).
916
- */
1093
+ * System prompt injection CONTENT (not file paths).
1094
+ * Set by agent-opts-resolver: schema structured-output instruction string.
1095
+ * Agent systemPrompt is NOT included here (handled by resolveIdentity/agentConfig).
1096
+ * pi 边界直出为 ExecuteOptions.appendSystemPrompt(同名同义透传,D6 合流后无中间映射层)。
1097
+ */
917
1098
  appendSystemPrompt?: string[];
918
1099
  /**
919
- * Schema JSON for PI_WORKFLOW_SCHEMA env var.
920
- * Set by agent-opts-resolver when opts.schema is present; passed as env var
921
- * to activate the structured-output tool + hook.
922
- */
1100
+ * Schema JSON for PI_WORKFLOW_SCHEMA env var.
1101
+ * Set by agent-opts-resolver when opts.schema is present (值 = stringifySchemaCached
1102
+ * compact,与 schema 派生等值); passed as env var to activate the structured-output
1103
+ * tool + hook. pi 边界直出时 schema 派生优先、本字段兜底(解耦形态通道,生产不可达)。
1104
+ */
923
1105
  schemaEnv?: string;
924
1106
  /**
925
1107
  * Per-call 工作目录(ADR-029 决策 1)。传给 child_process.spawn 的 cwd option。
@@ -938,11 +1120,36 @@ interface AgentCallOpts {
938
1120
  * agent() → execute-agent-call → SAR 路由层。
939
1121
  */
940
1122
  engine?: string;
941
- /** Filesystem isolation: when true, creates a new git worktree for the agent. Independent of fork. */
942
- worktree?: boolean;
1123
+ /** Filesystem isolation: when true, creates a new git worktree for the agent. Independent of fork.
1124
+ * [D6 合流] 类型扩展为 boolean | WorktreeHandle(原 AgentTaskSpec.worktree 的超集)——
1125
+ * WorktreeHandle 形态仅在 chat 域(复用外部已创建的 worktree)出现,workflow agent()
1126
+ * 恒传 boolean。 */
1127
+ worktree?: boolean | WorktreeHandle;
943
1128
  /** When true, agent() resolves {value, sessionFile, worktreePath, error} instead of a bare value.
944
- * Worker-layer flag only — not forwarded to ExecuteOptions (mapToExecuteOptions drops it). */
1129
+ * Worker-layer flag only — not consumed by any engine (dropped at the pi boundary). */
945
1130
  returnMeta?: boolean;
1131
+ /**
1132
+ * 可持续对话模式(原 AgentTaskSpec.conversation 并入):true = record 标记 chatMode,
1133
+ * 轮次完成进 idle 态等待 message 续聊。chat 域(ExecuteOptions.conversation 同名)经
1134
+ * host-task-spec 填充;workflow agent() 无写入方。
1135
+ */
1136
+ conversation?: boolean;
1137
+ /**
1138
+ * 空闲超时毫秒数(原 AgentTaskSpec.idleTimeoutMs 并入,仅 conversation 模式有意义)。
1139
+ * 优先级:参数 > env XYZ_SUBAGENT_IDLE_TIMEOUT_MS > 默认 300000ms;显式 0/负 = 禁用
1140
+ * idle GC。chat 域经 host-task-spec 填充。
1141
+ */
1142
+ idleTimeoutMs?: number;
1143
+ /**
1144
+ * 工具 denylist(原 AgentTaskSpec.denyTools 并入,中立新增面):各引擎做语法映射
1145
+ * (zcode buildZcodeArgv 消费;pi 链路暂无对应面)。无 workflow 写入方,预留形状。
1146
+ */
1147
+ denyTools?: string[];
1148
+ /**
1149
+ * 中立权限模式(原 AgentTaskSpec.permissionMode 并入,预留形状):映射按各引擎
1150
+ * capabilities.permissionMode。无生产写入方/消费者。
1151
+ */
1152
+ permissionMode?: string;
946
1153
  }
947
1154
  /**
948
1155
  * 单次 agent 调用的资源用量(FR-7 跨 turn 累积)。
@@ -965,6 +1172,23 @@ interface ToolCallEntry {
965
1172
  /** Args preview string. */
966
1173
  input: string;
967
1174
  }
1175
+ /**
1176
+ * 失败分诊结构化标签(D5-③,r1 MF4 钉正语义)。
1177
+ *
1178
+ * - stale_context:pi session context 被 compact/cancel/替换——重试无意义(同 call
1179
+ * 再次失败),不重试。
1180
+ * - schema_deterministic:确定性 schema 失败(SO tool 从未调用 / gate 终止 /
1181
+ * 不可满足 schema)——同 schema 重试必同结果,不重试。
1182
+ * - unknown:其余一切失败(瞬态 provider 错误、spawn 失败等)——**默认可重试**。
1183
+ *
1184
+ * **语义守恒(最高优先约束)**:unknown(含字段缺省)= 可重试——保持收敛前的
1185
+ * 默认重试语义;仅 stale_context 与 schema_deterministic 两态维持不重试特判。
1186
+ * 词表归属(产出侧单点识别):stale_context / schema_deterministic 的识别词表
1187
+ * (stale 词表与确定性 schema 失败标记前缀)保留在产出侧
1188
+ * execution/engine/engines/pi/output-collector.ts 包内——词表漂移的失效模式是
1189
+ * failureKind=unknown → 保守重试(安全默认),不再是静默漏诊。
1190
+ */
1191
+ type AgentFailureKind = "stale_context" | "schema_deterministic" | "unknown";
968
1192
  /**
969
1193
  * 单次 agent 调用的结果(统一形态)。
970
1194
  *
@@ -975,6 +1199,16 @@ interface AgentResult {
975
1199
  /** Raw text output from the agent. */
976
1200
  content: string;
977
1201
  /**
1202
+ * [D5-③] 失败分诊结构化标签(AgentFailureKind)。产出侧唯一识别点 =
1203
+ * execution/engine/engines/pi/output-collector.ts(collectResult 对最终 error
1204
+ * 分类后写入,经 agent-result-mapper / AgentOutcome 透传到本形态);消费侧
1205
+ * execute-agent-call 读本字段分诊,不再扫 error 文案子串。
1206
+ *
1207
+ * 仅在 error !== undefined 时有意义(成功时缺省);缺省视为 unknown = 可重试
1208
+ * (语义守恒,见 AgentFailureKind)。
1209
+ */
1210
+ failureKind?: AgentFailureKind;
1211
+ /**
978
1212
  * Parsed structured output.
979
1213
  * Present when `schema` was provided and the output was valid JSON.
980
1214
  * Source: tool_execution_end.result.details(validated data object)。
@@ -1069,95 +1303,6 @@ interface WorkerLogEntry {
1069
1303
  message: string;
1070
1304
  }
1071
1305
 
1072
- /** 人设(persona)注入规格:原 skillPath + appendSystemPrompt 收拢进一个语义单元(D2)。 */
1073
- interface PersonaSpec {
1074
- /**
1075
- * agent 名/路径。与 AgentTaskSpec.agent 的分工:agent 是 resolveIdentity 的身份解析
1076
- * 键(模型/系统提示等身份语义);agentRef 是 persona 注入通道的定位符——引擎按
1077
- * capabilities.personaInjection 决定注入通道(file/flag/prompt)时用它定位人设。
1078
- * pi 引擎不消费此字段(身份解析走 spec.agent),留给 flag/file 通道的引擎。
1079
- */
1080
- agentRef?: string;
1081
- /**
1082
- * 原 ExecuteOptions.skillPath。公共 persona 路由三策略(file/flag/prompt)的分流
1083
- * 载体(D4)——超长 prompt 时优先 file/flag 通道分流的落点。
1084
- */
1085
- skillPath?: string;
1086
- /** 追加系统提示内容数组(原样透传;schema 仿真段由公共降级层拼装后放入,P2)。 */
1087
- appendSystemPrompt?: string[];
1088
- }
1089
- /**
1090
- * 引擎无关的 agent 任务声明(= ExecuteOptions 泛化,字段逐条锚定设计 §3.3.5)。
1091
- *
1092
- * 与 ExecuteOptions 的差异(泛化点):
1093
- * - thinkingLevel(pi 7 档枚举语义)→ effort?: string,各引擎自行映射或忽略;
1094
- * - skillPath + appendSystemPrompt → persona(PersonaSpec);
1095
- * - conversation/idleTimeoutMs 保留原名透传——属 interact 交互控制面的 task 标志(D1),
1096
- * 不是 pi 专有语义的泄漏,而是「任务声明里声明交互模式」的中立表达;
1097
- * - 删字段去向:signal/ctxModel/onComplete 是运行期句柄,移入 RunContext(port.ts);
1098
- * schemaEnv 内化到 PiEngine(从 task.schema 派生,见 engines/pi/task-spec-mapper.ts)。
1099
- *
1100
- * 新增(为后续 wave 预留形状,P1 无生产写入方):
1101
- * - denyTools:中立工具 denylist(附录 A 该行的载体);
1102
- * - permissionMode:中立权限模式(映射按 capabilities.permissionMode)。
1103
- */
1104
- interface AgentTaskSpec {
1105
- /** 原样(ExecuteOptions.task)。 */
1106
- task: string;
1107
- /** 原样(ExecuteOptions.slug,≤35 字符)。 */
1108
- slug: string;
1109
- /** 原样(ExecuteOptions.agent,resolveIdentity 的 agent ref)。 */
1110
- agent?: string;
1111
- /** 原样(ExecuteOptions.model;在引擎 provider 体系内解释,D9②)。 */
1112
- model?: string;
1113
- /**
1114
- * 泛化:原 ExecuteOptions.thinkingLevel。引擎无关的推理投入档位字符串——
1115
- * pi 引擎把它原值映射回 thinkingLevel 7 档;其他引擎自行映射(CC 5 档)或忽略
1116
- * (kimi ❌)。不定义联合枚举:档位集合是引擎私有语义,中立层只透传字符串。
1117
- */
1118
- effort?: string;
1119
- /** 泛化:原 skillPath + appendSystemPrompt 收拢(D2)。 */
1120
- persona?: PersonaSpec;
1121
- /**
1122
- * 原样(ExecuteOptions.schema)。native/emulated 分流依据(D4 硬边界):pi 的
1123
- * PI_WORKFLOW_SCHEMA env 注入链路按 native 直传,公共仿真层只服务 emulated 引擎。
1124
- */
1125
- schema?: Record<string, unknown>;
1126
- /**
1127
- * 原样(ExecuteOptions.maxTurns)。pi 引擎专属(turn limiter + spawn watchdog
1128
- * 估算依赖 pi 的 turn_end 事件流);其他引擎 prepare 期显式拒绝(U4,同 fork 模式)。
1129
- * 显式 0 压过 SPAWN_WATCHDOG_ENV 兑底(SP-6 参数 > env,U5);undefined 未传才由
1130
- * env 兑底。
1131
- */
1132
- maxTurns?: number;
1133
- /** 原样(ExecuteOptions.graceTurns)。 */
1134
- graceTurns?: number;
1135
- /** 原样(ExecuteOptions.fork)。pi 专属;其他引擎 prepare 期按 capabilities 拒绝。 */
1136
- fork?: boolean;
1137
- /**
1138
- * 原样(ExecuteOptions.worktree)。公共层职责(worktree-manager),非引擎职责——
1139
- * 引擎只把它当 spawn cwd 的来源之一。
1140
- */
1141
- worktree?: boolean | WorktreeHandle;
1142
- /** 原样(ExecuteOptions.cwd)。 */
1143
- cwd?: string;
1144
- /** 原样(ExecuteOptions.conversation,interact 控制面的 task 标志,D1)。 */
1145
- conversation?: boolean;
1146
- /** 原样(ExecuteOptions.idleTimeoutMs,同上)。 */
1147
- idleTimeoutMs?: number;
1148
- /** 新增:中立工具 denylist。各引擎做语法映射(附录 A「工具 denylist」行的载体)。 */
1149
- denyTools?: string[];
1150
- /** 新增:中立权限模式。映射按 capabilities.permissionMode(kimi fixed auto = ignored)。 */
1151
- permissionMode?: string;
1152
- /**
1153
- * [P4 形状预留,D9① 守卫 b 的独立载体] 任务对引擎能力的显式依赖声明。
1154
- * 首期无生产写入方:守卫 b 与守卫 a 合流(显式 engine 即能力依赖声明)——调用方
1155
- * 按引擎 id 表达依赖。下钻时机(AgentTaskSpec 泛化成熟后):调用方改按能力表达
1156
- * (如 requires: { sandbox: 'native' }),路由层将本字段与各引擎 capabilities()
1157
- * 对照,无引擎满足时报 engine_capability_unsupported(调用前拒绝,D11 处置三级)。
1158
- */
1159
- requires?: Partial<EngineCapabilities>;
1160
- }
1161
1306
  /**
1162
1307
  * 一次引擎执行的终态。锚定 orchestration/models/types.ts 的 AgentResult(workflow
1163
1308
  * 引擎消费的那份——content/parsedOutput/usage/error)并追加引擎层字段;见文件头消歧说明。
@@ -1165,6 +1310,13 @@ interface AgentTaskSpec {
1165
1310
  interface AgentOutcome {
1166
1311
  /** 原样(AgentResult.content)。 */
1167
1312
  content: string;
1313
+ /**
1314
+ * 原样(AgentResult.failureKind,D5-③ 失败分诊结构化标签)。产出侧唯一识别点 =
1315
+ * engines/pi/output-collector(collectResult 分类写入);缺省 = unknown = 可重试
1316
+ * (消费侧 executeAgentCall 只读字段分诊,不扫 error 文案)。非 pi 引擎不产出,
1317
+ * 恒缺省(unknown 语义)。
1318
+ */
1319
+ failureKind?: AgentFailureKind;
1168
1320
  /**
1169
1321
  * 原样(AgentResult.parsedOutput)。native 引擎直传 / 仿真层 ajv 产出(D4 硬分流:
1170
1322
  * native 路径公共层不做二次校验、不改写其结果)。
@@ -1289,6 +1441,15 @@ interface EngineCapabilities {
1289
1441
  interrupt: "native" | "kill-only";
1290
1442
  /** kimi headless 固定 auto = ignored;GUI 据此隐藏/提示。 */
1291
1443
  permissionMode: "native" | "fixed" | "ignored";
1444
+ /**
1445
+ * [D3-④ r3 裁定] maxTurns 轮数上限的执行能力位(pi = true:turn limiter + spawn
1446
+ * watchdog 估算兑现;zcode = false:无 turn_end 语义,静默丢弃会造成「传了上限却
1447
+ * 失控」假象)。调用前预检(common/capability-gate)按本位拦「声明不支持的能力」
1448
+ * ——pi 不拦 maxTurns(已支持能力,由 turn-limiter 执行)、zcode 同步拒绝。
1449
+ * 现状 11 个能力位无可承载 maxTurns 的语义位(fork 拦截可借 session 分叉通道族判,
1450
+ * maxTurns 无可借位),故扩位而非保留引擎内硬编码 shape 检查。
1451
+ */
1452
+ maxTurns: boolean;
1292
1453
  }
1293
1454
  /** 引擎探针报告(probe() 返回)。探针在引擎 factory 初始化与版本变化检测时触发(P4 接线)。 */
1294
1455
  interface ProbeReport {
@@ -1311,9 +1472,16 @@ interface ProbeReport {
1311
1472
  * interact 的 action(D1 交互控制面)。pi 首期原生实现(现有 chatMode 行为直通);
1312
1473
  * 声明 conversation unsupported 的引擎调用前拒绝(engine_capability_unsupported)。
1313
1474
  */
1314
- type InteractAction = {
1475
+ type InteractAction =
1476
+ /**
1477
+ * interrupt:true = steer(抢占)/ false|缺省 = followUp(排队)——pi streamingBehavior
1478
+ * 语义的中立承载(D1 §3.3.5「后续 wave 如需抢占语义再扩展 InteractAction」的兑现,
1479
+ * chat 域投递经 engine.interact 接通时落地;不支持抢占的引擎忽略)。
1480
+ */
1481
+ {
1315
1482
  kind: "message";
1316
1483
  payload: string;
1484
+ interrupt?: boolean;
1317
1485
  } | {
1318
1486
  kind: "close";
1319
1487
  payload?: {
@@ -1335,4 +1503,4 @@ type InteractResult = {
1335
1503
  message: string;
1336
1504
  };
1337
1505
 
1338
- export { type AgentTaskSpec as A, type BgResponse as B, type ClosedReason as C, type DoneReason as D, type EngineCapabilities as E, type ForkFromResponse as F, type SubagentListItem as G, DirtyWorktreeError as H, type InteractAction as I, ForkDepthExceededError as J, type PersonaSpec as K, type ListResponse as L, type ModelInfo as M, type ReplayedTurn as N, ResurrectDeniedError as O, type ProbeReport as P, type RunStatus as R, type SessionView as S, type TracePatch as T, type WorkerLogEntry as W, type AgentEvent as a, type EngineHandleData as b, type EngineHandle as c, type AgentOutcome as d, type InteractResult as e, type AgentUsage as f, type AgentCallOpts as g, type AgentResult as h, type ExecutionTraceNode as i, type SubagentsGlobalConfig as j, type ModelRegistryLike as k, type AgentConfig as l, type ResolvedModel as m, type ExecutionRecord as n, type RecordSnapshot as o, type SubagentRecord as p, type ExecuteOptions as q, type ExecutionHandle as r, type ExecutionStatus as s, type ExecutionMode as t, type AgentEventLogEntry as u, type DisplayItem as v, type CancelResponse as w, type CloseResponse as x, type MessageResponse as y, type ExternalState as z };
1506
+ 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 };