frameboard 0.4.0 → 0.6.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
@@ -9,7 +9,7 @@ import process$1, { versions } from "node:process";
9
9
  import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { constants, copyFile, cp, link, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat as stat$1, writeFile } from "node:fs/promises";
12
- import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
12
+ import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
13
13
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
14
14
  import { STATUS_CODES, ServerResponse, createServer } from "node:http";
15
15
  import { Http2ServerRequest, constants as constants$1 } from "node:http2";
@@ -9360,7 +9360,7 @@ async function isDirectory(path) {
9360
9360
  }
9361
9361
  //#endregion
9362
9362
  //#region package.json
9363
- var version$1 = "0.4.0";
9363
+ var version$1 = "0.6.0";
9364
9364
  var dependencies = { "playwright-core": "1.64.1" };
9365
9365
  //#endregion
9366
9366
  //#region src/shared/version.ts
@@ -9383,7 +9383,7 @@ const addressFileSchema = looseObject({
9383
9383
  //#endregion
9384
9384
  //#region src/server/address.ts
9385
9385
  /** How long a live server has to answer the health check. */
9386
- const HEALTH_TIMEOUT_MS = 500;
9386
+ const HEALTH_TIMEOUT_MS = 5e3;
9387
9387
  function addressPath(root) {
9388
9388
  return join(root, RUN_FOLDER, ADDRESS_FILE);
9389
9389
  }
@@ -9438,7 +9438,7 @@ async function removeAddress(root, token) {
9438
9438
  }
9439
9439
  /**
9440
9440
  * The server recorded for this board when it is live: its pid answers and its
9441
- * health check answers within 500 ms with the same root. Anything else is
9441
+ * health check answers within 5000 ms with the same root. Anything else is
9442
9442
  * stale, and a new `serve` replaces it.
9443
9443
  */
9444
9444
  async function findLiveServer(root) {
@@ -13548,6 +13548,124 @@ async function readAuthor(root, env = process.env) {
13548
13548
  }
13549
13549
  }
13550
13550
  //#endregion
13551
+ //#region src/shared/records/claims.ts
13552
+ /** One session's hold on a frame while its agent rewrites it. */
13553
+ const claimSchema = looseObject({
13554
+ /** The canonical frame ref, `<project>/<page>/<frame>`. */
13555
+ frame: string$1(),
13556
+ /** The session holding it, the id `inbox` and a note's `to` use. */
13557
+ session: string$1(),
13558
+ /** The agent's name, such as `claude`, whose first letter the board shows. */
13559
+ agent: string$1(),
13560
+ /** The listener's tag form, `<agent> · <project folder>`. */
13561
+ tag: string$1(),
13562
+ /** When the session first claimed it, kept across renewals. */
13563
+ claimedAt: string$1(),
13564
+ /** When it lapses unless the session claims it again. */
13565
+ expiresAt: string$1()
13566
+ });
13567
+ /**
13568
+ * Whether a write naming `ref` reaches the frame a claim holds, being the
13569
+ * frame itself, its page, or its project, so a page ref never matches a
13570
+ * sibling page whose name only starts the same.
13571
+ */
13572
+ function claimCovers(ref, frame) {
13573
+ return frame === ref || frame.startsWith(`${ref}/`);
13574
+ }
13575
+ /** `.run/claims.json`. */
13576
+ const claimsFileSchema = looseObject({
13577
+ version: literal(1),
13578
+ claims: array$1(claimSchema)
13579
+ });
13580
+ //#endregion
13581
+ //#region src/server/claims/store.ts
13582
+ /** How long a claim holds after its last claim or renewal. */
13583
+ const CLAIM_TTL_MS = 3e5;
13584
+ const claimsSpec = {
13585
+ schema: claimsFileSchema,
13586
+ invalidCode: "claims-invalid",
13587
+ empty: () => ({
13588
+ version: 1,
13589
+ claims: []
13590
+ })
13591
+ };
13592
+ function claimsPath(root) {
13593
+ return join(root, RUN_FOLDER, CLAIMS_FILE);
13594
+ }
13595
+ function isLive(claim, now) {
13596
+ return Date.parse(claim.expiresAt) > now.getTime();
13597
+ }
13598
+ /** The claims still live at `now`, refusing a file that does not parse. */
13599
+ async function readClaims(root, now) {
13600
+ return (await readRecord(claimsPath(root), claimsSpec)).claims.filter((claim) => isLive(claim, now));
13601
+ }
13602
+ /**
13603
+ * Claims a frame for a session, or renews the session's own claim keeping
13604
+ * `claimedAt`. A frame another session holds live refuses `frame-claimed`.
13605
+ */
13606
+ async function claim(root, fields, now) {
13607
+ await ensureRunFolder(root);
13608
+ return (await updateRecord(claimsPath(root), claimsSpec, (file) => {
13609
+ const live = file.claims.filter((each) => isLive(each, now));
13610
+ const current = live.find((each) => each.frame === fields.frame);
13611
+ if (current && current.session !== fields.session) throw new FrameboardError("frame-claimed", `${current.tag} is editing ${fields.frame} until ${current.expiresAt}.`, {
13612
+ frame: current.frame,
13613
+ session: current.session,
13614
+ tag: current.tag,
13615
+ expiresAt: current.expiresAt
13616
+ });
13617
+ const held = {
13618
+ ...fields,
13619
+ claimedAt: current?.claimedAt ?? now.toISOString(),
13620
+ expiresAt: new Date(now.getTime() + CLAIM_TTL_MS).toISOString()
13621
+ };
13622
+ return {
13623
+ ...file,
13624
+ claims: [...live.filter((each) => each !== current), held]
13625
+ };
13626
+ })).claims.at(-1);
13627
+ }
13628
+ /**
13629
+ * Drops a session's claim on one frame, or every claim it holds when no
13630
+ * frame is named, returning what it dropped.
13631
+ */
13632
+ async function release(root, session, frame, now) {
13633
+ const dropped = [];
13634
+ await ensureRunFolder(root);
13635
+ await updateRecord(claimsPath(root), claimsSpec, (file) => {
13636
+ const kept = [];
13637
+ for (const each of file.claims) {
13638
+ if (!isLive(each, now)) continue;
13639
+ (each.session === session && (frame === void 0 || each.frame === frame) ? dropped : kept).push(each);
13640
+ }
13641
+ return {
13642
+ ...file,
13643
+ claims: kept
13644
+ };
13645
+ });
13646
+ return dropped;
13647
+ }
13648
+ //#endregion
13649
+ //#region src/server/claims/gate.ts
13650
+ /**
13651
+ * Refuses `frame-claimed` when another session holds a frame the hand write
13652
+ * would change. Each ref is a frame, page, or project ref, and a page or
13653
+ * project ref matches every claim under it. The claims are read without the
13654
+ * lock, so a claim landing between this read and the write lets that one
13655
+ * write through, where the file hash still guards the agent's own write.
13656
+ */
13657
+ async function refuseClaimed(root, refs, now) {
13658
+ if (refs.length === 0) return;
13659
+ const held = (await readClaims(root, now)).find((claim) => refs.some((ref) => claimCovers(ref, claim.frame)));
13660
+ if (!held) return;
13661
+ throw new FrameboardError("frame-claimed", `${held.tag} is editing ${held.frame} until ${held.expiresAt}.`, {
13662
+ frame: held.frame,
13663
+ tag: held.tag,
13664
+ claimedAt: held.claimedAt,
13665
+ expiresAt: held.expiresAt
13666
+ });
13667
+ }
13668
+ //#endregion
13551
13669
  //#region node_modules/picocolors/picocolors.js
13552
13670
  var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
13553
13671
  let p = process || {};
@@ -27616,6 +27734,7 @@ const STATUS$4 = {
27616
27734
  "page-not-found": 404,
27617
27735
  "frame-not-found": 404,
27618
27736
  "stale-layout": 409,
27737
+ "frame-claimed": 409,
27619
27738
  "frame-locked": 423,
27620
27739
  "layout-invalid": 422,
27621
27740
  "lock-timeout": 503
@@ -27683,6 +27802,8 @@ function apiRoutes(root, actions, look, history) {
27683
27802
  }, 400);
27684
27803
  const { page, boxes, expected } = body.data;
27685
27804
  try {
27805
+ const target = await resolvePageRef(root, page, { cwd: root });
27806
+ await refuseClaimed(root, Object.keys(boxes).map((name) => `${target.project}/${target.name}/${name}`), /* @__PURE__ */ new Date());
27686
27807
  const journal = history?.journal();
27687
27808
  const frames = await setBoxes(root, page, boxes, expected, {
27688
27809
  cwd: root,
@@ -28616,6 +28737,7 @@ const STATUS$3 = {
28616
28737
  "frame-not-found": 404,
28617
28738
  "name-taken": 409,
28618
28739
  "stale-layout": 409,
28740
+ "frame-claimed": 409,
28619
28741
  "undo-overtaken": 409,
28620
28742
  "nothing-to-undo": 409,
28621
28743
  "frame-locked": 423,
@@ -28682,6 +28804,7 @@ function editRoutes(root, access, history) {
28682
28804
  const body = await parseBody$1(c.req.raw, editSchema);
28683
28805
  const frame = await resolveFrameRef(root, body.ref, { cwd: root });
28684
28806
  const ref = `${frame.project}/${frame.page}/${frame.name}`;
28807
+ await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
28685
28808
  const before = readFileSync(frame.path);
28686
28809
  const result = editFrameFile(frame.path, {
28687
28810
  index: body.index,
@@ -34243,23 +34366,148 @@ function elementsRoutes(root, access, selection, tokens = null) {
34243
34366
  });
34244
34367
  return app;
34245
34368
  }
34369
+ /** How much of a text hit's text shows before the match, and in all. */
34370
+ const SNIPPET_BEFORE = 20;
34371
+ const SNIPPET_LENGTH = 80;
34372
+ /** Elements whose text is code rather than copy. */
34373
+ const NOT_COPY = /* @__PURE__ */ new Set(["script", "style"]);
34374
+ /**
34375
+ * Every hit for `query` across the shown frames of a project, in page order
34376
+ * and then stacking order, matching case-insensitively against each frame's
34377
+ * name, each element's name by the layers rule, and each element's own text.
34378
+ * An element named by its own text hits as text alone, so it is not listed
34379
+ * twice, and a frame `elementTree` refuses hits by its name alone.
34380
+ */
34381
+ async function findInProject(root, project, query) {
34382
+ const { name } = await resolveProject(root, project);
34383
+ const needle = query.trim().toLowerCase();
34384
+ if (needle === "") return {
34385
+ project: name,
34386
+ query,
34387
+ hits: [],
34388
+ truncated: false
34389
+ };
34390
+ const frames = (await scanProject(root, name)).pages.flatMap((page) => page.frames.filter((frame) => !frame.hidden));
34391
+ const hits = (await Promise.all(frames.map((frame) => frameHits(frame, needle)))).flat();
34392
+ return {
34393
+ project: name,
34394
+ query,
34395
+ hits: hits.slice(0, 200),
34396
+ truncated: hits.length > 200
34397
+ };
34398
+ }
34399
+ async function frameHits(frame, needle) {
34400
+ let bytes;
34401
+ try {
34402
+ bytes = await readFile(frame.path);
34403
+ } catch (error) {
34404
+ if (isCode(error, "ENOENT")) return [];
34405
+ throw error;
34406
+ }
34407
+ const base = {
34408
+ page: frame.page,
34409
+ frame: frame.name,
34410
+ ref: frame.ref
34411
+ };
34412
+ const hits = [];
34413
+ if (frame.name.toLowerCase().includes(needle)) hits.push({
34414
+ ...base,
34415
+ kind: "frame",
34416
+ index: null,
34417
+ hash: null,
34418
+ name: frame.name,
34419
+ snippet: null
34420
+ });
34421
+ const source = bytes.toString("utf8");
34422
+ const rows = elementTree(source);
34423
+ if (!Array.isArray(rows)) return hits;
34424
+ const hash = contentHash(bytes);
34425
+ const { elements } = parseFrame(source);
34426
+ for (const row of rows) {
34427
+ const element = elements[row.index];
34428
+ if (!element) continue;
34429
+ const text = NOT_COPY.has(row.tag) ? "" : directText(element);
34430
+ const at = text.toLowerCase().indexOf(needle);
34431
+ const namedByText = row.textOnly && !hasDataName(element);
34432
+ const address = {
34433
+ ...base,
34434
+ index: row.index,
34435
+ hash,
34436
+ name: row.name
34437
+ };
34438
+ if (at !== -1) hits.push({
34439
+ ...address,
34440
+ kind: "text",
34441
+ snippet: snippet(text, at)
34442
+ });
34443
+ else if (!namedByText && row.name.toLowerCase().includes(needle)) hits.push({
34444
+ ...address,
34445
+ kind: "element",
34446
+ snippet: null
34447
+ });
34448
+ }
34449
+ return hits;
34450
+ }
34451
+ /**
34452
+ * The element's own text nodes joined and whitespace-collapsed, leaving out
34453
+ * its children's text, so a phrase split by an inline child is found by
34454
+ * either side and the hit selects the element holding it.
34455
+ */
34456
+ function directText(element) {
34457
+ return element.childNodes.filter((node) => node.nodeName === "#text").map((node) => node.value).join(" ").replace(/\s+/g, " ").trim();
34458
+ }
34459
+ function hasDataName(element) {
34460
+ return element.attrs.some((attr) => attr.name === "data-name" && attr.value.trim() !== "");
34461
+ }
34462
+ function snippet(text, at) {
34463
+ const start = Math.max(0, at - SNIPPET_BEFORE);
34464
+ const end = start + SNIPPET_LENGTH;
34465
+ return `${start > 0 ? "…" : ""}${text.slice(start, end)}${end < text.length ? "…" : ""}`;
34466
+ }
34467
+ //#endregion
34468
+ //#region src/server/routes/find.ts
34469
+ /** Longer than any name or line of copy anyone types into the field. */
34470
+ const MAX_QUERY = 200;
34471
+ /**
34472
+ * `GET /api/find?project=&q=` answers the `find` record over the project's
34473
+ * frame files, so a frame culled offscreen or on another page is found like
34474
+ * any other. It only reads, so it takes no writer guard.
34475
+ */
34476
+ function findRoutes(root) {
34477
+ const app = new Hono();
34478
+ app.get("/api/find", async (c) => {
34479
+ const project = c.req.query("project");
34480
+ if (!project) throw new FrameboardError("usage", "Name the project as ?project=.");
34481
+ const query = c.req.query("q") ?? "";
34482
+ if (query.length > MAX_QUERY) throw new FrameboardError("usage", `Keep ?q= to ${MAX_QUERY} characters.`);
34483
+ const data = await findInProject(root, project, query);
34484
+ return c.json({
34485
+ ok: true,
34486
+ data
34487
+ });
34488
+ });
34489
+ app.onError(answerRefusal);
34490
+ return app;
34491
+ }
34246
34492
  //#endregion
34247
34493
  //#region src/server/routes/history.ts
34248
34494
  /**
34249
34495
  * Undo and redo of the board's own writes, behind `requireWriter`. Each
34250
34496
  * answers the page to show and the frames the step touched, and refuses with
34251
- * `undo-overtaken` when an agent changed what the step would write.
34497
+ * `undo-overtaken` when an agent changed what the step would write, or
34498
+ * `frame-claimed`, keeping the step, while another session holds what it names.
34252
34499
  */
34253
34500
  function historyRoutes(access, history) {
34254
34501
  const app = new Hono();
34255
34502
  const authorized = requireWriter(access);
34503
+ const unclaimed = (refs) => refuseClaimed(history.root, refs, /* @__PURE__ */ new Date());
34256
34504
  app.post("/api/undo", authorized, async (c) => c.json({
34257
34505
  ok: true,
34258
- data: await history.undo()
34506
+ data: await history.undo(unclaimed)
34259
34507
  }));
34260
34508
  app.post("/api/redo", authorized, async (c) => c.json({
34261
34509
  ok: true,
34262
- data: await history.redo()
34510
+ data: await history.redo(unclaimed)
34263
34511
  }));
34264
34512
  app.onError(answerRefusal);
34265
34513
  return app;
@@ -34319,6 +34567,9 @@ const LOOK_MARKER = "data-frameboard";
34319
34567
  * the route served, so a live frame names the exact file an edit addresses.
34320
34568
  */
34321
34569
  const RENDERED_HASH = "data-hash";
34570
+ function isTheme$1(value) {
34571
+ return value === "light" || value === "dark";
34572
+ }
34322
34573
  /**
34323
34574
  * Shows a frame's root in `theme`: `data-theme`, `color-scheme`, and the
34324
34575
  * `.dark` or `.light` class, the selectors a token sheet reads. The frame
@@ -35189,20 +35440,33 @@ async function holdFrames(root, refs, options) {
35189
35440
  }
35190
35441
  /**
35191
35442
  * Writes held frames onto a page as new files on top of its stack, each
35192
- * taking the next free name so nothing on the page is overwritten. A frame
35193
- * keeps its box on another page and lands beside its source on its own,
35194
- * the way `duplicateFrame` places a copy.
35443
+ * taking the next free name so nothing on the page is overwritten. Without
35444
+ * `at`, a frame keeps its box on another page and lands beside its source
35445
+ * on its own, the way `duplicateFrame` places a copy.
35195
35446
  */
35196
35447
  async function pasteFrames(root, pageRef, held, options) {
35197
- const { journal } = options;
35448
+ const { journal, at } = options;
35198
35449
  const target = await resolvePageRef(root, pageRef, options);
35450
+ const left = Math.min(...held.map((frame) => frame.placement.box.x));
35451
+ const top = Math.min(...held.map((frame) => frame.placement.box.y));
35452
+ const place = (frame) => {
35453
+ const { box } = frame.placement;
35454
+ if (at) return {
35455
+ ...box,
35456
+ x: at.x + box.x - left,
35457
+ y: at.y + box.y - top
35458
+ };
35459
+ return frame.page === target.path ? {
35460
+ ...box,
35461
+ x: box.x + box.width + 80
35462
+ } : box;
35463
+ };
35199
35464
  const names = await withLayouts([target.path], async (layouts) => {
35200
35465
  const layout = layouts.get(target.path);
35201
35466
  if (!layout) throw new Error(`No layout read for ${target.path}.`);
35202
35467
  const pasted = [];
35203
35468
  for (const frame of held) {
35204
35469
  const name = freeFrameName(layout.names, frame.name, void 0);
35205
- const { box } = frame.placement;
35206
35470
  const path = join(target.path, `${name}${FRAME_EXTENSION}`);
35207
35471
  await writeFile(path, frame.bytes, { flag: "wx" });
35208
35472
  await journal?.created(path);
@@ -35210,10 +35474,7 @@ async function pasteFrames(root, pageRef, held, options) {
35210
35474
  if (frame.entry) layout.file.frames[name] = { ...frame.entry };
35211
35475
  layout.set(name, {
35212
35476
  ...frame.placement,
35213
- box: frame.page === target.path ? {
35214
- ...box,
35215
- x: box.x + box.width + 80
35216
- } : box,
35477
+ box: place(frame),
35217
35478
  order: layout.topOrder()
35218
35479
  });
35219
35480
  pasted.push(name);
@@ -35321,7 +35582,13 @@ const frameAddSchema = object$1({
35321
35582
  y: coordinate.optional()
35322
35583
  });
35323
35584
  const framesSchema = object$1({ refs });
35324
- const pasteSchema = object$1({ ref });
35585
+ const pasteSchema = object$1({
35586
+ ref,
35587
+ at: object$1({
35588
+ x: coordinate,
35589
+ y: coordinate
35590
+ }).optional()
35591
+ });
35325
35592
  const frameFlagSchema = object$1({
35326
35593
  refs,
35327
35594
  flag: _enum$1(["hidden", "locked"]),
@@ -35356,6 +35623,18 @@ function structureRoutes(root, access, history) {
35356
35623
  });
35357
35624
  return result;
35358
35625
  };
35626
+ /**
35627
+ * Refuses a write that would rename, move, or remove a frame another
35628
+ * session holds, before anything is written. Writes that leave every
35629
+ * existing frame file and box alone, being an add, a duplicate, a flag, a
35630
+ * copy, a paste, and a move of a page or frame in its order, go at once.
35631
+ */
35632
+ const refuseHeld = (refs) => refuseClaimed(root, refs, /* @__PURE__ */ new Date());
35633
+ /** `refuseHeld` for frames as the body names them, read back to their canonical refs. */
35634
+ const refuseHeldFrames = async (frames) => {
35635
+ const records = await Promise.all(frames.map((frame) => readFrame$1(root, frame, { cwd })));
35636
+ await refuseHeld(records.map((record) => record.ref));
35637
+ };
35359
35638
  const orderOf = async (project) => (await readPageOrder(join(root, project))).pages;
35360
35639
  app.post("/api/page/add", async (c) => {
35361
35640
  const body = await parseBody$1(c.req.raw, addSchema);
@@ -35402,6 +35681,7 @@ function structureRoutes(root, access, history) {
35402
35681
  app.post("/api/page/rename", async (c) => {
35403
35682
  const body = await parseBody$1(c.req.raw, renameSchema);
35404
35683
  const source = await resolvePageRef(root, body.ref, { cwd });
35684
+ await refuseHeld([`${source.project}/${source.name}`]);
35405
35685
  const page = await recorded((journal) => renamePage(root, body.ref, body.name, {
35406
35686
  cwd,
35407
35687
  journal
@@ -35435,6 +35715,7 @@ function structureRoutes(root, access, history) {
35435
35715
  app.post("/api/page/delete", async (c) => {
35436
35716
  const body = await parseBody$1(c.req.raw, deleteSchema);
35437
35717
  const source = await resolvePageRef(root, body.ref, { cwd });
35718
+ await refuseHeld([`${source.project}/${source.name}`]);
35438
35719
  const order = await orderOf(source.project);
35439
35720
  const at = order.indexOf(source.name);
35440
35721
  const beside = order[at + 1] ?? order[at - 1];
@@ -35494,6 +35775,7 @@ function structureRoutes(root, access, history) {
35494
35775
  });
35495
35776
  app.post("/api/frame/rename", async (c) => {
35496
35777
  const body = await parseBody$1(c.req.raw, renameSchema);
35778
+ await refuseHeldFrames([body.ref]);
35497
35779
  const frame = await recorded((journal) => renameFrame(root, body.ref, body.name, {
35498
35780
  cwd,
35499
35781
  journal
@@ -35530,6 +35812,7 @@ function structureRoutes(root, access, history) {
35530
35812
  app.post("/api/frame/delete", async (c) => {
35531
35813
  const body = await parseBody$1(c.req.raw, framesSchema);
35532
35814
  await refuseLocked(body.refs);
35815
+ await refuseHeldFrames(body.refs);
35533
35816
  const deleted = await eachFrame(body.refs, (frame, journal) => deleteFrame(root, frame, {
35534
35817
  cwd,
35535
35818
  journal
@@ -35555,6 +35838,7 @@ function structureRoutes(root, access, history) {
35555
35838
  app.post("/api/clipboard/cut", async (c) => {
35556
35839
  const body = await parseBody$1(c.req.raw, framesSchema);
35557
35840
  await refuseLocked(body.refs);
35841
+ await refuseHeldFrames(body.refs);
35558
35842
  const held = await holdFrames(root, body.refs, { cwd });
35559
35843
  await eachFrame(body.refs, (frame, journal) => deleteFrame(root, frame, {
35560
35844
  cwd,
@@ -35572,7 +35856,8 @@ function structureRoutes(root, access, history) {
35572
35856
  const held = clipboard;
35573
35857
  const frames = await recorded((journal) => pasteFrames(root, body.ref, held, {
35574
35858
  cwd,
35575
- journal
35859
+ journal,
35860
+ at: body.at
35576
35861
  }), (pasted) => onFrames(pasted.map((frame) => frame.ref)));
35577
35862
  return c.json({
35578
35863
  ok: true,
@@ -35594,6 +35879,7 @@ function structureRoutes(root, access, history) {
35594
35879
  });
35595
35880
  app.post("/api/project/rename", async (c) => {
35596
35881
  const body = await parseBody$1(c.req.raw, renameSchema);
35882
+ await refuseHeld([(await resolveProject(root, body.ref)).name]);
35597
35883
  const project = await recorded((journal) => renameProject(root, body.ref, body.name, { journal }), onHome);
35598
35884
  return c.json({
35599
35885
  ok: true,
@@ -35610,6 +35896,7 @@ function structureRoutes(root, access, history) {
35610
35896
  });
35611
35897
  app.post("/api/project/delete", async (c) => {
35612
35898
  const body = await parseBody$1(c.req.raw, projectSchema);
35899
+ await refuseHeld([(await resolveProject(root, body.ref)).name]);
35613
35900
  const result = await recorded((journal) => deleteProject(root, body.ref, { journal }), onHome);
35614
35901
  return c.json({
35615
35902
  ok: true,
@@ -35620,6 +35907,55 @@ function structureRoutes(root, access, history) {
35620
35907
  return app;
35621
35908
  }
35622
35909
  //#endregion
35910
+ //#region src/server/routes/thumbnails.ts
35911
+ /**
35912
+ * `GET /api/thumbnails?theme=` answers `{ stamps }`, the stamp of each
35913
+ * visible frame on every project's first page whose capture in that theme is
35914
+ * current, and queues a render of the rest, so the home view asks once and
35915
+ * hears each landing over the live socket. `GET /api/thumbnails/png` serves
35916
+ * one capture at `?ref=&theme=&v=<stamp>`, cached for good since a changed
35917
+ * frame takes a new stamp. Both only read, so they take no writer guard.
35918
+ */
35919
+ function thumbnailRoutes(root, store) {
35920
+ const app = new Hono();
35921
+ app.get("/api/thumbnails", async (c) => {
35922
+ const theme = themeOf(c.req.query("theme"), "Ask for /api/thumbnails?theme=<light|dark>.");
35923
+ const frames = (await scanBoard(root)).projects.flatMap((project) => (project.pages[0]?.frames ?? []).filter((frame) => !frame.hidden).map(({ ref, box }) => ({
35924
+ ref,
35925
+ box: {
35926
+ width: box.width,
35927
+ height: box.height
35928
+ }
35929
+ })));
35930
+ return c.json({
35931
+ ok: true,
35932
+ data: { stamps: store.ask(theme, frames) }
35933
+ });
35934
+ });
35935
+ app.get("/api/thumbnails/png", async (c) => {
35936
+ const theme = themeOf(c.req.query("theme"), "Ask for /api/thumbnails/png?ref=<frame-ref>&theme=<light|dark>&v=<stamp>.");
35937
+ const ref = c.req.query("ref") ?? "";
35938
+ const stamp = c.req.query("v") ?? "";
35939
+ const path = store.file(ref, theme, stamp);
35940
+ const bytes = path ? await readFile(path).catch(() => null) : null;
35941
+ if (!bytes) throw new FrameboardError("frame-not-found", `No current thumbnail of ${ref} in ${theme} at v=${stamp}.`, {
35942
+ ref,
35943
+ theme,
35944
+ v: stamp
35945
+ });
35946
+ return c.body(new Uint8Array(bytes), 200, {
35947
+ "Content-Type": "image/png",
35948
+ "Cache-Control": "public, max-age=31536000, immutable"
35949
+ });
35950
+ });
35951
+ app.onError(answerRefusal);
35952
+ return app;
35953
+ }
35954
+ function themeOf(value, usage) {
35955
+ if (!isTheme$1(value)) throw new FrameboardError("usage", usage, { theme: value ?? "" });
35956
+ return value;
35957
+ }
35958
+ //#endregion
35623
35959
  //#region src/server/app.ts
35624
35960
  const LOOPBACK_NAMES = /* @__PURE__ */ new Set(["127.0.0.1", "localhost"]);
35625
35961
  /**
@@ -35643,7 +35979,7 @@ function boardHostGuard(port) {
35643
35979
  await next();
35644
35980
  };
35645
35981
  }
35646
- function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks }) {
35982
+ function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails }) {
35647
35983
  const app = new Hono();
35648
35984
  const given = tokens ?? null;
35649
35985
  app.use("*", async (c, next) => {
@@ -35667,9 +36003,11 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
35667
36003
  app.route("/", notesRoutes(root, actions.access, delivery));
35668
36004
  app.route("/", assetsRoutes(root, actions.access));
35669
36005
  app.route("/", elementsRoutes(root, actions.access, selection, given));
36006
+ app.route("/", findRoutes(root));
35670
36007
  app.route("/", editRoutes(root, actions.access, history));
35671
36008
  app.route("/", pngRoutes(root, renderFrame));
35672
36009
  if (checks) app.route("/", checkRoutes(actions.access, checks));
36010
+ if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
35673
36011
  app.route("/", frames.routes);
35674
36012
  app.use("*", serveStatic({ root: clientDir }));
35675
36013
  app.get("/p/*", serveStatic({
@@ -35982,11 +36320,11 @@ function createWarmBrowser(launch) {
35982
36320
  };
35983
36321
  }
35984
36322
  /**
35985
- * Renders on a server's warm browser one frame at a time at twice its size.
35986
- * The queue is the renderer's own, so a PNG never waits behind another
35987
- * consumer of the browser.
36323
+ * Renders on a server's warm browser one frame at a time at `scale`. The
36324
+ * queue is the renderer's own, so a PNG never waits behind another consumer
36325
+ * of the browser, such as a thumbnail.
35988
36326
  */
35989
- function createWarmRenderer({ baseUrl, browser }) {
36327
+ function createWarmRenderer({ baseUrl, browser, scale }) {
35990
36328
  let queue = Promise.resolve();
35991
36329
  return (frame, theme) => {
35992
36330
  const run = queue.then(async () => {
@@ -35995,7 +36333,7 @@ function createWarmRenderer({ baseUrl, browser }) {
35995
36333
  ref: frame.ref,
35996
36334
  box: frame.box,
35997
36335
  theme,
35998
- scale: 2
36336
+ scale
35999
36337
  });
36000
36338
  try {
36001
36339
  return await opened.page.screenshot({
@@ -36695,8 +37033,19 @@ async function measure(browser, baseUrl, ref, box) {
36695
37033
  }
36696
37034
  function readContentSize() {
36697
37035
  const root = document.documentElement;
37036
+ const crops = (element) => {
37037
+ const style = getComputedStyle(element);
37038
+ return style.overflowX !== "visible" || style.overflowY !== "visible";
37039
+ };
37040
+ const isCropped = (element) => {
37041
+ for (let parent = element.parentElement; parent && parent !== document.body; parent = parent.parentElement) if (crops(parent)) return true;
37042
+ return false;
37043
+ };
36698
37044
  let bottom = root.getBoundingClientRect().bottom;
36699
- for (const element of document.querySelectorAll("body *")) bottom = Math.max(bottom, element.getBoundingClientRect().bottom);
37045
+ for (const element of document.querySelectorAll("body *")) {
37046
+ if (isCropped(element)) continue;
37047
+ bottom = Math.max(bottom, element.getBoundingClientRect().bottom);
37048
+ }
36700
37049
  return {
36701
37050
  height: Math.max(1, Math.ceil(bottom + window.scrollY)),
36702
37051
  width: root.scrollWidth
@@ -36900,7 +37249,7 @@ async function checkPages(root, project, pages, context) {
36900
37249
  //#endregion
36901
37250
  //#region src/cli/board-server.ts
36902
37251
  /** How long a running server has to answer before the verb gives up on it. */
36903
- const REQUEST_TIMEOUT_MS = 500;
37252
+ const REQUEST_TIMEOUT_MS = 5e3;
36904
37253
  /**
36905
37254
  * Posts to a running board server's write route with the address file's
36906
37255
  * token, resolving the `data` of its envelope. `timeoutMs` lengthens the
@@ -37305,28 +37654,6 @@ const checkResultSchema = /* @__PURE__ */ object({
37305
37654
  browser: /* @__PURE__ */ optional(browserRunSchema)
37306
37655
  });
37307
37656
  //#endregion
37308
- //#region src/shared/records/claims.ts
37309
- /** One session's hold on a frame while its agent rewrites it. */
37310
- const claimSchema = looseObject({
37311
- /** The canonical frame ref, `<project>/<page>/<frame>`. */
37312
- frame: string$1(),
37313
- /** The session holding it, the id `inbox` and a note's `to` use. */
37314
- session: string$1(),
37315
- /** The agent's name, such as `claude`, whose first letter the board shows. */
37316
- agent: string$1(),
37317
- /** The listener's tag form, `<agent> · <project folder>`. */
37318
- tag: string$1(),
37319
- /** When the session first claimed it, kept across renewals. */
37320
- claimedAt: string$1(),
37321
- /** When it lapses unless the session claims it again. */
37322
- expiresAt: string$1()
37323
- });
37324
- /** `.run/claims.json`. */
37325
- const claimsFileSchema = looseObject({
37326
- version: literal(1),
37327
- claims: array$1(claimSchema)
37328
- });
37329
- //#endregion
37330
37657
  //#region src/shared/records/edit.ts
37331
37658
  /** What `edit` returns: the frame it wrote, the element, and the hash the next edit is made from. */
37332
37659
  const editResultSchema = object$1({
@@ -37377,6 +37704,36 @@ object$1({
37377
37704
  colors: array$1(styleValueSchema)
37378
37705
  });
37379
37706
  //#endregion
37707
+ //#region src/shared/records/find.ts
37708
+ /** One match: a frame by its name, an element by its name, or an element's own text. */
37709
+ const findHitSchema = object$1({
37710
+ kind: _enum$1([
37711
+ "frame",
37712
+ "element",
37713
+ "text"
37714
+ ]),
37715
+ page: string$1(),
37716
+ /** The frame's name. */
37717
+ frame: string$1(),
37718
+ /** The frame ref, `<project>/<page>/<frame>`. */
37719
+ ref: string$1(),
37720
+ /** The element's index as `edit --index` takes it, null for a frame hit. */
37721
+ index: int$1().min(0).nullable(),
37722
+ /** The hash of the file the index was read from, null for a frame hit. */
37723
+ hash: string$1().regex(/^[0-9a-f]{64}$/).nullable(),
37724
+ /** The frame's name for a frame hit, else the element's name by the layers rule. */
37725
+ name: string$1(),
37726
+ /** A text hit's own text around the match, null for any other hit. */
37727
+ snippet: string$1().nullable()
37728
+ });
37729
+ /** What `GET /api/find` answers, in page order, with `truncated` set once the hits were cut. */
37730
+ const findResultSchema = object$1({
37731
+ project: string$1(),
37732
+ query: string$1(),
37733
+ hits: array$1(findHitSchema),
37734
+ truncated: boolean$1()
37735
+ });
37736
+ //#endregion
37380
37737
  //#region src/shared/records/inspect.ts
37381
37738
  const themeSchema = _enum$1(["light", "dark"]);
37382
37739
  /** One rendered element, addressed by the index `edit --index` takes. */
@@ -37460,7 +37817,8 @@ const RECORDS = {
37460
37817
  assetList: assetListSchema,
37461
37818
  assetAdd: assetAddResultSchema,
37462
37819
  elements: elementTreeSchema,
37463
- selection: selectionResultSchema
37820
+ selection: selectionResultSchema,
37821
+ find: findResultSchema
37464
37822
  };
37465
37823
  //#endregion
37466
37824
  //#region src/cli/docs/content-format.ts
@@ -37613,74 +37971,6 @@ function registerEdit(program, context) {
37613
37971
  });
37614
37972
  }
37615
37973
  //#endregion
37616
- //#region src/server/claims/store.ts
37617
- /** How long a claim holds after its last claim or renewal. */
37618
- const CLAIM_TTL_MS = 3e5;
37619
- const claimsSpec = {
37620
- schema: claimsFileSchema,
37621
- invalidCode: "claims-invalid",
37622
- empty: () => ({
37623
- version: 1,
37624
- claims: []
37625
- })
37626
- };
37627
- function claimsPath(root) {
37628
- return join(root, RUN_FOLDER, CLAIMS_FILE);
37629
- }
37630
- function isLive(claim, now) {
37631
- return Date.parse(claim.expiresAt) > now.getTime();
37632
- }
37633
- /** The claims still live at `now`, refusing a file that does not parse. */
37634
- async function readClaims(root, now) {
37635
- return (await readRecord(claimsPath(root), claimsSpec)).claims.filter((claim) => isLive(claim, now));
37636
- }
37637
- /**
37638
- * Claims a frame for a session, or renews the session's own claim keeping
37639
- * `claimedAt`. A frame another session holds live refuses `frame-claimed`.
37640
- */
37641
- async function claim(root, fields, now) {
37642
- await ensureRunFolder(root);
37643
- return (await updateRecord(claimsPath(root), claimsSpec, (file) => {
37644
- const live = file.claims.filter((each) => isLive(each, now));
37645
- const current = live.find((each) => each.frame === fields.frame);
37646
- if (current && current.session !== fields.session) throw new FrameboardError("frame-claimed", `${current.tag} is editing ${fields.frame} until ${current.expiresAt}.`, {
37647
- frame: current.frame,
37648
- session: current.session,
37649
- tag: current.tag,
37650
- expiresAt: current.expiresAt
37651
- });
37652
- const held = {
37653
- ...fields,
37654
- claimedAt: current?.claimedAt ?? now.toISOString(),
37655
- expiresAt: new Date(now.getTime() + CLAIM_TTL_MS).toISOString()
37656
- };
37657
- return {
37658
- ...file,
37659
- claims: [...live.filter((each) => each !== current), held]
37660
- };
37661
- })).claims.at(-1);
37662
- }
37663
- /**
37664
- * Drops a session's claim on one frame, or every claim it holds when no
37665
- * frame is named, returning what it dropped.
37666
- */
37667
- async function release(root, session, frame, now) {
37668
- const dropped = [];
37669
- await ensureRunFolder(root);
37670
- await updateRecord(claimsPath(root), claimsSpec, (file) => {
37671
- const kept = [];
37672
- for (const each of file.claims) {
37673
- if (!isLive(each, now)) continue;
37674
- (each.session === session && (frame === void 0 || each.frame === frame) ? dropped : kept).push(each);
37675
- }
37676
- return {
37677
- ...file,
37678
- claims: kept
37679
- };
37680
- });
37681
- return dropped;
37682
- }
37683
- //#endregion
37684
37974
  //#region src/cli/session.ts
37685
37975
  /** The variable Claude Code sets to the session a command runs in. */
37686
37976
  const SESSION_ENV = "CLAUDE_CODE_SESSION_ID";
@@ -41952,6 +42242,77 @@ function createTickets(now = Date.now) {
41952
42242
  };
41953
42243
  }
41954
42244
  //#endregion
42245
+ //#region src/server/capture/thumbnails.ts
42246
+ const THUMBNAILS_FOLDER = "thumbnails";
42247
+ /**
42248
+ * The home view's frame captures, one per frame and theme under
42249
+ * `.run/thumbnails/<project>/<page>/<frame>.<theme>.png`. A stamp names the
42250
+ * server run, how often the frame changed, and its size, so a capture of a
42251
+ * changed or resized frame, or one a previous server served, is never
42252
+ * answered as current. A failed render is remembered against its stamp, so a
42253
+ * frame refusing `font-missing`, or a board with no headless shell, costs one
42254
+ * render until the frame changes.
42255
+ */
42256
+ function createThumbnailStore({ root, run, render, onRendered }) {
42257
+ const folder = join(root, RUN_FOLDER, THUMBNAILS_FOLDER);
42258
+ const generations = /* @__PURE__ */ new Map();
42259
+ const entries = /* @__PURE__ */ new Map();
42260
+ const inFlight = /* @__PURE__ */ new Set();
42261
+ const pathOf = (ref, theme) => join(folder, `${ref}.${theme}.png`);
42262
+ const keyOf = (ref, theme) => `${theme}:${ref}`;
42263
+ const stampOf = ({ ref, box }) => `${run}-${generations.get(ref) ?? 0}-${box.width}x${box.height}`;
42264
+ const start = (frame, theme, stamp) => {
42265
+ const key = keyOf(frame.ref, theme);
42266
+ const entry = {
42267
+ stamp,
42268
+ state: "rendering"
42269
+ };
42270
+ entries.set(key, entry);
42271
+ const landing = render(frame, theme).then(async (bytes) => {
42272
+ if (entries.get(key) !== entry) return;
42273
+ const path = pathOf(frame.ref, theme);
42274
+ await mkdir(dirname(path), { recursive: true });
42275
+ await writeFile(path, bytes);
42276
+ if (entries.get(key) !== entry) return;
42277
+ entry.state = "done";
42278
+ onRendered(theme, { [frame.ref]: stamp });
42279
+ }).catch(() => {
42280
+ entry.state = "failed";
42281
+ }).finally(() => inFlight.delete(landing));
42282
+ inFlight.add(landing);
42283
+ };
42284
+ return {
42285
+ ask: (theme, frames) => {
42286
+ const stamps = {};
42287
+ for (const frame of frames) {
42288
+ const stamp = stampOf(frame);
42289
+ const entry = entries.get(keyOf(frame.ref, theme));
42290
+ if (entry?.stamp !== stamp) start(frame, theme, stamp);
42291
+ else if (entry.state === "done") stamps[frame.ref] = stamp;
42292
+ }
42293
+ return stamps;
42294
+ },
42295
+ invalidate: (refs) => {
42296
+ for (const ref of refs) {
42297
+ generations.set(ref, (generations.get(ref) ?? 0) + 1);
42298
+ entries.delete(keyOf(ref, "light"));
42299
+ entries.delete(keyOf(ref, "dark"));
42300
+ }
42301
+ },
42302
+ file: (ref, theme, stamp) => {
42303
+ const entry = entries.get(keyOf(ref, theme));
42304
+ return entry?.stamp === stamp && entry.state === "done" ? pathOf(ref, theme) : null;
42305
+ },
42306
+ settled: async () => {
42307
+ while (inFlight.size > 0) await Promise.all(inFlight);
42308
+ },
42309
+ empty: () => rm(folder, {
42310
+ recursive: true,
42311
+ force: true
42312
+ })
42313
+ };
42314
+ }
42315
+ //#endregion
41955
42316
  //#region src/server/changes/diff.ts
41956
42317
  /** Past this many changed elements, one glow over the frame reads better than many. */
41957
42318
  const MOST_ELEMENTS = 8;
@@ -42511,6 +42872,7 @@ async function exists(path) {
42511
42872
  throw error;
42512
42873
  }
42513
42874
  }
42875
+ const OPEN = async () => {};
42514
42876
  /**
42515
42877
  * The developer's undo and redo stacks, in memory, holding the board's own
42516
42878
  * writes and never an agent's. Undo and redo run one at a time, each
@@ -42550,16 +42912,46 @@ var History = class {
42550
42912
  this.onChange(this.counts());
42551
42913
  this.onWrite(step);
42552
42914
  }
42553
- undo() {
42554
- return this.#inTurn(() => this.#move(this.#undo, this.#redo, "before"));
42915
+ /**
42916
+ * The refs the top undo or redo step would write, without popping it, so a
42917
+ * route can refuse a claimed frame before the step is taken. These are the
42918
+ * step's frames, and the page or project folder and frame file each move
42919
+ * or removal names, since a page or project step names no frames.
42920
+ */
42921
+ peek(side) {
42922
+ const step = (side === "undo" ? this.#undo : this.#redo).at(-1);
42923
+ if (!step) return [];
42924
+ const refs = step.changes.flatMap((change) => {
42925
+ if (change.kind === "moved") return [change.from, change.to];
42926
+ if (change.kind === "path") return [change.path];
42927
+ return [];
42928
+ }).flatMap((path) => {
42929
+ const inBoard = relative(this.root, path);
42930
+ if (inBoard === "" || inBoard.startsWith("..") || isAbsolute(inBoard)) return [];
42931
+ const ref = inBoard.split(sep).join("/");
42932
+ return [ref.endsWith(".html") ? ref.slice(0, -5) : ref];
42933
+ });
42934
+ return [.../* @__PURE__ */ new Set([...step.frames, ...refs])];
42935
+ }
42936
+ /**
42937
+ * Undoes the top step. `gate` reads what `peek` names of that step in turn,
42938
+ * before it is taken, so a refusal it throws leaves the step on its stack
42939
+ * and a quick second undo never checks one step and takes another.
42940
+ */
42941
+ undo(gate = OPEN) {
42942
+ return this.#inTurn(() => this.#move(this.#undo, this.#redo, "before", gate));
42555
42943
  }
42556
- redo() {
42557
- return this.#inTurn(() => this.#move(this.#redo, this.#undo, "after"));
42944
+ /** Redoes the top step, gated as `undo` is. */
42945
+ redo(gate = OPEN) {
42946
+ return this.#inTurn(() => this.#move(this.#redo, this.#undo, "after", gate));
42558
42947
  }
42559
42948
  /** Takes the top step of `from`, writes `to` side of it, and pushes it onto `onto`. */
42560
- async #move(from, onto, to) {
42949
+ async #move(from, onto, to, gate) {
42950
+ const empty = () => new FrameboardError("nothing-to-undo", `There is nothing to ${to === "before" ? "undo" : "redo"}.`);
42951
+ if (from.length === 0) throw empty();
42952
+ await gate(this.peek(from === this.#undo ? "undo" : "redo"));
42561
42953
  const step = from.pop();
42562
- if (!step) throw new FrameboardError("nothing-to-undo", `There is nothing to ${to === "before" ? "undo" : "redo"}.`);
42954
+ if (!step) throw empty();
42563
42955
  const was = to === "before" ? "after" : "before";
42564
42956
  const locks = step.changes.flatMap(lockPaths).filter((path) => existsSync(dirname(path)));
42565
42957
  try {
@@ -44920,14 +45312,30 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
44920
45312
  inTurn
44921
45313
  });
44922
45314
  const browser = createWarmBrowser(() => launchCaptureBrowser({
44923
- purpose: "Board PNGs and browser checks",
45315
+ purpose: "Board PNGs, thumbnails, and browser checks",
44924
45316
  launch
44925
45317
  }));
44926
45318
  const baseUrl = () => `http://${HOSTNAME}:${bound}`;
44927
45319
  const renderFrame = createWarmRenderer({
44928
45320
  baseUrl,
44929
- browser
45321
+ browser,
45322
+ scale: 2
44930
45323
  });
45324
+ const thumbnails = createThumbnailStore({
45325
+ root,
45326
+ run: randomUUID().slice(0, 8),
45327
+ render: createWarmRenderer({
45328
+ baseUrl,
45329
+ browser,
45330
+ scale: .5
45331
+ }),
45332
+ onRendered: (theme, stamps) => hub.broadcast({
45333
+ type: "thumbnails",
45334
+ theme,
45335
+ stamps
45336
+ })
45337
+ });
45338
+ await thumbnails.empty();
44931
45339
  const rendered = createRenderedFindings({
44932
45340
  check: async (frame) => checkRendered(await browser.get(), {
44933
45341
  baseUrl: baseUrl(),
@@ -44962,6 +45370,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
44962
45370
  history,
44963
45371
  selection,
44964
45372
  renderFrame,
45373
+ thumbnails,
44965
45374
  checks: {
44966
45375
  refresh: () => inTurn(async () => {
44967
45376
  try {
@@ -45020,6 +45429,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45020
45429
  delivery,
45021
45430
  tracker,
45022
45431
  claims,
45432
+ thumbnails,
45023
45433
  settleLater
45024
45434
  }));
45025
45435
  });
@@ -45051,12 +45461,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45051
45461
  }
45052
45462
  /**
45053
45463
  * One rescan per batch: the whole board to every tab, then the frames to
45054
- * reload, then the findings of every frame the batch rechecked, queueing the
45464
+ * reload, marking their thumbnails stale in both themes without rendering
45465
+ * any, then the findings of every frame the batch rechecked, queueing the
45055
45466
  * same frames for the browser checker, then the notes of every page whose
45056
45467
  * notes or frames it touched, whose queue it offers to delivery. The frames
45057
45468
  * an agent changed wait out the grace before the board hears of them.
45058
45469
  */
45059
- async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, settleLater }) {
45470
+ async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, settleLater }) {
45060
45471
  let board;
45061
45472
  try {
45062
45473
  board = await scanBoard(root);
@@ -45068,10 +45479,19 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
45068
45479
  data: board
45069
45480
  });
45070
45481
  const refs = reloadRefs(root, paths, board, tokens);
45071
- if (refs.length > 0) hub.broadcast({
45072
- type: "reload",
45073
- refs
45074
- });
45482
+ if (refs.length > 0) {
45483
+ hub.broadcast({
45484
+ type: "reload",
45485
+ refs
45486
+ });
45487
+ thumbnails.invalidate(refs);
45488
+ const stale = Object.fromEntries(refs.map((ref) => [ref, null]));
45489
+ for (const theme of THEMES) hub.broadcast({
45490
+ type: "thumbnails",
45491
+ theme,
45492
+ stamps: stale
45493
+ });
45494
+ }
45075
45495
  const held = await tracker.update(board, paths, await claims.read());
45076
45496
  if (held.length > 0) settleLater(held);
45077
45497
  const changed = findings.update(board, paths);