@namewta/skills-hub 0.1.16 → 0.1.17
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 +1 -1
- package/cli.mjs +6 -4
- package/install.mjs +11 -1
- package/package.json +1 -1
- package/tree-select.mjs +111 -74
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ node /path/to/skills-hub/install.mjs install --skill system-herdr-core
|
|
|
29
29
|
npx @namewta/skills-hub install --domain upstream-skills --dry-run
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
交互界面默认勾选当前项目已安装的技能。使用 ↑/↓ 移动、Tab 展开或收拢领域、空格勾选、←/→ 翻页,按 Enter 查看安装确认。按 `/` 可搜索名称、分组或中文用途。非交互环境使用带 `--domain`、`--skill` 或 `--all` 的安装命令。
|
|
33
33
|
|
|
34
34
|
技能安装到当前项目的 `.agents/skills/<技能名>/`。重复安装时,相同内容保持不变,有差异的同名技能先备份再替换。安装器只复制文件,不执行技能中的工具;技能是否自动加载由所用 Agent 决定,也可以直接读取对应的 `SKILL.md`。
|
|
35
35
|
|
package/cli.mjs
CHANGED
|
@@ -24,9 +24,11 @@ export async function interactive({ argv = [], project = process.cwd(), ui = pro
|
|
|
24
24
|
try {
|
|
25
25
|
ui.intro(pc.cyan('skills-hub · 按需安装中文技能'));
|
|
26
26
|
ui.note(project, '目标项目(技能写入 .agents/skills/)');
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
27
|
+
const installer = createInstaller();
|
|
28
|
+
const skills = installer.catalog();
|
|
29
|
+
const initialNames = installer.installedNames(skills, project);
|
|
30
|
+
if (initialNames.length) ui.note(`已预选 ${initialNames.length} 个已安装技能。`, '当前项目');
|
|
31
|
+
const names = await ask(choose({ skills, initialNames }));
|
|
30
32
|
const selected = select(skills, [], names);
|
|
31
33
|
if (!selected.length) throw new Error('请至少勾选一个技能。');
|
|
32
34
|
ui.note(formatSummary(selected.map(skill => skill.name)), `${selected.length} 个技能`);
|
|
@@ -34,7 +36,7 @@ export async function interactive({ argv = [], project = process.cwd(), ui = pro
|
|
|
34
36
|
ui.note('将补齐所选领域的持久化目录和简短 AGENTS.md;固定模板自动更新,业务记录保留,预览不写入。', '领域初始化');
|
|
35
37
|
}
|
|
36
38
|
const dryRun = argv.includes('--dry-run');
|
|
37
|
-
if (!await ask(ui.confirm({ message: dryRun ? '检查安装计划?(不写入文件)' : '
|
|
39
|
+
if (!await ask(ui.confirm({ message: dryRun ? '检查安装计划?(不写入文件)' : '安装或更新以上技能?(有差异的现有技能会先备份)', initialValue: true }))) {
|
|
38
40
|
ui.cancel('已取消,未修改文件。'); return 0;
|
|
39
41
|
}
|
|
40
42
|
const command = ['install', '--skill', ...selected.map(skill => skill.name)];
|
package/install.mjs
CHANGED
|
@@ -132,6 +132,16 @@ export function createInstaller({ repository = repositoryRoot, fsOps = fs } = {}
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
function installedNames(skills, project) {
|
|
136
|
+
const agents = path.join(project, '.agents');
|
|
137
|
+
const target = path.join(agents, 'skills');
|
|
138
|
+
if (!exists(agents)?.isDirectory() || !exists(target)?.isDirectory()) return [];
|
|
139
|
+
return skills.filter(({ name }) => {
|
|
140
|
+
const directory = path.join(target, name);
|
|
141
|
+
return exists(directory)?.isDirectory() && exists(path.join(directory, 'SKILL.md'))?.isFile();
|
|
142
|
+
}).map(({ name }) => name);
|
|
143
|
+
}
|
|
144
|
+
|
|
135
145
|
function plan(skills, project, replace = true) {
|
|
136
146
|
const actualProject = fsOps.realpathSync(project);
|
|
137
147
|
for (const source of [skillRoot, upstreamRoot, licenseRoot]) {
|
|
@@ -236,7 +246,7 @@ export function createInstaller({ repository = repositoryRoot, fsOps = fs } = {}
|
|
|
236
246
|
for (const lock of locks.reverse()) fsOps.rmdirSync(lock);
|
|
237
247
|
}
|
|
238
248
|
}
|
|
239
|
-
return { catalog, plan, apply, persistencePlan };
|
|
249
|
+
return { catalog, installedNames, plan, apply, persistencePlan };
|
|
240
250
|
}
|
|
241
251
|
|
|
242
252
|
export function catalog(repository = repositoryRoot) { return createInstaller({ repository }).catalog(); }
|
package/package.json
CHANGED
package/tree-select.mjs
CHANGED
|
@@ -18,8 +18,9 @@ export function matchesSkillSearch(search, option) {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function createSkillTree(skills) {
|
|
22
|
-
const
|
|
21
|
+
export function createSkillTree(skills, initialNames = []) {
|
|
22
|
+
const installed = new Set(initialNames);
|
|
23
|
+
const selected = new Set(skills.filter(skill => installed.has(skill.name)).map(skill => skill.name));
|
|
23
24
|
const root = { value: '@all', label: '全部技能', depth: 0, names: skills.map(skill => skill.name) };
|
|
24
25
|
const nodes = [root];
|
|
25
26
|
for (const domain of [...new Set(skills.map(skill => skill.domain))]) {
|
|
@@ -55,63 +56,81 @@ export function createSkillTree(skills) {
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
59
|
+
const maxPageSize = 20;
|
|
60
|
+
const frameOverhead = 5;
|
|
61
|
+
|
|
62
|
+
export function createTreePager(tree, pageSize = maxPageSize) {
|
|
63
|
+
const [root] = tree.nodes;
|
|
64
|
+
const domains = tree.nodes.filter(node => node.depth === 1);
|
|
65
|
+
let query = '', size = Math.max(1, pageSize), page = 0, focus = root.value, expanded;
|
|
66
|
+
const matchingDomains = () => domains.filter(node => tree.matches(query, node));
|
|
67
|
+
const matchingChildren = () => expanded
|
|
68
|
+
? tree.nodes.filter(node => node.domain === expanded && tree.matches(query, node)) : [];
|
|
72
69
|
function view() {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
const rows =
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
const groups = matchingDomains();
|
|
71
|
+
const matching = matchingChildren();
|
|
72
|
+
const children = matching.slice(page * size, (page + 1) * size);
|
|
73
|
+
const rows = groups.length ? [root, ...groups.flatMap(domain =>
|
|
74
|
+
domain.value === expanded ? [domain, ...children] : [domain])] : [];
|
|
75
|
+
const cursor = rows.findIndex(node => node.value === focus);
|
|
76
|
+
return { rows, cursor, page, totalPages: Math.ceil(matching.length / size), query,
|
|
77
|
+
pageSize: size, expanded, groups, children };
|
|
78
|
+
}
|
|
79
|
+
function clearSearch() {
|
|
80
|
+
query = '';
|
|
81
|
+
page = 0;
|
|
82
|
+
focus = root.value;
|
|
83
|
+
expanded = undefined;
|
|
79
84
|
}
|
|
80
85
|
return {
|
|
81
86
|
view,
|
|
87
|
+
clearSearch,
|
|
82
88
|
search(value) {
|
|
83
89
|
if (value === query) return;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
if (!value.trim()) {
|
|
91
|
+
clearSearch();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
query = value;
|
|
95
|
+
page = 0;
|
|
96
|
+
focus = root.value;
|
|
97
|
+
const domain = matchingDomains()[0];
|
|
98
|
+
expanded = domain?.value;
|
|
99
|
+
if (domain && !matchesSkillSearch(query, root)) {
|
|
100
|
+
focus = matchesSkillSearch(query, domain) ? domain.value : matchingChildren()[0]?.value ?? domain.value;
|
|
89
101
|
}
|
|
90
102
|
},
|
|
91
103
|
resize(value) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const target = all.findIndex(item => item.children.some(node => node.value === focused)
|
|
98
|
-
|| ((focused === '@all' || focused === before.domain?.value) && item.domain.value === before.domain?.value));
|
|
99
|
-
if (target !== -1) page = target;
|
|
100
|
-
const current = view();
|
|
101
|
-
const index = current.rows.findIndex(node => node.value === focused);
|
|
102
|
-
if (index !== -1) cursor = index;
|
|
104
|
+
const nextSize = Math.max(1, value);
|
|
105
|
+
if (size === nextSize) return;
|
|
106
|
+
const index = matchingChildren().findIndex(node => node.value === focus);
|
|
107
|
+
page = Math.floor((index === -1 ? page * size : index) / nextSize);
|
|
108
|
+
size = nextSize;
|
|
103
109
|
},
|
|
104
110
|
move(direction) {
|
|
105
111
|
const current = view();
|
|
106
|
-
|
|
112
|
+
const index = Math.max(0, Math.min(current.cursor + direction, current.rows.length - 1));
|
|
113
|
+
focus = current.rows[index]?.value ?? focus;
|
|
107
114
|
},
|
|
108
115
|
turn(direction) {
|
|
116
|
+
const { totalPages } = view();
|
|
117
|
+
const next = Math.max(0, Math.min(page + direction, totalPages - 1));
|
|
118
|
+
if (next === page) return;
|
|
119
|
+
page = next;
|
|
120
|
+
focus = view().children[0].value;
|
|
121
|
+
},
|
|
122
|
+
toggleExpanded() {
|
|
109
123
|
const current = view();
|
|
110
|
-
const
|
|
111
|
-
|
|
124
|
+
const node = current.rows[current.cursor];
|
|
125
|
+
const domain = node?.depth === 1 ? node.value : node?.domain;
|
|
126
|
+
if (!domain) return;
|
|
127
|
+
expanded = domain === expanded ? undefined : domain;
|
|
128
|
+
focus = domain;
|
|
129
|
+
page = 0;
|
|
112
130
|
},
|
|
113
131
|
toggle() {
|
|
114
|
-
const
|
|
132
|
+
const current = view();
|
|
133
|
+
const focused = current.rows[current.cursor];
|
|
115
134
|
if (focused) tree.toggle(focused.value);
|
|
116
135
|
},
|
|
117
136
|
};
|
|
@@ -130,67 +149,85 @@ export function fitTreeText(value, width) {
|
|
|
130
149
|
return `${result}…`;
|
|
131
150
|
}
|
|
132
151
|
|
|
133
|
-
export function renderTreePage(tree, pager, { columns = 80, colors = pc, error = '' } = {}) {
|
|
134
|
-
const c = colors, view = pager.view(), width = Math.max(
|
|
152
|
+
export function renderTreePage(tree, pager, { columns = 80, rows = Infinity, colors = pc, error = '', editing = false } = {}) {
|
|
153
|
+
const c = colors, view = pager.view(), width = Math.max(1, columns - 1);
|
|
135
154
|
const line = (text, style = value => value) => style(fitTreeText(text, width));
|
|
136
|
-
const lines = [line('◆
|
|
137
|
-
|
|
155
|
+
const lines = [line('◆ 选择安装技能', c.green), line(editing
|
|
156
|
+
? `│ 搜索:${view.query} ▌` : `│ / 搜索${view.query ? ` · ${view.query}` : ''}`)];
|
|
157
|
+
const available = Math.max(1, rows - frameOverhead);
|
|
158
|
+
const start = Math.max(0, Math.min(view.cursor - available + 1, view.rows.length - available));
|
|
159
|
+
const selected = new Set(tree.names());
|
|
160
|
+
for (const [offset, node] of view.rows.slice(start, start + available).entries()) {
|
|
161
|
+
const index = start + offset;
|
|
138
162
|
const active = index === view.cursor;
|
|
139
163
|
const state = tree.state(node.value);
|
|
140
164
|
const marker = { none: '□', all: '■', partial: '◩' }[state];
|
|
141
|
-
const branch = node.depth === 0 ? '◆ '
|
|
142
|
-
:
|
|
165
|
+
const branch = node.depth === 0 ? '◆ '
|
|
166
|
+
: node.depth === 1 ? `${node === view.groups.at(-1) ? '└─' : '├─'} ${node.value === view.expanded ? '▾' : '▸'} `
|
|
167
|
+
: node === view.children.at(-1) ? ' └─ ' : ' ├─ ';
|
|
143
168
|
const prefix = `│ ${active ? '›' : ' '} ${branch}${marker} `;
|
|
144
|
-
const suffix = node.depth < 2 ? ` ${node.names.filter(name =>
|
|
169
|
+
const suffix = node.depth < 2 ? ` ${node.names.filter(name => selected.has(name)).length}/${node.names.length}` : '';
|
|
145
170
|
const name = node.depth < 2 ? `${node.label}${node.depth === 1 ? ` ${node.groupType}` : ''}` : node.label;
|
|
171
|
+
if (stringWidth(prefix) >= width) {
|
|
172
|
+
lines.push(line(`${prefix}${name}`, active ? c.green : c.dim));
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
146
175
|
const label = fitTreeText(`${prefix}${name}${suffix}`, width).slice(prefix.length);
|
|
147
176
|
// 行首保留非空树枝,避免折行工具裁掉缩进;目录与技能有不同图标和颜色。
|
|
148
177
|
lines.push(c.gray(prefix.slice(0, -2)) + (state === 'none' ? c.dim(`${marker} `) : c.green(`${marker} `))
|
|
149
178
|
+ (node.depth < 2 ? c.bold(active ? c.green(label) : c.cyan(label)) : active ? c.green(label) : label));
|
|
150
179
|
}
|
|
151
|
-
if (!view.rows.length) lines.push(line('│ 无匹配;退格修改或 Ctrl+U 清空搜索。', c.yellow));
|
|
152
180
|
const focused = view.rows[view.cursor];
|
|
153
|
-
const detail = focused?.depth === 2 ? focused.hint
|
|
154
|
-
|
|
155
|
-
lines.push(
|
|
156
|
-
line(`│ ${
|
|
157
|
-
line(
|
|
158
|
-
|
|
159
|
-
line('└ Tab 勾选 · Enter 确认 · Ctrl+C 取消', c.dim));
|
|
181
|
+
const detail = focused?.depth === 2 ? focused.hint : '空格勾选整组,包括其他页和筛选隐藏项。';
|
|
182
|
+
const page = view.totalPages ? ` · 第 ${view.page + 1}/${view.totalPages} 页` : '';
|
|
183
|
+
lines.push(line(error ? `│ ${error}` : focused ? `│ ${detail}` : '│ 无匹配,按 / 修改或 Ctrl+U 清空。', error ? c.red : focused ? c.dim : c.yellow),
|
|
184
|
+
line(`│ 已选 ${selected.size} 个${page}${editing ? ' · 输入关键词,空格分隔' : ' · ↑/↓ 移动 · ←/→ 翻页'}`, c.green),
|
|
185
|
+
line(editing ? '└ Enter 返回树 · Ctrl+U 清空 · Ctrl+C 取消'
|
|
186
|
+
: '└ Tab 展开/收拢 · 空格勾选 · Enter 确认 · Ctrl+U 清空 · Ctrl+C 取消', c.dim));
|
|
160
187
|
return lines.join('\n');
|
|
161
188
|
}
|
|
162
189
|
|
|
163
|
-
export function treeSelect({ skills, input = process.stdin, output = process.stdout }) {
|
|
164
|
-
const tree = createSkillTree(skills);
|
|
165
|
-
const
|
|
166
|
-
const pager = createTreePager(tree, pageSize());
|
|
190
|
+
export function treeSelect({ skills, initialNames = [], input = process.stdin, output = process.stdout }) {
|
|
191
|
+
const tree = createSkillTree(skills, initialNames);
|
|
192
|
+
const pager = createTreePager(tree);
|
|
167
193
|
class TreePrompt extends Prompt {
|
|
168
194
|
constructor() {
|
|
169
195
|
super({ input, output,
|
|
170
196
|
render() {
|
|
171
197
|
if (this.state === 'submit') return pc.green(`◇ 已选择 ${tree.names().length} 个技能`);
|
|
172
198
|
if (this.state === 'cancel') return pc.yellow('◇ 已取消树形选择');
|
|
173
|
-
|
|
174
|
-
|
|
199
|
+
const rows = output.rows || 24;
|
|
200
|
+
pager.resize(Math.min(maxPageSize, rows - frameOverhead - 1 - pager.view().groups.length));
|
|
201
|
+
return renderTreePage(tree, pager, { rows, columns: output.columns || 80,
|
|
202
|
+
error: this.state === 'error' ? this.error : '', editing: this.editing });
|
|
175
203
|
},
|
|
176
204
|
});
|
|
177
|
-
this.
|
|
178
|
-
this.
|
|
205
|
+
this.editing = false;
|
|
206
|
+
this.value = tree.names();
|
|
207
|
+
this.on('userInput', value => {
|
|
208
|
+
if (this.editing) pager.search(value);
|
|
209
|
+
});
|
|
179
210
|
this.on('key', (character, key) => {
|
|
180
|
-
if (key.
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
211
|
+
if (key.ctrl && key.name === 'u') pager.clearSearch();
|
|
212
|
+
if (this.editing) return;
|
|
213
|
+
if (character === '/') {
|
|
214
|
+
const { query } = pager.view();
|
|
215
|
+
this._clearUserInput();
|
|
216
|
+
this.editing = true;
|
|
217
|
+
this._setUserInput(query, true);
|
|
185
218
|
}
|
|
186
|
-
if (key.name === '
|
|
219
|
+
if (key.name === 'up' || key.name === 'down') pager.move(key.name === 'up' ? -1 : 1);
|
|
220
|
+
if (key.name === 'left' || key.name === 'right') pager.turn(key.name === 'left' ? -1 : 1);
|
|
221
|
+
if (key.name === 'tab') pager.toggleExpanded();
|
|
222
|
+
if (key.name === 'space') pager.toggle();
|
|
187
223
|
this.value = tree.names();
|
|
188
224
|
});
|
|
189
225
|
}
|
|
190
|
-
_isActionKey(character, key) {
|
|
191
|
-
return key.name === 'tab' || (key.name === 'space' && !pager.view().query.trim());
|
|
192
|
-
}
|
|
193
226
|
_shouldSubmit() {
|
|
227
|
+
if (this.editing) {
|
|
228
|
+
this.editing = false;
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
194
231
|
if (this.value.length) return true;
|
|
195
232
|
this.error = '请至少勾选一个技能。';
|
|
196
233
|
this.state = 'error';
|