iskills 0.2.27 → 0.2.40
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/README.md +8 -13
- package/bin/iskills.js +9 -0
- package/dist/src/cli.js +16 -17
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/browser-actions.d.ts +5 -0
- package/dist/src/commands/browser-actions.js +345 -0
- package/dist/src/commands/browser-actions.js.map +1 -0
- package/dist/src/commands/index.d.ts +3 -6
- package/dist/src/commands/index.js +18 -131
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/library.d.ts +0 -1
- package/dist/src/commands/library.js +40 -216
- package/dist/src/commands/library.js.map +1 -1
- package/dist/src/commands/search.js +32 -47
- package/dist/src/commands/search.js.map +1 -1
- package/dist/src/domain/collection-write.d.ts +22 -0
- package/dist/src/domain/collection-write.js +411 -0
- package/dist/src/domain/collection-write.js.map +1 -0
- package/dist/src/domain/core.d.ts +2 -10
- package/dist/src/domain/core.js +18 -261
- package/dist/src/domain/core.js.map +1 -1
- package/dist/src/domain/git.js +15 -25
- package/dist/src/domain/git.js.map +1 -1
- package/dist/src/domain/types.d.ts +7 -1
- package/dist/src/ui/browser/browser.d.ts +11 -0
- package/dist/src/ui/browser/browser.js +657 -0
- package/dist/src/ui/browser/browser.js.map +1 -0
- package/dist/src/ui/browser/detail.d.ts +12 -0
- package/dist/src/ui/browser/detail.js +47 -0
- package/dist/src/ui/browser/detail.js.map +1 -0
- package/dist/src/ui/browser/footer.d.ts +6 -0
- package/dist/src/ui/browser/footer.js +199 -0
- package/dist/src/ui/browser/footer.js.map +1 -0
- package/dist/src/ui/browser/format.d.ts +105 -0
- package/dist/src/ui/browser/format.js +421 -0
- package/dist/src/ui/browser/format.js.map +1 -0
- package/dist/src/ui/browser/index.d.ts +16 -0
- package/dist/src/ui/browser/index.js +176 -0
- package/dist/src/ui/browser/index.js.map +1 -0
- package/dist/src/ui/browser/layout.d.ts +31 -0
- package/dist/src/ui/browser/layout.js +55 -0
- package/dist/src/ui/browser/layout.js.map +1 -0
- package/dist/src/ui/browser/shortcut-help.d.ts +10 -0
- package/dist/src/ui/browser/shortcut-help.js +124 -0
- package/dist/src/ui/browser/shortcut-help.js.map +1 -0
- package/dist/src/ui/browser/store.d.ts +59 -0
- package/dist/src/ui/browser/store.js +81 -0
- package/dist/src/ui/browser/store.js.map +1 -0
- package/dist/src/ui/browser/types.d.ts +134 -0
- package/dist/src/ui/browser/types.js +2 -0
- package/dist/src/ui/browser/types.js.map +1 -0
- package/dist/src/ui/collection-match.d.ts +7 -0
- package/dist/src/ui/collection-match.js +15 -0
- package/dist/src/ui/collection-match.js.map +1 -0
- package/dist/src/ui/components/colors.d.ts +7 -0
- package/dist/src/ui/components/colors.js +10 -0
- package/dist/src/ui/components/colors.js.map +1 -0
- package/dist/src/ui/components/confirm.d.ts +6 -0
- package/dist/src/ui/components/confirm.js +22 -0
- package/dist/src/ui/components/confirm.js.map +1 -0
- package/dist/src/ui/components/framed-panel.d.ts +21 -0
- package/dist/src/ui/components/framed-panel.js +66 -0
- package/dist/src/ui/components/framed-panel.js.map +1 -0
- package/dist/src/ui/components/link.d.ts +7 -0
- package/dist/src/ui/components/link.js +12 -0
- package/dist/src/ui/components/link.js.map +1 -0
- package/dist/src/ui/components/modal.d.ts +16 -0
- package/dist/src/ui/components/modal.js +58 -0
- package/dist/src/ui/components/modal.js.map +1 -0
- package/dist/src/ui/components/mouse/bounds.d.ts +13 -0
- package/dist/src/ui/components/mouse/bounds.js +29 -0
- package/dist/src/ui/components/mouse/bounds.js.map +1 -0
- package/dist/src/ui/components/mouse/clickable.d.ts +10 -0
- package/dist/src/ui/components/mouse/clickable.js +14 -0
- package/dist/src/ui/components/mouse/clickable.js.map +1 -0
- package/dist/src/ui/components/mouse/index.d.ts +4 -0
- package/dist/src/ui/components/mouse/index.js +5 -0
- package/dist/src/ui/components/mouse/index.js.map +1 -0
- package/dist/src/ui/components/mouse/parse.d.ts +13 -0
- package/dist/src/ui/components/mouse/parse.js +54 -0
- package/dist/src/ui/components/mouse/parse.js.map +1 -0
- package/dist/src/ui/components/mouse/provider.d.ts +31 -0
- package/dist/src/ui/components/mouse/provider.js +114 -0
- package/dist/src/ui/components/mouse/provider.js.map +1 -0
- package/dist/src/ui/components/multi-select.d.ts +9 -0
- package/dist/src/ui/components/multi-select.js +49 -0
- package/dist/src/ui/components/multi-select.js.map +1 -0
- package/dist/src/ui/components/options.d.ts +20 -0
- package/dist/src/ui/components/options.js +47 -0
- package/dist/src/ui/components/options.js.map +1 -0
- package/dist/src/ui/components/select.d.ts +9 -0
- package/dist/src/ui/components/select.js +47 -0
- package/dist/src/ui/components/select.js.map +1 -0
- package/dist/src/ui/components/tabs.d.ts +18 -0
- package/dist/src/ui/components/tabs.js +38 -0
- package/dist/src/ui/components/tabs.js.map +1 -0
- package/dist/src/ui/components/tag-editor.d.ts +8 -0
- package/dist/src/ui/components/tag-editor.js +56 -0
- package/dist/src/ui/components/tag-editor.js.map +1 -0
- package/dist/src/ui/components/termcn.d.ts +12 -0
- package/dist/src/ui/components/termcn.js +12 -0
- package/dist/src/ui/components/termcn.js.map +1 -0
- package/dist/src/ui/components/terminal-layout.d.ts +4 -0
- package/dist/src/ui/components/terminal-layout.js +43 -0
- package/dist/src/ui/components/terminal-layout.js.map +1 -0
- package/dist/src/ui/components/text-input.d.ts +10 -0
- package/dist/src/ui/components/text-input.js +78 -0
- package/dist/src/ui/components/text-input.js.map +1 -0
- package/dist/src/ui/components/text.d.ts +2 -0
- package/dist/src/ui/components/text.js +8 -0
- package/dist/src/ui/components/text.js.map +1 -0
- package/dist/src/ui/components/use-input.d.ts +12 -0
- package/dist/src/ui/components/use-input.js +21 -0
- package/dist/src/ui/components/use-input.js.map +1 -0
- package/dist/src/ui/footer/resolve-footer.d.ts +8 -0
- package/dist/src/ui/footer/resolve-footer.js +178 -0
- package/dist/src/ui/footer/resolve-footer.js.map +1 -0
- package/dist/src/ui/footer/types.d.ts +63 -0
- package/dist/src/ui/footer/types.js +2 -0
- package/dist/src/ui/footer/types.js.map +1 -0
- package/dist/src/ui/import/index.d.ts +7 -0
- package/dist/src/ui/import/index.js +7 -0
- package/dist/src/ui/import/index.js.map +1 -0
- package/dist/src/ui/import/review.d.ts +9 -0
- package/dist/src/ui/import/review.js +98 -0
- package/dist/src/ui/import/review.js.map +1 -0
- package/dist/src/ui/import/skill-select.d.ts +15 -0
- package/dist/src/ui/import/skill-select.js +219 -0
- package/dist/src/ui/import/skill-select.js.map +1 -0
- package/dist/src/ui/import/types.d.ts +13 -0
- package/dist/src/ui/import/types.js +2 -0
- package/dist/src/ui/import/types.js.map +1 -0
- package/dist/src/ui/install/index.d.ts +6 -0
- package/dist/src/ui/install/index.js +6 -0
- package/dist/src/ui/install/index.js.map +1 -0
- package/dist/src/ui/install/review.d.ts +10 -0
- package/dist/src/ui/install/review.js +134 -0
- package/dist/src/ui/install/review.js.map +1 -0
- package/dist/src/ui/install/types.d.ts +15 -0
- package/dist/src/ui/install/types.js +6 -0
- package/dist/src/ui/install/types.js.map +1 -0
- package/dist/src/ui/overlay/bridge.d.ts +29 -0
- package/dist/src/ui/overlay/bridge.js +34 -0
- package/dist/src/ui/overlay/bridge.js.map +1 -0
- package/dist/src/ui/overlay/dialogs.d.ts +6 -0
- package/dist/src/ui/overlay/dialogs.js +31 -0
- package/dist/src/ui/overlay/dialogs.js.map +1 -0
- package/dist/src/ui/overlay/host.d.ts +30 -0
- package/dist/src/ui/overlay/host.js +164 -0
- package/dist/src/ui/overlay/host.js.map +1 -0
- package/dist/src/ui/overlay/index.d.ts +11 -0
- package/dist/src/ui/overlay/index.js +11 -0
- package/dist/src/ui/overlay/index.js.map +1 -0
- package/dist/src/ui/overlay/slot.d.ts +20 -0
- package/dist/src/ui/overlay/slot.js +50 -0
- package/dist/src/ui/overlay/slot.js.map +1 -0
- package/dist/src/ui/overlay/static.d.ts +13 -0
- package/dist/src/ui/overlay/static.js +34 -0
- package/dist/src/ui/overlay/static.js.map +1 -0
- package/dist/src/ui/overlay/types.d.ts +57 -0
- package/dist/src/ui/overlay/types.js +2 -0
- package/dist/src/ui/overlay/types.js.map +1 -0
- package/dist/src/ui/prompts/index.d.ts +5 -0
- package/dist/src/ui/prompts/index.js +6 -0
- package/dist/src/ui/prompts/index.js.map +1 -0
- package/dist/src/ui/prompts/present.d.ts +29 -0
- package/dist/src/ui/prompts/present.js +71 -0
- package/dist/src/ui/prompts/present.js.map +1 -0
- package/dist/src/ui/search/index.d.ts +4 -0
- package/dist/src/ui/{search.js → search/index.js} +20 -8
- package/dist/src/ui/search/index.js.map +1 -0
- package/dist/src/ui/search/types.d.ts +9 -0
- package/dist/src/ui/search/types.js +2 -0
- package/dist/src/ui/search/types.js.map +1 -0
- package/dist/src/ui/shell/app-shell.d.ts +22 -0
- package/dist/src/ui/shell/app-shell.js +46 -0
- package/dist/src/ui/shell/app-shell.js.map +1 -0
- package/dist/src/ui/shell/footer.d.ts +7 -0
- package/dist/src/ui/shell/footer.js +38 -0
- package/dist/src/ui/shell/footer.js.map +1 -0
- package/dist/src/ui/shell/run.d.ts +41 -0
- package/dist/src/ui/shell/run.js +201 -0
- package/dist/src/ui/shell/run.js.map +1 -0
- package/dist/src/{contracts → ui/shell}/terminal.d.ts +1 -0
- package/dist/src/{contracts → ui/shell}/terminal.js +1 -0
- package/dist/src/ui/shell/terminal.js.map +1 -0
- package/dist/src/ui/skill-labels.d.ts +10 -0
- package/dist/src/ui/skill-labels.js +11 -0
- package/dist/src/ui/skill-labels.js.map +1 -0
- package/package.json +20 -17
- package/dist/src/commands/browser.d.ts +0 -3
- package/dist/src/commands/browser.js +0 -413
- package/dist/src/commands/browser.js.map +0 -1
- package/dist/src/contracts/browser.d.ts +0 -68
- package/dist/src/contracts/browser.js +0 -2
- package/dist/src/contracts/browser.js.map +0 -1
- package/dist/src/contracts/search.d.ts +0 -7
- package/dist/src/contracts/search.js +0 -2
- package/dist/src/contracts/search.js.map +0 -1
- package/dist/src/contracts/terminal.js.map +0 -1
- package/dist/src/ui/browser-state.d.ts +0 -11
- package/dist/src/ui/browser-state.js +0 -17
- package/dist/src/ui/browser-state.js.map +0 -1
- package/dist/src/ui/browser.d.ts +0 -32
- package/dist/src/ui/browser.js +0 -786
- package/dist/src/ui/browser.js.map +0 -1
- package/dist/src/ui/prompts.d.ts +0 -20
- package/dist/src/ui/prompts.js +0 -49
- package/dist/src/ui/prompts.js.map +0 -1
- package/dist/src/ui/reviews.d.ts +0 -47
- package/dist/src/ui/reviews.js +0 -390
- package/dist/src/ui/reviews.js.map +0 -1
- package/dist/src/ui/search.d.ts +0 -5
- package/dist/src/ui/search.js.map +0 -1
- package/dist/src/ui/session.d.ts +0 -11
- package/dist/src/ui/session.js +0 -104
- package/dist/src/ui/session.js.map +0 -1
- package/dist/src/ui/termcn.d.ts +0 -58
- package/dist/src/ui/termcn.js +0 -303
- package/dist/src/ui/termcn.js.map +0 -1
|
@@ -1,81 +1,13 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { commandList, interactiveList } from './browser.js';
|
|
6
|
-
import { commandAdd, commandImport, commandRemove } from './library.js';
|
|
7
|
-
import { commandSearch } from './search.js';
|
|
8
|
-
export { commandAdd, commandImport, commandList, commandRemove, commandSearch, interactiveList };
|
|
9
|
-
export async function commandUpdate(argv) {
|
|
10
|
-
const { values, positionals } = parseArgs({
|
|
11
|
-
args: argv,
|
|
12
|
-
allowPositionals: true,
|
|
13
|
-
options: {
|
|
14
|
-
all: { type: 'boolean' },
|
|
15
|
-
yes: { type: 'boolean', short: 'y' },
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
const updateable = (await listCollection()).filter((skill) => skill.source.type === 'git');
|
|
19
|
-
let selected;
|
|
20
|
-
if (positionals.length) {
|
|
21
|
-
selected = positionals.flatMap((name) => {
|
|
22
|
-
const skill = updateable.find((item) => item.name === name);
|
|
23
|
-
return skill ? [skill] : [];
|
|
24
|
-
});
|
|
25
|
-
const found = new Set(selected.map((skill) => skill.name));
|
|
26
|
-
const missing = positionals.filter((name) => !found.has(name));
|
|
27
|
-
if (missing.length)
|
|
28
|
-
throw new Error(`没有可更新的来源:${missing.join(', ')}`);
|
|
29
|
-
}
|
|
30
|
-
else if (values.all) {
|
|
31
|
-
selected = updateable;
|
|
32
|
-
}
|
|
33
|
-
else if (process.stdin.isTTY) {
|
|
34
|
-
selected = await chooseMany(updateable, '选择要更新的技能:');
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
throw new Error('请指定技能名称或使用 --all');
|
|
38
|
-
}
|
|
39
|
-
const results = [];
|
|
40
|
-
for (const skill of selected) {
|
|
41
|
-
try {
|
|
42
|
-
const allowDelete = values.yes ?? false;
|
|
43
|
-
results.push({
|
|
44
|
-
name: skill.name,
|
|
45
|
-
status: await updateGitSkill(skill, allowDelete, {
|
|
46
|
-
confirmDelete: async (links) => {
|
|
47
|
-
if (!process.stdin.isTTY) {
|
|
48
|
-
throw new Error(`上游已删除 ${skill.name};确认后使用 --yes`);
|
|
49
|
-
}
|
|
50
|
-
console.log(`上游已删除 ${skill.name},以下位置会受影响:`);
|
|
51
|
-
links.forEach((link) => console.log(`- ${link.path} (${link.kind})`));
|
|
52
|
-
return confirm('执行收藏夹移除流程吗?');
|
|
53
|
-
},
|
|
54
|
-
}),
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
results.push({ name: skill.name, status: 'error', error: errorMessage(error) });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
for (const result of results) {
|
|
62
|
-
console.log(`${result.name}: ${result.status}${result.error ? ` — ${result.error}` : ''}`);
|
|
63
|
-
if (result.status === 'conflict') {
|
|
64
|
-
const conflict = (await readState()).conflicts.find((item) => item.type === 'source' && item.skill === result.name);
|
|
65
|
-
if (conflict?.type === 'source') {
|
|
66
|
-
console.log(` 请在 ${conflict.path} 中手动解决并提交 Git 合并。`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (results.some((result) => result.status === 'error'))
|
|
71
|
-
process.exitCode = 1;
|
|
2
|
+
import { configureCollectionRemote, initCollectionGit, } from '../domain/git.js';
|
|
3
|
+
export async function commandAdd(argv) {
|
|
4
|
+
return (await import('./library.js')).commandAdd(argv);
|
|
72
5
|
}
|
|
73
|
-
export async function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await syncCollection(values.background ?? false);
|
|
6
|
+
export async function commandImport(argv) {
|
|
7
|
+
return (await import('./library.js')).commandImport(argv);
|
|
8
|
+
}
|
|
9
|
+
export async function commandSearch(argv) {
|
|
10
|
+
return (await import('./search.js')).commandSearch(argv);
|
|
79
11
|
}
|
|
80
12
|
export async function commandInit(argv = []) {
|
|
81
13
|
const { values } = parseArgs({
|
|
@@ -85,8 +17,14 @@ export async function commandInit(argv = []) {
|
|
|
85
17
|
const initialized = await initCollectionGit();
|
|
86
18
|
console.log(initialized ? '已初始化收藏夹 Git。' : '收藏夹 Git 已初始化。');
|
|
87
19
|
let remote = values.remote;
|
|
88
|
-
if (!remote && initialized && process.stdin.isTTY
|
|
89
|
-
|
|
20
|
+
if (!remote && initialized && process.stdin.isTTY) {
|
|
21
|
+
const [{ Modal }, { promptText }] = await Promise.all([
|
|
22
|
+
import('../ui/overlay/static.js'),
|
|
23
|
+
import('../ui/prompts/present.js'),
|
|
24
|
+
]);
|
|
25
|
+
if (await Modal.confirm({ title: '确认', message: '是否配置远程仓库?' })) {
|
|
26
|
+
remote = await promptText('远程仓库地址:');
|
|
27
|
+
}
|
|
90
28
|
}
|
|
91
29
|
if (remote) {
|
|
92
30
|
await configureCollectionRemote(remote);
|
|
@@ -96,14 +34,10 @@ export async function commandInit(argv = []) {
|
|
|
96
34
|
const COMMAND_HELP = {
|
|
97
35
|
search: `用法:
|
|
98
36
|
iskills search [关键词]
|
|
99
|
-
iskills search <关键词> --json
|
|
100
|
-
iskills search --collect <resultId> [--replace]
|
|
101
37
|
|
|
102
38
|
实时搜索 skills.sh,选择后保存到收藏夹。
|
|
103
39
|
|
|
104
40
|
选项:
|
|
105
|
-
--json 以 JSON 输出搜索结果
|
|
106
|
-
--collect <ID> 按搜索结果 ID 收藏,不依赖交互排名
|
|
107
41
|
--replace 替换异源同名收藏
|
|
108
42
|
-h, --help 显示帮助
|
|
109
43
|
`,
|
|
@@ -133,50 +67,6 @@ const COMMAND_HELP = {
|
|
|
133
67
|
--replace 替换收藏夹中的同名技能
|
|
134
68
|
-y, --yes 跳过确认
|
|
135
69
|
-h, --help 显示帮助
|
|
136
|
-
`,
|
|
137
|
-
list: `用法:
|
|
138
|
-
iskills list [关键词] [选项]
|
|
139
|
-
|
|
140
|
-
交互浏览当前项目、收藏夹和 Agent 全局技能;JSON 输出项目与收藏夹。
|
|
141
|
-
|
|
142
|
-
选项:
|
|
143
|
-
--json 以 JSON 格式输出
|
|
144
|
-
--note <文本> 编辑收藏夹技能的备注(需指定技能名)
|
|
145
|
-
--tags <标签> 编辑收藏夹技能的标签,逗号分隔(需指定技能名)
|
|
146
|
-
--source <类型> 绑定来源类型(需指定技能名和 --source-path)
|
|
147
|
-
--ref <引用> 绑定来源引用
|
|
148
|
-
--source-path <路径> 绑定来源路径
|
|
149
|
-
-h, --help 显示帮助
|
|
150
|
-
`,
|
|
151
|
-
remove: `用法:
|
|
152
|
-
iskills remove <技能> [选项]
|
|
153
|
-
|
|
154
|
-
从当前项目或收藏夹移除技能。
|
|
155
|
-
|
|
156
|
-
选项:
|
|
157
|
-
-g, --global 从收藏夹移除(还回原始位置)
|
|
158
|
-
--from <目录> 限定移除范围
|
|
159
|
-
-y, --yes 跳过确认
|
|
160
|
-
-h, --help 显示帮助
|
|
161
|
-
`,
|
|
162
|
-
update: `用法:
|
|
163
|
-
iskills update [技能...] [选项]
|
|
164
|
-
|
|
165
|
-
更新 Git 来源的技能。
|
|
166
|
-
|
|
167
|
-
选项:
|
|
168
|
-
--all 更新全部可更新的技能
|
|
169
|
-
-y, --yes 自动接受远端变更
|
|
170
|
-
-h, --help 显示帮助
|
|
171
|
-
`,
|
|
172
|
-
sync: `用法:
|
|
173
|
-
iskills sync [选项]
|
|
174
|
-
|
|
175
|
-
同步收藏夹 Git 仓库。
|
|
176
|
-
|
|
177
|
-
选项:
|
|
178
|
-
--background 后台异步同步
|
|
179
|
-
-h, --help 显示帮助
|
|
180
70
|
`,
|
|
181
71
|
init: `用法:
|
|
182
72
|
iskills init [选项]
|
|
@@ -194,6 +84,8 @@ export function printHelp(command) {
|
|
|
194
84
|
console.log(help);
|
|
195
85
|
return;
|
|
196
86
|
}
|
|
87
|
+
if (command)
|
|
88
|
+
throw new Error(`未知命令:${command}`);
|
|
197
89
|
console.log(`Skill 收藏夹
|
|
198
90
|
|
|
199
91
|
用法:
|
|
@@ -203,17 +95,12 @@ export function printHelp(command) {
|
|
|
203
95
|
search [关键词] 搜索技能并保存到收藏夹
|
|
204
96
|
add [技能...] 从收藏夹添加到当前项目
|
|
205
97
|
import [来源] 导入本地路径或 Git 来源
|
|
206
|
-
list [关键词] 浏览当前项目、收藏夹和全局技能
|
|
207
|
-
remove <技能> 从当前项目或收藏夹移除
|
|
208
|
-
update [技能...] 更新 Git 来源技能
|
|
209
98
|
init 初始化收藏夹 Git
|
|
210
|
-
sync 同步收藏夹 Git
|
|
211
99
|
|
|
212
100
|
选项:
|
|
213
101
|
-h, --help 显示帮助(可用 iskills help <命令>)
|
|
214
102
|
-v, --version 显示版本
|
|
215
103
|
|
|
216
|
-
不带命令时打开交互式浏览界面。
|
|
217
104
|
`);
|
|
218
105
|
}
|
|
219
106
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAc;IAC7C,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAc;IAChD,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAc;IAChD,OAAO,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAI,GAAa,EAAE;IACnD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;QAC3B,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;KACxC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,MAAM,iBAAiB,EAAE,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;IAC5D,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,MAAM,IAAI,WAAW,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAClD,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACpD,MAAM,CAAC,yBAAyB,CAAC;YACjC,MAAM,CAAC,0BAA0B,CAAC;SACnC,CAAC,CAAC;QACH,IAAI,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;YAC/D,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,yBAAyB,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAA2B;IAC3C,MAAM,EAAE;;;;;;;;CAQT;IACC,GAAG,EAAE;;;;;;;;;;;;;CAaN;IACC,MAAM,EAAE;;;;;;;;;;;;CAYT;IACC,IAAI,EAAE;;;;;;;;CAQP;CACA,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,OAAgB;IACxC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzD,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,OAAO;IACT,CAAC;IACD,IAAI,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;CAeb,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -40,5 +40,4 @@ export declare function addSkillsToProject(skills: CollectedSkill[], values?: Ad
|
|
|
40
40
|
targetCount: number;
|
|
41
41
|
}>;
|
|
42
42
|
export declare function commandAdd(argv: string[]): Promise<void>;
|
|
43
|
-
export declare function commandRemove(argv: string[]): Promise<void>;
|
|
44
43
|
export {};
|
|
@@ -2,17 +2,20 @@ import { cp, lstat, mkdir, mkdtemp, realpath, rm, symlink } from 'node:fs/promis
|
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import { AGENTS, PROJECT_SKILL_DIRS, assertRelativePath, assertSkillName, baselinePath, collectionPaths, commitCollection, discoverSkills, ensureCollection,
|
|
5
|
+
import { AGENTS, PROJECT_SKILL_DIRS, assertRelativePath, assertSkillName, baselinePath, classifyCollectionMatch, collectionPaths, commitCollection, discoverSkills, ensureCollection, exists, isExactSymlink, isGitSource, listCollection, moveDirectory, pathPresent, provenanceFromKnownLocks, readMetadata, sameGitIdentity, sanitizeTerminal, validateSkillTree, writeMetadata, } from '../domain/core.js';
|
|
6
|
+
import { registerCollectionLinks, replaceCollectionSkill, } from '../domain/collection-write.js';
|
|
7
|
+
import { matchesSkill } from '../domain/skill-query.js';
|
|
6
8
|
import { cloneGitSource } from '../domain/git.js';
|
|
7
|
-
import {
|
|
9
|
+
import { collectionMatchLabels } from '../ui/collection-match.js';
|
|
10
|
+
function present() {
|
|
11
|
+
return import('../ui/prompts/present.js');
|
|
12
|
+
}
|
|
8
13
|
function gitSkillDisplayPath(skill, gitContext) {
|
|
9
14
|
const sourcePath = assertRelativePath(relative(gitContext.repository, skill.path).split(sep).join('/'));
|
|
10
15
|
const ref = gitContext.source.ref ? `#${gitContext.source.ref}` : '';
|
|
11
|
-
const status = skill.collectionStatus
|
|
12
|
-
?
|
|
13
|
-
:
|
|
14
|
-
? ' · 已收藏同名技能'
|
|
15
|
-
: '';
|
|
16
|
+
const status = skill.collectionStatus
|
|
17
|
+
? ` · ${collectionMatchLabels[skill.collectionStatus]}`
|
|
18
|
+
: '';
|
|
16
19
|
return `${sanitizeTerminal(gitContext.source.url)}${sanitizeTerminal(ref)} · ${sanitizeTerminal(sourcePath)}${status}`;
|
|
17
20
|
}
|
|
18
21
|
function gitSkillMetadata(skill, gitContext, tags = []) {
|
|
@@ -34,116 +37,8 @@ function annotateGitCollectionStatus(skills, gitContext, collection) {
|
|
|
34
37
|
return skill;
|
|
35
38
|
return {
|
|
36
39
|
...skill,
|
|
37
|
-
collectionStatus:
|
|
38
|
-
? 'same-source'
|
|
39
|
-
: 'same-name',
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async function replaceCollectionSkill(input) {
|
|
44
|
-
const paths = collectionPaths();
|
|
45
|
-
const target = join(paths.skills, input.name);
|
|
46
|
-
const metadata = metadataPath(input.name);
|
|
47
|
-
const baseline = baselinePath(input.name);
|
|
48
|
-
const transaction = await mkdtemp(join(paths.local, `.replace-${input.name}-`));
|
|
49
|
-
const oldTree = join(transaction, 'old-tree');
|
|
50
|
-
const oldMetadata = join(transaction, 'old-metadata.json');
|
|
51
|
-
const oldBaseline = join(transaction, 'old-baseline');
|
|
52
|
-
const newSource = join(transaction, 'new-source');
|
|
53
|
-
const state = await readState();
|
|
54
|
-
const links = state.links.filter((link) => link.skill === input.name);
|
|
55
|
-
const origin = links.find((link) => link.kind === 'origin');
|
|
56
|
-
const hadMetadata = await pathPresent(metadata);
|
|
57
|
-
const hadBaseline = await pathPresent(baseline);
|
|
58
|
-
let sourceMoved = false;
|
|
59
|
-
if (origin && !(await isExactSymlink(origin.path, target))) {
|
|
60
|
-
await rm(transaction, { recursive: true, force: true });
|
|
61
|
-
throw new Error(`原始位置已不是指向收藏夹的软链,已中止:${origin.path}`);
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
await cp(target, oldTree, { recursive: true, errorOnExist: true });
|
|
65
|
-
if (hadMetadata)
|
|
66
|
-
await cp(metadata, oldMetadata, { errorOnExist: true });
|
|
67
|
-
if (hadBaseline)
|
|
68
|
-
await cp(baseline, oldBaseline, { recursive: true, errorOnExist: true });
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
await rm(transaction, { recursive: true, force: true });
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
if (input.local) {
|
|
76
|
-
await moveDirectory(input.local.source, newSource);
|
|
77
|
-
sourceMoved = true;
|
|
78
|
-
}
|
|
79
|
-
if (origin) {
|
|
80
|
-
await rm(origin.path);
|
|
81
|
-
await cp(oldTree, origin.path, { recursive: true, errorOnExist: true });
|
|
82
|
-
}
|
|
83
|
-
await rm(target, { recursive: true, force: true });
|
|
84
|
-
await moveDirectory(input.staged, target);
|
|
85
|
-
if (input.local)
|
|
86
|
-
await symlink(target, input.local.source, 'dir');
|
|
87
|
-
await writeMetadata(input.metadata);
|
|
88
|
-
await rm(baseline, { recursive: true, force: true });
|
|
89
|
-
if (input.metadata.source.type === 'git' && !input.metadata.source.commit) {
|
|
90
|
-
await cp(target, baseline, { recursive: true });
|
|
91
|
-
}
|
|
92
|
-
const nextState = {
|
|
93
|
-
links: state.links.filter((link) => link.skill !== input.name || link.kind === 'usage'),
|
|
94
|
-
conflicts: state.conflicts.filter((conflict) => conflict.type !== 'source' || conflict.skill !== input.name),
|
|
40
|
+
collectionStatus: classifyCollectionMatch(sameName, gitSkillMetadata(skill, gitContext)),
|
|
95
41
|
};
|
|
96
|
-
if (input.local) {
|
|
97
|
-
nextState.links.push({ skill: input.name, path: input.local.source, kind: 'origin' });
|
|
98
|
-
if (input.local.selectedWasSymlink) {
|
|
99
|
-
nextState.links.push({
|
|
100
|
-
skill: input.name,
|
|
101
|
-
path: input.local.selectedPath,
|
|
102
|
-
kind: 'dependent',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
await writeState(nextState);
|
|
107
|
-
await commitCollection(`import ${input.name}`, true);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
try {
|
|
111
|
-
if (input.local && sourceMoved) {
|
|
112
|
-
await rm(input.local.source, { recursive: true, force: true });
|
|
113
|
-
await moveDirectory(newSource, input.local.source);
|
|
114
|
-
}
|
|
115
|
-
await rm(target, { recursive: true, force: true });
|
|
116
|
-
await cp(oldTree, target, { recursive: true, errorOnExist: true });
|
|
117
|
-
if (hadMetadata)
|
|
118
|
-
await cp(oldMetadata, metadata, { force: true });
|
|
119
|
-
else
|
|
120
|
-
await rm(metadata, { force: true });
|
|
121
|
-
await rm(baseline, { recursive: true, force: true });
|
|
122
|
-
if (hadBaseline)
|
|
123
|
-
await cp(oldBaseline, baseline, { recursive: true });
|
|
124
|
-
await writeState(state);
|
|
125
|
-
if (origin) {
|
|
126
|
-
await rm(origin.path, { recursive: true, force: true });
|
|
127
|
-
await mkdir(resolve(origin.path, '..'), { recursive: true });
|
|
128
|
-
await symlink(target, origin.path, 'dir');
|
|
129
|
-
}
|
|
130
|
-
await commitCollection(`rollback import ${input.name}`);
|
|
131
|
-
}
|
|
132
|
-
catch (rollbackError) {
|
|
133
|
-
throw new Error(`导入失败:${errorMessage(error)};回滚失败:${errorMessage(rollbackError)}`);
|
|
134
|
-
}
|
|
135
|
-
await rm(transaction, { recursive: true, force: true }).catch(() => { });
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
for (const conflict of state.conflicts) {
|
|
139
|
-
if (conflict.type === 'source' && conflict.skill === input.name) {
|
|
140
|
-
await rm(conflict.path, { recursive: true, force: true }).catch((error) => {
|
|
141
|
-
console.error(`警告:旧冲突目录清理失败:${errorMessage(error)}`);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
await rm(transaction, { recursive: true, force: true }).catch((error) => {
|
|
146
|
-
console.error(`警告:替换备份清理失败:${errorMessage(error)}`);
|
|
147
42
|
});
|
|
148
43
|
}
|
|
149
44
|
async function importLocalSkill(skill, allowReplace, tags = []) {
|
|
@@ -208,12 +103,11 @@ async function importLocalSkill(skill, allowReplace, tags = []) {
|
|
|
208
103
|
await rm(baseline, { recursive: true, force: true });
|
|
209
104
|
await cp(target, baseline, { recursive: true });
|
|
210
105
|
}
|
|
211
|
-
const
|
|
212
|
-
state.links.push({ skill: skill.name, path: source, kind: 'origin' });
|
|
106
|
+
const links = [{ skill: skill.name, path: source, kind: 'origin' }];
|
|
213
107
|
if (selectedStats.isSymbolicLink()) {
|
|
214
|
-
|
|
108
|
+
links.push({ skill: skill.name, path: selectedPath, kind: 'dependent' });
|
|
215
109
|
}
|
|
216
|
-
await
|
|
110
|
+
await registerCollectionLinks(links);
|
|
217
111
|
return true;
|
|
218
112
|
}
|
|
219
113
|
async function importRemoteSkill(skill, gitContext, allowReplace, tags = []) {
|
|
@@ -301,7 +195,10 @@ export async function importSkillsToCollection(skills, options = {}) {
|
|
|
301
195
|
}
|
|
302
196
|
allowReplace = options.confirmReplace
|
|
303
197
|
? await options.confirmReplace(conflicts)
|
|
304
|
-
: await
|
|
198
|
+
: await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
199
|
+
title: '确认',
|
|
200
|
+
message: `替换同名收藏 ${conflicts.join(', ')} 吗?`,
|
|
201
|
+
});
|
|
305
202
|
if (!allowReplace) {
|
|
306
203
|
selected = selected.filter((skill) => !conflicts.includes(skill.name));
|
|
307
204
|
}
|
|
@@ -355,23 +252,6 @@ export async function globalSkillGroups(names = []) {
|
|
|
355
252
|
}
|
|
356
253
|
return groups.sort((a, b) => a.agent.localeCompare(b.agent));
|
|
357
254
|
}
|
|
358
|
-
async function collectionNoteLookup(groups) {
|
|
359
|
-
const collection = await listCollection().catch(() => []);
|
|
360
|
-
const noteByPath = new Map(collection.filter((skill) => skill.note).map((skill) => [skill.path, skill.note]));
|
|
361
|
-
const realpathBySkillPath = new Map();
|
|
362
|
-
await Promise.all(groups.flatMap((group) => group.skills.map(async (skill) => {
|
|
363
|
-
try {
|
|
364
|
-
realpathBySkillPath.set(skill.path, await realpath(skill.path));
|
|
365
|
-
}
|
|
366
|
-
catch {
|
|
367
|
-
// Ignore unresolved links; their notes cannot be matched safely.
|
|
368
|
-
}
|
|
369
|
-
})));
|
|
370
|
-
return (skill) => {
|
|
371
|
-
const path = realpathBySkillPath.get(skill.path);
|
|
372
|
-
return path ? noteByPath.get(path) : undefined;
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
255
|
export async function commandImport(argv) {
|
|
376
256
|
const { values, positionals } = parseArgs({
|
|
377
257
|
args: argv,
|
|
@@ -423,11 +303,11 @@ export async function commandImport(argv) {
|
|
|
423
303
|
if (!process.stdin.isTTY)
|
|
424
304
|
throw new Error('请使用 --all 或交互选择要导入的技能');
|
|
425
305
|
const groups = globalGroups ?? [{ agent: gitContext ? 'Git' : '本地', skills }];
|
|
426
|
-
selected = await
|
|
306
|
+
selected = await (await present()).promptSkillGroups(groups, globalGroups
|
|
427
307
|
? '扫描全局 Skill 目录'
|
|
428
308
|
: !input
|
|
429
309
|
? '选择当前仓库技能'
|
|
430
|
-
: '发现以下技能'
|
|
310
|
+
: '发现以下技能');
|
|
431
311
|
}
|
|
432
312
|
if (!selected.length)
|
|
433
313
|
return;
|
|
@@ -438,7 +318,7 @@ export async function commandImport(argv) {
|
|
|
438
318
|
const existingTags = [...new Set((await listCollection().catch(() => []))
|
|
439
319
|
.flatMap((skill) => skill.tags))]
|
|
440
320
|
.sort((a, b) => a.localeCompare(b));
|
|
441
|
-
const review = await
|
|
321
|
+
const review = await (await present()).promptImportReview(selected.map((skill) => ({
|
|
442
322
|
skill,
|
|
443
323
|
detail: gitContext
|
|
444
324
|
? gitSkillDisplayPath(skill, gitContext)
|
|
@@ -468,7 +348,10 @@ export async function commandImport(argv) {
|
|
|
468
348
|
if (!process.stdin.isTTY) {
|
|
469
349
|
throw new Error(`收藏夹已存在:${conflicts.join(', ')};确认后使用 --replace`);
|
|
470
350
|
}
|
|
471
|
-
allowReplace = await
|
|
351
|
+
allowReplace = await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
352
|
+
title: '确认',
|
|
353
|
+
message: `替换同名收藏 ${conflicts.join(', ')} 吗?`,
|
|
354
|
+
});
|
|
472
355
|
if (!allowReplace)
|
|
473
356
|
selected = selected.filter((skill) => !conflicts.includes(skill.name));
|
|
474
357
|
}
|
|
@@ -494,7 +377,7 @@ async function resolveTargets(values) {
|
|
|
494
377
|
if (!names.length) {
|
|
495
378
|
if (!process.stdin.isTTY)
|
|
496
379
|
throw new Error('添加到全局目录时请指定 --agent');
|
|
497
|
-
names = await
|
|
380
|
+
names = await (await present()).promptChoicesMany(Object.keys(AGENTS).map((name) => ({ label: name, value: name })), '选择全局 Agent 目录:');
|
|
498
381
|
}
|
|
499
382
|
return [
|
|
500
383
|
...new Set(names.map((name) => {
|
|
@@ -528,7 +411,7 @@ async function resolveTargets(values) {
|
|
|
528
411
|
return unique.length ? unique : [resolve('.agents/skills')];
|
|
529
412
|
if (!process.stdin.isTTY)
|
|
530
413
|
return [resolve('.agents/skills')];
|
|
531
|
-
return
|
|
414
|
+
return (await present()).promptChoicesMany(unique.map((path) => ({ label: relative(process.cwd(), path), value: path })), '检测到多个 Agent 目录:');
|
|
532
415
|
}
|
|
533
416
|
async function selectCollectionSkills(names) {
|
|
534
417
|
const skills = await listCollection();
|
|
@@ -547,22 +430,24 @@ async function selectCollectionSkills(names) {
|
|
|
547
430
|
throw new Error('请指定技能名称');
|
|
548
431
|
if (!skills.length) {
|
|
549
432
|
let source;
|
|
550
|
-
|
|
433
|
+
const ui = await present();
|
|
434
|
+
source = await ui.promptChoice([
|
|
551
435
|
{ label: '扫描当前目录', value: 'current' },
|
|
552
436
|
{ label: '扫描常见全局 Agent 目录', value: 'global' },
|
|
553
437
|
{ label: '输入本地路径或 Git 来源', value: 'custom' },
|
|
554
438
|
], '收藏夹还是空的,先从哪里导入技能?');
|
|
555
439
|
if (source === 'custom')
|
|
556
|
-
source = await
|
|
440
|
+
source = await ui.promptText('路径或 Git 来源:');
|
|
557
441
|
if (!source)
|
|
558
442
|
return [];
|
|
559
443
|
await commandImport(source === 'global' ? ['-g'] : source === 'current' ? [] : [source]);
|
|
560
444
|
return listCollection();
|
|
561
445
|
}
|
|
562
|
-
const
|
|
446
|
+
const ui = await present();
|
|
447
|
+
const query = await ui.promptText('搜索收藏夹:');
|
|
563
448
|
if (query === undefined)
|
|
564
449
|
return [];
|
|
565
|
-
return
|
|
450
|
+
return ui.promptSkills(skills.filter((skill) => matchesSkill(skill, query)), '选择技能:');
|
|
566
451
|
}
|
|
567
452
|
export async function addSkillsToProject(skills, values = {}) {
|
|
568
453
|
if (!skills.length)
|
|
@@ -571,9 +456,9 @@ export async function addSkillsToProject(skills, values = {}) {
|
|
|
571
456
|
if (!targetRoots.length)
|
|
572
457
|
return { count: 0, targetCount: 0 };
|
|
573
458
|
await Promise.all(targetRoots.map((targetRoot) => mkdir(targetRoot, { recursive: true })));
|
|
574
|
-
const state = await readState();
|
|
575
459
|
const addedSkills = new Set();
|
|
576
460
|
const addedTargets = new Set();
|
|
461
|
+
const usageLinks = [];
|
|
577
462
|
for (const targetRoot of targetRoots) {
|
|
578
463
|
for (const skill of skills) {
|
|
579
464
|
const target = join(targetRoot, skill.name);
|
|
@@ -587,7 +472,10 @@ export async function addSkillsToProject(skills, values = {}) {
|
|
|
587
472
|
if (!replace && process.stdin.isTTY && !values.yes) {
|
|
588
473
|
replace = values.confirmReplace
|
|
589
474
|
? await values.confirmReplace(target)
|
|
590
|
-
: await confirm(
|
|
475
|
+
: await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
476
|
+
title: '确认',
|
|
477
|
+
message: `目标已存在,替换 ${target} 吗?`,
|
|
478
|
+
});
|
|
591
479
|
}
|
|
592
480
|
if (!replace) {
|
|
593
481
|
if (process.stdin.isTTY && !values.yes)
|
|
@@ -601,13 +489,13 @@ export async function addSkillsToProject(skills, values = {}) {
|
|
|
601
489
|
}
|
|
602
490
|
else {
|
|
603
491
|
await symlink(skill.path, target, 'dir');
|
|
604
|
-
|
|
492
|
+
usageLinks.push({ skill: skill.name, path: target, kind: 'usage' });
|
|
605
493
|
}
|
|
606
494
|
addedSkills.add(skill.name);
|
|
607
495
|
addedTargets.add(targetRoot);
|
|
608
496
|
}
|
|
609
497
|
}
|
|
610
|
-
await
|
|
498
|
+
await registerCollectionLinks(usageLinks);
|
|
611
499
|
if (!values.quiet) {
|
|
612
500
|
console.log(`已添加 ${addedSkills.size} 个技能到 ${addedTargets.size} 个目录${values.copy ? '(复制)' : ''}。`);
|
|
613
501
|
}
|
|
@@ -644,68 +532,4 @@ export async function commandAdd(argv) {
|
|
|
644
532
|
options.yes = values.yes;
|
|
645
533
|
await addSkillsToProject(skills, options);
|
|
646
534
|
}
|
|
647
|
-
async function removeUsage(name, from) {
|
|
648
|
-
const state = await readState();
|
|
649
|
-
const collectionTarget = join(collectionPaths().skills, assertSkillName(name));
|
|
650
|
-
const scope = resolve(from || process.cwd());
|
|
651
|
-
const candidates = state.links.filter((link) => link.skill === name &&
|
|
652
|
-
link.kind !== 'origin' &&
|
|
653
|
-
(resolve(link.path) === scope || resolve(link.path).startsWith(`${scope}${sep}`)));
|
|
654
|
-
if (!candidates.length)
|
|
655
|
-
throw new Error(`当前范围没有使用技能:${name}`);
|
|
656
|
-
for (const link of candidates) {
|
|
657
|
-
if (!(await isExactSymlink(link.path, collectionTarget))) {
|
|
658
|
-
throw new Error(`使用位置已不是预期软链,未删除:${link.path}`);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
for (const link of candidates)
|
|
662
|
-
await rm(link.path);
|
|
663
|
-
const removed = new Set(candidates.map((link) => resolve(link.path)));
|
|
664
|
-
state.links = state.links.filter((link) => !removed.has(resolve(link.path)));
|
|
665
|
-
await writeState(state);
|
|
666
|
-
console.log(`已从 ${candidates.length} 个位置移除 ${name},收藏夹内容保留。`);
|
|
667
|
-
}
|
|
668
|
-
async function selectOneCollectionSkill(name) {
|
|
669
|
-
if (name)
|
|
670
|
-
return name;
|
|
671
|
-
if (!process.stdin.isTTY)
|
|
672
|
-
throw new Error('请指定技能名称');
|
|
673
|
-
const skills = await listCollection();
|
|
674
|
-
return chooseOne(skills.map((skill) => ({ label: skill.name, value: skill.name })), '选择技能:');
|
|
675
|
-
}
|
|
676
|
-
export async function commandRemove(argv) {
|
|
677
|
-
const { values, positionals } = parseArgs({
|
|
678
|
-
args: argv,
|
|
679
|
-
allowPositionals: true,
|
|
680
|
-
options: {
|
|
681
|
-
global: { type: 'boolean', short: 'g' },
|
|
682
|
-
from: { type: 'string' },
|
|
683
|
-
yes: { type: 'boolean', short: 'y' },
|
|
684
|
-
},
|
|
685
|
-
});
|
|
686
|
-
if (positionals.length > 1)
|
|
687
|
-
throw new Error('一次只能移除一个技能');
|
|
688
|
-
const name = await selectOneCollectionSkill(positionals[0]);
|
|
689
|
-
if (!name)
|
|
690
|
-
return;
|
|
691
|
-
if (values.global) {
|
|
692
|
-
if (!values.yes) {
|
|
693
|
-
if (!process.stdin.isTTY)
|
|
694
|
-
throw new Error('从收藏夹移除需要使用 --yes 确认');
|
|
695
|
-
const state = await readState();
|
|
696
|
-
const links = state.links.filter((link) => link.skill === name);
|
|
697
|
-
console.log('该技能关联以下位置:');
|
|
698
|
-
links.forEach((link) => {
|
|
699
|
-
const kind = link.kind === 'origin' ? '原始' : link.kind === 'usage' ? '使用' : '依赖';
|
|
700
|
-
console.log(`- ${link.path}(${kind})`);
|
|
701
|
-
});
|
|
702
|
-
if (!(await confirm('从收藏夹移除吗?')))
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
await removeFromCollection(name, true);
|
|
706
|
-
}
|
|
707
|
-
else {
|
|
708
|
-
await removeUsage(name, values.from);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
535
|
//# sourceMappingURL=library.js.map
|