chatccc 0.2.227 → 0.2.229
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.
- package/package.json +1 -1
- package/src/__tests__/builtin-chat-session.test.ts +329 -350
- package/src/__tests__/builtin-file-tools.test.ts +240 -275
- package/src/__tests__/builtin-skills.test.ts +42 -10
- package/src/__tests__/builtin-web-tools.test.ts +220 -0
- package/src/__tests__/restart.test.ts +132 -0
- package/src/builtin/context.ts +333 -323
- package/src/builtin/file-tools.ts +54 -2
- package/src/builtin/index.ts +12 -5
- package/src/builtin/skills.ts +17 -2
- package/src/builtin/web-tools.ts +313 -0
- package/src/index.ts +315 -310
- package/src/orchestrator.ts +2489 -2388
|
@@ -1,275 +1,240 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
expect(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
await
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
afterSha256: sha256("
|
|
178
|
-
}));
|
|
179
|
-
await expect(readFile(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("
|
|
193
|
-
const dir = await makeTempDir();
|
|
194
|
-
await writeFile(join(dir, "
|
|
195
|
-
|
|
196
|
-
await
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
await
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
await expect(stat(join(dir, "old.txt"))).rejects.toThrow();
|
|
242
|
-
await expect(readFile(join(dir, "nested", "new.txt"), "utf8")).resolves.toBe("move me\n");
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it("applies a unified diff patch", async () => {
|
|
246
|
-
const dir = await makeTempDir();
|
|
247
|
-
await writeFile(join(dir, "patch.txt"), "one\ntwo\nthree\n", "utf8");
|
|
248
|
-
|
|
249
|
-
const result = await applyPatchForTool(dir, {
|
|
250
|
-
patch: [
|
|
251
|
-
"--- a/patch.txt",
|
|
252
|
-
"+++ b/patch.txt",
|
|
253
|
-
"@@ -1,4 +1,4 @@",
|
|
254
|
-
" one",
|
|
255
|
-
"-two",
|
|
256
|
-
"+TWO",
|
|
257
|
-
" three",
|
|
258
|
-
" ",
|
|
259
|
-
"",
|
|
260
|
-
].join("\n"),
|
|
261
|
-
expectedSha256ByPath: {
|
|
262
|
-
"patch.txt": sha256("one\ntwo\nthree\n"),
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
expect(result.changedFiles).toEqual([
|
|
267
|
-
expect.objectContaining({
|
|
268
|
-
action: "edit",
|
|
269
|
-
beforeSha256: sha256("one\ntwo\nthree\n"),
|
|
270
|
-
afterSha256: sha256("one\nTWO\nthree\n"),
|
|
271
|
-
}),
|
|
272
|
-
]);
|
|
273
|
-
await expect(readFile(join(dir, "patch.txt"), "utf8")).resolves.toBe("one\nTWO\nthree\n");
|
|
274
|
-
});
|
|
275
|
-
});
|
|
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 "../builtin/file-tools.ts";
|
|
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,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
2
|
import { mkdtempSync, rmSync, writeFileSync, mkdirSync, utimesSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
+
normalizeSkillPathForPrompt,
|
|
7
8
|
parseSkillFrontmatter,
|
|
8
9
|
scanSkillsDirs,
|
|
9
10
|
buildDefaultSkillDirs,
|
|
@@ -47,14 +48,14 @@ describe("parseSkillFrontmatter", () => {
|
|
|
47
48
|
const content = [
|
|
48
49
|
"---",
|
|
49
50
|
"name: feishu-doc-download-md",
|
|
50
|
-
"description:
|
|
51
|
+
"description: 下载飞书文档为 Markdown",
|
|
51
52
|
"---",
|
|
52
53
|
"",
|
|
53
|
-
"#
|
|
54
|
+
"# 正文",
|
|
54
55
|
].join("\n");
|
|
55
56
|
expect(parseSkillFrontmatter(content)).toEqual({
|
|
56
57
|
name: "feishu-doc-download-md",
|
|
57
|
-
description: "
|
|
58
|
+
description: "下载飞书文档为 Markdown",
|
|
58
59
|
});
|
|
59
60
|
});
|
|
60
61
|
|
|
@@ -70,10 +71,10 @@ describe("parseSkillFrontmatter", () => {
|
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
it("handles CRLF line endings", () => {
|
|
73
|
-
const content = "---\r\nname: crlf-skill\r\ndescription: CRLF
|
|
74
|
+
const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 描述\r\n---\r\n\r\nbody";
|
|
74
75
|
expect(parseSkillFrontmatter(content)).toEqual({
|
|
75
76
|
name: "crlf-skill",
|
|
76
|
-
description: "CRLF
|
|
77
|
+
description: "CRLF 描述",
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
});
|
|
@@ -158,7 +159,7 @@ describe("scanSkillsDirs hot reload (mtime cache)", () => {
|
|
|
158
159
|
expect(first.find((s) => s.name === "live")?.description).toBe("v1");
|
|
159
160
|
|
|
160
161
|
writeFileSync(skillPath, "---\nname: live\ndescription: v2\n---\n\nbody\n", "utf8");
|
|
161
|
-
utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); //
|
|
162
|
+
utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); // 强制 mtime 前进
|
|
162
163
|
|
|
163
164
|
const second = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
164
165
|
expect(second.find((s) => s.name === "live")?.description).toBe("v2");
|
|
@@ -171,7 +172,7 @@ describe("scanSkillsDirs hot reload (mtime cache)", () => {
|
|
|
171
172
|
const first = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
172
173
|
expect(first).toHaveLength(1);
|
|
173
174
|
|
|
174
|
-
makeSkill(dir, "b", "B"); //
|
|
175
|
+
makeSkill(dir, "b", "B"); // 新技能,无需改 mtime(目录枚举每次都做)
|
|
175
176
|
const second = await scanSkillsDirs([spec(dir, "deepccc")]);
|
|
176
177
|
expect(second.map((s) => s.name).sort()).toEqual(["a", "b"]);
|
|
177
178
|
});
|
|
@@ -211,12 +212,27 @@ describe("buildDefaultSkillDirs", () => {
|
|
|
211
212
|
});
|
|
212
213
|
});
|
|
213
214
|
|
|
215
|
+
describe("normalizeSkillPathForPrompt", () => {
|
|
216
|
+
it("abbreviates home-directory paths with ~ and normalizes separators", () => {
|
|
217
|
+
const home = homedir();
|
|
218
|
+
const abs = join(home, ".codex", "skills", "x", "SKILL.md");
|
|
219
|
+
expect(normalizeSkillPathForPrompt(abs)).toBe("~/.codex/skills/x/SKILL.md");
|
|
220
|
+
expect(normalizeSkillPathForPrompt(home)).toBe("~");
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("keeps paths outside the home directory unchanged (separators normalized)", () => {
|
|
224
|
+
expect(normalizeSkillPathForPrompt("C:\\proj\\.claude\\skills\\x\\SKILL.md")).toBe(
|
|
225
|
+
"C:/proj/.claude/skills/x/SKILL.md",
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
214
230
|
describe("buildSkillsIndexPrompt", () => {
|
|
215
231
|
it("renders index with source markers and the skill creation convention", () => {
|
|
216
232
|
const prompt = buildSkillsIndexPrompt([
|
|
217
233
|
{
|
|
218
234
|
name: "feishu-doc",
|
|
219
|
-
description: "
|
|
235
|
+
description: "下载飞书文档",
|
|
220
236
|
skillPath: "C:/x/feishu-doc/SKILL.md",
|
|
221
237
|
source: "codex",
|
|
222
238
|
scope: "global",
|
|
@@ -231,6 +247,22 @@ describe("buildSkillsIndexPrompt", () => {
|
|
|
231
247
|
expect(prompt).toContain("read_file");
|
|
232
248
|
});
|
|
233
249
|
|
|
250
|
+
it("renders home-abbreviated skill paths so the prompt stays stable across machines", () => {
|
|
251
|
+
const home = homedir();
|
|
252
|
+
const prompt = buildSkillsIndexPrompt([
|
|
253
|
+
{
|
|
254
|
+
name: "demo",
|
|
255
|
+
description: "d",
|
|
256
|
+
skillPath: join(home, ".codex", "skills", "demo", "SKILL.md"),
|
|
257
|
+
source: "codex",
|
|
258
|
+
scope: "global",
|
|
259
|
+
},
|
|
260
|
+
]);
|
|
261
|
+
|
|
262
|
+
expect(prompt).toContain("~/.codex/skills/demo/SKILL.md");
|
|
263
|
+
expect(prompt).not.toContain(home);
|
|
264
|
+
});
|
|
265
|
+
|
|
234
266
|
it("returns empty string for no skills", () => {
|
|
235
267
|
expect(buildSkillsIndexPrompt([])).toBe("");
|
|
236
268
|
});
|