chatccc 0.2.226 → 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.
Files changed (64) hide show
  1. package/.agents/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  2. package/.claude/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  3. package/.cursor/skills/create-chatccc-feishu-app/SKILL.md +85 -85
  4. package/README.md +90 -90
  5. package/package.json +1 -1
  6. package/src/__tests__/agent-activity.test.ts +76 -76
  7. package/src/__tests__/builtin-chat-session.test.ts +350 -350
  8. package/src/__tests__/builtin-config.test.ts +26 -26
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +275 -275
  11. package/src/__tests__/builtin-permissions.test.ts +211 -211
  12. package/src/__tests__/builtin-session-select.test.ts +116 -116
  13. package/src/__tests__/builtin-skills.test.ts +185 -74
  14. package/src/__tests__/card-action-routing.test.ts +18 -18
  15. package/src/__tests__/ccc-adapter.test.ts +136 -136
  16. package/src/__tests__/claude-adapter.test.ts +614 -614
  17. package/src/__tests__/codex-adapter.test.ts +58 -58
  18. package/src/__tests__/codex-raw-stream-log.test.ts +170 -170
  19. package/src/__tests__/cursor-adapter.test.ts +268 -268
  20. package/src/__tests__/feishu-avatar.test.ts +164 -164
  21. package/src/__tests__/feishu-message-ingress.test.ts +138 -138
  22. package/src/__tests__/package-files.test.ts +24 -24
  23. package/src/__tests__/progress-reducer.test.ts +110 -110
  24. package/src/__tests__/response-stall.test.ts +49 -49
  25. package/src/__tests__/sim-platform.test.ts +16 -16
  26. package/src/__tests__/startup-lifecycle.test.ts +231 -231
  27. package/src/__tests__/stop-session.test.ts +34 -34
  28. package/src/__tests__/terminal-renderer.test.ts +247 -247
  29. package/src/__tests__/update-command-guard.test.ts +144 -144
  30. package/src/__tests__/web-ui.test.ts +326 -326
  31. package/src/adapters/adapter-interface.ts +18 -18
  32. package/src/adapters/ccc-adapter.ts +131 -131
  33. package/src/adapters/claude-adapter.ts +620 -620
  34. package/src/adapters/codex-adapter.ts +426 -426
  35. package/src/adapters/cursor-adapter.ts +681 -681
  36. package/src/agent-activity.ts +170 -170
  37. package/src/agent-delegate-task.ts +91 -91
  38. package/src/builtin/cli.ts +61 -2
  39. package/src/builtin/config.ts +84 -84
  40. package/src/builtin/context.ts +323 -323
  41. package/src/builtin/file-log.ts +38 -38
  42. package/src/builtin/index.ts +44 -24
  43. package/src/builtin/proc-tree-kill.ts +61 -61
  44. package/src/builtin/progress/cards-helpers.ts +76 -76
  45. package/src/builtin/progress/reducer.ts +108 -108
  46. package/src/builtin/progress/terminal-renderer.ts +294 -294
  47. package/src/builtin/progress/view.ts +77 -77
  48. package/src/builtin/raw-stream-log.ts +124 -124
  49. package/src/builtin/session-select.ts +48 -48
  50. package/src/builtin/skills.ts +126 -44
  51. package/src/card-action-routing.ts +14 -14
  52. package/src/feishu-api.ts +193 -193
  53. package/src/feishu-message-ingress.ts +195 -195
  54. package/src/index.ts +306 -306
  55. package/src/orchestrator.ts +2388 -2388
  56. package/src/platform-adapter.ts +6 -6
  57. package/src/progress/reducer.ts +108 -108
  58. package/src/progress/terminal-renderer.ts +294 -294
  59. package/src/progress/view.ts +77 -77
  60. package/src/response-stall.ts +28 -28
  61. package/src/session-chat-binding.ts +82 -82
  62. package/src/startup-lifecycle.ts +250 -250
  63. package/src/stream-state.ts +18 -18
  64. package/src/update-command-guard.ts +165 -165
@@ -1,21 +1,41 @@
1
1
  /**
2
- * builtin/skills.ts — Codex-style skills 支持
2
+ * skills.ts — 多来源技能扫描(DeepCCC 统一入口)
3
3
  *
4
- * 从用户级(~/.codex/skills、~/.agents/skills)和项目级(<cwd>/.codex/skills)
5
- * 扫描 Codex 目录式 skill(<name>/SKILL.md),解析 frontmatter 中的
6
- * name + description,生成索引注入 system prompt。模型按需用 read_file
7
- * 读取 SKILL.md 全文并执行(索引注入省 token,触发靠 description + 指令)。
4
+ * 并行扫描 Claude / Codex / Cursor / DeepCCC 四套目录式技能
5
+ * (<name>/SKILL.md + YAML frontmatter,三套生态同构)。
6
+ *
7
+ * 同名优先级(高 低):deepccc > codex > cursor > claude;
8
+ * 同来源内:project(项目级)> global(用户级)。
9
+ * 目录列表按低 → 高排列,扫描时后者覆盖前者,天然实现优先级。
10
+ *
11
+ * 热加载:SKILL.md 内容带 mtime 缓存,文件变化时自动重读;
12
+ * 目录枚举每次都做(新技能目录立即被发现)。因此"创建技能 →
13
+ * 下一次对话自动生效",无需重启,也无需常驻 watcher。
8
14
  */
9
15
 
10
- import { readFileSync, readdirSync } from "node:fs";
16
+ import { readdirSync } from "node:fs";
17
+ import { readFile, stat } from "node:fs/promises";
11
18
  import { homedir } from "node:os";
12
19
  import { join } from "node:path";
13
20
 
21
+ export type SkillSource = "deepccc" | "codex" | "cursor" | "claude";
22
+ export type SkillScope = "global" | "project";
23
+
14
24
  export interface BuiltinSkill {
15
25
  name: string;
16
26
  description: string;
17
27
  /** SKILL.md 的绝对路径 */
18
28
  skillPath: string;
29
+ /** 来源(优先级 deepccc > codex > cursor > claude) */
30
+ source: SkillSource;
31
+ /** global = 用户级;project = 项目级(同来源内 project > global) */
32
+ scope: SkillScope;
33
+ }
34
+
35
+ export interface SkillDirSpec {
36
+ dir: string;
37
+ source: SkillSource;
38
+ scope: SkillScope;
19
39
  }
20
40
 
21
41
  /** 解析 SKILL.md frontmatter(兼容 CRLF),返回 name + description;无 frontmatter 返回 null */
@@ -34,41 +54,65 @@ export function parseSkillFrontmatter(
34
54
  };
35
55
  }
36
56
 
57
+ // ---------------------------------------------------------------------------
58
+ // mtime 热加载缓存:同一进程内重复扫描命中缓存(stat 校验),文件变化自动重读
59
+ // ---------------------------------------------------------------------------
60
+
61
+ const skillFileCache = new Map<string, { mtimeMs: number; content: string }>();
62
+
63
+ async function readSkillFile(skillPath: string): Promise<string | null> {
64
+ let st;
65
+ try {
66
+ st = await stat(skillPath);
67
+ } catch {
68
+ return null;
69
+ }
70
+ if (!st.isFile()) return null;
71
+ const cached = skillFileCache.get(skillPath);
72
+ if (cached && cached.mtimeMs === st.mtimeMs) return cached.content;
73
+ const content = await readFile(skillPath, "utf8");
74
+ skillFileCache.set(skillPath, { mtimeMs: st.mtimeMs, content });
75
+ return content;
76
+ }
77
+
37
78
  /**
38
- * 扫描多个 skill 目录,返回去重后的 skill 列表。
39
- * 同名 skill 后面的目录覆盖前面的(调用方应把项目级目录放最后)。
40
- * 隐藏目录(.system 等)和无 SKILL.md 的目录会被跳过。
79
+ * 扫描多个 skill 目录(并行读取),按 name 去重。
80
+ * 同名技能:后面的 spec(高优先级)覆盖前面的(低优先级)。
81
+ * 隐藏目录(.system 等)和无 SKILL.md 的目录会被跳过;缺失目录跳过。
41
82
  */
42
- export function scanSkillsDirs(dirs: string[]): BuiltinSkill[] {
83
+ export async function scanSkillsDirs(dirs: SkillDirSpec[]): Promise<BuiltinSkill[]> {
43
84
  const byName = new Map<string, BuiltinSkill>();
44
85
 
45
- for (const dir of dirs) {
86
+ for (const spec of dirs) {
46
87
  let entries;
47
88
  try {
48
- entries = readdirSync(dir, { withFileTypes: true });
89
+ entries = readdirSync(spec.dir, { withFileTypes: true });
49
90
  } catch {
50
91
  continue; // 目录不存在或不可读:跳过
51
92
  }
52
93
 
53
- for (const entry of entries) {
54
- if (!entry.isDirectory()) continue;
55
- if (entry.name.startsWith(".")) continue; // 排除 .system 等隐藏/内置目录
56
-
57
- const skillPath = join(dir, entry.name, "SKILL.md");
58
- let content: string;
59
- try {
60
- content = readFileSync(skillPath, "utf-8");
61
- } catch {
62
- continue; // 没有 SKILL.md 的目录不是 skill
63
- }
64
-
65
- const parsed = parseSkillFrontmatter(content);
66
- if (!parsed) continue;
67
-
68
- byName.set(parsed.name, {
69
- name: parsed.name,
70
- description: parsed.description,
71
- skillPath,
94
+ // 目录内所有候选 SKILL.md 并行读取(读文件是扫描的瓶颈)
95
+ const results = await Promise.all(
96
+ entries
97
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
98
+ .map(async (entry) => {
99
+ const skillPath = join(spec.dir, entry.name, "SKILL.md");
100
+ const content = await readSkillFile(skillPath);
101
+ if (content === null) return null;
102
+ const parsed = parseSkillFrontmatter(content);
103
+ if (!parsed) return null;
104
+ return { ...parsed, skillPath };
105
+ }),
106
+ );
107
+
108
+ for (const result of results) {
109
+ if (!result) continue;
110
+ byName.set(result.name, {
111
+ name: result.name,
112
+ description: result.description,
113
+ skillPath: result.skillPath,
114
+ source: spec.source,
115
+ scope: spec.scope,
72
116
  });
73
117
  }
74
118
  }
@@ -77,32 +121,70 @@ export function scanSkillsDirs(dirs: string[]): BuiltinSkill[] {
77
121
  }
78
122
 
79
123
  /**
80
- * 默认 skill 扫描目录:
81
- * 1. ~/.codex/skills(Codex CLI 旧路径,用户实际在用的地方)
82
- * 2. ~/.agents/skills(Codex 标准全局目录)
83
- * 3. <cwd>/.codex/skills(项目级,优先级最高,放最后)
124
+ * 默认技能扫描目录(按优先级从低到高排列,扫描时后者覆盖前者):
125
+ * claude(global→project) < cursor(global→project) < codex(global→project) < deepccc(global→project)
126
+ * 其中 codex 全局包含 ~/.codex/skills(CLI 旧路径)与 ~/.agents/skills(标准全局目录)。
84
127
  */
85
- export function buildDefaultSkillDirs(cwd: string): string[] {
128
+ export function buildDefaultSkillDirs(cwd: string): SkillDirSpec[] {
129
+ const h = homedir();
86
130
  return [
87
- join(homedir(), ".codex", "skills"),
88
- join(homedir(), ".agents", "skills"),
89
- join(cwd, ".codex", "skills"),
131
+ { dir: join(h, ".claude", "skills"), source: "claude", scope: "global" },
132
+ { dir: join(cwd, ".claude", "skills"), source: "claude", scope: "project" },
133
+ { dir: join(h, ".cursor", "skills"), source: "cursor", scope: "global" },
134
+ { dir: join(cwd, ".cursor", "skills"), source: "cursor", scope: "project" },
135
+ { dir: join(h, ".codex", "skills"), source: "codex", scope: "global" },
136
+ { dir: join(h, ".agents", "skills"), source: "codex", scope: "global" },
137
+ { dir: join(cwd, ".codex", "skills"), source: "codex", scope: "project" },
138
+ { dir: join(h, ".deepccc", "skills"), source: "deepccc", scope: "global" },
139
+ { dir: join(cwd, ".deepccc", "skills"), source: "deepccc", scope: "project" },
90
140
  ];
91
141
  }
92
142
 
93
143
  /**
94
144
  * 生成 skill 索引提示词(注入 system prompt)。
95
- * 索引只含 name + description + 路径,并指示模型在任务匹配时
96
- * 先用 read_file 读取 SKILL.md 全文再执行——这是触发率的关键。
145
+ * 索引只含 name + description + 来源 + 路径,并指示模型在任务匹配时
146
+ * 先用 read_file 读取 SKILL.md 全文再执行;同时声明"创建技能"约定
147
+ * (模型在对话中应把新技能创建到 ~/.deepccc/skills 或项目 .deepccc/skills)。
97
148
  */
98
149
  export function buildSkillsIndexPrompt(skills: BuiltinSkill[]): string {
99
150
  if (skills.length === 0) return "";
100
151
 
101
152
  const lines = [
102
- "## Available Skills (Codex-style)",
103
- "The following Codex-style skills are available on this machine. When a user request matches a skill's description, first read its full SKILL.md with read_file, then follow the instructions in it exactly.",
153
+ "## Available Skills",
154
+ "Skills are scanned in parallel from Claude/Codex/Cursor/DeepCCC skill directories.",
155
+ "On name conflicts: DeepCCC > Codex > Cursor > Claude wins; within one source, project scope wins over global.",
156
+ "When a user request matches a skill's description, first read its full SKILL.md with read_file, then follow the instructions in it exactly.",
157
+ "",
158
+ ...skills.map((s) => `- **${s.name}** [${s.source}:${s.scope}] (\`${s.skillPath}\`): ${s.description || "(no description)"}`),
159
+ "",
160
+ "## Creating Skills",
161
+ "When the user asks to create a skill, create it as a Codex-style directory skill at",
162
+ "~/.deepccc/skills/<name>/SKILL.md (global, default) or <cwd>/.deepccc/skills/<name>/SKILL.md (project, only when the user explicitly asks for a project-scoped skill).",
163
+ "SKILL.md format:",
164
+ "```",
165
+ "---",
166
+ "name: <skill-name>",
167
+ "description: <one-line description>",
168
+ "---",
104
169
  "",
105
- ...skills.map((s) => `- **${s.name}** (\`${s.skillPath}\`): ${s.description || "(no description)"}`),
170
+ "<instructions>",
171
+ "```",
172
+ "New skills are picked up automatically on the next message (hot reload); no restart is needed.",
106
173
  ];
107
174
  return lines.join("\n");
108
175
  }
176
+
177
+ /** 生成 Codex 结构的新技能 SKILL.md 模板(供 CLI skill create / 对话创建约定共用) */
178
+ export function buildSkillTemplate(name: string, description: string): string {
179
+ return [
180
+ "---",
181
+ `name: ${name}`,
182
+ `description: ${description}`,
183
+ "---",
184
+ "",
185
+ `# ${name}`,
186
+ "",
187
+ "<skill instructions>",
188
+ "",
189
+ ].join("\n");
190
+ }
@@ -1,14 +1,14 @@
1
- export type FeishuCommandChatType = "p2p" | "group";
2
-
3
- type SessionRegistryForRouting = Record<string, { chatType?: string }>;
4
-
5
- /**
6
- * Feishu card action callbacks do not include the chat type. Recover it from
7
- * the persisted binding so buttons clicked in a private chat stay in p2p.
8
- */
9
- export function resolveFeishuCardActionChatType(
10
- chatId: string,
11
- registry: SessionRegistryForRouting,
12
- ): FeishuCommandChatType {
13
- return registry[chatId]?.chatType === "p2p" ? "p2p" : "group";
14
- }
1
+ export type FeishuCommandChatType = "p2p" | "group";
2
+
3
+ type SessionRegistryForRouting = Record<string, { chatType?: string }>;
4
+
5
+ /**
6
+ * Feishu card action callbacks do not include the chat type. Recover it from
7
+ * the persisted binding so buttons clicked in a private chat stay in p2p.
8
+ */
9
+ export function resolveFeishuCardActionChatType(
10
+ chatId: string,
11
+ registry: SessionRegistryForRouting,
12
+ ): FeishuCommandChatType {
13
+ return registry[chatId]?.chatType === "p2p" ? "p2p" : "group";
14
+ }