@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,37 @@
|
|
|
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
|
+
|
|
13
|
+
export const RELAY_ENV_SOCKET = 'XYZ_SUBAGENT_RELAY_SOCKET';
|
|
14
|
+
export const RELAY_ENV_NODE = 'XYZ_SUBAGENT_RELAY_NODE';
|
|
15
|
+
export const RELAY_ENV_SCRIPT = 'XYZ_SUBAGENT_RELAY_SCRIPT';
|
|
16
|
+
export const RELAY_ENV_SESSION_ID = 'XYZ_SUBAGENT_RELAY_SESSION_ID';
|
|
17
|
+
export const RELAY_ENV_RECORD_ID = 'XYZ_SUBAGENT_RELAY_RECORD_ID';
|
|
18
|
+
|
|
19
|
+
/** relay 协议版本(握手帧 v 字段;runtime 与代理同包分发,不匹配=安装损坏)。 */
|
|
20
|
+
export const RELAY_PROTOCOL_VERSION = 1;
|
|
21
|
+
|
|
22
|
+
/** 代理专用退出码(extension 侧表现为「子进程非零退出」→ engine_run_failed 语义)。 */
|
|
23
|
+
export const RELAY_EXIT_CODES = {
|
|
24
|
+
/** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
|
|
25
|
+
VERSION_MISMATCH: 10,
|
|
26
|
+
/** relay socket 不可达(runtime 未运行或已重启)。 */
|
|
27
|
+
SOCKET_UNREACHABLE: 11,
|
|
28
|
+
/** socket 中途断开(runtime 崩溃等)——代理生命线断即退。 */
|
|
29
|
+
SOCKET_CLOSED: 12,
|
|
30
|
+
/** 归属 env(SESSION_ID/RECORD_ID)缺失——防无归属帧污染广播。 */
|
|
31
|
+
MISSING_IDENTITY: 13,
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
/** 激活判定:三 env 同时非空才走 relay,任一缺失回落直连 spawn 真实 pi(TUI/独立 pi 零回归)。 */
|
|
35
|
+
export function isRelayActive(env: NodeJS.ProcessEnv | Record<string, string | undefined>): boolean {
|
|
36
|
+
return Boolean(env[RELAY_ENV_SOCKET] && env[RELAY_ENV_NODE] && env[RELAY_ENV_SCRIPT]);
|
|
37
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/core/session-context-resolver.ts
|
|
2
|
+
//
|
|
3
|
+
// resolveSessionContext 纯函数——解析 fork/worktree 意图,返回执行上下文。
|
|
4
|
+
// D-014: 零副作用,零 Pi import。只返回意图,不调 forkFrom/不创建 sessionDir。
|
|
5
|
+
|
|
6
|
+
import type { ResolvedSessionContext, SessionResolveInput } from "./types.ts";
|
|
7
|
+
import { ForkDepthExceededError } from "./types.ts";
|
|
8
|
+
import { getSubagentSessionDir } from "./path-encoding.ts";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* fork 深度硬限。export 供 session-runner 注入 LLM env block 时引用同一常量,
|
|
12
|
+
* 避免硬限(拦截)与展示(`N/10`)两处 10 漂移。
|
|
13
|
+
*
|
|
14
|
+
* 双层护栏(互补,共享本常量):
|
|
15
|
+
* 1. resolveSessionContext 的 fork 护栏(parentForkDepth >= MAX_FORK_DEPTH → 拒):
|
|
16
|
+
* 只计 fork 链(fork=true 才递增 parentForkDepth),控 session 体积(每层 createBranchedSession)。
|
|
17
|
+
* 2. SubagentService.execute 入口的通用嵌套护栏(nestingDepth > MAX_FORK_DEPTH → 拒):
|
|
18
|
+
* 经 execCtxAls 计所有 subagent 嵌套(fork + 非 fork),更严——混合链
|
|
19
|
+
* (fork→非fork→fork)下 nestingDepth >= parentForkDepth,通用护栏先生效。
|
|
20
|
+
* 两者均允许深度 0..MAX_FORK_DEPTH(共 MAX+1 层),第 MAX+1 层(深度=MAX+1)被拒。
|
|
21
|
+
*/
|
|
22
|
+
export const MAX_FORK_DEPTH = 10;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 纯函数:解析 fork/worktree 意图 → 执行上下文。
|
|
26
|
+
*
|
|
27
|
+
* 只返回意图(shouldFork/forkSource/effectiveCwd/sessionDir),
|
|
28
|
+
* 不调 forkFrom / 不创建 sessionDir / 不 git worktree add。
|
|
29
|
+
*
|
|
30
|
+
* @throws {ForkDepthExceededError} fork=true 且 parentForkDepth >= 10
|
|
31
|
+
*/
|
|
32
|
+
export function resolveSessionContext(input: SessionResolveInput): ResolvedSessionContext {
|
|
33
|
+
const { fork, cwd, mainCwd, mainSessionFile, parentForkDepth, agentDir, worktreePath } =
|
|
34
|
+
input;
|
|
35
|
+
|
|
36
|
+
// fork 深度检查(D-007)
|
|
37
|
+
if (fork && (parentForkDepth ?? 0) >= MAX_FORK_DEPTH) {
|
|
38
|
+
throw new ForkDepthExceededError(
|
|
39
|
+
`fork depth ${parentForkDepth ?? 0} >= ${MAX_FORK_DEPTH}, refusing to fork`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const shouldFork = fork === true;
|
|
44
|
+
const forkSource = shouldFork ? mainSessionFile : undefined;
|
|
45
|
+
|
|
46
|
+
// [MF#5] fork 显式请求但主 session 文件不可用(session_start 未缓存)时直接抛错,
|
|
47
|
+
// 不静默降级到 from-scratch——否则用户显式 fork 却得到无继承 session,且无任何告警。
|
|
48
|
+
if (shouldFork && !forkSource) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"fork requested but main session file is unavailable " +
|
|
51
|
+
"(session_start did not cache it); cannot fork without a source session",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// effectiveCwd: worktree 模式用 handle.path(真实 checkout,由调用方传入),
|
|
56
|
+
// 否则用显式 cwd 或 mainCwd。worktreePath 与 worktree 标志同源(都来自 WorktreeHandle),
|
|
57
|
+
// 不再靠 tmpdir 拼凑,保证 effectiveCwd 与实际 checkout 严格一致。
|
|
58
|
+
const effectiveCwd = worktreePath ?? (cwd ?? mainCwd);
|
|
59
|
+
|
|
60
|
+
// sessionDir 用 mainCwd 编码(D-004: 同一主 cwd 下所有 subagent 存同一目录)
|
|
61
|
+
const sessionDir = getSubagentSessionDir(agentDir, mainCwd);
|
|
62
|
+
|
|
63
|
+
return { shouldFork, forkSource, effectiveCwd, sessionDir };
|
|
64
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/runtime/session-file-gc.ts
|
|
2
|
+
//
|
|
3
|
+
// 概率性清理过期 subagent session 文件(TTL 30 天)。
|
|
4
|
+
// session_start 时调用,best-effort(失败不影响启动)。
|
|
5
|
+
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
|
|
9
|
+
import { isProcessAlive, readAliveMarker } from "./alive-store.ts";
|
|
10
|
+
|
|
11
|
+
/** 30 天 TTL(毫秒)。 */
|
|
12
|
+
const TTL_DAYS = 30;
|
|
13
|
+
const HOURS_PER_DAY = 24;
|
|
14
|
+
const MINUTES_PER_HOUR = 60;
|
|
15
|
+
const SECONDS_PER_MINUTE = 60;
|
|
16
|
+
const MS_PER_SECOND = 1000;
|
|
17
|
+
const TTL_MS = TTL_DAYS * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MS_PER_SECOND;
|
|
18
|
+
|
|
19
|
+
/** 触发概率(1/20 = 5%,避免每次 session_start 都全扫)。 */
|
|
20
|
+
const CLEANUP_PROBABILITY_DIVISOR = 20;
|
|
21
|
+
const CLEANUP_PROBABILITY = 1 / CLEANUP_PROBABILITY_DIVISOR;
|
|
22
|
+
|
|
23
|
+
/** subagent session 文件目录(相对 agentDir)。 */
|
|
24
|
+
const SUBAGENTS_DIR = "subagents";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 概率性清理过期 session 文件。best-effort——任何异常不外抛。
|
|
28
|
+
*
|
|
29
|
+
* 1. 概率性触发(CLEANUP_PROBABILITY)
|
|
30
|
+
* 2. 递归扫描 <agentDir>/subagents 下所有 .jsonl 文件
|
|
31
|
+
* 3. mtime 超 TTL → unlink
|
|
32
|
+
*/
|
|
33
|
+
export function maybeCleanupExpiredSessionFiles(agentDir: string, cwd: string): void {
|
|
34
|
+
void cwd;
|
|
35
|
+
try {
|
|
36
|
+
if (Math.random() >= CLEANUP_PROBABILITY) return;
|
|
37
|
+
const dir = path.join(agentDir, SUBAGENTS_DIR);
|
|
38
|
+
if (!fs.existsSync(dir)) return;
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
walkAndClean(dir, now);
|
|
41
|
+
} catch (_e) {
|
|
42
|
+
// best-effort:任何异常不阻断 session_start
|
|
43
|
+
void _e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 递归扫描目录,unlink 超 TTL 的 .jsonl 文件及其 .cancelled sidecar。
|
|
48
|
+
* [F2] 进入名为 records 的子目录时,额外清理超 TTL 的 manifest .json(跳过 .tmp.——
|
|
49
|
+
* recoverTmpFiles 同步处理)。allowManifestJson 仅由父调用按目录名开启,其他位置
|
|
50
|
+
* (如 subagents/worktrees.json)不匹配 .json,避免误删 worktree reaper 状态文件。 */
|
|
51
|
+
function walkAndClean(dir: string, now: number, allowManifestJson = false): void {
|
|
52
|
+
let entries: fs.Dirent[];
|
|
53
|
+
try {
|
|
54
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
55
|
+
} catch (_e) {
|
|
56
|
+
void _e;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const entry of entries) {
|
|
60
|
+
const full = path.join(dir, entry.name);
|
|
61
|
+
if (entry.isDirectory()) {
|
|
62
|
+
// 只在进入名为 records 的子目录时打开 manifest .json 清理。
|
|
63
|
+
// records 在 <enc>/records/ 下递归自动覆盖;其他位置(如 subagents/worktrees.json)
|
|
64
|
+
// 不能匹配 .json——否则会误删 worktree reaper 依赖的状态文件。
|
|
65
|
+
walkAndClean(full, now, entry.name === "records");
|
|
66
|
+
} else if (
|
|
67
|
+
allowManifestJson &&
|
|
68
|
+
entry.name.endsWith(".json") &&
|
|
69
|
+
// 跳过 .tmp.:recoverTmpFiles(session_start)同步处理 tmp,GC 不重复。
|
|
70
|
+
// 不校验内容——30 天 mtime 已是强 orphan 信号,扩展名 + 文件名足够。
|
|
71
|
+
!entry.name.includes(".tmp.")
|
|
72
|
+
) {
|
|
73
|
+
try {
|
|
74
|
+
const stat = fs.statSync(full);
|
|
75
|
+
if (now - stat.mtimeMs > TTL_MS) {
|
|
76
|
+
fs.unlinkSync(full);
|
|
77
|
+
}
|
|
78
|
+
} catch (_e) {
|
|
79
|
+
// 文件可能已被删除,忽略
|
|
80
|
+
void _e;
|
|
81
|
+
}
|
|
82
|
+
} else if (entry.name.endsWith(".jsonl")) {
|
|
83
|
+
try {
|
|
84
|
+
const stat = fs.statSync(full);
|
|
85
|
+
if (now - stat.mtimeMs > TTL_MS) {
|
|
86
|
+
// .alive 探活:活进程的 session 不删(D-024 安全网)。
|
|
87
|
+
const aliveMarker = readAliveMarker(full);
|
|
88
|
+
if (aliveMarker !== undefined && isProcessAlive(aliveMarker.pid)) {
|
|
89
|
+
continue; // 活进程 → 跳过,不清理
|
|
90
|
+
}
|
|
91
|
+
fs.unlinkSync(full);
|
|
92
|
+
// 同名 sidecar 一起清理。
|
|
93
|
+
for (const ext of [".cancelled", ".finalized", ".alive"]) {
|
|
94
|
+
try { fs.unlinkSync(`${full}${ext}`); } catch (_e) { void _e; /* sidecar 可能不存在 */ }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch (_e) {
|
|
98
|
+
// 文件可能已被删除,忽略
|
|
99
|
+
void _e;
|
|
100
|
+
}
|
|
101
|
+
} else if (
|
|
102
|
+
entry.name.endsWith(".cancelled") ||
|
|
103
|
+
entry.name.endsWith(".finalized") ||
|
|
104
|
+
entry.name.endsWith(".alive") ||
|
|
105
|
+
// [MF#2] patch 回传(<branch>.patch)按 branch 命名,与 .jsonl basename 无关联,
|
|
106
|
+
// 删除 .jsonl 时无法同删;作为孤儿按 TTL 清理,避免永久堆积。
|
|
107
|
+
entry.name.endsWith(".patch")
|
|
108
|
+
) {
|
|
109
|
+
// 孤儿 sidecar(兄弟 .jsonl 已被外部删除):按同 TTL 清理。
|
|
110
|
+
try {
|
|
111
|
+
const stat = fs.statSync(full);
|
|
112
|
+
if (now - stat.mtimeMs > TTL_MS) {
|
|
113
|
+
fs.unlinkSync(full);
|
|
114
|
+
}
|
|
115
|
+
} catch (_e) {
|
|
116
|
+
void _e;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/execution/session-pending.ts
|
|
2
|
+
//
|
|
3
|
+
// agent_end 后代判定:读子进程的 session 文件,用 pending-notifications 的
|
|
4
|
+
// register − unregister 差集计数(经通知域窄端口 NotifyDomainPorts 注入的
|
|
5
|
+
// countActiveFromEntries——core 依赖闭包不含 pi-pending-notifications,见
|
|
6
|
+
// core/notify-ports.ts;端口缺席时按零活跃处理 = pending 门全开)判断该 subagent
|
|
7
|
+
// 是否还有活跃后代(background subagent / workflow)。
|
|
8
|
+
//
|
|
9
|
+
// 背景(v4 递归编排):层主 planning-agent 派子 subagent 后结束 turn 等待被唤醒。
|
|
10
|
+
// 若 runSpawn 在 agent_end 无条件 kill,进程被回收、steer 唤醒送不到,递归树断。
|
|
11
|
+
// 判定依据:子进程的 session 文件里 pending:register entry(其进程内 appendEntry
|
|
12
|
+
// 同步写盘,见 pi SessionManager._persist)减去 pending:unregister 的差集。
|
|
13
|
+
// fork 继承的主 session register 残留由 pending-notifications 的 session_start
|
|
14
|
+
// 重建流程补 unregister(expired) 抵消,纯差集不受污染。
|
|
15
|
+
//
|
|
16
|
+
// 纯函数 + fs,独立于 runSpawn,可单测。
|
|
17
|
+
|
|
18
|
+
import * as fs from "node:fs";
|
|
19
|
+
|
|
20
|
+
import { getLogger } from "../core/logger.ts";
|
|
21
|
+
import { getNotifyDomainPorts } from "../core/notify-ports.ts";
|
|
22
|
+
|
|
23
|
+
const logger = getLogger("subagents");
|
|
24
|
+
|
|
25
|
+
/** 后代刚完成(unregister)后,notify 唤醒父 agent 可能仍在路上(triggerTurn 的
|
|
26
|
+
* steer/followUp 经 sendMessage → agent 队列排空(agent-session.js:1081-1087),
|
|
27
|
+
* 不经 EventBus——EventBus 只用于扩展间 pi.events;与主进程处理 agent_end 行存在
|
|
28
|
+
* 毫秒级竞态——explorer 3 秒完成时实测 unregister 先于 agent_end 判定写入,导致
|
|
29
|
+
* 差集 0 误判完成)。此窗口内的 agent_end 不 kill,等父被唤醒后的下一次 agent_end 再判。 */
|
|
30
|
+
const RECENT_UNREGISTER_WINDOW_MS = 60_000;
|
|
31
|
+
|
|
32
|
+
/** 判定结果:count > 0 = 有活跃后代(应保持进程等唤醒)。 */
|
|
33
|
+
export interface ActivePendingResult {
|
|
34
|
+
count: number;
|
|
35
|
+
/** 最近窗口内(60s)有 pending:unregister——后代刚完成,唤醒通知可能在路上。 */
|
|
36
|
+
recentUnregister: boolean;
|
|
37
|
+
/** 读取/解析失败的原因(undefined = 成功)。调用方对 error 采取保守策略(不 kill)。 */
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* [perf] per-file 增量游标:session 文件 append-only,同文件重复判定(层主被多个
|
|
43
|
+
* 后代唤醒 N 次 → N 次 agent_end)只需读上次 offset 之后的新增行,累计 entries
|
|
44
|
+
* 差集语义与全量读完全一致。fork 继承的大 session(数十 MB)从「每次整读」降为
|
|
45
|
+
* 「首读全量 + 后续增量」。
|
|
46
|
+
* truncate/重建防御:size < offset → 重置全读。EOF 半行(写入竞态)不入账,
|
|
47
|
+
* offset 只推进到完整行边界,下次补读。
|
|
48
|
+
* 内存量级:每 sessionFile 一条(offset + 后代 entries,均有限);测试隔离用
|
|
49
|
+
* clearPendingCursors()。
|
|
50
|
+
*/
|
|
51
|
+
interface PendingReadCursor {
|
|
52
|
+
offset: number;
|
|
53
|
+
entries: unknown[];
|
|
54
|
+
latestUnregisterMs: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const cursors = new Map<string, PendingReadCursor>();
|
|
58
|
+
|
|
59
|
+
/** 清空增量游标缓存(测试隔离用)。 */
|
|
60
|
+
export function clearPendingCursors(): void {
|
|
61
|
+
cursors.clear();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** [taste/no-unsafe-cast] pending 行的最小结构守卫:非 null object 即可(字段访问
|
|
65
|
+
* 侧均做了 undefined 检查,全可选类型断言无校验意义,改守卫带运行时检查)。 */
|
|
66
|
+
function isPendingLineLike(v: unknown): v is { customType?: string; timestamp?: string } {
|
|
67
|
+
return typeof v === "object" && v !== null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 读 session 文件计算活跃 pending 数(增量读,见 PendingReadCursor)。
|
|
72
|
+
*
|
|
73
|
+
* 快速路径:行内含 pending 值(`"pending:register"` / `"pending:unregister"`)才解析,
|
|
74
|
+
* 大量 message 行只付 includes 扫描跳过 JSON.parse。
|
|
75
|
+
* [S-4] 按值匹配而非 `"customType":"pending:` 序列化格式——后者耦合 pi 的 JSON 序列化
|
|
76
|
+
* 空格习惯(冒号后无空格),pi 改 pretty-print 会导致全过滤 → count=0 → keep-alive
|
|
77
|
+
* 静默失效 → recursive tree 被杀、steer 丢失。值字符串本身不受序列化空格影响。
|
|
78
|
+
*
|
|
79
|
+
* 文件不存在(sessionFile 未回填/首次 assistant 前)→ error(调用方保守不 kill)。
|
|
80
|
+
* 坏行跳过(append 中途崩溃的截断行)。
|
|
81
|
+
*/
|
|
82
|
+
export function readActivePendingFromSessionFile(
|
|
83
|
+
sessionFile: string | undefined,
|
|
84
|
+
): ActivePendingResult {
|
|
85
|
+
if (!sessionFile) {
|
|
86
|
+
return { count: 0, recentUnregister: false, error: "no sessionFile (handshake not settled)" };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let size: number;
|
|
90
|
+
try {
|
|
91
|
+
size = fs.statSync(sessionFile).size;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
return {
|
|
94
|
+
count: 0,
|
|
95
|
+
recentUnregister: false,
|
|
96
|
+
error: `session file unreadable: ${err instanceof Error ? err.message : String(err)}`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let cursor = cursors.get(sessionFile);
|
|
101
|
+
if (cursor === undefined || size < cursor.offset) {
|
|
102
|
+
// 首次(全量)或文件被 truncate/重建(offset 越界)→ 重置从头读
|
|
103
|
+
cursor = { offset: 0, entries: [], latestUnregisterMs: 0 };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let chunk: string;
|
|
107
|
+
try {
|
|
108
|
+
if (cursor.offset === 0) {
|
|
109
|
+
chunk = fs.readFileSync(sessionFile, "utf-8");
|
|
110
|
+
} else {
|
|
111
|
+
const fd = fs.openSync(sessionFile, "r");
|
|
112
|
+
try {
|
|
113
|
+
const len = size - cursor.offset;
|
|
114
|
+
const buf = Buffer.alloc(len);
|
|
115
|
+
let total = 0;
|
|
116
|
+
while (total < len) {
|
|
117
|
+
const n = fs.readSync(fd, buf, total, len - total, cursor.offset + total);
|
|
118
|
+
if (n <= 0) break;
|
|
119
|
+
total += n;
|
|
120
|
+
}
|
|
121
|
+
chunk = buf.toString("utf-8", 0, total);
|
|
122
|
+
} finally {
|
|
123
|
+
fs.closeSync(fd);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
return {
|
|
128
|
+
count: 0,
|
|
129
|
+
recentUnregister: false,
|
|
130
|
+
error: `session file unreadable: ${err instanceof Error ? err.message : String(err)}`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 只消费到最后一个完整行:EOF 半行(append 写入竞态)不入账,offset 不推进,
|
|
135
|
+
// 下次从该行起点重读(补全后正常入账)。
|
|
136
|
+
const lastNl = chunk.lastIndexOf("\n");
|
|
137
|
+
const complete = lastNl === -1 ? "" : chunk.slice(0, lastNl);
|
|
138
|
+
cursor.offset += Buffer.byteLength(complete, "utf-8");
|
|
139
|
+
cursors.set(sessionFile, cursor);
|
|
140
|
+
|
|
141
|
+
for (const line of complete.split("\n")) {
|
|
142
|
+
// [S-4] 按值匹配:countActiveFromEntries 只消费 register/unregister 两种 customType,
|
|
143
|
+
// 故只需检测这两个值字符串;冒号前后空格变化不影响(值始终是连续子串)。
|
|
144
|
+
if (!line.includes('"pending:register"') && !line.includes('"pending:unregister"')) continue;
|
|
145
|
+
try {
|
|
146
|
+
const entry: unknown = JSON.parse(line);
|
|
147
|
+
if (!isPendingLineLike(entry)) continue;
|
|
148
|
+
cursor.entries.push(entry);
|
|
149
|
+
if (entry.customType === "pending:unregister" && entry.timestamp) {
|
|
150
|
+
const ts = Date.parse(entry.timestamp);
|
|
151
|
+
if (Number.isFinite(ts) && ts > cursor.latestUnregisterMs) cursor.latestUnregisterMs = ts;
|
|
152
|
+
}
|
|
153
|
+
} catch {
|
|
154
|
+
// 截断行/坏行跳过——不影响其余 entry 的差集判定(罕见:append 中途崩溃)
|
|
155
|
+
logger.debug("skipped malformed pending line", { sessionFile });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 计数器经通知域窄端口解析(缺省实现恒 0 = 零活跃,pending 门全开——安全侧缺省
|
|
160
|
+
// 收敛在端口层,见 core/notify-ports.ts DEFAULT_NOTIFY_PORTS;此处 `?? 0` 仅防御
|
|
161
|
+
// 宿主注入部分端口对象的形态)。
|
|
162
|
+
const countActive = getNotifyDomainPorts().countActiveFromEntries;
|
|
163
|
+
const active = countActive ? countActive(cursor.entries) : 0;
|
|
164
|
+
return {
|
|
165
|
+
count: active,
|
|
166
|
+
recentUnregister:
|
|
167
|
+
cursor.latestUnregisterMs > 0 &&
|
|
168
|
+
Date.now() - cursor.latestUnregisterMs < RECENT_UNREGISTER_WINDOW_MS,
|
|
169
|
+
};
|
|
170
|
+
}
|