@rbbtsn0w/adg 0.6.0 → 0.7.0-beta.1

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.
Files changed (83) hide show
  1. package/README.md +41 -9
  2. package/dist/bin/adg.js +4 -4
  3. package/dist/src/adapters/codex.js +12 -0
  4. package/dist/src/adapters/reverse.js +22 -1
  5. package/dist/src/agents/base.js +2 -1
  6. package/dist/src/agents/claude.js +52 -6
  7. package/dist/src/agents/codex.js +94 -14
  8. package/dist/src/cli/core-plugin-handlers.js +97 -0
  9. package/dist/src/cli/handlers.js +155 -210
  10. package/dist/src/cli/index.js +14 -4
  11. package/dist/src/codex-marketplace-migration.js +139 -0
  12. package/dist/src/commands/cache.js +92 -15
  13. package/dist/src/commands/inspect.js +41 -0
  14. package/dist/src/commands/install.js +140 -73
  15. package/dist/src/commands/link.js +4 -16
  16. package/dist/src/commands/marketplace.js +74 -20
  17. package/dist/src/commands/migrate.js +15 -3
  18. package/dist/src/commands/projection.js +15 -0
  19. package/dist/src/commands/select-components.js +12 -0
  20. package/dist/src/commands/state.js +4 -2
  21. package/dist/src/commands/sync.js +9 -15
  22. package/dist/src/commands/update.js +51 -10
  23. package/dist/src/commands/validate.js +9 -2
  24. package/dist/src/components.js +3 -0
  25. package/dist/src/default-dsl.js +142 -0
  26. package/dist/src/lock.js +25 -7
  27. package/dist/src/manifest.js +85 -4
  28. package/dist/src/materialize.js +5 -1
  29. package/dist/src/mcp.js +59 -0
  30. package/dist/src/paths.js +31 -4
  31. package/dist/src/render/plugins.js +7 -1
  32. package/dist/src/source-cache.js +140 -0
  33. package/dist/src/sources.js +76 -5
  34. package/dist/src/subprocess.js +53 -0
  35. package/dist/src/telemetry.js +28 -21
  36. package/dist/src/types.js +5 -1
  37. package/dist/vendor/skills/src/add.js +0 -15
  38. package/dist/vendor/skills/src/cli.js +6 -1
  39. package/dist/vendor/skills/src/git-tree.js +4 -4
  40. package/dist/vendor/skills/src/skill-lock.js +4 -3
  41. package/dist/vendor/skills/src/update.js +38 -77
  42. package/dist/vendor/skills/src/use.js +28 -4
  43. package/docs/agents-spec.md +27 -4
  44. package/docs/authoring.md +19 -2
  45. package/docs/branching-and-release.md +52 -0
  46. package/package.json +14 -3
  47. package/schemas/adg-plugin.schema.json +2 -0
  48. package/schemas/plugin-lock.schema.json +23 -1
  49. package/vendor/skills/PROVENANCE.md +2 -0
  50. package/vendor/skills/package.json +0 -144
  51. package/vendor/skills/src/add.ts +0 -2213
  52. package/vendor/skills/src/agents.ts +0 -811
  53. package/vendor/skills/src/blob.ts +0 -588
  54. package/vendor/skills/src/cli.ts +0 -391
  55. package/vendor/skills/src/constants.ts +0 -3
  56. package/vendor/skills/src/detect-agent.ts +0 -62
  57. package/vendor/skills/src/find.ts +0 -419
  58. package/vendor/skills/src/frontmatter.ts +0 -16
  59. package/vendor/skills/src/git-tree.ts +0 -36
  60. package/vendor/skills/src/git.ts +0 -277
  61. package/vendor/skills/src/install.ts +0 -91
  62. package/vendor/skills/src/installer.ts +0 -1307
  63. package/vendor/skills/src/list.ts +0 -231
  64. package/vendor/skills/src/local-lock.ts +0 -189
  65. package/vendor/skills/src/plugin-manifest.ts +0 -183
  66. package/vendor/skills/src/prompts/search-multiselect.ts +0 -387
  67. package/vendor/skills/src/providers/index.ts +0 -14
  68. package/vendor/skills/src/providers/registry.ts +0 -51
  69. package/vendor/skills/src/providers/types.ts +0 -97
  70. package/vendor/skills/src/providers/wellknown.ts +0 -812
  71. package/vendor/skills/src/remove.ts +0 -335
  72. package/vendor/skills/src/sanitize.ts +0 -65
  73. package/vendor/skills/src/self-cli.ts +0 -20
  74. package/vendor/skills/src/skill-lock.ts +0 -329
  75. package/vendor/skills/src/skills.ts +0 -316
  76. package/vendor/skills/src/source-parser.ts +0 -449
  77. package/vendor/skills/src/sync.ts +0 -478
  78. package/vendor/skills/src/telemetry.ts +0 -226
  79. package/vendor/skills/src/test-utils.ts +0 -73
  80. package/vendor/skills/src/types.ts +0 -129
  81. package/vendor/skills/src/update-source.ts +0 -90
  82. package/vendor/skills/src/update.ts +0 -821
  83. package/vendor/skills/src/use.ts +0 -682
@@ -1,4 +1,4 @@
1
- import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
1
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
3
  import { basename, join, relative, resolve } from "node:path";
4
4
  import { isDeepStrictEqual } from "node:util";
@@ -6,20 +6,22 @@ import { ADAPTER_TARGETS } from "../adapters/index.js";
6
6
  import { fromNativeManifest } from "../adapters/reverse.js";
7
7
  import { adaptPlugin } from "./adapt.js";
8
8
  import { removePlugin } from "./remove.js";
9
- import { toPosix, writeJson } from "../fsutil.js";
9
+ import { copyPluginDir, toPosix, writeJson } from "../fsutil.js";
10
10
  import { folderHash } from "../hash.js";
11
11
  import { packageFilter, PROJECTION_DIRS } from "../package.js";
12
12
  import { lockPath, marketplacePath, marketplaceSourcePath, pluginDir, pluginSourceCacheDir } from "../paths.js";
13
13
  import { readLock, upsertEntry, writeLock } from "../lock.js";
14
14
  import { ADG_MANIFEST_PATH, readManifest } from "../manifest.js";
15
+ import { recordTelemetryEvent } from "../telemetry.js";
15
16
  import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../marketplace.js";
16
17
  import { resolveInstallOrder } from "../deps.js";
17
- import { cloneGitHub, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
18
+ import { cloneGitHub, gitRevision, githubRepositoryDescription, parseGitHubSource, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
18
19
  import { normalizePluginSelection, pluginState, resolveSelectionDependencies, sameSource, COMPONENT_TYPES } from "../types.js";
19
20
  import { pluginContents, presentComponents } from "../components.js";
20
21
  import { skillDescriptionLoader } from "../skills.js";
21
22
  import { resolveAgents } from "../agents/index.js";
22
23
  import { effectivePackageFilter, materializePlugin, withPluginSourceCache } from "../materialize.js";
24
+ import { resolveDefaultDsl } from "../default-dsl.js";
23
25
  // Generated runtime projections never count toward a plugin's content hash.
24
26
  const HASH_IGNORE = PROJECTION_DIRS;
25
27
  /** Content hash over a plugin's packaged payload (hooks files are authored content, not generated). */
@@ -38,7 +40,7 @@ function contentHash(dir, manifest) {
38
40
  */
39
41
  export function installPlugin(opts) {
40
42
  const source = resolve(opts.source);
41
- const manifest = readManifest(source);
43
+ const manifest = readManifest(source, opts.telemetrySpan);
42
44
  const name = manifest.name;
43
45
  // Local installs stay flat; remote sources derive a per-marketplace dir from
44
46
  // their origin. The default (no origin) is a flat local copy-in.
@@ -55,6 +57,27 @@ export function installPlugin(opts) {
55
57
  // partial installs survive re-install / `marketplace upgrade`.
56
58
  const desiredSelection = normalizePluginSelection(opts.selection ?? prev?.selection);
57
59
  const selection = resolveSelectionDependencies(manifest, desiredSelection);
60
+ if (selection) {
61
+ const contents = pluginContents(source, manifest);
62
+ if (selection.skills) {
63
+ const invalid = selection.skills.filter((s) => !contents.skills.includes(s));
64
+ if (invalid.length > 0) {
65
+ throw new Error(`selected skill(s) not declared: ${invalid.join(", ")}`);
66
+ }
67
+ }
68
+ if (selection.mcp) {
69
+ const invalid = selection.mcp.filter((s) => !contents.mcp.includes(s));
70
+ if (invalid.length > 0) {
71
+ throw new Error(`selected mcp server(s) not declared: ${invalid.join(", ")}`);
72
+ }
73
+ }
74
+ recordTelemetryEvent("adg.install.selection", {
75
+ plugin: name,
76
+ "components.count": selection.components.length,
77
+ "skills.count": selection.skills ? selection.skills.length : -1,
78
+ "mcp.count": selection.mcp ? selection.mcp.length : -1,
79
+ }, opts.telemetrySpan);
80
+ }
58
81
  const sourceHash = contentHash(source, manifest);
59
82
  const cacheDir = pluginSourceCacheDir(opts.pluginsDir, name);
60
83
  return withPluginSourceCache(source, cacheDir, manifest, (snapshot) => {
@@ -95,6 +118,7 @@ export function installPlugin(opts) {
95
118
  version: manifest.version,
96
119
  sourceHash,
97
120
  installedHash,
121
+ ...(opts.resolvedRevision ? { resolvedRevision: opts.resolvedRevision } : {}),
98
122
  };
99
123
  if (manifest.dependencies?.length) {
100
124
  entry.dependencies = Object.fromEntries(manifest.dependencies.map((d) => [d.name, d.version]));
@@ -103,6 +127,8 @@ export function installPlugin(opts) {
103
127
  entry.selection = desiredSelection;
104
128
  if (prev?.state)
105
129
  entry.state = prev.state;
130
+ if (opts.definition)
131
+ entry.definition = opts.definition;
106
132
  const previousEntry = prev && Object.fromEntries(Object.entries(prev).filter(([key]) => key !== "installedAt" && key !== "updatedAt"));
107
133
  const changed = !prev || !isDeepStrictEqual(previousEntry, entry);
108
134
  if (changed) {
@@ -140,23 +166,14 @@ function discoverPlugins(root) {
140
166
  if (native.kind === "adg")
141
167
  continue;
142
168
  const raw = JSON.parse(readFileSync(native.manifestFile, "utf8"));
143
- const manifest = fromNativeManifest(raw, native.kind);
144
- // A Claude manifest omits `hooks` (Claude auto-loads hooks/hooks.json), and
145
- // `walkNative` prefers it over a sibling Codex manifest that *does* declare
146
- // hooks — so the reverse-adapt would silently drop the hooks payload. Recover
147
- // it from disk: a hooks/ directory means the ADG manifest must declare it, or
148
- // packagedRoots won't copy it and every downstream projection loses hooks.
149
- const hooksDir = join(native.dir, "hooks");
150
- if (!manifest.hooks && existsSync(hooksDir) && statSync(hooksDir).isDirectory()) {
151
- manifest.hooks = "./hooks/";
152
- }
169
+ const manifest = fromNativeManifest(raw, native.kind, native.dir);
153
170
  writeJson(join(native.dir, ADG_MANIFEST_PATH), manifest);
154
171
  converted.push(manifest.name);
155
172
  }
156
173
  return { candidates: scanPlugins(root), converted };
157
174
  }
158
175
  /** Resolve which discovered plugins to install from the selection options. */
159
- async function selectPluginNames(opts, candidates, workRoot, converted) {
176
+ async function selectPluginNames(opts, candidates, converted) {
160
177
  const names = [...candidates.keys()];
161
178
  if (opts.plugins?.length) {
162
179
  const missing = opts.plugins.filter((p) => !candidates.has(p));
@@ -165,13 +182,6 @@ async function selectPluginNames(opts, candidates, workRoot, converted) {
165
182
  }
166
183
  return opts.plugins.filter((p) => candidates.has(p));
167
184
  }
168
- if (opts.path) {
169
- const target = resolve(join(workRoot, opts.path));
170
- const hit = [...candidates.values()].find((c) => resolve(c.dir) === target);
171
- if (!hit)
172
- throw new Error(`no plugin found at --path ${opts.path}`);
173
- return [hit.manifest.name];
174
- }
175
185
  if (opts.all || candidates.size === 1)
176
186
  return names;
177
187
  if (opts.selectPlugins) {
@@ -196,15 +206,21 @@ async function selectPluginNames(opts, candidates, workRoot, converted) {
196
206
  */
197
207
  async function resolveSelections(opts, selected, candidates) {
198
208
  const selections = new Map();
199
- if (opts.only || opts.skillsSubset) {
209
+ if (opts.only || opts.skillsSubset || opts.mcpSubset) {
200
210
  const flagSelection = {
201
211
  components: opts.only ?? [...COMPONENT_TYPES],
202
212
  ...(opts.skillsSubset ? { skills: opts.skillsSubset } : {}),
213
+ ...(opts.mcpSubset ? { mcp: opts.mcpSubset } : {}),
203
214
  };
204
215
  for (const name of selected)
205
216
  selections.set(name, flagSelection);
206
217
  return selections;
207
218
  }
219
+ if (opts.replaySelection) {
220
+ for (const name of selected)
221
+ selections.set(name, opts.replaySelection);
222
+ return selections;
223
+ }
208
224
  if (!opts.confirmFull || !opts.selectComponents)
209
225
  return selections; // non-interactive default: full
210
226
  if (await opts.confirmFull(selected))
@@ -214,7 +230,7 @@ async function resolveSelections(opts, selected, candidates) {
214
230
  const contents = pluginContents(cand.dir, cand.manifest);
215
231
  const present = presentComponents(contents);
216
232
  // Nothing meaningful to pick: a lone category with at most one member.
217
- if (present.length <= 1 && contents.skills.length <= 1)
233
+ if (present.length <= 1 && contents.skills.length <= 1 && contents.mcp.length <= 1)
218
234
  continue;
219
235
  const skillDescription = skillDescriptionLoader(cand.dir, cand.manifest);
220
236
  selections.set(name, await opts.selectComponents({ name, contents, present, skillDescription }));
@@ -236,13 +252,12 @@ function sameRemoteSource(entry, parsed, ref) {
236
252
  * (`--plugin one` after previously installing `--all`) without leaving stale
237
253
  * runtime exports behind.
238
254
  */
239
- function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
255
+ function reconcileRemotePlugins(opts, parsed, ref, desired) {
240
256
  if (parsed.kind === "local")
241
257
  return [];
242
- // A path/sparse install does not prove the full source shape, so it must not
243
- // prune sibling plugins from the same repo that were intentionally excluded
244
- // from the checkout/selection window.
245
- if (narrowed || opts.sparse?.length)
258
+ // A sparse checkout does not prove the full source shape, so it must not
259
+ // prune sibling plugins from the same repo that were intentionally excluded.
260
+ if (opts.sparse?.length)
246
261
  return [];
247
262
  const lock = readLock(lockPath(opts.pluginsDir));
248
263
  const stale = Object.entries(lock.plugins)
@@ -268,42 +283,110 @@ function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
268
283
  }
269
284
  return stale;
270
285
  }
286
+ function activateInstalled(opts, targets, installed, existingPlugins) {
287
+ const updatedLock = readLock(lockPath(opts.pluginsDir));
288
+ const eligible = installed.filter((result) => pluginState(updatedLock.plugins[result.name]) === "enabled");
289
+ const toActivate = opts.skipUnchanged ? eligible.filter((result) => result.changed) : eligible;
290
+ if (!opts.activate || toActivate.length === 0)
291
+ return undefined;
292
+ const resolved = opts.agents ?? resolveAgents(targets);
293
+ const scope = opts.scope ?? "project";
294
+ const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
295
+ return resolved.map((agent) => {
296
+ const queryResult = agent.listInstalled?.(ctxFor([]));
297
+ const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
298
+ const alreadyInstalled = (name) => agentInstalled !== undefined
299
+ ? agentInstalled.includes(name)
300
+ : existingPlugins.has(name);
301
+ const activateNames = toActivate.filter((result) => !alreadyInstalled(result.name)).map((result) => result.name);
302
+ const refreshNames = toActivate.filter((result) => alreadyInstalled(result.name)).map((result) => result.name);
303
+ const parts = [];
304
+ if (activateNames.length > 0)
305
+ parts.push(agent.activate(ctxFor(activateNames)));
306
+ if (refreshNames.length > 0)
307
+ parts.push(agent.refresh(ctxFor(refreshNames)));
308
+ return parts.reduce((acc, result) => ({ agent: result.agent, affected: [...acc.affected, ...result.affected], skipped: acc.skipped && result.skipped }), { agent: agent.id, affected: [], skipped: true });
309
+ });
310
+ }
271
311
  /**
272
312
  * The unified install entrypoint. Treats any source as a marketplace: clone or
273
313
  * read it, discover every plugin (ADG plus reverse-adapted native), choose a
274
- * subset (--all / --plugin / --path / sole plugin / interactive picker), then
314
+ * subset (--all / --plugin / sole plugin / interactive picker), then
275
315
  * install the selection in dependency-first order.
276
316
  */
277
317
  export async function addPlugins(opts) {
278
- const parsed = parseSource(opts.spec);
318
+ // Prepared checkouts are used only by remote marketplace update. Parse their
319
+ // persisted owner/repo key as GitHub even when the caller's CWD shadows it.
320
+ const parsed = opts.preparedSourceDir ? parseGitHubSource(opts.spec) : parseSource(opts.spec);
279
321
  const sourceRef = parsed.kind === "local" ? undefined : (opts.ref ?? parsed.ref);
280
- const inferredPath = parsed.kind === "github" ? parsed.path : undefined;
281
- const path = opts.path ?? inferredPath;
322
+ if (parsed.kind === "github" && parsed.path) {
323
+ throw new Error("GitHub subdirectory sources are not supported; define a marketplace and select with --plugin or --all");
324
+ }
282
325
  let workRoot;
283
326
  let buildOrigin;
327
+ let resolvedRevision;
284
328
  let cleanup;
285
- if (parsed.kind === "local") {
329
+ let originDirOverride;
330
+ let definition;
331
+ let defaultDescription;
332
+ let structuralName;
333
+ if (opts.preparedSourceDir) {
334
+ workRoot = resolve(opts.preparedSourceDir);
335
+ resolvedRevision = opts.preparedResolvedRevision;
336
+ buildOrigin = (dir) => ({ type: "github", repo: parsed.kind === "github" ? parsed.source : opts.spec, ...(sourceRef ? { ref: sourceRef } : {}), path: toPosix(relative(workRoot, originDirOverride ?? dir)) || "." });
337
+ }
338
+ else if (parsed.kind === "local") {
286
339
  workRoot = resolve(parsed.dir);
287
- buildOrigin = (dir) => ({ type: "local", path: resolve(dir) });
340
+ buildOrigin = (dir) => ({ type: "local", path: resolve(originDirOverride ?? dir) });
288
341
  }
289
342
  else {
290
343
  const tmp = mkdtempSync(join(tmpdir(), "adg-clone-"));
291
344
  cleanup = () => rmSync(tmp, { recursive: true, force: true });
292
345
  cloneGitHub({ ...parsed, ref: sourceRef }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
293
346
  workRoot = tmp;
347
+ resolvedRevision = gitRevision(tmp);
294
348
  buildOrigin = (dir) => ({
295
349
  type: "github",
296
350
  repo: parsed.source,
297
351
  ...(sourceRef ? { ref: sourceRef } : {}),
298
- path: toPosix(relative(tmp, dir)) || ".",
352
+ path: toPosix(relative(tmp, originDirOverride ?? dir)) || ".",
299
353
  });
300
354
  }
301
355
  try {
302
- const { candidates, converted } = discoverPlugins(workRoot);
356
+ let { candidates, converted } = discoverPlugins(workRoot);
357
+ const existingLock = readLock(lockPath(opts.pluginsDir));
358
+ if (candidates.size > 0 && opts.as) {
359
+ throw new Error("--as is only supported for a default structural plugin source");
360
+ }
303
361
  if (candidates.size === 0) {
304
- throw new Error(`no plugin found in "${opts.spec}" (no .agents/.plugin.json, .claude-plugin or .codex-plugin manifest).`);
362
+ if (parsed.kind === "github" && !opts.preparedSourceDir && !opts.defaultDescription)
363
+ defaultDescription = await githubRepositoryDescription(parsed.source);
364
+ const structuralIdentity = opts.as ?? (parsed.kind === "github" ? parsed.source : basename(workRoot));
365
+ const generated = resolveDefaultDsl(workRoot, {
366
+ name: structuralIdentity,
367
+ description: defaultDescription ?? opts.defaultDescription ?? structuralIdentity,
368
+ }, {
369
+ ...(parsed.kind === "github" && resolvedRevision ? { resolvedRevision } : {}),
370
+ });
371
+ const authorized = opts.authorizedComponents;
372
+ const unauthorizedRisk = generated.components.some((c) => (c === "hooks" || c === "mcp") && !authorized?.includes(c));
373
+ if (opts.nonInteractive && unauthorizedRisk && opts.only === undefined) {
374
+ throw new Error("default source exposes hooks or MCP; pass --only to explicitly authorize selected components");
375
+ }
376
+ const staging = mkdtempSync(join(tmpdir(), "adg-default-plugin-"));
377
+ copyPluginDir(workRoot, staging);
378
+ writeJson(join(staging, ADG_MANIFEST_PATH), generated.manifest);
379
+ candidates = scanPlugins(staging);
380
+ structuralName = generated.manifest.name;
381
+ converted = [];
382
+ originDirOverride = workRoot;
383
+ definition = { kind: "default-dsl/v1", root: ".", ...(opts.as ? { as: generated.manifest.name } : {}), description: generated.manifest.description, fingerprint: generated.fingerprint, authorizedComponents: authorized ?? (opts.only ?? generated.components) };
384
+ cleanup = (() => {
385
+ const prior = cleanup;
386
+ return () => { rmSync(staging, { recursive: true, force: true }); prior?.(); };
387
+ })();
305
388
  }
306
- const selected = await selectPluginNames({ ...opts, path }, candidates, workRoot, converted);
389
+ const selected = structuralName ? [structuralName] : await selectPluginNames(opts, candidates, converted);
307
390
  // Resolve adapter targets after the plugin choice (lets a CLI agent picker
308
391
  // run once we know what's being installed). undefined → installPlugin's all.
309
392
  const targets = opts.targets ?? (opts.selectTargets ? await opts.selectTargets() : undefined);
@@ -313,13 +396,19 @@ export async function addPlugins(opts) {
313
396
  // upstream: don't abort — return what the source still offers so the
314
397
  // caller can report the deletions.
315
398
  if (opts.missingPlugins === "skip") {
316
- const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(selected));
399
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(selected));
317
400
  return { order: [], installed: [], removed, converted, available };
318
401
  }
319
402
  throw new Error("no plugins selected");
320
403
  }
321
404
  // Partial-install selection per user-chosen plugin (auto-deps install full).
322
405
  const selections = await resolveSelections(opts, selected, candidates);
406
+ if (definition && structuralName) {
407
+ definition = {
408
+ ...definition,
409
+ authorizedComponents: selections.get(structuralName)?.components ?? definition.authorizedComponents,
410
+ };
411
+ }
323
412
  // Dependency-first order across every selected plugin (chains deduped).
324
413
  const order = [];
325
414
  const seen = new Set();
@@ -332,7 +421,14 @@ export async function addPlugins(opts) {
332
421
  }
333
422
  }
334
423
  }
335
- const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(order));
424
+ // A generated Default DSL replay retains its definition profile. Only an
425
+ // explicit manifest discovered from the source may replace that profile.
426
+ const definitionSwitches = definition ? [] : order.filter((name) => existingLock.plugins[name]?.definition);
427
+ if (definitionSwitches.length > 0) {
428
+ const names = definitionSwitches.sort().map((name) => `"${name}"`).join(", ");
429
+ throw new Error(`source definition changed from default DSL to a manifest for ${names}; re-add or migrate the plugin explicitly`);
430
+ }
431
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(order));
336
432
  // Snapshot which plugins already existed before this call mutates the lock,
337
433
  // so the activation step below can tell brand-new installs from updates.
338
434
  const existingPlugins = new Set(Object.keys(readLock(lockPath(opts.pluginsDir)).plugins));
@@ -343,11 +439,13 @@ export async function addPlugins(opts) {
343
439
  source: candidate.dir,
344
440
  pluginsDir: opts.pluginsDir,
345
441
  origin: buildOrigin(candidate.dir),
442
+ resolvedRevision,
346
443
  marketplaceName: opts.marketplaceName,
347
444
  targets,
348
445
  selection: selections.get(name),
349
446
  skipUnchanged: opts.skipUnchanged,
350
447
  now: opts.now,
448
+ definition: name === structuralName ? definition : undefined,
351
449
  }));
352
450
  }
353
451
  // Activate into the selected agents so the plugins are actually usable, not
@@ -355,38 +453,7 @@ export async function addPlugins(opts) {
355
453
  // undefined targets = all registered agents. Under skipUnchanged (the update
356
454
  // path) only re-activate plugins that actually changed — re-running an agent
357
455
  // CLI for an untouched plugin is wasted work.
358
- let agents;
359
- const updatedLock = readLock(lockPath(opts.pluginsDir));
360
- const eligible = installed.filter((result) => pluginState(updatedLock.plugins[result.name]) === "enabled");
361
- const toActivate = opts.skipUnchanged ? eligible.filter((r) => r.changed) : eligible;
362
- if (opts.activate && toActivate.length > 0) {
363
- const resolved = opts.agents ?? resolveAgents(targets);
364
- const scope = opts.scope ?? "project";
365
- const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
366
- agents = resolved.map((a) => {
367
- const queryResult = a.listInstalled?.(ctxFor([]));
368
- const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
369
- const alreadyInstalled = (name) => agentInstalled !== undefined
370
- ? agentInstalled.includes(name)
371
- : existingPlugins.has(name);
372
- // Existing plugins must go through refresh even on an explicit `add`:
373
- // agents like Claude cache an installed copy, and their plain install
374
- // command is a no-op when the plugin already exists. If the agent can
375
- // enumerate live installs, trust that state; otherwise fall back to the
376
- // ADG lock to preserve clean-update behavior.
377
- const activateNames = toActivate.filter((r) => !alreadyInstalled(r.name)).map((r) => r.name);
378
- const refreshNames = toActivate.filter((r) => alreadyInstalled(r.name)).map((r) => r.name);
379
- // An agent may run both lifecycles (new installs + updates) in one pass;
380
- // merge into the existing affected/skipped contract so downstream report
381
- // and consolidation (renderAgentReport, mergeAgentResults) stay unchanged.
382
- const parts = [];
383
- if (activateNames.length > 0)
384
- parts.push(a.activate(ctxFor(activateNames)));
385
- if (refreshNames.length > 0)
386
- parts.push(a.refresh(ctxFor(refreshNames)));
387
- return parts.reduce((acc, r) => ({ agent: r.agent, affected: [...acc.affected, ...r.affected], skipped: acc.skipped && r.skipped }), { agent: a.id, affected: [], skipped: true });
388
- });
389
- }
456
+ const agents = activateInstalled(opts, targets, installed, existingPlugins);
390
457
  return { order, installed, removed, converted, available, agents };
391
458
  }
392
459
  finally {
@@ -1,9 +1,6 @@
1
- import { adaptedFilesForTarget, selectInstalled } from "./projection.js";
2
- import { pluginRematerializationSource } from "../paths.js";
1
+ import { adaptedFilesForTarget, rematerializeInstalled, selectInstalled } from "./projection.js";
3
2
  import { getAgent } from "../agents/index.js";
4
- import { ADAPTER_TARGETS } from "../adapters/index.js";
5
3
  import { pluginState } from "../types.js";
6
- import { installPlugin } from "./install.js";
7
4
  /**
8
5
  * Project installed plugins into an agent: (re)generate that agent's manifest
9
6
  * from each plugin (honoring its partial-install selection), then enable the
@@ -20,18 +17,8 @@ export function linkPlugins(opts) {
20
17
  throw new Error(`disabled plugin(s): ${names.join(", ")}. Run \`adg plugins enable ${names.join(" ")}\`.`);
21
18
  }
22
19
  const enabled = selected.filter((p) => pluginState(p) === "enabled");
23
- const actions = [];
24
- for (const p of enabled) {
25
- const result = installPlugin({
26
- source: pluginRematerializationSource(opts.pluginsDir, p.name, p.origin),
27
- pluginsDir: opts.pluginsDir,
28
- origin: p.origin,
29
- selection: p.selection,
30
- targets: [...ADAPTER_TARGETS],
31
- forceMaterialize: true,
32
- });
33
- actions.push({ name: p.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget) });
34
- }
20
+ const actions = rematerializeInstalled(opts.pluginsDir, enabled)
21
+ .map((result) => ({ name: result.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget) }));
35
22
  if (!agent)
36
23
  return { target: opts.target, actions };
37
24
  if (actions.length === 0)
@@ -40,6 +27,7 @@ export function linkPlugins(opts) {
40
27
  pluginsDir: opts.pluginsDir,
41
28
  plugins: actions.map((a) => a.name),
42
29
  scope: opts.global ? "user" : "project",
30
+ ...(opts.target === "codex" ? { reconcileLegacyAliases: true } : {}),
43
31
  });
44
32
  for (const a of actions)
45
33
  if (res.affected.includes(a.name))
@@ -1,3 +1,8 @@
1
+ import { gitRemoteRevision } from "../sources.js";
2
+ import { cloneGitHub, gitRevision, parseGitHubSource } from "../sources.js";
3
+ import { mkdtempSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
1
6
  import { lockPath } from "../paths.js";
2
7
  import { readLock } from "../lock.js";
3
8
  import { addPlugins } from "./install.js";
@@ -113,26 +118,75 @@ export async function updatePlugins(opts) {
113
118
  const remoteAgents = [];
114
119
  for (const group of remoteGroups) {
115
120
  try {
116
- const { installed, available, agents } = await addPlugins({
117
- spec: group.source,
118
- pluginsDir: opts.pluginsDir,
119
- ref: group.ref,
120
- // Default: refresh what's installed. --all: also install anything new.
121
- ...(opts.all ? { all: true } : { plugins: group.installed }),
122
- missingPlugins: "skip", // an upstream deletion is reported, not fatal
123
- skipUnchanged: true, // detect-then-update: leave unchanged plugins alone
124
- targets: opts.targets,
125
- marketplaceName: group.source,
126
- gitRunner: opts.gitRunner,
127
- activate: opts.activate,
128
- scope: opts.agentScope,
129
- agents: opts.agents,
130
- deactivationAgents: opts.deactivationAgents,
131
- now,
121
+ const lock = readLock(lockPath(opts.pluginsDir));
122
+ const revisions = group.installed.map((name) => lock.plugins[name]?.resolvedRevision).filter((revision) => Boolean(revision));
123
+ const remoteRevision = (opts.revisionResolver ?? gitRemoteRevision)(group.source, group.ref);
124
+ if (!opts.all && remoteRevision && revisions.length === group.installed.length && revisions.every((revision) => revision === remoteRevision)) {
125
+ remote.push({ source: group.source, ...(group.ref ? { ref: group.ref } : {}), updated: [], unchanged: [...group.installed].sort(), deleted: [], available: [] });
126
+ continue;
127
+ }
128
+ const structural = group.installed.flatMap((name) => {
129
+ const definition = lock.plugins[name]?.definition;
130
+ return definition ? [{ name, definition, selection: lock.plugins[name]?.selection }] : [];
132
131
  });
133
- if (agents)
134
- remoteAgents.push(...agents);
135
- const availableSet = new Set(available);
132
+ const ordinary = group.installed.filter((name) => !lock.plugins[name]?.definition);
133
+ // A structural profile always describes the source root. Replay each
134
+ // profile independently so its stable --as identity is preserved.
135
+ const requests = [
136
+ ...structural.map(({ name, definition, selection }) => ({
137
+ plugins: [name],
138
+ as: definition.as,
139
+ defaultDescription: definition.description,
140
+ authorizedComponents: definition.authorizedComponents,
141
+ replaySelection: selection ?? (definition.authorizedComponents ? { components: definition.authorizedComponents } : undefined),
142
+ })),
143
+ // A structural profile represents the whole source root. Never append
144
+ // an --all fallback that could derive a second Default DSL identity.
145
+ ...(structural.length === 0 && (ordinary.length > 0 || opts.all)
146
+ ? [{ plugins: opts.all ? undefined : ordinary }]
147
+ : []),
148
+ ];
149
+ const installed = [];
150
+ const available = new Set();
151
+ const checkout = mkdtempSync(join(tmpdir(), "adg-marketplace-update-"));
152
+ try {
153
+ const parsed = parseGitHubSource(group.source);
154
+ cloneGitHub({ ...parsed, ref: group.ref }, checkout, { runner: opts.gitRunner });
155
+ const resolvedRevision = gitRevision(checkout);
156
+ for (const request of requests) {
157
+ const result = await addPlugins({
158
+ spec: group.source,
159
+ pluginsDir: opts.pluginsDir,
160
+ ref: group.ref,
161
+ ...(opts.all && request.plugins === undefined ? { all: true } : { plugins: request.plugins }),
162
+ missingPlugins: "skip",
163
+ skipUnchanged: true,
164
+ nonInteractive: true,
165
+ ...(request.authorizedComponents ? { authorizedComponents: request.authorizedComponents } : {}),
166
+ ...(request.replaySelection ? { replaySelection: request.replaySelection } : {}),
167
+ targets: opts.targets,
168
+ marketplaceName: group.source,
169
+ gitRunner: opts.gitRunner,
170
+ ...(request.as ? { as: request.as } : {}),
171
+ ...(request.defaultDescription ? { defaultDescription: request.defaultDescription } : {}),
172
+ activate: opts.activate,
173
+ scope: opts.agentScope,
174
+ agents: opts.agents,
175
+ deactivationAgents: opts.deactivationAgents,
176
+ now,
177
+ preparedSourceDir: checkout,
178
+ preparedResolvedRevision: resolvedRevision,
179
+ });
180
+ installed.push(...result.installed);
181
+ result.available.forEach((name) => available.add(name));
182
+ if (result.agents)
183
+ remoteAgents.push(...result.agents);
184
+ }
185
+ }
186
+ finally {
187
+ rmSync(checkout, { recursive: true, force: true });
188
+ }
189
+ const availableSet = available;
136
190
  const installedNow = new Set(installed.map((r) => r.name));
137
191
  remote.push({
138
192
  source: group.source,
@@ -140,7 +194,7 @@ export async function updatePlugins(opts) {
140
194
  updated: installed.filter((r) => r.changed).map((r) => r.name).sort(),
141
195
  unchanged: installed.filter((r) => !r.changed).map((r) => r.name).sort(),
142
196
  deleted: group.installed.filter((n) => !availableSet.has(n)).sort(),
143
- available: available.filter((n) => !installedNow.has(n) && !group.installed.includes(n)).sort(),
197
+ available: [...available].filter((n) => !installedNow.has(n) && !group.installed.includes(n)).sort(),
144
198
  });
145
199
  }
146
200
  catch (err) {
@@ -20,7 +20,7 @@ import { LOCK_VERSION, normalizePluginSelection, resolveSelectionDependencies }
20
20
  * plugins already at their target path are reported as unchanged.
21
21
  */
22
22
  export function migrateLayout(pluginsDir, telemetrySpan) {
23
- const lockUpgraded = migrateLockV2(pluginsDir, telemetrySpan);
23
+ const lockUpgraded = migrateLock(pluginsDir, telemetrySpan);
24
24
  const lock = readLock(lockPath(pluginsDir), telemetrySpan);
25
25
  const moved = [];
26
26
  const unchanged = [];
@@ -61,15 +61,27 @@ export function migrateLayout(pluginsDir, telemetrySpan) {
61
61
  * selection-aware materialization, so unselected payload remains recoverable.
62
62
  * The v3 lock is written only after every plugin has been converted.
63
63
  */
64
- function migrateLockV2(pluginsDir, telemetrySpan) {
64
+ function migrateLock(pluginsDir, telemetrySpan) {
65
65
  const file = lockPath(pluginsDir);
66
66
  if (!existsSync(file))
67
67
  return false;
68
68
  const raw = JSON.parse(readFileSync(file, "utf8"));
69
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
70
+ throw new Error(`${file} is not a valid lock file`);
71
+ if (Array.isArray(raw.plugins))
72
+ throw new Error(`${file} is not a valid lock file`);
69
73
  if (raw.version === LOCK_VERSION)
70
74
  return false;
71
75
  if (typeof raw?.version === "number") {
72
- recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 ? 2 : -1 }, telemetrySpan);
76
+ recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 || raw.version === 3 || raw.version === 4 ? raw.version : -1 }, telemetrySpan);
77
+ }
78
+ if ((raw.version === 3 || raw.version === 4) && typeof raw.plugins === "object" && raw.plugins !== null) {
79
+ // v3 has the same payload model; v4 adds optional immutable provenance.
80
+ // Existing remote entries remain explicitly legacy until an update/add
81
+ // resolves their commit, rather than inventing a moving ref as a revision.
82
+ writeLock(file, { ...raw, version: LOCK_VERSION });
83
+ recordTelemetryEvent("adg.lock.migrate", { "from.version": raw.version, "to.version": LOCK_VERSION }, telemetrySpan);
84
+ return true;
73
85
  }
74
86
  if (raw.version !== 2 || typeof raw.plugins !== "object" || raw.plugins === null) {
75
87
  throw new Error(`${file} uses unsupported lock version ${raw.version}; expected ${LOCK_VERSION}`);
@@ -1,5 +1,8 @@
1
1
  import { listPlugins } from "./list.js";
2
2
  import { relative } from "node:path";
3
+ import { ADAPTER_TARGETS } from "../adapters/index.js";
4
+ import { installPlugin } from "./install.js";
5
+ import { resolvePluginSourceSnapshot } from "../source-cache.js";
3
6
  /**
4
7
  * Shared selection for the projection verbs (link / unlink / sync). Resolve which
5
8
  * installed plugins to act on: the named subset (validated against the store), or
@@ -32,3 +35,15 @@ export function adaptedFilesForTarget(installedTo, files, target) {
32
35
  const expected = target === "antigravity" ? "plugin.json" : `.${target}-plugin/plugin.json`;
33
36
  return files.filter((file) => relative(installedTo, file).split("\\").join("/") === expected);
34
37
  }
38
+ /** Rebuild runtime projections for installed plugins from their cached ADG source. */
39
+ export function rematerializeInstalled(pluginsDir, plugins) {
40
+ return plugins.map((plugin) => installPlugin({
41
+ source: resolvePluginSourceSnapshot(pluginsDir, plugin.name, plugin),
42
+ pluginsDir,
43
+ origin: plugin.origin,
44
+ resolvedRevision: plugin.resolvedRevision,
45
+ selection: plugin.selection,
46
+ targets: [...ADAPTER_TARGETS],
47
+ forceMaterialize: true,
48
+ }));
49
+ }
@@ -58,5 +58,17 @@ export async function selectComponentsInteractive(req) {
58
58
  selection.skills = picked;
59
59
  }
60
60
  }
61
+ // Drill into individual MCP servers only when mcp is kept and there's a choice.
62
+ if (chosen.includes("mcp") && req.contents.mcp.length > 1) {
63
+ const message = `${pc.bold(req.name)} — which MCP servers? ${pc.dim("(space to toggle)")}`;
64
+ const options = req.contents.mcp.map((s) => ({ value: s, label: s }));
65
+ const initialValues = [...req.contents.mcp];
66
+ const servers = await p.multiselect({ message, options, initialValues, required: true });
67
+ if (!cancelled(servers)) {
68
+ const picked = servers;
69
+ if (picked.length !== req.contents.mcp.length)
70
+ selection.mcp = picked;
71
+ }
72
+ }
61
73
  return selection;
62
74
  }
@@ -1,6 +1,7 @@
1
1
  import { listPlugins } from "./list.js";
2
2
  import { agentsForComponents, resolveAgents } from "../agents/index.js";
3
- import { lockPath, pluginRematerializationSource } from "../paths.js";
3
+ import { lockPath } from "../paths.js";
4
+ import { resolvePluginSourceSnapshot } from "../source-cache.js";
4
5
  import { readLock, writeLock } from "../lock.js";
5
6
  import { pluginState } from "../types.js";
6
7
  import { ADAPTER_TARGETS } from "../adapters/index.js";
@@ -66,9 +67,10 @@ export function enablePlugins(opts) {
66
67
  for (const name of changed) {
67
68
  const entry = lock.plugins[name];
68
69
  installPlugin({
69
- source: pluginRematerializationSource(opts.pluginsDir, name, entry.origin),
70
+ source: resolvePluginSourceSnapshot(opts.pluginsDir, name, entry),
70
71
  pluginsDir: opts.pluginsDir,
71
72
  origin: entry.origin,
73
+ resolvedRevision: entry.resolvedRevision,
72
74
  selection: entry.selection,
73
75
  targets: [...ADAPTER_TARGETS],
74
76
  forceMaterialize: true,