@jonandev/longbeard 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/AGENTS.md +22 -0
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/beard.json +94 -0
- package/bin/long-beard.js +750 -0
- package/package.json +27 -4
- package/skills/design-md/SKILL.md +21 -0
- package/skills/design-reference-hunt/SKILL.md +161 -0
- package/skills/design-reference-hunt/references/quality.md +45 -0
- package/skills/design-reference-hunt/references/shots.md +38 -0
- package/skills/design-reference-hunt/scripts/capture.mjs +248 -0
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, readSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
+
const curatedFile = join(root, "beard.json");
|
|
11
|
+
const SKILLS_CLI = "skills@1.7.2";
|
|
12
|
+
const START = "<!-- longbeard:start -->";
|
|
13
|
+
const END = "<!-- longbeard:end -->";
|
|
14
|
+
const START_OLD = "<!-- long-beard:start -->";
|
|
15
|
+
const END_OLD = "<!-- long-beard:end -->";
|
|
16
|
+
|
|
17
|
+
const help = `Long Beard
|
|
18
|
+
|
|
19
|
+
Drop this into a project so the agents you already use produce better work.
|
|
20
|
+
The catalog is beard.json. The command is longbeard, via npx in the project.
|
|
21
|
+
|
|
22
|
+
npm install --save-dev github:jonanderdev/longbeard
|
|
23
|
+
npx longbeard init
|
|
24
|
+
npx longbeard update
|
|
25
|
+
npx longbeard list
|
|
26
|
+
|
|
27
|
+
npx longbeard init [--global] [--all] [--yes] [--agent cursor]
|
|
28
|
+
npx longbeard update [--global] [--all] [--force] [--yes]
|
|
29
|
+
npx longbeard add <source> --skill <name> --author <name> --why <text> [--when text]
|
|
30
|
+
npx longbeard remove <name>
|
|
31
|
+
|
|
32
|
+
init installs missing skills from beard.json. A skill already present for an agent is left there.
|
|
33
|
+
update installs anything new, refreshes only items in beard-lock.json, and rewrites the AGENTS.md block.
|
|
34
|
+
add in a project writes beard.local.json (an extra, not a second kit). remove omits a kit skill here.
|
|
35
|
+
--agent skips the agent list and installs for that tool. Repeat it.
|
|
36
|
+
--force replaces local edits of skills this command installed.
|
|
37
|
+
--yes skips prompts and uses the catalog agents (cursor, claude-code).
|
|
38
|
+
This does not install marketplace plugins or replace Cursor or Claude commands.
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
const color = Boolean(process.stdout.isTTY);
|
|
42
|
+
function paint(code, text) {
|
|
43
|
+
return color ? `\x1b[${code}m${text}\x1b[0m` : text;
|
|
44
|
+
}
|
|
45
|
+
const bold = (text) => paint("1", text);
|
|
46
|
+
const dim = (text) => paint("2", text);
|
|
47
|
+
const green = (text) => paint("32", text);
|
|
48
|
+
const yellow = (text) => paint("33", text);
|
|
49
|
+
const cyan = (text) => paint("36", text);
|
|
50
|
+
|
|
51
|
+
function fail(message) {
|
|
52
|
+
console.error(message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function say(text = "") {
|
|
57
|
+
console.log(text && !text.startsWith(" ") ? ` ${text}` : text);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function heading(title, flags, agents) {
|
|
61
|
+
const where = flags.global ? "this machine" : "this project";
|
|
62
|
+
say();
|
|
63
|
+
say(bold("Long Beard"));
|
|
64
|
+
say(dim(`${title} · ${where} · ${agents.join(", ")}`));
|
|
65
|
+
say();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function nameWidth(groups) {
|
|
69
|
+
const names = groups.flat().map((skill) => skill.name);
|
|
70
|
+
if (names.length === 0) return 16;
|
|
71
|
+
return Math.max(16, ...names.map((name) => name.length));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function rows(label, paintLabel, skills, note, width) {
|
|
75
|
+
if (skills.length === 0) return;
|
|
76
|
+
say(paintLabel(label));
|
|
77
|
+
for (const skill of skills) {
|
|
78
|
+
const extra = [skill.author, skill.note, skill.why].filter(Boolean);
|
|
79
|
+
const rest = extra.length > 0 ? dim(` ${extra.join(" · ")}`) : "";
|
|
80
|
+
say(` ${skill.name.padEnd(width)}${rest}`);
|
|
81
|
+
}
|
|
82
|
+
if (note) say(` ${dim(note)}`);
|
|
83
|
+
say();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function plan(kind, flags, agents, classified) {
|
|
87
|
+
heading(kind, flags, agents);
|
|
88
|
+
const refresh = kind === "update" ? (flags.force ? [...classified.ours, ...classified.edited] : classified.ours) : [];
|
|
89
|
+
const heldEdits = kind === "update" && !flags.force ? classified.edited : [];
|
|
90
|
+
const already = kind === "update" ? classified.theirs : [...classified.theirs, ...classified.ours, ...classified.edited];
|
|
91
|
+
const width = nameWidth([already, heldEdits, refresh, classified.missing, classified.later ?? []]);
|
|
92
|
+
rows("already there", yellow, already, "Present for that agent. Not copied again.", width);
|
|
93
|
+
rows("your edits", yellow, heldEdits, "Changed after this command installed them. Pass --force to replace them.", width);
|
|
94
|
+
rows("refresh", cyan, refresh, "In beard-lock.json. Pull the author's current files.", width);
|
|
95
|
+
rows("install", green, classified.missing, "", width);
|
|
96
|
+
rows("later", dim, classified.later ?? [], "In the catalog. This version only installs skills.", width);
|
|
97
|
+
if (classified.writes.length > 0) {
|
|
98
|
+
say(cyan("will write"));
|
|
99
|
+
for (const file of classified.writes) say(` ${file}`);
|
|
100
|
+
say();
|
|
101
|
+
}
|
|
102
|
+
if (classified.missing.length === 0 && refresh.length === 0 && heldEdits.length === 0) {
|
|
103
|
+
say(dim("Nothing new to install."));
|
|
104
|
+
say();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function finish(lines) {
|
|
109
|
+
for (const line of lines) say(line);
|
|
110
|
+
say();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function readJson(file) {
|
|
114
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function writeJson(file, value) {
|
|
118
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
119
|
+
writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function parseArgs(argv) {
|
|
123
|
+
const flags = {
|
|
124
|
+
global: false,
|
|
125
|
+
all: false,
|
|
126
|
+
force: false,
|
|
127
|
+
yes: false,
|
|
128
|
+
optional: false,
|
|
129
|
+
agents: [],
|
|
130
|
+
skill: [],
|
|
131
|
+
why: "",
|
|
132
|
+
when: "",
|
|
133
|
+
author: "",
|
|
134
|
+
license: "",
|
|
135
|
+
};
|
|
136
|
+
const positionals = [];
|
|
137
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
138
|
+
const arg = argv[i];
|
|
139
|
+
if (arg === "--global" || arg === "-g") flags.global = true;
|
|
140
|
+
else if (arg === "--all") flags.all = true;
|
|
141
|
+
else if (arg === "--force") flags.force = true;
|
|
142
|
+
else if (arg === "--yes" || arg === "-y") flags.yes = true;
|
|
143
|
+
else if (arg === "--optional") flags.optional = true;
|
|
144
|
+
else if (arg === "--help" || arg === "-h") flags.help = true;
|
|
145
|
+
else if (arg === "--agent" || arg === "-a") flags.agents.push(take(argv, ++i, arg));
|
|
146
|
+
else if (arg === "--skill" || arg === "-s") flags.skill.push(take(argv, ++i, arg));
|
|
147
|
+
else if (arg === "--why") flags.why = take(argv, ++i, arg);
|
|
148
|
+
else if (arg === "--when") flags.when = take(argv, ++i, arg);
|
|
149
|
+
else if (arg === "--author") flags.author = take(argv, ++i, arg);
|
|
150
|
+
else if (arg === "--license") flags.license = take(argv, ++i, arg);
|
|
151
|
+
else if (arg.startsWith("-")) fail(`Unknown flag: ${arg}\n\n${help}`);
|
|
152
|
+
else positionals.push(arg);
|
|
153
|
+
}
|
|
154
|
+
return { command: positionals[0] || "help", rest: positionals.slice(1), flags };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function take(argv, index, flag) {
|
|
158
|
+
if (index >= argv.length || argv[index].startsWith("-")) fail(`${flag} needs a value`);
|
|
159
|
+
return argv[index];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function inRepository() {
|
|
163
|
+
return resolve(process.cwd()) === resolve(root);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function extraFile(flags, forWrite = false) {
|
|
167
|
+
if (flags.global) {
|
|
168
|
+
const next = join(homedir(), ".longbeard", "beard.local.json");
|
|
169
|
+
if (forWrite) return next;
|
|
170
|
+
const prev = join(homedir(), ".long-beard", "extra.json");
|
|
171
|
+
return existsSync(next) || !existsSync(prev) ? next : prev;
|
|
172
|
+
}
|
|
173
|
+
const next = join(process.cwd(), "beard.local.json");
|
|
174
|
+
if (forWrite) return next;
|
|
175
|
+
const prev = join(process.cwd(), "long-beard.json");
|
|
176
|
+
return existsSync(next) || !existsSync(prev) ? next : prev;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function lockFile(flags, forWrite = false) {
|
|
180
|
+
if (flags.global) {
|
|
181
|
+
const next = join(homedir(), ".longbeard", "beard-lock.json");
|
|
182
|
+
if (forWrite) return next;
|
|
183
|
+
const prev = join(homedir(), ".long-beard", "beard-lock.json");
|
|
184
|
+
return existsSync(next) || !existsSync(prev) ? next : prev;
|
|
185
|
+
}
|
|
186
|
+
return join(process.cwd(), "beard-lock.json");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function curated() {
|
|
190
|
+
return readJson(curatedFile);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function catalog(manifest) {
|
|
194
|
+
return manifest.items ?? manifest.skills ?? [];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function kind(item) {
|
|
198
|
+
return item.kind || "skill";
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function extraState(flags) {
|
|
202
|
+
if (inRepository() && !flags.global) return { items: [], omit: [] };
|
|
203
|
+
const file = extraFile(flags);
|
|
204
|
+
if (!existsSync(file)) return { items: [], omit: [] };
|
|
205
|
+
const data = readJson(file);
|
|
206
|
+
return { items: data.items ?? data.skills ?? [], omit: data.omit ?? [] };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function writeExtra(flags, state) {
|
|
210
|
+
writeJson(extraFile(flags, true), {
|
|
211
|
+
omit: state.omit ?? [],
|
|
212
|
+
items: state.items ?? [],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function chosen(flags) {
|
|
217
|
+
const manifest = curated();
|
|
218
|
+
const extra = extraState(flags);
|
|
219
|
+
const omitted = new Set(extra.omit);
|
|
220
|
+
const shared = catalog(manifest).filter((item) => (flags.all || !item.optional) && !omitted.has(item.name));
|
|
221
|
+
const seen = new Set(shared.map((item) => item.name));
|
|
222
|
+
const extras = extra.items.filter((item) => !seen.has(item.name) && !omitted.has(item.name));
|
|
223
|
+
const items = [...shared, ...extras];
|
|
224
|
+
return {
|
|
225
|
+
manifest,
|
|
226
|
+
extra,
|
|
227
|
+
items,
|
|
228
|
+
skills: items.filter((item) => kind(item) === "skill"),
|
|
229
|
+
later: items.filter((item) => kind(item) !== "skill"),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const agentNames = {
|
|
234
|
+
cursor: "Cursor",
|
|
235
|
+
"claude-code": "Claude Code",
|
|
236
|
+
codex: "Codex",
|
|
237
|
+
"github-copilot": "GitHub Copilot",
|
|
238
|
+
"gemini-cli": "Gemini CLI",
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
function knownAgents() {
|
|
242
|
+
return Object.keys(agentDirs);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function agentsFromLock(lock) {
|
|
246
|
+
return [...new Set(Object.values(lock?.skills ?? {}).flatMap((entry) => entry.agents ?? []))];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function readKey() {
|
|
250
|
+
const buf = Buffer.alloc(8);
|
|
251
|
+
const n = readSync(0, buf, 0, 8, null);
|
|
252
|
+
if (n <= 0) return "enter";
|
|
253
|
+
const code = buf[0];
|
|
254
|
+
if (code === 3) return "ctrl-c";
|
|
255
|
+
if (code === 13 || code === 10) return "enter";
|
|
256
|
+
if (code === 32) return "space";
|
|
257
|
+
if (code === 27 && buf[1] === 91) {
|
|
258
|
+
if (buf[2] === 65) return "up";
|
|
259
|
+
if (buf[2] === 66) return "down";
|
|
260
|
+
}
|
|
261
|
+
if (code === 107) return "up";
|
|
262
|
+
if (code === 106) return "down";
|
|
263
|
+
return "";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function pickAgents(options, selected) {
|
|
267
|
+
const on = new Set(selected);
|
|
268
|
+
let index = 0;
|
|
269
|
+
const height = options.length + 1;
|
|
270
|
+
const paintList = (first) => {
|
|
271
|
+
if (!first) process.stdout.write(`\x1b[${height}A`);
|
|
272
|
+
process.stdout.write(` Which agents? ${dim("space toggle · enter continue")}\x1b[K\n`);
|
|
273
|
+
for (let i = 0; i < options.length; i += 1) {
|
|
274
|
+
const name = options[i];
|
|
275
|
+
const arrow = i === index ? "❯" : " ";
|
|
276
|
+
const mark = on.has(name) ? "x" : " ";
|
|
277
|
+
const label = (agentNames[name] ?? name).padEnd(16);
|
|
278
|
+
const path = flagsPath(name);
|
|
279
|
+
process.stdout.write(` ${arrow} [${mark}] ${label} ${dim(path)}\x1b[K\n`);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
function flagsPath(name) {
|
|
283
|
+
return agentDirs[name].project;
|
|
284
|
+
}
|
|
285
|
+
process.stdin.setRawMode(true);
|
|
286
|
+
paintList(true);
|
|
287
|
+
try {
|
|
288
|
+
while (true) {
|
|
289
|
+
const key = readKey();
|
|
290
|
+
if (key === "ctrl-c") fail("Aborted.");
|
|
291
|
+
if (key === "enter") {
|
|
292
|
+
if (on.size === 0) continue;
|
|
293
|
+
return options.filter((name) => on.has(name));
|
|
294
|
+
}
|
|
295
|
+
if (key === "space") {
|
|
296
|
+
const name = options[index];
|
|
297
|
+
if (on.has(name)) on.delete(name);
|
|
298
|
+
else on.add(name);
|
|
299
|
+
} else if (key === "up") index = (index + options.length - 1) % options.length;
|
|
300
|
+
else if (key === "down") index = (index + 1) % options.length;
|
|
301
|
+
paintList(false);
|
|
302
|
+
}
|
|
303
|
+
} finally {
|
|
304
|
+
process.stdin.setRawMode(false);
|
|
305
|
+
say();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function chooseAgents(manifest, flags, { pick, lock } = {}) {
|
|
310
|
+
const known = knownAgents();
|
|
311
|
+
if (flags.agents.length) {
|
|
312
|
+
const bad = flags.agents.filter((name) => !known.includes(name));
|
|
313
|
+
if (bad.length) fail(`Unknown agent: ${bad.join(", ")}. Known: ${known.join(", ")}`);
|
|
314
|
+
const listed = [...new Set(flags.agents)];
|
|
315
|
+
if (pick) return listed;
|
|
316
|
+
return [...new Set([...agentsFromLock(lock).filter((name) => known.includes(name)), ...listed])];
|
|
317
|
+
}
|
|
318
|
+
if (!pick) {
|
|
319
|
+
const locked = agentsFromLock(lock).filter((name) => known.includes(name));
|
|
320
|
+
if (locked.length) return locked;
|
|
321
|
+
}
|
|
322
|
+
const fallback = (manifest.agents ?? []).filter((name) => known.includes(name));
|
|
323
|
+
const start = fallback.length ? fallback : ["cursor"];
|
|
324
|
+
if (!pick || flags.yes || !process.stdin.isTTY) return start;
|
|
325
|
+
return pickAgents(known, start);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function sourcePath(skill) {
|
|
329
|
+
if (skill.source !== "local") return skill.source;
|
|
330
|
+
return join(root, "skills");
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function runSkills(args) {
|
|
334
|
+
const npx = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
335
|
+
const result = spawnSync(npx, ["--yes", SKILLS_CLI, ...args], {
|
|
336
|
+
stdio: "inherit",
|
|
337
|
+
shell: process.platform === "win32",
|
|
338
|
+
});
|
|
339
|
+
if (result.error) fail(`Could not run npx. ${result.error.message}`);
|
|
340
|
+
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const agentDirs = {
|
|
344
|
+
cursor: { project: ".agents/skills", home: ".cursor/skills" },
|
|
345
|
+
"claude-code": { project: ".claude/skills", home: ".claude/skills" },
|
|
346
|
+
codex: { project: ".agents/skills", home: ".agents/skills" },
|
|
347
|
+
"github-copilot": { project: ".agents/skills", home: ".copilot/skills" },
|
|
348
|
+
"gemini-cli": { project: ".agents/skills", home: ".gemini/skills" },
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
function childDirs(dir) {
|
|
352
|
+
if (!existsSync(dir)) return [];
|
|
353
|
+
try {
|
|
354
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
355
|
+
.filter((entry) => entry.isDirectory())
|
|
356
|
+
.map((entry) => join(dir, entry.name));
|
|
357
|
+
} catch {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function pluginHas(name) {
|
|
363
|
+
for (const base of [join(homedir(), ".claude", "plugins"), join(process.cwd(), ".claude", "plugins")]) {
|
|
364
|
+
for (const plugin of childDirs(base)) {
|
|
365
|
+
if (existsSync(join(plugin, "skills", name, "SKILL.md"))) return true;
|
|
366
|
+
for (const nested of childDirs(plugin)) {
|
|
367
|
+
if (existsSync(join(nested, "skills", name, "SKILL.md"))) return true;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function agentDir(agent, global) {
|
|
375
|
+
const dirs = agentDirs[agent];
|
|
376
|
+
if (!dirs) fail(`Unknown agent: ${agent}. Known: ${Object.keys(agentDirs).join(", ")}.`);
|
|
377
|
+
return global ? join(homedir(), dirs.home) : join(process.cwd(), dirs.project);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function agentHas(name, agent, global) {
|
|
381
|
+
if (existsSync(join(agentDir(agent, global), name, "SKILL.md"))) return true;
|
|
382
|
+
return agent === "claude-code" && pluginHas(name);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function readLock(flags) {
|
|
386
|
+
const file = lockFile(flags);
|
|
387
|
+
if (!existsSync(file)) return { version: 1, skills: {} };
|
|
388
|
+
try {
|
|
389
|
+
const data = readJson(file);
|
|
390
|
+
return { version: 1, skills: data.skills ?? {} };
|
|
391
|
+
} catch {
|
|
392
|
+
return { version: 1, skills: {} };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function writeLock(flags, lock) {
|
|
397
|
+
writeJson(lockFile(flags, true), { version: 1, skills: lock.skills });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function recordInstall(lock, skill, agents) {
|
|
401
|
+
const prev = lock.skills[skill.name] ?? { agents: [] };
|
|
402
|
+
lock.skills[skill.name] = {
|
|
403
|
+
source: skill.source,
|
|
404
|
+
author: skill.author,
|
|
405
|
+
agents: [...new Set([...prev.agents, ...agents])],
|
|
406
|
+
installedAt: new Date().toISOString(),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function skillMarkdown(name, agents, global) {
|
|
411
|
+
const files = [];
|
|
412
|
+
const seen = new Set();
|
|
413
|
+
for (const agent of agents) {
|
|
414
|
+
const file = join(agentDir(agent, global), name, "SKILL.md");
|
|
415
|
+
if (seen.has(file)) continue;
|
|
416
|
+
seen.add(file);
|
|
417
|
+
if (existsSync(file)) files.push(file);
|
|
418
|
+
}
|
|
419
|
+
return files;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function locallyEdited(name, entry, agents, global) {
|
|
423
|
+
const installed = Date.parse(entry?.installedAt ?? "");
|
|
424
|
+
if (Number.isNaN(installed)) return false;
|
|
425
|
+
return skillMarkdown(name, entry.agents ?? agents, global).some((file) => statSync(file).mtimeMs > installed + 2000);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function generateRouter(items) {
|
|
429
|
+
const lines = items.filter((item) => kind(item) === "skill").map((item) => {
|
|
430
|
+
const when = item.when?.trim() || item.name;
|
|
431
|
+
const why = item.why?.trim();
|
|
432
|
+
return why ? `- ${when}: ${item.name}. ${why}` : `- ${when}: ${item.name}`;
|
|
433
|
+
});
|
|
434
|
+
return `# Long Beard
|
|
435
|
+
|
|
436
|
+
The project's own code, conventions, and DESIGN.md win.
|
|
437
|
+
|
|
438
|
+
Load only what the task needs. Leave the rest unread.
|
|
439
|
+
|
|
440
|
+
A marketing site is the page a person lands on to understand or choose. An application is the tool they come back to. With no DESIGN.md and no Figma, both hunt. A site hunts live pages, and those outweigh Dribbble. An application hunts screen shots, and those outweigh award sites. With a direction already, hunt only the piece.
|
|
441
|
+
|
|
442
|
+
${lines.join("\n")}
|
|
443
|
+
|
|
444
|
+
A normal change can be ponytail and a short premortem. That is still a small set.
|
|
445
|
+
|
|
446
|
+
Write so a person can use the reply in one read. End with what you did not check.
|
|
447
|
+
`;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function pointerWrites(flags, agents) {
|
|
451
|
+
if (flags.global) {
|
|
452
|
+
const home = join(homedir(), ".longbeard");
|
|
453
|
+
const dirs = [...new Set(agents.map((agent) => agentDir(agent, true)))];
|
|
454
|
+
return [join(home, "AGENTS.md"), join(home, "beard-lock.json"), ...dirs];
|
|
455
|
+
}
|
|
456
|
+
return ["AGENTS.md", "beard-lock.json"];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function classify(skills, agents, flags) {
|
|
460
|
+
const lock = readLock(flags);
|
|
461
|
+
const missing = [];
|
|
462
|
+
const ours = [];
|
|
463
|
+
const edited = [];
|
|
464
|
+
const theirs = [];
|
|
465
|
+
for (const skill of skills) {
|
|
466
|
+
const present = agents.filter((agent) => agentHas(skill.name, agent, flags.global));
|
|
467
|
+
const need = agents.filter((agent) => !agentHas(skill.name, agent, flags.global));
|
|
468
|
+
const oursAlready = Boolean(lock.skills[skill.name]);
|
|
469
|
+
if (oursAlready) {
|
|
470
|
+
if (locallyEdited(skill.name, lock.skills[skill.name], agents, flags.global)) edited.push(skill);
|
|
471
|
+
else ours.push(skill);
|
|
472
|
+
if (need.length > 0) missing.push({ ...skill, agentsNeed: need, note: `missing on ${need.join(", ")}` });
|
|
473
|
+
} else if (need.length === 0) {
|
|
474
|
+
theirs.push({ ...skill, note: `already on ${present.join(", ")}` });
|
|
475
|
+
} else {
|
|
476
|
+
missing.push({
|
|
477
|
+
...skill,
|
|
478
|
+
agentsNeed: need,
|
|
479
|
+
note: present.length > 0 ? `already on ${present.join(", ")}` : "",
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return { missing, ours, edited, theirs, writes: pointerWrites(flags, agents), lock };
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function confirmWrite(flags, writes) {
|
|
487
|
+
if (writes.length === 0 || flags.yes || !process.stdin.isTTY) return;
|
|
488
|
+
say(dim("Proceed? [Y/n]"));
|
|
489
|
+
const buf = Buffer.alloc(80);
|
|
490
|
+
const n = readSync(0, buf, 0, 80, null);
|
|
491
|
+
const line = buf.toString("utf8", 0, n).trim().toLowerCase();
|
|
492
|
+
if (line && line !== "y" && line !== "yes") fail("Aborted.");
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function installSkills(skills, { global, agents }) {
|
|
496
|
+
if (skills.length === 0) return;
|
|
497
|
+
const groups = new Map();
|
|
498
|
+
for (const skill of skills) {
|
|
499
|
+
const source = sourcePath(skill);
|
|
500
|
+
const need = skill.agentsNeed ?? agents;
|
|
501
|
+
const key = `${source}::${need.join(",")}`;
|
|
502
|
+
const group = groups.get(key) ?? { source, agents: need, names: [] };
|
|
503
|
+
group.names.push(skill.name);
|
|
504
|
+
groups.set(key, group);
|
|
505
|
+
}
|
|
506
|
+
for (const { source, agents: target, names } of groups.values()) {
|
|
507
|
+
const args = ["add", source, "-y"];
|
|
508
|
+
for (const name of names) args.push("--skill", name);
|
|
509
|
+
if (global) args.push("--global");
|
|
510
|
+
for (const agent of target) args.push("--agent", agent);
|
|
511
|
+
runSkills(args);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function upsertBlock(file, block) {
|
|
516
|
+
const wrapped = `${START}\n${block.trim()}\n${END}\n`;
|
|
517
|
+
if (!existsSync(file)) {
|
|
518
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
519
|
+
writeFileSync(file, wrapped);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
const current = readFileSync(file, "utf8");
|
|
523
|
+
for (const [open, close] of [[START, END], [START_OLD, END_OLD]]) {
|
|
524
|
+
const start = current.indexOf(open);
|
|
525
|
+
const end = current.indexOf(close);
|
|
526
|
+
if (start !== -1 && end > start) {
|
|
527
|
+
const next = `${current.slice(0, start)}${wrapped}${current.slice(end + close.length).replace(/^\n/, "")}`;
|
|
528
|
+
writeFileSync(file, next.endsWith("\n") ? next : `${next}\n`);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
writeFileSync(file, `${current.endsWith("\n") ? current : `${current}\n`}\n${wrapped}`);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function writePointers(flags, skills) {
|
|
536
|
+
const text = generateRouter(skills);
|
|
537
|
+
if (flags.global) {
|
|
538
|
+
const dir = join(homedir(), ".longbeard");
|
|
539
|
+
mkdirSync(dir, { recursive: true });
|
|
540
|
+
writeFileSync(join(dir, "AGENTS.md"), text.endsWith("\n") ? text : `${text}\n`);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
upsertBlock(join(process.cwd(), "AGENTS.md"), text);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function requireProject(flags) {
|
|
547
|
+
if (!flags.global && inRepository()) fail("Run this in the project you want Long Beard in.");
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function entry(name, source, flags) {
|
|
551
|
+
return {
|
|
552
|
+
kind: "skill",
|
|
553
|
+
name,
|
|
554
|
+
author: flags.author,
|
|
555
|
+
license: flags.license || "see repository",
|
|
556
|
+
source,
|
|
557
|
+
...(flags.optional ? { optional: true } : {}),
|
|
558
|
+
...(flags.when ? { when: flags.when } : {}),
|
|
559
|
+
why: flags.why,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function setCatalog(manifest, items) {
|
|
564
|
+
manifest.items = items;
|
|
565
|
+
delete manifest.skills;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function remember(lock, flags, skills, agents) {
|
|
569
|
+
for (const skill of skills) recordInstall(lock, skill, skill.agentsNeed ?? agents);
|
|
570
|
+
writeLock(flags, lock);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function init(flags) {
|
|
574
|
+
requireProject(flags);
|
|
575
|
+
const { manifest, skills, items, later } = chosen(flags);
|
|
576
|
+
const agents = chooseAgents(manifest, flags, { pick: true, lock: readLock(flags) });
|
|
577
|
+
const classified = classify(skills, agents, flags);
|
|
578
|
+
classified.later = later;
|
|
579
|
+
plan("init", flags, agents, classified);
|
|
580
|
+
confirmWrite(flags, classified.writes);
|
|
581
|
+
if (classified.missing.length > 0) say(dim("Installing…"));
|
|
582
|
+
installSkills(classified.missing, { global: flags.global, agents });
|
|
583
|
+
remember(classified.lock, flags, classified.missing, agents);
|
|
584
|
+
writePointers(flags, items);
|
|
585
|
+
finish([
|
|
586
|
+
green("Done."),
|
|
587
|
+
`${classified.missing.length} installed, ${classified.theirs.length + classified.ours.length + classified.edited.length} already there.`,
|
|
588
|
+
flags.global ? "Skills are available in every project on this machine. A copy of the note is in ~/.longbeard/AGENTS.md." : "Wrote the AGENTS.md block and beard-lock.json.",
|
|
589
|
+
]);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function update(flags) {
|
|
593
|
+
requireProject(flags);
|
|
594
|
+
const { manifest, skills, items, later } = chosen(flags);
|
|
595
|
+
const agents = chooseAgents(manifest, flags, { pick: false, lock: readLock(flags) });
|
|
596
|
+
const classified = classify(skills, agents, flags);
|
|
597
|
+
classified.later = later;
|
|
598
|
+
plan("update", flags, agents, classified);
|
|
599
|
+
confirmWrite(flags, classified.writes);
|
|
600
|
+
const refresh = flags.force ? [...classified.ours, ...classified.edited] : classified.ours;
|
|
601
|
+
if (classified.missing.length > 0) say(dim("Installing…"));
|
|
602
|
+
installSkills(classified.missing, { global: flags.global, agents });
|
|
603
|
+
remember(classified.lock, flags, classified.missing, agents);
|
|
604
|
+
if (refresh.length > 0) {
|
|
605
|
+
say(dim("Refreshing…"));
|
|
606
|
+
const args = ["update", ...refresh.map((skill) => skill.name), "-y"];
|
|
607
|
+
if (flags.global) args.push("--global");
|
|
608
|
+
else args.push("--project");
|
|
609
|
+
runSkills(args);
|
|
610
|
+
remember(readLock(flags), flags, refresh, agents);
|
|
611
|
+
}
|
|
612
|
+
writePointers(flags, items);
|
|
613
|
+
const held = flags.force ? classified.theirs.length : classified.theirs.length + classified.edited.length;
|
|
614
|
+
finish([
|
|
615
|
+
green("Done."),
|
|
616
|
+
`${classified.missing.length} installed, ${refresh.length} refreshed, ${held} left as they are.`,
|
|
617
|
+
flags.global ? "Rewrote ~/.longbeard/AGENTS.md." : "Rewrote the AGENTS.md block.",
|
|
618
|
+
]);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function add(flags, rest) {
|
|
622
|
+
const source = rest[0];
|
|
623
|
+
if (!source || flags.skill.length === 0 || !flags.author || !flags.why) {
|
|
624
|
+
fail(`add needs a source, --skill, --author, and --why.\n\n${help}`);
|
|
625
|
+
}
|
|
626
|
+
if (inRepository() && !flags.global) {
|
|
627
|
+
const manifest = curated();
|
|
628
|
+
const items = catalog(manifest);
|
|
629
|
+
for (const name of flags.skill) {
|
|
630
|
+
if (items.some((item) => item.name === name)) fail(`${name} is already in the catalog.`);
|
|
631
|
+
items.push(entry(name, source, flags));
|
|
632
|
+
}
|
|
633
|
+
setCatalog(manifest, items);
|
|
634
|
+
writeJson(curatedFile, manifest);
|
|
635
|
+
heading("add", flags, curated().agents);
|
|
636
|
+
rows("catalog", green, flags.skill.map((name) => entry(name, source, flags)), "", 16);
|
|
637
|
+
finish([green("Done."), "Wrote beard.json. Commit it and push. Projects pick this up on update."]);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const extra = extraState(flags);
|
|
641
|
+
const manifest = curated();
|
|
642
|
+
for (const name of flags.skill) {
|
|
643
|
+
if (extra.omit.includes(name)) {
|
|
644
|
+
fail(`${name} is omitted here. Delete it from omit in ${extraFile(flags)} and run update.`);
|
|
645
|
+
}
|
|
646
|
+
if (catalog(manifest).some((item) => item.name === name) || extra.items.some((item) => item.name === name)) {
|
|
647
|
+
fail(`${name} is already in the catalog.`);
|
|
648
|
+
}
|
|
649
|
+
extra.items.push(entry(name, source, flags));
|
|
650
|
+
}
|
|
651
|
+
writeExtra(flags, extra);
|
|
652
|
+
const toInstall = flags.skill.map((name) => ({ name, source, author: flags.author, why: flags.why, when: flags.when }));
|
|
653
|
+
const agents = chooseAgents(manifest, flags, { pick: false, lock: readLock(flags) });
|
|
654
|
+
const classified = classify(toInstall, agents, flags);
|
|
655
|
+
plan("add", flags, agents, classified);
|
|
656
|
+
if (classified.missing.length > 0) say(dim("Installing…"));
|
|
657
|
+
installSkills(classified.missing, { global: flags.global, agents });
|
|
658
|
+
remember(classified.lock, flags, classified.missing, agents);
|
|
659
|
+
writePointers(flags, chosen(flags).items);
|
|
660
|
+
finish([
|
|
661
|
+
green("Done."),
|
|
662
|
+
`On this ${flags.global ? "machine" : "project"} catalog: ${flags.skill.join(", ")}.`,
|
|
663
|
+
]);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function remove(flags, rest) {
|
|
667
|
+
const names = rest;
|
|
668
|
+
if (names.length === 0) fail(`remove needs a skill name.\n\n${help}`);
|
|
669
|
+
if (inRepository() && !flags.global) {
|
|
670
|
+
const manifest = curated();
|
|
671
|
+
const items = catalog(manifest);
|
|
672
|
+
const known = new Set(items.map((item) => item.name));
|
|
673
|
+
for (const name of names) {
|
|
674
|
+
if (!known.has(name)) fail(`${name} is not in the catalog.`);
|
|
675
|
+
}
|
|
676
|
+
setCatalog(manifest, items.filter((item) => !names.includes(item.name)));
|
|
677
|
+
writeJson(curatedFile, manifest);
|
|
678
|
+
heading("remove", flags, curated().agents);
|
|
679
|
+
rows("catalog", yellow, names.map((name) => ({ name })), "", 16);
|
|
680
|
+
finish([green("Done."), "Wrote beard.json. Commit it and push."]);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const { manifest, extra } = chosen(flags);
|
|
684
|
+
const shared = new Set(catalog(manifest).map((item) => item.name));
|
|
685
|
+
const extraNames = new Set(extra.items.map((item) => item.name));
|
|
686
|
+
for (const name of names) {
|
|
687
|
+
if (!shared.has(name) && !extraNames.has(name) && !extra.omit.includes(name)) {
|
|
688
|
+
fail(`${name} is not on this ${flags.global ? "machine" : "project"} catalog.`);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
extra.items = extra.items.filter((item) => !names.includes(item.name));
|
|
692
|
+
for (const name of names) {
|
|
693
|
+
if (shared.has(name) && !extra.omit.includes(name)) extra.omit.push(name);
|
|
694
|
+
}
|
|
695
|
+
writeExtra(flags, extra);
|
|
696
|
+
const lock = readLock(flags);
|
|
697
|
+
const ours = names.filter((name) => lock.skills[name]);
|
|
698
|
+
const agents = chooseAgents(manifest, flags, { pick: false, lock });
|
|
699
|
+
heading("remove", flags, agents);
|
|
700
|
+
rows("remove", yellow, names.map((name) => ({ name })), shared.has(names[0]) ? "Omitted here. Still in the shared catalog." : "This project only.", 16);
|
|
701
|
+
if (ours.length > 0) {
|
|
702
|
+
say(dim("Removing…"));
|
|
703
|
+
const args = ["remove", ...ours, "-y"];
|
|
704
|
+
if (flags.global) args.push("--global");
|
|
705
|
+
for (const agent of agents) args.push("--agent", agent);
|
|
706
|
+
runSkills(args);
|
|
707
|
+
for (const name of ours) delete lock.skills[name];
|
|
708
|
+
writeLock(flags, lock);
|
|
709
|
+
}
|
|
710
|
+
const next = chosen(flags);
|
|
711
|
+
writePointers(flags, next.items);
|
|
712
|
+
finish([
|
|
713
|
+
green("Done."),
|
|
714
|
+
`Removed ${names.join(", ")} from this ${flags.global ? "machine" : "project"}.`,
|
|
715
|
+
]);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function printSkill(skill, width, extra) {
|
|
719
|
+
const mark = extra.omit?.includes(skill.name) ? yellow("omitted ") : skill.optional ? dim("optional") : green("kept ");
|
|
720
|
+
const credit = [skill.author, skill.license].filter(Boolean).join(", ");
|
|
721
|
+
say(`${mark} ${skill.name.padEnd(width)} ${dim(credit)}`);
|
|
722
|
+
if (skill.why) say(` ${skill.why}`);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function list(flags) {
|
|
726
|
+
const shared = catalog(curated());
|
|
727
|
+
const extra = extraState(flags);
|
|
728
|
+
const width = nameWidth([shared, extra.items]);
|
|
729
|
+
say();
|
|
730
|
+
say(bold("Long Beard"));
|
|
731
|
+
say(dim("Catalog · beard.json"));
|
|
732
|
+
say();
|
|
733
|
+
for (const item of shared) printSkill(item, width, extra);
|
|
734
|
+
if (extra.items.length > 0) {
|
|
735
|
+
say();
|
|
736
|
+
say(dim(flags.global ? "This machine" : "This project"));
|
|
737
|
+
say();
|
|
738
|
+
for (const item of extra.items) printSkill(item, width, extra);
|
|
739
|
+
}
|
|
740
|
+
say();
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const { command, rest, flags } = parseArgs(process.argv.slice(2));
|
|
744
|
+
if (flags.help || command === "help") console.log(help);
|
|
745
|
+
else if (command === "init") init(flags);
|
|
746
|
+
else if (command === "add") add(flags, rest);
|
|
747
|
+
else if (command === "remove") remove(flags, rest);
|
|
748
|
+
else if (command === "update") update(flags);
|
|
749
|
+
else if (command === "list") list(flags);
|
|
750
|
+
else fail(`Unknown command: ${command}\n\n${help}`);
|