@zhushanwen/subagent-core 0.2.0 → 0.5.1
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.
- package/README.md +45 -2
- package/agents/analyst.md +60 -0
- package/agents/coder.md +69 -0
- package/agents/debugger.md +66 -0
- package/agents/doc-reviewer.md +49 -0
- package/agents/explorer.md +63 -0
- package/agents/general-purpose.md +32 -0
- package/agents/orchestrator.md +61 -0
- package/agents/planner.md +53 -0
- package/agents/researcher.md +67 -0
- package/agents/reviewer.md +73 -0
- package/dist/chunk-43ONBFZX.js +240 -0
- package/dist/chunk-APZY4IME.js +27 -0
- package/dist/chunk-V3VHZ2VX.js +59 -0
- package/dist/execution/engine/engines/zcode/constants.cjs +62 -9
- package/dist/execution/engine/engines/zcode/constants.d.cts +116 -12
- package/dist/execution/engine/engines/zcode/constants.d.ts +116 -12
- package/dist/execution/engine/engines/zcode/constants.js +39 -7
- package/dist/execution/engine/engines/zcode/reader.d.cts +2 -1
- package/dist/execution/engine/engines/zcode/reader.d.ts +2 -1
- package/dist/execution/engine/engines/zcode/reader.js +4 -234
- package/dist/execution/engine/paths.js +7 -19
- package/dist/index.cjs +18234 -1277
- package/dist/index.d.cts +5646 -673
- package/dist/index.d.ts +5646 -673
- package/dist/index.js +17828 -1277
- package/dist/{types-BxyAidGf.d.cts → types-Dv4QhSJ_.d.cts} +678 -112
- package/dist/{types-BxyAidGf.d.ts → types-Dv4QhSJ_.d.ts} +678 -112
- package/package.json +7 -4
- package/src/__tests__/agent-opts-resolver-schema-prompt.test.ts +0 -1
- package/src/__tests__/append-system-prompt-assembly.test.ts +8 -7
- package/src/__tests__/fr4-get-state-handshake.test.ts +2 -2
- package/src/__tests__/m2-append-content-probe.test.ts +0 -1
- package/src/__tests__/manifest-store.test.ts +10 -9
- package/src/__tests__/record-store-cache.test.ts +0 -2
- package/src/__tests__/record-store-index.test.ts +1 -2
- package/src/__tests__/review-fix-loop-script.test.ts +93 -3
- package/src/__tests__/review-fix-loop-utils.test.ts +31 -10
- package/src/__tests__/robustness-low-batch1.test.ts +6 -5
- package/src/__tests__/robustness-medium-batch1.test.ts +2 -2
- package/src/__tests__/robustness-medium-batch2.test.ts +17 -6
- package/src/__tests__/robustness-medium-batch4.test.ts +2 -2
- package/src/__tests__/session-runner.test.ts +1 -1
- package/src/__tests__/smoke.test.ts +9 -2
- package/src/core/__tests__/host-services.test.ts +2 -2
- package/src/core/__tests__/logger.test.ts +1 -1
- package/src/core/error-message.ts +9 -0
- package/src/core/host-services.ts +21 -5
- package/src/core/notify-ports.ts +18 -5
- package/src/execution/__tests__/agent-profile.test.ts +232 -0
- package/src/execution/__tests__/agent-registry.test.ts +370 -0
- package/src/execution/__tests__/agent-result-mapper.test.ts +18 -2
- package/src/execution/__tests__/agents-assembly.test.ts +219 -0
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +6 -6
- package/src/execution/__tests__/chat-engine-routing.test.ts +136 -30
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +5 -4
- package/src/execution/__tests__/cold-resurrect.test.ts +283 -0
- package/src/execution/__tests__/create-concurrency-pool.test.ts +194 -0
- package/src/execution/__tests__/delivery-methods.test.ts +77 -62
- package/src/execution/__tests__/descendant-sweep-guards.test.ts +220 -0
- package/src/execution/__tests__/descendant-sweep.test.ts +269 -0
- package/src/execution/__tests__/dialog-queue.test.ts +199 -1
- package/src/execution/__tests__/engine-model-validation.test.ts +741 -0
- package/src/execution/__tests__/epipe-fallback.test.ts +31 -24
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +21 -91
- package/src/execution/__tests__/execute-nesting.test.ts +34 -188
- package/src/execution/__tests__/execution-record.test.ts +217 -60
- package/src/execution/__tests__/execution-runtime-face.test.ts +272 -0
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +3 -3
- package/src/execution/__tests__/finalize-record.test.ts +278 -16
- package/src/execution/__tests__/gc-timer.test.ts +57 -2
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +14 -12
- package/src/execution/__tests__/get-state-handshake.test.ts +127 -0
- package/src/execution/__tests__/helpers/mock-extension-api.ts +1 -1
- package/src/execution/__tests__/helpers/session-runner-mocks.ts +113 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +150 -3
- package/src/execution/__tests__/helpers/subagent-service-mocks.ts +137 -0
- package/src/execution/__tests__/keep-alive-no-progress.test.ts +280 -0
- package/src/execution/__tests__/kill-all-escalation.test.ts +196 -0
- package/src/execution/__tests__/lifecycle-manager-idle-timer-identity.test.ts +117 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +39 -0
- package/src/execution/__tests__/lifecycle-predicates.test.ts +1 -2
- package/src/execution/__tests__/manifest-parentid.test.ts +4 -4
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +99 -0
- package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +113 -0
- package/src/execution/__tests__/model-resolver.test.ts +2 -2
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +23 -121
- package/src/execution/__tests__/nested-visibility.test.ts +2 -0
- package/src/execution/__tests__/notify-ledger.test.ts +1249 -0
- package/src/execution/__tests__/output-collector.test.ts +117 -6
- package/src/execution/__tests__/pi-invocation.test.ts +1 -1
- package/src/execution/__tests__/record-store-orphan-revive.test.ts +159 -0
- package/src/execution/__tests__/record-store.test.ts +89 -5
- package/src/execution/__tests__/records-cwd-isolation.test.ts +2 -2
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +29 -132
- package/src/execution/__tests__/recursive-visibility-env.test.ts +55 -179
- package/src/execution/__tests__/rpc-mode.test.ts +2 -2
- package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +387 -0
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +19 -9
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +5 -4
- package/src/execution/__tests__/run-spawn-edges.test.ts +418 -26
- package/src/execution/__tests__/run-spawn-integration.test.ts +3 -3
- package/src/execution/__tests__/run-spawn-resume.test.ts +2 -2
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +2 -2
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +16 -8
- package/src/execution/__tests__/service-kill-escalation.test.ts +91 -0
- package/src/execution/__tests__/session-context-resolver.test.ts +0 -2
- package/src/execution/__tests__/session-file-gc.test.ts +35 -0
- package/src/execution/__tests__/session-pending.test.ts +471 -0
- package/src/execution/__tests__/session-reconstructor.test.ts +366 -15
- package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +110 -0
- package/src/execution/__tests__/session-runner-close-prune.test.ts +181 -0
- package/src/execution/__tests__/session-runner-dispatch.test.ts +489 -0
- package/src/execution/__tests__/session-runner-epipe.test.ts +4 -3
- package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +227 -0
- package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +290 -0
- package/src/execution/__tests__/session-runner-schema-env.test.ts +7 -5
- package/src/execution/__tests__/settled-watchdog.test.ts +524 -0
- package/src/execution/__tests__/spawn-args.test.ts +11 -10
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +26 -23
- package/src/execution/__tests__/spawn-event-adapter.test.ts +1 -1
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +5 -4
- package/src/execution/__tests__/spawned-children.test.ts +155 -11
- package/src/execution/__tests__/start-sync-model-guard.test.ts +4 -4
- package/src/execution/__tests__/stdin-writer.test.ts +6 -4
- package/src/execution/__tests__/stream-sink-retirement.test.ts +6 -6
- package/src/execution/__tests__/subagent-actions-core.test.ts +1017 -0
- package/src/execution/__tests__/subagent-service-message-close.test.ts +99 -35
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +174 -0
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +271 -0
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +33 -29
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +341 -0
- package/src/execution/__tests__/subagent-service.test.ts +37 -30
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +88 -12
- package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +75 -0
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +22 -20
- package/src/execution/__tests__/temp-prompt.test.ts +1 -1
- package/src/execution/__tests__/timeout-integration.test.ts +13 -12
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +1 -1
- package/src/execution/__tests__/turn-limiter.test.ts +1 -1
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +107 -7
- package/src/execution/__tests__/ui-request-handler.test.ts +4 -3
- package/src/execution/__tests__/ui-request-queue.test.ts +167 -2
- package/src/execution/__tests__/worktree-git-ops.test.ts +571 -0
- package/src/execution/__tests__/worktree-manager.test.ts +14 -5
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +4 -3
- package/src/execution/__tests__/worktree-reconcile-aging.test.ts +204 -0
- package/src/execution/agent-registry.ts +298 -30
- package/src/execution/agent-result-mapper.ts +3 -0
- package/src/execution/agents-assembly.ts +88 -0
- package/src/execution/cold-resurrect.ts +199 -0
- package/src/execution/concurrency-pool.ts +71 -9
- package/src/execution/dialog-queue.ts +101 -3
- package/src/execution/engine/__tests__/common/capability-gate.test.ts +91 -0
- package/src/execution/engine/__tests__/common/data-dir.test.ts +1 -1
- package/src/execution/engine/__tests__/common/journal-wiring.test.ts +84 -0
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +34 -7
- package/src/execution/engine/__tests__/common/persona-router.test.ts +4 -5
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +211 -51
- package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +149 -0
- package/src/execution/engine/__tests__/common/session-view-service.test.ts +499 -0
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +56 -99
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +88 -15
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +33 -7
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +1 -1
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +75 -54
- package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +128 -0
- package/src/execution/engine/__tests__/engine-discovery.test.ts +15 -3
- package/src/execution/engine/__tests__/model-prompt.test.ts +15 -3
- package/src/execution/engine/__tests__/registry.test.ts +94 -3
- package/src/execution/engine/__tests__/routing.test.ts +115 -6
- package/src/execution/engine/common/capability-gate.ts +92 -0
- package/src/execution/engine/common/journal-wiring.ts +97 -0
- package/src/execution/engine/common/kill-chain.ts +42 -10
- package/src/execution/engine/common/nesting-guard.ts +66 -0
- package/src/execution/engine/common/persona-router.ts +18 -8
- package/src/execution/engine/common/pool-manager.ts +332 -78
- package/src/execution/engine/common/session-view-service.ts +506 -0
- package/src/execution/engine/common/session-view-types.ts +125 -0
- package/src/execution/engine/engine-discovery.ts +12 -16
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +174 -28
- package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +257 -0
- package/src/execution/{argv-mirror.ts → engine/engines/pi/argv-mirror.ts} +43 -21
- package/src/execution/{get-state-handshake.ts → engine/engines/pi/get-state-handshake.ts} +86 -11
- package/src/execution/{output-collector.ts → engine/engines/pi/output-collector.ts} +108 -19
- package/src/execution/engine/engines/pi/pi-engine.ts +434 -38
- package/src/execution/{pi-invocation.ts → engine/engines/pi/pi-invocation.ts} +2 -2
- package/src/execution/engine/engines/pi/reader.ts +11 -0
- package/src/execution/engine/engines/pi/registration.ts +4 -2
- package/src/execution/engine/engines/pi/session-runner.ts +2840 -0
- package/src/execution/{spawn-event-adapter.ts → engine/engines/pi/spawn-event-adapter.ts} +75 -34
- package/src/execution/{stdin-writer.ts → engine/engines/pi/stdin-writer.ts} +10 -9
- package/src/execution/{temp-prompt.ts → engine/engines/pi/temp-prompt.ts} +2 -2
- package/src/execution/{turn-limiter.ts → engine/engines/pi/turn-limiter.ts} +1 -1
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +301 -0
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +36 -0
- package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +321 -0
- package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +473 -0
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +7 -210
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +6 -110
- package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +247 -0
- package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +451 -0
- package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +792 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +782 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +168 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +210 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +353 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +282 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +372 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +65 -47
- package/src/execution/engine/engines/zcode/appserver-launcher.ts +167 -0
- package/src/execution/engine/engines/zcode/connection.ts +598 -0
- package/src/execution/engine/engines/zcode/constants.ts +147 -14
- package/src/execution/engine/engines/zcode/golden-sample.ts +42 -34
- package/src/execution/engine/engines/zcode/parser.ts +12 -346
- package/src/execution/engine/engines/zcode/preparer.ts +22 -150
- package/src/execution/engine/engines/zcode/session-channel.ts +968 -0
- package/src/execution/engine/engines/zcode/zcode-engine.ts +1023 -250
- package/src/execution/engine/host-task-spec.ts +32 -36
- package/src/execution/engine/model-validation.ts +177 -0
- package/src/execution/engine/port.ts +65 -7
- package/src/execution/engine/registry.ts +53 -0
- package/src/execution/engine/routing.ts +75 -1
- package/src/execution/engine/types.ts +30 -103
- package/src/execution/execution-record.ts +222 -144
- package/src/execution/finalize-record.ts +181 -85
- package/src/execution/idle-gc.ts +28 -0
- package/src/execution/lifecycle-manager.ts +27 -3
- package/src/execution/lifecycle-predicates.ts +1 -1
- package/src/execution/manifest-store.ts +53 -62
- package/src/execution/notifier.ts +10 -10
- package/src/execution/notify-host.ts +212 -0
- package/src/execution/notify-ledger.ts +117 -16
- package/src/execution/record-entry.ts +8 -2
- package/src/execution/record-store.ts +148 -88
- package/src/execution/round-settlement.ts +93 -0
- package/src/execution/session-file-gc.ts +96 -62
- package/src/execution/session-pending.ts +213 -62
- package/src/execution/session-reconstructor.ts +256 -143
- package/src/execution/sessions-index.ts +127 -102
- package/src/execution/settled-watchdog.ts +311 -0
- package/src/execution/subagent-actions-core.ts +686 -0
- package/src/execution/subagent-service.ts +1106 -907
- package/src/execution/subprocess-agent-runner.ts +144 -97
- package/src/execution/types.ts +9 -0
- package/src/execution/ui-request-handler-factory.ts +126 -75
- package/src/execution/ui-request-queue.ts +50 -19
- package/src/execution/worktree-git-ops.ts +397 -0
- package/src/execution/worktree-manager.ts +72 -10
- package/src/execution/worktree-registry.ts +6 -12
- package/src/index.ts +542 -9
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +42 -3
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +3 -5
- package/src/orchestration/__tests__/agent-call-stream.test.ts +2 -2
- package/src/orchestration/__tests__/args-meta.test.ts +358 -0
- package/src/orchestration/__tests__/args-validator.test.ts +14 -0
- package/src/orchestration/__tests__/error-recovery-rebuild-failure.test.ts +312 -0
- package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +384 -0
- package/src/orchestration/__tests__/execute-agent-call.test.ts +151 -11
- package/src/orchestration/__tests__/file-run-store-prune.test.ts +168 -0
- package/src/orchestration/__tests__/file-run-store-throttle.test.ts +168 -0
- package/src/orchestration/__tests__/file-run-store.test.ts +390 -0
- package/src/orchestration/__tests__/helpers/flush-microtasks.ts +13 -0
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +34 -0
- package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +357 -0
- package/src/orchestration/__tests__/lifecycle-recover-crashed.test.ts +289 -0
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +3 -3
- package/src/orchestration/__tests__/lifecycle.test.ts +84 -5
- package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +1 -1
- package/src/orchestration/__tests__/run-snapshot.test.ts +356 -0
- package/src/orchestration/__tests__/script-generate.test.ts +314 -0
- package/src/orchestration/__tests__/script-lint.test.ts +17 -0
- package/src/orchestration/__tests__/test-mocks.ts +2 -0
- package/src/orchestration/__tests__/worker-exit-without-result.test.ts +7 -6
- package/src/orchestration/__tests__/worker-message-pump-finalize-run.test.ts +229 -0
- package/src/orchestration/__tests__/{error-recovery-handlers.test.ts → worker-message-pump-handlers.test.ts} +28 -27
- package/src/orchestration/__tests__/{error-recovery-postmessage-defense.test.ts → worker-message-pump-postmessage-defense.test.ts} +8 -8
- package/src/orchestration/__tests__/{error-recovery-serialize-failed-result.test.ts → worker-message-pump-serialize-failed-result.test.ts} +2 -2
- package/src/orchestration/__tests__/{error-recovery-workflow-call.test.ts → worker-message-pump-workflow-call.test.ts} +1 -1
- package/src/orchestration/__tests__/worker-pending-timeout-abort.test.ts +275 -0
- package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +78 -1
- package/src/orchestration/__tests__/worker-script-builder.test.ts +1 -1
- package/src/orchestration/__tests__/workflow-files.test.ts +186 -0
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +1 -1
- package/src/orchestration/__tests__/workflow-run-summary.test.ts +119 -0
- package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +124 -0
- package/src/orchestration/agent-opts-resolver.ts +8 -8
- package/src/orchestration/args-meta.ts +198 -0
- package/src/orchestration/args-validator.ts +53 -31
- package/src/orchestration/execute-agent-call.ts +25 -79
- package/src/orchestration/file-run-store.ts +327 -0
- package/src/orchestration/launcher.ts +160 -104
- package/src/orchestration/lifecycle.ts +371 -97
- package/src/orchestration/models/agent-call.ts +7 -7
- package/src/orchestration/models/budget.ts +5 -5
- package/src/orchestration/models/ports.ts +4 -4
- package/src/orchestration/models/run-runtime.ts +15 -15
- package/src/orchestration/models/trace.ts +9 -9
- package/src/orchestration/models/types.ts +111 -22
- package/src/orchestration/models/workflow-run.ts +28 -28
- package/src/orchestration/models/workflow-script.ts +4 -4
- package/src/orchestration/run-snapshot.ts +266 -0
- package/src/orchestration/script-generate.ts +154 -0
- package/src/orchestration/script-lint.ts +123 -90
- package/src/orchestration/worker-handle.ts +10 -10
- package/src/orchestration/worker-host.ts +10 -10
- package/src/orchestration/{error-recovery.ts → worker-message-pump.ts} +498 -221
- package/src/orchestration/worker-script-builder.ts +401 -346
- package/src/orchestration/workflow-files.ts +37 -11
- package/src/orchestration/workflow-run-summary.ts +69 -0
- package/src/orchestration/workflow-script-registry-impl.ts +31 -9
- package/src/shared/__tests__/agent-ref.test.ts +209 -2
- package/src/shared/__tests__/atomic-write.test.ts +267 -0
- package/src/shared/__tests__/bounded-serialize.test.ts +236 -0
- package/src/shared/__tests__/injection-render.test.ts +518 -0
- package/src/shared/__tests__/meta-parser.test.ts +151 -0
- package/src/shared/__tests__/resource-discovery-host-roots.test.ts +474 -0
- package/src/shared/__tests__/resource-discovery.test.ts +261 -217
- package/src/shared/agent-ref.ts +143 -2
- package/src/shared/atomic-write.ts +323 -0
- package/src/shared/bounded-serialize.ts +154 -0
- package/src/shared/injection-render.ts +279 -0
- package/src/shared/meta-parser.ts +182 -68
- package/src/shared/model-ref.ts +15 -2
- package/src/shared/resource-discovery.ts +97 -204
- package/src/shared/resource-meta.ts +14 -0
- package/src/shared/schema-jsonify.ts +1 -1
- package/src/shared/xml-injection.ts +9 -9
- package/workflows/README.md +9 -9
- package/workflows/chain.js +4 -2
- package/workflows/map-reduce.js +5 -3
- package/workflows/parallel.js +5 -3
- package/workflows/review-fix-loop-utils.cjs +165 -92
- package/workflows/review-fix-loop-utils.d.cts +287 -0
- package/workflows/review-fix-loop.js +18 -7
- package/workflows/scatter-gather.js +4 -2
- package/dist/chunk-3VOERJPJ.js +0 -22
- package/src/execution/__tests__/execute-options-mapper.test.ts +0 -200
- package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
- package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
- package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -580
- package/src/execution/engine/engines/zcode/launcher.ts +0 -161
- package/src/execution/execute-options-mapper.ts +0 -115
- package/src/execution/session-runner.ts +0 -1789
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -288
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// src/execution/__tests__/agent-registry.test.ts
|
|
2
|
+
//
|
|
3
|
+
// AgentRegistry 测试(S2 路径统一版)。u-5c 迁自壳套件 src/__tests__/agent-registry.test.ts
|
|
4
|
+
// (被测 module 是 core 件,唯一测试覆盖原落壳——设计 §2.2 C6 / §1 目标 6)。
|
|
5
|
+
//
|
|
6
|
+
// 「builtin agents 数据合规」段:u-5c 曾拆出留壳(feat 侧布局:资产在壳包),但
|
|
7
|
+
// 合并终态 10 模板资产已迁 core 包 agents/(dev 侧 C5/D-1),壳 agents/ 不存在,
|
|
8
|
+
// 该段随资产回归 core 测试域(C5 锚点 + D-5 去 tools 化断言)。
|
|
9
|
+
//
|
|
10
|
+
// S2 重构:AgentRegistry 从「按名查找(discoverAll + cache Map<name>)」收敛为
|
|
11
|
+
// 「按绝对路径加载(loadByPath)」——agentRef 唯一形态 = .md 绝对路径(注入段
|
|
12
|
+
// <location>),内置 agent 即包内物理路径,无 builtin 合并、无名字查找。
|
|
13
|
+
// 发现(注入段数据源)职责由 shared/resource-discovery + injector 承担,
|
|
14
|
+
// 本文件不再测发现层(见 resource-discovery.test.ts)。
|
|
15
|
+
import * as fs from "node:fs";
|
|
16
|
+
import * as os from "node:os";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
|
|
20
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
21
|
+
|
|
22
|
+
// 隔离真实用户全局目录(~/.agents/agents/ 可能有真实 agent 文件)
|
|
23
|
+
vi.mock("node:os", async (importOriginal) => {
|
|
24
|
+
const actual = await importOriginal<typeof import("node:os")>();
|
|
25
|
+
return { ...actual, homedir: () => "/nonexistent-home-for-tests" };
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
import { AgentRegistry, parseAgentFrontmatter, parseAgentWithMeta } from "../agent-registry.ts";
|
|
29
|
+
import { clearEngines, registerEngine } from "../engine/registry.ts";
|
|
30
|
+
import type { EnginePort } from "../engine/port.ts";
|
|
31
|
+
import { lintAgentMeta } from "../../orchestration/script-lint.ts";
|
|
32
|
+
import { parseResourceMeta } from "../../shared/meta-parser.ts";
|
|
33
|
+
|
|
34
|
+
// ============================================================
|
|
35
|
+
// helpers
|
|
36
|
+
// ============================================================
|
|
37
|
+
|
|
38
|
+
function tmpWorkspace(): string {
|
|
39
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), "agent-reg-test-"));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeAgent(dir: string, name: string, body: string): string {
|
|
43
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
44
|
+
const filePath = path.join(dir, `${name}.md`);
|
|
45
|
+
fs.writeFileSync(filePath, body, "utf-8");
|
|
46
|
+
return filePath;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ============================================================
|
|
50
|
+
// parseAgentFrontmatter
|
|
51
|
+
// ============================================================
|
|
52
|
+
|
|
53
|
+
describe("parseAgentFrontmatter", () => {
|
|
54
|
+
it("parses name from filename + body as systemPrompt when no frontmatter", () => {
|
|
55
|
+
const cfg = parseAgentFrontmatter("/x/worker.md", "You are a worker.");
|
|
56
|
+
expect(cfg.name).toBe("worker");
|
|
57
|
+
expect(cfg.systemPrompt).toBe("You are a worker.");
|
|
58
|
+
});
|
|
59
|
+
it("extracts model/thinkingLevel/tools from frontmatter", () => {
|
|
60
|
+
const cfg = parseAgentFrontmatter("/x/coder.md", `---
|
|
61
|
+
name: coder
|
|
62
|
+
description: coding agent
|
|
63
|
+
model: anthropic/claude-3.5-sonnet
|
|
64
|
+
thinkingLevel: high
|
|
65
|
+
tools: [read, bash]
|
|
66
|
+
---
|
|
67
|
+
body text`);
|
|
68
|
+
expect(cfg.name).toBe("coder");
|
|
69
|
+
expect(cfg.model).toBe("anthropic/claude-3.5-sonnet");
|
|
70
|
+
expect(cfg.thinkingLevel).toBe("high");
|
|
71
|
+
expect(cfg.tools).toEqual(["read", "bash"]);
|
|
72
|
+
expect(cfg.systemPrompt).toBe("body text");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ============================================================
|
|
77
|
+
// parseAgentWithMeta(m5 T2:W4 lint 用 AgentMeta 二元组)
|
|
78
|
+
// ============================================================
|
|
79
|
+
|
|
80
|
+
describe("parseAgentWithMeta", () => {
|
|
81
|
+
it("有 frontmatter(IF1 通过):meta 非 null 且路由字段完整,config 同步正确", () => {
|
|
82
|
+
const { config, meta } = parseAgentWithMeta("/x/coder.md", `---
|
|
83
|
+
name: coder
|
|
84
|
+
description: 编码 agent
|
|
85
|
+
when: 需要写代码
|
|
86
|
+
notFor: 纯分析
|
|
87
|
+
model: anthropic/claude-3.5-sonnet
|
|
88
|
+
thinkingLevel: high
|
|
89
|
+
tools: [read, bash]
|
|
90
|
+
---
|
|
91
|
+
body text`);
|
|
92
|
+
expect(meta).not.toBeNull();
|
|
93
|
+
expect(meta!.kind).toBe("agent");
|
|
94
|
+
expect(meta!.name).toBe("coder");
|
|
95
|
+
expect(meta!.description).toBe("编码 agent");
|
|
96
|
+
expect(meta!.when).toBe("需要写代码");
|
|
97
|
+
expect(meta!.notFor).toBe("纯分析");
|
|
98
|
+
expect(config.name).toBe("coder");
|
|
99
|
+
expect(config.systemPrompt).toBe("body text");
|
|
100
|
+
expect(config.model).toBe("anthropic/claude-3.5-sonnet");
|
|
101
|
+
expect(config.thinkingLevel).toBe("high");
|
|
102
|
+
expect(config.tools).toEqual(["read", "bash"]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("无 frontmatter:meta = null,整个内容作为 systemPrompt", () => {
|
|
106
|
+
const { config, meta } = parseAgentWithMeta("/x/plain.md", "Just a prompt body.");
|
|
107
|
+
expect(meta).toBeNull();
|
|
108
|
+
expect(config).toEqual({
|
|
109
|
+
name: "plain",
|
|
110
|
+
systemPrompt: "Just a prompt body.",
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("MF-3 fallback:缺 description(IF1 返 null)时 model/tools 经 extractYamlField 仍生效", () => {
|
|
115
|
+
const { config, meta } = parseAgentWithMeta("/x/legacy.md", `---
|
|
116
|
+
name: legacy
|
|
117
|
+
model: anthropic/claude-3.5-sonnet
|
|
118
|
+
tools: read, bash, write
|
|
119
|
+
---
|
|
120
|
+
body text`);
|
|
121
|
+
// 缺 description → parseResourceMeta 返 null → meta 为 null(结构化路由不可见)
|
|
122
|
+
expect(meta).toBeNull();
|
|
123
|
+
// 但 config 的 model/tools 不丢(direct-path loadByPath 与重构前行为一致)
|
|
124
|
+
expect(config.name).toBe("legacy");
|
|
125
|
+
expect(config.model).toBe("anthropic/claude-3.5-sonnet");
|
|
126
|
+
expect(config.tools).toEqual(["read", "bash", "write"]);
|
|
127
|
+
expect(config.systemPrompt).toBe("body text");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("未闭合 frontmatter:meta = null,name 经 extractYamlField fallback,其余作为 systemPrompt", () => {
|
|
131
|
+
const { config, meta } = parseAgentWithMeta("/x/broken.md", `---
|
|
132
|
+
name: broken
|
|
133
|
+
model: x/y`);
|
|
134
|
+
expect(meta).toBeNull();
|
|
135
|
+
expect(config.name).toBe("broken");
|
|
136
|
+
// 未闭合分支只取 name(原行为),不解析 model
|
|
137
|
+
expect(config.systemPrompt).toBe(`---\nname: broken\nmodel: x/y`);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// ============================================================
|
|
142
|
+
// AgentRegistry.loadByPath(S2:agentRef = .md 绝对路径)
|
|
143
|
+
// ============================================================
|
|
144
|
+
|
|
145
|
+
describe("AgentRegistry.loadByPath", () => {
|
|
146
|
+
let ws: string;
|
|
147
|
+
beforeEach(() => { ws = tmpWorkspace(); });
|
|
148
|
+
afterEach(() => { fs.rmSync(ws, { recursive: true, force: true }); });
|
|
149
|
+
|
|
150
|
+
it("按绝对路径加载 agent:frontmatter + body → AgentConfig", () => {
|
|
151
|
+
const file = writeAgent(path.join(ws, ".pi", "agents"), "worker", `---
|
|
152
|
+
name: worker
|
|
153
|
+
description: 通用执行 agent
|
|
154
|
+
tools: [read, bash]
|
|
155
|
+
---
|
|
156
|
+
You are a worker.`);
|
|
157
|
+
const reg = new AgentRegistry();
|
|
158
|
+
const cfg = reg.loadByPath(file);
|
|
159
|
+
expect(cfg?.name).toBe("worker");
|
|
160
|
+
expect(cfg?.systemPrompt).toBe("You are a worker.");
|
|
161
|
+
expect(cfg?.tools).toEqual(["read", "bash"]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("无 frontmatter 文件:整个内容作为 systemPrompt", () => {
|
|
165
|
+
const file = writeAgent(ws, "plain", "Just a prompt body.");
|
|
166
|
+
const cfg = new AgentRegistry().loadByPath(file);
|
|
167
|
+
expect(cfg?.name).toBe("plain");
|
|
168
|
+
expect(cfg?.systemPrompt).toBe("Just a prompt body.");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("mtime 缓存:未变文件不重读(config 引用稳定)", () => {
|
|
172
|
+
const file = writeAgent(ws, "cached", "v1");
|
|
173
|
+
const reg = new AgentRegistry();
|
|
174
|
+
const first = reg.loadByPath(file);
|
|
175
|
+
const second = reg.loadByPath(file);
|
|
176
|
+
expect(second).toBe(first);
|
|
177
|
+
// 修改后 mtime 变化 → 新 config
|
|
178
|
+
fs.writeFileSync(file, "v2", "utf-8");
|
|
179
|
+
const third = reg.loadByPath(file);
|
|
180
|
+
expect(third?.systemPrompt).toBe("v2");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("相对路径引用返回 undefined(引用唯一形态 = 绝对路径)", () => {
|
|
184
|
+
const reg = new AgentRegistry();
|
|
185
|
+
expect(reg.loadByPath("worker")).toBeUndefined();
|
|
186
|
+
expect(reg.loadByPath("./agents/worker.md")).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("非 .md 引用返回 undefined", () => {
|
|
190
|
+
const reg = new AgentRegistry();
|
|
191
|
+
expect(reg.loadByPath("/tmp/worker.txt")).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("文件不存在返回 undefined,require=true 抛错带指引", () => {
|
|
195
|
+
const reg = new AgentRegistry();
|
|
196
|
+
expect(reg.loadByPath("/nonexistent/x.md")).toBeUndefined();
|
|
197
|
+
// R5(D7):三态错误文案统一带 <available_subagents> <location> 恢复指引
|
|
198
|
+
expect(() => reg.loadByPath("/nonexistent/x.md", true)).toThrow(/not found or unreadable/);
|
|
199
|
+
expect(() => reg.loadByPath("/nonexistent/x.md", true)).toThrow(/<available_subagents> <location>/);
|
|
200
|
+
expect(() => reg.loadByPath("relative", true)).toThrow(/Invalid agent ref/);
|
|
201
|
+
expect(() => reg.loadByPath("relative", true)).toThrow(/<available_subagents>/);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("~/ 前缀展开", () => {
|
|
205
|
+
const reg = new AgentRegistry();
|
|
206
|
+
// homedir 被 mock 为 /nonexistent-home-for-tests → 文件必然不存在,验证展开逻辑
|
|
207
|
+
expect(reg.loadByPath("~/agent.md")).toBeUndefined();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// ============================================================
|
|
212
|
+
// 包内 agents/*.md 数据合规(S2:内置 agent = 包内路径文件)
|
|
213
|
+
// ============================================================
|
|
214
|
+
|
|
215
|
+
describe("builtin agents 数据合规", () => {
|
|
216
|
+
// C5 过渡态收口:10 模板已迁 @zhushanwen/subagent-core/agents/(C1/D-1)——经
|
|
217
|
+
// ./workflows/* 子入口锚点解析 core 包根(与 src/host/pi-host.ts corePackageNpmRoot
|
|
218
|
+
// 同一锚,workspace 与发布形态同径),数据面断言随资产指向 core。
|
|
219
|
+
const CORE_PKG_ROOT = path.resolve(
|
|
220
|
+
path.dirname(createRequire(import.meta.url).resolve("@zhushanwen/subagent-core/workflows/README.md")),
|
|
221
|
+
"..",
|
|
222
|
+
);
|
|
223
|
+
const AGENTS_DIR = path.join(CORE_PKG_ROOT, "agents");
|
|
224
|
+
const CORE = ["explorer", "coder", "reviewer", "debugger", "analyst", "planner", "researcher", "orchestrator", "general-purpose", "doc-reviewer"];
|
|
225
|
+
|
|
226
|
+
it("agents/*.md 全部 IF1 解析成功", () => {
|
|
227
|
+
for (const f of fs.readdirSync(AGENTS_DIR).filter((x) => x.endsWith(".md"))) {
|
|
228
|
+
const meta = parseResourceMeta(fs.readFileSync(path.join(AGENTS_DIR, f), "utf-8"), "agent");
|
|
229
|
+
expect(meta?.kind, `${f} parse 失败`).toBe("agent");
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("核心 agent 均含 when/notFor/examples 且正反各一(lintAgentMeta 无 finding)", () => {
|
|
234
|
+
for (const name of CORE) {
|
|
235
|
+
const meta = parseResourceMeta(fs.readFileSync(path.join(AGENTS_DIR, `${name}.md`), "utf-8"), "agent");
|
|
236
|
+
expect(meta, `${name} 解析失败`).not.toBeNull();
|
|
237
|
+
if (meta?.kind !== "agent") continue;
|
|
238
|
+
expect(meta.when, `${name} 缺 when`).toBeDefined();
|
|
239
|
+
expect(meta.notFor, `${name} 缺 notFor`).toBeDefined();
|
|
240
|
+
expect(meta.examples?.length, `${name} 缺 examples`).toBeGreaterThanOrEqual(2);
|
|
241
|
+
expect(meta.examples?.some((e) => e.positive), `${name} 缺正向样本`).toBe(true);
|
|
242
|
+
expect(meta.examples?.some((e) => !e.positive), `${name} 缺反向样本`).toBe(true);
|
|
243
|
+
expect(lintAgentMeta(meta), `${name} examples 不合规`).toEqual([]);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("loadByPath 直接加载 core 包内 agent(内置 = 路径文件,无名字查找)", () => {
|
|
248
|
+
const reg = new AgentRegistry();
|
|
249
|
+
const coder = reg.loadByPath(path.join(AGENTS_DIR, "coder.md"));
|
|
250
|
+
expect(coder?.name).toBe("coder");
|
|
251
|
+
expect(coder?.systemPrompt.length).toBeGreaterThan(0);
|
|
252
|
+
// D-5(C1)去 tools 化:模板不再声明 tools 白名单——全部 undefined(工具约束
|
|
253
|
+
// 回归宿主默认面;想要白名单在 <ws>/.agents/agents/ 放同名 .md 覆写)。
|
|
254
|
+
// 本断言拦「tools 字段回流」——模板侧任何 tools 重新声明会在此立即报错。
|
|
255
|
+
for (const name of CORE) {
|
|
256
|
+
expect(
|
|
257
|
+
reg.loadByPath(path.join(AGENTS_DIR, `${name}.md`))?.tools,
|
|
258
|
+
`${name} 模板不应声明 tools`,
|
|
259
|
+
).toBeUndefined();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// ============================================================
|
|
265
|
+
// engine 字段(P4 D9:frontmatter 主通道 + 解析期注册表校验)
|
|
266
|
+
// ============================================================
|
|
267
|
+
|
|
268
|
+
describe("parseAgentWithMeta engine 字段(P4 路由)", () => {
|
|
269
|
+
beforeEach(() => {
|
|
270
|
+
// 解析期校验消费注册表——测试内注册假引擎(惰性工厂无副作用)
|
|
271
|
+
clearEngines();
|
|
272
|
+
// 工厂恒 throw:解析期校验只查注册表存在性,不实例化(惰性工厂契约)
|
|
273
|
+
const neverInstantiate = (): EnginePort => {
|
|
274
|
+
throw new Error("parse-time validation must not instantiate engines");
|
|
275
|
+
};
|
|
276
|
+
registerEngine("pi", neverInstantiate);
|
|
277
|
+
registerEngine("zcode", neverInstantiate);
|
|
278
|
+
});
|
|
279
|
+
afterEach(() => {
|
|
280
|
+
clearEngines();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("frontmatter engine 进 config.engine(结构化路径,IF1)", () => {
|
|
284
|
+
const { config, meta } = parseAgentWithMeta(
|
|
285
|
+
"/x/reviewer.md",
|
|
286
|
+
`---
|
|
287
|
+
name: reviewer
|
|
288
|
+
description: review agent
|
|
289
|
+
engine: zcode
|
|
290
|
+
---
|
|
291
|
+
body`,
|
|
292
|
+
);
|
|
293
|
+
expect(config.engine).toBe("zcode");
|
|
294
|
+
expect(meta?.kind === "agent" && meta.engine).toBe("zcode");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("IF1 未通过(缺 description)时 legacy fallback 取 engine(配置不丢,与 model 同判)", () => {
|
|
298
|
+
const { config } = parseAgentWithMeta(
|
|
299
|
+
"/x/reviewer.md",
|
|
300
|
+
`---
|
|
301
|
+
name: reviewer
|
|
302
|
+
engine: zcode
|
|
303
|
+
---
|
|
304
|
+
body`,
|
|
305
|
+
);
|
|
306
|
+
expect(config.engine).toBe("zcode");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("未注册 engine id:解析期抛 EngineNotFoundError,文案含注册清单与文件路径", () => {
|
|
310
|
+
expect(() =>
|
|
311
|
+
parseAgentWithMeta(
|
|
312
|
+
"/x/reviewer.md",
|
|
313
|
+
`---
|
|
314
|
+
name: reviewer
|
|
315
|
+
description: review agent
|
|
316
|
+
engine: nonexistent-engine
|
|
317
|
+
---
|
|
318
|
+
body`,
|
|
319
|
+
),
|
|
320
|
+
).toThrowError(/engine_not_found: engine 'nonexistent-engine'/);
|
|
321
|
+
expect(() =>
|
|
322
|
+
parseAgentWithMeta(
|
|
323
|
+
"/x/reviewer.md",
|
|
324
|
+
`---
|
|
325
|
+
name: reviewer
|
|
326
|
+
description: review agent
|
|
327
|
+
engine: nonexistent-engine
|
|
328
|
+
---
|
|
329
|
+
body`,
|
|
330
|
+
),
|
|
331
|
+
).toThrowError(/Registered engines: pi, zcode/);
|
|
332
|
+
expect(() =>
|
|
333
|
+
parseAgentWithMeta(
|
|
334
|
+
"/x/my-agent.md",
|
|
335
|
+
`---
|
|
336
|
+
name: my-agent
|
|
337
|
+
description: d
|
|
338
|
+
engine: nonexistent-engine
|
|
339
|
+
---
|
|
340
|
+
body`,
|
|
341
|
+
),
|
|
342
|
+
).toThrowError(/Source: \/x\/my-agent\.md/);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("已注册 id(pi/zcode):解析通过,不抛", () => {
|
|
346
|
+
expect(() =>
|
|
347
|
+
parseAgentWithMeta(
|
|
348
|
+
"/x/reviewer.md",
|
|
349
|
+
`---
|
|
350
|
+
name: reviewer
|
|
351
|
+
description: review agent
|
|
352
|
+
engine: pi
|
|
353
|
+
---
|
|
354
|
+
body`,
|
|
355
|
+
),
|
|
356
|
+
).not.toThrow();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("无 engine 字段:config.engine 缺省(走全局默认层)", () => {
|
|
360
|
+
const { config } = parseAgentWithMeta(
|
|
361
|
+
"/x/worker.md",
|
|
362
|
+
`---
|
|
363
|
+
name: worker
|
|
364
|
+
description: d
|
|
365
|
+
---
|
|
366
|
+
body`,
|
|
367
|
+
);
|
|
368
|
+
expect(config.engine).toBeUndefined();
|
|
369
|
+
});
|
|
370
|
+
});
|
|
@@ -57,6 +57,22 @@ describe("mapToWorkflowAgentResult (D-A10)", () => {
|
|
|
57
57
|
expect(result.parsedOutput).toEqual(parsedData);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
// ── D5-③: failureKind 分诊标签透传(产出侧 output-collector → 消费侧 executeAgentCall) ──
|
|
61
|
+
|
|
62
|
+
it("failureKind 三态逐值透传(stale_context / schema_deterministic / unknown)", () => {
|
|
63
|
+
for (const kind of ["stale_context", "schema_deterministic", "unknown"] as const) {
|
|
64
|
+
const r: SubagentsAgentResult = { ...minimalResult, success: false, error: "boom", failureKind: kind };
|
|
65
|
+
const result = mapToWorkflowAgentResult(r);
|
|
66
|
+
expect(result.failureKind).toBe(kind);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("failureKind 缺省(成功路径/上游未写)→ 不落键(消费侧视为 unknown = 可重试)", () => {
|
|
71
|
+
const result = mapToWorkflowAgentResult(minimalResult);
|
|
72
|
+
expect(result.failureKind).toBeUndefined();
|
|
73
|
+
expect("failureKind" in result).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
60
76
|
// ── T3.14: 失败路径 ──
|
|
61
77
|
|
|
62
78
|
it("映射失败: success=false 且 error → 填入 error 字段", () => {
|
|
@@ -74,7 +90,7 @@ describe("mapToWorkflowAgentResult (D-A10)", () => {
|
|
|
74
90
|
const result = mapToWorkflowAgentResult(r);
|
|
75
91
|
expect(result.error).toBeDefined();
|
|
76
92
|
expect(typeof result.error).toBe("string");
|
|
77
|
-
expect(result.error
|
|
93
|
+
expect(result.error!.length).toBeGreaterThan(0);
|
|
78
94
|
});
|
|
79
95
|
|
|
80
96
|
it("映射成功: success=true 且 error 存在 → error=undefined(不误填)", () => {
|
|
@@ -143,7 +159,7 @@ describe("mapToWorkflowAgentResult (D-A10)", () => {
|
|
|
143
159
|
});
|
|
144
160
|
|
|
145
161
|
it("映射 toolCalls: 无 toolCalls → undefined", () => {
|
|
146
|
-
const r
|
|
162
|
+
const r = { ...minimalResult, toolCalls: undefined } as unknown as SubagentsAgentResult;
|
|
147
163
|
const result = mapToWorkflowAgentResult(r);
|
|
148
164
|
expect(result.toolCalls).toBeUndefined();
|
|
149
165
|
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// src/execution/__tests__/agents-assembly.test.ts
|
|
2
|
+
//
|
|
3
|
+
// discoverAgents 装配函数测试(sink 设计 U2 / A6 / u-core-agent 验收②)。
|
|
4
|
+
//
|
|
5
|
+
// 等值对照口径:fixture 目录下,discoverAgents 产出与 pi 壳现装配循环
|
|
6
|
+
// (subagent-list-injector.discoverAllAgents)产出「同序同名同字段」。
|
|
7
|
+
// pi 壳装配循环无法直接 import 进 core 测试(core 对 pi-coding-agent /
|
|
8
|
+
// pi-extension-logger 零运行时触点——vitest.config 头注红线),故 oracle 在
|
|
9
|
+
// 测试内按 pi 循环逐句同构复刻,但全部消费 core 既有原语
|
|
10
|
+
// (discoverResources + parseResourceMeta 严格层 + sortByCodepoint)——
|
|
11
|
+
// 这正是 pi 循环消费的同一批 core 原语(pi 的 parseAgentFrontmatter 内部即
|
|
12
|
+
// parseResourceMeta(content, "agent") 投影)。oracle 与被测实现走不同解析路径
|
|
13
|
+
// (严格层 vs parseAgentProfile 宽容层),非自证。
|
|
14
|
+
//
|
|
15
|
+
// fixture 含全部清单可见性分支:正常条目(多形态)、同名遮蔽(hostRoots
|
|
16
|
+
// last-writer-wins)、无 frontmatter(README,两边都不进清单)、IF1 失败
|
|
17
|
+
// (缺 description,两边都不进清单)。
|
|
18
|
+
|
|
19
|
+
import * as fs from "node:fs";
|
|
20
|
+
import * as os from "node:os";
|
|
21
|
+
import * as path from "node:path";
|
|
22
|
+
|
|
23
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
24
|
+
|
|
25
|
+
import { configureCore, resetCoreForTests } from "../../core/host-services.ts";
|
|
26
|
+
import type { AgentEntry } from "../../shared/injection-render.ts";
|
|
27
|
+
import { sortByCodepoint } from "../../shared/injection-render.ts";
|
|
28
|
+
import { parseResourceMeta } from "../../shared/meta-parser.ts";
|
|
29
|
+
import {
|
|
30
|
+
clearFileCache,
|
|
31
|
+
discoverResources,
|
|
32
|
+
getCachedFileContent,
|
|
33
|
+
type ScanConfig,
|
|
34
|
+
} from "../../shared/resource-discovery.ts";
|
|
35
|
+
import type { DiscoveryRoot } from "../../core/host-services.ts";
|
|
36
|
+
import { discoverAgents } from "../agents-assembly.ts";
|
|
37
|
+
|
|
38
|
+
// ── oracle:pi 壳 discoverAllAgents 装配循环的逐句同构(消费同一批 core 原语)──
|
|
39
|
+
|
|
40
|
+
async function piAssemblyOracle(
|
|
41
|
+
workspaceRoot: string,
|
|
42
|
+
hostRoots: DiscoveryRoot[],
|
|
43
|
+
): Promise<AgentEntry[]> {
|
|
44
|
+
const config: ScanConfig = { kind: "agents", workspaceRoot, hostRoots };
|
|
45
|
+
const resources = await discoverResources(config);
|
|
46
|
+
|
|
47
|
+
const agentMap = new Map<string, AgentEntry>();
|
|
48
|
+
for (const resource of resources) {
|
|
49
|
+
if (!resource.available) continue;
|
|
50
|
+
const content = getCachedFileContent(resource.path);
|
|
51
|
+
if (content === null) continue; // pi: catch → logger.error → skip
|
|
52
|
+
// pi parseAgentFrontmatter 的投影面(parseResourceMeta 严格层)
|
|
53
|
+
const meta = parseResourceMeta(content, "agent");
|
|
54
|
+
if (meta && meta.kind === "agent") {
|
|
55
|
+
agentMap.set(meta.name, {
|
|
56
|
+
name: meta.name,
|
|
57
|
+
description: meta.description,
|
|
58
|
+
when: meta.when,
|
|
59
|
+
examples: meta.examples,
|
|
60
|
+
path: resource.path,
|
|
61
|
+
});
|
|
62
|
+
} else if (content.trimStart().startsWith("---")) {
|
|
63
|
+
// pi: startsWithFrontmatter → logger.warn(清单可见性口径:无 frontmatter 不 warn)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return sortByCodepoint([...agentMap.values()], (a) => a.name);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ── fixture ──────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
function writeAgent(root: string, rel: string, content: string): string {
|
|
72
|
+
const abs = path.join(root, rel);
|
|
73
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
74
|
+
fs.writeFileSync(abs, content, "utf-8");
|
|
75
|
+
return abs;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe("discoverAgents", () => {
|
|
79
|
+
let outerDir: string;
|
|
80
|
+
let workspaceRoot: string;
|
|
81
|
+
let hostRoot: string;
|
|
82
|
+
let logCalls: Array<{ level: string; component: string; message: string; data?: unknown }>;
|
|
83
|
+
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
outerDir = fs.mkdtempSync(path.join(os.tmpdir(), "agents-assembly-"));
|
|
86
|
+
workspaceRoot = path.join(outerDir, "ws");
|
|
87
|
+
hostRoot = path.join(outerDir, "host", "agents");
|
|
88
|
+
fs.mkdirSync(workspaceRoot, { recursive: true });
|
|
89
|
+
logCalls = [];
|
|
90
|
+
configureCore({
|
|
91
|
+
dataRoot: () => outerDir,
|
|
92
|
+
log: (level, component, message, data) => {
|
|
93
|
+
logCalls.push({ level, component, message, data });
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
resetCoreForTests();
|
|
100
|
+
clearFileCache();
|
|
101
|
+
fs.rmSync(outerDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("与 pi 壳现装配循环产出等值(同序同名同字段)——多形态 fixture 对照", async () => {
|
|
105
|
+
// project-pi 源(workspaceRoot/.pi/agents)
|
|
106
|
+
writeAgent(
|
|
107
|
+
workspaceRoot,
|
|
108
|
+
".pi/agents/alpha.md",
|
|
109
|
+
`---
|
|
110
|
+
name: alpha
|
|
111
|
+
description: single-line agent
|
|
112
|
+
model: provider/model-a
|
|
113
|
+
---
|
|
114
|
+
alpha body`,
|
|
115
|
+
);
|
|
116
|
+
// block-scalar description + 多行 - item(zsw mini parser 全形态)
|
|
117
|
+
writeAgent(
|
|
118
|
+
workspaceRoot,
|
|
119
|
+
".pi/agents/beta.md",
|
|
120
|
+
`---
|
|
121
|
+
name: beta
|
|
122
|
+
description: |
|
|
123
|
+
beta line one
|
|
124
|
+
beta line two
|
|
125
|
+
tools:
|
|
126
|
+
- read
|
|
127
|
+
- bash
|
|
128
|
+
---
|
|
129
|
+
beta body`,
|
|
130
|
+
);
|
|
131
|
+
// 无 frontmatter(两边都不进清单、都不 warn)
|
|
132
|
+
writeAgent(workspaceRoot, ".pi/agents/README.md", "# docs\n");
|
|
133
|
+
// IF1 失败(缺 description,两边都不进清单、都 warn)
|
|
134
|
+
writeAgent(
|
|
135
|
+
workspaceRoot,
|
|
136
|
+
".pi/agents/broken.md",
|
|
137
|
+
`---
|
|
138
|
+
name: broken
|
|
139
|
+
model: provider/x
|
|
140
|
+
---
|
|
141
|
+
broken body`,
|
|
142
|
+
);
|
|
143
|
+
// hostRoots 注入源(序位高于 project-pi)——同名遮蔽 alpha + 新增 gamma
|
|
144
|
+
writeAgent(
|
|
145
|
+
hostRoot,
|
|
146
|
+
"alpha.md",
|
|
147
|
+
`---
|
|
148
|
+
name: alpha
|
|
149
|
+
description: host shadowing version
|
|
150
|
+
---
|
|
151
|
+
host alpha body`,
|
|
152
|
+
);
|
|
153
|
+
writeAgent(
|
|
154
|
+
hostRoot,
|
|
155
|
+
"gamma.md",
|
|
156
|
+
`---
|
|
157
|
+
name: gamma
|
|
158
|
+
description: inline array agent
|
|
159
|
+
tools: [read, grep]
|
|
160
|
+
maxTurns: 2
|
|
161
|
+
---
|
|
162
|
+
gamma body`,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const hostRoots: DiscoveryRoot[] = [{ dir: hostRoot, source: "project-host" }];
|
|
166
|
+
const [actual, oracle] = await Promise.all([
|
|
167
|
+
discoverAgents(workspaceRoot, hostRoots),
|
|
168
|
+
piAssemblyOracle(workspaceRoot, hostRoots),
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
// 同序同名同字段(逐条目投影对比,path 为绝对路径逐字节一致)
|
|
172
|
+
expect(actual).toEqual(oracle);
|
|
173
|
+
// 码点序:alpha < beta < gamma
|
|
174
|
+
expect(actual.map((a) => a.name)).toEqual(["alpha", "beta", "gamma"]);
|
|
175
|
+
// 同名遮蔽:alpha = hostRoots 胜出版(path + description 都是注入根的)
|
|
176
|
+
const alpha = actual.find((a) => a.name === "alpha");
|
|
177
|
+
expect(alpha?.path).toBe(path.join(hostRoot, "alpha.md"));
|
|
178
|
+
expect(alpha?.description).toBe("host shadowing version");
|
|
179
|
+
// 无 frontmatter / IF1 失败不进清单
|
|
180
|
+
expect(actual.some((a) => a.path.endsWith("README.md"))).toBe(false);
|
|
181
|
+
expect(actual.some((a) => a.path.endsWith("broken.md"))).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("hostRoots 为空时仍扫硬编码槽(project .pi/agents),等值口径不破", async () => {
|
|
185
|
+
writeAgent(
|
|
186
|
+
workspaceRoot,
|
|
187
|
+
".pi/agents/solo.md",
|
|
188
|
+
"---\nname: solo\ndescription: only one\n---\nbody",
|
|
189
|
+
);
|
|
190
|
+
const [actual, oracle] = await Promise.all([
|
|
191
|
+
discoverAgents(workspaceRoot, []),
|
|
192
|
+
piAssemblyOracle(workspaceRoot, []),
|
|
193
|
+
]);
|
|
194
|
+
expect(actual).toEqual(oracle);
|
|
195
|
+
expect(actual.map((a) => a.name)).toEqual(["solo"]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("IF1 失败(有 frontmatter)→ warn 口径内聚:仅该类文件 warn,README 不 warn", async () => {
|
|
199
|
+
writeAgent(
|
|
200
|
+
workspaceRoot,
|
|
201
|
+
".pi/agents/broken.md",
|
|
202
|
+
"---\nname: broken\nmodel: provider/x\n---\nbody",
|
|
203
|
+
);
|
|
204
|
+
writeAgent(workspaceRoot, ".pi/agents/README.md", "# plain doc\n");
|
|
205
|
+
|
|
206
|
+
const actual = await discoverAgents(workspaceRoot, []);
|
|
207
|
+
expect(actual).toEqual([]);
|
|
208
|
+
|
|
209
|
+
const warns = logCalls.filter((c) => c.level === "warn");
|
|
210
|
+
expect(warns).toHaveLength(1);
|
|
211
|
+
expect(warns[0]!.message).toContain("broken.md");
|
|
212
|
+
expect(warns[0]!.message).toContain("IF1 校验不通过");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("空目录 / 不存在的 workspaceRoot:空清单不抛", async () => {
|
|
216
|
+
const actual = await discoverAgents(path.join(outerDir, "nonexistent"), []);
|
|
217
|
+
expect(actual).toEqual([]);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -72,7 +72,7 @@ vi.mock("../alive-store.ts", () => ({
|
|
|
72
72
|
writeAliveMarker: vi.fn(),
|
|
73
73
|
}));
|
|
74
74
|
|
|
75
|
-
vi.mock("../temp-prompt.ts", () => ({
|
|
75
|
+
vi.mock("../engine/engines/pi/temp-prompt.ts", () => ({
|
|
76
76
|
writePromptToTempFile: vi.fn(async (agent: string) => {
|
|
77
77
|
const safeName = agent.replace(/[^\w.-]+/g, "_");
|
|
78
78
|
return { dir: `/tmp/fake-${safeName}`, filePath: `/tmp/fake-${safeName}/prompt-${safeName}.md` };
|
|
@@ -81,7 +81,7 @@ vi.mock("../temp-prompt.ts", () => ({
|
|
|
81
81
|
}));
|
|
82
82
|
|
|
83
83
|
import { DialogGlobalQueue } from "../dialog-queue.ts";
|
|
84
|
-
import { runSpawn, type SessionRunnerContext } from "../session-runner.ts";
|
|
84
|
+
import { runSpawn, type SessionRunnerContext } from "../engine/engines/pi/session-runner.ts";
|
|
85
85
|
import { type ChannelHandler,createUiChannelRegistry } from "../ui-channels.ts";
|
|
86
86
|
import { createUiRequestHandlerForMode } from "../ui-request-handler-factory.ts";
|
|
87
87
|
import {
|
|
@@ -168,7 +168,7 @@ function makeAskUserCtx(
|
|
|
168
168
|
},
|
|
169
169
|
modelRegistry: undefined,
|
|
170
170
|
model: undefined,
|
|
171
|
-
} as SessionRunnerContext;
|
|
171
|
+
} as unknown as SessionRunnerContext;
|
|
172
172
|
const handler = createUiRequestHandlerForMode(ctx as never, registry, dialogQueue);
|
|
173
173
|
return makeCtxBase({
|
|
174
174
|
...overrides,
|
|
@@ -315,11 +315,11 @@ describe("ask_user 跨进程 transit e2e (#34)", () => {
|
|
|
315
315
|
// 验证:连续 emit 两个 ask_user,channel handler 按顺序被调,response 按顺序写回。
|
|
316
316
|
const registry = createUiChannelRegistry();
|
|
317
317
|
const callOrder: string[] = [];
|
|
318
|
-
const channelHandler: ChannelHandler = vi.fn(async (req:
|
|
319
|
-
callOrder.push(req.id);
|
|
318
|
+
const channelHandler: ChannelHandler = vi.fn(async (req: unknown) => {
|
|
319
|
+
callOrder.push((req as { id: string }).id);
|
|
320
320
|
// 加延迟让两个请求有机会并发(若队列没串行)
|
|
321
321
|
await new Promise((r) => setTimeout(r, 15));
|
|
322
|
-
return { value: `ans-${req.id}` };
|
|
322
|
+
return { value: `ans-${(req as { id: string }).id}` };
|
|
323
323
|
});
|
|
324
324
|
registry.register("ask_user", channelHandler);
|
|
325
325
|
|