@zhushanwen/subagent-core 0.2.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 (330) hide show
  1. package/README.md +114 -0
  2. package/dist/chunk-3VOERJPJ.js +22 -0
  3. package/dist/chunk-A4IVZWVX.js +31 -0
  4. package/dist/execution/engine/engines/zcode/constants.cjs +54 -0
  5. package/dist/execution/engine/engines/zcode/constants.d.cts +31 -0
  6. package/dist/execution/engine/engines/zcode/constants.d.ts +31 -0
  7. package/dist/execution/engine/engines/zcode/constants.js +22 -0
  8. package/dist/execution/engine/engines/zcode/reader.cjs +276 -0
  9. package/dist/execution/engine/engines/zcode/reader.d.cts +20 -0
  10. package/dist/execution/engine/engines/zcode/reader.d.ts +20 -0
  11. package/dist/execution/engine/engines/zcode/reader.js +239 -0
  12. package/dist/execution/engine/paths.cjs +55 -0
  13. package/dist/execution/engine/paths.d.cts +8 -0
  14. package/dist/execution/engine/paths.d.ts +8 -0
  15. package/dist/execution/engine/paths.js +26 -0
  16. package/dist/execution/relay-env.cjs +62 -0
  17. package/dist/execution/relay-env.d.cts +33 -0
  18. package/dist/execution/relay-env.d.ts +33 -0
  19. package/dist/execution/relay-env.js +20 -0
  20. package/dist/index.cjs +1852 -0
  21. package/dist/index.d.cts +1184 -0
  22. package/dist/index.d.ts +1184 -0
  23. package/dist/index.js +1810 -0
  24. package/dist/types-BxyAidGf.d.cts +875 -0
  25. package/dist/types-BxyAidGf.d.ts +875 -0
  26. package/package.json +99 -0
  27. package/src/__tests__/agent-opts-resolver-schema-prompt.test.ts +142 -0
  28. package/src/__tests__/append-system-prompt-assembly.test.ts +242 -0
  29. package/src/__tests__/builtin-workflows-structure.test.ts +180 -0
  30. package/src/__tests__/derive-closed-display-parity.test.ts +93 -0
  31. package/src/__tests__/fr4-get-state-handshake.test.ts +125 -0
  32. package/src/__tests__/fr8-orphan-recovery.test.ts +259 -0
  33. package/src/__tests__/m2-append-content-probe.test.ts +73 -0
  34. package/src/__tests__/manifest-store.test.ts +368 -0
  35. package/src/__tests__/record-store-cache.test.ts +335 -0
  36. package/src/__tests__/record-store-index.test.ts +560 -0
  37. package/src/__tests__/record-store-last-line.test.ts +129 -0
  38. package/src/__tests__/review-fix-loop-script.test.ts +288 -0
  39. package/src/__tests__/review-fix-loop-utils.test.ts +2377 -0
  40. package/src/__tests__/robustness-low-batch1.test.ts +286 -0
  41. package/src/__tests__/robustness-medium-batch1.test.ts +69 -0
  42. package/src/__tests__/robustness-medium-batch2.test.ts +65 -0
  43. package/src/__tests__/robustness-medium-batch3.test.ts +30 -0
  44. package/src/__tests__/robustness-medium-batch4.test.ts +358 -0
  45. package/src/__tests__/session-runner.test.ts +69 -0
  46. package/src/__tests__/smoke.test.ts +9 -0
  47. package/src/__tests__/stream-sink.test.ts +203 -0
  48. package/src/core/__tests__/host-services.test.ts +144 -0
  49. package/src/core/__tests__/logger.test.ts +78 -0
  50. package/src/core/__tests__/notify-ports.test.ts +104 -0
  51. package/src/core/host-services.ts +97 -0
  52. package/src/core/logger.ts +47 -0
  53. package/src/core/notify-ports.ts +126 -0
  54. package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +53 -0
  55. package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +1 -0
  56. package/src/execution/__tests__/agent-result-mapper.test.ts +150 -0
  57. package/src/execution/__tests__/alive-store.test.ts +147 -0
  58. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +490 -0
  59. package/src/execution/__tests__/channel-registry-handshake.test.ts +242 -0
  60. package/src/execution/__tests__/chat-engine-routing.test.ts +610 -0
  61. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +190 -0
  62. package/src/execution/__tests__/concurrency-pool.test.ts +250 -0
  63. package/src/execution/__tests__/config.test.ts +302 -0
  64. package/src/execution/__tests__/delivery-methods.test.ts +424 -0
  65. package/src/execution/__tests__/dialog-queue.test.ts +299 -0
  66. package/src/execution/__tests__/epipe-fallback.test.ts +241 -0
  67. package/src/execution/__tests__/execute-and-await-worktree.test.ts +243 -0
  68. package/src/execution/__tests__/execute-nesting.test.ts +323 -0
  69. package/src/execution/__tests__/execute-options-mapper.test.ts +200 -0
  70. package/src/execution/__tests__/execution-record.test.ts +1394 -0
  71. package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +171 -0
  72. package/src/execution/__tests__/finalize-record.test.ts +367 -0
  73. package/src/execution/__tests__/finalized-marker.test.ts +104 -0
  74. package/src/execution/__tests__/format-schema-instruction.test.ts +169 -0
  75. package/src/execution/__tests__/gc-timer.test.ts +184 -0
  76. package/src/execution/__tests__/get-record-for-action-restart.test.ts +254 -0
  77. package/src/execution/__tests__/helpers/mock-extension-api.ts +30 -0
  78. package/src/execution/__tests__/helpers/spawn-mock.ts +242 -0
  79. package/src/execution/__tests__/host-mode.test.ts +87 -0
  80. package/src/execution/__tests__/lifecycle-manager-lock.test.ts +211 -0
  81. package/src/execution/__tests__/lifecycle-manager.test.ts +383 -0
  82. package/src/execution/__tests__/lifecycle-predicates.test.ts +116 -0
  83. package/src/execution/__tests__/manifest-parentid.test.ts +117 -0
  84. package/src/execution/__tests__/model-resolver.test.ts +465 -0
  85. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +287 -0
  86. package/src/execution/__tests__/nested-visibility.test.ts +325 -0
  87. package/src/execution/__tests__/output-collector.test.ts +358 -0
  88. package/src/execution/__tests__/path-encoding.test.ts +104 -0
  89. package/src/execution/__tests__/pi-invocation.test.ts +134 -0
  90. package/src/execution/__tests__/record-store.test.ts +1057 -0
  91. package/src/execution/__tests__/records-cwd-isolation.test.ts +91 -0
  92. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +339 -0
  93. package/src/execution/__tests__/recursive-visibility-env.test.ts +273 -0
  94. package/src/execution/__tests__/relay-env.test.ts +42 -0
  95. package/src/execution/__tests__/resource-policy.test.ts +109 -0
  96. package/src/execution/__tests__/rpc-mode.test.ts +89 -0
  97. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +267 -0
  98. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +253 -0
  99. package/src/execution/__tests__/run-spawn-edges.test.ts +687 -0
  100. package/src/execution/__tests__/run-spawn-integration.test.ts +933 -0
  101. package/src/execution/__tests__/run-spawn-resume.test.ts +322 -0
  102. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +196 -0
  103. package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +199 -0
  104. package/src/execution/__tests__/session-context-resolver.test.ts +167 -0
  105. package/src/execution/__tests__/session-file-gc.test.ts +293 -0
  106. package/src/execution/__tests__/session-reconstructor.test.ts +379 -0
  107. package/src/execution/__tests__/session-runner-epipe.test.ts +178 -0
  108. package/src/execution/__tests__/session-runner-schema-env.test.ts +350 -0
  109. package/src/execution/__tests__/spawn-args.test.ts +445 -0
  110. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +189 -0
  111. package/src/execution/__tests__/spawn-event-adapter.test.ts +167 -0
  112. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +207 -0
  113. package/src/execution/__tests__/spawned-children.test.ts +92 -0
  114. package/src/execution/__tests__/start-sync-model-guard.test.ts +150 -0
  115. package/src/execution/__tests__/stdin-writer.test.ts +462 -0
  116. package/src/execution/__tests__/stream-sink-retirement.test.ts +261 -0
  117. package/src/execution/__tests__/subagent-service-abort.test.ts +60 -0
  118. package/src/execution/__tests__/subagent-service-message-close.test.ts +629 -0
  119. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +180 -0
  120. package/src/execution/__tests__/subagent-service.test.ts +788 -0
  121. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +310 -0
  122. package/src/execution/__tests__/subprocess-agent-runner.test.ts +612 -0
  123. package/src/execution/__tests__/temp-prompt.test.ts +53 -0
  124. package/src/execution/__tests__/timeout-integration.test.ts +615 -0
  125. package/src/execution/__tests__/tombstone-store.test.ts +73 -0
  126. package/src/execution/__tests__/turn-limiter-semantics.test.ts +194 -0
  127. package/src/execution/__tests__/turn-limiter.test.ts +65 -0
  128. package/src/execution/__tests__/ui-channels.test.ts +187 -0
  129. package/src/execution/__tests__/ui-interaction-model.test.ts +67 -0
  130. package/src/execution/__tests__/ui-request-handler-factory.test.ts +369 -0
  131. package/src/execution/__tests__/ui-request-handler.test.ts +204 -0
  132. package/src/execution/__tests__/ui-request-observability.test.ts +113 -0
  133. package/src/execution/__tests__/ui-request-queue.test.ts +133 -0
  134. package/src/execution/__tests__/worktree-manager.test.ts +633 -0
  135. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +229 -0
  136. package/src/execution/__tests__/worktree-reconcile.integration.test.ts +181 -0
  137. package/src/execution/__tests__/worktree-registry.test.ts +199 -0
  138. package/src/execution/agent-registry.ts +199 -0
  139. package/src/execution/agent-result-mapper.ts +90 -0
  140. package/src/execution/alive-store.ts +119 -0
  141. package/src/execution/argv-mirror.ts +113 -0
  142. package/src/execution/best-effort.ts +38 -0
  143. package/src/execution/channel-registry-access.ts +144 -0
  144. package/src/execution/concurrency-pool.ts +116 -0
  145. package/src/execution/config.ts +165 -0
  146. package/src/execution/dialog-queue.ts +330 -0
  147. package/src/execution/engine/__tests__/common/data-dir.test.ts +78 -0
  148. package/src/execution/engine/__tests__/common/errors.test.ts +132 -0
  149. package/src/execution/engine/__tests__/common/event-journal.test.ts +177 -0
  150. package/src/execution/engine/__tests__/common/kill-chain.test.ts +192 -0
  151. package/src/execution/engine/__tests__/common/nesting-guard.test.ts +81 -0
  152. package/src/execution/engine/__tests__/common/persona-router.test.ts +123 -0
  153. package/src/execution/engine/__tests__/common/pool-manager.test.ts +154 -0
  154. package/src/execution/engine/__tests__/common/schema-emulation.test.ts +128 -0
  155. package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +28 -0
  156. package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +141 -0
  157. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +109 -0
  158. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +101 -0
  159. package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +77 -0
  160. package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +104 -0
  161. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +201 -0
  162. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +76 -0
  163. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +79 -0
  164. package/src/execution/engine/__tests__/engine-discovery.test.ts +87 -0
  165. package/src/execution/engine/__tests__/model-prompt.test.ts +197 -0
  166. package/src/execution/engine/__tests__/paths.test.ts +39 -0
  167. package/src/execution/engine/__tests__/registry.test.ts +120 -0
  168. package/src/execution/engine/__tests__/routing.test.ts +231 -0
  169. package/src/execution/engine/common/data-dir.ts +66 -0
  170. package/src/execution/engine/common/errors.ts +183 -0
  171. package/src/execution/engine/common/event-journal.ts +254 -0
  172. package/src/execution/engine/common/journal-replay.ts +62 -0
  173. package/src/execution/engine/common/kill-chain.ts +221 -0
  174. package/src/execution/engine/common/nesting-guard.ts +50 -0
  175. package/src/execution/engine/common/persona-router.ts +108 -0
  176. package/src/execution/engine/common/pool-manager.ts +226 -0
  177. package/src/execution/engine/common/schema-emulation.ts +189 -0
  178. package/src/execution/engine/common/session-view-projection.ts +51 -0
  179. package/src/execution/engine/engine-discovery.ts +65 -0
  180. package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +469 -0
  181. package/src/execution/engine/engines/pi/__tests__/reader.test.ts +155 -0
  182. package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +164 -0
  183. package/src/execution/engine/engines/pi/pi-engine.ts +415 -0
  184. package/src/execution/engine/engines/pi/reader.ts +48 -0
  185. package/src/execution/engine/engines/pi/registration.ts +35 -0
  186. package/src/execution/engine/engines/pi/task-spec-mapper.ts +100 -0
  187. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +39 -0
  188. package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +150 -0
  189. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +246 -0
  190. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +228 -0
  191. package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +210 -0
  192. package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +71 -0
  193. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +127 -0
  194. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +580 -0
  195. package/src/execution/engine/engines/zcode/constants.ts +43 -0
  196. package/src/execution/engine/engines/zcode/golden-sample.ts +39 -0
  197. package/src/execution/engine/engines/zcode/launcher.ts +161 -0
  198. package/src/execution/engine/engines/zcode/parser.ts +436 -0
  199. package/src/execution/engine/engines/zcode/preparer.ts +363 -0
  200. package/src/execution/engine/engines/zcode/reader.ts +381 -0
  201. package/src/execution/engine/engines/zcode/registration.ts +37 -0
  202. package/src/execution/engine/engines/zcode/zcode-engine.ts +658 -0
  203. package/src/execution/engine/host-task-spec.ts +47 -0
  204. package/src/execution/engine/model-prompt.ts +158 -0
  205. package/src/execution/engine/paths.ts +42 -0
  206. package/src/execution/engine/port.ts +153 -0
  207. package/src/execution/engine/registry.ts +133 -0
  208. package/src/execution/engine/routing.ts +218 -0
  209. package/src/execution/engine/types.ts +309 -0
  210. package/src/execution/execute-options-mapper.ts +115 -0
  211. package/src/execution/execution-record.ts +984 -0
  212. package/src/execution/finalize-record.ts +254 -0
  213. package/src/execution/finalized-marker.ts +70 -0
  214. package/src/execution/get-state-handshake.ts +104 -0
  215. package/src/execution/host-mode.ts +56 -0
  216. package/src/execution/idle-gc.ts +47 -0
  217. package/src/execution/lifecycle-manager.ts +513 -0
  218. package/src/execution/lifecycle-predicates.ts +65 -0
  219. package/src/execution/manifest-store.ts +256 -0
  220. package/src/execution/model-config-service.ts +250 -0
  221. package/src/execution/model-resolver.ts +248 -0
  222. package/src/execution/notifier.ts +372 -0
  223. package/src/execution/notify-ledger.ts +580 -0
  224. package/src/execution/output-collector.ts +228 -0
  225. package/src/execution/path-encoding.ts +60 -0
  226. package/src/execution/pi-invocation.ts +120 -0
  227. package/src/execution/record-entry.ts +132 -0
  228. package/src/execution/record-store.ts +1265 -0
  229. package/src/execution/relay-env.ts +37 -0
  230. package/src/execution/session-context-resolver.ts +64 -0
  231. package/src/execution/session-file-gc.ts +120 -0
  232. package/src/execution/session-pending.ts +170 -0
  233. package/src/execution/session-reconstructor.ts +678 -0
  234. package/src/execution/session-runner.ts +1789 -0
  235. package/src/execution/sessions-index.ts +304 -0
  236. package/src/execution/spawn-event-adapter.ts +363 -0
  237. package/src/execution/stdin-writer.ts +198 -0
  238. package/src/execution/stream-sink.ts +126 -0
  239. package/src/execution/subagent-service.ts +2268 -0
  240. package/src/execution/subprocess-agent-runner.ts +317 -0
  241. package/src/execution/temp-prompt.ts +62 -0
  242. package/src/execution/tombstone-store.ts +72 -0
  243. package/src/execution/turn-limiter.ts +102 -0
  244. package/src/execution/types.ts +1023 -0
  245. package/src/execution/ui-channels.ts +216 -0
  246. package/src/execution/ui-interaction-model.ts +48 -0
  247. package/src/execution/ui-request-handler-factory.ts +243 -0
  248. package/src/execution/ui-request-observability.ts +81 -0
  249. package/src/execution/ui-request-queue.ts +184 -0
  250. package/src/execution/worktree-manager.ts +688 -0
  251. package/src/execution/worktree-registry.ts +279 -0
  252. package/src/index.ts +87 -0
  253. package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +349 -0
  254. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +202 -0
  255. package/src/orchestration/__tests__/agent-call-stream.test.ts +152 -0
  256. package/src/orchestration/__tests__/args-validator.test.ts +143 -0
  257. package/src/orchestration/__tests__/config-loader.test.ts +503 -0
  258. package/src/orchestration/__tests__/error-recovery-handlers.test.ts +809 -0
  259. package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +404 -0
  260. package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +56 -0
  261. package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +166 -0
  262. package/src/orchestration/__tests__/execute-agent-call.test.ts +451 -0
  263. package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +600 -0
  264. package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +96 -0
  265. package/src/orchestration/__tests__/lifecycle.test.ts +659 -0
  266. package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +95 -0
  267. package/src/orchestration/__tests__/review-fix-loop-scriptpath-failfast.test.ts +183 -0
  268. package/src/orchestration/__tests__/script-lint.test.ts +831 -0
  269. package/src/orchestration/__tests__/skill-discovery.test.ts +210 -0
  270. package/src/orchestration/__tests__/test-mocks.ts +197 -0
  271. package/src/orchestration/__tests__/worker-exit-without-result.test.ts +368 -0
  272. package/src/orchestration/__tests__/worker-host.test.ts +120 -0
  273. package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +164 -0
  274. package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +563 -0
  275. package/src/orchestration/__tests__/worker-script-builder.test.ts +309 -0
  276. package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +129 -0
  277. package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +317 -0
  278. package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +110 -0
  279. package/src/orchestration/agent-opts-resolver.ts +174 -0
  280. package/src/orchestration/args-validator.ts +127 -0
  281. package/src/orchestration/config-loader.ts +316 -0
  282. package/src/orchestration/error-recovery.ts +1018 -0
  283. package/src/orchestration/execute-agent-call.ts +256 -0
  284. package/src/orchestration/launcher.ts +455 -0
  285. package/src/orchestration/lifecycle.ts +399 -0
  286. package/src/orchestration/models/__tests__/budget.test.ts +307 -0
  287. package/src/orchestration/models/agent-call.ts +83 -0
  288. package/src/orchestration/models/budget.ts +118 -0
  289. package/src/orchestration/models/ports.ts +164 -0
  290. package/src/orchestration/models/run-runtime.ts +104 -0
  291. package/src/orchestration/models/run-spec.ts +83 -0
  292. package/src/orchestration/models/run-state.ts +44 -0
  293. package/src/orchestration/models/trace.ts +183 -0
  294. package/src/orchestration/models/types.ts +301 -0
  295. package/src/orchestration/models/workflow-run.ts +254 -0
  296. package/src/orchestration/models/workflow-script-registry.ts +35 -0
  297. package/src/orchestration/models/workflow-script.ts +117 -0
  298. package/src/orchestration/script-lint.ts +766 -0
  299. package/src/orchestration/skill-discovery.ts +135 -0
  300. package/src/orchestration/worker-handle.ts +115 -0
  301. package/src/orchestration/worker-host.ts +98 -0
  302. package/src/orchestration/worker-script-builder.ts +421 -0
  303. package/src/orchestration/workflow-files.ts +85 -0
  304. package/src/orchestration/workflow-script-registry-impl.ts +133 -0
  305. package/src/shared/__tests__/agent-ref.test.ts +34 -0
  306. package/src/shared/__tests__/meta-parser.test.ts +304 -0
  307. package/src/shared/__tests__/model-ref.test.ts +306 -0
  308. package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +288 -0
  309. package/src/shared/__tests__/resource-discovery.test.ts +749 -0
  310. package/src/shared/__tests__/resource-meta.test.ts +51 -0
  311. package/src/shared/__tests__/schema-jsonify.test.ts +81 -0
  312. package/src/shared/__tests__/timer-delay.test.ts +61 -0
  313. package/src/shared/agent-event.ts +13 -0
  314. package/src/shared/agent-ref.ts +57 -0
  315. package/src/shared/meta-parser.ts +261 -0
  316. package/src/shared/model-ref.ts +286 -0
  317. package/src/shared/resource-discovery.ts +835 -0
  318. package/src/shared/resource-meta.ts +65 -0
  319. package/src/shared/schema-env.ts +44 -0
  320. package/src/shared/schema-jsonify.ts +58 -0
  321. package/src/shared/timer-delay.ts +54 -0
  322. package/src/shared/xml-injection.ts +35 -0
  323. package/workflows/README.md +81 -0
  324. package/workflows/_shared/agent-refs.cjs +40 -0
  325. package/workflows/chain.js +137 -0
  326. package/workflows/map-reduce.js +180 -0
  327. package/workflows/parallel.js +154 -0
  328. package/workflows/review-fix-loop-utils.cjs +1542 -0
  329. package/workflows/review-fix-loop.js +1605 -0
  330. package/workflows/scatter-gather.js +184 -0
@@ -0,0 +1,875 @@
1
+ /**
2
+ * 唯一执行状态。所有路径共用。v4 B-1 两态收敛:旧 idle 折入 running、
3
+ * 旧 cancelled 折入 closed(closedReason='cancelled' 区分)。
4
+ *
5
+ * running = 活跃态。含两种子态(由派生谓词区分,见 lifecycle-predicates.ts):
6
+ * - 对话模式等待续聊(旧 idle):进程可能保活(isIdle=hasIdleTimer)或已回收
7
+ * 待冷路径 resume(isResumable=running && 无活进程句柄)。
8
+ * - 正在执行(有活进程句柄)。
9
+ *
10
+ * closed = 统一终态(done/failed/crashed/cancelled 合并)。具体关闭原因由
11
+ * {@link ClosedReason} 子枚举表达(如 user-close / gc / cancelled / parent-shutdown)。
12
+ * ExecutionRecord.closedReason 携带 L2 原因,投影层按需派生对外语义(error / ended)。
13
+ */
14
+ type ExecutionStatus = "running" | "closed";
15
+ /**
16
+ * closed 终态的 L2 关闭原因子枚举。
17
+ *
18
+ * 与 ExecutionStatus="closed" 配合使用,表达「为什么关闭」:
19
+ * parent-shutdown — 父进程 session_shutdown 时回收子进程
20
+ * parent-fork — 父进程 fork 新 session 时清理旧子进程
21
+ * parent-new — 父进程创建新 subagent 时清理旧子进程
22
+ * user-close — 用户手动 close action(含对话模式 close)
23
+ * cancelled — 用户取消(close(force:true) / cancelBackground)
24
+ * gc — 通用完成/失败(一次执行自然结束、超时、错误等无专属 reason 的终态)
25
+ * disconnected — .finalized sidecar 存在但无 reason 内容(磁盘重建兜底):
26
+ * 正常结束但死因不可考——旧格式 sidecar(v8.5 前写入的是空文件)、
27
+ * 或外部工具手工创建。替代旧的误导性 "gc" 兜底(自然完成 vs 断联
28
+ * 不分),message/fork-from 据此给出可行动指引。
29
+ */
30
+ type ClosedReason = 'parent-shutdown' | 'parent-fork' | 'parent-new' | 'user-close' | 'cancelled' | 'gc' | 'disconnected';
31
+ /**
32
+ * 终态三态对外语义(U3 C-outcome 一等披露)。
33
+ *
34
+ * 由 completeRecord 唯一写入点按 deriveOutcome 一次计算(判定顺序:cancelled 优先
35
+ * → error 非空 → completed),消费方(project/list/notify 文案/渲染器)只读本字段,
36
+ * 不再各自手写成败推导 switch(三处同构 switch 已随 U3 收敛删除)。
37
+ *
38
+ * [D6 显式取舍] parent-shutdown/parent-fork/parent-new 合成关闭(subagent-service
39
+ * disposeAllRecords 合成 result 恒写 error:"closed due to ...")落 "failed"——语义为
40
+ * 「父进程关闭时子 agent 未完成即失败」,选定行为而非疏漏,勿当 bug 改回 cancelled。
41
+ */
42
+ type ExecutionOutcome = "completed" | "failed" | "cancelled";
43
+ /** 执行模式。background = 调用方立即拿 handle 返回,子 agent 在 detached promise 里跑。 */
44
+ type ExecutionMode = "background";
45
+ /**
46
+ * Pi session.subscribe 上报的事件。Runtime 把它喂给 updateFromEvent。
47
+ *
48
+ * 设计:AgentEvent 携带 updateFromEvent 收口进 record 所需的**全部数据**——
49
+ * tool_end 带 result(供 turn.toolCalls 存完整 ToolCall),无需翻译层旁路累积。
50
+ *
51
+ * ACP 词汇对照(D11 注记级校准,零行为变更;新引擎实现者按本表对齐语义,
52
+ * 详见 docs/architecture/subagent-engine-gui-visibility.md §3.3 D11):
53
+ * text_delta / thinking_delta ↔ ACP content blocks(text / thinking)
54
+ * tool_start / tool_end ↔ ACP tool_call / tool_call_update
55
+ * turn_end / message_end ↔ ACP prompt turn 终态(stop_reason + usage)
56
+ * compaction ↔ ACP session/compaction
57
+ * 本协议以 pi 为语义锚点(D3)——命名不迁移,对照表仅保证未来 AcpEngine 适配器
58
+ * 与跨引擎 trace 映射的翻译成本最低。
59
+ */
60
+ type AgentEvent = {
61
+ type: "tool_start";
62
+ toolName: string;
63
+ args?: unknown;
64
+ } | {
65
+ type: "tool_end";
66
+ toolName: string;
67
+ args?: unknown;
68
+ result?: ToolCallResult;
69
+ isError?: boolean;
70
+ } | {
71
+ type: "text_delta";
72
+ delta: string;
73
+ } | {
74
+ type: "thinking_delta";
75
+ delta: string;
76
+ } | {
77
+ type: "turn_end";
78
+ summary?: string;
79
+ } | {
80
+ type: "message_end";
81
+ usage?: AgentUsage$1;
82
+ error?: string;
83
+ } | {
84
+ type: "compaction";
85
+ } | {
86
+ type: "error";
87
+ message: string;
88
+ };
89
+ /** token 用量(message_end 时由 Core 累加进 record.totalTokens)。 */
90
+ interface AgentUsage$1 {
91
+ input: number;
92
+ output: number;
93
+ cacheRead: number;
94
+ cacheWrite: number;
95
+ /** 本 message 的成本(USD,来自 SDK usage.cost.total)。可选——无成本数据时缺省。 */
96
+ cost?: number;
97
+ }
98
+ interface AgentUsageTotal extends AgentUsage$1 {
99
+ /** 上述四项之和。投影时不再手工求和。 */
100
+ total: number;
101
+ /** 累计成本(USD,来自 SdkEvent.message.usage.cost.total 求和)。无成本数据时为 0。 */
102
+ cost: number;
103
+ }
104
+ /** tool 调用结果(tool_execution_end 时累积,含 structured-output 的 details)。 */
105
+ interface ToolCallResult {
106
+ content?: unknown[];
107
+ details?: unknown;
108
+ }
109
+ /**
110
+ * tool 调用(导出的纯净数据形状,不含内部状态)。
111
+ *
112
+ * tool_start 到达但 tool_end 未到时,调用为进行中;一旦 tool_end 到达,
113
+ * result/isError 填充完成。对外投影(AgentResult.toolCalls / getAllToolCalls)
114
+ * 一律返回此类型——**不泄漏 running/done/failed 内部状态机**。
115
+ *
116
+ * 进行中状态由 execution-record 内部的 `InternalToolCall`(= ToolCall + _status)承载,
117
+ * 只存在于 record.turns[].toolCalls,跨边界导出时由 getAllToolCalls strip _status。
118
+ */
119
+ interface ToolCall {
120
+ toolName: string;
121
+ args?: unknown;
122
+ result?: ToolCallResult;
123
+ isError?: boolean;
124
+ }
125
+ /**
126
+ * 内部 ToolCall:在 ToolCall 基础上追加 _status 进行中状态标记与 startedTs 时间戳。
127
+ *
128
+ * running = tool_start 已收到但 tool_end 未到;
129
+ * done/failed = tool_end 已到。
130
+ *
131
+ * 仅存在于 ExecutionRecord.turns[].toolCalls(Core 内部可变状态)。
132
+ * 跨边界导出(getAllToolCalls → AgentResult.toolCalls / 持久化)由 getAllToolCalls
133
+ * 映射回 ToolCall(丢弃 _status / startedTs),保证导出形状清洁。
134
+ */
135
+ interface InternalToolCall extends ToolCall {
136
+ _status: "running" | "done" | "failed";
137
+ /** tool_start 到达时的墙钟时间戳(Date.now(),ms)。getEventLog 派生 tool 条目 ts 用。 */
138
+ startedTs: number;
139
+ }
140
+ /**
141
+ * 一个 turn 的完整内容(ExecutionRecord.turns[] 的元素)。
142
+ *
143
+ * 收口设计:text/thinking 流式累积**完整内容**(非 100 字切片),
144
+ * toolCalls 存完整 ToolCall(含 result + _status 内部状态)。turn_end 到达后 closed=true,
145
+ * 下次 text/thinking/tool 时开新 turn。
146
+ *
147
+ * eventLog / currentActivity / result 均从 turns[] 派生,不再独立存储。
148
+ */
149
+ interface Turn {
150
+ /** 本 turn assistant 正文(text_delta 流式累积,完整)。 */
151
+ text: string;
152
+ /** 本 turn 推理(thinking_delta 流式累积,完整)。 */
153
+ thinking: string;
154
+ /** 本 turn 工具调用(InternalToolCall:含完整 result + _status 进行中标记)。 */
155
+ toolCalls: InternalToolCall[];
156
+ /** 本 turn message_end 的 token 增量(聚合得 totalUsage)。 */
157
+ usageDelta?: AgentUsage$1;
158
+ /** turn_end 是否已到达。false=正在进行;true=已闭合,下次内容开新 turn。 */
159
+ closed: boolean;
160
+ /** turn_end 到达时的墙钟时间戳(Date.now(),ms)。getEventLog 派生 turn_end 条目 ts 用。 */
161
+ closedTs?: number;
162
+ }
163
+ /** 一次 session 执行的完整结果。collectResult 产出,写入 Record.outcome。 */
164
+ interface AgentResult$1 {
165
+ text: string;
166
+ turns: number;
167
+ durationMs: number;
168
+ success: boolean;
169
+ error?: string;
170
+ sessionId: string;
171
+ toolCalls: ToolCall[];
172
+ usage?: AgentUsageTotal;
173
+ /** /resume /fork 可恢复的 session 文件名(不含目录)。 */
174
+ sessionFile?: string;
175
+ /** schema 模式下,structured-output tool 的 result.details(已通过 schema 校验)。 */
176
+ parsedOutput?: unknown;
177
+ }
178
+ /**
179
+ * worktree handle 值对象。仅 worktree:true 时持有——worktree 是独立维度,
180
+ * 需显式开启,fork alone 不创建 worktree。
181
+ * Object.freeze 守卫保证不可变。
182
+ */
183
+ interface WorktreeHandle {
184
+ /** checkout 目录(子 agent 工作目录,tmpdir 下)。 */
185
+ readonly path: string;
186
+ readonly branch: string;
187
+ readonly baseCommit: string;
188
+ /** 主仓库根目录(cleanup/scan 需要,不再靠路径反推)。 */
189
+ readonly mainCwd: string;
190
+ }
191
+ /**
192
+ * 所有执行路径的唯一状态源。
193
+ *
194
+ * 收口设计:一次执行的完整内容(text/thinking/toolCalls/usage)按 turn 收口在
195
+ * `turns: Turn[]` 里。eventLog / currentActivity / result 文本均从 turns[] 派生
196
+ * (getEventLog / getCurrentActivity / getFullText),不再独立存储切片或缓冲。
197
+ *
198
+ * 生命周期:createRecord() 创建 → updateFromEvent() 实时更新(累积进 turns)→
199
+ * completeRecord() 冻结 → archive 立即移出内存(读时从 session.jsonl 重建)。
200
+ *
201
+ * TUI 永远拿 RecordSnapshot(.slice() 快照),不直接持此可变对象。
202
+ */
203
+ interface ExecutionRecord {
204
+ /** 唯一 ID(sync: "run-N",bg: "bg-N-xxx")。 */
205
+ readonly id: string;
206
+ readonly agent: string;
207
+ readonly model: string;
208
+ readonly thinkingLevel: string | undefined;
209
+ readonly mode: ExecutionMode;
210
+ readonly task: string;
211
+ /**
212
+ * 人类可读的短标签(≤35 字符),简述本次 subagent「在做什么」。
213
+ * 区别于 agent(类型名)/ task(完整 prompt)。旧持久化 record 反序列化时缺失兜底空串。
214
+ */
215
+ readonly slug: string;
216
+ readonly startedAt: number;
217
+ /** 根 Pi session ID(session 隔离过滤用)。递归链上所有层 record 同值。 */
218
+ readonly rootSessionId: string | undefined;
219
+ /** 直接父 subagent record ID(层级树构建用)。顶层 record 为 undefined。 */
220
+ readonly parentRecordId: string | undefined;
221
+ /** subagent 递归深度。顶层(主 session 直接创建)=0,每层嵌套 +1。 */
222
+ readonly depth: number;
223
+ /**
224
+ * 对话模式标志(可持续对话 subagent)。true = 轮次完成进 idle 态(保留 record +
225
+ * worktree)等待续聊,而非一次性终态化。
226
+ * undefined/false = 一次性模式(默认,行为完全不变)。
227
+ * 向后兼容:旧 record / 旧 session 文件无此字段,按一次性模式处理。
228
+ */
229
+ readonly chatMode?: boolean;
230
+ /**
231
+ * 执行态信号(residual-fixes 设计):true = 该 record 无活进程驱动(轮终 idle /
232
+ * 重建孤儿兜底),处于「可续聊/等续聊」态——不是后台真在跑。轮终迁移
233
+ * (doFinalizeRoundToIdle)置 true,冷路径续轮(进程启动)清除;GUI 侧
234
+ * streaming/waiting 细分与 hasRunning 判据消费。缺省 falsy = 有进程或旧数据。
235
+ */
236
+ resumable?: boolean;
237
+ /**
238
+ * 空闲超时毫秒数(仅 chatMode 有意义)。覆盖默认 5min idle timeout。
239
+ * 优先级:参数 > env XYZ_SUBAGENT_IDLE_TIMEOUT_MS > 默认 300000ms。
240
+ * 向后兼容:旧 record 无此字段,按默认值处理。
241
+ */
242
+ readonly idleTimeoutMs?: number;
243
+ /**
244
+ * 实际执行引擎 id(P4 路由留痕,D9①)。创建时确定不可变;缺省(存量 record)
245
+ * = pi 投影(消费方零迁移)。持久化经 subagent-record entry。
246
+ */
247
+ readonly engine?: string;
248
+ /**
249
+ * 引擎 fallback 留痕(D9①:probe 失败路由回默认引擎)。GUI 警告条数据源;
250
+ * 缺省 = 无 fallback。持久化经 subagent-record entry。
251
+ */
252
+ readonly engineFallback?: {
253
+ from: string;
254
+ reason: string;
255
+ };
256
+ /**
257
+ * 引擎自描述定位符(U2:非 pi run resolve 后回填、终态迁移落 entry 前——run 前
258
+ * 缺省不可用)。sessionRef 整体透传(失败终态 sessionId 缺失时仍回填已有部分,
259
+ * 读侧①级降②级的防御形态);journalPath 为 retarget 后实际落盘路径。pi 分支不
260
+ * 回填(sessionFile 即定位符)。持久化经 subagent-record entry。
261
+ */
262
+ engineHandle?: {
263
+ sessionRef: Record<string, string>;
264
+ journalPath?: string;
265
+ poolKey: string;
266
+ };
267
+ status: ExecutionStatus;
268
+ /** L2 关闭原因子枚举(仅 status="closed" 时有意义)。表达「为什么关闭」。
269
+ * 由 tryTransition(record, "closed", reason) 写入;投影层按需派生对外语义。
270
+ * 向后兼容:旧 record 无此字段,按 gc 处理(通用完成/失败)。 */
271
+ closedReason?: ClosedReason;
272
+ /**
273
+ * 终态三态对外语义(U3 C-outcome)。completeRecord 唯一写入点按 deriveOutcome
274
+ * 一次计算,消费方只读本字段不再自行推导。向后兼容:旧 record / 磁盘重建
275
+ * record 无此字段,投影层按 projectOutcome 兜底(closed-legacy 语义)。
276
+ */
277
+ outcome?: ExecutionOutcome;
278
+ /** 完整执行内容,按 turn 组织。createRecord 初始化为 [空 turn]。 */
279
+ turns: Turn[];
280
+ /** turn 计数(= turns.filter(closed).length,冗余存储供投影直接读)。 */
281
+ turnCount: number;
282
+ totalTokens: number;
283
+ /** 运行期最近一次 error 事件的消息(getEventLog 派生 error 条目用)。 */
284
+ lastError: string | undefined;
285
+ /**
286
+ * 对话轮次计数(仅 chatMode 有意义)。首轮运行时 = 0;每完成一轮(finalizeRoundToIdle
287
+ * 进 idle)+1。undefined 时视为 0。非 chatMode 不自增。
288
+ */
289
+ round?: number;
290
+ /**
291
+ * [增量通知] 当前轮次增量的 turns[] 起始下标(仅 chatMode 有意义;内存态记账,D4 不持久化)。
292
+ *
293
+ * - 生命周期:undefined 视为 0(首轮增量 = 全量,与改造前首轮通知逐字节一致,向后兼容旧
294
+ * record);唯一写点 onRoundSettled 第 5 步(notify 之后推进),唯一读点同回调第 2 步
295
+ * (`getFullTextFrom(record, record.roundBaseTurnIndex ?? 0)`)。非 chatMode 恒
296
+ * undefined(onRoundSettled 是 session-runner chatMode 分支专属回调)。
297
+ * - D1 滞后空 turn 防丢文本(防御性):pi 当前事件序下该形态不可达——带 usage 的
298
+ * message_end 恒先于 turn_end(@earendil-works/pi-agent-core dist/agent-loop.js
299
+ * :240/:253/:547 三处 message_end emit 均在 :131 正常路径 turn_end 之前),settle 时
300
+ * turn 全闭合。防 pi 未来事件序变化:若 settle 时刻末 turn 是滞后 message_end 开出的
301
+ * 空 turn(execution-record.ts message_end 分支经 currentTurn,需同时过两层 usage 守卫:
302
+ * session-runner.ts 转发层 `if (msg?.usage)`(bare message_end 不转发)+ execution-record.ts
303
+ * 累积层 `if (event.usage)`(bare message_end 不开 turn)),推进公式
304
+ * nextRoundBaseTurnIndex 把它留在下一轮增量内(新轮首个 text_delta 经 currentTurn 复用该
305
+ * 空 turn,复用累积被 slice 覆盖);直用 turns.length 推进会把下轮首段文本挤出 slice
306
+ * 范围静默丢失。
307
+ * - D4 不持久化:磁盘重建走 createRecord(turns 仅为初始 [emptyTurn()]),base=0 对空 turn
308
+ * 的增量派生等价为空、天然产出仅新轮增量,持久化是死数据。故不写 manifest、不参与重建。
309
+ * - pi 内部序锚定依据(R1 mitigation):@earendil-works/pi-agent-core 0.84.2
310
+ * dist/agent-loop.js :108-111(error/aborted stopReason 也先 emit turn_end 再 agent_end)
311
+ * 与 :131(正常路径 turn_end 收尾);agent_settled 在 agent_end 之后 emit,故未闭合
312
+ * turn 只可能来自滞后事件。pi 升级若改变 turn_end/agent_end 时序,onRoundSettled 推进前
313
+ * 的观测哨(末 turn 未闭合且 text 非空 → logger.warn)会留痕。
314
+ */
315
+ roundBaseTurnIndex?: number;
316
+ /**
317
+ * record 进入 idle 态的时间戳(ms)。finalizeRoundToIdle 设值;GC 定时器据此计算
318
+ * 剩余 TTL。undefined = 非 idle 态(running/closed/cancelled)或旧 record 缺失字段。
319
+ */
320
+ idleSince?: number;
321
+ /**
322
+ * close 优雅关闭标志(M2-B3)。chatMode record 运行中调 `close {force:false}` 时置 true;
323
+ * runAndFinalize 的 done 分流检查此标志——true 则终态化为 done(而非进 idle),并清标志。
324
+ * undefined/false = 正常 idle 分流(对话模式轮次完成进 idle 等续聊)。
325
+ * 仅 chatMode + running 时有意义;force:true(立即终止)不走此标志。
326
+ */
327
+ closeAfterRound?: boolean;
328
+ endedAt: number | undefined;
329
+ result: string | undefined;
330
+ error: string | undefined;
331
+ /** 完整 AgentResult(含 usage/toolCalls,完成时填)。 */
332
+ agentResult: AgentResult$1 | undefined;
333
+ /** session jsonl 文件名。session 创建成功后由 session-runner.run() 回填(窗口期内 undefined)。 */
334
+ sessionFile?: string;
335
+ /**
336
+ * [V2 决策 3] 子进程 pid(spawn 后由 session-runner 回填到内存 record)。
337
+ *
338
+ * 用于 lifecycle-manager 孤儿扫描(V2 §5.2 职责 4:父进程重启时按持久化 pid 扫收
339
+ * 上次崩溃遗留的孤儿)。本字段仅在内存记账,持久化留 Step 5(record
340
+ * 文件写入 pid + 启动时 scanOrphanProcesses 消费)。undefined = 尚未 spawn / 已退出。
341
+ * 向后兼容:旧 record 无此字段,按无 pid 处理(孤儿扫描跳过)。
342
+ */
343
+ pid?: number;
344
+ /** [MF#3] worktree 模式下子 agent 改动的 patch 文件路径(worktree 外,供调用方应用)。 */
345
+ patchFile?: string;
346
+ /** worktree 隔离时的 handle(仅 worktree:true 时存在;fork alone 无此字段)。 */
347
+ worktreeHandle?: WorktreeHandle;
348
+ /**
349
+ * [review round2] 该 record 创建时启用了 worktree 隔离(跨重启磁盘重建时从 session
350
+ * entry 的 worktree 标志恢复)。handle 本体不可序列化——跨重启后 worktreeHandle 恒
351
+ * undefined,续聊(冷路径 resume)须拒绝(防 cwd 静默回落主 repo 破坏隔离)。仅内存
352
+ * record 使用,与持久化无关;execute() 新建 record 不设(有真 handle 时无意义)。
353
+ */
354
+ hadWorktree?: boolean;
355
+ controller: AbortController | undefined;
356
+ }
357
+
358
+ /**
359
+ * Workflow Extension — Engine 共享类型
360
+ *
361
+ * Engine 层全局基础类型。零 infra 依赖——不 import 任何 infra 文件,
362
+ * 可独立编译测试(D-12 三层架构,AC-1)。
363
+ *
364
+ * 核心内容:
365
+ * - 状态机:RunStatus = "running" | "done"(2 态,一次性生命周期,FR-3)
366
+ * + DoneReason(completed/failed/aborted/budget_limited/time_limited)
367
+ * - AgentCallOpts / AgentResult / AgentUsage(单次 agent 调用的输入/输出)
368
+ * - ExecutionTraceNode / TracePatch / ToolCallEntry / WorkerLogEntry(trace 数据)
369
+ *
370
+ * 层归属:Engine(数据结构 + 不变式守卫)。
371
+ */
372
+
373
+ /**
374
+ * 状态机:2 态(D-12 / FR-3,一次性生命周期——run 不可挂起)。
375
+ *
376
+ * running → done
377
+ *
378
+ * `done` 是唯一终态,具体原因由 DoneReason 区分。
379
+ */
380
+ type RunStatus = "running" | "done";
381
+ /** 终态原因。done 时必有(WorkflowRun 不变式)。 */
382
+ type DoneReason = "completed" | "failed" | "aborted" | "budget_limited" | "time_limited" | "invalid_args";
383
+ /**
384
+ * 单次 agent 调用的输入选项。
385
+ *
386
+ * D-12 仅重组执行编排,AgentCallOpts 形状保持兼容。
387
+ */
388
+ interface AgentCallOpts {
389
+ /** The task prompt to send to the agent. */
390
+ prompt: string;
391
+ /**
392
+ * Optional JSON schema for structured output.
393
+ * When provided, the schema is passed via PI_WORKFLOW_SCHEMA env to the subprocess,
394
+ * which activates the structured-output tool + turn_end hook.
395
+ * The tool's execute validates model output against the schema.
396
+ * On success, `parsedOutput` on the result is set to `tool_execution_end.result.details`
397
+ * (the validated, parsed data object — not the raw tool call args).
398
+ */
399
+ schema?: Record<string, unknown>;
400
+ /**
401
+ * Model to use (e.g. "router-openai/glm-5.1").
402
+ * When omitted, pi's default model is used.
403
+ */
404
+ model?: string;
405
+ /**
406
+ * Thinking level override (e.g. "high", "medium", "low").
407
+ * M2: Added to align with subagent path's ExecuteOptions.thinkingLevel.
408
+ * When omitted, agent .md frontmatter thinkingLevel is used (via resolveIdentity/getAgentConfig).
409
+ */
410
+ thinkingLevel?: string;
411
+ /** Scene name passed through to the worker for model-selection hints. */
412
+ scene?: string;
413
+ /**
414
+ * Wall-clock timeout in milliseconds. When > 0, aborts the subprocess
415
+ * if it runs longer than this, regardless of external signal.
416
+ * Per-call,归 AgentCall 实体(G-027)。
417
+ */
418
+ timeoutMs?: number;
419
+ /**
420
+ * Turn 上限(turn limiter 用)。
421
+ *
422
+ * [预算语义对齐] 未传或 <=0 = 不限 turn;此时也不按 turns 估算 spawn watchdog——
423
+ * 仅当 env XYZ_SUBAGENT_SPAWN_WATCHDOG_MS 设置时才按绝对时限挂 watchdog(见
424
+ * session-runner.resolveSpawnWatchdogMs)。mapToExecuteOptions 原样透传到
425
+ * ExecuteOptions.maxTurns → 引擎 task-spec → runSpawn。
426
+ */
427
+ maxTurns?: number;
428
+ /**
429
+ * Skill name to load (e.g. "code-review"). Resolved to SKILL.md path
430
+ * and injected via --skill flag in the subprocess.
431
+ */
432
+ skill?: string;
433
+ /**
434
+ * Resolved absolute path to the skill directory or SKILL.md file.
435
+ * Set by agent-opts-resolver when opts.skill is present.
436
+ */
437
+ skillPath?: string;
438
+ /** Human-readable description for logging and debugging. */
439
+ description?: string;
440
+ /**
441
+ * Agent ref (absolute .md path). Resolved by resolveIdentity via getAgentConfig,
442
+ * which injects the agent's systemPrompt/model/tools/thinkingLevel. Not handled by
443
+ * resolveAgentOpts (single-responsibility: agent ref ownership belongs to resolveIdentity,
444
+ * M2 fix — previously overlapped causing double-injection + model-tier confusion).
445
+ */
446
+ agent?: string;
447
+ /**
448
+ * System prompt injection CONTENT (not file paths).
449
+ * Set by agent-opts-resolver: schema structured-output instruction string.
450
+ * Agent systemPrompt is NOT included here (handled by resolveIdentity/agentConfig).
451
+ * mapToExecuteOptions passes this through to ExecuteOptions.appendSystemPrompt
452
+ * (same name/semantics, transparent passthrough).
453
+ */
454
+ appendSystemPrompt?: string[];
455
+ /**
456
+ * Schema JSON for PI_WORKFLOW_SCHEMA env var.
457
+ * Set by agent-opts-resolver when opts.schema is present; passed as env var
458
+ * to activate the structured-output tool + hook.
459
+ */
460
+ schemaEnv?: string;
461
+ /**
462
+ * Per-call 工作目录(ADR-029 决策 1)。传给 child_process.spawn 的 cwd option。
463
+ *
464
+ * 用于 worktree 隔离:传入 worktree 绝对路径,spawn 的 pi 子进程绑定到该目录,
465
+ * 其内部的 createAgentSession/ResourceLoader/bash 工具都在该目录运行。
466
+ * undefined 时 spawn 继承 workflow 进程的 cwd(向后兼容)。
467
+ */
468
+ cwd?: string;
469
+ /** Inherit parent session context (fork mode). Independent of worktree (file isolation). */
470
+ fork?: boolean;
471
+ /**
472
+ * 执行引擎 id(P4 D9 三层优先级的第一层:调用参数级,workflow step 显式指定)。
473
+ * 仅限「必须某引擎独有能力」的场景使用并注释原因(D9③ workflow 脚本不写死
474
+ * engine——环境差异由 frontmatter/全局默认承载);透传链 worker-script-builder
475
+ * agent() → execute-agent-call → SAR 路由层。
476
+ */
477
+ engine?: string;
478
+ /** Filesystem isolation: when true, creates a new git worktree for the agent. Independent of fork. */
479
+ worktree?: boolean;
480
+ /** When true, agent() resolves {value, sessionFile, worktreePath, error} instead of a bare value.
481
+ * Worker-layer flag only — not forwarded to ExecuteOptions (mapToExecuteOptions drops it). */
482
+ returnMeta?: boolean;
483
+ }
484
+ /**
485
+ * 单次 agent 调用的资源用量(FR-7 跨 turn 累积)。
486
+ */
487
+ interface AgentUsage {
488
+ input: number;
489
+ output: number;
490
+ cacheRead: number;
491
+ cacheWrite: number;
492
+ cost: number;
493
+ contextTokens: number;
494
+ turns: number;
495
+ }
496
+ /**
497
+ * 单次 tool 调用记录(FR-7 从 agent JSONL 流采)。
498
+ */
499
+ interface ToolCallEntry {
500
+ /** Tool name. */
501
+ name: string;
502
+ /** Args preview string. */
503
+ input: string;
504
+ }
505
+ /**
506
+ * 单次 agent 调用的结果(统一形态)。
507
+ *
508
+ * Engine 直接消费 SubprocessAgentRunner 返回值;callCache replay 时 worker
509
+ * 取 parsedOutput ?? content(见 worker-script-builder.ts 消息处理)。
510
+ */
511
+ interface AgentResult {
512
+ /** Raw text output from the agent. */
513
+ content: string;
514
+ /**
515
+ * Parsed structured output.
516
+ * Present when `schema` was provided and the output was valid JSON.
517
+ * Source: tool_execution_end.result.details(validated data object)。
518
+ */
519
+ parsedOutput?: unknown;
520
+ /** Token and cost usage accumulated across all assistant turns. */
521
+ usage?: AgentUsage;
522
+ /** Wall-clock duration in milliseconds. */
523
+ durationMs?: number;
524
+ /** True when the pi process exited with code 0. */
525
+ error?: string;
526
+ /**
527
+ * Pi session ID for the subagent process (uuidv7).
528
+ * Present when pi emits a session header (default in --mode json).
529
+ * Can be used to locate the session JSONL file for post-run inspection (G-017)。
530
+ */
531
+ sessionId?: string;
532
+ /**
533
+ * Session JSONL 绝对路径(不含目录的文件名在 subagents 侧 AgentResult.sessionFile)。
534
+ * 由 mapToWorkflowAgentResult 从 subagents AgentResult 透传——让 workflow 编排层
535
+ * 继承 subagent 执行管道产出的 session 文件路径,overlay/GUI 可直接定位。
536
+ * 窗口期内可能 undefined(session 尚未创建成功)。
537
+ */
538
+ sessionFile?: string;
539
+ /**
540
+ * Absolute path of the git worktree used for filesystem isolation (set when
541
+ * worktree isolation is active). Injected by executeAndAwait from record.worktreeHandle.path.
542
+ *
543
+ * ⚠️ Diagnostic only, may not exist: executeAndAwait's finalizeRecord cleans up the
544
+ * worktree (git worktree remove --force) before returning, so by the time this field
545
+ * reaches the caller the directory has typically been deleted. Use it only for log/trace
546
+ * correlation (e.g. attributing a session jsonl to its worktree origin) — never as a cwd
547
+ * for a subsequent agent or filesystem operation (would ENOENT).
548
+ */
549
+ worktreePath?: string;
550
+ /** All tool calls collected from JSONL stream (FR-7). */
551
+ toolCalls?: ToolCallEntry[];
552
+ }
553
+ /**
554
+ * 执行追踪节点(事件流 D-10 单一来源)。
555
+ */
556
+ interface ExecutionTraceNode {
557
+ stepIndex: number;
558
+ agent: string;
559
+ task: string;
560
+ model: string;
561
+ status: "pending" | "running" | "completed" | "failed";
562
+ /** Phase name for TUI grouping. Set from explicit opts.phase or global _currentPhase. */
563
+ phase?: string;
564
+ startedAt?: string;
565
+ completedAt?: string;
566
+ result?: AgentResult;
567
+ error?: string;
568
+ /**
569
+ * Pi session ID (uuidv7) for the subagent process.
570
+ * Used to locate the session JSONL for post-run inspection.
571
+ */
572
+ sessionId?: string;
573
+ /**
574
+ * Session JSONL 绝对路径。finalizeCall 从 result.sessionFile 透传。
575
+ * 持久化到快照(serializeRun),跨 session 重水合后保留。
576
+ */
577
+ sessionFile?: string;
578
+ /**
579
+ * Live 执行进度对象(running 时存在,done 时由 dispatchAgentCall 清除)。
580
+ *
581
+ * 挂在 node 上(D-10 单源延伸:AgentCall.traceNode 与 Trace.nodes 共享同一引用)。
582
+ * TUI 通过 trace.toArray() 读 node.live,派生 getEventLog/getCurrentActivity 实时展示。
583
+ * 不持久化(序列化时 strip;重跑时由 dispatchAgentCall 重建)。
584
+ */
585
+ live?: ExecutionRecord;
586
+ }
587
+ /**
588
+ * Trace.update 用的 patch(字段全可选)。
589
+ *
590
+ * 不变式:只改单个 node 的 status/result/error/completedAt/sessionId。
591
+ * callId 不存在时 update 为 no-op(D-10)。
592
+ */
593
+ interface TracePatch {
594
+ status?: "pending" | "running" | "completed" | "failed";
595
+ result?: AgentResult;
596
+ error?: string;
597
+ completedAt?: string;
598
+ sessionId?: string;
599
+ sessionFile?: string;
600
+ }
601
+ /**
602
+ * Worker console.* 捕获条目(run 级诊断,仅展示在 TUI widget,不泄漏到 input area)。
603
+ */
604
+ interface WorkerLogEntry {
605
+ level: "log" | "warn" | "error" | "info";
606
+ message: string;
607
+ }
608
+
609
+ /** 人设(persona)注入规格:原 skillPath + appendSystemPrompt 收拢进一个语义单元(D2)。 */
610
+ interface PersonaSpec {
611
+ /**
612
+ * agent 名/路径。与 AgentTaskSpec.agent 的分工:agent 是 resolveIdentity 的身份解析
613
+ * 键(模型/系统提示等身份语义);agentRef 是 persona 注入通道的定位符——引擎按
614
+ * capabilities.personaInjection 决定注入通道(file/flag/prompt)时用它定位人设。
615
+ * pi 引擎不消费此字段(身份解析走 spec.agent),留给 flag/file 通道的引擎。
616
+ */
617
+ agentRef?: string;
618
+ /**
619
+ * 原 ExecuteOptions.skillPath。公共 persona 路由三策略(file/flag/prompt)的分流
620
+ * 载体(D4)——超长 prompt 时优先 file/flag 通道分流的落点。
621
+ */
622
+ skillPath?: string;
623
+ /** 追加系统提示内容数组(原样透传;schema 仿真段由公共降级层拼装后放入,P2)。 */
624
+ appendSystemPrompt?: string[];
625
+ }
626
+ /**
627
+ * 引擎无关的 agent 任务声明(= ExecuteOptions 泛化,字段逐条锚定设计 §3.3.5)。
628
+ *
629
+ * 与 ExecuteOptions 的差异(泛化点):
630
+ * - thinkingLevel(pi 7 档枚举语义)→ effort?: string,各引擎自行映射或忽略;
631
+ * - skillPath + appendSystemPrompt → persona(PersonaSpec);
632
+ * - conversation/idleTimeoutMs 保留原名透传——属 interact 交互控制面的 task 标志(D1),
633
+ * 不是 pi 专有语义的泄漏,而是「任务声明里声明交互模式」的中立表达;
634
+ * - 删字段去向:signal/ctxModel/onComplete 是运行期句柄,移入 RunContext(port.ts);
635
+ * schemaEnv 内化到 PiEngine(从 task.schema 派生,见 engines/pi/task-spec-mapper.ts)。
636
+ *
637
+ * 新增(为后续 wave 预留形状,P1 无生产写入方):
638
+ * - denyTools:中立工具 denylist(附录 A 该行的载体);
639
+ * - permissionMode:中立权限模式(映射按 capabilities.permissionMode)。
640
+ */
641
+ interface AgentTaskSpec {
642
+ /** 原样(ExecuteOptions.task)。 */
643
+ task: string;
644
+ /** 原样(ExecuteOptions.slug,≤35 字符)。 */
645
+ slug: string;
646
+ /** 原样(ExecuteOptions.agent,resolveIdentity 的 agent ref)。 */
647
+ agent?: string;
648
+ /** 原样(ExecuteOptions.model;在引擎 provider 体系内解释,D9②)。 */
649
+ model?: string;
650
+ /**
651
+ * 泛化:原 ExecuteOptions.thinkingLevel。引擎无关的推理投入档位字符串——
652
+ * pi 引擎把它原值映射回 thinkingLevel 7 档;其他引擎自行映射(CC 5 档)或忽略
653
+ * (kimi ❌)。不定义联合枚举:档位集合是引擎私有语义,中立层只透传字符串。
654
+ */
655
+ effort?: string;
656
+ /** 泛化:原 skillPath + appendSystemPrompt 收拢(D2)。 */
657
+ persona?: PersonaSpec;
658
+ /**
659
+ * 原样(ExecuteOptions.schema)。native/emulated 分流依据(D4 硬边界):pi 的
660
+ * PI_WORKFLOW_SCHEMA env 注入链路按 native 直传,公共仿真层只服务 emulated 引擎。
661
+ */
662
+ schema?: Record<string, unknown>;
663
+ /**
664
+ * 原样(ExecuteOptions.maxTurns)。pi 引擎专属(turn limiter + spawn watchdog
665
+ * 估算依赖 pi 的 turn_end 事件流);其他引擎 prepare 期显式拒绝(U4,同 fork 模式)。
666
+ * 显式 0 压过 SPAWN_WATCHDOG_ENV 兑底(SP-6 参数 > env,U5);undefined 未传才由
667
+ * env 兑底。
668
+ */
669
+ maxTurns?: number;
670
+ /** 原样(ExecuteOptions.graceTurns)。 */
671
+ graceTurns?: number;
672
+ /** 原样(ExecuteOptions.fork)。pi 专属;其他引擎 prepare 期按 capabilities 拒绝。 */
673
+ fork?: boolean;
674
+ /**
675
+ * 原样(ExecuteOptions.worktree)。公共层职责(worktree-manager),非引擎职责——
676
+ * 引擎只把它当 spawn cwd 的来源之一。
677
+ */
678
+ worktree?: boolean | WorktreeHandle;
679
+ /** 原样(ExecuteOptions.cwd)。 */
680
+ cwd?: string;
681
+ /** 原样(ExecuteOptions.conversation,interact 控制面的 task 标志,D1)。 */
682
+ conversation?: boolean;
683
+ /** 原样(ExecuteOptions.idleTimeoutMs,同上)。 */
684
+ idleTimeoutMs?: number;
685
+ /** 新增:中立工具 denylist。各引擎做语法映射(附录 A「工具 denylist」行的载体)。 */
686
+ denyTools?: string[];
687
+ /** 新增:中立权限模式。映射按 capabilities.permissionMode(kimi fixed auto = ignored)。 */
688
+ permissionMode?: string;
689
+ /**
690
+ * [P4 形状预留,D9① 守卫 b 的独立载体] 任务对引擎能力的显式依赖声明。
691
+ * 首期无生产写入方:守卫 b 与守卫 a 合流(显式 engine 即能力依赖声明)——调用方
692
+ * 按引擎 id 表达依赖。下钻时机(AgentTaskSpec 泛化成熟后):调用方改按能力表达
693
+ * (如 requires: { sandbox: 'native' }),路由层将本字段与各引擎 capabilities()
694
+ * 对照,无引擎满足时报 engine_capability_unsupported(调用前拒绝,D11 处置三级)。
695
+ */
696
+ requires?: Partial<EngineCapabilities>;
697
+ }
698
+ /**
699
+ * 一次引擎执行的终态。锚定 orchestration/models/types.ts 的 AgentResult(workflow
700
+ * 引擎消费的那份——content/parsedOutput/usage/error)并追加引擎层字段;见文件头消歧说明。
701
+ */
702
+ interface AgentOutcome {
703
+ /** 原样(AgentResult.content)。 */
704
+ content: string;
705
+ /**
706
+ * 原样(AgentResult.parsedOutput)。native 引擎直传 / 仿真层 ajv 产出(D4 硬分流:
707
+ * native 路径公共层不做二次校验、不改写其结果)。
708
+ */
709
+ parsedOutput?: unknown;
710
+ /** 原样(AgentResult.usage,orchestration 版 AgentUsage:含 contextTokens/turns)。 */
711
+ usage?: AgentUsage;
712
+ /** 原样(AgentResult.durationMs)。 */
713
+ durationMs?: number;
714
+ /** 原样(AgentResult.error,错误码前缀格式见设计 §3.3.3 错误规格表)。 */
715
+ error?: string;
716
+ /** 原样(AgentResult.sessionId,引擎语义 session id)。 */
717
+ sessionId?: string;
718
+ /** 原样(AgentResult.sessionFile)。 */
719
+ sessionFile?: string;
720
+ /** 原样(AgentResult.worktreePath,仅诊断——目录可能已被 finalize 清理)。 */
721
+ worktreePath?: string;
722
+ /** 原样(AgentResult.toolCalls,ToolCallEntry[])。 */
723
+ toolCalls?: ToolCallEntry[];
724
+ /** 新增:实际执行引擎(fallback 后可能 ≠ 请求值,D9①)。 */
725
+ engineId: string;
726
+ /** 新增:fallback 留痕(record 同步投影,GUI 警告条数据源)。P1 恒缺省(无 fallback 路由)。 */
727
+ engineFallback?: {
728
+ from: string;
729
+ reason: string;
730
+ };
731
+ /** 新增:null = 被信号杀死(杀链/abort 合成终态的判据)。P1 pi 链路不暴露 exit code,恒缺省。 */
732
+ exitCode?: number | null;
733
+ }
734
+ /**
735
+ * EngineHandle 的持久化形态(设计 §3.3.6,JSON v1)。
736
+ * 内存态 EngineHandle = 本数据 + 引擎运行时引用(各引擎自持)。
737
+ */
738
+ interface EngineHandleData {
739
+ v: 1;
740
+ /** 引擎 id('pi' | 'zcode' | ...,registry key)。 */
741
+ engineId: string;
742
+ /**
743
+ * 引擎自定义键值(定位符)。pi = { recordId?, sessionFile? }——recordId 是
744
+ * interact 控制面的 key(subagent record id),sessionFile 是 read 第①级(JSONL
745
+ * 直读)的定位符;zcode = { sessionId, dbPath }。
746
+ */
747
+ sessionRef: Record<string, string>;
748
+ /** 隔离池定位(设计 §3.3.9)。pi 无池化(PI_CODING_AGENT_DIR 全局一份)恒 'shared'。 */
749
+ poolKey: string;
750
+ /**
751
+ * journal 绝对路径(read 第②级数据源;runtime 读前校验前缀白名单)。
752
+ * P2 event journal 落地后由宿主回填;P1 无 journal 写入者,缺省 undefined——
753
+ * read 降级链第②级不可达,直接走 ①/③。
754
+ */
755
+ journalPath?: string;
756
+ /** probe 实测版本(漂移排查锚点)。 */
757
+ engineVersion?: string;
758
+ /** 适配器版本(golden 样本对齐排查)。 */
759
+ adapterVersion: string;
760
+ }
761
+ /**
762
+ * 引擎会话句柄(run 返回、interact/read 入参)。
763
+ *
764
+ * 契约三条(D1):不透明(上层不解构——唯一例外是 record 持久化层序列化 data 字段与
765
+ * read 降级链)、可持久化(data 是纯 JSON,主会话 reload 后 read/interact 仍可用)、
766
+ * 自描述(data 含 engineId + 引擎 session 定位符 + pool key + adapter 版本)。
767
+ *
768
+ * 对进程已死的 handle 调 interact 必须返回 engine_session_not_resumable(指向 cold
769
+ * resume 路径),而非笼统失败——由各引擎 interact 实现保证。
770
+ */
771
+ interface EngineHandle {
772
+ /** 持久化数据。上层不得解构其内部字段(见契约三条)。 */
773
+ readonly data: EngineHandleData;
774
+ }
775
+ /**
776
+ * read(handle) 的返回:turns[] 派生数据。与 Turn 同构但无内部态(_status/startedTs
777
+ * 剥离,closed 恒 true)。
778
+ */
779
+ interface ReplayedTurn {
780
+ text: string;
781
+ thinking: string;
782
+ /** 导出的纯净形状(execution 层 ToolCall,无 _status)。 */
783
+ toolCalls: ToolCall[];
784
+ closed: true;
785
+ }
786
+ /**
787
+ * session 历史的引擎中立视图。降级链三级(D6):①引擎原生读取(pi JSONL / zcode
788
+ * sqlite)→ ②宿主 event journal 重放(P2)→ ③outcome-only。source 字段是 GUI 降级
789
+ * 标记数据源(A8)。
790
+ */
791
+ interface SessionView {
792
+ engineId: string;
793
+ sessionId?: string;
794
+ /** turns[] 派生数据(重放/重建产物)。 */
795
+ turns: ReplayedTurn[];
796
+ /** 各 turn usageDelta 聚合(execution 层 AgentUsageTotal)。 */
797
+ usage?: AgentUsageTotal;
798
+ source: "native" | "journal" | "outcome-only";
799
+ }
800
+ /**
801
+ * 引擎能力声明(设计 D3 原样落地)。三级:native / emulated / unsupported。
802
+ *
803
+ * 易错点(D3):声明的是**本仓 subagent 链路实际接通的能力**,不是引擎 RPC 层的理论
804
+ * 能力——pi 的 RPC 有 steer 但现有 spawn 链路未接通(session-runner steer no-op),
805
+ * 故 PiEngine 声明 unsupported,接通后再升级。上层据声明选择策略(schema 为 emulated
806
+ * 时自动走公共降级层;steer/conversation unsupported 时 UI 隐藏对应入口),而非
807
+ * try-catch 运行时试错。
808
+ */
809
+ interface EngineCapabilities {
810
+ /** native: --json-schema/--output-schema/env 注入(pi = PI_WORKFLOW_SCHEMA 链路)。 */
811
+ schemaEnforcement: "native" | "emulated";
812
+ /** 注意区分「引擎 RPC 层有此能力」与「subagent 链路已接通」。 */
813
+ steer: "native" | "emulated" | "unsupported";
814
+ /** interact 控制面(message/close/cancel + idle)。 */
815
+ conversation: "native" | "unsupported";
816
+ /** 决定 persona 路由策略(公共降级层按此选择 file/flag/prompt 通道)。 */
817
+ personaInjection: "file" | "flag" | "prompt";
818
+ /** 粗粒度引擎:GUI 显示降级为阶段态。 */
819
+ eventGranularity: "stream" | "coarse";
820
+ /** emulated = worktree 隔离(无 OS sandbox 的引擎用文件写维度隔离补齐)。 */
821
+ sandbox: "native" | "emulated" | "none";
822
+ /** 重建历史的能力(read 降级链第①级的保真度上限)。 */
823
+ sessionRead: "full" | "partial" | "outcome-only";
824
+ resume: "native" | "cold" | "unsupported";
825
+ /** 优雅中断 or 只能杀进程(公共杀链兜底,见 D1 abort 分级)。 */
826
+ interrupt: "native" | "kill-only";
827
+ /** kimi headless 固定 auto = ignored;GUI 据此隐藏/提示。 */
828
+ permissionMode: "native" | "fixed" | "ignored";
829
+ }
830
+ /** 引擎探针报告(probe() 返回)。探针在引擎 factory 初始化与版本变化检测时触发(P4 接线)。 */
831
+ interface ProbeReport {
832
+ ok: boolean;
833
+ /** 实测版本(handle.engineVersion 数据源)。探测不到时为空串。 */
834
+ engineVersion: string;
835
+ /** 二进制存在/版本解析/干跑回归逐项。 */
836
+ checks: Array<{
837
+ name: string;
838
+ ok: boolean;
839
+ detail?: string;
840
+ }>;
841
+ /** engine_probe_failed 的恢复指引(设计 §3.3.3 终态四样例;ok=false 时必填)。 */
842
+ error?: {
843
+ code: string;
844
+ recovery: string;
845
+ };
846
+ }
847
+ /**
848
+ * interact 的 action(D1 交互控制面)。pi 首期原生实现(现有 chatMode 行为直通);
849
+ * 声明 conversation unsupported 的引擎调用前拒绝(engine_capability_unsupported)。
850
+ */
851
+ type InteractAction = {
852
+ kind: "message";
853
+ payload: string;
854
+ } | {
855
+ kind: "close";
856
+ payload?: {
857
+ force: boolean;
858
+ };
859
+ } | {
860
+ kind: "cancel";
861
+ };
862
+ /**
863
+ * interact 的结果。失败码取自设计 §3.3.3:engine_session_not_resumable(死 handle)/
864
+ * engine_capability_unsupported(能力声明拒绝)等。
865
+ */
866
+ type InteractResult = {
867
+ ok: true;
868
+ delivered: true;
869
+ } | {
870
+ ok: false;
871
+ code: string;
872
+ message: string;
873
+ };
874
+
875
+ export type { AgentTaskSpec as A, DoneReason as D, EngineCapabilities as E, InteractAction as I, ProbeReport as P, RunStatus as R, SessionView as S, TracePatch as T, WorkerLogEntry as W, AgentEvent as a, EngineHandle as b, AgentOutcome as c, InteractResult as d, AgentUsage as e, AgentCallOpts as f, AgentResult as g, ExecutionTraceNode as h, EngineHandleData as i, PersonaSpec as j, ReplayedTurn as k };