@rbbtsn0w/adg 0.6.0-beta.5 → 0.6.0-beta.7
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/dist/src/adapters/codex.js +12 -0
- package/dist/src/agents/codex.js +37 -6
- package/dist/src/cli/handlers.js +10 -2
- package/dist/src/cli/index.js +3 -0
- package/dist/src/codex-marketplace-migration.js +139 -0
- package/dist/src/commands/cache.js +92 -15
- package/dist/src/commands/install.js +5 -1
- package/dist/src/commands/link.js +1 -0
- package/dist/src/commands/migrate.js +13 -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/lock.js +16 -2
- package/dist/src/paths.js +31 -4
- package/dist/src/source-cache.js +140 -0
- package/dist/src/sources.js +27 -3
- package/dist/src/types.js +1 -1
- package/docs/agents-spec.md +5 -3
- package/docs/authoring.md +2 -2
- package/package.json +4 -2
- package/schemas/adg-plugin.schema.json +1 -0
- package/schemas/plugin-lock.schema.json +5 -1
|
@@ -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,11 +1,15 @@
|
|
|
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";
|
|
12
|
+
const MARKETPLACE = "adg";
|
|
9
13
|
/**
|
|
10
14
|
* Codex agent.
|
|
11
15
|
*
|
|
@@ -19,16 +23,16 @@ function codexHome(env) {
|
|
|
19
23
|
}
|
|
20
24
|
const { available, run } = makeCli("codex", { probeArgs: ["plugin", "--help"] });
|
|
21
25
|
/**
|
|
22
|
-
* Codex's
|
|
23
|
-
* and explicit stores get a store-scoped name to avoid colliding with
|
|
24
|
-
* or another project's configured marketplace.
|
|
26
|
+
* Keep Codex's global marketplace identity aligned with the Claude projection.
|
|
27
|
+
* Project and explicit stores get a store-scoped name to avoid colliding with
|
|
28
|
+
* the global store or another project's configured marketplace.
|
|
25
29
|
*/
|
|
26
30
|
export function codexMarketplaceName(pluginsDir) {
|
|
27
31
|
const normalized = resolve(pluginsDir);
|
|
28
32
|
if (normalized === resolve(globalPluginsDir()))
|
|
29
|
-
return
|
|
33
|
+
return MARKETPLACE;
|
|
30
34
|
const hash = createHash("sha1").update(normalized.split("\\").join("/")).digest("hex").slice(0, 8);
|
|
31
|
-
return
|
|
35
|
+
return `${MARKETPLACE}-${hash}`;
|
|
32
36
|
}
|
|
33
37
|
/** Ensure the generated Codex marketplace export uses this store's scoped name. */
|
|
34
38
|
export function writeCodexMarketplaceName(pluginsDir) {
|
|
@@ -52,6 +56,31 @@ export function syncMarketplace(pluginsDir, marketplace, runner = run, warn = co
|
|
|
52
56
|
warn(`failed to sync Codex marketplace (${marketplace}): ${upgraded.out.trim() || add.out.trim() || "codex plugin marketplace sync failed without an error message"}`);
|
|
53
57
|
}
|
|
54
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
|
+
}
|
|
55
84
|
export const codexAgent = {
|
|
56
85
|
id: "codex",
|
|
57
86
|
displayName: "Codex",
|
|
@@ -68,6 +97,8 @@ export const codexAgent = {
|
|
|
68
97
|
if (run(["plugin", "add", `${p}@${mp}`]).ok)
|
|
69
98
|
affected.push(p);
|
|
70
99
|
}
|
|
100
|
+
if (ctx.reconcileLegacyAliases && affected.length > 0)
|
|
101
|
+
reconcileLegacyAliases(ctx.pluginsDir, mp, affected);
|
|
71
102
|
return { agent: "codex", affected, skipped: false };
|
|
72
103
|
},
|
|
73
104
|
deactivate(ctx) {
|
package/dist/src/cli/handlers.js
CHANGED
|
@@ -12,7 +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
|
+
import { cleanPluginCache, pluginCacheStatus, prunePluginCache, restorePluginCache } from "../commands/cache.js";
|
|
16
16
|
import { marketplaceList, marketplaceRemove, marketplaceSync, updatePlugins } from "../commands/marketplace.js";
|
|
17
17
|
import { initScaffold } from "../commands/init.js";
|
|
18
18
|
import { confirmFullInstall, selectComponentsInteractive } from "../commands/select-components.js";
|
|
@@ -601,7 +601,8 @@ async function runCache(args) {
|
|
|
601
601
|
if (status.entries.length === 0)
|
|
602
602
|
console.log(ui.meta("cache is empty"));
|
|
603
603
|
for (const entry of status.entries) {
|
|
604
|
-
|
|
604
|
+
const label = entry.orphan ? ui.warn("orphan") : entry.recovery === "present" ? ui.ok("cached") : ui.warn(entry.recovery ?? "cached");
|
|
605
|
+
console.log(`${label} ${ui.name(entry.name)} ${ui.meta(`${entry.bytes} bytes`)}`);
|
|
605
606
|
}
|
|
606
607
|
console.log(ui.meta(`total: ${status.totalBytes} bytes`));
|
|
607
608
|
return;
|
|
@@ -622,5 +623,12 @@ async function runCache(args) {
|
|
|
622
623
|
console.log(ui.ok("cache cleaned"));
|
|
623
624
|
return;
|
|
624
625
|
}
|
|
626
|
+
if (sub === "restore") {
|
|
627
|
+
const { values, positionals } = parseVerb("cache", [...SCOPE], rest);
|
|
628
|
+
const scope = await resolveActionScope(values, "cache restore");
|
|
629
|
+
const restored = restorePluginCache(scope.pluginsDir, positionals);
|
|
630
|
+
console.log(restored.length > 0 ? `${ui.ok("restored")} ${restored.join(", ")}` : ui.meta("no source snapshots to restore"));
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
625
633
|
fail(`unknown cache subcommand: ${sub}`);
|
|
626
634
|
}
|
package/dist/src/cli/index.js
CHANGED
|
@@ -227,6 +227,9 @@ Commands:
|
|
|
227
227
|
Show cached snapshots, byte sizes, and orphan state.
|
|
228
228
|
adg plugins cache prune [--global | --project | --dir <dir>]
|
|
229
229
|
Delete snapshots that have no corresponding lock entry.
|
|
230
|
+
adg plugins cache restore [name...] [--global | --project | --dir <dir>]
|
|
231
|
+
Restore missing snapshots from a verified legacy cache, local source, or
|
|
232
|
+
the exact remote revision recorded in the lock.
|
|
230
233
|
adg plugins cache clean --force [--global | --project | --dir <dir>]
|
|
231
234
|
Delete every source snapshot for the selected store. A later update or
|
|
232
235
|
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
|
}
|
|
@@ -15,7 +15,7 @@ import { ADG_MANIFEST_PATH, readManifest } from "../manifest.js";
|
|
|
15
15
|
import { recordTelemetryEvent } from "../telemetry.js";
|
|
16
16
|
import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../marketplace.js";
|
|
17
17
|
import { resolveInstallOrder } from "../deps.js";
|
|
18
|
-
import { cloneGitHub, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
|
|
18
|
+
import { cloneGitHub, gitRevision, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
|
|
19
19
|
import { normalizePluginSelection, pluginState, resolveSelectionDependencies, sameSource, COMPONENT_TYPES } from "../types.js";
|
|
20
20
|
import { pluginContents, presentComponents } from "../components.js";
|
|
21
21
|
import { skillDescriptionLoader } from "../skills.js";
|
|
@@ -117,6 +117,7 @@ export function installPlugin(opts) {
|
|
|
117
117
|
version: manifest.version,
|
|
118
118
|
sourceHash,
|
|
119
119
|
installedHash,
|
|
120
|
+
...(opts.resolvedRevision ? { resolvedRevision: opts.resolvedRevision } : {}),
|
|
120
121
|
};
|
|
121
122
|
if (manifest.dependencies?.length) {
|
|
122
123
|
entry.dependencies = Object.fromEntries(manifest.dependencies.map((d) => [d.name, d.version]));
|
|
@@ -320,6 +321,7 @@ export async function addPlugins(opts) {
|
|
|
320
321
|
const path = opts.path ?? inferredPath;
|
|
321
322
|
let workRoot;
|
|
322
323
|
let buildOrigin;
|
|
324
|
+
let resolvedRevision;
|
|
323
325
|
let cleanup;
|
|
324
326
|
if (parsed.kind === "local") {
|
|
325
327
|
workRoot = resolve(parsed.dir);
|
|
@@ -330,6 +332,7 @@ export async function addPlugins(opts) {
|
|
|
330
332
|
cleanup = () => rmSync(tmp, { recursive: true, force: true });
|
|
331
333
|
cloneGitHub({ ...parsed, ref: sourceRef }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
|
|
332
334
|
workRoot = tmp;
|
|
335
|
+
resolvedRevision = gitRevision(tmp);
|
|
333
336
|
buildOrigin = (dir) => ({
|
|
334
337
|
type: "github",
|
|
335
338
|
repo: parsed.source,
|
|
@@ -382,6 +385,7 @@ export async function addPlugins(opts) {
|
|
|
382
385
|
source: candidate.dir,
|
|
383
386
|
pluginsDir: opts.pluginsDir,
|
|
384
387
|
origin: buildOrigin(candidate.dir),
|
|
388
|
+
resolvedRevision,
|
|
385
389
|
marketplaceName: opts.marketplaceName,
|
|
386
390
|
targets,
|
|
387
391
|
selection: selections.get(name),
|
|
@@ -27,6 +27,7 @@ export function linkPlugins(opts) {
|
|
|
27
27
|
pluginsDir: opts.pluginsDir,
|
|
28
28
|
plugins: actions.map((a) => a.name),
|
|
29
29
|
scope: opts.global ? "user" : "project",
|
|
30
|
+
...(opts.target === "codex" ? { reconcileLegacyAliases: true } : {}),
|
|
30
31
|
});
|
|
31
32
|
for (const a of actions)
|
|
32
33
|
if (res.affected.includes(a.name))
|
|
@@ -20,7 +20,7 @@ import { LOCK_VERSION, normalizePluginSelection, resolveSelectionDependencies }
|
|
|
20
20
|
* plugins already at their target path are reported as unchanged.
|
|
21
21
|
*/
|
|
22
22
|
export function migrateLayout(pluginsDir, telemetrySpan) {
|
|
23
|
-
const lockUpgraded =
|
|
23
|
+
const lockUpgraded = migrateLock(pluginsDir, telemetrySpan);
|
|
24
24
|
const lock = readLock(lockPath(pluginsDir), telemetrySpan);
|
|
25
25
|
const moved = [];
|
|
26
26
|
const unchanged = [];
|
|
@@ -61,15 +61,25 @@ export function migrateLayout(pluginsDir, telemetrySpan) {
|
|
|
61
61
|
* selection-aware materialization, so unselected payload remains recoverable.
|
|
62
62
|
* The v3 lock is written only after every plugin has been converted.
|
|
63
63
|
*/
|
|
64
|
-
function
|
|
64
|
+
function migrateLock(pluginsDir, telemetrySpan) {
|
|
65
65
|
const file = lockPath(pluginsDir);
|
|
66
66
|
if (!existsSync(file))
|
|
67
67
|
return false;
|
|
68
68
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
69
|
+
if (!raw || typeof raw !== "object")
|
|
70
|
+
throw new Error(`${file} is not a valid lock file`);
|
|
69
71
|
if (raw.version === LOCK_VERSION)
|
|
70
72
|
return false;
|
|
71
73
|
if (typeof raw?.version === "number") {
|
|
72
|
-
recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 ?
|
|
74
|
+
recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 || raw.version === 3 ? raw.version : -1 }, telemetrySpan);
|
|
75
|
+
}
|
|
76
|
+
if (raw.version === 3 && typeof raw.plugins === "object" && raw.plugins !== null) {
|
|
77
|
+
// v3 has the same payload model; v4 adds optional immutable provenance.
|
|
78
|
+
// Existing remote entries remain explicitly legacy until an update/add
|
|
79
|
+
// resolves their commit, rather than inventing a moving ref as a revision.
|
|
80
|
+
writeLock(file, { ...raw, version: LOCK_VERSION });
|
|
81
|
+
recordTelemetryEvent("adg.lock.migrate", { "from.version": 3, "to.version": LOCK_VERSION }, telemetrySpan);
|
|
82
|
+
return true;
|
|
73
83
|
}
|
|
74
84
|
if (raw.version !== 2 || typeof raw.plugins !== "object" || raw.plugins === null) {
|
|
75
85
|
throw new Error(`${file} uses unsupported lock version ${raw.version}; expected ${LOCK_VERSION}`);
|
|
@@ -2,7 +2,7 @@ import { listPlugins } from "./list.js";
|
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
4
4
|
import { installPlugin } from "./install.js";
|
|
5
|
-
import {
|
|
5
|
+
import { resolvePluginSourceSnapshot } from "../source-cache.js";
|
|
6
6
|
/**
|
|
7
7
|
* Shared selection for the projection verbs (link / unlink / sync). Resolve which
|
|
8
8
|
* installed plugins to act on: the named subset (validated against the store), or
|
|
@@ -38,9 +38,10 @@ export function adaptedFilesForTarget(installedTo, files, target) {
|
|
|
38
38
|
/** Rebuild runtime projections for installed plugins from their cached ADG source. */
|
|
39
39
|
export function rematerializeInstalled(pluginsDir, plugins) {
|
|
40
40
|
return plugins.map((plugin) => installPlugin({
|
|
41
|
-
source:
|
|
41
|
+
source: resolvePluginSourceSnapshot(pluginsDir, plugin.name, plugin),
|
|
42
42
|
pluginsDir,
|
|
43
43
|
origin: plugin.origin,
|
|
44
|
+
resolvedRevision: plugin.resolvedRevision,
|
|
44
45
|
selection: plugin.selection,
|
|
45
46
|
targets: [...ADAPTER_TARGETS],
|
|
46
47
|
forceMaterialize: true,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { listPlugins } from "./list.js";
|
|
2
2
|
import { agentsForComponents, resolveAgents } from "../agents/index.js";
|
|
3
|
-
import { lockPath
|
|
3
|
+
import { lockPath } from "../paths.js";
|
|
4
|
+
import { resolvePluginSourceSnapshot } from "../source-cache.js";
|
|
4
5
|
import { readLock, writeLock } from "../lock.js";
|
|
5
6
|
import { pluginState } from "../types.js";
|
|
6
7
|
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
@@ -66,9 +67,10 @@ export function enablePlugins(opts) {
|
|
|
66
67
|
for (const name of changed) {
|
|
67
68
|
const entry = lock.plugins[name];
|
|
68
69
|
installPlugin({
|
|
69
|
-
source:
|
|
70
|
+
source: resolvePluginSourceSnapshot(opts.pluginsDir, name, entry),
|
|
70
71
|
pluginsDir: opts.pluginsDir,
|
|
71
72
|
origin: entry.origin,
|
|
73
|
+
resolvedRevision: entry.resolvedRevision,
|
|
72
74
|
selection: entry.selection,
|
|
73
75
|
targets: [...ADAPTER_TARGETS],
|
|
74
76
|
forceMaterialize: true,
|
|
@@ -17,7 +17,12 @@ export function syncPlugins(opts) {
|
|
|
17
17
|
const scope = opts.global ? "user" : "project";
|
|
18
18
|
const parts = [
|
|
19
19
|
...(disabled.length > 0 ? [agent.deactivate({ pluginsDir: opts.pluginsDir, plugins: disabled.map((p) => p.name), scope })] : []),
|
|
20
|
-
...(enabled.length > 0 ? [agent.refresh({
|
|
20
|
+
...(enabled.length > 0 ? [agent.refresh({
|
|
21
|
+
pluginsDir: opts.pluginsDir,
|
|
22
|
+
plugins: enabled.map((p) => p.name),
|
|
23
|
+
scope,
|
|
24
|
+
...(opts.target === "codex" ? { reconcileLegacyAliases: true } : {}),
|
|
25
|
+
})] : []),
|
|
21
26
|
];
|
|
22
27
|
for (const action of actions)
|
|
23
28
|
if (parts.some((part) => part.affected.includes(action.name)))
|
package/dist/src/lock.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { recordTelemetryEvent } from "./telemetry.js";
|
|
3
3
|
import { LOCK_VERSION } from "./types.js";
|
|
4
|
+
/** Compatibility reads are upgraded in memory; record the transition on first successful persistence. */
|
|
5
|
+
const pendingLockMigrations = new WeakMap();
|
|
4
6
|
export function emptyLock() {
|
|
5
7
|
return { version: LOCK_VERSION, plugins: {} };
|
|
6
8
|
}
|
|
@@ -9,20 +11,32 @@ export function readLock(file, telemetrySpan) {
|
|
|
9
11
|
return emptyLock();
|
|
10
12
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
11
13
|
if (typeof raw?.version === "number") {
|
|
12
|
-
const observed = raw.version === 2 || raw.version === LOCK_VERSION ? raw.version : -1;
|
|
14
|
+
const observed = raw.version === 2 || raw.version === 3 || raw.version === LOCK_VERSION ? raw.version : -1;
|
|
13
15
|
recordTelemetryEvent("adg.lock.read", { "format.version": observed }, telemetrySpan);
|
|
14
16
|
}
|
|
15
17
|
if (typeof raw.version !== "number" || typeof raw.plugins !== "object" || raw.plugins === null) {
|
|
16
18
|
throw new Error(`${file} is not a valid .plugin-lock.json`);
|
|
17
19
|
}
|
|
20
|
+
if (raw.version === 3) {
|
|
21
|
+
// Read compatibility for the immediately preceding format keeps runtime
|
|
22
|
+
// adapters working before the user runs the explicit migration command.
|
|
23
|
+
const upgraded = { ...raw, version: LOCK_VERSION };
|
|
24
|
+
pendingLockMigrations.set(upgraded, 3);
|
|
25
|
+
return upgraded;
|
|
26
|
+
}
|
|
18
27
|
if (raw.version !== LOCK_VERSION) {
|
|
19
28
|
throw new Error(`${file} uses unsupported lock version ${raw.version}; expected ${LOCK_VERSION}. ` +
|
|
20
29
|
"Run `adg plugins migrate` with the same scope flag to upgrade it.");
|
|
21
30
|
}
|
|
22
31
|
return raw;
|
|
23
32
|
}
|
|
24
|
-
export function writeLock(file, lock) {
|
|
33
|
+
export function writeLock(file, lock, telemetrySpan) {
|
|
25
34
|
writeFileSync(file, JSON.stringify(lock, null, 2) + "\n");
|
|
35
|
+
const fromVersion = pendingLockMigrations.get(lock);
|
|
36
|
+
if (fromVersion !== undefined) {
|
|
37
|
+
pendingLockMigrations.delete(lock);
|
|
38
|
+
recordTelemetryEvent("adg.lock.migrate", { "from.version": fromVersion, "to.version": LOCK_VERSION }, telemetrySpan);
|
|
39
|
+
}
|
|
26
40
|
}
|
|
27
41
|
/**
|
|
28
42
|
* Remove a plugin entry from the lock. Drops it from `lastSelected` too.
|
package/dist/src/paths.js
CHANGED
|
@@ -55,21 +55,48 @@ export function marketplacePath(pluginsDir) {
|
|
|
55
55
|
/**
|
|
56
56
|
* Internal full-source cache for a plugin store. The runtime-facing
|
|
57
57
|
* `pluginsDir` contains only effective installations; complete source payloads
|
|
58
|
-
* live in the
|
|
58
|
+
* live in the OS-managed cache tree and are never registered with an agent.
|
|
59
59
|
*/
|
|
60
|
-
export function pluginCacheRoot(pluginsDir) {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
export function pluginCacheRoot(pluginsDir, env = process.env, platform = process.platform) {
|
|
61
|
+
return join(systemCacheHome(env, platform), "plugins", pluginStoreId(pluginsDir));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* OS-managed cache home for ADG. `ADG_CACHE_HOME` is intentionally an escape
|
|
65
|
+
* hatch for hermetic CI and tests; normal installations use the platform cache
|
|
66
|
+
* convention rather than the durable `~/.agents` state tree.
|
|
67
|
+
*/
|
|
68
|
+
export function systemCacheHome(env = process.env, platform = process.platform) {
|
|
69
|
+
if (env.ADG_CACHE_HOME)
|
|
70
|
+
return env.ADG_CACHE_HOME;
|
|
71
|
+
if (platform === "darwin")
|
|
72
|
+
return join(homedir(), "Library", "Caches", "adg");
|
|
73
|
+
if (platform === "win32")
|
|
74
|
+
return join(env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "adg");
|
|
75
|
+
return join(env.XDG_CACHE_HOME || join(homedir(), ".cache"), "adg");
|
|
76
|
+
}
|
|
77
|
+
function pluginStoreId(pluginsDir) {
|
|
78
|
+
return createHash("sha1").update(resolve(pluginsDir).split("\\").join("/")).digest("hex").slice(0, 12);
|
|
79
|
+
}
|
|
80
|
+
/** Read-only location used by ADG releases before the system-cache migration. */
|
|
81
|
+
export function legacyPluginCacheRoot(pluginsDir) {
|
|
82
|
+
return join(dirname(pluginsDir), "cache", "plugins", pluginStoreId(pluginsDir));
|
|
63
83
|
}
|
|
64
84
|
/** One replaceable full-source snapshot per installed plugin. */
|
|
65
85
|
export function pluginSourceCacheDir(pluginsDir, name) {
|
|
66
86
|
return join(pluginCacheRoot(pluginsDir), name);
|
|
67
87
|
}
|
|
88
|
+
/** One legacy snapshot path, retained as a read-only migration source. */
|
|
89
|
+
export function legacyPluginSourceCacheDir(pluginsDir, name) {
|
|
90
|
+
return join(legacyPluginCacheRoot(pluginsDir), name);
|
|
91
|
+
}
|
|
68
92
|
/** Resolve a complete payload for rebuilding, falling back to a live local source. */
|
|
69
93
|
export function pluginRematerializationSource(pluginsDir, name, origin) {
|
|
70
94
|
const cache = pluginSourceCacheDir(pluginsDir, name);
|
|
71
95
|
if (existsSync(cache))
|
|
72
96
|
return cache;
|
|
97
|
+
const legacyCache = legacyPluginSourceCacheDir(pluginsDir, name);
|
|
98
|
+
if (existsSync(legacyCache))
|
|
99
|
+
return legacyCache;
|
|
73
100
|
if (origin.type === "local") {
|
|
74
101
|
const localPath = resolve(pluginsDir, origin.path);
|
|
75
102
|
if (existsSync(localPath))
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { folderHash } from "./hash.js";
|
|
5
|
+
import { readManifest } from "./manifest.js";
|
|
6
|
+
import { withPluginSourceCache } from "./materialize.js";
|
|
7
|
+
import { PROJECTION_DIRS, packageFilter } from "./package.js";
|
|
8
|
+
import { legacyPluginSourceCacheDir, pluginSourceCacheDir } from "./paths.js";
|
|
9
|
+
import { recordTelemetryEvent } from "./telemetry.js";
|
|
10
|
+
import { runGit } from "./sources.js";
|
|
11
|
+
class SourceCacheIntegrityError extends Error {
|
|
12
|
+
}
|
|
13
|
+
function sourceHash(dir) {
|
|
14
|
+
const manifest = readManifest(dir);
|
|
15
|
+
return folderHash(dir, PROJECTION_DIRS, packageFilter(manifest, { includeProjections: false }));
|
|
16
|
+
}
|
|
17
|
+
function assertSourceHash(dir, name, expected) {
|
|
18
|
+
if (sourceHash(dir) !== expected) {
|
|
19
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "hash_mismatch" });
|
|
20
|
+
throw new SourceCacheIntegrityError(`source cache integrity mismatch for "${name}"; run \`adg plugins update\` or re-add the plugin`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function recordRecoveryFailure(error) {
|
|
24
|
+
if (!(error instanceof SourceCacheIntegrityError)) {
|
|
25
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "missing_unrecoverable" });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function remoteUrl(entry) {
|
|
29
|
+
if (entry.origin.type === "github")
|
|
30
|
+
return `https://github.com/${entry.origin.repo}.git`;
|
|
31
|
+
if (entry.origin.type === "git")
|
|
32
|
+
return entry.origin.url;
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function restoreExactRemoteSnapshot(pluginsDir, name, entry) {
|
|
36
|
+
const url = remoteUrl(entry);
|
|
37
|
+
if (!url || !entry.resolvedRevision)
|
|
38
|
+
return undefined;
|
|
39
|
+
const temp = mkdtempSync(join(tmpdir(), "adg-cache-restore-"));
|
|
40
|
+
try {
|
|
41
|
+
// Do not check out origin/ref: it is user update intent and can move. Fetch
|
|
42
|
+
// only the exact commit persisted by the v4 lock instead.
|
|
43
|
+
runGit(["-C", temp, "init"]);
|
|
44
|
+
runGit(["-C", temp, "remote", "add", "origin", url]);
|
|
45
|
+
runGit(["-C", temp, "fetch", "--depth", "1", "origin", entry.resolvedRevision]);
|
|
46
|
+
runGit(["-C", temp, "checkout", "--detach", "FETCH_HEAD"]);
|
|
47
|
+
const source = resolve(temp, entry.origin.path || ".");
|
|
48
|
+
const rel = relative(temp, source);
|
|
49
|
+
if (isAbsolute(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
|
|
50
|
+
throw new Error(`locked source path escapes the repository for "${name}"`);
|
|
51
|
+
}
|
|
52
|
+
if (!existsSync(source))
|
|
53
|
+
throw new Error(`locked source path is missing for "${name}"`);
|
|
54
|
+
assertSourceHash(source, name, entry.sourceHash);
|
|
55
|
+
const manifest = readManifest(source);
|
|
56
|
+
return withPluginSourceCache(source, pluginSourceCacheDir(pluginsDir, name), manifest, (snapshot) => {
|
|
57
|
+
assertSourceHash(snapshot, name, entry.sourceHash);
|
|
58
|
+
return snapshot;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
recordRecoveryFailure(error);
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
throw new Error(`cannot restore "${name}" at locked revision ${entry.resolvedRevision}: ${message}`);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
rmSync(temp, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Return a complete source payload for rematerialization. The modern cache is
|
|
72
|
+
* authoritative; a legacy snapshot is adopted only after proving it matches
|
|
73
|
+
* the lock hash. Local origins are likewise accepted only when they still
|
|
74
|
+
* reproduce the locked source hash. Remote entries intentionally never fall
|
|
75
|
+
* back to their moving ref: a missing immutable snapshot is a hard recovery
|
|
76
|
+
* failure until an explicit update/add records a new revision.
|
|
77
|
+
*/
|
|
78
|
+
export function resolvePluginSourceSnapshot(pluginsDir, name, entry) {
|
|
79
|
+
if (!entry || typeof entry !== "object" || !entry.origin || typeof entry.origin !== "object") {
|
|
80
|
+
throw new Error(`Invalid or missing lock entry for "${name}"`);
|
|
81
|
+
}
|
|
82
|
+
const cache = pluginSourceCacheDir(pluginsDir, name);
|
|
83
|
+
if (existsSync(cache)) {
|
|
84
|
+
try {
|
|
85
|
+
assertSourceHash(cache, name, entry.sourceHash);
|
|
86
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "hit" });
|
|
87
|
+
return cache;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
recordRecoveryFailure(error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const legacy = legacyPluginSourceCacheDir(pluginsDir, name);
|
|
95
|
+
if (existsSync(legacy)) {
|
|
96
|
+
try {
|
|
97
|
+
assertSourceHash(legacy, name, entry.sourceHash);
|
|
98
|
+
const manifest = readManifest(legacy);
|
|
99
|
+
const adopted = withPluginSourceCache(legacy, cache, manifest, (snapshot) => {
|
|
100
|
+
assertSourceHash(snapshot, name, entry.sourceHash);
|
|
101
|
+
return snapshot;
|
|
102
|
+
});
|
|
103
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "adopted_legacy" });
|
|
104
|
+
return adopted;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
recordRecoveryFailure(error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (entry.origin.type === "local") {
|
|
112
|
+
const local = resolve(pluginsDir, entry.origin.path);
|
|
113
|
+
if (existsSync(local)) {
|
|
114
|
+
try {
|
|
115
|
+
assertSourceHash(local, name, entry.sourceHash);
|
|
116
|
+
const manifest = readManifest(local);
|
|
117
|
+
const restored = withPluginSourceCache(local, cache, manifest, (snapshot) => {
|
|
118
|
+
assertSourceHash(snapshot, name, entry.sourceHash);
|
|
119
|
+
return snapshot;
|
|
120
|
+
});
|
|
121
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "restored_local" });
|
|
122
|
+
return restored;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
recordRecoveryFailure(error);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const restored = restoreExactRemoteSnapshot(pluginsDir, name, entry);
|
|
131
|
+
if (restored) {
|
|
132
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "restored_remote" });
|
|
133
|
+
return restored;
|
|
134
|
+
}
|
|
135
|
+
recordTelemetryEvent("adg.cache.recovery", { outcome: "missing_unrecoverable" });
|
|
136
|
+
const legacyHint = entry.origin.type === "github" || entry.origin.type === "git"
|
|
137
|
+
? "Remote source recovery requires an immutable revision; run `adg plugins update` or re-add the plugin."
|
|
138
|
+
: "Run `adg plugins update` or re-add the plugin.";
|
|
139
|
+
throw new Error(`source cache missing for "${name}". ${legacyHint}`);
|
|
140
|
+
}
|
package/dist/src/sources.js
CHANGED
|
@@ -91,13 +91,25 @@ export function cloneGitHub(src, dest, opts = {}) {
|
|
|
91
91
|
return dest;
|
|
92
92
|
}
|
|
93
93
|
export const defaultGitRunner = (args) => {
|
|
94
|
+
runGit(args);
|
|
95
|
+
};
|
|
96
|
+
/** Return a low-cardinality, string-safe error type for Git subprocess spans. */
|
|
97
|
+
export function gitErrorType(error, exitCode) {
|
|
98
|
+
const code = error && typeof error === "object" ? error.code : undefined;
|
|
99
|
+
return code === undefined || code === null ? `EXIT_CODE_${exitCode}` : String(code);
|
|
100
|
+
}
|
|
101
|
+
/** Run git under the shared CLI semantic-convention instrumentation. */
|
|
102
|
+
export function runGit(args, captureOutput = false) {
|
|
94
103
|
const tracer = getTracer();
|
|
95
104
|
return tracer.startActiveSpan("git", { kind: SpanKind.CLIENT }, (span) => {
|
|
96
105
|
try {
|
|
97
106
|
span.setAttribute("process.executable.name", "git");
|
|
98
107
|
span.setAttribute("process.command_args", sanitizeArgs(["git", ...args]));
|
|
99
|
-
execFileSync("git", args,
|
|
108
|
+
const output = execFileSync("git", args, captureOutput
|
|
109
|
+
? { stdio: "pipe", encoding: "utf8" }
|
|
110
|
+
: { stdio: "ignore" });
|
|
100
111
|
span.setAttribute("process.exit.code", 0);
|
|
112
|
+
return captureOutput ? String(output).trimEnd() : undefined;
|
|
101
113
|
}
|
|
102
114
|
catch (error) {
|
|
103
115
|
const exitCode = typeof error.status === "number" ? error.status : 1;
|
|
@@ -105,7 +117,7 @@ export const defaultGitRunner = (args) => {
|
|
|
105
117
|
if (typeof error.pid === "number") {
|
|
106
118
|
span.setAttribute("process.pid", error.pid);
|
|
107
119
|
}
|
|
108
|
-
span.setAttribute("error.type", error
|
|
120
|
+
span.setAttribute("error.type", gitErrorType(error, exitCode));
|
|
109
121
|
span.recordException(error);
|
|
110
122
|
span.setStatus({
|
|
111
123
|
code: SpanStatusCode.ERROR,
|
|
@@ -117,7 +129,19 @@ export const defaultGitRunner = (args) => {
|
|
|
117
129
|
span.end();
|
|
118
130
|
}
|
|
119
131
|
});
|
|
120
|
-
}
|
|
132
|
+
}
|
|
133
|
+
;
|
|
134
|
+
/** Resolve the immutable commit checked out in a cloned worktree. */
|
|
135
|
+
export function gitRevision(dir) {
|
|
136
|
+
try {
|
|
137
|
+
return runGit(["-C", dir, "rev-parse", "HEAD"], true) || undefined;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Injected/offline clone runners in tests may materialize a plain directory.
|
|
141
|
+
// Such entries remain legacy until a real update records an immutable commit.
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
121
145
|
/**
|
|
122
146
|
* Recursively find ADG plugins under `root` (directories containing
|
|
123
147
|
* `.agents/.plugin.json`, or the legacy `.adg-plugin/plugin.json`), keyed by
|
package/dist/src/types.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ADG type definitions mirroring the JSON Schemas under ../schemas.
|
|
3
3
|
*/
|
|
4
4
|
export const ADG_SCHEMA_VERSION = "adg.plugin/v1";
|
|
5
|
-
export const LOCK_VERSION =
|
|
5
|
+
export const LOCK_VERSION = 4;
|
|
6
6
|
/** The component categories a plugin can expose. */
|
|
7
7
|
export const COMPONENT_TYPES = ["skills", "agents", "commands", "mcp", "hooks", "apps"];
|
|
8
8
|
/** Canonicalize user intent without adding derived component dependencies. */
|
package/docs/agents-spec.md
CHANGED
|
@@ -102,9 +102,11 @@ The lock records two hashes: `sourceHash` covers the complete cached payload and
|
|
|
102
102
|
`installedHash` covers the effective selection. Runtime projections are excluded
|
|
103
103
|
from both hashes so re-adapting does not churn content identity.
|
|
104
104
|
|
|
105
|
-
The cache is scoped by a stable store id under the
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
The cache is scoped by a stable store id under the OS-managed
|
|
106
|
+
system cache tree (`~/Library/Caches/adg/plugins/` on macOS,
|
|
107
|
+
`$XDG_CACHE_HOME/adg/plugins/` on Linux). `adg plugins cache status` reports
|
|
108
|
+
its contents, `cache restore` recreates missing snapshots from the exact lock
|
|
109
|
+
revision, `cache prune` removes orphan snapshots, and `cache clean --force` removes all
|
|
108
110
|
snapshots. A missing remote snapshot must be restored with `plugins update` or
|
|
109
111
|
`plugins add`; a still-available local source is used directly as fallback.
|
|
110
112
|
|
package/docs/authoring.md
CHANGED
|
@@ -74,7 +74,7 @@ authoring artifact:
|
|
|
74
74
|
"author": { "name": "You", "url": "…", "email": "…" },
|
|
75
75
|
"license": "MIT",
|
|
76
76
|
"category": "Developer Tools",
|
|
77
|
-
"interface": { "displayName": "ASC", "icon": "asc.png" },
|
|
77
|
+
"interface": { "displayName": "ASC", "shortDescription": "Ship App Store releases with asc.", "icon": "asc.png" },
|
|
78
78
|
|
|
79
79
|
// ── Components: path pointers, never inlined content ──
|
|
80
80
|
"skills": "./skills/", // string (root dir) | string[] (explicit paths)
|
|
@@ -108,7 +108,7 @@ authoring artifact:
|
|
|
108
108
|
| `author` | `{ name, url?, email? }` | | |
|
|
109
109
|
| `license` | string | | SPDX id, e.g. `MIT`. |
|
|
110
110
|
| `category` | string | | Free-form, e.g. `Developer Tools`. |
|
|
111
|
-
| `interface` | `{ displayName?, icon? }` | | Presentation
|
|
111
|
+
| `interface` | `{ displayName?, shortDescription?, icon? }` | | Presentation metadata. Codex uses `shortDescription` in its plugin picker; when omitted, ADG uses the manifest `description`. |
|
|
112
112
|
| `skills` | string \| string[] | | Root dir (auto-scan) or explicit skill paths. |
|
|
113
113
|
| `commands` | string | | Directory of slash-command `.md` files. |
|
|
114
114
|
| `agents` | string | | Directory of sub-agent `.md` files. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbbtsn0w/adg",
|
|
3
|
-
"version": "0.6.0-beta.
|
|
3
|
+
"version": "0.6.0-beta.7",
|
|
4
4
|
"description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"adg": "node ./bin/adg.ts",
|
|
26
26
|
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json --noCheck && node -e \"require('fs').chmodSync('dist/bin/adg.js',0o755)\"",
|
|
27
|
-
"test": "node
|
|
27
|
+
"test": "node scripts/run-tests.mjs \"test/**/*.test.ts\" test/cache-sandbox.test.mjs",
|
|
28
|
+
"test:codex-sandbox": "node --test test/codex-sandbox.test.mjs",
|
|
29
|
+
"test:cache-sandbox": "node --test test/cache-sandbox.test.mjs",
|
|
28
30
|
"check:vendor-deps": "node scripts/check-vendor-deps.mjs",
|
|
29
31
|
"audit:prod": "npm audit --omit=dev",
|
|
30
32
|
"typecheck": "tsc --noEmit",
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"required": ["version", "plugins"],
|
|
8
8
|
"additionalProperties": false,
|
|
9
9
|
"properties": {
|
|
10
|
-
"version": { "type": "integer", "description": "Lock file format version.", "
|
|
10
|
+
"version": { "type": "integer", "description": "Lock file format version.", "enum": [3, 4] },
|
|
11
11
|
"plugins": {
|
|
12
12
|
"type": "object",
|
|
13
13
|
"additionalProperties": { "$ref": "#/$defs/lockEntry" }
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"description": "Digest of the complete cached source payload.",
|
|
31
31
|
"pattern": "^[a-z0-9]+-[0-9a-f]+$"
|
|
32
32
|
},
|
|
33
|
+
"resolvedRevision": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "Immutable remote commit that produced the cached source payload."
|
|
36
|
+
},
|
|
33
37
|
"installedHash": {
|
|
34
38
|
"type": "string",
|
|
35
39
|
"description": "Digest of the effective runtime installation.",
|