@zhushanwen/subagent-core 0.5.1 → 0.7.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 (318) hide show
  1. package/README.md +1 -1
  2. package/dist/chunk-KXVBIVOU.js +16 -0
  3. package/dist/chunk-T2SYBW3I.js +24 -0
  4. package/dist/chunk-VURUAGMM.js +2305 -0
  5. package/dist/{types-Dv4QhSJ_.d.cts → engine-discovery-scan-ocpM8FmI.d.cts} +835 -668
  6. package/dist/{types-Dv4QhSJ_.d.ts → engine-discovery-scan-ocpM8FmI.d.ts} +835 -668
  7. package/dist/execution/engine/engine-discovery-scan.cjs +2210 -0
  8. package/dist/execution/engine/engine-discovery-scan.d.cts +4 -0
  9. package/dist/execution/engine/engine-discovery-scan.d.ts +4 -0
  10. package/dist/execution/engine/engine-discovery-scan.js +20 -0
  11. package/dist/execution/engine/paths.cjs +6 -23
  12. package/dist/execution/engine/paths.d.cts +1 -8
  13. package/dist/execution/engine/paths.d.ts +1 -8
  14. package/dist/execution/engine/paths.js +1 -1
  15. package/dist/execution/relay-env.cjs +12 -28
  16. package/dist/execution/relay-env.d.cts +1 -33
  17. package/dist/execution/relay-env.d.ts +1 -33
  18. package/dist/execution/relay-env.js +5 -3
  19. package/dist/index.cjs +14123 -15467
  20. package/dist/index.d.cts +1179 -1540
  21. package/dist/index.d.ts +1179 -1540
  22. package/dist/index.js +7694 -10986
  23. package/dist.bundle/index.cjs +33485 -0
  24. package/package.json +20 -26
  25. package/src/__tests__/record-store-last-line.test.ts +16 -7
  26. package/src/core/error-message.ts +7 -6
  27. package/src/core/host-services.ts +8 -2
  28. package/src/core/notify-ports.ts +17 -2
  29. package/src/execution/__tests__/agent-registry.test.ts +1 -1
  30. package/src/execution/__tests__/alive-store.test.ts +1 -1
  31. package/src/execution/__tests__/chat-engine-routing.test.ts +62 -28
  32. package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +255 -0
  33. package/src/execution/__tests__/collect-budget.test.ts +291 -0
  34. package/src/execution/__tests__/collect-coordinator-service.test.ts +316 -0
  35. package/src/execution/__tests__/collect-coordinator.test.ts +371 -0
  36. package/src/execution/__tests__/collect-mixed-dispatch.test.ts +229 -0
  37. package/src/execution/__tests__/config-collect-sync.test.ts +120 -0
  38. package/src/execution/__tests__/config.test.ts +1 -1
  39. package/src/execution/__tests__/delivery-methods.test.ts +179 -237
  40. package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -2
  41. package/src/execution/__tests__/execute-nesting.test.ts +20 -13
  42. package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +21 -34
  43. package/src/execution/__tests__/finalized-marker.test.ts +1 -1
  44. package/src/execution/__tests__/gc-timer.test.ts +8 -23
  45. package/src/execution/__tests__/get-record-for-action-restart.test.ts +20 -10
  46. package/src/execution/__tests__/helpers/fake-engine-port.ts +187 -0
  47. package/src/execution/__tests__/helpers/spawn-mock.ts +36 -9
  48. package/src/execution/__tests__/helpers/subagent-service-mocks.ts +1 -1
  49. package/src/execution/__tests__/idle-gc.test.ts +200 -0
  50. package/src/execution/__tests__/lifecycle-predicates.test.ts +26 -21
  51. package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +1 -1
  52. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +5 -2
  53. package/src/execution/__tests__/notify-batch.test.ts +500 -0
  54. package/src/execution/__tests__/notify-ledger.test.ts +27 -0
  55. package/src/execution/__tests__/reconcile-sweep.test.ts +200 -0
  56. package/src/execution/__tests__/record-entry-collect.test.ts +102 -0
  57. package/src/execution/__tests__/record-store.test.ts +60 -6
  58. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +20 -13
  59. package/src/execution/__tests__/relay-env.test.ts +12 -1
  60. package/src/execution/__tests__/round-supervisor.test.ts +293 -0
  61. package/src/execution/__tests__/session-file-gc.test.ts +1 -1
  62. package/src/execution/__tests__/session-pending.test.ts +119 -17
  63. package/src/execution/__tests__/start-collect-guard.test.ts +255 -0
  64. package/src/execution/__tests__/stream-sink-retirement.test.ts +10 -10
  65. package/src/execution/__tests__/subagent-actions-core.test.ts +6 -0
  66. package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +14 -11
  67. package/src/execution/__tests__/subagent-service-notify-gate.test.ts +33 -30
  68. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +2 -9
  69. package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +59 -129
  70. package/src/execution/__tests__/subagent-service.test.ts +2 -2
  71. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +109 -7
  72. package/src/execution/__tests__/subprocess-agent-runner.test.ts +108 -36
  73. package/src/execution/__tests__/sync-collect-recovery.test.ts +1102 -0
  74. package/src/execution/__tests__/tombstone-store.test.ts +1 -1
  75. package/src/execution/__tests__/workflow-state-root.test.ts +232 -0
  76. package/src/execution/__tests__/worktree-git-ops.test.ts +1 -1
  77. package/src/execution/__tests__/worktree-reconcile-aging.test.ts +2 -2
  78. package/src/execution/__tests__/worktree-reconcile.integration.test.ts +1 -1
  79. package/src/execution/__tests__/worktree-registry.test.ts +1 -1
  80. package/src/execution/agent-registry.ts +6 -2
  81. package/src/execution/collect-coordinator.ts +200 -0
  82. package/src/execution/config.ts +77 -5
  83. package/src/execution/dialog-queue.ts +6 -73
  84. package/src/execution/engine/__tests__/common/capability-gate.test.ts +115 -15
  85. package/src/execution/engine/__tests__/common/errors.test.ts +11 -18
  86. package/src/execution/engine/__tests__/common/event-journal.test.ts +1 -1
  87. package/src/execution/engine/__tests__/common/kill-chain.test.ts +7 -0
  88. package/src/execution/engine/__tests__/common/nesting-guard.test.ts +9 -3
  89. package/src/execution/engine/__tests__/common/pool-manager.test.ts +2 -2
  90. package/src/execution/engine/__tests__/common/session-view-service.test.ts +90 -3
  91. package/src/execution/engine/__tests__/conformance/H9-test-disposition.md +116 -0
  92. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +377 -0
  93. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/recorded.fixture.json +331 -0
  94. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +213 -0
  95. package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +230 -0
  96. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +69 -42
  97. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +4 -81
  98. package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +67 -44
  99. package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +82 -55
  100. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +133 -70
  101. package/src/execution/engine/__tests__/conformance/engine-crash.test.ts +143 -0
  102. package/src/execution/engine/__tests__/conformance/fake-engine-capabilities.ts +19 -0
  103. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +8 -3
  104. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +6 -5
  105. package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +398 -0
  106. package/src/execution/engine/__tests__/conformance/registry-fork-filter.test.ts +221 -0
  107. package/src/execution/engine/__tests__/conformance/round-liveness-supervisor.test.ts +302 -0
  108. package/src/execution/engine/__tests__/conformance/static-spawn-guard.test.ts +58 -0
  109. package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +558 -0
  110. package/src/execution/engine/__tests__/host-task-spec.test.ts +45 -0
  111. package/src/execution/engine/__tests__/model-ref-split.test.ts +74 -0
  112. package/src/execution/engine/__tests__/registry.test.ts +206 -1
  113. package/src/execution/engine/__tests__/routing.test.ts +97 -0
  114. package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +97 -0
  115. package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +294 -0
  116. package/src/execution/engine/client/__tests__/engine-client.test.ts +516 -0
  117. package/src/execution/engine/client/__tests__/mirror.test.ts +67 -0
  118. package/src/execution/engine/client/__tests__/pid-file.test.ts +257 -0
  119. package/src/execution/engine/client/__tests__/protocol-closure.test.ts +95 -0
  120. package/src/execution/engine/client/__tests__/remote-engine.test.ts +457 -0
  121. package/src/execution/engine/client/client-options.ts +103 -0
  122. package/src/execution/engine/client/engine-client.ts +687 -0
  123. package/src/execution/engine/client/mirror.ts +167 -0
  124. package/src/execution/engine/client/pid-file.ts +392 -0
  125. package/src/execution/engine/client/reaper.ts +95 -0
  126. package/src/execution/engine/client/remote-engine.ts +441 -0
  127. package/src/execution/engine/client/reverse-router.ts +255 -0
  128. package/src/execution/engine/common/capability-gate.ts +109 -22
  129. package/src/execution/engine/common/errors.ts +9 -25
  130. package/src/execution/engine/common/event-journal.ts +4 -50
  131. package/src/execution/engine/common/journal-replay.ts +3 -1
  132. package/src/execution/engine/common/kill-chain.ts +18 -251
  133. package/src/execution/engine/common/nesting-guard.ts +18 -114
  134. package/src/execution/engine/common/pool-manager.ts +4 -0
  135. package/src/execution/engine/common/session-view-service.ts +56 -84
  136. package/src/execution/engine/config.ts +151 -0
  137. package/src/execution/engine/d8-compat.ts +346 -0
  138. package/src/execution/engine/engine-discovery-roots.ts +107 -0
  139. package/src/execution/engine/engine-discovery-scan.ts +269 -0
  140. package/src/execution/engine/engine-discovery.ts +30 -7
  141. package/src/execution/engine/engine-inspect-package.ts +282 -0
  142. package/src/execution/engine/engine-manifest.ts +244 -0
  143. package/src/execution/engine/host/__tests__/host-askuser-endpoint.test.ts +123 -0
  144. package/src/execution/engine/host/__tests__/host-bridge.test.ts +135 -0
  145. package/src/execution/engine/host/__tests__/spawned-children.test.ts +73 -0
  146. package/src/execution/engine/host/host-bridge.ts +150 -0
  147. package/src/execution/engine/host/host-ui-endpoint.ts +47 -0
  148. package/src/execution/engine/host/pi-host-binding.ts +91 -0
  149. package/src/execution/engine/host/spawned-children.ts +139 -0
  150. package/src/execution/engine/host-task-spec.ts +29 -2
  151. package/src/execution/engine/model-validation.ts +55 -2
  152. package/src/execution/engine/paths.ts +16 -41
  153. package/src/execution/engine/port.ts +48 -2
  154. package/src/execution/engine/registry.ts +153 -34
  155. package/src/execution/engine/routing.ts +225 -52
  156. package/src/execution/engine/types.ts +25 -200
  157. package/src/execution/execution-record.ts +7 -0
  158. package/src/execution/finalize-record.ts +40 -11
  159. package/src/execution/idle-gc.ts +89 -14
  160. package/src/execution/lifecycle-manager.ts +10 -7
  161. package/src/execution/lifecycle-predicates.ts +10 -8
  162. package/src/execution/notifier.ts +234 -25
  163. package/src/execution/notify-host.ts +21 -1
  164. package/src/execution/record-entry.ts +16 -0
  165. package/src/execution/record-store.ts +189 -31
  166. package/src/execution/relay-env.ts +19 -36
  167. package/src/execution/round-supervisor/domain.ts +89 -0
  168. package/src/execution/round-supervisor/index.ts +33 -0
  169. package/src/execution/round-supervisor/notify-accounting.ts +87 -0
  170. package/src/execution/round-supervisor/reconcile-sweep.ts +235 -0
  171. package/src/execution/round-supervisor/service-binding.test.ts +661 -0
  172. package/src/execution/round-supervisor/service-binding.ts +273 -0
  173. package/src/execution/round-supervisor/supervisor.ts +426 -0
  174. package/src/execution/session-pending.ts +68 -74
  175. package/src/execution/settled-watchdog.ts +39 -0
  176. package/src/execution/subagent-actions-core.ts +62 -6
  177. package/src/execution/subagent-service.ts +1161 -406
  178. package/src/execution/subprocess-agent-runner.ts +16 -8
  179. package/src/execution/sync-rebuild.ts +87 -0
  180. package/src/execution/types.ts +104 -117
  181. package/src/execution/ui-channels.ts +13 -214
  182. package/src/execution/ui-request-handler-factory.ts +7 -4
  183. package/src/execution/ui-request-observability.ts +2 -2
  184. package/src/execution/workflow-state-root.ts +67 -0
  185. package/src/execution/worktree-git-ops.ts +5 -0
  186. package/src/execution/worktree-manager.ts +11 -1
  187. package/src/index.ts +55 -26
  188. package/src/orchestration/__tests__/config-loader.test.ts +1 -1
  189. package/src/orchestration/__tests__/execute-agent-call.test.ts +1 -1
  190. package/src/orchestration/__tests__/file-run-store-prune.test.ts +1 -1
  191. package/src/orchestration/__tests__/file-run-store-throttle.test.ts +1 -1
  192. package/src/orchestration/__tests__/review-fix-loop-scriptpath-failfast.test.ts +1 -1
  193. package/src/orchestration/__tests__/script-generate.test.ts +5 -5
  194. package/src/orchestration/__tests__/skill-discovery.test.ts +2 -2
  195. package/src/orchestration/__tests__/workflow-files.test.ts +10 -10
  196. package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +1 -1
  197. package/src/orchestration/execute-agent-call.ts +1 -1
  198. package/src/orchestration/file-run-store.ts +144 -59
  199. package/src/orchestration/models/types.ts +43 -42
  200. package/src/shared/__tests__/atomic-write.test.ts +1 -1
  201. package/src/shared/__tests__/resource-discovery-host-roots.test.ts +5 -5
  202. package/src/shared/zcode-model-ref.ts +31 -0
  203. package/dist/chunk-43ONBFZX.js +0 -240
  204. package/dist/chunk-A4IVZWVX.js +0 -31
  205. package/dist/chunk-APZY4IME.js +0 -27
  206. package/dist/chunk-V3VHZ2VX.js +0 -59
  207. package/dist/execution/engine/engines/zcode/constants.cjs +0 -107
  208. package/dist/execution/engine/engines/zcode/constants.d.cts +0 -135
  209. package/dist/execution/engine/engines/zcode/constants.d.ts +0 -135
  210. package/dist/execution/engine/engines/zcode/constants.js +0 -54
  211. package/dist/execution/engine/engines/zcode/reader.cjs +0 -276
  212. package/dist/execution/engine/engines/zcode/reader.d.cts +0 -21
  213. package/dist/execution/engine/engines/zcode/reader.d.ts +0 -21
  214. package/dist/execution/engine/engines/zcode/reader.js +0 -9
  215. package/src/__tests__/append-system-prompt-assembly.test.ts +0 -243
  216. package/src/__tests__/fr4-get-state-handshake.test.ts +0 -125
  217. package/src/__tests__/session-runner.test.ts +0 -69
  218. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
  219. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -191
  220. package/src/execution/__tests__/descendant-sweep-guards.test.ts +0 -220
  221. package/src/execution/__tests__/descendant-sweep.test.ts +0 -269
  222. package/src/execution/__tests__/engine-model-validation.test.ts +0 -741
  223. package/src/execution/__tests__/epipe-fallback.test.ts +0 -248
  224. package/src/execution/__tests__/execution-runtime-face.test.ts +0 -272
  225. package/src/execution/__tests__/get-state-handshake.test.ts +0 -127
  226. package/src/execution/__tests__/helpers/session-runner-mocks.ts +0 -113
  227. package/src/execution/__tests__/keep-alive-no-progress.test.ts +0 -280
  228. package/src/execution/__tests__/kill-all-escalation.test.ts +0 -196
  229. package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +0 -113
  230. package/src/execution/__tests__/output-collector.test.ts +0 -469
  231. package/src/execution/__tests__/pi-invocation.test.ts +0 -134
  232. package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -149
  233. package/src/execution/__tests__/rpc-mode.test.ts +0 -89
  234. package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +0 -387
  235. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -277
  236. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -254
  237. package/src/execution/__tests__/run-spawn-edges.test.ts +0 -1079
  238. package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
  239. package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
  240. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
  241. package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +0 -207
  242. package/src/execution/__tests__/service-kill-escalation.test.ts +0 -91
  243. package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +0 -110
  244. package/src/execution/__tests__/session-runner-close-prune.test.ts +0 -181
  245. package/src/execution/__tests__/session-runner-dispatch.test.ts +0 -489
  246. package/src/execution/__tests__/session-runner-epipe.test.ts +0 -179
  247. package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +0 -227
  248. package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +0 -290
  249. package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -352
  250. package/src/execution/__tests__/settled-watchdog.test.ts +0 -524
  251. package/src/execution/__tests__/spawn-args.test.ts +0 -446
  252. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -192
  253. package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
  254. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -208
  255. package/src/execution/__tests__/spawned-children.test.ts +0 -236
  256. package/src/execution/__tests__/start-sync-model-guard.test.ts +0 -150
  257. package/src/execution/__tests__/stdin-writer.test.ts +0 -464
  258. package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -693
  259. package/src/execution/__tests__/temp-prompt.test.ts +0 -53
  260. package/src/execution/__tests__/timeout-integration.test.ts +0 -616
  261. package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
  262. package/src/execution/__tests__/turn-limiter.test.ts +0 -65
  263. package/src/execution/__tests__/ui-request-handler.test.ts +0 -205
  264. package/src/execution/__tests__/ui-request-queue.test.ts +0 -298
  265. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -230
  266. package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
  267. package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +0 -149
  268. package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
  269. package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +0 -128
  270. package/src/execution/engine/__tests__/paths.test.ts +0 -39
  271. package/src/execution/engine/common/schema-emulation.ts +0 -189
  272. package/src/execution/engine/common/session-view-projection.ts +0 -51
  273. package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -615
  274. package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
  275. package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +0 -257
  276. package/src/execution/engine/engines/pi/argv-mirror.ts +0 -135
  277. package/src/execution/engine/engines/pi/get-state-handshake.ts +0 -179
  278. package/src/execution/engine/engines/pi/output-collector.ts +0 -317
  279. package/src/execution/engine/engines/pi/pi-engine.ts +0 -811
  280. package/src/execution/engine/engines/pi/pi-invocation.ts +0 -120
  281. package/src/execution/engine/engines/pi/reader.ts +0 -59
  282. package/src/execution/engine/engines/pi/registration.ts +0 -37
  283. package/src/execution/engine/engines/pi/session-runner.ts +0 -2840
  284. package/src/execution/engine/engines/pi/spawn-event-adapter.ts +0 -404
  285. package/src/execution/engine/engines/pi/stdin-writer.ts +0 -199
  286. package/src/execution/engine/engines/pi/temp-prompt.ts +0 -62
  287. package/src/execution/engine/engines/pi/turn-limiter.ts +0 -102
  288. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +0 -301
  289. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +0 -36
  290. package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +0 -321
  291. package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +0 -473
  292. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -43
  293. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -124
  294. package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
  295. package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -71
  296. package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +0 -247
  297. package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +0 -451
  298. package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +0 -792
  299. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +0 -782
  300. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +0 -168
  301. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +0 -210
  302. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +0 -353
  303. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +0 -282
  304. package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +0 -372
  305. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -145
  306. package/src/execution/engine/engines/zcode/appserver-launcher.ts +0 -167
  307. package/src/execution/engine/engines/zcode/connection.ts +0 -598
  308. package/src/execution/engine/engines/zcode/constants.ts +0 -176
  309. package/src/execution/engine/engines/zcode/golden-sample.ts +0 -47
  310. package/src/execution/engine/engines/zcode/parser.ts +0 -102
  311. package/src/execution/engine/engines/zcode/preparer.ts +0 -235
  312. package/src/execution/engine/engines/zcode/reader.ts +0 -381
  313. package/src/execution/engine/engines/zcode/registration.ts +0 -37
  314. package/src/execution/engine/engines/zcode/session-channel.ts +0 -968
  315. package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -1431
  316. package/src/execution/round-settlement.ts +0 -93
  317. package/src/execution/ui-request-queue.ts +0 -215
  318. package/src/shared/schema-env.ts +0 -44
@@ -1,216 +1,15 @@
1
1
  // src/execution/ui-channels.ts
2
2
  //
3
- // UI channel 提取(marker 解析)+ channel 注册表。
4
- //
5
- // channel 是扩展协议自定义的业务路由标识,由 NUL 前缀 marker 标记。
6
- // 已知 marker(来自 @xyz-agent/extension-protocol):
7
- // - ASK_USER_MARKER = "\0XYZ_ASK_USER" 走 select method,出现在 title
8
- // (options[0] = JSON payload {questions, allowCancel})
9
- // - GUI_WIDGET_MARKER = "\0XYZ_GUI_WIDGET:" setWidget method,出现在 widgetLines[0]
10
- // (同行 marker 后紧跟 JSON payload {component})
11
- //
12
- // channel 提取位置随 method 变(.fix-plans/00-master-summary.md §一冲突 2):
13
- // - select → 从 title 解析 NUL 前缀(payload 从 options[0] 取)
14
- // - setWidget → 从 widgetLines[0] 解析 NUL 前缀(payload 从同行 marker 后取)
15
- // - 其他 method → 无 channel(返回 {})
16
- //
17
- // channel 名规范化:去 "XYZ_" 命名空间前缀,去尾部 ":",小写化。
18
- // XYZ_ASK_USER → ask_user
19
- // XYZ_GUI_WIDGET → gui_widget
20
- //
21
- // 本模块是协议层工具(method/marker 都是协议概念),不感知业务。
22
-
23
- /** NUL 前缀字符。Pi extension-protocol 用 NUL(\0)标记控制行,
24
- * 避免与用户可见文本冲突。 */
25
- const NUL = "\0";
26
-
27
- /** channel 提取结果。channel 无 NUL 前缀、字段缺失、JSON parse 失败时
28
- * channel 与 channelPayload 均为 undefined(返回 {})。 */
29
- export interface ParsedChannel {
30
- /** 规范化后的 channel 名(如 "ask_user"、"gui_widget")。
31
- * 无 marker 或解析失败时为 undefined。 */
32
- channel?: string;
33
- /** marker 标记的结构化 payload(已 JSON.parse)。
34
- * ask_user: {questions, allowCancel};gui_widget: {component}。
35
- * payload 来源缺失或 JSON parse 失败时为 undefined(channel 仍可解析)。 */
36
- channelPayload?: unknown;
37
- }
38
-
39
- /** parseChannel 入参的最小形状。
40
- * method 是判别字段;按 method 不同,对应字段(select 的 title/options、
41
- * setWidget 的 widgetLines)可选出现。其他 method 的字段统称 [key:string]。 */
42
- export interface ExtensionUiRequestLike {
43
- method: string;
44
- /** select method:title 字段(可能含 ASK_USER_MARKER NUL 前缀)。 */
45
- title?: string;
46
- /** select method:options 数组(options[0] 可能是 channel payload 的 JSON)。 */
47
- options?: string[];
48
- /** setWidget method:widgetKey 字段。 */
49
- widgetKey?: string;
50
- /** setWidget method:widgetLines 数组(widgetLines[0] 可能含 GUI_WIDGET_MARKER)。 */
51
- widgetLines?: string[] | undefined;
52
- /** 其他 method 的任意字段(容错:允许测试和未来扩展传入额外字段)。 */
53
- [key: string]: unknown;
54
- }
55
-
56
- /** channel handler 签名:接收 UiRequest,返回 UiResponse。
57
- * 具体类型定义在 session-runner.ts(W2 工作),此处用最小形状避免循环依赖。
58
- * handler 实现方按 channel 注册,由 session-runner 按 req.channel 分派。 */
59
- export type ChannelHandler = (req: unknown) => Promise<unknown>;
60
-
61
- /** channel 注册表接口。职责单一:只管业务路由,不管排队、不管透传判定。
62
- * - register(channel, handler):注册 channel 对应的 handler(同名覆盖)
63
- * - resolve(channel):取 channel 对应的 handler,未注册返回 undefined
64
- * - list():列举所有已注册 channel 名 */
65
- export interface UiChannelRegistry {
66
- register(channel: string, handler: ChannelHandler): void;
67
- resolve(channel: string): ChannelHandler | undefined;
68
- list(): string[];
69
- }
70
-
71
- /** 规范化 channel 名。
72
- * 输入是 NUL 前缀后的字面量(如 "XYZ_ASK_USER"、"XYZ_GUI_WIDGET:")。
73
- * 规则:
74
- * 1. 去 "XYZ_" 命名空间前缀(协议命名空间标识,非业务语义)
75
- * 2. 去尾部 ":"(GUI_WIDGET 等"行内 payload"型 marker 的分隔符)
76
- * 3. 小写化(XYZ_ASK_USER → ask_user)
77
- *
78
- * 例:
79
- * "XYZ_ASK_USER" → "ask_user"
80
- * "XYZ_GUI_WIDGET:" → "gui_widget"
81
- * "FOO_BAR" → "foo_bar"(无 XYZ_ 前缀也容忍,去前缀仅当字面量以 XYZ_ 开头) */
82
- function normalizeChannelName(markerLiteral: string): string {
83
- let name = markerLiteral;
84
- // 去 "XYZ_" 命名空间前缀(仅当以此开头)
85
- if (name.startsWith("XYZ_")) {
86
- name = name.slice("XYZ_".length);
87
- }
88
- // 去尾部 ":"(行内 payload 型 marker 的分隔符)
89
- if (name.endsWith(":")) {
90
- name = name.slice(0, -1);
91
- }
92
- return name.toLowerCase();
93
- }
94
-
95
- /** 从 marker 字面量字符串解析 channel 名。
96
- * 输入 str 形如 "\0XYZ_ASK_USER"(marker 占满整个字段,payload 在别处)。
97
- * 无 NUL 前缀返回 undefined。 */
98
- function parseMarkerFromField(str: string): string | undefined {
99
- if (!str.startsWith(NUL)) return undefined;
100
- // 去掉 NUL 前缀,取剩余字面量作为 marker literal
101
- const literal = str.slice(NUL.length);
102
- if (literal === "") return undefined;
103
- return normalizeChannelName(literal);
104
- }
105
-
106
- /** 从 marker + 行内 payload 字符串解析 channel 名 + payload。
107
- * 输入 str 形如 "\0XYZ_GUI_WIDGET:{...json...}"(marker 与 payload 在同一行)。
108
- * 无 NUL 前缀返回 undefined。
109
- * payload 解析失败时不抛(返回 channel 名,payload 由调用方处理)。 */
110
- function parseInlineMarkerFromField(str: string): { channel: string } | undefined {
111
- if (!str.startsWith(NUL)) return undefined;
112
- const rest = str.slice(NUL.length);
113
- // marker literal 与 payload 的分界:第一个 ":" 或行尾
114
- // GUI_WIDGET_MARKER 格式为 "\0XYZ_GUI_WIDGET:" + json,分界是 ":"
115
- const colonIdx = rest.indexOf(":");
116
- let literal: string;
117
- if (colonIdx >= 0) {
118
- literal = rest.slice(0, colonIdx + 1); // 含 ":",normalizeChannelName 会去尾部 ":"
119
- } else {
120
- literal = rest;
121
- }
122
- if (literal === "") return undefined;
123
- return { channel: normalizeChannelName(literal) };
124
- }
125
-
126
- /** 从 select.title 解析 channel(payload 从 options[0] 取)。
127
- * - title 无 NUL 前缀 → undefined
128
- * - title 含 marker → channel 名;payload 从 options[0] JSON.parse(失败/缺失 → undefined) */
129
- function parseFromMarkerString(
130
- title: string | undefined,
131
- options: string[] | undefined,
132
- ): ParsedChannel {
133
- if (title === undefined) return {};
134
- const channel = parseMarkerFromField(title);
135
- if (channel === undefined) return {};
136
- // payload 从 options[0] 取(ask_user 协议:title 是 marker,options[0] 是 JSON payload)
137
- let payload: unknown;
138
- if (options !== undefined && options.length > 0) {
139
- try {
140
- payload = JSON.parse(options[0]);
141
- } catch {
142
- payload = undefined; // JSON parse 失败:不抛,channel 仍解析
143
- }
144
- }
145
- return { channel, channelPayload: payload };
146
- }
147
-
148
- /** 从 setWidget.widgetLines[0] 解析 channel(payload 从同行 marker 后取)。
149
- * - widgetLines 缺失/空数组/首行无 NUL 前缀 → undefined
150
- * - 首行含 marker → channel 名;payload 从 marker 后的 JSON 取(失败 → undefined) */
151
- function parseFromMarkerArray(
152
- widgetLines: string[] | undefined,
153
- ): ParsedChannel {
154
- if (widgetLines === undefined || widgetLines.length === 0) return {};
155
- const firstLine = widgetLines[0];
156
- if (typeof firstLine !== "string") return {};
157
- const parsed = parseInlineMarkerFromField(firstLine);
158
- if (parsed === undefined) return {};
159
- // payload 从 marker 后的 JSON 取(GUI_WIDGET 协议:marker 与 payload 同行)
160
- let payload: unknown;
161
- const rest = firstLine.slice(NUL.length);
162
- const colonIdx = rest.indexOf(":");
163
- if (colonIdx >= 0) {
164
- const jsonStr = rest.slice(colonIdx + 1);
165
- if (jsonStr !== "") {
166
- try {
167
- payload = JSON.parse(jsonStr);
168
- } catch {
169
- payload = undefined; // JSON parse 失败:不抛,channel 仍解析
170
- }
171
- }
172
- }
173
- return { channel: parsed.channel, channelPayload: payload };
174
- }
175
-
176
- /** 按 method 分派解析 channel。
177
- *
178
- * - select → 从 title 解析 NUL 前缀(payload 从 options[0])
179
- * - setWidget → 从 widgetLines[0] 解析 NUL 前缀(payload 从同行 marker 后)
180
- * - 其他 method → {}(无 channel 提取位置)
181
- *
182
- * 边界(均不抛错):
183
- * - title/widgetLines 字段缺失 → {}
184
- * - 无 NUL 前缀 → {}
185
- * - JSON parse 失败 → channel 仍解析,channelPayload 为 undefined
186
- *
187
- * @param req ExtensionUiRequestLike(method + 对应字段)
188
- * @returns ParsedChannel(channel/channelPayload 可选) */
189
- export function parseChannel(req: ExtensionUiRequestLike): ParsedChannel {
190
- switch (req.method) {
191
- case "select":
192
- return parseFromMarkerString(req.title, req.options);
193
- case "setWidget":
194
- return parseFromMarkerArray(req.widgetLines);
195
- default:
196
- return {};
197
- }
198
- }
199
-
200
- /** 创建 channel 注册表实例。
201
- * 进程级单例(通常由 SubagentService 持有一个实例,跨所有子进程共享)。
202
- * register 同名 channel 会覆盖旧 handler。 */
203
- export function createUiChannelRegistry(): UiChannelRegistry {
204
- const handlers = new Map<string, ChannelHandler>();
205
- return {
206
- register(channel: string, handler: ChannelHandler): void {
207
- handlers.set(channel, handler);
208
- },
209
- resolve(channel: string): ChannelHandler | undefined {
210
- return handlers.get(channel);
211
- },
212
- list(): string[] {
213
- return Array.from(handlers.keys());
214
- },
215
- };
216
- }
3
+ // UI channel 提取(marker 解析)+ channel 注册表的 re-export shim:实现体单源
4
+ // @zhushanwen/subagent-engine-sdk(自本文件逐字等价移入 SDK,round1-reuse R1;
5
+ // core SDK 边界正向合法)。core 内消费方(channel-registry-access /
6
+ // ui-request-handler-factory)import 路径保持不变,barrel 导出面零变化。
7
+
8
+ export {
9
+ type ChannelHandler,
10
+ createUiChannelRegistry,
11
+ type ExtensionUiRequestLike,
12
+ parseChannel,
13
+ type ParsedChannel,
14
+ type UiChannelRegistry,
15
+ } from "@zhushanwen/subagent-engine-sdk";
@@ -2,10 +2,13 @@
2
2
  //
3
3
  // UI 请求 handler 工厂(透传 + 排队总控)。
4
4
  //
5
- // 按 ctx.mode(ExtensionMode)创建合适的 UiRequestHandler,让 SubagentService 持有后
6
- // 经 session-runner 透传给子进程的 extension_ui_request。本模块是「handler 注入链路」的
7
- // 组装点:把 channel registry(业务路由)+ dialog queue(L2 跨子进程串行)+ mode 分流
8
- //(TUI/GUI/headless)粘合成一个 handler。
5
+ // 按 ctx.mode(ExtensionMode)创建合适的 UiRequestHandlerSubagentService 持有后经
6
+ // host-ui-endpoint 登记处注入协议客户端——引擎进程的 extension_ui_request
7
+ // host/askUser 反向通道到达本 handler([W3] inproc L1 队列 inproc UI 请求队列(已删) 随
8
+ // inproc pi 引擎目录 删除消亡,「run 生命周期内闭包队列」语义由引擎包内等价物 +
9
+ // 协议应答路径承接)。本模块是「handler 注入链路」的组装点:把 channel registry
10
+ //(业务路由)+ dialog queue(L2 跨子进程串行)+ mode 分流(TUI/GUI/headless)
11
+ // 粘合成一个 handler。
9
12
  //
10
13
  // 设计依据(.fix-plans/00-master-summary.md):
11
14
  // - §一冲突 2「透传矩阵」:
@@ -9,9 +9,9 @@ import type { ExtensionMode } from "./host-mode.ts";
9
9
 
10
10
  const logger = getLogger("subagents");
11
11
 
12
- // ── 跨模块桥接(ui-request-queue 无 ctx.service 引用时走这里) ──
12
+ // ── 跨模块桥接(inproc UI 请求队列(已删) 无 ctx.service 引用时走这里) ──
13
13
  //
14
- // ui-request-queue.handleUiRequest 在 ctx.uiRequestHandler 缺失时需要触发去重告警,
14
+ // inproc UI 请求队列 handleUiRequest(已删) 在 ctx.uiRequestHandler 缺失时需要触发去重告警,
15
15
  // 但 SessionRunnerContext 不持有 service 引用(改 ctx 签名超出本组 4 文件范围)。
16
16
  // 解法:SubagentService 构造后调 registerGlobalObservability(this.uiObservability)
17
17
  // 把进程单例挂到 globalThis;queue 走 notifyMissingHandlerGlobal 路径调到同一实例,
@@ -0,0 +1,67 @@
1
+ // src/execution/workflow-state-root.ts
2
+ //
3
+ // [F-1 修复] pi 宿主 WorkflowRun state 目录解析(与 pi 壳 JsonlRunStore 同源布局)。
4
+ //
5
+ // 为什么存在:pi 宿主 workflow 域的 run state 真实落盘 = JsonlRunStore 的
6
+ // `<sessionDir>/workflow-state/<runId>.jsonl`,sessionDir 由 extension 侧
7
+ // `extensions/universal/subagent-workflow/src/session-lifecycle.ts` 的
8
+ // resolveSessionDir() 推导。core 侧两个读侧装配点(round-supervisor 的注册对账
9
+ // sweep、idle-gc 的 WorkflowRun GC)曾用 FileRunStore 缺省根
10
+ // `<dataRoot>/workflow-state`(zcode 宿主布局)——两目录生产不相交,读侧恒 ENOENT:
11
+ // sweep 把活跃 run 判 missing 补注销(误注销活跃 run),WorkflowRun GC 恒空转。
12
+ //
13
+ // core 不能 import extension——本文件按 resolveSessionDir 同规则在 core 侧重写推导,
14
+ // 两处注释互指锚定([同步纪律] 改 sessionDir 布局时必须同批改本文件与
15
+ // session-lifecycle.ts,漂移信号 = sweep 补注销活跃 run / GC 空转)。
16
+ //
17
+ // agentDir 推导锚定 pi 实装版 0.84.4 dist config.js getAgentDir:
18
+ // `process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent")`
19
+ // (ENV_AGENT_DIR = PI_CODING_AGENT_DIR、CONFIG_DIR_NAME = piConfig.configDir = ".pi",
20
+ // 无 piConfig.name 覆盖)。pi 升级若改 getAgentDir 语义 → 本推导漂移,可见信号同上。
21
+
22
+ import { existsSync } from "node:fs";
23
+ import { homedir } from "node:os";
24
+ import { join } from "node:path";
25
+
26
+ /** pi SDK getAgentDir 的 env 覆盖通道(实装版 dist config.js ENV_AGENT_DIR)。 */
27
+ const PI_AGENT_DIR_ENV = "PI_CODING_AGENT_DIR";
28
+
29
+ /** pi SDK 缺省 agent 目录分量(实装版 dist config.js:CONFIG_DIR_NAME + "agent")。 */
30
+ const DEFAULT_PI_AGENT_DIR_PARTS = [".pi", "agent"] as const;
31
+
32
+ /** resolvePiWorkflowStateDir 的注入面(测试用;生产缺省全走真实推导)。 */
33
+ export interface PiWorkflowStateDirOptions {
34
+ /** agent 配置目录覆盖(缺省 = PI_CODING_AGENT_DIR env 或 ~/.pi/agent)。 */
35
+ agentDir?: string;
36
+ /** cwd 覆盖(缺省 process.cwd()——对齐 session-lifecycle 用进程 cwd 而非 ctx.cwd)。 */
37
+ cwd?: string;
38
+ }
39
+
40
+ /**
41
+ * 解析 pi 宿主 WorkflowRun state 目录(`<sessionDir>/workflow-state`)。
42
+ *
43
+ * sessionDir 推导(与 session-lifecycle.resolveSessionDir 逐段同构,见文件头注):
44
+ * - cwd-slug = `--<cwd 去开头分隔符、`/`→`-`>--`(extension 侧字面规则——core 的
45
+ * encodeCwd 额外折叠 `:` 与 `\`,与建目录方不一致,此处不共用);
46
+ * - `<agentDir>/sessions/<slug>` 目录存在则用之(该目录由 workflow 域首次落盘
47
+ * 创建——cwd 有过 workflow run 才存在),否则回退 agentDir 根
48
+ * (JsonlRunStore 的 mkdir recursive 使首写直接落 agentDir 根,两侧探测一致)。
49
+ *
50
+ * 只读解析(existsSync 探测),无目录创建副作用——与 FileRunStore 的 save 侧
51
+ * mkdir 职责分离。
52
+ */
53
+ export function resolvePiWorkflowStateDir(opts?: PiWorkflowStateDirOptions): string {
54
+ const agentDir = opts?.agentDir ?? resolvePiAgentDir();
55
+ const cwd = opts?.cwd ?? process.cwd();
56
+ const sessionSlug = `--${cwd.replace(/^\//, "").replace(/\//g, "-")}--`;
57
+ const sessionScopedDir = join(agentDir, "sessions", sessionSlug);
58
+ const sessionDir = existsSync(sessionScopedDir) ? sessionScopedDir : agentDir;
59
+ return join(sessionDir, "workflow-state");
60
+ }
61
+
62
+ /** pi agent 目录(getAgentDir 同语义;推导锚定见文件头注)。 */
63
+ function resolvePiAgentDir(): string {
64
+ const envDir = process.env[PI_AGENT_DIR_ENV];
65
+ if (envDir !== undefined && envDir !== "") return envDir;
66
+ return join(homedir(), ...DEFAULT_PI_AGENT_DIR_PARTS);
67
+ }
@@ -25,6 +25,8 @@
25
25
  // 职责,不在纯内核复刻——git index.lock 冲突瞬时态正好落降级路径②,而非内核故障。
26
26
 
27
27
  import { execFile } from "node:child_process";
28
+
29
+ import { buildOutboundChildEnv } from "@zhushanwen/subagent-engine-sdk";
28
30
  import * as fs from "node:fs";
29
31
 
30
32
  import { getLogger } from "../core/logger.ts";
@@ -115,6 +117,9 @@ export function gitRun(
115
117
  timeout: opts.timeout ?? GIT_TIMEOUT_MS,
116
118
  ...(opts.maxBuffer !== undefined ? { maxBuffer: opts.maxBuffer } : {}),
117
119
  encoding: "utf-8",
120
+ // 出站卫生(R3 MF-C,impl-plan §2.12):同 worktree-manager.ts gitRunAsync——
121
+ // deny 键不进 git 子进程,git hooks 后代不再可能消费 deny 键。
122
+ env: buildOutboundChildEnv({ parentEnv: process.env }),
118
123
  },
119
124
  (err, stdout, stderr) => {
120
125
  if (err) {
@@ -23,6 +23,8 @@
23
23
  // 声称的「tmpdir + 分支对账兜底」由此成为代码。
24
24
 
25
25
  import { execFile } from "node:child_process";
26
+
27
+ import { buildOutboundChildEnv } from "@zhushanwen/subagent-engine-sdk";
26
28
  import * as fs from "node:fs";
27
29
  import * as os from "node:os";
28
30
  import * as path from "node:path";
@@ -713,7 +715,15 @@ export class WorktreeManager {
713
715
  execFile(
714
716
  "git",
715
717
  args,
716
- { cwd: opts.cwd, timeout: opts.timeout ?? GIT_TIMEOUT_MS, encoding: "utf-8" },
718
+ {
719
+ cwd: opts.cwd,
720
+ timeout: opts.timeout ?? GIT_TIMEOUT_MS,
721
+ encoding: "utf-8",
722
+ // 出站卫生(R3 MF-C,impl-plan §2.12):deny 键不进 git 子进程——
723
+ // git hooks 等后代不再可能消费生命周期标志 / WS 令牌。SDK 版缺省
724
+ // 全量继承父 env + deny 剥除,行为差异仅 deny 键剥除。
725
+ env: buildOutboundChildEnv({ parentEnv: process.env }),
726
+ },
717
727
  (err, stdout, stderr) => {
718
728
  if (err) {
719
729
  const execErr = err as Error & { code?: unknown; killed?: boolean; signal?: string };
package/src/index.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  * @zhushanwen/subagent-core — 公共 API barrel(D5 定稿 + post-convergence B-2 扩面)
3
3
  *
4
4
  * 公共 API 面 = 本文件导出 + package.json exports 的语义子入口
5
- * (./engines/zcode/reader、./engines/zcode/constants、./engine/paths、./relay-env
6
- * + ./workflows/* 资产子入口。exports 面即 semver 契约(D5):收窄不放宽——
5
+ * (./engine/paths、./engine/engine-discovery-scan、./relay-env——[W11/H3] 引擎
6
+ * 子入口 ./engines/zcode/* 已随内建引擎删除)+ ./workflows/* 资产子入口。exports 面即 semver 契约(D5):收窄不放宽——
7
7
  * 新增导出走 minor,本文件刻意不使用 `export *`,逐名列出以使 diff 可审。
8
8
  * 内部实现细节(error-recovery / execute-agent-call / worker-script-builder 等
9
9
  * engine 编排件)不经 barrel 导出;host-surface 扩面(zsw 回接 U0,2026-08-30)
@@ -24,7 +24,7 @@
24
24
  // 0.4.0 = 首个公开发布的收敛收口面(0.3.0 为 2026-08-30 裁决的跳号占位,永不单独
25
25
  // 发布;+ minor changeset 收口面落本号);与 package.json version 的一致性由
26
26
  // src/__tests__/smoke.test.ts 动态守护,改版本须两处同步。
27
- export const CORE_PACKAGE_VERSION = "0.5.1";
27
+ export const CORE_PACKAGE_VERSION = "0.7.0";
28
28
 
29
29
  // ── 宿主端口接线面(core/)────────────────────────────────────
30
30
  // HostServices:dataRoot / log / discoveryRoots 端口 + configureCore 注入;
@@ -88,34 +88,54 @@ export {
88
88
  type EngineRoutingInput,
89
89
  type EngineRoutingSource,
90
90
  } from "./execution/engine/routing.ts";
91
+ // [W8 补扫接线面] setEngineDiscoveryRescanOptions:宿主登记 hasEngineWithRescan 的
92
+ // 补扫发现参数(与 session_start 发现扫描同源);壳消费 = runtime
93
+ // subagent-engine-history 的 ensureRuntimeEngineWiring。
94
+ export { setEngineDiscoveryRescanOptions } from "./execution/engine/routing.ts";
91
95
 
92
96
  // ── 引擎注册 / 发现与进程面(execution/engine)────────────────
93
97
  // 组合根 index.ts 接线消费(registerXxx 引擎注册、syncEnginesFile engines 文件
94
98
  // 同步、killAllSpawnedChildren session 派生进程兜底清理)。
95
99
  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";
100
+ // [W11/DoD#5] registerPiEngine(inproc 'pi' 注册)已删;[W3 chat 域收口] chat 域 inproc
101
+ // 引擎(inproc pi 引擎目录)与 SubagentService 自持 DI 实例一并删除——registry 'pi' 由三级发现
102
+ // 装载 cli descriptor,chat 轮次与 run 域同路经协议客户端发往 pi-subagent-cli 引擎进程
103
+ // (G1:pi 引擎单一 CLI 形态,core 壳侧零内建引擎)。
104
+ // [W8 D8 薄壳] killAllSpawnedChildren:扩展 index.ts / zsw runner-core.js 的业务调用点
105
+ // 零改动。语义([F-7 注释纠偏,如实口径])= **仅镜像记账**——core 侧 spawnedChildren
106
+ // 镜像整体清空(engine/host/spawned-children.ts 公共面),不发任何进程信号;
107
+ // 子进程活在引擎进程内,其回收链 = ① stdin-EOF 自灭(宿主退出 / EngineClient 销毁
108
+ // → 引擎进程 stdin 断源自灭,正常路径);② disposeEngines()(registry)显式触发全部
109
+ // 已实例化引擎 dispose(cli 形态 = RemoteEngine.dispose → EngineClient 有界收口)——
110
+ // 该入口为宿主 shutdown 链预留,现无生产接线。subagent-workflow 扩展的
111
+ // reapSpawnedChildrenOnShutdown(process hook 调本函数)因此同为镜像置死 no-op,
112
+ // 不构成真实收割(现状登记,workflow 包生产码不动)。
113
+ export { killAllSpawnedChildren } from "./execution/engine/host/spawned-children.ts";
114
+
115
+ // [W8 D8 兼容公共面薄壳](设计 §3.6 D8 表):registerZcodeEngine 确保cli descriptor
116
+ // 注册(vendored 相对定位,失败回退 inproc 过渡)+ engineDataDir 记入;createZcodeEngine
117
+ // 返回 RemoteEngine('zcode')(deps → 协议客户端映射,sources 不跨进程)。实现见
118
+ // execution/engine/d8-compat.ts——engines/zcode/registration.ts 的同名符号不再经
119
+ // barrel 导出(inproc 实现保留至 W11,仅内部测试/过渡消费)。
120
+ export {
121
+ createZcodeEngine,
122
+ registerZcodeEngine,
123
+ type D8CompatZcodeEngineDeps,
124
+ } from "./execution/engine/d8-compat.ts";
99
125
 
100
- // pi session-runner 内核件(merge 裁决:dev 侧旧深路径 execution/session-runner.ts
101
- // 终态已不存在,符号随 u-2a 迁移至 engine/engines/pi/session-runner.ts):
102
126
  // maxTurnsToWatchdogMs 为 maxTurns→watchdog 毫秒换算(U3/U4 / D7,floor 语义
103
- // 文档化——两宿主预算一致性 S2 的函数级锚点);killRecordChildWithEscalation
104
- // record 子进程升级回收(session 派生进程清理的细粒度入口)。
127
+ // 文档化——两宿主预算一致性 S2 的函数级锚点;[W3] 定义收敛在 pi-host-binding,
128
+ // inproc session-runner(已删) 定义随删件消亡);killRecordChildWithEscalation 为
129
+ // 单 record 子进程终止的镜像记账入口([W3] 实际终止在引擎进程内经协议承载)。
105
130
  export {
106
131
  killRecordChildWithEscalation,
107
- maxTurnsToWatchdogMs,
108
- } from "./execution/engine/engines/pi/session-runner.ts";
132
+ } from "./execution/engine/host/spawned-children.ts";
133
+ export { maxTurnsToWatchdogMs } from "./execution/engine/host/pi-host-binding.ts";
109
134
 
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";
135
+ // zcode 引擎注册面([W8 D8 薄壳] createZcodeEngine 已上移 d8-compat——上方导出)。
136
+ // [W11 收口] ZcodeEngineDeps D8CompatZcodeEngineDeps 合并为别名(zsw 调用面的
137
+ // deps 形状契约保持);barrel 不导出引擎错误类(引擎错误归各引擎包自持)。
138
+ export type { ZcodeEngineDeps } from "./execution/engine/d8-compat.ts";
119
139
 
120
140
  // 引擎注册表原语 + 引擎感知提示面:engine-awareness injector 消费。
121
141
  export {
@@ -132,6 +152,11 @@ export {
132
152
  // 子入口(D9:每条子入口 bundle 多一份 host-services 副本)。
133
153
  export { parseEngineHandle } from "./execution/engine/common/session-view-types.ts";
134
154
  export { readSubagentHistoryMessages } from "./execution/engine/common/session-view-service.ts";
155
+ // [W8] registerNativeSessionReader:runtime 成为协议客户端的①级接入点——宿主把
156
+ // 「协议 read」注册为引擎原生 reader,core 三级降级链(①协议 read → ②journal →
157
+ // ③outcome)自动编排(含投影),宿主零投影代码。壳消费 = runtime
158
+ // subagent-engine-history 的协议 reader 注册。
159
+ export { registerNativeSessionReader } from "./execution/engine/common/session-view-service.ts";
135
160
 
136
161
  // ── 执行域(execution/)──────────────────────────────────────
137
162
  // types.ts 领域类型族:record / 响应 / 列表项等 subagent 域公共契约(壳消费最高频面,
@@ -262,7 +287,7 @@ export {
262
287
 
263
288
  // 错误类型族(error-recovery.ts 计划路径实测不存在,实测散布于下列源文件):
264
289
  // resurrect/fork-depth/dirty-worktree 为动作层守卫抛出点(types.ts),
265
- // GitRunError 见 worktree 内核组裁决,ZcodeTaskShapeError 见引擎注册面。
290
+ // GitRunError 见 worktree 内核组裁决。
266
291
  export {
267
292
  DirtyWorktreeError,
268
293
  ForkDepthExceededError,
@@ -313,14 +338,14 @@ export {
313
338
  } from "./execution/concurrency-pool.ts";
314
339
 
315
340
  // 模型引用切分原语(U1 契约面批件):provider/model 引用切分与缺省值(两宿主
316
- // maxTurns/model 换算同源);实现体内聚 zcode preparer/constants 不挪文件,
317
- // barrel re-export(§5.3)。
341
+ // maxTurns/model 换算同源)。[W11/H2] 实现体随 engines/zcode 删除迁至
342
+ // shared/zcode-model-ref.ts(宿主侧原语,与引擎包各自单源)。
318
343
  export {
319
344
  DEFAULT_PROVIDER_ID,
320
345
  hasApiKey,
321
346
  splitZcodeModelRef,
322
- } from "./execution/engine/engines/zcode/preparer.ts";
323
- export { ZCODE_FALLBACK_DEFAULT_MODEL } from "./execution/engine/engines/zcode/constants.ts";
347
+ ZCODE_FALLBACK_DEFAULT_MODEL,
348
+ } from "./shared/zcode-model-ref.ts";
324
349
 
325
350
  // ── worktree git 内核(U5 / D5)───────────────────────────────
326
351
  // git 语义纯函数单源:保真读(gitRun)、SafeId 校验、dirty 谓词、
@@ -484,10 +509,14 @@ export type {
484
509
  // LifecycleDeps.store 用;pi 壳继续用 session 锚定的 JsonlRunStore。
485
510
  // DEFAULT_* 两常量:壳 jsonl-run-store.ts 生产消费(D3 判定进 barrel),
486
511
  // u-2c 删 ./* 通配后深路径仅测试侧 vitest alias 可解析,生产消费必须走 barrel。
512
+ // pruneStateFilesBeyondCap:磁盘 retention 裁剪单源(S4-A7)——壳 jsonl-run-store
513
+ // 的同构私有实现已删,改 import 本函数并注入自身 logger tag / toErrorMessage。
487
514
  export {
488
515
  DEFAULT_SAVE_MIN_INTERVAL_MS,
489
516
  DEFAULT_STATE_MAX_RUNS,
490
517
  FileRunStore,
518
+ pruneStateFilesBeyondCap,
519
+ type PruneStateDeps,
491
520
  } from "./orchestration/file-run-store.ts";
492
521
 
493
522
  // ── 快照 codec(U8 / D4)──────────────────────────────────────
@@ -102,7 +102,7 @@ beforeEach(async () => {
102
102
 
103
103
  afterEach(async () => {
104
104
  vi.useRealTimers();
105
- if (ws) await rm(ws.root, { recursive: true, force: true });
105
+ if (ws) await rm(ws.root, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
106
106
  });
107
107
 
108
108
  /** 过滤掉可能从真实 homedir 泄漏进来的 user-agents 文件,只保留临时工作区内结果。 */
@@ -12,7 +12,7 @@ import {
12
12
  isDeterministicSchemaFailureMsg,
13
13
  isStaleContextErrorMsg,
14
14
  STALE_CONTEXT_PATTERNS,
15
- } from "../../execution/engine/engines/pi/output-collector.ts";
15
+ } from "@zhushanwen/pi-subagent-cli";
16
16
  import { executeAgentCall } from "../execute-agent-call.ts";
17
17
  import { AgentCall } from "../models/agent-call.ts";
18
18
  import { Budget } from "../models/budget.ts";
@@ -41,7 +41,7 @@ beforeEach(() => {
41
41
 
42
42
  afterEach(() => {
43
43
  resetCoreForTests();
44
- rmSync(dataRoot, { recursive: true, force: true });
44
+ rmSync(dataRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
45
45
  delete process.env[ENV_NAME];
46
46
  });
47
47
 
@@ -39,7 +39,7 @@ beforeEach(() => {
39
39
  afterEach(() => {
40
40
  vi.useRealTimers();
41
41
  resetCoreForTests();
42
- rmSync(dataRoot, { recursive: true, force: true });
42
+ rmSync(dataRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
43
43
  });
44
44
 
45
45
  /** 构造可持久化的 WorkflowRun(对齐 file-run-store.test.ts makeRun 模式)。 */
@@ -67,7 +67,7 @@ beforeEach(() => {
67
67
  });
68
68
 
69
69
  afterEach(() => {
70
- rmSync(sandboxDir, { recursive: true, force: true });
70
+ rmSync(sandboxDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
71
71
  });
72
72
 
73
73
  /** cwd 植入件:若任一脚本回退 process.cwd() 加载依赖,本文件被 require 即抛标记错误。 */
@@ -168,7 +168,7 @@ describe("generateWorkflowScript 校验闸(文案逐字对齐 pi 现版)", (
168
168
  );
169
169
  expect(existsSync(join(tmpRoot, "esm-wf.js"))).toBe(false);
170
170
  } finally {
171
- rmSync(tmpRoot, { recursive: true, force: true });
171
+ rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
172
172
  }
173
173
  });
174
174
 
@@ -216,7 +216,7 @@ describe("generateWorkflowScript 校验闸(文案逐字对齐 pi 现版)", (
216
216
  }
217
217
  expect(existsSync(join(tmpRoot, "bad-wf.js"))).toBe(false);
218
218
  } finally {
219
- rmSync(tmpRoot, { recursive: true, force: true });
219
+ rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
220
220
  }
221
221
  });
222
222
 
@@ -247,7 +247,7 @@ describe("generateWorkflowScript 合法样本落 tmp", () => {
247
247
  expect(existsSync(r.path)).toBe(true);
248
248
  expect(readFileSync(r.path, "utf-8")).toBe(PI_META_VALID);
249
249
  } finally {
250
- rmSync(tmpRoot, { recursive: true, force: true });
250
+ rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
251
251
  }
252
252
  });
253
253
 
@@ -259,7 +259,7 @@ describe("generateWorkflowScript 合法样本落 tmp", () => {
259
259
  if (!r.ok) throw new Error(r.error);
260
260
  expect(existsSync(r.path)).toBe(true);
261
261
  } finally {
262
- rmSync(tmpRoot, { recursive: true, force: true });
262
+ rmSync(tmpRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
263
263
  }
264
264
  });
265
265
 
@@ -274,7 +274,7 @@ describe("generateWorkflowScript 合法样本落 tmp", () => {
274
274
  expect(existsSync(r.path)).toBe(true);
275
275
  } finally {
276
276
  cwdSpy.mockRestore();
277
- rmSync(fakeCwd, { recursive: true, force: true });
277
+ rmSync(fakeCwd, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
278
278
  }
279
279
  });
280
280
  });
@@ -73,8 +73,8 @@ beforeEach(() => {
73
73
  afterEach(() => {
74
74
  vi.restoreAllMocks();
75
75
  resetCoreForTests();
76
- rmSync(projRoot, { recursive: true, force: true });
77
- rmSync(homeRoot, { recursive: true, force: true });
76
+ rmSync(projRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
77
+ rmSync(homeRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
78
78
  });
79
79
 
80
80
  /** mkdir -p(目录存在即 resolveSkillPath 命中——检查的是目录而非 SKILL.md)。 */