dsh-science-plugin 0.0.0-stage → 0.14.0
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/LICENSE +21 -0
- package/README.md +78 -2
- package/agents/_README.md +5 -0
- package/agents/analyst.md +27 -0
- package/agents/figure-expert.md +35 -0
- package/agents/literature-scout.md +32 -0
- package/agents/presentation.md +78 -0
- package/agents/reviewer.md +32 -0
- package/agents/simulator.md +30 -0
- package/agents/topic-designer.md +26 -0
- package/agents/trainer.md +36 -0
- package/agents/writer.md +44 -0
- package/assets/mascots/analyst.svg +33 -0
- package/assets/mascots/designer.svg +33 -0
- package/assets/mascots/figure.svg +35 -0
- package/assets/mascots/idle.svg +9 -0
- package/assets/mascots/lead.svg +33 -0
- package/assets/mascots/presentation.svg +40 -0
- package/assets/mascots/reviewer.svg +31 -0
- package/assets/mascots/scout.svg +31 -0
- package/assets/mascots/simulator.svg +33 -0
- package/assets/mascots/thinking.svg +23 -0
- package/assets/mascots/trainer.svg +32 -0
- package/assets/mascots/working.svg +9 -0
- package/assets/mascots/writer.svg +33 -0
- package/client/client.js +3425 -0
- package/client/client.js.map +7 -0
- package/cordis.patch.yml +12 -0
- package/docs/DEVLOG.md +864 -0
- package/docs/SPEC.md +452 -0
- package/docs/recipes/agent-teams-science.md +46 -0
- package/docs/research/2026-11-12-academic-figure-skill-/350/257/204/344/274/260.md +33 -0
- package/docs/research/2026-11-12-/347/224/237/347/211/251/347/247/221/347/240/224/350/203/275/345/212/233/344/270/216/345/267/245/344/275/234/345/217/260/351/233/206/346/210/220/350/260/203/347/240/224.md +169 -0
- package/docs/research/2026-11-12-/347/247/221/347/240/224/347/273/230/345/233/276/345/274/200/346/272/220/346/226/271/346/241/210/350/260/203/347/240/224.md +52 -0
- package/docs/research/2026-11-13-/345/257/271/350/257/235/351/251/261/345/212/250/347/247/221/347/240/224/345/267/245/344/275/234/345/217/260/344/272/247/345/223/201/347/255/226/347/225/245/350/260/203/347/240/224.md +319 -0
- package/docs/research/2026-11-13-/350/267/257/347/272/277B/346/212/200/346/234/257/345/217/257/350/241/214/346/200/247/344/270/216/344/275/216/347/274/272/351/231/267/350/256/276/350/256/241/350/260/203/347/240/224.md +65 -0
- package/docs/superpowers/specs/2026-11-12-/347/247/221/347/240/224/345/267/245/344/275/234/345/217/260/351/207/215/346/236/204/350/256/276/350/256/241.md +364 -0
- package/docs/superpowers/specs/2026-11-13-/345/257/271/350/257/235/344/274/230/345/205/210/347/247/221/347/240/224/345/215/241/347/211/207/345/267/245/344/275/234/345/217/260/351/207/215/346/236/204/350/256/276/350/256/241.md +607 -0
- package/icon.svg +6 -0
- package/lib/action-cards.js +194 -0
- package/lib/artifact-index.js +131 -0
- package/lib/blueprint.js +1487 -0
- package/lib/dag.js +69 -0
- package/lib/db.js +386 -0
- package/lib/figureqa.js +290 -0
- package/lib/figures.js +732 -0
- package/lib/httpdata-auth.js +91 -0
- package/lib/httpdata.js +862 -0
- package/lib/index.js +329 -0
- package/lib/lit.js +100 -0
- package/lib/paperspine.js +287 -0
- package/lib/project-adapter.js +259 -0
- package/lib/project-catalog.js +227 -0
- package/lib/project-context.js +282 -0
- package/lib/project-domain.js +849 -0
- package/lib/project-remote.js +348 -0
- package/lib/project-store.js +653 -0
- package/lib/rail-team.js +47 -0
- package/lib/resources.js +94 -0
- package/lib/reviewcov.js +238 -0
- package/lib/reviewer.js +638 -0
- package/lib/reviewruns.js +95 -0
- package/lib/roles.js +41 -0
- package/lib/router.js +133 -0
- package/lib/skeleton-context.js +181 -0
- package/lib/skillmenu.js +993 -0
- package/lib/ssh.js +637 -0
- package/lib/status.js +138 -0
- package/lib/store.js +50 -0
- package/lib/team.js +945 -0
- package/lib/vendor/ssh2.bundle.cjs +20124 -0
- package/lib/workspace-key.js +64 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +71 -6
- package/skills/sci-autoresearch/SKILL.md +41 -0
- package/skills/sci-figures/SKILL.md +91 -0
- package/skills/sci-figures/references/journal-requirements.md +22 -0
- package/skills/sci-figures/references/r-figures.md +106 -0
- package/skills/sci-figures/scripts/figure_export.py +45 -0
- package/skills/sci-figures/scripts/style_presets.py +82 -0
- package/skills/sci-hypothesis/SKILL.md +37 -0
- package/skills/sci-polish/SKILL.md +28 -0
- package/skills/sci-remote-jobs/SKILL.md +48 -0
- package/skills/sci-simulation/SKILL.md +70 -0
- package/skills/sci-simulation/references/tool-dossiers/_TEMPLATE.md +25 -0
- package/skills/sci-simulation/references/tool-dossiers/ase.md +42 -0
- package/skills/sci-simulation/references/tool-dossiers/gaussian.md +42 -0
- package/skills/sci-simulation/references/tool-dossiers/gromacs.md +37 -0
- package/skills/sci-simulation/references/tool-dossiers/lammps.md +34 -0
- package/skills/sci-simulation/references/tool-dossiers/quantum-espresso.md +34 -0
- package/skills/sci-simulation/references/universal-tool-onboarding.md +117 -0
- package/skills/sci-slides/SKILL.md +73 -0
- package/skills/sci-slides/scripts/make_deck.py +332 -0
- package/skills/sci-writing/SKILL.md +33 -0
package/lib/skillmenu.js
ADDED
|
@@ -0,0 +1,993 @@
|
|
|
1
|
+
// dsh-science — 角色级 skill 菜单(role-scoped skill menu, v0.10.0)
|
|
2
|
+
// 设计(与 DEVLOG 架构一致):
|
|
3
|
+
// 存储:$DSH_HOME/dsh-science/role-skills/<role>/<name>/(git clone --depth 1,execFile 无 shell)。
|
|
4
|
+
// 隔离:绝不注册进 DSH 全局 skills registry、也不进 bundled skills provider——技能只经
|
|
5
|
+
// spawnMember 的成员提示词末尾「扩展技能库」段(INDEX.md 路径清单)对成员生效;
|
|
6
|
+
// 成员用自带读文件工具按需读取。跨角色隔离 = 每角色独立目录 + 只有对应角色的
|
|
7
|
+
// spawn 提示词携带该目录索引。
|
|
8
|
+
// 状态:$DSH_HOME/dsh-science/role-skills.json(+ 工作区 .dsh-science/ 镜像)。
|
|
9
|
+
// 目录(CATALOG):每角色最多 3 个精选开源技能仓库;2026-11 逐个经 GitHub API/raw 验证可达、
|
|
10
|
+
// 结构含 SKILL.md、许可 MIT/Apache 为主;ARS 一条为 CC-BY-NC-4.0 已在 description 标明)。
|
|
11
|
+
// 安全:repo URL 白名单(https github/gitlab,仅 owner/repo 两段,禁 .. 与本地路径);
|
|
12
|
+
// 安装/删除走模块级互斥队列防并发 clone;subdir 解析做前缀校验防穿越;
|
|
13
|
+
// skill 内容安全由成员自行判断(本模块只做结构发现,不做内容执行)。
|
|
14
|
+
// 工具 schema 合同(DEVLOG 坑清单):参数名避开注解关键字;properties 内不用 required;
|
|
15
|
+
// 输出对象不含 undefined 值键(一律 null 兜底)。
|
|
16
|
+
|
|
17
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, renameSync, lstatSync, realpathSync } from 'node:fs'
|
|
18
|
+
import { execFile } from 'node:child_process'
|
|
19
|
+
import { join, resolve, sep, basename } from 'node:path'
|
|
20
|
+
import { dataDirOf, PKG_ROOT_OF } from './store.js'
|
|
21
|
+
import { ROLES } from './roles.js'
|
|
22
|
+
|
|
23
|
+
function log(msg) {
|
|
24
|
+
console.error(`[dsh-science skillmenu] ${msg}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const VERSION = '0.14.0'
|
|
28
|
+
const INSTALL_TIMEOUT_MS = 120000
|
|
29
|
+
|
|
30
|
+
// 自动唤醒钩子(brief 待办 8):team.js 注册「按 role 找已 spawn 成员并推送新技能路径」的实现,
|
|
31
|
+
// skillmenu 只负责在安装成功后调用,避免 skillmenu→team 的反向依赖(team 已 import 本模块)。
|
|
32
|
+
let memberWakeHook = null
|
|
33
|
+
export function setMemberWakeHook(fn) {
|
|
34
|
+
memberWakeHook = typeof fn === 'function' ? fn : null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 新装技能的通知文本:INDEX.md + 每个 SKILL.md 的绝对路径,成员可直接读取使用。
|
|
38
|
+
export function formatSkillWakeText(entry) {
|
|
39
|
+
const paths = (Array.isArray(entry.skills) ? entry.skills : [])
|
|
40
|
+
.map((s) => (s && s.relPath && s.relPath !== '.' ? join(entry.dir, s.relPath) : entry.dir))
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
return [
|
|
43
|
+
`队长为本角色新安装了扩展技能「${entry.name}」(${entry.repo}${entry.subdir ? ` @ ${entry.subdir}` : ''})。`,
|
|
44
|
+
`技能索引:${join(entry.dir, '..', 'INDEX.md')}`,
|
|
45
|
+
'可用 SKILL.md 路径:',
|
|
46
|
+
...(paths.length ? paths.map((p) => `- ${p}`) : [`- ${entry.dir}(未发现 SKILL.md,仅登记目录)`]),
|
|
47
|
+
'需要时直接按路径读取使用(无需重启,也无需等待队长再通知)。',
|
|
48
|
+
].join('\n')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ---- 精选目录(CATALOG)-----------------------------------------------------
|
|
52
|
+
// 2026-11-08 调研验证记录(GitHub API pushed_at / stars / license + raw SKILL.md 200):
|
|
53
|
+
// K-Dense-AI/scientific-agent-skills MIT pushed 2026-11-02 56.4k★
|
|
54
|
+
// HughYau/AcademicForge MIT pushed 2026-11-01 2.6k★(默认分支 site-first)
|
|
55
|
+
// SciMate-AI/HPC-Skills MIT pushed 2026-04-06(HPC 工作流技能集)
|
|
56
|
+
// huggingface/skills Apache-2.0 pushed 2026-10-30 11.3k★
|
|
57
|
+
// Orchestra-Research/AI-Research-SKILLs MIT pushed 2026-10-11 14.3k★
|
|
58
|
+
// O0000-code/paper-search-pro Apache-2.0 pushed 2026-11-03
|
|
59
|
+
// Master-cai/Research-Paper-Writing-Skills MIT pushed 2026-06-23 8.2k★
|
|
60
|
+
// jin-s13/ai-research-writing-skill MIT pushed 2026-10-18
|
|
61
|
+
// Imbad0202/academic-research-skills CC-BY-NC-4.0 pushed 2026-11-06 55.8k★(非商用,仅 reviewer 目录保留并标注)
|
|
62
|
+
// shaowen-ye/manuscript-review-skill MIT pushed 2026-07-16
|
|
63
|
+
// AlexWortega/ai-peer-review-skill MIT pushed 2026-05-08
|
|
64
|
+
// PlutoLei/paperbanana-skill MIT pushed 2026-11-02
|
|
65
|
+
// Dsadd4/AgentFigureGallery MIT pushed 2026-09-05
|
|
66
|
+
// ngtiendong/Academic-Research-Agent-Skill MIT pushed 2026-10-04
|
|
67
|
+
// jinwyp/open-ppt-skill MIT pushed 2026-08-07
|
|
68
|
+
// zouchenzhen/thesis-defense-pptx-skill Apache-2.0 pushed 2026-06-05
|
|
69
|
+
// Faust-Donf/beamer-academic MIT pushed 2026-08-17
|
|
70
|
+
// SPYfighting/my-academic-skills MIT 用户本人的 skill 仓库(本地克隆 research/user-academic-skills,
|
|
71
|
+
// main 分支经 git ls-remote 核验可达;scientific-ppt-drawing
|
|
72
|
+
// 子目录含 SKILL.md + scripts/figure_cli.py,CLI 需 CPython 3.11-3.13)
|
|
73
|
+
const KDENSE = 'https://github.com/K-Dense-AI/scientific-agent-skills'
|
|
74
|
+
const ACADEMICFORGE = 'https://github.com/HughYau/AcademicForge'
|
|
75
|
+
const ORCHESTRA = 'https://github.com/Orchestra-Research/AI-Research-SKILLs'
|
|
76
|
+
|
|
77
|
+
const KDENSE_SCIENTIFIC_REF = 'a25cf9ec00e2745d03f8704acf6f6919694ccd9a'
|
|
78
|
+
const KDENSE_SCIENTIFIC = 'https://github.com/K-Dense-AI/scientific-agent-skills'
|
|
79
|
+
const KDENSE_DRUG_DISCOVERY = 'https://github.com/K-Dense-AI/drug-discovery-agent-skills'
|
|
80
|
+
|
|
81
|
+
export const CATALOG = {
|
|
82
|
+
simulator: [
|
|
83
|
+
{
|
|
84
|
+
id: 'kdense-molecular-dynamics',
|
|
85
|
+
name: 'OpenMM 分子动力学',
|
|
86
|
+
repo: KDENSE_SCIENTIFIC,
|
|
87
|
+
subdir: 'skills/molecular-dynamics',
|
|
88
|
+
gitRef: KDENSE_SCIENTIFIC_REF,
|
|
89
|
+
hasSkillMd: true,
|
|
90
|
+
installable: true,
|
|
91
|
+
environment: '需要准备 OpenMM、力场、体系结构文件;GPU 可选但常用于加速。',
|
|
92
|
+
risk: '结果受体系准备、力场、模拟长度和重复设置影响;单个轨迹不能独立证明机制。',
|
|
93
|
+
description: '分子动力学流程说明:体系准备、参数检查、模拟和轨迹分析。',
|
|
94
|
+
license: 'MIT',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'kdense-boltz',
|
|
98
|
+
name: 'Boltz 复合物预测',
|
|
99
|
+
repo: KDENSE_DRUG_DISCOVERY,
|
|
100
|
+
subdir: 'skills/boltz',
|
|
101
|
+
hasSkillMd: true,
|
|
102
|
+
installable: false,
|
|
103
|
+
environment: '需要本地 GPU/存储;使用远程 MSA 服务会上传序列。',
|
|
104
|
+
risk: '技能入口已核实,但本机未取得可固定提交;固定版本前禁止安装。',
|
|
105
|
+
description: 'Boltz 结构与复合物预测技能。预测结构需要实验或其他独立证据验证。',
|
|
106
|
+
license: 'MIT',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'kdense-autodock-vina',
|
|
110
|
+
name: 'AutoDock Vina 分子对接',
|
|
111
|
+
repo: KDENSE_DRUG_DISCOVERY,
|
|
112
|
+
subdir: 'skills/autodock-vina',
|
|
113
|
+
hasSkillMd: true,
|
|
114
|
+
installable: false,
|
|
115
|
+
environment: '需要 AutoDock Vina 与受体/配体结构准备工具。',
|
|
116
|
+
risk: '技能入口已核实,但本机未取得可固定提交;固定版本前禁止安装。',
|
|
117
|
+
description: '受体/配体准备、搜索空间和可复现分子对接工作流。',
|
|
118
|
+
license: 'MIT',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
trainer: [
|
|
122
|
+
{
|
|
123
|
+
id: 'kdense-esm',
|
|
124
|
+
name: 'ESM 蛋白质语言模型',
|
|
125
|
+
repo: KDENSE_SCIENTIFIC,
|
|
126
|
+
subdir: 'skills/esm',
|
|
127
|
+
gitRef: KDENSE_SCIENTIFIC_REF,
|
|
128
|
+
hasSkillMd: true,
|
|
129
|
+
installable: true,
|
|
130
|
+
environment: '模型可本地运行;Biohub API 模式需要网络和服务凭据。',
|
|
131
|
+
risk: '远程 API 会传输请求内容;模型预测结果不能替代实验验证。',
|
|
132
|
+
description: '现代 ESM/ESMC/ESMFold2 使用说明,支持序列表示和结构预测。',
|
|
133
|
+
license: '技能仓库 MIT;模型权重许可按具体模型核对',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
'figure-expert': [
|
|
137
|
+
{
|
|
138
|
+
id: 'kdense-scientific-visualization',
|
|
139
|
+
name: '科研数据可视化',
|
|
140
|
+
repo: KDENSE_SCIENTIFIC,
|
|
141
|
+
subdir: 'skills/scientific-visualization',
|
|
142
|
+
gitRef: KDENSE_SCIENTIFIC_REF,
|
|
143
|
+
hasSkillMd: true,
|
|
144
|
+
installable: true,
|
|
145
|
+
environment: '本地 Python;建议安装 Matplotlib、Seaborn 或 Plotly。',
|
|
146
|
+
risk: '自动化图形检查不代表数据、统计方法或科学解释正确。',
|
|
147
|
+
description: '本地数据图、检查、期刊导出和来源记录。',
|
|
148
|
+
license: 'MIT',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: 'kdense-scientific-schematics',
|
|
152
|
+
name: '科研机制示意图',
|
|
153
|
+
repo: KDENSE_SCIENTIFIC,
|
|
154
|
+
subdir: 'skills/scientific-schematics',
|
|
155
|
+
gitRef: KDENSE_SCIENTIFIC_REF,
|
|
156
|
+
hasSkillMd: true,
|
|
157
|
+
installable: true,
|
|
158
|
+
environment: '依赖 OpenRouter/图像模型 API,需要网络与 API key。',
|
|
159
|
+
risk: '提示词和参考图会发送到外部服务;输出为栅格图,不可编辑。不要上传未发表或患者数据。',
|
|
160
|
+
description: '辅助生成生物机制与科研流程示意图,须人工核对标注和生物学关系。',
|
|
161
|
+
license: 'MIT',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
analyst: [
|
|
165
|
+
{
|
|
166
|
+
id: 'kdense-rdkit',
|
|
167
|
+
name: 'RDKit 化学信息学',
|
|
168
|
+
repo: KDENSE_SCIENTIFIC,
|
|
169
|
+
subdir: 'skills/rdkit',
|
|
170
|
+
gitRef: KDENSE_SCIENTIFIC_REF,
|
|
171
|
+
hasSkillMd: true,
|
|
172
|
+
installable: true,
|
|
173
|
+
environment: '需要 Python 与 RDKit;底层 RDKit 代码为 BSD-3-Clause。',
|
|
174
|
+
risk: '分子描述符和相似性分数不能直接解释为生物活性。',
|
|
175
|
+
description: '分子结构标准化、描述符、指纹和化学信息学工作流。',
|
|
176
|
+
license: '技能仓库 MIT;RDKit BSD-3-Clause',
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
}// ---- 存储 ------------------------------------------------------------------
|
|
180
|
+
const roleSkillsRoot = () => join(dataDirOf(), 'role-skills')
|
|
181
|
+
const stateFile = () => join(dataDirOf(), 'role-skills.json')
|
|
182
|
+
|
|
183
|
+
function loadState() {
|
|
184
|
+
try {
|
|
185
|
+
const parsed = JSON.parse(readFileSync(stateFile(), 'utf8'))
|
|
186
|
+
if (parsed && typeof parsed === 'object' && parsed.roles && typeof parsed.roles === 'object') {
|
|
187
|
+
// 归一化:roles 必须是对象;条目必须是对象(数组/字符串/ null 一律丢弃,防止调用方 TypeError)
|
|
188
|
+
if (Array.isArray(parsed.roles)) parsed.roles = {}
|
|
189
|
+
for (const [role, entries] of Object.entries(parsed.roles)) {
|
|
190
|
+
parsed.roles[role] = Array.isArray(entries) ? entries.filter((e) => e && typeof e === 'object' && !Array.isArray(e)) : []
|
|
191
|
+
}
|
|
192
|
+
return parsed
|
|
193
|
+
}
|
|
194
|
+
} catch (err) {
|
|
195
|
+
if (err && err.code !== 'ENOENT') log(`role-skills.json read failed (treated as empty): ${err && err.message}`)
|
|
196
|
+
}
|
|
197
|
+
return { version: VERSION, updatedAt: 0, roles: {} }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function saveState(state) {
|
|
201
|
+
state.version = VERSION
|
|
202
|
+
state.updatedAt = Date.now()
|
|
203
|
+
const text = JSON.stringify(state, null, 2)
|
|
204
|
+
const tmp = `${stateFile()}.tmp`
|
|
205
|
+
try {
|
|
206
|
+
writeFileSync(tmp, text, 'utf8')
|
|
207
|
+
renameSync(tmp, stateFile())
|
|
208
|
+
} catch (err) {
|
|
209
|
+
log(`atomic persist fallback: ${err && err.message}`)
|
|
210
|
+
writeFileSync(stateFile(), text, 'utf8')
|
|
211
|
+
}
|
|
212
|
+
return text
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ---- 安装/删除互斥队列(防并发 clone 写同一 INDEX/state)-----------------------
|
|
216
|
+
let queueTail = Promise.resolve()
|
|
217
|
+
function enqueue(task) {
|
|
218
|
+
const run = queueTail.then(task, task)
|
|
219
|
+
queueTail = run.then(() => undefined, () => undefined)
|
|
220
|
+
return run
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ---- URL / 名称校验 ----------------------------------------------------------
|
|
224
|
+
// 仅接受 https://github.com/<owner>/<repo>[.git] 或 https://gitlab*。<owner>/<repo>[.git];
|
|
225
|
+
// 禁本地路径、ssh 协议、路径穿越、超深路径。
|
|
226
|
+
export function validateRepoUrl(raw) {
|
|
227
|
+
const text = String(raw || '').trim()
|
|
228
|
+
if (!text) return { error: 'repo_url 不能为空' }
|
|
229
|
+
if (text.includes('..') || text.includes('\\') || /\s/.test(text)) {
|
|
230
|
+
return { error: 'repo_url 非法:禁止 ".."、反斜杠与空白字符' }
|
|
231
|
+
}
|
|
232
|
+
let url
|
|
233
|
+
try {
|
|
234
|
+
url = new URL(text)
|
|
235
|
+
} catch {
|
|
236
|
+
return { error: 'repo_url 不是合法 URL' }
|
|
237
|
+
}
|
|
238
|
+
if (url.protocol !== 'https:') return { error: 'repo_url 必须是 https:// (不接受本地路径/ssh/git 协议)' }
|
|
239
|
+
const host = url.hostname.toLowerCase()
|
|
240
|
+
const isGithub = host === 'github.com' || host === 'www.github.com'
|
|
241
|
+
// gitlab.com 及其子域;自建 gitlab 形如 gitlab.<domain>,但排除仿冒的 gitlab.com.<attacker>
|
|
242
|
+
const isGitlab =
|
|
243
|
+
host === 'gitlab.com' ||
|
|
244
|
+
host.endsWith('.gitlab.com') ||
|
|
245
|
+
(/^gitlab[\w-]*\.[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,}$/i.test(host) && !host.startsWith('gitlab.com'))
|
|
246
|
+
if (!isGithub && !isGitlab) return { error: `仅支持 github.com / gitlab 系仓库(收到 ${host})` }
|
|
247
|
+
const segments = url.pathname.split('/').filter(Boolean)
|
|
248
|
+
if (segments.length !== 2) {
|
|
249
|
+
return { error: 'repo_url 需形如 https://github.com/<owner>/<repo>(.git 后缀可选;不接受 /tree/ 子页面等深层路径)' }
|
|
250
|
+
}
|
|
251
|
+
const repo = segments[1].replace(/\.git$/i, '')
|
|
252
|
+
if (!/^[\w.-]{1,100}$/.test(repo) || !/^[\w.-]{1,100}$/.test(segments[0])) {
|
|
253
|
+
return { error: 'owner/repo 段含非法字符' }
|
|
254
|
+
}
|
|
255
|
+
return { owner: segments[0], repo: `${url.origin}/${segments[0]}/${repo}` }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function sanitizeName(raw) {
|
|
259
|
+
const name = String(raw || '').trim().toLowerCase().replace(/\.git$/i, '')
|
|
260
|
+
if (!name || name === '.' || name === '..') return { error: '名称非法' }
|
|
261
|
+
if (!/^[\w][\w.-]{0,63}$/.test(name)) return { error: '名称只能含字母/数字/_/-/.(≤64 字符,字母开头)' }
|
|
262
|
+
return { name }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ---- 安装 -------------------------------------------------------------------
|
|
266
|
+
// git --progress 的 stderr 进度行(\r 分隔原地刷新),取最后一条有效进度。
|
|
267
|
+
const PROGRESS_RE = /^(?:remote:\s*)?(Receiving objects|Resolving deltas|Compressing objects|Counting objects|Enumerating objects|Updating files):\s*(\d{1,3})%\s*(.*)$/
|
|
268
|
+
|
|
269
|
+
export function parseGitProgress(text) {
|
|
270
|
+
if (!text) return null
|
|
271
|
+
const lines = String(text).split(/[\r\n]+/)
|
|
272
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
273
|
+
const m = PROGRESS_RE.exec(lines[i].trim())
|
|
274
|
+
if (m) return { phase: m[1], percent: Number(m[2]), detail: m[3].trim() }
|
|
275
|
+
}
|
|
276
|
+
return null
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function formatCloneProgress(p, elapsedMs) {
|
|
280
|
+
if (!p) return '克隆中(尚无进度输出)'
|
|
281
|
+
const parts = [`${p.phase} ${p.percent}%`]
|
|
282
|
+
if (p.detail) parts.push(p.detail)
|
|
283
|
+
if (typeof elapsedMs === 'number') parts.push(`已用 ${Math.round(elapsedMs / 1000)}s`)
|
|
284
|
+
return parts.join(',')
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function gitCloneDefault(url, dest) {
|
|
288
|
+
const startedAt = Date.now()
|
|
289
|
+
log(`clone 开始:${url}(--depth 1,超时上限 ${INSTALL_TIMEOUT_MS / 1000}s)`)
|
|
290
|
+
return new Promise((resolveP, rejectP) => {
|
|
291
|
+
let last = null
|
|
292
|
+
let lastPhase = null
|
|
293
|
+
let lastLogAt = 0
|
|
294
|
+
const child = execFile(
|
|
295
|
+
'git',
|
|
296
|
+
['clone', '--depth', '1', '--progress', url, dest],
|
|
297
|
+
{ timeout: INSTALL_TIMEOUT_MS, windowsHide: true },
|
|
298
|
+
(err, _stdout, stderr) => {
|
|
299
|
+
const elapsedMs = Date.now() - startedAt
|
|
300
|
+
if (err) {
|
|
301
|
+
if (err.killed) {
|
|
302
|
+
rejectP(new Error(
|
|
303
|
+
`git clone 超时(上限 ${INSTALL_TIMEOUT_MS / 1000}s)${last ? `,最后进度:${formatCloneProgress(last, elapsedMs)}` : ',无进度输出'}。` +
|
|
304
|
+
'仓库可能过大或网络过慢:可重试一次;若持续超时,请换用更小的仓库。',
|
|
305
|
+
))
|
|
306
|
+
} else {
|
|
307
|
+
const msg = String(stderr || err.message || '').replace(/\r/g, '\n').trim().split(/\n/).filter(Boolean).slice(-3).join(' | ')
|
|
308
|
+
rejectP(new Error(`git clone 失败:${msg || err.message}`))
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
log(`clone 完成(${Math.round(elapsedMs / 1000)}s)`)
|
|
312
|
+
resolveP({ cloneMs: elapsedMs })
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
)
|
|
316
|
+
// 进度节流:阶段切换立即打,同阶段 ≥5s 一条(避免 \r 刷屏)
|
|
317
|
+
child.stderr.on('data', (chunk) => {
|
|
318
|
+
const p = parseGitProgress(String(chunk))
|
|
319
|
+
if (!p) return
|
|
320
|
+
last = p
|
|
321
|
+
const now = Date.now()
|
|
322
|
+
if (p.phase !== lastPhase || now - lastLogAt >= 5000) {
|
|
323
|
+
lastPhase = p.phase
|
|
324
|
+
lastLogAt = now
|
|
325
|
+
log(`clone 进度:${formatCloneProgress(p, now - startedAt)}`)
|
|
326
|
+
}
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function runGit(args, { onProgress = false } = {}) {
|
|
332
|
+
return new Promise((resolveP, rejectP) => {
|
|
333
|
+
let last = null
|
|
334
|
+
let lastPhase = null
|
|
335
|
+
let lastLogAt = 0
|
|
336
|
+
const startedAt = Date.now()
|
|
337
|
+
const child = execFile('git', args, { timeout: INSTALL_TIMEOUT_MS, windowsHide: true, encoding: 'utf8' }, (err, stdout, stderr) => {
|
|
338
|
+
if (err) {
|
|
339
|
+
const detail = String(stderr || err.message || '').replace(/\r/g, '\n').trim().split(/\n/).filter(Boolean).slice(-3).join(' | ')
|
|
340
|
+
rejectP(new Error(err.killed ? `固定版本获取超时(${INSTALL_TIMEOUT_MS / 1000}s)${last ? `,${formatCloneProgress(last, Date.now() - startedAt)}` : ''}` : `git ${args[0]} 失败:${detail || err.message}`))
|
|
341
|
+
return
|
|
342
|
+
}
|
|
343
|
+
resolveP({ stdout: String(stdout || '').trim(), stderr: String(stderr || '') })
|
|
344
|
+
})
|
|
345
|
+
if (onProgress && child.stderr) child.stderr.on('data', (chunk) => {
|
|
346
|
+
const progress = parseGitProgress(String(chunk))
|
|
347
|
+
if (!progress) return
|
|
348
|
+
last = progress
|
|
349
|
+
const now = Date.now()
|
|
350
|
+
if (progress.phase !== lastPhase || now - lastLogAt >= 5000) {
|
|
351
|
+
lastPhase = progress.phase
|
|
352
|
+
lastLogAt = now
|
|
353
|
+
log(`固定版本获取:${formatCloneProgress(progress, now - startedAt)}`)
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async function gitClone(url, dest, gitRef = null) {
|
|
360
|
+
if (!gitRef) return gitCloneDefault(url, dest)
|
|
361
|
+
if (!/^[a-f0-9]{40}$/i.test(gitRef)) throw new Error('固定版本必须是完整的 40 位 Git commit SHA。')
|
|
362
|
+
const startedAt = Date.now()
|
|
363
|
+
log(`固定版本安装开始:${url} @ ${gitRef}`)
|
|
364
|
+
await runGit(['init', dest])
|
|
365
|
+
await runGit(['-C', dest, 'remote', 'add', 'origin', url])
|
|
366
|
+
await runGit(['-C', dest, 'fetch', '--depth', '1', '--progress', 'origin', gitRef], { onProgress: true })
|
|
367
|
+
await runGit(['-C', dest, 'checkout', '--detach', 'FETCH_HEAD'])
|
|
368
|
+
const { stdout: commit } = await runGit(['-C', dest, 'rev-parse', 'HEAD'])
|
|
369
|
+
if (commit.toLowerCase() !== gitRef.toLowerCase()) throw new Error(`固定版本校验失败:请求 ${gitRef},实际检出 ${commit}。`)
|
|
370
|
+
const cloneMs = Date.now() - startedAt
|
|
371
|
+
log(`固定版本安装完成:${commit}(${Math.round(cloneMs / 1000)}s)`)
|
|
372
|
+
return { cloneMs, commit }
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function rmRf(dir) {
|
|
376
|
+
try {
|
|
377
|
+
rmSync(dir, { recursive: true, force: true })
|
|
378
|
+
} catch (err) {
|
|
379
|
+
log(`rm ${dir} failed: ${err && err.message}`)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// .staging 只作为临时克隆区:清空后把父目录也删掉,避免每次安装留一个空目录
|
|
384
|
+
function cleanupStagingRoot() {
|
|
385
|
+
const root = join(roleSkillsRoot(), '.staging')
|
|
386
|
+
try {
|
|
387
|
+
if (existsSync(root) && readdirSync(root).length === 0) rmSync(root, { recursive: true, force: true })
|
|
388
|
+
} catch (err) {
|
|
389
|
+
log(`cleanup .staging failed: ${err && err.message}`)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// 扫描安装目录内的 SKILL.md(深度 ≤3,跳过 .git/node_modules/dist 等噪音)
|
|
394
|
+
const SCAN_SKIP = new Set(['.git', 'node_modules', 'dist', 'build', '__pycache__', '.github', '.vscode'])
|
|
395
|
+
function discoverSkills(installDir, maxDepth) {
|
|
396
|
+
const found = []
|
|
397
|
+
const walk = (dir, rel, depth) => {
|
|
398
|
+
if (depth > maxDepth || found.length >= 24) return
|
|
399
|
+
let entries
|
|
400
|
+
try {
|
|
401
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
402
|
+
// 固定排序:不同文件系统的枚举顺序不一致,INDEX.md 需要可复现
|
|
403
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
404
|
+
} catch {
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
for (const e of entries) {
|
|
408
|
+
if (SCAN_SKIP.has(e.name)) continue
|
|
409
|
+
const abs = join(dir, e.name)
|
|
410
|
+
const r = rel ? `${rel}/${e.name}` : e.name
|
|
411
|
+
if (e.isFile() && e.name === 'SKILL.md') {
|
|
412
|
+
found.push(parseSkillMd(abs, r))
|
|
413
|
+
} else if (e.isDirectory()) {
|
|
414
|
+
walk(abs, r, depth + 1)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
walk(installDir, '', 0)
|
|
419
|
+
return found
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function parseSkillMd(absPath, relPath) {
|
|
423
|
+
let name = basename(join(relPath, '..'))
|
|
424
|
+
let description = ''
|
|
425
|
+
try {
|
|
426
|
+
const text = readFileSync(absPath, 'utf8')
|
|
427
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)
|
|
428
|
+
if (fm) {
|
|
429
|
+
const nm = /^name:\s*(.+)$/m.exec(fm[1])
|
|
430
|
+
if (nm) name = nm[1].trim()
|
|
431
|
+
const dm = /^description:\s*(.+)$/m.exec(fm[1])
|
|
432
|
+
if (dm) description = dm[1].trim().replace(/^["']|["']$/g, '')
|
|
433
|
+
}
|
|
434
|
+
} catch {
|
|
435
|
+
/* 读取失败保留目录名 */
|
|
436
|
+
}
|
|
437
|
+
if (description.length > 200) description = `${description.slice(0, 197)}...`
|
|
438
|
+
return { name: name || relPath, description: description || '(SKILL.md 无 description)', relPath }
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function renderIndexMd(role, entries) {
|
|
442
|
+
const lines = [
|
|
443
|
+
`# ${role} 角色扩展技能库索引`,
|
|
444
|
+
'',
|
|
445
|
+
`> 由 dsh-science v${VERSION} 自动生成(${new Date().toISOString()})。`,
|
|
446
|
+
'> 使用方式:用读文件工具按「路径」读取 SKILL.md,再按需读取其引用的同目录资源文件。',
|
|
447
|
+
'> 本库只在 dsh-science 本插件内对本角色成员生效(不在 DSH 全局技能注册表)。',
|
|
448
|
+
'',
|
|
449
|
+
]
|
|
450
|
+
if (!entries.length) {
|
|
451
|
+
lines.push('(该角色当前没有已安装技能。)')
|
|
452
|
+
}
|
|
453
|
+
for (const entry of entries) {
|
|
454
|
+
const entryName = entry.name || '(未命名)'
|
|
455
|
+
const entryDir = typeof entry.dir === 'string' && entry.dir ? entry.dir : join(roleSkillsRoot(), role, entryName)
|
|
456
|
+
lines.push(`## ${entryName}`, '')
|
|
457
|
+
if (entry.warn) {
|
|
458
|
+
lines.push(`- ⚠ 状态:未发现 SKILL.md——该仓库不是标准 skill 结构,谨慎参考其内容。`)
|
|
459
|
+
}
|
|
460
|
+
for (const sk of Array.isArray(entry.skills) ? entry.skills : []) {
|
|
461
|
+
if (!sk || typeof sk !== 'object') continue
|
|
462
|
+
lines.push(`- **${sk.name}** — ${sk.description}`)
|
|
463
|
+
const skillPath = typeof sk.relPath === 'string' && sk.relPath ? join(entryDir, sk.relPath) : entryDir
|
|
464
|
+
lines.push(` - SKILL.md: ${skillPath}`)
|
|
465
|
+
}
|
|
466
|
+
lines.push(` - 来源: ${entry.repo || '(来源未知)'}${entry.subdir ? ` @ ${entry.subdir}` : ''}(${entry.license || 'license 未知'})`)
|
|
467
|
+
lines.push('')
|
|
468
|
+
}
|
|
469
|
+
return lines.join('\n')
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function writeIndexForRole(role, state) {
|
|
473
|
+
const entries = Array.isArray(state.roles[role]) ? state.roles[role] : []
|
|
474
|
+
const dir = join(roleSkillsRoot(), role)
|
|
475
|
+
mkdirSync(dir, { recursive: true })
|
|
476
|
+
writeFileSync(join(dir, 'INDEX.md'), renderIndexMd(role, entries), 'utf8')
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// 安装入口(互斥队列内执行)。catalogId 与 repoUrl 二选一。
|
|
480
|
+
// cloneImpl 仅用于测试注入(签名同 gitClone:(url, dest) => Promise<{cloneMs}>)。
|
|
481
|
+
export async function installSkill({ role, catalogId, repoUrl, name, exec, cloneImpl }) {
|
|
482
|
+
if (!ROLES[role]) {
|
|
483
|
+
return { ok: false, error: `未知角色 ${role}(可用:${Object.keys(ROLES).join(' | ')})` }
|
|
484
|
+
}
|
|
485
|
+
if (catalogId && repoUrl) {
|
|
486
|
+
return { ok: false, error: 'repo_id 与 repo_url 只能二选一:精选目录用 repo_id,自定义仓库用 repo_url' }
|
|
487
|
+
}
|
|
488
|
+
let wakeCtx = null
|
|
489
|
+
const out = await enqueue(async () => {
|
|
490
|
+
const state = loadState()
|
|
491
|
+
const roleEntries = Array.isArray(state.roles[role]) ? state.roles[role] : []
|
|
492
|
+
let repo = null
|
|
493
|
+
let subdir = ''
|
|
494
|
+
let installName = null
|
|
495
|
+
let license = null
|
|
496
|
+
let description = ''
|
|
497
|
+
let gitRef = null
|
|
498
|
+
if (catalogId) {
|
|
499
|
+
const item = (CATALOG[role] || []).find((x) => x.id === String(catalogId))
|
|
500
|
+
if (!item) {
|
|
501
|
+
const ids = (CATALOG[role] || []).map((x) => x.id).join(' | ') || '(该角色目录为空)'
|
|
502
|
+
return { ok: false, error: `目录中找不到 ${catalogId}(${role} 可选:${ids})` }
|
|
503
|
+
}
|
|
504
|
+
if (item.installable !== true || !item.gitRef) {
|
|
505
|
+
return { ok: false, error: `“${item.name}”尚无已核实的固定版本,当前不能从精选目录安装。` }
|
|
506
|
+
}
|
|
507
|
+
const v = validateRepoUrl(item.repo)
|
|
508
|
+
if (v.error) return { ok: false, error: v.error }
|
|
509
|
+
repo = v.repo
|
|
510
|
+
subdir = item.subdir || ''
|
|
511
|
+
installName = item.id
|
|
512
|
+
license = item.license
|
|
513
|
+
description = item.description
|
|
514
|
+
gitRef = item.gitRef
|
|
515
|
+
const exists = roleEntries.find((x) => x.name === installName)
|
|
516
|
+
if (exists) {
|
|
517
|
+
return { ok: false, error: `已安装:${installName}(${join(roleSkillsRoot(), role, installName)})。无需重复安装。` }
|
|
518
|
+
}
|
|
519
|
+
} else if (repoUrl) {
|
|
520
|
+
const v = validateRepoUrl(repoUrl)
|
|
521
|
+
if (v.error) return { ok: false, error: v.error }
|
|
522
|
+
repo = v.repo
|
|
523
|
+
if (name) {
|
|
524
|
+
const n = sanitizeName(name)
|
|
525
|
+
if (n.error) return { ok: false, error: `name 非法:${n.error}` }
|
|
526
|
+
installName = n.name
|
|
527
|
+
} else {
|
|
528
|
+
const n = sanitizeName(repo.split('/').pop())
|
|
529
|
+
if (n.error) return { ok: false, error: `无法从 URL 推导目录名(${repo}),请提供 name 参数` }
|
|
530
|
+
installName = n.name
|
|
531
|
+
}
|
|
532
|
+
license = null
|
|
533
|
+
description = `自定义安装(${repo})`
|
|
534
|
+
} else {
|
|
535
|
+
return { ok: false, error: '需要 repo_id(精选目录 id)或 repo_url(https github/gitlab 仓库)之一' }
|
|
536
|
+
}
|
|
537
|
+
const installDir = join(roleSkillsRoot(), role, installName)
|
|
538
|
+
if (existsSync(installDir)) {
|
|
539
|
+
return { ok: false, error: `已安装:${installName}(${installDir})。无需重复安装。` }
|
|
540
|
+
}
|
|
541
|
+
// 克隆到同分区 staging(保证 rename 原子性),再拷贝 subdir 内容到安装目录
|
|
542
|
+
const staging = join(roleSkillsRoot(), '.staging', `${installName}-${Date.now().toString(36)}`)
|
|
543
|
+
mkdirSync(staging, { recursive: true })
|
|
544
|
+
let cloneMs = null
|
|
545
|
+
let clonedCommit = null
|
|
546
|
+
try {
|
|
547
|
+
const r = await (typeof cloneImpl === 'function' ? cloneImpl : gitClone)(repo, staging, gitRef)
|
|
548
|
+
cloneMs = r && typeof r.cloneMs === 'number' ? r.cloneMs : null
|
|
549
|
+
clonedCommit = r && typeof r.commit === 'string' ? r.commit : null
|
|
550
|
+
let srcDir = staging
|
|
551
|
+
if (subdir) {
|
|
552
|
+
srcDir = resolve(join(staging, subdir))
|
|
553
|
+
const stagingReal = resolve(staging)
|
|
554
|
+
if (srcDir !== stagingReal && !srcDir.startsWith(stagingReal + sep)) {
|
|
555
|
+
return { ok: false, error: `subdir 非法(逃逸仓库根):${subdir}` }
|
|
556
|
+
}
|
|
557
|
+
if (!existsSync(srcDir)) {
|
|
558
|
+
return { ok: false, error: `仓库内不存在子目录 ${subdir}(请核对 ${repo} 的目录结构)` }
|
|
559
|
+
}
|
|
560
|
+
// 符号链接/目录联接可指向仓库外:realpath 后必须仍在 staging 内
|
|
561
|
+
let srcReal
|
|
562
|
+
try {
|
|
563
|
+
srcReal = realpathSync(srcDir)
|
|
564
|
+
const stagingCanon = realpathSync(staging)
|
|
565
|
+
// Windows 路径大小写不敏感;其它平台按原样比较,避免放宽边界
|
|
566
|
+
const fold = (p) => (process.platform === 'win32' ? p.toLowerCase() : p)
|
|
567
|
+
const rootReal = fold(stagingCanon)
|
|
568
|
+
const targetReal = fold(srcReal)
|
|
569
|
+
if (targetReal !== rootReal && !targetReal.startsWith(rootReal + sep)) {
|
|
570
|
+
return { ok: false, error: `subdir 是符号链接且指向仓库外,拒绝安装:${subdir}` }
|
|
571
|
+
}
|
|
572
|
+
} catch (err) {
|
|
573
|
+
return { ok: false, error: `无法解析子目录 ${subdir}:${err && err.message}` }
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
mkdirSync(installDir, { recursive: true })
|
|
577
|
+
cpSync(srcDir, installDir, {
|
|
578
|
+
recursive: true,
|
|
579
|
+
filter: (src) => {
|
|
580
|
+
if (basename(src) === '.git' || src.includes(`${sep}.git${sep}`)) return false
|
|
581
|
+
// 跳过符号链接:避免把仓库指向本机任意路径的链接带进技能目录
|
|
582
|
+
try {
|
|
583
|
+
return !lstatSync(src).isSymbolicLink()
|
|
584
|
+
} catch {
|
|
585
|
+
return false
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
})
|
|
589
|
+
} catch (err) {
|
|
590
|
+
rmRf(staging)
|
|
591
|
+
rmRf(installDir)
|
|
592
|
+
return { ok: false, error: String(err && err.message) }
|
|
593
|
+
} finally {
|
|
594
|
+
rmRf(staging)
|
|
595
|
+
cleanupStagingRoot()
|
|
596
|
+
}
|
|
597
|
+
// 结构发现:SKILL.md 扫描(子目录聚合仓库可发现多个技能)
|
|
598
|
+
const skills = discoverSkills(installDir, 3)
|
|
599
|
+
const entry = {
|
|
600
|
+
name: installName,
|
|
601
|
+
catalogId: catalogId ? String(catalogId) : null,
|
|
602
|
+
repo,
|
|
603
|
+
subdir: subdir || null,
|
|
604
|
+
license,
|
|
605
|
+
description,
|
|
606
|
+
gitRef: gitRef || clonedCommit,
|
|
607
|
+
installedAt: Date.now(),
|
|
608
|
+
dir: installDir,
|
|
609
|
+
// warn:整仓未发现任何 SKILL.md(非标准 skill 仓库)
|
|
610
|
+
warn: skills.length === 0,
|
|
611
|
+
skills: skills.length > 0 ? skills : [{ name: installName, description: '(未发现 SKILL.md——非标准 skill 结构,INDEX 中仅登记路径)', relPath: '.' }],
|
|
612
|
+
}
|
|
613
|
+
state.roles[role] = [...roleEntries.filter((x) => x.name !== installName), entry]
|
|
614
|
+
const stateText = saveState(state)
|
|
615
|
+
try {
|
|
616
|
+
writeIndexForRole(role, state)
|
|
617
|
+
} catch (err) {
|
|
618
|
+
log(`INDEX.md write failed: ${err && err.message}`)
|
|
619
|
+
}
|
|
620
|
+
mirrorState(exec, stateText)
|
|
621
|
+
log(`skill installed: ${role}/${installName} (${repo}${subdir ? ` @ ${subdir}` : ''}, ${entry.skills.length} skill(s)${entry.warn ? ', WARN no SKILL.md' : ''})`)
|
|
622
|
+
const out = {
|
|
623
|
+
ok: true,
|
|
624
|
+
role,
|
|
625
|
+
name: installName,
|
|
626
|
+
dir: installDir,
|
|
627
|
+
cloneMs,
|
|
628
|
+
indexMd: join(roleSkillsRoot(), role, 'INDEX.md'),
|
|
629
|
+
skills: entry.skills.filter((s) => s && typeof s === 'object').map((s) => ({ name: s.name, description: s.description, path: s.relPath === '.' ? installDir : join(installDir, s.relPath) })),
|
|
630
|
+
warn: entry.warn,
|
|
631
|
+
note: entry.warn
|
|
632
|
+
? '该仓库未发现 SKILL.md(非标准 skill 结构),已登记但标记 warn。'
|
|
633
|
+
: `已写入 INDEX.md。若相关成员已 spawn,用 sci_team_send 告知其新技能路径(成员提示词含新技能通知规则)。`,
|
|
634
|
+
}
|
|
635
|
+
wakeCtx = { role, entry }
|
|
636
|
+
return out
|
|
637
|
+
})
|
|
638
|
+
// 自动唤醒(brief 待办 8):放在互斥队列外,sendMessage 较慢时不阻塞其它安装/删除。
|
|
639
|
+
if (out && out.ok && wakeCtx && typeof memberWakeHook === 'function' && exec && exec.agent) {
|
|
640
|
+
try {
|
|
641
|
+
const wr = await memberWakeHook(exec.agent, wakeCtx.role, wakeCtx.entry)
|
|
642
|
+
out.wake = {
|
|
643
|
+
attempted: true,
|
|
644
|
+
targets: Number.isFinite(wr && wr.targets) ? wr.targets : 0,
|
|
645
|
+
woken: Array.isArray(wr && wr.woken) ? wr.woken : [],
|
|
646
|
+
failed: Array.isArray(wr && wr.failed) ? wr.failed : [],
|
|
647
|
+
}
|
|
648
|
+
if (out.wake.woken.length > 0) {
|
|
649
|
+
out.note = `已写入 INDEX.md,并已自动通知 ${out.wake.woken.length} 名已 spawn 的 ${wakeCtx.role} 成员读取新技能(无需再手动 sci_team_send)。`
|
|
650
|
+
}
|
|
651
|
+
} catch (err) {
|
|
652
|
+
log(`member auto-wake failed: ${err && err.message}`)
|
|
653
|
+
out.wake = { attempted: true, targets: 0, woken: [], failed: [{ name: null, error: String(err && err.message) }] }
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return out
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// 删除入口(互斥队列内执行)
|
|
660
|
+
export async function removeSkill({ role, name, exec }) {
|
|
661
|
+
if (!ROLES[role]) {
|
|
662
|
+
return { ok: false, error: `未知角色 ${role}` }
|
|
663
|
+
}
|
|
664
|
+
const n = sanitizeName(name)
|
|
665
|
+
if (n.error) return { ok: false, error: `name 非法:${n.error}` }
|
|
666
|
+
return enqueue(async () => {
|
|
667
|
+
const state = loadState()
|
|
668
|
+
const roleEntries = Array.isArray(state.roles[role]) ? state.roles[role] : []
|
|
669
|
+
const entry = roleEntries.find((x) => x.name === n.name)
|
|
670
|
+
if (!entry) {
|
|
671
|
+
const names = roleEntries.map((x) => x.name).join(' | ') || '(无)'
|
|
672
|
+
return { ok: false, error: `未安装:${n.name}(${role} 当前已安装:${names})` }
|
|
673
|
+
}
|
|
674
|
+
rmRf(join(roleSkillsRoot(), role, n.name))
|
|
675
|
+
state.roles[role] = roleEntries.filter((x) => x.name !== n.name)
|
|
676
|
+
if (state.roles[role].length === 0) delete state.roles[role]
|
|
677
|
+
const stateText = saveState(state)
|
|
678
|
+
try {
|
|
679
|
+
writeIndexForRole(role, state)
|
|
680
|
+
} catch (err) {
|
|
681
|
+
log(`INDEX.md rewrite after remove failed: ${err && err.message}`)
|
|
682
|
+
}
|
|
683
|
+
mirrorState(exec, stateText)
|
|
684
|
+
log(`skill removed: ${role}/${n.name}`)
|
|
685
|
+
return { ok: true, role, name: n.name, indexMd: join(roleSkillsRoot(), role, 'INDEX.md') }
|
|
686
|
+
})
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// 工作区镜像(与 team/blueprint 同款 makeMirror 通道)
|
|
690
|
+
function mirrorState(exec, text) {
|
|
691
|
+
try {
|
|
692
|
+
const fn = exec && exec.__sciSkillMirror
|
|
693
|
+
if (typeof fn === 'function') fn('role-skills.json', text, exec)
|
|
694
|
+
} catch {
|
|
695
|
+
/* 镜像失败不影响主流程 */
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const OPTIONAL_INTEGRATIONS = Object.freeze([
|
|
700
|
+
Object.freeze({
|
|
701
|
+
id: 'builtin-figure-workflow',
|
|
702
|
+
role: 'figure-expert',
|
|
703
|
+
name: '内置科研绘图工作流',
|
|
704
|
+
kind: 'builtin-skill',
|
|
705
|
+
status: '已随插件提供;运行时绘图依赖未探测',
|
|
706
|
+
tone: 'good',
|
|
707
|
+
environment: '包含绘图计划、图件登记与检查流程;实际绘图软件和包依所选方法而定。',
|
|
708
|
+
sourcePath: 'skills/sci-figures/SKILL.md',
|
|
709
|
+
actionLabel: '技能说明随插件提供;当前工作台不提供文件打开入口。',
|
|
710
|
+
description: '本插件内置的绘图流程说明,不代表已安装 Matplotlib、R 或其他绘图运行环境。',
|
|
711
|
+
}),
|
|
712
|
+
Object.freeze({
|
|
713
|
+
id: 'scientific-figure-library',
|
|
714
|
+
role: 'figure-expert',
|
|
715
|
+
name: 'Scientific Figure Library(模板库)',
|
|
716
|
+
kind: 'dsh-plugin',
|
|
717
|
+
status: '可选独立插件;当前安装状态未探测',
|
|
718
|
+
tone: 'warn',
|
|
719
|
+
environment: '独立 DSH 插件;需按其仓库说明满足运行环境要求。',
|
|
720
|
+
repo: 'https://github.com/xuzhougeng/ScientificFigureLibrary',
|
|
721
|
+
actionUrl: 'https://github.com/xuzhougeng/ScientificFigureLibrary',
|
|
722
|
+
actionLabel: '查看仓库',
|
|
723
|
+
installCommand: 'dsh plugin --profile web add scientific-figure-library',
|
|
724
|
+
description: '本地优先的科研图件模板库:精确预览、版本/来源/许可记录与确认后复制;不执行绘图代码。安装后需重启 web profile。',
|
|
725
|
+
license: '代码 MIT;FigureYa/Community/用户模板逐项核权',
|
|
726
|
+
}),
|
|
727
|
+
Object.freeze({
|
|
728
|
+
id: 'biorender',
|
|
729
|
+
role: 'figure-expert',
|
|
730
|
+
name: 'BioRender',
|
|
731
|
+
kind: 'external-service',
|
|
732
|
+
status: '未连接;此插件不自动安装或授权',
|
|
733
|
+
tone: 'warn',
|
|
734
|
+
environment: '需要外部账号与网络;当前工作台未接入 BioRender 连接器。',
|
|
735
|
+
sourceUrl: 'https://www.biorender.com/',
|
|
736
|
+
actionUrl: 'https://www.biorender.com/',
|
|
737
|
+
actionLabel: '打开官网',
|
|
738
|
+
license: '专有内容;发表许可按账户计划、导出许可和出版用途核对。',
|
|
739
|
+
description: '外部商业绘图服务;本插件不打包其图标、模板或账号授权。',
|
|
740
|
+
}),
|
|
741
|
+
Object.freeze({
|
|
742
|
+
id: 'remote-model-apis',
|
|
743
|
+
role: 'trainer',
|
|
744
|
+
name: '网络模型 API',
|
|
745
|
+
kind: 'external-service',
|
|
746
|
+
status: '未配置;此插件不自动连接',
|
|
747
|
+
tone: 'warn',
|
|
748
|
+
environment: '需要目标服务、网络与独立凭据;当前工作台没有配置远程模型 API。',
|
|
749
|
+
sourcePath: 'docs/research/2026-11-12-生物科研能力与工作台集成调研.md',
|
|
750
|
+
actionLabel: '当前未配置连接器;使用前需人工核对服务来源与数据外传边界。',
|
|
751
|
+
description: '发送序列、结构、提示词或图像前,应先核对服务条款和数据外传授权。',
|
|
752
|
+
}),
|
|
753
|
+
])
|
|
754
|
+
|
|
755
|
+
// 供 httpdata /state 快照使用(客户端技能库面板数据)
|
|
756
|
+
export function skillMenuSnapshot() {
|
|
757
|
+
const state = loadState()
|
|
758
|
+
const catalog = Object.fromEntries(
|
|
759
|
+
Object.entries(CATALOG).map(([role, items]) => [
|
|
760
|
+
role,
|
|
761
|
+
items.map((x) => ({
|
|
762
|
+
id: x.id,
|
|
763
|
+
name: x.name,
|
|
764
|
+
repo: x.repo || '',
|
|
765
|
+
description: x.description,
|
|
766
|
+
license: x.license,
|
|
767
|
+
subdir: x.subdir || null,
|
|
768
|
+
gitRef: x.gitRef || null,
|
|
769
|
+
installable: x.installable === true,
|
|
770
|
+
hasSkillMd: x.hasSkillMd === true,
|
|
771
|
+
environment: x.environment || '',
|
|
772
|
+
risk: x.risk || '',
|
|
773
|
+
})),
|
|
774
|
+
]),
|
|
775
|
+
)
|
|
776
|
+
const installed = Object.fromEntries(
|
|
777
|
+
Object.entries(state.roles).map(([role, entries]) => [
|
|
778
|
+
role,
|
|
779
|
+
(Array.isArray(entries) ? entries : []).map((x) => ({
|
|
780
|
+
name: x.name,
|
|
781
|
+
catalogId: x.catalogId || null,
|
|
782
|
+
repo: x.repo || '',
|
|
783
|
+
subdir: x.subdir || null,
|
|
784
|
+
license: x.license || '',
|
|
785
|
+
description: x.description || '',
|
|
786
|
+
gitRef: x.gitRef || null,
|
|
787
|
+
dir: x.dir || '',
|
|
788
|
+
hasSkillMd: x.warn !== true && (Array.isArray(x.skills) ? x.skills : []).some((skill) => skill && typeof skill.relPath === 'string'),
|
|
789
|
+
skillMdPaths: (Array.isArray(x.skills) ? x.skills : []).filter((skill) => skill && typeof skill === 'object' && typeof skill.relPath === 'string' && skill.relPath !== '.').map((skill) => join(x.dir || '', skill.relPath)),
|
|
790
|
+
warn: x.warn === true,
|
|
791
|
+
skillNames: (Array.isArray(x.skills) ? x.skills : []).map((s) => s && s.name).filter(Boolean),
|
|
792
|
+
})),
|
|
793
|
+
]),
|
|
794
|
+
)
|
|
795
|
+
return { catalog, installed, integrations: OPTIONAL_INTEGRATIONS.map((x) => ({ ...x })) }
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// spawnMember 集成用:成员提示词的「扩展技能库」段(该角色已安装技能索引)。
|
|
799
|
+
// 无已安装技能时返回 ''(提示词保持精简)。隔离关键:只有对应角色拿到该目录索引。
|
|
800
|
+
export function roleSkillSectionText(role) {
|
|
801
|
+
const state = loadState()
|
|
802
|
+
const entries = Array.isArray(state.roles[role]) ? state.roles[role] : []
|
|
803
|
+
const lines = [
|
|
804
|
+
'## 扩展技能库(dsh-science 角色技能,仅你可用)',
|
|
805
|
+
`用户为本角色安装了以下开源技能(位于 ${roleSkillsRoot()}/${role}/,不在 DSH 全局技能注册表——只属于本插件本角色):`,
|
|
806
|
+
`- 技能索引(含每个技能的一句话与 SKILL.md 绝对路径):${join(roleSkillsRoot(), role, 'INDEX.md')}`,
|
|
807
|
+
'- 使用方式:需要时先读索引,再按路径读取对应 SKILL.md 与其引用的资源文件;技能内容与你的角色铁律冲突时,以角色铁律为准。',
|
|
808
|
+
'- 新技能通知:若队长消息告知某路径新增了技能(含 SKILL.md 路径),直接读取该 SKILL.md 后即可使用,无需等待重启。',
|
|
809
|
+
]
|
|
810
|
+
if (entries.length > 0) {
|
|
811
|
+
lines.push(
|
|
812
|
+
'- 当前已安装:',
|
|
813
|
+
...entries.map((e) => ` - ${e.name}(${(Array.isArray(e.skills) ? e.skills : []).map((s) => s && s.name).filter(Boolean).join('、') || '无 SKILL.md'})`),
|
|
814
|
+
)
|
|
815
|
+
return `\n\n${lines.join('\n')}`
|
|
816
|
+
}
|
|
817
|
+
return ''
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// 通用计算模拟规范(simulator 专属):新工具 8 步上手规范的绝对路径注入。
|
|
821
|
+
// 规范正文在插件 bundled skill(skills/sci-simulation/references/universal-tool-onboarding.md),
|
|
822
|
+
// spawn 时把绝对路径告诉成员(成员用读文件工具可达插件目录)。
|
|
823
|
+
export function universalOnboardingText(role) {
|
|
824
|
+
if (role !== 'simulator') return ''
|
|
825
|
+
const abs = join(PKG_ROOT_OF(), 'skills', 'sci-simulation', 'references', 'universal-tool-onboarding.md')
|
|
826
|
+
return [
|
|
827
|
+
'',
|
|
828
|
+
'## 通用计算模拟规范(新工具上手铁律)',
|
|
829
|
+
`遇到本角色未内置 dossier 的新工具/新模型时,必须先按「新工具上手 8 步规范」执行(版本核验→手册章节→最小模板→冒烟→见证→生产→诊断→登记 dossier),规范全文用读文件工具读取:`,
|
|
830
|
+
abs,
|
|
831
|
+
'(内置 5 个 dossier 见插件 skills/sci-simulation/references/tool-dossiers/;未内置的工具一律走 8 步规范,不许凭记忆直接写输入文件。)',
|
|
832
|
+
].join('\n')
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// ---- 工具注册 ----------------------------------------------------------------
|
|
836
|
+
function toolRender() {
|
|
837
|
+
return {
|
|
838
|
+
schema: { type: 'object' },
|
|
839
|
+
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }],
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
export function registerSkillMenuTools(ctx, opts = {}) {
|
|
844
|
+
const mirror = opts.mirror
|
|
845
|
+
// M2(M2 安全审查):安装=引入外部指令内容进成员提示词(提示注入供应链)——
|
|
846
|
+
// 每次安装先经宿主审批卡向用户展示来源;删除不拦截(反向操作)。
|
|
847
|
+
try {
|
|
848
|
+
if (typeof ctx.on === 'function') {
|
|
849
|
+
ctx.on('tools/pre-execute', async (toolExec, next) => {
|
|
850
|
+
if (!toolExec || toolExec.name !== 'sci_skill_install') return next()
|
|
851
|
+
const args = toolExec.arguments || {}
|
|
852
|
+
const source = args.repo_id ? `精选目录 ${args.repo_id}` : (args.repo_url || '自定义仓库')
|
|
853
|
+
const prompt = `请确认是否为角色「${args.role || '?'}」安装技能来源:${source}。安装后该仓库的 SKILL.md 会进入对应成员的提示词索引。`
|
|
854
|
+
return {
|
|
855
|
+
kind: 'ask',
|
|
856
|
+
reason: `dsh-science requires user approval before installing role skill from ${source}.`,
|
|
857
|
+
displayReason: { en: `Confirm installing a role skill from ${source}.`, zh: prompt, 'zh-CN': prompt },
|
|
858
|
+
}
|
|
859
|
+
})
|
|
860
|
+
}
|
|
861
|
+
} catch (err) {
|
|
862
|
+
log(`skill install pre-execute gate failed: ${err && err.message}`)
|
|
863
|
+
}
|
|
864
|
+
// makeMirror 的签名是 (name, text, exec);skillmenu 内部 mirrorState 约定读 exec.__sciSkillMirror。
|
|
865
|
+
// 这里把 mirror 挂到全局单例(插件级唯一,与其它模块 opts.mirror 注入方式等价)。
|
|
866
|
+
if (typeof mirror === 'function') {
|
|
867
|
+
mirrorHook = mirror
|
|
868
|
+
}
|
|
869
|
+
ctx.tools.register({
|
|
870
|
+
name: 'sci_skill_menu',
|
|
871
|
+
description:
|
|
872
|
+
'查看某角色的精选技能目录与已安装技能(role-scoped skill menu)。role 可选:' +
|
|
873
|
+
Object.keys(ROLES).join(' | ') +
|
|
874
|
+
'。返回目录项(id/名称/仓库/许可)与各自安装状态。',
|
|
875
|
+
parameters: {
|
|
876
|
+
role: { type: 'string', description: `角色 id(必填):${Object.keys(ROLES).join(' | ')}` },
|
|
877
|
+
},
|
|
878
|
+
output: toolRender(),
|
|
879
|
+
async execute(args) {
|
|
880
|
+
const role = String(args.role || '')
|
|
881
|
+
if (!ROLES[role]) {
|
|
882
|
+
return { ok: false, error: `未知角色 ${role}(可用:${Object.keys(ROLES).join(' | ')})` }
|
|
883
|
+
}
|
|
884
|
+
const state = loadState()
|
|
885
|
+
const installedEntries = Array.isArray(state.roles[role]) ? state.roles[role] : []
|
|
886
|
+
const items = (CATALOG[role] || []).map((x) => {
|
|
887
|
+
const inst = installedEntries.find((e) => e.catalogId === x.id || e.name === x.id)
|
|
888
|
+
return {
|
|
889
|
+
id: x.id,
|
|
890
|
+
name: x.name,
|
|
891
|
+
repo: x.repo,
|
|
892
|
+
subdir: x.subdir || null,
|
|
893
|
+
license: x.license,
|
|
894
|
+
summary: x.description,
|
|
895
|
+
gitRef: x.gitRef || null,
|
|
896
|
+
installable: x.installable === true,
|
|
897
|
+
installed: !!inst,
|
|
898
|
+
installName: inst ? inst.name : null,
|
|
899
|
+
}
|
|
900
|
+
})
|
|
901
|
+
const custom = installedEntries.filter((e) => !e.catalogId).map((e) => ({ name: e.name, repo: e.repo, installedAt: e.installedAt || 0, warn: e.warn === true }))
|
|
902
|
+
return {
|
|
903
|
+
ok: true,
|
|
904
|
+
role,
|
|
905
|
+
roleLabel: ROLES[role].label,
|
|
906
|
+
catalog: items,
|
|
907
|
+
customInstalled: custom,
|
|
908
|
+
installedCount: installedEntries.length,
|
|
909
|
+
indexMd: join(roleSkillsRoot(), role, 'INDEX.md'),
|
|
910
|
+
installHint: 'sci_skill_install(role, repo_id) 安装精选目录项;或 sci_skill_install(role, repo_url=..., name=...) 安装自定义仓库(https github/gitlab)。',
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
})
|
|
914
|
+
log('tool sci_skill_menu registered')
|
|
915
|
+
|
|
916
|
+
ctx.tools.register({
|
|
917
|
+
name: 'sci_skill_install',
|
|
918
|
+
description:
|
|
919
|
+
'为本角色安装一个开源 skill 仓库(git clone --depth 1 到 dsh-science/role-skills/<role>/<name>/,生成 INDEX.md,只在 dsh-science 内对该角色成员生效)。两种用法:① repo_id=精选目录 id(先 sci_skill_menu 查看);② repo_url=https://github.com/<owner>/<repo>(可加 name 指定目录名)。已安装会报「已安装」。',
|
|
920
|
+
parameters: {
|
|
921
|
+
role: { type: 'string', description: `角色 id(必填):${Object.keys(ROLES).join(' | ')}` },
|
|
922
|
+
repo_id: { type: 'string', description: '精选目录项 id(见 sci_skill_menu;与 repo_url 二选一)' },
|
|
923
|
+
repo_url: { type: 'string', description: '自定义仓库 URL(https github/gitlab,形如 https://github.com/owner/repo;与 repo_id 二选一)' },
|
|
924
|
+
name: { type: 'string', description: '安装目录名(仅 repo_url 时可选;缺省用仓库名)' },
|
|
925
|
+
},
|
|
926
|
+
output: toolRender(),
|
|
927
|
+
async execute(args, exec) {
|
|
928
|
+
const result = await installSkill({
|
|
929
|
+
role: String(args.role || ''),
|
|
930
|
+
catalogId: args.repo_id ? String(args.repo_id) : null,
|
|
931
|
+
repoUrl: args.repo_url ? String(args.repo_url) : null,
|
|
932
|
+
name: args.name ? String(args.name) : null,
|
|
933
|
+
exec: { ...exec, __sciSkillMirror: mirrorHook },
|
|
934
|
+
})
|
|
935
|
+
if (!result.ok) throw new Error(result.error || '安装失败')
|
|
936
|
+
return result
|
|
937
|
+
},
|
|
938
|
+
})
|
|
939
|
+
log('tool sci_skill_install registered')
|
|
940
|
+
|
|
941
|
+
ctx.tools.register({
|
|
942
|
+
name: 'sci_skill_remove',
|
|
943
|
+
description: '删除本角色已安装的技能(删目录 + 更新 INDEX.md)。name 为安装目录名(见 sci_skill_installed)。',
|
|
944
|
+
parameters: {
|
|
945
|
+
role: { type: 'string', description: `角色 id(必填):${Object.keys(ROLES).join(' | ')}` },
|
|
946
|
+
name: { type: 'string', description: '已安装技能目录名(必填)' },
|
|
947
|
+
},
|
|
948
|
+
output: toolRender(),
|
|
949
|
+
async execute(args, exec) {
|
|
950
|
+
const result = await removeSkill({ role: String(args.role || ''), name: String(args.name || ''), exec: { ...exec, __sciSkillMirror: mirrorHook } })
|
|
951
|
+
if (!result.ok) throw new Error(result.error || '删除失败')
|
|
952
|
+
return result
|
|
953
|
+
},
|
|
954
|
+
})
|
|
955
|
+
log('tool sci_skill_remove registered')
|
|
956
|
+
|
|
957
|
+
ctx.tools.register({
|
|
958
|
+
name: 'sci_skill_installed',
|
|
959
|
+
description: '列出某角色已安装的扩展技能(目录名/来源/SKILL.md 清单)与 INDEX.md 路径。',
|
|
960
|
+
parameters: {
|
|
961
|
+
role: { type: 'string', description: `角色 id(必填):${Object.keys(ROLES).join(' | ')}` },
|
|
962
|
+
},
|
|
963
|
+
output: toolRender(),
|
|
964
|
+
async execute(args) {
|
|
965
|
+
const role = String(args.role || '')
|
|
966
|
+
if (!ROLES[role]) {
|
|
967
|
+
return { ok: false, error: `未知角色 ${role}(可用:${Object.keys(ROLES).join(' | ')})` }
|
|
968
|
+
}
|
|
969
|
+
const state = loadState()
|
|
970
|
+
const entries = Array.isArray(state.roles[role]) ? state.roles[role] : []
|
|
971
|
+
return {
|
|
972
|
+
ok: true,
|
|
973
|
+
role,
|
|
974
|
+
indexMd: join(roleSkillsRoot(), role, 'INDEX.md'),
|
|
975
|
+
count: entries.length,
|
|
976
|
+
installed: entries.map((e) => ({
|
|
977
|
+
name: e.name,
|
|
978
|
+
repo: e.repo,
|
|
979
|
+
subdir: e.subdir || null,
|
|
980
|
+
catalogId: e.catalogId || null,
|
|
981
|
+
license: e.license || null,
|
|
982
|
+
installedAt: e.installedAt || 0,
|
|
983
|
+
warn: e.warn === true,
|
|
984
|
+
skills: (Array.isArray(e.skills) ? e.skills : []).filter((s) => s && typeof s === 'object').map((s) => ({ name: s.name, description: s.description, path: s.relPath === '.' ? join(roleSkillsRoot(), role, e.name) : join(roleSkillsRoot(), role, e.name, s.relPath) })),
|
|
985
|
+
})),
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
})
|
|
989
|
+
log('tool sci_skill_installed registered')
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// 模块级 mirror 单例(由 registerSkillMenuTools 注入;与 makeMirror 同签名)
|
|
993
|
+
let mirrorHook = null
|