@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
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { ADG_SCHEMA_VERSION } from "./types.js";
|
|
5
|
+
import { readSkillDescription } from "./skills.js";
|
|
6
|
+
import { recordTelemetryEvent } from "./telemetry.js";
|
|
7
|
+
/** Convert a repository directory name into the manifest's stable kebab-case identity. */
|
|
8
|
+
export function defaultPluginName(value) {
|
|
9
|
+
const normalized = value.trim().replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()
|
|
10
|
+
.replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
11
|
+
if (!normalized)
|
|
12
|
+
throw new Error("default plugin name is empty");
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the intentionally small structural DSL. It only recognizes the three
|
|
17
|
+
* documented default locations; other directories are never guessed as runtime
|
|
18
|
+
* components.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveDefaultDsl(root, metadata, options = {}) {
|
|
21
|
+
const { components, manifest: componentManifest } = probeDefaultDsl(root, options);
|
|
22
|
+
const hasSkills = components.includes("skills");
|
|
23
|
+
const hasHooks = components.includes("hooks");
|
|
24
|
+
const hasMcp = components.includes("mcp");
|
|
25
|
+
const skillsRoot = join(root, "skills");
|
|
26
|
+
const mcpFile = join(root, ".mcp.json");
|
|
27
|
+
const hasher = createHash("sha256").update(JSON.stringify({ name: defaultPluginName(metadata.name), components }));
|
|
28
|
+
if (hasSkills)
|
|
29
|
+
hashTree(hasher, skillsRoot, "skills");
|
|
30
|
+
if (hasHooks)
|
|
31
|
+
hashTree(hasher, join(root, "hooks"), "hooks");
|
|
32
|
+
if (hasMcp)
|
|
33
|
+
hasher.update(".mcp.json\0").update(readFileSync(mcpFile)).update("\0");
|
|
34
|
+
const fingerprint = hasher.digest("hex");
|
|
35
|
+
if (options.recordTelemetry !== false) {
|
|
36
|
+
recordTelemetryEvent("adg.default_dsl.resolve", {
|
|
37
|
+
"definition.kind": "default-dsl/v1",
|
|
38
|
+
"components.count": components.length,
|
|
39
|
+
outcome: "success",
|
|
40
|
+
}, options.telemetrySpan);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
components,
|
|
44
|
+
fingerprint,
|
|
45
|
+
manifest: {
|
|
46
|
+
schemaVersion: ADG_SCHEMA_VERSION,
|
|
47
|
+
name: defaultPluginName(metadata.name),
|
|
48
|
+
version: `0.0.0-adg.${fingerprint}`,
|
|
49
|
+
description: metadata.description,
|
|
50
|
+
...componentManifest,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Discover and validate conventional component locations without hashing payload contents. */
|
|
55
|
+
export function probeDefaultDsl(root, options = {}) {
|
|
56
|
+
const ignore = options.ignore ?? new Set();
|
|
57
|
+
const skillsRoot = join(root, "skills");
|
|
58
|
+
const skillFiles = !ignore.has("skills") && isDirectory(skillsRoot)
|
|
59
|
+
? readdirSync(skillsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(join(skillsRoot, entry.name, "SKILL.md"))).map((entry) => join(skillsRoot, entry.name, "SKILL.md"))
|
|
60
|
+
: [];
|
|
61
|
+
const invalidSkillFile = skillFiles.find((file) => !isRegularFile(file));
|
|
62
|
+
if (invalidSkillFile)
|
|
63
|
+
throw new Error(`invalid default skill file (must be a regular file): ${invalidSkillFile}`);
|
|
64
|
+
const invalidSkill = skillFiles.find((file) => !readSkillDescription(file));
|
|
65
|
+
if (invalidSkill)
|
|
66
|
+
throw new Error(`default skill requires SKILL.md frontmatter with a description: ${invalidSkill}`);
|
|
67
|
+
const hasSkills = skillFiles.length > 0;
|
|
68
|
+
const hooksFile = join(root, "hooks", "hooks.json");
|
|
69
|
+
const hasHooks = !ignore.has("hooks") && existsSync(hooksFile) && validJson(hooksFile);
|
|
70
|
+
if (!ignore.has("hooks") && existsSync(hooksFile) && !hasHooks)
|
|
71
|
+
throw new Error(`invalid default hooks configuration: ${hooksFile}`);
|
|
72
|
+
const mcpFile = join(root, ".mcp.json");
|
|
73
|
+
const hasMcp = !ignore.has("mcp") && existsSync(mcpFile) && validMcp(mcpFile);
|
|
74
|
+
if (!ignore.has("mcp") && existsSync(mcpFile) && !hasMcp)
|
|
75
|
+
throw new Error(`invalid default MCP configuration: ${mcpFile}`);
|
|
76
|
+
const components = [
|
|
77
|
+
...(hasSkills ? ["skills"] : []),
|
|
78
|
+
...(hasHooks ? ["hooks"] : []),
|
|
79
|
+
...(hasMcp ? ["mcp"] : []),
|
|
80
|
+
];
|
|
81
|
+
if (components.length === 0)
|
|
82
|
+
throw new Error(`no default plugin component found in ${root}`);
|
|
83
|
+
return {
|
|
84
|
+
components,
|
|
85
|
+
manifest: {
|
|
86
|
+
...(hasSkills ? { skills: "./skills/" } : { skills: [] }),
|
|
87
|
+
...(hasHooks ? { hooks: "./hooks/" } : {}),
|
|
88
|
+
...(hasMcp ? { mcpServers: "./.mcp.json" } : {}),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function validJson(file) {
|
|
93
|
+
if (!isRegularFile(file))
|
|
94
|
+
return false;
|
|
95
|
+
try {
|
|
96
|
+
JSON.parse(readFileSync(file, "utf8"));
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function isDirectory(path) {
|
|
104
|
+
try {
|
|
105
|
+
return lstatSync(path).isDirectory();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function isRegularFile(path) {
|
|
112
|
+
try {
|
|
113
|
+
return lstatSync(path).isFile();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function validMcp(file) {
|
|
120
|
+
if (!validJson(file))
|
|
121
|
+
return false;
|
|
122
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
123
|
+
if (json === null || typeof json !== "object" || Array.isArray(json))
|
|
124
|
+
return false;
|
|
125
|
+
const servers = json.mcpServers ?? json.servers;
|
|
126
|
+
return typeof servers === "object" && servers !== null && !Array.isArray(servers);
|
|
127
|
+
}
|
|
128
|
+
function hashTree(hasher, dir, rel) {
|
|
129
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
130
|
+
const child = join(dir, entry.name);
|
|
131
|
+
const childRel = `${rel}/${entry.name}`;
|
|
132
|
+
const stat = lstatSync(child);
|
|
133
|
+
if (stat.isSymbolicLink())
|
|
134
|
+
throw new Error(`default plugin component must not contain symlinks: ${child}`);
|
|
135
|
+
if (stat.isDirectory())
|
|
136
|
+
hashTree(hasher, child, childRel);
|
|
137
|
+
else if (stat.isFile())
|
|
138
|
+
hasher.update(childRel).update("\0").update(readFileSync(child)).update("\0");
|
|
139
|
+
}
|
|
140
|
+
}
|
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
|
}
|
|
@@ -8,21 +10,37 @@ export function readLock(file, telemetrySpan) {
|
|
|
8
10
|
if (!existsSync(file))
|
|
9
11
|
return emptyLock();
|
|
10
12
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
11
|
-
if (typeof raw
|
|
12
|
-
|
|
13
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
14
|
+
throw new Error(`${file} is not a valid .plugin-lock.json`);
|
|
15
|
+
}
|
|
16
|
+
const parsed = raw;
|
|
17
|
+
if (typeof parsed.version === "number") {
|
|
18
|
+
const observed = parsed.version === 2 || parsed.version === 3 || parsed.version === 4 || parsed.version === LOCK_VERSION ? parsed.version : -1;
|
|
13
19
|
recordTelemetryEvent("adg.lock.read", { "format.version": observed }, telemetrySpan);
|
|
14
20
|
}
|
|
15
|
-
if (typeof
|
|
21
|
+
if (typeof parsed.version !== "number" || typeof parsed.plugins !== "object" || parsed.plugins === null || Array.isArray(parsed.plugins)) {
|
|
16
22
|
throw new Error(`${file} is not a valid .plugin-lock.json`);
|
|
17
23
|
}
|
|
18
|
-
if (
|
|
19
|
-
|
|
24
|
+
if (parsed.version === 3 || parsed.version === 4) {
|
|
25
|
+
// Read compatibility for the retained v3 and v4 formats keeps runtime
|
|
26
|
+
// adapters working before the user runs the explicit migration command.
|
|
27
|
+
const upgraded = { ...parsed, version: LOCK_VERSION };
|
|
28
|
+
pendingLockMigrations.set(upgraded, parsed.version);
|
|
29
|
+
return upgraded;
|
|
30
|
+
}
|
|
31
|
+
if (parsed.version !== LOCK_VERSION) {
|
|
32
|
+
throw new Error(`${file} uses unsupported lock version ${parsed.version}; expected ${LOCK_VERSION}. ` +
|
|
20
33
|
"Run `adg plugins migrate` with the same scope flag to upgrade it.");
|
|
21
34
|
}
|
|
22
|
-
return
|
|
35
|
+
return parsed;
|
|
23
36
|
}
|
|
24
|
-
export function writeLock(file, lock) {
|
|
37
|
+
export function writeLock(file, lock, telemetrySpan) {
|
|
25
38
|
writeFileSync(file, JSON.stringify(lock, null, 2) + "\n");
|
|
39
|
+
const fromVersion = pendingLockMigrations.get(lock);
|
|
40
|
+
if (fromVersion !== undefined) {
|
|
41
|
+
pendingLockMigrations.delete(lock);
|
|
42
|
+
recordTelemetryEvent("adg.lock.migrate", { "from.version": fromVersion, "to.version": LOCK_VERSION }, telemetrySpan);
|
|
43
|
+
}
|
|
26
44
|
}
|
|
27
45
|
/**
|
|
28
46
|
* Remove a plugin entry from the lock. Drops it from `lastSelected` too.
|
package/dist/src/manifest.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { isAbsolute, join } from "node:path";
|
|
3
3
|
import { ADG_SCHEMA_VERSION, COMPONENT_TYPES } from "./types.js";
|
|
4
4
|
import { recordTelemetryEvent } from "./telemetry.js";
|
|
5
|
+
import { probeDefaultDsl } from "./default-dsl.js";
|
|
5
6
|
/** Canonical, vendor-neutral source manifest location (a plugin). */
|
|
6
7
|
export const ADG_MANIFEST_PATH = join(".agents", ".plugin.json");
|
|
7
8
|
/** Canonical, vendor-neutral source catalog location (a marketplace). */
|
|
@@ -47,8 +48,31 @@ export function readManifest(pluginDir, telemetrySpan) {
|
|
|
47
48
|
}
|
|
48
49
|
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
49
50
|
const m = raw;
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
// A repository manifest is an explicit mapping only for fields it names.
|
|
52
|
+
// Standard skills/hooks/MCP locations remain the default DSL for omitted
|
|
53
|
+
// component fields, keeping source authors from repeating boilerplate.
|
|
54
|
+
if (typeof m.name === "string" && typeof m.description === "string") {
|
|
55
|
+
try {
|
|
56
|
+
const ignored = new Set();
|
|
57
|
+
if (m.skills !== undefined)
|
|
58
|
+
ignored.add("skills");
|
|
59
|
+
if (m.hooks !== undefined)
|
|
60
|
+
ignored.add("hooks");
|
|
61
|
+
if (m.mcpServers !== undefined)
|
|
62
|
+
ignored.add("mcp");
|
|
63
|
+
const defaults = probeDefaultDsl(pluginDir, { ignore: ignored }).manifest;
|
|
64
|
+
for (const key of ["skills", "hooks", "mcpServers"]) {
|
|
65
|
+
if (m[key] === undefined && defaults[key] !== undefined)
|
|
66
|
+
m[key] = defaults[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// A manifest may use entirely custom locations and therefore have no
|
|
71
|
+
// conventional component. Any malformed conventional component that it
|
|
72
|
+
// *inherits*, however, is a source error and must never be hidden.
|
|
73
|
+
if (!(error instanceof Error) || !error.message.includes("no default plugin component"))
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
52
76
|
}
|
|
53
77
|
const schemaVersion = m.schemaVersion;
|
|
54
78
|
if (typeof schemaVersion === "string") {
|
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
|
@@ -4,6 +4,22 @@ import { join } from "node:path";
|
|
|
4
4
|
import { readManifest, findManifestFile } from "./manifest.js";
|
|
5
5
|
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
6
6
|
import { getTracer, sanitizeArgs } from "./telemetry.js";
|
|
7
|
+
/** Best-effort repository About lookup. Callers must retain their deterministic fallback on failure. */
|
|
8
|
+
export async function githubRepositoryDescription(repo) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(`https://api.github.com/repos/${repo.split("/").map(encodeURIComponent).join("/")}`, {
|
|
11
|
+
headers: { Accept: "application/vnd.github+json", "User-Agent": "adg-cli" },
|
|
12
|
+
signal: AbortSignal.timeout(3000),
|
|
13
|
+
});
|
|
14
|
+
if (!response.ok)
|
|
15
|
+
return undefined;
|
|
16
|
+
const body = await response.json();
|
|
17
|
+
return typeof body.description === "string" && body.description.trim() ? body.description.trim() : undefined;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
7
23
|
const GH_SHORTHAND = /^([\w.-]+)\/([\w.-]+?)(?:@(.+))?$/;
|
|
8
24
|
const GH_URL = /^(?:https?:\/\/github\.com\/|git@github\.com:)([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:@(.+))?$/;
|
|
9
25
|
const GH_BLOB_URL = /^(?:https?:\/\/github\.com\/)([\w.-]+)\/([\w.-]+?)(?:\.git)?\/(?:blob|tree)\/([^/]+)\/(.+)$/;
|
|
@@ -40,6 +56,15 @@ function decodeGitHubUrlPart(value) {
|
|
|
40
56
|
export function parseSource(spec) {
|
|
41
57
|
if (existsSync(spec))
|
|
42
58
|
return { kind: "local", dir: spec };
|
|
59
|
+
try {
|
|
60
|
+
return parseGitHubSource(spec);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Error(`cannot parse install source: "${spec}" (expected a local path, owner/repo[@ref], or a github.com URL)`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Parse a GitHub source without allowing an existing CWD path to override it. */
|
|
67
|
+
export function parseGitHubSource(spec) {
|
|
43
68
|
const clean = spec.replace(/[?#].*$/, "");
|
|
44
69
|
const blob = clean.match(GH_BLOB_URL);
|
|
45
70
|
if (blob) {
|
|
@@ -58,7 +83,7 @@ export function parseSource(spec) {
|
|
|
58
83
|
const [, owner, repo, ref] = short;
|
|
59
84
|
return gh(owner, repo, ref);
|
|
60
85
|
}
|
|
61
|
-
throw new Error(`cannot parse
|
|
86
|
+
throw new Error(`cannot parse GitHub source: "${spec}" (expected owner/repo[@ref] or a github.com URL)`);
|
|
62
87
|
}
|
|
63
88
|
function gh(owner, repo, ref) {
|
|
64
89
|
return {
|
|
@@ -91,13 +116,25 @@ export function cloneGitHub(src, dest, opts = {}) {
|
|
|
91
116
|
return dest;
|
|
92
117
|
}
|
|
93
118
|
export const defaultGitRunner = (args) => {
|
|
119
|
+
runGit(args);
|
|
120
|
+
};
|
|
121
|
+
/** Return a low-cardinality, string-safe error type for Git subprocess spans. */
|
|
122
|
+
export function gitErrorType(error, exitCode) {
|
|
123
|
+
const code = error && typeof error === "object" ? error.code : undefined;
|
|
124
|
+
return code === undefined || code === null ? `EXIT_CODE_${exitCode}` : String(code);
|
|
125
|
+
}
|
|
126
|
+
/** Run git under the shared CLI semantic-convention instrumentation. */
|
|
127
|
+
export function runGit(args, captureOutput = false) {
|
|
94
128
|
const tracer = getTracer();
|
|
95
129
|
return tracer.startActiveSpan("git", { kind: SpanKind.CLIENT }, (span) => {
|
|
96
130
|
try {
|
|
97
131
|
span.setAttribute("process.executable.name", "git");
|
|
98
132
|
span.setAttribute("process.command_args", sanitizeArgs(["git", ...args]));
|
|
99
|
-
execFileSync("git", args,
|
|
133
|
+
const output = execFileSync("git", args, captureOutput
|
|
134
|
+
? { stdio: "pipe", encoding: "utf8" }
|
|
135
|
+
: { stdio: "ignore" });
|
|
100
136
|
span.setAttribute("process.exit.code", 0);
|
|
137
|
+
return captureOutput ? String(output).trimEnd() : undefined;
|
|
101
138
|
}
|
|
102
139
|
catch (error) {
|
|
103
140
|
const exitCode = typeof error.status === "number" ? error.status : 1;
|
|
@@ -105,7 +142,7 @@ export const defaultGitRunner = (args) => {
|
|
|
105
142
|
if (typeof error.pid === "number") {
|
|
106
143
|
span.setAttribute("process.pid", error.pid);
|
|
107
144
|
}
|
|
108
|
-
span.setAttribute("error.type", error
|
|
145
|
+
span.setAttribute("error.type", gitErrorType(error, exitCode));
|
|
109
146
|
span.recordException(error);
|
|
110
147
|
span.setStatus({
|
|
111
148
|
code: SpanStatusCode.ERROR,
|
|
@@ -117,7 +154,41 @@ export const defaultGitRunner = (args) => {
|
|
|
117
154
|
span.end();
|
|
118
155
|
}
|
|
119
156
|
});
|
|
120
|
-
}
|
|
157
|
+
}
|
|
158
|
+
;
|
|
159
|
+
/** Resolve the immutable commit checked out in a cloned worktree. */
|
|
160
|
+
export function gitRevision(dir) {
|
|
161
|
+
try {
|
|
162
|
+
return runGit(["-C", dir, "rev-parse", "HEAD"], true) || undefined;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Injected/offline clone runners in tests may materialize a plain directory.
|
|
166
|
+
// Such entries remain legacy until a real update records an immutable commit.
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const GIT_SHA_RE = /^[0-9a-f]{40}$/i;
|
|
171
|
+
/** Extract the commit SHA from `git ls-remote`, preferring an annotated tag's peeled ref. */
|
|
172
|
+
export function parseRemoteRevision(output, ref) {
|
|
173
|
+
if (!output)
|
|
174
|
+
return undefined;
|
|
175
|
+
const rows = output.split(/\r?\n/).map((line) => line.trim().split(/\s+/)).filter(([sha, name]) => GIT_SHA_RE.test(sha ?? "") && name);
|
|
176
|
+
const peeled = ref ? rows.find(([, name]) => name === `refs/tags/${ref}^{}`)?.[0] : undefined;
|
|
177
|
+
return peeled ?? rows[0]?.[0];
|
|
178
|
+
}
|
|
179
|
+
/** Lightweight remote commit probe used to avoid cloning an unchanged source. */
|
|
180
|
+
export function gitRemoteRevision(repo, ref) {
|
|
181
|
+
if (ref && GIT_SHA_RE.test(ref))
|
|
182
|
+
return ref.toLowerCase();
|
|
183
|
+
try {
|
|
184
|
+
const pattern = ref || "HEAD";
|
|
185
|
+
const output = runGit(["ls-remote", `https://github.com/${repo}.git`, pattern, `${pattern}^{}`], true);
|
|
186
|
+
return parseRemoteRevision(output, ref);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
121
192
|
/**
|
|
122
193
|
* Recursively find ADG plugins under `root` (directories containing
|
|
123
194
|
* `.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 = 5;
|
|
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
|
@@ -80,7 +80,28 @@ are ADG-internal conventions, not declared in the manifest.
|
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
83
|
-
## 3.
|
|
83
|
+
## 3. Default directory DSL
|
|
84
|
+
|
|
85
|
+
When `.agents/.plugin.json` is absent, ADG recognizes only these fixed source
|
|
86
|
+
slots: `skills/<name>/SKILL.md`, `hooks/hooks.json`, and `.mcp.json`. At least
|
|
87
|
+
one valid slot is required. A skill needs non-empty frontmatter `description`;
|
|
88
|
+
hooks and MCP files must be valid JSON (MCP must contain an object of servers).
|
|
89
|
+
|
|
90
|
+
An explicit source manifest remains the only customization mechanism. Its
|
|
91
|
+
`skills`, `hooks`, and `mcpServers` fields replace the corresponding default
|
|
92
|
+
slot; omitted fields inherit valid defaults. A malformed inherited default slot
|
|
93
|
+
is an error, while an explicitly overridden slot is not interpreted. `--as` is
|
|
94
|
+
available only for structural sources. `--only` controls both copied payload and
|
|
95
|
+
runtime projection; non-interactive hooks/MCP discovery requires explicit
|
|
96
|
+
`--only`. Default DSL is source-root only.
|
|
97
|
+
|
|
98
|
+
Default DSL is deliberately **not** a monorepo discovery convention. A source
|
|
99
|
+
repository containing multiple plugins must declare every member with its own
|
|
100
|
+
`.agents/.plugin.json` (and may use `.agents/.marketplace.json` as its catalog).
|
|
101
|
+
Consumers select declared members with `--plugin` or `--all`; a source
|
|
102
|
+
subdirectory is never an install/inspect selector.
|
|
103
|
+
|
|
104
|
+
## 4. Packaging — manifest-driven allowlist
|
|
84
105
|
|
|
85
106
|
ADG first stores the complete declared payload in an internal source cache, then
|
|
86
107
|
materializes an **effective installation** into the runtime-facing plugins
|
|
@@ -102,9 +123,11 @@ The lock records two hashes: `sourceHash` covers the complete cached payload and
|
|
|
102
123
|
`installedHash` covers the effective selection. Runtime projections are excluded
|
|
103
124
|
from both hashes so re-adapting does not churn content identity.
|
|
104
125
|
|
|
105
|
-
The cache is scoped by a stable store id under the
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
The cache is scoped by a stable store id under the OS-managed
|
|
127
|
+
system cache tree (`~/Library/Caches/adg/plugins/` on macOS,
|
|
128
|
+
`$XDG_CACHE_HOME/adg/plugins/` on Linux). `adg plugins cache status` reports
|
|
129
|
+
its contents, `cache restore` recreates missing snapshots from the exact lock
|
|
130
|
+
revision, `cache prune` removes orphan snapshots, and `cache clean --force` removes all
|
|
108
131
|
snapshots. A missing remote snapshot must be restored with `plugins update` or
|
|
109
132
|
`plugins add`; a still-available local source is used directly as fallback.
|
|
110
133
|
|
package/docs/authoring.md
CHANGED
|
@@ -62,6 +62,23 @@ authoring artifact:
|
|
|
62
62
|
|
|
63
63
|
---
|
|
64
64
|
|
|
65
|
+
## Conventional skills repositories
|
|
66
|
+
|
|
67
|
+
A repository may omit `.agents/.plugin.json` when it follows the fixed Default
|
|
68
|
+
DSL: `skills/<name>/SKILL.md`, `hooks/hooks.json`, and/or `.mcp.json`. ADG
|
|
69
|
+
derives one plugin only from the source root; it does not recursively guess
|
|
70
|
+
other directories.
|
|
71
|
+
|
|
72
|
+
Default DSL is not available to a member directory of a multi-plugin repository.
|
|
73
|
+
For a marketplace, give every member its own `.agents/.plugin.json`; consumers
|
|
74
|
+
select that explicit member with `--plugin` rather than by source subdirectory.
|
|
75
|
+
|
|
76
|
+
Add `.agents/.plugin.json` for non-standard paths or metadata. Its `skills`,
|
|
77
|
+
`hooks`, and `mcpServers` fields replace their respective defaults; omitted
|
|
78
|
+
fields inherit valid conventional locations. In automation, explicitly use
|
|
79
|
+
`--only` before enabling discovered hooks or MCP. Consumers may use `--as` only
|
|
80
|
+
when installing a manifest-free structural source.
|
|
81
|
+
|
|
65
82
|
## The `.agents/.plugin.json` DSL
|
|
66
83
|
|
|
67
84
|
```jsonc
|
|
@@ -74,7 +91,7 @@ authoring artifact:
|
|
|
74
91
|
"author": { "name": "You", "url": "…", "email": "…" },
|
|
75
92
|
"license": "MIT",
|
|
76
93
|
"category": "Developer Tools",
|
|
77
|
-
"interface": { "displayName": "ASC", "icon": "asc.png" },
|
|
94
|
+
"interface": { "displayName": "ASC", "shortDescription": "Ship App Store releases with asc.", "icon": "asc.png" },
|
|
78
95
|
|
|
79
96
|
// ── Components: path pointers, never inlined content ──
|
|
80
97
|
"skills": "./skills/", // string (root dir) | string[] (explicit paths)
|
|
@@ -108,7 +125,7 @@ authoring artifact:
|
|
|
108
125
|
| `author` | `{ name, url?, email? }` | | |
|
|
109
126
|
| `license` | string | | SPDX id, e.g. `MIT`. |
|
|
110
127
|
| `category` | string | | Free-form, e.g. `Developer Tools`. |
|
|
111
|
-
| `interface` | `{ displayName?, icon? }` | | Presentation
|
|
128
|
+
| `interface` | `{ displayName?, shortDescription?, icon? }` | | Presentation metadata. Codex uses `shortDescription` in its plugin picker; when omitted, ADG uses the manifest `description`. |
|
|
112
129
|
| `skills` | string \| string[] | | Root dir (auto-scan) or explicit skill paths. |
|
|
113
130
|
| `commands` | string | | Directory of slash-command `.md` files. |
|
|
114
131
|
| `agents` | string | | Directory of sub-agent `.md` files. |
|