@marver-design/marver 0.27.0 → 0.28.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 (111) hide show
  1. package/CHANGELOG.md +195 -0
  2. package/README.md +9 -4
  3. package/dist/{anchor-check-ChdDqL5z.mjs → anchor-check-PHUOFj1N.mjs} +1 -1
  4. package/dist/{audio-Dw1lfMdb.mjs → audio-DX4POHAj.mjs} +39 -4
  5. package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
  6. package/dist/{boards-DlTcpF47.mjs → boards-BeWtjGUM.mjs} +50 -5
  7. package/dist/boards-EH2onUXM.mjs +995 -0
  8. package/dist/{build-DZnFysGU.mjs → build-BsAyLMT1.mjs} +9 -22
  9. package/dist/{capture-vadKjuCo.mjs → capture-DdZ6xgoz.mjs} +92 -30
  10. package/dist/cli.mjs +56 -21
  11. package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
  12. package/dist/{comments-DxOkCSNE.mjs → comments-CrBHPEQl.mjs} +4 -4
  13. package/dist/config-BezZTiov.mjs +182 -0
  14. package/dist/conn-BMiHS42T.mjs +222 -0
  15. package/dist/connectors-MR9d-EBP.mjs +290 -0
  16. package/dist/{context-HQ4Giw58.mjs → context-BUnFiyA3.mjs} +3 -3
  17. package/dist/{daemon-BSA0lV8d.mjs → daemon-C5dg2R-V.mjs} +2188 -183
  18. package/dist/{dev-eQJhWsqg.mjs → dev-D7YS7iT2.mjs} +25 -14
  19. package/dist/{init-COD0x48i.mjs → init-WE5lQkQL.mjs} +8 -3
  20. package/dist/jam-Cj5gBvwD.mjs +373 -0
  21. package/dist/{link-DDXZVGtv.mjs → link-BFFRgrMt.mjs} +4 -4
  22. package/dist/listener-DdLEM79A.mjs +80 -0
  23. package/dist/{ls-D7O1G505.mjs → ls-BZ5TAtd5.mjs} +1 -1
  24. package/dist/{manifest-Nl3KSVOk.mjs → manifest-DPZ3WNg_.mjs} +2 -2
  25. package/dist/{marks-CWM3WJjc.mjs → marks-Dyn6tmjp.mjs} +3 -3
  26. package/dist/{marks-CKgzucHZ.mjs → marks-Kmdab_5w.mjs} +3 -3
  27. package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
  28. package/dist/perf-Cn5LiRaY.mjs +1319 -0
  29. package/dist/perf-jam-QxD_UnzN.mjs +635 -0
  30. package/dist/permit-DDa6wqOs.mjs +187 -0
  31. package/dist/plugin-C_0yb-Fq.mjs +5089 -0
  32. package/dist/{poster-Bx83ZYVK.mjs → poster-DHi6I1fO.mjs} +1 -1
  33. package/dist/{profile-Bh5Y5zpW.mjs → profile-jIS6BcAs.mjs} +1 -1
  34. package/dist/{publish-bakes-aljgm45S.mjs → publish-bakes-r4PEZuPl.mjs} +3 -3
  35. package/dist/{queue-CAM_vNmX.mjs → queue-c-6aTHEz.mjs} +164 -25
  36. package/dist/{recover-t9Pno3u9.mjs → recover-nrLEVLyJ.mjs} +2 -2
  37. package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
  38. package/dist/{session-BAaJsK5c.mjs → session-DyVE7cCk.mjs} +1 -1
  39. package/dist/{share-W5H3BNvP.mjs → share-Ce4tP7ji.mjs} +1 -1
  40. package/dist/{shot-LFhC-WYD.mjs → shot-BrRtqaiS.mjs} +34 -8
  41. package/dist/{shot-DoHLl6ig.mjs → shot-DBWN8hPP.mjs} +1 -1
  42. package/dist/sizes-wjXDev3b.mjs +139 -0
  43. package/dist/{slots-DCDo3N0x.mjs → slots-CFNnegCc.mjs} +8 -1
  44. package/dist/speech-worker.mjs +23 -3
  45. package/dist/{sync-BQVlHZpx.mjs → sync-CQdGARJ9.mjs} +1 -1
  46. package/dist/transport-C5FnY9ni.mjs +203 -0
  47. package/dist/{work-BroFwnup.mjs → work-BYWD_1Zf.mjs} +3 -3
  48. package/dist/{work-Bp1p39kq.mjs → work-DJxH7cCX.mjs} +1 -1
  49. package/docs/jam-session.md +42 -16
  50. package/docs/live-jam.md +92 -10
  51. package/docs/performance.md +197 -35
  52. package/package.json +1 -1
  53. package/src/client/content/video.tsx +10 -2
  54. package/src/client/shell/App.tsx +10 -3
  55. package/src/client/shell/Comments.tsx +5 -3
  56. package/src/client/shell/ContextMenu.tsx +5 -3
  57. package/src/client/shell/JamSurface.tsx +56 -21
  58. package/src/client/shell/LockedApp.tsx +3 -0
  59. package/src/client/shell/Play.tsx +4 -2
  60. package/src/client/shell/Tip.tsx +3 -1
  61. package/src/client/shell/api.ts +47 -20
  62. package/src/client/shell/app-bridge.ts +254 -0
  63. package/src/client/shell/app-perf.ts +92 -0
  64. package/src/client/shell/canvas/Canvas.tsx +115 -22
  65. package/src/client/shell/canvas/FrameNode.tsx +10 -6
  66. package/src/client/shell/canvas/admission.ts +23 -8
  67. package/src/client/shell/canvas/ctl.ts +6 -0
  68. package/src/client/shell/canvas/sleep.ts +57 -17
  69. package/src/client/shell/canvas/updates.ts +2 -1
  70. package/src/client/shell/icons.tsx +1 -0
  71. package/src/client/shell/inset.ts +44 -0
  72. package/src/client/shell/jam-capture.ts +113 -33
  73. package/src/client/shell/jam-keys.ts +40 -9
  74. package/src/client/shell/jam-lane.tsx +14 -5
  75. package/src/client/shell/jam-lines.ts +66 -9
  76. package/src/client/shell/jam-panel.tsx +61 -6
  77. package/src/client/shell/jam-queue.ts +50 -8
  78. package/src/client/shell/jam-session.tsx +53 -4
  79. package/src/client/shell/jam-surface-parts.tsx +6 -3
  80. package/src/client/shell/jam-ui.tsx +6 -1
  81. package/src/client/shell/jam-voice-wait.ts +21 -0
  82. package/src/client/shell/jam-voice.ts +62 -15
  83. package/src/client/shell/main.tsx +14 -1
  84. package/src/client/shell/marks-ui.tsx +5 -3
  85. package/src/client/shell/marver-app.ts +21 -0
  86. package/src/client/shell/perf-run-probe.ts +34 -0
  87. package/src/client/shell/perf-run.ts +70 -0
  88. package/src/client/shell/perf.ts +11 -0
  89. package/src/client/shell/recorder.ts +45 -3
  90. package/src/client/shell/store.ts +52 -24
  91. package/src/client/shell/styles.css +65 -17
  92. package/src/client/shell/tidy.ts +3 -2
  93. package/src/client/shell/unsaved.ts +81 -0
  94. package/src/client/shell/whiteout-probes.ts +141 -0
  95. package/src/shared/app-api.ts +205 -0
  96. package/src/shared/app-perf.ts +308 -0
  97. package/src/shared/approval.ts +20 -0
  98. package/src/shared/events.ts +1 -1
  99. package/src/shared/logo-sniff.ts +86 -0
  100. package/src/shared/machine.ts +132 -0
  101. package/src/shared/perf-run.ts +177 -0
  102. package/templates/AGENTS-embedded.md +31 -1
  103. package/templates/AGENTS-studio.md +31 -1
  104. package/templates/instructions/boards.md +10 -2
  105. package/templates/instructions/jam.md +90 -0
  106. package/dist/bake-DM_uWgAA.mjs +0 -786
  107. package/dist/boards-CGg6piKF.mjs +0 -342
  108. package/dist/perf-BWzQwZqj.mjs +0 -369
  109. package/dist/perf-BoDSkbEb.mjs +0 -429
  110. package/dist/perf-jam-D55U3FZK.mjs +0 -242
  111. package/dist/plugin-C-E7omsh.mjs +0 -2762
@@ -1,429 +0,0 @@
1
- import { u as humanize } from "./board-tree-DRioF94d.mjs";
2
- import { a as readPage, o as readReloads } from "./perf-BWzQwZqj.mjs";
3
- import { r as readJam } from "./perf-jam-D55U3FZK.mjs";
4
- //#region src/cli/perf.ts
5
- /**
6
- * `marver perf` (spec 26 Part 1): the reload log read back - per edited file, the frames it reached
7
- * and how; every page-wide reload (sent or dropped) and every time the canvas page itself booted,
8
- * with what came just before; the slowest frames to settle; one line per board load. Reads
9
- * design/.local/perf/reloads.jsonl, and page.jsonl for the loads (`--loads`: each load in full, spec 28 A1.8).
10
- */
11
- function perfCommand(root, opts) {
12
- if (opts.jam) return jamPerf(root, opts);
13
- if (opts.loads) return loadsPerf(root, opts);
14
- const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
15
- const since = Date.now() - minutes * 6e4;
16
- const log = readReloads(root, since);
17
- const loads = loadsSummary(readPage(root, since));
18
- const files = /* @__PURE__ */ new Map();
19
- for (const e of log) if (e.kind === "update") {
20
- const f = files.get(e.file ?? "(no file)") ?? {
21
- edits: 0,
22
- reload: /* @__PURE__ */ new Set(),
23
- inPlace: /* @__PURE__ */ new Set()
24
- };
25
- f.edits++;
26
- for (const id of e.reload ?? []) f.reload.add(id);
27
- for (const id of e.inPlace ?? []) f.inPlace.add(id);
28
- files.set(e.file ?? "(no file)", f);
29
- }
30
- const reloads = log.filter((e) => e.kind === "full-reload");
31
- const boots = log.flatMap((e, i) => e.kind === "shell-boot" ? [{
32
- ts: e.ts,
33
- before: log.slice(Math.max(0, i - 3), i).filter((x) => x.kind !== "ready" && x.kind !== "settled")
34
- }] : []);
35
- const slow = log.filter((e) => e.kind === "settled" && typeof e.ms === "number").sort((a, b) => b.ms - a.ms).slice(0, 5);
36
- const booted = log.filter((e) => e.kind === "ready");
37
- const by = (c) => booted.filter((e) => e.cause === c).length;
38
- const reloaded = by("job");
39
- if (opts.json) {
40
- console.log(JSON.stringify({
41
- minutes,
42
- files: Object.fromEntries([...files].map(([k, v]) => [k, {
43
- edits: v.edits,
44
- reached: [...v.reload],
45
- inPlace: [...v.inPlace]
46
- }])),
47
- documents: {
48
- afterEdit: reloaded,
49
- byHand: by("manual"),
50
- retried: by("retry"),
51
- self: by("self"),
52
- first: by("first")
53
- },
54
- reloads,
55
- boots,
56
- slow,
57
- loads: loads.map((l) => ({
58
- at: l.at,
59
- board: l.board,
60
- cause: l.cause,
61
- state: l.state,
62
- settledMs: l.settledMs,
63
- cut: l.cut,
64
- ...l.mountedAfterCut ? { mountedAfterCut: true } : {},
65
- moves: l.moves.count,
66
- late: l.moves.late.count,
67
- errors: l.errors.length,
68
- lateErrors: l.errors.filter((e) => e.late).length
69
- }))
70
- }, null, 2));
71
- return;
72
- }
73
- const t = (ts) => new Date(ts).toLocaleTimeString();
74
- console.log(`last ${minutes} min - design/.local/perf/reloads.jsonl`);
75
- console.log(`\nedits (${files.size} files)`);
76
- for (const [file, f] of [...files].sort((a, b) => b[1].edits - a[1].edits)) console.log(` ${file} ${f.edits}x reached ${f.reload.size} frame${f.reload.size === 1 ? "" : "s"}${f.inPlace.size ? `, ${f.inPlace.size} updated in place` : ""}`);
77
- console.log(`\nframe documents booted: ${reloaded} after an edit (a frame off screen reloads when it comes into view), ${by("first")} first loads, ${by("manual")} by hand, ${by("retry")} watchdog retries, ${by("self")} reloaded themselves`);
78
- console.log(`\npage-wide reloads: ${reloads.filter((r) => r.passed).length} sent (dependency rebuilds), ${reloads.filter((r) => !r.passed).length} dropped`);
79
- for (const r of reloads) console.log(` ${t(r.ts)} ${r.passed ? "sent " : "dropped"} ${r.triggeredBy ?? "no file named"}`);
80
- console.log(`\ncanvas page loads: ${boots.length}`);
81
- for (const b of boots) console.log(` ${t(b.ts)}${b.before.length ? ` after: ${b.before.map((x) => x.kind + (x.file ? ` ${x.file}` : "")).join(", ")}` : ""}`);
82
- if (slow.length) {
83
- console.log("\nslowest to settle");
84
- for (const s of slow) console.log(` ${s.frame} ${s.ms} ms`);
85
- }
86
- if (loads.length) {
87
- console.log(`\nboard loads: ${loads.length} (--loads: each in full)`);
88
- const w = Math.max(...loads.map((l) => (l.board ?? "?").length));
89
- for (const l of loads) {
90
- const bits = [
91
- endOf(l),
92
- ...l.moves.count || l.moves.late.count ? [`${l.moves.count} move${l.moves.count === 1 ? "" : "s"}${l.moves.late.count ? ` (${l.moves.late.count} late)` : ""}`] : [],
93
- ...l.errors.length ? [`${l.errors.length} error${l.errors.length === 1 ? "" : "s"}${lateErrors(l) ? ` (${lateErrors(l)} late)` : ""}`] : []
94
- ];
95
- console.log(` ${t(l.at)} ${(l.board ?? "?").padEnd(w)} ${(l.cause ?? "").padEnd(11)} ${bits.join(" · ")}`);
96
- }
97
- }
98
- }
99
- /** Each record once: a send retried after its first attempt landed repeats its records - same ws, page and seq. */
100
- function unique(records) {
101
- const seen = /* @__PURE__ */ new Set();
102
- return records.filter((r) => {
103
- const k = `${r.ws}/${r.page}/${r.seq}`;
104
- if (seen.has(k)) return false;
105
- seen.add(k);
106
- return true;
107
- });
108
- }
109
- const ranked = (counts, n = 5) => [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, n);
110
- const bump = (m, k) => m.set(k, (m.get(k) ?? 0) + 1);
111
- /** Board loads (spec 28 A1.8): page.jsonl's records grouped by ws/page/load, each group in seq order; a node's last
112
- * `frame` record is its outcome. A load whose `load` record fell before the window still shows what is in it.
113
- * Records of no load (`load: '-'`, before the page's first board committed) are `unownedOf`'s. */
114
- function loadsSummary(records) {
115
- const groups = /* @__PURE__ */ new Map();
116
- for (const r of unique(records)) {
117
- if (typeof r.load !== "string" || r.load === "-" || typeof r.kind !== "string") continue;
118
- const k = `${r.ws}/${r.page}/${r.load}`;
119
- groups.set(k, [...groups.get(k) ?? [], r]);
120
- }
121
- const out = [];
122
- for (const g of groups.values()) {
123
- g.sort((a, b) => (a.seq ?? 0) - (b.seq ?? 0));
124
- const of = (kind) => g.filter((r) => r.kind === kind);
125
- const one = (kind) => g.find((r) => r.kind === kind);
126
- const load = one("load"), commit = one("commit"), settled = one("settled"), cut = one("cut"), quiet = one("quiet"), visible = one("visible");
127
- const moves = {
128
- count: 0,
129
- distance: 0,
130
- causes: /* @__PURE__ */ new Map()
131
- }, late = {
132
- count: 0,
133
- causes: /* @__PURE__ */ new Map()
134
- };
135
- for (const m of of("move")) {
136
- const cause = typeof m.cause === "string" ? m.cause : "unknown";
137
- if (m.late) {
138
- late.count++;
139
- bump(late.causes, cause);
140
- continue;
141
- }
142
- moves.count++;
143
- bump(moves.causes, cause);
144
- moves.distance += Math.hypot(m.dx ?? 0, m.dy ?? 0) + Math.abs(m.dw ?? 0) + Math.abs(m.dh ?? 0);
145
- }
146
- const last = /* @__PURE__ */ new Map();
147
- for (const f of of("frame")) if (typeof f.node === "string") last.set(f.node, f);
148
- const frames = [...last.values()];
149
- const name = (f) => String(f.frame ?? f.node);
150
- const num = (v) => typeof v === "number";
151
- const slowest = frames.filter((f) => f.outcome !== "cut").flatMap((f) => {
152
- const ms = f.settled ?? f.ready;
153
- return num(ms) ? [{
154
- node: f.node,
155
- ...f.frame ? { frame: f.frame } : {},
156
- ms,
157
- outcome: f.outcome,
158
- ...num(f.admitted) ? { admittedMs: f.admitted } : {},
159
- ...num(f.ready) ? { readyMs: f.ready } : {}
160
- }] : [];
161
- }).sort((a, b) => b.ms - a.ms).slice(0, 5);
162
- const started = frames.map((f) => f.admitted).filter(num);
163
- const seenErr = /* @__PURE__ */ new Set();
164
- const errors = of("error").flatMap((e) => {
165
- const k = `${e.source}|${e.frame ?? ""}|${e.message}|${e.late ? "late" : ""}`;
166
- if (seenErr.has(k)) return [];
167
- seenErr.add(k);
168
- return [{
169
- source: e.source,
170
- ...e.frame ? { frame: e.frame } : {},
171
- ...e.component ? { component: e.component } : {},
172
- message: String(e.message ?? ""),
173
- ...e.late ? { late: true } : {}
174
- }];
175
- });
176
- const gs = of("gesture");
177
- const cutFirst = !!cut && (typeof cut.request === "string" || !commit);
178
- out.push({
179
- ws: g[0].ws,
180
- page: g[0].page,
181
- load: g[0].load,
182
- at: load?.ts ?? Math.min(...g.map((r) => r.ts)),
183
- ...load ? {
184
- board: load.board,
185
- cause: load.cause
186
- } : {},
187
- state: settled ? "settled" : cut ? "cut" : "open",
188
- ...cut && !settled ? { cut: {
189
- reason: cut.reason,
190
- ...typeof cut.ms === "number" ? { ms: cut.ms } : {},
191
- ...cutFirst ? { request: true } : {}
192
- } } : {},
193
- committed: !!commit,
194
- ...commit && cutFirst ? { mountedAfterCut: true } : {},
195
- ...commit ? {
196
- commitMs: commit.ms,
197
- frames: commit.frames,
198
- byKind: commit.byKind,
199
- measuring: commit.measuring,
200
- savedHeights: commit.savedHeights
201
- } : {},
202
- ...visible ? {
203
- visible: visible.nodes,
204
- visibleMs: visible.ms,
205
- ...visible.assumed ? { visibleAssumed: true } : {}
206
- } : {},
207
- ...settled ? {
208
- visibleReadyMs: settled.visibleReadyMs,
209
- allReadyMs: settled.allReadyMs,
210
- settledMs: settled.ms,
211
- weight: settled.weight
212
- } : {},
213
- ...quiet ? { quietMs: quiet.ms } : {},
214
- ...typeof (settled ?? cut)?.lastMove === "number" ? { lastMoveMs: (settled ?? cut).lastMove } : {},
215
- moves: {
216
- count: moves.count,
217
- distance: Math.round(moves.distance),
218
- causes: ranked(moves.causes),
219
- late: {
220
- count: late.count,
221
- causes: ranked(late.causes)
222
- }
223
- },
224
- slowest,
225
- ...started.length ? { firstStartedMs: Math.min(...started) } : {},
226
- ...cut && !settled && commit && !cutFirst && typeof cut.frames === "number" && typeof cut.ready === "number" ? {
227
- framesAtCut: cut.frames,
228
- readyByCut: cut.ready
229
- } : {},
230
- errors,
231
- errorsNotRecorded: notRecorded(g),
232
- neverReady: frames.filter((f) => f.outcome === "never-ready").map(name),
233
- missing: frames.filter((f) => f.outcome === "missing").map(name),
234
- unfinished: frames.filter((f) => f.outcome === "cut").length,
235
- ...gs.length ? { gestures: {
236
- n: gs.length,
237
- worstP95: Math.max(...gs.map((x) => x.p95 ?? 0)),
238
- over33ms: gs.reduce((n, x) => n + (x.over33ms ?? 0), 0)
239
- } } : {}
240
- });
241
- }
242
- return out.sort((a, b) => a.at - b.at);
243
- }
244
- /** Errors past a load's 50 (`dropped` records with reason `errors`): counted by the page, never recorded. */
245
- const notRecorded = (g) => g.filter((r) => r.kind === "dropped" && r.reason === "errors").reduce((n, r) => n + (Number(r.n) || 0), 0);
246
- /** What a page recorded before its first board committed: its errors (those past 50 counted), and how many gestures. */
247
- function unownedOf(records) {
248
- const mine = unique(records).filter((r) => r.load === "-");
249
- return {
250
- errors: mine.filter((r) => r.kind === "error").map((e) => ({
251
- at: e.ts,
252
- source: e.source,
253
- ...e.frame ? { frame: e.frame } : {},
254
- message: e.message
255
- })),
256
- errorsNotRecorded: notRecorded(mine),
257
- gestures: mine.filter((r) => r.kind === "gesture").length
258
- };
259
- }
260
- /** Records the pages lost before they reached the log - past a page's queue, or in a send that failed three times
261
- * (`dropped` records without a reason; errors past a load's 50 are that load's). */
262
- const droppedOf = (records) => unique(records).filter((r) => r.kind === "dropped" && r.reason === void 0).reduce((n, r) => n + (Number(r.n) || 0), 0);
263
- const lateErrors = (l) => l.errors.filter((e) => e.late).length;
264
- /** The errors `--loads` prints for a load, as examples: the rest are counted on a line of their own (--json has all). */
265
- const ERRORS_SHOWN = 10;
266
- const secs = (ms) => typeof ms === "number" ? `${(ms / 1e3).toFixed(1)} s` : "-";
267
- /** a wait or a frame's own time, often under a second: to the hundredth */
268
- const secs2 = (ms) => ms >= 1e4 ? secs(ms) : `${(Math.max(0, ms) / 1e3).toFixed(2)} s`;
269
- const boardName = (b) => b === "~unplaced" ? "Not on a board" : b ? humanize(b) : "a board (its request is older)";
270
- /** How a load ended, in a few words. */
271
- function endOf(l) {
272
- if (l.state === "settled") return `settled ${secs(l.settledMs)}`;
273
- if (l.cut?.request && l.mountedAfterCut) return `cut (${l.cut.reason})${l.cut.ms !== void 0 ? ` at ${secs(l.cut.ms)}` : ""} before it mounted · mounted ${secs(l.commitMs)}`;
274
- if (l.cut?.request) return `not committed (${l.cut.reason})`;
275
- if (l.cut) return `cut (${l.cut.reason})${l.cut.ms !== void 0 ? ` at ${secs(l.cut.ms)}` : ""}`;
276
- return "not settled yet";
277
- }
278
- /** `marver perf --loads` (spec 28 A1.8): each board load in full, from design/.local/perf/page.jsonl. */
279
- function loadsPerf(root, opts) {
280
- const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
281
- const records = readPage(root, Date.now() - minutes * 6e4);
282
- const loads = loadsSummary(records);
283
- const dropped = droppedOf(records);
284
- if (opts.json) {
285
- console.log(JSON.stringify({
286
- minutes,
287
- loads,
288
- unowned: unownedOf(records),
289
- dropped
290
- }, null, 2));
291
- return;
292
- }
293
- console.log(`board loads, last ${minutes} min - design/.local/perf/page.jsonl`);
294
- if (!loads.length) {
295
- console.log("\nnothing yet - open a board in the canvas");
296
- return;
297
- }
298
- const t = (ts) => new Date(ts).toLocaleTimeString();
299
- const list = (r) => r.map(([k, n]) => `${k} ${n}`).join(", ");
300
- const plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
301
- for (const l of loads) {
302
- const head = `${boardName(l.board)}${l.cause ? ` (${l.cause})` : ""}`;
303
- console.log(`\n ${t(l.at)} ${head.padEnd(40)} ${endOf(l)}`);
304
- if (!l.committed) continue;
305
- const kinds = Object.entries(l.byKind ?? {}).filter(([, n]) => n).map(([k, n]) => `${n} ${k === "hifi" ? "hi-fi" : k}`);
306
- console.log(` ${l.mountedAfterCut ? "mounted after its cut" : "committed"} ${secs(l.commitMs)} · ${plural(l.frames ?? 0, "frame")}${kinds.length ? ` (${kinds.join(", ")})` : ""}${l.measuring ? ` · ${l.measuring} measure, ${l.savedHeights ?? 0} opened at a known height` : ""}`);
307
- const times = [
308
- ...l.firstStartedMs !== void 0 ? [`first frame started ${secs2(l.firstStartedMs)}`] : [],
309
- ...l.readyByCut !== void 0 ? [`${l.readyByCut} of ${l.framesAtCut} ready`] : [],
310
- ...l.visibleReadyMs !== void 0 ? [`visible ready ${secs(l.visibleReadyMs)}${l.visible !== void 0 ? ` (${plural(l.visible, "frame")}${l.visibleAssumed ? ", no fit" : ""})` : ""}`] : [],
311
- ...l.allReadyMs !== void 0 ? [`all ready ${secs(l.allReadyMs)}`] : [],
312
- ...l.quietMs !== void 0 ? [`quiet ${secs(l.quietMs)}`] : [],
313
- ...l.lastMoveMs !== void 0 ? [`last move ${secs(l.lastMoveMs)}`] : [],
314
- ...l.settledMs !== void 0 ? [`settled ${secs(l.settledMs)}`] : []
315
- ];
316
- if (times.length) console.log(` ${times.join(" · ")}`);
317
- const m = l.moves;
318
- console.log(` ${plural(m.count, "move")}${m.count ? `, ${m.distance} px: ${list(m.causes)}` : ""}${m.late.count ? ` · late, after it ${l.state === "settled" ? "settled" : l.state === "cut" ? "was cut" : "ended"}: ${m.late.count} (${list(m.late.causes)})` : ""}`);
319
- const took = (f) => `${f.frame ?? f.node} ${secs(f.ms)}${f.admittedMs !== void 0 ? ` (waited ${secs2(f.admittedMs)}, then ${secs2(f.ms - f.admittedMs)})` : ""}`;
320
- const slow = [...l.slowest.length ? [`slowest: ${l.slowest.map(took).join(", ")}`] : [], ...l.unfinished ? [`${l.unfinished} never finished`] : []];
321
- if (slow.length) console.log(` ${slow.join(" · ")}`);
322
- const gone = [...l.neverReady.length ? [`never ready: ${l.neverReady.join(", ")}`] : [], ...l.missing.length ? [`missing: ${l.missing.join(", ")}`] : []];
323
- if (gone.length) console.log(` ${gone.join(" · ")}`);
324
- for (const e of l.errors.slice(0, ERRORS_SHOWN)) console.log(` ${e.late ? "late error" : "error"} (${e.source}${e.frame ? ` ${e.frame}` : ""}${e.component ? `, in ${e.component}` : ""}): ${e.message}`);
325
- if (l.errors.length > ERRORS_SHOWN) console.log(` ${plural(l.errors.length - ERRORS_SHOWN, "more error")} not shown (--json lists every one)`);
326
- if (l.errorsNotRecorded) console.log(` ${plural(l.errorsNotRecorded, "more error")} past the first 50, not recorded`);
327
- if (l.gestures) console.log(` ${plural(l.gestures.n, "gesture")} · worst p95 ${l.gestures.worstP95} ms · ${plural(l.gestures.over33ms, "frame")} over 33 ms`);
328
- }
329
- if (dropped) console.log(`\n ${plural(dropped, "record")} never reached this log: a page's queue was full, or its sends failed`);
330
- }
331
- /** Count, median, p90 and max of a list of ms. */
332
- function spread(xs) {
333
- if (!xs.length) return { n: 0 };
334
- const v = [...xs].sort((a, b) => a - b);
335
- const at = (q) => v[Math.min(v.length - 1, Math.ceil(q * v.length) - 1)];
336
- return {
337
- n: v.length,
338
- median: at(.5),
339
- p90: at(.9),
340
- max: v[v.length - 1]
341
- };
342
- }
343
- /** `marver perf --jam`: each step of a capture and its run - count, median, p90, max - the runs by outcome, and the
344
- * last problems, from design/.local/perf/jam.jsonl (numbers and codes only). */
345
- function jamSummary(events) {
346
- const of = (kind) => events.filter((e) => e.kind === kind);
347
- const nums = (xs) => xs.filter((x) => typeof x === "number");
348
- const caps = of("capture"), runs = of("run").filter((r) => !r.redelivered), shots = of("shot"), words = of("words");
349
- const steps = {
350
- "capture: E to sealed": spread(nums(caps.map((c) => c.sealMs))),
351
- "capture: last words": spread(nums(caps.map((c) => c.wordsWaitMs))),
352
- "capture: a picture": spread(nums(caps.flatMap((c) => c.pictures?.ms ?? []))),
353
- "upload": spread(nums(of("upload").map((u) => u.ms))),
354
- "naming": spread(nums(of("name").map((n) => n.ms))),
355
- "words: wait": spread(nums(words.map((w) => w.waitMs))),
356
- "words: transcription": spread(nums(words.map((w) => w.decodeMs))),
357
- "words: model load": spread(nums(words.map((w) => w.modelLoadMs))),
358
- "run: queued": spread(nums(runs.flatMap((r) => (r.members ?? []).map((m) => m.waitMs)))),
359
- "run: pictures before": spread(nums(runs.map((r) => r.beforeMs))),
360
- "run: agent": spread(nums(runs.flatMap((r) => r.agentMs ?? []))),
361
- "run: pictures after": spread(nums(runs.map((r) => r.afterMs))),
362
- "run: delivery": spread(nums(of("run").map((r) => r.deliverMs))),
363
- "shot": spread(nums(shots.map((s) => s.ms)))
364
- };
365
- const outcomes = {};
366
- for (const r of runs) for (const m of r.members ?? []) outcomes[m.outcome ?? "unknown"] = (outcomes[m.outcome ?? "unknown"] ?? 0) + 1;
367
- return {
368
- steps,
369
- outcomes,
370
- problems: [
371
- ...of("run").filter((r) => r.failure).map((r) => ({
372
- ts: r.ts,
373
- what: `run ${String(r.batch).slice(0, 8)} ${r.redelivered ? "could not post its replies" : `failed: ${r.failure}`}`
374
- })),
375
- ...shots.filter((s) => s.outcome && s.outcome !== "ok").map((s) => ({
376
- ts: s.ts,
377
- what: `shot ${s.frame ?? "?"}: ${s.outcome}${s.recaptures ? ` after ${s.recaptures} retakes` : ""}`
378
- })),
379
- ...caps.filter((c) => c.pictures?.late || c.pictures?.failed).map((c) => ({
380
- ts: c.ts,
381
- what: `capture ${c.capture}: ${c.pictures.late ?? 0} picture(s) too late, ${c.pictures.failed ?? 0} failed`
382
- })),
383
- ...of("name").filter((n) => !n.ok).map((n) => ({
384
- ts: n.ts,
385
- what: `naming ${n.capture} gave no name`
386
- })),
387
- ...of("dropped").map((d) => ({
388
- ts: d.ts,
389
- what: `${d.count} event(s) dropped (the log was busy)`
390
- }))
391
- ].sort((a, b) => b.ts - a.ts).slice(0, 10),
392
- retakes: shots.reduce((n, s) => n + (s.recaptures ?? 0), 0)
393
- };
394
- }
395
- function jamPerf(root, opts) {
396
- const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 1440;
397
- const since = Date.now() - minutes * 6e4;
398
- const { events, first } = readJam(root, since);
399
- const sum = jamSummary(events);
400
- const partial = first !== void 0 && first > since;
401
- if (opts.json) {
402
- console.log(JSON.stringify({
403
- minutes,
404
- ...partial ? { startsAt: first } : {},
405
- ...sum
406
- }, null, 2));
407
- return;
408
- }
409
- const span = minutes >= 120 ? `${Math.round(minutes / 60)} h` : `${minutes} min`;
410
- console.log(`Jam timings, last ${span} - design/.local/perf/jam.jsonl${partial ? ` (the log starts ${new Date(first).toLocaleString()})` : ""}`);
411
- if (!events.length) {
412
- console.log("\nnothing yet - captures, runs and shots log here as they happen");
413
- return;
414
- }
415
- console.log("");
416
- const pad = (s, n) => s + " ".repeat(Math.max(1, n - s.length));
417
- console.log(` ${pad("step", 24)}${pad("count", 7)}${pad("median", 9)}${pad("p90", 9)}max`);
418
- const f = (v) => v === void 0 ? "-" : v >= 1e4 ? `${(v / 1e3).toFixed(0)} s` : v >= 1e3 ? `${(v / 1e3).toFixed(1)} s` : `${v} ms`;
419
- for (const [name, x] of Object.entries(sum.steps)) if (x.n) console.log(` ${pad(name, 24)}${pad(String(x.n), 7)}${pad(f(x.median), 9)}${pad(f(x.p90), 9)}${f(x.max)}`);
420
- const out = Object.entries(sum.outcomes);
421
- if (out.length) console.log(`\nruns by outcome: ${out.map(([k, n]) => `${n} ${k}`).join(", ")}`);
422
- if (sum.retakes) console.log(`pictures taken again (a stale surface): ${sum.retakes}`);
423
- if (sum.problems.length) {
424
- console.log("\nlately");
425
- for (const p of sum.problems) console.log(` ${new Date(p.ts).toLocaleTimeString()} ${p.what}`);
426
- }
427
- }
428
- //#endregion
429
- export { perfCommand };
@@ -1,242 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
- import { mkdirSync, readFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { appendFile, readFile, stat, writeFile } from "node:fs/promises";
5
- //#region src/server/perf-jam.ts
6
- /**
7
- * Jam timings (0.26.1, spec 27a Part D): one JSON line per event in design/.local/perf/jam.jsonl - local, never
8
- * committed, never published, never sent. `npx marver perf --jam` reads it back.
9
- *
10
- * Numbers and fixed codes only. Every event is rebuilt from an allowlist: opaque ids, frame ids, enums, bounded
11
- * integers - no words, notes, prompts, replies, titles, names, timelines or free-text errors (a failure is a code).
12
- * Writes are buffered and appended by one serialized writer off the hot path; past 1,000 events or 1 MB waiting,
13
- * new events are dropped and counted (the count written when the writer catches up). A write that fails changes
14
- * nothing for the operation it measured.
15
- */
16
- var perf_jam_exports = /* @__PURE__ */ __exportAll({
17
- FAILURES: () => FAILURES,
18
- KINDS: () => KINDS,
19
- RUN_OUTCOMES: () => RUN_OUTCOMES,
20
- SHOT_OUTCOMES: () => SHOT_OUTCOMES,
21
- cleanJamEvent: () => cleanJamEvent,
22
- jamLog: () => jamLog,
23
- jamSeams: () => jamSeams,
24
- logJam: () => logJam,
25
- readJam: () => readJam
26
- });
27
- const jamLog = (root) => join(root, "design", ".local", "perf", "jam.jsonl");
28
- const MAX_FILE = 2e6;
29
- /** A test seam: how a batch of lines is appended (to hold an append open). Never set outside tests. */
30
- const jamSeams = {};
31
- const MAX_EVENTS = 1e3;
32
- const MAX_BYTES = 1e6;
33
- const CAPTURE = /^cap-\d{10,16}-[a-z0-9]{4,12}$/;
34
- const BATCH = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
35
- const FRAME = /^[a-z0-9][\w-]{0,79}(\/[a-z0-9][\w-]{0,79}){1,3}$/i;
36
- const capId = (v) => typeof v === "string" && CAPTURE.test(v) ? v : void 0;
37
- const batchId = (v) => typeof v === "string" && BATCH.test(v) ? v : void 0;
38
- const frameId = (v) => typeof v === "string" && FRAME.test(v) ? v : void 0;
39
- const ms = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v < 1e9 ? Math.round(v) : void 0;
40
- const count = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 && v < 1e6 ? v : void 0;
41
- const oneOf = (v, set) => typeof v === "string" && set.includes(v) ? v : void 0;
42
- const msList = (v, max = 50) => Array.isArray(v) ? v.slice(0, max).map(ms).filter((x) => x !== void 0) : void 0;
43
- const prune = (o) => Object.fromEntries(Object.entries(o).filter(([, x]) => x !== void 0 && !(Array.isArray(x) && !x.length)));
44
- const RUN_OUTCOMES = [
45
- "review",
46
- "done",
47
- "asks",
48
- "failed"
49
- ];
50
- const FAILURES = [
51
- "agent",
52
- "changed",
53
- "delivery",
54
- "stopped",
55
- "other"
56
- ];
57
- const SHOT_OUTCOMES = [
58
- "ok",
59
- "unchecked",
60
- "stale",
61
- "timeout",
62
- "error"
63
- ];
64
- const KINDS = [
65
- "capture",
66
- "comment",
67
- "wrapup"
68
- ];
69
- /** An event rebuilt from the allowlist, or null. */
70
- function cleanJamEvent(raw) {
71
- switch (raw.kind) {
72
- case "capture": {
73
- const p = raw.pictures && typeof raw.pictures === "object" ? raw.pictures : {};
74
- const capture = capId(raw.capture);
75
- if (!capture) return null;
76
- return prune({
77
- kind: "capture",
78
- capture,
79
- sealMs: ms(raw.sealMs),
80
- wordsWaitMs: ms(raw.wordsWaitMs),
81
- pictures: prune({
82
- count: count(p.count),
83
- ms: msList(p.ms),
84
- late: count(p.late),
85
- failed: count(p.failed)
86
- }),
87
- interrupted: raw.interrupted === true ? true : void 0
88
- });
89
- }
90
- case "upload": {
91
- const capture = capId(raw.capture);
92
- return capture ? prune({
93
- kind: "upload",
94
- capture,
95
- ms: ms(raw.ms),
96
- tries: count(raw.tries)
97
- }) : null;
98
- }
99
- case "name": {
100
- const capture = capId(raw.capture);
101
- return capture ? prune({
102
- kind: "name",
103
- capture,
104
- ms: ms(raw.ms),
105
- ok: raw.ok === true
106
- }) : null;
107
- }
108
- case "words": return prune({
109
- kind: "words",
110
- audioMs: ms(raw.audioMs),
111
- waitMs: ms(raw.waitMs),
112
- decodeMs: ms(raw.decodeMs),
113
- backlogMs: ms(raw.backlogMs),
114
- modelLoadMs: ms(raw.modelLoadMs)
115
- });
116
- case "run": {
117
- const batch = batchId(raw.batch);
118
- if (!batch) return null;
119
- const members = Array.isArray(raw.members) ? raw.members.slice(0, 50).map((m) => prune({
120
- kind: oneOf(m?.kind, KINDS),
121
- waitMs: ms(m?.waitMs),
122
- outcome: oneOf(m?.outcome, RUN_OUTCOMES)
123
- })) : void 0;
124
- return prune({
125
- kind: "run",
126
- batch,
127
- members,
128
- beforeMs: ms(raw.beforeMs),
129
- agentMs: msList(raw.agentMs, 10),
130
- afterMs: ms(raw.afterMs),
131
- deliverMs: ms(raw.deliverMs),
132
- attempts: count(raw.attempts),
133
- failure: oneOf(raw.failure, FAILURES),
134
- redelivered: raw.redelivered === true ? true : void 0
135
- });
136
- }
137
- case "shot": return prune({
138
- kind: "shot",
139
- frame: frameId(raw.frame),
140
- scale: count(raw.scale),
141
- ms: ms(raw.ms),
142
- recaptures: count(raw.recaptures),
143
- outcome: oneOf(raw.outcome, SHOT_OUTCOMES)
144
- });
145
- default: return null;
146
- }
147
- }
148
- const writers = /* @__PURE__ */ new Map();
149
- /** Captures already logged, per root: a resent capture event is written once. */
150
- const seenCaptures = /* @__PURE__ */ new Map();
151
- /** Log one Jam event (best effort, never in the way): rebuilt from the allowlist, buffered, appended in order. */
152
- function logJam(root, raw) {
153
- try {
154
- const ev = cleanJamEvent(raw);
155
- if (!ev) return;
156
- if (ev.kind === "capture") {
157
- const seen = seenCaptures.get(root) ?? /* @__PURE__ */ new Set();
158
- seenCaptures.set(root, seen);
159
- if (seen.has(ev.capture)) return;
160
- seen.add(ev.capture);
161
- if (seen.size > 5e3) seen.delete(seen.values().next().value);
162
- }
163
- const line = JSON.stringify({
164
- v: 1,
165
- ts: Date.now(),
166
- ...ev
167
- }) + "\n";
168
- const w = writers.get(root) ?? {
169
- queue: [],
170
- bytes: 0,
171
- inFlight: 0,
172
- dropped: 0,
173
- busy: false,
174
- writes: 0
175
- };
176
- writers.set(root, w);
177
- if (w.queue.length + w.inFlight >= MAX_EVENTS || w.bytes + line.length > MAX_BYTES) {
178
- w.dropped++;
179
- return;
180
- }
181
- w.queue.push(line);
182
- w.bytes += line.length;
183
- if (!w.busy) {
184
- w.busy = true;
185
- w.draining = new Promise((done) => setImmediate(() => void drain(root, w).finally(done)));
186
- }
187
- } catch {}
188
- }
189
- async function drain(root, w) {
190
- const file = jamLog(root);
191
- try {
192
- mkdirSync(join(file, ".."), {
193
- recursive: true,
194
- mode: 448
195
- });
196
- } catch {}
197
- while (w.queue.length || w.dropped) {
198
- const lines = w.queue.splice(0);
199
- const held = lines.reduce((n, l) => n + l.length, 0);
200
- w.inFlight = lines.length;
201
- if (w.dropped) {
202
- lines.push(JSON.stringify({
203
- v: 1,
204
- ts: Date.now(),
205
- kind: "dropped",
206
- count: w.dropped
207
- }) + "\n");
208
- w.dropped = 0;
209
- }
210
- try {
211
- await (jamSeams.append ?? ((f, d) => appendFile(f, d, { mode: 384 })))(file, lines.join(""));
212
- if (++w.writes % 50 === 0 && (await stat(file)).size > MAX_FILE) {
213
- const all = (await readFile(file, "utf8")).split("\n");
214
- await writeFile(file, all.slice(Math.floor(all.length / 2)).join("\n"));
215
- }
216
- } catch {}
217
- w.inFlight = 0;
218
- w.bytes = Math.max(0, w.bytes - held);
219
- }
220
- w.busy = false;
221
- }
222
- /** The log read back from `since` (epoch ms): malformed lines skipped. */
223
- function readJam(root, since = 0) {
224
- try {
225
- const all = readFileSync(jamLog(root), "utf8").split("\n").flatMap((l) => {
226
- try {
227
- const e = JSON.parse(l);
228
- return e && typeof e.ts === "number" ? [e] : [];
229
- } catch {
230
- return [];
231
- }
232
- });
233
- return {
234
- events: all.filter((e) => e.ts >= since),
235
- ...all.length ? { first: all[0].ts } : {}
236
- };
237
- } catch {
238
- return { events: [] };
239
- }
240
- }
241
- //#endregion
242
- export { perf_jam_exports as n, readJam as r, logJam as t };