@marver-design/marver 0.22.1 → 0.23.1

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 (65) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +14 -10
  3. package/dist/agent-BsieQGTD.mjs +99 -0
  4. package/dist/{bake-CvY8QR3L.mjs → bake-DQtnDB8-.mjs} +1 -1
  5. package/dist/{board-status-CWGHIdo_.mjs → board-status-BZSzc9Hp.mjs} +69 -610
  6. package/dist/boards-BRLnoTC3.mjs +620 -0
  7. package/dist/{boards-BwKI0qWd.mjs → boards-Dv-Ipd8G.mjs} +13 -5
  8. package/dist/{build-B1kavcpc.mjs → build-_ndp_dXn.mjs} +18 -10
  9. package/dist/cli.mjs +20 -11
  10. package/dist/{comments-ClVgfQib.mjs → comments-BlqyZh3D.mjs} +71 -9
  11. package/dist/{config-DJxMRVD8.mjs → config-BUKprFAp.mjs} +5 -97
  12. package/dist/{context-D4t59wDi.mjs → context-CdkNiKdJ.mjs} +3 -2
  13. package/dist/{daemon-PmNqoOAk.mjs → daemon-BvMPdQ3k.mjs} +78 -19
  14. package/dist/{dev-Cf4wLGe2.mjs → dev-Cf-4eqaC.mjs} +50 -10
  15. package/dist/{init-C_K-cjBQ.mjs → init-hfZV7TwY.mjs} +10 -4
  16. package/dist/{ledger-Bu0BjqIe.mjs → ledger-BNXW14Xw.mjs} +1 -6
  17. package/dist/link-BodAbIQz.mjs +132 -0
  18. package/dist/{manifest-CcdWx7ud.mjs → manifest-TpfDWldB.mjs} +56 -6
  19. package/dist/{plugin-C5u07Yhv.mjs → plugin-DoXql0ZZ.mjs} +400 -48
  20. package/dist/{poster-BduzQBYz.mjs → poster-XBmUvQiL.mjs} +1 -1
  21. package/dist/{profile-BjAPAJSb.mjs → profile-CrZohD6g.mjs} +1 -1
  22. package/dist/{publish-bakes-b0jUwvM_.mjs → publish-bakes-KKTHWqq3.mjs} +2 -2
  23. package/dist/{share--bdSc4G5.mjs → share-BD-wcDQq.mjs} +1 -1
  24. package/dist/{shot-BAR8hmU9.mjs → shot-DOD8v6fJ.mjs} +2 -2
  25. package/dist/{shot-BFEuYbaz.mjs → shot-Dh6fV1Lm.mjs} +1 -1
  26. package/dist/{sync-BZaCWqK-.mjs → sync-DoA1vf4u.mjs} +15 -1
  27. package/dist/{work-0YopuMt9.mjs → work-ClFFq0Qh.mjs} +9 -3
  28. package/dist/{work-CLrmY-vQ.mjs → work-ayuL_9Kk.mjs} +72 -1
  29. package/docs/boards-and-folders.md +60 -7
  30. package/docs/context.md +10 -2
  31. package/docs/live-jam.md +11 -0
  32. package/docs/sticky-notes.md +1 -1
  33. package/package.json +1 -1
  34. package/src/client/content/diagram.tsx +7 -1
  35. package/src/client/content/img-lod.ts +12 -2
  36. package/src/client/content/index.tsx +73 -6
  37. package/src/client/content/md.ts +3 -2
  38. package/src/client/frame-host/inspect.js +23 -0
  39. package/src/client/shell/App.tsx +21 -10
  40. package/src/client/shell/BoardList.tsx +26 -6
  41. package/src/client/shell/LockedApp.tsx +2 -2
  42. package/src/client/shell/Play.tsx +5 -1
  43. package/src/client/shell/StatusPicker.tsx +12 -5
  44. package/src/client/shell/Tip.tsx +25 -5
  45. package/src/client/shell/board-icons.tsx +15 -1
  46. package/src/client/shell/canvas/Canvas.tsx +42 -6
  47. package/src/client/shell/canvas/anchor.ts +41 -0
  48. package/src/client/shell/canvas/ctl.ts +6 -0
  49. package/src/client/shell/comments-store.ts +8 -5
  50. package/src/client/shell/goto.ts +52 -3
  51. package/src/client/shell/hash.ts +24 -3
  52. package/src/client/shell/store.ts +261 -36
  53. package/src/client/shell/styles.css +20 -2
  54. package/src/client/shell/tidy.ts +34 -3
  55. package/src/shared/board-types.ts +10 -6
  56. package/src/shared/frames.ts +3 -0
  57. package/src/shared/status.ts +17 -8
  58. package/templates/AGENTS-embedded.md +43 -8
  59. package/templates/AGENTS-studio.md +43 -8
  60. package/templates/instructions/boards.md +13 -3
  61. package/templates/instructions/context.md +6 -2
  62. package/templates/instructions/iterate.md +29 -16
  63. package/templates/instructions/jam.md +9 -2
  64. package/templates/instructions/reference/deck-layouts.md +2 -1
  65. package/templates/instructions/reference/deck-story.md +2 -1
@@ -1,9 +1,9 @@
1
1
  import { n as replay } from "./events-B3LBn74P.mjs";
2
2
  import { i as readLog, r as listBoards, t as appendEvents } from "./comments-DZyobpxG.mjs";
3
- import { n as localProfile } from "./profile-BjAPAJSb.mjs";
4
- import { o as toFrameId } from "./manifest-CcdWx7ud.mjs";
5
- import { workActivity } from "./work-CLrmY-vQ.mjs";
6
- import { r as deviceId, t as has } from "./ledger-Bu0BjqIe.mjs";
3
+ import { n as localProfile } from "./profile-CrZohD6g.mjs";
4
+ import { c as toFrameId } from "./manifest-TpfDWldB.mjs";
5
+ import { a as workActivity } from "./work-ayuL_9Kk.mjs";
6
+ import { has, t as deviceId } from "./ledger-BNXW14Xw.mjs";
7
7
  import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, watch, writeFileSync, writeSync } from "node:fs";
8
8
  import { join } from "node:path";
9
9
  import { randomBytes, randomUUID } from "node:crypto";
@@ -865,11 +865,30 @@ function releaseLock(root) {
865
865
  * - the event id is in the device ledger (the trust boundary, §1) - synced-in events fail this
866
866
  */
867
867
  const MENTION = /@marver\b/i;
868
- /** Threads Marver is already ENGAGED in (it has replied there). An owner follow-up in one of
869
- * these is a conversation turn - it triggers without re-tagging @marver. */
870
- function engagedThreads(events) {
871
- const s = /* @__PURE__ */ new Set();
872
- for (const ev of events) if (ev.agent && ev.type === "reply" && ev.parentId) s.add(ev.parentId);
868
+ /** Threads Marver is already ENGAGED in, each with the moment it engaged. `owners` is the ledger
869
+ * check: only the owner's own mentions start a conversation (a synced collaborator's never does). An owner follow-up in an
870
+ * engaged thread written AFTER that moment is a conversation turn - it triggers without re-tagging;
871
+ * one written before it never wakes a job retroactively, whatever engages the thread later.
872
+ * - a chat agent's note or reply from the CLI engages from that event;
873
+ * - a Live Jam reply engages from the @marver mention that started the conversation, so an owner
874
+ * follow-up written while the job ran still counts. A jam reply with no mention in its thread
875
+ * answered a follow-up, which a CLI event already engaged - it adds nothing. */
876
+ function engagedThreads(events, owners) {
877
+ const s = /* @__PURE__ */ new Map();
878
+ const engage = (thread, at) => s.set(thread, Math.min(s.get(thread) ?? Infinity, at));
879
+ const mentioned = /* @__PURE__ */ new Map();
880
+ for (const ev of events) {
881
+ if (ev.agent || ev.type !== "create" && ev.type !== "reply" || !MENTION.test(ev.body ?? "") || !owners(ev.id)) continue;
882
+ const t = threadId(ev);
883
+ if (t) mentioned.set(t, Math.min(mentioned.get(t) ?? Infinity, ev.ts));
884
+ }
885
+ for (const ev of events) {
886
+ if (!ev.agent) continue;
887
+ if (ev.type === "create" && ev.commentId) engage(ev.commentId, ev.ts);
888
+ if (ev.type !== "reply" || !ev.parentId) continue;
889
+ if (!ev.id.startsWith("jam-")) engage(ev.parentId, ev.ts);
890
+ else if (mentioned.has(ev.parentId)) engage(ev.parentId, mentioned.get(ev.parentId));
891
+ }
873
892
  return s;
874
893
  }
875
894
  /** The one gate. An event on `board` triggers a job iff it passes every clause. Keyed on
@@ -879,7 +898,8 @@ function engagedThreads(events) {
879
898
  function triggers(root, board, ev, engaged) {
880
899
  if (ev.agent) return false;
881
900
  if (ev.type !== "create" && ev.type !== "reply") return false;
882
- const followUp = ev.type === "reply" && !!engaged?.has(threadId(ev));
901
+ const since = ev.type === "reply" ? engaged?.get(threadId(ev)) : void 0;
902
+ const followUp = since !== void 0 && ev.ts > since;
883
903
  if (!MENTION.test(ev.body ?? "") && !followUp) return false;
884
904
  return has(root, board, ev.id);
885
905
  }
@@ -888,12 +908,16 @@ function scanPending(root, commentsDir, journal) {
888
908
  const out = [];
889
909
  for (const board of listBoards(commentsDir)) {
890
910
  const events = readLog(commentsDir, board);
891
- const engaged = engagedThreads(events);
911
+ const engaged = engagedThreads(events, (id) => has(root, board, id));
912
+ const frameOf = /* @__PURE__ */ new Map();
913
+ for (const ev of events) if (ev.type === "create" && ev.commentId && ev.frame) frameOf.set(ev.commentId, ev.frame);
892
914
  for (const ev of events) {
893
915
  if (seen.has(ev.id) || !triggers(root, board, ev, engaged)) continue;
916
+ const frame = ev.frame ?? frameOf.get(threadId(ev));
894
917
  out.push({
895
918
  board,
896
- event: ev
919
+ event: ev,
920
+ ...frame ? { frame } : {}
897
921
  });
898
922
  }
899
923
  }
@@ -932,6 +956,8 @@ const JOB_TIMEOUT_MS = 6e5;
932
956
  const MAX_ATTEMPTS = 2;
933
957
  const MAX_OUT = 2e6;
934
958
  const RESCAN_MS = 5e3;
959
+ /** How often a chain held by a chat agent's `work start` looks again. */
960
+ const HOLD_RECHECK_MS = 2e3;
935
961
  /** Kill a whole process group (the child is detached, so pid === pgid). Best-effort. */
936
962
  const fenceGroup = (pid) => {
937
963
  try {
@@ -970,8 +996,9 @@ const sceneFrameMtimes = (root) => {
970
996
  return out;
971
997
  }
972
998
  for (const rel of entries) {
973
- const base = rel.split("/").pop() ?? rel;
974
- if (base.startsWith("_") || !FRAME_FILE.test(base)) continue;
999
+ const parts = rel.split(/[\\/]/);
1000
+ const base = parts[parts.length - 1];
1001
+ if (!FRAME_FILE.test(base) || base.startsWith("_") || parts.slice(1, -1).some((s) => s.startsWith("_"))) continue;
975
1002
  try {
976
1003
  out.set(toFrameId(`scenes/${rel}`), statSync(join(scenesDir, rel)).mtimeMs);
977
1004
  } catch {}
@@ -1141,7 +1168,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1141
1168
  * and `triggers` re-confirms ledger/agent/type/mention - the job can never drift to other content. */
1142
1169
  const resolveMember = (board, id) => {
1143
1170
  const events = readLog(commentsDir, board);
1144
- const engaged = engagedThreads(events);
1171
+ const engaged = engagedThreads(events, (id) => has(root, board, id));
1145
1172
  for (const ev of events) if (ev.id === id) return triggers(root, board, ev, engaged) ? {
1146
1173
  board,
1147
1174
  event: ev
@@ -1238,16 +1265,34 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1238
1265
  const rt = replay(readLog(commentsDir, p.board)).find((t) => t.id === threadId(p.event));
1239
1266
  return rt?.frame ? `f:${rt.frame}` : `t:${threadId(p.event) || p.event.id}`;
1240
1267
  };
1268
+ const heldKey = (key) => key.startsWith("f:") && !!hooks.held?.(key.slice(2));
1269
+ let recheck = null;
1270
+ const holdLater = () => {
1271
+ if (recheck || stopped) return;
1272
+ recheck = setTimeout(() => {
1273
+ recheck = null;
1274
+ pump();
1275
+ }, HOLD_RECHECK_MS);
1276
+ recheck.unref?.();
1277
+ };
1241
1278
  const pump = () => {
1242
1279
  if (stopped) return;
1243
1280
  for (const [key, q] of chains) {
1244
1281
  if (activeChains >= Math.max(1, cfg.concurrency)) break;
1245
1282
  if (q.running || !q.items.length) continue;
1283
+ if (heldKey(key)) {
1284
+ holdLater();
1285
+ continue;
1286
+ }
1246
1287
  q.running = true;
1247
1288
  activeChains += 1;
1248
1289
  (async () => {
1249
1290
  try {
1250
1291
  while (!stopped && q.items.length) {
1292
+ if (heldKey(key)) {
1293
+ holdLater();
1294
+ break;
1295
+ }
1251
1296
  const job = q.items.shift();
1252
1297
  try {
1253
1298
  await runBatch(job.b, job.p);
@@ -1288,11 +1333,12 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1288
1333
  * ONE shared waiter: overlapping ticks (the 5s rescan during a 10-min job) join the same
1289
1334
  * promise instead of each spinning its own poll loop. */
1290
1335
  let idleP = null;
1336
+ const quiet = () => activeChains === 0 && [...chains].every(([key, q]) => !q.items.length || heldKey(key));
1291
1337
  const idle = () => {
1292
- if (activeChains === 0 && chains.size === 0) return Promise.resolve();
1338
+ if (quiet()) return Promise.resolve();
1293
1339
  idleP ??= new Promise((res) => {
1294
1340
  const check = () => {
1295
- if (stopped || activeChains === 0 && chains.size === 0) {
1341
+ if (stopped || quiet()) {
1296
1342
  idleP = null;
1297
1343
  res();
1298
1344
  } else setTimeout(check, 50);
@@ -1302,6 +1348,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1302
1348
  return idleP;
1303
1349
  };
1304
1350
  let resumed = false;
1351
+ const waiting = /* @__PURE__ */ new Set();
1305
1352
  const tick = async () => {
1306
1353
  if (stopped) return;
1307
1354
  try {
@@ -1315,7 +1362,17 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1315
1362
  else finish(b);
1316
1363
  }
1317
1364
  }
1318
- for (const p of scanPending(root, commentsDir, journal)) enqueue(claim(p), p);
1365
+ for (const p of scanPending(root, commentsDir, journal)) {
1366
+ if (p.frame && hooks.held?.(p.frame)) {
1367
+ if (!waiting.has(p.event.id)) {
1368
+ waiting.add(p.event.id);
1369
+ log(` jam: waiting - ${p.frame} is being worked on in chat; the comment runs once it is done`);
1370
+ }
1371
+ continue;
1372
+ }
1373
+ waiting.delete(p.event.id);
1374
+ enqueue(claim(p), p);
1375
+ }
1319
1376
  } catch (err) {
1320
1377
  log(` jam: tick error - ${err.message}`);
1321
1378
  }
@@ -1325,6 +1382,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
1325
1382
  tick,
1326
1383
  stop() {
1327
1384
  stopped = true;
1385
+ if (recheck) clearTimeout(recheck);
1328
1386
  for (const c of activeChildren) fenceGroup(c.pid);
1329
1387
  },
1330
1388
  snapshot() {
@@ -1351,7 +1409,8 @@ function startJam(root, cfg, log = () => {}, onChanged = () => {}) {
1351
1409
  const activity = workActivity;
1352
1410
  const core = createJam(root, cfg, adapter, log, {
1353
1411
  work: (f, on) => on ? activity.mark(f ?? "", void 0, "jam") : activity.clear(f ?? "", "jam"),
1354
- changed: onChanged
1412
+ changed: onChanged,
1413
+ held: (f) => activity.has(f, "cli")
1355
1414
  });
1356
1415
  let stopped = false;
1357
1416
  let scheduled = null;
@@ -1,7 +1,7 @@
1
1
  import { i as PKG, r as NAME } from "./cli.mjs";
2
- import { i as detectHost, n as loadConfig } from "./config-DJxMRVD8.mjs";
3
- import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-C5u07Yhv.mjs";
4
- import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
2
+ import { n as loadConfig, r as detectHost } from "./config-BUKprFAp.mjs";
3
+ import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-DoXql0ZZ.mjs";
4
+ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch } from "node:fs";
5
5
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { createLogger, createServer, parseAst, searchForWorkspaceRoot } from "vite";
@@ -454,12 +454,12 @@ async function dev(root, portFlag) {
454
454
  console.log(`\n ${NAME} · ${projectName} → http://localhost:${port}/\n`);
455
455
  setTimeout(async () => {
456
456
  try {
457
- await (await import("./shot-BAR8hmU9.mjs")).sweepGhosts((m) => console.log(` ${m}`));
457
+ await (await import("./shot-DOD8v6fJ.mjs")).sweepGhosts((m) => console.log(` ${m}`));
458
458
  } catch {}
459
459
  }, 0);
460
460
  try {
461
461
  const { staleManagedInstructions } = await import("./managed-HwHVNI3h.mjs");
462
- const { installedVersion } = await import("./plugin-C5u07Yhv.mjs").then((n) => n.i);
462
+ const { installedVersion } = await import("./plugin-DoXql0ZZ.mjs").then((n) => n.i);
463
463
  const stale = staleManagedInstructions(root);
464
464
  if (stale.length) {
465
465
  const shown = stale.slice(0, 4).join(", ") + (stale.length > 4 ? `, +${stale.length - 4} more` : "");
@@ -469,11 +469,11 @@ async function dev(root, portFlag) {
469
469
  } catch {}
470
470
  try {
471
471
  if (!existsSync(join(root, "context"))) {
472
- const n = (await import("./manifest-CcdWx7ud.mjs").then((n) => n.r)).statusBoards(root).length;
472
+ const n = (await import("./manifest-TpfDWldB.mjs").then((n) => n.i)).statusBoards(root).length;
473
473
  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`);
474
474
  }
475
475
  } catch {}
476
- const { loadCollab, syncOnce } = await import("./sync-BZaCWqK-.mjs").then((n) => n.o);
476
+ const { loadCollab, syncOnce } = await import("./sync-DoA1vf4u.mjs").then((n) => n.o);
477
477
  if (loadCollab(root)) console.log(` comments: syncing with the published canvas\n`);
478
478
  let syncing = false;
479
479
  const tick = async () => {
@@ -488,8 +488,25 @@ async function dev(root, portFlag) {
488
488
  };
489
489
  tick();
490
490
  setInterval(tick, 3e4).unref();
491
- const { workActivity, writeDevInfo, removeDevInfo } = await import("./work-CLrmY-vQ.mjs");
492
- const unsubscribe = workActivity.onChange((frames) => server.ws.send("sh:jam-activity", { frames }));
491
+ const { workActivity, writeDevInfo, removeDevInfo, boardsShowing, onBoardsChanged, nextActivitySeq } = await import("./work-ayuL_9Kk.mjs").then((n) => n.o);
492
+ let sent = "";
493
+ const broadcast = (frames) => {
494
+ const state = {
495
+ frames: [...frames].sort(),
496
+ boards: boardsShowing(root, frames)
497
+ };
498
+ const key = JSON.stringify(state);
499
+ if (key === sent) return;
500
+ sent = key;
501
+ server.ws.send("sh:jam-activity", {
502
+ ...state,
503
+ seq: nextActivitySeq()
504
+ });
505
+ };
506
+ const unsubscribe = workActivity.onChange(broadcast);
507
+ const offBoards = onBoardsChanged((r) => {
508
+ if (r === root) broadcast(workActivity.active());
509
+ });
493
510
  const sweep = setInterval(() => workActivity.sweep(), 15e3);
494
511
  sweep.unref?.();
495
512
  writeDevInfo(root, port);
@@ -497,13 +514,36 @@ async function dev(root, portFlag) {
497
514
  const close = server.close.bind(server);
498
515
  server.close = (async () => {
499
516
  unsubscribe();
517
+ offBoards();
500
518
  clearInterval(sweep);
501
519
  removeDevInfo(root);
502
520
  return close();
503
521
  });
504
522
  }
523
+ {
524
+ const dir = join(root, "design", "comments");
525
+ const due = /* @__PURE__ */ new Map();
526
+ try {
527
+ mkdirSync(dir, { recursive: true });
528
+ const w = watch(dir, { persistent: false }, (_e, file) => {
529
+ const m = typeof file === "string" ? file.match(/^([a-z0-9][a-z0-9-]*)\.jsonl$/) : null;
530
+ if (!m) return;
531
+ clearTimeout(due.get(m[1]));
532
+ due.set(m[1], setTimeout(() => {
533
+ due.delete(m[1]);
534
+ server.ws.send("sh:jam-comment", { board: m[1] });
535
+ }, 120));
536
+ });
537
+ const close = server.close.bind(server);
538
+ server.close = (async () => {
539
+ w.close();
540
+ for (const t of due.values()) clearTimeout(t);
541
+ return close();
542
+ });
543
+ } catch {}
544
+ }
505
545
  if (config.jam) {
506
- const { startJam } = await import("./daemon-PmNqoOAk.mjs");
546
+ const { startJam } = await import("./daemon-BvMPdQ3k.mjs");
507
547
  const jam = startJam(root, config.jam, (m) => console.log(m), (board) => server.ws.send("sh:jam-comment", { board }));
508
548
  if (jam) {
509
549
  const close = server.close.bind(server);
@@ -1,9 +1,10 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { E as addFolders, J as FOLDER_MODULES, X as KIND_FOLDERS } from "./board-status-CWGHIdo_.mjs";
2
+ import { E as FOLDER_MODULES, O as KIND_FOLDERS, n as addFolders } from "./boards-BRLnoTC3.mjs";
3
+ import { r as detectAgent } from "./agent-BsieQGTD.mjs";
3
4
  import { MANAGED_PREFIX, enumerateInstructionTemplates, hashBody, pkgDir } from "./managed-HwHVNI3h.mjs";
4
5
  import { t as writeManaged } from "./managed-write-Bo-oPc-i.mjs";
5
- import { i as scanFrames, s as writeManifest } from "./manifest-CcdWx7ud.mjs";
6
- import { a as readJson, i as detectHost, r as detectAgent, t as DEFAULTS } from "./config-DJxMRVD8.mjs";
6
+ import { l as writeManifest, o as scanFrames } from "./manifest-TpfDWldB.mjs";
7
+ import { i as readJson, r as detectHost, t as DEFAULTS } from "./config-BUKprFAp.mjs";
7
8
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
8
9
  import { basename, dirname, join, relative } from "node:path";
9
10
  //#region src/cli/init.ts
@@ -217,7 +218,12 @@ function init(root, opts) {
217
218
  created.push("design/scenes/demo/ (3 frames)");
218
219
  }
219
220
  if (host.tsconfigSweepsDesign) patchTsconfigExclude(root);
220
- writeManifest(root, scanFrames(root, { name: basename(root) }));
221
+ const prev = readJson(join(design, "manifest.json"))?.project;
222
+ const str = (v) => typeof v === "string" && v ? v : void 0;
223
+ writeManifest(root, scanFrames(root, {
224
+ name: str(prev?.name) ?? basename(root),
225
+ description: str(prev?.description)
226
+ }));
221
227
  console.log(`\n${NAME} initialized (${opts.mode} mode). Created:`);
222
228
  for (const f of created) console.log(` + ${f}`);
223
229
  if (host.router === "next") console.log(`\n note: Next.js support is partial - frames render outside Next, so next/font, next/image and Server Components do not exist inside them (details in design/AGENTS.md).`);
@@ -1,4 +1,3 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
1
  import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, writeSync } from "node:fs";
3
2
  import { dirname, join } from "node:path";
4
3
  import { createHash } from "node:crypto";
@@ -59,10 +58,6 @@ function deviceId() {
59
58
  * design/.local/ and hand a clone a ledger full of pre-authorized ids. Lines stamped with
60
59
  * another machine match nothing here (device.ts).
61
60
  */
62
- var ledger_exports = /* @__PURE__ */ __exportAll({
63
- has: () => has,
64
- record: () => record
65
- });
66
61
  const ledgerFile = (root) => join(root, "design", ".local", "jam-ledger");
67
62
  const line = (board, id) => `${deviceId()}\t${board}\t${id}`;
68
63
  /** Was this (board, id) authorized on this device by the gated dev POST? */
@@ -89,4 +84,4 @@ function record(root, board, id) {
89
84
  }
90
85
  }
91
86
  //#endregion
92
- export { ledger_exports as n, deviceId as r, has as t };
87
+ export { has, record, deviceId as t };
@@ -0,0 +1,132 @@
1
+ import { r as NAME } from "./cli.mjs";
2
+ import { F as resolveType, _ as folderMap, h as flatten, i as checkBoardsDir, m as buildTree, r as boardFields, s as listBoardFiles, u as readRegistry, y as isBoardName } from "./boards-BRLnoTC3.mjs";
3
+ import { o as scanFrames } from "./manifest-TpfDWldB.mjs";
4
+ import { i as readDevInfo } from "./work-ayuL_9Kk.mjs";
5
+ import { join } from "node:path";
6
+ //#region src/cli/link.ts
7
+ /**
8
+ * `marver link <scene/frame | scene ...>` - the canvas link that lands ON the work: the board the
9
+ * frames sit on, opened in canvas mode with them selected and the camera fitted (never past 100%) -
10
+ * not the full-screen focus view. An agent knows frame ids and scene names; it does not know the
11
+ * shell's node keys or which port `marver dev` took, so it asks here and pastes what comes back.
12
+ * `work done` prints the same link for the frames it clears; `comments new` prints its thread's.
13
+ *
14
+ * The board: `--board` when given; else the first board in sidebar order that shows EVERY frame
15
+ * asked for (archive boards last - history is not where a change is reviewed); else `all-scenes`,
16
+ * which holds every frame.
17
+ */
18
+ function resolveLink(root, targets, board) {
19
+ if (!targets.length) throw new Error("name what to link: link <scene/frame | scene ...>");
20
+ const known = scanFrames(root).frames.map((f) => f.id);
21
+ const ids = new Set(known);
22
+ const frames = [], scenes = [], all = [], exact = [];
23
+ for (const raw of targets) {
24
+ const t = raw.replace(/^design\/scenes\//, "").replace(/\.(tsx|jsx|html)$/, "").replace(/\/+$/, "");
25
+ if (ids.has(t)) {
26
+ if (!frames.includes(t)) frames.push(t);
27
+ if (!all.includes(t)) all.push(t);
28
+ if (!exact.includes(t)) exact.push(t);
29
+ continue;
30
+ }
31
+ const members = known.filter((id) => id.startsWith(`${t}/`));
32
+ if (members.length) {
33
+ if (t.includes("/")) for (const m of members) {
34
+ if (!frames.includes(m)) frames.push(m);
35
+ if (!all.includes(m)) all.push(m);
36
+ }
37
+ else {
38
+ if (!scenes.includes(t)) scenes.push(t);
39
+ for (const m of members) if (!all.includes(m)) all.push(m);
40
+ }
41
+ continue;
42
+ }
43
+ throw new Error(`no frame or scene "${raw}" in design/scenes/ - a frame is <scene>/<name>, a scene is its folder`);
44
+ }
45
+ const dir = join(root, "design", "boards");
46
+ const files = checkBoardsDir(root, dir) ? [] : listBoardFiles(dir).boards;
47
+ const nodesOf = (name) => {
48
+ const json = files.find((b) => b.name === name)?.json;
49
+ return Array.isArray(json?.nodes) ? json.nodes.filter((n) => !!n && typeof n.frame === "string") : [];
50
+ };
51
+ const shows = (name) => {
52
+ const pins = new Set(nodesOf(name).map((n) => n.frame));
53
+ return all.every((f) => pins.has(f));
54
+ };
55
+ let pick = board;
56
+ let fellBack = false;
57
+ if (pick) {
58
+ if (!isBoardName(pick)) throw new Error(`"${pick}" is not a board name`);
59
+ if (pick !== "all-scenes" && !files.some((b) => b.name === pick)) throw new Error(`no board "${pick}" in design/boards/`);
60
+ if (pick !== "all-scenes" && !shows(pick)) {
61
+ const missing = all.filter((f) => !nodesOf(pick).some((n) => n.frame === f));
62
+ throw new Error(`board "${pick}" does not show ${missing.join(", ")} - pin ${missing.length === 1 ? "it" : "them"} there first, or leave --board out`);
63
+ }
64
+ } else {
65
+ const reg = readRegistry(dir);
66
+ const folders = reg.state === "ok" ? reg.folders : [];
67
+ const rows = files.filter((b) => b.name !== "all-scenes").map((b) => ({
68
+ name: b.name,
69
+ ...boardFields(b.json, isBoardName)
70
+ }));
71
+ const tree = buildTree(rows, folders);
72
+ const order = flatten(tree);
73
+ const fm = folderMap(tree);
74
+ const byName = new Map(folders.map((f) => [f.name, f]));
75
+ const typeOf = (n) => {
76
+ const folder = byName.get(fm.get(n) ?? "");
77
+ return resolveType(rows.find((r) => r.name === n)?.type, folder?.type, folder?.parent ? byName.get(folder.parent)?.type : void 0);
78
+ };
79
+ const isArchive = (n) => n === "archive" || typeOf(n) === "archive";
80
+ pick = [...order.filter((n) => !isArchive(n)), ...order.filter(isArchive)].find(shows);
81
+ if (!pick) {
82
+ pick = "all-scenes";
83
+ fellBack = true;
84
+ }
85
+ }
86
+ const q = [frames.length ? `f=${frames.join(",")}` : "", scenes.length ? `s=${scenes.join(",")}` : ""].filter(Boolean).join("&");
87
+ return {
88
+ board: pick,
89
+ frames,
90
+ exact,
91
+ scenes,
92
+ all,
93
+ hash: `#/b/${pick}?${q}`,
94
+ ...fellBack ? { fellBack } : {},
95
+ nodesOf
96
+ };
97
+ }
98
+ /** The dev server's origin when it is running in this repo and answers like `marver dev` - else null. */
99
+ async function devOrigin(root) {
100
+ const info = readDevInfo(root);
101
+ if (!info) return null;
102
+ try {
103
+ const res = await fetch(`http://localhost:${info.port}/__mv/api/work`, {
104
+ headers: { "x-mv-work": info.token },
105
+ signal: AbortSignal.timeout(1500)
106
+ });
107
+ const data = await res.json().catch(() => null);
108
+ return res.ok && Array.isArray(data?.frames) ? `http://localhost:${info.port}/` : null;
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ const NOT_RUNNING = `\`${NAME} dev\` is not running in this repo - start it (\`npx ${NAME} dev\`), then run this again: the link carries its port`;
114
+ async function linkCommand(root, targets, opts) {
115
+ const r = resolveLink(root, targets, opts.board);
116
+ const origin = await devOrigin(root);
117
+ if (!origin) throw new Error(NOT_RUNNING);
118
+ if (r.fellBack) console.error(` (no curated board shows ${r.all.length === 1 ? "it" : "all of them"} - the link opens on all-scenes; pin ${r.all.length === 1 ? "it" : "them"} on a board for a tighter view)`);
119
+ console.log(`${origin}${r.hash}`);
120
+ }
121
+ /** The link line other commands print after their own output - never fails them. */
122
+ async function linkLine(root, targets) {
123
+ try {
124
+ const r = resolveLink(root, targets);
125
+ const origin = await devOrigin(root);
126
+ return origin ? `${origin}${r.hash}` : null;
127
+ } catch {
128
+ return null;
129
+ }
130
+ }
131
+ //#endregion
132
+ export { devOrigin, linkCommand, linkLine, resolveLink };
@@ -1,6 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { i as PKG, n as CONTENT_WIDTH } from "./cli.mjs";
3
- import { D as boardFields, H as isBoardName, L as buildTree, N as readRegistry, O as checkBoardsDir, R as flatten, U as readDescription, W as readTitle, at as hash, j as listBoardFiles, k as checkRealDirs, t as annotateBoards, z as folderEntries } from "./board-status-CWGHIdo_.mjs";
3
+ import { L as hash, a as checkRealDirs, b as readDescription, g as folderEntries, h as flatten, i as checkBoardsDir, m as buildTree, r as boardFields, s as listBoardFiles, u as readRegistry, x as readTitle, y as isBoardName } from "./boards-BRLnoTC3.mjs";
4
+ import { t as annotateBoards } from "./board-status-BZSzc9Hp.mjs";
4
5
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
5
6
  import { join, relative, sep } from "node:path";
6
7
  import { randomBytes } from "node:crypto";
@@ -11,16 +12,20 @@ var manifest_exports = /* @__PURE__ */ __exportAll({
11
12
  codeOnly: () => codeOnly,
12
13
  contentScan: () => contentScan,
13
14
  contentWidthOf: () => contentWidthOf,
15
+ docTags: () => docTags,
14
16
  extractMeta: () => extractMeta,
15
17
  frontMatter: () => frontMatter,
16
18
  isNoteFile: () => isNoteFile,
19
+ layoutDocSource: () => layoutDocSource,
17
20
  noteFileFor: () => noteFileFor,
18
21
  readNote: () => readNote,
22
+ rendersDoc: () => rendersDoc,
19
23
  scanFrames: () => scanFrames,
20
24
  sceneBrief: () => sceneBrief,
21
25
  sceneNote: () => sceneNote,
22
26
  setSceneTitle: () => setSceneTitle,
23
27
  statusBoards: () => statusBoards,
28
+ tagPattern: () => tagPattern,
24
29
  toFrameId: () => toFrameId,
25
30
  writeManifest: () => writeManifest
26
31
  });
@@ -84,8 +89,46 @@ function extractMeta(src) {
84
89
  * <Chart> is still a screen (device height, no document measuring), never a spec. Returns
85
90
  * the inferred intent + natural width, or null for UI frames. */
86
91
  const CONTENT_IMPORT = new RegExp(`from\\s+['"]${PKG}/content['"]`);
87
- const WIDE_DOC = /<Doc\b[^>]*\blayout\s*=\s*["']wide["']/;
88
- const contentWidthOf = (src) => WIDE_DOC.test(src) ? CONTENT_WIDTH.wide : CONTENT_WIDTH.document;
92
+ /** The JSX names a Doc renders under in this source: `Doc`, an alias (`import { Doc as Page }`),
93
+ * a namespace's member (`import * as C` -> `C.Doc`). Read from the code only (codeOnly). */
94
+ function docTags(code) {
95
+ const tags = ["Doc"];
96
+ for (const m of code.matchAll(/\bDoc\s+as\s+([A-Za-z_$][\w$]*)/g)) tags.push(m[1]);
97
+ for (const m of code.matchAll(/import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from/g)) tags.push(`${m[1]}.Doc`);
98
+ return tags;
99
+ }
100
+ const tagPattern = (tag) => tag.replace(/[.$]/g, "\\$&");
101
+ /** Does this source render a `<Doc>` - the one primitive that measures (content/index.tsx)? Lexical
102
+ * on the code (comments and strings blanked), through an aliased or namespace import too. */
103
+ function rendersDoc(src) {
104
+ const code = codeOnly(src);
105
+ return docTags(code).some((t) => new RegExp(`<${tagPattern(t)}[\\s>/]`).test(code));
106
+ }
107
+ /** The source of the nearest `_layout.tsx|jsx` around a frame that renders a Doc - the frame host
108
+ * wraps a frame in every `_layout` from its directory up to `scenes/` or `components/` - or null.
109
+ * `file` is the frame's path from the root; `memo` caches per directory across one scan. */
110
+ function layoutDocSource(root, file, memo) {
111
+ const parts = file.split("/").slice(0, -1);
112
+ if (parts.includes("..")) return null;
113
+ for (let i = parts.length; i >= 2; i--) {
114
+ const dir = parts.slice(0, i).join("/");
115
+ let found = memo.get(dir);
116
+ if (found === void 0) {
117
+ found = null;
118
+ for (const ext of ["tsx", "jsx"]) try {
119
+ const src = readFileSync(join(root, dir, `_layout.${ext}`), "utf8");
120
+ if (rendersDoc(src)) {
121
+ found = src;
122
+ break;
123
+ }
124
+ } catch {}
125
+ memo.set(dir, found);
126
+ }
127
+ if (found !== null) return found;
128
+ }
129
+ return null;
130
+ }
131
+ const contentWidthOf = (src) => docTags(codeOnly(src)).some((t) => new RegExp(`<${tagPattern(t)}\\b[^>]*\\blayout\\s*=\\s*["']wide["']`).test(src)) ? CONTENT_WIDTH.wide : CONTENT_WIDTH.document;
89
132
  /** The source with comments, template literals and CODE-shaped strings blanked (a JSX
90
133
  * expression string `{'<Diagram>'}`, an attribute value), so a tag name quoted in an example
91
134
  * or a comment never counts as a rendered element. Prose is left alone: JSX text has
@@ -322,10 +365,12 @@ const statusBoards = (root) => (scanBoards(root).boards ?? []).filter((b) => b.t
322
365
  function scanFrames(root, project) {
323
366
  const design = join(root, "design");
324
367
  const frames = [];
368
+ const layoutDocs = /* @__PURE__ */ new Map();
325
369
  for (const base of ["scenes", "components"]) for (const abs of walk(join(design, base))) {
326
370
  const name = abs.split(sep).pop();
327
- if (name.startsWith("_") || !FRAME_EXT.test(name)) continue;
328
371
  const rel = relative(design, abs).split(sep).join("/");
372
+ const folders = rel.split("/").slice(base === "scenes" ? 2 : 1, -1);
373
+ if (!FRAME_EXT.test(name) || name.startsWith("_") || folders.some((s) => s.startsWith("_"))) continue;
329
374
  const id = toFrameId(rel);
330
375
  const scene = id.includes("/") ? id.split("/")[0] : "";
331
376
  if (base === "scenes" && RESERVED_SCENES.has(scene)) {
@@ -354,7 +399,8 @@ function scanFrames(root, project) {
354
399
  const content = contentScan(src);
355
400
  if (content || meta.intent) {
356
401
  entry.intent = meta.intent ?? content.intent;
357
- entry.contentWidth = content?.width ?? contentWidthOf(src);
402
+ const layout = rendersDoc(src) ? null : layoutDocSource(root, entry.file, layoutDocs);
403
+ entry.contentWidth = layout !== null ? contentWidthOf(layout) : content?.width ?? contentWidthOf(src);
358
404
  }
359
405
  }
360
406
  frames.push(entry);
@@ -376,6 +422,10 @@ function scanFrames(root, project) {
376
422
  inferVariantGroups(frames);
377
423
  const sceneCounts = /* @__PURE__ */ new Map();
378
424
  for (const f of frames) sceneCounts.set(f.scene, (sceneCounts.get(f.scene) ?? 0) + 1);
425
+ const scenesDir = join(design, "scenes");
426
+ if (existsSync(scenesDir)) {
427
+ for (const e of readdirSync(scenesDir, { withFileTypes: true })) if (e.isDirectory() && !e.name.startsWith(".") && !RESERVED_SCENES.has(e.name) && !sceneCounts.has(e.name) && existsSync(join(scenesDir, e.name, "_brief.md"))) sceneCounts.set(e.name, 0);
428
+ }
379
429
  const scenes = [...sceneCounts.entries()].map(([name, n]) => {
380
430
  const note = sceneNote(root, name);
381
431
  return {
@@ -475,4 +525,4 @@ function writeManifest(root, manifest) {
475
525
  return true;
476
526
  }
477
527
  //#endregion
478
- export { setSceneTitle as a, scanFrames as i, isNoteFile as n, toFrameId as o, manifest_exports as r, writeManifest as s, affectedFrameIds as t };
528
+ export { rendersDoc as a, toFrameId as c, manifest_exports as i, writeManifest as l, isNoteFile as n, scanFrames as o, layoutDocSource as r, setSceneTitle as s, affectedFrameIds as t };