@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,215 +0,0 @@
1
- // src/execution/__tests__/chatmode-round-notify-real-chain.test.ts
2
- //
3
- // [N2] chatMode 轮次通知正文——真实 session-runner 链路测试。
4
- //
5
- // round2 审查实证的断链:agent_settled → onRoundSettled 先 notifyComplete(此时
6
- // record.result 从未被写——成功轮次的 MF-2 原写点 doFinalizeRoundToIdle 对
7
- // runAndFinalize early return 不可达)→ 轮次通知正文恒 "(empty)",turns[].text 已累积
8
- // 但 notify 读的是 record.result。修复:onRoundSettled 在 notify 前从本轮 turns 派生
9
- // 回复文本(对齐 collectResult 的 getFullText)写入 record.result。
10
- //
11
- // 与 chatmode-first-round-closure-service.test.ts(mock session-runner)不同,本文件用
12
- // 真实 session-runner(FakeChild 驱动 text_delta / agent_settled)+ 真实
13
- // service.execute(conversation:true),禁止手工预置 record.result——那正是掩盖断链的方式。
14
- // mock 结构与 run-spawn-chatmode-settled.test.ts 一致(FakeChild + session-pending count=0)。
15
-
16
- import { spawn } from "node:child_process";
17
- import * as fs from "node:fs";
18
- import * as os from "node:os";
19
- import * as path from "node:path";
20
-
21
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
-
23
- const { loggerMock } = vi.hoisted(() => ({
24
- loggerMock: { debug: vi.fn(), warn: vi.fn(), error: vi.fn(), info: vi.fn() },
25
- }));
26
- vi.mock("@zhushanwen/pi-extension-logger", () => ({ getLogger: () => loggerMock }));
27
-
28
- vi.mock("node:child_process", async () => {
29
- const { FakeChild } = await import("./helpers/spawn-mock.ts");
30
- return {
31
- spawn: vi.fn(() => new FakeChild()),
32
- // buildEnvBlock 的 git branch 调用(execFile 异步):默认 err-first 兜底 → catch → branch=""
33
- execFile: vi.fn(
34
- (
35
- _cmd: string,
36
- _args: readonly string[],
37
- _opts: unknown,
38
- cb: (err: Error | null, stdout?: string, stderr?: string) => void,
39
- ) => cb(new Error("execFile not configured in this test")),
40
- ),
41
- };
42
- });
43
-
44
- vi.mock("node:fs", async () => {
45
- const actual = await import("node:fs");
46
- return {
47
- default: {
48
- ...actual,
49
- mkdirSync: vi.fn(),
50
- existsSync: vi.fn(() => false),
51
- appendFileSync: vi.fn(),
52
- writeFileSync: vi.fn(),
53
- readdirSync: vi.fn(() => []),
54
- },
55
- mkdirSync: vi.fn(),
56
- existsSync: vi.fn(() => false),
57
- appendFileSync: vi.fn(),
58
- writeFileSync: vi.fn(),
59
- readdirSync: vi.fn(() => []),
60
- // tmp 目录创建/清理走真实实现(本文件用例级隔离需要)
61
- mkdtempSync: actual.mkdtempSync,
62
- rmSync: actual.rmSync,
63
- promises: actual.promises,
64
- };
65
- });
66
-
67
- // removeAliveMarker 一并 mock(finalize-record 消费;成功轮次 early return 不触达,防御性补全)
68
- vi.mock("../alive-store.ts", () => ({
69
- writeAliveMarker: vi.fn(),
70
- removeAliveMarker: vi.fn(),
71
- }));
72
-
73
- // chatMode agent_end 早返回不读后代判定;统一 count=0(对齐 harness)。
74
- vi.mock("../session-pending.ts", () => ({
75
- readActivePendingFromSessionFile: vi.fn(() => ({ count: 0 })),
76
- }));
77
-
78
- vi.mock("../temp-prompt.ts", () => ({
79
- writePromptToTempFile: vi.fn(async (agent: string) => {
80
- const safeName = agent.replace(/[^\w.-]+/g, "_");
81
- return { dir: `/tmp/fake-${safeName}`, filePath: `/tmp/fake-${safeName}/prompt-${safeName}.md` };
82
- }),
83
- cleanupTempPrompt: vi.fn(async () => {}),
84
- }));
85
-
86
- import { _resetLifecycleState } from "../lifecycle-manager.ts";
87
- import { ModelConfigService } from "../model-config-service.ts";
88
- import type { ModelInfo, ModelRegistryLike } from "../model-resolver.ts";
89
- import type { ExecutionRecord } from "../types.ts";
90
- import { SubagentService } from "../subagent-service.ts";
91
- import type { PiLike } from "../subagent-service.ts";
92
- import {
93
- emitStdoutLine,
94
- lastSpawnedChild,
95
- sessionHeader,
96
- waitForSpawn,
97
- } from "./helpers/spawn-mock.ts";
98
-
99
- const mockSpawn = vi.mocked(spawn);
100
-
101
- const STUB_MODEL: ModelInfo = { id: "test-model", name: "Test", provider: "test", reasoning: false };
102
-
103
- /** 最小合法 registry(initModel fail-fast 需要;resolveModel 第三层直接透传 ctxModel)。 */
104
- function makeEmptyRegistry(): ModelRegistryLike {
105
- return { getAvailable: () => [], find: () => undefined, hasConfiguredAuth: () => true };
106
- }
107
-
108
- function makePi(): PiLike & {
109
- appendEntry: ReturnType<typeof vi.fn>;
110
- events: { emit: ReturnType<typeof vi.fn> };
111
- sendMessage: ReturnType<typeof vi.fn>;
112
- } {
113
- return { appendEntry: vi.fn(), events: { emit: vi.fn() }, sendMessage: vi.fn() };
114
- }
115
-
116
- /** 暴露私有 store 的接口(测试专用 cast)。 */
117
- interface ServiceInternals {
118
- store: { getMutable(id: string): ExecutionRecord | undefined };
119
- }
120
-
121
- describe("[N2] chatMode 轮次通知正文:真实 session-runner 链路", () => {
122
- let agentDir: string;
123
- let service: SubagentService;
124
- let pi: ReturnType<typeof makePi>;
125
- let internals: ServiceInternals;
126
-
127
- beforeEach(() => {
128
- vi.clearAllMocks();
129
- // lifecycle-manager 模块级单例(idleTimers Map 跨用例共享),每用例前清空防泄漏。
130
- _resetLifecycleState();
131
- agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "round-notify-"));
132
- const modelService = new ModelConfigService({ agentDir, cwd: agentDir });
133
- modelService.initModel({
134
- modelRegistry: makeEmptyRegistry(),
135
- sessionId: "root-session",
136
- ctxModel: STUB_MODEL,
137
- });
138
- service = new SubagentService({ cwd: agentDir, modelService });
139
- pi = makePi();
140
- service.initSession({ pi, sessionId: "root-session" });
141
- internals = service as unknown as ServiceInternals;
142
- });
143
-
144
- afterEach(() => {
145
- service.dispose();
146
- _resetLifecycleState();
147
- vi.restoreAllMocks();
148
- fs.rmSync(agentDir, { recursive: true, force: true });
149
- });
150
-
151
- it("真实 execute(conversation:true) + FakeChild 驱动 text_delta/agent_settled → 通知正文含本轮真实回复(非 (empty))", async () => {
152
- const ROUND_REPLY = "THE ROUND REPLY";
153
-
154
- // 真实链路:execute → kickOffBackground → runAndFinalize → 真实 runSpawn → FakeChild。
155
- // ctx.onRoundSettled 由 buildSessionRunnerContext 注入(真实回调,非 mock)。
156
- const handle = await service.execute({
157
- task: "tell me something",
158
- slug: "round-notify",
159
- conversation: true,
160
- });
161
-
162
- await waitForSpawn(mockSpawn);
163
- const child = lastSpawnedChild(mockSpawn);
164
-
165
- // 真实事件链:header(握手加速)→ text_delta(本轮回复累积进 turns)→ turn_end →
166
- // agent_end(chatMode 保活)→ agent_settled(真空闲:armIdleTimer → onRoundSettled)。
167
- emitStdoutLine(child, sessionHeader("sess-round-1"));
168
- emitStdoutLine(child, {
169
- type: "message_update",
170
- // type 对齐 pi-ai AssistantMessageEvent 真实协议(text 增量 = "text_delta",带 contentIndex)。
171
- // 曾用 {type:"text"} 假类型——旧实现不查 type 只看 delta 碰巧兼容;现实现按 type 正向
172
- // 分流(toolcall_delta 不混入 text 流),假类型事件被正确丢弃,fake 必须对齐真实协议。
173
- assistantMessageEvent: { type: "text_delta", contentIndex: 0, delta: ROUND_REPLY },
174
- });
175
- emitStdoutLine(child, { type: "turn_end" });
176
- emitStdoutLine(child, { type: "agent_end", willRetry: false });
177
- emitStdoutLine(child, { type: "agent_settled" });
178
-
179
- // agent_settled → onRoundSettled(round+1 + record.result 派生 + notifyComplete)→
180
- // 无其他 busy background → 立即 flush → pi.sendMessage。
181
- await vi.waitFor(() => {
182
- expect(pi.sendMessage).toHaveBeenCalledTimes(1);
183
- });
184
-
185
- const sentMsg = pi.sendMessage.mock.calls[0]![0] as { customType: string; content: string };
186
- expect(sentMsg.customType).toBe("subagent-bg-notify");
187
- expect(sentMsg.content).toContain("finished a round");
188
- // [N2] 核心:正文含本轮真实回复文本(修复前此处是 "(empty)")
189
- expect(sentMsg.content).toContain(ROUND_REPLY);
190
- expect(sentMsg.content).not.toContain("(empty)");
191
-
192
- // record 侧:turns 已累积 + result 从 turns 真实派生(非手工预置)+ running-resumable
193
- const record = internals.store.getMutable(handle.subagentId);
194
- expect(record).toBeDefined();
195
- expect(record!.turns[0]!.text).toBe(ROUND_REPLY);
196
- expect(record!.result).toBe(ROUND_REPLY);
197
- expect(record!.status).toBe("running");
198
- expect(record!.round).toBe(1);
199
-
200
- // 收尾:close 让 runSpawn resolve → runAndFinalize 续体 early return → .then 的
201
- // notifyComplete 被同 id:round dedup 吞——总发送数仍恰为 1。
202
- child.stdout.end();
203
- child.stderr.end();
204
- child.emit("close", 0);
205
- await new Promise((r) => setTimeout(r, 30));
206
- expect(pi.sendMessage).toHaveBeenCalledTimes(1);
207
-
208
- // [C2] close 现状语义扩展:终态化不再发新通知(总数仍 1),末条轮次通知含
209
- // Full transcript 指针行——真实链路 sessionHeader 已回填 record.sessionFile
210
- //(session-runner.ts:1039),chatMode:true 经 toNotifyRecord 条件透传到通知正文。
211
- const lastMsg = pi.sendMessage.mock.calls[0]![0] as { content: string; details?: { sessionFile?: string } };
212
- expect(lastMsg.details?.sessionFile).toBe(record!.sessionFile);
213
- expect(lastMsg.content).toContain(`\n\nFull transcript: ${record!.sessionFile}`);
214
- });
215
- });
@@ -1,250 +0,0 @@
1
- // src/__tests__/concurrency-pool.test.ts
2
- import { describe, expect, it } from "vitest";
3
-
4
- import { DefaultConcurrencyPool } from "../concurrency-pool.ts";
5
-
6
- describe("DefaultConcurrencyPool", () => {
7
- it("allows up to maxConcurrent concurrent tasks", async () => {
8
- const pool = new DefaultConcurrencyPool(2);
9
- await pool.acquire(0);
10
- await pool.acquire(0);
11
- // 第三个 acquire 应阻塞
12
- let thirdAcquired = false;
13
- const third = pool.acquire(0).then(() => { thirdAcquired = true; });
14
- await new Promise((r) => setTimeout(r, 5));
15
- expect(thirdAcquired).toBe(false);
16
- expect(pool.active).toBe(2);
17
-
18
- pool.release();
19
- await third;
20
- expect(thirdAcquired).toBe(true);
21
- expect(pool.active).toBe(2);
22
-
23
- pool.release();
24
- pool.release();
25
- await new Promise((r) => setTimeout(r, 5));
26
- expect(pool.active).toBe(0);
27
- });
28
-
29
- it("higher priority acquires the pool first", async () => {
30
- const pool = new DefaultConcurrencyPool(1);
31
- await pool.acquire(0); // 占满
32
-
33
- let lowAcquired = false;
34
- let highAcquired = false;
35
- const low = pool.acquire(10).then(() => { lowAcquired = true; });
36
- const high = pool.acquire(0).then(() => { highAcquired = true; });
37
-
38
- await new Promise((r) => setTimeout(r, 5));
39
- pool.release();
40
- await Promise.race([low, high, new Promise((r) => setTimeout(r, 20))]);
41
-
42
- expect(highAcquired).toBe(true);
43
- expect(lowAcquired).toBe(false);
44
- pool.release();
45
- });
46
-
47
- it("same-priority tasks wake in FIFO (seq) order", async () => {
48
- const pool = new DefaultConcurrencyPool(1);
49
- await pool.acquire(0); // fill slot
50
-
51
- const order: number[] = [];
52
- // Enqueue 3 tasks with same priority — they should resolve in enqueue order
53
- const p1 = pool.acquire(0).then(() => { order.push(1); pool.release(); });
54
- const p2 = pool.acquire(0).then(() => { order.push(2); pool.release(); });
55
- const p3 = pool.acquire(0).then(() => { order.push(3); pool.release(); });
56
-
57
- pool.release(); // kick off the chain
58
- await Promise.allSettled([p1, p2, p3]);
59
-
60
- expect(order).toEqual([1, 2, 3]);
61
- });
62
-
63
- it("extra release() does not make active negative", () => {
64
- const pool = new DefaultConcurrencyPool(2);
65
- pool.release(); // no acquires yet
66
- pool.release();
67
- pool.release();
68
- expect(pool.active).toBe(0);
69
- });
70
-
71
- it("active never exceeds maxConcurrent", async () => {
72
- const pool = new DefaultConcurrencyPool(2);
73
- const acquires: Array<Promise<void>> = [];
74
- let peak = 0;
75
- for (let i = 0; i < 6; i++) {
76
- acquires.push(pool.acquire(0).then(() => {
77
- peak = Math.max(peak, pool.active);
78
- }));
79
- }
80
- // Drain: release one at a time so we can observe peak
81
- for (let i = 0; i < 6; i++) {
82
- pool.release();
83
- await new Promise((r) => setTimeout(r, 2));
84
- }
85
- await Promise.allSettled(acquires);
86
- expect(peak).toBeLessThanOrEqual(2);
87
- });
88
-
89
- it("clamps maxConcurrent=0 to 1 (no deadlock, C3 fix)", async () => {
90
- const pool = new DefaultConcurrencyPool(0);
91
- // 不会死锁——clamp 到 1,acquire 立即返回
92
- await pool.acquire(0);
93
- expect(pool.active).toBe(1);
94
- pool.release();
95
- expect(pool.active).toBe(0);
96
- });
97
-
98
- it("clamps negative maxConcurrent to 1", async () => {
99
- const pool = new DefaultConcurrencyPool(-5);
100
- await pool.acquire(0);
101
- expect(pool.active).toBe(1);
102
- });
103
-
104
- it("priority 0 (sync) preempts priority 1000 (background)", async () => {
105
- const pool = new DefaultConcurrencyPool(1);
106
- await pool.acquire(1000); // background 占满
107
-
108
- let bgAcquired = false;
109
- let syncAcquired = false;
110
- const bg = pool.acquire(1000).then(() => { bgAcquired = true; });
111
- const sync = pool.acquire(0).then(() => { syncAcquired = true; });
112
-
113
- await new Promise((r) => setTimeout(r, 5));
114
- pool.release();
115
- await Promise.race([bg, sync, new Promise((r) => setTimeout(r, 20))]);
116
-
117
- expect(syncAcquired).toBe(true);
118
- expect(bgAcquired).toBe(false);
119
- pool.release();
120
- });
121
-
122
- // ============================================================
123
- // 分层配额:effectiveMaxConcurrent 参数控制放行上限 (T-A1~T-A4)
124
- // ============================================================
125
- //
126
- // [背景] T2 Wave 0 给 acquire 增加可选 effectiveMaxConcurrent 参数,让调用方
127
- // 传 max(1, maxConcurrent - depth) 实现分层配额(嵌套越深有效并发越小)。
128
- // 该参数覆盖实例级 maxConcurrent 的本次调用上限,不改实例状态。
129
- // 这组测试锁定该参数的语义。
130
-
131
- describe("分层配额 effectiveMaxConcurrent (T-A1~T-A4)", () => {
132
- it("T-A1: effectiveMaxConcurrent 限制本次调用放行数(小于实例级 maxConcurrent)", async () => {
133
- // 实例配额 5,但本次调用 effective=2 → 第 3 个应阻塞
134
- const pool = new DefaultConcurrencyPool(5);
135
- await pool.acquire(0, 2);
136
- await pool.acquire(0, 2);
137
- expect(pool.active).toBe(2);
138
-
139
- let thirdAcquired = false;
140
- const third = pool.acquire(0, 2).then(() => { thirdAcquired = true; });
141
- await new Promise((r) => setTimeout(r, 5));
142
-
143
- expect(thirdAcquired).toBe(false);
144
- expect(pool.active).toBe(2);
145
-
146
- pool.release();
147
- await third;
148
- expect(thirdAcquired).toBe(true);
149
- pool.release();
150
- pool.release();
151
- });
152
-
153
- it("T-A2: 同一 pool 实例不同 effectiveMaxConcurrent 控制不同调用放行数", async () => {
154
- // 同一 pool(实例级 maxConcurrent=5)
155
- const pool = new DefaultConcurrencyPool(5);
156
- // 前 3 个用 effective=3,全放行(active 0→1→2→3,每次 < 3)
157
- await pool.acquire(0, 3);
158
- await pool.acquire(0, 3);
159
- await pool.acquire(0, 3);
160
- expect(pool.active).toBe(3);
161
-
162
- // 第 4 个用 effective=3 → 阻塞(active 3 >= 3)
163
- let blockedAcquired = false;
164
- const blocked = pool.acquire(0, 3).then(() => { blockedAcquired = true; });
165
- await new Promise((r) => setTimeout(r, 5));
166
- expect(blockedAcquired).toBe(false);
167
-
168
- // 换 effective=5 放行(active 3 < 5)
169
- let wideAcquired = false;
170
- const wide = pool.acquire(0, 5).then(() => { wideAcquired = true; });
171
- await new Promise((r) => setTimeout(r, 5));
172
- expect(wideAcquired).toBe(true);
173
- expect(pool.active).toBe(4);
174
-
175
- // wide release 后 blocked 仍等(active 3 >= 3 不变直到再 release)
176
- pool.release(); // wide 释放
177
- await new Promise((r) => setTimeout(r, 5));
178
- expect(blockedAcquired).toBe(true);
179
-
180
- // 清理
181
- pool.release();
182
- pool.release();
183
- pool.release();
184
- pool.release();
185
- await Promise.allSettled([blocked, wide]);
186
- });
187
-
188
- it("T-A3: effectiveMaxConcurrent=1 只放行 1 个(保底)", async () => {
189
- const pool = new DefaultConcurrencyPool(5);
190
- await pool.acquire(0, 1);
191
- expect(pool.active).toBe(1);
192
-
193
- let secondAcquired = false;
194
- const second = pool.acquire(0, 1).then(() => { secondAcquired = true; });
195
- await new Promise((r) => setTimeout(r, 5));
196
- expect(secondAcquired).toBe(false);
197
- expect(pool.active).toBe(1);
198
-
199
- pool.release();
200
- await second;
201
- expect(secondAcquired).toBe(true);
202
- pool.release();
203
- });
204
-
205
- it("T-A4: maxConcurrent readonly 属性可读且等于构造值", () => {
206
- const pool = new DefaultConcurrencyPool(4);
207
- expect(pool.maxConcurrent).toBe(4);
208
-
209
- // clamp 路径也通过该属性暴露
210
- const clamped = new DefaultConcurrencyPool(0);
211
- expect(clamped.maxConcurrent).toBe(1);
212
-
213
- const negative = new DefaultConcurrencyPool(-3);
214
- expect(negative.maxConcurrent).toBe(1);
215
- });
216
- });
217
-
218
- // ============================================================
219
- // H2: acquire 支持 AbortSignal — abort 时排队条目 reject
220
- // ============================================================
221
- describe("H2 abort support for acquire", () => {
222
- it("abort signal rejects queued acquire with AbortError", async () => {
223
- const pool = new DefaultConcurrencyPool(1);
224
- await pool.acquire(0); // 占满
225
-
226
- const controller = new AbortController();
227
- const queued = pool.acquire(0, undefined, controller.signal);
228
-
229
- await new Promise((r) => setTimeout(r, 5));
230
- expect(pool.active).toBe(1); // 仍在排队
231
-
232
- controller.abort();
233
-
234
- await expect(queued).rejects.toThrow("aborted");
235
- });
236
-
237
- it("non-aborted acquire still resolves normally after release", async () => {
238
- const pool = new DefaultConcurrencyPool(1);
239
- await pool.acquire(0); // 占满
240
-
241
- const controller = new AbortController();
242
- const queued = pool.acquire(0, undefined, controller.signal);
243
-
244
- pool.release(); // 释放 → queued 应被 resolve
245
- await queued; // 不应 reject
246
- expect(pool.active).toBe(1);
247
- pool.release();
248
- });
249
- });
250
- });
@@ -1,110 +0,0 @@
1
- // src/__tests__/config.test.ts
2
- //
3
- // loadGlobalConfig 测试。
4
- // 配置已退化为仅 maxConcurrent(模型解析改为「主 agent model 优先」,
5
- // 不再有 categories/fallback/yolo/session 级覆盖)。
6
-
7
- import * as fs from "node:fs";
8
- import * as os from "node:os";
9
- import * as path from "node:path";
10
-
11
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
12
-
13
- import { getGlobalConfigPath, loadGlobalConfig } from "../config.ts";
14
-
15
- let tmpDir: string;
16
-
17
- beforeEach(() => {
18
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "subagents-config-test-"));
19
- });
20
-
21
- afterEach(() => {
22
- fs.rmSync(tmpDir, { recursive: true, force: true });
23
- });
24
-
25
- /** 写入 config.json(自动创建 subagents/ 子目录)。 */
26
- function writeConfig(agentDir: string, content: string): void {
27
- const configPath = getGlobalConfigPath(agentDir);
28
- fs.mkdirSync(path.dirname(configPath), { recursive: true });
29
- fs.writeFileSync(configPath, content, "utf-8");
30
- }
31
-
32
- // ============================================================
33
- // loadGlobalConfig
34
- // ============================================================
35
-
36
- describe("loadGlobalConfig", () => {
37
- it("returns default config when file does not exist", () => {
38
- const cfg = loadGlobalConfig(tmpDir);
39
- expect(cfg.version).toBe(1);
40
- expect(cfg.maxConcurrent).toBe(6);
41
- });
42
-
43
- it("returns default config when JSON is corrupt", () => {
44
- writeConfig(tmpDir, "{not valid json");
45
- const cfg = loadGlobalConfig(tmpDir);
46
- expect(cfg.version).toBe(1);
47
- expect(cfg.maxConcurrent).toBe(6);
48
- });
49
-
50
- it("deep-merges with defaults: missing fields fall back to defaults", () => {
51
- writeConfig(tmpDir, JSON.stringify({ version: 1 }));
52
- const cfg = loadGlobalConfig(tmpDir);
53
- expect(cfg.version).toBe(1);
54
- expect(cfg.maxConcurrent).toBe(6);
55
- });
56
-
57
- it("loads valid config with maxConcurrent override", () => {
58
- writeConfig(tmpDir, JSON.stringify({ version: 1, maxConcurrent: 8 }));
59
- const cfg = loadGlobalConfig(tmpDir);
60
- expect(cfg.maxConcurrent).toBe(8);
61
- });
62
-
63
- it("ignores legacy categories/fallback/yoloByDefault fields (model resolution deprecated)", () => {
64
- // 旧 config.json 仍可能含这些字段——读取时不报错,但 SubagentsGlobalConfig
65
- // 类型上已不含它们,loadGlobalConfig 只取 version + maxConcurrent。
66
- writeConfig(
67
- tmpDir,
68
- JSON.stringify({
69
- version: 1,
70
- maxConcurrent: 6,
71
- yoloByDefault: true,
72
- categories: { coding: { label: "C", model: "x/y" } },
73
- fallback: { model: "anthropic/x" },
74
- }),
75
- );
76
- const cfg = loadGlobalConfig(tmpDir);
77
- expect(cfg.maxConcurrent).toBe(6);
78
- expect(cfg.version).toBe(1);
79
- // 仅两个字段(类型保证)
80
- expect(Object.keys(cfg).sort()).toEqual(["maxConcurrent", "version"]);
81
- });
82
- });
83
-
84
- // ============================================================
85
- // sanitizeMaxConcurrent(经 loadGlobalConfig 间接覆盖)
86
- // ============================================================
87
-
88
- describe("sanitizeMaxConcurrent (via loadGlobalConfig)", () => {
89
- it("rejects non-number maxConcurrent → default", () => {
90
- writeConfig(tmpDir, JSON.stringify({ maxConcurrent: "eight" }));
91
- expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
92
- });
93
-
94
- it("rejects non-integer maxConcurrent → default", () => {
95
- writeConfig(tmpDir, JSON.stringify({ maxConcurrent: 4.5 }));
96
- expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
97
- });
98
-
99
- it("rejects zero/negative maxConcurrent → default", () => {
100
- writeConfig(tmpDir, JSON.stringify({ maxConcurrent: 0 }));
101
- expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
102
- writeConfig(tmpDir, JSON.stringify({ maxConcurrent: -1 }));
103
- expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
104
- });
105
-
106
- it("accepts positive integer", () => {
107
- writeConfig(tmpDir, JSON.stringify({ maxConcurrent: 16 }));
108
- expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(16);
109
- });
110
- });