@marver-design/marver 0.25.1 → 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 (95) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +5 -3
  3. package/dist/{anchor-DVV732zR.mjs → anchor-5H1vnoLu.mjs} +6 -1
  4. package/dist/{anchor-check-DGZnYviN.mjs → anchor-check-l-ny3UzH.mjs} +1 -1
  5. package/dist/audio-Dw1lfMdb.mjs +443 -0
  6. package/dist/{auth-DdUKeVKt.mjs → auth-Dix8wrXV.mjs} +1 -1
  7. package/dist/{bake-BpxMZfij.mjs → bake-C-awKgLA.mjs} +1 -1
  8. package/dist/{boards-Csxj2WJn.mjs → boards-DYG22tOe.mjs} +2 -2
  9. package/dist/{build-DKaGhoVN.mjs → build-BDRiO_mP.mjs} +16 -9
  10. package/dist/capture-vadKjuCo.mjs +730 -0
  11. package/dist/cli.mjs +24 -18
  12. package/dist/{collab-gqNdScUE.mjs → collab-Dxg2trOK.mjs} +4 -3
  13. package/dist/{comments-Zoch254k.mjs → comments-0BSbb04K.mjs} +14 -3
  14. package/dist/{comments-pTLlhjh4.mjs → comments-BqXua-XL.mjs} +7 -7
  15. package/dist/{config-cKgZBRj0.mjs → config-Cf7EjAMf.mjs} +12 -1
  16. package/dist/{context-D2ugHqwO.mjs → context-HQ4Giw58.mjs} +1 -1
  17. package/dist/daemon-DL6Fwq6D.mjs +2569 -0
  18. package/dist/{dev-Diqx1Rt8.mjs → dev-Bw_qYWWq.mjs} +202 -18
  19. package/dist/dev-lock-DWSpa6nj.mjs +179 -0
  20. package/dist/{events-DnK_AnrW.mjs → events-CLH4ijKP.mjs} +14 -4
  21. package/dist/{init-DO4DhUt_.mjs → init-D8DtrK_F.mjs} +2 -2
  22. package/dist/{ledger-BNXW14Xw.mjs → ledger-D54iROST.mjs} +17 -1
  23. package/dist/{link-C-qUIuKU.mjs → link-BNzLvdhI.mjs} +2 -2
  24. package/dist/live-Cgzsicwi.mjs +4 -0
  25. package/dist/{manifest-DnAte_fB.mjs → manifest-Nl3KSVOk.mjs} +1 -1
  26. package/dist/{marks-koRsbHfe.mjs → marks-CKgzucHZ.mjs} +2 -2
  27. package/dist/{marks-DFuintmJ.mjs → marks-DyWMv_Z1.mjs} +23 -5
  28. package/dist/{marver-id-gate-DGANtVyC.mjs → marver-id-gate-BjF6v4bT.mjs} +4 -4
  29. package/dist/perf-C75MZ73h.mjs +167 -0
  30. package/dist/{perf-CCisg-ny.mjs → perf-DPbLGhhO.mjs} +1 -1
  31. package/dist/perf-jam-BU3TVrZu.mjs +239 -0
  32. package/dist/{plugin-dTF5reck.mjs → plugin-DkGmZs_r.mjs} +298 -38
  33. package/dist/{poster-D-zjYpgk.mjs → poster-BdtSKMDm.mjs} +2 -1
  34. package/dist/{profile-Do0nGkXO.mjs → profile-WU9qcbIo.mjs} +1 -1
  35. package/dist/{publish-bakes-C_9VZ-Mq.mjs → publish-bakes-9RzRToXV.mjs} +3 -3
  36. package/dist/queue-29ok5_eZ.mjs +1319 -0
  37. package/dist/reserve-BURNQ2Y3.mjs +53 -0
  38. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
  39. package/dist/{serve-wv2QWdxB.mjs → serve-C8rVheYk.mjs} +12 -12
  40. package/dist/session-BAaJsK5c.mjs +191 -0
  41. package/dist/{share-ScamJcks.mjs → share--oFJ1bCI.mjs} +2 -2
  42. package/dist/{shot-CUlmkqFX.mjs → shot-DQeR_Pfn.mjs} +339 -20
  43. package/dist/shot-XQV7HC9A.mjs +139 -0
  44. package/dist/speech-models-DomiLQcY.mjs +299 -0
  45. package/dist/speech-worker.mjs +354 -0
  46. package/dist/{summary-CrW88e3q.mjs → summary-Y8MY1Wuc.mjs} +2 -2
  47. package/dist/{sync-C3035OnJ.mjs → sync-DKk-yT1V.mjs} +9 -8
  48. package/dist/{work-GE88wb_3.mjs → work-F5u-twpJ.mjs} +28 -5
  49. package/dist/{work-CpJn1gwY.mjs → work-VvX_JIgl.mjs} +2 -2
  50. package/docs/jam-session.md +194 -0
  51. package/docs/live-jam.md +29 -3
  52. package/package.json +7 -1
  53. package/src/client/frame-host/bridge.js +20 -2
  54. package/src/client/frame-host/inspect.d.ts +4 -0
  55. package/src/client/frame-host/inspect.js +96 -6
  56. package/src/client/frame-host/keys.d.ts +6 -0
  57. package/src/client/frame-host/keys.js +59 -0
  58. package/src/client/frame-host/trail.d.ts +7 -0
  59. package/src/client/frame-host/trail.js +204 -0
  60. package/src/client/shell/App.tsx +52 -8
  61. package/src/client/shell/Comments.tsx +20 -6
  62. package/src/client/shell/JamSurface.tsx +346 -0
  63. package/src/client/shell/Play.tsx +32 -9
  64. package/src/client/shell/Tip.tsx +8 -3
  65. package/src/client/shell/Toolbar.tsx +5 -4
  66. package/src/client/shell/canvas/Canvas.tsx +12 -2
  67. package/src/client/shell/canvas/FrameNode.tsx +14 -4
  68. package/src/client/shell/comments-store.ts +23 -16
  69. package/src/client/shell/icons.tsx +17 -0
  70. package/src/client/shell/jam-capture.ts +1005 -0
  71. package/src/client/shell/jam-keys.ts +358 -0
  72. package/src/client/shell/jam-lane.tsx +249 -0
  73. package/src/client/shell/jam-lines.ts +115 -0
  74. package/src/client/shell/jam-panel.tsx +556 -0
  75. package/src/client/shell/jam-queue.ts +126 -0
  76. package/src/client/shell/jam-session.tsx +389 -0
  77. package/src/client/shell/jam-state.ts +103 -0
  78. package/src/client/shell/jam-surface-parts.tsx +106 -0
  79. package/src/client/shell/jam-ui.tsx +104 -0
  80. package/src/client/shell/jam-voice.ts +479 -0
  81. package/src/client/shell/sound.ts +22 -0
  82. package/src/client/shell/stage-size.ts +11 -0
  83. package/src/client/shell/store.ts +47 -17
  84. package/src/client/shell/styles.css +564 -2
  85. package/src/client/stage/main.tsx +18 -2
  86. package/src/shared/capture-frames.ts +41 -0
  87. package/src/shared/events.ts +19 -4
  88. package/src/shared/speech.ts +16 -0
  89. package/templates/AGENTS-embedded.md +10 -2
  90. package/templates/AGENTS-studio.md +10 -2
  91. package/templates/instructions/iterate.md +8 -6
  92. package/templates/instructions/jam.md +131 -59
  93. package/dist/daemon-Cl8KXGW4.mjs +0 -1523
  94. package/dist/perf-QJIWtTw1.mjs +0 -68
  95. package/dist/shot-jdO_B6Qw.mjs +0 -86
@@ -1,7 +1,8 @@
1
- import { s as scanFrames } from "./manifest-DnAte_fB.mjs";
2
- import { r as replay, t as asks } from "./events-DnK_AnrW.mjs";
3
- import { a as readLog, i as listBoards } from "./comments-Zoch254k.mjs";
4
- import { o as projectMarks } from "./marks-koRsbHfe.mjs";
1
+ import { s as scanFrames } from "./manifest-Nl3KSVOk.mjs";
2
+ import { r as replay, t as asks } from "./events-CLH4ijKP.mjs";
3
+ import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
4
+ import { o as projectMarks } from "./marks-CKgzucHZ.mjs";
5
+ import { answers } from "./queue-29ok5_eZ.mjs";
5
6
  import { join } from "node:path";
6
7
  //#region src/shared/marks.ts
7
8
  const isNew = (m, id) => !!m && (m.changed[id] ?? 0) > (m.seen[id] ?? 0);
@@ -10,7 +11,9 @@ const isNew = (m, id) => !!m && (m.changed[id] ?? 0) > (m.seen[id] ?? 0);
10
11
  /**
11
12
  * `marver marks` (spec 26): what the human has not reviewed yet - the frames waiting on them (a
12
13
  * Marver thread whose last word is Marver's, the ones that ask first) and the frames new since they
13
- * looked. A read-only view of design/.local, a fresh scan of the frames and the comment logs:
14
+ * looked. Since 0.26 (spec 27) only a tag starts work, so it also lists what the human ANSWERED that
15
+ * nothing has acted on yet ("answered by you") - the coding agent's to-do for "go through my
16
+ * replies"; answers a 0.25 journal took in are apart, under "earlier, maybe handled". A read-only view of design/.local, a fresh scan of the frames and the comment logs:
14
17
  * running it writes nothing, so it never starts the clock, and it works with dev off.
15
18
  */
16
19
  function marksCommand(root, opts) {
@@ -30,10 +33,19 @@ function marksCommand(root, opts) {
30
33
  }];
31
34
  })).sort((a, b) => Number(b.asks) - Number(a.asks));
32
35
  const fresh = m ? manifest.frames.map((f) => f.id).filter((id) => isNew(m, id)) : [];
36
+ const { answered, earlier } = answers(root);
37
+ const said = (a) => ({
38
+ frame: a.frame,
39
+ thread: a.thread,
40
+ board: a.board,
41
+ body: a.body
42
+ });
33
43
  if (opts.json) {
34
44
  console.log(JSON.stringify({
35
45
  started: !!m,
36
46
  waiting,
47
+ answered: answered.map(said),
48
+ earlier: earlier.map(said),
37
49
  new: fresh
38
50
  }, null, 2));
39
51
  return;
@@ -43,6 +55,12 @@ function marksCommand(root, opts) {
43
55
  const w = Math.max(0, ...waiting.map((x) => x.frame.length)) + 2;
44
56
  if (waiting.length) waiting.forEach((x, i) => console.log(`${pad(i ? "" : `waiting on you (${waiting.length})`, 21)}${pad(x.frame, w)}${pad(x.asks ? "asks" : "", 6)}"${x.body.length > 60 ? x.body.slice(0, 57) + "..." : x.body}"`));
45
57
  else console.log(`${pad("waiting on you", 21)}nothing`);
58
+ const quote = (b) => `"${b.length > 60 ? b.slice(0, 57) + "..." : b}"`;
59
+ const aw = Math.max(0, ...answered.map((x) => (x.frame ?? x.board).length)) + 2;
60
+ if (answered.length) answered.forEach((x, i) => console.log(`${pad(i ? "" : `answered by you (${answered.length})`, 21)}${pad(x.frame ?? x.board, aw)}${pad(x.thread, 10)}${quote(x.body)}`));
61
+ else console.log(`${pad("answered by you", 21)}nothing`);
62
+ if (earlier.length && opts.all) earlier.forEach((x, i) => console.log(`${pad(i ? "" : `earlier, maybe handled (${earlier.length})`, 21)}${pad(x.frame ?? x.board, aw)}${pad(x.thread, 10)}${quote(x.body)}`));
63
+ else if (earlier.length) console.log(`${pad("earlier, maybe handled", 21)}${earlier.length} from before 0.26 - \`--all\` lists them`);
46
64
  const shown = fresh.slice(0, 6).join(", ") + (fresh.length > 6 ? `, ... (+${fresh.length - 6})` : "");
47
65
  console.log(`${pad(fresh.length ? `new (${fresh.length})` : "new", 21)}${fresh.length ? shown : "nothing"}`);
48
66
  }
@@ -1,6 +1,6 @@
1
- import { i as avatarSourceFor, n as attachAvatar, p as provisionFromMarverId } from "./auth-DdUKeVKt.mjs";
1
+ import { i as avatarSourceFor, n as attachAvatar, p as provisionFromMarverId } from "./auth-Dix8wrXV.mjs";
2
2
  import { TransactionStore, browserBinding, verifyAssertion } from "./marver-id-CVCoaMGI.mjs";
3
- import { t as poweredByUrl } from "./serve-wv2QWdxB.mjs";
3
+ import { t as poweredByUrl } from "./serve-C8rVheYk.mjs";
4
4
  import { randomBytes } from "node:crypto";
5
5
  import { isIP } from "node:net";
6
6
  import { lookup } from "node:dns/promises";
@@ -419,10 +419,10 @@ function marverIdHandler(dir, issuer, canvasName, branding = true, ceilings = {}
419
419
  console.warn(`[marver-id] ${result.identity.email} is not on this canvas's list`);
420
420
  let request;
421
421
  try {
422
- const { shareState, provisionVerdict } = await import("./auth-DdUKeVKt.mjs").then((n) => n.R);
422
+ const { shareState, provisionVerdict } = await import("./auth-Dix8wrXV.mjs").then((n) => n.R);
423
423
  const share = shareState(dir);
424
424
  if (!(share ? provisionVerdict(share, result.identity.email) === "blocked" : false)) {
425
- const { signCanvasJws } = await import("./summary-CrW88e3q.mjs");
425
+ const { signCanvasJws } = await import("./summary-Y8MY1Wuc.mjs");
426
426
  const now = Math.floor(Date.now() / 1e3);
427
427
  request = signCanvasJws(dir, {
428
428
  aud: origin,
@@ -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 };
@@ -1,4 +1,4 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { a as checkRealDirs } from "./boards-CGg6piKF.mjs";
3
3
  import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
4
4
  import { join } from "node:path";
@@ -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 };