@marver-design/marver 0.24.0 → 0.25.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 (80) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +1 -1
  3. package/dist/anchor-DVV732zR.mjs +33 -0
  4. package/dist/anchor-check-BE5VVN6Q.mjs +135 -0
  5. package/dist/{bake-ZhXq-X9f.mjs → bake-D8byeRzB.mjs} +1 -1
  6. package/dist/{boards-BRLnoTC3.mjs → board-tree-DRioF94d.mjs} +21 -277
  7. package/dist/boards-CGg6piKF.mjs +342 -0
  8. package/dist/{boards-Dv-Ipd8G.mjs → boards-Csxj2WJn.mjs} +23 -9
  9. package/dist/{build-ckcinlWH.mjs → build-BHoWLvSj.mjs} +63 -37
  10. package/dist/cli.mjs +31 -17
  11. package/dist/{collab-mAiNZlDj.mjs → collab-gqNdScUE.mjs} +39 -9
  12. package/dist/{comments-DZyobpxG.mjs → comments-Zoch254k.mjs} +19 -1
  13. package/dist/{comments-Dx1hCVOT.mjs → comments-pTLlhjh4.mjs} +150 -20
  14. package/dist/{config-BUKprFAp.mjs → config-cKgZBRj0.mjs} +1 -1
  15. package/dist/{context-BncTXjLB.mjs → context-D2ugHqwO.mjs} +17 -123
  16. package/dist/{daemon-CQv73-jM.mjs → daemon-Cl8KXGW4.mjs} +146 -64
  17. package/dist/{dev-gv4NS6Fk.mjs → dev-DJdgow47.mjs} +23 -11
  18. package/dist/{events-B3LBn74P.mjs → events-DnK_AnrW.mjs} +13 -15
  19. package/dist/imports-WBSnnHLb.mjs +143 -0
  20. package/dist/{init--3Moc4J7.mjs → init-DO4DhUt_.mjs} +28 -6
  21. package/dist/link-C-qUIuKU.mjs +160 -0
  22. package/dist/{board-status-BZSzc9Hp.mjs → manifest-DnAte_fB.mjs} +537 -13
  23. package/dist/marks-DFuintmJ.mjs +50 -0
  24. package/dist/marks-koRsbHfe.mjs +397 -0
  25. package/dist/{marver-id-gate-B_idGdHm.mjs → marver-id-gate-DGANtVyC.mjs} +2 -2
  26. package/dist/perf-CCisg-ny.mjs +49 -0
  27. package/dist/perf-QJIWtTw1.mjs +68 -0
  28. package/dist/{plugin-Sa08E7wO.mjs → plugin-CTyhjwoJ.mjs} +424 -207
  29. package/dist/{poster-B2QPvKOq.mjs → poster-D0cbV7hi.mjs} +1 -1
  30. package/dist/{profile-CrZohD6g.mjs → profile-Do0nGkXO.mjs} +1 -1
  31. package/dist/{publish-bakes-BJR3huhu.mjs → publish-bakes--l8ot2eQ.mjs} +9 -9
  32. package/dist/{serve-z5qtj_wJ.mjs → serve-wv2QWdxB.mjs} +6 -6
  33. package/dist/{share-BD-wcDQq.mjs → share-ScamJcks.mjs} +1 -1
  34. package/dist/{shot-Cw96h5Kk.mjs → shot-CckrGW-J.mjs} +19 -11
  35. package/dist/{shot-Dh6fV1Lm.mjs → shot-jdO_B6Qw.mjs} +1 -1
  36. package/dist/{summary-C7CAypbB.mjs → summary-CrW88e3q.mjs} +1 -1
  37. package/dist/{sync-DoA1vf4u.mjs → sync-C3035OnJ.mjs} +18 -8
  38. package/dist/{work-CBUfsOOT.mjs → work-CpJn1gwY.mjs} +8 -4
  39. package/dist/{work-ayuL_9Kk.mjs → work-GE88wb_3.mjs} +4 -4
  40. package/docs/boards-and-folders.md +62 -21
  41. package/docs/live-jam.md +10 -5
  42. package/package.json +1 -1
  43. package/src/client/frame-host/bridge.js +2 -1
  44. package/src/client/frame-host/inspect.js +195 -84
  45. package/src/client/frame-host/main.tsx +7 -2
  46. package/src/client/frame-host/registry.ts +5 -5
  47. package/src/client/shell/App.tsx +66 -22
  48. package/src/client/shell/BoardList.tsx +54 -11
  49. package/src/client/shell/Comments.tsx +79 -34
  50. package/src/client/shell/ContextMenu.tsx +5 -2
  51. package/src/client/shell/LockedApp.tsx +45 -12
  52. package/src/client/shell/Play.tsx +35 -34
  53. package/src/client/shell/Toolbar.tsx +3 -1
  54. package/src/client/shell/canvas/Canvas.tsx +1 -1
  55. package/src/client/shell/canvas/FrameNode.tsx +10 -5
  56. package/src/client/shell/canvas/sleep.ts +4 -3
  57. package/src/client/shell/canvas/updates.ts +55 -0
  58. package/src/client/shell/comments-store.ts +48 -19
  59. package/src/client/shell/goto.ts +11 -14
  60. package/src/client/shell/hash.ts +12 -5
  61. package/src/client/shell/icons.tsx +1 -2
  62. package/src/client/shell/legacy-links.ts +67 -0
  63. package/src/client/shell/marks-ui.tsx +17 -19
  64. package/src/client/shell/pin-layout.ts +37 -0
  65. package/src/client/shell/store.ts +312 -92
  66. package/src/client/shell/styles.css +10 -8
  67. package/src/client/stage/main.tsx +19 -2
  68. package/src/shared/anchor.ts +57 -0
  69. package/src/shared/board-tree.ts +27 -10
  70. package/src/shared/events.ts +19 -10
  71. package/src/shared/marks.ts +17 -12
  72. package/templates/AGENTS-embedded.md +34 -15
  73. package/templates/AGENTS-studio.md +34 -15
  74. package/templates/instructions/boards.md +9 -5
  75. package/templates/instructions/iterate.md +20 -10
  76. package/templates/instructions/jam.md +13 -4
  77. package/templates/instructions/publish.md +2 -1
  78. package/templates/instructions/reference/deck-story.md +2 -2
  79. package/dist/link-vXjxMHTG.mjs +0 -132
  80. package/dist/manifest-cyG3kbhk.mjs +0 -528
@@ -1,13 +1,15 @@
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 { 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, a as checkRealDirs, 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 noteFileFor, c as setSceneTitle, n as isNoteFile, o as rendersDoc, r as layoutDocSource, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-cyG3kbhk.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, statSync, watch, writeFileSync } from "node:fs";
10
- import { basename, dirname, join, resolve, sep } from "node:path";
3
+ import { c as nodeExists, d as readMembership, f as readRegistry, h as hash, i as checkBoardsDir, l as parseBoard, m as withRegistryLock, o as isRegularFile, r as boardFields, s as listBoardFiles, t as AUTHOR_FIELDS, u as pinFrames } from "./boards-CGg6piKF.mjs";
4
+ import { A as settableStatuses, D as readStatusWord, E as readReason, O as readType, T as readCapability, _ as wireKids, a as buildTree, c as folderMap, g as validateWire, h as readTitle, k as resolveType, m as readDescription, n as BOARD_NAME, r as FOLDERS_FILE, t as ALL_SCENES, x as HAS_STATUS } from "./board-tree-DRioF94d.mjs";
5
+ import { c as setSceneTitle, d as annotateBoards, f as planNames, m as readContextFacts, n as isNoteFile, o as rendersDoc, p as planWithStage, r as layoutDocSource, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-DnAte_fB.mjs";
6
+ import { r as boardsChanged } from "./work-GE88wb_3.mjs";
7
+ import { n as localProfile, t as isConnected } from "./profile-Do0nGkXO.mjs";
8
+ import { n as loadConfig } from "./config-cKgZBRj0.mjs";
9
+ import { a as observe, n as docRevs, r as initMarks, s as recordChanged, t as docRev } from "./marks-koRsbHfe.mjs";
10
+ import { t as logReload } from "./perf-CCisg-ny.mjs";
11
+ import { closeSync, copyFileSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, watch, writeFileSync } from "node:fs";
12
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
11
13
  import { fileURLToPath } from "node:url";
12
14
  import { randomBytes } from "node:crypto";
13
15
  //#region src/shared/frames.ts
@@ -15,126 +17,129 @@ import { randomBytes } from "node:crypto";
15
17
  * only an app frame does (#4). Empty counts as not content-only: the warning still helps there. */
16
18
  const contentOnly = (frames) => frames.length > 0 && frames.every((f) => !!f.intent);
17
19
  //#endregion
18
- //#region src/server/marks.ts
20
+ //#region src/server/updates.ts
19
21
  /**
20
- * Sidebar marks, the dev server's half (spec 25): when each frame last changed, and which change
21
- * you have seen. Local only - `design/.local/` is never committed and never published.
22
+ * Calm updates, the dev server's half (spec 26 Part 2). Frame documents take no updates from Vite:
23
+ * Fast Refresh is off under design/ (dev.ts) and the frame host's registry accepts every update and
24
+ * ignores it. Marver decides which frames an edit touched, before Vite's update collapses into that
25
+ * shared registry, and the shell reloads exactly those - a few at a time, on screen first.
22
26
  *
23
- * Changed = the latest of the frame file's mtime, its sticky note's, and `changes.json` - an agent
24
- * naming the frame in `work done` (an edit to a shared kit it imports), or the frame first appearing
25
- * under a new id (a rename keeps the file's old mtime). A git pull moves mtimes too.
26
- * Seen = `seen.json`: { version, baseline, ids, frames: { id: the change stamp you saw } }. Its first
27
- * read sets the baseline to now, so everything already on the canvas that day counts as seen.
28
- * A "seen" is the stamp the page displayed, never a clock: an edit landing after you looked is new.
27
+ * Which frames, two answers united:
28
+ * - by path: the edited file mapped directly - a frame, or a wrapper the frame host puts around
29
+ * frames (providers -> every TSX frame, a _layout or _fixtures file -> every TSX frame below it),
30
+ * which also covers a wrapper just created, before Vite has a module for it;
31
+ * - by graph: the edit's modules walked up their importers to frame modules, exact for every loaded
32
+ * document, the wrapper mapping applied wherever the walk reaches a wrapper.
33
+ * A walk that passes a module accepting its own updates (an app component under src/**, a stylesheet)
34
+ * has been applied in place: the frames past it are touched (marked) but not reloaded.
35
+ *
36
+ * Every other `full-reload` Vite or Tailwind sends is dropped and becomes reloads of the frames it
37
+ * names (or every frame, when it names none) - the shell never reloads for a design edit. The one
38
+ * that passes is the dependency optimiser's: module URLs changed, every document must reload.
29
39
  */
30
- var marks_exports = /* @__PURE__ */ __exportAll({
31
- markSeen: () => markSeen,
32
- readMarks: () => readMarks,
33
- readSeen: () => readSeen,
34
- recordChanged: () => recordChanged
35
- });
36
- const dir = (root) => join(root, "design", ".local");
37
- const read = (file) => {
40
+ const safeReal = (p) => {
38
41
  try {
39
- return JSON.parse(readFileSync(file, "utf8"));
42
+ return realpathSync(p);
40
43
  } catch {
41
- return null;
44
+ return p;
42
45
  }
43
46
  };
44
- /** Writes stay inside the project: a symlinked design/ or .local is refused (as boards.ts refuses). */
45
- const write = (root, name, data) => {
46
- if (checkRealDirs(root, [[join(root, "design"), "design"], [dir(root), "design/.local"]])) return;
47
- mkdirSync(dir(root), { recursive: true });
48
- const file = join(dir(root), name), tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
49
- writeFileSync(tmp, JSON.stringify(data) + "\n");
50
- renameSync(tmp, file);
51
- };
52
- const stamps = (o) => o && typeof o === "object" ? Object.fromEntries(Object.entries(o).filter(([, v]) => typeof v === "number" && Number.isFinite(v))) : {};
53
- function readSeen(root) {
54
- const f = read(join(dir(root), "seen.json"));
55
- const strs = (v) => Array.isArray(v) ? v.filter((i) => typeof i === "string") : null;
56
- if (f && typeof f.baseline === "number") return {
57
- version: 1,
58
- baseline: f.baseline,
59
- ids: strs(f.ids),
60
- notes: strs(f.notes) ?? [],
61
- frames: stamps(f.frames)
47
+ /** The frames an edit reaches: `doc` must reload to show it; `touched` saw it applied in place. */
48
+ function framesFor(root, manifest, file, modules, skipFirst = false) {
49
+ const real = safeReal(root);
50
+ const byFile = new Map(manifest.frames.flatMap((f) => [[join(root, f.file), f], [join(real, f.file), f]]));
51
+ const doc = /* @__PURE__ */ new Set(), touched = /* @__PURE__ */ new Set();
52
+ const wrapper = (f) => /(^|[/\\])(providers\.(tsx|jsx)|_layout\.(tsx|jsx)|_fixtures\.(ts|tsx|js|jsx|json))$/.test(f);
53
+ const add = (ids, inPlace) => {
54
+ for (const id of ids) (inPlace ? touched : doc).add(id);
62
55
  };
63
- const fresh = {
64
- version: 1,
65
- baseline: Date.now(),
66
- ids: null,
67
- frames: {}
68
- };
69
- write(root, "seen.json", fresh);
70
- return fresh;
71
- }
72
- /** You saw these frames at these change stamps. Never lowers a stamp; drops ids the canvas no longer has. */
73
- function markSeen(root, seen, known) {
74
- const s = readSeen(root);
75
- for (const [id, at] of Object.entries(stamps(seen))) if (known.has(id)) s.frames[id] = Math.max(s.frames[id] ?? 0, at);
76
- for (const id of Object.keys(s.frames)) if (!known.has(id)) delete s.frames[id];
77
- write(root, "seen.json", s);
78
- }
79
- const readChanges = (root) => stamps(read(join(dir(root), "changes.json"))?.frames);
80
- /** These frames changed now, whatever their files say (`work done`, or a frame new under its id). */
81
- function recordChanged(root, ids, known) {
82
- const c = readChanges(root), now = Date.now();
83
- for (const id of ids) c[id] = now;
84
- if (known) {
85
- for (const id of Object.keys(c)) if (!known.has(id)) delete c[id];
86
- }
87
- write(root, "changes.json", {
88
- version: 1,
89
- frames: c
90
- });
91
- }
92
- const mtime = (abs) => {
93
- try {
94
- return statSync(abs).mtimeMs;
95
- } catch {
96
- return 0;
56
+ add(affectedFrameIds(file, root, manifest) ?? [], false);
57
+ const seen = /* @__PURE__ */ new Map();
58
+ const queue = [];
59
+ for (const m of modules) {
60
+ if (skipFirst) {
61
+ for (const up of m.importers) queue.push([up, false]);
62
+ continue;
63
+ }
64
+ queue.push([m, false]);
97
65
  }
98
- };
99
- function readMarks(root, manifest) {
100
- const all = manifest.frames.map((f) => f.id);
101
- const known = new Set(all);
102
- const seen = readSeen(root);
103
- const noteAt = {};
104
- for (const f of manifest.frames) noteAt[f.id] = mtime(noteFileFor(join(root, f.file)));
105
- const notes = all.filter((id) => noteAt[id] > 0);
106
- const had = seen.ids ? new Set(seen.ids) : null;
107
- const added = had ? all.filter((id) => !had.has(id)) : [];
108
- const noteGone = had ? (seen.notes ?? []).filter((id) => known.has(id) && !noteAt[id]) : [];
109
- const removed = had ? [...had].some((id) => !known.has(id)) : false;
110
- if (added.length || noteGone.length || removed) recordChanged(root, [...added, ...noteGone], known);
111
- if (!had || had.size !== all.length || added.length || noteGone.length || notes.length !== (seen.notes ?? []).length) {
112
- const frames = Object.fromEntries(Object.entries(seen.frames).filter(([id]) => known.has(id)));
113
- write(root, "seen.json", {
114
- ...seen,
115
- ids: all,
116
- notes,
117
- frames
118
- });
119
- seen.frames = frames;
120
- }
121
- const done = readChanges(root);
122
- const changed = {};
123
- for (const f of manifest.frames) changed[f.id] = Math.max(mtime(join(root, f.file)), noteAt[f.id], done[f.id] ?? 0);
124
- const boards = { "all-scenes": all };
125
- const boardsDir = join(root, "design", "boards");
126
- if (existsSync(boardsDir) && !checkBoardsDir(root, boardsDir)) for (const b of listBoardFiles(boardsDir).boards) {
127
- const j = b.json;
128
- if (!j || b.name === "all-scenes") continue;
129
- boards[b.name] = j.auto === true ? all : Array.isArray(j.nodes) ? j.nodes.map((n) => n?.frame).filter((f) => typeof f === "string" && known.has(f)) : [];
66
+ while (queue.length) {
67
+ const [m, inPlace] = queue.shift();
68
+ const had = seen.get(m);
69
+ if (had === false || had === inPlace) continue;
70
+ seen.set(m, inPlace);
71
+ const f = m.file ? byFile.get(m.file) : void 0;
72
+ if (f) (inPlace ? touched : doc).add(f.id);
73
+ if (m.file && wrapper(m.file)) add(affectedFrameIds(m.file, root, manifest) ?? [], inPlace);
74
+ const accepts = m.isSelfAccepting === true;
75
+ for (const up of m.importers) queue.push([up, inPlace || accepts]);
130
76
  }
77
+ for (const id of doc) touched.delete(id);
78
+ return {
79
+ file,
80
+ doc: [...doc],
81
+ touched: [...touched]
82
+ };
83
+ }
84
+ /** The hook that runs last on every hot update of the client environment. */
85
+ function updatesPlugin(root, manifest, hooks, landed) {
131
86
  return {
132
- changed,
133
- seen: seen.frames,
134
- baseline: seen.baseline,
135
- boards
87
+ name: "marver:updates",
88
+ hotUpdate: {
89
+ order: "post",
90
+ handler(opts) {
91
+ landed(opts.file);
92
+ if (this.environment.name !== "client") return;
93
+ const h = hooks();
94
+ if (!h) return;
95
+ const t = framesFor(root, manifest(), opts.file, opts.modules);
96
+ if (t.doc.length || t.touched.length) h.onFrames(t, "update");
97
+ }
98
+ }
136
99
  };
137
100
  }
101
+ /** Wraps the client's hot channel: the reload guard and refused refreshes. */
102
+ function guardUpdates(server, root, manifest, hooks) {
103
+ const env = server.environments.client;
104
+ const wrap = (ch) => {
105
+ const send = ch.send.bind(ch);
106
+ ch.send = (...a) => {
107
+ const p = a[0];
108
+ if (typeof p === "object" && p?.type === "full-reload") {
109
+ const passed = p.path === "*" && !p.triggeredBy;
110
+ hooks.onReload({
111
+ triggeredBy: p.triggeredBy,
112
+ path: p.path
113
+ }, passed);
114
+ if (!passed) {
115
+ const by = p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
116
+ const mods = by ? env.moduleGraph.getModulesByFile(by) : void 0;
117
+ const all = manifest().frames.map((f) => f.id);
118
+ const t = by ? framesFor(root, manifest(), by, mods ?? []) : {
119
+ file: "",
120
+ doc: all,
121
+ touched: [],
122
+ unattributed: true
123
+ };
124
+ if (t.doc.length || t.touched.length) hooks.onFrames(t, "reload");
125
+ return;
126
+ }
127
+ }
128
+ send(...a);
129
+ };
130
+ };
131
+ wrap(env.hot);
132
+ if (server.ws !== env.hot) wrap(server.ws);
133
+ const refused = /* @__PURE__ */ new Map();
134
+ env.hot.on("vite:invalidate", (payload) => {
135
+ const mod = payload?.path ? env.moduleGraph.urlToModuleMap.get(payload.path) : void 0;
136
+ if (!mod?.file) return;
137
+ if (refused.get(mod.url) === mod.lastHMRTimestamp) return;
138
+ refused.set(mod.url, mod.lastHMRTimestamp);
139
+ const t = framesFor(root, manifest(), mod.file, [mod], true);
140
+ if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate");
141
+ });
142
+ }
138
143
  //#endregion
139
144
  //#region src/server/sizes.ts
140
145
  /**
@@ -358,6 +363,15 @@ function contained(target, base) {
358
363
  }
359
364
  }
360
365
  function apiMiddleware(root, opts = {}) {
366
+ const devManifest = () => {
367
+ if (opts.manifest) return opts.manifest();
368
+ try {
369
+ return JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
370
+ } catch {
371
+ return scanFrames(root);
372
+ }
373
+ };
374
+ const devFrames = () => devManifest().frames;
361
375
  const boardsDir = join(root, "design", "boards");
362
376
  const foldersPath = join(boardsDir, FOLDERS_FILE);
363
377
  const boardPath = (name) => {
@@ -580,6 +594,30 @@ function apiMiddleware(root, opts = {}) {
580
594
  return null;
581
595
  }
582
596
  };
597
+ if (path === "perf/reload" && req.method === "POST") {
598
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
599
+ const raw = await readBody(req);
600
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
601
+ let b;
602
+ try {
603
+ b = JSON.parse(raw);
604
+ } catch {
605
+ return json(res, 400, { error: "malformed JSON" });
606
+ }
607
+ const str = (v) => typeof v === "string" ? v.slice(0, 200) : void 0;
608
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
609
+ if (!str(b?.kind)) return json(res, 400, { error: "kind required" });
610
+ (await import("./perf-CCisg-ny.mjs").then((n) => n.n)).logReload(root, {
611
+ kind: str(b.kind),
612
+ tab: str(b.tab),
613
+ node: str(b.node),
614
+ frame: str(b.frame),
615
+ cause: str(b.cause),
616
+ shown: str(b.shown),
617
+ ms: num(b.ms)
618
+ });
619
+ return json(res, 200, { ok: true });
620
+ }
583
621
  if (path === "sizes" && req.method === "GET") {
584
622
  const frames = readManifestFrames();
585
623
  if (!frames) return json(res, 200, {
@@ -640,6 +678,30 @@ function apiMiddleware(root, opts = {}) {
640
678
  sha256: reg.sha256
641
679
  });
642
680
  }
681
+ if (path === "membership" && req.method === "GET") {
682
+ const de = dirError();
683
+ if (de) return json(res, 422, { error: de });
684
+ return json(res, 200, readMembership(root, scanFrames(root).frames.map((f) => f.id)));
685
+ }
686
+ if (path === "boards/pin" && req.method === "POST") {
687
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
688
+ const raw = await readBody(req);
689
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
690
+ let parsed;
691
+ try {
692
+ parsed = JSON.parse(raw);
693
+ } catch {
694
+ return json(res, 400, { error: "malformed JSON" });
695
+ }
696
+ const live = scanFrames(root).frames.map((f) => f.id);
697
+ const frames = Array.isArray(parsed?.frames) ? parsed.frames.filter((f) => typeof f === "string" && live.includes(f)) : [];
698
+ if (!validName(parsed?.board) || !frames.length) return json(res, 400, { error: "a board and frames on this canvas" });
699
+ try {
700
+ return json(res, 200, pinFrames(root, parsed.board, frames, live));
701
+ } catch (err) {
702
+ return json(res, 409, { error: err.message });
703
+ }
704
+ }
643
705
  if (path === "boards/rename" && req.method === "POST") {
644
706
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
645
707
  const raw = await readBody(req);
@@ -909,6 +971,7 @@ function apiMiddleware(root, opts = {}) {
909
971
  });
910
972
  }
911
973
  if (req.method === "PUT") {
974
+ if (boardMatch[1] === "all-scenes") return json(res, 400, { error: `"${ALL_SCENES}" is a reserved name` });
912
975
  const raw = await readBody(req);
913
976
  if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
914
977
  let body;
@@ -946,7 +1009,7 @@ function apiMiddleware(root, opts = {}) {
946
1009
  }
947
1010
  }
948
1011
  if (path === "shot" && req.method === "GET") {
949
- const { readDevInfo } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
1012
+ const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
950
1013
  const token = readDevInfo(root)?.token;
951
1014
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
952
1015
  const frameId = url.searchParams.get("frame") ?? "";
@@ -962,7 +1025,7 @@ function apiMiddleware(root, opts = {}) {
962
1025
  };
963
1026
  const asPng = url.searchParams.get("format") === "png";
964
1027
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
965
- const { shootFrame } = await import("./shot-Cw96h5Kk.mjs");
1028
+ const { shootFrame } = await import("./shot-CckrGW-J.mjs");
966
1029
  const r = await shootFrame({
967
1030
  root,
968
1031
  viewports: opts.viewports ?? {},
@@ -995,7 +1058,7 @@ function apiMiddleware(root, opts = {}) {
995
1058
  return res.end(png);
996
1059
  }
997
1060
  if (path === "shots" && req.method === "POST") {
998
- const { readDevInfo } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
1061
+ const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
999
1062
  const token = readDevInfo(root)?.token;
1000
1063
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
1001
1064
  const raw = await readBody(req);
@@ -1012,7 +1075,7 @@ function apiMiddleware(root, opts = {}) {
1012
1075
  if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
1013
1076
  const scale = body.scale === void 0 ? void 0 : body.scale;
1014
1077
  if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
1015
- const { resolveFrames, shootBatch } = await import("./shot-Cw96h5Kk.mjs");
1078
+ const { resolveFrames, shootBatch } = await import("./shot-CckrGW-J.mjs");
1016
1079
  const sel = resolveFrames(root, body);
1017
1080
  if (!sel.ok) return json(res, sel.status, { error: sel.error });
1018
1081
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
@@ -1029,6 +1092,40 @@ function apiMiddleware(root, opts = {}) {
1029
1092
  return json(res, 503, { error: err.message });
1030
1093
  }
1031
1094
  }
1095
+ if (path === "anchor" && req.method === "POST") {
1096
+ const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
1097
+ const token = readDevInfo(root)?.token;
1098
+ if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
1099
+ const raw = await readBody(req);
1100
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
1101
+ let b;
1102
+ try {
1103
+ b = JSON.parse(raw);
1104
+ } catch {
1105
+ return json(res, 400, { error: "malformed JSON" });
1106
+ }
1107
+ const { readTarget } = await import("./anchor-DVV732zR.mjs");
1108
+ const target = readTarget(b ?? {});
1109
+ if (typeof target === "string") return json(res, 400, { error: target });
1110
+ const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
1111
+ const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
1112
+ const { checkAnchor, CheckInputError } = await import("./anchor-check-BE5VVN6Q.mjs");
1113
+ try {
1114
+ return json(res, 200, await checkAnchor({
1115
+ root,
1116
+ viewports: opts.viewports ?? {},
1117
+ origin,
1118
+ frameId: String(b.frame ?? ""),
1119
+ target,
1120
+ others,
1121
+ viewport: typeof b.viewport === "string" ? b.viewport : void 0,
1122
+ theme: typeof b.theme === "string" ? b.theme : void 0
1123
+ }));
1124
+ } catch (err) {
1125
+ if (err instanceof CheckInputError) return json(res, 400, { error: err.message });
1126
+ throw err;
1127
+ }
1128
+ }
1032
1129
  if (path === "bakes" && req.method === "POST") {
1033
1130
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1034
1131
  const raw = await readBody(req);
@@ -1040,13 +1137,14 @@ function apiMiddleware(root, opts = {}) {
1040
1137
  return json(res, 400, { error: "malformed JSON" });
1041
1138
  }
1042
1139
  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" });
1043
- const { bakeBatch, ASK_MAX } = await import("./bake-ZhXq-X9f.mjs");
1140
+ const { bakeBatch, ASK_MAX } = await import("./bake-D8byeRzB.mjs");
1044
1141
  let manifest = {};
1045
1142
  try {
1046
1143
  manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
1047
1144
  } catch {}
1048
1145
  const frames = new Map((manifest.frames ?? []).map((f) => [f.id, f]));
1049
1146
  const asks = [];
1147
+ const docs = [];
1050
1148
  for (const a of body.asks) {
1051
1149
  const frame = typeof a?.frame === "string" ? a.frame : "";
1052
1150
  const theme = typeof a?.theme === "string" && /^[a-z0-9-]{1,32}$/i.test(a.theme) ? a.theme : "";
@@ -1058,34 +1156,52 @@ function apiMiddleware(root, opts = {}) {
1058
1156
  w,
1059
1157
  h
1060
1158
  });
1159
+ docs.push(typeof a?.doc === "string" ? a.doc : void 0);
1061
1160
  }
1161
+ const { docRev } = await import("./marks-koRsbHfe.mjs").then((n) => n.i);
1162
+ const all = devManifest().frames;
1163
+ const pending = opts.settled ? !opts.settled() : false;
1164
+ const behind = docs.map((d, i) => d !== void 0 && (pending || d !== docRev(root, all, asks[i].frame)));
1062
1165
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
1063
1166
  const { ROUTE } = await import("./cli.mjs").then((n) => n.t);
1064
1167
  const gen = opts.bakeGen?.() ?? 0;
1168
+ const baked = await bakeBatch({
1169
+ root,
1170
+ gen,
1171
+ asks: asks.filter((_, i) => !behind[i]),
1172
+ live: () => opts.bakeGen?.() ?? 0,
1173
+ log: (a) => {
1174
+ if (a.ok) console.log(` bake: ${a.frame} ${a.theme} ${a.w}x${a.h} - ${a.targets.length} effects, ${a.rejected} stay live, ${a.ms} ms`);
1175
+ else console.log(` bake: ${a.frame} ${a.theme} ${a.w}x${a.h} - stays live: ${a.error}`);
1176
+ },
1177
+ urlFor: (ask) => {
1178
+ const f = frames.get(ask.frame);
1179
+ return f.kind === "html" ? `${origin}/${f.file}?theme=${encodeURIComponent(ask.theme)}` : `${origin}${ROUTE}/frame/?id=${encodeURIComponent(ask.frame)}&theme=${encodeURIComponent(ask.theme)}`;
1180
+ },
1181
+ urlBase: `${ROUTE}/bakes`
1182
+ });
1183
+ const after = docs.map((d, i) => d !== void 0 && (!!opts.settled && !opts.settled() || d !== docRev(root, devManifest().frames, asks[i].frame)));
1184
+ let k = 0;
1065
1185
  return json(res, 200, {
1066
1186
  gen,
1067
- answers: await bakeBatch({
1068
- root,
1069
- gen,
1070
- asks,
1071
- live: () => opts.bakeGen?.() ?? 0,
1072
- log: (a) => {
1073
- if (a.ok) console.log(` bake: ${a.frame} ${a.theme} ${a.w}x${a.h} - ${a.targets.length} effects, ${a.rejected} stay live, ${a.ms} ms`);
1074
- else console.log(` bake: ${a.frame} ${a.theme} ${a.w}x${a.h} - stays live: ${a.error}`);
1075
- },
1076
- urlFor: (ask) => {
1077
- const f = frames.get(ask.frame);
1078
- return f.kind === "html" ? `${origin}/${f.file}?theme=${encodeURIComponent(ask.theme)}` : `${origin}${ROUTE}/frame/?id=${encodeURIComponent(ask.frame)}&theme=${encodeURIComponent(ask.theme)}`;
1079
- },
1080
- urlBase: `${ROUTE}/bakes`
1187
+ answers: asks.map((a, i) => {
1188
+ const r = behind[i] ? null : baked[k++];
1189
+ return {
1190
+ ...r && !after[i] ? r : {
1191
+ ...a,
1192
+ ok: false,
1193
+ error: "the document is behind its frame"
1194
+ },
1195
+ ...docs[i] ? { doc: docs[i] } : {}
1196
+ };
1081
1197
  })
1082
1198
  });
1083
1199
  }
1084
1200
  if (path === "poster" && req.method === "GET") {
1085
1201
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1086
1202
  const src = url.searchParams.get("src") ?? "";
1087
- const { ensurePoster, isLocalClip } = await import("./poster-B2QPvKOq.mjs");
1088
- const { isLocalAssetRef } = await import("./build-ckcinlWH.mjs");
1203
+ const { ensurePoster, isLocalClip } = await import("./poster-D0cbV7hi.mjs");
1204
+ const { isLocalAssetRef } = await import("./build-BHoWLvSj.mjs");
1089
1205
  if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
1090
1206
  const r = await ensurePoster(join(root, "design", "assets"), src);
1091
1207
  if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
@@ -1112,7 +1228,7 @@ function apiMiddleware(root, opts = {}) {
1112
1228
  }
1113
1229
  const dir = join(root, "design", ".local");
1114
1230
  mkdirSync(dir, { recursive: true });
1115
- const { validAvatar } = await import("./collab-mAiNZlDj.mjs");
1231
+ const { validAvatar } = await import("./collab-gqNdScUE.mjs");
1116
1232
  let cur = {};
1117
1233
  try {
1118
1234
  cur = JSON.parse(readFileSync(join(dir, "profile.json"), "utf8"));
@@ -1128,13 +1244,8 @@ function apiMiddleware(root, opts = {}) {
1128
1244
  }
1129
1245
  if (path === "marks" || path === "marks/seen") {
1130
1246
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1131
- const { readMarks, markSeen } = await Promise.resolve().then(() => marks_exports);
1132
- let manifest;
1133
- try {
1134
- manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
1135
- } catch {
1136
- manifest = scanFrames(root);
1137
- }
1247
+ const { readMarks, markSeen } = await import("./marks-koRsbHfe.mjs").then((n) => n.i);
1248
+ const manifest = devManifest();
1138
1249
  if (path === "marks" && req.method === "GET") return json(res, 200, readMarks(root, manifest));
1139
1250
  if (path === "marks/seen" && req.method === "POST") {
1140
1251
  const raw = await readBody(req);
@@ -1145,22 +1256,22 @@ function apiMiddleware(root, opts = {}) {
1145
1256
  } catch {
1146
1257
  return json(res, 400, { error: "malformed JSON" });
1147
1258
  }
1148
- if (!b?.frames || typeof b.frames !== "object" || Array.isArray(b.frames)) return json(res, 400, { error: "frames: { id: stamp } required" });
1149
- markSeen(root, b.frames, new Set(manifest.frames.map((f) => f.id)));
1259
+ if (!b?.frames || typeof b.frames !== "object" || Array.isArray(b.frames)) return json(res, 400, { error: "frames: { id: revision } required" });
1260
+ if (!markSeen(root, manifest.frames, b.epoch, b.frames)) return json(res, 409, { error: "the marks started over - read them again" });
1150
1261
  opts.notify?.("sh:marks");
1151
1262
  return json(res, 200, { ok: true });
1152
1263
  }
1153
1264
  return json(res, 405, { error: "method not allowed" });
1154
1265
  }
1155
1266
  if (path === "work") {
1156
- const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
1267
+ const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
1157
1268
  const tokenOk = () => {
1158
1269
  const t = readDevInfo(root)?.token;
1159
1270
  return !!t && req.headers["x-mv-work"] === t;
1160
1271
  };
1161
1272
  if (req.method === "GET") {
1162
1273
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
1163
- const { boardsShowing, activityClock } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
1274
+ const { boardsShowing, activityClock } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
1164
1275
  const frames = workActivity.active();
1165
1276
  return json(res, 200, {
1166
1277
  frames,
@@ -1183,7 +1294,7 @@ function apiMiddleware(root, opts = {}) {
1183
1294
  if (!on && b.all === true) {
1184
1295
  const done = workActivity.active().filter((f) => workActivity.has(f, "cli"));
1185
1296
  if (done.length) {
1186
- (await Promise.resolve().then(() => marks_exports)).recordChanged(root, done);
1297
+ (await import("./marks-koRsbHfe.mjs").then((n) => n.i)).recordChanged(root, devFrames(), done, { doc: false });
1187
1298
  opts.notify?.("sh:marks");
1188
1299
  }
1189
1300
  workActivity.clearAll("cli");
@@ -1193,7 +1304,7 @@ function apiMiddleware(root, opts = {}) {
1193
1304
  const ttl = Math.min(Math.max(Number(b.ttlMs) || WORK_TTL_DEFAULT, 1e4), WORK_TTL_MAX);
1194
1305
  for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
1195
1306
  if (!on) {
1196
- (await Promise.resolve().then(() => marks_exports)).recordChanged(root, frames);
1307
+ (await import("./marks-koRsbHfe.mjs").then((n) => n.i)).recordChanged(root, devFrames(), frames, { doc: false });
1197
1308
  opts.notify?.("sh:marks");
1198
1309
  return json(res, 200, { frames: workActivity.active() });
1199
1310
  }
@@ -1228,7 +1339,7 @@ function apiMiddleware(root, opts = {}) {
1228
1339
  }
1229
1340
  }
1230
1341
  if (path === "boards.rights" && req.method === "GET") {
1231
- const { listBoards } = await import("./comments-DZyobpxG.mjs").then((n) => n.n);
1342
+ const { listBoards } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
1232
1343
  return json(res, 200, {
1233
1344
  local: true,
1234
1345
  stored: listBoards(join(root, "design", "comments"))
@@ -1236,7 +1347,7 @@ function apiMiddleware(root, opts = {}) {
1236
1347
  }
1237
1348
  const cm = /^comments\/([a-z0-9][a-z0-9-]*)$/.exec(path);
1238
1349
  if (cm) {
1239
- const { appendEvents, readLog } = await import("./comments-DZyobpxG.mjs").then((n) => n.n);
1350
+ const { appendEvents, readLog } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
1240
1351
  const dir = join(root, "design", "comments");
1241
1352
  if (req.method === "GET") return json(res, 200, { events: readLog(dir, cm[1]) });
1242
1353
  if (req.method === "POST") {
@@ -1272,7 +1383,7 @@ function apiMiddleware(root, opts = {}) {
1272
1383
  }
1273
1384
  }
1274
1385
  if (path === "sync" && req.method === "POST") {
1275
- const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
1386
+ const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
1276
1387
  const collab = loadCollab(root);
1277
1388
  if (!collab) return json(res, 200, { connected: false });
1278
1389
  try {
@@ -1301,7 +1412,7 @@ function backgroundPush(root) {
1301
1412
  pushTimer = setTimeout(async () => {
1302
1413
  pushTimer = null;
1303
1414
  try {
1304
- const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
1415
+ const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
1305
1416
  const collab = loadCollab(root);
1306
1417
  if (collab) await syncOnce(root, collab);
1307
1418
  } catch {}
@@ -1309,12 +1420,7 @@ function backgroundPush(root) {
1309
1420
  }
1310
1421
  //#endregion
1311
1422
  //#region src/server/routes.ts
1312
- /**
1313
- * Serves the package's own pages. transformIndexHtml does not map URLs - we do (spec §3).
1314
- * Entry html files carry an {{ENTRY}} placeholder replaced with an /@fs/ absolute path,
1315
- * because a relative ./main.tsx would resolve against the URL, not the package dir.
1316
- */
1317
- function routesMiddleware(server, clientDir) {
1423
+ function routesMiddleware(server, clientDir, stamps) {
1318
1424
  const page = (dir) => {
1319
1425
  const html = readFileSync(join(clientDir, dir, "index.html"), "utf8");
1320
1426
  const entry = "/@fs/" + join(clientDir, dir, "main.tsx").split("\\").join("/");
@@ -1326,7 +1432,8 @@ function routesMiddleware(server, clientDir) {
1326
1432
  webmanifest: "application/manifest+json"
1327
1433
  };
1328
1434
  return async (req, res, next) => {
1329
- const path = new URL(req.url ?? "/", "http://x").pathname;
1435
+ const url = new URL(req.url ?? "/", "http://x");
1436
+ const path = url.pathname;
1330
1437
  let dir = null;
1331
1438
  if (path === "/" || path === "/index.html") dir = "shell";
1332
1439
  else if (path === `/__mv/frame/` || path === `/__mv/frame/index.html`) dir = "frame-host";
@@ -1366,7 +1473,9 @@ function routesMiddleware(server, clientDir) {
1366
1473
  }
1367
1474
  if (!dir) return next();
1368
1475
  try {
1369
- const html = await server.transformIndexHtml(req.url ?? "/", page(dir));
1476
+ const stamp = dir === "frame-host" ? stamps?.doc(url.searchParams.get("id") ?? "") : dir === "stage" ? JSON.stringify(stamps?.docs() ?? null) : void 0;
1477
+ let html = await server.transformIndexHtml(req.url ?? "/", page(dir));
1478
+ if (stamp) html = html.replace("<head>", `<head><meta name="mv-doc" content="${stamp.replace(/[&"<>]/g, (c) => `&#${c.charCodeAt(0)};`)}">`);
1370
1479
  res.setHeader("content-type", "text/html");
1371
1480
  res.setHeader("cache-control", "no-store");
1372
1481
  res.end(html);
@@ -1468,11 +1577,102 @@ function marverPlugin(ctx) {
1468
1577
  if (!devServer || !pendingInv.size) return;
1469
1578
  const frameIds = [...pendingInv];
1470
1579
  pendingInv.clear();
1580
+ const docs = docRevs(root, manifest.frames);
1471
1581
  devServer.ws.send("sh:frame-invalidated", {
1472
1582
  frameIds,
1473
- revision: `${bootId}:${++invRev}`
1583
+ revision: `${bootId}:${++invRev}`,
1584
+ epoch: docs?.epoch,
1585
+ docs: docs ? Object.fromEntries(frameIds.map((id) => [id, docs.doc[id] ?? 0])) : void 0
1474
1586
  });
1475
1587
  }, 120);
1588
+ const inFlight = /* @__PURE__ */ new Map();
1589
+ const late = /* @__PURE__ */ new Map();
1590
+ const envs = () => Object.keys(devServer?.environments ?? { client: 1 }).length;
1591
+ const waiting = [];
1592
+ const settled = () => inFlight.size === 0;
1593
+ const whenSettled = (fn) => {
1594
+ if (settled()) fn();
1595
+ else waiting.push(fn);
1596
+ };
1597
+ const drain = () => {
1598
+ if (settled()) for (const fn of waiting.splice(0)) try {
1599
+ fn();
1600
+ } catch (e) {
1601
+ console.warn(`[marver] ${e.message}`);
1602
+ }
1603
+ };
1604
+ const done = (file) => {
1605
+ const f = inFlight.get(file);
1606
+ if (!f) return;
1607
+ if (--f.events > 0) return;
1608
+ clearTimeout(f.timer);
1609
+ inFlight.delete(file);
1610
+ drain();
1611
+ };
1612
+ const flying = (file) => {
1613
+ const f = inFlight.get(file) ?? {
1614
+ events: 0,
1615
+ hits: 0,
1616
+ timer: void 0
1617
+ };
1618
+ f.events++;
1619
+ clearTimeout(f.timer);
1620
+ f.timer = setTimeout(() => {
1621
+ for (const env of Object.values(devServer?.environments ?? {})) env.moduleGraph.invalidateAll();
1622
+ late.set(file, (late.get(file) ?? 0) + f.events * envs() - f.hits);
1623
+ inFlight.delete(file);
1624
+ drain();
1625
+ }, 1e4);
1626
+ inFlight.set(file, f);
1627
+ };
1628
+ const landed = (file) => {
1629
+ const owed = late.get(file);
1630
+ if (owed) {
1631
+ if (owed > 1) late.set(file, owed - 1);
1632
+ else late.delete(file);
1633
+ return;
1634
+ }
1635
+ const f = inFlight.get(file);
1636
+ if (!f) return;
1637
+ if (++f.hits < envs()) return;
1638
+ f.hits = 0;
1639
+ setTimeout(() => done(file), 0);
1640
+ };
1641
+ const observeMarks = () => observed(observe(root, manifest.frames));
1642
+ const observeLater = () => whenSettled(() => {
1643
+ if (observeMarks()) devServer?.ws.send("sh:marks", {});
1644
+ });
1645
+ const hooks = {
1646
+ onFrames: (t, cause) => {
1647
+ setTimeout(() => whenSettled(() => record(t, cause)), 0);
1648
+ },
1649
+ onReload(p, passed) {
1650
+ logReload(root, {
1651
+ kind: "full-reload",
1652
+ passed,
1653
+ triggeredBy: p.triggeredBy ?? null,
1654
+ path: p.path ?? null
1655
+ });
1656
+ }
1657
+ };
1658
+ function record(t, cause) {
1659
+ const seen = observe(root, manifest.frames, t.file ? { file: t.file } : {});
1660
+ const doc = t.unattributed ? [] : t.doc.filter((id) => !seen.doc.includes(id));
1661
+ const touched = t.touched.filter((id) => !seen.doc.includes(id) && !seen.note.includes(id) && !doc.includes(id));
1662
+ if (doc.length) recordChanged(root, manifest.frames, doc, { doc: true });
1663
+ if (touched.length) recordChanged(root, manifest.frames, touched, { doc: false });
1664
+ const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
1665
+ for (const id of reload) pendingInv.add(id);
1666
+ flushInv();
1667
+ if (reload.length || touched.length || seen.note.length) devServer?.ws.send("sh:marks", {});
1668
+ logReload(root, {
1669
+ kind: "update",
1670
+ cause,
1671
+ file: t.file ? relative(root, t.file).split(sep).join("/") : null,
1672
+ reload,
1673
+ inPlace: t.touched
1674
+ });
1675
+ }
1476
1676
  /** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
1477
1677
  * Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
1478
1678
  * manifest; the config carries only whether a theme exists. */
@@ -1485,8 +1685,11 @@ function marverPlugin(ctx) {
1485
1685
  if (ctx.detectedThemeCss && existsSync(join(root, ctx.detectedThemeCss))) return join(root, ctx.detectedThemeCss);
1486
1686
  return null;
1487
1687
  };
1488
- return {
1688
+ return [{
1489
1689
  name: "marver",
1690
+ watchChange(id) {
1691
+ if (devServer) flying(id);
1692
+ },
1490
1693
  enforce: "pre",
1491
1694
  resolveId(id) {
1492
1695
  if (id === VIRTUAL_THEME) return themeFile() ?? "\0virtual:sh-theme.css";
@@ -1525,43 +1728,40 @@ function marverPlugin(ctx) {
1525
1728
  transformIndexHtml: {
1526
1729
  order: "pre",
1527
1730
  handler(html, hctx) {
1528
- if (!(hctx.originalUrl ?? hctx.path ?? "").split("?")[0].startsWith("/design/")) return;
1731
+ const path = (hctx.originalUrl ?? hctx.path ?? "").split("?")[0];
1732
+ if (!path.startsWith("/design/")) return;
1529
1733
  const bridge = "/@fs/" + join(clientDir, "frame-host", "bridge.js").split("\\").join("/") + "?html=1";
1734
+ const frame = manifest.frames.find((f) => "/" + f.file === path);
1735
+ const stamp = frame ? docRev(root, manifest.frames, frame.id) : "";
1530
1736
  return {
1531
1737
  html,
1532
- tags: [{
1533
- tag: "script",
1534
- attrs: { type: "module" },
1535
- children: `import '${VIRTUAL_THEME}'`,
1536
- injectTo: "head-prepend"
1537
- }, {
1538
- tag: "script",
1539
- attrs: {
1540
- type: "module",
1541
- src: bridge
1738
+ tags: [
1739
+ {
1740
+ tag: "script",
1741
+ attrs: { type: "module" },
1742
+ children: `import '${VIRTUAL_THEME}'`,
1743
+ injectTo: "head-prepend"
1744
+ },
1745
+ {
1746
+ tag: "script",
1747
+ attrs: {
1748
+ type: "module",
1749
+ src: bridge
1750
+ },
1751
+ injectTo: "head-prepend"
1542
1752
  },
1543
- injectTo: "head-prepend"
1544
- }]
1753
+ ...stamp ? [{
1754
+ tag: "meta",
1755
+ attrs: {
1756
+ name: "mv-doc",
1757
+ content: stamp
1758
+ },
1759
+ injectTo: "head-prepend"
1760
+ }] : []
1761
+ ]
1545
1762
  };
1546
1763
  }
1547
1764
  },
1548
- /**
1549
- * Frame add/unlink is OUR event (sh:manifest → shell appends/flags nodes); Vite's default for
1550
- * an out-of-graph file is a full-reload broadcast to every client, shell included. Suppress it.
1551
- * Edits to loaded frames keep normal HMR (modules present + file exists → pass through).
1552
- */
1553
- handleHotUpdate(hctx) {
1554
- const affected = affectedFrameIds(hctx.file, root, manifest);
1555
- if (affected === null) {
1556
- if ([join(root, "design", "scenes"), join(root, "design", "components")].some((w) => hctx.file.startsWith(w)) && !existsSync(hctx.file)) return [];
1557
- return;
1558
- }
1559
- if (affected.length) {
1560
- for (const id of affected) pendingInv.add(id);
1561
- flushInv();
1562
- }
1563
- return [];
1564
- },
1565
1765
  configureServer(server) {
1566
1766
  let bakeGen = Date.now();
1567
1767
  server.middlewares.use((req, res, next) => {
@@ -1591,19 +1791,36 @@ function marverPlugin(ctx) {
1591
1791
  if (!a || typeof a === "string") return null;
1592
1792
  return `http://${a.family === "IPv6" ? a.address === "::" ? "[::1]" : `[${a.address}]` : a.address === "0.0.0.0" ? "127.0.0.1" : a.address}:${a.port}`;
1593
1793
  };
1794
+ initMarks(root, manifest.frames);
1594
1795
  server.middlewares.use(apiMiddleware(root, {
1595
1796
  viewports: config.viewports,
1596
1797
  origin: listeningOrigin,
1597
1798
  bakeGen: () => bakeGen,
1598
- notify: (event) => server.ws.send(event, {})
1799
+ notify: (event) => server.ws.send(event, {}),
1800
+ manifest: () => manifest,
1801
+ settled
1802
+ }));
1803
+ server.middlewares.use(routesMiddleware(server, clientDir, {
1804
+ doc: (id) => docRev(root, manifest.frames, id),
1805
+ docs: () => docRevs(root, manifest.frames)
1599
1806
  }));
1600
- server.middlewares.use(routesMiddleware(server, clientDir));
1601
1807
  devServer = server;
1808
+ guardUpdates(server, root, () => manifest, hooks);
1602
1809
  let framesKey = JSON.stringify(manifest.frames);
1603
1810
  let scenesKey = JSON.stringify(manifest.scenes);
1811
+ let unplacedKey = "";
1812
+ const sayUnplaced = () => {
1813
+ const { unplaced } = readMembership(root, manifest.frames.map((f) => f.id));
1814
+ const key = unplaced.join(",");
1815
+ if (key && key !== unplacedKey) console.log(`[${NAME}] not on a board (${unplaced.length}): ${unplaced.join(", ")} - every frame goes on the board it belongs to: npx ${NAME} boards pin <board> <scene/frame ...>`);
1816
+ unplacedKey = key;
1817
+ };
1818
+ sayUnplaced();
1604
1819
  const regen = debounce(() => {
1605
1820
  manifest = scanFrames(root, projectInfo());
1821
+ sayUnplaced();
1606
1822
  const changed = writeManifest(root, manifest);
1823
+ observeLater();
1607
1824
  const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
1608
1825
  if (changed && key !== framesKey) server.ws.send("sh:manifest", manifest);
1609
1826
  else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
@@ -1641,7 +1858,7 @@ function marverPlugin(ctx) {
1641
1858
  };
1642
1859
  const prune = () => setTimeout(async () => {
1643
1860
  try {
1644
- (await import("./bake-ZhXq-X9f.mjs")).pruneBakes(root, bakeGen);
1861
+ (await import("./bake-D8byeRzB.mjs")).pruneBakes(root, bakeGen);
1645
1862
  } catch {}
1646
1863
  }, 500);
1647
1864
  prune();
@@ -1674,18 +1891,13 @@ function marverPlugin(ctx) {
1674
1891
  server.watcher.on("unlink", restatus);
1675
1892
  server.watcher.on("change", restatus);
1676
1893
  server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
1677
- const marksChanged = debounce(() => server.ws.send("sh:marks", {}), 300);
1894
+ const marksChanged = debounce(observeLater, 300);
1678
1895
  for (const ev of [
1679
1896
  "add",
1680
1897
  "change",
1681
1898
  "unlink"
1682
1899
  ]) server.watcher.on(ev, (f) => {
1683
- if (inScope(f) && (/\.(tsx|jsx|html)$/.test(f) || isNoteFile(f))) marksChanged();
1684
- });
1685
- server.watcher.on("unlink", (f) => {
1686
- if (!inScope(f) || !isNoteFile(f)) return;
1687
- const fr = manifest.frames.find((x) => noteFileFor(join(root, x.file)) === f);
1688
- if (fr) recordChanged(root, [fr.id]);
1900
+ if (!f.startsWith(localDir) && !f.startsWith(boardsDirGen)) marksChanged();
1689
1901
  });
1690
1902
  const configFile = join(root, "design", "config.ts");
1691
1903
  server.watcher.on("change", (f) => {
@@ -1712,9 +1924,10 @@ function marverPlugin(ctx) {
1712
1924
  if (!checkBoardsDir(root, boardsDir)) {
1713
1925
  for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
1714
1926
  }
1927
+ if (nodeExists(join(boardsDir, `all-scenes.json`))) console.log(`[${NAME}] design/boards/${ALL_SCENES}.json is left over from the All Scenes board, gone since 0.25 - nothing reads it any more; delete it when you like (its threads stay in design/comments/)`);
1715
1928
  let listTimer;
1716
1929
  const watcher = watch(boardsDir, (_event, file) => {
1717
- if (!file || !file.endsWith(".json") || file === "_sizes.json") return;
1930
+ if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
1718
1931
  clearTimeout(listTimer);
1719
1932
  listTimer = setTimeout(() => {
1720
1933
  server.ws.send("sh:boards", {});
@@ -1825,7 +2038,7 @@ function marverPlugin(ctx) {
1825
2038
  });
1826
2039
  return;
1827
2040
  }
1828
- const { shootFrame, shootBatch, resolveFrames } = await import("./shot-Cw96h5Kk.mjs");
2041
+ const { shootFrame, shootBatch, resolveFrames } = await import("./shot-CckrGW-J.mjs");
1829
2042
  if (ways[0] === "frame") {
1830
2043
  if (typeof spec.frame !== "string") {
1831
2044
  write({
@@ -1893,7 +2106,11 @@ function marverPlugin(ctx) {
1893
2106
  });
1894
2107
  } catch {}
1895
2108
  }
1896
- };
2109
+ }, updatesPlugin(root, () => manifest, () => devServer && hooks, landed)];
2110
+ }
2111
+ /** The marks look at the frames on disk; true when they recorded something. */
2112
+ function observed(r) {
2113
+ return r.doc.length + r.note.length > 0;
1897
2114
  }
1898
2115
  function debounce(fn, ms) {
1899
2116
  let t;