@marver-design/marver 0.22.1 → 0.23.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +13 -9
  3. package/dist/agent-BsieQGTD.mjs +99 -0
  4. package/dist/{bake-CvY8QR3L.mjs → bake-l6N12qgx.mjs} +1 -1
  5. package/dist/{board-status-CWGHIdo_.mjs → board-status-D_lHZZ09.mjs} +69 -610
  6. package/dist/{boards-BwKI0qWd.mjs → boards-CahYhF5B.mjs} +2 -1
  7. package/dist/boards-DbVJlbd5.mjs +612 -0
  8. package/dist/{build-B1kavcpc.mjs → build-CuRhHXcY.mjs} +10 -6
  9. package/dist/cli.mjs +20 -11
  10. package/dist/{comments-ClVgfQib.mjs → comments-0d3e274b.mjs} +71 -9
  11. package/dist/{config-DJxMRVD8.mjs → config-g-J8NrPn.mjs} +5 -97
  12. package/dist/{context-D4t59wDi.mjs → context-fAtQLHt2.mjs} +3 -2
  13. package/dist/{daemon-PmNqoOAk.mjs → daemon-DZ367fiM.mjs} +75 -17
  14. package/dist/{dev-Cf4wLGe2.mjs → dev-R6zvwbqX.mjs} +50 -10
  15. package/dist/{init-C_K-cjBQ.mjs → init-DAnBlt-V.mjs} +4 -3
  16. package/dist/{ledger-Bu0BjqIe.mjs → ledger-BNXW14Xw.mjs} +1 -6
  17. package/dist/link-CcfAfKY-.mjs +132 -0
  18. package/dist/{manifest-CcdWx7ud.mjs → manifest-BkjJ5OQk.mjs} +50 -5
  19. package/dist/{plugin-C5u07Yhv.mjs → plugin-C1avHL7g.mjs} +357 -31
  20. package/dist/{poster-BduzQBYz.mjs → poster-Bc4-3DlQ.mjs} +1 -1
  21. package/dist/{profile-BjAPAJSb.mjs → profile-CrZohD6g.mjs} +1 -1
  22. package/dist/{publish-bakes-b0jUwvM_.mjs → publish-bakes-DQWn14IY.mjs} +2 -2
  23. package/dist/{share--bdSc4G5.mjs → share-BD-wcDQq.mjs} +1 -1
  24. package/dist/{shot-BFEuYbaz.mjs → shot-C1YR_Sqx.mjs} +1 -1
  25. package/dist/{shot-BAR8hmU9.mjs → shot-CVOlQHUr.mjs} +2 -2
  26. package/dist/{sync-BZaCWqK-.mjs → sync-DoA1vf4u.mjs} +15 -1
  27. package/dist/{work-0YopuMt9.mjs → work-CJ8OIpBD.mjs} +9 -3
  28. package/dist/{work-CLrmY-vQ.mjs → work-CiUvBVa6.mjs} +72 -1
  29. package/docs/boards-and-folders.md +54 -6
  30. package/docs/context.md +10 -2
  31. package/docs/live-jam.md +11 -0
  32. package/package.json +1 -1
  33. package/src/client/content/diagram.tsx +7 -1
  34. package/src/client/content/img-lod.ts +12 -2
  35. package/src/client/content/index.tsx +69 -6
  36. package/src/client/frame-host/inspect.js +23 -0
  37. package/src/client/shell/App.tsx +19 -9
  38. package/src/client/shell/BoardList.tsx +21 -6
  39. package/src/client/shell/LockedApp.tsx +2 -2
  40. package/src/client/shell/Play.tsx +5 -1
  41. package/src/client/shell/StatusPicker.tsx +12 -5
  42. package/src/client/shell/Tip.tsx +25 -5
  43. package/src/client/shell/board-icons.tsx +15 -1
  44. package/src/client/shell/canvas/Canvas.tsx +42 -6
  45. package/src/client/shell/canvas/anchor.ts +41 -0
  46. package/src/client/shell/canvas/ctl.ts +6 -0
  47. package/src/client/shell/comments-store.ts +8 -5
  48. package/src/client/shell/goto.ts +52 -3
  49. package/src/client/shell/hash.ts +24 -3
  50. package/src/client/shell/store.ts +242 -28
  51. package/src/client/shell/styles.css +19 -2
  52. package/src/shared/board-types.ts +10 -6
  53. package/src/shared/status.ts +17 -8
  54. package/templates/AGENTS-embedded.md +43 -8
  55. package/templates/AGENTS-studio.md +43 -8
  56. package/templates/instructions/boards.md +13 -3
  57. package/templates/instructions/context.md +6 -2
  58. package/templates/instructions/iterate.md +29 -16
  59. package/templates/instructions/jam.md +9 -2
  60. package/templates/instructions/reference/deck-layouts.md +2 -1
  61. package/templates/instructions/reference/deck-story.md +2 -1
@@ -1,13 +1,131 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { a as ROUTE, i as PKG, r as NAME } from "./cli.mjs";
3
- import { A as isRegularFile, B as folderMap, D as boardFields, F as BOARD_NAME, G as validateWire, I as FOLDERS_FILE, K as wireKids, L as buildTree, M as nodeExists, N as readRegistry, O as checkBoardsDir, P as withRegistryLock, T as AUTHOR_FIELDS, U as readDescription, W as readTitle, Y as HAS_STATUS, at as hash, et as readReason, it as settableStatuses, j as listBoardFiles, n as readContextFacts, nt as readType, rt as resolveType, t as annotateBoards, tt as readStatusWord } from "./board-status-CWGHIdo_.mjs";
4
- import { n as localProfile, t as isConnected } from "./profile-BjAPAJSb.mjs";
5
- import { a as setSceneTitle, i as scanFrames, n as isNoteFile, s as writeManifest, t as affectedFrameIds } from "./manifest-CcdWx7ud.mjs";
6
- import { n as loadConfig } from "./config-DJxMRVD8.mjs";
7
- import { copyFileSync, existsSync, linkSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, watch, writeFileSync } from "node:fs";
3
+ import { A as readCapability, E as HAS_STATUS, F as settableStatuses, I as hash, M as readStatusWord, N as readType, P as resolveType, S as wireKids, b as readTitle, c as nodeExists, d as BOARD_NAME, f as FOLDERS_FILE, g as folderMap, i as checkBoardsDir, j as readReason, l as readRegistry, o as isRegularFile, p as buildTree, r as boardFields, s as listBoardFiles, t as AUTHOR_FIELDS, u as withRegistryLock, x as validateWire, y as readDescription } from "./boards-DbVJlbd5.mjs";
4
+ import { i as readContextFacts, n as planNames, r as planWithStage, t as annotateBoards } from "./board-status-D_lHZZ09.mjs";
5
+ import { n as localProfile, t as isConnected } from "./profile-CrZohD6g.mjs";
6
+ import { a as rendersDoc, l as writeManifest, n as isNoteFile, o as scanFrames, r as layoutDocSource, s as setSceneTitle, t as affectedFrameIds } from "./manifest-BkjJ5OQk.mjs";
7
+ import { n as loadConfig } from "./config-g-J8NrPn.mjs";
8
+ import { r as boardsChanged } from "./work-CiUvBVa6.mjs";
9
+ import { closeSync, copyFileSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, watch, writeFileSync } from "node:fs";
8
10
  import { basename, dirname, join, resolve, sep } from "node:path";
9
11
  import { fileURLToPath } from "node:url";
10
12
  import { randomBytes } from "node:crypto";
13
+ //#region src/server/sizes.ts
14
+ /**
15
+ * Content-frame heights - `design/boards/_sizes.json`, committed.
16
+ *
17
+ * A content frame (a Doc: markdown, diagrams, images) is as tall as its content, which only a
18
+ * render can tell. Measured live, every load started from a guess (3/4 of the width) and grew
19
+ * frame by frame, and each growth re-flowed the rows below - the board swam for seconds. The
20
+ * height a frame measured at its own width is a fact about the FRAME at that width, not about a
21
+ * board (one doc sits on several boards) and not something to write into the frame's source: so
22
+ * it lives here, one line per `scene/frame@width`, written by the dev server when the shell
23
+ * reports a settled measurement, read before the first layout - dev, `marver build` and the
24
+ * published canvas alike. A stale entry is still the best first guess; the live measurement
25
+ * corrects it and the file follows. Underscore = infrastructure, never a board (board-tree.ts).
26
+ */
27
+ const SIZES_FILE = "_sizes.json";
28
+ /** `scene/frame@width` - the frame id grammar the focus route accepts, then the width it was measured at. */
29
+ const SIZE_KEY = /^([\w./-]{1,200})@(\d{2,4})$/;
30
+ const ABOUT = "Written by marver dev: the height each content frame measured at its width, so boards open at their final size. Commit it; never edit it by hand.";
31
+ const sizesPath = (root) => join(root, "design", "boards", SIZES_FILE);
32
+ /** A valid entry: a well-formed key whose frame is not a traversal, and a height in the shell's clamp. */
33
+ function validEntry(key, h) {
34
+ if (typeof key !== "string" || typeof h !== "number" || !Number.isInteger(h) || h < 80 || h > 4e4) return false;
35
+ const m = SIZE_KEY.exec(key);
36
+ return !!m && !m[1].split("/").some((p) => p === ".." || p === "." || p === "");
37
+ }
38
+ function readSizesFile(root) {
39
+ const file = sizesPath(root);
40
+ if (!existsSync(file)) return {
41
+ state: "absent",
42
+ heights: {}
43
+ };
44
+ try {
45
+ const raw = JSON.parse(readFileSync(file, "utf8"));
46
+ if (!raw || typeof raw !== "object" || !raw.heights || typeof raw.heights !== "object" || Array.isArray(raw.heights)) return {
47
+ state: "invalid",
48
+ heights: {}
49
+ };
50
+ const out = {};
51
+ for (const [k, v] of Object.entries(raw.heights)) if (validEntry(k, v)) out[k] = v;
52
+ return {
53
+ state: "ok",
54
+ heights: out
55
+ };
56
+ } catch {
57
+ return {
58
+ state: "invalid",
59
+ heights: {}
60
+ };
61
+ }
62
+ }
63
+ /** Lenient read for the readers (the shell's first layout, the build): an absent or invalid file is
64
+ * no heights - every frame opens at its placeholder, as before. Never throws. */
65
+ const readSizes = (root) => readSizesFile(root).heights;
66
+ /** The file's text for a set of heights: sorted keys, one entry per line - a changed height is a
67
+ * one-line diff, and two branches that measured different frames merge without a conflict. */
68
+ function serializeSizes(heights) {
69
+ const sorted = {};
70
+ for (const k of Object.keys(heights).sort()) sorted[k] = heights[k];
71
+ return JSON.stringify({
72
+ about: ABOUT,
73
+ heights: sorted
74
+ }, null, 2) + "\n";
75
+ }
76
+ const keeps = (key, autoWidth) => {
77
+ const m = SIZE_KEY.exec(key);
78
+ return !!m && autoWidth(m[1]) === Number(m[2]);
79
+ };
80
+ /** Merge incoming heights into the current ones, keeping only what a board can use: a content frame
81
+ * that still exists, at the width it measures at on its own. Everything else is pruned - a deleted
82
+ * frame, a Doc that went from document to wide. Returns the next map and the keys taken. Pruning
83
+ * reads only the manifest: whether a frame still renders a Doc is asked on READ (keptSizes), so a
84
+ * source caught mid-write can hide an entry for one load, never delete it. */
85
+ function mergeSizes(current, incoming, autoWidth) {
86
+ const next = Object.fromEntries(Object.entries(current).filter(([k]) => keeps(k, autoWidth)));
87
+ const accepted = [];
88
+ for (const [k, v] of Object.entries(incoming)) {
89
+ if (!validEntry(k, v) || !keeps(k, autoWidth)) continue;
90
+ next[k] = v;
91
+ accepted.push(k);
92
+ }
93
+ return {
94
+ next,
95
+ accepted
96
+ };
97
+ }
98
+ /** The entries a board can use - what the GET and the build hand the shell: a content frame at its
99
+ * own width that MEASURES (renders a Doc). A frame that went from a Doc to a bare Md keeps the size
100
+ * its board gives it, never an old measurement. */
101
+ const keptSizes = (heights, autoWidth, measuring) => Object.fromEntries(Object.entries(heights).filter(([k]) => keeps(k, autoWidth) && measuring.has(k.slice(0, k.lastIndexOf("@")))));
102
+ /** The auto width rule over a manifest's frames (the shell's defaultSize, store.ts). */
103
+ function autoWidthOf(frames, viewports) {
104
+ const byId = new Map(frames.map((f) => [f.id, f]));
105
+ return (id) => {
106
+ const f = byId.get(id);
107
+ if (!f?.contentWidth) return null;
108
+ return viewports[f.viewport ?? ""]?.width ?? f.contentWidth;
109
+ };
110
+ }
111
+ /** The content frames that measure: the frame renders a Doc, or a `_layout` it renders inside does
112
+ * (manifest.ts layoutDocSource - the same rule the manifest's width follows). A source that cannot
113
+ * be read, or reads empty (an editor mid-write), gets the benefit of the doubt - this only decides
114
+ * what a load is handed, never what the file keeps. */
115
+ function measuringFrames(root, frames) {
116
+ const out = /* @__PURE__ */ new Set();
117
+ const memo = /* @__PURE__ */ new Map();
118
+ for (const f of frames) {
119
+ if (!f.contentWidth || f.kind === "html" || !f.file || f.file.split("/").includes("..")) continue;
120
+ let src = "";
121
+ try {
122
+ src = readFileSync(join(root, f.file), "utf8");
123
+ } catch {}
124
+ if (!src.trim() || rendersDoc(src) || layoutDocSource(root, f.file, memo) !== null) out.add(f.id);
125
+ }
126
+ return out;
127
+ }
128
+ //#endregion
11
129
  //#region src/server/api.ts
12
130
  const BODY_LIMIT = 1e6;
13
131
  const CSRF_MAX_AGE = 2592e3;
@@ -66,9 +184,38 @@ function atomicWrite(file, content) {
66
184
  throw err;
67
185
  }
68
186
  copyFileSync(tmp, file);
69
- rmSync(tmp, { force: true });
187
+ try {
188
+ rmSync(tmp, { force: true });
189
+ } catch {}
190
+ }
191
+ }
192
+ /** A replacement that is whole or not at all, in two steps: `stageWrite` puts the new content in a temp
193
+ * file beside the destination; `rename` swaps it in - one syscall, so a caller can look at the
194
+ * destination right before it and nothing but that rename stands between the look and the write.
195
+ * Never the copy fallback: a copy can fail part way, or not at all, and nothing tells which. For the
196
+ * status write, which writes several files and must say exactly what it changed. */
197
+ function stageWrite(file, content) {
198
+ const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
199
+ const fd = openSync(tmp, "wx");
200
+ let open = true;
201
+ try {
202
+ writeFileSync(fd, content);
203
+ open = false;
204
+ closeSync(fd);
205
+ } catch (err) {
206
+ if (open) try {
207
+ closeSync(fd);
208
+ } catch {}
209
+ discard(tmp);
210
+ throw err;
70
211
  }
212
+ return tmp;
71
213
  }
214
+ const discard = (tmp) => {
215
+ try {
216
+ rmSync(tmp, { force: true });
217
+ } catch {}
218
+ };
72
219
  /** Containment beyond string prefixes: the realpath of the parent dir must stay inside base. */
73
220
  function contained(target, base) {
74
221
  try {
@@ -98,6 +245,7 @@ function apiMiddleware(root, opts = {}) {
98
245
  const dirError = () => checkBoardsDir(root, boardsDir);
99
246
  const notSymlink = (p) => !nodeExists(p) || isRegularFile(p);
100
247
  const nodeExists$1 = nodeExists;
248
+ let sizesWarned = false;
101
249
  try {
102
250
  for (const f of readdirSync(boardsDir)) if (f.endsWith(".tmp")) rmSync(join(boardsDir, f), { force: true });
103
251
  } catch {}
@@ -140,14 +288,14 @@ function apiMiddleware(root, opts = {}) {
140
288
  const fm = folderMap(tree);
141
289
  const facts = readContextFacts(root);
142
290
  const notes = annotateBoards(root, files, regFolders, (n) => fm.get(n) ?? null, facts);
143
- const settable = settableStatuses(facts.present);
291
+ const settableFor = (cap) => settableStatuses(facts.present, !!facts.plans.get(cap)?.length);
144
292
  return json(res, 200, files.map((b, i) => {
145
293
  const n = notes.get(b.name);
146
294
  return {
147
295
  ...rows[i],
148
296
  sha256: b.sha256,
149
297
  ...n ?? {},
150
- ...n?.status ? { settable } : {}
298
+ ...n?.status ? { settable: settableFor(n.status.capability) } : {}
151
299
  };
152
300
  }));
153
301
  }
@@ -200,18 +348,161 @@ function apiMiddleware(root, opts = {}) {
200
348
  const parent = folder?.parent ? regFolders.find((f) => f.name === folder.parent) : void 0;
201
349
  const type = resolveType(obj.type, folder?.type, parent?.type);
202
350
  if (!HAS_STATUS.includes(type)) return json(res, 422, { error: `a ${type} board carries no status - only feature and project boards do` });
203
- if (status !== null && !settableStatuses(readContextFacts(root).present).includes(status)) return json(res, 422, { error: status === "done" ? "Done is never set by hand - it comes from context/shipped.md" : `with context/, ${status} is read from the evidence - a plan, a contract, the shipped record` });
204
- if (status === null) delete obj.status;
205
- else obj.status = status;
206
- if (status === "blocked") obj.reason = reason;
207
- else delete obj.reason;
351
+ const facts = readContextFacts(root);
352
+ const capability = readCapability(obj.capability) ?? name;
353
+ const plans = facts.present ? facts.plans.get(capability) ?? [] : [];
354
+ if (status !== null && !settableStatuses(facts.present, plans.length > 0).includes(status)) return json(res, 422, { error: status === "done" ? "Done is never set by hand - it comes from context/shipped.md" : status === "building" || status === "in-progress" ? `${status === "building" ? "Building" : "In progress"} needs an open plan naming ${capability} - context/plans/` : `with context/, ${status} is read from the evidence - a plan, a contract, the shipped record` });
355
+ const writes = [];
356
+ if (facts.present && (status === "building" || status === "in-progress")) {
357
+ for (const p of plans.filter((x, i) => plans.findIndex((y) => y.where === x.where) === i)) {
358
+ const file = join(root, p.where);
359
+ if (!notSymlink(file)) return json(res, 400, { error: `refusing to write a symlinked plan (${p.where})` });
360
+ const raw = readFileSync(file, "utf8");
361
+ if (!planNames(raw, capability)) return json(res, 409, { error: `${p.where} changed on disk - try again` });
362
+ const r = planWithStage(raw, status === "building" ? "build" : null);
363
+ if ("error" in r) return json(res, 422, { error: `${p.where} ${r.error} - fix the file` });
364
+ writes.push({
365
+ file,
366
+ raw,
367
+ next: r.text,
368
+ plan: p.where
369
+ });
370
+ }
371
+ delete obj.status;
372
+ delete obj.reason;
373
+ } else {
374
+ if (status === null) delete obj.status;
375
+ else obj.status = status;
376
+ if (status === "blocked") obj.reason = reason;
377
+ else delete obj.reason;
378
+ }
208
379
  const next = JSON.stringify(obj, null, 2) + "\n";
209
- if (next !== current) atomicWrite(file, next);
380
+ writes.push({
381
+ file,
382
+ raw: current,
383
+ next
384
+ });
385
+ const current_ = (f) => {
386
+ try {
387
+ return readFileSync(f, "utf8");
388
+ } catch {
389
+ return null;
390
+ }
391
+ };
392
+ const done = [];
393
+ const undo = () => {
394
+ const stuck = [];
395
+ for (const w of done.reverse()) {
396
+ const label = w.plan ?? `design/boards/${name}.json`;
397
+ let tmp;
398
+ try {
399
+ tmp = stageWrite(w.file, w.raw);
400
+ } catch {
401
+ stuck.push(label);
402
+ continue;
403
+ }
404
+ if (current_(w.file) !== w.next) {
405
+ discard(tmp);
406
+ stuck.push(`${label} (edited since - kept)`);
407
+ continue;
408
+ }
409
+ try {
410
+ renameSync(tmp, w.file);
411
+ } catch {
412
+ discard(tmp);
413
+ stuck.push(label);
414
+ }
415
+ }
416
+ return stuck;
417
+ };
418
+ for (const w of writes) {
419
+ if (w.next === w.raw) continue;
420
+ let tmp = null;
421
+ try {
422
+ tmp = stageWrite(w.file, w.next);
423
+ const now = current_(w.file);
424
+ if (now !== w.raw) {
425
+ discard(tmp);
426
+ const stuck = undo();
427
+ if (stuck.length) return json(res, 500, { error: `${w.plan ?? `board "${name}"`} changed on disk mid-write, and ${stuck.join(", ")} still ${stuck.length === 1 ? "holds" : "hold"} this change - check by hand` });
428
+ return json(res, 409, {
429
+ error: `${w.plan ?? `board "${name}"`} changed on disk - try again`,
430
+ ...w.plan || now === null ? {} : { sha256: hash(now) }
431
+ });
432
+ }
433
+ renameSync(tmp, w.file);
434
+ done.push(w);
435
+ } catch (err) {
436
+ if (tmp) discard(tmp);
437
+ const stuck = undo();
438
+ const off = writes.filter((x) => x.next !== x.raw && current_(x.file) !== x.raw).map((x) => x.plan ?? `design/boards/${name}.json`);
439
+ const named = [.../* @__PURE__ */ new Set([...stuck, ...off.filter((o) => !stuck.some((s) => s.startsWith(o)))])];
440
+ return json(res, 500, { error: named.length ? `could not write the status (${err.message}), and ${named.join(", ")} ${named.length === 1 ? "is" : "are"} not as before - check by hand` : `could not write the status (${err.message}) - nothing changed` });
441
+ }
442
+ }
210
443
  return json(res, 200, {
211
444
  name,
212
445
  sha256: hash(next)
213
446
  });
214
447
  }
448
+ const readManifestFrames = () => {
449
+ try {
450
+ const m = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
451
+ return Array.isArray(m?.frames) ? m.frames : null;
452
+ } catch {
453
+ return null;
454
+ }
455
+ };
456
+ if (path === "sizes" && req.method === "GET") {
457
+ const frames = readManifestFrames();
458
+ if (!frames) return json(res, 200, {
459
+ heights: {},
460
+ measuring: []
461
+ });
462
+ const measuring = measuringFrames(root, frames);
463
+ return json(res, 200, {
464
+ heights: keptSizes(readSizes(root), autoWidthOf(frames, opts.viewports ?? {}), measuring),
465
+ measuring: [...measuring].sort()
466
+ });
467
+ }
468
+ if (path === "sizes" && req.method === "POST") {
469
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
470
+ const raw = await readBody(req);
471
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
472
+ let body;
473
+ try {
474
+ body = JSON.parse(raw);
475
+ } catch {
476
+ return json(res, 400, { error: "malformed JSON" });
477
+ }
478
+ const incoming = body?.heights;
479
+ if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return json(res, 400, { error: "expected { heights: { \"scene/frame@width\": height } }" });
480
+ if (Object.keys(incoming).length > 500) return json(res, 400, { error: `at most 500 heights per write` });
481
+ {
482
+ const de = dirError();
483
+ if (de) return json(res, 400, { error: de });
484
+ }
485
+ const frames = readManifestFrames();
486
+ if (!frames) return json(res, 409, { error: "design/manifest.json is missing or mid-rewrite - try again" });
487
+ const file = sizesPath(root);
488
+ if (!notSymlink(file)) return json(res, 400, { error: "refusing to write a symlinked sizes file" });
489
+ const cur = readSizesFile(root);
490
+ if (cur.state === "invalid") {
491
+ if (!sizesWarned) {
492
+ sizesWarned = true;
493
+ console.warn(" marver: design/boards/_sizes.json is not valid JSON (a merge conflict?) - resolve it, either side is fine; heights are not saved until then");
494
+ }
495
+ return json(res, 409, { error: "design/boards/_sizes.json is not valid JSON - resolve it (either side is fine)" });
496
+ }
497
+ const { next, accepted } = mergeSizes(cur.heights, incoming, autoWidthOf(frames, opts.viewports ?? {}));
498
+ const text = serializeSizes(next);
499
+ const current = existsSync(file) ? readFileSync(file, "utf8") : "";
500
+ if (text !== current && (Object.keys(next).length || current)) {
501
+ mkdirSync(boardsDir, { recursive: true });
502
+ atomicWrite(file, text);
503
+ }
504
+ return json(res, 200, { accepted });
505
+ }
215
506
  if (path === "folders" && req.method === "GET") {
216
507
  const de = dirError();
217
508
  if (de) return json(res, 422, { error: de });
@@ -530,7 +821,7 @@ function apiMiddleware(root, opts = {}) {
530
821
  }
531
822
  }
532
823
  if (path === "shot" && req.method === "GET") {
533
- const { readDevInfo } = await import("./work-CLrmY-vQ.mjs");
824
+ const { readDevInfo } = await import("./work-CiUvBVa6.mjs").then((n) => n.o);
534
825
  const token = readDevInfo(root)?.token;
535
826
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
536
827
  const frameId = url.searchParams.get("frame") ?? "";
@@ -546,7 +837,7 @@ function apiMiddleware(root, opts = {}) {
546
837
  };
547
838
  const asPng = url.searchParams.get("format") === "png";
548
839
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
549
- const { shootFrame } = await import("./shot-BAR8hmU9.mjs");
840
+ const { shootFrame } = await import("./shot-CVOlQHUr.mjs");
550
841
  const r = await shootFrame({
551
842
  root,
552
843
  viewports: opts.viewports ?? {},
@@ -579,7 +870,7 @@ function apiMiddleware(root, opts = {}) {
579
870
  return res.end(png);
580
871
  }
581
872
  if (path === "shots" && req.method === "POST") {
582
- const { readDevInfo } = await import("./work-CLrmY-vQ.mjs");
873
+ const { readDevInfo } = await import("./work-CiUvBVa6.mjs").then((n) => n.o);
583
874
  const token = readDevInfo(root)?.token;
584
875
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
585
876
  const raw = await readBody(req);
@@ -596,7 +887,7 @@ function apiMiddleware(root, opts = {}) {
596
887
  if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
597
888
  const scale = body.scale === void 0 ? void 0 : body.scale;
598
889
  if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
599
- const { resolveFrames, shootBatch } = await import("./shot-BAR8hmU9.mjs");
890
+ const { resolveFrames, shootBatch } = await import("./shot-CVOlQHUr.mjs");
600
891
  const sel = resolveFrames(root, body);
601
892
  if (!sel.ok) return json(res, sel.status, { error: sel.error });
602
893
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
@@ -624,7 +915,7 @@ function apiMiddleware(root, opts = {}) {
624
915
  return json(res, 400, { error: "malformed JSON" });
625
916
  }
626
917
  if (!body || typeof body !== "object" || !Array.isArray(body.asks) || !body.asks.length || body.asks.length > 200) return json(res, 400, { error: "asks must list 1-200 frames" });
627
- const { bakeBatch, ASK_MAX } = await import("./bake-CvY8QR3L.mjs");
918
+ const { bakeBatch, ASK_MAX } = await import("./bake-l6N12qgx.mjs");
628
919
  let manifest = {};
629
920
  try {
630
921
  manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
@@ -668,8 +959,8 @@ function apiMiddleware(root, opts = {}) {
668
959
  if (path === "poster" && req.method === "GET") {
669
960
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
670
961
  const src = url.searchParams.get("src") ?? "";
671
- const { ensurePoster, isLocalClip } = await import("./poster-BduzQBYz.mjs");
672
- const { isLocalAssetRef } = await import("./build-B1kavcpc.mjs");
962
+ const { ensurePoster, isLocalClip } = await import("./poster-Bc4-3DlQ.mjs");
963
+ const { isLocalAssetRef } = await import("./build-CuRhHXcY.mjs");
673
964
  if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
674
965
  const r = await ensurePoster(join(root, "design", "assets"), src);
675
966
  if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
@@ -711,14 +1002,20 @@ function apiMiddleware(root, opts = {}) {
711
1002
  return json(res, 200, { user: localProfile(root) });
712
1003
  }
713
1004
  if (path === "work") {
714
- const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-CLrmY-vQ.mjs");
1005
+ const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-CiUvBVa6.mjs").then((n) => n.o);
715
1006
  const tokenOk = () => {
716
1007
  const t = readDevInfo(root)?.token;
717
1008
  return !!t && req.headers["x-mv-work"] === t;
718
1009
  };
719
1010
  if (req.method === "GET") {
720
1011
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
721
- return json(res, 200, { frames: workActivity.active() });
1012
+ const { boardsShowing, activityClock } = await import("./work-CiUvBVa6.mjs").then((n) => n.o);
1013
+ const frames = workActivity.active();
1014
+ return json(res, 200, {
1015
+ frames,
1016
+ boards: boardsShowing(root, frames),
1017
+ seq: activityClock.seq
1018
+ });
722
1019
  }
723
1020
  if (req.method === "POST") {
724
1021
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
@@ -739,7 +1036,35 @@ function apiMiddleware(root, opts = {}) {
739
1036
  if (!frames.length) return json(res, 400, { error: "frames required" });
740
1037
  const ttl = Math.min(Math.max(Number(b.ttlMs) || WORK_TTL_DEFAULT, 1e4), WORK_TTL_MAX);
741
1038
  for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
742
- return json(res, 200, { frames: workActivity.active() });
1039
+ if (!on) return json(res, 200, { frames: workActivity.active() });
1040
+ let behind = [];
1041
+ let contextPresent = false;
1042
+ try {
1043
+ const files = listBoardFiles(boardsDir).boards;
1044
+ const want = new Set(frames);
1045
+ const lit = new Set(files.filter((b) => {
1046
+ const j = b.json;
1047
+ return j?.auto === true || Array.isArray(j?.nodes) && j.nodes.some((n) => !!n && typeof n === "object" && want.has(n.frame));
1048
+ }).map((b) => b.name));
1049
+ const reg = readRegistry(boardsDir);
1050
+ const regFolders = reg.state === "ok" ? reg.folders : [];
1051
+ const fm = folderMap(buildTree(files.map((b) => ({
1052
+ name: b.name,
1053
+ ...boardFields(b.json, validName)
1054
+ })), regFolders));
1055
+ const facts = readContextFacts(root);
1056
+ contextPresent = facts.present;
1057
+ behind = [...annotateBoards(root, files.filter((b) => lit.has(b.name)), regFolders, (n) => fm.get(n) ?? null, facts)].filter(([, a]) => a.status && (a.status.status === "backlog" || a.status.status === "todo")).map(([board, a]) => ({
1058
+ board,
1059
+ status: a.status.status,
1060
+ capability: a.status.capability
1061
+ }));
1062
+ } catch {}
1063
+ return json(res, 200, {
1064
+ frames: workActivity.active(),
1065
+ behind,
1066
+ context: contextPresent
1067
+ });
743
1068
  }
744
1069
  }
745
1070
  if (path === "boards.rights" && req.method === "GET") {
@@ -780,14 +1105,14 @@ function apiMiddleware(root, opts = {}) {
780
1105
  };
781
1106
  });
782
1107
  const fresh = appendEvents(dir, cm[1], stamped);
783
- const { record } = await import("./ledger-Bu0BjqIe.mjs").then((n) => n.n);
1108
+ const { record } = await import("./ledger-BNXW14Xw.mjs");
784
1109
  for (const ev of fresh) if (ev.type === "create" || ev.type === "reply") record(root, cm[1], ev.id);
785
1110
  backgroundPush(root);
786
1111
  return json(res, 200, { accepted: fresh.length });
787
1112
  }
788
1113
  }
789
1114
  if (path === "sync" && req.method === "POST") {
790
- const { loadCollab, syncOnce } = await import("./sync-BZaCWqK-.mjs").then((n) => n.o);
1115
+ const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
791
1116
  const collab = loadCollab(root);
792
1117
  if (!collab) return json(res, 200, { connected: false });
793
1118
  try {
@@ -816,7 +1141,7 @@ function backgroundPush(root) {
816
1141
  pushTimer = setTimeout(async () => {
817
1142
  pushTimer = null;
818
1143
  try {
819
- const { loadCollab, syncOnce } = await import("./sync-BZaCWqK-.mjs").then((n) => n.o);
1144
+ const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
820
1145
  const collab = loadCollab(root);
821
1146
  if (collab) await syncOnce(root, collab);
822
1147
  } catch {}
@@ -1151,7 +1476,7 @@ function marverPlugin(ctx) {
1151
1476
  };
1152
1477
  const prune = () => setTimeout(async () => {
1153
1478
  try {
1154
- (await import("./bake-CvY8QR3L.mjs")).pruneBakes(root, bakeGen);
1479
+ (await import("./bake-l6N12qgx.mjs")).pruneBakes(root, bakeGen);
1155
1480
  } catch {}
1156
1481
  }, 500);
1157
1482
  prune();
@@ -1202,11 +1527,12 @@ function marverPlugin(ctx) {
1202
1527
  const timers = /* @__PURE__ */ new Map();
1203
1528
  let listTimer;
1204
1529
  const watcher = watch(boardsDir, (_event, file) => {
1205
- if (!file || !file.endsWith(".json")) return;
1530
+ if (!file || !file.endsWith(".json") || file === "_sizes.json") return;
1206
1531
  clearTimeout(listTimer);
1207
1532
  listTimer = setTimeout(() => {
1208
1533
  server.ws.send("sh:boards", {});
1209
1534
  regen();
1535
+ boardsChanged(root);
1210
1536
  }, 150);
1211
1537
  clearTimeout(timers.get(file));
1212
1538
  timers.set(file, setTimeout(() => {
@@ -1303,7 +1629,7 @@ function marverPlugin(ctx) {
1303
1629
  });
1304
1630
  return;
1305
1631
  }
1306
- const { shootFrame, shootBatch, resolveFrames } = await import("./shot-BAR8hmU9.mjs");
1632
+ const { shootFrame, shootBatch, resolveFrames } = await import("./shot-CVOlQHUr.mjs");
1307
1633
  if (ways[0] === "frame") {
1308
1634
  if (typeof spec.frame !== "string") {
1309
1635
  write({
@@ -1420,4 +1746,4 @@ async function tailwind3Css(root) {
1420
1746
  return null;
1421
1747
  }
1422
1748
  //#endregion
1423
- export { update_exports as i, tailwind3Css as n, tailwind4Plugin as r, marverPlugin as t };
1749
+ export { autoWidthOf as a, readSizes as c, update_exports as i, tailwind3Css as n, keptSizes as o, tailwind4Plugin as r, measuringFrames as s, marverPlugin as t };
@@ -1,4 +1,4 @@
1
- import { capture, t as findChrome } from "./shot-BAR8hmU9.mjs";
1
+ import { capture, t as findChrome } from "./shot-CVOlQHUr.mjs";
2
2
  import { constants, copyFileSync, existsSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { basename, dirname, join, sep } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
@@ -1,4 +1,4 @@
1
- import { i as loadCollab } from "./sync-BZaCWqK-.mjs";
1
+ import { i as loadCollab } from "./sync-DoA1vf4u.mjs";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  //#region src/server/profile.ts
@@ -1,6 +1,6 @@
1
1
  import { o as slideSize } from "./cli.mjs";
2
- import { planShot, t as findChrome } from "./shot-BAR8hmU9.mjs";
3
- import { ASK_MAX, bakeBatch } from "./bake-CvY8QR3L.mjs";
2
+ import { planShot, t as findChrome } from "./shot-CVOlQHUr.mjs";
3
+ import { ASK_MAX, bakeBatch } from "./bake-l6N12qgx.mjs";
4
4
  import { MIME } from "./serve-z5qtj_wJ.mjs";
5
5
  import { copyFileSync, lstatSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
6
6
  import { extname, isAbsolute, join, relative, resolve } from "node:path";
@@ -1,6 +1,6 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
2
  import { M as resolveAccess } from "./auth-DdUKeVKt.mjs";
3
- import { i as loadCollab } from "./sync-BZaCWqK-.mjs";
3
+ import { i as loadCollab } from "./sync-DoA1vf4u.mjs";
4
4
  //#region src/cli/share.ts
5
5
  /**
6
6
  * `marver share <action>` - the roster from the terminal (01-sharing §9).
@@ -1,5 +1,5 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { readDevInfo } from "./work-CLrmY-vQ.mjs";
2
+ import { i as readDevInfo } from "./work-CiUvBVa6.mjs";
3
3
  //#region src/cli/shot.ts
4
4
  /**
5
5
  * `marver shot <scene/frame> [...]`, `--scene <name>`, `--all` - render frames headless and
@@ -337,8 +337,8 @@ async function shootFrame(opts) {
337
337
  };
338
338
  const plan = planShot(frame, viewports, size);
339
339
  if (frame.kind !== "html") try {
340
- const { scanAssetRefs } = await import("./build-B1kavcpc.mjs");
341
- const { ensurePoster } = await import("./poster-BduzQBYz.mjs");
340
+ const { scanAssetRefs } = await import("./build-CuRhHXcY.mjs");
341
+ const { ensurePoster } = await import("./poster-Bc4-3DlQ.mjs");
342
342
  const refs = scanAssetRefs(readFileSync(join(root, frame.file), "utf8"), frame.file);
343
343
  for (const r of refs) if (r.endsWith(".poster.png")) await ensurePoster(join(root, "design", "assets"), r.slice(0, -11));
344
344
  } catch {}
@@ -27,6 +27,7 @@ var sync_exports = /* @__PURE__ */ __exportAll({
27
27
  connectClaim: () => connectClaim,
28
28
  connectToken: () => connectToken,
29
29
  loadCollab: () => loadCollab,
30
+ localOnlyThreads: () => localOnlyThreads,
30
31
  saveCollab: () => saveCollab,
31
32
  syncOnce: () => syncOnce
32
33
  });
@@ -149,7 +150,9 @@ async function syncOnce(root, collab) {
149
150
  const pulled = appendEvents(dir, board, remote).length;
150
151
  let pushed = 0;
151
152
  if (rights[board] === "comment") {
152
- const missing = diffEvents(readLog(dir, board), remote.map((e) => e.id)).filter((e) => !e.agent);
153
+ const local = readLog(dir, board);
154
+ const marverThreads = localOnlyThreads(local);
155
+ const missing = diffEvents(local, remote.map((e) => e.id)).filter((e) => !e.agent && !marverThreads.has(threadOf(e)));
153
156
  for (let i = 0; i < missing.length; i += 100) {
154
157
  const r = await fetch(`${base}/__mv/api/comments/${board}`, {
155
158
  method: "POST",
@@ -294,5 +297,16 @@ async function connectToken(root, url, token) {
294
297
  avatar: body.user.avatar
295
298
  });
296
299
  }
300
+ /** The thread an event belongs to: a reply names its root; everything else names its comment. */
301
+ const threadOf = (e) => e.parentId ?? e.commentId ?? "";
302
+ /** Threads that live on this machine only: started by Marver (an agent's `comments new`). Every id
303
+ * that resolves to one - the thread, and each reply in it (an edit or reaction names the reply) - is
304
+ * in the set, so `threadOf` of any event in such a thread hits it. */
305
+ function localOnlyThreads(events) {
306
+ const roots = new Set(events.filter((e) => e.agent && e.type === "create" && e.commentId).map((e) => e.commentId));
307
+ const out = new Set(roots);
308
+ for (const e of events) if (e.type === "reply" && e.parentId && roots.has(e.parentId) && e.commentId) out.add(e.commentId);
309
+ return out;
310
+ }
297
311
  //#endregion
298
312
  export { syncOnce as a, loadCollab as i, connectClaim as n, sync_exports as o, connectToken as r, connect as t };