@marver-design/marver 0.26.0 → 0.27.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 (96) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/README.md +10 -5
  3. package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
  4. package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
  5. package/dist/{bake-DtVlm0_F.mjs → bake-DM_uWgAA.mjs} +1 -1
  6. package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
  7. package/dist/{build-C_gUgcdC.mjs → build-DZnFysGU.mjs} +4 -4
  8. package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
  9. package/dist/cli.mjs +28 -16
  10. package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
  11. package/dist/{daemon-DZo6o3rU.mjs → daemon-BSA0lV8d.mjs} +400 -274
  12. package/dist/detect-C0wpaePX.mjs +125 -0
  13. package/dist/dev-eQJhWsqg.mjs +1273 -0
  14. package/dist/dev-lock-C_FC70Mu.mjs +65 -0
  15. package/dist/exclusive-B1RtpeeP.mjs +150 -0
  16. package/dist/{init-D8DtrK_F.mjs → init-COD0x48i.mjs} +5 -3
  17. package/dist/{link-BNzLvdhI.mjs → link-DDXZVGtv.mjs} +20 -8
  18. package/dist/ls-D7O1G505.mjs +38 -0
  19. package/dist/{marks-NQi0wZJ4.mjs → marks-CWM3WJjc.mjs} +1 -1
  20. package/dist/perf-BWzQwZqj.mjs +369 -0
  21. package/dist/perf-BoDSkbEb.mjs +429 -0
  22. package/dist/perf-jam-D55U3FZK.mjs +242 -0
  23. package/dist/{plugin-CTD0rydA.mjs → plugin-C-E7omsh.mjs} +425 -66
  24. package/dist/{poster-ChjXGTS5.mjs → poster-Bx83ZYVK.mjs} +2 -1
  25. package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
  26. package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-aljgm45S.mjs} +2 -2
  27. package/dist/{queue-BuiCKSX1.mjs → queue-CAM_vNmX.mjs} +3 -3
  28. package/dist/recover-t9Pno3u9.mjs +66 -0
  29. package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
  30. package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
  31. package/dist/shot-DoHLl6ig.mjs +139 -0
  32. package/dist/{shot-DqcxJibP.mjs → shot-LFhC-WYD.mjs} +343 -19
  33. package/dist/slots-DCDo3N0x.mjs +471 -0
  34. package/dist/speech-worker.mjs +40 -5
  35. package/dist/{sync-DKk-yT1V.mjs → sync-BQVlHZpx.mjs} +4 -3
  36. package/dist/{work-F5u-twpJ.mjs → work-Bp1p39kq.mjs} +4 -2
  37. package/dist/{work-VvX_JIgl.mjs → work-BroFwnup.mjs} +4 -2
  38. package/docs/boards-and-folders.md +3 -1
  39. package/docs/jam-session.md +78 -7
  40. package/docs/live-jam.md +8 -0
  41. package/docs/performance.md +262 -0
  42. package/package.json +2 -2
  43. package/src/client/content/index.tsx +3 -0
  44. package/src/client/content/video.tsx +6 -2
  45. package/src/client/frame-host/bridge.js +22 -6
  46. package/src/client/frame-host/inspect.js +8 -3
  47. package/src/client/frame-host/keys.js +6 -2
  48. package/src/client/frame-host/main.tsx +17 -5
  49. package/src/client/shell/App.tsx +188 -29
  50. package/src/client/shell/BoardList.tsx +5 -5
  51. package/src/client/shell/Comments.tsx +3 -2
  52. package/src/client/shell/JamSurface.tsx +13 -5
  53. package/src/client/shell/LockedApp.tsx +5 -5
  54. package/src/client/shell/Play.tsx +27 -15
  55. package/src/client/shell/Toolbar.tsx +17 -5
  56. package/src/client/shell/api.ts +206 -0
  57. package/src/client/shell/canvas/Canvas.tsx +30 -3
  58. package/src/client/shell/canvas/FrameNode.tsx +15 -5
  59. package/src/client/shell/canvas/admission.ts +8 -1
  60. package/src/client/shell/canvas/camera-broadcast.ts +15 -5
  61. package/src/client/shell/canvas/ctl.ts +2 -0
  62. package/src/client/shell/canvas/frame-registry.ts +28 -2
  63. package/src/client/shell/canvas/sleep.ts +4 -1
  64. package/src/client/shell/comments-store.ts +12 -4
  65. package/src/client/shell/goto.ts +22 -10
  66. package/src/client/shell/icons.tsx +2 -0
  67. package/src/client/shell/jam-capture.ts +96 -16
  68. package/src/client/shell/jam-keys.ts +51 -18
  69. package/src/client/shell/jam-lane.tsx +46 -5
  70. package/src/client/shell/jam-panel.tsx +66 -13
  71. package/src/client/shell/jam-queue.ts +3 -3
  72. package/src/client/shell/jam-session.tsx +14 -8
  73. package/src/client/shell/jam-state.ts +48 -6
  74. package/src/client/shell/jam-surface-parts.tsx +10 -6
  75. package/src/client/shell/jam-voice.ts +7 -5
  76. package/src/client/shell/legacy-links.ts +2 -2
  77. package/src/client/shell/main.tsx +4 -0
  78. package/src/client/shell/notes.ts +8 -1
  79. package/src/client/shell/perf.ts +69 -58
  80. package/src/client/shell/recorder-core.ts +183 -0
  81. package/src/client/shell/recorder.ts +565 -0
  82. package/src/client/shell/store.ts +268 -103
  83. package/src/client/shell/styles.css +54 -9
  84. package/src/client/stage/main.tsx +2 -0
  85. package/templates/AGENTS-embedded.md +22 -4
  86. package/templates/AGENTS-studio.md +22 -4
  87. package/templates/demo/dark.tsx +1 -1
  88. package/templates/demo/welcome.tsx +1 -1
  89. package/templates/instructions/jam.md +5 -3
  90. package/templates/instructions/welcome.md +6 -3
  91. package/dist/config-Cf7EjAMf.mjs +0 -292
  92. package/dist/dev-_Nlsc6v9.mjs +0 -742
  93. package/dist/dev-lock-DWSpa6nj.mjs +0 -179
  94. package/dist/perf-D6VmmJ2q.mjs +0 -68
  95. package/dist/perf-DPbLGhhO.mjs +0 -49
  96. package/dist/shot-CNbHoZ6H.mjs +0 -86
@@ -1,17 +1,181 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
1
  import { a as ROUTE, i as PKG, r as NAME } from "./cli.mjs";
3
2
  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
3
  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
4
  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-Nl3KSVOk.mjs";
6
- import { r as boardsChanged } from "./work-F5u-twpJ.mjs";
7
- import { n as localProfile, t as isConnected } from "./profile-WU9qcbIo.mjs";
8
- import { n as loadConfig } from "./config-Cf7EjAMf.mjs";
5
+ import { r as boardsChanged } from "./work-Bp1p39kq.mjs";
6
+ import { h as workspaceId, o as originOf } from "./slots-DCDo3N0x.mjs";
7
+ import { n as localProfile, t as isConnected } from "./profile-Bh5Y5zpW.mjs";
8
+ import { i as onPath, n as AGENT_NAMES, r as detectAgent, t as AGENT_BIN } from "./agent-BsieQGTD.mjs";
9
9
  import { a as observe, n as docRevs, r as initMarks, s as recordChanged, t as docRev } from "./marks-CKgzucHZ.mjs";
10
- import { t as logReload } from "./perf-DPbLGhhO.mjs";
10
+ import { n as logPage, r as logReload, s as tidyPerfDir, t as PAGE_BODY_MAX } from "./perf-BWzQwZqj.mjs";
11
11
  import { closeSync, copyFileSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, watch, writeFileSync } from "node:fs";
12
12
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
13
- import { fileURLToPath } from "node:url";
14
- import { createHash, randomBytes } from "node:crypto";
13
+ import { fileURLToPath, pathToFileURL } from "node:url";
14
+ import { createHmac, randomBytes } from "node:crypto";
15
+ //#region src/server/config.ts
16
+ const DEFAULTS = {
17
+ mode: "studio",
18
+ theme: null,
19
+ viewports: {
20
+ mobile: {
21
+ width: 390,
22
+ height: 844
23
+ },
24
+ tablet: {
25
+ width: 768,
26
+ height: 1024
27
+ },
28
+ laptop: {
29
+ width: 1280,
30
+ height: 800
31
+ },
32
+ monitor: {
33
+ width: 1920,
34
+ height: 1080
35
+ }
36
+ },
37
+ themes: ["light", "dark"],
38
+ port: 5199,
39
+ zoomSpeed: 1,
40
+ share: { branding: true }
41
+ };
42
+ /** Load design/config.ts via native TS import (Node >= 22.18). Missing or broken fields fall back to defaults. */
43
+ async function loadConfig(root) {
44
+ const file = join(root, "design", "config.ts");
45
+ if (!existsSync(file)) return {
46
+ ...DEFAULTS,
47
+ ...jamFields(void 0)
48
+ };
49
+ try {
50
+ const user = (await import(`${pathToFileURL(file).href}?t=${Date.now()}`)).default ?? {};
51
+ return {
52
+ ...DEFAULTS,
53
+ ...user,
54
+ viewports: validViewports(user.viewports) ?? DEFAULTS.viewports,
55
+ themes: Array.isArray(user.themes) && user.themes.length ? user.themes.map(String) : DEFAULTS.themes,
56
+ port: validPort(user.port) ?? DEFAULTS.port,
57
+ zoomSpeed: validZoom(user.zoomSpeed) ?? DEFAULTS.zoomSpeed,
58
+ description: readDescription(user.description),
59
+ share: {
60
+ branding: user.share?.branding !== false,
61
+ name: typeof user.share?.name === "string" ? user.share.name : void 0,
62
+ logo: typeof user.share?.logo === "string" ? user.share.logo : void 0,
63
+ frontDoor: user.share?.frontDoor !== false && user.share?.front_door !== false,
64
+ notify: user.share?.notify !== false
65
+ },
66
+ ...jamFields(user.jam)
67
+ };
68
+ } catch (err) {
69
+ console.error(`[marver] design/config.ts failed to load, using defaults and leaving Live Jam OFF:\n ${err.message}`);
70
+ return {
71
+ ...DEFAULTS,
72
+ jamOff: "unreadable"
73
+ };
74
+ }
75
+ }
76
+ const validDim = (n) => typeof n === "number" && Number.isFinite(n) && n >= 1 && n <= 2e4;
77
+ function validPort(n) {
78
+ return typeof n === "number" && Number.isInteger(n) && n > 0 && n < 65536 ? n : null;
79
+ }
80
+ function validZoom(n) {
81
+ return typeof n === "number" && Number.isFinite(n) && n >= .1 && n <= 10 ? n : null;
82
+ }
83
+ /** Six frames at once is what a jam actually feels like - at 3, half of a multi-frame
84
+ * ask sat waiting on the other half while the human watched. */
85
+ const DEFAULT_CONCURRENCY = 6;
86
+ /** A config value, printable in a warning. Never throws - a formatter that can crash inside an
87
+ * error path (JSON.stringify does, on a BigInt) turns a clear message into a mystery. */
88
+ const show = (v) => {
89
+ try {
90
+ return JSON.stringify(v) ?? String(v);
91
+ } catch {
92
+ return String(v);
93
+ }
94
+ };
95
+ /** A `{...}` written by hand, not a Date/Map/class instance that merely types as "object". */
96
+ const plainObject = (v) => {
97
+ if (!v || typeof v !== "object") return false;
98
+ const proto = Object.getPrototypeOf(v);
99
+ return proto === Object.prototype || proto === null;
100
+ };
101
+ /** The agent to arm with - or, when the human NAMED one we cannot use, why not (said once,
102
+ * here, because a bad `jam.agent` is a config-file error like any other).
103
+ *
104
+ * A named agent is never quietly swapped for another: running a different tool than the one
105
+ * asked for is worse than not running. Nor is one armed that cannot be spawned - that would
106
+ * claim every @marver mention, fail it, and never retry. */
107
+ function resolveAgent(named) {
108
+ if (named === void 0) return detectAgent() ?? "no-agent";
109
+ if (typeof named !== "string" || !Object.hasOwn(AGENT_BIN, named)) {
110
+ console.warn(`[marver] design/config.ts: jam.agent ${show(named)} is not an agent marver can spawn - Live Jam is off. Use ${AGENT_NAMES}.`);
111
+ return "bad-agent";
112
+ }
113
+ const agent = named;
114
+ if (!onPath(AGENT_BIN[agent])) {
115
+ console.warn(`[marver] design/config.ts names jam.agent "${agent}", but \`${AGENT_BIN[agent]}\` is not on PATH - Live Jam is off until it is installed.`);
116
+ return "bad-agent";
117
+ }
118
+ return agent;
119
+ }
120
+ /** Resolve the jam block. Live Jam is ON by default: an absent or partial `jam` resolves
121
+ * to whatever agent CLI this machine has, so a fresh workspace jams with nothing
122
+ * configured and an old one needs no re-init. `jam: false` is the off switch. */
123
+ function resolveJam(v) {
124
+ if (v === false) return "opted-out";
125
+ const shape = v === void 0 || v === true ? {} : typeof v === "string" ? { agent: v } : plainObject(v) ? v : null;
126
+ if (!shape) {
127
+ console.warn(`[marver] design/config.ts: jam must be false, an agent name, or an options object - got ${show(v)}. Live Jam is off.`);
128
+ return "bad-agent";
129
+ }
130
+ const j = shape;
131
+ const agent = resolveAgent(j.agent);
132
+ if (agent === "no-agent" || agent === "bad-agent") return agent;
133
+ const c = j.concurrency;
134
+ const pick = (key, v, ok, fallback, want) => {
135
+ if (v === void 0) return fallback;
136
+ if (ok(v)) return v;
137
+ console.warn(`[marver] design/config.ts: jam.${key} must be ${want} - got ${show(v)}. Using ${JSON.stringify(fallback)}.`);
138
+ return fallback;
139
+ };
140
+ const bool = (v) => typeof v === "boolean";
141
+ return {
142
+ agent,
143
+ concurrency: typeof c === "number" && Number.isInteger(c) && c >= 1 && c <= 16 ? c : DEFAULT_CONCURRENCY,
144
+ subagents: j.subagents !== false,
145
+ proactive: j.proactive === true,
146
+ chime: pick("chime", j.chime, bool, true, "true or false"),
147
+ capture: pick("capture", j.capture, (v) => v === "confirm" || v === "at-once", "confirm", `'confirm' or 'at-once'`),
148
+ loc: pick("loc", j.loc, bool, true, "true or false"),
149
+ names: pick("names", j.names, bool, true, "true or false")
150
+ };
151
+ }
152
+ /** Exactly one of `jam` (armed) or `jamOff` (why not) - so the dev server can speak up about
153
+ * the one off-state nothing has reported yet, and stay quiet about the rest. BOTH keys are
154
+ * always written: these spread over the user's own `jam`, and a raw `jam: false` reaching the
155
+ * server as config would arm the daemon against a truthy object check. */
156
+ function jamFields(v) {
157
+ const r = resolveJam(v);
158
+ return typeof r === "string" ? {
159
+ jam: void 0,
160
+ jamOff: r
161
+ } : {
162
+ jam: r,
163
+ jamOff: void 0
164
+ };
165
+ }
166
+ function validViewports(v) {
167
+ if (!v || typeof v !== "object") return null;
168
+ const out = {};
169
+ for (const [k, val] of Object.entries(v)) {
170
+ const vp = val;
171
+ if (validDim(vp?.width) && validDim(vp?.height)) out[k] = {
172
+ width: Math.round(vp.width),
173
+ height: Math.round(vp.height)
174
+ };
175
+ }
176
+ return Object.keys(out).length ? out : null;
177
+ }
178
+ //#endregion
15
179
  //#region src/shared/frames.ts
16
180
  /** A canvas made of content frames alone (Doc, Md, Diagram ship their own styling) needs no theme -
17
181
  * only an app frame does (#4). Empty counts as not content-only: the warning still helps there. */
@@ -363,6 +527,7 @@ function contained(target, base) {
363
527
  }
364
528
  }
365
529
  function apiMiddleware(root, opts = {}) {
530
+ const ws = opts.workspace ?? workspaceId(root);
366
531
  const devManifest = () => {
367
532
  if (opts.manifest) return opts.manifest();
368
533
  try {
@@ -607,7 +772,7 @@ function apiMiddleware(root, opts = {}) {
607
772
  const str = (v) => typeof v === "string" ? v.slice(0, 200) : void 0;
608
773
  const num = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
609
774
  if (!str(b?.kind)) return json(res, 400, { error: "kind required" });
610
- (await import("./perf-DPbLGhhO.mjs").then((n) => n.n)).logReload(root, {
775
+ (await import("./perf-BWzQwZqj.mjs").then((n) => n.i)).logReload(root, {
611
776
  kind: str(b.kind),
612
777
  tab: str(b.tab),
613
778
  node: str(b.node),
@@ -618,6 +783,36 @@ function apiMiddleware(root, opts = {}) {
618
783
  });
619
784
  return json(res, 200, { ok: true });
620
785
  }
786
+ if (path === "perf/jam" && req.method === "POST") {
787
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
788
+ const raw = await readBody(req);
789
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
790
+ let b;
791
+ try {
792
+ b = JSON.parse(raw);
793
+ } catch {
794
+ return json(res, 400, { error: "malformed JSON" });
795
+ }
796
+ if (!b || b.kind !== "capture" && b.kind !== "upload") return json(res, 400, { error: "kind must be capture or upload" });
797
+ (await import("./perf-jam-D55U3FZK.mjs").then((n) => n.n)).logJam(root, b);
798
+ return json(res, 200, { ok: true });
799
+ }
800
+ if (path === "perf/page" && req.method === "POST") {
801
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
802
+ const raw = await readBody(req, PAGE_BODY_MAX);
803
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
804
+ let b;
805
+ try {
806
+ b = JSON.parse(raw);
807
+ } catch {
808
+ return json(res, 400, { error: "malformed JSON" });
809
+ }
810
+ if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
811
+ return json(res, 200, {
812
+ ok: true,
813
+ accepted: logPage(root, b.records)
814
+ });
815
+ }
621
816
  if (path === "sizes" && req.method === "GET") {
622
817
  const frames = readManifestFrames();
623
818
  if (!frames) return json(res, 200, {
@@ -1009,7 +1204,7 @@ function apiMiddleware(root, opts = {}) {
1009
1204
  }
1010
1205
  }
1011
1206
  if (path === "shot" && req.method === "GET") {
1012
- const { readDevInfo } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
1207
+ const { readDevInfo } = await import("./work-Bp1p39kq.mjs").then((n) => n.o);
1013
1208
  const token = readDevInfo(root)?.token;
1014
1209
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
1015
1210
  const frameId = url.searchParams.get("frame") ?? "";
@@ -1025,7 +1220,7 @@ function apiMiddleware(root, opts = {}) {
1025
1220
  };
1026
1221
  const asPng = url.searchParams.get("format") === "png";
1027
1222
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
1028
- const { shootFrame } = await import("./shot-DqcxJibP.mjs");
1223
+ const { shootFrame } = await import("./shot-LFhC-WYD.mjs");
1029
1224
  const r = await shootFrame({
1030
1225
  root,
1031
1226
  viewports: opts.viewports ?? {},
@@ -1045,7 +1240,8 @@ function apiMiddleware(root, opts = {}) {
1045
1240
  scale: r.scale,
1046
1241
  ...r.truncated ? { truncated: true } : {},
1047
1242
  ...r.unsettled ? { unsettled: true } : {},
1048
- ...r.note ? { note: r.note } : {}
1243
+ ...r.note ? { note: r.note } : {},
1244
+ recaptures: r.recaptures
1049
1245
  };
1050
1246
  if (!asPng) return json(res, 200, summary);
1051
1247
  const png = readFileSync(join(root, r.path));
@@ -1058,7 +1254,7 @@ function apiMiddleware(root, opts = {}) {
1058
1254
  return res.end(png);
1059
1255
  }
1060
1256
  if (path === "shots" && req.method === "POST") {
1061
- const { readDevInfo } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
1257
+ const { readDevInfo } = await import("./work-Bp1p39kq.mjs").then((n) => n.o);
1062
1258
  const token = readDevInfo(root)?.token;
1063
1259
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
1064
1260
  const raw = await readBody(req);
@@ -1075,7 +1271,7 @@ function apiMiddleware(root, opts = {}) {
1075
1271
  if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
1076
1272
  const scale = body.scale === void 0 ? void 0 : body.scale;
1077
1273
  if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
1078
- const { resolveFrames, shootBatch } = await import("./shot-DqcxJibP.mjs");
1274
+ const { resolveFrames, shootBatch } = await import("./shot-LFhC-WYD.mjs");
1079
1275
  const sel = resolveFrames(root, body);
1080
1276
  if (!sel.ok) return json(res, sel.status, { error: sel.error });
1081
1277
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
@@ -1093,7 +1289,7 @@ function apiMiddleware(root, opts = {}) {
1093
1289
  }
1094
1290
  }
1095
1291
  if (path === "anchor" && req.method === "POST") {
1096
- const { readDevInfo } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
1292
+ const { readDevInfo } = await import("./work-Bp1p39kq.mjs").then((n) => n.o);
1097
1293
  const token = readDevInfo(root)?.token;
1098
1294
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
1099
1295
  const raw = await readBody(req);
@@ -1109,7 +1305,7 @@ function apiMiddleware(root, opts = {}) {
1109
1305
  if (typeof target === "string") return json(res, 400, { error: target });
1110
1306
  const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
1111
1307
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
1112
- const { checkAnchor, CheckInputError } = await import("./anchor-check-Dg5xpNnU.mjs");
1308
+ const { checkAnchor, CheckInputError } = await import("./anchor-check-ChdDqL5z.mjs");
1113
1309
  try {
1114
1310
  return json(res, 200, await checkAnchor({
1115
1311
  root,
@@ -1137,7 +1333,7 @@ function apiMiddleware(root, opts = {}) {
1137
1333
  return json(res, 400, { error: "malformed JSON" });
1138
1334
  }
1139
1335
  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" });
1140
- const { bakeBatch, ASK_MAX } = await import("./bake-DtVlm0_F.mjs");
1336
+ const { bakeBatch, ASK_MAX } = await import("./bake-DM_uWgAA.mjs");
1141
1337
  let manifest = {};
1142
1338
  try {
1143
1339
  manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
@@ -1198,11 +1394,19 @@ function apiMiddleware(root, opts = {}) {
1198
1394
  })
1199
1395
  });
1200
1396
  }
1201
- if (path === "poster" && req.method === "GET") {
1397
+ if (path === "poster" && req.method === "POST") {
1202
1398
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1203
- const src = url.searchParams.get("src") ?? "";
1204
- const { ensurePoster, isLocalClip } = await import("./poster-ChjXGTS5.mjs");
1205
- const { isLocalAssetRef } = await import("./build-C_gUgcdC.mjs");
1399
+ const raw = await readBody(req, 4096);
1400
+ if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
1401
+ let b;
1402
+ try {
1403
+ b = JSON.parse(raw);
1404
+ } catch {
1405
+ return json(res, 400, { error: "malformed JSON" });
1406
+ }
1407
+ const src = typeof b?.src === "string" ? b.src : "";
1408
+ const { ensurePoster, isLocalClip } = await import("./poster-Bx83ZYVK.mjs");
1409
+ const { isLocalAssetRef } = await import("./build-DZnFysGU.mjs");
1206
1410
  if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
1207
1411
  const r = await ensurePoster(join(root, "design", "assets"), src);
1208
1412
  if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
@@ -1265,14 +1469,14 @@ function apiMiddleware(root, opts = {}) {
1265
1469
  return json(res, 405, { error: "method not allowed" });
1266
1470
  }
1267
1471
  if (path === "work") {
1268
- const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
1472
+ const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-Bp1p39kq.mjs").then((n) => n.o);
1269
1473
  const tokenOk = () => {
1270
1474
  const t = readDevInfo(root)?.token;
1271
1475
  return !!t && req.headers["x-mv-work"] === t;
1272
1476
  };
1273
1477
  if (req.method === "GET") {
1274
1478
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
1275
- const { boardsShowing, activityClock } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
1479
+ const { boardsShowing, activityClock } = await import("./work-Bp1p39kq.mjs").then((n) => n.o);
1276
1480
  const frames = workActivity.active();
1277
1481
  return json(res, 200, {
1278
1482
  frames,
@@ -1367,7 +1571,7 @@ function apiMiddleware(root, opts = {}) {
1367
1571
  } catch {
1368
1572
  return json(res, 400, { error: "malformed JSON" });
1369
1573
  }
1370
- const { ACTIONS } = await import("./queue-BuiCKSX1.mjs");
1574
+ const { ACTIONS } = await import("./queue-CAM_vNmX.mjs");
1371
1575
  if (!b || typeof b.id !== "string" || !Number.isInteger(b.rev) || !ACTIONS.includes(b.action) || b.body !== void 0 && typeof b.body !== "string") return json(res, 400, { error: "expected { id, rev, action, body? }" });
1372
1576
  if ("kind" in b) return json(res, 400, { error: "a capture has no category" });
1373
1577
  const { jamLive } = await import("./live-Cgzsicwi.mjs");
@@ -1377,13 +1581,13 @@ function apiMiddleware(root, opts = {}) {
1377
1581
  }
1378
1582
  if (path === "jam/audio-ticket" && req.method === "POST") {
1379
1583
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1380
- const { issueTicket, speechLive } = await import("./audio-CmSRYFEs.mjs");
1584
+ const { issueTicket, speechLive } = await import("./audio-Dw1lfMdb.mjs");
1381
1585
  if (!speechLive.svc) return json(res, 409, { error: "jam is not running here" });
1382
1586
  return json(res, 200, { ticket: issueTicket() });
1383
1587
  }
1384
1588
  if (path === "jam/voice" && (req.method === "GET" || req.method === "POST")) {
1385
1589
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1386
- const { speechLive } = await import("./audio-CmSRYFEs.mjs");
1590
+ const { speechLive } = await import("./audio-Dw1lfMdb.mjs");
1387
1591
  const { downloadModels, downloadState, DOWNLOAD_MB } = await import("./speech-models-DomiLQcY.mjs");
1388
1592
  if (!speechLive.svc) return json(res, 409, { error: "jam is not running here" });
1389
1593
  if (req.method === "POST") {
@@ -1412,7 +1616,7 @@ function apiMiddleware(root, opts = {}) {
1412
1616
  if (!jamLive.session || !jamLive.view) return json(res, 409, { error: "jam is not running here" });
1413
1617
  if (req.method === "GET") {
1414
1618
  const ses = jamLive.view().session ?? null;
1415
- const { readTalk, talkMinutes, recordFile } = await import("./session-qZWKt_VA.mjs").then((n) => n.s);
1619
+ const { readTalk, talkMinutes, recordFile } = await import("./session-BAaJsK5c.mjs").then((n) => n.s);
1416
1620
  const folder = ses ? recordFile(root, ses.since, ses.id).replace(/[^/]+$/, "") : null;
1417
1621
  return json(res, 200, {
1418
1622
  session: ses,
@@ -1443,7 +1647,7 @@ function apiMiddleware(root, opts = {}) {
1443
1647
  });
1444
1648
  }
1445
1649
  if (b.action !== "start") {
1446
- const { speechLive } = await import("./audio-CmSRYFEs.mjs");
1650
+ const { speechLive } = await import("./audio-Dw1lfMdb.mjs");
1447
1651
  if (!await (speechLive.svc?.finishTalk(b.id) ?? Promise.resolve(true)).catch(() => false) && b.action === "wrapup" && b.includeTalk !== false) return json(res, 409, {
1448
1652
  ok: false,
1449
1653
  error: "what was said is still being written down - write the record again in a moment (or leave what was said out)"
@@ -1496,8 +1700,7 @@ function apiMiddleware(root, opts = {}) {
1496
1700
  } catch {
1497
1701
  return json(res, 400, { error: "malformed JSON" });
1498
1702
  }
1499
- const { createHash } = await import("node:crypto");
1500
- if (b?.workspace !== void 0 && b.workspace !== createHash("sha256").update(root).digest("hex").slice(0, 16)) return json(res, 409, { error: "this capture was made in another workspace" });
1703
+ if (b?.workspace !== void 0 && b.workspace !== ws) return json(res, 409, { error: "this capture was made in another workspace" });
1501
1704
  const { jamLive } = await import("./live-Cgzsicwi.mjs");
1502
1705
  if (!jamLive.capture) return json(res, 409, { error: "jam is not running here" });
1503
1706
  const r = await jamLive.capture(b?.record);
@@ -1505,7 +1708,7 @@ function apiMiddleware(root, opts = {}) {
1505
1708
  }
1506
1709
  if (path === "jam/capture" && req.method === "GET") {
1507
1710
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
1508
- const { readCapture } = await import("./capture-CrqvU_jh.mjs").then((n) => n.i);
1711
+ const { readCapture } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
1509
1712
  const id = url.searchParams.get("id") ?? "";
1510
1713
  const cap = readCapture(root, id);
1511
1714
  if (!cap) return json(res, 404, { error: "no such capture" });
@@ -1528,11 +1731,11 @@ function apiMiddleware(root, opts = {}) {
1528
1731
  } catch {
1529
1732
  return json(res, 400, { error: "malformed JSON" });
1530
1733
  }
1531
- const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-CrqvU_jh.mjs").then((n) => n.i);
1734
+ const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
1532
1735
  if (!b || typeof b.capture !== "string" || !CAPTURE_ID.test(b.capture) || typeof b.frame !== "string") return json(res, 400, { error: "expected { capture, frame, theme?, viewport? }" });
1533
1736
  if (readCapture(root, b.capture)) return json(res, 409, { error: "that capture is sealed" });
1534
1737
  const theme = typeof b.theme === "string" && /^[a-z0-9-]+$/i.test(b.theme) ? b.theme : "light";
1535
- const { shootFrame } = await import("./shot-DqcxJibP.mjs");
1738
+ const { shootFrame } = await import("./shot-LFhC-WYD.mjs");
1536
1739
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
1537
1740
  const vp = typeof b.viewport === "string" ? opts.viewports?.[b.viewport] : void 0;
1538
1741
  const dim = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
@@ -1553,15 +1756,20 @@ function apiMiddleware(root, opts = {}) {
1553
1756
  });
1554
1757
  if (!r.ok) return json(res, r.error.startsWith("unknown frame") ? 404 : 503, { error: r.error });
1555
1758
  sweepPictures(root);
1556
- return json(res, 200, { id: addPicture(root, r.path, {
1557
- frame: b.frame,
1558
- capture: b.capture
1559
- }) });
1759
+ const unchecked = /not checked for a stale surface/.test(r.note ?? "");
1760
+ return json(res, 200, {
1761
+ id: addPicture(root, r.path, {
1762
+ frame: b.frame,
1763
+ capture: b.capture,
1764
+ ...unchecked ? { unchecked: true } : {}
1765
+ }),
1766
+ ...unchecked ? { unchecked: true } : {}
1767
+ });
1560
1768
  }
1561
1769
  if (path === "jam/picture" && req.method === "GET") {
1562
1770
  const site = String(req.headers["sec-fetch-site"] ?? "");
1563
1771
  if (!ownerGated(req) && !(cookie(req, "mv_c") && (site === "same-origin" || site === "none"))) return json(res, 403, { error: "forbidden" });
1564
- const { picturePath } = await import("./capture-CrqvU_jh.mjs").then((n) => n.i);
1772
+ const { picturePath } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
1565
1773
  const p = picturePath(root, url.searchParams.get("id") ?? "");
1566
1774
  if (!p) return json(res, 404, { error: "no such picture" });
1567
1775
  const png = readFileSync(p.path);
@@ -1618,7 +1826,7 @@ function apiMiddleware(root, opts = {}) {
1618
1826
  }
1619
1827
  }
1620
1828
  if (path === "sync" && req.method === "POST") {
1621
- const { loadCollab, syncOnce } = await import("./sync-DKk-yT1V.mjs").then((n) => n.o);
1829
+ const { loadCollab, syncOnce } = await import("./sync-BQVlHZpx.mjs").then((n) => n.o);
1622
1830
  const collab = loadCollab(root);
1623
1831
  if (!collab) return json(res, 200, { connected: false });
1624
1832
  try {
@@ -1647,15 +1855,40 @@ function backgroundPush(root) {
1647
1855
  pushTimer = setTimeout(async () => {
1648
1856
  pushTimer = null;
1649
1857
  try {
1650
- const { loadCollab, syncOnce } = await import("./sync-DKk-yT1V.mjs").then((n) => n.o);
1858
+ const { loadCollab, syncOnce } = await import("./sync-BQVlHZpx.mjs").then((n) => n.o);
1651
1859
  const collab = loadCollab(root);
1652
1860
  if (collab) await syncOnce(root, collab);
1653
1861
  } catch {}
1654
1862
  }, 1500);
1655
1863
  }
1656
1864
  //#endregion
1865
+ //#region src/server/proof.ts
1866
+ /**
1867
+ * The document proof (spec 28 A1.4). The Mac app puts a fresh nonce on every main-frame request to a
1868
+ * local canvas (`x-mv-nonce`) and checks the answer before the document commits; only the canvas
1869
+ * holding the slot file's key can sign it, so the privileges the app grants belong to that exact
1870
+ * document. The proof rides the very response the app commits - the check and the load can never
1871
+ * reach different listeners.
1872
+ *
1873
+ * Pinned exactly, so the app (A2.3 `proof.ts`) computes the same: the key is the slot file's 32 bytes
1874
+ * (base64url there), HMAC-SHA256 over UTF-8 `doc|<nonce>|<port>` (port in decimal), base64url without
1875
+ * padding. Requests from the app itself carry `app|<port>` the same way.
1876
+ */
1877
+ /** 16-64 base64url characters - anything else is not a nonce, and is ignored. */
1878
+ const NONCE = /^[A-Za-z0-9_-]{16,64}$/;
1879
+ const sign$1 = (key, msg) => createHmac("sha256", key).update(msg, "utf8").digest("base64url");
1880
+ const docProof = (key, nonce, port) => sign$1(key, `doc|${nonce}|${port}`);
1881
+ /** The two headers for a request carrying a well-formed `x-mv-nonce`, else null. */
1882
+ function proofHeaders(p, nonce) {
1883
+ if (!p || typeof nonce !== "string" || !NONCE.test(nonce)) return null;
1884
+ return {
1885
+ "x-mv-instance": p.instance,
1886
+ "x-mv-proof": docProof(p.key, nonce, p.port)
1887
+ };
1888
+ }
1889
+ //#endregion
1657
1890
  //#region src/server/routes.ts
1658
- function routesMiddleware(server, clientDir, stamps) {
1891
+ function routesMiddleware(server, clientDir, stamps, proof) {
1659
1892
  const page = (dir) => {
1660
1893
  const html = readFileSync(join(clientDir, dir, "index.html"), "utf8");
1661
1894
  const entry = "/@fs/" + join(clientDir, dir, "main.tsx").split("\\").join("/");
@@ -1713,6 +1946,8 @@ function routesMiddleware(server, clientDir, stamps) {
1713
1946
  if (stamp) html = html.replace("<head>", `<head><meta name="mv-doc" content="${stamp.replace(/[&"<>]/g, (c) => `&#${c.charCodeAt(0)};`)}">`);
1714
1947
  res.setHeader("content-type", "text/html");
1715
1948
  res.setHeader("cache-control", "no-store");
1949
+ const signed = dir === "shell" && req.method === "GET" ? proofHeaders(proof, req.headers["x-mv-nonce"]) : null;
1950
+ if (signed) for (const [k, v] of Object.entries(signed)) res.setHeader(k, v);
1716
1951
  res.end(html);
1717
1952
  } catch (err) {
1718
1953
  res.statusCode = 500;
@@ -1721,6 +1956,89 @@ function routesMiddleware(server, clientDir, stamps) {
1721
1956
  };
1722
1957
  }
1723
1958
  //#endregion
1959
+ //#region src/server/guard.ts
1960
+ /** A workspace key as marver writes it: 16 hex. A frame's own `ws` query in another shape is the
1961
+ * frame's business, never ours. */
1962
+ const WS_KEY = /^[0-9a-f]{16}$/;
1963
+ /** Marks the workspace refusal, so the page tells it from every other 409 without reading the body. */
1964
+ const ELSEWHERE_HEADER = "x-mv-elsewhere";
1965
+ /** What a frame gets when its URL names another workspace: no script, nothing of this project. The
1966
+ * `mv-elsewhere` meta is how the shell, back on its own canvas, finds the frames to reload, and draws its own
1967
+ * quiet placeholder over them meanwhile (shell/api.ts) - so this page is read on its own: a frame's address
1968
+ * opened in a tab. It wears the frame's own theme (its URL's `theme`; a name with "dark" in it is dark), never
1969
+ * the system's: a light frame stays light on a Mac in dark mode. */
1970
+ function anotherCanvasPage(theme) {
1971
+ const dark = /dark/i.test(theme ?? "");
1972
+ const [bg, ink, dim, code] = dark ? [
1973
+ "#0f1015",
1974
+ "#ececf1",
1975
+ "#a1a1aa",
1976
+ "#1d1e26"
1977
+ ] : [
1978
+ "#ffffff",
1979
+ "#18181b",
1980
+ "#52525b",
1981
+ "#f0f0f2"
1982
+ ];
1983
+ return `<!doctype html><html><head><meta charset="utf-8"><meta name="mv-elsewhere" content="1"><meta name="color-scheme" content="${dark ? "dark" : "light"}"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Another canvas</title><style>html,body{height:100%;margin:0;background:${bg}}body{display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;font:400 13px/1.5 -apple-system,system-ui,sans-serif;color:${dim}}main{max-width:340px}h1{margin:0 0 6px;font-size:15px;font-weight:600;line-height:1.35;color:${ink}}p{margin:0}code{font:500 12px ui-monospace,SFMono-Regular,Menlo,monospace;color:${ink};background:${code};padding:1px 5px;border-radius:5px;white-space:nowrap}</style></head><body><main><h1>This frame's canvas stopped</h1><p>Another project runs on this address now. To bring this frame back, stop that project, run <code>npx marver dev</code> in this frame's own project, then reload.</p></main></body></html>`;
1984
+ }
1985
+ /**
1986
+ * The first middleware of every dev server (spec 28 A1.11). A page left open after its canvas
1987
+ * stopped may reach whatever listens on that port later; everything it sends names its workspace,
1988
+ * and this answers before anything of this project is read, written or served:
1989
+ * - `Service-Worker: script` (what the browser sends when it fetches a worker's script): 403 - no
1990
+ * service worker ever runs on a canvas, whatever later takes the port;
1991
+ * - `x-mv-ws` present and not ours: 409 `{ error: 'another workspace' }`;
1992
+ * - a `ws` query not ours (frame and stage URLs, a Jam picture's <img>): the same 409 under
1993
+ * /__mv/api/, else the "another canvas" page - a retained frame reloading its own URL never boots
1994
+ * this project's frame;
1995
+ * - `GET /__mv/api/hello`: `{ ok, ws }` - the stopped page asking "is my canvas back here?".
1996
+ * A request naming no workspace (the CLI, a test, an older page) is served as before.
1997
+ */
1998
+ function guardMiddleware(workspace) {
1999
+ return (req, res, next) => {
2000
+ if (String(req.headers["service-worker"] ?? "").toLowerCase() === "script") {
2001
+ res.statusCode = 403;
2002
+ res.setHeader("content-type", "text/plain; charset=utf-8");
2003
+ return res.end("marver canvases run no service workers");
2004
+ }
2005
+ let url;
2006
+ try {
2007
+ url = new URL(req.url ?? "/", "http://x");
2008
+ } catch {
2009
+ return next();
2010
+ }
2011
+ const api = url.pathname.startsWith(`${ROUTE}/api/`);
2012
+ const said = req.headers["x-mv-ws"];
2013
+ if (said !== void 0 && String(said) !== workspace) return elsewhere(res);
2014
+ const q = url.searchParams.get("ws");
2015
+ if (q !== null && WS_KEY.test(q) && q !== workspace) {
2016
+ if (api) return elsewhere(res);
2017
+ res.statusCode = 409;
2018
+ res.setHeader("content-type", "text/html; charset=utf-8");
2019
+ res.setHeader("cache-control", "no-store");
2020
+ res.setHeader(ELSEWHERE_HEADER, "1");
2021
+ return res.end(anotherCanvasPage(url.searchParams.get("theme")));
2022
+ }
2023
+ if (url.pathname === `/__mv/api/hello` && req.method === "GET") {
2024
+ res.setHeader("content-type", "application/json");
2025
+ res.setHeader("cache-control", "no-store");
2026
+ return res.end(JSON.stringify({
2027
+ ok: true,
2028
+ ws: workspace
2029
+ }));
2030
+ }
2031
+ next();
2032
+ };
2033
+ }
2034
+ function elsewhere(res) {
2035
+ res.statusCode = 409;
2036
+ res.setHeader("content-type", "application/json");
2037
+ res.setHeader("cache-control", "no-store");
2038
+ res.setHeader(ELSEWHERE_HEADER, "1");
2039
+ res.end(JSON.stringify({ error: "another workspace" }));
2040
+ }
2041
+ //#endregion
1724
2042
  //#region src/server/update.ts
1725
2043
  /**
1726
2044
  * Update discovery - dev only, and deliberately boring about privacy: one anonymous
@@ -1729,10 +2047,6 @@ function routesMiddleware(server, clientDir, stamps) {
1729
2047
  * firewalled registries degrade to silence. MARVER_NO_UPDATE_CHECK=1 disables it.
1730
2048
  * Published bundles never check anything - viewers are not the owner.
1731
2049
  */
1732
- var update_exports = /* @__PURE__ */ __exportAll({
1733
- checkUpdate: () => checkUpdate,
1734
- installedVersion: () => installedVersion
1735
- });
1736
2050
  const TTL = 864e5;
1737
2051
  /** Installed version: walk up from this module to the package's own package.json
1738
2052
  * (one level from dist/, two from src/server/ - the walk covers both). */
@@ -1798,6 +2112,9 @@ const VIRTUAL_CONFIG = "virtual:sh-config";
1798
2112
  const VIRTUAL_DATA = "virtual:sh-data";
1799
2113
  function marverPlugin(ctx) {
1800
2114
  const { root, clientDir, config } = ctx;
2115
+ const ws = ctx.workspace ?? workspaceId(root);
2116
+ /** a watcher this plugin makes, handed to the start (its error is said, not Node's crash) - as it is, outside one */
2117
+ const guarded = (w) => ctx.startup?.watch?.(w) ?? w;
1801
2118
  let project = {
1802
2119
  name: config.share.name || basename(root),
1803
2120
  description: config.description
@@ -1805,6 +2122,7 @@ function marverPlugin(ctx) {
1805
2122
  const projectInfo = () => project;
1806
2123
  let manifest = scanFrames(root, projectInfo());
1807
2124
  let devServer = null;
2125
+ let served = 0;
1808
2126
  const bootId = String(process.hrtime.bigint());
1809
2127
  let invRev = 0;
1810
2128
  const pendingInv = /* @__PURE__ */ new Set();
@@ -1860,6 +2178,10 @@ function marverPlugin(ctx) {
1860
2178
  }, 1e4);
1861
2179
  inFlight.set(file, f);
1862
2180
  };
2181
+ ctx.startup?.defer(() => {
2182
+ flushInv.cancel();
2183
+ for (const f of inFlight.values()) clearTimeout(f.timer);
2184
+ });
1863
2185
  const landed = (file) => {
1864
2186
  const owed = late.get(file);
1865
2187
  if (owed) {
@@ -1958,7 +2280,7 @@ function marverPlugin(ctx) {
1958
2280
  capture: config.jam.capture,
1959
2281
  names: config.jam.names && config.jam.agent === "claude"
1960
2282
  } : null,
1961
- workspace: createHash("sha256").update(root).digest("hex").slice(0, 16)
2283
+ workspace: ws
1962
2284
  })}`;
1963
2285
  }
1964
2286
  if (id === "\0virtual:sh-data") return "export default null";
@@ -2004,6 +2326,25 @@ function marverPlugin(ctx) {
2004
2326
  }
2005
2327
  },
2006
2328
  configureServer(server) {
2329
+ const closers = [];
2330
+ const onClose = (fn) => {
2331
+ closers.push(fn);
2332
+ };
2333
+ const closeAll = () => {
2334
+ for (const fn of closers.splice(0).reverse()) try {
2335
+ fn();
2336
+ } catch {}
2337
+ };
2338
+ const withdraw = ctx.startup?.defer(closeAll, server);
2339
+ server.httpServer?.once("close", () => {
2340
+ withdraw?.();
2341
+ closeAll();
2342
+ });
2343
+ if (served++) {
2344
+ manifest = scanFrames(root, projectInfo());
2345
+ observeLater();
2346
+ }
2347
+ server.middlewares.use(guardMiddleware(ws));
2007
2348
  let bakeGen = Date.now();
2008
2349
  server.middlewares.use((req, res, next) => {
2009
2350
  if (req.url && req.url.includes("/frame-host/registry.ts")) {
@@ -2027,25 +2368,27 @@ function marverPlugin(ctx) {
2027
2368
  }));
2028
2369
  });
2029
2370
  });
2030
- const listeningOrigin = () => {
2031
- const a = server.httpServer?.address();
2032
- if (!a || typeof a === "string") return null;
2033
- return `http://${a.family === "IPv6" ? a.address === "::" ? "[::1]" : `[${a.address}]` : a.address === "0.0.0.0" ? "127.0.0.1" : a.address}:${a.port}`;
2034
- };
2371
+ const listeningOrigin = () => originOf(server.httpServer?.address());
2035
2372
  initMarks(root, manifest.frames);
2373
+ tidyPerfDir(root);
2036
2374
  server.middlewares.use(apiMiddleware(root, {
2037
2375
  viewports: config.viewports,
2038
2376
  origin: listeningOrigin,
2039
2377
  bakeGen: () => bakeGen,
2040
2378
  notify: (event) => server.ws.send(event, {}),
2041
2379
  manifest: () => manifest,
2042
- settled
2380
+ settled,
2381
+ workspace: ws
2043
2382
  }));
2044
2383
  server.middlewares.use(routesMiddleware(server, clientDir, {
2045
2384
  doc: (id) => docRev(root, manifest.frames, id),
2046
2385
  docs: () => docRevs(root, manifest.frames)
2047
- }));
2386
+ }, ctx.proof));
2387
+ const before = devServer;
2048
2388
  devServer = server;
2389
+ onClose(() => {
2390
+ if (devServer === server) devServer = before;
2391
+ });
2049
2392
  guardUpdates(server, root, () => manifest, hooks);
2050
2393
  let framesKey = JSON.stringify(manifest.frames);
2051
2394
  let scenesKey = JSON.stringify(manifest.scenes);
@@ -2068,6 +2411,7 @@ function marverPlugin(ctx) {
2068
2411
  framesKey = key;
2069
2412
  scenesKey = sKey;
2070
2413
  }, 150);
2414
+ onClose(regen.cancel);
2071
2415
  const watched = [join(root, "design", "scenes"), join(root, "design", "components")];
2072
2416
  const inScope = (file) => watched.some((w) => file.startsWith(w));
2073
2417
  const themeModules = () => {
@@ -2087,6 +2431,7 @@ function marverPlugin(ctx) {
2087
2431
  const pushTheme = debounce(() => {
2088
2432
  for (const mod of themeModules()) server.reloadModule(mod).catch(() => {});
2089
2433
  }, 150);
2434
+ onClose(pushTheme.cancel);
2090
2435
  const rescanTheme = () => {
2091
2436
  for (const mod of themeModules()) server.moduleGraph.invalidateModule(mod);
2092
2437
  pushTheme();
@@ -2097,11 +2442,19 @@ function marverPlugin(ctx) {
2097
2442
  bakeGen++;
2098
2443
  prune();
2099
2444
  };
2100
- const prune = () => setTimeout(async () => {
2101
- try {
2102
- (await import("./bake-DtVlm0_F.mjs")).pruneBakes(root, bakeGen);
2103
- } catch {}
2104
- }, 500);
2445
+ const pruning = /* @__PURE__ */ new Set();
2446
+ const prune = () => {
2447
+ const t = setTimeout(async () => {
2448
+ pruning.delete(t);
2449
+ try {
2450
+ (await import("./bake-DM_uWgAA.mjs")).pruneBakes(root, bakeGen);
2451
+ } catch {}
2452
+ }, 500);
2453
+ pruning.add(t);
2454
+ };
2455
+ onClose(() => {
2456
+ for (const t of pruning) clearTimeout(t);
2457
+ });
2105
2458
  prune();
2106
2459
  server.watcher.on("add", bumpGen);
2107
2460
  server.watcher.on("unlink", bumpGen);
@@ -2120,6 +2473,7 @@ function marverPlugin(ctx) {
2120
2473
  });
2121
2474
  const contextDir = join(root, "context") + sep;
2122
2475
  let statusTimer;
2476
+ onClose(() => clearTimeout(statusTimer));
2123
2477
  const restatus = (f) => {
2124
2478
  if (!f.startsWith(contextDir) && !(inScope(f) && f.endsWith("_brief.md"))) return;
2125
2479
  clearTimeout(statusTimer);
@@ -2133,6 +2487,7 @@ function marverPlugin(ctx) {
2133
2487
  server.watcher.on("change", restatus);
2134
2488
  server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
2135
2489
  const marksChanged = debounce(observeLater, 300);
2490
+ onClose(marksChanged.cancel);
2136
2491
  for (const ev of [
2137
2492
  "add",
2138
2493
  "change",
@@ -2167,7 +2522,7 @@ function marverPlugin(ctx) {
2167
2522
  }
2168
2523
  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/)`);
2169
2524
  let listTimer;
2170
- const watcher = watch(boardsDir, (_event, file) => {
2525
+ const watcher = guarded(watch(boardsDir, (_event, file) => {
2171
2526
  if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
2172
2527
  clearTimeout(listTimer);
2173
2528
  listTimer = setTimeout(() => {
@@ -2196,8 +2551,12 @@ function marverPlugin(ctx) {
2196
2551
  sha256: hash(content)
2197
2552
  });
2198
2553
  }, 120));
2554
+ }));
2555
+ onClose(() => {
2556
+ watcher.close();
2557
+ clearTimeout(listTimer);
2558
+ for (const t of timers.values()) clearTimeout(t);
2199
2559
  });
2200
- server.httpServer?.once("close", () => watcher.close());
2201
2560
  } catch {}
2202
2561
  try {
2203
2562
  const inbox = join(root, "design", ".local", "shots");
@@ -2279,7 +2638,7 @@ function marverPlugin(ctx) {
2279
2638
  });
2280
2639
  return;
2281
2640
  }
2282
- const { shootFrame, shootBatch, resolveFrames } = await import("./shot-DqcxJibP.mjs");
2641
+ const { shootFrame, shootBatch, resolveFrames } = await import("./shot-LFhC-WYD.mjs");
2283
2642
  if (ways[0] === "frame") {
2284
2643
  if (typeof spec.frame !== "string") {
2285
2644
  write({
@@ -2332,16 +2691,16 @@ function marverPlugin(ctx) {
2332
2691
  }
2333
2692
  }, 60);
2334
2693
  };
2335
- const inboxWatcher = watch(inbox, { persistent: false }, (_e, file) => {
2694
+ const inboxWatcher = guarded(watch(inbox, { persistent: false }, (_e, file) => {
2336
2695
  if (file) processRequest(file);
2337
- });
2696
+ }));
2338
2697
  const sweep = setInterval(() => {
2339
2698
  try {
2340
2699
  for (const f of readdirSync(inbox)) processRequest(f);
2341
2700
  } catch {}
2342
2701
  }, 1e3);
2343
2702
  sweep.unref?.();
2344
- server.httpServer?.once("close", () => {
2703
+ onClose(() => {
2345
2704
  inboxWatcher.close();
2346
2705
  clearInterval(sweep);
2347
2706
  });
@@ -2355,10 +2714,10 @@ function observed(r) {
2355
2714
  }
2356
2715
  function debounce(fn, ms) {
2357
2716
  let t;
2358
- return ((...a) => {
2717
+ return Object.assign(((...a) => {
2359
2718
  clearTimeout(t);
2360
2719
  t = setTimeout(() => fn(...a), ms);
2361
- });
2720
+ }), { cancel: () => clearTimeout(t) });
2362
2721
  }
2363
2722
  /** Extra vite plugin when the host runs Tailwind v4. The host's own @tailwindcss/vite
2364
2723
  * wins (version-matched to their tailwindcss); the fallback is marver's bundled copy -
@@ -2400,4 +2759,4 @@ async function tailwind3Css(root) {
2400
2759
  return null;
2401
2760
  }
2402
2761
  //#endregion
2403
- 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 };
2762
+ export { autoWidthOf as a, readSizes as c, installedVersion as i, loadConfig as l, tailwind3Css as n, keptSizes as o, tailwind4Plugin as r, measuringFrames as s, marverPlugin as t };