chatccc 0.2.225 → 0.2.227

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.
@@ -1,141 +1,252 @@
1
- import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
-
5
- import { afterEach, describe, expect, it } from "vitest";
6
-
7
- import {
8
- buildSkillsIndexPrompt,
9
- parseSkillFrontmatter,
10
- scanSkillsDirs,
11
- } from "../builtin/skills.ts";
12
-
13
- const tempDirs: string[] = [];
14
-
15
- async function makeTempDir(): Promise<string> {
16
- const dir = await mkdtemp(join(tmpdir(), "chatccc-skills-"));
17
- tempDirs.push(dir);
18
- return dir;
19
- }
20
-
21
- afterEach(async () => {
22
- await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
23
- });
24
-
25
- describe("parseSkillFrontmatter", () => {
26
- it("parses name and description from frontmatter", () => {
27
- const content = [
28
- "---",
29
- "name: feishu-doc-download-md",
30
- "description: 下载飞书文档为 Markdown",
31
- "---",
32
- "",
33
- "# 正文",
34
- ].join("\n");
35
- expect(parseSkillFrontmatter(content)).toEqual({
36
- name: "feishu-doc-download-md",
37
- description: "下载飞书文档为 Markdown",
38
- });
39
- });
40
-
41
- it("returns null when there is no frontmatter", () => {
42
- expect(parseSkillFrontmatter("# just a heading")).toBeNull();
43
- });
44
-
45
- it("tolerates missing description", () => {
46
- expect(parseSkillFrontmatter("---\nname: minimal-skill\n---\n\nbody")).toEqual({
47
- name: "minimal-skill",
48
- description: "",
49
- });
50
- });
51
-
52
- it("handles CRLF line endings", () => {
53
- const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 描述\r\n---\r\n\r\nbody";
54
- expect(parseSkillFrontmatter(content)).toEqual({
55
- name: "crlf-skill",
56
- description: "CRLF 描述",
57
- });
58
- });
59
- });
60
-
61
- describe("scanSkillsDirs", () => {
62
- it("scans multiple dirs, skips hidden/system dirs, dedupes by name (later dir wins)", async () => {
63
- const dir = await makeTempDir();
64
- const userA = join(dir, "codex-skills");
65
- const userB = join(dir, "agents-skills");
66
- const project = join(dir, "project-codex");
67
- await mkdir(join(userA, "feishu-doc"), { recursive: true });
68
- await mkdir(join(userA, ".system"), { recursive: true });
69
- await mkdir(join(userA, "no-skill-dir"));
70
- await mkdir(join(userB, "feishu-doc"), { recursive: true });
71
- await mkdir(join(userB, "another"), { recursive: true });
72
- await mkdir(join(project, "feishu-doc"), { recursive: true });
73
-
74
- await writeFile(
75
- join(userA, "feishu-doc", "SKILL.md"),
76
- "---\nname: feishu-doc\ndescription: 用户级 A\n---\n",
77
- "utf8",
78
- );
79
- await writeFile(
80
- join(userA, ".system", "SKILL.md"),
81
- "---\nname: system-skill\ndescription: 内置\n---\n",
82
- "utf8",
83
- );
84
- await writeFile(
85
- join(userB, "feishu-doc", "SKILL.md"),
86
- "---\nname: feishu-doc\ndescription: 用户级 B\n---\n",
87
- "utf8",
88
- );
89
- await writeFile(
90
- join(userB, "another", "SKILL.md"),
91
- "---\nname: another\ndescription: 另一个\n---\n",
92
- "utf8",
93
- );
94
- await writeFile(
95
- join(project, "feishu-doc", "SKILL.md"),
96
- "---\nname: feishu-doc\ndescription: 项目级覆盖\n---\n",
97
- "utf8",
98
- );
99
-
100
- const skills = scanSkillsDirs([userA, userB, project]);
101
-
102
- // 去重:同名保留一个,后面的目录(项目级)覆盖前面的(用户级)
103
- expect(skills).toHaveLength(2);
104
- const byName = new Map(skills.map((s) => [s.name, s]));
105
- expect(byName.get("feishu-doc")?.description).toBe("项目级覆盖");
106
- expect(byName.get("feishu-doc")?.skillPath).toBe(join(project, "feishu-doc", "SKILL.md"));
107
- expect(byName.get("another")?.description).toBe("另一个");
108
- expect(byName.has("system-skill")).toBe(false); // 隐藏目录被排除
109
- });
110
-
111
- it("skips missing directories and dirs without SKILL.md", async () => {
112
- const dir = await makeTempDir();
113
- await mkdir(join(dir, "empty-dir"));
114
-
115
- const skills = scanSkillsDirs([join(dir, "missing-dir"), join(dir, "empty-dir")]);
116
-
117
- expect(skills).toEqual([]);
118
- });
119
- });
120
-
121
- describe("buildSkillsIndexPrompt", () => {
122
- it("renders a skill index with names, paths and descriptions", () => {
123
- const prompt = buildSkillsIndexPrompt([
124
- {
125
- name: "feishu-doc",
126
- description: "下载飞书文档",
127
- skillPath: "C:\\users\\x\\skills\\feishu-doc\\SKILL.md",
128
- },
129
- ]);
130
-
131
- expect(prompt).toContain("## Available Skills");
132
- expect(prompt).toContain("**feishu-doc**");
133
- expect(prompt).toContain("下载飞书文档");
134
- expect(prompt).toContain("C:\\users\\x\\skills\\feishu-doc\\SKILL.md");
135
- expect(prompt).toContain("read_file");
136
- });
137
-
138
- it("returns empty string for no skills", () => {
139
- expect(buildSkillsIndexPrompt([])).toBe("");
140
- });
141
- });
1
+ import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
+ import { mkdtempSync, rmSync, writeFileSync, mkdirSync, utimesSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ import {
7
+ parseSkillFrontmatter,
8
+ scanSkillsDirs,
9
+ buildDefaultSkillDirs,
10
+ buildSkillsIndexPrompt,
11
+ buildSkillTemplate,
12
+ type SkillDirSpec,
13
+ type SkillSource,
14
+ type SkillScope,
15
+ } from "../builtin/skills.ts";
16
+
17
+ let tempRoot: string;
18
+
19
+ beforeEach(() => {
20
+ tempRoot = mkdtempSync(join(tmpdir(), "deepccc-skills-"));
21
+ });
22
+
23
+ afterEach(() => {
24
+ try {
25
+ rmSync(tempRoot, { recursive: true, force: true });
26
+ } catch {}
27
+ });
28
+
29
+ function makeSkill(specDir: string, name: string, description: string): string {
30
+ const dir = join(specDir, name);
31
+ mkdirSync(dir, { recursive: true });
32
+ const skillPath = join(dir, "SKILL.md");
33
+ writeFileSync(skillPath, `---\nname: ${name}\ndescription: ${description}\n---\n\nbody\n`, "utf8");
34
+ return skillPath;
35
+ }
36
+
37
+ function spec(
38
+ dir: string,
39
+ source: SkillSource,
40
+ scope: SkillScope = "global",
41
+ ): SkillDirSpec {
42
+ return { dir, source, scope };
43
+ }
44
+
45
+ describe("parseSkillFrontmatter", () => {
46
+ it("parses name and description from frontmatter", () => {
47
+ const content = [
48
+ "---",
49
+ "name: feishu-doc-download-md",
50
+ "description: 涓嬭浇椋炰功鏂囨。涓?Markdown",
51
+ "---",
52
+ "",
53
+ "# 姝f枃",
54
+ ].join("\n");
55
+ expect(parseSkillFrontmatter(content)).toEqual({
56
+ name: "feishu-doc-download-md",
57
+ description: "涓嬭浇椋炰功鏂囨。涓?Markdown",
58
+ });
59
+ });
60
+
61
+ it("returns null when there is no frontmatter", () => {
62
+ expect(parseSkillFrontmatter("# just a heading")).toBeNull();
63
+ });
64
+
65
+ it("tolerates missing description", () => {
66
+ expect(parseSkillFrontmatter("---\nname: minimal-skill\n---\n\nbody")).toEqual({
67
+ name: "minimal-skill",
68
+ description: "",
69
+ });
70
+ });
71
+
72
+ it("handles CRLF line endings", () => {
73
+ const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 鎻忚堪\r\n---\r\n\r\nbody";
74
+ expect(parseSkillFrontmatter(content)).toEqual({
75
+ name: "crlf-skill",
76
+ description: "CRLF 鎻忚堪",
77
+ });
78
+ });
79
+ });
80
+
81
+ describe("scanSkillsDirs priority matrix", () => {
82
+ it("codex wins over cursor, cursor wins over claude for same-name skills", async () => {
83
+ const claudeDir = join(tempRoot, "claude");
84
+ const cursorDir = join(tempRoot, "cursor");
85
+ const codexDir = join(tempRoot, "codex");
86
+ makeSkill(claudeDir, "dupe", "claude version");
87
+ makeSkill(cursorDir, "dupe", "cursor version");
88
+ makeSkill(codexDir, "dupe", "codex version");
89
+ makeSkill(codexDir, "only-codex", "codex only");
90
+
91
+ const skills = await scanSkillsDirs([
92
+ spec(claudeDir, "claude"),
93
+ spec(cursorDir, "cursor"),
94
+ spec(codexDir, "codex"),
95
+ ]);
96
+
97
+ const byName = new Map(skills.map((s) => [s.name, s]));
98
+ expect(byName.get("dupe")?.description).toBe("codex version");
99
+ expect(byName.get("dupe")?.source).toBe("codex");
100
+ expect(byName.get("dupe")?.skillPath).toContain(join("codex", "dupe"));
101
+ expect(byName.get("only-codex")?.source).toBe("codex");
102
+ });
103
+
104
+ it("project scope wins over global scope within the same source", async () => {
105
+ const globalCodex = join(tempRoot, "codex-global");
106
+ const projectCodex = join(tempRoot, "codex-project");
107
+ makeSkill(globalCodex, "dup", "global version");
108
+ makeSkill(projectCodex, "dup", "project version");
109
+
110
+ const skills = await scanSkillsDirs([
111
+ spec(globalCodex, "codex", "global"),
112
+ spec(projectCodex, "codex", "project"),
113
+ ]);
114
+
115
+ const byName = new Map(skills.map((s) => [s.name, s]));
116
+ expect(byName.get("dup")?.description).toBe("project version");
117
+ expect(byName.get("dup")?.scope).toBe("project");
118
+ });
119
+
120
+ it("deepccc source has the highest priority over codex", async () => {
121
+ const codexDir = join(tempRoot, "codex");
122
+ const deepcccDir = join(tempRoot, "deepccc");
123
+ makeSkill(codexDir, "dup", "from codex");
124
+ makeSkill(deepcccDir, "dup", "from deepccc");
125
+
126
+ const skills = await scanSkillsDirs([
127
+ spec(codexDir, "codex"),
128
+ spec(deepcccDir, "deepccc"),
129
+ ]);
130
+
131
+ expect(skills.find((s) => s.name === "dup")?.description).toBe("from deepccc");
132
+ expect(skills.find((s) => s.name === "dup")?.source).toBe("deepccc");
133
+ });
134
+
135
+ it("skips hidden dirs, dirs without SKILL.md, and missing dirs", async () => {
136
+ const dir = join(tempRoot, "src");
137
+ mkdirSync(join(dir, ".system"), { recursive: true });
138
+ writeFileSync(join(dir, ".system", "SKILL.md"), "---\nname: system-skill\ndescription: x\n---\n", "utf8");
139
+ mkdirSync(join(dir, "no-skill-dir"));
140
+
141
+ makeSkill(dir, "ok", "fine");
142
+ const skills = await scanSkillsDirs([
143
+ spec(join(tempRoot, "missing-dir"), "codex"),
144
+ spec(dir, "codex"),
145
+ ]);
146
+
147
+ expect(skills).toHaveLength(1);
148
+ expect(skills[0].name).toBe("ok");
149
+ });
150
+ });
151
+
152
+ describe("scanSkillsDirs hot reload (mtime cache)", () => {
153
+ it("re-reads a skill after its SKILL.md content changes", async () => {
154
+ const dir = join(tempRoot, "src");
155
+ const skillPath = makeSkill(dir, "live", "v1");
156
+
157
+ const first = await scanSkillsDirs([spec(dir, "deepccc")]);
158
+ expect(first.find((s) => s.name === "live")?.description).toBe("v1");
159
+
160
+ writeFileSync(skillPath, "---\nname: live\ndescription: v2\n---\n\nbody\n", "utf8");
161
+ utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); // 寮哄埗 mtime 鍓嶈繘
162
+
163
+ const second = await scanSkillsDirs([spec(dir, "deepccc")]);
164
+ expect(second.find((s) => s.name === "live")?.description).toBe("v2");
165
+ });
166
+
167
+ it("new skill dirs are picked up on the next scan", async () => {
168
+ const dir = join(tempRoot, "src");
169
+ makeSkill(dir, "a", "A");
170
+
171
+ const first = await scanSkillsDirs([spec(dir, "deepccc")]);
172
+ expect(first).toHaveLength(1);
173
+
174
+ makeSkill(dir, "b", "B"); // 鏂版妧鑳斤紝鏃犻渶鏀?mtime锛堢洰褰曟灇涓炬瘡娆¢兘鍋氾級
175
+ const second = await scanSkillsDirs([spec(dir, "deepccc")]);
176
+ expect(second.map((s) => s.name).sort()).toEqual(["a", "b"]);
177
+ });
178
+
179
+ it("unchanged skills return identical results across scans", async () => {
180
+ const dir = join(tempRoot, "src");
181
+ makeSkill(dir, "a", "A");
182
+
183
+ const first = await scanSkillsDirs([spec(dir, "deepccc")]);
184
+ const second = await scanSkillsDirs([spec(dir, "deepccc")]);
185
+ expect(second).toEqual(first);
186
+ });
187
+ });
188
+
189
+ describe("buildDefaultSkillDirs", () => {
190
+ it("orders dirs low->high priority: claude < cursor < codex < deepccc, project after global", () => {
191
+ const dirs = buildDefaultSkillDirs("C:/proj");
192
+ expect(dirs.map((d) => `${d.source}:${d.scope}`)).toEqual([
193
+ "claude:global",
194
+ "claude:project",
195
+ "cursor:global",
196
+ "cursor:project",
197
+ "codex:global",
198
+ "codex:global",
199
+ "codex:project",
200
+ "deepccc:global",
201
+ "deepccc:project",
202
+ ]);
203
+ });
204
+
205
+ it("points codex global dirs at ~/.codex/skills and ~/.agents/skills", () => {
206
+ const dirs = buildDefaultSkillDirs("C:/proj").filter((d) => d.source === "codex" && d.scope === "global");
207
+ expect(dirs.map((d) => d.dir)).toEqual([
208
+ join(require("node:os").homedir(), ".codex", "skills"),
209
+ join(require("node:os").homedir(), ".agents", "skills"),
210
+ ]);
211
+ });
212
+ });
213
+
214
+ describe("buildSkillsIndexPrompt", () => {
215
+ it("renders index with source markers and the skill creation convention", () => {
216
+ const prompt = buildSkillsIndexPrompt([
217
+ {
218
+ name: "feishu-doc",
219
+ description: "涓嬭浇椋炰功鏂囨。",
220
+ skillPath: "C:/x/feishu-doc/SKILL.md",
221
+ source: "codex",
222
+ scope: "global",
223
+ },
224
+ ]);
225
+
226
+ expect(prompt).toContain("## Available Skills");
227
+ expect(prompt).toContain("**feishu-doc**");
228
+ expect(prompt).toContain("[codex:global]");
229
+ expect(prompt).toContain("## Creating Skills");
230
+ expect(prompt).toContain(".deepccc/skills");
231
+ expect(prompt).toContain("read_file");
232
+ });
233
+
234
+ it("returns empty string for no skills", () => {
235
+ expect(buildSkillsIndexPrompt([])).toBe("");
236
+ });
237
+ });
238
+
239
+ describe("buildSkillTemplate", () => {
240
+ it("renders a Codex-style SKILL.md with frontmatter", () => {
241
+ const tpl = buildSkillTemplate("my-skill", "does something");
242
+ expect(tpl.startsWith("---")).toBe(true);
243
+ expect(tpl).toContain("name: my-skill");
244
+ expect(tpl).toContain("description: does something");
245
+ expect(tpl).toContain("# my-skill");
246
+ });
247
+
248
+ it("defaults description to empty when omitted", () => {
249
+ const tpl = buildSkillTemplate("bare-skill", "");
250
+ expect(tpl).toContain("description: ");
251
+ });
252
+ });
@@ -33,6 +33,9 @@ function toChatSessionOptions(
33
33
  compactAtTokens: options.compactAtTokens,
34
34
  keepRecentMessages: options.keepRecentMessages,
35
35
  maxSteps: options.maxSteps,
36
+ // chatccc 无终端可交互,且对齐 claude/codex 适配器的 bypass 模式:
37
+ // 高危命令不询问,全部放行(与独立 deepccc CLI 的 ask 模式不同)
38
+ permissionMode: "bypass",
36
39
  };
37
40
  }
38
41