chatccc 0.2.231 → 0.2.233

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 (130) 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/agent-prompts/claude_specific.md +45 -45
  6. package/agent-prompts/codex_specific.md +2 -2
  7. package/agent-prompts/cursor_specific.md +13 -13
  8. package/bin/cccagent.mjs +17 -17
  9. package/im-skills/feishu-skill/receive-send-file.md +63 -63
  10. package/im-skills/feishu-skill/receive-send-image.md +24 -24
  11. package/im-skills/feishu-skill/skill.md +3 -3
  12. package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
  13. package/im-skills/wechat-file-skill/send-file.mjs +83 -83
  14. package/im-skills/wechat-file-skill/skill.md +10 -10
  15. package/im-skills/wechat-image-skill/skill.md +10 -10
  16. package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
  17. package/im-skills/wechat-video-skill/send-video.mjs +79 -79
  18. package/im-skills/wechat-video-skill/skill.md +10 -10
  19. package/package.json +1 -1
  20. package/scripts/postinstall-sharp-check.mjs +58 -58
  21. package/src/__tests__/agent-activity.test.ts +86 -86
  22. package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
  23. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
  24. package/src/__tests__/builtin-chat-session.test.ts +449 -393
  25. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  26. package/src/__tests__/builtin-config.test.ts +26 -26
  27. package/src/__tests__/builtin-context.test.ts +319 -202
  28. package/src/__tests__/builtin-file-tools.test.ts +240 -240
  29. package/src/__tests__/builtin-permissions.test.ts +211 -211
  30. package/src/__tests__/builtin-session-search.test.ts +228 -0
  31. package/src/__tests__/builtin-session-select.test.ts +116 -116
  32. package/src/__tests__/builtin-sigint.test.ts +56 -56
  33. package/src/__tests__/builtin-skills.test.ts +284 -284
  34. package/src/__tests__/builtin-web-tools.test.ts +220 -220
  35. package/src/__tests__/card-action-routing.test.ts +18 -18
  36. package/src/__tests__/cardkit.test.ts +60 -60
  37. package/src/__tests__/ccc-adapter.test.ts +170 -170
  38. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  39. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  40. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  41. package/src/__tests__/claude-adapter.test.ts +614 -614
  42. package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
  43. package/src/__tests__/codex-adapter.test.ts +58 -58
  44. package/src/__tests__/codex-raw-stream-log.test.ts +170 -170
  45. package/src/__tests__/codex-reset-actions.test.ts +146 -146
  46. package/src/__tests__/crash-logging.test.ts +95 -1
  47. package/src/__tests__/cursor-adapter.test.ts +268 -268
  48. package/src/__tests__/feishu-api.test.ts +60 -60
  49. package/src/__tests__/feishu-avatar.test.ts +164 -164
  50. package/src/__tests__/feishu-message-ingress.test.ts +138 -138
  51. package/src/__tests__/feishu-platform.test.ts +22 -22
  52. package/src/__tests__/format-message.test.ts +47 -47
  53. package/src/__tests__/jsonl-stream.test.ts +79 -79
  54. package/src/__tests__/package-files.test.ts +24 -24
  55. package/src/__tests__/privacy.test.ts +198 -198
  56. package/src/__tests__/progress-reducer.test.ts +121 -121
  57. package/src/__tests__/raw-stream-log.test.ts +106 -106
  58. package/src/__tests__/response-stall.test.ts +49 -49
  59. package/src/__tests__/restart.test.ts +55 -10
  60. package/src/__tests__/session.test.ts +199 -199
  61. package/src/__tests__/shared-prefix.test.ts +36 -36
  62. package/src/__tests__/sim-platform.test.ts +16 -16
  63. package/src/__tests__/startup-lifecycle.test.ts +231 -231
  64. package/src/__tests__/stop-session.test.ts +34 -34
  65. package/src/__tests__/stream-state.test.ts +42 -42
  66. package/src/__tests__/terminal-error.test.ts +54 -54
  67. package/src/__tests__/terminal-renderer.test.ts +247 -247
  68. package/src/__tests__/update-command-guard.test.ts +144 -144
  69. package/src/__tests__/web-ui.test.ts +326 -326
  70. package/src/adapters/adapter-interface.ts +33 -33
  71. package/src/adapters/ccc-adapter.ts +141 -141
  72. package/src/adapters/claude-adapter.ts +620 -620
  73. package/src/adapters/claude-session-meta-store.ts +120 -120
  74. package/src/adapters/codex-adapter.ts +426 -426
  75. package/src/adapters/cursor-adapter.ts +681 -681
  76. package/src/adapters/jsonl-stream.ts +157 -157
  77. package/src/adapters/raw-stream-log.ts +124 -124
  78. package/src/adapters/resource-monitor.ts +140 -140
  79. package/src/agent-activity.ts +175 -175
  80. package/src/agent-delegate-task-rpc.ts +153 -153
  81. package/src/agent-delegate-task.ts +91 -91
  82. package/src/agent-reload-config-rpc.ts +34 -34
  83. package/src/agent-stop-stuck.ts +129 -129
  84. package/src/builtin/cli.ts +6 -0
  85. package/src/builtin/config.ts +84 -84
  86. package/src/builtin/context.ts +465 -391
  87. package/src/builtin/file-log.ts +38 -38
  88. package/src/builtin/file-tools.ts +34 -0
  89. package/src/builtin/index.ts +24 -23
  90. package/src/builtin/proc-tree-kill.ts +61 -61
  91. package/src/builtin/progress/cards-helpers.ts +76 -76
  92. package/src/builtin/progress/reducer.ts +113 -113
  93. package/src/builtin/progress/terminal-renderer.ts +294 -294
  94. package/src/builtin/progress/view.ts +77 -77
  95. package/src/builtin/raw-stream-log.ts +124 -124
  96. package/src/builtin/session-search.ts +363 -0
  97. package/src/builtin/session-select.ts +48 -48
  98. package/src/builtin/sigint.ts +50 -50
  99. package/src/builtin/skills.ts +205 -205
  100. package/src/builtin/web-tools.ts +313 -313
  101. package/src/card-action-routing.ts +14 -14
  102. package/src/chatgpt-subscription-rpc.ts +27 -27
  103. package/src/chatgpt-subscription.ts +299 -299
  104. package/src/chrome-devtools-guard.ts +318 -318
  105. package/src/codex-reset-actions.ts +184 -184
  106. package/src/feishu-api.ts +193 -193
  107. package/src/feishu-message-ingress.ts +195 -195
  108. package/src/feishu-platform.ts +20 -20
  109. package/src/format-message.ts +293 -293
  110. package/src/index.ts +6 -1
  111. package/src/litellm-proxy.ts +374 -374
  112. package/src/orchestrator.ts +36 -13
  113. package/src/platform-adapter.ts +6 -6
  114. package/src/privacy.ts +118 -118
  115. package/src/progress/reducer.ts +113 -113
  116. package/src/progress/terminal-renderer.ts +294 -294
  117. package/src/progress/view.ts +77 -77
  118. package/src/response-stall.ts +28 -28
  119. package/src/runtime-reload.ts +34 -34
  120. package/src/session-chat-binding.ts +82 -82
  121. package/src/session-name.ts +8 -8
  122. package/src/session.ts +201 -201
  123. package/src/shared-prefix.ts +29 -29
  124. package/src/shared.ts +44 -0
  125. package/src/sim-platform.ts +20 -20
  126. package/src/startup-lifecycle.ts +250 -250
  127. package/src/stream-state.ts +21 -21
  128. package/src/terminal-error.ts +129 -129
  129. package/src/turn-cards.ts +117 -117
  130. package/src/update-command-guard.ts +165 -165
@@ -1,205 +1,205 @@
1
- /**
2
- * skills.ts — 多来源技能扫描(DeepCCC 统一入口)
3
- *
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。
14
- */
15
-
16
- import { readdirSync } from "node:fs";
17
- import { readFile, stat } from "node:fs/promises";
18
- import { homedir } from "node:os";
19
- import { join } from "node:path";
20
- export type SkillSource = "deepccc" | "codex" | "cursor" | "claude";
21
- export type SkillScope = "global" | "project";
22
-
23
- export interface BuiltinSkill {
24
- name: string;
25
- description: string;
26
- /** SKILL.md 的绝对路径 */
27
- skillPath: string;
28
- /** 来源(优先级 deepccc > codex > cursor > claude) */
29
- source: SkillSource;
30
- /** global = 用户级;project = 项目级(同来源内 project > global) */
31
- scope: SkillScope;
32
- }
33
-
34
- export interface SkillDirSpec {
35
- dir: string;
36
- source: SkillSource;
37
- scope: SkillScope;
38
- }
39
-
40
- /** 解析 SKILL.md frontmatter(兼容 CRLF),返回 name + description;无 frontmatter 返回 null */
41
- export function parseSkillFrontmatter(
42
- content: string,
43
- ): { name: string; description: string } | null {
44
- const match = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(content);
45
- if (!match) return null;
46
- const fm = match[1];
47
- const nameMatch = /^name:\s*(.+?)\s*$/m.exec(fm);
48
- if (!nameMatch) return null;
49
- const descMatch = /^description:\s*(.+?)\s*$/m.exec(fm);
50
- return {
51
- name: nameMatch[1].trim(),
52
- description: descMatch?.[1].trim() ?? "",
53
- };
54
- }
55
-
56
- // ---------------------------------------------------------------------------
57
- // mtime 热加载缓存:同一进程内重复扫描命中缓存(stat 校验),文件变化自动重读
58
- // ---------------------------------------------------------------------------
59
-
60
- const skillFileCache = new Map<string, { mtimeMs: number; content: string }>();
61
-
62
- async function readSkillFile(skillPath: string): Promise<string | null> {
63
- let st;
64
- try {
65
- st = await stat(skillPath);
66
- } catch {
67
- return null;
68
- }
69
- if (!st.isFile()) return null;
70
- const cached = skillFileCache.get(skillPath);
71
- if (cached && cached.mtimeMs === st.mtimeMs) return cached.content;
72
- const content = await readFile(skillPath, "utf8");
73
- skillFileCache.set(skillPath, { mtimeMs: st.mtimeMs, content });
74
- return content;
75
- }
76
-
77
- /**
78
- * 扫描多个 skill 目录(并行读取),按 name 去重。
79
- * 同名技能:后面的 spec(高优先级)覆盖前面的(低优先级)。
80
- * 隐藏目录(.system 等)和无 SKILL.md 的目录会被跳过;缺失目录跳过。
81
- */
82
- export async function scanSkillsDirs(dirs: SkillDirSpec[]): Promise<BuiltinSkill[]> {
83
- const byName = new Map<string, BuiltinSkill>();
84
-
85
- for (const spec of dirs) {
86
- let entries;
87
- try {
88
- entries = readdirSync(spec.dir, { withFileTypes: true });
89
- } catch {
90
- continue; // 目录不存在或不可读:跳过
91
- }
92
-
93
- // 目录内所有候选 SKILL.md 并行读取(读文件是扫描的瓶颈)
94
- const results = await Promise.all(
95
- entries
96
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
97
- .map(async (entry) => {
98
- const skillPath = join(spec.dir, entry.name, "SKILL.md");
99
- const content = await readSkillFile(skillPath);
100
- if (content === null) return null;
101
- const parsed = parseSkillFrontmatter(content);
102
- if (!parsed) return null;
103
- return { ...parsed, skillPath };
104
- }),
105
- );
106
-
107
- for (const result of results) {
108
- if (!result) continue;
109
- byName.set(result.name, {
110
- name: result.name,
111
- description: result.description,
112
- skillPath: result.skillPath,
113
- source: spec.source,
114
- scope: spec.scope,
115
- });
116
- }
117
- }
118
-
119
- return [...byName.values()];
120
- }
121
-
122
- /**
123
- * 默认技能扫描目录(按优先级从低到高排列,扫描时后者覆盖前者):
124
- * claude(global→project) < cursor(global→project) < codex(global→project) < deepccc(global→project)
125
- * 其中 codex 全局包含 ~/.codex/skills(CLI 旧路径)与 ~/.agents/skills(标准全局目录)。
126
- */
127
- export function buildDefaultSkillDirs(cwd: string): SkillDirSpec[] {
128
- const h = homedir();
129
- return [
130
- { dir: join(h, ".claude", "skills"), source: "claude", scope: "global" },
131
- { dir: join(cwd, ".claude", "skills"), source: "claude", scope: "project" },
132
- { dir: join(h, ".cursor", "skills"), source: "cursor", scope: "global" },
133
- { dir: join(cwd, ".cursor", "skills"), source: "cursor", scope: "project" },
134
- { dir: join(h, ".codex", "skills"), source: "codex", scope: "global" },
135
- { dir: join(h, ".agents", "skills"), source: "codex", scope: "global" },
136
- { dir: join(cwd, ".codex", "skills"), source: "codex", scope: "project" },
137
- { dir: join(h, ".deepccc", "skills"), source: "deepccc", scope: "global" },
138
- { dir: join(cwd, ".deepccc", "skills"), source: "deepccc", scope: "project" },
139
- ];
140
- }
141
-
142
- /**
143
- * 把技能绝对路径转成 prompt 展示形式:主目录下的路径缩写为 `~/...`(跨机器、
144
- * 跨用户稳定,避免用户名/盘符差异导致 system 前缀变化破坏缓存命中);
145
- * 分隔符统一为 `/`。主目录外的路径保持绝对路径(仅统一分隔符)。
146
- */
147
- export function normalizeSkillPathForPrompt(skillPath: string): string {
148
- const home = homedir().replace(/[\\/]+$/, "").replace(/\\/g, "/");
149
- const normalized = skillPath.replace(/\\/g, "/");
150
- if (normalized === home) return "~";
151
- if (normalized.startsWith(home + "/")) {
152
- return "~" + normalized.slice(home.length);
153
- }
154
- return normalized;
155
- }
156
-
157
- /**
158
- * 生成 skill 索引提示词(注入 system prompt)。
159
- * 索引只含 name + description + 来源 + 路径,并指示模型在任务匹配时
160
- * 先用 read_file 读取 SKILL.md 全文再执行;同时声明"创建技能"约定
161
- * (模型在对话中应把新技能创建到 ~/.deepccc/skills 或项目 .deepccc/skills)。
162
- * 路径经 normalizeSkillPathForPrompt 缩写,保持跨机器前缀稳定。
163
- */
164
- export function buildSkillsIndexPrompt(skills: BuiltinSkill[]): string {
165
- if (skills.length === 0) return "";
166
-
167
- const lines = [
168
- "## Available Skills",
169
- "Skills are scanned in parallel from Claude/Codex/Cursor/DeepCCC skill directories.",
170
- "On name conflicts: DeepCCC > Codex > Cursor > Claude wins; within one source, project scope wins over global.",
171
- "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.",
172
- "",
173
- ...skills.map((s) => `- **${s.name}** [${s.source}:${s.scope}] (\`${normalizeSkillPathForPrompt(s.skillPath)}\`): ${s.description || "(no description)"}`),
174
- "",
175
- "## Creating Skills",
176
- "When the user asks to create a skill, create it as a Codex-style directory skill at",
177
- "~/.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).",
178
- "SKILL.md format:",
179
- "```",
180
- "---",
181
- "name: <skill-name>",
182
- "description: <one-line description>",
183
- "---",
184
- "",
185
- "<instructions>",
186
- "```",
187
- "New skills are picked up automatically on the next message (hot reload); no restart is needed.",
188
- ];
189
- return lines.join("\n");
190
- }
191
-
192
- /** 生成 Codex 结构的新技能 SKILL.md 模板(供 CLI skill create / 对话创建约定共用) */
193
- export function buildSkillTemplate(name: string, description: string): string {
194
- return [
195
- "---",
196
- `name: ${name}`,
197
- `description: ${description}`,
198
- "---",
199
- "",
200
- `# ${name}`,
201
- "",
202
- "<skill instructions>",
203
- "",
204
- ].join("\n");
205
- }
1
+ /**
2
+ * skills.ts — 多来源技能扫描(DeepCCC 统一入口)
3
+ *
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。
14
+ */
15
+
16
+ import { readdirSync } from "node:fs";
17
+ import { readFile, stat } from "node:fs/promises";
18
+ import { homedir } from "node:os";
19
+ import { join } from "node:path";
20
+ export type SkillSource = "deepccc" | "codex" | "cursor" | "claude";
21
+ export type SkillScope = "global" | "project";
22
+
23
+ export interface BuiltinSkill {
24
+ name: string;
25
+ description: string;
26
+ /** SKILL.md 的绝对路径 */
27
+ skillPath: string;
28
+ /** 来源(优先级 deepccc > codex > cursor > claude) */
29
+ source: SkillSource;
30
+ /** global = 用户级;project = 项目级(同来源内 project > global) */
31
+ scope: SkillScope;
32
+ }
33
+
34
+ export interface SkillDirSpec {
35
+ dir: string;
36
+ source: SkillSource;
37
+ scope: SkillScope;
38
+ }
39
+
40
+ /** 解析 SKILL.md frontmatter(兼容 CRLF),返回 name + description;无 frontmatter 返回 null */
41
+ export function parseSkillFrontmatter(
42
+ content: string,
43
+ ): { name: string; description: string } | null {
44
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(content);
45
+ if (!match) return null;
46
+ const fm = match[1];
47
+ const nameMatch = /^name:\s*(.+?)\s*$/m.exec(fm);
48
+ if (!nameMatch) return null;
49
+ const descMatch = /^description:\s*(.+?)\s*$/m.exec(fm);
50
+ return {
51
+ name: nameMatch[1].trim(),
52
+ description: descMatch?.[1].trim() ?? "",
53
+ };
54
+ }
55
+
56
+ // ---------------------------------------------------------------------------
57
+ // mtime 热加载缓存:同一进程内重复扫描命中缓存(stat 校验),文件变化自动重读
58
+ // ---------------------------------------------------------------------------
59
+
60
+ const skillFileCache = new Map<string, { mtimeMs: number; content: string }>();
61
+
62
+ async function readSkillFile(skillPath: string): Promise<string | null> {
63
+ let st;
64
+ try {
65
+ st = await stat(skillPath);
66
+ } catch {
67
+ return null;
68
+ }
69
+ if (!st.isFile()) return null;
70
+ const cached = skillFileCache.get(skillPath);
71
+ if (cached && cached.mtimeMs === st.mtimeMs) return cached.content;
72
+ const content = await readFile(skillPath, "utf8");
73
+ skillFileCache.set(skillPath, { mtimeMs: st.mtimeMs, content });
74
+ return content;
75
+ }
76
+
77
+ /**
78
+ * 扫描多个 skill 目录(并行读取),按 name 去重。
79
+ * 同名技能:后面的 spec(高优先级)覆盖前面的(低优先级)。
80
+ * 隐藏目录(.system 等)和无 SKILL.md 的目录会被跳过;缺失目录跳过。
81
+ */
82
+ export async function scanSkillsDirs(dirs: SkillDirSpec[]): Promise<BuiltinSkill[]> {
83
+ const byName = new Map<string, BuiltinSkill>();
84
+
85
+ for (const spec of dirs) {
86
+ let entries;
87
+ try {
88
+ entries = readdirSync(spec.dir, { withFileTypes: true });
89
+ } catch {
90
+ continue; // 目录不存在或不可读:跳过
91
+ }
92
+
93
+ // 目录内所有候选 SKILL.md 并行读取(读文件是扫描的瓶颈)
94
+ const results = await Promise.all(
95
+ entries
96
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
97
+ .map(async (entry) => {
98
+ const skillPath = join(spec.dir, entry.name, "SKILL.md");
99
+ const content = await readSkillFile(skillPath);
100
+ if (content === null) return null;
101
+ const parsed = parseSkillFrontmatter(content);
102
+ if (!parsed) return null;
103
+ return { ...parsed, skillPath };
104
+ }),
105
+ );
106
+
107
+ for (const result of results) {
108
+ if (!result) continue;
109
+ byName.set(result.name, {
110
+ name: result.name,
111
+ description: result.description,
112
+ skillPath: result.skillPath,
113
+ source: spec.source,
114
+ scope: spec.scope,
115
+ });
116
+ }
117
+ }
118
+
119
+ return [...byName.values()];
120
+ }
121
+
122
+ /**
123
+ * 默认技能扫描目录(按优先级从低到高排列,扫描时后者覆盖前者):
124
+ * claude(global→project) < cursor(global→project) < codex(global→project) < deepccc(global→project)
125
+ * 其中 codex 全局包含 ~/.codex/skills(CLI 旧路径)与 ~/.agents/skills(标准全局目录)。
126
+ */
127
+ export function buildDefaultSkillDirs(cwd: string): SkillDirSpec[] {
128
+ const h = homedir();
129
+ return [
130
+ { dir: join(h, ".claude", "skills"), source: "claude", scope: "global" },
131
+ { dir: join(cwd, ".claude", "skills"), source: "claude", scope: "project" },
132
+ { dir: join(h, ".cursor", "skills"), source: "cursor", scope: "global" },
133
+ { dir: join(cwd, ".cursor", "skills"), source: "cursor", scope: "project" },
134
+ { dir: join(h, ".codex", "skills"), source: "codex", scope: "global" },
135
+ { dir: join(h, ".agents", "skills"), source: "codex", scope: "global" },
136
+ { dir: join(cwd, ".codex", "skills"), source: "codex", scope: "project" },
137
+ { dir: join(h, ".deepccc", "skills"), source: "deepccc", scope: "global" },
138
+ { dir: join(cwd, ".deepccc", "skills"), source: "deepccc", scope: "project" },
139
+ ];
140
+ }
141
+
142
+ /**
143
+ * 把技能绝对路径转成 prompt 展示形式:主目录下的路径缩写为 `~/...`(跨机器、
144
+ * 跨用户稳定,避免用户名/盘符差异导致 system 前缀变化破坏缓存命中);
145
+ * 分隔符统一为 `/`。主目录外的路径保持绝对路径(仅统一分隔符)。
146
+ */
147
+ export function normalizeSkillPathForPrompt(skillPath: string): string {
148
+ const home = homedir().replace(/[\\/]+$/, "").replace(/\\/g, "/");
149
+ const normalized = skillPath.replace(/\\/g, "/");
150
+ if (normalized === home) return "~";
151
+ if (normalized.startsWith(home + "/")) {
152
+ return "~" + normalized.slice(home.length);
153
+ }
154
+ return normalized;
155
+ }
156
+
157
+ /**
158
+ * 生成 skill 索引提示词(注入 system prompt)。
159
+ * 索引只含 name + description + 来源 + 路径,并指示模型在任务匹配时
160
+ * 先用 read_file 读取 SKILL.md 全文再执行;同时声明"创建技能"约定
161
+ * (模型在对话中应把新技能创建到 ~/.deepccc/skills 或项目 .deepccc/skills)。
162
+ * 路径经 normalizeSkillPathForPrompt 缩写,保持跨机器前缀稳定。
163
+ */
164
+ export function buildSkillsIndexPrompt(skills: BuiltinSkill[]): string {
165
+ if (skills.length === 0) return "";
166
+
167
+ const lines = [
168
+ "## Available Skills",
169
+ "Skills are scanned in parallel from Claude/Codex/Cursor/DeepCCC skill directories.",
170
+ "On name conflicts: DeepCCC > Codex > Cursor > Claude wins; within one source, project scope wins over global.",
171
+ "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.",
172
+ "",
173
+ ...skills.map((s) => `- **${s.name}** [${s.source}:${s.scope}] (\`${normalizeSkillPathForPrompt(s.skillPath)}\`): ${s.description || "(no description)"}`),
174
+ "",
175
+ "## Creating Skills",
176
+ "When the user asks to create a skill, create it as a Codex-style directory skill at",
177
+ "~/.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).",
178
+ "SKILL.md format:",
179
+ "```",
180
+ "---",
181
+ "name: <skill-name>",
182
+ "description: <one-line description>",
183
+ "---",
184
+ "",
185
+ "<instructions>",
186
+ "```",
187
+ "New skills are picked up automatically on the next message (hot reload); no restart is needed.",
188
+ ];
189
+ return lines.join("\n");
190
+ }
191
+
192
+ /** 生成 Codex 结构的新技能 SKILL.md 模板(供 CLI skill create / 对话创建约定共用) */
193
+ export function buildSkillTemplate(name: string, description: string): string {
194
+ return [
195
+ "---",
196
+ `name: ${name}`,
197
+ `description: ${description}`,
198
+ "---",
199
+ "",
200
+ `# ${name}`,
201
+ "",
202
+ "<skill instructions>",
203
+ "",
204
+ ].join("\n");
205
+ }