@jonandev/longbeard 0.11.2 → 0.12.1
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 +4 -5
- package/CHANGELOG.md +72 -0
- package/README.md +64 -43
- package/beard.json +124 -28
- package/bin/long-beard.js +171 -36
- package/package.json +1 -1
- package/skills/design/SKILL.md +51 -126
- package/skills/design-brief/SKILL.md +146 -0
- package/skills/design-brief/references/graphic.md +59 -0
- package/skills/design-check/SKILL.md +27 -11
- package/skills/design-check/references/design-rules.md +21 -7
- package/skills/design-check/scripts/capture.mjs +121 -37
- package/skills/design-check/scripts/contrast.mjs +23 -9
- package/skills/design-check/scripts/rules.mjs +613 -0
- package/skills/design-check/scripts/screen-contrast.mjs +428 -0
- package/skills/design-check/scripts/tokens.mjs +346 -0
- package/skills/design-content/SKILL.md +118 -0
- package/skills/design-content/scripts/contact-sheet.mjs +259 -0
- package/skills/design-content/scripts/pictures.mjs +197 -0
- package/skills/design-direction/SKILL.md +115 -200
- package/skills/design-direction/references/controls.md +58 -0
- package/skills/{design → design-direction}/references/design-rules.md +21 -7
- package/skills/design-direction/references/five-second.md +47 -0
- package/skills/design-direction/references/full-build.md +19 -0
- package/skills/design-direction/references/graphic.md +35 -0
- package/skills/design-direction/references/grid.md +114 -0
- package/skills/design-direction/references/library.md +75 -0
- package/skills/design-direction/references/screen-template.html +233 -0
- package/skills/design-direction/references/subject.md +33 -0
- package/skills/design-direction/scripts/capture.mjs +121 -37
- package/skills/design-direction/scripts/contact-sheet.mjs +18 -7
- package/skills/design-direction/scripts/fonts.mjs +276 -0
- package/skills/design-direction/scripts/layout-diff.mjs +118 -0
- package/skills/design-direction/scripts/measure.mjs +1728 -0
- package/skills/design-direction/scripts/moodboard.mjs +123 -32
- package/skills/design-direction/scripts/picture-cast.mjs +270 -0
- package/skills/design-direction/scripts/pictures.mjs +197 -0
- package/skills/design-direction/scripts/screen-contrast.mjs +428 -0
- package/skills/design-direction/scripts/sheet.mjs +67 -0
- package/skills/design-direction/scripts/subject-colours.mjs +410 -0
- package/skills/design-families/SKILL.md +138 -0
- package/skills/design-families/scripts/contact-sheet.mjs +259 -0
- package/skills/design-families/scripts/families.mjs +606 -0
- package/skills/design-families/scripts/measure.mjs +1728 -0
- package/skills/design-families/scripts/moodboard.mjs +467 -0
- package/skills/design-families/scripts/tag.mjs +289 -0
- package/skills/design-figma/SKILL.md +69 -0
- package/skills/design-figma/references/graphic.md +26 -0
- package/skills/design-identity/SKILL.md +134 -0
- package/skills/design-identity/references/graphic.md +8 -0
- package/skills/design-identity/references/identity-board.html +140 -0
- package/skills/{design → design-identity}/scripts/capture.mjs +121 -37
- package/skills/design-identity/scripts/colours.mjs +213 -0
- package/skills/design-identity/scripts/contrast.mjs +41 -0
- package/skills/design-identity/scripts/fonts.mjs +276 -0
- package/skills/design-identity/scripts/measure.mjs +1728 -0
- package/skills/design-identity/scripts/sheet.mjs +67 -0
- package/skills/design-identity/scripts/subject-colours.mjs +410 -0
- package/skills/design-moodboard/SKILL.md +184 -0
- package/skills/design-moodboard/references/graphic.md +25 -0
- package/skills/{design-direction → design-moodboard}/references/sources.md +21 -11
- package/skills/design-moodboard/scripts/capture.mjs +893 -0
- package/skills/design-moodboard/scripts/contact-sheet.mjs +259 -0
- package/skills/design-moodboard/scripts/crops.mjs +256 -0
- package/skills/design-moodboard/scripts/dribbble-cards.mjs +418 -0
- package/skills/design-moodboard/scripts/families.mjs +606 -0
- package/skills/design-moodboard/scripts/group.mjs +221 -0
- package/skills/design-moodboard/scripts/measure.mjs +1728 -0
- package/skills/design-moodboard/scripts/moodboard.mjs +467 -0
- package/skills/{design-direction → design-moodboard}/scripts/picker.mjs +121 -20
- package/skills/design-moodboard/scripts/pictures.mjs +197 -0
- package/skills/design-moodboard/scripts/tag.mjs +289 -0
- package/skills/design-prototype/SKILL.md +149 -0
- package/skills/design-prototype/references/design-md-template.md +82 -0
- package/skills/design-prototype/references/design-rules.md +203 -0
- package/skills/design-prototype/references/five-second.md +47 -0
- package/skills/design-prototype/references/graphic.md +27 -0
- package/skills/design-prototype/scripts/capture.mjs +893 -0
- package/skills/design-prototype/scripts/contrast.mjs +41 -0
- package/skills/design-prototype/scripts/links.mjs +308 -0
- package/skills/design-prototype/scripts/pictures.mjs +197 -0
- package/skills/design-prototype/scripts/rules.mjs +613 -0
- package/skills/design-prototype/scripts/screen-contrast.mjs +428 -0
- package/skills/design-prototype/scripts/sheet.mjs +67 -0
- package/skills/design-prototype/scripts/tokens.mjs +346 -0
- package/skills/design-wordmark/SKILL.md +65 -0
- package/skills/design-wordmark/scripts/capture.mjs +893 -0
- package/skills/design-wordmark/scripts/sheet.mjs +67 -0
- package/skills/framework-skills/SKILL.md +71 -0
- package/skills/idea/SKILL.md +13 -7
- package/skills/idea/references/graphic.md +64 -0
- package/skills/design/references/design-md-template.md +0 -58
- package/skills/design/scripts/contrast.mjs +0 -27
- package/skills/design-direction/scripts/dribbble-cards.mjs +0 -356
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Group a search's candidates into families before anyone picks, so the person
|
|
3
|
+
// chooses between looks first and a pool of one look shows itself. It reads
|
|
4
|
+
// each candidate's thumbnail from its URL, measures it with measure.mjs and
|
|
5
|
+
// sorts the numbers with families.mjs: the same sorter design-families uses.
|
|
6
|
+
//
|
|
7
|
+
// Nothing is kept. A thumbnail is hotlinked, never saved (sources.md, "What
|
|
8
|
+
// is saved"): each is fetched into a scratch folder outside the project, read
|
|
9
|
+
// there, and the folder is deleted when this ends, whatever the outcome. What
|
|
10
|
+
// is written is one small JSON of row ids, no picture.
|
|
11
|
+
//
|
|
12
|
+
// The TSV is the picker's: title, image, link, source, meta. A row's id is the
|
|
13
|
+
// round letter and its row number (a1, a2…), the same as the picker's, so
|
|
14
|
+
// the picker's marks and these groups name the same rows.
|
|
15
|
+
//
|
|
16
|
+
// node group.mjs .longbeard/design/moodboard/candidates.tsv --out .longbeard/design/moodboard/families.json
|
|
17
|
+
//
|
|
18
|
+
// families.json: each family's id, a `name` left empty for the agent to fill
|
|
19
|
+
// with what is seen, its size, what its members share, and its members as row
|
|
20
|
+
// ids, most typical first. The strays are one entry, `stray: true`. A row whose
|
|
21
|
+
// picture could not be read is listed under `unread` and is in no family.
|
|
22
|
+
//
|
|
23
|
+
// The floor: a pool where too few families hold real numbers gives the person
|
|
24
|
+
// nothing to choose between. A family counts when it holds at least one
|
|
25
|
+
// candidate in twenty (never fewer than three); under four that count, the
|
|
26
|
+
// floor is not met and the agent searches wider before the picker opens. It is
|
|
27
|
+
// asked of round 1 only: round 2 is sharper on purpose.
|
|
28
|
+
//
|
|
29
|
+
// --out file where families.json goes (required)
|
|
30
|
+
// --round n the picker's round, for the ids (default 1)
|
|
31
|
+
// --spread x families.mjs's spread, lower for finer families (default 0.52)
|
|
32
|
+
// --sheet file also write label<TAB>image rows in group order, for
|
|
33
|
+
// contact-sheet.mjs: the label is the id and its family
|
|
34
|
+
// --traits file skip the fetching and measuring: traits from measure.mjs
|
|
35
|
+
// --tsv, one row per picture named by its id (a1.jpg)
|
|
36
|
+
import { spawnSync } from "node:child_process";
|
|
37
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
38
|
+
import { tmpdir } from "node:os";
|
|
39
|
+
import { basename, dirname, extname, isAbsolute, join, resolve } from "node:path";
|
|
40
|
+
import { fileURLToPath } from "node:url";
|
|
41
|
+
|
|
42
|
+
export const NEED = 4;
|
|
43
|
+
export const SHARE = 0.05;
|
|
44
|
+
const MIN = 3;
|
|
45
|
+
|
|
46
|
+
// A family counts when it holds a twentieth of what was read, and at least three.
|
|
47
|
+
export function floor(families, grouped) {
|
|
48
|
+
const size = Math.max(MIN, Math.ceil(SHARE * grouped));
|
|
49
|
+
const counted = families.filter((f) => !f.stray && f.size >= size);
|
|
50
|
+
return { need: NEED, size, have: counted.length, met: counted.length >= NEED, counted: counted.map((f) => ({ id: f.id, size: f.size })) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The picker's rule for what is a row and what is its id.
|
|
54
|
+
export function rowsOf(text, letter = "a") {
|
|
55
|
+
return text
|
|
56
|
+
.split(/\r?\n/)
|
|
57
|
+
.filter((l) => l.trim() && !(l.trimStart().startsWith("#") && !l.includes("\t")))
|
|
58
|
+
.map((line, i) => {
|
|
59
|
+
const [title = "", image = "", link = "", source = "", meta = ""] = line.split("\t").map((c) => c.trim());
|
|
60
|
+
return { id: `${letter}${i + 1}`, title, image, link, source, meta };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The kind of picture, from its first bytes, as the extension measure.mjs reads.
|
|
65
|
+
export function sniff(buf) {
|
|
66
|
+
if (buf.length < 12) return "";
|
|
67
|
+
if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return ".jpg";
|
|
68
|
+
if (buf.toString("latin1", 1, 4) === "PNG") return ".png";
|
|
69
|
+
if (buf.toString("latin1", 0, 4) === "GIF8") return ".gif";
|
|
70
|
+
if (buf.toString("latin1", 0, 4) === "RIFF" && buf.toString("latin1", 8, 12) === "WEBP") return ".webp";
|
|
71
|
+
if (buf.toString("latin1", 4, 12) === "ftypavif") return ".avif";
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Families as the picker wants them: members are row ids, in the file's own order.
|
|
76
|
+
export function relabel(raw, idOf) {
|
|
77
|
+
return raw.families.map((f) => ({
|
|
78
|
+
id: f.id,
|
|
79
|
+
...(f.stray ? { stray: true } : { name: "" }),
|
|
80
|
+
size: f.size,
|
|
81
|
+
...(f.small ? { small: true } : {}),
|
|
82
|
+
shares: f.stray ? "far from every family" : [f.ranges.tone, `empty ${f.ranges.empty}`, `loud ${f.ranges.loud}`, `busy ${f.ranges.busy}`].join(" · "),
|
|
83
|
+
members: f.members.map(idOf).filter(Boolean),
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function main() {
|
|
88
|
+
const args = process.argv.slice(2);
|
|
89
|
+
const flag = (name) => {
|
|
90
|
+
const i = args.indexOf(`--${name}`);
|
|
91
|
+
return i === -1 ? "" : (args.splice(i, 2)[1] ?? "");
|
|
92
|
+
};
|
|
93
|
+
const outArg = flag("out");
|
|
94
|
+
const roundArg = flag("round") || "1";
|
|
95
|
+
const spreadArg = flag("spread");
|
|
96
|
+
const sheetArg = flag("sheet");
|
|
97
|
+
const traitsArg = flag("traits");
|
|
98
|
+
const round = Number(roundArg);
|
|
99
|
+
const [tsvArg] = args;
|
|
100
|
+
if (!tsvArg || !outArg || args.length !== 1 || !Number.isInteger(round) || round < 1 || round > 26 || (spreadArg && !(Number(spreadArg) > 0 && Number(spreadArg) < 1))) {
|
|
101
|
+
console.error("usage: node group.mjs .longbeard/design/moodboard/candidates.tsv --out .longbeard/design/moodboard/families.json [--round 1] [--spread 0.52] [--sheet sheet.tsv] [--traits traits.tsv]");
|
|
102
|
+
process.exit(2);
|
|
103
|
+
}
|
|
104
|
+
const letter = String.fromCharCode(96 + round);
|
|
105
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
106
|
+
const root = (() => {
|
|
107
|
+
const r = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf8" });
|
|
108
|
+
return r.status === 0 && r.stdout.trim() ? r.stdout.trim() : process.cwd();
|
|
109
|
+
})();
|
|
110
|
+
const at = (p) => (isAbsolute(p) ? p : resolve(root, p));
|
|
111
|
+
const fail = (text) => {
|
|
112
|
+
console.error(`group: ${text}`);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
};
|
|
115
|
+
if (!existsSync(at(tsvArg))) fail(`no candidates at ${tsvArg}`);
|
|
116
|
+
const rows = rowsOf(readFileSync(at(tsvArg), "utf8"), letter);
|
|
117
|
+
if (rows.length < 2) fail("fewer than two rows to group");
|
|
118
|
+
|
|
119
|
+
// The scratch folder is outside the project and goes whatever happens.
|
|
120
|
+
const scratch = mkdtempSync(join(tmpdir(), "longbeard-group-"));
|
|
121
|
+
const clean = () => {
|
|
122
|
+
try {
|
|
123
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
124
|
+
} catch {}
|
|
125
|
+
};
|
|
126
|
+
process.once("exit", clean);
|
|
127
|
+
for (const [sig, code] of [["SIGINT", 130], ["SIGTERM", 143]]) {
|
|
128
|
+
process.once(sig, () => {
|
|
129
|
+
clean();
|
|
130
|
+
process.exit(code);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const images = join(scratch, "images");
|
|
134
|
+
const work = join(scratch, "work");
|
|
135
|
+
mkdirSync(images);
|
|
136
|
+
mkdirSync(work);
|
|
137
|
+
|
|
138
|
+
const unread = new Map();
|
|
139
|
+
let traitsPath = traitsArg ? at(traitsArg) : join(work, "traits.tsv");
|
|
140
|
+
if (traitsArg && !existsSync(traitsPath)) fail(`no traits at ${traitsArg}`);
|
|
141
|
+
|
|
142
|
+
if (!traitsArg) {
|
|
143
|
+
// Fetch each thumbnail from its URL, a few at a time, into the scratch folder.
|
|
144
|
+
const queue = rows.filter((r) => r.image);
|
|
145
|
+
for (const r of rows) if (!r.image) unread.set(r.id, "no image");
|
|
146
|
+
const get = async (r) => {
|
|
147
|
+
try {
|
|
148
|
+
let buf;
|
|
149
|
+
if (/^https?:\/\//i.test(r.image)) {
|
|
150
|
+
const res = await fetch(r.image, { signal: AbortSignal.timeout(20000), redirect: "follow" });
|
|
151
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
152
|
+
buf = Buffer.from(await res.arrayBuffer());
|
|
153
|
+
} else {
|
|
154
|
+
const path = at(r.image);
|
|
155
|
+
if (!existsSync(path)) throw new Error("no file");
|
|
156
|
+
buf = readFileSync(path);
|
|
157
|
+
}
|
|
158
|
+
const ext = sniff(buf);
|
|
159
|
+
if (!ext) throw new Error("not a jpg, png, webp, gif or avif");
|
|
160
|
+
writeFileSync(join(images, `${r.id}${ext}`), buf);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
unread.set(r.id, error.cause?.code || error.message);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
await Promise.all(Array.from({ length: 8 }, async () => {
|
|
166
|
+
for (let r = queue.shift(); r; r = queue.shift()) await get(r);
|
|
167
|
+
}));
|
|
168
|
+
if (unread.size >= rows.length - 1) fail(`fewer than two thumbnails could be read (${[...unread].slice(0, 3).map(([id, why]) => `${id} ${why}`).join(", ")})`);
|
|
169
|
+
|
|
170
|
+
const measured = spawnSync(process.execPath, [join(here, "measure.mjs"), images, "--tsv"], { encoding: "utf8", maxBuffer: 1 << 26, timeout: 600000 });
|
|
171
|
+
// A non-zero exit says some picture was not read; the rest are still printed.
|
|
172
|
+
if (!measured.stdout.startsWith("ref\t")) fail(`measure.mjs read nothing: ${(measured.stderr || "no output").trim().split("\n").slice(-3).join(" ")}`);
|
|
173
|
+
if (measured.stderr.trim()) console.error(measured.stderr.trim());
|
|
174
|
+
writeFileSync(traitsPath, measured.stdout);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const traits = readFileSync(traitsPath, "utf8").trim().split(/\r?\n/).slice(1).map((l) => l.split("\t"));
|
|
178
|
+
const idOf = (shot) => basename(shot, extname(shot));
|
|
179
|
+
const read = new Set(traits.map((t) => idOf(t[0])));
|
|
180
|
+
for (const r of rows) if (!read.has(r.id) && !unread.has(r.id)) unread.set(r.id, "not measured");
|
|
181
|
+
|
|
182
|
+
const rawPath = join(work, "families.json");
|
|
183
|
+
const sorted = spawnSync(process.execPath, [join(here, "families.mjs"), traitsPath, "--out", rawPath, ...(spreadArg ? ["--spread", spreadArg] : [])], { encoding: "utf8", maxBuffer: 1 << 26 });
|
|
184
|
+
if (sorted.status !== 0 || !existsSync(rawPath)) fail(`families.mjs did not sort: ${(sorted.stderr || sorted.stdout).trim().split("\n").slice(-2).join(" ")}`);
|
|
185
|
+
const raw = JSON.parse(readFileSync(rawPath, "utf8"));
|
|
186
|
+
|
|
187
|
+
const families = relabel(raw, idOf);
|
|
188
|
+
const grouped = families.reduce((t, f) => t + f.members.length, 0);
|
|
189
|
+
const verdict = round === 1 ? floor(families, grouped) : null;
|
|
190
|
+
const doc = {
|
|
191
|
+
round,
|
|
192
|
+
spread: raw.spread,
|
|
193
|
+
rows: rows.length,
|
|
194
|
+
grouped,
|
|
195
|
+
...(verdict ? { floor: verdict } : {}),
|
|
196
|
+
unread: [...unread].map(([id, why]) => ({ id, why })),
|
|
197
|
+
families,
|
|
198
|
+
};
|
|
199
|
+
mkdirSync(dirname(at(outArg)), { recursive: true });
|
|
200
|
+
writeFileSync(at(outArg), `${JSON.stringify(doc, null, 2)}\n`);
|
|
201
|
+
|
|
202
|
+
if (sheetArg) {
|
|
203
|
+
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
204
|
+
const lines = families.flatMap((f) => f.members.map((id) => `${id} ${f.id}\t${byId.get(id).image}`));
|
|
205
|
+
mkdirSync(dirname(at(sheetArg)), { recursive: true });
|
|
206
|
+
writeFileSync(at(sheetArg), `${lines.join("\n")}\n`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
console.log(`group: ${grouped} of ${rows.length} rows grouped${unread.size ? `, ${unread.size} not read (${[...unread].slice(0, 4).map(([id, why]) => `${id} ${why}`).join(", ")}${unread.size > 4 ? " …" : ""})` : ""}, ${families.filter((f) => !f.stray).length} families, spread ${raw.spread}`);
|
|
210
|
+
for (const f of families) console.log(`${f.id.padEnd(7)} ${String(f.size).padStart(4)} ${f.shares}${f.small ? " [small]" : ""}`);
|
|
211
|
+
if (verdict) {
|
|
212
|
+
console.log(
|
|
213
|
+
verdict.met
|
|
214
|
+
? `floor: met, ${verdict.have} families of ${verdict.size} or more (need ${NEED})`
|
|
215
|
+
: `floor: not met, ${verdict.have} of ${NEED} families of ${verdict.size} or more${verdict.counted.length ? ` (${verdict.counted.map((f) => `${f.id} ${f.size}`).join(", ")})` : ""}. Say which looks the pool has and which it lacks, then search wider before the picker`,
|
|
216
|
+
);
|
|
217
|
+
} else console.log("floor: not asked after round 1");
|
|
218
|
+
console.log(outArg);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) await main();
|