@zhushanwen/pi-subagent-workflow 8.5.0 → 8.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 (336) hide show
  1. package/package.json +13 -16
  2. package/relay/relay.mjs +1 -1
  3. package/src/host/__tests__/pi-host.test.ts +214 -0
  4. package/src/host/pi-host.ts +109 -0
  5. package/src/index.ts +142 -32
  6. package/src/injectors/__tests__/engine-awareness.test.ts +292 -0
  7. package/src/injectors/__tests__/engine-section-stability.test.ts +341 -0
  8. package/src/injectors/__tests__/subagent-list-injector.test.ts +5 -5
  9. package/src/injectors/__tests__/workflow-list-injector.test.ts +5 -5
  10. package/src/injectors/engine-awareness.ts +123 -0
  11. package/src/injectors/model-list-injector.ts +1 -1
  12. package/src/injectors/subagent-list-injector.ts +8 -8
  13. package/src/injectors/workflow-list-injector.ts +8 -8
  14. package/src/interface/__tests__/detectors.test.ts +3 -3
  15. package/src/interface/__tests__/subagent-tool-path-guard.test.ts +157 -0
  16. package/src/interface/__tests__/subagent-tool-prompt.test.ts +12 -0
  17. package/src/interface/__tests__/tool-workflow-script-generate.test.ts +2 -2
  18. package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +1 -1
  19. package/src/interface/bg-notify-render.ts +34 -13
  20. package/src/interface/commands.ts +3 -3
  21. package/src/interface/format.ts +2 -2
  22. package/src/interface/helpers.ts +3 -3
  23. package/src/interface/list-component.ts +4 -4
  24. package/src/interface/list-shared.ts +2 -2
  25. package/src/interface/list-view.ts +2 -2
  26. package/src/interface/subagent-actions.ts +288 -19
  27. package/src/interface/subagent-tool-schema.ts +163 -0
  28. package/src/interface/subagent-tool.ts +65 -129
  29. package/src/interface/subagents.ts +5 -5
  30. package/src/interface/tool-render.ts +34 -2
  31. package/src/interface/tool-workflow-script.ts +4 -4
  32. package/src/interface/tool-workflow.ts +6 -6
  33. package/src/interface/views/WorkflowsView.ts +5 -5
  34. package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
  35. package/src/interface/views/__tests__/detail-content-session-file.test.ts +2 -2
  36. package/src/interface/views/detail-content.ts +4 -4
  37. package/src/interface/views/format.ts +4 -4
  38. package/src/{orchestration/jsonl-run-store.ts → jsonl-run-store.ts} +132 -18
  39. package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +0 -53
  40. package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +0 -1
  41. package/src/execution/__tests__/agent-registry.test.ts +0 -363
  42. package/src/execution/__tests__/agent-result-mapper.test.ts +0 -150
  43. package/src/execution/__tests__/alive-store.test.ts +0 -147
  44. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
  45. package/src/execution/__tests__/before-agent-start-injection.test.ts +0 -132
  46. package/src/execution/__tests__/bg-notify-render.test.ts +0 -256
  47. package/src/execution/__tests__/channel-registry-handshake.test.ts +0 -243
  48. package/src/execution/__tests__/chat-engine-routing.test.ts +0 -597
  49. package/src/execution/__tests__/chatmode-first-round-closure-service.test.ts +0 -365
  50. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -190
  51. package/src/execution/__tests__/chatmode-round-notify-real-chain.test.ts +0 -215
  52. package/src/execution/__tests__/concurrency-pool.test.ts +0 -250
  53. package/src/execution/__tests__/config.test.ts +0 -110
  54. package/src/execution/__tests__/conversation-wiring.test.ts +0 -198
  55. package/src/execution/__tests__/crash-recovery.test.ts +0 -320
  56. package/src/execution/__tests__/delivery-methods.test.ts +0 -385
  57. package/src/execution/__tests__/dialog-queue.test.ts +0 -299
  58. package/src/execution/__tests__/epipe-fallback.test.ts +0 -241
  59. package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -243
  60. package/src/execution/__tests__/execute-nesting.test.ts +0 -323
  61. package/src/execution/__tests__/execute-options-mapper.test.ts +0 -189
  62. package/src/execution/__tests__/execution-record.test.ts +0 -1284
  63. package/src/execution/__tests__/finalize-record.test.ts +0 -368
  64. package/src/execution/__tests__/finalized-marker.test.ts +0 -82
  65. package/src/execution/__tests__/format-schema-instruction.test.ts +0 -138
  66. package/src/execution/__tests__/format.test.ts +0 -458
  67. package/src/execution/__tests__/gc-timer.test.ts +0 -184
  68. package/src/execution/__tests__/get-record-for-action-restart.test.ts +0 -254
  69. package/src/execution/__tests__/gui-mode-dispatch.test.ts +0 -59
  70. package/src/execution/__tests__/helpers/mock-extension-api.ts +0 -30
  71. package/src/execution/__tests__/helpers/spawn-mock.ts +0 -238
  72. package/src/execution/__tests__/host-mode.test.ts +0 -87
  73. package/src/execution/__tests__/index-session-start-identity.test.ts +0 -371
  74. package/src/execution/__tests__/index-session-start.test.ts +0 -593
  75. package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
  76. package/src/execution/__tests__/lifecycle-manager.test.ts +0 -337
  77. package/src/execution/__tests__/lifecycle-predicates.test.ts +0 -116
  78. package/src/execution/__tests__/list-component.test.ts +0 -401
  79. package/src/execution/__tests__/list-fields.test.ts +0 -109
  80. package/src/execution/__tests__/manifest-parentid.test.ts +0 -117
  81. package/src/execution/__tests__/model-resolver.test.ts +0 -413
  82. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +0 -287
  83. package/src/execution/__tests__/nested-visibility.test.ts +0 -325
  84. package/src/execution/__tests__/notifier-flush.test.ts +0 -574
  85. package/src/execution/__tests__/notifier-golden-snapshot.test.ts +0 -261
  86. package/src/execution/__tests__/one-shot-upgrade.test.ts +0 -205
  87. package/src/execution/__tests__/output-collector.test.ts +0 -61
  88. package/src/execution/__tests__/parent-child-matrix.test.ts +0 -336
  89. package/src/execution/__tests__/path-encoding.test.ts +0 -104
  90. package/src/execution/__tests__/pi-invocation.test.ts +0 -134
  91. package/src/execution/__tests__/record-store.test.ts +0 -1057
  92. package/src/execution/__tests__/records-cwd-isolation.test.ts +0 -91
  93. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +0 -339
  94. package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -273
  95. package/src/execution/__tests__/relay-agent.test.ts +0 -448
  96. package/src/execution/__tests__/relay-env.test.ts +0 -42
  97. package/src/execution/__tests__/resource-policy.test.ts +0 -109
  98. package/src/execution/__tests__/rpc-mode.test.ts +0 -89
  99. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -267
  100. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -253
  101. package/src/execution/__tests__/run-spawn-edges.test.ts +0 -644
  102. package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
  103. package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
  104. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
  105. package/src/execution/__tests__/sdk-contract.test.ts +0 -273
  106. package/src/execution/__tests__/session-context-resolver.test.ts +0 -167
  107. package/src/execution/__tests__/session-file-gc.test.ts +0 -293
  108. package/src/execution/__tests__/session-pending.test.ts +0 -197
  109. package/src/execution/__tests__/session-reconstructor.test.ts +0 -379
  110. package/src/execution/__tests__/session-runner-epipe.test.ts +0 -178
  111. package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -311
  112. package/src/execution/__tests__/session-start-reaper.test.ts +0 -233
  113. package/src/execution/__tests__/spawn-args.test.ts +0 -434
  114. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -189
  115. package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
  116. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -207
  117. package/src/execution/__tests__/spawned-children.test.ts +0 -92
  118. package/src/execution/__tests__/startup-config-declaration.test.ts +0 -35
  119. package/src/execution/__tests__/status-refactor.test.ts +0 -345
  120. package/src/execution/__tests__/stdin-writer.test.ts +0 -463
  121. package/src/execution/__tests__/stream-sink-retirement.test.ts +0 -261
  122. package/src/execution/__tests__/subagent-service-abort.test.ts +0 -60
  123. package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -629
  124. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +0 -180
  125. package/src/execution/__tests__/subagent-service.test.ts +0 -788
  126. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -310
  127. package/src/execution/__tests__/subprocess-agent-runner.test.ts +0 -506
  128. package/src/execution/__tests__/temp-prompt.test.ts +0 -53
  129. package/src/execution/__tests__/timeout-integration.test.ts +0 -397
  130. package/src/execution/__tests__/tombstone-store.test.ts +0 -73
  131. package/src/execution/__tests__/tool-action.test.ts +0 -385
  132. package/src/execution/__tests__/truncline-snapshot.test.ts +0 -81
  133. package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
  134. package/src/execution/__tests__/turn-limiter.test.ts +0 -65
  135. package/src/execution/__tests__/ui-channels.test.ts +0 -187
  136. package/src/execution/__tests__/ui-interaction-model.test.ts +0 -67
  137. package/src/execution/__tests__/ui-request-handler-factory.test.ts +0 -370
  138. package/src/execution/__tests__/ui-request-handler.test.ts +0 -204
  139. package/src/execution/__tests__/ui-request-observability.test.ts +0 -114
  140. package/src/execution/__tests__/ui-request-queue.test.ts +0 -133
  141. package/src/execution/__tests__/worktree-manager.test.ts +0 -633
  142. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -229
  143. package/src/execution/__tests__/worktree-reconcile.integration.test.ts +0 -181
  144. package/src/execution/__tests__/worktree-registry.test.ts +0 -199
  145. package/src/execution/agent-registry.ts +0 -193
  146. package/src/execution/agent-result-mapper.ts +0 -90
  147. package/src/execution/alive-store.ts +0 -92
  148. package/src/execution/argv-mirror.ts +0 -109
  149. package/src/execution/best-effort.ts +0 -38
  150. package/src/execution/channel-registry-access.ts +0 -144
  151. package/src/execution/concurrency-pool.ts +0 -116
  152. package/src/execution/config.ts +0 -96
  153. package/src/execution/dialog-queue.ts +0 -330
  154. package/src/execution/engine/__tests__/common/data-dir.test.ts +0 -53
  155. package/src/execution/engine/__tests__/common/errors.test.ts +0 -132
  156. package/src/execution/engine/__tests__/common/event-journal.test.ts +0 -177
  157. package/src/execution/engine/__tests__/common/kill-chain.test.ts +0 -192
  158. package/src/execution/engine/__tests__/common/nesting-guard.test.ts +0 -81
  159. package/src/execution/engine/__tests__/common/persona-router.test.ts +0 -123
  160. package/src/execution/engine/__tests__/common/pool-manager.test.ts +0 -154
  161. package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
  162. package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
  163. package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +0 -141
  164. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +0 -109
  165. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +0 -101
  166. package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +0 -77
  167. package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +0 -104
  168. package/src/execution/engine/__tests__/conformance/contract.relay.test.ts +0 -342
  169. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +0 -201
  170. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +0 -76
  171. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +0 -79
  172. package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -87
  173. package/src/execution/engine/__tests__/engines-declaration.test.ts +0 -36
  174. package/src/execution/engine/__tests__/model-prompt.test.ts +0 -85
  175. package/src/execution/engine/__tests__/paths.test.ts +0 -39
  176. package/src/execution/engine/__tests__/registry.test.ts +0 -120
  177. package/src/execution/engine/__tests__/routing.test.ts +0 -231
  178. package/src/execution/engine/common/data-dir.ts +0 -62
  179. package/src/execution/engine/common/errors.ts +0 -183
  180. package/src/execution/engine/common/event-journal.ts +0 -254
  181. package/src/execution/engine/common/journal-replay.ts +0 -62
  182. package/src/execution/engine/common/kill-chain.ts +0 -221
  183. package/src/execution/engine/common/nesting-guard.ts +0 -50
  184. package/src/execution/engine/common/persona-router.ts +0 -108
  185. package/src/execution/engine/common/pool-manager.ts +0 -226
  186. package/src/execution/engine/common/schema-emulation.ts +0 -189
  187. package/src/execution/engine/common/session-view-projection.ts +0 -51
  188. package/src/execution/engine/engine-discovery.ts +0 -65
  189. package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -469
  190. package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
  191. package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
  192. package/src/execution/engine/engines/pi/pi-engine.ts +0 -415
  193. package/src/execution/engine/engines/pi/reader.ts +0 -48
  194. package/src/execution/engine/engines/pi/registration.ts +0 -35
  195. package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
  196. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
  197. package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
  198. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -246
  199. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -228
  200. package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
  201. package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -64
  202. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -127
  203. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -567
  204. package/src/execution/engine/engines/zcode/constants.ts +0 -43
  205. package/src/execution/engine/engines/zcode/golden-sample.ts +0 -39
  206. package/src/execution/engine/engines/zcode/launcher.ts +0 -161
  207. package/src/execution/engine/engines/zcode/parser.ts +0 -436
  208. package/src/execution/engine/engines/zcode/preparer.ts +0 -363
  209. package/src/execution/engine/engines/zcode/reader.ts +0 -381
  210. package/src/execution/engine/engines/zcode/registration.ts +0 -37
  211. package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -648
  212. package/src/execution/engine/host-task-spec.ts +0 -47
  213. package/src/execution/engine/model-prompt.ts +0 -59
  214. package/src/execution/engine/paths.ts +0 -42
  215. package/src/execution/engine/port.ts +0 -153
  216. package/src/execution/engine/registry.ts +0 -123
  217. package/src/execution/engine/routing.ts +0 -218
  218. package/src/execution/engine/types.ts +0 -304
  219. package/src/execution/execute-options-mapper.ts +0 -111
  220. package/src/execution/execution-record.ts +0 -906
  221. package/src/execution/finalize-record.ts +0 -251
  222. package/src/execution/finalized-marker.ts +0 -51
  223. package/src/execution/get-state-handshake.ts +0 -104
  224. package/src/execution/host-mode.ts +0 -56
  225. package/src/execution/idle-gc.ts +0 -47
  226. package/src/execution/lifecycle-manager.ts +0 -491
  227. package/src/execution/lifecycle-predicates.ts +0 -65
  228. package/src/execution/manifest-store.ts +0 -256
  229. package/src/execution/model-config-service.ts +0 -204
  230. package/src/execution/model-resolver.ts +0 -276
  231. package/src/execution/notifier.ts +0 -260
  232. package/src/execution/output-collector.ts +0 -88
  233. package/src/execution/path-encoding.ts +0 -60
  234. package/src/execution/pi-invocation.ts +0 -120
  235. package/src/execution/record-entry.ts +0 -132
  236. package/src/execution/record-store.ts +0 -1234
  237. package/src/execution/relay-env.ts +0 -37
  238. package/src/execution/session-context-resolver.ts +0 -64
  239. package/src/execution/session-file-gc.ts +0 -120
  240. package/src/execution/session-pending.ts +0 -164
  241. package/src/execution/session-reconstructor.ts +0 -678
  242. package/src/execution/session-runner.ts +0 -1548
  243. package/src/execution/sessions-index.ts +0 -304
  244. package/src/execution/spawn-event-adapter.ts +0 -363
  245. package/src/execution/stdin-writer.ts +0 -198
  246. package/src/execution/stream-sink.ts +0 -126
  247. package/src/execution/subagent-service.ts +0 -2119
  248. package/src/execution/subprocess-agent-runner.ts +0 -303
  249. package/src/execution/temp-prompt.ts +0 -62
  250. package/src/execution/tombstone-store.ts +0 -72
  251. package/src/execution/turn-limiter.ts +0 -102
  252. package/src/execution/types.ts +0 -910
  253. package/src/execution/ui-channels.ts +0 -216
  254. package/src/execution/ui-interaction-model.ts +0 -48
  255. package/src/execution/ui-request-handler-factory.ts +0 -212
  256. package/src/execution/ui-request-observability.ts +0 -81
  257. package/src/execution/ui-request-queue.ts +0 -174
  258. package/src/execution/worktree-manager.ts +0 -688
  259. package/src/execution/worktree-registry.ts +0 -222
  260. package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +0 -336
  261. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +0 -208
  262. package/src/orchestration/__tests__/agent-call-stream.test.ts +0 -157
  263. package/src/orchestration/__tests__/args-validator.test.ts +0 -143
  264. package/src/orchestration/__tests__/concurrency-gate.test.ts +0 -125
  265. package/src/orchestration/__tests__/config-loader.test.ts +0 -503
  266. package/src/orchestration/__tests__/error-recovery-handlers.test.ts +0 -724
  267. package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +0 -405
  268. package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +0 -56
  269. package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +0 -166
  270. package/src/orchestration/__tests__/execute-agent-call.test.ts +0 -314
  271. package/src/orchestration/__tests__/jsonl-run-store-loadall-sources.test.ts +0 -171
  272. package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +0 -1030
  273. package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -277
  274. package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +0 -96
  275. package/src/orchestration/__tests__/lifecycle.test.ts +0 -625
  276. package/src/orchestration/__tests__/review-fix-loop-e2e.test.ts +0 -1971
  277. package/src/orchestration/__tests__/script-lint.test.ts +0 -831
  278. package/src/orchestration/__tests__/skill-discovery.test.ts +0 -157
  279. package/src/orchestration/__tests__/test-mocks.ts +0 -197
  280. package/src/orchestration/__tests__/worker-host.test.ts +0 -120
  281. package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +0 -164
  282. package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +0 -520
  283. package/src/orchestration/__tests__/worker-script-builder.test.ts +0 -309
  284. package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +0 -110
  285. package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +0 -317
  286. package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +0 -110
  287. package/src/orchestration/__tests__/workflows-e2e.test.ts +0 -537
  288. package/src/orchestration/agent-opts-resolver.ts +0 -93
  289. package/src/orchestration/args-validator.ts +0 -127
  290. package/src/orchestration/concurrency-gate.ts +0 -69
  291. package/src/orchestration/config-loader.ts +0 -315
  292. package/src/orchestration/error-recovery.ts +0 -862
  293. package/src/orchestration/execute-agent-call.ts +0 -217
  294. package/src/orchestration/launcher.ts +0 -410
  295. package/src/orchestration/lifecycle.ts +0 -396
  296. package/src/orchestration/models/__tests__/budget.test.ts +0 -367
  297. package/src/orchestration/models/__tests__/trace.test.ts +0 -408
  298. package/src/orchestration/models/agent-call.ts +0 -83
  299. package/src/orchestration/models/budget.ts +0 -148
  300. package/src/orchestration/models/ports.ts +0 -164
  301. package/src/orchestration/models/run-runtime.ts +0 -89
  302. package/src/orchestration/models/run-spec.ts +0 -83
  303. package/src/orchestration/models/run-state.ts +0 -44
  304. package/src/orchestration/models/trace.ts +0 -183
  305. package/src/orchestration/models/types.ts +0 -292
  306. package/src/orchestration/models/workflow-run.ts +0 -254
  307. package/src/orchestration/models/workflow-script-registry.ts +0 -35
  308. package/src/orchestration/models/workflow-script.ts +0 -117
  309. package/src/orchestration/script-lint.ts +0 -766
  310. package/src/orchestration/skill-discovery.ts +0 -92
  311. package/src/orchestration/worker-handle.ts +0 -115
  312. package/src/orchestration/worker-host.ts +0 -98
  313. package/src/orchestration/worker-script-builder.ts +0 -408
  314. package/src/orchestration/workflow-files.ts +0 -85
  315. package/src/orchestration/workflow-script-registry-impl.ts +0 -133
  316. package/src/shared/__tests__/agent-ref.test.ts +0 -34
  317. package/src/shared/__tests__/meta-parser.test.ts +0 -304
  318. package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -280
  319. package/src/shared/__tests__/resource-discovery.test.ts +0 -736
  320. package/src/shared/__tests__/resource-meta.test.ts +0 -51
  321. package/src/shared/__tests__/schema-jsonify.test.ts +0 -81
  322. package/src/shared/agent-event.ts +0 -13
  323. package/src/shared/agent-ref.ts +0 -57
  324. package/src/shared/meta-parser.ts +0 -261
  325. package/src/shared/resource-discovery.ts +0 -811
  326. package/src/shared/resource-meta.ts +0 -65
  327. package/src/shared/schema-jsonify.ts +0 -56
  328. package/src/shared/xml-injection.ts +0 -35
  329. package/workflows/README.md +0 -81
  330. package/workflows/_shared/agent-refs.cjs +0 -40
  331. package/workflows/chain.js +0 -131
  332. package/workflows/map-reduce.js +0 -174
  333. package/workflows/parallel.js +0 -148
  334. package/workflows/review-fix-loop-utils.cjs +0 -1307
  335. package/workflows/review-fix-loop.js +0 -1396
  336. package/workflows/scatter-gather.js +0 -178
@@ -1,277 +0,0 @@
1
- /**
2
- * executeNestedWorkflow — workflow() 嵌套调用实现测试。
3
- *
4
- * 覆盖 6 个场景:循环检测、registry 未找到、lint 失败、成功执行、budget 同步、
5
- * 子 workflow 失败。
6
- *
7
- * 通过 vi.mock("../lifecycle.ts") 控制 runWorkflow:返回固定 runId + 把预构造的
8
- * child run 注入 deps.runs,使 pollRunToResult 首轮即命中 done 返回(无需真实 worker)。
9
- */
10
- import { beforeEach, describe, expect, it, vi } from "vitest";
11
-
12
- import { Budget } from "../models/budget.ts";
13
- import type { RunSpec } from "../models/run-spec.ts";
14
- import type { LauncherDeps } from "../launcher.ts";
15
- import type { LintResult } from "../script-lint.ts";
16
- import type { WorkflowRun } from "../models/workflow-run.ts";
17
- import type { WorkflowScript } from "../models/workflow-script.ts";
18
-
19
- // ── module mock:lifecycle.runWorkflow 由各 test 配置 ──────────────────
20
-
21
- vi.mock("../lifecycle.ts", () => ({
22
- runWorkflow: vi.fn(),
23
- abortRun: vi.fn(async () => {}),
24
- scheduleTimeBudget: vi.fn(() => undefined),
25
- }));
26
-
27
- // import 在 vi.mock 之后(hoisting 保证拿到 mock 版本)。runWorkflow 从被 mock 的
28
- // lifecycle 模块导入,与 launcher.ts 内部引用的是同一 mock 实例。
29
- import { runWorkflow } from "../lifecycle.ts";
30
- import { ArgsValidationError } from "../args-validator.ts";
31
- import { executeNestedWorkflow } from "../launcher.ts";
32
-
33
- const MOCK_RUN_ID = "wf-test-child";
34
-
35
- // ── helpers ──────────────────────────────────────────────────
36
-
37
- /** 构造 mock WorkflowScript(validate / toExecutable 可控)。 */
38
- function makeScript(opts: { valid?: boolean; lintErrorMsg?: string } = {}): WorkflowScript {
39
- const valid = opts.valid ?? true;
40
- return {
41
- name: "child-wf",
42
- path: "/fake/child-wf.js",
43
- meta: { name: "child-wf", description: "child workflow", phases: [] },
44
- toExecutable: () => "const meta = {}; execute() {}",
45
- validate: (): LintResult => ({
46
- valid,
47
- findings: valid
48
- ? []
49
- : [
50
- {
51
- severity: "error",
52
- line: 3,
53
- message: opts.lintErrorMsg ?? "lint boom",
54
- suggestion: "fix it",
55
- },
56
- ],
57
- }),
58
- } as unknown as WorkflowScript;
59
- }
60
-
61
- /**
62
- * 构造 mock parent WorkflowRun。
63
- *
64
- * parentBudget 用真实 Budget 实例(remaining() + 可写 usedTokens/usedCost)。
65
- * controller 提供 AbortSignal(默认未 abort)。
66
- */
67
- function makeParentRun(opts: {
68
- scriptName?: string;
69
- parentWorkflowChain?: readonly string[];
70
- budget?: Budget;
71
- aborted?: boolean;
72
- } = {}): WorkflowRun {
73
- const controller = new AbortController();
74
- if (opts.aborted) controller.abort();
75
- const spec = {
76
- scriptName: opts.scriptName ?? "parent-wf",
77
- parentWorkflowChain: opts.parentWorkflowChain,
78
- };
79
- return {
80
- spec,
81
- state: { budget: opts.budget ?? new Budget({ maxTokens: 10000 }) },
82
- runtime: { controller },
83
- } as unknown as WorkflowRun;
84
- }
85
-
86
- /**
87
- * 构造 mock child WorkflowRun(done 终态,pollRunToResult 首轮命中)。
88
- *
89
- * childBudget 用普通对象(仅需 usedTokens/usedCost 供 budget 同步读取)。
90
- */
91
- function makeDoneChildRun(opts: {
92
- reason?: "completed" | "failed" | "aborted";
93
- scriptResult?: unknown;
94
- error?: string;
95
- usedTokens?: number;
96
- usedCost?: number;
97
- }): WorkflowRun {
98
- const reason = opts.reason ?? "completed";
99
- return {
100
- runId: MOCK_RUN_ID,
101
- spec: { scriptName: "child-wf" },
102
- state: {
103
- status: "done",
104
- reason,
105
- scriptResult: opts.scriptResult,
106
- error: opts.error,
107
- budget: { usedTokens: opts.usedTokens ?? 0, usedCost: opts.usedCost ?? 0 },
108
- },
109
- } as unknown as WorkflowRun;
110
- }
111
-
112
- /** 构造 LauncherDeps mock:registry + runs(Map)+ 占位 port。 */
113
- function makeDeps(opts: {
114
- script?: WorkflowScript;
115
- childRun?: WorkflowRun;
116
- registry?: { getPath: ReturnType<typeof vi.fn> };
117
- } = {}): LauncherDeps {
118
- const runs = new Map<string, WorkflowRun>();
119
- if (opts.childRun) runs.set(MOCK_RUN_ID, opts.childRun);
120
- const registry = opts.registry ?? {
121
- getPath: vi.fn(async () => opts.script),
122
- };
123
- return {
124
- registry,
125
- runs,
126
- store: { save: vi.fn(async () => {}), loadAll: vi.fn(async () => []) },
127
- workerHost: { start: vi.fn(() => ({ postMessage: vi.fn() })) },
128
- runner: { run: vi.fn(async () => ({})) },
129
- log: vi.fn(),
130
- eventBus: { emit: vi.fn() },
131
- } as unknown as LauncherDeps;
132
- }
133
-
134
- /** 配置 runWorkflow mock:把 childRun 注入 deps.runs 并返回 MOCK_RUN_ID。 */
135
- function setupRunWorkflow(childRun: WorkflowRun): void {
136
- vi.mocked(runWorkflow).mockImplementation(async (_spec, deps) => {
137
- deps.runs.set(MOCK_RUN_ID, childRun);
138
- return MOCK_RUN_ID;
139
- });
140
- }
141
-
142
- beforeEach(() => {
143
- vi.clearAllMocks();
144
- });
145
-
146
- // ── tests ────────────────────────────────────────────────────
147
-
148
- describe("executeNestedWorkflow", () => {
149
- it("returns error result when workflow not found", async () => {
150
- const parent = makeParentRun();
151
- const signal = parent.runtime!.controller.signal;
152
- const addSpy = vi.spyOn(signal, "addEventListener");
153
- const removeSpy = vi.spyOn(signal, "removeEventListener");
154
- const deps = makeDeps({ script: undefined });
155
-
156
- const result = await executeNestedWorkflow("missing", {}, parent, deps);
157
-
158
- expect(result.error).toBe("Workflow 'missing' not found");
159
- expect(result.content).toBe("");
160
- expect(runWorkflow).not.toHaveBeenCalled();
161
- // E8:早返回也走 finally——Step 2 注册的 listener 被移除(原实现泄漏)
162
- expect(addSpy).toHaveBeenCalledTimes(1);
163
- expect(removeSpy).toHaveBeenCalledTimes(1);
164
- });
165
-
166
- it("returns error result on lint failure", async () => {
167
- const parent = makeParentRun();
168
- const deps = makeDeps({ script: makeScript({ valid: false, lintErrorMsg: "no entry point" }) });
169
-
170
- const result = await executeNestedWorkflow("child-wf", {}, parent, deps);
171
-
172
- expect(result.error).toContain("has lint errors");
173
- expect(result.error).toContain("no entry point");
174
- expect(result.content).toBe("");
175
- expect(runWorkflow).not.toHaveBeenCalled();
176
- });
177
-
178
- it("TC11: chokepoint 校验失败 → {error} + parentSignal listener 不泄漏(E8)", async () => {
179
- // 模块级 mock lifecycle:runWorkflow reject ArgsValidationError(真实实例——
180
- // launcher.ts 未被 mock,instanceof 检查命中同一 class)。
181
- vi.mocked(runWorkflow).mockRejectedValueOnce(
182
- new ArgsValidationError(
183
- "child-wf",
184
- "Invalid args for workflow 'child-wf': 1 error(s)\n- /target: is required\nRead the workflow script file (location from <available_workflows>) for the parameter schema and usage.",
185
- ),
186
- );
187
- const parent = makeParentRun();
188
- const signal = parent.runtime!.controller.signal;
189
- const addSpy = vi.spyOn(signal, "addEventListener");
190
- const removeSpy = vi.spyOn(signal, "removeEventListener");
191
- const deps = makeDeps({ script: makeScript() });
192
-
193
- const result = await executeNestedWorkflow("child-wf", {}, parent, deps);
194
-
195
- expect(result.content).toBe("");
196
- expect(result.error).toContain("Invalid args for workflow 'child-wf'");
197
- // Step 2 注册 1 次 + finally 移除 1 次 → 平衡即无泄漏(E8 修复点)
198
- expect(addSpy).toHaveBeenCalledTimes(1);
199
- expect(removeSpy).toHaveBeenCalledTimes(1);
200
- });
201
-
202
- it("detects circular call chain", async () => {
203
- // parent chain ["a"], parent scriptName "b", target name "a" → a→b→a 循环
204
- const parent = makeParentRun({
205
- scriptName: "b",
206
- parentWorkflowChain: ["a"],
207
- });
208
- const deps = makeDeps({ script: makeScript() });
209
-
210
- const result = await executeNestedWorkflow("a", {}, parent, deps);
211
-
212
- expect(result.error).toContain("Circular workflow call detected");
213
- expect(result.error).toContain("a → b → a");
214
- expect(result.content).toBe("");
215
- expect(runWorkflow).not.toHaveBeenCalled();
216
- });
217
-
218
- it("executes child workflow and returns result on success", async () => {
219
- const parent = makeParentRun();
220
- const childRun = makeDoneChildRun({
221
- reason: "completed",
222
- scriptResult: { summary: "done" },
223
- });
224
- const deps = makeDeps({ script: makeScript(), childRun });
225
- setupRunWorkflow(childRun);
226
-
227
- const result = await executeNestedWorkflow("child-wf", { k: 1 }, parent, deps);
228
-
229
- // content = JSON.stringify(scriptResult);parsedOutput 原样回传对象
230
- expect(result.error).toBeUndefined();
231
- expect(result.content).toBe(JSON.stringify({ summary: "done" }));
232
- expect(result.parsedOutput).toEqual({ summary: "done" });
233
- expect(runWorkflow).toHaveBeenCalledTimes(1);
234
- });
235
-
236
- it("shares parent budget reference with child run (no sync-back)", async () => {
237
- const parentBudget = new Budget({ maxTokens: 10000 });
238
- parentBudget.usedTokens = 100;
239
- const parent = makeParentRun({ budget: parentBudget });
240
- const childRun = makeDoneChildRun({
241
- reason: "completed",
242
- scriptResult: "ok",
243
- });
244
- const deps = makeDeps({ script: makeScript(), childRun });
245
-
246
- // 捕获传给 runWorkflow 的 spec——验证 budgetRef 共享父 Budget 引用
247
- let capturedSpec: RunSpec | undefined;
248
- vi.mocked(runWorkflow).mockImplementation(async (spec, d) => {
249
- capturedSpec = spec;
250
- d.runs.set(MOCK_RUN_ID, childRun);
251
- return MOCK_RUN_ID;
252
- });
253
-
254
- await executeNestedWorkflow("child-wf", {}, parent, deps);
255
-
256
- // 子 run 直接复用父 Budget 引用(budgetRef),而非独立 Budget + sync-back
257
- expect(capturedSpec?.budgetRef).toBe(parentBudget);
258
- expect(capturedSpec?.budgetTokens).toBeUndefined();
259
- // 无 sync-back:parent budget 不被 launcher 直接修改(mock 未真实 consume)
260
- expect(parent.state.budget.usedTokens).toBe(100);
261
- });
262
-
263
- it("returns error result when child workflow fails", async () => {
264
- const parent = makeParentRun();
265
- const childRun = makeDoneChildRun({
266
- reason: "failed",
267
- error: "agent exploded",
268
- });
269
- const deps = makeDeps({ script: makeScript(), childRun });
270
- setupRunWorkflow(childRun);
271
-
272
- const result = await executeNestedWorkflow("child-wf", {}, parent, deps);
273
-
274
- expect(result.content).toBe("");
275
- expect(result.error).toBe("agent exploded");
276
- });
277
- });
@@ -1,96 +0,0 @@
1
- /**
2
- * rfl 仪表 T2(tier-1 §7.1):引擎注入稳定 _runId。
3
- *
4
- * A3 runWorkflow 在 validateRunArgs 后向 spec.args 注入 _runId(值 = 返回的
5
- * runId)——runAndWait 与 executeNestedWorkflow 两个 args 入口共用的单一
6
- * choke point(lifecycle.ts runWorkflow)。
7
- * A4 rebuildRuntime 复用 run.spec.args 同一对象,_runId 跨 worker rebuild 不
8
- * 漂移(修复「rebuild 回退 run-<Date.now()> 导致 run 碎裂」)。
9
- */
10
- import { describe, expect, it, vi } from "vitest";
11
-
12
- import { rebuildRuntime } from "../error-recovery.ts";
13
- import { runWorkflow } from "../lifecycle.ts";
14
- import type { RunSpec } from "../models/run-spec.ts";
15
- import type { LifecycleDeps } from "../models/ports.ts";
16
-
17
- function makeSpec(args: Record<string, unknown> = {}): RunSpec {
18
- return {
19
- scriptSource: "module.exports = { execute: async () => 'ok' };",
20
- args,
21
- scriptName: "test-wf",
22
- scriptPath: "/fake/test.js",
23
- };
24
- }
25
-
26
- /** LifecycleDeps mock:workerHost.start 可观察(记录每次调用收到的 args 引用)。 */
27
- function makeRecordingDeps(): LifecycleDeps & {
28
- startCalls: Array<{ spec: RunSpec; args: Record<string, unknown> }>;
29
- } {
30
- const startCalls: Array<{ spec: RunSpec; args: Record<string, unknown> }> = [];
31
- const deps = {
32
- store: { save: vi.fn(async () => {}), loadAll: vi.fn(async () => []) },
33
- workerHost: {
34
- start: vi.fn((spec: RunSpec, args: Record<string, unknown>) => {
35
- startCalls.push({ spec, args });
36
- return { postMessage: vi.fn(), terminate: vi.fn(async () => {}) };
37
- }),
38
- },
39
- runner: { run: vi.fn(async () => ({})) },
40
- runs: new Map(),
41
- eventBus: { emit: vi.fn() },
42
- onRunDone: vi.fn(),
43
- log: vi.fn(),
44
- } as unknown as LifecycleDeps;
45
- return Object.assign(deps, { startCalls });
46
- }
47
-
48
- describe("A3 runWorkflow 注入 _runId(tier-1 §7.1)", () => {
49
- it("A3 runWorkflow 后 spec.args._runId === 返回的 runId(字符串),且 workerHost.start 收到同一值", async () => {
50
- const deps = makeRecordingDeps();
51
- const spec = makeSpec({ targetType: "file", target: "/tmp/x" });
52
- const runId = await runWorkflow(spec, deps);
53
- expect(runId).toBeTruthy();
54
- expect(spec.args._runId).toBe(runId);
55
- expect(typeof spec.args._runId).toBe("string");
56
- expect(deps.startCalls.length).toBe(1);
57
- expect(deps.startCalls[0].args._runId).toBe(runId);
58
- });
59
-
60
- it("A3 引擎注入覆盖用户预传的 _runId(非公开参数,引擎值权威)", async () => {
61
- const deps = makeRecordingDeps();
62
- const spec = makeSpec({ _runId: "user-supplied" });
63
- const runId = await runWorkflow(spec, deps);
64
- expect(runId).not.toBe("user-supplied");
65
- expect(spec.args._runId).toBe(runId);
66
- });
67
- });
68
-
69
- describe("A4 rebuild 后 _runId 稳定(tier-1 §7.1)", () => {
70
- it("A4 rebuildRuntime 第二次 workerHost.start 收到的 args._runId 非 undefined 且与首启一致(同一 args 对象)", async () => {
71
- const deps = makeRecordingDeps();
72
- const spec = makeSpec({ targetType: "file" });
73
- const runId = await runWorkflow(spec, deps);
74
- expect(deps.startCalls.length).toBe(1);
75
-
76
- const run = deps.runs.get(runId);
77
- expect(run).toBeTruthy();
78
- expect(run.state.status).toBe("running");
79
-
80
- // 触发 rebuild(对齐 error-recovery handleWorkerError 的恢复路径)
81
- rebuildRuntime(run, deps, {
82
- onMessage: vi.fn(),
83
- onError: vi.fn(),
84
- onExit: vi.fn(),
85
- });
86
-
87
- expect(deps.startCalls.length).toBe(2);
88
- const first = deps.startCalls[0].args;
89
- const second = deps.startCalls[1].args;
90
- expect(second._runId).not.toBeUndefined();
91
- expect(second._runId).toBe(first._runId);
92
- expect(second._runId).toBe(runId);
93
- // 同一对象引用(复用而非拷贝)——这是跨 rebuild 稳定的结构保证
94
- expect(second).toBe(first);
95
- });
96
- });