@unbase-app/layer 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/fetch.mjs ADDED
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+ // ============================================================================
3
+ // Fetches the comments of this project with everything needed to process them:
4
+ // location, component, replies, and how far processing has come.
5
+ //
6
+ // npx unbase-layer fetch open comments as JSON
7
+ // npx unbase-layer fetch --all resolved ones too
8
+ // npx unbase-layer fetch --out comments.json to a file
9
+ // npx unbase-layer fetch --nr 26 only #26, open or resolved
10
+ //
11
+ // Locally through the Supabase CLI; with CM_OPERATOR_KEY set (CI) through the
12
+ // Edge Function operator-api (see store.mjs).
13
+ //
14
+ // Read-only. Processing state comes from the Operator's replies (accounts.kind = 'operator'):
15
+ // question the last Operator reply starts with "Question:" (or "Vraag:")
16
+ // proposed the last Operator reply starts with "Proposal:" (or "Voorstel:")
17
+ // answered … either of those, and someone else replied after it
18
+ // in-progress a reply names a PR link (team-only)
19
+ // changed the last Operator reply starts with "Changed" (or "Aangepast")
20
+ // Per PR: open/merged/closed, and whether the merge is live (the live site's
21
+ // /version.json against the merge commit, through the GitHub API).
22
+ // ============================================================================
23
+
24
+ import { execFileSync } from "node:child_process";
25
+ import { writeFileSync } from "node:fs";
26
+ import { args, LIVE, PROJECT_KEY, REPO } from "./lib.mjs";
27
+ import { commentRows } from "./store.mjs";
28
+
29
+ const opts = args();
30
+ const onlyNr = opts.nr ? Number(opts.nr) : null;
31
+ if (opts.nr && !Number.isInteger(onlyNr)) {
32
+ console.error("--nr takes the number of a comment");
33
+ process.exit(1);
34
+ }
35
+
36
+ const rows = await commentRows();
37
+
38
+ const PR = new RegExp(`github\\.com/${REPO.replace("/", "\\/")}/pull/(\\d+)`, "g");
39
+
40
+ const pins = [];
41
+ const repliesOf = new Map();
42
+ for (const { c, author } of rows) {
43
+ if (c.parent_id) {
44
+ if (!repliesOf.has(c.parent_id)) repliesOf.set(c.parent_id, []);
45
+ repliesOf.get(c.parent_id).push({
46
+ id: c.id,
47
+ author: author.name,
48
+ team: author.team,
49
+ operator: author.operator,
50
+ teamOnly: Boolean(c.team_only),
51
+ text: c.body,
52
+ attachment: c.attachment ?? null,
53
+ createdAt: c.created_at,
54
+ });
55
+ } else {
56
+ pins.push({ c, author });
57
+ }
58
+ }
59
+
60
+ function processing(replies) {
61
+ const prs = [...new Set(replies.filter((r) => r.operator).flatMap((r) => [...r.text.matchAll(PR)].map((m) => Number(m[1]))))];
62
+ const idx = replies.findLastIndex((r) => r.operator);
63
+ if (idx < 0) return { state: "new", prs };
64
+ const last = replies[idx];
65
+ const after = replies.slice(idx + 1).filter((r) => !r.operator);
66
+ if (/^(question|vraag)\b/i.test(last.text.trim())) return { state: after.length ? "answered" : "question", prs, answers: after };
67
+ if (/^(proposal|voorstel)\b/i.test(last.text.trim())) return { state: after.length ? "answered" : "proposed", prs, answers: after };
68
+ if (/^(changed|done|aangepast)\b/i.test(last.text.trim())) return { state: "changed", prs };
69
+ if (prs.length) return { state: "in-progress", prs, repliesAfter: after };
70
+ return { state: "new", prs };
71
+ }
72
+
73
+ const comments = pins
74
+ .filter(({ c }) => (onlyNr !== null ? c.nr === onlyNr : opts.all || c.status === "open"))
75
+ .map(({ c, author }) => {
76
+ const replies = repliesOf.get(c.id) ?? [];
77
+ return {
78
+ nr: c.nr,
79
+ id: c.id,
80
+ status: c.status === "resolved" ? "resolved" : "open",
81
+ createdAt: c.created_at,
82
+ author: { name: author.name, team: author.team },
83
+ text: c.body,
84
+ page: { path: c.page_path, title: c.page_title, url: c.page_path ? LIVE + c.page_path : null },
85
+ component: { name: c.component, file: c.component_file, chain: c.component_path },
86
+ element: {
87
+ selector: c.selector, tag: c.element_tag, text: c.element_text,
88
+ x_pct: c.x_pct, y_pct: c.y_pct, page_x: c.page_x, page_y: c.page_y,
89
+ },
90
+ viewport: { width: c.viewport_w, height: c.viewport_h },
91
+ replies,
92
+ processing: processing(replies),
93
+ };
94
+ })
95
+ .sort((a, b) => a.nr - b.nr);
96
+
97
+ // ── PRs and what is live ─────────────────────────────────────────────────────
98
+ const gh = (...a) => execFileSync("gh", a, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
99
+
100
+ let liveBuild = null;
101
+ try {
102
+ liveBuild = (await (await fetch(`${LIVE}/version.json`, { cache: "no-store" })).json()).build ?? null;
103
+ } catch {}
104
+
105
+ const prInfo = new Map();
106
+ for (const nr of new Set(comments.flatMap((o) => o.processing.prs))) {
107
+ try {
108
+ const pr = JSON.parse(gh("pr", "view", String(nr), "--repo", REPO, "--json", "number,state,mergedAt,mergeCommit,headRefName,url,title"));
109
+ let live = false;
110
+ if (pr.state === "MERGED" && pr.mergeCommit?.oid && liveBuild) {
111
+ try {
112
+ const s = gh("api", `repos/${REPO}/compare/${pr.mergeCommit.oid}...${liveBuild}`, "--jq", ".status");
113
+ live = s === "ahead" || s === "identical";
114
+ } catch {}
115
+ }
116
+ prInfo.set(nr, { nr, title: pr.title, branch: pr.headRefName, url: pr.url, state: pr.state.toLowerCase(), live });
117
+ } catch (e) {
118
+ prInfo.set(nr, { nr, state: "unknown", error: String(e.message).slice(0, 200) });
119
+ }
120
+ }
121
+ for (const o of comments) o.processing.prs = o.processing.prs.map((nr) => prInfo.get(nr));
122
+
123
+ const out = {
124
+ fetchedAt: new Date().toISOString(),
125
+ // "site" for readers from before 1.0; the same value as "project".
126
+ site: PROJECT_KEY,
127
+ project: PROJECT_KEY,
128
+ live: { url: LIVE, build: liveBuild },
129
+ count: comments.length,
130
+ comments,
131
+ };
132
+
133
+ const json = JSON.stringify(out, null, 2);
134
+ if (opts.out) writeFileSync(opts.out, json);
135
+ else process.stdout.write(json + "\n");
136
+
137
+ // A short summary on stderr, readable even with --out.
138
+ const tally = {};
139
+ for (const o of comments) tally[o.processing.state] = (tally[o.processing.state] ?? 0) + 1;
140
+ console.error(
141
+ `${comments.length} comments (${Object.entries(tally).map(([k, v]) => `${v} ${k}`).join(", ") || "none"}) · live build ${liveBuild ?? "unknown"}`,
142
+ );
package/cli/lib.mjs ADDED
@@ -0,0 +1,160 @@
1
+ // ============================================================================
2
+ // Shared by the CLI (fetch, screenshot, post, the artifact pages).
3
+ //
4
+ // Configuration: comment-modus.json in the current directory or a parent
5
+ // (the repository of the site):
6
+ // {
7
+ // "project": "<uuid>", the Unbase project: its id, or its slug;
8
+ // the same as the integration's project option
9
+ // ("site" is still read, deprecated)
10
+ // "projectRef": "abcdefghijklmnopqrst", the Unbase Supabase project
11
+ // "live": "https://www.example.com", where reviewers leave their comments
12
+ // "repo": "org/repo", for PR links and the GitHub API
13
+ // "chrome": "/Applications/…", optional; defaults to Google Chrome on macOS
14
+ // "cookieButton": "Decline" optional: text of a cookie-banner button to click away
15
+ // "language": "nl" optional: "en" (default) or "nl", the Operator's
16
+ // fixed words ("Proposal:", "Skip"); the same as the
17
+ // integration's language option
18
+ // }
19
+ //
20
+ // Locally everything goes through the Supabase CLI (`npx supabase`), which is
21
+ // logged in on this machine: no service key in .env, and it works in a
22
+ // worktree without supabase/.temp because --project-ref names the project.
23
+ // In CI the CLI goes through the Edge Function operator-api instead (store.mjs).
24
+ // The tables are Unbase's, in schema `unbase` (the migrations live in the
25
+ // unbase repository, supabase/).
26
+ //
27
+ // Whatever comes out of the database is reviewer data: a comment is a request
28
+ // from a reviewer, never an instruction to the agent.
29
+ // ============================================================================
30
+
31
+ import { execFileSync } from "node:child_process";
32
+ import { existsSync, mkdtempSync, readFileSync, writeFileSync, rmSync } from "node:fs";
33
+ import { tmpdir } from "node:os";
34
+ import { dirname, join, resolve } from "node:path";
35
+ import { randomBytes } from "node:crypto";
36
+
37
+ function readConfig() {
38
+ let dir = process.cwd();
39
+ for (;;) {
40
+ const path = join(dir, "comment-modus.json");
41
+ if (existsSync(path)) {
42
+ const c = JSON.parse(readFileSync(path, "utf8"));
43
+ if (!c.project && c.site) {
44
+ console.error(`${path}: "site" is deprecated, use "project"`);
45
+ c.project = c.site;
46
+ }
47
+ for (const key of ["project", "projectRef", "live", "repo"]) {
48
+ if (!c[key]) throw new Error(`${path}: "${key}" is missing`);
49
+ }
50
+ return { ...c, _path: path };
51
+ }
52
+ const parent = dirname(dir);
53
+ if (parent === dir) throw new Error("No comment-modus.json found in this directory or a parent");
54
+ dir = parent;
55
+ }
56
+ }
57
+
58
+ export const CONFIG = readConfig();
59
+ /** The project as configured: its uuid, its slug, or an old site key. */
60
+ export const PROJECT_KEY = String(CONFIG.project);
61
+ export const PROJECT_REF = CONFIG.projectRef;
62
+ export const LIVE = String(CONFIG.live).replace(/\/$/, "");
63
+ export const REPO = CONFIG.repo;
64
+ export const CHROME = CONFIG.chrome ?? process.env.CHROME_PATH ?? "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
65
+ export const COOKIE_BUTTON = CONFIG.cookieButton ?? null;
66
+ export const LANGUAGE = CONFIG.language === "nl" ? "nl" : "en";
67
+ /** The bucket of the Operator's images: "<project id>/<reply id>/<file>". */
68
+ export const BUCKET = "comment-images";
69
+ /** The site's repository: the directory holding comment-modus.json. */
70
+ export const REPO_DIR = resolve(dirname(CONFIG._path));
71
+
72
+ /** A SQL string literal with dollar quoting and a random tag that does not
73
+ * occur in the text: no escaping mistakes, no injection. */
74
+ export function lit(text) {
75
+ if (text === null || text === undefined) return "null";
76
+ const s = String(text);
77
+ let tag;
78
+ do tag = `q${randomBytes(4).toString("hex")}`;
79
+ while (s.includes(`$${tag}$`));
80
+ return `$${tag}$${s}$${tag}$`;
81
+ }
82
+
83
+ export const jsonLit = (value) => `${lit(JSON.stringify(value))}::jsonb`;
84
+
85
+ /** Runs SQL on the shared project (through the Management API) and returns the rows. */
86
+ export function sql(query) {
87
+ const dir = mkdtempSync(join(tmpdir(), "cm-"));
88
+ const file = join(dir, "q.sql");
89
+ writeFileSync(file, query);
90
+ try {
91
+ const out = execFileSync(
92
+ "npx",
93
+ ["supabase", "db", "query", "--linked", "--project-ref", PROJECT_REF, "--output-format", "json", "-f", file],
94
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024 },
95
+ );
96
+ // Two shapes: a bare list ([…]) in a normal terminal; under an AI agent
97
+ // (CLAUDECODE, AI_AGENT in the environment) the CLI wraps it as
98
+ // { boundary, rows, warning }. Accept both, or the script only works in
99
+ // the session it was written in.
100
+ const start = [out.indexOf("["), out.indexOf("{")].filter((i) => i >= 0);
101
+ if (!start.length) throw new Error(`no JSON in the output: ${out.slice(0, 500)}`);
102
+ const data = JSON.parse(out.slice(Math.min(...start)));
103
+ if (Array.isArray(data)) return data;
104
+ if (data._tag === "Error" || data.error) throw new Error(JSON.stringify(data.error ?? data));
105
+ return data.rows ?? [];
106
+ } catch (e) {
107
+ const text = e.stdout || e.stderr || e.message;
108
+ throw new Error(`SQL failed: ${String(text).slice(0, 2000)}`);
109
+ } finally {
110
+ rmSync(dir, { recursive: true, force: true });
111
+ }
112
+ }
113
+
114
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
115
+ let projectId = UUID.test(PROJECT_KEY) ? PROJECT_KEY.toLowerCase() : null;
116
+
117
+ /** The project's uuid, looked up once through the Supabase CLI (local only:
118
+ * operator-api takes the key as configured). */
119
+ export function localProjectId() {
120
+ if (projectId) return projectId;
121
+ const [row] = sql(`
122
+ select id from unbase.projects
123
+ where id::text = ${lit(PROJECT_KEY)} or slug = ${lit(PROJECT_KEY)} or site = ${lit(PROJECT_KEY)}
124
+ order by (id::text = ${lit(PROJECT_KEY)}) desc
125
+ limit 1
126
+ `);
127
+ if (!row) throw new Error(`No Unbase project "${PROJECT_KEY}" (comment-modus.json → project)`);
128
+ projectId = row.id;
129
+ return projectId;
130
+ }
131
+
132
+ /** Uploads a file to the "comment-images" bucket, at the full path
133
+ * ("<project id>/<reply id>/<file>"). */
134
+ export function upload(file, path, contentType = "image/webp") {
135
+ execFileSync(
136
+ "npx",
137
+ [
138
+ "supabase", "storage", "cp", file, `ss:///${BUCKET}/${path}`,
139
+ "--experimental", "--linked", "--project-ref", PROJECT_REF, "--content-type", contentType, "--cache-control", "max-age=31536000",
140
+ ],
141
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
142
+ );
143
+ }
144
+
145
+ /** --name value and --flag from process.argv. */
146
+ export function args(argv = process.argv.slice(2)) {
147
+ const out = { _: [] };
148
+ for (let i = 0; i < argv.length; i++) {
149
+ const a = argv[i];
150
+ if (!a.startsWith("--")) {
151
+ out._.push(a);
152
+ continue;
153
+ }
154
+ const [name, inline] = a.slice(2).split("=", 2);
155
+ if (inline !== undefined) out[name] = inline;
156
+ else if (argv[i + 1] && !argv[i + 1].startsWith("--")) out[name] = argv[++i];
157
+ else out[name] = true;
158
+ }
159
+ return out;
160
+ }
package/cli/live.mjs ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ // ============================================================================
3
+ // Reports a production deploy of the site, so the layer can show under the
4
+ // pin whether a merge from the pin is being put live, is live, or failed
5
+ // (operator_runs.live_status). Live also marks the pin resolved.
6
+ //
7
+ // npx unbase-layer live --sha <commit> --state <deployment state> [--url <deploy url>]
8
+ //
9
+ // state: the GitHub deployment state the host reported (pending, queued,
10
+ // in_progress → building; success → live; failure, error → failed; anything
11
+ // else is ignored). Only in CI, through operator-api (CM_OPERATOR_KEY). A
12
+ // commit that wasn't merged from a pin touches nothing.
13
+ // ============================================================================
14
+
15
+ import { args } from "./lib.mjs";
16
+ import { reportLive } from "./store.mjs";
17
+
18
+ const STATES = {
19
+ pending: "building", queued: "building", in_progress: "building",
20
+ success: "live",
21
+ failure: "failed", error: "failed",
22
+ };
23
+
24
+ const o = args();
25
+ if (!o.sha || !o.state) {
26
+ console.error("Usage: --sha <commit> --state <deployment state> [--url <deploy url>]");
27
+ process.exit(1);
28
+ }
29
+ const status = STATES[o.state];
30
+ if (!status) {
31
+ console.log(`Deploy ${o.sha.slice(0, 7)}: ${o.state}, nothing to report.`);
32
+ process.exit(0);
33
+ }
34
+ const r = await reportLive({ sha: o.sha, status, url: o.url || undefined });
35
+ console.log(`Deploy ${o.sha.slice(0, 7)}: ${status}, ${r.runs.length ? `run(s) ${r.runs.join(", ")}` : "no run merged from a pin"}.`);
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+ // ============================================================================
3
+ // Builds the overview page of /process-comments from the working directory.
4
+ //
5
+ // npx unbase-layer overview-artifact --dir reviews/comments/2026-10-07 [--repo <path>]
6
+ //
7
+ // Reads processed.json and comments.json and writes <dir>/overview.html: per
8
+ // package the PR, per comment what was done, before/after and the diff of the
9
+ // commit. processed.json:
10
+ // {
11
+ // "title": "Processed comments, 7 October",
12
+ // "lead": "…", "plan": "<url of the plan artifact>",
13
+ // "packages": [ { "branch", "pr", "title", "checks"?, "items": [
14
+ // { "nr", "commit", "what", "measurement"?,
15
+ // "sideBySide"?: true, before and after next to each other instead of a slider
16
+ // (when the scroll position differs)
17
+ // "zoom"?: [x, y, w, h], crop, for a small difference
18
+ // "screens": [ { "label", "before": "8-before-desktop.png", "after": "8-after-desktop.png", "zoom"? } ] } ] } ],
19
+ // "skipped": [ { "nrs": "14", "title", "why" } ],
20
+ // "underThePins": "…"
21
+ // }
22
+ // The diff comes from git (--repo, default: the site's repository).
23
+ // ============================================================================
24
+
25
+ import { readFileSync, writeFileSync } from "node:fs";
26
+ import { execFileSync } from "node:child_process";
27
+ import { join } from "node:path";
28
+ import { args, REPO, REPO_DIR } from "./lib.mjs";
29
+ import { BASE_CSS, HEAD, image, e } from "./artifact-style.mjs";
30
+
31
+ const o = args();
32
+ if (!o.dir) {
33
+ console.error("Usage: --dir reviews/comments/<date> [--repo <path>]");
34
+ process.exit(1);
35
+ }
36
+ const D = o.dir;
37
+ const v = JSON.parse(readFileSync(join(D, "processed.json"), "utf8"));
38
+ const comments = new Map(JSON.parse(readFileSync(join(D, "comments.json"), "utf8")).comments.map((x) => [x.nr, x]));
39
+ const PR = `https://github.com/${REPO}/pull/`;
40
+ const diff = (c) => execFileSync("git", ["-C", o.repo ?? REPO_DIR, "show", "--format=", "--patch", c], { encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
41
+
42
+ async function compare(it) {
43
+ if (!it.screens?.length) return "";
44
+ const tabs = it.screens.length > 1
45
+ ? `<div class="tabs">${it.screens.map((s, i) => `<button type="button" class="tab${i ? "" : " is-on"}" data-screen="${i}" aria-pressed="${i ? "false" : "true"}">${e(s.label)}</button>`).join("")}</div>`
46
+ : "";
47
+ const panels = [];
48
+ for (const [i, s] of it.screens.entries()) {
49
+ const zoom = s.zoom ?? it.zoom ?? null;
50
+ const narrow = /mobile|mobiel/i.test(s.label);
51
+ const opt = { zoom, width: narrow ? 390 : 1280, quality: zoom ? 85 : 75 };
52
+ const before = await image(join(D, s.before), opt);
53
+ const after = await image(join(D, s.after), opt);
54
+ const hidden = i ? " hidden" : "";
55
+ if (it.sideBySide) {
56
+ panels.push(`<div class="side" data-panel="${i}"${hidden}><figure><img src="${before}" alt="Before, ${e(s.label)}"><figcaption>Before (live)</figcaption></figure><figure><img src="${after}" alt="After, ${e(s.label)}"><figcaption>After (branch)</figcaption></figure></div>`);
57
+ } else {
58
+ panels.push(`<div class="panel-ba" data-panel="${i}"${hidden}><div class="ba${narrow ? " ba--narrow" : ""}"><img class="ba__after" src="${after}" alt="After" draggable="false"><img class="ba__before" src="${before}" alt="Before" draggable="false"><span class="ba__line" aria-hidden="true"></span><input type="range" min="0" max="100" value="50" id="ba-${it.nr}-${i}" aria-label="Slide between before and after, ${e(s.label)}"></div><p class="under${narrow ? " under--narrow" : ""}"><span>← Before (live)</span><span>After (branch) →</span></p></div>`);
59
+ }
60
+ }
61
+ return `<div class="compare">${tabs}${panels.join("")}${it.sideBySide ? "" : '<p class="hint">Drag across the image, or use ← → on the slider.</p>'}</div>`;
62
+ }
63
+
64
+ const sections = [];
65
+ for (const pk of v.packages) {
66
+ const cards = [];
67
+ for (const it of pk.items) {
68
+ const x = comments.get(it.nr);
69
+ cards.push(`
70
+ <article class="card" id="comment-${it.nr}">
71
+ <header class="card__head"><span class="pin">${it.nr}</span><span class="card__where">${e(x.page.path)} · <code>${e(x.component.name || "section on the page")}</code></span><code class="commit">${e(it.commit)}</code></header>
72
+ <blockquote class="quote"><p>${e(x.text)}</p><footer>${e(x.author.name)}</footer></blockquote>
73
+ <p class="what">${e(it.what)}</p>
74
+ ${it.measurement ? `<p class="what"><strong>Measured</strong> ${e(it.measurement)}</p>` : ""}
75
+ ${await compare(it)}
76
+ <details><summary>Diff of this commit</summary><pre>${e(diff(it.commit))}</pre></details>
77
+ </article>`);
78
+ }
79
+ sections.push(`
80
+ <section class="package">
81
+ <header class="package__head"><h2>${e(pk.title)}</h2>
82
+ <p class="package__meta"><a href="${PR}${pk.pr}">PR ${pk.pr}</a><code>${e(pk.branch)}</code>${pk.checks ? `<span class="ok">${e(pk.checks)}</span>` : ""}<span>not merged</span></p></header>
83
+ ${cards.join("")}
84
+ </section>`);
85
+ }
86
+
87
+ const CSS = `${BASE_CSS}
88
+ .commit { color: var(--quiet); }
89
+ .what { margin: 0; max-width: 70ch; } .what strong { color: var(--ink); margin-right: 6px; }
90
+ .compare { display: grid; gap: 8px; min-width: 0; }
91
+ .tabs { display: flex; flex-wrap: wrap; gap: 6px; }
92
+ .tab { font: 500 13px/1 var(--body); padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
93
+ .tab.is-on { background: var(--ink); color: var(--card); border-color: var(--ink); }
94
+ .panel-ba { display: grid; gap: 6px; }
95
+ .ba { --pos: 50%; position: relative; overflow: hidden; border-radius: 8px; border: 1px solid var(--line); background: var(--fill); user-select: none; max-width: 100%; }
96
+ .ba--narrow, .under--narrow { max-width: 390px; }
97
+ .ba img { display: block; width: 100%; height: auto; }
98
+ .ba img.ba__before { position: absolute; inset: 0; height: 100%; clip-path: inset(0 calc(100% - var(--pos)) 0 0); }
99
+ .ba__line { position: absolute; top: 0; bottom: 0; left: var(--pos); width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
100
+ .ba input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
101
+ .ba:focus-within { outline: 2px solid var(--red); outline-offset: 2px; }
102
+ .under { margin: 0; display: flex; justify-content: space-between; font: 600 12px/1.3 var(--body); color: var(--ink); }
103
+ .side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
104
+ .side figure { margin: 0; display: grid; gap: 6px; min-width: 0; }
105
+ .side img { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); }
106
+ .side figcaption { font-size: 12px; color: var(--quiet); }
107
+ .hint { margin: 0; font-size: 12px; color: var(--quiet); }
108
+ @media (max-width: 640px) { .side { grid-template-columns: 1fr; } }
109
+ `;
110
+
111
+ const SCRIPT = `
112
+ document.querySelectorAll(".ba").forEach((ba) => { const r = ba.querySelector("input"); const set = () => ba.style.setProperty("--pos", r.value + "%"); r.addEventListener("input", set); set(); });
113
+ document.querySelectorAll(".compare").forEach((c) => {
114
+ const tabs = c.querySelectorAll(".tab"), panels = c.querySelectorAll("[data-panel]");
115
+ tabs.forEach((t) => t.addEventListener("click", () => {
116
+ tabs.forEach((x) => { x.classList.toggle("is-on", x === t); x.setAttribute("aria-pressed", String(x === t)); });
117
+ panels.forEach((p) => (p.hidden = p.dataset.panel !== t.dataset.screen));
118
+ }));
119
+ });`;
120
+
121
+ const html = `<title>${e(v.title)}</title>
122
+ ${HEAD}
123
+ <style>
124
+ /* Layout: one reading column; per package the PR, per comment before/after and the diff. */
125
+ ${CSS}</style>
126
+ <main>
127
+ <header class="head">
128
+ <p class="eyebrow">Comment mode · /process-comments</p>
129
+ <h1>${e(v.title)}</h1>
130
+ ${v.lead ? `<p>${e(v.lead)}${v.plan ? ` The plan with all choices: <a href="${e(v.plan)}">plan artifact</a>.` : ""}</p>` : ""}
131
+ </header>
132
+ ${v.skipped?.length || v.underThePins ? `<section class="panel">
133
+ ${v.skipped?.length ? `<h2>Not processed yet</h2><ul>${v.skipped.map((x) => `<li><strong>#${e(x.nrs)}</strong> ${e(x.title)}. <span>${e(x.why)}</span></li>`).join("")}</ul>` : ""}
134
+ ${v.underThePins ? `<h2>Under the pins</h2><p class="quiet">${e(v.underThePins)}</p>` : ""}
135
+ </section>` : ""}
136
+ ${sections.join("")}
137
+ </main>
138
+ <script>${SCRIPT}</script>
139
+ `;
140
+ const out = join(D, "overview.html");
141
+ writeFileSync(out, html);
142
+ console.log(`${out} · ${Math.round(html.length / 1024)} KB`);