my-dsh-skill-hub 0.2.0 → 0.3.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/client.js +22 -7
- package/host.js +81 -21
- package/package.json +4 -2
package/client.js
CHANGED
|
@@ -34,7 +34,7 @@ window.__ModuleLoader__.load({
|
|
|
34
34
|
* Visible build marker. A browser keeps the bundle it already loaded, so the
|
|
35
35
|
* page states which build it runs: bump this whenever the Client half changes.
|
|
36
36
|
*/
|
|
37
|
-
const UI_REVISION = '2026-11-
|
|
37
|
+
const UI_REVISION = '2026-11-18.2'
|
|
38
38
|
|
|
39
39
|
const zh = {
|
|
40
40
|
panel: '技能',
|
|
@@ -514,6 +514,14 @@ window.__ModuleLoader__.load({
|
|
|
514
514
|
),
|
|
515
515
|
h('p', { className: 'sh-item-desc' }, entry.description),
|
|
516
516
|
h('div', { className: 'sh-item-meta' }, tr('builtin.source', { provider: entry.provider })),
|
|
517
|
+
h('div', { className: 'sh-item-foot' },
|
|
518
|
+
h('button', {
|
|
519
|
+
type: 'button',
|
|
520
|
+
className: 'sh-btn sh-btn-link',
|
|
521
|
+
disabled: busy,
|
|
522
|
+
onClick: () => props.onPreview(entry.name),
|
|
523
|
+
}, tr('actions.preview')),
|
|
524
|
+
),
|
|
517
525
|
)
|
|
518
526
|
}
|
|
519
527
|
|
|
@@ -539,6 +547,8 @@ window.__ModuleLoader__.load({
|
|
|
539
547
|
const [previewPath, setPreviewPath] = React.useState('')
|
|
540
548
|
const [previewDoc, setPreviewDoc] = React.useState(null)
|
|
541
549
|
const [previewLoading, setPreviewLoading] = React.useState(false)
|
|
550
|
+
const [previewBuiltin, setPreviewBuiltin] = React.useState(false)
|
|
551
|
+
const [previewPresetId, setPreviewPresetId] = React.useState(null)
|
|
542
552
|
const [collapsedDirs, setCollapsedDirs] = React.useState(() => new Set())
|
|
543
553
|
const [confirming, setConfirming] = React.useState(null)
|
|
544
554
|
const [dragging, setDragging] = React.useState(false)
|
|
@@ -726,11 +736,11 @@ window.__ModuleLoader__.load({
|
|
|
726
736
|
}
|
|
727
737
|
|
|
728
738
|
/** 读技能包里的某个文件并显示。 */
|
|
729
|
-
const openSkillFile = async (name, path) => {
|
|
739
|
+
const openSkillFile = async (name, path, builtin = false, preset = null) => {
|
|
730
740
|
setPreviewLoading(true)
|
|
731
741
|
setPreviewPath(path)
|
|
732
742
|
try {
|
|
733
|
-
const value = await requestRef.current('file', { name, path })
|
|
743
|
+
const value = await requestRef.current('file', { name, path, builtin, presetId: preset })
|
|
734
744
|
setPreviewDoc(value)
|
|
735
745
|
} catch (error) {
|
|
736
746
|
setNotice({ kind: 'error', text: localizedError(tr, error) })
|
|
@@ -741,21 +751,23 @@ window.__ModuleLoader__.load({
|
|
|
741
751
|
}
|
|
742
752
|
|
|
743
753
|
/** 打开预览弹窗:先取文件树,默认打开 SKILL.md(没有就打开第一个文本文件)。 */
|
|
744
|
-
const openPreview = async (name) => {
|
|
754
|
+
const openPreview = async (name, builtin = false) => {
|
|
745
755
|
void ensureMarked(requestRef.current)
|
|
746
756
|
setBusy(`read:${name}`)
|
|
747
757
|
setPreviewSkill(name)
|
|
758
|
+
setPreviewBuiltin(builtin)
|
|
759
|
+
setPreviewPresetId(builtin ? presetId : null)
|
|
748
760
|
setPreviewTree(null)
|
|
749
761
|
setPreviewDoc(null)
|
|
750
762
|
setCollapsedDirs(new Set())
|
|
751
763
|
try {
|
|
752
|
-
const tree = await requestRef.current('files', { name })
|
|
764
|
+
const tree = await requestRef.current('files', { name, builtin, presetId: builtin ? presetId : null })
|
|
753
765
|
setPreviewTree(tree)
|
|
754
766
|
const nodes = Array.isArray(tree?.nodes) ? tree.nodes : []
|
|
755
767
|
const preferred = nodes.find(node => !node.dir && /^SKILL\.md$/i.test(node.name))
|
|
756
768
|
?? nodes.find(node => !node.dir && /\.(md|markdown|txt)$/i.test(node.name))
|
|
757
769
|
?? nodes.find(node => !node.dir)
|
|
758
|
-
if (preferred !== undefined) void openSkillFile(name, preferred.path)
|
|
770
|
+
if (preferred !== undefined) void openSkillFile(name, preferred.path, builtin, builtin ? presetId : null)
|
|
759
771
|
} catch (error) {
|
|
760
772
|
setNotice({ kind: 'error', text: localizedError(tr, error) })
|
|
761
773
|
} finally {
|
|
@@ -765,6 +777,8 @@ window.__ModuleLoader__.load({
|
|
|
765
777
|
|
|
766
778
|
const closePreview = () => {
|
|
767
779
|
setPreviewSkill(null)
|
|
780
|
+
setPreviewBuiltin(false)
|
|
781
|
+
setPreviewPresetId(null)
|
|
768
782
|
setPreviewTree(null)
|
|
769
783
|
setPreviewDoc(null)
|
|
770
784
|
setPreviewPath('')
|
|
@@ -966,6 +980,7 @@ window.__ModuleLoader__.load({
|
|
|
966
980
|
tr,
|
|
967
981
|
canAuthorize: presetId !== null && builtinControlsReady,
|
|
968
982
|
onToggle: toggleBuiltin,
|
|
983
|
+
onPreview: (name) => { void openPreview(name, true) },
|
|
969
984
|
}))),
|
|
970
985
|
),
|
|
971
986
|
h('p', { className: 'sh-foot' }, tr('foot.poolDir'), ' ', h('code', null, snapshot?.poolDir ?? '')),
|
|
@@ -988,7 +1003,7 @@ window.__ModuleLoader__.load({
|
|
|
988
1003
|
return next
|
|
989
1004
|
})
|
|
990
1005
|
},
|
|
991
|
-
onPick: (filePath) => { void openSkillFile(previewSkill, filePath) },
|
|
1006
|
+
onPick: (filePath) => { void openSkillFile(previewSkill, filePath, previewBuiltin, previewPresetId) },
|
|
992
1007
|
onClose: closePreview,
|
|
993
1008
|
renderDoc: (text) => (/\.(md|markdown)$/i.test(previewPath)
|
|
994
1009
|
? h('div', { className: 'sh-md', dangerouslySetInnerHTML: { __html: renderMarkdownHtml(text) } })
|
package/host.js
CHANGED
|
@@ -35,7 +35,7 @@ const HTTP_PATH = '/api/skill-hub'
|
|
|
35
35
|
* Host build marker, reported in the page snapshot. A running Harness keeps its
|
|
36
36
|
* loaded modules, so this states which Host half the page is talking to.
|
|
37
37
|
*/
|
|
38
|
-
const HOST_REVISION = '2026-11-
|
|
38
|
+
const HOST_REVISION = '2026-11-18.2'
|
|
39
39
|
/** Provider name registered in every Agent's scope layer. */
|
|
40
40
|
const PROVIDER_NAME = 'skill-hub'
|
|
41
41
|
/** Source label of a pool skill in the registry. */
|
|
@@ -508,8 +508,8 @@ class SkillHub {
|
|
|
508
508
|
case 'remove': return { ok: true, value: this.remove(asRecord(payload)) }
|
|
509
509
|
case 'authorize': return { ok: true, value: this.authorize(asRecord(payload)) }
|
|
510
510
|
case 'read': return { ok: true, value: this.readSkill(asRecord(payload)) }
|
|
511
|
-
case 'files': return { ok: true, value: this.listSkillFiles(asRecord(payload)) }
|
|
512
|
-
case 'file': return { ok: true, value: this.readSkillFile(asRecord(payload)) }
|
|
511
|
+
case 'files': return { ok: true, value: await this.listSkillFiles(asRecord(payload)) }
|
|
512
|
+
case 'file': return { ok: true, value: await this.readSkillFile(asRecord(payload)) }
|
|
513
513
|
case 'vendor': return { ok: true, value: this.vendorScript('marked.min.js') }
|
|
514
514
|
default:
|
|
515
515
|
throw new HubError('skill-hub/unknown-endpoint', `unknown endpoint "${endpoint}"`)
|
|
@@ -769,10 +769,50 @@ class SkillHub {
|
|
|
769
769
|
* @param {string} skillName - 已校验的技能名。
|
|
770
770
|
* @returns {{root: string, kind: 'dir'|'file'}} 根路径与类型。
|
|
771
771
|
*/
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
772
|
+
/**
|
|
773
|
+
* 取内置技能的完整定义:注册表的 list() 只给摘要(多数 provider 不带 path),
|
|
774
|
+
* get() 才会带回 path / resourceBase / content,预览靠它定位文件。
|
|
775
|
+
* @param {string} skillName - 技能名。
|
|
776
|
+
* @param {string|null} presetId - 角色预设。
|
|
777
|
+
* @returns {Promise<object|undefined>} 技能定义。
|
|
778
|
+
*/
|
|
779
|
+
async builtinDefinition(skillName, presetId) {
|
|
780
|
+
const presets = readService(this.ctx, 'agentPresets')
|
|
781
|
+
const registry = readService(this.ctx, 'skills')
|
|
782
|
+
if (presets === undefined || registry === undefined) return undefined
|
|
783
|
+
let lease
|
|
784
|
+
try {
|
|
785
|
+
lease = await presets.acquireScope(presetId)
|
|
786
|
+
const cwd = readService(this.ctx, 'workingDirectory')?.defaultDirectory
|
|
787
|
+
return await registry.get(skillName, { scope: lease.key, ...cwd === undefined ? {} : { cwd } })
|
|
788
|
+
} catch (error) {
|
|
789
|
+
this.ctx.logger?.warn?.(`skill-hub: built-in skill "${skillName}" unavailable: ${describe(error)}`)
|
|
790
|
+
return undefined
|
|
791
|
+
} finally {
|
|
792
|
+
try { await lease?.[Symbol.asyncDispose]?.() } catch { /* lease already released */ }
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
async skillRoot(skillName, options = {}) {
|
|
797
|
+
let file
|
|
798
|
+
if (options.builtin === true) {
|
|
799
|
+
const presetId = typeof options.presetId === 'string' && options.presetId !== '' ? options.presetId : null
|
|
800
|
+
const definition = await this.builtinDefinition(skillName, presetId)
|
|
801
|
+
if (definition === undefined) {
|
|
802
|
+
throw new HubError('skill-hub/not-found', `Built-in skill "${skillName}" is not available for this role`)
|
|
803
|
+
}
|
|
804
|
+
if (typeof definition.path === 'string' && definition.path !== '') {
|
|
805
|
+
file = resolve(definition.path)
|
|
806
|
+
} else if (typeof definition.resourceBase?.path === 'string' && definition.resourceBase.path !== '') {
|
|
807
|
+
return { root: resolve(definition.resourceBase.path), kind: 'dir' }
|
|
808
|
+
} else {
|
|
809
|
+
throw new HubError('skill-hub/no-file', `Built-in skill "${skillName}" ships without files; its body is available in the definition only`)
|
|
810
|
+
}
|
|
811
|
+
} else {
|
|
812
|
+
const entry = this.poolEntry(skillName)
|
|
813
|
+
if (entry === undefined) throw new HubError('skill-hub/not-found', `No installed skill is named "${skillName}"`)
|
|
814
|
+
file = resolve(entry.path)
|
|
815
|
+
}
|
|
776
816
|
const dir = resolve(file, '..')
|
|
777
817
|
try {
|
|
778
818
|
if (statSync(dir).isDirectory() && resolve(dir, 'SKILL.md') === file) return { root: dir, kind: 'dir' }
|
|
@@ -788,9 +828,12 @@ class SkillHub {
|
|
|
788
828
|
* @param {Record<string, unknown>} payload - `name`。
|
|
789
829
|
* @returns {{name: string, kind: 'dir'|'file', nodes: object[]}} 文件树。
|
|
790
830
|
*/
|
|
791
|
-
listSkillFiles(payload) {
|
|
831
|
+
async listSkillFiles(payload) {
|
|
792
832
|
const skillName = requireSkillName(payload.name)
|
|
793
|
-
const { root, kind } = this.skillRoot(skillName
|
|
833
|
+
const { root, kind } = await this.skillRoot(skillName, {
|
|
834
|
+
builtin: payload.builtin === true,
|
|
835
|
+
presetId: typeof payload.presetId === 'string' ? payload.presetId : null,
|
|
836
|
+
})
|
|
794
837
|
if (kind === 'file') {
|
|
795
838
|
const size = statSync(root).size
|
|
796
839
|
return { name: skillName, kind, nodes: [{ path: basename(root), name: basename(root), dir: false, depth: 0, size }] }
|
|
@@ -838,10 +881,13 @@ class SkillHub {
|
|
|
838
881
|
* @param {Record<string, unknown>} payload - `name`、`path`。
|
|
839
882
|
* @returns {{path: string, name: string, text: string, truncated: boolean, binary: boolean}} 文件内容。
|
|
840
883
|
*/
|
|
841
|
-
readSkillFile(payload) {
|
|
884
|
+
async readSkillFile(payload) {
|
|
842
885
|
const skillName = requireSkillName(payload.name)
|
|
843
886
|
const relative = typeof payload.path === 'string' ? payload.path : ''
|
|
844
|
-
const { root, kind } = this.skillRoot(skillName
|
|
887
|
+
const { root, kind } = await this.skillRoot(skillName, {
|
|
888
|
+
builtin: payload.builtin === true,
|
|
889
|
+
presetId: typeof payload.presetId === 'string' ? payload.presetId : null,
|
|
890
|
+
})
|
|
845
891
|
const base = kind === 'file' ? dirname(root) : root
|
|
846
892
|
const target = resolve(base, relative)
|
|
847
893
|
if (!target.startsWith(resolve(base) + sep) && target !== resolve(root)) {
|
|
@@ -1200,7 +1246,9 @@ function skillPlanFromArchive(bytes) {
|
|
|
1200
1246
|
for (const member of members) {
|
|
1201
1247
|
const path = sanitizeArchivePath(member.path)
|
|
1202
1248
|
if (path === undefined) continue
|
|
1203
|
-
|
|
1249
|
+
// 跳过 macOS 垃圾与点目录(.history / .git / .DS_Store)
|
|
1250
|
+
if (path.startsWith('__MACOSX/')) continue
|
|
1251
|
+
if (path.split('/').some(segment => segment.startsWith('.'))) continue
|
|
1204
1252
|
unpacked += member.data.byteLength
|
|
1205
1253
|
if (member.data.byteLength > MAX_ENTRY_BYTES) {
|
|
1206
1254
|
throw new HubError('skill-hub/too-large', `"${path}" exceeds the per-file limit`)
|
|
@@ -1225,27 +1273,39 @@ function skillPlanFromArchive(bytes) {
|
|
|
1225
1273
|
}
|
|
1226
1274
|
const skills = []
|
|
1227
1275
|
const seen = new Set()
|
|
1228
|
-
//
|
|
1229
|
-
//
|
|
1230
|
-
|
|
1276
|
+
// 先解析每个含 SKILL.md 的目录:只有带合法 frontmatter 的才算"技能"。
|
|
1277
|
+
// 嵌套的 notes/SKILL.md、knowledge-base/SKILL.md 这类是根技能的子文档,
|
|
1278
|
+
// 没有 frontmatter 是正常的 —— 它们应该并入上方那个真正的技能,而不是报错。
|
|
1279
|
+
const parsedRoots = new Map()
|
|
1280
|
+
for (const root of roots) {
|
|
1281
|
+
const prefix = root.length === 0 ? '' : `${root}/`
|
|
1282
|
+
const document = files.find(file => file.path === `${prefix}${SKILL_FILE}`)
|
|
1283
|
+
if (document === undefined) continue
|
|
1284
|
+
const parsed = parseSkillDocument(Buffer.from(document.data).toString('utf8'))
|
|
1285
|
+
parsedRoots.set(root, parsed)
|
|
1286
|
+
}
|
|
1287
|
+
const validRoots = [...parsedRoots.entries()].filter(([, parsed]) => parsed.ok).map(([root]) => root)
|
|
1288
|
+
if (validRoots.length === 0) {
|
|
1289
|
+
const [firstRoot, firstParsed] = [...parsedRoots.entries()][0] ?? ['', { ok: false, error: 'no SKILL.md' }]
|
|
1290
|
+
const prefix = firstRoot.length === 0 ? '' : `${firstRoot}/`
|
|
1291
|
+
throw new HubError('skill-hub/invalid-skill', `${prefix}${SKILL_FILE}: ${firstParsed.error}`)
|
|
1292
|
+
}
|
|
1293
|
+
// 每个文件归属于最深的"合法"技能根,深层子文档自然落到父技能里。
|
|
1231
1294
|
const rootPrefixOf = (path) => {
|
|
1232
1295
|
let best
|
|
1233
|
-
for (const root of
|
|
1296
|
+
for (const root of validRoots) {
|
|
1234
1297
|
const prefix = root.length === 0 ? '' : `${root}/`
|
|
1235
1298
|
if (!path.startsWith(prefix)) continue
|
|
1236
1299
|
if (best === undefined || prefix.length > best.length) best = prefix
|
|
1237
1300
|
}
|
|
1238
1301
|
return best
|
|
1239
1302
|
}
|
|
1240
|
-
for (const root of
|
|
1303
|
+
for (const root of validRoots) {
|
|
1241
1304
|
const prefix = root.length === 0 ? '' : `${root}/`
|
|
1242
1305
|
const owned = files.filter(file => rootPrefixOf(file.path) === prefix)
|
|
1243
1306
|
const document = owned.find(file => file.path === `${prefix}${SKILL_FILE}`)
|
|
1244
1307
|
if (document === undefined) continue
|
|
1245
|
-
const parsed =
|
|
1246
|
-
if (!parsed.ok) {
|
|
1247
|
-
throw new HubError('skill-hub/invalid-skill', `${prefix}${SKILL_FILE}: ${parsed.error}`)
|
|
1248
|
-
}
|
|
1308
|
+
const parsed = parsedRoots.get(root)
|
|
1249
1309
|
if (seen.has(parsed.name)) {
|
|
1250
1310
|
throw new HubError('skill-hub/duplicate-skill', `The archive installs "${parsed.name}" twice`)
|
|
1251
1311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-dsh-skill-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Skills panel: one shared external skill pool plus per-role authorization of pool skills and of each role's system built-in skills",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dsh": {
|
|
28
|
-
"bundle": {
|
|
28
|
+
"bundle": {
|
|
29
|
+
"patch": "./cordis.patch.yml"
|
|
30
|
+
},
|
|
29
31
|
"client": {
|
|
30
32
|
"platform": "web",
|
|
31
33
|
"immediately": true,
|