@dsh-cc/plugin-manager 0.6.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/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +32 -0
- package/README.zh.md +32 -0
- package/lib/errors.d.ts +51 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +94 -0
- package/lib/errors.js.map +1 -0
- package/lib/git.d.ts +38 -0
- package/lib/git.d.ts.map +1 -0
- package/lib/git.js +38 -0
- package/lib/git.js.map +1 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +94 -0
- package/lib/index.js.map +1 -0
- package/lib/install.d.ts +67 -0
- package/lib/install.d.ts.map +1 -0
- package/lib/install.js +192 -0
- package/lib/install.js.map +1 -0
- package/lib/list.d.ts +35 -0
- package/lib/list.d.ts.map +1 -0
- package/lib/list.js +98 -0
- package/lib/list.js.map +1 -0
- package/lib/marketplace.d.ts +89 -0
- package/lib/marketplace.d.ts.map +1 -0
- package/lib/marketplace.js +426 -0
- package/lib/marketplace.js.map +1 -0
- package/lib/merged-state.d.ts +54 -0
- package/lib/merged-state.d.ts.map +1 -0
- package/lib/merged-state.js +88 -0
- package/lib/merged-state.js.map +1 -0
- package/lib/paths.d.ts +75 -0
- package/lib/paths.d.ts.map +1 -0
- package/lib/paths.js +173 -0
- package/lib/paths.js.map +1 -0
- package/lib/resolve-id.d.ts +43 -0
- package/lib/resolve-id.d.ts.map +1 -0
- package/lib/resolve-id.js +110 -0
- package/lib/resolve-id.js.map +1 -0
- package/lib/settings-write.d.ts +16 -0
- package/lib/settings-write.d.ts.map +1 -0
- package/lib/settings-write.js +32 -0
- package/lib/settings-write.js.map +1 -0
- package/lib/state-store.d.ts +24 -0
- package/lib/state-store.d.ts.map +1 -0
- package/lib/state-store.js +54 -0
- package/lib/state-store.js.map +1 -0
- package/lib/toggles.d.ts +30 -0
- package/lib/toggles.d.ts.map +1 -0
- package/lib/toggles.js +62 -0
- package/lib/toggles.js.map +1 -0
- package/lib/types.d.ts +57 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +9 -0
- package/lib/types.js.map +1 -0
- package/lib/uninstall.d.ts +30 -0
- package/lib/uninstall.d.ts.map +1 -0
- package/lib/uninstall.js +78 -0
- package/lib/uninstall.js.map +1 -0
- package/lib/update.d.ts +34 -0
- package/lib/update.d.ts.map +1 -0
- package/lib/update.js +67 -0
- package/lib/update.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marketplace read/write operations (plan §2.2 C1/C6/C8): list, add
|
|
3
|
+
* (directory / `owner/repo` shorthand / git URL), update, remove — all in
|
|
4
|
+
* the byte shapes the real CLI v2.1.236 writes. Clones go through the
|
|
5
|
+
* injectable `GitRunner` into a tmp dir inside `marketplaces/` and are
|
|
6
|
+
* renamed into place only after the cloned manifest names the marketplace
|
|
7
|
+
* (no half-clones); failures remove the tmp dir.
|
|
8
|
+
*
|
|
9
|
+
* @module @dsh-cc/plugin-manager/marketplace
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
12
|
+
import { mkdir, readFile, rename, rm } from 'node:fs/promises';
|
|
13
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
14
|
+
import { gitFailure, createSystemGitRunner } from "./git.js";
|
|
15
|
+
import { invalidMarketplaceSource, marketplaceConflict, marketplaceManifestMissing, unknownMarketplace, unknownScope, } from "./errors.js";
|
|
16
|
+
import { canonicalizeExistingPath, claudePluginsStatePaths, pluginsStatePaths, settingsFileForScope } from "./paths.js";
|
|
17
|
+
import { loadMergedInstalledPlugins, loadMergedKnownMarketplaces } from "./merged-state.js";
|
|
18
|
+
import { parsePluginId } from "./resolve-id.js";
|
|
19
|
+
import { loadJsonFile, loadKnownMarketplaces, loadSettingsFile, saveJsonFileAtomic } from "./state-store.js";
|
|
20
|
+
import { uninstallPlugin } from "./uninstall.js";
|
|
21
|
+
import { marketplaceNameMismatch, projectScopeEnabledGuard } from "./errors.js";
|
|
22
|
+
const SCOPES = ['user', 'project', 'local'];
|
|
23
|
+
function resolveDeps(deps, opts) {
|
|
24
|
+
return {
|
|
25
|
+
now: opts?.now ?? deps.now ?? (() => new Date()),
|
|
26
|
+
runGit: opts?.runGit ?? deps.runGit ?? createSystemGitRunner(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function validateScope(scope) {
|
|
30
|
+
if (scope === undefined)
|
|
31
|
+
return 'user';
|
|
32
|
+
if (!SCOPES.includes(scope))
|
|
33
|
+
throw unknownScope(scope);
|
|
34
|
+
return scope;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Classify a source string: an existing directory (canonicalized) wins;
|
|
38
|
+
* then git URLs (`https://…`, `git@…`, trailing `.git`); then the
|
|
39
|
+
* `owner/repo` github shorthand; anything else is invalid.
|
|
40
|
+
*/
|
|
41
|
+
export function classifySource(source) {
|
|
42
|
+
if (existsSync(source) && statSync(source).isDirectory()) {
|
|
43
|
+
return { source: 'directory', path: canonicalizeExistingPath(source) };
|
|
44
|
+
}
|
|
45
|
+
if (/^https:\/\//.test(source) || /^git@/.test(source) || source.endsWith('.git')) {
|
|
46
|
+
return { source: 'git', url: source };
|
|
47
|
+
}
|
|
48
|
+
if (/^[^/\s]+\/[^/\s]+$/.test(source)) {
|
|
49
|
+
return { source: 'github', repo: source };
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function kindOf(source) {
|
|
54
|
+
return source.source;
|
|
55
|
+
}
|
|
56
|
+
/** Identity comparison for the already-registered check (same kind + same location). */
|
|
57
|
+
function sourcesEqual(a, b) {
|
|
58
|
+
if (a.source !== b.source)
|
|
59
|
+
return false;
|
|
60
|
+
if (a.source === 'directory' && b.source === 'directory')
|
|
61
|
+
return a.path === b.path;
|
|
62
|
+
if (a.source === 'github' && b.source === 'github')
|
|
63
|
+
return a.repo === b.repo;
|
|
64
|
+
if (a.source === 'git' && b.source === 'git')
|
|
65
|
+
return a.url === b.url;
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read `.claude-plugin/marketplace.json` in a marketplace dir: returns its
|
|
70
|
+
* `name` and plugin count, or throws the exact manifest error (missing /
|
|
71
|
+
* unreadable file → errno detail; missing `name` → `missing "name"`).
|
|
72
|
+
*/
|
|
73
|
+
async function readManifest(dir) {
|
|
74
|
+
let raw;
|
|
75
|
+
try {
|
|
76
|
+
raw = await readFile(join(dir, '.claude-plugin', 'marketplace.json'), 'utf8');
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw marketplaceManifestMissing(dir, error.code ?? error.message);
|
|
80
|
+
}
|
|
81
|
+
let manifest;
|
|
82
|
+
try {
|
|
83
|
+
manifest = JSON.parse(raw);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw marketplaceManifestMissing(dir, error.message);
|
|
87
|
+
}
|
|
88
|
+
if (typeof manifest['name'] !== 'string' || manifest['name'].length === 0) {
|
|
89
|
+
throw marketplaceManifestMissing(dir, 'missing "name"');
|
|
90
|
+
}
|
|
91
|
+
const plugins = Array.isArray(manifest['plugins']) ? manifest['plugins'] : [];
|
|
92
|
+
return { name: manifest['name'], pluginCount: plugins.length };
|
|
93
|
+
}
|
|
94
|
+
/** C1 `list` rows: MERGED known entries (dsh wins per name; tombstoned names absent) plus their name. */
|
|
95
|
+
export async function listMarketplaces(deps) {
|
|
96
|
+
const known = (await loadMergedKnownMarketplaces(deps)).entries;
|
|
97
|
+
return Object.entries(known).map(([name, entry]) => ({
|
|
98
|
+
name,
|
|
99
|
+
source: entry.source,
|
|
100
|
+
installLocation: entry.installLocation,
|
|
101
|
+
lastUpdated: entry.lastUpdated,
|
|
102
|
+
...(entry.autoUpdate !== undefined ? { autoUpdate: entry.autoUpdate } : {}),
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Write the known_marketplaces.json entry AND the scope settings
|
|
107
|
+
* declaration (preserving unrelated settings keys, C11), guarding against
|
|
108
|
+
* name conflicts with a different source. Same source ⇒ idempotent.
|
|
109
|
+
*
|
|
110
|
+
* Dual-home awareness (plan §4.5): the dsh known file may carry a `null`
|
|
111
|
+
* tombstone for the name — a tombstoned name counts as ABSENT for conflict
|
|
112
|
+
* detection (re-add always succeeds and clears the tombstone). When the
|
|
113
|
+
* claude file carries the same name: a same source is reused by REFERENCE
|
|
114
|
+
* (the dsh entry points at the claude entry's installLocation, no clone);
|
|
115
|
+
* a different source clones fresh and the result carries
|
|
116
|
+
* `shadowedClaudeEntry: true`. Returns whether the fresh clone is actually
|
|
117
|
+
* referenced (false ⇒ the caller drops it).
|
|
118
|
+
*/
|
|
119
|
+
async function commitAdd(deps, scope, now, info) {
|
|
120
|
+
const paths = pluginsStatePaths(deps);
|
|
121
|
+
const dshKnown = await loadKnownMarketplaces(paths.knownMarketplacesFile);
|
|
122
|
+
const claudePaths = claudePluginsStatePaths(deps);
|
|
123
|
+
const claudeKnown = claudePaths === null
|
|
124
|
+
? {}
|
|
125
|
+
: await loadJsonFile(claudePaths.knownMarketplacesFile, {});
|
|
126
|
+
const dshExisting = dshKnown[info.name];
|
|
127
|
+
const claudeExisting = claudeKnown[info.name];
|
|
128
|
+
// Conflict detection: a live dsh entry with a different source (a null
|
|
129
|
+
// tombstone is absent from the merged view, §4.5).
|
|
130
|
+
if (dshExisting != null && !sourcesEqual(dshExisting.source, info.source)) {
|
|
131
|
+
throw marketplaceConflict(info.name, kindOf(dshExisting.source));
|
|
132
|
+
}
|
|
133
|
+
const claudeEntryPresent = dshExisting == null && claudeExisting !== undefined;
|
|
134
|
+
const sameAsClaude = claudeEntryPresent && sourcesEqual(claudeExisting.source, info.source);
|
|
135
|
+
const shadowed = claudeEntryPresent && !sameAsClaude;
|
|
136
|
+
let entry;
|
|
137
|
+
let cloned = true;
|
|
138
|
+
if (sameAsClaude) {
|
|
139
|
+
// Reference, no clone (§4.5): promote-on-write handles freshness later.
|
|
140
|
+
entry = { ...claudeExisting, lastUpdated: now().toISOString() };
|
|
141
|
+
cloned = false;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
entry = {
|
|
145
|
+
source: info.source,
|
|
146
|
+
installLocation: info.installLocation,
|
|
147
|
+
lastUpdated: now().toISOString(),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
dshKnown[info.name] = entry;
|
|
151
|
+
await saveJsonFileAtomic(paths.knownMarketplacesFile, dshKnown);
|
|
152
|
+
const settingsFile = settingsFileForScope(scope, deps);
|
|
153
|
+
const settings = await loadSettingsFile(settingsFile);
|
|
154
|
+
const next = { ...settings };
|
|
155
|
+
next['extraKnownMarketplaces'] = { ...settings['extraKnownMarketplaces'], [info.name]: { source: info.source } };
|
|
156
|
+
await saveJsonFileAtomic(settingsFile, next);
|
|
157
|
+
return {
|
|
158
|
+
result: {
|
|
159
|
+
name: info.name,
|
|
160
|
+
sourceKind: info.sourceKind,
|
|
161
|
+
pluginCount: info.pluginCount,
|
|
162
|
+
...(shadowed ? { shadowedClaudeEntry: true } : {}),
|
|
163
|
+
},
|
|
164
|
+
cloned,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* `marketplace add <source>` (C1): directory sources are validated in place
|
|
169
|
+
* and never copied; github shorthand expands to
|
|
170
|
+
* `https://github.com/<owner>/<repo>.git` and git URLs are cloned as-is via
|
|
171
|
+
* the injected runner into a tmp dir, the marketplace name is read from the
|
|
172
|
+
* cloned manifest, then the clone is renamed into `marketplaces/<name>`.
|
|
173
|
+
*/
|
|
174
|
+
export async function addMarketplace(deps, source, opts = {}) {
|
|
175
|
+
const { now, runGit } = resolveDeps(deps, opts);
|
|
176
|
+
const scope = validateScope(opts.scope);
|
|
177
|
+
const paths = pluginsStatePaths(deps);
|
|
178
|
+
const classified = classifySource(source);
|
|
179
|
+
if (classified === null)
|
|
180
|
+
throw invalidMarketplaceSource(source);
|
|
181
|
+
// Idempotent re-add of the exact same source against the MERGED known map
|
|
182
|
+
// (§4.5): an entry in either home ⇒ idempotent success, no clone. A dsh
|
|
183
|
+
// tombstoned name is absent from the merged view and never matches here.
|
|
184
|
+
const mergedKnown = (await loadMergedKnownMarketplaces(deps)).entries;
|
|
185
|
+
for (const [name, entry] of Object.entries(mergedKnown)) {
|
|
186
|
+
if (sourcesEqual(entry.source, classified)) {
|
|
187
|
+
return {
|
|
188
|
+
name,
|
|
189
|
+
sourceKind: kindOf(entry.source),
|
|
190
|
+
pluginCount: manifestPluginCount(entry.installLocation),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (classified.source === 'directory') {
|
|
195
|
+
const manifest = await readManifest(classified.path);
|
|
196
|
+
const committed = await commitAdd(deps, scope, now, {
|
|
197
|
+
name: manifest.name,
|
|
198
|
+
source: classified,
|
|
199
|
+
installLocation: classified.path,
|
|
200
|
+
sourceKind: 'directory',
|
|
201
|
+
pluginCount: manifest.pluginCount,
|
|
202
|
+
});
|
|
203
|
+
return committed.result;
|
|
204
|
+
}
|
|
205
|
+
const url = classified.source === 'github' ? `https://github.com/${classified.repo}.git` : classified.url;
|
|
206
|
+
const candidate = (classified.source === 'github' ? basename(classified.repo) : basename(url).replace(/\.git$/, ''))
|
|
207
|
+
.replace(/[^\w.-]/g, '-') || 'marketplace';
|
|
208
|
+
// §4.5 reference fast path: a claude entry for the candidate name with the
|
|
209
|
+
// SAME source is reused by reference without cloning (the tombstone case —
|
|
210
|
+
// the merged-view loop above already returned for live entries). The
|
|
211
|
+
// commit-time reference check remains the authority when the manifest name
|
|
212
|
+
// differs from the candidate.
|
|
213
|
+
const claudePaths = claudePluginsStatePaths(deps);
|
|
214
|
+
if (claudePaths !== null) {
|
|
215
|
+
const claudeKnown = await loadJsonFile(claudePaths.knownMarketplacesFile, {});
|
|
216
|
+
const claudeEntry = claudeKnown[candidate];
|
|
217
|
+
if (claudeEntry !== undefined && sourcesEqual(claudeEntry.source, classified)) {
|
|
218
|
+
const committed = await commitAdd(deps, scope, now, {
|
|
219
|
+
name: candidate,
|
|
220
|
+
source: classified,
|
|
221
|
+
installLocation: claudeEntry.installLocation,
|
|
222
|
+
sourceKind: kindOf(classified),
|
|
223
|
+
pluginCount: manifestPluginCount(claudeEntry.installLocation),
|
|
224
|
+
});
|
|
225
|
+
return committed.result;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
await mkdir(paths.marketplacesDir, { recursive: true });
|
|
229
|
+
const tmpDir = join(paths.marketplacesDir, `.tmp-clone-${candidate}-${process.pid}`);
|
|
230
|
+
let clonedTo = null;
|
|
231
|
+
try {
|
|
232
|
+
const result = await runGit(['clone', url, tmpDir], { cwd: paths.marketplacesDir });
|
|
233
|
+
if (result.code !== 0)
|
|
234
|
+
throw gitFailure('clone', url, result);
|
|
235
|
+
const manifest = await readManifest(tmpDir);
|
|
236
|
+
const dest = join(paths.marketplacesDir, manifest.name);
|
|
237
|
+
await rename(tmpDir, dest);
|
|
238
|
+
clonedTo = dest;
|
|
239
|
+
const committed = await commitAdd(deps, scope, now, {
|
|
240
|
+
name: manifest.name,
|
|
241
|
+
source: classified,
|
|
242
|
+
installLocation: dest,
|
|
243
|
+
sourceKind: classified.source,
|
|
244
|
+
pluginCount: manifest.pluginCount,
|
|
245
|
+
});
|
|
246
|
+
if (!committed.cloned && clonedTo !== null) {
|
|
247
|
+
// The dsh entry references the claude entry's clone — drop ours (§4.5).
|
|
248
|
+
await rm(clonedTo, { recursive: true, force: true });
|
|
249
|
+
clonedTo = null;
|
|
250
|
+
}
|
|
251
|
+
return committed.result;
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
// No residue on any failure (clone failure, bad manifest, conflict):
|
|
255
|
+
// drop the tmp dir, and the renamed clone too if we got that far.
|
|
256
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
257
|
+
if (clonedTo !== null)
|
|
258
|
+
await rm(clonedTo, { recursive: true, force: true });
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/** Plugin count for an already-known marketplace: read its manifest in place. */
|
|
263
|
+
function manifestPluginCount(dir) {
|
|
264
|
+
try {
|
|
265
|
+
const manifest = JSON.parse(readFileSync(join(dir, '.claude-plugin', 'marketplace.json'), 'utf8'));
|
|
266
|
+
return Array.isArray(manifest['plugins']) ? manifest['plugins'].length : 0;
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* `marketplace update [name]` (C8): all marketplaces when name omitted, over
|
|
274
|
+
* the MERGED known map (§4.7). Dsh-owned entries: directory sources just
|
|
275
|
+
* re-validate the manifest; git/github sources run
|
|
276
|
+
* `git -C <installLocation> pull --ff-only`. Claude-owned entries are
|
|
277
|
+
* promoted on write (never a pull inside the claude home). The dsh known
|
|
278
|
+
* file is committed after each processed marketplace (decision G).
|
|
279
|
+
*/
|
|
280
|
+
export async function updateMarketplaces(deps, name) {
|
|
281
|
+
const { now, runGit } = resolveDeps(deps);
|
|
282
|
+
const paths = pluginsStatePaths(deps);
|
|
283
|
+
const mergedKnown = await loadMergedKnownMarketplaces(deps);
|
|
284
|
+
const names = Object.keys(mergedKnown.entries);
|
|
285
|
+
if (name !== undefined && !names.includes(name))
|
|
286
|
+
throw unknownMarketplace(name, names);
|
|
287
|
+
const targets = name !== undefined ? [name] : [...names].sort();
|
|
288
|
+
const updated = [];
|
|
289
|
+
for (const target of targets) {
|
|
290
|
+
const entry = mergedKnown.entries[target];
|
|
291
|
+
let newEntry;
|
|
292
|
+
if (mergedKnown.origin[target] === 'dsh') {
|
|
293
|
+
// Dsh-owned entry: today's behavior (pull --ff-only / re-validate).
|
|
294
|
+
if (entry.source.source === 'directory') {
|
|
295
|
+
await readManifest(entry.installLocation);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const result = await runGit(['-C', entry.installLocation, 'pull', '--ff-only'], { cwd: entry.installLocation });
|
|
299
|
+
if (result.code !== 0)
|
|
300
|
+
throw gitFailure('pull', entry.installLocation, result);
|
|
301
|
+
}
|
|
302
|
+
newEntry = { ...entry, lastUpdated: now().toISOString() };
|
|
303
|
+
}
|
|
304
|
+
else if (entry.source.source === 'directory') {
|
|
305
|
+
// Claude-owned directory source: no clone — the dsh entry points at
|
|
306
|
+
// the same external path with refreshed lastUpdated (§4.7).
|
|
307
|
+
await readManifest(entry.installLocation);
|
|
308
|
+
newEntry = { ...entry, lastUpdated: now().toISOString() };
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
// Claude-owned git/github entry: promote-on-write (§4.7) — never run
|
|
312
|
+
// `git pull` inside the claude home.
|
|
313
|
+
newEntry = await promoteGitEntry(entry, target, now, runGit, paths);
|
|
314
|
+
}
|
|
315
|
+
// Per-entry commit (decision G, §4.7): the dsh known file is saved after
|
|
316
|
+
// EACH successfully processed marketplace, so a mid-batch failure
|
|
317
|
+
// persists the processed prefix.
|
|
318
|
+
const dshKnown = await loadKnownMarketplaces(paths.knownMarketplacesFile);
|
|
319
|
+
dshKnown[target] = newEntry;
|
|
320
|
+
await saveJsonFileAtomic(paths.knownMarketplacesFile, dshKnown);
|
|
321
|
+
updated.push(target);
|
|
322
|
+
}
|
|
323
|
+
return updated;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Promote a claude-owned git/github entry (§4.7): fresh `git clone <source>`
|
|
327
|
+
* into `<dshHome>/plugins/marketplaces/<name>` under the tmp-dir + rename +
|
|
328
|
+
* rollback discipline. The clone's manifest name must match the entry name
|
|
329
|
+
* (`marketplaceNameMismatch` otherwise, clone dropped); the dsh entry keeps
|
|
330
|
+
* all claude entry fields (autoUpdate, unknown extras) with the new
|
|
331
|
+
* installLocation and refreshed lastUpdated. The claude home is untouched.
|
|
332
|
+
*/
|
|
333
|
+
async function promoteGitEntry(entry, name, now, runGit, paths) {
|
|
334
|
+
const source = entry.source;
|
|
335
|
+
if (source.source === 'directory')
|
|
336
|
+
throw marketplaceConflict(name, 'directory');
|
|
337
|
+
const url = source.source === 'github' ? `https://github.com/${source.repo}.git` : source.url;
|
|
338
|
+
await mkdir(paths.marketplacesDir, { recursive: true });
|
|
339
|
+
const dest = join(paths.marketplacesDir, name);
|
|
340
|
+
// Residue self-heal (§4.7): a dsh clone dir with no dsh known entry
|
|
341
|
+
// referencing it is a crashed earlier attempt — remove and re-clone.
|
|
342
|
+
if (existsSync(dest)) {
|
|
343
|
+
const dshKnown = await loadKnownMarketplaces(paths.knownMarketplacesFile);
|
|
344
|
+
const referenced = Object.values(dshKnown).some(candidate => candidate !== null && candidate.installLocation === dest);
|
|
345
|
+
if (!referenced)
|
|
346
|
+
await rm(dest, { recursive: true, force: true });
|
|
347
|
+
}
|
|
348
|
+
const tmpDir = join(paths.marketplacesDir, `.tmp-promote-${name}-${process.pid}`);
|
|
349
|
+
try {
|
|
350
|
+
const result = await runGit(['clone', url, tmpDir], { cwd: paths.marketplacesDir });
|
|
351
|
+
if (result.code !== 0)
|
|
352
|
+
throw gitFailure('clone', url, result);
|
|
353
|
+
const manifest = await readManifest(tmpDir);
|
|
354
|
+
if (manifest.name !== name)
|
|
355
|
+
throw marketplaceNameMismatch(name, manifest.name);
|
|
356
|
+
await rename(tmpDir, dest);
|
|
357
|
+
return { ...entry, installLocation: dest, lastUpdated: now().toISOString() };
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* `marketplace remove <name>` (C6): C6 pre-flight (C5 project-guard per
|
|
366
|
+
* plugin) over the MERGED installed view, then per-id cascade uninstall per
|
|
367
|
+
* §4.3; claude-owned clone dirs are never deleted (W3 — only dirs inside
|
|
368
|
+
* the DSH marketplaces dir are removed); the known name gets a dsh `null`
|
|
369
|
+
* tombstone (§3.5, dual-home) or a plain key removal (single-root C6);
|
|
370
|
+
* `extraKnownMarketplaces` stripping per §3.6 (user → dsh file only, never
|
|
371
|
+
* the claude file).
|
|
372
|
+
*/
|
|
373
|
+
export async function removeMarketplace(deps, name) {
|
|
374
|
+
const paths = pluginsStatePaths(deps);
|
|
375
|
+
const claudePaths = claudePluginsStatePaths(deps);
|
|
376
|
+
const mergedKnown = await loadMergedKnownMarketplaces(deps);
|
|
377
|
+
const entry = mergedKnown.entries[name];
|
|
378
|
+
if (entry === undefined)
|
|
379
|
+
throw unknownMarketplace(name, Object.keys(mergedKnown.entries));
|
|
380
|
+
// C6 cascade: uninstall every plugin installed from this marketplace,
|
|
381
|
+
// with the C5 project-scope pre-flight refusing the whole remove before
|
|
382
|
+
// any mutation. Individual uninstall steps skip their own C5 guard since
|
|
383
|
+
// the pre-flight passed.
|
|
384
|
+
const installed = (await loadMergedInstalledPlugins(deps)).file;
|
|
385
|
+
const projectSettings = await loadSettingsFile(settingsFileForScope('project', deps));
|
|
386
|
+
const ids = Object.keys(installed.plugins).filter(key => parsePluginId(key).marketplace === name).sort();
|
|
387
|
+
for (const id of ids) {
|
|
388
|
+
if (projectSettings['enabledPlugins']?.[id] === true)
|
|
389
|
+
throw projectScopeEnabledGuard(id);
|
|
390
|
+
}
|
|
391
|
+
const removedPlugins = [];
|
|
392
|
+
for (const id of ids) {
|
|
393
|
+
const scopes = [...new Set((installed.plugins[id] ?? []).map(installEntry => installEntry.scope))];
|
|
394
|
+
for (const scope of scopes) {
|
|
395
|
+
await uninstallPlugin(deps, id, { scope, skipProjectGuard: true });
|
|
396
|
+
}
|
|
397
|
+
removedPlugins.push(id);
|
|
398
|
+
}
|
|
399
|
+
if (entry.source.source !== 'directory') {
|
|
400
|
+
const loc = resolve(entry.installLocation);
|
|
401
|
+
const inside = canonicalizeExistingPath(paths.marketplacesDir);
|
|
402
|
+
if (existsSync(loc) && canonicalizeExistingPath(dirname(loc)) === inside) {
|
|
403
|
+
await rm(loc, { recursive: true, force: true });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
for (const scope of SCOPES) {
|
|
407
|
+
const settingsFile = settingsFileForScope(scope, deps);
|
|
408
|
+
const settings = await loadSettingsFile(settingsFile);
|
|
409
|
+
if (settings['extraKnownMarketplaces']?.[name] === undefined)
|
|
410
|
+
continue;
|
|
411
|
+
const next = { ...settings };
|
|
412
|
+
next['extraKnownMarketplaces'] = { ...settings['extraKnownMarketplaces'] };
|
|
413
|
+
delete next['extraKnownMarketplaces'][name];
|
|
414
|
+
await saveJsonFileAtomic(settingsFile, next);
|
|
415
|
+
}
|
|
416
|
+
// dsh known file: a null tombstone in dual-home (§3.5); plain key removal
|
|
417
|
+
// in single-root (C6 byte-parity — single-root never writes tombstones).
|
|
418
|
+
const dshKnown = await loadJsonFile(paths.knownMarketplacesFile, {});
|
|
419
|
+
if (claudePaths === null)
|
|
420
|
+
delete dshKnown[name];
|
|
421
|
+
else
|
|
422
|
+
dshKnown[name] = null;
|
|
423
|
+
await saveJsonFileAtomic(paths.knownMarketplacesFile, dshKnown);
|
|
424
|
+
return { name, removedPlugins };
|
|
425
|
+
}
|
|
426
|
+
//# sourceMappingURL=marketplace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketplace.js","sourceRoot":"","sources":["../src/marketplace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAkB,MAAM,UAAU,CAAA;AA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B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACtD,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAA;QACrD,IAAI,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,SAAQ;QACtE,MAAM,IAAI,GAAsB,EAAE,GAAG,QAAQ,EAAE,CAAA;QAC/C,IAAI,CAAC,wBAAwB,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAA;QAC1E,OAAO,IAAI,CAAC,wBAAwB,CAAE,CAAC,IAAI,CAAC,CAAA;QAC5C,MAAM,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,MAAM,QAAQ,GAAiD,MAAM,YAAY,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAA;IAClH,IAAI,WAAW,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAA;;QAC1C,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAC1B,MAAM,kBAAkB,CAAC,KAAK,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAA;IAC/D,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merged dual-home state readers (plan §3.2–§3.5): layered per-key maps in
|
|
3
|
+
* which the dsh home (write root) is authoritative over the claude home
|
|
4
|
+
* (compat read root) for keys it carries, while claude-only keys pass
|
|
5
|
+
* through. Nothing is cached — every call re-reads both homes. The dsh
|
|
6
|
+
* `known_marketplaces.json` may carry `null` tombstones (dsh-private
|
|
7
|
+
* extension, §3.5); the claude file keeps the strict CC type. In single-root
|
|
8
|
+
* mode (both homes canonicalize equal) each file is read exactly once.
|
|
9
|
+
*
|
|
10
|
+
* @module @dsh-cc/plugin-manager/merged-state
|
|
11
|
+
*/
|
|
12
|
+
import { type PathInputs } from './paths.ts';
|
|
13
|
+
import type { EnabledPlugins, InstalledPluginsFile, KnownMarketplaceEntry, KnownMarketplacesFile } from './types.ts';
|
|
14
|
+
/** Which home a merged key came from (provenance for later slices, §3.2). */
|
|
15
|
+
export type MergeOrigin = 'dsh' | 'claude';
|
|
16
|
+
/** The dsh known-marketplaces file may carry `null` tombstones (§3.5). */
|
|
17
|
+
export type DshKnownMarketplacesFile = Record<string, KnownMarketplaceEntry | null>;
|
|
18
|
+
export interface MergedKnownMarketplaces {
|
|
19
|
+
/** Merged entries; dsh-tombstoned names are omitted. */
|
|
20
|
+
entries: KnownMarketplacesFile;
|
|
21
|
+
/** Per-name origin, tracking the authoritative home. */
|
|
22
|
+
origin: Record<string, MergeOrigin>;
|
|
23
|
+
}
|
|
24
|
+
export interface MergedInstalledPlugins {
|
|
25
|
+
/** Merged file: per id, the dsh entry list — including an empty one — shadows the claude list (§3.4). */
|
|
26
|
+
file: InstalledPluginsFile;
|
|
27
|
+
/** Per-id origin, tracking the authoritative home. */
|
|
28
|
+
origin: Record<string, MergeOrigin>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Merged `known_marketplaces.json` (§3.5): per name a dsh entry wins;
|
|
32
|
+
* claude-only names pass through; a dsh `null` tombstones the name out of
|
|
33
|
+
* the merged view (and its origin).
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadMergedKnownMarketplaces(deps: PathInputs): Promise<MergedKnownMarketplaces>;
|
|
36
|
+
/**
|
|
37
|
+
* Merged `installed_plugins.json` (§3.4): per plugin id the dsh entry list —
|
|
38
|
+
* including the empty list — shadows the claude list; claude-only ids pass
|
|
39
|
+
* through. Entries' `installPath`s freely mix homes.
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadMergedInstalledPlugins(deps: PathInputs): Promise<MergedInstalledPlugins>;
|
|
42
|
+
/**
|
|
43
|
+
* The resolution view of a merged installed file (§3.4): ids whose merged
|
|
44
|
+
* entry list is non-empty. A shadowed (empty-list) id never resolves as
|
|
45
|
+
* installed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolutionIds(file: InstalledPluginsFile): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Merged user-scope `enabledPlugins` (§3.3): the dsh user settings value
|
|
50
|
+
* wins per key over the claude user settings; keys absent from the dsh file
|
|
51
|
+
* re-expose the claude value ("un-override").
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadMergedUserEnabledPlugins(deps: PathInputs): Promise<EnabledPlugins>;
|
|
54
|
+
//# sourceMappingURL=merged-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merged-state.d.ts","sourceRoot":"","sources":["../src/merged-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAqE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAE/G,OAAO,KAAK,EAAE,cAAc,EAAgB,oBAAoB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElI,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,CAAA;AAE1C,0EAA0E;AAC1E,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAC,CAAA;AAEnF,MAAM,WAAW,uBAAuB;IACtC,wDAAwD;IACxD,OAAO,EAAE,qBAAqB,CAAA;IAC9B,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC,yGAAyG;IACzG,IAAI,EAAE,oBAAoB,CAAA;IAC1B,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CACpC;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAuBpG;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAkBlG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAElE;AAED;;;;GAIG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAO5F"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merged dual-home state readers (plan §3.2–§3.5): layered per-key maps in
|
|
3
|
+
* which the dsh home (write root) is authoritative over the claude home
|
|
4
|
+
* (compat read root) for keys it carries, while claude-only keys pass
|
|
5
|
+
* through. Nothing is cached — every call re-reads both homes. The dsh
|
|
6
|
+
* `known_marketplaces.json` may carry `null` tombstones (dsh-private
|
|
7
|
+
* extension, §3.5); the claude file keeps the strict CC type. In single-root
|
|
8
|
+
* mode (both homes canonicalize equal) each file is read exactly once.
|
|
9
|
+
*
|
|
10
|
+
* @module @dsh-cc/plugin-manager/merged-state
|
|
11
|
+
*/
|
|
12
|
+
import { claudePluginsStatePaths, pluginsStatePaths, userSettingsReadFiles } from "./paths.js";
|
|
13
|
+
import { loadInstalledPlugins, loadJsonFile, loadSettingsFile } from "./state-store.js";
|
|
14
|
+
/**
|
|
15
|
+
* Merged `known_marketplaces.json` (§3.5): per name a dsh entry wins;
|
|
16
|
+
* claude-only names pass through; a dsh `null` tombstones the name out of
|
|
17
|
+
* the merged view (and its origin).
|
|
18
|
+
*/
|
|
19
|
+
export async function loadMergedKnownMarketplaces(deps) {
|
|
20
|
+
const paths = pluginsStatePaths(deps);
|
|
21
|
+
const claudePaths = claudePluginsStatePaths(deps);
|
|
22
|
+
const entries = {};
|
|
23
|
+
const origin = {};
|
|
24
|
+
if (claudePaths !== null) {
|
|
25
|
+
const claude = await loadJsonFile(claudePaths.knownMarketplacesFile, {});
|
|
26
|
+
for (const [name, entry] of Object.entries(claude)) {
|
|
27
|
+
entries[name] = entry;
|
|
28
|
+
origin[name] = 'claude';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const dsh = await loadJsonFile(paths.knownMarketplacesFile, {});
|
|
32
|
+
for (const [name, entry] of Object.entries(dsh)) {
|
|
33
|
+
if (entry === null) {
|
|
34
|
+
delete entries[name];
|
|
35
|
+
delete origin[name];
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
entries[name] = entry;
|
|
39
|
+
origin[name] = 'dsh';
|
|
40
|
+
}
|
|
41
|
+
return { entries, origin };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Merged `installed_plugins.json` (§3.4): per plugin id the dsh entry list —
|
|
45
|
+
* including the empty list — shadows the claude list; claude-only ids pass
|
|
46
|
+
* through. Entries' `installPath`s freely mix homes.
|
|
47
|
+
*/
|
|
48
|
+
export async function loadMergedInstalledPlugins(deps) {
|
|
49
|
+
const paths = pluginsStatePaths(deps);
|
|
50
|
+
const claudePaths = claudePluginsStatePaths(deps);
|
|
51
|
+
const file = { version: 2, plugins: {} };
|
|
52
|
+
const origin = {};
|
|
53
|
+
if (claudePaths !== null) {
|
|
54
|
+
const claude = await loadInstalledPlugins(claudePaths.installedPluginsFile);
|
|
55
|
+
for (const [id, entries] of Object.entries(claude.plugins)) {
|
|
56
|
+
file.plugins[id] = entries;
|
|
57
|
+
origin[id] = 'claude';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const dsh = await loadInstalledPlugins(paths.installedPluginsFile);
|
|
61
|
+
for (const [id, entries] of Object.entries(dsh.plugins)) {
|
|
62
|
+
file.plugins[id] = entries;
|
|
63
|
+
origin[id] = 'dsh';
|
|
64
|
+
}
|
|
65
|
+
return { file, origin };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The resolution view of a merged installed file (§3.4): ids whose merged
|
|
69
|
+
* entry list is non-empty. A shadowed (empty-list) id never resolves as
|
|
70
|
+
* installed.
|
|
71
|
+
*/
|
|
72
|
+
export function resolutionIds(file) {
|
|
73
|
+
return Object.keys(file.plugins).filter(id => file.plugins[id].length > 0);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Merged user-scope `enabledPlugins` (§3.3): the dsh user settings value
|
|
77
|
+
* wins per key over the claude user settings; keys absent from the dsh file
|
|
78
|
+
* re-expose the claude value ("un-override").
|
|
79
|
+
*/
|
|
80
|
+
export async function loadMergedUserEnabledPlugins(deps) {
|
|
81
|
+
const merged = {};
|
|
82
|
+
for (const file of userSettingsReadFiles(deps)) {
|
|
83
|
+
const settings = await loadSettingsFile(file);
|
|
84
|
+
Object.assign(merged, settings['enabledPlugins'] ?? {});
|
|
85
|
+
}
|
|
86
|
+
return merged;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=merged-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merged-state.js","sourceRoot":"","sources":["../src/merged-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,qBAAqB,EAAmB,MAAM,YAAY,CAAA;AAC/G,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAuBvF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,IAAgB;IAChE,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACrC,MAAM,WAAW,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,OAAO,GAA0B,EAAE,CAAA;IACzC,MAAM,MAAM,GAAgC,EAAE,CAAA;IAC9C,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,YAAY,CAAwB,WAAW,CAAC,qBAAqB,EAAE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