luminae-helper 1.1.2 → 1.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.2
4
+
5
+ - 公共技能的技能选择、目标工具、确认预览、兼容转换确认面板都固定提供「✕ 退出」;嵌入包装器时额外保留「↩ 返回主菜单」。
6
+ - 面板里显式选「退出」时流程返回 `abort`,包装器据此结束整个工具;「返回主菜单」与操作完成仍返回 `exit`,两者不再混淆。
7
+
8
+ ## 1.2.1
9
+
10
+ - 导出 `checkboxWithActionRows` 与 `NAV_BACK` / `NAV_EXIT`,供包装器的勾选列表复用「返回 / 退出」功能行。
11
+
12
+ ## 1.2.0
13
+
14
+ - 新增 runSkillOperation 单次公共安装/卸载入口,供包装器组织统一主菜单;复用现有保护和租约释放,独立菜单与版本命令保持兼容。
15
+
16
+ - 缓存只长期保留最近一次成功获取的正式版本,自动清理临时数据和闲置历史快照;通过跨进程占用保护并发安装,并在退出后回收,保留本地修改。
17
+
18
+ - 公共技能改为安装 / 更新时拉取 ai-skills 最新正式 Tag,显示版本及提交;不再随 npm 包内置或在构建时下载。
19
+ - 使用专用缓存与独立提交快照;下载失败必须明确选择才使用有效旧缓存,无缓存则停止安装。
20
+ - 从已安装受管内容发现离线卸载条目,不依赖源码缓存;保留现有覆盖保护。
21
+ - 包装器迁移:packageRoot 仅用于包身份和版本查询,移除公共内容打包与 sync-skills 钩子。
22
+
3
23
  ## 1.1.2
4
24
 
5
25
  - 安装时目标已存在且非本工具安装(缺 `managed-by`)→ 跳过并在结果表标「已跳过」,不再覆盖用户自建技能目录。
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 evenweiss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  AI 编程工具的 skills/commands 管理 CLI。一键将公共 AI agent 技能安装到 Claude Code、Cursor、Codex、Hermes Agent、OpenCode、Trae 等工具中。
4
4
 
5
- npm 包在构建时将所有内容打包,运行时纯本地操作文件系统,不访问网络。
5
+ 公共内容不内置在 npm 包中。选择「安装 / 更新」时从 `ai-skills` 拉取最新正式 Git Tag,再复制到目标工具。首次需要网络与 Git;卸载和 `--version` 不需要拉取技能。
6
6
 
7
7
  ## 前置条件
8
8
 
9
9
  - Node.js >= 18.0.0
10
+ - Git(公共技能安装 / 更新需要访问 GitHub)
10
11
  - 至少一个目标 AI 工具已安装
11
12
 
12
13
  ## 安装
@@ -38,7 +39,7 @@ luminae-helper
38
39
 
39
40
  卸载时只会删除带有 `managed-by: luminae-helper` 标识的文件,不会误删用户手动创建或 AI 工具自带的同名文件。
40
41
 
41
- 安装同理:目标位置已有同名的非本工具内容时直接跳过(结果表标「已跳过」),不会覆盖。
42
+ 安装同理:目标位置已有同名的非本工具内容时直接跳过(结果表标「已跳过」),不会覆盖。识别兼容顶层旧字段和 metadata 新字段,仅接受有效 frontmatter 中的 `luminae-helper` 管理者;正文示例、其他管理者、重复键、冲突或损坏内容不认领。公共安装不接管软链或链接形式的 SKILL.md;发现与卸载不会顺带迁移文件。
42
43
 
43
44
  ### 其他命令
44
45
 
@@ -63,7 +64,7 @@ luminae-helper outdated # 检查 npm registry 是否有新版本
63
64
 
64
65
  | 技能 | 用途 |
65
66
  |------|------|
66
- | `ai-development-workflow` | 按任务规模组织 AI 辅助开发协作,维护版本基线、环境受限验证及阶段验收与交接 |
67
+ | `ai-development-workflow` | AI 协作开发流程:协调跨阶段、多工作区和多会话任务,覆盖专业分工、回传监控、验证及交接 |
67
68
  | `git-flow` | Git Flow feature / release / hotfix 分支的创建、检出与 finish,版本号自动计算 |
68
69
  | `identity` | 检测项目类型,自动设定 agent 身份(前端/后端/全栈等) |
69
70
 
@@ -96,13 +97,14 @@ luminae-helper outdated # 检查 npm registry 是否有新版本
96
97
 
97
98
  ### managed-by 标识
98
99
 
99
- 安装时会在目标文件的 YAML frontmatter 中注入 `managed-by: luminae-helper`:
100
+ 复制安装或更新时,在目标文件的 YAML frontmatter 中写入 `metadata.managed-by`;已选中的受管旧副本自动迁移顶层字段,源文件保持不变:
100
101
 
101
102
  ```yaml
102
103
  ---
103
104
  name: git-push
104
105
  description: ...
105
- managed-by: luminae-helper
106
+ metadata:
107
+ managed-by: luminae-helper
106
108
  ---
107
109
  ```
108
110
 
@@ -124,42 +126,28 @@ npm uninstall -g luminae-helper
124
126
 
125
127
  ## 开发
126
128
 
127
- ### 同步公共技能
129
+ ### 公共技能来源与缓存
128
130
 
129
- `commands/` 和 `skills/` 是构建产物(gitignored)。本地开发时,保持 `ai-skills` 为同级目录或设置环境变量:
131
+ 源仓库为 `https://github.com/evenweiss/ai-skills.git`。每次选择「安装 / 更新」都会检查最大正式版本 Tag(`X.Y.Z` 或 `vX.Y.Z`,不含预发布版本),不跟随未发布的 main。界面显示实际 Tag 和提交。
130
132
 
131
- ```bash
132
- git clone https://github.com/evenweiss/ai-skills.git ../ai-skills
133
- LUMINAE_SKILLS_SOURCE=../ai-skills npm run sync-skills
134
- ```
133
+ 缓存位于 `~/.cache/luminae-helper/public-skills/`:首次 clone,后续 fetch。只长期保留最近一次成功获取的正式版本;临时目录和无人使用的历史快照会自动清理。并发安装登记独立占用,旧快照在最后一个使用者退出后才回收,下载与清理不会中断其他安装。正常完成、返回、取消或失败都会释放占用;异常退出的遗留占用与临时数据在下次缓存操作时回收。
134
+
135
+ 不要编辑缓存;工作树或 HEAD 被修改的快照会被保留并提示,不会自动覆盖或删除,因此这类快照需要自行保留改动后处理。
136
+
137
+ 更新失败时,CLI 显示有效旧缓存的 Tag/提交,默认返回;只有明确选择才使用旧缓存安装,且提示未确认是最新版本。没有有效缓存时停止本次安装。删除缓存后,下次安装会重新下载;已安装的受管内容仍可离线卸载,包括新版本中已移除的条目。
135
138
 
136
- 脚本会扫描 `ai-skills/commands/` 和 `ai-skills/skills/`,将包含 `SKILL.md` 的子目录复制到本项目的对应目录。
139
+ 安装继续采用复制方式;更新缓存不会自动修改已安装技能,需要再次选择安装 / 更新。公共技能保留覆盖保护,公司内部技能不属于本工具。
137
140
 
138
- ### 发布
141
+ ### 测试与发布
139
142
 
140
143
  ```bash
141
- npm publish
144
+ npm test
145
+ npm pack
142
146
  ```
143
147
 
144
- 发布前 `prepublishOnly` 钩子以 `--strict` 模式运行同步脚本,确保至少有一个 command 或 skill 被打包。
148
+ 测试使用临时源码、Git 仓库和目标目录,不依赖本地公共技能副本。打包和 npm 安装不再触发技能下载。`commands/`、`skills/` 的旧生成目录仍被忽略,但不会进入 npm 包;旧 `sync-skills` 脚本已移除。
145
149
 
146
- ### 项目结构
147
-
148
- ```
149
- luminae-helper/
150
- ├── src/
151
- │ ├── cli.js # 入口
152
- │ ├── index.js # runCli() 导出
153
- │ └── lib/
154
- │ ├── constants.js # 工具定义、技能发现、安装目标生成
155
- │ ├── installer.js # 安装/卸载逻辑
156
- │ ├── ui.js # 交互式 TUI(inquirer)
157
- │ └── checkbox-with-action-rows.js # 带功能行的多选组件
158
- ├── scripts/fetch-skills.js # 构建时技能同步脚本
159
- ├── commands/ # 构建产物(gitignored)
160
- ├── skills/ # 构建产物(gitignored)
161
- └── package.json
162
- ```
150
+ 需要正式发布 CLI 时再执行 `npm publish`,公共技能的新 Tag 不要求 CLI 同步发版。
163
151
 
164
152
  ## Library API
165
153
 
@@ -170,9 +158,23 @@ import { runCli } from "luminae-helper";
170
158
 
171
159
  const code = await runCli({
172
160
  argv: process.argv.slice(2),
173
- packageRoot: import.meta.dirname, // 指向你自己的 commands/ skills/
161
+ packageRoot: import.meta.dirname, // 包装器的 package.json 所在目录
174
162
  });
175
163
  process.exit(code);
176
164
  ```
177
165
 
178
- `packageRoot` 让包装器提供自己的 `commands/` 和 `skills/`,复用相同的交互式安装引擎。
166
+ `packageRoot` 用于包装器名称、版本和 registry 查询;公共技能统一使用运行时仓库缓存。
167
+
168
+ 迁移注意:`packageRoot` 不再作为公共技能分发源,包装器无需打包自己的 `commands/`、`skills/` 或执行同步钩子。已安装技能的管理标识保持兼容。
169
+
170
+
171
+ 包装器需要自行组织主菜单时,复用单次操作入口:
172
+
173
+ ```js
174
+ import { runSkillOperation } from "luminae-helper";
175
+
176
+ const code = await runSkillOperation("install", { packageRoot: wrapperRoot });
177
+ // 或 runSkillOperation("uninstall", { packageRoot: wrapperRoot })
178
+ ```
179
+
180
+ 只接受 `install` / `uninstall`,非法操作会拒绝。入口不展示引擎自己的主菜单,完成或取消后返回控制权;嵌入流程的操作结束提示为返回主菜单。操作异常返回 `1`,正常或取消返回 `0`。缓存、覆盖保护、复制安装、离线卸载和快照占用释放继续由共享实现负责。独立运行 `luminae-helper` 仍使用原菜单,`runCli()` 的版本命令保持不变。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "luminae-helper",
3
- "version": "1.1.2",
3
+ "version": "1.2.2",
4
4
  "description": "Install public AI agent skills to coding tools",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -12,20 +12,13 @@
12
12
  "src/index.js",
13
13
  "src/lib/*.js",
14
14
  "src/utils/*.js",
15
- "scripts/fetch-skills.js",
16
- "commands/",
17
- "skills/",
18
15
  "README.md",
19
16
  "CHANGELOG.md"
20
17
  ],
21
18
  "scripts": {
22
19
  "start": "node src/cli.js",
23
20
  "dev": "node --watch src/cli.js",
24
- "test": "vitest run",
25
- "sync-skills": "node scripts/fetch-skills.js",
26
- "prepare": "node scripts/fetch-skills.js",
27
- "prepack": "node scripts/fetch-skills.js --strict",
28
- "prepublishOnly": "node scripts/fetch-skills.js --strict"
21
+ "test": "vitest run"
29
22
  },
30
23
  "keywords": [
31
24
  "claude",
@@ -51,7 +44,8 @@
51
44
  "@inquirer/prompts": "^8.3.0",
52
45
  "chalk": "^5.3.0",
53
46
  "gradient-string": "^3.0.0",
54
- "wcwidth": "^1.0.1"
47
+ "wcwidth": "^1.0.1",
48
+ "yaml": "^2.9.1"
55
49
  },
56
50
  "devDependencies": {
57
51
  "vitest": "^4.1.6"
package/src/index.js CHANGED
@@ -1,10 +1,13 @@
1
+ export { isManagedSkill } from "./lib/managed-by.js";
2
+ // 包装器(如 kfz-skills-helper)复用带「返回 / 退出」功能行的多选列表
3
+ export { default as checkboxWithActionRows, NAV_BACK, NAV_EXIT } from "./lib/checkbox-with-action-rows.js";
4
+
1
5
  export async function runCli(options = {}) {
2
6
  const argv = Array.isArray(options.argv) ? options.argv : process.argv.slice(2);
3
7
  if (options.packageRoot) {
4
8
  globalThis.__LUMINAE_PACKAGE_ROOT__ = options.packageRoot;
5
9
  }
6
10
 
7
- const { runInteractive, TERM_GUTTER } = await import("./lib/ui.js");
8
11
  const { printVersion, checkOutdated } = await import("./utils/version.js");
9
12
 
10
13
  if (argv.includes("--version") || argv.includes("-v")) {
@@ -17,15 +20,25 @@ export async function runCli(options = {}) {
17
20
  return 0;
18
21
  }
19
22
 
23
+ const { runInteractive, runOperation, TERM_GUTTER } = await import("./lib/ui.js");
20
24
  try {
21
- await runInteractive();
25
+ if (options.operation) {
26
+ // 面板里显式选择「退出」时,把结束整个工具的意图交给包装器
27
+ if (await runOperation(options.operation) === "abort") return "abort";
28
+ } else await runInteractive();
22
29
  return 0;
23
30
  } catch (error) {
24
31
  if (error?.name === "ExitPromptError") {
25
- console.log("\n" + TERM_GUTTER + "👋 Bye!\n");
32
+ if (!options.operation) console.log("\n" + TERM_GUTTER + "👋 Bye!\n");
26
33
  return 0;
27
34
  }
28
35
  console.error("\n" + TERM_GUTTER + "Error:", error.message ?? String(error));
29
36
  return 1;
30
37
  }
31
38
  }
39
+
40
+ /** Execute one shared public-skill flow, then return control to a wrapper. */
41
+ export async function runSkillOperation(action, options = {}) {
42
+ if (!["install", "uninstall"].includes(action)) throw new TypeError(`Unknown skill operation: ${action}`);
43
+ return runCli({ ...options, argv: [], operation: action });
44
+ }
@@ -0,0 +1,112 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmdirSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { randomUUID } from "node:crypto";
5
+ import { setTimeout as delay } from "node:timers/promises";
6
+
7
+ function isAlive(pid) {
8
+ if (!Number.isSafeInteger(pid) || pid < 1) return true;
9
+ try { process.kill(pid, 0); return true; }
10
+ catch (error) { return error.code !== "ESRCH"; }
11
+ }
12
+ function ownerPid(name) {
13
+ const match = name.match(/^([1-9]\d*)-[a-f0-9-]{36}\.owner$/);
14
+ return match ? Number(match[1]) : null;
15
+ }
16
+ function removeOwner(directory, name) {
17
+ try { unlinkSync(join(directory, name)); } catch (error) { if (error.code !== "ENOENT") throw error; }
18
+ // Never recursively delete a shared lock: a new owner may already be here.
19
+ try { rmdirSync(directory); } catch (error) { if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(error.code)) throw error; }
20
+ }
21
+ function reapDeadLock(directory) {
22
+ try {
23
+ for (const name of readdirSync(directory)) {
24
+ const pid = ownerPid(name);
25
+ if (pid !== null && !isAlive(pid)) removeOwner(directory, name);
26
+ }
27
+ try { rmdirSync(directory); } catch (error) { if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(error.code)) throw error; }
28
+ } catch (error) { if (error.code !== "ENOENT") throw error; }
29
+ }
30
+ export async function withCacheLock(cacheDir, action) {
31
+ mkdirSync(cacheDir, { recursive: true });
32
+ const identity = `${process.pid}-${randomUUID()}`;
33
+ const waiting = join(cacheDir, `lock-${identity}`);
34
+ mkdirSync(waiting);
35
+ const owner = `${identity}.owner`;
36
+ const lock = join(cacheDir, "operation.lock");
37
+ try {
38
+ writeFileSync(join(waiting, owner), "");
39
+ const deadline = Date.now() + 120000;
40
+ while (true) {
41
+ try { renameSync(waiting, lock); break; }
42
+ catch (error) {
43
+ if (!["EEXIST", "ENOTEMPTY"].includes(error.code)) throw error;
44
+ reapDeadLock(lock);
45
+ if (Date.now() >= deadline) throw new Error("公共技能缓存正在更新,请稍后重试");
46
+ await delay(50);
47
+ }
48
+ }
49
+ try { return await action(); }
50
+ finally { removeOwner(lock, owner); }
51
+ } finally { rmSync(waiting, { recursive: true, force: true }); }
52
+ }
53
+ function activeCommits(cacheDir) {
54
+ const directory = join(cacheDir, "leases");
55
+ mkdirSync(directory, { recursive: true });
56
+ const active = new Set();
57
+ for (const name of readdirSync(directory)) {
58
+ if (!/^[a-f0-9-]{36}\.json$/.test(name)) continue;
59
+ const path = join(directory, name);
60
+ let lease;
61
+ try { lease = JSON.parse(readFileSync(path, "utf8")); } catch { rmSync(path, { force: true }); continue; }
62
+ if (isAlive(lease.pid)) {
63
+ if (/^[a-f0-9]{40,64}$/.test(lease.commit)) active.add(lease.commit);
64
+ } else { rmSync(path, { force: true }); }
65
+ }
66
+ return active;
67
+ }
68
+ // All lifecycle mutations, including lease registration, run under the same short lock.
69
+ export function cleanupCache(cacheDir) {
70
+ const active = activeCommits(cacheDir);
71
+ for (const name of readdirSync(cacheDir)) {
72
+ if (/^clone-[\w-]+$/.test(name) || /^current-[\w-]+\.json$/.test(name)) rmSync(join(cacheDir, name), { recursive: true, force: true });
73
+ const waiting = name.match(/^lock-([1-9]\d*)-[a-f0-9-]{36}$/);
74
+ if (waiting && !isAlive(Number(waiting[1]))) rmSync(join(cacheDir, name), { recursive: true, force: true });
75
+ }
76
+ let current;
77
+ try { current = JSON.parse(readFileSync(join(cacheDir, "current.json"), "utf8")).commit; } catch { /* Keep snapshots if the pointer cannot be read. */ }
78
+ const directory = join(cacheDir, "snapshots");
79
+ if (!existsSync(directory)) return;
80
+ for (const name of readdirSync(directory)) {
81
+ const path = join(directory, name);
82
+ if (/^checkout-[\w-]+$/.test(name)) { rmSync(path, { recursive: true, force: true }); continue; }
83
+ if (!/^[a-f0-9]{40,64}$/.test(current || "") || !/^[a-f0-9]{40,64}$/.test(name) || name === current || active.has(name)) continue;
84
+ if (!lstatSync(path).isDirectory()) continue;
85
+ try {
86
+ const run = args => execFileSync("git", args, { cwd: path, encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "pipe"] }).trim();
87
+ if (run(["rev-parse", "HEAD"]) !== name || run(["status", "--porcelain", "--untracked-files=all", "--ignored"])) {
88
+ console.warn(`公共技能旧快照包含本地修改,已保留:${path}`);
89
+ continue;
90
+ }
91
+ } catch { console.warn(`公共技能旧快照无法验证,已保留:${path}`); continue; }
92
+ rmSync(path, { recursive: true, force: true });
93
+ }
94
+ }
95
+ export function leaseSource(cacheDir, source) {
96
+ const directory = join(cacheDir, "leases");
97
+ mkdirSync(directory, { recursive: true });
98
+ const path = join(directory, `${randomUUID()}.json`);
99
+ writeFileSync(path, JSON.stringify({ pid: process.pid, commit: source.commit }));
100
+ let released = false;
101
+ return {
102
+ ...source,
103
+ async release() {
104
+ if (released) return;
105
+ await withCacheLock(cacheDir, () => {
106
+ rmSync(path, { force: true });
107
+ cleanupCache(cacheDir);
108
+ released = true;
109
+ });
110
+ },
111
+ };
112
+ }
@@ -1,6 +1,7 @@
1
1
  import { homedir } from "os";
2
2
  import { join } from "path";
3
- import { existsSync, readdirSync, readFileSync, statSync } from "fs";
3
+ import { existsSync, readdirSync, readFileSync, lstatSync } from "fs";
4
+ import { isManagedSkill } from "./managed-by.js";
4
5
  import { commandExists } from "../utils/platform.js";
5
6
 
6
7
  // ── Tools ──
@@ -147,8 +148,9 @@ function generateInstallTargets(skillId, skillType) {
147
148
  return targets;
148
149
  }
149
150
 
150
- export function discoverSkills() {
151
- const packageDir = getPackageDir();
151
+ let skillsRoot = null;
152
+
153
+ export function discoverSkills(packageDir = skillsRoot || getPackageDir()) {
152
154
  const skills = [];
153
155
 
154
156
  const typeDirs = [
@@ -160,14 +162,14 @@ export function discoverSkills() {
160
162
 
161
163
  for (const { dir, type } of typeDirs) {
162
164
  const typePath = join(packageDir, dir);
163
- if (!existsSync(typePath)) continue;
165
+ if (!existsSync(typePath) || !lstatSync(typePath).isDirectory()) continue;
164
166
 
165
167
  for (const entry of readdirSync(typePath)) {
166
168
  const skillPath = join(typePath, entry);
167
- if (!statSync(skillPath).isDirectory()) continue;
169
+ if (!lstatSync(skillPath).isDirectory()) continue;
168
170
 
169
171
  const skillFile = join(skillPath, "SKILL.md");
170
- if (!existsSync(skillFile)) continue;
172
+ if (!existsSync(skillFile) || !lstatSync(skillFile).isFile()) continue;
171
173
 
172
174
  const skillId = entry;
173
175
 
@@ -195,6 +197,40 @@ export function discoverSkills() {
195
197
 
196
198
  export const SKILLS = discoverSkills();
197
199
 
200
+ export function setSkillsSource(root) {
201
+ const skills = discoverSkills(root);
202
+ skillsRoot = root;
203
+ SKILLS.splice(0, SKILLS.length, ...skills);
204
+ }
205
+
206
+ export function discoverInstalledSkills(tools = TOOLS) {
207
+ const found = new Map();
208
+ for (const tool of tools) {
209
+ for (const mode of ["file", "dir"]) {
210
+ const parent = mode === "file" ? tool.commandDir?.() : tool.skillDir?.();
211
+ if (!parent || !existsSync(parent)) continue;
212
+ for (const entry of readdirSync(parent)) {
213
+ const dest = join(parent, entry);
214
+ if (mode === "file" ? !entry.endsWith(".md") || !lstatSync(dest).isFile() : !lstatSync(dest).isDirectory()) continue;
215
+ const file = mode === "file" ? dest : join(dest, "SKILL.md");
216
+ if (!existsSync(file) || !lstatSync(file).isFile()) continue;
217
+ const content = readFileSync(file, "utf8");
218
+ if (!isManagedSkill(content)) continue;
219
+ const id = mode === "file" ? entry.slice(0, -3) : entry;
220
+ // A command and a skill with the same id may both be installed in one tool.
221
+ const key = `${mode}:${id}`;
222
+ if (!found.has(key)) found.set(key, { id: key, ...parseSkillMeta(id, content), type: mode === "file" ? "command" : "skill", installTargets: [] });
223
+ found.get(key).installTargets.push({ toolId: tool.id, installMode: mode, conversion: null, destPath: () => dest });
224
+ }
225
+ }
226
+ }
227
+ return [...found.values()];
228
+ }
229
+
230
+ export function useInstalledSkills() {
231
+ SKILLS.splice(0, SKILLS.length, ...discoverInstalledSkills());
232
+ }
233
+
198
234
  export function detectInstalledTools() {
199
235
  return TOOLS.map((tool) => ({
200
236
  ...tool,
@@ -208,5 +244,5 @@ export function getSkillSourcePath(skillId) {
208
244
  throw new Error(`Unknown skillId: "${skillId}" — not found in discovered skills`);
209
245
  }
210
246
  const subDir = skill.type === "command" ? "commands" : "skills";
211
- return join(getPackageDir(), subDir, skillId);
247
+ return join(skillsRoot || getPackageDir(), subDir, skillId);
212
248
  }