@rbbtsn0w/adg 0.5.0 → 0.6.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -71,6 +71,42 @@ stable output and exit-code contract.
71
71
  `adg` is the only command you invoke — no Node build step beyond the global
72
72
  install. To hack on the CLI itself, see [Developing from source](#developing-from-source).
73
73
 
74
+ ## Copy-paste prompt for coding agents
75
+
76
+ Paste the prompt below into Codex, Claude Code, or another coding agent to have
77
+ it install ADG, add a plugin source, connect the installed plugins to the active
78
+ runtime, and verify the result. Replace the placeholders before sending it.
79
+
80
+ ```text
81
+ Set up ADG for this environment and use it to install plugins from
82
+ anthropics/knowledge-work-plugins.
83
+
84
+ Requirements:
85
+ 1. Inspect the current environment first. If `adg` is unavailable, install the
86
+ stable `@rbbtsn0w/adg` package with an available supported package manager
87
+ (`brew install adg` after `brew tap RbBtSn0w/tap`, or
88
+ `npm install -g @rbbtsn0w/adg`). Do not modify the current project yet.
89
+ 2. Use the <GLOBAL_OR_PROJECT> scope explicitly on every mutating command:
90
+ `--global` for plugins shared across projects, or `--project` for this
91
+ repository only. Do not rely on interactive prompts.
92
+ 3. Inspect the source and installed plugin names, then install the requested
93
+ plugins. Use `adg plugins add <OWNER/REPO_OR_LOCAL_PATH> --all
94
+ <SCOPE_FLAG>` unless I list specific plugins or components below.
95
+ 4. Connect the installed plugins to <codex|claude|antigravity|all> with
96
+ `adg plugins link --target <TARGET> <SCOPE_FLAG>`. Let ADG manage runtime
97
+ projections; do not manually edit or copy files into agent-specific plugin
98
+ directories.
99
+ 5. Verify the setup with `adg plugins list <SCOPE_FLAG>` and
100
+ `adg plugins status --target <TARGET> <SCOPE_FLAG>`. Report the commands you
101
+ ran, the installed plugin names, and any remaining drift or errors.
102
+
103
+ Requested plugins/components (optional): <ALL_OR_LIST>
104
+ ```
105
+
106
+ For example, replace `<GLOBAL_OR_PROJECT>` with `global`, `<SCOPE_FLAG>` with
107
+ `--global`, and `<TARGET>` with `codex` for a personal Codex setup available in
108
+ every project.
109
+
74
110
  ---
75
111
 
76
112
  # Works with existing ecosystems
@@ -1,3 +1,5 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
1
3
  import { ADG_SCHEMA_VERSION } from "../types.js";
2
4
  import { validateManifest } from "../manifest.js";
3
5
  import { toPosix } from "../fsutil.js";
@@ -15,7 +17,7 @@ import { toPosix } from "../fsutil.js";
15
17
  * emits valid `./skills/<id>` entries instead of leaking bare ids into a Claude
16
18
  * manifest.
17
19
  */
18
- export function fromNativeManifest(raw, kind) {
20
+ export function fromNativeManifest(raw, kind, pluginDir) {
19
21
  if (typeof raw !== "object" || raw === null) {
20
22
  throw new Error("native manifest must be a JSON object");
21
23
  }
@@ -36,6 +38,8 @@ export function fromNativeManifest(raw, kind) {
36
38
  copyIfString(n, out, "agents");
37
39
  copyIfString(n, out, "hooks");
38
40
  copyIfString(n, out, "mcpServers");
41
+ if (typeof out.mcpServers !== "string" && typeof n.mcp === "string")
42
+ out.mcpServers = n.mcp;
39
43
  copyIfString(n, out, "apps");
40
44
  if (typeof n.author === "object" && n.author !== null) {
41
45
  manifest.author = n.author;
@@ -57,6 +61,17 @@ export function fromNativeManifest(raw, kind) {
57
61
  manifest.skills = "./skills/";
58
62
  }
59
63
  manifest.strict = typeof n.strict === "boolean" ? n.strict : true;
64
+ if (!manifest.hooks && pluginDir) {
65
+ const hooksDir = join(pluginDir, "hooks");
66
+ try {
67
+ if (existsSync(hooksDir) && statSync(hooksDir).isDirectory())
68
+ manifest.hooks = "./hooks/";
69
+ }
70
+ catch {
71
+ // hooks inference is best-effort; unreadable or concurrently removed dirs
72
+ // must not abort reverse-adaptation.
73
+ }
74
+ }
60
75
  return validateManifest(manifest);
61
76
  }
62
77
  function copyIfString(src, dst, key) {
@@ -16,6 +16,7 @@ import { makeCli, skippedResult } from "./base.js";
16
16
  * versions) rather than hand-editing Claude's internal state.
17
17
  */
18
18
  const MARKETPLACE = "adg";
19
+ const UNRECOGNIZED_PLUGIN_LIST = "claude plugin list returned unrecognized output";
19
20
  function claudeHome(env) {
20
21
  return env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), ".claude");
21
22
  }
@@ -94,7 +95,7 @@ export function parseClaudeMarketplaceList(out) {
94
95
  }
95
96
  }
96
97
  /** Register or refresh the ADG store as a Claude marketplace, failing open. */
97
- export function syncMarketplace(pluginsDir, name, runner = run) {
98
+ export function syncMarketplace(pluginsDir, name, runner = run, warn = console.warn) {
98
99
  const listed = runner(["plugin", "marketplace", "list", "--json"]);
99
100
  if (listed.ok && parseClaudeMarketplaceList(listed.out).includes(name)) {
100
101
  // Claude's marketplace update path can fail on existing installs (for
@@ -104,7 +105,10 @@ export function syncMarketplace(pluginsDir, name, runner = run) {
104
105
  if (runner(["plugin", "marketplace", "update", name]).ok)
105
106
  return;
106
107
  }
107
- runner(["plugin", "marketplace", "add", pluginsDir]);
108
+ const added = runner(["plugin", "marketplace", "add", pluginsDir]);
109
+ if (!added.ok) {
110
+ warn(`failed to sync Claude marketplace (${name}): ${added.out.trim() || "claude plugin marketplace add failed without an error message"}`);
111
+ }
108
112
  }
109
113
  export const claudeAgent = {
110
114
  id: "claude",
@@ -156,12 +160,54 @@ export const claudeAgent = {
156
160
  listInstalled(ctx) {
157
161
  if (!available())
158
162
  return undefined;
159
- const res = run(["plugin", "list"]);
160
- if (!res.ok)
161
- return undefined;
162
- return parseClaudePluginList(res.out, claudeMarketplaceName(ctx.pluginsDir), ctx.scope);
163
+ const marketplace = claudeMarketplaceName(ctx.pluginsDir);
164
+ const jsonRes = run(["plugin", "list", "--json"]);
165
+ if (jsonRes.ok) {
166
+ const parsed = parseClaudePluginListJson(jsonRes.out, marketplace, ctx.scope);
167
+ if (parsed !== undefined)
168
+ return parsed;
169
+ return claudeListFailure(jsonRes.out);
170
+ }
171
+ const textRes = run(["plugin", "list"]);
172
+ if (!textRes.ok)
173
+ return { error: textRes.out.trim() || jsonRes.out.trim() || "claude plugin list failed without an error message" };
174
+ const fallback = parseClaudePluginList(textRes.out, marketplace, ctx.scope);
175
+ if (fallback.length > 0 || textRes.out.trim() === "")
176
+ return fallback;
177
+ return claudeListFailure(textRes.out);
163
178
  },
164
179
  };
180
+ export function claudeListFailure(out) {
181
+ const detail = out.trim() || "claude plugin list failed without an error message";
182
+ return { error: `${UNRECOGNIZED_PLUGIN_LIST}: ${detail}` };
183
+ }
184
+ /** Parse `claude plugin list --json` into enabled plugin names for a marketplace + scope. */
185
+ export function parseClaudePluginListJson(out, marketplace, scope) {
186
+ try {
187
+ const parsed = JSON.parse(out);
188
+ if (!Array.isArray(parsed))
189
+ return undefined;
190
+ const names = [];
191
+ const seen = new Set();
192
+ for (const entry of parsed) {
193
+ if (typeof entry !== "object" || entry === null)
194
+ continue;
195
+ const record = entry;
196
+ const id = typeof record.id === "string" ? record.id : undefined;
197
+ const entryScope = typeof record.scope === "string" ? record.scope.toLowerCase() : undefined;
198
+ const enabled = record.enabled === true;
199
+ const head = id?.match(/^(\S+?)@([\w.-]+)$/);
200
+ if (!head || head[2] !== marketplace || entryScope !== scope || !enabled || seen.has(head[1]))
201
+ continue;
202
+ seen.add(head[1]);
203
+ names.push(head[1]);
204
+ }
205
+ return names;
206
+ }
207
+ catch {
208
+ return undefined;
209
+ }
210
+ }
165
211
  /**
166
212
  * Parse `claude plugin list` output into the *enabled* plugin names from a given
167
213
  * marketplace and install scope. The listing groups each plugin as a
@@ -5,6 +5,7 @@ import { join, resolve } from "node:path";
5
5
  import { codexMarketplaceRoot, globalPluginsDir, marketplacePath } from "../paths.js";
6
6
  import { readMarketplace, writeMarketplace } from "../marketplace.js";
7
7
  import { makeCli, skippedResult } from "./base.js";
8
+ const UNRECOGNIZED_PLUGIN_LIST = "codex plugin list returned unrecognized output";
8
9
  /**
9
10
  * Codex agent.
10
11
  *
@@ -41,11 +42,15 @@ export function writeCodexMarketplaceName(pluginsDir) {
41
42
  return name;
42
43
  }
43
44
  /** Register the local marketplace root Codex expects for this store. */
44
- function syncMarketplace(pluginsDir, marketplace) {
45
+ export function syncMarketplace(pluginsDir, marketplace, runner = run, warn = console.warn) {
45
46
  const root = codexMarketplaceRoot(pluginsDir);
46
- const add = run(["plugin", "marketplace", "add", root]);
47
- if (!add.ok)
48
- run(["plugin", "marketplace", "upgrade", marketplace]);
47
+ const add = runner(["plugin", "marketplace", "add", root]);
48
+ if (add.ok)
49
+ return;
50
+ const upgraded = runner(["plugin", "marketplace", "upgrade", marketplace]);
51
+ if (!upgraded.ok) {
52
+ warn(`failed to sync Codex marketplace (${marketplace}): ${upgraded.out.trim() || add.out.trim() || "codex plugin marketplace sync failed without an error message"}`);
53
+ }
49
54
  }
50
55
  export const codexAgent = {
51
56
  id: "codex",
@@ -92,10 +97,20 @@ export const codexAgent = {
92
97
  const mp = writeCodexMarketplaceName(ctx.pluginsDir);
93
98
  if (!mp)
94
99
  return undefined; // no generated marketplace → can't scope the query
95
- const res = run(["plugin", "list"]);
96
- if (!res.ok)
97
- return codexListFailure(res.out);
98
- return parseCodexPluginList(res.out, mp);
100
+ const jsonRes = run(["plugin", "list", "--json"]);
101
+ if (jsonRes.ok) {
102
+ const parsed = parseCodexPluginListJson(jsonRes.out, mp);
103
+ if (parsed !== undefined)
104
+ return parsed;
105
+ return codexUnrecognizedListFailure(jsonRes.out);
106
+ }
107
+ const textRes = run(["plugin", "list"]);
108
+ if (!textRes.ok)
109
+ return codexListFailure(textRes.out || jsonRes.out);
110
+ const fallback = parseCodexPluginList(textRes.out, mp);
111
+ if (fallback.length > 0 || textRes.out.trim() === "")
112
+ return fallback;
113
+ return codexUnrecognizedListFailure(textRes.out);
99
114
  },
100
115
  };
101
116
  /** Preserve Codex's diagnostic and offer cleanup for a stale ADG project marketplace. */
@@ -107,6 +122,40 @@ export function codexListFailure(out) {
107
122
  ...(staleMarketplace ? { recoveryCommand: `codex plugin marketplace remove ${staleMarketplace[1]}` } : {}),
108
123
  };
109
124
  }
125
+ export function codexUnrecognizedListFailure(out) {
126
+ const detail = out.trim() || "codex plugin list failed without an error message";
127
+ return { error: `${UNRECOGNIZED_PLUGIN_LIST}: ${detail}` };
128
+ }
129
+ /** Parse `codex plugin list --json` into installed and enabled plugin names for one marketplace. */
130
+ export function parseCodexPluginListJson(out, marketplace) {
131
+ try {
132
+ const parsed = JSON.parse(out);
133
+ if (typeof parsed !== "object" || parsed === null)
134
+ return undefined;
135
+ const installed = parsed.installed;
136
+ if (!Array.isArray(installed))
137
+ return undefined;
138
+ const names = [];
139
+ const seen = new Set();
140
+ for (const entry of installed) {
141
+ if (typeof entry !== "object" || entry === null)
142
+ continue;
143
+ const record = entry;
144
+ const name = typeof record.name === "string" ? record.name : undefined;
145
+ const mp = typeof record.marketplaceName === "string" ? record.marketplaceName : undefined;
146
+ const isInstalled = record.installed === true;
147
+ const enabled = record.enabled === true;
148
+ if (!name || mp !== marketplace || !isInstalled || !enabled || seen.has(name))
149
+ continue;
150
+ seen.add(name);
151
+ names.push(name);
152
+ }
153
+ return names;
154
+ }
155
+ catch {
156
+ return undefined;
157
+ }
158
+ }
110
159
  /**
111
160
  * Parse `codex plugin list` output into the *installed and enabled* plugin names
112
161
  * from a given marketplace. The listing is a whitespace-aligned table whose
@@ -132,6 +132,14 @@ async function resolveActionScope(values, verb) {
132
132
  info: { label: global ? "global" : "project", globalDir },
133
133
  };
134
134
  }
135
+ function resolveVerbTargets(values, verb) {
136
+ return values.target === "all"
137
+ ? resolveTargets("all")
138
+ : [requireSingleTarget(values.target, verb)];
139
+ }
140
+ function printCliUnavailableNote(target, message) {
141
+ console.log(ui.warn(`note: \`${target}\` CLI not found — ${message}`));
142
+ }
135
143
  /**
136
144
  * Top-level dispatcher for `adg plugins <verb>`: render help, resolve aliases,
137
145
  * look the verb up in the command table, then hand off to the per-verb handler
@@ -163,6 +171,132 @@ export async function runPlugins(rawVerb, rest) {
163
171
  return runCache(rest);
164
172
  return runPluginsVerb(verb, rest, cmd);
165
173
  }
174
+ async function handleAdd(rest, cmd) {
175
+ const { values, positionals } = parseVerb("add", cmd.flags, rest);
176
+ const spec = positionals[0];
177
+ if (!spec)
178
+ fail("plugins add requires a <plugin-dir | owner/repo[@ref] | github-url>");
179
+ const tty = process.stdin.isTTY;
180
+ let global = Boolean(values.global);
181
+ if (!values.dir && values.global === undefined && values.project === undefined && tty) {
182
+ global = await selectScopeInteractive();
183
+ }
184
+ if (!values.dir)
185
+ global = promoteGlobalTrap(global);
186
+ const pluginsDir = values.dir
187
+ ? resolve(values.dir)
188
+ : global
189
+ ? globalPluginsDir()
190
+ : projectPluginsDir();
191
+ const only = resolveComponents(values.only);
192
+ const skillsSubset = values.skill && values.skill.length > 0 ? values.skill : undefined;
193
+ const narrowed = only !== undefined || skillsSubset !== undefined;
194
+ const { order, installed, removed, converted, agents } = await addPlugins({
195
+ spec,
196
+ pluginsDir,
197
+ ref: values.ref,
198
+ sparse: values.sparse,
199
+ path: values.path,
200
+ all: values.all,
201
+ plugins: values.plugin,
202
+ only,
203
+ skillsSubset,
204
+ withDeps: !values["no-deps"],
205
+ marketplaceName: values["marketplace-name"],
206
+ targets: values.target !== undefined ? resolveTargets(values.target) : undefined,
207
+ selectPlugins: tty ? selectPluginsInteractive : undefined,
208
+ selectTargets: tty && values.target === undefined ? selectTargetsInteractive : undefined,
209
+ confirmFull: tty && !narrowed ? confirmFullInstall : undefined,
210
+ selectComponents: tty && !narrowed ? selectComponentsInteractive : undefined,
211
+ activate: true,
212
+ scope: global ? "user" : "project",
213
+ });
214
+ for (const name of converted)
215
+ console.log(ui.meta(`converted native manifest -> .agents/.plugin.json: ${name}`));
216
+ for (const name of removed)
217
+ console.log(`${ui.warn("removed")} ${ui.name(name)}`);
218
+ if (order.length > 1)
219
+ console.log(ui.meta(`install order: ${order.join(" -> ")}`));
220
+ for (const res of installed) {
221
+ console.log(`${ui.ok("added")} ${ui.name(res.name)} ${ui.meta(`-> ${res.installedTo}`)}`);
222
+ console.log(ui.meta(` sourceHash: ${res.sourceHash}`));
223
+ console.log(ui.meta(` installedHash: ${res.installedHash}`));
224
+ for (const f of res.adapted)
225
+ console.log(ui.meta(` adapted: ${f}`));
226
+ }
227
+ for (const line of renderAgentReport(agents, "enabled"))
228
+ console.log(line);
229
+ }
230
+ async function handleLink(rest, cmd) {
231
+ const { values, positionals } = parseVerb("link", cmd.flags, rest);
232
+ const targets = resolveVerbTargets(values, "link");
233
+ const sc = await resolveActionScope(values, "link");
234
+ const names = positionals.length > 0 ? positionals : undefined;
235
+ for (const target of targets) {
236
+ const res = linkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
237
+ for (const action of res.actions) {
238
+ console.log(`${ui.ok("linked")} ${ui.name(action.name)} ${ui.meta(`[${res.target}]`)}${action.linkedTo ? ui.meta(` -> ${action.linkedTo}`) : ""}`);
239
+ for (const file of action.adapted)
240
+ console.log(ui.meta(` adapted: ${file}`));
241
+ }
242
+ if (res.cliSkipped)
243
+ printCliUnavailableNote(target, `manifests were generated, but nothing was enabled in ${target}.`);
244
+ }
245
+ }
246
+ async function handleUnlink(rest, cmd) {
247
+ const { values, positionals } = parseVerb("unlink", cmd.flags, rest);
248
+ const targets = resolveVerbTargets(values, "unlink");
249
+ const sc = await resolveActionScope(values, "unlink");
250
+ const names = positionals.length > 0 ? positionals : undefined;
251
+ for (const target of targets) {
252
+ const res = unlinkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
253
+ for (const name of res.unlinked)
254
+ console.log(`${ui.ok("unlinked")} ${ui.name(name)} ${ui.meta(`[${res.target}]`)}`);
255
+ if (res.cliSkipped) {
256
+ printCliUnavailableNote(target, `nothing was unlinked from ${target}.`);
257
+ }
258
+ else if (res.unlinked.length === 0 && targets.length === 1) {
259
+ console.log(ui.meta(`nothing to unlink from ${target}`));
260
+ }
261
+ }
262
+ }
263
+ async function handleSync(rest, cmd) {
264
+ const { values, positionals } = parseVerb("sync", cmd.flags, rest);
265
+ const targets = resolveVerbTargets(values, "sync");
266
+ const sc = await resolveActionScope(values, "sync");
267
+ const names = positionals.length > 0 ? positionals : undefined;
268
+ for (const target of targets) {
269
+ const res = syncPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
270
+ for (const action of res.actions) {
271
+ const tail = action.synced ? ui.meta(` -> ${res.target}`) : "";
272
+ console.log(`${ui.ok("synced")} ${ui.name(action.name)} ${ui.meta(`[${res.target}]`)}${tail}`);
273
+ }
274
+ if (res.cliSkipped)
275
+ printCliUnavailableNote(target, `manifests were regenerated, but nothing was re-synced in ${target}.`);
276
+ }
277
+ }
278
+ async function handleUpdate(rest, cmd) {
279
+ const { values, positionals } = parseVerb("update", cmd.flags, rest);
280
+ const source = positionals[0];
281
+ for (const sc of await resolveUpdateScopes(values)) {
282
+ if (sc.heading)
283
+ console.log(`${ui.name(sc.heading)}`);
284
+ try {
285
+ const result = await updatePlugins({
286
+ pluginsDir: sc.dir,
287
+ source,
288
+ all: values.all,
289
+ activate: true,
290
+ agentScope: sc.agentScope,
291
+ scope: { label: sc.label, globalDir: globalPluginsDir() },
292
+ });
293
+ printUpdateReport(result);
294
+ }
295
+ catch (err) {
296
+ console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
297
+ }
298
+ }
299
+ }
166
300
  async function runPluginsVerb(verb, rest, cmd) {
167
301
  switch (verb) {
168
302
  case "init": {
@@ -205,69 +339,7 @@ async function runPluginsVerb(verb, rest, cmd) {
205
339
  return;
206
340
  }
207
341
  case "add": {
208
- const { values, positionals } = parseVerb(verb, cmd.flags, rest);
209
- const spec = positionals[0];
210
- if (!spec)
211
- fail("plugins add requires a <plugin-dir | owner/repo[@ref] | github-url>");
212
- const tty = process.stdin.isTTY;
213
- // Scope: honor an explicit --dir/--global/--project, else ask in a terminal
214
- // (defaulting to project non-interactively).
215
- let global = Boolean(values.global);
216
- if (!values.dir && values.global === undefined && values.project === undefined && tty) {
217
- global = await selectScopeInteractive();
218
- }
219
- // Guard the home==global trap: installing global plugins at project scope
220
- // would pin them to the cwd. Skip for an explicit --dir store.
221
- if (!values.dir)
222
- global = promoteGlobalTrap(global);
223
- const pluginsDir = values.dir
224
- ? resolve(values.dir)
225
- : global
226
- ? globalPluginsDir()
227
- : projectPluginsDir();
228
- // A source may hold one plugin or a whole marketplace. addPlugins discovers
229
- // all of them; in a terminal the user picks scope, then plugins, then agents,
230
- // then (unless --only/--skill narrow it) chooses what to install per plugin.
231
- // --all / --plugin / --path / --only / --skill narrow non-interactively.
232
- const only = resolveComponents(values.only);
233
- const skillsSubset = values.skill && values.skill.length > 0 ? values.skill : undefined;
234
- const narrowed = only !== undefined || skillsSubset !== undefined;
235
- const { order, installed, removed, converted, agents } = await addPlugins({
236
- spec,
237
- pluginsDir,
238
- ref: values.ref,
239
- sparse: values.sparse,
240
- path: values.path,
241
- all: values.all,
242
- plugins: values.plugin,
243
- only,
244
- skillsSubset,
245
- withDeps: !values["no-deps"],
246
- marketplaceName: values["marketplace-name"],
247
- targets: values.target !== undefined ? resolveTargets(values.target) : undefined,
248
- selectPlugins: tty ? selectPluginsInteractive : undefined,
249
- selectTargets: tty && values.target === undefined ? selectTargetsInteractive : undefined,
250
- confirmFull: tty && !narrowed ? confirmFullInstall : undefined,
251
- selectComponents: tty && !narrowed ? selectComponentsInteractive : undefined,
252
- // Make the install actually usable in the chosen agents, not just stored.
253
- activate: true,
254
- scope: global ? "user" : "project",
255
- });
256
- for (const name of converted)
257
- console.log(ui.meta(`converted native manifest -> .agents/.plugin.json: ${name}`));
258
- for (const name of removed)
259
- console.log(`${ui.warn("removed")} ${ui.name(name)}`);
260
- if (order.length > 1)
261
- console.log(ui.meta(`install order: ${order.join(" -> ")}`));
262
- for (const res of installed) {
263
- console.log(`${ui.ok("added")} ${ui.name(res.name)} ${ui.meta(`-> ${res.installedTo}`)}`);
264
- console.log(ui.meta(` sourceHash: ${res.sourceHash}`));
265
- console.log(ui.meta(` installedHash: ${res.installedHash}`));
266
- for (const f of res.adapted)
267
- console.log(ui.meta(` adapted: ${f}`));
268
- }
269
- for (const line of renderAgentReport(agents, "enabled"))
270
- console.log(line);
342
+ await handleAdd(rest, cmd);
271
343
  return;
272
344
  }
273
345
  case "import-skills": {
@@ -289,23 +361,7 @@ async function runPluginsVerb(verb, rest, cmd) {
289
361
  return;
290
362
  }
291
363
  case "link": {
292
- const { values, positionals } = parseVerb(verb, cmd.flags, rest);
293
- const targets = values.target === "all"
294
- ? resolveTargets("all")
295
- : [requireSingleTarget(values.target, "link")];
296
- const sc = await resolveActionScope(values, "link");
297
- const names = positionals.length > 0 ? positionals : undefined;
298
- for (const target of targets) {
299
- const res = linkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
300
- for (const a of res.actions) {
301
- console.log(`${ui.ok("linked")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${a.linkedTo ? ui.meta(` -> ${a.linkedTo}`) : ""}`);
302
- for (const f of a.adapted)
303
- console.log(ui.meta(` adapted: ${f}`));
304
- }
305
- if (res.cliSkipped) {
306
- console.log(ui.warn(`note: \`${target}\` CLI not found — manifests were generated, but nothing was enabled in ${target}.`));
307
- }
308
- }
364
+ await handleLink(rest, cmd);
309
365
  return;
310
366
  }
311
367
  case "disable":
@@ -331,67 +387,15 @@ async function runPluginsVerb(verb, rest, cmd) {
331
387
  return;
332
388
  }
333
389
  case "unlink": {
334
- const { values, positionals } = parseVerb(verb, cmd.flags, rest);
335
- const targets = values.target === "all"
336
- ? resolveTargets("all")
337
- : [requireSingleTarget(values.target, "unlink")];
338
- const sc = await resolveActionScope(values, "unlink");
339
- const names = positionals.length > 0 ? positionals : undefined;
340
- for (const target of targets) {
341
- const res = unlinkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
342
- for (const name of res.unlinked)
343
- console.log(`${ui.ok("unlinked")} ${ui.name(name)} ${ui.meta(`[${res.target}]`)}`);
344
- if (res.cliSkipped) {
345
- console.log(ui.warn(`note: \`${target}\` CLI not found — nothing was unlinked from ${target}.`));
346
- }
347
- else if (res.unlinked.length === 0) {
348
- if (targets.length === 1) {
349
- console.log(ui.meta(`nothing to unlink from ${target}`));
350
- }
351
- }
352
- }
390
+ await handleUnlink(rest, cmd);
353
391
  return;
354
392
  }
355
393
  case "sync": {
356
- const { values, positionals } = parseVerb(verb, cmd.flags, rest);
357
- const targets = values.target === "all"
358
- ? resolveTargets("all")
359
- : [requireSingleTarget(values.target, "sync")];
360
- const sc = await resolveActionScope(values, "sync");
361
- const names = positionals.length > 0 ? positionals : undefined;
362
- for (const target of targets) {
363
- const res = syncPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
364
- for (const a of res.actions) {
365
- const tail = a.synced ? ui.meta(` -> ${res.target}`) : "";
366
- console.log(`${ui.ok("synced")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${tail}`);
367
- }
368
- if (res.cliSkipped) {
369
- console.log(ui.warn(`note: \`${target}\` CLI not found — manifests were regenerated, but nothing was re-synced in ${target}.`));
370
- }
371
- }
394
+ await handleSync(rest, cmd);
372
395
  return;
373
396
  }
374
397
  case "update": {
375
- const { values, positionals } = parseVerb(verb, cmd.flags, rest);
376
- const source = positionals[0];
377
- for (const sc of await resolveUpdateScopes(values)) {
378
- if (sc.heading)
379
- console.log(`${ui.name(sc.heading)}`);
380
- try {
381
- const result = await updatePlugins({
382
- pluginsDir: sc.dir,
383
- source,
384
- all: values.all,
385
- activate: true,
386
- agentScope: sc.agentScope,
387
- scope: { label: sc.label, globalDir: globalPluginsDir() },
388
- });
389
- printUpdateReport(result);
390
- }
391
- catch (err) {
392
- console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
393
- }
394
- }
398
+ await handleUpdate(rest, cmd);
395
399
  return;
396
400
  }
397
401
  case "remove": {
@@ -556,9 +560,7 @@ async function runMarketplace(args) {
556
560
  const source = positionals[0];
557
561
  if (!source)
558
562
  fail("marketplace sync requires a <source>");
559
- const targets = values.target === "all"
560
- ? resolveTargets("all")
561
- : [requireSingleTarget(values.target, "marketplace sync")];
563
+ const targets = resolveVerbTargets(values, "marketplace sync");
562
564
  const sc = await resolveActionScope(values, "marketplace sync");
563
565
  for (const target of targets) {
564
566
  const res = marketplaceSync({
@@ -572,7 +574,7 @@ async function runMarketplace(args) {
572
574
  console.log(`${ui.ok("synced")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${a.synced ? ui.meta(` -> ${res.target}`) : ""}`);
573
575
  }
574
576
  if (res.cliSkipped) {
575
- console.log(ui.warn(`note: \`${target}\` CLI not found — manifests were regenerated, but nothing was re-synced in ${target}.`));
577
+ printCliUnavailableNote(target, `manifests were regenerated, but nothing was re-synced in ${target}.`);
576
578
  }
577
579
  }
578
580
  return;
@@ -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";
@@ -140,16 +140,7 @@ function discoverPlugins(root) {
140
140
  if (native.kind === "adg")
141
141
  continue;
142
142
  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
- }
143
+ const manifest = fromNativeManifest(raw, native.kind, native.dir);
153
144
  writeJson(join(native.dir, ADG_MANIFEST_PATH), manifest);
154
145
  converted.push(manifest.name);
155
146
  }
@@ -268,6 +259,31 @@ function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
268
259
  }
269
260
  return stale;
270
261
  }
262
+ function activateInstalled(opts, targets, installed, existingPlugins) {
263
+ const updatedLock = readLock(lockPath(opts.pluginsDir));
264
+ const eligible = installed.filter((result) => pluginState(updatedLock.plugins[result.name]) === "enabled");
265
+ const toActivate = opts.skipUnchanged ? eligible.filter((result) => result.changed) : eligible;
266
+ if (!opts.activate || toActivate.length === 0)
267
+ return undefined;
268
+ const resolved = opts.agents ?? resolveAgents(targets);
269
+ const scope = opts.scope ?? "project";
270
+ const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
271
+ return resolved.map((agent) => {
272
+ const queryResult = agent.listInstalled?.(ctxFor([]));
273
+ const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
274
+ const alreadyInstalled = (name) => agentInstalled !== undefined
275
+ ? agentInstalled.includes(name)
276
+ : existingPlugins.has(name);
277
+ const activateNames = toActivate.filter((result) => !alreadyInstalled(result.name)).map((result) => result.name);
278
+ const refreshNames = toActivate.filter((result) => alreadyInstalled(result.name)).map((result) => result.name);
279
+ const parts = [];
280
+ if (activateNames.length > 0)
281
+ parts.push(agent.activate(ctxFor(activateNames)));
282
+ if (refreshNames.length > 0)
283
+ parts.push(agent.refresh(ctxFor(refreshNames)));
284
+ return parts.reduce((acc, result) => ({ agent: result.agent, affected: [...acc.affected, ...result.affected], skipped: acc.skipped && result.skipped }), { agent: agent.id, affected: [], skipped: true });
285
+ });
286
+ }
271
287
  /**
272
288
  * The unified install entrypoint. Treats any source as a marketplace: clone or
273
289
  * read it, discover every plugin (ADG plus reverse-adapted native), choose a
@@ -355,38 +371,7 @@ export async function addPlugins(opts) {
355
371
  // undefined targets = all registered agents. Under skipUnchanged (the update
356
372
  // path) only re-activate plugins that actually changed — re-running an agent
357
373
  // 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
- }
374
+ const agents = activateInstalled(opts, targets, installed, existingPlugins);
390
375
  return { order, installed, removed, converted, available, agents };
391
376
  }
392
377
  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)
@@ -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 { pluginRematerializationSource } from "../paths.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,14 @@ 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: pluginRematerializationSource(pluginsDir, plugin.name, plugin.origin),
42
+ pluginsDir,
43
+ origin: plugin.origin,
44
+ selection: plugin.selection,
45
+ targets: [...ADAPTER_TARGETS],
46
+ forceMaterialize: true,
47
+ }));
48
+ }
@@ -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
  /** Regenerate manifests for the selected plugins, then refresh them in the agent. */
8
5
  export function syncPlugins(opts) {
9
6
  const agent = opts.agent ?? getAgent(opts.target);
@@ -12,16 +9,8 @@ export function syncPlugins(opts) {
12
9
  const enabled = selected.filter((p) => pluginState(p) === "enabled");
13
10
  const disabled = selected.filter((p) => pluginState(p) === "disabled");
14
11
  const actions = disabled.map((p) => ({ name: p.name, adapted: [], synced: false }));
15
- for (const p of enabled) {
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 });
12
+ for (const result of rematerializeInstalled(opts.pluginsDir, enabled)) {
13
+ actions.push({ name: result.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget), synced: false });
25
14
  }
26
15
  if (!agent)
27
16
  return { target: opts.target, actions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-beta.2",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",