@zhushanwen/subagent-core 0.6.0 → 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-C3fE3R9x.d.cts → engine-discovery-scan-ocpM8FmI.d.cts} +770 -668
- package/dist/{types-C3fE3R9x.d.ts → engine-discovery-scan-ocpM8FmI.d.ts} +770 -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 +14045 -16059
- package/dist/index.d.cts +1035 -1579
- package/dist/index.d.ts +1035 -1579
- package/dist/index.js +9838 -13800
- package/dist.bundle/index.cjs +28875 -30323
- 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__/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-coordinator-service.test.ts +36 -47
- package/src/execution/__tests__/collect-mixed-dispatch.test.ts +20 -53
- 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 +20 -33
- package/src/execution/__tests__/gc-timer.test.ts +7 -22
- 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__/nested-visibility-env-propagation.test.ts +5 -2
- package/src/execution/__tests__/reconcile-sweep.test.ts +200 -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__/round-supervisor.test.ts +293 -0
- package/src/execution/__tests__/session-pending.test.ts +119 -17
- package/src/execution/__tests__/stream-sink-retirement.test.ts +10 -10
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +1 -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 +21 -36
- package/src/execution/__tests__/workflow-state-root.test.ts +232 -0
- package/src/execution/agent-registry.ts +6 -2
- 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/kill-chain.test.ts +7 -0
- package/src/execution/engine/__tests__/common/nesting-guard.test.ts +9 -3
- 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 +81 -54
- 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 +7 -2
- 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/finalize-record.ts +25 -0
- 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/record-store.ts +29 -2
- 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-service.ts +746 -400
- package/src/execution/subprocess-agent-runner.ts +16 -8
- package/src/execution/types.ts +41 -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__/execute-agent-call.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/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 -166
- 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
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// src/execution/engine/engines/pi/turn-limiter.ts
|
|
2
|
-
//
|
|
3
|
-
// soft/hard turn 限制器。maxTurns 到达 → steer 提醒收尾;
|
|
4
|
-
// graceTurns 后仍不结束 → abort。
|
|
5
|
-
|
|
6
|
-
/** steer 提醒消息:要求 agent 总结已完成/未完成/下一步,不得谎报完成。 */
|
|
7
|
-
const WRAP_UP_MESSAGE = [
|
|
8
|
-
"You have reached your turn limit. Wrap up now:",
|
|
9
|
-
"1. Summarize what you have completed (with evidence: file paths, command output).",
|
|
10
|
-
"2. List what remains undone and why.",
|
|
11
|
-
"3. State the single most important next step for whoever continues.",
|
|
12
|
-
"Do NOT claim the task is complete if any part remains unfinished.",
|
|
13
|
-
].join(" ");
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 预防性 wrap-up 提示(启动时注入 --append-system-prompt)。
|
|
17
|
-
*
|
|
18
|
-
* spawn 模式下 runSpawn 无法在达 maxTurns 时运行时注入 steer(pi `--mode json` 是
|
|
19
|
-
* single-shot,无 stdin 命令通道;见 session-runner.ts limiter 注释)。作为短期补偿,
|
|
20
|
-
* 在启动时预置此预防性指令,让 agent 在感知接近上限时主动收尾。
|
|
21
|
-
*
|
|
22
|
-
* 长期方案是切到 pi `--mode rpc`(支持运行时 steer 命令),见 follow-up。
|
|
23
|
-
*/
|
|
24
|
-
export const WRAP_UP_HINT = [
|
|
25
|
-
`You have a turn limit. As you sense you are approaching it, proactively wrap up:`,
|
|
26
|
-
"1. Summarize what you have completed (with evidence: file paths, command output).",
|
|
27
|
-
"2. List what remains undone and why.",
|
|
28
|
-
"3. State the single most important next step for whoever continues.",
|
|
29
|
-
"Do NOT claim the task is complete if any part remains unfinished.",
|
|
30
|
-
].join(" ");
|
|
31
|
-
|
|
32
|
-
/** turn limiter 配置。 */
|
|
33
|
-
export interface TurnLimiterOptions {
|
|
34
|
-
maxTurns: number;
|
|
35
|
-
graceTurns: number;
|
|
36
|
-
steer: (msg: string) => void;
|
|
37
|
-
abort: () => void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* soft/hard turn 限制。
|
|
42
|
-
*
|
|
43
|
-
* onTurnEnd(currentTurns):
|
|
44
|
-
* 已 aborted 或 maxTurns<=0(禁用)→ 直接 return
|
|
45
|
-
* currentTurns >= maxTurns 且未 steer → steer(WRAP_UP_MESSAGE)(仅一次)
|
|
46
|
-
* 已 steer 且 currentTurns >= maxTurns + graceTurns → abort()(仅一次)
|
|
47
|
-
*
|
|
48
|
-
* maxTurns<=0 表示不限(limit=Infinity,永不触发)。
|
|
49
|
-
* graceTurns<=0 时 steer 后下一 turn 即 abort。
|
|
50
|
-
*/
|
|
51
|
-
export interface TurnLimiter {
|
|
52
|
-
/** 每次 turn_end 调用。 */
|
|
53
|
-
onTurnEnd(currentTurns: number): void;
|
|
54
|
-
/**
|
|
55
|
-
* 重置 steered/aborted 标志(新一轮开始)。
|
|
56
|
-
*
|
|
57
|
-
* chatMode 下 agent_settled 时调用——每轮(message → agent_settled)独立计数,
|
|
58
|
-
* maxTurns 不跨轮累计(续聊本质是无限轮,累计上限违背 G1)。
|
|
59
|
-
* 非 chatMode 不调用,行为不变(全程累计)。
|
|
60
|
-
*/
|
|
61
|
-
reset(): void;
|
|
62
|
-
/** 是否已发过 steer(诊断用)。 */
|
|
63
|
-
readonly didSteer: boolean;
|
|
64
|
-
/** 是否已 abort(诊断用)。 */
|
|
65
|
-
readonly didAbort: boolean;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 工厂函数。 */
|
|
69
|
-
export function createTurnLimiter(opts: TurnLimiterOptions): TurnLimiter {
|
|
70
|
-
let steered = false;
|
|
71
|
-
let aborted = false;
|
|
72
|
-
const limit = opts.maxTurns > 0 ? opts.maxTurns : Infinity;
|
|
73
|
-
const grace = opts.graceTurns > 0 ? opts.graceTurns : 0;
|
|
74
|
-
|
|
75
|
-
const onTurnEnd = (turn: number): void => {
|
|
76
|
-
if (aborted || !Number.isFinite(limit)) return;
|
|
77
|
-
if (!steered && turn >= limit) {
|
|
78
|
-
steered = true;
|
|
79
|
-
opts.steer(WRAP_UP_MESSAGE);
|
|
80
|
-
}
|
|
81
|
-
if (steered && turn >= limit + grace) {
|
|
82
|
-
aborted = true;
|
|
83
|
-
opts.abort();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const reset = (): void => {
|
|
88
|
-
steered = false;
|
|
89
|
-
aborted = false;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
onTurnEnd,
|
|
94
|
-
reset,
|
|
95
|
-
get didSteer(): boolean {
|
|
96
|
-
return steered;
|
|
97
|
-
},
|
|
98
|
-
get didAbort(): boolean {
|
|
99
|
-
return aborted;
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* fake app-server(R2 连接层测试专用,绝不 spawn 真 zcode.cjs)。
|
|
3
|
-
*
|
|
4
|
-
* 移植改造自 zsw 仓 84b63a0^ z-subagent-workflow/fixtures/fake-appserver.js 的测试
|
|
5
|
-
* 模式(该仓只读参照),vitest 子进程形态(ESM——本仓 eslint 禁 require,CJS 形态
|
|
6
|
-
* 被 no-require-imports 拦截):启动方式与真协议对齐——由被测 AppServerConnection
|
|
7
|
-
* 以 `node <本文件> app-server --cwd <dir>` spawn(argv 解析后记录进流水,不消费)。
|
|
8
|
-
* stdio NDJSON,帧形态对齐设计附录 A.1(无 jsonrpc 字段)。
|
|
9
|
-
*
|
|
10
|
-
* 测试断言面 = FAKE_STATE_FILE 事件流水(append JSONL):
|
|
11
|
-
* boot / env / recv(收到的每个客户端帧)/ reverse-answer(反向请求收到的我方应答)
|
|
12
|
-
* / unparseable-from-client。env 开关随 spawn env 固化:
|
|
13
|
-
* FAKE_STATE_FILE 流水文件路径(未设则不记流水)
|
|
14
|
-
* FAKE_STDERR=1 启动时往 stderr 写两行(tee 落盘断言取证)
|
|
15
|
-
* FAKE_EXTRA_KEYS=1 我方应答/推送帧携带未知键(客户端宽容解析断言)
|
|
16
|
-
* FAKE_PROTOCOL_PUSH=1 协议自报走 {method:'protocol'} 推送形态(缺省走 A.1 首帧
|
|
17
|
-
* {protocol:{...}} 形态)
|
|
18
|
-
*
|
|
19
|
-
* 内置方法(可编程注入四帧型的全部形态):
|
|
20
|
-
* test/echo 应答 {id, result: params}(原样回显——并发 id 关联断言依据)
|
|
21
|
-
* test/delay-echo delayMs 后应答回显(制造在途请求)
|
|
22
|
-
* test/fail 应答 {id, error:{code,message,data}}(params 指定)
|
|
23
|
-
* test/push 先推一帧 {method: pushMethod, params: pushParams} 再应答
|
|
24
|
-
* test/reverse 发一个反向请求(method=params.reverseMethod)并等客户端
|
|
25
|
-
* 应答,流水记录后回 {id, result:{answered:true}}
|
|
26
|
-
* test/malformed-first 先写一行非 JSON 再正常应答(坏行跳过不断流断言)
|
|
27
|
-
* test/suicide stderr 写 600 字符噪声 + 标记后 exit(1)(崩溃收割断言)
|
|
28
|
-
* session/create 真实协议语义(A.2):先发反向请求 session/requestRuntime
|
|
29
|
-
* Preferences 并等客户端应答(D9 常量表断言依据),流水记录
|
|
30
|
-
* 后回 {session:{sessionId}}
|
|
31
|
-
* session/subscribe 应答 {subscribed:true}(R3;真实应答形状未知——会话层不校验)
|
|
32
|
-
* session/send 按 FAKE_SESSION_SCENARIO 推送帧序列后应答(缺省 {accepted:true})
|
|
33
|
-
* session/read 按 FAKE_SESSION_SCENARIO 应答(缺省 {messages:[]})
|
|
34
|
-
* session/close 应答 {closed:true}
|
|
35
|
-
* 其余方法 应答 -32601(method not found)
|
|
36
|
-
*
|
|
37
|
-
* 会话场景注入(R3 会话层测试;不设 = 各方法走缺省行为,R2 连接层测试不受影响):
|
|
38
|
-
* FAKE_SESSION_SCENARIO=<path> 启动时读取一次的 JSON 文件:
|
|
39
|
-
* {
|
|
40
|
-
* createResult?: object 覆盖 create 应答(golden create 应答注入)
|
|
41
|
-
* createError?: {code,message,data} create 应答 error 帧(-32602/-32601 注入)
|
|
42
|
-
* sendError?: {code,message,data} send 应答 error 帧(-32010/-32602 注入)
|
|
43
|
-
* sendPushes?: [frame, ...] send 应答前逐帧推送(推送流 + 终态帧全显式
|
|
44
|
-
* 逐字回放,不经 withExtra 改写)
|
|
45
|
-
* sendResult?: object 缺省 {accepted:true}
|
|
46
|
-
* crashAfterSendMs?: number [P0-1 U4] send 应答后 N ms 自杀 exit(1)(连接
|
|
47
|
-
* 崩溃收割注入——onClose → failAllTurns 在途
|
|
48
|
-
* turn 收割;进程死 → 下次 request 惰性重建
|
|
49
|
-
* boot 新代重读 scenario,重试轮/下一任务形态
|
|
50
|
-
* 切换经测试侧 rewriteScenario)
|
|
51
|
-
* rebootSendPushes?: [frame, ...] [P0-1 U4] 非首代进程(本 fake 启动时 state 流水
|
|
52
|
-
* 已有 boot 记录——崩溃/杀链后的重建代)的 send
|
|
53
|
-
* 推送序列,替代 sendPushes:崩溃后惰性重建的
|
|
54
|
-
* 重试轮拿到不同行为(如完整终态流)——首轮挂起
|
|
55
|
-
* + 重试轮成功的静态注入通道(同任务重试轮无法
|
|
56
|
-
* 经测试侧 rewriteScenario 插手,run 整体 await)
|
|
57
|
-
* readError?: {code,message,data} read 应答 error 帧(read 兜底降级链断言)
|
|
58
|
-
* readResult?: object 覆盖 read 应答
|
|
59
|
-
* stopBehavior?: 'terminal'|'none'|'hang'
|
|
60
|
-
* session/stop 的行为(R4 abort 链断言面):
|
|
61
|
-
* 'terminal'(缺省)= stop 时推送该会话的
|
|
62
|
-
* turn.terminal 终态帧(stop 优雅生效——不杀
|
|
63
|
-
* 进程的 abort 路径);'none' = 只应答不推终态
|
|
64
|
-
* (grace 窗口耗尽 → killChain 兜底路径);
|
|
65
|
-
* 'hang' = 连应答都不给(P0-1 U2 超时入口态③——
|
|
66
|
-
* 控制面假死注入,stop 3s 超时 → 连接级失败判据)
|
|
67
|
-
* stopError?: {code,message,data} stop 应答 error 帧(P0-1 U2 超时入口态②——
|
|
68
|
-
* 协议性 error(如会话已回收)注入,断言不升级杀链)
|
|
69
|
-
* }
|
|
70
|
-
*
|
|
71
|
-
* 多会话支持(R4 引擎接线 / RA3 双会话地基):
|
|
72
|
-
* FAKE_STAMP_SESSION=1 session/send 的推送帧回放时把 params.sessionId 统一改写
|
|
73
|
-
* 为「当前 send 的目标会话」,telemetry 帧(无 sid)补记
|
|
74
|
-
* sessionId——并发两会话各自收到归因正确的推送流,不串线。
|
|
75
|
-
* (缺省关:R2/R3 单会话用例的字节级行为不变。)
|
|
76
|
-
* session/stop 应答 {stopped:true};按 scenario.stopBehavior 决定是否
|
|
77
|
-
* 推送终态帧(见上)。stopTerminal 推送同样受 STAMP 改写。
|
|
78
|
-
*/
|
|
79
|
-
import fs from 'node:fs';
|
|
80
|
-
import readline from 'node:readline';
|
|
81
|
-
|
|
82
|
-
const STATE_FILE = process.env.FAKE_STATE_FILE;
|
|
83
|
-
const EXTRA_KEYS = process.env.FAKE_EXTRA_KEYS === '1';
|
|
84
|
-
const PROTOCOL_AS_PUSH = process.env.FAKE_PROTOCOL_PUSH === '1';
|
|
85
|
-
// [R4] 多会话推送改写开关(见文件头注释)
|
|
86
|
-
const STAMP_SESSION = process.env.FAKE_STAMP_SESSION === '1';
|
|
87
|
-
|
|
88
|
-
// 会话场景(R3):启动时读取一次(env 固化语义与其他 FAKE_ 开关一致)
|
|
89
|
-
let SCENARIO = null;
|
|
90
|
-
if (process.env.FAKE_SESSION_SCENARIO) {
|
|
91
|
-
try {
|
|
92
|
-
SCENARIO = JSON.parse(fs.readFileSync(process.env.FAKE_SESSION_SCENARIO, 'utf8'));
|
|
93
|
-
} catch (err) {
|
|
94
|
-
log('scenario-load-failed', { message: String(err && err.message) });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// [P0-1 U4] 本进程代数(state 流水已有 boot 记录数 + 1):崩溃/杀链后的惰性重建代
|
|
99
|
-
// ≥2——rebootSendPushes 仅对重建代生效(重试轮拿到与首轮不同的推送序列)
|
|
100
|
-
let BOOT_GEN = 1;
|
|
101
|
-
if (STATE_FILE && SCENARIO && SCENARIO.rebootSendPushes) {
|
|
102
|
-
try {
|
|
103
|
-
const priorBoots = fs
|
|
104
|
-
.readFileSync(STATE_FILE, 'utf8')
|
|
105
|
-
.split('\n')
|
|
106
|
-
.filter((l) => l.includes('"ev":"boot"')).length;
|
|
107
|
-
BOOT_GEN = priorBoots + 1;
|
|
108
|
-
} catch { /* 流水读失败按首代处理 */ }
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let seq = 0;
|
|
112
|
-
function log(ev, data = {}) {
|
|
113
|
-
if (!STATE_FILE) return;
|
|
114
|
-
try {
|
|
115
|
-
fs.appendFileSync(STATE_FILE, JSON.stringify({ seq: ++seq, ev, ...data }) + '\n');
|
|
116
|
-
} catch { /* 流水写失败不影响协议行为 */ }
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const out = (frame) => process.stdout.write(`${JSON.stringify(frame)}\n`);
|
|
120
|
-
const withExtra = (frame) => (EXTRA_KEYS ? { ...frame, unknownServerKey: 'lenient' } : frame);
|
|
121
|
-
const reply = (id, result) => out(withExtra({ id, result }));
|
|
122
|
-
const replyErr = (id, code, message, data) =>
|
|
123
|
-
out({ id, error: { code, message, ...(data !== undefined ? { data } : {}) } });
|
|
124
|
-
|
|
125
|
-
// 协议自报(A.1:首帧 {protocol:{...}};推送形态显式开关——两种到达形态都要被忽略)
|
|
126
|
-
if (PROTOCOL_AS_PUSH) out({ method: 'protocol', params: { name: 'ZCode Protocol', version: 1 } });
|
|
127
|
-
else out({ protocol: { name: 'ZCode Protocol', version: 1 } });
|
|
128
|
-
|
|
129
|
-
// SIGTERM 优雅窗口:默认终止会丢弃「已写入管道但尚未读到」的帧——延迟退出让
|
|
130
|
-
// stdin 排空后收尾(dispose 的 close-帧-先于-SIGTERM 顺序在本侧可观测:
|
|
131
|
-
// killChain 的 grace 远大于本窗口,不会升级 SIGKILL)
|
|
132
|
-
process.on('SIGTERM', () => {
|
|
133
|
-
setTimeout(() => process.exit(0), 100);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// env 快照 + boot 流水(惰性启动 / argv 形态 / env 惯例断言的数据源)
|
|
137
|
-
log('env', {
|
|
138
|
-
pid: process.pid,
|
|
139
|
-
home: process.env.HOME,
|
|
140
|
-
telemetry: process.env.ZCODE_MODEL_TELEMETRY_ENABLED,
|
|
141
|
-
nested: process.env.ZSW_NESTED,
|
|
142
|
-
unifiedNested: process.env.XYZ_AGENT_SUBAGENT,
|
|
143
|
-
});
|
|
144
|
-
log('boot', { pid: process.pid, argv: process.argv.slice(2) });
|
|
145
|
-
if (process.env.FAKE_STDERR === '1') {
|
|
146
|
-
process.stderr.write('fake-appserver stderr line A\nfake-appserver stderr line B\n');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// 反向请求记账:id -> 客户端应答到达时 resolve
|
|
150
|
-
let reqSeq = 0;
|
|
151
|
-
const pendingReverse = new Map();
|
|
152
|
-
|
|
153
|
-
function sendReverse(method, params) {
|
|
154
|
-
return new Promise((resolve) => {
|
|
155
|
-
const id = `srv-${++reqSeq}`;
|
|
156
|
-
pendingReverse.set(id, resolve);
|
|
157
|
-
out({ id, method, ...(params !== undefined ? { params } : {}) });
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function onClientAnswer(frame) {
|
|
162
|
-
const settle = pendingReverse.get(frame.id);
|
|
163
|
-
if (settle) {
|
|
164
|
-
pendingReverse.delete(frame.id);
|
|
165
|
-
settle({ id: frame.id, result: frame.result, error: frame.error });
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// 推送帧回放(scenario 帧即 golden 语料/注入形态本身,不走 withExtra)。STAMP_SESSION
|
|
170
|
-
// 开启时统一改写/补记 params.sessionId 为目标会话(RA3 双会话地基:并发两会话各自
|
|
171
|
-
// 收到归因正确的推送流——真服务端推送本就按会话归因,telemetry 帧不带 sid 属协议
|
|
172
|
-
// 实测形态,stamp 是 fake 侧的确定性等价物)。
|
|
173
|
-
function pushFrames(frames, targetSessionId) {
|
|
174
|
-
for (const frame of frames || []) {
|
|
175
|
-
if (!STAMP_SESSION || !targetSessionId) {
|
|
176
|
-
out(frame);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
const stamped = JSON.parse(JSON.stringify(frame));
|
|
180
|
-
if (stamped && typeof stamped.params === 'object' && stamped.params !== null) {
|
|
181
|
-
stamped.params.sessionId = targetSessionId;
|
|
182
|
-
}
|
|
183
|
-
out(stamped);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// [R4] stop 触发的终态推送(stopBehavior 缺省 'terminal'——abort 优雅生效路径)
|
|
188
|
-
const TURN_TERMINAL_FRAME = {
|
|
189
|
-
method: 'v4/telemetry/event',
|
|
190
|
-
params: { kind: 'turn.terminal', status: 'success' },
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
async function handleRequest(f) {
|
|
194
|
-
const { id, method } = f;
|
|
195
|
-
const params = f.params ?? {};
|
|
196
|
-
switch (method) {
|
|
197
|
-
case 'test/echo':
|
|
198
|
-
return reply(id, params);
|
|
199
|
-
case 'test/delay-echo': {
|
|
200
|
-
const delay = Number(params.delayMs) || 50;
|
|
201
|
-
setTimeout(() => reply(id, params), delay);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
case 'test/fail':
|
|
205
|
-
return replyErr(id, Number(params.code) || -32603, String(params.message || 'fake failure'), params.data);
|
|
206
|
-
case 'test/push': {
|
|
207
|
-
const pushMethod = String(params.pushMethod || 'test/notification');
|
|
208
|
-
out(withExtra({ method: pushMethod, ...(params.pushParams !== undefined ? { params: params.pushParams } : {}) }));
|
|
209
|
-
return reply(id, { pushed: true });
|
|
210
|
-
}
|
|
211
|
-
case 'test/reverse': {
|
|
212
|
-
const answer = await sendReverse(String(params.reverseMethod || 'permission/request'), params.reverseParams);
|
|
213
|
-
log('reverse-answer', { requested: params.reverseMethod, answer });
|
|
214
|
-
return reply(id, { answered: true });
|
|
215
|
-
}
|
|
216
|
-
case 'test/malformed-first':
|
|
217
|
-
process.stdout.write('this is not json {{{\n');
|
|
218
|
-
return reply(id, { survived: true });
|
|
219
|
-
case 'test/suicide':
|
|
220
|
-
process.stderr.write('A'.repeat(600) + 'CRASH-MARK-TAIL');
|
|
221
|
-
process.exit(1);
|
|
222
|
-
return; // 不可达(exit 先行),保持 switch 完整
|
|
223
|
-
case 'session/create': {
|
|
224
|
-
if (SCENARIO && SCENARIO.createError) {
|
|
225
|
-
return replyErr(id, SCENARIO.createError.code, SCENARIO.createError.message, SCENARIO.createError.data);
|
|
226
|
-
}
|
|
227
|
-
const answer = await sendReverse('session/requestRuntimePreferences');
|
|
228
|
-
log('reverse-answer', { requested: 'session/requestRuntimePreferences', answer });
|
|
229
|
-
if (SCENARIO && SCENARIO.createResult) return reply(id, SCENARIO.createResult);
|
|
230
|
-
return reply(id, { session: { sessionId: `sess_${id}` } });
|
|
231
|
-
}
|
|
232
|
-
case 'session/subscribe':
|
|
233
|
-
return reply(id, (SCENARIO && SCENARIO.subscribeResult) || { subscribed: true });
|
|
234
|
-
case 'session/send': {
|
|
235
|
-
if (SCENARIO && SCENARIO.sendError) {
|
|
236
|
-
return replyErr(id, SCENARIO.sendError.code, SCENARIO.sendError.message, SCENARIO.sendError.data);
|
|
237
|
-
}
|
|
238
|
-
// 推送帧逐字回放(STAMP_SESSION 时按目标会话归因改写);重建代走 rebootSendPushes
|
|
239
|
-
// (U4:重试轮的不同行为通道)
|
|
240
|
-
const pushes =
|
|
241
|
-
BOOT_GEN > 1 && SCENARIO && SCENARIO.rebootSendPushes
|
|
242
|
-
? SCENARIO.rebootSendPushes
|
|
243
|
-
: SCENARIO && SCENARIO.sendPushes;
|
|
244
|
-
pushFrames(pushes, String(params.sessionId || ''));
|
|
245
|
-
// [P0-1 U4] 崩溃收割注入:应答后 N ms 自杀(onClose → failAllTurns 在途 turn
|
|
246
|
-
// 收割的确定性触发面;exit(1) 非零码与 test/suicide 同形态)
|
|
247
|
-
const crashAfterSendMs = SCENARIO && SCENARIO.crashAfterSendMs;
|
|
248
|
-
if (typeof crashAfterSendMs === 'number' && crashAfterSendMs >= 0) {
|
|
249
|
-
setTimeout(() => {
|
|
250
|
-
log('crash-injected', { afterMs: crashAfterSendMs });
|
|
251
|
-
process.exit(1);
|
|
252
|
-
}, crashAfterSendMs).unref();
|
|
253
|
-
}
|
|
254
|
-
return reply(id, (SCENARIO && SCENARIO.sendResult) || { accepted: true });
|
|
255
|
-
}
|
|
256
|
-
case 'session/stop': {
|
|
257
|
-
// [R4] abort 链断言面:缺省推终态(stop 优雅生效);stopBehavior:'none' 只应答;
|
|
258
|
-
// stopError 注入协议性 error 应答帧(P0-1 U2 态②——不升级杀链判据);
|
|
259
|
-
// stopBehavior:'hang' 永不应答(态③——stop 3s 超时 = 连接级失败判据)
|
|
260
|
-
const behavior = (SCENARIO && SCENARIO.stopBehavior) || 'terminal';
|
|
261
|
-
if (behavior === 'hang') return;
|
|
262
|
-
if (SCENARIO && SCENARIO.stopError) {
|
|
263
|
-
return replyErr(id, SCENARIO.stopError.code, SCENARIO.stopError.message, SCENARIO.stopError.data);
|
|
264
|
-
}
|
|
265
|
-
if (behavior === 'terminal') {
|
|
266
|
-
pushFrames([TURN_TERMINAL_FRAME], String(params.sessionId || ''));
|
|
267
|
-
}
|
|
268
|
-
return reply(id, { stopped: true });
|
|
269
|
-
}
|
|
270
|
-
case 'session/read': {
|
|
271
|
-
if (SCENARIO && SCENARIO.readError) {
|
|
272
|
-
return replyErr(id, SCENARIO.readError.code, SCENARIO.readError.message, SCENARIO.readError.data);
|
|
273
|
-
}
|
|
274
|
-
return reply(id, (SCENARIO && SCENARIO.readResult) || { messages: [] });
|
|
275
|
-
}
|
|
276
|
-
case 'session/close':
|
|
277
|
-
return reply(id, { closed: true });
|
|
278
|
-
default:
|
|
279
|
-
return replyErr(id, -32601, `method not found: ${method}`);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const rl = readline.createInterface({ input: process.stdin });
|
|
284
|
-
rl.on('line', (line) => {
|
|
285
|
-
const text = String(line).trim();
|
|
286
|
-
if (!text) return;
|
|
287
|
-
let f;
|
|
288
|
-
try {
|
|
289
|
-
f = JSON.parse(text);
|
|
290
|
-
} catch {
|
|
291
|
-
log('unparseable-from-client', { line: text.slice(0, 100) });
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
log('recv', { frame: f });
|
|
295
|
-
if (f && f.id != null && typeof f.method === 'string') {
|
|
296
|
-
void handleRequest(f);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (f && f.id != null) onClientAnswer(f); // 我方反向请求的客户端应答
|
|
300
|
-
});
|
|
301
|
-
rl.on('close', () => process.exit(0));
|
package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_meta": {
|
|
3
|
-
"description": "zcode app-server 常驻通道 golden 帧序列语料(R3)。四类样本:create 应答 / 推送流 / 终态帧 / read 应答(NDJSON 逐行,附录 A.2 任务生命周期帧序)",
|
|
4
|
-
"source": "synthesized-from-A2-protocol-authority",
|
|
5
|
-
"synthesisNote": "非真机实录——按设计附录 A.2(协议权威,zcode.cjs 0.16.5 二进制字符串级验证命中)+ 旧 zsw 实现真机抓包形态(zsw 仓 84b63a0^ runner-appserver.js 实测注释)合成。真机冒烟(RA 跨仓段)后应替换为实录并同步双副本。telemetry 帧不带 sessionId(A.2 未标)——归因走唯一在途兜底;session/event 帧带 sessionId",
|
|
6
|
-
"engineVersion": "0.16.5 (app-server)",
|
|
7
|
-
"protocolVersion": 1,
|
|
8
|
-
"recordedAt": "2026-08-30",
|
|
9
|
-
"invariants": {
|
|
10
|
-
"textIdentity": "pushStream 中 payload.delta 拼接 === terminal 收尾帧 payload.response === readResponse 最后 assistant 消息 text parts 拼接('你好,任务完成')——不变量 1 双来源",
|
|
11
|
-
"usage": "收尾帧 usage {inputTokens:12599, outputTokens:17} 与 spawn golden(zcode-golden-spawn.json)同值——漂移对照锚点"
|
|
12
|
-
},
|
|
13
|
-
"frames": {
|
|
14
|
-
"createResponse": "session/create 应答帧(NDJSON 单行)。projection.sessionId 恒 \"unknown\"(勿用),权威位置 session.sessionId",
|
|
15
|
-
"pushStream": "推送流帧(A.2 ④ 逐行):state.updated 进入 running / v4 telemetry stream.chunk(无文本,chunkLength 遥测)/ session/event payload.delta(实时文本增量)",
|
|
16
|
-
"terminal": "终态帧(A.2 ⑤ 逐行):v4 telemetry turn.terminal(终态权威,status 枚举)+ session/event 收尾帧(全文 + usage)",
|
|
17
|
-
"readResponse": "session/read 应答帧(NDJSON 单行,A.2 ⑥):messages[].info.role + parts[](text 全文 / step-finish tokens——tokens 结构属 A.5 未确认项,宽容解析)"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"frames": {
|
|
21
|
-
"createResponse": "{\"session\":{\"sessionId\":\"sess_golden_r3_01\"},\"projection\":{\"sessionId\":\"unknown\",\"status\":\"idle\",\"turnCount\":0,\"totalTokenCount\":0,\"contextUsed\":0,\"contextWindow\":1000000}}",
|
|
22
|
-
"pushStream": [
|
|
23
|
-
"{\"method\":\"state.updated\",\"params\":{\"sessionId\":\"sess_golden_r3_01\",\"patch\":{\"status\":\"running\"},\"reason\":\"prompt_started\"}}",
|
|
24
|
-
"{\"method\":\"v4/telemetry/event\",\"params\":{\"kind\":\"stream.chunk\",\"channel\":\"text\",\"chunkLength\":6,\"firstChunk\":true,\"assistantMessageId\":\"msg_golden_r3_01\"}}",
|
|
25
|
-
"{\"method\":\"session/event\",\"params\":{\"sessionId\":\"sess_golden_r3_01\",\"payload\":{\"delta\":\"你好\",\"assistantMessageId\":\"msg_golden_r3_01\"}}}",
|
|
26
|
-
"{\"method\":\"v4/telemetry/event\",\"params\":{\"kind\":\"stream.chunk\",\"channel\":\"text\",\"chunkLength\":1,\"firstChunk\":false,\"assistantMessageId\":\"msg_golden_r3_01\"}}",
|
|
27
|
-
"{\"method\":\"session/event\",\"params\":{\"sessionId\":\"sess_golden_r3_01\",\"payload\":{\"delta\":\",\",\"assistantMessageId\":\"msg_golden_r3_01\"}}}",
|
|
28
|
-
"{\"method\":\"session/event\",\"params\":{\"sessionId\":\"sess_golden_r3_01\",\"payload\":{\"delta\":\"任务完成\",\"assistantMessageId\":\"msg_golden_r3_01\"}}}"
|
|
29
|
-
],
|
|
30
|
-
"terminal": [
|
|
31
|
-
"{\"method\":\"v4/telemetry/event\",\"params\":{\"kind\":\"turn.terminal\",\"status\":\"success\"}}",
|
|
32
|
-
"{\"method\":\"session/event\",\"params\":{\"sessionId\":\"sess_golden_r3_01\",\"payload\":{\"response\":\"你好,任务完成\",\"usage\":{\"inputTokens\":12599,\"outputTokens\":17}}}}"
|
|
33
|
-
],
|
|
34
|
-
"readResponse": "{\"messages\":[{\"info\":{\"role\":\"user\"},\"parts\":[{\"type\":\"text\",\"text\":\"做点什么\"}]},{\"info\":{\"role\":\"assistant\"},\"parts\":[{\"type\":\"text\",\"text\":\"你好\"},{\"type\":\"text\",\"text\":\",任务完成\"},{\"type\":\"step-finish\",\"tokens\":{\"input\":12599,\"output\":17,\"reasoning\":0,\"cache\":512,\"total\":12616}}]}]}"
|
|
35
|
-
}
|
|
36
|
-
}
|