@rbbtsn0w/adg 0.6.0-beta.6 → 0.6.0-beta.8

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.
@@ -6,7 +6,7 @@ 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";
@@ -15,12 +15,13 @@ import { ADG_MANIFEST_PATH, readManifest } from "../manifest.js";
15
15
  import { recordTelemetryEvent } from "../telemetry.js";
16
16
  import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../marketplace.js";
17
17
  import { resolveInstallOrder } from "../deps.js";
18
- import { cloneGitHub, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
18
+ import { cloneGitHub, gitRevision, githubRepositoryDescription, parseGitHubSource, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
19
19
  import { normalizePluginSelection, pluginState, resolveSelectionDependencies, sameSource, COMPONENT_TYPES } from "../types.js";
20
20
  import { pluginContents, presentComponents } from "../components.js";
21
21
  import { skillDescriptionLoader } from "../skills.js";
22
22
  import { resolveAgents } from "../agents/index.js";
23
23
  import { effectivePackageFilter, materializePlugin, withPluginSourceCache } from "../materialize.js";
24
+ import { resolveDefaultDsl } from "../default-dsl.js";
24
25
  // Generated runtime projections never count toward a plugin's content hash.
25
26
  const HASH_IGNORE = PROJECTION_DIRS;
26
27
  /** Content hash over a plugin's packaged payload (hooks files are authored content, not generated). */
@@ -117,6 +118,7 @@ export function installPlugin(opts) {
117
118
  version: manifest.version,
118
119
  sourceHash,
119
120
  installedHash,
121
+ ...(opts.resolvedRevision ? { resolvedRevision: opts.resolvedRevision } : {}),
120
122
  };
121
123
  if (manifest.dependencies?.length) {
122
124
  entry.dependencies = Object.fromEntries(manifest.dependencies.map((d) => [d.name, d.version]));
@@ -125,6 +127,8 @@ export function installPlugin(opts) {
125
127
  entry.selection = desiredSelection;
126
128
  if (prev?.state)
127
129
  entry.state = prev.state;
130
+ if (opts.definition)
131
+ entry.definition = opts.definition;
128
132
  const previousEntry = prev && Object.fromEntries(Object.entries(prev).filter(([key]) => key !== "installedAt" && key !== "updatedAt"));
129
133
  const changed = !prev || !isDeepStrictEqual(previousEntry, entry);
130
134
  if (changed) {
@@ -169,7 +173,7 @@ function discoverPlugins(root) {
169
173
  return { candidates: scanPlugins(root), converted };
170
174
  }
171
175
  /** Resolve which discovered plugins to install from the selection options. */
172
- async function selectPluginNames(opts, candidates, workRoot, converted) {
176
+ async function selectPluginNames(opts, candidates, converted) {
173
177
  const names = [...candidates.keys()];
174
178
  if (opts.plugins?.length) {
175
179
  const missing = opts.plugins.filter((p) => !candidates.has(p));
@@ -178,13 +182,6 @@ async function selectPluginNames(opts, candidates, workRoot, converted) {
178
182
  }
179
183
  return opts.plugins.filter((p) => candidates.has(p));
180
184
  }
181
- if (opts.path) {
182
- const target = resolve(join(workRoot, opts.path));
183
- const hit = [...candidates.values()].find((c) => resolve(c.dir) === target);
184
- if (!hit)
185
- throw new Error(`no plugin found at --path ${opts.path}`);
186
- return [hit.manifest.name];
187
- }
188
185
  if (opts.all || candidates.size === 1)
189
186
  return names;
190
187
  if (opts.selectPlugins) {
@@ -219,6 +216,11 @@ async function resolveSelections(opts, selected, candidates) {
219
216
  selections.set(name, flagSelection);
220
217
  return selections;
221
218
  }
219
+ if (opts.replaySelection) {
220
+ for (const name of selected)
221
+ selections.set(name, opts.replaySelection);
222
+ return selections;
223
+ }
222
224
  if (!opts.confirmFull || !opts.selectComponents)
223
225
  return selections; // non-interactive default: full
224
226
  if (await opts.confirmFull(selected))
@@ -250,13 +252,12 @@ function sameRemoteSource(entry, parsed, ref) {
250
252
  * (`--plugin one` after previously installing `--all`) without leaving stale
251
253
  * runtime exports behind.
252
254
  */
253
- function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
255
+ function reconcileRemotePlugins(opts, parsed, ref, desired) {
254
256
  if (parsed.kind === "local")
255
257
  return [];
256
- // A path/sparse install does not prove the full source shape, so it must not
257
- // prune sibling plugins from the same repo that were intentionally excluded
258
- // from the checkout/selection window.
259
- 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)
260
261
  return [];
261
262
  const lock = readLock(lockPath(opts.pluginsDir));
262
263
  const stale = Object.entries(lock.plugins)
@@ -310,39 +311,80 @@ function activateInstalled(opts, targets, installed, existingPlugins) {
310
311
  /**
311
312
  * The unified install entrypoint. Treats any source as a marketplace: clone or
312
313
  * read it, discover every plugin (ADG plus reverse-adapted native), choose a
313
- * subset (--all / --plugin / --path / sole plugin / interactive picker), then
314
+ * subset (--all / --plugin / sole plugin / interactive picker), then
314
315
  * install the selection in dependency-first order.
315
316
  */
316
317
  export async function addPlugins(opts) {
317
- 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);
318
321
  const sourceRef = parsed.kind === "local" ? undefined : (opts.ref ?? parsed.ref);
319
- const inferredPath = parsed.kind === "github" ? parsed.path : undefined;
320
- 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
+ }
321
325
  let workRoot;
322
326
  let buildOrigin;
327
+ let resolvedRevision;
323
328
  let cleanup;
324
- 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") {
325
339
  workRoot = resolve(parsed.dir);
326
- buildOrigin = (dir) => ({ type: "local", path: resolve(dir) });
340
+ buildOrigin = (dir) => ({ type: "local", path: resolve(originDirOverride ?? dir) });
327
341
  }
328
342
  else {
329
343
  const tmp = mkdtempSync(join(tmpdir(), "adg-clone-"));
330
344
  cleanup = () => rmSync(tmp, { recursive: true, force: true });
331
345
  cloneGitHub({ ...parsed, ref: sourceRef }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
332
346
  workRoot = tmp;
347
+ resolvedRevision = gitRevision(tmp);
333
348
  buildOrigin = (dir) => ({
334
349
  type: "github",
335
350
  repo: parsed.source,
336
351
  ...(sourceRef ? { ref: sourceRef } : {}),
337
- path: toPosix(relative(tmp, dir)) || ".",
352
+ path: toPosix(relative(tmp, originDirOverride ?? dir)) || ".",
338
353
  });
339
354
  }
340
355
  try {
341
- 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
+ }
342
361
  if (candidates.size === 0) {
343
- 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
+ const authorized = opts.authorizedComponents;
370
+ const unauthorizedRisk = generated.components.some((c) => (c === "hooks" || c === "mcp") && !authorized?.includes(c));
371
+ if (opts.nonInteractive && unauthorizedRisk && opts.only === undefined) {
372
+ throw new Error("default source exposes hooks or MCP; pass --only to explicitly authorize selected components");
373
+ }
374
+ const staging = mkdtempSync(join(tmpdir(), "adg-default-plugin-"));
375
+ copyPluginDir(workRoot, staging);
376
+ writeJson(join(staging, ADG_MANIFEST_PATH), generated.manifest);
377
+ candidates = scanPlugins(staging);
378
+ structuralName = generated.manifest.name;
379
+ converted = [];
380
+ originDirOverride = workRoot;
381
+ 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) };
382
+ cleanup = (() => {
383
+ const prior = cleanup;
384
+ return () => { rmSync(staging, { recursive: true, force: true }); prior?.(); };
385
+ })();
344
386
  }
345
- const selected = await selectPluginNames({ ...opts, path }, candidates, workRoot, converted);
387
+ const selected = structuralName ? [structuralName] : await selectPluginNames(opts, candidates, converted);
346
388
  // Resolve adapter targets after the plugin choice (lets a CLI agent picker
347
389
  // run once we know what's being installed). undefined → installPlugin's all.
348
390
  const targets = opts.targets ?? (opts.selectTargets ? await opts.selectTargets() : undefined);
@@ -352,13 +394,19 @@ export async function addPlugins(opts) {
352
394
  // upstream: don't abort — return what the source still offers so the
353
395
  // caller can report the deletions.
354
396
  if (opts.missingPlugins === "skip") {
355
- const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(selected));
397
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(selected));
356
398
  return { order: [], installed: [], removed, converted, available };
357
399
  }
358
400
  throw new Error("no plugins selected");
359
401
  }
360
402
  // Partial-install selection per user-chosen plugin (auto-deps install full).
361
403
  const selections = await resolveSelections(opts, selected, candidates);
404
+ if (definition && structuralName) {
405
+ definition = {
406
+ ...definition,
407
+ authorizedComponents: selections.get(structuralName)?.components ?? definition.authorizedComponents,
408
+ };
409
+ }
362
410
  // Dependency-first order across every selected plugin (chains deduped).
363
411
  const order = [];
364
412
  const seen = new Set();
@@ -371,7 +419,14 @@ export async function addPlugins(opts) {
371
419
  }
372
420
  }
373
421
  }
374
- const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(order));
422
+ // A generated Default DSL replay retains its definition profile. Only an
423
+ // explicit manifest discovered from the source may replace that profile.
424
+ const definitionSwitches = definition ? [] : order.filter((name) => existingLock.plugins[name]?.definition);
425
+ if (definitionSwitches.length > 0) {
426
+ const names = definitionSwitches.sort().map((name) => `"${name}"`).join(", ");
427
+ throw new Error(`source definition changed from default DSL to a manifest for ${names}; re-add or migrate the plugin explicitly`);
428
+ }
429
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(order));
375
430
  // Snapshot which plugins already existed before this call mutates the lock,
376
431
  // so the activation step below can tell brand-new installs from updates.
377
432
  const existingPlugins = new Set(Object.keys(readLock(lockPath(opts.pluginsDir)).plugins));
@@ -382,11 +437,13 @@ export async function addPlugins(opts) {
382
437
  source: candidate.dir,
383
438
  pluginsDir: opts.pluginsDir,
384
439
  origin: buildOrigin(candidate.dir),
440
+ resolvedRevision,
385
441
  marketplaceName: opts.marketplaceName,
386
442
  targets,
387
443
  selection: selections.get(name),
388
444
  skipUnchanged: opts.skipUnchanged,
389
445
  now: opts.now,
446
+ definition: name === structuralName ? definition : undefined,
390
447
  }));
391
448
  }
392
449
  // Activate into the selected agents so the plugins are actually usable, not
@@ -27,6 +27,7 @@ export function linkPlugins(opts) {
27
27
  pluginsDir: opts.pluginsDir,
28
28
  plugins: actions.map((a) => a.name),
29
29
  scope: opts.global ? "user" : "project",
30
+ ...(opts.target === "codex" ? { reconcileLegacyAliases: true } : {}),
30
31
  });
31
32
  for (const a of actions)
32
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}`);
@@ -2,7 +2,7 @@ import { listPlugins } from "./list.js";
2
2
  import { relative } from "node:path";
3
3
  import { ADAPTER_TARGETS } from "../adapters/index.js";
4
4
  import { installPlugin } from "./install.js";
5
- import { pluginRematerializationSource } from "../paths.js";
5
+ import { resolvePluginSourceSnapshot } from "../source-cache.js";
6
6
  /**
7
7
  * Shared selection for the projection verbs (link / unlink / sync). Resolve which
8
8
  * installed plugins to act on: the named subset (validated against the store), or
@@ -38,9 +38,10 @@ export function adaptedFilesForTarget(installedTo, files, target) {
38
38
  /** Rebuild runtime projections for installed plugins from their cached ADG source. */
39
39
  export function rematerializeInstalled(pluginsDir, plugins) {
40
40
  return plugins.map((plugin) => installPlugin({
41
- source: pluginRematerializationSource(pluginsDir, plugin.name, plugin.origin),
41
+ source: resolvePluginSourceSnapshot(pluginsDir, plugin.name, plugin),
42
42
  pluginsDir,
43
43
  origin: plugin.origin,
44
+ resolvedRevision: plugin.resolvedRevision,
44
45
  selection: plugin.selection,
45
46
  targets: [...ADAPTER_TARGETS],
46
47
  forceMaterialize: true,
@@ -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,
@@ -17,7 +17,12 @@ export function syncPlugins(opts) {
17
17
  const scope = opts.global ? "user" : "project";
18
18
  const parts = [
19
19
  ...(disabled.length > 0 ? [agent.deactivate({ pluginsDir: opts.pluginsDir, plugins: disabled.map((p) => p.name), scope })] : []),
20
- ...(enabled.length > 0 ? [agent.refresh({ pluginsDir: opts.pluginsDir, plugins: enabled.map((p) => p.name), scope })] : []),
20
+ ...(enabled.length > 0 ? [agent.refresh({
21
+ pluginsDir: opts.pluginsDir,
22
+ plugins: enabled.map((p) => p.name),
23
+ scope,
24
+ ...(opts.target === "codex" ? { reconcileLegacyAliases: true } : {}),
25
+ })] : []),
21
26
  ];
22
27
  for (const action of actions)
23
28
  if (parts.some((part) => part.affected.includes(action.name)))
@@ -1,9 +1,13 @@
1
- import { existsSync } from "node:fs";
2
- import { resolve } from "node:path";
1
+ import { existsSync, mkdtempSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join, resolve } from "node:path";
3
4
  import { resolveAgents } from "../agents/index.js";
4
5
  import { installedPluginDir, lockPath, pluginSourceCacheDir } from "../paths.js";
5
6
  import { readLock } from "../lock.js";
6
7
  import { installPlugin } from "./install.js";
8
+ import { resolveDefaultDsl } from "../default-dsl.js";
9
+ import { ADG_MANIFEST_PATH } from "../manifest.js";
10
+ import { copyPluginDir, writeJson } from "../fsutil.js";
7
11
  /**
8
12
  * Refresh local sources and repair effective installations from their complete
9
13
  * source snapshots. Runtime installations are never treated as upstream input.
@@ -28,14 +32,49 @@ export function updateLock(pluginsDir, now = new Date().toISOString(), opts = {}
28
32
  missing.push(name);
29
33
  continue;
30
34
  }
31
- const result = installPlugin({
32
- source,
33
- pluginsDir,
34
- origin: entry.origin,
35
- selection: entry.selection,
36
- skipUnchanged: true,
37
- now,
38
- });
35
+ if (entry.definition && localSource && existsSync(join(localSource, ADG_MANIFEST_PATH))) {
36
+ throw new Error(`source definition changed from default DSL to a manifest for "${name}"; re-add or migrate the plugin explicitly`);
37
+ }
38
+ let installSource = source;
39
+ let staging;
40
+ let definition = entry.definition;
41
+ if (!existsSync(join(source, ADG_MANIFEST_PATH))) {
42
+ try {
43
+ const generated = resolveDefaultDsl(source, { name, description: entry.definition?.description ?? name });
44
+ const authorized = entry.definition?.authorizedComponents;
45
+ const unauthorizedRisk = generated.components.some((component) => (component === "hooks" || component === "mcp") && !authorized?.includes(component));
46
+ if (entry.definition && unauthorizedRisk) {
47
+ throw new Error(`default source exposes an unauthorized hook or MCP component for "${name}"; re-add the plugin with an explicit component selection`);
48
+ }
49
+ if (entry.definition)
50
+ definition = { ...entry.definition, description: generated.manifest.description, fingerprint: generated.fingerprint };
51
+ staging = mkdtempSync(join(tmpdir(), "adg-default-update-"));
52
+ copyPluginDir(source, staging);
53
+ writeJson(join(staging, ADG_MANIFEST_PATH), generated.manifest);
54
+ installSource = staging;
55
+ }
56
+ catch (error) {
57
+ if (!(error instanceof Error) || !error.message.includes("no default plugin component"))
58
+ throw error;
59
+ // Non-plugin local directories continue through the normal manifest path.
60
+ }
61
+ }
62
+ let result;
63
+ try {
64
+ result = installPlugin({
65
+ source: installSource,
66
+ pluginsDir,
67
+ origin: entry.origin,
68
+ selection: entry.selection ?? (entry.definition?.authorizedComponents ? { components: entry.definition.authorizedComponents } : undefined),
69
+ skipUnchanged: true,
70
+ now,
71
+ definition,
72
+ });
73
+ }
74
+ finally {
75
+ if (staging)
76
+ rmSync(staging, { recursive: true, force: true });
77
+ }
39
78
  if (result.changed)
40
79
  changedNames.push(name);
41
80
  results.push({
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
2
+ import { basename, join } from "node:path";
3
3
  import { ADG_MANIFEST_PATH, collectIssues } from "../manifest.js";
4
+ import { resolveDefaultDsl } from "../default-dsl.js";
4
5
  /**
5
6
  * Validate a plugin's manifest against the ADG schema and check that the
6
7
  * directories/files it references actually exist.
@@ -8,7 +9,13 @@ import { ADG_MANIFEST_PATH, collectIssues } from "../manifest.js";
8
9
  export function validatePlugin(pluginDir) {
9
10
  const manifestFile = join(pluginDir, ADG_MANIFEST_PATH);
10
11
  if (!existsSync(manifestFile)) {
11
- return { ok: false, issues: [`${ADG_MANIFEST_PATH} not found in ${pluginDir}`] };
12
+ try {
13
+ resolveDefaultDsl(pluginDir, { name: basename(pluginDir), description: basename(pluginDir) });
14
+ return { ok: true, issues: [] };
15
+ }
16
+ catch (error) {
17
+ return { ok: false, issues: [error instanceof Error ? error.message : String(error)] };
18
+ }
12
19
  }
13
20
  let raw;
14
21
  try {