luminae-helper 1.2.0 → 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 +9 -0
- package/LICENSE +21 -0
- package/README.md +5 -4
- package/package.json +3 -2
- package/src/index.js +8 -2
- package/src/lib/constants.js +2 -1
- package/src/lib/installer.js +50 -128
- package/src/lib/managed-by.js +68 -0
- package/src/lib/ui.js +23 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
|
|
3
12
|
## 1.2.0
|
|
4
13
|
|
|
5
14
|
- 新增 runSkillOperation 单次公共安装/卸载入口,供包装器组织统一主菜单;复用现有保护和租约释放,独立菜单与版本命令保持兼容。
|
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
|
@@ -39,7 +39,7 @@ luminae-helper
|
|
|
39
39
|
|
|
40
40
|
卸载时只会删除带有 `managed-by: luminae-helper` 标识的文件,不会误删用户手动创建或 AI 工具自带的同名文件。
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
安装同理:目标位置已有同名的非本工具内容时直接跳过(结果表标「已跳过」),不会覆盖。识别兼容顶层旧字段和 metadata 新字段,仅接受有效 frontmatter 中的 `luminae-helper` 管理者;正文示例、其他管理者、重复键、冲突或损坏内容不认领。公共安装不接管软链或链接形式的 SKILL.md;发现与卸载不会顺带迁移文件。
|
|
43
43
|
|
|
44
44
|
### 其他命令
|
|
45
45
|
|
|
@@ -64,7 +64,7 @@ luminae-helper outdated # 检查 npm registry 是否有新版本
|
|
|
64
64
|
|
|
65
65
|
| 技能 | 用途 |
|
|
66
66
|
|------|------|
|
|
67
|
-
| `ai-development-workflow` |
|
|
67
|
+
| `ai-development-workflow` | AI 协作开发流程:协调跨阶段、多工作区和多会话任务,覆盖专业分工、回传监控、验证及交接 |
|
|
68
68
|
| `git-flow` | Git Flow feature / release / hotfix 分支的创建、检出与 finish,版本号自动计算 |
|
|
69
69
|
| `identity` | 检测项目类型,自动设定 agent 身份(前端/后端/全栈等) |
|
|
70
70
|
|
|
@@ -97,13 +97,14 @@ luminae-helper outdated # 检查 npm registry 是否有新版本
|
|
|
97
97
|
|
|
98
98
|
### managed-by 标识
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
复制安装或更新时,在目标文件的 YAML frontmatter 中写入 `metadata.managed-by`;已选中的受管旧副本自动迁移顶层字段,源文件保持不变:
|
|
101
101
|
|
|
102
102
|
```yaml
|
|
103
103
|
---
|
|
104
104
|
name: git-push
|
|
105
105
|
description: ...
|
|
106
|
-
|
|
106
|
+
metadata:
|
|
107
|
+
managed-by: luminae-helper
|
|
107
108
|
---
|
|
108
109
|
```
|
|
109
110
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "luminae-helper",
|
|
3
|
-
"version": "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",
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"@inquirer/prompts": "^8.3.0",
|
|
45
45
|
"chalk": "^5.3.0",
|
|
46
46
|
"gradient-string": "^3.0.0",
|
|
47
|
-
"wcwidth": "^1.0.1"
|
|
47
|
+
"wcwidth": "^1.0.1",
|
|
48
|
+
"yaml": "^2.9.1"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"vitest": "^4.1.6"
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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) {
|
|
@@ -18,8 +22,10 @@ export async function runCli(options = {}) {
|
|
|
18
22
|
|
|
19
23
|
const { runInteractive, runOperation, TERM_GUTTER } = await import("./lib/ui.js");
|
|
20
24
|
try {
|
|
21
|
-
if (options.operation)
|
|
22
|
-
|
|
25
|
+
if (options.operation) {
|
|
26
|
+
// 面板里显式选择「退出」时,把结束整个工具的意图交给包装器
|
|
27
|
+
if (await runOperation(options.operation) === "abort") return "abort";
|
|
28
|
+
} else await runInteractive();
|
|
23
29
|
return 0;
|
|
24
30
|
} catch (error) {
|
|
25
31
|
if (error?.name === "ExitPromptError") {
|
package/src/lib/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { homedir } from "os";
|
|
2
2
|
import { join } from "path";
|
|
3
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 ──
|
|
@@ -214,7 +215,7 @@ export function discoverInstalledSkills(tools = TOOLS) {
|
|
|
214
215
|
const file = mode === "file" ? dest : join(dest, "SKILL.md");
|
|
215
216
|
if (!existsSync(file) || !lstatSync(file).isFile()) continue;
|
|
216
217
|
const content = readFileSync(file, "utf8");
|
|
217
|
-
if (!content
|
|
218
|
+
if (!isManagedSkill(content)) continue;
|
|
218
219
|
const id = mode === "file" ? entry.slice(0, -3) : entry;
|
|
219
220
|
// A command and a skill with the same id may both be installed in one tool.
|
|
220
221
|
const key = `${mode}:${id}`;
|
package/src/lib/installer.js
CHANGED
|
@@ -1,51 +1,7 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, copyFileSync, readFileSync, readdirSync, renameSync, rmSync,
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, copyFileSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, writeFileSync } from "fs";
|
|
2
2
|
import { dirname, join } from "path";
|
|
3
3
|
import { getSkillSourcePath } from "./constants.js";
|
|
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
|
-
}
|
|
4
|
+
import { isManagedSkill, withManagedBy } from "./managed-by.js";
|
|
49
5
|
|
|
50
6
|
function ensureDir(filePath) {
|
|
51
7
|
const dir = dirname(filePath);
|
|
@@ -62,77 +18,46 @@ function copyFile(src, dest) {
|
|
|
62
18
|
/** 目录名黑名单:复制 skill 目录时跳过这些条目,避免污染用户 home */
|
|
63
19
|
const COPY_SKIP_ENTRIES = new Set(["node_modules", ".git", ".DS_Store", "Thumbs.db", "README.md"]);
|
|
64
20
|
|
|
65
|
-
function copyDir(src, dest) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
if (existsSync(tmpDest)) {
|
|
70
|
-
rmSync(tmpDest, { recursive: true, force: true });
|
|
71
|
-
}
|
|
72
|
-
mkdirSync(tmpDest, { recursive: true });
|
|
73
|
-
const entries = readdirSync(src, { withFileTypes: true });
|
|
74
|
-
for (const entry of entries) {
|
|
75
|
-
if (COPY_SKIP_ENTRIES.has(entry.name)) continue;
|
|
76
|
-
// 软链一律跳过:跟随复制会把包外文件内容带进工具目录
|
|
77
|
-
if (entry.isSymbolicLink()) continue;
|
|
78
|
-
const srcPath = join(src, entry.name);
|
|
79
|
-
const destPath = join(tmpDest, entry.name);
|
|
80
|
-
if (entry.isDirectory()) {
|
|
81
|
-
copyDir(srcPath, destPath);
|
|
82
|
-
} else {
|
|
83
|
-
copyFile(srcPath, destPath);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// 临时目录拷贝完成,替换目标
|
|
87
|
-
// 先备份旧目标,rename 失败时可恢复
|
|
88
|
-
const backupDest = dest + ".__bak__";
|
|
21
|
+
function copyDir(src, dest, managedContent) {
|
|
22
|
+
ensureDir(dest);
|
|
23
|
+
const tmpDest = mkdtempSync(dest + ".__tmp__");
|
|
24
|
+
const backupDest = tmpDest + ".__bak__";
|
|
89
25
|
let hasBackup = false;
|
|
90
|
-
|
|
91
|
-
|
|
26
|
+
let committed = false;
|
|
27
|
+
try {
|
|
28
|
+
for (const entry of readdirSync(src, { withFileTypes: true })) {
|
|
29
|
+
if (COPY_SKIP_ENTRIES.has(entry.name) || entry.isSymbolicLink()) continue;
|
|
30
|
+
const srcPath = join(src, entry.name);
|
|
31
|
+
const destPath = join(tmpDest, entry.name);
|
|
32
|
+
if (entry.isDirectory()) copyDir(srcPath, destPath);
|
|
33
|
+
else copyFile(srcPath, destPath);
|
|
34
|
+
}
|
|
35
|
+
if (managedContent !== undefined) writeFileSync(join(tmpDest, "SKILL.md"), managedContent, "utf8");
|
|
36
|
+
if (lstatSync(dest, { throwIfNoEntry: false })) {
|
|
92
37
|
renameSync(dest, backupDest);
|
|
93
38
|
hasBackup = true;
|
|
94
|
-
} catch {
|
|
95
|
-
// 无法重命名旧目录,直接删除
|
|
96
|
-
rmSync(dest, { recursive: true, force: true });
|
|
97
39
|
}
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
40
|
renameSync(tmpDest, dest);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (hasBackup &&
|
|
104
|
-
try { renameSync(backupDest, dest); }
|
|
41
|
+
committed = true;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (hasBackup && !lstatSync(dest, { throwIfNoEntry: false })) {
|
|
44
|
+
try { renameSync(backupDest, dest); }
|
|
45
|
+
catch { throw new Error(`安装失败,旧内容保留于 ${backupDest}`); }
|
|
105
46
|
}
|
|
106
|
-
|
|
47
|
+
throw error;
|
|
48
|
+
} finally {
|
|
107
49
|
if (existsSync(tmpDest)) rmSync(tmpDest, { recursive: true, force: true });
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
// 成功后清理备份
|
|
111
|
-
if (hasBackup && existsSync(backupDest)) {
|
|
112
|
-
rmSync(backupDest, { recursive: true, force: true });
|
|
50
|
+
if (committed && hasBackup) rmSync(backupDest, { recursive: true, force: true });
|
|
113
51
|
}
|
|
114
52
|
}
|
|
115
53
|
|
|
116
|
-
/**
|
|
117
|
-
* 检查目标路径是否由本工具安装(SKILL.md / .md 文件中包含 `managed-by: luminae-helper`),
|
|
118
|
-
* 避免误删用户手动创建或 AI 工具自带的同名文件/目录。
|
|
119
|
-
*/
|
|
54
|
+
/** Only regular managed copies belong to the public installer; links have separate owners. */
|
|
120
55
|
function isInstalledByUs(destPath, isDirBased) {
|
|
121
|
-
if (!existsSync(destPath)) return false;
|
|
122
56
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const content = readFileSync(skillFile, "utf-8");
|
|
128
|
-
return hasManagedBy(content);
|
|
129
|
-
} else {
|
|
130
|
-
// file 模式:检查 .md 文件内容是否含 managed-by 标识
|
|
131
|
-
const stat = statSync(destPath);
|
|
132
|
-
if (!stat.isFile() || stat.size === 0) return false;
|
|
133
|
-
const content = readFileSync(destPath, "utf-8");
|
|
134
|
-
return hasManagedBy(content);
|
|
135
|
-
}
|
|
57
|
+
const stat = lstatSync(destPath);
|
|
58
|
+
if (isDirBased ? !stat.isDirectory() : !stat.isFile()) return false;
|
|
59
|
+
const file = isDirBased ? join(destPath, "SKILL.md") : destPath;
|
|
60
|
+
return lstatSync(file).isFile() && isManagedSkill(readFileSync(file, "utf8"));
|
|
136
61
|
} catch {
|
|
137
62
|
return false;
|
|
138
63
|
}
|
|
@@ -165,33 +90,30 @@ export function installSkillToTool(skill, tool) {
|
|
|
165
90
|
const destPath = target.destPath();
|
|
166
91
|
const isDirBased = target.installMode === "dir";
|
|
167
92
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (isDirBased) {
|
|
174
|
-
try {
|
|
175
|
-
copyDir(sourceDir, destPath);
|
|
176
|
-
} catch (e) {
|
|
177
|
-
return { success: false, message: `安装失败: ${e.message}` };
|
|
93
|
+
try {
|
|
94
|
+
if (lstatSync(destPath, { throwIfNoEntry: false }) && !isInstalledByUs(destPath, isDirBased)) {
|
|
95
|
+
return { success: false, skipped: true, message: `目标已存在且非本工具安装,已跳过: ${destPath}` };
|
|
178
96
|
}
|
|
179
|
-
// 注入 managed-by 标识到目标 SKILL.md
|
|
180
|
-
stampManagedBy(join(destPath, "SKILL.md"));
|
|
181
|
-
return { success: true, message: `Installed to ${destPath}` };
|
|
182
|
-
} else {
|
|
183
97
|
const srcSkillFile = join(sourceDir, "SKILL.md");
|
|
184
|
-
if (!
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
98
|
+
if (!lstatSync(srcSkillFile).isFile()) throw new Error("SKILL.md must be a regular file");
|
|
99
|
+
const managedContent = withManagedBy(readFileSync(srcSkillFile, "utf8"));
|
|
100
|
+
if (isDirBased) {
|
|
101
|
+
copyDir(sourceDir, destPath, managedContent);
|
|
102
|
+
} else {
|
|
103
|
+
ensureDir(destPath);
|
|
104
|
+
const stagingDir = mkdtempSync(destPath + ".__tmp__");
|
|
105
|
+
try {
|
|
106
|
+
const stagedFile = join(stagingDir, "content.md");
|
|
107
|
+
copyFileSync(srcSkillFile, stagedFile);
|
|
108
|
+
writeFileSync(stagedFile, managedContent, "utf8");
|
|
109
|
+
renameSync(stagedFile, destPath);
|
|
110
|
+
} finally {
|
|
111
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
112
|
+
}
|
|
191
113
|
}
|
|
192
|
-
// 注入 managed-by 标识到目标 .md 文件
|
|
193
|
-
stampManagedBy(destPath);
|
|
194
114
|
return { success: true, message: `Installed to ${destPath}` };
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return { success: false, message: `安装失败: ${error.message}` };
|
|
195
117
|
}
|
|
196
118
|
}
|
|
197
119
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Document, isMap, isScalar, parseDocument, visit } from "yaml";
|
|
2
|
+
|
|
3
|
+
const MANAGED_BY = "luminae-helper";
|
|
4
|
+
|
|
5
|
+
function frontmatter(content) {
|
|
6
|
+
const bom = content.startsWith("\uFEFF") ? "\uFEFF" : "";
|
|
7
|
+
if (!/^\uFEFF?---[ \t]*(?:\r?\n|$)/.test(content)) {
|
|
8
|
+
return { doc: new Document({}), body: content.slice(bom.length), bom, eol: "\n" };
|
|
9
|
+
}
|
|
10
|
+
const match = content.match(/^\uFEFF?---[ \t]*\r?\n([\s\S]*?)^---[ \t]*(?:\r?\n|$)/m);
|
|
11
|
+
if (!match) throw new Error("Unclosed skill frontmatter");
|
|
12
|
+
const doc = parseDocument(match[1], { uniqueKeys: true, stringKeys: true, prettyErrors: false });
|
|
13
|
+
if (doc.errors.length || doc.warnings.length || (doc.contents !== null && !isMap(doc.contents))) {
|
|
14
|
+
throw new Error("Invalid skill frontmatter");
|
|
15
|
+
}
|
|
16
|
+
// Parsing alone does not validate missing/forward aliases or excessive alias expansion.
|
|
17
|
+
doc.toJS({ maxAliasCount: 100 });
|
|
18
|
+
if (doc.contents === null) doc.contents = doc.createNode({});
|
|
19
|
+
if (doc.has("metadata") && !isMap(doc.get("metadata", true))) {
|
|
20
|
+
throw new Error("Skill metadata must be a mapping");
|
|
21
|
+
}
|
|
22
|
+
return { doc, body: content.slice(match[0].length), bom, eol: match[0].includes("\r\n") ? "\r\n" : "\n" };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function markers(doc) {
|
|
26
|
+
const result = [];
|
|
27
|
+
if (doc.has("managed-by")) result.push(doc.get("managed-by", true));
|
|
28
|
+
const metadata = doc.get("metadata", true);
|
|
29
|
+
if (metadata?.has("managed-by")) result.push(metadata.get("managed-by", true));
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Ownership comes only from unambiguous frontmatter, never body examples or names. */
|
|
34
|
+
export function isManagedSkill(content) {
|
|
35
|
+
try {
|
|
36
|
+
const owners = markers(frontmatter(content).doc);
|
|
37
|
+
return owners.length > 0 && owners.every(owner => isScalar(owner) && owner.value === MANAGED_BY);
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function withManagedBy(content) {
|
|
44
|
+
const { doc, body, bom, eol } = frontmatter(content);
|
|
45
|
+
if (markers(doc).some(owner => !isScalar(owner) || owner.value !== MANAGED_BY)) {
|
|
46
|
+
throw new Error("Skill management owner is invalid or conflicts with this tool");
|
|
47
|
+
}
|
|
48
|
+
const legacy = doc.get("managed-by", true);
|
|
49
|
+
const oldKey = doc.contents.items.find(pair => pair.key?.value === "managed-by")?.key;
|
|
50
|
+
if (legacy?.anchor || oldKey?.anchor) {
|
|
51
|
+
// Moving the owner must not move its anchor after an existing alias.
|
|
52
|
+
visit(doc, { Alias: (_key, alias) => {
|
|
53
|
+
const target = alias.resolve(doc);
|
|
54
|
+
if (target !== legacy && target !== oldKey) return;
|
|
55
|
+
const scalar = doc.createNode(target.value);
|
|
56
|
+
scalar.comment = alias.comment;
|
|
57
|
+
scalar.commentBefore = alias.commentBefore;
|
|
58
|
+
return scalar;
|
|
59
|
+
} });
|
|
60
|
+
}
|
|
61
|
+
const marker = doc.getIn(["metadata", "managed-by"], true) ?? legacy ?? doc.createNode(MANAGED_BY);
|
|
62
|
+
if (oldKey?.commentBefore) marker.commentBefore = [oldKey.commentBefore, marker.commentBefore].filter(Boolean).join("\n");
|
|
63
|
+
if (legacy && legacy !== marker && legacy.comment) marker.comment = [marker.comment, legacy.comment].filter(Boolean).join("\n");
|
|
64
|
+
doc.delete("managed-by");
|
|
65
|
+
doc.setIn(["metadata", "managed-by"], marker);
|
|
66
|
+
const header = doc.toString({ lineWidth: 0 }).replaceAll("\n", eol);
|
|
67
|
+
return `${bom}---${eol}${header}---${eol}${body}`;
|
|
68
|
+
}
|
package/src/lib/ui.js
CHANGED
|
@@ -195,7 +195,8 @@ async function stepConfirmConversionFallbacks(skillIds, toolIds, embedded = fals
|
|
|
195
195
|
{ name: "✓ 允许转换并安装", value: "allow" },
|
|
196
196
|
{ name: "- 跳过该工具的这些转换项", value: "skip" },
|
|
197
197
|
{ name: "↩ 返回上一步", value: "back" },
|
|
198
|
-
{ name:
|
|
198
|
+
...(embedded ? [{ name: "↩ 返回主菜单", value: "menu" }] : []),
|
|
199
|
+
{ name: "✕ 退出", value: "exit" },
|
|
199
200
|
],
|
|
200
201
|
theme: { prefix: chalk.cyan(" ◆"), style: { highlight: (t) => chalk.cyan(t) } },
|
|
201
202
|
},
|
|
@@ -203,7 +204,8 @@ async function stepConfirmConversionFallbacks(skillIds, toolIds, embedded = fals
|
|
|
203
204
|
).catch(() => "back");
|
|
204
205
|
|
|
205
206
|
if (ans === "back") return { action: "back", skippedKeys };
|
|
206
|
-
if (ans === "
|
|
207
|
+
if (ans === "menu") return { action: "exit", skippedKeys };
|
|
208
|
+
if (ans === "exit") return { action: "abort", skippedKeys };
|
|
207
209
|
if (ans === "skip") {
|
|
208
210
|
for (const { skill } of items) skippedKeys.add(`${toolId}::${skill.id}`);
|
|
209
211
|
}
|
|
@@ -243,7 +245,7 @@ async function runCheckbox(config) {
|
|
|
243
245
|
}
|
|
244
246
|
|
|
245
247
|
// ── Step 1: Select entries (checkbox multi-select) ──
|
|
246
|
-
async function stepSelectSkills(
|
|
248
|
+
async function stepSelectSkills() {
|
|
247
249
|
while (true) {
|
|
248
250
|
await afterPromptFlush();
|
|
249
251
|
printBanner();
|
|
@@ -262,7 +264,7 @@ async function stepSelectSkills(embedded = false) {
|
|
|
262
264
|
|
|
263
265
|
const ans = await runCheckbox({
|
|
264
266
|
message: "选择命令/技能:",
|
|
265
|
-
choices: withNavChoices(skillChoices, "↩ 返回主菜单",
|
|
267
|
+
choices: withNavChoices(skillChoices, "↩ 返回主菜单", "✕ 退出"),
|
|
266
268
|
loop: false,
|
|
267
269
|
theme,
|
|
268
270
|
});
|
|
@@ -270,7 +272,7 @@ async function stepSelectSkills(embedded = false) {
|
|
|
270
272
|
const result = parseCheckboxResult(ans);
|
|
271
273
|
|
|
272
274
|
if (result === "back") return "back";
|
|
273
|
-
if (result === "exit") return "
|
|
275
|
+
if (result === "exit") return "abort";
|
|
274
276
|
|
|
275
277
|
if (result.length === 0) {
|
|
276
278
|
console.log(chalk.yellow(TERM_GUTTER + "请至少选择一个命令/技能"));
|
|
@@ -283,7 +285,7 @@ async function stepSelectSkills(embedded = false) {
|
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
// ── Step 2: Select tools (checkbox multi-select) ──
|
|
286
|
-
async function stepSelectTools(installedTools
|
|
288
|
+
async function stepSelectTools(installedTools) {
|
|
287
289
|
while (true) {
|
|
288
290
|
await afterPromptFlush();
|
|
289
291
|
printBanner();
|
|
@@ -302,7 +304,7 @@ async function stepSelectTools(installedTools, embedded = false) {
|
|
|
302
304
|
// 第二步:底部为返回/退出功能行(移上后回车触发)
|
|
303
305
|
const ans = await runCheckbox({
|
|
304
306
|
message: "选择工具:",
|
|
305
|
-
choices: withNavChoices(toolChoices, "↩ 返回上一步",
|
|
307
|
+
choices: withNavChoices(toolChoices, "↩ 返回上一步", "✕ 退出"),
|
|
306
308
|
loop: false,
|
|
307
309
|
theme,
|
|
308
310
|
});
|
|
@@ -310,7 +312,7 @@ async function stepSelectTools(installedTools, embedded = false) {
|
|
|
310
312
|
const result = parseCheckboxResult(ans);
|
|
311
313
|
|
|
312
314
|
if (result === "back") return "back";
|
|
313
|
-
if (result === "exit") return "
|
|
315
|
+
if (result === "exit") return "abort";
|
|
314
316
|
|
|
315
317
|
if (result.length === 0) {
|
|
316
318
|
console.log(chalk.yellow(TERM_GUTTER + "请至少选择一个工具"));
|
|
@@ -346,13 +348,16 @@ async function stepPreviewConfirm(isUninstall, embedded = false) {
|
|
|
346
348
|
choices: [
|
|
347
349
|
{ name: "✓ 确认" + actionLabel, value: "confirm" },
|
|
348
350
|
{ name: "↩ 返回上一步", value: "back" },
|
|
349
|
-
{ name:
|
|
351
|
+
...(embedded ? [{ name: "↩ 返回主菜单", value: "menu" }] : []),
|
|
352
|
+
{ name: "✕ 退出", value: "exit" },
|
|
350
353
|
],
|
|
351
354
|
theme: { prefix: chalk.cyan(" ◆"), style: { highlight: (t) => chalk.cyan(t) } },
|
|
352
355
|
},
|
|
353
356
|
inquirerContext
|
|
354
357
|
).catch(() => "back");
|
|
355
358
|
|
|
359
|
+
if (ans === "menu") return "exit"; // 结束本次操作,回包装器主菜单
|
|
360
|
+
if (ans === "exit") return "abort"; // 退出整个工具
|
|
356
361
|
return ans;
|
|
357
362
|
}
|
|
358
363
|
|
|
@@ -578,25 +583,27 @@ async function runFlowWithSource(isUninstall, holdSource, embedded) {
|
|
|
578
583
|
|
|
579
584
|
while (true) {
|
|
580
585
|
if (step === 1) {
|
|
581
|
-
const result = await stepSelectSkills(
|
|
586
|
+
const result = await stepSelectSkills();
|
|
582
587
|
if (result === "back") return "back";
|
|
583
|
-
if (result === "
|
|
588
|
+
if (result === "abort") return "abort";
|
|
584
589
|
selectedSkillIds = result;
|
|
585
590
|
step = 2;
|
|
586
591
|
} else if (step === 2) {
|
|
587
|
-
const result = await stepSelectTools(installedTools
|
|
592
|
+
const result = await stepSelectTools(installedTools);
|
|
588
593
|
if (result === "back") { step = 1; continue; }
|
|
589
|
-
if (result === "
|
|
594
|
+
if (result === "abort") return "abort";
|
|
590
595
|
selectedToolIds = result;
|
|
591
596
|
skippedConversionKeys = new Set();
|
|
592
597
|
step = 3;
|
|
593
598
|
} else if (step === 3) {
|
|
594
599
|
const result = await stepPreviewConfirm(isUninstall, embedded);
|
|
595
600
|
if (result === "back") { step = 2; continue; }
|
|
601
|
+
if (result === "abort") return "abort";
|
|
596
602
|
if (result === "exit") return "exit";
|
|
597
603
|
if (!isUninstall && SHOW_CONVERSION_CONFIRM_PROMPT) {
|
|
598
604
|
const fallbackResult = await stepConfirmConversionFallbacks(selectedSkillIds, selectedToolIds, embedded);
|
|
599
605
|
if (fallbackResult.action === "back") { step = 2; continue; }
|
|
606
|
+
if (fallbackResult.action === "abort") return "abort";
|
|
600
607
|
if (fallbackResult.action === "exit") return "exit";
|
|
601
608
|
skippedConversionKeys = fallbackResult.skippedKeys;
|
|
602
609
|
}
|
|
@@ -685,8 +692,9 @@ async function runFlowWithSource(isUninstall, holdSource, embedded) {
|
|
|
685
692
|
export async function runOperation(action) {
|
|
686
693
|
if (!["install", "uninstall"].includes(action)) throw new TypeError(`Unknown skill operation: ${action}`);
|
|
687
694
|
await afterPromptFlush();
|
|
688
|
-
await runFlow(action === "uninstall", true);
|
|
695
|
+
const result = await runFlow(action === "uninstall", true);
|
|
689
696
|
await afterPromptFlush();
|
|
697
|
+
return result;
|
|
690
698
|
}
|
|
691
699
|
|
|
692
700
|
// ── Main ──
|
|
@@ -716,7 +724,7 @@ export async function runInteractive() {
|
|
|
716
724
|
await afterPromptFlush();
|
|
717
725
|
const result = await runFlow(action === "uninstall");
|
|
718
726
|
|
|
719
|
-
if (result === "exit") {
|
|
727
|
+
if (result === "exit" || result === "abort") {
|
|
720
728
|
exit = true;
|
|
721
729
|
}
|
|
722
730
|
await afterPromptFlush();
|