@marver-design/marver 0.22.1 → 0.23.1

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 (65) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +14 -10
  3. package/dist/agent-BsieQGTD.mjs +99 -0
  4. package/dist/{bake-CvY8QR3L.mjs → bake-DQtnDB8-.mjs} +1 -1
  5. package/dist/{board-status-CWGHIdo_.mjs → board-status-BZSzc9Hp.mjs} +69 -610
  6. package/dist/boards-BRLnoTC3.mjs +620 -0
  7. package/dist/{boards-BwKI0qWd.mjs → boards-Dv-Ipd8G.mjs} +13 -5
  8. package/dist/{build-B1kavcpc.mjs → build-_ndp_dXn.mjs} +18 -10
  9. package/dist/cli.mjs +20 -11
  10. package/dist/{comments-ClVgfQib.mjs → comments-BlqyZh3D.mjs} +71 -9
  11. package/dist/{config-DJxMRVD8.mjs → config-BUKprFAp.mjs} +5 -97
  12. package/dist/{context-D4t59wDi.mjs → context-CdkNiKdJ.mjs} +3 -2
  13. package/dist/{daemon-PmNqoOAk.mjs → daemon-BvMPdQ3k.mjs} +78 -19
  14. package/dist/{dev-Cf4wLGe2.mjs → dev-Cf-4eqaC.mjs} +50 -10
  15. package/dist/{init-C_K-cjBQ.mjs → init-hfZV7TwY.mjs} +10 -4
  16. package/dist/{ledger-Bu0BjqIe.mjs → ledger-BNXW14Xw.mjs} +1 -6
  17. package/dist/link-BodAbIQz.mjs +132 -0
  18. package/dist/{manifest-CcdWx7ud.mjs → manifest-TpfDWldB.mjs} +56 -6
  19. package/dist/{plugin-C5u07Yhv.mjs → plugin-DoXql0ZZ.mjs} +400 -48
  20. package/dist/{poster-BduzQBYz.mjs → poster-XBmUvQiL.mjs} +1 -1
  21. package/dist/{profile-BjAPAJSb.mjs → profile-CrZohD6g.mjs} +1 -1
  22. package/dist/{publish-bakes-b0jUwvM_.mjs → publish-bakes-KKTHWqq3.mjs} +2 -2
  23. package/dist/{share--bdSc4G5.mjs → share-BD-wcDQq.mjs} +1 -1
  24. package/dist/{shot-BAR8hmU9.mjs → shot-DOD8v6fJ.mjs} +2 -2
  25. package/dist/{shot-BFEuYbaz.mjs → shot-Dh6fV1Lm.mjs} +1 -1
  26. package/dist/{sync-BZaCWqK-.mjs → sync-DoA1vf4u.mjs} +15 -1
  27. package/dist/{work-0YopuMt9.mjs → work-ClFFq0Qh.mjs} +9 -3
  28. package/dist/{work-CLrmY-vQ.mjs → work-ayuL_9Kk.mjs} +72 -1
  29. package/docs/boards-and-folders.md +60 -7
  30. package/docs/context.md +10 -2
  31. package/docs/live-jam.md +11 -0
  32. package/docs/sticky-notes.md +1 -1
  33. package/package.json +1 -1
  34. package/src/client/content/diagram.tsx +7 -1
  35. package/src/client/content/img-lod.ts +12 -2
  36. package/src/client/content/index.tsx +73 -6
  37. package/src/client/content/md.ts +3 -2
  38. package/src/client/frame-host/inspect.js +23 -0
  39. package/src/client/shell/App.tsx +21 -10
  40. package/src/client/shell/BoardList.tsx +26 -6
  41. package/src/client/shell/LockedApp.tsx +2 -2
  42. package/src/client/shell/Play.tsx +5 -1
  43. package/src/client/shell/StatusPicker.tsx +12 -5
  44. package/src/client/shell/Tip.tsx +25 -5
  45. package/src/client/shell/board-icons.tsx +15 -1
  46. package/src/client/shell/canvas/Canvas.tsx +42 -6
  47. package/src/client/shell/canvas/anchor.ts +41 -0
  48. package/src/client/shell/canvas/ctl.ts +6 -0
  49. package/src/client/shell/comments-store.ts +8 -5
  50. package/src/client/shell/goto.ts +52 -3
  51. package/src/client/shell/hash.ts +24 -3
  52. package/src/client/shell/store.ts +261 -36
  53. package/src/client/shell/styles.css +20 -2
  54. package/src/client/shell/tidy.ts +34 -3
  55. package/src/shared/board-types.ts +10 -6
  56. package/src/shared/frames.ts +3 -0
  57. package/src/shared/status.ts +17 -8
  58. package/templates/AGENTS-embedded.md +43 -8
  59. package/templates/AGENTS-studio.md +43 -8
  60. package/templates/instructions/boards.md +13 -3
  61. package/templates/instructions/context.md +6 -2
  62. package/templates/instructions/iterate.md +29 -16
  63. package/templates/instructions/jam.md +9 -2
  64. package/templates/instructions/reference/deck-layouts.md +2 -1
  65. package/templates/instructions/reference/deck-story.md +2 -1
@@ -1,13 +1,136 @@
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 { C as wireKids, D as HAS_STATUS, F as resolveType, I as settableStatuses, L as hash, M as readReason, N as readStatusWord, P as readType, S as validateWire, _ as folderMap, b as readDescription, c as nodeExists, d as withRegistryLock, f as BOARD_NAME, i as checkBoardsDir, j as readCapability, l as parseBoard, m as buildTree, o as isRegularFile, p as FOLDERS_FILE, r as boardFields, s as listBoardFiles, t as AUTHOR_FIELDS, u as readRegistry, x as readTitle } from "./boards-BRLnoTC3.mjs";
4
+ import { i as readContextFacts, n as planNames, r as planWithStage, t as annotateBoards } from "./board-status-BZSzc9Hp.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-TpfDWldB.mjs";
7
+ import { n as loadConfig } from "./config-BUKprFAp.mjs";
8
+ import { r as boardsChanged } from "./work-ayuL_9Kk.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/shared/frames.ts
14
+ /** A canvas made of content frames alone (Doc, Md, Diagram ship their own styling) needs no theme -
15
+ * only an app frame does (#4). Empty counts as not content-only: the warning still helps there. */
16
+ const contentOnly = (frames) => frames.length > 0 && frames.every((f) => !!f.intent);
17
+ //#endregion
18
+ //#region src/server/sizes.ts
19
+ /**
20
+ * Content-frame heights - `design/boards/_sizes.json`, committed.
21
+ *
22
+ * A content frame (a Doc: markdown, diagrams, images) is as tall as its content, which only a
23
+ * render can tell. Measured live, every load started from a guess (3/4 of the width) and grew
24
+ * frame by frame, and each growth re-flowed the rows below - the board swam for seconds. The
25
+ * height a frame measured at its own width is a fact about the FRAME at that width, not about a
26
+ * board (one doc sits on several boards) and not something to write into the frame's source: so
27
+ * it lives here, one line per `scene/frame@width`, written by the dev server when the shell
28
+ * reports a settled measurement, read before the first layout - dev, `marver build` and the
29
+ * published canvas alike. A stale entry is still the best first guess; the live measurement
30
+ * corrects it and the file follows. Underscore = infrastructure, never a board (board-tree.ts).
31
+ */
32
+ const SIZES_FILE = "_sizes.json";
33
+ /** `scene/frame@width` - the frame id grammar the focus route accepts, then the width it was measured at. */
34
+ const SIZE_KEY = /^([\w./-]{1,200})@(\d{2,4})$/;
35
+ 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.";
36
+ const sizesPath = (root) => join(root, "design", "boards", SIZES_FILE);
37
+ /** A valid entry: a well-formed key whose frame is not a traversal, and a height in the shell's clamp. */
38
+ function validEntry(key, h) {
39
+ if (typeof key !== "string" || typeof h !== "number" || !Number.isInteger(h) || h < 80 || h > 4e4) return false;
40
+ const m = SIZE_KEY.exec(key);
41
+ return !!m && !m[1].split("/").some((p) => p === ".." || p === "." || p === "");
42
+ }
43
+ function readSizesFile(root) {
44
+ const file = sizesPath(root);
45
+ if (!existsSync(file)) return {
46
+ state: "absent",
47
+ heights: {}
48
+ };
49
+ try {
50
+ const raw = JSON.parse(readFileSync(file, "utf8"));
51
+ if (!raw || typeof raw !== "object" || !raw.heights || typeof raw.heights !== "object" || Array.isArray(raw.heights)) return {
52
+ state: "invalid",
53
+ heights: {}
54
+ };
55
+ const out = {};
56
+ for (const [k, v] of Object.entries(raw.heights)) if (validEntry(k, v)) out[k] = v;
57
+ return {
58
+ state: "ok",
59
+ heights: out
60
+ };
61
+ } catch {
62
+ return {
63
+ state: "invalid",
64
+ heights: {}
65
+ };
66
+ }
67
+ }
68
+ /** Lenient read for the readers (the shell's first layout, the build): an absent or invalid file is
69
+ * no heights - every frame opens at its placeholder, as before. Never throws. */
70
+ const readSizes = (root) => readSizesFile(root).heights;
71
+ /** The file's text for a set of heights: sorted keys, one entry per line - a changed height is a
72
+ * one-line diff, and two branches that measured different frames merge without a conflict. */
73
+ function serializeSizes(heights) {
74
+ const sorted = {};
75
+ for (const k of Object.keys(heights).sort()) sorted[k] = heights[k];
76
+ return JSON.stringify({
77
+ about: ABOUT,
78
+ heights: sorted
79
+ }, null, 2) + "\n";
80
+ }
81
+ const keeps = (key, autoWidth) => {
82
+ const m = SIZE_KEY.exec(key);
83
+ return !!m && autoWidth(m[1]) === Number(m[2]);
84
+ };
85
+ /** Merge incoming heights into the current ones, keeping only what a board can use: a content frame
86
+ * that still exists, at the width it measures at on its own. Everything else is pruned - a deleted
87
+ * frame, a Doc that went from document to wide. Returns the next map and the keys taken. Pruning
88
+ * reads only the manifest: whether a frame still renders a Doc is asked on READ (keptSizes), so a
89
+ * source caught mid-write can hide an entry for one load, never delete it. */
90
+ function mergeSizes(current, incoming, autoWidth) {
91
+ const next = Object.fromEntries(Object.entries(current).filter(([k]) => keeps(k, autoWidth)));
92
+ const accepted = [];
93
+ for (const [k, v] of Object.entries(incoming)) {
94
+ if (!validEntry(k, v) || !keeps(k, autoWidth)) continue;
95
+ next[k] = v;
96
+ accepted.push(k);
97
+ }
98
+ return {
99
+ next,
100
+ accepted
101
+ };
102
+ }
103
+ /** The entries a board can use - what the GET and the build hand the shell: a content frame at its
104
+ * own width that MEASURES (renders a Doc). A frame that went from a Doc to a bare Md keeps the size
105
+ * its board gives it, never an old measurement. */
106
+ const keptSizes = (heights, autoWidth, measuring) => Object.fromEntries(Object.entries(heights).filter(([k]) => keeps(k, autoWidth) && measuring.has(k.slice(0, k.lastIndexOf("@")))));
107
+ /** The auto width rule over a manifest's frames (the shell's defaultSize, store.ts). */
108
+ function autoWidthOf(frames, viewports) {
109
+ const byId = new Map(frames.map((f) => [f.id, f]));
110
+ return (id) => {
111
+ const f = byId.get(id);
112
+ if (!f?.contentWidth) return null;
113
+ return viewports[f.viewport ?? ""]?.width ?? f.contentWidth;
114
+ };
115
+ }
116
+ /** The content frames that measure: the frame renders a Doc, or a `_layout` it renders inside does
117
+ * (manifest.ts layoutDocSource - the same rule the manifest's width follows). A source that cannot
118
+ * be read, or reads empty (an editor mid-write), gets the benefit of the doubt - this only decides
119
+ * what a load is handed, never what the file keeps. */
120
+ function measuringFrames(root, frames) {
121
+ const out = /* @__PURE__ */ new Set();
122
+ const memo = /* @__PURE__ */ new Map();
123
+ for (const f of frames) {
124
+ if (!f.contentWidth || f.kind === "html" || !f.file || f.file.split("/").includes("..")) continue;
125
+ let src = "";
126
+ try {
127
+ src = readFileSync(join(root, f.file), "utf8");
128
+ } catch {}
129
+ if (!src.trim() || rendersDoc(src) || layoutDocSource(root, f.file, memo) !== null) out.add(f.id);
130
+ }
131
+ return out;
132
+ }
133
+ //#endregion
11
134
  //#region src/server/api.ts
12
135
  const BODY_LIMIT = 1e6;
13
136
  const CSRF_MAX_AGE = 2592e3;
@@ -66,9 +189,38 @@ function atomicWrite(file, content) {
66
189
  throw err;
67
190
  }
68
191
  copyFileSync(tmp, file);
69
- rmSync(tmp, { force: true });
192
+ try {
193
+ rmSync(tmp, { force: true });
194
+ } catch {}
195
+ }
196
+ }
197
+ /** A replacement that is whole or not at all, in two steps: `stageWrite` puts the new content in a temp
198
+ * file beside the destination; `rename` swaps it in - one syscall, so a caller can look at the
199
+ * destination right before it and nothing but that rename stands between the look and the write.
200
+ * Never the copy fallback: a copy can fail part way, or not at all, and nothing tells which. For the
201
+ * status write, which writes several files and must say exactly what it changed. */
202
+ function stageWrite(file, content) {
203
+ const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
204
+ const fd = openSync(tmp, "wx");
205
+ let open = true;
206
+ try {
207
+ writeFileSync(fd, content);
208
+ open = false;
209
+ closeSync(fd);
210
+ } catch (err) {
211
+ if (open) try {
212
+ closeSync(fd);
213
+ } catch {}
214
+ discard(tmp);
215
+ throw err;
70
216
  }
217
+ return tmp;
71
218
  }
219
+ const discard = (tmp) => {
220
+ try {
221
+ rmSync(tmp, { force: true });
222
+ } catch {}
223
+ };
72
224
  /** Containment beyond string prefixes: the realpath of the parent dir must stay inside base. */
73
225
  function contained(target, base) {
74
226
  try {
@@ -98,6 +250,7 @@ function apiMiddleware(root, opts = {}) {
98
250
  const dirError = () => checkBoardsDir(root, boardsDir);
99
251
  const notSymlink = (p) => !nodeExists(p) || isRegularFile(p);
100
252
  const nodeExists$1 = nodeExists;
253
+ let sizesWarned = false;
101
254
  try {
102
255
  for (const f of readdirSync(boardsDir)) if (f.endsWith(".tmp")) rmSync(join(boardsDir, f), { force: true });
103
256
  } catch {}
@@ -132,7 +285,8 @@ function apiMiddleware(root, opts = {}) {
132
285
  const files = listBoardFiles(boardsDir).boards;
133
286
  const rows = files.map((b) => ({
134
287
  name: b.name,
135
- ...boardFields(b.json, validName)
288
+ ...boardFields(b.json, validName),
289
+ ...b.error ? { error: b.error } : {}
136
290
  }));
137
291
  const reg = readRegistry(boardsDir);
138
292
  const regFolders = reg.state === "ok" ? reg.folders : [];
@@ -140,14 +294,14 @@ function apiMiddleware(root, opts = {}) {
140
294
  const fm = folderMap(tree);
141
295
  const facts = readContextFacts(root);
142
296
  const notes = annotateBoards(root, files, regFolders, (n) => fm.get(n) ?? null, facts);
143
- const settable = settableStatuses(facts.present);
297
+ const settableFor = (cap) => settableStatuses(facts.present, !!facts.plans.get(cap)?.length);
144
298
  return json(res, 200, files.map((b, i) => {
145
299
  const n = notes.get(b.name);
146
300
  return {
147
301
  ...rows[i],
148
302
  sha256: b.sha256,
149
303
  ...n ?? {},
150
- ...n?.status ? { settable } : {}
304
+ ...n?.status ? { settable: settableFor(n.status.capability) } : {}
151
305
  };
152
306
  }));
153
307
  }
@@ -200,18 +354,161 @@ function apiMiddleware(root, opts = {}) {
200
354
  const parent = folder?.parent ? regFolders.find((f) => f.name === folder.parent) : void 0;
201
355
  const type = resolveType(obj.type, folder?.type, parent?.type);
202
356
  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;
357
+ const facts = readContextFacts(root);
358
+ const capability = readCapability(obj.capability) ?? name;
359
+ const plans = facts.present ? facts.plans.get(capability) ?? [] : [];
360
+ 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` });
361
+ const writes = [];
362
+ if (facts.present && (status === "building" || status === "in-progress")) {
363
+ for (const p of plans.filter((x, i) => plans.findIndex((y) => y.where === x.where) === i)) {
364
+ const file = join(root, p.where);
365
+ if (!notSymlink(file)) return json(res, 400, { error: `refusing to write a symlinked plan (${p.where})` });
366
+ const raw = readFileSync(file, "utf8");
367
+ if (!planNames(raw, capability)) return json(res, 409, { error: `${p.where} changed on disk - try again` });
368
+ const r = planWithStage(raw, status === "building" ? "build" : null);
369
+ if ("error" in r) return json(res, 422, { error: `${p.where} ${r.error} - fix the file` });
370
+ writes.push({
371
+ file,
372
+ raw,
373
+ next: r.text,
374
+ plan: p.where
375
+ });
376
+ }
377
+ delete obj.status;
378
+ delete obj.reason;
379
+ } else {
380
+ if (status === null) delete obj.status;
381
+ else obj.status = status;
382
+ if (status === "blocked") obj.reason = reason;
383
+ else delete obj.reason;
384
+ }
208
385
  const next = JSON.stringify(obj, null, 2) + "\n";
209
- if (next !== current) atomicWrite(file, next);
386
+ writes.push({
387
+ file,
388
+ raw: current,
389
+ next
390
+ });
391
+ const current_ = (f) => {
392
+ try {
393
+ return readFileSync(f, "utf8");
394
+ } catch {
395
+ return null;
396
+ }
397
+ };
398
+ const done = [];
399
+ const undo = () => {
400
+ const stuck = [];
401
+ for (const w of done.reverse()) {
402
+ const label = w.plan ?? `design/boards/${name}.json`;
403
+ let tmp;
404
+ try {
405
+ tmp = stageWrite(w.file, w.raw);
406
+ } catch {
407
+ stuck.push(label);
408
+ continue;
409
+ }
410
+ if (current_(w.file) !== w.next) {
411
+ discard(tmp);
412
+ stuck.push(`${label} (edited since - kept)`);
413
+ continue;
414
+ }
415
+ try {
416
+ renameSync(tmp, w.file);
417
+ } catch {
418
+ discard(tmp);
419
+ stuck.push(label);
420
+ }
421
+ }
422
+ return stuck;
423
+ };
424
+ for (const w of writes) {
425
+ if (w.next === w.raw) continue;
426
+ let tmp = null;
427
+ try {
428
+ tmp = stageWrite(w.file, w.next);
429
+ const now = current_(w.file);
430
+ if (now !== w.raw) {
431
+ discard(tmp);
432
+ const stuck = undo();
433
+ 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` });
434
+ return json(res, 409, {
435
+ error: `${w.plan ?? `board "${name}"`} changed on disk - try again`,
436
+ ...w.plan || now === null ? {} : { sha256: hash(now) }
437
+ });
438
+ }
439
+ renameSync(tmp, w.file);
440
+ done.push(w);
441
+ } catch (err) {
442
+ if (tmp) discard(tmp);
443
+ const stuck = undo();
444
+ const off = writes.filter((x) => x.next !== x.raw && current_(x.file) !== x.raw).map((x) => x.plan ?? `design/boards/${name}.json`);
445
+ const named = [.../* @__PURE__ */ new Set([...stuck, ...off.filter((o) => !stuck.some((s) => s.startsWith(o)))])];
446
+ 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` });
447
+ }
448
+ }
210
449
  return json(res, 200, {
211
450
  name,
212
451
  sha256: hash(next)
213
452
  });
214
453
  }
454
+ const readManifestFrames = () => {
455
+ try {
456
+ const m = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
457
+ return Array.isArray(m?.frames) ? m.frames : null;
458
+ } catch {
459
+ return null;
460
+ }
461
+ };
462
+ if (path === "sizes" && req.method === "GET") {
463
+ const frames = readManifestFrames();
464
+ if (!frames) return json(res, 200, {
465
+ heights: {},
466
+ measuring: []
467
+ });
468
+ const measuring = measuringFrames(root, frames);
469
+ return json(res, 200, {
470
+ heights: keptSizes(readSizes(root), autoWidthOf(frames, opts.viewports ?? {}), measuring),
471
+ measuring: [...measuring].sort()
472
+ });
473
+ }
474
+ if (path === "sizes" && req.method === "POST") {
475
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
476
+ const raw = await readBody(req);
477
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
478
+ let body;
479
+ try {
480
+ body = JSON.parse(raw);
481
+ } catch {
482
+ return json(res, 400, { error: "malformed JSON" });
483
+ }
484
+ const incoming = body?.heights;
485
+ if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return json(res, 400, { error: "expected { heights: { \"scene/frame@width\": height } }" });
486
+ if (Object.keys(incoming).length > 500) return json(res, 400, { error: `at most 500 heights per write` });
487
+ {
488
+ const de = dirError();
489
+ if (de) return json(res, 400, { error: de });
490
+ }
491
+ const frames = readManifestFrames();
492
+ if (!frames) return json(res, 409, { error: "design/manifest.json is missing or mid-rewrite - try again" });
493
+ const file = sizesPath(root);
494
+ if (!notSymlink(file)) return json(res, 400, { error: "refusing to write a symlinked sizes file" });
495
+ const cur = readSizesFile(root);
496
+ if (cur.state === "invalid") {
497
+ if (!sizesWarned) {
498
+ sizesWarned = true;
499
+ 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");
500
+ }
501
+ return json(res, 409, { error: "design/boards/_sizes.json is not valid JSON - resolve it (either side is fine)" });
502
+ }
503
+ const { next, accepted } = mergeSizes(cur.heights, incoming, autoWidthOf(frames, opts.viewports ?? {}));
504
+ const text = serializeSizes(next);
505
+ const current = existsSync(file) ? readFileSync(file, "utf8") : "";
506
+ if (text !== current && (Object.keys(next).length || current)) {
507
+ mkdirSync(boardsDir, { recursive: true });
508
+ atomicWrite(file, text);
509
+ }
510
+ return json(res, 200, { accepted });
511
+ }
215
512
  if (path === "folders" && req.method === "GET") {
216
513
  const de = dirError();
217
514
  if (de) return json(res, 422, { error: de });
@@ -483,14 +780,12 @@ function apiMiddleware(root, opts = {}) {
483
780
  if (req.method === "GET") {
484
781
  if (!existsSync(p)) return json(res, 200, { board: null });
485
782
  const content = readFileSync(p, "utf8");
486
- try {
487
- return json(res, 200, {
488
- board: JSON.parse(content),
489
- sha256: hash(content)
490
- });
491
- } catch {
492
- return json(res, 422, { error: `board "${boardMatch[1]}" is not valid JSON - fix the file` });
493
- }
783
+ const parsed = parseBoard(content);
784
+ if (parsed.error) return json(res, 422, { error: `design/boards/${boardMatch[1]}.json is not valid JSON - ${parsed.error}` });
785
+ return json(res, 200, {
786
+ board: parsed.json,
787
+ sha256: hash(content)
788
+ });
494
789
  }
495
790
  if (req.method === "PUT") {
496
791
  const raw = await readBody(req);
@@ -530,7 +825,7 @@ function apiMiddleware(root, opts = {}) {
530
825
  }
531
826
  }
532
827
  if (path === "shot" && req.method === "GET") {
533
- const { readDevInfo } = await import("./work-CLrmY-vQ.mjs");
828
+ const { readDevInfo } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
534
829
  const token = readDevInfo(root)?.token;
535
830
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
536
831
  const frameId = url.searchParams.get("frame") ?? "";
@@ -546,7 +841,7 @@ function apiMiddleware(root, opts = {}) {
546
841
  };
547
842
  const asPng = url.searchParams.get("format") === "png";
548
843
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
549
- const { shootFrame } = await import("./shot-BAR8hmU9.mjs");
844
+ const { shootFrame } = await import("./shot-DOD8v6fJ.mjs");
550
845
  const r = await shootFrame({
551
846
  root,
552
847
  viewports: opts.viewports ?? {},
@@ -579,7 +874,7 @@ function apiMiddleware(root, opts = {}) {
579
874
  return res.end(png);
580
875
  }
581
876
  if (path === "shots" && req.method === "POST") {
582
- const { readDevInfo } = await import("./work-CLrmY-vQ.mjs");
877
+ const { readDevInfo } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
583
878
  const token = readDevInfo(root)?.token;
584
879
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
585
880
  const raw = await readBody(req);
@@ -596,7 +891,7 @@ function apiMiddleware(root, opts = {}) {
596
891
  if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
597
892
  const scale = body.scale === void 0 ? void 0 : body.scale;
598
893
  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");
894
+ const { resolveFrames, shootBatch } = await import("./shot-DOD8v6fJ.mjs");
600
895
  const sel = resolveFrames(root, body);
601
896
  if (!sel.ok) return json(res, sel.status, { error: sel.error });
602
897
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
@@ -624,7 +919,7 @@ function apiMiddleware(root, opts = {}) {
624
919
  return json(res, 400, { error: "malformed JSON" });
625
920
  }
626
921
  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");
922
+ const { bakeBatch, ASK_MAX } = await import("./bake-DQtnDB8-.mjs");
628
923
  let manifest = {};
629
924
  try {
630
925
  manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
@@ -668,8 +963,8 @@ function apiMiddleware(root, opts = {}) {
668
963
  if (path === "poster" && req.method === "GET") {
669
964
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
670
965
  const src = url.searchParams.get("src") ?? "";
671
- const { ensurePoster, isLocalClip } = await import("./poster-BduzQBYz.mjs");
672
- const { isLocalAssetRef } = await import("./build-B1kavcpc.mjs");
966
+ const { ensurePoster, isLocalClip } = await import("./poster-XBmUvQiL.mjs");
967
+ const { isLocalAssetRef } = await import("./build-_ndp_dXn.mjs");
673
968
  if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
674
969
  const r = await ensurePoster(join(root, "design", "assets"), src);
675
970
  if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
@@ -711,14 +1006,20 @@ function apiMiddleware(root, opts = {}) {
711
1006
  return json(res, 200, { user: localProfile(root) });
712
1007
  }
713
1008
  if (path === "work") {
714
- const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-CLrmY-vQ.mjs");
1009
+ const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
715
1010
  const tokenOk = () => {
716
1011
  const t = readDevInfo(root)?.token;
717
1012
  return !!t && req.headers["x-mv-work"] === t;
718
1013
  };
719
1014
  if (req.method === "GET") {
720
1015
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
721
- return json(res, 200, { frames: workActivity.active() });
1016
+ const { boardsShowing, activityClock } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
1017
+ const frames = workActivity.active();
1018
+ return json(res, 200, {
1019
+ frames,
1020
+ boards: boardsShowing(root, frames),
1021
+ seq: activityClock.seq
1022
+ });
722
1023
  }
723
1024
  if (req.method === "POST") {
724
1025
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
@@ -739,7 +1040,35 @@ function apiMiddleware(root, opts = {}) {
739
1040
  if (!frames.length) return json(res, 400, { error: "frames required" });
740
1041
  const ttl = Math.min(Math.max(Number(b.ttlMs) || WORK_TTL_DEFAULT, 1e4), WORK_TTL_MAX);
741
1042
  for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
742
- return json(res, 200, { frames: workActivity.active() });
1043
+ if (!on) return json(res, 200, { frames: workActivity.active() });
1044
+ let behind = [];
1045
+ let contextPresent = false;
1046
+ try {
1047
+ const files = listBoardFiles(boardsDir).boards;
1048
+ const want = new Set(frames);
1049
+ const lit = new Set(files.filter((b) => {
1050
+ const j = b.json;
1051
+ return j?.auto === true || Array.isArray(j?.nodes) && j.nodes.some((n) => !!n && typeof n === "object" && want.has(n.frame));
1052
+ }).map((b) => b.name));
1053
+ const reg = readRegistry(boardsDir);
1054
+ const regFolders = reg.state === "ok" ? reg.folders : [];
1055
+ const fm = folderMap(buildTree(files.map((b) => ({
1056
+ name: b.name,
1057
+ ...boardFields(b.json, validName)
1058
+ })), regFolders));
1059
+ const facts = readContextFacts(root);
1060
+ contextPresent = facts.present;
1061
+ 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]) => ({
1062
+ board,
1063
+ status: a.status.status,
1064
+ capability: a.status.capability
1065
+ }));
1066
+ } catch {}
1067
+ return json(res, 200, {
1068
+ frames: workActivity.active(),
1069
+ behind,
1070
+ context: contextPresent
1071
+ });
743
1072
  }
744
1073
  }
745
1074
  if (path === "boards.rights" && req.method === "GET") {
@@ -780,14 +1109,14 @@ function apiMiddleware(root, opts = {}) {
780
1109
  };
781
1110
  });
782
1111
  const fresh = appendEvents(dir, cm[1], stamped);
783
- const { record } = await import("./ledger-Bu0BjqIe.mjs").then((n) => n.n);
1112
+ const { record } = await import("./ledger-BNXW14Xw.mjs");
784
1113
  for (const ev of fresh) if (ev.type === "create" || ev.type === "reply") record(root, cm[1], ev.id);
785
1114
  backgroundPush(root);
786
1115
  return json(res, 200, { accepted: fresh.length });
787
1116
  }
788
1117
  }
789
1118
  if (path === "sync" && req.method === "POST") {
790
- const { loadCollab, syncOnce } = await import("./sync-BZaCWqK-.mjs").then((n) => n.o);
1119
+ const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
791
1120
  const collab = loadCollab(root);
792
1121
  if (!collab) return json(res, 200, { connected: false });
793
1122
  try {
@@ -816,7 +1145,7 @@ function backgroundPush(root) {
816
1145
  pushTimer = setTimeout(async () => {
817
1146
  pushTimer = null;
818
1147
  try {
819
- const { loadCollab, syncOnce } = await import("./sync-BZaCWqK-.mjs").then((n) => n.o);
1148
+ const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
820
1149
  const collab = loadCollab(root);
821
1150
  if (collab) await syncOnce(root, collab);
822
1151
  } catch {}
@@ -988,6 +1317,10 @@ function marverPlugin(ctx) {
988
1317
  revision: `${bootId}:${++invRev}`
989
1318
  });
990
1319
  }, 120);
1320
+ /** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
1321
+ * Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
1322
+ * manifest; the config carries only whether a theme exists. */
1323
+ const themeMissing = () => themeFile() == null && !contentOnly(manifest.frames);
991
1324
  /** Theme resolution: design/theme.css wrapper > configured > detected > empty (spec §5.4). */
992
1325
  const themeFile = () => {
993
1326
  const wrapper = join(root, "design", "theme.css");
@@ -1006,7 +1339,7 @@ function marverPlugin(ctx) {
1006
1339
  },
1007
1340
  load(id) {
1008
1341
  if (id === "\0virtual:sh-theme.css") {
1009
- console.warn("[marver] no theme detected - frames render unstyled. Create design/theme.css importing your app's stylesheet (or set `theme` in design/config.ts).");
1342
+ if (themeMissing()) console.warn("[marver] no theme detected - frames render unstyled. Create design/theme.css importing your app's stylesheet (or set `theme` in design/config.ts).");
1010
1343
  return "/* marver: no theme configured */";
1011
1344
  }
1012
1345
  if (id === "\0virtual:sh-config") {
@@ -1151,7 +1484,7 @@ function marverPlugin(ctx) {
1151
1484
  };
1152
1485
  const prune = () => setTimeout(async () => {
1153
1486
  try {
1154
- (await import("./bake-CvY8QR3L.mjs")).pruneBakes(root, bakeGen);
1487
+ (await import("./bake-DQtnDB8-.mjs")).pruneBakes(root, bakeGen);
1155
1488
  } catch {}
1156
1489
  }, 500);
1157
1490
  prune();
@@ -1200,25 +1533,44 @@ function marverPlugin(ctx) {
1200
1533
  try {
1201
1534
  mkdirSync(boardsDir, { recursive: true });
1202
1535
  const timers = /* @__PURE__ */ new Map();
1536
+ const badBoards = /* @__PURE__ */ new Map();
1537
+ const reportBad = (file, content, error) => {
1538
+ if (badBoards.get(file) === hash(content)) return;
1539
+ badBoards.set(file, hash(content));
1540
+ console.warn(`[marver] design/boards/${file} is not valid JSON - ${error}`);
1541
+ };
1542
+ if (!checkBoardsDir(root, boardsDir)) {
1543
+ for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
1544
+ }
1203
1545
  let listTimer;
1204
1546
  const watcher = watch(boardsDir, (_event, file) => {
1205
- if (!file || !file.endsWith(".json")) return;
1547
+ if (!file || !file.endsWith(".json") || file === "_sizes.json") return;
1206
1548
  clearTimeout(listTimer);
1207
1549
  listTimer = setTimeout(() => {
1208
1550
  server.ws.send("sh:boards", {});
1209
1551
  regen();
1552
+ boardsChanged(root);
1210
1553
  }, 150);
1211
1554
  clearTimeout(timers.get(file));
1212
1555
  timers.set(file, setTimeout(() => {
1213
1556
  timers.delete(file);
1557
+ let content;
1558
+ if (!isRegularFile(join(boardsDir, file))) return;
1214
1559
  try {
1215
- const content = readFileSync(join(boardsDir, file), "utf8");
1216
- JSON.parse(content);
1217
- server.ws.send("sh:board", {
1218
- name: file.replace(/\.json$/, ""),
1219
- sha256: hash(content)
1220
- });
1221
- } catch {}
1560
+ content = readFileSync(join(boardsDir, file), "utf8");
1561
+ } catch {
1562
+ return;
1563
+ }
1564
+ const { error } = parseBoard(content);
1565
+ if (error) {
1566
+ if (!checkBoardsDir(root, boardsDir)) reportBad(file, content, error);
1567
+ return;
1568
+ }
1569
+ badBoards.delete(file);
1570
+ server.ws.send("sh:board", {
1571
+ name: file.replace(/\.json$/, ""),
1572
+ sha256: hash(content)
1573
+ });
1222
1574
  }, 120));
1223
1575
  });
1224
1576
  server.httpServer?.once("close", () => watcher.close());
@@ -1303,7 +1655,7 @@ function marverPlugin(ctx) {
1303
1655
  });
1304
1656
  return;
1305
1657
  }
1306
- const { shootFrame, shootBatch, resolveFrames } = await import("./shot-BAR8hmU9.mjs");
1658
+ const { shootFrame, shootBatch, resolveFrames } = await import("./shot-DOD8v6fJ.mjs");
1307
1659
  if (ways[0] === "frame") {
1308
1660
  if (typeof spec.frame !== "string") {
1309
1661
  write({
@@ -1420,4 +1772,4 @@ async function tailwind3Css(root) {
1420
1772
  return null;
1421
1773
  }
1422
1774
  //#endregion
1423
- export { update_exports as i, tailwind3Css as n, tailwind4Plugin as r, marverPlugin as t };
1775
+ 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-DOD8v6fJ.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-DOD8v6fJ.mjs";
3
+ import { ASK_MAX, bakeBatch } from "./bake-DQtnDB8-.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";