@zhushanwen/subagent-core 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-VURUAGMM.js → chunk-LZJOEDGQ.js} +603 -154
- package/dist/engine-discovery-scan-Da4Dkzsi.d.cts +818 -0
- package/dist/engine-discovery-scan-Da4Dkzsi.d.ts +818 -0
- package/dist/execution/engine/engine-discovery-scan.cjs +325 -154
- package/dist/execution/engine/engine-discovery-scan.d.cts +1 -2
- package/dist/execution/engine/engine-discovery-scan.d.ts +1 -2
- package/dist/execution/engine/engine-discovery-scan.js +1 -1
- package/dist/execution/relay-env.js +5 -4
- package/dist/index.cjs +9799 -7954
- package/dist/index.d.cts +1896 -1360
- package/dist/index.d.ts +1896 -1360
- package/dist/index.js +8952 -7513
- package/dist.bundle/index.cjs +7897 -6054
- package/package.json +5 -5
- package/src/__tests__/manifest-store.test.ts +16 -15
- package/src/__tests__/record-store-last-line.test.ts +12 -0
- package/src/__tests__/robustness-medium-batch1.test.ts +10 -14
- package/src/__tests__/robustness-medium-batch2.test.ts +7 -2
- package/src/core/logger.ts +1 -1
- package/src/execution/__tests__/alive-store.test.ts +117 -1
- package/src/execution/__tests__/batch-finalized.test.ts +206 -0
- package/src/execution/__tests__/chat-engine-routing.test.ts +117 -1
- package/src/execution/__tests__/{cold-resurrect.test.ts → cold-lookup.test.ts} +133 -33
- package/src/execution/__tests__/collect-coordinator-service.test.ts +7 -5
- package/src/execution/__tests__/conversation-continuation.test.ts +1452 -0
- package/src/execution/__tests__/delivery-methods.test.ts +90 -176
- package/src/execution/__tests__/dialog-queue.test.ts +70 -3
- package/src/execution/__tests__/dispose-manifest-recovery.test.ts +475 -0
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +3 -3
- package/src/execution/__tests__/execute-nesting.test.ts +8 -5
- package/src/execution/__tests__/execution-record.test.ts +8 -148
- package/src/execution/__tests__/finalize-record.test.ts +295 -129
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +21 -29
- package/src/execution/__tests__/helpers/fake-engine-port.ts +13 -68
- package/src/execution/__tests__/helpers/legacy-sidecar.ts +33 -0
- package/src/execution/__tests__/helpers/subagent-service-mocks.ts +9 -5
- package/src/execution/__tests__/idle-gc.test.ts +60 -0
- package/src/execution/__tests__/inflight-production-wiring.test.ts +223 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +3 -254
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +43 -22
- package/src/execution/__tests__/model-config-service.test.ts +111 -0
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +10 -6
- package/src/execution/__tests__/nested-visibility.test.ts +13 -1
- package/src/execution/__tests__/notify-ledger.test.ts +42 -1
- package/src/execution/__tests__/rebuild-indexes.test.ts +329 -0
- package/src/execution/__tests__/record-binding.test.ts +613 -0
- package/src/execution/__tests__/record-origin.test.ts +318 -0
- package/src/execution/__tests__/record-store-intent-api.test.ts +600 -0
- package/src/execution/__tests__/record-store-orphan-revive.test.ts +71 -3
- package/src/execution/__tests__/record-store.test.ts +72 -54
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +8 -5
- package/src/execution/__tests__/round-supervisor-workflow-origin.test.ts +205 -0
- package/src/execution/__tests__/run-orchestration-write-lease.test.ts +293 -0
- package/src/execution/__tests__/run-orchestration.test.ts +199 -0
- package/src/execution/__tests__/session-file-gc.test.ts +35 -4
- package/src/execution/__tests__/session-reconstructor.test.ts +78 -0
- package/src/execution/__tests__/state-marker.test.ts +288 -0
- package/src/execution/__tests__/stream-sink-retirement.test.ts +8 -5
- package/src/execution/__tests__/subagent-actions-core.test.ts +67 -16
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +0 -1
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +27 -11
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +17 -11
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +130 -53
- package/src/execution/__tests__/subagent-service.test.ts +17 -215
- package/src/execution/__tests__/subprocess-agent-runner-no-progress-killall.test.ts +138 -0
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +105 -660
- package/src/execution/__tests__/sync-collect-recovery.test.ts +23 -16
- package/src/execution/__tests__/terminal-write-latency.test.ts +79 -0
- package/src/execution/__tests__/workflow-agent-dispatch.test.ts +782 -0
- package/src/execution/alive-store.ts +37 -28
- package/src/execution/{cold-resurrect.ts → cold-lookup.ts} +48 -45
- package/src/execution/config.ts +1 -1
- package/src/execution/conversation-continuation.ts +541 -0
- package/src/execution/dialog-queue.ts +60 -12
- package/src/execution/engine/__tests__/common/capability-gate.test.ts +1 -1
- package/src/execution/engine/__tests__/common/journal-wiring.test.ts +16 -1
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +17 -51
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +0 -5
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +1 -1
- package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +5 -9
- package/src/execution/engine/__tests__/conformance/registry-fork-filter.test.ts +55 -53
- package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +0 -3
- package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -3
- package/src/execution/engine/__tests__/inflight-snapshot.test.ts +180 -0
- package/src/execution/engine/__tests__/model-prompt.test.ts +0 -3
- package/src/execution/engine/__tests__/registry.test.ts +0 -1
- package/src/execution/engine/__tests__/routing.test.ts +0 -1
- package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +0 -3
- package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +0 -3
- package/src/execution/engine/client/__tests__/engine-client-reap.test.ts +212 -0
- package/src/execution/engine/client/__tests__/mirror.test.ts +73 -1
- package/src/execution/engine/client/__tests__/protocol-closure.test.ts +2 -9
- package/src/execution/engine/client/__tests__/remote-engine.test.ts +46 -12
- package/src/execution/engine/client/engine-client.ts +111 -26
- package/src/execution/engine/client/mirror.ts +9 -0
- package/src/execution/engine/client/remote-engine.ts +52 -34
- package/src/execution/engine/client/reverse-router.ts +6 -27
- package/src/execution/engine/common/__tests__/run-signals.test.ts +79 -0
- package/src/execution/engine/common/capability-gate.ts +27 -0
- package/src/execution/engine/common/data-dir.ts +3 -2
- package/src/execution/engine/common/errors.ts +1 -1
- package/src/execution/engine/common/journal-wiring.ts +18 -9
- package/src/execution/engine/common/run-signals.ts +83 -0
- package/src/execution/engine/d8-compat.ts +1 -1
- package/src/execution/engine/host/__tests__/host-bridge.test.ts +3 -18
- package/src/execution/engine/host/host-bridge.ts +26 -41
- package/src/execution/engine/host/pi-host-binding.ts +5 -5
- package/src/execution/engine/host/spawned-children.ts +1 -1
- package/src/execution/engine/inflight-snapshot.ts +92 -0
- package/src/execution/engine/port.ts +52 -54
- package/src/execution/engine/types.ts +11 -14
- package/src/execution/execution-record.ts +15 -47
- package/src/execution/finalize-record.ts +94 -197
- package/src/execution/idle-gc.ts +9 -3
- package/src/execution/lifecycle-manager.ts +25 -361
- package/src/execution/lifecycle-predicates.ts +22 -19
- package/src/execution/manifest-store.ts +40 -42
- package/src/execution/model-config-service.ts +1 -1
- package/src/execution/notifier.ts +39 -1
- package/src/execution/notify-host.ts +13 -4
- package/src/execution/path-encoding.ts +6 -0
- package/src/execution/record-entry.ts +20 -2
- package/src/execution/record-store.ts +925 -160
- package/src/execution/relay-env.ts +8 -3
- package/src/execution/round-supervisor/domain.ts +17 -5
- package/src/execution/round-supervisor/service-binding.test.ts +89 -53
- package/src/execution/round-supervisor/service-binding.ts +71 -21
- package/src/execution/round-supervisor/supervisor.ts +23 -9
- package/src/execution/service/record-access.ts +547 -0
- package/src/execution/service/record-lifecycle.ts +542 -0
- package/src/execution/service/run-orchestration.ts +1647 -0
- package/src/execution/service/service-bootstrap.ts +111 -0
- package/src/execution/service/service-constants.ts +27 -0
- package/src/execution/service/session-baselines.ts +401 -0
- package/src/execution/service/sync-collect-domain.ts +442 -0
- package/src/execution/service/workflow-dispatch.ts +567 -0
- package/src/execution/session-file-gc.ts +11 -8
- package/src/execution/session-reconstructor.ts +44 -1
- package/src/execution/sessions-index.ts +20 -3
- package/src/execution/settled-watchdog.ts +86 -43
- package/src/execution/state-marker.ts +516 -0
- package/src/execution/stream-sink.ts +1 -1
- package/src/execution/subagent-actions-core.ts +53 -31
- package/src/execution/subagent-service.ts +643 -2955
- package/src/execution/subprocess-agent-runner.ts +46 -323
- package/src/execution/types.ts +60 -43
- package/src/execution/ui-request-handler-factory.ts +5 -0
- package/src/execution/worktree-manager.ts +1 -1
- package/src/execution/worktree-registry.ts +12 -8
- package/src/index.ts +16 -5
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +2 -3
- package/src/orchestration/__tests__/agent-call-stream.test.ts +24 -49
- package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +4 -4
- package/src/orchestration/__tests__/file-run-store.test.ts +5 -7
- package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +2 -3
- package/src/orchestration/__tests__/run-snapshot.test.ts +27 -43
- package/src/orchestration/__tests__/worker-message-pump-workflow-dispatch.test.ts +274 -0
- package/src/orchestration/execute-agent-call.ts +1 -1
- package/src/orchestration/file-run-store.ts +1 -1
- package/src/orchestration/models/ports.ts +20 -13
- package/src/orchestration/models/types.ts +11 -13
- package/src/orchestration/run-snapshot.ts +18 -22
- package/src/orchestration/worker-message-pump.ts +33 -57
- package/src/shared/atomic-write.ts +10 -8
- package/dist/chunk-T2SYBW3I.js +0 -24
- package/dist/engine-discovery-scan-ocpM8FmI.d.cts +0 -1608
- package/dist/engine-discovery-scan-ocpM8FmI.d.ts +0 -1608
- package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +0 -255
- package/src/execution/__tests__/finalized-marker.test.ts +0 -104
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -488
- package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +0 -75
- package/src/execution/__tests__/tombstone-store.test.ts +0 -73
- package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +0 -230
- package/src/execution/finalized-marker.ts +0 -70
- package/src/execution/tombstone-store.ts +0 -72
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// src/execution/__tests__/subprocess-agent-runner-no-progress-killall.test.ts
|
|
2
|
+
//
|
|
3
|
+
// [M3 决策 9 / V5c] killAll 组杀邻接(真引擎进程,集成层)。
|
|
4
|
+
//
|
|
5
|
+
// 被测语义:M3 fire 的 abort 并入 mergedSignal 后走 RemoteEngine 既有 wireAbortSignal
|
|
6
|
+
// 阶梯——引擎对 cancel 帧 >收敛窗无响应 → killAll 组杀引擎 CLI → 同引擎其余在途 run
|
|
7
|
+
// 全部以 engine_crashed error 终态化(G1 字面保持:有终态 + executeAgentCall 可重试),
|
|
8
|
+
// 无悬挂。
|
|
9
|
+
//
|
|
10
|
+
// 与 V5① 的分工(如实声明):
|
|
11
|
+
// - V5①(fake timers,单测)锁「30min 窗口到点 → watchdog abort」的计时链路;
|
|
12
|
+
// - 本文件锁「watchdog abort(= fire 的同步动作)→ mergedSignal → 阶梯 → killAll →
|
|
13
|
+
// 邻接 run 终态」的进程链路。mid-round 窗是原语内纯常量、无 env/测试 seam 可缩短
|
|
14
|
+
// (K6 结论),真引擎进程无法与 fake timers 混跑,故此处直接驱动 watchdog 的
|
|
15
|
+
// AbortController(即 fire 回调内的唯一同步动作,逐字等价)。
|
|
16
|
+
//
|
|
17
|
+
// 对端 sessionDir = mkdtempSync 自建自删(禁碰真实数据目录)。
|
|
18
|
+
|
|
19
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
23
|
+
|
|
24
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
25
|
+
|
|
26
|
+
import { EngineClient } from "../engine/client/engine-client.ts";
|
|
27
|
+
import { RemoteEngine, type RemoteEngineManifestSnapshot } from "../engine/client/remote-engine.ts";
|
|
28
|
+
import { mergeRunSignals } from "../subprocess-agent-runner.ts";
|
|
29
|
+
|
|
30
|
+
const FAKE_ENGINE = fileURLToPath(
|
|
31
|
+
new URL("../engine/client/__tests__/__fixtures__/fake-engine.mjs", import.meta.url),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
/** 与 fake 引擎 initialize 应答逐位一致(gate 位多声明判定「一致放行」基线)。 */
|
|
35
|
+
const FAKE_MATCHED_CAPS = {
|
|
36
|
+
schemaEnforcement: "emulated",
|
|
37
|
+
steer: "unsupported",
|
|
38
|
+
conversation: "unsupported",
|
|
39
|
+
personaInjection: "prompt",
|
|
40
|
+
eventGranularity: "stream",
|
|
41
|
+
sandbox: "emulated",
|
|
42
|
+
sessionRead: "full",
|
|
43
|
+
resume: "cold",
|
|
44
|
+
interrupt: "kill-only",
|
|
45
|
+
permissionMode: "fixed",
|
|
46
|
+
maxTurns: false,
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
/** run 动作脚本:长 delay 保持两路 run 在途(cancel 不做收敛,考验 3s 收敛窗后的杀链)。 */
|
|
50
|
+
const HANG_RUN_ACTIONS = JSON.stringify([{ op: "delay", ms: 30_000 }]);
|
|
51
|
+
|
|
52
|
+
async function waitForTrue(predicate: () => boolean, timeoutMs = 8_000, stepMs = 25): Promise<void> {
|
|
53
|
+
const deadline = Date.now() + timeoutMs;
|
|
54
|
+
while (Date.now() < deadline) {
|
|
55
|
+
if (predicate()) return;
|
|
56
|
+
await new Promise((resolve) => setTimeout(resolve, stepMs));
|
|
57
|
+
}
|
|
58
|
+
throw new Error("waitForTrue: condition not met within timeout");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** fake 引擎收到 run 帧后回显的 run-params 事件(run 已派发的确定性同步点)。 */
|
|
62
|
+
function sawRunParams(events: unknown[]): boolean {
|
|
63
|
+
return events.some(
|
|
64
|
+
(e) =>
|
|
65
|
+
(e as { type?: string; message?: string }).type === "error" &&
|
|
66
|
+
typeof (e as { message?: string }).message === "string" &&
|
|
67
|
+
(e as { message: string }).message.startsWith("run-params:"),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("M3 V5c killAll 组杀邻接", () => {
|
|
72
|
+
let dataDir = "";
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
dataDir = mkdtempSync(join(tmpdir(), "m3-v5c-"));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
rmSync(dataDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("watchdog fire(引擎对 cancel 无响应)→ killAll → 邻接 run 以 engine_crashed 收敛,无悬挂", async () => {
|
|
83
|
+
const client = new EngineClient({
|
|
84
|
+
engineId: "fake",
|
|
85
|
+
command: process.execPath,
|
|
86
|
+
args: [FAKE_ENGINE, "--run-actions", HANG_RUN_ACTIONS],
|
|
87
|
+
hostKind: "test",
|
|
88
|
+
dataDir,
|
|
89
|
+
envPrefixes: [],
|
|
90
|
+
});
|
|
91
|
+
const manifest: RemoteEngineManifestSnapshot = {
|
|
92
|
+
capabilities: { ...FAKE_MATCHED_CAPS },
|
|
93
|
+
};
|
|
94
|
+
const engine = new RemoteEngine({ engineId: "fake", client, dataDir, hostKind: "test", manifest });
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const eventsA: unknown[] = [];
|
|
98
|
+
const eventsB: unknown[] = [];
|
|
99
|
+
// M3 形态的合并 signal:外部 run 级 signal(永不 abort)+ watchdog abort 源。
|
|
100
|
+
const watchdog = new AbortController();
|
|
101
|
+
const mergedA = mergeRunSignals(new AbortController().signal, undefined, watchdog.signal);
|
|
102
|
+
|
|
103
|
+
const runA = engine.run(
|
|
104
|
+
{ prompt: "wedged" },
|
|
105
|
+
{ taskId: "run-a", poolKey: "shared", signal: mergedA.signal, onEvent: (e) => eventsA.push(e) },
|
|
106
|
+
);
|
|
107
|
+
const runB = engine.run(
|
|
108
|
+
{ prompt: "healthy" },
|
|
109
|
+
{
|
|
110
|
+
taskId: "run-b",
|
|
111
|
+
poolKey: "shared",
|
|
112
|
+
signal: new AbortController().signal,
|
|
113
|
+
onEvent: (e) => eventsB.push(e),
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// 两路 run 帧均已到达引擎(确定性同步点)后触发 fire
|
|
118
|
+
await waitForTrue(() => sawRunParams(eventsA) && sawRunParams(eventsB));
|
|
119
|
+
watchdog.abort();
|
|
120
|
+
|
|
121
|
+
const [a, b] = await Promise.all([runA, runB]);
|
|
122
|
+
|
|
123
|
+
// 被 fire 的 run:cancel 未收敛 → 杀链 → 合成 abort 终态(不 reject)
|
|
124
|
+
expect(a.outcome.error).toContain("aborted before terminal answer");
|
|
125
|
+
expect(a.outcome.exitCode).toBeNull();
|
|
126
|
+
expect(a.handle.data.engineId).toBe("fake");
|
|
127
|
+
|
|
128
|
+
// 邻接 healthy run:killAll 组杀连带 → engine_crashed error 终态(G1:有终态 + 可重试)
|
|
129
|
+
expect(b.outcome.error).toContain("engine_crashed");
|
|
130
|
+
expect(b.outcome.exitCode).toBeNull();
|
|
131
|
+
expect(b.handle.data.engineId).toBe("fake");
|
|
132
|
+
|
|
133
|
+
mergedA.dispose();
|
|
134
|
+
} finally {
|
|
135
|
+
await client.dispose().catch(() => {});
|
|
136
|
+
}
|
|
137
|
+
}, 20_000);
|
|
138
|
+
});
|