@ai-primitives-hub/cli 0.1.0 → 0.2.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/dist/commands/apply.d.ts.map +1 -1
- package/dist/commands/apply.js +11 -1
- package/dist/commands/apply.js.map +1 -1
- package/dist/commands/bundle-build.d.ts.map +1 -1
- package/dist/commands/bundle-build.js +8 -23
- package/dist/commands/bundle-build.js.map +1 -1
- package/dist/commands/completion.d.ts +24 -1
- package/dist/commands/completion.d.ts.map +1 -1
- package/dist/commands/completion.js +113 -211
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +13 -2
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/hub-replicate.d.ts +29 -0
- package/dist/commands/hub-replicate.d.ts.map +1 -0
- package/dist/commands/hub-replicate.js +93 -0
- package/dist/commands/hub-replicate.js.map +1 -0
- package/dist/commands/hub.d.ts +8 -0
- package/dist/commands/hub.d.ts.map +1 -1
- package/dist/commands/hub.js +192 -28
- package/dist/commands/hub.js.map +1 -1
- package/dist/commands/index-build.d.ts +1 -0
- package/dist/commands/index-build.d.ts.map +1 -1
- package/dist/commands/index-build.js +4 -0
- package/dist/commands/index-build.js.map +1 -1
- package/dist/commands/index-harvest.d.ts +5 -0
- package/dist/commands/index-harvest.d.ts.map +1 -1
- package/dist/commands/index-harvest.js +37 -12
- package/dist/commands/index-harvest.js.map +1 -1
- package/dist/commands/index-search.d.ts.map +1 -1
- package/dist/commands/index-search.js +2 -2
- package/dist/commands/index-search.js.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +37 -13
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.d.ts +36 -4
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +327 -48
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/profile.d.ts +11 -6
- package/dist/commands/profile.d.ts.map +1 -1
- package/dist/commands/profile.js +184 -57
- package/dist/commands/profile.js.map +1 -1
- package/dist/commands/registry.d.ts +15 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +117 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/source.d.ts +3 -0
- package/dist/commands/source.d.ts.map +1 -1
- package/dist/commands/source.js +38 -5
- package/dist/commands/source.js.map +1 -1
- package/dist/commands/uninstall.d.ts.map +1 -1
- package/dist/commands/uninstall.js +8 -5
- package/dist/commands/uninstall.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +149 -41
- package/dist/commands/update.js.map +1 -1
- package/dist/doctor/diagnostics.d.ts +24 -1
- package/dist/doctor/diagnostics.d.ts.map +1 -1
- package/dist/doctor/diagnostics.js +77 -16
- package/dist/doctor/diagnostics.js.map +1 -1
- package/dist/framework/cli.d.ts.map +1 -1
- package/dist/framework/cli.js +12 -2
- package/dist/framework/cli.js.map +1 -1
- package/dist/framework/command-paths.d.ts +33 -0
- package/dist/framework/command-paths.d.ts.map +1 -0
- package/dist/framework/command-paths.js +45 -0
- package/dist/framework/command-paths.js.map +1 -0
- package/dist/framework/hub-manager.d.ts.map +1 -1
- package/dist/framework/hub-manager.js +19 -1
- package/dist/framework/hub-manager.js.map +1 -1
- package/dist/framework/index.d.ts +1 -0
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +4 -1
- package/dist/framework/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -111
- package/dist/main.js.map +1 -1
- package/package.json +8 -9
package/dist/commands/install.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createInstallCommand = exports.createWriterFactory = exports.InstallCommand = void 0;
|
|
37
|
+
exports.createSourceAwareInstallDependencyCache = createSourceAwareInstallDependencyCache;
|
|
37
38
|
exports.githubApiFor = githubApiFor;
|
|
38
39
|
exports.installBundleWithSource = installBundleWithSource;
|
|
39
40
|
exports.fetchFilesForSource = fetchFilesForSource;
|
|
@@ -47,7 +48,8 @@ exports.fetchFilesForSource = fetchFilesForSource;
|
|
|
47
48
|
* Lockfile integration uses `app`'s dict-based `Lockfile` (extension-compatible
|
|
48
49
|
* schema, `bundles: Record<bundleId, LockfileBundleEntry>`) rather than the
|
|
49
50
|
* reference branch's array-of-entries schema. There is no per-entry `target`
|
|
50
|
-
* field — repository scope
|
|
51
|
+
* field — repository scope writes under the target's own layout base directory
|
|
52
|
+
* (e.g. `.github/` for VS Code, `.kiro/` for Kiro; see `default-layouts.json`),
|
|
51
53
|
* and user-scope installs get their own lockfile file
|
|
52
54
|
* (`resolveUserConfigPaths(env).userLockfile`) rather than the project-root one.
|
|
53
55
|
* `SourceDispatcher`/`GitHubBundleResolver` take a shared `GitHubApi` client
|
|
@@ -71,15 +73,99 @@ function extractRepoSlug(url) {
|
|
|
71
73
|
}
|
|
72
74
|
return url;
|
|
73
75
|
}
|
|
76
|
+
function sourceSpecForInstall(repoSlug, sourceConfig, target) {
|
|
77
|
+
const sourceType = sourceConfig?.type === 'awesome-copilot' ? 'awesome-copilot' : 'github';
|
|
78
|
+
const config = sourceConfig?.config ?? {};
|
|
79
|
+
return {
|
|
80
|
+
id: sourceConfig?.id ?? repoSlug,
|
|
81
|
+
name: sourceConfig?.name ?? repoSlug,
|
|
82
|
+
type: sourceType,
|
|
83
|
+
url: sourceConfig?.url ?? `https://${target.host}/${target.owner}/${target.repository}`,
|
|
84
|
+
owner: target.owner,
|
|
85
|
+
repo: target.repository,
|
|
86
|
+
branch: typeof config.branch === 'string' ? config.branch : 'main',
|
|
87
|
+
...(sourceType === 'awesome-copilot'
|
|
88
|
+
? { collectionsPath: typeof config.collectionsPath === 'string' ? config.collectionsPath : 'collections' }
|
|
89
|
+
: {}),
|
|
90
|
+
rawConfig: config
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function sourceAwareInstallDependencies(repoSlug, sourceConfig, http, ctx, runtime = (0, infra_1.createGitHubSourceAuthRuntime)({ env: ctx.env, http })) {
|
|
94
|
+
const sourceUrl = sourceConfig?.url ?? `https://github.com/${repoSlug}`;
|
|
95
|
+
const repositoryTarget = (0, infra_1.parseGitHubRepositoryTarget)(sourceUrl);
|
|
96
|
+
const sourceSpec = sourceSpecForInstall(repoSlug, sourceConfig, repositoryTarget);
|
|
97
|
+
const report = await runtime.preflight([sourceSpec], {
|
|
98
|
+
includeReleases: sourceConfig === undefined || sourceConfig.type === 'github',
|
|
99
|
+
onLog: (message) => ctx.stderr.write(`[github preflight] ${message}\n`)
|
|
100
|
+
});
|
|
101
|
+
const decision = report.results[0];
|
|
102
|
+
if (!report.valid || decision === undefined || decision.category === 'unresolved' || decision.target === undefined) {
|
|
103
|
+
const code = decision?.errorCode ?? 'GH_SOURCE_PREFLIGHT_UNRESOLVED';
|
|
104
|
+
throw new Error(`GitHub source preflight failed for ${sourceSpec.id}: ${code}`);
|
|
105
|
+
}
|
|
106
|
+
const downloadTokens = runtime.tokenProviderFor(decision.category) ?? new infra_1.StaticTokenProvider('');
|
|
107
|
+
return {
|
|
108
|
+
githubApi: runtime.clientFor(decision.target, decision.category),
|
|
109
|
+
downloadTokens,
|
|
110
|
+
repositoryTarget: decision.target,
|
|
111
|
+
authenticationCategory: decision.category
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function sourceAwareInstallDependencyKey(repoSlug, sourceConfig) {
|
|
115
|
+
const sourceUrl = sourceConfig?.url ?? `https://github.com/${repoSlug}`;
|
|
116
|
+
const target = (0, infra_1.parseGitHubRepositoryTarget)(sourceUrl);
|
|
117
|
+
const config = sourceConfig?.config ?? {};
|
|
118
|
+
return [
|
|
119
|
+
target.host.toLowerCase(),
|
|
120
|
+
target.owner.toLowerCase(),
|
|
121
|
+
target.repository.toLowerCase(),
|
|
122
|
+
sourceConfig?.type ?? 'github',
|
|
123
|
+
typeof config.branch === 'string' ? config.branch : 'main',
|
|
124
|
+
typeof config.collectionsPath === 'string' ? config.collectionsPath : 'collections'
|
|
125
|
+
].join('\u0000');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a command-scoped cache for source-aware install dependencies.
|
|
129
|
+
*
|
|
130
|
+
* The App token cache is owned by the runtime's shared provider. Keeping the
|
|
131
|
+
* runtime and preflight promises at command scope prevents every bundle in a
|
|
132
|
+
* lockfile from repeating the same repository checks and minting a fresh
|
|
133
|
+
* token for an already-seen source.
|
|
134
|
+
* @param http HTTP client used by source preflight and resolvers.
|
|
135
|
+
* @param ctx CLI context.
|
|
136
|
+
* @param runtime Optional runtime seam for tests or advanced callers.
|
|
137
|
+
*/
|
|
138
|
+
function createSourceAwareInstallDependencyCache(http, ctx, runtime) {
|
|
139
|
+
const sharedRuntime = runtime ?? (0, infra_1.createGitHubSourceAuthRuntime)({ env: ctx.env, http });
|
|
140
|
+
const entries = new Map();
|
|
141
|
+
return {
|
|
142
|
+
get: (repoSlug, sourceConfig) => {
|
|
143
|
+
const key = sourceAwareInstallDependencyKey(repoSlug, sourceConfig);
|
|
144
|
+
const existing = entries.get(key);
|
|
145
|
+
if (existing !== undefined) {
|
|
146
|
+
return existing;
|
|
147
|
+
}
|
|
148
|
+
const dependency = sourceAwareInstallDependencies(repoSlug, sourceConfig, http, ctx, sharedRuntime);
|
|
149
|
+
entries.set(key, dependency);
|
|
150
|
+
return dependency;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
74
154
|
/**
|
|
75
155
|
* Build a `GitHubApi` client shared by every GitHub-backed resolver in
|
|
76
156
|
* a single command invocation.
|
|
77
157
|
* @param http HTTP client.
|
|
78
158
|
* @param tokens Token provider.
|
|
159
|
+
* @param repositoryTarget
|
|
160
|
+
* @param authenticationCategory
|
|
79
161
|
* @returns GitHubApiClient instance.
|
|
80
162
|
*/
|
|
81
|
-
function githubApiFor(http, tokens) {
|
|
82
|
-
return new infra_1.GitHubApiClient(http, {
|
|
163
|
+
function githubApiFor(http, tokens, repositoryTarget, authenticationCategory) {
|
|
164
|
+
return new infra_1.GitHubApiClient(http, {
|
|
165
|
+
tokenProvider: tokens,
|
|
166
|
+
repositoryTarget,
|
|
167
|
+
authenticationCategory
|
|
168
|
+
});
|
|
83
169
|
}
|
|
84
170
|
/**
|
|
85
171
|
* Base class for install/uninstall commands.
|
|
@@ -163,9 +249,9 @@ class InstallCommand extends BaseInstallCommand {
|
|
|
163
249
|
}));
|
|
164
250
|
}
|
|
165
251
|
try {
|
|
166
|
-
const targetName = await (0, framework_2.resolveTargetName)(opts.target, 'install', ctx, () => (0,
|
|
252
|
+
const targetName = await (0, framework_2.resolveTargetName)(opts.target, 'install', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
167
253
|
checkAllowTarget(targetName, opts);
|
|
168
|
-
const configuredTarget = await (0, framework_2.resolveTarget)(targetName, 'install', ctx, () => (0,
|
|
254
|
+
const configuredTarget = await (0, framework_2.resolveTarget)(targetName, 'install', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
169
255
|
const target = (0, framework_2.resolveEffectiveTarget)(ctx, configuredTarget, opts);
|
|
170
256
|
const mode = determineInstallMode(opts);
|
|
171
257
|
if (mode === undefined) {
|
|
@@ -272,8 +358,71 @@ async function executeInstallMode(mode, opts, target, ctx, fmt) {
|
|
|
272
358
|
return await performLockfileInstall(opts, target, ctx, fmt);
|
|
273
359
|
}
|
|
274
360
|
default: {
|
|
275
|
-
return await performRemoteInstall(opts, target, ctx, fmt);
|
|
361
|
+
return await performRemoteInstall(await resolveRemoteSourceOption(opts, ctx), target, ctx, fmt);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Resolve `install <bundle-id> --source <value>` for a remote install:
|
|
367
|
+
* `<value>` is tried as a source id in the active hub, then as a hub id
|
|
368
|
+
* (see `resolveInstallSource` in `app`), and only then as a GitHub
|
|
369
|
+
* `owner/repo` slug.
|
|
370
|
+
* @param opts Install options.
|
|
371
|
+
* @param ctx CLI context.
|
|
372
|
+
* @returns Options carrying the resolved source, or `opts` unchanged.
|
|
373
|
+
* @throws {RegistryError} `BUNDLE.NOT_FOUND` when `<value>` matches nothing.
|
|
374
|
+
*/
|
|
375
|
+
async function resolveRemoteSourceOption(opts, ctx) {
|
|
376
|
+
const value = opts.source;
|
|
377
|
+
if (opts.sourceConfig !== undefined || value === undefined || value.length === 0 || opts.bundle === undefined) {
|
|
378
|
+
return opts;
|
|
379
|
+
}
|
|
380
|
+
let bundleId;
|
|
381
|
+
try {
|
|
382
|
+
bundleId = (0, core_1.parseBundleSpec)(opts.bundle).bundleId;
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
return opts; // performRemoteInstall reports the invalid spec.
|
|
386
|
+
}
|
|
387
|
+
const source = await lookupHubSource(opts, ctx, value, bundleId);
|
|
388
|
+
if (source !== null) {
|
|
389
|
+
return {
|
|
390
|
+
...opts,
|
|
391
|
+
source: extractRepoSlug(source.url),
|
|
392
|
+
sourceConfig: source,
|
|
393
|
+
sourceRepoSlug: (0, app_1.githubRepoSlugForSource)(source)
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
if (value.includes('/')) {
|
|
397
|
+
// `owner/repo` (or a URL): keep the historical GitHub-slug behavior.
|
|
398
|
+
return opts;
|
|
399
|
+
}
|
|
400
|
+
throw new framework_2.RegistryError({
|
|
401
|
+
code: 'BUNDLE.NOT_FOUND',
|
|
402
|
+
message: `install: --source "${value}" matched no source id in the active hub, no hub id, and is not a GitHub owner/repo`,
|
|
403
|
+
hint: 'Run `ai-primitives-hub source list` or `ai-primitives-hub hub list` to see valid ids, or pass --source <owner/repo>.',
|
|
404
|
+
context: { bundle: opts.bundle, source: value, tried: ['source id', 'hub id', 'GitHub owner/repo'] }
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Hub lookup for {@link resolveRemoteSourceOption}. A hub configuration
|
|
409
|
+
* that cannot be loaded is reported (`HUB.LOAD_FAILED`), except for an
|
|
410
|
+
* `owner/repo` value, which never needs the hub.
|
|
411
|
+
* @param opts Install options (HTTP/token seams).
|
|
412
|
+
* @param ctx CLI context.
|
|
413
|
+
* @param value `--source` value.
|
|
414
|
+
* @param bundleId Bundle id being installed.
|
|
415
|
+
* @returns Resolved source, or null.
|
|
416
|
+
*/
|
|
417
|
+
async function lookupHubSource(opts, ctx, value, bundleId) {
|
|
418
|
+
try {
|
|
419
|
+
return await (0, app_1.resolveInstallSource)((0, framework_1.createHubManager)({ ctx, http: opts.http, tokens: opts.tokens }), value, bundleId);
|
|
420
|
+
}
|
|
421
|
+
catch (err) {
|
|
422
|
+
if (value.includes('/')) {
|
|
423
|
+
return null; // `owner/repo`: fall back to the GitHub slug.
|
|
276
424
|
}
|
|
425
|
+
throw err;
|
|
277
426
|
}
|
|
278
427
|
}
|
|
279
428
|
/**
|
|
@@ -479,13 +628,22 @@ async function confirmInstallation(ctx) {
|
|
|
479
628
|
}
|
|
480
629
|
async function installSelectedBundles(bundles, sourceMap, opts, target, ctx, fmt) {
|
|
481
630
|
let installedCount = 0;
|
|
631
|
+
const sourceAwareDependencyCache = (0, infra_1.isGitHubAppAuthEnabled)(ctx.env)
|
|
632
|
+
? createSourceAwareInstallDependencyCache(opts.http ?? new infra_1.NodeHttpClient(), ctx)
|
|
633
|
+
: undefined;
|
|
482
634
|
for (const bundle of bundles) {
|
|
483
635
|
const source = sourceMap.get(bundle.source);
|
|
484
636
|
if (!source) {
|
|
485
637
|
ctx.stderr.write(`Failed to install ${bundle.id}@${bundle.version}: source "${bundle.source}" not found in hub\n`);
|
|
486
638
|
continue;
|
|
487
639
|
}
|
|
488
|
-
const bundleOpts = {
|
|
640
|
+
const bundleOpts = {
|
|
641
|
+
...opts,
|
|
642
|
+
bundle: bundle.id,
|
|
643
|
+
source: source.url,
|
|
644
|
+
sourceConfig: source,
|
|
645
|
+
sourceAwareDependencyCache
|
|
646
|
+
};
|
|
489
647
|
try {
|
|
490
648
|
const result = await performRemoteInstall(bundleOpts, target, ctx, fmt);
|
|
491
649
|
if (result === 0) {
|
|
@@ -529,8 +687,9 @@ async function performLocalInstall(opts, target, ctx, fmt) {
|
|
|
529
687
|
try {
|
|
530
688
|
const effectiveTarget = (0, framework_2.resolveEffectiveTarget)(ctx, target, opts);
|
|
531
689
|
const files = await (0, infra_1.readLocalBundle)(opts.from, ctx.fs);
|
|
690
|
+
// No bundle id on the command line: accept the manifest id as-is.
|
|
532
691
|
const manifest = (0, core_1.validateManifest)(files, {
|
|
533
|
-
expectedId: opts.bundle
|
|
692
|
+
expectedId: opts.bundle !== undefined && opts.bundle.length > 0 ? opts.bundle : undefined,
|
|
534
693
|
expectedVersion: undefined
|
|
535
694
|
});
|
|
536
695
|
if (opts.dryRun === true) {
|
|
@@ -552,8 +711,7 @@ async function performLocalInstall(opts, target, ctx, fmt) {
|
|
|
552
711
|
}
|
|
553
712
|
const writerFactory = (0, exports.createWriterFactory)(ctx, opts);
|
|
554
713
|
const writer = writerFactory(effectiveTarget);
|
|
555
|
-
const targetFiles = (0,
|
|
556
|
-
const result = await (0, app_1.writeTargetSafely)(writer, effectiveTarget, targetFiles);
|
|
714
|
+
const { installableFiles: targetFiles, result } = await (0, app_1.writeBundleSafely)(writer, effectiveTarget, files, manifest);
|
|
557
715
|
const scope = effectiveTarget.scope;
|
|
558
716
|
const commitMode = effectiveTarget.commitMode ?? 'commit';
|
|
559
717
|
const lockPath = (0, framework_1.lockfilePathForTarget)(ctx, effectiveTarget);
|
|
@@ -564,17 +722,19 @@ async function performLocalInstall(opts, target, ctx, fmt) {
|
|
|
564
722
|
sourceId: localSourceId,
|
|
565
723
|
sourceType: 'local',
|
|
566
724
|
installedAt: new Date().toISOString(),
|
|
567
|
-
files: (0, app_1.checksumFiles)(targetFiles, result.writtenBundlePaths ?? targetFiles.keys())
|
|
725
|
+
files: (0, app_1.checksumFiles)(targetFiles, result.writtenBundlePaths ?? targetFiles.keys(), result.installedPaths)
|
|
568
726
|
};
|
|
569
727
|
if (scope === 'repository') {
|
|
570
728
|
entry.commitMode = commitMode;
|
|
571
729
|
}
|
|
730
|
+
const previousFiles = existing.bundles[manifest.id]?.files;
|
|
572
731
|
let nextLock = (0, app_1.upsertBundleEntry)(existing, manifest.id, entry);
|
|
573
732
|
nextLock = (0, app_1.upsertSource)(nextLock, localSourceId, {
|
|
574
733
|
type: 'local',
|
|
575
734
|
url: path.resolve(ctx.cwd(), opts.from)
|
|
576
735
|
});
|
|
577
736
|
await (0, app_1.writeLockfile)(lockPath, nextLock, ctx.fs);
|
|
737
|
+
await (0, app_1.removeSupersededFiles)(writer, effectiveTarget, previousFiles, entry.files);
|
|
578
738
|
await updateTargetState(ctx, effectiveTarget.name, manifest.id, manifest.version);
|
|
579
739
|
(0, framework_2.formatOutput)({
|
|
580
740
|
ctx,
|
|
@@ -628,6 +788,9 @@ async function performLockfileInstall(opts, target, ctx, fmt) {
|
|
|
628
788
|
const tokens = opts.tokens ?? (0, infra_1.defaultTokenProvider)(ctx.env);
|
|
629
789
|
const writerFactory = (0, exports.createWriterFactory)(ctx, opts);
|
|
630
790
|
const writer = writerFactory(effectiveTarget);
|
|
791
|
+
const sourceAwareDependencyCache = (0, infra_1.isGitHubAppAuthEnabled)(ctx.env)
|
|
792
|
+
? createSourceAwareInstallDependencyCache(http, ctx)
|
|
793
|
+
: undefined;
|
|
631
794
|
const { replayed, failures } = await replayLockfileEntries({
|
|
632
795
|
bundleIds,
|
|
633
796
|
lock,
|
|
@@ -636,7 +799,8 @@ async function performLockfileInstall(opts, target, ctx, fmt) {
|
|
|
636
799
|
writer,
|
|
637
800
|
target: effectiveTarget,
|
|
638
801
|
ctx,
|
|
639
|
-
verbose: opts.verbose ?? false
|
|
802
|
+
verbose: opts.verbose ?? false,
|
|
803
|
+
sourceAwareDependencyCache
|
|
640
804
|
});
|
|
641
805
|
if (replayed.length > 0) {
|
|
642
806
|
await updateTargetStateFromLockfile(ctx, effectiveTarget.name, lock, replayed);
|
|
@@ -698,19 +862,55 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
698
862
|
}
|
|
699
863
|
const http = opts.http ?? new infra_1.NodeHttpClient();
|
|
700
864
|
const tokens = opts.tokens ?? (0, infra_1.defaultTokenProvider)(ctx.env);
|
|
701
|
-
const
|
|
702
|
-
|
|
865
|
+
const isArtifactory = opts.sourceConfig?.type === 'artifactory';
|
|
866
|
+
let githubApi;
|
|
867
|
+
let downloadTokens;
|
|
868
|
+
let repositoryTarget;
|
|
869
|
+
let authenticationCategory;
|
|
870
|
+
if (isArtifactory) {
|
|
871
|
+
githubApi = githubApiFor(http, tokens);
|
|
872
|
+
downloadTokens = tokens;
|
|
873
|
+
}
|
|
874
|
+
else if ((0, infra_1.isGitHubAppAuthEnabled)(ctx.env)) {
|
|
875
|
+
const dependencies = opts.sourceAwareDependencyCache === undefined
|
|
876
|
+
? await sourceAwareInstallDependencies(repoSlug, opts.sourceConfig, http, ctx)
|
|
877
|
+
: await opts.sourceAwareDependencyCache.get(repoSlug, opts.sourceConfig);
|
|
878
|
+
githubApi = dependencies.githubApi;
|
|
879
|
+
downloadTokens = dependencies.downloadTokens;
|
|
880
|
+
repositoryTarget = dependencies.repositoryTarget;
|
|
881
|
+
authenticationCategory = dependencies.authenticationCategory;
|
|
882
|
+
}
|
|
883
|
+
else {
|
|
884
|
+
githubApi = githubApiFor(http, tokens);
|
|
885
|
+
downloadTokens = tokens;
|
|
886
|
+
}
|
|
887
|
+
// Use SourceDispatcher to select the appropriate resolver based on source config.
|
|
703
888
|
let resolver;
|
|
704
|
-
|
|
889
|
+
let downloader;
|
|
890
|
+
if (isArtifactory && opts.sourceConfig !== undefined) {
|
|
891
|
+
const config = opts.sourceConfig.config ?? {};
|
|
892
|
+
const credentialRef = typeof config.credentialRef === 'string' ? config.credentialRef : undefined;
|
|
893
|
+
const credentials = config.authMode === 'bearer' && credentialRef !== undefined
|
|
894
|
+
? new infra_1.ArtifactoryEnvCredentialProvider(ctx.env, credentialRef, opts.sourceConfig.url)
|
|
895
|
+
: new infra_1.AnonymousCredentialProvider();
|
|
896
|
+
const artifactoryHttp = new infra_1.ArtifactoryHttpClient(http, credentials, opts.sourceConfig.url);
|
|
897
|
+
const dispatcher = new infra_1.SourceDispatcher({
|
|
898
|
+
githubApi, fs: ctx.fs, http,
|
|
899
|
+
artifactoryCredentialProvider: () => credentials
|
|
900
|
+
});
|
|
901
|
+
resolver = dispatcher.resolverFor(opts.sourceConfig);
|
|
902
|
+
downloader = new infra_1.ArtifactoryBundleDownloader(artifactoryHttp);
|
|
903
|
+
}
|
|
904
|
+
else if (opts.sourceConfig) {
|
|
705
905
|
const dispatcher = new infra_1.SourceDispatcher({ githubApi, fs: ctx.fs });
|
|
706
906
|
const selectedResolver = dispatcher.resolverFor(opts.sourceConfig);
|
|
707
907
|
resolver = selectedResolver ?? new infra_1.GitHubBundleResolver({ repoSlug, githubApi });
|
|
908
|
+
downloader = new infra_1.HttpsBundleDownloader(http, downloadTokens, repositoryTarget, authenticationCategory);
|
|
708
909
|
}
|
|
709
910
|
else {
|
|
710
|
-
// Default to GitHub resolver when no source config is provided
|
|
711
911
|
resolver = new infra_1.GitHubBundleResolver({ repoSlug, githubApi });
|
|
912
|
+
downloader = new infra_1.HttpsBundleDownloader(http, downloadTokens, repositoryTarget, authenticationCategory);
|
|
712
913
|
}
|
|
713
|
-
const downloader = new infra_1.HttpsBundleDownloader(http, tokens);
|
|
714
914
|
const extractor = new infra_1.ZipBundleExtractor();
|
|
715
915
|
const installable = await resolver.resolve(spec);
|
|
716
916
|
if (installable === null) {
|
|
@@ -723,10 +923,16 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
723
923
|
}
|
|
724
924
|
const dl = await downloader.download(installable);
|
|
725
925
|
const files = await extractor.extract(dl.bytes);
|
|
926
|
+
// A plain `owner/repo` source and a GitHub source resolved from
|
|
927
|
+
// `--source` check the id source-aware; other hub-driven installs keep
|
|
928
|
+
// accepting the manifest id as-is.
|
|
929
|
+
const sourceRepoSlug = opts.sourceConfig === undefined ? repoSlug : opts.sourceRepoSlug;
|
|
726
930
|
const manifest = (0, core_1.validateManifest)(files, {
|
|
727
|
-
expectedId: opts.sourceConfig === undefined ? spec.bundleId : undefined,
|
|
728
|
-
|
|
931
|
+
expectedId: opts.sourceConfig === undefined || opts.sourceRepoSlug !== undefined ? spec.bundleId : undefined,
|
|
932
|
+
sourceRepoSlug,
|
|
933
|
+
expectedVersion: isArtifactory ? installable.ref.bundleVersion : (spec.bundleVersion === 'latest' ? undefined : spec.bundleVersion)
|
|
729
934
|
});
|
|
935
|
+
const lockKey = isArtifactory ? installable.ref.bundleId : manifest.id;
|
|
730
936
|
if (opts.dryRun === true) {
|
|
731
937
|
(0, framework_2.formatOutput)({
|
|
732
938
|
ctx,
|
|
@@ -736,8 +942,8 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
736
942
|
data: {
|
|
737
943
|
dryRun: true,
|
|
738
944
|
target: effectiveTarget.name,
|
|
739
|
-
bundle: { id:
|
|
740
|
-
source: { type: 'github', repo: repoSlug, downloadUrl: installable.downloadUrl },
|
|
945
|
+
bundle: { id: lockKey, version: manifest.version },
|
|
946
|
+
source: { type: opts.sourceConfig?.type ?? 'github', repo: repoSlug, downloadUrl: installable.downloadUrl },
|
|
741
947
|
sha256: dl.sha256,
|
|
742
948
|
files: [...files.keys()]
|
|
743
949
|
},
|
|
@@ -749,8 +955,7 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
749
955
|
}
|
|
750
956
|
const writerFactory = (0, exports.createWriterFactory)(ctx, opts);
|
|
751
957
|
const writer = writerFactory(effectiveTarget);
|
|
752
|
-
const targetFiles = (0,
|
|
753
|
-
const result = await (0, app_1.writeTargetSafely)(writer, effectiveTarget, targetFiles);
|
|
958
|
+
const { installableFiles: targetFiles, result } = await (0, app_1.writeBundleSafely)(writer, effectiveTarget, files, manifest);
|
|
754
959
|
const scope = effectiveTarget.scope;
|
|
755
960
|
const commitMode = effectiveTarget.commitMode ?? 'commit';
|
|
756
961
|
const lockPath = (0, framework_1.lockfilePathForTarget)(ctx, effectiveTarget);
|
|
@@ -761,19 +966,29 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
761
966
|
sourceType: installable.ref.sourceType,
|
|
762
967
|
checksum: dl.sha256,
|
|
763
968
|
installedAt: new Date().toISOString(),
|
|
764
|
-
files: (0, app_1.checksumFiles)(targetFiles, result.writtenBundlePaths ?? targetFiles.keys())
|
|
969
|
+
files: (0, app_1.checksumFiles)(targetFiles, result.writtenBundlePaths ?? targetFiles.keys(), result.installedPaths)
|
|
765
970
|
};
|
|
766
971
|
if (scope === 'repository') {
|
|
767
972
|
entry.commitMode = commitMode;
|
|
768
973
|
}
|
|
769
|
-
|
|
770
|
-
|
|
974
|
+
const previousFiles = existing.bundles[lockKey]?.files;
|
|
975
|
+
let nextLock = (0, app_1.upsertBundleEntry)(existing, lockKey, entry);
|
|
976
|
+
const sourceConfig = opts.sourceConfig;
|
|
977
|
+
const collectionsPath = sourceConfig?.config?.collectionsPath;
|
|
771
978
|
nextLock = (0, app_1.upsertSource)(nextLock, installable.ref.sourceId, {
|
|
772
|
-
type: 'github',
|
|
773
|
-
url: `https://github.com/${repoSlug}`,
|
|
774
|
-
...(collectionsPath ? { collectionsPath } : {})
|
|
979
|
+
type: sourceConfig?.type ?? 'github',
|
|
980
|
+
url: sourceConfig?.url ?? `https://github.com/${repoSlug}`,
|
|
981
|
+
...(collectionsPath ? { collectionsPath } : {}),
|
|
982
|
+
...(sourceConfig?.type === 'artifactory'
|
|
983
|
+
? {
|
|
984
|
+
indexFile: typeof sourceConfig.config?.indexFile === 'string' ? sourceConfig.config.indexFile : undefined,
|
|
985
|
+
authMode: sourceConfig.config?.authMode === 'bearer' ? 'bearer' : 'anonymous',
|
|
986
|
+
credentialRef: typeof sourceConfig.config?.credentialRef === 'string' ? sourceConfig.config.credentialRef : undefined
|
|
987
|
+
}
|
|
988
|
+
: {})
|
|
775
989
|
});
|
|
776
990
|
await (0, app_1.writeLockfile)(lockPath, nextLock, ctx.fs);
|
|
991
|
+
await (0, app_1.removeSupersededFiles)(writer, effectiveTarget, previousFiles, entry.files);
|
|
777
992
|
(0, framework_2.formatOutput)({
|
|
778
993
|
ctx,
|
|
779
994
|
command: 'install',
|
|
@@ -781,8 +996,8 @@ async function performRemoteInstall(opts, target, ctx, fmt) {
|
|
|
781
996
|
status: 'ok',
|
|
782
997
|
data: {
|
|
783
998
|
target: effectiveTarget.name,
|
|
784
|
-
bundle: { id:
|
|
785
|
-
source: { type: 'github', repo: repoSlug, sourceId: installable.ref.sourceId },
|
|
999
|
+
bundle: { id: lockKey, version: manifest.version },
|
|
1000
|
+
source: { type: opts.sourceConfig?.type ?? 'github', repo: repoSlug, sourceId: installable.ref.sourceId },
|
|
786
1001
|
sha256: dl.sha256,
|
|
787
1002
|
written: result.written,
|
|
788
1003
|
skipped: result.skipped,
|
|
@@ -922,9 +1137,9 @@ const createInstallCommand = (opts = {}) => (0, framework_2.defineCommand)({
|
|
|
922
1137
|
}));
|
|
923
1138
|
}
|
|
924
1139
|
try {
|
|
925
|
-
const targetName = await (0, framework_2.resolveTargetName)(opts.target, 'install', ctx, () => (0,
|
|
1140
|
+
const targetName = await (0, framework_2.resolveTargetName)(opts.target, 'install', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
926
1141
|
checkAllowTarget(targetName, opts);
|
|
927
|
-
const configuredTarget = await (0, framework_2.resolveTarget)(targetName, 'install', ctx, () => (0,
|
|
1142
|
+
const configuredTarget = await (0, framework_2.resolveTarget)(targetName, 'install', ctx, () => (0, framework_1.loadTargets)(ctx));
|
|
928
1143
|
const target = (0, framework_2.resolveEffectiveTarget)(ctx, configuredTarget, opts);
|
|
929
1144
|
if (opts.from !== undefined && opts.from.length > 0) {
|
|
930
1145
|
return await performLocalInstall(opts, target, ctx, fmt);
|
|
@@ -944,7 +1159,7 @@ const createInstallCommand = (opts = {}) => (0, framework_2.defineCommand)({
|
|
|
944
1159
|
});
|
|
945
1160
|
exports.createInstallCommand = createInstallCommand;
|
|
946
1161
|
async function replayLockfileEntries(opts) {
|
|
947
|
-
const { bundleIds, lock, http, tokens, writer, target, ctx, verbose } = opts;
|
|
1162
|
+
const { bundleIds, lock, http, tokens, writer, target, ctx, verbose, sourceAwareDependencyCache } = opts;
|
|
948
1163
|
const replayed = [];
|
|
949
1164
|
const failures = [];
|
|
950
1165
|
if (verbose) {
|
|
@@ -961,7 +1176,8 @@ async function replayLockfileEntries(opts) {
|
|
|
961
1176
|
writer,
|
|
962
1177
|
target,
|
|
963
1178
|
ctx,
|
|
964
|
-
verbose
|
|
1179
|
+
verbose,
|
|
1180
|
+
sourceAwareDependencyCache
|
|
965
1181
|
});
|
|
966
1182
|
if (result.success) {
|
|
967
1183
|
replayed.push(bundleId);
|
|
@@ -973,29 +1189,32 @@ async function replayLockfileEntries(opts) {
|
|
|
973
1189
|
return { replayed, failures };
|
|
974
1190
|
}
|
|
975
1191
|
async function replaySingleEntry(opts) {
|
|
976
|
-
const { bundleId, entry, sources, http, tokens, writer, target, ctx, verbose } = opts;
|
|
1192
|
+
const { bundleId, entry, sources, http, tokens, writer, target, ctx, verbose, sourceAwareDependencyCache } = opts;
|
|
977
1193
|
const src = sources[entry.sourceId];
|
|
978
1194
|
if (src === undefined) {
|
|
979
1195
|
return handleMissingSource(bundleId, entry, verbose, ctx);
|
|
980
1196
|
}
|
|
981
1197
|
try {
|
|
982
|
-
const files = await fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verbose);
|
|
1198
|
+
const files = await fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verbose, sourceAwareDependencyCache);
|
|
983
1199
|
if (files === null) {
|
|
984
1200
|
return handleFetchFailure(bundleId, src, verbose, ctx);
|
|
985
1201
|
}
|
|
986
|
-
await validateAndWrite(files, bundleId, entry, writer, target, ctx, verbose);
|
|
1202
|
+
await validateAndWrite(files, bundleId, entry, writer, target, ctx, verbose, src);
|
|
987
1203
|
return { success: true, reason: '' };
|
|
988
1204
|
}
|
|
989
1205
|
catch (cause) {
|
|
990
1206
|
return handleInstallError(bundleId, cause, verbose, ctx);
|
|
991
1207
|
}
|
|
992
1208
|
}
|
|
993
|
-
async function validateAndWrite(files, bundleId, entry, writer, target, ctx, verbose) {
|
|
1209
|
+
async function validateAndWrite(files, bundleId, entry, writer, target, ctx, verbose, src) {
|
|
994
1210
|
const manifest = (0, core_1.validateManifest)(files, {
|
|
995
|
-
expectedId: bundleId,
|
|
996
|
-
expectedVersion: entry.version
|
|
1211
|
+
expectedId: src.type === 'artifactory' ? undefined : bundleId,
|
|
1212
|
+
expectedVersion: entry.version,
|
|
1213
|
+
// Lockfile keys written by `profile activate` keep the hub's
|
|
1214
|
+
// `{owner}-{repo}-{manifestId}` id; match it against the source repo.
|
|
1215
|
+
sourceRepoSlug: (0, app_1.githubRepoSlugForSource)(src)
|
|
997
1216
|
});
|
|
998
|
-
await (0, app_1.
|
|
1217
|
+
await (0, app_1.writeBundleSafely)(writer, target, files, manifest);
|
|
999
1218
|
if (verbose) {
|
|
1000
1219
|
ctx.stdout.write(`[verbose] Successfully installed ${bundleId}\n`);
|
|
1001
1220
|
}
|
|
@@ -1034,9 +1253,10 @@ function handleInstallError(bundleId, cause, verbose, ctx) {
|
|
|
1034
1253
|
* @param tokens Token provider.
|
|
1035
1254
|
* @param ctx CLI context.
|
|
1036
1255
|
* @param verbose Whether to write `[verbose]` progress lines to stdout.
|
|
1256
|
+
* @param sourceAwareDependencyCache Optional command-scoped source-aware cache.
|
|
1037
1257
|
* @returns The extracted files, or `null` if the bundle couldn't be resolved/fetched.
|
|
1038
1258
|
*/
|
|
1039
|
-
async function fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verbose) {
|
|
1259
|
+
async function fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verbose, sourceAwareDependencyCache) {
|
|
1040
1260
|
if (src.type === 'local') {
|
|
1041
1261
|
if (verbose) {
|
|
1042
1262
|
ctx.stdout.write(`[verbose] Reading local bundle from ${src.url}\n`);
|
|
@@ -1044,11 +1264,70 @@ async function fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verb
|
|
|
1044
1264
|
const files = await (0, infra_1.readLocalBundle)(src.url, ctx.fs);
|
|
1045
1265
|
return new Map(files);
|
|
1046
1266
|
}
|
|
1047
|
-
if (src.type === '
|
|
1048
|
-
const
|
|
1267
|
+
if (src.type === 'artifactory') {
|
|
1268
|
+
const sourceConfig = {
|
|
1269
|
+
id: entry.sourceId, name: entry.sourceId, type: 'artifactory', url: src.url,
|
|
1270
|
+
enabled: true, priority: 0,
|
|
1271
|
+
config: {
|
|
1272
|
+
...(src.indexFile ? { indexFile: src.indexFile } : {}),
|
|
1273
|
+
...(src.authMode ? { authMode: src.authMode } : {}),
|
|
1274
|
+
...(src.credentialRef ? { credentialRef: src.credentialRef } : {})
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
const credentialRef = src.credentialRef;
|
|
1278
|
+
const credentials = src.authMode === 'bearer' && credentialRef !== undefined
|
|
1279
|
+
? new infra_1.ArtifactoryEnvCredentialProvider(ctx.env, credentialRef, src.url)
|
|
1280
|
+
: new infra_1.AnonymousCredentialProvider();
|
|
1281
|
+
const artifactoryHttp = new infra_1.ArtifactoryHttpClient(http, credentials, src.url);
|
|
1282
|
+
const dispatcher = new infra_1.SourceDispatcher({ githubApi: githubApiFor(http, tokens), fs: ctx.fs, http, artifactoryCredentialProvider: () => credentials });
|
|
1283
|
+
const resolver = dispatcher.resolverFor(sourceConfig);
|
|
1284
|
+
if (resolver === null) {
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
const installable = await resolver.resolve({ bundleId, bundleVersion: entry.version });
|
|
1288
|
+
if (installable === null) {
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
const dl = await new infra_1.ArtifactoryBundleDownloader(artifactoryHttp).download(installable);
|
|
1292
|
+
if (entry.checksum !== undefined && dl.sha256 !== entry.checksum) {
|
|
1293
|
+
return null;
|
|
1294
|
+
}
|
|
1295
|
+
return new Map(await new infra_1.ZipBundleExtractor().extract(dl.bytes));
|
|
1296
|
+
}
|
|
1297
|
+
if (src.type === 'github' || src.type === 'skills' || src.type === 'awesome-copilot') {
|
|
1049
1298
|
// Check if this is an awesome-copilot source (detected by sourceId prefix)
|
|
1050
|
-
const isAwesomeCopilot =
|
|
1051
|
-
|
|
1299
|
+
const isAwesomeCopilot = src.type === 'awesome-copilot'
|
|
1300
|
+
|| bundleId.startsWith('awesome-copilot-')
|
|
1301
|
+
|| entry.sourceId.startsWith('awesome-copilot-');
|
|
1302
|
+
const sourceConfig = {
|
|
1303
|
+
id: entry.sourceId,
|
|
1304
|
+
name: entry.sourceId,
|
|
1305
|
+
type: isAwesomeCopilot ? 'awesome-copilot' : (src.type === 'skills' ? 'skills' : 'github'),
|
|
1306
|
+
url: src.url,
|
|
1307
|
+
enabled: true,
|
|
1308
|
+
priority: 0,
|
|
1309
|
+
config: {
|
|
1310
|
+
branch: src.branch,
|
|
1311
|
+
collectionsPath: src.collectionsPath
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
const repoSlug = extractRepoSlug(src.url);
|
|
1315
|
+
let githubApi;
|
|
1316
|
+
let downloadTokens = tokens;
|
|
1317
|
+
let repositoryTarget;
|
|
1318
|
+
let authenticationCategory;
|
|
1319
|
+
if ((0, infra_1.isGitHubAppAuthEnabled)(ctx.env)) {
|
|
1320
|
+
const dependencies = sourceAwareDependencyCache === undefined
|
|
1321
|
+
? await sourceAwareInstallDependencies(repoSlug, sourceConfig, http, ctx)
|
|
1322
|
+
: await sourceAwareDependencyCache.get(repoSlug, sourceConfig);
|
|
1323
|
+
githubApi = dependencies.githubApi;
|
|
1324
|
+
downloadTokens = dependencies.downloadTokens;
|
|
1325
|
+
repositoryTarget = dependencies.repositoryTarget;
|
|
1326
|
+
authenticationCategory = dependencies.authenticationCategory;
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
githubApi = githubApiFor(http, tokens);
|
|
1330
|
+
}
|
|
1052
1331
|
if (verbose) {
|
|
1053
1332
|
ctx.stdout.write(`[verbose] Resolving ${bundleId}@${entry.version} from ${repoSlug} (${isAwesomeCopilot ? 'awesome-copilot' : 'github'})\n`);
|
|
1054
1333
|
}
|
|
@@ -1073,7 +1352,7 @@ async function fetchFilesForSource(src, bundleId, entry, http, tokens, ctx, verb
|
|
|
1073
1352
|
}
|
|
1074
1353
|
// Use GitHub resolver for regular github sources
|
|
1075
1354
|
const resolver = new infra_1.GitHubBundleResolver({ repoSlug, githubApi });
|
|
1076
|
-
const downloader = new infra_1.HttpsBundleDownloader(http,
|
|
1355
|
+
const downloader = new infra_1.HttpsBundleDownloader(http, downloadTokens, repositoryTarget, authenticationCategory);
|
|
1077
1356
|
const installable = await resolver.resolve({ bundleId, bundleVersion: entry.version });
|
|
1078
1357
|
if (installable === null) {
|
|
1079
1358
|
if (verbose) {
|