chatccc 0.2.241 → 0.2.243

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 (66) hide show
  1. package/README.md +5 -5
  2. package/bin/cccagent.mjs +17 -17
  3. package/deepccc-agent/LICENSE +201 -0
  4. package/deepccc-agent/README.md +291 -0
  5. package/deepccc-agent/bin/deepccc.mjs +26 -0
  6. package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
  7. package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
  8. package/deepccc-agent/package-lock.json +1959 -0
  9. package/deepccc-agent/package.json +62 -0
  10. package/deepccc-agent/src/__tests__/chat-session.test.ts +578 -0
  11. package/deepccc-agent/src/__tests__/cli-json.test.ts +49 -0
  12. package/deepccc-agent/src/__tests__/config.test.ts +26 -0
  13. package/deepccc-agent/src/__tests__/context.test.ts +319 -0
  14. package/deepccc-agent/src/__tests__/file-tools.test.ts +240 -0
  15. package/deepccc-agent/src/__tests__/permissions.test.ts +195 -0
  16. package/deepccc-agent/src/__tests__/privacy.test.ts +311 -0
  17. package/deepccc-agent/src/__tests__/progress-reducer.test.ts +121 -0
  18. package/deepccc-agent/src/__tests__/session-search.test.ts +262 -0
  19. package/deepccc-agent/src/__tests__/session-select.test.ts +116 -0
  20. package/deepccc-agent/src/__tests__/sigint.test.ts +56 -0
  21. package/deepccc-agent/src/__tests__/skills.test.ts +284 -0
  22. package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +247 -0
  23. package/deepccc-agent/src/__tests__/web-tools.test.ts +220 -0
  24. package/{src/builtin → deepccc-agent/src}/config.ts +84 -84
  25. package/{src/builtin → deepccc-agent/src}/context.ts +465 -465
  26. package/{src/builtin → deepccc-agent/src}/file-log.ts +38 -38
  27. package/{src/builtin → deepccc-agent/src}/index.ts +22 -0
  28. package/{src/builtin → deepccc-agent/src}/proc-tree-kill.ts +61 -61
  29. package/{src/builtin → deepccc-agent/src}/progress/cards-helpers.ts +76 -76
  30. package/{src/builtin → deepccc-agent/src}/progress/reducer.ts +113 -113
  31. package/{src/builtin → deepccc-agent/src}/progress/terminal-renderer.ts +294 -294
  32. package/{src/builtin → deepccc-agent/src}/progress/view.ts +77 -77
  33. package/{src/builtin → deepccc-agent/src}/raw-stream-log.ts +124 -124
  34. package/{src/builtin → deepccc-agent/src}/session-search.ts +370 -370
  35. package/{src/builtin → deepccc-agent/src}/session-select.ts +48 -48
  36. package/{src/builtin → deepccc-agent/src}/sigint.ts +50 -50
  37. package/{src/builtin → deepccc-agent/src}/skills.ts +205 -205
  38. package/{src/builtin → deepccc-agent/src}/web-tools.ts +313 -313
  39. package/deepccc-agent/tsconfig.build.json +13 -0
  40. package/deepccc-agent/tsconfig.json +13 -0
  41. package/deepccc-agent/vitest.config.ts +7 -0
  42. package/package.json +3 -1
  43. package/src/__tests__/builtin-chat-session.test.ts +522 -522
  44. package/src/__tests__/builtin-config.test.ts +26 -26
  45. package/src/__tests__/builtin-context.test.ts +319 -319
  46. package/src/__tests__/builtin-file-tools.test.ts +240 -240
  47. package/src/__tests__/builtin-permissions.test.ts +211 -211
  48. package/src/__tests__/builtin-session-search.test.ts +262 -262
  49. package/src/__tests__/builtin-session-select.test.ts +116 -116
  50. package/src/__tests__/builtin-sigint.test.ts +56 -56
  51. package/src/__tests__/builtin-skills.test.ts +284 -284
  52. package/src/__tests__/builtin-web-tools.test.ts +220 -220
  53. package/src/__tests__/config.test.ts +17 -17
  54. package/src/__tests__/progress-reducer.test.ts +121 -121
  55. package/src/__tests__/session-ccc-config.test.ts +45 -45
  56. package/src/__tests__/session.test.ts +298 -298
  57. package/src/adapters/ccc-adapter.ts +145 -145
  58. package/src/config-utils.ts +13 -13
  59. package/src/config.ts +13 -13
  60. package/src/progress/reducer.ts +113 -113
  61. package/src/session-chat-binding.ts +83 -83
  62. package/src/session.ts +311 -311
  63. /package/{src/builtin → deepccc-agent/src}/cli.ts +0 -0
  64. /package/{src/builtin → deepccc-agent/src}/file-tools.ts +0 -0
  65. /package/{src/builtin → deepccc-agent/src}/permissions.ts +0 -0
  66. /package/{src/builtin → deepccc-agent/src}/privacy.ts +0 -0
@@ -1,211 +1,211 @@
1
- import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
-
7
- const testHome = vi.hoisted(() => ({ dir: "" }));
8
-
9
- const aiMocks = vi.hoisted(() => ({
10
- streamText: vi.fn(),
11
- generateText: vi.fn(),
12
- }));
13
-
14
- vi.mock("node:os", async () => {
15
- const actual = await vi.importActual<typeof import("node:os")>("node:os");
16
- const [{ mkdtempSync }, { join }] = await Promise.all([import("node:fs"), import("node:path")]);
17
- testHome.dir = mkdtempSync(join(actual.tmpdir(), "chatccc-builtin-perm-"));
18
- return { ...actual, homedir: () => testHome.dir };
19
- });
20
-
21
- vi.mock("@ai-sdk/openai-compatible", () => ({
22
- createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
23
- }));
24
-
25
- vi.mock("ai", () => ({
26
- streamText: aiMocks.streamText,
27
- generateText: aiMocks.generateText,
28
- isLoopFinished: vi.fn(() => ({ loopFinished: true })),
29
- stepCountIs: vi.fn((count: number) => ({ count })),
30
- jsonSchema: vi.fn((schema: unknown) => schema),
31
- tool: vi.fn((definition: unknown) => definition),
32
- }));
33
-
34
- vi.mock("../builtin/raw-stream-log.ts", () => ({
35
- createRawStreamLog: vi.fn().mockResolvedValue(null),
36
- }));
37
-
38
- import {
39
- PermissionGate,
40
- getAllowRules,
41
- isDangerousCommand,
42
- matchRule,
43
- reloadAllowRules,
44
- } from "../builtin/permissions.ts";
45
- import { createBuiltinFileTools } from "../builtin/file-tools.ts";
46
- import { ChatSession } from "../builtin/index.ts";
47
-
48
- const streamTextMock = aiMocks.streamText;
49
- const generateTextMock = aiMocks.generateText;
50
-
51
- const ALLOW_FILE = () => join(testHome.dir, ".deepccc", "allow.json");
52
-
53
- async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
54
- const events: unknown[] = [];
55
- for await (const event of iterable) events.push(event);
56
- return events;
57
- }
58
-
59
- async function* textStream(...chunks: string[]): AsyncIterable<string> {
60
- for (const chunk of chunks) yield chunk;
61
- }
62
-
63
- function lastRunCommandExecute(): (input: { command: string }, opts?: unknown) => Promise<unknown> {
64
- const call = streamTextMock.mock.calls.at(-1)?.[0] as { tools?: Record<string, { execute?: unknown }> };
65
- const execute = call?.tools?.run_command?.execute as ((input: { command: string }, opts?: unknown) => Promise<unknown>) | undefined;
66
- if (!execute) throw new Error("streamText was not called with tools.run_command.execute");
67
- return execute;
68
- }
69
-
70
- afterEach(() => {
71
- try {
72
- rmSync(ALLOW_FILE(), { force: true });
73
- } catch {}
74
- reloadAllowRules();
75
- streamTextMock.mockReset();
76
- generateTextMock.mockReset();
77
- });
78
-
79
- beforeEach(() => {
80
- try {
81
- rmSync(join(testHome.dir, ".deepccc"), { recursive: true, force: true });
82
- } catch {}
83
- mkdirSync(join(testHome.dir, ".deepccc"), { recursive: true });
84
- reloadAllowRules();
85
- });
86
-
87
- describe("builtin permissions module", () => {
88
- it("flags destructive commands and ignores normal ones", () => {
89
- expect(isDangerousCommand("rm -rf node_modules")).toBe(true);
90
- expect(isDangerousCommand("git push --force origin main")).toBe(true);
91
- expect(isDangerousCommand("git status")).toBe(false);
92
- expect(isDangerousCommand("npm test")).toBe(false);
93
- });
94
-
95
- it("matches allow/deny rules with wildcards and relative paths", () => {
96
- expect(matchRule("run_command:git status*", "run_command:git status --short")).toBe(true);
97
- expect(matchRule("edit_file:node_modules/**", "edit_file:node_modules/a/b.js")).toBe(true);
98
- expect(matchRule("run_command:npm test", "run_command:npm test extra")).toBe(false);
99
- });
100
-
101
- it("returns empty rules when allow.json is missing", () => {
102
- expect(getAllowRules()).toEqual({ allow: [], deny: [] });
103
- });
104
-
105
- it("loads rules from ~/.deepccc/allow.json", () => {
106
- writeFileSync(ALLOW_FILE(), JSON.stringify({ deny: ["run_command:npm publish*"] }), "utf-8");
107
- reloadAllowRules();
108
- expect(getAllowRules().deny).toEqual(["run_command:npm publish*"]);
109
- });
110
- });
111
-
112
- describe("builtin PermissionGate", () => {
113
- it("bypass mode allows everything", async () => {
114
- const gate = new PermissionGate("bypass");
115
- expect(await gate.check({ tool: "run_command", action: "rm -rf /", reason: "high-risk", detail: "x" })).toBe("allow");
116
- });
117
-
118
- it("ask mode denies high-risk without resolver", async () => {
119
- const gate = new PermissionGate("ask");
120
- expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
121
- });
122
-
123
- it("ask mode allows non-high-risk operations without asking", async () => {
124
- const resolver = vi.fn();
125
- const gate = new PermissionGate("ask", resolver as never);
126
- expect(await gate.check({ tool: "run_command", action: "npm test", reason: "rule", detail: "x" })).toBe("allow");
127
- expect(await gate.check({ tool: "edit_file", action: "src/a.ts", reason: "rule", detail: "x" })).toBe("allow");
128
- expect(resolver).not.toHaveBeenCalled();
129
- });
130
-
131
- it("follows resolver answer", async () => {
132
- let answer: "allow" | "deny" = "allow";
133
- const gate = new PermissionGate("ask", async () => answer);
134
- expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("allow");
135
- answer = "deny";
136
- expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
137
- });
138
-
139
- it("deny rule wins over allow rule", async () => {
140
- writeFileSync(
141
- ALLOW_FILE(),
142
- JSON.stringify({ allow: ["run_command:rm -rf /tmp*"], deny: ["run_command:rm -rf /tmp/forbidden*"] }),
143
- "utf-8",
144
- );
145
- reloadAllowRules();
146
- const gate = new PermissionGate("ask");
147
- expect(await gate.check({ tool: "run_command", action: "rm -rf /tmp/forbidden/x", reason: "high-risk", detail: "x" })).toBe("deny");
148
- });
149
- });
150
-
151
- describe("builtin file-tools permission integration", () => {
152
- it("run_command high-risk is denied by default gate", async () => {
153
- const tools = createBuiltinFileTools(testHome.dir, { permissionGate: new PermissionGate("ask") });
154
- const tool = tools.run_command as unknown as {
155
- execute: (input: { command: string }, opts?: unknown) => Promise<unknown>;
156
- };
157
- await expect(tool.execute({ command: "rm -rf node_modules" }, { abortSignal: undefined })).rejects.toThrow(/权限拒绝/);
158
- });
159
-
160
- it("no gate keeps original behavior", async () => {
161
- const tools = createBuiltinFileTools(testHome.dir);
162
- const tool = tools.run_command as unknown as {
163
- execute: (input: { command: string }, opts?: unknown) => Promise<{ exitCode: number | null }>;
164
- };
165
- const result = await tool.execute({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined });
166
- expect(result.exitCode).toBe(0);
167
- });
168
- });
169
-
170
- describe("builtin ChatSession permission integration", () => {
171
- it("permissionMode bypass lets high-risk run_command execute", async () => {
172
- const session = new ChatSession(
173
- { apiKey: "sk-test" },
174
- { sessionId: "perm-bypass", permissionMode: "bypass" },
175
- );
176
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
177
- await collect(session.chat("hi"));
178
-
179
- const result = (await lastRunCommandExecute()({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined })) as { exitCode: number };
180
- expect(result.exitCode).toBe(0);
181
- });
182
-
183
- it("default ask mode without resolver denies high-risk run_command", async () => {
184
- const session = new ChatSession(
185
- { apiKey: "sk-test" },
186
- { sessionId: "perm-ask" },
187
- );
188
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
189
- await collect(session.chat("hi"));
190
-
191
- await expect(
192
- lastRunCommandExecute()({ command: "rm -rf node_modules" }, { abortSignal: undefined }),
193
- ).rejects.toThrow(/权限拒绝/);
194
- });
195
- });
196
-
197
- describe("ccc-adapter uses bypass mode (aligns with claude/codex)", () => {
198
- it("tools created via ccc adapter run high-risk commands without asking", async () => {
199
- const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
200
- const adapter = createCccAdapter({ apiKey: "sk-test", contextDir: testHome.dir });
201
- const { sessionId } = await adapter.createSession(testHome.dir);
202
- streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
203
-
204
- for await (const _m of adapter.prompt(sessionId, "hi", testHome.dir)) {
205
- // drain
206
- }
207
-
208
- const result = (await lastRunCommandExecute()({ command: "node -e \"console.log('bypass')\"" }, { abortSignal: undefined })) as { exitCode: number };
209
- expect(result.exitCode).toBe(0);
210
- });
211
- });
1
+ import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+
7
+ const testHome = vi.hoisted(() => ({ dir: "" }));
8
+
9
+ const aiMocks = vi.hoisted(() => ({
10
+ streamText: vi.fn(),
11
+ generateText: vi.fn(),
12
+ }));
13
+
14
+ vi.mock("node:os", async () => {
15
+ const actual = await vi.importActual<typeof import("node:os")>("node:os");
16
+ const [{ mkdtempSync }, { join }] = await Promise.all([import("node:fs"), import("node:path")]);
17
+ testHome.dir = mkdtempSync(join(actual.tmpdir(), "chatccc-builtin-perm-"));
18
+ return { ...actual, homedir: () => testHome.dir };
19
+ });
20
+
21
+ vi.mock("@ai-sdk/openai-compatible", () => ({
22
+ createOpenAICompatible: vi.fn(() => (modelId: string) => ({ modelId })),
23
+ }));
24
+
25
+ vi.mock("ai", () => ({
26
+ streamText: aiMocks.streamText,
27
+ generateText: aiMocks.generateText,
28
+ isLoopFinished: vi.fn(() => ({ loopFinished: true })),
29
+ stepCountIs: vi.fn((count: number) => ({ count })),
30
+ jsonSchema: vi.fn((schema: unknown) => schema),
31
+ tool: vi.fn((definition: unknown) => definition),
32
+ }));
33
+
34
+ vi.mock("../../deepccc-agent/src/raw-stream-log.ts", () => ({
35
+ createRawStreamLog: vi.fn().mockResolvedValue(null),
36
+ }));
37
+
38
+ import {
39
+ PermissionGate,
40
+ getAllowRules,
41
+ isDangerousCommand,
42
+ matchRule,
43
+ reloadAllowRules,
44
+ } from "../../deepccc-agent/src/permissions.ts";
45
+ import { createBuiltinFileTools } from "../../deepccc-agent/src/file-tools.ts";
46
+ import { ChatSession } from "../../deepccc-agent/src/index.ts";
47
+
48
+ const streamTextMock = aiMocks.streamText;
49
+ const generateTextMock = aiMocks.generateText;
50
+
51
+ const ALLOW_FILE = () => join(testHome.dir, ".deepccc", "allow.json");
52
+
53
+ async function collect(iterable: AsyncIterable<unknown>): Promise<unknown[]> {
54
+ const events: unknown[] = [];
55
+ for await (const event of iterable) events.push(event);
56
+ return events;
57
+ }
58
+
59
+ async function* textStream(...chunks: string[]): AsyncIterable<string> {
60
+ for (const chunk of chunks) yield chunk;
61
+ }
62
+
63
+ function lastRunCommandExecute(): (input: { command: string }, opts?: unknown) => Promise<unknown> {
64
+ const call = streamTextMock.mock.calls.at(-1)?.[0] as { tools?: Record<string, { execute?: unknown }> };
65
+ const execute = call?.tools?.run_command?.execute as ((input: { command: string }, opts?: unknown) => Promise<unknown>) | undefined;
66
+ if (!execute) throw new Error("streamText was not called with tools.run_command.execute");
67
+ return execute;
68
+ }
69
+
70
+ afterEach(() => {
71
+ try {
72
+ rmSync(ALLOW_FILE(), { force: true });
73
+ } catch {}
74
+ reloadAllowRules();
75
+ streamTextMock.mockReset();
76
+ generateTextMock.mockReset();
77
+ });
78
+
79
+ beforeEach(() => {
80
+ try {
81
+ rmSync(join(testHome.dir, ".deepccc"), { recursive: true, force: true });
82
+ } catch {}
83
+ mkdirSync(join(testHome.dir, ".deepccc"), { recursive: true });
84
+ reloadAllowRules();
85
+ });
86
+
87
+ describe("builtin permissions module", () => {
88
+ it("flags destructive commands and ignores normal ones", () => {
89
+ expect(isDangerousCommand("rm -rf node_modules")).toBe(true);
90
+ expect(isDangerousCommand("git push --force origin main")).toBe(true);
91
+ expect(isDangerousCommand("git status")).toBe(false);
92
+ expect(isDangerousCommand("npm test")).toBe(false);
93
+ });
94
+
95
+ it("matches allow/deny rules with wildcards and relative paths", () => {
96
+ expect(matchRule("run_command:git status*", "run_command:git status --short")).toBe(true);
97
+ expect(matchRule("edit_file:node_modules/**", "edit_file:node_modules/a/b.js")).toBe(true);
98
+ expect(matchRule("run_command:npm test", "run_command:npm test extra")).toBe(false);
99
+ });
100
+
101
+ it("returns empty rules when allow.json is missing", () => {
102
+ expect(getAllowRules()).toEqual({ allow: [], deny: [] });
103
+ });
104
+
105
+ it("loads rules from ~/.deepccc/allow.json", () => {
106
+ writeFileSync(ALLOW_FILE(), JSON.stringify({ deny: ["run_command:npm publish*"] }), "utf-8");
107
+ reloadAllowRules();
108
+ expect(getAllowRules().deny).toEqual(["run_command:npm publish*"]);
109
+ });
110
+ });
111
+
112
+ describe("builtin PermissionGate", () => {
113
+ it("bypass mode allows everything", async () => {
114
+ const gate = new PermissionGate("bypass");
115
+ expect(await gate.check({ tool: "run_command", action: "rm -rf /", reason: "high-risk", detail: "x" })).toBe("allow");
116
+ });
117
+
118
+ it("ask mode denies high-risk without resolver", async () => {
119
+ const gate = new PermissionGate("ask");
120
+ expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
121
+ });
122
+
123
+ it("ask mode allows non-high-risk operations without asking", async () => {
124
+ const resolver = vi.fn();
125
+ const gate = new PermissionGate("ask", resolver as never);
126
+ expect(await gate.check({ tool: "run_command", action: "npm test", reason: "rule", detail: "x" })).toBe("allow");
127
+ expect(await gate.check({ tool: "edit_file", action: "src/a.ts", reason: "rule", detail: "x" })).toBe("allow");
128
+ expect(resolver).not.toHaveBeenCalled();
129
+ });
130
+
131
+ it("follows resolver answer", async () => {
132
+ let answer: "allow" | "deny" = "allow";
133
+ const gate = new PermissionGate("ask", async () => answer);
134
+ expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("allow");
135
+ answer = "deny";
136
+ expect(await gate.check({ tool: "run_command", action: "rm -rf x", reason: "high-risk", detail: "x" })).toBe("deny");
137
+ });
138
+
139
+ it("deny rule wins over allow rule", async () => {
140
+ writeFileSync(
141
+ ALLOW_FILE(),
142
+ JSON.stringify({ allow: ["run_command:rm -rf /tmp*"], deny: ["run_command:rm -rf /tmp/forbidden*"] }),
143
+ "utf-8",
144
+ );
145
+ reloadAllowRules();
146
+ const gate = new PermissionGate("ask");
147
+ expect(await gate.check({ tool: "run_command", action: "rm -rf /tmp/forbidden/x", reason: "high-risk", detail: "x" })).toBe("deny");
148
+ });
149
+ });
150
+
151
+ describe("builtin file-tools permission integration", () => {
152
+ it("run_command high-risk is denied by default gate", async () => {
153
+ const tools = createBuiltinFileTools(testHome.dir, { permissionGate: new PermissionGate("ask") });
154
+ const tool = tools.run_command as unknown as {
155
+ execute: (input: { command: string }, opts?: unknown) => Promise<unknown>;
156
+ };
157
+ await expect(tool.execute({ command: "rm -rf node_modules" }, { abortSignal: undefined })).rejects.toThrow(/权限拒绝/);
158
+ });
159
+
160
+ it("no gate keeps original behavior", async () => {
161
+ const tools = createBuiltinFileTools(testHome.dir);
162
+ const tool = tools.run_command as unknown as {
163
+ execute: (input: { command: string }, opts?: unknown) => Promise<{ exitCode: number | null }>;
164
+ };
165
+ const result = await tool.execute({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined });
166
+ expect(result.exitCode).toBe(0);
167
+ });
168
+ });
169
+
170
+ describe("builtin ChatSession permission integration", () => {
171
+ it("permissionMode bypass lets high-risk run_command execute", async () => {
172
+ const session = new ChatSession(
173
+ { apiKey: "sk-test" },
174
+ { sessionId: "perm-bypass", permissionMode: "bypass" },
175
+ );
176
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
177
+ await collect(session.chat("hi"));
178
+
179
+ const result = (await lastRunCommandExecute()({ command: "node -e \"console.log('ok')\"" }, { abortSignal: undefined })) as { exitCode: number };
180
+ expect(result.exitCode).toBe(0);
181
+ });
182
+
183
+ it("default ask mode without resolver denies high-risk run_command", async () => {
184
+ const session = new ChatSession(
185
+ { apiKey: "sk-test" },
186
+ { sessionId: "perm-ask" },
187
+ );
188
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
189
+ await collect(session.chat("hi"));
190
+
191
+ await expect(
192
+ lastRunCommandExecute()({ command: "rm -rf node_modules" }, { abortSignal: undefined }),
193
+ ).rejects.toThrow(/权限拒绝/);
194
+ });
195
+ });
196
+
197
+ describe("ccc-adapter uses bypass mode (aligns with claude/codex)", () => {
198
+ it("tools created via ccc adapter run high-risk commands without asking", async () => {
199
+ const { createCccAdapter } = await import("../adapters/ccc-adapter.ts");
200
+ const adapter = createCccAdapter({ apiKey: "sk-test", contextDir: testHome.dir });
201
+ const { sessionId } = await adapter.createSession(testHome.dir);
202
+ streamTextMock.mockReturnValueOnce({ textStream: textStream("hi") });
203
+
204
+ for await (const _m of adapter.prompt(sessionId, "hi", testHome.dir)) {
205
+ // drain
206
+ }
207
+
208
+ const result = (await lastRunCommandExecute()({ command: "node -e \"console.log('bypass')\"" }, { abortSignal: undefined })) as { exitCode: number };
209
+ expect(result.exitCode).toBe(0);
210
+ });
211
+ });