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/manager.js
DELETED
|
@@ -1,581 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SuiteManager: the host-authoritative orchestrator behind the market page.
|
|
3
|
-
*
|
|
4
|
-
* Owns the persisted state (sources + install entries), discovery over the
|
|
5
|
-
* source checkouts, and every mutating action (source add/remove/refresh,
|
|
6
|
-
* install/uninstall, enable/disable). Mutations serialize through a
|
|
7
|
-
* single-flight queue so concurrent HTTP actions cannot interleave state
|
|
8
|
-
* writes or git operations. After every mutation it calls `onChanged()`,
|
|
9
|
-
* which is where the runtime consumers (skill registry invalidation, MCP
|
|
10
|
-
* mount reconciliation) pick the new enabled set up.
|
|
11
|
-
*/
|
|
12
|
-
import { mkdir, readFile } from 'node:fs/promises';
|
|
13
|
-
import { join } from 'node:path';
|
|
14
|
-
import { discoverLspEntries, discoverSourceList, discoverSuitesInSource, listMdFiles, repoName } from './discovery.js';
|
|
15
|
-
import { gitClone, gitHead, gitPull, gitRemove } from './git.js';
|
|
16
|
-
import { buildMcpStatus } from './mcp-status.js';
|
|
17
|
-
import { deriveSourceId, expandHome, isDirectory, resolveProjectRoot, sanitizeId, sourceCheckoutDir, sourcesDir, STATE_FILE_NAME } from './paths.js';
|
|
18
|
-
import { loadState, saveState, EMPTY_STATE } from './state.js';
|
|
19
|
-
export class SuiteManager {
|
|
20
|
-
options;
|
|
21
|
-
state = EMPTY_STATE;
|
|
22
|
-
mutationQueue = Promise.resolve();
|
|
23
|
-
statePath;
|
|
24
|
-
/** Cached `git rev-parse HEAD` per source id, so overview reads stay instant; cleared whenever a checkout may have moved. */
|
|
25
|
-
headCache = new Map();
|
|
26
|
-
/** Latest MCP mount diagnostics (suiteId -> reasons), fed by the host reconcile. */
|
|
27
|
-
mcpDiagnostics = [];
|
|
28
|
-
toolSnapshotProvider = () => [];
|
|
29
|
-
constructor(options) {
|
|
30
|
-
this.options = options;
|
|
31
|
-
this.statePath = join(options.userRoot, STATE_FILE_NAME);
|
|
32
|
-
}
|
|
33
|
-
/** Install the host tool snapshot provider used by the MCP status surface. */
|
|
34
|
-
setMcpToolSnapshotProvider(provider) {
|
|
35
|
-
this.toolSnapshotProvider = provider;
|
|
36
|
-
}
|
|
37
|
-
/** Build the flat MCP service inventory for the status surface. */
|
|
38
|
-
async mcpStatus() {
|
|
39
|
-
const suites = await this.discoverDimension('user', this.options.userRoot);
|
|
40
|
-
return buildMcpStatus(suites, this.mcpDiagnostics, this.toolSnapshotProvider());
|
|
41
|
-
}
|
|
42
|
-
/** Load persisted state once at plugin activation. */
|
|
43
|
-
async load() {
|
|
44
|
-
this.state = await loadState(this.statePath);
|
|
45
|
-
}
|
|
46
|
-
get sources() {
|
|
47
|
-
return this.state.sources;
|
|
48
|
-
}
|
|
49
|
-
/** The user-dimension suite root this manager operates. */
|
|
50
|
-
get userRoot() {
|
|
51
|
-
return this.options.userRoot;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* One suite's full detail for the market detail modal: manifest fields,
|
|
55
|
-
* skill metadata, validated mcp.json servers, and per-surface file lists.
|
|
56
|
-
*/
|
|
57
|
-
async suiteDetail(sourceId, suiteId) {
|
|
58
|
-
const suites = await this.discoverDimension('user', this.options.userRoot);
|
|
59
|
-
const suite = suites.find(entry => entry.sourceId === sourceId && entry.id === suiteId);
|
|
60
|
-
if (suite === undefined)
|
|
61
|
-
throw new Error(`suite "${suiteId}" not found in source "${sourceId}"`);
|
|
62
|
-
const installed = this.state.installed[installKey(sourceId, suiteId)];
|
|
63
|
-
const remoteUrl = suite.remote?.url;
|
|
64
|
-
return {
|
|
65
|
-
sourceId,
|
|
66
|
-
suiteId: suite.id,
|
|
67
|
-
name: suite.manifest.name,
|
|
68
|
-
version: suite.manifest.version ?? null,
|
|
69
|
-
description: suite.manifest.description ?? null,
|
|
70
|
-
author: suite.manifest.author ?? null,
|
|
71
|
-
keywords: suite.manifest.keywords ?? [],
|
|
72
|
-
layout: suite.manifest.layout,
|
|
73
|
-
dimension: suite.dimension,
|
|
74
|
-
root: remoteUrl ?? suite.root,
|
|
75
|
-
remoteUrl: remoteUrl ?? null,
|
|
76
|
-
installed: installed !== undefined,
|
|
77
|
-
enabled: installed?.enabled === true,
|
|
78
|
-
skills: suite.skills.map(skill => ({
|
|
79
|
-
name: skill.name,
|
|
80
|
-
description: skill.description,
|
|
81
|
-
...skill.whenToUse === undefined ? {} : { whenToUse: skill.whenToUse },
|
|
82
|
-
path: skill.file,
|
|
83
|
-
})),
|
|
84
|
-
mcpServers: suite.mcp === undefined ? [] : Object.entries(suite.mcp.servers).map(([key, server]) => ({ key, ...server })),
|
|
85
|
-
hooks: remoteUrl === undefined ? await this.hooksPreviews(suite.root) : { count: 0, entries: [] },
|
|
86
|
-
commands: remoteUrl === undefined ? await this.commandPreviews(`${suite.root}/commands`) : [],
|
|
87
|
-
agents: remoteUrl === undefined ? await this.agentPreviews(`${suite.root}/agents`) : [],
|
|
88
|
-
lsp: remoteUrl === undefined ? await this.lspPreviews(suite.root) : [],
|
|
89
|
-
errors: suite.errors,
|
|
90
|
-
mcpErrors: this.mcpDiagnostics.filter(diagnostic => diagnostic.suiteId === suite.id).map(diagnostic => `${diagnostic.serverKey}: ${diagnostic.reason}`),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
async readPreview(path, capBytes = 64 * 1024) {
|
|
94
|
-
const text = await readFile(path, 'utf8');
|
|
95
|
-
return text.length > capBytes ? `${text.slice(0, capBytes)}\n… (truncated)` : text;
|
|
96
|
-
}
|
|
97
|
-
/** One skill's full SKILL.md text for the market detail modal. */
|
|
98
|
-
async skillContent(sourceId, suiteId, skillName) {
|
|
99
|
-
const suites = await this.discoverDimension('user', this.options.userRoot);
|
|
100
|
-
const suite = suites.find(entry => entry.sourceId === sourceId && entry.id === suiteId);
|
|
101
|
-
if (suite === undefined)
|
|
102
|
-
throw new Error(`suite "${suiteId}" not found in source "${sourceId}"`);
|
|
103
|
-
const skill = suite.skills.find(entry => entry.name === skillName);
|
|
104
|
-
if (skill === undefined)
|
|
105
|
-
throw new Error(`skill "${skillName}" not found in suite "${suiteId}"`);
|
|
106
|
-
let content;
|
|
107
|
-
try {
|
|
108
|
-
content = await readFile(skill.file, 'utf8');
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
throw new Error(`skill file unreadable: ${error instanceof Error ? error.message : String(error)}`);
|
|
112
|
-
}
|
|
113
|
-
return { name: skill.name, description: skill.description, content, path: skill.file };
|
|
114
|
-
}
|
|
115
|
-
/** The full market overview: fresh discovery merged with install entries. */
|
|
116
|
-
async overview() {
|
|
117
|
-
const suites = await this.discoverDimension('user', this.options.userRoot);
|
|
118
|
-
const sourceRows = [];
|
|
119
|
-
for (const source of this.state.sources) {
|
|
120
|
-
const inFlight = this.currentSourceState?.sourceId === source.id ? this.currentSourceState : undefined;
|
|
121
|
-
const checkout = this.sourceCheckoutPath(source);
|
|
122
|
-
let cloned = false;
|
|
123
|
-
let lockCommit;
|
|
124
|
-
let error;
|
|
125
|
-
if (source.local === true) {
|
|
126
|
-
cloned = await isDirectory(checkout);
|
|
127
|
-
if (!cloned)
|
|
128
|
-
error = `local source directory ${checkout} is missing`;
|
|
129
|
-
}
|
|
130
|
-
else if (inFlight !== undefined) {
|
|
131
|
-
// A mutation owns this source right now (clone/pull in progress): report
|
|
132
|
-
// its snapshot instead of racing git against the transient directory.
|
|
133
|
-
cloned = inFlight.cloned || await isDirectory(checkout);
|
|
134
|
-
lockCommit = inFlight.head;
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
const cachedHead = this.headCache.get(source.id);
|
|
138
|
-
if (cachedHead !== undefined && await isDirectory(checkout)) {
|
|
139
|
-
cloned = true;
|
|
140
|
-
lockCommit = cachedHead;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
try {
|
|
144
|
-
lockCommit = await gitHead(checkout);
|
|
145
|
-
cloned = true;
|
|
146
|
-
this.headCache.set(source.id, lockCommit);
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
// not cloned yet (or a broken checkout); the clone attempt records its own error on refresh
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const sourceSuites = suites.filter(suite => suite.sourceId === source.id);
|
|
154
|
-
sourceRows.push({
|
|
155
|
-
id: source.id,
|
|
156
|
-
url: source.url,
|
|
157
|
-
...source.branch === undefined ? {} : { branch: source.branch },
|
|
158
|
-
...source.local === true ? { local: true } : {},
|
|
159
|
-
cloned,
|
|
160
|
-
...lockCommit === undefined ? {} : { lockCommit },
|
|
161
|
-
...error === undefined ? {} : { error },
|
|
162
|
-
suiteIds: sourceSuites.map(suite => suite.id),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
const installed = new Set(Object.keys(this.state.installed));
|
|
166
|
-
const cards = suites.map(suite => ({
|
|
167
|
-
sourceId: suite.sourceId,
|
|
168
|
-
suiteId: suite.id,
|
|
169
|
-
name: suite.manifest.name,
|
|
170
|
-
version: suite.manifest.version,
|
|
171
|
-
description: suite.manifest.description,
|
|
172
|
-
keywords: suite.manifest.keywords ?? [],
|
|
173
|
-
surfaces: suite.surfaces,
|
|
174
|
-
enabled: suite.enabled,
|
|
175
|
-
installed: installed.has(installKey(suite.sourceId, suite.id)),
|
|
176
|
-
dimension: suite.dimension,
|
|
177
|
-
layout: suite.manifest.layout,
|
|
178
|
-
errors: suite.errors,
|
|
179
|
-
mcpErrors: this.mcpDiagnostics.filter(diagnostic => diagnostic.suiteId === suite.id).map(diagnostic => `${diagnostic.serverKey}: ${diagnostic.reason}`),
|
|
180
|
-
}));
|
|
181
|
-
return {
|
|
182
|
-
sources: sourceRows,
|
|
183
|
-
suites: cards,
|
|
184
|
-
totals: {
|
|
185
|
-
all: cards.length,
|
|
186
|
-
installed: cards.filter(card => card.installed).length,
|
|
187
|
-
enabled: cards.filter(card => card.enabled).length,
|
|
188
|
-
},
|
|
189
|
-
roots: { user: this.options.userRoot, data: this.options.dataRoot },
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/** Enabled user-dimension suites (the MCP mount input). */
|
|
193
|
-
async enabledUserSuites() {
|
|
194
|
-
const suites = await this.discoverDimension('user', this.options.userRoot);
|
|
195
|
-
return suites.filter(suite => suite.enabled);
|
|
196
|
-
}
|
|
197
|
-
/** Enabled user- and project-dimension suites for a workspace cwd. */
|
|
198
|
-
async enabledSuitesForCwd(cwd) {
|
|
199
|
-
const user = await this.enabledUserSuites();
|
|
200
|
-
const project = (await this.discoverDimension('project', await resolveProjectRoot(cwd))).filter(suite => suite.enabled);
|
|
201
|
-
return { user, project };
|
|
202
|
-
}
|
|
203
|
-
/** All suites (any enabled state) of one dimension. */
|
|
204
|
-
async suitesForDimension(dimension, dimensionRoot) {
|
|
205
|
-
return this.discoverDimension(dimension, dimensionRoot);
|
|
206
|
-
}
|
|
207
|
-
// ---- mutations ----
|
|
208
|
-
/**
|
|
209
|
-
* Add a source and clone it immediately. The id is derived from the suite
|
|
210
|
-
* repository's own JSON (marketplace plugin entry name first, then the
|
|
211
|
-
* root manifest name, then the repo basename), sanitized; collisions get a
|
|
212
|
-
* numeric suffix.
|
|
213
|
-
*/
|
|
214
|
-
async addSource(input) {
|
|
215
|
-
return this.enqueue(async () => {
|
|
216
|
-
const baseId = this.uniqueSourceId(deriveSourceId(input.url));
|
|
217
|
-
const source = {
|
|
218
|
-
id: baseId,
|
|
219
|
-
url: input.url,
|
|
220
|
-
...input.branch === undefined ? {} : { branch: input.branch },
|
|
221
|
-
...input.local === true ? { local: true } : {},
|
|
222
|
-
};
|
|
223
|
-
const checkout = this.sourceCheckoutPath(source);
|
|
224
|
-
if (input.local === true) {
|
|
225
|
-
if (!await isDirectory(checkout))
|
|
226
|
-
throw new Error(`local source directory ${checkout} is missing`);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
this.beginSourceState(baseId, 'cloning', false);
|
|
230
|
-
try {
|
|
231
|
-
await this.ensureClone(source);
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
this.endSourceState();
|
|
235
|
-
throw error;
|
|
236
|
-
}
|
|
237
|
-
this.updateSourceStep('reading');
|
|
238
|
-
}
|
|
239
|
-
source.id = this.uniqueSourceId(sanitizeId(await repoName(checkout)));
|
|
240
|
-
const head = await tryHead(checkout);
|
|
241
|
-
if (head !== undefined)
|
|
242
|
-
this.headCache.set(source.id, head);
|
|
243
|
-
this.endSourceState();
|
|
244
|
-
this.state = { ...this.state, sources: [...this.state.sources, source] };
|
|
245
|
-
await saveState(this.statePath, this.state);
|
|
246
|
-
this.options.onChanged();
|
|
247
|
-
return source;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Progress snapshot of the source mutation currently in flight, if any.
|
|
252
|
-
* While present, `overview()` reports it instead of running git against
|
|
253
|
-
* the transient checkout directory.
|
|
254
|
-
*/
|
|
255
|
-
currentSourceState;
|
|
256
|
-
/**
|
|
257
|
-
* Begin reporting progress for a source mutation: `step` names the active
|
|
258
|
-
* phase and `cloned` whether the checkout directory exists yet. The client
|
|
259
|
-
* polls this through the `progress` route while its add-source modal is
|
|
260
|
-
* open, and `overview()` merges the snapshot into the source row.
|
|
261
|
-
*/
|
|
262
|
-
beginSourceState(sourceId, step, cloned) {
|
|
263
|
-
this.currentSourceState = { sourceId, step, cloned };
|
|
264
|
-
}
|
|
265
|
-
/** Advance the in-flight mutation's step (checkout state unchanged). */
|
|
266
|
-
updateSourceStep(step) {
|
|
267
|
-
if (this.currentSourceState !== undefined) {
|
|
268
|
-
this.currentSourceState = { ...this.currentSourceState, step };
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
/** Stop reporting progress; `overview()` falls back to on-disk inspection. */
|
|
272
|
-
endSourceState() {
|
|
273
|
-
this.currentSourceState = undefined;
|
|
274
|
-
}
|
|
275
|
-
/** Progress snapshot for the `progress` route (never throws). */
|
|
276
|
-
sourceProgress() {
|
|
277
|
-
const state = this.currentSourceState;
|
|
278
|
-
return state === undefined
|
|
279
|
-
? { active: false, sourceId: '', step: '' }
|
|
280
|
-
: { active: true, sourceId: state.sourceId, step: state.step };
|
|
281
|
-
}
|
|
282
|
-
uniqueSourceId(derived) {
|
|
283
|
-
if (!this.state.sources.some(source => source.id === derived))
|
|
284
|
-
return derived;
|
|
285
|
-
for (let suffix = 2;; suffix++) {
|
|
286
|
-
const candidate = `${derived}-${suffix}`;
|
|
287
|
-
if (!this.state.sources.some(source => source.id === candidate))
|
|
288
|
-
return candidate;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Update one source's url / branch / local flag. A git source whose URL
|
|
293
|
-
* changes drops its stale checkout (the next refresh clones the new URL);
|
|
294
|
-
* a local source's directory is never touched.
|
|
295
|
-
*/
|
|
296
|
-
async updateSource(sourceId, patch) {
|
|
297
|
-
return this.enqueue(async () => {
|
|
298
|
-
const index = this.state.sources.findIndex(source => source.id === sourceId);
|
|
299
|
-
if (index === -1)
|
|
300
|
-
throw new Error(`unknown source "${sourceId}"`);
|
|
301
|
-
const current = this.state.sources[index];
|
|
302
|
-
const next = {
|
|
303
|
-
id: sourceId,
|
|
304
|
-
url: patch.url ?? current.url,
|
|
305
|
-
...(patch.branch !== undefined ? { branch: patch.branch } : current.branch === undefined ? {} : { branch: current.branch }),
|
|
306
|
-
...(patch.local !== undefined ? { local: patch.local } : current.local === undefined ? {} : { local: current.local }),
|
|
307
|
-
};
|
|
308
|
-
if (current.local !== true && patch.url !== undefined && patch.url !== current.url) {
|
|
309
|
-
this.headCache.delete(sourceId);
|
|
310
|
-
await gitRemove(sourceCheckoutDir(this.options.userRoot, sourceId));
|
|
311
|
-
}
|
|
312
|
-
this.state = { ...this.state, sources: this.state.sources.map((source, i) => i === index ? next : source) };
|
|
313
|
-
await saveState(this.statePath, this.state);
|
|
314
|
-
this.options.onChanged();
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
/** Remove a source: delete its checkout, forget its suites and install entries. */
|
|
318
|
-
async removeSource(sourceId) {
|
|
319
|
-
return this.enqueue(async () => {
|
|
320
|
-
this.state = {
|
|
321
|
-
...this.state,
|
|
322
|
-
sources: this.state.sources.filter(source => source.id !== sourceId),
|
|
323
|
-
installed: Object.fromEntries(Object.entries(this.state.installed).filter(([key]) => !key.startsWith(`${sourceId}/`))),
|
|
324
|
-
};
|
|
325
|
-
await saveState(this.statePath, this.state);
|
|
326
|
-
const source = this.state.sources.find(entry => entry.id === sourceId);
|
|
327
|
-
this.headCache.delete(sourceId);
|
|
328
|
-
if (source === undefined || source.local !== true) {
|
|
329
|
-
await gitRemove(sourceCheckoutDir(this.options.userRoot, sourceId));
|
|
330
|
-
}
|
|
331
|
-
this.options.onChanged();
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
/** Refresh one source checkout (pull), or every source when `sourceId` is omitted. */
|
|
335
|
-
async refreshSource(sourceId) {
|
|
336
|
-
return this.enqueue(async () => {
|
|
337
|
-
const targets = sourceId === undefined ? this.state.sources : this.state.sources.filter(source => source.id === sourceId);
|
|
338
|
-
for (const source of targets) {
|
|
339
|
-
if (source.local === true) {
|
|
340
|
-
if (!await isDirectory(expandHome(source.url))) {
|
|
341
|
-
throw new Error(`local source directory ${expandHome(source.url)} is missing`);
|
|
342
|
-
}
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
const checkout = sourceCheckoutDir(this.options.userRoot, source.id);
|
|
346
|
-
this.headCache.delete(source.id);
|
|
347
|
-
try {
|
|
348
|
-
await gitHead(checkout);
|
|
349
|
-
}
|
|
350
|
-
catch {
|
|
351
|
-
await this.ensureClone(source);
|
|
352
|
-
try {
|
|
353
|
-
this.headCache.set(source.id, await gitHead(checkout));
|
|
354
|
-
}
|
|
355
|
-
catch {
|
|
356
|
-
// a failed head read simply means the next overview re-probes
|
|
357
|
-
}
|
|
358
|
-
continue;
|
|
359
|
-
}
|
|
360
|
-
await gitPull(checkout);
|
|
361
|
-
try {
|
|
362
|
-
this.headCache.set(source.id, await gitHead(checkout));
|
|
363
|
-
}
|
|
364
|
-
catch {
|
|
365
|
-
// a failed head read simply means the next overview re-probes
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
this.options.onChanged();
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
/** Install a suite: the source must be cloned; the suite dir becomes an enabled install entry. */
|
|
372
|
-
async install(sourceId, suiteId) {
|
|
373
|
-
return this.enqueue(async () => {
|
|
374
|
-
const source = this.state.sources.find(entry => entry.id === sourceId);
|
|
375
|
-
if (source === undefined)
|
|
376
|
-
throw new Error(`unknown source "${sourceId}"`);
|
|
377
|
-
const checkout = this.sourceCheckoutPath(source);
|
|
378
|
-
if (!await isDirectory(checkout))
|
|
379
|
-
await this.ensureClone(source);
|
|
380
|
-
const suites = await discoverSuitesInSource(checkout, sourceId, 'user');
|
|
381
|
-
const suite = suites.find(entry => entry.id === suiteId);
|
|
382
|
-
if (suite === undefined)
|
|
383
|
-
throw new Error(`suite "${suiteId}" not found in source "${sourceId}"`);
|
|
384
|
-
if (suite.remote !== undefined)
|
|
385
|
-
throw new Error(`suite "${suiteId}" is a remote reference (${suite.remote.url}); add its repository as a source before installing`);
|
|
386
|
-
await this.setInstalled(sourceId, suiteId, { enabled: true, installedAt: new Date().toISOString(), lockCommit: await tryHead(checkout) });
|
|
387
|
-
this.options.onChanged();
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
/** Uninstall a suite: drop the install entry (the source clone stays for browsing). */
|
|
391
|
-
async uninstall(sourceId, suiteId) {
|
|
392
|
-
return this.enqueue(async () => {
|
|
393
|
-
const key = installKey(sourceId, suiteId);
|
|
394
|
-
if (this.state.installed[key] === undefined)
|
|
395
|
-
throw new Error(`suite "${suiteId}" is not installed`);
|
|
396
|
-
const { [key]: _removed, ...rest } = this.state.installed;
|
|
397
|
-
this.state = { ...this.state, installed: rest };
|
|
398
|
-
await saveState(this.statePath, this.state);
|
|
399
|
-
this.options.onChanged();
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
/** Enable or disable an installed suite. */
|
|
403
|
-
async setEnabled(sourceId, suiteId, enabled) {
|
|
404
|
-
return this.enqueue(async () => {
|
|
405
|
-
const key = installKey(sourceId, suiteId);
|
|
406
|
-
const entry = this.state.installed[key];
|
|
407
|
-
if (entry === undefined)
|
|
408
|
-
throw new Error(`suite "${suiteId}" is not installed`);
|
|
409
|
-
await this.setInstalled(sourceId, suiteId, { ...entry, enabled });
|
|
410
|
-
this.options.onChanged();
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
/** Append config-seeded sources missing from state and persist; clones lazily on first refresh/install. */
|
|
414
|
-
async mergeSources(sources) {
|
|
415
|
-
const existing = new Set(this.state.sources.map(source => source.id));
|
|
416
|
-
const additions = sources.filter(source => !existing.has(source.id));
|
|
417
|
-
if (additions.length === 0)
|
|
418
|
-
return;
|
|
419
|
-
this.state = { ...this.state, sources: [...this.state.sources, ...additions] };
|
|
420
|
-
await saveState(this.statePath, this.state);
|
|
421
|
-
}
|
|
422
|
-
async setInstalled(sourceId, suiteId, entry) {
|
|
423
|
-
this.state = { ...this.state, installed: { ...this.state.installed, [installKey(sourceId, suiteId)]: entry } };
|
|
424
|
-
await saveState(this.statePath, this.state);
|
|
425
|
-
}
|
|
426
|
-
async ensureClone(source) {
|
|
427
|
-
if (source.local === true) {
|
|
428
|
-
if (!await isDirectory(expandHome(source.url))) {
|
|
429
|
-
throw new Error(`local source directory ${expandHome(source.url)} is missing`);
|
|
430
|
-
}
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
const checkout = sourceCheckoutDir(this.options.userRoot, source.id);
|
|
434
|
-
await mkdir(sourcesDir(this.options.userRoot), { recursive: true });
|
|
435
|
-
await gitClone(source.url, source.branch, checkout);
|
|
436
|
-
}
|
|
437
|
-
/** The filesystem location one source is read from. */
|
|
438
|
-
sourceCheckoutPath(source) {
|
|
439
|
-
return source.local === true ? expandHome(source.url) : sourceCheckoutDir(this.options.userRoot, source.id);
|
|
440
|
-
}
|
|
441
|
-
async discoverDimension(dimension, dimensionRoot) {
|
|
442
|
-
const discovered = await discoverSourceList(this.state.sources, dimension, dimensionRoot);
|
|
443
|
-
const suites = [];
|
|
444
|
-
for (const suite of discovered) {
|
|
445
|
-
const installed = this.state.installed[installKey(suite.sourceId, suite.id)];
|
|
446
|
-
suites.push({
|
|
447
|
-
...suite,
|
|
448
|
-
enabled: dimension === 'user' && installed?.enabled === true,
|
|
449
|
-
...installed?.lockCommit === undefined ? {} : { lockCommit: installed.lockCommit },
|
|
450
|
-
...installed?.installedAt === undefined ? {} : { installedAt: installed.installedAt },
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
return suites;
|
|
454
|
-
}
|
|
455
|
-
async commandPreviews(dir) {
|
|
456
|
-
const names = await listMdFiles(dir);
|
|
457
|
-
const previews = [];
|
|
458
|
-
for (const name of names) {
|
|
459
|
-
const file = `${dir}/${name}`;
|
|
460
|
-
try {
|
|
461
|
-
const content = await this.readPreview(file);
|
|
462
|
-
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(content);
|
|
463
|
-
let description;
|
|
464
|
-
if (match !== null) {
|
|
465
|
-
const yaml = (await import('yaml')).parse(match[1]);
|
|
466
|
-
if (typeof yaml === 'object' && yaml !== null) {
|
|
467
|
-
const desc = yaml['description'];
|
|
468
|
-
if (typeof desc === 'string')
|
|
469
|
-
description = desc;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
previews.push({ name: name.slice(0, -3), ...description === undefined ? {} : { description }, content });
|
|
473
|
-
}
|
|
474
|
-
catch {
|
|
475
|
-
// unreadable command files are skipped in previews
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return previews;
|
|
479
|
-
}
|
|
480
|
-
async agentPreviews(dir) {
|
|
481
|
-
const names = await listMdFiles(dir);
|
|
482
|
-
const previews = [];
|
|
483
|
-
for (const name of names) {
|
|
484
|
-
const file = `${dir}/${name}`;
|
|
485
|
-
try {
|
|
486
|
-
const content = await this.readPreview(file);
|
|
487
|
-
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(content);
|
|
488
|
-
let description;
|
|
489
|
-
if (match !== null) {
|
|
490
|
-
const yaml = (await import('yaml')).parse(match[1]);
|
|
491
|
-
if (typeof yaml === 'object' && yaml !== null) {
|
|
492
|
-
const desc = yaml['description'];
|
|
493
|
-
if (typeof desc === 'string')
|
|
494
|
-
description = desc;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
previews.push({ name: name.slice(0, -3), ...description === undefined ? {} : { description }, content });
|
|
498
|
-
}
|
|
499
|
-
catch {
|
|
500
|
-
// unreadable agent files are skipped in previews
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return previews;
|
|
504
|
-
}
|
|
505
|
-
/** Parse CC hooks.json into flat {event, matcher, command} preview entries. */
|
|
506
|
-
async hooksPreviews(root) {
|
|
507
|
-
for (const relative of ['hooks/hooks.json', 'hooks.json']) {
|
|
508
|
-
let text;
|
|
509
|
-
try {
|
|
510
|
-
text = await readFile(`${root}/${relative}`, 'utf8');
|
|
511
|
-
}
|
|
512
|
-
catch {
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
try {
|
|
516
|
-
const parsed = JSON.parse(text);
|
|
517
|
-
if (typeof parsed !== 'object' || parsed === null)
|
|
518
|
-
continue;
|
|
519
|
-
const hooks = parsed['hooks'];
|
|
520
|
-
if (typeof hooks !== 'object' || hooks === null)
|
|
521
|
-
continue;
|
|
522
|
-
const entries = [];
|
|
523
|
-
for (const [event, groups] of Object.entries(hooks)) {
|
|
524
|
-
if (!Array.isArray(groups))
|
|
525
|
-
continue;
|
|
526
|
-
for (const group of groups) {
|
|
527
|
-
if (typeof group !== 'object' || group === null)
|
|
528
|
-
continue;
|
|
529
|
-
const record = group;
|
|
530
|
-
const matcher = typeof record['matcher'] === 'string' ? record['matcher'] : undefined;
|
|
531
|
-
const hooksList = record['hooks'];
|
|
532
|
-
if (Array.isArray(hooksList)) {
|
|
533
|
-
for (const hook of hooksList) {
|
|
534
|
-
if (typeof hook !== 'object' || hook === null)
|
|
535
|
-
continue;
|
|
536
|
-
const hookRecord = hook;
|
|
537
|
-
if (typeof hookRecord['command'] === 'string') {
|
|
538
|
-
entries.push({ event, ...matcher === undefined ? {} : { matcher }, command: hookRecord['command'] });
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
return { count: entries.length, entries };
|
|
545
|
-
}
|
|
546
|
-
catch {
|
|
547
|
-
// unparsable hook files yield zero entries
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return { count: 0, entries: [] };
|
|
551
|
-
}
|
|
552
|
-
async lspPreviews(root) {
|
|
553
|
-
const previews = [];
|
|
554
|
-
for (const entry of await discoverLspEntries(root)) {
|
|
555
|
-
try {
|
|
556
|
-
previews.push({ name: entry.name, content: await this.readPreview(entry.path) });
|
|
557
|
-
}
|
|
558
|
-
catch {
|
|
559
|
-
// unreadable LSP files are skipped in previews
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return previews;
|
|
563
|
-
}
|
|
564
|
-
enqueue(operation) {
|
|
565
|
-
const result = this.mutationQueue.then(operation, operation);
|
|
566
|
-
this.mutationQueue = result.catch(() => { });
|
|
567
|
-
return result;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
function installKey(sourceId, suiteId) {
|
|
571
|
-
return `${sourceId}/${suiteId}`;
|
|
572
|
-
}
|
|
573
|
-
/** Read a checkout's HEAD when it is a git repository; other checkouts have no lock commit. */
|
|
574
|
-
async function tryHead(dir) {
|
|
575
|
-
try {
|
|
576
|
-
return await gitHead(dir);
|
|
577
|
-
}
|
|
578
|
-
catch {
|
|
579
|
-
return undefined;
|
|
580
|
-
}
|
|
581
|
-
}
|
package/lib/types/discovery.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { SourceRef, Suite, SuiteDimension } from './types.js';
|
|
2
|
-
import { repoName } from './discovery/manifests.js';
|
|
3
|
-
import { discoverLspEntries, listMdFiles, type LspEntry } from './discovery/surfaces.js';
|
|
4
|
-
export { repoName, listMdFiles, discoverLspEntries };
|
|
5
|
-
export type { LspEntry };
|
|
6
|
-
/** Discover every suite under one cloned source checkout. */
|
|
7
|
-
export declare function discoverSuitesInSource(checkoutDir: string, sourceId: string, dimension: SuiteDimension): Promise<Suite[]>;
|
|
8
|
-
/** Whether a suite root path lies outside the checkout (defense for malformed marketplace sources). */
|
|
9
|
-
export declare function isOutside(root: string, candidate: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Discover suites for one dimension. User catalogs only read configured
|
|
12
|
-
* sources: unmanaged user checkouts have no persisted identity and otherwise
|
|
13
|
-
* leak stale repositories into the catalog totals. Project catalogs retain
|
|
14
|
-
* unmanaged checkout ids because project state may authorize them through its
|
|
15
|
-
* installed map without duplicating source configuration. All selected
|
|
16
|
-
* checkouts are discovered concurrently so one large repository does not
|
|
17
|
-
* serialize every other repository's scan.
|
|
18
|
-
*/
|
|
19
|
-
export declare function discoverSourceList(sources: SourceRef[], dimension: SuiteDimension, dimensionRoot: string): Promise<Suite[]>;
|