@marver-design/marver 0.29.0 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +2 -1
  3. package/dist/{anchor-check-DhlpKl2K.mjs → anchor-check-Bv4o-R2T.mjs} +1 -1
  4. package/dist/{build-CWbrb2bl.mjs → build-zWGXSzly.mjs} +5 -4
  5. package/dist/cli.mjs +5 -5
  6. package/dist/{daemon-Sc_z8gT6.mjs → daemon-CChgWJNq.mjs} +2 -2
  7. package/dist/{dev-DWBKQhxf.mjs → dev-DOgIITpT.mjs} +8 -8
  8. package/dist/{perf-Denssrko.mjs → perf-6MOTHxay.mjs} +710 -99
  9. package/dist/perf-BCxAo0IS.mjs +1743 -0
  10. package/dist/{plugin-DqoZB-D6.mjs → plugin-CFWBcAba.mjs} +928 -539
  11. package/dist/{poster-CrsjqhY4.mjs → poster-DPPpQiva.mjs} +1 -1
  12. package/dist/{publish-bakes-DW-NDgU2.mjs → publish-bakes-_Zx8crP3.mjs} +2 -2
  13. package/dist/{recover-GtJ9UDAB.mjs → recover-mDUVsnPd.mjs} +1 -1
  14. package/dist/{shot-T04Ixrvq.mjs → shot-d4h_hJi9.mjs} +3 -3
  15. package/docs/app.md +194 -0
  16. package/docs/performance.md +100 -19
  17. package/package.json +1 -1
  18. package/src/client/frame-host/bridge.js +17 -8
  19. package/src/client/frame-host/inplace.ts +124 -0
  20. package/src/client/frame-host/inspect.d.ts +1 -0
  21. package/src/client/frame-host/inspect.js +13 -4
  22. package/src/client/frame-host/main.tsx +12 -3
  23. package/src/client/frame-host/messages.ts +85 -0
  24. package/src/client/frame-host/signals.d.ts +15 -0
  25. package/src/client/frame-host/signals.js +219 -0
  26. package/src/client/recorder-level.ts +41 -0
  27. package/src/client/shell/App.tsx +158 -88
  28. package/src/client/shell/BoardList.tsx +103 -48
  29. package/src/client/shell/Comments.tsx +66 -42
  30. package/src/client/shell/ContextMenu.tsx +3 -2
  31. package/src/client/shell/JamSurface.tsx +116 -71
  32. package/src/client/shell/LockedApp.tsx +19 -3
  33. package/src/client/shell/Play.tsx +94 -58
  34. package/src/client/shell/StatusPicker.tsx +19 -9
  35. package/src/client/shell/Toolbar.tsx +15 -7
  36. package/src/client/shell/api.ts +18 -4
  37. package/src/client/shell/app-bridge.ts +12 -6
  38. package/src/client/shell/app-perf.ts +31 -1
  39. package/src/client/shell/canvas/Canvas.tsx +17 -6
  40. package/src/client/shell/canvas/FrameNode.tsx +25 -12
  41. package/src/client/shell/canvas/Sticky.tsx +4 -2
  42. package/src/client/shell/canvas/ctl.ts +2 -0
  43. package/src/client/shell/canvas/ready-watch.ts +4 -0
  44. package/src/client/shell/canvas/sleep.ts +2 -0
  45. package/src/client/shell/canvas/updates.ts +13 -6
  46. package/src/client/shell/commands.ts +765 -0
  47. package/src/client/shell/comments-store.ts +42 -27
  48. package/src/client/shell/goto.ts +11 -6
  49. package/src/client/shell/jam-keys.ts +141 -75
  50. package/src/client/shell/jam-lane.tsx +19 -12
  51. package/src/client/shell/jam-panel.tsx +61 -48
  52. package/src/client/shell/jam-session.tsx +41 -37
  53. package/src/client/shell/jam-state.ts +9 -1
  54. package/src/client/shell/jam-surface-parts.tsx +8 -6
  55. package/src/client/shell/jam-ui.tsx +9 -6
  56. package/src/client/shell/jam-voice.ts +4 -2
  57. package/src/client/shell/main.tsx +7 -1
  58. package/src/client/shell/marks-ui.tsx +11 -0
  59. package/src/client/shell/perf.ts +51 -5
  60. package/src/client/shell/recorder-core.ts +4 -1
  61. package/src/client/shell/recorder-hmr.ts +36 -0
  62. package/src/client/shell/recorder-reloads.ts +264 -0
  63. package/src/client/shell/recorder-seams.ts +116 -0
  64. package/src/client/shell/recorder-self.ts +73 -0
  65. package/src/client/shell/recorder-signals-core.ts +139 -0
  66. package/src/client/shell/recorder-signals.ts +485 -0
  67. package/src/client/shell/recorder.ts +118 -43
  68. package/src/client/shell/store.ts +112 -32
  69. package/src/client/shell/whiteout-probes.ts +3 -1
  70. package/src/client/stage/main.tsx +10 -5
  71. package/src/shared/app-api.ts +28 -6
  72. package/src/shared/app-perf.ts +99 -6
  73. package/src/shared/app-report.ts +586 -0
  74. package/src/shared/perf-records.ts +445 -0
  75. package/src/shared/perf-run.ts +6 -2
  76. package/dist/perf-jam-CLkERSHo.mjs +0 -642
@@ -2,63 +2,10 @@ import { a as checkBoardsDir, c as listBoardFiles, r as boardFields } from "./bo
2
2
  import { f as isBoardName, p as labelOf } from "./board-tree-BXR8dw4b.mjs";
3
3
  import { i as readDevInfo } from "./work-DJxH7cCX.mjs";
4
4
  import { i as marverHome, v as workspaceId } from "./slots-Dn4Onb0V.mjs";
5
- import { d as readRuns, l as readPage, r as readJam, u as readReloads } from "./perf-jam-CLkERSHo.mjs";
6
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
5
+ import { a as readPage, g as parseAppLine, h as APP_LOG, i as perfDir, m as appLogFiles, o as readReloads, p as readJam, s as readRuns } from "./perf-BCxAo0IS.mjs";
6
+ import { closeSync, existsSync, fstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync } from "node:fs";
7
7
  import { join } from "node:path";
8
8
  import { homedir } from "node:os";
9
- //#region src/shared/app-perf.ts
10
- /** The file each flavour writes, under `<MARVER_HOME>/perf/`. */
11
- const APP_LOG = {
12
- release: "app.jsonl",
13
- dev: "app-dev.jsonl"
14
- };
15
- const KINDS = /* @__PURE__ */ new Set([
16
- "start",
17
- "sample",
18
- "agx",
19
- "gone",
20
- "child-gone",
21
- "gpu-restart",
22
- "unresponsive",
23
- "responsive",
24
- "gpu",
25
- "power",
26
- "tab",
27
- "shown",
28
- "pressure",
29
- "unload",
30
- "unload-skip",
31
- "unload-effect",
32
- "reopen",
33
- "cover",
34
- "flash",
35
- "whiteout-candidate",
36
- "dropped",
37
- "main-error"
38
- ]);
39
- const isInt = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
40
- /**
41
- * One line of app.jsonl, or null (A3.5): the envelope checked - `v: 1`, a finite `ts`, a known `kind`, an `app` id,
42
- * a whole `seq`, a `flavour`, a `machine` hash or null. The body is the writer's and is passed on as it is: a
43
- * reader takes the fields it knows. A line without the envelope (app 0.1's main-error lines) is null.
44
- */
45
- function parseAppLine(line) {
46
- let r;
47
- try {
48
- r = JSON.parse(line);
49
- } catch {
50
- return null;
51
- }
52
- if (!r || typeof r !== "object" || Array.isArray(r)) return null;
53
- const o = r;
54
- if (o.v !== 1 || typeof o.ts !== "number" || !Number.isFinite(o.ts)) return null;
55
- if (typeof o.kind !== "string" || !KINDS.has(o.kind)) return null;
56
- if (typeof o.app !== "string" || !/^[0-9a-f]{12}$/.test(o.app) || !isInt(o.seq)) return null;
57
- if (o.flavour !== "release" && o.flavour !== "dev") return null;
58
- if (o.machine !== null && (typeof o.machine !== "string" || !/^[0-9a-f]{16}$/.test(o.machine))) return null;
59
- return o;
60
- }
61
- //#endregion
62
9
  //#region src/cli/perf-app.ts
63
10
  /**
64
11
  * `marver perf --crashes`, `--flashes`, `--machine` and `--runs` (spec 28 A3.5, A3.8 #22, #23): the app's records
@@ -89,25 +36,38 @@ function parseAppLine(line) {
89
36
  * `gpu-restart`, `gpu`), whatever a line holds: a renderer's end or a utility process's is not one. A flash's pressure
90
37
  * is the reading at the mark only when it was at most 10 s old then (two samples); older, it is unknown.
91
38
  */
92
- /** Both flavours' app records from `since` (epoch ms), in file order per flavour; a line without the envelope skipped; a line written twice (its launch, flavour and seq) once. */
39
+ /**
40
+ * Both flavours' app records from `since` (epoch ms): each flavour's `app.jsonl` and, from app 1.0.1, `samples.jsonl`,
41
+ * every segment of both (spec 30 #42, #44) merged by time and `seq`; a line without the envelope skipped; a line
42
+ * written twice (its launch, flavour and seq) once. A 1.0.0 log - samples in `app.jsonl`, one file - reads the same. A
43
+ * file the writer closed while these were read - renamed under a list already made - is read too; its lines read before
44
+ * the rename count once, by that same identity.
45
+ */
93
46
  function readAppLog(home, since = 0) {
94
47
  const out = [];
95
48
  const seen = /* @__PURE__ */ new Set();
96
49
  for (const f of Object.keys(APP_LOG)) {
97
- let text = "";
98
- try {
99
- text = readFileSync(join(home, "perf", APP_LOG[f]), "utf8");
100
- } catch {
101
- continue;
102
- }
103
- for (const l of text.split("\n")) {
104
- const r = l ? parseAppLine(l) : null;
105
- if (!r || r.ts < since) continue;
106
- const k = `${r.flavour}/${r.app}/${r.seq}`;
107
- if (seen.has(k)) continue;
108
- seen.add(k);
109
- out.push(r);
50
+ const mine = [];
51
+ const done = /* @__PURE__ */ new Set();
52
+ for (let paths = appLogFiles(join(home, "perf"), f, since); paths.length; paths = appLogFiles(join(home, "perf"), f, since).filter((p) => !done.has(p))) for (const path of paths) {
53
+ done.add(path);
54
+ let text = "";
55
+ try {
56
+ text = readFileSync(path, "utf8");
57
+ } catch {
58
+ continue;
59
+ }
60
+ for (const l of text.split("\n")) {
61
+ const r = l ? parseAppLine(l) : null;
62
+ if (!r || r.ts < since) continue;
63
+ const k = `${r.flavour}/${r.app}/${r.seq}`;
64
+ if (seen.has(k)) continue;
65
+ seen.add(k);
66
+ mine.push(r);
67
+ }
110
68
  }
69
+ mine.sort((a, b) => a.ts - b.ts || a.seq - b.seq);
70
+ for (const r of mine) out.push(r);
111
71
  }
112
72
  return out;
113
73
  }
@@ -368,6 +328,7 @@ function flashesSummary(app, page, workspaces, o = {}) {
368
328
  skipped: x.skipped,
369
329
  inconclusive: x.inconclusive,
370
330
  gpuEvents: Array.isArray(x.gpuEvents) ? x.gpuEvents.filter(isGpuProcessEvent).length : 0,
331
+ ...Array.isArray(x.why) ? { why: x.why } : {},
371
332
  ...momentOf(x, page, observedAt[0] ?? r.ts)
372
333
  });
373
334
  }
@@ -436,7 +397,7 @@ function machineSummary(home, app, runs) {
436
397
  }))
437
398
  };
438
399
  }
439
- /** `--runs`: comparisons inside one cohort (script, board, chrome, flags, machine, power, slow, bakes), by inputs; `against` two runs of one cohort. */
400
+ /** `--runs`: comparisons inside one cohort (script, board, chrome, flags, machine, power, slow, bakes, the recorder's level), by inputs; `against` two runs of one cohort. */
440
401
  function runsSummary(runs, o = {}) {
441
402
  const ordered = [...runs].sort((a, b) => a.ts - b.ts);
442
403
  const comparable = (r) => r.valid && !r.overlapped;
@@ -483,7 +444,7 @@ function runsSummary(runs, o = {}) {
483
444
  within10: within(base, latest)
484
445
  } : {
485
446
  run: base.run,
486
- error: !comparable(base) ? `run ${base.run} is ${base.valid ? "overlapped" : `invalid (${base.invalidReason})`}: never compared` : "no later valid run of its cohort (script, board, Chrome, flags, machine, power, --slow, bakes) - pass the earlier run"
447
+ error: !comparable(base) ? `run ${base.run} is ${base.valid ? "overlapped" : `invalid (${base.invalidReason})`}: never compared` : "no later valid run of its cohort (script, board, Chrome, flags, machine, power, --slow, bakes, --recorder) - pass the earlier run"
487
448
  };
488
449
  }
489
450
  }
@@ -498,7 +459,8 @@ const cohortOf = (r) => ({
498
459
  machine: r.machine,
499
460
  power: r.power,
500
461
  slow: r.slow,
501
- bakes: r.bakes
462
+ bakes: r.bakes,
463
+ recorder: r.recorder
502
464
  });
503
465
  const cohortKey = (r) => JSON.stringify(cohortOf(r));
504
466
  const brief = (r) => ({
@@ -530,6 +492,586 @@ function within(a, b, pct = 10) {
530
492
  const ok = (x, y) => x !== null && y !== null && Math.abs(y - x) <= Math.max(Math.abs(x), 1) * pct / 100;
531
493
  return ok(a.loadToSettledMs, b.loadToSettledMs) && ok(a.p95, b.p95);
532
494
  }
495
+ /** What the lifecycle lines prove: did the page or the launch behind this start end after it? */
496
+ function endedAfter(lifecycle) {
497
+ const gone = /* @__PURE__ */ new Set();
498
+ /** a page, and one app line that names it: its launch */
499
+ const held = /* @__PURE__ */ new Map();
500
+ const starts = [];
501
+ for (const r of lifecycle) {
502
+ if (r.kind === "shell-boot" && typeof r.prev === "string") gone.add(r.prev);
503
+ if (typeof r.app !== "string") continue;
504
+ if (r.kind === "start") starts.push(r);
505
+ const page = r.page ?? r.firstCanvas?.page;
506
+ if (typeof page !== "string") continue;
507
+ held.set(page, r);
508
+ if (r.kind === "gone") gone.add(page);
509
+ }
510
+ const launchedAfter = (of, ts) => starts.some((s) => s.app !== of.app && s.flavour === of.flavour && s.ts > ts);
511
+ return (start) => {
512
+ if (typeof start.app === "string") return launchedAfter(start, start.ts);
513
+ if (gone.has(start.page)) return true;
514
+ const launch = held.get(start.page);
515
+ return !!launch && launchedAfter(launch, start.ts);
516
+ };
517
+ }
518
+ /**
519
+ * Each command's last word, once: a `late` second end does not count against it; the first end says what was seen by
520
+ * its deadline. `lifecycle`: the lines that say a page or a launch ended, beside `records` when they live elsewhere.
521
+ */
522
+ function commandsSummary(records, now = Date.now(), lifecycle = records) {
523
+ const failed = {}, unobserved = {};
524
+ const ended = /* @__PURE__ */ new Set();
525
+ const started = /* @__PURE__ */ new Map();
526
+ const seen = /* @__PURE__ */ new Set();
527
+ const add = (o, k) => {
528
+ const c = typeof k === "string" && k ? k : "unknown";
529
+ o[c] = (o[c] ?? 0) + 1;
530
+ };
531
+ for (const r of records) {
532
+ if (r.kind !== "cmd" || typeof r.id !== "string") continue;
533
+ if (r.phase === "start") {
534
+ started.set(r.id, r);
535
+ continue;
536
+ }
537
+ if (r.late) {
538
+ ended.add(r.id);
539
+ continue;
540
+ }
541
+ ended.add(r.id);
542
+ if (seen.has(r.id)) continue;
543
+ seen.add(r.id);
544
+ if (r.outcome === "failed") add(failed, r.why);
545
+ else if (r.outcome === "unobserved") add(unobserved, r.why);
546
+ }
547
+ const isOver = endedAfter(lifecycle);
548
+ let interrupted = 0, unmatched = 0;
549
+ for (const [id, start] of started) {
550
+ if (ended.has(id)) continue;
551
+ if (isOver(start)) interrupted++;
552
+ else if (now - start.ts > 13e4) unmatched++;
553
+ }
554
+ return {
555
+ failed,
556
+ unobserved,
557
+ interrupted,
558
+ unmatched
559
+ };
560
+ }
561
+ //#endregion
562
+ //#region src/cli/perf-all.ts
563
+ /**
564
+ * `marver perf --all` (spec 30 R10 #46): every canvas the Mac knows, one summary, read-only and with no repo needed:
565
+ * `~/.marver/running/*.json` (`root`, `ws`, `name`) plus the app's `state/recent.json` (`root`, `workspace`, `name`),
566
+ * deduplicated by real path; a root with no records says so. Per canvas over `--days` (14 by default) the 4 Nov
567
+ * baseline's columns - loads, after an edit, settled, all-ready p50/p90/max, frames max, heap max, worst gesture p95 -
568
+ * then edit to last redraw, ambiguous and unknown full reloads, re-render totals (React's render work only), the
569
+ * longest theme switch, comments mode's shown p50, errors by source, commands failed or unobserved by code. Then the
570
+ * app's: launches, crashes, hangs, flashes, candidates by `why`, uncovered window time. `--json` emits the same. It
571
+ * replaces agg-loads.mjs, with its quantile: the value at `floor(p * n)` of the sorted list.
572
+ *
573
+ * Every page and reload record is read once by `(page, seq)` (#7): a retry past the server's window can write one twice.
574
+ */
575
+ /** The canvases this Mac knows (#46): those running, then those the app remembers; one per real path, the running one's name kept. */
576
+ function knownCanvases(home = marverHome()) {
577
+ const seen = /* @__PURE__ */ new Map();
578
+ const add = (root, name, ws, running) => {
579
+ if (typeof root !== "string" || !root) return;
580
+ let real = root;
581
+ try {
582
+ real = realpathSync(root);
583
+ } catch {}
584
+ const had = seen.get(real);
585
+ if (had) {
586
+ had.running ||= running;
587
+ had.ws ??= typeof ws === "string" ? ws : void 0;
588
+ return;
589
+ }
590
+ seen.set(real, {
591
+ root: real,
592
+ name: typeof name === "string" && name ? name : real.split("/").at(-1) ?? real,
593
+ ...typeof ws === "string" ? { ws } : {},
594
+ running
595
+ });
596
+ };
597
+ const read = (f) => {
598
+ try {
599
+ return JSON.parse(readFileSync(f, "utf8"));
600
+ } catch {
601
+ return null;
602
+ }
603
+ };
604
+ const running = join(home, "running");
605
+ let names = [];
606
+ try {
607
+ names = readdirSync(running);
608
+ } catch {}
609
+ for (const n of names.filter((x) => x.endsWith(".json")).sort()) {
610
+ const e = read(join(running, n));
611
+ if (e) add(e.root, e.name, e.ws, true);
612
+ }
613
+ const recent = read(join(home, "state", "recent.json"));
614
+ if (Array.isArray(recent?.canvases)) for (const e of recent.canvases) add(e?.root, e?.name, e?.workspace, false);
615
+ return [...seen.values()];
616
+ }
617
+ /** The baseline's quantile (agg-loads.mjs): the value at `floor(p * n)` of the sorted list. */
618
+ const quantile = (xs, p) => {
619
+ if (!xs.length) return null;
620
+ const s = [...xs].sort((a, b) => a - b);
621
+ return s[Math.min(s.length - 1, Math.floor(p * s.length))];
622
+ };
623
+ const nums = (xs) => xs.filter((x) => typeof x === "number" && Number.isFinite(x));
624
+ const threes = (xs) => ({
625
+ p50: quantile(xs, .5),
626
+ p90: quantile(xs, .9),
627
+ max: quantile(xs, 1)
628
+ });
629
+ const twos = (xs) => ({
630
+ p50: quantile(xs, .5),
631
+ max: quantile(xs, 1)
632
+ });
633
+ /**
634
+ * Edit to last redraw (#2): a change, the revisions that carried it (`invalidate`, in parts: many to many), and the
635
+ * latest `ready` that names one of those revisions. From the watcher's event: the change line's `at`; a line from before
636
+ * it, its own time less its flight, else its `hmrTs`. A change no ready names is not in it.
637
+ */
638
+ function editToRedraw(reloads) {
639
+ const at = /* @__PURE__ */ new Map();
640
+ const revisions = /* @__PURE__ */ new Map();
641
+ for (const r of reloads) {
642
+ if (r.kind === "change" && typeof r.change === "string") at.set(r.change, typeof r.at === "number" ? r.at : typeof r.flightMs === "number" ? r.ts - r.flightMs : typeof r.hmrTs === "number" ? r.hmrTs : r.ts);
643
+ if ((r.kind === "invalidate" || r.kind === "invalidate-ids") && typeof r.revision === "string" && Array.isArray(r.changes)) for (const c of r.changes) {
644
+ if (typeof c !== "string") continue;
645
+ let s = revisions.get(c);
646
+ if (!s) revisions.set(c, s = /* @__PURE__ */ new Set());
647
+ s.add(r.revision);
648
+ }
649
+ }
650
+ const lastReady = /* @__PURE__ */ new Map();
651
+ for (const r of reloads) {
652
+ if (r.kind !== "ready" || !Array.isArray(r.revisions) || typeof r.ts !== "number") continue;
653
+ for (const v of r.revisions) if (typeof v === "string" && r.ts > (lastReady.get(v) ?? -Infinity)) lastReady.set(v, r.ts);
654
+ }
655
+ const out = [];
656
+ for (const [c, t0] of at) {
657
+ const last = Math.max(...[...revisions.get(c) ?? []].map((v) => lastReady.get(v) ?? -Infinity), -Infinity);
658
+ if (last !== -Infinity && last >= t0) out.push(last - t0);
659
+ }
660
+ return out;
661
+ }
662
+ /** One canvas's figures from what it recorded since `since`; `app`: the app's records, for what they say of its pages. */
663
+ function canvasSummary(c, since, now = Date.now(), app = []) {
664
+ const page = dedupeSeq(ownLoads(readPage(c.root, since)).records);
665
+ const reloads = dedupeSeq(readReloads(c.root, since));
666
+ const loads = loadsSummary(page);
667
+ const settled = loads.filter((l) => l.state === "settled");
668
+ const fulls = reloads.filter((r) => r.kind === "full-reload");
669
+ const renders = {
670
+ commits: 0,
671
+ ms: 0,
672
+ inGesture: 0
673
+ };
674
+ for (const r of page) if (r.kind === "renders" && Array.isArray(r.rows)) for (const x of r.rows) {
675
+ renders.commits += Number(x?.commits) || 0;
676
+ renders.ms += Number(x?.ms) || 0;
677
+ renders.inGesture += Number(x?.inGesture) || 0;
678
+ }
679
+ const errors = {};
680
+ for (const r of page) if (r.kind === "error") {
681
+ const k = String(r.source ?? "unknown");
682
+ errors[k] = (errors[k] ?? 0) + 1;
683
+ }
684
+ const edits = editToRedraw(reloads);
685
+ return {
686
+ root: c.root,
687
+ name: c.name,
688
+ ...c.ws ? { ws: c.ws } : {},
689
+ running: c.running,
690
+ records: page.length > 0 || reloads.length > 0,
691
+ loads: loads.length,
692
+ afterEdit: loads.filter((l) => l.cause === "disk-reload").length,
693
+ settled: settled.length,
694
+ allReadyMs: threes(nums(settled.map((l) => l.allReadyMs))),
695
+ framesMax: quantile(nums(loads.map((l) => l.frames)), 1),
696
+ heapMaxMB: quantile(nums(loads.map((l) => l.weight?.heapMB)), 1),
697
+ gestureWorstP95: twos(nums(loads.map((l) => l.gestures?.worstP95))),
698
+ editToRedrawMs: {
699
+ n: edits.length,
700
+ p50: quantile(edits, .5),
701
+ p90: quantile(edits, .9)
702
+ },
703
+ fullReloads: {
704
+ ambiguous: fulls.filter((r) => r.by === "ambiguous").length,
705
+ unknown: fulls.filter((r) => r.by === "unknown").length
706
+ },
707
+ renders: {
708
+ commits: renders.commits,
709
+ ms: Math.round(renders.ms),
710
+ inGesture: renders.inGesture
711
+ },
712
+ themeMaxMs: quantile(nums(page.filter((r) => r.kind === "theme").map((r) => r.maxMs)), 1),
713
+ commentsShownP50Ms: quantile(nums(page.filter((r) => r.kind === "mode" && r.mode === "comments" && r.phase === "enter").map((r) => r.shownMs)), .5),
714
+ errors,
715
+ commands: commandsSummary(page, now, [...reloads, ...app]),
716
+ inplaceNoAfterUpdate: reloads.filter((r) => r.kind === "inplace" && r.noAfterUpdate === true).length,
717
+ retentionCap: [...page, ...reloads].filter((r) => r.kind === "dropped" && r.reason === "retention-cap").reduce((n, r) => n + (Number(r.n) || 0), 0)
718
+ };
719
+ }
720
+ /** The app's figures from `readAppLog`'s records. A crash is a canvas renderer's end that main did not ask for. */
721
+ function appSummary(app, now = Date.now()) {
722
+ const launches = app.filter((r) => r.kind === "launch");
723
+ const noCanvas = {};
724
+ for (const l of launches) if (!l.firstCanvas && typeof l.why === "string") noCanvas[l.why] = (noCanvas[l.why] ?? 0) + 1;
725
+ const candidates = {};
726
+ for (const r of app) {
727
+ if (r.kind !== "whiteout-candidate") continue;
728
+ const why = r.why;
729
+ for (const k of Array.isArray(why) && why.length ? why : ["gesture"]) candidates[String(k)] = (candidates[String(k)] ?? 0) + 1;
730
+ }
731
+ const uncoveredMs = {
732
+ stage: 0,
733
+ budget: 0,
734
+ hidden: 0
735
+ };
736
+ const capture = {
737
+ captures: 0,
738
+ captureMs: 0,
739
+ overrunMs: 0,
740
+ skipped: 0
741
+ };
742
+ for (const r of app) {
743
+ const w = r.kind === "sample" ? r.whiteout : null;
744
+ if (!w) continue;
745
+ for (const k of [
746
+ "stage",
747
+ "budget",
748
+ "hidden"
749
+ ]) uncoveredMs[k] += Number(w.uncoveredMs?.[k]) || 0;
750
+ for (const k of [
751
+ "captures",
752
+ "captureMs",
753
+ "overrunMs",
754
+ "skipped"
755
+ ]) capture[k] += Number(w[k]) || 0;
756
+ }
757
+ return {
758
+ records: app.length > 0,
759
+ launches: launches.length,
760
+ toFirstCanvasMs: twos(nums(launches.map((l) => l.firstCanvas?.uncoveredMs))),
761
+ noCanvas,
762
+ crashes: app.filter((r) => r.kind === "gone" && r.role === "canvas" && r.ours !== true).length,
763
+ hangs: app.filter((r) => r.kind === "unresponsive" && r.role === "canvas").length,
764
+ flashes: app.filter((r) => r.kind === "flash").length,
765
+ candidates,
766
+ uncoveredMs,
767
+ capture,
768
+ commands: commandsSummary(app, now)
769
+ };
770
+ }
771
+ function allSummary(o = {}) {
772
+ const days = Number(o.days) > 0 ? Math.min(90, Number(o.days)) : 14;
773
+ const now = o.now ?? Date.now();
774
+ const since = now - days * 864e5;
775
+ const home = o.home ?? marverHome();
776
+ const app = readAppLog(home, since);
777
+ return {
778
+ days,
779
+ canvases: knownCanvases(home).map((c) => canvasSummary(c, since, now, app)),
780
+ app: appSummary(app, now)
781
+ };
782
+ }
783
+ const s1 = (ms) => ms === null ? "-" : `${(ms / 1e3).toFixed(1)}`;
784
+ const dur = (ms) => ms === null ? "-" : ms >= 1e3 ? `${(ms / 1e3).toFixed(1)} s` : `${Math.round(ms)} ms`;
785
+ const tilde$1 = (p) => {
786
+ const h = homedir();
787
+ return p === h ? "~" : p.startsWith(h + "/") ? `~${p.slice(h.length)}` : p;
788
+ };
789
+ const list = (o) => Object.entries(o).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([k, n]) => `${k} ${n}`).join(", ");
790
+ const num1 = (v) => v === null ? "-" : String(Math.round(v * 10) / 10);
791
+ /** A command's lines: failed and unobserved by code, interrupted, and a start nothing explains. */
792
+ function commandsWords(c) {
793
+ return [
794
+ ...Object.keys(c.failed).length ? [`commands failed: ${list(c.failed)}`] : [],
795
+ ...Object.keys(c.unobserved).length ? [`unobserved: ${list(c.unobserved)}`] : [],
796
+ ...c.interrupted ? [`interrupted: ${c.interrupted}`] : [],
797
+ ...c.unmatched ? [`no end, nothing says why: ${c.unmatched}`] : []
798
+ ];
799
+ }
800
+ /** `marver perf --all`. */
801
+ function allPerf(opts) {
802
+ const sum = allSummary({ days: opts.days });
803
+ if (opts.json) {
804
+ console.log(JSON.stringify(sum, null, 2));
805
+ return;
806
+ }
807
+ const withRecords = sum.canvases.filter((c) => c.records).length;
808
+ console.log(`every canvas, last ${sum.days} days - ${sum.canvases.length} known, ${withRecords} with records`);
809
+ if (!sum.canvases.length) console.log("\nno canvas known yet - a canvas this Mac ran or the app opened is listed here");
810
+ for (const c of sum.canvases) {
811
+ console.log(`\n ${c.name} ${tilde$1(c.root)}${c.running ? "" : " (not running)"}`);
812
+ if (!c.records) {
813
+ console.log(existsSync(c.root) ? " no records in the window" : " no records: its folder is gone");
814
+ continue;
815
+ }
816
+ console.log(` loads ${c.loads} · after an edit ${c.afterEdit} · settled ${c.settled} · all ready ${s1(c.allReadyMs.p50)} / ${s1(c.allReadyMs.p90)} / ${s1(c.allReadyMs.max)} s · frames max ${c.framesMax ?? "-"} · heap max ${c.heapMaxMB === null ? "-" : `${Math.round(c.heapMaxMB)} MB`} · gesture worst p95 ${num1(c.gestureWorstP95.p50)} / ${num1(c.gestureWorstP95.max)} ms`);
817
+ const more = [
818
+ ...c.editToRedrawMs.n ? [`edit to last redraw ${dur(c.editToRedrawMs.p50)} / ${dur(c.editToRedrawMs.p90)} (${c.editToRedrawMs.n})`] : [],
819
+ ...c.fullReloads.ambiguous || c.fullReloads.unknown ? [`full reloads ambiguous ${c.fullReloads.ambiguous}, unknown ${c.fullReloads.unknown}`] : [],
820
+ ...c.renders.commits ? [`re-renders ${c.renders.commits} commits, ${c.renders.ms} ms of React's render work (not layout or paint), ${c.renders.inGesture} in gestures`] : [],
821
+ ...c.themeMaxMs !== null ? [`theme switch max ${dur(c.themeMaxMs)}`] : [],
822
+ ...c.commentsShownP50Ms !== null ? [`comments mode shown p50 ${dur(c.commentsShownP50Ms)}`] : []
823
+ ];
824
+ if (more.length) console.log(` ${more.join(" · ")}`);
825
+ const trouble = [
826
+ ...Object.keys(c.errors).length ? [`errors: ${list(c.errors)}`] : [],
827
+ ...commandsWords(c.commands),
828
+ ...c.inplaceNoAfterUpdate ? [`in-place updates with no end from Vite: ${c.inplaceNoAfterUpdate}`] : [],
829
+ ...c.retentionCap ? [`${c.retentionCap} lines deleted by the safety cap`] : []
830
+ ];
831
+ if (trouble.length) console.log(` ${trouble.join(" · ")}`);
832
+ }
833
+ const a = sum.app;
834
+ console.log("\nthe Mac app");
835
+ if (!a.records) {
836
+ console.log(" no records in the window");
837
+ return;
838
+ }
839
+ console.log(` launches ${a.launches} · to first canvas p50 ${dur(a.toFirstCanvasMs.p50)}, max ${dur(a.toFirstCanvasMs.max)}${Object.keys(a.noCanvas).length ? ` · no canvas: ${list(a.noCanvas)}` : ""} · crashes ${a.crashes} · hangs ${a.hangs} · flashes ${a.flashes}`);
840
+ console.log(` white-out candidates (automatic, not verified)${Object.keys(a.candidates).length ? `: ${list(a.candidates)}` : ": 0"} · captures ${a.capture.captures}, ${dur(a.capture.captureMs)}${a.capture.overrunMs ? ` (${dur(a.capture.overrunMs)} past their 500 ms)` : ""} · uncovered window time: stage ${dur(a.uncoveredMs.stage)}, budget ${dur(a.uncoveredMs.budget)}, hidden ${dur(a.uncoveredMs.hidden)}`);
841
+ const cmds = commandsWords(a.commands);
842
+ if (cmds.length) console.log(` ${cmds.join(" · ")}`);
843
+ }
844
+ /** Enough for a page that retried a batch; a line older than this repeating is a reader's report's to dedupe. */
845
+ const SEEN_MAX = 8192;
846
+ /** A partial line longer than this is no line (never a whole file held in memory). */
847
+ const PARTIAL_MAX = 8 * 2 ** 20;
848
+ const REFRESH_POLLS = 20;
849
+ /** One file, held by identity. `end`: start from the file's end (a path found at the tail's start). */
850
+ var Tail = class {
851
+ path;
852
+ fd = null;
853
+ ino = -1;
854
+ dev = -1;
855
+ pos = 0;
856
+ partial = Buffer.alloc(0);
857
+ constructor(path, end) {
858
+ this.path = path;
859
+ if (end && this.open()) this.pos = fstatSync(this.fd).size;
860
+ }
861
+ open() {
862
+ try {
863
+ const fd = openSync(this.path, "r");
864
+ const st = fstatSync(fd);
865
+ if (!st.isFile()) {
866
+ closeSync(fd);
867
+ return false;
868
+ }
869
+ this.fd = fd;
870
+ this.ino = st.ino;
871
+ this.dev = st.dev;
872
+ this.pos = 0;
873
+ this.partial = Buffer.alloc(0);
874
+ return true;
875
+ } catch {
876
+ return false;
877
+ }
878
+ }
879
+ /** The open descriptor to its end: its whole lines, the partial one kept. */
880
+ drain() {
881
+ if (this.fd === null) return [];
882
+ const chunks = [this.partial];
883
+ for (;;) {
884
+ const b = Buffer.alloc(65536);
885
+ let n = 0;
886
+ try {
887
+ n = readSync(this.fd, b, 0, b.length, this.pos);
888
+ } catch {
889
+ break;
890
+ }
891
+ if (n <= 0) break;
892
+ chunks.push(b.subarray(0, n));
893
+ this.pos += n;
894
+ }
895
+ const all = Buffer.concat(chunks);
896
+ const nl = all.lastIndexOf(10);
897
+ if (nl < 0) {
898
+ this.partial = all.length > PARTIAL_MAX ? Buffer.alloc(0) : all;
899
+ return [];
900
+ }
901
+ this.partial = all.subarray(nl + 1).length > PARTIAL_MAX ? Buffer.alloc(0) : Buffer.from(all.subarray(nl + 1));
902
+ return all.subarray(0, nl).toString("utf8").split("\n").filter(Boolean);
903
+ }
904
+ /** One poll: what the open file holds now, then - only then - the file the path names now, if it is another. */
905
+ poll() {
906
+ const out = this.drain();
907
+ let st;
908
+ try {
909
+ st = statSync(this.path);
910
+ } catch {
911
+ return out;
912
+ }
913
+ if (this.fd !== null && st.ino === this.ino && st.dev === this.dev) return out;
914
+ if (this.fd !== null) {
915
+ try {
916
+ closeSync(this.fd);
917
+ } catch {}
918
+ this.fd = null;
919
+ }
920
+ if (this.open()) out.push(...this.drain());
921
+ return out;
922
+ }
923
+ close() {
924
+ if (this.fd !== null) {
925
+ try {
926
+ closeSync(this.fd);
927
+ } catch {}
928
+ this.fd = null;
929
+ }
930
+ }
931
+ };
932
+ const shorten = (v, n = 80) => {
933
+ const s = String(v);
934
+ return s.length > n ? `${s.slice(0, n - 1)}…` : s;
935
+ };
936
+ /** The fields that matter, by what a record holds; the rest is `--json`'s. */
937
+ const FIELDS = [
938
+ "board",
939
+ "cause",
940
+ "trigger",
941
+ "reason",
942
+ "request",
943
+ "ms",
944
+ "node",
945
+ "frame",
946
+ "outcome",
947
+ "file",
948
+ "event",
949
+ "change",
950
+ "revision",
951
+ "cmd",
952
+ "phase",
953
+ "via",
954
+ "in",
955
+ "keys",
956
+ "why",
957
+ "mode",
958
+ "to",
959
+ "scope",
960
+ "source",
961
+ "type",
962
+ "p95",
963
+ "n",
964
+ "readyMs",
965
+ "tab",
966
+ "noAfterUpdate",
967
+ "message"
968
+ ];
969
+ /** One line for a record: its time, its canvas, its kind, the fields that matter. */
970
+ function liveLine(canvas, r) {
971
+ const t = typeof r.ts === "number" ? new Date(r.ts).toLocaleTimeString() : "-";
972
+ const bits = [];
973
+ for (const k of FIELDS) {
974
+ const v = r[k];
975
+ if (v !== void 0 && v !== null && typeof v !== "object") bits.push(`${k} ${shorten(v, k === "message" ? 120 : 40)}`);
976
+ }
977
+ if (Array.isArray(r.reload)) bits.push(`reload ${r.reloadN ?? r.reload.length}`);
978
+ return `${t} ${canvas} ${String(r.kind ?? "run")}${bits.length ? ` ${bits.join(" · ")}` : ""}`;
979
+ }
980
+ /** What one record is, once (#7), in its own source's terms - an app event may name a page, and its `seq` is the launch's,
981
+ * never the page's; null for a line that names none, which was written once and always prints. */
982
+ function identity(r, app) {
983
+ if (typeof r.seq !== "number") return null;
984
+ if (app) return typeof r.app === "string" ? `app/${String(r.flavour ?? "")}/${r.app}/${r.seq}` : null;
985
+ return typeof r.page === "string" ? `page/${r.page}/${r.seq}` : null;
986
+ }
987
+ const CANVAS_FILES = [
988
+ "page.jsonl",
989
+ "reloads.jsonl",
990
+ "jam.jsonl",
991
+ "runs.jsonl"
992
+ ];
993
+ /**
994
+ * The tails and what they print. `add` follows a canvas's live files from their ends (a file not there yet from its
995
+ * start); `poll` prints what came since. Separate from the timer so a test can drive it, poll by poll.
996
+ */
997
+ var Live = class {
998
+ o;
999
+ tails = [];
1000
+ known = /* @__PURE__ */ new Set();
1001
+ seen = /* @__PURE__ */ new Set();
1002
+ kinds;
1003
+ print;
1004
+ constructor(o = {}) {
1005
+ this.o = o;
1006
+ this.kinds = o.kinds?.length ? new Set(o.kinds) : null;
1007
+ this.print = o.print ?? ((l) => console.log(l));
1008
+ }
1009
+ follow(path, canvas, app = false) {
1010
+ if (this.known.has(path)) return;
1011
+ this.known.add(path);
1012
+ this.tails.push({
1013
+ tail: new Tail(path, true),
1014
+ canvas,
1015
+ app
1016
+ });
1017
+ }
1018
+ addCanvas(root, canvas) {
1019
+ for (const f of CANVAS_FILES) this.follow(join(perfDir(root), f), canvas);
1020
+ }
1021
+ addApp(home) {
1022
+ for (const f of Object.values(APP_LOG)) this.follow(join(home, "perf", f), "app", true);
1023
+ }
1024
+ poll() {
1025
+ for (const { tail, canvas, app } of this.tails) for (const line of tail.poll()) this.line(canvas, line, app);
1026
+ }
1027
+ line(canvas, text, app) {
1028
+ let r;
1029
+ try {
1030
+ r = JSON.parse(text);
1031
+ } catch {
1032
+ return;
1033
+ }
1034
+ if (!r || typeof r !== "object") return;
1035
+ if (this.kinds && !this.kinds.has(String(r.kind ?? "run"))) return;
1036
+ const k = identity(r, app);
1037
+ if (k !== null) {
1038
+ if (this.seen.has(k)) return;
1039
+ this.seen.add(k);
1040
+ if (this.seen.size > SEEN_MAX) this.seen.delete(this.seen.values().next().value);
1041
+ }
1042
+ this.print(this.o.json ? text : liveLine(canvas, r));
1043
+ }
1044
+ close() {
1045
+ for (const { tail } of this.tails) tail.close();
1046
+ }
1047
+ };
1048
+ /** `marver perf --live`: until Ctrl-C. */
1049
+ function livePerf(root, opts) {
1050
+ const live = new Live({
1051
+ kinds: typeof opts.kinds === "string" ? opts.kinds.split(",").map((k) => k.trim()).filter(Boolean) : [],
1052
+ json: opts.json
1053
+ });
1054
+ const home = marverHome();
1055
+ const add = () => {
1056
+ if (opts.all) for (const c of knownCanvases(home)) live.addCanvas(c.root, c.name);
1057
+ live.addApp(home);
1058
+ };
1059
+ if (!opts.all) live.addCanvas(root, root.split("/").at(-1) ?? root);
1060
+ add();
1061
+ if (!opts.json) console.log(`following ${opts.all ? "every known canvas" : "this repo"} and the app, from now - about 3 s behind (Ctrl-C ends it)`);
1062
+ return new Promise((done) => {
1063
+ let n = 0;
1064
+ const timer = setInterval(() => {
1065
+ live.poll();
1066
+ if (opts.all && ++n % REFRESH_POLLS === 0) add();
1067
+ }, 500);
1068
+ process.once("SIGINT", () => {
1069
+ clearInterval(timer);
1070
+ live.close();
1071
+ done();
1072
+ });
1073
+ });
1074
+ }
533
1075
  //#endregion
534
1076
  //#region src/cli/perf.ts
535
1077
  /**
@@ -537,35 +1079,32 @@ function within(a, b, pct = 10) {
537
1079
  * and how; every page-wide reload (sent or dropped) and every time the canvas page itself booted,
538
1080
  * with what came just before; the slowest frames to settle; one line per board load. Reads
539
1081
  * design/.local/perf/reloads.jsonl, and page.jsonl for the loads (`--loads`: each load in full, spec 28 A1.8).
1082
+ *
1083
+ * Spec 30 (R14 #56): every view reads every segment and both kinds of data. 0.29 lines read as ever: no change ids
1084
+ * (each `update` an edit, grouped by file), uncapped reload lists, samples in app.jsonl, no segments. 0.30 lines: an
1085
+ * edit is a change id, its frames the union of its `update` and `update-ids` lines (#10); every page and shell record
1086
+ * once by `(page, seq)` (#7). `--all` is perf-all.ts, `--live` perf-live.ts.
540
1087
  */
541
1088
  function perfCommand(root, opts) {
1089
+ if (opts.live) return livePerf(root, opts);
542
1090
  if (opts.jam) return jamPerf(root, opts);
543
1091
  if (opts.loads) return loadsPerf(root, opts);
544
1092
  if (opts.runs) return runsPerf(root, opts);
545
1093
  if (opts.crashes) return crashesPerf(root, opts);
546
1094
  if (opts.flashes) return flashesPerf(root, opts);
547
1095
  if (opts.machine) return machinePerf(root, opts);
1096
+ if (opts.all) return allPerf(opts);
548
1097
  const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
549
1098
  const since = Date.now() - minutes * 6e4;
550
- const log = readReloads(root, since);
1099
+ const log = dedupeSeq(readReloads(root, since));
551
1100
  const { records: pageRecords, runLoads } = ownLoads(readPage(root, since));
552
1101
  const loads = loadsSummary(pageRecords);
553
- const files = /* @__PURE__ */ new Map();
554
- for (const e of log) if (e.kind === "update") {
555
- const f = files.get(e.file ?? "(no file)") ?? {
556
- edits: 0,
557
- reload: /* @__PURE__ */ new Set(),
558
- inPlace: /* @__PURE__ */ new Set()
559
- };
560
- f.edits++;
561
- for (const id of e.reload ?? []) f.reload.add(id);
562
- for (const id of e.inPlace ?? []) f.inPlace.add(id);
563
- files.set(e.file ?? "(no file)", f);
564
- }
1102
+ const files = editsByFile(log);
565
1103
  const reloads = log.filter((e) => e.kind === "full-reload");
566
- const boots = log.flatMap((e, i) => e.kind === "shell-boot" ? [{
1104
+ const said = log.filter((x) => !BOOKKEEPING.has(x.kind));
1105
+ const boots = said.flatMap((e, i) => e.kind === "shell-boot" ? [{
567
1106
  ts: e.ts,
568
- before: log.slice(Math.max(0, i - 3), i).filter((x) => x.kind !== "ready" && x.kind !== "settled")
1107
+ before: said.slice(Math.max(0, i - 3), i).filter((x) => x.kind !== "ready" && x.kind !== "settled")
569
1108
  }] : []);
570
1109
  const slow = log.filter((e) => e.kind === "settled" && typeof e.ms === "number").sort((a, b) => b.ms - a.ms).slice(0, 5);
571
1110
  const booted = log.filter((e) => e.kind === "ready");
@@ -612,7 +1151,7 @@ function perfCommand(root, opts) {
612
1151
  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` : ""}`);
613
1152
  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`);
614
1153
  console.log(`\npage-wide reloads: ${reloads.filter((r) => r.passed).length} sent (dependency rebuilds), ${reloads.filter((r) => !r.passed).length} dropped`);
615
- for (const r of reloads) console.log(` ${t(r.ts)} ${r.passed ? "sent " : "dropped"} ${r.triggeredBy ?? "no file named"}`);
1154
+ for (const r of reloads) console.log(` ${t(r.ts)} ${r.passed ? "sent " : "dropped"} ${r.triggeredBy ?? (r.by === "hook" && r.file ? r.file : "no file named")}${r.by === "hook" ? " (the file whose hooks were running)" : r.by === "ambiguous" ? ` (two files' hooks were running: ${r.candidates?.n ?? 0} candidates)` : r.by === "unknown" ? ` (no file's hooks were running${r.candidates?.n ? `: ${r.candidates.n} in flight` : ""})` : ""}`);
616
1155
  console.log(`\ncanvas page loads: ${boots.length}`);
617
1156
  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(", ")}` : ""}`);
618
1157
  if (slow.length) {
@@ -634,16 +1173,83 @@ function perfCommand(root, opts) {
634
1173
  }
635
1174
  }
636
1175
  }
637
- /** Each record once: a send retried after its first attempt landed repeats its records - same ws, page and seq. */
638
- function unique(records) {
1176
+ /** Spec 30's reload lines that are bookkeeping for a reader (R13), never what a page load came after. */
1177
+ const BOOKKEEPING = /* @__PURE__ */ new Set([
1178
+ "change",
1179
+ "update-ids",
1180
+ "invalidate",
1181
+ "invalidate-ids",
1182
+ "invalidated",
1183
+ "invalidated-nodes",
1184
+ "inplace",
1185
+ "watchdog"
1186
+ ]);
1187
+ /**
1188
+ * Edits per file, with the frames each reached and how (#10, #56). With 0.30's change ids an edit is its id, and its
1189
+ * lists the union of its `update` and `update-ids` lines. A line with none (0.29, or a refused refresh: `unknown`,
1190
+ * never attributed, #8) is an edit of its own, as 0.29 counted; a refused refresh's parts name no change, so they go by
1191
+ * where they are: the server writes an `update` and its parts in one append, so the parts right after it are its own.
1192
+ * A part whose `update` fell before the window goes.
1193
+ */
1194
+ function editsByFile(log) {
1195
+ const files = /* @__PURE__ */ new Map();
1196
+ const ofChange = /* @__PURE__ */ new Map();
1197
+ const put = (key) => {
1198
+ let f = files.get(key);
1199
+ if (!f) files.set(key, f = {
1200
+ edits: 0,
1201
+ reload: /* @__PURE__ */ new Set(),
1202
+ inPlace: /* @__PURE__ */ new Set()
1203
+ });
1204
+ return f;
1205
+ };
1206
+ const change = (e) => typeof e.change === "string" && e.change !== "unknown" ? e.change : null;
1207
+ const union = (f, e) => {
1208
+ for (const x of e.reload ?? []) f.reload.add(x);
1209
+ for (const x of e.inPlace ?? []) f.inPlace.add(x);
1210
+ };
1211
+ /** the refused refresh whose parts may come next */
1212
+ let refused = null;
1213
+ for (const e of log) {
1214
+ if (refused && e.kind === "update-ids" && e.change === "unknown" && refused.parts === e.parts) {
1215
+ union(put(refused.key), e);
1216
+ continue;
1217
+ }
1218
+ refused = null;
1219
+ if (e.kind !== "update") continue;
1220
+ const key = e.file ?? "(no file)", id = change(e);
1221
+ const f = put(key);
1222
+ if (!id || !ofChange.has(id)) f.edits++;
1223
+ if (id) ofChange.set(id, key);
1224
+ union(f, e);
1225
+ if (e.change === "unknown" && Number(e.parts) > 1) refused = {
1226
+ key,
1227
+ parts: e.parts
1228
+ };
1229
+ }
1230
+ for (const e of log) {
1231
+ if (e.kind !== "update-ids") continue;
1232
+ const key = ofChange.get(e.change);
1233
+ if (key !== void 0) union(put(key), e);
1234
+ }
1235
+ return files;
1236
+ }
1237
+ /**
1238
+ * Each record once (spec 30 #7): a send retried after its first attempt landed repeats its records - same page and
1239
+ * seq, one seq per page across page and shell lines. A line that names none - a server's own, a 0.29 shell's, the
1240
+ * safety cap's - was written once and is kept as it is.
1241
+ */
1242
+ function dedupeSeq(records) {
639
1243
  const seen = /* @__PURE__ */ new Set();
640
1244
  return records.filter((r) => {
641
- const k = `${r.ws}/${r.page}/${r.seq}`;
1245
+ if (typeof r.page !== "string" || typeof r.seq !== "number") return true;
1246
+ const k = `${r.ws ?? ""}/${r.page}/${r.seq}`;
642
1247
  if (seen.has(k)) return false;
643
1248
  seen.add(k);
644
1249
  return true;
645
1250
  });
646
1251
  }
1252
+ const unique = dedupeSeq;
647
1253
  const ranked = (counts, n = 5) => [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, n);
648
1254
  const bump = (m, k) => m.set(k, (m.get(k) ?? 0) + 1);
649
1255
  /** Board loads (spec 28 A1.8): page.jsonl's records grouped by ws/page/load, each group in seq order; a node's last
@@ -830,7 +1436,7 @@ function endOf(l) {
830
1436
  function ownLoads(records) {
831
1437
  const loads = /* @__PURE__ */ new Set();
832
1438
  return {
833
- records: records.filter((r) => {
1439
+ records: dedupeSeq(records).filter((r) => {
834
1440
  if (typeof r.run !== "string") return true;
835
1441
  if (r.kind === "load") loads.add(`${r.ws}/${r.page}/${r.load}`);
836
1442
  return false;
@@ -844,13 +1450,15 @@ function loadsPerf(root, opts) {
844
1450
  const { records, runLoads } = ownLoads(readPage(root, Date.now() - minutes * 6e4));
845
1451
  const loads = loadsSummary(records);
846
1452
  const dropped = droppedOf(records);
1453
+ const capped = records.filter((r) => r.kind === "dropped" && r.reason === "retention-cap").reduce((n, r) => n + (Number(r.n) || 0), 0);
847
1454
  if (opts.json) {
848
1455
  console.log(JSON.stringify({
849
1456
  minutes,
850
1457
  loads,
851
1458
  unowned: unownedOf(records),
852
1459
  dropped,
853
- runLoads
1460
+ runLoads,
1461
+ ...capped ? { retentionCap: capped } : {}
854
1462
  }, null, 2));
855
1463
  return;
856
1464
  }
@@ -892,6 +1500,7 @@ function loadsPerf(root, opts) {
892
1500
  if (l.gestures) console.log(` ${plural(l.gestures.n, "gesture")} · worst p95 ${l.gestures.worstP95} ms · ${plural(l.gestures.over33ms, "frame")} over 33 ms`);
893
1501
  }
894
1502
  if (dropped) console.log(`\n ${plural(dropped, "record")} never reached this log: a page's queue was full, or its sends failed`);
1503
+ if (capped) console.log(`\n ${plural(capped, "record")} deleted by the safety cap: the log was past its size for its 14 days`);
895
1504
  if (hidden) console.log(`\n ${hidden}`);
896
1505
  }
897
1506
  /** Count, median, p90 and max of a list of ms. */
@@ -953,7 +1562,7 @@ function jamSummary(events) {
953
1562
  })),
954
1563
  ...of("dropped").map((d) => ({
955
1564
  ts: d.ts,
956
- what: `${d.count} event(s) dropped (the log was busy)`
1565
+ what: d.reason === "retention-cap" ? `${d.count} event(s) deleted by the safety cap` : `${d.count} event(s) dropped (the log was busy)`
957
1566
  }))
958
1567
  ].sort((a, b) => b.ts - a.ts).slice(0, 10);
959
1568
  const lives = caps.map((c) => c.pictures?.live).filter((l) => !!l);
@@ -1122,7 +1731,7 @@ function flashesPerf(root, opts) {
1122
1731
  }
1123
1732
  if (!opts.all && sum.others) console.log(`\n${sum.others} more mark${sum.others === 1 ? "" : "s"} on other canvases or on Home (--all shows them)`);
1124
1733
  console.log(`\nwhite-out candidates (automatic, not verified): ${sum.candidates.length}`);
1125
- for (const c of sum.candidates) console.log(` ${when(c.at)} white at ${c.observedAt.length} samples ${c.rateHz ? `at ${c.rateHz} Hz ` : ""}(${c.observedAt.map((t) => secs2(t - c.at)).join(", ")}) · ${momentWords(c, name)}`);
1734
+ for (const c of sum.candidates) console.log(` ${when(c.at)} white at ${c.observedAt.length} samples ${c.rateHz ? `at ${c.rateHz} Hz ` : ""}(${c.observedAt.map((t) => secs2(t - c.at)).join(", ")})${c.why?.length ? ` · during ${c.why.join(", ")}` : ""} · ${momentWords(c, name)}`);
1126
1735
  }
1127
1736
  /** `marver perf --machine`: the machine profiles, by host, which is current, and how many records and runs name each. */
1128
1737
  function machinePerf(root, opts) {
@@ -1172,7 +1781,7 @@ const hint = (l) => l.restarted ? "the dev server restarted during the run (an .
1172
1781
  function runBlock(l, name) {
1173
1782
  const h = hint(l);
1174
1783
  return [
1175
- `run ${l.run} · ${name(l.board)} · Chrome ${l.chrome.split(".")[0]} · bakes ${l.bakes}${l.slow ? " · --slow" : ""}${l.overlapped ? " · overlapped" : ""}`,
1784
+ `run ${l.run} · ${name(l.board)} · Chrome ${l.chrome.split(".")[0]} · bakes ${l.bakes}${l.slow ? " · --slow" : ""}${l.recorder === "core" ? " · recorder core" : ""}${l.overlapped ? " · overlapped" : ""}`,
1176
1785
  `load to settled ${ms2(l.loadToSettledMs)} · ${l.moves} move${l.moves === 1 ? "" : "s"}${l.lateMoves ? ` (${l.lateMoves} late)` : ""} · p50 ${mms(l.p50)} p95 ${mms(l.p95)} · ${over33(l.over33ms)} · heap peak ${l.heapPeakMB ?? "-"} MB${l.postersMissing ? ` · ${l.postersMissing} without a poster` : ""}`,
1177
1786
  `${l.valid ? "valid" : why(l)} · inputs ${l.inputs ? `${l.inputs.hash.slice(0, 8)}… (${l.inputs.files.toLocaleString("en-US")} files)` : "unknown"}${l.forbidden ? ` · ${l.forbidden} write${l.forbidden === 1 ? "" : "s"} refused` : ""}`,
1178
1787
  ...h ? [h] : []
@@ -1209,7 +1818,8 @@ var ServerSaid = class extends Error {};
1209
1818
  * `done`, under a run waits for that run's line.
1210
1819
  */
1211
1820
  async function perfRunCommand(root, board, opts) {
1212
- if (!board) throw new Error("name the board: marver perf run <board> [--slow] [--repeat 1-5] [--json]");
1821
+ if (!board) throw new Error("name the board: marver perf run <board> [--slow] [--repeat 1-5] [--recorder core|full] [--json]");
1822
+ if (opts.recorder !== void 0 && opts.recorder !== "core" && opts.recorder !== "full") throw new Error("--recorder must be core or full");
1213
1823
  const info = readDevInfo(root);
1214
1824
  if (!info) throw new Error("`marver dev` is not running in this repo (design/.local/dev.json not found) - start it first.");
1215
1825
  const repeat = opts.repeat === void 0 ? 1 : Number(opts.repeat);
@@ -1231,7 +1841,8 @@ async function perfRunCommand(root, board, opts) {
1231
1841
  body: JSON.stringify({
1232
1842
  board,
1233
1843
  slow: !!opts.slow,
1234
- repeat
1844
+ repeat,
1845
+ recorder: opts.recorder ?? "full"
1235
1846
  })
1236
1847
  });
1237
1848
  if (!res.ok || !res.body) {
@@ -1316,7 +1927,7 @@ function runsPerf(root, opts) {
1316
1927
  }
1317
1928
  const pct = (a, b) => a && b !== null ? `${b >= a ? "+" : ""}${Math.round((b - a) / a * 100)} %` : "-";
1318
1929
  for (const b of sum.boards) {
1319
- console.log(`\n ${name(b.board)} · Chrome ${String(b.cohort.chrome).split(".")[0]} · bakes ${b.cohort.bakes}${b.cohort.slow ? " · --slow" : ""} · ${b.runs} valid run${b.runs === 1 ? "" : "s"}`);
1930
+ console.log(`\n ${name(b.board)} · Chrome ${String(b.cohort.chrome).split(".")[0]} · bakes ${b.cohort.bakes}${b.cohort.slow ? " · --slow" : ""}${b.cohort.recorder === "core" ? " · recorder core" : ""} · ${b.runs} valid run${b.runs === 1 ? "" : "s"}`);
1320
1931
  const d33 = b.afterChange?.deltas.over33ms ?? null;
1321
1932
  console.log(` latest ${b.latest.run}: load to settled ${ms2(b.latest.loadToSettledMs)} · p95 ${mms(b.latest.p95)} · ${b.latest.over33ms ?? "-"} over 33 ms · inputs ${b.latest.inputs?.slice(0, 8) ?? "unknown"}…`);
1322
1933
  if (b.sameInputs) console.log(` against ${b.sameInputs.from.run} (same inputs): ${b.sameInputs.within10 ? "within 10 %" : "NOT within 10 %"} - load ${pct(b.sameInputs.from.loadToSettledMs, b.latest.loadToSettledMs)}, p95 ${pct(b.sameInputs.from.p95, b.latest.p95)}`);