@rbbtsn0w/adg 0.6.0-beta.1 → 0.6.0-beta.3
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 +14 -0
- package/dist/src/adapters/reverse.js +22 -1
- package/dist/src/agents/claude.js +52 -6
- package/dist/src/agents/codex.js +57 -8
- package/dist/src/cli/handlers.js +143 -139
- package/dist/src/cli/index.js +3 -1
- package/dist/src/commands/install.js +54 -46
- package/dist/src/commands/link.js +3 -16
- package/dist/src/commands/projection.js +14 -0
- package/dist/src/commands/select-components.js +12 -0
- package/dist/src/commands/sync.js +3 -14
- package/dist/src/components.js +3 -0
- package/dist/src/manifest.js +5 -1
- package/dist/src/materialize.js +5 -1
- package/dist/src/mcp.js +59 -0
- package/dist/src/types.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -156,6 +156,20 @@ adg plugins update --global
|
|
|
156
156
|
adg plugins link --target claude --global
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
+
### Example 3 — `cloudflare/skills` (auto-discovery and selective installation)
|
|
160
|
+
|
|
161
|
+
A repository containing skills for the Cloudflare Developer Platform. Although the repository doesn't explicitly declare an MCP configuration in its native `.claude-plugin/plugin.json` manifest, it includes a `.mcp.json` file in its root. ADG auto-discovers this file, allowing you to selectively choose which components, skills, or MCP servers to install:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# Add the cloudflare plugin globally (interactive guide asks which skills/MCP servers to install)
|
|
165
|
+
adg plugins add https://github.com/cloudflare/skills --global
|
|
166
|
+
|
|
167
|
+
# Or install it non-interactively, limiting to specific skills and MCP servers:
|
|
168
|
+
adg plugins add https://github.com/cloudflare/skills --global \
|
|
169
|
+
--skill agents-sdk --skill cloudflare --skill durable-objects \
|
|
170
|
+
--mcp wrangler-mcp --mcp d1-mcp
|
|
171
|
+
```
|
|
172
|
+
|
|
159
173
|
> Both repos are pulled by `owner/repo` shorthand over a shallow clone (sparse
|
|
160
174
|
> checkout when `--sparse` is given). Provenance — `{type:"github",repo,ref,path}`
|
|
161
175
|
> — plus a `sha256` integrity hash land in `.plugin-lock.json`, so the install is
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
1
3
|
import { ADG_SCHEMA_VERSION } from "../types.js";
|
|
2
4
|
import { validateManifest } from "../manifest.js";
|
|
3
5
|
import { toPosix } from "../fsutil.js";
|
|
@@ -15,7 +17,7 @@ import { toPosix } from "../fsutil.js";
|
|
|
15
17
|
* emits valid `./skills/<id>` entries instead of leaking bare ids into a Claude
|
|
16
18
|
* manifest.
|
|
17
19
|
*/
|
|
18
|
-
export function fromNativeManifest(raw, kind) {
|
|
20
|
+
export function fromNativeManifest(raw, kind, pluginDir) {
|
|
19
21
|
if (typeof raw !== "object" || raw === null) {
|
|
20
22
|
throw new Error("native manifest must be a JSON object");
|
|
21
23
|
}
|
|
@@ -36,6 +38,14 @@ export function fromNativeManifest(raw, kind) {
|
|
|
36
38
|
copyIfString(n, out, "agents");
|
|
37
39
|
copyIfString(n, out, "hooks");
|
|
38
40
|
copyIfString(n, out, "mcpServers");
|
|
41
|
+
if (typeof out.mcpServers !== "string") {
|
|
42
|
+
if (typeof n.mcp === "string") {
|
|
43
|
+
out.mcpServers = n.mcp;
|
|
44
|
+
}
|
|
45
|
+
else if (pluginDir && existsSync(join(pluginDir, ".mcp.json"))) {
|
|
46
|
+
out.mcpServers = "./.mcp.json";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
copyIfString(n, out, "apps");
|
|
40
50
|
if (typeof n.author === "object" && n.author !== null) {
|
|
41
51
|
manifest.author = n.author;
|
|
@@ -57,6 +67,17 @@ export function fromNativeManifest(raw, kind) {
|
|
|
57
67
|
manifest.skills = "./skills/";
|
|
58
68
|
}
|
|
59
69
|
manifest.strict = typeof n.strict === "boolean" ? n.strict : true;
|
|
70
|
+
if (!manifest.hooks && pluginDir) {
|
|
71
|
+
const hooksDir = join(pluginDir, "hooks");
|
|
72
|
+
try {
|
|
73
|
+
if (existsSync(hooksDir) && statSync(hooksDir).isDirectory())
|
|
74
|
+
manifest.hooks = "./hooks/";
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// hooks inference is best-effort; unreadable or concurrently removed dirs
|
|
78
|
+
// must not abort reverse-adaptation.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
60
81
|
return validateManifest(manifest);
|
|
61
82
|
}
|
|
62
83
|
function copyIfString(src, dst, key) {
|
|
@@ -16,6 +16,7 @@ import { makeCli, skippedResult } from "./base.js";
|
|
|
16
16
|
* versions) rather than hand-editing Claude's internal state.
|
|
17
17
|
*/
|
|
18
18
|
const MARKETPLACE = "adg";
|
|
19
|
+
const UNRECOGNIZED_PLUGIN_LIST = "claude plugin list returned unrecognized output";
|
|
19
20
|
function claudeHome(env) {
|
|
20
21
|
return env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), ".claude");
|
|
21
22
|
}
|
|
@@ -94,7 +95,7 @@ export function parseClaudeMarketplaceList(out) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
/** Register or refresh the ADG store as a Claude marketplace, failing open. */
|
|
97
|
-
export function syncMarketplace(pluginsDir, name, runner = run) {
|
|
98
|
+
export function syncMarketplace(pluginsDir, name, runner = run, warn = console.warn) {
|
|
98
99
|
const listed = runner(["plugin", "marketplace", "list", "--json"]);
|
|
99
100
|
if (listed.ok && parseClaudeMarketplaceList(listed.out).includes(name)) {
|
|
100
101
|
// Claude's marketplace update path can fail on existing installs (for
|
|
@@ -104,7 +105,10 @@ export function syncMarketplace(pluginsDir, name, runner = run) {
|
|
|
104
105
|
if (runner(["plugin", "marketplace", "update", name]).ok)
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
|
-
runner(["plugin", "marketplace", "add", pluginsDir]);
|
|
108
|
+
const added = runner(["plugin", "marketplace", "add", pluginsDir]);
|
|
109
|
+
if (!added.ok) {
|
|
110
|
+
warn(`failed to sync Claude marketplace (${name}): ${added.out.trim() || "claude plugin marketplace add failed without an error message"}`);
|
|
111
|
+
}
|
|
108
112
|
}
|
|
109
113
|
export const claudeAgent = {
|
|
110
114
|
id: "claude",
|
|
@@ -156,12 +160,54 @@ export const claudeAgent = {
|
|
|
156
160
|
listInstalled(ctx) {
|
|
157
161
|
if (!available())
|
|
158
162
|
return undefined;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
const marketplace = claudeMarketplaceName(ctx.pluginsDir);
|
|
164
|
+
const jsonRes = run(["plugin", "list", "--json"]);
|
|
165
|
+
if (jsonRes.ok) {
|
|
166
|
+
const parsed = parseClaudePluginListJson(jsonRes.out, marketplace, ctx.scope);
|
|
167
|
+
if (parsed !== undefined)
|
|
168
|
+
return parsed;
|
|
169
|
+
return claudeListFailure(jsonRes.out);
|
|
170
|
+
}
|
|
171
|
+
const textRes = run(["plugin", "list"]);
|
|
172
|
+
if (!textRes.ok)
|
|
173
|
+
return { error: textRes.out.trim() || jsonRes.out.trim() || "claude plugin list failed without an error message" };
|
|
174
|
+
const fallback = parseClaudePluginList(textRes.out, marketplace, ctx.scope);
|
|
175
|
+
if (fallback.length > 0 || textRes.out.trim() === "")
|
|
176
|
+
return fallback;
|
|
177
|
+
return claudeListFailure(textRes.out);
|
|
163
178
|
},
|
|
164
179
|
};
|
|
180
|
+
export function claudeListFailure(out) {
|
|
181
|
+
const detail = out.trim() || "claude plugin list failed without an error message";
|
|
182
|
+
return { error: `${UNRECOGNIZED_PLUGIN_LIST}: ${detail}` };
|
|
183
|
+
}
|
|
184
|
+
/** Parse `claude plugin list --json` into enabled plugin names for a marketplace + scope. */
|
|
185
|
+
export function parseClaudePluginListJson(out, marketplace, scope) {
|
|
186
|
+
try {
|
|
187
|
+
const parsed = JSON.parse(out);
|
|
188
|
+
if (!Array.isArray(parsed))
|
|
189
|
+
return undefined;
|
|
190
|
+
const names = [];
|
|
191
|
+
const seen = new Set();
|
|
192
|
+
for (const entry of parsed) {
|
|
193
|
+
if (typeof entry !== "object" || entry === null)
|
|
194
|
+
continue;
|
|
195
|
+
const record = entry;
|
|
196
|
+
const id = typeof record.id === "string" ? record.id : undefined;
|
|
197
|
+
const entryScope = typeof record.scope === "string" ? record.scope.toLowerCase() : undefined;
|
|
198
|
+
const enabled = record.enabled === true;
|
|
199
|
+
const head = id?.match(/^(\S+?)@([\w.-]+)$/);
|
|
200
|
+
if (!head || head[2] !== marketplace || entryScope !== scope || !enabled || seen.has(head[1]))
|
|
201
|
+
continue;
|
|
202
|
+
seen.add(head[1]);
|
|
203
|
+
names.push(head[1]);
|
|
204
|
+
}
|
|
205
|
+
return names;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
165
211
|
/**
|
|
166
212
|
* Parse `claude plugin list` output into the *enabled* plugin names from a given
|
|
167
213
|
* marketplace and install scope. The listing groups each plugin as a
|
package/dist/src/agents/codex.js
CHANGED
|
@@ -5,6 +5,7 @@ import { join, resolve } from "node:path";
|
|
|
5
5
|
import { codexMarketplaceRoot, globalPluginsDir, marketplacePath } from "../paths.js";
|
|
6
6
|
import { readMarketplace, writeMarketplace } from "../marketplace.js";
|
|
7
7
|
import { makeCli, skippedResult } from "./base.js";
|
|
8
|
+
const UNRECOGNIZED_PLUGIN_LIST = "codex plugin list returned unrecognized output";
|
|
8
9
|
/**
|
|
9
10
|
* Codex agent.
|
|
10
11
|
*
|
|
@@ -41,11 +42,15 @@ export function writeCodexMarketplaceName(pluginsDir) {
|
|
|
41
42
|
return name;
|
|
42
43
|
}
|
|
43
44
|
/** Register the local marketplace root Codex expects for this store. */
|
|
44
|
-
function syncMarketplace(pluginsDir, marketplace) {
|
|
45
|
+
export function syncMarketplace(pluginsDir, marketplace, runner = run, warn = console.warn) {
|
|
45
46
|
const root = codexMarketplaceRoot(pluginsDir);
|
|
46
|
-
const add =
|
|
47
|
-
if (
|
|
48
|
-
|
|
47
|
+
const add = runner(["plugin", "marketplace", "add", root]);
|
|
48
|
+
if (add.ok)
|
|
49
|
+
return;
|
|
50
|
+
const upgraded = runner(["plugin", "marketplace", "upgrade", marketplace]);
|
|
51
|
+
if (!upgraded.ok) {
|
|
52
|
+
warn(`failed to sync Codex marketplace (${marketplace}): ${upgraded.out.trim() || add.out.trim() || "codex plugin marketplace sync failed without an error message"}`);
|
|
53
|
+
}
|
|
49
54
|
}
|
|
50
55
|
export const codexAgent = {
|
|
51
56
|
id: "codex",
|
|
@@ -92,10 +97,20 @@ export const codexAgent = {
|
|
|
92
97
|
const mp = writeCodexMarketplaceName(ctx.pluginsDir);
|
|
93
98
|
if (!mp)
|
|
94
99
|
return undefined; // no generated marketplace → can't scope the query
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
const jsonRes = run(["plugin", "list", "--json"]);
|
|
101
|
+
if (jsonRes.ok) {
|
|
102
|
+
const parsed = parseCodexPluginListJson(jsonRes.out, mp);
|
|
103
|
+
if (parsed !== undefined)
|
|
104
|
+
return parsed;
|
|
105
|
+
return codexUnrecognizedListFailure(jsonRes.out);
|
|
106
|
+
}
|
|
107
|
+
const textRes = run(["plugin", "list"]);
|
|
108
|
+
if (!textRes.ok)
|
|
109
|
+
return codexListFailure(textRes.out || jsonRes.out);
|
|
110
|
+
const fallback = parseCodexPluginList(textRes.out, mp);
|
|
111
|
+
if (fallback.length > 0 || textRes.out.trim() === "")
|
|
112
|
+
return fallback;
|
|
113
|
+
return codexUnrecognizedListFailure(textRes.out);
|
|
99
114
|
},
|
|
100
115
|
};
|
|
101
116
|
/** Preserve Codex's diagnostic and offer cleanup for a stale ADG project marketplace. */
|
|
@@ -107,6 +122,40 @@ export function codexListFailure(out) {
|
|
|
107
122
|
...(staleMarketplace ? { recoveryCommand: `codex plugin marketplace remove ${staleMarketplace[1]}` } : {}),
|
|
108
123
|
};
|
|
109
124
|
}
|
|
125
|
+
export function codexUnrecognizedListFailure(out) {
|
|
126
|
+
const detail = out.trim() || "codex plugin list failed without an error message";
|
|
127
|
+
return { error: `${UNRECOGNIZED_PLUGIN_LIST}: ${detail}` };
|
|
128
|
+
}
|
|
129
|
+
/** Parse `codex plugin list --json` into installed and enabled plugin names for one marketplace. */
|
|
130
|
+
export function parseCodexPluginListJson(out, marketplace) {
|
|
131
|
+
try {
|
|
132
|
+
const parsed = JSON.parse(out);
|
|
133
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
134
|
+
return undefined;
|
|
135
|
+
const installed = parsed.installed;
|
|
136
|
+
if (!Array.isArray(installed))
|
|
137
|
+
return undefined;
|
|
138
|
+
const names = [];
|
|
139
|
+
const seen = new Set();
|
|
140
|
+
for (const entry of installed) {
|
|
141
|
+
if (typeof entry !== "object" || entry === null)
|
|
142
|
+
continue;
|
|
143
|
+
const record = entry;
|
|
144
|
+
const name = typeof record.name === "string" ? record.name : undefined;
|
|
145
|
+
const mp = typeof record.marketplaceName === "string" ? record.marketplaceName : undefined;
|
|
146
|
+
const isInstalled = record.installed === true;
|
|
147
|
+
const enabled = record.enabled === true;
|
|
148
|
+
if (!name || mp !== marketplace || !isInstalled || !enabled || seen.has(name))
|
|
149
|
+
continue;
|
|
150
|
+
seen.add(name);
|
|
151
|
+
names.push(name);
|
|
152
|
+
}
|
|
153
|
+
return names;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
110
159
|
/**
|
|
111
160
|
* Parse `codex plugin list` output into the *installed and enabled* plugin names
|
|
112
161
|
* from a given marketplace. The listing is a whitespace-aligned table whose
|
package/dist/src/cli/handlers.js
CHANGED
|
@@ -132,6 +132,14 @@ async function resolveActionScope(values, verb) {
|
|
|
132
132
|
info: { label: global ? "global" : "project", globalDir },
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
+
function resolveVerbTargets(values, verb) {
|
|
136
|
+
return values.target === "all"
|
|
137
|
+
? resolveTargets("all")
|
|
138
|
+
: [requireSingleTarget(values.target, verb)];
|
|
139
|
+
}
|
|
140
|
+
function printCliUnavailableNote(target, message) {
|
|
141
|
+
console.log(ui.warn(`note: \`${target}\` CLI not found — ${message}`));
|
|
142
|
+
}
|
|
135
143
|
/**
|
|
136
144
|
* Top-level dispatcher for `adg plugins <verb>`: render help, resolve aliases,
|
|
137
145
|
* look the verb up in the command table, then hand off to the per-verb handler
|
|
@@ -163,6 +171,134 @@ export async function runPlugins(rawVerb, rest) {
|
|
|
163
171
|
return runCache(rest);
|
|
164
172
|
return runPluginsVerb(verb, rest, cmd);
|
|
165
173
|
}
|
|
174
|
+
async function handleAdd(rest, cmd) {
|
|
175
|
+
const { values, positionals } = parseVerb("add", cmd.flags, rest);
|
|
176
|
+
const spec = positionals[0];
|
|
177
|
+
if (!spec)
|
|
178
|
+
fail("plugins add requires a <plugin-dir | owner/repo[@ref] | github-url>");
|
|
179
|
+
const tty = process.stdin.isTTY;
|
|
180
|
+
let global = Boolean(values.global);
|
|
181
|
+
if (!values.dir && values.global === undefined && values.project === undefined && tty) {
|
|
182
|
+
global = await selectScopeInteractive();
|
|
183
|
+
}
|
|
184
|
+
if (!values.dir)
|
|
185
|
+
global = promoteGlobalTrap(global);
|
|
186
|
+
const pluginsDir = values.dir
|
|
187
|
+
? resolve(values.dir)
|
|
188
|
+
: global
|
|
189
|
+
? globalPluginsDir()
|
|
190
|
+
: projectPluginsDir();
|
|
191
|
+
const only = resolveComponents(values.only);
|
|
192
|
+
const skillsSubset = values.skill && values.skill.length > 0 ? values.skill : undefined;
|
|
193
|
+
const mcpSubset = values.mcp && values.mcp.length > 0 ? values.mcp : undefined;
|
|
194
|
+
const narrowed = only !== undefined || skillsSubset !== undefined || mcpSubset !== undefined;
|
|
195
|
+
const { order, installed, removed, converted, agents } = await addPlugins({
|
|
196
|
+
spec,
|
|
197
|
+
pluginsDir,
|
|
198
|
+
ref: values.ref,
|
|
199
|
+
sparse: values.sparse,
|
|
200
|
+
path: values.path,
|
|
201
|
+
all: values.all,
|
|
202
|
+
plugins: values.plugin,
|
|
203
|
+
only,
|
|
204
|
+
skillsSubset,
|
|
205
|
+
mcpSubset,
|
|
206
|
+
withDeps: !values["no-deps"],
|
|
207
|
+
marketplaceName: values["marketplace-name"],
|
|
208
|
+
targets: values.target !== undefined ? resolveTargets(values.target) : undefined,
|
|
209
|
+
selectPlugins: tty ? selectPluginsInteractive : undefined,
|
|
210
|
+
selectTargets: tty && values.target === undefined ? selectTargetsInteractive : undefined,
|
|
211
|
+
confirmFull: tty && !narrowed ? confirmFullInstall : undefined,
|
|
212
|
+
selectComponents: tty && !narrowed ? selectComponentsInteractive : undefined,
|
|
213
|
+
activate: true,
|
|
214
|
+
scope: global ? "user" : "project",
|
|
215
|
+
});
|
|
216
|
+
for (const name of converted)
|
|
217
|
+
console.log(ui.meta(`converted native manifest -> .agents/.plugin.json: ${name}`));
|
|
218
|
+
for (const name of removed)
|
|
219
|
+
console.log(`${ui.warn("removed")} ${ui.name(name)}`);
|
|
220
|
+
if (order.length > 1)
|
|
221
|
+
console.log(ui.meta(`install order: ${order.join(" -> ")}`));
|
|
222
|
+
for (const res of installed) {
|
|
223
|
+
console.log(`${ui.ok("added")} ${ui.name(res.name)} ${ui.meta(`-> ${res.installedTo}`)}`);
|
|
224
|
+
console.log(ui.meta(` sourceHash: ${res.sourceHash}`));
|
|
225
|
+
console.log(ui.meta(` installedHash: ${res.installedHash}`));
|
|
226
|
+
for (const f of res.adapted)
|
|
227
|
+
console.log(ui.meta(` adapted: ${f}`));
|
|
228
|
+
}
|
|
229
|
+
for (const line of renderAgentReport(agents, "enabled"))
|
|
230
|
+
console.log(line);
|
|
231
|
+
}
|
|
232
|
+
async function handleLink(rest, cmd) {
|
|
233
|
+
const { values, positionals } = parseVerb("link", cmd.flags, rest);
|
|
234
|
+
const targets = resolveVerbTargets(values, "link");
|
|
235
|
+
const sc = await resolveActionScope(values, "link");
|
|
236
|
+
const names = positionals.length > 0 ? positionals : undefined;
|
|
237
|
+
for (const target of targets) {
|
|
238
|
+
const res = linkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
|
|
239
|
+
for (const action of res.actions) {
|
|
240
|
+
console.log(`${ui.ok("linked")} ${ui.name(action.name)} ${ui.meta(`[${res.target}]`)}${action.linkedTo ? ui.meta(` -> ${action.linkedTo}`) : ""}`);
|
|
241
|
+
for (const file of action.adapted)
|
|
242
|
+
console.log(ui.meta(` adapted: ${file}`));
|
|
243
|
+
}
|
|
244
|
+
if (res.cliSkipped)
|
|
245
|
+
printCliUnavailableNote(target, `manifests were generated, but nothing was enabled in ${target}.`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function handleUnlink(rest, cmd) {
|
|
249
|
+
const { values, positionals } = parseVerb("unlink", cmd.flags, rest);
|
|
250
|
+
const targets = resolveVerbTargets(values, "unlink");
|
|
251
|
+
const sc = await resolveActionScope(values, "unlink");
|
|
252
|
+
const names = positionals.length > 0 ? positionals : undefined;
|
|
253
|
+
for (const target of targets) {
|
|
254
|
+
const res = unlinkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
|
|
255
|
+
for (const name of res.unlinked)
|
|
256
|
+
console.log(`${ui.ok("unlinked")} ${ui.name(name)} ${ui.meta(`[${res.target}]`)}`);
|
|
257
|
+
if (res.cliSkipped) {
|
|
258
|
+
printCliUnavailableNote(target, `nothing was unlinked from ${target}.`);
|
|
259
|
+
}
|
|
260
|
+
else if (res.unlinked.length === 0 && targets.length === 1) {
|
|
261
|
+
console.log(ui.meta(`nothing to unlink from ${target}`));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function handleSync(rest, cmd) {
|
|
266
|
+
const { values, positionals } = parseVerb("sync", cmd.flags, rest);
|
|
267
|
+
const targets = resolveVerbTargets(values, "sync");
|
|
268
|
+
const sc = await resolveActionScope(values, "sync");
|
|
269
|
+
const names = positionals.length > 0 ? positionals : undefined;
|
|
270
|
+
for (const target of targets) {
|
|
271
|
+
const res = syncPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
|
|
272
|
+
for (const action of res.actions) {
|
|
273
|
+
const tail = action.synced ? ui.meta(` -> ${res.target}`) : "";
|
|
274
|
+
console.log(`${ui.ok("synced")} ${ui.name(action.name)} ${ui.meta(`[${res.target}]`)}${tail}`);
|
|
275
|
+
}
|
|
276
|
+
if (res.cliSkipped)
|
|
277
|
+
printCliUnavailableNote(target, `manifests were regenerated, but nothing was re-synced in ${target}.`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async function handleUpdate(rest, cmd) {
|
|
281
|
+
const { values, positionals } = parseVerb("update", cmd.flags, rest);
|
|
282
|
+
const source = positionals[0];
|
|
283
|
+
for (const sc of await resolveUpdateScopes(values)) {
|
|
284
|
+
if (sc.heading)
|
|
285
|
+
console.log(`${ui.name(sc.heading)}`);
|
|
286
|
+
try {
|
|
287
|
+
const result = await updatePlugins({
|
|
288
|
+
pluginsDir: sc.dir,
|
|
289
|
+
source,
|
|
290
|
+
all: values.all,
|
|
291
|
+
activate: true,
|
|
292
|
+
agentScope: sc.agentScope,
|
|
293
|
+
scope: { label: sc.label, globalDir: globalPluginsDir() },
|
|
294
|
+
});
|
|
295
|
+
printUpdateReport(result);
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
166
302
|
async function runPluginsVerb(verb, rest, cmd) {
|
|
167
303
|
switch (verb) {
|
|
168
304
|
case "init": {
|
|
@@ -205,69 +341,7 @@ async function runPluginsVerb(verb, rest, cmd) {
|
|
|
205
341
|
return;
|
|
206
342
|
}
|
|
207
343
|
case "add": {
|
|
208
|
-
|
|
209
|
-
const spec = positionals[0];
|
|
210
|
-
if (!spec)
|
|
211
|
-
fail("plugins add requires a <plugin-dir | owner/repo[@ref] | github-url>");
|
|
212
|
-
const tty = process.stdin.isTTY;
|
|
213
|
-
// Scope: honor an explicit --dir/--global/--project, else ask in a terminal
|
|
214
|
-
// (defaulting to project non-interactively).
|
|
215
|
-
let global = Boolean(values.global);
|
|
216
|
-
if (!values.dir && values.global === undefined && values.project === undefined && tty) {
|
|
217
|
-
global = await selectScopeInteractive();
|
|
218
|
-
}
|
|
219
|
-
// Guard the home==global trap: installing global plugins at project scope
|
|
220
|
-
// would pin them to the cwd. Skip for an explicit --dir store.
|
|
221
|
-
if (!values.dir)
|
|
222
|
-
global = promoteGlobalTrap(global);
|
|
223
|
-
const pluginsDir = values.dir
|
|
224
|
-
? resolve(values.dir)
|
|
225
|
-
: global
|
|
226
|
-
? globalPluginsDir()
|
|
227
|
-
: projectPluginsDir();
|
|
228
|
-
// A source may hold one plugin or a whole marketplace. addPlugins discovers
|
|
229
|
-
// all of them; in a terminal the user picks scope, then plugins, then agents,
|
|
230
|
-
// then (unless --only/--skill narrow it) chooses what to install per plugin.
|
|
231
|
-
// --all / --plugin / --path / --only / --skill narrow non-interactively.
|
|
232
|
-
const only = resolveComponents(values.only);
|
|
233
|
-
const skillsSubset = values.skill && values.skill.length > 0 ? values.skill : undefined;
|
|
234
|
-
const narrowed = only !== undefined || skillsSubset !== undefined;
|
|
235
|
-
const { order, installed, removed, converted, agents } = await addPlugins({
|
|
236
|
-
spec,
|
|
237
|
-
pluginsDir,
|
|
238
|
-
ref: values.ref,
|
|
239
|
-
sparse: values.sparse,
|
|
240
|
-
path: values.path,
|
|
241
|
-
all: values.all,
|
|
242
|
-
plugins: values.plugin,
|
|
243
|
-
only,
|
|
244
|
-
skillsSubset,
|
|
245
|
-
withDeps: !values["no-deps"],
|
|
246
|
-
marketplaceName: values["marketplace-name"],
|
|
247
|
-
targets: values.target !== undefined ? resolveTargets(values.target) : undefined,
|
|
248
|
-
selectPlugins: tty ? selectPluginsInteractive : undefined,
|
|
249
|
-
selectTargets: tty && values.target === undefined ? selectTargetsInteractive : undefined,
|
|
250
|
-
confirmFull: tty && !narrowed ? confirmFullInstall : undefined,
|
|
251
|
-
selectComponents: tty && !narrowed ? selectComponentsInteractive : undefined,
|
|
252
|
-
// Make the install actually usable in the chosen agents, not just stored.
|
|
253
|
-
activate: true,
|
|
254
|
-
scope: global ? "user" : "project",
|
|
255
|
-
});
|
|
256
|
-
for (const name of converted)
|
|
257
|
-
console.log(ui.meta(`converted native manifest -> .agents/.plugin.json: ${name}`));
|
|
258
|
-
for (const name of removed)
|
|
259
|
-
console.log(`${ui.warn("removed")} ${ui.name(name)}`);
|
|
260
|
-
if (order.length > 1)
|
|
261
|
-
console.log(ui.meta(`install order: ${order.join(" -> ")}`));
|
|
262
|
-
for (const res of installed) {
|
|
263
|
-
console.log(`${ui.ok("added")} ${ui.name(res.name)} ${ui.meta(`-> ${res.installedTo}`)}`);
|
|
264
|
-
console.log(ui.meta(` sourceHash: ${res.sourceHash}`));
|
|
265
|
-
console.log(ui.meta(` installedHash: ${res.installedHash}`));
|
|
266
|
-
for (const f of res.adapted)
|
|
267
|
-
console.log(ui.meta(` adapted: ${f}`));
|
|
268
|
-
}
|
|
269
|
-
for (const line of renderAgentReport(agents, "enabled"))
|
|
270
|
-
console.log(line);
|
|
344
|
+
await handleAdd(rest, cmd);
|
|
271
345
|
return;
|
|
272
346
|
}
|
|
273
347
|
case "import-skills": {
|
|
@@ -289,23 +363,7 @@ async function runPluginsVerb(verb, rest, cmd) {
|
|
|
289
363
|
return;
|
|
290
364
|
}
|
|
291
365
|
case "link": {
|
|
292
|
-
|
|
293
|
-
const targets = values.target === "all"
|
|
294
|
-
? resolveTargets("all")
|
|
295
|
-
: [requireSingleTarget(values.target, "link")];
|
|
296
|
-
const sc = await resolveActionScope(values, "link");
|
|
297
|
-
const names = positionals.length > 0 ? positionals : undefined;
|
|
298
|
-
for (const target of targets) {
|
|
299
|
-
const res = linkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
|
|
300
|
-
for (const a of res.actions) {
|
|
301
|
-
console.log(`${ui.ok("linked")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${a.linkedTo ? ui.meta(` -> ${a.linkedTo}`) : ""}`);
|
|
302
|
-
for (const f of a.adapted)
|
|
303
|
-
console.log(ui.meta(` adapted: ${f}`));
|
|
304
|
-
}
|
|
305
|
-
if (res.cliSkipped) {
|
|
306
|
-
console.log(ui.warn(`note: \`${target}\` CLI not found — manifests were generated, but nothing was enabled in ${target}.`));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
366
|
+
await handleLink(rest, cmd);
|
|
309
367
|
return;
|
|
310
368
|
}
|
|
311
369
|
case "disable":
|
|
@@ -331,67 +389,15 @@ async function runPluginsVerb(verb, rest, cmd) {
|
|
|
331
389
|
return;
|
|
332
390
|
}
|
|
333
391
|
case "unlink": {
|
|
334
|
-
|
|
335
|
-
const targets = values.target === "all"
|
|
336
|
-
? resolveTargets("all")
|
|
337
|
-
: [requireSingleTarget(values.target, "unlink")];
|
|
338
|
-
const sc = await resolveActionScope(values, "unlink");
|
|
339
|
-
const names = positionals.length > 0 ? positionals : undefined;
|
|
340
|
-
for (const target of targets) {
|
|
341
|
-
const res = unlinkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
|
|
342
|
-
for (const name of res.unlinked)
|
|
343
|
-
console.log(`${ui.ok("unlinked")} ${ui.name(name)} ${ui.meta(`[${res.target}]`)}`);
|
|
344
|
-
if (res.cliSkipped) {
|
|
345
|
-
console.log(ui.warn(`note: \`${target}\` CLI not found — nothing was unlinked from ${target}.`));
|
|
346
|
-
}
|
|
347
|
-
else if (res.unlinked.length === 0) {
|
|
348
|
-
if (targets.length === 1) {
|
|
349
|
-
console.log(ui.meta(`nothing to unlink from ${target}`));
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
392
|
+
await handleUnlink(rest, cmd);
|
|
353
393
|
return;
|
|
354
394
|
}
|
|
355
395
|
case "sync": {
|
|
356
|
-
|
|
357
|
-
const targets = values.target === "all"
|
|
358
|
-
? resolveTargets("all")
|
|
359
|
-
: [requireSingleTarget(values.target, "sync")];
|
|
360
|
-
const sc = await resolveActionScope(values, "sync");
|
|
361
|
-
const names = positionals.length > 0 ? positionals : undefined;
|
|
362
|
-
for (const target of targets) {
|
|
363
|
-
const res = syncPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
|
|
364
|
-
for (const a of res.actions) {
|
|
365
|
-
const tail = a.synced ? ui.meta(` -> ${res.target}`) : "";
|
|
366
|
-
console.log(`${ui.ok("synced")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${tail}`);
|
|
367
|
-
}
|
|
368
|
-
if (res.cliSkipped) {
|
|
369
|
-
console.log(ui.warn(`note: \`${target}\` CLI not found — manifests were regenerated, but nothing was re-synced in ${target}.`));
|
|
370
|
-
}
|
|
371
|
-
}
|
|
396
|
+
await handleSync(rest, cmd);
|
|
372
397
|
return;
|
|
373
398
|
}
|
|
374
399
|
case "update": {
|
|
375
|
-
|
|
376
|
-
const source = positionals[0];
|
|
377
|
-
for (const sc of await resolveUpdateScopes(values)) {
|
|
378
|
-
if (sc.heading)
|
|
379
|
-
console.log(`${ui.name(sc.heading)}`);
|
|
380
|
-
try {
|
|
381
|
-
const result = await updatePlugins({
|
|
382
|
-
pluginsDir: sc.dir,
|
|
383
|
-
source,
|
|
384
|
-
all: values.all,
|
|
385
|
-
activate: true,
|
|
386
|
-
agentScope: sc.agentScope,
|
|
387
|
-
scope: { label: sc.label, globalDir: globalPluginsDir() },
|
|
388
|
-
});
|
|
389
|
-
printUpdateReport(result);
|
|
390
|
-
}
|
|
391
|
-
catch (err) {
|
|
392
|
-
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
400
|
+
await handleUpdate(rest, cmd);
|
|
395
401
|
return;
|
|
396
402
|
}
|
|
397
403
|
case "remove": {
|
|
@@ -556,9 +562,7 @@ async function runMarketplace(args) {
|
|
|
556
562
|
const source = positionals[0];
|
|
557
563
|
if (!source)
|
|
558
564
|
fail("marketplace sync requires a <source>");
|
|
559
|
-
const targets = values
|
|
560
|
-
? resolveTargets("all")
|
|
561
|
-
: [requireSingleTarget(values.target, "marketplace sync")];
|
|
565
|
+
const targets = resolveVerbTargets(values, "marketplace sync");
|
|
562
566
|
const sc = await resolveActionScope(values, "marketplace sync");
|
|
563
567
|
for (const target of targets) {
|
|
564
568
|
const res = marketplaceSync({
|
|
@@ -572,7 +576,7 @@ async function runMarketplace(args) {
|
|
|
572
576
|
console.log(`${ui.ok("synced")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${a.synced ? ui.meta(` -> ${res.target}`) : ""}`);
|
|
573
577
|
}
|
|
574
578
|
if (res.cliSkipped) {
|
|
575
|
-
|
|
579
|
+
printCliUnavailableNote(target, `manifests were regenerated, but nothing was re-synced in ${target}.`);
|
|
576
580
|
}
|
|
577
581
|
}
|
|
578
582
|
return;
|
package/dist/src/cli/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export const FLAGS = {
|
|
|
25
25
|
author: { type: "string", hint: "<name>", help: "plugin author" },
|
|
26
26
|
type: { type: "string", hint: "plugin|marketplace|all", help: "init: which .agents/ artifact to scaffold (default plugin)" },
|
|
27
27
|
skill: { type: "string", short: "s", multiple: true, hint: "<name>", help: "skill name (init: seed one · add: limit to these)" },
|
|
28
|
+
mcp: { type: "string", short: "m", multiple: true, hint: "<name>", help: "MCP server name (add: limit to these)" },
|
|
28
29
|
only: { type: "string", hint: "<types>", help: "limit to these component types (skills,agents,commands,mcp,hooks,apps)" },
|
|
29
30
|
as: { type: "string", hint: "<name>", help: "plugin name to wrap the skills as" },
|
|
30
31
|
prefix: { type: "string", hint: "<p>", help: "prefix imported skill names" },
|
|
@@ -49,12 +50,13 @@ export const PLUGIN_COMMANDS = {
|
|
|
49
50
|
blurb: "In a terminal, add guides you through: scope → plugins → agents → what to install.\n" +
|
|
50
51
|
"By default it installs everything; choose 'No, let me choose' to pick components,\n" +
|
|
51
52
|
"or pass the flags below to skip any prompt (e.g. for scripts/CI).",
|
|
52
|
-
flags: ["all", "plugin", "only", "skill", "target", "no-deps", "path", "ref", "sparse", "marketplace-name", ...SCOPE],
|
|
53
|
+
flags: ["all", "plugin", "only", "skill", "mcp", "target", "no-deps", "path", "ref", "sparse", "marketplace-name", ...SCOPE],
|
|
53
54
|
examples: [
|
|
54
55
|
"adg plugins add owner/repo # guided",
|
|
55
56
|
"adg plugins add owner/repo --all --global # all plugins, global, non-interactive",
|
|
56
57
|
"adg plugins add owner/repo --only skills # expose only the skills",
|
|
57
58
|
"adg plugins add owner/repo --skill brainstorming --skill writing-plans",
|
|
59
|
+
"adg plugins add owner/repo --mcp server-name",
|
|
58
60
|
],
|
|
59
61
|
start: true,
|
|
60
62
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { basename, join, relative, resolve } from "node:path";
|
|
4
4
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -12,6 +12,7 @@ import { packageFilter, PROJECTION_DIRS } from "../package.js";
|
|
|
12
12
|
import { lockPath, marketplacePath, marketplaceSourcePath, pluginDir, pluginSourceCacheDir } from "../paths.js";
|
|
13
13
|
import { readLock, upsertEntry, writeLock } from "../lock.js";
|
|
14
14
|
import { ADG_MANIFEST_PATH, readManifest } from "../manifest.js";
|
|
15
|
+
import { recordTelemetryEvent } from "../telemetry.js";
|
|
15
16
|
import { readMarketplace, upsertMarketplacePlugin, writeMarketplace } from "../marketplace.js";
|
|
16
17
|
import { resolveInstallOrder } from "../deps.js";
|
|
17
18
|
import { cloneGitHub, parseSource, scanNativePlugins, scanPlugins } from "../sources.js";
|
|
@@ -38,7 +39,7 @@ function contentHash(dir, manifest) {
|
|
|
38
39
|
*/
|
|
39
40
|
export function installPlugin(opts) {
|
|
40
41
|
const source = resolve(opts.source);
|
|
41
|
-
const manifest = readManifest(source);
|
|
42
|
+
const manifest = readManifest(source, opts.telemetrySpan);
|
|
42
43
|
const name = manifest.name;
|
|
43
44
|
// Local installs stay flat; remote sources derive a per-marketplace dir from
|
|
44
45
|
// their origin. The default (no origin) is a flat local copy-in.
|
|
@@ -55,6 +56,27 @@ export function installPlugin(opts) {
|
|
|
55
56
|
// partial installs survive re-install / `marketplace upgrade`.
|
|
56
57
|
const desiredSelection = normalizePluginSelection(opts.selection ?? prev?.selection);
|
|
57
58
|
const selection = resolveSelectionDependencies(manifest, desiredSelection);
|
|
59
|
+
if (selection) {
|
|
60
|
+
const contents = pluginContents(source, manifest);
|
|
61
|
+
if (selection.skills) {
|
|
62
|
+
const invalid = selection.skills.filter((s) => !contents.skills.includes(s));
|
|
63
|
+
if (invalid.length > 0) {
|
|
64
|
+
throw new Error(`selected skill(s) not declared: ${invalid.join(", ")}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (selection.mcp) {
|
|
68
|
+
const invalid = selection.mcp.filter((s) => !contents.mcp.includes(s));
|
|
69
|
+
if (invalid.length > 0) {
|
|
70
|
+
throw new Error(`selected mcp server(s) not declared: ${invalid.join(", ")}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
recordTelemetryEvent("adg.install.selection", {
|
|
74
|
+
plugin: name,
|
|
75
|
+
"components.count": selection.components.length,
|
|
76
|
+
"skills.count": selection.skills ? selection.skills.length : -1,
|
|
77
|
+
"mcp.count": selection.mcp ? selection.mcp.length : -1,
|
|
78
|
+
}, opts.telemetrySpan);
|
|
79
|
+
}
|
|
58
80
|
const sourceHash = contentHash(source, manifest);
|
|
59
81
|
const cacheDir = pluginSourceCacheDir(opts.pluginsDir, name);
|
|
60
82
|
return withPluginSourceCache(source, cacheDir, manifest, (snapshot) => {
|
|
@@ -140,16 +162,7 @@ function discoverPlugins(root) {
|
|
|
140
162
|
if (native.kind === "adg")
|
|
141
163
|
continue;
|
|
142
164
|
const raw = JSON.parse(readFileSync(native.manifestFile, "utf8"));
|
|
143
|
-
const manifest = fromNativeManifest(raw, native.kind);
|
|
144
|
-
// A Claude manifest omits `hooks` (Claude auto-loads hooks/hooks.json), and
|
|
145
|
-
// `walkNative` prefers it over a sibling Codex manifest that *does* declare
|
|
146
|
-
// hooks — so the reverse-adapt would silently drop the hooks payload. Recover
|
|
147
|
-
// it from disk: a hooks/ directory means the ADG manifest must declare it, or
|
|
148
|
-
// packagedRoots won't copy it and every downstream projection loses hooks.
|
|
149
|
-
const hooksDir = join(native.dir, "hooks");
|
|
150
|
-
if (!manifest.hooks && existsSync(hooksDir) && statSync(hooksDir).isDirectory()) {
|
|
151
|
-
manifest.hooks = "./hooks/";
|
|
152
|
-
}
|
|
165
|
+
const manifest = fromNativeManifest(raw, native.kind, native.dir);
|
|
153
166
|
writeJson(join(native.dir, ADG_MANIFEST_PATH), manifest);
|
|
154
167
|
converted.push(manifest.name);
|
|
155
168
|
}
|
|
@@ -196,10 +209,11 @@ async function selectPluginNames(opts, candidates, workRoot, converted) {
|
|
|
196
209
|
*/
|
|
197
210
|
async function resolveSelections(opts, selected, candidates) {
|
|
198
211
|
const selections = new Map();
|
|
199
|
-
if (opts.only || opts.skillsSubset) {
|
|
212
|
+
if (opts.only || opts.skillsSubset || opts.mcpSubset) {
|
|
200
213
|
const flagSelection = {
|
|
201
214
|
components: opts.only ?? [...COMPONENT_TYPES],
|
|
202
215
|
...(opts.skillsSubset ? { skills: opts.skillsSubset } : {}),
|
|
216
|
+
...(opts.mcpSubset ? { mcp: opts.mcpSubset } : {}),
|
|
203
217
|
};
|
|
204
218
|
for (const name of selected)
|
|
205
219
|
selections.set(name, flagSelection);
|
|
@@ -214,7 +228,7 @@ async function resolveSelections(opts, selected, candidates) {
|
|
|
214
228
|
const contents = pluginContents(cand.dir, cand.manifest);
|
|
215
229
|
const present = presentComponents(contents);
|
|
216
230
|
// Nothing meaningful to pick: a lone category with at most one member.
|
|
217
|
-
if (present.length <= 1 && contents.skills.length <= 1)
|
|
231
|
+
if (present.length <= 1 && contents.skills.length <= 1 && contents.mcp.length <= 1)
|
|
218
232
|
continue;
|
|
219
233
|
const skillDescription = skillDescriptionLoader(cand.dir, cand.manifest);
|
|
220
234
|
selections.set(name, await opts.selectComponents({ name, contents, present, skillDescription }));
|
|
@@ -268,6 +282,31 @@ function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
|
|
|
268
282
|
}
|
|
269
283
|
return stale;
|
|
270
284
|
}
|
|
285
|
+
function activateInstalled(opts, targets, installed, existingPlugins) {
|
|
286
|
+
const updatedLock = readLock(lockPath(opts.pluginsDir));
|
|
287
|
+
const eligible = installed.filter((result) => pluginState(updatedLock.plugins[result.name]) === "enabled");
|
|
288
|
+
const toActivate = opts.skipUnchanged ? eligible.filter((result) => result.changed) : eligible;
|
|
289
|
+
if (!opts.activate || toActivate.length === 0)
|
|
290
|
+
return undefined;
|
|
291
|
+
const resolved = opts.agents ?? resolveAgents(targets);
|
|
292
|
+
const scope = opts.scope ?? "project";
|
|
293
|
+
const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
|
|
294
|
+
return resolved.map((agent) => {
|
|
295
|
+
const queryResult = agent.listInstalled?.(ctxFor([]));
|
|
296
|
+
const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
|
|
297
|
+
const alreadyInstalled = (name) => agentInstalled !== undefined
|
|
298
|
+
? agentInstalled.includes(name)
|
|
299
|
+
: existingPlugins.has(name);
|
|
300
|
+
const activateNames = toActivate.filter((result) => !alreadyInstalled(result.name)).map((result) => result.name);
|
|
301
|
+
const refreshNames = toActivate.filter((result) => alreadyInstalled(result.name)).map((result) => result.name);
|
|
302
|
+
const parts = [];
|
|
303
|
+
if (activateNames.length > 0)
|
|
304
|
+
parts.push(agent.activate(ctxFor(activateNames)));
|
|
305
|
+
if (refreshNames.length > 0)
|
|
306
|
+
parts.push(agent.refresh(ctxFor(refreshNames)));
|
|
307
|
+
return parts.reduce((acc, result) => ({ agent: result.agent, affected: [...acc.affected, ...result.affected], skipped: acc.skipped && result.skipped }), { agent: agent.id, affected: [], skipped: true });
|
|
308
|
+
});
|
|
309
|
+
}
|
|
271
310
|
/**
|
|
272
311
|
* The unified install entrypoint. Treats any source as a marketplace: clone or
|
|
273
312
|
* read it, discover every plugin (ADG plus reverse-adapted native), choose a
|
|
@@ -355,38 +394,7 @@ export async function addPlugins(opts) {
|
|
|
355
394
|
// undefined targets = all registered agents. Under skipUnchanged (the update
|
|
356
395
|
// path) only re-activate plugins that actually changed — re-running an agent
|
|
357
396
|
// CLI for an untouched plugin is wasted work.
|
|
358
|
-
|
|
359
|
-
const updatedLock = readLock(lockPath(opts.pluginsDir));
|
|
360
|
-
const eligible = installed.filter((result) => pluginState(updatedLock.plugins[result.name]) === "enabled");
|
|
361
|
-
const toActivate = opts.skipUnchanged ? eligible.filter((r) => r.changed) : eligible;
|
|
362
|
-
if (opts.activate && toActivate.length > 0) {
|
|
363
|
-
const resolved = opts.agents ?? resolveAgents(targets);
|
|
364
|
-
const scope = opts.scope ?? "project";
|
|
365
|
-
const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
|
|
366
|
-
agents = resolved.map((a) => {
|
|
367
|
-
const queryResult = a.listInstalled?.(ctxFor([]));
|
|
368
|
-
const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
|
|
369
|
-
const alreadyInstalled = (name) => agentInstalled !== undefined
|
|
370
|
-
? agentInstalled.includes(name)
|
|
371
|
-
: existingPlugins.has(name);
|
|
372
|
-
// Existing plugins must go through refresh even on an explicit `add`:
|
|
373
|
-
// agents like Claude cache an installed copy, and their plain install
|
|
374
|
-
// command is a no-op when the plugin already exists. If the agent can
|
|
375
|
-
// enumerate live installs, trust that state; otherwise fall back to the
|
|
376
|
-
// ADG lock to preserve clean-update behavior.
|
|
377
|
-
const activateNames = toActivate.filter((r) => !alreadyInstalled(r.name)).map((r) => r.name);
|
|
378
|
-
const refreshNames = toActivate.filter((r) => alreadyInstalled(r.name)).map((r) => r.name);
|
|
379
|
-
// An agent may run both lifecycles (new installs + updates) in one pass;
|
|
380
|
-
// merge into the existing affected/skipped contract so downstream report
|
|
381
|
-
// and consolidation (renderAgentReport, mergeAgentResults) stay unchanged.
|
|
382
|
-
const parts = [];
|
|
383
|
-
if (activateNames.length > 0)
|
|
384
|
-
parts.push(a.activate(ctxFor(activateNames)));
|
|
385
|
-
if (refreshNames.length > 0)
|
|
386
|
-
parts.push(a.refresh(ctxFor(refreshNames)));
|
|
387
|
-
return parts.reduce((acc, r) => ({ agent: r.agent, affected: [...acc.affected, ...r.affected], skipped: acc.skipped && r.skipped }), { agent: a.id, affected: [], skipped: true });
|
|
388
|
-
});
|
|
389
|
-
}
|
|
397
|
+
const agents = activateInstalled(opts, targets, installed, existingPlugins);
|
|
390
398
|
return { order, installed, removed, converted, available, agents };
|
|
391
399
|
}
|
|
392
400
|
finally {
|
|
@@ -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
|
/**
|
|
8
5
|
* Project installed plugins into an agent: (re)generate that agent's manifest
|
|
9
6
|
* from each plugin (honoring its partial-install selection), then enable the
|
|
@@ -20,18 +17,8 @@ export function linkPlugins(opts) {
|
|
|
20
17
|
throw new Error(`disabled plugin(s): ${names.join(", ")}. Run \`adg plugins enable ${names.join(" ")}\`.`);
|
|
21
18
|
}
|
|
22
19
|
const enabled = selected.filter((p) => pluginState(p) === "enabled");
|
|
23
|
-
const actions =
|
|
24
|
-
|
|
25
|
-
const result = installPlugin({
|
|
26
|
-
source: pluginRematerializationSource(opts.pluginsDir, p.name, p.origin),
|
|
27
|
-
pluginsDir: opts.pluginsDir,
|
|
28
|
-
origin: p.origin,
|
|
29
|
-
selection: p.selection,
|
|
30
|
-
targets: [...ADAPTER_TARGETS],
|
|
31
|
-
forceMaterialize: true,
|
|
32
|
-
});
|
|
33
|
-
actions.push({ name: p.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget) });
|
|
34
|
-
}
|
|
20
|
+
const actions = rematerializeInstalled(opts.pluginsDir, enabled)
|
|
21
|
+
.map((result) => ({ name: result.name, adapted: adaptedFilesForTarget(result.installedTo, result.adapted, adaptTarget) }));
|
|
35
22
|
if (!agent)
|
|
36
23
|
return { target: opts.target, actions };
|
|
37
24
|
if (actions.length === 0)
|
|
@@ -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 { pluginRematerializationSource } from "../paths.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,14 @@ 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: pluginRematerializationSource(pluginsDir, plugin.name, plugin.origin),
|
|
42
|
+
pluginsDir,
|
|
43
|
+
origin: plugin.origin,
|
|
44
|
+
selection: plugin.selection,
|
|
45
|
+
targets: [...ADAPTER_TARGETS],
|
|
46
|
+
forceMaterialize: true,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
@@ -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,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,16 +9,8 @@ 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 };
|
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
|
}
|
package/dist/src/manifest.js
CHANGED
|
@@ -46,7 +46,11 @@ export function readManifest(pluginDir, telemetrySpan) {
|
|
|
46
46
|
throw new ManifestError([`${file} is not valid JSON: ${err.message}`]);
|
|
47
47
|
}
|
|
48
48
|
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
49
|
-
const
|
|
49
|
+
const m = raw;
|
|
50
|
+
if (m.mcpServers === undefined && existsSync(join(pluginDir, ".mcp.json"))) {
|
|
51
|
+
m.mcpServers = "./.mcp.json";
|
|
52
|
+
}
|
|
53
|
+
const schemaVersion = m.schemaVersion;
|
|
50
54
|
if (typeof schemaVersion === "string") {
|
|
51
55
|
recordTelemetryEvent("adg.manifest.read", {
|
|
52
56
|
"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))
|
package/dist/src/mcp.js
CHANGED
|
@@ -1,4 +1,63 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
1
2
|
/** ADG's canonical MCP config pointer. */
|
|
2
3
|
export function mcpConfigPath(manifest) {
|
|
3
4
|
return manifest.mcpServers;
|
|
4
5
|
}
|
|
6
|
+
/** Filter the servers defined in the MCP config file. */
|
|
7
|
+
export function filterMcpConfig(file, allowedNames) {
|
|
8
|
+
if (!existsSync(file))
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
const json = JSON.parse(readFileSync(file, "utf8"));
|
|
12
|
+
if (typeof json !== "object" || json === null) {
|
|
13
|
+
throw new Error("MCP config root must be an object");
|
|
14
|
+
}
|
|
15
|
+
// Find and validate all defined server names
|
|
16
|
+
const definedNames = new Set();
|
|
17
|
+
let hasMcpServersOrServers = false;
|
|
18
|
+
for (const key of ["mcpServers", "servers"]) {
|
|
19
|
+
const servers = json[key];
|
|
20
|
+
if (servers !== undefined) {
|
|
21
|
+
if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
|
|
22
|
+
throw new Error(`MCP config "${key}" must be an object`);
|
|
23
|
+
}
|
|
24
|
+
hasMcpServersOrServers = true;
|
|
25
|
+
for (const name of Object.keys(servers)) {
|
|
26
|
+
definedNames.add(name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (allowedNames.length > 0 && !hasMcpServersOrServers) {
|
|
31
|
+
throw new Error("MCP config does not define any servers");
|
|
32
|
+
}
|
|
33
|
+
const missing = allowedNames.filter((name) => !definedNames.has(name));
|
|
34
|
+
if (missing.length > 0) {
|
|
35
|
+
throw new Error(`selected mcp server(s) not declared: ${missing.join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
const allowed = new Set(allowedNames);
|
|
38
|
+
let changed = false;
|
|
39
|
+
for (const key of ["mcpServers", "servers"]) {
|
|
40
|
+
const servers = json[key];
|
|
41
|
+
if (servers && typeof servers === "object" && !Array.isArray(servers)) {
|
|
42
|
+
const obj = servers;
|
|
43
|
+
const newObj = {};
|
|
44
|
+
for (const [name, config] of Object.entries(obj)) {
|
|
45
|
+
if (allowed.has(name)) {
|
|
46
|
+
newObj[name] = config;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
changed = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
json[key] = newObj;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (changed) {
|
|
56
|
+
writeFileSync(file, JSON.stringify(json, null, 2), "utf8");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
61
|
+
throw new Error("Failed to filter MCP config at " + file + ": " + msg);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/dist/src/types.js
CHANGED
|
@@ -12,9 +12,12 @@ export function normalizePluginSelection(selection) {
|
|
|
12
12
|
const components = new Set(selection.components);
|
|
13
13
|
if (selection.skills !== undefined)
|
|
14
14
|
components.add("skills");
|
|
15
|
+
if (selection.mcp !== undefined)
|
|
16
|
+
components.add("mcp");
|
|
15
17
|
return {
|
|
16
18
|
components: COMPONENT_TYPES.filter((component) => components.has(component)),
|
|
17
19
|
...(selection.skills !== undefined ? { skills: [...new Set(selection.skills)].sort() } : {}),
|
|
20
|
+
...(selection.mcp !== undefined ? { mcp: [...new Set(selection.mcp)].sort() } : {}),
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
/** Expand mandatory component/skill requirements to a stable closure. */
|
|
@@ -53,6 +56,7 @@ export function resolveSelectionDependencies(manifest, selection) {
|
|
|
53
56
|
return {
|
|
54
57
|
components: COMPONENT_TYPES.filter((component) => components.has(component)),
|
|
55
58
|
...(skills ? { skills: [...skills].sort() } : {}),
|
|
59
|
+
...(normalized.mcp !== undefined ? { mcp: [...new Set(normalized.mcp)].sort() } : {}),
|
|
56
60
|
};
|
|
57
61
|
}
|
|
58
62
|
export function pluginState(entry) {
|