@marver-design/marver 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +3 -1
  3. package/dist/{anchor-DVV732zR.mjs → anchor-5H1vnoLu.mjs} +6 -1
  4. package/dist/{anchor-check-BE5VVN6Q.mjs → anchor-check-Dg5xpNnU.mjs} +1 -1
  5. package/dist/audio-CmSRYFEs.mjs +429 -0
  6. package/dist/{auth-DdUKeVKt.mjs → auth-Dix8wrXV.mjs} +1 -1
  7. package/dist/{bake-D8byeRzB.mjs → bake-DtVlm0_F.mjs} +45 -6
  8. package/dist/{boards-Csxj2WJn.mjs → boards-DYG22tOe.mjs} +2 -2
  9. package/dist/{build-BHoWLvSj.mjs → build-C_gUgcdC.mjs} +16 -9
  10. package/dist/capture-CrqvU_jh.mjs +729 -0
  11. package/dist/cli.mjs +23 -17
  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-DZo6o3rU.mjs +2445 -0
  18. package/dist/{dev-DJdgow47.mjs → dev-_Nlsc6v9.mjs} +189 -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-NQi0wZJ4.mjs} +23 -5
  28. package/dist/{marver-id-gate-DGANtVyC.mjs → marver-id-gate-BjF6v4bT.mjs} +4 -4
  29. package/dist/{perf-QJIWtTw1.mjs → perf-D6VmmJ2q.mjs} +1 -1
  30. package/dist/{perf-CCisg-ny.mjs → perf-DPbLGhhO.mjs} +1 -1
  31. package/dist/{plugin-CTyhjwoJ.mjs → plugin-CTD0rydA.mjs} +279 -38
  32. package/dist/{poster-D0cbV7hi.mjs → poster-ChjXGTS5.mjs} +1 -1
  33. package/dist/{profile-Do0nGkXO.mjs → profile-WU9qcbIo.mjs} +1 -1
  34. package/dist/{publish-bakes--l8ot2eQ.mjs → publish-bakes-CEP_2NRc.mjs} +3 -3
  35. package/dist/queue-BuiCKSX1.mjs +1319 -0
  36. package/dist/reserve-BURNQ2Y3.mjs +53 -0
  37. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
  38. package/dist/{serve-wv2QWdxB.mjs → serve-C8rVheYk.mjs} +12 -12
  39. package/dist/session-qZWKt_VA.mjs +191 -0
  40. package/dist/{share-ScamJcks.mjs → share--oFJ1bCI.mjs} +2 -2
  41. package/dist/{shot-jdO_B6Qw.mjs → shot-CNbHoZ6H.mjs} +1 -1
  42. package/dist/{shot-CckrGW-J.mjs → shot-DqcxJibP.mjs} +4 -3
  43. package/dist/speech-models-DomiLQcY.mjs +299 -0
  44. package/dist/speech-worker.mjs +319 -0
  45. package/dist/{summary-CrW88e3q.mjs → summary-Y8MY1Wuc.mjs} +2 -2
  46. package/dist/{sync-C3035OnJ.mjs → sync-DKk-yT1V.mjs} +9 -8
  47. package/dist/{work-GE88wb_3.mjs → work-F5u-twpJ.mjs} +28 -5
  48. package/dist/{work-CpJn1gwY.mjs → work-VvX_JIgl.mjs} +2 -2
  49. package/docs/jam-session.md +177 -0
  50. package/docs/live-jam.md +21 -3
  51. package/package.json +7 -1
  52. package/src/client/frame-host/bridge.js +20 -2
  53. package/src/client/frame-host/inspect.d.ts +4 -0
  54. package/src/client/frame-host/inspect.js +88 -3
  55. package/src/client/frame-host/keys.d.ts +6 -0
  56. package/src/client/frame-host/keys.js +55 -0
  57. package/src/client/frame-host/trail.d.ts +7 -0
  58. package/src/client/frame-host/trail.js +204 -0
  59. package/src/client/shell/App.tsx +45 -5
  60. package/src/client/shell/Comments.tsx +20 -6
  61. package/src/client/shell/JamSurface.tsx +340 -0
  62. package/src/client/shell/Play.tsx +22 -3
  63. package/src/client/shell/Tip.tsx +8 -3
  64. package/src/client/shell/canvas/Canvas.tsx +12 -2
  65. package/src/client/shell/canvas/FrameNode.tsx +11 -2
  66. package/src/client/shell/canvas/sleep.ts +19 -1
  67. package/src/client/shell/comments-store.ts +23 -16
  68. package/src/client/shell/icons.tsx +15 -0
  69. package/src/client/shell/jam-capture.ts +939 -0
  70. package/src/client/shell/jam-keys.ts +329 -0
  71. package/src/client/shell/jam-lane.tsx +208 -0
  72. package/src/client/shell/jam-lines.ts +115 -0
  73. package/src/client/shell/jam-panel.tsx +506 -0
  74. package/src/client/shell/jam-queue.ts +126 -0
  75. package/src/client/shell/jam-session.tsx +389 -0
  76. package/src/client/shell/jam-state.ts +61 -0
  77. package/src/client/shell/jam-surface-parts.tsx +102 -0
  78. package/src/client/shell/jam-ui.tsx +104 -0
  79. package/src/client/shell/jam-voice.ts +479 -0
  80. package/src/client/shell/sound.ts +22 -0
  81. package/src/client/shell/stage-size.ts +11 -0
  82. package/src/client/shell/store.ts +34 -13
  83. package/src/client/shell/styles.css +544 -2
  84. package/src/client/stage/main.tsx +16 -2
  85. package/src/shared/capture-frames.ts +41 -0
  86. package/src/shared/events.ts +19 -4
  87. package/src/shared/speech.ts +16 -0
  88. package/templates/AGENTS-embedded.md +10 -2
  89. package/templates/AGENTS-studio.md +10 -2
  90. package/templates/instructions/iterate.md +8 -6
  91. package/templates/instructions/jam.md +129 -59
  92. package/dist/daemon-Cl8KXGW4.mjs +0 -1523
@@ -0,0 +1,53 @@
1
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ //#region src/server/jam/reserve.ts
4
+ /**
5
+ * One reservation table for every writer (spec 27, "One job per frame"). A jam batch reserves
6
+ * every frame its cards name; `marver work start` holds frames for a chat agent. A batch starts
7
+ * only when none of its frames is held, and `work start` on a frame a batch holds is refused - one
8
+ * table, both directions. An exclusive job (a shared file, a board-level comment) reserves the
9
+ * whole canvas: while it waits or runs, no new batch starts and no NEW hold is taken, but a hold
10
+ * that already exists may renew and end, so an agent mid-edit never loses it.
11
+ *
12
+ * The jam side lives in memory (the daemon re-forms it at boot from the journal); the CLI's holds
13
+ * are written to design/.local/work-holds.json with their expiry and restored at boot, before any
14
+ * batch is scheduled, so a hold taken before a restart still holds after it.
15
+ */
16
+ /** One per process - the daemon writes it, the work route reads it. */
17
+ const jamReservations = {
18
+ frames: /* @__PURE__ */ new Map(),
19
+ exclusive: null
20
+ };
21
+ /** Why `work start` may not take `frame` now, or null. `holding`: the CLI already holds it (a
22
+ * renewal is always allowed). */
23
+ function refuseHold(frame, holding, r = jamReservations) {
24
+ if (holding) return null;
25
+ if (r.frames.has(frame)) return "Marver is working on this frame - try again when it is done";
26
+ if (r.exclusive) return "Marver is changing a shared file - try again when it is done";
27
+ if (r.settling) return "Marver is finishing a job - try again in a moment";
28
+ return null;
29
+ }
30
+ const holdsFile = (root) => join(root, "design", ".local", "work-holds.json");
31
+ /** Write the CLI's unexpired holds (frame and expiry only). Best-effort and atomic. */
32
+ function saveHolds(root, activity) {
33
+ try {
34
+ mkdirSync(join(root, "design", ".local"), { recursive: true });
35
+ const tmp = `${holdsFile(root)}.tmp`;
36
+ writeFileSync(tmp, JSON.stringify(Object.fromEntries(activity.leases("cli"))), { mode: 384 });
37
+ renameSync(tmp, holdsFile(root));
38
+ } catch {}
39
+ }
40
+ /** Bring back the holds a previous server wrote - expired ones stay gone. */
41
+ function restoreHolds(root, activity) {
42
+ let n = 0;
43
+ try {
44
+ const v = JSON.parse(readFileSync(holdsFile(root), "utf8"));
45
+ for (const [frame, until] of Object.entries(v ?? {})) if (typeof until === "number" && until > Date.now()) {
46
+ activity.restore(frame, until, "cli");
47
+ n++;
48
+ }
49
+ } catch {}
50
+ return n;
51
+ }
52
+ //#endregion
53
+ export { jamReservations, refuseHold, restoreHolds, saveHolds };
@@ -1,3 +1,4 @@
1
+ import "node:module";
1
2
  //#region \0rolldown/runtime.js
2
3
  var __defProp = Object.defineProperty;
3
4
  var __exportAll = (all, no_symbols) => {
@@ -75,9 +75,9 @@ async function serve(root, portFlag) {
75
75
  * accounts get in. Null when there is no roster to consult. */
76
76
  let guestDoorOpen = null;
77
77
  if (process.env.MARVER_DATA_DIR) {
78
- const { collabHandler } = await import("./collab-gqNdScUE.mjs");
79
- const { appendEvents, readLog } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
80
- const { dataDir } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
78
+ const { collabHandler } = await import("./collab-Dxg2trOK.mjs");
79
+ const { appendEvents, readLog } = await import("./comments-0BSbb04K.mjs").then((n) => n.n);
80
+ const { dataDir } = await import("./comments-0BSbb04K.mjs").then((n) => n.n);
81
81
  const dir = dataDir();
82
82
  for (const seedDir of [join(root, "design", ".dist-seeds"), join(dist, "design", "comments")]) {
83
83
  if (!existsSync(seedDir)) continue;
@@ -88,8 +88,8 @@ async function serve(root, portFlag) {
88
88
  }
89
89
  }
90
90
  collab = collabHandler(dir, dist);
91
- const { loadStore, createInvite, normEmail, operatorUser, sessionUser } = await import("./auth-DdUKeVKt.mjs").then((n) => n.r);
92
- const share = await import("./auth-DdUKeVKt.mjs").then((n) => n.R);
91
+ const { loadStore, createInvite, normEmail, operatorUser, sessionUser } = await import("./auth-Dix8wrXV.mjs").then((n) => n.r);
92
+ const share = await import("./auth-Dix8wrXV.mjs").then((n) => n.R);
93
93
  const ceilings = share.ceilingsFromRights(meta.rights ?? {});
94
94
  const admitted = (u) => !!u && share.entryAllowed(dir, u, ceilings);
95
95
  guestDoorOpen = () => {
@@ -119,7 +119,7 @@ async function serve(root, portFlag) {
119
119
  }
120
120
  const cliToken = process.env.MARVER_CLI_TOKEN ?? "";
121
121
  if (cliToken) {
122
- const { cliTokenProblem } = await import("./auth-DdUKeVKt.mjs").then((n) => n.r);
122
+ const { cliTokenProblem } = await import("./auth-Dix8wrXV.mjs").then((n) => n.r);
123
123
  if (!process.env.MARVER_DATA_DIR) {
124
124
  console.error(`[${NAME}] MARVER_CLI_TOKEN needs MARVER_DATA_DIR - there are no accounts for it to act as otherwise.`);
125
125
  process.exit(1);
@@ -147,10 +147,10 @@ async function serve(root, portFlag) {
147
147
  console.error(`[${NAME}] MARVER_ID_ISSUER is set but MARVER_PUBLIC_ORIGIN is not.\n Every assertion is bound to this canvas's exact origin, and it cannot be\n inferred from request headers - a proxy can make any request look local.\n Set it to the origin people actually reach this canvas on:\n MARVER_PUBLIC_ORIGIN=https://canvas.example.com\n MARVER_PUBLIC_ORIGIN=http://localhost:${portFlag ?? (Number(process.env.PORT) || 4199)} (development)`);
148
148
  process.exit(1);
149
149
  }
150
- const { marverIdHandler } = await import("./marver-id-gate-DGANtVyC.mjs");
151
- const { dataDir } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
150
+ const { marverIdHandler } = await import("./marver-id-gate-BjF6v4bT.mjs");
151
+ const { dataDir } = await import("./comments-0BSbb04K.mjs").then((n) => n.n);
152
152
  const canvasName = humanName(meta.name);
153
- const { ceilingsFromRights } = await import("./auth-DdUKeVKt.mjs").then((n) => n.R);
153
+ const { ceilingsFromRights } = await import("./auth-Dix8wrXV.mjs").then((n) => n.R);
154
154
  idHandler = marverIdHandler(dataDir(), idIssuer, canvasName, meta.branding, ceilingsFromRights(meta.rights ?? {}));
155
155
  }
156
156
  if (idIssuer && process.env.MARVER_PASSWORD) console.log(` note: MARVER_ID_ISSUER and MARVER_PASSWORD are both set - the identity gate wins, the password is IGNORED`);
@@ -168,9 +168,9 @@ async function serve(root, portFlag) {
168
168
  };
169
169
  const gated = Boolean(verifier || idIssuer);
170
170
  if (collab) {
171
- const { ensureShare, reclampShare, ceilingsFromRights } = await import("./auth-DdUKeVKt.mjs").then((n) => n.R);
172
- const { loadStore } = await import("./auth-DdUKeVKt.mjs").then((n) => n.r);
173
- const { dataDir } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
171
+ const { ensureShare, reclampShare, ceilingsFromRights } = await import("./auth-Dix8wrXV.mjs").then((n) => n.R);
172
+ const { loadStore } = await import("./auth-Dix8wrXV.mjs").then((n) => n.r);
173
+ const { dataDir } = await import("./comments-0BSbb04K.mjs").then((n) => n.n);
174
174
  const dir = dataDir();
175
175
  const ceilings = ceilingsFromRights(meta.rights ?? {});
176
176
  const mode = idIssuer ? "private" : verifier ? "password" : "public";
@@ -0,0 +1,191 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { f as readCapture } from "./capture-CrqvU_jh.mjs";
3
+ import { appendFileSync, closeSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, writeSync } from "node:fs";
4
+ import { dirname, join, relative, sep } from "node:path";
5
+ import { createHash, randomBytes } from "node:crypto";
6
+ //#region src/server/jam/session.ts
7
+ /**
8
+ * The Jam session (spec 27, Part 5): `J` starts one, `J` again ends it with a wrap-up.
9
+ *
10
+ * While a session runs, the microphone is live and what is said BETWEEN captures - its talk - is kept in
11
+ * `design/.local/jam/sessions/<id>.jsonl` (local, never committed, sent to no agent unless you say so at
12
+ * the end). Every capture made in it carries the session.
13
+ *
14
+ * "Write the record" seals a wrap-up into `design/.local/jam/wrapups/<id>.json` - your instructions
15
+ * first, every confirmed capture of the session (its record, your edit, its card's state and reply), the
16
+ * kept ones (as kept), the verdicts, and the talk if you left that on - ledgered with its hash and checked
17
+ * again at claim, like a capture. Drafts and dropped captures are left out; tags are answered in their
18
+ * threads and are not in it. The agent writes the record to `context/sessions/<date>-<slug>.md` (or
19
+ * `design/sessions/` with no `context/`) and nothing else.
20
+ */
21
+ var session_exports = /* @__PURE__ */ __exportAll({
22
+ SESSION_ID: () => SESSION_ID,
23
+ WRAPUP_ID: () => WRAPUP_ID,
24
+ appendTalk: () => appendTalk,
25
+ buildWrapup: () => buildWrapup,
26
+ moreOf: () => moreOf,
27
+ readTalk: () => readTalk,
28
+ readWrapup: () => readWrapup,
29
+ recordFile: () => recordFile,
30
+ recordPathProblem: () => recordPathProblem,
31
+ storeWrapup: () => storeWrapup,
32
+ talkMinutes: () => talkMinutes
33
+ });
34
+ const SESSION_ID = /^ses-\d{10,16}-[a-z0-9]{4,12}$/;
35
+ const WRAPUP_ID = /^wrap-\d{10,16}-[a-z0-9]{4,12}$/;
36
+ const jamDir = (root) => join(root, "design", ".local", "jam");
37
+ const sessionsDir = (root) => join(jamDir(root), "sessions");
38
+ const wrapupsDir = (root) => join(jamDir(root), "wrapups");
39
+ const hashOf = (s) => createHash("sha256").update(s).digest("hex");
40
+ /** Words said between captures: one line per phrase, appended to the session's transcript. */
41
+ function appendTalk(root, session, words) {
42
+ if (!SESSION_ID.test(session) || !words.length) return;
43
+ mkdirSync(sessionsDir(root), { recursive: true });
44
+ const line = {
45
+ at: words[0].at,
46
+ text: words.map((w) => w.w).join(" "),
47
+ words: words.map((w) => ({
48
+ w: w.w,
49
+ at: w.at
50
+ }))
51
+ };
52
+ appendFileSync(join(sessionsDir(root), `${session}.jsonl`), JSON.stringify(line) + "\n", { mode: 384 });
53
+ }
54
+ function readTalk(root, session) {
55
+ if (!SESSION_ID.test(session)) return [];
56
+ try {
57
+ return readFileSync(join(sessionsDir(root), `${session}.jsonl`), "utf8").split("\n").flatMap((l) => {
58
+ try {
59
+ const x = JSON.parse(l);
60
+ return typeof x?.text === "string" && Number.isFinite(x.at) ? [x] : [];
61
+ } catch {
62
+ return [];
63
+ }
64
+ });
65
+ } catch {
66
+ return [];
67
+ }
68
+ }
69
+ /** How long the talk runs, for the sheet ("26 min"): from its first line to its last. */
70
+ const talkMinutes = (talk) => talk.length ? Math.max(1, Math.round((talk[talk.length - 1].at - talk[0].at) / 6e4)) : 0;
71
+ /** The record's file: `context/sessions/<date>-<hhmm>-<session>.md`, or `design/sessions/` with no
72
+ * `context/` - the session's own id in it, so two sessions never write one file. */
73
+ function recordFile(root, since, session = "ses-0-session") {
74
+ const d = new Date(since);
75
+ const pad = (n) => String(n).padStart(2, "0");
76
+ const date = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
77
+ const tail = (/^ses-\d+-([a-z0-9]+)$/.exec(session)?.[1] ?? "session").slice(0, 12);
78
+ const name = `${date}-${pad(d.getHours())}${pad(d.getMinutes())}-session-${tail}.md`;
79
+ return existsSync(join(root, "context")) ? `context/sessions/${name}` : `design/sessions/${name}`;
80
+ }
81
+ /** Why a record path is not safe to write or read, or null: it must be a plain `.md` under
82
+ * `context/sessions/` or `design/sessions/`, and no part of it that exists - the folders or the file -
83
+ * may be a link (a link would send the agent's write, or the panel's read, somewhere else). */
84
+ function recordPathProblem(root, file) {
85
+ if (!/^(context|design)\/sessions\/[a-z0-9][a-z0-9-]*\.md$/.test(file)) return "not a session record path";
86
+ let rootReal;
87
+ try {
88
+ rootReal = realpathSync(root);
89
+ } catch {
90
+ return "the project folder is not there";
91
+ }
92
+ let at = root;
93
+ for (const part of file.split("/")) {
94
+ at = join(at, part);
95
+ let st;
96
+ try {
97
+ st = lstatSync(at);
98
+ } catch {
99
+ break;
100
+ }
101
+ if (st.isSymbolicLink()) return `${relative(root, at)} is a link`;
102
+ }
103
+ let probe = join(root, file);
104
+ while (!existsSync(probe) && probe !== root) probe = dirname(probe);
105
+ try {
106
+ const real = realpathSync(probe);
107
+ if (real !== rootReal && !real.startsWith(rootReal + sep)) return "it leads outside the project";
108
+ } catch {
109
+ return "it cannot be checked";
110
+ }
111
+ return null;
112
+ }
113
+ /** What the wrap-up says of the session, at this moment ("as of"). */
114
+ function buildWrapup(j, root, o) {
115
+ const now = o.now ?? Date.now();
116
+ const caps = [];
117
+ for (const c of j.cards.filter((x) => x.kind === "capture" && x.session === o.session).sort((a, b) => a.made - b.made)) {
118
+ if (c.state === "draft" || c.state === "dropped" || c.state === "confirming") continue;
119
+ if (o.intact && !o.intact(c)) return { error: "a capture of the session changed after it was confirmed - capture it again, then write the record" };
120
+ const cap = readCapture(root, c.id);
121
+ if (!cap) return { error: "a capture of the session is gone - write the record again without it" };
122
+ const verdict = c.verdict;
123
+ caps.push({
124
+ id: c.id,
125
+ title: o.title?.(c) ?? c.name ?? c.id,
126
+ state: c.state,
127
+ ...c.state === "kept" ? { kept: true } : {},
128
+ record: cap.record,
129
+ ...c.payload?.edited !== void 0 ? { edited: c.payload.edited } : {},
130
+ ...c.payload?.added?.length ? { added: c.payload.added } : {},
131
+ ...o.reply?.(c) ? { reply: o.reply(c) } : {},
132
+ ...verdict ? { verdict } : {},
133
+ ...o.more?.(c).length ? { more: o.more(c) } : {}
134
+ });
135
+ }
136
+ const talk = o.includeTalk ? readTalk(root, o.session) : void 0;
137
+ return {
138
+ format: "marver.jam.wrapup",
139
+ v: 1,
140
+ id: `wrap-${now}-${randomBytes(4).toString("hex").slice(0, 6)}`,
141
+ session: o.session,
142
+ since: o.since,
143
+ until: now,
144
+ instructions: o.instructions.slice(0, 2e4),
145
+ file: recordFile(root, o.since, o.session),
146
+ captures: caps,
147
+ tags: o.tags,
148
+ ...talk ? { talk } : {}
149
+ };
150
+ }
151
+ /** More work on a record: the same content - its captures, talk and file - with your note, as a wrap-up of
152
+ * its own (sealed and ledgered like the first). */
153
+ function moreOf(prev, note, now = Date.now()) {
154
+ return {
155
+ ...prev,
156
+ id: `wrap-${now}-${randomBytes(4).toString("hex").slice(0, 6)}`,
157
+ more: note.slice(0, 2e4)
158
+ };
159
+ }
160
+ /** Seal a wrap-up once (a second store of the same id is refused). Returns its hash. */
161
+ function storeWrapup(root, w) {
162
+ mkdirSync(wrapupsDir(root), { recursive: true });
163
+ const file = join(wrapupsDir(root), `${w.id}.json`);
164
+ if (existsSync(file)) throw new Error("a wrap-up is already stored under this id");
165
+ const body = JSON.stringify(w);
166
+ const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
167
+ const fd = openSync(tmp, "w", 384);
168
+ try {
169
+ writeSync(fd, body);
170
+ fsyncSync(fd);
171
+ } finally {
172
+ closeSync(fd);
173
+ }
174
+ renameSync(tmp, file);
175
+ return hashOf(body);
176
+ }
177
+ /** A stored wrap-up and the hash of its bytes as they are now (changed after the seal: refused at claim). */
178
+ function readWrapup(root, id) {
179
+ if (!WRAPUP_ID.test(id)) return null;
180
+ try {
181
+ const body = readFileSync(join(wrapupsDir(root), `${id}.json`), "utf8");
182
+ return {
183
+ wrapup: JSON.parse(body),
184
+ hash: hashOf(body)
185
+ };
186
+ } catch {
187
+ return null;
188
+ }
189
+ }
190
+ //#endregion
191
+ export { recordFile as a, storeWrapup as c, readWrapup as i, buildWrapup as n, recordPathProblem as o, moreOf as r, session_exports as s, SESSION_ID as t };
@@ -1,6 +1,6 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { M as resolveAccess } from "./auth-DdUKeVKt.mjs";
3
- import { i as loadCollab } from "./sync-C3035OnJ.mjs";
2
+ import { M as resolveAccess } from "./auth-Dix8wrXV.mjs";
3
+ import { i as loadCollab } from "./sync-DKk-yT1V.mjs";
4
4
  //#region src/cli/share.ts
5
5
  /**
6
6
  * `marver share <action>` - the roster from the terminal (01-sharing §9).
@@ -1,5 +1,5 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { i as readDevInfo } from "./work-GE88wb_3.mjs";
2
+ import { i as readDevInfo } from "./work-F5u-twpJ.mjs";
3
3
  //#region src/cli/shot.ts
4
4
  /**
5
5
  * `marver shot <scene/frame> [...]`, `--scene <name>`, `--all` - render frames headless and
@@ -104,13 +104,14 @@ var Browser = class Browser {
104
104
  }
105
105
  /** Spawn and handshake (`Browser.getVersion` within 15s), or throw with the reason. A Chrome
106
106
  * that starts but never brings up CDP is killed here - it can never hold a lane. */
107
- static async launch(prefix = "mv-shot-") {
107
+ static async launch(prefix = "mv-shot-", extra = []) {
108
108
  const bin = findChrome();
109
109
  if (!bin) throw new Error("no Chrome/Chromium found - install one or set MARVER_CHROME to a browser binary");
110
110
  const b = new Browser();
111
111
  b.profile = mkdtempSync(join(tmpdir(), prefix));
112
112
  b.proc = spawn(bin, [
113
113
  ...FLAGS,
114
+ ...extra,
114
115
  `--user-data-dir=${b.profile}`,
115
116
  "--remote-debugging-pipe",
116
117
  "about:blank"
@@ -333,8 +334,8 @@ async function shootFrame(opts) {
333
334
  };
334
335
  const plan = planShot(frame, viewports, size);
335
336
  if (frame.kind !== "html") try {
336
- const { scanAssetRefs } = await import("./build-BHoWLvSj.mjs");
337
- const { ensurePoster } = await import("./poster-D0cbV7hi.mjs");
337
+ const { scanAssetRefs } = await import("./build-C_gUgcdC.mjs");
338
+ const { ensurePoster } = await import("./poster-ChjXGTS5.mjs");
338
339
  const refs = scanAssetRefs(readFileSync(join(root, frame.file), "utf8"), frame.file);
339
340
  for (const r of refs) if (r.endsWith(".poster.png")) await ensurePoster(join(root, "design", "assets"), r.slice(0, -11));
340
341
  } catch {}
@@ -0,0 +1,299 @@
1
+ import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { createHash, randomBytes } from "node:crypto";
4
+ import { homedir } from "node:os";
5
+ import { spawn } from "node:child_process";
6
+ import { Readable } from "node:stream";
7
+ import { pipeline } from "node:stream/promises";
8
+ //#region src/server/jam/speech-models.ts
9
+ /**
10
+ * The speech model, on this Mac (spec 27, Part 4): Parakeet TDT 0.6B v3 (int8) transcribes, Silero VAD
11
+ * cuts phrases. Downloaded once - only after you say yes - to `~/.marver/models/`, and every file is
12
+ * checked against the hash it was published with before it is used. Nothing here runs a model; the
13
+ * worker does (speech-worker.ts).
14
+ */
15
+ const RELEASE = "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/";
16
+ const ARCHIVE = {
17
+ name: "sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8.tar.bz2",
18
+ sha256: "5793d0fd397c5778d2cf2126994d58e9d56b1be7c04d13c7a15bb1b4eafb16bf",
19
+ bytes: 487170055
20
+ };
21
+ const PARAKEET_DIR = "sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8";
22
+ /** The files the recognizer reads, in the archive's folder - each checked before use. */
23
+ const PARAKEET_FILES = {
24
+ encoder: {
25
+ file: "encoder.int8.onnx",
26
+ sha256: "acfc2b4456377e15d04f0243af540b7fe7c992f8d898d751cf134c3a55fd2247"
27
+ },
28
+ decoder: {
29
+ file: "decoder.int8.onnx",
30
+ sha256: "179e50c43d1a9de79c8a24149a2f9bac6eb5981823f2a2ed88d655b24248db4e"
31
+ },
32
+ joiner: {
33
+ file: "joiner.int8.onnx",
34
+ sha256: "3164c13fc2821009440d20fcb5fdc78bff28b4db2f8d0f0b329101719c0948b3"
35
+ },
36
+ tokens: {
37
+ file: "tokens.txt",
38
+ sha256: "d58544679ea4bc6ac563d1f545eb7d474bd6cfa467f0a6e2c1dc1c7d37e3c35d"
39
+ }
40
+ };
41
+ const VAD = {
42
+ name: "silero_vad.onnx",
43
+ sha256: "9e2449e1087496d8d4caba907f23e0bd3f78d91fa552479bb9c23ac09cbb1fd6",
44
+ bytes: 643854
45
+ };
46
+ /** About what the download weighs, for the question ("490 MB, once"). */
47
+ const DOWNLOAD_MB = Math.round((ARCHIVE.bytes + VAD.bytes) / 1e6);
48
+ /** Where the models live: `~/.marver/models/` (MARVER_MODELS points elsewhere - the tests). */
49
+ const modelsDir = () => process.env.MARVER_MODELS || join(homedir(), ".marver", "models");
50
+ const modelPaths = (dir = modelsDir()) => ({
51
+ encoder: join(dir, PARAKEET_DIR, PARAKEET_FILES.encoder.file),
52
+ decoder: join(dir, PARAKEET_DIR, PARAKEET_FILES.decoder.file),
53
+ joiner: join(dir, PARAKEET_DIR, PARAKEET_FILES.joiner.file),
54
+ tokens: join(dir, PARAKEET_DIR, PARAKEET_FILES.tokens.file),
55
+ vad: join(dir, VAD.name)
56
+ });
57
+ const sha256File = async (path) => {
58
+ const h = createHash("sha256");
59
+ await pipeline(createReadStream(path), h);
60
+ return h.digest("hex");
61
+ };
62
+ /** A hash checked once per file per process (by its size and mtime): the 650 MB encoder is hashed once. */
63
+ const checked = /* @__PURE__ */ new Map();
64
+ async function fileOk(path, sha256) {
65
+ let st;
66
+ try {
67
+ st = statSync(path);
68
+ } catch {
69
+ return false;
70
+ }
71
+ const key = `${path}|${st.size}|${st.mtimeMs}`;
72
+ if (checked.get(key) === sha256) return true;
73
+ const ok = await sha256File(path) === sha256;
74
+ if (ok) checked.set(key, sha256);
75
+ return ok;
76
+ }
77
+ /** Are the model files there, each the one published? */
78
+ async function modelsReady(dir = modelsDir()) {
79
+ const p = modelPaths(dir);
80
+ const all = [...Object.keys(PARAKEET_FILES).map((k) => [p[k], PARAKEET_FILES[k].sha256]), [p.vad, VAD.sha256]];
81
+ for (const [path, sha] of all) if (!await fileOk(path, sha)) return false;
82
+ return true;
83
+ }
84
+ let download = {
85
+ state: "idle",
86
+ received: 0,
87
+ total: ARCHIVE.bytes + VAD.bytes
88
+ };
89
+ let running = null;
90
+ const downloadState = () => ({ ...download });
91
+ /** Fetch one file to `dest` through a temporary name, counting bytes; refuse it unless its hash matches. */
92
+ async function fetchChecked(url, dest, sha256, onBytes, fetchImpl) {
93
+ const tmp = `${dest}.part`;
94
+ const res = await fetchImpl(url);
95
+ if (!res.ok || !res.body) throw new Error(`download failed (${res.status}) - ${url}`);
96
+ const h = createHash("sha256");
97
+ const body = Readable.fromWeb(res.body);
98
+ body.on("data", (c) => {
99
+ h.update(c);
100
+ onBytes(c.length);
101
+ });
102
+ await pipeline(body, createWriteStream(tmp));
103
+ if (h.digest("hex") !== sha256) {
104
+ rmSync(tmp, { force: true });
105
+ throw new Error(`${dest.split("/").pop()} did not match its published hash - nothing was kept`);
106
+ }
107
+ renameSync(tmp, dest);
108
+ }
109
+ const untar = (archive, into) => new Promise((resolve, reject) => {
110
+ const p = spawn("tar", [
111
+ "-xjf",
112
+ archive,
113
+ "-C",
114
+ into
115
+ ], { stdio: "ignore" });
116
+ p.on("error", reject);
117
+ p.on("exit", (code) => code === 0 ? resolve() : reject(/* @__PURE__ */ new Error(`tar exited ${code}`)));
118
+ });
119
+ const alive = (pid) => {
120
+ try {
121
+ process.kill(pid, 0);
122
+ return true;
123
+ } catch (e) {
124
+ return e.code === "EPERM";
125
+ }
126
+ };
127
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
128
+ /** A lock file unreadable (half written by a process that died writing it) for this long is stale. */
129
+ const LOCK_GRACE = 1e4;
130
+ const ageOf = (f) => {
131
+ try {
132
+ return Date.now() - statSync(f).mtimeMs;
133
+ } catch {
134
+ return 0;
135
+ }
136
+ };
137
+ /** A lock's text, or null when there is no lock; any other read error (permissions) is thrown - waited on,
138
+ * it would never change. */
139
+ const readRaw = (f) => {
140
+ try {
141
+ return readFileSync(f, "utf8");
142
+ } catch (e) {
143
+ if (e.code === "ENOENT") return null;
144
+ throw e;
145
+ }
146
+ };
147
+ /** Take the download lock (one installer at a time, across dev servers). Resolves to this installer's
148
+ * token, or to 'done' when another process finished the models while this one waited. A stale lock - its
149
+ * process gone, or unreadable past the grace - is reclaimed by one process at a time, under a guard, and
150
+ * only if it is still the same stale lock. */
151
+ async function takeLock(lock, dir) {
152
+ const token = `${process.pid}-${randomBytes(6).toString("hex")}`;
153
+ for (;;) {
154
+ try {
155
+ writeFileSync(lock, JSON.stringify({
156
+ pid: process.pid,
157
+ token
158
+ }), { flag: "wx" });
159
+ return token;
160
+ } catch (e) {
161
+ if (e.code !== "EEXIST") throw e;
162
+ }
163
+ const raw = readRaw(lock);
164
+ if (raw === null) {
165
+ await sleep(50);
166
+ continue;
167
+ }
168
+ let pid = 0;
169
+ try {
170
+ pid = Number(JSON.parse(raw).pid) || 0;
171
+ } catch {
172
+ pid = 0;
173
+ }
174
+ if (pid ? !alive(pid) : ageOf(lock) > LOCK_GRACE) {
175
+ const guard = `${lock}.reclaim`;
176
+ try {
177
+ writeFileSync(guard, String(process.pid), { flag: "wx" });
178
+ } catch (e) {
179
+ if (e.code !== "EEXIST") throw e;
180
+ if (ageOf(guard) > LOCK_GRACE) rmSync(guard, { force: true });
181
+ await sleep(200);
182
+ continue;
183
+ }
184
+ try {
185
+ if (readRaw(lock) === raw) rmSync(lock, { force: true });
186
+ } finally {
187
+ rmSync(guard, { force: true });
188
+ }
189
+ continue;
190
+ }
191
+ await sleep(1e3);
192
+ if (!existsSync(lock) && await modelsReady(dir)) return "done";
193
+ }
194
+ }
195
+ /** Release the lock - only this installer's own. */
196
+ const dropLock = (lock, token) => {
197
+ try {
198
+ const raw = readRaw(lock);
199
+ if (raw && JSON.parse(raw).token === token) rmSync(lock, { force: true });
200
+ } catch {}
201
+ };
202
+ /** Download the models (once - a second call joins the first; another dev server downloading them is
203
+ * waited for, through a lock file). Everything lands in a staging folder of this process first, is
204
+ * checked there, and only then moves into place; a failure leaves nothing behind. */
205
+ function downloadModels(dir = modelsDir(), fetchImpl = fetch) {
206
+ if (running) return running;
207
+ download = {
208
+ state: "downloading",
209
+ received: 0,
210
+ total: ARCHIVE.bytes + VAD.bytes
211
+ };
212
+ running = (async () => {
213
+ const lock = join(dir, ".download.lock");
214
+ let token;
215
+ try {
216
+ mkdirSync(dir, { recursive: true });
217
+ token = await takeLock(lock, dir);
218
+ } catch (err) {
219
+ download = {
220
+ ...download,
221
+ state: "failed",
222
+ error: `the download could not start: ${err.message}`
223
+ };
224
+ return;
225
+ }
226
+ if (token === "done") {
227
+ download = {
228
+ ...download,
229
+ state: "done",
230
+ received: download.total
231
+ };
232
+ return;
233
+ }
234
+ const stage = join(dir, `.staging-${process.pid}-${randomBytes(4).toString("hex")}`);
235
+ try {
236
+ mkdirSync(stage, { recursive: true });
237
+ const count = (n) => {
238
+ download.received += n;
239
+ };
240
+ const p = modelPaths(dir);
241
+ if (!await fileOk(p.vad, VAD.sha256)) await fetchChecked(RELEASE + VAD.name, join(stage, VAD.name), VAD.sha256, count, fetchImpl);
242
+ else download.received += VAD.bytes;
243
+ const parakeetOk = await (async () => {
244
+ for (const k of Object.keys(PARAKEET_FILES)) if (!await fileOk(p[k], PARAKEET_FILES[k].sha256)) return false;
245
+ return true;
246
+ })();
247
+ if (!parakeetOk) {
248
+ const archive = join(stage, ARCHIVE.name);
249
+ await fetchChecked(RELEASE + ARCHIVE.name, archive, ARCHIVE.sha256, count, fetchImpl);
250
+ download.state = "checking";
251
+ await untar(archive, stage);
252
+ rmSync(archive, { force: true });
253
+ if (!await parakeetIn(stage)) throw new Error("the unpacked model did not match its published hashes");
254
+ } else download.received += ARCHIVE.bytes;
255
+ download.state = "checking";
256
+ if (!parakeetOk) {
257
+ rmSync(join(dir, PARAKEET_DIR), {
258
+ recursive: true,
259
+ force: true
260
+ });
261
+ renameSync(join(stage, PARAKEET_DIR), join(dir, PARAKEET_DIR));
262
+ }
263
+ if (existsSync(join(stage, VAD.name))) renameSync(join(stage, VAD.name), p.vad);
264
+ if (!await modelsReady(dir)) throw new Error("the model did not match its published hashes once in place");
265
+ download.state = "done";
266
+ } catch (err) {
267
+ download = {
268
+ ...download,
269
+ state: "failed",
270
+ error: err.message
271
+ };
272
+ } finally {
273
+ try {
274
+ rmSync(stage, {
275
+ recursive: true,
276
+ force: true
277
+ });
278
+ } catch {}
279
+ dropLock(lock, token);
280
+ }
281
+ })().catch((err) => {
282
+ download = {
283
+ ...download,
284
+ state: "failed",
285
+ error: err.message
286
+ };
287
+ }).finally(() => {
288
+ running = null;
289
+ });
290
+ return running;
291
+ }
292
+ /** The recognizer's files, checked, in a folder (the staging one: the VAD may already be in place). */
293
+ async function parakeetIn(dir) {
294
+ const p = modelPaths(dir);
295
+ for (const k of Object.keys(PARAKEET_FILES)) if (!await fileOk(p[k], PARAKEET_FILES[k].sha256)) return false;
296
+ return true;
297
+ }
298
+ //#endregion
299
+ export { DOWNLOAD_MB, downloadModels, downloadState, modelPaths, modelsReady };