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