@rbbtsn0w/adg 0.5.0-beta.4 → 0.5.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/bin/adg.js +6 -2
- package/dist/src/agents/antigravity.js +4 -1
- package/dist/src/agents/base.js +71 -23
- package/dist/src/agents/claude.js +31 -5
- package/dist/src/cli/handlers.js +45 -3
- package/dist/src/cli/index.js +17 -1
- package/dist/src/commands/cache.js +54 -0
- package/dist/src/commands/install.js +81 -57
- package/dist/src/commands/link.js +13 -9
- package/dist/src/commands/list.js +4 -1
- package/dist/src/commands/marketplace.js +8 -1
- package/dist/src/commands/migrate.js +73 -6
- package/dist/src/commands/projection.js +6 -0
- package/dist/src/commands/remove.js +11 -2
- package/dist/src/commands/select-components.js +2 -1
- package/dist/src/commands/state.js +18 -12
- package/dist/src/commands/sync.js +13 -9
- package/dist/src/commands/update.js +34 -36
- package/dist/src/fsutil.js +15 -2
- package/dist/src/lock.js +10 -6
- package/dist/src/manifest.js +52 -3
- package/dist/src/materialize.js +176 -0
- package/dist/src/paths.js +27 -1
- package/dist/src/render/json.js +2 -1
- package/dist/src/render/plugins.js +1 -1
- package/dist/src/self-update.js +9 -1
- package/dist/src/sources.js +35 -2
- package/dist/src/telemetry.js +9 -0
- package/dist/src/types.js +51 -1
- package/dist/src/update-check.js +3 -1
- package/docs/agents-spec.md +23 -12
- package/docs/cli-json.md +2 -1
- package/package.json +1 -1
- package/schemas/adg-plugin.schema.json +23 -0
- package/schemas/plugin-lock.schema.json +10 -5
package/README.md
CHANGED
|
@@ -165,7 +165,7 @@ asc/
|
|
|
165
165
|
| File | Schema | Role |
|
|
166
166
|
|------|--------|------|
|
|
167
167
|
| `.agents/.plugin.json` | [adg-plugin.schema.json](schemas/adg-plugin.schema.json) (`adg.plugin/v1`) | Universal manifest — source of truth |
|
|
168
|
-
| `.plugin-lock.json` | [plugin-lock.schema.json](schemas/plugin-lock.schema.json) (`version:
|
|
168
|
+
| `.plugin-lock.json` | [plugin-lock.schema.json](schemas/plugin-lock.schema.json) (`version: 3`) | **Control plane** — ADG's authoritative state |
|
|
169
169
|
| `marketplace.json` | [marketplace.schema.json](schemas/marketplace.schema.json) | **Export** — de-facto catalog for Codex |
|
|
170
170
|
|
|
171
171
|
The split is deliberate:
|
|
@@ -243,7 +243,7 @@ adg plugins marketplace sync owner/repo --target all # same, scoped to a who
|
|
|
243
243
|
adg plugins status --target antigravity # live-diff store vs agent (isolates global plugins if project is uninitialized)
|
|
244
244
|
adg plugins update --dir plugins # re-fetch remote sources; rescan local ones in place
|
|
245
245
|
adg plugins list --dir plugins # list locked plugins
|
|
246
|
-
adg plugins migrate --dir plugins # move flat installs
|
|
246
|
+
adg plugins migrate --dir plugins # upgrade legacy locks and move flat installs
|
|
247
247
|
|
|
248
248
|
```
|
|
249
249
|
|
package/dist/bin/adg.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process";
|
|
|
3
3
|
import { readFileSync, realpathSync } from "node:fs";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { selfUpdateCommand, parseSelfUpdateArgs, SELF_UPDATE_USAGE } from "../src/self-update.js";
|
|
6
|
+
import { selfUpdateCommand, parseSelfUpdateArgs, SELF_UPDATE_USAGE, selfUpdateSpawnOptions } from "../src/self-update.js";
|
|
7
7
|
import { checkForUpdate, formatUpdateNotice } from "../src/update-check.js";
|
|
8
8
|
import { ui } from "../src/render/ui.js";
|
|
9
9
|
import { TOP_USAGE, fail } from "../src/cli/index.js";
|
|
@@ -63,7 +63,11 @@ function runSelfUpdate(args) {
|
|
|
63
63
|
return 0;
|
|
64
64
|
}
|
|
65
65
|
const command = selfUpdateCommand(options.beta);
|
|
66
|
-
const r = spawnSync(command.command, command.args,
|
|
66
|
+
const r = spawnSync(command.command, command.args, selfUpdateSpawnOptions());
|
|
67
|
+
if (r.error) {
|
|
68
|
+
console.error(r.error.message);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
67
71
|
return r.status ?? 1;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
@@ -9,6 +9,7 @@ import { readLock } from "../lock.js";
|
|
|
9
9
|
import { toAntigravityManifest, writeAntigravityMcpConfig } from "../adapters/antigravity.js";
|
|
10
10
|
import { writeAntigravityHooks } from "../adapters/antigravity-hooks.js";
|
|
11
11
|
import { skippedResult } from "./base.js";
|
|
12
|
+
import { resolveSelectionDependencies } from "../types.js";
|
|
12
13
|
/**
|
|
13
14
|
* Antigravity (`agy`) agent — physical-directory model, no CLI.
|
|
14
15
|
*
|
|
@@ -212,7 +213,9 @@ function pluginRealDir(pluginsDir, name) {
|
|
|
212
213
|
if (!entry)
|
|
213
214
|
return undefined;
|
|
214
215
|
const dir = installedPluginDir(pluginsDir, name, entry.origin);
|
|
215
|
-
|
|
216
|
+
if (!existsSync(dir))
|
|
217
|
+
return undefined;
|
|
218
|
+
return { dir, selection: resolveSelectionDependencies(readManifest(dir), entry.selection) };
|
|
216
219
|
}
|
|
217
220
|
export const antigravityAgent = {
|
|
218
221
|
id: ID,
|
package/dist/src/agents/base.js
CHANGED
|
@@ -10,6 +10,76 @@ import { getTracer, sanitizeArgs } from "../telemetry.js";
|
|
|
10
10
|
export function skippedResult(agent) {
|
|
11
11
|
return { agent, affected: [], skipped: true };
|
|
12
12
|
}
|
|
13
|
+
function clipText(value, max = 512) {
|
|
14
|
+
return value.length <= max ? value : `${value.slice(0, max - 1)}…`;
|
|
15
|
+
}
|
|
16
|
+
function summarizeFailure(r) {
|
|
17
|
+
const stderr = r.stderr?.trim();
|
|
18
|
+
if (stderr)
|
|
19
|
+
return { stream: "stderr", text: clipText(stderr) };
|
|
20
|
+
const stdout = r.stdout?.trim();
|
|
21
|
+
if (stdout)
|
|
22
|
+
return { stream: "stdout", text: clipText(stdout) };
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
function recordFailureExcerpt(span, summary) {
|
|
26
|
+
if (!summary)
|
|
27
|
+
return;
|
|
28
|
+
span.setAttribute(summary.stream === "stderr" ? "cli.stderr_excerpt" : "cli.stdout_excerpt", summary.text);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Record CLI process telemetry in one place so success/failure semantics stay
|
|
32
|
+
* consistent across every agent wrapper.
|
|
33
|
+
*/
|
|
34
|
+
export function annotateCliRun(span, bin, args, r) {
|
|
35
|
+
if (r.pid !== undefined) {
|
|
36
|
+
span.setAttribute("process.pid", r.pid);
|
|
37
|
+
}
|
|
38
|
+
if (r.status !== null) {
|
|
39
|
+
span.setAttribute("process.exit.code", r.status);
|
|
40
|
+
if (r.status !== 0) {
|
|
41
|
+
const summary = summarizeFailure(r);
|
|
42
|
+
const command = sanitizeArgs([bin, ...args]).join(" ");
|
|
43
|
+
const message = summary ? `${command} exited with status ${r.status}: ${summary.text}` : `${command} exited with status ${r.status}`;
|
|
44
|
+
span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
|
|
45
|
+
span.setAttribute("exception.slug", "cli-nonzero-exit");
|
|
46
|
+
recordFailureExcerpt(span, summary);
|
|
47
|
+
span.recordException(new Error(message));
|
|
48
|
+
span.setStatus({
|
|
49
|
+
code: SpanStatusCode.ERROR,
|
|
50
|
+
message,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (r.signal) {
|
|
56
|
+
const summary = summarizeFailure(r);
|
|
57
|
+
const command = sanitizeArgs([bin, ...args]).join(" ");
|
|
58
|
+
const message = summary ? `${command} terminated by signal ${r.signal}: ${summary.text}` : `${command} terminated by signal ${r.signal}`;
|
|
59
|
+
span.setAttribute("process.exit.code", -1);
|
|
60
|
+
span.setAttribute("process.exit.signal", r.signal);
|
|
61
|
+
span.setAttribute("error.type", `SIGNAL_${r.signal}`);
|
|
62
|
+
span.setAttribute("exception.slug", "cli-signal-exit");
|
|
63
|
+
recordFailureExcerpt(span, summary);
|
|
64
|
+
span.recordException(new Error(message));
|
|
65
|
+
span.setStatus({
|
|
66
|
+
code: SpanStatusCode.ERROR,
|
|
67
|
+
message,
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (r.error) {
|
|
72
|
+
const errCode = r.error.code;
|
|
73
|
+
span.setAttribute("process.exit.code", -1);
|
|
74
|
+
span.setAttribute("error.type", (typeof errCode === "string" || typeof errCode === "number" ? String(errCode) : null) || r.error.name || "SpawnError");
|
|
75
|
+
span.setAttribute("exception.slug", "cli-spawn-failure");
|
|
76
|
+
span.recordException(r.error);
|
|
77
|
+
span.setStatus({
|
|
78
|
+
code: SpanStatusCode.ERROR,
|
|
79
|
+
message: r.error.message,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
13
83
|
/**
|
|
14
84
|
* Build the shared `available()` / `run()` pair for an agent that drives an
|
|
15
85
|
* external plugin CLI. Centralizing the `spawnSync` here keeps error handling,
|
|
@@ -32,29 +102,7 @@ export function makeCli(bin, opts) {
|
|
|
32
102
|
span.setAttribute("process.executable.name", bin);
|
|
33
103
|
span.setAttribute("process.command_args", sanitizeArgs([bin, ...args]));
|
|
34
104
|
const r = spawnSync(bin, args, { encoding: "utf8" });
|
|
35
|
-
|
|
36
|
-
span.setAttribute("process.pid", r.pid);
|
|
37
|
-
}
|
|
38
|
-
if (r.status !== null) {
|
|
39
|
-
span.setAttribute("process.exit.code", r.status);
|
|
40
|
-
if (r.status !== 0) {
|
|
41
|
-
span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
|
|
42
|
-
span.setStatus({
|
|
43
|
-
code: SpanStatusCode.ERROR,
|
|
44
|
-
message: `Command exited with non-zero status ${r.status}`,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else if (r.error) {
|
|
49
|
-
span.setAttribute("process.exit.code", -1);
|
|
50
|
-
const errCode = r.error.code;
|
|
51
|
-
span.setAttribute("error.type", (typeof errCode === "string" || typeof errCode === "number" ? String(errCode) : null) || r.error.name || "SpawnError");
|
|
52
|
-
span.recordException(r.error);
|
|
53
|
-
span.setStatus({
|
|
54
|
-
code: SpanStatusCode.ERROR,
|
|
55
|
-
message: r.error.message,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
105
|
+
annotateCliRun(span, bin, args, r);
|
|
58
106
|
const ok = r.status === 0 && !r.error;
|
|
59
107
|
if (!ok && opts.echoStderr) {
|
|
60
108
|
if (r.error)
|
|
@@ -74,11 +74,37 @@ export function writeClaudeCatalog(pluginsDir, name = claudeMarketplaceName(plug
|
|
|
74
74
|
writeJson(file, catalog);
|
|
75
75
|
return { file, name };
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
/** Parse `claude plugin marketplace list --json` into configured marketplace names. */
|
|
78
|
+
export function parseClaudeMarketplaceList(out) {
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(out);
|
|
81
|
+
if (!Array.isArray(parsed))
|
|
82
|
+
return [];
|
|
83
|
+
return parsed
|
|
84
|
+
.map((entry) => {
|
|
85
|
+
if (typeof entry !== "object" || entry === null)
|
|
86
|
+
return undefined;
|
|
87
|
+
const name = entry["name"];
|
|
88
|
+
return typeof name === "string" ? name : undefined;
|
|
89
|
+
})
|
|
90
|
+
.filter((name) => Boolean(name));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Register or refresh the ADG store as a Claude marketplace, failing open. */
|
|
97
|
+
export function syncMarketplace(pluginsDir, name, runner = run) {
|
|
98
|
+
const listed = runner(["plugin", "marketplace", "list", "--json"]);
|
|
99
|
+
if (listed.ok && parseClaudeMarketplaceList(listed.out).includes(name)) {
|
|
100
|
+
// Claude's marketplace update path can fail on existing installs (for
|
|
101
|
+
// example, merge-conflict-style failures on older CLI builds). When that
|
|
102
|
+
// happens, fall back to re-adding the marketplace so the refresh remains
|
|
103
|
+
// best-effort instead of surfacing a hard EXIT_CODE_1 in the ADG timeline.
|
|
104
|
+
if (runner(["plugin", "marketplace", "update", name]).ok)
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
runner(["plugin", "marketplace", "add", pluginsDir]);
|
|
82
108
|
}
|
|
83
109
|
export const claudeAgent = {
|
|
84
110
|
id: "claude",
|
package/dist/src/cli/handlers.js
CHANGED
|
@@ -12,6 +12,7 @@ import { removePlugin } from "../commands/remove.js";
|
|
|
12
12
|
import { disablePlugins, enablePlugins } from "../commands/state.js";
|
|
13
13
|
import { migrateLayout } from "../commands/migrate.js";
|
|
14
14
|
import { pluginStatus } from "../commands/status.js";
|
|
15
|
+
import { cleanPluginCache, pluginCacheStatus, prunePluginCache } from "../commands/cache.js";
|
|
15
16
|
import { marketplaceList, marketplaceRemove, marketplaceSync, updatePlugins } from "../commands/marketplace.js";
|
|
16
17
|
import { initScaffold } from "../commands/init.js";
|
|
17
18
|
import { confirmFullInstall, selectComponentsInteractive } from "../commands/select-components.js";
|
|
@@ -23,7 +24,7 @@ import { getAgent } from "../agents/index.js";
|
|
|
23
24
|
import { ui } from "../render/ui.js";
|
|
24
25
|
import { renderAgentReport, renderMarketplaceList, renderPluginList, renderStatus, renderUpdateReport, } from "../render/plugins.js";
|
|
25
26
|
import { pluginsListJson, pluginsStatusJson, printJson } from "../render/json.js";
|
|
26
|
-
import { MARKETPLACE_USAGE, PLUGIN_ALIASES, PLUGIN_COMMANDS, SCOPE, fail, parseVerb, renderPluginsHelp, renderVerbHelp, requireSingleTarget, resolveComponents, resolveScopeDir, resolveTargets, scopeOf, wantsHelp, } from "./index.js";
|
|
27
|
+
import { CACHE_USAGE, MARKETPLACE_USAGE, PLUGIN_ALIASES, PLUGIN_COMMANDS, SCOPE, fail, parseVerb, renderPluginsHelp, renderVerbHelp, requireSingleTarget, resolveComponents, resolveScopeDir, resolveTargets, scopeOf, wantsHelp, } from "./index.js";
|
|
27
28
|
/**
|
|
28
29
|
* Resolve which scope(s) `plugins update` should refresh, mirroring
|
|
29
30
|
* `adg skills update`: an explicit --dir is a single ad-hoc location; otherwise
|
|
@@ -158,6 +159,8 @@ export async function runPlugins(rawVerb, rest) {
|
|
|
158
159
|
}
|
|
159
160
|
if (verb === "marketplace")
|
|
160
161
|
return runMarketplace(rest);
|
|
162
|
+
if (verb === "cache")
|
|
163
|
+
return runCache(rest);
|
|
161
164
|
return runPluginsVerb(verb, rest, cmd);
|
|
162
165
|
}
|
|
163
166
|
async function runPluginsVerb(verb, rest, cmd) {
|
|
@@ -258,7 +261,8 @@ async function runPluginsVerb(verb, rest, cmd) {
|
|
|
258
261
|
console.log(ui.meta(`install order: ${order.join(" -> ")}`));
|
|
259
262
|
for (const res of installed) {
|
|
260
263
|
console.log(`${ui.ok("added")} ${ui.name(res.name)} ${ui.meta(`-> ${res.installedTo}`)}`);
|
|
261
|
-
console.log(ui.meta(`
|
|
264
|
+
console.log(ui.meta(` sourceHash: ${res.sourceHash}`));
|
|
265
|
+
console.log(ui.meta(` installedHash: ${res.installedHash}`));
|
|
262
266
|
for (const f of res.adapted)
|
|
263
267
|
console.log(ui.meta(` adapted: ${f}`));
|
|
264
268
|
}
|
|
@@ -455,11 +459,13 @@ async function runPluginsVerb(verb, rest, cmd) {
|
|
|
455
459
|
const { values } = parseVerb(verb, cmd.flags, rest);
|
|
456
460
|
const sc = await resolveActionScope(values, "migrate");
|
|
457
461
|
const res = migrateLayout(sc.pluginsDir);
|
|
462
|
+
if (res.lockUpgraded)
|
|
463
|
+
console.log(`${ui.ok("upgraded")} plugin lock to version 3`);
|
|
458
464
|
for (const m of res.moved)
|
|
459
465
|
console.log(`${ui.ok("moved")} ${ui.name(m.name)}: ${ui.meta(`${m.from} -> ${m.to}`)}`);
|
|
460
466
|
for (const m of res.missing)
|
|
461
467
|
console.error(ui.warn(` ! missing directory for locked plugin: ${m}`));
|
|
462
|
-
if (res.moved.length === 0)
|
|
468
|
+
if (!res.lockUpgraded && res.moved.length === 0)
|
|
463
469
|
console.log(ui.meta(`nothing to migrate (${res.unchanged.length} already in place)`));
|
|
464
470
|
return;
|
|
465
471
|
}
|
|
@@ -578,3 +584,39 @@ async function runMarketplace(args) {
|
|
|
578
584
|
}
|
|
579
585
|
}
|
|
580
586
|
}
|
|
587
|
+
async function runCache(args) {
|
|
588
|
+
const [sub, ...rest] = args;
|
|
589
|
+
if (sub === undefined || sub === "-h" || sub === "--help" || sub === "help" || wantsHelp(rest)) {
|
|
590
|
+
console.log(CACHE_USAGE);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (sub === "status") {
|
|
594
|
+
const { values } = parseVerb("cache", [...SCOPE], rest);
|
|
595
|
+
const status = pluginCacheStatus(resolveScopeDir(values));
|
|
596
|
+
console.log(ui.meta(status.root));
|
|
597
|
+
if (status.entries.length === 0)
|
|
598
|
+
console.log(ui.meta("cache is empty"));
|
|
599
|
+
for (const entry of status.entries) {
|
|
600
|
+
console.log(`${entry.orphan ? ui.warn("orphan") : ui.ok("cached")} ${ui.name(entry.name)} ${ui.meta(`${entry.bytes} bytes`)}`);
|
|
601
|
+
}
|
|
602
|
+
console.log(ui.meta(`total: ${status.totalBytes} bytes`));
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (sub === "prune") {
|
|
606
|
+
const { values } = parseVerb("cache", [...SCOPE], rest);
|
|
607
|
+
const scope = await resolveActionScope(values, "cache prune");
|
|
608
|
+
const removed = prunePluginCache(scope.pluginsDir);
|
|
609
|
+
console.log(removed.length > 0 ? `${ui.ok("pruned")} ${removed.join(", ")}` : ui.meta("no orphan cache snapshots"));
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (sub === "clean") {
|
|
613
|
+
const { values } = parseVerb("cache", ["force", ...SCOPE], rest);
|
|
614
|
+
if (!values.force)
|
|
615
|
+
fail("cache clean requires --force");
|
|
616
|
+
const scope = await resolveActionScope(values, "cache clean");
|
|
617
|
+
cleanPluginCache(scope.pluginsDir);
|
|
618
|
+
console.log(ui.ok("cache cleaned"));
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
fail(`unknown cache subcommand: ${sub}`);
|
|
622
|
+
}
|
package/dist/src/cli/index.js
CHANGED
|
@@ -162,7 +162,7 @@ export const PLUGIN_COMMANDS = {
|
|
|
162
162
|
],
|
|
163
163
|
},
|
|
164
164
|
migrate: {
|
|
165
|
-
summary: "move flat installs
|
|
165
|
+
summary: "upgrade legacy locks and move flat installs",
|
|
166
166
|
synopsis: "adg plugins migrate",
|
|
167
167
|
flags: [...SCOPE],
|
|
168
168
|
},
|
|
@@ -172,6 +172,12 @@ export const PLUGIN_COMMANDS = {
|
|
|
172
172
|
flags: [],
|
|
173
173
|
delegated: true,
|
|
174
174
|
},
|
|
175
|
+
cache: {
|
|
176
|
+
summary: "inspect and garbage-collect source snapshots",
|
|
177
|
+
synopsis: "adg plugins cache <status|prune|clean>",
|
|
178
|
+
flags: [],
|
|
179
|
+
delegated: true,
|
|
180
|
+
},
|
|
175
181
|
};
|
|
176
182
|
// Aliases tolerated for plugin verbs.
|
|
177
183
|
export const PLUGIN_ALIASES = { rm: "remove", mp: "marketplace" };
|
|
@@ -212,6 +218,16 @@ Commands:
|
|
|
212
218
|
Kept as an alias. To pull upstream changes, prefer \`adg plugins update\`.
|
|
213
219
|
|
|
214
220
|
<source> is a key from \`marketplace list\` (e.g. owner/repo).`;
|
|
221
|
+
export const CACHE_USAGE = `adg plugins cache — inspect and garbage-collect complete source snapshots
|
|
222
|
+
|
|
223
|
+
Commands:
|
|
224
|
+
adg plugins cache status [--global | --project | --dir <dir>]
|
|
225
|
+
Show cached snapshots, byte sizes, and orphan state.
|
|
226
|
+
adg plugins cache prune [--global | --project | --dir <dir>]
|
|
227
|
+
Delete snapshots that have no corresponding lock entry.
|
|
228
|
+
adg plugins cache clean --force [--global | --project | --dir <dir>]
|
|
229
|
+
Delete every source snapshot for the selected store. A later update or
|
|
230
|
+
add may be required before link/sync can rebuild remote plugins.`;
|
|
215
231
|
export function flagLabel(name) {
|
|
216
232
|
const f = FLAGS[name];
|
|
217
233
|
const lead = f.short ? `-${f.short}, --${name}` : ` --${name}`;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { existsSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readLock } from "../lock.js";
|
|
4
|
+
import { lockPath, pluginCacheRoot } from "../paths.js";
|
|
5
|
+
export function directoryBytes(dir) {
|
|
6
|
+
let total = 0;
|
|
7
|
+
try {
|
|
8
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
9
|
+
const path = join(dir, entry.name);
|
|
10
|
+
if (entry.isDirectory())
|
|
11
|
+
total += directoryBytes(path);
|
|
12
|
+
else if (entry.isFile()) {
|
|
13
|
+
try {
|
|
14
|
+
total += statSync(path).size;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// A concurrent cache mutation must not make status fail.
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Treat an unreadable or concurrently removed directory as empty.
|
|
24
|
+
}
|
|
25
|
+
return total;
|
|
26
|
+
}
|
|
27
|
+
export function pluginCacheStatus(pluginsDir) {
|
|
28
|
+
const root = pluginCacheRoot(pluginsDir);
|
|
29
|
+
const installed = new Set(Object.keys(readLock(lockPath(pluginsDir)).plugins));
|
|
30
|
+
const entries = existsSync(root)
|
|
31
|
+
? readdirSync(root, { withFileTypes: true })
|
|
32
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
33
|
+
.map((entry) => {
|
|
34
|
+
const path = join(root, entry.name);
|
|
35
|
+
return { name: entry.name, path, bytes: directoryBytes(path), orphan: !installed.has(entry.name) };
|
|
36
|
+
})
|
|
37
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
38
|
+
: [];
|
|
39
|
+
return { root, entries, totalBytes: entries.reduce((sum, entry) => sum + entry.bytes, 0) };
|
|
40
|
+
}
|
|
41
|
+
/** Delete cache snapshots that have no corresponding lock entry. */
|
|
42
|
+
export function prunePluginCache(pluginsDir) {
|
|
43
|
+
const status = pluginCacheStatus(pluginsDir);
|
|
44
|
+
const removed = status.entries.filter((entry) => entry.orphan);
|
|
45
|
+
for (const entry of removed)
|
|
46
|
+
rmSync(entry.path, { recursive: true, force: true });
|
|
47
|
+
if (existsSync(status.root) && readdirSync(status.root).length === 0)
|
|
48
|
+
rmSync(status.root, { recursive: true, force: true });
|
|
49
|
+
return removed.map((entry) => entry.name);
|
|
50
|
+
}
|
|
51
|
+
/** Delete every rebuildable source snapshot for this store. */
|
|
52
|
+
export function cleanPluginCache(pluginsDir) {
|
|
53
|
+
rmSync(pluginCacheRoot(pluginsDir), { recursive: true, force: true });
|
|
54
|
+
}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { basename, join, relative, resolve } from "node:path";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
5
|
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
5
6
|
import { fromNativeManifest } from "../adapters/reverse.js";
|
|
6
7
|
import { adaptPlugin } from "./adapt.js";
|
|
7
8
|
import { removePlugin } from "./remove.js";
|
|
8
|
-
import {
|
|
9
|
+
import { toPosix, writeJson } from "../fsutil.js";
|
|
9
10
|
import { folderHash } from "../hash.js";
|
|
10
11
|
import { packageFilter, PROJECTION_DIRS } from "../package.js";
|
|
11
|
-
import { lockPath, marketplacePath, marketplaceSourcePath, pluginDir } from "../paths.js";
|
|
12
|
+
import { lockPath, marketplacePath, marketplaceSourcePath, pluginDir, pluginSourceCacheDir } from "../paths.js";
|
|
12
13
|
import { readLock, upsertEntry, writeLock } from "../lock.js";
|
|
13
14
|
import { ADG_MANIFEST_PATH, readManifest } from "../manifest.js";
|
|
14
15
|
import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../marketplace.js";
|
|
15
16
|
import { resolveInstallOrder } from "../deps.js";
|
|
16
17
|
import { cloneGitHub, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
|
|
17
|
-
import { pluginState, sameSource, COMPONENT_TYPES } from "../types.js";
|
|
18
|
+
import { normalizePluginSelection, pluginState, resolveSelectionDependencies, sameSource, COMPONENT_TYPES } from "../types.js";
|
|
18
19
|
import { pluginContents, presentComponents } from "../components.js";
|
|
19
20
|
import { skillDescriptionLoader } from "../skills.js";
|
|
20
21
|
import { resolveAgents } from "../agents/index.js";
|
|
22
|
+
import { effectivePackageFilter, materializePlugin, withPluginSourceCache } from "../materialize.js";
|
|
21
23
|
// Generated runtime projections never count toward a plugin's content hash.
|
|
22
24
|
const HASH_IGNORE = PROJECTION_DIRS;
|
|
23
25
|
/** Content hash over a plugin's packaged payload (hooks files are authored content, not generated). */
|
|
@@ -40,7 +42,7 @@ export function installPlugin(opts) {
|
|
|
40
42
|
const name = manifest.name;
|
|
41
43
|
// Local installs stay flat; remote sources derive a per-marketplace dir from
|
|
42
44
|
// their origin. The default (no origin) is a flat local copy-in.
|
|
43
|
-
const origin = opts.origin ?? { type: "local", path:
|
|
45
|
+
const origin = opts.origin ?? { type: "local", path: source };
|
|
44
46
|
const dest = pluginDir(opts.pluginsDir, name, origin);
|
|
45
47
|
const lockFile = lockPath(opts.pluginsDir);
|
|
46
48
|
const lock = readLock(lockFile);
|
|
@@ -49,56 +51,76 @@ export function installPlugin(opts) {
|
|
|
49
51
|
throw new Error(`name collision: "${name}" is already installed from a different source ` +
|
|
50
52
|
`(${describe(prev.origin)} vs ${describe(origin)}). Rename one to avoid the conflict.`);
|
|
51
53
|
}
|
|
52
|
-
// Detect-then-update: compute the source's content hash up front (cheap, no
|
|
53
|
-
// copy) and, when asked, short-circuit if it matches what's already recorded —
|
|
54
|
-
// so an unchanged upstream source is never re-copied, re-adapted, or re-locked.
|
|
55
|
-
if (opts.skipUnchanged && prev) {
|
|
56
|
-
const sourceHash = contentHash(source, manifest);
|
|
57
|
-
if (prev.folderHash === sourceHash && prev.version === manifest.version) {
|
|
58
|
-
return { name, installedTo: dest, folderHash: sourceHash, adapted: [], changed: false };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// When the source already lives at the destination (e.g. adapting an
|
|
62
|
-
// in-repo reference plugin) skip the copy to avoid copying onto itself.
|
|
63
|
-
// Only the manifest-declared payload is copied (projections included) — dev
|
|
64
|
-
// cruft like src/ or test/ never ships.
|
|
65
|
-
if (resolve(dest) !== source) {
|
|
66
|
-
copyPluginDir(source, dest, packageFilter(manifest, { includeProjections: true }));
|
|
67
|
-
}
|
|
68
54
|
// A new selection wins; otherwise keep whatever a prior install recorded so
|
|
69
55
|
// partial installs survive re-install / `marketplace upgrade`.
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
56
|
+
const desiredSelection = normalizePluginSelection(opts.selection ?? prev?.selection);
|
|
57
|
+
const selection = resolveSelectionDependencies(manifest, desiredSelection);
|
|
58
|
+
const sourceHash = contentHash(source, manifest);
|
|
59
|
+
const cacheDir = pluginSourceCacheDir(opts.pluginsDir, name);
|
|
60
|
+
return withPluginSourceCache(source, cacheDir, manifest, (snapshot) => {
|
|
61
|
+
// Detect-then-update compares the complete source snapshot, never the
|
|
62
|
+
// selection-pruned runtime installation.
|
|
63
|
+
if (!opts.forceMaterialize && opts.skipUnchanged && prev
|
|
64
|
+
&& prev.sourceHash === sourceHash && prev.version === manifest.version) {
|
|
65
|
+
const installedIntact = existsSync(dest)
|
|
66
|
+
&& folderHash(dest, PROJECTION_DIRS, effectivePackageFilter(manifest, selection)) === prev.installedHash;
|
|
67
|
+
if (installedIntact) {
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
version: manifest.version,
|
|
71
|
+
installedTo: dest,
|
|
72
|
+
sourceHash,
|
|
73
|
+
installedHash: prev.installedHash,
|
|
74
|
+
adapted: [],
|
|
75
|
+
changed: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const targets = opts.targets ?? [...ADAPTER_TARGETS];
|
|
80
|
+
const adapted = [];
|
|
81
|
+
let installedHash = "";
|
|
82
|
+
materializePlugin({
|
|
83
|
+
source: snapshot,
|
|
84
|
+
destination: dest,
|
|
85
|
+
manifest,
|
|
86
|
+
selection,
|
|
87
|
+
build: (staging) => {
|
|
88
|
+
adapted.push(...adaptPlugin(staging, targets, selection).map((r) => relative(staging, r.file)));
|
|
89
|
+
installedHash = folderHash(staging, PROJECTION_DIRS, effectivePackageFilter(manifest, selection));
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
const adaptedFiles = adapted.map((file) => join(dest, file));
|
|
93
|
+
const entry = {
|
|
94
|
+
origin,
|
|
95
|
+
version: manifest.version,
|
|
96
|
+
sourceHash,
|
|
97
|
+
installedHash,
|
|
98
|
+
};
|
|
99
|
+
if (manifest.dependencies?.length) {
|
|
100
|
+
entry.dependencies = Object.fromEntries(manifest.dependencies.map((d) => [d.name, d.version]));
|
|
101
|
+
}
|
|
102
|
+
if (desiredSelection)
|
|
103
|
+
entry.selection = desiredSelection;
|
|
104
|
+
if (prev?.state)
|
|
105
|
+
entry.state = prev.state;
|
|
106
|
+
const previousEntry = prev && Object.fromEntries(Object.entries(prev).filter(([key]) => key !== "installedAt" && key !== "updatedAt"));
|
|
107
|
+
const changed = !prev || !isDeepStrictEqual(previousEntry, entry);
|
|
108
|
+
if (changed) {
|
|
109
|
+
upsertEntry(lock, name, entry, opts.now);
|
|
110
|
+
writeLock(lockFile, lock);
|
|
111
|
+
}
|
|
112
|
+
const marketFile = marketplacePath(opts.pluginsDir);
|
|
113
|
+
const fallbackName = opts.marketplaceName ?? basename(opts.pluginsDir);
|
|
114
|
+
const market = readMarketplace(marketFile, fallbackName);
|
|
115
|
+
upsertMarketplacePlugin(market, {
|
|
116
|
+
name,
|
|
117
|
+
source: { source: "local", path: marketplaceSourcePath(opts.pluginsDir, dest) },
|
|
118
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
119
|
+
...(manifest.category ? { category: manifest.category } : {}),
|
|
120
|
+
});
|
|
121
|
+
writeMarketplace(marketFile, market);
|
|
122
|
+
return { name, version: manifest.version, installedTo: dest, sourceHash, installedHash, adapted: adaptedFiles, changed };
|
|
99
123
|
});
|
|
100
|
-
writeMarketplace(marketFile, market);
|
|
101
|
-
return { name, installedTo: dest, folderHash: hash, adapted, changed };
|
|
102
124
|
}
|
|
103
125
|
function describe(s) {
|
|
104
126
|
switch (s.type) {
|
|
@@ -214,13 +236,13 @@ function sameRemoteSource(entry, parsed, ref) {
|
|
|
214
236
|
* (`--plugin one` after previously installing `--all`) without leaving stale
|
|
215
237
|
* runtime exports behind.
|
|
216
238
|
*/
|
|
217
|
-
function reconcileRemotePlugins(opts, parsed, ref, desired) {
|
|
239
|
+
function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
|
|
218
240
|
if (parsed.kind === "local")
|
|
219
241
|
return [];
|
|
220
242
|
// A path/sparse install does not prove the full source shape, so it must not
|
|
221
243
|
// prune sibling plugins from the same repo that were intentionally excluded
|
|
222
244
|
// from the checkout/selection window.
|
|
223
|
-
if (
|
|
245
|
+
if (narrowed || opts.sparse?.length)
|
|
224
246
|
return [];
|
|
225
247
|
const lock = readLock(lockPath(opts.pluginsDir));
|
|
226
248
|
const stale = Object.entries(lock.plugins)
|
|
@@ -255,12 +277,14 @@ function reconcileRemotePlugins(opts, parsed, ref, desired) {
|
|
|
255
277
|
export async function addPlugins(opts) {
|
|
256
278
|
const parsed = parseSource(opts.spec);
|
|
257
279
|
const sourceRef = parsed.kind === "local" ? undefined : (opts.ref ?? parsed.ref);
|
|
280
|
+
const inferredPath = parsed.kind === "github" ? parsed.path : undefined;
|
|
281
|
+
const path = opts.path ?? inferredPath;
|
|
258
282
|
let workRoot;
|
|
259
283
|
let buildOrigin;
|
|
260
284
|
let cleanup;
|
|
261
285
|
if (parsed.kind === "local") {
|
|
262
286
|
workRoot = resolve(parsed.dir);
|
|
263
|
-
buildOrigin = (dir) => ({ type: "local", path:
|
|
287
|
+
buildOrigin = (dir) => ({ type: "local", path: resolve(dir) });
|
|
264
288
|
}
|
|
265
289
|
else {
|
|
266
290
|
const tmp = mkdtempSync(join(tmpdir(), "adg-clone-"));
|
|
@@ -279,7 +303,7 @@ export async function addPlugins(opts) {
|
|
|
279
303
|
if (candidates.size === 0) {
|
|
280
304
|
throw new Error(`no plugin found in "${opts.spec}" (no .agents/.plugin.json, .claude-plugin or .codex-plugin manifest).`);
|
|
281
305
|
}
|
|
282
|
-
const selected = await selectPluginNames(opts, candidates, workRoot, converted);
|
|
306
|
+
const selected = await selectPluginNames({ ...opts, path }, candidates, workRoot, converted);
|
|
283
307
|
// Resolve adapter targets after the plugin choice (lets a CLI agent picker
|
|
284
308
|
// run once we know what's being installed). undefined → installPlugin's all.
|
|
285
309
|
const targets = opts.targets ?? (opts.selectTargets ? await opts.selectTargets() : undefined);
|
|
@@ -289,7 +313,7 @@ export async function addPlugins(opts) {
|
|
|
289
313
|
// upstream: don't abort — return what the source still offers so the
|
|
290
314
|
// caller can report the deletions.
|
|
291
315
|
if (opts.missingPlugins === "skip") {
|
|
292
|
-
const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(selected));
|
|
316
|
+
const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(selected));
|
|
293
317
|
return { order: [], installed: [], removed, converted, available };
|
|
294
318
|
}
|
|
295
319
|
throw new Error("no plugins selected");
|
|
@@ -308,7 +332,7 @@ export async function addPlugins(opts) {
|
|
|
308
332
|
}
|
|
309
333
|
}
|
|
310
334
|
}
|
|
311
|
-
const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(order));
|
|
335
|
+
const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(order));
|
|
312
336
|
// Snapshot which plugins already existed before this call mutates the lock,
|
|
313
337
|
// so the activation step below can tell brand-new installs from updates.
|
|
314
338
|
const existingPlugins = new Set(Object.keys(readLock(lockPath(opts.pluginsDir)).plugins));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { selectInstalled } from "./projection.js";
|
|
4
|
-
import { installedPluginDir } from "../paths.js";
|
|
1
|
+
import { adaptedFilesForTarget, selectInstalled } from "./projection.js";
|
|
2
|
+
import { pluginRematerializationSource } from "../paths.js";
|
|
5
3
|
import { getAgent } from "../agents/index.js";
|
|
4
|
+
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
6
5
|
import { pluginState } from "../types.js";
|
|
6
|
+
import { installPlugin } from "./install.js";
|
|
7
7
|
/**
|
|
8
8
|
* Project installed plugins into an agent: (re)generate that agent's manifest
|
|
9
9
|
* from each plugin (honoring its partial-install selection), then enable the
|
|
@@ -22,11 +22,15 @@ export function linkPlugins(opts) {
|
|
|
22
22
|
const enabled = selected.filter((p) => pluginState(p) === "enabled");
|
|
23
23
|
const actions = [];
|
|
24
24
|
for (const p of enabled) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const result = installPlugin({
|
|
26
|
+
source: pluginRematerializationSource(opts.pluginsDir, p.name, p.origin),
|
|
27
|
+
pluginsDir: opts.pluginsDir,
|
|
28
|
+
origin: p.origin,
|
|
29
|
+
selection: p.selection,
|
|
30
|
+
targets: [...ADAPTER_TARGETS],
|
|
31
|
+
forceMaterialize: true,
|
|
32
|
+
});
|
|
33
|
+
actions.push({ name: p.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget) });
|
|
30
34
|
}
|
|
31
35
|
if (!agent)
|
|
32
36
|
return { target: opts.target, actions };
|