@jonandev/longbeard 0.11.2 → 0.12.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.
Files changed (93) hide show
  1. package/AGENTS.md +3 -4
  2. package/CHANGELOG.md +67 -0
  3. package/README.md +63 -43
  4. package/beard.json +113 -26
  5. package/bin/long-beard.js +172 -36
  6. package/package.json +1 -1
  7. package/skills/design/SKILL.md +51 -126
  8. package/skills/design-brief/SKILL.md +146 -0
  9. package/skills/design-brief/references/graphic.md +59 -0
  10. package/skills/design-check/SKILL.md +27 -11
  11. package/skills/design-check/references/design-rules.md +21 -7
  12. package/skills/design-check/scripts/capture.mjs +121 -37
  13. package/skills/design-check/scripts/contrast.mjs +23 -9
  14. package/skills/design-check/scripts/rules.mjs +613 -0
  15. package/skills/design-check/scripts/screen-contrast.mjs +428 -0
  16. package/skills/design-check/scripts/tokens.mjs +346 -0
  17. package/skills/design-content/SKILL.md +118 -0
  18. package/skills/design-content/scripts/contact-sheet.mjs +259 -0
  19. package/skills/design-content/scripts/pictures.mjs +197 -0
  20. package/skills/design-direction/SKILL.md +115 -200
  21. package/skills/design-direction/references/controls.md +58 -0
  22. package/skills/{design → design-direction}/references/design-rules.md +21 -7
  23. package/skills/design-direction/references/five-second.md +47 -0
  24. package/skills/design-direction/references/full-build.md +19 -0
  25. package/skills/design-direction/references/graphic.md +35 -0
  26. package/skills/design-direction/references/grid.md +114 -0
  27. package/skills/design-direction/references/library.md +75 -0
  28. package/skills/design-direction/references/screen-template.html +233 -0
  29. package/skills/design-direction/references/subject.md +33 -0
  30. package/skills/design-direction/scripts/capture.mjs +121 -37
  31. package/skills/design-direction/scripts/contact-sheet.mjs +18 -7
  32. package/skills/design-direction/scripts/fonts.mjs +276 -0
  33. package/skills/design-direction/scripts/layout-diff.mjs +118 -0
  34. package/skills/design-direction/scripts/measure.mjs +1728 -0
  35. package/skills/design-direction/scripts/moodboard.mjs +123 -32
  36. package/skills/design-direction/scripts/picture-cast.mjs +270 -0
  37. package/skills/design-direction/scripts/pictures.mjs +197 -0
  38. package/skills/design-direction/scripts/screen-contrast.mjs +428 -0
  39. package/skills/design-direction/scripts/sheet.mjs +67 -0
  40. package/skills/design-direction/scripts/subject-colours.mjs +410 -0
  41. package/skills/design-families/SKILL.md +138 -0
  42. package/skills/design-families/scripts/contact-sheet.mjs +259 -0
  43. package/skills/design-families/scripts/families.mjs +606 -0
  44. package/skills/design-families/scripts/measure.mjs +1728 -0
  45. package/skills/design-families/scripts/moodboard.mjs +467 -0
  46. package/skills/design-families/scripts/tag.mjs +289 -0
  47. package/skills/design-figma/SKILL.md +69 -0
  48. package/skills/design-figma/references/graphic.md +26 -0
  49. package/skills/design-identity/SKILL.md +134 -0
  50. package/skills/design-identity/references/graphic.md +8 -0
  51. package/skills/design-identity/references/identity-board.html +140 -0
  52. package/skills/{design → design-identity}/scripts/capture.mjs +121 -37
  53. package/skills/design-identity/scripts/colours.mjs +213 -0
  54. package/skills/design-identity/scripts/contrast.mjs +41 -0
  55. package/skills/design-identity/scripts/fonts.mjs +276 -0
  56. package/skills/design-identity/scripts/measure.mjs +1728 -0
  57. package/skills/design-identity/scripts/sheet.mjs +67 -0
  58. package/skills/design-identity/scripts/subject-colours.mjs +410 -0
  59. package/skills/design-moodboard/SKILL.md +184 -0
  60. package/skills/design-moodboard/references/graphic.md +25 -0
  61. package/skills/{design-direction → design-moodboard}/references/sources.md +17 -11
  62. package/skills/design-moodboard/scripts/capture.mjs +893 -0
  63. package/skills/design-moodboard/scripts/contact-sheet.mjs +259 -0
  64. package/skills/design-moodboard/scripts/crops.mjs +256 -0
  65. package/skills/design-moodboard/scripts/dribbble-cards.mjs +418 -0
  66. package/skills/design-moodboard/scripts/families.mjs +606 -0
  67. package/skills/design-moodboard/scripts/group.mjs +221 -0
  68. package/skills/design-moodboard/scripts/measure.mjs +1728 -0
  69. package/skills/design-moodboard/scripts/moodboard.mjs +467 -0
  70. package/skills/{design-direction → design-moodboard}/scripts/picker.mjs +121 -20
  71. package/skills/design-moodboard/scripts/pictures.mjs +197 -0
  72. package/skills/design-moodboard/scripts/tag.mjs +289 -0
  73. package/skills/design-prototype/SKILL.md +149 -0
  74. package/skills/design-prototype/references/design-md-template.md +82 -0
  75. package/skills/design-prototype/references/design-rules.md +203 -0
  76. package/skills/design-prototype/references/five-second.md +47 -0
  77. package/skills/design-prototype/references/graphic.md +27 -0
  78. package/skills/design-prototype/scripts/capture.mjs +893 -0
  79. package/skills/design-prototype/scripts/contrast.mjs +41 -0
  80. package/skills/design-prototype/scripts/links.mjs +308 -0
  81. package/skills/design-prototype/scripts/pictures.mjs +197 -0
  82. package/skills/design-prototype/scripts/rules.mjs +613 -0
  83. package/skills/design-prototype/scripts/screen-contrast.mjs +428 -0
  84. package/skills/design-prototype/scripts/sheet.mjs +67 -0
  85. package/skills/design-prototype/scripts/tokens.mjs +346 -0
  86. package/skills/design-wordmark/SKILL.md +65 -0
  87. package/skills/design-wordmark/scripts/capture.mjs +893 -0
  88. package/skills/design-wordmark/scripts/sheet.mjs +67 -0
  89. package/skills/idea/SKILL.md +13 -7
  90. package/skills/idea/references/graphic.md +64 -0
  91. package/skills/design/references/design-md-template.md +0 -58
  92. package/skills/design/scripts/contrast.mjs +0 -27
  93. package/skills/design-direction/scripts/dribbble-cards.mjs +0 -356
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ // Lay screenshots out as one numbered sheet, so a round of first screens can
3
+ // be seen and picked from together. It writes an HTML page; capture.mjs turns
4
+ // that into the picture to show. No dependencies.
5
+ //
6
+ // node sheet.mjs .longbeard/design/direction/grid/sheet.html .longbeard/design/direction/grid/1.png .longbeard/design/direction/grid/2.png …
7
+ // node sheet.mjs .longbeard/design/direction/grid/vary.html --cols 5 .longbeard/design/direction/grid/v*.png
8
+ // node capture.mjs "file://$PWD/.longbeard/design/direction/grid/sheet.html" --out .longbeard/design/direction/grid/sheet.png
9
+ // node sheet.mjs <out.html> --rough 1,2,4 --note "built without fresh agents: weaker" <shots…>
10
+ //
11
+ // --rough 1,2,4 (or none) labels those tiles "rough" and the rest "full", so a quick screen is never
12
+ // read as a finished one. --note prints a line under the sheet.
13
+
14
+ // Tiles are numbered in the order given, left to right, top to bottom, which
15
+ // is the recipe's number when the shots are passed in order.
16
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
17
+ import { dirname, relative, resolve } from "node:path";
18
+
19
+ const args = process.argv.slice(2);
20
+ const at = args.indexOf("--cols");
21
+ const cols = at === -1 ? 2 : Number(args.splice(at, 2)[1]);
22
+ const take = (name) => {
23
+ const i = args.indexOf(name);
24
+ return i === -1 ? null : (args.splice(i, 2)[1] ?? "");
25
+ };
26
+ const roughArg = take("--rough");
27
+ const note = take("--note");
28
+ const rough = new Set((roughArg ?? "").split(",").filter((n) => n && n !== "none").map(Number));
29
+ const [outArg, ...shots] = args;
30
+ if (!outArg || [...rough].some((n) => !Number.isInteger(n) || n < 1) || roughArg === "" || note === "" || !/\.html$/.test(outArg) || !shots.length || !Number.isInteger(cols) || cols < 1 || cols > 8) {
31
+ console.error('usage: node sheet.mjs <out.html> [--cols 2] [--rough 1,2|none] [--note "text"] <shot.png> …');
32
+ process.exit(2);
33
+ }
34
+ const out = resolve(outArg);
35
+ for (const shot of shots) {
36
+ if (!existsSync(resolve(shot))) {
37
+ console.error(`sheet: no file at ${shot}`);
38
+ process.exit(1);
39
+ }
40
+ }
41
+ const escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
42
+ // A local path in a src: each part encoded, so # ? % and spaces stay in the name.
43
+ const urlPath = (path) => path.split("/").map(encodeURIComponent).join("/");
44
+ const tiles = shots
45
+ .map((shot, i) => `<figure><img src="${escape(urlPath(relative(dirname(out), resolve(shot)).split("\\").join("/")))}" alt="Screen ${i + 1}"><figcaption>${i + 1}${roughArg === null ? "" : rough.has(i + 1) ? " · rough" : " · full"}</figcaption></figure>`)
46
+ .join("\n");
47
+ mkdirSync(dirname(out), { recursive: true });
48
+ writeFileSync(
49
+ out,
50
+ `<!doctype html>
51
+ <meta charset="utf-8">
52
+ <title>Sheet</title>
53
+ <style>
54
+ body { margin: 0; padding: 24px; background: #6f6f6f; font: 600 22px/1 system-ui, sans-serif; }
55
+ main { display: grid; grid-template-columns: repeat(${cols}, 720px); gap: 24px; width: max-content; }
56
+ figure { margin: 0; display: flex; flex-direction: column-reverse; gap: 8px; }
57
+ img { display: block; width: 720px; height: auto; }
58
+ /* The number sits above the screen, never on it: a corner of a screen is where its name or menu is. */
59
+ p { margin: 24px 0 0; max-width: 1200px; font-weight: 400; font-size: 20px; line-height: 1.4; color: #fff; }
60
+ figcaption { align-self: flex-start; min-width: 44px; padding: 8px 10px; text-align: center; background: #111; color: #fff; }
61
+ </style>
62
+ <main>
63
+ ${tiles}
64
+ </main>
65
+ ${note ? `<p>${escape(note)}</p>\n` : ""}`,
66
+ );
67
+ console.log(`${shots.length} screens, ${cols} across: ${outArg}`);
@@ -0,0 +1,410 @@
1
+ #!/usr/bin/env node
2
+ // Colour proposals from the product's subject pictures: three or four photos
3
+ // of what the product is about (loaves, for a bakery). The pictures' raw
4
+ // colours are greys, shadows and backgrounds, so they are never used as
5
+ // found: each role is taken from the right colour and tuned by rule.
6
+ // Node 22+, an installed Chrome (measure.mjs reads the pictures). No
7
+ // dependencies.
8
+ //
9
+ // node subject-colours.mjs .longbeard/design/subject
10
+ // node subject-colours.mjs a.jpg b.jpg c.jpg --json
11
+ // node subject-colours.mjs .longbeard/design/subject --sheet subject.html
12
+ // node subject-colours.mjs --from swatches.json --exclude "#806c71"
13
+ // node subject-colours.mjs .longbeard/design/subject --level AAA
14
+ //
15
+ // measure.mjs --swatches gives each picture's ten colours. They are pooled
16
+ // across pictures, near-twins merged, and noise dropped: under 2%, specular
17
+ // highlights, and black shadows (kept only to give a dark ground).
18
+ //
19
+ // A colour that lies mostly at the pictures' edges is the backdrop, not the
20
+ // subject (a blue wall, a striped cloth): edge over 0.55, or over 0.4 in one
21
+ // picture only. It is marked background and is never the signature or the
22
+ // accent. A colour found in two or more pictures is preferred to one in one.
23
+ // --exclude "#hex,#hex" drops colours near those (OKLab 0.06), for one you saw
24
+ // is not the subject: run again without it.
25
+ //
26
+ // - Signature: the heaviest colour with some chroma (the crust).
27
+ // - Light ground: the heaviest light colour, else the signature's hue, made an
28
+ // off-white that keeps its hue. Dark ground: the same, made a near-black.
29
+ // --level AA|AAA is the design brief's accessibility. AA asks 4.5:1 for text
30
+ // and 3:1 for an accent; AAA asks 7:1 and 4.5:1 (an accent may carry large
31
+ // text). Below, "4.5:1" and "3:1" are those two, at AA.
32
+ //
33
+ // - Ink: the other ground's hue, dark on light and light on dark, 4.5:1 or
34
+ // darker (lighter) until it is.
35
+ // - Accent: the most colourful heavy colour whose hue stands off the ground,
36
+ // else the signature; chroma raised, lightness 0.55 to 0.72, 3:1 on its
37
+ // ground or left out (and said).
38
+ // - Signature ground: the signature at lightness 0.5 to 0.62 where one of the
39
+ // two inks reads on it, or left out (and said).
40
+ //
41
+ // Prints three proposals (light, dark, signature) as a table: role, colour,
42
+ // the colour it came from (its share, in how many pictures), how it was tuned,
43
+ // its contrast. --json prints { signature, colours, proposals, library, notes }:
44
+ // colours are the pooled colours that survived the noise rules, and library
45
+ // holds one or two grounds ({ id, ground, ink, from: ["subject"] }), the
46
+ // subject's palette for library.json, and an accent only when the subject has a second hue of its own
47
+ // (a one-hue accent stays in the proposals, for design-identity to offer).
48
+ // The light ground is a quiet tint. The second may be the signature at full
49
+ // strength: a screen borrows it as a ground only when a reference has a ground
50
+ // that strong, and as an accent otherwise, so the subject's colours never push
51
+ // a board somewhere it is not.
52
+ //
53
+ // --sheet out.html writes a page: each proposal's colours as large swatches,
54
+ // and beside each, every picture with the pixels near its source colour lit
55
+ // and the rest dimmed, so the eye can check each colour is the subject.
56
+ // The pictures are written into the page (a browser will not let a page read
57
+ // the pixels of a file:// picture), so the page is about as large as they are.
58
+ import { spawnSync } from "node:child_process";
59
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
60
+ import { dirname, extname, join, resolve } from "node:path";
61
+ import { fileURLToPath, pathToFileURL } from "node:url";
62
+
63
+ const fail = (text) => {
64
+ console.error(`subject-colours: ${text}`);
65
+ process.exit(2);
66
+ };
67
+ const usage = 'usage: node subject-colours.mjs <folder | image …> | --from swatches.json [--json] [--level AA|AAA] [--exclude "#hex,#hex"] [--sheet out.html]';
68
+ const args = process.argv.slice(2);
69
+ const option = (name) => {
70
+ const i = args.indexOf(`--${name}`);
71
+ if (i === -1) return null;
72
+ const value = args[i + 1];
73
+ if (!value || value.startsWith("--")) fail(`--${name} needs a value\n${usage}`);
74
+ args.splice(i, 2);
75
+ return value;
76
+ };
77
+ const json = args.includes("--json");
78
+ if (json) args.splice(args.indexOf("--json"), 1);
79
+ const fromArg = option("from");
80
+ const excludeArg = option("exclude");
81
+ const sheetArg = option("sheet");
82
+ const level = (option("level") || "AA").toUpperCase();
83
+ if (level !== "AA" && level !== "AAA") fail(`--level is AA or AAA, not ${level}`);
84
+ const textNeed = level === "AAA" ? 7 : 4.5;
85
+ const accentNeed = level === "AAA" ? 4.5 : 3;
86
+ if (args.some((a) => a.startsWith("--")) || (fromArg ? args.length : !args.length)) fail(usage);
87
+ const hex6 = (v) => {
88
+ const s = String(v || "").trim().toLowerCase();
89
+ if (/^#[0-9a-f]{3}$/.test(s)) return `#${[...s.slice(1)].map((c) => c + c).join("")}`;
90
+ return /^#[0-9a-f]{6}$/.test(s) ? s : null;
91
+ };
92
+ const excluded = excludeArg ? excludeArg.split(",").map((v) => hex6(v) || fail(`--exclude takes hex colours, not ${v.trim()}`)) : [];
93
+
94
+ let measured;
95
+ let base = process.cwd();
96
+ if (fromArg) {
97
+ if (!existsSync(fromArg)) fail(`no file at ${fromArg}`);
98
+ try {
99
+ measured = JSON.parse(readFileSync(fromArg, "utf8"));
100
+ } catch {
101
+ fail(`${fromArg} is not JSON`);
102
+ }
103
+ base = dirname(resolve(fromArg));
104
+ } else {
105
+ // measure.mjs is copied beside this script.
106
+ const measure = join(dirname(fileURLToPath(import.meta.url)), "measure.mjs");
107
+ const run = spawnSync(process.execPath, [measure, ...args, "--swatches"], { encoding: "utf8", maxBuffer: 64 << 20 });
108
+ if (run.stderr) process.stderr.write(run.stderr);
109
+ if (!run.stdout.trim()) process.exit(run.status || 1);
110
+ measured = JSON.parse(run.stdout);
111
+ }
112
+ if (!Array.isArray(measured)) fail("swatches JSON must be a list of { target, swatches }");
113
+ const pictures = measured.filter((m) => Array.isArray(m?.swatches) && m.swatches.length);
114
+ if (!pictures.length) fail("no picture had any swatches");
115
+
116
+ // sRGB, OKLab and OKLCH, both ways. Out of gamut, chroma is reduced until the colour fits.
117
+ const toLin = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
118
+ const toGam = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
119
+ const rgbOf = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255);
120
+ function labOf(hex) {
121
+ const [r, g, b] = rgbOf(hex).map(toLin);
122
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
123
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
124
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
125
+ return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
126
+ }
127
+ function linOfLab([L, a, b]) {
128
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
129
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
130
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
131
+ return [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
132
+ }
133
+ const lchOfLab = ([L, a, b]) => ({ L, C: Math.hypot(a, b), h: ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360 });
134
+ const labOfLch = ({ L, C, h }) => [L, C * Math.cos((h * Math.PI) / 180), C * Math.sin((h * Math.PI) / 180)];
135
+ const inGamut = (lin) => lin.every((c) => c >= -0.0001 && c <= 1.0001);
136
+ // The colour at this lightness and hue with as much of the chroma asked for as sRGB holds.
137
+ function fit({ L, C, h }) {
138
+ L = Math.min(1, Math.max(0, L));
139
+ if (!inGamut(linOfLab(labOfLch({ L, C, h })))) {
140
+ let lo = 0, hi = C;
141
+ for (let i = 0; i < 24; i++) {
142
+ const mid = (lo + hi) / 2;
143
+ if (inGamut(linOfLab(labOfLch({ L, C: mid, h })))) lo = mid;
144
+ else hi = mid;
145
+ }
146
+ C = lo;
147
+ }
148
+ return { L, C, h };
149
+ }
150
+ const hexOf = (lch) => `#${linOfLab(labOfLch(fit(lch))).map((c) => Math.round(Math.min(1, Math.max(0, toGam(Math.min(1, Math.max(0, c))))) * 255).toString(16).padStart(2, "0")).join("")}`;
151
+ const lumOf = (hex) => {
152
+ const [r, g, b] = rgbOf(hex).map(toLin);
153
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
154
+ };
155
+ const contrast = (x, y) => {
156
+ const [a, b] = [lumOf(x), lumOf(y)].sort((p, q) => q - p);
157
+ return (a + 0.05) / (b + 0.05);
158
+ };
159
+ const distance = (p, q) => Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]);
160
+ const hueGap = (a, b) => Math.abs(((a - b + 540) % 360) - 180);
161
+ const r2 = (v) => Math.round(v * 100) / 100;
162
+ const r3 = (v) => Math.round(v * 1000) / 1000;
163
+ // A contrast is cut, not rounded, so one just under its need never prints as the need.
164
+ const cut2 = (v) => Math.floor(v * 100) / 100;
165
+
166
+ // Pool every picture's swatches, each share counted as a share of all the pictures.
167
+ const pooled = [];
168
+ pictures.forEach((p, n) => {
169
+ for (const s of p.swatches) if (hex6(s.hex) && s.share > 0) pooled.push({ lab: labOf(hex6(s.hex)), share: s.share / pictures.length, edge: Number.isFinite(s.edge) ? s.edge : 0, by: { [n]: s.share } });
170
+ });
171
+ pooled.sort((a, b) => b.share - a.share);
172
+ // Near-twins (OKLab distance under 0.05) are one colour, averaged by share.
173
+ const clusters = [];
174
+ for (const p of pooled) {
175
+ const twin = clusters.find((c) => distance(c.lab, p.lab) < 0.05);
176
+ if (!twin) {
177
+ clusters.push({ ...p, lab: [...p.lab], by: { ...p.by } });
178
+ continue;
179
+ }
180
+ const w = twin.share + p.share;
181
+ twin.lab = twin.lab.map((v, i) => (v * twin.share + p.lab[i] * p.share) / w);
182
+ twin.edge = (twin.edge * twin.share + p.edge * p.share) / w;
183
+ twin.share = w;
184
+ for (const [n, s] of Object.entries(p.by)) twin.by[n] = (twin.by[n] || 0) + s;
185
+ }
186
+ for (const c of clusters) {
187
+ Object.assign(c, lchOfLab(c.lab), { hex: hexOf(lchOfLab(c.lab)) });
188
+ c.pictures = Object.values(c.by).filter((s) => s >= 2).length;
189
+ // A backdrop: mostly at the edges, or at the edges of the one picture it is in.
190
+ c.background = c.edge > 0.55 || (c.pictures <= 1 && c.edge > 0.4);
191
+ }
192
+ clusters.sort((a, b) => b.share - a.share);
193
+ const notes = [];
194
+ const out = clusters.filter((c) => excluded.some((x) => distance(labOf(x), c.lab) < 0.06));
195
+ if (excluded.length) notes.push(`excluded: ${out.length ? out.map((c) => c.hex).join(", ") : "nothing was near those colours"}`);
196
+ const counted = clusters.filter((c) => c.share >= 2 && c.L <= 0.97 && !out.includes(c));
197
+ const kept = counted.filter((c) => c.L >= 0.12);
198
+ const dropped = clusters.length - out.length - kept.length;
199
+ if (dropped) notes.push(`${dropped} of ${clusters.length} colours dropped as noise, highlights or black shadow`);
200
+ const backdrop = kept.filter((c) => c.background);
201
+ if (backdrop.length) notes.push(`background, never the signature or accent: ${backdrop.map((c) => c.hex).join(", ")}`);
202
+ if (!kept.length) fail("every colour was noise: try other pictures");
203
+ const subject = kept.filter((c) => !c.background);
204
+ // Colours found in two or more pictures first, each group heaviest first.
205
+ const preferred = (list) => [...list.filter((c) => c.pictures >= 2), ...list.filter((c) => c.pictures < 2)];
206
+
207
+ const from = (c) => ({ hex: c.hex, share: r2(c.share), pictures: c.pictures, edge: r2(c.edge), ...(c.background ? { background: true } : {}) });
208
+ const colour = (role, lch, source, tuned) => ({ role, hex: hexOf(lch), ...fit(lch), from: source ? from(source) : null, tuned });
209
+
210
+ let signature = preferred(subject).find((c) => c.C >= 0.05);
211
+ if (!signature) {
212
+ signature = preferred(subject)[0] || kept[0];
213
+ notes.push(subject.length ? "no subject colour has much chroma: the signature is the heaviest, grey as it is" : "every colour looks like background: the signature is the heaviest of them");
214
+ }
215
+ // A ground keeps its source's hue. A near-grey source (chroma under 0.02: a wall, a table) has no
216
+ // hue worth keeping, so it takes the signature's, and the ground reads as the subject's off-white.
217
+ // A background colour seeds a ground only when no subject colour can.
218
+ function ground(test, list, L, maxC, word) {
219
+ const source = preferred(list.filter((c) => !c.background)).find(test) || (subject.length ? null : list.find(test));
220
+ const own = source && source.C >= 0.02;
221
+ const h = own ? source.h : signature.h;
222
+ const C = own ? Math.min(source.C, maxC) : Math.min(signature.C, maxC, 0.015);
223
+ const said = source ? `${word}${source.background ? " from a background colour" : ""}, ${own ? "its hue kept" : "the signature's hue added"}${own && source.C > maxC ? ", chroma lowered" : ""}` : `the signature's hue ${word}`;
224
+ return colour("ground", { L, C, h }, source || signature, said);
225
+ }
226
+ const light = ground((c) => c.L >= 0.82, kept, 0.96, 0.02, "made an off-white");
227
+ const dark = ground((c) => c.L <= 0.35, counted, 0.17, 0.03, "made a near-black");
228
+
229
+ // Ink in the other ground's hue, moved darker (on light) or lighter (on dark) until it reads at the text level.
230
+ function ink(on, hueOf, startL, step) {
231
+ const C = Math.min(hueOf.C, step < 0 ? 0.03 : 0.02);
232
+ let L = startL;
233
+ while (contrast(hexOf({ L, C, h: hueOf.h }), on.hex) < textNeed && L > 0 && L < 1) L = Math.min(1, Math.max(0, L + step));
234
+ const moved = Math.abs(L - startL) > 0.001;
235
+ return colour("ink", { L, C, h: hueOf.h }, null, `the ${step < 0 ? "dark" : "light"} ground's hue at L ${r2(L)}${moved ? `, ${step < 0 ? "darkened" : "lightened"} to read ${textNeed}:1` : ""}`);
236
+ }
237
+ const darkInk = (on) => ink(on, dark, 0.2, -0.01);
238
+ const lightInk = (on) => ink(on, light, 0.95, 0.01);
239
+
240
+ // The accent: colourful, heavy, a hue apart from the ground, never background; chroma raised, at the accent level on the ground.
241
+ function accent(on, label) {
242
+ const score = (c) => c.C * Math.sqrt(c.share);
243
+ const fits = subject.filter((c) => c.C >= 0.08 && hueGap(c.h, on.h) >= 25);
244
+ const pick = [...fits.filter((c) => c.pictures >= 2).sort((a, b) => score(b) - score(a)), ...fits.filter((c) => c.pictures < 2).sort((a, b) => score(b) - score(a))][0];
245
+ const source = pick || signature;
246
+ const C = Math.max(source.C, 0.13);
247
+ const start = Math.min(0.72, Math.max(0.55, source.L));
248
+ const ok = (L) => contrast(hexOf({ L, C, h: source.h }), on.hex) >= accentNeed;
249
+ let L = null;
250
+ for (let d = 0; d <= 0.17 + 1e-9 && L === null; d += 0.005) for (const x of [start - d, start + d]) if (L === null && x >= 0.55 - 1e-9 && x <= 0.72 + 1e-9 && ok(x)) L = x;
251
+ if (L === null) {
252
+ notes.push(`${label}: no accent reaches ${accentNeed}:1 on this ground at lightness 0.55 to 0.72, so it has none`);
253
+ return null;
254
+ }
255
+ const how = [];
256
+ if (!pick) how.push("the signature (no subject colour stands off the ground's hue)");
257
+ if (C > source.C + 0.001) how.push("chroma raised to read as an accent");
258
+ if (Math.abs(L - start) > 0.001) how.push(`${L > start ? "lightened" : "darkened"} to reach ${accentNeed}:1 on the ground`);
259
+ else if (Math.abs(L - source.L) > 0.01) how.push(`${L > source.L ? "lightened" : "darkened"} into the accent range`);
260
+ const made = colour("accent", { L, C, h: source.h }, source, how.join(", ") || "as found");
261
+ // An accent of the ground's own hue makes a one-hue palette: fine to offer, but not a second colour.
262
+ made.ownHue = !pick;
263
+ return made;
264
+ }
265
+
266
+ const proposal = (name, g, i) => {
267
+ const a = accent(g, name);
268
+ const rows = [g, i, ...(a ? [a] : [])];
269
+ for (const r of rows) if (r.role !== "ground") r.contrast = cut2(contrast(r.hex, g.hex));
270
+ return { name, ground: g.hex, ink: i.hex, accent: a?.hex || null, ownHue: a ? a.ownHue : null, colours: rows };
271
+ };
272
+ const proposals = [proposal("light", light, darkInk(light)), proposal("dark", dark, lightInk(dark))];
273
+
274
+ // The signature itself as a ground, at a lightness where one of the inks reads.
275
+ {
276
+ const own = Math.min(0.62, Math.max(0.5, signature.L));
277
+ let best = null;
278
+ for (let d = 0; d <= 0.12 + 1e-9 && !best; d += 0.005) {
279
+ for (const L of [own - d, own + d]) {
280
+ if (best || L < 0.5 - 1e-9 || L > 0.62 + 1e-9) continue;
281
+ const g = colour("ground", { L, C: signature.C, h: signature.h }, signature, "");
282
+ const inks = [darkInk(light), lightInk(dark)].filter((i) => contrast(i.hex, g.hex) >= textNeed);
283
+ if (inks.length) best = { g, i: inks.sort((x, y) => contrast(y.hex, g.hex) - contrast(x.hex, g.hex))[0], L };
284
+ }
285
+ }
286
+ if (!best) notes.push("signature: neither ink reaches ${textNeed}:1 on the signature at lightness 0.5 to 0.62, so there is no signature ground");
287
+ else {
288
+ const { g, i, L } = best;
289
+ g.tuned = Math.abs(L - signature.L) <= 0.01 ? "as found" : `${L > signature.L ? "lightened" : "darkened"} to carry ${i.L > 0.5 ? "light" : "dark"} text`;
290
+ i.tuned = `the ${i.L > 0.5 ? "dark" : "light"} proposal's ink`;
291
+ proposals.push(proposal("signature", g, i));
292
+ }
293
+ }
294
+
295
+ // One or two grounds and an accent for the library: the light one, and the signature (else the dark).
296
+ const second = proposals.find((p) => p.name === "signature") || proposals.find((p) => p.name === "dark");
297
+ const grounds = [proposals[0], second].map((p) => ({ id: `subject-${p.name}`, ground: p.ground, panel: null, ink: p.ink, gradient: null, pattern: null, from: ["subject"] }));
298
+ // The library takes an accent only when the subject has a second hue of its own. One that is the
299
+ // signature with more chroma would make every subject screen one hue: then accents come from the
300
+ // references, and the one-hue palettes stay in the proposals for design-identity to offer.
301
+ const acc = proposals.find((p) => p.accent && !p.ownHue);
302
+ if (!acc && proposals.some((p) => p.accent)) notes.push("no second hue in the subject: the library takes no subject accent, so accents come from the references; the one-hue palettes are still proposed");
303
+ const library = { grounds, accents: acc ? [{ id: "subject-accent", colour: acc.accent, device: "the subject's own colour", from: ["subject"] }] : [] };
304
+
305
+ if (sheetArg) writeSheet(sheetArg);
306
+ if (json) {
307
+ const clean = (c) => ({ role: c.role, hex: c.hex, L: r3(c.L), C: r3(c.C), h: Math.round(c.h), from: c.from, tuned: c.tuned, ...(c.contrast ? { contrast: c.contrast } : {}) });
308
+ const listed = kept.map((c) => ({ ...from(c), L: r3(c.L), C: r3(c.C), h: Math.round(c.h), background: c.background }));
309
+ console.log(JSON.stringify({ level, signature: from(signature), colours: listed, proposals: proposals.map((p) => ({ ...p, colours: p.colours.map(clean) })), library, notes }, null, 1));
310
+ } else {
311
+ const source = (f) => (f ? `${f.hex} ${f.share}%, ${f.pictures} of ${pictures.length}${f.background ? ", background" : ""}` : "");
312
+ const rows = [["proposal", "role", "colour", "from (share, pictures)", "how", "contrast"]];
313
+ for (const p of proposals) for (const c of p.colours) rows.push([p.name, c.role, c.hex, source(c.from), c.tuned, c.contrast ? `${c.contrast}:1` : ""]);
314
+ const widths = rows[0].map((_, i) => Math.max(...rows.map((r) => r[i].length)));
315
+ console.log(`signature: ${signature.hex} (${r2(signature.share)}% of the pictures, in ${signature.pictures} of ${pictures.length})`);
316
+ for (const r of rows) console.log(r.map((v, i) => v.padEnd(widths[i])).join(" ").trimEnd());
317
+ for (const n of notes) console.log(`note: ${n}`);
318
+ if (sheetArg) console.log(`sheet: ${sheetArg}`);
319
+ }
320
+
321
+ // The sheet: each colour, and where its source lives in every picture, worked out in the page.
322
+ function writeSheet(path) {
323
+ const pics = pictures.map((p) => {
324
+ const at = [resolve(p.target), resolve(base, p.target)].find((x) => existsSync(x)) || resolve(p.target);
325
+ const type = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp", ".gif": "image/gif", ".avif": "image/avif" }[extname(at).toLowerCase()];
326
+ const url = existsSync(at) && type ? `data:${type};base64,${readFileSync(at).toString("base64")}` : pathToFileURL(at).href;
327
+ return { name: at.split(/[\\/]/).pop(), url };
328
+ });
329
+ const data = { pictures: pics, proposals: proposals.map((p) => ({ name: p.name, colours: p.colours.map((c) => ({ role: c.role, hex: c.hex, from: c.from, tuned: c.tuned, contrast: c.contrast || null })) })), notes, signature: from(signature) };
330
+ const esc = (s) => JSON.stringify(s).replace(/</g, "\\u003c");
331
+ writeFileSync(
332
+ path,
333
+ `<!doctype html>
334
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
335
+ <title>Subject colours</title>
336
+ <style>
337
+ :root { --bg: #f6f5f2; --fg: #1d1c1a; --soft: #6b6862; --line: #dcd9d2; }
338
+ body { margin: 0; padding: 24px 16px; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, sans-serif; }
339
+ h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 32px 0 8px; text-transform: capitalize; }
340
+ .note { color: var(--soft); margin: 2px 0; }
341
+ .row { display: grid; grid-template-columns: 220px 1fr; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); align-items: start; }
342
+ .chip { height: 120px; border-radius: 6px; border: 1px solid var(--line); display: flex; align-items: end; padding: 8px; box-sizing: border-box; font-weight: 600; }
343
+ .meta { margin-top: 6px; } .meta span { display: block; color: var(--soft); }
344
+ .from { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -2px; border: 1px solid var(--line); }
345
+ .pics { display: flex; flex-wrap: wrap; gap: 8px; } canvas { height: 150px; width: auto; border-radius: 4px; background: #000; }
346
+ @media (max-width: 600px) { .row { grid-template-columns: 1fr; } canvas { height: 100px; } }
347
+ </style></head><body>
348
+ <h1>Subject colours</h1>
349
+ <p class="note">Lit: the pixels near each colour's source (OKLab distance under 0.08). Dimmed: the rest. A source lit mostly outside the subject is background: run again with --exclude.</p>
350
+ <div id="notes"></div><div id="out"></div>
351
+ <script>
352
+ const DATA = ${esc(data)};
353
+ const lin = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
354
+ const LIN = Array.from({ length: 256 }, (_, i) => lin(i / 255));
355
+ function lab(r, g, b) {
356
+ r = LIN[r]; g = LIN[g]; b = LIN[b];
357
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b), m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b), s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
358
+ return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
359
+ }
360
+ const hexLab = (h) => lab(...[1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)));
361
+ const el = (tag, props = {}, ...kids) => { const e = Object.assign(document.createElement(tag), props); e.append(...kids); return e; };
362
+ for (const n of DATA.notes) document.getElementById("notes").append(el("p", { className: "note", textContent: "Note: " + n }));
363
+ const images = DATA.pictures.map((p) => new Promise((done) => { const img = new Image(); img.onload = () => done(img); img.onerror = () => done(null); img.src = p.url; }));
364
+ Promise.all(images).then((imgs) => {
365
+ const pixels = imgs.map((img) => {
366
+ if (!img) return null;
367
+ const k = Math.min(1, 320 / Math.max(img.naturalWidth, img.naturalHeight));
368
+ const w = Math.round(img.naturalWidth * k), h = Math.round(img.naturalHeight * k);
369
+ const c = Object.assign(document.createElement("canvas"), { width: w, height: h }).getContext("2d");
370
+ c.drawImage(img, 0, 0, w, h);
371
+ try { const d = c.getImageData(0, 0, w, h); const L = new Float32Array(w * h * 3); for (let i = 0, j = 0; i < d.data.length; i += 4, j += 3) L.set(lab(d.data[i], d.data[i + 1], d.data[i + 2]), j); return { w, h, d, L }; }
372
+ catch { return { w, h, img, blocked: true }; }
373
+ });
374
+ const out = document.getElementById("out");
375
+ for (const p of DATA.proposals) {
376
+ out.append(el("h2", { textContent: p.name }));
377
+ const ground = p.colours.find((c) => c.role === "ground");
378
+ for (const c of p.colours) {
379
+ const chip = el("div", { className: "chip", textContent: c.role + " " + c.hex });
380
+ chip.style.background = c.hex;
381
+ chip.style.color = c.role === "ground" ? p.colours.find((x) => x.role === "ink").hex : ground.hex;
382
+ const f = c.from;
383
+ const fromLine = f ? el("span", {}, el("i", { className: "from", style: "background:" + f.hex }), " from " + f.hex + ", " + f.share + "% in " + f.pictures + " of " + DATA.pictures.length + (f.background ? ", background" : "") + ", edge " + f.edge) : el("span", { textContent: "derived, no source colour" });
384
+ const meta = el("div", { className: "meta" }, fromLine, el("span", { textContent: c.tuned + (c.contrast ? " · " + c.contrast + ":1" : "") }));
385
+ const pics = el("div", { className: "pics" });
386
+ if (f) {
387
+ const target = hexLab(f.hex);
388
+ pixels.forEach((px, n) => {
389
+ if (!px) { pics.append(el("span", { className: "note", textContent: DATA.pictures[n].name + ": not found" })); return; }
390
+ const cv = el("canvas", { width: px.w, height: px.h, title: DATA.pictures[n].name });
391
+ const ctx = cv.getContext("2d");
392
+ if (px.blocked) { ctx.drawImage(px.img, 0, 0, px.w, px.h); pics.append(cv, el("span", { className: "note", textContent: "the browser will not let this page read the picture's pixels" })); return; }
393
+ const o = new ImageData(new Uint8ClampedArray(px.d.data), px.w, px.h);
394
+ for (let i = 0, j = 0; i < o.data.length; i += 4, j += 3) {
395
+ const dist = Math.hypot(px.L[j] - target[0], px.L[j + 1] - target[1], px.L[j + 2] - target[2]);
396
+ if (dist >= 0.08) { const g = 0.3 * o.data[i] + 0.59 * o.data[i + 1] + 0.11 * o.data[i + 2]; o.data[i] = o.data[i + 1] = o.data[i + 2] = 20 + g * 0.18; }
397
+ }
398
+ ctx.putImageData(o, 0, 0);
399
+ pics.append(cv);
400
+ });
401
+ }
402
+ out.append(el("div", { className: "row" }, el("div", {}, chip, meta), pics));
403
+ }
404
+ }
405
+ document.body.dataset.ready = "1";
406
+ });
407
+ </script></body></html>
408
+ `,
409
+ );
410
+ }
@@ -0,0 +1,138 @@
1
+ ---
2
+ name: design-families
3
+ description: >
4
+ Optional. Sort a big or messy moodboard (a large Figma board, a folder, a
5
+ wide search) into families: groups of references that look alike from across
6
+ a room. Every reference is measured and tagged, sorted by script, checked by
7
+ eye, and named for what is seen. They take one or two families, and those
8
+ become the references the next skills work from. Call it by hand, or when
9
+ design or design-moodboard offers it for a board over about 60 references.
10
+ Never worth it for a board someone already curated to a few dozen.
11
+ ---
12
+
13
+ # Design families
14
+
15
+ **Needs:** `docs/design/design-moodboard.md`
16
+ **Uses if there:** `docs/design/design-brief.md`
17
+ **Writes:** `docs/design/design-families.md`
18
+
19
+ One job: sort a board into looks so choosing is easy. It reads and sorts the board; it builds no screens.
20
+
21
+ Comes out:
22
+
23
+ - **`docs/design/design-families.md`**, committed: each family named, what it shares, how big it is, and which they took.
24
+ - **In Figma**, for a Figma board: a new page, `Families`, with one section per family holding copies of its cards. Their own pages are never moved or changed.
25
+ - **`.longbeard/design/families/`**, gitignored: `profiles.json`, `tags.tsv`, one TSV per family, the families page.
26
+
27
+ ## Gate
28
+
29
+ 1. No board → `design-moodboard` first, or they give one now (a Figma link, a folder, a list of links).
30
+ 2. Under about 60 references → say a board this size is easier to choose from as it is, and stop unless they insist.
31
+ 3. A Figma board of hundreds → ask once, "The whole file, or one page or section?", and offer to read only cards their own tags mark as screens. Reading and tagging 1,300 cards cost about 800K tokens.
32
+
33
+ A board `design-moodboard` already read has its captures in `.longbeard/design/moodboard/refs/` and `board.md`. Otherwise run `design-moodboard` on it first: it reads the board (Figma originals, crops from shared sheets, captures for links) and keeps every card, with no picker.
34
+
35
+ ## 1. Measure, in one browser run
36
+
37
+ `links.tsv` (`name<TAB>link`) for the keeps with a live page, then:
38
+
39
+ ```
40
+ node <skill>/scripts/measure.mjs .longbeard/design/moodboard/refs --links .longbeard/design/families/links.tsv --profiles .longbeard/design/families/profiles.json --jobs 6
41
+ ```
42
+
43
+ From each picture: how light, how empty, how loud, how busy, its colours, and where things sit on a 6×4 grid. From a live page: the largest type and where it sits, what the screen is made of, its fonts, gradients and patterns. A screen on a presentation surround is measured inside the surround. Never one call per image, and never read the profiles into the chat.
44
+
45
+ ## 2. Tag what numbers cannot see
46
+
47
+ ```
48
+ node <skill>/scripts/tag.mjs .longbeard/design/families/profiles.json --sheets <scratch>/tag
49
+ node <skill>/scripts/tag.mjs .longbeard/design/families/profiles.json .longbeard/design/families/tags.tsv
50
+ ```
51
+
52
+ The first makes sheets of 16 untagged keeps and prints the vocabulary, one vocabulary in two layers:
53
+
54
+ - **The look**, sorted on, stored in `tags`: picture, photo, type, weight, layout, colour, surface, scale, and `motion` (none, kinetic, blur-grain, ui, repetition) for gifs, videos and live pages.
55
+ - **What it is and is for**, stored in `about`, checked but never sorted on: format, domain, mood, hue, density, and `shows` (portrait, close-crop, landscape, still-life, classical-art, cutout, type-only), what the picture shows. It is what a brief and a search pick references by.
56
+
57
+ Write a header row naming the columns (`name<TAB>picture<TAB>…<TAB>scale<TAB>motion<TAB>format<TAB>domain<TAB>mood<TAB>hue<TAB>density<TAB>note`, any order), then one row per keep from the sheets. The eight look fields are required; motion, the about fields and the note are optional, an empty cell when not seen. A row without a header is the old one: name, the eight look fields, an optional note. A header can also name one `line` column: the keep's tags as one flat line of words, the way people keep them by hand, look first, then ` · `, then about: `photo colour serif weight:bold split muted grain large kinetic · web-hero fashion calm red airy portrait`. It fills the fields the cells leave empty; a field in both is refused. A word in two fields (today none, ui, collage, mono, duotone, bold, editorial) is written `field:word`, as `type:mono` or `mood:editorial`; bare, or in no field, it refuses the merge and is named. Leave none out: a line without picture, photo or motion reads them as none. Every tool reads such a line with `parseTagLine` from `tag.mjs`, and writes one with `formatTagLine`. The second command checks every word against its field. Their own board tags seed the rows: map each to the vocabulary and tag only what is left. Tag what is there, never what is good. On a big board, split the sheets across a few agents.
58
+
59
+ ## 3. Sort, then the eye
60
+
61
+ ```
62
+ node <skill>/scripts/families.mjs .longbeard/design/families/profiles.json --board .longbeard/design/families/board.md --sliders "loud=2,picture=4,rich=2,cool=2,dense=2"
63
+ ```
64
+
65
+ The sliders are the design brief's personality, copied from its `personality:` line (`picture-led` is `picture`; `playful` and `new` are passed over, since a picture cannot tell them: judge those by eye in step 4). It joins the closest references first and stops when groups no longer look alike, so outliers stay strays. A wide gap on what is seen first (how empty, how loud, type size, where things sit, what the picture is) keeps two apart; light or dark does not. A bin far bigger than the rest is sorted again on its own and said; one it cannot split is sorted alone with `--only .longbeard/design/families/families/f3.tsv --spread 0.4` (its parts land in `families/families/f3-split/`). `--spread` lower splits finer.
66
+
67
+ Then check each family by eye on contact sheets, never picture by picture:
68
+
69
+ ```
70
+ node <skill>/scripts/contact-sheet.mjs .longbeard/design/families/families/f1.tsv --out <scratch>/f1 --contain
71
+ ```
72
+
73
+ - Split a family that holds two looks, merge two that are one, place each stray. Strays are often the most distinctive references: never drop one for being a stray.
74
+ - **Name each family for what is seen**, in words a person outside design would use ("one huge word is the picture", "dark app pages, headline centred"). If the only honest name is a number ("dark, all picture"), it is a bin: break it up.
75
+ - As many families as there are looks. Never merge to reach a number.
76
+ - On hundreds of references: check each family's six most typical now, and every member of a family once it is taken.
77
+
78
+ ## 4. Show them, once
79
+
80
+ The families page, each family as its six most typical, its size and what it shares:
81
+
82
+ ```
83
+ node <skill>/scripts/moodboard.mjs .longbeard/design/families/board.md --overview 6 --out .longbeard/design/families/families.html
84
+ ```
85
+
86
+ For a Figma board, also build the `Families` page with `use_figma` (load `figma-use` first): a section per family, named, with copies of its cards, most typical first. Read the names back from the nodes.
87
+
88
+ In the same message, one line per family: its name, what the eye changed from the numbers, and, as hints only, which fit the design brief's personality, which look like its "never", and which rely on pictures they do not have. Where what they chose sits far from what they said ("you said quiet; your board is loud"), ask which to go by. Then:
89
+
90
+ > Take the families you want to work from, one or two. Note any that look like two, or belong together.
91
+
92
+ - **A split or merge note:** apply it, show the page again. `families.mjs` will not overwrite a board: remove `.longbeard/design/families/board.md` before sorting again.
93
+ - **None taken:** ask in one line what is missing, and offer `design-moodboard` for a search sized to it.
94
+ - **Two taken:** two looks. Ask which comes first; the other waits.
95
+
96
+ ## Write `docs/design/design-families.md`
97
+
98
+ ```markdown
99
+ # Families: <product>
100
+
101
+ <n> references sorted into <n> families and <n> strays.
102
+
103
+ ## Taken
104
+ ### <family name>
105
+ <what its members share, in one or two lines: how much type against picture, how empty, how loud, how pictures are treated> · <n> references
106
+
107
+ ## Also on the board
108
+ - <family name> — <what it shares> · <n>
109
+ ```
110
+
111
+ No names, links or paths. The members of each family are in `.longbeard/design/families/families/f<n>.tsv`; the taken ones are the references `design-direction` and `design-identity` work from.
112
+
113
+ Then the next step in one line: `design-direction`.
114
+
115
+ ## A library that grows
116
+
117
+ When new references arrive after the families are named, add them without sorting again: nothing already in a family moves, and the names stay. Measure and tag only the new keeps into the same `profiles.json` (steps 1 and 2), then:
118
+
119
+ ```
120
+ node <skill>/scripts/families.mjs .longbeard/design/families/profiles.json --assign .longbeard/design/families/families.json
121
+ ```
122
+
123
+ Every reference in no family is new. Each joins the nearest family when it sits within `--spread`, with a confidence from 0 to 1 and its 5 nearest references already in families. The new ones that join nothing are sorted among themselves: a group of three or more is a **seed**, a proposed new family; the rest are strays with their nearest family. It writes `assign.json` and never changes `families.json`.
124
+
125
+ - Check each join by eye on a contact sheet beside its family, low confidence first. Move one that does not belong.
126
+ - Name each seed for what is seen, as in step 3, or fold it into a family by eye.
127
+ - Place each stray as in step 3.
128
+ - Show only what changed: which family each new reference went to, and any new family. Then update `docs/design/design-families.md`: sizes, and any new family under **Also on the board**.
129
+
130
+ Sort the whole pool again only when they ask, or when the new references outnumber the ones already sorted.
131
+
132
+ ## Do not
133
+
134
+ - Run on a curated board of a few dozen without being asked.
135
+ - Move, rename or delete anything on their own Figma pages.
136
+ - Pick the family for them, or hide one because it looks like their "never".
137
+ - Sort before every keep is measured and tagged, or read profiles into the chat.
138
+ - Sort a named pool from scratch to add a few new references: use `--assign`.