@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
package/src/index.ts CHANGED
@@ -1,26 +1,40 @@
1
1
  /**
2
- * @zhushanwen/subagent-core — 公共 API barrel(D5 定稿)
2
+ * @zhushanwen/subagent-core — 公共 API barrel(D5 定稿 + post-convergence B-2 扩面)
3
3
  *
4
4
  * 公共 API 面 = 本文件导出 + package.json exports 的语义子入口
5
5
  * (./engines/zcode/reader、./engines/zcode/constants、./engine/paths、./relay-env)
6
6
  * + ./workflows/* 资产子入口。exports 面即 semver 契约(D5):收窄不放宽——
7
7
  * 新增导出走 minor,本文件刻意不使用 `export *`,逐名列出以使 diff 可审。
8
- * 内部实现细节(registry / error-recovery / execution 编排件等)不经 barrel 导出,
9
- * 仓内壳侧深路径消费(`./*` -> src 通配)不受本文件约束。
8
+ * 内部实现细节(error-recovery / execute-agent-call / worker-script-builder
9
+ * engine 编排件)不经 barrel 导出;host-surface 扩面(zsw 回接 U0,2026-08-30)
10
+ * 后 port 的 Infra 实现与宿主组装件已列入公共面。
11
+ *
12
+ * 扩面判定标准(post-convergence D3):壳非测试代码实际消费 ≥1 处即进 barrel——
13
+ * 契约面 = 壳的实际消费面,core 内部移动/重命名文件不再是对壳的隐性 breaking。
14
+ * 未进 barrel 的内部实现细节仍不经此导出;`./*` -> src 开发态通配已随 u-2a/u-2b
15
+ * 从 package.json 删除,深路径归一由消费侧单元(u-2b/u-2c)收口,barrel 是公共
16
+ * 消费终点。
10
17
  *
11
18
  * 设计权威源:docs/design/subagent-core-package-extraction.md §3.3 D5;
19
+ * docs/design/subagent-post-convergence-architecture.md §3.2 B-2 / §3.6 D3/D8/D9;
20
+ * docs/design/subagent-core-sink-design.md(sink 下沉收口扩面,2026-08-31);
12
21
  * 宿主接入示例见包 README(§3.4 core_host_not_configured 恢复指引的落点)。
13
22
  */
14
23
 
15
- export const CORE_PACKAGE_VERSION = "0.2.0";
24
+ // 0.4.0 = 首个公开发布的收敛收口面(0.3.0 为 2026-08-30 裁决的跳号占位,永不单独
25
+ // 发布;+ minor changeset 收口面落本号);与 package.json version 的一致性由
26
+ // src/__tests__/smoke.test.ts 动态守护,改版本须两处同步。
27
+ export const CORE_PACKAGE_VERSION = "0.5.1";
16
28
 
17
29
  // ── 宿主端口接线面(core/)────────────────────────────────────
18
30
  // HostServices:dataRoot / log / discoveryRoots 端口 + configureCore 注入;
19
31
  // 未 configureCore 即消费 dataRoot 抛 core_host_not_configured(§3.4 错误规格,
20
32
  // 恢复指引指向 README 接入示例)。DEFAULT_DATA_ROOT 显式导出供宿主选用——
21
- // 消除「缺省静默漂目录」。
33
+ // 消除「缺省静默漂目录」。getHostServices:core 内统一取用点,宿主 injector
34
+ // 消费(resource-list-injector)。
22
35
  export {
23
36
  configureCore,
37
+ getHostServices,
24
38
  DEFAULT_DATA_ROOT,
25
39
  type DiscoveryRoot,
26
40
  type HostServices,
@@ -49,13 +63,11 @@ export type {
49
63
  export type {
50
64
  AgentEvent,
51
65
  AgentOutcome,
52
- AgentTaskSpec,
53
66
  EngineCapabilities,
54
67
  EngineHandle,
55
68
  EngineHandleData,
56
69
  InteractAction,
57
70
  InteractResult,
58
- PersonaSpec,
59
71
  ProbeReport,
60
72
  ReplayedTurn,
61
73
  SessionView,
@@ -77,11 +89,532 @@ export {
77
89
  type EngineRoutingSource,
78
90
  } from "./execution/engine/routing.ts";
79
91
 
92
+ // ── 引擎注册 / 发现与进程面(execution/engine)────────────────
93
+ // 组合根 index.ts 接线消费(registerXxx 引擎注册、syncEnginesFile engines 文件
94
+ // 同步、killAllSpawnedChildren session 派生进程兜底清理)。
95
+ export { syncEnginesFile } from "./execution/engine/engine-discovery.ts";
96
+ export { registerPiEngine } from "./execution/engine/engines/pi/registration.ts";
97
+ export { killAllSpawnedChildren } from "./execution/engine/engines/pi/session-runner.ts";
98
+ export { registerZcodeEngine } from "./execution/engine/engines/zcode/registration.ts";
99
+
100
+ // pi session-runner 内核件(merge 裁决:dev 侧旧深路径 execution/session-runner.ts
101
+ // 终态已不存在,符号随 u-2a 迁移至 engine/engines/pi/session-runner.ts):
102
+ // maxTurnsToWatchdogMs 为 maxTurns→watchdog 毫秒换算(U3/U4 / D7,floor 语义
103
+ // 文档化——两宿主预算一致性 S2 的函数级锚点);killRecordChildWithEscalation 为
104
+ // 单 record 子进程升级回收(session 派生进程清理的细粒度入口)。
105
+ export {
106
+ killRecordChildWithEscalation,
107
+ maxTurnsToWatchdogMs,
108
+ } from "./execution/engine/engines/pi/session-runner.ts";
109
+
110
+ // zcode 引擎注册面:registerZcodeEngine 把 'zcode' 引擎登记进 registry(组合根
111
+ // 职责,幂等,上方已导出);createZcodeEngine 为 DI 工厂(测试/宿主注入 deps)。
112
+ // ZcodeEngineDeps 经 registration.ts 的 re-export 导出(避免与 zcode-engine.ts 双源)。
113
+ export { createZcodeEngine } from "./execution/engine/engines/zcode/registration.ts";
114
+ export type { ZcodeEngineDeps } from "./execution/engine/engines/zcode/registration.ts";
115
+
116
+ // ZcodeTaskShapeError:zcode 任务形状错误类(instanceof 分流用)——
117
+ // execution-runtime-face.test.ts:29 消费,barrel 保留导出(engines 域 A1 裁决)。
118
+ export { ZcodeTaskShapeError } from "./execution/engine/engines/zcode/zcode-engine.ts";
119
+
120
+ // 引擎注册表原语 + 引擎感知提示面:engine-awareness injector 消费。
121
+ export {
122
+ DEFAULT_ENGINE_ID,
123
+ normalizeEngineId,
124
+ } from "./execution/engine/registry.ts";
125
+ export {
126
+ buildEngineModelsPromptAppend,
127
+ buildSubagentEngineSection,
128
+ } from "./execution/engine/model-prompt.ts";
129
+
130
+ // session-view 归一符号(post-convergence D3):runtime 读取侧 2 处深路径
131
+ // (subagent-extractor / subagent-engine-history)归一 barrel 的前置——不新增
132
+ // 子入口(D9:每条子入口 bundle 多一份 host-services 副本)。
133
+ export { parseEngineHandle } from "./execution/engine/common/session-view-types.ts";
134
+ export { readSubagentHistoryMessages } from "./execution/engine/common/session-view-service.ts";
135
+
136
+ // ── 执行域(execution/)──────────────────────────────────────
137
+ // types.ts 领域类型族:record / 响应 / 列表项等 subagent 域公共契约(壳消费最高频面,
138
+ // tool 面 / interface 渲染层 / bg-notify 共同消费)。CLOSED_REASONS / DEFAULT_AGENT_NAME
139
+ // 为值常量,ResurrectDeniedError 为错误类(值 + 类型双形态)。
140
+ export {
141
+ CLOSED_REASONS,
142
+ DEFAULT_AGENT_NAME,
143
+ ResurrectDeniedError,
144
+ } from "./execution/types.ts";
145
+ export type {
146
+ AgentEventLogEntry,
147
+ BgResponse,
148
+ CancelResponse,
149
+ CloseResponse,
150
+ ClosedReason,
151
+ DisplayItem,
152
+ ExecutionMode,
153
+ ExecutionOutcome,
154
+ ExecutionRecord,
155
+ ExecutionStatus,
156
+ ExternalState,
157
+ ForkFromResponse,
158
+ ListResponse,
159
+ MessageResponse,
160
+ SubagentListItem,
161
+ SubagentRecord,
162
+ SubagentToolResult,
163
+ } from "./execution/types.ts";
164
+
165
+ // execution-record 投影函数族:record → 渲染态投影(outcome / elapsed / tool calls /
166
+ // live progress),interface 渲染层唯一消费入口。
167
+ export {
168
+ computeElapsedSeconds,
169
+ countAllToolCalls,
170
+ deriveOutcome,
171
+ getAllToolCalls,
172
+ projectLiveProgress,
173
+ projectOutcome,
174
+ } from "./execution/execution-record.ts";
175
+
176
+ // SubagentService 聚合面 + 进程单例访问器(post-convergence D8):访问器经
177
+ // globalThis[Symbol.for] slot 防 jiti 多实例分裂,/resume /fork 复用既有实例
178
+ // (SR-3/SR-4 语义)。createSubagentService / SubagentServiceInit 为构造依赖参数
179
+ // 注入形态(modelService 等,无全局查找,@experimental U10 / D6)。
180
+ export {
181
+ SubagentService,
182
+ getSubagentService,
183
+ setSubagentService,
184
+ createSubagentService,
185
+ type SubagentServiceInit,
186
+ } from "./execution/subagent-service.ts";
187
+ // notifyGateAllowsDelivery:closedReason → 投递许可判定(通知门)——
188
+ // 投递内核与壳侧 notify 链的共同语义锚点(execution 生产域消费,A2a)。
189
+ export { notifyGateAllowsDelivery } from "./execution/subagent-service.ts";
190
+
191
+ // ModelConfigService 聚合面 + 单例访问器四件中的 model 侧两件(D8);
192
+ // ModelConfigServiceInit 为 SubagentServiceInit.modelService 的构造依赖
193
+ // (MF-4:jsdoc 示例 `new ModelConfigService({cwd, agentDir})` 可构造)。
194
+ export {
195
+ ModelConfigService,
196
+ getModelConfigService,
197
+ setModelConfigService,
198
+ type ModelConfigServiceInit,
199
+ } from "./execution/model-config-service.ts";
200
+
201
+ // notify ledger:宿主通知账本端口(bind / getBound)——组合根装配 + workflow 域消费。
202
+ export {
203
+ bindNotifyLedgerHost,
204
+ getBoundNotifyLedger,
205
+ type NotifyLedgerHost,
206
+ } from "./execution/notify-ledger.ts";
207
+
208
+ // identity 重建常量与类型:session_start identity custom entry 的写入侧契约。
209
+ export {
210
+ IDENTITY_CUSTOM_TYPE,
211
+ type SubagentIdentityData,
212
+ } from "./execution/session-reconstructor.ts";
213
+
214
+ // 执行域外围件(组合根 / interface 层直接消费的独立单点件)。
215
+ export { bestEffort } from "./execution/best-effort.ts";
216
+ // channel-registry 类型闭包(UiChannelRegistry / ChannelHandler)随值符号进 barrel
217
+ // (u-2b 主 agent 裁决 2026-09-03):壳 index.ts 跨扩展 re-export surface 的非测试
218
+ // 生产消费,满足 D3 判定标准;type-only,零运行时面变化。
219
+ export {
220
+ getOrCreateChannelRegistry,
221
+ type UiChannelRegistry,
222
+ type ChannelHandler,
223
+ } from "./execution/channel-registry-access.ts";
224
+ export { DialogGlobalQueue } from "./execution/dialog-queue.ts";
225
+ export {
226
+ readGlobalConfig,
227
+ type GlobalConfigReadResult,
228
+ } from "./execution/config.ts";
229
+ export { isResumable } from "./execution/lifecycle-predicates.ts";
230
+ export { maybeCleanupExpiredSessionFiles } from "./execution/session-file-gc.ts";
231
+ export { createUiRequestHandlerForMode } from "./execution/ui-request-handler-factory.ts";
232
+ export { WorktreeManager } from "./execution/worktree-manager.ts";
233
+ export { SubprocessAgentRunner } from "./execution/subprocess-agent-runner.ts";
234
+
235
+ // record 存储面:RecordStore 类 + 索引文件名常量(bench 扫描基准消费);
236
+ // ChangeListener / RecordStorePi / StatusFilter 为状态查询面的类型闭包
237
+ //(@experimental U10 / D6:lookupRecordAnyState 全态查询等签名直接引用)。
238
+ export {
239
+ RecordStore,
240
+ type ChangeListener,
241
+ type RecordStorePi,
242
+ type StatusFilter,
243
+ } from "./execution/record-store.ts";
244
+ export { INDEX_FILENAME } from "./execution/sessions-index.ts";
245
+
246
+ // record 落盘 entry 契约:custom entry 写入侧(@experimental U10 / D6)。
247
+ export {
248
+ SUBAGENT_RECORD_CUSTOM_TYPE,
249
+ toSubagentRecordEntry,
250
+ type SubagentRecordEntryData,
251
+ } from "./execution/record-entry.ts";
252
+
253
+ // agent-registry 执行消费面:loadByPath 直接加载(@experimental U10 / D6)+
254
+ // parseAgentProfile 宽容解析(无 frontmatter 不拒、name 缺省 stem、返回 body 与
255
+ // 执行字段全量)——执行消费面单点;与严格注入投影(parseResourceMeta)双轨分离
256
+ // 的执行侧统一入口(U2 / D3)。
257
+ export { AgentRegistry } from "./execution/agent-registry.ts";
258
+ export {
259
+ parseAgentProfile,
260
+ type AgentProfile,
261
+ } from "./execution/agent-registry.ts";
262
+
263
+ // 错误类型族(error-recovery.ts 计划路径实测不存在,实测散布于下列源文件):
264
+ // resurrect/fork-depth/dirty-worktree 为动作层守卫抛出点(types.ts),
265
+ // GitRunError 见 worktree 内核组裁决,ZcodeTaskShapeError 见引擎注册面。
266
+ export {
267
+ DirtyWorktreeError,
268
+ ForkDepthExceededError,
269
+ } from "./execution/types.ts";
270
+
271
+ // 动作层领域内核(@experimental U10 / D6):六 handler 的校验/守卫链/归属判定/
272
+ // 终态映射,产出领域对象,宿主 adapter 负责包装渲染。
273
+ export {
274
+ BG_MESSAGE,
275
+ cancelHandler,
276
+ closeHandler,
277
+ DEFAULT_LIST_LIMIT,
278
+ endedMessageGuard,
279
+ FORK_FROM_DEFAULT_PROMPT,
280
+ forkFromHandler,
281
+ listHandler,
282
+ mapExternalState,
283
+ MAX_LIST_LIMIT,
284
+ messageHandler,
285
+ NOTIFY_CONTRACT,
286
+ recordToListItem,
287
+ startHandler,
288
+ wrapForkFromPrompt,
289
+ type CancelHandlerInput,
290
+ type CancelHandlerResult,
291
+ type CloseHandlerInput,
292
+ type CloseHandlerResult,
293
+ type ForkFromHandlerInput,
294
+ type ForkFromHandlerResult,
295
+ type ListHandlerInput,
296
+ type ListHandlerResult,
297
+ type MessageHandlerInput,
298
+ type MessageHandlerResult,
299
+ type StartHandlerInput,
300
+ type StartHandlerResult,
301
+ } from "./execution/subagent-actions-core.ts";
302
+
303
+ // 进程活性探针(watchdog/孤儿判定共用,agent-ref 契约原语组 U1)。
304
+ export { isProcessAlive } from "./execution/alive-store.ts";
305
+
306
+ // 并发池工厂(U3/U4 / D7):queuePolicy 缺省 priority 保 pi 行为,zsw 消费
307
+ // strict-fifo——策略差异显式化而非双实现。
308
+ export {
309
+ createConcurrencyPool,
310
+ type ConcurrencyPool,
311
+ type CreateConcurrencyPoolOptions,
312
+ type QueuePolicy,
313
+ } from "./execution/concurrency-pool.ts";
314
+
315
+ // 模型引用切分原语(U1 契约面批件):provider/model 引用切分与缺省值(两宿主
316
+ // maxTurns/model 换算同源);实现体内聚 zcode preparer/constants 不挪文件,
317
+ // barrel re-export(§5.3)。
318
+ export {
319
+ DEFAULT_PROVIDER_ID,
320
+ hasApiKey,
321
+ splitZcodeModelRef,
322
+ } from "./execution/engine/engines/zcode/preparer.ts";
323
+ export { ZCODE_FALLBACK_DEFAULT_MODEL } from "./execution/engine/engines/zcode/constants.ts";
324
+
325
+ // ── worktree git 内核(U5 / D5)───────────────────────────────
326
+ // git 语义纯函数单源:保真读(gitRun)、SafeId 校验、dirty 谓词、
327
+ // collectWorktreePatch(统一 add+diff 基线机制,返回结构即 patchIncomplete
328
+ // 留痕载体)、三步容错清理、listWorktreePorcelain(原始输出供宿主 realpath
329
+ // 对账)。锚点缺失/损坏与 add 失败两条降级路径 warn + 留痕(⛔3)。
330
+ //
331
+ // GitRunError 同名双类裁决(u-core-exec-export 交接):worktree-manager.ts 与
332
+ // worktree-git-ops.ts 各有一个 GitRunError(文案同但类独立)——barrel 只导出
333
+ // 本组 worktree-git-ops 版(git 语义新单源);worktree-manager 版不进 barrel,
334
+ // 将来 manager 收缩到 git-ops 内核时随之消除。
335
+ export {
336
+ assertSafeId,
337
+ cleanupWorktree,
338
+ collectWorktreePatch,
339
+ GitRunError,
340
+ gitRun,
341
+ isSafeId,
342
+ isTreeDirty,
343
+ listWorktreePorcelain,
344
+ SAFE_ID_RE,
345
+ type CleanupWorktreeOptions,
346
+ type CollectWorktreePatchOptions,
347
+ type ListWorktreePorcelainOptions,
348
+ type PatchBaselineAnchor,
349
+ type WorktreePatchResult,
350
+ } from "./execution/worktree-git-ops.ts";
351
+
352
+ // 组装层(U2 装配):discoverAgents 发现→宽容解析→去重→码点序(workflow 侧
353
+ // discoverWorkflows 对称面,第三宿主「列 agents」入口)。
354
+ export { discoverAgents } from "./execution/agents-assembly.ts";
355
+
80
356
  // ── workflow 编排入口(orchestration)────────────────────────
81
357
  // runWorkflow / abortRun:run 生命周期 free functions(D-12)——orchestration 的
82
358
  // 最小宿主入口。更细粒度编排(terminateRunningRuns / evictDoneRunsBeyondCap /
83
- // scheduleTimeBudget)与 launcher 层(runAndWait 等)暂不进 barrel
84
- // 无宿主触点证据前不放宽(端口演进纪律②);壳侧现经深路径消费,不受影响。
359
+ // scheduleTimeBudget / 上限常量)为组合根实际消费面,随 B-2 扩面进 barrel
360
+ // (D3 判定标准首次执行)。host-surface 扩面(zsw 回接 U0)同出 barrel:宿主壳
361
+ // 组装 LifecycleDeps 需要亲手构造三个 port 实现与消费细粒度编排函数,深路径消费
362
+ // 在 npm 形态不可达(发布面无 `./*` 通配)——宿主触点证据即 zsw 回接设计 D2。
85
363
  export { abortRun, runWorkflow } from "./orchestration/lifecycle.ts";
364
+ export {
365
+ terminateRunningRuns,
366
+ evictDoneRunsBeyondCap,
367
+ scheduleTimeBudget,
368
+ MAX_RETAINED_DONE_RUNS,
369
+ } from "./orchestration/lifecycle.ts";
370
+
371
+ // recoverCrashedRuns:崩溃恢复四步装配(宿主事件经 hooks 外置,U7 生命周期 / D8)。
372
+ export {
373
+ recoverCrashedRuns,
374
+ type RecoverCrashedRunsHooks,
375
+ type RecoverCrashedRunsResult,
376
+ } from "./orchestration/lifecycle.ts";
377
+
378
+ // launcher 层:runAndWait / executeNestedWorkflow(workflow 域嵌套编排入口)
379
+ // + deps / 结果类型。
380
+ export {
381
+ runAndWait,
382
+ executeNestedWorkflow,
383
+ type LauncherDeps,
384
+ type WorkflowRunResult,
385
+ } from "./orchestration/launcher.ts";
386
+
387
+ // worker-message-pump 内核件(execution 生产域消费,A2a):finalizeRun run 终态
388
+ // 收口 + FinalizeRunOptions 契约、closeOutInFlightCalls 在飞 call 批量清算、
389
+ // makeSerializeFailedResult 序列化失败结果构造、postBudgetUpdate 预算播报、
390
+ // resetRebuildFailureInjectionForTest 重建失败注入复位(测试面)。
391
+ export {
392
+ finalizeRun,
393
+ closeOutInFlightCalls,
394
+ makeSerializeFailedResult,
395
+ postBudgetUpdate,
396
+ resetRebuildFailureInjectionForTest,
397
+ type FinalizeRunOptions,
398
+ } from "./orchestration/worker-message-pump.ts";
399
+
400
+ // workflow 领域模型族:run / call / trace / budget / 状态与规格(壳 store 与
401
+ // interface 渲染层共同消费)。
86
402
  export type { RunSpec } from "./orchestration/models/run-spec.ts";
87
403
  export type { LifecycleDeps } from "./orchestration/models/ports.ts";
404
+ export type { RunStore } from "./orchestration/models/ports.ts";
405
+ // RunStore / AgentRunner / WorkerHost port 契约类型:宿主自写 Infra 实现(如 zsw
406
+ // 的 RunnerPort 桥接)需要契约面;WorkerHandlers 已随 WorkerHost 注释。
407
+ export type {
408
+ AgentRunner,
409
+ WorkerHandlers,
410
+ WorkerHost,
411
+ } from "./orchestration/models/ports.ts";
412
+ export type { RunState } from "./orchestration/models/run-state.ts";
413
+ export { Trace } from "./orchestration/models/trace.ts";
414
+ export { AgentCall } from "./orchestration/models/agent-call.ts";
415
+ export { Budget } from "./orchestration/models/budget.ts";
416
+ export { WorkflowRun, type WorkflowRunMeta } from "./orchestration/models/workflow-run.ts";
417
+ export type {
418
+ AgentCallOpts,
419
+ AgentResult,
420
+ DoneReason,
421
+ ExecutionTraceNode,
422
+ RunStatus,
423
+ ToolCallEntry,
424
+ WorkerLogEntry,
425
+ } from "./orchestration/models/types.ts";
426
+ // SLUG_MAX_LENGTH 单源(merge 收敛完成):唯一定义在 orchestration/models/types.ts;
427
+ // 原 execution/execute-options-mapper.ts 重复定义已删(改 import 消费,深路径消费者
428
+ // subagent-actions-core 同步切到 models/types 单源)。
429
+ export { SLUG_MAX_LENGTH } from "./orchestration/models/types.ts";
430
+
431
+ // workflow 脚本资产面:registry 契约 + 实现 / 脚本 lint / 文件落盘(save / delete)
432
+ // + skill 路径缓存清理——组合根装配与 workflow 工具面消费。
433
+ export type { WorkflowScriptRegistry } from "./orchestration/models/workflow-script-registry.ts";
434
+ export { WorkflowScriptRegistryImpl } from "./orchestration/workflow-script-registry-impl.ts";
435
+ // WorkflowScript 实体与按路径加载工厂(第三宿主零复刻脚本加载,G3/S5)。
436
+ export {
437
+ loadWorkflowScriptByPath,
438
+ WorkflowScript,
439
+ } from "./orchestration/workflow-script-registry-impl.ts";
440
+ // lintScript:workflow 脚本静态检查(执行前 fail-fast,宿主 list/validate 面消费)。
441
+ export { lintScript } from "./orchestration/script-lint.ts";
442
+ export type { LintFinding, LintResult } from "./orchestration/script-lint.ts";
443
+ export { saveWorkflow, deleteWorkflow } from "./orchestration/workflow-files.ts";
444
+ export { clearSkillPathCache } from "./orchestration/skill-discovery.ts";
445
+ export { WorkerHostImpl } from "./orchestration/worker-host.ts";
446
+
447
+ // ── workflow 创作闭环面(orchestration/script-generate + workflow-files,W4)──
448
+ // generateWorkflowScript:generate 校验管线(五道闸 + @pi-meta round-trip + tmp
449
+ // 写盘)从 pi-sw 插件层下沉(D-6)——纯函数返回结构化结果(不 throw,pi 的
450
+ // isError 契约转换由宿主负责),报错文案逐字对齐 pi 现版(CA2 前提)。
451
+ // saveWorkflow/deleteWorkflow(上方已导出)+ 目录经 WorkflowDirOptions 注入
452
+ // (缺省 pi 布局 DEFAULT_WORKFLOW_TMP_DIR / DEFAULT_WORKFLOW_SAVED_DIR,向后兼容
453
+ // ——pi 现深路径调用形态行为不变,改接在 C5)。
454
+ export { generateWorkflowScript } from "./orchestration/script-generate.ts";
455
+ export type {
456
+ GenerateWorkflowScriptOptions,
457
+ GenerateWorkflowScriptResult,
458
+ } from "./orchestration/script-generate.ts";
459
+ export type { WorkflowDirOptions } from "./orchestration/workflow-files.ts";
460
+ // 缺省目录常量随面导出:宿主显式注入 pi 缺省布局时引用常量,避免字面硬编码回流。
461
+ export {
462
+ DEFAULT_WORKFLOW_SAVED_DIR,
463
+ DEFAULT_WORKFLOW_TMP_DIR,
464
+ } from "./orchestration/workflow-files.ts";
465
+
466
+ // workflow 发现/加载(ADR-031 统一资源发现):宿主 list 面与 registry 构造消费;
467
+ // invalidateCache 供宿主在写脚本后主动失效 mtime 缓存。
468
+ export {
469
+ discoverWorkflows,
470
+ getWorkflow,
471
+ getWorkflowByPath,
472
+ invalidateCache,
473
+ loadWorkflows,
474
+ } from "./orchestration/config-loader.ts";
475
+ export type {
476
+ CachedWorkflowMeta,
477
+ WorkflowMeta,
478
+ WorkflowScanConfig,
479
+ WorkflowSource,
480
+ } from "./orchestration/config-loader.ts";
481
+
482
+ // FileRunStore:RunStore port 的宿主无关文件实现(D2 设计件)——落盘
483
+ // <dataRoot>/workflow-state/<runId>.jsonl,zsw 等无 pi session 设施的宿主装配
484
+ // LifecycleDeps.store 用;pi 壳继续用 session 锚定的 JsonlRunStore。
485
+ // DEFAULT_* 两常量:壳 jsonl-run-store.ts 生产消费(D3 判定进 barrel),
486
+ // u-2c 删 ./* 通配后深路径仅测试侧 vitest alias 可解析,生产消费必须走 barrel。
487
+ export {
488
+ DEFAULT_SAVE_MIN_INTERVAL_MS,
489
+ DEFAULT_STATE_MAX_RUNS,
490
+ FileRunStore,
491
+ } from "./orchestration/file-run-store.ts";
492
+
493
+ // ── 快照 codec(U8 / D4)──────────────────────────────────────
494
+ // WorkflowRun ↔ 落盘快照的单一投影:版本常量沿用 pi "wf-run-v2"(存量逐字节
495
+ // 可读)、live 字段 strip、更高版本跳过(宿主侧 warn 可见性自决)。
496
+ export {
497
+ fromRunSnapshot,
498
+ SNAPSHOT_VERSION,
499
+ toRunSnapshot,
500
+ type RunSnapshot,
501
+ } from "./orchestration/run-snapshot.ts";
502
+
503
+ // run 投影(U7 / D8):isScriptRunning / runSummary 以 core WorkflowRun 为准的
504
+ // 投影(runSummary 双投影分叉收口)。
505
+ export {
506
+ isScriptRunning,
507
+ runSummary,
508
+ type WorkflowRunSummary,
509
+ } from "./orchestration/workflow-run-summary.ts";
510
+
511
+ // ── schema 助手(U9 / D9)─────────────────────────────────────
512
+ // workflow 资产 @pi-meta parameters 的 schema→已知键集、平铺参数检测与
513
+ // 归一化(pi tool-workflow 消费面下沉;宿主白名单退役入口)。
514
+ export {
515
+ argKeysFromMeta,
516
+ findFlattenedArgKeys,
517
+ normalizeArgsByMeta,
518
+ type ArgKeySet,
519
+ type ArgMetaOptions,
520
+ type ArgMetaWarning,
521
+ type NormalizedArgs,
522
+ } from "./orchestration/args-meta.ts";
523
+
524
+ // ── 共享原语(shared/)───────────────────────────────────────
525
+ // agent 展示名归一(渲染层 7 处消费的 SSOT)+ meta 解析 / XML 注入 / 资源发现 /
526
+ // thinking 档位序(THINKING_ORDER 定义源 shared/model-ref,model-resolver 为转发)。
527
+ export { displayAgentName } from "./shared/agent-ref.ts";
528
+ export {
529
+ parseResourceMeta,
530
+ parseResourceMetaDetailed,
531
+ } from "./shared/meta-parser.ts";
532
+ export { THINKING_ORDER } from "./shared/model-ref.ts";
533
+ // 定时器上限(壳 tool-workflow.ts OR-1 消费,D3 判定进 barrel)
534
+ export { MAX_TIMER_DELAY_MS } from "./shared/timer-delay.ts";
535
+ // 资源发现面(W2③):discoverResources——agent .md / workflow .js 的多源统一发现
536
+ // (ADR-031)——多源扫描 + stem last-writer-wins 合并 + realpath 去重。宿主(zsw
537
+ // 回接)经 ScanConfig.hostRoots 注入发现根(source 标签即 ResourceSource 槽位键,
538
+ // 含 project-host 项目级槽);深路径消费在 npm/vendored 发布形态不可达(exports 无
539
+ // 深路径通配),故出 barrel。发现链辅助(C5b):findWorkspaceRoot(project 源根
540
+ // 定位)、getCachedParsed/getCachedFileContent(mtime 缓存读取)——发现链消费方
541
+ // (pi-sw injector 等宿主接线)逐条解析 DiscoveredResource 的 frontmatter/meta
542
+ // 需要它们,深路径同样不可达。
543
+ export {
544
+ discoverResources,
545
+ findWorkspaceRoot,
546
+ getCachedFileContent,
547
+ getCachedParsed,
548
+ } from "./shared/resource-discovery.ts";
549
+ export type {
550
+ DiscoveredResource,
551
+ ResourceKind,
552
+ ResourceSource,
553
+ ScanConfig,
554
+ } from "./shared/resource-discovery.ts";
555
+ export { escapeXml, renderXmlSection } from "./shared/xml-injection.ts";
556
+
557
+ // ── agent-ref 面(契约原语,U1)────────────────────────────────
558
+ // agent 引用规范化(normalizeRef 含 `..` 段拒绝——G4 声明的唯一行为收紧,
559
+ // ⛔2 样本集验证)+ 引用扩展名常量 + 报错文案工厂。
560
+ export {
561
+ AGENT_REF_EXT,
562
+ invalidAgentRefMessage,
563
+ normalizeRef,
564
+ type InvalidAgentRefMessageOptions,
565
+ WORKFLOW_REF_EXT,
566
+ } from "./shared/agent-ref.ts";
567
+
568
+ // ── workflow 契约面(U1)──────────────────────────────────────
569
+ // workflow 引用规范化(名/路径二分 + 保留字裁决,knownNames 宿主注入——内置
570
+ // workflow 名不 core 硬编码)。
571
+ export {
572
+ normalizeWorkflowRef,
573
+ WORKFLOW_REF_RESERVED_NAMES,
574
+ type NormalizeWorkflowRefOptions,
575
+ type NormalizedWorkflowRef,
576
+ type WorkflowRefInvalidReason,
577
+ } from "./shared/agent-ref.ts";
578
+
579
+ // ── 注入渲染面(shared/injection-render,W3)───────────────────
580
+ // 三段 XML(<available_subagents>/<available_workflows>/<available_provider_models>)
581
+ // 的 format 纯函数 + Entry 接口从 pi-sw 插件层下沉(D-3):ModelEntry 并集口径
582
+ // (除 id/name 外全字段 optional,红线 5 守卫不抛不渲垃圾)、分段条目预算
583
+ // (码点序排 + 截尾 + 宿主注入兜底指引;models 段无预算永不截,红线 7)、
584
+ // guide 文案宿主注入(core 不内嵌平台文案)。summarizeDescription 随
585
+ // WorkflowEntry 链导出(zsw 侧同口径消费)。
586
+ export {
587
+ formatAgentList,
588
+ formatModelList,
589
+ formatWorkflowList,
590
+ sortByCodepoint,
591
+ summarizeDescription,
592
+ } from "./shared/injection-render.ts";
593
+ export type {
594
+ AgentEntry,
595
+ ListFormatOptions,
596
+ ModelEntry,
597
+ ModelListFormatOptions,
598
+ ModelReasoningInfo,
599
+ WorkflowEntry,
600
+ } from "./shared/injection-render.ts";
601
+
602
+ // ── 原语(U6a)────────────────────────────────────────────────
603
+ // atomic-write:tmp+rename 原子写单一实现(统一 tmp 命名 `.tmp.<pid>.<seq>-<rand>`、
604
+ // 失败清理、崩溃残留扫描/清理入口)——core 内部全部写点已收敛于此(U6b);
605
+ // sync/async 两档耐久语义见模块头。bounded-serialize:预算内 JSON 序列化
606
+ // (自 pi-sw helpers 平移,输出逐字节一致)。
607
+ export {
608
+ atomicTmpPathFor,
609
+ cleanupStaleTmpFiles,
610
+ listStaleTmpFiles,
611
+ parseAtomicTmpPath,
612
+ writeAtomicFile,
613
+ writeAtomicFileSync,
614
+ type AtomicTmpRef,
615
+ type AtomicWriteFileOptions,
616
+ type AtomicWriteOptions,
617
+ type CleanupStaleTmpOptions,
618
+ type CleanupStaleTmpResult,
619
+ } from "./shared/atomic-write.ts";
620
+ export { boundedPrettySerialize } from "./shared/bounded-serialize.ts";