@rbbtsn0w/adg 0.6.0-beta.6 → 0.6.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 +17 -2
- package/dist/src/adapters/codex.js +12 -0
- package/dist/src/agents/codex.js +31 -1
- package/dist/src/cli/handlers.js +22 -3
- package/dist/src/cli/index.js +12 -4
- package/dist/src/codex-marketplace-migration.js +139 -0
- package/dist/src/commands/cache.js +92 -15
- package/dist/src/commands/inspect.js +41 -0
- package/dist/src/commands/install.js +84 -27
- package/dist/src/commands/link.js +1 -0
- package/dist/src/commands/marketplace.js +74 -20
- package/dist/src/commands/migrate.js +15 -3
- package/dist/src/commands/projection.js +3 -2
- package/dist/src/commands/state.js +4 -2
- package/dist/src/commands/sync.js +6 -1
- package/dist/src/commands/update.js +49 -10
- package/dist/src/commands/validate.js +9 -2
- package/dist/src/default-dsl.js +140 -0
- package/dist/src/lock.js +25 -7
- package/dist/src/manifest.js +26 -2
- package/dist/src/paths.js +31 -4
- package/dist/src/source-cache.js +140 -0
- package/dist/src/sources.js +75 -4
- package/dist/src/types.js +1 -1
- package/docs/agents-spec.md +27 -4
- package/docs/authoring.md +19 -2
- package/package.json +4 -2
- package/schemas/adg-plugin.schema.json +1 -0
- package/schemas/plugin-lock.schema.json +23 -1
package/README.md
CHANGED
|
@@ -31,6 +31,21 @@ See [docs/authoring.md](docs/authoring.md) to author a plugin, and
|
|
|
31
31
|
- **Reproducibility** — `.plugin-lock.json` records source, version and a content
|
|
32
32
|
hash for every installed plugin.
|
|
33
33
|
|
|
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
|
+
|
|
34
49
|
---
|
|
35
50
|
|
|
36
51
|
# Install and quick start
|
|
@@ -266,9 +281,9 @@ adg plugins add plugins/my-plugin --project # <repo>/.agents/plugins
|
|
|
266
281
|
adg plugins add plugins/my-plugin --global # ~/.agents/plugins
|
|
267
282
|
adg plugins add plugins/asc --dir plugins # explicit target dir
|
|
268
283
|
|
|
269
|
-
# add from GitHub (shorthand, @ref, or full URL)
|
|
284
|
+
# add from GitHub (shorthand, @ref, or full URL)
|
|
270
285
|
adg plugins add owner/repo --dir plugins
|
|
271
|
-
adg plugins add owner/repo@v0.1.0 --
|
|
286
|
+
adg plugins add owner/repo@v0.1.0 --plugin asc --dir plugins
|
|
272
287
|
adg plugins add https://github.com/owner/repo.git --ref main --dir plugins
|
|
273
288
|
adg plugins add plugins/asc --dir plugins --no-deps # skip transitive deps
|
|
274
289
|
|
|
@@ -3,6 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { resolveProjectedSkills } from "../skills.js";
|
|
4
4
|
import { isExposed } from "../components.js";
|
|
5
5
|
import { mcpConfigPath } from "../mcp.js";
|
|
6
|
+
import { recordTelemetryEvent } from "../telemetry.js";
|
|
6
7
|
/**
|
|
7
8
|
* Resolve the hooks config *file* Codex should reference. ADG declares `hooks` as
|
|
8
9
|
* a directory, but Codex (unlike Claude) has no auto-load — it needs an explicit
|
|
@@ -52,6 +53,17 @@ export function toCodexManifest(pluginDir, manifest, selection) {
|
|
|
52
53
|
description: manifest.description,
|
|
53
54
|
skills,
|
|
54
55
|
};
|
|
56
|
+
const displayName = typeof manifest.interface?.displayName === "string" ? manifest.interface.displayName : undefined;
|
|
57
|
+
const explicitShortDescription = typeof manifest.interface?.shortDescription === "string" && manifest.interface.shortDescription.trim()
|
|
58
|
+
? manifest.interface.shortDescription.trim()
|
|
59
|
+
: undefined;
|
|
60
|
+
out.interface = {
|
|
61
|
+
...(displayName ? { displayName } : {}),
|
|
62
|
+
shortDescription: explicitShortDescription ?? manifest.description,
|
|
63
|
+
};
|
|
64
|
+
recordTelemetryEvent("adg.codex.interface", {
|
|
65
|
+
"interface.short_description_source": explicitShortDescription ? "explicit" : "manifest",
|
|
66
|
+
});
|
|
55
67
|
if (manifest.author)
|
|
56
68
|
out.author = manifest.author;
|
|
57
69
|
if (manifest.homepage)
|
package/dist/src/agents/codex.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
|
+
import { SpanKind } from "@opentelemetry/api";
|
|
5
6
|
import { codexMarketplaceRoot, globalPluginsDir, marketplacePath } from "../paths.js";
|
|
6
7
|
import { readMarketplace, writeMarketplace } from "../marketplace.js";
|
|
7
8
|
import { makeCli, skippedResult } from "./base.js";
|
|
9
|
+
import { reconcileCodexMarketplaceAliases } from "../codex-marketplace-migration.js";
|
|
10
|
+
import { getTracer, recordTelemetryEvent } from "../telemetry.js";
|
|
8
11
|
const UNRECOGNIZED_PLUGIN_LIST = "codex plugin list returned unrecognized output";
|
|
9
12
|
const MARKETPLACE = "adg";
|
|
10
13
|
/**
|
|
@@ -53,6 +56,31 @@ export function syncMarketplace(pluginsDir, marketplace, runner = run, warn = co
|
|
|
53
56
|
warn(`failed to sync Codex marketplace (${marketplace}): ${upgraded.out.trim() || add.out.trim() || "codex plugin marketplace sync failed without an error message"}`);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Best-effort retirement of historical aliases after canonical installs succeed.
|
|
61
|
+
* Keep this compatibility path only until telemetry reports no legacy aliases for
|
|
62
|
+
* two release cycles.
|
|
63
|
+
*/
|
|
64
|
+
function reconcileLegacyAliases(pluginsDir, marketplace, plugins) {
|
|
65
|
+
getTracer().startActiveSpan("adg.codex.marketplace_alias_migration", { kind: SpanKind.INTERNAL }, (span) => {
|
|
66
|
+
try {
|
|
67
|
+
const result = reconcileCodexMarketplaceAliases({
|
|
68
|
+
pluginsDir,
|
|
69
|
+
marketplace,
|
|
70
|
+
plugins,
|
|
71
|
+
readConfig: () => readFileSync(join(codexHome(process.env), "config.toml"), "utf8"),
|
|
72
|
+
run,
|
|
73
|
+
report: (attributes) => recordTelemetryEvent("adg.codex.marketplace_alias_migration", attributes, span),
|
|
74
|
+
});
|
|
75
|
+
if (result.outcome === "partial") {
|
|
76
|
+
console.warn("Codex legacy marketplace alias cleanup was only partially completed; rerun `adg plugins sync --target codex` to retry.");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
span.end();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
56
84
|
export const codexAgent = {
|
|
57
85
|
id: "codex",
|
|
58
86
|
displayName: "Codex",
|
|
@@ -69,6 +97,8 @@ export const codexAgent = {
|
|
|
69
97
|
if (run(["plugin", "add", `${p}@${mp}`]).ok)
|
|
70
98
|
affected.push(p);
|
|
71
99
|
}
|
|
100
|
+
if (ctx.reconcileLegacyAliases && affected.length > 0)
|
|
101
|
+
reconcileLegacyAliases(ctx.pluginsDir, mp, affected);
|
|
72
102
|
return { agent: "codex", affected, skipped: false };
|
|
73
103
|
},
|
|
74
104
|
deactivate(ctx) {
|
package/dist/src/cli/handlers.js
CHANGED
|
@@ -5,6 +5,7 @@ import { addPlugins } from "../commands/install.js";
|
|
|
5
5
|
import { validatePlugin } from "../commands/validate.js";
|
|
6
6
|
import { listPlugins } from "../commands/list.js";
|
|
7
7
|
import { importSkills } from "../commands/import.js";
|
|
8
|
+
import { inspectSource } from "../commands/inspect.js";
|
|
8
9
|
import { linkPlugins } from "../commands/link.js";
|
|
9
10
|
import { unlinkPlugins } from "../commands/unlink.js";
|
|
10
11
|
import { syncPlugins } from "../commands/sync.js";
|
|
@@ -12,7 +13,7 @@ import { removePlugin } from "../commands/remove.js";
|
|
|
12
13
|
import { disablePlugins, enablePlugins } from "../commands/state.js";
|
|
13
14
|
import { migrateLayout } from "../commands/migrate.js";
|
|
14
15
|
import { pluginStatus } from "../commands/status.js";
|
|
15
|
-
import { cleanPluginCache, pluginCacheStatus, prunePluginCache } from "../commands/cache.js";
|
|
16
|
+
import { cleanPluginCache, pluginCacheStatus, prunePluginCache, restorePluginCache } from "../commands/cache.js";
|
|
16
17
|
import { marketplaceList, marketplaceRemove, marketplaceSync, updatePlugins } from "../commands/marketplace.js";
|
|
17
18
|
import { initScaffold } from "../commands/init.js";
|
|
18
19
|
import { confirmFullInstall, selectComponentsInteractive } from "../commands/select-components.js";
|
|
@@ -197,7 +198,6 @@ async function handleAdd(rest, cmd) {
|
|
|
197
198
|
pluginsDir,
|
|
198
199
|
ref: values.ref,
|
|
199
200
|
sparse: values.sparse,
|
|
200
|
-
path: values.path,
|
|
201
201
|
all: values.all,
|
|
202
202
|
plugins: values.plugin,
|
|
203
203
|
only,
|
|
@@ -205,12 +205,14 @@ async function handleAdd(rest, cmd) {
|
|
|
205
205
|
mcpSubset,
|
|
206
206
|
withDeps: !values["no-deps"],
|
|
207
207
|
marketplaceName: values["marketplace-name"],
|
|
208
|
+
as: values.as,
|
|
208
209
|
targets: values.target !== undefined ? resolveTargets(values.target) : undefined,
|
|
209
210
|
selectPlugins: tty ? selectPluginsInteractive : undefined,
|
|
210
211
|
selectTargets: tty && values.target === undefined ? selectTargetsInteractive : undefined,
|
|
211
212
|
confirmFull: tty && !narrowed ? confirmFullInstall : undefined,
|
|
212
213
|
selectComponents: tty && !narrowed ? selectComponentsInteractive : undefined,
|
|
213
214
|
activate: true,
|
|
215
|
+
nonInteractive: !tty,
|
|
214
216
|
scope: global ? "user" : "project",
|
|
215
217
|
});
|
|
216
218
|
for (const name of converted)
|
|
@@ -340,6 +342,15 @@ async function runPluginsVerb(verb, rest, cmd) {
|
|
|
340
342
|
}
|
|
341
343
|
return;
|
|
342
344
|
}
|
|
345
|
+
case "inspect": {
|
|
346
|
+
const { values, positionals } = parseVerb(verb, cmd.flags, rest);
|
|
347
|
+
const result = await inspectSource({ spec: positionals[0] ?? process.cwd(), ref: values.ref });
|
|
348
|
+
if (values.json)
|
|
349
|
+
console.log(JSON.stringify(result, null, 2));
|
|
350
|
+
else
|
|
351
|
+
console.log(`${ui.ok("inspected")} ${ui.name(result.manifest.name)} ${ui.meta(`[${result.kind}] ${result.components.join(", ") || "no components"}`)}`);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
343
354
|
case "add": {
|
|
344
355
|
await handleAdd(rest, cmd);
|
|
345
356
|
return;
|
|
@@ -601,7 +612,8 @@ async function runCache(args) {
|
|
|
601
612
|
if (status.entries.length === 0)
|
|
602
613
|
console.log(ui.meta("cache is empty"));
|
|
603
614
|
for (const entry of status.entries) {
|
|
604
|
-
|
|
615
|
+
const label = entry.orphan ? ui.warn("orphan") : entry.recovery === "present" ? ui.ok("cached") : ui.warn(entry.recovery ?? "cached");
|
|
616
|
+
console.log(`${label} ${ui.name(entry.name)} ${ui.meta(`${entry.bytes} bytes`)}`);
|
|
605
617
|
}
|
|
606
618
|
console.log(ui.meta(`total: ${status.totalBytes} bytes`));
|
|
607
619
|
return;
|
|
@@ -622,5 +634,12 @@ async function runCache(args) {
|
|
|
622
634
|
console.log(ui.ok("cache cleaned"));
|
|
623
635
|
return;
|
|
624
636
|
}
|
|
637
|
+
if (sub === "restore") {
|
|
638
|
+
const { values, positionals } = parseVerb("cache", [...SCOPE], rest);
|
|
639
|
+
const scope = await resolveActionScope(values, "cache restore");
|
|
640
|
+
const restored = restorePluginCache(scope.pluginsDir, positionals);
|
|
641
|
+
console.log(restored.length > 0 ? `${ui.ok("restored")} ${restored.join(", ")}` : ui.meta("no source snapshots to restore"));
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
625
644
|
fail(`unknown cache subcommand: ${sub}`);
|
|
626
645
|
}
|
package/dist/src/cli/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export const FLAGS = {
|
|
|
8
8
|
// Short flags are first-letter aliases. Where several long flags share a
|
|
9
9
|
// first letter, the highest-frequency one wins the short and the rest stay
|
|
10
10
|
// long-only: d → dir (not description) a → all (not author/as)
|
|
11
|
-
// s → skill (not sparse) p → plugin (not
|
|
11
|
+
// s → skill (not sparse) p → plugin (not project/prefix)
|
|
12
12
|
dir: { type: "string", short: "d", hint: "<dir>", help: "install into an explicit directory" },
|
|
13
13
|
global: { type: "boolean", short: "g", help: "use ~/.agents/plugins (across all projects)" },
|
|
14
14
|
project: { type: "boolean", help: "use <repo>/.agents/plugins (default)" },
|
|
@@ -16,7 +16,6 @@ export const FLAGS = {
|
|
|
16
16
|
all: { type: "boolean", short: "a", help: "select all available plugins" },
|
|
17
17
|
plugin: { type: "string", short: "p", multiple: true, hint: "<name>", help: "select a specific plugin (repeatable)" },
|
|
18
18
|
"no-deps": { type: "boolean", short: "n", help: "don't install dependencies" },
|
|
19
|
-
path: { type: "string", hint: "<subdir>", help: "install only this subdir of the source" },
|
|
20
19
|
ref: { type: "string", short: "r", hint: "<ref>", help: "pin a git ref (branch/tag/sha)" },
|
|
21
20
|
sparse: { type: "string", multiple: true, hint: "<path>", help: "sparse-checkout path (repeatable)" },
|
|
22
21
|
"marketplace-name": { type: "string", hint: "<name>", help: "override the marketplace key" },
|
|
@@ -27,7 +26,7 @@ export const FLAGS = {
|
|
|
27
26
|
skill: { type: "string", short: "s", multiple: true, hint: "<name>", help: "skill name (init: seed one · add: limit to these)" },
|
|
28
27
|
mcp: { type: "string", short: "m", multiple: true, hint: "<name>", help: "MCP server name (add: limit to these)" },
|
|
29
28
|
only: { type: "string", hint: "<types>", help: "limit to these component types (skills,agents,commands,mcp,hooks,apps)" },
|
|
30
|
-
as: { type: "string", hint: "<name>", help: "
|
|
29
|
+
as: { type: "string", hint: "<name>", help: "installed identity for a manifest-free structural source" },
|
|
31
30
|
prefix: { type: "string", hint: "<p>", help: "prefix imported skill names" },
|
|
32
31
|
verbose: { type: "boolean", short: "v", help: "expand each component to its member names" },
|
|
33
32
|
json: { type: "boolean", help: "print stable machine-readable JSON" },
|
|
@@ -50,7 +49,7 @@ export const PLUGIN_COMMANDS = {
|
|
|
50
49
|
blurb: "In a terminal, add guides you through: scope → plugins → agents → what to install.\n" +
|
|
51
50
|
"By default it installs everything; choose 'No, let me choose' to pick components,\n" +
|
|
52
51
|
"or pass the flags below to skip any prompt (e.g. for scripts/CI).",
|
|
53
|
-
flags: ["all", "plugin", "only", "skill", "mcp", "target", "no-deps", "
|
|
52
|
+
flags: ["all", "plugin", "only", "skill", "mcp", "target", "no-deps", "ref", "sparse", "marketplace-name", "as", ...SCOPE],
|
|
54
53
|
examples: [
|
|
55
54
|
"adg plugins add owner/repo # guided",
|
|
56
55
|
"adg plugins add owner/repo --all --global # all plugins, global, non-interactive",
|
|
@@ -128,6 +127,12 @@ export const PLUGIN_COMMANDS = {
|
|
|
128
127
|
positional: "<dir> plugin directory (default: current directory)",
|
|
129
128
|
flags: [],
|
|
130
129
|
},
|
|
130
|
+
inspect: {
|
|
131
|
+
summary: "inspect a plugin source without installing it",
|
|
132
|
+
synopsis: "adg plugins inspect [<source>] [--ref <ref>]",
|
|
133
|
+
positional: "<source> local directory or owner/repo[@ref] (default: current directory)",
|
|
134
|
+
flags: ["json", "ref"],
|
|
135
|
+
},
|
|
131
136
|
"import-skills": {
|
|
132
137
|
summary: "wrap an existing skills/ dir as a plugin",
|
|
133
138
|
synopsis: "adg plugins import-skills <skills-dir> --as <name>",
|
|
@@ -227,6 +232,9 @@ Commands:
|
|
|
227
232
|
Show cached snapshots, byte sizes, and orphan state.
|
|
228
233
|
adg plugins cache prune [--global | --project | --dir <dir>]
|
|
229
234
|
Delete snapshots that have no corresponding lock entry.
|
|
235
|
+
adg plugins cache restore [name...] [--global | --project | --dir <dir>]
|
|
236
|
+
Restore missing snapshots from a verified legacy cache, local source, or
|
|
237
|
+
the exact remote revision recorded in the lock.
|
|
230
238
|
adg plugins cache clean --force [--global | --project | --dir <dir>]
|
|
231
239
|
Delete every source snapshot for the selected store. A later update or
|
|
232
240
|
add may be required before link/sync can rebuild remote plugins.`;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { codexMarketplaceRoot } from "./paths.js";
|
|
3
|
+
/**
|
|
4
|
+
* Read only the marketplace/plugin tables that this migrator owns. Codex keeps
|
|
5
|
+
* these values as simple TOML scalars, so a narrow parser avoids adding a TOML
|
|
6
|
+
* dependency to ADG's runtime just for a one-shot cleanup utility.
|
|
7
|
+
*/
|
|
8
|
+
export function parseCodexPluginConfig(toml) {
|
|
9
|
+
const marketplaces = new Map();
|
|
10
|
+
const plugins = [];
|
|
11
|
+
let marketplace;
|
|
12
|
+
let plugin;
|
|
13
|
+
const flushPlugin = () => {
|
|
14
|
+
if (plugin)
|
|
15
|
+
plugins.push(plugin);
|
|
16
|
+
plugin = undefined;
|
|
17
|
+
};
|
|
18
|
+
for (const line of toml.split("\n")) {
|
|
19
|
+
const marketplaceHeader = line.match(/^\s*\[marketplaces\.([A-Za-z0-9_-]+)\]\s*$/u);
|
|
20
|
+
const pluginHeader = line.match(/^\s*\[plugins\."([^"@]+)@([^"@]+)"\]\s*$/u);
|
|
21
|
+
if (marketplaceHeader || pluginHeader || /^\s*\[/u.test(line)) {
|
|
22
|
+
flushPlugin();
|
|
23
|
+
marketplace = marketplaceHeader?.[1];
|
|
24
|
+
if (pluginHeader)
|
|
25
|
+
plugin = { name: pluginHeader[1], marketplace: pluginHeader[2], enabled: false };
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (marketplace) {
|
|
29
|
+
const source = line.match(/^\s*source\s*=\s*"([^"]+)"\s*$/u);
|
|
30
|
+
if (source)
|
|
31
|
+
marketplaces.set(marketplace, source[1]);
|
|
32
|
+
}
|
|
33
|
+
if (plugin && /^\s*enabled\s*=\s*true\s*$/u.test(line))
|
|
34
|
+
plugin.enabled = true;
|
|
35
|
+
}
|
|
36
|
+
flushPlugin();
|
|
37
|
+
return { marketplaces, plugins };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build an idempotent cleanup sequence for plugins whose canonical identity was
|
|
41
|
+
* successfully installed during this link/sync pass.
|
|
42
|
+
*/
|
|
43
|
+
export function planCodexMarketplaceCleanup(config, canonicalRoot, canonicalMarketplace, pluginNames) {
|
|
44
|
+
const root = resolve(canonicalRoot);
|
|
45
|
+
const legacyMarketplaces = [...config.marketplaces]
|
|
46
|
+
.filter(([name, source]) => name !== canonicalMarketplace && resolve(root, source) === root)
|
|
47
|
+
.map(([name]) => name)
|
|
48
|
+
.sort();
|
|
49
|
+
const legacySet = new Set(legacyMarketplaces);
|
|
50
|
+
const selected = new Set(pluginNames);
|
|
51
|
+
const legacyPlugins = config.plugins.filter((plugin) => legacySet.has(plugin.marketplace));
|
|
52
|
+
const commands = [];
|
|
53
|
+
for (const plugin of legacyPlugins) {
|
|
54
|
+
if (!selected.has(plugin.name))
|
|
55
|
+
continue;
|
|
56
|
+
commands.push(["plugin", "remove", `${plugin.name}@${plugin.marketplace}`]);
|
|
57
|
+
}
|
|
58
|
+
for (const marketplace of legacyMarketplaces) {
|
|
59
|
+
const residual = legacyPlugins.some((plugin) => plugin.marketplace === marketplace && !selected.has(plugin.name));
|
|
60
|
+
if (!residual)
|
|
61
|
+
commands.push(["plugin", "marketplace", "remove", marketplace]);
|
|
62
|
+
}
|
|
63
|
+
// Old Codex versions can leave plugin entries behind after their marketplace
|
|
64
|
+
// registration was removed. Delete only an orphan selected by this successful
|
|
65
|
+
// pass; a different live marketplace is intentionally left alone even if it
|
|
66
|
+
// happens to use the same plugin name.
|
|
67
|
+
const configuredMarketplaces = new Set(config.marketplaces.keys());
|
|
68
|
+
const orphaned = config.plugins
|
|
69
|
+
.filter((plugin) => plugin.marketplace !== canonicalMarketplace)
|
|
70
|
+
.filter((plugin) => !configuredMarketplaces.has(plugin.marketplace))
|
|
71
|
+
.filter((plugin) => selected.has(plugin.name))
|
|
72
|
+
.sort((a, b) => `${a.name}@${a.marketplace}`.localeCompare(`${b.name}@${b.marketplace}`));
|
|
73
|
+
for (const plugin of orphaned) {
|
|
74
|
+
commands.push(["plugin", "remove", `${plugin.name}@${plugin.marketplace}`]);
|
|
75
|
+
}
|
|
76
|
+
return { legacyMarketplaces, legacyPluginCount: legacyPlugins.length, orphanPluginCount: orphaned.length, commands };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Remove legacy Codex plugin identities only after this run has successfully
|
|
80
|
+
* installed their canonical replacements. A failed deletion leaves the legacy
|
|
81
|
+
* marketplace in place, so cleanup cannot make the remaining identities
|
|
82
|
+
* undiscoverable.
|
|
83
|
+
*/
|
|
84
|
+
export function reconcileCodexMarketplaceAliases(opts) {
|
|
85
|
+
let config;
|
|
86
|
+
try {
|
|
87
|
+
config = parseCodexPluginConfig(opts.readConfig());
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
const result = { outcome: "config_unavailable", removedPluginCount: 0, removedMarketplaceCount: 0 };
|
|
91
|
+
opts.report({
|
|
92
|
+
"legacy.marketplace_count": 0,
|
|
93
|
+
"legacy.plugin_count": 0,
|
|
94
|
+
"legacy.orphan_plugin_count": 0,
|
|
95
|
+
"migration.removed_plugin_count": 0,
|
|
96
|
+
"migration.removed_marketplace_count": 0,
|
|
97
|
+
"migration.outcome": result.outcome,
|
|
98
|
+
});
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
const plan = planCodexMarketplaceCleanup(config, codexMarketplaceRoot(opts.pluginsDir), opts.marketplace, opts.plugins);
|
|
102
|
+
const pluginCommands = plan.commands.filter((command) => command[1] !== "marketplace");
|
|
103
|
+
const marketplaceCommands = plan.commands.filter((command) => command[1] === "marketplace");
|
|
104
|
+
let removedPluginCount = 0;
|
|
105
|
+
let removedMarketplaceCount = 0;
|
|
106
|
+
let failed = false;
|
|
107
|
+
for (const command of pluginCommands) {
|
|
108
|
+
if (opts.run(command).ok)
|
|
109
|
+
removedPluginCount += 1;
|
|
110
|
+
else
|
|
111
|
+
failed = true;
|
|
112
|
+
}
|
|
113
|
+
if (!failed) {
|
|
114
|
+
for (const command of marketplaceCommands) {
|
|
115
|
+
if (opts.run(command).ok)
|
|
116
|
+
removedMarketplaceCount += 1;
|
|
117
|
+
else
|
|
118
|
+
failed = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const hasLegacy = plan.legacyMarketplaces.length > 0 || plan.legacyPluginCount > 0 || plan.orphanPluginCount > 0;
|
|
122
|
+
const hasDeferredLegacy = plan.legacyMarketplaces.some((marketplace) => !marketplaceCommands.some((command) => command[3] === marketplace));
|
|
123
|
+
const outcome = failed
|
|
124
|
+
? "partial"
|
|
125
|
+
: !hasLegacy
|
|
126
|
+
? "none"
|
|
127
|
+
: hasDeferredLegacy
|
|
128
|
+
? "deferred"
|
|
129
|
+
: "completed";
|
|
130
|
+
opts.report({
|
|
131
|
+
"legacy.marketplace_count": plan.legacyMarketplaces.length,
|
|
132
|
+
"legacy.plugin_count": plan.legacyPluginCount,
|
|
133
|
+
"legacy.orphan_plugin_count": plan.orphanPluginCount,
|
|
134
|
+
"migration.removed_plugin_count": removedPluginCount,
|
|
135
|
+
"migration.removed_marketplace_count": removedMarketplaceCount,
|
|
136
|
+
"migration.outcome": outcome,
|
|
137
|
+
});
|
|
138
|
+
return { outcome, removedPluginCount, removedMarketplaceCount };
|
|
139
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
3
|
import { readLock } from "../lock.js";
|
|
4
|
-
import { lockPath, pluginCacheRoot } from "../paths.js";
|
|
4
|
+
import { legacyPluginCacheRoot, legacyPluginSourceCacheDir, lockPath, pluginCacheRoot, pluginSourceCacheDir } from "../paths.js";
|
|
5
|
+
import { resolvePluginSourceSnapshot } from "../source-cache.js";
|
|
5
6
|
export function directoryBytes(dir) {
|
|
6
7
|
let total = 0;
|
|
7
8
|
try {
|
|
@@ -24,31 +25,107 @@ export function directoryBytes(dir) {
|
|
|
24
25
|
}
|
|
25
26
|
return total;
|
|
26
27
|
}
|
|
28
|
+
function cacheDirectories(root) {
|
|
29
|
+
try {
|
|
30
|
+
if (!existsSync(root))
|
|
31
|
+
return [];
|
|
32
|
+
return readdirSync(root, { withFileTypes: true })
|
|
33
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
34
|
+
.map((entry) => entry.name);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function removeRootIfEmpty(root) {
|
|
41
|
+
try {
|
|
42
|
+
if (existsSync(root) && readdirSync(root).length === 0)
|
|
43
|
+
rmSync(root, { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// A concurrent cache mutation or unreadable directory must not make prune fail.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
27
49
|
export function pluginCacheStatus(pluginsDir) {
|
|
28
50
|
const root = pluginCacheRoot(pluginsDir);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
const lock = readLock(lockPath(pluginsDir));
|
|
52
|
+
const installed = new Set(Object.keys(lock.plugins));
|
|
53
|
+
let entries = [];
|
|
54
|
+
try {
|
|
55
|
+
if (existsSync(root)) {
|
|
56
|
+
entries = cacheDirectories(root)
|
|
57
|
+
.map((name) => {
|
|
58
|
+
const path = join(root, name);
|
|
59
|
+
return { name, path, bytes: directoryBytes(path), orphan: !installed.has(name), recovery: "present" };
|
|
60
|
+
})
|
|
61
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Treat an unreadable or concurrently removed directory as empty.
|
|
66
|
+
}
|
|
67
|
+
for (const [name, entry] of Object.entries(lock.plugins)) {
|
|
68
|
+
if (entries.some((item) => item.name === name))
|
|
69
|
+
continue;
|
|
70
|
+
const legacy = legacyPluginSourceCacheDir(pluginsDir, name);
|
|
71
|
+
const localRecoverable = entry.origin.type === "local" && existsSync(resolve(pluginsDir, entry.origin.path));
|
|
72
|
+
const remoteRecoverable = (entry.origin.type === "github" || entry.origin.type === "git") && Boolean(entry.resolvedRevision);
|
|
73
|
+
const hasLegacy = existsSync(legacy);
|
|
74
|
+
entries.push({
|
|
75
|
+
name,
|
|
76
|
+
path: hasLegacy ? legacy : pluginSourceCacheDir(pluginsDir, name),
|
|
77
|
+
bytes: hasLegacy ? directoryBytes(legacy) : 0,
|
|
78
|
+
orphan: false,
|
|
79
|
+
recovery: hasLegacy ? "legacy" : (localRecoverable || remoteRecoverable ? "missing-recoverable" : "missing-unrecoverable"),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const seen = new Set(entries.map((entry) => entry.name));
|
|
83
|
+
for (const name of cacheDirectories(legacyPluginCacheRoot(pluginsDir))) {
|
|
84
|
+
if (seen.has(name))
|
|
85
|
+
continue;
|
|
86
|
+
if (installed.has(name))
|
|
87
|
+
continue;
|
|
88
|
+
const path = legacyPluginSourceCacheDir(pluginsDir, name);
|
|
89
|
+
entries.push({ name, path, bytes: directoryBytes(path), orphan: true, recovery: "legacy" });
|
|
90
|
+
}
|
|
91
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
39
92
|
return { root, entries, totalBytes: entries.reduce((sum, entry) => sum + entry.bytes, 0) };
|
|
40
93
|
}
|
|
94
|
+
/** Restore the selected snapshots with lock-hash verification. */
|
|
95
|
+
export function restorePluginCache(pluginsDir, names) {
|
|
96
|
+
const lock = readLock(lockPath(pluginsDir));
|
|
97
|
+
const selected = names?.length ? [...new Set(names)] : Object.keys(lock.plugins);
|
|
98
|
+
const missing = selected.filter((name) => !lock.plugins[name]);
|
|
99
|
+
if (missing.length > 0)
|
|
100
|
+
throw new Error(`not installed: ${missing.join(", ")}. See \`adg plugins list\`.`);
|
|
101
|
+
const restored = [];
|
|
102
|
+
for (const name of selected) {
|
|
103
|
+
const cache = pluginSourceCacheDir(pluginsDir, name);
|
|
104
|
+
const wasPresent = existsSync(cache);
|
|
105
|
+
resolvePluginSourceSnapshot(pluginsDir, name, lock.plugins[name]);
|
|
106
|
+
if (!wasPresent)
|
|
107
|
+
restored.push(name);
|
|
108
|
+
}
|
|
109
|
+
return restored;
|
|
110
|
+
}
|
|
41
111
|
/** Delete cache snapshots that have no corresponding lock entry. */
|
|
42
112
|
export function prunePluginCache(pluginsDir) {
|
|
43
113
|
const status = pluginCacheStatus(pluginsDir);
|
|
44
114
|
const removed = status.entries.filter((entry) => entry.orphan);
|
|
45
115
|
for (const entry of removed)
|
|
46
116
|
rmSync(entry.path, { recursive: true, force: true });
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
117
|
+
const installed = new Set(Object.keys(readLock(lockPath(pluginsDir)).plugins));
|
|
118
|
+
const legacyRoot = legacyPluginCacheRoot(pluginsDir);
|
|
119
|
+
for (const name of cacheDirectories(legacyRoot)) {
|
|
120
|
+
if (!installed.has(name))
|
|
121
|
+
rmSync(legacyPluginSourceCacheDir(pluginsDir, name), { recursive: true, force: true });
|
|
122
|
+
}
|
|
123
|
+
removeRootIfEmpty(status.root);
|
|
124
|
+
removeRootIfEmpty(legacyRoot);
|
|
125
|
+
return [...new Set(removed.map((entry) => entry.name))];
|
|
50
126
|
}
|
|
51
127
|
/** Delete every rebuildable source snapshot for this store. */
|
|
52
128
|
export function cleanPluginCache(pluginsDir) {
|
|
53
129
|
rmSync(pluginCacheRoot(pluginsDir), { recursive: true, force: true });
|
|
130
|
+
rmSync(legacyPluginCacheRoot(pluginsDir), { recursive: true, force: true });
|
|
54
131
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { basename, join, resolve } from "node:path";
|
|
4
|
+
import { findManifestFile, readManifest } from "../manifest.js";
|
|
5
|
+
import { resolveDefaultDsl } from "../default-dsl.js";
|
|
6
|
+
import { pluginContents } from "../components.js";
|
|
7
|
+
import { cloneGitHub, githubRepositoryDescription, parseSource } from "../sources.js";
|
|
8
|
+
/** Read-only definition resolution for a local plugin root. */
|
|
9
|
+
export function inspectPlugin(root, metadata) {
|
|
10
|
+
const dir = resolve(root);
|
|
11
|
+
const file = findManifestFile(dir);
|
|
12
|
+
const manifest = file
|
|
13
|
+
? readManifest(dir)
|
|
14
|
+
: resolveDefaultDsl(dir, metadata ?? { name: basename(dir), description: basename(dir) }).manifest;
|
|
15
|
+
const contents = pluginContents(dir, manifest);
|
|
16
|
+
return { kind: file ? "manifest" : "default-dsl", root: dir, manifest, components: Object.entries(contents).filter(([, v]) => v.length > 0).map(([k]) => k) };
|
|
17
|
+
}
|
|
18
|
+
/** Resolve a local or GitHub source without creating a store, lock, or projection. */
|
|
19
|
+
export async function inspectSource(opts) {
|
|
20
|
+
const parsed = parseSource(opts.spec);
|
|
21
|
+
if (parsed.kind === "local") {
|
|
22
|
+
return inspectPlugin(parsed.dir);
|
|
23
|
+
}
|
|
24
|
+
if (parsed.path)
|
|
25
|
+
throw new Error("GitHub subdirectory sources are not supported; define a marketplace and select with --plugin or --all");
|
|
26
|
+
const staging = mkdtempSync(join(tmpdir(), "adg-inspect-"));
|
|
27
|
+
try {
|
|
28
|
+
cloneGitHub({ ...parsed, ref: opts.ref ?? parsed.ref }, staging, { runner: opts.gitRunner });
|
|
29
|
+
const manifestFile = findManifestFile(staging);
|
|
30
|
+
const description = manifestFile
|
|
31
|
+
? undefined
|
|
32
|
+
: await (opts.descriptionResolver ?? githubRepositoryDescription)(parsed.source);
|
|
33
|
+
const result = inspectPlugin(staging, manifestFile
|
|
34
|
+
? undefined
|
|
35
|
+
: { name: parsed.source, description: description ?? parsed.source });
|
|
36
|
+
return { ...result, root: "." };
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
rmSync(staging, { recursive: true, force: true });
|
|
40
|
+
}
|
|
41
|
+
}
|