@rbbtsn0w/adg 0.11.0 → 0.11.1-dev.pr200.c6ce45e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +131 -73
  2. package/dist/src/agents/antigravity.js +218 -45
  3. package/dist/src/agents/base.js +1 -1
  4. package/dist/src/agents/claude.js +98 -38
  5. package/dist/src/agents/codex.js +32 -42
  6. package/dist/src/cli/core-plugin-handlers.js +3 -3
  7. package/dist/src/cli/handlers.js +171 -39
  8. package/dist/src/cli/index.js +23 -14
  9. package/dist/src/cli/review-update.js +80 -0
  10. package/dist/src/commands/install/default-dsl.js +1 -1
  11. package/dist/src/commands/install/discovery.js +3 -1
  12. package/dist/src/commands/install/install-one.js +41 -31
  13. package/dist/src/commands/install.js +59 -24
  14. package/dist/src/commands/marketplace.js +171 -115
  15. package/dist/src/commands/migrate.js +2 -2
  16. package/dist/src/commands/projection.js +3 -1
  17. package/dist/src/commands/remove.js +10 -0
  18. package/dist/src/commands/review-executables.js +106 -0
  19. package/dist/src/commands/select-agents.js +2 -2
  20. package/dist/src/commands/select-components.js +2 -2
  21. package/dist/src/commands/select-plugins.js +15 -2
  22. package/dist/src/commands/select-scope.js +3 -4
  23. package/dist/src/commands/source-upgrade.js +552 -0
  24. package/dist/src/commands/state.js +3 -1
  25. package/dist/src/commands/status.js +1 -0
  26. package/dist/src/commands/update.js +3 -1
  27. package/dist/src/lock.js +13 -5
  28. package/dist/src/migration-transaction.js +1011 -0
  29. package/dist/src/native-retry.js +329 -0
  30. package/dist/src/process-identity.js +88 -0
  31. package/dist/src/render/plugins.js +149 -27
  32. package/dist/src/render/ui.js +4 -4
  33. package/dist/src/source-history.js +194 -0
  34. package/dist/src/source-intent.js +7 -0
  35. package/dist/src/store-mutex.js +179 -0
  36. package/dist/src/types.js +1 -1
  37. package/dist/src/update-executables.js +193 -0
  38. package/dist/src/upgrade-plan.js +378 -0
  39. package/docs/agents/antigravity.md +5 -0
  40. package/docs/agents-spec.md +10 -0
  41. package/docs/branching-and-release.md +369 -55
  42. package/docs/cli-json.md +9 -0
  43. package/docs/marketing/README.md +211 -0
  44. package/docs/marketing/assets.json +228 -0
  45. package/docs/marketing/capture.json +130 -0
  46. package/docs/marketing/live-readiness.json +353 -0
  47. package/docs/marketing/posts.en.md +94 -0
  48. package/docs/marketing/posts.zh-CN.md +67 -0
  49. package/docs/marketing/production.md +210 -0
  50. package/docs/marketing/source/timeline.json +29 -0
  51. package/docs/marketing/source/workflow-01.svg +16 -0
  52. package/docs/marketing/source/workflow-02.svg +14 -0
  53. package/docs/marketing/source/workflow-03.svg +19 -0
  54. package/docs/marketing/source/workflow-poster.svg +32 -0
  55. package/docs/marketing/transcript.md +48 -0
  56. package/docs/plugin-update-semantics.md +53 -10
  57. package/docs/plugin-upgrade-migrations.md +349 -0
  58. package/package.json +14 -10
  59. package/schemas/plugin-lock.schema.json +78 -1
package/README.md CHANGED
@@ -1,84 +1,76 @@
1
1
  # Agent Directory Group (ADG)
2
2
 
3
- `adg` is one umbrella CLI with **two domains**, each aligned to an existing
4
- ecosystem so there is little new to learn:
3
+ **One source. Multiple agents.**
5
4
 
6
- | Domain | Command | Aligns to |
7
- |--------|---------|-----------|
8
- | **plugins** | `adg plugins <verb>` | the Codex plugin flow (`~/.agents/plugins/marketplace.json`) |
9
- | **skills** | `adg skills <verb>` | [vercel-labs/skills](https://github.com/vercel-labs/skills) — a **vendored fork** (see [vendor/skills](vendor/skills/PROVENANCE.md)) |
5
+ Manage AI agent plugins and skills across **Codex, Claude Code, and
6
+ Antigravity** from one CLI. Add an existing plugin repository, choose the
7
+ runtimes you use, and inspect their state without maintaining a separate
8
+ source inventory for each agent.
10
9
 
11
- For plugins, one universal manifest — `.agents/.plugin.json` — is the source
12
- of truth. Runtime-specific manifests (`.claude-plugin/plugin.json`,
13
- `.codex-plugin/plugin.json`) are *generated* from it, so a plugin is authored
14
- once and adapted to each runtime.
15
-
16
- **Control plane vs export.** ADG's own management lives in the lock
17
- (`.plugin-lock.json`: provenance, `sha256` integrity, dependencies) — that is the
18
- only file ADG treats as authoritative. `marketplace.json` is a thin
19
- **runtime-facing export** kept in the de-facto shape Codex consumes; ADG never
20
- manages plugins through it.
10
+ ![ADG installs a skill from superpowers, connects Claude Code, and checks Codex and Claude registration.](website/assets/workflow.gif)
21
11
 
22
- See [docs/authoring.md](docs/authoring.md) to author a plugin, and
23
- [docs/agents-spec.md](docs/agents-spec.md) for the `.agents/` directory spec.
12
+ Real CLI output, edited into a 10-second replay; waits condensed.
13
+ [Watch with playback controls](website/assets/workflow.mp4) ·
14
+ [Static walkthrough](website/assets/workflow-poster.png) ·
15
+ [Text transcript](docs/marketing/transcript.md) ·
16
+ [Website](https://adg.rbbtsn0w.me/) · [Quick start](#install-and-quick-start)
24
17
 
25
18
  ## Why
26
19
 
27
- - **Skill explosion** — hundreds of skills become unmanageable; ADG groups them
28
- into versioned, discoverable plugins.
29
- - **Runtime fragmentation** — Claude and Codex use different plugin layouts;
30
- ADG generates each from a single source.
31
- - **Reproducibility** — `.plugin-lock.json` records source, version and a content
32
- hash for every installed plugin.
20
+ - **Keep using existing plugins.** Import repositories with Claude or Codex
21
+ manifests, or a standard skills layout, without rewriting their source.
22
+ - **Connect the agents you use.** Manage one source inventory and let ADG
23
+ generate runtime projections and register plugins through native CLIs.
24
+ - **Know what is installed.** Inspect source, version, content hashes, and
25
+ runtime drift before deciding what to update.
33
26
 
34
- ## Default plugin layout
35
-
36
- A repository without a manifest is also installable when it uses the standard
37
- plugin locations: `skills/<name>/SKILL.md`, `hooks/hooks.json`, or `.mcp.json`.
38
- ADG derives a default manifest from the locations that exist. Add
39
- `.agents/.plugin.json` only when a source needs custom component paths or other
40
- plugin metadata; its `skills`, `hooks`, and `mcpServers` fields override only
41
- their matching defaults, while omitted fields inherit valid standard locations.
42
- For structural sources, `--as` sets a stable installed identity and `--only`
43
- limits both the stored payload and runtime exposure. In non-interactive runs,
44
- discovered hooks or MCP require explicit `--only`. Default DSL applies only to
45
- the source root. It is not a monorepo convention: every member of a
46
- multi-plugin repository must declare its own `.agents/.plugin.json` and be
47
- selected with `--plugin` or `--all`.
48
27
 
49
28
  ---
50
29
 
51
30
  # Install and quick start
52
31
 
32
+ Requires Node.js `^22.22.2 || ^24.15.0 || >=26`. CI and release tooling use npm 12.2.2.
33
+
53
34
  Install the CLI once, then run `adg` from anywhere:
54
35
 
55
36
  ```bash
56
37
  npm install -g @rbbtsn0w/adg # stable channel
57
- npm install -g @rbbtsn0w/adg@beta # pre-release channel
58
38
  brew tap RbBtSn0w/tap
59
39
  brew install adg
60
40
  # or run ad-hoc, no install:
61
41
  npx @rbbtsn0w/adg --help
62
42
  ```
63
43
 
64
- Typical end-user flow — pull a marketplace into your global store, then load it
65
- into the runtimes you use:
44
+ Try one skill in a project where you want to use both Codex and Claude Code.
45
+ Install the corresponding agent CLIs first. Every command below names its
46
+ scope explicitly:
66
47
 
67
48
  ```bash
68
- # 1) collect plugins into the global store (~/.agents/plugins)
69
- adg plugins add anthropics/knowledge-work-plugins --ref main --global
70
- # large monorepo? fetch only what you need:
71
- adg plugins add anthropics/knowledge-work-plugins --ref main --sparse engineering --global
49
+ # 1) add just the brainstorming skill and register it with Codex
50
+ adg plugins add obra/superpowers --ref main --only skills \
51
+ --skill brainstorming --target codex --project
72
52
 
73
- # 2) load into the runtimes you use
74
- adg plugins link --target codex --global # Codex discovers ~/.agents/plugins natively
75
- adg plugins link --target claude --global # Claude loads via ~/.claude/skills symlinks
53
+ # 2) connect the same managed plugin to Claude Code
54
+ adg plugins link --target claude --project
76
55
 
77
- # 3) keep it current
78
- adg plugins update --global
79
- adg plugins list --global
56
+ # 3) check the store against each runtime's native plugin state
57
+ adg plugins status --target codex --project
58
+ adg plugins status --target claude --project
80
59
  ```
81
60
 
61
+ The demo uses ADG 1.0.2 and a fixed upstream revision; its
62
+ [capture record](docs/marketing/capture.json) includes exact versions and
63
+ commands. A healthy status confirms plugin registration, not that an LLM has
64
+ executed the skill. Start a new agent session and verify skill discovery before
65
+ relying on it.
66
+
67
+ For plugins shared across projects, use `--global` consistently instead of
68
+ `--project`. To refresh the project store later, run
69
+ `adg plugins update --project`, then inspect status again. Read
70
+ [update and recovery behavior](docs/plugin-upgrade-migrations.md) before
71
+ changing an existing installation. ADG sends anonymous command telemetry by
72
+ default; see [what is collected and how to opt out](#telemetry).
73
+
82
74
  Machine consumers can use `adg plugins list --json` and
83
75
  `adg plugins status --json`; see [docs/cli-json.md](docs/cli-json.md) for the
84
76
  stable output and exit-code contract.
@@ -150,8 +142,8 @@ adg plugins add anthropics/knowledge-work-plugins --ref main --sparse engineerin
150
142
 
151
143
  # each category's .claude-plugin manifest is reverse-adapted on import,
152
144
  # then projected back onto the runtimes you use
153
- adg plugins link --target claude --global # → ~/.claude/skills/<plugin>:<skill>
154
- adg plugins link --target codex --global # native, zero-copy
145
+ adg plugins link --target claude --global # register and install via the native CLI
146
+ adg plugins link --target codex --global # register and install via the native CLI
155
147
  adg plugins list --global
156
148
  ```
157
149
 
@@ -198,6 +190,44 @@ adg plugins add https://github.com/cloudflare/skills --global \
198
190
 
199
191
  These apply the same whether you run a released build or the source tree.
200
192
 
193
+ ## Two command domains
194
+
195
+ | Domain | Command | Aligns to |
196
+ |--------|---------|-----------|
197
+ | **plugins** | `adg plugins <verb>` | native agent plugin flows and an ADG-managed store |
198
+ | **skills** | `adg skills <verb>` | [vercel-labs/skills](https://github.com/vercel-labs/skills) — a **vendored fork** (see [vendor/skills](vendor/skills/PROVENANCE.md)) |
199
+
200
+ For plugins, one universal manifest — `.agents/.plugin.json` — is the source
201
+ of truth for authoring. Runtime-specific manifests
202
+ (`.claude-plugin/plugin.json`, `.codex-plugin/plugin.json`) are generated from
203
+ it, so a plugin is authored once and adapted to each runtime.
204
+
205
+ **Control plane vs export.** ADG's own management lives in the lock
206
+ (`.plugin-lock.json`: provenance, `sha256` integrity, dependencies) — that is the
207
+ only file ADG treats as authoritative for installed state. `marketplace.json`
208
+ is a thin runtime-facing export in the shape Codex consumes; ADG never manages
209
+ plugins through it.
210
+
211
+ See [docs/authoring.md](docs/authoring.md) to author a plugin, and
212
+ [docs/agents-spec.md](docs/agents-spec.md) for the `.agents/` directory spec.
213
+
214
+ ## Default plugin layout
215
+
216
+ A repository without a manifest is also installable when it uses the standard
217
+ plugin locations: `skills/<name>/SKILL.md`, `hooks/hooks.json`, or `.mcp.json`.
218
+ ADG derives a default manifest from the locations that exist. Add
219
+ `.agents/.plugin.json` only when a source needs custom component paths or other
220
+ plugin metadata; its `skills`, `hooks`, and `mcpServers` fields override only
221
+ their matching defaults, while omitted fields inherit valid standard locations.
222
+ For structural sources, `--as` sets a stable installed identity and `--only`
223
+ limits both the stored payload and runtime exposure. In non-interactive runs,
224
+ discovered hooks or MCP require explicit `--only`. Default DSL applies only to
225
+ the source root, not to manifest-free member directories in a monorepo. Each
226
+ member of a multi-plugin repository needs either its own `.agents/.plugin.json`
227
+ or a native manifest (`.claude-plugin/plugin.json` or
228
+ `.codex-plugin/plugin.json`), which ADG reverse-adapts on add. A member with
229
+ neither manifest is not discovered. Select members with `--plugin` or `--all`.
230
+
201
231
  ## Layout
202
232
 
203
233
  ```
@@ -295,7 +325,7 @@ adg plugins import-skills ~/.agents/skills --as asc --prefix asc- --dir plugins
295
325
 
296
326
  # project installed plugins into a runtime's discovery path (store stays the source of truth)
297
327
  adg plugins link --target codex --global # enable in one agent (regenerate .codex-plugin)
298
- adg plugins link --target claude --global # symlink into ~/.claude/skills/
328
+ adg plugins link --target claude --global # register and install via the native CLI
299
329
  adg plugins unlink --target antigravity asc # disable in one agent only (supports agent-only residuals)
300
330
  adg plugins unlink --target all asc # disable in all agents
301
331
  adg plugins disable --global asc # persistently disable everywhere; keep store payload
@@ -326,6 +356,34 @@ discovery manifest/projection is cleared. `update` may refresh a disabled
326
356
  plugin's payload but never activates it. `list` groups enabled and disabled
327
357
  entries, and `status` distinguishes intentional disablement from runtime drift.
328
358
 
359
+ `adg plugins update -g` updates the global store and follows relocated skills
360
+ using ADG's installation history and the current source catalog. Existing
361
+ marketplace `renames` entries handle plugin identity changes. If an older update
362
+ lost selection history, the same command can recover a verified historical
363
+ release and offer restoration candidates whose prior selection is unknown.
364
+ The default keeps the current selection; choosing individual candidates starts
365
+ with none selected. Deferred recovery is recorded separately from exclusions,
366
+ so repeated updates stay quiet. Use the same update command with `--repair` to
367
+ reconsider deferred candidates. Publishers use their ordinary
368
+ manifests and marketplace. Existing pins, disabled state and component selections are
369
+ preserved. An interrupted migration resumes on the next update, including when
370
+ the source is offline.
371
+
372
+ ADG reads existing lock formats 3 through 5 and writes format 6 for recovery
373
+ history. Every ADG installation sharing the same store must support format 6;
374
+ older clients cannot read a store after it has been upgraded.
375
+
376
+ `plugins add <source> --all` subscribes to future plugins from that source.
377
+ Selecting plugins individually maintains that selection. `plugins update --all`
378
+ includes available plugins for this run. Explicit removals remain excluded.
379
+ New hook handlers and MCP services require review before activation.
380
+ Partial skill choices survive plugin splits and merges, including whole-source
381
+ subscriptions and one-time `--all` updates. An unattended update defers unknown
382
+ historical choices, reports outstanding permissions and preserves affected
383
+ contents. Use `--verbose` for details or `--json` for a structured report;
384
+ `deferredRecovery` identifies unknown candidates separately from `notRestored`.
385
+ See the [update and recovery behavior](docs/plugin-upgrade-migrations.md).
386
+
329
387
  For the local-directory-source flow into Claude's registry/cache, see
330
388
  [docs/local-plugin-registration.md](docs/local-plugin-registration.md).
331
389
 
@@ -345,7 +403,7 @@ under a per-marketplace bucket; local installs stay flat:
345
403
  ```
346
404
 
347
405
  The plugin **name stays the unique key** across the lock, `marketplace.json`, and
348
- the Claude symlink bridge — nesting is organizational only, so two sources still
406
+ the runtime projections — nesting is organizational only, so two sources still
349
407
  can't both install a plugin of the same name. `marketplace.json`'s `source.path`
350
408
  tracks the real on-disk path (e.g. `./owner__repo/asc`), keeping the Codex export
351
409
  accurate. Run `adg plugins migrate` once to lift an older flat store into this
@@ -409,31 +467,32 @@ optionally filtered by `--prefix`.
409
467
 
410
468
  ### Runtime mapping (`link`)
411
469
 
412
- A single `.agents/plugins/` source of truth is projected onto each runtime's
413
- private discovery path:
470
+ A single managed store is projected into each runtime's plugin format. Codex
471
+ and Claude Code registration uses their native CLIs, which own their respective
472
+ registries and caches:
414
473
 
415
- | | Codex (OpenAI) | Claude (Anthropic) |
474
+ | | Codex (OpenAI) | Claude Code (Anthropic) |
416
475
  |---|---|---|
417
476
  | plugin manifest | `.codex-plugin/plugin.json` (generated) | `.claude-plugin/plugin.json` (generated) |
418
- | marketplace root | `~/.agents/plugins/` — **native, zero-copy** | `~/.claude/skills/<name>/` — **symlink bridge** |
419
- | skill name | scanned | namespaced `/<plugin>:<skill>` |
420
-
421
- - `link --target codex` only (re)generates `.codex-plugin/plugin.json` —
422
- `.agents/plugins/` is already Codex's marketplace root.
423
- - `link --target claude [--global]` (re)generates `.claude-plugin/plugin.json`
424
- and symlinks each plugin into Claude's skills-dir (`~/.claude/skills/` with
425
- `--global`, else `<cwd>/.claude/skills/`) so it auto-loads as
426
- `<name>@skills-dir`. Symlinks never overwrite a real directory — only a stale
427
- symlink is replaced. This writes under Claude's own `~/.claude/`; the
428
- never-touched `~/.agents/skills/` and `~/.agents/AGENTS.md` are unaffected.
477
+ | marketplace source | ADG-generated catalog and configured source root | ADG-generated `.claude-plugin/marketplace.json` |
478
+ | native activation | `codex plugin marketplace` and `codex plugin add` | `claude plugin marketplace` and `claude plugin install` |
479
+
480
+ `link --target codex` and `link --target claude` generate the matching projection,
481
+ register the catalog, and activate the installed plugins through the native
482
+ CLI. A store-scoped marketplace identity keeps project and explicit stores
483
+ distinct from the global store. Native registries and caches can still live
484
+ outside the project; `--project` is an installation scope, not a security
485
+ sandbox. See [local registration](docs/local-plugin-registration.md) for details
486
+ and the [Antigravity specification](docs/agents/antigravity.md) for its separate
487
+ projection and discovery model.
429
488
 
430
489
  ---
431
490
 
432
491
  # Developing from source
433
492
 
434
493
  For working on the CLI itself, or testing a plugin before release. The CLI runs
435
- directly on **Node ≥ 22.18** via native TypeScript type-stripping — **no build
436
- step**.
494
+ directly on the supported Node.js versions above via native TypeScript
495
+ type-stripping — **no build step**.
437
496
 
438
497
  ```bash
439
498
  git clone <this-repo> && cd adg
@@ -502,8 +561,7 @@ it's sanitized.
502
561
 
503
562
  ## Contributing
504
563
 
505
- All feature/fix pull requests target the **`develop`** integration branch; `main`
506
- is reserved for stable releases. See [CONTRIBUTING.md](CONTRIBUTING.md) and
564
+ All feature/fix pull requests target the **`main`** integration branch. See [CONTRIBUTING.md](CONTRIBUTING.md) and
507
565
  [docs/branching-and-release.md](docs/branching-and-release.md).
508
566
 
509
567
  ## License
@@ -1,6 +1,7 @@
1
- import { existsSync, rmSync } from "node:fs";
1
+ import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync } from "node:fs";
2
+ import { randomUUID } from "node:crypto";
2
3
  import { homedir } from "node:os";
3
- import { join, resolve } from "node:path";
4
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
4
5
  import { ensureDir, writeJson } from "../fsutil.js";
5
6
  import { findManifestFile, readManifest } from "../manifest.js";
6
7
  import { isExposed } from "../components.js";
@@ -27,9 +28,9 @@ export { cleanupAntigravityMcp, pruneStaleAntigravity, reconcileAntigravityActiv
27
28
  * We therefore drive Antigravity purely by placing files, never by a CLI:
28
29
  * - Project scope is *in place*: ADG's store folder already sits in the
29
30
  * workspace scan dir, so we just write the agy `plugin.json` at its root.
30
- * - Global scope (and remote-nested project plugins, which live two levels
31
- * under the scan dir) get an exposure symlink `<scanDir>/<name>` -> the real
32
- * store folder, with a copy fallback where symlinks are unavailable.
31
+ * - Global scope and remote-nested project plugins get a real, ADG-owned
32
+ * directory at `<scanDir>/<name>`. Native agy ignores root symlinks while
33
+ * following component symlinks inside a real root.
33
34
  *
34
35
  * Provenance is owned by ADG: `listInstalled` answers from the queried scope's
35
36
  * own lock intersected with that scope's scan dir — never from the agent — so a
@@ -117,6 +118,7 @@ function componentSegment(value) {
117
118
  * Idempotent; safe to re-run. Never deletes a real (non-symlink) component dir.
118
119
  */
119
120
  export function ensureAntigravityRoot(dir, selection) {
121
+ let complete = true;
120
122
  const manifest = readManifest(dir);
121
123
  const { manifest: pluginJson } = toAntigravityManifest(dir, manifest, selection);
122
124
  writeJson(join(dir, ANTIGRAVITY_MANIFEST), pluginJson);
@@ -135,31 +137,123 @@ export function ensureAntigravityRoot(dir, selection) {
135
137
  ? () => console.error(`antigravity: skipping "${field}" alias for "${dir}" — ${link} already exists and is not ADG-managed. ` +
136
138
  `Remove it to let ADG manage this component.`)
137
139
  : undefined;
138
- reconcile(link, desired, warn);
140
+ const reconciled = reconcile(link, desired, warn);
141
+ if (desired.kind === "linked" && !reconciled)
142
+ complete = false;
139
143
  }
144
+ return complete;
140
145
  }
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 real content `src/projection-slot.ts`'s `observeSlot` can't prove
145
- * ADG owns (no `.adg-owned` marker) — we never clobber a plugin slot we don't own.
146
- * Replacing our own alias or a prior copy-fallback projection (which carries the
147
- * marker) is fine.
148
- *
149
- * Migration note: a copy-fallback exposure created before this module existed
150
- * carries no marker — ownership was inferred from a root `plugin.json` instead,
151
- * which is also just Antigravity's own plugin format and proves nothing on its
152
- * own — so `adoptLegacyExposure` below requires ADG-specific evidence too
153
- * before it plants the marker; see that function's doc for why a bare
154
- * `plugin.json` isn't enough by itself.
146
+ const PROJECTION_STATE = ".adg-antigravity-projection.json";
147
+ function physicalPluginRoot(path) {
148
+ try {
149
+ const stat = lstatSync(path);
150
+ return stat.isDirectory() && !stat.isSymbolicLink() && existsSync(join(path, ANTIGRAVITY_MANIFEST));
151
+ }
152
+ catch (error) {
153
+ if (error.code === "ENOENT")
154
+ return false;
155
+ throw error;
156
+ }
157
+ }
158
+ function ownedExposure(target, name, store, realDir) {
159
+ const observed = observeSlot(target);
160
+ if (observed.kind === "absent")
161
+ return true;
162
+ const storeRoot = existsSync(store) ? realpathSync(store) : resolve(store);
163
+ if (observed.kind === "owned-dir") {
164
+ const stateFile = join(target, PROJECTION_STATE);
165
+ if (!existsSync(stateFile))
166
+ return true; // Legacy copy-fallback marker has no source receipt.
167
+ try {
168
+ const state = JSON.parse(readFileSync(stateFile, "utf8"));
169
+ if (state.version !== 1 || typeof state.source !== "string")
170
+ return false;
171
+ const rel = relative(storeRoot, resolve(state.source));
172
+ return !!rel && !isAbsolute(rel) && !rel.startsWith("..") && basename(state.source) === name;
173
+ }
174
+ catch {
175
+ return false;
176
+ }
177
+ }
178
+ if (observed.kind !== "symlink")
179
+ return false;
180
+ if (realDir && resolve(observed.target) === resolve(realDir))
181
+ return true;
182
+ const linkTarget = existsSync(observed.target) ? realpathSync(observed.target) : resolve(observed.target);
183
+ const rel = relative(storeRoot, linkTarget);
184
+ return !!rel && !isAbsolute(rel) && !rel.startsWith("..") && basename(observed.target) === name;
185
+ }
186
+ /** Build outside the scan directory, then replace only a proven ADG exposure.
187
+ * Native agy skips symlinked plugin roots, but follows component aliases inside
188
+ * real roots. A copied root also keeps native version/manifest discovery local.
155
189
  */
156
- function exposeAt(scanDir, name, realDir) {
190
+ function exposeAt(scanDir, name, realDir, store, entry) {
157
191
  const target = join(scanDir, name);
158
192
  if (resolve(target) === resolve(realDir))
159
- return true; // project, flat: already in the scan dir
193
+ return true;
160
194
  adoptLegacyExposure(target, name);
161
- return reconcile(target, { kind: "linked", target: resolve(realDir) }, () => console.error(`antigravity: skipping "${name}" — ${target} already exists and is not ADG-managed. ` +
162
- `Remove it to let ADG manage this plugin.`));
195
+ if (!ownedExposure(target, name, store, realDir))
196
+ return false;
197
+ const work = join(dirname(scanDir), ".adg-projection-staging", randomUUID());
198
+ const staged = join(work, "next");
199
+ const backup = join(work, "previous");
200
+ mkdirSync(work, { recursive: true, mode: 0o700 });
201
+ try {
202
+ cpSync(realDir, staged, { recursive: true, dereference: false });
203
+ const manifest = readManifest(staged);
204
+ const selection = resolveSelectionDependencies(manifest, entry.selection);
205
+ writeJson(join(staged, ANTIGRAVITY_MANIFEST), toAntigravityManifest(staged, manifest, entry.selection).manifest);
206
+ writeAntigravityMcpConfig(staged, manifest, selection);
207
+ writeAntigravityHooks(staged, manifest, selection, target);
208
+ markOwned(staged);
209
+ writeJson(join(staged, PROJECTION_STATE), {
210
+ version: 1, source: realpathSync(realDir), installedHash: entry.installedHash, selection: entry.selection,
211
+ });
212
+ // Recheck after preparation so a user-owned folder appearing meanwhile stays intact.
213
+ if (!ownedExposure(target, name, store, realDir))
214
+ return false;
215
+ if (observeSlot(target).kind !== "absent")
216
+ renameSync(target, backup);
217
+ try {
218
+ renameSync(staged, target);
219
+ }
220
+ catch (error) {
221
+ if (observeSlot(target).kind === "absent" && existsSync(backup))
222
+ renameSync(backup, target);
223
+ throw error;
224
+ }
225
+ return physicalPluginRoot(target);
226
+ }
227
+ finally {
228
+ rmSync(work, { recursive: true, force: true });
229
+ }
230
+ }
231
+ /** Read-only detection also runs before an unchanged-source revision fast path. */
232
+ export function antigravityProjectionRepairs(ctx) {
233
+ if (!antigravityAgent.detect())
234
+ return [];
235
+ const lock = readLock(lockPath(ctx.pluginsDir));
236
+ const requested = ctx.plugins.length ? new Set(ctx.plugins) : undefined;
237
+ const scan = antigravityScanDir(ctx);
238
+ return Object.entries(lock.plugins).filter(([name, entry]) => {
239
+ if ((requested && !requested.has(name)) || entry.state === "disabled")
240
+ return false;
241
+ const realDir = installedPluginDir(ctx.pluginsDir, name, entry.origin);
242
+ const target = join(scan, name);
243
+ if (!physicalPluginRoot(target))
244
+ return true;
245
+ if (resolve(target) === resolve(realDir))
246
+ return false;
247
+ try {
248
+ if (observeSlot(target).kind !== "owned-dir")
249
+ return true;
250
+ const state = JSON.parse(readFileSync(join(target, PROJECTION_STATE), "utf8"));
251
+ return state.version !== 1 || state.source !== realpathSync(realDir) || state.installedHash !== entry.installedHash;
252
+ }
253
+ catch {
254
+ return true;
255
+ }
256
+ }).map(([name]) => name);
163
257
  }
164
258
  /**
165
259
  * Adopt a copy-fallback exposure created before the projection-slot module
@@ -236,9 +330,31 @@ function pluginRealDir(pluginsDir, name) {
236
330
  const dir = installedPluginDir(pluginsDir, name, entry.origin);
237
331
  if (!existsSync(dir))
238
332
  return undefined;
239
- return { dir, selection: resolveSelectionDependencies(readManifest(dir), entry.selection) };
333
+ return { dir, selection: resolveSelectionDependencies(readManifest(dir), entry.selection), entry };
334
+ }
335
+ /** Compatibility writes are best-effort; native state must still confirm them. */
336
+ function verifyRuntimeState(name, enabled) {
337
+ const home = geminiHome(process.env);
338
+ const configPath = join(home, "config", "config.json");
339
+ if (existsSync(configPath)) {
340
+ const parsed = JSON.parse(readFileSync(configPath, "utf8"));
341
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
342
+ throw new Error("Antigravity configuration cannot be verified");
343
+ const plugins = parsed.plugins;
344
+ if (plugins && (plugins[name]?.enabled ?? false) !== enabled)
345
+ throw new Error("Antigravity enablement write was not confirmed");
346
+ }
347
+ if (!enabled) {
348
+ for (const marker of ANTIGRAVITY_MARKERS) {
349
+ const schemas = join(home, marker, "mcp");
350
+ if (existsSync(schemas) && readdirSync(schemas).some((entry) => entry.startsWith(`${name}_`))) {
351
+ throw new Error("Antigravity runtime tool cleanup was not confirmed");
352
+ }
353
+ }
354
+ }
240
355
  }
241
356
  export const antigravityAgent = {
357
+ retrySafeOperations: ["activate", "refresh", "deactivate"],
242
358
  id: ID,
243
359
  displayName: "Antigravity",
244
360
  adaptTarget: "antigravity",
@@ -246,29 +362,36 @@ export const antigravityAgent = {
246
362
  // home is the signal that Antigravity is installed and its scan dirs are real.
247
363
  detect: (env = process.env) => antigravityPresent(env),
248
364
  available: () => antigravityPresent(process.env),
365
+ needsProjectionRefresh: antigravityProjectionRepairs,
249
366
  activate(ctx) {
250
367
  if (!antigravityAgent.detect())
251
368
  return skippedResult(ID);
252
369
  const scanDir = antigravityScanDir(ctx);
253
370
  ensureDir(scanDir);
254
371
  const affected = [];
372
+ const failures = [];
255
373
  for (const p of ctx.plugins) {
256
374
  // Isolate each plugin: a malformed manifest or fs error must not abort the rest.
257
375
  try {
258
376
  const real = pluginRealDir(ctx.pluginsDir, p);
259
377
  if (!real)
260
- continue;
261
- ensureAntigravityRoot(real.dir, real.selection);
262
- if (exposeAt(scanDir, p, real.dir)) {
378
+ throw new Error("Plugin payload is missing from the store");
379
+ if (!ensureAntigravityRoot(real.dir, real.selection))
380
+ throw new Error("A component alias is occupied by foreign content");
381
+ if (exposeAt(scanDir, p, real.dir, ctx.pluginsDir, real.entry)) {
263
382
  reconcileAntigravityActivation(p);
383
+ verifyRuntimeState(p, true);
264
384
  affected.push(p);
265
385
  }
386
+ else
387
+ throw new Error("Plugin exposure is occupied by foreign content");
266
388
  }
267
389
  catch (err) {
390
+ failures.push({ plugin: p, stage: "install", errorType: "projection_failure", message: err instanceof Error ? err.message : String(err) });
268
391
  console.error(`failed to enable "${p}" in Antigravity:`, err);
269
392
  }
270
393
  }
271
- return { agent: ID, affected, skipped: false };
394
+ return { agent: ID, affected, skipped: false, ...(failures.length ? { failures } : {}) };
272
395
  },
273
396
  deactivate(ctx) {
274
397
  if (!antigravityAgent.detect())
@@ -276,36 +399,86 @@ export const antigravityAgent = {
276
399
  const scanDir = antigravityScanDir(ctx);
277
400
  const lock = readLock(lockPath(ctx.pluginsDir)).plugins;
278
401
  const affected = [];
402
+ const failures = [];
279
403
  for (const p of ctx.plugins) {
280
- const entry = lock[p];
281
- const realDir = entry ? installedPluginDir(ctx.pluginsDir, p, entry.origin) : undefined;
282
- const target = join(scanDir, p);
283
- adoptLegacyExposure(target, p);
284
- if ((!realDir || resolve(target) !== resolve(realDir)) && observeSlot(target).kind === "foreign") {
285
- continue;
404
+ try {
405
+ const entry = lock[p];
406
+ const realDir = entry ? installedPluginDir(ctx.pluginsDir, p, entry.origin) : undefined;
407
+ const target = join(scanDir, p);
408
+ adoptLegacyExposure(target, p);
409
+ if ((!realDir || resolve(target) !== resolve(realDir)) && !ownedExposure(target, p, ctx.pluginsDir, realDir)) {
410
+ throw new Error("Plugin exposure is occupied by foreign content");
411
+ }
412
+ reconcileAntigravityDeactivation(p, scanDir, realDir);
413
+ removeProjection(scanDir, p, realDir);
414
+ verifyRuntimeState(p, false);
415
+ if (existsSync(join(target, ANTIGRAVITY_MANIFEST)))
416
+ throw new Error("Plugin projection is still visible after removal");
417
+ affected.push(p);
418
+ }
419
+ catch (error) {
420
+ failures.push({ plugin: p, stage: "remove", errorType: "projection_failure", message: error instanceof Error ? error.message : String(error) });
286
421
  }
287
- reconcileAntigravityDeactivation(p, scanDir, realDir);
288
- removeProjection(scanDir, p, realDir);
289
- affected.push(p);
290
422
  }
291
- return { agent: ID, affected, skipped: false };
423
+ return { agent: ID, affected, skipped: false, ...(failures.length ? { failures } : {}) };
292
424
  },
293
425
  // Re-running activate is the refresh: it rewrites the manifest and re-exposes
294
426
  // the store dir, so a changed plugin replaces its stale projection in place.
295
427
  refresh(ctx) {
296
- return antigravityAgent.activate(ctx);
428
+ const config = join(geminiHome(process.env), "config", "config.json");
429
+ let preservedDisabled = [];
430
+ try {
431
+ if (!ctx.forceEnable && existsSync(config)) {
432
+ const parsed = JSON.parse(readFileSync(config, "utf8"));
433
+ preservedDisabled = ctx.plugins.filter((name) => parsed?.plugins?.[name]?.enabled === false);
434
+ }
435
+ }
436
+ catch { /* Activation returns an explicit verification failure for malformed configuration. */ }
437
+ const active = ctx.plugins.filter((name) => !preservedDisabled.includes(name));
438
+ const result = active.length ? antigravityAgent.activate({ ...ctx, plugins: active })
439
+ : { agent: ID, affected: [], skipped: !antigravityAgent.detect() };
440
+ return { ...result, ...(preservedDisabled.length ? { preservedDisabled } : {}) };
441
+ },
442
+ inspectPlugins(ctx) {
443
+ if (!antigravityAgent.detect())
444
+ return undefined;
445
+ try {
446
+ const config = join(geminiHome(process.env), "config", "config.json");
447
+ let enabled;
448
+ if (existsSync(config)) {
449
+ const parsed = JSON.parse(readFileSync(config, "utf8"));
450
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
451
+ return { error: "Antigravity enablement cannot be inspected" };
452
+ enabled = parsed.plugins;
453
+ }
454
+ const scan = antigravityScanDir(ctx);
455
+ return ctx.plugins.map((name) => {
456
+ const dir = join(scan, name);
457
+ const entry = readLock(lockPath(ctx.pluginsDir)).plugins[name];
458
+ const real = entry ? installedPluginDir(ctx.pluginsDir, name, entry.origin) : undefined;
459
+ const installed = physicalPluginRoot(dir) && !!real && (resolve(dir) === resolve(real) || ownedExposure(dir, name, ctx.pluginsDir, real));
460
+ return { id: name, name, installed, enabled: installed && (enabled?.[name]?.enabled ?? true),
461
+ ...(installed ? { version: readManifest(dir).version } : {}) };
462
+ });
463
+ }
464
+ catch (error) {
465
+ return { error: error instanceof Error ? error.message : String(error) };
466
+ }
297
467
  },
298
- // Provenance is ADG's, not the agent's: enumerate the queried scope's own lock
299
- // and keep only plugins Antigravity actually sees in that scope's scan dir (a
300
- // root `plugin.json`, reached directly or via the exposure link). A project
468
+ // Native discovery ignores symlinked plugin roots. Scope provenance requires
469
+ // both a real root and a projection belonging to the queried ADG store. A project
301
470
  // query therefore can't surface globally-installed plugins. `undefined` only
302
471
  // when Antigravity isn't present at all ("unknown"), never confused with empty.
303
472
  listInstalled(ctx) {
304
473
  if (!antigravityAgent.detect())
305
474
  return undefined;
306
475
  const scanDir = antigravityScanDir(ctx);
307
- const names = Object.keys(readLock(lockPath(ctx.pluginsDir)).plugins);
308
- return names.filter((name) => existsSync(join(scanDir, name, ANTIGRAVITY_MANIFEST)));
476
+ const entries = readLock(lockPath(ctx.pluginsDir)).plugins;
477
+ return Object.keys(entries).filter((name) => {
478
+ const target = join(scanDir, name);
479
+ const real = installedPluginDir(ctx.pluginsDir, name, entries[name].origin);
480
+ return physicalPluginRoot(target) && (resolve(target) === resolve(real) || ownedExposure(target, name, ctx.pluginsDir, real));
481
+ });
309
482
  },
310
483
  pruneStale() {
311
484
  if (!antigravityAgent.available()) {