@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
@@ -1,13 +1,14 @@
1
1
  import { l as toFrameId } from "./manifest-Nl3KSVOk.mjs";
2
- import { a as workActivity } from "./work-F5u-twpJ.mjs";
2
+ import { a as workActivity } from "./work-Bp1p39kq.mjs";
3
3
  import { r as replay } from "./events-CLH4ijKP.mjs";
4
4
  import { a as readLog, t as appendEvents } from "./comments-0BSbb04K.mjs";
5
- import { n as localProfile } from "./profile-WU9qcbIo.mjs";
5
+ import { n as localProfile } from "./profile-Bh5Y5zpW.mjs";
6
6
  import { r as uncheckedAnchor } from "./anchor-5H1vnoLu.mjs";
7
7
  import { i as record, t as has } from "./ledger-D54iROST.mjs";
8
- import { _ as packetPath, a as checkRecord, c as firstPoint, d as picturePath, f as readCapture, g as goalText, h as buildPacket, n as captureFrames, o as continues, p as storeCapture, r as captureWords, t as CAPTURE_ID, v as parseAgentText, x as sharedFile, y as parseMembers } from "./capture-CrqvU_jh.mjs";
9
- import { a as recordFile, c as storeWrapup, i as readWrapup, n as buildWrapup, o as recordPathProblem, r as moreOf, t as SESSION_ID } from "./session-qZWKt_VA.mjs";
10
- import { act, addCapture, addWrapup, answeredSince, beginStep, captureComment, captureIntact, conflictStep, createQueue, ctxFor, endSession, endStep, fail, form, looksGood, moreWrapup, n as releaseLock, payloadKey, pending, prune, redelivering, sameComment, settle, startSession, stillOwned, t as acquireLock, textOf, undelivered, wrapupIntact, wrapupOf } from "./queue-BuiCKSX1.mjs";
8
+ import { _ as packetPath, a as checkRecord, c as firstPoint, d as picturePath, f as readCapture, g as goalText, h as buildPacket, n as captureFrames, o as continues, p as storeCapture, r as captureWords, t as CAPTURE_ID, v as parseAgentText, x as sharedFile, y as parseMembers } from "./capture-vadKjuCo.mjs";
9
+ import { a as recordFile, c as storeWrapup, i as readWrapup, n as buildWrapup, o as recordPathProblem, r as moreOf, t as SESSION_ID } from "./session-BAaJsK5c.mjs";
10
+ import { act, addCapture, addWrapup, answeredSince, beginStep, captureComment, captureIntact, conflictStep, createQueue, ctxFor, endSession, endStep, fail, form, looksGood, moreWrapup, n as releaseLock, payloadKey, pending, prune, redelivering, sameComment, settle, startSession, stillOwned, t as acquireLock, textOf, undelivered, wrapupIntact, wrapupOf } from "./queue-CAM_vNmX.mjs";
11
+ import { t as logJam } from "./perf-jam-D55U3FZK.mjs";
11
12
  import { jamReservations, restoreHolds } from "./reserve-BURNQ2Y3.mjs";
12
13
  import { jamLive } from "./live-Cgzsicwi.mjs";
13
14
  import { lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
@@ -939,6 +940,28 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
939
940
  * nothing when the agent has no namer, the capture has no words, or the call fails (its first words stay). */
940
941
  const naming = /* @__PURE__ */ new Set();
941
942
  let namerDir;
943
+ const queuedSince = /* @__PURE__ */ new Map();
944
+ const atBoot = /* @__PURE__ */ new Set();
945
+ let scanned = false;
946
+ const noteQueued = () => {
947
+ try {
948
+ const now = performance.now();
949
+ const queued = /* @__PURE__ */ new Set();
950
+ for (const c of q.j.cards) if (c.state === "queued") {
951
+ queued.add(c.id);
952
+ if (!queuedSince.has(c.id)) {
953
+ queuedSince.set(c.id, now);
954
+ if (!scanned) atBoot.add(c.id);
955
+ }
956
+ }
957
+ scanned = true;
958
+ for (const k of [...queuedSince.keys()]) if (!queued.has(k)) {
959
+ queuedSince.delete(k);
960
+ atBoot.delete(k);
961
+ }
962
+ } catch {}
963
+ };
964
+ const batchWaits = /* @__PURE__ */ new Map();
942
965
  const nameCapture = (id) => {
943
966
  const c0 = q.j.cards.find((x) => x.id === id);
944
967
  if (!adapter.namerArgs || cfg.names === false || !c0 || c0.kind !== "capture" || c0.name || c0.autoName || naming.has(id)) return;
@@ -952,6 +975,18 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
952
975
  let child;
953
976
  namerDir ??= mkdtempSync(join(tmpdir(), "marver-namer-"));
954
977
  const cwd = namerDir;
978
+ const t0 = performance.now();
979
+ let named = false;
980
+ const timed = (ok) => {
981
+ if (named) return;
982
+ named = true;
983
+ logJam(root, {
984
+ kind: "name",
985
+ capture: id,
986
+ ms: performance.now() - t0,
987
+ ok
988
+ });
989
+ };
955
990
  try {
956
991
  child = spawn(cmd, args, {
957
992
  cwd,
@@ -981,12 +1016,17 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
981
1016
  child.on("error", () => {
982
1017
  clearTimeout(to);
983
1018
  naming.delete(id);
1019
+ timed(false);
984
1020
  });
985
1021
  child.on("close", (code) => {
986
1022
  clearTimeout(to);
987
1023
  naming.delete(id);
988
- if (stopped || code !== 0) return;
1024
+ if (stopped || code !== 0) {
1025
+ if (!stopped) timed(false);
1026
+ return;
1027
+ }
989
1028
  const name = (out.split("\n").map((l) => l.trim()).find(Boolean) ?? "").replace(/^["'“”‘’`*#\s-]+|["'“”‘’`*.\s]+$/g, "").replace(/\s+/g, " ").slice(0, 60).trim();
1029
+ timed(!!name);
990
1030
  if (!name) return;
991
1031
  q.lock((j) => {
992
1032
  const c = j.cards.find((x) => x.id === id);
@@ -1099,6 +1139,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1099
1139
  jamReservations.settling = !ready || delivering.size > 0;
1100
1140
  };
1101
1141
  const queueChanged = () => {
1142
+ noteQueued();
1102
1143
  try {
1103
1144
  hooks.queue?.();
1104
1145
  } catch {}
@@ -1193,295 +1234,342 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1193
1234
  log(` jam: replied ${replies} of ${b.members.length}${b.model ? ` (${b.model})` : ""}${repinned ? ` · re-pinned ${repinned}` : ""}`);
1194
1235
  };
1195
1236
  const runBatch = async (b) => {
1196
- const myStart = ++batchStarts;
1197
- const aloneAtStart = [...runningBatches.keys()].every((k) => k === b.batchId);
1198
- let crowded = !!hooks.anyHold?.();
1199
- const markCrowded = (x) => {
1200
- if (x.crowded) return;
1201
- q.lock(() => {
1202
- x.crowded = true;
1203
- q.persist();
1237
+ const timing = { agentMs: [] };
1238
+ let timed = false;
1239
+ const members0 = [...b.members];
1240
+ const timeRun = (failure) => {
1241
+ if (timed) return;
1242
+ timed = true;
1243
+ const waits = batchWaits.get(b.batchId);
1244
+ batchWaits.delete(b.batchId);
1245
+ logJam(root, {
1246
+ kind: "run",
1247
+ batch: b.batchId,
1248
+ attempts: b.attempts,
1249
+ ...timing,
1250
+ ...failure ? { failure } : {},
1251
+ members: members0.map((m) => {
1252
+ const c = q.j.cards.find((x) => x.id === m.card);
1253
+ return {
1254
+ kind: c?.kind,
1255
+ waitMs: waits?.get(m.card),
1256
+ outcome: failure || !b.members.includes(m) ? "failed" : c?.state
1257
+ };
1258
+ })
1204
1259
  });
1205
1260
  };
1206
- const unwatch = hooks.watchHolds?.(() => {
1207
- crowded = true;
1208
- markCrowded(b);
1209
- }) ?? (() => {});
1210
- for (const o of runningBatches.values()) if (o !== b) markCrowded(o);
1211
- const bad = [];
1212
- const logs = /* @__PURE__ */ new Map();
1213
- const threadsOf = (board) => {
1214
- let t = logs.get(board);
1215
- if (!t) logs.set(board, t = replay(readLog(commentsDir, board)));
1216
- return t;
1217
- };
1218
- const members = [];
1219
- let disk = null;
1220
1261
  try {
1221
- disk = JSON.parse(readFileSync(join(root, packetPath(b.batchId)), "utf8"));
1222
- } catch {
1223
- disk = null;
1224
- }
1225
- for (const m of b.members) {
1226
- const c = q.j.cards.find((x) => x.id === m.card);
1227
- const kept = m.brief ?? (c && c.kind !== "wrapup" ? disk?.members.find((x) => x.card === m.card && x.id === m.id)?.brief : void 0);
1228
- if (!c || !kept) {
1229
- bad.push(m.card);
1230
- continue;
1262
+ const myStart = ++batchStarts;
1263
+ const aloneAtStart = [...runningBatches.keys()].every((k) => k === b.batchId);
1264
+ let crowded = !!hooks.anyHold?.();
1265
+ const markCrowded = (x) => {
1266
+ if (x.crowded) return;
1267
+ q.lock(() => {
1268
+ x.crowded = true;
1269
+ q.persist();
1270
+ });
1271
+ };
1272
+ const unwatch = hooks.watchHolds?.(() => {
1273
+ crowded = true;
1274
+ markCrowded(b);
1275
+ }) ?? (() => {});
1276
+ for (const o of runningBatches.values()) if (o !== b) markCrowded(o);
1277
+ const bad = [];
1278
+ const logs = /* @__PURE__ */ new Map();
1279
+ const threadsOf = (board) => {
1280
+ let t = logs.get(board);
1281
+ if (!t) logs.set(board, t = replay(readLog(commentsDir, board)));
1282
+ return t;
1283
+ };
1284
+ const members = [];
1285
+ let disk = null;
1286
+ try {
1287
+ disk = JSON.parse(readFileSync(join(root, packetPath(b.batchId)), "utf8"));
1288
+ } catch {
1289
+ disk = null;
1231
1290
  }
1232
- let brief = kept;
1233
- if (c.kind === "wrapup") {
1234
- const w = readWrapup(root, wrapupOf(c));
1235
- if (!w || !wrapupIntact(q.ctx(), c) || recordPathProblem(root, w.wrapup.file)) {
1291
+ for (const m of b.members) {
1292
+ const c = q.j.cards.find((x) => x.id === m.card);
1293
+ const kept = m.brief ?? (c && c.kind !== "wrapup" ? disk?.members.find((x) => x.card === m.card && x.id === m.id)?.brief : void 0);
1294
+ if (!c || !kept) {
1236
1295
  bad.push(m.card);
1237
1296
  continue;
1238
1297
  }
1239
- brief = {
1240
- ...brief,
1241
- wrapup: {
1242
- content: w.wrapup,
1243
- hash: w.hash
1244
- }
1245
- };
1246
- } else if (brief.wrapup) {
1247
- const { wrapup: _w, ...rest } = brief;
1248
- brief = rest;
1249
- }
1250
- const t = c.thread ? threadsOf(m.board).find((x) => x.id === c.thread) : void 0;
1251
- members.push({
1252
- id: m.id,
1253
- card: c.id,
1254
- kind: c.kind,
1255
- board: m.board,
1256
- ...c.thread ? { thread: c.thread } : {},
1257
- frames: c.frames,
1258
- ...t?.anchor !== void 0 ? { anchor: t.anchor } : {},
1259
- brief
1260
- });
1261
- }
1262
- if (bad.length) {
1263
- await q.lock((j) => {
1264
- for (const id of bad) {
1265
- const c = j.cards.find((x) => x.id === id);
1266
- if (c && c.state === "working") {
1267
- c.state = "failed";
1268
- c.note = c.kind === "wrapup" ? "the session record changed after it was written - write it again" : "interrupted - Retry";
1269
- c.rev += 1;
1270
- c.at = Date.now();
1298
+ let brief = kept;
1299
+ if (c.kind === "wrapup") {
1300
+ const w = readWrapup(root, wrapupOf(c));
1301
+ if (!w || !wrapupIntact(q.ctx(), c) || recordPathProblem(root, w.wrapup.file)) {
1302
+ bad.push(m.card);
1303
+ continue;
1271
1304
  }
1305
+ brief = {
1306
+ ...brief,
1307
+ wrapup: {
1308
+ content: w.wrapup,
1309
+ hash: w.hash
1310
+ }
1311
+ };
1312
+ } else if (brief.wrapup) {
1313
+ const { wrapup: _w, ...rest } = brief;
1314
+ brief = rest;
1272
1315
  }
1273
- q.persist();
1274
- });
1275
- b.members = b.members.filter((m) => !bad.includes(m.card));
1276
- if (!b.members.length) {
1316
+ const t = c.thread ? threadsOf(m.board).find((x) => x.id === c.thread) : void 0;
1317
+ members.push({
1318
+ id: m.id,
1319
+ card: c.id,
1320
+ kind: c.kind,
1321
+ board: m.board,
1322
+ ...c.thread ? { thread: c.thread } : {},
1323
+ frames: c.frames,
1324
+ ...t?.anchor !== void 0 ? { anchor: t.anchor } : {},
1325
+ brief
1326
+ });
1327
+ }
1328
+ if (bad.length) {
1277
1329
  await q.lock((j) => {
1278
- const x = j.batches.find((y) => y.batchId === b.batchId);
1279
- if (x) x.state = "failed";
1330
+ for (const id of bad) {
1331
+ const c = j.cards.find((x) => x.id === id);
1332
+ if (c && c.state === "working") {
1333
+ c.state = "failed";
1334
+ c.note = c.kind === "wrapup" ? "the session record changed after it was written - write it again" : "interrupted - Retry";
1335
+ c.rev += 1;
1336
+ c.at = Date.now();
1337
+ }
1338
+ }
1280
1339
  q.persist();
1281
1340
  });
1282
- queueChanged();
1283
- return;
1284
- }
1285
- }
1286
- const packet = buildPacket(b.batchId, members, b.frames, b.exclusive ? [...new Set(cards0(b).flatMap((c) => c.exclusive ?? []))] : void 0);
1287
- writeFileSync(join(root, packetPath(b.batchId)), JSON.stringify(packet, null, 1), { mode: 384 });
1288
- const cards = () => b.members.map((m) => q.j.cards.find((c) => c.id === m.card)).filter((c) => !!c);
1289
- const lit = /* @__PURE__ */ new Set();
1290
- const light = (f) => {
1291
- if (f && !lit.has(f)) {
1292
- hooks.work?.(f, true);
1293
- lit.add(f);
1341
+ b.members = b.members.filter((m) => !bad.includes(m.card));
1342
+ if (!b.members.length) {
1343
+ await q.lock((j) => {
1344
+ const x = j.batches.find((y) => y.batchId === b.batchId);
1345
+ if (x) x.state = "failed";
1346
+ q.persist();
1347
+ });
1348
+ queueChanged();
1349
+ timeRun("changed");
1350
+ return;
1351
+ }
1294
1352
  }
1295
- };
1296
- const clearGlow = () => {
1297
- for (const f of lit) hooks.work?.(f, false);
1298
- lit.clear();
1299
- };
1300
- const startMtimes = sceneFrameMtimes(root);
1301
- await q.lock(() => {
1302
- const made = new Set(b.created ?? []);
1303
- b.before = [.../* @__PURE__ */ new Set([...b.before ?? [], ...[...startMtimes.keys()].filter((f) => !made.has(f))])];
1304
- q.persist();
1305
- });
1306
- if (crowded || !aloneAtStart) await q.lock(() => {
1307
- b.crowded = true;
1308
- q.persist();
1309
- });
1310
- const one0 = b.members.length === 1 ? q.j.cards.find((c) => c.id === b.members[0].card) : void 0;
1311
- const discover = async () => {
1312
- if (one0?.kind !== "capture" || b.crowded || crowded || !aloneAtStart || batchStarts !== myStart || hooks.anyHold?.()) return;
1313
- const found = newFrames(new Set(b.before ?? []), b).filter((f) => !(b.created ?? []).includes(f));
1314
- if (!found.length) return;
1353
+ const packet = buildPacket(b.batchId, members, b.frames, b.exclusive ? [...new Set(cards0(b).flatMap((c) => c.exclusive ?? []))] : void 0);
1354
+ writeFileSync(join(root, packetPath(b.batchId)), JSON.stringify(packet, null, 1), { mode: 384 });
1355
+ const cards = () => b.members.map((m) => q.j.cards.find((c) => c.id === m.card)).filter((c) => !!c);
1356
+ const lit = /* @__PURE__ */ new Set();
1357
+ const light = (f) => {
1358
+ if (f && !lit.has(f)) {
1359
+ hooks.work?.(f, true);
1360
+ lit.add(f);
1361
+ }
1362
+ };
1363
+ const clearGlow = () => {
1364
+ for (const f of lit) hooks.work?.(f, false);
1365
+ lit.clear();
1366
+ };
1367
+ const startMtimes = sceneFrameMtimes(root);
1315
1368
  await q.lock(() => {
1316
- b.created = [...b.created ?? [], ...found];
1317
- b.frames = [.../* @__PURE__ */ new Set([...b.frames, ...b.created])];
1369
+ const made = new Set(b.created ?? []);
1370
+ b.before = [.../* @__PURE__ */ new Set([...b.before ?? [], ...[...startMtimes.keys()].filter((f) => !made.has(f))])];
1318
1371
  q.persist();
1319
1372
  });
1320
- reserve();
1321
- };
1322
- const sharedBefore = b.exclusive ? null : sharedMtimes(root);
1323
- const touched = /* @__PURE__ */ new Set();
1324
- for (const f of b.frames) light(f);
1325
- const capturing = cards().some((c) => !!c.capture);
1326
- const theme = (() => {
1327
- const c = cards().find((x) => x.capture);
1328
- return c && readCapture(root, c.capture)?.record.view.theme || "light";
1329
- })();
1330
- const sizes = Object.assign({}, ...cards().flatMap((c) => c.capture ? [readCapture(root, c.capture)?.record.sizes ?? {}] : []));
1331
- const shoot = async (when) => {
1332
- if (!capturing || !hooks.shoot) return;
1333
- const shots = b.shots ?? b.frames.map((frame) => ({ frame }));
1334
- for (const s of shots) {
1335
- if (stopped) return;
1336
- if (s.new) continue;
1337
- const id = await hooks.shoot(s.frame, theme, { batch: b.batchId }, sizes[s.frame]).catch(() => null);
1338
- if (id) s[when] = id;
1339
- }
1340
- if (when === "after") for (const s of shots) if (s.before && s.after && samePicture(s.before, s.after)) s.same = true;
1341
- else delete s.same;
1342
- await q.lock(() => {
1343
- b.shots = shots;
1373
+ if (crowded || !aloneAtStart) await q.lock(() => {
1374
+ b.crowded = true;
1344
1375
  q.persist();
1345
1376
  });
1346
- };
1347
- if (!b.shots?.some((s) => s.before)) await shoot("before");
1348
- const followWork = () => {
1349
- if (hooks.anyHold?.()) crowded = true;
1350
- discover();
1351
- for (const [id, mt] of sceneFrameMtimes(root)) if (startMtimes.get(id) !== mt) touched.add(id);
1352
- for (const id of touched) light(id);
1353
- for (const f of lit) hooks.work?.(f, true);
1354
- };
1355
- let early;
1356
- let run = {
1357
- reply: "",
1358
- asks: false,
1359
- ok: false,
1360
- reanchors: []
1361
- };
1362
- try {
1363
- while (!stopped && b.attempts < MAX_ATTEMPTS) {
1377
+ const one0 = b.members.length === 1 ? q.j.cards.find((c) => c.id === b.members[0].card) : void 0;
1378
+ const discover = async () => {
1379
+ if (one0?.kind !== "capture" || b.crowded || crowded || !aloneAtStart || batchStarts !== myStart || hooks.anyHold?.()) return;
1380
+ const found = newFrames(new Set(b.before ?? []), b).filter((f) => !(b.created ?? []).includes(f));
1381
+ if (!found.length) return;
1364
1382
  await q.lock(() => {
1365
- b.attempts += 1;
1366
- b.leaseUntil = Date.now() + LEASE_MS;
1383
+ b.created = [...b.created ?? [], ...found];
1384
+ b.frames = [.../* @__PURE__ */ new Set([...b.frames, ...b.created])];
1367
1385
  q.persist();
1368
1386
  });
1369
- for (const m of packet.members) if (m.kind === "wrapup") {
1370
- const c = q.j.cards.find((x) => x.id === m.card);
1371
- const w = c && readWrapup(root, wrapupOf(c));
1372
- if (!c || !w || !wrapupIntact(q.ctx(), c) || recordPathProblem(root, w.wrapup.file)) throw new Error("the session record changed after it was written - write it again");
1373
- m.brief = {
1374
- ...m.brief,
1375
- wrapup: {
1376
- content: w.wrapup,
1377
- hash: w.hash
1378
- }
1379
- };
1387
+ reserve();
1388
+ };
1389
+ const sharedBefore = b.exclusive ? null : sharedMtimes(root);
1390
+ const touched = /* @__PURE__ */ new Set();
1391
+ for (const f of b.frames) light(f);
1392
+ const capturing = cards().some((c) => !!c.capture);
1393
+ const theme = (() => {
1394
+ const c = cards().find((x) => x.capture);
1395
+ return c && readCapture(root, c.capture)?.record.view.theme || "light";
1396
+ })();
1397
+ const sizes = Object.assign({}, ...cards().flatMap((c) => c.capture ? [readCapture(root, c.capture)?.record.sizes ?? {}] : []));
1398
+ const shoot = async (when) => {
1399
+ if (!capturing || !hooks.shoot) return;
1400
+ const shots = b.shots ?? b.frames.map((frame) => ({ frame }));
1401
+ for (const s of shots) {
1402
+ if (stopped) return;
1403
+ if (s.new) continue;
1404
+ const id = await hooks.shoot(s.frame, theme, { batch: b.batchId }, sizes[s.frame]).catch(() => null);
1405
+ if (id) s[when] = id;
1380
1406
  }
1381
- writeFileSync(join(root, packetPath(b.batchId)), JSON.stringify(packet, null, 1), { mode: 384 });
1382
- const beat = setInterval(followWork, 2e3);
1383
- beat.unref?.();
1384
- try {
1385
- const one = b.members.length === 1 ? cards()[0] : void 0;
1386
- run = await runAgent(goalText(packet, cfg.subagents && adapter.supportsSubagents), (pid) => {
1387
- b.pgid = pid;
1407
+ if (when === "after") for (const s of shots) if (s.before && s.after && samePicture(s.before, s.after)) s.same = true;
1408
+ else delete s.same;
1409
+ await q.lock(() => {
1410
+ b.shots = shots;
1411
+ q.persist();
1412
+ });
1413
+ };
1414
+ if (!b.shots?.some((s) => s.before)) {
1415
+ const t = performance.now();
1416
+ await shoot("before");
1417
+ if (capturing) timing.beforeMs = performance.now() - t;
1418
+ }
1419
+ const followWork = () => {
1420
+ if (hooks.anyHold?.()) crowded = true;
1421
+ discover();
1422
+ for (const [id, mt] of sceneFrameMtimes(root)) if (startMtimes.get(id) !== mt) touched.add(id);
1423
+ for (const id of touched) light(id);
1424
+ for (const f of lit) hooks.work?.(f, true);
1425
+ };
1426
+ let early;
1427
+ let run = {
1428
+ reply: "",
1429
+ asks: false,
1430
+ ok: false,
1431
+ reanchors: []
1432
+ };
1433
+ try {
1434
+ while (!stopped && b.attempts < MAX_ATTEMPTS) {
1435
+ await q.lock(() => {
1436
+ b.attempts += 1;
1437
+ b.leaseUntil = Date.now() + LEASE_MS;
1388
1438
  q.persist();
1389
- }, one?.thread ? (text, asks, model) => {
1390
- if (stopped) return;
1391
- const p = postReply(b, one, "m1", text, asks, model, "early");
1392
- early = {
1393
- body: text,
1394
- asks,
1395
- commentId: p.commentId,
1396
- ts: p.ts
1439
+ });
1440
+ for (const m of packet.members) if (m.kind === "wrapup") {
1441
+ const c = q.j.cards.find((x) => x.id === m.card);
1442
+ const w = c && readWrapup(root, wrapupOf(c));
1443
+ if (!c || !w || !wrapupIntact(q.ctx(), c) || recordPathProblem(root, w.wrapup.file)) throw new Error("the session record changed after it was written - write it again");
1444
+ m.brief = {
1445
+ ...m.brief,
1446
+ wrapup: {
1447
+ content: w.wrapup,
1448
+ hash: w.hash
1449
+ }
1397
1450
  };
1398
- hooks.changed?.(one.board);
1399
- } : void 0);
1400
- } finally {
1401
- clearInterval(beat);
1451
+ }
1452
+ writeFileSync(join(root, packetPath(b.batchId)), JSON.stringify(packet, null, 1), { mode: 384 });
1453
+ const beat = setInterval(followWork, 2e3);
1454
+ beat.unref?.();
1455
+ const tAgent = performance.now();
1456
+ try {
1457
+ const one = b.members.length === 1 ? cards()[0] : void 0;
1458
+ run = await runAgent(goalText(packet, cfg.subagents && adapter.supportsSubagents), (pid) => {
1459
+ b.pgid = pid;
1460
+ q.persist();
1461
+ }, one?.thread ? (text, asks, model) => {
1462
+ if (stopped) return;
1463
+ const p = postReply(b, one, "m1", text, asks, model, "early");
1464
+ early = {
1465
+ body: text,
1466
+ asks,
1467
+ commentId: p.commentId,
1468
+ ts: p.ts
1469
+ };
1470
+ hooks.changed?.(one.board);
1471
+ } : void 0);
1472
+ } finally {
1473
+ clearInterval(beat);
1474
+ timing.agentMs.push(performance.now() - tAgent);
1475
+ }
1476
+ logRun(b.batchId, run.raw);
1477
+ if (run.ok) break;
1478
+ }
1479
+ if (stopped) return;
1480
+ if (!run.ok) {
1481
+ await discover();
1482
+ await q.lock((j) => {
1483
+ ownCreated(j, b);
1484
+ settled(fail(j, b, "the agent could not finish - its run log is in design/.local/jam-logs"));
1485
+ q.persist();
1486
+ });
1487
+ queueChanged();
1488
+ log(` jam: gave up on a batch of ${b.members.length} after ${b.attempts} attempts`);
1489
+ timeRun("agent");
1490
+ return;
1491
+ }
1492
+ if (!aloneAtStart || batchStarts !== myStart || crowded || hooks.anyHold?.()) {
1493
+ if (!b.crowded) await q.lock(() => {
1494
+ b.crowded = true;
1495
+ q.persist();
1496
+ });
1402
1497
  }
1403
- logRun(b.batchId, run.raw);
1404
- if (run.ok) break;
1405
- }
1406
- if (stopped) return;
1407
- if (!run.ok) {
1408
1498
  await discover();
1409
- await q.lock((j) => {
1410
- ownCreated(j, b);
1411
- settled(fail(j, b, "the agent could not finish - its run log is in design/.local/jam-logs"));
1412
- q.persist();
1413
- });
1414
- queueChanged();
1415
- log(` jam: gave up on a batch of ${b.members.length} after ${b.attempts} attempts`);
1416
- return;
1417
- }
1418
- if (!aloneAtStart || batchStarts !== myStart || crowded || hooks.anyHold?.()) {
1419
- if (!b.crowded) await q.lock(() => {
1420
- b.crowded = true;
1499
+ const tAfter = performance.now();
1500
+ await shoot("after");
1501
+ const one = b.members.length === 1 ? cards()[0] : void 0;
1502
+ const created = capturing && one?.kind === "capture" ? liveCreated(b) : [];
1503
+ let hosts = [];
1504
+ if (!created.length && b.shots?.some((x) => x.new)) await q.lock(() => {
1505
+ b.shots = (b.shots ?? []).filter((x) => !x.new);
1421
1506
  q.persist();
1422
1507
  });
1423
- }
1424
- await discover();
1425
- await shoot("after");
1426
- const one = b.members.length === 1 ? cards()[0] : void 0;
1427
- const created = capturing && one?.kind === "capture" ? liveCreated(b) : [];
1428
- let hosts = [];
1429
- if (!created.length && b.shots?.some((x) => x.new)) await q.lock(() => {
1430
- b.shots = (b.shots ?? []).filter((x) => !x.new);
1431
- q.persist();
1432
- });
1433
- if (created.length && hooks.shoot) {
1434
- const shots = (b.shots ?? []).filter((x) => !x.new);
1435
- for (const f of created.slice(0, 3)) {
1436
- if (stopped) return;
1437
- if (shots.some((x) => x.frame === f)) continue;
1438
- const id = await hooks.shoot(f, theme, { batch: b.batchId }, sizeOnBoard(f, one.board)).catch(() => null);
1439
- shots.push({
1440
- frame: f,
1441
- ...id ? { after: id } : {},
1442
- new: true
1508
+ if (created.length && hooks.shoot) {
1509
+ const shots = (b.shots ?? []).filter((x) => !x.new);
1510
+ for (const f of created.slice(0, 3)) {
1511
+ if (stopped) return;
1512
+ if (shots.some((x) => x.frame === f)) continue;
1513
+ const id = await hooks.shoot(f, theme, { batch: b.batchId }, sizeOnBoard(f, one.board)).catch(() => null);
1514
+ shots.push({
1515
+ frame: f,
1516
+ ...id ? { after: id } : {},
1517
+ new: true
1518
+ });
1519
+ }
1520
+ const own = shots.filter((x) => !x.new && one.frames.includes(x.frame));
1521
+ if (one.thread && own.every((x) => x.same)) hosts = [{
1522
+ member: b.members[0].id,
1523
+ frame: created[0]
1524
+ }];
1525
+ await q.lock(() => {
1526
+ b.shots = shots;
1527
+ q.persist();
1443
1528
  });
1444
1529
  }
1445
- const own = shots.filter((x) => !x.new && one.frames.includes(x.frame));
1446
- if (one.thread && own.every((x) => x.same)) hosts = [{
1447
- member: b.members[0].id,
1448
- frame: created[0]
1449
- }];
1530
+ if (capturing) timing.afterMs = performance.now() - tAfter;
1531
+ const split = parseMembers(run.said ?? run.reply, b.members.map((m) => m.id));
1532
+ const changedShared = sharedBefore ? [...sharedMtimes(root)].filter(([f, mt]) => sharedBefore.get(f) !== mt).map(([f]) => f) : [];
1533
+ const results = {};
1534
+ for (const [id, r0] of Object.entries(split)) {
1535
+ let r = r0;
1536
+ if ("shared" in r) {
1537
+ const files = r.shared.map(realShared).filter((f) => !!f);
1538
+ r = files.length ? { shared: files } : { missing: true };
1539
+ }
1540
+ results[id] = "body" in r ? {
1541
+ body: r.body,
1542
+ asks: r.asks,
1543
+ ...run.model ? { model: run.model } : {},
1544
+ reanchors: [],
1545
+ ...changedShared.length ? { alsoChanged: changedShared } : {}
1546
+ } : r;
1547
+ }
1450
1548
  await q.lock(() => {
1451
- b.shots = shots;
1549
+ b.results = results;
1550
+ if (run.reanchors.length) b.reanchors = run.reanchors;
1551
+ if (hosts.length) b.hosts = hosts;
1552
+ if (early) b.early = early;
1553
+ if (run.model) b.model = run.model;
1452
1554
  q.persist();
1453
1555
  });
1454
- }
1455
- const split = parseMembers(run.said ?? run.reply, b.members.map((m) => m.id));
1456
- const changedShared = sharedBefore ? [...sharedMtimes(root)].filter(([f, mt]) => sharedBefore.get(f) !== mt).map(([f]) => f) : [];
1457
- const results = {};
1458
- for (const [id, r0] of Object.entries(split)) {
1459
- let r = r0;
1460
- if ("shared" in r) {
1461
- const files = r.shared.map(realShared).filter((f) => !!f);
1462
- r = files.length ? { shared: files } : { missing: true };
1556
+ if (changedShared.length) log(` jam: also changed ${changedShared.map((f) => relative("design", f)).join(", ")}`);
1557
+ const tDeliver = performance.now();
1558
+ try {
1559
+ await deliver(b);
1560
+ } catch (err) {
1561
+ timing.deliverMs = performance.now() - tDeliver;
1562
+ timeRun("delivery");
1563
+ throw err;
1463
1564
  }
1464
- results[id] = "body" in r ? {
1465
- body: r.body,
1466
- asks: r.asks,
1467
- ...run.model ? { model: run.model } : {},
1468
- reanchors: [],
1469
- ...changedShared.length ? { alsoChanged: changedShared } : {}
1470
- } : r;
1565
+ timing.deliverMs = performance.now() - tDeliver;
1566
+ timeRun();
1567
+ } finally {
1568
+ unwatch();
1569
+ clearGlow();
1471
1570
  }
1472
- await q.lock(() => {
1473
- b.results = results;
1474
- if (run.reanchors.length) b.reanchors = run.reanchors;
1475
- if (hosts.length) b.hosts = hosts;
1476
- if (early) b.early = early;
1477
- if (run.model) b.model = run.model;
1478
- q.persist();
1479
- });
1480
- if (changedShared.length) log(` jam: also changed ${changedShared.map((f) => relative("design", f)).join(", ")}`);
1481
- await deliver(b);
1482
1571
  } finally {
1483
- unwatch();
1484
- clearGlow();
1572
+ if (!stopped) timeRun("other");
1485
1573
  }
1486
1574
  };
1487
1575
  /** Write a card's pending comment (once - an event already there must say the same, or the step
@@ -1702,6 +1790,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1702
1790
  launch(b);
1703
1791
  }
1704
1792
  const started = await q.lock((j, ctx) => {
1793
+ noteQueued();
1705
1794
  const frames = new Set([...runningBatches.values()].flatMap((b) => b.frames));
1706
1795
  const { batches, exclusiveWaiting } = form(j, ctx, {
1707
1796
  free: Math.max(1, cfg.concurrency) - runningBatches.size,
@@ -1713,6 +1802,11 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1713
1802
  prune(j);
1714
1803
  q.persist();
1715
1804
  for (const b of batches) runningBatches.set(b.batchId, b);
1805
+ const now = performance.now();
1806
+ for (const b of batches) batchWaits.set(b.batchId, new Map(b.members.flatMap((m) => {
1807
+ const t = queuedSince.get(m.card);
1808
+ return t !== void 0 && !atBoot.has(m.card) ? [[m.card, now - t]] : [];
1809
+ })));
1716
1810
  reserve(exclusiveWaiting);
1717
1811
  for (const c of j.cards) {
1718
1812
  if (c.state !== "queued") continue;
@@ -1769,9 +1863,24 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1769
1863
  const t = setTimeout(() => {
1770
1864
  timers.delete(t);
1771
1865
  if (stopped) return;
1772
- deliver(b).then(() => settleDelivery(b), async (err) => {
1866
+ const tDeliver = performance.now();
1867
+ deliver(b).then(() => {
1868
+ logJam(root, {
1869
+ kind: "run",
1870
+ batch: b.batchId,
1871
+ redelivered: true,
1872
+ deliverMs: performance.now() - tDeliver
1873
+ });
1874
+ settleDelivery(b);
1875
+ }, async (err) => {
1773
1876
  log(` jam: posting failed again - ${err.message}`);
1774
1877
  if (n < 5) return redeliver(b, n + 1);
1878
+ logJam(root, {
1879
+ kind: "run",
1880
+ batch: b.batchId,
1881
+ redelivered: true,
1882
+ failure: "delivery"
1883
+ });
1775
1884
  await q.lock((j) => {
1776
1885
  settled(undelivered(j, b, "its replies could not be posted - Retry posts them"));
1777
1886
  q.persist();
@@ -1935,20 +2044,35 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1935
2044
  redelivering(j, b);
1936
2045
  q.persist();
1937
2046
  });
1938
- for (let n = 1;; n++) try {
1939
- await deliver(b);
1940
- break;
1941
- } catch (err) {
1942
- if (n >= 4 || stopped) {
1943
- log(` jam: could not post a recovered batch - ${err.message}; its cards fail, Retry posts them`);
1944
- await q.lock((j) => {
1945
- settled(undelivered(j, b, "its replies could not be posted - Retry posts them"));
1946
- q.persist();
2047
+ for (let n = 1;; n++) {
2048
+ const tDeliver = performance.now();
2049
+ try {
2050
+ await deliver(b);
2051
+ logJam(root, {
2052
+ kind: "run",
2053
+ batch: b.batchId,
2054
+ redelivered: true,
2055
+ deliverMs: performance.now() - tDeliver
1947
2056
  });
1948
2057
  break;
2058
+ } catch (err) {
2059
+ if (n >= 4 || stopped) {
2060
+ log(` jam: could not post a recovered batch - ${err.message}; its cards fail, Retry posts them`);
2061
+ logJam(root, {
2062
+ kind: "run",
2063
+ batch: b.batchId,
2064
+ redelivered: true,
2065
+ failure: "delivery"
2066
+ });
2067
+ await q.lock((j) => {
2068
+ settled(undelivered(j, b, "its replies could not be posted - Retry posts them"));
2069
+ q.persist();
2070
+ });
2071
+ break;
2072
+ }
2073
+ await nap(500 * 2 ** n);
2074
+ if (stopped) return;
1949
2075
  }
1950
- await nap(500 * 2 ** n);
1951
- if (stopped) return;
1952
2076
  }
1953
2077
  runningBatches.delete(b.batchId);
1954
2078
  }
@@ -2033,7 +2157,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
2033
2157
  return structuredClone(c);
2034
2158
  });
2035
2159
  queueChanged();
2036
- if (cfg.capture === "at-once" && card.state === "draft") return confirm(card.id, card.rev, "queued");
2160
+ if (cfg.capture === "at-once" && card.state === "draft" && !rec.context.interrupted) return confirm(card.id, card.rev, "queued");
2037
2161
  return {
2038
2162
  ok: true,
2039
2163
  card
@@ -2372,8 +2496,9 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
2372
2496
  * activity set (work.ts) - the `marver work` CLI writes the same set, so the canvas shows
2373
2497
  * one merged glow, and its holds are also reservations (reserve.ts), restored here before
2374
2498
  * anything is scheduled. Returns null when the adapter is unavailable or another dev server
2375
- * already holds the repo lock (that one runs the loop; this one watches without it). */
2376
- function startJam(root, cfg, log = () => {}, onChanged = () => {}, anchor, onQueue, shoot) {
2499
+ * already holds the repo lock (that one runs the loop; this one watches without it). `watched` takes the comments
2500
+ * watcher as it is made, so its error is the dev server's to say (dev.ts watchGuard), never Node's unhandled one. */
2501
+ function startJam(root, cfg, log = () => {}, onChanged = () => {}, anchor, onQueue, shoot, watched) {
2377
2502
  const adapter = adapters[cfg.agent] ?? null;
2378
2503
  if (!adapter) {
2379
2504
  log(` jam: the "${cfg.agent}" adapter is not available yet; Live Jam is off`);
@@ -2410,6 +2535,7 @@ function startJam(root, cfg, log = () => {}, onChanged = () => {}, anchor, onQue
2410
2535
  let watcher = null;
2411
2536
  try {
2412
2537
  watcher = watch(commentsDir, { persistent: false }, schedule);
2538
+ watched?.(watcher);
2413
2539
  } catch {}
2414
2540
  const interval = setInterval(() => void core.poke(), RESCAN_MS);
2415
2541
  interval.unref?.();