chatccc 0.2.243 → 0.2.244

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