@marver-design/marver 0.28.0 → 0.29.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 (62) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +2 -2
  3. package/dist/{anchor-check-PHUOFj1N.mjs → anchor-check-DhlpKl2K.mjs} +1 -1
  4. package/dist/{build-BsAyLMT1.mjs → build-CWbrb2bl.mjs} +5 -3
  5. package/dist/{capture-DdZ6xgoz.mjs → capture-DEtM4qm5.mjs} +168 -5
  6. package/dist/cli.mjs +10 -10
  7. package/dist/{comments-CrBHPEQl.mjs → comments-XNhMmSSu.mjs} +2 -2
  8. package/dist/{connectors-MR9d-EBP.mjs → connectors-DekQvKt9.mjs} +3 -1
  9. package/dist/{daemon-C5dg2R-V.mjs → daemon-Sc_z8gT6.mjs} +28 -29
  10. package/dist/{dev-D7YS7iT2.mjs → dev-DWBKQhxf.mjs} +19 -14
  11. package/dist/{init-WE5lQkQL.mjs → init-CYlFaRzG.mjs} +1 -1
  12. package/dist/logo-CXY-1yrn.mjs +305 -0
  13. package/dist/{ls-BZ5TAtd5.mjs → ls-NqmePKOf.mjs} +1 -1
  14. package/dist/{marks-Kmdab_5w.mjs → marks-BnNANic9.mjs} +20 -1
  15. package/dist/{marks-Dyn6tmjp.mjs → marks-DBp3h1Mc.mjs} +2 -5
  16. package/dist/{marver-id-gate-D-R0hSt_.mjs → marver-id-gate-vBLb_Icb.mjs} +1 -1
  17. package/dist/{perf-Cn5LiRaY.mjs → perf-Denssrko.mjs} +43 -25
  18. package/dist/{perf-jam-QxD_UnzN.mjs → perf-jam-CLkERSHo.mjs} +8 -1
  19. package/dist/{plugin-C_0yb-Fq.mjs → plugin-DqoZB-D6.mjs} +511 -298
  20. package/dist/{poster-DHi6I1fO.mjs → poster-CrsjqhY4.mjs} +1 -1
  21. package/dist/{profile-jIS6BcAs.mjs → profile-B1FKOM1e.mjs} +1 -1
  22. package/dist/{publish-bakes-r4PEZuPl.mjs → publish-bakes-DW-NDgU2.mjs} +3 -3
  23. package/dist/{queue-c-6aTHEz.mjs → queue-DeSQm24g.mjs} +29 -14
  24. package/dist/{recover-nrLEVLyJ.mjs → recover-GtJ9UDAB.mjs} +2 -2
  25. package/dist/{serve-Dp3nHstu.mjs → serve-DQv3Ti6X.mjs} +8 -4
  26. package/dist/{session-DyVE7cCk.mjs → session-VDJfXEEm.mjs} +1 -1
  27. package/dist/{share-Ce4tP7ji.mjs → share-Bu_kuOKL.mjs} +1 -1
  28. package/dist/{shot-BrRtqaiS.mjs → shot-T04Ixrvq.mjs} +3 -3
  29. package/dist/{slots-CFNnegCc.mjs → slots-Dn4Onb0V.mjs} +101 -3
  30. package/dist/{sync-CQdGARJ9.mjs → sync-CMozOwZ0.mjs} +1 -1
  31. package/docs/boards-and-folders.md +11 -0
  32. package/docs/jam-session.md +12 -3
  33. package/docs/live-jam.md +3 -0
  34. package/docs/performance.md +1 -1
  35. package/docs/publish.md +7 -0
  36. package/package.json +1 -1
  37. package/src/client/shell/Comments.tsx +5 -4
  38. package/src/client/shell/ContextMenu.tsx +5 -4
  39. package/src/client/shell/JamSurface.tsx +80 -9
  40. package/src/client/shell/Play.tsx +16 -4
  41. package/src/client/shell/api.ts +7 -3
  42. package/src/client/shell/app-bridge.ts +11 -3
  43. package/src/client/shell/comments-store.ts +14 -0
  44. package/src/client/shell/goto.ts +4 -3
  45. package/src/client/shell/jam-capture.ts +39 -15
  46. package/src/client/shell/jam-keys.ts +166 -40
  47. package/src/client/shell/jam-lines.ts +10 -1
  48. package/src/client/shell/jam-panel.tsx +8 -6
  49. package/src/client/shell/jam-queue.ts +6 -1
  50. package/src/client/shell/jam-session.tsx +2 -2
  51. package/src/client/shell/jam-state.ts +19 -4
  52. package/src/client/shell/jam-ui.tsx +4 -0
  53. package/src/client/shell/live-picture.ts +134 -0
  54. package/src/client/shell/open-item.ts +83 -0
  55. package/src/client/shell/open-resolve.ts +50 -0
  56. package/src/client/shell/store.ts +6 -2
  57. package/src/client/shell/styles.css +2 -0
  58. package/src/client/stage/main.tsx +30 -8
  59. package/src/shared/app-api.ts +173 -3
  60. package/src/shared/app-perf.ts +4 -2
  61. package/templates/instructions/jam.md +4 -0
  62. package/dist/live-Cgzsicwi.mjs +0 -4
@@ -3,18 +3,21 @@ import { a as ROUTE, i as PKG, r as NAME } from "./cli.mjs";
3
3
  import { a as checkBoardsDir, c as listBoardFiles, d as pinFrames, g as tryFileLock, h as takeFileLock, i as boardLock, l as nodeExists, m as readRegistry, p as readMembership, r as boardFields, s as isRegularFile, t as AUTHOR_FIELDS, u as parseBoard, v as withRegistryLock, y as hash } from "./boards-EH2onUXM.mjs";
4
4
  import { A as resolveType, D as readReason, E as readCapability, O as readStatusWord, S as HAS_STATUS, _ as validateWire, a as buildTree, c as folderMap, g as readTitle, h as readDescription, j as settableStatuses, k as readType, n as BOARD_NAME, r as FOLDERS_FILE, t as ALL_SCENES, v as wireKids } from "./board-tree-BXR8dw4b.mjs";
5
5
  import { c as setSceneTitle, d as annotateBoards, f as planNames, m as readContextFacts, n as isNoteFile, p as planWithStage, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-DPZ3WNg_.mjs";
6
- import { r as boardsChanged } from "./work-DJxH7cCX.mjs";
7
- import { h as workspaceId, i as marverHome, o as originOf } from "./slots-CFNnegCc.mjs";
8
- import { n as localProfile, t as isConnected } from "./profile-jIS6BcAs.mjs";
9
- import { a as observe, n as docRevs, r as initMarks, s as recordChanged, t as docRev } from "./marks-Kmdab_5w.mjs";
10
- import { a as appendRun, f as tidyPerfDir, i as PAGE_BODY_MAX, o as logPage, s as logReload } from "./perf-jam-QxD_UnzN.mjs";
6
+ import { a as workActivity, r as boardsChanged } from "./work-DJxH7cCX.mjs";
7
+ import { r as replay, t as asks } from "./events-CLH4ijKP.mjs";
8
+ import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
9
+ import { g as LIVE_WIRE, h as LIVE_BOUNDS, i as marverHome, o as originOf, v as workspaceId } from "./slots-Dn4Onb0V.mjs";
10
+ import { n as localProfile, t as isConnected } from "./profile-B1FKOM1e.mjs";
11
+ import { c as recordChanged, i as initMarks, n as docRevs, o as observe, r as freshFrames, t as docRev } from "./marks-BnNANic9.mjs";
12
+ import { a as appendRun, f as tidyPerfDir, i as PAGE_BODY_MAX, o as logPage, s as logReload } from "./perf-jam-CLkERSHo.mjs";
11
13
  import { n as loadConfig } from "./config-BezZTiov.mjs";
12
14
  import { a as mergeSizes, c as serializeSizes, i as measuringFrames, l as sizesPath, n as autoWidthOf, o as readSizes, r as keptSizes, s as readSizesFile } from "./sizes-wjXDev3b.mjs";
13
- import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-BrRtqaiS.mjs";
14
- import { closeSync, constants, copyFileSync, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, watch, writeFileSync } from "node:fs";
15
+ import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-T04Ixrvq.mjs";
16
+ import { a as appProofOk, o as proofHeaders, r as logoRoute } from "./logo-CXY-1yrn.mjs";
17
+ import { closeSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, watch, writeFileSync } from "node:fs";
15
18
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
16
19
  import { fileURLToPath } from "node:url";
17
- import { createHash, createHmac, randomBytes } from "node:crypto";
20
+ import { createHash, randomBytes } from "node:crypto";
18
21
  import { arch, cpus, totalmem } from "node:os";
19
22
  import { execFile } from "node:child_process";
20
23
  import { stat } from "node:fs/promises";
@@ -2420,6 +2423,32 @@ function readBody(req, limit = BODY_LIMIT) {
2420
2423
  req.on("error", () => done(null));
2421
2424
  });
2422
2425
  }
2426
+ /** A raw body (A4.6 #37): `limit` counted as the bytes arrive, never trusting `content-length` - past it `large`, and
2427
+ * nothing more is kept; `stop` ends the read where it stands. The socket is left alone, so the answer still goes out. */
2428
+ function readBytes(req, limit, stop) {
2429
+ return new Promise((done) => {
2430
+ let size = 0, settled = false;
2431
+ const chunks = [];
2432
+ const end = (v) => {
2433
+ if (!settled) {
2434
+ settled = true;
2435
+ chunks.length = 0;
2436
+ done(v);
2437
+ }
2438
+ };
2439
+ req.on("data", (c) => {
2440
+ if (settled) return;
2441
+ size += c.length;
2442
+ if (size > limit) end("large");
2443
+ else chunks.push(c);
2444
+ });
2445
+ req.on("end", () => end(Buffer.concat(chunks)));
2446
+ req.on("error", () => end("error"));
2447
+ stop?.addEventListener("abort", () => end("stopped"), { once: true });
2448
+ });
2449
+ }
2450
+ /** A live picture's bytes at most (A4.6 #37): a 4096 px image of a design is well under it. */
2451
+ const LIVE_PICTURE_MAX = 8388608;
2423
2452
  /** Atomic write: random temp name (no predictable symlink target), rename, and a
2424
2453
  * copy-fallback only for the Windows rename errors - anything else rethrows. */
2425
2454
  function atomicWrite(file, content) {
@@ -2509,6 +2538,31 @@ function apiMiddleware(root, opts = {}) {
2509
2538
  try {
2510
2539
  for (const f of readdirSync(boardsDir)) if (f.endsWith(".tmp")) rmSync(join(boardsDir, f), { force: true });
2511
2540
  } catch {}
2541
+ /** `POST jam/picture/live?capture=&frame=` (A4.6 #37), in order: a PNG body, a capture id, a frame of the manifest, a
2542
+ * capture not sealed; then the bytes, 8 MB at most as they arrive, their signature and the whole PNG; and the capture
2543
+ * still not sealed, just before it is stored. Nothing is stored once `stop` (the deadline) has fired. */
2544
+ const livePicture = async (req, url, stop) => {
2545
+ const { CAPTURE_ID, addPictureBytes, checkPng, isPng, readCapture, sweepPictures } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
2546
+ if (String(req.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase() !== "image/png") return [415, { error: "expected image/png" }];
2547
+ const capture = url.searchParams.get("capture") ?? "", frame = url.searchParams.get("frame") ?? "";
2548
+ if (!CAPTURE_ID.test(capture)) return [400, { error: "bad capture id" }];
2549
+ if (!devFrames().some((f) => f.id === frame)) return [404, { error: "unknown frame" }];
2550
+ if (readCapture(root, capture)) return [409, { error: "that capture is sealed" }];
2551
+ const png = await readBytes(req, LIVE_PICTURE_MAX, stop);
2552
+ if (png === "large") return [413, { error: `a live picture is ${LIVE_PICTURE_MAX / 2 ** 20} MB at most` }];
2553
+ if (typeof png === "string") return [400, { error: "the picture did not arrive whole" }];
2554
+ if (!isPng(png)) return [415, { error: "not a PNG" }];
2555
+ const checked = await checkPng(png);
2556
+ if (typeof checked === "string") return [400, { error: `not a picture it takes: ${checked}` }];
2557
+ if (stop.aborted) return [408, { error: "the picture took too long" }];
2558
+ if (readCapture(root, capture)) return [409, { error: "that capture is sealed" }];
2559
+ sweepPictures(root);
2560
+ return [200, { id: addPictureBytes(root, png, {
2561
+ frame,
2562
+ capture,
2563
+ source: "live"
2564
+ }) }];
2565
+ };
2512
2566
  return async (req, res, next) => {
2513
2567
  const url = new URL(req.url ?? "/", "http://x");
2514
2568
  if (!url.pathname.startsWith(`/__mv/api/`)) return next();
@@ -2737,7 +2791,7 @@ function apiMiddleware(root, opts = {}) {
2737
2791
  const str = (v) => typeof v === "string" ? v.slice(0, 200) : void 0;
2738
2792
  const num = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
2739
2793
  if (!str(b?.kind)) return json(res, 400, { error: "kind required" });
2740
- (await import("./perf-jam-QxD_UnzN.mjs").then((n) => n.c)).logReload(root, {
2794
+ (await import("./perf-jam-CLkERSHo.mjs").then((n) => n.c)).logReload(root, {
2741
2795
  kind: str(b.kind),
2742
2796
  tab: str(b.tab),
2743
2797
  node: str(b.node),
@@ -2759,7 +2813,7 @@ function apiMiddleware(root, opts = {}) {
2759
2813
  return json(res, 400, { error: "malformed JSON" });
2760
2814
  }
2761
2815
  if (!b || b.kind !== "capture" && b.kind !== "upload") return json(res, 400, { error: "kind must be capture or upload" });
2762
- (await import("./perf-jam-QxD_UnzN.mjs").then((n) => n.n)).logJam(root, b);
2816
+ (await import("./perf-jam-CLkERSHo.mjs").then((n) => n.n)).logJam(root, b);
2763
2817
  return json(res, 200, { ok: true });
2764
2818
  }
2765
2819
  if (path === "perf/page" && req.method === "POST") {
@@ -3249,7 +3303,7 @@ function apiMiddleware(root, opts = {}) {
3249
3303
  };
3250
3304
  const asPng = url.searchParams.get("format") === "png";
3251
3305
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
3252
- const { shootFrame } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
3306
+ const { shootFrame } = await import("./shot-T04Ixrvq.mjs").then((n) => n.u);
3253
3307
  const r = await shootFrame({
3254
3308
  root,
3255
3309
  viewports: opts.viewports ?? {},
@@ -3300,7 +3354,7 @@ function apiMiddleware(root, opts = {}) {
3300
3354
  if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
3301
3355
  const scale = body.scale === void 0 ? void 0 : body.scale;
3302
3356
  if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
3303
- const { resolveFrames, shootBatch } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
3357
+ const { resolveFrames, shootBatch } = await import("./shot-T04Ixrvq.mjs").then((n) => n.u);
3304
3358
  const sel = resolveFrames(root, body);
3305
3359
  if (!sel.ok) return json(res, sel.status, { error: sel.error });
3306
3360
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
@@ -3334,7 +3388,7 @@ function apiMiddleware(root, opts = {}) {
3334
3388
  if (typeof target === "string") return json(res, 400, { error: target });
3335
3389
  const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
3336
3390
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
3337
- const { checkAnchor, CheckInputError } = await import("./anchor-check-PHUOFj1N.mjs");
3391
+ const { checkAnchor, CheckInputError } = await import("./anchor-check-DhlpKl2K.mjs");
3338
3392
  try {
3339
3393
  return json(res, 200, await checkAnchor({
3340
3394
  root,
@@ -3384,7 +3438,7 @@ function apiMiddleware(root, opts = {}) {
3384
3438
  });
3385
3439
  docs.push(typeof a?.doc === "string" ? a.doc : void 0);
3386
3440
  }
3387
- const { docRev } = await import("./marks-Kmdab_5w.mjs").then((n) => n.i);
3441
+ const { docRev } = await import("./marks-BnNANic9.mjs").then((n) => n.a);
3388
3442
  const all = devManifest().frames;
3389
3443
  const pending = opts.settled ? !opts.settled() : false;
3390
3444
  const behind = docs.map((d, i) => d !== void 0 && (pending || d !== docRev(root, all, asks[i].frame)));
@@ -3442,8 +3496,8 @@ function apiMiddleware(root, opts = {}) {
3442
3496
  return json(res, 400, { error: "malformed JSON" });
3443
3497
  }
3444
3498
  const src = typeof b?.src === "string" ? b.src : "";
3445
- const { ensurePoster, isLocalClip } = await import("./poster-DHi6I1fO.mjs");
3446
- const { isLocalAssetRef } = await import("./build-BsAyLMT1.mjs");
3499
+ const { ensurePoster, isLocalClip } = await import("./poster-CrsjqhY4.mjs");
3500
+ const { isLocalAssetRef } = await import("./build-CWbrb2bl.mjs");
3447
3501
  if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
3448
3502
  const r = await ensurePoster(join(root, "design", "assets"), src);
3449
3503
  if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
@@ -3486,7 +3540,7 @@ function apiMiddleware(root, opts = {}) {
3486
3540
  }
3487
3541
  if (path === "marks" || path === "marks/seen") {
3488
3542
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3489
- const { readMarks, markSeen } = await import("./marks-Kmdab_5w.mjs").then((n) => n.i);
3543
+ const { readMarks, markSeen } = await import("./marks-BnNANic9.mjs").then((n) => n.a);
3490
3544
  const manifest = devManifest();
3491
3545
  if (path === "marks" && req.method === "GET") return json(res, 200, readMarks(root, manifest));
3492
3546
  if (path === "marks/seen" && req.method === "POST") {
@@ -3536,7 +3590,7 @@ function apiMiddleware(root, opts = {}) {
3536
3590
  if (!on && b.all === true) {
3537
3591
  const done = workActivity.active().filter((f) => workActivity.has(f, "cli"));
3538
3592
  if (done.length) {
3539
- (await import("./marks-Kmdab_5w.mjs").then((n) => n.i)).recordChanged(root, devFrames(), done, { doc: false });
3593
+ (await import("./marks-BnNANic9.mjs").then((n) => n.a)).recordChanged(root, devFrames(), done, { doc: false });
3540
3594
  opts.notify?.("sh:marks");
3541
3595
  }
3542
3596
  workActivity.clearAll("cli");
@@ -3556,7 +3610,7 @@ function apiMiddleware(root, opts = {}) {
3556
3610
  for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
3557
3611
  saveHolds(root, workActivity);
3558
3612
  if (!on) {
3559
- (await import("./marks-Kmdab_5w.mjs").then((n) => n.i)).recordChanged(root, devFrames(), frames, { doc: false });
3613
+ (await import("./marks-BnNANic9.mjs").then((n) => n.a)).recordChanged(root, devFrames(), frames, { doc: false });
3560
3614
  opts.notify?.("sh:marks");
3561
3615
  return json(res, 200, { frames: workActivity.active() });
3562
3616
  }
@@ -3592,7 +3646,7 @@ function apiMiddleware(root, opts = {}) {
3592
3646
  }
3593
3647
  if (path === "jam/queue" && req.method === "GET") {
3594
3648
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3595
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3649
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3596
3650
  return json(res, 200, jamLive.view?.() ?? {
3597
3651
  agent: null,
3598
3652
  cards: [],
@@ -3609,10 +3663,10 @@ function apiMiddleware(root, opts = {}) {
3609
3663
  } catch {
3610
3664
  return json(res, 400, { error: "malformed JSON" });
3611
3665
  }
3612
- const { ACTIONS } = await import("./queue-c-6aTHEz.mjs");
3666
+ const { ACTIONS } = await import("./queue-DeSQm24g.mjs");
3613
3667
  if (!b || typeof b.id !== "string" || !Number.isInteger(b.rev) || !ACTIONS.includes(b.action) || b.body !== void 0 && typeof b.body !== "string") return json(res, 400, { error: "expected { id, rev, action, body? }" });
3614
3668
  if ("kind" in b) return json(res, 400, { error: "a capture has no category" });
3615
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3669
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3616
3670
  if (!jamLive.act) return json(res, 409, { error: "jam is not running here" });
3617
3671
  const r = await jamLive.act(b.id, b.rev, b.action, b.body);
3618
3672
  return json(res, r.ok ? 200 : 409, r);
@@ -3650,11 +3704,11 @@ function apiMiddleware(root, opts = {}) {
3650
3704
  }
3651
3705
  if (path === "jam/session" && (req.method === "GET" || req.method === "POST")) {
3652
3706
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3653
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3707
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3654
3708
  if (!jamLive.session || !jamLive.view) return json(res, 409, { error: "jam is not running here" });
3655
3709
  if (req.method === "GET") {
3656
3710
  const ses = jamLive.view().session ?? null;
3657
- const { readTalk, talkMinutes, recordFile } = await import("./session-DyVE7cCk.mjs").then((n) => n.s);
3711
+ const { readTalk, talkMinutes, recordFile } = await import("./session-VDJfXEEm.mjs").then((n) => n.s);
3658
3712
  const folder = ses ? recordFile(root, ses.since, ses.id).replace(/[^/]+$/, "") : null;
3659
3713
  return json(res, 200, {
3660
3714
  session: ses,
@@ -3703,7 +3757,7 @@ function apiMiddleware(root, opts = {}) {
3703
3757
  id: b.id
3704
3758
  });
3705
3759
  if (r.ok && b.action === "start") {
3706
- const { ensureConnectors } = await import("./connectors-MR9d-EBP.mjs");
3760
+ const { ensureConnectors } = await import("./connectors-DekQvKt9.mjs");
3707
3761
  const connectors = ensureConnectors(root);
3708
3762
  jamLive.connectors = connectors;
3709
3763
  return json(res, 200, {
@@ -3728,7 +3782,7 @@ function apiMiddleware(root, opts = {}) {
3728
3782
  "background",
3729
3783
  "drop"
3730
3784
  ].includes(b.action)) return json(res, 400, { error: "expected { batch, gen, action }" });
3731
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3785
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3732
3786
  if (!jamLive.runAct) return json(res, 409, { error: "jam is not running here" });
3733
3787
  const r = await jamLive.runAct(b.batch, b.gen, b.action);
3734
3788
  jamLive.refresh?.();
@@ -3737,8 +3791,8 @@ function apiMiddleware(root, opts = {}) {
3737
3791
  if (path === "jam/prefs" && (req.method === "GET" || req.method === "POST")) {
3738
3792
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3739
3793
  const { readPrefs, writePrefs, validConnId } = await import("./conn-BMiHS42T.mjs").then((n) => n.a);
3740
- const { ensureConnectors, present } = await import("./connectors-MR9d-EBP.mjs");
3741
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3794
+ const { ensureConnectors, present } = await import("./connectors-DekQvKt9.mjs");
3795
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3742
3796
  const tools = [
3743
3797
  "claude",
3744
3798
  "codex",
@@ -3800,7 +3854,7 @@ function apiMiddleware(root, opts = {}) {
3800
3854
  } catch {
3801
3855
  return json(res, 400, { error: "malformed JSON" });
3802
3856
  }
3803
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3857
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3804
3858
  if (!jamLive.captureOpen) return json(res, 409, { error: "jam is not running here" });
3805
3859
  if (typeof b?.capture !== "string" || typeof b?.session !== "string") return json(res, 400, { error: "expected { capture, session, on }" });
3806
3860
  return jamLive.captureOpen(b.capture, b.session, b.on === true) === "ended" ? json(res, 409, {
@@ -3811,7 +3865,7 @@ function apiMiddleware(root, opts = {}) {
3811
3865
  }
3812
3866
  if (path === "jam/record" && req.method === "GET") {
3813
3867
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3814
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3868
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3815
3869
  const r = jamLive.record?.(url.searchParams.get("id") ?? "");
3816
3870
  return r ? json(res, 200, r) : json(res, 404, { error: "no such record" });
3817
3871
  }
@@ -3826,18 +3880,18 @@ function apiMiddleware(root, opts = {}) {
3826
3880
  return json(res, 400, { error: "malformed JSON" });
3827
3881
  }
3828
3882
  if (b?.workspace !== void 0 && b.workspace !== ws) return json(res, 409, { error: "this capture was made in another workspace" });
3829
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3883
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3830
3884
  if (!jamLive.capture) return json(res, 409, { error: "jam is not running here" });
3831
3885
  const r = await jamLive.capture(b?.record);
3832
3886
  return json(res, r.ok ? 200 : 400, r);
3833
3887
  }
3834
3888
  if (path === "jam/capture" && req.method === "GET") {
3835
3889
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3836
- const { readCapture } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
3890
+ const { readCapture } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
3837
3891
  const id = url.searchParams.get("id") ?? "";
3838
3892
  const cap = readCapture(root, id);
3839
3893
  if (!cap) return json(res, 404, { error: "no such capture" });
3840
- const { jamLive } = await import("./live-Cgzsicwi.mjs");
3894
+ const { jamLive } = await Promise.resolve().then(() => live_exports);
3841
3895
  const card = jamLive.view?.().cards.find((c) => c.id === id);
3842
3896
  return json(res, 200, {
3843
3897
  record: cap.record,
@@ -3856,11 +3910,11 @@ function apiMiddleware(root, opts = {}) {
3856
3910
  } catch {
3857
3911
  return json(res, 400, { error: "malformed JSON" });
3858
3912
  }
3859
- const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
3913
+ const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
3860
3914
  if (!b || typeof b.capture !== "string" || !CAPTURE_ID.test(b.capture) || typeof b.frame !== "string") return json(res, 400, { error: "expected { capture, frame, theme?, viewport? }" });
3861
3915
  if (readCapture(root, b.capture)) return json(res, 409, { error: "that capture is sealed" });
3862
3916
  const theme = typeof b.theme === "string" && /^[a-z0-9-]+$/i.test(b.theme) ? b.theme : "light";
3863
- const { shootFrame } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
3917
+ const { shootFrame } = await import("./shot-T04Ixrvq.mjs").then((n) => n.u);
3864
3918
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
3865
3919
  const vp = typeof b.viewport === "string" ? opts.viewports?.[b.viewport] : void 0;
3866
3920
  const dim = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
@@ -3892,10 +3946,24 @@ function apiMiddleware(root, opts = {}) {
3892
3946
  ...unchecked ? { unchecked: true } : {}
3893
3947
  });
3894
3948
  }
3949
+ if (path === "jam/picture/live" && req.method === "POST") {
3950
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3951
+ const stop = new AbortController();
3952
+ let timer;
3953
+ const late = new Promise((done) => {
3954
+ timer = setTimeout(() => {
3955
+ stop.abort();
3956
+ done([408, { error: "the picture took too long" }]);
3957
+ }, opts.livePictureMs ?? 1e4);
3958
+ });
3959
+ const [status, body] = await Promise.race([livePicture(req, url, stop.signal), late]).finally(() => clearTimeout(timer));
3960
+ if (status === 408 || status === 413) res.setHeader("connection", "close");
3961
+ return json(res, status, body);
3962
+ }
3895
3963
  if (path === "jam/picture" && req.method === "GET") {
3896
3964
  const site = String(req.headers["sec-fetch-site"] ?? "");
3897
3965
  if (!ownerGated(req) && !(cookie(req, "mv_c") && (site === "same-origin" || site === "none"))) return json(res, 403, { error: "forbidden" });
3898
- const { picturePath } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
3966
+ const { picturePath } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
3899
3967
  const p = picturePath(root, url.searchParams.get("id") ?? "");
3900
3968
  if (!p) return json(res, 404, { error: "no such picture" });
3901
3969
  const png = readFileSync(p.path);
@@ -3946,13 +4014,13 @@ function apiMiddleware(root, opts = {}) {
3946
4014
  const fresh = appendEvents(dir, cm[1], stamped);
3947
4015
  const { record } = await import("./ledger-D54iROST.mjs").then((n) => n.n);
3948
4016
  for (const ev of fresh) if (ev.type === "create" || ev.type === "reply" || ev.type === "edit") record(root, cm[1], ev.id);
3949
- (await import("./live-Cgzsicwi.mjs")).jamLive.poke?.();
4017
+ (await Promise.resolve().then(() => live_exports)).jamLive.poke?.();
3950
4018
  backgroundPush(root);
3951
4019
  return json(res, 200, { accepted: fresh.length });
3952
4020
  }
3953
4021
  }
3954
4022
  if (path === "sync" && req.method === "POST") {
3955
- const { loadCollab, syncOnce } = await import("./sync-CQdGARJ9.mjs").then((n) => n.o);
4023
+ const { loadCollab, syncOnce } = await import("./sync-CMozOwZ0.mjs").then((n) => n.o);
3956
4024
  const collab = loadCollab(root);
3957
4025
  if (!collab) return json(res, 200, { connected: false });
3958
4026
  try {
@@ -3981,42 +4049,13 @@ function backgroundPush(root) {
3981
4049
  pushTimer = setTimeout(async () => {
3982
4050
  pushTimer = null;
3983
4051
  try {
3984
- const { loadCollab, syncOnce } = await import("./sync-CQdGARJ9.mjs").then((n) => n.o);
4052
+ const { loadCollab, syncOnce } = await import("./sync-CMozOwZ0.mjs").then((n) => n.o);
3985
4053
  const collab = loadCollab(root);
3986
4054
  if (collab) await syncOnce(root, collab);
3987
4055
  } catch {}
3988
4056
  }, 1500);
3989
4057
  }
3990
4058
  //#endregion
3991
- //#region src/server/proof.ts
3992
- /**
3993
- * The document proof (spec 28 A1.4). The Mac app puts a fresh nonce on every main-frame request to a
3994
- * local canvas (`x-mv-nonce`) and checks the answer before the document commits; only the canvas
3995
- * holding the slot file's key can sign it, so the privileges the app grants belong to that exact
3996
- * document. The proof rides the very response the app commits - the check and the load can never
3997
- * reach different listeners.
3998
- *
3999
- * Pinned exactly, so the app (A2.3 `proof.ts`) computes the same: the key is the slot file's 32 bytes
4000
- * (base64url there), HMAC-SHA256 over UTF-8 `doc|<nonce>|<port>` (port in decimal), base64url without
4001
- * padding. Requests from the app itself carry `app|<port>` the same way, and the logo the app fetches
4002
- * (`GET /__mv/logo`, spec 28 A2.4) `logo|<nonce>|<port>`: a listener that took the port after the tab was
4003
- * verified can never hand it a logo.
4004
- */
4005
- /** 16-64 base64url characters - anything else is not a nonce, and is ignored. */
4006
- const NONCE = /^[A-Za-z0-9_-]{16,64}$/;
4007
- const sign$1 = (key, msg) => createHmac("sha256", key).update(msg, "utf8").digest("base64url");
4008
- const docProof = (key, nonce, port) => sign$1(key, `doc|${nonce}|${port}`);
4009
- const logoProof = (key, nonce, port) => sign$1(key, `logo|${nonce}|${port}`);
4010
- /** The two headers for a request carrying a well-formed `x-mv-nonce`, else null: over the shell's document
4011
- * (`doc`), or over the logo (`logo`). */
4012
- function proofHeaders(p, nonce, kind = "doc") {
4013
- if (!p || typeof nonce !== "string" || !NONCE.test(nonce)) return null;
4014
- return {
4015
- "x-mv-instance": p.instance,
4016
- "x-mv-proof": (kind === "logo" ? logoProof : docProof)(p.key, nonce, p.port)
4017
- };
4018
- }
4019
- //#endregion
4020
4059
  //#region src/server/routes.ts
4021
4060
  function routesMiddleware(server, clientDir, stamps, proof) {
4022
4061
  const page = (dir) => {
@@ -4085,229 +4124,6 @@ function routesMiddleware(server, clientDir, stamps, proof) {
4085
4124
  }
4086
4125
  };
4087
4126
  }
4088
- /** The type each sniffed logo is served with. */
4089
- const LOGO_MIME = {
4090
- png: "image/png",
4091
- ico: "image/x-icon",
4092
- svg: "image/svg+xml"
4093
- };
4094
- const PNG = [
4095
- 137,
4096
- 80,
4097
- 78,
4098
- 71,
4099
- 13,
4100
- 10,
4101
- 26,
4102
- 10
4103
- ];
4104
- /** The logo type these bytes are, or null when they are none of the three. */
4105
- function sniffLogo(b) {
4106
- if (b.length >= PNG.length && PNG.every((x, i) => b[i] === x)) return "png";
4107
- if (b.length >= 4 && b[0] === 0 && b[1] === 0 && b[2] === 1 && b[3] === 0) return "ico";
4108
- return svgRoot(b) ? "svg" : null;
4109
- }
4110
- /** Is this UTF-8 text an SVG document: its root element `<svg`, with only the prolog A2.14 #24 allows before it? */
4111
- function svgRoot(b) {
4112
- let s;
4113
- try {
4114
- s = new TextDecoder("utf-8", { fatal: true }).decode(b);
4115
- } catch {
4116
- return false;
4117
- }
4118
- let i = s.charCodeAt(0) === 65279 ? 1 : 0;
4119
- const space = () => {
4120
- while (i < s.length && /\s/.test(s[i])) i++;
4121
- };
4122
- space();
4123
- if (s.startsWith("<?xml", i) && /[\s?]/.test(s[i + 5] ?? "")) {
4124
- const end = s.indexOf("?>", i);
4125
- if (end < 0) return false;
4126
- i = end + 2;
4127
- }
4128
- let doctype = false;
4129
- for (;;) {
4130
- space();
4131
- if (s.startsWith("<!--", i)) {
4132
- const end = s.indexOf("-->", i + 4);
4133
- if (end < 0) return false;
4134
- i = end + 3;
4135
- continue;
4136
- }
4137
- if (s.startsWith("<!DOCTYPE", i)) {
4138
- if (doctype) return false;
4139
- doctype = true;
4140
- const end = doctypeEnd(s, i + 9);
4141
- if (end < 0) return false;
4142
- i = end;
4143
- continue;
4144
- }
4145
- break;
4146
- }
4147
- return s.startsWith("<svg", i) && /[\s>/]/.test(s[i + 4] ?? "");
4148
- }
4149
- /** Just past the `>` that closes a `<!DOCTYPE svg ...>` whose body starts at `i`, or -1: another root name, an
4150
- * internal subset (`[` outside quotes) or no end. Quoted public and system ids may hold anything but their quote. */
4151
- function doctypeEnd(s, i) {
4152
- if (!/\s/.test(s[i] ?? "")) return -1;
4153
- while (i < s.length && /\s/.test(s[i])) i++;
4154
- if (!s.startsWith("svg", i) || !/[\s>]/.test(s[i + 3] ?? "")) return -1;
4155
- i += 3;
4156
- while (i < s.length) {
4157
- const c = s[i];
4158
- if (c === ">") return i + 1;
4159
- if (c === "[") return -1;
4160
- if (c === "\"" || c === "'") {
4161
- const close = s.indexOf(c, i + 1);
4162
- if (close < 0) return -1;
4163
- i = close + 1;
4164
- continue;
4165
- }
4166
- i++;
4167
- }
4168
- return -1;
4169
- }
4170
- //#endregion
4171
- //#region src/server/logo.ts
4172
- const LOGO_LADDER = [
4173
- "design/logo.svg",
4174
- "design/logo.png",
4175
- "public/logo.svg",
4176
- "public/logo.png",
4177
- "public/favicon.svg",
4178
- "public/favicon.png",
4179
- "public/favicon.ico"
4180
- ];
4181
- /** The first candidate that passes every check, read whole; null when none does. `warn` hears why a `share.logo`
4182
- * was ignored (the ladder's own entries are tried quietly: most repos have none of them). */
4183
- function findLogo(root, shareLogo, warn) {
4184
- let realRoot;
4185
- try {
4186
- realRoot = realpathSync(root);
4187
- } catch {
4188
- return null;
4189
- }
4190
- const own = typeof shareLogo === "string" && shareLogo !== "" ? shareLogo : null;
4191
- for (const cand of new Set(own ? [own, ...LOGO_LADDER] : LOGO_LADDER)) {
4192
- const r = readLogo(realRoot, resolve(realRoot, cand));
4193
- if (typeof r !== "string") return {
4194
- ...r,
4195
- from: cand
4196
- };
4197
- if (cand === own) warn?.(`share.logo ${own} is ignored: ${r}`);
4198
- }
4199
- return null;
4200
- }
4201
- /** One candidate: its bytes and type, or why it does not count. */
4202
- function readLogo(realRoot, file) {
4203
- let st;
4204
- try {
4205
- st = lstatSync(file);
4206
- } catch (e) {
4207
- return e.code === "ENOENT" || e.code === "ENOTDIR" ? "no such file" : "unreadable";
4208
- }
4209
- if (st.isSymbolicLink()) return "a symlink";
4210
- if (!st.isFile()) return "not a file";
4211
- if (!/\.(svg|png|ico)$/i.test(file)) return "not .svg, .png or .ico";
4212
- if (st.size > 262144) return "over 256 KB";
4213
- let real;
4214
- try {
4215
- real = realpathSync(file);
4216
- } catch {
4217
- return "unreadable";
4218
- }
4219
- if (!real.startsWith(realRoot + sep)) return "outside the repo";
4220
- let fd;
4221
- try {
4222
- fd = openSync(real, constants.O_RDONLY | constants.O_NOFOLLOW);
4223
- } catch {
4224
- return "unreadable";
4225
- }
4226
- try {
4227
- const f = fstatSync(fd);
4228
- if (!f.isFile() || f.ino !== st.ino || f.dev !== st.dev) return "changed while it was read";
4229
- const buf = Buffer.alloc(262145);
4230
- let n = 0;
4231
- for (let k = 1; k > 0 && n < buf.length; n += k) k = readSync(fd, buf, n, buf.length - n, null);
4232
- if (n > 262144) return "over 256 KB";
4233
- const bytes = Buffer.from(buf.subarray(0, n));
4234
- const type = sniffLogo(bytes);
4235
- return type ? {
4236
- type,
4237
- bytes
4238
- } : "not an image (PNG, ICO or SVG)";
4239
- } catch {
4240
- return "unreadable";
4241
- } finally {
4242
- closeSync(fd);
4243
- }
4244
- }
4245
- /** `marver build`: the logo into `<outDir>/__mv/logo.<type>` (an `.ico` as `logo.ico`), by its bytes - never a copy
4246
- * that follows a link. Its published path, or undefined when the repo has none. */
4247
- function publishLogo(root, shareLogo, outDir, warn) {
4248
- const logo = findLogo(root, shareLogo, warn);
4249
- if (!logo) return void 0;
4250
- const dir = join(outDir, ROUTE.slice(1));
4251
- mkdirSync(dir, { recursive: true });
4252
- writeFileSync(join(dir, `logo.${logo.type}`), logo.bytes);
4253
- return `${ROUTE}/logo.${logo.type}`;
4254
- }
4255
- /** A strong `ETag` for these bytes. */
4256
- const logoTag = (bytes) => `"${createHash("sha256").update(bytes).digest("base64url").slice(0, 22)}"`;
4257
- /** Does an `If-None-Match` name this tag (a list, a weak tag, or `*`)? */
4258
- function matches(header, tag) {
4259
- if (typeof header !== "string") return false;
4260
- return header.split(",").map((t) => t.trim().replace(/^W\//, "")).some((t) => t === "*" || t === tag);
4261
- }
4262
- /**
4263
- * `marver dev`'s `GET|HEAD /__mv/logo`. Read once per request (256 KB at most), checked, and answered with its sniffed
4264
- * type, an `ETag` and `Cache-Control: no-cache`; `x-content-type-options: nosniff` and a CSP that runs nothing, so an
4265
- * SVG opened as a page is a picture. A request carrying a well-formed `x-mv-nonce` gets the logo proof
4266
- * (`x-mv-instance`, `x-mv-proof` over `logo|<nonce>|<port>`), on a 200 and a 304 alike. 404 when the repo has none.
4267
- */
4268
- function logoRoute(root, shareLogo, proof) {
4269
- const warned = /* @__PURE__ */ new Set();
4270
- const warn = (m) => {
4271
- if (warned.has(m)) return;
4272
- warned.add(m);
4273
- console.warn(` marver: ${m}`);
4274
- };
4275
- return (req, res, next) => {
4276
- let path;
4277
- try {
4278
- path = new URL(req.url ?? "/", "http://x").pathname;
4279
- } catch {
4280
- return next();
4281
- }
4282
- if (path !== `/__mv/logo`) return next();
4283
- if (req.method !== "GET" && req.method !== "HEAD") {
4284
- res.statusCode = 405;
4285
- res.setHeader("allow", "GET, HEAD");
4286
- return res.end();
4287
- }
4288
- const logo = findLogo(root, shareLogo(), warn);
4289
- if (!logo) {
4290
- res.statusCode = 404;
4291
- res.setHeader("cache-control", "no-store");
4292
- return res.end();
4293
- }
4294
- const tag = logoTag(logo.bytes);
4295
- res.setHeader("content-type", LOGO_MIME[logo.type]);
4296
- res.setHeader("etag", tag);
4297
- res.setHeader("cache-control", "no-cache");
4298
- res.setHeader("vary", "x-mv-nonce");
4299
- res.setHeader("x-content-type-options", "nosniff");
4300
- res.setHeader("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'");
4301
- const signed = proofHeaders(proof, req.headers["x-mv-nonce"], "logo");
4302
- if (signed) for (const [k, v] of Object.entries(signed)) res.setHeader(k, v);
4303
- if (matches(req.headers["if-none-match"], tag)) {
4304
- res.statusCode = 304;
4305
- return res.end();
4306
- }
4307
- res.setHeader("content-length", String(logo.bytes.length));
4308
- res.end(req.method === "HEAD" ? void 0 : logo.bytes);
4309
- };
4310
- }
4311
4127
  //#endregion
4312
4128
  //#region src/server/guard.ts
4313
4129
  /** A workspace key as marver writes it: 16 hex. A frame's own `ws` query in another shape is the
@@ -4392,6 +4208,337 @@ function elsewhere(res) {
4392
4208
  res.end(JSON.stringify({ error: "another workspace" }));
4393
4209
  }
4394
4210
  //#endregion
4211
+ //#region src/server/app-live.ts
4212
+ /**
4213
+ * The live stream (spec 28 A4.1, A4.6 #4-#15): what waits on the owner in this canvas, for the Mac app's marks and
4214
+ * notices. `GET /__mv/app/live` is an event stream of whole snapshots (`LiveEvent` v1, src/shared/app-api.ts), proved
4215
+ * both ways - the request by `x-mv-app`, the answer by `liveProof` over the app's fresh nonce - so only the slot key's
4216
+ * holder is answered, and a listener that took the port after a canvas stopped can never put words into a notice.
4217
+ *
4218
+ * Four parts, each pure or nearly: the selector `liveSnapshot(input)` (#7-#11), the id hash (#9), the encoder with its
4219
+ * byte budget (#11, r1 #4), and the hub `createLiveHub` with its clients (#14), behind the route `liveRoute` (#5, #6).
4220
+ * The adapters that read the real sources - the comment logs, the marks, the Jam view, `marver work`'s leases - stay in
4221
+ * plugin.ts as the hub's `read()`. Erasable TypeScript, no Vite, only `node:crypto`, `./proof.ts` and the shared
4222
+ * contracts: the Mac app's fake canvas runs it under Node's type stripping over a scripted `read()`, so the app's cases
4223
+ * meet this code, not a copy (#4).
4224
+ */
4225
+ /** An item's id (#9): its kind and the first 20 hex of a sha256 over the occurrence's persisted parts, NUL-joined. */
4226
+ const liveId = (kind, ...parts) => `${kind}:${createHash("sha256").update(parts.map(String).join("\0")).digest("hex").slice(0, 20)}`;
4227
+ /** One line of at most `max` UTF-16 units: whitespace collapsed, control characters gone, never cut inside a pair. A
4228
+ * log is data: a body that is not a string (a hand edit, a dev POST) reads as none, never stopping the stream. */
4229
+ function oneLine(s, max = LIVE_BOUNDS.title) {
4230
+ const t = (typeof s === "string" ? s : "").replace(/\s+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").trim();
4231
+ if (t.length <= max) return t;
4232
+ const cut = t.slice(0, max);
4233
+ return /[\ud800-\udbff]$/.test(cut) ? cut.slice(0, -1) : cut;
4234
+ }
4235
+ /** Every ref an item carries is at most `LIVE_BOUNDS.ref`: one past it can never be shown, so it is counted, never sent. */
4236
+ const refsFit = (i) => [
4237
+ i.board,
4238
+ i.frame,
4239
+ i.thread,
4240
+ i.msg,
4241
+ i.batch,
4242
+ ...i.cards ?? []
4243
+ ].every((r) => r === void 0 || r.length <= LIVE_BOUNDS.ref);
4244
+ const byMade = (a, b) => a.made - b.made || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
4245
+ const firstFrame = (c) => c.frames[0];
4246
+ /**
4247
+ * What waits on the owner now (#7, #8, #10, #12): one item per need, newest first, at most `LIVE_BOUNDS.items`, with
4248
+ * exact counts. Pure and deterministic - the same input gives the same bytes. `ask` from the threads alone (a Jam card
4249
+ * in `asks` is the same question, carried as its target); `review`, `failed` and `stalled` from Jam's view, each
4250
+ * failed or stalled run one item; unseen frames a count; `working` from `marver work`'s leases and the runs at work.
4251
+ */
4252
+ function liveSnapshot(input) {
4253
+ const view = input.jam;
4254
+ const cards = view?.cards ?? [];
4255
+ const threadOf = /* @__PURE__ */ new Map();
4256
+ for (const { board, threads } of input.boards) for (const t of threads) threadOf.set(`${board}\0${t.id}`, t);
4257
+ const items = [];
4258
+ for (const { board, threads } of input.boards) for (const t of threads) {
4259
+ if (t.resolved || !(t.agent || t.replies.some((r) => r.agent))) continue;
4260
+ const last = t.replies.length ? t.replies[t.replies.length - 1] : t;
4261
+ if (!last.agent || !asks(last, last === t)) continue;
4262
+ const msg = last === t ? t.id : last.id;
4263
+ const card = cards.filter((c) => c.state === "asks" && c.board === board && c.thread === t.id).sort(byMade).map((c) => c.id);
4264
+ items.push({
4265
+ id: liveId("ask", board, t.id, msg),
4266
+ kind: "ask",
4267
+ board,
4268
+ title: oneLine(last.body),
4269
+ at: last.ts,
4270
+ ...t.frame ? { frame: t.frame } : {},
4271
+ thread: t.id,
4272
+ msg,
4273
+ ...card.length ? { cards: card.slice(0, LIVE_BOUNDS.cards) } : {}
4274
+ });
4275
+ }
4276
+ const titleOf = (c) => oneLine(c.kind === "comment" ? (c.thread ? threadOf.get(`${c.board}\0${c.thread}`)?.body : void 0) ?? c.title : c.title);
4277
+ const thread = (c) => c.kind === "comment" && c.thread ? { thread: c.thread } : {};
4278
+ for (const c of cards.filter((x) => x.state === "review").sort(byMade)) {
4279
+ const occ = c.att ?? 0;
4280
+ items.push({
4281
+ id: liveId("review", c.id, occ),
4282
+ kind: "review",
4283
+ board: c.board,
4284
+ title: titleOf(c),
4285
+ at: c.at,
4286
+ ...firstFrame(c) ? { frame: firstFrame(c) } : {},
4287
+ ...thread(c),
4288
+ cards: [c.id],
4289
+ ...c.batch ? { batch: c.batch } : {},
4290
+ occ
4291
+ });
4292
+ }
4293
+ const failed = /* @__PURE__ */ new Map();
4294
+ for (const c of cards.filter((x) => x.state === "failed").sort(byMade)) {
4295
+ const k = c.batch ? `b\0${c.batch}` : `c\0${c.id}`;
4296
+ failed.set(k, [...failed.get(k) ?? [], c]);
4297
+ }
4298
+ for (const [k, group] of failed) {
4299
+ const c = group[0];
4300
+ const run = k.startsWith("b\0");
4301
+ const occ = run ? c.fails ?? 0 : c.att ?? 0;
4302
+ items.push({
4303
+ id: run ? liveId("failed", c.batch, occ) : liveId("failed", c.id, occ),
4304
+ kind: "failed",
4305
+ board: c.board,
4306
+ title: titleOf(c),
4307
+ ...c.note ? { note: oneLine(c.note, LIVE_BOUNDS.note) } : {},
4308
+ at: Math.max(...group.map((x) => x.at)),
4309
+ ...firstFrame(c) ? { frame: firstFrame(c) } : {},
4310
+ ...thread(c),
4311
+ cards: group.map((x) => x.id).slice(0, LIVE_BOUNDS.cards),
4312
+ ...run ? { batch: c.batch } : {},
4313
+ occ
4314
+ });
4315
+ }
4316
+ const stalled = /* @__PURE__ */ new Map();
4317
+ for (const c of cards.filter((x) => x.state === "working" && x.runner?.kind === "session" && x.runner.state === "stalled").sort(byMade)) {
4318
+ const k = c.runner.batch;
4319
+ stalled.set(k, [...stalled.get(k) ?? [], c]);
4320
+ }
4321
+ for (const [batch, group] of stalled) {
4322
+ const c = group[0];
4323
+ const gen = c.runner.gen ?? 0, occ = c.runner.stalls ?? 0;
4324
+ items.push({
4325
+ id: liveId("stalled", batch, gen, occ),
4326
+ kind: "stalled",
4327
+ board: c.board,
4328
+ title: titleOf(c),
4329
+ at: Math.max(...group.map((x) => x.at)),
4330
+ ...firstFrame(c) ? { frame: firstFrame(c) } : {},
4331
+ ...thread(c),
4332
+ cards: group.map((x) => x.id).slice(0, LIVE_BOUNDS.cards),
4333
+ batch,
4334
+ gen,
4335
+ occ
4336
+ });
4337
+ }
4338
+ const counts = {
4339
+ ask: 0,
4340
+ review: 0,
4341
+ failed: 0,
4342
+ stalled: 0
4343
+ };
4344
+ for (const i of items) counts[i.kind]++;
4345
+ const shown = items.filter(refsFit).sort((a, b) => b.at - a.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
4346
+ const working = input.cli.length > 0 || cards.some((c) => c.state === "working" && (!c.runner || !c.runner.state || c.runner.state === "claimed"));
4347
+ return {
4348
+ jam: view ? "on" : "off",
4349
+ items: shown.slice(0, LIVE_BOUNDS.items),
4350
+ cut: Math.max(0, shown.length - LIVE_BOUNDS.items),
4351
+ counts,
4352
+ unseen: input.fresh.length,
4353
+ working,
4354
+ session: !!view?.session
4355
+ };
4356
+ }
4357
+ const block = (e) => `event: ${LIVE_WIRE.event}\ndata: ${JSON.stringify(e)}\n\n`;
4358
+ /**
4359
+ * The event as written (#11, r1 #4): `event: live`, one `data:` line, a blank line - within `LIVE_BOUNDS.eventBytes`
4360
+ * in UTF-8. While it is over, the oldest whole items go (the end of `items`), counted in `cut`; `counts` stay exact.
4361
+ */
4362
+ function encodeLive(e) {
4363
+ let text = block(e);
4364
+ if (Buffer.byteLength(text) <= LIVE_BOUNDS.eventBytes) return text;
4365
+ const sizes = e.items.map((i) => Buffer.byteLength(JSON.stringify(i)) + 1);
4366
+ let over = Buffer.byteLength(text) - LIVE_BOUNDS.eventBytes;
4367
+ let keep = e.items.length;
4368
+ while (keep > 0 && over > 0) over -= sizes[--keep];
4369
+ for (;;) {
4370
+ text = block({
4371
+ ...e,
4372
+ items: e.items.slice(0, keep),
4373
+ cut: e.cut + e.items.length - keep
4374
+ });
4375
+ if (keep === 0 || Buffer.byteLength(text) <= LIVE_BOUNDS.eventBytes) return text;
4376
+ keep--;
4377
+ }
4378
+ }
4379
+ /** `seq`: per server process, rising across Vite restarts - one counter for every hub this module makes (#11, #14). */
4380
+ const SEQ = { n: 0 };
4381
+ const hubs = /* @__PURE__ */ new Set();
4382
+ /** A source the stream reads changed - beside each place the server already tells pages (#13). Pokes every open hub. */
4383
+ function liveChanged() {
4384
+ for (const h of hubs) h.changed();
4385
+ }
4386
+ const LIVE_DEBOUNCE_MAX_MS = 1e3;
4387
+ /**
4388
+ * One hub per server (#14). It computes only while a client is connected, and writes only a snapshot that differs
4389
+ * from the last one written, `seq` one higher. A new client gets the snapshot at once - alone, when nothing changed.
4390
+ * A heartbeat `: hb` every 30 s recomputes too, so a missed hook costs 30 s at most. A fifth client ends the oldest; a
4391
+ * client with more than 64 KiB unsent is destroyed before the next write (it reconnects for a fresh snapshot). `on`
4392
+ * subscribes the hub to a source that tells it of changes itself (workActivity), unsubscribed at close.
4393
+ */
4394
+ function createLiveHub(o) {
4395
+ const now = o.clock ?? Date.now;
4396
+ const seq = o.seq ?? SEQ;
4397
+ const clients = [];
4398
+ let last = null;
4399
+ let text = "";
4400
+ let timer;
4401
+ let first = 0;
4402
+ let beat;
4403
+ let closed = false;
4404
+ /** no client left: no timer runs */
4405
+ const idle = () => {
4406
+ if (!clients.length) {
4407
+ clearInterval(beat);
4408
+ beat = void 0;
4409
+ clearTimeout(timer);
4410
+ timer = void 0;
4411
+ }
4412
+ };
4413
+ const remove = (res) => {
4414
+ const i = clients.indexOf(res);
4415
+ if (i >= 0) clients.splice(i, 1);
4416
+ idle();
4417
+ };
4418
+ const write = (res, chunk) => {
4419
+ if (res.writableLength > LIVE_WIRE.slowBytes) {
4420
+ remove(res);
4421
+ res.destroy();
4422
+ return;
4423
+ }
4424
+ res.write(chunk);
4425
+ };
4426
+ /** Read the sources; a changed snapshot goes to every client. False when the read failed (nothing written). */
4427
+ const recompute = () => {
4428
+ let body;
4429
+ try {
4430
+ body = o.read();
4431
+ } catch {
4432
+ return false;
4433
+ }
4434
+ const key = JSON.stringify(body);
4435
+ if (key === last) return true;
4436
+ last = key;
4437
+ text = encodeLive({
4438
+ v: 1,
4439
+ instance: o.instance,
4440
+ seq: ++seq.n,
4441
+ ...body
4442
+ });
4443
+ for (const c of [...clients]) write(c, text);
4444
+ return true;
4445
+ };
4446
+ const fire = () => {
4447
+ timer = void 0;
4448
+ if (clients.length && !closed) recompute();
4449
+ };
4450
+ const hub = {
4451
+ changed() {
4452
+ if (closed || !clients.length) return;
4453
+ const t = now();
4454
+ if (timer === void 0) first = t;
4455
+ clearTimeout(timer);
4456
+ timer = setTimeout(fire, Math.max(0, Math.min(150, first + LIVE_DEBOUNCE_MAX_MS - t)));
4457
+ },
4458
+ push() {
4459
+ clearTimeout(timer);
4460
+ timer = void 0;
4461
+ if (!closed) recompute();
4462
+ },
4463
+ add(res) {
4464
+ if (closed) {
4465
+ res.end();
4466
+ return;
4467
+ }
4468
+ while (clients.length >= LIVE_WIRE.clients) clients.shift().end();
4469
+ clients.push(res);
4470
+ res.on("close", () => remove(res));
4471
+ res.on("error", () => remove(res));
4472
+ const was = last;
4473
+ if (recompute() && last === was && text) write(res, text);
4474
+ beat ??= setInterval(() => {
4475
+ recompute();
4476
+ for (const c of [...clients]) write(c, `${LIVE_WIRE.heartbeat}\n\n`);
4477
+ }, LIVE_WIRE.heartbeatMs);
4478
+ beat.unref?.();
4479
+ },
4480
+ clients: () => clients.length,
4481
+ drop() {
4482
+ for (const c of clients.splice(0)) c.destroy();
4483
+ idle();
4484
+ },
4485
+ close() {
4486
+ if (closed) return;
4487
+ closed = true;
4488
+ hubs.delete(hub);
4489
+ off?.();
4490
+ for (const c of clients.splice(0)) try {
4491
+ c.end();
4492
+ } catch {}
4493
+ clearInterval(beat);
4494
+ beat = void 0;
4495
+ clearTimeout(timer);
4496
+ timer = void 0;
4497
+ }
4498
+ };
4499
+ const off = o.on?.(() => hub.changed());
4500
+ hubs.add(hub);
4501
+ return hub;
4502
+ }
4503
+ const refuse = (res, status, extra = {}) => {
4504
+ res.writeHead(status, {
4505
+ "content-type": "text/plain; charset=utf-8",
4506
+ "cache-control": "no-store",
4507
+ ...extra
4508
+ });
4509
+ res.end(String(status));
4510
+ };
4511
+ /**
4512
+ * `GET /__mv/app/live` (#5, #6): mounted right after the workspace guard (an `x-mv-ws` naming another workspace is a
4513
+ * 409 before anything is read) and the perf barrier. Another method 405; an `x-mv-app` that is not `appProof(key,
4514
+ * port)` 403, and a missing or malformed `x-mv-nonce` 400 - before anything is read or computed. The 200 carries
4515
+ * `x-mv-instance` and `x-mv-proof` = `liveProof`. No hub or no proof (no slot: an in-process plugin, a test server):
4516
+ * 404. Proved, the stream admits nothing else: it never makes a document trusted.
4517
+ */
4518
+ function liveRoute(hub, proof) {
4519
+ return (req, res, next) => {
4520
+ if ((req.url ?? "").split("?")[0] !== LIVE_WIRE.path) return next();
4521
+ if (!hub || !proof) return refuse(res, 404);
4522
+ if (req.method !== "GET") return refuse(res, 405, { allow: "GET" });
4523
+ if (!appProofOk(proof, req.headers["x-mv-app"])) return refuse(res, 403);
4524
+ const signed = proofHeaders(proof, req.headers["x-mv-nonce"], "live");
4525
+ if (!signed) return refuse(res, 400);
4526
+ res.writeHead(200, {
4527
+ "content-type": `${LIVE_WIRE.type}; charset=utf-8`,
4528
+ "cache-control": "no-store",
4529
+ "x-content-type-options": "nosniff",
4530
+ ...signed
4531
+ });
4532
+ res.socket?.setNoDelay(true);
4533
+ res.flushHeaders?.();
4534
+ hub.add(res);
4535
+ };
4536
+ }
4537
+ //#endregion
4538
+ //#region src/server/jam/live.ts
4539
+ var live_exports = /* @__PURE__ */ __exportAll({ jamLive: () => jamLive });
4540
+ const jamLive = {};
4541
+ //#endregion
4395
4542
  //#region src/server/plugin.ts
4396
4543
  const VIRTUAL_THEME = "virtual:sh-theme";
4397
4544
  const VIRTUAL_CONFIG = "virtual:sh-config";
@@ -4433,6 +4580,7 @@ function marverPlugin(ctx) {
4433
4580
  return s ? loadedFiles(urls, s.config.root, s.environments?.client?.moduleGraph ?? null, s.config.base) : [];
4434
4581
  }
4435
4582
  };
4583
+ const live = liveSources(root);
4436
4584
  const bootId = String(process.hrtime.bigint());
4437
4585
  let invRev = 0;
4438
4586
  const pendingInv = /* @__PURE__ */ new Set();
@@ -4507,7 +4655,10 @@ function marverPlugin(ctx) {
4507
4655
  };
4508
4656
  const observeMarks = () => observed(observe(root, manifest.frames));
4509
4657
  const observeLater = () => whenSettled(() => {
4510
- if (observeMarks()) devServer?.ws.send("sh:marks", {});
4658
+ if (observeMarks()) {
4659
+ devServer?.ws.send("sh:marks", {});
4660
+ liveChanged();
4661
+ }
4511
4662
  });
4512
4663
  const hooks = {
4513
4664
  onFrames: (t, cause) => {
@@ -4531,7 +4682,10 @@ function marverPlugin(ctx) {
4531
4682
  const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
4532
4683
  for (const id of reload) pendingInv.add(id);
4533
4684
  flushInv();
4534
- if (reload.length || touched.length || seen.note.length) devServer?.ws.send("sh:marks", {});
4685
+ if (reload.length || touched.length || seen.note.length) {
4686
+ devServer?.ws.send("sh:marks", {});
4687
+ liveChanged();
4688
+ }
4535
4689
  logReload(root, {
4536
4690
  kind: "update",
4537
4691
  cause,
@@ -4658,6 +4812,13 @@ function marverPlugin(ctx) {
4658
4812
  }
4659
4813
  server.middlewares.use(guardMiddleware(ws));
4660
4814
  server.middlewares.use(perfRunBarrier());
4815
+ const hub = ctx.proof ? createLiveHub({
4816
+ instance: ctx.proof.instance,
4817
+ read: () => liveSnapshot(live.read(manifest.frames)),
4818
+ on: (fn) => workActivity.onChange(fn)
4819
+ }) : null;
4820
+ if (hub) onClose(() => hub.close());
4821
+ server.middlewares.use(liveRoute(hub, ctx.proof));
4661
4822
  const viteWatcher = server.watcher;
4662
4823
  watching.server = server;
4663
4824
  watching.watcher = viteWatcher;
@@ -4699,7 +4860,10 @@ function marverPlugin(ctx) {
4699
4860
  viewports: config.viewports,
4700
4861
  origin: listeningOrigin,
4701
4862
  bakeGen: () => bakeGen,
4702
- notify: (event) => server.ws.send(event, {}),
4863
+ notify: (event) => {
4864
+ server.ws.send(event, {});
4865
+ liveChanged();
4866
+ },
4703
4867
  manifest: () => manifest,
4704
4868
  settled,
4705
4869
  workspace: ws,
@@ -4732,8 +4896,10 @@ function marverPlugin(ctx) {
4732
4896
  const changed = writeManifest(root, manifest);
4733
4897
  observeLater();
4734
4898
  const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
4735
- if (changed && key !== framesKey) server.ws.send("sh:manifest", manifest);
4736
- else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
4899
+ if (changed && key !== framesKey) {
4900
+ server.ws.send("sh:manifest", manifest);
4901
+ liveChanged();
4902
+ } else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
4737
4903
  framesKey = key;
4738
4904
  scenesKey = sKey;
4739
4905
  }, 150);
@@ -4965,7 +5131,7 @@ function marverPlugin(ctx) {
4965
5131
  });
4966
5132
  return;
4967
5133
  }
4968
- const { shootFrame, shootBatch, resolveFrames } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
5134
+ const { shootFrame, shootBatch, resolveFrames } = await import("./shot-T04Ixrvq.mjs").then((n) => n.u);
4969
5135
  if (ways[0] === "frame") {
4970
5136
  if (typeof spec.frame !== "string") {
4971
5137
  write({
@@ -5035,6 +5201,53 @@ function marverPlugin(ctx) {
5035
5201
  }
5036
5202
  }, updatesPlugin(root, () => manifest, () => devServer && hooks, landed)];
5037
5203
  }
5204
+ /**
5205
+ * The live stream's four adapters (spec 28 A4.6 #7), the hub's `read()`: every board's comment log replayed - cached by
5206
+ * its `size:mtimeMs`, so a recompute re-reads only a log that changed (the logs only grow); the frames new now, from the
5207
+ * running server's marks (`freshFrames`); Jam's view (`jamLive.view()`, absent when Jam is off or its lock is held
5208
+ * elsewhere); and `marver work`'s own leases - never `active()`, which holds the Jam daemon's too (A4.6 r2 #3).
5209
+ */
5210
+ function liveSources(root) {
5211
+ const dir = join(root, "design", "comments");
5212
+ const cache = /* @__PURE__ */ new Map();
5213
+ let reads = 0;
5214
+ return {
5215
+ read(frames) {
5216
+ const names = listBoards(dir);
5217
+ for (const b of cache.keys()) if (!names.includes(b)) cache.delete(b);
5218
+ const boards = [];
5219
+ for (const board of names) {
5220
+ let key;
5221
+ try {
5222
+ const st = statSync(join(dir, `${board}.jsonl`));
5223
+ key = `${st.size}:${st.mtimeMs}`;
5224
+ } catch {
5225
+ continue;
5226
+ }
5227
+ let c = cache.get(board);
5228
+ if (c?.key !== key) {
5229
+ reads++;
5230
+ c = {
5231
+ key,
5232
+ threads: replay(readLog(dir, board))
5233
+ };
5234
+ cache.set(board, c);
5235
+ }
5236
+ boards.push({
5237
+ board,
5238
+ threads: c.threads
5239
+ });
5240
+ }
5241
+ return {
5242
+ boards,
5243
+ fresh: freshFrames(root, frames),
5244
+ jam: jamLive.view?.(),
5245
+ cli: workActivity.leases("cli").map(([f]) => f)
5246
+ };
5247
+ },
5248
+ reads: () => reads
5249
+ };
5250
+ }
5038
5251
  /** The marks look at the frames on disk; true when they recorded something. */
5039
5252
  function observed(r) {
5040
5253
  return r.doc.length + r.note.length > 0;
@@ -5086,4 +5299,4 @@ async function tailwind3Css(root) {
5086
5299
  return null;
5087
5300
  }
5088
5301
  //#endregion
5089
- export { installedVersion as a, publishLogo as i, tailwind3Css as n, ASK_MAX as o, tailwind4Plugin as r, bakeBatch as s, marverPlugin as t };
5302
+ export { live_exports as a, ASK_MAX as c, jamLive as i, bakeBatch as l, tailwind3Css as n, liveChanged as o, tailwind4Plugin as r, installedVersion as s, marverPlugin as t };