@rbbtsn0w/adg 0.5.0 → 0.6.0-beta.10
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 +67 -2
- package/dist/bin/adg.js +0 -1
- package/dist/src/adapters/codex.js +12 -0
- package/dist/src/adapters/reverse.js +22 -1
- package/dist/src/agents/claude.js +52 -6
- package/dist/src/agents/codex.js +94 -14
- package/dist/src/cli/handlers.js +164 -141
- package/dist/src/cli/index.js +14 -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 +140 -73
- package/dist/src/commands/link.js +4 -16
- package/dist/src/commands/marketplace.js +74 -20
- package/dist/src/commands/migrate.js +15 -3
- package/dist/src/commands/projection.js +15 -0
- package/dist/src/commands/select-components.js +12 -0
- package/dist/src/commands/state.js +4 -2
- package/dist/src/commands/sync.js +9 -15
- package/dist/src/commands/update.js +51 -10
- package/dist/src/commands/validate.js +9 -2
- package/dist/src/components.js +3 -0
- package/dist/src/default-dsl.js +142 -0
- package/dist/src/lock.js +25 -7
- package/dist/src/manifest.js +29 -1
- package/dist/src/materialize.js +5 -1
- package/dist/src/mcp.js +59 -0
- package/dist/src/paths.js +31 -4
- package/dist/src/render/plugins.js +7 -1
- package/dist/src/source-cache.js +140 -0
- package/dist/src/sources.js +76 -5
- package/dist/src/telemetry.js +28 -21
- package/dist/src/types.js +5 -1
- package/dist/vendor/skills/src/cli.js +6 -1
- package/dist/vendor/skills/src/update.js +29 -4
- package/docs/agents-spec.md +27 -4
- package/docs/authoring.md +19 -2
- package/package.json +8 -2
- package/schemas/adg-plugin.schema.json +1 -0
- package/schemas/plugin-lock.schema.json +23 -1
- package/vendor/skills/src/cli.ts +6 -1
- package/vendor/skills/src/update.ts +32 -4
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { gitRemoteRevision } from "../sources.js";
|
|
2
|
+
import { cloneGitHub, gitRevision, parseGitHubSource } from "../sources.js";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
1
6
|
import { lockPath } from "../paths.js";
|
|
2
7
|
import { readLock } from "../lock.js";
|
|
3
8
|
import { addPlugins } from "./install.js";
|
|
@@ -113,26 +118,75 @@ export async function updatePlugins(opts) {
|
|
|
113
118
|
const remoteAgents = [];
|
|
114
119
|
for (const group of remoteGroups) {
|
|
115
120
|
try {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
gitRunner: opts.gitRunner,
|
|
127
|
-
activate: opts.activate,
|
|
128
|
-
scope: opts.agentScope,
|
|
129
|
-
agents: opts.agents,
|
|
130
|
-
deactivationAgents: opts.deactivationAgents,
|
|
131
|
-
now,
|
|
121
|
+
const lock = readLock(lockPath(opts.pluginsDir));
|
|
122
|
+
const revisions = group.installed.map((name) => lock.plugins[name]?.resolvedRevision).filter((revision) => Boolean(revision));
|
|
123
|
+
const remoteRevision = (opts.revisionResolver ?? gitRemoteRevision)(group.source, group.ref);
|
|
124
|
+
if (!opts.all && remoteRevision && revisions.length === group.installed.length && revisions.every((revision) => revision === remoteRevision)) {
|
|
125
|
+
remote.push({ source: group.source, ...(group.ref ? { ref: group.ref } : {}), updated: [], unchanged: [...group.installed].sort(), deleted: [], available: [] });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const structural = group.installed.flatMap((name) => {
|
|
129
|
+
const definition = lock.plugins[name]?.definition;
|
|
130
|
+
return definition ? [{ name, definition, selection: lock.plugins[name]?.selection }] : [];
|
|
132
131
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
const ordinary = group.installed.filter((name) => !lock.plugins[name]?.definition);
|
|
133
|
+
// A structural profile always describes the source root. Replay each
|
|
134
|
+
// profile independently so its stable --as identity is preserved.
|
|
135
|
+
const requests = [
|
|
136
|
+
...structural.map(({ name, definition, selection }) => ({
|
|
137
|
+
plugins: [name],
|
|
138
|
+
as: definition.as,
|
|
139
|
+
defaultDescription: definition.description,
|
|
140
|
+
authorizedComponents: definition.authorizedComponents,
|
|
141
|
+
replaySelection: selection ?? (definition.authorizedComponents ? { components: definition.authorizedComponents } : undefined),
|
|
142
|
+
})),
|
|
143
|
+
// A structural profile represents the whole source root. Never append
|
|
144
|
+
// an --all fallback that could derive a second Default DSL identity.
|
|
145
|
+
...(structural.length === 0 && (ordinary.length > 0 || opts.all)
|
|
146
|
+
? [{ plugins: opts.all ? undefined : ordinary }]
|
|
147
|
+
: []),
|
|
148
|
+
];
|
|
149
|
+
const installed = [];
|
|
150
|
+
const available = new Set();
|
|
151
|
+
const checkout = mkdtempSync(join(tmpdir(), "adg-marketplace-update-"));
|
|
152
|
+
try {
|
|
153
|
+
const parsed = parseGitHubSource(group.source);
|
|
154
|
+
cloneGitHub({ ...parsed, ref: group.ref }, checkout, { runner: opts.gitRunner });
|
|
155
|
+
const resolvedRevision = gitRevision(checkout);
|
|
156
|
+
for (const request of requests) {
|
|
157
|
+
const result = await addPlugins({
|
|
158
|
+
spec: group.source,
|
|
159
|
+
pluginsDir: opts.pluginsDir,
|
|
160
|
+
ref: group.ref,
|
|
161
|
+
...(opts.all && request.plugins === undefined ? { all: true } : { plugins: request.plugins }),
|
|
162
|
+
missingPlugins: "skip",
|
|
163
|
+
skipUnchanged: true,
|
|
164
|
+
nonInteractive: true,
|
|
165
|
+
...(request.authorizedComponents ? { authorizedComponents: request.authorizedComponents } : {}),
|
|
166
|
+
...(request.replaySelection ? { replaySelection: request.replaySelection } : {}),
|
|
167
|
+
targets: opts.targets,
|
|
168
|
+
marketplaceName: group.source,
|
|
169
|
+
gitRunner: opts.gitRunner,
|
|
170
|
+
...(request.as ? { as: request.as } : {}),
|
|
171
|
+
...(request.defaultDescription ? { defaultDescription: request.defaultDescription } : {}),
|
|
172
|
+
activate: opts.activate,
|
|
173
|
+
scope: opts.agentScope,
|
|
174
|
+
agents: opts.agents,
|
|
175
|
+
deactivationAgents: opts.deactivationAgents,
|
|
176
|
+
now,
|
|
177
|
+
preparedSourceDir: checkout,
|
|
178
|
+
preparedResolvedRevision: resolvedRevision,
|
|
179
|
+
});
|
|
180
|
+
installed.push(...result.installed);
|
|
181
|
+
result.available.forEach((name) => available.add(name));
|
|
182
|
+
if (result.agents)
|
|
183
|
+
remoteAgents.push(...result.agents);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
rmSync(checkout, { recursive: true, force: true });
|
|
188
|
+
}
|
|
189
|
+
const availableSet = available;
|
|
136
190
|
const installedNow = new Set(installed.map((r) => r.name));
|
|
137
191
|
remote.push({
|
|
138
192
|
source: group.source,
|
|
@@ -140,7 +194,7 @@ export async function updatePlugins(opts) {
|
|
|
140
194
|
updated: installed.filter((r) => r.changed).map((r) => r.name).sort(),
|
|
141
195
|
unchanged: installed.filter((r) => !r.changed).map((r) => r.name).sort(),
|
|
142
196
|
deleted: group.installed.filter((n) => !availableSet.has(n)).sort(),
|
|
143
|
-
available: available.filter((n) => !installedNow.has(n) && !group.installed.includes(n)).sort(),
|
|
197
|
+
available: [...available].filter((n) => !installedNow.has(n) && !group.installed.includes(n)).sort(),
|
|
144
198
|
});
|
|
145
199
|
}
|
|
146
200
|
catch (err) {
|
|
@@ -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,27 @@ 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" || Array.isArray(raw))
|
|
70
|
+
throw new Error(`${file} is not a valid lock file`);
|
|
71
|
+
if (Array.isArray(raw.plugins))
|
|
72
|
+
throw new Error(`${file} is not a valid lock file`);
|
|
69
73
|
if (raw.version === LOCK_VERSION)
|
|
70
74
|
return false;
|
|
71
75
|
if (typeof raw?.version === "number") {
|
|
72
|
-
recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 ?
|
|
76
|
+
recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 || raw.version === 3 || raw.version === 4 ? raw.version : -1 }, telemetrySpan);
|
|
77
|
+
}
|
|
78
|
+
if ((raw.version === 3 || raw.version === 4) && typeof raw.plugins === "object" && raw.plugins !== null) {
|
|
79
|
+
// v3 has the same payload model; v4 adds optional immutable provenance.
|
|
80
|
+
// Existing remote entries remain explicitly legacy until an update/add
|
|
81
|
+
// resolves their commit, rather than inventing a moving ref as a revision.
|
|
82
|
+
writeLock(file, { ...raw, version: LOCK_VERSION });
|
|
83
|
+
recordTelemetryEvent("adg.lock.migrate", { "from.version": raw.version, "to.version": LOCK_VERSION }, telemetrySpan);
|
|
84
|
+
return true;
|
|
73
85
|
}
|
|
74
86
|
if (raw.version !== 2 || typeof raw.plugins !== "object" || raw.plugins === null) {
|
|
75
87
|
throw new Error(`${file} uses unsupported lock version ${raw.version}; expected ${LOCK_VERSION}`);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { listPlugins } from "./list.js";
|
|
2
2
|
import { relative } from "node:path";
|
|
3
|
+
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
4
|
+
import { installPlugin } from "./install.js";
|
|
5
|
+
import { resolvePluginSourceSnapshot } from "../source-cache.js";
|
|
3
6
|
/**
|
|
4
7
|
* Shared selection for the projection verbs (link / unlink / sync). Resolve which
|
|
5
8
|
* installed plugins to act on: the named subset (validated against the store), or
|
|
@@ -32,3 +35,15 @@ export function adaptedFilesForTarget(installedTo, files, target) {
|
|
|
32
35
|
const expected = target === "antigravity" ? "plugin.json" : `.${target}-plugin/plugin.json`;
|
|
33
36
|
return files.filter((file) => relative(installedTo, file).split("\\").join("/") === expected);
|
|
34
37
|
}
|
|
38
|
+
/** Rebuild runtime projections for installed plugins from their cached ADG source. */
|
|
39
|
+
export function rematerializeInstalled(pluginsDir, plugins) {
|
|
40
|
+
return plugins.map((plugin) => installPlugin({
|
|
41
|
+
source: resolvePluginSourceSnapshot(pluginsDir, plugin.name, plugin),
|
|
42
|
+
pluginsDir,
|
|
43
|
+
origin: plugin.origin,
|
|
44
|
+
resolvedRevision: plugin.resolvedRevision,
|
|
45
|
+
selection: plugin.selection,
|
|
46
|
+
targets: [...ADAPTER_TARGETS],
|
|
47
|
+
forceMaterialize: true,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
@@ -58,5 +58,17 @@ export async function selectComponentsInteractive(req) {
|
|
|
58
58
|
selection.skills = picked;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
// Drill into individual MCP servers only when mcp is kept and there's a choice.
|
|
62
|
+
if (chosen.includes("mcp") && req.contents.mcp.length > 1) {
|
|
63
|
+
const message = `${pc.bold(req.name)} — which MCP servers? ${pc.dim("(space to toggle)")}`;
|
|
64
|
+
const options = req.contents.mcp.map((s) => ({ value: s, label: s }));
|
|
65
|
+
const initialValues = [...req.contents.mcp];
|
|
66
|
+
const servers = await p.multiselect({ message, options, initialValues, required: true });
|
|
67
|
+
if (!cancelled(servers)) {
|
|
68
|
+
const picked = servers;
|
|
69
|
+
if (picked.length !== req.contents.mcp.length)
|
|
70
|
+
selection.mcp = picked;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
61
73
|
return selection;
|
|
62
74
|
}
|
|
@@ -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,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { adaptedFilesForTarget, selectInstalled } from "./projection.js";
|
|
2
|
-
import { pluginRematerializationSource } from "../paths.js";
|
|
1
|
+
import { adaptedFilesForTarget, rematerializeInstalled, selectInstalled } from "./projection.js";
|
|
3
2
|
import { getAgent } from "../agents/index.js";
|
|
4
|
-
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
5
3
|
import { pluginState } from "../types.js";
|
|
6
|
-
import { installPlugin } from "./install.js";
|
|
7
4
|
/** Regenerate manifests for the selected plugins, then refresh them in the agent. */
|
|
8
5
|
export function syncPlugins(opts) {
|
|
9
6
|
const agent = opts.agent ?? getAgent(opts.target);
|
|
@@ -12,23 +9,20 @@ export function syncPlugins(opts) {
|
|
|
12
9
|
const enabled = selected.filter((p) => pluginState(p) === "enabled");
|
|
13
10
|
const disabled = selected.filter((p) => pluginState(p) === "disabled");
|
|
14
11
|
const actions = disabled.map((p) => ({ name: p.name, adapted: [], synced: false }));
|
|
15
|
-
for (const
|
|
16
|
-
|
|
17
|
-
source: pluginRematerializationSource(opts.pluginsDir, p.name, p.origin),
|
|
18
|
-
pluginsDir: opts.pluginsDir,
|
|
19
|
-
origin: p.origin,
|
|
20
|
-
selection: p.selection,
|
|
21
|
-
targets: [...ADAPTER_TARGETS],
|
|
22
|
-
forceMaterialize: true,
|
|
23
|
-
});
|
|
24
|
-
actions.push({ name: p.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget), synced: false });
|
|
12
|
+
for (const result of rematerializeInstalled(opts.pluginsDir, enabled)) {
|
|
13
|
+
actions.push({ name: result.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget), synced: false });
|
|
25
14
|
}
|
|
26
15
|
if (!agent)
|
|
27
16
|
return { target: opts.target, actions };
|
|
28
17
|
const scope = opts.global ? "user" : "project";
|
|
29
18
|
const parts = [
|
|
30
19
|
...(disabled.length > 0 ? [agent.deactivate({ pluginsDir: opts.pluginsDir, plugins: disabled.map((p) => p.name), scope })] : []),
|
|
31
|
-
...(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
|
+
})] : []),
|
|
32
26
|
];
|
|
33
27
|
for (const action of actions)
|
|
34
28
|
if (parts.some((part) => part.affected.includes(action.name)))
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
3
4
|
import { resolveAgents } from "../agents/index.js";
|
|
4
5
|
import { installedPluginDir, lockPath, pluginSourceCacheDir } from "../paths.js";
|
|
5
6
|
import { readLock } from "../lock.js";
|
|
6
7
|
import { installPlugin } from "./install.js";
|
|
8
|
+
import { resolveDefaultDsl } from "../default-dsl.js";
|
|
9
|
+
import { ADG_MANIFEST_PATH } from "../manifest.js";
|
|
10
|
+
import { copyPluginDir, writeJson } from "../fsutil.js";
|
|
7
11
|
/**
|
|
8
12
|
* Refresh local sources and repair effective installations from their complete
|
|
9
13
|
* source snapshots. Runtime installations are never treated as upstream input.
|
|
@@ -28,14 +32,51 @@ export function updateLock(pluginsDir, now = new Date().toISOString(), opts = {}
|
|
|
28
32
|
missing.push(name);
|
|
29
33
|
continue;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
source
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (entry.definition && localSource && existsSync(join(localSource, ADG_MANIFEST_PATH))) {
|
|
36
|
+
throw new Error(`source definition changed from default DSL to a manifest for "${name}"; re-add or migrate the plugin explicitly`);
|
|
37
|
+
}
|
|
38
|
+
let installSource = source;
|
|
39
|
+
let staging;
|
|
40
|
+
let definition = entry.definition;
|
|
41
|
+
if (!existsSync(join(source, ADG_MANIFEST_PATH))) {
|
|
42
|
+
try {
|
|
43
|
+
const generated = resolveDefaultDsl(source, { name, description: entry.definition?.description ?? name }, {
|
|
44
|
+
...(entry.origin.type === "github" && entry.resolvedRevision ? { resolvedRevision: entry.resolvedRevision } : {}),
|
|
45
|
+
});
|
|
46
|
+
const authorized = entry.definition?.authorizedComponents;
|
|
47
|
+
const unauthorizedRisk = generated.components.some((component) => (component === "hooks" || component === "mcp") && !authorized?.includes(component));
|
|
48
|
+
if (entry.definition && unauthorizedRisk) {
|
|
49
|
+
throw new Error(`default source exposes an unauthorized hook or MCP component for "${name}"; re-add the plugin with an explicit component selection`);
|
|
50
|
+
}
|
|
51
|
+
if (entry.definition)
|
|
52
|
+
definition = { ...entry.definition, description: generated.manifest.description, fingerprint: generated.fingerprint };
|
|
53
|
+
staging = mkdtempSync(join(tmpdir(), "adg-default-update-"));
|
|
54
|
+
copyPluginDir(source, staging);
|
|
55
|
+
writeJson(join(staging, ADG_MANIFEST_PATH), generated.manifest);
|
|
56
|
+
installSource = staging;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (!(error instanceof Error) || !error.message.includes("no default plugin component"))
|
|
60
|
+
throw error;
|
|
61
|
+
// Non-plugin local directories continue through the normal manifest path.
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let result;
|
|
65
|
+
try {
|
|
66
|
+
result = installPlugin({
|
|
67
|
+
source: installSource,
|
|
68
|
+
pluginsDir,
|
|
69
|
+
origin: entry.origin,
|
|
70
|
+
selection: entry.selection ?? (entry.definition?.authorizedComponents ? { components: entry.definition.authorizedComponents } : undefined),
|
|
71
|
+
skipUnchanged: true,
|
|
72
|
+
now,
|
|
73
|
+
definition,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
if (staging)
|
|
78
|
+
rmSync(staging, { recursive: true, force: true });
|
|
79
|
+
}
|
|
39
80
|
if (result.changed)
|
|
40
81
|
changedNames.push(name);
|
|
41
82
|
results.push({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
3
|
import { ADG_MANIFEST_PATH, collectIssues } from "../manifest.js";
|
|
4
|
+
import { resolveDefaultDsl } from "../default-dsl.js";
|
|
4
5
|
/**
|
|
5
6
|
* Validate a plugin's manifest against the ADG schema and check that the
|
|
6
7
|
* directories/files it references actually exist.
|
|
@@ -8,7 +9,13 @@ import { ADG_MANIFEST_PATH, collectIssues } from "../manifest.js";
|
|
|
8
9
|
export function validatePlugin(pluginDir) {
|
|
9
10
|
const manifestFile = join(pluginDir, ADG_MANIFEST_PATH);
|
|
10
11
|
if (!existsSync(manifestFile)) {
|
|
11
|
-
|
|
12
|
+
try {
|
|
13
|
+
resolveDefaultDsl(pluginDir, { name: basename(pluginDir), description: basename(pluginDir) });
|
|
14
|
+
return { ok: true, issues: [] };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return { ok: false, issues: [error instanceof Error ? error.message : String(error)] };
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
20
|
let raw;
|
|
14
21
|
try {
|
package/dist/src/components.js
CHANGED
|
@@ -84,6 +84,9 @@ export function exposedContents(contents, selection) {
|
|
|
84
84
|
else if (c === "skills" && selection.skills) {
|
|
85
85
|
out[c] = contents.skills.filter((s) => selection.skills.includes(s));
|
|
86
86
|
}
|
|
87
|
+
else if (c === "mcp" && selection.mcp) {
|
|
88
|
+
out[c] = contents.mcp.filter((s) => selection.mcp.includes(s));
|
|
89
|
+
}
|
|
87
90
|
else {
|
|
88
91
|
out[c] = contents[c];
|
|
89
92
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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: options.resolvedRevision
|
|
49
|
+
? `0.0.0-git.${options.resolvedRevision}`
|
|
50
|
+
: `0.0.0-adg.${fingerprint}`,
|
|
51
|
+
description: metadata.description,
|
|
52
|
+
...componentManifest,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Discover and validate conventional component locations without hashing payload contents. */
|
|
57
|
+
export function probeDefaultDsl(root, options = {}) {
|
|
58
|
+
const ignore = options.ignore ?? new Set();
|
|
59
|
+
const skillsRoot = join(root, "skills");
|
|
60
|
+
const skillFiles = !ignore.has("skills") && isDirectory(skillsRoot)
|
|
61
|
+
? readdirSync(skillsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(join(skillsRoot, entry.name, "SKILL.md"))).map((entry) => join(skillsRoot, entry.name, "SKILL.md"))
|
|
62
|
+
: [];
|
|
63
|
+
const invalidSkillFile = skillFiles.find((file) => !isRegularFile(file));
|
|
64
|
+
if (invalidSkillFile)
|
|
65
|
+
throw new Error(`invalid default skill file (must be a regular file): ${invalidSkillFile}`);
|
|
66
|
+
const invalidSkill = skillFiles.find((file) => !readSkillDescription(file));
|
|
67
|
+
if (invalidSkill)
|
|
68
|
+
throw new Error(`default skill requires SKILL.md frontmatter with a description: ${invalidSkill}`);
|
|
69
|
+
const hasSkills = skillFiles.length > 0;
|
|
70
|
+
const hooksFile = join(root, "hooks", "hooks.json");
|
|
71
|
+
const hasHooks = !ignore.has("hooks") && existsSync(hooksFile) && validJson(hooksFile);
|
|
72
|
+
if (!ignore.has("hooks") && existsSync(hooksFile) && !hasHooks)
|
|
73
|
+
throw new Error(`invalid default hooks configuration: ${hooksFile}`);
|
|
74
|
+
const mcpFile = join(root, ".mcp.json");
|
|
75
|
+
const hasMcp = !ignore.has("mcp") && existsSync(mcpFile) && validMcp(mcpFile);
|
|
76
|
+
if (!ignore.has("mcp") && existsSync(mcpFile) && !hasMcp)
|
|
77
|
+
throw new Error(`invalid default MCP configuration: ${mcpFile}`);
|
|
78
|
+
const components = [
|
|
79
|
+
...(hasSkills ? ["skills"] : []),
|
|
80
|
+
...(hasHooks ? ["hooks"] : []),
|
|
81
|
+
...(hasMcp ? ["mcp"] : []),
|
|
82
|
+
];
|
|
83
|
+
if (components.length === 0)
|
|
84
|
+
throw new Error(`no default plugin component found in ${root}`);
|
|
85
|
+
return {
|
|
86
|
+
components,
|
|
87
|
+
manifest: {
|
|
88
|
+
...(hasSkills ? { skills: "./skills/" } : { skills: [] }),
|
|
89
|
+
...(hasHooks ? { hooks: "./hooks/" } : {}),
|
|
90
|
+
...(hasMcp ? { mcpServers: "./.mcp.json" } : {}),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function validJson(file) {
|
|
95
|
+
if (!isRegularFile(file))
|
|
96
|
+
return false;
|
|
97
|
+
try {
|
|
98
|
+
JSON.parse(readFileSync(file, "utf8"));
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function isDirectory(path) {
|
|
106
|
+
try {
|
|
107
|
+
return lstatSync(path).isDirectory();
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function isRegularFile(path) {
|
|
114
|
+
try {
|
|
115
|
+
return lstatSync(path).isFile();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function validMcp(file) {
|
|
122
|
+
if (!validJson(file))
|
|
123
|
+
return false;
|
|
124
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
125
|
+
if (json === null || typeof json !== "object" || Array.isArray(json))
|
|
126
|
+
return false;
|
|
127
|
+
const servers = json.mcpServers ?? json.servers;
|
|
128
|
+
return typeof servers === "object" && servers !== null && !Array.isArray(servers);
|
|
129
|
+
}
|
|
130
|
+
function hashTree(hasher, dir, rel) {
|
|
131
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
132
|
+
const child = join(dir, entry.name);
|
|
133
|
+
const childRel = `${rel}/${entry.name}`;
|
|
134
|
+
const stat = lstatSync(child);
|
|
135
|
+
if (stat.isSymbolicLink())
|
|
136
|
+
throw new Error(`default plugin component must not contain symlinks: ${child}`);
|
|
137
|
+
if (stat.isDirectory())
|
|
138
|
+
hashTree(hasher, child, childRel);
|
|
139
|
+
else if (stat.isFile())
|
|
140
|
+
hasher.update(childRel).update("\0").update(readFileSync(child)).update("\0");
|
|
141
|
+
}
|
|
142
|
+
}
|
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). */
|
|
@@ -46,7 +47,34 @@ export function readManifest(pluginDir, telemetrySpan) {
|
|
|
46
47
|
throw new ManifestError([`${file} is not valid JSON: ${err.message}`]);
|
|
47
48
|
}
|
|
48
49
|
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
49
|
-
const
|
|
50
|
+
const m = raw;
|
|
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
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const schemaVersion = m.schemaVersion;
|
|
50
78
|
if (typeof schemaVersion === "string") {
|
|
51
79
|
recordTelemetryEvent("adg.manifest.read", {
|
|
52
80
|
"schema.version": schemaVersion === ADG_SCHEMA_VERSION ? schemaVersion : "other",
|
package/dist/src/materialize.js
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, renameSync, rmSync } from "node:fs";
|
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
4
|
import { copyPluginDir, ensureDir, toPosix, writeJson } from "./fsutil.js";
|
|
5
5
|
import { ADG_MANIFEST_PATH } from "./manifest.js";
|
|
6
|
-
import { mcpConfigPath } from "./mcp.js";
|
|
6
|
+
import { filterMcpConfig, mcpConfigPath } from "./mcp.js";
|
|
7
7
|
import { packageFilter } from "./package.js";
|
|
8
8
|
const META_RE = /^(README|LICEN[CS]E|CHANGELOG|NOTICE)(\..+)?$/i;
|
|
9
9
|
function normalizeRelative(path) {
|
|
@@ -106,6 +106,10 @@ export function materializePlugin(opts) {
|
|
|
106
106
|
}
|
|
107
107
|
try {
|
|
108
108
|
copyPluginDir(opts.source, staging, effectivePackageFilter(opts.manifest, opts.selection));
|
|
109
|
+
const mcp = mcpConfigPath(opts.manifest);
|
|
110
|
+
if (mcp && opts.selection?.components.includes("mcp") && opts.selection.mcp) {
|
|
111
|
+
filterMcpConfig(join(staging, mcp), opts.selection.mcp);
|
|
112
|
+
}
|
|
109
113
|
writeJson(join(staging, ADG_MANIFEST_PATH), effectiveManifest);
|
|
110
114
|
opts.build(staging, effectiveManifest);
|
|
111
115
|
if (existsSync(destination))
|