@namewta/skills-hub 0.1.1 → 0.1.3
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 -8
- package/cli.mjs +7 -12
- package/install.mjs +2 -1
- package/package.json +3 -1
- package/tree-select.mjs +199 -0
package/README.md
CHANGED
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
需要 Node.js 22.14+。npm 包名为 `@namewta/skills-hub`,命令名为 `skills-hub`。可直接通过 npm 使用,无需预先克隆:
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
#
|
|
13
|
-
npx @namewta/skills-hub@0.1.
|
|
12
|
+
# 直接进入可搜索的领域 / 技能树
|
|
13
|
+
npx @namewta/skills-hub@0.1.3
|
|
14
14
|
|
|
15
15
|
# 或全局安装后运行
|
|
16
|
-
npm install -g @namewta/skills-hub@0.1.
|
|
16
|
+
npm install -g @namewta/skills-hub@0.1.3
|
|
17
17
|
skills-hub
|
|
18
18
|
|
|
19
19
|
# 原有命令行安装方式继续保留
|
|
20
|
-
npx @namewta/skills-hub@0.1.
|
|
21
|
-
npx @namewta/skills-hub@0.1.
|
|
22
|
-
npx @namewta/skills-hub@0.1.
|
|
20
|
+
npx @namewta/skills-hub@0.1.3 list
|
|
21
|
+
npx @namewta/skills-hub@0.1.3 install --domain dev
|
|
22
|
+
npx @namewta/skills-hub@0.1.3 install --skill dev-grill dev-spec system-proxy
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
在目标项目根目录执行,按领域或技能选择;npm 下载包不会自动安装技能。终端中不带参数运行 `skills-hub` 或 `skills-hub install
|
|
25
|
+
在目标项目根目录执行,按领域或技能选择;npm 下载包不会自动安装技能。终端中不带参数运行 `skills-hub` 或 `skills-hub install`,直接进入可搜索的领域 / 技能树,无需先选择安装模式。勾选领域会选中其全部子技能,可再取消个别子项,也能混选其他领域的技能;根节点用于全选 / 清空。绿色 `■` 表示全选,`◩` 表示部分选中,`□` 表示未选;目录使用加粗名称与 `▸` 图标,技能用 `├─` / `└─` 树枝区分。直接输入名称、领域或中文用途实时模糊搜索,支持缩写与多个关键词;↑/↓ 页内移动、←/→ 整页翻页、Tab 勾选/取消、Enter 确认。每页只属于一个领域,领域行固定在顶部且可勾选;页内到达边界不会滚动加载,底部显示全局页码及领域内页码。技能说明只显示当前焦点项,避免长文本铺满终端。更换搜索词保留已选技能,Ctrl+U 清空搜索,Ctrl+C 取消。搜索时父节点仍操作整个领域(包括隐藏子项),部分选中时再勾父节点会补齐全选。支持 `skills-hub install --dry-run` 交互预览;内容冲突需检查后显式运行 `skills-hub install --replace`,不会自动覆盖。非交互环境继续要求明确参数,不会等待输入。
|
|
26
26
|
|
|
27
|
-
交互界面使用 `@clack/prompts`、`picocolors`、`string-width` 和 `wrap-ansi`;npm 自动安装这些依赖。源码的显式参数安装器仍仅依赖 Node.js 标准库、可离线运行;源码交互模式先运行 `npm ci`。也可以克隆源码后离线运行安装器:
|
|
27
|
+
交互界面使用 `@clack/prompts`、`@clack/core`、`picocolors`、`string-width` 和 `wrap-ansi`;npm 自动安装这些依赖。源码的显式参数安装器仍仅依赖 Node.js 标准库、可离线运行;源码交互模式先运行 `npm ci`。也可以克隆源码后离线运行安装器:
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
30
|
git clone https://github.com/NAMEWTA/skills-hub.git
|
package/cli.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import pc from 'picocolors';
|
|
|
3
3
|
import stringWidth from 'string-width';
|
|
4
4
|
import wrapAnsi from 'wrap-ansi';
|
|
5
5
|
import { createInstaller, select, main } from './install.mjs';
|
|
6
|
+
import { treeSelect } from './tree-select.mjs';
|
|
7
|
+
export { matchesSkillSearch } from './tree-select.mjs';
|
|
6
8
|
|
|
7
9
|
export function formatSummary(names, columns = process.stdout.columns ?? 80) {
|
|
8
10
|
const width = Math.max(20, Math.min(columns - 8, 100));
|
|
@@ -10,7 +12,7 @@ export function formatSummary(names, columns = process.stdout.columns ?? 80) {
|
|
|
10
12
|
return wrapAnsi(`${pc.bold(label)}${' '.repeat(Math.max(1, 8 - stringWidth(label)))}${names.join('、')}`, width, { hard: true });
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export async function interactive({ argv = [], project = process.cwd(), ui = prompts } = {}) {
|
|
15
|
+
export async function interactive({ argv = [], project = process.cwd(), ui = prompts, choose = treeSelect } = {}) {
|
|
14
16
|
if (argv.some(value => !['install', '--replace', '--dry-run'].includes(value))) {
|
|
15
17
|
throw new Error('交互安装只接受 install、--replace 和 --dry-run。');
|
|
16
18
|
}
|
|
@@ -23,17 +25,10 @@ export async function interactive({ argv = [], project = process.cwd(), ui = pro
|
|
|
23
25
|
ui.intro(pc.cyan('skills-hub · 按需安装中文技能'));
|
|
24
26
|
ui.note(project, '目标项目(技能写入 .agents/skills/)');
|
|
25
27
|
const skills = createInstaller().catalog();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
] }));
|
|
31
|
-
let domains = [], names = [];
|
|
32
|
-
if (mode === 'domain') domains = await ask(ui.multiselect({ message: '选择领域(空格勾选,回车继续)', required: true,
|
|
33
|
-
options: [...new Set(skills.map(skill => skill.domain))].map(domain => ({ value: domain, label: domain, hint: `${skills.filter(skill => skill.domain === domain).length} 个技能` })) }));
|
|
34
|
-
if (mode === 'skill') names = await ask(ui.multiselect({ message: '选择技能(空格勾选,回车继续)', required: true,
|
|
35
|
-
options: skills.map(skill => ({ value: skill.name, label: skill.name, hint: skill.domain })) }));
|
|
36
|
-
const selected = select(skills, domains, names, mode === 'all');
|
|
28
|
+
ui.note('↑/↓ 页内移动,←/→ 整页翻页,Tab 勾选,Enter 确认。\n直接输入搜索;勾选领域包含其他页和隐藏子项,可再取消个别技能。\n■ 全选 · ◩ 部分选中 · □ 未选;Ctrl+U 清空搜索。', '树形搜索多选');
|
|
29
|
+
const names = await ask(choose({ skills }));
|
|
30
|
+
const selected = select(skills, [], names);
|
|
31
|
+
if (!selected.length) throw new Error('请至少勾选一个技能。');
|
|
37
32
|
ui.note(formatSummary(selected.map(skill => skill.name)), `${selected.length} 个技能`);
|
|
38
33
|
const dryRun = argv.includes('--dry-run');
|
|
39
34
|
if (!await ask(ui.confirm({ message: dryRun ? '检查安装计划?(不写入文件)' : '安装以上技能?', initialValue: true }))) {
|
package/install.mjs
CHANGED
|
@@ -110,7 +110,8 @@ export function createInstaller({ repository = repositoryRoot, fsOps = fs } = {}
|
|
|
110
110
|
if (declared !== name) throw new InstallError(`Frontmatter name must equal directory name: ${manifest}`);
|
|
111
111
|
if (seen.has(name)) throw new InstallError(`Duplicate install name: ${name}`);
|
|
112
112
|
seen.add(name);
|
|
113
|
-
|
|
113
|
+
const description = header[1].match(/^description:\s*([^\r\n]+)/m)?.[1].trim().replace(/^["']|["']$/g, '') ?? '';
|
|
114
|
+
skills.push({ domain, name, source, description });
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
if (!skills.length) throw new InstallError(`No skills found in ${skillRoot}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namewta/skills-hub",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "独立中文 Agent Skills:按领域安装,覆盖开发交付、项目知识与系统维护。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"install.mjs",
|
|
11
11
|
"cli.mjs",
|
|
12
|
+
"tree-select.mjs",
|
|
12
13
|
"skills/",
|
|
13
14
|
"licenses/",
|
|
14
15
|
"LICENSE",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"registry": "https://registry.npmjs.org/"
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
53
|
+
"@clack/core": "1.5.1",
|
|
52
54
|
"@clack/prompts": "1.8.1",
|
|
53
55
|
"picocolors": "1.1.1",
|
|
54
56
|
"string-width": "8.3.0",
|
package/tree-select.mjs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Prompt } from '@clack/core';
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
import stringWidth from 'string-width';
|
|
4
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
5
|
+
|
|
6
|
+
// 非连续字符匹配,支持中文、全角英文和多关键词,不做拼音转换或拼写纠错。
|
|
7
|
+
export function matchesSkillSearch(search, option) {
|
|
8
|
+
const normalize = value => String(value ?? '').normalize('NFKC').toLowerCase();
|
|
9
|
+
const text = normalize(`${option.label ?? option.value} ${option.hint ?? ''}`);
|
|
10
|
+
return normalize(search).trim().split(/\s+/u).filter(Boolean).every(term => {
|
|
11
|
+
let position = 0;
|
|
12
|
+
for (const character of term) {
|
|
13
|
+
const found = text.indexOf(character, position);
|
|
14
|
+
if (found === -1) return false;
|
|
15
|
+
position = found + character.length;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createSkillTree(skills) {
|
|
22
|
+
const selected = new Set();
|
|
23
|
+
const root = { value: '@all', label: '全部技能', depth: 0, names: skills.map(skill => skill.name) };
|
|
24
|
+
const nodes = [root];
|
|
25
|
+
for (const domain of [...new Set(skills.map(skill => skill.domain))]) {
|
|
26
|
+
const children = skills.filter(skill => skill.domain === domain);
|
|
27
|
+
nodes.push({ value: `@domain:${domain}`, label: `${domain}/`, depth: 1, names: children.map(skill => skill.name) });
|
|
28
|
+
nodes.push(...children.map(skill => ({ value: skill.name, label: skill.name, depth: 2,
|
|
29
|
+
domain: `@domain:${domain}`, hint: `${domain} · ${skill.description ?? ''}`, names: [skill.name] })));
|
|
30
|
+
}
|
|
31
|
+
const byValue = new Map(nodes.map(node => [node.value, node]));
|
|
32
|
+
return {
|
|
33
|
+
nodes,
|
|
34
|
+
names: () => skills.filter(skill => selected.has(skill.name)).map(skill => skill.name),
|
|
35
|
+
state(value) {
|
|
36
|
+
const names = byValue.get(value)?.names ?? [];
|
|
37
|
+
const count = names.filter(name => selected.has(name)).length;
|
|
38
|
+
return count === 0 ? 'none' : count === names.length ? 'all' : 'partial';
|
|
39
|
+
},
|
|
40
|
+
toggle(value) {
|
|
41
|
+
const node = byValue.get(value);
|
|
42
|
+
if (!node) throw new Error(`未知树节点:${value}`);
|
|
43
|
+
const remove = node.names.every(name => selected.has(name));
|
|
44
|
+
for (const name of node.names) { if (remove) selected.delete(name); else selected.add(name); }
|
|
45
|
+
},
|
|
46
|
+
matches(search, node) {
|
|
47
|
+
if (matchesSkillSearch(search, root)) return true;
|
|
48
|
+
if (node.depth === 0) return false;
|
|
49
|
+
if (matchesSkillSearch(search, node)) return true;
|
|
50
|
+
if (node.depth === 2) return matchesSkillSearch(search, byValue.get(node.domain));
|
|
51
|
+
return nodes.some(child => child.domain === node.value && matchesSkillSearch(search, child));
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 每页只属于一个领域;领域行始终置顶且可勾选,不与子项一起滚出屏幕。
|
|
57
|
+
export function createTreePager(tree, pageSize = 8) {
|
|
58
|
+
let query = '', size = Math.max(1, pageSize), page = 0, cursor = 0;
|
|
59
|
+
function pages() {
|
|
60
|
+
const result = [];
|
|
61
|
+
for (const domain of tree.nodes.filter(node => node.depth === 1)) {
|
|
62
|
+
const children = tree.nodes.filter(node => node.domain === domain.value && tree.matches(query, node));
|
|
63
|
+
for (let start = 0; start < children.length; start += size) {
|
|
64
|
+
result.push({ domain, children: children.slice(start, start + size),
|
|
65
|
+
domainPage: Math.floor(start / size) + 1, domainPages: Math.ceil(children.length / size) });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function view() {
|
|
71
|
+
const all = pages();
|
|
72
|
+
page = Math.max(0, Math.min(page, all.length - 1));
|
|
73
|
+
const current = all[page];
|
|
74
|
+
const rows = current ? [tree.nodes[0], current.domain, ...current.children] : [];
|
|
75
|
+
cursor = Math.max(0, Math.min(cursor, rows.length - 1));
|
|
76
|
+
return { ...current, rows, cursor, page, totalPages: all.length, query, pageSize: size };
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
view,
|
|
80
|
+
search(value) {
|
|
81
|
+
if (value === query) return;
|
|
82
|
+
query = value; page = 0; cursor = 0;
|
|
83
|
+
const current = view();
|
|
84
|
+
if (query.trim() && current.rows.length) {
|
|
85
|
+
cursor = matchesSkillSearch(query, tree.nodes[0]) ? 0
|
|
86
|
+
: matchesSkillSearch(query, current.domain) ? 1 : 2;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
resize(value) {
|
|
90
|
+
if (size === value) return;
|
|
91
|
+
const before = view();
|
|
92
|
+
const focused = before.rows[cursor]?.value;
|
|
93
|
+
size = Math.max(1, value);
|
|
94
|
+
const all = pages();
|
|
95
|
+
const target = all.findIndex(item => item.children.some(node => node.value === focused)
|
|
96
|
+
|| ((focused === '@all' || focused === before.domain?.value) && item.domain.value === before.domain?.value));
|
|
97
|
+
if (target !== -1) page = target;
|
|
98
|
+
const current = view();
|
|
99
|
+
const index = current.rows.findIndex(node => node.value === focused);
|
|
100
|
+
if (index !== -1) cursor = index;
|
|
101
|
+
},
|
|
102
|
+
move(direction) {
|
|
103
|
+
const current = view();
|
|
104
|
+
cursor = Math.max(0, Math.min(cursor + direction, current.rows.length - 1));
|
|
105
|
+
},
|
|
106
|
+
turn(direction) {
|
|
107
|
+
const current = view();
|
|
108
|
+
const next = Math.max(0, Math.min(page + direction, current.totalPages - 1));
|
|
109
|
+
if (next !== page) { page = next; cursor = 2; }
|
|
110
|
+
},
|
|
111
|
+
toggle() {
|
|
112
|
+
const focused = view().rows[cursor];
|
|
113
|
+
if (focused) tree.toggle(focused.value);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const graphemes = new Intl.Segmenter('zh', { granularity: 'grapheme' });
|
|
119
|
+
export function fitTreeText(value, width) {
|
|
120
|
+
const text = stripVTControlCharacters(String(value)).replace(/[\u0000-\u001f\u007f]/g, ' ');
|
|
121
|
+
if (stringWidth(text) <= width) return text;
|
|
122
|
+
let result = '', used = 0;
|
|
123
|
+
for (const { segment } of graphemes.segment(text)) {
|
|
124
|
+
const length = stringWidth(segment);
|
|
125
|
+
if (used + length > width - 1) break;
|
|
126
|
+
result += segment; used += length;
|
|
127
|
+
}
|
|
128
|
+
return `${result}…`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function renderTreePage(tree, pager, { columns = 80, colors = pc, error = '' } = {}) {
|
|
132
|
+
const c = colors, view = pager.view(), width = Math.max(12, columns - 1);
|
|
133
|
+
const line = (text, style = value => value) => style(fitTreeText(text, width));
|
|
134
|
+
const lines = [line('◆ 搜索并选择领域 / 技能', c.green), line(`│ 搜索:${view.query || '输入名称 / 用途'} ▌`), '│'];
|
|
135
|
+
for (const [index, node] of view.rows.entries()) {
|
|
136
|
+
const active = index === view.cursor;
|
|
137
|
+
const state = tree.state(node.value);
|
|
138
|
+
const marker = { none: '□', all: '■', partial: '◩' }[state];
|
|
139
|
+
const branch = node.depth === 0 ? '◆ ' : node.depth === 1 ? '└─ ▸ '
|
|
140
|
+
: index === view.rows.length - 1 ? ' └─ ' : ' ├─ ';
|
|
141
|
+
const prefix = `│ ${active ? '›' : ' '} ${branch}${marker} `;
|
|
142
|
+
const suffix = node.depth < 2 ? ` ${node.names.filter(name => tree.names().includes(name)).length}/${node.names.length}` : '';
|
|
143
|
+
const name = node.depth < 2 ? `${node.label}${node.depth === 1 ? ' 领域' : ''}` : node.label;
|
|
144
|
+
const label = fitTreeText(`${prefix}${name}${suffix}`, width).slice(prefix.length);
|
|
145
|
+
// 行首保留非空树枝,避免折行工具裁掉缩进;目录与技能有不同图标和颜色。
|
|
146
|
+
lines.push(c.gray(prefix.slice(0, -2)) + (state === 'none' ? c.dim(`${marker} `) : c.green(`${marker} `))
|
|
147
|
+
+ (node.depth < 2 ? c.bold(active ? c.green(label) : c.cyan(label)) : active ? c.green(label) : label));
|
|
148
|
+
}
|
|
149
|
+
if (!view.rows.length) lines.push(line('│ 无匹配;退格修改或 Ctrl+U 清空搜索。', c.yellow));
|
|
150
|
+
const focused = view.rows[view.cursor];
|
|
151
|
+
const detail = focused?.depth === 2 ? focused.hint
|
|
152
|
+
: focused ? '勾选将操作全部子技能,包括其他页和搜索隐藏项。' : '输入其他关键词以继续选择。';
|
|
153
|
+
lines.push('│', line(`│ ${focused?.label ?? '搜索提示'} · ${view.domain?.label ?? '—'}`, c.dim),
|
|
154
|
+
line(`│ ${detail}`, c.dim),
|
|
155
|
+
line(`│ 第 ${view.totalPages ? view.page + 1 : 0}/${view.totalPages} 页 · ${view.domain?.label ?? '—'} ${view.domainPage ?? 0}/${view.domainPages ?? 0} · 已选 ${tree.names().length} 个`, c.green),
|
|
156
|
+
line(error ? `│ ${error}` : '│ ←/→ 整页翻页 · ↑/↓ 页内移动', error ? c.red : c.dim),
|
|
157
|
+
line('└ Tab 勾选 · Enter 确认 · Ctrl+C 取消', c.dim));
|
|
158
|
+
return lines.join('\n');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function treeSelect({ skills, input = process.stdin, output = process.stdout }) {
|
|
162
|
+
const tree = createSkillTree(skills);
|
|
163
|
+
const pageSize = () => Math.max(1, Math.min(8, (output.rows || 24) - 13));
|
|
164
|
+
const pager = createTreePager(tree, pageSize());
|
|
165
|
+
class TreePrompt extends Prompt {
|
|
166
|
+
constructor() {
|
|
167
|
+
super({ input, output,
|
|
168
|
+
render() {
|
|
169
|
+
if (this.state === 'submit') return pc.green(`◇ 已选择 ${tree.names().length} 个技能`);
|
|
170
|
+
if (this.state === 'cancel') return pc.yellow('◇ 已取消树形选择');
|
|
171
|
+
pager.resize(pageSize());
|
|
172
|
+
return renderTreePage(tree, pager, { columns: output.columns || 80, error: this.state === 'error' ? this.error : '' });
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
this.value = [];
|
|
176
|
+
this.on('userInput', value => pager.search(value));
|
|
177
|
+
this.on('key', (character, key) => {
|
|
178
|
+
if (key.name === 'up' || key.name === 'down') pager.move(key.name === 'up' ? -1 : 1);
|
|
179
|
+
if (key.name === 'left' || key.name === 'right') {
|
|
180
|
+
pager.turn(key.name === 'left' ? -1 : 1);
|
|
181
|
+
// 左右键被分页占用,不让 readline 光标移动后将搜索文字插到中间。
|
|
182
|
+
if (this.rl) this.rl.cursor = this.rl.line.length;
|
|
183
|
+
}
|
|
184
|
+
if (key.name === 'tab' || (key.name === 'space' && !pager.view().query.trim())) pager.toggle();
|
|
185
|
+
this.value = tree.names();
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
_isActionKey(character, key) {
|
|
189
|
+
return key.name === 'tab' || (key.name === 'space' && !pager.view().query.trim());
|
|
190
|
+
}
|
|
191
|
+
_shouldSubmit() {
|
|
192
|
+
if (this.value.length) return true;
|
|
193
|
+
this.error = '请至少勾选一个技能。';
|
|
194
|
+
this.state = 'error';
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return new TreePrompt().prompt();
|
|
199
|
+
}
|