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.
- package/README.md +16 -10
- package/README.zh.md +16 -10
- package/client/client.js +540 -417
- package/client/client.js.map +1 -1
- package/lib/application/catalog.js +447 -0
- package/lib/application/details.js +136 -0
- package/lib/application/queries.js +1 -0
- package/lib/{discovery → catalog}/manifests.js +20 -12
- package/lib/{paths.js → catalog/paths.js} +5 -1
- package/lib/{skills-parse.js → catalog/skills-parse.js} +7 -4
- package/lib/catalog/source-catalog.js +38 -0
- package/lib/{discovery.js → catalog/suite-scanner.js} +28 -86
- package/lib/{discovery → catalog}/surfaces.js +9 -11
- package/lib/{validate.js → catalog/validate.js} +3 -3
- package/lib/context.js +11 -13
- package/lib/contracts/market.js +27 -0
- package/lib/contracts/mcp-status.js +2 -0
- package/lib/index.js +32 -49
- package/lib/{state.js → model/state.js} +2 -2
- package/lib/routes.js +21 -21
- package/lib/{commands-mounts.js → runtime/commands-mounts.js} +10 -11
- package/lib/{hooks-mounts.js → runtime/hooks-mounts.js} +1 -1
- package/lib/{mcp-config.js → runtime/mcp-config.js} +7 -4
- package/lib/{mcp-status.js → runtime/mcp-status.js} +8 -41
- package/lib/runtime/reconciler.js +46 -0
- package/lib/{skills-provider.js → runtime/skills-provider.js} +26 -23
- package/lib/runtime/tool-registry-observer.js +35 -0
- package/lib/types/application/catalog.d.ts +113 -0
- package/lib/types/application/details.d.ts +12 -0
- package/lib/types/application/queries.d.ts +33 -0
- package/lib/types/{discovery → catalog}/manifests.d.ts +1 -1
- package/lib/types/catalog/source-catalog.d.ts +3 -0
- package/lib/types/catalog/suite-scanner.d.ts +9 -0
- package/lib/types/{discovery → catalog}/surfaces.d.ts +1 -1
- package/lib/types/{validate.d.ts → catalog/validate.d.ts} +1 -1
- package/lib/types/context.d.ts +2 -2
- package/lib/types/contracts/market.d.ts +153 -0
- package/lib/types/contracts/mcp-status.d.ts +38 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/{types.d.ts → model/types.d.ts} +2 -42
- package/lib/types/routes.d.ts +2 -2
- package/lib/types/{commands-mounts.d.ts → runtime/commands-mounts.d.ts} +1 -1
- package/lib/types/{hooks-mounts.d.ts → runtime/hooks-mounts.d.ts} +1 -1
- package/lib/types/{mcp-config.d.ts → runtime/mcp-config.d.ts} +1 -1
- package/lib/types/{mcp-mounts.d.ts → runtime/mcp-mounts.d.ts} +1 -1
- package/lib/types/runtime/mcp-status.d.ts +13 -0
- package/lib/types/runtime/reconciler.d.ts +33 -0
- package/lib/types/{skills-provider.d.ts → runtime/skills-provider.d.ts} +3 -3
- package/lib/types/runtime/tool-registry-observer.d.ts +14 -0
- package/package.json +34 -19
- package/schemas/README.md +2 -5
- package/lib/manager.js +0 -581
- package/lib/types/discovery.d.ts +0 -19
- package/lib/types/manager.d.ts +0 -124
- package/lib/types/mcp-status.d.ts +0 -51
- /package/lib/{git.js → catalog/git.js} +0 -0
- /package/lib/{types.js → model/types.js} +0 -0
- /package/lib/{mcp-mounts.js → runtime/mcp-mounts.js} +0 -0
- /package/lib/types/{git.d.ts → catalog/git.d.ts} +0 -0
- /package/lib/types/{paths.d.ts → catalog/paths.d.ts} +0 -0
- /package/lib/types/{skills-parse.d.ts → catalog/skills-parse.d.ts} +0 -0
- /package/lib/types/{state.d.ts → model/state.d.ts} +0 -0
package/lib/routes.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HTTP routes bridging the market page to the
|
|
2
|
+
* HTTP routes bridging the market page to the application market service.
|
|
3
3
|
*
|
|
4
|
-
* This layer only parses requests, delegates to the
|
|
4
|
+
* This layer only parses requests, delegates to the application service, and serializes
|
|
5
5
|
* responses. Mutating routes accept same-origin POSTs exclusively: a
|
|
6
6
|
* cross-site form or fetch cannot trigger a clone, an uninstall, or an
|
|
7
7
|
* enable/disable against a local profile.
|
|
8
8
|
*/
|
|
9
9
|
import { isAbsolute } from 'node:path';
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import { MARKET_ROUTES } from './contracts/market.js';
|
|
11
|
+
import { expandHome } from './catalog/paths.js';
|
|
12
12
|
const MAX_BODY_BYTES = 64 * 1024;
|
|
13
13
|
/** Mount every route; returns the disposer releasing them all. */
|
|
14
14
|
export function mountSuiteRoutes(hostCtx, manager) {
|
|
@@ -40,22 +40,22 @@ export function mountSuiteRoutes(hostCtx, manager) {
|
|
|
40
40
|
sendJson(response, 400, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
41
41
|
}
|
|
42
42
|
})();
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
}));
|
|
45
45
|
};
|
|
46
|
-
get(
|
|
46
|
+
get(MARKET_ROUTES.overview, async (_request, response) => {
|
|
47
47
|
sendJson(response, 200, await manager.overview());
|
|
48
48
|
});
|
|
49
|
-
get(
|
|
49
|
+
get(MARKET_ROUTES.mcpStatus, async (_request, response) => {
|
|
50
50
|
sendJson(response, 200, await manager.mcpStatus());
|
|
51
51
|
});
|
|
52
|
-
get(
|
|
52
|
+
get(MARKET_ROUTES.progress, async (_request, response) => {
|
|
53
53
|
sendJson(response, 200, manager.sourceProgress());
|
|
54
54
|
});
|
|
55
|
-
get(
|
|
55
|
+
get(MARKET_ROUTES.config, async (_request, response) => {
|
|
56
56
|
sendJson(response, 200, { sources: manager.sources });
|
|
57
57
|
});
|
|
58
|
-
get(
|
|
58
|
+
get(MARKET_ROUTES.suite, async (request, response) => {
|
|
59
59
|
const query = queryOf(request);
|
|
60
60
|
const sourceId = query.get('sourceId');
|
|
61
61
|
const suiteId = query.get('suiteId');
|
|
@@ -70,7 +70,7 @@ export function mountSuiteRoutes(hostCtx, manager) {
|
|
|
70
70
|
sendJson(response, 404, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
|
-
get(
|
|
73
|
+
get(MARKET_ROUTES.skill, async (request, response) => {
|
|
74
74
|
const query = queryOf(request);
|
|
75
75
|
const sourceId = query.get('sourceId');
|
|
76
76
|
const suiteId = query.get('suiteId');
|
|
@@ -86,7 +86,7 @@ export function mountSuiteRoutes(hostCtx, manager) {
|
|
|
86
86
|
sendJson(response, 404, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
-
post(
|
|
89
|
+
post(MARKET_ROUTES.addSource, async (body) => {
|
|
90
90
|
const url = String(body['url'] ?? '').trim();
|
|
91
91
|
if (url === '')
|
|
92
92
|
throw new Error('missing source url');
|
|
@@ -99,12 +99,12 @@ export function mountSuiteRoutes(hostCtx, manager) {
|
|
|
99
99
|
const branch = body['branch'];
|
|
100
100
|
const source = await manager.addSource({
|
|
101
101
|
url: local ? expandHome(url) : url,
|
|
102
|
-
...typeof branch === 'string' && branch.trim() !== '' ? { branch: branch.trim() } : {},
|
|
103
|
-
...local ? { local: true } : {}
|
|
102
|
+
...(typeof branch === 'string' && branch.trim() !== '' ? { branch: branch.trim() } : {}),
|
|
103
|
+
...(local ? { local: true } : {})
|
|
104
104
|
});
|
|
105
105
|
return { source };
|
|
106
106
|
});
|
|
107
|
-
post(
|
|
107
|
+
post(MARKET_ROUTES.updateSource, async (body) => {
|
|
108
108
|
const id = body['id'];
|
|
109
109
|
if (typeof id !== 'string' || id === '')
|
|
110
110
|
throw new Error('missing source id');
|
|
@@ -122,29 +122,29 @@ export function mountSuiteRoutes(hostCtx, manager) {
|
|
|
122
122
|
await manager.updateSource(id, patch);
|
|
123
123
|
return {};
|
|
124
124
|
});
|
|
125
|
-
post(
|
|
125
|
+
post(MARKET_ROUTES.removeSource, async (body) => {
|
|
126
126
|
const id = body['id'];
|
|
127
127
|
if (typeof id !== 'string' || id === '')
|
|
128
128
|
throw new Error('missing source id');
|
|
129
129
|
await manager.removeSource(id);
|
|
130
130
|
return {};
|
|
131
131
|
});
|
|
132
|
-
post(
|
|
132
|
+
post(MARKET_ROUTES.refreshSource, async (body) => {
|
|
133
133
|
const id = body['id'];
|
|
134
134
|
await manager.refreshSource(typeof id === 'string' && id !== '' ? id : undefined);
|
|
135
135
|
return {};
|
|
136
136
|
});
|
|
137
|
-
post(
|
|
137
|
+
post(MARKET_ROUTES.install, async (body) => {
|
|
138
138
|
const { sourceId, suiteId } = parseTarget(body);
|
|
139
139
|
await manager.install(sourceId, suiteId);
|
|
140
140
|
return {};
|
|
141
141
|
});
|
|
142
|
-
post(
|
|
142
|
+
post(MARKET_ROUTES.uninstall, async (body) => {
|
|
143
143
|
const { sourceId, suiteId } = parseTarget(body);
|
|
144
144
|
await manager.uninstall(sourceId, suiteId);
|
|
145
145
|
return {};
|
|
146
146
|
});
|
|
147
|
-
post(
|
|
147
|
+
post(MARKET_ROUTES.setEnabled, async (body) => {
|
|
148
148
|
const { sourceId, suiteId } = parseTarget(body);
|
|
149
149
|
const enabled = body['enabled'];
|
|
150
150
|
if (typeof enabled !== 'boolean')
|
|
@@ -178,7 +178,7 @@ function sameOrigin(request) {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
function readJsonBody(request) {
|
|
181
|
-
return new Promise(
|
|
181
|
+
return new Promise(resolve => {
|
|
182
182
|
let size = 0;
|
|
183
183
|
const chunks = [];
|
|
184
184
|
request.on('data', (chunk) => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { readFile, readdir } from 'node:fs/promises';
|
|
14
14
|
import { join } from 'node:path';
|
|
15
15
|
import { parse as parseYaml } from 'yaml';
|
|
16
|
-
import { parseSkillFrontmatter, stripFrontmatter } from '
|
|
16
|
+
import { parseSkillFrontmatter, stripFrontmatter } from '../catalog/skills-parse.js';
|
|
17
17
|
const COMMAND_NAME = /^[a-z][a-z0-9_-]*$/;
|
|
18
18
|
export class CommandMountRegistry {
|
|
19
19
|
ctx;
|
|
@@ -26,7 +26,7 @@ export class CommandMountRegistry {
|
|
|
26
26
|
const diagnostics = [];
|
|
27
27
|
const wanted = new Map();
|
|
28
28
|
for (const suite of enabledSuites) {
|
|
29
|
-
for (const spec of [...await readCommands(suite.root), ...await readAgents(suite.root)]) {
|
|
29
|
+
for (const spec of [...(await readCommands(suite.root)), ...(await readAgents(suite.root))]) {
|
|
30
30
|
const key = `${suite.id}/${spec.name}`;
|
|
31
31
|
wanted.set(key, { ...spec, suiteId: suite.id, suiteName: suite.manifest.name });
|
|
32
32
|
}
|
|
@@ -50,17 +50,13 @@ export class CommandMountRegistry {
|
|
|
50
50
|
const disposer = host.commands.register({
|
|
51
51
|
name: spec.name,
|
|
52
52
|
description: `[${spec.suiteName}] ${spec.description}`,
|
|
53
|
-
...spec.hint === undefined ? {} : { input: { hint: spec.hint } },
|
|
54
|
-
handler:
|
|
53
|
+
...(spec.hint === undefined ? {} : { input: { hint: spec.hint } }),
|
|
54
|
+
handler: invocation => {
|
|
55
55
|
const agent = invocation.agent;
|
|
56
|
-
const text = [
|
|
57
|
-
`[Agent Plugins 命令 /${spec.name}(来自 ${spec.suiteId})]`,
|
|
58
|
-
'',
|
|
59
|
-
spec.body.replaceAll('$ARGUMENTS', invocation.rawInput.trim()),
|
|
60
|
-
].join('\n');
|
|
56
|
+
const text = [`[Agent Plugins 命令 /${spec.name}(来自 ${spec.suiteId})]`, '', spec.body.replaceAll('$ARGUMENTS', invocation.rawInput.trim())].join('\n');
|
|
61
57
|
agent.followup({ content: [{ type: 'text', text }], source: { kind: 'plugin', plugin: 'dsh-agent-plugins-market' } });
|
|
62
58
|
return { kind: 'success', text: `/${spec.name} 已转交模型执行(${spec.suiteId})` };
|
|
63
|
-
}
|
|
59
|
+
}
|
|
64
60
|
});
|
|
65
61
|
this.live.set(key, disposer);
|
|
66
62
|
}
|
|
@@ -164,6 +160,9 @@ function commandMeta(text) {
|
|
|
164
160
|
}
|
|
165
161
|
}
|
|
166
162
|
function firstLine(text) {
|
|
167
|
-
const line = text
|
|
163
|
+
const line = text
|
|
164
|
+
.split('\n')
|
|
165
|
+
.map(line => line.trim())
|
|
166
|
+
.find(line => line !== '');
|
|
168
167
|
return line;
|
|
169
168
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* are skipped with a per-server reason.
|
|
11
11
|
*/
|
|
12
12
|
import { createHash } from 'node:crypto';
|
|
13
|
-
import { expandPlaceholders, resolveCwd } from '
|
|
13
|
+
import { expandPlaceholders, resolveCwd } from '../catalog/validate.js';
|
|
14
14
|
/** The max length `dsh-mcp-client` accepts for a serverName. */
|
|
15
15
|
const SERVER_NAME_MAX = 32;
|
|
16
16
|
/**
|
|
@@ -57,7 +57,7 @@ function toStdio(serverName, suite, server, pluginDataRoot) {
|
|
|
57
57
|
env,
|
|
58
58
|
cwd,
|
|
59
59
|
toolCallTimeoutMs: 60_000,
|
|
60
|
-
failOnStartupError: false
|
|
60
|
+
failOnStartupError: false
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
function toHttp(serverName, suite, server, pluginDataRoot) {
|
|
@@ -69,7 +69,7 @@ function toHttp(serverName, suite, server, pluginDataRoot) {
|
|
|
69
69
|
url: server.url,
|
|
70
70
|
headers,
|
|
71
71
|
toolCallTimeoutMs: 60_000,
|
|
72
|
-
failOnStartupError: false
|
|
72
|
+
failOnStartupError: false
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
function transportReason(server) {
|
|
@@ -82,7 +82,10 @@ function joinInside(root, segment) {
|
|
|
82
82
|
}
|
|
83
83
|
/** Sanitize one token into `[A-Za-z0-9_-]`. */
|
|
84
84
|
function sanitizeToken(raw) {
|
|
85
|
-
const cleaned = raw
|
|
85
|
+
const cleaned = raw
|
|
86
|
+
.replace(/[^A-Za-z0-9_-]+/g, '_')
|
|
87
|
+
.replace(/_+/g, '_')
|
|
88
|
+
.replace(/^_+|_+$/g, '');
|
|
86
89
|
return cleaned === '' ? 'server' : cleaned;
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { deriveServerName } from './mcp-config.js';
|
|
2
|
+
import { inspectToolRegistry } from './tool-registry-observer.js';
|
|
3
|
+
export { inspectToolRegistry };
|
|
2
4
|
/** Build status rows from discovered plugin MCP definitions and observed tool names. */
|
|
3
5
|
export function buildMcpStatus(suites, diagnostics, observed) {
|
|
4
6
|
const entries = [];
|
|
@@ -22,11 +24,7 @@ export function buildMcpStatus(suites, diagnostics, observed) {
|
|
|
22
24
|
const tools = observedByServer.get(serverName) ?? [];
|
|
23
25
|
claimedServers.add(serverName);
|
|
24
26
|
const diagnostic = diagnosticsByKey.get(`${suite.id}\u0000${serverKey}`);
|
|
25
|
-
const state = diagnostic !== undefined
|
|
26
|
-
? 'failed'
|
|
27
|
-
: tools.length > 0
|
|
28
|
-
? 'connected'
|
|
29
|
-
: 'degraded';
|
|
27
|
+
const state = diagnostic !== undefined ? 'failed' : tools.length > 0 ? 'connected' : 'degraded';
|
|
30
28
|
entries.push({
|
|
31
29
|
id: `plugin:${suite.sourceId}/${suite.id}/${serverKey}`,
|
|
32
30
|
name: serverName,
|
|
@@ -38,8 +36,8 @@ export function buildMcpStatus(suites, diagnostics, observed) {
|
|
|
38
36
|
transport: server.type,
|
|
39
37
|
endpoint: endpointOf(server),
|
|
40
38
|
config: redactConfig(server),
|
|
41
|
-
tools: tools.map(tool => ({ name: tool.name, ...tool.description === undefined ? {} : { description: tool.description } })),
|
|
42
|
-
...diagnostic === undefined ? {} : { reason: diagnostic.reason }
|
|
39
|
+
tools: tools.map(tool => ({ name: tool.name, ...(tool.description === undefined ? {} : { description: tool.description }) })),
|
|
40
|
+
...(diagnostic === undefined ? {} : { reason: diagnostic.reason })
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
43
|
}
|
|
@@ -52,7 +50,7 @@ export function buildMcpStatus(suites, diagnostics, observed) {
|
|
|
52
50
|
kind: 'direct',
|
|
53
51
|
state: 'connected',
|
|
54
52
|
transport: 'observed',
|
|
55
|
-
tools: tools.map(tool => ({ name: tool.name, ...tool.description === undefined ? {} : { description: tool.description } }))
|
|
53
|
+
tools: tools.map(tool => ({ name: tool.name, ...(tool.description === undefined ? {} : { description: tool.description }) }))
|
|
56
54
|
});
|
|
57
55
|
}
|
|
58
56
|
const totals = {
|
|
@@ -60,7 +58,7 @@ export function buildMcpStatus(suites, diagnostics, observed) {
|
|
|
60
58
|
connected: entries.filter(entry => entry.state === 'connected').length,
|
|
61
59
|
degraded: entries.filter(entry => entry.state === 'degraded').length,
|
|
62
60
|
failed: entries.filter(entry => entry.state === 'failed').length,
|
|
63
|
-
disabled: entries.filter(entry => entry.state === 'disabled').length
|
|
61
|
+
disabled: entries.filter(entry => entry.state === 'disabled').length
|
|
64
62
|
};
|
|
65
63
|
return { entries, observedAt: new Date().toISOString(), totals, directObservationOnly: true };
|
|
66
64
|
}
|
|
@@ -90,7 +88,7 @@ function groupObservedTools(observed, knownServerNames) {
|
|
|
90
88
|
if (serverName === undefined || rawName === undefined || rawName === '')
|
|
91
89
|
continue;
|
|
92
90
|
const list = grouped.get(serverName) ?? [];
|
|
93
|
-
list.push({ name: rawName, ...tool.description === undefined ? {} : { description: tool.description } });
|
|
91
|
+
list.push({ name: rawName, ...(tool.description === undefined ? {} : { description: tool.description }) });
|
|
94
92
|
grouped.set(serverName, list);
|
|
95
93
|
}
|
|
96
94
|
return grouped;
|
|
@@ -114,34 +112,3 @@ function redactValue(value, key = '') {
|
|
|
114
112
|
}
|
|
115
113
|
return value;
|
|
116
114
|
}
|
|
117
|
-
/** Read model-facing MCP tool names from the dsh-tools runtime when available.
|
|
118
|
-
* The registry intentionally has no public listing API in rc.6; this adapter
|
|
119
|
-
* uses only the runtime's stable `layers.merge(...).tools.entries()` data shape
|
|
120
|
-
* and safely returns an empty observation when another host changes it. */
|
|
121
|
-
export function inspectToolRegistry(runtime) {
|
|
122
|
-
if (typeof runtime !== 'object' || runtime === null)
|
|
123
|
-
return [];
|
|
124
|
-
const layers = runtime.layers;
|
|
125
|
-
if (typeof layers !== 'object' || layers === null)
|
|
126
|
-
return [];
|
|
127
|
-
const merge = layers.merge;
|
|
128
|
-
if (typeof merge !== 'function')
|
|
129
|
-
return [];
|
|
130
|
-
const empty = { entries: () => [] };
|
|
131
|
-
try {
|
|
132
|
-
const visible = merge.call(layers, undefined, layer => layer.tools ?? empty);
|
|
133
|
-
const output = [];
|
|
134
|
-
for (const [name, definition] of visible.entries()) {
|
|
135
|
-
if (!name.startsWith('mcp__'))
|
|
136
|
-
continue;
|
|
137
|
-
const description = typeof definition === 'object' && definition !== null && typeof definition.description === 'string'
|
|
138
|
-
? definition.description
|
|
139
|
-
: undefined;
|
|
140
|
-
output.push({ name, ...description === undefined ? {} : { description } });
|
|
141
|
-
}
|
|
142
|
-
return output;
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CommandMountRegistry } from './commands-mounts.js';
|
|
2
|
+
import { HooksMountRegistry } from './hooks-mounts.js';
|
|
3
|
+
import { McpMountRegistry } from './mcp-mounts.js';
|
|
4
|
+
export class RuntimeReconciler {
|
|
5
|
+
mcp;
|
|
6
|
+
commands;
|
|
7
|
+
hooks;
|
|
8
|
+
constructor(ctx, dataRoot) {
|
|
9
|
+
this.mcp = new McpMountRegistry(ctx, dataRoot);
|
|
10
|
+
this.commands = new CommandMountRegistry(ctx);
|
|
11
|
+
this.hooks = new HooksMountRegistry(ctx);
|
|
12
|
+
}
|
|
13
|
+
/** Reconcile all runtime surfaces against one enabled-suite snapshot. */
|
|
14
|
+
async reconcile(enabledSuites) {
|
|
15
|
+
const suites = [...enabledSuites];
|
|
16
|
+
const diagnostics = { mcp: [], commands: [], hooks: [], errors: [] };
|
|
17
|
+
try {
|
|
18
|
+
diagnostics.mcp = await this.mcp.reconcile(suites);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
diagnostics.errors.push({ surface: 'mcp', reason: messageOf(error) });
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
diagnostics.commands = await this.commands.reconcile(suites);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
diagnostics.errors.push({ surface: 'commands', reason: messageOf(error) });
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
diagnostics.hooks = await this.hooks.reconcile(suites);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
diagnostics.errors.push({ surface: 'hooks', reason: messageOf(error) });
|
|
34
|
+
}
|
|
35
|
+
return diagnostics;
|
|
36
|
+
}
|
|
37
|
+
/** Dispose all live mounts and registrations. */
|
|
38
|
+
async dispose() {
|
|
39
|
+
await this.mcp.disposeAll();
|
|
40
|
+
await this.hooks.disposeAll();
|
|
41
|
+
this.commands.disposeAll();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function messageOf(error) {
|
|
45
|
+
return error instanceof Error ? error.message : String(error);
|
|
46
|
+
}
|
|
@@ -14,10 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
16
16
|
import { join } from 'node:path';
|
|
17
|
-
import {
|
|
18
|
-
import { resolveProjectRoot, STATE_FILE_NAME } from './paths.js';
|
|
19
|
-
import { discoverSourceList } from './discovery.js';
|
|
20
|
-
import { parseSkillFrontmatter, stripFrontmatter } from './skills-parse.js';
|
|
17
|
+
import { parseSkillFrontmatter, stripFrontmatter } from '../catalog/skills-parse.js';
|
|
21
18
|
export const SUITE_PROJECT_SOURCE = 'agent-plugin-project';
|
|
22
19
|
export const SUITE_USER_SOURCE = 'agent-plugin-user';
|
|
23
20
|
const PROJECT_RANK = 250;
|
|
@@ -65,20 +62,25 @@ export class SuiteSkillProvider {
|
|
|
65
62
|
continue;
|
|
66
63
|
}
|
|
67
64
|
const parsed = parseSkillFrontmatter(text, agentName);
|
|
68
|
-
const description = typeof parsed === 'string' ? suite.manifest.description ?? agentName : parsed.description;
|
|
65
|
+
const description = typeof parsed === 'string' ? (suite.manifest.description ?? agentName) : parsed.description;
|
|
69
66
|
const skill = {
|
|
70
67
|
name: `agent-${agentName}`,
|
|
71
68
|
directory: dir,
|
|
72
69
|
file,
|
|
73
70
|
description,
|
|
74
71
|
...(typeof parsed !== 'string' && parsed.whenToUse !== undefined ? { whenToUse: parsed.whenToUse } : {}),
|
|
75
|
-
invocation: typeof parsed === 'string' ? { modelInvocable: true, userInvocable: false } : parsed.invocation
|
|
72
|
+
invocation: typeof parsed === 'string' ? { modelInvocable: true, userInvocable: false } : parsed.invocation
|
|
76
73
|
};
|
|
77
|
-
located.push({
|
|
74
|
+
located.push({
|
|
75
|
+
rank: suite.dimension === 'project' ? PROJECT_RANK : USER_RANK,
|
|
76
|
+
source: suite.dimension === 'project' ? SUITE_PROJECT_SOURCE : SUITE_USER_SOURCE,
|
|
77
|
+
suite,
|
|
78
|
+
skill
|
|
79
|
+
});
|
|
78
80
|
}
|
|
79
81
|
return located;
|
|
80
82
|
}
|
|
81
|
-
async get(candidate,
|
|
83
|
+
async get(candidate, _options) {
|
|
82
84
|
const locator = candidate.locator;
|
|
83
85
|
let text;
|
|
84
86
|
try {
|
|
@@ -96,7 +98,7 @@ export class SuiteSkillProvider {
|
|
|
96
98
|
'',
|
|
97
99
|
'```markdown',
|
|
98
100
|
text,
|
|
99
|
-
'```'
|
|
101
|
+
'```'
|
|
100
102
|
].join('\n');
|
|
101
103
|
return {
|
|
102
104
|
name: candidate.name,
|
|
@@ -106,7 +108,7 @@ export class SuiteSkillProvider {
|
|
|
106
108
|
provider: this.name,
|
|
107
109
|
resourceBase: { kind: 'directory', path: locator.directory },
|
|
108
110
|
path: locator.file,
|
|
109
|
-
content
|
|
111
|
+
content
|
|
110
112
|
};
|
|
111
113
|
}
|
|
112
114
|
const parsed = parseSkillFrontmatter(text, candidate.name);
|
|
@@ -116,27 +118,32 @@ export class SuiteSkillProvider {
|
|
|
116
118
|
return {
|
|
117
119
|
name: parsed.name,
|
|
118
120
|
description: candidate.description,
|
|
119
|
-
...parsed.whenToUse === undefined ? {} : { whenToUse: parsed.whenToUse },
|
|
121
|
+
...(parsed.whenToUse === undefined ? {} : { whenToUse: parsed.whenToUse }),
|
|
120
122
|
invocation: parsed.invocation,
|
|
121
123
|
source: candidate.source,
|
|
122
124
|
provider: this.name,
|
|
123
125
|
resourceBase: { kind: 'directory', path: locator.directory },
|
|
124
126
|
path: locator.file,
|
|
125
|
-
content
|
|
127
|
+
content
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
candidateFor(entry) {
|
|
129
131
|
return {
|
|
130
132
|
name: entry.skill.name,
|
|
131
133
|
description: `[${entry.suite.manifest.name}] ${entry.skill.description}`,
|
|
132
|
-
...entry.skill.whenToUse === undefined ? {} : { whenToUse: entry.skill.whenToUse },
|
|
134
|
+
...(entry.skill.whenToUse === undefined ? {} : { whenToUse: entry.skill.whenToUse }),
|
|
133
135
|
invocation: entry.skill.invocation,
|
|
134
136
|
source: entry.source,
|
|
135
137
|
provider: this.name,
|
|
136
138
|
rank: entry.rank,
|
|
137
|
-
locator: {
|
|
139
|
+
locator: {
|
|
140
|
+
file: entry.skill.file,
|
|
141
|
+
directory: entry.skill.directory,
|
|
142
|
+
suiteRoot: entry.suite.root,
|
|
143
|
+
kind: entry.skill.name.startsWith('agent-') ? 'agent' : 'skill'
|
|
144
|
+
},
|
|
138
145
|
path: entry.skill.file,
|
|
139
|
-
resourceBase: { kind: 'directory', path: entry.skill.directory }
|
|
146
|
+
resourceBase: { kind: 'directory', path: entry.skill.directory }
|
|
140
147
|
};
|
|
141
148
|
}
|
|
142
149
|
async locate(cwd) {
|
|
@@ -146,21 +153,17 @@ export class SuiteSkillProvider {
|
|
|
146
153
|
for (const skill of suite.skills) {
|
|
147
154
|
located.push({ rank: USER_RANK, source: SUITE_USER_SOURCE, suite, skill });
|
|
148
155
|
}
|
|
149
|
-
located.push(...await this.agentsOf(suite));
|
|
156
|
+
located.push(...(await this.agentsOf(suite)));
|
|
150
157
|
}
|
|
151
158
|
if (cwd !== undefined) {
|
|
152
|
-
located.push(...await this.locateProject(cwd));
|
|
159
|
+
located.push(...(await this.locateProject(cwd)));
|
|
153
160
|
}
|
|
154
161
|
return located;
|
|
155
162
|
}
|
|
156
163
|
async locateProject(cwd) {
|
|
157
|
-
const
|
|
158
|
-
const state = await loadState(join(projectRoot, STATE_FILE_NAME));
|
|
164
|
+
const snapshot = await this.manager.readProjectCatalog(cwd);
|
|
159
165
|
const located = [];
|
|
160
|
-
const
|
|
161
|
-
for (const suite of suites) {
|
|
162
|
-
if (state.installed[`${suite.sourceId}/${suite.id}`]?.enabled !== true)
|
|
163
|
-
continue;
|
|
166
|
+
for (const suite of snapshot.enabledSuites) {
|
|
164
167
|
for (const skill of suite.skills) {
|
|
165
168
|
located.push({ rank: PROJECT_RANK, source: SUITE_PROJECT_SOURCE, suite, skill });
|
|
166
169
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Host-private adapter for observing model-facing MCP tools. */
|
|
2
|
+
/**
|
|
3
|
+
* Read MCP tool names from the dsh-tools runtime when available.
|
|
4
|
+
*
|
|
5
|
+
* The registry has no public listing API in the current host release. This
|
|
6
|
+
* adapter uses the observed `layers.merge(...).tools.entries()` data shape and
|
|
7
|
+
* returns an empty observation when a host changes it.
|
|
8
|
+
*/
|
|
9
|
+
export function inspectToolRegistry(runtime) {
|
|
10
|
+
if (typeof runtime !== 'object' || runtime === null)
|
|
11
|
+
return [];
|
|
12
|
+
const layers = runtime.layers;
|
|
13
|
+
if (typeof layers !== 'object' || layers === null)
|
|
14
|
+
return [];
|
|
15
|
+
const merge = layers.merge;
|
|
16
|
+
if (typeof merge !== 'function')
|
|
17
|
+
return [];
|
|
18
|
+
const empty = { entries: () => [] };
|
|
19
|
+
try {
|
|
20
|
+
const visible = merge.call(layers, undefined, layer => layer.tools ?? empty);
|
|
21
|
+
const output = [];
|
|
22
|
+
for (const [name, definition] of visible.entries()) {
|
|
23
|
+
if (!name.startsWith('mcp__'))
|
|
24
|
+
continue;
|
|
25
|
+
const description = typeof definition === 'object' && definition !== null && typeof definition.description === 'string'
|
|
26
|
+
? definition.description
|
|
27
|
+
: undefined;
|
|
28
|
+
output.push({ name, ...(description === undefined ? {} : { description }) });
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type McpToolSnapshot } from '../runtime/mcp-status.js';
|
|
2
|
+
import type { McpStatusPayload } from '../contracts/mcp-status.js';
|
|
3
|
+
import type { OverviewPayload, SkillContent, SuiteDetail } from '../contracts/market.js';
|
|
4
|
+
import type { SourceRef, Suite, SuiteDimension } from '../model/types.js';
|
|
5
|
+
/** Dependencies and host callback used by the catalog application module. */
|
|
6
|
+
export interface CatalogOptions {
|
|
7
|
+
userRoot: string;
|
|
8
|
+
dataRoot: string;
|
|
9
|
+
onChanged: () => void;
|
|
10
|
+
}
|
|
11
|
+
/** A coherent discovered-and-installed view for one catalog dimension. */
|
|
12
|
+
export interface CatalogSnapshot {
|
|
13
|
+
revision: number;
|
|
14
|
+
sources: SourceRef[];
|
|
15
|
+
suites: Suite[];
|
|
16
|
+
enabledSuites: Suite[];
|
|
17
|
+
}
|
|
18
|
+
export declare class Catalog {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private state;
|
|
21
|
+
private mutationQueue;
|
|
22
|
+
private readonly statePath;
|
|
23
|
+
private readonly headCache;
|
|
24
|
+
private readonly listeners;
|
|
25
|
+
private revision;
|
|
26
|
+
private userSnapshot;
|
|
27
|
+
private userSnapshotPromise;
|
|
28
|
+
/** Latest MCP mount diagnostics (suiteId -> reasons), fed by host reconcile. */
|
|
29
|
+
mcpDiagnostics: Array<{
|
|
30
|
+
suiteId: string;
|
|
31
|
+
serverKey: string;
|
|
32
|
+
reason: string;
|
|
33
|
+
}>;
|
|
34
|
+
private toolSnapshotProvider;
|
|
35
|
+
constructor(options: CatalogOptions);
|
|
36
|
+
/** Install the host tool snapshot provider used by the MCP status surface. */
|
|
37
|
+
setMcpToolSnapshotProvider(provider: () => readonly McpToolSnapshot[]): void;
|
|
38
|
+
/** Subscribe to completed catalog mutations; returns an unsubscribe function. */
|
|
39
|
+
subscribe(listener: () => void): () => void;
|
|
40
|
+
/** Build the flat MCP service inventory for the status surface. */
|
|
41
|
+
mcpStatus(): Promise<McpStatusPayload>;
|
|
42
|
+
/** Load persisted user state once at plugin activation. */
|
|
43
|
+
load(): Promise<void>;
|
|
44
|
+
get sources(): SourceRef[];
|
|
45
|
+
/** The user-dimension suite root this catalog operates. */
|
|
46
|
+
get userRoot(): string;
|
|
47
|
+
/** Read one coherent user-dimension snapshot, reusing in-flight discovery. */
|
|
48
|
+
readUserCatalog(): Promise<CatalogSnapshot>;
|
|
49
|
+
/** Read one coherent project-dimension snapshot for a workspace cwd. */
|
|
50
|
+
readProjectCatalog(cwd: string): Promise<CatalogSnapshot>;
|
|
51
|
+
/** One suite's full detail for the market detail modal. */
|
|
52
|
+
suiteDetail(sourceId: string, suiteId: string): Promise<SuiteDetail>;
|
|
53
|
+
/** One skill's full SKILL.md text for the market detail modal. */
|
|
54
|
+
skillContent(sourceId: string, suiteId: string, skillName: string): Promise<SkillContent>;
|
|
55
|
+
/** The full market overview from one user snapshot. */
|
|
56
|
+
overview(): Promise<OverviewPayload>;
|
|
57
|
+
/** Enabled user-dimension suites from one user snapshot. */
|
|
58
|
+
enabledUserSuites(): Promise<Suite[]>;
|
|
59
|
+
/** Enabled user- and project-dimension suites for a workspace cwd. */
|
|
60
|
+
enabledSuitesForCwd(cwd: string): Promise<{
|
|
61
|
+
user: Suite[];
|
|
62
|
+
project: Suite[];
|
|
63
|
+
}>;
|
|
64
|
+
/** All suites of one dimension. */
|
|
65
|
+
suitesForDimension(dimension: SuiteDimension, dimensionRoot: string): Promise<Suite[]>;
|
|
66
|
+
/** Add a source and clone it immediately. */
|
|
67
|
+
addSource(input: {
|
|
68
|
+
url: string;
|
|
69
|
+
branch?: string;
|
|
70
|
+
local?: boolean;
|
|
71
|
+
}): Promise<SourceRef>;
|
|
72
|
+
/** Progress snapshot of the source mutation currently in flight. */
|
|
73
|
+
private currentSourceState;
|
|
74
|
+
/** Begin reporting progress for a source mutation. */
|
|
75
|
+
beginSourceState(sourceId: string, step: string, cloned: boolean): void;
|
|
76
|
+
/** Advance the in-flight source mutation step. */
|
|
77
|
+
updateSourceStep(step: string): void;
|
|
78
|
+
/** Stop reporting source mutation progress. */
|
|
79
|
+
endSourceState(): void;
|
|
80
|
+
/** Progress snapshot for the progress route. */
|
|
81
|
+
sourceProgress(): {
|
|
82
|
+
active: boolean;
|
|
83
|
+
sourceId: string;
|
|
84
|
+
step: string;
|
|
85
|
+
};
|
|
86
|
+
private uniqueSourceId;
|
|
87
|
+
/** Update one source's URL, branch, or local flag. */
|
|
88
|
+
updateSource(sourceId: string, patch: {
|
|
89
|
+
url?: string;
|
|
90
|
+
branch?: string;
|
|
91
|
+
local?: boolean;
|
|
92
|
+
}): Promise<void>;
|
|
93
|
+
/** Remove a source, its install entries, and its managed checkout. */
|
|
94
|
+
removeSource(sourceId: string): Promise<void>;
|
|
95
|
+
/** Refresh one source checkout, or every source when sourceId is omitted. */
|
|
96
|
+
refreshSource(sourceId?: string): Promise<void>;
|
|
97
|
+
/** Install a suite from a source and enable it. */
|
|
98
|
+
install(sourceId: string, suiteId: string): Promise<void>;
|
|
99
|
+
/** Uninstall a suite while retaining the source checkout. */
|
|
100
|
+
uninstall(sourceId: string, suiteId: string): Promise<void>;
|
|
101
|
+
/** Enable or disable an installed suite. */
|
|
102
|
+
setEnabled(sourceId: string, suiteId: string, enabled: boolean): Promise<void>;
|
|
103
|
+
/** Append config-seeded sources missing from user state and persist them. */
|
|
104
|
+
mergeSources(sources: SourceRef[]): Promise<void>;
|
|
105
|
+
private setInstalled;
|
|
106
|
+
private ensureClone;
|
|
107
|
+
/** The filesystem location of one source. */
|
|
108
|
+
private sourceCheckoutPath;
|
|
109
|
+
private buildSnapshot;
|
|
110
|
+
private invalidateSnapshot;
|
|
111
|
+
private notifyChanged;
|
|
112
|
+
private enqueue;
|
|
113
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SkillContent, SuiteDetail } from '../contracts/market.js';
|
|
2
|
+
import type { InstalledEntry, Suite } from '../model/types.js';
|
|
3
|
+
interface McpDiagnostic {
|
|
4
|
+
suiteId: string;
|
|
5
|
+
serverKey: string;
|
|
6
|
+
reason: string;
|
|
7
|
+
}
|
|
8
|
+
/** Build the detail response for one normalized suite. */
|
|
9
|
+
export declare function buildSuiteDetail(suite: Suite, installed: InstalledEntry | undefined, diagnostics: readonly McpDiagnostic[]): Promise<SuiteDetail>;
|
|
10
|
+
/** Read one skill body from a normalized suite. */
|
|
11
|
+
export declare function readSkillContent(suite: Suite, skillName: string): Promise<SkillContent>;
|
|
12
|
+
export {};
|