@zhushanwen/subagent-core 0.5.1 → 0.7.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 +1 -1
- package/dist/chunk-KXVBIVOU.js +16 -0
- package/dist/chunk-T2SYBW3I.js +24 -0
- package/dist/chunk-VURUAGMM.js +2305 -0
- package/dist/{types-Dv4QhSJ_.d.cts → engine-discovery-scan-ocpM8FmI.d.cts} +835 -668
- package/dist/{types-Dv4QhSJ_.d.ts → engine-discovery-scan-ocpM8FmI.d.ts} +835 -668
- package/dist/execution/engine/engine-discovery-scan.cjs +2210 -0
- package/dist/execution/engine/engine-discovery-scan.d.cts +4 -0
- package/dist/execution/engine/engine-discovery-scan.d.ts +4 -0
- package/dist/execution/engine/engine-discovery-scan.js +20 -0
- package/dist/execution/engine/paths.cjs +6 -23
- package/dist/execution/engine/paths.d.cts +1 -8
- package/dist/execution/engine/paths.d.ts +1 -8
- package/dist/execution/engine/paths.js +1 -1
- package/dist/execution/relay-env.cjs +12 -28
- package/dist/execution/relay-env.d.cts +1 -33
- package/dist/execution/relay-env.d.ts +1 -33
- package/dist/execution/relay-env.js +5 -3
- package/dist/index.cjs +14123 -15467
- package/dist/index.d.cts +1179 -1540
- package/dist/index.d.ts +1179 -1540
- package/dist/index.js +7694 -10986
- package/dist.bundle/index.cjs +33485 -0
- package/package.json +20 -26
- package/src/__tests__/record-store-last-line.test.ts +16 -7
- package/src/core/error-message.ts +7 -6
- package/src/core/host-services.ts +8 -2
- package/src/core/notify-ports.ts +17 -2
- package/src/execution/__tests__/agent-registry.test.ts +1 -1
- package/src/execution/__tests__/alive-store.test.ts +1 -1
- package/src/execution/__tests__/chat-engine-routing.test.ts +62 -28
- package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +255 -0
- package/src/execution/__tests__/collect-budget.test.ts +291 -0
- package/src/execution/__tests__/collect-coordinator-service.test.ts +316 -0
- package/src/execution/__tests__/collect-coordinator.test.ts +371 -0
- package/src/execution/__tests__/collect-mixed-dispatch.test.ts +229 -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 +179 -237
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -2
- package/src/execution/__tests__/execute-nesting.test.ts +20 -13
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +21 -34
- package/src/execution/__tests__/finalized-marker.test.ts +1 -1
- package/src/execution/__tests__/gc-timer.test.ts +8 -23
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +20 -10
- package/src/execution/__tests__/helpers/fake-engine-port.ts +187 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +36 -9
- package/src/execution/__tests__/helpers/subagent-service-mocks.ts +1 -1
- package/src/execution/__tests__/idle-gc.test.ts +200 -0
- package/src/execution/__tests__/lifecycle-predicates.test.ts +26 -21
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +1 -1
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +5 -2
- package/src/execution/__tests__/notify-batch.test.ts +500 -0
- package/src/execution/__tests__/notify-ledger.test.ts +27 -0
- package/src/execution/__tests__/reconcile-sweep.test.ts +200 -0
- package/src/execution/__tests__/record-entry-collect.test.ts +102 -0
- package/src/execution/__tests__/record-store.test.ts +60 -6
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +20 -13
- package/src/execution/__tests__/relay-env.test.ts +12 -1
- package/src/execution/__tests__/round-supervisor.test.ts +293 -0
- package/src/execution/__tests__/session-file-gc.test.ts +1 -1
- package/src/execution/__tests__/session-pending.test.ts +119 -17
- package/src/execution/__tests__/start-collect-guard.test.ts +255 -0
- package/src/execution/__tests__/stream-sink-retirement.test.ts +10 -10
- package/src/execution/__tests__/subagent-actions-core.test.ts +6 -0
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +14 -11
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +33 -30
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +2 -9
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +59 -129
- package/src/execution/__tests__/subagent-service.test.ts +2 -2
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +109 -7
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +108 -36
- package/src/execution/__tests__/sync-collect-recovery.test.ts +1102 -0
- package/src/execution/__tests__/tombstone-store.test.ts +1 -1
- package/src/execution/__tests__/workflow-state-root.test.ts +232 -0
- package/src/execution/__tests__/worktree-git-ops.test.ts +1 -1
- 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 +6 -2
- package/src/execution/collect-coordinator.ts +200 -0
- package/src/execution/config.ts +77 -5
- package/src/execution/dialog-queue.ts +6 -73
- package/src/execution/engine/__tests__/common/capability-gate.test.ts +115 -15
- package/src/execution/engine/__tests__/common/errors.test.ts +11 -18
- package/src/execution/engine/__tests__/common/event-journal.test.ts +1 -1
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +7 -0
- package/src/execution/engine/__tests__/common/nesting-guard.test.ts +9 -3
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +2 -2
- package/src/execution/engine/__tests__/common/session-view-service.test.ts +90 -3
- package/src/execution/engine/__tests__/conformance/H9-test-disposition.md +116 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +377 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/recorded.fixture.json +331 -0
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +213 -0
- package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +230 -0
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +69 -42
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +4 -81
- package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +67 -44
- package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +82 -55
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +133 -70
- package/src/execution/engine/__tests__/conformance/engine-crash.test.ts +143 -0
- package/src/execution/engine/__tests__/conformance/fake-engine-capabilities.ts +19 -0
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +8 -3
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +6 -5
- package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +398 -0
- package/src/execution/engine/__tests__/conformance/registry-fork-filter.test.ts +221 -0
- package/src/execution/engine/__tests__/conformance/round-liveness-supervisor.test.ts +302 -0
- package/src/execution/engine/__tests__/conformance/static-spawn-guard.test.ts +58 -0
- package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +558 -0
- package/src/execution/engine/__tests__/host-task-spec.test.ts +45 -0
- package/src/execution/engine/__tests__/model-ref-split.test.ts +74 -0
- package/src/execution/engine/__tests__/registry.test.ts +206 -1
- package/src/execution/engine/__tests__/routing.test.ts +97 -0
- package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +97 -0
- package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +294 -0
- package/src/execution/engine/client/__tests__/engine-client.test.ts +516 -0
- package/src/execution/engine/client/__tests__/mirror.test.ts +67 -0
- package/src/execution/engine/client/__tests__/pid-file.test.ts +257 -0
- package/src/execution/engine/client/__tests__/protocol-closure.test.ts +95 -0
- package/src/execution/engine/client/__tests__/remote-engine.test.ts +457 -0
- package/src/execution/engine/client/client-options.ts +103 -0
- package/src/execution/engine/client/engine-client.ts +687 -0
- package/src/execution/engine/client/mirror.ts +167 -0
- package/src/execution/engine/client/pid-file.ts +392 -0
- package/src/execution/engine/client/reaper.ts +95 -0
- package/src/execution/engine/client/remote-engine.ts +441 -0
- package/src/execution/engine/client/reverse-router.ts +255 -0
- package/src/execution/engine/common/capability-gate.ts +109 -22
- package/src/execution/engine/common/errors.ts +9 -25
- package/src/execution/engine/common/event-journal.ts +4 -50
- package/src/execution/engine/common/journal-replay.ts +3 -1
- package/src/execution/engine/common/kill-chain.ts +18 -251
- package/src/execution/engine/common/nesting-guard.ts +18 -114
- package/src/execution/engine/common/pool-manager.ts +4 -0
- package/src/execution/engine/common/session-view-service.ts +56 -84
- package/src/execution/engine/config.ts +151 -0
- package/src/execution/engine/d8-compat.ts +346 -0
- package/src/execution/engine/engine-discovery-roots.ts +107 -0
- package/src/execution/engine/engine-discovery-scan.ts +269 -0
- package/src/execution/engine/engine-discovery.ts +30 -7
- package/src/execution/engine/engine-inspect-package.ts +282 -0
- package/src/execution/engine/engine-manifest.ts +244 -0
- package/src/execution/engine/host/__tests__/host-askuser-endpoint.test.ts +123 -0
- package/src/execution/engine/host/__tests__/host-bridge.test.ts +135 -0
- package/src/execution/engine/host/__tests__/spawned-children.test.ts +73 -0
- package/src/execution/engine/host/host-bridge.ts +150 -0
- package/src/execution/engine/host/host-ui-endpoint.ts +47 -0
- package/src/execution/engine/host/pi-host-binding.ts +91 -0
- package/src/execution/engine/host/spawned-children.ts +139 -0
- package/src/execution/engine/host-task-spec.ts +29 -2
- package/src/execution/engine/model-validation.ts +55 -2
- package/src/execution/engine/paths.ts +16 -41
- package/src/execution/engine/port.ts +48 -2
- package/src/execution/engine/registry.ts +153 -34
- package/src/execution/engine/routing.ts +225 -52
- package/src/execution/engine/types.ts +25 -200
- package/src/execution/execution-record.ts +7 -0
- package/src/execution/finalize-record.ts +40 -11
- package/src/execution/idle-gc.ts +89 -14
- package/src/execution/lifecycle-manager.ts +10 -7
- package/src/execution/lifecycle-predicates.ts +10 -8
- package/src/execution/notifier.ts +234 -25
- package/src/execution/notify-host.ts +21 -1
- package/src/execution/record-entry.ts +16 -0
- package/src/execution/record-store.ts +189 -31
- package/src/execution/relay-env.ts +19 -36
- package/src/execution/round-supervisor/domain.ts +89 -0
- package/src/execution/round-supervisor/index.ts +33 -0
- package/src/execution/round-supervisor/notify-accounting.ts +87 -0
- package/src/execution/round-supervisor/reconcile-sweep.ts +235 -0
- package/src/execution/round-supervisor/service-binding.test.ts +661 -0
- package/src/execution/round-supervisor/service-binding.ts +273 -0
- package/src/execution/round-supervisor/supervisor.ts +426 -0
- package/src/execution/session-pending.ts +68 -74
- package/src/execution/settled-watchdog.ts +39 -0
- package/src/execution/subagent-actions-core.ts +62 -6
- package/src/execution/subagent-service.ts +1161 -406
- package/src/execution/subprocess-agent-runner.ts +16 -8
- package/src/execution/sync-rebuild.ts +87 -0
- package/src/execution/types.ts +104 -117
- package/src/execution/ui-channels.ts +13 -214
- package/src/execution/ui-request-handler-factory.ts +7 -4
- package/src/execution/ui-request-observability.ts +2 -2
- package/src/execution/workflow-state-root.ts +67 -0
- package/src/execution/worktree-git-ops.ts +5 -0
- package/src/execution/worktree-manager.ts +11 -1
- package/src/index.ts +55 -26
- package/src/orchestration/__tests__/config-loader.test.ts +1 -1
- package/src/orchestration/__tests__/execute-agent-call.test.ts +1 -1
- 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__/review-fix-loop-scriptpath-failfast.test.ts +1 -1
- package/src/orchestration/__tests__/script-generate.test.ts +5 -5
- package/src/orchestration/__tests__/skill-discovery.test.ts +2 -2
- package/src/orchestration/__tests__/workflow-files.test.ts +10 -10
- package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +1 -1
- package/src/orchestration/execute-agent-call.ts +1 -1
- package/src/orchestration/file-run-store.ts +144 -59
- package/src/orchestration/models/types.ts +43 -42
- package/src/shared/__tests__/atomic-write.test.ts +1 -1
- package/src/shared/__tests__/resource-discovery-host-roots.test.ts +5 -5
- package/src/shared/zcode-model-ref.ts +31 -0
- package/dist/chunk-43ONBFZX.js +0 -240
- package/dist/chunk-A4IVZWVX.js +0 -31
- package/dist/chunk-APZY4IME.js +0 -27
- package/dist/chunk-V3VHZ2VX.js +0 -59
- package/dist/execution/engine/engines/zcode/constants.cjs +0 -107
- package/dist/execution/engine/engines/zcode/constants.d.cts +0 -135
- package/dist/execution/engine/engines/zcode/constants.d.ts +0 -135
- package/dist/execution/engine/engines/zcode/constants.js +0 -54
- package/dist/execution/engine/engines/zcode/reader.cjs +0 -276
- package/dist/execution/engine/engines/zcode/reader.d.cts +0 -21
- package/dist/execution/engine/engines/zcode/reader.d.ts +0 -21
- package/dist/execution/engine/engines/zcode/reader.js +0 -9
- package/src/__tests__/append-system-prompt-assembly.test.ts +0 -243
- package/src/__tests__/fr4-get-state-handshake.test.ts +0 -125
- package/src/__tests__/session-runner.test.ts +0 -69
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -191
- package/src/execution/__tests__/descendant-sweep-guards.test.ts +0 -220
- package/src/execution/__tests__/descendant-sweep.test.ts +0 -269
- package/src/execution/__tests__/engine-model-validation.test.ts +0 -741
- package/src/execution/__tests__/epipe-fallback.test.ts +0 -248
- package/src/execution/__tests__/execution-runtime-face.test.ts +0 -272
- package/src/execution/__tests__/get-state-handshake.test.ts +0 -127
- package/src/execution/__tests__/helpers/session-runner-mocks.ts +0 -113
- package/src/execution/__tests__/keep-alive-no-progress.test.ts +0 -280
- package/src/execution/__tests__/kill-all-escalation.test.ts +0 -196
- package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +0 -113
- package/src/execution/__tests__/output-collector.test.ts +0 -469
- package/src/execution/__tests__/pi-invocation.test.ts +0 -134
- package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -149
- package/src/execution/__tests__/rpc-mode.test.ts +0 -89
- package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +0 -387
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -277
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -254
- package/src/execution/__tests__/run-spawn-edges.test.ts +0 -1079
- package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
- package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +0 -207
- package/src/execution/__tests__/service-kill-escalation.test.ts +0 -91
- package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +0 -110
- package/src/execution/__tests__/session-runner-close-prune.test.ts +0 -181
- package/src/execution/__tests__/session-runner-dispatch.test.ts +0 -489
- package/src/execution/__tests__/session-runner-epipe.test.ts +0 -179
- package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +0 -227
- package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +0 -290
- package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -352
- package/src/execution/__tests__/settled-watchdog.test.ts +0 -524
- package/src/execution/__tests__/spawn-args.test.ts +0 -446
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -192
- package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -208
- package/src/execution/__tests__/spawned-children.test.ts +0 -236
- package/src/execution/__tests__/start-sync-model-guard.test.ts +0 -150
- package/src/execution/__tests__/stdin-writer.test.ts +0 -464
- package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -693
- package/src/execution/__tests__/temp-prompt.test.ts +0 -53
- package/src/execution/__tests__/timeout-integration.test.ts +0 -616
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
- package/src/execution/__tests__/turn-limiter.test.ts +0 -65
- package/src/execution/__tests__/ui-request-handler.test.ts +0 -205
- package/src/execution/__tests__/ui-request-queue.test.ts +0 -298
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -230
- package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
- package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +0 -149
- package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
- package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +0 -128
- package/src/execution/engine/__tests__/paths.test.ts +0 -39
- package/src/execution/engine/common/schema-emulation.ts +0 -189
- package/src/execution/engine/common/session-view-projection.ts +0 -51
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -615
- package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
- package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +0 -257
- package/src/execution/engine/engines/pi/argv-mirror.ts +0 -135
- package/src/execution/engine/engines/pi/get-state-handshake.ts +0 -179
- package/src/execution/engine/engines/pi/output-collector.ts +0 -317
- package/src/execution/engine/engines/pi/pi-engine.ts +0 -811
- package/src/execution/engine/engines/pi/pi-invocation.ts +0 -120
- package/src/execution/engine/engines/pi/reader.ts +0 -59
- package/src/execution/engine/engines/pi/registration.ts +0 -37
- package/src/execution/engine/engines/pi/session-runner.ts +0 -2840
- package/src/execution/engine/engines/pi/spawn-event-adapter.ts +0 -404
- package/src/execution/engine/engines/pi/stdin-writer.ts +0 -199
- package/src/execution/engine/engines/pi/temp-prompt.ts +0 -62
- package/src/execution/engine/engines/pi/turn-limiter.ts +0 -102
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +0 -301
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +0 -36
- package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +0 -321
- package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +0 -473
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -43
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -124
- package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
- package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -71
- package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +0 -247
- package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +0 -451
- package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +0 -792
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +0 -782
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +0 -168
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +0 -210
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +0 -353
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +0 -282
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +0 -372
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -145
- package/src/execution/engine/engines/zcode/appserver-launcher.ts +0 -167
- package/src/execution/engine/engines/zcode/connection.ts +0 -598
- package/src/execution/engine/engines/zcode/constants.ts +0 -176
- package/src/execution/engine/engines/zcode/golden-sample.ts +0 -47
- package/src/execution/engine/engines/zcode/parser.ts +0 -102
- package/src/execution/engine/engines/zcode/preparer.ts +0 -235
- package/src/execution/engine/engines/zcode/reader.ts +0 -381
- package/src/execution/engine/engines/zcode/registration.ts +0 -37
- package/src/execution/engine/engines/zcode/session-channel.ts +0 -968
- package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -1431
- package/src/execution/round-settlement.ts +0 -93
- package/src/execution/ui-request-queue.ts +0 -215
- package/src/shared/schema-env.ts +0 -44
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# W10 H9 测试面处置表(core 深路径测试三选一)
|
|
2
|
+
|
|
3
|
+
> 实施计划 §2.10「core 测试逐文件三选一处置清单」的执行记录(W10,2026-09-09)。
|
|
4
|
+
> 处置依据 = 文件 import 实测 + W5/W7 已迁件核对。处置后 core test 全绿
|
|
5
|
+
> (2999 passed | 7 skipped;删除 48 文件 / 改写 5 文件 / 保留待 W11 同批改写 4 文件——保留的 4 文件已随 W3 收口(1 删 3 改写),见 §② 节尾回写注记)。
|
|
6
|
+
|
|
7
|
+
## ① 已随引擎包迁移 —— 删除 core 重复副本(11 文件)
|
|
8
|
+
|
|
9
|
+
W5/W7 已把自包含件迁入引擎包(pi-subagent-cli / zcode-subagent-cli `__tests__/`,
|
|
10
|
+
两包 test 全绿),core 侧同名副本属重复实现测试,删除:
|
|
11
|
+
|
|
12
|
+
| core 副本(已删) | 引擎包权威副本 |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `src/__tests__/fr4-get-state-handshake.test.ts` | pi-subagent-cli `__tests__/get-state-handshake.test.ts` |
|
|
15
|
+
| `execution/__tests__/get-state-handshake.test.ts` | 同上 |
|
|
16
|
+
| `execution/__tests__/output-collector.test.ts` | pi `__tests__/output-collector.test.ts` |
|
|
17
|
+
| `execution/__tests__/pi-invocation.test.ts` | pi `__tests__/pi-invocation.test.ts` |
|
|
18
|
+
| `execution/__tests__/temp-prompt.test.ts` | pi `__tests__/temp-prompt.test.ts` |
|
|
19
|
+
| `execution/__tests__/stdin-writer.test.ts` | pi `__tests__/stdin-writer.test.ts` |
|
|
20
|
+
| `execution/__tests__/spawn-event-adapter.test.ts` | pi `__tests__/spawn-event-adapter.test.ts` |
|
|
21
|
+
| `execution/__tests__/spawn-event-adapter-rpc.test.ts` | pi `__tests__/spawn-event-adapter-rpc.test.ts` |
|
|
22
|
+
| `execution/__tests__/turn-limiter.test.ts` | pi `__tests__/turn-limiter.test.ts` |
|
|
23
|
+
| `execution/__tests__/turn-limiter-semantics.test.ts` | pi `__tests__/turn-limiter-semantics.test.ts` |
|
|
24
|
+
| `execution/__tests__/spawn-args.test.ts` | pi `__tests__/spawn-args.test.ts`(core 副本的 `MAX_FORK_DEPTH` 断言面由 `recursive-visibility-baseline`/`nested-visibility` 族承接) |
|
|
25
|
+
|
|
26
|
+
## ① 随 SDK 原语迁移(1 文件)
|
|
27
|
+
|
|
28
|
+
| core(已删) | 迁移落点 |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `execution/engine/__tests__/paths.test.ts` | `subagent-engine-sdk/src/__tests__/paths.test.ts`(import 改 SDK 包内相对路径,5 用例全绿) |
|
|
31
|
+
|
|
32
|
+
## ② 改写为镜像/协议等价断言 —— 已完成(5 文件)
|
|
33
|
+
|
|
34
|
+
| 文件 | 改写内容 |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `src/orchestration/__tests__/execute-agent-call.test.ts` | output-collector 深路径 import → `@zhushanwen/pi-subagent-cli` 公共导出面(25 用例绿) |
|
|
37
|
+
| `execution/__tests__/subprocess-agent-runner-routing.test.ts` | `getChildByRecord` 深路径 → core 侧镜像 `host/spawned-children.ts coreSpawnedChildrenMirror().getChildByRecord`(pid 同构判据);「退出后按句移除」断言移至 protocol-blackbox childStateChanged 用例(inproc 双模不回灌该通道,文件内已注记) |
|
|
38
|
+
| `execution/__tests__/chat-engine-routing.test.ts` | 同上(镜像面改写) |
|
|
39
|
+
| `execution/engine/__tests__/common/capability-gate.test.ts` | PiEngine/ZcodeEngine 内建构造 → 读两引擎包 package.json manifest `xyz-agent.subagentEngine.capabilities`(同步成员唯一源;11 用例绿) |
|
|
40
|
+
| `execution/engine/__tests__/conformance/contract.{probe,abort,read-degradation,agent-events}.test.ts` + `golden-replay.{pi,zcode}.test.ts` + `engine-conformance.live.test.ts` | conformance 契约套件整体协议黑盒化:RemoteEngine × fake 引擎 CLI / golden 语料改引擎包 `__golden__/` + 公共导出面 / live 门改「协议客户端 × 引擎包 CLI」形态(A2 真机形态本身) |
|
|
41
|
+
|
|
42
|
+
## ② 改写被阻塞 —— 保留 + W10 处置注记,W11 同批改写(4 文件)[v1.x W3 已收口,见节尾回写注记]
|
|
43
|
+
|
|
44
|
+
`src/__tests__/append-system-prompt-assembly.test.ts`、`execution/__tests__/explicit-agent-ref-guard.test.ts`、`execution/__tests__/delivery-methods.test.ts`、`execution/__tests__/gc-timer.test.ts`。
|
|
45
|
+
|
|
46
|
+
阻塞原因(同根):这些文件 `vi.mock("…engines/pi/session-runner.ts")` 拦截的**是 core 生产代码的 inproc 深路径 import**(subagent-service / lifecycle 谓词等消费点在生产侧)——mock 目标改指引擎包或镜像需生产 import 先改线,而 W6 已把改线收敛到 W11 收口(`subagent-service.ts` W7 注 + `lifecycle-predicates.test.ts` 仍深 import spawnedChildren 同证)。W11 删内建当轮必须同批改写这 4 个文件(每文件头部已留 `[W10 处置注记]`)。
|
|
47
|
+
|
|
48
|
+
> **[v1.x W3 已收口 —— 回写注记(2026-09-09)]** 上方 4 文件已随 commit `0df9ef8b3`(W3 删 inproc pi 引擎 + chat 协议化改线)处理完毕:`append-system-prompt-assembly.test.ts` 删除,其余 3 文件改写为协议等价断言(`explicit-agent-ref-guard.test.ts` / `delivery-methods.test.ts` / `gc-timer.test.ts`,现头注 `[W3 改写]` 可核)。原 `[W10 处置注记]` 已被 `[W3 改写]` 头注取代,W11 对这 4 文件无剩余改写面。本节标题、阻塞原因与文首统计行保留作 W10 时点历史([HISTORICAL] 纪律),现行状态以本注记为准。
|
|
49
|
+
|
|
50
|
+
## ③ 声明废弃 —— 删除(34 文件 + 1 helper)
|
|
51
|
+
|
|
52
|
+
统一理由(按文件另有侧重):**被测行为 = 内建 pi/zcode inproc 编排实现**,协议化终态下该实现归引擎进程(W11 删除 core `engines/pi|zcode`);行为面承接:
|
|
53
|
+
|
|
54
|
+
- **引擎内部行为**(spawn 参数/dispatch/LRU/心跳/EPIPE/收敛)→ `@zhushanwen/pi-subagent-cli` / `zcode-subagent-cli` 包内测试(W5/W7 迁移件,两包全绿);
|
|
55
|
+
- **协议契约面**(run/cancel/read/反向通道/错误帧/结构等价)→ W10 新协议黑盒套件 `conformance/protocol-blackbox.test.ts` + `client/__tests__/*`(W2);
|
|
56
|
+
- **收割/杀链语义**(R9-1 口径:一代子进程 + 组内后代)→ SDK kill-chain 单测 + A3 真机门;
|
|
57
|
+
- **inproc 双模过渡态**(XYZ_SUBAGENT_ENGINE_MODE)本身 = DoD#5 删除对象,不保留锚定测试。
|
|
58
|
+
|
|
59
|
+
| 已删文件 | 侧重理由 |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `src/__tests__/session-runner.test.ts` | 引擎内部(pi spawn-runner) |
|
|
62
|
+
| ask-user-transit-e2e / ui-request-handler | ui 请求链引擎内部面(pi 包 ui-channels/ui-request-queue 测试 + W10 反向通道用例) |
|
|
63
|
+
| chatmode-first-round-closure-spawn / run-and-finalize-chatmode / run-spawn-chatmode-settled | chat 轮次收敛编排(pi 包 spawn-runner;chat 域 HostBridge 编排 W7 已登记 stage-3 gap) |
|
|
64
|
+
| descendant-sweep / descendant-sweep-guards / kill-all-escalation / service-kill-escalation / spawned-children | 收割/杀链(SDK kill-chain + A3 真机门;镜像面 = protocol-blackbox) |
|
|
65
|
+
| epipe-fallback / session-runner-epipe | EPIPE 兜底(pi 包 stdin-writer/spawn-runner 测试) |
|
|
66
|
+
| keep-alive-no-progress / settled-watchdog / timeout-integration | 进度/超时判据(ADR-0047 域)。**处置改写(2026-09-09,Gate B 后纠正)**:原「pi 包 + A8 真机门」承接声称不成立——pi 包内无等价测试(grep keep-alive/no-progress/settled-watchdog/timeout-integration 零命中),Gate B 时点 A8 真机门为 blocked/manual、不构成承接证据;该三测试的行为面**随 keep-alive 协议化偏差登记**(impl-plan §5 2026-09-09 行:workflow 域单次 run 口径 agent_end 即终结,后台后代保活编排未随迁移),**不声称已承接** |
|
|
67
|
+
| recursive-visibility-env / start-sync-model-guard / session-runner-schema-env | 引擎内 env 注入面(pi 包 spawn-args/relay-env 测试;W12 env 契约单测) |
|
|
68
|
+
| rpc-mode / run-spawn-rpc-mode / run-spawn-integration / run-spawn-resume / run-spawn-edges / run-and-finalize-anchoring / run-spawn-stdout-callback-throw / spawn-worktree-guidance | run 全链编排(pi 包 spawn-runner/protocol-e2e;协议面 = W10 黑盒套件) |
|
|
69
|
+
| session-runner-branch-cache-lru / session-runner-close-prune / session-runner-dispatch / session-runner-heartbeat-idle-fallback / session-runner-lifecycle-helpers | session-runner 内部机制(pi 包) |
|
|
70
|
+
| max-turns-to-watchdog-ms | turn limiter 换算(pi 包 turn-limiter 测试) |
|
|
71
|
+
| subagent-service-message-close | message-close 编排(chat 域 stage-3 gap 承接) |
|
|
72
|
+
| worktree-pid-registration.integration | pid 注册集成(镜像面承接;worktree 面归 W12 回归) |
|
|
73
|
+
| execution-runtime-face / engine-model-validation / session-view-service-zcode-dbpath | zcode 引擎内部(zcode 包 zcode-engine-* / reader / zcode-session-db-isolation 测试) |
|
|
74
|
+
| `helpers/session-runner-mocks.ts` | 消费者全部随上表删除(spawn-mock.ts 保留——3 个存活壳侧行为测试仍消费) |
|
|
75
|
+
|
|
76
|
+
## 未入清单的既有深路径引用(W11 处置面,W10 显式登记)[v1.x W3 已收口,见节尾回写注记]
|
|
77
|
+
|
|
78
|
+
以下文件经 `vi.mock` 字符串路径引用 `engines/pi|zcode`(非值 import,grep 字符串命中),
|
|
79
|
+
不在 §2.10 三选一清单内、本次未动,W11 删内建时同批核处:
|
|
80
|
+
`recursive-visibility-baseline` / `nested-visibility-env-propagation` / `execute-nesting` / `execute-and-await-worktree` / `collect-coordinator-service` / `collect-mixed-dispatch` / `get-record-for-action-restart` / `stream-sink-retirement` / `subagent-agent-runner.test` / `subagent-service-{multiproc-guard,notify-gate,parent-guard,recovery-bounds}` / `sync-collect-recovery` / `helpers/{spawn-mock,subagent-service-mocks}` / `lifecycle-predicates.test`(归 W6/W11)。
|
|
81
|
+
|
|
82
|
+
> **[v1.x W3 已收口 —— 回写注记(2026-09-09)]** 上节登记的 17 项(14 测试 + 2 helper + `lifecycle-predicates.test`)已全部随 commit `0df9ef8b3`(W3 删 inproc pi 引擎 + chat 协议化改线)处理完毕:节内所列文件在该 commit 全部为改写(M),无一保留原深路径 mock;其中 `subagent-agent-runner.test` 系 `subprocess-agent-runner.test.ts` 的简写登记,同在该 commit 改写。`vi.mock(…engines/pi|zcode)` 深路径命中现全 core 树清零(grep 实测:残留仅注释/用例描述文本,无模块路径引用);`[W3]`/`[W3 改写]` 标记 17 项中 14 项可核(标记散布文件头部注记与用例旁注,非全在文件头),余 3 项(`execute-and-await-worktree` / `subagent-service-multiproc-guard` / `subagent-service-parent-guard`)无标记但同 commit 已删深路径 mock(diff 可核)。W11(commit `6d5f6747d`)对该面无剩余核处义务。原节登记保留作 W10 时点历史([HISTORICAL] 纪律),现行状态以本注记为准。
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## 主会话修正(2026-09-09,W10 修复轮)
|
|
86
|
+
|
|
87
|
+
- `engine/__tests__/common/session-view-service-zcode-dbpath.test.ts` 原列 §2.10 清单①(随 zcode 包迁移/W5),但 W5 未迁(它测的是 core 壳侧 session-view-service 白名单分支,非引擎内部行为)、W10 批次误删——已按原样恢复(8 用例绿)。该文件深路径 import(engines/zcode/{reader,constants,db-path})在 **W11 H1 改写当轮**随 session-view-service 协议化同批改写为协议等价断言(或由 zcode 包 e2e 接替后删除);在此之前保留为 A plan(zcode-session-db-isolation)生产链验收证据。
|
|
88
|
+
- ①类清单中「测 core 壳侧模块」的文件(本件与 execution-runtime-face / engine-model-validation)处置归属应为「W11 H1/H2 同批」而非「随引擎包迁移」——后续处置以本节为准。
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## W6 承接回写(2026-09-09,chat-domain v1.x 轮次活性治理)
|
|
92
|
+
|
|
93
|
+
> 设计权威源:`docs/design/chat-domain-v1x-liveness-governance.md` §3.2 D2/D5 + §5 W6 行。
|
|
94
|
+
> 本节回写 §③ 行「keep-alive-no-progress / settled-watchdog / timeout-integration」的
|
|
95
|
+
> 处置改写注记(该行「不声称已承接」状态自本节起 supersede)——三测试行为面已随
|
|
96
|
+
> W4/W6 落地,承接落点如下。原注记保留作历史,不删([HISTORICAL] 纪律)。
|
|
97
|
+
|
|
98
|
+
| 原测试 | 承接落点 | 状态 |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| keep-alive-no-progress | **W4 轮次活性监督器**(keep-alive 编排归属裁决 A:core 编排层持有「轮次活性权威」,`execution/round-supervisor/`——no-progress 判定域按设计 D2 域分类收窄:run 域 resumable 无驱动任务归监督器三态;chat 域 idle 稳态豁免归 settled-watchdog/idle 机制)+ conformance 协议黑盒场景链 `conformance/round-liveness-supervisor.test.ts`(SIGTERM crash → 纳管 → 该唤醒 → 该放弃全链 / boot 分区 / 通知对账 / 重建不解管)+ W4 判定矩阵单测 `execution/__tests__/round-supervisor.test.ts` | 已承接(W6 回写) |
|
|
101
|
+
| settled-watchdog | **含生产接线归属**:两段守护行为面 = 既有 core 原语套件(`execution/__tests__/subagent-service-recovery-bounds.test.ts`:armSettledWatchdog / mid-round no-progress / settled 硬顶 / 双 disarm 回收面)。**生产接线归属(D5「删件不同批重接 = 失守」约束)**:W4 已立协议事件 API 三入口——`execution/settled-watchdog.ts` 的 `refreshFromProtocolEvent`(协议事件行到达刷新中段)/ `noteRoundSettledFromProtocol`(settled 相位中段让位收尾段)/ `disarmRoundFromProtocol`(idle 相位/close/终态两段一并清),零新语义薄委托、与存量原语幂等并存;**W3 删 `engines/pi/session-runner.ts` 时必须同批把存量 arm/refresh/kill 接线(arm 点 = 轮开始;refresh 源 = host/streamDelta + host/roundLifecycle;kill/终态 = 既有杀链)换到这三个入口**——接线未重接完成前 W3 不得删件 | 已承接(协议事件面已立 + W3 重接认领) |
|
|
102
|
+
| timeout-integration | live conformance 门(`conformance/engine-conformance.live.test.ts`,`ENGINE_CONFORMANCE_LIVE=1 PI_LIVE_MODEL=<模型>`;设计验收 A7)——超时/abort/收敛行为在真机引擎 + 真实进程生命周期下验证;单测不再锚定 inproc 实现(原 timeout-integration 的「abort 超时强杀集成」语义由 W7 runtime 三级阶梯测试 + 本 live 门共同承载) | 已承接(live 门) |
|
|
103
|
+
|
|
104
|
+
**W6 同批新增语义钉住**(conformance 领地,均绿于 `pnpm --filter @zhushanwen/subagent-core test`):
|
|
105
|
+
|
|
106
|
+
- 引擎中途 SIGTERM → run 终态 failed(**D5 前置闸:本用例先于 W3 删 `engines/pi/session-runner.ts` 旧 143 误分类器存在并保持绿**,P2 探针的 conformance 承载)→ `conformance/engine-crash.test.ts`;
|
|
107
|
+
- chat 轮次协议 v1.x(host/roundLifecycle 三相位 × runId|recordId 关联键回执链 + recordId 键 delta 分路 + conversation gate 负向 A6)→ `conformance/chat-round-protocol.test.ts`;
|
|
108
|
+
- 翻档事实(三类型全 process 档、跨时长无 TTL 清理)+ fork 读侧过滤①③两口径 + **bash 跨 session 可见性显式断言**(R4 一刀钉成显式选择)+ 偏差 #4 探针(goal 守卫口径实测)→ `conformance/registry-fork-filter.test.ts`。
|
|
109
|
+
|
|
110
|
+
**goal 熔断(W5)处置**:**由 extension 侧单测承载,不重复造**——`extensions/universal/goal` 393 例已覆盖双维度熔断(circuit-breaker 6 + liveness 17:50 次封顶必停发、第 5 轮起间隔 ×2、恢复清零退避不重置总数、defer 通知去重);设计验收 A10(实机熔断场景)仍归 Gate B 真机剧本,不在 conformance 重复。
|
|
111
|
+
|
|
112
|
+
## 一致性审查批 2 修复回写(2026-09-09,F-2 首轮 arm 重接)
|
|
113
|
+
|
|
114
|
+
上方 W6 承接回写节「settled-watchdog」行声称的「W3 重接」**当时失实**(一致性审查批 2 F-2 证实):W3 实际只重接了热路径续聊轮(`deliverChatMessage` 的 arm 调用点),`kickOffChatRound`(spawn 首轮 + 冷续 resume 轮)内无任何 arm 调用——:1382 注释声称「首轮调用点在 kickOffChatRound 的 run 派发后」不存在,被删的 inproc stdout-pump 是首轮唯一中段守护,协议化后引擎侧 spawn-runner 仅 turn 计数无墙钟 → **首轮 wedged 无熔断**(LC-1 场景①重新敞开)。H9 行「已承接」按当时状态属过度声称。
|
|
115
|
+
|
|
116
|
+
**修复后真实状态**(本行 supersede 上方 W6 行的承接声明):`kickOffChatRound` 在 run 派发前(pool acquire 成功后)补 `armMidRoundNoProgress`,与热路径 arm 复用同一守护实例语义(同一 `onHotPathSettledWatchdogTimeout` 处置闭包);refresh 源核实齐备——首轮 runId 键 `ctx.onEvent` 协议事件行(含 text_delta,引擎侧 spawn-runner 对 text_delta 同时走 onEvent/onDelta 两通道)+ `ctx.onRoundLifecycle` settled 相位交棒(`noteRoundSettledFromProtocol`,首轮 runId 键经同一 handleChatRoundPhase 收敛,本批测试核实生效)。承接测试:`execution/__tests__/chat-round-first-round-watchdog.test.ts`(首轮 arm / 冷续轮静默 30min 熔断 / 中段事件行刷新 / settled 交棒不继承中段计时)。
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
// fake-engine-protocol.mjs —— W10 协议黑盒套件的 fake 引擎 CLI(conformance 专用,
|
|
2
|
+
// 与 W2 client/__tests__ 的 fake-engine.mjs 分工:后者测 EngineClient 连接域语义,
|
|
3
|
+
// 本件是协议基线回放器——按 fixture(schemaVersion 1)回放帧序列)。
|
|
4
|
+
//
|
|
5
|
+
// 形态对齐协议 v1(stdout 独占 NDJSON;stdin 帧驱动):
|
|
6
|
+
// - FAKE_PROTOCOL_FIXTURE:fixture JSON 路径(必填);本件 = 该 fixture 的回放引擎;
|
|
7
|
+
// - 正向方法(10 个):initialize / probe / run / cancel / interact / read /
|
|
8
|
+
// listModels / validateModel / dispose / ping——结果取 fixture 对应段;
|
|
9
|
+
// - 反向通道(8 个):host/log / host/askUser / host/permission / host/streamDelta /
|
|
10
|
+
// host/poolResolved / host/handleReady / host/childSpawned / host/childStateChanged
|
|
11
|
+
// ——run 期间按 fixture.run.script 逐动作播放;
|
|
12
|
+
// - 错误帧:FAKE_PROTOCOL_ERROR=run_failed(run 回错误帧)| unknown_method(对任意
|
|
13
|
+
// 未知名方法回 engine_method_unknown——不在 v1 错误码表内的码也必须原样透传,
|
|
14
|
+
// 断言的是帧形态而非码表);FAKE_PROTOCOL_VERSION 越界 → initialize 回
|
|
15
|
+
// engine_protocol_mismatch;
|
|
16
|
+
// - childSpawned 的 pid = 真 spawn 一个同组长眠 node 子进程(供 POSIX kill(-pid,0)
|
|
17
|
+
// 组探测断言与 killAll 收割断言——范围口径 R9-1:一代子进程 + 组内后代)。
|
|
18
|
+
//
|
|
19
|
+
// [W6 conformance 增量] 追加面(全部 env 开关驱动,缺省关闭——既有回放行为不变):
|
|
20
|
+
// - FAKE_PID_FILE:启动时写自身 pid(SIGTERM 用例的 kill 定位锚——core 侧 pidfile
|
|
21
|
+
// 归 EngineClient 所有,fake 侧不触碰,路径自建自删归测试);
|
|
22
|
+
// - FAKE_CAPABILITIES_CONVERSATION:覆写 initialize 应答的
|
|
23
|
+
// capabilities.conversation(chat gate 负向:旧形态引擎 manifest 无该位);
|
|
24
|
+
// - 新 script op(env 注入 script,沿 FAKE_RUN_HANG 先例):
|
|
25
|
+
// { op:"stderr", text } → 引擎 stderr 写点(engine_crashed
|
|
26
|
+
// 的 stderr 尾 400 窗口实证);
|
|
27
|
+
// { op:"roundLifecycle", keyedBy, key,
|
|
28
|
+
// phase, error?, anchor? } → host/roundLifecycle 帧(三相位 ×
|
|
29
|
+
// runId|recordId 关联键分路);
|
|
30
|
+
// streamDelta op 支持 action.recordId → recordId 键 delta(续聊轮关联键);
|
|
31
|
+
// - 数据面应答回声:roundLifecycle / recordId-delta 帧的②应答到达时回发
|
|
32
|
+
// host/log("ack <label>")——core 侧断言「宿主确认收到」回执链闭合的观测锚;
|
|
33
|
+
// - FAKE_RUN_LIFECYCLE=1 / FAKE_RUN_RECORD_DELTA=1 / FAKE_RUN_STDERR_HANG=1:
|
|
34
|
+
// run script 注入上述动作段(三相位 × 双键 / recordId 键 delta / stderr+hang)。
|
|
35
|
+
|
|
36
|
+
import { spawn } from "node:child_process";
|
|
37
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
38
|
+
import { createInterface } from "node:readline";
|
|
39
|
+
|
|
40
|
+
const fixturePath = process.env.FAKE_PROTOCOL_FIXTURE;
|
|
41
|
+
if (!fixturePath) {
|
|
42
|
+
process.stderr.write("fake-engine-protocol: FAKE_PROTOCOL_FIXTURE is required\n");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const fixture = JSON.parse(readFileSync(fixturePath, "utf8"));
|
|
46
|
+
|
|
47
|
+
const MODE = process.env.FAKE_PROTOCOL_ERROR ?? "none"; // none | run_failed | unknown_method
|
|
48
|
+
const PROTOCOL_VERSION = Number(process.env.FAKE_PROTOCOL_VERSION ?? fixture.protocolVersion ?? 1);
|
|
49
|
+
|
|
50
|
+
// [W6] SIGTERM 用例的进程定位锚(测试自建自删;写失败不阻断回放主路径)。
|
|
51
|
+
if (process.env.FAKE_PID_FILE) {
|
|
52
|
+
try {
|
|
53
|
+
writeFileSync(process.env.FAKE_PID_FILE, String(process.pid), "utf8");
|
|
54
|
+
} catch {
|
|
55
|
+
// 定位锚写失败只影响依赖它的用例(该用例 waitFor pidfile 会超时显式红),
|
|
56
|
+
// 不影响其余回放行为。
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// [W6] 数据面应答回声记账:请求 id → 回声 label(帧②到达时回发 host/log)。
|
|
61
|
+
const ackEchoLabels = new Map();
|
|
62
|
+
|
|
63
|
+
let grandchildren = []; // 同组长眠子进程(killAll 收割断言对象)
|
|
64
|
+
|
|
65
|
+
function send(frame) {
|
|
66
|
+
process.stdout.write(`${JSON.stringify(frame)}\n`);
|
|
67
|
+
}
|
|
68
|
+
function reverseRequest(id, method, params) {
|
|
69
|
+
send({ id, method, params });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let nextRequestId = 100;
|
|
73
|
+
|
|
74
|
+
async function playRunScript(runId, script) {
|
|
75
|
+
for (const action of script) {
|
|
76
|
+
if (cancelledRuns.has(runId)) return;
|
|
77
|
+
switch (action.op) {
|
|
78
|
+
case "log":
|
|
79
|
+
reverseRequest(`rev-log-${nextRequestId++}`, "host/log", {
|
|
80
|
+
level: action.level ?? "info",
|
|
81
|
+
component: action.component ?? "fake",
|
|
82
|
+
message: action.message ?? "",
|
|
83
|
+
});
|
|
84
|
+
break;
|
|
85
|
+
case "poolResolved":
|
|
86
|
+
reverseRequest(`rev-pool-${nextRequestId++}`, "host/poolResolved", {
|
|
87
|
+
runId,
|
|
88
|
+
poolKey: action.poolKey ?? "shared",
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
case "handleReady":
|
|
92
|
+
reverseRequest(`rev-ready-${nextRequestId++}`, "host/handleReady", {
|
|
93
|
+
runId,
|
|
94
|
+
sessionRef: action.sessionRef ?? { sessionId: "sess-fixture" },
|
|
95
|
+
poolKey: action.poolKey ?? "shared",
|
|
96
|
+
});
|
|
97
|
+
break;
|
|
98
|
+
case "childSpawned": {
|
|
99
|
+
const grandchild = spawn(
|
|
100
|
+
process.execPath,
|
|
101
|
+
["-e", "setInterval(() => {}, 1000)"],
|
|
102
|
+
{ detached: false, stdio: "ignore" },
|
|
103
|
+
);
|
|
104
|
+
grandchildren.push(grandchild);
|
|
105
|
+
reverseRequest(`rev-child-${nextRequestId++}`, "host/childSpawned", {
|
|
106
|
+
pid: grandchild.pid,
|
|
107
|
+
recordId: action.recordId ?? runId,
|
|
108
|
+
});
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case "childStateChanged":
|
|
112
|
+
reverseRequest(`rev-childst-${nextRequestId++}`, "host/childStateChanged", {
|
|
113
|
+
pid: grandchildren[grandchildren.length - 1]?.pid,
|
|
114
|
+
recordId: action.recordId ?? runId,
|
|
115
|
+
state: action.state ?? "exited",
|
|
116
|
+
killed: action.killed ?? false,
|
|
117
|
+
...(action.exitCode !== undefined ? { exitCode: action.exitCode } : {}),
|
|
118
|
+
...(action.signal !== undefined ? { signal: action.signal } : {}),
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
case "streamDelta": {
|
|
122
|
+
// [W6] action.recordId 有值 = 续聊轮 recordId 键 delta(关联键分路——
|
|
123
|
+
// D1-A:interact 发起的轮无 runId,经 handle.sessionRef 的 recordId 关联)。
|
|
124
|
+
const streamReqId = `rev-stream-${nextRequestId++}`;
|
|
125
|
+
if (action.recordId !== undefined) {
|
|
126
|
+
ackEchoLabels.set(streamReqId, `streamDelta recordId=${action.recordId}`);
|
|
127
|
+
reverseRequest(streamReqId, "host/streamDelta", {
|
|
128
|
+
recordId: action.recordId,
|
|
129
|
+
delta: action.delta ?? "",
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
reverseRequest(streamReqId, "host/streamDelta", {
|
|
133
|
+
runId,
|
|
134
|
+
delta: action.delta ?? "",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case "stderr":
|
|
140
|
+
// [W6] 引擎 stderr 写点(engine_crashed stderr 尾窗的实证面——同步写,
|
|
141
|
+
// 后续动作可用 host/log 做到达锚)。
|
|
142
|
+
process.stderr.write(action.text ?? "");
|
|
143
|
+
break;
|
|
144
|
+
case "roundLifecycle": {
|
|
145
|
+
// [W6] host/roundLifecycle 帧(三相位 × runId|recordId 双关联键)。
|
|
146
|
+
// failed 相位必含 error{code,message}(isHostRoundLifecycleParams 判据)。
|
|
147
|
+
const lcReqId = `rev-lc-${nextRequestId++}`;
|
|
148
|
+
const keyed =
|
|
149
|
+
action.keyedBy === "recordId"
|
|
150
|
+
? { recordId: action.key }
|
|
151
|
+
: { runId: action.key };
|
|
152
|
+
ackEchoLabels.set(lcReqId, `roundLifecycle ${action.key} ${action.phase}`);
|
|
153
|
+
reverseRequest(lcReqId, "host/roundLifecycle", {
|
|
154
|
+
...keyed,
|
|
155
|
+
phase: action.phase,
|
|
156
|
+
...(action.usage !== undefined ? { usage: action.usage } : {}),
|
|
157
|
+
...(action.error !== undefined ? { error: action.error } : {}),
|
|
158
|
+
...(action.anchor !== undefined ? { anchor: action.anchor } : {}),
|
|
159
|
+
});
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case "permission":
|
|
163
|
+
reverseRequest(`rev-perm-${nextRequestId++}`, "host/permission", {
|
|
164
|
+
runId,
|
|
165
|
+
request: action.request ?? {},
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
case "askUser":
|
|
169
|
+
reverseRequest(`rev-ask-${nextRequestId++}`, "host/askUser", {
|
|
170
|
+
runId,
|
|
171
|
+
request: action.request ?? {},
|
|
172
|
+
});
|
|
173
|
+
break;
|
|
174
|
+
case "emit":
|
|
175
|
+
send({ method: "event", params: { runId, seq: action.seq, event: action.event } });
|
|
176
|
+
break;
|
|
177
|
+
case "hang":
|
|
178
|
+
// 挂起至 cancel 收敛(无 cancel 则永久挂起——core 3s 收敛窗口超时杀链面)
|
|
179
|
+
await new Promise((resolveHang) => {
|
|
180
|
+
hangingRuns.set(runId, resolveHang);
|
|
181
|
+
});
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const KNOWN_METHODS = new Set([
|
|
190
|
+
"initialize", "probe", "run", "cancel", "interact", "read",
|
|
191
|
+
"listModels", "validateModel", "dispose", "ping",
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
const askUserResults = new Map(); // 反向请求 id → 最终结果帧②(交互面两阶段)
|
|
195
|
+
const hangingRuns = new Map(); // runId → settle()——cancel 收敛用(hang 动作挂起时登记)
|
|
196
|
+
const cancelledRuns = new Set(); // cancel 已收敛的 runId——后续脚本动作全部跳过
|
|
197
|
+
|
|
198
|
+
createInterface({ input: process.stdin }).on("line", (line) => {
|
|
199
|
+
if (line.trim() === "") return;
|
|
200
|
+
let frame;
|
|
201
|
+
try {
|
|
202
|
+
frame = JSON.parse(line);
|
|
203
|
+
} catch {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 帧②(core 对反向请求的应答):askUser 最终结果到达——回放层记录后继续。
|
|
208
|
+
// [W6] 数据面(roundLifecycle / recordId-delta)应答到达 → 回发 host/log 回声
|
|
209
|
+
// (core 侧「宿主确认收到」回执链闭合的观测锚;NDJSON 单连接有序,回声先于
|
|
210
|
+
// run 应答帧到达)。
|
|
211
|
+
if (typeof frame.id === "string") {
|
|
212
|
+
const echoLabel = ackEchoLabels.get(frame.id);
|
|
213
|
+
if (echoLabel !== undefined) {
|
|
214
|
+
ackEchoLabels.delete(frame.id);
|
|
215
|
+
reverseRequest(`rev-ack-${nextRequestId++}`, "host/log", {
|
|
216
|
+
level: "debug",
|
|
217
|
+
component: "fake",
|
|
218
|
+
message: `ack ${echoLabel}`,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
askUserResults.set(frame.id, frame.result ?? { unsupported: frame.error !== undefined });
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const { id, method, params } = frame;
|
|
226
|
+
if (MODE === "unknown_method" && !KNOWN_METHODS.has(method)) {
|
|
227
|
+
send({
|
|
228
|
+
id,
|
|
229
|
+
error: {
|
|
230
|
+
code: "engine_method_unknown",
|
|
231
|
+
message: `method "${method}" is not part of protocol v1`,
|
|
232
|
+
recovery: "Upgrade the engine package or align the protocol version.",
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
switch (method) {
|
|
239
|
+
case "initialize": {
|
|
240
|
+
if (PROTOCOL_VERSION !== fixture.protocolVersion) {
|
|
241
|
+
send({
|
|
242
|
+
id,
|
|
243
|
+
error: {
|
|
244
|
+
code: "engine_protocol_mismatch",
|
|
245
|
+
message: `engine speaks protocol v${PROTOCOL_VERSION}, core requested/handshake produced v${fixture.protocolVersion}`,
|
|
246
|
+
recovery: "Align the engine package version with the host.",
|
|
247
|
+
data: { engineVersion: PROTOCOL_VERSION, coreVersion: fixture.protocolVersion },
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
{
|
|
253
|
+
// [W6] chat gate 负向:env 覆写 capabilities.conversation(旧形态引擎
|
|
254
|
+
// manifest 无该 gate 位 → chat 请求同步拒的 initialize 面实证)。
|
|
255
|
+
const initResult = fixture.initialize.result;
|
|
256
|
+
const convOverride = process.env.FAKE_CAPABILITIES_CONVERSATION;
|
|
257
|
+
const result =
|
|
258
|
+
convOverride !== undefined && initResult.capabilities !== undefined
|
|
259
|
+
? {
|
|
260
|
+
...initResult,
|
|
261
|
+
capabilities: { ...initResult.capabilities, conversation: convOverride },
|
|
262
|
+
}
|
|
263
|
+
: initResult;
|
|
264
|
+
send({ id, result });
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
case "probe":
|
|
269
|
+
if (process.env.FAKE_PROBE_FAIL === "1" && fixture.probeFailure !== undefined) {
|
|
270
|
+
send({ id, result: fixture.probeFailure });
|
|
271
|
+
} else {
|
|
272
|
+
send({ id, result: fixture.probe.result });
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
case "listModels":
|
|
276
|
+
send({ id, result: fixture.listModels.result });
|
|
277
|
+
return;
|
|
278
|
+
case "validateModel":
|
|
279
|
+
send({ id, result: fixture.validateModel.result });
|
|
280
|
+
return;
|
|
281
|
+
case "interact":
|
|
282
|
+
send({ id, result: fixture.interact.result });
|
|
283
|
+
return;
|
|
284
|
+
case "read":
|
|
285
|
+
send({ id, result: fixture.read.result });
|
|
286
|
+
return;
|
|
287
|
+
case "ping":
|
|
288
|
+
case "dispose":
|
|
289
|
+
send({ id, result: { ok: true } });
|
|
290
|
+
if (method === "dispose") {
|
|
291
|
+
for (const g of grandchildren) g.kill("SIGTERM");
|
|
292
|
+
setImmediate(() => process.exit(0));
|
|
293
|
+
}
|
|
294
|
+
return;
|
|
295
|
+
case "cancel": {
|
|
296
|
+
// 受理应答 + 收敛在途挂起 run(3s 收敛窗口语义):挂起中的 playRunScript
|
|
297
|
+
// 以 cancelResult 终态应答回收(协议 cancel 契约:引擎须在窗口内收敛终态)。
|
|
298
|
+
send({ id, result: { ok: true } });
|
|
299
|
+
const runId = params?.runId;
|
|
300
|
+
const settle = hangingRuns.get(runId);
|
|
301
|
+
if (settle !== undefined) {
|
|
302
|
+
hangingRuns.delete(runId);
|
|
303
|
+
cancelledRuns.add(runId);
|
|
304
|
+
settle(); // 收敛:挂起解除,run 以 cancelResult 终态应答(脚本余项跳过)
|
|
305
|
+
}
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
case "run": {
|
|
309
|
+
if (MODE === "run_failed") {
|
|
310
|
+
send({
|
|
311
|
+
id,
|
|
312
|
+
error: {
|
|
313
|
+
code: "engine_run_failed",
|
|
314
|
+
message: "scripted run failure (redacted)",
|
|
315
|
+
recovery: "Inspect the task and retry.",
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const runId = params?.runId ?? "run-smoke-1";
|
|
321
|
+
// [W6] env 注入 script 前置段(沿 FAKE_RUN_HANG 先例;顺序 = 注入段 → fixture 段)。
|
|
322
|
+
const injected = [];
|
|
323
|
+
if (process.env.FAKE_RUN_STDERR_HANG === "1") {
|
|
324
|
+
injected.push(
|
|
325
|
+
{ op: "stderr", text: process.env.FAKE_STDERR_SAMPLE ?? "" },
|
|
326
|
+
{ op: "log", level: "info", component: "fake", message: "stderr-flushed" },
|
|
327
|
+
{ op: "hang" },
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
if (process.env.FAKE_RUN_LIFECYCLE === "1") {
|
|
331
|
+
injected.push(
|
|
332
|
+
// 三相位 × 双关联键(settled 带 usage;idle/failed 带 anchor;failed 带
|
|
333
|
+
// error{code,message}——isHostRoundLifecycleParams 的相位居留形状)。
|
|
334
|
+
{ op: "roundLifecycle", keyedBy: "runId", key: "run-smoke-1", phase: "settled", usage: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 } },
|
|
335
|
+
{ op: "roundLifecycle", keyedBy: "runId", key: "run-smoke-1", phase: "idle", anchor: { sessionRef: { sessionId: "sess-fixture" }, poolKey: "shared" } },
|
|
336
|
+
{ op: "roundLifecycle", keyedBy: "runId", key: "run-smoke-1", phase: "failed", error: { code: "engine_run_failed", message: "round failed (scripted)", recovery: "Inspect the task and retry." } },
|
|
337
|
+
{ op: "roundLifecycle", keyedBy: "recordId", key: "rec-chat-1", phase: "settled" },
|
|
338
|
+
{ op: "roundLifecycle", keyedBy: "recordId", key: "rec-chat-1", phase: "idle", anchor: { sessionRef: { sessionId: "sess-chat-1" }, poolKey: "shared" } },
|
|
339
|
+
{ op: "roundLifecycle", keyedBy: "recordId", key: "rec-chat-1", phase: "failed", error: { code: "engine_run_failed", message: "chat round failed (scripted)", recovery: "Inspect the task and retry." } },
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
if (process.env.FAKE_RUN_RECORD_DELTA === "1") {
|
|
343
|
+
injected.push({ op: "streamDelta", recordId: "rec-chat-1", delta: "chat-delta-not-routed-to-runId" });
|
|
344
|
+
}
|
|
345
|
+
const script = [...injected, ...(process.env.FAKE_RUN_HANG === "1"
|
|
346
|
+
? [{ op: "poolResolved", poolKey: "shared" }, { op: "hang" }]
|
|
347
|
+
: []), ...fixture.run.script];
|
|
348
|
+
playRunScript(runId, script)
|
|
349
|
+
.then(() => send({ id, result: cancelledRuns.has(runId)
|
|
350
|
+
? (fixture.run.cancelResult ?? {
|
|
351
|
+
handle: fixture.run.result.handle,
|
|
352
|
+
outcome: { content: "", error: "engine_run_failed: cancelled (fake)", exitCode: null, engineId: fixture.engineId },
|
|
353
|
+
})
|
|
354
|
+
: fixture.run.result }))
|
|
355
|
+
.catch((err) => {
|
|
356
|
+
send({ id, error: { code: "engine_run_failed", message: String(err), recovery: "Inspect the engine logs." } });
|
|
357
|
+
});
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
default:
|
|
361
|
+
send({
|
|
362
|
+
id,
|
|
363
|
+
error: {
|
|
364
|
+
code: "engine_method_unknown",
|
|
365
|
+
message: `unhandled method "${String(method)}"`,
|
|
366
|
+
recovery: "Align protocol versions.",
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// stdin EOF(宿主死亡)→ 自灭 + 收割同组后代(R9-1:一代子进程 + 组内后代零残留;
|
|
373
|
+
// 引擎自身 detached 后代不在收割覆盖范围——设计 §3.9 已接受代价)。
|
|
374
|
+
process.stdin.on("end", () => {
|
|
375
|
+
for (const g of grandchildren) g.kill("SIGKILL");
|
|
376
|
+
process.exit(0);
|
|
377
|
+
});
|