chatccc 0.2.221 → 0.2.223

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatccc",
3
- "version": "0.2.221",
3
+ "version": "0.2.223",
4
4
  "description": "Feishu bot bridge for Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -53,6 +53,46 @@ afterEach(() => {
53
53
  config.rawStreamLogs = structuredClone(originalRawStreamLogs);
54
54
  });
55
55
 
56
+ describe("ChatSession codex-style skills", () => {
57
+ it("injects skill index into system prompt from skillsDirs", async () => {
58
+ const { ChatSession } = await import("../builtin/index.ts");
59
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-skills-"));
60
+ const skillsDir = join(dir, ".codex", "skills");
61
+ await mkdir(join(skillsDir, "demo-skill"), { recursive: true });
62
+ await writeFile(
63
+ join(skillsDir, "demo-skill", "SKILL.md"),
64
+ "---\nname: demo-skill\ndescription: 演示技能\n---\n\n# 演示",
65
+ "utf-8",
66
+ );
67
+ streamTextMock.mockReturnValueOnce({ textStream: textStream() });
68
+
69
+ const session = new ChatSession(
70
+ { apiKey: "sk-test" },
71
+ { cwd: dir, sessionId: "skill-index", skillsDirs: [skillsDir] },
72
+ );
73
+ await collect(session.chat("hi"));
74
+
75
+ const system = streamTextMock.mock.calls.at(-1)?.[0].system as string;
76
+ expect(system).toContain("## Available Skills");
77
+ expect(system).toContain("demo-skill");
78
+ expect(system).toContain("演示技能");
79
+ });
80
+
81
+ it("skips skill injection when no skills are found", async () => {
82
+ const { ChatSession } = await import("../builtin/index.ts");
83
+ const dir = await mkdtemp(join(tmpdir(), "chatccc-session-no-skills-"));
84
+ streamTextMock.mockReturnValueOnce({ textStream: textStream() });
85
+
86
+ const session = new ChatSession(
87
+ { apiKey: "sk-test" },
88
+ { cwd: dir, sessionId: "no-skills", skillsDirs: [join(dir, "missing")] },
89
+ );
90
+ await collect(session.chat("hi"));
91
+
92
+ const system = streamTextMock.mock.calls.at(-1)?.[0].system as string;
93
+ expect(system).not.toContain("## Available Skills");
94
+ });
95
+ });
56
96
  describe("ChatSession context management", () => {
57
97
  it("injects cwd project instruction files before runtime workspace details", async () => {
58
98
  const { ChatSession } = await import("../builtin/index.ts");
@@ -0,0 +1,141 @@
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,6 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
3
  import { cardJsonToPlainText } from "../card-plain-text.ts";
4
+ import { progressView } from "../progress/view.ts";
4
5
  import {
5
6
  buildHelpCard,
6
7
  buildProgressCard,
@@ -16,11 +17,11 @@ describe("cardJsonToPlainText", () => {
16
17
  expect(text).toContain("/new");
17
18
  expect(text).toContain("/new cursor");
18
19
  expect(text).toContain("/new codex");
19
- expect(text).toContain("/restart");
20
- expect(text).toContain("/update");
21
- expect(text).toContain("/cd");
22
- expect(text).toContain("/abd");
23
- });
20
+ expect(text).toContain("/restart");
21
+ expect(text).toContain("/update");
22
+ expect(text).toContain("/cd");
23
+ expect(text).toContain("/abd");
24
+ });
24
25
 
25
26
  it("converts status cards from v1 card format", () => {
26
27
  const text = cardJsonToPlainText(buildStatusCard("status body", "green"));
@@ -30,7 +31,7 @@ describe("cardJsonToPlainText", () => {
30
31
  });
31
32
 
32
33
  it("converts schema 2.0 progress cards", () => {
33
- const text = cardJsonToPlainText(buildProgressCard("stream body"));
34
+ const text = cardJsonToPlainText(buildProgressCard(progressView({ text: "stream body" })));
34
35
 
35
36
  expect(text).toContain("# 生成中...");
36
37
  expect(text).toContain("stream body");