@rbbtsn0w/adg 0.4.0-beta.6 → 0.4.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.
package/README.md CHANGED
@@ -64,6 +64,10 @@ adg plugins update --global
64
64
  adg plugins list --global
65
65
  ```
66
66
 
67
+ Machine consumers can use `adg plugins list --json` and
68
+ `adg plugins status --json`; see [docs/cli-json.md](docs/cli-json.md) for the
69
+ stable output and exit-code contract.
70
+
67
71
  `adg` is the only command you invoke — no Node build step beyond the global
68
72
  install. To hack on the CLI itself, see [Developing from source](#developing-from-source).
69
73
 
@@ -247,6 +251,9 @@ record; **agents are projections** of it (`link` / `unlink` toggle one agent;
247
251
  every agent at once — for per-agent control use `unlink`. When something looks
248
252
  off, `status` shows the drift and `sync` repairs it.
249
253
 
254
+ For the local-directory-source flow into Claude's registry/cache, see
255
+ [docs/local-plugin-registration.md](docs/local-plugin-registration.md).
256
+
250
257
  #### On-disk layout
251
258
 
252
259
  Plugins are grouped on disk by the source they came from. Remote installs nest
@@ -1,20 +1,16 @@
1
- import { join } from "node:path";
2
1
  import { isExposed } from "../components.js";
3
2
  import { mcpConfigPath } from "../mcp.js";
4
- /** Projection subdirectory that holds the self-contained agy plugin root. */
5
- export const ANTIGRAVITY_PROJECTION_DIR = ".antigravity-plugin";
6
3
  /**
7
4
  * Generate an Antigravity (`agy`) plugin.json from an ADG manifest.
8
5
  *
9
- * Antigravity reads the same plugin.json MCP pointer shape as the other plugin
10
- * runtimes (`mcpServers`). The agent-side projection still materializes a
11
- * self-contained root for partial installs by copying the referenced file next
12
- * to plugin.json and linking selected component dirs.
6
+ * Antigravity discovers a plugin by scanning a directory for a root `plugin.json`
7
+ * plus sibling component dirs, so the manifest is emitted at the plugin folder
8
+ * root. It reads the same `mcpServers` pointer shape as the other runtimes.
13
9
  */
14
10
  export function toAntigravityManifest(_pluginDir, manifest, selection) {
15
11
  const out = { name: manifest.name };
16
12
  const mcp = mcpConfigPath(manifest);
17
13
  if (mcp && isExposed(selection, "mcp"))
18
14
  out.mcpServers = mcp;
19
- return { defaultPath: join(ANTIGRAVITY_PROJECTION_DIR, "plugin.json"), manifest: out };
15
+ return { defaultPath: "plugin.json", manifest: out };
20
16
  }
@@ -1,70 +1,82 @@
1
- import { cpSync, existsSync, rmSync, statSync, symlinkSync } from "node:fs";
1
+ import { cpSync, existsSync, lstatSync, rmSync, symlinkSync, unlinkSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
- import { dirname, join, relative } from "node:path";
3
+ import { dirname, join, relative, resolve } from "node:path";
4
4
  import { ensureDir, writeJson } from "../fsutil.js";
5
5
  import { readManifest } from "../manifest.js";
6
- import { resolveSkillEntries } from "../skills.js";
7
6
  import { isExposed } from "../components.js";
8
7
  import { installedPluginDir, lockPath } from "../paths.js";
9
8
  import { readLock } from "../lock.js";
10
- import { ANTIGRAVITY_PROJECTION_DIR } from "../adapters/antigravity.js";
11
- import { mcpConfigPath } from "../mcp.js";
12
- import { makeCli, skippedResult } from "./base.js";
9
+ import { toAntigravityManifest } from "../adapters/antigravity.js";
10
+ import { skippedResult } from "./base.js";
13
11
  /**
14
- * Antigravity (`agy`) agent.
12
+ * Antigravity (`agy`) agent — physical-directory model, no CLI.
15
13
  *
16
- * Antigravity discovers a plugin by convention relative to the directory handed
17
- * to `agy plugin install` — `plugin.json` plus sibling `skills/`, `agents/`,
18
- * `commands/`, `hooks/` dirs plus plugin.json path pointers. We therefore
19
- * project a self-contained agy plugin root under `<store>/.antigravity-plugin/`:
20
- * generated `plugin.json` + copied MCP config (when selected) and
21
- * *symlinks* to the real component dirs one level up, so nothing is duplicated
22
- * on disk. agy follows these symlinks; where the platform forbids them (e.g.
23
- * Windows without privilege) we fall back to a copy. We then drive
24
- * `agy plugin install/uninstall` (which owns `~/.gemini/antigravity-cli`).
14
+ * Antigravity discovers plugins by *scanning* designated directories; the
15
+ * directory itself carries the scope (the provenance), and there is no agy lock
16
+ * or marketplace:
17
+ * - Workspace: `<ws>/.agents/plugins/<name>` (ADG's own project store)
18
+ * - Global: `~/.gemini/config/plugins/<name>`
19
+ * A plugin folder is recognized by a root `plugin.json` plus sibling component
20
+ * dirs (`skills/ agents/ commands/ hooks/`).
21
+ *
22
+ * We therefore drive Antigravity purely by placing files, never by a CLI:
23
+ * - Project scope is *in place*: ADG's store folder already sits in the
24
+ * workspace scan dir, so we just write the agy `plugin.json` at its root.
25
+ * - Global scope (and remote-nested project plugins, which live two levels
26
+ * under the scan dir) get an exposure symlink `<scanDir>/<name>` -> the real
27
+ * store folder, with a copy fallback where symlinks are unavailable.
28
+ *
29
+ * Provenance is owned by ADG: `listInstalled` answers from the queried scope's
30
+ * own lock intersected with that scope's scan dir — never from the agent — so a
31
+ * project query can't surface globally-installed plugins (and vice versa).
32
+ *
33
+ * Tradeoff (in-place): partial installs are best-effort, and a `skills` value is
34
+ * read from the single convention dir `<plugin>/skills/`. `plugin.json` reflects
35
+ * the selection's MCP pointer, but agy discovers component dirs by convention
36
+ * name, so the auto-scan model does NOT honor: dir-level pruning (a narrowed skill
37
+ * subset, a dropped category), nor a multi-root skills path-list (e.g.
38
+ * `["./skills/one","./extra/two"]` — only the `skills/` root is exposed; `extra/`
39
+ * is not). These would require a separate self-contained projection dir, which the
40
+ * in-place model deliberately avoids; the full canonical dirs are read in place.
25
41
  */
26
42
  const ID = "antigravity";
43
+ /** The manifest filename Antigravity's auto-scan looks for at a plugin folder root. */
44
+ const ANTIGRAVITY_MANIFEST = "plugin.json";
27
45
  /**
28
- * Single-directory component fields: agy reads each as a sibling dir named by
29
- * convention. `skills` is handled separately because it can be a path-list and
30
- * supports per-skill subsetting.
46
+ * Component fields agy reads as a sibling dir named by convention. We ensure each
47
+ * resolves under its convention name, aliasing when the manifest declares a
48
+ * non-convention source dir.
31
49
  */
32
- const DIR_FIELDS = ["agents", "commands", "hooks"];
50
+ const CONVENTION_FIELDS = ["skills", "agents", "commands", "hooks"];
33
51
  function geminiHome(env) {
34
52
  return env.GEMINI_HOME?.trim() || join(homedir(), ".gemini");
35
53
  }
36
54
  /**
37
- * agy's config/store home: `<GEMINI_HOME>/antigravity-cli` (defaulting to
38
- * `~/.gemini/antigravity-cli`). Exported so the resolver itself is testable
39
- * without depending on the host filesystem state.
55
+ * Antigravity-specific markers under the Gemini home. `~/.gemini` itself is
56
+ * shared with the plain Gemini CLI, so detection keys on an `antigravity*` dir to
57
+ * avoid falsely registering a Gemini-CLI-only user (and writing into their home).
40
58
  */
41
- export function antigravityHome(env = process.env) {
42
- return join(geminiHome(env), "antigravity-cli");
59
+ const ANTIGRAVITY_MARKERS = ["antigravity", "antigravity-cli", "antigravity-ide"];
60
+ function antigravityPresent(env) {
61
+ const home = geminiHome(env);
62
+ return ANTIGRAVITY_MARKERS.some((marker) => existsSync(join(home, marker)));
43
63
  }
44
- // `--help` is rejected by `agy plugin install` (it parses it as a target), so
45
- // probe the plugin command group with its own `help` subcommand instead.
46
- // `echoStderr` surfaces the CLI's own diagnostics on failure.
47
- const { available, run } = makeCli("agy", { probeArgs: ["plugin", "help"], echoStderr: true });
48
- /** Resolve a plugin's on-disk store directory and selection from the lock's provenance. */
49
- function pluginStore(pluginsDir, name) {
50
- const entry = readLock(lockPath(pluginsDir)).plugins[name];
51
- if (!entry)
52
- return undefined;
53
- const dir = installedPluginDir(pluginsDir, name, entry.origin);
54
- return existsSync(dir) ? { dir, selection: entry.selection } : undefined;
64
+ /**
65
+ * Antigravity's global plugin scan dir: `<GEMINI_HOME>/config/plugins`
66
+ * (defaulting to `~/.gemini/config/plugins`). Exported so the resolver is
67
+ * testable without host filesystem state.
68
+ */
69
+ export function antigravityGlobalPluginsDir(env = process.env) {
70
+ return join(geminiHome(env), "config", "plugins");
55
71
  }
56
- /** First on-disk top segment of a declared component path (e.g. "./agents/" -> "agents"). */
57
- function componentSegment(value) {
58
- const first = Array.isArray(value) ? value[0] : value;
59
- if (typeof first !== "string")
60
- return undefined;
61
- const seg = first.replace(/^\.?[/\\]/, "").split(/[/\\]/)[0];
62
- return seg || undefined;
72
+ /** The scan dir Antigravity reads for a given scope: global home, or the project store itself. */
73
+ function antigravityScanDir(ctx, env = process.env) {
74
+ return ctx.scope === "user" ? antigravityGlobalPluginsDir(env) : ctx.pluginsDir;
63
75
  }
64
76
  /**
65
- * Symlink `linkPath` at `absTarget` (target stored relative so the projection
66
- * survives the whole plugin dir being moved), copying instead where symlinks are
67
- * unavailable (e.g. Windows without privilege). Idempotent.
77
+ * Symlink `linkPath` at `absTarget` (target stored relative so the link survives
78
+ * a move), copying instead where symlinks are unavailable (e.g. Windows without
79
+ * privilege). Idempotent.
68
80
  */
69
81
  function linkOrCopy(linkPath, absTarget) {
70
82
  rmSync(linkPath, { recursive: true, force: true });
@@ -76,115 +88,146 @@ function linkOrCopy(linkPath, absTarget) {
76
88
  cpSync(absTarget, linkPath, { recursive: true });
77
89
  }
78
90
  }
79
- /** Link a file with a relative symlink, copying instead when symlinks fail. */
80
- function linkFileOrCopy(linkPath, absTarget) {
81
- rmSync(linkPath, { force: true });
82
- ensureDir(dirname(linkPath));
91
+ /**
92
+ * Remove `path` when it is a symlink — including a *broken* one. `lstatSync` (in a
93
+ * `try`) is used rather than `existsSync`, which follows the link and reports false
94
+ * for a dangling alias, leaving it on disk. Removal uses `unlinkSync`, not
95
+ * `rmSync(..., { force: true })`: on Node < 24 the latter follows the link, hits
96
+ * `ENOENT`, and the `force` flag then swallows it without unlinking the symlink.
97
+ * A real file/dir is left untouched.
98
+ */
99
+ function rmIfSymlink(path) {
100
+ let st;
83
101
  try {
84
- symlinkSync(relative(dirname(linkPath), absTarget), linkPath, "file");
102
+ st = lstatSync(path);
85
103
  }
86
104
  catch {
87
- cpSync(absTarget, linkPath);
105
+ return; // absent
88
106
  }
107
+ if (st.isSymbolicLink())
108
+ unlinkSync(path);
109
+ }
110
+ /** First on-disk top segment of a declared component path (e.g. "./agents/" -> "agents"). */
111
+ function componentSegment(value) {
112
+ const first = Array.isArray(value) ? value[0] : value;
113
+ if (typeof first !== "string")
114
+ return undefined;
115
+ const seg = first.replace(/^\.?[/\\]/, "").split(/[/\\]/)[0];
116
+ return seg || undefined;
89
117
  }
90
118
  /**
91
- * Build the agy-native projection under `<dir>/.antigravity-plugin/`: a
92
- * `plugin.json`, an MCP config file copied verbatim from the manifest's
93
- * `mcpServers` pointer when present, an agy-conventional `mcp_config.json` link
94
- * to that file, and relative symlinks (copy fallback) to the declared component
95
- * dirs named for agy's convention.
96
- *
97
- * An optional `selection` (the plugin's partial install) narrows what is
98
- * projected: component categories outside it are dropped, and `skills` is pinned
99
- * to the selected subset. `skills` is also projected per-skill into a real
100
- * `skills/` dir, so a path-list spanning multiple roots is fully honored rather
101
- * than collapsing to its first root. Idempotent; safe to re-run.
119
+ * Make `dir` a valid agy plugin root in place: write the agy `plugin.json` at the
120
+ * root and ensure each exposed component resolves under its convention name
121
+ * (aliasing with a symlink/copy only when the manifest's source dir name differs).
122
+ * Idempotent; safe to re-run. Never deletes a real (non-symlink) component dir.
102
123
  */
103
- export function writeAntigravityProjection(dir, selection) {
124
+ export function ensureAntigravityRoot(dir, selection) {
104
125
  const manifest = readManifest(dir);
105
- const stage = join(dir, ANTIGRAVITY_PROJECTION_DIR);
106
- ensureDir(stage);
107
- rmSync(join(stage, "mcp_config.json"), { force: true });
108
- const mcp = mcpConfigPath(manifest);
109
- const pluginJson = { name: manifest.name };
110
- if (mcp && isExposed(selection, "mcp")) {
111
- pluginJson.mcpServers = mcp;
112
- const mcpFile = join(dir, mcp);
113
- const projectedMcp = join(stage, mcp);
114
- rmSync(projectedMcp, { force: true });
115
- ensureDir(dirname(projectedMcp));
116
- // Copy verbatim — preserving formatting and avoiding a parse/re-serialize round-trip.
117
- if (existsSync(mcpFile)) {
118
- cpSync(mcpFile, projectedMcp);
119
- linkFileOrCopy(join(stage, "mcp_config.json"), projectedMcp);
120
- }
121
- }
122
- else {
123
- rmSync(join(stage, mcp || ".mcp.json"), { force: true });
124
- }
125
- writeJson(join(stage, "plugin.json"), pluginJson);
126
- const skillsDir = join(stage, "skills");
127
- rmSync(skillsDir, { recursive: true, force: true });
128
- if (manifest.skills !== undefined && isExposed(selection, "skills")) {
129
- const pick = selection?.skills;
130
- for (const e of resolveSkillEntries(dir, manifest)) {
131
- if (pick && !pick.includes(e.name))
132
- continue;
133
- if (!e.skillMd)
134
- continue;
135
- const srcSkillDir = dirname(e.skillMd);
136
- if (existsSync(srcSkillDir) && statSync(srcSkillDir).isDirectory()) {
137
- linkOrCopy(join(skillsDir, e.name), srcSkillDir);
138
- }
139
- }
140
- }
141
- for (const field of DIR_FIELDS) {
142
- const link = join(stage, field);
143
- rmSync(link, { recursive: true, force: true });
126
+ const { manifest: pluginJson } = toAntigravityManifest(dir, manifest, selection);
127
+ writeJson(join(dir, ANTIGRAVITY_MANIFEST), pluginJson);
128
+ for (const field of CONVENTION_FIELDS) {
129
+ const link = join(dir, field);
130
+ rmIfSymlink(link); // clear a stale alias (incl. a broken one); a real source dir is left untouched
144
131
  if (!isExposed(selection, field))
145
132
  continue;
146
133
  const seg = componentSegment(manifest[field]);
147
- if (!seg)
148
- continue;
149
- const srcDir = join(dir, seg);
150
- // agy reads the component by its convention name (`field`); point that at
151
- // the real source dir so a non-conventional source name still resolves.
152
- if (existsSync(srcDir))
153
- linkOrCopy(link, srcDir);
134
+ if (!seg || seg === field)
135
+ continue; // absent, or already convention-named in place
136
+ const src = join(dir, seg);
137
+ if (existsSync(src))
138
+ linkOrCopy(link, src);
154
139
  }
155
140
  }
141
+ /**
142
+ * Expose `realDir` to Antigravity at `<scanDir>/<name>`. No-op when the real dir
143
+ * already *is* that path (project, flat). Returns false without touching disk when
144
+ * the target is a real directory ADG didn't create (no agy manifest) — we never
145
+ * clobber a plugin slot we don't own. Replacing our own alias or a prior
146
+ * projection (which carries the manifest) is fine.
147
+ */
148
+ function exposeAt(scanDir, name, realDir) {
149
+ const target = join(scanDir, name);
150
+ if (resolve(target) === resolve(realDir))
151
+ return true; // project, flat: already in the scan dir
152
+ let existing;
153
+ try {
154
+ existing = lstatSync(target);
155
+ }
156
+ catch {
157
+ existing = undefined; // absent — safe to create
158
+ }
159
+ if (existing?.isDirectory() && !existing.isSymbolicLink() && !existsSync(join(target, ANTIGRAVITY_MANIFEST))) {
160
+ console.error(`antigravity: skipping "${name}" — ${target} already exists and is not ADG-managed. ` +
161
+ `Remove it to let ADG manage this plugin.`);
162
+ return false;
163
+ }
164
+ linkOrCopy(target, realDir);
165
+ return true;
166
+ }
167
+ /**
168
+ * Tear down a plugin's projection. When the real store dir is known, drop its agy
169
+ * manifest and any convention alias links (in-place cleanup). Remove the external
170
+ * exposure entry only when it is our own alias (a symlink) or a copy-fallback dir
171
+ * that carries the manifest — never recursively delete an unattributable dir, and
172
+ * never the in-place store folder itself.
173
+ */
174
+ function removeProjection(scanDir, name, realDir) {
175
+ const target = join(scanDir, name);
176
+ let st;
177
+ try {
178
+ st = lstatSync(target);
179
+ }
180
+ catch {
181
+ st = undefined;
182
+ }
183
+ if (realDir) {
184
+ // The real store dir is known: drop the in-place manifest + convention aliases.
185
+ rmSync(join(realDir, ANTIGRAVITY_MANIFEST), { force: true });
186
+ for (const field of CONVENTION_FIELDS)
187
+ rmIfSymlink(join(realDir, field));
188
+ if (resolve(target) === resolve(realDir))
189
+ return; // in-place: target IS the store folder — never delete it
190
+ // Aliased exposure we created (symlink, or a copy-fallback dir): safe to drop wholesale.
191
+ if (st)
192
+ rmSync(target, { recursive: true, force: true });
193
+ return;
194
+ }
195
+ // Real dir unknown (e.g. the store entry is already gone): we cannot prove a real
196
+ // directory at `target` is our exposure vs. a store/foreign folder, so only ever
197
+ // remove a symlink alias — never recursively delete an unattributable directory.
198
+ if (st?.isSymbolicLink())
199
+ rmSync(target, { force: true });
200
+ }
201
+ /** Resolve a plugin's on-disk dir and selection from the lock, or undefined when not installed. */
202
+ function pluginRealDir(pluginsDir, name) {
203
+ const entry = readLock(lockPath(pluginsDir)).plugins[name];
204
+ if (!entry)
205
+ return undefined;
206
+ const dir = installedPluginDir(pluginsDir, name, entry.origin);
207
+ return existsSync(dir) ? { dir, selection: entry.selection } : undefined;
208
+ }
156
209
  export const antigravityAgent = {
157
210
  id: ID,
158
211
  displayName: "Antigravity",
159
212
  adaptTarget: "antigravity",
160
- detect: (env = process.env) => existsSync(antigravityHome(env)),
161
- available,
213
+ // The directory model needs no CLI: an `antigravity*` marker under the Gemini
214
+ // home is the signal that Antigravity is installed and its scan dirs are real.
215
+ detect: (env = process.env) => antigravityPresent(env),
216
+ available: () => antigravityPresent(process.env),
162
217
  activate(ctx) {
163
- if (!available())
218
+ if (!antigravityAgent.detect())
164
219
  return skippedResult(ID);
165
- // Query agy once up front so the pre-install uninstall below is issued only
166
- // for plugins that are actually present (a brand-new plugin has no residual
167
- // to clear). `undefined` (couldn't enumerate) falls back to always
168
- // uninstalling, preserving the clean-replace guarantee.
169
- const installed = antigravityInstalled();
220
+ const scanDir = antigravityScanDir(ctx);
221
+ ensureDir(scanDir);
170
222
  const affected = [];
171
223
  for (const p of ctx.plugins) {
172
- // Isolate each plugin: a malformed manifest or a filesystem error must not
173
- // abort activation of the remaining (valid) plugins.
224
+ // Isolate each plugin: a malformed manifest or fs error must not abort the rest.
174
225
  try {
175
- const store = pluginStore(ctx.pluginsDir, p);
176
- if (!store)
226
+ const real = pluginRealDir(ctx.pluginsDir, p);
227
+ if (!real)
177
228
  continue;
178
- writeAntigravityProjection(store.dir, store.selection);
179
- // `agy plugin install` *merges* into an existing `<store>/plugins/<name>`
180
- // rather than replacing it, so components dropped since the last sync (a
181
- // narrowed selection, or a skill removed upstream) would linger as
182
- // residual data. Uninstall an existing copy first to force a clean
183
- // re-import; skip it for a not-yet-installed plugin (nothing to clear).
184
- if (installed === undefined || installed.includes(p)) {
185
- run(["plugin", "uninstall", p]);
186
- }
187
- if (run(["plugin", "install", join(store.dir, ANTIGRAVITY_PROJECTION_DIR)]).ok)
229
+ ensureAntigravityRoot(real.dir, real.selection);
230
+ if (exposeAt(scanDir, p, real.dir))
188
231
  affected.push(p);
189
232
  }
190
233
  catch (err) {
@@ -194,55 +237,34 @@ export const antigravityAgent = {
194
237
  return { agent: ID, affected, skipped: false };
195
238
  },
196
239
  deactivate(ctx) {
197
- if (!available())
240
+ if (!antigravityAgent.detect())
198
241
  return skippedResult(ID);
242
+ const scanDir = antigravityScanDir(ctx);
243
+ const lock = readLock(lockPath(ctx.pluginsDir)).plugins;
199
244
  const affected = [];
200
245
  for (const p of ctx.plugins) {
201
- if (run(["plugin", "uninstall", p]).ok)
202
- affected.push(p);
246
+ const entry = lock[p];
247
+ const realDir = entry ? installedPluginDir(ctx.pluginsDir, p, entry.origin) : undefined;
248
+ removeProjection(scanDir, p, realDir);
249
+ affected.push(p);
203
250
  }
204
251
  return { agent: ID, affected, skipped: false };
205
252
  },
206
- // Re-running activate is the refresh: it uninstalls then re-imports the source
207
- // dir, so a shrunk component set replaces the stale copy instead of merging.
253
+ // Re-running activate is the refresh: it rewrites the manifest and re-exposes
254
+ // the store dir, so a changed plugin replaces its stale projection in place.
208
255
  refresh(ctx) {
209
256
  return antigravityAgent.activate(ctx);
210
257
  },
211
- // `agy plugin list` emits JSON (`{ imports: [{ name }] }`). agy has no
212
- // marketplace concept, so this returns *every* imported plugin — including
213
- // ones imported outside ADG; the caller treats agy-only names as "not managed
214
- // here" rather than asserting they are ADG orphans.
215
- // `available()` (stdio-ignored probe) gates the query, so an absent CLI is a
216
- // quiet `undefined` ("unknown") rather than echoing a spawn error to stderr.
217
- listInstalled: () => antigravityInstalled(),
258
+ // Provenance is ADG's, not the agent's: enumerate the queried scope's own lock
259
+ // and keep only plugins Antigravity actually sees in that scope's scan dir (a
260
+ // root `plugin.json`, reached directly or via the exposure link). A project
261
+ // query therefore can't surface globally-installed plugins. `undefined` only
262
+ // when Antigravity isn't present at all ("unknown"), never confused with empty.
263
+ listInstalled(ctx) {
264
+ if (!antigravityAgent.detect())
265
+ return undefined;
266
+ const scanDir = antigravityScanDir(ctx);
267
+ const names = Object.keys(readLock(lockPath(ctx.pluginsDir)).plugins);
268
+ return names.filter((name) => existsSync(join(scanDir, name, ANTIGRAVITY_MANIFEST)));
269
+ },
218
270
  };
219
- /**
220
- * The plugin names agy currently has imported, or `undefined` when the CLI is
221
- * absent or its output can't be parsed. Shared by `listInstalled` and by
222
- * `activate` (to skip the pre-install uninstall for brand-new plugins).
223
- */
224
- function antigravityInstalled() {
225
- if (!available())
226
- return undefined;
227
- const res = run(["plugin", "list"]);
228
- if (!res.ok)
229
- return undefined;
230
- return parseAntigravityPluginList(res.out);
231
- }
232
- /**
233
- * Parse `agy plugin list` JSON (`{ imports: [{ name }] }`) into deduped plugin
234
- * names, or `undefined` when the output isn't the expected JSON. Pure (no CLI)
235
- * so it is unit-testable against captured output.
236
- */
237
- export function parseAntigravityPluginList(out) {
238
- try {
239
- const parsed = JSON.parse(out);
240
- const names = (parsed.imports ?? [])
241
- .map((i) => i.name)
242
- .filter((n) => typeof n === "string");
243
- return [...new Set(names)];
244
- }
245
- catch {
246
- return undefined; // unparseable output — report "unknown", don't guess
247
- }
248
- }
@@ -1,9 +1,10 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { existsSync } from "node:fs";
2
3
  import { homedir } from "node:os";
3
- import { join, relative } from "node:path";
4
+ import { join, relative, resolve } from "node:path";
4
5
  import { toPosix, writeJson } from "../fsutil.js";
5
6
  import { readManifest } from "../manifest.js";
6
- import { installedPluginDir, lockPath } from "../paths.js";
7
+ import { globalPluginsDir, installedPluginDir, lockPath } from "../paths.js";
7
8
  import { readLock } from "../lock.js";
8
9
  import { makeCli, skippedResult } from "./base.js";
9
10
  /**
@@ -19,11 +20,24 @@ function claudeHome(env) {
19
20
  return env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), ".claude");
20
21
  }
21
22
  const { available, run } = makeCli("claude", { probeArgs: ["plugin", "--help"] });
23
+ /**
24
+ * Claude's marketplace registry is keyed only by marketplace name. Keep the
25
+ * historical global marketplace name stable, but give project/explicit stores a
26
+ * store-scoped name so a project install never updates or queries a stale global
27
+ * `adg` marketplace.
28
+ */
29
+ export function claudeMarketplaceName(pluginsDir) {
30
+ const normalized = resolve(pluginsDir);
31
+ if (normalized === resolve(globalPluginsDir()))
32
+ return MARKETPLACE;
33
+ const hash = createHash("sha1").update(toPosix(normalized)).digest("hex").slice(0, 8);
34
+ return `${MARKETPLACE}-${hash}`;
35
+ }
22
36
  /**
23
37
  * Write a Claude marketplace catalog listing every installed plugin, each
24
38
  * `source` pointing at its on-disk directory (relative to the catalog).
25
39
  */
26
- export function writeClaudeCatalog(pluginsDir, name = MARKETPLACE) {
40
+ export function writeClaudeCatalog(pluginsDir, name = claudeMarketplaceName(pluginsDir)) {
27
41
  const lock = readLock(lockPath(pluginsDir));
28
42
  const plugins = [];
29
43
  for (const [pname, entry] of Object.entries(lock.plugins)) {
@@ -61,11 +75,9 @@ export function writeClaudeCatalog(pluginsDir, name = MARKETPLACE) {
61
75
  return { file, name };
62
76
  }
63
77
  /** Register the ADG store as a Claude marketplace (add, or update if present). */
64
- function syncMarketplace(pluginsDir) {
65
- const list = run(["plugin", "marketplace", "list"]);
66
- if (list.ok && list.out.includes(MARKETPLACE))
67
- run(["plugin", "marketplace", "update", MARKETPLACE]);
68
- else
78
+ function syncMarketplace(pluginsDir, name) {
79
+ const update = run(["plugin", "marketplace", "update", name]);
80
+ if (!update.ok)
69
81
  run(["plugin", "marketplace", "add", pluginsDir]);
70
82
  }
71
83
  export const claudeAgent = {
@@ -77,18 +89,18 @@ export const claudeAgent = {
77
89
  activate(ctx) {
78
90
  if (!available())
79
91
  return skippedResult("claude");
80
- writeClaudeCatalog(ctx.pluginsDir);
81
- syncMarketplace(ctx.pluginsDir);
92
+ const { name: marketplace } = writeClaudeCatalog(ctx.pluginsDir);
93
+ syncMarketplace(ctx.pluginsDir, marketplace);
82
94
  const affected = [];
83
95
  for (const p of ctx.plugins) {
84
- const r = run(["plugin", "install", `${p}@${MARKETPLACE}`, "--scope", ctx.scope]);
96
+ const r = run(["plugin", "install", `${p}@${marketplace}`, "--scope", ctx.scope]);
85
97
  if (r.ok)
86
98
  affected.push(p);
87
99
  // Surface the CLI's reason instead of silently dropping the plugin — a
88
100
  // rejected manifest (e.g. `hooks: Invalid input`) otherwise looks like a
89
101
  // no-op "missing" with no diagnostic.
90
102
  else
91
- console.error(`claude: failed to install ${p}@${MARKETPLACE}: ${r.out.trim()}`);
103
+ console.error(`claude: failed to install ${p}@${marketplace}: ${r.out.trim()}`);
92
104
  }
93
105
  return { agent: "claude", affected, skipped: false };
94
106
  },
@@ -121,7 +133,7 @@ export const claudeAgent = {
121
133
  const res = run(["plugin", "list"]);
122
134
  if (!res.ok)
123
135
  return undefined;
124
- return parseClaudePluginList(res.out, MARKETPLACE, ctx.scope);
136
+ return parseClaudePluginList(res.out, claudeMarketplaceName(ctx.pluginsDir), ctx.scope);
125
137
  },
126
138
  };
127
139
  /**
@@ -1,23 +1,51 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { existsSync } from "node:fs";
2
3
  import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { marketplacePath } from "../paths.js";
5
- import { readMarketplace } from "../marketplace.js";
4
+ import { join, resolve } from "node:path";
5
+ import { codexMarketplaceRoot, globalPluginsDir, marketplacePath } from "../paths.js";
6
+ import { readMarketplace, writeMarketplace } from "../marketplace.js";
6
7
  import { makeCli, skippedResult } from "./base.js";
7
8
  /**
8
9
  * Codex agent.
9
10
  *
10
- * Codex natively discovers the `.agents/plugins/marketplace.json` ADG writes, so
11
- * plugins show up as *available* — but aren't usable until installed with
12
- * `codex plugin add`. We drive that via the `codex` CLI (which owns ~/.codex).
11
+ * Codex consumes configured marketplace roots. For a project store at
12
+ * `<root>/.agents/plugins`, the configured root is `<root>`; the marketplace file
13
+ * remains at `.agents/plugins/marketplace.json`. Plugins are usable only after
14
+ * `codex plugin add`, so activation registers the root then installs the plugin.
13
15
  */
14
16
  function codexHome(env) {
15
17
  return env.CODEX_HOME?.trim() || join(homedir(), ".codex");
16
18
  }
17
19
  const { available, run } = makeCli("codex", { probeArgs: ["plugin", "--help"] });
18
- /** The marketplace name Codex sees, read from the generated marketplace.json. */
19
- function marketplaceName(pluginsDir) {
20
- return readMarketplace(marketplacePath(pluginsDir), "").name;
20
+ /**
21
+ * Codex's default global marketplace is historically named `plugins`. Project
22
+ * and explicit stores get a store-scoped name to avoid colliding with a global
23
+ * or another project's configured marketplace.
24
+ */
25
+ export function codexMarketplaceName(pluginsDir) {
26
+ const normalized = resolve(pluginsDir);
27
+ if (normalized === resolve(globalPluginsDir()))
28
+ return "plugins";
29
+ const hash = createHash("sha1").update(normalized.split("\\").join("/")).digest("hex").slice(0, 8);
30
+ return `adg-${hash}`;
31
+ }
32
+ /** Ensure the generated Codex marketplace export uses this store's scoped name. */
33
+ export function writeCodexMarketplaceName(pluginsDir) {
34
+ const file = marketplacePath(pluginsDir);
35
+ const marketplace = readMarketplace(file, codexMarketplaceName(pluginsDir));
36
+ const name = codexMarketplaceName(pluginsDir);
37
+ if (marketplace.name !== name) {
38
+ marketplace.name = name;
39
+ writeMarketplace(file, marketplace);
40
+ }
41
+ return name;
42
+ }
43
+ /** Register the local marketplace root Codex expects for this store. */
44
+ function syncMarketplace(pluginsDir, marketplace) {
45
+ const root = codexMarketplaceRoot(pluginsDir);
46
+ const add = run(["plugin", "marketplace", "add", root]);
47
+ if (!add.ok)
48
+ run(["plugin", "marketplace", "upgrade", marketplace]);
21
49
  }
22
50
  export const codexAgent = {
23
51
  id: "codex",
@@ -26,9 +54,10 @@ export const codexAgent = {
26
54
  detect: (env = process.env) => existsSync(codexHome(env)) || existsSync("/etc/codex"),
27
55
  available,
28
56
  activate(ctx) {
29
- const mp = marketplaceName(ctx.pluginsDir);
57
+ const mp = writeCodexMarketplaceName(ctx.pluginsDir);
30
58
  if (!available())
31
59
  return skippedResult("codex");
60
+ syncMarketplace(ctx.pluginsDir, mp);
32
61
  const affected = [];
33
62
  for (const p of ctx.plugins) {
34
63
  if (run(["plugin", "add", `${p}@${mp}`]).ok)
@@ -37,7 +66,7 @@ export const codexAgent = {
37
66
  return { agent: "codex", affected, skipped: false };
38
67
  },
39
68
  deactivate(ctx) {
40
- const mp = marketplaceName(ctx.pluginsDir);
69
+ const mp = writeCodexMarketplaceName(ctx.pluginsDir);
41
70
  if (!available())
42
71
  return skippedResult("codex");
43
72
  const affected = [];
@@ -60,7 +89,7 @@ export const codexAgent = {
60
89
  listInstalled(ctx) {
61
90
  if (!available())
62
91
  return undefined;
63
- const mp = marketplaceName(ctx.pluginsDir);
92
+ const mp = writeCodexMarketplaceName(ctx.pluginsDir);
64
93
  if (!mp)
65
94
  return undefined; // no generated marketplace → can't scope the query
66
95
  const res = run(["plugin", "list"]);
@@ -9,4 +9,5 @@ registerAgent(codexAgent);
9
9
  registerAgent(antigravityAgent);
10
10
  export * from "./types.js";
11
11
  export { registerAgent, getAgent, allAgents, detectedAgents, resolveAgents, agentsForComponents } from "./registry.js";
12
- export { writeClaudeCatalog } from "./claude.js";
12
+ export { claudeMarketplaceName, writeClaudeCatalog } from "./claude.js";
13
+ export { codexMarketplaceName, writeCodexMarketplaceName } from "./codex.js";
@@ -21,6 +21,7 @@ import { globalPluginsDir, projectPluginsDir, lockPath } from "../paths.js";
21
21
  import { getAgent } from "../agents/index.js";
22
22
  import { ui } from "../render/ui.js";
23
23
  import { renderAgentReport, renderMarketplaceList, renderPluginList, renderStatus, renderUpdateReport, } from "../render/plugins.js";
24
+ import { pluginsListJson, pluginsStatusJson, printJson } from "../render/json.js";
24
25
  import { MARKETPLACE_USAGE, PLUGIN_ALIASES, PLUGIN_COMMANDS, SCOPE, fail, parseVerb, renderPluginsHelp, renderVerbHelp, requireSingleTarget, resolveComponents, resolveScopeDir, resolveTargets, scopeOf, wantsHelp, } from "./index.js";
25
26
  /**
26
27
  * Resolve which scope(s) `plugins update` should refresh, mirroring
@@ -227,7 +228,7 @@ async function runPluginsVerb(verb, rest, cmd) {
227
228
  const only = resolveComponents(values.only);
228
229
  const skillsSubset = values.skill && values.skill.length > 0 ? values.skill : undefined;
229
230
  const narrowed = only !== undefined || skillsSubset !== undefined;
230
- const { order, installed, converted, agents } = await addPlugins({
231
+ const { order, installed, removed, converted, agents } = await addPlugins({
231
232
  spec,
232
233
  pluginsDir,
233
234
  ref: values.ref,
@@ -250,6 +251,8 @@ async function runPluginsVerb(verb, rest, cmd) {
250
251
  });
251
252
  for (const name of converted)
252
253
  console.log(ui.meta(`converted native manifest -> .agents/.plugin.json: ${name}`));
254
+ for (const name of removed)
255
+ console.log(`${ui.warn("removed")} ${ui.name(name)}`);
253
256
  if (order.length > 1)
254
257
  console.log(ui.meta(`install order: ${order.join(" -> ")}`));
255
258
  for (const res of installed) {
@@ -402,6 +405,10 @@ async function runPluginsVerb(verb, rest, cmd) {
402
405
  const { values } = parseVerb(verb, cmd.flags, rest);
403
406
  const pluginsDir = resolveScopeDir(values);
404
407
  const plugins = listPlugins(pluginsDir);
408
+ if (values.json) {
409
+ printJson(pluginsListJson(plugins, pluginsDir));
410
+ return;
411
+ }
405
412
  for (const line of renderPluginList(plugins, pluginsDir, { verbose: values.verbose })) {
406
413
  console.log(line);
407
414
  }
@@ -409,8 +416,14 @@ async function runPluginsVerb(verb, rest, cmd) {
409
416
  }
410
417
  case "status": {
411
418
  const { values } = parseVerb(verb, cmd.flags, rest);
412
- const targets = values.target !== undefined ? resolveTargets(values.target) : undefined;
413
- const statuses = pluginStatus({ pluginsDir: resolveScopeDir(values), scope: scopeOf(values), targets });
419
+ const targets = resolveTargets(values.target);
420
+ const pluginsDir = resolveScopeDir(values);
421
+ const scope = scopeOf(values);
422
+ const statuses = pluginStatus({ pluginsDir, scope, targets });
423
+ if (values.json) {
424
+ printJson(pluginsStatusJson(statuses, pluginsDir, scope, targets));
425
+ return;
426
+ }
414
427
  for (const line of renderStatus(statuses))
415
428
  console.log(line);
416
429
  return;
@@ -29,6 +29,7 @@ export const FLAGS = {
29
29
  as: { type: "string", hint: "<name>", help: "plugin name to wrap the skills as" },
30
30
  prefix: { type: "string", hint: "<p>", help: "prefix imported skill names" },
31
31
  verbose: { type: "boolean", short: "v", help: "expand each component to its member names" },
32
+ json: { type: "boolean", help: "print stable machine-readable JSON" },
32
33
  };
33
34
  // Scope flags recur on almost every command; name the group once.
34
35
  export const SCOPE = ["project", "global", "dir"];
@@ -61,13 +62,13 @@ export const PLUGIN_COMMANDS = {
61
62
  summary: "list installed plugins",
62
63
  synopsis: "adg plugins list",
63
64
  blurb: "Each plugin shows a one-line summary of what it contains. Add --verbose\nto expand every component (skills, agents, commands, …) to its member names.",
64
- flags: ["verbose", ...SCOPE],
65
+ flags: ["verbose", "json", ...SCOPE],
65
66
  },
66
67
  status: {
67
68
  summary: "show store-vs-agent drift per runtime",
68
69
  synopsis: "adg plugins status [--target claude|codex|antigravity]",
69
70
  blurb: "Query each agent's CLI live and diff it against the store: what's in\nsync, missing (needs `link`/`sync`), or present in the agent only. Each drift\nrow carries the command that repairs it. Inspects the active scope (--global →\nuser, else project). Name-level only — run `sync` if unsure.",
70
- flags: ["target", ...SCOPE],
71
+ flags: ["target", "json", ...SCOPE],
71
72
  },
72
73
  update: {
73
74
  summary: "pull upstream changes for installed plugins",
@@ -4,6 +4,7 @@ import { basename, join, relative, resolve } from "node:path";
4
4
  import { ADAPTER_TARGETS } from "../adapters/index.js";
5
5
  import { fromNativeManifest } from "../adapters/reverse.js";
6
6
  import { adaptPlugin } from "./adapt.js";
7
+ import { removePlugin } from "./remove.js";
7
8
  import { copyPluginDir, toPosix, writeJson } from "../fsutil.js";
8
9
  import { folderHash } from "../hash.js";
9
10
  import { packageFilter, PROJECTION_DIRS } from "../package.js";
@@ -196,6 +197,53 @@ async function resolveSelections(opts, selected, candidates) {
196
197
  }
197
198
  return selections;
198
199
  }
200
+ /** True when a locked plugin belongs to the same remote checkout currently being reconciled. */
201
+ function sameRemoteSource(entry, parsed, ref) {
202
+ if (parsed.kind === "local")
203
+ return false;
204
+ if (entry.type !== "github")
205
+ return false;
206
+ return entry.repo === parsed.source && entry.ref === ref;
207
+ }
208
+ /**
209
+ * Remove plugins from the same remote source that disappeared from the latest
210
+ * desired set. This handles both source layout changes (one plugin splitting
211
+ * into several differently named plugins) and an explicit narrowed reinstall
212
+ * (`--plugin one` after previously installing `--all`) without leaving stale
213
+ * runtime exports behind.
214
+ */
215
+ function reconcileRemotePlugins(opts, parsed, ref, desired) {
216
+ if (parsed.kind === "local")
217
+ return [];
218
+ // A path/sparse install does not prove the full source shape, so it must not
219
+ // prune sibling plugins from the same repo that were intentionally excluded
220
+ // from the checkout/selection window.
221
+ if (opts.path || opts.sparse?.length)
222
+ return [];
223
+ const lock = readLock(lockPath(opts.pluginsDir));
224
+ const stale = Object.entries(lock.plugins)
225
+ .filter(([name, entry]) => sameRemoteSource(entry.origin, parsed, ref) && !desired.has(name))
226
+ .map(([name]) => name)
227
+ .sort();
228
+ if (stale.length === 0)
229
+ return [];
230
+ // Removing from the ADG store is target-agnostic: once a plugin is no longer
231
+ // desired, every agent that may have cached it must be asked to drop it. The
232
+ // install/refresh pass below still honors `targets`; this broader deactivation
233
+ // only applies to removed store entries.
234
+ const agents = opts.activate ? (opts.deactivationAgents ?? resolveAgents()) : undefined;
235
+ for (const name of stale) {
236
+ removePlugin({
237
+ pluginsDir: opts.pluginsDir,
238
+ name,
239
+ force: true,
240
+ deactivate: opts.activate,
241
+ scope: opts.scope,
242
+ agents,
243
+ });
244
+ }
245
+ return stale;
246
+ }
199
247
  /**
200
248
  * The unified install entrypoint. Treats any source as a marketplace: clone or
201
249
  * read it, discover every plugin (ADG plus reverse-adapted native), choose a
@@ -204,6 +252,7 @@ async function resolveSelections(opts, selected, candidates) {
204
252
  */
205
253
  export async function addPlugins(opts) {
206
254
  const parsed = parseSource(opts.spec);
255
+ const sourceRef = parsed.kind === "local" ? undefined : (opts.ref ?? parsed.ref);
207
256
  let workRoot;
208
257
  let buildOrigin;
209
258
  let cleanup;
@@ -212,15 +261,14 @@ export async function addPlugins(opts) {
212
261
  buildOrigin = (dir) => ({ type: "local", path: `./${toPosix(relative(workRoot, dir)) || basename(dir)}` });
213
262
  }
214
263
  else {
215
- const ref = opts.ref ?? parsed.ref;
216
264
  const tmp = mkdtempSync(join(tmpdir(), "adg-clone-"));
217
265
  cleanup = () => rmSync(tmp, { recursive: true, force: true });
218
- cloneGitHub({ ...parsed, ref }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
266
+ cloneGitHub({ ...parsed, ref: sourceRef }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
219
267
  workRoot = tmp;
220
268
  buildOrigin = (dir) => ({
221
269
  type: "github",
222
270
  repo: parsed.source,
223
- ...(ref ? { ref } : {}),
271
+ ...(sourceRef ? { ref: sourceRef } : {}),
224
272
  path: toPosix(relative(tmp, dir)) || ".",
225
273
  });
226
274
  }
@@ -230,18 +278,20 @@ export async function addPlugins(opts) {
230
278
  throw new Error(`no plugin found in "${opts.spec}" (no .agents/.plugin.json, .claude-plugin or .codex-plugin manifest).`);
231
279
  }
232
280
  const selected = await selectPluginNames(opts, candidates, workRoot, converted);
281
+ // Resolve adapter targets after the plugin choice (lets a CLI agent picker
282
+ // run once we know what's being installed). undefined → installPlugin's all.
283
+ const targets = opts.targets ?? (opts.selectTargets ? await opts.selectTargets() : undefined);
284
+ const available = [...candidates.keys()];
233
285
  if (selected.length === 0) {
234
286
  // Under "skip" (the update path) every requested plugin was deleted
235
287
  // upstream: don't abort — return what the source still offers so the
236
288
  // caller can report the deletions.
237
289
  if (opts.missingPlugins === "skip") {
238
- return { order: [], installed: [], converted, available: [...candidates.keys()] };
290
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(selected));
291
+ return { order: [], installed: [], removed, converted, available };
239
292
  }
240
293
  throw new Error("no plugins selected");
241
294
  }
242
- // Resolve adapter targets after the plugin choice (lets a CLI agent picker
243
- // run once we know what's being installed). undefined → installPlugin's all.
244
- const targets = opts.targets ?? (opts.selectTargets ? await opts.selectTargets() : undefined);
245
295
  // Partial-install selection per user-chosen plugin (auto-deps install full).
246
296
  const selections = await resolveSelections(opts, selected, candidates);
247
297
  // Dependency-first order across every selected plugin (chains deduped).
@@ -256,6 +306,7 @@ export async function addPlugins(opts) {
256
306
  }
257
307
  }
258
308
  }
309
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(order));
259
310
  // Snapshot which plugins already existed before this call mutates the lock,
260
311
  // so the activation step below can tell brand-new installs from updates.
261
312
  const existingPlugins = new Set(Object.keys(readLock(lockPath(opts.pluginsDir)).plugins));
@@ -307,7 +358,7 @@ export async function addPlugins(opts) {
307
358
  return parts.reduce((acc, r) => ({ agent: r.agent, affected: [...acc.affected, ...r.affected], skipped: acc.skipped && r.skipped }), { agent: a.id, affected: [], skipped: true });
308
359
  });
309
360
  }
310
- return { order, installed, converted, available: [...candidates.keys()], agents };
361
+ return { order, installed, removed, converted, available, agents };
311
362
  }
312
363
  finally {
313
364
  cleanup?.();
@@ -120,6 +120,7 @@ export async function updatePlugins(opts) {
120
120
  activate: opts.activate,
121
121
  scope: opts.agentScope,
122
122
  agents: opts.agents,
123
+ deactivationAgents: opts.deactivationAgents,
123
124
  now,
124
125
  });
125
126
  if (agents)
@@ -11,7 +11,12 @@ import { mcpConfigPath } from "./mcp.js";
11
11
  */
12
12
  /** Top-level metadata files always shipped with a plugin, matched case-insensitively. */
13
13
  const META_RE = /^(README|LICEN[CS]E|CHANGELOG|NOTICE)(\..+)?$/i;
14
- /** Generated runtime projections — shipped, but excluded from the content hash. */
14
+ /**
15
+ * Generated runtime projections — shipped, but excluded from the content hash.
16
+ * `.antigravity-plugin` is legacy: Antigravity now projects a root `plugin.json`
17
+ * (auto-scan model), but the entry is kept so any pre-migration projection dir
18
+ * stays hash-ignored rather than registering as spurious drift.
19
+ */
15
20
  export const PROJECTION_DIRS = [".claude-plugin", ".codex-plugin", ".antigravity-plugin"];
16
21
  /** Extract the first path segment of a manifest component value (e.g. "./skills/" -> "skills"). */
17
22
  function topSegment(p) {
package/dist/src/paths.js CHANGED
@@ -51,6 +51,19 @@ export function lockPath(pluginsDir) {
51
51
  export function marketplacePath(pluginsDir) {
52
52
  return join(pluginsDir, MARKETPLACE_FILENAME);
53
53
  }
54
+ /** True when `pluginsDir` has the canonical `<root>/.agents/plugins` shape. */
55
+ export function isCanonicalPluginsDir(pluginsDir) {
56
+ return basename(pluginsDir) === "plugins" && basename(dirname(pluginsDir)) === ".agents";
57
+ }
58
+ /**
59
+ * Resolve the marketplace root Codex expects for a local marketplace source.
60
+ * For `<root>/.agents/plugins`, Codex's source root is `<root>`; for explicit
61
+ * `--dir` stores there is no `.agents/` project root, so the store itself is the
62
+ * root and source paths are relative to it.
63
+ */
64
+ export function codexMarketplaceRoot(pluginsDir) {
65
+ return isCanonicalPluginsDir(pluginsDir) ? dirname(dirname(pluginsDir)) : pluginsDir;
66
+ }
54
67
  /**
55
68
  * Make a filesystem-safe single path segment out of a git URL by replacing the
56
69
  * scheme/host/path separators with `__` and dropping a trailing `.git`.
@@ -117,7 +130,6 @@ export function installedPluginDir(pluginsDir, name, origin) {
117
130
  * leaking parent-directory names from a fixed two-levels-up assumption.
118
131
  */
119
132
  export function marketplaceSourcePath(pluginsDir, dest) {
120
- const isCanonical = basename(pluginsDir) === "plugins" && basename(dirname(pluginsDir)) === ".agents";
121
- const root = isCanonical ? dirname(dirname(pluginsDir)) : pluginsDir;
133
+ const root = codexMarketplaceRoot(pluginsDir);
122
134
  return `./${relative(root, dest).split("\\").join("/")}`;
123
135
  }
@@ -0,0 +1,41 @@
1
+ import { installedPluginDir } from "../paths.js";
2
+ import { agentsForComponents } from "../agents/index.js";
3
+ import { COMPONENT_TYPES } from "../types.js";
4
+ function normalizedContents(contents) {
5
+ return Object.fromEntries(COMPONENT_TYPES.map((type) => [type, contents?.[type] ?? []]));
6
+ }
7
+ function contentCounts(contents) {
8
+ return Object.fromEntries(COMPONENT_TYPES.map((type) => [type, contents[type].length]));
9
+ }
10
+ function contentTypes(contents) {
11
+ return COMPONENT_TYPES.filter((type) => contents[type].length > 0);
12
+ }
13
+ /** Stable machine-readable shape for `adg plugins list --json`. */
14
+ export function pluginsListJson(plugins, pluginsDir) {
15
+ return {
16
+ pluginsDir,
17
+ plugins: plugins.map((plugin) => {
18
+ const contents = normalizedContents(plugin.contents);
19
+ return {
20
+ name: plugin.name,
21
+ version: plugin.version,
22
+ source: plugin.origin,
23
+ folderHash: plugin.folderHash,
24
+ installedAt: plugin.installedAt,
25
+ updatedAt: plugin.updatedAt,
26
+ path: installedPluginDir(pluginsDir, plugin.name, plugin.origin),
27
+ agents: agentsForComponents(contentTypes(contents)).map((agent) => agent.id),
28
+ contents,
29
+ counts: contentCounts(contents),
30
+ partial: plugin.selection !== undefined,
31
+ };
32
+ }),
33
+ };
34
+ }
35
+ /** Stable machine-readable shape for `adg plugins status --json`. */
36
+ export function pluginsStatusJson(statuses, pluginsDir, scope, targets) {
37
+ return { pluginsDir, scope, targets, statuses };
38
+ }
39
+ export function printJson(value) {
40
+ console.log(JSON.stringify(value, null, 2));
41
+ }
@@ -90,7 +90,7 @@ export function renderUpdateReport(result) {
90
90
  else
91
91
  out.push(`${head}: ${ui.meta(`up to date (${r.unchanged.length})`)}`);
92
92
  if (r.deleted.length > 0) {
93
- out.push(ui.warn(` deleted upstream: ${r.deleted.join(", ")} — remove with \`adg plugins remove <name>\``));
93
+ out.push(ui.warn(` removed stale upstream entries: ${r.deleted.join(", ")}`));
94
94
  }
95
95
  if (r.available.length > 0) {
96
96
  out.push(ui.meta(` ${r.available.length} more available (use --all): ${r.available.join(", ")}`));
package/docs/authoring.md CHANGED
@@ -384,8 +384,11 @@ here, at consumption time:
384
384
  └── .claude-plugin/marketplace.json # Claude-facing discovery export
385
385
  ```
386
386
 
387
- The runtimes (Claude, Codex) discover the plugin through their respective
388
- `marketplace.json`; you do not need to configure them by hand.
387
+ After `add`, run `link` or `sync` for the runtimes that should see the plugin.
388
+ Claude keeps its own registry/cache, so local directory-source plugins are not
389
+ fully visible there until ADG links or syncs them. See
390
+ [local-plugin-registration.md](local-plugin-registration.md) for the supported
391
+ integrator flow and the Claude registration boundary.
389
392
 
390
393
  ### Legacy note
391
394
 
@@ -0,0 +1,107 @@
1
+ # CLI JSON Output Contract
2
+
3
+ ADG exposes stable JSON output for read-only plugin commands so external tools
4
+ can integrate over the CLI boundary without scraping human-formatted text.
5
+
6
+ ## General Contract
7
+
8
+ - Supported commands in this contract:
9
+ - `adg plugins list --json`
10
+ - `adg plugins status --json`
11
+ - On success, stdout contains exactly one valid JSON document and no human
12
+ formatting, ANSI color, notes, or tips.
13
+ - On failure, diagnostics are written to stderr and the process exits non-zero.
14
+ JSON error envelopes are not part of this contract.
15
+ - Existing fields documented here are stable. Future releases may add fields;
16
+ callers should ignore unknown fields.
17
+
18
+ ## Exit Codes
19
+
20
+ | Code | Meaning |
21
+ | --- | --- |
22
+ | `0` | Command succeeded; stdout is complete and parseable. |
23
+ | `1` | Invalid arguments, missing required input, validation/runtime error, unknown option, or command failure. |
24
+
25
+ ## `adg plugins list --json`
26
+
27
+ Shape:
28
+
29
+ ```json
30
+ {
31
+ "pluginsDir": "/absolute/path/to/.agents/plugins",
32
+ "plugins": [
33
+ {
34
+ "name": "apple-skills",
35
+ "version": "1.13.2",
36
+ "source": { "type": "github", "repo": "RbBtSn0w/apple-skills" },
37
+ "folderHash": "sha256-...",
38
+ "installedAt": "2026-06-26T00:00:00.000Z",
39
+ "updatedAt": "2026-06-26T00:00:00.000Z",
40
+ "path": "/absolute/path/to/.agents/plugins/RbBtSn0w__apple-skills/apple-skills",
41
+ "agents": ["claude", "codex", "antigravity"],
42
+ "contents": {
43
+ "skills": ["xcode-build-fixer"],
44
+ "agents": [],
45
+ "commands": [],
46
+ "mcp": ["xcode"],
47
+ "hooks": [],
48
+ "apps": []
49
+ },
50
+ "counts": {
51
+ "skills": 1,
52
+ "agents": 0,
53
+ "commands": 0,
54
+ "mcp": 1,
55
+ "hooks": 0,
56
+ "apps": 0
57
+ },
58
+ "partial": false
59
+ }
60
+ ]
61
+ }
62
+ ```
63
+
64
+ Field notes:
65
+
66
+ - `pluginsDir` and each `path` are absolute filesystem paths.
67
+ - `source` is ADG's lock-file provenance object.
68
+ - `agents` contains stable agent ids, not display names.
69
+ - `contents` always includes every component category, using empty arrays when a
70
+ plugin has none of that category.
71
+ - `counts` mirrors `contents` lengths.
72
+ - `partial` is true when the installed plugin has a stored partial-install
73
+ selection.
74
+
75
+ ## `adg plugins status --json`
76
+
77
+ Shape:
78
+
79
+ ```json
80
+ {
81
+ "pluginsDir": "/absolute/path/to/.agents/plugins",
82
+ "scope": "user",
83
+ "targets": ["claude"],
84
+ "statuses": [
85
+ {
86
+ "id": "claude",
87
+ "displayName": "Claude Code",
88
+ "queryable": true,
89
+ "inSync": ["apple-skills"],
90
+ "missing": [],
91
+ "agentOnly": []
92
+ }
93
+ ]
94
+ }
95
+ ```
96
+
97
+ Field notes:
98
+
99
+ - `scope` is the agent install scope: `user` for `--global`, otherwise
100
+ `project`.
101
+ - `targets` contains the resolved target ids requested by `--target`; omitted
102
+ `--target` resolves to all registered targets.
103
+ - `queryable: false` means the agent CLI could not be queried; the arrays are
104
+ then empty because live state is unknown.
105
+ - `inSync`, `missing`, and `agentOnly` are name-level comparisons. Content drift
106
+ is not represented; use `adg plugins sync` when a full runtime refresh is
107
+ required.
@@ -0,0 +1,125 @@
1
+ # Local Plugin Registration
2
+
3
+ This note documents the supported flow for taking a local directory-source
4
+ plugin and making it available in Claude, Codex, and Antigravity through ADG.
5
+ Integrators should rely on these commands instead of editing runtime-private
6
+ registry files.
7
+
8
+ ## End-to-End Flow
9
+
10
+ Given a local plugin directory with a canonical `.agents/.plugin.json`:
11
+
12
+ ```bash
13
+ adg plugins add <plugin-dir> --global
14
+ adg plugins link --target all <plugin-name> --global
15
+ ```
16
+
17
+ Use `sync` instead of `link` when you want a clean runtime refresh:
18
+
19
+ ```bash
20
+ adg plugins sync --target all <plugin-name> --global
21
+ ```
22
+
23
+ Both `link` and `sync` are idempotent and safe to re-run. The recommended
24
+ integrator pattern is:
25
+
26
+ 1. Run `add` to copy the directory-source plugin into ADG's store.
27
+ 2. Run `link` or `sync` for each runtime target that should see the plugin.
28
+ 3. Re-run `sync` to self-heal runtime drift after updates, manual cleanup, or
29
+ suspected stale runtime caches.
30
+
31
+ ## What `add` Writes
32
+
33
+ `adg plugins add <plugin-dir> --global` records the plugin in the global ADG
34
+ store:
35
+
36
+ ```text
37
+ ~/.agents/plugins/
38
+ ├── <plugin-name>/
39
+ │ ├── .agents/.plugin.json
40
+ │ ├── .claude-plugin/plugin.json
41
+ │ ├── .codex-plugin/plugin.json
42
+ │ └── ...
43
+ ├── .plugin-lock.json
44
+ ├── marketplace.json
45
+ └── .claude-plugin/marketplace.json
46
+ ```
47
+
48
+ For a local directory source, the lock provenance uses `source.type: "local"`.
49
+ The generated marketplace entries make the plugin a member of ADG's local
50
+ `adg` marketplace. At this point ADG has stored and adapted the plugin, but a
51
+ runtime that keeps its own registry may still need a `link` or `sync` step.
52
+
53
+ ## Claude Registration
54
+
55
+ Claude Code does not become fully registered just because the plugin exists in
56
+ `~/.agents/plugins`. Register it through ADG:
57
+
58
+ ```bash
59
+ adg plugins link --target claude <plugin-name> --global
60
+ ```
61
+
62
+ or refresh it through ADG:
63
+
64
+ ```bash
65
+ adg plugins sync --target claude <plugin-name> --global
66
+ ```
67
+
68
+ ADG drives Claude's plugin CLI and lets Claude own its private registry. A
69
+ successful registration creates or updates a Claude entry equivalent to:
70
+
71
+ ```json
72
+ {
73
+ "plugins": {
74
+ "<plugin-name>@adg": [
75
+ {
76
+ "scope": "user",
77
+ "installPath": "~/.claude/plugins/cache/adg/<plugin-name>/<version>",
78
+ "version": "<version>",
79
+ "installedAt": "<timestamp>",
80
+ "lastUpdated": "<timestamp>"
81
+ }
82
+ ]
83
+ }
84
+ }
85
+ ```
86
+
87
+ The concrete file is `~/.claude/plugins/installed_plugins.json`, and Claude also
88
+ keeps a cached copy under `~/.claude/plugins/cache/adg/<plugin-name>/<version>`.
89
+ These paths describe the contract boundary for integrators, but they are
90
+ Claude-managed implementation details. Do not hand-edit them; use ADG
91
+ `link`/`sync`/`unlink`.
92
+
93
+ For project installs, the Claude entry uses `scope: "project"` and records a
94
+ `projectPath`. For global installs, the entry uses `scope: "user"`.
95
+
96
+ ## Other Runtimes
97
+
98
+ Codex reads the ADG marketplace export directly from `~/.agents/plugins`, but
99
+ `link --target codex` is still the supported way to regenerate projections and
100
+ ensure the runtime sees the latest store state.
101
+
102
+ Antigravity imports from ADG's generated `.antigravity-plugin/` projection.
103
+ Use `link --target antigravity` for first registration and `sync --target
104
+ antigravity` when you need to clear stale imported components.
105
+
106
+ ## Operational Checks
107
+
108
+ Use these read commands rather than scraping runtime-private files:
109
+
110
+ ```bash
111
+ adg plugins list --global --json
112
+ adg plugins status --target claude --global --json
113
+ ```
114
+
115
+ `status` reports name-level drift:
116
+
117
+ - `inSync`: present in both ADG's store and the runtime.
118
+ - `missing`: present in ADG's store but not linked into the runtime.
119
+ - `agentOnly`: present in the runtime but absent from ADG's store.
120
+
121
+ Repair drift with:
122
+
123
+ ```bash
124
+ adg plugins sync --target <runtime> <plugin-name> --global
125
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.4.0-beta.6",
3
+ "version": "0.4.0-beta.8",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",