@ai-primitives-hub/cli 0.2.0 → 0.2.2-next.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 +26 -1
- package/dist/commands/bundle-build.d.ts +1 -0
- package/dist/commands/bundle-build.d.ts.map +1 -1
- package/dist/commands/bundle-build.js +23 -4
- package/dist/commands/bundle-build.js.map +1 -1
- package/dist/commands/collection-affected.d.ts.map +1 -1
- package/dist/commands/collection-affected.js +1 -34
- package/dist/commands/collection-affected.js.map +1 -1
- package/dist/commands/collection-validate.d.ts +15 -2
- package/dist/commands/collection-validate.d.ts.map +1 -1
- package/dist/commands/collection-validate.js +42 -4
- package/dist/commands/collection-validate.js.map +1 -1
- package/dist/commands/doctor.d.ts +4 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +37 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/explain.d.ts.map +1 -1
- package/dist/commands/explain.js +54 -4
- package/dist/commands/explain.js.map +1 -1
- package/dist/commands/hub-replicate.d.ts +1 -0
- package/dist/commands/hub-replicate.d.ts.map +1 -1
- package/dist/commands/hub-replicate.js +16 -5
- package/dist/commands/hub-replicate.js.map +1 -1
- package/dist/commands/hub-scoped-governance.d.ts +21 -0
- package/dist/commands/hub-scoped-governance.d.ts.map +1 -0
- package/dist/commands/hub-scoped-governance.js +74 -0
- package/dist/commands/hub-scoped-governance.js.map +1 -0
- package/dist/commands/hub.d.ts +6 -0
- package/dist/commands/hub.d.ts.map +1 -1
- package/dist/commands/hub.js +68 -0
- package/dist/commands/hub.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +3 -10
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.d.ts +18 -10
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +472 -253
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/plugin-create.d.ts.map +1 -1
- package/dist/commands/plugin-create.js +72 -43
- package/dist/commands/plugin-create.js.map +1 -1
- package/dist/commands/profile.d.ts +42 -4
- package/dist/commands/profile.d.ts.map +1 -1
- package/dist/commands/profile.js +739 -144
- package/dist/commands/profile.js.map +1 -1
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +5 -0
- package/dist/commands/registry.js.map +1 -1
- package/dist/commands/security-rate.d.ts +26 -0
- package/dist/commands/security-rate.d.ts.map +1 -0
- package/dist/commands/security-rate.js +281 -0
- package/dist/commands/security-rate.js.map +1 -0
- package/dist/commands/security-scan.d.ts +40 -0
- package/dist/commands/security-scan.d.ts.map +1 -0
- package/dist/commands/security-scan.js +395 -0
- package/dist/commands/security-scan.js.map +1 -0
- package/dist/commands/status.d.ts +18 -11
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +42 -33
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/uninstall.d.ts +2 -9
- package/dist/commands/uninstall.d.ts.map +1 -1
- package/dist/commands/uninstall.js +413 -147
- package/dist/commands/uninstall.js.map +1 -1
- package/dist/commands/update.d.ts +1 -2
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +379 -56
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validation-governance.d.ts +27 -0
- package/dist/commands/validation-governance.d.ts.map +1 -0
- package/dist/commands/validation-governance.js +92 -0
- package/dist/commands/validation-governance.js.map +1 -0
- package/dist/doctor/diagnostics.d.ts +72 -5
- package/dist/doctor/diagnostics.d.ts.map +1 -1
- package/dist/doctor/diagnostics.js +95 -40
- package/dist/doctor/diagnostics.js.map +1 -1
- package/dist/doctor/primitive-driver.d.ts +24 -0
- package/dist/doctor/primitive-driver.d.ts.map +1 -0
- package/dist/doctor/primitive-driver.js +162 -0
- package/dist/doctor/primitive-driver.js.map +1 -0
- package/dist/doctor/primitives-text.d.ts +27 -0
- package/dist/doctor/primitives-text.d.ts.map +1 -0
- package/dist/doctor/primitives-text.js +131 -0
- package/dist/doctor/primitives-text.js.map +1 -0
- package/dist/doctor/primitives.d.ts +24 -0
- package/dist/doctor/primitives.d.ts.map +1 -0
- package/dist/doctor/primitives.js +101 -0
- package/dist/doctor/primitives.js.map +1 -0
- package/dist/framework/error.d.ts +19 -18
- package/dist/framework/error.d.ts.map +1 -1
- package/dist/framework/error.js +78 -22
- package/dist/framework/error.js.map +1 -1
- package/dist/framework/index.d.ts +3 -1
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +42 -1
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/install-record.d.ts +555 -0
- package/dist/framework/install-record.d.ts.map +1 -0
- package/dist/framework/install-record.js +968 -0
- package/dist/framework/install-record.js.map +1 -0
- package/dist/framework/target.d.ts +9 -12
- package/dist/framework/target.d.ts.map +1 -1
- package/dist/framework/target.js +9 -12
- package/dist/framework/target.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -1
- package/dist/main.js.map +1 -1
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +15 -0
- package/dist/version.js.map +1 -0
- package/package.json +6 -4
|
@@ -33,17 +33,28 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.createWriterFactory = exports.UninstallCommand = void 0;
|
|
37
37
|
exports.runUserScopeUninstall = runUserScopeUninstall;
|
|
38
38
|
/**
|
|
39
39
|
* Uninstall command for removing bundles from targets.
|
|
40
40
|
*
|
|
41
41
|
* Symmetric to install: supports three modes:
|
|
42
|
-
* ai-primitives-hub uninstall <bundle-id> (by bundle ID)
|
|
42
|
+
* ai-primitives-hub uninstall --bundle <bundle-id> (by bundle ID)
|
|
43
43
|
* ai-primitives-hub uninstall --lockfile <path> (from lockfile)
|
|
44
44
|
* ai-primitives-hub uninstall --all (all bundles for target)
|
|
45
45
|
*
|
|
46
|
-
* Repository-scope
|
|
46
|
+
* Repository-scope `<bundle-id>` and `--all` uninstalls first use the 3.0.0
|
|
47
|
+
* install record, keeping files another entry lists or that were edited since
|
|
48
|
+
* the install; bundles not recorded there fall back to the old store.
|
|
49
|
+
*
|
|
50
|
+
* `uninstall --lockfile <ai-primitives-hub.*.lock.json>` removes only the
|
|
51
|
+
* target tool's entries, and `uninstall --bundle <id>` without `--target` is refused
|
|
52
|
+
* when the record lists the bundle for several tools.
|
|
53
|
+
*
|
|
54
|
+
* Without an inferred target, `uninstall --bundle <id>` lets the record decide the
|
|
55
|
+
* tool; every other mode needs `--target` unless one target is configured.
|
|
56
|
+
*
|
|
57
|
+
* Repository-scope targets otherwise delegate to `UninstallPipeline`
|
|
47
58
|
* (`@ai-primitives-hub/app`), which already encapsulates the
|
|
48
59
|
* commit/local-only two-file split (see its module doc). User/workspace
|
|
49
60
|
* scope has no such split — there is a single, non-split
|
|
@@ -53,12 +64,12 @@ exports.runUserScopeUninstall = runUserScopeUninstall;
|
|
|
53
64
|
*/
|
|
54
65
|
const path = __importStar(require("node:path"));
|
|
55
66
|
const app_1 = require("@ai-primitives-hub/app");
|
|
67
|
+
const core_1 = require("@ai-primitives-hub/core");
|
|
56
68
|
const infra_1 = require("@ai-primitives-hub/infra");
|
|
57
69
|
const framework_1 = require("../framework");
|
|
58
|
-
const framework_2 = require("../framework");
|
|
59
70
|
/**
|
|
60
71
|
* Detect uninstall context from the project environment (symmetric with install).
|
|
61
|
-
* Fills in `opts.lockfile`
|
|
72
|
+
* Fills in `opts.lockfile` when it can be inferred; the target is inferred later.
|
|
62
73
|
* @param opts Uninstall options (mutated in-place).
|
|
63
74
|
* @param ctx CLI context.
|
|
64
75
|
*/
|
|
@@ -69,12 +80,80 @@ async function detectUninstallContext(opts, ctx) {
|
|
|
69
80
|
opts.lockfile = foundLock;
|
|
70
81
|
}
|
|
71
82
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The `USAGE.MISSING_FLAG` error for a bundle recorded for several tools.
|
|
86
|
+
* @param bundleId Bundle to uninstall.
|
|
87
|
+
* @param tools Its recorded tools.
|
|
88
|
+
*/
|
|
89
|
+
const multiToolError = (bundleId, tools) => new framework_1.RegistryError({
|
|
90
|
+
code: 'USAGE.MISSING_FLAG',
|
|
91
|
+
message: `uninstall: bundle "${bundleId}" is installed for several tools (${tools.join(', ')}); pass --target to choose one`,
|
|
92
|
+
hint: `Example: ai-primitives-hub uninstall --bundle ${bundleId} --target <name of a ${tools[0]} target>`,
|
|
93
|
+
context: { bundle: bundleId, tools: [...tools] }
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Refuse `uninstall --bundle <id>` without `--target` when the record lists the bundle for several tools.
|
|
97
|
+
* @param rows Rows of the record decision.
|
|
98
|
+
* @param bundleId Bundle to uninstall.
|
|
99
|
+
* @throws {RegistryError} `USAGE.MISSING_FLAG` listing the tools; nothing was removed.
|
|
100
|
+
*/
|
|
101
|
+
function assertSingleTool(rows, bundleId) {
|
|
102
|
+
const tools = (0, framework_1.recordedTools)(rows, bundleId);
|
|
103
|
+
if (tools.length > 1) {
|
|
104
|
+
throw multiToolError(bundleId, tools);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether `uninstall` removes one bundle (`<bundle-id>`, no `--all` or `--lockfile`).
|
|
109
|
+
* @param opts Uninstall options.
|
|
110
|
+
*/
|
|
111
|
+
const isBundleMode = (opts) => opts.bundle !== undefined && opts.bundle.length > 0 && opts.all !== true
|
|
112
|
+
&& (opts.lockfile === undefined || opts.lockfile.length === 0);
|
|
113
|
+
/**
|
|
114
|
+
* `uninstall --bundle <bundle-id>` with no inferred target: a lone `unknown` entry is
|
|
115
|
+
* removed keeping its files, else the bundle goes through the target mapped to its tool.
|
|
116
|
+
* @param opts Uninstall options; `opts.bundle` is set.
|
|
117
|
+
* @param ctx CLI context.
|
|
118
|
+
* @param fmt Output format.
|
|
119
|
+
* @param decision The read-only record decision.
|
|
120
|
+
* @returns Exit code, or `undefined` when the record has no entry for the bundle.
|
|
121
|
+
* @throws {RegistryError} `USAGE.MISSING_FLAG`, or a `RECORD.*` error naming the file.
|
|
122
|
+
*/
|
|
123
|
+
async function uninstallWithoutTarget(opts, ctx, fmt, decision) {
|
|
124
|
+
const bundleId = opts.bundle;
|
|
125
|
+
let current = decision;
|
|
126
|
+
// A migration can change the bundle's entries once; the second pass decides on the migrated record.
|
|
127
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
128
|
+
const tools = (0, framework_1.recordedTools)(current.rows, bundleId);
|
|
129
|
+
if (tools.length === 0) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const [tool] = tools;
|
|
133
|
+
if (tool === core_1.UNKNOWN_TOOL_NAME) {
|
|
134
|
+
const prepared = await (0, framework_1.prepareUnknownUninstall)(ctx, current, bundleId, { dryRun: opts.dryRun });
|
|
135
|
+
if ('changed' in prepared) {
|
|
136
|
+
assertSingleTool(prepared.changed.rows, bundleId);
|
|
137
|
+
current = prepared.changed;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
return performUnknownBundleUninstall({ opts, ctx, fmt }, prepared.uninstall, bundleId);
|
|
141
|
+
}
|
|
142
|
+
const { selection, fs } = current.prepared;
|
|
143
|
+
const targets = await (0, framework_1.readTargetsSafely)((0, framework_1.loadTargets)(ctx));
|
|
144
|
+
const mapping = await (0, app_1.mapToolToTarget)({ fs, tool, level: selection.level, gitRoot: selection.root, targets, cwd: ctx.cwd() });
|
|
145
|
+
if ('skip' in mapping) {
|
|
146
|
+
throw new framework_1.RegistryError({
|
|
147
|
+
code: 'USAGE.MISSING_FLAG',
|
|
148
|
+
message: `uninstall: no ${tool} target configured; add one with target add, or pass --target`,
|
|
149
|
+
hint: `Example: ai-primitives-hub target add <name> --type ${tool}`,
|
|
150
|
+
context: { bundle: bundleId, tool, reason: mapping.skip }
|
|
151
|
+
});
|
|
76
152
|
}
|
|
153
|
+
const target = (0, framework_1.resolveEffectiveTarget)(ctx, mapping.target, opts);
|
|
154
|
+
return performBundleUninstall(opts, target, ctx, fmt, false, mapping.note === undefined ? [] : [mapping.note]);
|
|
77
155
|
}
|
|
156
|
+
return undefined;
|
|
78
157
|
}
|
|
79
158
|
/**
|
|
80
159
|
* Base class for the uninstall command.
|
|
@@ -105,7 +184,7 @@ class UninstallCommand extends BaseUninstallCommand {
|
|
|
105
184
|
-o, --output <format> Output format (text, json, yaml, ndjson)
|
|
106
185
|
|
|
107
186
|
Examples:
|
|
108
|
-
ai-primitives-hub uninstall --lockfile
|
|
187
|
+
ai-primitives-hub uninstall --lockfile ai-primitives-hub.lock.json --target my-vscode
|
|
109
188
|
ai-primitives-hub uninstall --all --target my-vscode
|
|
110
189
|
ai-primitives-hub uninstall --dry-run --target my-vscode
|
|
111
190
|
`
|
|
@@ -131,33 +210,55 @@ class UninstallCommand extends BaseUninstallCommand {
|
|
|
131
210
|
scope: this.scope,
|
|
132
211
|
commitMode: this.commitMode
|
|
133
212
|
};
|
|
213
|
+
const typedTarget = opts.target !== undefined && opts.target.length > 0;
|
|
214
|
+
const bundleMode = isBundleMode(opts);
|
|
215
|
+
// Without --target the record is read once, read-only, and decides below.
|
|
216
|
+
let decision;
|
|
217
|
+
try {
|
|
218
|
+
// Checked before the target is inferred, so one configured target never picks one of several recorded tools.
|
|
219
|
+
if (!typedTarget && bundleMode) {
|
|
220
|
+
decision = await (0, framework_1.prepareRecordDecision)(ctx, { command: 'uninstall', scope: opts.scope });
|
|
221
|
+
assertSingleTool(decision.rows, opts.bundle);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
if (err instanceof framework_1.RegistryError) {
|
|
226
|
+
return (0, framework_1.failWith)(ctx, fmt, 'uninstall', err);
|
|
227
|
+
}
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
134
230
|
await detectUninstallContext(opts, ctx);
|
|
135
|
-
const { bundle: noBundle, lockfile: noLockfile, all: noAll } = (0,
|
|
231
|
+
const { bundle: noBundle, lockfile: noLockfile, all: noAll } = (0, framework_1.validateInputs)(opts, { flags: ['bundle', 'lockfile', 'all'] });
|
|
136
232
|
if (noBundle && noLockfile && noAll) {
|
|
137
|
-
return (0, framework_1.failWith)(ctx, fmt, 'uninstall', new
|
|
233
|
+
return (0, framework_1.failWith)(ctx, fmt, 'uninstall', new framework_1.RegistryError({
|
|
138
234
|
code: 'USAGE.MISSING_FLAG',
|
|
139
235
|
message: 'uninstall: provide <bundle-id>, --lockfile <path>, or --all',
|
|
140
236
|
hint: 'Examples:\n'
|
|
141
|
-
+ ' ai-primitives-hub uninstall <bundle-id> --target my-vscode\n'
|
|
142
|
-
+ ' ai-primitives-hub uninstall --lockfile
|
|
237
|
+
+ ' ai-primitives-hub uninstall --bundle <bundle-id> --target my-vscode\n'
|
|
238
|
+
+ ' ai-primitives-hub uninstall --lockfile ai-primitives-hub.lock.json\n'
|
|
143
239
|
+ ' ai-primitives-hub uninstall --all\n\n'
|
|
144
240
|
+ 'Note: Lockfile is auto-detected in current directory and parent directories.'
|
|
145
241
|
}));
|
|
146
242
|
}
|
|
147
243
|
try {
|
|
148
|
-
const targetName = await (0,
|
|
149
|
-
|
|
150
|
-
|
|
244
|
+
const targetName = await (0, framework_1.inferTargetName)(ctx, opts.target);
|
|
245
|
+
if (decision !== undefined && targetName === undefined) {
|
|
246
|
+
const code = await uninstallWithoutTarget(opts, ctx, fmt, decision);
|
|
247
|
+
if (code !== undefined) {
|
|
248
|
+
return code;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const target = await (0, framework_1.resolveCommandTarget)(ctx, 'uninstall', targetName, opts);
|
|
151
252
|
if (opts.all === true) {
|
|
152
253
|
return await performAllUninstall(opts, target, ctx, fmt);
|
|
153
254
|
}
|
|
154
255
|
if (opts.lockfile !== undefined && opts.lockfile.length > 0) {
|
|
155
256
|
return await performLockfileUninstall(opts, target, ctx, fmt);
|
|
156
257
|
}
|
|
157
|
-
return await performBundleUninstall(opts, target, ctx, fmt);
|
|
258
|
+
return await performBundleUninstall(opts, target, ctx, fmt, typedTarget);
|
|
158
259
|
}
|
|
159
260
|
catch (err) {
|
|
160
|
-
if (err instanceof
|
|
261
|
+
if (err instanceof framework_1.RegistryError) {
|
|
161
262
|
return (0, framework_1.failWith)(ctx, fmt, 'uninstall', err);
|
|
162
263
|
}
|
|
163
264
|
throw err;
|
|
@@ -179,11 +280,7 @@ const createWriterFactory = (ctx, opts) => {
|
|
|
179
280
|
// path that `writer.write()` used (targets with a real, non-identity
|
|
180
281
|
// transformer like Kiro would otherwise resolve the wrong path).
|
|
181
282
|
const transformerRegistry = app_1.TransformerRegistry.withBuiltIns();
|
|
182
|
-
const layoutLoader =
|
|
183
|
-
cwd: ctx.cwd(),
|
|
184
|
-
fs: ctx.fs,
|
|
185
|
-
userConfigDir: (0, infra_1.resolveUserConfigDir)(ctx.env)
|
|
186
|
-
});
|
|
283
|
+
const layoutLoader = (0, framework_1.createLayoutLoader)(ctx);
|
|
187
284
|
return (target) => {
|
|
188
285
|
const effectiveTarget = (0, framework_1.resolveEffectiveTarget)(ctx, target, opts);
|
|
189
286
|
const scope = effectiveTarget.scope;
|
|
@@ -202,7 +299,7 @@ const createWriterFactory = (ctx, opts) => {
|
|
|
202
299
|
const transformer = transformerRegistry.getTransformer(effectiveTarget.type);
|
|
203
300
|
return new app_1.FileTreeTargetWriter({
|
|
204
301
|
fs: ctx.fs,
|
|
205
|
-
env: ctx.env,
|
|
302
|
+
env: (0, framework_1.writerEnv)(ctx.env, scope),
|
|
206
303
|
transformer,
|
|
207
304
|
layoutLoader
|
|
208
305
|
});
|
|
@@ -253,15 +350,16 @@ async function runUserScopeUninstall(bundleId, lockPath, target, ctx, writer) {
|
|
|
253
350
|
* @param target Target being uninstalled from.
|
|
254
351
|
* @param ctx CLI context.
|
|
255
352
|
* @param writer Target writer.
|
|
353
|
+
* @param exclude Bundle ids already uninstalled from the user record, left alone here.
|
|
256
354
|
* @returns Uninstall results, one per bundle removed.
|
|
257
355
|
*/
|
|
258
|
-
async function runAllUserScopeUninstall(lockPath, target, ctx, writer) {
|
|
356
|
+
async function runAllUserScopeUninstall(lockPath, target, ctx, writer, exclude = new Set()) {
|
|
259
357
|
const lock = await (0, app_1.readLockfile)(lockPath, ctx.fs);
|
|
260
358
|
if (lock === null) {
|
|
261
359
|
return [];
|
|
262
360
|
}
|
|
263
361
|
const results = [];
|
|
264
|
-
for (const bundleId of Object.keys(lock.bundles)) {
|
|
362
|
+
for (const bundleId of Object.keys(lock.bundles).filter((id) => !exclude.has(id))) {
|
|
265
363
|
results.push(await runUserScopeUninstall(bundleId, lockPath, target, ctx, writer));
|
|
266
364
|
}
|
|
267
365
|
return results;
|
|
@@ -318,19 +416,100 @@ async function findAllBundleEntries(target, opts, ctx) {
|
|
|
318
416
|
const lock = await (0, app_1.readLockfile)(lockPath, ctx.fs);
|
|
319
417
|
return lock?.bundles ?? {};
|
|
320
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Print the dry run of a one-bundle uninstall.
|
|
421
|
+
* @param ctx CLI context.
|
|
422
|
+
* @param fmt Output format.
|
|
423
|
+
* @param target Target the bundle is uninstalled from.
|
|
424
|
+
* @param bundleId Bundle id.
|
|
425
|
+
* @param files Paths that would be removed.
|
|
426
|
+
* @param extra Notes and the record a real run would change.
|
|
427
|
+
* @param extra.warnings Tool-to-target mapping notes.
|
|
428
|
+
* @param extra.record The record a real run would change.
|
|
429
|
+
* @returns Exit code.
|
|
430
|
+
*/
|
|
431
|
+
function renderBundleDryRun(ctx, fmt, target, bundleId, files, extra = {}) {
|
|
432
|
+
const { warnings = [], record } = extra;
|
|
433
|
+
(0, framework_1.formatOutput)({
|
|
434
|
+
ctx,
|
|
435
|
+
command: 'uninstall',
|
|
436
|
+
output: fmt,
|
|
437
|
+
status: 'ok',
|
|
438
|
+
data: {
|
|
439
|
+
dryRun: true,
|
|
440
|
+
...(record === undefined ? {} : { level: record.level, records: [...record.records] }),
|
|
441
|
+
target: target.name,
|
|
442
|
+
bundle: bundleId,
|
|
443
|
+
files: [...files]
|
|
444
|
+
},
|
|
445
|
+
warnings: warnings.length > 0 ? [...warnings] : undefined,
|
|
446
|
+
textRenderer: (d) => `[dry-run] Would uninstall bundle "${d.bundle}" from target "${d.target}":\n`
|
|
447
|
+
+ ` Files: ${d.files.join(', ')}\n`
|
|
448
|
+
+ 'Run without --dry-run to apply.\n'
|
|
449
|
+
+ (record === undefined ? '' : (0, framework_1.renderRecordLine)(record))
|
|
450
|
+
});
|
|
451
|
+
return 0;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Print the outcome of a one-bundle uninstall.
|
|
455
|
+
* @param ctx CLI context.
|
|
456
|
+
* @param fmt Output format.
|
|
457
|
+
* @param target Target the bundle was uninstalled from.
|
|
458
|
+
* @param outcome Bundle, removed files, updated file and warnings.
|
|
459
|
+
* @returns Exit code.
|
|
460
|
+
*/
|
|
461
|
+
function renderBundleUninstalled(ctx, fmt, target, outcome) {
|
|
462
|
+
(0, framework_1.formatOutput)({
|
|
463
|
+
ctx,
|
|
464
|
+
command: 'uninstall',
|
|
465
|
+
output: fmt,
|
|
466
|
+
status: 'ok',
|
|
467
|
+
data: {
|
|
468
|
+
...(outcome.record === undefined ? {} : { level: outcome.record.level, records: [...outcome.record.records] }),
|
|
469
|
+
target: target.name,
|
|
470
|
+
bundle: outcome.bundleId,
|
|
471
|
+
removed: [...outcome.removed],
|
|
472
|
+
...(outcome.mcpServersRemoved === undefined || outcome.mcpServersRemoved.length === 0 ? {} : { mcpServersRemoved: [...outcome.mcpServersRemoved] }),
|
|
473
|
+
lockfile: outcome.lockfile,
|
|
474
|
+
...(outcome.migration === undefined ? {} : { migration: outcome.migration })
|
|
475
|
+
},
|
|
476
|
+
warnings: outcome.warnings !== undefined && outcome.warnings.length > 0 ? [...outcome.warnings] : undefined,
|
|
477
|
+
textRenderer: (d) => `Uninstalled ${d.bundle} from target "${d.target}" `
|
|
478
|
+
+ `(${d.removed.length} file${d.removed.length === 1 ? '' : 's'}`
|
|
479
|
+
+ `${d.mcpServersRemoved === undefined ? '' : ` and ${d.mcpServersRemoved.length} MCP server${d.mcpServersRemoved.length === 1 ? '' : 's'}`} removed). `
|
|
480
|
+
+ `Updated ${d.lockfile}.\n`
|
|
481
|
+
+ (0, framework_1.renderMigration)(outcome.migration)
|
|
482
|
+
+ (outcome.record === undefined ? '' : (0, framework_1.renderRecordLine)(outcome.record))
|
|
483
|
+
});
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
321
486
|
/**
|
|
322
487
|
* Perform uninstall by bundle ID.
|
|
323
488
|
* @param opts Uninstall options.
|
|
324
489
|
* @param target Target configuration.
|
|
325
490
|
* @param ctx CLI context.
|
|
326
491
|
* @param fmt Output format.
|
|
492
|
+
* @param typedTarget Whether `--target` was typed; only a plain uninstall removes a lone `unknown` entry.
|
|
493
|
+
* @param notes Tool-to-target mapping notes, for `warnings`.
|
|
327
494
|
* @returns Exit code.
|
|
328
495
|
*/
|
|
329
|
-
async function performBundleUninstall(opts, target, ctx, fmt) {
|
|
496
|
+
async function performBundleUninstall(opts, target, ctx, fmt, typedTarget, notes = []) {
|
|
330
497
|
const bundleId = opts.bundle;
|
|
331
|
-
|
|
498
|
+
// A RECORD.* error stops here with nothing removed; unrecorded bundles fall back to the old store.
|
|
499
|
+
const prepared = await (0, framework_1.prepareUninstallForTarget)(ctx, target, { dryRun: opts.dryRun });
|
|
500
|
+
if (prepared !== undefined) {
|
|
501
|
+
const recordedFiles = prepared.entries.get(bundleId);
|
|
502
|
+
if (recordedFiles !== undefined) {
|
|
503
|
+
return await performRecordBundleUninstall({ opts, target, ctx, fmt }, prepared, bundleId, recordedFiles, notes);
|
|
504
|
+
}
|
|
505
|
+
if (!typedTarget && prepared.loneUnknown?.has(bundleId) === true) {
|
|
506
|
+
return await performUnknownBundleUninstall({ opts, target, ctx, fmt }, prepared, bundleId);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
// The imported old user lockfile is not read at user level any more.
|
|
510
|
+
const entry = prepared?.ignoresOldStore === true ? null : await findBundleEntry(bundleId, target, opts, ctx);
|
|
332
511
|
if (entry === null) {
|
|
333
|
-
(0,
|
|
512
|
+
(0, framework_1.formatOutput)({
|
|
334
513
|
ctx,
|
|
335
514
|
command: 'uninstall',
|
|
336
515
|
output: fmt,
|
|
@@ -338,30 +517,17 @@ async function performBundleUninstall(opts, target, ctx, fmt) {
|
|
|
338
517
|
data: {
|
|
339
518
|
target: target.name,
|
|
340
519
|
bundle: bundleId,
|
|
341
|
-
reason: 'not found in lockfile'
|
|
520
|
+
reason: 'not found in lockfile',
|
|
521
|
+
...(prepared?.migration === undefined ? {} : { migration: prepared.migration })
|
|
342
522
|
},
|
|
343
523
|
textRenderer: (d) => `Bundle "${d.bundle}" is not installed in target "${d.target}". Nothing to uninstall.\n`
|
|
524
|
+
+ (0, framework_1.renderMigration)(d.migration)
|
|
344
525
|
});
|
|
345
526
|
return 0;
|
|
346
527
|
}
|
|
347
528
|
// Dry-run: show what would be removed without deleting
|
|
348
529
|
if (opts.dryRun === true) {
|
|
349
|
-
(
|
|
350
|
-
ctx,
|
|
351
|
-
command: 'uninstall',
|
|
352
|
-
output: fmt,
|
|
353
|
-
status: 'ok',
|
|
354
|
-
data: {
|
|
355
|
-
dryRun: true,
|
|
356
|
-
target: target.name,
|
|
357
|
-
bundle: bundleId,
|
|
358
|
-
files: entry.files.map((f) => f.path)
|
|
359
|
-
},
|
|
360
|
-
textRenderer: (d) => `[dry-run] Would uninstall bundle "${d.bundle}" from target "${d.target}":\n`
|
|
361
|
-
+ ` Files: ${d.files.join(', ')}\n`
|
|
362
|
-
+ 'Run without --dry-run to apply.\n'
|
|
363
|
-
});
|
|
364
|
-
return 0;
|
|
530
|
+
return renderBundleDryRun(ctx, fmt, target, bundleId, entry.files.map((f) => f.path));
|
|
365
531
|
}
|
|
366
532
|
const writerFactory = (0, exports.createWriterFactory)(ctx, opts);
|
|
367
533
|
let result;
|
|
@@ -381,22 +547,170 @@ async function performBundleUninstall(opts, target, ctx, fmt) {
|
|
|
381
547
|
lockPath = (0, framework_1.lockfilePathForTarget)(ctx, target);
|
|
382
548
|
result = await runUserScopeUninstall(bundleId, lockPath, target, ctx, writerFactory(target));
|
|
383
549
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
550
|
+
return renderBundleUninstalled(ctx, fmt, target, { bundleId, removed: result.removed, lockfile: lockPath });
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The record file a real uninstall would change: the level's file holding the entry, else the prepared file.
|
|
554
|
+
* @param prepared The level's record files, loaded and checked.
|
|
555
|
+
* @param bundleId Bundle to uninstall.
|
|
556
|
+
*/
|
|
557
|
+
async function holdingRecordLocation(prepared, bundleId) {
|
|
558
|
+
return await prepared.service.holdingLocation(prepared.locations, bundleId, prepared.tool) ?? prepared.location;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Uninstall one bundle recorded in the repository install record for the target's type.
|
|
562
|
+
* @param run Options, target, context and output format.
|
|
563
|
+
* @param prepared Both record files, loaded and checked.
|
|
564
|
+
* @param bundleId Bundle to uninstall.
|
|
565
|
+
* @param recordedFiles Its recorded root-relative paths, for the dry run.
|
|
566
|
+
* @param notes Tool-to-target mapping notes, for `warnings`.
|
|
567
|
+
* @returns Exit code.
|
|
568
|
+
*/
|
|
569
|
+
async function performRecordBundleUninstall(run, prepared, bundleId, recordedFiles, notes = []) {
|
|
570
|
+
const { opts, target, ctx, fmt } = run;
|
|
571
|
+
// The tool keeps one entry per bundle, so an older key of the same bundle goes too.
|
|
572
|
+
const others = await (0, framework_1.otherKeysOfIdentity)(prepared, bundleId);
|
|
573
|
+
if (opts.dryRun === true) {
|
|
574
|
+
// The default rule may have picked the level, so the preview names the file.
|
|
575
|
+
const location = await holdingRecordLocation(prepared, bundleId);
|
|
576
|
+
const files = [...new Set([...recordedFiles, ...others.flatMap((key) => prepared.entries.get(key) ?? [])])];
|
|
577
|
+
return renderBundleDryRun(ctx, fmt, target, bundleId, files, {
|
|
578
|
+
warnings: notes,
|
|
579
|
+
record: { level: location.level, records: [location.path] }
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
const removed = [];
|
|
583
|
+
const mcpServersRemoved = [];
|
|
584
|
+
const warnings = [...notes];
|
|
585
|
+
for (const key of others) {
|
|
586
|
+
const older = await (0, framework_1.recordRepositoryUninstall)(prepared, key);
|
|
587
|
+
removed.push(...older.removed);
|
|
588
|
+
mcpServersRemoved.push(...older.mcpServersRemoved);
|
|
589
|
+
warnings.push(...older.warnings);
|
|
590
|
+
}
|
|
591
|
+
const recorded = await (0, framework_1.recordRepositoryUninstall)(prepared, bundleId);
|
|
592
|
+
removed.push(...recorded.removed);
|
|
593
|
+
mcpServersRemoved.push(...recorded.mcpServersRemoved);
|
|
594
|
+
warnings.push(...recorded.warnings);
|
|
595
|
+
return renderBundleUninstalled(ctx, fmt, target, {
|
|
596
|
+
bundleId,
|
|
597
|
+
removed,
|
|
598
|
+
mcpServersRemoved,
|
|
599
|
+
lockfile: recorded.lockfile,
|
|
600
|
+
warnings,
|
|
601
|
+
record: { level: prepared.location.level, records: [recorded.lockfile] },
|
|
602
|
+
...(prepared.migration === undefined ? {} : { migration: prepared.migration })
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Plain `uninstall <bundle>` of a bundle whose only entry is `unknown`: remove
|
|
607
|
+
* the entry and keep its files, because the tool that wrote them is not known.
|
|
608
|
+
* @param run Options, context, output format and the target, if any; without one the output names the record.
|
|
609
|
+
* @param prepared The level's record files, loaded and migrated.
|
|
610
|
+
* @param bundleId Bundle to uninstall.
|
|
611
|
+
* @returns Exit code.
|
|
612
|
+
*/
|
|
613
|
+
async function performUnknownBundleUninstall(run, prepared, bundleId) {
|
|
614
|
+
const { opts, target, ctx, fmt } = run;
|
|
615
|
+
const targetField = target === undefined ? {} : { target: target.name };
|
|
616
|
+
const keptNote = (count) => `${String(count)} file${count === 1 ? '' : 's'} kept because their tool is unknown`;
|
|
617
|
+
if (opts.dryRun === true) {
|
|
618
|
+
const recordFields = target === undefined ? { level: prepared.location.level, records: [prepared.location.path] } : undefined;
|
|
619
|
+
(0, framework_1.formatOutput)({
|
|
620
|
+
ctx,
|
|
621
|
+
command: 'uninstall',
|
|
622
|
+
output: fmt,
|
|
623
|
+
status: 'ok',
|
|
624
|
+
data: { dryRun: true, ...targetField, ...recordFields, bundle: bundleId, files: [] },
|
|
625
|
+
textRenderer: (d) => `[dry-run] Would remove the record entry of "${d.bundle}" (tool unknown); its files would be kept.\n`
|
|
626
|
+
+ 'Run without --dry-run to apply.\n'
|
|
627
|
+
+ (d.level === undefined ? '' : (0, framework_1.renderRecordLine)({ level: d.level, records: d.records ?? [] }))
|
|
628
|
+
});
|
|
629
|
+
return 0;
|
|
630
|
+
}
|
|
631
|
+
const recorded = await (0, framework_1.recordUnknownUninstall)(prepared, bundleId);
|
|
632
|
+
(0, framework_1.formatOutput)({
|
|
387
633
|
ctx,
|
|
388
634
|
command: 'uninstall',
|
|
389
635
|
output: fmt,
|
|
390
636
|
status: 'ok',
|
|
391
637
|
data: {
|
|
392
|
-
|
|
638
|
+
level: prepared.location.level,
|
|
639
|
+
records: [recorded.lockfile],
|
|
640
|
+
...targetField,
|
|
393
641
|
bundle: bundleId,
|
|
394
|
-
|
|
395
|
-
|
|
642
|
+
tool: 'unknown',
|
|
643
|
+
removed: recorded.removed,
|
|
644
|
+
kept: recorded.kept,
|
|
645
|
+
lockfile: recorded.lockfile,
|
|
646
|
+
...(prepared.migration === undefined ? {} : { migration: prepared.migration })
|
|
396
647
|
},
|
|
397
|
-
|
|
398
|
-
|
|
648
|
+
warnings: recorded.warnings.length > 0 ? recorded.warnings : undefined,
|
|
649
|
+
textRenderer: (d) => `Removed the record entry of ${d.bundle} (tool unknown); ${keptNote(d.kept.length)}. `
|
|
399
650
|
+ `Updated ${d.lockfile}.\n`
|
|
651
|
+
+ d.kept.map((file) => ` kept ${file}\n`).join('')
|
|
652
|
+
+ (0, framework_1.renderMigration)(d.migration)
|
|
653
|
+
+ (0, framework_1.renderRecordLine)({ level: d.level, records: d.records })
|
|
654
|
+
});
|
|
655
|
+
return 0;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* `uninstall --lockfile <record file>`: remove only the target tool's entries, keeping files another entry lists or that were edited since the install.
|
|
659
|
+
* @param run Options, target, context and output format.
|
|
660
|
+
* @param prepared The selected record file, loaded and checked.
|
|
661
|
+
* @returns Exit code.
|
|
662
|
+
* @throws {RegistryError} A `RECORD.*` error naming the file; `USAGE.INVALID_FLAG` when the target does not write to the record.
|
|
663
|
+
*/
|
|
664
|
+
async function performRecordLockfileUninstall(run, prepared) {
|
|
665
|
+
const { target, ctx, fmt, opts } = run;
|
|
666
|
+
const { selection, fs } = prepared;
|
|
667
|
+
const mapping = await (0, app_1.mapToolToTarget)({ fs, tool: target.type, level: selection.level, gitRoot: selection.root, targets: [], explicit: target, cwd: ctx.cwd() });
|
|
668
|
+
if ('skip' in mapping) {
|
|
669
|
+
throw new framework_1.RegistryError({
|
|
670
|
+
code: 'USAGE.INVALID_FLAG',
|
|
671
|
+
message: `uninstall: ${mapping.skip}`,
|
|
672
|
+
hint: 'Pass a --target whose scope and repository match the record.'
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
// The user record keeps the files its old user lockfile lists; a repository file uses its git root's info/exclude, as the install did.
|
|
676
|
+
const uninstall = (selection.level === 'user' ? await (0, framework_1.prepareUninstallForTarget)(ctx, target) : undefined)
|
|
677
|
+
?? await (0, framework_1.prepareRepositoryUninstall)(ctx, target, { locations: selection.locations });
|
|
678
|
+
const { location, entries } = uninstall;
|
|
679
|
+
const fields = await (0, framework_1.recordOutputFields)(selection, fs);
|
|
680
|
+
const bundleIds = [...entries.keys()];
|
|
681
|
+
if (opts.dryRun === true) {
|
|
682
|
+
(0, framework_1.formatOutput)({
|
|
683
|
+
ctx,
|
|
684
|
+
command: 'uninstall',
|
|
685
|
+
output: fmt,
|
|
686
|
+
status: 'ok',
|
|
687
|
+
data: { dryRun: true, ...fields, lockfile: location.path, target: target.name, bundles: bundleIds, files: [...entries.values()].flat() },
|
|
688
|
+
textRenderer: (d) => `[dry-run] Would uninstall ${d.bundles.length} bundle${d.bundles.length === 1 ? '' : 's'} from target "${d.target}" (from ${d.lockfile}):\n`
|
|
689
|
+
+ ` Bundles: ${d.bundles.join(', ')}\n`
|
|
690
|
+
+ ` Files: ${d.files.length} total\n`
|
|
691
|
+
+ 'Run without --dry-run to apply.\n'
|
|
692
|
+
+ (0, framework_1.renderRecordLine)({ level: d.level, records: d.records })
|
|
693
|
+
});
|
|
694
|
+
return 0;
|
|
695
|
+
}
|
|
696
|
+
const results = [];
|
|
697
|
+
const warnings = [];
|
|
698
|
+
for (const bundleId of bundleIds) {
|
|
699
|
+
const recorded = await (0, framework_1.recordRepositoryUninstall)(uninstall, bundleId);
|
|
700
|
+
results.push({ id: bundleId, removed: recorded.removed.length });
|
|
701
|
+
warnings.push(...recorded.warnings);
|
|
702
|
+
}
|
|
703
|
+
(0, framework_1.formatOutput)({
|
|
704
|
+
ctx,
|
|
705
|
+
command: 'uninstall',
|
|
706
|
+
output: fmt,
|
|
707
|
+
status: 'ok',
|
|
708
|
+
data: { ...fields, lockfile: location.path, target: target.name, uninstalled: results.length, bundles: results },
|
|
709
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
710
|
+
textRenderer: (d) => (d.uninstalled === 0
|
|
711
|
+
? `No bundles found to uninstall from target "${d.target}".\n`
|
|
712
|
+
: `Uninstalled ${d.uninstalled} bundle${d.uninstalled === 1 ? '' : 's'} from target "${d.target}" (from ${d.lockfile}).\n`)
|
|
713
|
+
+ (0, framework_1.renderRecordLine)({ level: d.level, records: d.records })
|
|
400
714
|
});
|
|
401
715
|
return 0;
|
|
402
716
|
}
|
|
@@ -410,12 +724,17 @@ async function performBundleUninstall(opts, target, ctx, fmt) {
|
|
|
410
724
|
*/
|
|
411
725
|
async function performLockfileUninstall(opts, target, ctx, fmt) {
|
|
412
726
|
const lockfile = opts.lockfile;
|
|
727
|
+
// A record file is loaded and checked first; any other file keeps the old path.
|
|
728
|
+
const selected = await (0, framework_1.prepareRecordSelection)(ctx, { command: 'uninstall', lockfile }, target);
|
|
729
|
+
if (selected.selection.locations.length > 0) {
|
|
730
|
+
return performRecordLockfileUninstall({ opts, target, ctx, fmt }, selected);
|
|
731
|
+
}
|
|
413
732
|
const lockPath = path.isAbsolute(lockfile)
|
|
414
733
|
? lockfile
|
|
415
734
|
: path.join(ctx.cwd(), lockfile);
|
|
416
735
|
const lock = await (0, app_1.readLockfile)(lockPath, ctx.fs);
|
|
417
736
|
if (lock === null) {
|
|
418
|
-
(0,
|
|
737
|
+
(0, framework_1.formatOutput)({
|
|
419
738
|
ctx,
|
|
420
739
|
command: 'uninstall',
|
|
421
740
|
output: fmt,
|
|
@@ -429,7 +748,7 @@ async function performLockfileUninstall(opts, target, ctx, fmt) {
|
|
|
429
748
|
// Dry-run: show what would be removed without deleting
|
|
430
749
|
if (opts.dryRun === true) {
|
|
431
750
|
const allFiles = bundleIds.flatMap((id) => lock.bundles[id].files.map((f) => f.path));
|
|
432
|
-
(0,
|
|
751
|
+
(0, framework_1.formatOutput)({
|
|
433
752
|
ctx,
|
|
434
753
|
command: 'uninstall',
|
|
435
754
|
output: fmt,
|
|
@@ -463,7 +782,7 @@ async function performLockfileUninstall(opts, target, ctx, fmt) {
|
|
|
463
782
|
results = await runAllUserScopeUninstall(lockPath, target, ctx, writerFactory(target));
|
|
464
783
|
}
|
|
465
784
|
if (results.length === 0) {
|
|
466
|
-
(0,
|
|
785
|
+
(0, framework_1.formatOutput)({
|
|
467
786
|
ctx,
|
|
468
787
|
command: 'uninstall',
|
|
469
788
|
output: fmt,
|
|
@@ -477,7 +796,7 @@ async function performLockfileUninstall(opts, target, ctx, fmt) {
|
|
|
477
796
|
});
|
|
478
797
|
return 0;
|
|
479
798
|
}
|
|
480
|
-
(0,
|
|
799
|
+
(0, framework_1.formatOutput)({
|
|
481
800
|
ctx,
|
|
482
801
|
command: 'uninstall',
|
|
483
802
|
output: fmt,
|
|
@@ -502,12 +821,23 @@ async function performLockfileUninstall(opts, target, ctx, fmt) {
|
|
|
502
821
|
* @returns Exit code.
|
|
503
822
|
*/
|
|
504
823
|
async function performAllUninstall(opts, target, ctx, fmt) {
|
|
505
|
-
|
|
506
|
-
const
|
|
824
|
+
// A RECORD.* error stops here with nothing removed; the old store is handled afterwards.
|
|
825
|
+
const prepared = await (0, framework_1.prepareUninstallForTarget)(ctx, target, { dryRun: opts.dryRun });
|
|
826
|
+
const recordedIds = prepared === undefined ? [] : [...prepared.entries.keys()];
|
|
827
|
+
// Each id is handled and reported once, even when both stores list it.
|
|
828
|
+
const recordedSet = new Set(recordedIds);
|
|
829
|
+
const ignoresOldStore = prepared?.ignoresOldStore === true;
|
|
830
|
+
const entries = ignoresOldStore
|
|
831
|
+
? {}
|
|
832
|
+
: Object.fromEntries(Object.entries(await findAllBundleEntries(target, opts, ctx)).filter(([id]) => !recordedSet.has(id)));
|
|
833
|
+
const bundleIds = [...recordedIds, ...Object.keys(entries)];
|
|
507
834
|
// Dry-run: show what would be removed without deleting
|
|
508
835
|
if (opts.dryRun === true) {
|
|
509
|
-
const allFiles =
|
|
510
|
-
|
|
836
|
+
const allFiles = [
|
|
837
|
+
...recordedIds.flatMap((id) => prepared?.entries.get(id) ?? []),
|
|
838
|
+
...Object.values(entries).flatMap((entry) => entry.files.map((f) => f.path))
|
|
839
|
+
];
|
|
840
|
+
(0, framework_1.formatOutput)({
|
|
511
841
|
ctx,
|
|
512
842
|
command: 'uninstall',
|
|
513
843
|
output: fmt,
|
|
@@ -526,7 +856,13 @@ async function performAllUninstall(opts, target, ctx, fmt) {
|
|
|
526
856
|
return 0;
|
|
527
857
|
}
|
|
528
858
|
const writerFactory = (0, exports.createWriterFactory)(ctx, opts);
|
|
529
|
-
|
|
859
|
+
const results = [];
|
|
860
|
+
const warnings = [];
|
|
861
|
+
for (const bundleId of recordedIds) {
|
|
862
|
+
const recorded = await (0, framework_1.recordRepositoryUninstall)(prepared, bundleId);
|
|
863
|
+
results.push({ bundleId, removed: recorded.removed, skipped: [] });
|
|
864
|
+
warnings.push(...recorded.warnings);
|
|
865
|
+
}
|
|
530
866
|
if (target.scope === 'repository') {
|
|
531
867
|
const pipeline = new app_1.UninstallPipeline({
|
|
532
868
|
fs: ctx.fs,
|
|
@@ -534,37 +870,30 @@ async function performAllUninstall(opts, target, ctx, fmt) {
|
|
|
534
870
|
repositoryPath: target.rootPath ?? ctx.cwd(),
|
|
535
871
|
writerFactory
|
|
536
872
|
});
|
|
537
|
-
results
|
|
873
|
+
results.push(...await pipeline.runAll({ exclude: recordedSet }));
|
|
538
874
|
}
|
|
539
|
-
else {
|
|
875
|
+
else if (!ignoresOldStore) {
|
|
876
|
+
// Old user lockfile: bundles not uninstalled from the user record above.
|
|
540
877
|
const lockPath = (0, framework_1.lockfilePathForTarget)(ctx, target);
|
|
541
|
-
results
|
|
878
|
+
results.push(...await runAllUserScopeUninstall(lockPath, target, ctx, writerFactory(target), recordedSet));
|
|
542
879
|
}
|
|
543
880
|
if (results.length === 0) {
|
|
544
|
-
(0,
|
|
881
|
+
(0, framework_1.formatOutput)({
|
|
545
882
|
ctx,
|
|
546
883
|
command: 'uninstall',
|
|
547
884
|
output: fmt,
|
|
548
885
|
status: 'ok',
|
|
549
886
|
data: {
|
|
550
887
|
target: target.name,
|
|
551
|
-
uninstalled: 0
|
|
888
|
+
uninstalled: 0,
|
|
889
|
+
...(prepared?.migration === undefined ? {} : { migration: prepared.migration })
|
|
552
890
|
},
|
|
553
891
|
textRenderer: (d) => `No bundles installed in target "${d.target}". Nothing to uninstall.\n`
|
|
892
|
+
+ (0, framework_1.renderMigration)(d.migration)
|
|
554
893
|
});
|
|
555
894
|
return 0;
|
|
556
895
|
}
|
|
557
|
-
|
|
558
|
-
const stateStore = new infra_1.TargetStateStore({
|
|
559
|
-
fs: ctx.fs,
|
|
560
|
-
statePath: path.join(ctx.cwd(), '.ai-primitives-hub', 'target-state.json')
|
|
561
|
-
});
|
|
562
|
-
await stateStore.save({
|
|
563
|
-
targetName: target.name,
|
|
564
|
-
lastInstalledBundles: [],
|
|
565
|
-
lastUsedAt: new Date().toISOString()
|
|
566
|
-
});
|
|
567
|
-
(0, framework_2.formatOutput)({
|
|
896
|
+
(0, framework_1.formatOutput)({
|
|
568
897
|
ctx,
|
|
569
898
|
command: 'uninstall',
|
|
570
899
|
output: fmt,
|
|
@@ -572,77 +901,14 @@ async function performAllUninstall(opts, target, ctx, fmt) {
|
|
|
572
901
|
data: {
|
|
573
902
|
target: target.name,
|
|
574
903
|
uninstalled: results.length,
|
|
575
|
-
bundles: results.map((r) => ({ id: r.bundleId, removed: r.removed.length }))
|
|
904
|
+
bundles: results.map((r) => ({ id: r.bundleId, removed: r.removed.length })),
|
|
905
|
+
...(prepared?.migration === undefined ? {} : { migration: prepared.migration })
|
|
576
906
|
},
|
|
907
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
577
908
|
textRenderer: (d) => `Uninstalled ${d.uninstalled} bundle${d.uninstalled === 1 ? '' : 's'} `
|
|
578
909
|
+ `from target "${d.target}".\n`
|
|
910
|
+
+ (0, framework_1.renderMigration)(d.migration)
|
|
579
911
|
});
|
|
580
912
|
return 0;
|
|
581
913
|
}
|
|
582
|
-
/**
|
|
583
|
-
* Update target state by removing bundle.
|
|
584
|
-
* @param ctx CLI context.
|
|
585
|
-
* @param targetName Target name.
|
|
586
|
-
* @param bundleId Bundle ID to remove.
|
|
587
|
-
*/
|
|
588
|
-
async function updateTargetState(ctx, targetName, bundleId) {
|
|
589
|
-
const stateStore = new infra_1.TargetStateStore({
|
|
590
|
-
fs: ctx.fs,
|
|
591
|
-
statePath: path.join(ctx.cwd(), '.ai-primitives-hub', 'target-state.json')
|
|
592
|
-
});
|
|
593
|
-
const existingState = await stateStore.load(targetName);
|
|
594
|
-
const newBundles = existingState?.lastInstalledBundles ?? [];
|
|
595
|
-
const bundleIndex = newBundles.findIndex((b) => b.bundleId === bundleId);
|
|
596
|
-
if (bundleIndex !== -1) {
|
|
597
|
-
newBundles.splice(bundleIndex, 1);
|
|
598
|
-
}
|
|
599
|
-
await stateStore.save({
|
|
600
|
-
targetName,
|
|
601
|
-
lastInstalledBundles: newBundles,
|
|
602
|
-
lastUsedAt: new Date().toISOString()
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* Build the `uninstall` command.
|
|
607
|
-
* @param opts - Command options.
|
|
608
|
-
* @returns CommandDefinition wired to the framework adapter.
|
|
609
|
-
*/
|
|
610
|
-
const createUninstallCommand = (opts = {}) => (0, framework_2.defineCommand)({
|
|
611
|
-
path: ['uninstall'],
|
|
612
|
-
description: 'Remove bundles from a configured target.',
|
|
613
|
-
category: 'Install & Manage',
|
|
614
|
-
run: async ({ ctx }) => {
|
|
615
|
-
const fmt = opts.output ?? 'text';
|
|
616
|
-
const { bundle: noBundle, lockfile: noLockfile, all: noAll } = (0, framework_2.validateInputs)(opts, { flags: ['bundle', 'lockfile', 'all'] });
|
|
617
|
-
if (noBundle && noLockfile && noAll) {
|
|
618
|
-
return (0, framework_1.failWith)(ctx, fmt, 'uninstall', new framework_2.RegistryError({
|
|
619
|
-
code: 'USAGE.MISSING_FLAG',
|
|
620
|
-
message: 'uninstall: provide <bundle-id>, --lockfile <path>, or --all',
|
|
621
|
-
hint: 'Examples:\n'
|
|
622
|
-
+ ' ai-primitives-hub uninstall <bundle-id> --target my-vscode\n'
|
|
623
|
-
+ ' ai-primitives-hub uninstall --lockfile prompt-registry.lock.json\n'
|
|
624
|
-
+ ' ai-primitives-hub uninstall --all --target my-vscode'
|
|
625
|
-
}));
|
|
626
|
-
}
|
|
627
|
-
try {
|
|
628
|
-
const targetName = await (0, framework_2.resolveTargetName)(opts.target, 'uninstall', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
629
|
-
const configuredTarget = await (0, framework_2.resolveTarget)(targetName, 'uninstall', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
630
|
-
const target = (0, framework_1.resolveEffectiveTarget)(ctx, configuredTarget, opts);
|
|
631
|
-
if (opts.all === true) {
|
|
632
|
-
return await performAllUninstall(opts, target, ctx, fmt);
|
|
633
|
-
}
|
|
634
|
-
if (opts.lockfile !== undefined && opts.lockfile.length > 0) {
|
|
635
|
-
return await performLockfileUninstall(opts, target, ctx, fmt);
|
|
636
|
-
}
|
|
637
|
-
return await performBundleUninstall(opts, target, ctx, fmt);
|
|
638
|
-
}
|
|
639
|
-
catch (err) {
|
|
640
|
-
if (err instanceof framework_2.RegistryError) {
|
|
641
|
-
return (0, framework_1.failWith)(ctx, fmt, 'uninstall', err);
|
|
642
|
-
}
|
|
643
|
-
throw err;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
exports.createUninstallCommand = createUninstallCommand;
|
|
648
914
|
//# sourceMappingURL=uninstall.js.map
|