@rbbtsn0w/adg 0.5.0-beta.4 → 0.5.0-beta.6

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.
@@ -2,6 +2,7 @@ import { installedPluginDir, lockPath } from "../paths.js";
2
2
  import { readLock } from "../lock.js";
3
3
  import { readManifest } from "../manifest.js";
4
4
  import { exposedContents, pluginContents } from "../components.js";
5
+ import { resolveSelectionDependencies } from "../types.js";
5
6
  /** List plugins recorded in a plugins directory's .plugin-lock.json. */
6
7
  export function listPlugins(pluginsDir) {
7
8
  const lock = readLock(lockPath(pluginsDir));
@@ -9,7 +10,9 @@ export function listPlugins(pluginsDir) {
9
10
  const dir = installedPluginDir(pluginsDir, name, entry.origin);
10
11
  let contents;
11
12
  try {
12
- contents = exposedContents(pluginContents(dir, readManifest(dir)), entry.selection);
13
+ const manifest = readManifest(dir);
14
+ const effectiveSelection = resolveSelectionDependencies(manifest, entry.selection);
15
+ contents = exposedContents(pluginContents(dir, manifest), effectiveSelection);
13
16
  }
14
17
  catch {
15
18
  contents = undefined; // no/invalid manifest on disk — show provenance only
@@ -60,7 +60,14 @@ function requireGroup(pluginsDir, source, scope) {
60
60
  const where = scope?.label ? `${scope.label}: ${pluginsDir}` : pluginsDir;
61
61
  let msg = `no installed source "${source}" in ${where}. Known sources: ${keys}`;
62
62
  if (scope?.globalDir && scope.globalDir !== pluginsDir) {
63
- const inGlobal = marketplaceList({ pluginsDir: scope.globalDir }).some((g) => g.source === source);
63
+ let inGlobal = false;
64
+ try {
65
+ inGlobal = marketplaceList({ pluginsDir: scope.globalDir }).some((g) => g.source === source);
66
+ }
67
+ catch {
68
+ // The global store is only an optional suggestion source. A malformed or
69
+ // unsupported global lock must not mask the active scope's real error.
70
+ }
64
71
  if (inGlobal)
65
72
  msg += ` — found in global; did you mean \`-g\`?`;
66
73
  }
@@ -1,8 +1,16 @@
1
- import { existsSync, mkdirSync, renameSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, renameSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
- import { lockPath, marketplacePath, marketplaceSourcePath, pluginDir } from "../paths.js";
4
- import { readLock } from "../lock.js";
3
+ import { ADAPTER_TARGETS } from "../adapters/index.js";
4
+ import { folderHash } from "../hash.js";
5
+ import { readManifest } from "../manifest.js";
6
+ import { effectivePackageFilter, materializePlugin, withPluginSourceCache } from "../materialize.js";
7
+ import { packageFilter, PROJECTION_DIRS } from "../package.js";
8
+ import { installedPluginDir, lockPath, marketplacePath, marketplaceSourcePath, pluginDir, pluginSourceCacheDir } from "../paths.js";
9
+ import { readLock, writeLock } from "../lock.js";
5
10
  import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../marketplace.js";
11
+ import { adaptPlugin } from "./adapt.js";
12
+ import { recordTelemetryEvent } from "../telemetry.js";
13
+ import { LOCK_VERSION, normalizePluginSelection, resolveSelectionDependencies } from "../types.js";
6
14
  /**
7
15
  * Migrate a flat plugins directory to the per-marketplace nested layout.
8
16
  *
@@ -11,8 +19,9 @@ import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../m
11
19
  * flat) and rewrite its marketplace.json `source.path` to match. Idempotent:
12
20
  * plugins already at their target path are reported as unchanged.
13
21
  */
14
- export function migrateLayout(pluginsDir) {
15
- const lock = readLock(lockPath(pluginsDir));
22
+ export function migrateLayout(pluginsDir, telemetrySpan) {
23
+ const lockUpgraded = migrateLockV2(pluginsDir, telemetrySpan);
24
+ const lock = readLock(lockPath(pluginsDir), telemetrySpan);
16
25
  const moved = [];
17
26
  const unchanged = [];
18
27
  const missing = [];
@@ -45,7 +54,65 @@ export function migrateLayout(pluginsDir) {
45
54
  }
46
55
  if (marketDirty)
47
56
  writeMarketplace(marketFile, market);
48
- return { moved, unchanged, missing };
57
+ return { lockUpgraded, moved, unchanged, missing };
58
+ }
59
+ /**
60
+ * Explicitly upgrade a v2 store. The old full installation is cached before
61
+ * selection-aware materialization, so unselected payload remains recoverable.
62
+ * The v3 lock is written only after every plugin has been converted.
63
+ */
64
+ function migrateLockV2(pluginsDir, telemetrySpan) {
65
+ const file = lockPath(pluginsDir);
66
+ if (!existsSync(file))
67
+ return false;
68
+ const raw = JSON.parse(readFileSync(file, "utf8"));
69
+ if (raw.version === LOCK_VERSION)
70
+ return false;
71
+ if (typeof raw?.version === "number") {
72
+ recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 ? 2 : -1 }, telemetrySpan);
73
+ }
74
+ if (raw.version !== 2 || typeof raw.plugins !== "object" || raw.plugins === null) {
75
+ throw new Error(`${file} uses unsupported lock version ${raw.version}; expected ${LOCK_VERSION}`);
76
+ }
77
+ const plugins = {};
78
+ for (const [name, oldEntry] of Object.entries(raw.plugins)) {
79
+ const installed = installedPluginDir(pluginsDir, name, oldEntry.origin);
80
+ const cache = pluginSourceCacheDir(pluginsDir, name);
81
+ const source = existsSync(cache) ? cache : installed;
82
+ if (!existsSync(source))
83
+ throw new Error(`cannot migrate "${name}": installed directory and source cache are missing`);
84
+ const manifest = readManifest(source, telemetrySpan);
85
+ const desiredSelection = normalizePluginSelection(oldEntry.selection);
86
+ const selection = resolveSelectionDependencies(manifest, desiredSelection);
87
+ withPluginSourceCache(source, cache, manifest, (snapshot) => {
88
+ const sourceHash = folderHash(snapshot, PROJECTION_DIRS, packageFilter(manifest, { includeProjections: false }));
89
+ let installedHash = "";
90
+ materializePlugin({
91
+ source: snapshot,
92
+ destination: installed,
93
+ manifest,
94
+ selection,
95
+ build: (staging) => {
96
+ adaptPlugin(staging, [...ADAPTER_TARGETS], selection);
97
+ installedHash = folderHash(staging, PROJECTION_DIRS, effectivePackageFilter(manifest, selection));
98
+ },
99
+ });
100
+ plugins[name] = {
101
+ origin: oldEntry.origin,
102
+ version: oldEntry.version,
103
+ sourceHash,
104
+ installedHash,
105
+ installedAt: oldEntry.installedAt,
106
+ updatedAt: oldEntry.updatedAt,
107
+ ...(oldEntry.dependencies ? { dependencies: oldEntry.dependencies } : {}),
108
+ ...(desiredSelection ? { selection: desiredSelection } : {}),
109
+ ...(oldEntry.state ? { state: oldEntry.state } : {}),
110
+ };
111
+ });
112
+ }
113
+ writeLock(file, { version: LOCK_VERSION, plugins, ...(raw.lastSelected ? { lastSelected: raw.lastSelected } : {}) });
114
+ recordTelemetryEvent("adg.lock.migrate", { "from.version": 2, "to.version": LOCK_VERSION }, telemetrySpan);
115
+ return true;
49
116
  }
50
117
  /** Point a marketplace entry's `source.path` at the plugin's on-disk dir. */
51
118
  function rewriteMarketplacePath(market, name, pluginsDir, dir) {
@@ -1,4 +1,5 @@
1
1
  import { listPlugins } from "./list.js";
2
+ import { relative } from "node:path";
2
3
  /**
3
4
  * Shared selection for the projection verbs (link / unlink / sync). Resolve which
4
5
  * installed plugins to act on: the named subset (validated against the store), or
@@ -26,3 +27,8 @@ export function selectInstalled(pluginsDir, names) {
26
27
  }
27
28
  return picked;
28
29
  }
30
+ /** Keep only the generated manifest reported for one runtime target. */
31
+ export function adaptedFilesForTarget(installedTo, files, target) {
32
+ const expected = target === "antigravity" ? "plugin.json" : `.${target}-plugin/plugin.json`;
33
+ return files.filter((file) => relative(installedTo, file).split("\\").join("/") === expected);
34
+ }
@@ -1,6 +1,6 @@
1
1
  import { existsSync, lstatSync, readdirSync, readlinkSync, rmdirSync, rmSync } from "node:fs";
2
2
  import { basename, dirname, join, resolve } from "node:path";
3
- import { claudeSkillsDir, lockPath, marketplacePath, pluginDir } from "../paths.js";
3
+ import { claudeSkillsDir, lockPath, marketplacePath, pluginCacheRoot, pluginDir, pluginSourceCacheDir } from "../paths.js";
4
4
  import { readLock, removeEntry, writeLock } from "../lock.js";
5
5
  import { readMarketplace, removeMarketplacePlugin, writeMarketplace } from "../marketplace.js";
6
6
  import { resolveAgents } from "../agents/index.js";
@@ -55,6 +55,15 @@ export function removePlugin(opts) {
55
55
  // Drop the per-marketplace bucket if it became empty (nested remote layout).
56
56
  pruneEmptyParent(dirname(dir), opts.pluginsDir);
57
57
  }
58
+ const cacheDir = pluginSourceCacheDir(opts.pluginsDir, name);
59
+ let removedCacheDir;
60
+ if (existsSync(cacheDir)) {
61
+ rmSync(cacheDir, { recursive: true, force: true });
62
+ removedCacheDir = cacheDir;
63
+ const cacheRoot = pluginCacheRoot(opts.pluginsDir);
64
+ if (existsSync(cacheRoot) && readdirSync(cacheRoot).length === 0)
65
+ rmSync(cacheRoot, { recursive: true, force: true });
66
+ }
58
67
  const removedFromLock = removeEntry(lock, name);
59
68
  if (removedFromLock)
60
69
  writeLock(lockFile, lock);
@@ -70,7 +79,7 @@ export function removePlugin(opts) {
70
79
  const ctx = { pluginsDir: opts.pluginsDir, plugins: [name], scope: opts.scope ?? "project" };
71
80
  agents = (opts.agents ?? resolveAgents()).map((a) => a.deactivate(ctx));
72
81
  }
73
- return { name, removedDir, unlinked, removedFromLock, removedFromMarketplace, agents };
82
+ return { name, removedDir, removedCacheDir, unlinked, removedFromLock, removedFromMarketplace, agents };
74
83
  }
75
84
  /**
76
85
  * Remove `parent` if it is an empty per-marketplace bucket below `pluginsDir`.
@@ -30,7 +30,8 @@ export async function confirmFullInstall(plugins) {
30
30
  /**
31
31
  * Per-plugin component picker (①). Choose which categories to expose; if skills
32
32
  * is kept and the plugin has several, drill in to pick individual skills. Files
33
- * are still installed in full — this only narrows what the runtime sees.
33
+ * are materialized into the effective installation; unselected payload stays
34
+ * only in ADG's internal source cache.
34
35
  */
35
36
  export async function selectComponentsInteractive(req) {
36
37
  const components = await p.multiselect({
@@ -1,10 +1,10 @@
1
- import { existsSync } from "node:fs";
2
- import { adaptPlugin } from "./adapt.js";
3
1
  import { listPlugins } from "./list.js";
4
2
  import { agentsForComponents, resolveAgents } from "../agents/index.js";
5
- import { installedPluginDir, lockPath } from "../paths.js";
3
+ import { lockPath, pluginRematerializationSource } from "../paths.js";
6
4
  import { readLock, writeLock } from "../lock.js";
7
5
  import { pluginState } from "../types.js";
6
+ import { ADAPTER_TARGETS } from "../adapters/index.js";
7
+ import { installPlugin } from "./install.js";
8
8
  function selectedLock(opts) {
9
9
  const lock = readLock(lockPath(opts.pluginsDir));
10
10
  const names = [...new Set(opts.names)];
@@ -63,19 +63,25 @@ export function enablePlugins(opts) {
63
63
  const { lock, names } = selectedLock(opts);
64
64
  const order = enableOrder(lock, names);
65
65
  const changed = order.filter((name) => pluginState(lock.plugins[name]) !== "enabled");
66
+ for (const name of changed) {
67
+ const entry = lock.plugins[name];
68
+ installPlugin({
69
+ source: pluginRematerializationSource(opts.pluginsDir, name, entry.origin),
70
+ pluginsDir: opts.pluginsDir,
71
+ origin: entry.origin,
72
+ selection: entry.selection,
73
+ targets: [...ADAPTER_TARGETS],
74
+ forceMaterialize: true,
75
+ });
76
+ }
77
+ const plugins = listPlugins(opts.pluginsDir);
78
+ const updatedLock = readLock(lockPath(opts.pluginsDir));
66
79
  for (const name of order)
67
- lock.plugins[name].state = "enabled";
80
+ updatedLock.plugins[name].state = "enabled";
68
81
  if (changed.length > 0)
69
- writeLock(lockPath(opts.pluginsDir), lock);
70
- const plugins = listPlugins(opts.pluginsDir);
82
+ writeLock(lockPath(opts.pluginsDir), updatedLock);
71
83
  const agents = (opts.agents ?? resolveAgents()).map((agent) => {
72
84
  const compatible = changed.filter((name) => pluginAgentIds(plugins, name).has(agent.id));
73
- for (const name of compatible) {
74
- const entry = lock.plugins[name];
75
- const dir = installedPluginDir(opts.pluginsDir, name, entry.origin);
76
- if (existsSync(dir))
77
- adaptPlugin(dir, [agent.adaptTarget], entry.selection);
78
- }
79
85
  if (compatible.length === 0)
80
86
  return { agent: agent.id, affected: [], skipped: false };
81
87
  return agent.activate({ pluginsDir: opts.pluginsDir, plugins: compatible, scope: opts.scope });
@@ -1,9 +1,9 @@
1
- import { existsSync } from "node:fs";
2
- import { adaptPlugin } from "./adapt.js";
3
- import { selectInstalled } from "./projection.js";
4
- import { installedPluginDir } from "../paths.js";
1
+ import { adaptedFilesForTarget, selectInstalled } from "./projection.js";
2
+ import { pluginRematerializationSource } from "../paths.js";
5
3
  import { getAgent } from "../agents/index.js";
4
+ import { ADAPTER_TARGETS } from "../adapters/index.js";
6
5
  import { pluginState } from "../types.js";
6
+ import { installPlugin } from "./install.js";
7
7
  /** Regenerate manifests for the selected plugins, then refresh them in the agent. */
8
8
  export function syncPlugins(opts) {
9
9
  const agent = opts.agent ?? getAgent(opts.target);
@@ -13,11 +13,15 @@ export function syncPlugins(opts) {
13
13
  const disabled = selected.filter((p) => pluginState(p) === "disabled");
14
14
  const actions = disabled.map((p) => ({ name: p.name, adapted: [], synced: false }));
15
15
  for (const p of enabled) {
16
- const dir = installedPluginDir(opts.pluginsDir, p.name, p.origin);
17
- if (!existsSync(dir))
18
- continue;
19
- const adapted = adaptPlugin(dir, [adaptTarget], p.selection).map((r) => r.file);
20
- actions.push({ name: p.name, adapted, synced: false });
16
+ const result = installPlugin({
17
+ source: pluginRematerializationSource(opts.pluginsDir, p.name, p.origin),
18
+ pluginsDir: opts.pluginsDir,
19
+ origin: p.origin,
20
+ selection: p.selection,
21
+ targets: [...ADAPTER_TARGETS],
22
+ forceMaterialize: true,
23
+ });
24
+ actions.push({ name: p.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget), synced: false });
21
25
  }
22
26
  if (!agent)
23
27
  return { target: opts.target, actions };
@@ -1,57 +1,55 @@
1
1
  import { existsSync } from "node:fs";
2
- import { folderHash } from "../hash.js";
3
- import { packageFilter, PROJECTION_DIRS } from "../package.js";
4
- import { lockPath, installedPluginDir } from "../paths.js";
5
- import { readLock, writeLock } from "../lock.js";
6
- import { readManifest } from "../manifest.js";
7
- import { adaptPlugin } from "./adapt.js";
8
- import { ADAPTER_TARGETS } from "../adapters/index.js";
2
+ import { resolve } from "node:path";
9
3
  import { resolveAgents } from "../agents/index.js";
4
+ import { installedPluginDir, lockPath, pluginSourceCacheDir } from "../paths.js";
5
+ import { readLock } from "../lock.js";
6
+ import { installPlugin } from "./install.js";
10
7
  /**
11
- * Re-scan installed plugins in a plugins directory, refreshing each lock
12
- * entry's version and folderHash from disk. Entries whose content or version
13
- * changed are reported as `changed`. A missing plugin directory is reported as
14
- * an issue rather than silently dropped.
15
- *
16
- * Changed plugins always have their runtime manifests regenerated (honoring
17
- * their selection). With `resync`, the regenerated content is additionally
18
- * re-installed into the agents so Claude/Codex reflect the new content.
8
+ * Refresh local sources and repair effective installations from their complete
9
+ * source snapshots. Runtime installations are never treated as upstream input.
19
10
  */
20
11
  export function updateLock(pluginsDir, now = new Date().toISOString(), opts = {}) {
21
- const lockFile = lockPath(pluginsDir);
22
- const lock = readLock(lockFile);
12
+ const snapshot = readLock(lockPath(pluginsDir));
13
+ const only = opts.only ? new Set(opts.only) : undefined;
23
14
  const results = [];
24
15
  const missing = [];
25
16
  const changedNames = [];
26
- const only = opts.only ? new Set(opts.only) : undefined;
27
- for (const [name, entry] of Object.entries(lock.plugins)) {
17
+ for (const [name, entry] of Object.entries(snapshot.plugins)) {
28
18
  if (only && !only.has(name))
29
19
  continue;
30
- const dir = installedPluginDir(pluginsDir, name, entry.origin);
31
- if (!existsSync(dir)) {
20
+ const installedDir = installedPluginDir(pluginsDir, name, entry.origin);
21
+ const resolvedSource = entry.origin.type === "local" ? resolve(pluginsDir, entry.origin.path) : undefined;
22
+ const localSource = resolvedSource && resolvedSource !== resolve(installedDir)
23
+ ? resolvedSource
24
+ : undefined;
25
+ const cache = pluginSourceCacheDir(pluginsDir, name);
26
+ const source = localSource && existsSync(localSource) ? localSource : cache;
27
+ if (!existsSync(source)) {
32
28
  missing.push(name);
33
29
  continue;
34
30
  }
35
- const manifest = readManifest(dir);
36
- const hash = folderHash(dir, PROJECTION_DIRS, packageFilter(manifest, { includeProjections: false }));
37
- const changed = hash !== entry.folderHash || manifest.version !== entry.version;
38
- if (changed) {
39
- entry.folderHash = hash;
40
- entry.version = manifest.version;
41
- entry.updatedAt = now;
42
- // Regenerate runtime manifests from the updated source, honoring selection.
43
- // Covers every registered adapter target (claude/codex/antigravity) so a
44
- // projection can't go stale after an update.
45
- adaptPlugin(dir, [...ADAPTER_TARGETS], entry.selection);
31
+ const result = installPlugin({
32
+ source,
33
+ pluginsDir,
34
+ origin: entry.origin,
35
+ selection: entry.selection,
36
+ skipUnchanged: true,
37
+ now,
38
+ });
39
+ if (result.changed)
46
40
  changedNames.push(name);
47
- }
48
- results.push({ name, changed, version: manifest.version, folderHash: hash });
41
+ results.push({
42
+ name,
43
+ changed: result.changed,
44
+ version: result.version,
45
+ sourceHash: result.sourceHash,
46
+ installedHash: result.installedHash,
47
+ });
49
48
  }
50
- writeLock(lockFile, lock);
51
49
  const out = { results, missing };
52
50
  if (opts.resync && changedNames.length > 0) {
53
51
  const ctx = { pluginsDir, plugins: changedNames, scope: opts.scope ?? "project" };
54
- out.agents = (opts.agents ?? resolveAgents()).map((a) => a.refresh(ctx));
52
+ out.agents = (opts.agents ?? resolveAgents()).map((agent) => agent.refresh(ctx));
55
53
  }
56
54
  return out;
57
55
  }
@@ -1,5 +1,5 @@
1
- import { cpSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { dirname, relative } from "node:path";
1
+ import { cpSync, lstatSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
2
+ import { dirname, isAbsolute, relative } from "node:path";
3
3
  export function ensureDir(dir) {
4
4
  mkdirSync(dir, { recursive: true });
5
5
  }
@@ -22,12 +22,25 @@ export function writeText(file, value) {
22
22
  */
23
23
  export function copyPluginDir(src, dest, include) {
24
24
  ensureDir(dirname(dest));
25
+ const sourceRoot = realpathSync(src);
25
26
  cpSync(src, dest, {
26
27
  recursive: true,
28
+ dereference: true,
27
29
  filter: (from) => {
28
30
  const base = from.split(/[/\\]/).pop() ?? "";
29
31
  if (base === ".git" || base === "node_modules" || base === ".DS_Store")
30
32
  return false;
33
+ try {
34
+ if (lstatSync(from).isSymbolicLink()) {
35
+ const target = realpathSync(from);
36
+ const relTarget = relative(sourceRoot, target);
37
+ if (relTarget === ".." || relTarget.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute(relTarget))
38
+ return false;
39
+ }
40
+ }
41
+ catch {
42
+ return false;
43
+ }
31
44
  if (!include)
32
45
  return true;
33
46
  return include(relative(src, from));
package/dist/src/lock.js CHANGED
@@ -1,20 +1,24 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { recordTelemetryEvent } from "./telemetry.js";
2
3
  import { LOCK_VERSION } from "./types.js";
3
4
  export function emptyLock() {
4
5
  return { version: LOCK_VERSION, plugins: {} };
5
6
  }
6
- export function readLock(file) {
7
+ export function readLock(file, telemetrySpan) {
7
8
  if (!existsSync(file))
8
9
  return emptyLock();
9
10
  const raw = JSON.parse(readFileSync(file, "utf8"));
11
+ if (typeof raw?.version === "number") {
12
+ const observed = raw.version === 2 || raw.version === LOCK_VERSION ? raw.version : -1;
13
+ recordTelemetryEvent("adg.lock.read", { "format.version": observed }, telemetrySpan);
14
+ }
10
15
  if (typeof raw.version !== "number" || typeof raw.plugins !== "object" || raw.plugins === null) {
11
16
  throw new Error(`${file} is not a valid .plugin-lock.json`);
12
17
  }
13
- // Pre-release policy: a lock from an older format version is fully
14
- // regenerable from the plugin directories, so rebuild rather than merge
15
- // incompatible entry shapes.
16
- if (raw.version !== LOCK_VERSION)
17
- return emptyLock();
18
+ if (raw.version !== LOCK_VERSION) {
19
+ throw new Error(`${file} uses unsupported lock version ${raw.version}; expected ${LOCK_VERSION}. ` +
20
+ "Run `adg plugins migrate` with the same scope flag to upgrade it.");
21
+ }
18
22
  return raw;
19
23
  }
20
24
  export function writeLock(file, lock) {
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { ADG_SCHEMA_VERSION } from "./types.js";
2
+ import { isAbsolute, join } from "node:path";
3
+ import { ADG_SCHEMA_VERSION, COMPONENT_TYPES } from "./types.js";
4
+ import { recordTelemetryEvent } from "./telemetry.js";
4
5
  /** Canonical, vendor-neutral source manifest location (a plugin). */
5
6
  export const ADG_MANIFEST_PATH = join(".agents", ".plugin.json");
6
7
  /** Canonical, vendor-neutral source catalog location (a marketplace). */
@@ -32,7 +33,7 @@ export class ManifestError extends Error {
32
33
  }
33
34
  }
34
35
  /** Read and validate a plugin's `.agents/.plugin.json` (or legacy fallback). */
35
- export function readManifest(pluginDir) {
36
+ export function readManifest(pluginDir, telemetrySpan) {
36
37
  const file = findManifestFile(pluginDir);
37
38
  if (!file) {
38
39
  throw new ManifestError([`${ADG_MANIFEST_PATH} not found in ${pluginDir}`]);
@@ -44,6 +45,15 @@ export function readManifest(pluginDir) {
44
45
  catch (err) {
45
46
  throw new ManifestError([`${file} is not valid JSON: ${err.message}`]);
46
47
  }
48
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
49
+ const schemaVersion = raw.schemaVersion;
50
+ if (typeof schemaVersion === "string") {
51
+ recordTelemetryEvent("adg.manifest.read", {
52
+ "schema.version": schemaVersion === ADG_SCHEMA_VERSION ? schemaVersion : "other",
53
+ "manifest.layout": file === join(pluginDir, LEGACY_MANIFEST_PATH) ? "legacy" : "canonical",
54
+ }, telemetrySpan);
55
+ }
56
+ }
47
57
  return validateManifest(raw);
48
58
  }
49
59
  /** Validate an already-parsed manifest object, throwing ManifestError on failure. */
@@ -75,6 +85,11 @@ export function collectIssues(raw) {
75
85
  if (m.skills !== undefined && typeof m.skills !== "string" && !isStringArray(m.skills)) {
76
86
  issues.push("skills must be a string or an array of strings");
77
87
  }
88
+ if (typeof m.skills === "string" && !isSafeRelativePointer(m.skills))
89
+ issues.push("skills must stay within the plugin directory");
90
+ if (isStringArray(m.skills) && m.skills.some((path) => !isSafeRelativePointer(path))) {
91
+ issues.push("skills entries must stay within the plugin directory");
92
+ }
78
93
  if (m.mcp !== undefined) {
79
94
  issues.push("mcp is not supported; use mcpServers");
80
95
  }
@@ -82,6 +97,10 @@ export function collectIssues(raw) {
82
97
  if (m[key] !== undefined && typeof m[key] !== "string") {
83
98
  issues.push(`${key} must be a string`);
84
99
  }
100
+ if (typeof m[key] === "string" && ["agents", "commands", "apps", "hooks", "mcpServers"].includes(key)
101
+ && !isSafeRelativePointer(m[key])) {
102
+ issues.push(`${key} must stay within the plugin directory`);
103
+ }
85
104
  }
86
105
  if (m.strict !== undefined && typeof m.strict !== "boolean") {
87
106
  issues.push("strict must be a boolean");
@@ -104,6 +123,31 @@ export function collectIssues(raw) {
104
123
  });
105
124
  }
106
125
  }
126
+ if (m.selectionDependencies !== undefined) {
127
+ if (typeof m.selectionDependencies !== "object" || m.selectionDependencies === null || Array.isArray(m.selectionDependencies)) {
128
+ issues.push("selectionDependencies must be an object");
129
+ }
130
+ else {
131
+ for (const [component, rawRequirement] of Object.entries(m.selectionDependencies)) {
132
+ if (!COMPONENT_TYPES.includes(component)) {
133
+ issues.push(`selectionDependencies.${component} is not a supported component`);
134
+ continue;
135
+ }
136
+ if (typeof rawRequirement !== "object" || rawRequirement === null || Array.isArray(rawRequirement)) {
137
+ issues.push(`selectionDependencies.${component} must be an object`);
138
+ continue;
139
+ }
140
+ const requirement = rawRequirement;
141
+ if (requirement.components !== undefined && (!isStringArray(requirement.components)
142
+ || requirement.components.some((value) => !COMPONENT_TYPES.includes(value)))) {
143
+ issues.push(`selectionDependencies.${component}.components must contain supported component names`);
144
+ }
145
+ if (requirement.skills !== undefined && !isStringArray(requirement.skills)) {
146
+ issues.push(`selectionDependencies.${component}.skills must be an array of strings`);
147
+ }
148
+ }
149
+ }
150
+ }
107
151
  // `adapters` is no longer part of the DSL. A stray one from an old manifest is
108
152
  // tolerated (ignored) rather than rejected — output paths are ADG-internal.
109
153
  return issues;
@@ -111,3 +155,8 @@ export function collectIssues(raw) {
111
155
  function isStringArray(v) {
112
156
  return Array.isArray(v) && v.every((x) => typeof x === "string");
113
157
  }
158
+ function isSafeRelativePointer(value) {
159
+ if (isAbsolute(value) || /^[A-Za-z]:/.test(value) || /^[/\\]{2}/.test(value))
160
+ return false;
161
+ return !value.replaceAll("\\", "/").split("/").includes("..");
162
+ }