@marver-design/marver 0.26.0 → 0.26.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 (44) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +2 -2
  3. package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-l-ny3UzH.mjs} +1 -1
  4. package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
  5. package/dist/{bake-DtVlm0_F.mjs → bake-C-awKgLA.mjs} +1 -1
  6. package/dist/{build-C_gUgcdC.mjs → build-BDRiO_mP.mjs} +3 -3
  7. package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
  8. package/dist/cli.mjs +6 -6
  9. package/dist/{daemon-DZo6o3rU.mjs → daemon-DL6Fwq6D.mjs} +394 -270
  10. package/dist/{dev-_Nlsc6v9.mjs → dev-Bw_qYWWq.mjs} +24 -11
  11. package/dist/{marks-NQi0wZJ4.mjs → marks-DyWMv_Z1.mjs} +1 -1
  12. package/dist/perf-C75MZ73h.mjs +167 -0
  13. package/dist/perf-jam-BU3TVrZu.mjs +239 -0
  14. package/dist/{plugin-CTD0rydA.mjs → plugin-DkGmZs_r.mjs} +42 -22
  15. package/dist/{poster-ChjXGTS5.mjs → poster-BdtSKMDm.mjs} +2 -1
  16. package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-9RzRToXV.mjs} +2 -2
  17. package/dist/{queue-BuiCKSX1.mjs → queue-29ok5_eZ.mjs} +2 -2
  18. package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
  19. package/dist/{shot-DqcxJibP.mjs → shot-DQeR_Pfn.mjs} +337 -19
  20. package/dist/shot-XQV7HC9A.mjs +139 -0
  21. package/dist/speech-worker.mjs +40 -5
  22. package/docs/jam-session.md +24 -7
  23. package/docs/live-jam.md +8 -0
  24. package/package.json +1 -1
  25. package/src/client/frame-host/inspect.js +8 -3
  26. package/src/client/frame-host/keys.js +6 -2
  27. package/src/client/shell/App.tsx +8 -4
  28. package/src/client/shell/JamSurface.tsx +9 -3
  29. package/src/client/shell/Play.tsx +11 -7
  30. package/src/client/shell/Toolbar.tsx +5 -4
  31. package/src/client/shell/canvas/FrameNode.tsx +3 -2
  32. package/src/client/shell/icons.tsx +2 -0
  33. package/src/client/shell/jam-capture.ts +77 -11
  34. package/src/client/shell/jam-keys.ts +47 -18
  35. package/src/client/shell/jam-lane.tsx +46 -5
  36. package/src/client/shell/jam-panel.tsx +63 -13
  37. package/src/client/shell/jam-state.ts +48 -6
  38. package/src/client/shell/jam-surface-parts.tsx +10 -6
  39. package/src/client/shell/store.ts +14 -5
  40. package/src/client/shell/styles.css +28 -8
  41. package/src/client/stage/main.tsx +2 -0
  42. package/templates/instructions/jam.md +5 -3
  43. package/dist/perf-D6VmmJ2q.mjs +0 -68
  44. package/dist/shot-CNbHoZ6H.mjs +0 -86
@@ -1,6 +1,6 @@
1
1
  import { i as PKG, r as NAME } from "./cli.mjs";
2
2
  import { n as loadConfig, r as detectHost } from "./config-Cf7EjAMf.mjs";
3
- import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-CTD0rydA.mjs";
3
+ import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-DkGmZs_r.mjs";
4
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch } from "node:fs";
5
5
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -521,6 +521,7 @@ async function boot(root, portFlag, instance, unhook) {
521
521
  const server = await createServer$1({
522
522
  configFile: false,
523
523
  root,
524
+ cacheDir: join(root, "node_modules", ".vite-marver"),
524
525
  css,
525
526
  customLogger: logger,
526
527
  plugins,
@@ -582,6 +583,10 @@ async function boot(root, portFlag, instance, unhook) {
582
583
  `${PKG} > mermaid`,
583
584
  `${PKG} > roughjs`,
584
585
  `${PKG} > html-to-image`,
586
+ `${PKG} > echarts/core`,
587
+ `${PKG} > echarts/renderers`,
588
+ `${PKG} > echarts/charts`,
589
+ `${PKG} > echarts/components`,
585
590
  ...iconModules(root)
586
591
  ],
587
592
  entries: [join(clientDir, "frame-host", "index.html"), "design/**/*.{tsx,jsx}"]
@@ -595,12 +600,12 @@ async function boot(root, portFlag, instance, unhook) {
595
600
  console.log(`\n ${NAME} · ${projectName} → http://localhost:${port}/\n`);
596
601
  setTimeout(async () => {
597
602
  try {
598
- await (await import("./shot-DqcxJibP.mjs")).sweepGhosts((m) => console.log(` ${m}`));
603
+ await (await import("./shot-DQeR_Pfn.mjs")).sweepGhosts((m) => console.log(` ${m}`));
599
604
  } catch {}
600
605
  }, 0);
601
606
  try {
602
607
  const { staleManagedInstructions } = await import("./managed-HwHVNI3h.mjs");
603
- const { installedVersion } = await import("./plugin-CTD0rydA.mjs").then((n) => n.i);
608
+ const { installedVersion } = await import("./plugin-DkGmZs_r.mjs").then((n) => n.i);
604
609
  const stale = staleManagedInstructions(root);
605
610
  if (stale.length) {
606
611
  const shown = stale.slice(0, 4).join(", ") + (stale.length > 4 ? `, +${stale.length - 4} more` : "");
@@ -685,8 +690,8 @@ async function boot(root, portFlag, instance, unhook) {
685
690
  } catch {}
686
691
  }
687
692
  if (config.jam) {
688
- const { startJam } = await import("./daemon-DZo6o3rU.mjs");
689
- const { checkAnchor } = await import("./anchor-check-Dg5xpNnU.mjs");
693
+ const { startJam } = await import("./daemon-DL6Fwq6D.mjs");
694
+ const { checkAnchor } = await import("./anchor-check-l-ny3UzH.mjs");
690
695
  const jam = startJam(root, config.jam, (m) => console.log(m), (board) => server.ws.send("sh:jam-comment", { board }), (frameId, target, others, look) => checkAnchor({
691
696
  root,
692
697
  viewports: config.viewports,
@@ -705,7 +710,7 @@ async function boot(root, portFlag, instance, unhook) {
705
710
  }, 60);
706
711
  };
707
712
  })(), async (frameId, theme, entry, size) => {
708
- const { shootFrame } = await import("./shot-DqcxJibP.mjs");
713
+ const { shootFrame } = await import("./shot-DQeR_Pfn.mjs");
709
714
  const r = await shootFrame({
710
715
  root,
711
716
  viewports: config.viewports,
@@ -715,16 +720,24 @@ async function boot(root, portFlag, instance, unhook) {
715
720
  ...size ? { size } : {}
716
721
  });
717
722
  if (!r.ok) return null;
718
- const { addPicture } = await import("./capture-CrqvU_jh.mjs").then((n) => n.i);
723
+ const { addPicture } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
719
724
  return addPicture(root, r.path, {
720
725
  frame: frameId,
721
- ...entry
726
+ ...entry,
727
+ .../not checked for a stale surface/.test(r.note ?? "") ? { unchecked: true } : {}
722
728
  });
723
729
  });
724
730
  if (jam) {
725
- const { createSpeech, speechLive } = await import("./audio-CmSRYFEs.mjs");
726
- const { appendTalk } = await import("./session-qZWKt_VA.mjs").then((n) => n.s);
727
- const speech = createSpeech({ onTalk: (t) => appendTalk(root, t.session, t.words) });
731
+ const { createSpeech, speechLive } = await import("./audio-Dw1lfMdb.mjs");
732
+ const { appendTalk } = await import("./session-BAaJsK5c.mjs").then((n) => n.s);
733
+ const { logJam } = await import("./perf-jam-BU3TVrZu.mjs").then((n) => n.n);
734
+ const speech = createSpeech({
735
+ onTalk: (t) => appendTalk(root, t.session, t.words),
736
+ onTiming: (t) => logJam(root, {
737
+ kind: "words",
738
+ ...t
739
+ })
740
+ });
728
741
  if (server.httpServer) speech.attach(server.httpServer);
729
742
  speechLive.svc = speech;
730
743
  const close = server.close.bind(server);
@@ -2,7 +2,7 @@ import { s as scanFrames } from "./manifest-Nl3KSVOk.mjs";
2
2
  import { r as replay, t as asks } from "./events-CLH4ijKP.mjs";
3
3
  import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
4
4
  import { o as projectMarks } from "./marks-CKgzucHZ.mjs";
5
- import { answers } from "./queue-BuiCKSX1.mjs";
5
+ import { answers } from "./queue-29ok5_eZ.mjs";
6
6
  import { join } from "node:path";
7
7
  //#region src/shared/marks.ts
8
8
  const isNew = (m, id) => !!m && (m.changed[id] ?? 0) > (m.seen[id] ?? 0);
@@ -0,0 +1,167 @@
1
+ import { r as readReloads } from "./perf-DPbLGhhO.mjs";
2
+ import { r as readJam } from "./perf-jam-BU3TVrZu.mjs";
3
+ //#region src/cli/perf.ts
4
+ /**
5
+ * `marver perf` (spec 26 Part 1): the reload log read back - per edited file, the frames it reached
6
+ * and how; every page-wide reload (sent or dropped) and every time the canvas page itself booted,
7
+ * with what came just before; the slowest frames to settle. Reads design/.local/perf/reloads.jsonl.
8
+ */
9
+ function perfCommand(root, opts) {
10
+ if (opts.jam) return jamPerf(root, opts);
11
+ const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
12
+ const log = readReloads(root, Date.now() - minutes * 6e4);
13
+ const files = /* @__PURE__ */ new Map();
14
+ for (const e of log) if (e.kind === "update") {
15
+ const f = files.get(e.file ?? "(no file)") ?? {
16
+ edits: 0,
17
+ reload: /* @__PURE__ */ new Set(),
18
+ inPlace: /* @__PURE__ */ new Set()
19
+ };
20
+ f.edits++;
21
+ for (const id of e.reload ?? []) f.reload.add(id);
22
+ for (const id of e.inPlace ?? []) f.inPlace.add(id);
23
+ files.set(e.file ?? "(no file)", f);
24
+ }
25
+ const reloads = log.filter((e) => e.kind === "full-reload");
26
+ const boots = log.flatMap((e, i) => e.kind === "shell-boot" ? [{
27
+ ts: e.ts,
28
+ before: log.slice(Math.max(0, i - 3), i).filter((x) => x.kind !== "ready" && x.kind !== "settled")
29
+ }] : []);
30
+ const slow = log.filter((e) => e.kind === "settled" && typeof e.ms === "number").sort((a, b) => b.ms - a.ms).slice(0, 5);
31
+ const booted = log.filter((e) => e.kind === "ready");
32
+ const by = (c) => booted.filter((e) => e.cause === c).length;
33
+ const reloaded = by("job");
34
+ if (opts.json) {
35
+ console.log(JSON.stringify({
36
+ minutes,
37
+ files: Object.fromEntries([...files].map(([k, v]) => [k, {
38
+ edits: v.edits,
39
+ reached: [...v.reload],
40
+ inPlace: [...v.inPlace]
41
+ }])),
42
+ documents: {
43
+ afterEdit: reloaded,
44
+ byHand: by("manual"),
45
+ retried: by("retry"),
46
+ self: by("self"),
47
+ first: by("first")
48
+ },
49
+ reloads,
50
+ boots,
51
+ slow
52
+ }, null, 2));
53
+ return;
54
+ }
55
+ const t = (ts) => new Date(ts).toLocaleTimeString();
56
+ console.log(`last ${minutes} min - design/.local/perf/reloads.jsonl`);
57
+ console.log(`\nedits (${files.size} files)`);
58
+ 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` : ""}`);
59
+ 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`);
60
+ console.log(`\npage-wide reloads: ${reloads.filter((r) => r.passed).length} sent (dependency rebuilds), ${reloads.filter((r) => !r.passed).length} dropped`);
61
+ for (const r of reloads) console.log(` ${t(r.ts)} ${r.passed ? "sent " : "dropped"} ${r.triggeredBy ?? "no file named"}`);
62
+ console.log(`\ncanvas page loads: ${boots.length}`);
63
+ 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(", ")}` : ""}`);
64
+ if (slow.length) {
65
+ console.log("\nslowest to settle");
66
+ for (const s of slow) console.log(` ${s.frame} ${s.ms} ms`);
67
+ }
68
+ }
69
+ /** Count, median, p90 and max of a list of ms. */
70
+ function spread(xs) {
71
+ if (!xs.length) return { n: 0 };
72
+ const v = [...xs].sort((a, b) => a - b);
73
+ const at = (q) => v[Math.min(v.length - 1, Math.ceil(q * v.length) - 1)];
74
+ return {
75
+ n: v.length,
76
+ median: at(.5),
77
+ p90: at(.9),
78
+ max: v[v.length - 1]
79
+ };
80
+ }
81
+ /** `marver perf --jam`: each step of a capture and its run - count, median, p90, max - the runs by outcome, and the
82
+ * last problems, from design/.local/perf/jam.jsonl (numbers and codes only). */
83
+ function jamSummary(events) {
84
+ const of = (kind) => events.filter((e) => e.kind === kind);
85
+ const nums = (xs) => xs.filter((x) => typeof x === "number");
86
+ const caps = of("capture"), runs = of("run").filter((r) => !r.redelivered), shots = of("shot"), words = of("words");
87
+ const steps = {
88
+ "capture: E to sealed": spread(nums(caps.map((c) => c.sealMs))),
89
+ "capture: last words": spread(nums(caps.map((c) => c.wordsWaitMs))),
90
+ "capture: a picture": spread(nums(caps.flatMap((c) => c.pictures?.ms ?? []))),
91
+ "upload": spread(nums(of("upload").map((u) => u.ms))),
92
+ "naming": spread(nums(of("name").map((n) => n.ms))),
93
+ "words: wait": spread(nums(words.map((w) => w.waitMs))),
94
+ "words: transcription": spread(nums(words.map((w) => w.decodeMs))),
95
+ "words: model load": spread(nums(words.map((w) => w.modelLoadMs))),
96
+ "run: queued": spread(nums(runs.flatMap((r) => (r.members ?? []).map((m) => m.waitMs)))),
97
+ "run: pictures before": spread(nums(runs.map((r) => r.beforeMs))),
98
+ "run: agent": spread(nums(runs.flatMap((r) => r.agentMs ?? []))),
99
+ "run: pictures after": spread(nums(runs.map((r) => r.afterMs))),
100
+ "run: delivery": spread(nums(of("run").map((r) => r.deliverMs))),
101
+ "shot": spread(nums(shots.map((s) => s.ms)))
102
+ };
103
+ const outcomes = {};
104
+ for (const r of runs) for (const m of r.members ?? []) outcomes[m.outcome ?? "unknown"] = (outcomes[m.outcome ?? "unknown"] ?? 0) + 1;
105
+ return {
106
+ steps,
107
+ outcomes,
108
+ problems: [
109
+ ...of("run").filter((r) => r.failure).map((r) => ({
110
+ ts: r.ts,
111
+ what: `run ${String(r.batch).slice(0, 8)} ${r.redelivered ? "could not post its replies" : `failed: ${r.failure}`}`
112
+ })),
113
+ ...shots.filter((s) => s.outcome && s.outcome !== "ok").map((s) => ({
114
+ ts: s.ts,
115
+ what: `shot ${s.frame ?? "?"}: ${s.outcome}${s.recaptures ? ` after ${s.recaptures} retakes` : ""}`
116
+ })),
117
+ ...caps.filter((c) => c.pictures?.late || c.pictures?.failed).map((c) => ({
118
+ ts: c.ts,
119
+ what: `capture ${c.capture}: ${c.pictures.late ?? 0} picture(s) too late, ${c.pictures.failed ?? 0} failed`
120
+ })),
121
+ ...of("name").filter((n) => !n.ok).map((n) => ({
122
+ ts: n.ts,
123
+ what: `naming ${n.capture} gave no name`
124
+ })),
125
+ ...of("dropped").map((d) => ({
126
+ ts: d.ts,
127
+ what: `${d.count} event(s) dropped (the log was busy)`
128
+ }))
129
+ ].sort((a, b) => b.ts - a.ts).slice(0, 10),
130
+ retakes: shots.reduce((n, s) => n + (s.recaptures ?? 0), 0)
131
+ };
132
+ }
133
+ function jamPerf(root, opts) {
134
+ const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 1440;
135
+ const since = Date.now() - minutes * 6e4;
136
+ const { events, first } = readJam(root, since);
137
+ const sum = jamSummary(events);
138
+ const partial = first !== void 0 && first > since;
139
+ if (opts.json) {
140
+ console.log(JSON.stringify({
141
+ minutes,
142
+ ...partial ? { startsAt: first } : {},
143
+ ...sum
144
+ }, null, 2));
145
+ return;
146
+ }
147
+ const span = minutes >= 120 ? `${Math.round(minutes / 60)} h` : `${minutes} min`;
148
+ console.log(`Jam timings, last ${span} - design/.local/perf/jam.jsonl${partial ? ` (the log starts ${new Date(first).toLocaleString()})` : ""}`);
149
+ if (!events.length) {
150
+ console.log("\nnothing yet - captures, runs and shots log here as they happen");
151
+ return;
152
+ }
153
+ console.log("");
154
+ const pad = (s, n) => s + " ".repeat(Math.max(1, n - s.length));
155
+ console.log(` ${pad("step", 24)}${pad("count", 7)}${pad("median", 9)}${pad("p90", 9)}max`);
156
+ const f = (v) => v === void 0 ? "-" : v >= 1e4 ? `${(v / 1e3).toFixed(0)} s` : v >= 1e3 ? `${(v / 1e3).toFixed(1)} s` : `${v} ms`;
157
+ 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)}`);
158
+ const out = Object.entries(sum.outcomes);
159
+ if (out.length) console.log(`\nruns by outcome: ${out.map(([k, n]) => `${n} ${k}`).join(", ")}`);
160
+ if (sum.retakes) console.log(`pictures taken again (a stale surface): ${sum.retakes}`);
161
+ if (sum.problems.length) {
162
+ console.log("\nlately");
163
+ for (const p of sum.problems) console.log(` ${new Date(p.ts).toLocaleTimeString()} ${p.what}`);
164
+ }
165
+ }
166
+ //#endregion
167
+ export { perfCommand };
@@ -0,0 +1,239 @@
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, ".."), { recursive: true });
193
+ } catch {}
194
+ while (w.queue.length || w.dropped) {
195
+ const lines = w.queue.splice(0);
196
+ const held = lines.reduce((n, l) => n + l.length, 0);
197
+ w.inFlight = lines.length;
198
+ if (w.dropped) {
199
+ lines.push(JSON.stringify({
200
+ v: 1,
201
+ ts: Date.now(),
202
+ kind: "dropped",
203
+ count: w.dropped
204
+ }) + "\n");
205
+ w.dropped = 0;
206
+ }
207
+ try {
208
+ await (jamSeams.append ?? appendFile)(file, lines.join(""));
209
+ if (++w.writes % 50 === 0 && (await stat(file)).size > MAX_FILE) {
210
+ const all = (await readFile(file, "utf8")).split("\n");
211
+ await writeFile(file, all.slice(Math.floor(all.length / 2)).join("\n"));
212
+ }
213
+ } catch {}
214
+ w.inFlight = 0;
215
+ w.bytes = Math.max(0, w.bytes - held);
216
+ }
217
+ w.busy = false;
218
+ }
219
+ /** The log read back from `since` (epoch ms): malformed lines skipped. */
220
+ function readJam(root, since = 0) {
221
+ try {
222
+ const all = readFileSync(jamLog(root), "utf8").split("\n").flatMap((l) => {
223
+ try {
224
+ const e = JSON.parse(l);
225
+ return e && typeof e.ts === "number" ? [e] : [];
226
+ } catch {
227
+ return [];
228
+ }
229
+ });
230
+ return {
231
+ events: all.filter((e) => e.ts >= since),
232
+ ...all.length ? { first: all[0].ts } : {}
233
+ };
234
+ } catch {
235
+ return { events: [] };
236
+ }
237
+ }
238
+ //#endregion
239
+ export { perf_jam_exports as n, readJam as r, logJam as t };