chatccc 0.2.226 → 0.2.227

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 (64) hide show
  1. package/.agents/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  2. package/.claude/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  3. package/.cursor/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  4. package/README.md +90 -90
  5. package/package.json +1 -1
  6. package/src/__tests__/agent-activity.test.ts +76 -76
  7. package/src/__tests__/builtin-chat-session.test.ts +350 -350
  8. package/src/__tests__/builtin-config.test.ts +26 -26
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +275 -275
  11. package/src/__tests__/builtin-permissions.test.ts +211 -211
  12. package/src/__tests__/builtin-session-select.test.ts +116 -116
  13. package/src/__tests__/builtin-skills.test.ts +185 -74
  14. package/src/__tests__/card-action-routing.test.ts +18 -18
  15. package/src/__tests__/ccc-adapter.test.ts +136 -136
  16. package/src/__tests__/claude-adapter.test.ts +614 -614
  17. package/src/__tests__/codex-adapter.test.ts +58 -58
  18. package/src/__tests__/codex-raw-stream-log.test.ts +170 -170
  19. package/src/__tests__/cursor-adapter.test.ts +268 -268
  20. package/src/__tests__/feishu-avatar.test.ts +164 -164
  21. package/src/__tests__/feishu-message-ingress.test.ts +138 -138
  22. package/src/__tests__/package-files.test.ts +24 -24
  23. package/src/__tests__/progress-reducer.test.ts +110 -110
  24. package/src/__tests__/response-stall.test.ts +49 -49
  25. package/src/__tests__/sim-platform.test.ts +16 -16
  26. package/src/__tests__/startup-lifecycle.test.ts +231 -231
  27. package/src/__tests__/stop-session.test.ts +34 -34
  28. package/src/__tests__/terminal-renderer.test.ts +247 -247
  29. package/src/__tests__/update-command-guard.test.ts +144 -144
  30. package/src/__tests__/web-ui.test.ts +326 -326
  31. package/src/adapters/adapter-interface.ts +18 -18
  32. package/src/adapters/ccc-adapter.ts +131 -131
  33. package/src/adapters/claude-adapter.ts +620 -620
  34. package/src/adapters/codex-adapter.ts +426 -426
  35. package/src/adapters/cursor-adapter.ts +681 -681
  36. package/src/agent-activity.ts +170 -170
  37. package/src/agent-delegate-task.ts +91 -91
  38. package/src/builtin/cli.ts +61 -2
  39. package/src/builtin/config.ts +84 -84
  40. package/src/builtin/context.ts +323 -323
  41. package/src/builtin/file-log.ts +38 -38
  42. package/src/builtin/index.ts +44 -24
  43. package/src/builtin/proc-tree-kill.ts +61 -61
  44. package/src/builtin/progress/cards-helpers.ts +76 -76
  45. package/src/builtin/progress/reducer.ts +108 -108
  46. package/src/builtin/progress/terminal-renderer.ts +294 -294
  47. package/src/builtin/progress/view.ts +77 -77
  48. package/src/builtin/raw-stream-log.ts +124 -124
  49. package/src/builtin/session-select.ts +48 -48
  50. package/src/builtin/skills.ts +126 -44
  51. package/src/card-action-routing.ts +14 -14
  52. package/src/feishu-api.ts +193 -193
  53. package/src/feishu-message-ingress.ts +195 -195
  54. package/src/index.ts +306 -306
  55. package/src/orchestrator.ts +2388 -2388
  56. package/src/platform-adapter.ts +6 -6
  57. package/src/progress/reducer.ts +108 -108
  58. package/src/progress/terminal-renderer.ts +294 -294
  59. package/src/progress/view.ts +77 -77
  60. package/src/response-stall.ts +28 -28
  61. package/src/session-chat-binding.ts +82 -82
  62. package/src/startup-lifecycle.ts +250 -250
  63. package/src/stream-state.ts +18 -18
  64. package/src/update-command-guard.ts +165 -165
@@ -2,9 +2,9 @@ import { describe, it, expect } from "vitest";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { join, dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
- import {
6
- buildCodexInvocationArgs,
7
- normalizeCodexMessage,
5
+ import {
6
+ buildCodexInvocationArgs,
7
+ normalizeCodexMessage,
8
8
  createCodexAdapter,
9
9
  type CreateCodexAdapterOptions,
10
10
  } from "../adapters/codex-adapter.ts";
@@ -15,21 +15,21 @@ import {
15
15
  } from "../adapters/codex-session-meta-store.ts";
16
16
  import { accumulateBlockContent, pickFinalReply, type AccumulatorState } from "../session.ts";
17
17
 
18
- const __dirname = dirname(fileURLToPath(import.meta.url));
19
-
20
- describe("buildCodexInvocationArgs", () => {
21
- it("forces the priority service tier when Fast mode is on", () => {
22
- expect(buildCodexInvocationArgs(["exec", "--json"], "", "", true)).toContain(
23
- 'service_tier="fast"',
24
- );
25
- });
26
-
27
- it("forces the standard service tier when Fast mode is off", () => {
28
- const args = buildCodexInvocationArgs(["exec", "--json"], "", "", false);
29
- expect(args).toContain('service_tier="default"');
30
- expect(args).not.toContain('service_tier="fast"');
31
- });
32
- });
18
+ const __dirname = dirname(fileURLToPath(import.meta.url));
19
+
20
+ describe("buildCodexInvocationArgs", () => {
21
+ it("forces the priority service tier when Fast mode is on", () => {
22
+ expect(buildCodexInvocationArgs(["exec", "--json"], "", "", true)).toContain(
23
+ 'service_tier="fast"',
24
+ );
25
+ });
26
+
27
+ it("forces the standard service tier when Fast mode is off", () => {
28
+ const args = buildCodexInvocationArgs(["exec", "--json"], "", "", false);
29
+ expect(args).toContain('service_tier="default"');
30
+ expect(args).not.toContain('service_tier="fast"');
31
+ });
32
+ });
33
33
 
34
34
  function readFixture(name: string): unknown[] {
35
35
  const raw = readFileSync(join(__dirname, "fixtures", name), "utf-8");
@@ -71,16 +71,16 @@ function createInMemoryMetaStore(
71
71
  // ---------------------------------------------------------------------------
72
72
 
73
73
  describe("normalizeCodexMessage", () => {
74
- it("normalizes agent_message into assistant text block", () => {
75
- const result = normalizeCodexMessage({
76
- type: "item.completed",
77
- item: { id: "item_0", type: "agent_message", text: "hello" },
74
+ it("normalizes agent_message into assistant text block", () => {
75
+ const result = normalizeCodexMessage({
76
+ type: "item.completed",
77
+ item: { id: "item_0", type: "agent_message", text: "hello" },
78
78
  });
79
- expect(result).not.toBeNull();
80
- expect(result!.type).toBe("assistant");
81
- expect(result!.blocks).toEqual([{ type: "text", text: "hello" }]);
82
- expect(result!.isFinalResponse).toBeUndefined();
83
- });
79
+ expect(result).not.toBeNull();
80
+ expect(result!.type).toBe("assistant");
81
+ expect(result!.blocks).toEqual([{ type: "text", text: "hello" }]);
82
+ expect(result!.isFinalResponse).toBeUndefined();
83
+ });
84
84
 
85
85
  it("normalizes command_execution start into tool_use block", () => {
86
86
  const result = normalizeCodexMessage({
@@ -92,12 +92,12 @@ describe("normalizeCodexMessage", () => {
92
92
  status: "in_progress",
93
93
  },
94
94
  });
95
- expect(result).not.toBeNull();
96
- expect(result!.type).toBe("assistant");
97
- expect(result!.blocks).toEqual([
98
- { type: "tool_use", id: "item_0", name: "Bash", input: { command: "powershell.exe -Command ls" } },
99
- ]);
100
- });
95
+ expect(result).not.toBeNull();
96
+ expect(result!.type).toBe("assistant");
97
+ expect(result!.blocks).toEqual([
98
+ { type: "tool_use", id: "item_0", name: "Bash", input: { command: "powershell.exe -Command ls" } },
99
+ ]);
100
+ });
101
101
 
102
102
  it("normalizes command_execution completion as tool_result (success)", () => {
103
103
  const result = normalizeCodexMessage({
@@ -158,17 +158,17 @@ describe("normalizeCodexMessage", () => {
158
158
  expect(normalizeCodexMessage({ type: "turn.started" })).toBeNull();
159
159
  });
160
160
 
161
- it("marks turn.completed as the authoritative final response", () => {
162
- expect(
163
- normalizeCodexMessage({
164
- type: "turn.completed",
165
- usage: { input_tokens: 100, output_tokens: 50 },
166
- }),
167
- ).toEqual({
168
- type: "assistant",
169
- blocks: [],
170
- isFinalResponse: true,
171
- });
161
+ it("marks turn.completed as the authoritative final response", () => {
162
+ expect(
163
+ normalizeCodexMessage({
164
+ type: "turn.completed",
165
+ usage: { input_tokens: 100, output_tokens: 50 },
166
+ }),
167
+ ).toEqual({
168
+ type: "assistant",
169
+ blocks: [],
170
+ isFinalResponse: true,
171
+ });
172
172
  });
173
173
 
174
174
  it("returns null for unknown event types", () => {
@@ -244,7 +244,7 @@ describe("Codex stream fixtures", () => {
244
244
  expect(state.accumulatedContent).toContain("tool_test");
245
245
  });
246
246
 
247
- it("with tool: 普通输出不标终态,只有 turn.completed 标记终态", () => {
247
+ it("with tool: 普通输出不标终态,只有 turn.completed 标记终态", () => {
248
248
  const lines = readFixture("codex_with_tool.jsonl");
249
249
  const messages: UnifiedStreamMessage[] = [];
250
250
  for (const raw of lines) {
@@ -254,18 +254,18 @@ describe("Codex stream fixtures", () => {
254
254
  if (normalized) messages.push(normalized);
255
255
  }
256
256
 
257
- // 应有: tool_use + tool_result + text + turn.completed = 4 条消息
258
- expect(messages.length).toBe(4);
259
- expect(messages[0].blocks[0].type).toBe("tool_use");
260
- expect(messages[1].blocks[0].type).toBe("tool_result");
261
- expect(messages[2].blocks[0].type).toBe("text");
262
- expect(messages[2].isFinalResponse).toBeUndefined();
263
- expect(messages[3]).toEqual({
264
- type: "assistant",
265
- blocks: [],
266
- isFinalResponse: true,
267
- });
268
- });
257
+ // 应有: tool_use + tool_result + text + turn.completed = 4 条消息
258
+ expect(messages.length).toBe(4);
259
+ expect(messages[0].blocks[0].type).toBe("tool_use");
260
+ expect(messages[1].blocks[0].type).toBe("tool_result");
261
+ expect(messages[2].blocks[0].type).toBe("text");
262
+ expect(messages[2].isFinalResponse).toBeUndefined();
263
+ expect(messages[3]).toEqual({
264
+ type: "assistant",
265
+ blocks: [],
266
+ isFinalResponse: true,
267
+ });
268
+ });
269
269
  });
270
270
 
271
271
  // ---------------------------------------------------------------------------
@@ -328,4 +328,4 @@ describe("createCodexAdapter", () => {
328
328
  });
329
329
  expect(await adapter.getSessionInfo("sid-C")).toBeUndefined();
330
330
  });
331
- });
331
+ });
@@ -1,170 +1,170 @@
1
- import { EventEmitter } from "node:events";
2
- import { PassThrough } from "node:stream";
3
-
4
- import { afterEach, describe, expect, it, vi } from "vitest";
5
-
6
- const spawnMock = vi.hoisted(() => vi.fn());
7
- const createRawStreamLogMock = vi.hoisted(() => vi.fn());
8
- const rawLogWriteLineMock = vi.hoisted(() => vi.fn());
9
- const rawLogCloseMock = vi.hoisted(() => vi.fn());
10
- const killProcessTreeMock = vi.hoisted(() => vi.fn(async () => {}));
11
-
12
- vi.mock("node:child_process", () => ({
13
- spawn: spawnMock,
14
- }));
15
-
16
- vi.mock("../adapters/raw-stream-log.ts", () => ({
17
- createRawStreamLog: createRawStreamLogMock,
18
- }));
19
-
20
- vi.mock("../adapters/proc-tree-kill.ts", () => ({
21
- killProcessTree: killProcessTreeMock,
22
- }));
23
-
24
- import { config } from "../config.ts";
25
- import { createCodexAdapter } from "../adapters/codex-adapter.ts";
26
- import { BadJsonIdleTimeoutError } from "../adapters/jsonl-stream.ts";
27
- import type { CodexSessionMetaStore } from "../adapters/codex-session-meta-store.ts";
28
-
29
- const originalRawStreamLogs = structuredClone(config.rawStreamLogs);
30
-
31
- function createProc(lines: string[]): EventEmitter & {
32
- stdout: PassThrough;
33
- stderr: PassThrough;
34
- stdin: PassThrough;
35
- pid: number;
36
- } {
37
- const proc = new EventEmitter() as EventEmitter & {
38
- stdout: PassThrough;
39
- stderr: PassThrough;
40
- stdin: PassThrough;
41
- pid: number;
42
- };
43
- proc.stdout = new PassThrough();
44
- proc.stderr = new PassThrough();
45
- proc.stdin = new PassThrough();
46
- proc.pid = 4242;
47
- queueMicrotask(() => {
48
- for (const line of lines) proc.stdout.write(`${line}\n`);
49
- proc.stdout.end();
50
- proc.stderr.end();
51
- proc.emit("close", 0);
52
- });
53
- return proc;
54
- }
55
-
56
- function createHangingProc(lines: string[]): EventEmitter & {
57
- stdout: PassThrough;
58
- stderr: PassThrough;
59
- stdin: PassThrough;
60
- pid: number;
61
- } {
62
- const proc = new EventEmitter() as EventEmitter & {
63
- stdout: PassThrough;
64
- stderr: PassThrough;
65
- stdin: PassThrough;
66
- pid: number;
67
- };
68
- proc.stdout = new PassThrough();
69
- proc.stderr = new PassThrough();
70
- proc.stdin = new PassThrough();
71
- proc.pid = 4242;
72
- queueMicrotask(() => {
73
- for (const line of lines) proc.stdout.write(`${line}\n`);
74
- });
75
- return proc;
76
- }
77
-
78
- async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
79
- const events: unknown[] = [];
80
- for await (const event of iterable) events.push(event);
81
- return events;
82
- }
83
-
84
- function metaStore(): CodexSessionMetaStore {
85
- return {
86
- async get(sessionId) {
87
- return sessionId === "sid-raw" ? { cwd: "F:/project" } : undefined;
88
- },
89
- async set() {},
90
- async setThreadId() {},
91
- };
92
- }
93
-
94
- afterEach(() => {
95
- vi.useRealTimers();
96
- spawnMock.mockReset();
97
- createRawStreamLogMock.mockReset();
98
- rawLogWriteLineMock.mockReset();
99
- rawLogCloseMock.mockReset();
100
- killProcessTreeMock.mockClear();
101
- config.rawStreamLogs = structuredClone(originalRawStreamLogs);
102
- });
103
-
104
- describe("Codex raw stream logs", () => {
105
- it("writes raw Codex JSONL stdout lines when enabled", async () => {
106
- const lines = [
107
- JSON.stringify({ type: "thread.started", thread_id: "thread-1" }),
108
- JSON.stringify({ type: "item.completed", item: { id: "item-1", type: "agent_message", text: "hello" } }),
109
- JSON.stringify({ type: "turn.completed" }),
110
- ];
111
- spawnMock.mockReturnValueOnce(createProc(lines));
112
- createRawStreamLogMock.mockResolvedValueOnce({
113
- filePath: "codex.jsonl.gz",
114
- writeLine: rawLogWriteLineMock,
115
- close: rawLogCloseMock,
116
- });
117
- config.rawStreamLogs.codex = {
118
- enabled: true,
119
- maxBytesPerTurn: 2048,
120
- retentionDays: 2,
121
- keepCompleted: false,
122
- };
123
-
124
- const adapter = createCodexAdapter({ metaStore: metaStore() });
125
- const events = await collect(adapter.prompt("sid-raw", "hi", "F:/project"));
126
-
127
- expect(createRawStreamLogMock).toHaveBeenCalledWith(expect.objectContaining({
128
- enabled: true,
129
- tool: "codex",
130
- sessionId: "sid-raw",
131
- label: "prompt",
132
- maxBytesPerTurn: 2048,
133
- retentionDays: 2,
134
- }));
135
- expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(1, lines[0]);
136
- expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(2, lines[1]);
137
- expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(3, lines[2]);
138
- expect(rawLogCloseMock).toHaveBeenCalledWith({ keep: false });
139
- expect(events).toEqual([
140
- {
141
- type: "assistant",
142
- blocks: [{ type: "text", text: "hello" }],
143
- },
144
- {
145
- type: "assistant",
146
- blocks: [],
147
- isFinalResponse: true,
148
- },
149
- ]);
150
- });
151
-
152
- it("fails the turn and kills the process tree when bad JSON is followed by idle stdout", async () => {
153
- vi.useFakeTimers();
154
- spawnMock.mockReturnValueOnce(createHangingProc([
155
- "{\"type\":\"item.started\",\"item\":{\"type\":\"command_execution\"",
156
- ]));
157
- createRawStreamLogMock.mockResolvedValueOnce(null);
158
-
159
- const adapter = createCodexAdapter({ metaStore: metaStore() });
160
- const pending = collect(adapter.prompt("sid-raw", "hi", "F:/project"))
161
- .catch((error: unknown) => error);
162
-
163
- await Promise.resolve();
164
- await vi.advanceTimersByTimeAsync(120_000);
165
-
166
- const error = await pending;
167
- expect(error).toBeInstanceOf(BadJsonIdleTimeoutError);
168
- expect(killProcessTreeMock).toHaveBeenCalledWith(4242);
169
- });
170
- });
1
+ import { EventEmitter } from "node:events";
2
+ import { PassThrough } from "node:stream";
3
+
4
+ import { afterEach, describe, expect, it, vi } from "vitest";
5
+
6
+ const spawnMock = vi.hoisted(() => vi.fn());
7
+ const createRawStreamLogMock = vi.hoisted(() => vi.fn());
8
+ const rawLogWriteLineMock = vi.hoisted(() => vi.fn());
9
+ const rawLogCloseMock = vi.hoisted(() => vi.fn());
10
+ const killProcessTreeMock = vi.hoisted(() => vi.fn(async () => {}));
11
+
12
+ vi.mock("node:child_process", () => ({
13
+ spawn: spawnMock,
14
+ }));
15
+
16
+ vi.mock("../adapters/raw-stream-log.ts", () => ({
17
+ createRawStreamLog: createRawStreamLogMock,
18
+ }));
19
+
20
+ vi.mock("../adapters/proc-tree-kill.ts", () => ({
21
+ killProcessTree: killProcessTreeMock,
22
+ }));
23
+
24
+ import { config } from "../config.ts";
25
+ import { createCodexAdapter } from "../adapters/codex-adapter.ts";
26
+ import { BadJsonIdleTimeoutError } from "../adapters/jsonl-stream.ts";
27
+ import type { CodexSessionMetaStore } from "../adapters/codex-session-meta-store.ts";
28
+
29
+ const originalRawStreamLogs = structuredClone(config.rawStreamLogs);
30
+
31
+ function createProc(lines: string[]): EventEmitter & {
32
+ stdout: PassThrough;
33
+ stderr: PassThrough;
34
+ stdin: PassThrough;
35
+ pid: number;
36
+ } {
37
+ const proc = new EventEmitter() as EventEmitter & {
38
+ stdout: PassThrough;
39
+ stderr: PassThrough;
40
+ stdin: PassThrough;
41
+ pid: number;
42
+ };
43
+ proc.stdout = new PassThrough();
44
+ proc.stderr = new PassThrough();
45
+ proc.stdin = new PassThrough();
46
+ proc.pid = 4242;
47
+ queueMicrotask(() => {
48
+ for (const line of lines) proc.stdout.write(`${line}\n`);
49
+ proc.stdout.end();
50
+ proc.stderr.end();
51
+ proc.emit("close", 0);
52
+ });
53
+ return proc;
54
+ }
55
+
56
+ function createHangingProc(lines: string[]): EventEmitter & {
57
+ stdout: PassThrough;
58
+ stderr: PassThrough;
59
+ stdin: PassThrough;
60
+ pid: number;
61
+ } {
62
+ const proc = new EventEmitter() as EventEmitter & {
63
+ stdout: PassThrough;
64
+ stderr: PassThrough;
65
+ stdin: PassThrough;
66
+ pid: number;
67
+ };
68
+ proc.stdout = new PassThrough();
69
+ proc.stderr = new PassThrough();
70
+ proc.stdin = new PassThrough();
71
+ proc.pid = 4242;
72
+ queueMicrotask(() => {
73
+ for (const line of lines) proc.stdout.write(`${line}\n`);
74
+ });
75
+ return proc;
76
+ }
77
+
78
+ async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
79
+ const events: unknown[] = [];
80
+ for await (const event of iterable) events.push(event);
81
+ return events;
82
+ }
83
+
84
+ function metaStore(): CodexSessionMetaStore {
85
+ return {
86
+ async get(sessionId) {
87
+ return sessionId === "sid-raw" ? { cwd: "F:/project" } : undefined;
88
+ },
89
+ async set() {},
90
+ async setThreadId() {},
91
+ };
92
+ }
93
+
94
+ afterEach(() => {
95
+ vi.useRealTimers();
96
+ spawnMock.mockReset();
97
+ createRawStreamLogMock.mockReset();
98
+ rawLogWriteLineMock.mockReset();
99
+ rawLogCloseMock.mockReset();
100
+ killProcessTreeMock.mockClear();
101
+ config.rawStreamLogs = structuredClone(originalRawStreamLogs);
102
+ });
103
+
104
+ describe("Codex raw stream logs", () => {
105
+ it("writes raw Codex JSONL stdout lines when enabled", async () => {
106
+ const lines = [
107
+ JSON.stringify({ type: "thread.started", thread_id: "thread-1" }),
108
+ JSON.stringify({ type: "item.completed", item: { id: "item-1", type: "agent_message", text: "hello" } }),
109
+ JSON.stringify({ type: "turn.completed" }),
110
+ ];
111
+ spawnMock.mockReturnValueOnce(createProc(lines));
112
+ createRawStreamLogMock.mockResolvedValueOnce({
113
+ filePath: "codex.jsonl.gz",
114
+ writeLine: rawLogWriteLineMock,
115
+ close: rawLogCloseMock,
116
+ });
117
+ config.rawStreamLogs.codex = {
118
+ enabled: true,
119
+ maxBytesPerTurn: 2048,
120
+ retentionDays: 2,
121
+ keepCompleted: false,
122
+ };
123
+
124
+ const adapter = createCodexAdapter({ metaStore: metaStore() });
125
+ const events = await collect(adapter.prompt("sid-raw", "hi", "F:/project"));
126
+
127
+ expect(createRawStreamLogMock).toHaveBeenCalledWith(expect.objectContaining({
128
+ enabled: true,
129
+ tool: "codex",
130
+ sessionId: "sid-raw",
131
+ label: "prompt",
132
+ maxBytesPerTurn: 2048,
133
+ retentionDays: 2,
134
+ }));
135
+ expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(1, lines[0]);
136
+ expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(2, lines[1]);
137
+ expect(rawLogWriteLineMock).toHaveBeenNthCalledWith(3, lines[2]);
138
+ expect(rawLogCloseMock).toHaveBeenCalledWith({ keep: false });
139
+ expect(events).toEqual([
140
+ {
141
+ type: "assistant",
142
+ blocks: [{ type: "text", text: "hello" }],
143
+ },
144
+ {
145
+ type: "assistant",
146
+ blocks: [],
147
+ isFinalResponse: true,
148
+ },
149
+ ]);
150
+ });
151
+
152
+ it("fails the turn and kills the process tree when bad JSON is followed by idle stdout", async () => {
153
+ vi.useFakeTimers();
154
+ spawnMock.mockReturnValueOnce(createHangingProc([
155
+ "{\"type\":\"item.started\",\"item\":{\"type\":\"command_execution\"",
156
+ ]));
157
+ createRawStreamLogMock.mockResolvedValueOnce(null);
158
+
159
+ const adapter = createCodexAdapter({ metaStore: metaStore() });
160
+ const pending = collect(adapter.prompt("sid-raw", "hi", "F:/project"))
161
+ .catch((error: unknown) => error);
162
+
163
+ await Promise.resolve();
164
+ await vi.advanceTimersByTimeAsync(120_000);
165
+
166
+ const error = await pending;
167
+ expect(error).toBeInstanceOf(BadJsonIdleTimeoutError);
168
+ expect(killProcessTreeMock).toHaveBeenCalledWith(4242);
169
+ });
170
+ });