@namewta/skills-hub 0.1.1 → 0.1.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/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.1
12
+ # 直接进入可搜索的领域 / 技能树
13
+ npx @namewta/skills-hub@0.1.2
14
14
 
15
15
  # 或全局安装后运行
16
- npm install -g @namewta/skills-hub@0.1.1
16
+ npm install -g @namewta/skills-hub@0.1.2
17
17
  skills-hub
18
18
 
19
19
  # 原有命令行安装方式继续保留
20
- npx @namewta/skills-hub@0.1.1 list
21
- npx @namewta/skills-hub@0.1.1 install --domain dev
22
- npx @namewta/skills-hub@0.1.1 install --skill dev-grill dev-spec system-proxy
20
+ npx @namewta/skills-hub@0.1.2 list
21
+ npx @namewta/skills-hub@0.1.2 install --domain dev
22
+ npx @namewta/skills-hub@0.1.2 install --skill dev-grill dev-spec system-proxy
23
23
  ```
24
24
 
25
- 在目标项目根目录执行,按领域或技能选择;npm 下载包不会自动安装技能。终端中不带参数运行 `skills-hub` 或 `skills-hub install` 会进入中文交互:空格多选,回车确认,Ctrl+C 取消。支持 `skills-hub install --dry-run` 交互预览;内容冲突需检查后显式运行 `skills-hub install --replace`,不会自动覆盖。非交互环境继续要求明确参数,不会等待输入。
25
+ 在目标项目根目录执行,按领域或技能选择;npm 下载包不会自动安装技能。终端中不带参数运行 `skills-hub` 或 `skills-hub install`,直接进入可搜索的领域 / 技能树,无需先选择安装模式。勾选领域会选中其全部子技能,可再取消个别子项,也能混选其他领域的技能;根节点用于全选 / 清空。`[x]` 表示全选,`[-]` 表示部分选中,`[ ]` 表示未选。直接输入名称、领域或中文用途实时模糊搜索,支持缩写与多个关键词;↑/↓ 定位、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
- const mode = await ask(ui.select({ message: '如何选择?', options: [
27
- { value: 'domain', label: '按领域安装' },
28
- { value: 'skill', label: '选择特定技能' },
29
- { value: 'all', label: '安装全部技能' },
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[x] 全选,[-] 部分选中,[ ] 未选;更换搜索词保留选择,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
- skills.push({ domain, name, source });
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.1",
3
+ "version": "0.1.2",
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",
@@ -0,0 +1,89 @@
1
+ import { AutocompletePrompt } from '@clack/core';
2
+ import pc from 'picocolors';
3
+ import wrapAnsi from 'wrap-ansi';
4
+
5
+ // 非连续字符匹配,支持中文、全角英文和多关键词,不做拼音转换或拼写纠错。
6
+ export function matchesSkillSearch(search, option) {
7
+ const normalize = value => String(value ?? '').normalize('NFKC').toLowerCase();
8
+ const text = normalize(`${option.label ?? option.value} ${option.hint ?? ''}`);
9
+ return normalize(search).trim().split(/\s+/u).filter(Boolean).every(term => {
10
+ let position = 0;
11
+ for (const character of term) {
12
+ const found = text.indexOf(character, position);
13
+ if (found === -1) return false;
14
+ position = found + character.length;
15
+ }
16
+ return true;
17
+ });
18
+ }
19
+
20
+ export function createSkillTree(skills) {
21
+ const selected = new Set();
22
+ const root = { value: '@all', label: '全部技能', depth: 0, names: skills.map(skill => skill.name) };
23
+ const nodes = [root];
24
+ for (const domain of [...new Set(skills.map(skill => skill.domain))]) {
25
+ const children = skills.filter(skill => skill.domain === domain);
26
+ nodes.push({ value: `@domain:${domain}`, label: `${domain}/`, depth: 1, names: children.map(skill => skill.name) });
27
+ nodes.push(...children.map(skill => ({ value: skill.name, label: skill.name, depth: 2,
28
+ domain: `@domain:${domain}`, hint: `${domain} · ${skill.description ?? ''}`, names: [skill.name] })));
29
+ }
30
+ const byValue = new Map(nodes.map(node => [node.value, node]));
31
+ return {
32
+ nodes,
33
+ names: () => skills.filter(skill => selected.has(skill.name)).map(skill => skill.name),
34
+ state(value) {
35
+ const names = byValue.get(value)?.names ?? [];
36
+ const count = names.filter(name => selected.has(name)).length;
37
+ return count === 0 ? 'none' : count === names.length ? 'all' : 'partial';
38
+ },
39
+ toggle(value) {
40
+ const node = byValue.get(value);
41
+ if (!node) throw new Error(`未知树节点:${value}`);
42
+ const remove = node.names.every(name => selected.has(name));
43
+ for (const name of node.names) { if (remove) selected.delete(name); else selected.add(name); }
44
+ },
45
+ matches(search, node) {
46
+ if (matchesSkillSearch(search, root)) return true;
47
+ if (node.depth === 0) return false;
48
+ if (matchesSkillSearch(search, node)) return true;
49
+ if (node.depth === 2) return matchesSkillSearch(search, byValue.get(node.domain));
50
+ return nodes.some(child => child.domain === node.value && matchesSkillSearch(search, child));
51
+ },
52
+ };
53
+ }
54
+
55
+ export function treeSelect({ skills, input = process.stdin, output = process.stdout }) {
56
+ const tree = createSkillTree(skills);
57
+ class TreePrompt extends AutocompletePrompt {
58
+ toggleSelected(value) {
59
+ // 父节点不是安装项;最终值始终只有明确的叶子名称。
60
+ tree.toggle(value);
61
+ this.selectedValues = tree.names();
62
+ }
63
+ }
64
+ return new TreePrompt({ input, output, multiple: true, options: tree.nodes,
65
+ filter: (search, node) => tree.matches(search, node),
66
+ validate: values => !values?.length ? '请至少勾选一个技能。' : undefined,
67
+ render() {
68
+ const count = tree.names().length;
69
+ if (this.state === 'submit') return pc.green(`✓ 已选择 ${count} 个技能`);
70
+ if (this.state === 'cancel') return pc.yellow('已取消树形选择');
71
+ const rows = this.filteredOptions;
72
+ const size = Math.max(1, Math.min(10, (output.rows || 24) - 8));
73
+ const start = Math.max(0, Math.min(this.cursor - Math.floor(size / 2), rows.length - size));
74
+ const width = Math.max(16, (output.columns || 80) - 4);
75
+ const lines = rows.slice(start, start + size).map((node, index) => {
76
+ const marker = { none: '[ ]', all: '[x]', partial: '[-]' }[tree.state(node.value)];
77
+ const prefix = `${start + index === this.cursor ? '›' : ' '} ${' '.repeat(node.depth)}${marker} `;
78
+ const detail = node.depth < 2 ? ` (${node.names.length} 个技能)` : ` · ${node.hint}`;
79
+ const line = wrapAnsi(`${prefix}${node.label}${detail}`, width, { hard: true }).split('\n')[0];
80
+ return start + index === this.cursor ? pc.cyan(line) : line;
81
+ });
82
+ return [pc.bold('搜索并选择领域 / 技能'), `搜索:${this.userInputWithCursor}`,
83
+ ...(!rows.length ? [pc.yellow('无匹配;退格修改或 Ctrl+U 清空搜索。')] : lines),
84
+ `已选 ${count}/${skills.length} 个技能 · 显示 ${rows.length ? start + 1 : 0}–${Math.min(start + size, rows.length)}/${rows.length} 项`,
85
+ pc.dim('↑/↓ 定位 · Tab 勾选 · Enter 确认 · Ctrl+C 取消'),
86
+ ...(this.state === 'error' ? [pc.red(this.error)] : [])].join('\n');
87
+ },
88
+ }).prompt();
89
+ }