@marver-design/marver 0.26.0 → 0.27.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 (96) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/README.md +10 -5
  3. package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
  4. package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
  5. package/dist/{bake-DtVlm0_F.mjs → bake-DM_uWgAA.mjs} +1 -1
  6. package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
  7. package/dist/{build-C_gUgcdC.mjs → build-DZnFysGU.mjs} +4 -4
  8. package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
  9. package/dist/cli.mjs +28 -16
  10. package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
  11. package/dist/{daemon-DZo6o3rU.mjs → daemon-BSA0lV8d.mjs} +400 -274
  12. package/dist/detect-C0wpaePX.mjs +125 -0
  13. package/dist/dev-eQJhWsqg.mjs +1273 -0
  14. package/dist/dev-lock-C_FC70Mu.mjs +65 -0
  15. package/dist/exclusive-B1RtpeeP.mjs +150 -0
  16. package/dist/{init-D8DtrK_F.mjs → init-COD0x48i.mjs} +5 -3
  17. package/dist/{link-BNzLvdhI.mjs → link-DDXZVGtv.mjs} +20 -8
  18. package/dist/ls-D7O1G505.mjs +38 -0
  19. package/dist/{marks-NQi0wZJ4.mjs → marks-CWM3WJjc.mjs} +1 -1
  20. package/dist/perf-BWzQwZqj.mjs +369 -0
  21. package/dist/perf-BoDSkbEb.mjs +429 -0
  22. package/dist/perf-jam-D55U3FZK.mjs +242 -0
  23. package/dist/{plugin-CTD0rydA.mjs → plugin-C-E7omsh.mjs} +425 -66
  24. package/dist/{poster-ChjXGTS5.mjs → poster-Bx83ZYVK.mjs} +2 -1
  25. package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
  26. package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-aljgm45S.mjs} +2 -2
  27. package/dist/{queue-BuiCKSX1.mjs → queue-CAM_vNmX.mjs} +3 -3
  28. package/dist/recover-t9Pno3u9.mjs +66 -0
  29. package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
  30. package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
  31. package/dist/shot-DoHLl6ig.mjs +139 -0
  32. package/dist/{shot-DqcxJibP.mjs → shot-LFhC-WYD.mjs} +343 -19
  33. package/dist/slots-DCDo3N0x.mjs +471 -0
  34. package/dist/speech-worker.mjs +40 -5
  35. package/dist/{sync-DKk-yT1V.mjs → sync-BQVlHZpx.mjs} +4 -3
  36. package/dist/{work-F5u-twpJ.mjs → work-Bp1p39kq.mjs} +4 -2
  37. package/dist/{work-VvX_JIgl.mjs → work-BroFwnup.mjs} +4 -2
  38. package/docs/boards-and-folders.md +3 -1
  39. package/docs/jam-session.md +78 -7
  40. package/docs/live-jam.md +8 -0
  41. package/docs/performance.md +262 -0
  42. package/package.json +2 -2
  43. package/src/client/content/index.tsx +3 -0
  44. package/src/client/content/video.tsx +6 -2
  45. package/src/client/frame-host/bridge.js +22 -6
  46. package/src/client/frame-host/inspect.js +8 -3
  47. package/src/client/frame-host/keys.js +6 -2
  48. package/src/client/frame-host/main.tsx +17 -5
  49. package/src/client/shell/App.tsx +188 -29
  50. package/src/client/shell/BoardList.tsx +5 -5
  51. package/src/client/shell/Comments.tsx +3 -2
  52. package/src/client/shell/JamSurface.tsx +13 -5
  53. package/src/client/shell/LockedApp.tsx +5 -5
  54. package/src/client/shell/Play.tsx +27 -15
  55. package/src/client/shell/Toolbar.tsx +17 -5
  56. package/src/client/shell/api.ts +206 -0
  57. package/src/client/shell/canvas/Canvas.tsx +30 -3
  58. package/src/client/shell/canvas/FrameNode.tsx +15 -5
  59. package/src/client/shell/canvas/admission.ts +8 -1
  60. package/src/client/shell/canvas/camera-broadcast.ts +15 -5
  61. package/src/client/shell/canvas/ctl.ts +2 -0
  62. package/src/client/shell/canvas/frame-registry.ts +28 -2
  63. package/src/client/shell/canvas/sleep.ts +4 -1
  64. package/src/client/shell/comments-store.ts +12 -4
  65. package/src/client/shell/goto.ts +22 -10
  66. package/src/client/shell/icons.tsx +2 -0
  67. package/src/client/shell/jam-capture.ts +96 -16
  68. package/src/client/shell/jam-keys.ts +51 -18
  69. package/src/client/shell/jam-lane.tsx +46 -5
  70. package/src/client/shell/jam-panel.tsx +66 -13
  71. package/src/client/shell/jam-queue.ts +3 -3
  72. package/src/client/shell/jam-session.tsx +14 -8
  73. package/src/client/shell/jam-state.ts +48 -6
  74. package/src/client/shell/jam-surface-parts.tsx +10 -6
  75. package/src/client/shell/jam-voice.ts +7 -5
  76. package/src/client/shell/legacy-links.ts +2 -2
  77. package/src/client/shell/main.tsx +4 -0
  78. package/src/client/shell/notes.ts +8 -1
  79. package/src/client/shell/perf.ts +69 -58
  80. package/src/client/shell/recorder-core.ts +183 -0
  81. package/src/client/shell/recorder.ts +565 -0
  82. package/src/client/shell/store.ts +268 -103
  83. package/src/client/shell/styles.css +54 -9
  84. package/src/client/stage/main.tsx +2 -0
  85. package/templates/AGENTS-embedded.md +22 -4
  86. package/templates/AGENTS-studio.md +22 -4
  87. package/templates/demo/dark.tsx +1 -1
  88. package/templates/demo/welcome.tsx +1 -1
  89. package/templates/instructions/jam.md +5 -3
  90. package/templates/instructions/welcome.md +6 -3
  91. package/dist/config-Cf7EjAMf.mjs +0 -292
  92. package/dist/dev-_Nlsc6v9.mjs +0 -742
  93. package/dist/dev-lock-DWSpa6nj.mjs +0 -179
  94. package/dist/perf-D6VmmJ2q.mjs +0 -68
  95. package/dist/perf-DPbLGhhO.mjs +0 -49
  96. package/dist/shot-CNbHoZ6H.mjs +0 -86
@@ -0,0 +1,471 @@
1
+ import { r as NAME } from "./cli.mjs";
2
+ import { a as readJson, i as portInUse, o as takeExclusive, r as pidRuns, t as asHolder } from "./exclusive-B1RtpeeP.mjs";
3
+ import { chmodSync, existsSync, mkdirSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { createHash, randomBytes } from "node:crypto";
6
+ import { homedir } from "node:os";
7
+ //#region src/server/workspace.ts
8
+ /**
9
+ * A project's one identity on this Mac (spec 28 A1.6): the first 16 hex of sha256 over its REAL path,
10
+ * so a root reached through a symlink is the same project. CONFIG.workspace, the capture upload's
11
+ * check, the slot file, the preference file and the app's partition all read it.
12
+ *
13
+ * A run holds two values (A1.13 #6): the canonical identity, which picks the project's preference
14
+ * file, and the effective workspace - this run's documents, API, captures and registry record. They
15
+ * differ only in a `--recover` run, which serves under the workspace key an earlier address used.
16
+ *
17
+ * The CLI already hands `dev()` the root's real path (cli/index.ts), so for every canvas started with
18
+ * `npx marver dev` this equals 0.26's key: unsent captures keep their key, and only the origin moves.
19
+ */
20
+ const key = (s) => createHash("sha256").update(s).digest("hex").slice(0, 16);
21
+ /** realpath, or the path itself when it cannot be resolved (never throws at boot). */
22
+ const realRoot = (root) => {
23
+ try {
24
+ return realpathSync(root);
25
+ } catch {
26
+ return root;
27
+ }
28
+ };
29
+ /** The project's canonical identity. */
30
+ const workspaceId = (root) => key(realRoot(root));
31
+ /** 0.26's key, for `--recover` alone: sha256 of the root exactly as it was given (0.26 hashed the
32
+ * given root in plugin.ts and api.ts alike). Equals `workspaceId` for every CLI start. */
33
+ const legacyWorkspace = (root) => key(root);
34
+ const runIdentity = (root, recoverWs) => {
35
+ const real = realRoot(root);
36
+ const id = key(real);
37
+ return {
38
+ root: real,
39
+ id,
40
+ ws: recoverWs ?? id
41
+ };
42
+ };
43
+ const marverHome = () => process.env.MARVER_HOME || join(homedir(), ".marver");
44
+ /** The port before slot 1 - slot n listens on base + n (localhost:4805-4824). MARVER_SLOT_BASE moves
45
+ * the range for the test suite alone: the port check sees every program on this Mac, so a suite on
46
+ * 4805+ would take the slot of a canvas someone is using. */
47
+ function slotBase() {
48
+ const b = Number(process.env.MARVER_SLOT_BASE);
49
+ return process.env.MARVER_SLOT_BASE && Number.isInteger(b) && b >= 1024 && b <= 65515 ? b : 4804;
50
+ }
51
+ const slotPort = (n) => slotBase() + n;
52
+ const slotOfPort = (port) => {
53
+ const n = port - slotBase();
54
+ return n >= 1 && n <= 20 ? n : null;
55
+ };
56
+ /** `~/x` for a path under the home directory - how paths are shown. */
57
+ const tilde = (p) => {
58
+ const h = homedir();
59
+ return p === h ? "~" : p.startsWith(h + "/") ? `~${p.slice(h.length)}` : p;
60
+ };
61
+ const runningDir = () => join(marverHome(), "running");
62
+ const preferDir = () => join(marverHome(), "prefer");
63
+ /** A registry folder, made for writing: mode 700. The home itself is made 700 only when missing (it holds
64
+ * canvases/ and models/ too, and an existing one is never changed). */
65
+ function made(d) {
66
+ mkdirSync(marverHome(), {
67
+ recursive: true,
68
+ mode: 448
69
+ });
70
+ mkdirSync(d, {
71
+ recursive: true,
72
+ mode: 448
73
+ });
74
+ try {
75
+ chmodSync(d, 448);
76
+ } catch {}
77
+ return d;
78
+ }
79
+ const slotFileOf = (n) => join(runningDir(), `slot-${n}.json`);
80
+ const portFileOf = (port) => join(runningDir(), `port-${port}.json`);
81
+ /** Write `file` whole: a private temp file renamed over it. */
82
+ function writeWhole(file, body) {
83
+ const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
84
+ writeFileSync(tmp, body, { mode: 384 });
85
+ try {
86
+ renameSync(tmp, file);
87
+ } catch (err) {
88
+ try {
89
+ unlinkSync(tmp);
90
+ } catch {}
91
+ throw err;
92
+ }
93
+ }
94
+ /** A record read back, or null when the file names no canvas. Lenient on what a later version adds. */
95
+ function asRecord(v) {
96
+ const h = asHolder(v);
97
+ const r = v;
98
+ if (!h || !r || typeof r.port !== "number" || typeof r.url !== "string") return null;
99
+ return {
100
+ v: 1,
101
+ state: r.state === "ready" || r.state === "closing" ? r.state : "starting",
102
+ pid: h.pid,
103
+ instance: h.instance,
104
+ slot: typeof r.slot === "number" ? r.slot : null,
105
+ port: r.port,
106
+ origin: typeof r.origin === "string" ? r.origin : null,
107
+ url: r.url,
108
+ root: typeof r.root === "string" ? r.root : "",
109
+ name: typeof r.name === "string" ? r.name : "",
110
+ version: typeof r.version === "string" ? r.version : "",
111
+ features: Array.isArray(r.features) ? r.features.filter((f) => typeof f === "string") : [],
112
+ ws: typeof r.ws === "string" ? r.ws : "",
113
+ startedAt: typeof r.startedAt === "number" ? r.startedAt : h.at,
114
+ key: typeof r.key === "string" ? r.key : ""
115
+ };
116
+ }
117
+ /** Take one candidate: the file, then - holding it - the port check. */
118
+ async function take(i, slot, port) {
119
+ const file = slot ? slotFileOf(slot) : portFileOf(port);
120
+ made(runningDir());
121
+ const key = randomBytes(32);
122
+ const rec = {
123
+ v: 1,
124
+ state: "starting",
125
+ pid: process.pid,
126
+ instance: i.instance,
127
+ slot,
128
+ port,
129
+ origin: null,
130
+ url: `http://localhost:${port}/`,
131
+ root: i.root,
132
+ name: i.name,
133
+ version: i.version,
134
+ features: [],
135
+ ws: i.ws,
136
+ startedAt: Date.now(),
137
+ key: key.toString("base64url")
138
+ };
139
+ const r = await takeExclusive(file, {
140
+ pid: rec.pid,
141
+ instance: rec.instance,
142
+ at: rec.startedAt
143
+ }, JSON.stringify(rec, null, 2) + "\n", { reclaimWaitMs: i.reclaimWaitMs });
144
+ if (!r.ok) return r.why === "held" ? {
145
+ ok: false,
146
+ why: "held",
147
+ holder: asRecord(readJson(file)),
148
+ file
149
+ } : {
150
+ ok: false,
151
+ why: r.why,
152
+ file
153
+ };
154
+ i.onHold?.(r.release);
155
+ if (await (i.inUse ?? portInUse)(port)) {
156
+ r.release();
157
+ return {
158
+ ok: false,
159
+ why: "busy",
160
+ file
161
+ };
162
+ }
163
+ let now = rec;
164
+ const rewrite = (next) => {
165
+ if (asHolder(readJson(file))?.instance !== rec.instance) return;
166
+ writeWhole(file, JSON.stringify(next, null, 2) + "\n");
167
+ now = next;
168
+ };
169
+ return {
170
+ ok: true,
171
+ claim: {
172
+ slot,
173
+ port,
174
+ file,
175
+ instance: rec.instance,
176
+ key,
177
+ url: rec.url,
178
+ release: r.release,
179
+ ready(origin) {
180
+ if (now.state !== "closing") rewrite({
181
+ ...now,
182
+ state: "ready",
183
+ origin
184
+ });
185
+ },
186
+ closing() {
187
+ if (now.state !== "closing") rewrite({
188
+ ...now,
189
+ state: "closing"
190
+ });
191
+ }
192
+ }
193
+ };
194
+ }
195
+ const canvasOf = (rec) => rec ? `"${rec.name || "?"}" (${tilde(rec.root) || "?"})` : "another canvas";
196
+ const stuckLine = (n) => `slot ${n} is stuck: delete ${tilde(slotFileOf(n))}.reclaim if no canvas is starting`;
197
+ const unreadableLine = (file, n) => `${tilde(file)} is unreadable - ${n ? `slot ${n}` : "that port"} skipped (delete it if no canvas runs there)`;
198
+ /** A slot, any slot: the project's preferred one first, then 1..20. */
199
+ async function anySlot(i, notes) {
200
+ const preferred = readPrefer(i.id)?.slot ?? null;
201
+ const order = [...preferred ? [preferred] : [], ...Array.from({ length: 20 }, (_, k) => k + 1).filter((n) => n !== preferred)];
202
+ for (const n of order) {
203
+ const t = await take(i, n, slotPort(n));
204
+ if (t.ok) return {
205
+ ok: true,
206
+ claim: t.claim,
207
+ notes
208
+ };
209
+ if (t.why === "busy") notes.push(`port ${slotPort(n)} is used by another program - slot ${n} skipped`);
210
+ else if (t.why === "stuck") notes.push(stuckLine(n));
211
+ else if (t.why === "unreadable") notes.push(unreadableLine(t.file, n));
212
+ }
213
+ return {
214
+ ok: false,
215
+ message: [
216
+ `all 20 slots are taken:`,
217
+ ...formatRunning(readRunning()).map((l) => ` ${l}`),
218
+ ...notes,
219
+ "stop one (Ctrl-C in its terminal), or start this one with --port <n>"
220
+ ].join("\n ")
221
+ };
222
+ }
223
+ /** Where this canvas listens: a slot, a port of its own, or --recover's exact one - held as a file before
224
+ * anything binds. */
225
+ async function place(i) {
226
+ if (i.recover) {
227
+ const port = i.recover.port;
228
+ const n = slotOfPort(port);
229
+ const t = await take(i, n, port);
230
+ if (t.ok) return {
231
+ ok: true,
232
+ claim: t.claim,
233
+ notes: []
234
+ };
235
+ const never = "--recover never takes another address";
236
+ return {
237
+ ok: false,
238
+ message: t.why === "held" && t.holder?.state === "closing" ? `port ${port} is held by ${canvasOf(t.holder)}, which is closing - ${never}; run it again once it has stopped` : t.why === "held" ? `port ${port} is held by ${canvasOf(t.holder)} - ${never}; stop it (Ctrl-C in its terminal) and run it again` : t.why === "busy" ? `port ${port} is in use - ${never}; stop what holds it and run it again` : t.why === "stuck" && n ? `${stuckLine(n)} - ${never}` : `${unreadableLine(t.file, n)} - ${never}`
239
+ };
240
+ }
241
+ if (i.explicit) {
242
+ const { port, from } = i.explicit;
243
+ const n = slotOfPort(port);
244
+ if (n) {
245
+ const t = await take(i, n, port);
246
+ if (t.ok) return {
247
+ ok: true,
248
+ claim: t.claim,
249
+ notes: []
250
+ };
251
+ const instead = from === "config" ? "or remove `port` from design/config.ts" : "or start without --port";
252
+ return {
253
+ ok: false,
254
+ message: t.why === "held" && t.holder?.state === "closing" ? `port ${port} is slot ${n}, and ${canvasOf(t.holder)} holds it while it closes - start again once it has stopped, ${instead}` : t.why === "held" ? `port ${port} is slot ${n}, and ${canvasOf(t.holder)} holds it - stop it first (Ctrl-C in its terminal), ${instead}` : t.why === "busy" ? `port ${port} (slot ${n}) is in use by another program - stop it, ${instead}` : t.why === "stuck" ? stuckLine(n) : unreadableLine(t.file, n)
255
+ };
256
+ }
257
+ const t = await take(i, null, port);
258
+ if (t.ok) return {
259
+ ok: true,
260
+ claim: t.claim,
261
+ notes: []
262
+ };
263
+ const placed = await anySlot(i, t.why === "stuck" ? [`${tilde(t.file)}.reclaim is left from a start that crashed: delete it if no canvas is starting`] : t.why === "unreadable" ? [unreadableLine(t.file, null)] : []);
264
+ return placed.ok ? {
265
+ ...placed,
266
+ fellBackFrom: port
267
+ } : placed;
268
+ }
269
+ return anySlot(i, []);
270
+ }
271
+ /** The address a listening server actually bound - `[::1]` or `127.0.0.1`, wildcards mapped to
272
+ * loopback - or null before it listens. */
273
+ const originOf = (a) => {
274
+ if (!a || typeof a === "string") return null;
275
+ return `http://${a.family === "IPv6" ? a.address === "::" ? "[::1]" : `[${a.address}]` : a.address === "0.0.0.0" ? "127.0.0.1" : a.address}:${a.port}`;
276
+ };
277
+ /** 0.26's per-project port in [5200,5399], verbatim - kept only so --recover can offer the address a
278
+ * canvas had before 0.27. Hashes the root exactly as given, as 0.26 did. */
279
+ const legacyPort = (root) => {
280
+ let h = 0;
281
+ for (let i = 0; i < root.length; i++) h = Math.imul(h, 31) + root.charCodeAt(i) | 0;
282
+ return 5200 + Math.abs(h) % 200;
283
+ };
284
+ /** What every `marver dev` since 0.24 writes in design/.local as it starts and keeps once it stops: the sidebar
285
+ * marks (changes.json, seen.json - the dev server their only writer, at every start), the Jam queue, the reload
286
+ * log. No other command writes them, and dev.lock and dev.json go when a canvas stops. Not the daily update check
287
+ * (update-check.json): a start sets it off and does not wait for it, so it lands when it lands - after a failed
288
+ * start has taken back its traces, or while another start reads them - and says nothing of a canvas that ran. */
289
+ const DEV_TRACES = [
290
+ "changes.json",
291
+ "seen.json",
292
+ "jam-jobs.json",
293
+ join("perf", "reloads.jsonl")
294
+ ];
295
+ /** Did a `marver dev` run in this folder before? Read once a start holds the folder's lock, before it writes any of
296
+ * them: with none, a project with no preference file is new, not one 0.26 served - and its first start has nothing
297
+ * to say about 0.26. */
298
+ const ranDevBefore = (root) => DEV_TRACES.some((f) => existsSync(join(root, "design", ".local", f)));
299
+ /** A start that found none of them and never served (a sandbox, a port just taken) takes back those it wrote - the
300
+ * marks (with their deps.json) and the rest - so the folder still reads as one no canvas ran in. */
301
+ const forgetDevTraces = (root) => {
302
+ for (const f of [...DEV_TRACES, "deps.json"]) try {
303
+ rmSync(join(root, "design", ".local", f), { force: true });
304
+ } catch {}
305
+ };
306
+ const HISTORY = 5;
307
+ const preferFileOf = (id) => /^[0-9a-f]{16}$/.test(id) ? join(preferDir(), `${id}.json`) : null;
308
+ const sameAddress = (a, b) => a.url === b.url && a.bind === b.bind && a.ws === b.ws;
309
+ /** The project's preference: undefined when it has none (its first 0.27 run), null when the file is there
310
+ * but unreadable (not a first run; the next write replaces it). */
311
+ function readPrefer(id) {
312
+ const file = preferFileOf(id);
313
+ if (!file) return null;
314
+ const raw = readJson(file);
315
+ if (raw === void 0) return void 0;
316
+ if (!raw || raw.v !== 1 || !(raw.slot === null || Number.isInteger(raw.slot) && raw.slot >= 1 && raw.slot <= 20) || !Array.isArray(raw.history)) return null;
317
+ const history = raw.history.filter((a) => !!a && typeof a.url === "string" && typeof a.bind === "string" && typeof a.ws === "string").map((a) => ({
318
+ url: a.url,
319
+ bind: a.bind,
320
+ ws: a.ws,
321
+ from: Number(a.from) || 0,
322
+ until: Number(a.until) || 0
323
+ }));
324
+ return {
325
+ v: 1,
326
+ slot: raw.slot ?? null,
327
+ history
328
+ };
329
+ }
330
+ /** Record this run's address, after ready: a new entry only when url, bind or ws differ from the newest
331
+ * (so recovery never loses the one it needs); an address it ran on before moves to the front, keeping its
332
+ * first start - five distinct addresses at most. Says whether this is the project's first 0.27 run, and
333
+ * the address it ran on last. */
334
+ function notePrefer(id, run, now = Date.now()) {
335
+ const file = preferFileOf(id);
336
+ if (!file) throw new Error(`not a workspace id: ${id}`);
337
+ const cur = readPrefer(id);
338
+ const previous = cur?.history[0] ? { ...cur.history[0] } : null;
339
+ const before = cur?.history.find((a) => sameAddress(a, run));
340
+ const history = [{
341
+ url: run.url,
342
+ bind: run.bind,
343
+ ws: run.ws,
344
+ from: before?.from ?? now,
345
+ until: now
346
+ }, ...(cur?.history ?? []).filter((a) => !sameAddress(a, run))];
347
+ made(preferDir());
348
+ writeWhole(file, JSON.stringify({
349
+ v: 1,
350
+ slot: run.slot ?? cur?.slot ?? null,
351
+ history: history.slice(0, HISTORY)
352
+ }, null, 2) + "\n");
353
+ return {
354
+ first: cur === void 0,
355
+ previous
356
+ };
357
+ }
358
+ /** This run stopped: its entry's `until` (best effort, synchronous - it runs on exit and on signals). */
359
+ function stopPrefer(id, run, now = Date.now()) {
360
+ try {
361
+ const file = preferFileOf(id);
362
+ const cur = readPrefer(id);
363
+ if (!file || !cur || !cur.history[0] || !sameAddress(cur.history[0], run)) return;
364
+ cur.history[0].until = now;
365
+ writeWhole(file, JSON.stringify(cur, null, 2) + "\n");
366
+ } catch {}
367
+ }
368
+ /** The address 0.26 gave this folder: its hash port, `localhost`, and its key. */
369
+ const legacyEntry = (root, port = legacyPort(root)) => ({
370
+ url: `http://localhost:${port}/`,
371
+ bind: `http://localhost:${port}`,
372
+ ws: legacyWorkspace(root),
373
+ legacy: true
374
+ });
375
+ /** The addresses this project ran on, newest first, then the one 0.26 gave it - always last, because the
376
+ * first 0.27 run has written history by the time anyone acts on its hint (A1.13 #6). */
377
+ function recoverEntries(root) {
378
+ const history = readPrefer(workspaceId(root))?.history ?? [];
379
+ const legacy = legacyEntry(root);
380
+ return history.some((h) => h.url === legacy.url && h.ws === legacy.ws) ? history : [...history, legacy];
381
+ }
382
+ /** What a start says about where this canvas ran before (A1.6) - nothing, when nothing a person could have open
383
+ * there has moved:
384
+ * - its first 0.27 start on a slot, only when a `marver dev` ran in this folder before: a new project has no 0.26
385
+ * address to name;
386
+ * - another link than last time (its slot taken, a port of its own given up): where it was, who runs there now
387
+ * when a canvas does, and how to run there again. A tab still open there keeps its unsaved edits until this
388
+ * canvas answers there, and a Jam capture left unsent waits there too. The link alone counts: the address a run
389
+ * bound (`[::1]` or `127.0.0.1`) is what the Mac app loads, and a browser at the link reaches either. */
390
+ function startedWhere(b) {
391
+ if (b.first) {
392
+ if (!b.ranBefore || !b.run.slot) return [];
393
+ const old = legacyPort(b.root);
394
+ return [`ports are now fixed slots: this canvas is at ${b.run.url}`, ...old !== b.port ? [`0.26 served this canvas at http://localhost:${old}/ - if a Jam capture was left unsent there, \`npx ${NAME} dev --recover\` gets it back`] : []];
395
+ }
396
+ const p = b.previous;
397
+ if (!p || p.url === b.run.url) return [];
398
+ const holder = readRunning().find((r) => r.url === p.url && r.pid !== process.pid && r.state !== "closing");
399
+ const who = holder ? `"${holder.name || "?"}"` : null;
400
+ const n = recoverEntries(b.root).findIndex((e) => e.url === p.url && e.bind === p.bind && e.ws === p.ws) + 1;
401
+ return [
402
+ `last run was at ${p.url}${who ? ` - ${who} runs there now` : ""}`,
403
+ "a tab still open there keeps its unsaved edits until this canvas runs there again (a Jam capture left unsent there waits too):",
404
+ `stop ${who ? `${who} and ` : ""}this canvas, then \`npx ${NAME} dev --recover${n ? ` ${n}` : ""}\``
405
+ ];
406
+ }
407
+ function recoverTarget(e) {
408
+ const b = new URL(e.bind);
409
+ const port = Number(b.port);
410
+ const host = b.hostname === "localhost" ? void 0 : b.hostname.replace(/^\[(.*)\]$/, "$1");
411
+ return {
412
+ port,
413
+ ...host ? { host } : {},
414
+ ws: e.ws,
415
+ url: e.url,
416
+ bind: e.bind
417
+ };
418
+ }
419
+ /** The canvases running on this Mac: every slot and port file whose pid runs, slots by number, then
420
+ * ports. Reads only - a Mac with no registry has none. */
421
+ function readRunning() {
422
+ let names;
423
+ try {
424
+ names = readdirSync(runningDir());
425
+ } catch {
426
+ return [];
427
+ }
428
+ const out = [];
429
+ for (const name of names) {
430
+ if (!/^(slot-\d+|port-\d+)\.json$/.test(name)) continue;
431
+ const file = join(runningDir(), name);
432
+ const rec = asRecord(readJson(file));
433
+ if (!rec || !pidRuns(rec.pid)) continue;
434
+ const { key: _key, instance: _instance, ...pub } = rec;
435
+ out.push({
436
+ ...pub,
437
+ file
438
+ });
439
+ }
440
+ return out.sort((a, b) => (a.slot === null ? 1 : 0) - (b.slot === null ? 1 : 0) || (a.slot ?? a.port) - (b.slot ?? b.port));
441
+ }
442
+ const uptime = (ms) => {
443
+ const s = Math.max(0, Math.floor(ms / 1e3)), m = Math.floor(s / 60), h = Math.floor(m / 60), d = Math.floor(h / 24);
444
+ return d ? `${d}d ${h % 24}h` : h ? `${h}h ${m % 60}m` : m ? `${m}m` : `${s}s`;
445
+ };
446
+ /** The list as `marver ls` prints it: slot, link, name, version, state, uptime, then the folder - last, its length
447
+ * its own, so the columns before it stay on the line. A canvas that is closing is listed, `closing`: it still holds
448
+ * its slot and its folder, so a start there is refused until it has gone, and the list says why. */
449
+ function formatRunning(list, now = Date.now()) {
450
+ const rows = [[
451
+ "slot",
452
+ "link",
453
+ "name",
454
+ "version",
455
+ "state",
456
+ "up",
457
+ "folder"
458
+ ], ...list.map((r) => [
459
+ r.slot === null ? "-" : String(r.slot),
460
+ r.url,
461
+ r.name,
462
+ r.version,
463
+ r.state,
464
+ uptime(now - r.startedAt),
465
+ tilde(r.root)
466
+ ])];
467
+ const widths = rows[0].map((_, c) => Math.max(...rows.map((r) => r[c].length)));
468
+ return rows.map((r) => r.map((cell, c) => c === 0 ? cell.padStart(widths[c]) : cell.padEnd(widths[c])).join(" ").trimEnd());
469
+ }
470
+ //#endregion
471
+ export { notePrefer as a, ranDevBefore as c, recoverTarget as d, startedWhere as f, workspaceId as h, marverHome as i, readRunning as l, runIdentity as m, formatRunning as n, originOf as o, stopPrefer as p, legacyEntry as r, place as s, forgetDevTraces as t, recoverEntries as u };
@@ -54,10 +54,16 @@ var Segmenter = class {
54
54
  vad;
55
55
  recognize;
56
56
  onWords;
57
- constructor(vad, recognize, onWords) {
57
+ onTiming;
58
+ decoding = 0;
59
+ /** the audio waiting for the recognizer, in samples - this capture's alone, or (the worker's) every capture sharing it */
60
+ backlog;
61
+ constructor(vad, recognize, onWords, onTiming, backlog) {
58
62
  this.vad = vad;
59
63
  this.recognize = recognize;
60
64
  this.onWords = onWords;
65
+ this.onTiming = onTiming;
66
+ this.backlog = backlog ?? (() => this.waitingSamples + this.decoding);
61
67
  }
62
68
  /** The samples from `offset` on (the page numbers them; an overlap is skipped). A short gap is silence
63
69
  * given to the VAD; a long one (over a second - a microphone that opened late, a resumed capture) ends
@@ -130,6 +136,8 @@ var Segmenter = class {
130
136
  }
131
137
  }
132
138
  enqueue(p) {
139
+ p.queuedAt = performance.now();
140
+ p.backlog = this.backlog();
133
141
  this.waiting.push(p);
134
142
  while (this.waiting.length > 1 && this.waiting.reduce((n, x) => n + x.samples.length, 0) > 48e4) {
135
143
  const gone = this.waiting.shift();
@@ -148,8 +156,13 @@ var Segmenter = class {
148
156
  while (this.waiting.length) {
149
157
  const p = this.waiting.shift();
150
158
  let words = [];
159
+ const t0 = performance.now();
160
+ this.decoding = p.samples.length;
161
+ let decodeMs;
151
162
  try {
152
- words = tokensToWords(await this.recognize(p.samples), p.start);
163
+ const r = await this.recognize(p.samples);
164
+ decodeMs = r.ms;
165
+ words = tokensToWords(r, p.start);
153
166
  } catch {
154
167
  words = [{
155
168
  w: "[words lost]",
@@ -157,6 +170,15 @@ var Segmenter = class {
157
170
  lost: true
158
171
  }];
159
172
  }
173
+ this.decoding = 0;
174
+ const end = performance.now();
175
+ const dec = decodeMs ?? end - t0;
176
+ if (!this.cancelled) this.onTiming?.({
177
+ audioMs: p.samples.length / RATE * 1e3,
178
+ waitMs: Math.max(0, end - dec - (p.queuedAt ?? t0)),
179
+ decodeMs: dec,
180
+ backlogMs: (p.backlog ?? 0) / RATE * 1e3
181
+ });
160
182
  const kept = words.filter((x) => x.at <= this.last);
161
183
  if (kept.length && !this.cancelled) this.onWords(kept);
162
184
  }
@@ -175,6 +197,10 @@ var Segmenter = class {
175
197
  this.pending = /* @__PURE__ */ new Float32Array(0);
176
198
  if (!this.busy) for (const f of this.idle.splice(0)) f();
177
199
  }
200
+ /** The phrase being transcribed now, in samples. */
201
+ get decodingSamples() {
202
+ return this.decoding;
203
+ }
178
204
  /** Audio given and not yet turned into words: phrases waiting, in samples (the worker's backlog). */
179
205
  get waitingSamples() {
180
206
  return this.waiting.reduce((n, x) => n + x.samples.length, 0);
@@ -224,6 +250,7 @@ const port = parentPort;
224
250
  const paths = workerData.paths;
225
251
  let sherpa;
226
252
  let recognizer;
253
+ const loadStart = performance.now();
227
254
  try {
228
255
  sherpa = createRequire(import.meta.url)("sherpa-onnx-node");
229
256
  recognizer = new sherpa.OfflineRecognizer({
@@ -243,7 +270,10 @@ try {
243
270
  modelType: "nemo_transducer"
244
271
  }
245
272
  });
246
- port.postMessage({ type: "ready" });
273
+ port.postMessage({
274
+ type: "ready",
275
+ modelLoadMs: performance.now() - loadStart
276
+ });
247
277
  } catch (err) {
248
278
  port.postMessage({
249
279
  type: "unavailable",
@@ -265,6 +295,7 @@ const vadFor = () => new sherpa.Vad({
265
295
  const turn = () => new Promise((r) => setImmediate(r));
266
296
  const recognize = async (samples) => {
267
297
  await turn();
298
+ const t0 = performance.now();
268
299
  const s = recognizer.createStream();
269
300
  s.acceptWaveform({
270
301
  sampleRate: RATE,
@@ -274,7 +305,8 @@ const recognize = async (samples) => {
274
305
  const r = recognizer.getResult(s);
275
306
  return {
276
307
  tokens: r.tokens ?? [],
277
- timestamps: r.timestamps ?? []
308
+ timestamps: r.timestamps ?? [],
309
+ ms: performance.now() - t0
278
310
  };
279
311
  };
280
312
  const captures = /* @__PURE__ */ new Map();
@@ -286,7 +318,10 @@ port.on("message", (m) => {
286
318
  type: "words",
287
319
  capture: id,
288
320
  words
289
- })));
321
+ }), (t) => port.postMessage({
322
+ type: "timing",
323
+ ...t
324
+ }), () => [...captures.values()].reduce((n, x) => n + x.waitingSamples + x.decodingSamples, 0)));
290
325
  } else if (m.type === "audio") {
291
326
  const seg = captures.get(id);
292
327
  if (!seg || !(m.pcm instanceof Int16Array)) return;
@@ -2,10 +2,10 @@ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { n as diffEvents } from "./events-CLH4ijKP.mjs";
3
3
  import { a as readLog, i as listBoards, t as appendEvents } from "./comments-0BSbb04K.mjs";
4
4
  import { t as CLI_TOKEN_CHARS } from "./auth-Dix8wrXV.mjs";
5
+ import { i as marverHome } from "./slots-DCDo3N0x.mjs";
5
6
  import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, unlinkSync, writeSync } from "node:fs";
6
7
  import { join } from "node:path";
7
8
  import { createHash, randomBytes } from "node:crypto";
8
- import { homedir } from "node:os";
9
9
  //#region src/server/sync.ts
10
10
  /**
11
11
  * Dev ↔ published comment sync - one merge rule, run from the dev side.
@@ -43,13 +43,14 @@ var sync_exports = /* @__PURE__ */ __exportAll({
43
43
  *
44
44
  * So the file moved out of reach instead. Under the user's home, keyed by the
45
45
  * absolute path of the project it belongs to, one file per canvas per machine.
46
- * Nothing serves that directory, so there is no path to guard.
46
+ * Nothing serves that directory, so there is no path to guard. (MARVER_HOME moves
47
+ * it with the registry: the test suite's, so no test writes the owner's.)
47
48
  *
48
49
  * The old location is still read once, moved, and removed - a credential left
49
50
  * behind in a repo is exactly the thing being fixed.
50
51
  */
51
52
  const legacyCollabFile = (root) => join(root, "design", ".local", "collab.json");
52
- const collabDir = () => join(homedir(), ".marver", "canvases");
53
+ const collabDir = () => join(marverHome(), "canvases");
53
54
  const collabFile = (root) => {
54
55
  let canonical = root;
55
56
  try {
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { s as listBoardFiles } from "./boards-CGg6piKF.mjs";
3
- import { r as pidRuns } from "./dev-lock-DWSpa6nj.mjs";
3
+ import { r as pidRuns } from "./exclusive-B1RtpeeP.mjs";
4
4
  import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
5
  import { join } from "node:path";
6
6
  import { randomBytes, randomUUID } from "node:crypto";
@@ -128,13 +128,15 @@ function removeDevInfo(root, instance = written.get(root)) {
128
128
  if (written.get(root) === instance) written.delete(root);
129
129
  } catch {}
130
130
  }
131
+ /** The running server's dev.json: its port and token, and its pid (a file from before 0.26 has none). */
131
132
  function readDevInfo(root) {
132
133
  try {
133
134
  const v = JSON.parse(readFileSync(infoPath(root), "utf8"));
134
135
  if (v?.pid !== void 0 && !pidRuns(v.pid)) return null;
135
136
  return typeof v?.port === "number" && typeof v?.token === "string" ? {
136
137
  port: v.port,
137
- token: v.token
138
+ token: v.token,
139
+ ...typeof v.pid === "number" ? { pid: v.pid } : {}
138
140
  } : null;
139
141
  } catch {
140
142
  return null;
@@ -1,5 +1,6 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { i as readDevInfo, n as WORK_TTL_MAX, t as WORK_TTL_DEFAULT } from "./work-F5u-twpJ.mjs";
2
+ import { i as readDevInfo, n as WORK_TTL_MAX, t as WORK_TTL_DEFAULT } from "./work-Bp1p39kq.mjs";
3
+ import { unreachable } from "./link-DDXZVGtv.mjs";
3
4
  //#region src/cli/work.ts
4
5
  /**
5
6
  * `marver work` - the coding agent's hand on the canvas working state.
@@ -30,6 +31,7 @@ async function workCommand(root, action, frames, opts) {
30
31
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
31
32
  });
32
33
  } catch {
34
+ if (info.pid !== void 0) throw new Error(`${unreachable(info.pid)} The working glow needs it; the canvas itself is fine - \`npx ${NAME} link <scene/frame>\` still prints its link`);
33
35
  throw new Error(`could not reach \`${NAME} dev\` on port ${info.port} - is it still running?`);
34
36
  }
35
37
  const data = await res.json().catch(() => ({}));
@@ -66,7 +68,7 @@ async function workCommand(root, action, frames, opts) {
66
68
  });
67
69
  console.log(active.length ? `still working: ${active.join(", ")}` : "nothing working - all clear");
68
70
  const done = before.filter((f) => !active.includes(f));
69
- const { links, hints } = done.length ? await (await import("./link-BNzLvdhI.mjs")).handBack(root, done) : {
71
+ const { links, hints } = done.length ? await (await import("./link-DDXZVGtv.mjs")).handBack(root, done) : {
70
72
  links: [],
71
73
  hints: []
72
74
  };
@@ -106,7 +106,9 @@ screen first; a frame off screen waits until you scroll to it, and one you are u
106
106
  drawing a laser, commenting) waits until you are done. A content frame keeps its height while it
107
107
  reloads, so the rows below stay still; if heights did change, the board moves once. The canvas page
108
108
  itself never reloads for a design edit. `npx marver perf` shows what each edit reloaded and how long
109
- it took (from `design/.local/perf/reloads.jsonl`).
109
+ it took (from `design/.local/perf/reloads.jsonl`), and `npx marver perf --loads` what each board load
110
+ did: how long until it settled, how many moves it took on the way, and why
111
+ ([Performance](performance.md)).
110
112
 
111
113
  ## In the files
112
114