@zhushanwen/subagent-core 0.4.0 → 0.6.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.
- package/dist/{chunk-4KN4TTG7.js → chunk-43ONBFZX.js} +1 -1
- package/dist/{chunk-X7SZ5HLQ.js → chunk-V3VHZ2VX.js} +20 -27
- package/dist/execution/engine/engines/zcode/constants.cjs +29 -41
- package/dist/execution/engine/engines/zcode/constants.d.cts +65 -53
- package/dist/execution/engine/engines/zcode/constants.d.ts +65 -53
- package/dist/execution/engine/engines/zcode/constants.js +17 -27
- 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 +2 -2
- package/dist/index.cjs +17100 -14082
- package/dist/index.d.cts +5336 -4033
- package/dist/index.d.ts +5336 -4033
- package/dist/index.js +17020 -14055
- package/dist/{types-DpUO16pj.d.cts → types-C3fE3R9x.d.cts} +280 -112
- package/dist/{types-DpUO16pj.d.ts → types-C3fE3R9x.d.ts} +280 -112
- package/dist.bundle/index.cjs +34933 -0
- package/package.json +3 -3
- 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 +4 -2
- package/src/__tests__/review-fix-loop-utils.test.ts +10 -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/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 +4 -4
- 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 +2 -2
- package/src/execution/__tests__/alive-store.test.ts +1 -1
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +6 -6
- package/src/execution/__tests__/chat-engine-routing.test.ts +68 -33
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +4 -4
- package/src/execution/__tests__/cold-resurrect.test.ts +283 -0
- package/src/execution/__tests__/collect-budget.test.ts +291 -0
- package/src/execution/__tests__/collect-coordinator-service.test.ts +327 -0
- package/src/execution/__tests__/collect-coordinator.test.ts +371 -0
- package/src/execution/__tests__/collect-mixed-dispatch.test.ts +262 -0
- package/src/execution/__tests__/config-collect-sync.test.ts +120 -0
- package/src/execution/__tests__/config.test.ts +1 -1
- package/src/execution/__tests__/delivery-methods.test.ts +75 -62
- package/src/execution/__tests__/descendant-sweep-guards.test.ts +220 -0
- package/src/execution/__tests__/descendant-sweep.test.ts +6 -6
- package/src/execution/__tests__/dialog-queue.test.ts +2 -2
- package/src/execution/__tests__/engine-model-validation.test.ts +741 -0
- package/src/execution/__tests__/epipe-fallback.test.ts +29 -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 +5 -5
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +4 -4
- package/src/execution/__tests__/finalize-record.test.ts +173 -17
- package/src/execution/__tests__/finalized-marker.test.ts +1 -1
- package/src/execution/__tests__/gc-timer.test.ts +56 -3
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +12 -12
- package/src/execution/__tests__/get-state-handshake.test.ts +1 -1
- 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 +50 -148
- package/src/execution/__tests__/kill-all-escalation.test.ts +2 -2
- 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 +1 -1
- package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +1 -1
- 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-batch.test.ts +500 -0
- package/src/execution/__tests__/notify-ledger.test.ts +1000 -18
- package/src/execution/__tests__/output-collector.test.ts +117 -6
- package/src/execution/__tests__/pi-invocation.test.ts +36 -4
- package/src/execution/__tests__/record-entry-collect.test.ts +102 -0
- package/src/execution/__tests__/record-store.test.ts +10 -9
- 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__/relay-env.test.ts +12 -1
- 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 +15 -9
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +4 -4
- package/src/execution/__tests__/run-spawn-edges.test.ts +17 -15
- package/src/execution/__tests__/run-spawn-integration.test.ts +2 -2
- 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 +4 -4
- package/src/execution/__tests__/service-kill-escalation.test.ts +7 -5
- package/src/execution/__tests__/session-context-resolver.test.ts +0 -2
- package/src/execution/__tests__/session-file-gc.test.ts +36 -1
- package/src/execution/__tests__/session-pending.test.ts +257 -14
- package/src/execution/__tests__/session-reconstructor.test.ts +366 -15
- package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +1 -1
- package/src/execution/__tests__/session-runner-close-prune.test.ts +2 -2
- package/src/execution/__tests__/session-runner-dispatch.test.ts +489 -0
- package/src/execution/__tests__/session-runner-epipe.test.ts +3 -3
- package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +5 -4
- 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 +282 -47
- 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 +3 -3
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +5 -4
- package/src/execution/__tests__/spawned-children.test.ts +2 -1
- package/src/execution/__tests__/start-collect-guard.test.ts +255 -0
- package/src/execution/__tests__/start-sync-model-guard.test.ts +5 -5
- 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 +48 -22
- package/src/execution/__tests__/subagent-service-message-close.test.ts +29 -26
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +21 -8
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +27 -22
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +30 -29
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +45 -20
- 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__/sync-collect-recovery.test.ts +1117 -0
- package/src/execution/__tests__/temp-prompt.test.ts +1 -1
- package/src/execution/__tests__/timeout-integration.test.ts +6 -5
- package/src/execution/__tests__/tombstone-store.test.ts +1 -1
- 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 +12 -6
- package/src/execution/__tests__/ui-request-handler.test.ts +4 -3
- package/src/execution/__tests__/ui-request-queue.test.ts +142 -2
- package/src/execution/__tests__/worktree-git-ops.test.ts +1 -1
- 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 +2 -2
- package/src/execution/__tests__/worktree-reconcile.integration.test.ts +1 -1
- package/src/execution/__tests__/worktree-registry.test.ts +1 -1
- package/src/execution/agent-registry.ts +74 -30
- package/src/execution/agent-result-mapper.ts +3 -0
- package/src/execution/cold-resurrect.ts +199 -0
- package/src/execution/collect-coordinator.ts +200 -0
- package/src/execution/config.ts +77 -5
- 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/event-journal.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 +213 -53
- 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 +22 -112
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +15 -28
- package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +1 -1
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +12 -12
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +2 -2
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +21 -82
- package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +4 -7
- 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 +4 -2
- 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/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} +1 -1
- 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/{session-runner.ts → engine/engines/pi/session-runner.ts} +617 -412
- 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 +54 -27
- package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +321 -0
- package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +13 -12
- 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 +20 -8
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +77 -110
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +26 -320
- 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 +48 -148
- package/src/execution/engine/engines/zcode/appserver-launcher.ts +167 -0
- package/src/execution/engine/engines/zcode/connection.ts +24 -11
- package/src/execution/engine/engines/zcode/constants.ts +75 -71
- package/src/execution/engine/engines/zcode/golden-sample.ts +8 -46
- package/src/execution/engine/engines/zcode/parser.ts +12 -346
- package/src/execution/engine/engines/zcode/preparer.ts +12 -143
- package/src/execution/engine/engines/zcode/session-channel.ts +351 -39
- package/src/execution/engine/engines/zcode/zcode-engine.ts +665 -760
- 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 +24 -6
- package/src/execution/engine/routing.ts +75 -1
- package/src/execution/engine/types.ts +30 -103
- package/src/execution/execution-record.ts +229 -144
- package/src/execution/finalize-record.ts +141 -99
- package/src/execution/idle-gc.ts +28 -0
- package/src/execution/lifecycle-predicates.ts +1 -1
- package/src/execution/notifier.ts +234 -25
- package/src/execution/notify-host.ts +232 -0
- package/src/execution/record-entry.ts +16 -0
- package/src/execution/record-store.ts +280 -103
- package/src/execution/round-settlement.ts +93 -0
- package/src/execution/session-file-gc.ts +96 -62
- package/src/execution/session-reconstructor.ts +256 -143
- package/src/execution/sessions-index.ts +117 -47
- package/src/execution/settled-watchdog.ts +264 -52
- package/src/execution/subagent-actions-core.ts +84 -28
- package/src/execution/subagent-service.ts +1225 -964
- package/src/execution/subprocess-agent-runner.ts +144 -97
- package/src/execution/sync-rebuild.ts +87 -0
- package/src/execution/types.ts +72 -0
- package/src/execution/ui-request-handler-factory.ts +102 -74
- package/src/execution/ui-request-queue.ts +50 -19
- package/src/index.ts +442 -316
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +1 -1
- package/src/orchestration/__tests__/agent-call-stream.test.ts +2 -2
- package/src/orchestration/__tests__/args-validator.test.ts +14 -0
- package/src/orchestration/__tests__/config-loader.test.ts +1 -1
- package/src/orchestration/__tests__/error-recovery-rebuild-failure.test.ts +1 -1
- package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +11 -9
- package/src/orchestration/__tests__/execute-agent-call.test.ts +151 -11
- package/src/orchestration/__tests__/file-run-store-prune.test.ts +1 -1
- package/src/orchestration/__tests__/file-run-store-throttle.test.ts +1 -1
- package/src/orchestration/__tests__/file-run-store.test.ts +7 -6
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +2 -2
- package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +1 -1
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +3 -3
- package/src/orchestration/__tests__/lifecycle.test.ts +7 -5
- package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +1 -1
- package/src/orchestration/__tests__/review-fix-loop-scriptpath-failfast.test.ts +1 -1
- package/src/orchestration/__tests__/run-snapshot.test.ts +8 -5
- package/src/orchestration/__tests__/script-generate.test.ts +5 -5
- package/src/orchestration/__tests__/script-lint.test.ts +17 -0
- package/src/orchestration/__tests__/skill-discovery.test.ts +2 -2
- 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} +27 -19
- 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 +1 -1
- package/src/orchestration/__tests__/worker-script-builder.test.ts +1 -1
- package/src/orchestration/__tests__/workflow-files.test.ts +10 -10
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +1 -1
- package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +1 -1
- package/src/orchestration/agent-opts-resolver.ts +1 -1
- package/src/orchestration/args-validator.ts +53 -31
- package/src/orchestration/execute-agent-call.ts +19 -73
- package/src/orchestration/launcher.ts +128 -81
- package/src/orchestration/lifecycle.ts +43 -45
- package/src/orchestration/models/ports.ts +4 -4
- package/src/orchestration/models/run-runtime.ts +2 -2
- package/src/orchestration/models/trace.ts +1 -1
- package/src/orchestration/models/types.ts +111 -22
- package/src/orchestration/models/workflow-run.ts +1 -1
- package/src/orchestration/script-lint.ts +91 -58
- package/src/orchestration/{error-recovery.ts → worker-message-pump.ts} +157 -150
- package/src/shared/__tests__/atomic-write.test.ts +1 -1
- package/src/shared/__tests__/meta-parser.test.ts +151 -0
- package/src/shared/__tests__/resource-discovery-host-roots.test.ts +5 -5
- package/src/shared/__tests__/resource-discovery.test.ts +258 -215
- package/src/shared/atomic-write.ts +12 -9
- package/src/shared/meta-parser.ts +158 -84
- package/src/shared/model-ref.ts +15 -2
- package/src/shared/resource-discovery.ts +9 -183
- package/src/shared/schema-jsonify.ts +1 -1
- package/workflows/review-fix-loop-utils.cjs +151 -89
- package/workflows/review-fix-loop-utils.d.cts +287 -0
- 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__/preparer-appserver.test.ts +0 -387
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -710
- package/src/execution/engine/engines/zcode/appserver-home.ts +0 -442
- package/src/execution/engine/engines/zcode/appserver-probe.ts +0 -141
- package/src/execution/engine/engines/zcode/launcher.ts +0 -161
- package/src/execution/execute-options-mapper.ts +0 -115
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -288
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// src/execution/engine/engines/zcode/appserver-launcher.ts
|
|
2
|
+
//
|
|
3
|
+
// app-server 启动 wrapper(2026-09 共享宿主 HOME 形态的凭据供数机制)。
|
|
4
|
+
//
|
|
5
|
+
// 为什么需要:CLI 形态的 zcode app-server 只从 `$HOME/.zcode/cli/config.json` 的
|
|
6
|
+
// provider 字段读凭据(bundle 实测:路径硬编码,userConfigPath/modelConfig 参数仅对
|
|
7
|
+
// GUI 同代码库内嵌调用方开放,env/argv/协议面无配置注入通道);而 GUI 把凭据放
|
|
8
|
+
// `~/.zcode/v2/config.json` 且从不写 cli/config.json——外部 spawn 的 app-server 在
|
|
9
|
+
// 真实 HOME 下是「无源之水」(实测报 "Model provider ... is missing baseURL")。
|
|
10
|
+
//
|
|
11
|
+
// 解法(fs 拦截 wrapper,用户拍板「包一层」):spawn 的不是 zcode.cjs 而是本模块
|
|
12
|
+
// 落盘的 launcher 脚本——它 patch fs.readFileSync/fsPromises.readFile/existsSync
|
|
13
|
+
// (真实 bundle 的用户 config 读取是 existsSync 短路在前:文件不存在直接返回空
|
|
14
|
+
// config,readFileSync 不被调用——GUI-only 登录宿主上不拦 existsSync = 注入整体
|
|
15
|
+
// 不可见),把对 cli/config.json 精确路径的读取重定向为「真实文件 + v2 provider
|
|
16
|
+
// 注入」的内存合并结果(同 id 时 v2 整条优先——v2 是权威凭据源,等价复刻 GUI
|
|
17
|
+
// 直传 modelConfig),再以原 argv 启动 zcode.cjs。HOME 保持真实值(共享语义
|
|
18
|
+
// 不变:db/plugins/MCP 全继承宿主 HOME)。
|
|
19
|
+
//
|
|
20
|
+
// 漂移面如实登记:zcode 升级若改变配置读取路径/方式,失败信号 = missing baseURL /
|
|
21
|
+
// Model config is missing 明确报错(不静默坏)——与协议漂移直接报错的既有姿态同级。
|
|
22
|
+
//
|
|
23
|
+
// 源码以内嵌字符串形态进 dist bundle(vendored 面只拷 dist/,独立 .cjs 资产会被
|
|
24
|
+
// vendor 脚本漏掉——字符串常量无此问题),运行时幂等落盘 engineDataDir。
|
|
25
|
+
|
|
26
|
+
import * as fs from "node:fs";
|
|
27
|
+
import * as path from "node:path";
|
|
28
|
+
import { toErrorMessage } from "../../../../core/error-message.ts";
|
|
29
|
+
|
|
30
|
+
/** wrapper 落盘文件名(engineDataDir/engines/zcode/ 下)。 */
|
|
31
|
+
export const ZCODE_APPSERVER_LAUNCHER_NAME = "appserver-launcher.cjs";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* wrapper 源码(CJS;内容即版本——修改须同步本常量,落盘端按内容幂等覆盖)。
|
|
35
|
+
* env 契约:ZCODE_ENG_CLI_PATH(zcode.cjs 绝对路径,必填)、
|
|
36
|
+
* ZCODE_ENG_V2_CONFIG(v2 config 路径,缺省 ~/.zcode/v2/config.json)。
|
|
37
|
+
*/
|
|
38
|
+
export const APPSERVER_LAUNCHER_SOURCE = `'use strict';
|
|
39
|
+
// zcode app-server fs 拦截 wrapper(由 subagent-core appserver-launcher 落盘生成)
|
|
40
|
+
const fs = require('node:fs');
|
|
41
|
+
const path = require('node:path');
|
|
42
|
+
const os = require('node:os');
|
|
43
|
+
|
|
44
|
+
const CLI_PATH = process.env.ZCODE_ENG_CLI_PATH;
|
|
45
|
+
const V2_PATH = process.env.ZCODE_ENG_V2_CONFIG || path.join(os.homedir(), '.zcode', 'v2', 'config.json');
|
|
46
|
+
const CONFIG_PATH = path.join(os.homedir(), '.zcode', 'cli', 'config.json');
|
|
47
|
+
// 与 constants.ts ZCODE_FALLBACK_DEFAULT_MODEL 双源(内嵌字符串无法 import)——改那边须同步此处
|
|
48
|
+
const FALLBACK_MODEL_MAIN = 'builtin:bigmodel-coding-plan/GLM-5.3';
|
|
49
|
+
|
|
50
|
+
// 合并形态:真实 cli config 原样(model/plugins/mcp/subagents 等 worker 继承面不变)
|
|
51
|
+
// + v2 的 provider 字典注入,同 id 时 v2 条目整条优先——GUI 直传 modelConfig 时
|
|
52
|
+
// v2 即权威源(进程外等价复刻);cli config 不在 GUI 管理面、可能残留历史验证
|
|
53
|
+
// 配置(2026-08-25 事故:残留旧 key 压过新凭据致 turn 0 401),故不取 real 优先。
|
|
54
|
+
// 返回 null = 无可注入凭据(v2 无 provider 条目)——不 patch,让原生报错透出。
|
|
55
|
+
// 读源经 readOrig 间接取:patch 前首调 = fs.readFileSync 本体;patch 后 = 原函数
|
|
56
|
+
// (防 patch 后的递归自调用)。
|
|
57
|
+
function injectedConfigText() {
|
|
58
|
+
const readOrig = fs.__origReadFileSync || fs.readFileSync;
|
|
59
|
+
let real = {};
|
|
60
|
+
try { real = JSON.parse(readOrig(CONFIG_PATH, 'utf8')); } catch { /* 无/损坏 → 空 */ }
|
|
61
|
+
let v2 = {};
|
|
62
|
+
try { v2 = JSON.parse(readOrig(V2_PATH, 'utf8')); }
|
|
63
|
+
catch (err) {
|
|
64
|
+
// ENOENT = 桌面端未登录(正常 no-patch,静默);其他失败(JSON 损坏/权限)
|
|
65
|
+
// 出声——否则排障会被原生「请登录」报错误导,与真因(文件损坏)不符
|
|
66
|
+
if (!err || err.code !== 'ENOENT') {
|
|
67
|
+
process.stderr.write('[zcode-launcher] v2 config 读取失败(' + ((err && err.code) || (err && err.message) || 'unknown') + '): ' + V2_PATH + '——凭据注入未生效\\n');
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const v2Providers = v2.provider && typeof v2.provider === 'object' ? v2.provider : {};
|
|
72
|
+
const hasKey = (entry) => entry && typeof entry === 'object'
|
|
73
|
+
&& entry.options && typeof entry.options.apiKey === 'string' && entry.options.apiKey !== '';
|
|
74
|
+
const injectable = {};
|
|
75
|
+
for (const [id, entry] of Object.entries(v2Providers)) {
|
|
76
|
+
if (hasKey(entry)) injectable[id] = entry;
|
|
77
|
+
}
|
|
78
|
+
if (Object.keys(injectable).length === 0) return null;
|
|
79
|
+
const merged = { ...real };
|
|
80
|
+
merged.provider = { ...(real.provider && typeof real.provider === 'object' ? real.provider : {}), ...injectable };
|
|
81
|
+
if (!merged.model || typeof merged.model !== 'object' || !merged.model.main) {
|
|
82
|
+
const main = (v2.model && v2.model.main) || FALLBACK_MODEL_MAIN;
|
|
83
|
+
merged.model = { ...(merged.model || {}), main };
|
|
84
|
+
}
|
|
85
|
+
return JSON.stringify(merged);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!CLI_PATH) {
|
|
89
|
+
process.stderr.write('[zcode-launcher] ZCODE_ENG_CLI_PATH 未设置,无法启动 app-server(该 env 由引擎自动设置;手工运行 wrapper 需显式传入)\\n');
|
|
90
|
+
process.exit(2);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const text = injectedConfigText();
|
|
94
|
+
if (text !== null) {
|
|
95
|
+
// encoding 归一(Node 别名面):'utf8'/'utf-8'/大小写变体统一按 string 返回——
|
|
96
|
+
// 真实 bundle 的 config 读取恰用 'utf-8' 形态,仅匹配 'utf8' 会错回 Buffer
|
|
97
|
+
// (当下游不只 JSON.parse 而做字符串运算时即 TypeError)
|
|
98
|
+
const shape = (args, value) => {
|
|
99
|
+
const enc = args[0];
|
|
100
|
+
const e = typeof enc === 'string' ? enc
|
|
101
|
+
: (enc && typeof enc === 'object' && typeof enc.encoding === 'string' ? enc.encoding : undefined);
|
|
102
|
+
if (e !== undefined && String(e).toLowerCase().replace(/-/g, '') === 'utf8') return value;
|
|
103
|
+
return Buffer.from(value);
|
|
104
|
+
};
|
|
105
|
+
fs.__origReadFileSync = fs.readFileSync;
|
|
106
|
+
fs.readFileSync = function (p, ...rest) {
|
|
107
|
+
if (typeof p === 'string' && p === CONFIG_PATH) {
|
|
108
|
+
const cur = injectedConfigText();
|
|
109
|
+
if (cur !== null) return shape(rest, cur);
|
|
110
|
+
}
|
|
111
|
+
return fs.__origReadFileSync.call(fs, p, ...rest);
|
|
112
|
+
};
|
|
113
|
+
fs.promises.__origReadFile = fs.promises.readFile;
|
|
114
|
+
fs.promises.readFile = function (p, ...rest) {
|
|
115
|
+
if (typeof p === 'string' && p === CONFIG_PATH) {
|
|
116
|
+
const cur = injectedConfigText();
|
|
117
|
+
if (cur !== null) return Promise.resolve(shape(rest, cur));
|
|
118
|
+
}
|
|
119
|
+
return fs.promises.__origReadFile.call(fs.promises, p, ...rest);
|
|
120
|
+
};
|
|
121
|
+
// existsSync 拦截:真实 bundle 的用户 config 读取(loadFileConfig)以 existsSync
|
|
122
|
+
// 为短路门——文件不存在时返回空 config 且 readFileSync 不被调用,GUI-only
|
|
123
|
+
// 登录宿主(cli/config.json 从未被 CLI 侧写过)上注入只挂在读取面 = 不可见
|
|
124
|
+
fs.__origExistsSync = fs.existsSync;
|
|
125
|
+
fs.existsSync = function (p) {
|
|
126
|
+
if (typeof p === 'string' && p === CONFIG_PATH) {
|
|
127
|
+
const cur = injectedConfigText();
|
|
128
|
+
if (cur !== null) return true;
|
|
129
|
+
}
|
|
130
|
+
return fs.__origExistsSync.call(fs, p);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 以原 argv 形态启动 zcode.cjs(argv[0]=node, argv[1]=本 wrapper,argv[2]=app-server——
|
|
135
|
+
// zcode.cjs 的 includes('app-server') 判定不受影响)。import() 兼容 CJS/ESM 入口。
|
|
136
|
+
import(CLI_PATH).catch((err) => {
|
|
137
|
+
process.stderr.write('[zcode-launcher] zcode.cjs 加载失败: ' + (err && err.message || err) + '\\n');
|
|
138
|
+
process.exit(3);
|
|
139
|
+
});
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 幂等落盘 launcher 脚本并返回其绝对路径(内容未变跳过写——mtime 免重写)。
|
|
144
|
+
* @param engineDataDir 引擎数据根(launcher 落 engineDataDir/engines/zcode/)
|
|
145
|
+
*/
|
|
146
|
+
export function ensureAppServerLauncher(engineDataDir: string): string {
|
|
147
|
+
const dir = path.join(engineDataDir, "engines", "zcode");
|
|
148
|
+
const file = path.join(dir, ZCODE_APPSERVER_LAUNCHER_NAME);
|
|
149
|
+
const existing = fs.existsSync(file) && fs.statSync(file).isFile()
|
|
150
|
+
? fs.readFileSync(file, "utf8")
|
|
151
|
+
: undefined;
|
|
152
|
+
if (existing === APPSERVER_LAUNCHER_SOURCE) return file;
|
|
153
|
+
try {
|
|
154
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
155
|
+
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
156
|
+
fs.writeFileSync(tmp, APPSERVER_LAUNCHER_SOURCE);
|
|
157
|
+
fs.renameSync(tmp, file);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
// 裸 errno(EACCES/ENOSPC)不含恢复动作——与 probe 失败的错误姿态对齐
|
|
160
|
+
const reason = toErrorMessage(err);
|
|
161
|
+
throw new Error(
|
|
162
|
+
`zcode app-server launcher 落盘失败: ${file}(${reason})。恢复:检查引擎数据目录` +
|
|
163
|
+
` 写权限与磁盘空间(engineDataDir 由宿主传入,路径见上)后重试。`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return file;
|
|
167
|
+
}
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
ZCODE_APPSERVER_STDERR_TAIL_CHARS,
|
|
48
48
|
ZCODE_KILL_GRACE_MS,
|
|
49
49
|
} from "./constants.ts";
|
|
50
|
+
import { toErrorMessage } from "../../../../core/error-message.ts";
|
|
50
51
|
|
|
51
52
|
const logger = getLogger("subagents");
|
|
52
53
|
|
|
@@ -108,7 +109,7 @@ function frameIdOf(frame: Record<string, unknown>): string | number | undefined
|
|
|
108
109
|
|
|
109
110
|
/** 错误/日志出声用的 message 提取(非 Error 值不抛二次异常)。 */
|
|
110
111
|
function errMessage(err: unknown): string {
|
|
111
|
-
return
|
|
112
|
+
return toErrorMessage(err);
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
// ============================================================
|
|
@@ -117,16 +118,18 @@ function errMessage(err: unknown): string {
|
|
|
117
118
|
|
|
118
119
|
/**
|
|
119
120
|
* 组装 app-server 子进程 env:嵌套防护经公共 nesting-guard(注入统一
|
|
120
|
-
* XYZ_AGENT_SUBAGENT=1 +
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
121
|
+
* XYZ_AGENT_SUBAGENT=1 + 剥离引擎原生嵌套标记),遥测关闭(旧实现实证)。
|
|
122
|
+
* 2026-09 起共享宿主 HOME——不再覆写 HOME:db/plugins/MCP 继承宿主 ~/.zcode/
|
|
123
|
+
* (引擎会话与 GUI 共写同一 SQLite,WAL 并发安全),HOME 依赖副作用(如 pnpm
|
|
124
|
+
* store 路径翻转)随之消失。凭据不在此层注入:CLI 形态 app-server 只从
|
|
125
|
+
* ~/.zcode/cli/config.json 读 provider(GUI 登录态在 v2/config.json),由
|
|
126
|
+
* launcherScript 指向的 fs 拦截 wrapper 把该读取重定向为「真实文件 + v2
|
|
127
|
+
* provider 注入」内存合并(同 id 时 v2 整条优先——见 appserver-launcher.ts)。
|
|
124
128
|
*/
|
|
125
|
-
export function buildAppServerEnv(
|
|
129
|
+
export function buildAppServerEnv(baseEnv: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
126
130
|
return {
|
|
127
131
|
...buildNestedSpawnEnv(baseEnv),
|
|
128
132
|
ZCODE_MODEL_TELEMETRY_ENABLED: "false",
|
|
129
|
-
HOME: homeDir,
|
|
130
133
|
};
|
|
131
134
|
}
|
|
132
135
|
|
|
@@ -142,6 +145,12 @@ export interface AppServerConnectionOptions {
|
|
|
142
145
|
cwd: string;
|
|
143
146
|
/** 完整子进程 env(buildAppServerEnv 产物或调用方自行组装)。 */
|
|
144
147
|
env: NodeJS.ProcessEnv;
|
|
148
|
+
/**
|
|
149
|
+
* fs 拦截 wrapper 脚本路径(appserver-launcher.ts 落盘产物)。设置时 spawn 的
|
|
150
|
+
* script 换为本路径(cliPath 经 env ZCODE_ENG_CLI_PATH 传给 wrapper)——共享宿主
|
|
151
|
+
* HOME 形态的凭据供数机制;缺省 undefined = 直接 spawn cliPath(测试 fake 直连)。
|
|
152
|
+
*/
|
|
153
|
+
launcherScript?: string;
|
|
145
154
|
/**
|
|
146
155
|
* stderr tee 落盘路径(append;引擎数据目录由 R4 注入,测试用 tmp 目录)。
|
|
147
156
|
* 懒打开:首条 stderr 才建文件,无 stderr 的短命连接零文件;写失败静默降级
|
|
@@ -155,9 +164,10 @@ export interface AppServerConnectionOptions {
|
|
|
155
164
|
/** 反向请求 handler 表(缺省 D9 常量表;测试注入故障 handler 用)。 */
|
|
156
165
|
reverseHandlers?: Readonly<Record<string, (params: unknown) => unknown>>;
|
|
157
166
|
/**
|
|
158
|
-
* [R4] 每代进程 spawn
|
|
159
|
-
*
|
|
160
|
-
*
|
|
167
|
+
* [R4] 每代进程 spawn 成功后的同步回调。pidfile 机制删除后引擎侧不再传——现为
|
|
168
|
+
* 测试专有的代级观测面(采集 spawn 时序 / 子进程句柄)。与 RunContext.onChildSpawned
|
|
169
|
+
* 无关:常驻进程不进宿主 spawnedChildren(D6——其生命周期归引擎 dispose)。
|
|
170
|
+
* 不抛保证:回调异常吞掉记 warn,不影响帧泵。
|
|
161
171
|
*/
|
|
162
172
|
onSpawned?: (child: ChildProcess) => void;
|
|
163
173
|
}
|
|
@@ -192,6 +202,7 @@ export class AppServerConnection {
|
|
|
192
202
|
private readonly requestTimeoutMs: number;
|
|
193
203
|
private readonly reverseHandlers: Readonly<Record<string, (params: unknown) => unknown>>;
|
|
194
204
|
private readonly onSpawned: ((child: ChildProcess) => void) | undefined;
|
|
205
|
+
private readonly launcherScript: string | undefined;
|
|
195
206
|
|
|
196
207
|
/** 当前代子进程;null = 无活进程(未启动或已死,下次使用重建)。 */
|
|
197
208
|
private child: ChildProcess | null = null;
|
|
@@ -217,6 +228,7 @@ export class AppServerConnection {
|
|
|
217
228
|
|
|
218
229
|
constructor(opts: AppServerConnectionOptions) {
|
|
219
230
|
this.cliPath = opts.cliPath;
|
|
231
|
+
this.launcherScript = opts.launcherScript;
|
|
220
232
|
this.cwd = opts.cwd;
|
|
221
233
|
this.env = opts.env;
|
|
222
234
|
this.stderrLogPath = opts.stderrLogPath;
|
|
@@ -363,7 +375,8 @@ export class AppServerConnection {
|
|
|
363
375
|
this.generation += 1;
|
|
364
376
|
const gen = this.generation;
|
|
365
377
|
|
|
366
|
-
const
|
|
378
|
+
const script = this.launcherScript ?? this.cliPath;
|
|
379
|
+
const child = spawn(this.nodeBin, [script, "app-server", "--cwd", this.cwd], {
|
|
367
380
|
env: this.env,
|
|
368
381
|
stdio: ["pipe", "pipe", "pipe"],
|
|
369
382
|
});
|
|
@@ -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,23 +22,26 @@ 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;
|
|
@@ -44,7 +51,7 @@ export const ZCODE_ERROR_TAIL_CHARS = 2000;
|
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
* [R2] app-server 控制面请求默认超时(ms)。依据:旧 zsw 实现 REQUEST_TIMEOUT_MS=15s
|
|
47
|
-
* (60+ fake-server 用例 + 真机 e2e
|
|
54
|
+
* (60+ fake-server 用例 + 真机 e2e 验证值)。
|
|
48
55
|
*/
|
|
49
56
|
export const ZCODE_APPSERVER_REQUEST_TIMEOUT_MS = 15_000;
|
|
50
57
|
|
|
@@ -72,35 +79,70 @@ export const ZCODE_APPSERVER_TURN_READ_TIMEOUT_MS = 5_000;
|
|
|
72
79
|
export const ZCODE_APPSERVER_TURN_CLOSE_TIMEOUT_MS = 1_500;
|
|
73
80
|
|
|
74
81
|
/**
|
|
75
|
-
* [R3
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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 等)以本名记录事故成因,删除即产生悬空引用。
|
|
78
88
|
*/
|
|
79
89
|
export const ZCODE_APPSERVER_TURN_DEFAULT_TIMEOUT_MS = 300_000;
|
|
80
90
|
|
|
81
91
|
// ============================================================
|
|
82
|
-
// [
|
|
92
|
+
// [P0-1 U1] turn 等待两 timer(idle 主判定 + 总上界回收兜底)
|
|
93
|
+
// 设计权威源:docs/design/timeout-zcode-turn-and-settled-watchdog.md §6 D1/D2
|
|
83
94
|
// ============================================================
|
|
84
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
|
+
|
|
85
102
|
/**
|
|
86
|
-
* [
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* `home-appserver-2`… 后缀目录,handle.poolKey 记实际目录名。
|
|
103
|
+
* [P0-1 D1] turn idle 主判定缺省阈值(ms):该 turn 任何事件到达刷新计时,连续
|
|
104
|
+
* 静默达此值判「执行已不可推进」。活跃事件流零误杀(ADR-0047 逆否面)。默认
|
|
105
|
+
* 30min 为先验值,⛔P-Z1 门(事件流 inter-event gap 分布)标定前用此默认。
|
|
90
106
|
*/
|
|
91
|
-
export const
|
|
107
|
+
export const ZCODE_TURN_IDLE_TIMEOUT_MS = 1_800_000;
|
|
92
108
|
|
|
93
|
-
/**
|
|
94
|
-
|
|
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;
|
|
95
117
|
|
|
96
|
-
/**
|
|
97
|
-
export
|
|
118
|
+
/** `parseZcodeTurnTimeoutEnv` 的解析结果(可判别联合——valid 分支 ms 必有)。 */
|
|
119
|
+
export type ZcodeTurnTimeoutEnvParse =
|
|
120
|
+
| { state: "unset" }
|
|
121
|
+
| { state: "valid"; ms: number }
|
|
122
|
+
| { state: "invalid" };
|
|
98
123
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
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
|
+
}
|
|
101
139
|
|
|
102
|
-
/**
|
|
103
|
-
|
|
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";
|
|
104
146
|
|
|
105
147
|
/**
|
|
106
148
|
* [R4 D3] abort 链第一级:session/stop 的控制面超时(ms)。stop 失败/超时即落
|
|
@@ -114,59 +156,21 @@ export const ZCODE_APPSERVER_STOP_TIMEOUT_MS = 3_000;
|
|
|
114
156
|
*/
|
|
115
157
|
export const ZCODE_APPSERVER_ABORT_GRACE_MS = 3_000;
|
|
116
158
|
|
|
117
|
-
/** [R4 D6③] 孤儿回收的 SIGTERM→SIGKILL grace 窗口(ms)。 */
|
|
118
|
-
export const ZCODE_APPSERVER_PIDFILE_GRACE_MS = 2_000;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* [R4/R5] 执行模式定向 env(appserver | spawn)。定向时不探不降;缺省走 app-server
|
|
122
|
-
* (R5 降级链在缺省路径插 probe 门控)。spawn 降级路径(D2 兜底)继续用
|
|
123
|
-
* home-<provider>-<model> 池。
|
|
124
|
-
*/
|
|
125
|
-
export const ZCODE_MODE_ENV_VAR = "XYZ_ZCODE_MODE";
|
|
126
|
-
|
|
127
159
|
/**
|
|
128
160
|
* [R4] app-server 内部错误码中「模型配置缺失」的归类判据(A.3:-32603 内部错误族,
|
|
129
161
|
* 消息含 "Model config is missing"——错误规格表第 2 行:报 engine_credential_missing)。
|
|
130
162
|
*/
|
|
131
163
|
export const ZCODE_APPSERVER_ERR_MODEL_CONFIG_MISSING = -32603;
|
|
132
164
|
|
|
133
|
-
// ============================================================
|
|
134
|
-
// [R5] 降级链(D2)/ probe 冒烟(D8)
|
|
135
|
-
// ============================================================
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* [R5 D8] 协议冒烟探针的总预算(ms):独立短命连接上 create 探针会话 → close →
|
|
139
|
-
* shutdown 的全部时间窗。不发模型请求(无 session/send)、不产生费用。超预算按
|
|
140
|
-
* 探针失败处理(错误规格表末行:结论 failed → 降级 spawn)。
|
|
141
|
-
*/
|
|
142
|
-
export const ZCODE_APPSERVER_PROBE_BUDGET_MS = 10_000;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* [R5 D2] 漂移类 RPC 错误码(错误规格表第 1 行:-32601 方法不存在 / -32602 参数
|
|
146
|
-
* 变形)。运行中命中任一 → 归档 protocol-drift:首任务降级 spawn 重跑一次 + 后续
|
|
147
|
-
* 任务直走 spawn(降级标志内存化,进程重启后重探重建)。-32004/-32010/-32603 不在
|
|
148
|
-
* 此列(任务失败上报 / 凭据缺失归类,均不降级)。
|
|
149
|
-
*/
|
|
150
|
-
const RPC_METHOD_NOT_FOUND = -32601;
|
|
151
|
-
const RPC_INVALID_PARAMS = -32602;
|
|
152
|
-
export const ZCODE_APPSERVER_DRIFT_RPC_CODES = [RPC_METHOD_NOT_FOUND, RPC_INVALID_PARAMS] as const;
|
|
153
|
-
|
|
154
165
|
/**
|
|
155
166
|
* [R5] app-server 内部错误码「会话忙」:send 时该会话已有轮在跑(busy 不排队不打断)。
|
|
156
167
|
* 单会话一任务是结构保证,运行中命中即 bug(错误文案引导上报 sessionId 与 state 流水)。
|
|
157
168
|
*/
|
|
158
169
|
export const ZCODE_APPSERVER_ERR_BUSY_SESSION = -32010;
|
|
159
170
|
|
|
160
|
-
/**
|
|
161
|
-
* [R5 D8] 探针连接的 env 标记:探针用独立短命连接(不污染主连接),但 env 与主连接
|
|
162
|
-
* 同源(同一常驻 HOME)。此标记供 fake/诊断侧区分「探针进程」与「常驻进程」(测试
|
|
163
|
-
* 断言探针帧序、故障注入只命中探针或只命中主连接的判据)。
|
|
164
|
-
*/
|
|
165
|
-
export const ZCODE_APPSERVER_PROBE_CONN_ENV = "ZCODE_APPSERVER_PROBE_CONN";
|
|
166
|
-
|
|
167
171
|
/**
|
|
168
172
|
* [R5] 崩溃收割确认的兜底窗口(ms):killChain 在 `exit` 事件 resolve,而连接
|
|
169
173
|
* finalize(onClose → 在途 turn 崩溃收割)挂 `close` 事件——channel 退订前等 onClose
|
|
170
|
-
* 触发,本窗口兜底防 `close` 永不到达时 dispose
|
|
174
|
+
* 触发,本窗口兜底防 `close` 永不到达时 dispose 挂死。
|
|
171
175
|
*/
|
|
172
176
|
export const ZCODE_APPSERVER_HARVEST_GRACE_MS = 1_000;
|
|
@@ -1,52 +1,14 @@
|
|
|
1
1
|
// src/execution/engine/engines/zcode/golden-sample.ts
|
|
2
2
|
//
|
|
3
|
-
// golden
|
|
3
|
+
// golden 语料内嵌副本(2026-09 收缩:CLI spawn 链删除后只剩 app-server 通道语料——
|
|
4
|
+
// spawn 单 JSON 样本(ZCODE_GOLDEN_STDOUT)随 probe 干跑/spawn 回归一并删除):
|
|
4
5
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// (zcode-engine probe 干跑 + conformance spawn 回归),故 R3 帧序列语料落地为
|
|
12
|
-
// 并存新增而非删除替换——漂移防御的主力语料已切换到 ②(登记于 impl-plan 偏差表)。
|
|
13
|
-
//
|
|
14
|
-
// ② app-server NDJSON 帧序列(R3,D8-②):常驻通道的 golden 帧序列语料,四类样本
|
|
15
|
-
// (create 应答 / 推送流 / 终态帧 / read 应答,附录 A.2 任务生命周期帧序)。
|
|
16
|
-
// 来源:按 A.2 协议权威 + 旧 zsw 实现真机抓包形态合成(非实录,fixture _meta
|
|
17
|
-
// 如实标注);真机冒烟后替换。双副本 diff 机制沿用 ① 的先例:fixture
|
|
18
|
-
// __tests__/__fixtures__/zcode-golden-appserver.json 是采集 SSOT,此处为运行时
|
|
19
|
-
// 副本,更新样本需同步改两处(session-channel 测试 diff 校验;R6 conformance
|
|
20
|
-
// 迁移后由 golden 回放层接管)。
|
|
21
|
-
|
|
22
|
-
/** [①spawn] 实录 stdout 原文(单 JSON:sessionId/traceId/turnId/response/usage/eventCount/projection)。 */
|
|
23
|
-
export const ZCODE_GOLDEN_STDOUT = `{
|
|
24
|
-
"sessionId": "sess_35852a0f-1302-4e20-9e48-87f47527abe3",
|
|
25
|
-
"traceId": "9fffaebd-749e-468b-af3f-2a89e3347785",
|
|
26
|
-
"turnId": "turn_99879260-1c9b-4e97-afe1-c2e7abeaf5b9",
|
|
27
|
-
"response": "ok",
|
|
28
|
-
"usage": {
|
|
29
|
-
"source": "provider",
|
|
30
|
-
"modelRequestCount": 1,
|
|
31
|
-
"inputTokens": 12599,
|
|
32
|
-
"outputTokens": 17,
|
|
33
|
-
"totalTokens": 12616,
|
|
34
|
-
"cacheReadTokens": 512,
|
|
35
|
-
"cacheWriteTokens": 0,
|
|
36
|
-
"reasoningTokens": 0,
|
|
37
|
-
"webFetchRequests": 0,
|
|
38
|
-
"webSearchRequests": 0
|
|
39
|
-
},
|
|
40
|
-
"eventCount": 17,
|
|
41
|
-
"projection": {
|
|
42
|
-
"status": "idle",
|
|
43
|
-
"turnCount": 1,
|
|
44
|
-
"totalTokenCount": 12616,
|
|
45
|
-
"contextUsed": 12616,
|
|
46
|
-
"contextWindow": 1000000
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
`;
|
|
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 校验)。
|
|
50
12
|
|
|
51
13
|
// ============================================================
|
|
52
14
|
// [②app-server] NDJSON 帧序列语料(R3,附录 A.2 帧序逐字)
|