luminae-helper 0.0.6 → 0.0.7

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,4 +1,4 @@
1
- # skill-git-commit
1
+ # git-commit
2
2
 
3
3
  > Generate commit message from git diff and execute git commit
4
4
 
@@ -12,7 +12,7 @@
12
12
  4. 输出生成的 commit message 供用户知悉
13
13
  5. 直接执行 `git commit`(无需用户确认)
14
14
 
15
- **如只需生成 commit message 而不执行提交,请使用 `skill-git-commit-msg`。**
15
+ **如只需生成 commit message 而不执行提交,请使用 `git-commit-msg`。**
16
16
 
17
17
  ## Conventional Commits 类型
18
18
 
@@ -1,4 +1,4 @@
1
- # skill-git-commit
1
+ # git-commit-msg
2
2
 
3
3
  Smart commit message generator with Conventional Commits format.
4
4
 
@@ -53,16 +53,16 @@ Smart commit message generator with Conventional Commits format.
53
53
 
54
54
  ```bash
55
55
  # Claude Code
56
- cp skills/skill-git-commit/SKILL.md ~/.claude/commands/git-commit.md
56
+ cp commands/git-commit-msg/SKILL.md ~/.claude/commands/git-commit-msg.md
57
57
 
58
58
  # Cursor
59
- cp skills/skill-git-commit/SKILL.md ~/.cursor/commands/git-commit.md
59
+ cp commands/git-commit-msg/SKILL.md ~/.cursor/commands/git-commit-msg.md
60
60
 
61
61
  # OpenCode
62
- cp -r skills/skill-git-commit ~/.opencode/skills/
62
+ cp -r commands/git-commit-msg ~/.opencode/skills/
63
63
 
64
64
  # Trae
65
- cp skills/skill-git-commit/SKILL.md ~/.trae/commands/git-commit.md
65
+ cp commands/git-commit-msg/SKILL.md ~/.trae/commands/git-commit-msg.md
66
66
  ```
67
67
 
68
68
  ## License
@@ -1,4 +1,4 @@
1
- # skill-git-commit-msg
1
+ # git-commit-msg
2
2
 
3
3
  > Generate commit message from git diff, and optionally execute git commit
4
4
 
@@ -13,7 +13,7 @@
13
13
  5. 询问用户是否以当前生成的 message 进行 commit
14
14
  6. 如果用户回复"是"、"同意"、"确认"等肯定词,则执行 `git commit`;否则不执行
15
15
 
16
- **注意:** 如需生成后直接提交(无需询问),请使用 `skill-git-commit`。
16
+ **注意:** 如需生成后直接提交(无需询问),请使用 `git-commit`。
17
17
 
18
18
  ## Conventional Commits 类型
19
19
 
@@ -1,4 +1,4 @@
1
- # skill-git-push
1
+ # git-push
2
2
 
3
3
  Code review + commit + push workflow for AI coding agents.
4
4
 
@@ -41,16 +41,16 @@ Code review + commit + push workflow for AI coding agents.
41
41
 
42
42
  ```bash
43
43
  # Claude Code
44
- cp skills/skill-git-push/SKILL.md ~/.claude/commands/git-push.md
44
+ cp commands/git-push/SKILL.md ~/.claude/commands/git-push.md
45
45
 
46
46
  # Cursor
47
- cp skills/skill-git-push/SKILL.md ~/.cursor/commands/git-push.md
47
+ cp commands/git-push/SKILL.md ~/.cursor/commands/git-push.md
48
48
 
49
49
  # OpenCode
50
- cp -r skills/skill-git-push ~/.opencode/skills/
50
+ cp -r commands/git-push ~/.opencode/skills/
51
51
 
52
52
  # Trae
53
- cp skills/skill-git-push/SKILL.md ~/.trae/commands/git-push.md
53
+ cp commands/git-push/SKILL.md ~/.trae/commands/git-push.md
54
54
  ```
55
55
 
56
56
  ## License
@@ -1,4 +1,4 @@
1
- # skill-git-push
1
+ # git-push
2
2
 
3
3
  > Code review + commit + push workflow
4
4
 
@@ -1,4 +1,4 @@
1
- # skill-identity
1
+ # identity
2
2
 
3
3
  Detect project type and set agent identity - foundation for all tasks.
4
4
 
@@ -40,16 +40,16 @@ Detect project type and set agent identity - foundation for all tasks.
40
40
 
41
41
  ```bash
42
42
  # Claude Code
43
- cp skills/skill-identity/SKILL.md ~/.claude/commands/identity.md
43
+ cp commands/identity/SKILL.md ~/.claude/commands/identity.md
44
44
 
45
45
  # Cursor
46
- cp skills/skill-identity/SKILL.md ~/.cursor/commands/identity.md
46
+ cp commands/identity/SKILL.md ~/.cursor/commands/identity.md
47
47
 
48
48
  # OpenCode
49
- cp -r skills/skill-identity ~/.opencode/skills/
49
+ cp -r commands/identity ~/.opencode/skills/
50
50
 
51
51
  # Trae
52
- cp skills/skill-identity/SKILL.md ~/.trae/commands/identity.md
52
+ cp commands/identity/SKILL.md ~/.trae/commands/identity.md
53
53
  ```
54
54
 
55
55
  ## License
@@ -1,4 +1,4 @@
1
- # skill-identity
1
+ # identity
2
2
 
3
3
  > Detect project type and set agent identity - foundation for all tasks
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "luminae-helper",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Install AI skills to coding tools (Claude Code, Cursor, OpenCode, Trae, etc.)",
5
5
  "type": "module",
6
6
  "main": "src/cli.js",
@@ -11,6 +11,7 @@
11
11
  "src/cli.js",
12
12
  "src/lib/*.js",
13
13
  "src/utils/*.js",
14
+ "commands/",
14
15
  "skills/",
15
16
  "README.md"
16
17
  ],
@@ -44,6 +45,9 @@
44
45
  "gradient-string": "^3.0.0",
45
46
  "wcwidth": "^1.0.1"
46
47
  },
48
+ "devDependencies": {
49
+ "vitest": "^4.1.6"
50
+ },
47
51
  "publishConfig": {
48
52
  "registry": "https://registry.npmjs.org/"
49
53
  }
@@ -10,74 +10,50 @@ export const TOOLS = [
10
10
  id: "claude-code",
11
11
  name: "Claude Code",
12
12
  command: "claude",
13
- installMode: "file",
14
- skillsDir: () => join(homedir(), ".claude", "commands"),
13
+ commandDir: () => join(homedir(), ".claude", "commands"),
14
+ skillDir: () => join(homedir(), ".claude", "skills"),
15
15
  installHint: "npm install -g @anthropic-ai/claude-code",
16
16
  },
17
+ {
18
+ id: "codex",
19
+ name: "Codex",
20
+ command: "codex",
21
+ commandDir: null,
22
+ skillDir: () => join(homedir(), ".codex", "skills"),
23
+ installHint: "npm install -g @openai/codex",
24
+ },
17
25
  {
18
26
  id: "cursor",
19
27
  name: "Cursor",
20
28
  command: "cursor",
21
- installMode: "file",
22
- skillsDir: () => join(homedir(), ".cursor", "commands"),
29
+ commandDir: null,
30
+ skillDir: () => join(homedir(), ".cursor", "skills"),
23
31
  installHint: "Download from https://cursor.com",
24
32
  },
33
+ {
34
+ id: "hermes-agent",
35
+ name: "Hermes Agent",
36
+ command: "hermes",
37
+ commandDir: null,
38
+ skillDir: () => join(homedir(), ".hermes", "skills"),
39
+ installHint: "pip install hermes-ai",
40
+ },
25
41
  {
26
42
  id: "opencode",
27
43
  name: "OpenCode",
28
44
  command: "opencode",
29
- installMode: "dir",
30
- skillsDir: () => join(homedir(), ".opencode", "skills"),
45
+ commandDir: null,
46
+ skillDir: () => join(homedir(), ".opencode", "skills"),
31
47
  installHint: "npm install -g opencode-ai",
32
48
  },
33
49
  {
34
50
  id: "trae",
35
51
  name: "Trae",
36
52
  command: "trae",
37
- installMode: "file",
38
- skillsDir: () => join(homedir(), ".trae", "commands"),
53
+ commandDir: () => join(homedir(), ".trae", "commands"),
54
+ skillDir: null,
39
55
  installHint: "Download from https://trae.ai",
40
56
  },
41
- {
42
- id: "openclaw",
43
- name: "OpenClaw",
44
- command: "openclaw",
45
- installMode: "dir",
46
- skillsDir: () => join(homedir(), ".openclaw", "skills"),
47
- installHint: "npm install -g openclaw",
48
- },
49
- {
50
- id: "nanobot",
51
- name: "Nanobot",
52
- command: "nanobot",
53
- installMode: "dir",
54
- skillsDir: () => join(homedir(), ".nanobot", "skills"),
55
- installHint: "pip install nanobot",
56
- },
57
- {
58
- id: "hermes-agent",
59
- name: "Hermes Agent",
60
- command: "hermes",
61
- installMode: "dir",
62
- skillsDir: () => join(homedir(), ".hermes", "skills"),
63
- installHint: "pip install hermes-ai",
64
- },
65
- {
66
- id: "zeroclaw",
67
- name: "ZeroClaw",
68
- command: "zeroclaw",
69
- installMode: "dir",
70
- skillsDir: () => join(homedir(), ".zeroclaw", "skills"),
71
- installHint: "npm install -g zeroclaw",
72
- },
73
- {
74
- id: "codex",
75
- name: "Codex",
76
- command: "codex",
77
- installMode: "dir",
78
- skillsDir: () => join(homedir(), ".codex", "skills"),
79
- installHint: "npm install -g @openai/codex",
80
- },
81
57
  ];
82
58
 
83
59
  // ── Skill auto-discovery ──
@@ -111,16 +87,28 @@ function parseSkillMeta(skillId, content) {
111
87
  for (const line of fmMatch[1].split("\n")) {
112
88
  const m = line.match(/^(\w+):\s*(.+)/);
113
89
  if (m) {
114
- if (m[1] === "name") name = m[2].trim();
115
- if (m[1] === "description") description = m[2].trim();
90
+ let value = m[2].trim();
91
+ // Strip YAML inline comments (unquoted # after value)
92
+ // But preserve # inside quoted strings
93
+ if (!((value.startsWith('"') && value.endsWith('"')) ||
94
+ (value.startsWith("'") && value.endsWith("'")))) {
95
+ const hashIdx = value.indexOf(" #");
96
+ if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
97
+ }
98
+ // Strip surrounding quotes (single or double) from YAML values
99
+ if ((value.startsWith('"') && value.endsWith('"')) ||
100
+ (value.startsWith("'") && value.endsWith("'"))) {
101
+ value = value.slice(1, -1);
102
+ }
103
+ if (m[1] === "name") name = value;
104
+ if (m[1] === "description") description = value;
116
105
  }
117
106
  }
118
107
  }
119
108
 
120
- // Default name: skillId without "skill-" prefix, capitalize words
109
+ // Default name: skillId, capitalize words separated by hyphens
121
110
  if (!name) {
122
111
  name = skillId
123
- .replace(/^skill-/, "")
124
112
  .replace(/(^|-)(\w)/g, (_, p, c) => (p === "-" ? " " : "") + c.toUpperCase());
125
113
  }
126
114
 
@@ -134,47 +122,101 @@ function parseSkillMeta(skillId, content) {
134
122
  }
135
123
 
136
124
  /**
137
- * Generate destPath for a skill+tool combo based on installMode.
138
- * - file mode: <skillsDir>/<shortName>.md
139
- * - dir mode: <skillsDir>/<skillId>/
125
+ * Generate installTargets for an entry based on tool capability.
126
+ * - skillType "command" + tool supports commandDir → file mode (commands/)
127
+ * - skillType "command" + tool only supports skillDir → fallback dir mode
128
+ * - skillType "skill" + tool supports skillDir → dir mode (skills/)
129
+ * - skillType "skill" + tool only supports commandDir → fallback file mode
130
+ * - tool supports neither → skip
140
131
  */
141
- function generateDestPath(tool, skillId) {
142
- const shortName = skillId.replace(/^skill-/, "");
143
- if (tool.installMode === "dir") {
144
- return () => join(tool.skillsDir(), skillId);
132
+ function generateInstallTargets(skillId, skillType) {
133
+ const targets = [];
134
+ for (const tool of TOOLS) {
135
+ const supportsCommand = Boolean(tool.commandDir);
136
+ const supportsSkill = Boolean(tool.skillDir);
137
+
138
+ if (skillType === "command") {
139
+ if (supportsCommand) {
140
+ targets.push({
141
+ toolId: tool.id,
142
+ installMode: "file",
143
+ destPath: () => join(tool.commandDir(), `${skillId}.md`),
144
+ });
145
+ } else if (supportsSkill) {
146
+ // Fallback: tool only supports skills, install command as skill
147
+ targets.push({
148
+ toolId: tool.id,
149
+ installMode: "dir",
150
+ destPath: () => join(tool.skillDir(), skillId),
151
+ });
152
+ }
153
+ } else if (skillType === "skill") {
154
+ if (supportsSkill) {
155
+ targets.push({
156
+ toolId: tool.id,
157
+ installMode: "dir",
158
+ destPath: () => join(tool.skillDir(), skillId),
159
+ });
160
+ } else if (supportsCommand) {
161
+ // Fallback: tool only supports commands, install skill as command
162
+ targets.push({
163
+ toolId: tool.id,
164
+ installMode: "file",
165
+ destPath: () => join(tool.commandDir(), `${skillId}.md`),
166
+ });
167
+ }
168
+ }
145
169
  }
146
- return () => join(tool.skillsDir(), `${shortName}.md`);
170
+ return targets;
147
171
  }
148
172
 
149
173
  /**
150
- * Scan skills/ directory and build SKILLS array automatically.
174
+ * Scan commands/ and skills/ directories and build SKILLS array automatically.
151
175
  * Each subdirectory containing a SKILL.md is a valid skill.
176
+ * - commands/<skillId>/ → type: "command"
177
+ * - skills/<skillId>/ → type: "skill"
152
178
  */
153
179
  export function discoverSkills() {
154
- const skillsRoot = join(getPackageDir(), "skills");
155
- if (!existsSync(skillsRoot)) return [];
156
-
180
+ const packageDir = getPackageDir();
157
181
  const skills = [];
158
- for (const entry of readdirSync(skillsRoot)) {
159
- const skillPath = join(skillsRoot, entry);
160
- if (!statSync(skillPath).isDirectory()) continue;
161
-
162
- const skillFile = join(skillPath, "SKILL.md");
163
- if (!existsSync(skillFile)) continue;
164
-
165
- const skillId = entry;
166
- const content = readFileSync(skillFile, "utf-8");
167
- const { name, description } = parseSkillMeta(skillId, content);
168
-
169
- skills.push({
170
- id: skillId,
171
- name,
172
- description,
173
- installTargets: TOOLS.map((tool) => ({
174
- toolId: tool.id,
175
- destPath: generateDestPath(tool, skillId),
176
- })),
177
- });
182
+
183
+ const typeDirs = [
184
+ { dir: "commands", type: "command" },
185
+ { dir: "skills", type: "skill" },
186
+ ];
187
+
188
+ const seenIds = new Set();
189
+
190
+ for (const { dir, type } of typeDirs) {
191
+ const typePath = join(packageDir, dir);
192
+ if (!existsSync(typePath)) continue;
193
+
194
+ for (const entry of readdirSync(typePath)) {
195
+ const skillPath = join(typePath, entry);
196
+ if (!statSync(skillPath).isDirectory()) continue;
197
+
198
+ const skillFile = join(skillPath, "SKILL.md");
199
+ if (!existsSync(skillFile)) continue;
200
+
201
+ const skillId = entry;
202
+
203
+ if (seenIds.has(skillId)) {
204
+ console.warn(`[luminae-helper] 警告:skillId "${skillId}" 在 commands/ 和 skills/ 中重复,仅使用 commands/ 下的条目`);
205
+ continue;
206
+ }
207
+ seenIds.add(skillId);
208
+
209
+ const content = readFileSync(skillFile, "utf-8");
210
+ const { name, description } = parseSkillMeta(skillId, content);
211
+
212
+ skills.push({
213
+ id: skillId,
214
+ name,
215
+ description,
216
+ type,
217
+ installTargets: generateInstallTargets(skillId, type),
218
+ });
219
+ }
178
220
  }
179
221
 
180
222
  return skills;
@@ -196,8 +238,14 @@ export function detectInstalledTools() {
196
238
 
197
239
  /**
198
240
  * Find skill source directory bundled inside this package.
199
- * Skills are at <luminae-helper>/skills/<skillId>/
241
+ * - command: <luminae-helper>/commands/<skillId>/
242
+ * - skill: <luminae-helper>/skills/<skillId>/
200
243
  */
201
244
  export function getSkillSourcePath(skillId) {
202
- return join(getPackageDir(), "skills", skillId);
245
+ const skill = SKILLS.find(s => s.id === skillId);
246
+ if (!skill) {
247
+ throw new Error(`Unknown skillId: "${skillId}" — not found in discovered skills`);
248
+ }
249
+ const subDir = skill.type === "command" ? "commands" : "skills";
250
+ return join(getPackageDir(), subDir, skillId);
203
251
  }
@@ -1,7 +1,52 @@
1
- import { existsSync, mkdirSync, copyFileSync, readdirSync, rmSync, unlinkSync } from "fs";
1
+ import { existsSync, mkdirSync, copyFileSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "fs";
2
2
  import { dirname, join } from "path";
3
3
  import { getSkillSourcePath } from "./constants.js";
4
4
 
5
+ // ── managed-by 标识 ──
6
+
7
+ const MANAGED_BY = "luminae-helper";
8
+ const MANAGED_LINE = `managed-by: ${MANAGED_BY}`;
9
+
10
+ /**
11
+ * 在 SKILL.md 内容的 YAML frontmatter 中注入 `managed-by: luminae-helper`。
12
+ * - 如果 frontmatter 中已有该行,不重复添加。
13
+ * - 如果没有 frontmatter(理论上不会发生),在文件开头创建一个。
14
+ */
15
+ function injectManagedBy(content) {
16
+ if (content.includes(MANAGED_LINE)) return content;
17
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
18
+ if (fmMatch) {
19
+ // 在 frontmatter 关闭的 --- 前插入一行
20
+ return content.replace(/\n---\n/, `\n${MANAGED_LINE}\n---\n`);
21
+ }
22
+ // 无 frontmatter:包一层
23
+ return `---\n${MANAGED_LINE}\n---\n${content}`;
24
+ }
25
+
26
+ /**
27
+ * 检查 SKILL.md 内容是否包含 `managed-by: luminae-helper` 标识。
28
+ */
29
+ function hasManagedBy(content) {
30
+ return content.includes(MANAGED_LINE);
31
+ }
32
+
33
+ /**
34
+ * 向目标文件注入 managed-by 标识(原地修改)。
35
+ * 读取文件内容,注入标识后写回。
36
+ */
37
+ function stampManagedBy(filePath) {
38
+ try {
39
+ if (!existsSync(filePath)) return;
40
+ const content = readFileSync(filePath, "utf-8");
41
+ const stamped = injectManagedBy(content);
42
+ if (stamped !== content) {
43
+ writeFileSync(filePath, stamped, "utf-8");
44
+ }
45
+ } catch {
46
+ // 注入失败不阻塞安装流程,只是卸载时无法识别
47
+ }
48
+ }
49
+
5
50
  function ensureDir(filePath) {
6
51
  const dir = dirname(filePath);
7
52
  if (!existsSync(dir)) {
@@ -14,21 +59,81 @@ function copyFile(src, dest) {
14
59
  copyFileSync(src, dest);
15
60
  }
16
61
 
62
+ /** 目录名黑名单:复制 skill 目录时跳过这些条目,避免污染用户 home */
63
+ const COPY_SKIP_ENTRIES = new Set(["node_modules", ".git", ".DS_Store", "Thumbs.db"]);
64
+
17
65
  function copyDir(src, dest) {
18
66
  if (!existsSync(src)) throw new Error(`Source dir not found: ${src}`);
19
- if (!existsSync(dest)) {
20
- mkdirSync(dest, { recursive: true });
67
+ // 先拷贝到临时目录,成功后原子替换,避免中途失败导致数据丢失
68
+ const tmpDest = dest + ".__tmp__";
69
+ if (existsSync(tmpDest)) {
70
+ rmSync(tmpDest, { recursive: true, force: true });
21
71
  }
72
+ mkdirSync(tmpDest, { recursive: true });
22
73
  const entries = readdirSync(src, { withFileTypes: true });
23
74
  for (const entry of entries) {
75
+ if (COPY_SKIP_ENTRIES.has(entry.name)) continue;
24
76
  const srcPath = join(src, entry.name);
25
- const destPath = join(dest, entry.name);
77
+ const destPath = join(tmpDest, entry.name);
26
78
  if (entry.isDirectory()) {
27
79
  copyDir(srcPath, destPath);
28
80
  } else {
29
81
  copyFile(srcPath, destPath);
30
82
  }
31
83
  }
84
+ // 临时目录拷贝完成,替换目标
85
+ // 先备份旧目标,rename 失败时可恢复
86
+ const backupDest = dest + ".__bak__";
87
+ let hasBackup = false;
88
+ if (existsSync(dest)) {
89
+ try {
90
+ renameSync(dest, backupDest);
91
+ hasBackup = true;
92
+ } catch {
93
+ // 无法重命名旧目录,直接删除
94
+ rmSync(dest, { recursive: true, force: true });
95
+ }
96
+ }
97
+ try {
98
+ renameSync(tmpDest, dest);
99
+ } catch (e) {
100
+ // 替换失败:尝试恢复备份
101
+ if (hasBackup && existsSync(backupDest)) {
102
+ try { renameSync(backupDest, dest); } catch { /* 恢复也失败,无法做更多 */ }
103
+ }
104
+ // 清理临时目录
105
+ if (existsSync(tmpDest)) rmSync(tmpDest, { recursive: true, force: true });
106
+ throw new Error(`替换目标目录失败: ${e.message}`);
107
+ }
108
+ // 成功后清理备份
109
+ if (hasBackup && existsSync(backupDest)) {
110
+ rmSync(backupDest, { recursive: true, force: true });
111
+ }
112
+ }
113
+
114
+ /**
115
+ * 检查目标路径是否由本工具安装(SKILL.md / .md 文件中包含 `managed-by: luminae-helper`),
116
+ * 避免误删用户手动创建或 AI 工具自带的同名文件/目录。
117
+ */
118
+ function isInstalledByUs(destPath, isDirBased) {
119
+ if (!existsSync(destPath)) return false;
120
+ try {
121
+ if (isDirBased) {
122
+ // dir 模式:检查目录下 SKILL.md 是否含 managed-by 标识
123
+ const skillFile = join(destPath, "SKILL.md");
124
+ if (!existsSync(skillFile)) return false;
125
+ const content = readFileSync(skillFile, "utf-8");
126
+ return hasManagedBy(content);
127
+ } else {
128
+ // file 模式:检查 .md 文件内容是否含 managed-by 标识
129
+ const stat = statSync(destPath);
130
+ if (!stat.isFile() || stat.size === 0) return false;
131
+ const content = readFileSync(destPath, "utf-8");
132
+ return hasManagedBy(content);
133
+ }
134
+ } catch {
135
+ return false;
136
+ }
32
137
  }
33
138
 
34
139
  /**
@@ -38,38 +143,47 @@ function copyDir(src, dest) {
38
143
  * @returns {{ success: boolean, message: string }}
39
144
  */
40
145
  export function installSkillToTool(skill, tool) {
41
- // Look up the correct destPath from installTargets
146
+ // Look up the correct target from installTargets
42
147
  const target = skill.installTargets?.find(tgt => tgt.toolId === tool.id);
43
148
  if (!target) {
44
149
  return { success: false, message: `Skill does not support ${tool.name}` };
45
150
  }
46
151
 
47
- const sourceDir = getSkillSourcePath(skill.id);
152
+ let sourceDir;
153
+ try {
154
+ sourceDir = getSkillSourcePath(skill.id);
155
+ } catch (e) {
156
+ return { success: false, message: e.message };
157
+ }
48
158
 
49
159
  if (!existsSync(sourceDir)) {
50
160
  return { success: false, message: `Skill source not found: ${sourceDir}` };
51
161
  }
52
162
 
53
163
  const destPath = target.destPath();
54
- const destDir = dirname(destPath);
55
-
56
- if (!existsSync(destDir)) {
57
- mkdirSync(destDir, { recursive: true });
58
- }
59
-
60
- const srcSkillFile = join(sourceDir, "SKILL.md");
61
- if (!existsSync(srcSkillFile)) {
62
- return { success: false, message: `SKILL.md not found in ${sourceDir}` };
63
- }
64
-
65
- const isDirBased = tool.installMode === "dir";
164
+ const isDirBased = target.installMode === "dir";
66
165
 
67
166
  if (isDirBased) {
68
- const destSkillDir = destPath;
69
- copyDir(sourceDir, destSkillDir);
70
- return { success: true, message: `Installed to ${destSkillDir}` };
167
+ try {
168
+ copyDir(sourceDir, destPath);
169
+ } catch (e) {
170
+ return { success: false, message: `安装失败: ${e.message}` };
171
+ }
172
+ // 注入 managed-by 标识到目标 SKILL.md
173
+ stampManagedBy(join(destPath, "SKILL.md"));
174
+ return { success: true, message: `Installed to ${destPath}` };
71
175
  } else {
72
- copyFile(srcSkillFile, destPath);
176
+ const srcSkillFile = join(sourceDir, "SKILL.md");
177
+ if (!existsSync(srcSkillFile)) {
178
+ return { success: false, message: `SKILL.md not found in ${sourceDir}` };
179
+ }
180
+ try {
181
+ copyFile(srcSkillFile, destPath);
182
+ } catch (e) {
183
+ return { success: false, message: `安装失败: ${e.message}` };
184
+ }
185
+ // 注入 managed-by 标识到目标 .md 文件
186
+ stampManagedBy(destPath);
73
187
  return { success: true, message: `Installed to ${destPath}` };
74
188
  }
75
189
  }
@@ -83,22 +197,34 @@ export function uninstallSkillFromTool(skill, tool) {
83
197
  return { success: false, message: `Skill does not support ${tool.name}` };
84
198
  }
85
199
 
86
- const destPath = target.destPath();
87
- const isDirBased = tool.installMode === "dir";
200
+ let destPath;
201
+ try {
202
+ destPath = target.destPath();
203
+ } catch (e) {
204
+ return { success: false, message: e.message };
205
+ }
206
+ const isDirBased = target.installMode === "dir";
88
207
 
89
- if (isDirBased) {
208
+ if (!isInstalledByUs(destPath, isDirBased)) {
90
209
  if (existsSync(destPath)) {
210
+ return { success: false, message: `目标路径 ${destPath} 存在但非本工具安装,已跳过删除` };
211
+ }
212
+ return { success: false, message: "Not installed" };
213
+ }
214
+
215
+ if (isDirBased) {
216
+ try {
91
217
  rmSync(destPath, { recursive: true, force: true });
92
- return { success: true, message: `Uninstalled from ${destPath}` };
93
- } else {
94
- return { success: false, message: "Not installed" };
218
+ } catch (e) {
219
+ return { success: false, message: `卸载失败: ${e.message}` };
95
220
  }
221
+ return { success: true, message: `Uninstalled from ${destPath}` };
96
222
  } else {
97
- if (existsSync(destPath)) {
223
+ try {
98
224
  unlinkSync(destPath);
99
- return { success: true, message: `Uninstalled from ${destPath}` };
100
- } else {
101
- return { success: false, message: "Not installed" };
225
+ } catch (e) {
226
+ return { success: false, message: `卸载失败: ${e.message}` };
102
227
  }
228
+ return { success: true, message: `Uninstalled from ${destPath}` };
103
229
  }
104
230
  }
package/src/lib/ui.js CHANGED
@@ -50,7 +50,7 @@ function printBanner() {
50
50
  /**
51
51
  * Pad a choice label to a consistent display width so icons don't misalign.
52
52
  */
53
- function padChoice(text, targetWidth = 20) {
53
+ export function padChoice(text, targetWidth = 20) {
54
54
  const stripped = text.replace(/\x1b\[[0-9;]*m/g, "");
55
55
  const w = wcswidth(stripped);
56
56
  const pad = w < 0 ? 0 : Math.max(0, targetWidth - w);
@@ -64,7 +64,7 @@ function padChoice(text, targetWidth = 20) {
64
64
  * @param {unknown} ans
65
65
  * @returns {"back"|"exit"|string[]}
66
66
  */
67
- function parseCheckboxResult(ans) {
67
+ export function parseCheckboxResult(ans) {
68
68
  if (ans === "exit" || ans === "__exit__") return "exit";
69
69
  if (ans === "back" || ans === "__back__") return "back";
70
70
  if (ans === "esc_timeout") return "back";
@@ -106,12 +106,12 @@ async function runCheckbox(config) {
106
106
  });
107
107
  }
108
108
 
109
- // ── Step 1: Select skills (checkbox multi-select) ──
109
+ // ── Step 1: Select entries (checkbox multi-select) ──
110
110
  async function stepSelectSkills() {
111
111
  while (true) {
112
112
  await afterPromptFlush();
113
113
  printBanner();
114
- printSectionTitle("━━━ 选择 Skill ━━━");
114
+ printSectionTitle("━━━ 选择命令/技能 ━━━");
115
115
 
116
116
  const skillChoices = SKILLS.map(s => ({
117
117
  name: s.name + " - " + s.description,
@@ -124,7 +124,7 @@ async function stepSelectSkills() {
124
124
  };
125
125
 
126
126
  const ans = await runCheckbox({
127
- message: "选择 Skill:",
127
+ message: "选择命令/技能:",
128
128
  choices: withNavChoices(skillChoices, "↩ 返回主菜单"),
129
129
  loop: false,
130
130
  theme,
@@ -136,7 +136,7 @@ async function stepSelectSkills() {
136
136
  if (result === "exit") return "exit";
137
137
 
138
138
  if (result.length === 0) {
139
- console.log(chalk.yellow(TERM_GUTTER + "请至少选择一个 Skill"));
139
+ console.log(chalk.yellow(TERM_GUTTER + "请至少选择一个命令/技能"));
140
140
  await new Promise(r => setTimeout(r, 1200));
141
141
  continue;
142
142
  }
@@ -220,7 +220,16 @@ async function stepPreviewConfirm(isUninstall) {
220
220
  }
221
221
 
222
222
  // ── Step 4: Execute ──
223
- async function stepExecute(skillIds, toolIds, installedTools, isUninstall) {
223
+ /**
224
+ * @param {string[]} skillIds
225
+ * @param {string[]} toolIds
226
+ * @param {object[]} installedTools
227
+ * @param {boolean} isUninstall
228
+ * @param {Set<string>|null} failedKeys - 若提供,只执行 key 在此集合中的组合;否则执行全部
229
+ * key 格式: `${toolId}::${skillId}`
230
+ * @returns {{ allSuccess: boolean, failedKeys: Set<string> }}
231
+ */
232
+ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, failedKeys = null) {
224
233
  const sids = asIdArray(skillIds);
225
234
  const tids = asIdArray(toolIds);
226
235
  await afterPromptFlush();
@@ -229,18 +238,34 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall) {
229
238
  printSectionTitle("━━━ 执行中 ━━━");
230
239
 
231
240
  let allSuccess = true;
241
+ /** 可重试的失败(I/O 错误等) */
242
+ const retryableFailedKeys = new Set();
243
+ /** 不可重试的失败(不支持、未注册等) */
244
+ const permanentFailedKeys = new Set();
232
245
 
233
246
  for (const toolId of tids) {
234
247
  const tool = TOOLS.find(t => t.id === toolId);
235
- if (!tool) continue;
248
+ if (!tool) {
249
+ console.log(chalk.gray(TERM_GUTTER + "- 工具 " + toolId + " 未识别,跳过"));
250
+ continue;
251
+ }
236
252
 
237
253
  for (const skillId of sids) {
238
254
  const skill = SKILLS.find(s => s.id === skillId);
239
- if (!skill) continue;
255
+ if (!skill) {
256
+ console.log(chalk.gray(TERM_GUTTER + "- Skill " + skillId + " 未识别,跳过"));
257
+ continue;
258
+ }
259
+
260
+ const key = `${toolId}::${skillId}`;
261
+ // 如果是重试模式,只执行之前失败的组合
262
+ if (failedKeys && !failedKeys.has(key)) continue;
240
263
 
241
264
  const supported = skill.installTargets?.some(tgt => tgt.toolId === toolId);
242
265
  if (!supported) {
243
- console.log(chalk.gray(TERM_GUTTER + "- " + skill.name + " × " + tool.name + " (不支持)"));
266
+ console.log(chalk.yellow(TERM_GUTTER + "- " + skill.name + " × " + tool.name + " (不支持,跳过)"));
267
+ allSuccess = false;
268
+ permanentFailedKeys.add(key);
244
269
  continue;
245
270
  }
246
271
 
@@ -249,7 +274,10 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall) {
249
274
  if (result.success) {
250
275
  console.log(chalk.green(TERM_GUTTER + "✓ " + skill.name + " - " + tool.name));
251
276
  } else {
252
- console.log(chalk.yellow(TERM_GUTTER + "- " + skill.name + " - " + tool.name + " (未安装)"));
277
+ console.log(chalk.yellow(TERM_GUTTER + "- " + skill.name + " - " + tool.name + " (" + result.message + ")"));
278
+ allSuccess = false;
279
+ // "未安装" 不可重试,"非本工具安装" 也不可重试
280
+ permanentFailedKeys.add(key);
253
281
  }
254
282
  } else {
255
283
  const result = installSkillToTool(skill, tool);
@@ -258,6 +286,8 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall) {
258
286
  } else {
259
287
  console.log(chalk.red(TERM_GUTTER + "✗ " + skill.name + " → " + tool.name + ": " + result.message));
260
288
  allSuccess = false;
289
+ // 安装失败可能是临时 I/O 问题,可重试
290
+ retryableFailedKeys.add(key);
261
291
  }
262
292
  }
263
293
  }
@@ -267,10 +297,13 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall) {
267
297
  if (allSuccess) {
268
298
  console.log(chalk.green(TERM_GUTTER + "✅ 操作完成!\n"));
269
299
  } else {
270
- console.log(chalk.yellow(TERM_GUTTER + "⚠ 部分操作失败,请检查错误信息。\n"));
300
+ const parts = [];
301
+ if (retryableFailedKeys.size > 0) parts.push(`${retryableFailedKeys.size} 项可重试`);
302
+ if (permanentFailedKeys.size > 0) parts.push(`${permanentFailedKeys.size} 项不可重试`);
303
+ console.log(chalk.yellow(TERM_GUTTER + `⚠ 部分操作失败(${parts.join(",")}),请检查错误信息。\n`));
271
304
  }
272
305
 
273
- return allSuccess;
306
+ return { allSuccess, failedKeys: retryableFailedKeys, permanentFailedKeys };
274
307
  }
275
308
 
276
309
  // ── Unified flow (install / uninstall) ──
@@ -319,16 +352,7 @@ async function runFlow(isUninstall) {
319
352
  if (result === "exit") return "exit";
320
353
  step = 4;
321
354
  } else if (step === 4) {
322
- let attempt = 0;
323
- let allSuccess = false;
324
- while (attempt < 3) {
325
- allSuccess = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall);
326
- if (allSuccess) break;
327
- attempt++;
328
- if (attempt < 3) {
329
- console.log(chalk.yellow(TERM_GUTTER + `第 ${attempt} 次重试...\n`));
330
- }
331
- }
355
+ const { allSuccess, failedKeys, permanentFailedKeys } = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall);
332
356
  if (allSuccess) {
333
357
  await input(
334
358
  {
@@ -339,7 +363,55 @@ async function runFlow(isUninstall) {
339
363
  ).catch(() => {});
340
364
  return "exit";
341
365
  } else {
342
- console.log(chalk.red(TERM_GUTTER + "❌ 重试 3 次后仍有失败,请手动检查。\n"));
366
+ // 卸载操作失败是"未安装",重试无意义;安装操作失败可重试
367
+ if (!isUninstall && failedKeys.size > 0) {
368
+ let attempt = 1;
369
+ let retrySuccess = false;
370
+ let retryFailedKeys = failedKeys;
371
+ let accumulatedPermanent = new Set(permanentFailedKeys);
372
+ while (attempt < 3) {
373
+ console.log(chalk.yellow(TERM_GUTTER + `第 ${attempt} 次重试(${retryFailedKeys.size} 项)...\n`));
374
+ const retryResult = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall, retryFailedKeys);
375
+ retrySuccess = retryResult.allSuccess;
376
+ retryFailedKeys = retryResult.failedKeys;
377
+ for (const k of retryResult.permanentFailedKeys) accumulatedPermanent.add(k);
378
+ if (retrySuccess) break;
379
+ attempt++;
380
+ }
381
+ if (retrySuccess && accumulatedPermanent.size === 0) {
382
+ await input(
383
+ {
384
+ message: "按任意键退出...",
385
+ theme: { prefix: chalk.cyan(" ◆"), style: { highlight: (t) => chalk.cyan(t) } },
386
+ },
387
+ inquirerContext
388
+ ).catch(() => {});
389
+ return "exit";
390
+ } else if (retrySuccess && accumulatedPermanent.size > 0) {
391
+ // 重试成功但仍有不可重试的失败项(如"不支持")
392
+ console.log(chalk.yellow(TERM_GUTTER + `⚠ ${accumulatedPermanent.size} 项不可重试的操作已跳过(不支持或非本工具安装)\n`));
393
+ await input(
394
+ {
395
+ message: "按任意键返回主菜单...",
396
+ theme: { prefix: chalk.cyan(" ◆"), style: { highlight: (t) => chalk.cyan(t) } },
397
+ },
398
+ inquirerContext
399
+ ).catch(() => {});
400
+ return "back";
401
+ }
402
+ } else if (permanentFailedKeys.size > 0 && failedKeys.size === 0) {
403
+ // 全部是 permanent 失败,无重试价值
404
+ console.log(chalk.yellow(TERM_GUTTER + `⚠ ${permanentFailedKeys.size} 项操作不可执行(不支持或非本工具安装),已跳过\n`));
405
+ await input(
406
+ {
407
+ message: "按任意键返回主菜单...",
408
+ theme: { prefix: chalk.cyan(" ◆"), style: { highlight: (t) => chalk.cyan(t) } },
409
+ },
410
+ inquirerContext
411
+ ).catch(() => {});
412
+ return "back";
413
+ }
414
+ console.log(chalk.red(TERM_GUTTER + "❌ 操作未能全部成功,请手动检查。\n"));
343
415
  await input(
344
416
  {
345
417
  message: "按任意键返回主菜单...",
@@ -2,13 +2,18 @@ import { spawnSync } from "child_process";
2
2
  import { platform } from "os";
3
3
 
4
4
  export function commandExists(commandName) {
5
- const lookup = getCommandLookup(platform(), commandName);
6
- const result = spawnSync(lookup.command, lookup.args, {
7
- encoding: "utf-8",
8
- shell: false,
9
- stdio: ["ignore", "pipe", "ignore"],
10
- });
11
- return result.status === 0;
5
+ try {
6
+ const lookup = getCommandLookup(platform(), commandName);
7
+ const result = spawnSync(lookup.command, lookup.args, {
8
+ encoding: "utf-8",
9
+ shell: false,
10
+ stdio: ["ignore", "pipe", "ignore"],
11
+ });
12
+ if (result.error) return false;
13
+ return result.status === 0;
14
+ } catch {
15
+ return false;
16
+ }
12
17
  }
13
18
 
14
19
  export function runCommand(command, args = [], options = {}) {