@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
@@ -0,0 +1,369 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { a as checkRealDirs } from "./boards-CGg6piKF.mjs";
3
+ import { appendFileSync, chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
4
+ import { basename, join } from "node:path";
5
+ //#region src/server/perf.ts
6
+ /**
7
+ * The perf logs, one JSON line per event in design/.local/perf/ - local, never committed, the owner's alone (the
8
+ * directory 700, every file in it 600). `npx marver perf` reads them back.
9
+ * - reloads.jsonl, the reload log (spec 26 Part 1): the server's view (an edit and the frames it reached, a full
10
+ * reload sent or dropped) and the page's (each document that actually booted, and how long it took);
11
+ * - page.jsonl, the recorder's page half (spec 28 A1.7): what each board load did, from the page - its request and
12
+ * commit, each frame's outcome, every move and why, quiet, the last move and settled - plus gestures and
13
+ * errors. Each record is rebuilt from its kind's allowlist; `npx marver perf --loads` reads them back.
14
+ */
15
+ var perf_exports = /* @__PURE__ */ __exportAll({
16
+ CUT_REASONS: () => CUT_REASONS,
17
+ DROP_REASONS: () => DROP_REASONS,
18
+ GESTURES: () => GESTURES,
19
+ LOAD_CAUSES: () => LOAD_CAUSES,
20
+ OUTCOMES: () => OUTCOMES,
21
+ PAGE_BODY_MAX: () => PAGE_BODY_MAX,
22
+ PAGE_KINDS: () => PAGE_KINDS,
23
+ SOURCES: () => SOURCES,
24
+ cleanPageRecord: () => cleanPageRecord,
25
+ logPage: () => logPage,
26
+ logReload: () => logReload,
27
+ pageLog: () => pageLog,
28
+ perfDir: () => perfDir,
29
+ readPage: () => readPage,
30
+ readReloads: () => readReloads,
31
+ reloadLog: () => reloadLog,
32
+ tidyPerfDir: () => tidyPerfDir
33
+ });
34
+ const MAX = 2e6;
35
+ /** page.jsonl's: one load of a 120-frame board writes ~140 KB (two thirds of it moves), so 2 MB held about fourteen
36
+ * such loads - hours, not the 14 days the lines may stay. 8 MB holds four times as many. */
37
+ const PAGE_MAX = 8e6;
38
+ const maxOf = (file) => basename(file) === "page.jsonl" ? PAGE_MAX : MAX;
39
+ const KEEP_MS = 12096e5;
40
+ /** The logs whose lines age out and whose size is held at start (spec 28 A1.7, A1.13): every one with a `ts` per line. */
41
+ const AGED = [
42
+ "reloads.jsonl",
43
+ "page.jsonl",
44
+ "runs.jsonl",
45
+ "jam.jsonl"
46
+ ];
47
+ const perfDir = (root) => join(root, "design", ".local", "perf");
48
+ const reloadLog = (root) => join(perfDir(root), "reloads.jsonl");
49
+ const pageLog = (root) => join(perfDir(root), "page.jsonl");
50
+ /** design/, design/.local and its perf/ must be real directories inside the project: a log is never written through a link. */
51
+ const unsafe = (root) => checkRealDirs(root, [
52
+ [join(root, "design"), "design"],
53
+ [join(root, "design", ".local"), "design/.local"],
54
+ [perfDir(root), "design/.local/perf"]
55
+ ]);
56
+ /** One append to a perf log: the directory 700 and the file 600 from their creation, never through a link, the
57
+ * oldest half gone past its cap (maxOf). Throws - callers swallow. */
58
+ function appendLog(root, file, text) {
59
+ const why = unsafe(root);
60
+ if (why) throw new Error(why);
61
+ mkdirSync(join(root, "design", ".local"), { recursive: true });
62
+ mkdirSync(perfDir(root), {
63
+ recursive: true,
64
+ mode: 448
65
+ });
66
+ if (existsSync(file)) {
67
+ if (!lstatSync(file).isFile()) throw new Error("not a regular file");
68
+ if (statSync(file).size > maxOf(file)) {
69
+ const lines = readFileSync(file, "utf8").split("\n");
70
+ writeFileSync(file, lines.slice(Math.floor(lines.length / 2)).join("\n"));
71
+ }
72
+ }
73
+ appendFileSync(file, text, { mode: 384 });
74
+ }
75
+ function logReload(root, entry) {
76
+ try {
77
+ appendLog(root, reloadLog(root), JSON.stringify({
78
+ ts: Date.now(),
79
+ ...entry
80
+ }) + "\n");
81
+ } catch {}
82
+ }
83
+ const readLines = (file, since) => {
84
+ try {
85
+ return readFileSync(file, "utf8").split("\n").flatMap((l) => {
86
+ try {
87
+ const e = JSON.parse(l);
88
+ return typeof e?.ts === "number" && e.ts >= since ? [e] : [];
89
+ } catch {
90
+ return [];
91
+ }
92
+ });
93
+ } catch {
94
+ return [];
95
+ }
96
+ };
97
+ const readReloads = (root, since = 0) => readLines(reloadLog(root), since);
98
+ /** The page's records from `since` (epoch ms): malformed lines skipped. */
99
+ const readPage = (root, since = 0) => readLines(pageLog(root), since);
100
+ /** What one request may carry. */
101
+ const PAGE_BODY_MAX = 524288;
102
+ const PAGE_KINDS = [
103
+ "load",
104
+ "commit",
105
+ "visible",
106
+ "frame",
107
+ "move",
108
+ "quiet",
109
+ "settled",
110
+ "cut",
111
+ "gesture",
112
+ "error",
113
+ "dropped"
114
+ ];
115
+ const LOAD_CAUSES = [
116
+ "boot",
117
+ "switch",
118
+ "disk-reload"
119
+ ];
120
+ const CUT_REASONS = [
121
+ "switch",
122
+ "reload",
123
+ "hidden",
124
+ "timeout",
125
+ "superseded",
126
+ "error",
127
+ "edited",
128
+ "unsaved"
129
+ ];
130
+ const OUTCOMES = [
131
+ "settled",
132
+ "ready",
133
+ "missing",
134
+ "error",
135
+ "never-ready",
136
+ "cut"
137
+ ];
138
+ const GESTURES = [
139
+ "pan",
140
+ "zoom",
141
+ "layout"
142
+ ];
143
+ const SOURCES = [
144
+ "shell",
145
+ "frame",
146
+ "stage"
147
+ ];
148
+ /** why records were dropped, when it is not the queue's bound or a failed send: errors past a load's 50 */
149
+ const DROP_REASONS = ["errors"];
150
+ const ID = /^[0-9a-f]{12}$/;
151
+ const WS = /^[0-9a-f]{16}$/;
152
+ const CAUSE = /^[a-z][a-z0-9:+-]{0,63}$/;
153
+ const BOARD = /^(?:~unplaced|[a-z0-9][a-z0-9-]{0,63})$/;
154
+ const str = (v, n = 200) => typeof v === "string" && v ? v.slice(0, n) : void 0;
155
+ const id = (v) => typeof v === "string" && ID.test(v) ? v : void 0;
156
+ const count = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 && v < 1e7 ? v : void 0;
157
+ const ms = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v < 1e9 ? Math.round(v) : void 0;
158
+ const tenth = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v < 1e7 ? Math.round(v * 10) / 10 : void 0;
159
+ const delta = (v) => typeof v === "number" && Number.isFinite(v) && Math.abs(v) < 1e7 ? Math.round(v) : void 0;
160
+ const flag = (v) => v === true ? true : void 0;
161
+ const oneOf = (v, set) => typeof v === "string" && set.includes(v) ? v : void 0;
162
+ const obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
163
+ const prune = (o) => Object.fromEntries(Object.entries(o).filter(([, x]) => x !== void 0));
164
+ const cause = (v) => typeof v === "string" && CAUSE.test(v) ? v : void 0;
165
+ /** Each kind's fields, rebuilt from what the page sent - anything else is left out; null = the record is dropped. */
166
+ const BODY = {
167
+ load: (r) => {
168
+ const board = typeof r.board === "string" && BOARD.test(r.board) ? r.board : void 0, c = oneOf(r.cause, LOAD_CAUSES), request = id(r.request);
169
+ return board && c && request ? {
170
+ board,
171
+ cause: c,
172
+ request,
173
+ sinceNav: ms(r.sinceNav)
174
+ } : null;
175
+ },
176
+ commit: (r) => {
177
+ const k = obj(r.byKind);
178
+ return {
179
+ request: id(r.request),
180
+ ms: ms(r.ms),
181
+ frames: count(r.frames),
182
+ byKind: prune({
183
+ hifi: count(k.hifi),
184
+ content: count(k.content),
185
+ html: count(k.html),
186
+ image: count(k.image)
187
+ }),
188
+ measuring: count(r.measuring),
189
+ savedHeights: count(r.savedHeights),
190
+ late: flag(r.late)
191
+ };
192
+ },
193
+ visible: (r) => ({
194
+ nodes: count(r.nodes),
195
+ ms: ms(r.ms),
196
+ assumed: flag(r.assumed)
197
+ }),
198
+ frame: (r) => {
199
+ const node = str(r.node), outcome = oneOf(r.outcome, OUTCOMES);
200
+ return node && outcome ? {
201
+ node,
202
+ frame: str(r.frame),
203
+ gen: str(r.gen, 32),
204
+ boot: str(r.boot, 32),
205
+ admitted: ms(r.admitted),
206
+ ready: ms(r.ready),
207
+ firstMeasure: ms(r.firstMeasure),
208
+ settled: ms(r.settled),
209
+ outcome,
210
+ kept: flag(r.kept)
211
+ } : null;
212
+ },
213
+ move: (r) => {
214
+ const node = str(r.node), c = cause(r.cause);
215
+ return node && c ? {
216
+ node,
217
+ dx: delta(r.dx),
218
+ dy: delta(r.dy),
219
+ dw: delta(r.dw),
220
+ dh: delta(r.dh),
221
+ cause: c,
222
+ late: flag(r.late)
223
+ } : null;
224
+ },
225
+ quiet: (r) => ms(r.ms) === void 0 ? null : { ms: ms(r.ms) },
226
+ settled: (r) => {
227
+ if (ms(r.ms) === void 0) return null;
228
+ const w = obj(r.weight);
229
+ return {
230
+ ms: ms(r.ms),
231
+ moves: count(r.moves),
232
+ distance: count(r.distance),
233
+ lastMove: ms(r.lastMove),
234
+ causes: Object.fromEntries(Object.entries(obj(r.causes)).slice(0, 32).flatMap(([k, n]) => cause(k) && count(n) !== void 0 ? [[k, n]] : [])),
235
+ visibleReadyMs: ms(r.visibleReadyMs),
236
+ allReadyMs: ms(r.allReadyMs),
237
+ missing: count(r.missing),
238
+ neverReady: count(r.neverReady),
239
+ errors: count(r.errors),
240
+ weight: prune({
241
+ domNodes: count(w.domNodes),
242
+ iframes: count(w.iframes),
243
+ awake: count(w.awake),
244
+ asleep: count(w.asleep),
245
+ heapMB: tenth(w.heapMB)
246
+ })
247
+ };
248
+ },
249
+ cut: (r) => {
250
+ const reason = oneOf(r.reason, CUT_REASONS);
251
+ return reason ? {
252
+ reason,
253
+ request: id(r.request),
254
+ ms: ms(r.ms),
255
+ lastMove: ms(r.lastMove),
256
+ frames: count(r.frames),
257
+ ready: count(r.ready)
258
+ } : null;
259
+ },
260
+ gesture: (r) => {
261
+ const type = oneOf(r.type, GESTURES);
262
+ return type ? {
263
+ type,
264
+ ms: ms(r.ms),
265
+ frames: count(r.frames),
266
+ p50: tenth(r.p50),
267
+ p95: tenth(r.p95),
268
+ max: tenth(r.max),
269
+ over17ms: count(r.over17ms),
270
+ over33ms: count(r.over33ms),
271
+ longFrames: count(r.longFrames)
272
+ } : null;
273
+ },
274
+ error: (r) => {
275
+ const source = oneOf(r.source, SOURCES), message = str(r.message);
276
+ const stack = Array.isArray(r.stack) ? r.stack.slice(0, 3).map((l) => str(l)).filter((l) => !!l) : [];
277
+ return source && message ? {
278
+ source,
279
+ frame: str(r.frame),
280
+ component: str(r.component),
281
+ message,
282
+ stack: stack.length ? stack : void 0,
283
+ late: flag(r.late)
284
+ } : null;
285
+ },
286
+ dropped: (r) => count(r.n) === void 0 ? null : {
287
+ n: count(r.n),
288
+ reason: oneOf(r.reason, DROP_REASONS)
289
+ }
290
+ };
291
+ /** A page record rebuilt from the envelope and its kind's allowlist, or null. Strings are cut to 200 characters. */
292
+ function cleanPageRecord(raw, now = Date.now()) {
293
+ const r = obj(raw);
294
+ if (r.v !== 1) return null;
295
+ const kind = oneOf(r.kind, PAGE_KINDS);
296
+ const ws = typeof r.ws === "string" && WS.test(r.ws) ? r.ws : void 0;
297
+ const page = id(r.page), load = r.load === "-" ? "-" : id(r.load), seq = count(r.seq);
298
+ if (!kind || !ws || !page || !load || seq === void 0) return null;
299
+ const body = BODY[kind](r);
300
+ if (!body) return null;
301
+ return {
302
+ v: 1,
303
+ ws,
304
+ page,
305
+ load,
306
+ seq,
307
+ ts: typeof r.ts === "number" && Number.isFinite(r.ts) && Math.abs(r.ts - now) < 864e5 ? Math.round(r.ts) : now,
308
+ kind,
309
+ ...prune(body)
310
+ };
311
+ }
312
+ /** The page's records into design/.local/perf/page.jsonl - best effort; how many were kept. */
313
+ function logPage(root, raws) {
314
+ const now = Date.now();
315
+ const lines = raws.slice(0, 5e3).flatMap((x) => {
316
+ const c = cleanPageRecord(x, now);
317
+ return c ? [JSON.stringify(c)] : [];
318
+ });
319
+ if (!lines.length) return 0;
320
+ try {
321
+ appendLog(root, pageLog(root), lines.join("\n") + "\n");
322
+ } catch {
323
+ return 0;
324
+ }
325
+ return lines.length;
326
+ }
327
+ /** At start (spec 28 A1.7): design/.local/perf/ is the owner's alone - the directory 700 and every file in it 600,
328
+ * those earlier versions created without modes included - and the logs whose lines age out lose the ones older than
329
+ * 14 days and, still past their cap (2 MB; page.jsonl 8 MB), their oldest half. Synchronous, before the server
330
+ * listens: no append of this process interleaves. Best effort; a link is never followed. */
331
+ function tidyPerfDir(root, now = Date.now()) {
332
+ try {
333
+ if (unsafe(root)) return;
334
+ const dir = perfDir(root);
335
+ let st;
336
+ try {
337
+ st = lstatSync(dir);
338
+ } catch {
339
+ return;
340
+ }
341
+ if (!st.isDirectory()) return;
342
+ chmodSync(dir, 448);
343
+ for (const name of readdirSync(dir)) {
344
+ const f = join(dir, name);
345
+ try {
346
+ if (!lstatSync(f).isFile()) continue;
347
+ chmodSync(f, 384);
348
+ if (!AGED.includes(name)) continue;
349
+ const text = readFileSync(f, "utf8");
350
+ let lines = text.split("\n").filter((l) => {
351
+ try {
352
+ const e = JSON.parse(l);
353
+ return typeof e?.ts === "number" && e.ts >= now - KEEP_MS;
354
+ } catch {
355
+ return false;
356
+ }
357
+ });
358
+ if (Buffer.byteLength(lines.join("\n")) > maxOf(name)) lines = lines.slice(Math.floor(lines.length / 2));
359
+ const next = lines.length ? lines.join("\n") + "\n" : "";
360
+ if (next === text) continue;
361
+ const tmp = `${f}.${process.pid}.tmp`;
362
+ writeFileSync(tmp, next, { mode: 384 });
363
+ renameSync(tmp, f);
364
+ } catch {}
365
+ }
366
+ } catch {}
367
+ }
368
+ //#endregion
369
+ export { readPage as a, perf_exports as i, logPage as n, readReloads as o, logReload as r, tidyPerfDir as s, PAGE_BODY_MAX as t };