@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,240 +0,0 @@
1
- import {
2
- ZCODE_ENGINE_ID
3
- } from "./chunk-V3VHZ2VX.js";
4
-
5
- // src/execution/engine/engines/zcode/reader.ts
6
- import * as fs from "fs";
7
- var ZcodeReaderError = class extends Error {
8
- code;
9
- /** 原始失败细节(缺文件/表漂移/运行时不支持)。 */
10
- detail;
11
- constructor(detail, hint) {
12
- super(
13
- `[engine_session_read_failed] zcode \u539F\u751F session \u8BFB\u53D6\u5931\u8D25\uFF1A${detail}\u3002` + (hint ?? "\u8C03\u7528\u65B9\u5E94\u964D\u7EA7\u5230\u7B2C\u2461\u7EA7\uFF08\u5BBF\u4E3B event journal\uFF09\u6216\u7B2C\u2462\u7EA7\uFF08outcome-only\uFF09\u3002")
14
- );
15
- this.name = "ZcodeReaderError";
16
- this.code = "engine_session_read_failed";
17
- this.detail = detail;
18
- }
19
- };
20
- function parseJsonField(raw, ctx) {
21
- try {
22
- const v = JSON.parse(raw);
23
- return typeof v === "object" && v !== null && !Array.isArray(v) ? v : void 0;
24
- } catch (err) {
25
- throw new ZcodeReaderError(
26
- `${ctx} \u884C data \u4E0D\u662F\u5408\u6CD5 JSON\uFF08${err instanceof Error ? err.message : String(err)}\uFF09`,
27
- "db \u5185\u5BB9\u635F\u574F\u6216\u7248\u672C\u4E0D\u517C\u5BB9\u2014\u2014\u8C03\u7528\u65B9\u5E94\u964D\u7EA7\u5230\u7B2C\u2461\u7EA7\uFF08\u5BBF\u4E3B event journal\uFF09\u3002"
28
- );
29
- }
30
- }
31
- function finiteOr(v, fallback) {
32
- const n = typeof v === "number" ? v : Number(v);
33
- return Number.isFinite(n) ? n : fallback;
34
- }
35
- function usageFromStepFinish(part) {
36
- const tokens = part.tokens;
37
- if (typeof tokens !== "object" || tokens === null) return void 0;
38
- const t = tokens;
39
- const cache = typeof t.cache === "object" && t.cache !== null ? t.cache : {};
40
- if (t.input === void 0 && t.output === void 0) return void 0;
41
- return {
42
- input: finiteOr(t.input, 0),
43
- output: finiteOr(t.output, 0),
44
- cacheRead: finiteOr(cache.read, 0),
45
- cacheWrite: finiteOr(cache.write, 0)
46
- };
47
- }
48
- function toolFromPart(part) {
49
- const toolName = typeof part.tool === "string" ? part.tool : "unknown";
50
- let state;
51
- if (typeof part.state === "string") {
52
- try {
53
- const v = JSON.parse(part.state);
54
- state = typeof v === "object" && v !== null ? v : void 0;
55
- } catch {
56
- state = void 0;
57
- }
58
- }
59
- const status = typeof state?.status === "string" ? state.status : "unknown";
60
- const output = state?.output;
61
- return {
62
- toolName,
63
- ...state?.input !== void 0 ? { args: state.input } : {},
64
- // 输出形态(实测):string(内容)或 object(结构化)——分别映射到 pi ToolCallResult
65
- // 的 content[] / details,不发明第二形状
66
- ...typeof output === "string" ? { result: { content: [output] } } : {},
67
- ...typeof output === "object" && output !== null ? { result: { details: output } } : {},
68
- ...status !== "completed" ? { isError: true } : {}
69
- };
70
- }
71
- var TotalsAcc = class {
72
- input = 0;
73
- output = 0;
74
- cacheRead = 0;
75
- cacheWrite = 0;
76
- cost = 0;
77
- has = false;
78
- add(u) {
79
- this.has = true;
80
- this.input += u.input;
81
- this.output += u.output;
82
- this.cacheRead += u.cacheRead;
83
- this.cacheWrite += u.cacheWrite;
84
- this.cost += u.cost ?? 0;
85
- }
86
- toTotal() {
87
- if (!this.has) return void 0;
88
- return {
89
- input: this.input,
90
- output: this.output,
91
- cacheRead: this.cacheRead,
92
- cacheWrite: this.cacheWrite,
93
- cost: this.cost,
94
- total: this.input + this.output + this.cacheRead + this.cacheWrite
95
- };
96
- }
97
- };
98
- function closeTurn(acc, turns, totals) {
99
- if (acc === null) return;
100
- turns.push({ text: acc.text, thinking: acc.thinking, toolCalls: acc.toolCalls, closed: true });
101
- if (acc.usageDelta !== void 0) totals.add(acc.usageDelta);
102
- }
103
- function rowToMessageRow(v) {
104
- if (typeof v === "object" && v !== null && "id" in v && "data" in v) {
105
- const r = v;
106
- if (typeof r.id === "string" && typeof r.data === "string") return { id: r.id, data: r.data };
107
- }
108
- throw new ZcodeReaderError("message \u884C\u5F62\u72B6\u5F02\u5E38\uFF08id/data \u5217\u7F3A\u5931\u6216\u7C7B\u578B\u6F02\u79FB\uFF09");
109
- }
110
- function rowToPartRow(v) {
111
- if (typeof v === "object" && v !== null && "data" in v) {
112
- const r = v;
113
- if (typeof r.data === "string") return { data: r.data };
114
- }
115
- throw new ZcodeReaderError("part \u884C\u5F62\u72B6\u5F02\u5E38\uFF08data \u5217\u7F3A\u5931\u6216\u7C7B\u578B\u6F02\u79FB\uFF09");
116
- }
117
- function resolveSessionId(db, sessionId) {
118
- if (sessionId !== void 0) {
119
- const hit = db.prepare("SELECT id FROM session WHERE id = ?").get(sessionId);
120
- if (hit === void 0) {
121
- throw new ZcodeReaderError(
122
- `session \u4E0D\u5B58\u5728\uFF1A${sessionId}`,
123
- "sessionId \u53EF\u80FD\u6765\u81EA\u5DF2\u6E05\u7406\u7684\u6C60\u2014\u2014\u964D\u7EA7\u5230 outcome-only\u3002"
124
- );
125
- }
126
- return sessionId;
127
- }
128
- const latest = db.prepare("SELECT id FROM session ORDER BY time_created DESC LIMIT 1").get();
129
- if (latest === void 0 || typeof latest.id !== "string") {
130
- throw new ZcodeReaderError("db \u5185\u65E0\u4EFB\u4F55 session \u884C");
131
- }
132
- return latest.id;
133
- }
134
- function loadGroupedParts(db, sessionId) {
135
- const grouped = /* @__PURE__ */ new Map();
136
- for (const raw of db.prepare(
137
- "SELECT part.message_id AS mid, part.data AS data FROM part JOIN message ON part.message_id = message.id WHERE part.session_id = ? ORDER BY message.sequence, part.sequence"
138
- ).all(sessionId)) {
139
- if (typeof raw !== "object" || raw === null || !("mid" in raw)) continue;
140
- const mid = String(raw.mid);
141
- const arr = grouped.get(mid) ?? [];
142
- arr.push(rowToPartRow(raw));
143
- grouped.set(mid, arr);
144
- }
145
- return grouped;
146
- }
147
- function appendPartText(current, part) {
148
- return current === "" ? String(part.text ?? "") : current + "\n" + String(part.text ?? "");
149
- }
150
- function applyPartToTurn(part, acc, turns, totals) {
151
- switch (part.type) {
152
- case "text":
153
- acc = acc ?? { text: "", thinking: "", toolCalls: [] };
154
- acc.text = appendPartText(acc.text, part);
155
- return acc;
156
- case "reasoning":
157
- acc = acc ?? { text: "", thinking: "", toolCalls: [] };
158
- acc.thinking = appendPartText(acc.thinking, part);
159
- return acc;
160
- case "tool":
161
- acc = acc ?? { text: "", thinking: "", toolCalls: [] };
162
- acc.toolCalls.push(toolFromPart(part));
163
- return acc;
164
- case "step-finish": {
165
- const u = usageFromStepFinish(part);
166
- const cost = finiteOr(part.cost, 0);
167
- if (acc === null) acc = { text: "", thinking: "", toolCalls: [] };
168
- if (u !== void 0) acc.usageDelta = cost > 0 ? { ...u, cost } : u;
169
- closeTurn(acc, turns, totals);
170
- return null;
171
- }
172
- default:
173
- return acc;
174
- }
175
- }
176
- function collectTurns(messages, grouped, totals) {
177
- const turns = [];
178
- for (const msg of messages) {
179
- const parsedMsg = parseJsonField(msg.data, "message");
180
- if (parsedMsg?.role !== "assistant") continue;
181
- let acc = null;
182
- for (const partRow of grouped.get(msg.id) ?? []) {
183
- const part = parseJsonField(partRow.data, "part");
184
- if (part === void 0) continue;
185
- acc = applyPartToTurn(part, acc, turns, totals);
186
- }
187
- closeTurn(acc, turns, totals);
188
- }
189
- return turns;
190
- }
191
- function buildView(db, sessionId) {
192
- const messages = db.prepare("SELECT id, data FROM message WHERE session_id = ? ORDER BY sequence").all(sessionId).map(rowToMessageRow);
193
- const totals = new TotalsAcc();
194
- const turns = collectTurns(messages, loadGroupedParts(db, sessionId), totals);
195
- const usageTotal = totals.toTotal();
196
- return {
197
- engineId: ZCODE_ENGINE_ID,
198
- sessionId,
199
- ...usageTotal !== void 0 ? { usage: usageTotal } : {},
200
- turns,
201
- source: "native"
202
- };
203
- }
204
- async function readZcodeSessionView(dbPath, sessionId) {
205
- if (!fs.existsSync(dbPath)) {
206
- throw new ZcodeReaderError(`db \u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${dbPath}`);
207
- }
208
- const sqliteModuleId = "node:sqlite";
209
- const sqliteMod = await import(sqliteModuleId).catch(() => void 0);
210
- const DatabaseSyncCtor = sqliteMod?.DatabaseSync;
211
- if (typeof DatabaseSyncCtor !== "function") {
212
- throw new ZcodeReaderError(
213
- "\u5F53\u524D node \u8FD0\u884C\u65F6\u4E0D\u652F\u6301 node:sqlite\uFF08\u9700 >=22.13\uFF09",
214
- "\u5347\u7EA7 node \u6216\u6539\u7528\u7B2C\u2461\u7EA7\uFF08\u5BBF\u4E3B event journal\uFF09\u8BFB\u53D6\u3002"
215
- );
216
- }
217
- const open = DatabaseSyncCtor;
218
- let db;
219
- try {
220
- db = new open(dbPath, { readOnly: true });
221
- return buildView(db, resolveSessionId(db, sessionId));
222
- } catch (err) {
223
- if (err instanceof ZcodeReaderError) throw err;
224
- throw new ZcodeReaderError(
225
- `sqlite \u67E5\u8BE2\u5931\u8D25\uFF08${err instanceof Error ? err.message : String(err)}\uFF09`,
226
- "\u7591\u4F3C\u8868\u7ED3\u6784\u6F02\u79FB\uFF08zcode schema_migration \u5347\u7EA7\uFF09\u2014\u2014\u8C03\u7528\u65B9\u5E94\u964D\u7EA7\u5230\u7B2C\u2461\u7EA7\uFF1B\u5E76\u628A\u65B0 schema \u6837\u672C\u8865\u5F55\u8FDB golden \u5E93\u540E\u66F4\u65B0 reader\u3002"
227
- );
228
- } finally {
229
- try {
230
- db?.close();
231
- } catch (err) {
232
- void err;
233
- }
234
- }
235
- }
236
-
237
- export {
238
- ZcodeReaderError,
239
- readZcodeSessionView
240
- };
@@ -1,31 +0,0 @@
1
- // src/execution/relay-env.ts
2
- var RELAY_ENV_SOCKET = "XYZ_SUBAGENT_RELAY_SOCKET";
3
- var RELAY_ENV_NODE = "XYZ_SUBAGENT_RELAY_NODE";
4
- var RELAY_ENV_SCRIPT = "XYZ_SUBAGENT_RELAY_SCRIPT";
5
- var RELAY_ENV_SESSION_ID = "XYZ_SUBAGENT_RELAY_SESSION_ID";
6
- var RELAY_ENV_RECORD_ID = "XYZ_SUBAGENT_RELAY_RECORD_ID";
7
- var RELAY_PROTOCOL_VERSION = 1;
8
- var RELAY_EXIT_CODES = {
9
- /** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
10
- VERSION_MISMATCH: 10,
11
- /** relay socket 不可达(runtime 未运行或已重启)。 */
12
- SOCKET_UNREACHABLE: 11,
13
- /** socket 中途断开(runtime 崩溃等)——代理生命线断即退。 */
14
- SOCKET_CLOSED: 12,
15
- /** 归属 env(SESSION_ID/RECORD_ID)缺失——防无归属帧污染广播。 */
16
- MISSING_IDENTITY: 13
17
- };
18
- function isRelayActive(env) {
19
- return Boolean(env[RELAY_ENV_SOCKET] && env[RELAY_ENV_NODE] && env[RELAY_ENV_SCRIPT]);
20
- }
21
-
22
- export {
23
- RELAY_ENV_SOCKET,
24
- RELAY_ENV_NODE,
25
- RELAY_ENV_SCRIPT,
26
- RELAY_ENV_SESSION_ID,
27
- RELAY_ENV_RECORD_ID,
28
- RELAY_PROTOCOL_VERSION,
29
- RELAY_EXIT_CODES,
30
- isRelayActive
31
- };
@@ -1,27 +0,0 @@
1
- // src/execution/engine/paths.ts
2
- import { join } from "path";
3
- var MAX_SEG_CHARS = 80;
4
- function sanitizeSeg(input) {
5
- const s = input.replace(/[^A-Za-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
6
- return s.length > 0 ? s.slice(0, MAX_SEG_CHARS) : "default";
7
- }
8
- function resolveEnginesRoot(dataDir) {
9
- return join(dataDir, "engines");
10
- }
11
- function resolveEngineDir(dataDir, engineId) {
12
- return join(resolveEnginesRoot(dataDir), sanitizeSeg(engineId));
13
- }
14
- function resolvePoolDir(dataDir, engineId, poolKey) {
15
- return join(resolveEngineDir(dataDir, sanitizeSeg(engineId)), sanitizeSeg(poolKey));
16
- }
17
- function resolveJournalPath(dataDir, engineId, poolKey, taskId) {
18
- return join(resolvePoolDir(dataDir, engineId, poolKey), `journal-${sanitizeSeg(taskId)}.jsonl`);
19
- }
20
-
21
- export {
22
- sanitizeSeg,
23
- resolveEnginesRoot,
24
- resolveEngineDir,
25
- resolvePoolDir,
26
- resolveJournalPath
27
- };
@@ -1,59 +0,0 @@
1
- // src/execution/engine/engines/zcode/constants.ts
2
- var ZCODE_ENGINE_ID = "zcode";
3
- var ZCODE_ADAPTER_VERSION = "2.0.0";
4
- var ZCODE_CLI_DEFAULT_PATH = "/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs";
5
- var ZCODE_V2_CONFIG_PATH_SUFFIX = [".zcode", "v2", "config.json"];
6
- var ZCODE_FALLBACK_DEFAULT_MODEL = "builtin:bigmodel-coding-plan/GLM-5.3";
7
- var ZCODE_HOST_DB_SUFFIX = [".zcode", "cli", "db", "db.sqlite"];
8
- var ZCODE_KILL_GRACE_MS = 5e3;
9
- var ZCODE_ERROR_TAIL_CHARS = 2e3;
10
- var ZCODE_APPSERVER_REQUEST_TIMEOUT_MS = 15e3;
11
- var ZCODE_APPSERVER_STDERR_TAIL_CHARS = 400;
12
- var ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS = 2048;
13
- var ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS = 5e3;
14
- var ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS = 1500;
15
- var ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS = 3e5;
16
- var ZCODE_TURN_IDLE_TIMEOUT_ENV = "XYZ_ZCODE_TURN_IDLE_TIMEOUT_MS";
17
- var ZCODE_TURN_MAX_TIMEOUT_ENV = "XYZ_ZCODE_TURN_MAX_TIMEOUT_MS";
18
- var ZCODE_TURN_IDLE_TIMEOUT_MS = 18e5;
19
- var ZCODE_TURN_MAX_TIMEOUT_MS = 36e5;
20
- function parseZcodeTurnTimeoutEnv(raw) {
21
- if (raw === void 0 || raw === "") return { state: "unset" };
22
- const parsed = Number(raw);
23
- if (!Number.isFinite(parsed)) return { state: "invalid" };
24
- return { state: "valid", ms: parsed };
25
- }
26
- var ZCODE_SHARED_POOL_KEY = "shared";
27
- var ZCODE_APPSERVER_STOP_TIMEOUT_MS = 3e3;
28
- var ZCODE_APPSERVER_ABORT_GRACE_MS = 3e3;
29
- var ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING = -32603;
30
- var ZCODE_APPSERVER_ERR_BUSY_SESSION = -32010;
31
- var ZCODE_APPSERVER_HARVEST_GRACE_MS = 1e3;
32
-
33
- export {
34
- ZCODE_ENGINE_ID,
35
- ZCODE_ADAPTER_VERSION,
36
- ZCODE_CLI_DEFAULT_PATH,
37
- ZCODE_V2_CONFIG_PATH_SUFFIX,
38
- ZCODE_FALLBACK_DEFAULT_MODEL,
39
- ZCODE_HOST_DB_SUFFIX,
40
- ZCODE_KILL_GRACE_MS,
41
- ZCODE_ERROR_TAIL_CHARS,
42
- ZCODE_APPSERVER_REQUEST_TIMEOUT_MS,
43
- ZCODE_APPSERVER_STDERR_TAIL_CHARS,
44
- ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS,
45
- ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS,
46
- ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS,
47
- ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS,
48
- ZCODE_TURN_IDLE_TIMEOUT_ENV,
49
- ZCODE_TURN_MAX_TIMEOUT_ENV,
50
- ZCODE_TURN_IDLE_TIMEOUT_MS,
51
- ZCODE_TURN_MAX_TIMEOUT_MS,
52
- parseZcodeTurnTimeoutEnv,
53
- ZCODE_SHARED_POOL_KEY,
54
- ZCODE_APPSERVER_STOP_TIMEOUT_MS,
55
- ZCODE_APPSERVER_ABORT_GRACE_MS,
56
- ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING,
57
- ZCODE_APPSERVER_ERR_BUSY_SESSION,
58
- ZCODE_APPSERVER_HARVEST_GRACE_MS
59
- };
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/execution/engine/engines/zcode/constants.ts
21
- var constants_exports = {};
22
- __export(constants_exports, {
23
- ZCODE_ADAPTER_VERSION: () => ZCODE_ADAPTER_VERSION,
24
- ZCODE_APPSERVER_ABORT_GRACE_MS: () => ZCODE_APPSERVER_ABORT_GRACE_MS,
25
- ZCODE_APPSERVER_ERR_BUSY_SESSION: () => ZCODE_APPSERVER_ERR_BUSY_SESSION,
26
- ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING: () => ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING,
27
- ZCODE_APPSERVER_HARVEST_GRACE_MS: () => ZCODE_APPSERVER_HARVEST_GRACE_MS,
28
- ZCODE_APPSERVER_REQUEST_TIMEOUT_MS: () => ZCODE_APPSERVER_REQUEST_TIMEOUT_MS,
29
- ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS: () => ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS,
30
- ZCODE_APPSERVER_STDERR_TAIL_CHARS: () => ZCODE_APPSERVER_STDERR_TAIL_CHARS,
31
- ZCODE_APPSERVER_STOP_TIMEOUT_MS: () => ZCODE_APPSERVER_STOP_TIMEOUT_MS,
32
- ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS: () => ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS,
33
- ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS: () => ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS,
34
- ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS: () => ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS,
35
- ZCODE_CLI_DEFAULT_PATH: () => ZCODE_CLI_DEFAULT_PATH,
36
- ZCODE_ENGINE_ID: () => ZCODE_ENGINE_ID,
37
- ZCODE_ERROR_TAIL_CHARS: () => ZCODE_ERROR_TAIL_CHARS,
38
- ZCODE_FALLBACK_DEFAULT_MODEL: () => ZCODE_FALLBACK_DEFAULT_MODEL,
39
- ZCODE_HOST_DB_SUFFIX: () => ZCODE_HOST_DB_SUFFIX,
40
- ZCODE_KILL_GRACE_MS: () => ZCODE_KILL_GRACE_MS,
41
- ZCODE_SHARED_POOL_KEY: () => ZCODE_SHARED_POOL_KEY,
42
- ZCODE_TURN_IDLE_TIMEOUT_ENV: () => ZCODE_TURN_IDLE_TIMEOUT_ENV,
43
- ZCODE_TURN_IDLE_TIMEOUT_MS: () => ZCODE_TURN_IDLE_TIMEOUT_MS,
44
- ZCODE_TURN_MAX_TIMEOUT_ENV: () => ZCODE_TURN_MAX_TIMEOUT_ENV,
45
- ZCODE_TURN_MAX_TIMEOUT_MS: () => ZCODE_TURN_MAX_TIMEOUT_MS,
46
- ZCODE_V2_CONFIG_PATH_SUFFIX: () => ZCODE_V2_CONFIG_PATH_SUFFIX,
47
- parseZcodeTurnTimeoutEnv: () => parseZcodeTurnTimeoutEnv
48
- });
49
- module.exports = __toCommonJS(constants_exports);
50
- var ZCODE_ENGINE_ID = "zcode";
51
- var ZCODE_ADAPTER_VERSION = "2.0.0";
52
- var ZCODE_CLI_DEFAULT_PATH = "/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs";
53
- var ZCODE_V2_CONFIG_PATH_SUFFIX = [".zcode", "v2", "config.json"];
54
- var ZCODE_FALLBACK_DEFAULT_MODEL = "builtin:bigmodel-coding-plan/GLM-5.3";
55
- var ZCODE_HOST_DB_SUFFIX = [".zcode", "cli", "db", "db.sqlite"];
56
- var ZCODE_KILL_GRACE_MS = 5e3;
57
- var ZCODE_ERROR_TAIL_CHARS = 2e3;
58
- var ZCODE_APPSERVER_REQUEST_TIMEOUT_MS = 15e3;
59
- var ZCODE_APPSERVER_STDERR_TAIL_CHARS = 400;
60
- var ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS = 2048;
61
- var ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS = 5e3;
62
- var ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS = 1500;
63
- var ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS = 3e5;
64
- var ZCODE_TURN_IDLE_TIMEOUT_ENV = "XYZ_ZCODE_TURN_IDLE_TIMEOUT_MS";
65
- var ZCODE_TURN_MAX_TIMEOUT_ENV = "XYZ_ZCODE_TURN_MAX_TIMEOUT_MS";
66
- var ZCODE_TURN_IDLE_TIMEOUT_MS = 18e5;
67
- var ZCODE_TURN_MAX_TIMEOUT_MS = 36e5;
68
- function parseZcodeTurnTimeoutEnv(raw) {
69
- if (raw === void 0 || raw === "") return { state: "unset" };
70
- const parsed = Number(raw);
71
- if (!Number.isFinite(parsed)) return { state: "invalid" };
72
- return { state: "valid", ms: parsed };
73
- }
74
- var ZCODE_SHARED_POOL_KEY = "shared";
75
- var ZCODE_APPSERVER_STOP_TIMEOUT_MS = 3e3;
76
- var ZCODE_APPSERVER_ABORT_GRACE_MS = 3e3;
77
- var ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING = -32603;
78
- var ZCODE_APPSERVER_ERR_BUSY_SESSION = -32010;
79
- var ZCODE_APPSERVER_HARVEST_GRACE_MS = 1e3;
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- ZCODE_ADAPTER_VERSION,
83
- ZCODE_APPSERVER_ABORT_GRACE_MS,
84
- ZCODE_APPSERVER_ERR_BUSY_SESSION,
85
- ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING,
86
- ZCODE_APPSERVER_HARVEST_GRACE_MS,
87
- ZCODE_APPSERVER_REQUEST_TIMEOUT_MS,
88
- ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS,
89
- ZCODE_APPSERVER_STDERR_TAIL_CHARS,
90
- ZCODE_APPSERVER_STOP_TIMEOUT_MS,
91
- ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS,
92
- ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS,
93
- ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS,
94
- ZCODE_CLI_DEFAULT_PATH,
95
- ZCODE_ENGINE_ID,
96
- ZCODE_ERROR_TAIL_CHARS,
97
- ZCODE_FALLBACK_DEFAULT_MODEL,
98
- ZCODE_HOST_DB_SUFFIX,
99
- ZCODE_KILL_GRACE_MS,
100
- ZCODE_SHARED_POOL_KEY,
101
- ZCODE_TURN_IDLE_TIMEOUT_ENV,
102
- ZCODE_TURN_IDLE_TIMEOUT_MS,
103
- ZCODE_TURN_MAX_TIMEOUT_ENV,
104
- ZCODE_TURN_MAX_TIMEOUT_MS,
105
- ZCODE_V2_CONFIG_PATH_SUFFIX,
106
- parseZcodeTurnTimeoutEnv
107
- });
@@ -1,135 +0,0 @@
1
- /** zcode 引擎的 registry key。 */
2
- declare const ZCODE_ENGINE_ID = "zcode";
3
- /** zcode 适配器版本(handle.adapterVersion 数据源——golden 样本对齐排查锚点)。 */
4
- declare const ZCODE_ADAPTER_VERSION = "2.0.0";
5
- /**
6
- * zcode CLI 缺省路径(12.4MB node bundle,不在 PATH——2026-08-25 实测)。
7
- * 组合根可用 deps.cliPath 覆盖(测试注入 / 未来安装形态变化)。
8
- */
9
- declare const ZCODE_CLI_DEFAULT_PATH = "/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs";
10
- /**
11
- * 唯一凭据源 config(桌面端登录态,zsub V2_CONFIG_PATH 同构)。
12
- * 为什么绝不读 ~/.zcode/cli/config.json 作为引擎侧凭据校验源:它不在 ZCode GUI
13
- * 管理面,可能残留历史验证配置(2026-08-25 事故:8/24 zsub 开发残留把默认模型
14
- * 劫持到失效 router 端点,turn 0 即 401);桌面端登录凭据落在 v2/config.json,
15
- * 是 zsub 生产验证过的凭据源。共享宿主 HOME 后引擎侧只读它做模型解析校验;
16
- * app-server 进程侧 CLI 只认 ~/.zcode/cli/config.json(GUI 从不写该文件),由
17
- * appserver-launcher 的 fs 拦截 wrapper 把对该文件的读取重定向为「真实文件 +
18
- * v2 provider 注入」内存合并(同 id 时 v2 整条优先)——凭据实际供数仍以 v2 为
19
- * 权威源,并非直接消费宿主 HOME 的原始 cli config。
20
- */
21
- declare const ZCODE_V2_CONFIG_PATH_SUFFIX: readonly [".zcode", "v2", "config.json"];
22
- /** zsub 同构的兜底缺省模型(v2 config 无 model.main 且 task 未指定时)。 */
23
- declare const ZCODE_FALLBACK_DEFAULT_MODEL = "builtin:bigmodel-coding-plan/GLM-5.3";
24
- /**
25
- * 宿主 HOME 下 zcode 会话 db 的相对位置(共享 HOME 形态的 handle.sessionRef.dbPath
26
- * 锚点——绝对路径 = join(os.homedir(), ...suffix);runtime 读侧用它做精确白名单,
27
- * 旧池时代 records 的相对 dbPath 仍按 poolKey 锚定兼容)。
28
- */
29
- declare const ZCODE_HOST_DB_SUFFIX: readonly [".zcode", "cli", "db", "db.sqlite"];
30
- /** 杀链 grace 窗口:SIGTERM 后等这么久再 SIGKILL(zsub 同构 5s;实测 SIGTERM→exit 仅 103ms)。 */
31
- declare const ZCODE_KILL_GRACE_MS = 5000;
32
- /** 错误信息里保留的 stdout 尾部长度(engine_run_failed 规格:够诊断、不刷屏)。 */
33
- declare const ZCODE_ERROR_TAIL_CHARS = 2000;
34
- /**
35
- * [R2] app-server 控制面请求默认超时(ms)。依据:旧 zsw 实现 REQUEST_TIMEOUT_MS=15s
36
- * (60+ fake-server 用例 + 真机 e2e 验证值)。
37
- */
38
- declare const ZCODE_APPSERVER_REQUEST_TIMEOUT_MS = 15000;
39
- /**
40
- * [R2] 连接崩溃错误信息附带的 stderr 尾部长度(字符)。设计 zcode-engine-appserver-
41
- * resident.md §3.1 失败路径 2 / §3.3 错误规格表「进程意外退出」行:stderr 尾 400 字符。
42
- */
43
- declare const ZCODE_APPSERVER_STDERR_TAIL_CHARS = 400;
44
- /**
45
- * [R2] stderr 滚动缓冲上限(字符):只保最近内容供崩溃诊断。旧 zsw 实现同值 2048。
46
- */
47
- declare const ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS = 2048;
48
- /**
49
- * [R3] 终态判定后 session/read 兜底拉取的超时(ms)。read 是全文权威来源(不变量 1
50
- * 的双来源之二),失败不抛——降级收尾帧/delta 聚合。旧 zsw 实现 READ_TIMEOUT_MS=5000。
51
- */
52
- declare const ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS = 5000;
53
- /**
54
- * [R3] 任务收尾 session/close 的控制面超时(ms,best-effort——失败只 warn 不抛)。
55
- * 旧 zsw 实现 RELEASE_CLOSE_TIMEOUT_MS=1500(wave2 D2,同值同语义)。
56
- */
57
- declare const ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS = 1500;
58
- /**
59
- * [R3 → superseded by P0-1] 旧「一轮终态等待」固定墙钟缺省值(ms)。**已被
60
- * `ZCODE_TURN_IDLE_TIMEOUT_MS`(idle 主判定)+ `ZCODE_TURN_MAX_TIMEOUT_MS`
61
- * (总上界兜底)两 timer 语义替换,session-channel 不再消费本值**——固定墙钟
62
- * 「到点=不可推进」判定被 2026-09 T001 深诊击穿(21% 活跃任务被误杀,见设计
63
- * timeout-zcode-turn-and-settled-watchdog.md §3.1/§4)。符号保留:audit/设计
64
- * 文档(timeout-audit-2026-09.md 等)以本名记录事故成因,删除即产生悬空引用。
65
- */
66
- declare const ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS = 300000;
67
- /** turn idle 主判定的 env 覆盖通道(>0 覆盖、≤0 关闭、非法值 warn+回落默认)。 */
68
- declare const ZCODE_TURN_IDLE_TIMEOUT_ENV = "XYZ_ZCODE_TURN_IDLE_TIMEOUT_MS";
69
- /** turn 总上界的 env 覆盖通道(语义同上;0=关闭后 chatty-wedge 无自动回收)。 */
70
- declare const ZCODE_TURN_MAX_TIMEOUT_ENV = "XYZ_ZCODE_TURN_MAX_TIMEOUT_MS";
71
- /**
72
- * [P0-1 D1] turn idle 主判定缺省阈值(ms):该 turn 任何事件到达刷新计时,连续
73
- * 静默达此值判「执行已不可推进」。活跃事件流零误杀(ADR-0047 逆否面)。默认
74
- * 30min 为先验值,⛔P-Z1 门(事件流 inter-event gap 分布)标定前用此默认。
75
- */
76
- declare const ZCODE_TURN_IDLE_TIMEOUT_MS = 1800000;
77
- /**
78
- * [P0-1 D1] turn 总上界缺省值(ms):从 openTurn 挂载起固定不刷新,兜 idle 覆盖
79
- * 不了的 chatty-wedge(事件持续但终态永不到达)。对超上界的合法极长任务是显式
80
- * 接受的残余误杀面(env 可调/可关 + 错误文案附自救指引)。默认 60min 为先验值
81
- * (T001 34 任务最长 541s,先验远离 6.6×),⛔P-Z0 门(任务总时长分布)标定前
82
- * 用此默认。
83
- */
84
- declare const ZCODE_TURN_MAX_TIMEOUT_MS = 3600000;
85
- /** `parseZcodeTurnTimeoutEnv` 的解析结果(可判别联合——valid 分支 ms 必有)。 */
86
- type ZcodeTurnTimeoutEnvParse = {
87
- state: "unset";
88
- } | {
89
- state: "valid";
90
- ms: number;
91
- } | {
92
- state: "invalid";
93
- };
94
- /**
95
- * 解析 turn 阈值 env 原始值(空串视同未设置,对齐 lifecycle-manager 先例的
96
- * `if (!raw)` 口径)。**与 `XYZ_SUBAGENT_IDLE_TIMEOUT_MS` 先例的刻意分歧(设计
97
- * D2/r3 SG-5 显式登记)**:先例 ≤0=非法回落且禁用后不认 env;本通道 ≤0=显式
98
- * 关闭该 timer(规则 19 的 opt-out 出路),非法(非数字)才回落默认——调用方
99
- * 必须对 invalid 与 ≤0 关闭分别 warn 留痕(生效行为可见,A10① 断言依据)。
100
- */
101
- declare function parseZcodeTurnTimeoutEnv(raw: string | undefined): ZcodeTurnTimeoutEnvParse;
102
- /**
103
- * 共享宿主 HOME 语义下的 journal 分组 key(与 pi 引擎 PI_POOL_KEY='shared' 同构):
104
- * journal 落 engineDataDir/engines/zcode/shared/journal-<taskId>.jsonl。无隔离池、
105
- * 无派生目录——key 是固定字面量,仅作 pool-manager 通用契约的分组锚点。
106
- */
107
- declare const ZCODE_SHARED_POOL_KEY = "shared";
108
- /**
109
- * [R4 D3] abort 链第一级:session/stop 的控制面超时(ms)。stop 失败/超时即落
110
- * killChain(协议此时已不可信)。
111
- */
112
- declare const ZCODE_APPSERVER_STOP_TIMEOUT_MS = 3000;
113
- /**
114
- * [R4 D3] abort 链第二级:stop 送达后的终态确认 grace 窗口(ms)。窗口内终态
115
- * 到达 → 不杀共享进程;超时 → killChain 连坐。
116
- */
117
- declare const ZCODE_APPSERVER_ABORT_GRACE_MS = 3000;
118
- /**
119
- * [R4] app-server 内部错误码中「模型配置缺失」的归类判据(A.3:-32603 内部错误族,
120
- * 消息含 "Model config is missing"——错误规格表第 2 行:报 engine_credential_missing)。
121
- */
122
- declare const ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING = -32603;
123
- /**
124
- * [R5] app-server 内部错误码「会话忙」:send 时该会话已有轮在跑(busy 不排队不打断)。
125
- * 单会话一任务是结构保证,运行中命中即 bug(错误文案引导上报 sessionId 与 state 流水)。
126
- */
127
- declare const ZCODE_APPSERVER_ERR_BUSY_SESSION = -32010;
128
- /**
129
- * [R5] 崩溃收割确认的兜底窗口(ms):killChain 在 `exit` 事件 resolve,而连接
130
- * finalize(onClose → 在途 turn 崩溃收割)挂 `close` 事件——channel 退订前等 onClose
131
- * 触发,本窗口兜底防 `close` 永不到达时 dispose 挂死。
132
- */
133
- declare const ZCODE_APPSERVER_HARVEST_GRACE_MS = 1000;
134
-
135
- export { ZCODE_ADAPTER_VERSION, ZCODE_APPSERVER_ABORT_GRACE_MS, ZCODE_APPSERVER_ERR_BUSY_SESSION, ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING, ZCODE_APPSERVER_HARVEST_GRACE_MS, ZCODE_APPSERVER_REQUEST_TIMEOUT_MS, ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS, ZCODE_APPSERVER_STDERR_TAIL_CHARS, ZCODE_APPSERVER_STOP_TIMEOUT_MS, ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS, ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS, ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS, ZCODE_CLI_DEFAULT_PATH, ZCODE_ENGINE_ID, ZCODE_ERROR_TAIL_CHARS, ZCODE_FALLBACK_DEFAULT_MODEL, ZCODE_HOST_DB_SUFFIX, ZCODE_KILL_GRACE_MS, ZCODE_SHARED_POOL_KEY, ZCODE_TURN_IDLE_TIMEOUT_ENV, ZCODE_TURN_IDLE_TIMEOUT_MS, ZCODE_TURN_MAX_TIMEOUT_ENV, ZCODE_TURN_MAX_TIMEOUT_MS, ZCODE_V2_CONFIG_PATH_SUFFIX, type ZcodeTurnTimeoutEnvParse, parseZcodeTurnTimeoutEnv };