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,284 +1,284 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
- import { mkdtempSync, rmSync, writeFileSync, mkdirSync, utimesSync } from "node:fs";
3
- import { homedir, tmpdir } from "node:os";
4
- import { join } from "node:path";
5
-
6
- import {
7
- normalizeSkillPathForPrompt,
8
- parseSkillFrontmatter,
9
- scanSkillsDirs,
10
- buildDefaultSkillDirs,
11
- buildSkillsIndexPrompt,
12
- buildSkillTemplate,
13
- type SkillDirSpec,
14
- type SkillSource,
15
- type SkillScope,
16
- } from "../../deepccc-agent/src/skills.ts";
17
-
18
- let tempRoot: string;
19
-
20
- beforeEach(() => {
21
- tempRoot = mkdtempSync(join(tmpdir(), "deepccc-skills-"));
22
- });
23
-
24
- afterEach(() => {
25
- try {
26
- rmSync(tempRoot, { recursive: true, force: true });
27
- } catch {}
28
- });
29
-
30
- function makeSkill(specDir: string, name: string, description: string): string {
31
- const dir = join(specDir, name);
32
- mkdirSync(dir, { recursive: true });
33
- const skillPath = join(dir, "SKILL.md");
34
- writeFileSync(skillPath, `---\nname: ${name}\ndescription: ${description}\n---\n\nbody\n`, "utf8");
35
- return skillPath;
36
- }
37
-
38
- function spec(
39
- dir: string,
40
- source: SkillSource,
41
- scope: SkillScope = "global",
42
- ): SkillDirSpec {
43
- return { dir, source, scope };
44
- }
45
-
46
- describe("parseSkillFrontmatter", () => {
47
- it("parses name and description from frontmatter", () => {
48
- const content = [
49
- "---",
50
- "name: feishu-doc-download-md",
51
- "description: 下载飞书文档为 Markdown",
52
- "---",
53
- "",
54
- "# 正文",
55
- ].join("\n");
56
- expect(parseSkillFrontmatter(content)).toEqual({
57
- name: "feishu-doc-download-md",
58
- description: "下载飞书文档为 Markdown",
59
- });
60
- });
61
-
62
- it("returns null when there is no frontmatter", () => {
63
- expect(parseSkillFrontmatter("# just a heading")).toBeNull();
64
- });
65
-
66
- it("tolerates missing description", () => {
67
- expect(parseSkillFrontmatter("---\nname: minimal-skill\n---\n\nbody")).toEqual({
68
- name: "minimal-skill",
69
- description: "",
70
- });
71
- });
72
-
73
- it("handles CRLF line endings", () => {
74
- const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 描述\r\n---\r\n\r\nbody";
75
- expect(parseSkillFrontmatter(content)).toEqual({
76
- name: "crlf-skill",
77
- description: "CRLF 描述",
78
- });
79
- });
80
- });
81
-
82
- describe("scanSkillsDirs priority matrix", () => {
83
- it("codex wins over cursor, cursor wins over claude for same-name skills", async () => {
84
- const claudeDir = join(tempRoot, "claude");
85
- const cursorDir = join(tempRoot, "cursor");
86
- const codexDir = join(tempRoot, "codex");
87
- makeSkill(claudeDir, "dupe", "claude version");
88
- makeSkill(cursorDir, "dupe", "cursor version");
89
- makeSkill(codexDir, "dupe", "codex version");
90
- makeSkill(codexDir, "only-codex", "codex only");
91
-
92
- const skills = await scanSkillsDirs([
93
- spec(claudeDir, "claude"),
94
- spec(cursorDir, "cursor"),
95
- spec(codexDir, "codex"),
96
- ]);
97
-
98
- const byName = new Map(skills.map((s) => [s.name, s]));
99
- expect(byName.get("dupe")?.description).toBe("codex version");
100
- expect(byName.get("dupe")?.source).toBe("codex");
101
- expect(byName.get("dupe")?.skillPath).toContain(join("codex", "dupe"));
102
- expect(byName.get("only-codex")?.source).toBe("codex");
103
- });
104
-
105
- it("project scope wins over global scope within the same source", async () => {
106
- const globalCodex = join(tempRoot, "codex-global");
107
- const projectCodex = join(tempRoot, "codex-project");
108
- makeSkill(globalCodex, "dup", "global version");
109
- makeSkill(projectCodex, "dup", "project version");
110
-
111
- const skills = await scanSkillsDirs([
112
- spec(globalCodex, "codex", "global"),
113
- spec(projectCodex, "codex", "project"),
114
- ]);
115
-
116
- const byName = new Map(skills.map((s) => [s.name, s]));
117
- expect(byName.get("dup")?.description).toBe("project version");
118
- expect(byName.get("dup")?.scope).toBe("project");
119
- });
120
-
121
- it("deepccc source has the highest priority over codex", async () => {
122
- const codexDir = join(tempRoot, "codex");
123
- const deepcccDir = join(tempRoot, "deepccc");
124
- makeSkill(codexDir, "dup", "from codex");
125
- makeSkill(deepcccDir, "dup", "from deepccc");
126
-
127
- const skills = await scanSkillsDirs([
128
- spec(codexDir, "codex"),
129
- spec(deepcccDir, "deepccc"),
130
- ]);
131
-
132
- expect(skills.find((s) => s.name === "dup")?.description).toBe("from deepccc");
133
- expect(skills.find((s) => s.name === "dup")?.source).toBe("deepccc");
134
- });
135
-
136
- it("skips hidden dirs, dirs without SKILL.md, and missing dirs", async () => {
137
- const dir = join(tempRoot, "src");
138
- mkdirSync(join(dir, ".system"), { recursive: true });
139
- writeFileSync(join(dir, ".system", "SKILL.md"), "---\nname: system-skill\ndescription: x\n---\n", "utf8");
140
- mkdirSync(join(dir, "no-skill-dir"));
141
-
142
- makeSkill(dir, "ok", "fine");
143
- const skills = await scanSkillsDirs([
144
- spec(join(tempRoot, "missing-dir"), "codex"),
145
- spec(dir, "codex"),
146
- ]);
147
-
148
- expect(skills).toHaveLength(1);
149
- expect(skills[0].name).toBe("ok");
150
- });
151
- });
152
-
153
- describe("scanSkillsDirs hot reload (mtime cache)", () => {
154
- it("re-reads a skill after its SKILL.md content changes", async () => {
155
- const dir = join(tempRoot, "src");
156
- const skillPath = makeSkill(dir, "live", "v1");
157
-
158
- const first = await scanSkillsDirs([spec(dir, "deepccc")]);
159
- expect(first.find((s) => s.name === "live")?.description).toBe("v1");
160
-
161
- writeFileSync(skillPath, "---\nname: live\ndescription: v2\n---\n\nbody\n", "utf8");
162
- utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); // 强制 mtime 前进
163
-
164
- const second = await scanSkillsDirs([spec(dir, "deepccc")]);
165
- expect(second.find((s) => s.name === "live")?.description).toBe("v2");
166
- });
167
-
168
- it("new skill dirs are picked up on the next scan", async () => {
169
- const dir = join(tempRoot, "src");
170
- makeSkill(dir, "a", "A");
171
-
172
- const first = await scanSkillsDirs([spec(dir, "deepccc")]);
173
- expect(first).toHaveLength(1);
174
-
175
- makeSkill(dir, "b", "B"); // 新技能,无需改 mtime(目录枚举每次都做)
176
- const second = await scanSkillsDirs([spec(dir, "deepccc")]);
177
- expect(second.map((s) => s.name).sort()).toEqual(["a", "b"]);
178
- });
179
-
180
- it("unchanged skills return identical results across scans", async () => {
181
- const dir = join(tempRoot, "src");
182
- makeSkill(dir, "a", "A");
183
-
184
- const first = await scanSkillsDirs([spec(dir, "deepccc")]);
185
- const second = await scanSkillsDirs([spec(dir, "deepccc")]);
186
- expect(second).toEqual(first);
187
- });
188
- });
189
-
190
- describe("buildDefaultSkillDirs", () => {
191
- it("orders dirs low->high priority: claude < cursor < codex < deepccc, project after global", () => {
192
- const dirs = buildDefaultSkillDirs("C:/proj");
193
- expect(dirs.map((d) => `${d.source}:${d.scope}`)).toEqual([
194
- "claude:global",
195
- "claude:project",
196
- "cursor:global",
197
- "cursor:project",
198
- "codex:global",
199
- "codex:global",
200
- "codex:project",
201
- "deepccc:global",
202
- "deepccc:project",
203
- ]);
204
- });
205
-
206
- it("points codex global dirs at ~/.codex/skills and ~/.agents/skills", () => {
207
- const dirs = buildDefaultSkillDirs("C:/proj").filter((d) => d.source === "codex" && d.scope === "global");
208
- expect(dirs.map((d) => d.dir)).toEqual([
209
- join(require("node:os").homedir(), ".codex", "skills"),
210
- join(require("node:os").homedir(), ".agents", "skills"),
211
- ]);
212
- });
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
-
230
- describe("buildSkillsIndexPrompt", () => {
231
- it("renders index with source markers and the skill creation convention", () => {
232
- const prompt = buildSkillsIndexPrompt([
233
- {
234
- name: "feishu-doc",
235
- description: "下载飞书文档",
236
- skillPath: "C:/x/feishu-doc/SKILL.md",
237
- source: "codex",
238
- scope: "global",
239
- },
240
- ]);
241
-
242
- expect(prompt).toContain("## Available Skills");
243
- expect(prompt).toContain("**feishu-doc**");
244
- expect(prompt).toContain("[codex:global]");
245
- expect(prompt).toContain("## Creating Skills");
246
- expect(prompt).toContain(".deepccc/skills");
247
- expect(prompt).toContain("read_file");
248
- });
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
-
266
- it("returns empty string for no skills", () => {
267
- expect(buildSkillsIndexPrompt([])).toBe("");
268
- });
269
- });
270
-
271
- describe("buildSkillTemplate", () => {
272
- it("renders a Codex-style SKILL.md with frontmatter", () => {
273
- const tpl = buildSkillTemplate("my-skill", "does something");
274
- expect(tpl.startsWith("---")).toBe(true);
275
- expect(tpl).toContain("name: my-skill");
276
- expect(tpl).toContain("description: does something");
277
- expect(tpl).toContain("# my-skill");
278
- });
279
-
280
- it("defaults description to empty when omitted", () => {
281
- const tpl = buildSkillTemplate("bare-skill", "");
282
- expect(tpl).toContain("description: ");
283
- });
284
- });
1
+ import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
+ import { mkdtempSync, rmSync, writeFileSync, mkdirSync, utimesSync } from "node:fs";
3
+ import { homedir, tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ import {
7
+ normalizeSkillPathForPrompt,
8
+ parseSkillFrontmatter,
9
+ scanSkillsDirs,
10
+ buildDefaultSkillDirs,
11
+ buildSkillsIndexPrompt,
12
+ buildSkillTemplate,
13
+ type SkillDirSpec,
14
+ type SkillSource,
15
+ type SkillScope,
16
+ } from "../../deepccc-agent/src/skills.ts";
17
+
18
+ let tempRoot: string;
19
+
20
+ beforeEach(() => {
21
+ tempRoot = mkdtempSync(join(tmpdir(), "deepccc-skills-"));
22
+ });
23
+
24
+ afterEach(() => {
25
+ try {
26
+ rmSync(tempRoot, { recursive: true, force: true });
27
+ } catch {}
28
+ });
29
+
30
+ function makeSkill(specDir: string, name: string, description: string): string {
31
+ const dir = join(specDir, name);
32
+ mkdirSync(dir, { recursive: true });
33
+ const skillPath = join(dir, "SKILL.md");
34
+ writeFileSync(skillPath, `---\nname: ${name}\ndescription: ${description}\n---\n\nbody\n`, "utf8");
35
+ return skillPath;
36
+ }
37
+
38
+ function spec(
39
+ dir: string,
40
+ source: SkillSource,
41
+ scope: SkillScope = "global",
42
+ ): SkillDirSpec {
43
+ return { dir, source, scope };
44
+ }
45
+
46
+ describe("parseSkillFrontmatter", () => {
47
+ it("parses name and description from frontmatter", () => {
48
+ const content = [
49
+ "---",
50
+ "name: feishu-doc-download-md",
51
+ "description: 下载飞书文档为 Markdown",
52
+ "---",
53
+ "",
54
+ "# 正文",
55
+ ].join("\n");
56
+ expect(parseSkillFrontmatter(content)).toEqual({
57
+ name: "feishu-doc-download-md",
58
+ description: "下载飞书文档为 Markdown",
59
+ });
60
+ });
61
+
62
+ it("returns null when there is no frontmatter", () => {
63
+ expect(parseSkillFrontmatter("# just a heading")).toBeNull();
64
+ });
65
+
66
+ it("tolerates missing description", () => {
67
+ expect(parseSkillFrontmatter("---\nname: minimal-skill\n---\n\nbody")).toEqual({
68
+ name: "minimal-skill",
69
+ description: "",
70
+ });
71
+ });
72
+
73
+ it("handles CRLF line endings", () => {
74
+ const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 描述\r\n---\r\n\r\nbody";
75
+ expect(parseSkillFrontmatter(content)).toEqual({
76
+ name: "crlf-skill",
77
+ description: "CRLF 描述",
78
+ });
79
+ });
80
+ });
81
+
82
+ describe("scanSkillsDirs priority matrix", () => {
83
+ it("codex wins over cursor, cursor wins over claude for same-name skills", async () => {
84
+ const claudeDir = join(tempRoot, "claude");
85
+ const cursorDir = join(tempRoot, "cursor");
86
+ const codexDir = join(tempRoot, "codex");
87
+ makeSkill(claudeDir, "dupe", "claude version");
88
+ makeSkill(cursorDir, "dupe", "cursor version");
89
+ makeSkill(codexDir, "dupe", "codex version");
90
+ makeSkill(codexDir, "only-codex", "codex only");
91
+
92
+ const skills = await scanSkillsDirs([
93
+ spec(claudeDir, "claude"),
94
+ spec(cursorDir, "cursor"),
95
+ spec(codexDir, "codex"),
96
+ ]);
97
+
98
+ const byName = new Map(skills.map((s) => [s.name, s]));
99
+ expect(byName.get("dupe")?.description).toBe("codex version");
100
+ expect(byName.get("dupe")?.source).toBe("codex");
101
+ expect(byName.get("dupe")?.skillPath).toContain(join("codex", "dupe"));
102
+ expect(byName.get("only-codex")?.source).toBe("codex");
103
+ });
104
+
105
+ it("project scope wins over global scope within the same source", async () => {
106
+ const globalCodex = join(tempRoot, "codex-global");
107
+ const projectCodex = join(tempRoot, "codex-project");
108
+ makeSkill(globalCodex, "dup", "global version");
109
+ makeSkill(projectCodex, "dup", "project version");
110
+
111
+ const skills = await scanSkillsDirs([
112
+ spec(globalCodex, "codex", "global"),
113
+ spec(projectCodex, "codex", "project"),
114
+ ]);
115
+
116
+ const byName = new Map(skills.map((s) => [s.name, s]));
117
+ expect(byName.get("dup")?.description).toBe("project version");
118
+ expect(byName.get("dup")?.scope).toBe("project");
119
+ });
120
+
121
+ it("deepccc source has the highest priority over codex", async () => {
122
+ const codexDir = join(tempRoot, "codex");
123
+ const deepcccDir = join(tempRoot, "deepccc");
124
+ makeSkill(codexDir, "dup", "from codex");
125
+ makeSkill(deepcccDir, "dup", "from deepccc");
126
+
127
+ const skills = await scanSkillsDirs([
128
+ spec(codexDir, "codex"),
129
+ spec(deepcccDir, "deepccc"),
130
+ ]);
131
+
132
+ expect(skills.find((s) => s.name === "dup")?.description).toBe("from deepccc");
133
+ expect(skills.find((s) => s.name === "dup")?.source).toBe("deepccc");
134
+ });
135
+
136
+ it("skips hidden dirs, dirs without SKILL.md, and missing dirs", async () => {
137
+ const dir = join(tempRoot, "src");
138
+ mkdirSync(join(dir, ".system"), { recursive: true });
139
+ writeFileSync(join(dir, ".system", "SKILL.md"), "---\nname: system-skill\ndescription: x\n---\n", "utf8");
140
+ mkdirSync(join(dir, "no-skill-dir"));
141
+
142
+ makeSkill(dir, "ok", "fine");
143
+ const skills = await scanSkillsDirs([
144
+ spec(join(tempRoot, "missing-dir"), "codex"),
145
+ spec(dir, "codex"),
146
+ ]);
147
+
148
+ expect(skills).toHaveLength(1);
149
+ expect(skills[0].name).toBe("ok");
150
+ });
151
+ });
152
+
153
+ describe("scanSkillsDirs hot reload (mtime cache)", () => {
154
+ it("re-reads a skill after its SKILL.md content changes", async () => {
155
+ const dir = join(tempRoot, "src");
156
+ const skillPath = makeSkill(dir, "live", "v1");
157
+
158
+ const first = await scanSkillsDirs([spec(dir, "deepccc")]);
159
+ expect(first.find((s) => s.name === "live")?.description).toBe("v1");
160
+
161
+ writeFileSync(skillPath, "---\nname: live\ndescription: v2\n---\n\nbody\n", "utf8");
162
+ utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); // 强制 mtime 前进
163
+
164
+ const second = await scanSkillsDirs([spec(dir, "deepccc")]);
165
+ expect(second.find((s) => s.name === "live")?.description).toBe("v2");
166
+ });
167
+
168
+ it("new skill dirs are picked up on the next scan", async () => {
169
+ const dir = join(tempRoot, "src");
170
+ makeSkill(dir, "a", "A");
171
+
172
+ const first = await scanSkillsDirs([spec(dir, "deepccc")]);
173
+ expect(first).toHaveLength(1);
174
+
175
+ makeSkill(dir, "b", "B"); // 新技能,无需改 mtime(目录枚举每次都做)
176
+ const second = await scanSkillsDirs([spec(dir, "deepccc")]);
177
+ expect(second.map((s) => s.name).sort()).toEqual(["a", "b"]);
178
+ });
179
+
180
+ it("unchanged skills return identical results across scans", async () => {
181
+ const dir = join(tempRoot, "src");
182
+ makeSkill(dir, "a", "A");
183
+
184
+ const first = await scanSkillsDirs([spec(dir, "deepccc")]);
185
+ const second = await scanSkillsDirs([spec(dir, "deepccc")]);
186
+ expect(second).toEqual(first);
187
+ });
188
+ });
189
+
190
+ describe("buildDefaultSkillDirs", () => {
191
+ it("orders dirs low->high priority: claude < cursor < codex < deepccc, project after global", () => {
192
+ const dirs = buildDefaultSkillDirs("C:/proj");
193
+ expect(dirs.map((d) => `${d.source}:${d.scope}`)).toEqual([
194
+ "claude:global",
195
+ "claude:project",
196
+ "cursor:global",
197
+ "cursor:project",
198
+ "codex:global",
199
+ "codex:global",
200
+ "codex:project",
201
+ "deepccc:global",
202
+ "deepccc:project",
203
+ ]);
204
+ });
205
+
206
+ it("points codex global dirs at ~/.codex/skills and ~/.agents/skills", () => {
207
+ const dirs = buildDefaultSkillDirs("C:/proj").filter((d) => d.source === "codex" && d.scope === "global");
208
+ expect(dirs.map((d) => d.dir)).toEqual([
209
+ join(require("node:os").homedir(), ".codex", "skills"),
210
+ join(require("node:os").homedir(), ".agents", "skills"),
211
+ ]);
212
+ });
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
+
230
+ describe("buildSkillsIndexPrompt", () => {
231
+ it("renders index with source markers and the skill creation convention", () => {
232
+ const prompt = buildSkillsIndexPrompt([
233
+ {
234
+ name: "feishu-doc",
235
+ description: "下载飞书文档",
236
+ skillPath: "C:/x/feishu-doc/SKILL.md",
237
+ source: "codex",
238
+ scope: "global",
239
+ },
240
+ ]);
241
+
242
+ expect(prompt).toContain("## Available Skills");
243
+ expect(prompt).toContain("**feishu-doc**");
244
+ expect(prompt).toContain("[codex:global]");
245
+ expect(prompt).toContain("## Creating Skills");
246
+ expect(prompt).toContain(".deepccc/skills");
247
+ expect(prompt).toContain("read_file");
248
+ });
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
+
266
+ it("returns empty string for no skills", () => {
267
+ expect(buildSkillsIndexPrompt([])).toBe("");
268
+ });
269
+ });
270
+
271
+ describe("buildSkillTemplate", () => {
272
+ it("renders a Codex-style SKILL.md with frontmatter", () => {
273
+ const tpl = buildSkillTemplate("my-skill", "does something");
274
+ expect(tpl.startsWith("---")).toBe(true);
275
+ expect(tpl).toContain("name: my-skill");
276
+ expect(tpl).toContain("description: does something");
277
+ expect(tpl).toContain("# my-skill");
278
+ });
279
+
280
+ it("defaults description to empty when omitted", () => {
281
+ const tpl = buildSkillTemplate("bare-skill", "");
282
+ expect(tpl).toContain("description: ");
283
+ });
284
+ });