dsh-agent-plugins-market 0.4.6 → 0.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.
Files changed (62) hide show
  1. package/README.md +16 -10
  2. package/README.zh.md +16 -10
  3. package/client/client.js +540 -417
  4. package/client/client.js.map +1 -1
  5. package/lib/application/catalog.js +447 -0
  6. package/lib/application/details.js +136 -0
  7. package/lib/application/queries.js +1 -0
  8. package/lib/{discovery → catalog}/manifests.js +20 -12
  9. package/lib/{paths.js → catalog/paths.js} +5 -1
  10. package/lib/{skills-parse.js → catalog/skills-parse.js} +7 -4
  11. package/lib/catalog/source-catalog.js +38 -0
  12. package/lib/{discovery.js → catalog/suite-scanner.js} +28 -86
  13. package/lib/{discovery → catalog}/surfaces.js +9 -11
  14. package/lib/{validate.js → catalog/validate.js} +3 -3
  15. package/lib/context.js +11 -13
  16. package/lib/contracts/market.js +27 -0
  17. package/lib/contracts/mcp-status.js +2 -0
  18. package/lib/index.js +32 -49
  19. package/lib/{state.js → model/state.js} +2 -2
  20. package/lib/routes.js +21 -21
  21. package/lib/{commands-mounts.js → runtime/commands-mounts.js} +10 -11
  22. package/lib/{hooks-mounts.js → runtime/hooks-mounts.js} +1 -1
  23. package/lib/{mcp-config.js → runtime/mcp-config.js} +7 -4
  24. package/lib/{mcp-status.js → runtime/mcp-status.js} +8 -41
  25. package/lib/runtime/reconciler.js +46 -0
  26. package/lib/{skills-provider.js → runtime/skills-provider.js} +26 -23
  27. package/lib/runtime/tool-registry-observer.js +35 -0
  28. package/lib/types/application/catalog.d.ts +113 -0
  29. package/lib/types/application/details.d.ts +12 -0
  30. package/lib/types/application/queries.d.ts +33 -0
  31. package/lib/types/{discovery → catalog}/manifests.d.ts +1 -1
  32. package/lib/types/catalog/source-catalog.d.ts +3 -0
  33. package/lib/types/catalog/suite-scanner.d.ts +9 -0
  34. package/lib/types/{discovery → catalog}/surfaces.d.ts +1 -1
  35. package/lib/types/{validate.d.ts → catalog/validate.d.ts} +1 -1
  36. package/lib/types/context.d.ts +2 -2
  37. package/lib/types/contracts/market.d.ts +153 -0
  38. package/lib/types/contracts/mcp-status.d.ts +38 -0
  39. package/lib/types/index.d.ts +1 -1
  40. package/lib/types/{types.d.ts → model/types.d.ts} +2 -42
  41. package/lib/types/routes.d.ts +2 -2
  42. package/lib/types/{commands-mounts.d.ts → runtime/commands-mounts.d.ts} +1 -1
  43. package/lib/types/{hooks-mounts.d.ts → runtime/hooks-mounts.d.ts} +1 -1
  44. package/lib/types/{mcp-config.d.ts → runtime/mcp-config.d.ts} +1 -1
  45. package/lib/types/{mcp-mounts.d.ts → runtime/mcp-mounts.d.ts} +1 -1
  46. package/lib/types/runtime/mcp-status.d.ts +13 -0
  47. package/lib/types/runtime/reconciler.d.ts +33 -0
  48. package/lib/types/{skills-provider.d.ts → runtime/skills-provider.d.ts} +3 -3
  49. package/lib/types/runtime/tool-registry-observer.d.ts +14 -0
  50. package/package.json +34 -19
  51. package/schemas/README.md +2 -5
  52. package/lib/manager.js +0 -581
  53. package/lib/types/discovery.d.ts +0 -19
  54. package/lib/types/manager.d.ts +0 -124
  55. package/lib/types/mcp-status.d.ts +0 -51
  56. /package/lib/{git.js → catalog/git.js} +0 -0
  57. /package/lib/{types.js → model/types.js} +0 -0
  58. /package/lib/{mcp-mounts.js → runtime/mcp-mounts.js} +0 -0
  59. /package/lib/types/{git.d.ts → catalog/git.d.ts} +0 -0
  60. /package/lib/types/{paths.d.ts → catalog/paths.d.ts} +0 -0
  61. /package/lib/types/{skills-parse.d.ts → catalog/skills-parse.d.ts} +0 -0
  62. /package/lib/types/{state.d.ts → model/state.d.ts} +0 -0
@@ -17,7 +17,10 @@ export function isSkillName(name) {
17
17
  * → "presentations"), or `undefined` when nothing usable remains.
18
18
  */
19
19
  export function normalizeSkillName(name) {
20
- const normalized = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
20
+ const normalized = name
21
+ .toLowerCase()
22
+ .replace(/[^a-z0-9]+/g, '-')
23
+ .replace(/^-+|-+$/g, '');
21
24
  return normalized === '' ? undefined : normalized;
22
25
  }
23
26
  function parseBoolean(value) {
@@ -87,11 +90,11 @@ export function parseSkillFrontmatter(text, expectedName) {
87
90
  return {
88
91
  name,
89
92
  description: description.trim(),
90
- ...whenToUse === undefined ? {} : { whenToUse },
93
+ ...(whenToUse === undefined ? {} : { whenToUse }),
91
94
  invocation: {
92
95
  modelInvocable: disableModel !== true,
93
- userInvocable: userInvocable !== false,
94
- },
96
+ userInvocable: userInvocable !== false
97
+ }
95
98
  };
96
99
  }
97
100
  /** Lenient frontmatter recovery for prose fields with embedded `: `. */
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Select source checkouts for a catalog dimension.
3
+ *
4
+ * User catalogs include only configured sources. Project catalogs additionally
5
+ * retain unmanaged checkout ids because project install state can authorize
6
+ * them without duplicating source configuration.
7
+ */
8
+ import { readdir } from 'node:fs/promises';
9
+ import { join } from 'node:path';
10
+ import { expandHome, isDirectory, sourcesDir } from './paths.js';
11
+ import { discoverSuitesInSource } from './suite-scanner.js';
12
+ /** Discover suites from the selected configured or project checkouts. */
13
+ export async function discoverSourceList(sources, dimension, dimensionRoot) {
14
+ const checkoutRoot = sourcesDir(dimensionRoot);
15
+ const listed = new Set(sources.map(source => source.id));
16
+ const checkouts = sources.map(source => ({
17
+ sourceId: source.id,
18
+ checkout: source.local === true ? expandHome(source.url) : join(checkoutRoot, source.id)
19
+ }));
20
+ if (dimension === 'project') {
21
+ try {
22
+ for (const entry of await readdir(checkoutRoot, { withFileTypes: true })) {
23
+ if (!entry.isDirectory() || entry.name.startsWith('.') || listed.has(entry.name))
24
+ continue;
25
+ checkouts.push({ sourceId: entry.name, checkout: join(checkoutRoot, entry.name) });
26
+ }
27
+ }
28
+ catch {
29
+ // A missing project checkout root has no unmanaged project sources.
30
+ }
31
+ }
32
+ const discovered = await Promise.all(checkouts.map(async ({ sourceId, checkout }) => {
33
+ if (!(await isDirectory(checkout)))
34
+ return [];
35
+ return discoverSuitesInSource(checkout, sourceId, dimension);
36
+ }));
37
+ return discovered.flat();
38
+ }
@@ -1,43 +1,25 @@
1
1
  /**
2
- * Suite discovery facade: maps a repository checkout (or a configured source
3
- * list) onto normalized suites.
2
+ * Scan one source checkout into normalized suites.
4
3
  *
5
- * Pipeline: the manifest layer (src/discovery/manifests.ts) detects which
6
- * suite-manifest dialects a root carries and resolves names; the roots step
7
- * decides where suites live (marketplace entries, a single root, container
8
- * scans, or manifest-less skill collections); the surface layer
9
- * (src/discovery/surfaces.ts) scans skills/commands/agents/hooks/lsp/mcp.
10
- *
11
- * The public API of this module is the discovery contract importers depend
12
- * on: discoverSuitesInSource, discoverSourceList, listMdFiles,
13
- * discoverLspEntries, and the new repoName for source-id derivation.
4
+ * This module owns root selection inside one checkout and delegates manifest and
5
+ * surface parsing to the established discovery adapters. Source-list policy
6
+ * (configured, local, and project checkout selection) belongs to source-catalog.
14
7
  */
15
- import { readdir } from 'node:fs/promises';
8
+ import { readdir, stat } from 'node:fs/promises';
16
9
  import { isAbsolute, join } from 'node:path';
17
- import { expandHome, isDirectory, sanitizeId, sourcesDir } from './paths.js';
18
- import { declaredSkillsPath, detectManifest, marketplaceEntryDir, readManifest, readMarketplace, repoName, syntheticManifestName, } from './discovery/manifests.js';
19
- import { countSurfaces, discoverLspEntries, discoverMcp, discoverSkills, listMdFiles, } from './discovery/surfaces.js';
10
+ import { isDirectory, sanitizeId } from './paths.js';
11
+ import { declaredSkillsPath, detectManifest, marketplaceEntryDir, readManifest, readMarketplace, repoName, syntheticManifestName } from './manifests.js';
12
+ import { countSurfaces, discoverLspEntries, discoverMcp, discoverSkills, listMdFiles } from './surfaces.js';
20
13
  export { repoName, listMdFiles, discoverLspEntries };
21
14
  const CONTAINER_DIRS = ['plugins', 'external_plugins', 'skills'];
22
15
  const DOT_DIRS = new Set(['.git', '.github', '.claude', '.cursor', '.kimi', '.plugin', '.sources', 'node_modules']);
23
- /** Discover every suite under one cloned source checkout. */
16
+ /** Discover every suite under one source checkout. */
24
17
  export async function discoverSuitesInSource(checkoutDir, sourceId, dimension) {
25
18
  const roots = await suiteRoots(checkoutDir);
26
- const suites = await Promise.all(roots.map(async (root) => root.dir === undefined
27
- ? remoteSuite(sourceId, dimension, root)
28
- : readSuite(root.dir, sourceId, dimension, root.hint)));
19
+ const suites = await Promise.all(roots.map(async (root) => (root.dir === undefined ? remoteSuite(sourceId, dimension, root) : readSuite(root.dir, sourceId, dimension, root.hint))));
29
20
  return suites.filter((suite) => suite !== undefined);
30
21
  }
31
- /**
32
- * Resolve the suite roots of one checkout. A marketplace manifest is the
33
- * authoritative list: local entries (relative paths, Codex `{source:
34
- * 'local', path}`) surface when they carry a manifest or skills, container
35
- * paths recurse into nested plugin dirs, and remote-URL entries become
36
- * metadata-only remote suites. Manifest-bearing container dirs the
37
- * marketplace did not list (e.g. official example plugins) are supplemented.
38
- * Without a marketplace: a single-suite root, a recursive manifest/skill
39
- * scan, or a manifest-less skill collection applies.
40
- */
22
+ /** Resolve all suite roots selected by a marketplace or checkout layout. */
41
23
  async function suiteRoots(checkoutDir) {
42
24
  const marketplace = await readMarketplace(checkoutDir);
43
25
  if (marketplace !== undefined && marketplace.entries.length > 0) {
@@ -61,10 +43,10 @@ async function suiteRoots(checkoutDir) {
61
43
  }
62
44
  for (const container of CONTAINER_DIRS) {
63
45
  const containerDir = join(checkoutDir, container);
64
- if (!await isDirectory(containerDir))
46
+ if (!(await isDirectory(containerDir)))
65
47
  continue;
66
48
  for (const child of await listChildDirs(containerDir)) {
67
- if (!seen.has(child) && await hasSuiteManifest(child))
49
+ if (!seen.has(child) && (await hasSuiteManifest(child)))
68
50
  roots.push({ dir: child });
69
51
  }
70
52
  }
@@ -84,13 +66,11 @@ async function suiteRoots(checkoutDir) {
84
66
  }
85
67
  return collection;
86
68
  }
87
- /** Collect one root, recursing through container dirs (nested `plugins/`
88
- * bundles) up to four levels so Codex runtime layouts
89
- * (`plugins/<bundle>/plugins/<name>`) are reached. */
69
+ /** Collect nested plugin roots up to four levels deep. */
90
70
  async function collectRoot(dir, hint, out, seen, depth = 0) {
91
71
  if (depth > 4 || seen.has(dir))
92
72
  return;
93
- if (await hasSuiteManifest(dir) || await hasSkillFiles(dir)) {
73
+ if ((await hasSuiteManifest(dir)) || (await hasSkillFiles(dir))) {
94
74
  out.push({ dir, hint });
95
75
  seen.add(dir);
96
76
  return;
@@ -108,7 +88,7 @@ async function hasSkillFiles(dir) {
108
88
  if (await isFile(join(dir, 'SKILL.md')))
109
89
  return true;
110
90
  const skillsDir = join(dir, 'skills');
111
- if (!await isDirectory(skillsDir))
91
+ if (!(await isDirectory(skillsDir)))
112
92
  return false;
113
93
  for (const child of await listChildDirs(skillsDir)) {
114
94
  if (await isFile(join(child, 'SKILL.md')))
@@ -124,14 +104,12 @@ async function listChildDirs(dir) {
124
104
  catch {
125
105
  return [];
126
106
  }
127
- return entries
128
- .filter(entry => entry.isDirectory() && !DOT_DIRS.has(entry.name) && !entry.name.startsWith('.'))
129
- .map(entry => join(dir, entry.name));
107
+ return entries.filter(entry => entry.isDirectory() && !DOT_DIRS.has(entry.name) && !entry.name.startsWith('.')).map(entry => join(dir, entry.name));
130
108
  }
131
- /** Read one suite root into the normalized shape, or `undefined` when no manifest parses. */
109
+ /** Read one suite root into the normalized shape, or undefined when no manifest parses. */
132
110
  async function readSuite(root, sourceId, dimension, hint) {
133
111
  const errors = [];
134
- const manifest = await readManifest(root, errors, hint) ?? await syntheticManifest(root);
112
+ const manifest = (await readManifest(root, errors, hint)) ?? (await syntheticManifest(root));
135
113
  if (manifest === undefined)
136
114
  return undefined;
137
115
  const declared = await declaredSkillsPath(root);
@@ -144,15 +122,14 @@ async function readSuite(root, sourceId, dimension, hint) {
144
122
  root,
145
123
  manifest,
146
124
  skills,
147
- ...mcp === undefined ? {} : { mcp },
125
+ ...(mcp === undefined ? {} : { mcp }),
148
126
  surfaces,
149
127
  dimension,
150
128
  enabled: false,
151
- errors,
129
+ errors
152
130
  };
153
131
  }
154
- /** Metadata-only suite for a marketplace entry whose content lives in a
155
- * remote repository that is not part of this clone. */
132
+ /** Metadata-only suite for a marketplace entry whose content is remote. */
156
133
  function remoteSuite(sourceId, dimension, root) {
157
134
  const name = root.hint?.name ?? 'remote-plugin';
158
135
  return {
@@ -165,72 +142,37 @@ function remoteSuite(sourceId, dimension, root) {
165
142
  id: sanitizeId(name),
166
143
  name,
167
144
  version: root.hint?.version,
168
- description: root.hint?.description,
145
+ description: root.hint?.description
169
146
  },
170
147
  skills: [],
171
148
  surfaces: { skills: 0, mcp: 0, hooks: 0, commands: 0, agents: 0, lsp: 0 },
172
149
  dimension,
173
150
  enabled: false,
174
151
  remote: { url: root.remoteUrl ?? '' },
175
- errors: [],
152
+ errors: []
176
153
  };
177
154
  }
178
155
  /** Manifest-less directories still produce a synthetic suite identity. */
179
156
  async function syntheticManifest(root) {
180
- if (!await hasSkillFiles(root))
157
+ if (!(await hasSkillFiles(root)))
181
158
  return undefined;
182
159
  const name = syntheticManifestName(root);
183
160
  return {
184
161
  layout: 'skill-collection',
185
162
  path: join(root, 'SKILL.md'),
186
163
  id: sanitizeId(name),
187
- name,
164
+ name
188
165
  };
189
166
  }
190
167
  async function isFile(path) {
191
168
  try {
192
- return (await (await import('node:fs/promises')).stat(path)).isFile();
169
+ return (await stat(path)).isFile();
193
170
  }
194
171
  catch {
195
172
  return false;
196
173
  }
197
174
  }
198
- /** Whether a suite root path lies outside the checkout (defense for malformed marketplace sources). */
175
+ /** Whether a suite root path lies outside the checkout. */
199
176
  export function isOutside(root, candidate) {
200
177
  return isAbsolute(candidate) ? !candidate.startsWith(root) : false;
201
178
  }
202
- /**
203
- * Discover suites for one dimension. User catalogs only read configured
204
- * sources: unmanaged user checkouts have no persisted identity and otherwise
205
- * leak stale repositories into the catalog totals. Project catalogs retain
206
- * unmanaged checkout ids because project state may authorize them through its
207
- * installed map without duplicating source configuration. All selected
208
- * checkouts are discovered concurrently so one large repository does not
209
- * serialize every other repository's scan.
210
- */
211
- export async function discoverSourceList(sources, dimension, dimensionRoot) {
212
- const checkoutRoot = sourcesDir(dimensionRoot);
213
- const listed = new Set(sources.map(source => source.id));
214
- const checkouts = sources.map(source => ({
215
- sourceId: source.id,
216
- checkout: source.local === true ? expandHome(source.url) : join(checkoutRoot, source.id),
217
- }));
218
- if (dimension === 'project') {
219
- try {
220
- for (const entry of await readdir(checkoutRoot, { withFileTypes: true })) {
221
- if (!entry.isDirectory() || entry.name.startsWith('.') || listed.has(entry.name))
222
- continue;
223
- checkouts.push({ sourceId: entry.name, checkout: join(checkoutRoot, entry.name) });
224
- }
225
- }
226
- catch {
227
- // A missing project checkout root has no unmanaged project sources.
228
- }
229
- }
230
- const discovered = await Promise.all(checkouts.map(async ({ sourceId, checkout }) => {
231
- if (!await isDirectory(checkout))
232
- return [];
233
- return discoverSuitesInSource(checkout, sourceId, dimension);
234
- }));
235
- return discovered.flat();
236
- }
@@ -11,9 +11,9 @@
11
11
  */
12
12
  import { readFile, readdir, stat } from 'node:fs/promises';
13
13
  import { join } from 'node:path';
14
- import { parseSkillFrontmatter } from '../skills-parse.js';
15
- import { isDirectory } from '../paths.js';
16
- import { validateMcpJson } from '../validate.js';
14
+ import { parseSkillFrontmatter } from './skills-parse.js';
15
+ import { isDirectory } from './paths.js';
16
+ import { validateMcpJson } from './validate.js';
17
17
  import { declaredMcpServers } from './manifests.js';
18
18
  const DOT_DIRS = new Set(['.git', '.github', '.claude', '.cursor', '.kimi', '.plugin', '.sources', 'node_modules']);
19
19
  /** Resolve a manifest-declared skills path into absolute directories (string or array form). */
@@ -77,7 +77,7 @@ export async function discoverSkills(root, errors, declared) {
77
77
  return skills;
78
78
  }
79
79
  async function parseOneSkill(file, directory, fallbackName, errors) {
80
- if (!await isFile(file))
80
+ if (!(await isFile(file)))
81
81
  return undefined;
82
82
  let text;
83
83
  try {
@@ -97,15 +97,15 @@ async function parseOneSkill(file, directory, fallbackName, errors) {
97
97
  directory,
98
98
  file,
99
99
  description: parsed.description,
100
- ...parsed.whenToUse === undefined ? {} : { whenToUse: parsed.whenToUse },
101
- invocation: parsed.invocation,
100
+ ...(parsed.whenToUse === undefined ? {} : { whenToUse: parsed.whenToUse }),
101
+ invocation: parsed.invocation
102
102
  };
103
103
  }
104
104
  /** Read the suite's MCP config: `mcp.json` or `.mcp.json`, else the winning manifest's inline `mcpServers`. */
105
105
  export async function discoverMcp(root, errors) {
106
106
  for (const name of ['mcp.json', '.mcp.json']) {
107
107
  const path = join(root, name);
108
- if (!await isFile(path))
108
+ if (!(await isFile(path)))
109
109
  continue;
110
110
  let raw;
111
111
  try {
@@ -141,7 +141,7 @@ export async function countSurfaces(root, skills, mcp) {
141
141
  hooks,
142
142
  commands,
143
143
  agents,
144
- lsp,
144
+ lsp
145
145
  };
146
146
  }
147
147
  /** LSP definitions: `.claude-plugin/lsp/*.json` plus reverse-domain `lsp/` dirs. */
@@ -218,9 +218,7 @@ async function listChildDirs(dir) {
218
218
  catch {
219
219
  return [];
220
220
  }
221
- return entries
222
- .filter(entry => entry.isDirectory() && !DOT_DIRS.has(entry.name) && !entry.name.startsWith('.'))
223
- .map(entry => join(dir, entry.name));
221
+ return entries.filter(entry => entry.isDirectory() && !DOT_DIRS.has(entry.name) && !entry.name.startsWith('.')).map(entry => join(dir, entry.name));
224
222
  }
225
223
  async function isFile(path) {
226
224
  try {
@@ -14,7 +14,7 @@ import { fileURLToPath } from 'node:url';
14
14
  // The 2020-12 dist build's d.ts resolves to a CJS namespace under NodeNext;
15
15
  // the runtime default export is the class itself (module.exports = Ajv2020).
16
16
  import Ajv2020Default from 'ajv/dist/2020.js';
17
- const SCHEMAS_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', 'schemas', '1.0.0');
17
+ const SCHEMAS_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'schemas', '1.0.0');
18
18
  const Ajv2020Class = Ajv2020Default;
19
19
  export const PLUGIN_SCHEMA_ID = 'https://agent-plugins.org/schemas/1.0.0/plugin.schema.json';
20
20
  export const MCP_SCHEMA_ID = 'https://agent-plugins.org/schemas/1.0.0/mcp.schema.json';
@@ -38,7 +38,7 @@ export async function validateAgainstSchema(schemaId, document) {
38
38
  if (validate === undefined)
39
39
  return [`no bundled validator for ${schemaId}`];
40
40
  validate(document);
41
- return (validate.errors ?? []).map((error) => `${error.instancePath === '' ? 'root' : error.instancePath} ${error.message ?? 'invalid'}`);
41
+ return (validate.errors ?? []).map(error => `${error.instancePath === '' ? 'root' : error.instancePath} ${error.message ?? 'invalid'}`);
42
42
  }
43
43
  /** Whether a `$schema` value selects the local v1.0.0 ruleset. */
44
44
  export function isRecognizedSchema(value) {
@@ -84,7 +84,7 @@ export async function validatePluginManifest(raw) {
84
84
  if (!isRecognizedSchema(record['$schema'])) {
85
85
  errors.push(`unrecognized $schema ${JSON.stringify(record['$schema'])}; this manager supports agent-plugins 1.0.0 only`);
86
86
  }
87
- errors.push(...await validateAgainstSchema(PLUGIN_SCHEMA_ID, raw));
87
+ errors.push(...(await validateAgainstSchema(PLUGIN_SCHEMA_ID, raw)));
88
88
  return errors;
89
89
  }
90
90
  /**
package/lib/context.js CHANGED
@@ -1,8 +1,8 @@
1
- import { deriveServerName } from './mcp-config.js';
1
+ import { deriveServerName } from './runtime/mcp-config.js';
2
2
  /** Mount the agent_plugins query tool. */
3
3
  export function mountSuiteContext(ctx, manager) {
4
4
  const disposers = [];
5
- ctx.inject(['tools'], (toolsCtx) => {
5
+ ctx.inject(['tools'], toolsCtx => {
6
6
  const tools = toolsCtx;
7
7
  if (typeof tools.tools?.register !== 'function')
8
8
  return;
@@ -11,10 +11,10 @@ export function mountSuiteContext(ctx, manager) {
11
11
  properties: {
12
12
  action: { type: 'string', enum: ['list', 'info'], description: 'list: 列出全部 Agent Plugins;info: 查看单个 Agent Plugins 详情' },
13
13
  suiteId: { type: 'string', description: 'info 动作时必填:Agent Plugins id' },
14
- sourceId: { type: 'string', description: 'info 动作时可选:Agent Plugins 所属仓库源 id' },
14
+ sourceId: { type: 'string', description: 'info 动作时可选:Agent Plugins 所属仓库源 id' }
15
15
  },
16
16
  required: ['action'],
17
- additionalProperties: false,
17
+ additionalProperties: false
18
18
  };
19
19
  const outputSchema = {
20
20
  type: 'object',
@@ -22,8 +22,8 @@ export function mountSuiteContext(ctx, manager) {
22
22
  suites: { type: 'array', items: { type: 'object' } },
23
23
  skills: { type: 'array', items: { type: 'object' } },
24
24
  mcpServers: { type: 'array', items: { type: 'object' } },
25
- note: { type: 'string' },
26
- },
25
+ note: { type: 'string' }
26
+ }
27
27
  };
28
28
  const dispose = tools.tools.register({
29
29
  name: 'agent_plugins',
@@ -35,7 +35,7 @@ export function mountSuiteContext(ctx, manager) {
35
35
  render: (_args, value) => {
36
36
  const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2);
37
37
  return [{ type: 'text', text }];
38
- },
38
+ }
39
39
  },
40
40
  execute: async (args) => {
41
41
  const record = args;
@@ -45,7 +45,7 @@ export function mountSuiteContext(ctx, manager) {
45
45
  if (action === 'info')
46
46
  return infoPayload(await manager.enabledUserSuites(), record);
47
47
  return { suites: [], skills: [], mcpServers: [], note: `unknown action ${JSON.stringify(action)}` };
48
- },
48
+ }
49
49
  });
50
50
  disposers.push(dispose);
51
51
  });
@@ -62,13 +62,11 @@ function listPayload(suites) {
62
62
  name: suite.manifest.name,
63
63
  version: suite.manifest.version ?? null,
64
64
  description: suite.manifest.description ?? null,
65
- layout: suite.manifest.layout,
65
+ layout: suite.manifest.layout
66
66
  })),
67
67
  skills: suites.flatMap(suite => suite.skills.map(skill => ({ suiteId: suite.id, name: skill.name, description: `[${suite.manifest.name}] ${skill.description}` }))),
68
- mcpServers: suites.flatMap(suite => suite.mcp === undefined
69
- ? []
70
- : Object.keys(suite.mcp.servers).map(key => ({ suiteId: suite.id, server: key, tools: `mcp__${deriveServerName(suite.id, key)}__*` }))),
71
- note: '技能正文通过 skill 工具按 name 加载;MCP 工具名形如 mcp__<plugin>__<server>__<tool>。',
68
+ mcpServers: suites.flatMap(suite => suite.mcp === undefined ? [] : Object.keys(suite.mcp.servers).map(key => ({ suiteId: suite.id, server: key, tools: `mcp__${deriveServerName(suite.id, key)}__*` }))),
69
+ note: '技能正文通过 skill 工具按 name 加载;MCP 工具名形如 mcp__<plugin>__<server>__<tool>。'
72
70
  };
73
71
  }
74
72
  function infoPayload(suites, record) {
@@ -0,0 +1,27 @@
1
+ /** Browser-safe market wire records and route constants shared by host and client. */
2
+ /** Prefix for all Agent Plugins Market HTTP routes. */
3
+ export const MARKET_API_PREFIX = '/api/agent-plugins/';
4
+ /** Fixed Agent Plugins Market HTTP routes. */
5
+ export const MARKET_ROUTES = {
6
+ overview: `${MARKET_API_PREFIX}overview`,
7
+ mcpStatus: `${MARKET_API_PREFIX}mcp-status`,
8
+ progress: `${MARKET_API_PREFIX}progress`,
9
+ config: `${MARKET_API_PREFIX}config`,
10
+ suite: `${MARKET_API_PREFIX}suite`,
11
+ skill: `${MARKET_API_PREFIX}skill`,
12
+ addSource: `${MARKET_API_PREFIX}sources/add`,
13
+ updateSource: `${MARKET_API_PREFIX}sources/update`,
14
+ removeSource: `${MARKET_API_PREFIX}sources/remove`,
15
+ refreshSource: `${MARKET_API_PREFIX}sources/refresh`,
16
+ install: `${MARKET_API_PREFIX}install`,
17
+ uninstall: `${MARKET_API_PREFIX}uninstall`,
18
+ setEnabled: `${MARKET_API_PREFIX}set-enabled`
19
+ };
20
+ /** Build a suite-detail URL without duplicating route or query encoding logic. */
21
+ export function suiteRoute(sourceId, suiteId) {
22
+ return `${MARKET_ROUTES.suite}?sourceId=${encodeURIComponent(sourceId)}&suiteId=${encodeURIComponent(suiteId)}`;
23
+ }
24
+ /** Build a skill-content URL without duplicating route or query encoding logic. */
25
+ export function skillRoute(sourceId, suiteId, skill) {
26
+ return `${MARKET_ROUTES.skill}?sourceId=${encodeURIComponent(sourceId)}&suiteId=${encodeURIComponent(suiteId)}&skill=${encodeURIComponent(skill)}`;
27
+ }
@@ -0,0 +1,2 @@
1
+ /** Browser-safe MCP status records shared by host aggregation and client rendering. */
2
+ export {};
package/lib/index.js CHANGED
@@ -1,78 +1,61 @@
1
- import { CommandMountRegistry } from './commands-mounts.js';
2
- import { HooksMountRegistry } from './hooks-mounts.js';
3
1
  import { mountSuiteContext } from './context.js';
4
- import { SuiteManager } from './manager.js';
5
- import { McpMountRegistry } from './mcp-mounts.js';
6
- import { inspectToolRegistry } from './mcp-status.js';
7
- import { resolveDataRoot, resolveUserRoot } from './paths.js';
2
+ import { Catalog } from './application/catalog.js';
3
+ import { RuntimeReconciler } from './runtime/reconciler.js';
4
+ import { inspectToolRegistry } from './runtime/tool-registry-observer.js';
5
+ import { resolveDataRoot, resolveUserRoot } from './catalog/paths.js';
8
6
  import { mountSuiteRoutes } from './routes.js';
9
- import { SuiteSkillProvider } from './skills-provider.js';
7
+ import { SuiteSkillProvider } from './runtime/skills-provider.js';
10
8
  export const name = 'dsh-agent-plugins-market';
11
9
  export const inject = ['skills', 'commands'];
12
10
  export function apply(ctx, config = {}) {
13
11
  const userRoot = resolveUserRoot(config.userRoot);
14
12
  const dataRoot = resolveDataRoot(config.dataRoot);
15
13
  let providerControl;
16
- const mounts = new McpMountRegistry(ctx, dataRoot);
17
- const commandMounts = new CommandMountRegistry(ctx);
18
- const hookMounts = new HooksMountRegistry(ctx);
14
+ const runtime = new RuntimeReconciler(ctx, dataRoot);
19
15
  const reconcileMounts = () => {
20
16
  void (async () => {
21
- try {
22
- const diagnostics = await mounts.reconcile(await manager.enabledUserSuites());
23
- manager.mcpDiagnostics = diagnostics;
24
- for (const diagnostic of diagnostics) {
25
- ctx.logger?.warn(`[dsh-agent-plugins-market] suite "${diagnostic.suiteId}" mcp server "${diagnostic.serverKey}": ${diagnostic.reason}`);
26
- }
17
+ const snapshot = await catalog.readUserCatalog();
18
+ const diagnostics = await runtime.reconcile(snapshot.enabledSuites);
19
+ catalog.mcpDiagnostics = diagnostics.mcp;
20
+ for (const diagnostic of diagnostics.mcp) {
21
+ ctx.logger?.warn(`[dsh-agent-plugins-market] suite "${diagnostic.suiteId}" mcp server "${diagnostic.serverKey}": ${diagnostic.reason}`);
27
22
  }
28
- catch (error) {
29
- ctx.logger?.warn(`[dsh-agent-plugins-market] mcp reconcile failed: ${error instanceof Error ? error.message : String(error)}`);
23
+ for (const diagnostic of diagnostics.commands) {
24
+ if (diagnostic.reason !== '')
25
+ ctx.logger?.warn(`[dsh-agent-plugins-market] suite "${diagnostic.suiteId}" command "${diagnostic.command}": ${diagnostic.reason}`);
30
26
  }
31
- try {
32
- const diagnostics = await commandMounts.reconcile(await manager.enabledUserSuites());
33
- for (const diagnostic of diagnostics) {
34
- if (diagnostic.reason !== '')
35
- ctx.logger?.warn(`[dsh-agent-plugins-market] suite "${diagnostic.suiteId}" command "${diagnostic.command}": ${diagnostic.reason}`);
36
- }
27
+ for (const diagnostic of diagnostics.hooks) {
28
+ ctx.logger?.warn(`[dsh-agent-plugins-market] suite "${diagnostic.suiteId}" hooks: ${diagnostic.reason}`);
37
29
  }
38
- catch (error) {
39
- ctx.logger?.warn(`[dsh-agent-plugins-market] command reconcile failed: ${error instanceof Error ? error.message : String(error)}`);
30
+ for (const error of diagnostics.errors) {
31
+ ctx.logger?.warn(`[dsh-agent-plugins-market] ${error.surface} reconcile failed: ${error.reason}`);
40
32
  }
41
- try {
42
- const diagnostics = await hookMounts.reconcile(await manager.enabledUserSuites());
43
- for (const diagnostic of diagnostics) {
44
- ctx.logger?.warn(`[dsh-agent-plugins-market] suite "${diagnostic.suiteId}" hooks: ${diagnostic.reason}`);
45
- }
46
- }
47
- catch (error) {
48
- ctx.logger?.warn(`[dsh-agent-plugins-market] hooks reconcile failed: ${error instanceof Error ? error.message : String(error)}`);
49
- }
50
- })();
33
+ })().catch(error => {
34
+ ctx.logger?.warn(`[dsh-agent-plugins-market] runtime reconcile failed: ${error instanceof Error ? error.message : String(error)}`);
35
+ });
51
36
  };
52
37
  const onChanged = () => {
53
38
  providerControl?.invalidate();
54
39
  reconcileMounts();
55
40
  };
56
- const manager = new SuiteManager({ userRoot, dataRoot, onChanged });
57
- ctx.inject(['tools'], (toolsCtx) => {
58
- manager.setMcpToolSnapshotProvider(() => inspectToolRegistry(toolsCtx.tools));
41
+ const catalog = new Catalog({ userRoot, dataRoot, onChanged });
42
+ ctx.inject(['tools'], toolsCtx => {
43
+ catalog.setMcpToolSnapshotProvider(() => inspectToolRegistry(toolsCtx.tools));
59
44
  });
60
- void manager.load().then(async () => {
61
- await manager.mergeSources(config.sources ?? []);
45
+ void catalog.load().then(async () => {
46
+ await catalog.mergeSources(config.sources ?? []);
62
47
  reconcileMounts();
63
48
  });
64
- ctx.skills.registerProvider((control) => {
49
+ ctx.skills.registerProvider(control => {
65
50
  providerControl = control;
66
- return new SuiteSkillProvider(manager);
51
+ return new SuiteSkillProvider(catalog);
67
52
  });
68
- const disposeContext = mountSuiteContext(ctx, manager);
69
- ctx.inject(['webServer', 'loader'], (hostCtx) => {
70
- hostCtx.effect(() => mountSuiteRoutes(hostCtx, manager), 'dsh-agent-plugins-market: http routes');
53
+ const disposeContext = mountSuiteContext(ctx, catalog);
54
+ ctx.inject(['webServer', 'loader'], hostCtx => {
55
+ hostCtx.effect(() => mountSuiteRoutes(hostCtx, catalog), 'dsh-agent-plugins-market: http routes');
71
56
  });
72
57
  ctx.effect(() => () => {
73
- void mounts.disposeAll();
74
- void hookMounts.disposeAll();
75
- commandMounts.disposeAll();
58
+ void runtime.dispose();
76
59
  disposeContext();
77
60
  }, 'dsh-agent-plugins-market: lifecycle');
78
61
  }
@@ -37,7 +37,7 @@ function normalizeState(record) {
37
37
  return [];
38
38
  const branch = typeof source['branch'] === 'string' ? source['branch'] : undefined;
39
39
  const local = source['local'] === true;
40
- return [{ id, url, ...branch === undefined ? {} : { branch }, ...local ? { local: true } : {} }];
40
+ return [{ id, url, ...(branch === undefined ? {} : { branch }), ...(local ? { local: true } : {}) }];
41
41
  })
42
42
  : [];
43
43
  const installed = {};
@@ -49,7 +49,7 @@ function normalizeState(record) {
49
49
  installed[key] = {
50
50
  enabled: entry['enabled'] === true,
51
51
  lockCommit: typeof entry['lockCommit'] === 'string' ? entry['lockCommit'] : undefined,
52
- installedAt: typeof entry['installedAt'] === 'string' ? entry['installedAt'] : new Date(0).toISOString(),
52
+ installedAt: typeof entry['installedAt'] === 'string' ? entry['installedAt'] : new Date(0).toISOString()
53
53
  };
54
54
  }
55
55
  }