@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);
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  // Build labelled contact sheets from a TSV of label\timageURL.
3
- // Writes JPEG grids (~36 per sheet) into an output directory (scratch, not .design/).
3
+ // Writes JPEG grids (~36 per sheet) into an output directory (scratch, not design-exploration/).
4
4
  // Viewing listing thumbnails is allowed; this is not a capture.
5
5
  //
6
6
  // node contact-sheet.mjs candidates.tsv --out /tmp/hunt-sheets
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  // A moodboard of the references: every card with a shot, its name, its
3
- // tagline, and a link to its source. The layout is this file. It shows what
3
+ // pattern, and a link to its source. The layout is this file. It shows what
4
4
  // we saw. It does not paint a brand, a logo, a line, or a stat.
5
5
  //
6
- // node moodboard.mjs .design/board.md --out .design/moodboard.html
7
- // node moodboard.mjs .design/hunts/pricing/board.md --out .design/hunts/pricing/moodboard.html
8
- //
9
- // A card with `slot: product` stays off: a product page cropped into a tile is noise.
6
+ // node moodboard.mjs design-exploration/identity/board.md --out design-exploration/identity/moodboard.html
7
+ // node moodboard.mjs design-exploration/pricing/board.md --out design-exploration/pricing/moodboard.html
10
8
  import { execSync } from "node:child_process";
11
9
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
12
10
  import { dirname, isAbsolute, relative, resolve } from "node:path";
@@ -16,7 +14,7 @@ const outAt = args.indexOf("--out");
16
14
  const outArg = outAt === -1 ? "" : (args.splice(outAt, 2)[1] ?? "");
17
15
  const boardArg = args[0];
18
16
  if (!boardArg || !outArg || args.length !== 1) {
19
- console.error("usage: node moodboard.mjs .design/board.md --out .design/moodboard.html");
17
+ console.error("usage: node moodboard.mjs design-exploration/<slug>/board.md --out design-exploration/<slug>/moodboard.html");
20
18
  process.exit(2);
21
19
  }
22
20
 
@@ -65,7 +63,7 @@ const cards = md
65
63
 
66
64
  const tiles = [];
67
65
  for (const card of cards) {
68
- if (!card.shot || /product/i.test(card.slot || "")) continue;
66
+ if (!card.shot) continue;
69
67
  const abs = resolvePath(card.shot.trim());
70
68
  if (!existsSync(abs)) {
71
69
  console.error(`moodboard: missing shot ${card.shot.trim()}`);
@@ -74,12 +72,12 @@ for (const card of cards) {
74
72
  let src = relative(dirname(outPath), abs).split("\\").join("/");
75
73
  if (!src.startsWith(".")) src = `./${src}`;
76
74
  // A seed shared in chat has no URL, so its tile has no link.
77
- const url = (card.url || "").trim().split(/\s+/)[0];
75
+ const url = (card.link || "").trim().split(/\s+/)[0];
78
76
  const img = `<img src="${esc(src)}" alt="${esc(card.name)}" loading="lazy">`;
79
77
  const frame = /^https?:\/\//i.test(url)
80
78
  ? `<a class="frame" href="${esc(url)}" target="_blank" rel="noopener noreferrer">${img}</a>`
81
79
  : `<div class="frame">${img}</div>`;
82
- const line = card.tagline ? `<p class="line">${esc(card.tagline)}</p>` : "";
80
+ const line = card.pattern ? `<p class="line">${esc(card.pattern)}</p>` : "";
83
81
  tiles.push(`<figure class="tile">${frame}<figcaption><p class="name">${esc(card.name)}</p>${line}</figcaption></figure>`);
84
82
  }
85
83
 
@@ -0,0 +1,103 @@
1
+ ---
2
+ name: idea
3
+ description: >
4
+ Turn an idea, or an existing repo, into docs/brief.md: one page that says
5
+ what the product is, for whom, its core flows and key screens, and whether
6
+ it has a UI. Grills in rounds until every section is settled, then writes
7
+ the brief and offers the next stage. Runs first in a new project, when a
8
+ repo has no brief, or when the product itself changes. A feature for a
9
+ product that has a brief goes to to-spec, not here.
10
+ ---
11
+
12
+ # Idea
13
+
14
+ One file comes out: `docs/brief.md`, about 500 words, one page. Every later stage reads it: `design-direction` for the people, surface and identity nouns, `design` for the key screens, `to-spec` for the flows. No stage asks for these again, so the brief has to settle them.
15
+
16
+ The brief says what and for whom, never how. No framework, database, host or library. Those are Architecture's.
17
+
18
+ ## Gate
19
+
20
+ Look at the repo. Do not ask what is there.
21
+
22
+ 1. `docs/brief.md` exists and they bring a feature → not this skill. Grill the feature with `grill-with-docs` when it brings new terms, otherwise `grilling`; then `to-spec`. The brief stays as it is.
23
+ 2. `docs/brief.md` exists and the product itself changes (new people, new surface, a flow dropped) → **Change**.
24
+ 3. No brief, and the repo has code or a README → **Existing project**.
25
+ 4. Otherwise → **New idea**.
26
+
27
+ ## New idea
28
+
29
+ Load Matt's `grilling` and run it. The design tree is the brief's sections below. Start with the frontier: a working name, problem, who it is for, surface. Flows, screens and scope hang off those. A working name is enough; it can change.
30
+
31
+ - One round per message, numbered, a recommended answer on each, as `grilling` says.
32
+ - Recommend from the idea itself. A one-line idea still has a likely person and a likely first flow: propose them, they correct.
33
+ - A section they do not care about gets your recommendation and a "yes" settles it. Never leave one blank.
34
+ - Stop asking when every section has an answer. Then say the brief in chat in six lines (problem, for, flows, surface, v1, out) and ask "Write `docs/brief.md`?" Write on yes.
35
+
36
+ ## Existing project
37
+
38
+ Read the README, the package manifest, the routes or entry points, and any `docs/`. Draft every section you can from what is there and mark each one **from the repo** or **gap**. A section the code shows but the README contradicts is a gap.
39
+
40
+ Show the draft, then grill only the gaps, in rounds. Same confirm, same write.
41
+
42
+ ## Change
43
+
44
+ Read the brief. Grill only what changes and what hangs off it: a new surface reopens key screens, a new person reopens flows. Update those sections, add a line under **Changes** with the date and why, and leave the rest word for word.
45
+
46
+ ## The brief
47
+
48
+ ```markdown
49
+ # <Product name>
50
+
51
+ <One sentence: what it is and for whom.>
52
+
53
+ ## Problem
54
+ <What is hard or missing today, for whom, in two or three sentences. The cost of leaving it.>
55
+
56
+ ## For
57
+ <The one person it is built for first: who, their situation, what they do today instead. Others later, in one line.>
58
+
59
+ ## Flows
60
+ 1. <Verb phrase, start to end: "log a catch from the boat in under a minute">
61
+ <3–5 flows. Each is one thing someone comes to do, and how they know it worked.>
62
+
63
+ ## Key screens
64
+ - <Screen>: <what is on it, which flow it serves>
65
+ <2–4. The screens design prototypes first. No UI: "none".>
66
+
67
+ ## Surface
68
+ <site | app | no UI (CLI, API, library)>. <One line why. A site is the page a person lands on to understand or choose; an app is the tool they come back to.>
69
+
70
+ ## V1 and later
71
+ - v1: <what ships first, as flows from above>
72
+ - later: <what waits>
73
+
74
+ ## Constraints
75
+ - <What is fixed: devices, offline, languages, accessibility needs, a deadline, a budget. Not tech choices.>
76
+
77
+ ## Identity nouns
78
+ <4–8 concrete nouns from the product's world: the things, places, tools and materials its people know. "Tide, buoy, logbook, brass", not "trust, speed, simple".>
79
+
80
+ ## Out of scope
81
+ - <What it will not do, so later stages do not drift into it.>
82
+ ```
83
+
84
+ - Every section has content. "None" is an answer. A guess is not.
85
+ - **Changes** is added under Out of scope by the first Change, never before.
86
+ - Content is real: the longest names the people will type, the likely numbers, the real empty case. `design` uses them as copy.
87
+ - Over a page means a flow is really two products, or a section is doing Architecture's job. Cut it.
88
+
89
+ ## After writing
90
+
91
+ Offer the next stage in one line:
92
+
93
+ - Surface is site or app → `design-direction`.
94
+ - No UI → stages 2 and 3 are skipped. Next is Architecture: `grill-with-docs`.
95
+
96
+ Do not start it until they say so.
97
+
98
+ ## Do not
99
+
100
+ - Pick a stack, or write a requirement as one ("uses Postgres").
101
+ - Ask a question the repo or the idea already answers.
102
+ - Write the brief before they confirm the six-line summary.
103
+ - Edit the brief for a feature. Features get specs.