@marver-design/marver 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +3 -1
  3. package/dist/{anchor-DVV732zR.mjs → anchor-5H1vnoLu.mjs} +6 -1
  4. package/dist/{anchor-check-BE5VVN6Q.mjs → anchor-check-Dg5xpNnU.mjs} +1 -1
  5. package/dist/audio-CmSRYFEs.mjs +429 -0
  6. package/dist/{auth-DdUKeVKt.mjs → auth-Dix8wrXV.mjs} +1 -1
  7. package/dist/{bake-D8byeRzB.mjs → bake-DtVlm0_F.mjs} +45 -6
  8. package/dist/{boards-Csxj2WJn.mjs → boards-DYG22tOe.mjs} +2 -2
  9. package/dist/{build-BHoWLvSj.mjs → build-C_gUgcdC.mjs} +16 -9
  10. package/dist/capture-CrqvU_jh.mjs +729 -0
  11. package/dist/cli.mjs +23 -17
  12. package/dist/{collab-gqNdScUE.mjs → collab-Dxg2trOK.mjs} +4 -3
  13. package/dist/{comments-Zoch254k.mjs → comments-0BSbb04K.mjs} +14 -3
  14. package/dist/{comments-pTLlhjh4.mjs → comments-BqXua-XL.mjs} +7 -7
  15. package/dist/{config-cKgZBRj0.mjs → config-Cf7EjAMf.mjs} +12 -1
  16. package/dist/{context-D2ugHqwO.mjs → context-HQ4Giw58.mjs} +1 -1
  17. package/dist/daemon-DZo6o3rU.mjs +2445 -0
  18. package/dist/{dev-DJdgow47.mjs → dev-_Nlsc6v9.mjs} +189 -18
  19. package/dist/dev-lock-DWSpa6nj.mjs +179 -0
  20. package/dist/{events-DnK_AnrW.mjs → events-CLH4ijKP.mjs} +14 -4
  21. package/dist/{init-DO4DhUt_.mjs → init-D8DtrK_F.mjs} +2 -2
  22. package/dist/{ledger-BNXW14Xw.mjs → ledger-D54iROST.mjs} +17 -1
  23. package/dist/{link-C-qUIuKU.mjs → link-BNzLvdhI.mjs} +2 -2
  24. package/dist/live-Cgzsicwi.mjs +4 -0
  25. package/dist/{manifest-DnAte_fB.mjs → manifest-Nl3KSVOk.mjs} +1 -1
  26. package/dist/{marks-koRsbHfe.mjs → marks-CKgzucHZ.mjs} +2 -2
  27. package/dist/{marks-DFuintmJ.mjs → marks-NQi0wZJ4.mjs} +23 -5
  28. package/dist/{marver-id-gate-DGANtVyC.mjs → marver-id-gate-BjF6v4bT.mjs} +4 -4
  29. package/dist/{perf-QJIWtTw1.mjs → perf-D6VmmJ2q.mjs} +1 -1
  30. package/dist/{perf-CCisg-ny.mjs → perf-DPbLGhhO.mjs} +1 -1
  31. package/dist/{plugin-CTyhjwoJ.mjs → plugin-CTD0rydA.mjs} +279 -38
  32. package/dist/{poster-D0cbV7hi.mjs → poster-ChjXGTS5.mjs} +1 -1
  33. package/dist/{profile-Do0nGkXO.mjs → profile-WU9qcbIo.mjs} +1 -1
  34. package/dist/{publish-bakes--l8ot2eQ.mjs → publish-bakes-CEP_2NRc.mjs} +3 -3
  35. package/dist/queue-BuiCKSX1.mjs +1319 -0
  36. package/dist/reserve-BURNQ2Y3.mjs +53 -0
  37. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
  38. package/dist/{serve-wv2QWdxB.mjs → serve-C8rVheYk.mjs} +12 -12
  39. package/dist/session-qZWKt_VA.mjs +191 -0
  40. package/dist/{share-ScamJcks.mjs → share--oFJ1bCI.mjs} +2 -2
  41. package/dist/{shot-jdO_B6Qw.mjs → shot-CNbHoZ6H.mjs} +1 -1
  42. package/dist/{shot-CckrGW-J.mjs → shot-DqcxJibP.mjs} +4 -3
  43. package/dist/speech-models-DomiLQcY.mjs +299 -0
  44. package/dist/speech-worker.mjs +319 -0
  45. package/dist/{summary-CrW88e3q.mjs → summary-Y8MY1Wuc.mjs} +2 -2
  46. package/dist/{sync-C3035OnJ.mjs → sync-DKk-yT1V.mjs} +9 -8
  47. package/dist/{work-GE88wb_3.mjs → work-F5u-twpJ.mjs} +28 -5
  48. package/dist/{work-CpJn1gwY.mjs → work-VvX_JIgl.mjs} +2 -2
  49. package/docs/jam-session.md +177 -0
  50. package/docs/live-jam.md +21 -3
  51. package/package.json +7 -1
  52. package/src/client/frame-host/bridge.js +20 -2
  53. package/src/client/frame-host/inspect.d.ts +4 -0
  54. package/src/client/frame-host/inspect.js +88 -3
  55. package/src/client/frame-host/keys.d.ts +6 -0
  56. package/src/client/frame-host/keys.js +55 -0
  57. package/src/client/frame-host/trail.d.ts +7 -0
  58. package/src/client/frame-host/trail.js +204 -0
  59. package/src/client/shell/App.tsx +45 -5
  60. package/src/client/shell/Comments.tsx +20 -6
  61. package/src/client/shell/JamSurface.tsx +340 -0
  62. package/src/client/shell/Play.tsx +22 -3
  63. package/src/client/shell/Tip.tsx +8 -3
  64. package/src/client/shell/canvas/Canvas.tsx +12 -2
  65. package/src/client/shell/canvas/FrameNode.tsx +11 -2
  66. package/src/client/shell/canvas/sleep.ts +19 -1
  67. package/src/client/shell/comments-store.ts +23 -16
  68. package/src/client/shell/icons.tsx +15 -0
  69. package/src/client/shell/jam-capture.ts +939 -0
  70. package/src/client/shell/jam-keys.ts +329 -0
  71. package/src/client/shell/jam-lane.tsx +208 -0
  72. package/src/client/shell/jam-lines.ts +115 -0
  73. package/src/client/shell/jam-panel.tsx +506 -0
  74. package/src/client/shell/jam-queue.ts +126 -0
  75. package/src/client/shell/jam-session.tsx +389 -0
  76. package/src/client/shell/jam-state.ts +61 -0
  77. package/src/client/shell/jam-surface-parts.tsx +102 -0
  78. package/src/client/shell/jam-ui.tsx +104 -0
  79. package/src/client/shell/jam-voice.ts +479 -0
  80. package/src/client/shell/sound.ts +22 -0
  81. package/src/client/shell/stage-size.ts +11 -0
  82. package/src/client/shell/store.ts +34 -13
  83. package/src/client/shell/styles.css +544 -2
  84. package/src/client/stage/main.tsx +16 -2
  85. package/src/shared/capture-frames.ts +41 -0
  86. package/src/shared/events.ts +19 -4
  87. package/src/shared/speech.ts +16 -0
  88. package/templates/AGENTS-embedded.md +10 -2
  89. package/templates/AGENTS-studio.md +10 -2
  90. package/templates/instructions/iterate.md +8 -6
  91. package/templates/instructions/jam.md +129 -59
  92. package/dist/daemon-Cl8KXGW4.mjs +0 -1523
@@ -1,12 +1,13 @@
1
1
  import { i as PKG, r as NAME } from "./cli.mjs";
2
- import { n as loadConfig, r as detectHost } from "./config-cKgZBRj0.mjs";
3
- import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-CTyhjwoJ.mjs";
2
+ import { n as loadConfig, r as detectHost } from "./config-Cf7EjAMf.mjs";
3
+ import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-CTD0rydA.mjs";
4
4
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch } from "node:fs";
5
- import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
5
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
- import { createLogger, createServer, parseAst, searchForWorkspaceRoot } from "vite";
7
+ import { createServer } from "node:net";
8
+ import { createLogger, createServer as createServer$1, parseAst, parseSync, searchForWorkspaceRoot } from "vite";
8
9
  import react from "@vitejs/plugin-react";
9
- import { createServer as createServer$1 } from "node:net";
10
+ import MagicString from "magic-string";
10
11
  //#region src/server/icons.ts
11
12
  /**
12
13
  * Icon barrels, unrolled.
@@ -200,13 +201,116 @@ function iconsPlugin(root) {
200
201
  };
201
202
  }
202
203
  //#endregion
204
+ //#region src/server/loc.ts
205
+ /**
206
+ * Every element knows its source (spec 27, Part 6). A dev-only transform on design files adds
207
+ * `data-mv-loc="<path>:<line>:<col>"` to every HOST JSX element - a lowercase plain name (`<div>`,
208
+ * `<button>`, `<my-el>`). Components (`<Card>`) and member names (`<motion.div>`) are skipped: they
209
+ * may not pass attributes on. The laser and a capture's bundles already read `dataset.mvLoc` into
210
+ * `source` (frame-host/inspect.js), so a pick names its file and line and the agent goes there first.
211
+ *
212
+ * It parses with Vite's own `parseSync` (oxc), so anything Vite compiles it reads, and inserts the
213
+ * attribute right after the tag name - FIRST, so an explicit `data-mv-loc` or a spread later in the
214
+ * tag wins. Edits go through magic-string, whose hires map composes with Vite's.
215
+ *
216
+ * Location: the `<` of the opening tag in the ORIGINAL source, 1-based line and 1-based column, the
217
+ * column in UTF-16 code units - what JS string indices, source maps and editors' column counters
218
+ * (VS Code included) use, so an emoji before the tag counts 2.
219
+ */
220
+ const DESIGN_FILE = /\.(tsx|jsx)$/;
221
+ /** Line starts of `code`, so an offset becomes a 1-based line and column. */
222
+ function lineIndex(code) {
223
+ const starts = [0];
224
+ for (let i = 0; i < code.length; i++) if (code.charCodeAt(i) === 10) starts.push(i + 1);
225
+ return (offset) => {
226
+ let lo = 0, hi = starts.length - 1;
227
+ while (lo < hi) {
228
+ const mid = lo + hi + 1 >> 1;
229
+ if (starts[mid] <= offset) lo = mid;
230
+ else hi = mid - 1;
231
+ }
232
+ return {
233
+ line: lo + 1,
234
+ col: offset - starts[lo] + 1
235
+ };
236
+ };
237
+ }
238
+ /** Add `data-mv-loc` to every host element of one design file. `file` is the path the attribute
239
+ * names (relative to the repo root, forward slashes). Null when there is nothing to add or the
240
+ * file does not parse - Vite then reports the error as it would have. */
241
+ function addSourceLocations(code, file) {
242
+ if (!code.includes("<")) return null;
243
+ const parsed = parseSync(file, code, {
244
+ lang: file.endsWith(".jsx") ? "jsx" : "tsx",
245
+ sourceType: "module"
246
+ });
247
+ if (parsed.errors.length) return null;
248
+ const at = lineIndex(code);
249
+ const s = new MagicString(code);
250
+ let added = 0;
251
+ const walk = (n) => {
252
+ if (!n || typeof n !== "object") return;
253
+ if (Array.isArray(n)) {
254
+ for (const x of n) walk(x);
255
+ return;
256
+ }
257
+ const node = n;
258
+ if (node.type === "JSXOpeningElement" && node.name?.type === "JSXIdentifier" && /^[a-z]/.test(node.name.name ?? "") && typeof node.start === "number" && typeof node.name.end === "number") {
259
+ const { line, col } = at(node.start);
260
+ s.appendLeft(node.name.end, ` data-mv-loc={${JSON.stringify(`${file}:${line}:${col}`)}}`);
261
+ added++;
262
+ }
263
+ for (const k in node) if (k !== "parent") walk(node[k]);
264
+ };
265
+ walk(parsed.program);
266
+ if (!added) return null;
267
+ return {
268
+ code: s.toString(),
269
+ map: s.generateMap({
270
+ hires: true,
271
+ source: file,
272
+ includeContent: true
273
+ })
274
+ };
275
+ }
276
+ /** The dev server's plugin: design/**\/*.tsx|jsx only, never node_modules, never the published
277
+ * build (dev.ts adds it; build.ts does not). Ids are real paths, so the root is matched both ways. */
278
+ function locPlugin(root) {
279
+ const roots = [.../* @__PURE__ */ new Set([root, safeReal$1(root)])];
280
+ const repoPath = (id) => {
281
+ const file = id.split("?")[0];
282
+ if (!DESIGN_FILE.test(file) || file.includes(`${sep}node_modules${sep}`) || file.includes("/node_modules/")) return null;
283
+ for (const r of roots) {
284
+ const rel = relative(r, file);
285
+ if (!rel.startsWith("..") && (rel.startsWith(`design${sep}`) || rel.startsWith("design/"))) return rel.split(sep).join("/");
286
+ }
287
+ return null;
288
+ };
289
+ return {
290
+ name: "marver:loc",
291
+ enforce: "pre",
292
+ apply: "serve",
293
+ transform(code, id) {
294
+ const file = repoPath(id);
295
+ return file ? addSourceLocations(code, file) : null;
296
+ }
297
+ };
298
+ }
299
+ function safeReal$1(p) {
300
+ try {
301
+ return realpathSync(p);
302
+ } catch {
303
+ return p;
304
+ }
305
+ }
306
+ //#endregion
203
307
  //#region src/server/dev.ts
204
308
  /** packageDir = the installed marver package root (dist/cli.js lives one level down). */
205
309
  function packageDir() {
206
310
  return join(dirname(fileURLToPath(import.meta.url)), "..");
207
311
  }
208
312
  const portFree = (p) => new Promise((res) => {
209
- const s = createServer$1();
313
+ const s = createServer();
210
314
  s.once("error", () => res(false));
211
315
  s.once("listening", () => s.close(() => res(true)));
212
316
  s.listen(p, "127.0.0.1");
@@ -346,7 +450,40 @@ function denyLocalSecrets(root) {
346
450
  }
347
451
  };
348
452
  }
453
+ /** A canvas already runs in this folder (or one is starting): the line says where, or what to do. */
454
+ var DevLockError = class extends Error {};
349
455
  async function dev(root, portFlag) {
456
+ const { takeDevLock } = await import("./dev-lock-DWSpa6nj.mjs").then((n) => n.n);
457
+ const lock = await takeDevLock(root);
458
+ if (!lock.ok) throw new DevLockError(lock.message);
459
+ const { removeDevInfo } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
460
+ const onExit = () => {
461
+ removeDevInfo(root, lock.instance);
462
+ lock.release();
463
+ };
464
+ const onSignal = (sig) => {
465
+ onExit();
466
+ process.kill(process.pid, sig);
467
+ };
468
+ process.once("exit", onExit);
469
+ process.once("SIGINT", onSignal);
470
+ process.once("SIGTERM", onSignal);
471
+ process.once("SIGHUP", onSignal);
472
+ const unhook = () => {
473
+ process.off("exit", onExit);
474
+ process.off("SIGINT", onSignal);
475
+ process.off("SIGTERM", onSignal);
476
+ process.off("SIGHUP", onSignal);
477
+ lock.release();
478
+ };
479
+ try {
480
+ return await boot(root, portFlag, lock.instance, unhook);
481
+ } catch (err) {
482
+ unhook();
483
+ throw err;
484
+ }
485
+ }
486
+ async function boot(root, portFlag, instance, unhook) {
350
487
  const config = await loadConfig(root);
351
488
  const host = detectHost(root);
352
489
  const pkgDir = packageDir();
@@ -357,6 +494,7 @@ async function dev(root, portFlag) {
357
494
  const esc = (p) => join(p, "design").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
358
495
  const designDir = new RegExp(`^(${[.../* @__PURE__ */ new Set([root, safeReal(root)])].map(esc).join("|")})[/\\\\]`);
359
496
  const plugins = [denyLocalSecrets(root), react({ exclude: [/\/node_modules\//, designDir] })];
497
+ if (config.jam?.loc !== false) plugins.unshift(locPlugin(root));
360
498
  if (host.tailwind === 4) {
361
499
  const tw = await tailwind4Plugin(root);
362
500
  if (tw) plugins.push(...tw);
@@ -380,7 +518,7 @@ async function dev(root, portFlag) {
380
518
  logger.warnOnce = (msg, opts) => {
381
519
  if (!noise(msg)) warnOnceBase(msg, opts);
382
520
  };
383
- const server = await createServer({
521
+ const server = await createServer$1({
384
522
  configFile: false,
385
523
  root,
386
524
  css,
@@ -457,12 +595,12 @@ async function dev(root, portFlag) {
457
595
  console.log(`\n ${NAME} · ${projectName} → http://localhost:${port}/\n`);
458
596
  setTimeout(async () => {
459
597
  try {
460
- await (await import("./shot-CckrGW-J.mjs")).sweepGhosts((m) => console.log(` ${m}`));
598
+ await (await import("./shot-DqcxJibP.mjs")).sweepGhosts((m) => console.log(` ${m}`));
461
599
  } catch {}
462
600
  }, 0);
463
601
  try {
464
602
  const { staleManagedInstructions } = await import("./managed-HwHVNI3h.mjs");
465
- const { installedVersion } = await import("./plugin-CTyhjwoJ.mjs").then((n) => n.i);
603
+ const { installedVersion } = await import("./plugin-CTD0rydA.mjs").then((n) => n.i);
466
604
  const stale = staleManagedInstructions(root);
467
605
  if (stale.length) {
468
606
  const shown = stale.slice(0, 4).join(", ") + (stale.length > 4 ? `, +${stale.length - 4} more` : "");
@@ -472,11 +610,11 @@ async function dev(root, portFlag) {
472
610
  } catch {}
473
611
  try {
474
612
  if (!existsSync(join(root, "context"))) {
475
- const n = (await import("./manifest-DnAte_fB.mjs").then((n) => n.i)).statusBoards(root).length;
613
+ const n = (await import("./manifest-Nl3KSVOk.mjs").then((n) => n.i)).statusBoards(root).length;
476
614
  if (n) console.log(` ${n} feature/project board${n === 1 ? "" : "s"}, no context/ - every status reads Backlog. To start it, tell your agent: "Set up our context."\n`);
477
615
  }
478
616
  } catch {}
479
- const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
617
+ const { loadCollab, syncOnce } = await import("./sync-DKk-yT1V.mjs").then((n) => n.o);
480
618
  if (loadCollab(root)) console.log(` comments: syncing with the published canvas\n`);
481
619
  let syncing = false;
482
620
  const tick = async () => {
@@ -491,7 +629,7 @@ async function dev(root, portFlag) {
491
629
  };
492
630
  tick();
493
631
  setInterval(tick, 3e4).unref();
494
- const { workActivity, writeDevInfo, removeDevInfo, boardsShowing, onBoardsChanged, nextActivitySeq } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
632
+ const { workActivity, writeDevInfo, removeDevInfo, boardsShowing, onBoardsChanged, nextActivitySeq } = await import("./work-F5u-twpJ.mjs").then((n) => n.o);
495
633
  let sent = "";
496
634
  const broadcast = (frames) => {
497
635
  const state = {
@@ -512,14 +650,15 @@ async function dev(root, portFlag) {
512
650
  });
513
651
  const sweep = setInterval(() => workActivity.sweep(), 15e3);
514
652
  sweep.unref?.();
515
- writeDevInfo(root, port);
653
+ writeDevInfo(root, port, instance);
516
654
  {
517
655
  const close = server.close.bind(server);
518
656
  server.close = (async () => {
519
657
  unsubscribe();
520
658
  offBoards();
521
659
  clearInterval(sweep);
522
- removeDevInfo(root);
660
+ removeDevInfo(root, instance);
661
+ unhook();
523
662
  return close();
524
663
  });
525
664
  }
@@ -546,8 +685,8 @@ async function dev(root, portFlag) {
546
685
  } catch {}
547
686
  }
548
687
  if (config.jam) {
549
- const { startJam } = await import("./daemon-Cl8KXGW4.mjs");
550
- const { checkAnchor } = await import("./anchor-check-BE5VVN6Q.mjs");
688
+ const { startJam } = await import("./daemon-DZo6o3rU.mjs");
689
+ const { checkAnchor } = await import("./anchor-check-Dg5xpNnU.mjs");
551
690
  const jam = startJam(root, config.jam, (m) => console.log(m), (board) => server.ws.send("sh:jam-comment", { board }), (frameId, target, others, look) => checkAnchor({
552
691
  root,
553
692
  viewports: config.viewports,
@@ -556,11 +695,43 @@ async function dev(root, portFlag) {
556
695
  target,
557
696
  others,
558
697
  ...look
559
- }));
698
+ }), (() => {
699
+ let due = null;
700
+ return () => {
701
+ due ??= setTimeout(async () => {
702
+ due = null;
703
+ const { jamLive } = await import("./live-Cgzsicwi.mjs");
704
+ server.ws.send("sh:jam-queue", jamLive.view?.() ?? { cards: [] });
705
+ }, 60);
706
+ };
707
+ })(), async (frameId, theme, entry, size) => {
708
+ const { shootFrame } = await import("./shot-DqcxJibP.mjs");
709
+ const r = await shootFrame({
710
+ root,
711
+ viewports: config.viewports,
712
+ frameId,
713
+ theme,
714
+ origin: `http://localhost:${port}`,
715
+ ...size ? { size } : {}
716
+ });
717
+ if (!r.ok) return null;
718
+ const { addPicture } = await import("./capture-CrqvU_jh.mjs").then((n) => n.i);
719
+ return addPicture(root, r.path, {
720
+ frame: frameId,
721
+ ...entry
722
+ });
723
+ });
560
724
  if (jam) {
725
+ const { createSpeech, speechLive } = await import("./audio-CmSRYFEs.mjs");
726
+ const { appendTalk } = await import("./session-qZWKt_VA.mjs").then((n) => n.s);
727
+ const speech = createSpeech({ onTalk: (t) => appendTalk(root, t.session, t.words) });
728
+ if (server.httpServer) speech.attach(server.httpServer);
729
+ speechLive.svc = speech;
561
730
  const close = server.close.bind(server);
562
731
  server.close = (async () => {
563
732
  jam.stop();
733
+ speech.stop();
734
+ speechLive.svc = void 0;
564
735
  return close();
565
736
  });
566
737
  }
@@ -568,4 +739,4 @@ async function dev(root, portFlag) {
568
739
  return server;
569
740
  }
570
741
  //#endregion
571
- export { dev };
742
+ export { DevLockError, dev };
@@ -0,0 +1,179 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { linkSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { randomBytes, randomUUID } from "node:crypto";
5
+ import { createServer } from "node:net";
6
+ //#region src/server/dev-lock.ts
7
+ /**
8
+ * One canvas per folder (#19, spec 27 Part 7). `marver dev` takes design/.local/dev.lock before it
9
+ * starts the server, so a second `marver dev` in the same folder says where the first one runs
10
+ * instead of taking over dev.json (which the CLI - `work`, `shot`, `comments new --on` - reads to
11
+ * find the canvas).
12
+ *
13
+ * The rules, none of which guess a holder dead from time or from an unanswered request:
14
+ * - no lock: create it exclusively. Done.
15
+ * - a lock whose pid runs: a canvas runs here (a slow or paused one too) - stop with its link.
16
+ * - a lock whose pid is dead: reclaim it while holding dev.lock.reclaim (also exclusive): read it
17
+ * again, still the same dead holder -> replace it. A reclaim lock already there means another
18
+ * start is reclaiming: wait a second and start over once; still there -> fail closed.
19
+ * - a 0.25 server writes no lock and no pid: dev.json without a lock is decided by binding its port.
20
+ *
21
+ * Both files are created by linking a fully written temp file into place, so a reader never sees
22
+ * an empty or half-written lock - `link` fails if the name exists, which is the exclusive create.
23
+ */
24
+ var dev_lock_exports = /* @__PURE__ */ __exportAll({
25
+ RECLAIM_STUCK: () => RECLAIM_STUCK,
26
+ createExclusive: () => createExclusive,
27
+ pidRuns: () => pidRuns,
28
+ portInUse: () => portInUse,
29
+ releaseDevLock: () => releaseDevLock,
30
+ takeDevLock: () => takeDevLock
31
+ });
32
+ const localDir = (root) => join(root, "design", ".local");
33
+ const lockPath = (root) => join(localDir(root), "dev.lock");
34
+ const reclaimPath = (root) => `${lockPath(root)}.reclaim`;
35
+ const infoPath = (root) => join(localDir(root), "dev.json");
36
+ /** Is this pid a running process? EPERM means it runs under another user - still running. A
37
+ * process paused with SIGSTOP runs too, as far as this is concerned. */
38
+ function pidRuns(pid) {
39
+ if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
40
+ try {
41
+ process.kill(pid, 0);
42
+ return true;
43
+ } catch (err) {
44
+ return err.code === "EPERM";
45
+ }
46
+ }
47
+ /** Create `file` holding `body`, failing with EEXIST if it is there - atomically, content included. */
48
+ function createExclusive(file, body) {
49
+ const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
50
+ writeFileSync(tmp, body, { mode: 384 });
51
+ try {
52
+ linkSync(tmp, file);
53
+ } finally {
54
+ try {
55
+ unlinkSync(tmp);
56
+ } catch {}
57
+ }
58
+ }
59
+ const readJson = (file) => {
60
+ try {
61
+ return JSON.parse(readFileSync(file, "utf8"));
62
+ } catch (err) {
63
+ return err.code === "ENOENT" ? void 0 : null;
64
+ }
65
+ };
66
+ const asHolder = (v) => {
67
+ const h = v;
68
+ return h && typeof h.pid === "number" && typeof h.instance === "string" ? {
69
+ pid: h.pid,
70
+ instance: h.instance,
71
+ at: Number(h.at) || 0
72
+ } : null;
73
+ };
74
+ /** Is anything listening on `port` on this machine? Vite binds ::1 for `localhost`, an older or
75
+ * configured one 127.0.0.1 - a port is in use if either refuses the bind. */
76
+ async function portInUse(port) {
77
+ const bind = (host) => new Promise((res) => {
78
+ const s = createServer();
79
+ s.once("error", (err) => res(err.code === "EADDRINUSE" || err.code === "EACCES"));
80
+ s.once("listening", () => s.close(() => res(false)));
81
+ s.listen(port, host);
82
+ });
83
+ return await bind("127.0.0.1") || await bind("::1");
84
+ }
85
+ const runsHere = (root) => {
86
+ const port = readJson(infoPath(root))?.port;
87
+ return typeof port === "number" ? `a canvas already runs here: http://localhost:${port} - open it, or stop it first` : "a canvas already runs here - open it, or stop it first";
88
+ };
89
+ const RECLAIM_STUCK = "a canvas is starting here, or a start crashed: delete design/.local/dev.lock.reclaim if no canvas runs";
90
+ /** Take the folder's canvas lock. On success the caller owns dev.lock until `release()` (which
91
+ * removes it only while it still names this instance). */
92
+ async function takeDevLock(root, opts = {}) {
93
+ mkdirSync(localDir(root), { recursive: true });
94
+ const me = {
95
+ pid: opts.pid ?? process.pid,
96
+ instance: randomUUID(),
97
+ at: Date.now()
98
+ };
99
+ const body = JSON.stringify(me);
100
+ const release = () => releaseDevLock(root, me.instance);
101
+ const won = async () => {
102
+ const info = readJson(infoPath(root));
103
+ if (info && info.instance !== me.instance) {
104
+ if (typeof info.pid === "number" ? pidRuns(info.pid) : typeof info.port === "number" ? await portInUse(info.port) : false) {
105
+ release();
106
+ return {
107
+ ok: false,
108
+ message: `${runsHere(root)}${typeof info.pid === "number" ? "" : " (or delete design/.local/dev.json if it is not)"}`
109
+ };
110
+ }
111
+ }
112
+ return {
113
+ ok: true,
114
+ instance: me.instance,
115
+ release
116
+ };
117
+ };
118
+ for (let round = 0; round < 2; round++) {
119
+ try {
120
+ createExclusive(lockPath(root), body);
121
+ return await won();
122
+ } catch (err) {
123
+ if (err.code !== "EEXIST") throw err;
124
+ }
125
+ const raw = readJson(lockPath(root));
126
+ if (raw === void 0) continue;
127
+ const holder = asHolder(raw);
128
+ if (!holder) return {
129
+ ok: false,
130
+ message: "design/.local/dev.lock is unreadable: delete it if no canvas runs"
131
+ };
132
+ if (pidRuns(holder.pid)) return {
133
+ ok: false,
134
+ message: runsHere(root)
135
+ };
136
+ try {
137
+ createExclusive(reclaimPath(root), body);
138
+ } catch (err) {
139
+ if (err.code !== "EEXIST") throw err;
140
+ if (round === 0) {
141
+ await new Promise((r) => setTimeout(r, opts.reclaimWaitMs ?? 1e3));
142
+ continue;
143
+ }
144
+ return {
145
+ ok: false,
146
+ message: RECLAIM_STUCK
147
+ };
148
+ }
149
+ try {
150
+ const again = asHolder(readJson(lockPath(root)));
151
+ if (again && again.pid === holder.pid && again.instance === holder.instance) {
152
+ unlinkSync(lockPath(root));
153
+ try {
154
+ createExclusive(lockPath(root), body);
155
+ return await won();
156
+ } catch (err) {
157
+ if (err.code !== "EEXIST") throw err;
158
+ }
159
+ }
160
+ } finally {
161
+ try {
162
+ unlinkSync(reclaimPath(root));
163
+ } catch {}
164
+ }
165
+ }
166
+ const last = asHolder(readJson(lockPath(root)));
167
+ return {
168
+ ok: false,
169
+ message: last && pidRuns(last.pid) ? runsHere(root) : RECLAIM_STUCK
170
+ };
171
+ }
172
+ /** Remove dev.lock if it still names `instance` - a lock some other start took over stays. */
173
+ function releaseDevLock(root, instance) {
174
+ try {
175
+ if (asHolder(readJson(lockPath(root)))?.instance === instance) unlinkSync(lockPath(root));
176
+ } catch {}
177
+ }
178
+ //#endregion
179
+ export { dev_lock_exports as n, pidRuns as r, createExclusive as t };
@@ -33,7 +33,11 @@ function replay(events) {
33
33
  mentions: ev.mentions,
34
34
  asks: ev.asks,
35
35
  replies: [],
36
- reactions: {}
36
+ reactions: {},
37
+ ...ev.capture ? {
38
+ capture: ev.capture,
39
+ ...ev.facts ? { facts: ev.facts } : {}
40
+ } : {}
37
41
  });
38
42
  }
39
43
  for (const ev of ordered) switch (ev.type) {
@@ -48,16 +52,18 @@ function replay(events) {
48
52
  agent: ev.agent,
49
53
  agentMeta: ev.agentMeta,
50
54
  mentions: ev.mentions,
51
- asks: ev.asks
55
+ asks: ev.asks,
56
+ ...ev.alsoChanged?.length ? { alsoChanged: ev.alsoChanged } : {}
52
57
  });
53
58
  break;
54
59
  }
55
60
  case "edit": {
56
- if (!ev.commentId || ev.body === void 0 && ev.asks === void 0) break;
61
+ if (!ev.commentId || ev.body === void 0 && ev.asks === void 0 && ev.alsoChanged === void 0) break;
57
62
  const m = threads.get(ev.commentId) ?? [...threads.values()].flatMap((th) => th.replies).find((r) => r.id === ev.commentId);
58
63
  if (!m) break;
59
64
  if (ev.body !== void 0) m.body = ev.body;
60
65
  if (ev.asks !== void 0) m.asks = ev.asks;
66
+ if (ev.alsoChanged !== void 0 && !("replies" in m)) m.alsoChanged = ev.alsoChanged;
61
67
  break;
62
68
  }
63
69
  case "resolve": {
@@ -78,7 +84,11 @@ function replay(events) {
78
84
  }
79
85
  case "reanchor": {
80
86
  const t = ev.commentId ? threads.get(ev.commentId) : void 0;
81
- if (t && ev.anchor != null) t.anchor = ev.anchor;
87
+ if (t && typeof ev.frame === "string" && ev.frame) {
88
+ t.frame = ev.frame;
89
+ t.nodeKey = ev.nodeKey;
90
+ t.anchor = ev.anchor ?? void 0;
91
+ } else if (t && ev.anchor != null) t.anchor = ev.anchor;
82
92
  break;
83
93
  }
84
94
  case "react": {
@@ -1,11 +1,11 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
2
  import { n as addFolders, s as listBoardFiles } from "./boards-CGg6piKF.mjs";
3
3
  import { S as KIND_FOLDERS, b as FOLDER_MODULES } from "./board-tree-DRioF94d.mjs";
4
- import { s as scanFrames, u as writeManifest } from "./manifest-DnAte_fB.mjs";
4
+ import { s as scanFrames, u as writeManifest } from "./manifest-Nl3KSVOk.mjs";
5
5
  import { r as detectAgent } from "./agent-BsieQGTD.mjs";
6
6
  import { MANAGED_PREFIX, enumerateInstructionTemplates, hashBody, pkgDir } from "./managed-HwHVNI3h.mjs";
7
7
  import { t as writeManaged } from "./managed-write-Bo-oPc-i.mjs";
8
- import { i as readJson, r as detectHost, t as DEFAULTS } from "./config-cKgZBRj0.mjs";
8
+ import { i as readJson, r as detectHost, t as DEFAULTS } from "./config-Cf7EjAMf.mjs";
9
9
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
10
10
  import { basename, dirname, join, relative } from "node:path";
11
11
  //#region src/cli/init.ts
@@ -1,3 +1,4 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
1
2
  import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, writeSync } from "node:fs";
2
3
  import { dirname, join } from "node:path";
3
4
  import { createHash } from "node:crypto";
@@ -58,6 +59,11 @@ function deviceId() {
58
59
  * design/.local/ and hand a clone a ledger full of pre-authorized ids. Lines stamped with
59
60
  * another machine match nothing here (device.ts).
60
61
  */
62
+ var ledger_exports = /* @__PURE__ */ __exportAll({
63
+ has: () => has,
64
+ owned: () => owned,
65
+ record: () => record
66
+ });
61
67
  const ledgerFile = (root) => join(root, "design", ".local", "jam-ledger");
62
68
  const line = (board, id) => `${deviceId()}\t${board}\t${id}`;
63
69
  /** Was this (board, id) authorized on this device by the gated dev POST? */
@@ -83,5 +89,15 @@ function record(root, board, id) {
83
89
  closeSync(fd);
84
90
  }
85
91
  }
92
+ /** Every (board, id) this device authorized, as `board\tid` - one read for a whole ingest, so
93
+ * an event that is not ledgered (yet, or ever) costs a set lookup each time it is looked at. */
94
+ function owned(root) {
95
+ const out = /* @__PURE__ */ new Set();
96
+ const file = ledgerFile(root);
97
+ if (!existsSync(file)) return out;
98
+ const mine = deviceId() + " ";
99
+ for (const l of readFileSync(file, "utf8").split("\n")) if (l.startsWith(mine)) out.add(l.slice(mine.length));
100
+ return out;
101
+ }
86
102
  //#endregion
87
- export { has, record, deviceId as t };
103
+ export { deviceId as a, record as i, ledger_exports as n, owned as r, has as t };
@@ -1,8 +1,8 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
2
  import { d as readMembership, i as checkBoardsDir, p as unplacedHint, s as listBoardFiles } from "./boards-CGg6piKF.mjs";
3
3
  import { f as isBoardName } from "./board-tree-DRioF94d.mjs";
4
- import { s as scanFrames } from "./manifest-DnAte_fB.mjs";
5
- import { i as readDevInfo } from "./work-GE88wb_3.mjs";
4
+ import { s as scanFrames } from "./manifest-Nl3KSVOk.mjs";
5
+ import { i as readDevInfo } from "./work-F5u-twpJ.mjs";
6
6
  import { join } from "node:path";
7
7
  //#region src/cli/link.ts
8
8
  /**
@@ -0,0 +1,4 @@
1
+ //#region src/server/jam/live.ts
2
+ const jamLive = {};
3
+ //#endregion
4
+ export { jamLive };
@@ -1,4 +1,4 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { i as PKG, n as CONTENT_WIDTH } from "./cli.mjs";
3
3
  import { a as checkRealDirs, f as readRegistry, h as hash, i as checkBoardsDir, r as boardFields, s as listBoardFiles } from "./boards-CGg6piKF.mjs";
4
4
  import { D as readStatusWord, E as readReason, T as readCapability, a as buildTree, f as isBoardName, h as readTitle, k as resolveType, m as readDescription, o as flatten, s as folderEntries, x as HAS_STATUS, y as DECISIONS } from "./board-tree-DRioF94d.mjs";
@@ -1,7 +1,7 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { a as checkRealDirs, h as hash, i as checkBoardsDir, s as listBoardFiles } from "./boards-CGg6piKF.mjs";
3
3
  import { l as framesOn } from "./board-tree-DRioF94d.mjs";
4
- import { a as noteFileFor } from "./manifest-DnAte_fB.mjs";
4
+ import { a as noteFileFor } from "./manifest-Nl3KSVOk.mjs";
5
5
  import { t as imports } from "./imports-WBSnnHLb.mjs";
6
6
  import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
7
7
  import { dirname, join, relative, sep } from "node:path";
@@ -1,7 +1,8 @@
1
- import { s as scanFrames } from "./manifest-DnAte_fB.mjs";
2
- import { r as replay, t as asks } from "./events-DnK_AnrW.mjs";
3
- import { a as readLog, i as listBoards } from "./comments-Zoch254k.mjs";
4
- import { o as projectMarks } from "./marks-koRsbHfe.mjs";
1
+ import { s as scanFrames } from "./manifest-Nl3KSVOk.mjs";
2
+ import { r as replay, t as asks } from "./events-CLH4ijKP.mjs";
3
+ import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
4
+ import { o as projectMarks } from "./marks-CKgzucHZ.mjs";
5
+ import { answers } from "./queue-BuiCKSX1.mjs";
5
6
  import { join } from "node:path";
6
7
  //#region src/shared/marks.ts
7
8
  const isNew = (m, id) => !!m && (m.changed[id] ?? 0) > (m.seen[id] ?? 0);
@@ -10,7 +11,9 @@ const isNew = (m, id) => !!m && (m.changed[id] ?? 0) > (m.seen[id] ?? 0);
10
11
  /**
11
12
  * `marver marks` (spec 26): what the human has not reviewed yet - the frames waiting on them (a
12
13
  * Marver thread whose last word is Marver's, the ones that ask first) and the frames new since they
13
- * looked. A read-only view of design/.local, a fresh scan of the frames and the comment logs:
14
+ * looked. Since 0.26 (spec 27) only a tag starts work, so it also lists what the human ANSWERED that
15
+ * nothing has acted on yet ("answered by you") - the coding agent's to-do for "go through my
16
+ * replies"; answers a 0.25 journal took in are apart, under "earlier, maybe handled". A read-only view of design/.local, a fresh scan of the frames and the comment logs:
14
17
  * running it writes nothing, so it never starts the clock, and it works with dev off.
15
18
  */
16
19
  function marksCommand(root, opts) {
@@ -30,10 +33,19 @@ function marksCommand(root, opts) {
30
33
  }];
31
34
  })).sort((a, b) => Number(b.asks) - Number(a.asks));
32
35
  const fresh = m ? manifest.frames.map((f) => f.id).filter((id) => isNew(m, id)) : [];
36
+ const { answered, earlier } = answers(root);
37
+ const said = (a) => ({
38
+ frame: a.frame,
39
+ thread: a.thread,
40
+ board: a.board,
41
+ body: a.body
42
+ });
33
43
  if (opts.json) {
34
44
  console.log(JSON.stringify({
35
45
  started: !!m,
36
46
  waiting,
47
+ answered: answered.map(said),
48
+ earlier: earlier.map(said),
37
49
  new: fresh
38
50
  }, null, 2));
39
51
  return;
@@ -43,6 +55,12 @@ function marksCommand(root, opts) {
43
55
  const w = Math.max(0, ...waiting.map((x) => x.frame.length)) + 2;
44
56
  if (waiting.length) waiting.forEach((x, i) => console.log(`${pad(i ? "" : `waiting on you (${waiting.length})`, 21)}${pad(x.frame, w)}${pad(x.asks ? "asks" : "", 6)}"${x.body.length > 60 ? x.body.slice(0, 57) + "..." : x.body}"`));
45
57
  else console.log(`${pad("waiting on you", 21)}nothing`);
58
+ const quote = (b) => `"${b.length > 60 ? b.slice(0, 57) + "..." : b}"`;
59
+ const aw = Math.max(0, ...answered.map((x) => (x.frame ?? x.board).length)) + 2;
60
+ if (answered.length) answered.forEach((x, i) => console.log(`${pad(i ? "" : `answered by you (${answered.length})`, 21)}${pad(x.frame ?? x.board, aw)}${pad(x.thread, 10)}${quote(x.body)}`));
61
+ else console.log(`${pad("answered by you", 21)}nothing`);
62
+ if (earlier.length && opts.all) earlier.forEach((x, i) => console.log(`${pad(i ? "" : `earlier, maybe handled (${earlier.length})`, 21)}${pad(x.frame ?? x.board, aw)}${pad(x.thread, 10)}${quote(x.body)}`));
63
+ else if (earlier.length) console.log(`${pad("earlier, maybe handled", 21)}${earlier.length} from before 0.26 - \`--all\` lists them`);
46
64
  const shown = fresh.slice(0, 6).join(", ") + (fresh.length > 6 ? `, ... (+${fresh.length - 6})` : "");
47
65
  console.log(`${pad(fresh.length ? `new (${fresh.length})` : "new", 21)}${fresh.length ? shown : "nothing"}`);
48
66
  }