@zhushanwen/pi-subagent-workflow 8.6.0 → 8.8.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 (364) hide show
  1. package/README.md +5 -11
  2. package/package.json +13 -20
  3. package/relay/relay.mjs +1 -1
  4. package/skills/workflow-script-format/SKILL.md +32 -13
  5. package/src/host/__tests__/pi-host.test.ts +235 -0
  6. package/src/host/pi-host.ts +163 -0
  7. package/src/index.ts +141 -138
  8. package/src/injectors/__tests__/engine-awareness.test.ts +292 -0
  9. package/src/injectors/__tests__/engine-section-stability.test.ts +343 -0
  10. package/src/injectors/__tests__/model-list-injector.test.ts +18 -21
  11. package/src/injectors/__tests__/subagent-list-injector.test.ts +59 -19
  12. package/src/injectors/__tests__/workflow-list-injector.test.ts +31 -17
  13. package/src/injectors/engine-awareness.ts +119 -0
  14. package/src/injectors/model-list-injector.ts +15 -58
  15. package/src/injectors/subagent-list-injector.ts +56 -114
  16. package/src/injectors/workflow-list-injector.ts +37 -70
  17. package/src/interface/__tests__/detectors.test.ts +48 -37
  18. package/src/interface/__tests__/subagent-tool-path-guard.test.ts +2 -2
  19. package/src/interface/__tests__/subagent-tool-prompt.test.ts +6 -3
  20. package/src/interface/__tests__/tool-workflow-run-builtin-name.test.ts +216 -0
  21. package/src/interface/__tests__/tool-workflow-script-generate.test.ts +17 -6
  22. package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +38 -2
  23. package/src/interface/bg-notify-render.ts +7 -17
  24. package/src/interface/command-actions.ts +5 -15
  25. package/src/interface/commands.ts +4 -4
  26. package/src/interface/format.ts +17 -6
  27. package/src/interface/gui-mappers.ts +18 -22
  28. package/src/interface/helpers.ts +9 -130
  29. package/src/interface/list-component.ts +5 -5
  30. package/src/interface/list-shared.ts +3 -3
  31. package/src/interface/list-view.ts +3 -3
  32. package/src/interface/subagent-actions.ts +66 -439
  33. package/src/interface/subagent-tool-schema.ts +21 -17
  34. package/src/interface/subagent-tool.ts +12 -7
  35. package/src/interface/subagents.ts +4 -4
  36. package/src/interface/tool-render.ts +37 -15
  37. package/src/interface/tool-workflow-script.ts +34 -76
  38. package/src/interface/tool-workflow.ts +57 -94
  39. package/src/interface/views/WorkflowsView.ts +8 -16
  40. package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
  41. package/src/interface/views/__tests__/detail-content-session-file.test.ts +2 -2
  42. package/src/interface/views/detail-content.ts +4 -4
  43. package/src/interface/views/format.ts +23 -62
  44. package/src/{orchestration/jsonl-run-store.ts → jsonl-run-store.ts} +137 -225
  45. package/agents/analyst.md +0 -61
  46. package/agents/coder.md +0 -70
  47. package/agents/debugger.md +0 -67
  48. package/agents/doc-reviewer.md +0 -50
  49. package/agents/explorer.md +0 -64
  50. package/agents/general-purpose.md +0 -32
  51. package/agents/orchestrator.md +0 -63
  52. package/agents/planner.md +0 -54
  53. package/agents/researcher.md +0 -65
  54. package/agents/reviewer.md +0 -74
  55. package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +0 -53
  56. package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +0 -1
  57. package/src/execution/__tests__/agent-registry.test.ts +0 -363
  58. package/src/execution/__tests__/agent-result-mapper.test.ts +0 -150
  59. package/src/execution/__tests__/alive-store.test.ts +0 -147
  60. package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
  61. package/src/execution/__tests__/before-agent-start-injection.test.ts +0 -132
  62. package/src/execution/__tests__/bg-notify-render.test.ts +0 -329
  63. package/src/execution/__tests__/channel-registry-handshake.test.ts +0 -243
  64. package/src/execution/__tests__/chat-engine-routing.test.ts +0 -601
  65. package/src/execution/__tests__/chatmode-first-round-closure-service.test.ts +0 -365
  66. package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -190
  67. package/src/execution/__tests__/chatmode-round-notify-real-chain.test.ts +0 -215
  68. package/src/execution/__tests__/concurrency-pool.test.ts +0 -250
  69. package/src/execution/__tests__/config.test.ts +0 -110
  70. package/src/execution/__tests__/conversation-wiring.test.ts +0 -198
  71. package/src/execution/__tests__/crash-recovery.test.ts +0 -320
  72. package/src/execution/__tests__/delivery-methods.test.ts +0 -422
  73. package/src/execution/__tests__/dialog-queue.test.ts +0 -299
  74. package/src/execution/__tests__/epipe-fallback.test.ts +0 -241
  75. package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -243
  76. package/src/execution/__tests__/execute-nesting.test.ts +0 -323
  77. package/src/execution/__tests__/execute-options-mapper.test.ts +0 -200
  78. package/src/execution/__tests__/execution-record.test.ts +0 -1394
  79. package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +0 -171
  80. package/src/execution/__tests__/finalize-record.test.ts +0 -368
  81. package/src/execution/__tests__/finalized-marker.test.ts +0 -82
  82. package/src/execution/__tests__/format-schema-instruction.test.ts +0 -169
  83. package/src/execution/__tests__/format.test.ts +0 -458
  84. package/src/execution/__tests__/gc-timer.test.ts +0 -184
  85. package/src/execution/__tests__/get-record-for-action-restart.test.ts +0 -254
  86. package/src/execution/__tests__/gui-mode-dispatch.test.ts +0 -59
  87. package/src/execution/__tests__/helpers/mock-extension-api.ts +0 -30
  88. package/src/execution/__tests__/helpers/spawn-mock.ts +0 -242
  89. package/src/execution/__tests__/host-mode.test.ts +0 -87
  90. package/src/execution/__tests__/index-session-start-identity.test.ts +0 -371
  91. package/src/execution/__tests__/index-session-start.test.ts +0 -672
  92. package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
  93. package/src/execution/__tests__/lifecycle-manager.test.ts +0 -383
  94. package/src/execution/__tests__/lifecycle-predicates.test.ts +0 -116
  95. package/src/execution/__tests__/list-component.test.ts +0 -401
  96. package/src/execution/__tests__/list-fields.test.ts +0 -140
  97. package/src/execution/__tests__/manifest-parentid.test.ts +0 -117
  98. package/src/execution/__tests__/model-resolver.test.ts +0 -465
  99. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +0 -287
  100. package/src/execution/__tests__/nested-visibility.test.ts +0 -325
  101. package/src/execution/__tests__/notifier-flush.test.ts +0 -612
  102. package/src/execution/__tests__/notifier-golden-snapshot.test.ts +0 -261
  103. package/src/execution/__tests__/notify-ledger.test.ts +0 -826
  104. package/src/execution/__tests__/one-shot-upgrade.test.ts +0 -205
  105. package/src/execution/__tests__/output-collector.test.ts +0 -358
  106. package/src/execution/__tests__/parent-child-matrix.test.ts +0 -336
  107. package/src/execution/__tests__/path-encoding.test.ts +0 -104
  108. package/src/execution/__tests__/pi-invocation.test.ts +0 -134
  109. package/src/execution/__tests__/record-store.test.ts +0 -1057
  110. package/src/execution/__tests__/records-cwd-isolation.test.ts +0 -91
  111. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +0 -339
  112. package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -273
  113. package/src/execution/__tests__/relay-agent.test.ts +0 -448
  114. package/src/execution/__tests__/relay-env.test.ts +0 -42
  115. package/src/execution/__tests__/resource-policy.test.ts +0 -109
  116. package/src/execution/__tests__/rpc-mode.test.ts +0 -89
  117. package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -267
  118. package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -253
  119. package/src/execution/__tests__/run-spawn-edges.test.ts +0 -687
  120. package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
  121. package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
  122. package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
  123. package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +0 -199
  124. package/src/execution/__tests__/sdk-contract.test.ts +0 -273
  125. package/src/execution/__tests__/session-context-resolver.test.ts +0 -167
  126. package/src/execution/__tests__/session-file-gc.test.ts +0 -293
  127. package/src/execution/__tests__/session-pending.test.ts +0 -197
  128. package/src/execution/__tests__/session-reconstructor.test.ts +0 -379
  129. package/src/execution/__tests__/session-runner-epipe.test.ts +0 -178
  130. package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -350
  131. package/src/execution/__tests__/session-start-reaper.test.ts +0 -233
  132. package/src/execution/__tests__/spawn-args.test.ts +0 -445
  133. package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -189
  134. package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
  135. package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -207
  136. package/src/execution/__tests__/spawned-children.test.ts +0 -92
  137. package/src/execution/__tests__/start-sync-model-guard.test.ts +0 -150
  138. package/src/execution/__tests__/startup-config-declaration.test.ts +0 -35
  139. package/src/execution/__tests__/status-refactor.test.ts +0 -345
  140. package/src/execution/__tests__/stdin-writer.test.ts +0 -463
  141. package/src/execution/__tests__/stream-sink-retirement.test.ts +0 -261
  142. package/src/execution/__tests__/subagent-service-abort.test.ts +0 -60
  143. package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -629
  144. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +0 -180
  145. package/src/execution/__tests__/subagent-service.test.ts +0 -788
  146. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -310
  147. package/src/execution/__tests__/subprocess-agent-runner.test.ts +0 -599
  148. package/src/execution/__tests__/temp-prompt.test.ts +0 -53
  149. package/src/execution/__tests__/timeout-integration.test.ts +0 -615
  150. package/src/execution/__tests__/tombstone-store.test.ts +0 -73
  151. package/src/execution/__tests__/tool-action.test.ts +0 -476
  152. package/src/execution/__tests__/truncline-snapshot.test.ts +0 -81
  153. package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
  154. package/src/execution/__tests__/turn-limiter.test.ts +0 -65
  155. package/src/execution/__tests__/ui-channels.test.ts +0 -187
  156. package/src/execution/__tests__/ui-interaction-model.test.ts +0 -67
  157. package/src/execution/__tests__/ui-request-handler-factory.test.ts +0 -370
  158. package/src/execution/__tests__/ui-request-handler.test.ts +0 -204
  159. package/src/execution/__tests__/ui-request-observability.test.ts +0 -114
  160. package/src/execution/__tests__/ui-request-queue.test.ts +0 -133
  161. package/src/execution/__tests__/worktree-manager.test.ts +0 -633
  162. package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -229
  163. package/src/execution/__tests__/worktree-reconcile.integration.test.ts +0 -181
  164. package/src/execution/__tests__/worktree-registry.test.ts +0 -199
  165. package/src/execution/agent-registry.ts +0 -199
  166. package/src/execution/agent-result-mapper.ts +0 -90
  167. package/src/execution/alive-store.ts +0 -92
  168. package/src/execution/argv-mirror.ts +0 -113
  169. package/src/execution/best-effort.ts +0 -38
  170. package/src/execution/channel-registry-access.ts +0 -144
  171. package/src/execution/concurrency-pool.ts +0 -116
  172. package/src/execution/config.ts +0 -96
  173. package/src/execution/dialog-queue.ts +0 -330
  174. package/src/execution/engine/__tests__/common/data-dir.test.ts +0 -53
  175. package/src/execution/engine/__tests__/common/errors.test.ts +0 -132
  176. package/src/execution/engine/__tests__/common/event-journal.test.ts +0 -177
  177. package/src/execution/engine/__tests__/common/kill-chain.test.ts +0 -192
  178. package/src/execution/engine/__tests__/common/nesting-guard.test.ts +0 -81
  179. package/src/execution/engine/__tests__/common/persona-router.test.ts +0 -123
  180. package/src/execution/engine/__tests__/common/pool-manager.test.ts +0 -154
  181. package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
  182. package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
  183. package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +0 -141
  184. package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +0 -109
  185. package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +0 -101
  186. package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +0 -77
  187. package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +0 -104
  188. package/src/execution/engine/__tests__/conformance/contract.relay.test.ts +0 -342
  189. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +0 -201
  190. package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +0 -76
  191. package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +0 -79
  192. package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -87
  193. package/src/execution/engine/__tests__/engines-declaration.test.ts +0 -36
  194. package/src/execution/engine/__tests__/model-prompt.test.ts +0 -85
  195. package/src/execution/engine/__tests__/paths.test.ts +0 -39
  196. package/src/execution/engine/__tests__/registry.test.ts +0 -120
  197. package/src/execution/engine/__tests__/routing.test.ts +0 -231
  198. package/src/execution/engine/common/data-dir.ts +0 -62
  199. package/src/execution/engine/common/errors.ts +0 -183
  200. package/src/execution/engine/common/event-journal.ts +0 -254
  201. package/src/execution/engine/common/journal-replay.ts +0 -62
  202. package/src/execution/engine/common/kill-chain.ts +0 -221
  203. package/src/execution/engine/common/nesting-guard.ts +0 -50
  204. package/src/execution/engine/common/persona-router.ts +0 -108
  205. package/src/execution/engine/common/pool-manager.ts +0 -226
  206. package/src/execution/engine/common/schema-emulation.ts +0 -189
  207. package/src/execution/engine/common/session-view-projection.ts +0 -51
  208. package/src/execution/engine/engine-discovery.ts +0 -65
  209. package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -469
  210. package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
  211. package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
  212. package/src/execution/engine/engines/pi/pi-engine.ts +0 -415
  213. package/src/execution/engine/engines/pi/reader.ts +0 -48
  214. package/src/execution/engine/engines/pi/registration.ts +0 -35
  215. package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
  216. package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
  217. package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
  218. package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -246
  219. package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -228
  220. package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
  221. package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -64
  222. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -127
  223. package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -580
  224. package/src/execution/engine/engines/zcode/constants.ts +0 -43
  225. package/src/execution/engine/engines/zcode/golden-sample.ts +0 -39
  226. package/src/execution/engine/engines/zcode/launcher.ts +0 -161
  227. package/src/execution/engine/engines/zcode/parser.ts +0 -436
  228. package/src/execution/engine/engines/zcode/preparer.ts +0 -363
  229. package/src/execution/engine/engines/zcode/reader.ts +0 -381
  230. package/src/execution/engine/engines/zcode/registration.ts +0 -37
  231. package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -658
  232. package/src/execution/engine/host-task-spec.ts +0 -47
  233. package/src/execution/engine/model-prompt.ts +0 -59
  234. package/src/execution/engine/paths.ts +0 -42
  235. package/src/execution/engine/port.ts +0 -153
  236. package/src/execution/engine/registry.ts +0 -123
  237. package/src/execution/engine/routing.ts +0 -218
  238. package/src/execution/engine/types.ts +0 -309
  239. package/src/execution/execute-options-mapper.ts +0 -112
  240. package/src/execution/execution-record.ts +0 -965
  241. package/src/execution/finalize-record.ts +0 -251
  242. package/src/execution/finalized-marker.ts +0 -51
  243. package/src/execution/get-state-handshake.ts +0 -104
  244. package/src/execution/host-mode.ts +0 -56
  245. package/src/execution/idle-gc.ts +0 -47
  246. package/src/execution/lifecycle-manager.ts +0 -513
  247. package/src/execution/lifecycle-predicates.ts +0 -65
  248. package/src/execution/manifest-store.ts +0 -256
  249. package/src/execution/model-config-service.ts +0 -219
  250. package/src/execution/model-resolver.ts +0 -248
  251. package/src/execution/notifier.ts +0 -330
  252. package/src/execution/notify-ledger.ts +0 -580
  253. package/src/execution/output-collector.ts +0 -228
  254. package/src/execution/path-encoding.ts +0 -60
  255. package/src/execution/pi-invocation.ts +0 -120
  256. package/src/execution/record-entry.ts +0 -132
  257. package/src/execution/record-store.ts +0 -1234
  258. package/src/execution/relay-env.ts +0 -37
  259. package/src/execution/session-context-resolver.ts +0 -64
  260. package/src/execution/session-file-gc.ts +0 -120
  261. package/src/execution/session-pending.ts +0 -164
  262. package/src/execution/session-reconstructor.ts +0 -678
  263. package/src/execution/session-runner.ts +0 -1781
  264. package/src/execution/sessions-index.ts +0 -304
  265. package/src/execution/spawn-event-adapter.ts +0 -363
  266. package/src/execution/stdin-writer.ts +0 -198
  267. package/src/execution/stream-sink.ts +0 -126
  268. package/src/execution/subagent-service.ts +0 -2141
  269. package/src/execution/subprocess-agent-runner.ts +0 -317
  270. package/src/execution/temp-prompt.ts +0 -62
  271. package/src/execution/tombstone-store.ts +0 -72
  272. package/src/execution/turn-limiter.ts +0 -102
  273. package/src/execution/types.ts +0 -973
  274. package/src/execution/ui-channels.ts +0 -216
  275. package/src/execution/ui-interaction-model.ts +0 -48
  276. package/src/execution/ui-request-handler-factory.ts +0 -212
  277. package/src/execution/ui-request-observability.ts +0 -81
  278. package/src/execution/ui-request-queue.ts +0 -184
  279. package/src/execution/worktree-manager.ts +0 -688
  280. package/src/execution/worktree-registry.ts +0 -222
  281. package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +0 -349
  282. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +0 -202
  283. package/src/orchestration/__tests__/agent-call-stream.test.ts +0 -152
  284. package/src/orchestration/__tests__/args-validator.test.ts +0 -143
  285. package/src/orchestration/__tests__/config-loader.test.ts +0 -503
  286. package/src/orchestration/__tests__/error-recovery-handlers.test.ts +0 -809
  287. package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +0 -405
  288. package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +0 -56
  289. package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +0 -166
  290. package/src/orchestration/__tests__/execute-agent-call.test.ts +0 -451
  291. package/src/orchestration/__tests__/jsonl-run-store-corrupt-entry.test.ts +0 -150
  292. package/src/orchestration/__tests__/jsonl-run-store-loadall-sources.test.ts +0 -171
  293. package/src/orchestration/__tests__/jsonl-run-store-retention.test.ts +0 -202
  294. package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +0 -1030
  295. package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -600
  296. package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +0 -96
  297. package/src/orchestration/__tests__/lifecycle.test.ts +0 -659
  298. package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +0 -95
  299. package/src/orchestration/__tests__/review-fix-loop-e2e.test.ts +0 -2025
  300. package/src/orchestration/__tests__/script-lint.test.ts +0 -831
  301. package/src/orchestration/__tests__/skill-discovery.test.ts +0 -201
  302. package/src/orchestration/__tests__/test-mocks.ts +0 -197
  303. package/src/orchestration/__tests__/worker-exit-without-result.test.ts +0 -368
  304. package/src/orchestration/__tests__/worker-host.test.ts +0 -120
  305. package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +0 -164
  306. package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +0 -563
  307. package/src/orchestration/__tests__/worker-script-builder.test.ts +0 -309
  308. package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +0 -129
  309. package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +0 -317
  310. package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +0 -110
  311. package/src/orchestration/__tests__/workflows-e2e.test.ts +0 -537
  312. package/src/orchestration/agent-opts-resolver.ts +0 -174
  313. package/src/orchestration/args-validator.ts +0 -127
  314. package/src/orchestration/config-loader.ts +0 -315
  315. package/src/orchestration/error-recovery.ts +0 -1018
  316. package/src/orchestration/execute-agent-call.ts +0 -256
  317. package/src/orchestration/launcher.ts +0 -455
  318. package/src/orchestration/lifecycle.ts +0 -399
  319. package/src/orchestration/models/__tests__/budget.test.ts +0 -307
  320. package/src/orchestration/models/__tests__/trace.test.ts +0 -408
  321. package/src/orchestration/models/agent-call.ts +0 -83
  322. package/src/orchestration/models/budget.ts +0 -118
  323. package/src/orchestration/models/ports.ts +0 -164
  324. package/src/orchestration/models/run-runtime.ts +0 -104
  325. package/src/orchestration/models/run-spec.ts +0 -83
  326. package/src/orchestration/models/run-state.ts +0 -44
  327. package/src/orchestration/models/trace.ts +0 -183
  328. package/src/orchestration/models/types.ts +0 -301
  329. package/src/orchestration/models/workflow-run.ts +0 -254
  330. package/src/orchestration/models/workflow-script-registry.ts +0 -35
  331. package/src/orchestration/models/workflow-script.ts +0 -117
  332. package/src/orchestration/script-lint.ts +0 -766
  333. package/src/orchestration/skill-discovery.ts +0 -115
  334. package/src/orchestration/worker-handle.ts +0 -115
  335. package/src/orchestration/worker-host.ts +0 -98
  336. package/src/orchestration/worker-script-builder.ts +0 -421
  337. package/src/orchestration/workflow-files.ts +0 -85
  338. package/src/orchestration/workflow-script-registry-impl.ts +0 -133
  339. package/src/shared/__tests__/agent-ref.test.ts +0 -34
  340. package/src/shared/__tests__/meta-parser.test.ts +0 -304
  341. package/src/shared/__tests__/model-ref.test.ts +0 -306
  342. package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -280
  343. package/src/shared/__tests__/resource-discovery.test.ts +0 -736
  344. package/src/shared/__tests__/resource-meta.test.ts +0 -51
  345. package/src/shared/__tests__/schema-jsonify.test.ts +0 -81
  346. package/src/shared/__tests__/timer-delay.test.ts +0 -61
  347. package/src/shared/agent-event.ts +0 -13
  348. package/src/shared/agent-ref.ts +0 -57
  349. package/src/shared/meta-parser.ts +0 -261
  350. package/src/shared/model-ref.ts +0 -286
  351. package/src/shared/resource-discovery.ts +0 -811
  352. package/src/shared/resource-meta.ts +0 -65
  353. package/src/shared/schema-env.ts +0 -44
  354. package/src/shared/schema-jsonify.ts +0 -58
  355. package/src/shared/timer-delay.ts +0 -54
  356. package/src/shared/xml-injection.ts +0 -35
  357. package/workflows/README.md +0 -81
  358. package/workflows/_shared/agent-refs.cjs +0 -40
  359. package/workflows/chain.js +0 -131
  360. package/workflows/map-reduce.js +0 -174
  361. package/workflows/parallel.js +0 -148
  362. package/workflows/review-fix-loop-utils.cjs +0 -1309
  363. package/workflows/review-fix-loop.js +0 -1404
  364. package/workflows/scatter-gather.js +0 -178
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Subagent List Injector(迁移自 unified-hooks + P3/P4 改造)
2
+ * Subagent List Injector(迁移自 unified-hooks + P3/P4 改造;C5① 渲染改接 core)
3
3
  *
4
4
  * 发现所有可用 subagent(builtin + user + project 各源)并通过 before_agent_start
5
5
  * 每 turn 注入 `<available_subagents>` 段(name + description),让模型能选对 agent
@@ -7,15 +7,23 @@
7
7
  *
8
8
  * 改造点:
9
9
  * - P4:发现路径由自实现扫 4 目录改为同包 ADR-031 统一发现 discoverResources
10
- * (覆盖 7 源:user-pi/user-agents/npm/npm-dev/project-pi/project-agents + manifest
11
- * 模式 + 优先级合并)。discoverResources 只返回 DiscoveredResource(path/source/
10
+ * (P4 时点覆盖 7 源;C2 扩源后为统一发现全源 9 值 ResourceSource,含
11
+ * user-extension-paths/project-pi-tmp/project-host——序见 resource-discovery.ts
12
+ * 模块头注 + 优先级合并)。discoverResources 只返回 DiscoveredResource(path/source/
12
13
  * available),不含 name/description——保留 parseAgentFrontmatter 解析每个 .md 的
13
14
  * frontmatter 提取 name+description。
14
- * - P3:formatAgentList 开头补正向触发引导(何时该 delegate),保留原有「ONLY use
15
- * agent names from this list」名字约束。
15
+ * - P3:注入段引导语含正向触发引导(何时该 delegate)+ 名字约束(文案见
16
+ * SUBAGENT_LIST_GUIDE)。
17
+ * - C5①(convergence D-3):formatAgentList/sortByCodepoint 下沉 core,本文件改调
18
+ * core barrel(渲染骨架与条目模板逐字节同 pi 旧本地实现——CA2 快照验收前提);
19
+ * guide 文案是 pi 宿主注入(core 不内嵌平台文案)。
20
+ * - U11(sink 设计):装配循环(发现→解析→去重→排序 + warn/error 口径)整体改
21
+ * 消费 core discoverAgents(execution/agents-assembly,U2/A6)——壳侧收缩为
22
+ * 「宿主注入根现取 + 委托」,语义等值口径见 agents-assembly.ts 头注(⛔1 探针
23
+ * 对照注入 XML diff 为空验收)。
16
24
  *
17
- * 归位原因:injector 是 subagent-workflow 的内聚功能(让 LLM 知道有哪些 agent 可用),
18
- * 与同包 resource-discovery 同包后可直接 import,消除跨包依赖。
25
+ * 归位原因:injector 是 subagent-workflow 的内聚功能壳——事件接线与数据获取留
26
+ * 在插件层(before_agent_start / modelRegistry),解析/渲染算法消费 core。
19
27
  */
20
28
 
21
29
 
@@ -28,20 +36,38 @@ import type {
28
36
  SessionShutdownEvent,
29
37
  SessionStartEvent,
30
38
  } from "@earendil-works/pi-coding-agent";
31
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
32
39
  import { getLogger } from "@zhushanwen/pi-extension-logger";
33
40
 
41
+ import { getHostServices } from "@zhushanwen/subagent-core/core/host-services.ts";
42
+ // U11(sink 设计):agent 装配循环单源 core discoverAgents(U2/A6 装配函数,
43
+ // 深路径消费);渲染(formatAgentList)与 workspace 根推导(findWorkspaceRoot)
44
+ // 走 barrel,parseResourceMeta 仍服务 parseAgentFrontmatter(严格注入投影语义锚)。
45
+ // 上方 getHostServices 深路径刻意保留:core 服务定位器(core 内模块统一经它取用
46
+ // 宿主端口),barrel 刻意不导出(D5 exports 面即 semver 契约、逐名列出,未列名
47
+ // 的内部件不经 barrel——见 subagent-core src/index.ts 头注),壳侧深路径消费经包
48
+ // `./*` -> src 通配豁免。
34
49
  import {
35
- discoverResources,
50
+ type AgentEntry,
36
51
  findWorkspaceRoot,
37
- getCachedFileContent,
38
- getCachedParsed,
39
- } from "../shared/resource-discovery.ts";
40
- import { parseResourceMeta } from "../shared/meta-parser.ts";
41
- import { escapeXml, renderXmlSection } from "../shared/xml-injection.ts";
52
+ formatAgentList,
53
+ parseResourceMeta,
54
+ } from "@zhushanwen/subagent-core";
55
+ import { discoverAgents } from "@zhushanwen/subagent-core/execution/agents-assembly.ts";
42
56
 
43
57
  const logger = getLogger("injector");
44
58
 
59
+ /**
60
+ * pi 版注入引导文案(C5① guide 参数化——core 渲染函数不内嵌平台文案,宿主注入)。
61
+ *
62
+ * 2026-08 C5 重写依据(pi 现参数面,src/interface/subagent-tool-schema.ts):
63
+ * 旧句「pass systemPrompt alongside the agent name to create a dynamic agent」
64
+ * 指向的 systemPrompt 参数已不在 subagent tool schema——现 agent 参数 = .md 绝对
65
+ * 路径(<location>),缺省落 general-purpose(继承主 agent 模型与项目上下文),
66
+ * 动态指引经 task 文本 / appendSystemPrompt 参数承载。
67
+ */
68
+ export const SUBAGENT_LIST_GUIDE =
69
+ "The following subagents are available. PRIORITY: when a task involves reading 3+ files, writing 100+ lines, parallel research, or specialized review, delegate to a matching subagent FIRST instead of doing it yourself — this keeps your context focused on orchestration. Do NOT call list to discover available subagents; use list only for running state. When using the subagent tool, ONLY use agents from this list — pass the <location> path (absolute .md path) as the agent param. If no agent matches your task, omit agent (a general-purpose agent is used) and put all role-specific instructions in the task text.";
70
+
45
71
  /**
46
72
  * Session 级 agent 列表缓存(per-process = per-session)。
47
73
  *
@@ -63,17 +89,8 @@ let agentInjectionCache: string | null = null;
63
89
  /** agentCache 唯一写点:数据与渲染缓存同步更新(null 清空两者)。 */
64
90
  function setAgentCache(entries: AgentEntry[] | null): void {
65
91
  agentCache = entries;
66
- agentInjectionCache = entries !== null ? formatAgentList(entries) : null;
67
- }
68
-
69
- /** 从 .md frontmatter 提取的最小 agent 信息(m5:+ when/examples 路由样本;S1:+ path) */
70
- export interface AgentEntry {
71
- name: string;
72
- description: string;
73
- when?: string;
74
- examples?: Array<{ match: string; action: string; positive: boolean }>;
75
- /** agentRef:agent .md 文件的绝对路径(注入段 <location>,模型直接引用) */
76
- path: string;
92
+ agentInjectionCache =
93
+ entries !== null ? formatAgentList(entries, { guide: SUBAGENT_LIST_GUIDE }) : null;
77
94
  }
78
95
 
79
96
  /**
@@ -96,102 +113,29 @@ export function parseAgentFrontmatter(content: string): AgentEntry | null {
96
113
  }
97
114
 
98
115
  /**
99
- * 用统一资源发现(ADR-031)发现所有可用 agent
116
+ * 发现所有可用 agent(注入清单装配入口)。
100
117
  *
101
- * discoverResources 返回按文件名 stem 去重、优先级合并后的 DiscoveredResource[]
102
- * (project > user > builtin,返回顺序低→高优先级——Map 后写覆盖依赖此序,不可在
103
- * 发现层重排)。此处逐个解析 frontmatter 提取 name+description(经 getCachedParsed
104
- * mtime 级缓存),再按 agent name 去重(高优先级靠后,Map.set 后者覆盖前者,故最终
105
- * 保留最高优先级同名 agent)。
118
+ * U11(sink 设计):原手写装配循环(discoverResources 逐个 parseAgentFrontmatter
119
+ * 解析 agent name 去重(高优先级靠后 Map 后写胜)→ name 码点序排序 + warn/error
120
+ * 口径)整体改消费 core `discoverAgents`(U2/A6 装配函数)——解析/去重/排序/warn
121
+ * 口径单源 core,第三宿主免复刻(G3/S5)。等值口径(IF1 严格层可见性、warn 仅限
122
+ * 「有 frontmatter 但解析失败」、KV-cache 码点序契约:注入段进每 turn system
123
+ * prompt,顺序与 readdir 枚举序解耦,目录内容不变时任意重建渲染逐字节一致)登记见
124
+ * core execution/agents-assembly.ts 头注。
106
125
  *
107
- * 输出按 name 码点序排序(KV-cache 契约):注入段进每 turn system prompt,顺序必须
108
- * 与文件系统枚举序(readdir 无契约)解耦——目录内容不变时,session_start / fallback /
109
- * resume 任意重建的渲染结果逐字节一致;仅条目增减时文本才变化。
126
+ * 壳侧保留职责:签名(workspaceRoot 单参)与宿主注入根现取(pi discoveryRoots
127
+ * 每次现取 getAgentDir,实例隔离;agentDir 形参已删——其唯一用途就是喂 ScanConfig,
128
+ * u0-data-discovery 偏差 #7)。
110
129
  *
111
130
  * 永不抛错——发现本身 fail-safe,单个文件读失败仅记日志。
112
131
  */
113
132
  export async function discoverAllAgents(
114
133
  workspaceRoot: string,
115
- agentDir: string,
116
134
  ): Promise<AgentEntry[]> {
117
- const resources = await discoverResources({
118
- kind: "agents",
135
+ return discoverAgents(
119
136
  workspaceRoot,
120
- agentDir,
121
- });
122
-
123
- const agentMap = new Map<string, AgentEntry>();
124
- for (const resource of resources) {
125
- if (!resource.available) continue;
126
- try {
127
- const agent = getCachedParsed(resource.path, parseAgentFrontmatter);
128
- if (agent) {
129
- agentMap.set(agent.name, { ...agent, path: resource.path });
130
- } else if (startsWithFrontmatter(resource.path)) {
131
- // m5(评审 M3/F2 + minor-5):仅「有 frontmatter 但解析失败」才 warn
132
- // (缺 name/description/examples 单条非法致整体 reject)——README 等
133
- // 无 frontmatter 的 .md 不刷 warn(每 turn 扫描)。
134
- logger.warn(
135
- `[subagent-list-injector] ${resource.path}: agent frontmatter 解析失败(IF1 校验不通过)——agent 未注入`,
136
- );
137
- }
138
- } catch (err) {
139
- // 单个文件读失败不阻断整条 agent 列表注入
140
- logger.error(
141
- `[subagent-list-injector] skip unreadable agent file ${resource.path}`,
142
- { reason: err instanceof Error ? err.message : String(err) },
143
- );
144
- }
145
- }
146
- return sortByCodepoint([...agentMap.values()], (a) => a.name);
147
- }
148
-
149
- /** 码点序排序(显式契约,禁 localeCompare——宿主 locale 差异会破坏跨环境字节一致)。 */
150
- function sortByCodepoint<T>(items: T[], key: (item: T) => string): T[] {
151
- return items.sort((a, b) => {
152
- const ka = key(a);
153
- const kb = key(b);
154
- return ka < kb ? -1 : ka > kb ? 1 : 0;
155
- });
156
- }
157
-
158
- /** 内容以 frontmatter 分隔符开头(解析失败才值得 warn 的判据)。 */
159
- function startsWithFrontmatter(filePath: string): boolean {
160
- return (getCachedFileContent(filePath) ?? "").trimStart().startsWith("---");
161
- }
162
-
163
- /**
164
- * 将 agent 列表格式化为 XML 注入段。
165
- *
166
- * P3:引导语开头补正向触发条件(何时该 delegate),再保留原「ONLY use agent names
167
- * from this list」名字约束。空列表返回空串(不注入)。
168
- */
169
- export function formatAgentList(agents: AgentEntry[]): string {
170
- if (agents.length === 0) return "";
171
-
172
- const items = agents.map((agent) => {
173
- let block = ` <agent><name>${escapeXml(agent.name)}</name><description>${escapeXml(agent.description)}</description>`;
174
- // m5:路由样本(when + examples 正反原样渲染——negative 的 action 由作者写
175
- // 「不调用(原因)」,渲染器不硬编码;全部内容 escapeXml 防 XML 注入段破坏)
176
- if (agent.when) {
177
- block += `<when>${escapeXml(agent.when)}</when>`;
178
- }
179
- if (agent.examples && agent.examples.length > 0) {
180
- // 两极性原样渲染——negative 的 action 由作者写「不调用(原因)」,
181
- // 渲染器不硬编码后缀(exec-review major-1:曾追加「(不调用)」致双后缀)
182
- const exampleLines = agent.examples.map(
183
- (e) => ` - "${escapeXml(e.match)}" → ${escapeXml(e.action)}`,
184
- );
185
- block += `\n <examples>\n${exampleLines.join("\n")}\n </examples>`;
186
- }
187
- block += `<location>${escapeXml(agent.path)}</location></agent>`;
188
- return block;
189
- });
190
- return renderXmlSection({
191
- tag: "available_subagents",
192
- guide: "The following subagents are available. PRIORITY: when a task involves reading 3+ files, writing 100+ lines, parallel research, or specialized review, delegate to a matching subagent FIRST instead of doing it yourself — this keeps your context focused on orchestration. Do NOT call list to discover available subagents; use list only for running state. When using the subagent tool, ONLY use agent names from this list. If no agent matches your task, pass systemPrompt alongside the agent name to create a dynamic agent.",
193
- items,
194
- });
137
+ getHostServices().discoveryRoots?.()?.agents ?? [],
138
+ );
195
139
  }
196
140
 
197
141
  /**
@@ -214,7 +158,6 @@ export function setupSubagentListInjector(pi: ExtensionAPI): void {
214
158
  setAgentCache(
215
159
  await discoverAllAgents(
216
160
  findWorkspaceRoot(ctx.cwd),
217
- getAgentDir(),
218
161
  ),
219
162
  );
220
163
  } catch (err) {
@@ -238,7 +181,6 @@ export function setupSubagentListInjector(pi: ExtensionAPI): void {
238
181
  setAgentCache(
239
182
  await discoverAllAgents(
240
183
  findWorkspaceRoot(ctx.cwd),
241
- getAgentDir(),
242
184
  ),
243
185
  );
244
186
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Workflow List Injector(B2 / P1)
2
+ * Workflow List Injector(B2 / P1;C5① 渲染改接 core
3
3
  *
4
4
  * 发现所有可用 workflow(.js/.mjs)并通过 before_agent_start 每 turn 注入
5
5
  * `<available_workflows>` 段(name + description),与 subagent 注入段对称。
@@ -10,9 +10,13 @@
10
10
  * 实现要点:
11
11
  * - 发现走同包 ADR-031 统一发现 discoverResources({kind:"workflows", includeTmp:true})
12
12
  * (includeTmp 覆盖 .pi/workflows/.tmp/,即 workflow-script generate 的产物)
13
- * - 解析每个 workflow 的 `const meta = {name, description, ...}` 提取 name+description
13
+ * - 解析每个 workflow 的 meta 提取 name+description(IF1 parseResourceMeta)
14
14
  * - description 截断为 prompt 友好的摘要(builtin 的 review-fix-loop 描述超长,全量
15
- * 注入每 turn 会膨胀 prompt
15
+ * 注入每 turn 会膨胀 prompt)——summarizeDescription C5① 起改用 core barrel
16
+ * (算法逐字同本地旧实现)
17
+ * - C5①(convergence D-3):formatWorkflowList 下沉 core,本文件改调 core barrel
18
+ * (渲染骨架与条目模板逐字节同 pi 旧本地实现——CA2 快照验收前提);guide 文案
19
+ * 是 pi 宿主注入(core 不内嵌平台文案)
16
20
  */
17
21
 
18
22
 
@@ -25,16 +29,27 @@ import type {
25
29
  SessionShutdownEvent,
26
30
  SessionStartEvent,
27
31
  } from "@earendil-works/pi-coding-agent";
28
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
29
32
  import { getLogger } from "@zhushanwen/pi-extension-logger";
30
33
 
34
+ import { getHostServices } from "@zhushanwen/subagent-core/core/host-services.ts";
35
+ // C5①/C5⑦/C5b:发现与渲染统一走 core barrel——发现链辅助
36
+ // (resource-discovery/meta-parser 面:findWorkspaceRoot/getCachedParsed/
37
+ // parseResourceMeta)深路径 import 已归零。上方 getHostServices 深路径刻意
38
+ // 保留:core 服务定位器(core 内模块统一经它取用宿主端口),barrel 刻意不
39
+ // 导出(D5 exports 面即 semver 契约、逐名列出,未列名的内部件不经 barrel——
40
+ // 见 subagent-core src/index.ts 头注),壳侧深路径消费经包 `./*` -> src 通配豁免。
31
41
  import {
32
42
  discoverResources,
33
43
  findWorkspaceRoot,
44
+ formatWorkflowList,
34
45
  getCachedParsed,
35
- } from "../shared/resource-discovery.ts";
36
- import { parseResourceMeta } from "../shared/meta-parser.ts";
37
- import { escapeXml, renderXmlSection } from "../shared/xml-injection.ts";
46
+ parseResourceMeta,
47
+ summarizeDescription,
48
+ type WorkflowEntry,
49
+ } from "@zhushanwen/subagent-core";
50
+ // U11(sink 设计):注入清单排序码点序单源——深路径消费 core sortByCodepoint
51
+ // (与 barrel 版同一实现,深路径遵循任务指定消费形态;`./*` -> src 通配豁免)。
52
+ import { sortByCodepoint } from "@zhushanwen/subagent-core/shared/injection-render.ts";
38
53
 
39
54
  const logger = getLogger("injector");
40
55
 
@@ -53,44 +68,19 @@ let workflowInjectionCache: string | null = null;
53
68
  /** workflowCache 唯一写点:数据与渲染缓存同步更新(null 清空两者)。 */
54
69
  function setWorkflowCache(entries: WorkflowEntry[] | null): void {
55
70
  workflowCache = entries;
56
- workflowInjectionCache = entries !== null ? formatWorkflowList(entries) : null;
57
- }
58
-
59
- /** 注入段中单个 workflow 的最大描述长度(控制每 turn prompt 体积) */
60
- const MAX_DESC_LEN = 160;
61
-
62
- /** 断句阈值比例:句末标点位置须 >= maxLen 的 40% 才采用,否则硬截断保留更多信息 */
63
- const DESC_BOUNDARY_MIN_RATIO = 0.4;
64
-
65
- /** 解析后的 workflow 条目(name + 截断后的 description + agentRef 路径) */
66
- export interface WorkflowEntry {
67
- name: string;
68
- description: string;
69
- /** workflowRef:脚本 .js 文件的绝对路径(注入段 <location>,模型直接引用) */
70
- path: string;
71
+ workflowInjectionCache =
72
+ entries !== null ? formatWorkflowList(entries, { guide: WORKFLOW_LIST_GUIDE }) : null;
71
73
  }
72
74
 
73
75
  /**
74
- * workflow description 截断为 prompt 友好的摘要。
75
- * 优先在 limit 内的最后一个句末标点处断句;无合适断点则硬截断 + 省略号。
76
+ * pi 版注入引导文案(C5① guide 参数化——core 渲染函数不内嵌平台文案,宿主注入;
77
+ * 文案与改造前本地实现逐字一致——workflow guide 无过期问题)。
78
+ *
79
+ * 引导语与具体 workflow 解耦:不写死内置名(列表本身已含全部 workflow,名字/描述
80
+ * 每 turn 由 @pi-meta 动态注入),只给通用路由指引 + read location 参数指针。
76
81
  */
77
- export function summarizeDescription(
78
- desc: string,
79
- maxLen = MAX_DESC_LEN,
80
- ): string {
81
- const trimmed = desc.trim();
82
- if (trimmed.length <= maxLen) return trimmed;
83
- const slice = trimmed.slice(0, maxLen);
84
- const boundary = Math.max(
85
- slice.lastIndexOf("。"),
86
- slice.lastIndexOf(";"),
87
- slice.lastIndexOf(";"),
88
- slice.lastIndexOf(". "),
89
- );
90
- // 断点过靠前(< 阈值比例)时不采用,改硬截断保留更多信息
91
- if (boundary > maxLen * DESC_BOUNDARY_MIN_RATIO) return slice.slice(0, boundary + 1);
92
- return `${slice}…`;
93
- }
82
+ export const WORKFLOW_LIST_GUIDE =
83
+ "The following workflows are available. Do NOT call list to discover available workflows — they are listed below; use list only for running state. All listed workflows run directly via action:run — do NOT use workflow-script generate for any listed workflow. For parameter details, read the <location> script file (script header has @pi-meta parameters + usage).";
94
84
 
95
85
  /**
96
86
  * 解析 workflow .js 文件的 meta(name + description),经 IF1 parseResourceMeta。
@@ -114,12 +104,13 @@ export function parseWorkflowMeta(content: string): WorkflowEntry | null {
114
104
  */
115
105
  export async function discoverAllWorkflows(
116
106
  workspaceRoot: string,
117
- agentDir: string,
118
107
  ): Promise<WorkflowEntry[]> {
119
108
  const resources = await discoverResources({
120
109
  kind: "workflows",
121
110
  workspaceRoot,
122
- agentDir,
111
+ // 宿主注入根现取(pi 壳 discoveryRoots 每次现取 getAgentDir,实例隔离);
112
+ // agentDir 形参已删——其唯一用途就是喂 ScanConfig(u0-data-discovery 偏差 #7)
113
+ hostRoots: getHostServices().discoveryRoots?.()?.workflows ?? [],
123
114
  includeTmp: true,
124
115
  });
125
116
 
@@ -136,31 +127,9 @@ export async function discoverAllWorkflows(
136
127
  );
137
128
  }
138
129
  }
139
- return [...map.values()].sort((a, b) =>
140
- a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
141
- );
142
- }
143
-
144
- /**
145
- * 将 workflow 列表格式化为 XML 注入段。
146
- *
147
- * 引导语对齐 subagent injector:workflow 已在下方列出,模型应直接 run;
148
- * list 仅用于查询运行态。builtin workflow 点名「run directly」。
149
- * 空列表返回空串(不注入)。
150
- */
151
- export function formatWorkflowList(workflows: WorkflowEntry[]): string {
152
- if (workflows.length === 0) return "";
153
-
154
- const items = workflows.map((wf) =>
155
- ` <workflow><name>${escapeXml(wf.name)}</name><description>${escapeXml(wf.description)}</description><location>${escapeXml(wf.path)}</location></workflow>`,
156
- );
157
- return renderXmlSection({
158
- tag: "available_workflows",
159
- // 引导语与具体 workflow 解耦:不写死内置名(列表本身已含全部 workflow,
160
- // 名字/描述每 turn 由 @pi-meta 动态注入),只给通用路由指引 + read location 参数指针。
161
- guide: "The following workflows are available. Do NOT call list to discover available workflows — they are listed below; use list only for running state. All listed workflows run directly via action:run — do NOT use workflow-script generate for any listed workflow. For parameter details, read the <location> script file (script header has @pi-meta parameters + usage).",
162
- items,
163
- });
130
+ // U11:内联码点序 sort 折叠为 core sortByCodepoint(实现逐字等价——同比较器
131
+ // 语义:ka < kb ? -1 : ka > kb ? 1 : 0,非变异副本排序)
132
+ return sortByCodepoint([...map.values()], (a) => a.name);
164
133
  }
165
134
 
166
135
  /**
@@ -178,7 +147,6 @@ export function setupWorkflowListInjector(pi: ExtensionAPI): void {
178
147
  setWorkflowCache(
179
148
  await discoverAllWorkflows(
180
149
  findWorkspaceRoot(ctx.cwd),
181
- getAgentDir(),
182
150
  ),
183
151
  );
184
152
  } catch (err) {
@@ -202,7 +170,6 @@ export function setupWorkflowListInjector(pi: ExtensionAPI): void {
202
170
  setWorkflowCache(
203
171
  await discoverAllWorkflows(
204
172
  findWorkspaceRoot(ctx.cwd),
205
- getAgentDir(),
206
173
  ),
207
174
  );
208
175
  }
@@ -17,63 +17,73 @@ import { describe, expect, it } from "vitest";
17
17
  import { readFileSync } from "node:fs";
18
18
  import { join } from "node:path";
19
19
 
20
- import { argKeysFromMeta, findFlattenedArgKeys } from "../tool-workflow";
21
- import { parseResourceMeta } from "../../shared/meta-parser.ts";
20
+ // D9 下沉后权威实现迁至 core args-meta——宿主差异(TOOL_TOP_LEVEL 撞名保护)经
21
+ // reservedKeys 注入,与 tool-workflow 调用点保持同一契约。
22
+ import {
23
+ argKeysFromMeta,
24
+ findFlattenedArgKeys,
25
+ } from "@zhushanwen/subagent-core/orchestration/args-meta.ts";
26
+ import { TOOL_TOP_LEVEL } from "../tool-workflow";
27
+ import { parseResourceMeta } from "@zhushanwen/subagent-core/shared/meta-parser.ts";
22
28
 
23
- // 真实参数集(argKeysFromMeta 产物——m6 动态数据源,与 TC2 同源防漂移)
24
- function rflKeys() {
25
- const src = readFileSync(join(__dirname, "../../../workflows/review-fix-loop.js"), "utf-8");
29
+ // 宿主 reservedKeys 注入(与 tool-workflow ARGS_META_OPTIONS 等值契约)
30
+ const OPT = { reservedKeys: TOOL_TOP_LEVEL };
31
+
32
+ // 真实参数 meta(@pi-meta parameters——m6 动态数据源,与 TC2 同源防漂移)
33
+ function rflMeta() {
34
+ const src = readFileSync(join(__dirname, "../../../node_modules/@zhushanwen/subagent-core/workflows/review-fix-loop.js"), "utf-8");
26
35
  const meta = parseResourceMeta(src, "workflow");
27
36
  if (!meta || meta.kind !== "workflow" || !meta.parameters) throw new Error("rfl meta");
28
- return argKeysFromMeta(meta.parameters);
37
+ return meta.parameters;
29
38
  }
30
- function chainKeys() {
31
- const src = readFileSync(join(__dirname, "../../../workflows/chain.js"), "utf-8");
39
+ function chainMeta() {
40
+ const src = readFileSync(join(__dirname, "../../../node_modules/@zhushanwen/subagent-core/workflows/chain.js"), "utf-8");
32
41
  const meta = parseResourceMeta(src, "workflow");
33
42
  if (!meta || meta.kind !== "workflow" || !meta.parameters) throw new Error("chain meta");
34
- return argKeysFromMeta(meta.parameters);
43
+ return meta.parameters;
35
44
  }
36
- const RFL = rflKeys();
37
- const CHAIN = chainKeys();
45
+ const RFL = rflMeta();
46
+ const CHAIN = chainMeta();
38
47
 
39
48
  describe("findFlattenedArgKeys (workflow args flatten detector — P0)", () => {
40
49
  it("TC3a: trigger——chain 参数集平铺 task 被识别;跨 workflow 区分(items 非 chain 参数不触发)", () => {
41
50
  expect(
42
- findFlattenedArgKeys({ action: "run", name: "chain", task: "x" }, CHAIN.exact, CHAIN.patterns),
51
+ findFlattenedArgKeys({ action: "run", name: "chain", task: "x" }, CHAIN, OPT),
43
52
  ).toEqual(["task"]);
44
53
  // 跨 workflow:items 是 map-reduce 参数非 chain 参数 → 不触发(m6 动态集语义)
45
54
  expect(
46
- findFlattenedArgKeys({ action: "run", name: "chain", items: ["a"] }, CHAIN.exact, CHAIN.patterns),
55
+ findFlattenedArgKeys({ action: "run", name: "chain", items: ["a"] }, CHAIN, OPT),
47
56
  ).toEqual([]);
48
57
  });
49
58
 
50
59
  it("TC3b: 嵌套 args 不触发", () => {
51
60
  expect(
52
- findFlattenedArgKeys({ action: "run", name: "x", args: { task: "x", items: ["a"] } }, CHAIN.exact, CHAIN.patterns),
61
+ findFlattenedArgKeys({ action: "run", name: "x", args: { task: "x", items: ["a"] } }, CHAIN, OPT),
53
62
  ).toEqual([]);
54
63
  });
55
64
 
56
65
  it("TC3c: 顶层 + args 内共存不触发(args-排除保留)", () => {
57
66
  expect(
58
- findFlattenedArgKeys({ action: "run", name: "x", args: { task: "x" }, task: "y" }, CHAIN.exact, CHAIN.patterns),
67
+ findFlattenedArgKeys({ action: "run", name: "x", args: { task: "x" }, task: "y" }, CHAIN, OPT),
59
68
  ).toEqual([]);
60
69
  });
61
70
 
62
71
  it("TC3d: 无已知键不触发;空集不触发", () => {
63
72
  expect(
64
- findFlattenedArgKeys({ action: "run", name: "x", args: {} }, CHAIN.exact, CHAIN.patterns),
73
+ findFlattenedArgKeys({ action: "run", name: "x", args: {} }, CHAIN, OPT),
65
74
  ).toEqual([]);
75
+ // meta undefined → 空键集(原「空集不触发」等价形态)
66
76
  expect(
67
- findFlattenedArgKeys({ action: "status" }, new Set(), []),
77
+ findFlattenedArgKeys({ action: "status" }, undefined),
68
78
  ).toEqual([]);
69
79
  });
70
80
 
71
81
  it("TC3e: review-fix-loop fixAgent 平铺被识别(动态集 exact)", () => {
72
82
  expect(
73
- findFlattenedArgKeys({ action: "run", name: "review-fix-loop", fixAgent: "worker" }, RFL.exact, RFL.patterns),
83
+ findFlattenedArgKeys({ action: "run", name: "review-fix-loop", fixAgent: "worker" }, RFL, OPT),
74
84
  ).toEqual(["fixAgent"]);
75
85
  expect(
76
- findFlattenedArgKeys({ action: "run", name: "review-fix-loop", args: { fixAgent: "worker" } }, RFL.exact, RFL.patterns),
86
+ findFlattenedArgKeys({ action: "run", name: "review-fix-loop", args: { fixAgent: "worker" } }, RFL, OPT),
77
87
  ).toEqual([]);
78
88
  });
79
89
 
@@ -81,27 +91,27 @@ describe("findFlattenedArgKeys (workflow args flatten detector — P0)", () => {
81
91
  expect(
82
92
  findFlattenedArgKeys(
83
93
  { action: "run", name: "review-fix-loop", targetType: "git-diff", target: "main" },
84
- RFL.exact,
85
- RFL.patterns,
94
+ RFL,
95
+ OPT,
86
96
  ),
87
97
  ).toEqual(["targetType", "target"]);
88
98
  expect(
89
99
  findFlattenedArgKeys(
90
100
  { action: "run", name: "review-fix-loop", batch1: "reviewer", autoCommit: true },
91
- RFL.exact,
92
- RFL.patterns,
101
+ RFL,
102
+ OPT,
93
103
  ),
94
104
  ).toEqual(["batch1", "autoCommit"]);
95
105
  expect(
96
106
  findFlattenedArgKeys(
97
107
  { action: "run", name: "review-fix-loop", args: { targetType: "git-diff", target: "main" } },
98
- RFL.exact,
99
- RFL.patterns,
108
+ RFL,
109
+ OPT,
100
110
  ),
101
111
  ).toEqual([]);
102
112
  // batchl 拼错(非数字后缀)不触发(m6 评审 C-1:pattern 自带数字后缀校验)
103
113
  expect(
104
- findFlattenedArgKeys({ action: "run", name: "x", batchl: "reviewer" }, RFL.exact, RFL.patterns),
114
+ findFlattenedArgKeys({ action: "run", name: "x", batchl: "reviewer" }, RFL, OPT),
105
115
  ).toEqual([]);
106
116
  });
107
117
 
@@ -109,42 +119,43 @@ describe("findFlattenedArgKeys (workflow args flatten detector — P0)", () => {
109
119
  expect(
110
120
  findFlattenedArgKeys(
111
121
  { action: "run", name: "review-fix-loop", model: "ds-flash", maxFixAttempts: 3, convergeNewIssues: 2, convergeRounds: 3 },
112
- RFL.exact,
113
- RFL.patterns,
122
+ RFL,
123
+ OPT,
114
124
  ),
115
125
  ).toEqual(["maxFixAttempts", "convergeNewIssues", "convergeRounds"]);
116
126
  expect(
117
127
  findFlattenedArgKeys(
118
128
  { action: "run", name: "review-fix-loop", args: { model: "ds-flash", maxFixAttempts: 3 }, convergeRounds: 3 },
119
- RFL.exact,
120
- RFL.patterns,
129
+ RFL,
130
+ OPT,
121
131
  ),
122
132
  ).toEqual(["convergeRounds"]);
123
133
  });
124
134
 
125
135
  it("TC3h: non-object 输入返回 []", () => {
126
- expect(findFlattenedArgKeys(null, new Set(), [])).toEqual([]);
127
- expect(findFlattenedArgKeys(undefined, new Set(), [])).toEqual([]);
136
+ expect(findFlattenedArgKeys(null)).toEqual([]);
137
+ expect(findFlattenedArgKeys(undefined)).toEqual([]);
128
138
  });
129
139
 
130
140
  it("TC3i: tool 顶层键不误报(M-3 回归——合成 parameters 直测 argKeysFromMeta 排除)", () => {
131
141
  // 合成 parameters:workflow 声明参数 name(tool 键撞名)——argKeysFromMeta 必须排除
132
- const keys = argKeysFromMeta({
142
+ const synthetic = {
133
143
  type: "object",
134
144
  properties: { name: { type: "string" }, task: { type: "string" } },
135
145
  required: ["name"],
136
- });
146
+ };
147
+ const keys = argKeysFromMeta(synthetic, OPT);
137
148
  expect(keys.exact.has("task")).toBe(true);
138
149
  expect(keys.exact.has("name")).toBe(false); // TOOL_TOP_LEVEL 排除(M-3 真回归锁定)
139
150
  // 合法调用不误报
140
151
  expect(
141
152
  findFlattenedArgKeys(
142
153
  { action: "run", name: "mywf", args: { name: "x" } },
143
- keys.exact,
144
- keys.patterns,
154
+ synthetic,
155
+ OPT,
145
156
  ),
146
157
  ).toEqual([]);
147
158
  // 真实 meta 不含 name(探针实测 16 键)——附加验证
148
- expect(RFL.exact.has("name")).toBe(false);
159
+ expect(argKeysFromMeta(RFL, OPT).exact.has("name")).toBe(false);
149
160
  });
150
161
  });
@@ -39,12 +39,12 @@ vi.mock("typebox", () => ({
39
39
  const { mockServiceExecute } = vi.hoisted(() => ({
40
40
  mockServiceExecute: vi.fn(),
41
41
  }));
42
- vi.mock("../../execution/subagent-service.ts", () => ({
42
+ vi.mock("@zhushanwen/subagent-core/execution/subagent-service.ts", () => ({
43
43
  getSubagentService: () => ({ execute: mockServiceExecute }),
44
44
  }));
45
45
 
46
46
  import { registerSubagentTool } from "../../interface/subagent-tool.ts";
47
- import { mockExtensionApi } from "../../execution/__tests__/helpers/mock-extension-api.ts";
47
+ import { mockExtensionApi } from "@zhushanwen/subagent-core/execution/__tests__/helpers/mock-extension-api.ts";
48
48
 
49
49
  type ExecuteCb = (...args: unknown[]) => Promise<unknown>;
50
50
 
@@ -12,6 +12,7 @@
12
12
  import { readFileSync } from "node:fs";
13
13
  import { dirname,join } from "node:path";
14
14
  import { fileURLToPath } from "node:url";
15
+ import { createRequire } from "node:module";
15
16
 
16
17
  import { describe, expect, it } from "vitest";
17
18
 
@@ -153,12 +154,14 @@ describe("subagent tool runtime handler — 错误文案含纠正正例", () =>
153
154
  // 让弱模型撞错后第二次能直接照抄正确形态。
154
155
  // 拍平后:startParam envelope 删除,平铺 task/slug 是合法形态;
155
156
  // 平铺检测 guard(hasFlattenedStartFields)已删除,源码不应再含此表达式。
156
- it("subagent-actions.ts startHandler throw 含 Correct 纠正正例(平铺形态)", () => {
157
+ it("startHandler throw 含 Correct 纠正正例(平铺形态)", () => {
158
+ // [D6②] startHandler 内核(含 Correct 文案)已下沉 core subagent-actions-core,
159
+ // 断言目标跟随文案权威源(resolve 方式同 prompt-quality-batch1 U4 先例)。
157
160
  const actionsSrc = readFileSync(
158
- join(__dirname, "../subagent-actions.ts"),
161
+ createRequire(import.meta.url).resolve("@zhushanwen/subagent-core/execution/subagent-actions-core.ts"),
159
162
  "utf-8",
160
163
  );
161
- // 三处 throw(input 缺失 / task 空白 / slug 空白)都应含 Correct 正例。
164
+ // 四处 throw(input 缺失 / task 空白 / slug 空白 / slug 超长)都应含 Correct 正例。
162
165
  // 用 occurrences 计数——至少 3 处。
163
166
  const occurrences = (actionsSrc.match(/Correct: \{"action":"start"/g) ?? []).length;
164
167
  expect(occurrences).toBeGreaterThanOrEqual(3);