universal-plugin-hub 1.1.0 → 1.5.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/README.md +15 -3
- package/README.zh.md +14 -2
- package/client/client.js +5421 -1199
- package/package.json +1 -1
- package/src/at-plugins.js +823 -0
- package/src/icons.js +226 -36
- package/src/index.js +44 -2
- package/src/install.js +1618 -852
- package/src/local.js +439 -71
- package/src/market.js +112 -56
- package/src/oauth-bridge.js +1 -2
- package/src/oauth-config.js +4 -0
- package/src/oauth-store.js +24 -11
- package/src/oauth.js +5 -4
- package/src/parser.js +1272 -462
- package/src/routes.js +410 -128
- package/src/runtime.js +3 -1
- package/src/skill-uploads.js +116 -12
- package/src/skills.js +12 -5
- package/src/store.js +258 -40
package/src/parser.js
CHANGED
|
@@ -9,18 +9,187 @@
|
|
|
9
9
|
* 5. Single-plugin Standalone Repositories (root SKILL.md, plugin.json, skills/, commands/, agents/, .cursorrules)
|
|
10
10
|
*/
|
|
11
11
|
import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, copyFileSync } from 'node:fs'
|
|
12
|
-
import { join, basename, dirname, isAbsolute } from 'node:path'
|
|
12
|
+
import { join, basename, dirname, isAbsolute, relative, resolve } from 'node:path'
|
|
13
13
|
import { load as parseYaml } from 'js-yaml'
|
|
14
|
-
import { sourceCacheDir, installedDir } from './store.js'
|
|
15
|
-
import { safeSegment, pluginPath, sourceRepositoryDir } from './market.js'
|
|
14
|
+
import { sourceCacheDir, installedDir, pluginDataDir } from './store.js'
|
|
15
|
+
import { safeSegment, pluginPath, sourceRepositoryDir, normalizeRemotePluginSource, remoteCheckoutDir } from './market.js'
|
|
16
16
|
import { parseAgentDefinition } from './agents-map.js'
|
|
17
|
-
import { buildPluginIcons } from './icons.js'
|
|
17
|
+
import { buildPluginIcons, touchLru, setLru } from './icons.js'
|
|
18
18
|
|
|
19
19
|
const DIR_PARSER_CACHE = new Map()
|
|
20
20
|
const DIR_PARSER_CACHE_TTL = 20000 // 20s TTL for file scanning
|
|
21
|
+
let PARSER_CACHE_REVISION = 0
|
|
22
|
+
|
|
23
|
+
export function parserCacheRevision() {
|
|
24
|
+
return PARSER_CACHE_REVISION
|
|
25
|
+
}
|
|
26
|
+
const VALID_PLUGIN_NAME = /^[a-z0-9][a-z0-9._-]*$/i
|
|
27
|
+
const MANIFEST_CANDIDATE_PARTS = [
|
|
28
|
+
['.claude-plugin', 'marketplace.json'],
|
|
29
|
+
['.agents', 'plugins', 'marketplace.json'],
|
|
30
|
+
['marketplace.json'],
|
|
31
|
+
['claude-plugins.json'],
|
|
32
|
+
['registry.json'],
|
|
33
|
+
['plugins.json'],
|
|
34
|
+
['catalog.json'],
|
|
35
|
+
['market.json'],
|
|
36
|
+
['mcp-servers.json'],
|
|
37
|
+
['servers.json'],
|
|
38
|
+
['index.json'],
|
|
39
|
+
['.well-known', 'agent-card.json'],
|
|
40
|
+
]
|
|
41
|
+
const MONO_DIRS = ['plugins', 'skills', 'packages', 'tools', 'extensions']
|
|
42
|
+
const ROOT_PLUGIN_MARKER_PARTS = [
|
|
43
|
+
['SKILL.md'],
|
|
44
|
+
['skills'],
|
|
45
|
+
['commands'],
|
|
46
|
+
['agents'],
|
|
47
|
+
['hooks'],
|
|
48
|
+
['mcp.json'],
|
|
49
|
+
['.mcp.json'],
|
|
50
|
+
['server.json'],
|
|
51
|
+
['.lsp.json'],
|
|
52
|
+
['lsp.json'],
|
|
53
|
+
['.claude-plugin', 'plugin.json'],
|
|
54
|
+
['.codex-plugin', 'plugin.json'],
|
|
55
|
+
['plugin.json'],
|
|
56
|
+
['.cursor', 'rules'],
|
|
57
|
+
['.cursorrules'],
|
|
58
|
+
['package.json'],
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
export const PLUGIN_RUNTIME_ENV_KEYS = ['PLUGIN_ROOT', 'PLUGIN_DATA', 'CLAUDE_PLUGIN_ROOT', 'CLAUDE_PLUGIN_DATA']
|
|
62
|
+
const BUILTIN_PLUGIN_ROOT_RE = /\$\{(?:CLAUDE_PLUGIN_ROOT|PLUGIN_ROOT)\}|\$(?:CLAUDE_PLUGIN_ROOT|PLUGIN_ROOT)\b/g
|
|
63
|
+
const BUILTIN_PLUGIN_DATA_RE = /\$\{(?:CLAUDE_PLUGIN_DATA|PLUGIN_DATA)\}|\$(?:CLAUDE_PLUGIN_DATA|PLUGIN_DATA)\b/g
|
|
64
|
+
|
|
65
|
+
export function hasUnresolvedVarPlaceholder(value) {
|
|
66
|
+
if (typeof value !== 'string') return false
|
|
67
|
+
const stripped = value.replace(BUILTIN_PLUGIN_ROOT_RE, '').replace(BUILTIN_PLUGIN_DATA_RE, '')
|
|
68
|
+
return /\$\{[^}]+\}/.test(stripped)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isDotRelativePath(value) {
|
|
72
|
+
return typeof value === 'string' && /^\.\.?(?:[\\/]|$)/.test(value.trim())
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function pluginDataDirForRoot(pluginRoot, explicitDataDir) {
|
|
76
|
+
if (typeof explicitDataDir === 'string' && explicitDataDir) return explicitDataDir
|
|
77
|
+
if (typeof pluginRoot === 'string' && pluginRoot) {
|
|
78
|
+
if (basename(dirname(pluginRoot)) === 'installed') return pluginDataDir(basename(pluginRoot))
|
|
79
|
+
return join(pluginRoot, '.plugin-data')
|
|
80
|
+
}
|
|
81
|
+
return ''
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function expandPluginVars(val, pluginRoot, explicitDataDir) {
|
|
85
|
+
if (typeof val === 'string') {
|
|
86
|
+
const normalizedRoot = String(pluginRoot || '').replace(/\\/g, '/')
|
|
87
|
+
const resolvedData = pluginDataDirForRoot(pluginRoot, explicitDataDir)
|
|
88
|
+
const normalizedData = String(resolvedData || '').replace(/\\/g, '/')
|
|
89
|
+
let out = val.replace(BUILTIN_PLUGIN_ROOT_RE, () => normalizedRoot)
|
|
90
|
+
if (normalizedData) out = out.replace(BUILTIN_PLUGIN_DATA_RE, () => normalizedData)
|
|
91
|
+
return out
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(val)) return val.map((item) => expandPluginVars(item, pluginRoot, explicitDataDir))
|
|
94
|
+
if (val && typeof val === 'object') {
|
|
95
|
+
const res = {}
|
|
96
|
+
for (const [k, v] of Object.entries(val)) res[k] = expandPluginVars(v, pluginRoot, explicitDataDir)
|
|
97
|
+
return res
|
|
98
|
+
}
|
|
99
|
+
return val
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function resolvePluginScopedPath(rawVal, pluginRoot, explicitDataDir) {
|
|
103
|
+
const rawTrimmed = String(rawVal).trim()
|
|
104
|
+
const expanded = expandPluginVars(rawVal, pluginRoot, explicitDataDir).trim()
|
|
105
|
+
if (!expanded) return null
|
|
106
|
+
if (pluginRoot && isDotRelativePath(expanded)) {
|
|
107
|
+
try { return pluginPath(pluginRoot, expanded).replace(/\\/g, '/') } catch { return null }
|
|
108
|
+
}
|
|
109
|
+
if (pluginRoot && /^\$(?:\{(?:CLAUDE_)?PLUGIN_ROOT\}|(?:CLAUDE_)?PLUGIN_ROOT\b)/.test(rawTrimmed)) {
|
|
110
|
+
const rel = relative(resolve(pluginRoot), resolve(expanded))
|
|
111
|
+
if (rel === '..' || rel.startsWith('..') || isAbsolute(rel)) return null
|
|
112
|
+
try { return pluginPath(pluginRoot, rel || '.').replace(/\\/g, '/') } catch { return null }
|
|
113
|
+
}
|
|
114
|
+
return expanded
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function resolvePluginCommand(command, pluginRoot, explicitDataDir) {
|
|
118
|
+
if (typeof command !== 'string') return command ?? null
|
|
119
|
+
return resolvePluginScopedPath(command, pluginRoot, explicitDataDir)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function resolvePluginCwd(rawCwd, pluginRoot, explicitDataDir, { command, args } = {}) {
|
|
123
|
+
if (rawCwd === '') return ''
|
|
124
|
+
if (typeof rawCwd === 'string' && rawCwd.trim()) {
|
|
125
|
+
const scoped = resolvePluginScopedPath(rawCwd, pluginRoot, explicitDataDir)
|
|
126
|
+
return scoped ? scoped.replace(/\\/g, '/') : null
|
|
127
|
+
}
|
|
128
|
+
if (pluginRoot && (isDotRelativePath(command) || (Array.isArray(args) && args.some(isDotRelativePath)))) {
|
|
129
|
+
return pluginRoot.replace(/\\/g, '/')
|
|
130
|
+
}
|
|
131
|
+
return ''
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function resolveConnectorDisplay(cfg, pluginRoot, explicitDataDir) {
|
|
135
|
+
if (!cfg || typeof cfg !== 'object') {
|
|
136
|
+
return { displayUrl: null, displayCommand: null, displayArgs: [], displayCwd: null }
|
|
137
|
+
}
|
|
138
|
+
const expanded = expandPluginVars({
|
|
139
|
+
url: cfg.url || null,
|
|
140
|
+
args: Array.isArray(cfg.args) ? cfg.args : [],
|
|
141
|
+
}, pluginRoot, explicitDataDir)
|
|
142
|
+
const displayCommand = cfg.command ? resolvePluginCommand(cfg.command, pluginRoot, explicitDataDir) : null
|
|
143
|
+
const cwdVal = resolvePluginCwd(cfg.cwd ?? null, pluginRoot, explicitDataDir, {
|
|
144
|
+
command: cfg.command,
|
|
145
|
+
args: Array.isArray(cfg.args) ? cfg.args : [],
|
|
146
|
+
})
|
|
147
|
+
return {
|
|
148
|
+
displayUrl: expanded.url,
|
|
149
|
+
displayCommand,
|
|
150
|
+
displayArgs: expanded.args,
|
|
151
|
+
displayCwd: cwdVal || null,
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function resolvePluginSpecPath(dir, specPath) {
|
|
156
|
+
if (typeof specPath !== 'string') return null
|
|
157
|
+
const trimmed = specPath.trim()
|
|
158
|
+
if (!trimmed) return null
|
|
159
|
+
try {
|
|
160
|
+
return pluginPath(dir, trimmed)
|
|
161
|
+
} catch {
|
|
162
|
+
return null
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function resolveMarketplacePluginSource(rawSource, pluginRootMeta) {
|
|
167
|
+
if (rawSource?.source === 'local') {
|
|
168
|
+
const localPath = typeof rawSource.path === 'string' ? rawSource.path.trim() : ''
|
|
169
|
+
if (!localPath.startsWith('./')) return null
|
|
170
|
+
return localPath
|
|
171
|
+
}
|
|
172
|
+
if (rawSource && typeof rawSource === 'object') {
|
|
173
|
+
return normalizeRemotePluginSource(rawSource)
|
|
174
|
+
}
|
|
175
|
+
if (typeof rawSource === 'string') {
|
|
176
|
+
const trimmed = rawSource.trim()
|
|
177
|
+
if (!trimmed || trimmed === '.' || trimmed === './') return './'
|
|
178
|
+
if (trimmed.startsWith('./')) return trimmed
|
|
179
|
+
if (/^https?:\/\//i.test(trimmed) || /^git@/i.test(trimmed)) return trimmed
|
|
180
|
+
if (trimmed.startsWith('/') || trimmed.includes('..') || /^[a-z]:/i.test(trimmed)) return null
|
|
181
|
+
const rawBase = typeof pluginRootMeta === 'string' ? pluginRootMeta.trim() : ''
|
|
182
|
+
if (rawBase && (rawBase.includes('..') || rawBase.startsWith('/') || /^[a-z]:/i.test(rawBase))) return null
|
|
183
|
+
const baseRoot = rawBase.replace(/^\.\//, '').replace(/^\/+|\/+$/g, '')
|
|
184
|
+
const combined = baseRoot ? `${baseRoot}/${trimmed.replace(/^\/+/, '')}` : trimmed
|
|
185
|
+
return `./${combined}`
|
|
186
|
+
}
|
|
187
|
+
return './'
|
|
188
|
+
}
|
|
21
189
|
|
|
22
190
|
export function invalidateParserCaches() {
|
|
23
191
|
DIR_PARSER_CACHE.clear()
|
|
192
|
+
PARSER_CACHE_REVISION += 1
|
|
24
193
|
}
|
|
25
194
|
|
|
26
195
|
export function formatDisplayName(name) {
|
|
@@ -68,7 +237,7 @@ function extractMdDescription(text) {
|
|
|
68
237
|
|
|
69
238
|
// Presentation only: read Codex's card copy without changing which manifest
|
|
70
239
|
// owns the plugin's description, components, or installation behavior.
|
|
71
|
-
function readPluginShortDescription(dir) {
|
|
240
|
+
export function readPluginShortDescription(dir) {
|
|
72
241
|
if (!dir) return ''
|
|
73
242
|
const text = value => typeof value === 'string' ? value.trim() : ''
|
|
74
243
|
try {
|
|
@@ -83,10 +252,42 @@ function readPluginShortDescription(dir) {
|
|
|
83
252
|
} catch { return '' }
|
|
84
253
|
}
|
|
85
254
|
|
|
86
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Normalizes a semantic/free-form version string: trims whitespace, drops a
|
|
257
|
+
* redundant leading `v` before digits so UI badges render `vX.Y.Z` consistently,
|
|
258
|
+
* and maps empty values to `undefined`.
|
|
259
|
+
*/
|
|
260
|
+
export function normalizeVersion(value) {
|
|
261
|
+
if (typeof value !== 'string') return undefined
|
|
262
|
+
const trimmed = value.trim()
|
|
263
|
+
if (!trimmed) return undefined
|
|
264
|
+
return trimmed.replace(/^v(?=\d)/i, '')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function manifestRootDir(manifestPath) {
|
|
268
|
+
const parent = dirname(manifestPath)
|
|
269
|
+
const folder = basename(parent)
|
|
270
|
+
if (folder === '.claude-plugin' || folder === '.codex-plugin' || folder === '.well-known') return dirname(parent)
|
|
271
|
+
if (folder === 'plugins' && basename(dirname(parent)) === '.agents') return dirname(dirname(parent))
|
|
272
|
+
return parent
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function readPackageVersion(dir) {
|
|
276
|
+
if (!dir) return undefined
|
|
277
|
+
try {
|
|
278
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
279
|
+
return normalizeVersion(pkg?.['claude-plugin']?.version) || normalizeVersion(pkg?.version)
|
|
280
|
+
} catch {
|
|
281
|
+
return undefined
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export const MARKETPLACE_COMPONENT_KEYS = ['mcpServers', 'lspServers', 'hooks', 'skills', 'commands', 'agents', 'prompts']
|
|
286
|
+
|
|
287
|
+
function normalizeRow(row, sourceId, dir, { skipIcons = false, pluginRootMeta = undefined } = {}) {
|
|
87
288
|
if (!row) return null
|
|
88
289
|
const name = typeof row.name === 'string' ? row.name : (typeof row.identifier === 'string' ? row.identifier : '')
|
|
89
|
-
if (!name ||
|
|
290
|
+
if (!name || !VALID_PLUGIN_NAME.test(name)) return null
|
|
90
291
|
const cleanName = name.toLowerCase()
|
|
91
292
|
|
|
92
293
|
const author = row.author && typeof row.author === 'object'
|
|
@@ -101,8 +302,8 @@ function normalizeRow(row, sourceId, dir) {
|
|
|
101
302
|
const shortDescription = readPluginShortDescription(dir)
|
|
102
303
|
|| (typeof row.interface?.shortDescription === 'string' ? row.interface.shortDescription.trim() : '')
|
|
103
304
|
|
|
104
|
-
const source =
|
|
105
|
-
if (
|
|
305
|
+
const source = resolveMarketplacePluginSource(row.source, pluginRootMeta)
|
|
306
|
+
if (source === null) return null
|
|
106
307
|
|
|
107
308
|
return {
|
|
108
309
|
id: `${sourceId}/${cleanName}`,
|
|
@@ -112,28 +313,37 @@ function normalizeRow(row, sourceId, dir) {
|
|
|
112
313
|
description,
|
|
113
314
|
...(shortDescription ? { shortDescription } : {}),
|
|
114
315
|
author: typeof author === 'string' ? author : (meta.author || undefined),
|
|
115
|
-
version:
|
|
316
|
+
version: normalizeVersion(row.version)
|
|
317
|
+
|| normalizeVersion(row.interface?.version)
|
|
318
|
+
|| normalizeVersion(row.extensions?.['com.openai']?.version)
|
|
319
|
+
|| normalizeVersion(meta.version),
|
|
116
320
|
category: typeof row.category === 'string' ? row.category : (meta.category || undefined),
|
|
117
321
|
homepage: typeof row.homepage === 'string' ? row.homepage : (meta.homepage || undefined),
|
|
118
322
|
source,
|
|
119
323
|
local: typeof source === 'string' && (source === './' || source.startsWith('./')),
|
|
120
|
-
|
|
121
|
-
|
|
324
|
+
...(row.strict !== undefined ? { strict: row.strict } : {}),
|
|
325
|
+
...Object.fromEntries(MARKETPLACE_COMPONENT_KEYS.filter((k) => row[k] !== undefined).map((k) => [k, row[k]])),
|
|
326
|
+
...(skipIcons ? {} : { icons: buildPluginIcons(row, { sourceId, name: cleanName, dir, source }) }),
|
|
122
327
|
}
|
|
123
328
|
}
|
|
124
329
|
|
|
125
330
|
const MARKETPLACE_CACHE = new Map()
|
|
126
331
|
const MARKETPLACE_SELECTION_CACHE = new Map()
|
|
332
|
+
const PLUGIN_DIR_INDEX_CACHE = new Map()
|
|
333
|
+
const PLUGIN_DIR_INDEX_LIMIT = 64
|
|
127
334
|
const MARKETPLACE_CACHE_TTL = 30000 // 30 seconds
|
|
128
335
|
|
|
129
336
|
export function invalidateMarketplaceCache(sourceId) {
|
|
130
337
|
if (sourceId) {
|
|
131
338
|
MARKETPLACE_CACHE.delete(sourceId)
|
|
132
339
|
MARKETPLACE_SELECTION_CACHE.delete(sourceId)
|
|
340
|
+
PLUGIN_DIR_INDEX_CACHE.delete(sourceId)
|
|
133
341
|
} else {
|
|
134
342
|
MARKETPLACE_CACHE.clear()
|
|
135
343
|
MARKETPLACE_SELECTION_CACHE.clear()
|
|
344
|
+
PLUGIN_DIR_INDEX_CACHE.clear()
|
|
136
345
|
}
|
|
346
|
+
PARSER_CACHE_REVISION += 1
|
|
137
347
|
}
|
|
138
348
|
|
|
139
349
|
/**
|
|
@@ -164,15 +374,52 @@ export function readMarketplace(sourceId, names) {
|
|
|
164
374
|
return rows
|
|
165
375
|
}
|
|
166
376
|
|
|
167
|
-
|
|
377
|
+
function resolveMcpDict(content) {
|
|
378
|
+
if (!content || typeof content !== 'object') return null
|
|
379
|
+
if (content.mcpServers && typeof content.mcpServers === 'object') return content.mcpServers
|
|
380
|
+
if (content.servers && typeof content.servers === 'object') return content.servers
|
|
381
|
+
return null
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function resolveCaseAEntryDir(sourceId, cache, r, pluginRootMeta) {
|
|
385
|
+
const source = resolveMarketplacePluginSource(r.source, pluginRootMeta)
|
|
386
|
+
let dir = null
|
|
387
|
+
if (typeof source === 'string' && source.startsWith('./')) {
|
|
388
|
+
try { dir = pluginPath(cache, source) } catch { return { source: null, dir: null } }
|
|
389
|
+
}
|
|
390
|
+
if (source && typeof source === 'object' && r.name) {
|
|
391
|
+
dir = sourceRepositoryDir(cache, source) || pluginContentDir(sourceId, r.name, source, false)
|
|
392
|
+
}
|
|
393
|
+
return { source, dir }
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function isPortableRootManifest(dir) {
|
|
397
|
+
const rootPath = join(dir, 'plugin.json')
|
|
398
|
+
if (!existsSync(rootPath)) return false
|
|
399
|
+
try {
|
|
400
|
+
const raw = JSON.parse(readFileSync(rootPath, 'utf8'))
|
|
401
|
+
return /^https:\/\/agent-plugins\.org\//.test(raw?.$schema || '') || Boolean(raw?.extensions?.['com.openai'])
|
|
402
|
+
} catch { return false }
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function hasExplicitRootPlugin(cache) {
|
|
406
|
+
return existsSync(join(cache, '.codex-plugin', 'plugin.json'))
|
|
407
|
+
|| existsSync(join(cache, '.claude-plugin', 'plugin.json'))
|
|
408
|
+
|| isPortableRootManifest(cache)
|
|
409
|
+
|| existsSync(join(cache, 'SKILL.md'))
|
|
410
|
+
|| existsSync(join(cache, 'skill.md'))
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function resolveDirPluginInfo(entryDir, fallbackName, { includeMetadata = true } = {}) {
|
|
168
414
|
const rootSkill = existsSync(join(entryDir, 'SKILL.md')) || existsSync(join(entryDir, 'skill.md'))
|
|
169
415
|
const hasSkill = rootSkill || existsSync(join(entryDir, 'skills')) || existsSync(join(entryDir, 'commands'))
|
|
170
416
|
const hasManifest = existsSync(join(entryDir, '.codex-plugin', 'plugin.json')) || existsSync(join(entryDir, '.claude-plugin', 'plugin.json')) || existsSync(join(entryDir, 'plugin.json')) || existsSync(join(entryDir, 'package.json'))
|
|
171
417
|
const hasMcp = existsSync(join(entryDir, 'mcp.json')) || existsSync(join(entryDir, '.mcp.json')) || existsSync(join(entryDir, 'server.json'))
|
|
418
|
+
const hasLsp = existsSync(join(entryDir, '.lsp.json')) || existsSync(join(entryDir, 'lsp.json'))
|
|
172
419
|
const hasAgents = existsSync(join(entryDir, 'agents'))
|
|
173
|
-
if (!hasSkill && !hasManifest && !hasMcp && !hasAgents) return null
|
|
420
|
+
if (!hasSkill && !hasManifest && !hasMcp && !hasLsp && !hasAgents) return null
|
|
174
421
|
|
|
175
|
-
let displayName = formatDisplayName(fallbackName)
|
|
422
|
+
let displayName = includeMetadata ? formatDisplayName(fallbackName) : ''
|
|
176
423
|
let description = ''
|
|
177
424
|
let version = '1.0.0'
|
|
178
425
|
let author = undefined
|
|
@@ -181,87 +428,308 @@ export function parsePluginRowFromDir(entryDir, fallbackName, sourceId) {
|
|
|
181
428
|
const manifest = readPluginManifest(entryDir, false)
|
|
182
429
|
if (manifest) {
|
|
183
430
|
if (manifest.name) name = manifest.name
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
431
|
+
if (includeMetadata) {
|
|
432
|
+
displayName = manifest.displayName || formatDisplayName(name)
|
|
433
|
+
if (manifest.description) description = manifest.description
|
|
434
|
+
if (manifest.version) version = manifest.version
|
|
435
|
+
if (manifest.author) author = typeof manifest.author === 'string' ? manifest.author : manifest.author?.name
|
|
436
|
+
}
|
|
188
437
|
} else if (rootSkill) {
|
|
189
438
|
try {
|
|
190
439
|
const raw = readFileSync(join(entryDir, existsSync(join(entryDir, 'SKILL.md')) ? 'SKILL.md' : 'skill.md'), 'utf8')
|
|
191
440
|
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/)
|
|
192
441
|
const meta = match ? parseYaml(match[1]) : null
|
|
193
442
|
if (typeof meta?.name === 'string') name = meta.name
|
|
194
|
-
|
|
195
|
-
|
|
443
|
+
if (includeMetadata) {
|
|
444
|
+
displayName = formatDisplayName(name)
|
|
445
|
+
description = extractMdDescription(raw)
|
|
446
|
+
}
|
|
196
447
|
} catch {}
|
|
197
|
-
} else if (existsSync(join(entryDir, 'README.md'))) {
|
|
448
|
+
} else if (includeMetadata && existsSync(join(entryDir, 'README.md'))) {
|
|
198
449
|
try { description = extractMdDescription(readFileSync(join(entryDir, 'README.md'), 'utf8')) } catch {}
|
|
199
450
|
}
|
|
200
451
|
|
|
452
|
+
return { name, displayName, description, version, author, manifest }
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function resolveStandaloneRootInfo(cache, sourceId, { includeMetadata = true } = {}) {
|
|
456
|
+
if (!ROOT_PLUGIN_MARKER_PARTS.some((parts) => existsSync(join(cache, ...parts)))) return null
|
|
457
|
+
let name = sourceId
|
|
458
|
+
let displayName = includeMetadata ? formatDisplayName(sourceId) : ''
|
|
459
|
+
let description = ''
|
|
460
|
+
let version = '1.0.0'
|
|
461
|
+
let author = undefined
|
|
462
|
+
|
|
463
|
+
const manifest = readPluginManifest(cache)
|
|
464
|
+
if (manifest) {
|
|
465
|
+
if (manifest.name) name = manifest.name
|
|
466
|
+
if (includeMetadata) {
|
|
467
|
+
if (manifest.displayName) displayName = manifest.displayName
|
|
468
|
+
if (manifest.description) description = manifest.description
|
|
469
|
+
if (manifest.version) version = manifest.version
|
|
470
|
+
if (manifest.author) author = typeof manifest.author === 'string' ? manifest.author : manifest.author.name
|
|
471
|
+
}
|
|
472
|
+
} else if (includeMetadata && existsSync(join(cache, 'SKILL.md'))) {
|
|
473
|
+
try {
|
|
474
|
+
description = extractMdDescription(readFileSync(join(cache, 'SKILL.md'), 'utf8'))
|
|
475
|
+
} catch {}
|
|
476
|
+
} else if (includeMetadata && existsSync(join(cache, 'README.md'))) {
|
|
477
|
+
try {
|
|
478
|
+
description = extractMdDescription(readFileSync(join(cache, 'README.md'), 'utf8'))
|
|
479
|
+
} catch {}
|
|
480
|
+
}
|
|
481
|
+
return { name, displayName, description, version, author, manifest }
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function parsePluginRowFromDir(entryDir, fallbackName, sourceId, options = {}) {
|
|
485
|
+
const info = resolveDirPluginInfo(entryDir, fallbackName, { includeMetadata: true })
|
|
486
|
+
if (!info) return null
|
|
487
|
+
|
|
201
488
|
return normalizeRow({
|
|
202
|
-
...manifest,
|
|
203
|
-
name,
|
|
204
|
-
displayName,
|
|
205
|
-
description,
|
|
206
|
-
version,
|
|
207
|
-
author,
|
|
489
|
+
...info.manifest,
|
|
490
|
+
name: info.name,
|
|
491
|
+
displayName: info.displayName,
|
|
492
|
+
description: info.description,
|
|
493
|
+
version: info.version,
|
|
494
|
+
author: info.author,
|
|
208
495
|
source: `./${fallbackName}`,
|
|
209
|
-
}, sourceId, entryDir)
|
|
496
|
+
}, sourceId, entryDir, options)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function indexManifestPluginDirs(sourceId, cache, content) {
|
|
500
|
+
if (!content || typeof content !== 'object') return null
|
|
501
|
+
if (Array.isArray(content.plugins)) {
|
|
502
|
+
const entries = new Map()
|
|
503
|
+
const pluginRootMeta = content.metadata?.pluginRoot
|
|
504
|
+
for (const r of content.plugins) {
|
|
505
|
+
if (!r || typeof r !== 'object') continue
|
|
506
|
+
const { source, dir } = resolveCaseAEntryDir(sourceId, cache, r, pluginRootMeta)
|
|
507
|
+
if (source === null) continue
|
|
508
|
+
let rawName = ''
|
|
509
|
+
if (typeof r.name === 'string') {
|
|
510
|
+
rawName = r.name
|
|
511
|
+
} else {
|
|
512
|
+
const manifest = r.name === undefined && dir ? readPluginManifest(dir, false) : null
|
|
513
|
+
if (r.name === undefined && typeof manifest?.name === 'string') rawName = manifest.name
|
|
514
|
+
else rawName = typeof r.identifier === 'string' ? r.identifier : ''
|
|
515
|
+
}
|
|
516
|
+
if (!rawName || !VALID_PLUGIN_NAME.test(rawName)) continue
|
|
517
|
+
const cleanName = rawName.toLowerCase()
|
|
518
|
+
if (!entries.has(cleanName)) entries.set(cleanName, dir)
|
|
519
|
+
}
|
|
520
|
+
if (entries.size > 0) return entries
|
|
521
|
+
}
|
|
522
|
+
if (Array.isArray(content)) {
|
|
523
|
+
const entries = new Map()
|
|
524
|
+
for (const r of content) {
|
|
525
|
+
if (!r || typeof r !== 'object') continue
|
|
526
|
+
const rawName = typeof r.name === 'string' ? r.name : (typeof r.identifier === 'string' ? r.identifier : '')
|
|
527
|
+
if (!rawName || !VALID_PLUGIN_NAME.test(rawName)) continue
|
|
528
|
+
const source = r.source?.source === 'local' ? r.source.path : (r.source || './')
|
|
529
|
+
if (r.source?.source === 'local' && (typeof source !== 'string' || !source.startsWith('./'))) continue
|
|
530
|
+
const cleanName = rawName.toLowerCase()
|
|
531
|
+
if (!entries.has(cleanName)) entries.set(cleanName, pluginContentDir(sourceId, cleanName, source, false))
|
|
532
|
+
}
|
|
533
|
+
if (entries.size > 0) return entries
|
|
534
|
+
}
|
|
535
|
+
const mcpDict = resolveMcpDict(content)
|
|
536
|
+
if (mcpDict) {
|
|
537
|
+
const entries = new Map()
|
|
538
|
+
for (const srvName of Object.keys(mcpDict)) {
|
|
539
|
+
if (!VALID_PLUGIN_NAME.test(srvName)) continue
|
|
540
|
+
const cleanName = srvName.toLowerCase()
|
|
541
|
+
if (!entries.has(cleanName)) entries.set(cleanName, cache)
|
|
542
|
+
}
|
|
543
|
+
if (entries.size > 0) return entries
|
|
544
|
+
}
|
|
545
|
+
return null
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function monoSubRootStamp(cache) {
|
|
549
|
+
return MONO_DIRS.map((sub) => {
|
|
550
|
+
try {
|
|
551
|
+
const info = statSync(join(cache, sub))
|
|
552
|
+
return info.isDirectory() ? String(info.mtimeMs) : ''
|
|
553
|
+
} catch { return '' }
|
|
554
|
+
}).join('|')
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function indexMonoPluginDirs(cache) {
|
|
558
|
+
const entries = new Map()
|
|
559
|
+
for (const sub of MONO_DIRS) {
|
|
560
|
+
const subRoot = join(cache, sub)
|
|
561
|
+
if (!existsSync(subRoot)) continue
|
|
562
|
+
try {
|
|
563
|
+
for (const entry of readdirSync(subRoot, { withFileTypes: true })) {
|
|
564
|
+
if (!entry.isDirectory()) continue
|
|
565
|
+
const dir = join(subRoot, entry.name)
|
|
566
|
+
const info = resolveDirPluginInfo(dir, entry.name, { includeMetadata: false })
|
|
567
|
+
if (info && typeof info.name === 'string' && VALID_PLUGIN_NAME.test(info.name)) {
|
|
568
|
+
const cleanName = info.name.toLowerCase()
|
|
569
|
+
if (!entries.has(cleanName)) entries.set(cleanName, dir)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
} catch {}
|
|
573
|
+
}
|
|
574
|
+
return entries
|
|
210
575
|
}
|
|
211
576
|
|
|
212
|
-
|
|
577
|
+
/**
|
|
578
|
+
* Resolve one plugin's directory in O(1) sharing the exact manifest/directory
|
|
579
|
+
* discovery precedence of `parseMarketplaceFromDisk` without scanning sibling
|
|
580
|
+
* artwork (`buildPluginIcons`) or unrelated plugins.
|
|
581
|
+
*/
|
|
582
|
+
export function resolveMarketplacePluginDir(sourceId, pluginName) {
|
|
583
|
+
safeSegment(sourceId, 'source id')
|
|
584
|
+
const targetName = safeSegment(pluginName, 'plugin name').toLowerCase()
|
|
585
|
+
const cache = sourceCacheDir(sourceId)
|
|
586
|
+
if (!existsSync(cache)) {
|
|
587
|
+
PLUGIN_DIR_INDEX_CACHE.delete(sourceId)
|
|
588
|
+
return null
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const cached = PLUGIN_DIR_INDEX_CACHE.get(sourceId)
|
|
592
|
+
if (cached) {
|
|
593
|
+
if (cached.manifestPath) {
|
|
594
|
+
try {
|
|
595
|
+
const info = statSync(cached.manifestPath)
|
|
596
|
+
if (info.isFile() && info.mtimeMs === cached.mtimeMs && info.size === cached.size) {
|
|
597
|
+
touchLru(PLUGIN_DIR_INDEX_CACHE, sourceId, cached)
|
|
598
|
+
return cached.entries.get(targetName) || null
|
|
599
|
+
}
|
|
600
|
+
} catch {}
|
|
601
|
+
PLUGIN_DIR_INDEX_CACHE.delete(sourceId)
|
|
602
|
+
} else if (cached.monoStamp !== undefined) {
|
|
603
|
+
if (monoSubRootStamp(cache) === cached.monoStamp) {
|
|
604
|
+
touchLru(PLUGIN_DIR_INDEX_CACHE, sourceId, cached)
|
|
605
|
+
return cached.entries.get(targetName) || null
|
|
606
|
+
}
|
|
607
|
+
PLUGIN_DIR_INDEX_CACHE.delete(sourceId)
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
213
611
|
// 1. Check Multi-Plugin Manifest Candidates
|
|
214
|
-
const
|
|
215
|
-
join(cache,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
612
|
+
for (const parts of MANIFEST_CANDIDATE_PARTS) {
|
|
613
|
+
const manifestPath = join(cache, ...parts)
|
|
614
|
+
let info
|
|
615
|
+
try { info = statSync(manifestPath) } catch { continue }
|
|
616
|
+
if (!info.isFile()) continue
|
|
617
|
+
try {
|
|
618
|
+
const content = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
619
|
+
const entries = indexManifestPluginDirs(sourceId, cache, content)
|
|
620
|
+
if (entries) {
|
|
621
|
+
setLru(PLUGIN_DIR_INDEX_CACHE, PLUGIN_DIR_INDEX_LIMIT, sourceId, {
|
|
622
|
+
manifestPath, mtimeMs: info.mtimeMs, size: info.size, entries,
|
|
623
|
+
})
|
|
624
|
+
return entries.get(targetName) || null
|
|
625
|
+
}
|
|
626
|
+
} catch {}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// 2. Local source direct subdirectories discovery
|
|
630
|
+
if (sourceId === 'local') {
|
|
631
|
+
const direct = join(cache, targetName)
|
|
632
|
+
if (existsSync(direct)) {
|
|
633
|
+
const info = resolveDirPluginInfo(direct, targetName, { includeMetadata: false })
|
|
634
|
+
if (info && typeof info.name === 'string' && VALID_PLUGIN_NAME.test(info.name) && info.name.toLowerCase() === targetName) return direct
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
for (const entry of readdirSync(cache, { withFileTypes: true })) {
|
|
638
|
+
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
639
|
+
const dir = join(cache, entry.name)
|
|
640
|
+
const info = resolveDirPluginInfo(dir, entry.name, { includeMetadata: false })
|
|
641
|
+
if (info && typeof info.name === 'string' && VALID_PLUGIN_NAME.test(info.name) && info.name.toLowerCase() === targetName) return dir
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
} catch {}
|
|
645
|
+
return null
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// 3. Explicit root plugin manifests / SKILL.md
|
|
649
|
+
if (hasExplicitRootPlugin(cache)) {
|
|
650
|
+
const info = resolveDirPluginInfo(cache, sourceId, { includeMetadata: false })
|
|
651
|
+
if (info && typeof info.name === 'string' && VALID_PLUGIN_NAME.test(info.name)) {
|
|
652
|
+
return info.name.toLowerCase() === targetName ? cache : null
|
|
653
|
+
}
|
|
654
|
+
}
|
|
228
655
|
|
|
229
|
-
|
|
656
|
+
// 4. Monorepo subdirectories (direct path check first, then indexed scan)
|
|
657
|
+
for (const sub of MONO_DIRS) {
|
|
658
|
+
const direct = join(cache, sub, targetName)
|
|
659
|
+
if (existsSync(direct)) {
|
|
660
|
+
const info = resolveDirPluginInfo(direct, targetName, { includeMetadata: false })
|
|
661
|
+
if (info && typeof info.name === 'string' && VALID_PLUGIN_NAME.test(info.name) && info.name.toLowerCase() === targetName) return direct
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
const monoEntries = indexMonoPluginDirs(cache)
|
|
665
|
+
if (monoEntries.size > 0) {
|
|
666
|
+
setLru(PLUGIN_DIR_INDEX_CACHE, PLUGIN_DIR_INDEX_LIMIT, sourceId, {
|
|
667
|
+
monoStamp: monoSubRootStamp(cache), entries: monoEntries,
|
|
668
|
+
})
|
|
669
|
+
return monoEntries.get(targetName) || null
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// 5. Single Standalone Root Plugin Repository
|
|
673
|
+
const rootInfo = resolveStandaloneRootInfo(cache, sourceId, { includeMetadata: false })
|
|
674
|
+
if (rootInfo && typeof rootInfo.name === 'string' && VALID_PLUGIN_NAME.test(rootInfo.name)) {
|
|
675
|
+
return rootInfo.name.toLowerCase() === targetName ? cache : null
|
|
676
|
+
}
|
|
677
|
+
return null
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export function parseMarketplaceFromDisk(sourceId, cache, names, options = {}) {
|
|
681
|
+
// 1. Check Multi-Plugin Manifest Candidates
|
|
682
|
+
for (const parts of MANIFEST_CANDIDATE_PARTS) {
|
|
683
|
+
const manifestPath = join(cache, ...parts)
|
|
230
684
|
if (existsSync(manifestPath)) {
|
|
231
685
|
try {
|
|
232
686
|
const content = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
233
687
|
// Case A: Claude / standard manifest with plugins array
|
|
234
688
|
if (Array.isArray(content.plugins)) {
|
|
235
689
|
let skipped = false
|
|
690
|
+
const pluginRootMeta = content.metadata?.pluginRoot
|
|
691
|
+
const marketVersion = normalizeVersion(content.metadata?.version) || normalizeVersion(content.version)
|
|
236
692
|
const rows = content.plugins.map((r) => {
|
|
237
|
-
const source
|
|
238
|
-
|
|
239
|
-
if (source && typeof source === 'object' && r.name) {
|
|
240
|
-
dir = sourceRepositoryDir(cache, source) || pluginContentDir(sourceId, r.name, source, false)
|
|
241
|
-
}
|
|
693
|
+
const { source, dir } = resolveCaseAEntryDir(sourceId, cache, r, pluginRootMeta)
|
|
694
|
+
if (source === null) return null
|
|
242
695
|
if (names && typeof r.name === 'string' && !names.has(r.name.toLowerCase())) {
|
|
243
696
|
skipped = true
|
|
244
697
|
return null
|
|
245
698
|
}
|
|
246
699
|
const manifest = dir ? readPluginManifest(dir, false) : null
|
|
700
|
+
const resolvedVersion =
|
|
701
|
+
normalizeVersion(r.version)
|
|
702
|
+
|| normalizeVersion(r.interface?.version)
|
|
703
|
+
|| normalizeVersion(r.extensions?.['com.openai']?.version)
|
|
704
|
+
|| normalizeVersion(manifest?.version)
|
|
705
|
+
|| marketVersion
|
|
247
706
|
return normalizeRow({ ...manifest, ...r,
|
|
707
|
+
version: resolvedVersion,
|
|
248
708
|
displayName: r.displayName || r.interface?.displayName || manifest?.displayName,
|
|
249
709
|
description: r.description || r.interface?.shortDescription || manifest?.description,
|
|
250
|
-
}, sourceId, dir)
|
|
710
|
+
}, sourceId, dir, { ...options, pluginRootMeta })
|
|
251
711
|
}).filter(Boolean)
|
|
252
712
|
if (rows.length > 0) return rows
|
|
253
713
|
// Preserve manifest precedence and discovery fallbacks on a miss.
|
|
254
|
-
if (skipped) return parseMarketplaceFromDisk(sourceId, cache)
|
|
714
|
+
if (skipped) return parseMarketplaceFromDisk(sourceId, cache, undefined, options)
|
|
255
715
|
}
|
|
256
716
|
// Case B: Direct array of plugin descriptors
|
|
257
717
|
if (Array.isArray(content)) {
|
|
258
|
-
const rows = content.map((r) =>
|
|
718
|
+
const rows = content.map((r) => {
|
|
719
|
+
const { source, dir } = resolveCaseAEntryDir(sourceId, cache, r)
|
|
720
|
+
if (source === null) return null
|
|
721
|
+
const manifest = dir ? readPluginManifest(dir, false) : null
|
|
722
|
+
const resolvedVersion =
|
|
723
|
+
normalizeVersion(r?.version)
|
|
724
|
+
|| normalizeVersion(r?.interface?.version)
|
|
725
|
+
|| normalizeVersion(r?.extensions?.['com.openai']?.version)
|
|
726
|
+
|| normalizeVersion(manifest?.version)
|
|
727
|
+
return normalizeRow({ ...manifest, ...r, version: resolvedVersion }, sourceId, dir, options)
|
|
728
|
+
}).filter(Boolean)
|
|
259
729
|
if (rows.length > 0) return rows
|
|
260
730
|
}
|
|
261
731
|
// Case C: MCP Servers dictionary (mcpServers or servers object)
|
|
262
|
-
const mcpDict = (content
|
|
263
|
-
? content.mcpServers
|
|
264
|
-
: ((content.servers && typeof content.servers === 'object') ? content.servers : null)
|
|
732
|
+
const mcpDict = resolveMcpDict(content)
|
|
265
733
|
if (mcpDict) {
|
|
266
734
|
const rows = []
|
|
267
735
|
for (const [srvName, srvCfg] of Object.entries(mcpDict)) {
|
|
@@ -272,7 +740,7 @@ export function parseMarketplaceFromDisk(sourceId, cache, names) {
|
|
|
272
740
|
author: srvCfg.author || content.author || 'MCP',
|
|
273
741
|
category: 'mcp',
|
|
274
742
|
source: './',
|
|
275
|
-
}, sourceId))
|
|
743
|
+
}, sourceId, undefined, options))
|
|
276
744
|
}
|
|
277
745
|
if (rows.filter(Boolean).length > 0) return rows.filter(Boolean)
|
|
278
746
|
}
|
|
@@ -289,7 +757,7 @@ export function parseMarketplaceFromDisk(sourceId, cache, names) {
|
|
|
289
757
|
try {
|
|
290
758
|
for (const entry of readdirSync(cache, { withFileTypes: true })) {
|
|
291
759
|
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
292
|
-
const row = parsePluginRowFromDir(join(cache, entry.name), entry.name, 'local')
|
|
760
|
+
const row = parsePluginRowFromDir(join(cache, entry.name), entry.name, 'local', options)
|
|
293
761
|
if (row) localRows.push(row)
|
|
294
762
|
}
|
|
295
763
|
}
|
|
@@ -299,25 +767,20 @@ export function parseMarketplaceFromDisk(sourceId, cache, names) {
|
|
|
299
767
|
}
|
|
300
768
|
|
|
301
769
|
// Explicit plugin manifests describe the whole package, including its skills.
|
|
302
|
-
if (
|
|
303
|
-
const row = parsePluginRowFromDir(cache, sourceId, sourceId)
|
|
304
|
-
if (row) return [{ ...row, source: './' }]
|
|
305
|
-
}
|
|
306
|
-
if (existsSync(join(cache, 'SKILL.md')) || existsSync(join(cache, 'skill.md'))) {
|
|
307
|
-
const row = parsePluginRowFromDir(cache, sourceId, sourceId)
|
|
770
|
+
if (hasExplicitRootPlugin(cache)) {
|
|
771
|
+
const row = parsePluginRowFromDir(cache, sourceId, sourceId, options)
|
|
308
772
|
if (row) return [{ ...row, source: './' }]
|
|
309
773
|
}
|
|
310
774
|
|
|
311
775
|
// 3. Monorepo subdirectories auto-discovery (plugins/*, skills/*, packages/*, tools/*, extensions/*)
|
|
312
|
-
const monoDirs = ['plugins', 'skills', 'packages', 'tools', 'extensions']
|
|
313
776
|
const monoRows = []
|
|
314
|
-
for (const sub of
|
|
777
|
+
for (const sub of MONO_DIRS) {
|
|
315
778
|
const subRoot = join(cache, sub)
|
|
316
779
|
if (existsSync(subRoot)) {
|
|
317
780
|
try {
|
|
318
781
|
for (const entry of readdirSync(subRoot, { withFileTypes: true })) {
|
|
319
782
|
if (entry.isDirectory()) {
|
|
320
|
-
const row = parsePluginRowFromDir(join(subRoot, entry.name), entry.name, sourceId)
|
|
783
|
+
const row = parsePluginRowFromDir(join(subRoot, entry.name), entry.name, sourceId, options)
|
|
321
784
|
if (row) {
|
|
322
785
|
row.source = `./${sub}/${entry.name}`
|
|
323
786
|
monoRows.push(row)
|
|
@@ -330,74 +793,34 @@ export function parseMarketplaceFromDisk(sourceId, cache, names) {
|
|
|
330
793
|
if (monoRows.filter(Boolean).length > 0) return monoRows.filter(Boolean)
|
|
331
794
|
|
|
332
795
|
// 3. Single Standalone Root Plugin Repository
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
const rootCommandsDir = join(cache, 'commands')
|
|
336
|
-
const rootAgentsDir = join(cache, 'agents')
|
|
337
|
-
const rootHooksDir = join(cache, 'hooks')
|
|
338
|
-
const rootMcp = join(cache, 'mcp.json')
|
|
339
|
-
const rootDotMcp = join(cache, '.mcp.json')
|
|
340
|
-
const rootServerJson = join(cache, 'server.json')
|
|
341
|
-
const rootPluginJson = join(cache, '.claude-plugin', 'plugin.json')
|
|
342
|
-
const rootCodexPluginJson = join(cache, '.codex-plugin', 'plugin.json')
|
|
343
|
-
const rootDirectPluginJson = join(cache, 'plugin.json')
|
|
344
|
-
const rootCursorRules = join(cache, '.cursor', 'rules')
|
|
345
|
-
const rootCursorRulesFile = join(cache, '.cursorrules')
|
|
346
|
-
const rootPkgJson = join(cache, 'package.json')
|
|
347
|
-
|
|
348
|
-
const isRootPlugin = existsSync(rootSkillMd)
|
|
349
|
-
|| existsSync(rootSkillsDir)
|
|
350
|
-
|| existsSync(rootCommandsDir)
|
|
351
|
-
|| existsSync(rootAgentsDir)
|
|
352
|
-
|| existsSync(rootHooksDir)
|
|
353
|
-
|| existsSync(rootMcp)
|
|
354
|
-
|| existsSync(rootDotMcp)
|
|
355
|
-
|| existsSync(rootServerJson)
|
|
356
|
-
|| existsSync(rootPluginJson)
|
|
357
|
-
|| existsSync(rootCodexPluginJson)
|
|
358
|
-
|| existsSync(rootDirectPluginJson)
|
|
359
|
-
|| existsSync(rootCursorRules)
|
|
360
|
-
|| existsSync(rootCursorRulesFile)
|
|
361
|
-
|| existsSync(rootPkgJson)
|
|
362
|
-
|
|
363
|
-
if (isRootPlugin) {
|
|
364
|
-
let name = sourceId
|
|
365
|
-
let displayName = formatDisplayName(sourceId)
|
|
366
|
-
let description = ''
|
|
367
|
-
let version = '1.0.0'
|
|
368
|
-
let author = undefined
|
|
369
|
-
|
|
370
|
-
const manifest = readPluginManifest(cache)
|
|
371
|
-
if (manifest) {
|
|
372
|
-
if (manifest.name) name = manifest.name
|
|
373
|
-
if (manifest.displayName) displayName = manifest.displayName
|
|
374
|
-
if (manifest.description) description = manifest.description
|
|
375
|
-
if (manifest.version) version = manifest.version
|
|
376
|
-
if (manifest.author) author = typeof manifest.author === 'string' ? manifest.author : manifest.author.name
|
|
377
|
-
} else if (existsSync(rootSkillMd)) {
|
|
378
|
-
try {
|
|
379
|
-
description = extractMdDescription(readFileSync(rootSkillMd, 'utf8'))
|
|
380
|
-
} catch {}
|
|
381
|
-
} else if (existsSync(join(cache, 'README.md'))) {
|
|
382
|
-
try {
|
|
383
|
-
description = extractMdDescription(readFileSync(join(cache, 'README.md'), 'utf8'))
|
|
384
|
-
} catch {}
|
|
385
|
-
}
|
|
386
|
-
|
|
796
|
+
const rootInfo = resolveStandaloneRootInfo(cache, sourceId, { includeMetadata: true })
|
|
797
|
+
if (rootInfo) {
|
|
387
798
|
return [normalizeRow({
|
|
388
|
-
...manifest,
|
|
389
|
-
name,
|
|
390
|
-
displayName,
|
|
391
|
-
description,
|
|
392
|
-
version,
|
|
393
|
-
author,
|
|
799
|
+
...rootInfo.manifest,
|
|
800
|
+
name: rootInfo.name,
|
|
801
|
+
displayName: rootInfo.displayName,
|
|
802
|
+
description: rootInfo.description,
|
|
803
|
+
version: rootInfo.version,
|
|
804
|
+
author: rootInfo.author,
|
|
394
805
|
source: './',
|
|
395
|
-
}, sourceId, cache)].filter(Boolean)
|
|
806
|
+
}, sourceId, cache, options)].filter(Boolean)
|
|
396
807
|
}
|
|
397
808
|
|
|
398
809
|
return []
|
|
399
810
|
}
|
|
400
811
|
|
|
812
|
+
/** Display metadata from the same marketplace formats used for listing. */
|
|
813
|
+
export function readMarketplaceName(cache) {
|
|
814
|
+
for (const parts of MANIFEST_CANDIDATE_PARTS) {
|
|
815
|
+
try {
|
|
816
|
+
const market = JSON.parse(readFileSync(join(cache, ...parts), 'utf8'))
|
|
817
|
+
if (!Array.isArray(market?.plugins) || !market.plugins.length) continue
|
|
818
|
+
return [market.displayName, market.title, market.name]
|
|
819
|
+
.find((value) => typeof value === 'string' && value.trim())?.trim()
|
|
820
|
+
} catch {}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
401
824
|
/** Resolve the directory that holds a plugin's content (cache or remote checkout). */
|
|
402
825
|
export function pluginContentDir(sourceId, pluginName, source, preferInstalled = true) {
|
|
403
826
|
safeSegment(sourceId, 'source id')
|
|
@@ -419,14 +842,13 @@ export function pluginContentDir(sourceId, pluginName, source, preferInstalled =
|
|
|
419
842
|
}
|
|
420
843
|
|
|
421
844
|
// Check if in remote git cache
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
845
|
+
const remoteSrc = normalizeRemotePluginSource(source)
|
|
846
|
+
if (remoteSrc && typeof remoteSrc === 'object' && (remoteSrc.source === 'url' || remoteSrc.source === 'git-subdir' || remoteSrc.source === 'github')) {
|
|
847
|
+
if (typeof remoteSrc.url === 'string' && remoteSrc.url) {
|
|
848
|
+
const ownDir = sourceRepositoryDir(sourceCacheDir(sourceId), remoteSrc)
|
|
425
849
|
if (ownDir) return ownDir
|
|
426
|
-
const
|
|
427
|
-
const
|
|
428
|
-
const checkout = join(sourceCacheDir('remote'), remoteKey)
|
|
429
|
-
const dir = source.path ? pluginPath(checkout, source.path) : checkout
|
|
850
|
+
const checkout = remoteCheckoutDir(remoteSrc.url, remoteSrc.ref)
|
|
851
|
+
const dir = remoteSrc.path ? pluginPath(checkout, remoteSrc.path) : checkout
|
|
430
852
|
return existsSync(dir) ? dir : null
|
|
431
853
|
}
|
|
432
854
|
}
|
|
@@ -436,7 +858,7 @@ export function pluginContentDir(sourceId, pluginName, source, preferInstalled =
|
|
|
436
858
|
return existsSync(fallback) ? fallback : null
|
|
437
859
|
}
|
|
438
860
|
|
|
439
|
-
/** Read plugin metadata with Claude precedence
|
|
861
|
+
/** Read plugin metadata with Claude/portable precedence and Codex overlay merge. */
|
|
440
862
|
export function readPluginManifest(dir, includeParent = true) {
|
|
441
863
|
const rootManifest = join(dir, 'plugin.json')
|
|
442
864
|
let portable = false
|
|
@@ -451,12 +873,14 @@ export function readPluginManifest(dir, includeParent = true) {
|
|
|
451
873
|
...(portable ? [rootManifest] : []),
|
|
452
874
|
join(dir, '.codex-plugin', 'plugin.json'),
|
|
453
875
|
join(dir, '.claude-plugin', 'marketplace.json'),
|
|
876
|
+
join(dir, '.agents', 'plugins', 'marketplace.json'),
|
|
454
877
|
rootManifest,
|
|
455
878
|
join(dir, 'manifest.json'),
|
|
456
879
|
join(dir, 'server.json'),
|
|
457
880
|
join(dir, 'package.json'),
|
|
458
881
|
...(includeParent ? [join(dir, '..', '.claude-plugin', 'plugin.json'),
|
|
459
882
|
join(dir, '..', '.claude-plugin', 'marketplace.json'),
|
|
883
|
+
join(dir, '..', '.agents', 'plugins', 'marketplace.json'),
|
|
460
884
|
join(dir, '..', 'plugin.json'),
|
|
461
885
|
join(dir, '..', 'manifest.json')] : []),
|
|
462
886
|
]
|
|
@@ -466,12 +890,17 @@ export function readPluginManifest(dir, includeParent = true) {
|
|
|
466
890
|
try {
|
|
467
891
|
const raw = JSON.parse(readFileSync(p, 'utf8'))
|
|
468
892
|
if (p.endsWith('package.json')) {
|
|
469
|
-
if (raw['claude-plugin'])
|
|
893
|
+
if (raw['claude-plugin']) {
|
|
894
|
+
return {
|
|
895
|
+
...raw['claude-plugin'],
|
|
896
|
+
version: normalizeVersion(raw['claude-plugin']?.version) || normalizeVersion(raw.version),
|
|
897
|
+
}
|
|
898
|
+
}
|
|
470
899
|
return {
|
|
471
900
|
name: raw.name,
|
|
472
901
|
displayName: raw.displayName || formatDisplayName(raw.name),
|
|
473
902
|
description: raw.description,
|
|
474
|
-
version: raw.version,
|
|
903
|
+
version: normalizeVersion(raw.version),
|
|
475
904
|
author: raw.author,
|
|
476
905
|
mcpServers: raw.mcpServers,
|
|
477
906
|
lspServers: raw.lspServers,
|
|
@@ -483,26 +912,48 @@ export function readPluginManifest(dir, includeParent = true) {
|
|
|
483
912
|
name: matched.name || raw.name,
|
|
484
913
|
displayName: matched.displayName || formatDisplayName(matched.name || raw.name),
|
|
485
914
|
description: matched.description || raw.metadata?.description || '',
|
|
486
|
-
version: matched.version
|
|
915
|
+
version: normalizeVersion(matched.version)
|
|
916
|
+
|| normalizeVersion(matched.interface?.version)
|
|
917
|
+
|| normalizeVersion(matched.extensions?.['com.openai']?.version)
|
|
918
|
+
|| normalizeVersion(raw.metadata?.version)
|
|
919
|
+
|| normalizeVersion(raw.version),
|
|
487
920
|
author: matched.author || raw.owner?.name || undefined,
|
|
921
|
+
strict: matched.strict,
|
|
922
|
+
prompts: matched.prompts,
|
|
488
923
|
skills: matched.skills,
|
|
489
924
|
commands: matched.commands,
|
|
490
925
|
agents: matched.agents,
|
|
926
|
+
hooks: matched.hooks,
|
|
491
927
|
mcpServers: matched.mcpServers,
|
|
492
928
|
lspServers: matched.lspServers,
|
|
493
929
|
}
|
|
494
930
|
}
|
|
495
931
|
const openai = raw.extensions?.['com.openai']
|
|
496
|
-
|
|
932
|
+
let overlay = openai && typeof openai === 'object' && !Array.isArray(openai) ? openai : null
|
|
933
|
+
if (!overlay && (p === join(dir, '.claude-plugin', 'plugin.json') || p === rootManifest)) {
|
|
934
|
+
const codexPath = join(manifestRootDir(p), '.codex-plugin', 'plugin.json')
|
|
935
|
+
if (existsSync(codexPath)) {
|
|
936
|
+
try {
|
|
937
|
+
const codexRaw = JSON.parse(readFileSync(codexPath, 'utf8'))
|
|
938
|
+
if (codexRaw && typeof codexRaw === 'object') overlay = codexRaw
|
|
939
|
+
} catch {}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
const merged = overlay ? { ...overlay, ...raw } : raw
|
|
943
|
+
const iface = overlay?.interface || raw.interface || {}
|
|
944
|
+
const version =
|
|
945
|
+
normalizeVersion(raw.version)
|
|
946
|
+
|| normalizeVersion(overlay?.version)
|
|
947
|
+
|| normalizeVersion(iface.version)
|
|
948
|
+
|| readPackageVersion(manifestRootDir(p))
|
|
497
949
|
return {
|
|
498
|
-
...
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
homepage: raw.homepage || settings.interface?.websiteURL,
|
|
950
|
+
...merged,
|
|
951
|
+
name: raw.name || overlay?.name,
|
|
952
|
+
version,
|
|
953
|
+
displayName: raw.displayName || iface.displayName,
|
|
954
|
+
description: raw.description || iface.shortDescription || iface.longDescription || '',
|
|
955
|
+
author: raw.author || iface.developerName,
|
|
956
|
+
homepage: raw.homepage || iface.websiteURL,
|
|
506
957
|
}
|
|
507
958
|
} catch {}
|
|
508
959
|
}
|
|
@@ -510,81 +961,227 @@ export function readPluginManifest(dir, includeParent = true) {
|
|
|
510
961
|
return null
|
|
511
962
|
}
|
|
512
963
|
|
|
513
|
-
|
|
964
|
+
function scanCommandDirectory(cmdRoot, seenFiles, addCommandEntry, prefix = '') {
|
|
965
|
+
if (!cmdRoot || !existsSync(cmdRoot)) return
|
|
966
|
+
try {
|
|
967
|
+
const st = statSync(cmdRoot)
|
|
968
|
+
if (st.isFile()) {
|
|
969
|
+
if (/\.(md)$/i.test(cmdRoot)) {
|
|
970
|
+
const key = resolve(cmdRoot)
|
|
971
|
+
if (!seenFiles.has(key)) {
|
|
972
|
+
seenFiles.add(key)
|
|
973
|
+
const stem = basename(cmdRoot).replace(/\.md$/i, '')
|
|
974
|
+
const name = prefix || stem
|
|
975
|
+
addCommandEntry({ name, filePath: cmdRoot, content: null, description: '' })
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return
|
|
979
|
+
}
|
|
980
|
+
for (const entry of readdirSync(cmdRoot, { withFileTypes: true })) {
|
|
981
|
+
const fullPath = join(cmdRoot, entry.name)
|
|
982
|
+
if (entry.isFile() && entry.name.endsWith('.md') && !/^readme\.md$/i.test(entry.name)) {
|
|
983
|
+
const key = resolve(fullPath)
|
|
984
|
+
if (seenFiles.has(key)) continue
|
|
985
|
+
seenFiles.add(key)
|
|
986
|
+
const stem = entry.name.replace(/\.md$/i, '')
|
|
987
|
+
const name = prefix ? `${prefix}-${stem}` : stem
|
|
988
|
+
addCommandEntry({ name, filePath: fullPath, content: null, description: '' })
|
|
989
|
+
} else if (entry.isDirectory()) {
|
|
990
|
+
const nextPrefix = prefix ? `${prefix}-${entry.name}` : entry.name
|
|
991
|
+
const skillMd = join(fullPath, 'SKILL.md')
|
|
992
|
+
const altMd = join(fullPath, 'skill.md')
|
|
993
|
+
const directMd = existsSync(skillMd) ? skillMd : (existsSync(altMd) ? altMd : null)
|
|
994
|
+
if (directMd) {
|
|
995
|
+
const key = resolve(directMd)
|
|
996
|
+
if (!seenFiles.has(key)) {
|
|
997
|
+
seenFiles.add(key)
|
|
998
|
+
addCommandEntry({ name: nextPrefix, filePath: directMd, content: null, description: '' })
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
scanCommandDirectory(fullPath, seenFiles, addCommandEntry, nextPrefix)
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
} catch {}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/** Resolve disk/inline slash command entries from commands/ dirs and manifest.commands. */
|
|
1008
|
+
export function resolvePluginCommandEntries(dir, manifest = readPluginManifest(dir)) {
|
|
1009
|
+
const entries = []
|
|
1010
|
+
const seenNames = new Set()
|
|
1011
|
+
const seenFiles = new Set()
|
|
1012
|
+
const pushEntry = (item) => {
|
|
1013
|
+
if (!item?.name || seenNames.has(item.name)) return
|
|
1014
|
+
seenNames.add(item.name)
|
|
1015
|
+
entries.push(item)
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const candidateCmdRoots = [
|
|
1019
|
+
join(dir, 'commands'),
|
|
1020
|
+
join(dir, '.claude', 'commands'),
|
|
1021
|
+
]
|
|
1022
|
+
// A Claude plugin manifest owns a package root. Siblings are often
|
|
1023
|
+
// implementations for other hosts, not capabilities of this plugin.
|
|
1024
|
+
if (!existsSync(join(dir, '.claude-plugin', 'plugin.json'))) {
|
|
1025
|
+
candidateCmdRoots.splice(1, 0, join(dir, '..', 'commands'))
|
|
1026
|
+
candidateCmdRoots.push(join(dir, '..', '.claude', 'commands'))
|
|
1027
|
+
}
|
|
1028
|
+
const inlineFallbacks = []
|
|
1029
|
+
const declared = manifest?.commands
|
|
1030
|
+
if (typeof declared === 'string') {
|
|
1031
|
+
const resolved = resolvePluginSpecPath(dir, declared)
|
|
1032
|
+
if (resolved) candidateCmdRoots.push(resolved)
|
|
1033
|
+
} else if (Array.isArray(declared)) {
|
|
1034
|
+
for (const item of declared) {
|
|
1035
|
+
if (typeof item === 'string') {
|
|
1036
|
+
const resolved = resolvePluginSpecPath(dir, item)
|
|
1037
|
+
if (resolved && existsSync(resolved)) {
|
|
1038
|
+
candidateCmdRoots.push(resolved)
|
|
1039
|
+
} else {
|
|
1040
|
+
inlineFallbacks.push(item)
|
|
1041
|
+
}
|
|
1042
|
+
} else if (item && typeof item === 'object') {
|
|
1043
|
+
const rel = item.source || item.path || item.file
|
|
1044
|
+
const resolved = typeof rel === 'string' ? resolvePluginSpecPath(dir, rel) : null
|
|
1045
|
+
if (resolved && existsSync(resolved)) {
|
|
1046
|
+
if (statSync(resolved).isFile()) {
|
|
1047
|
+
const name = item.name || basename(resolved).replace(/\.md$/i, '')
|
|
1048
|
+
seenFiles.add(resolve(resolved))
|
|
1049
|
+
pushEntry({ name, filePath: resolved, content: null, description: item.description || '' })
|
|
1050
|
+
} else {
|
|
1051
|
+
candidateCmdRoots.push(resolved)
|
|
1052
|
+
}
|
|
1053
|
+
} else if (item.name) {
|
|
1054
|
+
if (typeof item.content === 'string') {
|
|
1055
|
+
pushEntry({
|
|
1056
|
+
name: item.name,
|
|
1057
|
+
filePath: null,
|
|
1058
|
+
content: item.content,
|
|
1059
|
+
description: item.description || '',
|
|
1060
|
+
})
|
|
1061
|
+
} else {
|
|
1062
|
+
inlineFallbacks.push({ name: item.name, description: item.description || '' })
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
} else if (declared && typeof declared === 'object') {
|
|
1068
|
+
for (const [cmdName, cfg] of Object.entries(declared)) {
|
|
1069
|
+
if (typeof cfg === 'string') {
|
|
1070
|
+
const resolved = resolvePluginSpecPath(dir, cfg)
|
|
1071
|
+
if (resolved && existsSync(resolved)) {
|
|
1072
|
+
if (statSync(resolved).isFile()) {
|
|
1073
|
+
seenFiles.add(resolve(resolved))
|
|
1074
|
+
pushEntry({ name: cmdName, filePath: resolved, content: null, description: '' })
|
|
1075
|
+
} else {
|
|
1076
|
+
scanCommandDirectory(resolved, seenFiles, pushEntry, cmdName)
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
inlineFallbacks.push({ name: cmdName, description: cfg })
|
|
1080
|
+
}
|
|
1081
|
+
} else if (cfg && typeof cfg === 'object') {
|
|
1082
|
+
const rel = cfg.source || cfg.path || cfg.file
|
|
1083
|
+
const resolved = typeof rel === 'string' ? resolvePluginSpecPath(dir, rel) : null
|
|
1084
|
+
if (resolved && existsSync(resolved) && statSync(resolved).isFile()) {
|
|
1085
|
+
seenFiles.add(resolve(resolved))
|
|
1086
|
+
pushEntry({ name: cmdName, filePath: resolved, content: null, description: cfg.description || '' })
|
|
1087
|
+
} else if (typeof cfg.content === 'string') {
|
|
1088
|
+
pushEntry({
|
|
1089
|
+
name: cmdName,
|
|
1090
|
+
filePath: null,
|
|
1091
|
+
content: cfg.content,
|
|
1092
|
+
description: cfg.description || '',
|
|
1093
|
+
})
|
|
1094
|
+
} else {
|
|
1095
|
+
inlineFallbacks.push({ name: cmdName, description: cfg.description || '' })
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
for (const cRoot of candidateCmdRoots) {
|
|
1102
|
+
scanCommandDirectory(cRoot, seenFiles, pushEntry)
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
return { entries, inlineFallbacks }
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/** List skill & command directories/files (skills/*, commands/*, root SKILL.md, manifest declarations). */
|
|
514
1109
|
export function listSkills(dir, manifest = readPluginManifest(dir)) {
|
|
515
1110
|
const out = []
|
|
516
1111
|
const seen = new Set()
|
|
517
1112
|
|
|
518
|
-
const addSkill = (name, skillMdPath) => {
|
|
1113
|
+
const addSkill = (name, skillMdPath, inlineContent = null, fallbackDesc = '') => {
|
|
519
1114
|
if (!name || seen.has(name)) return
|
|
520
1115
|
let description = ''
|
|
521
1116
|
if (skillMdPath) {
|
|
522
1117
|
try {
|
|
523
1118
|
description = extractMdDescription(readFileSync(skillMdPath, 'utf8'))
|
|
524
1119
|
} catch {}
|
|
1120
|
+
} else if (typeof inlineContent === 'string') {
|
|
1121
|
+
description = extractMdDescription(inlineContent)
|
|
525
1122
|
}
|
|
526
|
-
out.push({ name, command: `/${name}`, description })
|
|
1123
|
+
out.push({ name, command: `/${name}`, description: description || fallbackDesc || '' })
|
|
527
1124
|
seen.add(name)
|
|
528
1125
|
}
|
|
529
1126
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
} else if (entry.isFile() && entry.name.endsWith('.md') && !['README.md', 'CONTRIBUTING.md', 'LICENSE.md', 'CHANGELOG.md'].includes(entry.name)) {
|
|
553
|
-
const name = entry.name.replace(/\.md$/, '')
|
|
554
|
-
addSkill(name, join(sRoot, entry.name))
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
} catch {}
|
|
558
|
-
}
|
|
1127
|
+
const NON_SKILL_DIRS = new Set([
|
|
1128
|
+
'node_modules', '.git', '.agents', '.claude-plugin', '.codex-plugin', '.well-known',
|
|
1129
|
+
'agents', 'commands', 'prompts', 'hooks', '.cursor', 'docs', 'assets', 'eval',
|
|
1130
|
+
'staging', 'walkthroughs', 'mcp', 'lsp', 'scripts', 'server', 'dist', 'build', '__pycache__',
|
|
1131
|
+
])
|
|
1132
|
+
|
|
1133
|
+
// 1. Check skills/ and manifest.skills paths (including '.' and './...')
|
|
1134
|
+
const rawSkills = typeof manifest?.skills === 'string' ? [manifest.skills] : (Array.isArray(manifest?.skills) ? manifest.skills : [])
|
|
1135
|
+
const declaredSkillPaths = rawSkills
|
|
1136
|
+
.filter((s) => typeof s === 'string' && isDotRelativePath(s))
|
|
1137
|
+
.map((p) => resolvePluginSpecPath(dir, p))
|
|
1138
|
+
.filter(Boolean)
|
|
1139
|
+
const candidateSkillRoots = []
|
|
1140
|
+
const seenSkillRoots = new Set()
|
|
1141
|
+
const skillRoots = [...declaredSkillPaths, join(dir, 'skills')]
|
|
1142
|
+
if (!existsSync(join(dir, '.claude-plugin', 'plugin.json'))) skillRoots.push(join(dir, '..', 'skills'))
|
|
1143
|
+
for (const rootCandidate of skillRoots) {
|
|
1144
|
+
const resolvedRoot = resolve(rootCandidate)
|
|
1145
|
+
if (seenSkillRoots.has(resolvedRoot)) continue
|
|
1146
|
+
seenSkillRoots.add(resolvedRoot)
|
|
1147
|
+
candidateSkillRoots.push(rootCandidate)
|
|
559
1148
|
}
|
|
560
1149
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
1150
|
+
for (const sRoot of candidateSkillRoots) {
|
|
1151
|
+
if (!existsSync(sRoot)) continue
|
|
1152
|
+
try {
|
|
1153
|
+
if (statSync(sRoot).isFile()) {
|
|
1154
|
+
if (/^skill\.md$/i.test(basename(sRoot))) addSkill(basename(dirname(sRoot)), sRoot)
|
|
1155
|
+
else if (/\.md$/i.test(sRoot)) addSkill(basename(sRoot).replace(/\.md$/i, ''), sRoot)
|
|
1156
|
+
continue
|
|
1157
|
+
}
|
|
1158
|
+
const rootMd = ['SKILL.md', 'skill.md'].map((f) => join(sRoot, f)).find(existsSync)
|
|
1159
|
+
if (rootMd && resolve(sRoot) !== resolve(dir)) {
|
|
1160
|
+
addSkill(basename(sRoot), rootMd)
|
|
1161
|
+
}
|
|
1162
|
+
for (const entry of readdirSync(sRoot, { withFileTypes: true })) {
|
|
1163
|
+
if (entry.isDirectory()) {
|
|
1164
|
+
if (NON_SKILL_DIRS.has(entry.name) || entry.name.startsWith('.')) continue
|
|
1165
|
+
const skillMd = join(sRoot, entry.name, 'SKILL.md')
|
|
1166
|
+
const altMd = join(sRoot, entry.name, 'skill.md')
|
|
1167
|
+
if (existsSync(skillMd)) {
|
|
1168
|
+
addSkill(entry.name, skillMd)
|
|
1169
|
+
} else if (existsSync(altMd)) {
|
|
1170
|
+
addSkill(entry.name, altMd)
|
|
581
1171
|
}
|
|
1172
|
+
} else if (entry.isFile() && entry.name.endsWith('.md') && !['README.md', 'CONTRIBUTING.md', 'LICENSE.md', 'CHANGELOG.md', 'SKILL.md', 'skill.md'].includes(entry.name)) {
|
|
1173
|
+
const name = entry.name.replace(/\.md$/, '')
|
|
1174
|
+
addSkill(name, join(sRoot, entry.name))
|
|
582
1175
|
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
1176
|
+
}
|
|
1177
|
+
} catch {}
|
|
585
1178
|
}
|
|
586
1179
|
|
|
587
|
-
|
|
1180
|
+
// 2. Check commands/ and .claude/commands/ and manifest.commands
|
|
1181
|
+
const { entries: cmdEntries, inlineFallbacks: cmdFallbacks } = resolvePluginCommandEntries(dir, manifest)
|
|
1182
|
+
for (const cmd of cmdEntries) {
|
|
1183
|
+
addSkill(cmd.name, cmd.filePath, cmd.content, cmd.description)
|
|
1184
|
+
}
|
|
588
1185
|
|
|
589
1186
|
// 4. Single-skill repository fallback: if no skills/ or commands/ exist, check root SKILL.md
|
|
590
1187
|
if (out.length === 0) {
|
|
@@ -600,14 +1197,14 @@ export function listSkills(dir, manifest = readPluginManifest(dir)) {
|
|
|
600
1197
|
}
|
|
601
1198
|
}
|
|
602
1199
|
|
|
603
|
-
// 5.
|
|
1200
|
+
// 5. Fallback for non-path entries declared in manifest.skills / manifest.commands
|
|
604
1201
|
if (manifest && out.length === 0) {
|
|
605
1202
|
if (Array.isArray(manifest.skills)) {
|
|
606
1203
|
for (const item of manifest.skills) {
|
|
607
1204
|
const rawName = typeof item === 'string' ? item : item?.name
|
|
608
1205
|
if (rawName) {
|
|
609
1206
|
const name = basename(rawName).replace(/\.(md|mdc)$/i, '')
|
|
610
|
-
if (name && !['skills', 'commands'].includes(name.toLowerCase()) && !seen.has(name)) {
|
|
1207
|
+
if (name && !['.', 'skills', 'commands'].includes(name.toLowerCase()) && !seen.has(name)) {
|
|
611
1208
|
seen.add(name)
|
|
612
1209
|
out.push({
|
|
613
1210
|
name,
|
|
@@ -618,20 +1215,12 @@ export function listSkills(dir, manifest = readPluginManifest(dir)) {
|
|
|
618
1215
|
}
|
|
619
1216
|
}
|
|
620
1217
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
seen.add(name)
|
|
628
|
-
out.push({
|
|
629
|
-
name,
|
|
630
|
-
command: `/${name}`,
|
|
631
|
-
description: typeof item === 'object' ? item.description || '' : '',
|
|
632
|
-
})
|
|
633
|
-
}
|
|
634
|
-
}
|
|
1218
|
+
for (const item of cmdFallbacks) {
|
|
1219
|
+
const rawName = typeof item === 'string' ? item : item?.name
|
|
1220
|
+
const name = rawName ? basename(rawName).replace(/\.md$/i, '') : ''
|
|
1221
|
+
if (name && !['.', 'skills', 'commands'].includes(name.toLowerCase()) && !seen.has(name)) {
|
|
1222
|
+
seen.add(name)
|
|
1223
|
+
out.push({ name, command: `/${name}`, description: typeof item === 'object' ? (item.description || '') : '' })
|
|
635
1224
|
}
|
|
636
1225
|
}
|
|
637
1226
|
}
|
|
@@ -639,123 +1228,167 @@ export function listSkills(dir, manifest = readPluginManifest(dir)) {
|
|
|
639
1228
|
return out
|
|
640
1229
|
}
|
|
641
1230
|
|
|
642
|
-
/** List agent definition files (agents
|
|
1231
|
+
/** List agent definition files (agents/<subpath>/*.yaml|yml|md|json, .well-known/agent-card.json, agent.json, manifest.agents). */
|
|
643
1232
|
export function listAgents(dir, manifest = readPluginManifest(dir)) {
|
|
644
1233
|
const out = []
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
const candidateAgentRoots = [
|
|
648
|
-
join(dir, 'agents'),
|
|
649
|
-
join(dir, '.agents'),
|
|
650
|
-
join(dir, '..', 'agents'),
|
|
651
|
-
join(dir, '..', '.agents'),
|
|
652
|
-
join(dir, '.claude-plugin', 'agents'),
|
|
653
|
-
join(dir, '..', '.claude-plugin', 'agents'),
|
|
654
|
-
]
|
|
655
|
-
|
|
1234
|
+
const seenFiles = new Set()
|
|
1235
|
+
const seenNames = new Set()
|
|
656
1236
|
const pluginName = basename(dir)
|
|
657
1237
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
seen.add(entry.name)
|
|
672
|
-
out.push({
|
|
673
|
-
file: entry.name,
|
|
674
|
-
name: parsed.name,
|
|
675
|
-
displayName: parsed.displayName || parsed.name,
|
|
676
|
-
description: parsed.description,
|
|
677
|
-
tools: parsed.tools,
|
|
678
|
-
model: parsed.model,
|
|
679
|
-
instructions: parsed.instructions,
|
|
680
|
-
raw,
|
|
681
|
-
})
|
|
682
|
-
continue
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
} catch { /* skip */ }
|
|
686
|
-
|
|
687
|
-
// Fallback if parsing failed
|
|
688
|
-
seen.add(entry.name)
|
|
689
|
-
const fallbackName = entry.name.replace(/\.[^.]+$/, '')
|
|
1238
|
+
const addAgentFile = (filePath, labelName) => {
|
|
1239
|
+
const absPath = resolve(filePath)
|
|
1240
|
+
if (seenFiles.has(absPath)) return
|
|
1241
|
+
seenFiles.add(absPath)
|
|
1242
|
+
const fileLabel = labelName.replace(/\\/g, '/')
|
|
1243
|
+
try {
|
|
1244
|
+
const raw = readFileSync(filePath, 'utf8')
|
|
1245
|
+
if (raw) {
|
|
1246
|
+
const parsed = parseAgentDefinition(pluginName, fileLabel, raw)
|
|
1247
|
+
if (parsed && !parsed.error) {
|
|
1248
|
+
const dedupeKey = parsed.name || fileLabel
|
|
1249
|
+
if (seenNames.has(dedupeKey)) return
|
|
1250
|
+
seenNames.add(dedupeKey)
|
|
690
1251
|
out.push({
|
|
691
|
-
file:
|
|
692
|
-
name:
|
|
693
|
-
displayName:
|
|
694
|
-
description:
|
|
695
|
-
tools:
|
|
696
|
-
model:
|
|
697
|
-
instructions:
|
|
698
|
-
raw
|
|
1252
|
+
file: fileLabel,
|
|
1253
|
+
name: parsed.name,
|
|
1254
|
+
displayName: parsed.displayName || parsed.name,
|
|
1255
|
+
description: parsed.description,
|
|
1256
|
+
tools: parsed.tools,
|
|
1257
|
+
model: parsed.model,
|
|
1258
|
+
instructions: parsed.instructions,
|
|
1259
|
+
raw,
|
|
699
1260
|
})
|
|
1261
|
+
return
|
|
700
1262
|
}
|
|
701
|
-
}
|
|
1263
|
+
}
|
|
1264
|
+
} catch { /* skip */ }
|
|
1265
|
+
|
|
1266
|
+
const fallbackName = basename(fileLabel).replace(/\.[^.]+$/, '')
|
|
1267
|
+
if (seenNames.has(fallbackName)) return
|
|
1268
|
+
seenNames.add(fallbackName)
|
|
1269
|
+
out.push({
|
|
1270
|
+
file: fileLabel,
|
|
1271
|
+
name: fallbackName,
|
|
1272
|
+
displayName: formatDisplayName(fallbackName),
|
|
1273
|
+
description: 'Autonomous sub-agent workflow',
|
|
1274
|
+
tools: null,
|
|
1275
|
+
model: null,
|
|
1276
|
+
instructions: '',
|
|
1277
|
+
raw: null,
|
|
1278
|
+
})
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
const walkAgentDir = (rootDir, prefix = '', allowRecurse = true) => {
|
|
1282
|
+
if (!existsSync(rootDir)) return
|
|
1283
|
+
try {
|
|
1284
|
+
const st = statSync(rootDir)
|
|
1285
|
+
if (st.isFile()) {
|
|
1286
|
+
if (/\.(ya?ml|md|json)$/i.test(rootDir)) {
|
|
1287
|
+
addAgentFile(rootDir, (relative(dir, rootDir) || basename(rootDir)).replace(/\\/g, '/'))
|
|
1288
|
+
}
|
|
1289
|
+
return
|
|
1290
|
+
}
|
|
1291
|
+
for (const entry of readdirSync(rootDir, { withFileTypes: true })) {
|
|
1292
|
+
if (entry.name === 'node_modules' || entry.name === '.git') continue
|
|
1293
|
+
const full = join(rootDir, entry.name)
|
|
1294
|
+
const relLabel = prefix ? `${prefix}/${entry.name}` : entry.name
|
|
1295
|
+
if (entry.isFile() && /\.(ya?ml|md|json)$/i.test(entry.name)) {
|
|
1296
|
+
addAgentFile(full, relLabel)
|
|
1297
|
+
} else if (entry.isDirectory() && allowRecurse && entry.name !== 'plugins' && entry.name !== 'skills') {
|
|
1298
|
+
walkAgentDir(full, relLabel, true)
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
} catch {}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
const declaredAgents = typeof manifest?.agents === 'string'
|
|
1305
|
+
? [manifest.agents]
|
|
1306
|
+
: (Array.isArray(manifest?.agents) ? manifest.agents : [])
|
|
1307
|
+
const fallbackAgentItems = []
|
|
1308
|
+
|
|
1309
|
+
// Explicit manifest paths resolved first (supports nested files and custom subdirs like './custom-agents')
|
|
1310
|
+
for (const item of declaredAgents) {
|
|
1311
|
+
const spec = typeof item === 'string' ? item : (item?.source || item?.path || item?.file)
|
|
1312
|
+
if (typeof spec === 'string') {
|
|
1313
|
+
const resolved = resolvePluginSpecPath(dir, spec)
|
|
1314
|
+
if (resolved && existsSync(resolved)) {
|
|
1315
|
+
const relPrefix = relative(dir, resolved).replace(/\\/g, '/')
|
|
1316
|
+
const initPrefix = (!relPrefix || relPrefix === '.' || relPrefix === 'agents' || relPrefix === '.agents' || relPrefix === '.claude-plugin/agents')
|
|
1317
|
+
? ''
|
|
1318
|
+
: relPrefix
|
|
1319
|
+
walkAgentDir(resolved, initPrefix, true)
|
|
1320
|
+
continue
|
|
1321
|
+
}
|
|
702
1322
|
}
|
|
1323
|
+
fallbackAgentItems.push(item)
|
|
703
1324
|
}
|
|
704
1325
|
|
|
1326
|
+
walkAgentDir(join(dir, 'agents'), '', true)
|
|
1327
|
+
walkAgentDir(join(dir, '.agents'), '', false)
|
|
1328
|
+
walkAgentDir(join(dir, '..', 'agents'), '', true)
|
|
1329
|
+
walkAgentDir(join(dir, '..', '.agents'), '', false)
|
|
1330
|
+
walkAgentDir(join(dir, '.claude-plugin', 'agents'), '', true)
|
|
1331
|
+
walkAgentDir(join(dir, '..', '.claude-plugin', 'agents'), '', true)
|
|
1332
|
+
|
|
705
1333
|
// Check Agent Card format (.well-known/agent-card.json or agent.json)
|
|
706
1334
|
for (const agentCardPath of [join(dir, '.well-known', 'agent-card.json'), join(dir, 'agent.json')]) {
|
|
707
|
-
if (existsSync(agentCardPath) && !
|
|
1335
|
+
if (existsSync(agentCardPath) && !seenFiles.has(resolve(agentCardPath))) {
|
|
1336
|
+
seenFiles.add(resolve(agentCardPath))
|
|
708
1337
|
try {
|
|
709
1338
|
const raw = readFileSync(agentCardPath, 'utf8')
|
|
710
1339
|
const parsed = parseAgentDefinition(pluginName, basename(agentCardPath), raw)
|
|
711
|
-
seen.add(basename(agentCardPath))
|
|
712
1340
|
if (parsed && !parsed.error) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
1341
|
+
if (!seenNames.has(parsed.name)) {
|
|
1342
|
+
seenNames.add(parsed.name)
|
|
1343
|
+
out.push({
|
|
1344
|
+
file: basename(agentCardPath),
|
|
1345
|
+
name: parsed.name,
|
|
1346
|
+
displayName: parsed.displayName || parsed.name,
|
|
1347
|
+
description: parsed.description,
|
|
1348
|
+
tools: parsed.tools,
|
|
1349
|
+
model: parsed.model,
|
|
1350
|
+
instructions: parsed.instructions,
|
|
1351
|
+
raw,
|
|
1352
|
+
})
|
|
1353
|
+
}
|
|
723
1354
|
} else {
|
|
724
1355
|
const jsonDoc = JSON.parse(raw)
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
1356
|
+
const agentName = jsonDoc.name || basename(dir)
|
|
1357
|
+
if (!seenNames.has(agentName)) {
|
|
1358
|
+
seenNames.add(agentName)
|
|
1359
|
+
out.push({
|
|
1360
|
+
file: basename(agentCardPath),
|
|
1361
|
+
name: agentName,
|
|
1362
|
+
displayName: jsonDoc.displayName || formatDisplayName(agentName),
|
|
1363
|
+
description: jsonDoc.description || '',
|
|
1364
|
+
tools: jsonDoc.tools || null,
|
|
1365
|
+
model: jsonDoc.model || null,
|
|
1366
|
+
instructions: jsonDoc.instructions || '',
|
|
1367
|
+
raw,
|
|
1368
|
+
})
|
|
1369
|
+
}
|
|
735
1370
|
}
|
|
736
1371
|
} catch {}
|
|
737
1372
|
}
|
|
738
1373
|
}
|
|
739
1374
|
|
|
740
|
-
//
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
})
|
|
758
|
-
}
|
|
1375
|
+
// Fallback for non-path items declared in manifest.agents
|
|
1376
|
+
for (const item of fallbackAgentItems) {
|
|
1377
|
+
const rawName = typeof item === 'string' ? item : item?.name
|
|
1378
|
+
if (rawName && !seenNames.has(rawName)) {
|
|
1379
|
+
seenNames.add(rawName)
|
|
1380
|
+
const name = typeof item === 'string' ? item : (item.name || rawName)
|
|
1381
|
+
const displayName = typeof item === 'object' && item.displayName ? item.displayName : (typeof item === 'object' && item.name ? item.name : formatDisplayName(name))
|
|
1382
|
+
out.push({
|
|
1383
|
+
file: typeof item === 'object' && item.file ? item.file : `${name}.md`,
|
|
1384
|
+
name,
|
|
1385
|
+
displayName,
|
|
1386
|
+
description: typeof item === 'object' ? item.description || '' : '',
|
|
1387
|
+
tools: typeof item === 'object' ? item.tools || null : null,
|
|
1388
|
+
model: typeof item === 'object' ? item.model || null : null,
|
|
1389
|
+
instructions: '',
|
|
1390
|
+
raw: null,
|
|
1391
|
+
})
|
|
759
1392
|
}
|
|
760
1393
|
}
|
|
761
1394
|
|
|
@@ -798,24 +1431,34 @@ function formatHookEventName(evt) {
|
|
|
798
1431
|
return map[evt] || evt
|
|
799
1432
|
}
|
|
800
1433
|
|
|
801
|
-
|
|
802
|
-
* Parse hook event names from a Claude/Codex hook config file's content.
|
|
803
|
-
* Accepts `{ hooks: {...} }`, a doubly-nested `{ hooks: { hooks: {...} } }`,
|
|
804
|
-
* or a bare event map. Never treats implementation scripts as hooks.
|
|
805
|
-
*/
|
|
806
|
-
export function parseHookConfig(raw, isJson) {
|
|
807
|
-
const out = []
|
|
1434
|
+
function extractHookEventMap(raw, isJson) {
|
|
808
1435
|
let parsed
|
|
809
1436
|
try {
|
|
810
1437
|
parsed = isJson ? JSON.parse(raw) : parseYaml(raw)
|
|
811
1438
|
} catch {
|
|
812
|
-
return
|
|
1439
|
+
return null
|
|
813
1440
|
}
|
|
814
|
-
|
|
1441
|
+
return unwrapHookObject(parsed)
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function unwrapHookObject(parsed) {
|
|
1445
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return null
|
|
815
1446
|
let hookObj = (parsed.hooks && typeof parsed.hooks === 'object' && !Array.isArray(parsed.hooks)) ? parsed.hooks : parsed
|
|
816
1447
|
if (hookObj && typeof hookObj === 'object' && !Array.isArray(hookObj) && typeof hookObj.hooks === 'object' && !Array.isArray(hookObj.hooks)) {
|
|
817
1448
|
hookObj = hookObj.hooks
|
|
818
1449
|
}
|
|
1450
|
+
return hookObj
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
/**
|
|
1454
|
+
* Parse hook event names from a Claude/Codex hook config file's content.
|
|
1455
|
+
* Accepts `{ hooks: {...} }`, a doubly-nested `{ hooks: { hooks: {...} } }`,
|
|
1456
|
+
* or a bare event map. Never treats implementation scripts as hooks.
|
|
1457
|
+
*/
|
|
1458
|
+
export function parseHookConfig(raw, isJson) {
|
|
1459
|
+
const out = []
|
|
1460
|
+
const hookObj = extractHookEventMap(raw, isJson)
|
|
1461
|
+
if (!hookObj) return out
|
|
819
1462
|
for (const [eventName, val] of Object.entries(hookObj)) {
|
|
820
1463
|
const formattedEvent = formatHookEventName(eventName)
|
|
821
1464
|
if (Array.isArray(val)) {
|
|
@@ -833,31 +1476,82 @@ export function parseHookConfig(raw, isJson) {
|
|
|
833
1476
|
return out
|
|
834
1477
|
}
|
|
835
1478
|
|
|
1479
|
+
function collectHookSources(dir, manifest = readPluginManifest(dir)) {
|
|
1480
|
+
const sources = []
|
|
1481
|
+
const seenFiles = new Set()
|
|
1482
|
+
|
|
1483
|
+
const addFile = (filePath) => {
|
|
1484
|
+
if (!filePath || !existsSync(filePath)) return false
|
|
1485
|
+
try {
|
|
1486
|
+
if (!statSync(filePath).isFile()) return false
|
|
1487
|
+
const key = resolve(filePath)
|
|
1488
|
+
if (seenFiles.has(key)) return true
|
|
1489
|
+
seenFiles.add(key)
|
|
1490
|
+
sources.push({ type: 'file', path: filePath, isJson: /\.json$/i.test(filePath) })
|
|
1491
|
+
return true
|
|
1492
|
+
} catch {
|
|
1493
|
+
return false
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
const addInlineItem = (item) => {
|
|
1498
|
+
if (typeof item === 'string') {
|
|
1499
|
+
const resolved = resolvePluginSpecPath(dir, item)
|
|
1500
|
+
if (resolved && addFile(resolved)) return
|
|
1501
|
+
if (!/\.(json|ya?ml)$/i.test(item) && !isDotRelativePath(item)) {
|
|
1502
|
+
sources.push({ type: 'label', label: item })
|
|
1503
|
+
}
|
|
1504
|
+
return
|
|
1505
|
+
}
|
|
1506
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
1507
|
+
if (typeof item.name === 'string' && !item.hooks && Object.keys(item).length <= 2) {
|
|
1508
|
+
sources.push({ type: 'label', label: item.name })
|
|
1509
|
+
return
|
|
1510
|
+
}
|
|
1511
|
+
const eventMap = unwrapHookObject(item)
|
|
1512
|
+
if (eventMap && Object.keys(eventMap).length > 0) {
|
|
1513
|
+
sources.push({ type: 'inline', eventMap })
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
if (manifest?.hooks !== undefined) {
|
|
1519
|
+
if (Array.isArray(manifest.hooks)) {
|
|
1520
|
+
for (const item of manifest.hooks) addInlineItem(item)
|
|
1521
|
+
} else {
|
|
1522
|
+
addInlineItem(manifest.hooks)
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
const hooksRoot = join(dir, 'hooks')
|
|
1527
|
+
if (existsSync(hooksRoot)) {
|
|
1528
|
+
for (const fixedName of ['hooks.json', 'hooks.yaml', 'hooks.yml']) {
|
|
1529
|
+
if (addFile(join(hooksRoot, fixedName))) break
|
|
1530
|
+
}
|
|
1531
|
+
if (seenFiles.size === 0) {
|
|
1532
|
+
try {
|
|
1533
|
+
const dialect = readdirSync(hooksRoot)
|
|
1534
|
+
.filter((n) => /-hooks\.(json|ya?ml)$/i.test(n) && statSync(join(hooksRoot, n)).isFile())
|
|
1535
|
+
.sort((a, b) => {
|
|
1536
|
+
const score = (n) => (/claude/i.test(n) ? 0 : (/codex/i.test(n) ? 1 : 2))
|
|
1537
|
+
return score(a) - score(b)
|
|
1538
|
+
})
|
|
1539
|
+
if (dialect.length > 0) addFile(join(hooksRoot, dialect[0]))
|
|
1540
|
+
} catch {}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
return sources
|
|
1545
|
+
}
|
|
1546
|
+
|
|
836
1547
|
/**
|
|
837
1548
|
* Resolve the plugin's Claude/Codex hook config file path: the manifest `hooks`
|
|
838
1549
|
* path first, then `hooks/hooks.json|yaml|yml`, then `*-hooks.{json,yaml}` files.
|
|
839
1550
|
* Returns null when the plugin declares no hook config (e.g. only scripts).
|
|
840
1551
|
*/
|
|
841
1552
|
export function resolveHookConfigPath(dir, manifest = readPluginManifest(dir)) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
if (existsSync(p) && statSync(p).isFile()) return p
|
|
845
|
-
}
|
|
846
|
-
const hooksRoot = join(dir, 'hooks')
|
|
847
|
-
if (existsSync(hooksRoot)) {
|
|
848
|
-
const fixed = ['hooks.json', 'hooks.yaml', 'hooks.yml'].map((n) => join(hooksRoot, n)).find((p) => existsSync(p) && statSync(p).isFile())
|
|
849
|
-
if (fixed) return fixed
|
|
850
|
-
try {
|
|
851
|
-
const dialect = readdirSync(hooksRoot)
|
|
852
|
-
.filter((n) => /-hooks\.(json|ya?ml)$/i.test(n) && statSync(join(hooksRoot, n)).isFile())
|
|
853
|
-
.sort((a, b) => {
|
|
854
|
-
const score = (n) => (/claude/i.test(n) ? 0 : (/codex/i.test(n) ? 1 : 2))
|
|
855
|
-
return score(a) - score(b)
|
|
856
|
-
})
|
|
857
|
-
if (dialect.length > 0) return join(hooksRoot, dialect[0])
|
|
858
|
-
} catch {}
|
|
859
|
-
}
|
|
860
|
-
return null
|
|
1553
|
+
const firstFile = collectHookSources(dir, manifest).find((s) => s.type === 'file')
|
|
1554
|
+
return firstFile ? firstFile.path : null
|
|
861
1555
|
}
|
|
862
1556
|
|
|
863
1557
|
/** Hook entries: follow the plugin manifest's `hooks` config, then hooks/ config files. */
|
|
@@ -866,26 +1560,90 @@ export function listHooks(dir, manifest = readPluginManifest(dir)) {
|
|
|
866
1560
|
const seen = new Set()
|
|
867
1561
|
const add = (h) => { if (h && !seen.has(h)) { seen.add(h); hooks.push(h) } }
|
|
868
1562
|
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1563
|
+
for (const src of collectHookSources(dir, manifest)) {
|
|
1564
|
+
if (src.type === 'file') {
|
|
1565
|
+
try {
|
|
1566
|
+
const raw = readFileSync(src.path, 'utf8')
|
|
1567
|
+
for (const h of parseHookConfig(raw, src.isJson)) add(h)
|
|
1568
|
+
} catch {}
|
|
1569
|
+
} else if (src.type === 'inline') {
|
|
1570
|
+
for (const h of parseHookConfig(JSON.stringify({ hooks: src.eventMap }), true)) add(h)
|
|
1571
|
+
} else if (src.type === 'label') {
|
|
1572
|
+
add(src.label)
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
return hooks
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
function formatHookCmdArg(arg) {
|
|
1580
|
+
return /[\s"'\\$`]/.test(arg) ? JSON.stringify(arg) : arg
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
/**
|
|
1584
|
+
* Compile all Claude/Codex hook sources (JSON, YAML, inline objects, mixed arrays,
|
|
1585
|
+
* `args` arrays, and builtin variables) into a single JSON structure compatible
|
|
1586
|
+
* with `@deepseek-ai/dsh-hooks-claude-code`. Returns null if no hook rules exist.
|
|
1587
|
+
*/
|
|
1588
|
+
export function compileResolvedHooks(pluginRoot, manifest = readPluginManifest(pluginRoot), explicitDataDir) {
|
|
1589
|
+
const compiled = {}
|
|
1590
|
+
const eventMaps = []
|
|
1591
|
+
|
|
1592
|
+
for (const src of collectHookSources(pluginRoot, manifest)) {
|
|
1593
|
+
if (src.type === 'file') {
|
|
1594
|
+
try {
|
|
1595
|
+
const map = extractHookEventMap(readFileSync(src.path, 'utf8'), src.isJson)
|
|
1596
|
+
if (map) eventMaps.push(map)
|
|
1597
|
+
} catch {}
|
|
1598
|
+
} else if (src.type === 'inline') {
|
|
1599
|
+
eventMaps.push(src.eventMap)
|
|
1600
|
+
}
|
|
875
1601
|
}
|
|
876
1602
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1603
|
+
for (const eventMap of eventMaps) {
|
|
1604
|
+
for (const [eventName, val] of Object.entries(eventMap)) {
|
|
1605
|
+
const rules = Array.isArray(val) ? val : (val && typeof val === 'object' ? [val] : [])
|
|
1606
|
+
for (const rule of rules) {
|
|
1607
|
+
if (!rule || typeof rule !== 'object') continue
|
|
1608
|
+
const rawInner = Array.isArray(rule.hooks) ? rule.hooks : (rule.command || rule.type ? [rule] : [])
|
|
1609
|
+
const compiledInner = []
|
|
1610
|
+
for (const h of rawInner) {
|
|
1611
|
+
if (!h || typeof h !== 'object') continue
|
|
1612
|
+
if (h.type === undefined || h.type === 'command') {
|
|
1613
|
+
let cmd = typeof h.command === 'string' ? expandPluginVars(h.command, pluginRoot, explicitDataDir).trim() : ''
|
|
1614
|
+
if (pluginRoot && /^\.\.?[\\/]/.test(cmd)) {
|
|
1615
|
+
const m = cmd.match(/^(\S+)([\s\S]*)$/)
|
|
1616
|
+
if (m) {
|
|
1617
|
+
const resolvedBin = resolvePluginCommand(m[1], pluginRoot, explicitDataDir)
|
|
1618
|
+
cmd = resolvedBin ? `${resolvedBin}${m[2]}` : ''
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
if (Array.isArray(h.args) && h.args.length > 0) {
|
|
1622
|
+
const extraArgs = h.args.map((a) => {
|
|
1623
|
+
const expanded = expandPluginVars(String(a), pluginRoot, explicitDataDir)
|
|
1624
|
+
return formatHookCmdArg(expanded)
|
|
1625
|
+
})
|
|
1626
|
+
cmd = [cmd, ...extraArgs].filter(Boolean).join(' ')
|
|
1627
|
+
}
|
|
1628
|
+
if (!cmd) continue
|
|
1629
|
+
const { args: _droppedArgs, ...rest } = h
|
|
1630
|
+
compiledInner.push({ ...rest, type: 'command', command: cmd })
|
|
1631
|
+
} else {
|
|
1632
|
+
compiledInner.push(expandPluginVars(h, pluginRoot, explicitDataDir))
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
if (compiledInner.length > 0) {
|
|
1636
|
+
if (!compiled[eventName]) compiled[eventName] = []
|
|
1637
|
+
compiled[eventName].push({
|
|
1638
|
+
...(rule.matcher !== undefined ? { matcher: rule.matcher } : {}),
|
|
1639
|
+
hooks: compiledInner,
|
|
1640
|
+
})
|
|
1641
|
+
}
|
|
884
1642
|
}
|
|
885
1643
|
}
|
|
886
1644
|
}
|
|
887
1645
|
|
|
888
|
-
return hooks
|
|
1646
|
+
return Object.keys(compiled).length > 0 ? { hooks: compiled } : null
|
|
889
1647
|
}
|
|
890
1648
|
|
|
891
1649
|
/**
|
|
@@ -910,158 +1668,207 @@ export function isRemoteTransportName(type) {
|
|
|
910
1668
|
return type === 'http' || type === 'sse' || type === 'streamable-http' || type === 'streamableHttp'
|
|
911
1669
|
}
|
|
912
1670
|
|
|
913
|
-
|
|
1671
|
+
function extractConnectorDict(mcp) {
|
|
1672
|
+
if (!mcp || typeof mcp !== 'object' || Array.isArray(mcp)) return null
|
|
1673
|
+
if (mcp.mcpServers && typeof mcp.mcpServers === 'object') return mcp.mcpServers
|
|
1674
|
+
if (mcp.servers && typeof mcp.servers === 'object') return mcp.servers
|
|
1675
|
+
if (mcp.name && (mcp.url || mcp.command || mcp.type)) return { [mcp.name]: mcp }
|
|
1676
|
+
const direct = {}
|
|
1677
|
+
for (const [k, v] of Object.entries(mcp)) {
|
|
1678
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
1679
|
+
if (v.url || v.command || v.type || v.args || v.headers || v.env || v.cwd !== undefined) {
|
|
1680
|
+
direct[k] = v
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
return Object.keys(direct).length > 0 ? direct : null
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
function pushConnectorDict(dict, seen, connectors) {
|
|
1688
|
+
if (!dict || typeof dict !== 'object') return
|
|
1689
|
+
for (const [name, cfg] of Object.entries(dict)) {
|
|
1690
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) continue
|
|
1691
|
+
if (!seen.has(name)) {
|
|
1692
|
+
seen.add(name)
|
|
1693
|
+
connectors.push({
|
|
1694
|
+
name,
|
|
1695
|
+
type: connectorTransport(cfg.type, cfg.url, cfg.command),
|
|
1696
|
+
url: cfg.url || null,
|
|
1697
|
+
command: cfg.command || null,
|
|
1698
|
+
args: Array.isArray(cfg.args) ? cfg.args : [],
|
|
1699
|
+
...(cfg.cwd !== undefined ? { cwd: cfg.cwd } : {}),
|
|
1700
|
+
env: cfg.env || {},
|
|
1701
|
+
headers: cfg.headers || {},
|
|
1702
|
+
})
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
function loadMcpEntry(entry, dir, seen, connectors, seenFiles) {
|
|
1708
|
+
if (!entry) return
|
|
1709
|
+
if (typeof entry === 'string') {
|
|
1710
|
+
const resolved = resolvePluginSpecPath(dir, entry)
|
|
1711
|
+
if (!resolved || !existsSync(resolved)) return
|
|
1712
|
+
const key = resolve(resolved)
|
|
1713
|
+
if (seenFiles.has(key)) return
|
|
1714
|
+
seenFiles.add(key)
|
|
1715
|
+
try {
|
|
1716
|
+
const mcp = JSON.parse(readFileSync(resolved, 'utf8'))
|
|
1717
|
+
pushConnectorDict(extractConnectorDict(mcp), seen, connectors)
|
|
1718
|
+
} catch { /* ignore malformed */ }
|
|
1719
|
+
return
|
|
1720
|
+
}
|
|
1721
|
+
if (Array.isArray(entry)) {
|
|
1722
|
+
for (const item of entry) loadMcpEntry(item, dir, seen, connectors, seenFiles)
|
|
1723
|
+
return
|
|
1724
|
+
}
|
|
1725
|
+
if (typeof entry === 'object') {
|
|
1726
|
+
pushConnectorDict(extractConnectorDict(entry), seen, connectors)
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
/** Connector-ish entries: .mcp.json, mcp.json, server.json, or plugin.json "mcpServers" / "connectors". */
|
|
914
1731
|
export function listConnectors(dir, manifest = readPluginManifest(dir)) {
|
|
915
1732
|
const connectors = []
|
|
916
1733
|
const seen = new Set()
|
|
1734
|
+
const seenFiles = new Set()
|
|
917
1735
|
|
|
918
1736
|
for (const mcpFile of ['.mcp.json', 'mcp.json', 'server.json', 'mcp-servers.json']) {
|
|
919
1737
|
const mcpPath = join(dir, mcpFile)
|
|
920
1738
|
if (existsSync(mcpPath)) {
|
|
921
|
-
|
|
922
|
-
const mcp = JSON.parse(readFileSync(mcpPath, 'utf8'))
|
|
923
|
-
let dict = null
|
|
924
|
-
if (mcp && typeof mcp === 'object' && !Array.isArray(mcp)) {
|
|
925
|
-
if (mcp.mcpServers && typeof mcp.mcpServers === 'object') {
|
|
926
|
-
dict = mcp.mcpServers
|
|
927
|
-
} else if (mcp.servers && typeof mcp.servers === 'object') {
|
|
928
|
-
dict = mcp.servers
|
|
929
|
-
} else if (mcp.name && (mcp.url || mcp.command || mcp.type)) {
|
|
930
|
-
dict = { [mcp.name]: mcp }
|
|
931
|
-
} else {
|
|
932
|
-
const direct = {}
|
|
933
|
-
for (const [k, v] of Object.entries(mcp)) {
|
|
934
|
-
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
935
|
-
if (v.url || v.command || v.type || v.args || v.headers || v.env) {
|
|
936
|
-
direct[k] = v
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (Object.keys(direct).length > 0) dict = direct
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
if (dict && typeof dict === 'object') {
|
|
944
|
-
for (const [name, cfg] of Object.entries(dict)) {
|
|
945
|
-
if (!seen.has(name)) {
|
|
946
|
-
seen.add(name)
|
|
947
|
-
connectors.push({
|
|
948
|
-
name,
|
|
949
|
-
type: connectorTransport(cfg.type, cfg.url, cfg.command),
|
|
950
|
-
url: cfg.url || null,
|
|
951
|
-
command: cfg.command || null,
|
|
952
|
-
args: cfg.args || [],
|
|
953
|
-
env: cfg.env || {},
|
|
954
|
-
headers: cfg.headers || {},
|
|
955
|
-
})
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
} catch { /* ignore malformed */ }
|
|
1739
|
+
loadMcpEntry(`./${mcpFile}`, dir, seen, connectors, seenFiles)
|
|
960
1740
|
}
|
|
961
1741
|
}
|
|
962
1742
|
|
|
963
1743
|
if (manifest) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
dict = manifest.servers
|
|
969
|
-
} else if (manifest.mcp && typeof manifest.mcp === 'object') {
|
|
970
|
-
dict = manifest.mcp.mcpServers || manifest.mcp
|
|
1744
|
+
loadMcpEntry(manifest.mcpServers, dir, seen, connectors, seenFiles)
|
|
1745
|
+
loadMcpEntry(manifest.servers, dir, seen, connectors, seenFiles)
|
|
1746
|
+
if (manifest.mcp && typeof manifest.mcp === 'object') {
|
|
1747
|
+
loadMcpEntry(manifest.mcp.mcpServers || manifest.mcp, dir, seen, connectors, seenFiles)
|
|
971
1748
|
}
|
|
972
|
-
if (
|
|
973
|
-
for (const
|
|
974
|
-
|
|
1749
|
+
if (Array.isArray(manifest.connectors)) {
|
|
1750
|
+
for (const c of manifest.connectors) {
|
|
1751
|
+
const name = typeof c === 'string' ? c : c?.name
|
|
1752
|
+
if (name && !seen.has(name)) {
|
|
975
1753
|
seen.add(name)
|
|
1754
|
+
const cfg = typeof c === 'object' ? c : {}
|
|
976
1755
|
connectors.push({
|
|
977
1756
|
name,
|
|
978
1757
|
type: connectorTransport(cfg.type, cfg.url, cfg.command),
|
|
979
1758
|
url: cfg.url || null,
|
|
980
1759
|
command: cfg.command || null,
|
|
981
|
-
args: cfg.args
|
|
1760
|
+
args: Array.isArray(cfg.args) ? cfg.args : [],
|
|
1761
|
+
...(cfg.cwd !== undefined ? { cwd: cfg.cwd } : {}),
|
|
982
1762
|
env: cfg.env || {},
|
|
983
1763
|
headers: cfg.headers || {},
|
|
984
1764
|
})
|
|
985
1765
|
}
|
|
986
1766
|
}
|
|
987
1767
|
}
|
|
988
|
-
if (Array.isArray(manifest.connectors)) {
|
|
989
|
-
for (const c of manifest.connectors) {
|
|
990
|
-
const name = typeof c === 'string' ? c : c.name
|
|
991
|
-
if (name && !seen.has(name)) {
|
|
992
|
-
seen.add(name)
|
|
993
|
-
connectors.push({
|
|
994
|
-
name,
|
|
995
|
-
type: connectorTransport(c.type, c.url, c.command),
|
|
996
|
-
url: c.url || null,
|
|
997
|
-
command: c.command || null,
|
|
998
|
-
args: c.args || [],
|
|
999
|
-
env: c.env || {},
|
|
1000
|
-
headers: c.headers || {},
|
|
1001
|
-
})
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
1768
|
}
|
|
1006
1769
|
return connectors
|
|
1007
1770
|
}
|
|
1008
1771
|
|
|
1772
|
+
function collectLspDicts(spec, dir, seenFiles, outDicts) {
|
|
1773
|
+
if (!spec) return
|
|
1774
|
+
if (typeof spec === 'string') {
|
|
1775
|
+
if (!dir) return
|
|
1776
|
+
const resolved = resolvePluginSpecPath(dir, spec)
|
|
1777
|
+
if (!resolved || !existsSync(resolved)) return
|
|
1778
|
+
const key = resolve(resolved)
|
|
1779
|
+
if (seenFiles.has(key)) return
|
|
1780
|
+
seenFiles.add(key)
|
|
1781
|
+
try {
|
|
1782
|
+
const parsed = JSON.parse(readFileSync(resolved, 'utf8'))
|
|
1783
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
1784
|
+
outDicts.push(parsed.lspServers && typeof parsed.lspServers === 'object' ? parsed.lspServers : parsed)
|
|
1785
|
+
}
|
|
1786
|
+
} catch {}
|
|
1787
|
+
return
|
|
1788
|
+
}
|
|
1789
|
+
if (Array.isArray(spec)) {
|
|
1790
|
+
for (const item of spec) collectLspDicts(item, dir, seenFiles, outDicts)
|
|
1791
|
+
return
|
|
1792
|
+
}
|
|
1793
|
+
if (typeof spec === 'object') {
|
|
1794
|
+
outDicts.push(spec.lspServers && typeof spec.lspServers === 'object' ? spec.lspServers : spec)
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1009
1798
|
/**
|
|
1010
|
-
* List LSP server definitions from
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
* `readPluginManifest`) or a pre-resolved marketplace row object (uses
|
|
1014
|
-
* `row.lspServers` directly). The fallback path lets the plugin detail
|
|
1015
|
-
* surface LSP servers in browse mode, where the plugin directory itself
|
|
1016
|
-
* is only a README placeholder and the lspServers live in marketplace.json.
|
|
1799
|
+
* List LSP server definitions from `.lsp.json` / `lsp.json` and manifest
|
|
1800
|
+
* `lspServers` (object, file path, or array of paths/objects). Maps Claude's
|
|
1801
|
+
* `settings` field to `configuration` for DSH compatibility.
|
|
1017
1802
|
*/
|
|
1018
|
-
export function listLspServers(input) {
|
|
1019
|
-
|
|
1803
|
+
export function listLspServers(input, manifestOverride) {
|
|
1804
|
+
const dicts = []
|
|
1805
|
+
const seenFiles = new Set()
|
|
1806
|
+
|
|
1020
1807
|
if (typeof input === 'string') {
|
|
1021
|
-
|
|
1808
|
+
for (const fname of ['.lsp.json', 'lsp.json']) {
|
|
1809
|
+
const p = join(input, fname)
|
|
1810
|
+
if (existsSync(p)) collectLspDicts(`./${fname}`, input, seenFiles, dicts)
|
|
1811
|
+
}
|
|
1812
|
+
const manifest = manifestOverride ?? readPluginManifest(input)
|
|
1813
|
+
collectLspDicts(manifest?.lspServers, input, seenFiles, dicts)
|
|
1022
1814
|
} else if (input && typeof input === 'object' && !Array.isArray(input)) {
|
|
1023
|
-
|
|
1815
|
+
collectLspDicts(input.lspServers, null, seenFiles, dicts)
|
|
1024
1816
|
}
|
|
1025
|
-
|
|
1817
|
+
|
|
1026
1818
|
const out = []
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1819
|
+
const seen = new Set()
|
|
1820
|
+
for (const raw of dicts) {
|
|
1821
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) continue
|
|
1822
|
+
for (const [name, cfg] of Object.entries(raw)) {
|
|
1823
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) continue
|
|
1824
|
+
if (seen.has(name)) continue
|
|
1825
|
+
seen.add(name)
|
|
1826
|
+
out.push({
|
|
1827
|
+
name,
|
|
1828
|
+
command: cfg.command || null,
|
|
1829
|
+
args: Array.isArray(cfg.args) ? cfg.args : [],
|
|
1830
|
+
env: (cfg.env && typeof cfg.env === 'object') ? cfg.env : {},
|
|
1831
|
+
extensionToLanguage: (cfg.extensionToLanguage && typeof cfg.extensionToLanguage === 'object') ? cfg.extensionToLanguage : {},
|
|
1832
|
+
initializationOptions: cfg.initializationOptions ?? null,
|
|
1833
|
+
configuration: cfg.configuration ?? cfg.settings ?? null,
|
|
1834
|
+
startupTimeout: cfg.startupTimeout ?? null,
|
|
1835
|
+
})
|
|
1836
|
+
}
|
|
1039
1837
|
}
|
|
1040
1838
|
return out
|
|
1041
1839
|
}
|
|
1042
1840
|
|
|
1841
|
+
/** Merge manifest metadata with marketplace row overrides (especially `strict: false`). */
|
|
1842
|
+
export function mergeManifestWithRow(manifest, rowFallback) {
|
|
1843
|
+
if (!rowFallback || typeof rowFallback !== 'object') return manifest
|
|
1844
|
+
const base = manifest && typeof manifest === 'object' ? { ...manifest } : {}
|
|
1845
|
+
for (const key of MARKETPLACE_COMPONENT_KEYS) {
|
|
1846
|
+
if (rowFallback[key] !== undefined && (rowFallback.strict === false || !manifest || manifest[key] === undefined)) {
|
|
1847
|
+
base[key] = rowFallback[key]
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return Object.keys(base).length > 0 ? base : null
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1043
1853
|
/** Full detail view for one plugin (installed copy or cache). */
|
|
1044
1854
|
export function pluginDetail(sourceId, pluginName, source, rowFallback) {
|
|
1045
1855
|
const dir = pluginContentDir(sourceId, pluginName, source)
|
|
1046
1856
|
if (!dir) return null
|
|
1047
1857
|
const manifest = readPluginManifest(dir)
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
// browsing an uninstalled plugin whose directory is only a README placeholder
|
|
1051
|
-
// — fall back to the `lspServers` field carried by the marketplace row.
|
|
1052
|
-
let lspServers = listLspServers(dir)
|
|
1858
|
+
const effectiveManifest = mergeManifestWithRow(manifest, rowFallback)
|
|
1859
|
+
let lspServers = listLspServers(dir, effectiveManifest)
|
|
1053
1860
|
if (lspServers.length === 0 && rowFallback) {
|
|
1054
1861
|
lspServers = listLspServers(rowFallback)
|
|
1055
1862
|
}
|
|
1056
1863
|
return {
|
|
1057
1864
|
name: pluginName,
|
|
1058
|
-
displayName:
|
|
1059
|
-
description:
|
|
1060
|
-
author:
|
|
1061
|
-
version:
|
|
1062
|
-
icons: buildPluginIcons(
|
|
1063
|
-
skills: listSkills(dir),
|
|
1064
|
-
agents: listAgents(dir).map((a) => ({
|
|
1865
|
+
displayName: effectiveManifest?.displayName || rowFallback?.displayName || formatDisplayName(pluginName),
|
|
1866
|
+
description: effectiveManifest?.description || rowFallback?.description || '',
|
|
1867
|
+
author: effectiveManifest?.author?.name || (typeof effectiveManifest?.author === 'string' ? effectiveManifest.author : rowFallback?.author),
|
|
1868
|
+
version: effectiveManifest?.version || rowFallback?.version,
|
|
1869
|
+
icons: buildPluginIcons(effectiveManifest, { sourceId, name: pluginName, dir, source }),
|
|
1870
|
+
skills: listSkills(dir, effectiveManifest),
|
|
1871
|
+
agents: listAgents(dir, effectiveManifest).map((a) => ({
|
|
1065
1872
|
file: a.file,
|
|
1066
1873
|
name: a.name,
|
|
1067
1874
|
displayName: a.displayName || a.name,
|
|
@@ -1069,9 +1876,12 @@ export function pluginDetail(sourceId, pluginName, source, rowFallback) {
|
|
|
1069
1876
|
tools: a.tools || null,
|
|
1070
1877
|
model: a.model || null,
|
|
1071
1878
|
})),
|
|
1072
|
-
prompts: listPrompts(dir),
|
|
1073
|
-
connectors: listConnectors(dir)
|
|
1074
|
-
|
|
1879
|
+
prompts: listPrompts(dir, effectiveManifest),
|
|
1880
|
+
connectors: listConnectors(dir, effectiveManifest).map((c) => ({
|
|
1881
|
+
...c,
|
|
1882
|
+
...resolveConnectorDisplay(c, dir),
|
|
1883
|
+
})),
|
|
1884
|
+
hooks: listHooks(dir, effectiveManifest),
|
|
1075
1885
|
lspServers,
|
|
1076
1886
|
}
|
|
1077
1887
|
}
|