@toolmesh/agent-deck 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +433 -2
- package/bin/agent-deck.js +2 -0
- package/package.json +42 -4
- package/src/agents.mjs +87 -0
- package/src/cli.mjs +484 -0
- package/src/gitignore.mjs +109 -0
- package/src/hosts/claude-native.mjs +113 -0
- package/src/hosts/copy.mjs +279 -0
- package/src/init.mjs +65 -0
- package/src/install.mjs +395 -0
- package/src/lockfile.mjs +133 -0
- package/src/materialize.mjs +184 -0
- package/src/outdated.mjs +91 -0
- package/src/paths.mjs +63 -0
- package/src/plugins.mjs +158 -0
- package/src/profiles.mjs +80 -0
- package/src/project.mjs +110 -0
- package/src/sources/fetch.mjs +250 -0
- package/src/sources/locate.mjs +396 -0
- package/src/sources/spec.mjs +254 -0
- package/src/state.mjs +41 -0
- package/src/status.mjs +137 -0
- package/src/worktree.mjs +52 -0
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { installAll, installOne, lockOnly, materializeTo, pinFor, refreshGitignore, uninstallOne } from "./install.mjs";
|
|
5
|
+
import { readLockfile, removeLockEntry, upsertLockEntry, writeLockfile } from "./lockfile.mjs";
|
|
6
|
+
import { isOutdated, outdated } from "./outdated.mjs";
|
|
7
|
+
import { LOCAL_PLUGINS_FILE, LOCK_FILE, PLUGINS_FILE } from "./paths.mjs";
|
|
8
|
+
import {
|
|
9
|
+
addLocalPlugin,
|
|
10
|
+
addPlugin,
|
|
11
|
+
deleteLocalPlugins,
|
|
12
|
+
emptyLocalPlugins,
|
|
13
|
+
emptyPlugins,
|
|
14
|
+
parseLinkSpec,
|
|
15
|
+
readLocalPlugins,
|
|
16
|
+
readPlugins,
|
|
17
|
+
removeLocalPlugin,
|
|
18
|
+
removePlugin,
|
|
19
|
+
writeLocalPlugins,
|
|
20
|
+
writePlugins,
|
|
21
|
+
} from "./plugins.mjs";
|
|
22
|
+
import { clearProfile, createProfile, useProfile } from "./profiles.mjs";
|
|
23
|
+
import { PROFILES_DIR, listProfiles, loadProject, profileDir } from "./project.mjs";
|
|
24
|
+
import { defaultId, normalizeRequest, parseAddSpec } from "./sources/spec.mjs";
|
|
25
|
+
import { initProject } from "./init.mjs";
|
|
26
|
+
import { status } from "./status.mjs";
|
|
27
|
+
|
|
28
|
+
const USAGE = `agent-deck — install AI plugins and skills into a project, for Claude Code and Cursor
|
|
29
|
+
|
|
30
|
+
Usage:
|
|
31
|
+
agent-deck init [--commit-copies]
|
|
32
|
+
agent-deck add <source> [--skill <name>]… [--ref <ref>] [--profile <name>]
|
|
33
|
+
agent-deck remove <id> [--profile <name>]
|
|
34
|
+
agent-deck install [--frozen]
|
|
35
|
+
agent-deck update [<id>…] [--profile <name>]
|
|
36
|
+
agent-deck status
|
|
37
|
+
agent-deck outdated
|
|
38
|
+
agent-deck link <folder>[@<plugin>] [--skill <name>]…
|
|
39
|
+
agent-deck unlink <id>
|
|
40
|
+
agent-deck profile new|use|off|list [<name>]
|
|
41
|
+
agent-deck materialize --out <dir> [--profile <name>] [--json]
|
|
42
|
+
|
|
43
|
+
Sources (add):
|
|
44
|
+
owner/repo@plugin a plugin from a GitHub marketplace
|
|
45
|
+
owner/repo a single-plugin repository, or a repository of skills
|
|
46
|
+
git+<url>[#ref]@plugin any git host (also git@host:owner/repo.git)
|
|
47
|
+
npm:<package>[@version] an npm package
|
|
48
|
+
https://….zip | .tar.gz an archive
|
|
49
|
+
./<path>[@plugin] a directory inside the project (committed)
|
|
50
|
+
|
|
51
|
+
Options for every command:
|
|
52
|
+
-C, --project <dir> project root (default: current directory)
|
|
53
|
+
--force replace files that agent-deck did not write
|
|
54
|
+
-h, --help
|
|
55
|
+
-v, --version print the agent-deck version (alone, without a command)
|
|
56
|
+
|
|
57
|
+
Advanced options:
|
|
58
|
+
add --id <id> --path <dir in source> --sha256 <hex> --no-install
|
|
59
|
+
remove --keep-files (unlink too)
|
|
60
|
+
link --id <id> --path <dir> --no-install
|
|
61
|
+
|
|
62
|
+
Files:
|
|
63
|
+
ai-plugin.json, ai-plugin.lock.json the base: what every profile gets (commit)
|
|
64
|
+
.ai/profiles/<name>/prompt.md, ai-plugin.json, lock a profile, added on top when active (commit)
|
|
65
|
+
.ai/current, .ai/installed/, ai-plugin.local.json local only
|
|
66
|
+
|
|
67
|
+
Settings in ai-plugin.json:
|
|
68
|
+
"hosts": { "claude": "native" | "copy" | "off", "cursor": "copy" | "off" }
|
|
69
|
+
"agentsMd": false do not write the Skills block in AGENTS.md
|
|
70
|
+
"gitignoreCopies": false commit the copies in .claude/ and .cursor/ (agent-deck init --commit-copies)
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
const VALUE_FLAGS = new Set(["ref", "profile", "id", "path", "sha256", "out"]);
|
|
74
|
+
const BOOL_FLAGS = new Set(["frozen", "force", "keep-files", "no-install", "json", "commit-copies", "help"]);
|
|
75
|
+
const GLOBAL_FLAGS = ["force", "help"];
|
|
76
|
+
|
|
77
|
+
/** Flags each command takes, besides the global ones. */
|
|
78
|
+
const COMMANDS = {
|
|
79
|
+
init: ["commit-copies"],
|
|
80
|
+
add: ["ref", "skill", "profile", "id", "path", "sha256", "no-install"],
|
|
81
|
+
remove: ["profile", "keep-files"],
|
|
82
|
+
install: ["frozen"],
|
|
83
|
+
update: ["profile"],
|
|
84
|
+
status: [],
|
|
85
|
+
outdated: [],
|
|
86
|
+
link: ["id", "skill", "path", "no-install"],
|
|
87
|
+
unlink: ["keep-files"],
|
|
88
|
+
profile: [],
|
|
89
|
+
materialize: ["out", "profile", "json"],
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function parseArgs(argv) {
|
|
93
|
+
const args = { _: [], flags: new Map(), skills: [], project: process.cwd() };
|
|
94
|
+
for (let i = 0; i < argv.length; i++) {
|
|
95
|
+
const a = argv[i];
|
|
96
|
+
if (a === "-C" || a === "--project") {
|
|
97
|
+
const v = argv[++i];
|
|
98
|
+
if (!v) throw new Error(`${a} needs a directory`);
|
|
99
|
+
args.project = path.resolve(v);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (a === "-h") {
|
|
103
|
+
args.flags.set("help", true);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!a.startsWith("--")) {
|
|
107
|
+
if (a.startsWith("-")) throw new Error(`Unknown option: ${a}`);
|
|
108
|
+
args._.push(a);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const name = a.slice(2);
|
|
112
|
+
if (name === "skill") {
|
|
113
|
+
const v = argv[++i];
|
|
114
|
+
if (v === undefined || v.startsWith("--")) throw new Error("--skill needs a value");
|
|
115
|
+
args.skills.push(v);
|
|
116
|
+
args.flags.set("skill", true);
|
|
117
|
+
} else if (VALUE_FLAGS.has(name)) {
|
|
118
|
+
const v = argv[++i];
|
|
119
|
+
if (v === undefined || v.startsWith("--")) throw new Error(`--${name} needs a value`);
|
|
120
|
+
args.flags.set(name, v);
|
|
121
|
+
} else if (BOOL_FLAGS.has(name)) {
|
|
122
|
+
args.flags.set(name, true);
|
|
123
|
+
} else {
|
|
124
|
+
throw new Error(`Unknown option: ${a}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return args;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Refuse an option the command does not take, instead of ignoring it. */
|
|
131
|
+
function checkFlags(cmd, args) {
|
|
132
|
+
const allowed = new Set([...(COMMANDS[cmd] ?? []), ...GLOBAL_FLAGS]);
|
|
133
|
+
for (const name of args.flags.keys()) {
|
|
134
|
+
if (!allowed.has(name)) throw new Error(`agent-deck ${cmd} does not take --${name}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function describe(entry) {
|
|
139
|
+
const r = entry.resolved;
|
|
140
|
+
const where =
|
|
141
|
+
r.type === "git" || r.type === "local"
|
|
142
|
+
? String(r.sha).slice(0, 12)
|
|
143
|
+
: r.type === "npm"
|
|
144
|
+
? `${r.package}@${r.version}`
|
|
145
|
+
: r.type === "path"
|
|
146
|
+
? r.path
|
|
147
|
+
: String(r.sha256).slice(0, 12);
|
|
148
|
+
const c = entry.components;
|
|
149
|
+
const parts = [
|
|
150
|
+
`skills=${c.skills.length}`,
|
|
151
|
+
`agents=${c.agents.length}`,
|
|
152
|
+
c.commands.length ? `commands=${c.commands.length}` : null,
|
|
153
|
+
c.rules.length ? `rules=${c.rules.length}` : null,
|
|
154
|
+
c.hooks ? "hooks" : null,
|
|
155
|
+
c.mcp.length ? `mcp=${c.mcp.length}` : null,
|
|
156
|
+
].filter(Boolean);
|
|
157
|
+
return `${entry.id} ${parts.join(" ")} ${r.type}:${where}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function printResult({ entry, warnings = [], linked, skipped }) {
|
|
161
|
+
console.log(` ${describe(entry)}${linked ? " (linked)" : ""}${skipped ? " (up to date)" : ""}`);
|
|
162
|
+
for (const warning of warnings) console.log(` ! ${warning}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The folder whose ai-plugin.json a command edits: the base, or a profile. */
|
|
166
|
+
function targetDir(root, profile) {
|
|
167
|
+
if (!profile) return root;
|
|
168
|
+
const dir = profileDir(root, profile);
|
|
169
|
+
if (!fs.existsSync(path.join(dir, PLUGINS_FILE))) {
|
|
170
|
+
throw new Error(`No profile "${profile}". Create it with: agent-deck profile new ${profile}`);
|
|
171
|
+
}
|
|
172
|
+
return dir;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function install(root, options = {}) {
|
|
176
|
+
const project = loadProject(root);
|
|
177
|
+
if (!project.exists) throw new Error(`No ${PLUGINS_FILE}. Run agent-deck add <source>.`);
|
|
178
|
+
const label = project.profile ? ` (profile ${project.profile})` : "";
|
|
179
|
+
if (project.doc.plugins.length > 0) {
|
|
180
|
+
console.log(`${options.update ? "Updating" : "Installing"} ${project.doc.plugins.length} plugin(s)${label}…`);
|
|
181
|
+
}
|
|
182
|
+
const { results, removed } = await installAll(root, project.doc, project.lock, {
|
|
183
|
+
...options,
|
|
184
|
+
saveLock: project.saveLock,
|
|
185
|
+
});
|
|
186
|
+
for (const id of removed) console.log(` - ${id} (no longer requested)`);
|
|
187
|
+
for (const result of results) printResult(result);
|
|
188
|
+
if (project.doc.plugins.length === 0) console.log(`Nothing requested${label}.`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Pin requests of a profile that is not active, without installing them. */
|
|
192
|
+
async function lockProfile(root, profile, requests, { update = false } = {}) {
|
|
193
|
+
const dir = profileDir(root, profile);
|
|
194
|
+
let lock = readLockfile(dir) ?? { lockfileVersion: 1, writeAgentsMd: true, plugins: [] };
|
|
195
|
+
for (const request of requests) {
|
|
196
|
+
const entry = await lockOnly(request, pinFor(lock, request, update), { base: root });
|
|
197
|
+
lock = upsertLockEntry(lock, entry);
|
|
198
|
+
console.log(` ${describe(entry)} (locked; profile ${profile} is not active)`);
|
|
199
|
+
}
|
|
200
|
+
writeLockfile(dir, lock);
|
|
201
|
+
refreshGitignore(root);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function cmdAdd(root, args, rest) {
|
|
205
|
+
const profile = args.flags.get("profile");
|
|
206
|
+
const request = parseAddSpec(rest[0], {
|
|
207
|
+
ref: args.flags.get("ref"),
|
|
208
|
+
path: args.flags.get("path"),
|
|
209
|
+
id: args.flags.get("id"),
|
|
210
|
+
sha256: args.flags.get("sha256"),
|
|
211
|
+
skills: args.skills,
|
|
212
|
+
});
|
|
213
|
+
const dir = targetDir(root, profile);
|
|
214
|
+
const doc = addPlugin(readPlugins(dir) ?? emptyPlugins(), request);
|
|
215
|
+
const where = profile ? `profile ${profile}` : PLUGINS_FILE;
|
|
216
|
+
|
|
217
|
+
if (args.flags.has("no-install")) {
|
|
218
|
+
writePlugins(dir, doc);
|
|
219
|
+
console.log(`Added ${request.id} to ${where} (not installed)`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const project = loadProject(root);
|
|
224
|
+
const owner = project.owner.get(request.id);
|
|
225
|
+
const side = profile ?? "base";
|
|
226
|
+
if (owner && owner !== side) {
|
|
227
|
+
throw new Error(`"${request.id}" is already requested by ${owner === "base" ? PLUGINS_FILE : `profile ${owner}`}.`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (profile && profile !== project.profile) {
|
|
231
|
+
// Like npm install: the request is written only once it resolved.
|
|
232
|
+
await lockProfile(root, profile, [request]);
|
|
233
|
+
writePlugins(dir, doc);
|
|
234
|
+
console.log(`Added ${request.id} to ${where}. It is installed when the profile is active: agent-deck profile use ${profile}`);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
project.owner.set(request.id, side);
|
|
239
|
+
const result = await installOne(root, project.doc, request, project.lock, {
|
|
240
|
+
force: args.flags.has("force"),
|
|
241
|
+
saveLock: project.saveLock,
|
|
242
|
+
});
|
|
243
|
+
writePlugins(dir, doc);
|
|
244
|
+
console.log(`Added ${request.id} to ${where}:`);
|
|
245
|
+
printResult(result);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function cmdRemove(root, args, rest) {
|
|
249
|
+
if (!rest[0]) throw new Error("remove needs a plugin id");
|
|
250
|
+
const id = rest[0];
|
|
251
|
+
const profile = args.flags.get("profile");
|
|
252
|
+
const dir = targetDir(root, profile);
|
|
253
|
+
const doc = readPlugins(dir);
|
|
254
|
+
if (!doc) throw new Error(`No ${PLUGINS_FILE}${profile ? ` in profile ${profile}` : ""}`);
|
|
255
|
+
const next = removePlugin(doc, id);
|
|
256
|
+
const project = loadProject(root);
|
|
257
|
+
|
|
258
|
+
if (profile && profile !== project.profile) {
|
|
259
|
+
writePlugins(dir, next);
|
|
260
|
+
const lock = readLockfile(dir);
|
|
261
|
+
if (lock) writeLockfile(dir, removeLockEntry(lock, id));
|
|
262
|
+
refreshGitignore(root);
|
|
263
|
+
console.log(`Removed ${id} from profile ${profile}`);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
writePlugins(dir, next);
|
|
267
|
+
uninstallOne(root, id, project.lock, { keepFiles: args.flags.has("keep-files"), saveLock: project.saveLock });
|
|
268
|
+
console.log(`Removed ${id}`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function cmdUpdate(root, args, rest) {
|
|
272
|
+
const ids = rest;
|
|
273
|
+
const profile = args.flags.get("profile");
|
|
274
|
+
const active = loadProject(root).profile;
|
|
275
|
+
if (profile && profile !== active) {
|
|
276
|
+
const doc = readPlugins(targetDir(root, profile)) ?? emptyPlugins();
|
|
277
|
+
const requests = doc.plugins.filter((p) => ids.length === 0 || ids.includes(p.id));
|
|
278
|
+
console.log(`Updating ${requests.length} plugin(s) of profile ${profile}…`);
|
|
279
|
+
await lockProfile(root, profile, requests, { update: true });
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
await install(root, { update: ids.length > 0 ? ids : true, force: args.flags.has("force") });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function cmdStatus(root) {
|
|
286
|
+
const { profile, rows, findings } = status(root);
|
|
287
|
+
const profiles = listProfiles(root);
|
|
288
|
+
if (profile) console.log(`Profile: ${profile} (${PROFILES_DIR}/${profile})`);
|
|
289
|
+
else if (profiles.length > 0) console.log(`Profile: none (${profiles.join(", ")} available: agent-deck profile use <name>)`);
|
|
290
|
+
if (rows.length === 0) console.log("(no plugins)");
|
|
291
|
+
for (const row of rows) {
|
|
292
|
+
const what = [row.source, row.ref && `#${row.ref}`].filter(Boolean).join("");
|
|
293
|
+
const over = row.overrides
|
|
294
|
+
? `, overrides ${row.overrides.source}${row.overrides.ref ? `#${row.overrides.ref}` : ""}`
|
|
295
|
+
: "";
|
|
296
|
+
console.log(`${row.id} [${row.from}${over}] ${what}`);
|
|
297
|
+
if (row.entry && !row.linked) console.log(` locked: ${describe(row.entry)}`);
|
|
298
|
+
}
|
|
299
|
+
const mark = { error: "✖", warn: "!", ok: "✔" };
|
|
300
|
+
for (const f of findings) console.log(`${mark[f.level]} ${f.id ? `${f.id}: ` : ""}${f.message}`);
|
|
301
|
+
if (findings.some((f) => f.level === "error")) process.exitCode = 1;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function cmdOutdated(root) {
|
|
305
|
+
const rows = outdated(root);
|
|
306
|
+
if (rows.length === 0) {
|
|
307
|
+
console.log("(nothing locked)");
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const table = [["id", "type", "current", "wanted", "latest", ""]].concat(
|
|
311
|
+
rows.map((r) => [r.id, r.type, r.current, r.wanted ?? "-", r.latest ?? "-", r.note ?? ""]),
|
|
312
|
+
);
|
|
313
|
+
const widths = table[0].map((_, i) => Math.max(...table.map((row) => String(row[i]).length)));
|
|
314
|
+
for (const row of table) console.log(row.map((cell, i) => String(cell).padEnd(widths[i])).join(" ").trimEnd());
|
|
315
|
+
if (rows.some(isOutdated)) process.exitCode = 1;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function cmdLink(root, args, rest) {
|
|
319
|
+
if (!rest[0]) throw new Error("link needs <folder>[@<plugin>]");
|
|
320
|
+
const { checkout, name } = parseLinkSpec(rest[0]);
|
|
321
|
+
const from = path.resolve(checkout);
|
|
322
|
+
if (!fs.existsSync(from) || !fs.statSync(from).isDirectory()) {
|
|
323
|
+
throw new Error(`Cannot link ${checkout}: ${from} is not a directory`);
|
|
324
|
+
}
|
|
325
|
+
const request = normalizeRequest({
|
|
326
|
+
id: args.flags.get("id") || name || defaultId({ source: `local:${from}` }),
|
|
327
|
+
source: `local:${from}`,
|
|
328
|
+
...(name ? { plugin: name } : {}),
|
|
329
|
+
...(args.skills.length ? { skills: args.skills } : {}),
|
|
330
|
+
...(args.flags.get("path") ? { path: args.flags.get("path") } : {}),
|
|
331
|
+
});
|
|
332
|
+
const local = addLocalPlugin(readLocalPlugins(root) ?? emptyLocalPlugins(), request);
|
|
333
|
+
if (args.flags.has("no-install")) {
|
|
334
|
+
writeLocalPlugins(root, local);
|
|
335
|
+
console.log(`Linked ${request.id} from ${from} (${LOCAL_PLUGINS_FILE}, not installed)`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const project = loadProject(root);
|
|
339
|
+
const result = await installOne(root, project.doc, { ...request, linked: true }, project.lock, {
|
|
340
|
+
force: args.flags.has("force"),
|
|
341
|
+
saveLock: project.saveLock,
|
|
342
|
+
});
|
|
343
|
+
writeLocalPlugins(root, local);
|
|
344
|
+
console.log(`Linked ${request.id} from ${from}:`);
|
|
345
|
+
printResult({ ...result, linked: true });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function cmdUnlink(root, args, rest) {
|
|
349
|
+
if (!rest[0]) throw new Error("unlink needs a plugin id");
|
|
350
|
+
const id = rest[0];
|
|
351
|
+
const local = readLocalPlugins(root);
|
|
352
|
+
if (!local) throw new Error(`No ${LOCAL_PLUGINS_FILE}`);
|
|
353
|
+
const nextLocal = removeLocalPlugin(local, id);
|
|
354
|
+
if (nextLocal.plugins.length === 0) deleteLocalPlugins(root);
|
|
355
|
+
else writeLocalPlugins(root, nextLocal);
|
|
356
|
+
if (args.flags.has("keep-files")) {
|
|
357
|
+
console.log(`Unlinked ${id} (kept installed files)`);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const project = loadProject(root);
|
|
361
|
+
const committed = project.doc.plugins.find((p) => p.id === id && !p.linked);
|
|
362
|
+
if (committed) {
|
|
363
|
+
const result = await installOne(root, project.doc, committed, project.lock, {
|
|
364
|
+
force: args.flags.has("force"),
|
|
365
|
+
saveLock: project.saveLock,
|
|
366
|
+
});
|
|
367
|
+
console.log(`Unlinked ${id}; restored the committed request:`);
|
|
368
|
+
printResult(result);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
uninstallOne(root, id, project.lock, { saveLock: project.saveLock });
|
|
372
|
+
console.log(`Unlinked ${id}`);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function cmdProfile(root, args, rest) {
|
|
376
|
+
const [sub = "list", name] = rest;
|
|
377
|
+
switch (sub) {
|
|
378
|
+
case "new": {
|
|
379
|
+
if (!name) throw new Error("agent-deck profile new needs a name");
|
|
380
|
+
createProfile(root, name);
|
|
381
|
+
console.log(`Created ${PROFILES_DIR}/${name}. Edit its prompt.md, add plugins with: agent-deck add <source> --profile ${name}`);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
case "use": {
|
|
385
|
+
if (!name) throw new Error("agent-deck profile use needs a name");
|
|
386
|
+
targetDir(root, name);
|
|
387
|
+
useProfile(root, name);
|
|
388
|
+
await install(root, { force: args.flags.has("force") });
|
|
389
|
+
console.log(`Profile ${name} is active. Start a new Claude session (or /reload-plugins) and reload the Cursor window.`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
case "off": {
|
|
393
|
+
clearProfile(root);
|
|
394
|
+
await install(root, { force: args.flags.has("force") });
|
|
395
|
+
console.log("No profile is active.");
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
case "list": {
|
|
399
|
+
const active = loadProject(root).profile;
|
|
400
|
+
const names = listProfiles(root);
|
|
401
|
+
if (names.length === 0) console.log(`(no profiles — create one with: agent-deck profile new <name>)`);
|
|
402
|
+
for (const n of names) {
|
|
403
|
+
const count = readPlugins(profileDir(root, n))?.plugins.length ?? 0;
|
|
404
|
+
console.log(`${n === active ? "*" : " "} ${n} (${count} plugin${count === 1 ? "" : "s"})`);
|
|
405
|
+
}
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
default:
|
|
409
|
+
throw new Error(`Unknown profile command "${sub}". Use: agent-deck profile new|use|off|list`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async function cmdMaterialize(root, args) {
|
|
414
|
+
const out = args.flags.get("out");
|
|
415
|
+
if (!out) throw new Error("agent-deck materialize needs --out <dir>");
|
|
416
|
+
const profile = args.flags.get("profile");
|
|
417
|
+
if (profile) targetDir(root, profile);
|
|
418
|
+
const result = await materializeTo(root, { out, profile: profile ?? null });
|
|
419
|
+
if (args.flags.has("json")) {
|
|
420
|
+
const plugins = result.plugins.map(({ skipped, ...plugin }) => plugin);
|
|
421
|
+
console.log(JSON.stringify({ ...result, plugins }, null, 2));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
console.log(`Materialized ${result.plugins.length} plugin(s)${profile ? ` (base + profile ${profile})` : " (base)"} into ${result.out}`);
|
|
425
|
+
for (const p of result.plugins) console.log(` ${p.id}${p.skipped ? " (up to date)" : ""}`);
|
|
426
|
+
if (result.prompt) console.log(`Prompt: ${result.prompt}`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** The version of this CLI, read from its own package.json. */
|
|
430
|
+
function cliVersion() {
|
|
431
|
+
const pkgPath = new URL("../package.json", import.meta.url);
|
|
432
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf8")).version;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async function main() {
|
|
436
|
+
const argv = process.argv.slice(2);
|
|
437
|
+
if (argv.length === 1 && (argv[0] === "-v" || argv[0] === "--version")) {
|
|
438
|
+
console.log(cliVersion());
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const args = parseArgs(argv);
|
|
442
|
+
const [cmd, ...rest] = args._;
|
|
443
|
+
if (!cmd || args.flags.has("help")) {
|
|
444
|
+
console.log(USAGE);
|
|
445
|
+
process.exit(cmd || args.flags.has("help") ? 0 : 1);
|
|
446
|
+
}
|
|
447
|
+
if (!(cmd in COMMANDS)) throw new Error(`Unknown command: ${cmd}\n\n${USAGE}`);
|
|
448
|
+
checkFlags(cmd, args);
|
|
449
|
+
const root = args.project;
|
|
450
|
+
|
|
451
|
+
switch (cmd) {
|
|
452
|
+
case "init": {
|
|
453
|
+
const done = initProject(root, { commitCopies: args.flags.has("commit-copies") });
|
|
454
|
+
if (done.length === 0) console.log("Already set up.");
|
|
455
|
+
for (const line of done) console.log(` ${line}`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
case "add":
|
|
459
|
+
return cmdAdd(root, args, rest);
|
|
460
|
+
case "remove":
|
|
461
|
+
return cmdRemove(root, args, rest);
|
|
462
|
+
case "install":
|
|
463
|
+
return install(root, { frozen: args.flags.has("frozen"), force: args.flags.has("force") });
|
|
464
|
+
case "update":
|
|
465
|
+
return cmdUpdate(root, args, rest);
|
|
466
|
+
case "status":
|
|
467
|
+
return cmdStatus(root);
|
|
468
|
+
case "outdated":
|
|
469
|
+
return cmdOutdated(root);
|
|
470
|
+
case "link":
|
|
471
|
+
return cmdLink(root, args, rest);
|
|
472
|
+
case "unlink":
|
|
473
|
+
return cmdUnlink(root, args, rest);
|
|
474
|
+
case "profile":
|
|
475
|
+
return cmdProfile(root, args, rest);
|
|
476
|
+
case "materialize":
|
|
477
|
+
return cmdMaterialize(root, args);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
main().catch((err) => {
|
|
482
|
+
console.error(err.message || err);
|
|
483
|
+
process.exit(1);
|
|
484
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { plannedCopyPaths } from "./hosts/copy.mjs";
|
|
4
|
+
import { readLockfile } from "./lockfile.mjs";
|
|
5
|
+
import { CURRENT_LINK_PATH, CURSOR_RULE_PATH, HOSTS, INSTALLED_DIR, LOCAL_PLUGINS_FILE, LOCK_FILE } from "./paths.mjs";
|
|
6
|
+
import { listProfiles, profileDir } from "./project.mjs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* One block of .gitignore belongs to agent-deck, between two markers, and is
|
|
10
|
+
* rewritten whole: the local files, and (unless the project commits them) every
|
|
11
|
+
* path copy mode writes in .claude/ and .cursor/ — for the base and for every
|
|
12
|
+
* profile, active or not, so switching profiles never changes a committed file.
|
|
13
|
+
* Lines outside the block are never touched. Like npm with node_modules: commit
|
|
14
|
+
* the intent, not the output.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const GITIGNORE = ".gitignore";
|
|
18
|
+
export const BLOCK_START = "# >>> @toolmesh/agent-deck (managed: rewritten by agent-deck install)";
|
|
19
|
+
export const BLOCK_END = "# <<< @toolmesh/agent-deck";
|
|
20
|
+
|
|
21
|
+
/** Local files every project ignores. */
|
|
22
|
+
export const LOCAL_ENTRIES = [`${INSTALLED_DIR}/`, CURRENT_LINK_PATH, LOCAL_PLUGINS_FILE, CURSOR_RULE_PATH];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The copies agent-deck's block ignores: every path copy mode writes for each plugin
|
|
26
|
+
* the base or any profile pins (from the committed locks), plus what this
|
|
27
|
+
* machine actually wrote (a link, or Claude falling back to copy mode).
|
|
28
|
+
* Nothing when the project commits its copies.
|
|
29
|
+
* @param {string} projectRoot
|
|
30
|
+
* @param {import("./state.mjs").State} state
|
|
31
|
+
* @param {{ gitignoreCopies?: boolean } | null} doc the base ai-plugin.json
|
|
32
|
+
* @param {Record<string, string>} modes declared host modes (see hostModes)
|
|
33
|
+
* @returns {string[]}
|
|
34
|
+
*/
|
|
35
|
+
export function copiesToIgnore(projectRoot, state, doc, modes) {
|
|
36
|
+
if (doc?.gitignoreCopies === false) return [];
|
|
37
|
+
// Every host that is not off: a native host falls back to copy mode on a
|
|
38
|
+
// machine without its CLI, and that machine must not change a committed
|
|
39
|
+
// file. Ignoring a path nothing wrote costs nothing.
|
|
40
|
+
const hosts = Object.keys(HOSTS).filter((name) => modes[name] !== "off");
|
|
41
|
+
const locks = [projectRoot, ...listProfiles(projectRoot).map((name) => profileDir(projectRoot, name))];
|
|
42
|
+
const planned = locks.flatMap((root) => {
|
|
43
|
+
let lock = null;
|
|
44
|
+
try {
|
|
45
|
+
lock = readLockfile(root);
|
|
46
|
+
} catch {
|
|
47
|
+
// An unreadable lock is reported by `agent-deck status`; it ignores nothing here.
|
|
48
|
+
}
|
|
49
|
+
return (lock?.plugins ?? []).flatMap((entry) => plannedCopyPaths(entry.id, entry.components, hosts));
|
|
50
|
+
});
|
|
51
|
+
const written = Object.values(state.plugins).flatMap((entry) => entry.paths ?? []);
|
|
52
|
+
return [...planned, ...written];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The current block's lines (markers excluded), or null when there is none. */
|
|
56
|
+
export function readBlock(projectRoot) {
|
|
57
|
+
const file = path.join(projectRoot, GITIGNORE);
|
|
58
|
+
if (!fs.existsSync(file)) return null;
|
|
59
|
+
const lines = fs.readFileSync(file, "utf8").split(/\r?\n/);
|
|
60
|
+
const start = lines.indexOf(BLOCK_START);
|
|
61
|
+
const end = lines.indexOf(BLOCK_END, start + 1);
|
|
62
|
+
if (start === -1 || end === -1) return null;
|
|
63
|
+
return lines.slice(start + 1, end);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Write agent-deck's block in .gitignore.
|
|
68
|
+
* @param {string} projectRoot
|
|
69
|
+
* @param {{ copies?: string[], create?: boolean }} [options]
|
|
70
|
+
* copies: project paths copy mode wrote, to ignore (empty when they are committed)
|
|
71
|
+
* create: create .gitignore when it is missing (agent-deck init); install never creates it
|
|
72
|
+
* @returns {{ wrote: boolean, created: boolean }}
|
|
73
|
+
*/
|
|
74
|
+
export function writeGitignoreBlock(projectRoot, { copies = [], create = false } = {}) {
|
|
75
|
+
const file = path.join(projectRoot, GITIGNORE);
|
|
76
|
+
const exists = fs.existsSync(file);
|
|
77
|
+
if (!exists && !create) return { wrote: false, created: false };
|
|
78
|
+
|
|
79
|
+
const original = exists ? fs.readFileSync(file, "utf8") : "";
|
|
80
|
+
const lines = original.length > 0 ? original.replace(/\n$/, "").split(/\r?\n/) : [];
|
|
81
|
+
const block = [BLOCK_START, ...LOCAL_ENTRIES, ...[...new Set(copies)].sort().map((rel) => `/${rel}`), BLOCK_END];
|
|
82
|
+
const start = lines.indexOf(BLOCK_START);
|
|
83
|
+
const end = start === -1 ? -1 : lines.indexOf(BLOCK_END, start + 1);
|
|
84
|
+
|
|
85
|
+
let next;
|
|
86
|
+
if (start !== -1 && end !== -1) {
|
|
87
|
+
next = [...lines.slice(0, start), ...block, ...lines.slice(end + 1)];
|
|
88
|
+
} else {
|
|
89
|
+
next = lines.length > 0 && lines.at(-1) !== "" ? [...lines, "", ...block] : [...lines, ...block];
|
|
90
|
+
}
|
|
91
|
+
const text = `${next.join("\n")}\n`;
|
|
92
|
+
if (text === original) return { wrote: false, created: false };
|
|
93
|
+
fs.writeFileSync(file, text, "utf8");
|
|
94
|
+
return { wrote: true, created: !exists };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* What .gitignore says about agent-deck's files, for `agent-deck status`.
|
|
99
|
+
* @returns {null | { block: boolean, lockIgnored: boolean }}
|
|
100
|
+
*/
|
|
101
|
+
export function gitignoreStatus(projectRoot) {
|
|
102
|
+
const file = path.join(projectRoot, GITIGNORE);
|
|
103
|
+
if (!fs.existsSync(file)) return null;
|
|
104
|
+
const lines = fs.readFileSync(file, "utf8").split(/\r?\n/).map((l) => l.trim());
|
|
105
|
+
return {
|
|
106
|
+
block: readBlock(projectRoot) !== null,
|
|
107
|
+
lockIgnored: lines.some((l) => [LOCK_FILE, `/${LOCK_FILE}`].includes(l)),
|
|
108
|
+
};
|
|
109
|
+
}
|