@zhushanwen/subagent-core 0.8.0 → 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.
Files changed (167) hide show
  1. package/dist/{chunk-OL5BK4VN.js → chunk-LZJOEDGQ.js} +455 -203
  2. package/dist/engine-discovery-scan-Da4Dkzsi.d.cts +818 -0
  3. package/dist/engine-discovery-scan-Da4Dkzsi.d.ts +818 -0
  4. package/dist/execution/engine/engine-discovery-scan.cjs +216 -155
  5. package/dist/execution/engine/engine-discovery-scan.d.cts +1 -2
  6. package/dist/execution/engine/engine-discovery-scan.d.ts +1 -2
  7. package/dist/execution/engine/engine-discovery-scan.js +1 -1
  8. package/dist/execution/relay-env.js +5 -4
  9. package/dist/index.cjs +7686 -5894
  10. package/dist/index.d.cts +1876 -1360
  11. package/dist/index.d.ts +1876 -1360
  12. package/dist/index.js +7048 -5493
  13. package/dist.bundle/index.cjs +7747 -5957
  14. package/package.json +4 -4
  15. package/src/__tests__/manifest-store.test.ts +16 -15
  16. package/src/__tests__/robustness-medium-batch1.test.ts +10 -14
  17. package/src/__tests__/robustness-medium-batch2.test.ts +7 -2
  18. package/src/execution/__tests__/alive-store.test.ts +117 -1
  19. package/src/execution/__tests__/batch-finalized.test.ts +206 -0
  20. package/src/execution/__tests__/chat-engine-routing.test.ts +117 -1
  21. package/src/execution/__tests__/{cold-resurrect.test.ts → cold-lookup.test.ts} +133 -33
  22. package/src/execution/__tests__/collect-coordinator-service.test.ts +7 -5
  23. package/src/execution/__tests__/conversation-continuation.test.ts +1452 -0
  24. package/src/execution/__tests__/delivery-methods.test.ts +90 -176
  25. package/src/execution/__tests__/dialog-queue.test.ts +70 -3
  26. package/src/execution/__tests__/dispose-manifest-recovery.test.ts +475 -0
  27. package/src/execution/__tests__/execute-and-await-worktree.test.ts +3 -3
  28. package/src/execution/__tests__/execute-nesting.test.ts +8 -5
  29. package/src/execution/__tests__/execution-record.test.ts +8 -148
  30. package/src/execution/__tests__/finalize-record.test.ts +295 -129
  31. package/src/execution/__tests__/get-record-for-action-restart.test.ts +21 -29
  32. package/src/execution/__tests__/helpers/fake-engine-port.ts +13 -68
  33. package/src/execution/__tests__/helpers/legacy-sidecar.ts +33 -0
  34. package/src/execution/__tests__/helpers/subagent-service-mocks.ts +9 -5
  35. package/src/execution/__tests__/idle-gc.test.ts +60 -0
  36. package/src/execution/__tests__/lifecycle-manager.test.ts +3 -254
  37. package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +43 -22
  38. package/src/execution/__tests__/model-config-service.test.ts +111 -0
  39. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +10 -6
  40. package/src/execution/__tests__/notify-ledger.test.ts +42 -1
  41. package/src/execution/__tests__/rebuild-indexes.test.ts +329 -0
  42. package/src/execution/__tests__/record-binding.test.ts +613 -0
  43. package/src/execution/__tests__/record-origin.test.ts +318 -0
  44. package/src/execution/__tests__/record-store-intent-api.test.ts +600 -0
  45. package/src/execution/__tests__/record-store-orphan-revive.test.ts +71 -3
  46. package/src/execution/__tests__/record-store.test.ts +72 -54
  47. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +8 -5
  48. package/src/execution/__tests__/round-supervisor-workflow-origin.test.ts +205 -0
  49. package/src/execution/__tests__/run-orchestration-write-lease.test.ts +293 -0
  50. package/src/execution/__tests__/run-orchestration.test.ts +199 -0
  51. package/src/execution/__tests__/session-file-gc.test.ts +35 -4
  52. package/src/execution/__tests__/session-reconstructor.test.ts +78 -0
  53. package/src/execution/__tests__/state-marker.test.ts +288 -0
  54. package/src/execution/__tests__/stream-sink-retirement.test.ts +8 -5
  55. package/src/execution/__tests__/subagent-actions-core.test.ts +67 -16
  56. package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +0 -1
  57. package/src/execution/__tests__/subagent-service-notify-gate.test.ts +27 -11
  58. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +17 -11
  59. package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +130 -53
  60. package/src/execution/__tests__/subagent-service.test.ts +17 -215
  61. package/src/execution/__tests__/subprocess-agent-runner-no-progress-killall.test.ts +138 -0
  62. package/src/execution/__tests__/subprocess-agent-runner.test.ts +105 -660
  63. package/src/execution/__tests__/sync-collect-recovery.test.ts +23 -16
  64. package/src/execution/__tests__/terminal-write-latency.test.ts +79 -0
  65. package/src/execution/__tests__/workflow-agent-dispatch.test.ts +782 -0
  66. package/src/execution/alive-store.ts +37 -28
  67. package/src/execution/{cold-resurrect.ts → cold-lookup.ts} +48 -45
  68. package/src/execution/config.ts +1 -1
  69. package/src/execution/conversation-continuation.ts +541 -0
  70. package/src/execution/dialog-queue.ts +60 -12
  71. package/src/execution/engine/__tests__/common/capability-gate.test.ts +1 -1
  72. package/src/execution/engine/__tests__/common/journal-wiring.test.ts +16 -1
  73. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +17 -51
  74. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +0 -5
  75. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +1 -1
  76. package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +5 -9
  77. package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +0 -3
  78. package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -3
  79. package/src/execution/engine/__tests__/model-prompt.test.ts +0 -3
  80. package/src/execution/engine/__tests__/registry.test.ts +0 -1
  81. package/src/execution/engine/__tests__/routing.test.ts +0 -1
  82. package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +0 -3
  83. package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +0 -3
  84. package/src/execution/engine/client/__tests__/engine-client-reap.test.ts +212 -0
  85. package/src/execution/engine/client/__tests__/mirror.test.ts +73 -1
  86. package/src/execution/engine/client/__tests__/protocol-closure.test.ts +2 -9
  87. package/src/execution/engine/client/__tests__/remote-engine.test.ts +46 -12
  88. package/src/execution/engine/client/engine-client.ts +81 -25
  89. package/src/execution/engine/client/mirror.ts +9 -0
  90. package/src/execution/engine/client/remote-engine.ts +52 -34
  91. package/src/execution/engine/client/reverse-router.ts +6 -27
  92. package/src/execution/engine/common/__tests__/run-signals.test.ts +79 -0
  93. package/src/execution/engine/common/capability-gate.ts +27 -0
  94. package/src/execution/engine/common/data-dir.ts +3 -2
  95. package/src/execution/engine/common/errors.ts +1 -1
  96. package/src/execution/engine/common/journal-wiring.ts +18 -9
  97. package/src/execution/engine/common/run-signals.ts +83 -0
  98. package/src/execution/engine/d8-compat.ts +1 -1
  99. package/src/execution/engine/host/__tests__/host-bridge.test.ts +3 -18
  100. package/src/execution/engine/host/host-bridge.ts +19 -41
  101. package/src/execution/engine/host/pi-host-binding.ts +5 -5
  102. package/src/execution/engine/port.ts +34 -54
  103. package/src/execution/engine/types.ts +11 -14
  104. package/src/execution/execution-record.ts +15 -47
  105. package/src/execution/finalize-record.ts +94 -197
  106. package/src/execution/idle-gc.ts +9 -3
  107. package/src/execution/lifecycle-manager.ts +25 -361
  108. package/src/execution/lifecycle-predicates.ts +22 -19
  109. package/src/execution/manifest-store.ts +40 -42
  110. package/src/execution/model-config-service.ts +1 -1
  111. package/src/execution/notifier.ts +39 -1
  112. package/src/execution/notify-host.ts +13 -4
  113. package/src/execution/record-entry.ts +20 -2
  114. package/src/execution/record-store.ts +925 -160
  115. package/src/execution/relay-env.ts +8 -3
  116. package/src/execution/round-supervisor/domain.ts +17 -5
  117. package/src/execution/round-supervisor/service-binding.test.ts +89 -53
  118. package/src/execution/round-supervisor/service-binding.ts +71 -21
  119. package/src/execution/round-supervisor/supervisor.ts +23 -9
  120. package/src/execution/service/record-access.ts +547 -0
  121. package/src/execution/service/record-lifecycle.ts +542 -0
  122. package/src/execution/service/run-orchestration.ts +1647 -0
  123. package/src/execution/service/service-bootstrap.ts +111 -0
  124. package/src/execution/service/service-constants.ts +27 -0
  125. package/src/execution/service/session-baselines.ts +401 -0
  126. package/src/execution/service/sync-collect-domain.ts +442 -0
  127. package/src/execution/service/workflow-dispatch.ts +567 -0
  128. package/src/execution/session-file-gc.ts +11 -8
  129. package/src/execution/session-reconstructor.ts +44 -1
  130. package/src/execution/sessions-index.ts +20 -3
  131. package/src/execution/settled-watchdog.ts +86 -43
  132. package/src/execution/state-marker.ts +516 -0
  133. package/src/execution/stream-sink.ts +1 -1
  134. package/src/execution/subagent-actions-core.ts +53 -31
  135. package/src/execution/subagent-service.ts +643 -2980
  136. package/src/execution/subprocess-agent-runner.ts +46 -323
  137. package/src/execution/types.ts +60 -43
  138. package/src/execution/ui-request-handler-factory.ts +5 -0
  139. package/src/execution/worktree-manager.ts +1 -1
  140. package/src/execution/worktree-registry.ts +1 -1
  141. package/src/index.ts +6 -5
  142. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +2 -3
  143. package/src/orchestration/__tests__/agent-call-stream.test.ts +24 -49
  144. package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +4 -4
  145. package/src/orchestration/__tests__/file-run-store.test.ts +5 -7
  146. package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +2 -3
  147. package/src/orchestration/__tests__/run-snapshot.test.ts +27 -43
  148. package/src/orchestration/__tests__/worker-message-pump-workflow-dispatch.test.ts +274 -0
  149. package/src/orchestration/execute-agent-call.ts +1 -1
  150. package/src/orchestration/file-run-store.ts +1 -1
  151. package/src/orchestration/models/ports.ts +20 -13
  152. package/src/orchestration/models/types.ts +11 -13
  153. package/src/orchestration/run-snapshot.ts +18 -22
  154. package/src/orchestration/worker-message-pump.ts +33 -57
  155. package/src/shared/atomic-write.ts +10 -8
  156. package/dist/chunk-T2SYBW3I.js +0 -24
  157. package/dist/engine-discovery-scan-BXLA8y-z.d.cts +0 -1624
  158. package/dist/engine-discovery-scan-BXLA8y-z.d.ts +0 -1624
  159. package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +0 -255
  160. package/src/execution/__tests__/finalized-marker.test.ts +0 -104
  161. package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
  162. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -488
  163. package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +0 -75
  164. package/src/execution/__tests__/tombstone-store.test.ts +0 -73
  165. package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +0 -230
  166. package/src/execution/finalized-marker.ts +0 -70
  167. 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
+ });