@jonandev/longbeard 0.8.0 → 0.10.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.
@@ -0,0 +1,489 @@
1
+ #!/usr/bin/env node
2
+ // Full-page capture. Unsticks fixed/sticky chrome first so Chrome does not
3
+ // repeat the same fold. Node 22+. Uses an installed Chrome/Edge/Chromium.
4
+ //
5
+ // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg
6
+ // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg --review /tmp/name-review.jpg
7
+ // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg --clip x,y,w,h
8
+ // node capture.mjs <url> --out design-exploration/<slug>/refs/name.jpg --clip-selector "main"
9
+ // node capture.mjs <url> --out /tmp/mobile.png --width 390
10
+ // node capture.mjs http://localhost:3000/app --out /tmp/app.png --cookie "session=abc; theme=dark" --strict
11
+ //
12
+ // A page that ends up at another address (a login, or a site's canonical
13
+ // www) is named on stderr. With --strict that is exit 1, so a 0 means the
14
+ // shot is of the page asked for.
15
+ // node capture.mjs file:///abs/path/moodboard.html --out /tmp/moodboard.jpg
16
+ // node capture.mjs file:///abs/path/shot.jpg --out design-exploration/<slug>/refs/name.jpg --clip x,y,w,h
17
+ import { spawn, execSync } from "node:child_process";
18
+ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
19
+ import { tmpdir } from "node:os";
20
+ import { dirname, isAbsolute, join, resolve } from "node:path";
21
+
22
+ const args = process.argv.slice(2);
23
+ const flag = (name, def) => {
24
+ const i = args.indexOf(`--${name}`);
25
+ if (i === -1) return def;
26
+ const v = args[i + 1];
27
+ args.splice(i, 2);
28
+ return v;
29
+ };
30
+ const url = args[0];
31
+ const outArg = flag("out", "") || "";
32
+ const reviewArg = flag("review", "") || "";
33
+ const clipArg = flag("clip", "") || "";
34
+ const clipSelector = flag("clip-selector", "") || "";
35
+ // Sent with every request to the page's own origin, as a logged-in browser would.
36
+ const cookieArg = flag("cookie", "") || "";
37
+ const strictAt = args.indexOf("--strict");
38
+ const strict = strictAt !== -1;
39
+ if (strict) args.splice(strictAt, 1);
40
+ // Below 768 the page gets a phone viewport: mobile layout, 2x pixels.
41
+ const width = Math.round(Number(flag("width", "1440")));
42
+ if (!url || !/^(https?|file):\/\//.test(url) || !outArg) {
43
+ console.error(
44
+ 'usage: node capture.mjs <https://url | file:///path> --out design-exploration/<slug>/refs/name.jpg [--review /tmp/name-review.jpg] [--clip x,y,w,h | --clip-selector "css"] [--width 390] [--cookie "name=value; …"] [--strict]',
45
+ );
46
+ process.exit(2);
47
+ }
48
+ if (!Number.isFinite(width) || width < 200 || width > 3840) {
49
+ console.error("width must be a number from 200 to 3840");
50
+ process.exit(2);
51
+ }
52
+ const mobile = width < 768;
53
+ const height = mobile ? 844 : 900;
54
+ if (clipArg && clipSelector) {
55
+ console.error("pass --clip or --clip-selector, not both");
56
+ process.exit(2);
57
+ }
58
+
59
+ function projectRoot() {
60
+ try {
61
+ return execSync("git rev-parse --show-toplevel", { encoding: "utf8" }).trim();
62
+ } catch {
63
+ return process.cwd();
64
+ }
65
+ }
66
+
67
+ function resolveOut(path) {
68
+ if (!path) return "";
69
+ if (isAbsolute(path)) return path;
70
+ return resolve(projectRoot(), path);
71
+ }
72
+
73
+ const out = resolveOut(outArg);
74
+ const reviewOut = resolveOut(reviewArg);
75
+
76
+ function parseClip(s) {
77
+ if (!s) return null;
78
+ const parts = s.split(",").map((n) => Number(n.trim()));
79
+ if (parts.length !== 4 || parts.some((n) => !Number.isFinite(n) || n < 0)) {
80
+ console.error("clip must be x,y,w,h (non-negative numbers)");
81
+ process.exit(2);
82
+ }
83
+ const [x, y, w, h] = parts;
84
+ if (w < 1 || h < 1) {
85
+ console.error("clip width and height must be >= 1");
86
+ process.exit(2);
87
+ }
88
+ return { x, y, width: w, height: h, scale: 1 };
89
+ }
90
+
91
+ const clip = parseClip(clipArg);
92
+
93
+ function findChrome() {
94
+ const env = process.env.CHROME_PATH;
95
+ if (env && existsSync(env)) return env;
96
+ const home = process.env.HOME || process.env.USERPROFILE || "";
97
+ const local = process.env.LOCALAPPDATA || "";
98
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
99
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
100
+ const candidates = [
101
+ join(pf, "Google/Chrome/Application/chrome.exe"),
102
+ join(pf86, "Google/Chrome/Application/chrome.exe"),
103
+ join(local, "Google/Chrome/Application/chrome.exe"),
104
+ join(pf, "Microsoft/Edge/Application/msedge.exe"),
105
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
106
+ "/Applications/Chromium.app/Contents/MacOS/Chromium",
107
+ "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
108
+ join(home, "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
109
+ "/usr/bin/google-chrome",
110
+ "/usr/bin/google-chrome-stable",
111
+ "/usr/bin/chromium",
112
+ "/usr/bin/chromium-browser",
113
+ ];
114
+ return candidates.find((path) => path && existsSync(path)) || null;
115
+ }
116
+
117
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
118
+
119
+ const exe = findChrome();
120
+ if (!exe) {
121
+ console.error("No Chrome/Edge/Chromium found. Install one or set CHROME_PATH.");
122
+ process.exit(1);
123
+ }
124
+ if (typeof WebSocket === "undefined") {
125
+ console.error("Node 22+ is required.");
126
+ process.exit(1);
127
+ }
128
+
129
+ const dir = mkdtempSync(join(tmpdir(), "hunt-chrome-"));
130
+ let proc;
131
+ const drop = () => {
132
+ try {
133
+ if (proc?.pid) process.kill(proc.pid, "SIGKILL");
134
+ } catch {}
135
+ try {
136
+ rmSync(dir, { recursive: true, force: true });
137
+ } catch {}
138
+ };
139
+ process.once("exit", drop);
140
+
141
+ proc = spawn(
142
+ exe,
143
+ [
144
+ "--headless=new",
145
+ "--remote-debugging-port=0",
146
+ `--user-data-dir=${dir}`,
147
+ "--no-first-run",
148
+ "--hide-scrollbars",
149
+ "--mute-audio",
150
+ "--force-color-profile=srgb",
151
+ `--window-size=${width},${height}`,
152
+ "about:blank",
153
+ ],
154
+ { stdio: ["ignore", "ignore", "pipe"] },
155
+ );
156
+
157
+ let buf = "";
158
+ const wsUrl = await new Promise((resolveWs, reject) => {
159
+ const t = setTimeout(() => reject(new Error("Chrome did not start")), 20000);
160
+ proc.stderr.on("data", (d) => {
161
+ buf += d.toString();
162
+ const m = buf.match(/DevTools listening on (ws:\/\/[^\s]+)/);
163
+ if (m) {
164
+ clearTimeout(t);
165
+ resolveWs(m[1]);
166
+ }
167
+ });
168
+ proc.on("exit", (code) => {
169
+ clearTimeout(t);
170
+ reject(new Error(`Chrome exited ${code}`));
171
+ });
172
+ });
173
+
174
+ const ws = new WebSocket(wsUrl);
175
+ await new Promise((res, rej) => {
176
+ ws.onopen = res;
177
+ ws.onerror = () => rej(new Error("CDP socket failed"));
178
+ });
179
+ let nextId = 1;
180
+ const pending = new Map();
181
+ ws.onmessage = (ev) => {
182
+ const msg = JSON.parse(typeof ev.data === "string" ? ev.data : Buffer.from(ev.data).toString());
183
+ if (msg.id && pending.has(msg.id)) {
184
+ const { resolve: ok, reject: bad } = pending.get(msg.id);
185
+ pending.delete(msg.id);
186
+ if (msg.error) bad(new Error(msg.error.message));
187
+ else ok(msg.result);
188
+ }
189
+ };
190
+ const send = (method, params = {}, sessionId, timeoutMs = 30000) => {
191
+ const id = nextId++;
192
+ return new Promise((resolveSend, reject) => {
193
+ const timer = setTimeout(() => {
194
+ pending.delete(id);
195
+ reject(new Error(`CDP timeout: ${method}`));
196
+ }, timeoutMs);
197
+ pending.set(id, {
198
+ resolve: (v) => {
199
+ clearTimeout(timer);
200
+ resolveSend(v);
201
+ },
202
+ reject: (e) => {
203
+ clearTimeout(timer);
204
+ reject(e);
205
+ },
206
+ });
207
+ ws.send(JSON.stringify(sessionId ? { id, method, params, sessionId } : { id, method, params }));
208
+ });
209
+ };
210
+
211
+ const { targetId } = await send("Target.createTarget", { url: "about:blank" });
212
+ const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true });
213
+ const page = (method, params, timeoutMs) => send(method, params, sessionId, timeoutMs);
214
+
215
+ await page("Page.enable");
216
+ await page("Runtime.enable");
217
+ await page("Emulation.setDeviceMetricsOverride", {
218
+ width,
219
+ height,
220
+ deviceScaleFactor: mobile ? 2 : 1,
221
+ mobile,
222
+ });
223
+ // Chrome centres an image file and shrinks it to the window. A page that holds
224
+ // it at full size from 0,0 makes --clip x,y,w,h the image's own pixels.
225
+ let target = url;
226
+ if (/^file:\/\/.*\.(png|jpe?g|webp|gif)$/i.test(url)) {
227
+ target = `file://${join(dir, "image.html")}`;
228
+ writeFileSync(join(dir, "image.html"), `<!doctype html><body style="margin:0;background:#000"><img src="${url.replace(/"/g, "%22")}" style="display:block">`);
229
+ }
230
+ if (cookieArg && /^https?:/.test(url)) {
231
+ const cookies = cookieArg
232
+ .split(";")
233
+ .map((pair) => pair.trim())
234
+ .filter(Boolean)
235
+ .map((pair) => {
236
+ const at = pair.indexOf("=");
237
+ return { name: pair.slice(0, at), value: pair.slice(at + 1), url: new URL(url).origin };
238
+ });
239
+ if (cookies.some((cookie) => !cookie.name)) {
240
+ console.error('cookie must be "name=value; name=value"');
241
+ drop();
242
+ process.exit(2);
243
+ }
244
+ await page("Network.setCookies", { cookies });
245
+ }
246
+ await page("Page.navigate", { url: target }, 40000);
247
+ await sleep(2500);
248
+
249
+ const beforeHref = (
250
+ await page("Runtime.evaluate", {
251
+ expression: "location.href",
252
+ returnByValue: true,
253
+ })
254
+ ).result.value;
255
+
256
+ await page("Runtime.evaluate", {
257
+ expression: `(() => {
258
+ const labels = /^(accept( all)?( cookies)?|agree|ok|okay|got it|allow( all)?|i understand|acepto|aceptar)$/i;
259
+ const clickable = document.querySelectorAll("button, [role=button]");
260
+ for (const el of clickable) {
261
+ const t = (el.innerText || el.textContent || "").trim().replace(/\\s+/g, " ");
262
+ if (t.length < 40 && labels.test(t)) { el.click(); break; }
263
+ }
264
+ // Strip short privacy/cookie dialogs (e.g. Google Fonts "×" banner).
265
+ const privacy = /uses cookies|privacy and google fonts|cookie settings/i;
266
+ for (const el of [...document.querySelectorAll("div, section, aside, dialog")]) {
267
+ const t = (el.innerText || el.textContent || "").trim();
268
+ if (t.length > 0 && t.length < 300 && privacy.test(t) && el.children.length < 12) {
269
+ el.remove();
270
+ }
271
+ }
272
+ })()`,
273
+ awaitPromise: true,
274
+ returnByValue: true,
275
+ });
276
+ await sleep(800);
277
+
278
+ const afterHref = (
279
+ await page("Runtime.evaluate", {
280
+ expression: "location.href",
281
+ returnByValue: true,
282
+ })
283
+ ).result.value;
284
+
285
+ if (afterHref !== beforeHref) {
286
+ console.error(`navigated away: ${afterHref}`);
287
+ drop();
288
+ process.exit(1);
289
+ }
290
+
291
+ await page(
292
+ "Runtime.evaluate",
293
+ {
294
+ expression: `(() => new Promise((done) => {
295
+ (async () => {
296
+ for (const img of document.images) {
297
+ if (img.loading === "lazy") img.loading = "eager";
298
+ }
299
+ const dwell = (ms) => new Promise((r) => setTimeout(r, ms));
300
+ const step = Math.max(480, Math.round(window.innerHeight * 0.65));
301
+ const limit = Math.min(
302
+ Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight || 0),
303
+ 14000
304
+ );
305
+ let y = 0;
306
+ while (y < limit) {
307
+ y = Math.min(limit, y + step);
308
+ window.scrollTo(0, y);
309
+ await dwell(600);
310
+ }
311
+ await Promise.race([
312
+ Promise.all([...document.images].map((img) => img.decode().catch(() => {}))),
313
+ dwell(8000),
314
+ ]);
315
+ window.scrollTo(0, 0);
316
+ await dwell(700);
317
+ done();
318
+ })().catch(() => done());
319
+ }))()`,
320
+ awaitPromise: true,
321
+ returnByValue: true,
322
+ },
323
+ 90000,
324
+ );
325
+
326
+ await page("Runtime.evaluate", {
327
+ expression: `(() => {
328
+ const style = document.createElement("style");
329
+ style.textContent = \`
330
+ html, body { height: auto !important; max-height: none !important; overflow: visible !important; }
331
+ * { animation-play-state: paused !important; transition: none !important; scroll-behavior: auto !important; }
332
+ \`;
333
+ document.head.appendChild(style);
334
+ for (const el of document.querySelectorAll("*")) {
335
+ const pos = getComputedStyle(el).position;
336
+ if (pos === "fixed" || pos === "sticky") {
337
+ el.style.setProperty("position", "relative", "important");
338
+ el.style.setProperty("top", "auto", "important");
339
+ el.style.setProperty("bottom", "auto", "important");
340
+ }
341
+ }
342
+ })()`,
343
+ awaitPromise: true,
344
+ returnByValue: true,
345
+ });
346
+ await sleep(400);
347
+
348
+ // A redirect can land late (an app checks the session after it loads), so
349
+ // the address is checked last, right before the shot.
350
+ if (target === url) {
351
+ const landed = (await page("Runtime.evaluate", { expression: "location.href", returnByValue: true })).result.value;
352
+ const where = (href) => {
353
+ const u = new URL(href);
354
+ return `${u.origin}${u.pathname.replace(/\/$/, "")}`;
355
+ };
356
+ if (where(landed) !== where(url)) {
357
+ console.error(`landed on ${landed}, not ${url}.${/^https?:/.test(landed) ? " Behind a login? Pass --cookie." : " Check the address."}`);
358
+ if (strict) {
359
+ drop();
360
+ process.exit(1);
361
+ }
362
+ }
363
+ }
364
+
365
+ // --clip-selector takes the element's box in document coordinates, measured
366
+ // after the unstick pass so the numbers match what the capture sees.
367
+ let selected = null;
368
+ if (clipSelector) {
369
+ const { result } = await page("Runtime.evaluate", {
370
+ expression: `(() => {
371
+ const el = document.querySelector(${JSON.stringify(clipSelector)});
372
+ if (!el) return null;
373
+ const r = el.getBoundingClientRect();
374
+ return {
375
+ x: Math.max(0, Math.round(r.left + window.scrollX)),
376
+ y: Math.max(0, Math.round(r.top + window.scrollY)),
377
+ width: Math.round(r.width),
378
+ height: Math.round(r.height),
379
+ };
380
+ })()`,
381
+ returnByValue: true,
382
+ });
383
+ selected = result?.value || null;
384
+ if (!selected) {
385
+ console.error(`no element matches ${clipSelector}`);
386
+ drop();
387
+ process.exit(1);
388
+ }
389
+ if (selected.width < 1 || selected.height < 1) {
390
+ console.error(`${clipSelector} has no box (width ${selected.width}, height ${selected.height})`);
391
+ drop();
392
+ process.exit(1);
393
+ }
394
+ }
395
+
396
+ const metrics = await page("Page.getLayoutMetrics");
397
+ const size = metrics.cssContentSize || metrics.contentSize;
398
+ const fullWidth = Math.max(1, Math.ceil(size.width || width));
399
+ const fullHeight = Math.max(1, Math.min(Math.ceil(size.height || height), 14000));
400
+ const clipBox = clip || (selected ? { ...selected, scale: 1 } : null);
401
+ const shotClip = clipBox
402
+ ? {
403
+ x: Math.min(clipBox.x, fullWidth - 1),
404
+ y: Math.min(clipBox.y, fullHeight - 1),
405
+ width: Math.min(clipBox.width, fullWidth - Math.min(clipBox.x, fullWidth - 1)),
406
+ height: Math.min(clipBox.height, fullHeight - Math.min(clipBox.y, fullHeight - 1)),
407
+ scale: 1,
408
+ }
409
+ : { x: 0, y: 0, width: fullWidth, height: fullHeight, scale: 1 };
410
+
411
+ // The file is what its name says, so a reader that trusts the extension is right.
412
+ const format = /\.png$/i.test(out) ? "png" : /\.webp$/i.test(out) ? "webp" : "jpeg";
413
+ const { data } = await page(
414
+ "Page.captureScreenshot",
415
+ {
416
+ format,
417
+ ...(format === "png" ? {} : { quality: 70 }),
418
+ captureBeyondViewport: true,
419
+ clip: shotClip,
420
+ },
421
+ 60000,
422
+ );
423
+
424
+ mkdirSync(dirname(out), { recursive: true });
425
+ writeFileSync(out, Buffer.from(data, "base64"));
426
+ console.log(out);
427
+
428
+ if (reviewOut) {
429
+ // Side-by-side columns ~2800 px tall so a tall capture stays readable.
430
+ // Real capture stays the single tall file; review is scratch only.
431
+ const reviewHtml = `<!doctype html><meta charset=utf-8>
432
+ <canvas id=c></canvas>
433
+ <script>
434
+ const src = "data:image/${format};base64,${data}";
435
+ const img = new Image();
436
+ img.onload = () => {
437
+ const colH = 2800;
438
+ const gap = 20;
439
+ const cols = Math.max(1, Math.ceil(img.height / colH));
440
+ const c = document.getElementById("c");
441
+ c.width = cols * img.width + (cols - 1) * gap;
442
+ c.height = Math.min(colH, img.height);
443
+ const ctx = c.getContext("2d");
444
+ ctx.fillStyle = "#111";
445
+ ctx.fillRect(0, 0, c.width, c.height);
446
+ for (let i = 0; i < cols; i++) {
447
+ const sy = i * colH;
448
+ const sh = Math.min(colH, img.height - sy);
449
+ ctx.drawImage(img, 0, sy, img.width, sh, i * (img.width + gap), 0, img.width, sh);
450
+ }
451
+ document.title = "ready";
452
+ };
453
+ img.src = src;
454
+ </script>`;
455
+ const reviewPage = join(dir, "review.html");
456
+ writeFileSync(reviewPage, reviewHtml);
457
+ await page("Page.navigate", { url: `file://${reviewPage}` }, 20000);
458
+ await sleep(400);
459
+ for (let i = 0; i < 40; i++) {
460
+ const title = (
461
+ await page("Runtime.evaluate", { expression: "document.title", returnByValue: true })
462
+ ).result.value;
463
+ if (title === "ready") break;
464
+ await sleep(100);
465
+ }
466
+ const { result: sizeResult } = await page("Runtime.evaluate", {
467
+ expression: `(() => {
468
+ const c = document.getElementById("c");
469
+ return { w: c.width, h: c.height };
470
+ })()`,
471
+ returnByValue: true,
472
+ });
473
+ const { data: reviewData } = await page(
474
+ "Page.captureScreenshot",
475
+ {
476
+ format: /\.png$/i.test(reviewOut) ? "png" : "jpeg",
477
+ quality: 75,
478
+ clip: { x: 0, y: 0, width: sizeResult.value.w, height: sizeResult.value.h, scale: 1 },
479
+ captureBeyondViewport: true,
480
+ },
481
+ 60000,
482
+ );
483
+ mkdirSync(dirname(reviewOut), { recursive: true });
484
+ writeFileSync(reviewOut, Buffer.from(reviewData, "base64"));
485
+ console.log(reviewOut);
486
+ }
487
+
488
+ drop();
489
+ process.exit(0);
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ // WCAG 2.x contrast for colour pairs.
3
+ // node contrast.mjs "#2c2824 on #f6f1e7" "#b0563a on #f6f1e7:mark"
4
+ // Suffix :large or :mark checks against 3:1 instead of 4.5:1.
5
+ const lum = (hex) => {
6
+ const [r, g, b] = [1, 3, 5]
7
+ .map((i) => parseInt(hex.slice(i, i + 2), 16) / 255)
8
+ .map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
9
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
10
+ };
11
+ let failed = false;
12
+ for (const arg of process.argv.slice(2)) {
13
+ const m = arg.match(/^(#[0-9a-f]{6})\s+on\s+(#[0-9a-f]{6})(?::(large|mark))?$/i);
14
+ if (!m) {
15
+ console.error(`skip: ${arg}`);
16
+ continue;
17
+ }
18
+ const [a, b] = [lum(m[1]), lum(m[2])];
19
+ const ratio = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
20
+ const need = m[3] ? 3 : 4.5;
21
+ const verdict = ratio >= 7 && !m[3] ? "AAA" : ratio >= need ? "AA" : "FAIL";
22
+ if (verdict === "FAIL") failed = true;
23
+ console.log(
24
+ `${m[1]} on ${m[2]} ${ratio.toFixed(2)}:1 ${verdict}${m[3] ? ` (${m[3]}, needs 3:1)` : ""}`,
25
+ );
26
+ }
27
+ process.exit(failed ? 1 : 0);
@@ -0,0 +1,78 @@
1
+ ---
2
+ name: design-check
3
+ description: >
4
+ Check a screen against the design rules and DESIGN.md, and report findings
5
+ (rule, hard or soft, where, fix). Frame mode checks a Figma frame, called
6
+ by design after each screen. Build mode checks a built UI spec against its
7
+ Ready frames, run after implement-spec, with evidence for the PR. Hard
8
+ findings block; soft findings are reported. It reports and never redesigns.
9
+ ---
10
+
11
+ # design-check
12
+
13
+ Checks one thing: does this screen pass [design-rules.md](references/design-rules.md) and follow `DESIGN.md`? It returns findings. The caller fixes them. It does not suggest a new look, and it does not change `DESIGN.md`.
14
+
15
+ ## Findings
16
+
17
+ One line per finding, hard first:
18
+
19
+ ```
20
+ | Rule | Hard/soft | Where | Fix |
21
+ |---|---|---|---|
22
+ | 8 States | hard | Today, no empty frame | Add "Today — empty": what goes here, and the one action that fills it |
23
+ | 4 Spacing | soft | Today, list to heading gap 24 | Use space/lg (32) or say why in DESIGN.md |
24
+ ```
25
+
26
+ - **Rule** is the number and name from design-rules.md, plus the check if the section has several.
27
+ - **Where** names the screen and the element, so someone can find it without the screenshot.
28
+ - **Fix** is the smallest change that passes, in `DESIGN.md`'s tokens. Never a new colour, face or component the file does not have. If the only fix is one, write "needs a design decision" and say what.
29
+ - A soft rule that `DESIGN.md` overrides with a reason is not a finding. Without a reason, it is.
30
+ - No findings: say "passes" and list which rules were checked.
31
+
32
+ **Hard blocks; soft is reported.** The caller gets one fresh pass to fix the hard findings, then one re-check. Hard findings that remain are listed as open. They never pass silently.
33
+
34
+ ## Order
35
+
36
+ 1. **Idea** (rule 0): cover the logo. Is it still this product?
37
+ 2. **Hard** checks, every section, then the site or app list from the brief's surface.
38
+ 3. **Soft** checks, then the tells (rule 14).
39
+
40
+ Read `DESIGN.md` first: its tokens, components and decisions are what "follows the file" means.
41
+
42
+ ## Frame mode
43
+
44
+ Called by `design` after it composes or changes a Figma screen. Input: the file key, the node IDs of the screen and its state frames, and the approved prototype shot of that screen when there is one.
45
+
46
+ 1. Load `figma-use` for any `use_figma` call. Screenshot each frame (`get_screenshot`, `maxDimension` 1440 so text is readable). Read structure with `get_metadata` when spacing or alignment needs numbers.
47
+ 2. Find the states: frames named `<screen> — empty`, `— loading`, `— error` next to the default. A missing one is a rule 8 hard finding.
48
+ 3. Check tokens where the screenshot cannot tell: in one read-only `use_figma` call, list fills, gaps and text styles that are not bound to a variable or style. An unbound value is a rule 7 soft finding when a token exists for it.
49
+ 4. Compare with the prototype shot, side by side. The frame must be faithful to what they approved. Anything lost or changed without their yes is a hard finding, under rule 0. Pixels do not count. No shot: say "not compared".
50
+ 5. Return the findings. `design` fixes the hard ones, runs this once more, then shows the screen. A frame with open hard findings is never marked Ready.
51
+
52
+ ## Build mode
53
+
54
+ After `implement-spec` builds a UI spec. Input: the running app's URL for each screen, and the Ready frames the tickets link.
55
+
56
+ 1. **Render** each screen at phone and desktop:
57
+ ```
58
+ node <skill>/scripts/capture.mjs <url> --out <scratch>/<screen>-390.png --width 390 --strict
59
+ node <skill>/scripts/capture.mjs <url> --out <scratch>/<screen>-1440.png --strict
60
+ ```
61
+ Behind a login, pass `--cookie "name=value"` from a dev session the project already uses (a seed user, a test token). Never ask for real credentials. `--strict` exits 1 when the page lands elsewhere: a shot of the login page is not a check. Report it and stop for that screen.
62
+ 2. **Reach the states.** Render empty, loading and error the way the app allows: a fixture, a seed, a query flag, a test route. A state that cannot be reached is reported as "not checked", never as passed.
63
+ 3. **Compare with the Ready frame on meaning, not pixels:**
64
+ - structure: the same sections, in the same order, with the same hierarchy
65
+ - tokens: colours, type and spacing are `DESIGN.md`'s values (`scripts/contrast.mjs` for any pair that looks off)
66
+ - copy: the frame's words, not placeholders or new ones
67
+ - states: each frame state exists and says the same thing
68
+ A difference from the frame is a finding, hard when it breaks a hard rule or changes structure or copy. The rules' glue line holds: a mismatch with the frame is a bug.
69
+ 4. **Check the rules** on the build shots, in the order above.
70
+ 5. **Fix pass.** Hard findings get one fresh fix pass (a new agent or a clean context, with the findings as its brief), then one re-check.
71
+ 6. **PR evidence.** Matt's `pr` writes the body. Put the shots in its Before/After: the Ready frame beside the build at each width. Then the findings table, with what remains open after the re-check.
72
+
73
+ ## Do not
74
+
75
+ - Redesign, or suggest a colour, face or component `DESIGN.md` does not have.
76
+ - Pass a state you could not see, or a screen whose shot landed on another page.
77
+ - Edit `DESIGN.md` or the Figma file. Fixes are the caller's.
78
+ - Compare pixels. Two renders of the same design differ by antialiasing and fonts. Meaning is what is checked.