@zhushanwen/subagent-core 0.2.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/README.md +114 -0
- package/dist/chunk-3VOERJPJ.js +22 -0
- package/dist/chunk-A4IVZWVX.js +31 -0
- package/dist/execution/engine/engines/zcode/constants.cjs +54 -0
- package/dist/execution/engine/engines/zcode/constants.d.cts +31 -0
- package/dist/execution/engine/engines/zcode/constants.d.ts +31 -0
- package/dist/execution/engine/engines/zcode/constants.js +22 -0
- package/dist/execution/engine/engines/zcode/reader.cjs +276 -0
- package/dist/execution/engine/engines/zcode/reader.d.cts +20 -0
- package/dist/execution/engine/engines/zcode/reader.d.ts +20 -0
- package/dist/execution/engine/engines/zcode/reader.js +239 -0
- package/dist/execution/engine/paths.cjs +55 -0
- package/dist/execution/engine/paths.d.cts +8 -0
- package/dist/execution/engine/paths.d.ts +8 -0
- package/dist/execution/engine/paths.js +26 -0
- package/dist/execution/relay-env.cjs +62 -0
- package/dist/execution/relay-env.d.cts +33 -0
- package/dist/execution/relay-env.d.ts +33 -0
- package/dist/execution/relay-env.js +20 -0
- package/dist/index.cjs +1852 -0
- package/dist/index.d.cts +1184 -0
- package/dist/index.d.ts +1184 -0
- package/dist/index.js +1810 -0
- package/dist/types-BxyAidGf.d.cts +875 -0
- package/dist/types-BxyAidGf.d.ts +875 -0
- package/package.json +99 -0
- package/src/__tests__/agent-opts-resolver-schema-prompt.test.ts +142 -0
- package/src/__tests__/append-system-prompt-assembly.test.ts +242 -0
- package/src/__tests__/builtin-workflows-structure.test.ts +180 -0
- package/src/__tests__/derive-closed-display-parity.test.ts +93 -0
- package/src/__tests__/fr4-get-state-handshake.test.ts +125 -0
- package/src/__tests__/fr8-orphan-recovery.test.ts +259 -0
- package/src/__tests__/m2-append-content-probe.test.ts +73 -0
- package/src/__tests__/manifest-store.test.ts +368 -0
- package/src/__tests__/record-store-cache.test.ts +335 -0
- package/src/__tests__/record-store-index.test.ts +560 -0
- package/src/__tests__/record-store-last-line.test.ts +129 -0
- package/src/__tests__/review-fix-loop-script.test.ts +288 -0
- package/src/__tests__/review-fix-loop-utils.test.ts +2377 -0
- package/src/__tests__/robustness-low-batch1.test.ts +286 -0
- package/src/__tests__/robustness-medium-batch1.test.ts +69 -0
- package/src/__tests__/robustness-medium-batch2.test.ts +65 -0
- package/src/__tests__/robustness-medium-batch3.test.ts +30 -0
- package/src/__tests__/robustness-medium-batch4.test.ts +358 -0
- package/src/__tests__/session-runner.test.ts +69 -0
- package/src/__tests__/smoke.test.ts +9 -0
- package/src/__tests__/stream-sink.test.ts +203 -0
- package/src/core/__tests__/host-services.test.ts +144 -0
- package/src/core/__tests__/logger.test.ts +78 -0
- package/src/core/__tests__/notify-ports.test.ts +104 -0
- package/src/core/host-services.ts +97 -0
- package/src/core/logger.ts +47 -0
- package/src/core/notify-ports.ts +126 -0
- package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +53 -0
- package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +1 -0
- package/src/execution/__tests__/agent-result-mapper.test.ts +150 -0
- package/src/execution/__tests__/alive-store.test.ts +147 -0
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +490 -0
- package/src/execution/__tests__/channel-registry-handshake.test.ts +242 -0
- package/src/execution/__tests__/chat-engine-routing.test.ts +610 -0
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +190 -0
- package/src/execution/__tests__/concurrency-pool.test.ts +250 -0
- package/src/execution/__tests__/config.test.ts +302 -0
- package/src/execution/__tests__/delivery-methods.test.ts +424 -0
- package/src/execution/__tests__/dialog-queue.test.ts +299 -0
- package/src/execution/__tests__/epipe-fallback.test.ts +241 -0
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +243 -0
- package/src/execution/__tests__/execute-nesting.test.ts +323 -0
- package/src/execution/__tests__/execute-options-mapper.test.ts +200 -0
- package/src/execution/__tests__/execution-record.test.ts +1394 -0
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +171 -0
- package/src/execution/__tests__/finalize-record.test.ts +367 -0
- package/src/execution/__tests__/finalized-marker.test.ts +104 -0
- package/src/execution/__tests__/format-schema-instruction.test.ts +169 -0
- package/src/execution/__tests__/gc-timer.test.ts +184 -0
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +254 -0
- package/src/execution/__tests__/helpers/mock-extension-api.ts +30 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +242 -0
- package/src/execution/__tests__/host-mode.test.ts +87 -0
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +211 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +383 -0
- package/src/execution/__tests__/lifecycle-predicates.test.ts +116 -0
- package/src/execution/__tests__/manifest-parentid.test.ts +117 -0
- package/src/execution/__tests__/model-resolver.test.ts +465 -0
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +287 -0
- package/src/execution/__tests__/nested-visibility.test.ts +325 -0
- package/src/execution/__tests__/output-collector.test.ts +358 -0
- package/src/execution/__tests__/path-encoding.test.ts +104 -0
- package/src/execution/__tests__/pi-invocation.test.ts +134 -0
- package/src/execution/__tests__/record-store.test.ts +1057 -0
- package/src/execution/__tests__/records-cwd-isolation.test.ts +91 -0
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +339 -0
- package/src/execution/__tests__/recursive-visibility-env.test.ts +273 -0
- package/src/execution/__tests__/relay-env.test.ts +42 -0
- package/src/execution/__tests__/resource-policy.test.ts +109 -0
- package/src/execution/__tests__/rpc-mode.test.ts +89 -0
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +267 -0
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +253 -0
- package/src/execution/__tests__/run-spawn-edges.test.ts +687 -0
- package/src/execution/__tests__/run-spawn-integration.test.ts +933 -0
- package/src/execution/__tests__/run-spawn-resume.test.ts +322 -0
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +196 -0
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +199 -0
- package/src/execution/__tests__/session-context-resolver.test.ts +167 -0
- package/src/execution/__tests__/session-file-gc.test.ts +293 -0
- package/src/execution/__tests__/session-reconstructor.test.ts +379 -0
- package/src/execution/__tests__/session-runner-epipe.test.ts +178 -0
- package/src/execution/__tests__/session-runner-schema-env.test.ts +350 -0
- package/src/execution/__tests__/spawn-args.test.ts +445 -0
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +189 -0
- package/src/execution/__tests__/spawn-event-adapter.test.ts +167 -0
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +207 -0
- package/src/execution/__tests__/spawned-children.test.ts +92 -0
- package/src/execution/__tests__/start-sync-model-guard.test.ts +150 -0
- package/src/execution/__tests__/stdin-writer.test.ts +462 -0
- package/src/execution/__tests__/stream-sink-retirement.test.ts +261 -0
- package/src/execution/__tests__/subagent-service-abort.test.ts +60 -0
- package/src/execution/__tests__/subagent-service-message-close.test.ts +629 -0
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +180 -0
- package/src/execution/__tests__/subagent-service.test.ts +788 -0
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +310 -0
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +612 -0
- package/src/execution/__tests__/temp-prompt.test.ts +53 -0
- package/src/execution/__tests__/timeout-integration.test.ts +615 -0
- package/src/execution/__tests__/tombstone-store.test.ts +73 -0
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +194 -0
- package/src/execution/__tests__/turn-limiter.test.ts +65 -0
- package/src/execution/__tests__/ui-channels.test.ts +187 -0
- package/src/execution/__tests__/ui-interaction-model.test.ts +67 -0
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +369 -0
- package/src/execution/__tests__/ui-request-handler.test.ts +204 -0
- package/src/execution/__tests__/ui-request-observability.test.ts +113 -0
- package/src/execution/__tests__/ui-request-queue.test.ts +133 -0
- package/src/execution/__tests__/worktree-manager.test.ts +633 -0
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +229 -0
- package/src/execution/__tests__/worktree-reconcile.integration.test.ts +181 -0
- package/src/execution/__tests__/worktree-registry.test.ts +199 -0
- package/src/execution/agent-registry.ts +199 -0
- package/src/execution/agent-result-mapper.ts +90 -0
- package/src/execution/alive-store.ts +119 -0
- package/src/execution/argv-mirror.ts +113 -0
- package/src/execution/best-effort.ts +38 -0
- package/src/execution/channel-registry-access.ts +144 -0
- package/src/execution/concurrency-pool.ts +116 -0
- package/src/execution/config.ts +165 -0
- package/src/execution/dialog-queue.ts +330 -0
- package/src/execution/engine/__tests__/common/data-dir.test.ts +78 -0
- package/src/execution/engine/__tests__/common/errors.test.ts +132 -0
- package/src/execution/engine/__tests__/common/event-journal.test.ts +177 -0
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +192 -0
- package/src/execution/engine/__tests__/common/nesting-guard.test.ts +81 -0
- package/src/execution/engine/__tests__/common/persona-router.test.ts +123 -0
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +154 -0
- package/src/execution/engine/__tests__/common/schema-emulation.test.ts +128 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +28 -0
- package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +141 -0
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +109 -0
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +101 -0
- package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +77 -0
- package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +104 -0
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +201 -0
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +76 -0
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +79 -0
- package/src/execution/engine/__tests__/engine-discovery.test.ts +87 -0
- package/src/execution/engine/__tests__/model-prompt.test.ts +197 -0
- package/src/execution/engine/__tests__/paths.test.ts +39 -0
- package/src/execution/engine/__tests__/registry.test.ts +120 -0
- package/src/execution/engine/__tests__/routing.test.ts +231 -0
- package/src/execution/engine/common/data-dir.ts +66 -0
- package/src/execution/engine/common/errors.ts +183 -0
- package/src/execution/engine/common/event-journal.ts +254 -0
- package/src/execution/engine/common/journal-replay.ts +62 -0
- package/src/execution/engine/common/kill-chain.ts +221 -0
- package/src/execution/engine/common/nesting-guard.ts +50 -0
- package/src/execution/engine/common/persona-router.ts +108 -0
- package/src/execution/engine/common/pool-manager.ts +226 -0
- package/src/execution/engine/common/schema-emulation.ts +189 -0
- package/src/execution/engine/common/session-view-projection.ts +51 -0
- package/src/execution/engine/engine-discovery.ts +65 -0
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +469 -0
- package/src/execution/engine/engines/pi/__tests__/reader.test.ts +155 -0
- package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +164 -0
- package/src/execution/engine/engines/pi/pi-engine.ts +415 -0
- package/src/execution/engine/engines/pi/reader.ts +48 -0
- package/src/execution/engine/engines/pi/registration.ts +35 -0
- package/src/execution/engine/engines/pi/task-spec-mapper.ts +100 -0
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +39 -0
- package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +150 -0
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +246 -0
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +228 -0
- package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +210 -0
- package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +71 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +127 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +580 -0
- package/src/execution/engine/engines/zcode/constants.ts +43 -0
- package/src/execution/engine/engines/zcode/golden-sample.ts +39 -0
- package/src/execution/engine/engines/zcode/launcher.ts +161 -0
- package/src/execution/engine/engines/zcode/parser.ts +436 -0
- package/src/execution/engine/engines/zcode/preparer.ts +363 -0
- package/src/execution/engine/engines/zcode/reader.ts +381 -0
- package/src/execution/engine/engines/zcode/registration.ts +37 -0
- package/src/execution/engine/engines/zcode/zcode-engine.ts +658 -0
- package/src/execution/engine/host-task-spec.ts +47 -0
- package/src/execution/engine/model-prompt.ts +158 -0
- package/src/execution/engine/paths.ts +42 -0
- package/src/execution/engine/port.ts +153 -0
- package/src/execution/engine/registry.ts +133 -0
- package/src/execution/engine/routing.ts +218 -0
- package/src/execution/engine/types.ts +309 -0
- package/src/execution/execute-options-mapper.ts +115 -0
- package/src/execution/execution-record.ts +984 -0
- package/src/execution/finalize-record.ts +254 -0
- package/src/execution/finalized-marker.ts +70 -0
- package/src/execution/get-state-handshake.ts +104 -0
- package/src/execution/host-mode.ts +56 -0
- package/src/execution/idle-gc.ts +47 -0
- package/src/execution/lifecycle-manager.ts +513 -0
- package/src/execution/lifecycle-predicates.ts +65 -0
- package/src/execution/manifest-store.ts +256 -0
- package/src/execution/model-config-service.ts +250 -0
- package/src/execution/model-resolver.ts +248 -0
- package/src/execution/notifier.ts +372 -0
- package/src/execution/notify-ledger.ts +580 -0
- package/src/execution/output-collector.ts +228 -0
- package/src/execution/path-encoding.ts +60 -0
- package/src/execution/pi-invocation.ts +120 -0
- package/src/execution/record-entry.ts +132 -0
- package/src/execution/record-store.ts +1265 -0
- package/src/execution/relay-env.ts +37 -0
- package/src/execution/session-context-resolver.ts +64 -0
- package/src/execution/session-file-gc.ts +120 -0
- package/src/execution/session-pending.ts +170 -0
- package/src/execution/session-reconstructor.ts +678 -0
- package/src/execution/session-runner.ts +1789 -0
- package/src/execution/sessions-index.ts +304 -0
- package/src/execution/spawn-event-adapter.ts +363 -0
- package/src/execution/stdin-writer.ts +198 -0
- package/src/execution/stream-sink.ts +126 -0
- package/src/execution/subagent-service.ts +2268 -0
- package/src/execution/subprocess-agent-runner.ts +317 -0
- package/src/execution/temp-prompt.ts +62 -0
- package/src/execution/tombstone-store.ts +72 -0
- package/src/execution/turn-limiter.ts +102 -0
- package/src/execution/types.ts +1023 -0
- package/src/execution/ui-channels.ts +216 -0
- package/src/execution/ui-interaction-model.ts +48 -0
- package/src/execution/ui-request-handler-factory.ts +243 -0
- package/src/execution/ui-request-observability.ts +81 -0
- package/src/execution/ui-request-queue.ts +184 -0
- package/src/execution/worktree-manager.ts +688 -0
- package/src/execution/worktree-registry.ts +279 -0
- package/src/index.ts +87 -0
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +349 -0
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +202 -0
- package/src/orchestration/__tests__/agent-call-stream.test.ts +152 -0
- package/src/orchestration/__tests__/args-validator.test.ts +143 -0
- package/src/orchestration/__tests__/config-loader.test.ts +503 -0
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +809 -0
- package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +404 -0
- package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +56 -0
- package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +166 -0
- package/src/orchestration/__tests__/execute-agent-call.test.ts +451 -0
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +600 -0
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +96 -0
- package/src/orchestration/__tests__/lifecycle.test.ts +659 -0
- package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +95 -0
- package/src/orchestration/__tests__/review-fix-loop-scriptpath-failfast.test.ts +183 -0
- package/src/orchestration/__tests__/script-lint.test.ts +831 -0
- package/src/orchestration/__tests__/skill-discovery.test.ts +210 -0
- package/src/orchestration/__tests__/test-mocks.ts +197 -0
- package/src/orchestration/__tests__/worker-exit-without-result.test.ts +368 -0
- package/src/orchestration/__tests__/worker-host.test.ts +120 -0
- package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +164 -0
- package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +563 -0
- package/src/orchestration/__tests__/worker-script-builder.test.ts +309 -0
- package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +129 -0
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +317 -0
- package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +110 -0
- package/src/orchestration/agent-opts-resolver.ts +174 -0
- package/src/orchestration/args-validator.ts +127 -0
- package/src/orchestration/config-loader.ts +316 -0
- package/src/orchestration/error-recovery.ts +1018 -0
- package/src/orchestration/execute-agent-call.ts +256 -0
- package/src/orchestration/launcher.ts +455 -0
- package/src/orchestration/lifecycle.ts +399 -0
- package/src/orchestration/models/__tests__/budget.test.ts +307 -0
- package/src/orchestration/models/agent-call.ts +83 -0
- package/src/orchestration/models/budget.ts +118 -0
- package/src/orchestration/models/ports.ts +164 -0
- package/src/orchestration/models/run-runtime.ts +104 -0
- package/src/orchestration/models/run-spec.ts +83 -0
- package/src/orchestration/models/run-state.ts +44 -0
- package/src/orchestration/models/trace.ts +183 -0
- package/src/orchestration/models/types.ts +301 -0
- package/src/orchestration/models/workflow-run.ts +254 -0
- package/src/orchestration/models/workflow-script-registry.ts +35 -0
- package/src/orchestration/models/workflow-script.ts +117 -0
- package/src/orchestration/script-lint.ts +766 -0
- package/src/orchestration/skill-discovery.ts +135 -0
- package/src/orchestration/worker-handle.ts +115 -0
- package/src/orchestration/worker-host.ts +98 -0
- package/src/orchestration/worker-script-builder.ts +421 -0
- package/src/orchestration/workflow-files.ts +85 -0
- package/src/orchestration/workflow-script-registry-impl.ts +133 -0
- package/src/shared/__tests__/agent-ref.test.ts +34 -0
- package/src/shared/__tests__/meta-parser.test.ts +304 -0
- package/src/shared/__tests__/model-ref.test.ts +306 -0
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +288 -0
- package/src/shared/__tests__/resource-discovery.test.ts +749 -0
- package/src/shared/__tests__/resource-meta.test.ts +51 -0
- package/src/shared/__tests__/schema-jsonify.test.ts +81 -0
- package/src/shared/__tests__/timer-delay.test.ts +61 -0
- package/src/shared/agent-event.ts +13 -0
- package/src/shared/agent-ref.ts +57 -0
- package/src/shared/meta-parser.ts +261 -0
- package/src/shared/model-ref.ts +286 -0
- package/src/shared/resource-discovery.ts +835 -0
- package/src/shared/resource-meta.ts +65 -0
- package/src/shared/schema-env.ts +44 -0
- package/src/shared/schema-jsonify.ts +58 -0
- package/src/shared/timer-delay.ts +54 -0
- package/src/shared/xml-injection.ts +35 -0
- package/workflows/README.md +81 -0
- package/workflows/_shared/agent-refs.cjs +40 -0
- package/workflows/chain.js +137 -0
- package/workflows/map-reduce.js +180 -0
- package/workflows/parallel.js +154 -0
- package/workflows/review-fix-loop-utils.cjs +1542 -0
- package/workflows/review-fix-loop.js +1605 -0
- package/workflows/scatter-gather.js +184 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZCODE_ENGINE_ID
|
|
3
|
+
} from "../../../../chunk-3VOERJPJ.js";
|
|
4
|
+
|
|
5
|
+
// src/execution/engine/engines/zcode/reader.ts
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
var ZcodeReaderError = class extends Error {
|
|
8
|
+
code;
|
|
9
|
+
/** 原始失败细节(缺文件/表漂移/运行时不支持)。 */
|
|
10
|
+
detail;
|
|
11
|
+
constructor(detail, hint) {
|
|
12
|
+
super(
|
|
13
|
+
`[engine_session_read_failed] zcode \u539F\u751F session \u8BFB\u53D6\u5931\u8D25\uFF1A${detail}\u3002` + (hint ?? "\u8C03\u7528\u65B9\u5E94\u964D\u7EA7\u5230\u7B2C\u2461\u7EA7\uFF08\u5BBF\u4E3B event journal\uFF09\u6216\u7B2C\u2462\u7EA7\uFF08outcome-only\uFF09\u3002")
|
|
14
|
+
);
|
|
15
|
+
this.name = "ZcodeReaderError";
|
|
16
|
+
this.code = "engine_session_read_failed";
|
|
17
|
+
this.detail = detail;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function parseJsonField(raw, ctx) {
|
|
21
|
+
try {
|
|
22
|
+
const v = JSON.parse(raw);
|
|
23
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : void 0;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
throw new ZcodeReaderError(
|
|
26
|
+
`${ctx} \u884C data \u4E0D\u662F\u5408\u6CD5 JSON\uFF08${err instanceof Error ? err.message : String(err)}\uFF09`,
|
|
27
|
+
"db \u5185\u5BB9\u635F\u574F\u6216\u7248\u672C\u4E0D\u517C\u5BB9\u2014\u2014\u8C03\u7528\u65B9\u5E94\u964D\u7EA7\u5230\u7B2C\u2461\u7EA7\uFF08\u5BBF\u4E3B event journal\uFF09\u3002"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function finiteOr(v, fallback) {
|
|
32
|
+
const n = typeof v === "number" ? v : Number(v);
|
|
33
|
+
return Number.isFinite(n) ? n : fallback;
|
|
34
|
+
}
|
|
35
|
+
function usageFromStepFinish(part) {
|
|
36
|
+
const tokens = part.tokens;
|
|
37
|
+
if (typeof tokens !== "object" || tokens === null) return void 0;
|
|
38
|
+
const t = tokens;
|
|
39
|
+
const cache = typeof t.cache === "object" && t.cache !== null ? t.cache : {};
|
|
40
|
+
if (t.input === void 0 && t.output === void 0) return void 0;
|
|
41
|
+
return {
|
|
42
|
+
input: finiteOr(t.input, 0),
|
|
43
|
+
output: finiteOr(t.output, 0),
|
|
44
|
+
cacheRead: finiteOr(cache.read, 0),
|
|
45
|
+
cacheWrite: finiteOr(cache.write, 0)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function toolFromPart(part) {
|
|
49
|
+
const toolName = typeof part.tool === "string" ? part.tool : "unknown";
|
|
50
|
+
let state;
|
|
51
|
+
if (typeof part.state === "string") {
|
|
52
|
+
try {
|
|
53
|
+
const v = JSON.parse(part.state);
|
|
54
|
+
state = typeof v === "object" && v !== null ? v : void 0;
|
|
55
|
+
} catch {
|
|
56
|
+
state = void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const status = typeof state?.status === "string" ? state.status : "unknown";
|
|
60
|
+
const output = state?.output;
|
|
61
|
+
return {
|
|
62
|
+
toolName,
|
|
63
|
+
...state?.input !== void 0 ? { args: state.input } : {},
|
|
64
|
+
// 输出形态(实测):string(内容)或 object(结构化)——分别映射到 pi ToolCallResult
|
|
65
|
+
// 的 content[] / details,不发明第二形状
|
|
66
|
+
...typeof output === "string" ? { result: { content: [output] } } : {},
|
|
67
|
+
...typeof output === "object" && output !== null ? { result: { details: output } } : {},
|
|
68
|
+
...status !== "completed" ? { isError: true } : {}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
var TotalsAcc = class {
|
|
72
|
+
input = 0;
|
|
73
|
+
output = 0;
|
|
74
|
+
cacheRead = 0;
|
|
75
|
+
cacheWrite = 0;
|
|
76
|
+
cost = 0;
|
|
77
|
+
has = false;
|
|
78
|
+
add(u) {
|
|
79
|
+
this.has = true;
|
|
80
|
+
this.input += u.input;
|
|
81
|
+
this.output += u.output;
|
|
82
|
+
this.cacheRead += u.cacheRead;
|
|
83
|
+
this.cacheWrite += u.cacheWrite;
|
|
84
|
+
this.cost += u.cost ?? 0;
|
|
85
|
+
}
|
|
86
|
+
toTotal() {
|
|
87
|
+
if (!this.has) return void 0;
|
|
88
|
+
return {
|
|
89
|
+
input: this.input,
|
|
90
|
+
output: this.output,
|
|
91
|
+
cacheRead: this.cacheRead,
|
|
92
|
+
cacheWrite: this.cacheWrite,
|
|
93
|
+
cost: this.cost,
|
|
94
|
+
total: this.input + this.output + this.cacheRead + this.cacheWrite
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function closeTurn(acc, turns, totals) {
|
|
99
|
+
if (acc === null) return;
|
|
100
|
+
turns.push({ text: acc.text, thinking: acc.thinking, toolCalls: acc.toolCalls, closed: true });
|
|
101
|
+
if (acc.usageDelta !== void 0) totals.add(acc.usageDelta);
|
|
102
|
+
}
|
|
103
|
+
function rowToMessageRow(v) {
|
|
104
|
+
if (typeof v === "object" && v !== null && "id" in v && "data" in v) {
|
|
105
|
+
const r = v;
|
|
106
|
+
if (typeof r.id === "string" && typeof r.data === "string") return { id: r.id, data: r.data };
|
|
107
|
+
}
|
|
108
|
+
throw new ZcodeReaderError("message \u884C\u5F62\u72B6\u5F02\u5E38\uFF08id/data \u5217\u7F3A\u5931\u6216\u7C7B\u578B\u6F02\u79FB\uFF09");
|
|
109
|
+
}
|
|
110
|
+
function rowToPartRow(v) {
|
|
111
|
+
if (typeof v === "object" && v !== null && "data" in v) {
|
|
112
|
+
const r = v;
|
|
113
|
+
if (typeof r.data === "string") return { data: r.data };
|
|
114
|
+
}
|
|
115
|
+
throw new ZcodeReaderError("part \u884C\u5F62\u72B6\u5F02\u5E38\uFF08data \u5217\u7F3A\u5931\u6216\u7C7B\u578B\u6F02\u79FB\uFF09");
|
|
116
|
+
}
|
|
117
|
+
function resolveSessionId(db, sessionId) {
|
|
118
|
+
if (sessionId !== void 0) {
|
|
119
|
+
const hit = db.prepare("SELECT id FROM session WHERE id = ?").get(sessionId);
|
|
120
|
+
if (hit === void 0) {
|
|
121
|
+
throw new ZcodeReaderError(
|
|
122
|
+
`session \u4E0D\u5B58\u5728\uFF1A${sessionId}`,
|
|
123
|
+
"sessionId \u53EF\u80FD\u6765\u81EA\u5DF2\u6E05\u7406\u7684\u6C60\u2014\u2014\u964D\u7EA7\u5230 outcome-only\u3002"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return sessionId;
|
|
127
|
+
}
|
|
128
|
+
const latest = db.prepare("SELECT id FROM session ORDER BY time_created DESC LIMIT 1").get();
|
|
129
|
+
if (latest === void 0 || typeof latest.id !== "string") {
|
|
130
|
+
throw new ZcodeReaderError("db \u5185\u65E0\u4EFB\u4F55 session \u884C");
|
|
131
|
+
}
|
|
132
|
+
return latest.id;
|
|
133
|
+
}
|
|
134
|
+
function loadGroupedParts(db, sessionId) {
|
|
135
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
136
|
+
for (const raw of db.prepare(
|
|
137
|
+
"SELECT part.message_id AS mid, part.data AS data FROM part JOIN message ON part.message_id = message.id WHERE part.session_id = ? ORDER BY message.sequence, part.sequence"
|
|
138
|
+
).all(sessionId)) {
|
|
139
|
+
if (typeof raw !== "object" || raw === null || !("mid" in raw)) continue;
|
|
140
|
+
const mid = String(raw.mid);
|
|
141
|
+
const arr = grouped.get(mid) ?? [];
|
|
142
|
+
arr.push(rowToPartRow(raw));
|
|
143
|
+
grouped.set(mid, arr);
|
|
144
|
+
}
|
|
145
|
+
return grouped;
|
|
146
|
+
}
|
|
147
|
+
function appendPartText(current, part) {
|
|
148
|
+
return current === "" ? String(part.text ?? "") : current + "\n" + String(part.text ?? "");
|
|
149
|
+
}
|
|
150
|
+
function applyPartToTurn(part, acc, turns, totals) {
|
|
151
|
+
switch (part.type) {
|
|
152
|
+
case "text":
|
|
153
|
+
acc = acc ?? { text: "", thinking: "", toolCalls: [] };
|
|
154
|
+
acc.text = appendPartText(acc.text, part);
|
|
155
|
+
return acc;
|
|
156
|
+
case "reasoning":
|
|
157
|
+
acc = acc ?? { text: "", thinking: "", toolCalls: [] };
|
|
158
|
+
acc.thinking = appendPartText(acc.thinking, part);
|
|
159
|
+
return acc;
|
|
160
|
+
case "tool":
|
|
161
|
+
acc = acc ?? { text: "", thinking: "", toolCalls: [] };
|
|
162
|
+
acc.toolCalls.push(toolFromPart(part));
|
|
163
|
+
return acc;
|
|
164
|
+
case "step-finish": {
|
|
165
|
+
const u = usageFromStepFinish(part);
|
|
166
|
+
const cost = finiteOr(part.cost, 0);
|
|
167
|
+
if (acc === null) acc = { text: "", thinking: "", toolCalls: [] };
|
|
168
|
+
if (u !== void 0) acc.usageDelta = cost > 0 ? { ...u, cost } : u;
|
|
169
|
+
closeTurn(acc, turns, totals);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
default:
|
|
173
|
+
return acc;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function collectTurns(messages, grouped, totals) {
|
|
177
|
+
const turns = [];
|
|
178
|
+
for (const msg of messages) {
|
|
179
|
+
const parsedMsg = parseJsonField(msg.data, "message");
|
|
180
|
+
if (parsedMsg?.role !== "assistant") continue;
|
|
181
|
+
let acc = null;
|
|
182
|
+
for (const partRow of grouped.get(msg.id) ?? []) {
|
|
183
|
+
const part = parseJsonField(partRow.data, "part");
|
|
184
|
+
if (part === void 0) continue;
|
|
185
|
+
acc = applyPartToTurn(part, acc, turns, totals);
|
|
186
|
+
}
|
|
187
|
+
closeTurn(acc, turns, totals);
|
|
188
|
+
}
|
|
189
|
+
return turns;
|
|
190
|
+
}
|
|
191
|
+
function buildView(db, sessionId) {
|
|
192
|
+
const messages = db.prepare("SELECT id, data FROM message WHERE session_id = ? ORDER BY sequence").all(sessionId).map(rowToMessageRow);
|
|
193
|
+
const totals = new TotalsAcc();
|
|
194
|
+
const turns = collectTurns(messages, loadGroupedParts(db, sessionId), totals);
|
|
195
|
+
const usageTotal = totals.toTotal();
|
|
196
|
+
return {
|
|
197
|
+
engineId: ZCODE_ENGINE_ID,
|
|
198
|
+
sessionId,
|
|
199
|
+
...usageTotal !== void 0 ? { usage: usageTotal } : {},
|
|
200
|
+
turns,
|
|
201
|
+
source: "native"
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
async function readZcodeSessionView(dbPath, sessionId) {
|
|
205
|
+
if (!fs.existsSync(dbPath)) {
|
|
206
|
+
throw new ZcodeReaderError(`db \u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${dbPath}`);
|
|
207
|
+
}
|
|
208
|
+
const sqliteModuleId = "node:sqlite";
|
|
209
|
+
const sqliteMod = await import(sqliteModuleId).catch(() => void 0);
|
|
210
|
+
const DatabaseSyncCtor = sqliteMod?.DatabaseSync;
|
|
211
|
+
if (typeof DatabaseSyncCtor !== "function") {
|
|
212
|
+
throw new ZcodeReaderError(
|
|
213
|
+
"\u5F53\u524D node \u8FD0\u884C\u65F6\u4E0D\u652F\u6301 node:sqlite\uFF08\u9700 >=22.13\uFF09",
|
|
214
|
+
"\u5347\u7EA7 node \u6216\u6539\u7528\u7B2C\u2461\u7EA7\uFF08\u5BBF\u4E3B event journal\uFF09\u8BFB\u53D6\u3002"
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
const open = DatabaseSyncCtor;
|
|
218
|
+
let db;
|
|
219
|
+
try {
|
|
220
|
+
db = new open(dbPath, { readOnly: true });
|
|
221
|
+
return buildView(db, resolveSessionId(db, sessionId));
|
|
222
|
+
} catch (err) {
|
|
223
|
+
if (err instanceof ZcodeReaderError) throw err;
|
|
224
|
+
throw new ZcodeReaderError(
|
|
225
|
+
`sqlite \u67E5\u8BE2\u5931\u8D25\uFF08${err instanceof Error ? err.message : String(err)}\uFF09`,
|
|
226
|
+
"\u7591\u4F3C\u8868\u7ED3\u6784\u6F02\u79FB\uFF08zcode schema_migration \u5347\u7EA7\uFF09\u2014\u2014\u8C03\u7528\u65B9\u5E94\u964D\u7EA7\u5230\u7B2C\u2461\u7EA7\uFF1B\u5E76\u628A\u65B0 schema \u6837\u672C\u8865\u5F55\u8FDB golden \u5E93\u540E\u66F4\u65B0 reader\u3002"
|
|
227
|
+
);
|
|
228
|
+
} finally {
|
|
229
|
+
try {
|
|
230
|
+
db?.close();
|
|
231
|
+
} catch (err) {
|
|
232
|
+
void err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
export {
|
|
237
|
+
ZcodeReaderError,
|
|
238
|
+
readZcodeSessionView
|
|
239
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/execution/engine/paths.ts
|
|
21
|
+
var paths_exports = {};
|
|
22
|
+
__export(paths_exports, {
|
|
23
|
+
resolveEngineDir: () => resolveEngineDir,
|
|
24
|
+
resolveEnginesRoot: () => resolveEnginesRoot,
|
|
25
|
+
resolveJournalPath: () => resolveJournalPath,
|
|
26
|
+
resolvePoolDir: () => resolvePoolDir,
|
|
27
|
+
sanitizeSeg: () => sanitizeSeg
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(paths_exports);
|
|
30
|
+
var import_node_path = require("path");
|
|
31
|
+
var MAX_SEG_CHARS = 80;
|
|
32
|
+
function sanitizeSeg(input) {
|
|
33
|
+
const s = input.replace(/[^A-Za-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
34
|
+
return s.length > 0 ? s.slice(0, MAX_SEG_CHARS) : "default";
|
|
35
|
+
}
|
|
36
|
+
function resolveEnginesRoot(dataDir) {
|
|
37
|
+
return (0, import_node_path.join)(dataDir, "engines");
|
|
38
|
+
}
|
|
39
|
+
function resolveEngineDir(dataDir, engineId) {
|
|
40
|
+
return (0, import_node_path.join)(resolveEnginesRoot(dataDir), sanitizeSeg(engineId));
|
|
41
|
+
}
|
|
42
|
+
function resolvePoolDir(dataDir, engineId, poolKey) {
|
|
43
|
+
return (0, import_node_path.join)(resolveEngineDir(dataDir, sanitizeSeg(engineId)), sanitizeSeg(poolKey));
|
|
44
|
+
}
|
|
45
|
+
function resolveJournalPath(dataDir, engineId, poolKey, taskId) {
|
|
46
|
+
return (0, import_node_path.join)(resolvePoolDir(dataDir, engineId, poolKey), `journal-${sanitizeSeg(taskId)}.jsonl`);
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
resolveEngineDir,
|
|
51
|
+
resolveEnginesRoot,
|
|
52
|
+
resolveJournalPath,
|
|
53
|
+
resolvePoolDir,
|
|
54
|
+
sanitizeSeg
|
|
55
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** 路径段进入文件系统前的安全编码:路径穿越、分隔符、空白、超长全部归一。 */
|
|
2
|
+
declare function sanitizeSeg(input: string): string;
|
|
3
|
+
declare function resolveEnginesRoot(dataDir: string): string;
|
|
4
|
+
declare function resolveEngineDir(dataDir: string, engineId: string): string;
|
|
5
|
+
declare function resolvePoolDir(dataDir: string, engineId: string, poolKey: string): string;
|
|
6
|
+
declare function resolveJournalPath(dataDir: string, engineId: string, poolKey: string, taskId: string): string;
|
|
7
|
+
|
|
8
|
+
export { resolveEngineDir, resolveEnginesRoot, resolveJournalPath, resolvePoolDir, sanitizeSeg };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** 路径段进入文件系统前的安全编码:路径穿越、分隔符、空白、超长全部归一。 */
|
|
2
|
+
declare function sanitizeSeg(input: string): string;
|
|
3
|
+
declare function resolveEnginesRoot(dataDir: string): string;
|
|
4
|
+
declare function resolveEngineDir(dataDir: string, engineId: string): string;
|
|
5
|
+
declare function resolvePoolDir(dataDir: string, engineId: string, poolKey: string): string;
|
|
6
|
+
declare function resolveJournalPath(dataDir: string, engineId: string, poolKey: string, taskId: string): string;
|
|
7
|
+
|
|
8
|
+
export { resolveEngineDir, resolveEnginesRoot, resolveJournalPath, resolvePoolDir, sanitizeSeg };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/execution/engine/paths.ts
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
var MAX_SEG_CHARS = 80;
|
|
4
|
+
function sanitizeSeg(input) {
|
|
5
|
+
const s = input.replace(/[^A-Za-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6
|
+
return s.length > 0 ? s.slice(0, MAX_SEG_CHARS) : "default";
|
|
7
|
+
}
|
|
8
|
+
function resolveEnginesRoot(dataDir) {
|
|
9
|
+
return join(dataDir, "engines");
|
|
10
|
+
}
|
|
11
|
+
function resolveEngineDir(dataDir, engineId) {
|
|
12
|
+
return join(resolveEnginesRoot(dataDir), sanitizeSeg(engineId));
|
|
13
|
+
}
|
|
14
|
+
function resolvePoolDir(dataDir, engineId, poolKey) {
|
|
15
|
+
return join(resolveEngineDir(dataDir, sanitizeSeg(engineId)), sanitizeSeg(poolKey));
|
|
16
|
+
}
|
|
17
|
+
function resolveJournalPath(dataDir, engineId, poolKey, taskId) {
|
|
18
|
+
return join(resolvePoolDir(dataDir, engineId, poolKey), `journal-${sanitizeSeg(taskId)}.jsonl`);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
resolveEngineDir,
|
|
22
|
+
resolveEnginesRoot,
|
|
23
|
+
resolveJournalPath,
|
|
24
|
+
resolvePoolDir,
|
|
25
|
+
sanitizeSeg
|
|
26
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/execution/relay-env.ts
|
|
21
|
+
var relay_env_exports = {};
|
|
22
|
+
__export(relay_env_exports, {
|
|
23
|
+
RELAY_ENV_NODE: () => RELAY_ENV_NODE,
|
|
24
|
+
RELAY_ENV_RECORD_ID: () => RELAY_ENV_RECORD_ID,
|
|
25
|
+
RELAY_ENV_SCRIPT: () => RELAY_ENV_SCRIPT,
|
|
26
|
+
RELAY_ENV_SESSION_ID: () => RELAY_ENV_SESSION_ID,
|
|
27
|
+
RELAY_ENV_SOCKET: () => RELAY_ENV_SOCKET,
|
|
28
|
+
RELAY_EXIT_CODES: () => RELAY_EXIT_CODES,
|
|
29
|
+
RELAY_PROTOCOL_VERSION: () => RELAY_PROTOCOL_VERSION,
|
|
30
|
+
isRelayActive: () => isRelayActive
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(relay_env_exports);
|
|
33
|
+
var RELAY_ENV_SOCKET = "XYZ_SUBAGENT_RELAY_SOCKET";
|
|
34
|
+
var RELAY_ENV_NODE = "XYZ_SUBAGENT_RELAY_NODE";
|
|
35
|
+
var RELAY_ENV_SCRIPT = "XYZ_SUBAGENT_RELAY_SCRIPT";
|
|
36
|
+
var RELAY_ENV_SESSION_ID = "XYZ_SUBAGENT_RELAY_SESSION_ID";
|
|
37
|
+
var RELAY_ENV_RECORD_ID = "XYZ_SUBAGENT_RELAY_RECORD_ID";
|
|
38
|
+
var RELAY_PROTOCOL_VERSION = 1;
|
|
39
|
+
var RELAY_EXIT_CODES = {
|
|
40
|
+
/** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
|
|
41
|
+
VERSION_MISMATCH: 10,
|
|
42
|
+
/** relay socket 不可达(runtime 未运行或已重启)。 */
|
|
43
|
+
SOCKET_UNREACHABLE: 11,
|
|
44
|
+
/** socket 中途断开(runtime 崩溃等)——代理生命线断即退。 */
|
|
45
|
+
SOCKET_CLOSED: 12,
|
|
46
|
+
/** 归属 env(SESSION_ID/RECORD_ID)缺失——防无归属帧污染广播。 */
|
|
47
|
+
MISSING_IDENTITY: 13
|
|
48
|
+
};
|
|
49
|
+
function isRelayActive(env) {
|
|
50
|
+
return Boolean(env[RELAY_ENV_SOCKET] && env[RELAY_ENV_NODE] && env[RELAY_ENV_SCRIPT]);
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
RELAY_ENV_NODE,
|
|
55
|
+
RELAY_ENV_RECORD_ID,
|
|
56
|
+
RELAY_ENV_SCRIPT,
|
|
57
|
+
RELAY_ENV_SESSION_ID,
|
|
58
|
+
RELAY_ENV_SOCKET,
|
|
59
|
+
RELAY_EXIT_CODES,
|
|
60
|
+
RELAY_PROTOCOL_VERSION,
|
|
61
|
+
isRelayActive
|
|
62
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* subagent relay 通道 env 名与协议常量 SSOT(docs/architecture/subagent-realtime-channel.md §5.1/§5.2/§3.1)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么独立成模块:三方消费同一份常量——extension 侧(pi-invocation 激活判定 /
|
|
5
|
+
* buildChildEnv 归属写入)、runtime 侧(env 注入与镜像校验)、代理脚本 relay.mjs
|
|
6
|
+
* (零依赖脚本不能 import workspace 包,只能内嵌镜像,镜像一致性由 conformance
|
|
7
|
+
* relay 变体断言锁定)。禁各处手写字符串。
|
|
8
|
+
*
|
|
9
|
+
* env 语义:SOCKET/NODE/SCRIPT 三者同时非空 = relay 激活(全有或全无,无中间态);
|
|
10
|
+
* SESSION_ID/RECORD_ID 是 tee 帧归属键(缺失由代理握手前自检拒绝,退出码 13)。
|
|
11
|
+
*/
|
|
12
|
+
declare const RELAY_ENV_SOCKET = "XYZ_SUBAGENT_RELAY_SOCKET";
|
|
13
|
+
declare const RELAY_ENV_NODE = "XYZ_SUBAGENT_RELAY_NODE";
|
|
14
|
+
declare const RELAY_ENV_SCRIPT = "XYZ_SUBAGENT_RELAY_SCRIPT";
|
|
15
|
+
declare const RELAY_ENV_SESSION_ID = "XYZ_SUBAGENT_RELAY_SESSION_ID";
|
|
16
|
+
declare const RELAY_ENV_RECORD_ID = "XYZ_SUBAGENT_RELAY_RECORD_ID";
|
|
17
|
+
/** relay 协议版本(握手帧 v 字段;runtime 与代理同包分发,不匹配=安装损坏)。 */
|
|
18
|
+
declare const RELAY_PROTOCOL_VERSION = 1;
|
|
19
|
+
/** 代理专用退出码(extension 侧表现为「子进程非零退出」→ engine_run_failed 语义)。 */
|
|
20
|
+
declare const RELAY_EXIT_CODES: {
|
|
21
|
+
/** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
|
|
22
|
+
readonly VERSION_MISMATCH: 10;
|
|
23
|
+
/** relay socket 不可达(runtime 未运行或已重启)。 */
|
|
24
|
+
readonly SOCKET_UNREACHABLE: 11;
|
|
25
|
+
/** socket 中途断开(runtime 崩溃等)——代理生命线断即退。 */
|
|
26
|
+
readonly SOCKET_CLOSED: 12;
|
|
27
|
+
/** 归属 env(SESSION_ID/RECORD_ID)缺失——防无归属帧污染广播。 */
|
|
28
|
+
readonly MISSING_IDENTITY: 13;
|
|
29
|
+
};
|
|
30
|
+
/** 激活判定:三 env 同时非空才走 relay,任一缺失回落直连 spawn 真实 pi(TUI/独立 pi 零回归)。 */
|
|
31
|
+
declare function isRelayActive(env: NodeJS.ProcessEnv | Record<string, string | undefined>): boolean;
|
|
32
|
+
|
|
33
|
+
export { RELAY_ENV_NODE, RELAY_ENV_RECORD_ID, RELAY_ENV_SCRIPT, RELAY_ENV_SESSION_ID, RELAY_ENV_SOCKET, RELAY_EXIT_CODES, RELAY_PROTOCOL_VERSION, isRelayActive };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* subagent relay 通道 env 名与协议常量 SSOT(docs/architecture/subagent-realtime-channel.md §5.1/§5.2/§3.1)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么独立成模块:三方消费同一份常量——extension 侧(pi-invocation 激活判定 /
|
|
5
|
+
* buildChildEnv 归属写入)、runtime 侧(env 注入与镜像校验)、代理脚本 relay.mjs
|
|
6
|
+
* (零依赖脚本不能 import workspace 包,只能内嵌镜像,镜像一致性由 conformance
|
|
7
|
+
* relay 变体断言锁定)。禁各处手写字符串。
|
|
8
|
+
*
|
|
9
|
+
* env 语义:SOCKET/NODE/SCRIPT 三者同时非空 = relay 激活(全有或全无,无中间态);
|
|
10
|
+
* SESSION_ID/RECORD_ID 是 tee 帧归属键(缺失由代理握手前自检拒绝,退出码 13)。
|
|
11
|
+
*/
|
|
12
|
+
declare const RELAY_ENV_SOCKET = "XYZ_SUBAGENT_RELAY_SOCKET";
|
|
13
|
+
declare const RELAY_ENV_NODE = "XYZ_SUBAGENT_RELAY_NODE";
|
|
14
|
+
declare const RELAY_ENV_SCRIPT = "XYZ_SUBAGENT_RELAY_SCRIPT";
|
|
15
|
+
declare const RELAY_ENV_SESSION_ID = "XYZ_SUBAGENT_RELAY_SESSION_ID";
|
|
16
|
+
declare const RELAY_ENV_RECORD_ID = "XYZ_SUBAGENT_RELAY_RECORD_ID";
|
|
17
|
+
/** relay 协议版本(握手帧 v 字段;runtime 与代理同包分发,不匹配=安装损坏)。 */
|
|
18
|
+
declare const RELAY_PROTOCOL_VERSION = 1;
|
|
19
|
+
/** 代理专用退出码(extension 侧表现为「子进程非零退出」→ engine_run_failed 语义)。 */
|
|
20
|
+
declare const RELAY_EXIT_CODES: {
|
|
21
|
+
/** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
|
|
22
|
+
readonly VERSION_MISMATCH: 10;
|
|
23
|
+
/** relay socket 不可达(runtime 未运行或已重启)。 */
|
|
24
|
+
readonly SOCKET_UNREACHABLE: 11;
|
|
25
|
+
/** socket 中途断开(runtime 崩溃等)——代理生命线断即退。 */
|
|
26
|
+
readonly SOCKET_CLOSED: 12;
|
|
27
|
+
/** 归属 env(SESSION_ID/RECORD_ID)缺失——防无归属帧污染广播。 */
|
|
28
|
+
readonly MISSING_IDENTITY: 13;
|
|
29
|
+
};
|
|
30
|
+
/** 激活判定:三 env 同时非空才走 relay,任一缺失回落直连 spawn 真实 pi(TUI/独立 pi 零回归)。 */
|
|
31
|
+
declare function isRelayActive(env: NodeJS.ProcessEnv | Record<string, string | undefined>): boolean;
|
|
32
|
+
|
|
33
|
+
export { RELAY_ENV_NODE, RELAY_ENV_RECORD_ID, RELAY_ENV_SCRIPT, RELAY_ENV_SESSION_ID, RELAY_ENV_SOCKET, RELAY_EXIT_CODES, RELAY_PROTOCOL_VERSION, isRelayActive };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RELAY_ENV_NODE,
|
|
3
|
+
RELAY_ENV_RECORD_ID,
|
|
4
|
+
RELAY_ENV_SCRIPT,
|
|
5
|
+
RELAY_ENV_SESSION_ID,
|
|
6
|
+
RELAY_ENV_SOCKET,
|
|
7
|
+
RELAY_EXIT_CODES,
|
|
8
|
+
RELAY_PROTOCOL_VERSION,
|
|
9
|
+
isRelayActive
|
|
10
|
+
} from "../chunk-A4IVZWVX.js";
|
|
11
|
+
export {
|
|
12
|
+
RELAY_ENV_NODE,
|
|
13
|
+
RELAY_ENV_RECORD_ID,
|
|
14
|
+
RELAY_ENV_SCRIPT,
|
|
15
|
+
RELAY_ENV_SESSION_ID,
|
|
16
|
+
RELAY_ENV_SOCKET,
|
|
17
|
+
RELAY_EXIT_CODES,
|
|
18
|
+
RELAY_PROTOCOL_VERSION,
|
|
19
|
+
isRelayActive
|
|
20
|
+
};
|