@ai-primitives-hub/cli 0.2.1 → 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 +94 -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/package.json +6 -4
package/dist/commands/install.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.createWriterFactory = exports.InstallCommand = void 0;
|
|
37
37
|
exports.createSourceAwareInstallDependencyCache = createSourceAwareInstallDependencyCache;
|
|
38
38
|
exports.githubApiFor = githubApiFor;
|
|
39
39
|
exports.installBundleWithSource = installBundleWithSource;
|
|
@@ -61,7 +61,6 @@ const app_1 = require("@ai-primitives-hub/app");
|
|
|
61
61
|
const core_1 = require("@ai-primitives-hub/core");
|
|
62
62
|
const infra_1 = require("@ai-primitives-hub/infra");
|
|
63
63
|
const framework_1 = require("../framework");
|
|
64
|
-
const framework_2 = require("../framework");
|
|
65
64
|
/**
|
|
66
65
|
* Extract repo slug from a GitHub URL.
|
|
67
66
|
* @param url GitHub URL (e.g., "https://github.com/owner/repo" or "owner/repo").
|
|
@@ -167,6 +166,30 @@ function githubApiFor(http, tokens, repositoryTarget, authenticationCategory) {
|
|
|
167
166
|
authenticationCategory
|
|
168
167
|
});
|
|
169
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Text listing the content a partial install skipped, appended to the
|
|
171
|
+
* install summary. Empty when nothing was skipped.
|
|
172
|
+
* @param skipped Skipped content.
|
|
173
|
+
* @returns The `Skipped:` block, or an empty string.
|
|
174
|
+
*/
|
|
175
|
+
const renderSkipped = (skipped) => skipped.length === 0
|
|
176
|
+
? ''
|
|
177
|
+
: 'Skipped:\n' + skipped.map((s) => ` - ${s.path}: ${s.reason}\n`).join('');
|
|
178
|
+
/**
|
|
179
|
+
* Output warnings for the content a partial install skipped.
|
|
180
|
+
* @param skipped Skipped content.
|
|
181
|
+
* @returns One warning per skipped item, or `undefined` when none.
|
|
182
|
+
*/
|
|
183
|
+
const skippedWarnings = (skipped) => skipped.length === 0 ? undefined : skipped.map((s) => `skipped ${s.path}: ${s.reason}`);
|
|
184
|
+
/**
|
|
185
|
+
* Skipped-content warnings, then install-record warnings; `undefined` when there are none.
|
|
186
|
+
* @param skipped Skipped content.
|
|
187
|
+
* @param recordWarnings Warnings from the install record.
|
|
188
|
+
*/
|
|
189
|
+
const installWarnings = (skipped, recordWarnings) => {
|
|
190
|
+
const all = [...(skippedWarnings(skipped) ?? []), ...recordWarnings];
|
|
191
|
+
return all.length === 0 ? undefined : all;
|
|
192
|
+
};
|
|
170
193
|
/**
|
|
171
194
|
* Base class for install/uninstall commands.
|
|
172
195
|
*/
|
|
@@ -194,12 +217,13 @@ class InstallCommand extends BaseInstallCommand {
|
|
|
194
217
|
--dry-run Validate and plan without writing
|
|
195
218
|
--scope <scope> Installation scope (user or repository)
|
|
196
219
|
--commit-mode <mode> Commit mode for repository scope
|
|
220
|
+
--skip-unsupported Install the supported items and list the rest instead of failing
|
|
197
221
|
--verbose Show detailed progress and error messages
|
|
198
222
|
-o, --output <format> Output format (text, json, yaml, ndjson)
|
|
199
223
|
|
|
200
224
|
Examples:
|
|
201
225
|
ai-primitives-hub install --from <path> --target my-vscode
|
|
202
|
-
ai-primitives-hub install --lockfile
|
|
226
|
+
ai-primitives-hub install --lockfile ai-primitives-hub.lock.json --target my-vscode
|
|
203
227
|
ai-primitives-hub install --source amadeus-hub --interactive --target my-vscode
|
|
204
228
|
`
|
|
205
229
|
});
|
|
@@ -213,6 +237,7 @@ class InstallCommand extends BaseInstallCommand {
|
|
|
213
237
|
scope = framework_1.Option.String('--scope');
|
|
214
238
|
commitMode = framework_1.Option.String('--commit-mode');
|
|
215
239
|
verbose = framework_1.Option.Boolean('--verbose', false);
|
|
240
|
+
skipUnsupported = framework_1.Option.Boolean('--skip-unsupported', false);
|
|
216
241
|
allowTarget = framework_1.Option.String('--allow-target');
|
|
217
242
|
bundle = framework_1.Option.String({ required: false }); // Optional positional argument
|
|
218
243
|
async execute() {
|
|
@@ -234,33 +259,56 @@ class InstallCommand extends BaseInstallCommand {
|
|
|
234
259
|
tokens,
|
|
235
260
|
scope: this.scope,
|
|
236
261
|
commitMode: this.commitMode,
|
|
237
|
-
verbose: this.verbose
|
|
262
|
+
verbose: this.verbose,
|
|
263
|
+
skipUnsupported: this.skipUnsupported
|
|
238
264
|
};
|
|
239
|
-
|
|
240
|
-
|
|
265
|
+
const typedTarget = opts.target !== undefined && opts.target.length > 0;
|
|
266
|
+
let recordReplay;
|
|
267
|
+
try {
|
|
268
|
+
recordReplay = await detectInstallContext(opts, ctx);
|
|
269
|
+
if (recordReplay !== undefined) {
|
|
270
|
+
// Each recorded tool maps to its own target; only a typed --target narrows the replay.
|
|
271
|
+
let explicit;
|
|
272
|
+
if (typedTarget) {
|
|
273
|
+
checkAllowTarget(opts.target, opts);
|
|
274
|
+
explicit = await (0, framework_1.resolveCommandTarget)(ctx, 'install', opts.target, opts);
|
|
275
|
+
}
|
|
276
|
+
return await performRecordReplay({ ctx, fmt, opts, prepared: recordReplay, explicit });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
if (err instanceof framework_1.RegistryError) {
|
|
281
|
+
return (0, framework_1.failWith)(ctx, fmt, 'install', err);
|
|
282
|
+
}
|
|
283
|
+
throw err;
|
|
284
|
+
}
|
|
285
|
+
const { bundle: noBundle, lockfile: noLockfile } = (0, framework_1.validateInputs)(opts, { flags: ['bundle', 'lockfile'] });
|
|
241
286
|
if (noBundle && noLockfile && !opts.from && !opts.source) {
|
|
242
|
-
return (0, framework_1.failWith)(ctx, fmt, 'install', new
|
|
287
|
+
return (0, framework_1.failWith)(ctx, fmt, 'install', new framework_1.RegistryError({
|
|
243
288
|
code: 'USAGE.MISSING_FLAG',
|
|
244
289
|
message: 'install: provide either <bundle-id> (imperative), --lockfile <path> (declarative), --from <path> (local directory), or --source <hub-id> (list bundles)',
|
|
245
290
|
hint: 'Examples:\n'
|
|
246
291
|
+ ' ai-primitives-hub install --from <path> --target my-vscode\n'
|
|
247
|
-
+ ' ai-primitives-hub install --lockfile
|
|
292
|
+
+ ' ai-primitives-hub install --lockfile ai-primitives-hub.lock.json\n'
|
|
248
293
|
+ ' ai-primitives-hub install --source amadeus-hub --target my-vscode'
|
|
249
294
|
}));
|
|
250
295
|
}
|
|
251
296
|
try {
|
|
252
|
-
const targetName = await (0,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
297
|
+
const targetName = await (0, framework_1.inferTargetName)(ctx, opts.target);
|
|
298
|
+
if (targetName !== undefined) {
|
|
299
|
+
checkAllowTarget(targetName, opts);
|
|
300
|
+
}
|
|
301
|
+
const target = await (0, framework_1.resolveCommandTarget)(ctx, 'install', targetName, opts);
|
|
302
|
+
// The modes report the target they ran with, typed or inferred.
|
|
303
|
+
const runOpts = { ...opts, target: targetName };
|
|
304
|
+
const mode = determineInstallMode(runOpts);
|
|
257
305
|
if (mode === undefined) {
|
|
258
|
-
return await performRemoteInstall(
|
|
306
|
+
return await performRemoteInstall(runOpts, target, ctx, fmt);
|
|
259
307
|
}
|
|
260
|
-
return await executeInstallMode(mode,
|
|
308
|
+
return await executeInstallMode(mode, runOpts, target, ctx, fmt);
|
|
261
309
|
}
|
|
262
310
|
catch (err) {
|
|
263
|
-
if (err instanceof
|
|
311
|
+
if (err instanceof framework_1.RegistryError) {
|
|
264
312
|
return (0, framework_1.failWith)(ctx, fmt, 'install', err);
|
|
265
313
|
}
|
|
266
314
|
throw err;
|
|
@@ -274,7 +322,7 @@ exports.InstallCommand = InstallCommand;
|
|
|
274
322
|
* @returns Installation mode.
|
|
275
323
|
*/
|
|
276
324
|
function determineInstallMode(opts) {
|
|
277
|
-
const { bundle: noBundle } = (0,
|
|
325
|
+
const { bundle: noBundle } = (0, framework_1.validateInputs)(opts, { flags: ['bundle', 'lockfile'] });
|
|
278
326
|
if (opts.source !== undefined && opts.source.length > 0 && noBundle) {
|
|
279
327
|
return opts.interactive ? 'interactive' : 'list';
|
|
280
328
|
}
|
|
@@ -301,19 +349,53 @@ async function autoDetectHubSource(opts, ctx, userPaths) {
|
|
|
301
349
|
opts.interactive = true;
|
|
302
350
|
}
|
|
303
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Refuse `--dry-run` for a record replay, which migrates and writes.
|
|
354
|
+
* @param opts Install options.
|
|
355
|
+
* @throws {RegistryError} `USAGE.INVALID_FLAG` when `--dry-run` is set.
|
|
356
|
+
*/
|
|
357
|
+
function refuseDryRunReplay(opts) {
|
|
358
|
+
if (opts.dryRun === true) {
|
|
359
|
+
throw new framework_1.RegistryError({
|
|
360
|
+
code: 'USAGE.INVALID_FLAG',
|
|
361
|
+
message: 'install: --dry-run cannot be used to replay an install record; a replay migrates older records and writes every recorded bundle',
|
|
362
|
+
hint: 'Run `status` to see what is recorded, or install one bundle with install <bundle-id> --dry-run.'
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
304
366
|
/**
|
|
305
367
|
* Detect install context from the project environment.
|
|
306
|
-
* Fills in `opts.lockfile`, `opts.source
|
|
307
|
-
*
|
|
368
|
+
* Fills in `opts.lockfile`, `opts.source` and `opts.interactive` when they can
|
|
369
|
+
* be inferred without user input; the target is inferred later. A bare `install`
|
|
370
|
+
* that finds a record or an old `prompt-registry` file at the git root replays it,
|
|
371
|
+
* migrating the old file first.
|
|
308
372
|
* @param opts Install options (mutated in-place).
|
|
309
373
|
* @param ctx CLI context.
|
|
374
|
+
* @returns The selected record to replay, or `undefined` for the other modes.
|
|
375
|
+
* @throws {RegistryError} A `RECORD.*` error naming the file; nothing was written.
|
|
310
376
|
*/
|
|
311
377
|
async function detectInstallContext(opts, ctx) {
|
|
312
|
-
const { bundle: noBundle, lockfile: noLockfile } = (0,
|
|
378
|
+
const { bundle: noBundle, lockfile: noLockfile } = (0, framework_1.validateInputs)(opts, { flags: ['bundle', 'lockfile'] });
|
|
313
379
|
const noExplicitSource = !opts.source || opts.source.length === 0;
|
|
314
380
|
const noMode = noBundle && noLockfile && !opts.from && noExplicitSource;
|
|
315
381
|
const userPaths = (0, app_1.resolveUserConfigPaths)(ctx.env);
|
|
382
|
+
if (!noLockfile && noBundle && !opts.from) {
|
|
383
|
+
const prepared = await (0, framework_1.prepareRecordSelection)(ctx, { command: 'install', lockfile: opts.lockfile });
|
|
384
|
+
if (prepared.selection.locations.length > 0) {
|
|
385
|
+
// The replay changes the record: migrate its level first.
|
|
386
|
+
refuseDryRunReplay(opts);
|
|
387
|
+
return (0, framework_1.prepareRecordSelection)(ctx, { command: 'install', lockfile: opts.lockfile, write: true });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
316
390
|
if (noMode && !opts.interactive) {
|
|
391
|
+
const prepared = await (0, framework_1.prepareRecordSelection)(ctx, { command: 'install', scope: opts.scope });
|
|
392
|
+
const { selection } = prepared;
|
|
393
|
+
// An old file at the git root is migrated first, then the record is replayed.
|
|
394
|
+
const migratesOldFile = selection.level === 'repository' && selection.oldLockfile !== undefined;
|
|
395
|
+
if (migratesOldFile || (await prepared.service.listEntries(selection.locations)).length > 0) {
|
|
396
|
+
refuseDryRunReplay(opts);
|
|
397
|
+
return (0, framework_1.prepareRecordSelection)(ctx, { command: 'install', scope: opts.scope, write: true });
|
|
398
|
+
}
|
|
317
399
|
const found = await (0, framework_1.findProjectLockfile)(ctx);
|
|
318
400
|
if (found !== null) {
|
|
319
401
|
opts.lockfile = found;
|
|
@@ -327,12 +409,7 @@ async function detectInstallContext(opts, ctx) {
|
|
|
327
409
|
// Ignore errors; proceed without auto-detected hub
|
|
328
410
|
}
|
|
329
411
|
}
|
|
330
|
-
|
|
331
|
-
const targets = await (0, framework_2.readTargetsSafely)((0, framework_1.loadTargets)(ctx));
|
|
332
|
-
if (targets.length === 1) {
|
|
333
|
-
opts.target = targets[0].name;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
412
|
+
return undefined;
|
|
336
413
|
}
|
|
337
414
|
/**
|
|
338
415
|
* Execute installation based on determined mode.
|
|
@@ -397,7 +474,7 @@ async function resolveRemoteSourceOption(opts, ctx) {
|
|
|
397
474
|
// `owner/repo` (or a URL): keep the historical GitHub-slug behavior.
|
|
398
475
|
return opts;
|
|
399
476
|
}
|
|
400
|
-
throw new
|
|
477
|
+
throw new framework_1.RegistryError({
|
|
401
478
|
code: 'BUNDLE.NOT_FOUND',
|
|
402
479
|
message: `install: --source "${value}" matched no source id in the active hub, no hub id, and is not a GitHub owner/repo`,
|
|
403
480
|
hint: 'Run `ai-primitives-hub source list` or `ai-primitives-hub hub list` to see valid ids, or pass --source <owner/repo>.',
|
|
@@ -425,6 +502,19 @@ async function lookupHubSource(opts, ctx, value, bundleId) {
|
|
|
425
502
|
throw err;
|
|
426
503
|
}
|
|
427
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Persist an install in the repository install record when one was prepared, otherwise in the old lockfile.
|
|
507
|
+
* @param prepared The prepared record, or `undefined` for the old lockfile.
|
|
508
|
+
* @param record What the install record gets.
|
|
509
|
+
* @param legacy Writes the old lockfile entry and returns its path.
|
|
510
|
+
*/
|
|
511
|
+
const persistInstall = async (prepared, record, legacy) => {
|
|
512
|
+
if (prepared === undefined) {
|
|
513
|
+
return { lockPath: await legacy(), warnings: [] };
|
|
514
|
+
}
|
|
515
|
+
const recorded = await (0, framework_1.recordRepositoryInstall)(prepared, record);
|
|
516
|
+
return { lockPath: recorded.lockfile, warnings: recorded.warnings };
|
|
517
|
+
};
|
|
428
518
|
/**
|
|
429
519
|
* Create a writer factory that routes to the appropriate
|
|
430
520
|
* writer based on target scope.
|
|
@@ -432,18 +522,15 @@ async function lookupHubSource(opts, ctx, value, bundleId) {
|
|
|
432
522
|
* - repository scope → RepositoryScopeWriter
|
|
433
523
|
* @param ctx CLI context.
|
|
434
524
|
* @param opts Install options.
|
|
525
|
+
* @param exclusion Where a `local-only` repository install lists its files; defaults to `<workspace>/.git/info/exclude`.
|
|
435
526
|
* @returns Writer factory function.
|
|
436
527
|
*/
|
|
437
|
-
const createWriterFactory = (ctx, opts) => {
|
|
528
|
+
const createWriterFactory = (ctx, opts, exclusion) => {
|
|
438
529
|
// Create transformer registry and hierarchical layout loader once per command.
|
|
439
530
|
const transformerRegistry = app_1.TransformerRegistry.withBuiltIns();
|
|
440
|
-
const layoutLoader =
|
|
441
|
-
cwd: ctx.cwd(),
|
|
442
|
-
fs: ctx.fs,
|
|
443
|
-
userConfigDir: (0, infra_1.resolveUserConfigDir)(ctx.env)
|
|
444
|
-
});
|
|
531
|
+
const layoutLoader = (0, framework_1.createLayoutLoader)(ctx);
|
|
445
532
|
return (target) => {
|
|
446
|
-
const effectiveTarget = (0,
|
|
533
|
+
const effectiveTarget = (0, framework_1.resolveEffectiveTarget)(ctx, target, opts);
|
|
447
534
|
const scope = effectiveTarget.scope;
|
|
448
535
|
const commitMode = effectiveTarget.commitMode ?? 'commit';
|
|
449
536
|
const workspaceRoot = effectiveTarget.rootPath ?? ctx.cwd();
|
|
@@ -455,14 +542,15 @@ const createWriterFactory = (ctx, opts) => {
|
|
|
455
542
|
const writer = new infra_1.RepositoryScopeWriter({
|
|
456
543
|
fs: ctx.fs,
|
|
457
544
|
workspaceRoot,
|
|
458
|
-
commitMode
|
|
545
|
+
commitMode,
|
|
546
|
+
exclusion
|
|
459
547
|
});
|
|
460
548
|
return new infra_1.RepositoryScopeWriterAdapter(writer);
|
|
461
549
|
}
|
|
462
550
|
const transformer = transformerRegistry.getTransformer(effectiveTarget.type);
|
|
463
551
|
return new app_1.FileTreeTargetWriter({
|
|
464
552
|
fs: ctx.fs,
|
|
465
|
-
env: ctx.env,
|
|
553
|
+
env: (0, framework_1.writerEnv)(ctx.env, scope),
|
|
466
554
|
transformer,
|
|
467
555
|
layoutLoader
|
|
468
556
|
});
|
|
@@ -486,7 +574,7 @@ async function listSourceBundles(opts, ctx, fmt) {
|
|
|
486
574
|
return active;
|
|
487
575
|
}
|
|
488
576
|
const bundles = active.config.profiles.flatMap((p) => p.bundles);
|
|
489
|
-
(0,
|
|
577
|
+
(0, framework_1.formatOutput)({
|
|
490
578
|
ctx,
|
|
491
579
|
command: 'install',
|
|
492
580
|
output: fmt,
|
|
@@ -502,21 +590,33 @@ async function listSourceBundles(opts, ctx, fmt) {
|
|
|
502
590
|
return 0;
|
|
503
591
|
}
|
|
504
592
|
catch (err) {
|
|
505
|
-
if (err instanceof
|
|
593
|
+
if (err instanceof framework_1.RegistryError) {
|
|
506
594
|
return (0, framework_1.failWith)(ctx, fmt, 'install', err);
|
|
507
595
|
}
|
|
508
|
-
return (0, framework_1.failWith)(ctx, fmt, 'install', new
|
|
596
|
+
return (0, framework_1.failWith)(ctx, fmt, 'install', new framework_1.RegistryError({
|
|
509
597
|
code: 'HUB.LOAD_FAILED',
|
|
510
598
|
message: `Failed to load hub "${hubId}": ${err instanceof Error ? err.message : String(err)}`,
|
|
511
599
|
cause: err instanceof Error ? err : undefined
|
|
512
600
|
}));
|
|
513
601
|
}
|
|
514
602
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
603
|
+
/**
|
|
604
|
+
* The error an interactive install from a hub reports: a `RegistryError`
|
|
605
|
+
* as thrown, anything else wrapped with the hub it was installing from.
|
|
606
|
+
* @param hubId Hub the bundles were being selected from.
|
|
607
|
+
* @param err What the interactive install threw.
|
|
608
|
+
* @returns The error to report.
|
|
609
|
+
*/
|
|
610
|
+
function buildInstallError(hubId, err) {
|
|
611
|
+
if (err instanceof framework_1.RegistryError) {
|
|
612
|
+
return err;
|
|
613
|
+
}
|
|
614
|
+
return new framework_1.RegistryError({
|
|
615
|
+
code: 'HUB.INSTALL_FAILED',
|
|
616
|
+
message: `install: interactive install from hub "${hubId}" failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
617
|
+
hint: 'Check the hub id (`ai-primitives-hub hub list`) and the hub configuration, then try again.',
|
|
618
|
+
context: { hubId },
|
|
619
|
+
cause: err instanceof Error ? err : undefined
|
|
520
620
|
});
|
|
521
621
|
}
|
|
522
622
|
/**
|
|
@@ -536,31 +636,45 @@ async function interactiveBundleSelection(opts, target, ctx, fmt) {
|
|
|
536
636
|
if (typeof active === 'number') {
|
|
537
637
|
return active;
|
|
538
638
|
}
|
|
539
|
-
|
|
639
|
+
// The active hub owns these sources.
|
|
640
|
+
const sourceMap = buildSourceMap(active.config.sources.map((source) => ({ ...source, hubId: active.id })));
|
|
540
641
|
const bundles = deduplicateBundles(active.config.profiles);
|
|
541
642
|
const bundleChoices = buildBundleChoices(bundles);
|
|
542
643
|
const selectedBundles = await promptBundleSelection(bundleChoices, bundles);
|
|
543
644
|
if (selectedBundles.length === 0) {
|
|
544
645
|
return 0;
|
|
545
646
|
}
|
|
546
|
-
previewInstallation(selectedBundles, target.name, ctx);
|
|
647
|
+
previewInstallation(selectedBundles, target.name, ctx, fmt);
|
|
547
648
|
const confirmed = await confirmInstallation(ctx);
|
|
548
649
|
if (!confirmed) {
|
|
549
650
|
return 0;
|
|
550
651
|
}
|
|
551
|
-
const
|
|
552
|
-
(
|
|
652
|
+
const { installed, failures } = await installSelectedBundles(selectedBundles, sourceMap, opts, target, ctx, fmt);
|
|
653
|
+
const failureLines = failures.map((f) => `${f.bundleId}: ${f.reason}`);
|
|
654
|
+
if (installed.length === 0 && failures.length > 0) {
|
|
655
|
+
return (0, framework_1.failWith)(ctx, fmt, 'install', new framework_1.RegistryError({
|
|
656
|
+
code: 'HUB.INSTALL_FAILED',
|
|
657
|
+
message: `install: none of the selected bundles from hub "${hubId}" could be installed: ${failureLines.join('; ')}`,
|
|
658
|
+
hint: 'Check that each bundle\'s source is configured, reachable, and authenticated, then try again.',
|
|
659
|
+
context: { hubId, failures }
|
|
660
|
+
}));
|
|
661
|
+
}
|
|
662
|
+
(0, framework_1.formatOutput)({
|
|
553
663
|
ctx,
|
|
554
664
|
command: 'install',
|
|
555
665
|
output: fmt,
|
|
556
|
-
status: 'ok',
|
|
557
|
-
data: { installed:
|
|
666
|
+
status: failures.length === 0 ? 'ok' : 'warning',
|
|
667
|
+
data: { installed: installed.length, total: selectedBundles.length, bundles: installed, failures },
|
|
668
|
+
warnings: failures.length > 0 ? failureLines : undefined,
|
|
558
669
|
textRenderer: (d) => `Installed ${d.installed}/${d.total} bundles\n`
|
|
670
|
+
+ (d.failures.length > 0
|
|
671
|
+
? `Failures:\n${d.failures.map((f) => ` - ${f.bundleId}: ${f.reason}\n`).join('')}`
|
|
672
|
+
: '')
|
|
559
673
|
});
|
|
560
|
-
return 0;
|
|
674
|
+
return failures.length === 0 ? 0 : 1;
|
|
561
675
|
}
|
|
562
676
|
catch (err) {
|
|
563
|
-
return (0, framework_1.failWith)(ctx, fmt, 'install', buildInstallError(err));
|
|
677
|
+
return (0, framework_1.failWith)(ctx, fmt, 'install', buildInstallError(hubId, err));
|
|
564
678
|
}
|
|
565
679
|
}
|
|
566
680
|
function buildSourceMap(sources) {
|
|
@@ -604,10 +718,12 @@ async function promptBundleSelection(bundleChoices, bundles) {
|
|
|
604
718
|
const selectedBundleIds = answers.selectedBundles;
|
|
605
719
|
return bundles.filter((b) => selectedBundleIds.includes(b.id));
|
|
606
720
|
}
|
|
607
|
-
function previewInstallation(bundles, targetName, ctx) {
|
|
608
|
-
|
|
721
|
+
function previewInstallation(bundles, targetName, ctx, fmt) {
|
|
722
|
+
// Keep stdout a single document for structured output; the preview still shows on stderr.
|
|
723
|
+
const out = fmt === 'text' ? ctx.stdout : ctx.stderr;
|
|
724
|
+
out.write(`\nPreview: Installing ${bundles.length} bundle${bundles.length === 1 ? '' : 's'} to target "${targetName}"\n`);
|
|
609
725
|
for (const b of bundles) {
|
|
610
|
-
|
|
726
|
+
out.write(` - ${b.id}@${b.version} (source: ${b.source})\n`);
|
|
611
727
|
}
|
|
612
728
|
}
|
|
613
729
|
async function confirmInstallation(ctx) {
|
|
@@ -626,35 +742,50 @@ async function confirmInstallation(ctx) {
|
|
|
626
742
|
}
|
|
627
743
|
return true;
|
|
628
744
|
}
|
|
745
|
+
/**
|
|
746
|
+
* Install the bundles picked in the interactive hub install, one by one.
|
|
747
|
+
* A failed bundle is recorded and the rest are still installed; nothing is
|
|
748
|
+
* printed per bundle, so the caller reports one summary.
|
|
749
|
+
* @param bundles Selected bundles.
|
|
750
|
+
* @param sourceMap Hub sources by id and name.
|
|
751
|
+
* @param opts Install options.
|
|
752
|
+
* @param target Target to install onto.
|
|
753
|
+
* @param ctx CLI context.
|
|
754
|
+
* @param fmt Output format.
|
|
755
|
+
* @returns The installed bundles with their version, and the failures with their reason.
|
|
756
|
+
*/
|
|
629
757
|
async function installSelectedBundles(bundles, sourceMap, opts, target, ctx, fmt) {
|
|
630
|
-
|
|
758
|
+
const installed = [];
|
|
759
|
+
const failures = [];
|
|
631
760
|
const sourceAwareDependencyCache = (0, infra_1.isGitHubAppAuthEnabled)(ctx.env)
|
|
632
761
|
? createSourceAwareInstallDependencyCache(opts.http ?? new infra_1.NodeHttpClient(), ctx)
|
|
633
762
|
: undefined;
|
|
634
763
|
for (const bundle of bundles) {
|
|
635
764
|
const source = sourceMap.get(bundle.source);
|
|
636
765
|
if (!source) {
|
|
637
|
-
|
|
766
|
+
failures.push({ bundleId: bundle.id, reason: `source "${bundle.source}" not found in hub` });
|
|
638
767
|
continue;
|
|
639
768
|
}
|
|
769
|
+
let version;
|
|
640
770
|
const bundleOpts = {
|
|
641
771
|
...opts,
|
|
642
772
|
bundle: bundle.id,
|
|
643
773
|
source: source.url,
|
|
644
774
|
sourceConfig: source,
|
|
645
|
-
sourceAwareDependencyCache
|
|
775
|
+
sourceAwareDependencyCache,
|
|
776
|
+
onInstalled: (result) => {
|
|
777
|
+
version = result.version;
|
|
778
|
+
}
|
|
646
779
|
};
|
|
647
780
|
try {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
installedCount++;
|
|
651
|
-
}
|
|
781
|
+
await performRemoteInstall(bundleOpts, target, ctx, fmt);
|
|
782
|
+
installed.push({ bundleId: bundle.id, version: version ?? bundle.version });
|
|
652
783
|
}
|
|
653
784
|
catch (err) {
|
|
654
|
-
|
|
785
|
+
failures.push({ bundleId: bundle.id, reason: err instanceof Error ? err.message : String(err) });
|
|
655
786
|
}
|
|
656
787
|
}
|
|
657
|
-
return
|
|
788
|
+
return { installed, failures };
|
|
658
789
|
}
|
|
659
790
|
/**
|
|
660
791
|
* Check if target is in allowlist.
|
|
@@ -667,7 +798,7 @@ function checkAllowTarget(targetName, opts) {
|
|
|
667
798
|
}
|
|
668
799
|
const allowSet = new Set(opts.allowTarget.split(',').map((s) => s.trim()).filter((s) => s.length > 0));
|
|
669
800
|
if (!allowSet.has(targetName)) {
|
|
670
|
-
throw new
|
|
801
|
+
throw new framework_1.RegistryError({
|
|
671
802
|
code: 'USAGE.MISSING_FLAG',
|
|
672
803
|
message: `install: target "${targetName}" is not in --allow-target=${opts.allowTarget}`,
|
|
673
804
|
hint: 'Add it to --allow-target or unset the flag to allow any configured target.',
|
|
@@ -685,7 +816,7 @@ function checkAllowTarget(targetName, opts) {
|
|
|
685
816
|
*/
|
|
686
817
|
async function performLocalInstall(opts, target, ctx, fmt) {
|
|
687
818
|
try {
|
|
688
|
-
const effectiveTarget = (0,
|
|
819
|
+
const effectiveTarget = (0, framework_1.resolveEffectiveTarget)(ctx, target, opts);
|
|
689
820
|
const files = await (0, infra_1.readLocalBundle)(opts.from, ctx.fs);
|
|
690
821
|
// No bundle id on the command line: accept the manifest id as-is.
|
|
691
822
|
const manifest = (0, core_1.validateManifest)(files, {
|
|
@@ -693,7 +824,7 @@ async function performLocalInstall(opts, target, ctx, fmt) {
|
|
|
693
824
|
expectedVersion: undefined
|
|
694
825
|
});
|
|
695
826
|
if (opts.dryRun === true) {
|
|
696
|
-
(0,
|
|
827
|
+
(0, framework_1.formatOutput)({
|
|
697
828
|
ctx,
|
|
698
829
|
command: 'install',
|
|
699
830
|
output: fmt,
|
|
@@ -709,57 +840,74 @@ async function performLocalInstall(opts, target, ctx, fmt) {
|
|
|
709
840
|
});
|
|
710
841
|
return 0;
|
|
711
842
|
}
|
|
712
|
-
|
|
843
|
+
// Check the record files before the writer runs, so a RECORD.* error writes nothing.
|
|
844
|
+
const prepared = await (0, framework_1.prepareRecordForTarget)(ctx, effectiveTarget);
|
|
845
|
+
const mcp = (0, framework_1.bundleMcpOf)(manifest, ctx.env);
|
|
846
|
+
await (0, framework_1.checkRepositoryInstallMcp)(prepared, { bundleId: manifest.id, version: manifest.version, tool: effectiveTarget.type, mcp });
|
|
847
|
+
const writerFactory = (0, exports.createWriterFactory)(ctx, opts, prepared?.exclusion);
|
|
713
848
|
const writer = writerFactory(effectiveTarget);
|
|
714
|
-
const { installableFiles: targetFiles, result } = await (0, app_1.
|
|
715
|
-
const scope = effectiveTarget.scope;
|
|
716
|
-
const commitMode = effectiveTarget.commitMode ?? 'commit';
|
|
717
|
-
const lockPath = (0, framework_1.lockfilePathForTarget)(ctx, effectiveTarget);
|
|
718
|
-
const existing = await (0, app_1.readLockfile)(lockPath, ctx.fs) ?? (0, app_1.emptyLockfile)('ai-primitives-hub-cli');
|
|
849
|
+
const { installableFiles: targetFiles, result, skipped } = await (0, app_1.writeBundleForInstall)(writer, effectiveTarget, files, manifest, { skipUnsupported: opts.skipUnsupported === true });
|
|
719
850
|
const localSourceId = `local-${path.basename(opts.from)}`;
|
|
720
|
-
const
|
|
851
|
+
const localSourceUrl = path.resolve(ctx.cwd(), opts.from);
|
|
852
|
+
const { lockPath, warnings } = await persistInstall(prepared, {
|
|
853
|
+
bundleId: manifest.id,
|
|
721
854
|
version: manifest.version,
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
855
|
+
tool: effectiveTarget.type,
|
|
856
|
+
source: { sourceId: localSourceId, type: 'local', url: localSourceUrl },
|
|
857
|
+
writtenPaths: result.written,
|
|
858
|
+
bundle: { name: manifest.id, files },
|
|
859
|
+
mcp
|
|
860
|
+
}, async () => {
|
|
861
|
+
const legacyLockPath = (0, framework_1.lockfilePathForTarget)(ctx, effectiveTarget);
|
|
862
|
+
const existing = await (0, app_1.readLockfile)(legacyLockPath, ctx.fs) ?? (0, app_1.emptyLockfile)('ai-primitives-hub-cli');
|
|
863
|
+
const entry = {
|
|
864
|
+
version: manifest.version,
|
|
865
|
+
sourceId: localSourceId,
|
|
866
|
+
sourceType: 'local',
|
|
867
|
+
installedAt: new Date().toISOString(),
|
|
868
|
+
files: (0, app_1.checksumFiles)(targetFiles, result.writtenBundlePaths ?? targetFiles.keys(), result.installedPaths)
|
|
869
|
+
};
|
|
870
|
+
const previousFiles = existing.bundles[manifest.id]?.files;
|
|
871
|
+
let nextLock = (0, app_1.upsertBundleEntry)(existing, manifest.id, entry);
|
|
872
|
+
nextLock = (0, app_1.upsertSource)(nextLock, localSourceId, {
|
|
873
|
+
type: 'local',
|
|
874
|
+
url: localSourceUrl
|
|
875
|
+
});
|
|
876
|
+
await (0, app_1.writeLockfile)(legacyLockPath, nextLock, ctx.fs);
|
|
877
|
+
await (0, app_1.removeSupersededFiles)(writer, effectiveTarget, previousFiles, entry.files);
|
|
878
|
+
return legacyLockPath;
|
|
735
879
|
});
|
|
736
|
-
|
|
737
|
-
await (0, app_1.removeSupersededFiles)(writer, effectiveTarget, previousFiles, entry.files);
|
|
738
|
-
await updateTargetState(ctx, effectiveTarget.name, manifest.id, manifest.version);
|
|
739
|
-
(0, framework_2.formatOutput)({
|
|
880
|
+
(0, framework_1.formatOutput)({
|
|
740
881
|
ctx,
|
|
741
882
|
command: 'install',
|
|
742
883
|
output: fmt,
|
|
743
|
-
status: 'ok',
|
|
884
|
+
status: skipped.length === 0 ? 'ok' : 'warning',
|
|
744
885
|
data: {
|
|
745
886
|
target: effectiveTarget.name,
|
|
746
887
|
bundle: { id: manifest.id, version: manifest.version },
|
|
747
888
|
written: result.written,
|
|
748
|
-
skipped
|
|
749
|
-
lockfile: lockPath
|
|
889
|
+
skipped,
|
|
890
|
+
lockfile: lockPath,
|
|
891
|
+
...(prepared?.migration === undefined ? {} : { migration: prepared.migration })
|
|
750
892
|
},
|
|
893
|
+
warnings: installWarnings(skipped, warnings),
|
|
751
894
|
textRenderer: (d) => `Installed ${d.bundle.id}@${d.bundle.version} into target "${d.target}" `
|
|
752
895
|
+ `(${d.written.length} written, ${d.skipped.length} skipped). `
|
|
753
896
|
+ `Updated ${d.lockfile}.\n`
|
|
897
|
+
+ renderSkipped(d.skipped)
|
|
898
|
+
+ (0, framework_1.renderMigration)(d.migration)
|
|
754
899
|
});
|
|
755
900
|
return 0;
|
|
756
901
|
}
|
|
757
902
|
catch (cause) {
|
|
903
|
+
if ((0, core_1.isRecordError)(cause)) {
|
|
904
|
+
throw cause;
|
|
905
|
+
}
|
|
758
906
|
const raw = cause.code;
|
|
759
907
|
const code = raw !== undefined && /^(BUNDLE|FS|NETWORK|USAGE|CONFIG)\.[A-Z0-9_]+$/.test(raw)
|
|
760
908
|
? raw
|
|
761
909
|
: 'INTERNAL.UNEXPECTED';
|
|
762
|
-
throw new
|
|
910
|
+
throw new framework_1.RegistryError({
|
|
763
911
|
code,
|
|
764
912
|
message: `install: ${cause.message}`,
|
|
765
913
|
hint: 'Run `ai-primitives-hub doctor` for environment diagnostics.',
|
|
@@ -777,7 +925,16 @@ async function performLocalInstall(opts, target, ctx, fmt) {
|
|
|
777
925
|
* @returns Exit code.
|
|
778
926
|
*/
|
|
779
927
|
async function performLockfileInstall(opts, target, ctx, fmt) {
|
|
780
|
-
|
|
928
|
+
if (opts.skipUnsupported === true) {
|
|
929
|
+
// Replay never rewrites lockfile entries, so a partial replay would
|
|
930
|
+
// leave skipped files recorded as installed.
|
|
931
|
+
throw new framework_1.RegistryError({
|
|
932
|
+
code: 'USAGE.INVALID_FLAG',
|
|
933
|
+
message: 'install: --skip-unsupported cannot be used with --lockfile; lockfile replay installs every recorded bundle in full',
|
|
934
|
+
hint: 'Install the bundle on its own: install <bundle-id> --skip-unsupported (or --from <dir>).'
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
const effectiveTarget = (0, framework_1.resolveEffectiveTarget)(ctx, target, opts);
|
|
781
938
|
const lockfile = opts.lockfile;
|
|
782
939
|
const lockPath = path.isAbsolute(lockfile)
|
|
783
940
|
? lockfile
|
|
@@ -802,11 +959,8 @@ async function performLockfileInstall(opts, target, ctx, fmt) {
|
|
|
802
959
|
verbose: opts.verbose ?? false,
|
|
803
960
|
sourceAwareDependencyCache
|
|
804
961
|
});
|
|
805
|
-
if (replayed.length > 0) {
|
|
806
|
-
await updateTargetStateFromLockfile(ctx, effectiveTarget.name, lock, replayed);
|
|
807
|
-
}
|
|
808
962
|
const status = failures.length === 0 ? 'ok' : 'warning';
|
|
809
|
-
(0,
|
|
963
|
+
(0, framework_1.formatOutput)({
|
|
810
964
|
ctx,
|
|
811
965
|
command: 'install',
|
|
812
966
|
output: fmt,
|
|
@@ -837,6 +991,152 @@ async function performLockfileInstall(opts, target, ctx, fmt) {
|
|
|
837
991
|
});
|
|
838
992
|
return failures.length === 0 ? 0 : 1;
|
|
839
993
|
}
|
|
994
|
+
function renderRecordReplay(d) {
|
|
995
|
+
const lines = [
|
|
996
|
+
`Replay: ${d.replayed.length}/${d.replayPlanned} entr${d.replayPlanned === 1 ? 'y' : 'ies'} installed.`,
|
|
997
|
+
...d.replayed.map((r) => ` ${r.bundleId}@${r.version} (${r.tool}) into target "${r.target}"`),
|
|
998
|
+
...d.needsReinstall.map((n) => `Needs reinstall: ${n.bundleId}@${n.version} (tool unknown)`),
|
|
999
|
+
...d.skipped.map((s) => `Skipped ${s.bundleId} (${s.tool}): ${s.reason}`),
|
|
1000
|
+
...d.failures.map((f) => `Failed ${f.bundleId} (${f.tool}): ${f.reason}`)
|
|
1001
|
+
];
|
|
1002
|
+
if (d.oldFile !== undefined) {
|
|
1003
|
+
const old = d.oldFile;
|
|
1004
|
+
lines.push(`Old file ${old.lockfile}: ${String(old.replayed.length)}/${String(old.replayPlanned)} bundle${old.replayPlanned === 1 ? '' : 's'} installed`
|
|
1005
|
+
+ (old.target === undefined ? '.' : ` into target "${old.target}".`), ...old.failures.map((f) => `Failed ${f.bundleId}: ${f.reason}`));
|
|
1006
|
+
}
|
|
1007
|
+
return lines.join('\n') + '\n' + (0, framework_1.renderMigration)(d.migration) + (0, framework_1.renderRecordLine)({ level: d.level, records: d.records });
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Reinstall every recorded entry at its recorded version with its mapped target, and record it again.
|
|
1011
|
+
* @param run Replay inputs.
|
|
1012
|
+
* @returns Exit code.
|
|
1013
|
+
* @throws {RegistryError} A `RECORD.*` error naming the file.
|
|
1014
|
+
*/
|
|
1015
|
+
async function performRecordReplay(run) {
|
|
1016
|
+
const { ctx, fmt, opts, prepared, explicit } = run;
|
|
1017
|
+
if (opts.skipUnsupported === true) {
|
|
1018
|
+
throw new framework_1.RegistryError({
|
|
1019
|
+
code: 'USAGE.INVALID_FLAG',
|
|
1020
|
+
message: 'install: --skip-unsupported cannot be used with a record replay; the replay installs every recorded entry in full',
|
|
1021
|
+
hint: 'Install the bundle on its own: install <bundle-id> --skip-unsupported (or --from <dir>).'
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
const { selection, store, service, fs } = prepared;
|
|
1025
|
+
const http = opts.http ?? new infra_1.NodeHttpClient();
|
|
1026
|
+
const tokens = opts.tokens ?? (0, infra_1.defaultTokenProvider)(ctx.env);
|
|
1027
|
+
const cache = (0, infra_1.isGitHubAppAuthEnabled)(ctx.env) ? createSourceAwareInstallDependencyCache(http, ctx) : undefined;
|
|
1028
|
+
// Local-only files go to the record's info/exclude, also in a git worktree.
|
|
1029
|
+
const writerFactory = (0, exports.createWriterFactory)(ctx, opts, prepared.exclusion);
|
|
1030
|
+
// Every entry is mapped and its source gated before any fetch.
|
|
1031
|
+
const plan = await (0, app_1.planRecordEntries)({
|
|
1032
|
+
service,
|
|
1033
|
+
store,
|
|
1034
|
+
fs,
|
|
1035
|
+
selection,
|
|
1036
|
+
targets: await (0, framework_1.readTargetsSafely)((0, framework_1.loadTargets)(ctx)),
|
|
1037
|
+
...await (0, framework_1.configuredRecordSources)(ctx),
|
|
1038
|
+
explicit,
|
|
1039
|
+
cwd: ctx.cwd(),
|
|
1040
|
+
holdingFile: 'first-holding'
|
|
1041
|
+
});
|
|
1042
|
+
const data = {
|
|
1043
|
+
...await (0, framework_1.recordOutputFields)(selection, fs),
|
|
1044
|
+
replayPlanned: plan.considered,
|
|
1045
|
+
replayed: [],
|
|
1046
|
+
skipped: plan.skipped,
|
|
1047
|
+
needsReinstall: plan.needsReinstall.map((row) => ({ bundleId: row.bundleId, version: row.version })),
|
|
1048
|
+
failures: [],
|
|
1049
|
+
...(prepared.migration === undefined ? {} : { migration: prepared.migration })
|
|
1050
|
+
};
|
|
1051
|
+
// Every mapped target is checked against --allow-target before anything is fetched or written.
|
|
1052
|
+
for (const item of plan.items) {
|
|
1053
|
+
checkAllowTarget((0, framework_1.resolveEffectiveTarget)(ctx, item.target).name, opts);
|
|
1054
|
+
}
|
|
1055
|
+
const changes = [];
|
|
1056
|
+
for (const item of plan.items) {
|
|
1057
|
+
const { bundleId, tool, entry } = item;
|
|
1058
|
+
const source = (0, app_1.toLockfileSourceEntry)(item.source);
|
|
1059
|
+
const target = (0, framework_1.resolveEffectiveTarget)(ctx, item.target);
|
|
1060
|
+
let written = [];
|
|
1061
|
+
try {
|
|
1062
|
+
// No archive checksum in a record entry; recordInstall re-checksums the written files.
|
|
1063
|
+
const files = await fetchFilesForSource(source, bundleId, (0, app_1.toLockfileBundleEntry)(entry), http, (0, framework_1.tokensForRecordSource)(tokens, item.fromRecordOnly), ctx, opts.verbose ?? false, item.fromRecordOnly ? undefined : cache);
|
|
1064
|
+
if (files === null) {
|
|
1065
|
+
data.failures.push({ bundleId, tool, reason: `failed to fetch files from ${source.type} source` });
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1068
|
+
const manifest = (0, core_1.validateManifest)(files, {
|
|
1069
|
+
expectedId: source.type === 'artifactory' ? undefined : bundleId,
|
|
1070
|
+
expectedVersion: entry.version,
|
|
1071
|
+
sourceRepoSlug: (0, app_1.githubRepoSlugForSource)(source)
|
|
1072
|
+
});
|
|
1073
|
+
const mcp = (0, framework_1.bundleMcpOf)(manifest, ctx.env, source.type === 'github' ? source.url : undefined);
|
|
1074
|
+
await (0, framework_1.checkPlannedInstallMcp)(service, item, target, ctx, manifest.version, mcp);
|
|
1075
|
+
const { result } = await (0, app_1.writeBundleSafely)(writerFactory(target), target, files, manifest);
|
|
1076
|
+
written = [...result.written];
|
|
1077
|
+
changes.push(await (0, framework_1.recordPlannedInstall)(service, { ...item, sourceId: entry.sourceId, source, sourceType: source.type, hubId: item.source.hubId }, target, ctx, manifest.version, written, false, { name: manifest.id, files }, mcp));
|
|
1078
|
+
data.replayed.push({ bundleId, tool, version: manifest.version, target: target.name });
|
|
1079
|
+
}
|
|
1080
|
+
catch (cause) {
|
|
1081
|
+
if ((0, core_1.isRecordError)(cause)) {
|
|
1082
|
+
throw (0, framework_1.toCommandRecordError)('install', cause, written);
|
|
1083
|
+
}
|
|
1084
|
+
data.failures.push({ bundleId, tool, reason: cause instanceof Error ? cause.message : String(cause) });
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
const warnings = [...plan.notes, ...await (0, framework_1.finishRecordRun)(service, changes)];
|
|
1088
|
+
// Bundles only in the old file replay with the old code; the record wins for the others.
|
|
1089
|
+
data.oldFile = await replayOldFileOnly(run, { http, tokens, cache });
|
|
1090
|
+
warnings.push(...data.skipped.map((s) => `${s.bundleId} (${s.tool}): ${s.reason}`), ...data.needsReinstall.map((n) => `${n.bundleId}: needs reinstall`), ...data.failures.map((f) => `${f.bundleId} (${f.tool}): ${f.reason}`), ...(data.oldFile?.failures ?? []).map((f) => `${f.bundleId}: ${f.reason}`));
|
|
1091
|
+
(0, framework_1.formatOutput)({
|
|
1092
|
+
ctx,
|
|
1093
|
+
command: 'install',
|
|
1094
|
+
output: fmt,
|
|
1095
|
+
status: warnings.length === 0 ? 'ok' : 'warning',
|
|
1096
|
+
data,
|
|
1097
|
+
warnings: warnings.length === 0 ? undefined : warnings,
|
|
1098
|
+
textRenderer: renderRecordReplay
|
|
1099
|
+
});
|
|
1100
|
+
// Exit 1 when every planned entry was skipped.
|
|
1101
|
+
const nothingProcessed = data.replayPlanned > 0 && data.replayed.length === 0 && data.failures.length === 0
|
|
1102
|
+
&& (data.oldFile === undefined || data.oldFile.replayed.length === 0);
|
|
1103
|
+
const failed = data.failures.length > 0 || (data.oldFile?.failures.length ?? 0) > 0;
|
|
1104
|
+
return failed || nothingProcessed ? 1 : 0;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Replay the bundles only the old `prompt-registry.*` file has, with the old code and on that file.
|
|
1108
|
+
* They go to the `--target` or only configured target, else fail with the missing-target message.
|
|
1109
|
+
* @param run Replay inputs.
|
|
1110
|
+
* @param fetch HTTP client, token provider and source-aware dependency cache.
|
|
1111
|
+
* @param fetch.http HTTP client.
|
|
1112
|
+
* @param fetch.tokens Token provider.
|
|
1113
|
+
* @param fetch.cache Source-aware dependency cache, when GitHub App auth is on.
|
|
1114
|
+
* @returns What was replayed, or `undefined` when there is no old-file-only bundle.
|
|
1115
|
+
*/
|
|
1116
|
+
async function replayOldFileOnly(run, fetch) {
|
|
1117
|
+
const { ctx, opts, prepared, explicit } = run;
|
|
1118
|
+
const old = await (0, framework_1.prepareOldFileOnly)(ctx, prepared, { command: 'install', target: explicit, overrides: opts });
|
|
1119
|
+
if (old === undefined) {
|
|
1120
|
+
return undefined;
|
|
1121
|
+
}
|
|
1122
|
+
const { lockPath, lock, bundleIds } = old;
|
|
1123
|
+
if ('reason' in old) {
|
|
1124
|
+
return { lockfile: lockPath, replayPlanned: bundleIds.length, replayed: [], failures: bundleIds.map((bundleId) => ({ bundleId, reason: old.reason })) };
|
|
1125
|
+
}
|
|
1126
|
+
const { target } = old;
|
|
1127
|
+
const { replayed, failures } = await replayLockfileEntries({
|
|
1128
|
+
bundleIds,
|
|
1129
|
+
lock,
|
|
1130
|
+
http: fetch.http,
|
|
1131
|
+
tokens: fetch.tokens,
|
|
1132
|
+
writer: (0, exports.createWriterFactory)(ctx, opts)(target),
|
|
1133
|
+
target,
|
|
1134
|
+
ctx,
|
|
1135
|
+
verbose: opts.verbose ?? false,
|
|
1136
|
+
sourceAwareDependencyCache: fetch.cache
|
|
1137
|
+
});
|
|
1138
|
+
return { lockfile: lockPath, target: target.name, replayPlanned: bundleIds.length, replayed, failures };
|
|
1139
|
+
}
|
|
840
1140
|
/**
|
|
841
1141
|
* Perform remote install from GitHub.
|
|
842
1142
|
* @param opts Install options.
|
|
@@ -847,11 +1147,11 @@ async function performLockfileInstall(opts, target, ctx, fmt) {
|
|
|
847
1147
|
*/
|
|
848
1148
|
async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
849
1149
|
try {
|
|
850
|
-
const effectiveTarget = (0,
|
|
1150
|
+
const effectiveTarget = (0, framework_1.resolveEffectiveTarget)(ctx, target, opts);
|
|
851
1151
|
const spec = (0, core_1.parseBundleSpec)(opts.bundle);
|
|
852
1152
|
const repoSlug = opts.source ?? spec.sourceId;
|
|
853
1153
|
if (repoSlug === undefined || repoSlug.length === 0) {
|
|
854
|
-
throw new
|
|
1154
|
+
throw new framework_1.RegistryError({
|
|
855
1155
|
code: 'USAGE.MISSING_FLAG',
|
|
856
1156
|
message: 'install: a remote install needs --source <owner/repo> (or `install owner/repo:<bundleId>`).',
|
|
857
1157
|
hint: 'Examples:\n'
|
|
@@ -914,7 +1214,7 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
914
1214
|
const extractor = new infra_1.ZipBundleExtractor();
|
|
915
1215
|
const installable = await resolver.resolve(spec);
|
|
916
1216
|
if (installable === null) {
|
|
917
|
-
throw new
|
|
1217
|
+
throw new framework_1.RegistryError({
|
|
918
1218
|
code: 'BUNDLE.NOT_FOUND',
|
|
919
1219
|
message: `install: ${spec.bundleId} not found at ${repoSlug}`,
|
|
920
1220
|
hint: 'Check the source slug and that a release with the requested version + asset (bundle.zip) exists.',
|
|
@@ -924,17 +1224,19 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
924
1224
|
const dl = await downloader.download(installable);
|
|
925
1225
|
const files = await extractor.extract(dl.bytes);
|
|
926
1226
|
// A plain `owner/repo` source and a GitHub source resolved from
|
|
927
|
-
// `--source` check the id source-aware
|
|
928
|
-
//
|
|
929
|
-
const sourceRepoSlug = opts.sourceConfig === undefined ? repoSlug : opts.sourceRepoSlug;
|
|
1227
|
+
// `--source` check the id source-aware. Artifactory uses the resolved
|
|
1228
|
+
// index entry and its published repository namespace.
|
|
1229
|
+
const sourceRepoSlug = installable.sourceRepoSlug ?? (opts.sourceConfig === undefined ? repoSlug : opts.sourceRepoSlug);
|
|
930
1230
|
const manifest = (0, core_1.validateManifest)(files, {
|
|
931
|
-
expectedId:
|
|
1231
|
+
expectedId: isArtifactory
|
|
1232
|
+
? installable.ref.bundleId
|
|
1233
|
+
: (opts.sourceConfig === undefined || opts.sourceRepoSlug !== undefined ? spec.bundleId : undefined),
|
|
932
1234
|
sourceRepoSlug,
|
|
933
1235
|
expectedVersion: isArtifactory ? installable.ref.bundleVersion : (spec.bundleVersion === 'latest' ? undefined : spec.bundleVersion)
|
|
934
1236
|
});
|
|
935
1237
|
const lockKey = isArtifactory ? installable.ref.bundleId : manifest.id;
|
|
936
1238
|
if (opts.dryRun === true) {
|
|
937
|
-
(0,
|
|
1239
|
+
(0, framework_1.formatOutput)({
|
|
938
1240
|
ctx,
|
|
939
1241
|
command: 'install',
|
|
940
1242
|
output: fmt,
|
|
@@ -953,71 +1255,87 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
953
1255
|
});
|
|
954
1256
|
return 0;
|
|
955
1257
|
}
|
|
956
|
-
|
|
1258
|
+
// Check the record files before the writer runs, so a RECORD.* error writes nothing.
|
|
1259
|
+
const prepared = await (0, framework_1.prepareRecordForTarget)(ctx, effectiveTarget);
|
|
1260
|
+
// Optional hub metadata, looked up before any file is written; a failed lookup records no hub.
|
|
1261
|
+
const hub = prepared === undefined ? undefined : await (0, framework_1.recordHubOf)(ctx, opts.sourceConfig).catch(() => undefined);
|
|
1262
|
+
// No configured source: the GitHub repository the bundle was resolved from.
|
|
1263
|
+
const recordSource = opts.sourceConfig === undefined
|
|
1264
|
+
? { type: 'github', url: `https://github.com/${repoSlug}` }
|
|
1265
|
+
: (0, app_1.toRecordSource)(opts.sourceConfig, installable.ref.sourceId, hub);
|
|
1266
|
+
// A source recorded from another hub is refused before any file is written.
|
|
1267
|
+
await (0, framework_1.checkRecordSourceHub)(prepared, { ...recordSource, sourceId: installable.ref.sourceId }, hub);
|
|
1268
|
+
const mcp = (0, framework_1.bundleMcpOf)(manifest, ctx.env, `https://github.com/${repoSlug}`);
|
|
1269
|
+
await (0, framework_1.checkRepositoryInstallMcp)(prepared, { bundleId: lockKey, version: manifest.version, tool: effectiveTarget.type, mcp });
|
|
1270
|
+
const writerFactory = (0, exports.createWriterFactory)(ctx, opts, prepared?.exclusion);
|
|
957
1271
|
const writer = writerFactory(effectiveTarget);
|
|
958
|
-
const { installableFiles: targetFiles, result } = await (0, app_1.
|
|
959
|
-
|
|
960
|
-
const
|
|
961
|
-
const lockPath =
|
|
962
|
-
|
|
963
|
-
const entry = {
|
|
1272
|
+
const { installableFiles: targetFiles, result, skipped } = await (0, app_1.writeBundleForInstall)(writer, effectiveTarget, files, manifest, { skipUnsupported: opts.skipUnsupported === true });
|
|
1273
|
+
// The old lockfile never kept a branch.
|
|
1274
|
+
const { branch: _branch, ...sourceDetails } = (0, app_1.toLockfileSourceEntry)(recordSource);
|
|
1275
|
+
const { lockPath, warnings } = await persistInstall(prepared, {
|
|
1276
|
+
bundleId: lockKey,
|
|
964
1277
|
version: manifest.version,
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
: {})
|
|
1278
|
+
tool: effectiveTarget.type,
|
|
1279
|
+
source: { ...recordSource, sourceId: installable.ref.sourceId },
|
|
1280
|
+
...(hub === undefined ? {} : { hub }),
|
|
1281
|
+
writtenPaths: result.written,
|
|
1282
|
+
bundle: { name: manifest.id, files },
|
|
1283
|
+
mcp
|
|
1284
|
+
}, async () => {
|
|
1285
|
+
const legacyLockPath = (0, framework_1.lockfilePathForTarget)(ctx, effectiveTarget);
|
|
1286
|
+
const existing = await (0, app_1.readLockfile)(legacyLockPath, ctx.fs) ?? (0, app_1.emptyLockfile)('ai-primitives-hub-cli');
|
|
1287
|
+
const entry = {
|
|
1288
|
+
version: manifest.version,
|
|
1289
|
+
sourceId: installable.ref.sourceId,
|
|
1290
|
+
sourceType: installable.ref.sourceType,
|
|
1291
|
+
checksum: dl.sha256,
|
|
1292
|
+
installedAt: new Date().toISOString(),
|
|
1293
|
+
files: (0, app_1.checksumFiles)(targetFiles, result.writtenBundlePaths ?? targetFiles.keys(), result.installedPaths)
|
|
1294
|
+
};
|
|
1295
|
+
const previousFiles = existing.bundles[lockKey]?.files;
|
|
1296
|
+
let nextLock = (0, app_1.upsertBundleEntry)(existing, lockKey, entry);
|
|
1297
|
+
nextLock = (0, app_1.upsertSource)(nextLock, installable.ref.sourceId, sourceDetails);
|
|
1298
|
+
await (0, app_1.writeLockfile)(legacyLockPath, nextLock, ctx.fs);
|
|
1299
|
+
await (0, app_1.removeSupersededFiles)(writer, effectiveTarget, previousFiles, entry.files);
|
|
1300
|
+
return legacyLockPath;
|
|
989
1301
|
});
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1302
|
+
if (opts.onInstalled !== undefined) {
|
|
1303
|
+
opts.onInstalled({ version: manifest.version });
|
|
1304
|
+
return 0;
|
|
1305
|
+
}
|
|
1306
|
+
(0, framework_1.formatOutput)({
|
|
993
1307
|
ctx,
|
|
994
1308
|
command: 'install',
|
|
995
1309
|
output: fmt,
|
|
996
|
-
status: 'ok',
|
|
1310
|
+
status: skipped.length === 0 ? 'ok' : 'warning',
|
|
997
1311
|
data: {
|
|
998
1312
|
target: effectiveTarget.name,
|
|
999
1313
|
bundle: { id: lockKey, version: manifest.version },
|
|
1000
1314
|
source: { type: opts.sourceConfig?.type ?? 'github', repo: repoSlug, sourceId: installable.ref.sourceId },
|
|
1001
1315
|
sha256: dl.sha256,
|
|
1002
1316
|
written: result.written,
|
|
1003
|
-
skipped
|
|
1004
|
-
lockfile: lockPath
|
|
1317
|
+
skipped,
|
|
1318
|
+
lockfile: lockPath,
|
|
1319
|
+
...(prepared?.migration === undefined ? {} : { migration: prepared.migration })
|
|
1005
1320
|
},
|
|
1321
|
+
warnings: installWarnings(skipped, warnings),
|
|
1006
1322
|
textRenderer: (d) => `Installed ${d.bundle.id}@${d.bundle.version} from ${d.source.repo} `
|
|
1007
1323
|
+ `into target "${d.target}" (${d.written.length} written, ${d.skipped.length} skipped). `
|
|
1008
1324
|
+ `Updated ${d.lockfile}.\n`
|
|
1325
|
+
+ renderSkipped(d.skipped)
|
|
1326
|
+
+ (0, framework_1.renderMigration)(d.migration)
|
|
1009
1327
|
});
|
|
1010
1328
|
return 0;
|
|
1011
1329
|
}
|
|
1012
1330
|
catch (cause) {
|
|
1013
|
-
if (cause instanceof
|
|
1331
|
+
if (cause instanceof framework_1.RegistryError) {
|
|
1014
1332
|
throw cause;
|
|
1015
1333
|
}
|
|
1016
1334
|
const raw = cause.code;
|
|
1017
1335
|
const code = raw !== undefined && /^(BUNDLE|FS|NETWORK|USAGE|CONFIG)\.[A-Z0-9_]+$/.test(raw)
|
|
1018
1336
|
? raw
|
|
1019
1337
|
: 'NETWORK.DOWNLOAD_FAILED';
|
|
1020
|
-
throw new
|
|
1338
|
+
throw new framework_1.RegistryError({
|
|
1021
1339
|
code,
|
|
1022
1340
|
message: `install: ${cause.message}`,
|
|
1023
1341
|
hint: 'Run `ai-primitives-hub doctor` for environment diagnostics, or use `--from <localDir>` to install a pre-built bundle.',
|
|
@@ -1031,68 +1349,6 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
1031
1349
|
});
|
|
1032
1350
|
}
|
|
1033
1351
|
}
|
|
1034
|
-
/**
|
|
1035
|
-
* Update target state with installed bundle.
|
|
1036
|
-
* @param ctx CLI context.
|
|
1037
|
-
* @param targetName Target name.
|
|
1038
|
-
* @param bundleId Bundle ID.
|
|
1039
|
-
* @param version Bundle version.
|
|
1040
|
-
*/
|
|
1041
|
-
async function updateTargetState(ctx, targetName, bundleId, version) {
|
|
1042
|
-
const stateStore = new infra_1.TargetStateStore({
|
|
1043
|
-
fs: ctx.fs,
|
|
1044
|
-
statePath: path.join(ctx.cwd(), '.ai-primitives-hub', 'target-state.json')
|
|
1045
|
-
});
|
|
1046
|
-
const existingState = await stateStore.load(targetName);
|
|
1047
|
-
const newBundles = existingState?.lastInstalledBundles ?? [];
|
|
1048
|
-
const bundleIndex = newBundles.findIndex((b) => b.bundleId === bundleId);
|
|
1049
|
-
const bundleState = { bundleId, version, installedAt: new Date().toISOString() };
|
|
1050
|
-
if (bundleIndex === -1) {
|
|
1051
|
-
newBundles.push(bundleState);
|
|
1052
|
-
}
|
|
1053
|
-
else {
|
|
1054
|
-
newBundles[bundleIndex] = bundleState;
|
|
1055
|
-
}
|
|
1056
|
-
await stateStore.save({
|
|
1057
|
-
targetName,
|
|
1058
|
-
lastInstalledBundles: newBundles,
|
|
1059
|
-
lastUsedAt: new Date().toISOString()
|
|
1060
|
-
});
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Update target state from lockfile entries.
|
|
1064
|
-
* @param ctx CLI context.
|
|
1065
|
-
* @param targetName Target name.
|
|
1066
|
-
* @param lock Lockfile.
|
|
1067
|
-
* @param replayed Replayed bundle IDs.
|
|
1068
|
-
*/
|
|
1069
|
-
async function updateTargetStateFromLockfile(ctx, targetName, lock, replayed) {
|
|
1070
|
-
const stateStore = new infra_1.TargetStateStore({
|
|
1071
|
-
fs: ctx.fs,
|
|
1072
|
-
statePath: path.join(ctx.cwd(), '.ai-primitives-hub', 'target-state.json')
|
|
1073
|
-
});
|
|
1074
|
-
const existingState = await stateStore.load(targetName);
|
|
1075
|
-
const newBundles = existingState?.lastInstalledBundles ?? [];
|
|
1076
|
-
for (const bundleId of replayed) {
|
|
1077
|
-
const entry = lock.bundles[bundleId];
|
|
1078
|
-
if (entry === undefined) {
|
|
1079
|
-
continue;
|
|
1080
|
-
}
|
|
1081
|
-
const bundleIndex = newBundles.findIndex((b) => b.bundleId === bundleId);
|
|
1082
|
-
const bundleState = { bundleId, version: entry.version, installedAt: entry.installedAt };
|
|
1083
|
-
if (bundleIndex === -1) {
|
|
1084
|
-
newBundles.push(bundleState);
|
|
1085
|
-
}
|
|
1086
|
-
else {
|
|
1087
|
-
newBundles[bundleIndex] = bundleState;
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
await stateStore.save({
|
|
1091
|
-
targetName,
|
|
1092
|
-
lastInstalledBundles: newBundles,
|
|
1093
|
-
lastUsedAt: new Date().toISOString()
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
1352
|
/**
|
|
1097
1353
|
* Install a single bundle given an explicit source configuration.
|
|
1098
1354
|
* Shared by `install --interactive` and `index search --install`.
|
|
@@ -1115,49 +1371,6 @@ async function installBundleWithSource(bundleId, sourceConfig, target, ctx, http
|
|
|
1115
1371
|
};
|
|
1116
1372
|
return performRemoteInstall(opts, target, ctx, fmt);
|
|
1117
1373
|
}
|
|
1118
|
-
/**
|
|
1119
|
-
* Build the `install` command (factory function for backward compatibility).
|
|
1120
|
-
* @param opts - Command options.
|
|
1121
|
-
* @returns CommandDefinition wired to the framework adapter.
|
|
1122
|
-
*/
|
|
1123
|
-
const createInstallCommand = (opts = {}) => (0, framework_2.defineCommand)({
|
|
1124
|
-
path: ['install'],
|
|
1125
|
-
description: 'Install bundles to a configured target.',
|
|
1126
|
-
category: 'Install & Manage',
|
|
1127
|
-
run: async ({ ctx }) => {
|
|
1128
|
-
const fmt = opts.output ?? 'text';
|
|
1129
|
-
const { bundle: noBundle, lockfile: noLockfile } = (0, framework_2.validateInputs)(opts, { flags: ['bundle', 'lockfile'] });
|
|
1130
|
-
if (noBundle && noLockfile) {
|
|
1131
|
-
return (0, framework_1.failWith)(ctx, fmt, 'install', new framework_2.RegistryError({
|
|
1132
|
-
code: 'USAGE.MISSING_FLAG',
|
|
1133
|
-
message: 'install: provide either <bundle-id> (imperative) or --lockfile <path> (declarative)',
|
|
1134
|
-
hint: 'Examples:\n'
|
|
1135
|
-
+ ' ai-primitives-hub install <bundle-id>\n'
|
|
1136
|
-
+ ' ai-primitives-hub install --lockfile prompt-registry.lock.json'
|
|
1137
|
-
}));
|
|
1138
|
-
}
|
|
1139
|
-
try {
|
|
1140
|
-
const targetName = await (0, framework_2.resolveTargetName)(opts.target, 'install', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
1141
|
-
checkAllowTarget(targetName, opts);
|
|
1142
|
-
const configuredTarget = await (0, framework_2.resolveTarget)(targetName, 'install', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
1143
|
-
const target = (0, framework_2.resolveEffectiveTarget)(ctx, configuredTarget, opts);
|
|
1144
|
-
if (opts.from !== undefined && opts.from.length > 0) {
|
|
1145
|
-
return await performLocalInstall(opts, target, ctx, fmt);
|
|
1146
|
-
}
|
|
1147
|
-
if (opts.lockfile !== undefined && opts.lockfile.length > 0) {
|
|
1148
|
-
return await performLockfileInstall(opts, target, ctx, fmt);
|
|
1149
|
-
}
|
|
1150
|
-
return await performRemoteInstall(opts, target, ctx, fmt);
|
|
1151
|
-
}
|
|
1152
|
-
catch (err) {
|
|
1153
|
-
if (err instanceof framework_2.RegistryError) {
|
|
1154
|
-
return (0, framework_1.failWith)(ctx, fmt, 'install', err);
|
|
1155
|
-
}
|
|
1156
|
-
throw err;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
});
|
|
1160
|
-
exports.createInstallCommand = createInstallCommand;
|
|
1161
1374
|
async function replayLockfileEntries(opts) {
|
|
1162
1375
|
const { bundleIds, lock, http, tokens, writer, target, ctx, verbose, sourceAwareDependencyCache } = opts;
|
|
1163
1376
|
const replayed = [];
|
|
@@ -1292,7 +1505,13 @@ async function fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verb
|
|
|
1292
1505
|
if (entry.checksum !== undefined && dl.sha256 !== entry.checksum) {
|
|
1293
1506
|
return null;
|
|
1294
1507
|
}
|
|
1295
|
-
|
|
1508
|
+
const files = new Map(await new infra_1.ZipBundleExtractor().extract(dl.bytes));
|
|
1509
|
+
(0, core_1.validateManifest)(files, {
|
|
1510
|
+
expectedId: installable.ref.bundleId,
|
|
1511
|
+
expectedVersion: installable.ref.bundleVersion,
|
|
1512
|
+
sourceRepoSlug: installable.sourceRepoSlug
|
|
1513
|
+
});
|
|
1514
|
+
return files;
|
|
1296
1515
|
}
|
|
1297
1516
|
if (src.type === 'github' || src.type === 'skills' || src.type === 'awesome-copilot') {
|
|
1298
1517
|
// Check if this is an awesome-copilot source (detected by sourceId prefix)
|