@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
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
// src/execution/engine/engines/zcode/constants.ts
|
|
2
2
|
//
|
|
3
3
|
// ZcodeEngine 共享常量(P3)。独立成模块的原因:reader.ts 是双端复用的无状态模块
|
|
4
|
-
// (设计 §3.3.7:runtime 侧也会 import
|
|
5
|
-
//
|
|
4
|
+
// (设计 §3.3.7:runtime 侧也会 import),它需要的常量不能连带其他模块的模块级
|
|
5
|
+
// 副作用(如 logger 初始化)一起加载——constants.ts 保持零 import 纯常量。
|
|
6
|
+
//
|
|
7
|
+
// 2026-09 重构(共享宿主 HOME):删除 CLI spawn 降级链与 HOME 池化全部常量
|
|
8
|
+
// (home-appserver 池/锁/pidfile/派生上限/凭据引导/probe 冒烟/漂移降级码)。
|
|
9
|
+
// 引擎只走 app-server RPC,spawn env 不覆写 HOME(共享宿主 ~/.zcode/)。
|
|
6
10
|
|
|
7
11
|
/** zcode 引擎的 registry key。 */
|
|
8
12
|
export const ZCODE_ENGINE_ID = "zcode";
|
|
9
13
|
|
|
10
14
|
/** zcode 适配器版本(handle.adapterVersion 数据源——golden 样本对齐排查锚点)。 */
|
|
11
|
-
export const ZCODE_ADAPTER_VERSION = "
|
|
15
|
+
export const ZCODE_ADAPTER_VERSION = "2.0.0";
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* zcode CLI 缺省路径(12.4MB node bundle,不在 PATH——2026-08-25 实测)。
|
|
@@ -18,26 +22,155 @@ export const ZCODE_CLI_DEFAULT_PATH = "/Applications/ZCode.app/Contents/Resource
|
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* 唯一凭据源 config(桌面端登录态,zsub V2_CONFIG_PATH 同构)。
|
|
21
|
-
* 为什么绝不读 ~/.zcode/cli/config.json
|
|
22
|
-
*
|
|
23
|
-
* turn 0 即 401);桌面端登录凭据落在 v2/config.json
|
|
25
|
+
* 为什么绝不读 ~/.zcode/cli/config.json 作为引擎侧凭据校验源:它不在 ZCode GUI
|
|
26
|
+
* 管理面,可能残留历史验证配置(2026-08-25 事故:8/24 zsub 开发残留把默认模型
|
|
27
|
+
* 劫持到失效 router 端点,turn 0 即 401);桌面端登录凭据落在 v2/config.json,
|
|
28
|
+
* 是 zsub 生产验证过的凭据源。共享宿主 HOME 后引擎侧只读它做模型解析校验;
|
|
29
|
+
* app-server 进程侧 CLI 只认 ~/.zcode/cli/config.json(GUI 从不写该文件),由
|
|
30
|
+
* appserver-launcher 的 fs 拦截 wrapper 把对该文件的读取重定向为「真实文件 +
|
|
31
|
+
* v2 provider 注入」内存合并(同 id 时 v2 整条优先)——凭据实际供数仍以 v2 为
|
|
32
|
+
* 权威源,并非直接消费宿主 HOME 的原始 cli config。
|
|
24
33
|
*/
|
|
25
34
|
export const ZCODE_V2_CONFIG_PATH_SUFFIX = [".zcode", "v2", "config.json"] as const;
|
|
26
35
|
|
|
27
|
-
/**
|
|
28
|
-
export const
|
|
36
|
+
/** zsub 同构的兜底缺省模型(v2 config 无 model.main 且 task 未指定时)。 */
|
|
37
|
+
export const ZCODE_FALLBACK_DEFAULT_MODEL = "builtin:bigmodel-coding-plan/GLM-5.3";
|
|
29
38
|
|
|
30
39
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
40
|
+
* 宿主 HOME 下 zcode 会话 db 的相对位置(共享 HOME 形态的 handle.sessionRef.dbPath
|
|
41
|
+
* 锚点——绝对路径 = join(os.homedir(), ...suffix);runtime 读侧用它做精确白名单,
|
|
42
|
+
* 旧池时代 records 的相对 dbPath 仍按 poolKey 锚定兼容)。
|
|
33
43
|
*/
|
|
34
|
-
export const
|
|
35
|
-
|
|
36
|
-
/** zsub 同构的兜底缺省模型(v2 config 无 model.main 且 task 未指定时)。 */
|
|
37
|
-
export const ZCODE_FALLBACK_DEFAULT_MODEL = "builtin:bigmodel-coding-plan/GLM-5.3";
|
|
44
|
+
export const ZCODE_HOST_DB_SUFFIX = [".zcode", "cli", "db", "db.sqlite"] as const;
|
|
38
45
|
|
|
39
46
|
/** 杀链 grace 窗口:SIGTERM 后等这么久再 SIGKILL(zsub 同构 5s;实测 SIGTERM→exit 仅 103ms)。 */
|
|
40
47
|
export const ZCODE_KILL_GRACE_MS = 5_000;
|
|
41
48
|
|
|
42
49
|
/** 错误信息里保留的 stdout 尾部长度(engine_run_failed 规格:够诊断、不刷屏)。 */
|
|
43
50
|
export const ZCODE_ERROR_TAIL_CHARS = 2000;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* [R2] app-server 控制面请求默认超时(ms)。依据:旧 zsw 实现 REQUEST_TIMEOUT_MS=15s
|
|
54
|
+
* (60+ fake-server 用例 + 真机 e2e 验证值)。
|
|
55
|
+
*/
|
|
56
|
+
export const ZCODE_APPSERVER_REQUEST_TIMEOUT_MS = 15_000;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* [R2] 连接崩溃错误信息附带的 stderr 尾部长度(字符)。设计 zcode-engine-appserver-
|
|
60
|
+
* resident.md §3.1 失败路径 2 / §3.3 错误规格表「进程意外退出」行:stderr 尾 400 字符。
|
|
61
|
+
*/
|
|
62
|
+
export const ZCODE_APPSERVER_STDERR_TAIL_CHARS = 400;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* [R2] stderr 滚动缓冲上限(字符):只保最近内容供崩溃诊断。旧 zsw 实现同值 2048。
|
|
66
|
+
*/
|
|
67
|
+
export const ZCODE_APPSERVER_STDERR_TAIL_BUFFER_CHARS = 2048;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* [R3] 终态判定后 session/read 兜底拉取的超时(ms)。read 是全文权威来源(不变量 1
|
|
71
|
+
* 的双来源之二),失败不抛——降级收尾帧/delta 聚合。旧 zsw 实现 READ_TIMEOUT_MS=5000。
|
|
72
|
+
*/
|
|
73
|
+
export const ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS = 5_000;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* [R3] 任务收尾 session/close 的控制面超时(ms,best-effort——失败只 warn 不抛)。
|
|
77
|
+
* 旧 zsw 实现 RELEASE_CLOSE_TIMEOUT_MS=1500(wave2 D2,同值同语义)。
|
|
78
|
+
*/
|
|
79
|
+
export const ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS = 1_500;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* [R3 → superseded by P0-1] 旧「一轮终态等待」固定墙钟缺省值(ms)。**已被
|
|
83
|
+
* `ZCODE_TURN_IDLE_TIMEOUT_MS`(idle 主判定)+ `ZCODE_TURN_MAX_TIMEOUT_MS`
|
|
84
|
+
* (总上界兜底)两 timer 语义替换,session-channel 不再消费本值**——固定墙钟
|
|
85
|
+
* 「到点=不可推进」判定被 2026-09 T001 深诊击穿(21% 活跃任务被误杀,见设计
|
|
86
|
+
* timeout-zcode-turn-and-settled-watchdog.md §3.1/§4)。符号保留:audit/设计
|
|
87
|
+
* 文档(timeout-audit-2026-09.md 等)以本名记录事故成因,删除即产生悬空引用。
|
|
88
|
+
*/
|
|
89
|
+
export const ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS = 300_000;
|
|
90
|
+
|
|
91
|
+
// ============================================================
|
|
92
|
+
// [P0-1 U1] turn 等待两 timer(idle 主判定 + 总上界回收兜底)
|
|
93
|
+
// 设计权威源:docs/design/timeout-zcode-turn-and-settled-watchdog.md §6 D1/D2
|
|
94
|
+
// ============================================================
|
|
95
|
+
|
|
96
|
+
/** turn idle 主判定的 env 覆盖通道(>0 覆盖、≤0 关闭、非法值 warn+回落默认)。 */
|
|
97
|
+
export const ZCODE_TURN_IDLE_TIMEOUT_ENV = "XYZ_ZCODE_TURN_IDLE_TIMEOUT_MS";
|
|
98
|
+
|
|
99
|
+
/** turn 总上界的 env 覆盖通道(语义同上;0=关闭后 chatty-wedge 无自动回收)。 */
|
|
100
|
+
export const ZCODE_TURN_MAX_TIMEOUT_ENV = "XYZ_ZCODE_TURN_MAX_TIMEOUT_MS";
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* [P0-1 D1] turn idle 主判定缺省阈值(ms):该 turn 任何事件到达刷新计时,连续
|
|
104
|
+
* 静默达此值判「执行已不可推进」。活跃事件流零误杀(ADR-0047 逆否面)。默认
|
|
105
|
+
* 30min 为先验值,⛔P-Z1 门(事件流 inter-event gap 分布)标定前用此默认。
|
|
106
|
+
*/
|
|
107
|
+
export const ZCODE_TURN_IDLE_TIMEOUT_MS = 1_800_000;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* [P0-1 D1] turn 总上界缺省值(ms):从 openTurn 挂载起固定不刷新,兜 idle 覆盖
|
|
111
|
+
* 不了的 chatty-wedge(事件持续但终态永不到达)。对超上界的合法极长任务是显式
|
|
112
|
+
* 接受的残余误杀面(env 可调/可关 + 错误文案附自救指引)。默认 60min 为先验值
|
|
113
|
+
* (T001 34 任务最长 541s,先验远离 6.6×),⛔P-Z0 门(任务总时长分布)标定前
|
|
114
|
+
* 用此默认。
|
|
115
|
+
*/
|
|
116
|
+
export const ZCODE_TURN_MAX_TIMEOUT_MS = 3_600_000;
|
|
117
|
+
|
|
118
|
+
/** `parseZcodeTurnTimeoutEnv` 的解析结果(可判别联合——valid 分支 ms 必有)。 */
|
|
119
|
+
export type ZcodeTurnTimeoutEnvParse =
|
|
120
|
+
| { state: "unset" }
|
|
121
|
+
| { state: "valid"; ms: number }
|
|
122
|
+
| { state: "invalid" };
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 解析 turn 阈值 env 原始值(空串视同未设置,对齐 lifecycle-manager 先例的
|
|
126
|
+
* `if (!raw)` 口径)。**与 `XYZ_SUBAGENT_IDLE_TIMEOUT_MS` 先例的刻意分歧(设计
|
|
127
|
+
* D2/r3 SG-5 显式登记)**:先例 ≤0=非法回落且禁用后不认 env;本通道 ≤0=显式
|
|
128
|
+
* 关闭该 timer(规则 19 的 opt-out 出路),非法(非数字)才回落默认——调用方
|
|
129
|
+
* 必须对 invalid 与 ≤0 关闭分别 warn 留痕(生效行为可见,A10① 断言依据)。
|
|
130
|
+
*/
|
|
131
|
+
export function parseZcodeTurnTimeoutEnv(
|
|
132
|
+
raw: string | undefined
|
|
133
|
+
): ZcodeTurnTimeoutEnvParse {
|
|
134
|
+
if (raw === undefined || raw === "") return { state: "unset" };
|
|
135
|
+
const parsed = Number(raw);
|
|
136
|
+
if (!Number.isFinite(parsed)) return { state: "invalid" };
|
|
137
|
+
return { state: "valid", ms: parsed };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 共享宿主 HOME 语义下的 journal 分组 key(与 pi 引擎 PI_POOL_KEY='shared' 同构):
|
|
142
|
+
* journal 落 engineDataDir/engines/zcode/shared/journal-<taskId>.jsonl。无隔离池、
|
|
143
|
+
* 无派生目录——key 是固定字面量,仅作 pool-manager 通用契约的分组锚点。
|
|
144
|
+
*/
|
|
145
|
+
export const ZCODE_SHARED_POOL_KEY = "shared";
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* [R4 D3] abort 链第一级:session/stop 的控制面超时(ms)。stop 失败/超时即落
|
|
149
|
+
* killChain(协议此时已不可信)。
|
|
150
|
+
*/
|
|
151
|
+
export const ZCODE_APPSERVER_STOP_TIMEOUT_MS = 3_000;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* [R4 D3] abort 链第二级:stop 送达后的终态确认 grace 窗口(ms)。窗口内终态
|
|
155
|
+
* 到达 → 不杀共享进程;超时 → killChain 连坐。
|
|
156
|
+
*/
|
|
157
|
+
export const ZCODE_APPSERVER_ABORT_GRACE_MS = 3_000;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* [R4] app-server 内部错误码中「模型配置缺失」的归类判据(A.3:-32603 内部错误族,
|
|
161
|
+
* 消息含 "Model config is missing"——错误规格表第 2 行:报 engine_credential_missing)。
|
|
162
|
+
*/
|
|
163
|
+
export const ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING = -32603;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* [R5] app-server 内部错误码「会话忙」:send 时该会话已有轮在跑(busy 不排队不打断)。
|
|
167
|
+
* 单会话一任务是结构保证,运行中命中即 bug(错误文案引导上报 sessionId 与 state 流水)。
|
|
168
|
+
*/
|
|
169
|
+
export const ZCODE_APPSERVER_ERR_BUSY_SESSION = -32010;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* [R5] 崩溃收割确认的兜底窗口(ms):killChain 在 `exit` 事件 resolve,而连接
|
|
173
|
+
* finalize(onClose → 在途 turn 崩溃收割)挂 `close` 事件——channel 退订前等 onClose
|
|
174
|
+
* 触发,本窗口兜底防 `close` 永不到达时 dispose 挂死。
|
|
175
|
+
*/
|
|
176
|
+
export const ZCODE_APPSERVER_HARVEST_GRACE_MS = 1_000;
|
|
@@ -1,39 +1,47 @@
|
|
|
1
1
|
// src/execution/engine/engines/zcode/golden-sample.ts
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// golden 语料内嵌副本(2026-09 收缩:CLI spawn 链删除后只剩 app-server 通道语料——
|
|
4
|
+
// spawn 单 JSON 样本(ZCODE_GOLDEN_STDOUT)随 probe 干跑/spawn 回归一并删除):
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
6
|
+
// app-server NDJSON 帧序列(R3,D8-②):常驻通道的 golden 帧序列语料,四类样本
|
|
7
|
+
// (create 应答 / 推送流 / 终态帧 / read 应答,附录 A.2 任务生命周期帧序)。
|
|
8
|
+
// 来源:按 A.2 协议权威 + 旧 zsw 实现真机抓包形态合成(非实录,fixture _meta
|
|
9
|
+
// 如实标注);真机冒烟后替换。fixture __tests__/__fixtures__/zcode-golden-appserver.json
|
|
10
|
+
// 是采集 SSOT,此处为运行时副本,更新样本需同步改两处(session-channel 测试
|
|
11
|
+
// diff 校验)。
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"reasoningTokens": 0,
|
|
27
|
-
"webFetchRequests": 0,
|
|
28
|
-
"webSearchRequests": 0
|
|
29
|
-
},
|
|
30
|
-
"eventCount": 17,
|
|
31
|
-
"projection": {
|
|
32
|
-
"status": "idle",
|
|
33
|
-
"turnCount": 1,
|
|
34
|
-
"totalTokenCount": 12616,
|
|
35
|
-
"contextUsed": 12616,
|
|
36
|
-
"contextWindow": 1000000
|
|
37
|
-
}
|
|
13
|
+
// ============================================================
|
|
14
|
+
// [②app-server] NDJSON 帧序列语料(R3,附录 A.2 帧序逐字)
|
|
15
|
+
// ============================================================
|
|
16
|
+
|
|
17
|
+
/** 四类样本的结构(与 zcode-golden-appserver.json 的 frames 字段一一对应)。 */
|
|
18
|
+
export interface AppServerGoldenFrames {
|
|
19
|
+
/** ① session/create 应答帧(NDJSON 单行;projection.sessionId 恒 "unknown" 勿用)。 */
|
|
20
|
+
createResponse: string;
|
|
21
|
+
/** ④ 推送流帧(NDJSON 逐行:state.updated / stream.chunk 无文本 / session/event delta 有文本)。 */
|
|
22
|
+
pushStream: string[];
|
|
23
|
+
/** ⑤ 终态帧(NDJSON 逐行:v4 telemetry turn.terminal 权威 + session/event 收尾帧全文/usage)。 */
|
|
24
|
+
terminal: string[];
|
|
25
|
+
/** ⑥ session/read 应答帧(NDJSON 单行:messages[].parts[],text 全文 + step-finish tokens)。 */
|
|
26
|
+
readResponse: string;
|
|
38
27
|
}
|
|
39
|
-
|
|
28
|
+
|
|
29
|
+
/** [②app-server] golden 帧序列内嵌副本(采集 SSOT = zcode-golden-appserver.json,双副本 diff 防漂移)。 */
|
|
30
|
+
export const ZCODE_APPSERVER_GOLDEN: AppServerGoldenFrames = {
|
|
31
|
+
createResponse:
|
|
32
|
+
'{"session":{"sessionId":"sess_golden_r3_01"},"projection":{"sessionId":"unknown","status":"idle","turnCount":0,"totalTokenCount":0,"contextUsed":0,"contextWindow":1000000}}',
|
|
33
|
+
pushStream: [
|
|
34
|
+
'{"method":"state.updated","params":{"sessionId":"sess_golden_r3_01","patch":{"status":"running"},"reason":"prompt_started"}}',
|
|
35
|
+
'{"method":"v4/telemetry/event","params":{"kind":"stream.chunk","channel":"text","chunkLength":6,"firstChunk":true,"assistantMessageId":"msg_golden_r3_01"}}',
|
|
36
|
+
'{"method":"session/event","params":{"sessionId":"sess_golden_r3_01","payload":{"delta":"你好","assistantMessageId":"msg_golden_r3_01"}}}',
|
|
37
|
+
'{"method":"v4/telemetry/event","params":{"kind":"stream.chunk","channel":"text","chunkLength":1,"firstChunk":false,"assistantMessageId":"msg_golden_r3_01"}}',
|
|
38
|
+
'{"method":"session/event","params":{"sessionId":"sess_golden_r3_01","payload":{"delta":",","assistantMessageId":"msg_golden_r3_01"}}}',
|
|
39
|
+
'{"method":"session/event","params":{"sessionId":"sess_golden_r3_01","payload":{"delta":"任务完成","assistantMessageId":"msg_golden_r3_01"}}}',
|
|
40
|
+
],
|
|
41
|
+
terminal: [
|
|
42
|
+
'{"method":"v4/telemetry/event","params":{"kind":"turn.terminal","status":"success"}}',
|
|
43
|
+
'{"method":"session/event","params":{"sessionId":"sess_golden_r3_01","payload":{"response":"你好,任务完成","usage":{"inputTokens":12599,"outputTokens":17}}}}',
|
|
44
|
+
],
|
|
45
|
+
readResponse:
|
|
46
|
+
'{"messages":[{"info":{"role":"user"},"parts":[{"type":"text","text":"做点什么"}]},{"info":{"role":"assistant"},"parts":[{"type":"text","text":"你好"},{"type":"text","text":",任务完成"},{"type":"step-finish","tokens":{"input":12599,"output":17,"reasoning":0,"cache":512,"total":12616}}]}]}',
|
|
47
|
+
};
|