chatccc 0.2.197 → 0.2.199

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 (52) hide show
  1. package/agent-prompts/cursor_specific.md +13 -13
  2. package/bin/cccagent.mjs +17 -17
  3. package/config.sample.json +27 -27
  4. package/package.json +2 -1
  5. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
  6. package/src/__tests__/builtin-chat-session.test.ts +277 -277
  7. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  8. package/src/__tests__/builtin-config.test.ts +33 -33
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +224 -224
  11. package/src/__tests__/builtin-session-select.test.ts +116 -116
  12. package/src/__tests__/builtin-sigint.test.ts +56 -56
  13. package/src/__tests__/cards.test.ts +109 -109
  14. package/src/__tests__/ccc-adapter.test.ts +114 -114
  15. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  16. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  17. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  18. package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
  19. package/src/__tests__/codex-raw-stream-log.test.ts +163 -120
  20. package/src/__tests__/config-reload.test.ts +10 -10
  21. package/src/__tests__/config-sample.test.ts +18 -18
  22. package/src/__tests__/cursor-adapter.test.ts +114 -1
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/jsonl-stream.test.ts +79 -0
  25. package/src/__tests__/orchestrator.test.ts +200 -200
  26. package/src/__tests__/raw-stream-log.test.ts +106 -106
  27. package/src/__tests__/session.test.ts +40 -40
  28. package/src/__tests__/sim-platform.test.ts +12 -12
  29. package/src/__tests__/web-ui.test.ts +209 -209
  30. package/src/adapters/ccc-adapter.ts +121 -121
  31. package/src/adapters/claude-adapter.ts +603 -603
  32. package/src/adapters/codex-adapter.ts +380 -392
  33. package/src/adapters/cursor-adapter.ts +56 -30
  34. package/src/adapters/jsonl-stream.ts +157 -0
  35. package/src/adapters/raw-stream-log.ts +124 -124
  36. package/src/agent-reload-config-rpc.ts +34 -34
  37. package/src/builtin/cli.ts +473 -473
  38. package/src/builtin/context.ts +323 -323
  39. package/src/builtin/file-tools.ts +1072 -1072
  40. package/src/builtin/index.ts +404 -404
  41. package/src/builtin/session-select.ts +48 -48
  42. package/src/builtin/sigint.ts +50 -50
  43. package/src/cards.ts +195 -195
  44. package/src/chatgpt-subscription-rpc.ts +27 -27
  45. package/src/chatgpt-subscription.ts +299 -299
  46. package/src/chrome-devtools-guard.ts +318 -318
  47. package/src/config.ts +125 -125
  48. package/src/feishu-api.ts +49 -49
  49. package/src/orchestrator.ts +179 -179
  50. package/src/runtime-reload.ts +34 -34
  51. package/src/session.ts +141 -141
  52. package/src/web-ui.ts +205 -205
@@ -1,224 +1,224 @@
1
- import { execFile } from "node:child_process";
2
- import { createHash } from "node:crypto";
3
- import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- import { promisify } from "node:util";
7
-
8
- import { afterEach, describe, expect, it } from "vitest";
9
-
10
- import {
11
- applyPatchForTool,
12
- createFileForTool,
13
- deleteFileForTool,
14
- editFileForTool,
15
- listDirForTool,
16
- moveFileForTool,
17
- readFileForTool,
18
- runCommandForTool,
19
- searchCodeForTool,
20
- } from "../builtin/file-tools.ts";
21
-
22
- const execFileAsync = promisify(execFile);
23
- const tempDirs: string[] = [];
24
-
25
- async function makeTempDir(): Promise<string> {
26
- const dir = await mkdtemp(join(tmpdir(), "chatccc-builtin-tools-"));
27
- tempDirs.push(dir);
28
- return dir;
29
- }
30
-
31
- async function hasRg(): Promise<boolean> {
32
- try {
33
- await execFileAsync("rg", ["--version"]);
34
- return true;
35
- } catch {
36
- return false;
37
- }
38
- }
39
-
40
- function sha256(text: string): string {
41
- return createHash("sha256").update(text).digest("hex");
42
- }
43
-
44
- afterEach(async () => {
45
- await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
46
- });
47
-
48
- describe("builtin file tools", () => {
49
- it("reads a text file with line ranges", async () => {
50
- const dir = await makeTempDir();
51
- await writeFile(join(dir, ".secret.txt"), "one\ntwo\nthree\n", "utf8");
52
-
53
- const result = await readFileForTool(dir, { path: ".secret.txt", startLine: 2, endLine: 3 });
54
-
55
- expect(result).toEqual(expect.objectContaining({
56
- sha256: sha256("one\ntwo\nthree\n"),
57
- isBinary: false,
58
- content: "two\nthree",
59
- startLine: 2,
60
- endLine: 3,
61
- totalLines: 4,
62
- }));
63
- expect(result.path).toContain(".secret.txt");
64
- });
65
-
66
- it("lists directory entries including hidden files", async () => {
67
- const dir = await makeTempDir();
68
- await writeFile(join(dir, ".env"), "TOKEN=x", "utf8");
69
-
70
- const result = await listDirForTool(dir);
71
-
72
- expect(result.entries).toContainEqual(expect.objectContaining({
73
- name: ".env",
74
- type: "file",
75
- }));
76
- });
77
-
78
- it("searches code with rg without using a shell", async () => {
79
- if (!await hasRg()) return;
80
-
81
- const dir = await makeTempDir();
82
- await writeFile(join(dir, "a.ts"), "const marker = 1;\n", "utf8");
83
-
84
- const result = await searchCodeForTool(dir, { query: "marker", glob: "*.ts" });
85
-
86
- expect(result.matches).toEqual([
87
- expect.objectContaining({
88
- line: 1,
89
- text: "const marker = 1;",
90
- }),
91
- ]);
92
- });
93
-
94
- it("runs non-interactive shell commands in the requested cwd", async () => {
95
- const dir = await makeTempDir();
96
-
97
- const result = await runCommandForTool(dir, {
98
- command: "node -e \"process.stdout.write(process.cwd())\"",
99
- timeoutMs: 5_000,
100
- });
101
-
102
- expect(result.exitCode).toBe(0);
103
- expect(result.timedOut).toBe(false);
104
- expect(result.stdout.toLowerCase()).toBe(dir.toLowerCase());
105
- expect(result.stderr).toBe("");
106
- });
107
-
108
- it("returns non-zero command exits without throwing", async () => {
109
- const dir = await makeTempDir();
110
-
111
- const result = await runCommandForTool(dir, {
112
- command: "node -e \"process.stderr.write('failed'); process.exit(7)\"",
113
- timeoutMs: 5_000,
114
- });
115
-
116
- expect(result.exitCode).toBe(7);
117
- expect(result.stderr).toBe("failed");
118
- expect(result.timedOut).toBe(false);
119
- });
120
-
121
- it("edits a file with exact replacements and a SHA-256 precondition", async () => {
122
- const dir = await makeTempDir();
123
- const file = join(dir, "edit.txt");
124
- await writeFile(file, "alpha\nbeta\ngamma\n", "utf8");
125
-
126
- const result = await editFileForTool(dir, {
127
- path: "edit.txt",
128
- expectedSha256: sha256("alpha\nbeta\ngamma\n"),
129
- edits: [{ oldText: "beta", newText: "BETA" }],
130
- });
131
-
132
- expect(result).toEqual(expect.objectContaining({
133
- changed: true,
134
- editsApplied: 1,
135
- beforeSha256: sha256("alpha\nbeta\ngamma\n"),
136
- afterSha256: sha256("alpha\nBETA\ngamma\n"),
137
- }));
138
- await expect(readFile(file, "utf8")).resolves.toBe("alpha\nBETA\ngamma\n");
139
- });
140
-
141
- it("rejects edits when the SHA-256 precondition does not match", async () => {
142
- const dir = await makeTempDir();
143
- await writeFile(join(dir, "edit.txt"), "current\n", "utf8");
144
-
145
- await expect(editFileForTool(dir, {
146
- path: "edit.txt",
147
- expectedSha256: sha256("stale\n"),
148
- edits: [{ oldText: "current", newText: "next" }],
149
- })).rejects.toThrow("SHA-256 mismatch");
150
- });
151
-
152
- it("creates and deletes files", async () => {
153
- const dir = await makeTempDir();
154
-
155
- const created = await createFileForTool(dir, {
156
- path: "created.txt",
157
- content: "created\n",
158
- });
159
- expect(created).toEqual(expect.objectContaining({
160
- changed: true,
161
- afterSha256: sha256("created\n"),
162
- }));
163
- await expect(readFile(join(dir, "created.txt"), "utf8")).resolves.toBe("created\n");
164
-
165
- const deleted = await deleteFileForTool(dir, {
166
- path: "created.txt",
167
- expectedSha256: sha256("created\n"),
168
- });
169
- expect(deleted).toEqual(expect.objectContaining({
170
- deleted: true,
171
- beforeSha256: sha256("created\n"),
172
- }));
173
- await expect(stat(join(dir, "created.txt"))).rejects.toThrow();
174
- });
175
-
176
- it("moves files and creates the destination directory", async () => {
177
- const dir = await makeTempDir();
178
- await writeFile(join(dir, "old.txt"), "move me\n", "utf8");
179
-
180
- const result = await moveFileForTool(dir, {
181
- sourcePath: "old.txt",
182
- destinationPath: "nested/new.txt",
183
- expectedSourceSha256: sha256("move me\n"),
184
- });
185
-
186
- expect(result).toEqual(expect.objectContaining({
187
- moved: true,
188
- sourceSha256: sha256("move me\n"),
189
- }));
190
- await expect(stat(join(dir, "old.txt"))).rejects.toThrow();
191
- await expect(readFile(join(dir, "nested", "new.txt"), "utf8")).resolves.toBe("move me\n");
192
- });
193
-
194
- it("applies a unified diff patch", async () => {
195
- const dir = await makeTempDir();
196
- await writeFile(join(dir, "patch.txt"), "one\ntwo\nthree\n", "utf8");
197
-
198
- const result = await applyPatchForTool(dir, {
199
- patch: [
200
- "--- a/patch.txt",
201
- "+++ b/patch.txt",
202
- "@@ -1,4 +1,4 @@",
203
- " one",
204
- "-two",
205
- "+TWO",
206
- " three",
207
- " ",
208
- "",
209
- ].join("\n"),
210
- expectedSha256ByPath: {
211
- "patch.txt": sha256("one\ntwo\nthree\n"),
212
- },
213
- });
214
-
215
- expect(result.changedFiles).toEqual([
216
- expect.objectContaining({
217
- action: "edit",
218
- beforeSha256: sha256("one\ntwo\nthree\n"),
219
- afterSha256: sha256("one\nTWO\nthree\n"),
220
- }),
221
- ]);
222
- await expect(readFile(join(dir, "patch.txt"), "utf8")).resolves.toBe("one\nTWO\nthree\n");
223
- });
224
- });
1
+ import { execFile } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { promisify } from "node:util";
7
+
8
+ import { afterEach, describe, expect, it } from "vitest";
9
+
10
+ import {
11
+ applyPatchForTool,
12
+ createFileForTool,
13
+ deleteFileForTool,
14
+ editFileForTool,
15
+ listDirForTool,
16
+ moveFileForTool,
17
+ readFileForTool,
18
+ runCommandForTool,
19
+ searchCodeForTool,
20
+ } from "../builtin/file-tools.ts";
21
+
22
+ const execFileAsync = promisify(execFile);
23
+ const tempDirs: string[] = [];
24
+
25
+ async function makeTempDir(): Promise<string> {
26
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-builtin-tools-"));
27
+ tempDirs.push(dir);
28
+ return dir;
29
+ }
30
+
31
+ async function hasRg(): Promise<boolean> {
32
+ try {
33
+ await execFileAsync("rg", ["--version"]);
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ }
39
+
40
+ function sha256(text: string): string {
41
+ return createHash("sha256").update(text).digest("hex");
42
+ }
43
+
44
+ afterEach(async () => {
45
+ await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
46
+ });
47
+
48
+ describe("builtin file tools", () => {
49
+ it("reads a text file with line ranges", async () => {
50
+ const dir = await makeTempDir();
51
+ await writeFile(join(dir, ".secret.txt"), "one\ntwo\nthree\n", "utf8");
52
+
53
+ const result = await readFileForTool(dir, { path: ".secret.txt", startLine: 2, endLine: 3 });
54
+
55
+ expect(result).toEqual(expect.objectContaining({
56
+ sha256: sha256("one\ntwo\nthree\n"),
57
+ isBinary: false,
58
+ content: "two\nthree",
59
+ startLine: 2,
60
+ endLine: 3,
61
+ totalLines: 4,
62
+ }));
63
+ expect(result.path).toContain(".secret.txt");
64
+ });
65
+
66
+ it("lists directory entries including hidden files", async () => {
67
+ const dir = await makeTempDir();
68
+ await writeFile(join(dir, ".env"), "TOKEN=x", "utf8");
69
+
70
+ const result = await listDirForTool(dir);
71
+
72
+ expect(result.entries).toContainEqual(expect.objectContaining({
73
+ name: ".env",
74
+ type: "file",
75
+ }));
76
+ });
77
+
78
+ it("searches code with rg without using a shell", async () => {
79
+ if (!await hasRg()) return;
80
+
81
+ const dir = await makeTempDir();
82
+ await writeFile(join(dir, "a.ts"), "const marker = 1;\n", "utf8");
83
+
84
+ const result = await searchCodeForTool(dir, { query: "marker", glob: "*.ts" });
85
+
86
+ expect(result.matches).toEqual([
87
+ expect.objectContaining({
88
+ line: 1,
89
+ text: "const marker = 1;",
90
+ }),
91
+ ]);
92
+ });
93
+
94
+ it("runs non-interactive shell commands in the requested cwd", async () => {
95
+ const dir = await makeTempDir();
96
+
97
+ const result = await runCommandForTool(dir, {
98
+ command: "node -e \"process.stdout.write(process.cwd())\"",
99
+ timeoutMs: 5_000,
100
+ });
101
+
102
+ expect(result.exitCode).toBe(0);
103
+ expect(result.timedOut).toBe(false);
104
+ expect(result.stdout.toLowerCase()).toBe(dir.toLowerCase());
105
+ expect(result.stderr).toBe("");
106
+ });
107
+
108
+ it("returns non-zero command exits without throwing", async () => {
109
+ const dir = await makeTempDir();
110
+
111
+ const result = await runCommandForTool(dir, {
112
+ command: "node -e \"process.stderr.write('failed'); process.exit(7)\"",
113
+ timeoutMs: 5_000,
114
+ });
115
+
116
+ expect(result.exitCode).toBe(7);
117
+ expect(result.stderr).toBe("failed");
118
+ expect(result.timedOut).toBe(false);
119
+ });
120
+
121
+ it("edits a file with exact replacements and a SHA-256 precondition", async () => {
122
+ const dir = await makeTempDir();
123
+ const file = join(dir, "edit.txt");
124
+ await writeFile(file, "alpha\nbeta\ngamma\n", "utf8");
125
+
126
+ const result = await editFileForTool(dir, {
127
+ path: "edit.txt",
128
+ expectedSha256: sha256("alpha\nbeta\ngamma\n"),
129
+ edits: [{ oldText: "beta", newText: "BETA" }],
130
+ });
131
+
132
+ expect(result).toEqual(expect.objectContaining({
133
+ changed: true,
134
+ editsApplied: 1,
135
+ beforeSha256: sha256("alpha\nbeta\ngamma\n"),
136
+ afterSha256: sha256("alpha\nBETA\ngamma\n"),
137
+ }));
138
+ await expect(readFile(file, "utf8")).resolves.toBe("alpha\nBETA\ngamma\n");
139
+ });
140
+
141
+ it("rejects edits when the SHA-256 precondition does not match", async () => {
142
+ const dir = await makeTempDir();
143
+ await writeFile(join(dir, "edit.txt"), "current\n", "utf8");
144
+
145
+ await expect(editFileForTool(dir, {
146
+ path: "edit.txt",
147
+ expectedSha256: sha256("stale\n"),
148
+ edits: [{ oldText: "current", newText: "next" }],
149
+ })).rejects.toThrow("SHA-256 mismatch");
150
+ });
151
+
152
+ it("creates and deletes files", async () => {
153
+ const dir = await makeTempDir();
154
+
155
+ const created = await createFileForTool(dir, {
156
+ path: "created.txt",
157
+ content: "created\n",
158
+ });
159
+ expect(created).toEqual(expect.objectContaining({
160
+ changed: true,
161
+ afterSha256: sha256("created\n"),
162
+ }));
163
+ await expect(readFile(join(dir, "created.txt"), "utf8")).resolves.toBe("created\n");
164
+
165
+ const deleted = await deleteFileForTool(dir, {
166
+ path: "created.txt",
167
+ expectedSha256: sha256("created\n"),
168
+ });
169
+ expect(deleted).toEqual(expect.objectContaining({
170
+ deleted: true,
171
+ beforeSha256: sha256("created\n"),
172
+ }));
173
+ await expect(stat(join(dir, "created.txt"))).rejects.toThrow();
174
+ });
175
+
176
+ it("moves files and creates the destination directory", async () => {
177
+ const dir = await makeTempDir();
178
+ await writeFile(join(dir, "old.txt"), "move me\n", "utf8");
179
+
180
+ const result = await moveFileForTool(dir, {
181
+ sourcePath: "old.txt",
182
+ destinationPath: "nested/new.txt",
183
+ expectedSourceSha256: sha256("move me\n"),
184
+ });
185
+
186
+ expect(result).toEqual(expect.objectContaining({
187
+ moved: true,
188
+ sourceSha256: sha256("move me\n"),
189
+ }));
190
+ await expect(stat(join(dir, "old.txt"))).rejects.toThrow();
191
+ await expect(readFile(join(dir, "nested", "new.txt"), "utf8")).resolves.toBe("move me\n");
192
+ });
193
+
194
+ it("applies a unified diff patch", async () => {
195
+ const dir = await makeTempDir();
196
+ await writeFile(join(dir, "patch.txt"), "one\ntwo\nthree\n", "utf8");
197
+
198
+ const result = await applyPatchForTool(dir, {
199
+ patch: [
200
+ "--- a/patch.txt",
201
+ "+++ b/patch.txt",
202
+ "@@ -1,4 +1,4 @@",
203
+ " one",
204
+ "-two",
205
+ "+TWO",
206
+ " three",
207
+ " ",
208
+ "",
209
+ ].join("\n"),
210
+ expectedSha256ByPath: {
211
+ "patch.txt": sha256("one\ntwo\nthree\n"),
212
+ },
213
+ });
214
+
215
+ expect(result.changedFiles).toEqual([
216
+ expect.objectContaining({
217
+ action: "edit",
218
+ beforeSha256: sha256("one\ntwo\nthree\n"),
219
+ afterSha256: sha256("one\nTWO\nthree\n"),
220
+ }),
221
+ ]);
222
+ await expect(readFile(join(dir, "patch.txt"), "utf8")).resolves.toBe("one\nTWO\nthree\n");
223
+ });
224
+ });