@rbbtsn0w/adg 0.3.0 → 0.4.0-beta.2
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 +18 -5
- package/dist/bin/adg.js +10 -621
- package/dist/src/agents/antigravity.js +55 -4
- package/dist/src/agents/base.js +16 -1
- package/dist/src/agents/claude.js +57 -4
- package/dist/src/agents/codex.js +50 -5
- package/dist/src/cli/handlers.js +454 -0
- package/dist/src/cli/index.js +319 -0
- package/dist/src/commands/link.js +2 -2
- package/dist/src/commands/marketplace.js +17 -42
- package/dist/src/commands/projection.js +28 -0
- package/dist/src/commands/status.js +35 -0
- package/dist/src/commands/sync.js +29 -0
- package/dist/src/commands/unlink.js +39 -0
- package/dist/src/render/plugins.js +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
4
|
+
import { COMPONENT_TYPES } from "../types.js";
|
|
5
|
+
import { globalPluginsDir, projectPluginsDir } from "../paths.js";
|
|
6
|
+
import { ui } from "../render/ui.js";
|
|
7
|
+
export const FLAGS = {
|
|
8
|
+
// Short flags are first-letter aliases. Where several long flags share a
|
|
9
|
+
// first letter, the highest-frequency one wins the short and the rest stay
|
|
10
|
+
// long-only: d → dir (not description) a → all (not author/as)
|
|
11
|
+
// s → skill (not sparse) p → plugin (not path/project/prefix)
|
|
12
|
+
dir: { type: "string", short: "d", hint: "<dir>", help: "install into an explicit directory" },
|
|
13
|
+
global: { type: "boolean", short: "g", help: "use ~/.agents/plugins (across all projects)" },
|
|
14
|
+
project: { type: "boolean", help: "use <repo>/.agents/plugins (default)" },
|
|
15
|
+
target: { type: "string", short: "t", hint: "claude|codex|antigravity|all", help: "runtime(s) to adapt for" },
|
|
16
|
+
all: { type: "boolean", short: "a", help: "select all available plugins" },
|
|
17
|
+
plugin: { type: "string", short: "p", multiple: true, hint: "<name>", help: "select a specific plugin (repeatable)" },
|
|
18
|
+
"no-deps": { type: "boolean", short: "n", help: "don't install dependencies" },
|
|
19
|
+
path: { type: "string", hint: "<subdir>", help: "install only this subdir of the source" },
|
|
20
|
+
ref: { type: "string", short: "r", hint: "<ref>", help: "pin a git ref (branch/tag/sha)" },
|
|
21
|
+
sparse: { type: "string", multiple: true, hint: "<path>", help: "sparse-checkout path (repeatable)" },
|
|
22
|
+
"marketplace-name": { type: "string", hint: "<name>", help: "override the marketplace key" },
|
|
23
|
+
force: { type: "boolean", short: "f", help: "skip confirmation / force" },
|
|
24
|
+
description: { type: "string", hint: "<text>", help: "plugin description" },
|
|
25
|
+
author: { type: "string", hint: "<name>", help: "plugin author" },
|
|
26
|
+
type: { type: "string", hint: "plugin|marketplace|all", help: "init: which .agents/ artifact to scaffold (default plugin)" },
|
|
27
|
+
skill: { type: "string", short: "s", multiple: true, hint: "<name>", help: "skill name (init: seed one · add: limit to these)" },
|
|
28
|
+
only: { type: "string", hint: "<types>", help: "limit to these component types (skills,agents,commands,mcp,hooks,apps)" },
|
|
29
|
+
as: { type: "string", hint: "<name>", help: "plugin name to wrap the skills as" },
|
|
30
|
+
prefix: { type: "string", hint: "<p>", help: "prefix imported skill names" },
|
|
31
|
+
verbose: { type: "boolean", short: "v", help: "expand each component to its member names" },
|
|
32
|
+
};
|
|
33
|
+
// Scope flags recur on almost every command; name the group once.
|
|
34
|
+
export const SCOPE = ["project", "global", "dir"];
|
|
35
|
+
export function optionsFor(names) {
|
|
36
|
+
const out = {};
|
|
37
|
+
for (const n of names) {
|
|
38
|
+
const f = FLAGS[n];
|
|
39
|
+
out[n] = { type: f.type, ...(f.short ? { short: f.short } : {}), ...(f.multiple ? { multiple: true } : {}) };
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
export const PLUGIN_COMMANDS = {
|
|
44
|
+
add: {
|
|
45
|
+
summary: "install plugins from a source",
|
|
46
|
+
synopsis: "adg plugins add <source>",
|
|
47
|
+
positional: "<source> = <local-dir> | <owner/repo[@ref]> | <github-url>",
|
|
48
|
+
blurb: "In a terminal, add guides you through: scope → plugins → agents → what to install.\n" +
|
|
49
|
+
"By default it installs everything; choose 'No, let me choose' to pick components,\n" +
|
|
50
|
+
"or pass the flags below to skip any prompt (e.g. for scripts/CI).",
|
|
51
|
+
flags: ["all", "plugin", "only", "skill", "target", "no-deps", "path", "ref", "sparse", "marketplace-name", ...SCOPE],
|
|
52
|
+
examples: [
|
|
53
|
+
"adg plugins add owner/repo # guided",
|
|
54
|
+
"adg plugins add owner/repo --all --global # all plugins, global, non-interactive",
|
|
55
|
+
"adg plugins add owner/repo --only skills # expose only the skills",
|
|
56
|
+
"adg plugins add owner/repo --skill brainstorming --skill writing-plans",
|
|
57
|
+
],
|
|
58
|
+
start: true,
|
|
59
|
+
},
|
|
60
|
+
list: {
|
|
61
|
+
summary: "list installed plugins",
|
|
62
|
+
synopsis: "adg plugins list",
|
|
63
|
+
blurb: "Each plugin shows a one-line summary of what it contains. Add --verbose\nto expand every component (skills, agents, commands, …) to its member names.",
|
|
64
|
+
flags: ["verbose", ...SCOPE],
|
|
65
|
+
},
|
|
66
|
+
status: {
|
|
67
|
+
summary: "show store-vs-agent drift per runtime",
|
|
68
|
+
synopsis: "adg plugins status [--target claude|codex|antigravity]",
|
|
69
|
+
blurb: "Query each agent's CLI live and diff it against the store: what's in\nsync, missing (needs `link`/`sync`), or present in the agent only. Each drift\nrow carries the command that repairs it. Inspects the active scope (--global →\nuser, else project). Name-level only — run `sync` if unsure.",
|
|
70
|
+
flags: ["target", ...SCOPE],
|
|
71
|
+
},
|
|
72
|
+
update: {
|
|
73
|
+
summary: "pull upstream changes for installed plugins",
|
|
74
|
+
synopsis: "adg plugins update [<source>]",
|
|
75
|
+
positional: "<source> limit to one source key from `adg plugins marketplace list` (default: all)",
|
|
76
|
+
blurb: "Re-fetches every remote source and refreshes the plugins installed from it,\n" +
|
|
77
|
+
"reporting what changed, what's unchanged, what was deleted upstream, and what's\n" +
|
|
78
|
+
"newly available (install those too with --all). Local-source plugins are\n" +
|
|
79
|
+
"rescanned in place. In a terminal, it asks whether to update project, global,\n" +
|
|
80
|
+
"or both; pass a scope flag to skip the prompt.\n\n" +
|
|
81
|
+
"This is the plugins-domain twin of `adg skills update`.",
|
|
82
|
+
flags: ["all", ...SCOPE],
|
|
83
|
+
examples: [
|
|
84
|
+
"adg plugins update # guided: project / global / both",
|
|
85
|
+
"adg plugins update --global # every global source",
|
|
86
|
+
"adg plugins update owner/repo # just one source",
|
|
87
|
+
"adg plugins update owner/repo --all # also install newly-added plugins",
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
remove: {
|
|
91
|
+
summary: "uninstall a plugin",
|
|
92
|
+
synopsis: "adg plugins remove <name>",
|
|
93
|
+
positional: "<name> an installed plugin name (see `adg plugins list`)",
|
|
94
|
+
flags: ["force", ...SCOPE],
|
|
95
|
+
},
|
|
96
|
+
init: {
|
|
97
|
+
summary: "scaffold a new plugin or marketplace (.agents/ only)",
|
|
98
|
+
synopsis: "adg plugins init <name> [--type plugin|marketplace|all]",
|
|
99
|
+
positional: "<name> directory name for the new plugin/marketplace",
|
|
100
|
+
flags: ["dir", "description", "author", "skill", "type"],
|
|
101
|
+
},
|
|
102
|
+
adapt: {
|
|
103
|
+
summary: "regenerate Claude/Codex manifests from .agents/.plugin.json",
|
|
104
|
+
synopsis: "adg plugins adapt [<dir>]",
|
|
105
|
+
positional: "<dir> plugin directory (default: current directory)",
|
|
106
|
+
flags: ["target"],
|
|
107
|
+
},
|
|
108
|
+
validate: {
|
|
109
|
+
summary: "check a directory is a valid ADG plugin",
|
|
110
|
+
synopsis: "adg plugins validate [<dir>]",
|
|
111
|
+
positional: "<dir> plugin directory (default: current directory)",
|
|
112
|
+
flags: [],
|
|
113
|
+
},
|
|
114
|
+
"import-skills": {
|
|
115
|
+
summary: "wrap an existing skills/ dir as a plugin",
|
|
116
|
+
synopsis: "adg plugins import-skills <skills-dir> --as <name>",
|
|
117
|
+
positional: "<skills-dir> a directory of SKILL.md folders",
|
|
118
|
+
flags: ["as", "prefix", "description", ...SCOPE],
|
|
119
|
+
},
|
|
120
|
+
link: {
|
|
121
|
+
summary: "link installed plugins into a runtime",
|
|
122
|
+
synopsis: "adg plugins link --target claude|codex|antigravity [name...]",
|
|
123
|
+
positional: "[name...] installed plugin names to link (default: all)",
|
|
124
|
+
blurb: "Project the store into one agent: (re)generate its manifests and enable\nthe plugins via that agent's CLI. The store is unchanged. The inverse is\n`adg plugins unlink`; to force an agent to match the store, use `adg plugins sync`.",
|
|
125
|
+
flags: ["target", ...SCOPE],
|
|
126
|
+
},
|
|
127
|
+
unlink: {
|
|
128
|
+
summary: "unlink plugins from a runtime (store kept)",
|
|
129
|
+
synopsis: "adg plugins unlink --target claude|codex|antigravity [name...]",
|
|
130
|
+
positional: "[name...] installed plugin names to unlink (default: all)",
|
|
131
|
+
blurb: "Disable the plugins in one agent without removing them from the store —\nthe per-agent inverse of `link`. To delete from the store and every agent\nat once, use `adg plugins remove`.",
|
|
132
|
+
flags: ["target", ...SCOPE],
|
|
133
|
+
examples: [
|
|
134
|
+
"adg plugins unlink --target antigravity asc # drop asc from agy only",
|
|
135
|
+
"adg plugins unlink --target codex # unlink everything from codex",
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
sync: {
|
|
139
|
+
summary: "reconcile a runtime's plugins with the store",
|
|
140
|
+
synopsis: "adg plugins sync --target claude|codex|antigravity [name...]",
|
|
141
|
+
positional: "[name...] installed plugin names to sync (default: all)",
|
|
142
|
+
blurb: "Make one agent's copy match the store: regenerate manifests and re-import,\nclearing components that were dropped since the last sync. Use this to repair\ndrift (e.g. residual skills). Only store-known plugins are touched.",
|
|
143
|
+
flags: ["target", ...SCOPE],
|
|
144
|
+
examples: [
|
|
145
|
+
"adg plugins sync --target antigravity asc # clear agy residual for asc",
|
|
146
|
+
"adg plugins sync --target claude # re-sync every plugin into Claude",
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
migrate: {
|
|
150
|
+
summary: "move flat installs into per-marketplace dirs",
|
|
151
|
+
synopsis: "adg plugins migrate",
|
|
152
|
+
flags: [...SCOPE],
|
|
153
|
+
},
|
|
154
|
+
marketplace: {
|
|
155
|
+
summary: "view installed plugins grouped by source",
|
|
156
|
+
synopsis: "adg plugins marketplace <list|sync|upgrade|remove>",
|
|
157
|
+
flags: [],
|
|
158
|
+
delegated: true,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
// Aliases tolerated for plugin verbs.
|
|
162
|
+
export const PLUGIN_ALIASES = { rm: "remove", mp: "marketplace" };
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Help rendering (all generated from the tables above).
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
export const TOP_USAGE = `adg — Agent Directory Group toolkit
|
|
167
|
+
|
|
168
|
+
Group scattered skills and plugins, by source, into versioned and reproducible
|
|
169
|
+
plugin sets — and adapt each to both Claude and Codex runtimes from one manifest.
|
|
170
|
+
|
|
171
|
+
Quick start:
|
|
172
|
+
adg plugins add <owner/repo> install plugins from a source (guided in a terminal)
|
|
173
|
+
adg plugins list see what's installed
|
|
174
|
+
|
|
175
|
+
Two domains:
|
|
176
|
+
adg plugins <verb> manage plugins (run \`adg plugins -h\`)
|
|
177
|
+
adg skills <verb> manage skills (run \`adg skills -h\`)
|
|
178
|
+
|
|
179
|
+
Concepts & architecture: see README.md and docs/agents-spec.md`;
|
|
180
|
+
export const MARKETPLACE_USAGE = `adg plugins marketplace — view installed plugins by source, and re-sync
|
|
181
|
+
|
|
182
|
+
A marketplace is just your installed plugins grouped by where they came from
|
|
183
|
+
(no separate registry). You add sources with \`adg plugins add\`; these commands
|
|
184
|
+
look back over what you installed.
|
|
185
|
+
|
|
186
|
+
Commands:
|
|
187
|
+
adg plugins marketplace list [--verbose] [--global | --project | --dir <dir>]
|
|
188
|
+
Group installed plugins by source. --verbose expands each plugin to its
|
|
189
|
+
components (skills, agents, commands, …).
|
|
190
|
+
adg plugins marketplace remove <source> [--force] [--global | --project | --dir <dir>]
|
|
191
|
+
Uninstall every plugin that came from <source>.
|
|
192
|
+
adg plugins marketplace sync <source> --target <agent> [--global | --project | --dir <dir>]
|
|
193
|
+
Reconcile one agent's copy of every plugin from <source> with the store
|
|
194
|
+
(the source-scoped twin of \`adg plugins sync\`).
|
|
195
|
+
adg plugins marketplace upgrade … (deprecated → use \`adg plugins update\`)
|
|
196
|
+
Kept as an alias. To pull upstream changes, prefer \`adg plugins update\`.
|
|
197
|
+
|
|
198
|
+
<source> is a key from \`marketplace list\` (e.g. owner/repo).`;
|
|
199
|
+
export function flagLabel(name) {
|
|
200
|
+
const f = FLAGS[name];
|
|
201
|
+
const lead = f.short ? `-${f.short}, --${name}` : ` --${name}`;
|
|
202
|
+
return f.hint ? `${lead} ${f.hint}` : lead;
|
|
203
|
+
}
|
|
204
|
+
export function renderFlags(names) {
|
|
205
|
+
if (names.length === 0)
|
|
206
|
+
return "";
|
|
207
|
+
const labels = names.map(flagLabel);
|
|
208
|
+
const width = Math.max(...labels.map((l) => l.length));
|
|
209
|
+
const lines = names.map((n, i) => ` ${labels[i].padEnd(width)} ${FLAGS[n].help}`);
|
|
210
|
+
return `Flags:\n${lines.join("\n")}`;
|
|
211
|
+
}
|
|
212
|
+
/** L1: `adg plugins -h` — overview of the domain and a one-line verb list. */
|
|
213
|
+
export function renderPluginsHelp() {
|
|
214
|
+
const names = Object.keys(PLUGIN_COMMANDS);
|
|
215
|
+
const width = Math.max(...names.map((n) => n.length));
|
|
216
|
+
const rows = names.map((n) => {
|
|
217
|
+
const cmd = PLUGIN_COMMANDS[n];
|
|
218
|
+
const tag = cmd.start ? " ← start here" : "";
|
|
219
|
+
return ` ${n.padEnd(width)} ${cmd.summary}${tag}`;
|
|
220
|
+
});
|
|
221
|
+
return `adg plugins — manage agent plugins
|
|
222
|
+
|
|
223
|
+
A plugin bundles skills/agents/commands, installed from a source (a local dir, or
|
|
224
|
+
a GitHub repo holding one plugin or many). Authored once in .agents/.plugin.json,
|
|
225
|
+
then adapted to Claude and Codex automatically.
|
|
226
|
+
|
|
227
|
+
Commands (run \`adg plugins <verb> -h\` for details & flags):
|
|
228
|
+
${rows.join("\n")}
|
|
229
|
+
|
|
230
|
+
Scope (most commands): --project (default) | --global | --dir <dir>
|
|
231
|
+
--global honors XDG_STATE_HOME / ADG_PLUGINS_HOME. Only the plugins/ subtree is
|
|
232
|
+
touched; AGENTS.md and skills/ are never modified.`;
|
|
233
|
+
}
|
|
234
|
+
/** L2: `adg plugins <verb> -h` — just this command's region. */
|
|
235
|
+
export function renderVerbHelp(name) {
|
|
236
|
+
const cmd = PLUGIN_COMMANDS[name];
|
|
237
|
+
const parts = [`adg plugins ${name} — ${cmd.summary}`, "", cmd.synopsis];
|
|
238
|
+
if (cmd.positional)
|
|
239
|
+
parts.push(` ${cmd.positional}`);
|
|
240
|
+
if (cmd.blurb)
|
|
241
|
+
parts.push("", cmd.blurb);
|
|
242
|
+
const flags = renderFlags(cmd.flags);
|
|
243
|
+
if (flags)
|
|
244
|
+
parts.push("", flags);
|
|
245
|
+
if (cmd.examples)
|
|
246
|
+
parts.push("", "Examples:", ...cmd.examples.map((e) => ` ${e}`));
|
|
247
|
+
return parts.join("\n");
|
|
248
|
+
}
|
|
249
|
+
export function wantsHelp(args) {
|
|
250
|
+
return args.includes("-h") || args.includes("--help");
|
|
251
|
+
}
|
|
252
|
+
/** Print a top-level usage error and exit non-zero. */
|
|
253
|
+
export function fail(msg) {
|
|
254
|
+
console.error(`${ui.err("error:")} ${msg}\n`);
|
|
255
|
+
console.error(TOP_USAGE);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
export function resolveScopeDir(values) {
|
|
259
|
+
if (typeof values.dir === "string")
|
|
260
|
+
return resolve(values.dir);
|
|
261
|
+
return values.global ? globalPluginsDir() : projectPluginsDir();
|
|
262
|
+
}
|
|
263
|
+
/** Describe the active scope so "source not found" errors can name where they looked. */
|
|
264
|
+
export function scopeInfo(values) {
|
|
265
|
+
const label = typeof values.dir === "string" ? resolve(values.dir) : values.global ? "global" : "project";
|
|
266
|
+
return { label, globalDir: globalPluginsDir() };
|
|
267
|
+
}
|
|
268
|
+
/** Map the active scope to an agent install scope (global → user, else project). */
|
|
269
|
+
export function scopeOf(values) {
|
|
270
|
+
return values.global ? "user" : "project";
|
|
271
|
+
}
|
|
272
|
+
/** Friendly `--target` aliases mapped onto canonical adapter target ids. */
|
|
273
|
+
export const TARGET_ALIASES = {
|
|
274
|
+
anthropic: "claude",
|
|
275
|
+
openai: "codex",
|
|
276
|
+
agy: "antigravity",
|
|
277
|
+
gemini: "antigravity",
|
|
278
|
+
};
|
|
279
|
+
export function resolveTargets(target) {
|
|
280
|
+
if (!target || target === "all")
|
|
281
|
+
return [...ADAPTER_TARGETS];
|
|
282
|
+
const t = TARGET_ALIASES[target] ?? target;
|
|
283
|
+
if (ADAPTER_TARGETS.includes(t))
|
|
284
|
+
return [t];
|
|
285
|
+
fail(`invalid --target "${target}" (expected ${[...ADAPTER_TARGETS, "all"].join("|")})`);
|
|
286
|
+
}
|
|
287
|
+
/** A single-agent projection verb (link/unlink/sync) needs exactly one --target. */
|
|
288
|
+
export function requireSingleTarget(target, verb) {
|
|
289
|
+
if (target === undefined || target === "all") {
|
|
290
|
+
fail(`plugins ${verb} requires a single --target (${ADAPTER_TARGETS.join("|")})`);
|
|
291
|
+
}
|
|
292
|
+
return resolveTargets(target)[0]; // validates + maps aliases (agy → antigravity); always non-empty
|
|
293
|
+
}
|
|
294
|
+
/** Parse a `--only skills,commands` list into validated component types. */
|
|
295
|
+
export function resolveComponents(only) {
|
|
296
|
+
if (only === undefined)
|
|
297
|
+
return undefined;
|
|
298
|
+
const parts = only.split(",").map((s) => s.trim()).filter(Boolean);
|
|
299
|
+
const bad = parts.filter((p) => !COMPONENT_TYPES.includes(p));
|
|
300
|
+
if (bad.length > 0)
|
|
301
|
+
fail(`invalid --only "${bad.join(", ")}" (expected ${COMPONENT_TYPES.join("|")})`);
|
|
302
|
+
return parts;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Parse a verb's args against only the flags it declares. An unknown flag (or a
|
|
306
|
+
* malformed value) prints that command's own help — so `-h` and a typo lead to
|
|
307
|
+
* the same place. Returns parsed values + positionals.
|
|
308
|
+
*/
|
|
309
|
+
export function parseVerb(name, flags, rest) {
|
|
310
|
+
try {
|
|
311
|
+
const { values, positionals } = parseArgs({ args: rest, options: optionsFor(flags), allowPositionals: true });
|
|
312
|
+
return { values: values, positionals };
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}\n`);
|
|
316
|
+
console.error(renderVerbHelp(name));
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { adaptPlugin } from "./adapt.js";
|
|
3
|
-
import {
|
|
3
|
+
import { selectInstalled } from "./projection.js";
|
|
4
4
|
import { installedPluginDir } from "../paths.js";
|
|
5
5
|
import { getAgent } from "../agents/index.js";
|
|
6
6
|
/**
|
|
@@ -13,7 +13,7 @@ export function linkPlugins(opts) {
|
|
|
13
13
|
const agent = opts.agent ?? getAgent(opts.target);
|
|
14
14
|
const adaptTarget = agent?.adaptTarget ?? opts.target;
|
|
15
15
|
const actions = [];
|
|
16
|
-
for (const p of
|
|
16
|
+
for (const p of selectInstalled(opts.pluginsDir, opts.names)) {
|
|
17
17
|
const dir = installedPluginDir(opts.pluginsDir, p.name, p.origin);
|
|
18
18
|
if (!existsSync(dir))
|
|
19
19
|
continue;
|
|
@@ -2,6 +2,7 @@ import { lockPath } from "../paths.js";
|
|
|
2
2
|
import { readLock } from "../lock.js";
|
|
3
3
|
import { addPlugins } from "./install.js";
|
|
4
4
|
import { removePlugin } from "./remove.js";
|
|
5
|
+
import { syncPlugins } from "./sync.js";
|
|
5
6
|
import { updateLock } from "./update.js";
|
|
6
7
|
/**
|
|
7
8
|
* A stable key identifying the source a plugin came from. GitHub/git plugins
|
|
@@ -65,48 +66,6 @@ function requireGroup(pluginsDir, source, scope) {
|
|
|
65
66
|
}
|
|
66
67
|
throw new Error(msg);
|
|
67
68
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Re-fetch a source and update the plugins installed from it. By default only
|
|
70
|
-
* already-installed plugins are refreshed; `all` also installs everything new
|
|
71
|
-
* the source now offers. With no `source`, every remote source is upgraded.
|
|
72
|
-
*/
|
|
73
|
-
export async function marketplaceUpgrade(opts) {
|
|
74
|
-
const groups = opts.source
|
|
75
|
-
? [requireGroup(opts.pluginsDir, opts.source, opts.scope)]
|
|
76
|
-
: marketplaceList({ pluginsDir: opts.pluginsDir }).filter((g) => g.remote);
|
|
77
|
-
if (opts.source && !groups[0].remote) {
|
|
78
|
-
throw new Error(`source "${opts.source}" is local and cannot be re-synced; re-run \`adg plugins add\`.`);
|
|
79
|
-
}
|
|
80
|
-
if (groups.length === 0) {
|
|
81
|
-
throw new Error(`no remote sources installed in ${opts.pluginsDir}`);
|
|
82
|
-
}
|
|
83
|
-
const now = opts.now ?? new Date().toISOString();
|
|
84
|
-
const results = [];
|
|
85
|
-
for (const group of groups) {
|
|
86
|
-
const { installed, converted, available } = await addPlugins({
|
|
87
|
-
spec: group.source,
|
|
88
|
-
pluginsDir: opts.pluginsDir,
|
|
89
|
-
ref: group.ref,
|
|
90
|
-
// Default: refresh what's installed. --all: install everything too.
|
|
91
|
-
...(opts.all ? { all: true } : { plugins: group.installed }),
|
|
92
|
-
targets: opts.targets,
|
|
93
|
-
marketplaceName: group.source,
|
|
94
|
-
gitRunner: opts.gitRunner,
|
|
95
|
-
// Re-activate so the agents pick up the upgraded content, not just the store.
|
|
96
|
-
activate: opts.activate,
|
|
97
|
-
scope: opts.agentScope,
|
|
98
|
-
now,
|
|
99
|
-
});
|
|
100
|
-
const installedSet = new Set(group.installed);
|
|
101
|
-
results.push({
|
|
102
|
-
source: group.source,
|
|
103
|
-
updated: installed,
|
|
104
|
-
converted,
|
|
105
|
-
available: available.filter((n) => !installedSet.has(n)),
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return results;
|
|
109
|
-
}
|
|
110
69
|
/** Merge per-agent sync results from several passes into one entry per agent. */
|
|
111
70
|
export function mergeAgentResults(groups) {
|
|
112
71
|
const merged = new Map();
|
|
@@ -214,3 +173,19 @@ export function marketplaceRemove(opts) {
|
|
|
214
173
|
}
|
|
215
174
|
return { source: opts.source, removed };
|
|
216
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Reconcile one agent's copy of every plugin from a given source to the store —
|
|
178
|
+
* the source-scoped twin of `adg plugins sync`. Resolves the source's installed
|
|
179
|
+
* plugins from the lock, then drives `syncPlugins` for just that set, so a whole
|
|
180
|
+
* marketplace can be repaired in one call without naming each plugin.
|
|
181
|
+
*/
|
|
182
|
+
export function marketplaceSync(opts) {
|
|
183
|
+
const group = requireGroup(opts.pluginsDir, opts.source, opts.scope);
|
|
184
|
+
return syncPlugins({
|
|
185
|
+
pluginsDir: opts.pluginsDir,
|
|
186
|
+
target: opts.target,
|
|
187
|
+
global: opts.global,
|
|
188
|
+
names: group.installed,
|
|
189
|
+
agent: opts.agent,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { listPlugins } from "./list.js";
|
|
2
|
+
/**
|
|
3
|
+
* Shared selection for the projection verbs (link / unlink / sync). Resolve which
|
|
4
|
+
* installed plugins to act on: the named subset (validated against the store), or
|
|
5
|
+
* every installed plugin when no names are given. Throws — naming the unknown
|
|
6
|
+
* plugins — so a typo surfaces rather than silently no-op'ing, and dedupes
|
|
7
|
+
* repeats so `sync foo foo` acts on `foo` once. Centralized here (not in any one
|
|
8
|
+
* verb) so all three select identically.
|
|
9
|
+
*/
|
|
10
|
+
export function selectInstalled(pluginsDir, names) {
|
|
11
|
+
const all = listPlugins(pluginsDir);
|
|
12
|
+
if (!names || names.length === 0)
|
|
13
|
+
return all;
|
|
14
|
+
const byName = new Map(all.map((p) => [p.name, p]));
|
|
15
|
+
const missing = names.filter((n) => !byName.has(n));
|
|
16
|
+
if (missing.length > 0) {
|
|
17
|
+
throw new Error(`not installed: ${missing.join(", ")}. See \`adg plugins list\`.`);
|
|
18
|
+
}
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const picked = [];
|
|
21
|
+
for (const n of names) {
|
|
22
|
+
if (seen.has(n))
|
|
23
|
+
continue;
|
|
24
|
+
seen.add(n);
|
|
25
|
+
picked.push(byName.get(n));
|
|
26
|
+
}
|
|
27
|
+
return picked;
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { listPlugins } from "./list.js";
|
|
3
|
+
import { allAgents, resolveAgents } from "../agents/index.js";
|
|
4
|
+
import { lockPath } from "../paths.js";
|
|
5
|
+
/** Diff the store against each agent's live plugin list. Read-only. */
|
|
6
|
+
export function pluginStatus(opts) {
|
|
7
|
+
const store = listPlugins(opts.pluginsDir).map((p) => p.name);
|
|
8
|
+
const storeSet = new Set(store);
|
|
9
|
+
// Query every registered agent (not just `detect`ed ones): `detect` is a
|
|
10
|
+
// config-dir heuristic that can miss an installed CLI, and an agent that
|
|
11
|
+
// can't be queried reports "unknown" anyway — so this never silently drops one.
|
|
12
|
+
const agents = opts.agents ?? (opts.targets ? resolveAgents(opts.targets) : allAgents());
|
|
13
|
+
const hasProjectLock = existsSync(lockPath(opts.pluginsDir));
|
|
14
|
+
return agents.map((a) => {
|
|
15
|
+
const installed = a.listInstalled?.({ pluginsDir: opts.pluginsDir, plugins: [], scope: opts.scope });
|
|
16
|
+
if (installed === undefined) {
|
|
17
|
+
return { id: a.id, displayName: a.displayName, queryable: false, inSync: [], missing: [], agentOnly: [] };
|
|
18
|
+
}
|
|
19
|
+
const agentSet = new Set(installed);
|
|
20
|
+
// If we're in project scope and the project doesn't have an ADG lock file,
|
|
21
|
+
// the project is not initialized with ADG plugins. We should not report global
|
|
22
|
+
// or other projects' plugins as "agent only" since they are unrelated.
|
|
23
|
+
const agentOnly = (opts.scope === "project" && !hasProjectLock)
|
|
24
|
+
? []
|
|
25
|
+
: installed.filter((n) => !storeSet.has(n));
|
|
26
|
+
return {
|
|
27
|
+
id: a.id,
|
|
28
|
+
displayName: a.displayName,
|
|
29
|
+
queryable: true,
|
|
30
|
+
inSync: store.filter((n) => agentSet.has(n)),
|
|
31
|
+
missing: store.filter((n) => !agentSet.has(n)),
|
|
32
|
+
agentOnly,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { adaptPlugin } from "./adapt.js";
|
|
3
|
+
import { selectInstalled } from "./projection.js";
|
|
4
|
+
import { installedPluginDir } from "../paths.js";
|
|
5
|
+
import { getAgent } from "../agents/index.js";
|
|
6
|
+
/** Regenerate manifests for the selected plugins, then refresh them in the agent. */
|
|
7
|
+
export function syncPlugins(opts) {
|
|
8
|
+
const agent = opts.agent ?? getAgent(opts.target);
|
|
9
|
+
const adaptTarget = agent?.adaptTarget ?? opts.target;
|
|
10
|
+
const actions = [];
|
|
11
|
+
for (const p of selectInstalled(opts.pluginsDir, opts.names)) {
|
|
12
|
+
const dir = installedPluginDir(opts.pluginsDir, p.name, p.origin);
|
|
13
|
+
if (!existsSync(dir))
|
|
14
|
+
continue;
|
|
15
|
+
const adapted = adaptPlugin(dir, [adaptTarget], p.selection).map((r) => r.file);
|
|
16
|
+
actions.push({ name: p.name, adapted, synced: false });
|
|
17
|
+
}
|
|
18
|
+
if (!agent)
|
|
19
|
+
return { target: opts.target, actions };
|
|
20
|
+
const res = agent.refresh({
|
|
21
|
+
pluginsDir: opts.pluginsDir,
|
|
22
|
+
plugins: actions.map((a) => a.name),
|
|
23
|
+
scope: opts.global ? "user" : "project",
|
|
24
|
+
});
|
|
25
|
+
for (const a of actions)
|
|
26
|
+
if (res.affected.includes(a.name))
|
|
27
|
+
a.synced = true;
|
|
28
|
+
return { target: opts.target, actions, cliSkipped: res.skipped };
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { listPlugins } from "./list.js";
|
|
2
|
+
import { getAgent } from "../agents/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Deactivate the selected plugins from one agent. Store/lock/marketplace catalog
|
|
5
|
+
* are never touched — only the agent's own enabled state changes.
|
|
6
|
+
*/
|
|
7
|
+
export function unlinkPlugins(opts) {
|
|
8
|
+
const agent = opts.agent ?? getAgent(opts.target);
|
|
9
|
+
if (!agent)
|
|
10
|
+
return { target: opts.target, unlinked: [] };
|
|
11
|
+
const scope = opts.global ? "user" : "project";
|
|
12
|
+
const installedInAgent = agent.listInstalled?.({ pluginsDir: opts.pluginsDir, plugins: [], scope });
|
|
13
|
+
const installedInStore = listPlugins(opts.pluginsDir).map((p) => p.name);
|
|
14
|
+
// A name is valid if it is installed in either the store OR the agent (if queryable).
|
|
15
|
+
const validNames = new Set([...installedInStore, ...(installedInAgent ?? [])]);
|
|
16
|
+
const names = opts.names && opts.names.length > 0
|
|
17
|
+
? opts.names
|
|
18
|
+
: installedInStore;
|
|
19
|
+
if (opts.names && opts.names.length > 0) {
|
|
20
|
+
const missing = opts.names.filter((n) => !validNames.has(n));
|
|
21
|
+
if (missing.length > 0) {
|
|
22
|
+
throw new Error(`not installed: ${missing.join(", ")}. See \`adg plugins list\`.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Only filter if we successfully queried the agent's installed plugins.
|
|
26
|
+
// Otherwise, fall back to always calling deactivate for the selected names.
|
|
27
|
+
const toUnlink = installedInAgent !== undefined
|
|
28
|
+
? names.filter((n) => installedInAgent.includes(n))
|
|
29
|
+
: names;
|
|
30
|
+
if (toUnlink.length === 0 && installedInAgent !== undefined) {
|
|
31
|
+
return { target: opts.target, unlinked: [], cliSkipped: false };
|
|
32
|
+
}
|
|
33
|
+
const res = agent.deactivate({
|
|
34
|
+
pluginsDir: opts.pluginsDir,
|
|
35
|
+
plugins: toUnlink,
|
|
36
|
+
scope,
|
|
37
|
+
});
|
|
38
|
+
return { target: opts.target, unlinked: res.affected, cliSkipped: res.skipped };
|
|
39
|
+
}
|
|
@@ -105,6 +105,38 @@ export function renderUpdateReport(result) {
|
|
|
105
105
|
out.push(ui.meta("nothing to update (no installed sources)"));
|
|
106
106
|
return out;
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* `adg plugins status` — per-agent diff of the store against the agent's live
|
|
110
|
+
* plugin list, each drift row tagged with the command that repairs it.
|
|
111
|
+
*/
|
|
112
|
+
export function renderStatus(statuses) {
|
|
113
|
+
if (statuses.length === 0)
|
|
114
|
+
return [ui.meta("no agents detected — install an agent CLI, then `adg plugins link`.")];
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const s of statuses) {
|
|
117
|
+
out.push(ui.name(s.displayName));
|
|
118
|
+
if (!s.queryable) {
|
|
119
|
+
out.push(ui.meta(" live state unknown — agent CLI not available or not queryable"));
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
out.push(ui.meta(` in sync (${s.inSync.length})${s.inSync.length ? ": " + s.inSync.join(", ") : ""}`));
|
|
123
|
+
if (s.missing.length > 0) {
|
|
124
|
+
out.push(ui.warn(` missing (${s.missing.length}): ${s.missing.join(", ")}`));
|
|
125
|
+
out.push(ui.meta(` → adg plugins sync --target ${s.id} ${s.missing.join(" ")}`));
|
|
126
|
+
}
|
|
127
|
+
if (s.agentOnly.length > 0) {
|
|
128
|
+
out.push(ui.warn(` in agent only (${s.agentOnly.length}): ${s.agentOnly.join(", ")}`));
|
|
129
|
+
out.push(ui.meta(` → if ADG-managed, adg plugins unlink --target ${s.id} <name> (else ignore)`));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const totalSync = statuses.reduce((acc, s) => acc + s.inSync.length + s.missing.length, 0);
|
|
133
|
+
const totalAgentOnly = statuses.reduce((acc, s) => acc + s.agentOnly.length, 0);
|
|
134
|
+
if (totalSync === 0 && totalAgentOnly > 0) {
|
|
135
|
+
out.push(ui.meta("tip: project store has no plugins recorded. If you wanted to check global plugins, append --global (-g)"));
|
|
136
|
+
}
|
|
137
|
+
out.push(ui.meta("note: name-level only; content drift isn't shown — run `adg plugins sync` if unsure."));
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
108
140
|
/**
|
|
109
141
|
* `adg plugins marketplace list` — installed plugins grouped by source.
|
|
110
142
|
* `details` (name → ListedPlugin) enables the verbose per-plugin component drill;
|