universal-plugin-hub 1.0.25 → 1.0.30

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/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "universal-plugin-hub",
3
3
  "title": "Universal Plugin Hub",
4
4
  "displayName": "Universal Plugin Hub",
5
- "description": "在 DSH 中使用 Claude Code、Codex 等软件生态的插件,一站式管理插件、Skills 与 MCP。支持添加自己的 Git 插件源、上传插件和 Skills、添加 MCP 服务器,自动扫描并开关本地 Skills,接入插件提供的子代理、MCP、Hooks 与 LSP。",
6
- "version": "1.0.25",
5
+ "description": "在 DSH 中使用 Claude Code、Codex 等软件生态的插件,一站式管理插件、Skills 与 MCP。支持添加 Git 插件源和 marketplace、上传插件和 Skills、添加 MCP 服务器,自动扫描并开关本地 Skills,接入插件提供的子代理、MCP、Hooks 与 LSP。",
6
+ "version": "1.0.30",
7
7
  "engines": {
8
8
  "dsh": ">=0.1.5-rc.1"
9
9
  },
package/src/skills.js CHANGED
@@ -31,17 +31,49 @@ function policyValue(value, fallback) {
31
31
  if (['false', 'no', 'off', '0'].includes(normalized)) return false
32
32
  throw new Error('调用策略必须是布尔值')
33
33
  }
34
+ function parseYamlObject(source) {
35
+ try {
36
+ const value = parseYaml(source)
37
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined
38
+ } catch { return undefined }
39
+ }
40
+ // Some SKILL.md files carry the metadata block twice: a template header that
41
+ // was never removed sits above the real one. Only the first block was read and
42
+ // cut, so the copy rendered as a `--- name: … ---` table at the top of the
43
+ // detail page — and the card took the template's name. The body starts after
44
+ // the last leading block instead; a `---` rule further down is page content.
45
+ function splitFrontmatter(raw) {
46
+ // Both ends of a block pin the same line terminator: with `\r?` on only one
47
+ // side, an LF file matches a range running from line 1's `---` to line 2's
48
+ // closing one plus its leading `\r`, and the leftover `\n` throws the next
49
+ // round off by a line — the second copy then never matched.
50
+ const block = /^---[ \t]*(\r?\n)([\s\S]*?)\1---[ \t]*\1/
51
+ // The blank line a copy sits under is skipped with it, so the check below
52
+ // lands on the next block instead of stopping at the gap.
53
+ const gap = /^(?:[ \t]*\r?\n)*/
54
+ let yaml = '', end = 0
55
+ while (end < raw.length) {
56
+ const skip = raw.slice(end).match(gap)[0].length
57
+ const next = raw.slice(end + skip).match(block)
58
+ // Only consecutive metadata counts. A block further down sits under page
59
+ // content, where it is a horizontal rule and a table, not a header.
60
+ if (!next || parseYamlObject(next[2]) === undefined) break
61
+ yaml = next[2]
62
+ end += skip + next[0].length
63
+ }
64
+ return yaml ? { yaml, body: raw.slice(end) } : null
65
+ }
34
66
  function readSkill(file, root, isNested) {
35
67
  let raw = '', meta = {}, content = '', error = ''
36
68
  let invocation = { modelInvocable: true, userInvocable: true }
37
69
  try {
38
70
  if (statSync(file).size > MAX_FILE) throw new Error('SKILL.md 文件过大')
39
71
  raw = readFileSync(file, 'utf8').replace(/^\uFEFF/, '')
40
- const match = raw.match(/^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/)
41
- if (!match) throw new Error('缺少完整的 YAML 元数据')
42
- meta = parseYaml(match[1]) || {}
72
+ const parsed = splitFrontmatter(raw)
73
+ if (!parsed) throw new Error('缺少完整的 YAML 元数据')
74
+ meta = parseYaml(parsed.yaml) || {}
43
75
  if (typeof meta !== 'object' || Array.isArray(meta)) throw new Error('YAML 元数据必须是对象')
44
- content = raw.slice(match[0].length)
76
+ content = parsed.body
45
77
  if (typeof meta.name !== 'string' || !NAME.test(meta.name)) throw new Error('名称不符合 DSH 的小写连字符格式')
46
78
  if (typeof meta.description !== 'string' || !meta.description.trim()) throw new Error('缺少 description')
47
79
  invocation = { modelInvocable: !policyValue(meta['disable-model-invocation'], false), userInvocable: policyValue(meta['user-invocable'], true) }