codechart 0.5.0 → 0.7.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/dist/cli.js CHANGED
@@ -618,9 +618,9 @@ function gitParent(cwd, sha) {
618
618
  function gitEmptyTree(cwd) {
619
619
  return git(cwd, ["hash-object", "-t", "tree", "--stdin"], { input: "" }).trim();
620
620
  }
621
- function gitMergeBase(cwd, base, head = "HEAD") {
621
+ function gitMergeBase(cwd, base, head2 = "HEAD") {
622
622
  checkRef("--since", base);
623
- return git(cwd, ["merge-base", base, head]).trim();
623
+ return git(cwd, ["merge-base", base, head2]).trim();
624
624
  }
625
625
  function gitBlobSizes(cwd, specs) {
626
626
  if (!specs.length) return [];
@@ -667,6 +667,17 @@ var diffArgs = (range, paths) => [
667
667
  function gitFileDiff(cwd, range, rel, maxBytes) {
668
668
  return git(cwd, diffArgs(range, [rel]), { config: [["core.bigFileThreshold", "5m"], ...range.config], maxBuffer: maxBytes });
669
669
  }
670
+ function gitGeneratedAttr(cwd, rels) {
671
+ const out = /* @__PURE__ */ new Map();
672
+ if (!rels.length) return out;
673
+ const parts = git(cwd, ["check-attr", "-z", "--stdin", "linguist-generated"], { input: rels.map((r) => `${r}\0`).join("") }).split("\0");
674
+ for (let i = 0; i + 2 < parts.length; i += 3) {
675
+ const value = parts[i + 2];
676
+ if (value === "unspecified") continue;
677
+ out.set(parts[i], value !== "unset" && value !== "false");
678
+ }
679
+ return out;
680
+ }
670
681
  var CHUNK_PATHS = 500;
671
682
  var CHUNK_CHARS = 2e4;
672
683
  function chunks(paths) {
@@ -699,10 +710,10 @@ function gitFileDiffs(cwd, range, rels, maxBytes) {
699
710
  for (const [i, start] of starts.entries()) {
700
711
  const end = starts[i + 1] ?? text.length;
701
712
  const eol = text.indexOf("\n", start);
702
- const head = text.slice(start + "diff --git ".length, eol < 0 ? end : eol);
703
- const len = (head.length - "a/ b/".length) / 2;
704
- const rel = head.slice("a/".length, "a/".length + len);
705
- if (!Number.isInteger(len) || head !== `a/${rel} b/${rel}` || !wanted.has(rel)) return void 0;
713
+ const head2 = text.slice(start + "diff --git ".length, eol < 0 ? end : eol);
714
+ const len = (head2.length - "a/ b/".length) / 2;
715
+ const rel = head2.slice("a/".length, "a/".length + len);
716
+ if (!Number.isInteger(len) || head2 !== `a/${rel} b/${rel}` || !wanted.has(rel)) return void 0;
706
717
  out.set(rel, (out.get(rel) ?? "") + text.slice(start, end));
707
718
  }
708
719
  }
@@ -728,10 +739,10 @@ function gitCommitFiles(cwd, ref) {
728
739
  if (!parent) return nulList(git(cwd, ["diff-tree", "-r", "--root", "--no-commit-id", "--name-only", "-z", sha]));
729
740
  return nulList(git(cwd, ["diff", "--no-renames", "--name-only", "-z", parent, sha, "--"]));
730
741
  }
731
- function gitSinceFiles(cwd, base, head = "HEAD") {
742
+ function gitSinceFiles(cwd, base, head2 = "HEAD") {
732
743
  checkRef("--since", base);
733
- checkRef("--head", head);
734
- return nulList(git(cwd, ["diff", "--no-renames", "--name-only", "-z", `${base}...${head}`, "--"]));
744
+ checkRef("--head", head2);
745
+ return nulList(git(cwd, ["diff", "--no-renames", "--name-only", "-z", `${base}...${head2}`, "--"]));
735
746
  }
736
747
  function gitListFiles(cwd, sha) {
737
748
  return nulList(
@@ -799,8 +810,8 @@ function diffRange(root, o) {
799
810
  return { args: [parent, sha], revs: [parent, sha], worktree: false, config };
800
811
  }
801
812
  if (o.since !== void 0 && !o.git) {
802
- const head = resolveCommit(root, "--head", o.head ?? "HEAD");
803
- return { args: [`${o.since}...${head}`], revs: [gitMergeBase(root, o.since, head), head], worktree: false, config };
813
+ const head2 = resolveCommit(root, "--head", o.head ?? "HEAD");
814
+ return { args: [`${o.since}...${head2}`], revs: [gitMergeBase(root, o.since, head2), head2], worktree: false, config };
804
815
  }
805
816
  const from = o.since !== void 0 ? gitMergeBase(root, o.since) : gitHead(root) ?? gitEmptyTree(root);
806
817
  return { args: [from], revs: [from], worktree: true, config: [...config, ...repoFilterOverrides(root)] };
@@ -907,10 +918,10 @@ function renderPieces(pieces) {
907
918
  }
908
919
  return merged.map((p) => p.item?.paint ? p.item.paint(p.text) : p.text).join("");
909
920
  }
910
- function wrapItems(head, items2, width) {
911
- const indent = " ".repeat(columns(head));
921
+ function wrapItems(head2, items2, width) {
922
+ const indent = " ".repeat(columns(head2));
912
923
  const lines = [];
913
- let line = [{ text: head }];
924
+ let line = [{ text: head2 }];
914
925
  let fresh = true;
915
926
  const room = () => width - line.reduce((n, p) => n + columns(p.text), 0);
916
927
  const append = (text, item) => {
@@ -1100,7 +1111,7 @@ function privateDir(dir) {
1100
1111
  async function writeHtml(build, o) {
1101
1112
  const { config, now } = o;
1102
1113
  const file = htmlOutputPath(config, repoFolder(o.root), o.slug, now);
1103
- const html = await build({ generatedAt: now, repo: basename2(o.root), repoKey: repoFolder(o.root), theme: o.theme, ...o.update && { update: o.update } });
1114
+ const html = await build({ generatedAt: now, repo: basename2(o.root), repoKey: repoFolder(o.root), theme: o.theme, ...o.update && { update: o.update, updateNotes: o.updateNotes } });
1104
1115
  const dir = dirname3(file);
1105
1116
  privateDir(dir);
1106
1117
  writeFileSync(file, html, { mode: 384 });
@@ -1113,13 +1124,65 @@ async function writeHtml(build, o) {
1113
1124
  return { file, openFailed: Boolean(failed) };
1114
1125
  }
1115
1126
 
1127
+ // src/update/changelog.ts
1128
+ var NOTES_URL = "https://github.com/freeleex/codechart/blob/main/CHANGELOG.md";
1129
+ var RAW = "https://raw.githubusercontent.com/freeleex/codechart";
1130
+ var VERSION = /^\d+\.\d+\.\d+$/;
1131
+ var MAX_BYTES2 = 256 * 1024;
1132
+ var MAX_CHARS = 200;
1133
+ function parseChangelog(md2) {
1134
+ const releases = [];
1135
+ for (const line of md2.split(/\r?\n/)) {
1136
+ const heading = /^## (\d+\.\d+\.\d+)(?:\s|$)/.exec(line);
1137
+ if (heading) releases.push({ version: heading[1], bullets: [] });
1138
+ else if (line.startsWith("- ") && releases.length) releases.at(-1).bullets.push(line.slice(2).trim());
1139
+ }
1140
+ return releases;
1141
+ }
1142
+ function cleanBullet(s) {
1143
+ const text = stripInvisible(s).replace(/[\u0000-\u001f\u007f-\u009f]/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
1144
+ const chars = [...text];
1145
+ return chars.length > MAX_CHARS ? `${chars.slice(0, MAX_CHARS - 1).join("")}\u2026` : text;
1146
+ }
1147
+ function highlights(md2, current, latest, max = 5) {
1148
+ const all = parseChangelog(md2).filter((r) => isNewer(r.version, current) && !isNewer(r.version, latest)).sort((a, b) => isNewer(a.version, b.version) ? -1 : 1).flatMap((r) => r.bullets.map(cleanBullet)).filter(Boolean);
1149
+ return { bullets: all.slice(0, max), more: all.length > max };
1150
+ }
1151
+ async function readCapped(body) {
1152
+ const chunks2 = [];
1153
+ let size = 0;
1154
+ for await (const chunk of body) {
1155
+ size += chunk.byteLength;
1156
+ if (size > MAX_BYTES2) return void 0;
1157
+ chunks2.push(chunk);
1158
+ }
1159
+ return Buffer.concat(chunks2).toString("utf8");
1160
+ }
1161
+ async function fetchHighlights(fetchFn, current, latest, timeoutMs) {
1162
+ if (!VERSION.test(latest)) return void 0;
1163
+ try {
1164
+ const res = await fetchFn(`${RAW}/v${latest}/CHANGELOG.md`, { signal: AbortSignal.timeout(timeoutMs) });
1165
+ if (!res.ok || !res.body || Number(res.headers.get("content-length")) > MAX_BYTES2) return void 0;
1166
+ const md2 = await readCapped(res.body);
1167
+ if (md2 === void 0) return void 0;
1168
+ const found = highlights(md2, current, latest);
1169
+ return found.bullets.length ? found : void 0;
1170
+ } catch {
1171
+ return void 0;
1172
+ }
1173
+ }
1174
+ function notesLines(h) {
1175
+ if (!h?.bullets.length) return [];
1176
+ return [...h.bullets.map((b) => ` - ${b}`), ...h.more ? [" - \u2026and more"] : [], ` all notes: ${NOTES_URL}`];
1177
+ }
1178
+
1116
1179
  // src/update/check.ts
1117
1180
  var REGISTRY = "https://registry.npmjs.org/codechart/latest";
1118
1181
  var DAY = 24 * 60 * 60 * 1e3;
1119
- var VERSION = /^\d+\.\d+\.\d+$/;
1182
+ var VERSION2 = /^\d+\.\d+\.\d+$/;
1120
1183
  var currentVersion = () => JSON.parse(readFileSync(packageFile("package.json"), "utf8")).version;
1121
1184
  function isNewer(a, b) {
1122
- if (!VERSION.test(a) || !VERSION.test(b)) return false;
1185
+ if (!VERSION2.test(a) || !VERSION2.test(b)) return false;
1123
1186
  const [x, y] = [a, b].map((v) => v.split(".").map(Number));
1124
1187
  for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i];
1125
1188
  return false;
@@ -1129,7 +1192,7 @@ async function fetchLatest(fetchFn, timeoutMs) {
1129
1192
  const res = await fetchFn(REGISTRY, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
1130
1193
  if (!res.ok) return void 0;
1131
1194
  const version = (await res.json()).version;
1132
- return typeof version === "string" && VERSION.test(version) ? version : void 0;
1195
+ return typeof version === "string" && VERSION2.test(version) ? version : void 0;
1133
1196
  } catch {
1134
1197
  return void 0;
1135
1198
  }
@@ -1156,6 +1219,13 @@ function rememberSkillDir(cacheDir, dir) {
1156
1219
  const dirs = skillDirs(state);
1157
1220
  if (!dirs.includes(dir)) writeState(cacheDir, { ...state, skillDirs: [...dirs, dir] });
1158
1221
  }
1222
+ var span = (from, to) => `${from}..${to}`;
1223
+ function knownHighlights(state, from, to) {
1224
+ if (state.highlightsFor !== span(from, to) || !Array.isArray(state.highlights)) return void 0;
1225
+ const bullets = state.highlights.filter((b) => typeof b === "string").map(cleanBullet).filter(Boolean).slice(0, 5);
1226
+ return bullets.length ? { bullets, more: state.highlightsMore === true } : void 0;
1227
+ }
1228
+ var withHighlights = (state, from, to, h) => h ? { ...state, highlights: h.bullets, highlightsMore: h.more, highlightsFor: span(from, to) } : state;
1159
1229
  function knownUpdate(cacheDir, current = currentVersion()) {
1160
1230
  const { latest } = readState(cacheDir);
1161
1231
  return latest && isNewer(latest, current) ? latest : void 0;
@@ -1167,19 +1237,20 @@ function checkAllowed(c, installPath = packageFile("")) {
1167
1237
  async function updateNotice(c) {
1168
1238
  if (!checkAllowed(c)) return void 0;
1169
1239
  const state = readState(c.cacheDir);
1240
+ const current = c.current ?? currentVersion();
1170
1241
  let changed = false;
1171
1242
  if (!state.checkedAt || c.now - state.checkedAt >= DAY) {
1172
1243
  changed = true;
1173
1244
  const latest = await fetchLatest(c.fetch, 1e3);
1174
1245
  Object.assign(state, { checkedAt: c.now }, latest ? { latest } : {});
1246
+ if (latest && isNewer(latest, current) && !knownHighlights(state, current, latest)) Object.assign(state, withHighlights(state, current, latest, await fetchHighlights(c.fetch, current, latest, 1e3)));
1175
1247
  }
1176
- const current = c.current ?? currentVersion();
1177
1248
  const told = c.terminal ? "toldTerminal" : "toldAgent";
1178
1249
  let line;
1179
1250
  if (state.latest && isNewer(state.latest, current) && c.now - (state[told] ?? 0) >= DAY) {
1180
1251
  state[told] = c.now;
1181
1252
  changed = true;
1182
- line = c.terminal ? `codechart ${state.latest} is available (you have ${current}): run codechart update` : `codechart ${state.latest} is available (you have ${current}). Tell the user once: run \`codechart update\`.`;
1253
+ line = c.terminal ? [`codechart ${state.latest} is available (you have ${current}): run codechart update`, ...notesLines(knownHighlights(state, current, state.latest))].join("\n") : `codechart ${state.latest} is available (you have ${current}). Tell the user once: run \`codechart update\`.`;
1183
1254
  }
1184
1255
  if (changed) writeState(c.cacheDir, state);
1185
1256
  return line;
@@ -1532,8 +1603,8 @@ function pickerLines(title, items2, s, width = Infinity) {
1532
1603
  return [
1533
1604
  cut(title, width),
1534
1605
  ...items2.map((it, i) => {
1535
- const head = cut(`${i === s.cursor ? "\u276F" : " "} ${s.checked[i] ? "\u25C9" : "\u25EF"} ${it.label.padEnd(pad2)} `, width);
1536
- return head + dim(cut(it.hint, width - head.length));
1606
+ const head2 = cut(`${i === s.cursor ? "\u276F" : " "} ${s.checked[i] ? "\u25C9" : "\u25EF"} ${it.label.padEnd(pad2)} `, width);
1607
+ return head2 + dim(cut(it.hint, width - head2.length));
1537
1608
  }),
1538
1609
  dim(cut("\u2191/\u2193 move \xB7 Space toggle \xB7 a all \xB7 Enter confirm \xB7 Esc cancel", width))
1539
1610
  ];
@@ -1703,7 +1774,6 @@ import { existsSync as existsSync7, realpathSync as realpathSync3 } from "fs";
1703
1774
  import { homedir as homedir3 } from "os";
1704
1775
  import { dirname as dirname6, join as join12, resolve as resolve4, sep as sep2 } from "path";
1705
1776
  import { Command as Command4 } from "commander";
1706
- var RELEASES = "https://github.com/freeleex/codechart/releases";
1707
1777
  var spawnOptions = (command, platform = process.platform) => platform === "win32" && command === "npm" ? { shell: true, cwd: dirname6(process.execPath) } : { shell: false };
1708
1778
  var binary = (command) => command === "codechart" ? [process.execPath, [process.argv[1]]] : [command, []];
1709
1779
  var defaultRunner = {
@@ -1759,7 +1829,9 @@ async function update(o, opts, runner) {
1759
1829
  const latest = await fetchLatest(opts.fetch ?? fetch, 1e4);
1760
1830
  if (!latest) throw new Error("couldn't reach the npm registry to look up the newest version");
1761
1831
  const cacheDir = cacheDirOf(opts);
1762
- writeState(cacheDir, { ...readState(cacheDir), checkedAt: opts.now?.().getTime() ?? Date.now(), latest });
1832
+ const state = { ...readState(cacheDir), checkedAt: opts.now?.().getTime() ?? Date.now(), latest };
1833
+ const notes = isNewer(latest, current) ? await fetchHighlights(opts.fetch ?? fetch, current, latest, 1e4) : void 0;
1834
+ writeState(cacheDir, withHighlights(state, current, latest, notes));
1763
1835
  if (!isNewer(latest, current)) {
1764
1836
  opts.stdout(`codechart ${current} is the newest version.
1765
1837
  `);
@@ -1767,7 +1839,7 @@ async function update(o, opts, runner) {
1767
1839
  return;
1768
1840
  }
1769
1841
  if (o.check) {
1770
- opts.stdout(`codechart ${latest} is available (you have ${current}): run codechart update
1842
+ opts.stdout(`${[`codechart ${latest} is available (you have ${current}): run codechart update`, ...notesLines(notes)].join("\n")}
1771
1843
  `);
1772
1844
  return;
1773
1845
  }
@@ -1779,15 +1851,16 @@ async function update(o, opts, runner) {
1779
1851
  }
1780
1852
  const how = installedBy(packageFile(""), npmRoot);
1781
1853
  if (!how.npm) {
1782
- opts.stdout(`codechart ${latest} is available (you have ${current}), but ${how.hint}.
1854
+ opts.stdout(`${[`codechart ${latest} is available (you have ${current}), but ${how.hint}.`, ...notesLines(notes)].join("\n")}
1783
1855
  `);
1784
1856
  return;
1785
1857
  }
1786
- opts.stdout(`Updating codechart ${current} \u2192 ${latest}: npm install -g codechart@${latest}
1858
+ const lines = [`Updating codechart ${current} \u2192 ${latest}: npm install -g codechart@${latest}`, ...notesLines(notes)];
1859
+ opts.stdout(`${lines.join("\n")}
1787
1860
  `);
1788
1861
  runner.show("npm", ["install", "-g", `codechart@${latest}`]);
1789
1862
  runner.show("codechart", ["update", "--skills-only"]);
1790
- opts.stdout(`codechart ${latest} installed. What changed: ${RELEASES}
1863
+ opts.stdout(`codechart ${latest} installed. What changed: ${NOTES_URL}
1791
1864
  `);
1792
1865
  }
1793
1866
  async function runUpdate(o, opts) {
@@ -2003,7 +2076,7 @@ function prune(dir, now) {
2003
2076
  if (st.isFile() && now - st.mtimeMs > KEEP_DAYS * 864e5) unlinkSync3(p);
2004
2077
  }
2005
2078
  }
2006
- var nudge = (count) => `This turn changed ${count} files and your reply has no codechart diagram. Unless the user said no diagram, follow the codechart skill now (check, then render) and reply with what it prints; if it says no diagram applies, stop without mentioning it.`;
2079
+ var nudge = (count2) => `This turn changed ${count2} files and your reply has no codechart diagram. Unless the user said no diagram, follow the codechart skill now (check, then render) and reply with what it prints; if it says no diagram applies, stop without mentioning it.`;
2007
2080
  function saveSnapshot(dir, file, root, now) {
2008
2081
  const snap = snapshot(root);
2009
2082
  mkdirSync4(dir, { recursive: true, mode: 448 });
@@ -2335,11 +2408,11 @@ function checkTag(c) {
2335
2408
  const total = c.unit === "node" ? String(c.checked) : units(c.checked, c.unit);
2336
2409
  return ` \xB7 \u2713 ${c.mismatches.length ? `${c.checked - c.mismatches.length} of ` : ""}${total} checked${unchecked}`;
2337
2410
  }
2338
- function itemsLine(head, all, width) {
2411
+ function itemsLine(head2, all, width) {
2339
2412
  const items2 = all.slice(0, MAX_SHOWN);
2340
2413
  if (all.length > MAX_SHOWN) items2.push(`+${all.length - MAX_SHOWN} more`);
2341
- if (columns(head) <= width / 2) return wrapItems(head, items2, width);
2342
- return `${truncate(head.trimEnd(), width)}
2414
+ if (columns(head2) <= width / 2) return wrapItems(head2, items2, width);
2415
+ return `${truncate(head2.trimEnd(), width)}
2343
2416
  ${wrapItems(" ", items2, width)}`;
2344
2417
  }
2345
2418
  function alertLine(c, width) {
@@ -2353,14 +2426,14 @@ function alertLine(c, width) {
2353
2426
  function webAlert(c, width) {
2354
2427
  return [alertLine(c, width), c?.diffUnchecked ? UNCHECKED : ""].filter(Boolean).join("\n");
2355
2428
  }
2356
- function countLines(counts, c, width) {
2429
+ function countLines(counts2, c, width) {
2357
2430
  const tag2 = checkTag(c);
2358
- if (columns(counts + tag2) <= width) return counts + tag2;
2359
- if (!tag2) return truncate(counts, width);
2431
+ if (columns(counts2 + tag2) <= width) return counts2 + tag2;
2432
+ if (!tag2) return truncate(counts2, width);
2360
2433
  const parts = tag2.replace(/^ · /, "").split(" \xB7 ");
2361
2434
  const joined = parts.join(" \xB7 ");
2362
2435
  const rest = columns(joined) <= width ? [joined] : parts.map((p) => truncate(p, width));
2363
- return [truncate(counts, width), ...rest].join("\n");
2436
+ return [truncate(counts2, width), ...rest].join("\n");
2364
2437
  }
2365
2438
  function checkHeadline(c) {
2366
2439
  if (!c) return "";
@@ -2387,11 +2460,11 @@ var gutter = (status) => `${marker(status) || " "} `;
2387
2460
  import { createHash as createHash2 } from "crypto";
2388
2461
 
2389
2462
  // src/render/web/styles.ts
2390
- var DARK_VARS = "--bg:#0f1115;--panel:#161b22;--card:#161b22;--line:#30363d;--text:#c9d1d9;--muted:#8b949e;--edge:#79c0ff;--new:#3fb950;--new-t:#7ee787;--chg:#d29922;--chg-t:#f2cc60;--cfg:#a371f7;--cfg-t:#d2a8ff;--add:#7ee787;--rem:#ff7b72";
2463
+ var DARK_VARS = "--bg:#0f1115;--panel:#161b22;--card:#161b22;--line:#30363d;--text:#c9d1d9;--muted:#8b949e;--edge:#79c0ff;--new:#3fb950;--new-t:#7ee787;--chg:#d29922;--chg-t:#f2cc60;--cfg:#a371f7;--cfg-t:#d2a8ff;--add:#7ee787;--rem:#ff7b72;--add-bg:rgba(46,160,67,.22);--rem-bg:rgba(248,81,73,.22);--gap-bg:rgba(110,118,129,.12);--hh-bg:rgba(56,139,253,.10);--hh-line:rgba(56,139,253,.28);--ln:#484f58;--ln-add:rgba(126,231,135,.55);--ln-rem:rgba(255,123,114,.55)";
2391
2464
  var DARK_AUTO = `@media (prefers-color-scheme: dark){:root[data-theme="auto"]{${DARK_VARS}}}`;
2392
2465
  var DARK_FORCED = `:root[data-theme="dark"]{${DARK_VARS}}`;
2393
2466
  var CSS = `
2394
- :root{color-scheme:light dark;--bg:#f6f8fa;--panel:#fff;--card:#fff;--line:#d0d7de;--text:#1f2328;--muted:#656d76;--edge:#0969da;--new:#2ea043;--new-t:#1a7f37;--chg:#d29922;--chg-t:#9a6700;--cfg:#8957e5;--cfg-t:#8250df;--add:#1a7f37;--rem:#cf222e}
2467
+ :root{color-scheme:light dark;--bg:#f6f8fa;--panel:#fff;--card:#fff;--line:#d0d7de;--text:#1f2328;--muted:#656d76;--edge:#0969da;--new:#2ea043;--new-t:#1a7f37;--chg:#d29922;--chg-t:#9a6700;--cfg:#8957e5;--cfg-t:#8250df;--add:#1a7f37;--rem:#cf222e;--add-bg:rgba(46,160,67,.18);--rem-bg:rgba(255,129,130,.25);--gap-bg:rgba(110,118,129,.12);--hh-bg:rgba(9,105,218,.07);--hh-line:rgba(9,105,218,.22);--ln:var(--muted);--ln-add:rgba(26,127,55,.6);--ln-rem:rgba(207,34,46,.6)}
2395
2468
  :root[data-theme="light"]{color-scheme:light}
2396
2469
  :root[data-theme="dark"]{color-scheme:dark}
2397
2470
  ${DARK_AUTO}
@@ -2420,10 +2493,13 @@ aside{width:clamp(300px,35vw,600px);min-width:300px;max-width:80vw;border-left:1
2420
2493
  #panel-nav button{padding:0 7px;font:13px/20px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:10px;cursor:pointer}
2421
2494
  #panel-nav button:hover:not(:disabled){border-color:var(--edge)}#panel-nav button:disabled{opacity:.4;cursor:default}
2422
2495
  aside h2{margin:0 0 6px;font-size:13px;overflow-wrap:anywhere}
2496
+ aside .ptitle{display:flex;gap:7px;align-items:flex-start;min-height:26px;margin-bottom:8px;line-height:1.35}aside .ptitle input{flex:none;margin:2px 0 0}
2423
2497
  aside h3{margin:12px 0 4px;font-size:11px;text-transform:uppercase;color:var(--muted)}
2498
+ aside h3.ch-head{display:flex;justify-content:space-between;align-items:baseline}aside .ch-head .fh-stat{font:11px ui-monospace,monospace;text-transform:none}
2499
+ aside h4{margin:0 0 2px;font-size:11px;font-weight:600;color:var(--muted)}
2424
2500
  aside ul{margin:0;padding-left:18px}
2425
- aside .tick-row{display:block;margin:0 0 6px;color:var(--muted)}
2426
- aside .relations{list-style:none;padding:0}
2501
+ aside .relations{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:6px 14px}
2502
+ aside .rel-col ul{list-style:none;padding:0}aside .rel-none{margin:0;color:var(--muted);font-style:italic}
2427
2503
  aside .rel{padding:1px 0;font:inherit;color:var(--edge);background:none;border:0;cursor:pointer;text-align:left;overflow-wrap:anywhere}aside .rel:hover{text-decoration:underline}
2428
2504
  aside .fields-note{color:var(--muted);font-size:11.5px;font-style:italic;margin:6px 0 0}
2429
2505
  aside code{font-family:ui-monospace,monospace;font-size:11px;font-style:normal}
@@ -2431,7 +2507,18 @@ aside .path{font-family:ui-monospace,monospace;font-size:11px;overflow-wrap:anyw
2431
2507
  aside .snippet{font:11px/1.45 ui-monospace,monospace;background:var(--bg);border:1px solid var(--line);border-radius:4px;padding:6px 8px;margin:6px 0;white-space:pre-wrap;overflow-wrap:anywhere}
2432
2508
  aside .snippet code{display:grid;grid-template-columns:auto minmax(0,1fr);column-gap:10px}
2433
2509
  aside .snippet .ln{min-width:3ch;color:var(--muted);text-align:right;user-select:none}
2434
- aside .d-add{color:var(--add)}aside .d-del{color:var(--rem)}aside .d-hunk{color:var(--muted)}
2510
+ aside .snippet.diff{background:none;border:0;border-radius:0;padding:0;margin:2px 0}
2511
+ aside .snippet.diff code{display:flex;flex-direction:column}
2512
+ aside .dr{display:flex;padding:0 14px 0 4px}
2513
+ aside .dr .ln{flex:none;width:4.5ch;min-width:0;color:var(--ln);text-align:right;user-select:none}
2514
+ aside .dr .sg{flex:none;width:2.4ch;text-align:center;user-select:none}
2515
+ aside .ind{white-space:pre;tab-size:4}aside .dr .cd{flex:1;min-width:0;white-space:pre-wrap;overflow-wrap:anywhere}
2516
+ aside .dr.d-add{background:var(--add-bg)}aside .dr.d-add .ln{color:var(--ln-add)}aside .dr.d-add .sg{color:var(--add)}
2517
+ aside .dr.d-del{background:var(--rem-bg)}aside .dr.d-del .ln{color:var(--ln-rem)}aside .dr.d-del .sg{color:var(--rem)}
2518
+ aside .n-add{color:var(--add)}aside .n-del{color:var(--rem)}
2519
+ aside .cgap{display:flex;flex-direction:column}aside .cgap .gap-rows{display:none;flex-direction:column}aside .cgap.open .gap-rows{display:flex}
2520
+ aside .gap{display:flex;width:100%;padding:2px 14px 2px calc(4px + 4.5ch);font:11px ui-monospace,monospace;color:var(--muted);background:var(--gap-bg);text-align:left;white-space:nowrap}
2521
+ aside button.gap{border:0;cursor:pointer}aside button.gap:hover{color:var(--text)}
2435
2522
  aside .mismatch-note{color:var(--rem);margin:6px 0}
2436
2523
  aside .mismatch-why{color:var(--muted);font-size:11.5px;margin:0 0 6px}
2437
2524
  header .check{font-size:11px;color:var(--new-t)}header .check.bad{color:var(--rem);font-weight:600;font-family:inherit;background:none;border:0;padding:0;cursor:pointer;text-decoration:underline dotted}
@@ -2475,6 +2562,8 @@ body.focus .node:not(.lit),body.focus .edge:not(.lit){--dim:.25}
2475
2562
  .node.reviewed :is(.card,.fold,.shape){stroke:var(--muted)}
2476
2563
  .node.reviewed .tick-box{fill:var(--muted)}.node.reviewed .tick-mark{display:inline}
2477
2564
  .node.selected .card{stroke-width:2.5}
2565
+ .node.selected{filter:drop-shadow(0 0 6px color-mix(in srgb,var(--edge) 45%,transparent))}
2566
+ .node.selected :is(.card,.shape){stroke-width:3}
2478
2567
  .node:focus{outline:none}
2479
2568
  .node:focus-visible .card{stroke:var(--edge);stroke-width:3.5}
2480
2569
  .status-new :is(.card,.fold){stroke:var(--new)}.status-new .badge{fill:var(--new-t)}
@@ -2489,6 +2578,28 @@ body.focus .node:not(.lit),body.focus .edge:not(.lit){--dim:.25}
2489
2578
  #info-toggle:hover,#link-toggle:hover,#theme-toggle:hover,#next-unreviewed:hover:not(:disabled){border-color:var(--edge)}
2490
2579
  #next-unreviewed{padding:0 8px;font:10.5px/16px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:10px;cursor:pointer}
2491
2580
  #next-unreviewed:disabled{opacity:.4;cursor:default}
2581
+ aside .file{margin:6px -14px}
2582
+ aside .file-head{display:flex;gap:8px;align-items:baseline;justify-content:space-between;margin:0 0 4px;padding:0 14px;color:var(--muted);font-size:11px}
2583
+ aside .file-head .path{min-width:0}
2584
+ aside .hunk{border-left:3px solid transparent}aside .hunk+.hunk{margin-top:4px}
2585
+ aside .hunk.cur{border-left-color:var(--edge)}
2586
+ aside .hh{display:flex;gap:8px;align-items:baseline;width:100%;padding:2px 14px 2px 5px;font:11px ui-monospace,monospace;color:var(--muted);background:var(--hh-bg);border:0;border-top:1px solid var(--hh-line);border-bottom:1px solid var(--hh-line);text-align:left;white-space:nowrap;overflow:hidden}
2587
+ aside button.hunk-sum{cursor:pointer}aside button.hunk-sum:hover{color:var(--text)}
2588
+ aside .hh>*{flex:none}
2589
+ aside .hh .caret{width:1ch}aside .hh .caret::before{content:"\\2304"}aside .hunk.folded .hh .caret::before{content:"\\203A"}
2590
+ aside .hh .hs-fn{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;color:var(--edge)}
2591
+ aside .hh .hs-first{flex:1 1 0;min-width:0;overflow:hidden;text-overflow:ellipsis}
2592
+ aside .hh .hs-stat{margin-left:auto}
2593
+ aside .hunk:not(.folded) .hs-first{display:none}
2594
+ aside .hunk.folded .hunk-body,aside .hunk.folded .gap-out{display:none}
2595
+ aside .hunk-end{margin:6px 0;color:var(--muted);font-size:11px;font-style:italic}
2596
+ #key-help{position:fixed;right:14px;bottom:14px;z-index:5;padding:8px 12px;font-size:11.5px;line-height:1.6;background:var(--panel);border:1px solid var(--line);border-radius:6px;box-shadow:0 2px 8px #0003;cursor:pointer}
2597
+ #key-help[hidden]{display:none}
2598
+ aside .pager{position:sticky;top:-10px;z-index:2;display:flex;flex-wrap:wrap;align-items:center;gap:4px 6px;margin:0 -14px 4px;padding:14px 14px 4px;background:var(--panel);border-bottom:1px solid var(--line);font-size:11px;color:var(--muted)}
2599
+ aside .pager button{padding:0 7px;font:13px/20px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:10px;cursor:pointer}
2600
+ aside .pager button:hover,aside .pager button:focus-visible{border-color:var(--edge)}aside .pager button:focus:not(:focus-visible){outline:none}
2601
+ aside .pager .pg-count{flex:1;min-width:0;text-align:center;white-space:nowrap}
2602
+ aside .pager .pg-keys{margin-left:auto;font-size:11px}aside .pager .pg-all{font:11px/20px system-ui,sans-serif}
2492
2603
  `;
2493
2604
 
2494
2605
  // src/render/web/client.ts
@@ -2770,17 +2881,251 @@ var CLIENT_JS = [
2770
2881
  " if (id !== null)",
2771
2882
  " toggle(id);",
2772
2883
  " });",
2773
- " if (next) {",
2774
- " next.addEventListener('click', () => {",
2775
- " var _a, _b;",
2776
- " const at = ids.indexOf((_b = (_a = document.querySelector('.node.selected')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id')) !== null && _b !== void 0 ? _b : '');",
2777
- " const to = ids.map((_, i) => ids[(at + 1 + i) % ids.length]).find((id) => !done.has(id));",
2778
- " if (to !== undefined)",
2779
- " goTo(to);",
2780
- " });",
2781
- " }",
2884
+ " const step = (dir) => {",
2885
+ " var _a, _b;",
2886
+ " const at = ids.indexOf((_b = (_a = document.querySelector('.node.selected')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id')) !== null && _b !== void 0 ? _b : '');",
2887
+ " const from = at < 0 && dir < 0 ? ids.length : at;",
2888
+ " const to = ids.map((_, i) => ids[(((from + dir * (1 + i)) % ids.length) + ids.length) % ids.length]).find((id) => !done.has(id));",
2889
+ " if (to !== undefined)",
2890
+ " goTo(to);",
2891
+ " };",
2892
+ " if (next)",
2893
+ " next.addEventListener('click', () => step(1));",
2894
+ " const toggleSelected = () => {",
2895
+ " var _a;",
2896
+ " const id = (_a = document.querySelector('.node.selected')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id');",
2897
+ " if (id)",
2898
+ " toggle(id);",
2899
+ " };",
2782
2900
  " paint();",
2783
- " return { paint };",
2901
+ " return { paint, step, toggleSelected };",
2902
+ "}",
2903
+ "",
2904
+ "const ZOOM_MAX = 1.5;",
2905
+ "const FILL = 0.35;",
2906
+ "const GLIDE_MS = 250;",
2907
+ "function nodeView(b, pane) {",
2908
+ " const k = Math.min(ZOOM_MAX, (pane.width * FILL) / (b.width || 1), (pane.height * FILL) / (b.height || 1));",
2909
+ " return { k, x: pane.width / 2 - (b.x + b.width / 2) * k, y: pane.height / 2 - (b.y + b.height / 2) * k };",
2910
+ "}",
2911
+ "function glide(from, to, set) {",
2912
+ " var _a;",
2913
+ " if (((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(prefers-reduced-motion: reduce)').matches) || !window.requestAnimationFrame) {",
2914
+ " set(to);",
2915
+ " return () => { };",
2916
+ " }",
2917
+ " let live = true;",
2918
+ " const t0 = performance.now();",
2919
+ " const step = (now) => {",
2920
+ " if (!live)",
2921
+ " return;",
2922
+ " const f = Math.min(1, (now - t0) / GLIDE_MS);",
2923
+ " const e = 1 - (1 - f) ** 3;",
2924
+ " set({ x: from.x + (to.x - from.x) * e, y: from.y + (to.y - from.y) * e, k: from.k + (to.k - from.k) * e });",
2925
+ " if (f < 1)",
2926
+ " requestAnimationFrame(step);",
2927
+ " };",
2928
+ " requestAnimationFrame(step);",
2929
+ " return () => {",
2930
+ " live = false;",
2931
+ " };",
2932
+ "}",
2933
+ "",
2934
+ "function initPanelResize() {",
2935
+ " const aside = document.querySelector('aside');",
2936
+ " const handle = document.getElementById('resize');",
2937
+ " let width = 0;",
2938
+ " const panes = !!document.getElementById('panes');",
2939
+ " const widthKey = panes ? 'codechart.panel.panes' : 'codechart.panel';",
2940
+ " const minWidth = panes ? 200 : 300;",
2941
+ " const setWidth = (w, remember) => {",
2942
+ " width = Math.round(Math.max(minWidth, Math.min(w, window.innerWidth * 0.8)));",
2943
+ " aside.style.width = `${width}px`;",
2944
+ " if (remember)",
2945
+ " save(widthKey, String(width));",
2946
+ " };",
2947
+ " const currentWidth = () => width || aside.getBoundingClientRect().width;",
2948
+ " const savedWidth = Number(load(widthKey));",
2949
+ " if (savedWidth > 0)",
2950
+ " setWidth(savedWidth, false);",
2951
+ " let sizing = false;",
2952
+ " handle.addEventListener('pointerdown', (e) => {",
2953
+ " sizing = true;",
2954
+ " handle.classList.add('drag');",
2955
+ " if (handle.setPointerCapture)",
2956
+ " handle.setPointerCapture(e.pointerId);",
2957
+ " e.preventDefault();",
2958
+ " });",
2959
+ " handle.addEventListener('pointermove', (e) => {",
2960
+ " if (sizing)",
2961
+ " setWidth(window.innerWidth - e.clientX, false);",
2962
+ " });",
2963
+ " const endSize = () => {",
2964
+ " if (!sizing)",
2965
+ " return;",
2966
+ " sizing = false;",
2967
+ " handle.classList.remove('drag');",
2968
+ " setWidth(currentWidth(), true);",
2969
+ " };",
2970
+ " handle.addEventListener('pointerup', endSize);",
2971
+ " handle.addEventListener('pointercancel', endSize);",
2972
+ " handle.addEventListener('keydown', (e) => {",
2973
+ " const step = e.key === 'ArrowLeft' ? 40 : e.key === 'ArrowRight' ? -40 : 0;",
2974
+ " if (!step)",
2975
+ " return;",
2976
+ " e.preventDefault();",
2977
+ " setWidth(currentWidth() + step, true);",
2978
+ " });",
2979
+ "}",
2980
+ "",
2981
+ "const typing = (t) => {",
2982
+ " const el = t;",
2983
+ " if (!el)",
2984
+ " return false;",
2985
+ " if (el.tagName === 'INPUT')",
2986
+ " return !['checkbox', 'radio', 'button', 'submit', 'reset'].includes(el.type);",
2987
+ " return el.tagName === 'TEXTAREA' || el.tagName === 'SELECT' || el.isContentEditable === true;",
2988
+ "};",
2989
+ "const isOpen = (h) => !h.classList.contains('folded');",
2990
+ "function setOpen(h, open) {",
2991
+ " var _a;",
2992
+ " h.classList.toggle('folded', !open);",
2993
+ " (_a = h.querySelector('.hunk-sum')) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-expanded', String(open));",
2994
+ "}",
2995
+ "const hunksIn = (panel) => [...panel.querySelectorAll('.hunk')];",
2996
+ "function paintCount(panel, cur) {",
2997
+ " const label = panel.querySelector('.pg-count');",
2998
+ " if (!label)",
2999
+ " return;",
3000
+ " const hunks = hunksIn(panel);",
3001
+ " const at = cur ? hunks.indexOf(cur) + 1 : 0;",
3002
+ " label.textContent = `${at || '\\u2013'} / ${hunks.length}`;",
3003
+ " label.setAttribute('aria-label', at ? `hunk ${at} of ${hunks.length}` : `${hunks.length} hunks`);",
3004
+ "}",
3005
+ "function endNote(panel) {",
3006
+ " var _a;",
3007
+ " const note = document.createElement('p');",
3008
+ " note.className = 'hunk-end';",
3009
+ " note.textContent = 'end of node \xB7 ] next unreviewed';",
3010
+ " const last = (_a = hunksIn(panel).at(-1)) === null || _a === void 0 ? void 0 : _a.closest('.file');",
3011
+ " if (last)",
3012
+ " last.after(note);",
3013
+ " else",
3014
+ " panel.appendChild(note);",
3015
+ " return note;",
3016
+ "}",
3017
+ "function walker(panel, aside) {",
3018
+ " let cur = null;",
3019
+ " let end = null;",
3020
+ " const paint = () => paintCount(panel, cur);",
3021
+ " const mark = (h) => {",
3022
+ " cur === null || cur === void 0 ? void 0 : cur.classList.remove('cur');",
3023
+ " cur = h;",
3024
+ " h === null || h === void 0 ? void 0 : h.classList.add('cur');",
3025
+ " paint();",
3026
+ " };",
3027
+ " const hideEnd = () => {",
3028
+ " end === null || end === void 0 ? void 0 : end.remove();",
3029
+ " end = null;",
3030
+ " };",
3031
+ " const show = (h) => {",
3032
+ " hideEnd();",
3033
+ " mark(h);",
3034
+ " hunksIn(panel).forEach((x) => setOpen(x, x === h));",
3035
+ " };",
3036
+ " const showEnd = () => {",
3037
+ " end !== null && end !== void 0 ? end : (end = endNote(panel));",
3038
+ " };",
3039
+ " const setAll = (open) => hunksIn(panel).forEach((h) => setOpen(h, open));",
3040
+ " return {",
3041
+ " step(dir) {",
3042
+ " if (end && dir < 0) {",
3043
+ " if (cur)",
3044
+ " show(cur);",
3045
+ " return;",
3046
+ " }",
3047
+ " const hunks = hunksIn(panel);",
3048
+ " const i = cur ? hunks.indexOf(cur) : -1;",
3049
+ " const to = hunks[dir > 0 ? i + 1 : Math.max(0, i - 1)];",
3050
+ " if (to)",
3051
+ " show(to);",
3052
+ " else if (dir > 0)",
3053
+ " showEnd();",
3054
+ " },",
3055
+ " toggle() {",
3056
+ " const h = cur !== null && cur !== void 0 ? cur : hunksIn(panel)[0];",
3057
+ " if (h)",
3058
+ " setOpen(h, !isOpen(h));",
3059
+ " },",
3060
+ " toggleAll() {",
3061
+ " setAll(!hunksIn(panel).every(isOpen));",
3062
+ " },",
3063
+ " setAll,",
3064
+ " pick(h) {",
3065
+ " setOpen(h, !isOpen(h));",
3066
+ " mark(h);",
3067
+ " hideEnd();",
3068
+ " },",
3069
+ " reset() {",
3070
+ " cur = null;",
3071
+ " end = null;",
3072
+ " aside.scrollTop = 0;",
3073
+ " paint();",
3074
+ " },",
3075
+ " };",
3076
+ "}",
3077
+ "function initHunks(panel, review, zoomToNode) {",
3078
+ " const nav = walker(panel, panel.closest('aside'));",
3079
+ " const help = document.getElementById('key-help');",
3080
+ " const toggleHelp = () => {",
3081
+ " help.hidden = !help.hidden;",
3082
+ " };",
3083
+ " const keys = {",
3084
+ " n: () => nav.step(1),",
3085
+ " p: () => nav.step(-1),",
3086
+ " ']': () => review.step(1),",
3087
+ " '[': () => review.step(-1),",
3088
+ " r: () => review.toggleSelected(),",
3089
+ " f: zoomToNode,",
3090
+ " o: () => nav.toggle(),",
3091
+ " O: () => nav.toggleAll(),",
3092
+ " '?': toggleHelp,",
3093
+ " };",
3094
+ " const buttons = {",
3095
+ " '.pg-prev': () => nav.step(-1),",
3096
+ " '.pg-next': () => nav.step(1),",
3097
+ " '.pg-expand': () => nav.setAll(true),",
3098
+ " '.pg-collapse': () => nav.setAll(false),",
3099
+ " '.pg-keys': toggleHelp,",
3100
+ " };",
3101
+ " panel.addEventListener('click', (e) => {",
3102
+ " var _a;",
3103
+ " const t = e.target;",
3104
+ " const h = (_a = t.closest('.hunk-sum')) === null || _a === void 0 ? void 0 : _a.closest('.hunk');",
3105
+ " if (h)",
3106
+ " nav.pick(h);",
3107
+ " const gap = t.closest('.gap-run');",
3108
+ " if (gap)",
3109
+ " gap.setAttribute('aria-expanded', String(gap.parentElement.classList.toggle('open')));",
3110
+ " for (const [sel, run] of Object.entries(buttons))",
3111
+ " if (t.closest(sel))",
3112
+ " run();",
3113
+ " });",
3114
+ " help.addEventListener('click', () => {",
3115
+ " help.hidden = true;",
3116
+ " });",
3117
+ " window.addEventListener('keydown', (e) => {",
3118
+ " if (e.key === 'Escape')",
3119
+ " help.hidden = true;",
3120
+ " if (e.ctrlKey || e.metaKey || e.altKey || typing(e.target))",
3121
+ " return;",
3122
+ " const run = Object.hasOwn(keys, e.key) ? keys[e.key] : undefined;",
3123
+ " if (!run)",
3124
+ " return;",
3125
+ " e.preventDefault();",
3126
+ " run();",
3127
+ " });",
3128
+ " return { reset: nav.reset };",
2784
3129
  "}",
2785
3130
  "",
2786
3131
  "const THEMES = ['auto', 'light', 'dark'];",
@@ -2790,12 +3135,14 @@ var CLIENT_JS = [
2790
3135
  "const panel = document.getElementById('panel');",
2791
3136
  "const info = document.getElementById('page-info');",
2792
3137
  "const infoBtn = document.getElementById('info-toggle');",
3138
+ "const focusBtn = document.getElementById('nav-focus');",
2793
3139
  "let ts = canvases.map(() => ({ x: 0, y: 0, k: 1 }));",
2794
3140
  "let linked = true;",
2795
3141
  "let last = 0;",
2796
3142
  "let drag = null;",
2797
3143
  "let moved = false;",
2798
3144
  "let trail;",
3145
+ "let stopGlide = () => { };",
2799
3146
  "function apply() {",
2800
3147
  " vps.forEach((vp, i) => {",
2801
3148
  " const t = ts[i];",
@@ -2807,6 +3154,23 @@ var CLIENT_JS = [
2807
3154
  " ts = ts.map((old, j) => (linked || j === i ? { x: t.x, y: t.y, k: t.k } : old));",
2808
3155
  " apply();",
2809
3156
  "}",
3157
+ "function zoomToSelected() {",
3158
+ " var _a;",
3159
+ " const id = (_a = document.querySelector('.node.selected')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id');",
3160
+ " if (!id)",
3161
+ " return;",
3162
+ " stopGlide();",
3163
+ " const stops = [];",
3164
+ " for (let i = 0; i < canvases.length; i++) {",
3165
+ ' const g = canvases[i].querySelector(`.node[data-id="${CSS.escape(id)}"]`);',
3166
+ " if (!g)",
3167
+ " continue;",
3168
+ " stops.push(glide(ts[i], nodeView(g.getBBox(), canvases[i].querySelector('svg').getBoundingClientRect()), (v) => move(i, v)));",
3169
+ " if (linked)",
3170
+ " break;",
3171
+ " }",
3172
+ " stopGlide = () => stops.forEach((s) => s());",
3173
+ "}",
2810
3174
  "function fit() {",
2811
3175
  " const r = canvases[0].querySelector('svg').getBoundingClientRect();",
2812
3176
  " const k = Math.min(r.width / data.width, r.height / data.height, 1) || 1;",
@@ -2824,6 +3188,7 @@ var CLIENT_JS = [
2824
3188
  " const svg = canvas.querySelector('svg');",
2825
3189
  " canvas.addEventListener('wheel', (e) => {",
2826
3190
  " e.preventDefault();",
3191
+ " stopGlide();",
2827
3192
  " const t = ts[i];",
2828
3193
  " const r = svg.getBoundingClientRect();",
2829
3194
  " const px = e.clientX - r.left;",
@@ -2832,6 +3197,7 @@ var CLIENT_JS = [
2832
3197
  " move(i, { x: px - ((px - t.x) / t.k) * k, y: py - ((py - t.y) / t.k) * k, k });",
2833
3198
  " }, { passive: false });",
2834
3199
  " canvas.addEventListener('pointerdown', (e) => {",
3200
+ " stopGlide();",
2835
3201
  " drag = { i, x: e.clientX - ts[i].x, y: e.clientY - ts[i].y, sx: e.clientX, sy: e.clientY, canvas };",
2836
3202
  " moved = false;",
2837
3203
  " });",
@@ -2882,7 +3248,9 @@ var CLIENT_JS = [
2882
3248
  " panel.appendChild(tpl.content.cloneNode(true));",
2883
3249
  " }",
2884
3250
  " setInfo(!tpl);",
3251
+ " focusBtn.disabled = !tpl;",
2885
3252
  " review.paint();",
3253
+ " hunks.reset();",
2886
3254
  "}",
2887
3255
  "function reveal(v) {",
2888
3256
  " if (v === null)",
@@ -2927,6 +3295,7 @@ var CLIENT_JS = [
2927
3295
  " });",
2928
3296
  " backBtn.addEventListener('click', () => trail.back());",
2929
3297
  " forwardBtn.addEventListener('click', () => trail.forward());",
3298
+ " focusBtn.addEventListener('click', zoomToSelected);",
2930
3299
  " window.addEventListener('keydown', (e) => {",
2931
3300
  " if (!e.altKey || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight'))",
2932
3301
  " return;",
@@ -2977,52 +3346,6 @@ var CLIENT_JS = [
2977
3346
  " setTheme(THEMES[(i + 1) % THEMES.length], true);",
2978
3347
  " });",
2979
3348
  "}",
2980
- "function initPanelResize() {",
2981
- " const aside = document.querySelector('aside');",
2982
- " const handle = document.getElementById('resize');",
2983
- " let width = 0;",
2984
- " const panes = !!document.getElementById('panes');",
2985
- " const widthKey = panes ? 'codechart.panel.panes' : 'codechart.panel';",
2986
- " const minWidth = panes ? 200 : 300;",
2987
- " const setWidth = (w, remember) => {",
2988
- " width = Math.round(Math.max(minWidth, Math.min(w, window.innerWidth * 0.8)));",
2989
- " aside.style.width = `${width}px`;",
2990
- " if (remember)",
2991
- " save(widthKey, String(width));",
2992
- " };",
2993
- " const currentWidth = () => width || aside.getBoundingClientRect().width;",
2994
- " const savedWidth = Number(load(widthKey));",
2995
- " if (savedWidth > 0)",
2996
- " setWidth(savedWidth, false);",
2997
- " let sizing = false;",
2998
- " handle.addEventListener('pointerdown', (e) => {",
2999
- " sizing = true;",
3000
- " handle.classList.add('drag');",
3001
- " if (handle.setPointerCapture)",
3002
- " handle.setPointerCapture(e.pointerId);",
3003
- " e.preventDefault();",
3004
- " });",
3005
- " handle.addEventListener('pointermove', (e) => {",
3006
- " if (sizing)",
3007
- " setWidth(window.innerWidth - e.clientX, false);",
3008
- " });",
3009
- " const endSize = () => {",
3010
- " if (!sizing)",
3011
- " return;",
3012
- " sizing = false;",
3013
- " handle.classList.remove('drag');",
3014
- " setWidth(currentWidth(), true);",
3015
- " };",
3016
- " handle.addEventListener('pointerup', endSize);",
3017
- " handle.addEventListener('pointercancel', endSize);",
3018
- " handle.addEventListener('keydown', (e) => {",
3019
- " const step = e.key === 'ArrowLeft' ? 40 : e.key === 'ArrowRight' ? -40 : 0;",
3020
- " if (!step)",
3021
- " return;",
3022
- " e.preventDefault();",
3023
- " setWidth(currentWidth() + step, true);",
3024
- " });",
3025
- "}",
3026
3349
  "initPanZoom();",
3027
3350
  "initPaneLink();",
3028
3351
  "initTheme();",
@@ -3032,12 +3355,18 @@ var CLIENT_JS = [
3032
3355
  "dismissFocus(canvases, () => moved);",
3033
3356
  "initChips();",
3034
3357
  "const review = initReview(data.repoKey, goTo);",
3358
+ "const hunks = initHunks(panel, review, zoomToSelected);",
3035
3359
  "initPanel();",
3036
3360
  "})();",
3037
3361
  ""
3038
3362
  ].join("\n");
3039
3363
 
3040
3364
  // src/render/web/page.ts
3365
+ var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
3366
+ function prettyDate(d) {
3367
+ const pad2 = (n) => String(n).padStart(2, "0");
3368
+ return `${d.getDate()} ${MONTHS[d.getMonth()]} ${d.getFullYear()}, ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
3369
+ }
3041
3370
  function esc(s) {
3042
3371
  return stripInvisible(s).replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
3043
3372
  }
@@ -3069,6 +3398,7 @@ function midpoint(points) {
3069
3398
  return points[0] ?? { x: 0, y: 0 };
3070
3399
  }
3071
3400
  var keyHtml = (key) => key.map((k) => `<span class="k-${k.tone}">${esc(k.text)}</span>`).join(" \xB7 ");
3401
+ var KEY_HELP = ["n / p: next / previous hunk (opens it, folds the others)", "] / [: next / previous unreviewed node", "r: toggle reviewed", "o / O: fold this hunk / toggle all hunks", "f: zoom to the selected node", "?: this help"];
3072
3402
  var CSP = `default-src 'none'; style-src 'unsafe-inline'; script-src 'sha256-${createHash2("sha256").update(CLIENT_JS).digest("base64")}'; img-src data:; base-uri 'none'; form-action 'none'`;
3073
3403
  function renderPage(p) {
3074
3404
  const theme = p.meta.theme && THEMES.includes(p.meta.theme) ? p.meta.theme : "auto";
@@ -3083,13 +3413,14 @@ function renderPage(p) {
3083
3413
  <title>${esc(p.title)}</title>
3084
3414
  <style>${CSS}${p.extraCss ?? ""}</style></head>
3085
3415
  <body>
3086
- <header><h1>${esc(p.title)}</h1>${p.headerNote ?? ""}<span class="meta">${esc(p.meta.repo)} \xB7 ${esc(p.meta.generatedAt.toISOString())}</span>${p.meta.update ? `<span class="update" title="A newer codechart is out">codechart ${esc(p.meta.update)} is out: run <code>codechart update</code></span>` : ""}${p.infoButton}${p.panes ? '<button id="link-toggle" type="button" title="Linked: panning or zooming one pane moves both"></button>' : ""}<button id="theme-toggle" type="button" title="Cycle theme: auto, light, dark"></button></header>
3416
+ <header><h1>${esc(p.title)}</h1>${p.headerNote ?? ""}<span class="meta">${esc(p.meta.repo)} \xB7 <time datetime="${p.meta.generatedAt.toISOString()}" title="${p.meta.generatedAt.toISOString()}">${prettyDate(p.meta.generatedAt)}</time></span>${p.meta.update ? `<span class="update" title="${esc(["A newer codechart is out", ...(p.meta.updateNotes ?? []).map((n) => `- ${n}`)].join("\n"))}">codechart ${esc(p.meta.update)} is out: run <code>codechart update</code></span>` : ""}${p.infoButton}${p.panes ? '<button id="link-toggle" type="button" title="Linked: panning or zooming one pane moves both"></button>' : ""}<button id="theme-toggle" type="button" title="Cycle theme: auto, light, dark"></button></header>
3087
3417
  ${p.toolbar ? `<div id="toolbar">${p.toolbar}</div>
3088
3418
  ` : ""}<main>
3089
3419
  ${body}
3090
3420
  <div id="resize" role="separator" aria-orientation="vertical" aria-label="Resize panel" tabindex="0" title="Drag to resize the panel"></div>
3091
- <aside><nav id="panel-nav" aria-label="Panel history"><button id="nav-back" type="button" disabled aria-label="Back" title="Back (Alt+\u2190)">\u2190</button><button id="nav-forward" type="button" disabled aria-label="Forward" title="Forward (Alt+\u2192)">\u2192</button></nav>${p.aside}</aside>
3421
+ <aside><nav id="panel-nav" aria-label="Panel history"><button id="nav-focus" type="button" disabled aria-label="Focus node (f)" title="Focus node (f)">\u25CE</button><button id="nav-back" type="button" disabled aria-label="Back" title="Back (Alt+\u2190)">\u2190</button><button id="nav-forward" type="button" disabled aria-label="Forward" title="Forward (Alt+\u2192)">\u2192</button></nav>${p.aside}</aside>
3092
3422
  </main>
3423
+ <div id="key-help" role="dialog" aria-label="Keys" hidden><b>Keys</b>${KEY_HELP.map((k) => `<div>${esc(k)}</div>`).join("")}</div>
3093
3424
  <script type="application/json" id="spec-data">${jsonForScript(data)}</script>
3094
3425
  <script>${CLIENT_JS}</script>
3095
3426
  </body></html>
@@ -3185,9 +3516,9 @@ var LABEL_LINE_HEIGHT = 14;
3185
3516
  var LABEL_BREAKS = ["_", ".", "/", "-", " "];
3186
3517
  function labelLines(label) {
3187
3518
  if (label.length <= LABEL_CHARS) return [label];
3188
- const head = label.slice(0, LABEL_CHARS);
3189
- const camel = [...head.matchAll(/[a-z\d](?=[A-Z])/g)].map((m) => m.index);
3190
- const cut2 = Math.max(...LABEL_BREAKS.map((c) => head.lastIndexOf(c)), ...camel) + 1;
3519
+ const head2 = label.slice(0, LABEL_CHARS);
3520
+ const camel = [...head2.matchAll(/[a-z\d](?=[A-Z])/g)].map((m) => m.index);
3521
+ const cut2 = Math.max(...LABEL_BREAKS.map((c) => head2.lastIndexOf(c)), ...camel) + 1;
3191
3522
  const at = cut2 >= LABEL_CHARS / 2 ? cut2 : LABEL_CHARS;
3192
3523
  const rest = label.slice(at).trim();
3193
3524
  return [label.slice(0, at).trimEnd(), rest.length > LABEL_MORE_CHARS ? rest.slice(0, LABEL_MORE_CHARS - 1) + "\u2026" : rest];
@@ -3352,7 +3683,7 @@ var flowObject = z3.strictObject({
3352
3683
  gaps: z3.array(long()).optional()
3353
3684
  });
3354
3685
  function flowFacts(spec) {
3355
- const counts = outgoingCounts(spec, spec.links);
3686
+ const counts2 = outgoingCounts(spec, spec.links);
3356
3687
  const live = outgoingLinks(spec, spec.links.map((l, i) => ({ ...l, i })));
3357
3688
  const byId = new Map(spec.steps.map((s) => [s.id, s]));
3358
3689
  const brandNew = (id) => byId.get(id)?.status === "planned" && !byId.get(id)?.source;
@@ -3372,7 +3703,7 @@ function flowFacts(spec) {
3372
3703
  brandNew,
3373
3704
  removedStep,
3374
3705
  existsNow,
3375
- typeOf: (step) => step.type ?? inferType(counts.get(step.id) ?? 0),
3706
+ typeOf: (step) => step.type ?? inferType(counts2.get(step.id) ?? 0),
3376
3707
  branchesNow: (id) => spec.kind === "plan" && (nowOut.get(id)?.length ?? 0) >= 2 && (live.get(id)?.length ?? 0) < 2
3377
3708
  };
3378
3709
  }
@@ -3436,19 +3767,19 @@ function shapeIssues(spec, facts, issue) {
3436
3767
  for (const li of linkIdx) if (!spec.links[li].label) issue(["links", li, "label"], "required on a link leaving a decision");
3437
3768
  };
3438
3769
  spec.steps.forEach((step, i) => {
3439
- const count = (facts.live.get(step.id) ?? []).length;
3440
- if (step.type === void 0 && step.label.trim().endsWith("?") && count < 2 && !facts.branchesNow(step.id)) {
3441
- issue(["steps", i, "type"], `label ends in "?", so this is a decision: it needs at least 2 outgoing links, has ${count}`);
3770
+ const count2 = (facts.live.get(step.id) ?? []).length;
3771
+ if (step.type === void 0 && step.label.trim().endsWith("?") && count2 < 2 && !facts.branchesNow(step.id)) {
3772
+ issue(["steps", i, "type"], `label ends in "?", so this is a decision: it needs at least 2 outgoing links, has ${count2}`);
3442
3773
  return;
3443
3774
  }
3444
3775
  const type = facts.typeOf(step);
3445
- if (type === "end" && count > 0) issue(["steps", i, "type"], `an end has no outgoing links, has ${count}`);
3446
- if (type === "step" && count > 1) issue(["steps", i, "type"], `has ${count} outgoing links; make it a decision with labelled branches`);
3776
+ if (type === "end" && count2 > 0) issue(["steps", i, "type"], `an end has no outgoing links, has ${count2}`);
3777
+ if (type === "step" && count2 > 1) issue(["steps", i, "type"], `has ${count2} outgoing links; make it a decision with labelled branches`);
3447
3778
  if (type !== "decision") {
3448
3779
  if (facts.branchesNow(step.id)) needLabels(facts.nowOut.get(step.id) ?? []);
3449
3780
  return;
3450
3781
  }
3451
- if (count < 2) issue(["steps", i, "id"], `decision "${step.id}" needs at least 2 outgoing links, has ${count}`);
3782
+ if (count2 < 2) issue(["steps", i, "id"], `decision "${step.id}" needs at least 2 outgoing links, has ${count2}`);
3452
3783
  needLabels(facts.outgoing.get(step.id) ?? []);
3453
3784
  });
3454
3785
  }
@@ -3477,8 +3808,8 @@ var flowSchema = flowObject.superRefine((spec, ctx) => {
3477
3808
  function validateFlowSpec(input) {
3478
3809
  const result = flowSchema.safeParse(input);
3479
3810
  if (!result.success) return { ok: false, errors: formatIssues(result.error) };
3480
- const counts = outgoingCounts(result.data, result.data.links);
3481
- const steps = result.data.steps.map((s) => ({ ...s, type: s.type ?? inferType(counts.get(s.id) ?? 0) }));
3811
+ const counts2 = outgoingCounts(result.data, result.data.links);
3812
+ const steps = result.data.steps.map((s) => ({ ...s, type: s.type ?? inferType(counts2.get(s.id) ?? 0) }));
3482
3813
  return { ok: true, spec: { ...result.data, diagram: "flow", steps } };
3483
3814
  }
3484
3815
  function flowJsonSchema() {
@@ -3522,12 +3853,12 @@ var CHIP_ORDER = ["new", "changed", "removed", "planned", "config", "context", "
3522
3853
  var CHIP_MARK = { new: "+", changed: "~", removed: "\u2212", planned: "\u25CB", config: "\u25C6", context: "\xB7", existing: "\xB7" };
3523
3854
  var UNCHANGED = ["context", "existing"];
3524
3855
  function statusChips(statuses) {
3525
- const counts = /* @__PURE__ */ new Map();
3526
- for (const s of statuses) counts.set(s, (counts.get(s) ?? 0) + 1);
3527
- const chips = CHIP_ORDER.filter((s) => counts.has(s)).map(
3528
- (s) => `<button type="button" class="chip chip-${s}" data-status="${s}" aria-pressed="false" title="Fade ${s} nodes">${CHIP_MARK[s]}${counts.get(s)} ${s}</button>`
3856
+ const counts2 = /* @__PURE__ */ new Map();
3857
+ for (const s of statuses) counts2.set(s, (counts2.get(s) ?? 0) + 1);
3858
+ const chips = CHIP_ORDER.filter((s) => counts2.has(s)).map(
3859
+ (s) => `<button type="button" class="chip chip-${s}" data-status="${s}" aria-pressed="false" title="Fade ${s} nodes">${CHIP_MARK[s]}${counts2.get(s)} ${s}</button>`
3529
3860
  );
3530
- const unchanged = UNCHANGED.find((s) => counts.has(s));
3861
+ const unchanged = UNCHANGED.find((s) => counts2.has(s));
3531
3862
  if (unchanged) {
3532
3863
  chips.unshift(
3533
3864
  `<button type="button" class="chip chip-delta" data-delta="${unchanged}" aria-pressed="false" title="Fade ${unchanged} nodes, leaving only the changes">\u0394 changes only</button>`
@@ -3538,7 +3869,7 @@ function statusChips(statuses) {
3538
3869
  var reviewControls = (total) => `<div id="review"><span id="review-count">0/${total} reviewed</span><span id="review-bar" aria-hidden="true"><i></i></span><button id="next-unreviewed" type="button" title="Next unreviewed: select the next node not ticked as reviewed" aria-label="Next unreviewed">Next \u25B8</button></div>`;
3539
3870
  var diffRev = (p) => p ? createHash3("sha256").update(JSON.stringify(p)).digest("hex").slice(0, 12) : void 0;
3540
3871
  var tickSvg = (x, y) => `<g class="tick" aria-hidden="true"><rect class="tick-hit" x="${num(x - 9)}" y="${num(y - 9)}" width="18" height="18"/><rect class="tick-box" x="${num(x - 6)}" y="${num(y - 6)}" width="12" height="12" rx="2"/><path class="tick-mark" d="M${num(x - 3)},${num(y)} L${num(x - 1)},${num(y + 3)} L${num(x + 3.5)},${num(y - 3)}"/></g>`;
3541
- var tickRow = (id) => `<label class="tick-row"><input type="checkbox" data-tick-for="${esc(id)}"> Reviewed</label>`;
3872
+ var panelTitle = (id, text) => `<h2 class="ptitle"><input type="checkbox" data-tick-for="${esc(id)}" aria-label="Reviewed"><span>${esc(text)}</span></h2>`;
3542
3873
  var note = (l) => l.label || (l.kind !== "other" ? l.kind : void 0);
3543
3874
  function relationsOf(id, links, labelOf2) {
3544
3875
  return links.flatMap((l) => {
@@ -3548,12 +3879,10 @@ function relationsOf(id, links, labelOf2) {
3548
3879
  return [{ out, id: other, label: labelOf2(other), ...note(l) ? { kind: note(l) } : {} }];
3549
3880
  });
3550
3881
  }
3882
+ var relList = (rels) => rels.length ? `<ul>${rels.map((r) => `<li><button type="button" class="rel" data-goto="${esc(r.id)}">${esc(r.label)}${r.kind ? ` (${esc(r.kind)})` : ""}</button></li>`).join("")}</ul>` : '<p class="rel-none">none</p>';
3551
3883
  function relationsHtml(rels) {
3552
3884
  if (!rels.length) return "";
3553
- const rows = rels.map(
3554
- (r) => `<li><button type="button" class="rel" data-goto="${esc(r.id)}">${r.out ? "\u2192" : "\u2190"} ${esc(r.label)}${r.kind ? ` (${esc(r.kind)})` : ""}</button></li>`
3555
- );
3556
- return `<h3>Relations</h3><ul class="relations">${rows.join("")}</ul>`;
3885
+ return `<h3>Relations</h3><div class="relations"><div class="rel-col"><h4>\u2190 Used by</h4>${relList(rels.filter((r) => !r.out))}</div><div class="rel-col"><h4>Uses \u2192</h4>${relList(rels.filter((r) => r.out))}</div></div>`;
3557
3886
  }
3558
3887
 
3559
3888
  // src/render/web/diagram.ts
@@ -3706,7 +4035,7 @@ var FLOW_CSS = `
3706
4035
  .node .shape{fill:var(--card);stroke:var(--muted);stroke-width:1.2}
3707
4036
  .node .label{font-weight:500;text-anchor:middle}
3708
4037
  .node .badge{text-anchor:middle;font-weight:600}
3709
- .node.selected .shape{stroke-width:2.5}
4038
+ .node.selected .shape{stroke-width:3}
3710
4039
  .node:focus-visible .shape{stroke:var(--edge);stroke-width:3.5}
3711
4040
  .status-new .shape{stroke:var(--new)}
3712
4041
  .status-changed .shape{stroke:var(--chg)}
@@ -3767,7 +4096,20 @@ function renderLink(link, e, tone, ends) {
3767
4096
  });
3768
4097
  }
3769
4098
  var pathHtml = (p) => esc(p).replaceAll("/", "/<wbr>");
3770
- var codeRow = (n, code, cls) => `<span class="ln">${n ?? ""}</span><span${cls ? ` class="${cls}"` : ""}>${code}</span>`;
4099
+ var TAB = 4;
4100
+ var splitIndent = (code) => {
4101
+ const rest = code.trimStart();
4102
+ const lead = code.slice(0, code.length - rest.length);
4103
+ const width = [...lead].reduce((w, c) => w + (c === " " ? TAB : 1), 0);
4104
+ return [width, lead ? `<span class="ind">${lead}</span>${rest}` : rest];
4105
+ };
4106
+ var codeRow = (n, code, cls, sign) => {
4107
+ const cl = (c) => c ? ` class="${c}"` : "";
4108
+ const [indent, text] = n === void 0 ? [0, code] : splitIndent(code);
4109
+ const pad2 = indent ? ` style="padding-left:${indent}ch;text-indent:-${indent}ch"` : "";
4110
+ if (sign === void 0) return `<span class="ln">${n ?? ""}</span><span${cl(cls)}${pad2}>${text}</span>`;
4111
+ return `<span class="${cls} dr"><span class="ln">${n ?? ""}</span><span class="sg">${sign}</span><span class="cd"${pad2}>${text}</span></span>`;
4112
+ };
3771
4113
  function snippetHtml(s) {
3772
4114
  const code = s.lines.map((l, i) => codeRow(s.startLine + i, esc(l))).join("\n");
3773
4115
  const end = Number(s.source.match(/-(\d+)$/)?.[1] ?? s.startLine);
@@ -3777,7 +4119,7 @@ function snippetHtml(s) {
3777
4119
  }
3778
4120
  var tag = (status) => `<span class="tag tag-${esc(status)}">${esc(status)}</span>`;
3779
4121
  function stepPanel(spec, step, snippets, byId, check) {
3780
- let out = `<h2>${esc(step.label)}</h2>${tickRow(step.id)}`;
4122
+ let out = panelTitle(step.id, step.label);
3781
4123
  out += `<div class="status">${tag(step.status)} ${esc(step.type)}</div>`;
3782
4124
  out += mismatchNote(check, step.id);
3783
4125
  const snip = snippets.steps.get(step.id);
@@ -3848,6 +4190,82 @@ function renderFlowHtml(spec, layout, snippets, meta, check) {
3848
4190
  });
3849
4191
  }
3850
4192
 
4193
+ // src/render/web/changes.ts
4194
+ var GAP_MIN = 4;
4195
+ var MARK3 = { add: "+", del: "-", ctx: " " };
4196
+ var HEADER = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@ ?(.*)$/;
4197
+ function hunksOf(lines) {
4198
+ const out = [];
4199
+ for (const l of lines) {
4200
+ if (l.kind === "hunk") out.push([l]);
4201
+ else out.at(-1)?.push(l);
4202
+ }
4203
+ return out;
4204
+ }
4205
+ function headerOf(rows) {
4206
+ const m = HEADER.exec(rows[0].text);
4207
+ return m ? { start: Number(m[1]), count: m[2] === void 0 ? 1 : Number(m[2]), fn: m[3] ?? "" } : void 0;
4208
+ }
4209
+ var span2 = (h) => h.count === 0 ? [h.start + 1, h.start] : [h.start, h.start + h.count - 1];
4210
+ var PAGER = '<div class="pager" role="group" aria-label="Hunks"><button type="button" class="pg-prev" aria-label="Previous hunk" title="Previous hunk (p)">\u2039</button><span class="pg-count" role="status" aria-label="{n} hunks">\u2013 / {n}</span><button type="button" class="pg-next" aria-label="Next hunk" title="Next hunk (n)">\u203A</button><button type="button" class="pg-all pg-expand" aria-label="Expand all" title="Expand all hunks">+ all</button><button type="button" class="pg-all pg-collapse" aria-label="Collapse all" title="Collapse all hunks">\u2212 all</button><button type="button" class="pg-keys" aria-label="Show keys" title="Keys">? keys</button></div>';
4211
+ var plural2 = (n, what) => `${n} ${what}${n === 1 ? "" : "s"}`;
4212
+ var count = (n) => plural2(n, "changed line");
4213
+ var counts = (add, del, cls) => `<span class="${cls}"><span class="n-add">+${add}</span> <span class="n-del">\u2212${del}</span></span>`;
4214
+ var tally = (rows) => ({ add: rows.filter((l) => l.kind === "add").length, del: rows.filter((l) => l.kind === "del").length });
4215
+ function head(rows) {
4216
+ const h = headerOf(rows);
4217
+ const body = rows.slice(1);
4218
+ const { add, del } = tally(body);
4219
+ const first = body.find((l) => l.kind !== "ctx");
4220
+ return `<button type="button" class="hunk-sum hh" aria-expanded="false"><span class="caret" aria-hidden="true"></span>` + (h ? `<span class="hs-ln">L${h.start}</span>` : "") + (h?.fn ? `<span class="hs-fn">${esc(h.fn)}</span>` : "") + (first ? `<span class="hs-first">${esc(MARK3[first.kind] + first.text.trim())}</span>` : "") + `${counts(add, del, "hs-stat")}</button>`;
4221
+ }
4222
+ function outside(prev, cur) {
4223
+ if (!cur) return "";
4224
+ const n = span2(cur)[0] - (prev ? span2(prev)[1] : 0) - 1;
4225
+ if (n <= 0) return "";
4226
+ return `<div class="gap gap-out">\u22EF ${plural2(n, "line")} ${prev ? "not in the diff" : "above"}</div>`;
4227
+ }
4228
+ var rowsHtml = (rows) => rows.map((l) => codeRow(l.n, esc(l.text), `d-${l.kind}`, MARK3[l.kind])).join("\n");
4229
+ function bodyHtml(rows) {
4230
+ const out = [];
4231
+ let j = 1;
4232
+ while (j < rows.length) {
4233
+ let k = j;
4234
+ while (k < rows.length && rows[k].kind === "ctx") k++;
4235
+ if (k - j >= GAP_MIN) {
4236
+ out.push(
4237
+ `<span class="cgap"><button type="button" class="gap gap-run" aria-expanded="false">\u22EF ${plural2(k - j, "unchanged line")}</button><span class="gap-rows">${rowsHtml(rows.slice(j, k))}</span></span>`
4238
+ );
4239
+ j = k;
4240
+ } else {
4241
+ out.push(rowsHtml([rows[j]]));
4242
+ j++;
4243
+ }
4244
+ }
4245
+ return out.join("\n");
4246
+ }
4247
+ function totals(p) {
4248
+ const { add, del } = tally(p.lines);
4249
+ return p.rows > p.lines.length ? `<span class="fh-stat">${count(p.total)}</span>` : counts(add, del, "fh-stat");
4250
+ }
4251
+ var samePath = (p, nodePath) => nodePath?.replace(/:\d+(?:-\d+)?$/, "").replace(/^\.\//, "") === p.path;
4252
+ function changesHtml(p, nodePath) {
4253
+ const title = "<h3>Changes</h3>";
4254
+ if (p.note) return `${title}<p class="more">${esc(p.note)}</p>`;
4255
+ const hunks = hunksOf(p.lines);
4256
+ const pager = hunks.length > 1 ? PAGER.replaceAll("{n}", String(hunks.length)) : "";
4257
+ let prev;
4258
+ const body = hunks.map((rows) => {
4259
+ const cur = headerOf(rows);
4260
+ const gap = outside(prev, cur);
4261
+ prev = cur;
4262
+ return `<div class="hunk folded">${gap}${head(rows)}<code class="hunk-body">${bodyHtml(rows)}</code></div>`;
4263
+ });
4264
+ const file = samePath(p, nodePath) ? "" : `<div class="file-head"><span class="path">${pathHtml(p.path)}</span></div>`;
4265
+ const cut2 = p.rows > p.lines.length ? `<p class="more">showing ${p.lines.length} of ${p.rows} lines</p>` : "";
4266
+ return `<h3 class="ch-head">Changes${totals(p)}</h3>${pager}<div class="file">${file}<div class="snippet diff">${body.join("")}</div></div>${cut2}`;
4267
+ }
4268
+
3851
4269
  // src/render/web/html.ts
3852
4270
  var FIELD_CHARS = 34;
3853
4271
  function clip(s, max) {
@@ -3881,13 +4299,13 @@ var SHAPE2 = {
3881
4299
  other: "other"
3882
4300
  };
3883
4301
  var FOLD = 12;
3884
- function cardShape(shape2, { x, y, w, h }, head) {
4302
+ function cardShape(shape2, { x, y, w, h }, head2) {
3885
4303
  const r = x + w;
3886
4304
  if (shape2 === "file") {
3887
4305
  return `<path class="card" d="M${x},${y} H${r - FOLD} L${r},${y + FOLD} V${y + h} H${x} Z"/><path class="fold" d="M${r - FOLD},${y} V${y + FOLD} H${r}"/>`;
3888
4306
  }
3889
4307
  const card = `<rect class="card" x="${x}" y="${y}" width="${w}" height="${h}"${shape2 === "symbol" ? "" : ' rx="6"'}/>`;
3890
- return shape2 === "data" ? card + `<line class="head" x1="${x}" y1="${y + head - 3}" x2="${r}" y2="${y + head - 3}"/>` : card;
4308
+ return shape2 === "data" ? card + `<line class="head" x1="${x}" y1="${y + head2 - 3}" x2="${r}" y2="${y + head2 - 3}"/>` : card;
3891
4309
  }
3892
4310
  function renderNode(n, box, flag, fields, rev) {
3893
4311
  const flagged2 = flag !== "";
@@ -3895,8 +4313,8 @@ function renderNode(n, box, flag, fields, rev) {
3895
4313
  const y = Math.round(box.y * 10) / 10;
3896
4314
  const w = box.w;
3897
4315
  const lines = [];
3898
- const head = headerHeight(n.label);
3899
- let row = head;
4316
+ const head2 = headerHeight(n.label);
4317
+ let row = head2;
3900
4318
  const text = (cls, s) => {
3901
4319
  lines.push(`<text class="${cls}" x="${x + 8}" y="${y + row + 12}">${esc(s)}</text>`);
3902
4320
  row += 16;
@@ -3908,20 +4326,9 @@ function renderNode(n, box, flag, fields, rev) {
3908
4326
  const height = Math.max(row, Math.round(box.h * 10) / 10);
3909
4327
  const shape2 = SHAPE2[n.kind];
3910
4328
  const top = y + 18 + KIND_ROW;
3911
- return `<g class="node status-${n.status} shape-${shape2}" data-id="${esc(n.id)}" data-status="${n.status}"${rev ? ` data-rev="${rev}"` : ""} tabindex="0" role="button" aria-label="${esc(`${n.label} (${nodeWhat(n)}${flagged2 ? ", doesn't match the code" : ""})`)}">` + flag + cardShape(shape2, { x, y, w, h: height }, head) + `<line class="head" x1="${x}" y1="${y + head}" x2="${x + w}" y2="${y + head}"/>` + (n.kind === "other" ? "" : `<text class="kind" x="${x + 8}" y="${y + 12}">${n.kind}</text>`) + labelLines(n.label).map((l, i) => `<text class="label" x="${x + 8}" y="${top + i * LABEL_LINE_HEIGHT}">${esc(l)}</text>`).join("") + `<text class="badge" x="${x + w - 8}" y="${top}">${esc(n.status)}</text>` + lines.join("") + tickSvg(x, y) + (flagged2 ? flagMark(shape2 === "file" ? x + w - FOLD - 6 : x + w, y) : "") + `</g>`;
4329
+ return `<g class="node status-${n.status} shape-${shape2}" data-id="${esc(n.id)}" data-status="${n.status}"${rev ? ` data-rev="${rev}"` : ""} tabindex="0" role="button" aria-label="${esc(`${n.label} (${nodeWhat(n)}${flagged2 ? ", doesn't match the code" : ""})`)}">` + flag + cardShape(shape2, { x, y, w, h: height }, head2) + `<line class="head" x1="${x}" y1="${y + head2}" x2="${x + w}" y2="${y + head2}"/>` + (n.kind === "other" ? "" : `<text class="kind" x="${x + 8}" y="${y + 12}">${n.kind}</text>`) + labelLines(n.label).map((l, i) => `<text class="label" x="${x + 8}" y="${top + i * LABEL_LINE_HEIGHT}">${esc(l)}</text>`).join("") + `<text class="badge" x="${x + w - 8}" y="${top}">${esc(n.status)}</text>` + lines.join("") + tickSvg(x, y) + (flagged2 ? flagMark(shape2 === "file" ? x + w - FOLD - 6 : x + w, y) : "") + `</g>`;
3912
4330
  }
3913
4331
  var FIELDS_NOTE = "Only the fields the agent saw are listed. Set <code>defaults.context: full</code> in <code>.codechart.yaml</code> to let it read the full definition.";
3914
- var DIFF_MARK = { add: "+", del: "-", ctx: " " };
3915
- function previewHtml(p) {
3916
- let out = "<h3>Changes</h3>";
3917
- if (p.note) return `${out}<p class="more">${esc(p.note)}</p>`;
3918
- const rows = p.lines.map(
3919
- (l) => l.kind === "hunk" ? codeRow(void 0, esc(l.text), "d-hunk") : codeRow(l.n, esc(DIFF_MARK[l.kind] + l.text), `d-${l.kind}`)
3920
- );
3921
- out += `<pre class="snippet diff"><code>${rows.join("\n")}</code></pre>`;
3922
- const count = p.shown < p.total ? `showing ${p.shown} of ${p.total} changed lines` : `${p.total} changed line${p.total === 1 ? "" : "s"}`;
3923
- return `${out}<p class="more">${count} \xB7 whole file: <span class="path">${pathHtml(p.path)}</span></p>`;
3924
- }
3925
4332
  var fieldList = (fields) => `<ul>${fields.map((f) => `<li${f.change ? ` class="field-${f.change}-t"` : ""}>${esc(fieldText(f))}</li>`).join("")}</ul>`;
3926
4333
  function fieldsHtml(n, sides2) {
3927
4334
  if (!sides2 || !nodeOn("now", n.status) || !nodeOn("after", n.status)) return `<h3>Fields</h3>${fieldList(n.fields)}`;
@@ -3931,14 +4338,14 @@ function fieldsHtml(n, sides2) {
3931
4338
  return `<h3>Fields now</h3>${fieldList(now)}<h3>Fields after</h3>${fieldList(after)}`;
3932
4339
  }
3933
4340
  function cardPanel(spec, n, check, previews, sides2) {
3934
- let out = `<h2>${esc(`${n.label} (${nodeWhat(n)})`)}</h2>${tickRow(n.id)}`;
4341
+ let out = panelTitle(n.id, `${n.label} (${nodeWhat(n)})`);
3935
4342
  out += mismatchNote(check, n.id);
3936
4343
  const match = check?.matches.get(n.id);
3937
4344
  if (match) out += snippetHtml(match);
3938
4345
  else if (n.path) out += `<div class="path">${pathHtml(n.path)}</div>`;
3939
4346
  if (n.summary) out += `<p>${esc(n.summary)}</p>`;
3940
4347
  const preview = previews?.get(n.id);
3941
- if (preview) out += previewHtml(preview);
4348
+ if (preview) out += changesHtml(preview, n.path);
3942
4349
  if (n.fields?.length) {
3943
4350
  out += fieldsHtml(n, sides2);
3944
4351
  if (n.fieldsComplete === false) out += `<p class="fields-note">${FIELDS_NOTE}</p>`;
@@ -4026,14 +4433,14 @@ function checkLines(spec, check) {
4026
4433
  return lines;
4027
4434
  }
4028
4435
  function nodeDetail(n, check) {
4029
- const head = `- **${nodeName(n)}** \xB7 ${nodeWhat(n)}${n.path ? ` \xB7 \`${n.path.replace(/`/g, "")}\`` : ""}`;
4436
+ const head2 = `- **${nodeName(n)}** \xB7 ${nodeWhat(n)}${n.path ? ` \xB7 \`${n.path.replace(/`/g, "")}\`` : ""}`;
4030
4437
  const lines = [];
4031
4438
  const m = check?.mismatches.find((x) => x.id === n.id);
4032
4439
  if (m) lines.push(`\u2717 ${md(m.detail)}`);
4033
4440
  if (n.summary) lines.push(md(n.summary));
4034
4441
  if (n.fields?.length) lines.push(`Fields: ${n.fields.map((f) => md(fieldText(f))).join(" \xB7 ")}${n.fieldsComplete === false ? " (only the ones the agent saw)" : ""}`);
4035
4442
  for (const note2 of n.notes ?? []) lines.push(`Note: ${md(note2)}`);
4036
- return [head, ...lines.map((l) => ` - ${l}`)].join("\n");
4443
+ return [head2, ...lines.map((l) => ` - ${l}`)].join("\n");
4037
4444
  }
4038
4445
  var MAX_FILES2 = 8;
4039
4446
  var fileList = (files) => {
@@ -4050,15 +4457,15 @@ ${JSON.stringify(spec).replace(/</g, "\\u003c").replace(/>/g, "\\u003e")}
4050
4457
  -->`;
4051
4458
  var imageHref = (url) => encodeURI(url).replace(/[()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
4052
4459
  function prBlock(spec, check, imageUrl) {
4053
- const count = (s) => spec.nodes.filter((n) => n.status === s).length;
4054
- const counts = [`${spec.nodes.length} nodes`, `${count("new")} new`, `${count("changed")} changed`, ...count("removed") ? [`${count("removed")} removed`] : []].join(" \xB7 ");
4460
+ const count2 = (s) => spec.nodes.filter((n) => n.status === s).length;
4461
+ const counts2 = [`${spec.nodes.length} nodes`, `${count2("new")} new`, `${count2("changed")} changed`, ...count2("removed") ? [`${count2("removed")} removed`] : []].join(" \xB7 ");
4055
4462
  const url = imageHref(imageUrl);
4056
4463
  const nodes = [...spec.nodes].sort((a, b) => STATUS_ORDER.indexOf(a.status) - STATUS_ORDER.indexOf(b.status));
4057
4464
  const parts = [
4058
4465
  BLOCK_START,
4059
4466
  `<details><summary>Map: ${esc(flat(spec.title))}</summary>`,
4060
4467
  "",
4061
- [counts, checkHeadline(check)].filter(Boolean).join(" \xB7 "),
4468
+ [counts2, checkHeadline(check)].filter(Boolean).join(" \xB7 "),
4062
4469
  "",
4063
4470
  `[![${md(spec.title)}](${url})](${url})`
4064
4471
  ];
@@ -4201,12 +4608,12 @@ import { realpathSync as realpathSync4, statSync as statSync2 } from "fs";
4201
4608
  import { isAbsolute as isAbsolute3, relative as relative2, resolve as resolve5, sep as sep3 } from "path";
4202
4609
 
4203
4610
  // src/render/clip.ts
4204
- var MAX_CHARS = 300;
4205
- var clip2 = (l) => l.length > MAX_CHARS ? `${l.slice(0, MAX_CHARS)}\u2026` : l;
4611
+ var MAX_CHARS2 = 300;
4612
+ var clip2 = (l) => l.length > MAX_CHARS2 ? `${l.slice(0, MAX_CHARS2)}\u2026` : l;
4206
4613
 
4207
4614
  // src/render/flow/anchors.ts
4208
4615
  var SNIPPET_MAX_LINES = 15;
4209
- var MAX_BYTES2 = 5 * 1024 * 1024;
4616
+ var MAX_BYTES3 = 5 * 1024 * 1024;
4210
4617
  var MAX_TOTAL_BYTES = 25 * 1024 * 1024;
4211
4618
  var escapes = (rel) => rel === ".." || rel.startsWith(`..${sep3}`) || isAbsolute3(rel);
4212
4619
  var inGit = (rel) => rel.split(sep3).some((s) => s.toLowerCase() === ".git");
@@ -4221,7 +4628,7 @@ var overBudget = (path3) => ({
4221
4628
  function readLinesAt(path3, rel, root, sha, budget) {
4222
4629
  try {
4223
4630
  if (budget.left <= 0) return overBudget(path3);
4224
- const r = gitFileAt(root, sha, rel.split(sep3).join("/"), MAX_BYTES2);
4631
+ const r = gitFileAt(root, sha, rel.split(sep3).join("/"), MAX_BYTES3);
4225
4632
  if (typeof r !== "string") return r;
4226
4633
  budget.left -= Buffer.byteLength(r);
4227
4634
  return budget.left < 0 ? overBudget(path3) : toLines(r);
@@ -4244,7 +4651,7 @@ function readLines(path3, root, realRoot, budget) {
4244
4651
  let refused2;
4245
4652
  const text = readRegularFile(real, (st) => {
4246
4653
  if (!st.isFile()) refused2 = { error: `${path3} is not a regular file` };
4247
- else if (st.size > MAX_BYTES2) refused2 = { error: `${path3} is too large (over 5 MB)` };
4654
+ else if (st.size > MAX_BYTES3) refused2 = { error: `${path3} is too large (over 5 MB)` };
4248
4655
  else if (st.size > budget.left) refused2 = overBudget(path3);
4249
4656
  else budget.left -= st.size;
4250
4657
  return refused2 === void 0;
@@ -4319,8 +4726,8 @@ function present2(c, path3) {
4319
4726
  }
4320
4727
  function withCwd(c, path3, get, missing) {
4321
4728
  const direct = get(path3);
4322
- const outside = !isAbsolute3(path3) && escapes(relative2(c.root, resolve5(c.root, path3)));
4323
- if (c.cwd && (missing(direct) || outside)) {
4729
+ const outside2 = !isAbsolute3(path3) && escapes(relative2(c.root, resolve5(c.root, path3)));
4730
+ if (c.cwd && (missing(direct) || outside2)) {
4324
4731
  const rel = relative2(c.root, resolve5(c.cwd, path3));
4325
4732
  if (rel !== "" && !escapes(rel)) {
4326
4733
  const alt = rel.split(sep3).join("/");
@@ -4485,8 +4892,8 @@ var shownFields = (node) => {
4485
4892
  return [];
4486
4893
  };
4487
4894
  var fieldItem = (f) => flat(`${f.change ? FIELD_MARK2[f.change] : ""}${f.name}${f.was !== void 0 ? ` ${f.was} \u2192 ${f.type ?? "?"}` : f.type ? ` ${f.type}` : ""}`);
4488
- function arrowLines(head, links, byId, { width, color, cuts }) {
4489
- const indent = columns(head.text) + 1;
4895
+ function arrowLines(head2, links, byId, { width, color, cuts }) {
4896
+ const indent = columns(head2.text) + 1;
4490
4897
  const labels = links.map((e) => `${e.change ? EDGE_MARK[e.change] : ""}${flat(e.label ?? "")}`);
4491
4898
  const targets = links.map((e) => byId.get(e.to));
4492
4899
  const longest = Math.max(...labels.map(columns));
@@ -4499,7 +4906,7 @@ function arrowLines(head, links, byId, { width, color, cuts }) {
4499
4906
  const target = targets[i];
4500
4907
  return fit(
4501
4908
  [
4502
- i === 0 ? head : { text: " ".repeat(columns(head.text)) },
4909
+ i === 0 ? head2 : { text: " ".repeat(columns(head2.text)) },
4503
4910
  { text: ` ${arrow} ` },
4504
4911
  { text: truncate(kindLabel(target), width - indent - 4 - col, cuts), paint: color ? (s) => paint(target, s) : void 0 }
4505
4912
  ],
@@ -4512,8 +4919,8 @@ function blockLines(node, links, fields, byId, ctx) {
4512
4919
  const { width, color, cuts } = ctx;
4513
4920
  const cap = links.length > 0 ? Math.floor(width / 3) : width - columns(gutter(node.status));
4514
4921
  const text = `${gutter(node.status)}${truncate(kindLabel(node), cap, cuts)}`;
4515
- const head = { text, paint: color ? (s) => paint(node, s) : void 0 };
4516
- const lines = links.length > 0 ? arrowLines(head, links, byId, ctx) : [head.paint ? head.paint(text) : text];
4922
+ const head2 = { text, paint: color ? (s) => paint(node, s) : void 0 };
4923
+ const lines = links.length > 0 ? arrowLines(head2, links, byId, ctx) : [head2.paint ? head2.paint(text) : text];
4517
4924
  if (fields.length > 0) lines.push(wrapItems(DETAIL, fields.map(fieldItem), width));
4518
4925
  return lines;
4519
4926
  }
@@ -4591,10 +4998,10 @@ function defaultWidth(stdout = process.stdout, env = process.env) {
4591
4998
  return Number.isFinite(fromEnv) && fromEnv > 0 && fromEnv <= MAX_ENV_WIDTH ? fromEnv : NOT_TTY_WIDTH;
4592
4999
  }
4593
5000
  function footer(spec, hidden, { width, htmlPath, check }, keyLine) {
4594
- const count = (status) => spec.nodes.filter((n) => n.status === status).length;
4595
- const removed = count("removed") > 0 ? ` \xB7 ${count("removed")} removed` : "";
5001
+ const count2 = (status) => spec.nodes.filter((n) => n.status === status).length;
5002
+ const removed = count2("removed") > 0 ? ` \xB7 ${count2("removed")} removed` : "";
4596
5003
  const lines = [
4597
- countLines(`${spec.nodes.length} nodes \xB7 ${count("new")} new \xB7 ${count("changed")} changed${removed} \xB7 ${count("config")} config`, check, width)
5004
+ countLines(`${spec.nodes.length} nodes \xB7 ${count2("new")} new \xB7 ${count2("changed")} changed${removed} \xB7 ${count2("config")} config`, check, width)
4598
5005
  ];
4599
5006
  if (keyLine) lines.push(truncate(KEY2, width));
4600
5007
  if (spec.gaps?.length) lines.push(wrapItems("gaps: ", spec.gaps.map(flat), width));
@@ -4679,17 +5086,17 @@ function walkFlow(spec, budget) {
4679
5086
  return shared.has(to) ? { items: [ref(step)] } : chain(step, false);
4680
5087
  };
4681
5088
  const start = byId.get(spec.start);
4682
- let head;
5089
+ let head2;
4683
5090
  if (shared.has(start.id)) {
4684
5091
  if (!take(start.id)) return { blocks: [], unreachable: 0, truncated: true };
4685
5092
  queue.push(start.id);
4686
- head = { shared: true, chain: chain(start, true) };
5093
+ head2 = { shared: true, chain: chain(start, true) };
4687
5094
  } else {
4688
- head = { shared: false, chain: chain(start, false) };
5095
+ head2 = { shared: false, chain: chain(start, false) };
4689
5096
  }
4690
- if (head.chain.items.some((i) => i.kind === "cut")) return { blocks: [], unreachable: 0, truncated: true };
4691
- const blocks2 = [head];
4692
- for (let i = head.shared ? 1 : 0; i < queue.length; i++) {
5097
+ if (head2.chain.items.some((i) => i.kind === "cut")) return { blocks: [], unreachable: 0, truncated: true };
5098
+ const blocks2 = [head2];
5099
+ for (let i = head2.shared ? 1 : 0; i < queue.length; i++) {
4693
5100
  blocks2.push({ shared: true, chain: chain(byId.get(queue[i]), true) });
4694
5101
  }
4695
5102
  const unreachable = spec.steps.filter((s) => !seen.has(s.id)).length;
@@ -4749,13 +5156,13 @@ function armLines(arms, rest, ctx) {
4749
5156
  const last = i === arms.length - 1;
4750
5157
  const glyph = last ? "\u2514\u2500 " : "\u251C\u2500 ";
4751
5158
  const label = truncate(labels[i], pad2, ctx.cuts);
4752
- const head = [{ text: rest + glyph }];
5159
+ const head2 = [{ text: rest + glyph }];
4753
5160
  if (pad2 > 0) {
4754
5161
  const paint2 = tones[i] ? painter(tones[i], ctx) : void 0;
4755
- head.push({ text: label, paint: paint2 }, { text: `${" ".repeat(pad2 - columns(label))} \u2192 ` });
5162
+ head2.push({ text: label, paint: paint2 }, { text: `${" ".repeat(pad2 - columns(label))} \u2192 ` });
4756
5163
  }
4757
5164
  const under2 = `${rest}${last ? " " : "\u2502 "}${pad2 > 0 ? " ".repeat(pad2 + 3) : ""}`;
4758
- return chainLines(arm.chain, head, under2, "", ctx);
5165
+ return chainLines(arm.chain, head2, under2, "", ctx);
4759
5166
  });
4760
5167
  }
4761
5168
  function chainLines(chain, first, rest, lead, ctx) {
@@ -4766,18 +5173,18 @@ function chainLines(chain, first, rest, lead, ctx) {
4766
5173
  prefix = [{ text: rest }];
4767
5174
  }
4768
5175
  if (chain.branch) {
4769
- const { head, arms } = chain.branch;
4770
- const glyph = head.type === "decision" ? "\u25C7 " : "";
4771
- lines.push(fit([...prefix, { text: glyph }, stepSegment(head, ctx)], ctx.width, ctx.cuts));
5176
+ const { head: head2, arms } = chain.branch;
5177
+ const glyph = head2.type === "decision" ? "\u25C7 " : "";
5178
+ lines.push(fit([...prefix, { text: glyph }, stepSegment(head2, ctx)], ctx.width, ctx.cuts));
4772
5179
  lines.push(...armLines(arms, rest, ctx));
4773
5180
  }
4774
5181
  return lines;
4775
5182
  }
4776
5183
  function footer2(spec, ctx, md2) {
4777
- const count = (status) => spec.steps.filter((s) => s.status === status).length;
5184
+ const count2 = (status) => spec.steps.filter((s) => s.status === status).length;
4778
5185
  const lines = [
4779
5186
  countLines(
4780
- `${spec.steps.length} steps \xB7 ${count("new")} new \xB7 ${count("changed")} changed \xB7 ${count("planned")} planned${count("removed") ? ` \xB7 ${count("removed")} removed` : ""}`,
5187
+ `${spec.steps.length} steps \xB7 ${count2("new")} new \xB7 ${count2("changed")} changed \xB7 ${count2("planned")} planned${count2("removed") ? ` \xB7 ${count2("removed")} removed` : ""}`,
4781
5188
  ctx.check,
4782
5189
  ctx.width
4783
5190
  )
@@ -4808,12 +5215,12 @@ function renderFlowTree(spec, opts) {
4808
5215
  const md2 = opts.md ?? false;
4809
5216
  const alert = alertLine(opts.check, ctx.width);
4810
5217
  if (walk.blocks.length === 0) {
4811
- const head = webAlert(opts.check, ctx.width);
4812
- const body = (line) => head ? `${head}
5218
+ const head2 = webAlert(opts.check, ctx.width);
5219
+ const body = (line) => head2 ? `${head2}
4813
5220
  ${line}` : line;
4814
5221
  if (!opts.htmlPath) return { text: md2 ? flowMarkdown(spec.title, body(TOO_LARGE), ctx, flowKey(spec)) : `${body(TOO_LARGE)}
4815
5222
  `, truncated: true };
4816
- const text2 = md2 ? flowMarkdown(spec.title, head || void 0, ctx, flowKey(spec)) : `${body(fullMapLine(opts.htmlPath))}
5223
+ const text2 = md2 ? flowMarkdown(spec.title, head2 || void 0, ctx, flowKey(spec)) : `${body(fullMapLine(opts.htmlPath))}
4817
5224
  `;
4818
5225
  return { text: text2, truncated: true };
4819
5226
  }
@@ -5150,22 +5557,47 @@ import { writeFileSync as writeFileSync6 } from "fs";
5150
5557
  // src/render/preview.ts
5151
5558
  import { lstatSync as lstatSync9, realpathSync as realpathSync5 } from "fs";
5152
5559
  import { dirname as dirname7, join as join19, resolve as resolve9, sep as sep5 } from "path";
5153
- var MAX_HUNKS = 3;
5154
- var MAX_LINES2 = 40;
5155
- var MAX_BYTES3 = 5 * 1024 * 1024;
5560
+
5561
+ // src/render/generated.ts
5562
+ var LOCKFILES = /* @__PURE__ */ new Set([
5563
+ "package-lock.json",
5564
+ "npm-shrinkwrap.json",
5565
+ "yarn.lock",
5566
+ "pnpm-lock.yaml",
5567
+ "bun.lock",
5568
+ "Cargo.lock",
5569
+ "Gemfile.lock",
5570
+ "poetry.lock",
5571
+ "composer.lock",
5572
+ "go.sum"
5573
+ ]);
5574
+ var byName = (rel) => LOCKFILES.has(rel.slice(rel.lastIndexOf("/") + 1)) || /\.min\.(js|css)$/.test(rel) || /(^|\/)dist\//.test(rel);
5575
+ function generatedFiles(root, rels) {
5576
+ let attr = /* @__PURE__ */ new Map();
5577
+ try {
5578
+ attr = gitGeneratedAttr(root, rels.filter((r) => !r.includes("\n")));
5579
+ } catch {
5580
+ }
5581
+ return new Set(rels.filter((r) => attr.get(r) ?? byName(r)));
5582
+ }
5583
+
5584
+ // src/render/preview.ts
5585
+ var MAX_ROWS = 1e3;
5586
+ var MAX_BYTES4 = 5 * 1024 * 1024;
5156
5587
  var MAX_TOTAL_BYTES2 = 25 * 1024 * 1024;
5157
5588
  function parseDiff(path3, text) {
5158
- const p = { path: path3, lines: [], shown: 0, total: 0 };
5589
+ const p = { path: path3, lines: [], total: 0, rows: 0 };
5159
5590
  let hunks = 0;
5160
5591
  let oldN = 0;
5161
5592
  let newN = 0;
5162
- const room = () => hunks <= MAX_HUNKS && p.lines.length < MAX_LINES2;
5593
+ const room = () => p.lines.length < MAX_ROWS;
5163
5594
  for (const raw of text.split("\n")) {
5164
5595
  const h = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(raw);
5165
5596
  if (h) {
5166
5597
  hunks++;
5167
5598
  oldN = Number(h[1]);
5168
5599
  newN = Number(h[2]);
5600
+ p.rows++;
5169
5601
  if (room()) p.lines.push({ kind: "hunk", text: clip2(raw) });
5170
5602
  continue;
5171
5603
  }
@@ -5181,32 +5613,32 @@ function parseDiff(path3, text) {
5181
5613
  oldN++;
5182
5614
  } else continue;
5183
5615
  if (line.kind !== "ctx") p.total++;
5184
- if (!room()) continue;
5185
- p.lines.push({ ...line, text: clip2(line.text.replace(/\r$/, "")) });
5186
- if (line.kind !== "ctx") p.shown++;
5616
+ p.rows++;
5617
+ if (room()) p.lines.push({ ...line, text: clip2(line.text.replace(/\r$/, "")) });
5187
5618
  }
5188
5619
  return p;
5189
5620
  }
5190
5621
  var TOO_LARGE2 = "diff is too large (over 5 MB)";
5191
5622
  var OVER_BUDGET = "not shown: the diffs pass 25 MB together";
5623
+ var GENERATED = { note: "generated file, not shown" };
5192
5624
  function untrackedPreview(root, rel, budget, max) {
5193
5625
  let size = 0;
5194
5626
  const text = readRegularFile(join19(root, rel), (st) => st.isFile() && (size = st.size) <= max);
5195
- if (text === void 0) return { note: size > MAX_BYTES3 ? TOO_LARGE2 : size > max ? OVER_BUDGET : "not a regular file" };
5627
+ if (text === void 0) return { note: size > MAX_BYTES4 ? TOO_LARGE2 : size > max ? OVER_BUDGET : "not a regular file" };
5196
5628
  if (text.includes("\0")) return { note: "binary file" };
5197
5629
  if (PRIVATE_KEY.test(text)) return SECRET;
5198
5630
  budget.left -= Buffer.byteLength(text);
5199
5631
  const all = text.split("\n");
5200
5632
  if (all[all.length - 1] === "") all.pop();
5201
- const shown = all.slice(0, MAX_LINES2 - 1);
5633
+ const kept = all.slice(0, MAX_ROWS - 1);
5202
5634
  return {
5203
5635
  path: rel,
5204
5636
  lines: [
5205
5637
  { kind: "hunk", text: `@@ -0,0 +1,${all.length} @@` },
5206
- ...shown.map((l, i) => ({ kind: "add", n: i + 1, text: clip2(l.replace(/\r$/, "")) }))
5638
+ ...kept.map((l, i) => ({ kind: "add", n: i + 1, text: clip2(l.replace(/\r$/, "")) }))
5207
5639
  ],
5208
- shown: shown.length,
5209
- total: all.length
5640
+ total: all.length,
5641
+ rows: all.length + 1
5210
5642
  };
5211
5643
  }
5212
5644
  var SECRET = { note: "not shown: looks like a secret" };
@@ -5231,10 +5663,10 @@ var worktreeSize = (root, rel) => {
5231
5663
  const path3 = join19(root, rel);
5232
5664
  return insideRoot(root, path3) ? lstatSync9(path3, { throwIfNoEntry: false })?.size ?? 0 : 0;
5233
5665
  };
5234
- function prefetch(root, range, rels) {
5666
+ function prefetch(root, range, rels, generated) {
5235
5667
  const pre = noPrefetch();
5236
5668
  try {
5237
- const cands = rels.filter((r) => !looksSecret(r) && !r.includes("\n"));
5669
+ const cands = rels.filter((r) => !looksSecret(r) && !r.includes("\n") && !generated.has(r));
5238
5670
  const specs = cands.flatMap((r) => range.revs.map((rev) => `${rev}:${r}`));
5239
5671
  gitBlobSizes(root, specs).forEach((size, i) => pre.sizes.set(specs[i], size));
5240
5672
  let room = MAX_TOTAL_BYTES2;
@@ -5243,7 +5675,7 @@ function prefetch(root, range, rels) {
5243
5675
  for (const r of cands) {
5244
5676
  const keys = range.revs.map((rev) => `${rev}:${r}`).filter((k) => pre.sizes.get(k) !== void 0);
5245
5677
  const sizes = [...keys.map((k) => pre.sizes.get(k)), ...range.worktree ? [worktreeSize(root, r)] : []];
5246
- if (sizes.some((n) => n > MAX_BYTES3)) continue;
5678
+ if (sizes.some((n) => n > MAX_BYTES4)) continue;
5247
5679
  const cost = sizes.reduce((a, b) => a + b, 0);
5248
5680
  if (cost > room) break;
5249
5681
  room -= cost;
@@ -5266,7 +5698,7 @@ function prefetch(root, range, rels) {
5266
5698
  }
5267
5699
  function sides(root, range, rel, budget, pre) {
5268
5700
  const take = (size) => {
5269
- if (size > MAX_BYTES3) return TOO_LARGE2;
5701
+ if (size > MAX_BYTES4) return TOO_LARGE2;
5270
5702
  if (size > budget.left) return OVER_BUDGET;
5271
5703
  budget.left -= size;
5272
5704
  return void 0;
@@ -5291,15 +5723,16 @@ function sides(root, range, rel, budget, pre) {
5291
5723
  }
5292
5724
  return texts;
5293
5725
  }
5294
- function fileDiff(root, range, rel, budget, pre) {
5726
+ function fileDiff(root, range, rel, budget, pre, generated) {
5295
5727
  if (looksSecret(rel)) return SECRET;
5296
5728
  if (rel.includes("\n")) return { note: "not shown: the file name has a line break" };
5297
- let max = MAX_BYTES3;
5729
+ if (generated.has(rel)) return GENERATED;
5730
+ let max = MAX_BYTES4;
5298
5731
  try {
5299
5732
  const files = sides(root, range, rel, budget, pre);
5300
5733
  if (!Array.isArray(files)) return files;
5301
5734
  if (files.some((t) => PRIVATE_KEY.test(t))) return SECRET;
5302
- max = Math.min(MAX_BYTES3, budget.left);
5735
+ max = Math.min(MAX_BYTES4, budget.left);
5303
5736
  if (max <= 0) return { note: OVER_BUDGET };
5304
5737
  const batched = pre.diffs.get(rel);
5305
5738
  if (batched !== void 0 && Buffer.byteLength(batched) > max) throw new OutputTooLarge(`git output over ${max} bytes`);
@@ -5310,7 +5743,7 @@ function fileDiff(root, range, rel, budget, pre) {
5310
5743
  budget.left -= Buffer.byteLength(shown);
5311
5744
  return PRIVATE_KEY.test(shown) ? SECRET : shown;
5312
5745
  } catch (e) {
5313
- if (e instanceof OutputTooLarge) return { note: max < MAX_BYTES3 ? OVER_BUDGET : TOO_LARGE2 };
5746
+ if (e instanceof OutputTooLarge) return { note: max < MAX_BYTES4 ? OVER_BUDGET : TOO_LARGE2 };
5314
5747
  return { note: `diff not read (${e.message})` };
5315
5748
  }
5316
5749
  }
@@ -5325,15 +5758,17 @@ function nodePreviews(spec, root, diff, range, found, cwd) {
5325
5758
  const rel = candidates2.find((p) => diff.hasFile(p));
5326
5759
  if (rel !== void 0) rels.set(node.id, rel);
5327
5760
  }
5328
- const pre = prefetch(root, range, [...new Set(rels.values())]);
5761
+ const files = [...new Set(rels.values())];
5762
+ const generated = generatedFiles(root, files);
5763
+ const pre = prefetch(root, range, files, generated);
5329
5764
  const byFile = /* @__PURE__ */ new Map();
5330
5765
  const budget = { left: MAX_TOTAL_BYTES2 };
5331
5766
  for (const node of spec.nodes) {
5332
5767
  const rel = rels.get(node.id);
5333
5768
  if (rel === void 0) continue;
5334
5769
  if (!byFile.has(rel)) {
5335
- const r = budget.left > 0 ? fileDiff(root, range, rel, budget, pre) : { note: OVER_BUDGET };
5336
- byFile.set(rel, typeof r === "string" ? r === "" ? void 0 : parseDiff(rel, r) : "lines" in r ? r : { path: rel, lines: [], shown: 0, total: 0, note: r.note });
5770
+ const r = budget.left > 0 ? fileDiff(root, range, rel, budget, pre, generated) : { note: OVER_BUDGET };
5771
+ byFile.set(rel, typeof r === "string" ? r === "" ? void 0 : parseDiff(rel, r) : "lines" in r ? r : { path: rel, lines: [], total: 0, rows: 0, note: r.note });
5337
5772
  }
5338
5773
  const preview = byFile.get(rel);
5339
5774
  if (preview) out.set(node.id, preview);
@@ -5468,6 +5903,7 @@ async function renderSpec(arg, o, opts, cwd) {
5468
5903
  }
5469
5904
  const env = opts.env ?? process.env;
5470
5905
  const slug = fileSlug(spec.title, target.diagram);
5906
+ const update2 = checkAllowed({ enabled: config.updateCheck, env: { ...process.env, ...env } }) ? knownUpdate(config.web.outDir) : void 0;
5471
5907
  const ctx = {
5472
5908
  output,
5473
5909
  minNodes: config.web.minNodes,
@@ -5493,7 +5929,8 @@ async function renderSpec(arg, o, opts, cwd) {
5493
5929
  inEditor: inCodeEditor(env),
5494
5930
  open: opts.open ?? openInBrowser,
5495
5931
  stderr: opts.stderr,
5496
- update: checkAllowed({ enabled: config.updateCheck, env: { ...process.env, ...env } }) ? knownUpdate(config.web.outDir) : void 0
5932
+ update: update2,
5933
+ updateNotes: update2 ? knownHighlights(readState(config.web.outDir), currentVersion(), update2)?.bullets : void 0
5497
5934
  })
5498
5935
  };
5499
5936
  const { text, check, html } = target.diagram === "flow" ? await renderFlow(target.spec, target, ctx) : await renderMap(target.spec, ctx);