@marver-design/marver 0.27.2 → 0.28.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 (64) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +4 -2
  3. package/dist/{anchor-check-gkxkPAIv.mjs → anchor-check-PHUOFj1N.mjs} +1 -1
  4. package/dist/{audio-Dw1lfMdb.mjs → audio-DX4POHAj.mjs} +39 -4
  5. package/dist/{boards-BqUqKNW8.mjs → boards-BeWtjGUM.mjs} +49 -4
  6. package/dist/boards-EH2onUXM.mjs +995 -0
  7. package/dist/{build-VgNg4rr8.mjs → build-BsAyLMT1.mjs} +7 -5
  8. package/dist/{capture-vadKjuCo.mjs → capture-DdZ6xgoz.mjs} +92 -30
  9. package/dist/cli.mjs +37 -16
  10. package/dist/{comments-YEU1Zhv9.mjs → comments-CrBHPEQl.mjs} +2 -2
  11. package/dist/config-BezZTiov.mjs +182 -0
  12. package/dist/conn-BMiHS42T.mjs +222 -0
  13. package/dist/connectors-MR9d-EBP.mjs +290 -0
  14. package/dist/{context-Ccjrhr1J.mjs → context-BUnFiyA3.mjs} +2 -2
  15. package/dist/{daemon-Dc9AH0M3.mjs → daemon-C5dg2R-V.mjs} +2187 -182
  16. package/dist/{dev-ri6nAlRp.mjs → dev-D7YS7iT2.mjs} +22 -11
  17. package/dist/{init-W0nxR1OY.mjs → init-WE5lQkQL.mjs} +7 -2
  18. package/dist/jam-Cj5gBvwD.mjs +373 -0
  19. package/dist/{link-CdTgn94Y.mjs → link-BFFRgrMt.mjs} +3 -3
  20. package/dist/listener-DdLEM79A.mjs +80 -0
  21. package/dist/{manifest-aFyDmL8C.mjs → manifest-DPZ3WNg_.mjs} +1 -1
  22. package/dist/{marks-BF9pNEgH.mjs → marks-Dyn6tmjp.mjs} +3 -3
  23. package/dist/{marks-CnCCfAbD.mjs → marks-Kmdab_5w.mjs} +2 -2
  24. package/dist/{perf-DkAUFT6W.mjs → perf-Cn5LiRaY.mjs} +3 -3
  25. package/dist/{perf-jam-BaH3Lg0m.mjs → perf-jam-QxD_UnzN.mjs} +1 -1
  26. package/dist/permit-DDa6wqOs.mjs +187 -0
  27. package/dist/{plugin-B8UghYuF.mjs → plugin-C_0yb-Fq.mjs} +365 -518
  28. package/dist/{poster-BNgafWMK.mjs → poster-DHi6I1fO.mjs} +1 -1
  29. package/dist/{publish-bakes-38Nja78p.mjs → publish-bakes-r4PEZuPl.mjs} +2 -2
  30. package/dist/{queue-CAM_vNmX.mjs → queue-c-6aTHEz.mjs} +164 -25
  31. package/dist/{recover-B8AiI29B.mjs → recover-nrLEVLyJ.mjs} +1 -1
  32. package/dist/{session-BAaJsK5c.mjs → session-DyVE7cCk.mjs} +1 -1
  33. package/dist/{shot-Ch24tiMO.mjs → shot-BrRtqaiS.mjs} +7 -6
  34. package/dist/{shot-CMQgMVZm.mjs → shot-DBWN8hPP.mjs} +1 -1
  35. package/dist/sizes-wjXDev3b.mjs +139 -0
  36. package/dist/speech-worker.mjs +23 -3
  37. package/dist/transport-C5FnY9ni.mjs +203 -0
  38. package/dist/{work-Bxz-ObF3.mjs → work-BYWD_1Zf.mjs} +3 -3
  39. package/dist/{work-CNhFF9pU.mjs → work-DJxH7cCX.mjs} +1 -1
  40. package/docs/jam-session.md +39 -14
  41. package/docs/live-jam.md +92 -10
  42. package/package.json +1 -1
  43. package/src/client/shell/JamSurface.tsx +56 -21
  44. package/src/client/shell/icons.tsx +1 -0
  45. package/src/client/shell/jam-capture.ts +97 -22
  46. package/src/client/shell/jam-keys.ts +32 -6
  47. package/src/client/shell/jam-lane.tsx +14 -5
  48. package/src/client/shell/jam-lines.ts +66 -9
  49. package/src/client/shell/jam-panel.tsx +55 -3
  50. package/src/client/shell/jam-queue.ts +50 -8
  51. package/src/client/shell/jam-session.tsx +53 -4
  52. package/src/client/shell/jam-surface-parts.tsx +6 -3
  53. package/src/client/shell/jam-ui.tsx +6 -1
  54. package/src/client/shell/jam-voice-wait.ts +21 -0
  55. package/src/client/shell/jam-voice.ts +14 -5
  56. package/src/client/shell/styles.css +27 -11
  57. package/src/client/shell/tidy.ts +3 -2
  58. package/src/shared/approval.ts +20 -0
  59. package/src/shared/events.ts +1 -1
  60. package/templates/AGENTS-embedded.md +28 -1
  61. package/templates/AGENTS-studio.md +28 -1
  62. package/templates/instructions/boards.md +7 -1
  63. package/templates/instructions/jam.md +90 -0
  64. package/dist/boards-BHKP5yhI.mjs +0 -342
@@ -1,186 +1,23 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { a as ROUTE, i as PKG, r as NAME } from "./cli.mjs";
3
- import { c as nodeExists, d as readMembership, f as readRegistry, h as hash, i as checkBoardsDir, l as parseBoard, m as withRegistryLock, o as isRegularFile, r as boardFields, s as listBoardFiles, t as AUTHOR_FIELDS, u as pinFrames } from "./boards-BHKP5yhI.mjs";
3
+ import { a as checkBoardsDir, c as listBoardFiles, d as pinFrames, g as tryFileLock, h as takeFileLock, i as boardLock, l as nodeExists, m as readRegistry, p as readMembership, r as boardFields, s as isRegularFile, t as AUTHOR_FIELDS, u as parseBoard, v as withRegistryLock, y as hash } from "./boards-EH2onUXM.mjs";
4
4
  import { A as resolveType, D as readReason, E as readCapability, O as readStatusWord, S as HAS_STATUS, _ as validateWire, a as buildTree, c as folderMap, g as readTitle, h as readDescription, j as settableStatuses, k as readType, n as BOARD_NAME, r as FOLDERS_FILE, t as ALL_SCENES, v as wireKids } from "./board-tree-BXR8dw4b.mjs";
5
- import { c as setSceneTitle, d as annotateBoards, f as planNames, m as readContextFacts, n as isNoteFile, o as rendersDoc, p as planWithStage, r as layoutDocSource, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-aFyDmL8C.mjs";
6
- import { r as boardsChanged } from "./work-CNhFF9pU.mjs";
5
+ import { c as setSceneTitle, d as annotateBoards, f as planNames, m as readContextFacts, n as isNoteFile, p as planWithStage, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-DPZ3WNg_.mjs";
6
+ import { r as boardsChanged } from "./work-DJxH7cCX.mjs";
7
7
  import { h as workspaceId, i as marverHome, o as originOf } from "./slots-CFNnegCc.mjs";
8
8
  import { n as localProfile, t as isConnected } from "./profile-jIS6BcAs.mjs";
9
- import { i as onPath, n as AGENT_NAMES, r as detectAgent, t as AGENT_BIN } from "./agent-BsieQGTD.mjs";
10
- import { a as observe, n as docRevs, r as initMarks, s as recordChanged, t as docRev } from "./marks-CnCCfAbD.mjs";
11
- import { a as appendRun, f as tidyPerfDir, i as PAGE_BODY_MAX, o as logPage, s as logReload } from "./perf-jam-BaH3Lg0m.mjs";
12
- import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-Ch24tiMO.mjs";
9
+ import { a as observe, n as docRevs, r as initMarks, s as recordChanged, t as docRev } from "./marks-Kmdab_5w.mjs";
10
+ import { a as appendRun, f as tidyPerfDir, i as PAGE_BODY_MAX, o as logPage, s as logReload } from "./perf-jam-QxD_UnzN.mjs";
11
+ import { n as loadConfig } from "./config-BezZTiov.mjs";
12
+ import { a as mergeSizes, c as serializeSizes, i as measuringFrames, l as sizesPath, n as autoWidthOf, o as readSizes, r as keptSizes, s as readSizesFile } from "./sizes-wjXDev3b.mjs";
13
+ import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-BrRtqaiS.mjs";
13
14
  import { closeSync, constants, copyFileSync, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, watch, writeFileSync } from "node:fs";
14
15
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
15
- import { fileURLToPath, pathToFileURL } from "node:url";
16
+ import { fileURLToPath } from "node:url";
16
17
  import { createHash, createHmac, randomBytes } from "node:crypto";
17
18
  import { arch, cpus, totalmem } from "node:os";
18
19
  import { execFile } from "node:child_process";
19
20
  import { stat } from "node:fs/promises";
20
- //#region src/server/config.ts
21
- const DEFAULTS = {
22
- mode: "studio",
23
- theme: null,
24
- viewports: {
25
- mobile: {
26
- width: 390,
27
- height: 844
28
- },
29
- tablet: {
30
- width: 768,
31
- height: 1024
32
- },
33
- laptop: {
34
- width: 1280,
35
- height: 800
36
- },
37
- monitor: {
38
- width: 1920,
39
- height: 1080
40
- }
41
- },
42
- themes: ["light", "dark"],
43
- port: 5199,
44
- zoomSpeed: 1,
45
- share: { branding: true }
46
- };
47
- /** Load design/config.ts via native TS import (Node >= 22.18). Missing or broken fields fall back to defaults. */
48
- async function loadConfig(root) {
49
- const file = join(root, "design", "config.ts");
50
- if (!existsSync(file)) return {
51
- ...DEFAULTS,
52
- ...jamFields(void 0)
53
- };
54
- try {
55
- const user = (await import(`${pathToFileURL(file).href}?t=${Date.now()}`)).default ?? {};
56
- return {
57
- ...DEFAULTS,
58
- ...user,
59
- viewports: validViewports(user.viewports) ?? DEFAULTS.viewports,
60
- themes: Array.isArray(user.themes) && user.themes.length ? user.themes.map(String) : DEFAULTS.themes,
61
- port: validPort(user.port) ?? DEFAULTS.port,
62
- zoomSpeed: validZoom(user.zoomSpeed) ?? DEFAULTS.zoomSpeed,
63
- description: readDescription(user.description),
64
- share: {
65
- branding: user.share?.branding !== false,
66
- name: typeof user.share?.name === "string" ? user.share.name : void 0,
67
- logo: typeof user.share?.logo === "string" ? user.share.logo : void 0,
68
- frontDoor: user.share?.frontDoor !== false && user.share?.front_door !== false,
69
- notify: user.share?.notify !== false
70
- },
71
- ...jamFields(user.jam)
72
- };
73
- } catch (err) {
74
- console.error(`[marver] design/config.ts failed to load, using defaults and leaving Live Jam OFF:\n ${err.message}`);
75
- return {
76
- ...DEFAULTS,
77
- jamOff: "unreadable"
78
- };
79
- }
80
- }
81
- const validDim = (n) => typeof n === "number" && Number.isFinite(n) && n >= 1 && n <= 2e4;
82
- function validPort(n) {
83
- return typeof n === "number" && Number.isInteger(n) && n > 0 && n < 65536 ? n : null;
84
- }
85
- function validZoom(n) {
86
- return typeof n === "number" && Number.isFinite(n) && n >= .1 && n <= 10 ? n : null;
87
- }
88
- /** Six frames at once is what a jam actually feels like - at 3, half of a multi-frame
89
- * ask sat waiting on the other half while the human watched. */
90
- const DEFAULT_CONCURRENCY = 6;
91
- /** A config value, printable in a warning. Never throws - a formatter that can crash inside an
92
- * error path (JSON.stringify does, on a BigInt) turns a clear message into a mystery. */
93
- const show = (v) => {
94
- try {
95
- return JSON.stringify(v) ?? String(v);
96
- } catch {
97
- return String(v);
98
- }
99
- };
100
- /** A `{...}` written by hand, not a Date/Map/class instance that merely types as "object". */
101
- const plainObject = (v) => {
102
- if (!v || typeof v !== "object") return false;
103
- const proto = Object.getPrototypeOf(v);
104
- return proto === Object.prototype || proto === null;
105
- };
106
- /** The agent to arm with - or, when the human NAMED one we cannot use, why not (said once,
107
- * here, because a bad `jam.agent` is a config-file error like any other).
108
- *
109
- * A named agent is never quietly swapped for another: running a different tool than the one
110
- * asked for is worse than not running. Nor is one armed that cannot be spawned - that would
111
- * claim every @marver mention, fail it, and never retry. */
112
- function resolveAgent(named) {
113
- if (named === void 0) return detectAgent() ?? "no-agent";
114
- if (typeof named !== "string" || !Object.hasOwn(AGENT_BIN, named)) {
115
- console.warn(`[marver] design/config.ts: jam.agent ${show(named)} is not an agent marver can spawn - Live Jam is off. Use ${AGENT_NAMES}.`);
116
- return "bad-agent";
117
- }
118
- const agent = named;
119
- if (!onPath(AGENT_BIN[agent])) {
120
- console.warn(`[marver] design/config.ts names jam.agent "${agent}", but \`${AGENT_BIN[agent]}\` is not on PATH - Live Jam is off until it is installed.`);
121
- return "bad-agent";
122
- }
123
- return agent;
124
- }
125
- /** Resolve the jam block. Live Jam is ON by default: an absent or partial `jam` resolves
126
- * to whatever agent CLI this machine has, so a fresh workspace jams with nothing
127
- * configured and an old one needs no re-init. `jam: false` is the off switch. */
128
- function resolveJam(v) {
129
- if (v === false) return "opted-out";
130
- const shape = v === void 0 || v === true ? {} : typeof v === "string" ? { agent: v } : plainObject(v) ? v : null;
131
- if (!shape) {
132
- console.warn(`[marver] design/config.ts: jam must be false, an agent name, or an options object - got ${show(v)}. Live Jam is off.`);
133
- return "bad-agent";
134
- }
135
- const j = shape;
136
- const agent = resolveAgent(j.agent);
137
- if (agent === "no-agent" || agent === "bad-agent") return agent;
138
- const c = j.concurrency;
139
- const pick = (key, v, ok, fallback, want) => {
140
- if (v === void 0) return fallback;
141
- if (ok(v)) return v;
142
- console.warn(`[marver] design/config.ts: jam.${key} must be ${want} - got ${show(v)}. Using ${JSON.stringify(fallback)}.`);
143
- return fallback;
144
- };
145
- const bool = (v) => typeof v === "boolean";
146
- return {
147
- agent,
148
- concurrency: typeof c === "number" && Number.isInteger(c) && c >= 1 && c <= 16 ? c : DEFAULT_CONCURRENCY,
149
- subagents: j.subagents !== false,
150
- proactive: j.proactive === true,
151
- chime: pick("chime", j.chime, bool, true, "true or false"),
152
- capture: pick("capture", j.capture, (v) => v === "confirm" || v === "at-once", "confirm", `'confirm' or 'at-once'`),
153
- loc: pick("loc", j.loc, bool, true, "true or false"),
154
- names: pick("names", j.names, bool, true, "true or false")
155
- };
156
- }
157
- /** Exactly one of `jam` (armed) or `jamOff` (why not) - so the dev server can speak up about
158
- * the one off-state nothing has reported yet, and stay quiet about the rest. BOTH keys are
159
- * always written: these spread over the user's own `jam`, and a raw `jam: false` reaching the
160
- * server as config would arm the daemon against a truthy object check. */
161
- function jamFields(v) {
162
- const r = resolveJam(v);
163
- return typeof r === "string" ? {
164
- jam: void 0,
165
- jamOff: r
166
- } : {
167
- jam: r,
168
- jamOff: void 0
169
- };
170
- }
171
- function validViewports(v) {
172
- if (!v || typeof v !== "object") return null;
173
- const out = {};
174
- for (const [k, val] of Object.entries(v)) {
175
- const vp = val;
176
- if (validDim(vp?.width) && validDim(vp?.height)) out[k] = {
177
- width: Math.round(vp.width),
178
- height: Math.round(vp.height)
179
- };
180
- }
181
- return Object.keys(out).length ? out : null;
182
- }
183
- //#endregion
184
21
  //#region src/shared/frames.ts
185
22
  /** A canvas made of content frames alone (Doc, Md, Diagram ship their own styling) needs no theme -
186
23
  * only an app frame does (#4). Empty counts as not content-only: the warning still helps there. */
@@ -310,122 +147,6 @@ function guardUpdates(server, root, manifest, hooks) {
310
147
  });
311
148
  }
312
149
  //#endregion
313
- //#region src/server/sizes.ts
314
- /**
315
- * Content-frame heights - `design/boards/_sizes.json`, committed.
316
- *
317
- * A content frame (a Doc: markdown, diagrams, images) is as tall as its content, which only a
318
- * render can tell. Measured live, every load started from a guess (3/4 of the width) and grew
319
- * frame by frame, and each growth re-flowed the rows below - the board swam for seconds. The
320
- * height a frame measured at its own width is a fact about the FRAME at that width, not about a
321
- * board (one doc sits on several boards) and not something to write into the frame's source: so
322
- * it lives here, one line per `scene/frame@width`, written by the dev server when the shell
323
- * reports a settled measurement, read before the first layout - dev, `marver build` and the
324
- * published canvas alike. A stale entry is still the best first guess; the live measurement
325
- * corrects it and the file follows. Underscore = infrastructure, never a board (board-tree.ts).
326
- */
327
- const SIZES_FILE = "_sizes.json";
328
- /** `scene/frame@width` - the frame id grammar the focus route accepts, then the width it was measured at. */
329
- const SIZE_KEY = /^([\w./-]{1,200})@(\d{2,4})$/;
330
- const ABOUT = "Written by marver dev: the height each content frame measured at its width, so boards open at their final size. Commit it; never edit it by hand.";
331
- const sizesPath = (root) => join(root, "design", "boards", SIZES_FILE);
332
- /** A valid entry: a well-formed key whose frame is not a traversal, and a height in the shell's clamp. */
333
- function validEntry(key, h) {
334
- if (typeof key !== "string" || typeof h !== "number" || !Number.isInteger(h) || h < 80 || h > 4e4) return false;
335
- const m = SIZE_KEY.exec(key);
336
- return !!m && !m[1].split("/").some((p) => p === ".." || p === "." || p === "");
337
- }
338
- function readSizesFile(root) {
339
- const file = sizesPath(root);
340
- if (!existsSync(file)) return {
341
- state: "absent",
342
- heights: {}
343
- };
344
- try {
345
- const raw = JSON.parse(readFileSync(file, "utf8"));
346
- if (!raw || typeof raw !== "object" || !raw.heights || typeof raw.heights !== "object" || Array.isArray(raw.heights)) return {
347
- state: "invalid",
348
- heights: {}
349
- };
350
- const out = {};
351
- for (const [k, v] of Object.entries(raw.heights)) if (validEntry(k, v)) out[k] = v;
352
- return {
353
- state: "ok",
354
- heights: out
355
- };
356
- } catch {
357
- return {
358
- state: "invalid",
359
- heights: {}
360
- };
361
- }
362
- }
363
- /** Lenient read for the readers (the shell's first layout, the build): an absent or invalid file is
364
- * no heights - every frame opens at its placeholder, as before. Never throws. */
365
- const readSizes = (root) => readSizesFile(root).heights;
366
- /** The file's text for a set of heights: sorted keys, one entry per line - a changed height is a
367
- * one-line diff, and two branches that measured different frames merge without a conflict. */
368
- function serializeSizes(heights) {
369
- const sorted = {};
370
- for (const k of Object.keys(heights).sort()) sorted[k] = heights[k];
371
- return JSON.stringify({
372
- about: ABOUT,
373
- heights: sorted
374
- }, null, 2) + "\n";
375
- }
376
- const keeps = (key, autoWidth) => {
377
- const m = SIZE_KEY.exec(key);
378
- return !!m && autoWidth(m[1]) === Number(m[2]);
379
- };
380
- /** Merge incoming heights into the current ones, keeping only what a board can use: a content frame
381
- * that still exists, at the width it measures at on its own. Everything else is pruned - a deleted
382
- * frame, a Doc that went from document to wide. Returns the next map and the keys taken. Pruning
383
- * reads only the manifest: whether a frame still renders a Doc is asked on READ (keptSizes), so a
384
- * source caught mid-write can hide an entry for one load, never delete it. */
385
- function mergeSizes(current, incoming, autoWidth) {
386
- const next = Object.fromEntries(Object.entries(current).filter(([k]) => keeps(k, autoWidth)));
387
- const accepted = [];
388
- for (const [k, v] of Object.entries(incoming)) {
389
- if (!validEntry(k, v) || !keeps(k, autoWidth)) continue;
390
- next[k] = v;
391
- accepted.push(k);
392
- }
393
- return {
394
- next,
395
- accepted
396
- };
397
- }
398
- /** The entries a board can use - what the GET and the build hand the shell: a content frame at its
399
- * own width that MEASURES (renders a Doc). A frame that went from a Doc to a bare Md keeps the size
400
- * its board gives it, never an old measurement. */
401
- const keptSizes = (heights, autoWidth, measuring) => Object.fromEntries(Object.entries(heights).filter(([k]) => keeps(k, autoWidth) && measuring.has(k.slice(0, k.lastIndexOf("@")))));
402
- /** The auto width rule over a manifest's frames (the shell's defaultSize, store.ts). */
403
- function autoWidthOf(frames, viewports) {
404
- const byId = new Map(frames.map((f) => [f.id, f]));
405
- return (id) => {
406
- const f = byId.get(id);
407
- if (!f?.contentWidth) return null;
408
- return viewports[f.viewport ?? ""]?.width ?? f.contentWidth;
409
- };
410
- }
411
- /** The content frames that measure: the frame renders a Doc, or a `_layout` it renders inside does
412
- * (manifest.ts layoutDocSource - the same rule the manifest's width follows). A source that cannot
413
- * be read, or reads empty (an editor mid-write), gets the benefit of the doubt - this only decides
414
- * what a load is handed, never what the file keeps. */
415
- function measuringFrames(root, frames) {
416
- const out = /* @__PURE__ */ new Set();
417
- const memo = /* @__PURE__ */ new Map();
418
- for (const f of frames) {
419
- if (!f.contentWidth || f.kind === "html" || !f.file || f.file.split("/").includes("..")) continue;
420
- let src = "";
421
- try {
422
- src = readFileSync(join(root, f.file), "utf8");
423
- } catch {}
424
- if (!src.trim() || rendersDoc(src) || layoutDocSource(root, f.file, memo) !== null) out.add(f.id);
425
- }
426
- return out;
427
- }
428
- //#endregion
429
150
  //#region src/shared/perf-run.ts
430
151
  /** A run's own generated id: the same in the URL, the request headers and the output line (A3.4). */
431
152
  const RUN_ID = /^[0-9a-f]{16}$/;
@@ -2864,126 +2585,136 @@ function apiMiddleware(root, opts = {}) {
2864
2585
  const file = boardPath(name);
2865
2586
  if (!file) return json(res, 400, { error: "invalid board name" });
2866
2587
  if (!existsSync(file)) return json(res, 404, { error: `board "${name}" does not exist` });
2867
- if (!notSymlink(file)) return json(res, 400, { error: "refusing to write a symlinked board file" });
2868
- const current = readFileSync(file, "utf8");
2869
- if (baseHash !== void 0 && baseHash !== hash(current)) return json(res, 409, {
2870
- error: "board changed on disk",
2871
- sha256: hash(current)
2588
+ const unlock = await takeFileLock(boardLock(boardsDir, name), 2e3).catch((e) => {
2589
+ if (e.code === "EACCES" || e.code === "EPERM" || e.code === "EROFS") return () => {};
2590
+ throw e;
2872
2591
  });
2873
- let obj;
2592
+ if (!unlock) return json(res, 503, { error: "the board is being written - try again" });
2874
2593
  try {
2875
- obj = JSON.parse(current);
2876
- } catch {
2877
- return json(res, 422, { error: `board "${name}" is not valid JSON - fix the file` });
2878
- }
2879
- if (!obj || typeof obj !== "object" || Array.isArray(obj)) return json(res, 422, { error: `board "${name}" is not a JSON object - fix the file` });
2880
- const reg = readRegistry(boardsDir);
2881
- const regFolders = reg.state === "ok" ? reg.folders : [];
2882
- const all = listBoardFiles(boardsDir).boards;
2883
- const fm = folderMap(buildTree(all.map((b) => ({
2884
- name: b.name,
2885
- ...boardFields(b.json, validName)
2886
- })), regFolders));
2887
- const folder = regFolders.find((f) => f.name === fm.get(name));
2888
- const parent = folder?.parent ? regFolders.find((f) => f.name === folder.parent) : void 0;
2889
- const type = resolveType(obj.type, folder?.type, parent?.type);
2890
- if (!HAS_STATUS.includes(type)) return json(res, 422, { error: `a ${type} board carries no status - only feature and project boards do` });
2891
- const facts = readContextFacts(root);
2892
- const capability = readCapability(obj.capability) ?? name;
2893
- const plans = facts.present ? facts.plans.get(capability) ?? [] : [];
2894
- if (status !== null && !settableStatuses(facts.present, plans.length > 0).includes(status)) return json(res, 422, { error: status === "done" ? "Done is never set by hand - it comes from context/shipped.md" : status === "building" || status === "in-progress" ? `${status === "building" ? "Building" : "In progress"} needs an open plan naming ${capability} - context/plans/` : `with context/, ${status} is read from the evidence - a plan, a contract, the shipped record` });
2895
- const writes = [];
2896
- if (facts.present && (status === "building" || status === "in-progress")) {
2897
- for (const p of plans.filter((x, i) => plans.findIndex((y) => y.where === x.where) === i)) {
2898
- const file = join(root, p.where);
2899
- if (!notSymlink(file)) return json(res, 400, { error: `refusing to write a symlinked plan (${p.where})` });
2900
- const raw = readFileSync(file, "utf8");
2901
- if (!planNames(raw, capability)) return json(res, 409, { error: `${p.where} changed on disk - try again` });
2902
- const r = planWithStage(raw, status === "building" ? "build" : null);
2903
- if ("error" in r) return json(res, 422, { error: `${p.where} ${r.error} - fix the file` });
2904
- writes.push({
2905
- file,
2906
- raw,
2907
- next: r.text,
2908
- plan: p.where
2909
- });
2910
- }
2911
- delete obj.status;
2912
- delete obj.reason;
2913
- } else {
2914
- if (status === null) delete obj.status;
2915
- else obj.status = status;
2916
- if (status === "blocked") obj.reason = reason;
2917
- else delete obj.reason;
2918
- }
2919
- const next = JSON.stringify(obj, null, 2) + "\n";
2920
- writes.push({
2921
- file,
2922
- raw: current,
2923
- next
2924
- });
2925
- const current_ = (f) => {
2594
+ if (!existsSync(file)) return json(res, 404, { error: `board "${name}" does not exist` });
2595
+ if (!notSymlink(file)) return json(res, 400, { error: "refusing to write a symlinked board file" });
2596
+ const current = readFileSync(file, "utf8");
2597
+ if (baseHash !== void 0 && baseHash !== hash(current)) return json(res, 409, {
2598
+ error: "board changed on disk",
2599
+ sha256: hash(current)
2600
+ });
2601
+ let obj;
2926
2602
  try {
2927
- return readFileSync(f, "utf8");
2603
+ obj = JSON.parse(current);
2928
2604
  } catch {
2929
- return null;
2605
+ return json(res, 422, { error: `board "${name}" is not valid JSON - fix the file` });
2930
2606
  }
2931
- };
2932
- const done = [];
2933
- const undo = () => {
2934
- const stuck = [];
2935
- for (const w of done.reverse()) {
2936
- const label = w.plan ?? `design/boards/${name}.json`;
2937
- let tmp;
2607
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) return json(res, 422, { error: `board "${name}" is not a JSON object - fix the file` });
2608
+ const reg = readRegistry(boardsDir);
2609
+ const regFolders = reg.state === "ok" ? reg.folders : [];
2610
+ const all = listBoardFiles(boardsDir).boards;
2611
+ const fm = folderMap(buildTree(all.map((b) => ({
2612
+ name: b.name,
2613
+ ...boardFields(b.json, validName)
2614
+ })), regFolders));
2615
+ const folder = regFolders.find((f) => f.name === fm.get(name));
2616
+ const parent = folder?.parent ? regFolders.find((f) => f.name === folder.parent) : void 0;
2617
+ const type = resolveType(obj.type, folder?.type, parent?.type);
2618
+ if (!HAS_STATUS.includes(type)) return json(res, 422, { error: `a ${type} board carries no status - only feature and project boards do` });
2619
+ const facts = readContextFacts(root);
2620
+ const capability = readCapability(obj.capability) ?? name;
2621
+ const plans = facts.present ? facts.plans.get(capability) ?? [] : [];
2622
+ if (status !== null && !settableStatuses(facts.present, plans.length > 0).includes(status)) return json(res, 422, { error: status === "done" ? "Done is never set by hand - it comes from context/shipped.md" : status === "building" || status === "in-progress" ? `${status === "building" ? "Building" : "In progress"} needs an open plan naming ${capability} - context/plans/` : `with context/, ${status} is read from the evidence - a plan, a contract, the shipped record` });
2623
+ const writes = [];
2624
+ if (facts.present && (status === "building" || status === "in-progress")) {
2625
+ for (const p of plans.filter((x, i) => plans.findIndex((y) => y.where === x.where) === i)) {
2626
+ const file = join(root, p.where);
2627
+ if (!notSymlink(file)) return json(res, 400, { error: `refusing to write a symlinked plan (${p.where})` });
2628
+ const raw = readFileSync(file, "utf8");
2629
+ if (!planNames(raw, capability)) return json(res, 409, { error: `${p.where} changed on disk - try again` });
2630
+ const r = planWithStage(raw, status === "building" ? "build" : null);
2631
+ if ("error" in r) return json(res, 422, { error: `${p.where} ${r.error} - fix the file` });
2632
+ writes.push({
2633
+ file,
2634
+ raw,
2635
+ next: r.text,
2636
+ plan: p.where
2637
+ });
2638
+ }
2639
+ delete obj.status;
2640
+ delete obj.reason;
2641
+ } else {
2642
+ if (status === null) delete obj.status;
2643
+ else obj.status = status;
2644
+ if (status === "blocked") obj.reason = reason;
2645
+ else delete obj.reason;
2646
+ }
2647
+ const next = JSON.stringify(obj, null, 2) + "\n";
2648
+ writes.push({
2649
+ file,
2650
+ raw: current,
2651
+ next
2652
+ });
2653
+ const current_ = (f) => {
2938
2654
  try {
2939
- tmp = stageWrite(w.file, w.raw);
2655
+ return readFileSync(f, "utf8");
2940
2656
  } catch {
2941
- stuck.push(label);
2942
- continue;
2657
+ return null;
2943
2658
  }
2944
- if (current_(w.file) !== w.next) {
2945
- discard(tmp);
2946
- stuck.push(`${label} (edited since - kept)`);
2947
- continue;
2659
+ };
2660
+ const done = [];
2661
+ const undo = () => {
2662
+ const stuck = [];
2663
+ for (const w of done.reverse()) {
2664
+ const label = w.plan ?? `design/boards/${name}.json`;
2665
+ let tmp;
2666
+ try {
2667
+ tmp = stageWrite(w.file, w.raw);
2668
+ } catch {
2669
+ stuck.push(label);
2670
+ continue;
2671
+ }
2672
+ if (current_(w.file) !== w.next) {
2673
+ discard(tmp);
2674
+ stuck.push(`${label} (edited since - kept)`);
2675
+ continue;
2676
+ }
2677
+ try {
2678
+ renameSync(tmp, w.file);
2679
+ } catch {
2680
+ discard(tmp);
2681
+ stuck.push(label);
2682
+ }
2948
2683
  }
2684
+ return stuck;
2685
+ };
2686
+ for (const w of writes) {
2687
+ if (w.next === w.raw) continue;
2688
+ let tmp = null;
2949
2689
  try {
2690
+ tmp = stageWrite(w.file, w.next);
2691
+ const now = current_(w.file);
2692
+ if (now !== w.raw) {
2693
+ discard(tmp);
2694
+ const stuck = undo();
2695
+ if (stuck.length) return json(res, 500, { error: `${w.plan ?? `board "${name}"`} changed on disk mid-write, and ${stuck.join(", ")} still ${stuck.length === 1 ? "holds" : "hold"} this change - check by hand` });
2696
+ return json(res, 409, {
2697
+ error: `${w.plan ?? `board "${name}"`} changed on disk - try again`,
2698
+ ...w.plan || now === null ? {} : { sha256: hash(now) }
2699
+ });
2700
+ }
2950
2701
  renameSync(tmp, w.file);
2951
- } catch {
2952
- discard(tmp);
2953
- stuck.push(label);
2954
- }
2955
- }
2956
- return stuck;
2957
- };
2958
- for (const w of writes) {
2959
- if (w.next === w.raw) continue;
2960
- let tmp = null;
2961
- try {
2962
- tmp = stageWrite(w.file, w.next);
2963
- const now = current_(w.file);
2964
- if (now !== w.raw) {
2965
- discard(tmp);
2702
+ done.push(w);
2703
+ } catch (err) {
2704
+ if (tmp) discard(tmp);
2966
2705
  const stuck = undo();
2967
- if (stuck.length) return json(res, 500, { error: `${w.plan ?? `board "${name}"`} changed on disk mid-write, and ${stuck.join(", ")} still ${stuck.length === 1 ? "holds" : "hold"} this change - check by hand` });
2968
- return json(res, 409, {
2969
- error: `${w.plan ?? `board "${name}"`} changed on disk - try again`,
2970
- ...w.plan || now === null ? {} : { sha256: hash(now) }
2971
- });
2706
+ const off = writes.filter((x) => x.next !== x.raw && current_(x.file) !== x.raw).map((x) => x.plan ?? `design/boards/${name}.json`);
2707
+ const named = [.../* @__PURE__ */ new Set([...stuck, ...off.filter((o) => !stuck.some((s) => s.startsWith(o)))])];
2708
+ return json(res, 500, { error: named.length ? `could not write the status (${err.message}), and ${named.join(", ")} ${named.length === 1 ? "is" : "are"} not as before - check by hand` : `could not write the status (${err.message}) - nothing changed` });
2972
2709
  }
2973
- renameSync(tmp, w.file);
2974
- done.push(w);
2975
- } catch (err) {
2976
- if (tmp) discard(tmp);
2977
- const stuck = undo();
2978
- const off = writes.filter((x) => x.next !== x.raw && current_(x.file) !== x.raw).map((x) => x.plan ?? `design/boards/${name}.json`);
2979
- const named = [.../* @__PURE__ */ new Set([...stuck, ...off.filter((o) => !stuck.some((s) => s.startsWith(o)))])];
2980
- return json(res, 500, { error: named.length ? `could not write the status (${err.message}), and ${named.join(", ")} ${named.length === 1 ? "is" : "are"} not as before - check by hand` : `could not write the status (${err.message}) - nothing changed` });
2981
2710
  }
2711
+ return json(res, 200, {
2712
+ name,
2713
+ sha256: hash(next)
2714
+ });
2715
+ } finally {
2716
+ unlock();
2982
2717
  }
2983
- return json(res, 200, {
2984
- name,
2985
- sha256: hash(next)
2986
- });
2987
2718
  }
2988
2719
  const readManifestFrames = () => {
2989
2720
  try {
@@ -3006,7 +2737,7 @@ function apiMiddleware(root, opts = {}) {
3006
2737
  const str = (v) => typeof v === "string" ? v.slice(0, 200) : void 0;
3007
2738
  const num = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
3008
2739
  if (!str(b?.kind)) return json(res, 400, { error: "kind required" });
3009
- (await import("./perf-jam-BaH3Lg0m.mjs").then((n) => n.c)).logReload(root, {
2740
+ (await import("./perf-jam-QxD_UnzN.mjs").then((n) => n.c)).logReload(root, {
3010
2741
  kind: str(b.kind),
3011
2742
  tab: str(b.tab),
3012
2743
  node: str(b.node),
@@ -3028,7 +2759,7 @@ function apiMiddleware(root, opts = {}) {
3028
2759
  return json(res, 400, { error: "malformed JSON" });
3029
2760
  }
3030
2761
  if (!b || b.kind !== "capture" && b.kind !== "upload") return json(res, 400, { error: "kind must be capture or upload" });
3031
- (await import("./perf-jam-BaH3Lg0m.mjs").then((n) => n.n)).logJam(root, b);
2762
+ (await import("./perf-jam-QxD_UnzN.mjs").then((n) => n.n)).logJam(root, b);
3032
2763
  return json(res, 200, { ok: true });
3033
2764
  }
3034
2765
  if (path === "perf/page" && req.method === "POST") {
@@ -3053,7 +2784,7 @@ function apiMiddleware(root, opts = {}) {
3053
2784
  });
3054
2785
  }
3055
2786
  if (path === "perf/run" && req.method === "POST" || path === "perf/inputs" && req.method === "GET") {
3056
- const { readDevInfo } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
2787
+ const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
3057
2788
  const token = readDevInfo(root)?.token;
3058
2789
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
3059
2790
  if (path === "perf/inputs") {
@@ -3193,56 +2924,63 @@ function apiMiddleware(root, opts = {}) {
3193
2924
  const fromPath = boardPath(from), toPath = boardPath(to);
3194
2925
  if (!fromPath || !toPath) return json(res, 400, { error: "invalid board name" });
3195
2926
  if (!existsSync(fromPath)) return json(res, 404, { error: `board "${from}" does not exist` });
3196
- if (!notSymlink(fromPath)) return json(res, 400, { error: "refusing to rename a symlinked board file" });
3197
- const current = readFileSync(fromPath, "utf8");
3198
- if (baseHash !== void 0 && baseHash !== hash(current)) return json(res, 409, {
3199
- error: "board changed on disk",
3200
- sha256: hash(current)
3201
- });
3202
- let obj = null;
3203
- if (titleRaw !== void 0) {
3204
- let parsedBoard;
3205
- try {
3206
- parsedBoard = JSON.parse(current);
3207
- } catch {
3208
- return json(res, 422, { error: `board "${from}" is not valid JSON - fix the file` });
2927
+ const unlock = await takeFileLock(boardLock(boardsDir, from), 2e3);
2928
+ if (!unlock) return json(res, 503, { error: "the board is being written - try again" });
2929
+ try {
2930
+ if (!existsSync(fromPath)) return json(res, 404, { error: `board "${from}" does not exist` });
2931
+ if (!notSymlink(fromPath)) return json(res, 400, { error: "refusing to rename a symlinked board file" });
2932
+ const current = readFileSync(fromPath, "utf8");
2933
+ if (baseHash !== void 0 && baseHash !== hash(current)) return json(res, 409, {
2934
+ error: "board changed on disk",
2935
+ sha256: hash(current)
2936
+ });
2937
+ let obj = null;
2938
+ if (titleRaw !== void 0) {
2939
+ let parsedBoard;
2940
+ try {
2941
+ parsedBoard = JSON.parse(current);
2942
+ } catch {
2943
+ return json(res, 422, { error: `board "${from}" is not valid JSON - fix the file` });
2944
+ }
2945
+ if (!parsedBoard || typeof parsedBoard !== "object" || Array.isArray(parsedBoard)) return json(res, 422, { error: `board "${from}" is not a JSON object - fix the file` });
2946
+ obj = parsedBoard;
3209
2947
  }
3210
- if (!parsedBoard || typeof parsedBoard !== "object" || Array.isArray(parsedBoard)) return json(res, 422, { error: `board "${from}" is not a JSON object - fix the file` });
3211
- obj = parsedBoard;
3212
- }
3213
- let next;
3214
- if (obj) {
3215
- const title = readTitle(titleRaw);
3216
- if (title) obj.title = title;
3217
- else delete obj.title;
3218
- next = JSON.stringify(obj, null, 2) + "\n";
3219
- }
3220
- if (to !== from) {
3221
- if (isConnected(root)) return json(res, 409, { error: "disconnect before renaming boards - comment sync is board-keyed" });
3222
- if (existsSync(join(root, "design", "comments", `${from}.jsonl`))) return json(res, 409, { error: "rename a board before commenting on it - this board has threads" });
3223
- if (nodeExists$1(toPath)) return json(res, 409, { error: `a board named "${to}" already exists` });
3224
- try {
3225
- if (next !== void 0) writeFileSync(toPath, next, { flag: "wx" });
3226
- else linkSync(fromPath, toPath);
3227
- } catch (err) {
3228
- const code = err.code;
3229
- if (code === "EEXIST") return json(res, 409, { error: `a board named "${to}" already exists` });
3230
- if (next !== void 0 || code !== "EPERM" && code !== "ENOSYS" && code !== "ENOTSUP" && code !== "EOPNOTSUPP") throw err;
2948
+ let next;
2949
+ if (obj) {
2950
+ const title = readTitle(titleRaw);
2951
+ if (title) obj.title = title;
2952
+ else delete obj.title;
2953
+ next = JSON.stringify(obj, null, 2) + "\n";
2954
+ }
2955
+ if (to !== from) {
2956
+ if (isConnected(root)) return json(res, 409, { error: "disconnect before renaming boards - comment sync is board-keyed" });
2957
+ if (existsSync(join(root, "design", "comments", `${from}.jsonl`))) return json(res, 409, { error: "rename a board before commenting on it - this board has threads" });
3231
2958
  if (nodeExists$1(toPath)) return json(res, 409, { error: `a board named "${to}" already exists` });
3232
- renameSync(fromPath, toPath);
3233
- return json(res, 200, { name: to });
2959
+ try {
2960
+ if (next !== void 0) writeFileSync(toPath, next, { flag: "wx" });
2961
+ else linkSync(fromPath, toPath);
2962
+ } catch (err) {
2963
+ const code = err.code;
2964
+ if (code === "EEXIST") return json(res, 409, { error: `a board named "${to}" already exists` });
2965
+ if (next !== void 0 || code !== "EPERM" && code !== "ENOSYS" && code !== "ENOTSUP" && code !== "EOPNOTSUPP") throw err;
2966
+ if (nodeExists$1(toPath)) return json(res, 409, { error: `a board named "${to}" already exists` });
2967
+ renameSync(fromPath, toPath);
2968
+ return json(res, 200, { name: to });
2969
+ }
2970
+ rmSync(fromPath);
2971
+ return json(res, 200, {
2972
+ name: to,
2973
+ ...next !== void 0 ? { sha256: hash(next) } : {}
2974
+ });
3234
2975
  }
3235
- rmSync(fromPath);
2976
+ atomicWrite(toPath, next);
3236
2977
  return json(res, 200, {
3237
2978
  name: to,
3238
- ...next !== void 0 ? { sha256: hash(next) } : {}
2979
+ sha256: hash(next)
3239
2980
  });
2981
+ } finally {
2982
+ unlock();
3240
2983
  }
3241
- atomicWrite(toPath, next);
3242
- return json(res, 200, {
3243
- name: to,
3244
- sha256: hash(next)
3245
- });
3246
2984
  }
3247
2985
  if (path === "scenes/rename" && req.method === "POST") {
3248
2986
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
@@ -3380,41 +3118,54 @@ function apiMiddleware(root, opts = {}) {
3380
3118
  stale
3381
3119
  });
3382
3120
  const sha256 = {};
3383
- for (const w of plan) {
3384
- if (w.obj.order === w.order && (w.folder ? w.obj.folder === w.folder : w.obj.folder === void 0)) continue;
3385
- if (hash(readFileSync(w.path, "utf8")) !== b.boards[w.name]) return reply(409, {
3386
- error: "boards changed on disk",
3387
- stale: [w.name]
3121
+ const writes = plan.filter((w) => !(w.obj.order === w.order && (w.folder ? w.obj.folder === w.folder : w.obj.folder === void 0)));
3122
+ const unlocks = [];
3123
+ try {
3124
+ for (const w of writes) {
3125
+ const u = tryFileLock(boardLock(boardsDir, w.name));
3126
+ if (!u) return reply(409, {
3127
+ error: "boards changed on disk",
3128
+ stale: [w.name]
3129
+ });
3130
+ unlocks.push(u);
3131
+ }
3132
+ for (const w of writes) {
3133
+ if (hash(readFileSync(w.path, "utf8")) !== b.boards[w.name]) return reply(409, {
3134
+ error: "boards changed on disk",
3135
+ stale: [w.name]
3136
+ });
3137
+ w.obj.order = w.order;
3138
+ if (w.folder) w.obj.folder = w.folder;
3139
+ else delete w.obj.folder;
3140
+ const next = JSON.stringify(w.obj, null, 2) + "\n";
3141
+ atomicWrite(w.path, next);
3142
+ sha256[w.name] = hash(next);
3143
+ }
3144
+ mkdirSync(boardsDir, { recursive: true });
3145
+ if ((nodeExists(foldersPath) ? hash(readFileSync(foldersPath, "utf8")) : null) !== b.folders) return reply(409, {
3146
+ error: "folders changed on disk",
3147
+ stale: [FOLDERS_FILE]
3148
+ });
3149
+ let foldersSha = null;
3150
+ if (folders.length) {
3151
+ const version = folders.some((f) => f.parent) ? 2 : 1;
3152
+ const next = JSON.stringify({
3153
+ version,
3154
+ folders
3155
+ }, null, 2) + "\n";
3156
+ atomicWrite(foldersPath, next);
3157
+ foldersSha = hash(next);
3158
+ } else rmSync(foldersPath, { force: true });
3159
+ return reply(200, {
3160
+ ok: true,
3161
+ sha256: {
3162
+ boards: sha256,
3163
+ folders: foldersSha
3164
+ }
3388
3165
  });
3389
- w.obj.order = w.order;
3390
- if (w.folder) w.obj.folder = w.folder;
3391
- else delete w.obj.folder;
3392
- const next = JSON.stringify(w.obj, null, 2) + "\n";
3393
- atomicWrite(w.path, next);
3394
- sha256[w.name] = hash(next);
3166
+ } finally {
3167
+ for (const u of unlocks) u();
3395
3168
  }
3396
- mkdirSync(boardsDir, { recursive: true });
3397
- if ((nodeExists(foldersPath) ? hash(readFileSync(foldersPath, "utf8")) : null) !== b.folders) return reply(409, {
3398
- error: "folders changed on disk",
3399
- stale: [FOLDERS_FILE]
3400
- });
3401
- let foldersSha = null;
3402
- if (folders.length) {
3403
- const version = folders.some((f) => f.parent) ? 2 : 1;
3404
- const next = JSON.stringify({
3405
- version,
3406
- folders
3407
- }, null, 2) + "\n";
3408
- atomicWrite(foldersPath, next);
3409
- foldersSha = hash(next);
3410
- } else rmSync(foldersPath, { force: true });
3411
- return reply(200, {
3412
- ok: true,
3413
- sha256: {
3414
- boards: sha256,
3415
- folders: foldersSha
3416
- }
3417
- });
3418
3169
  });
3419
3170
  if (!locked) return json(res, 409, {
3420
3171
  error: "folders changed on disk",
@@ -3450,32 +3201,39 @@ function apiMiddleware(root, opts = {}) {
3450
3201
  error: "board no longer exists on disk",
3451
3202
  gone: true
3452
3203
  });
3453
- const current = existsSync(p) ? readFileSync(p, "utf8") : "";
3454
- if (current && body.baseHash !== hash(current)) {
3455
- let disk = null;
3456
- try {
3457
- disk = JSON.parse(current);
3204
+ mkdirSync(boardsDir, { recursive: true });
3205
+ const unlock = await takeFileLock(boardLock(boardsDir, boardMatch[1]), 2e3);
3206
+ if (!unlock) return json(res, 503, { error: "the board is being written - try again" });
3207
+ try {
3208
+ const current = existsSync(p) ? readFileSync(p, "utf8") : "";
3209
+ if (current && body.baseHash !== hash(current)) {
3210
+ let disk = null;
3211
+ try {
3212
+ disk = JSON.parse(current);
3213
+ } catch {}
3214
+ return json(res, 409, {
3215
+ error: "board changed on disk",
3216
+ board: disk,
3217
+ sha256: hash(current)
3218
+ });
3219
+ }
3220
+ mkdirSync(boardsDir, { recursive: true });
3221
+ const incoming = body.board;
3222
+ if (incoming && typeof incoming === "object" && current) try {
3223
+ const disk = JSON.parse(current);
3224
+ const valid = boardFields(disk, validName);
3225
+ for (const k of AUTHOR_FIELDS) if (incoming[k] === void 0 && valid[k] !== void 0) incoming[k] = disk[k];
3458
3226
  } catch {}
3459
- return json(res, 409, {
3460
- error: "board changed on disk",
3461
- board: disk,
3462
- sha256: hash(current)
3463
- });
3227
+ const next2 = JSON.stringify(body.board, null, 2) + "\n";
3228
+ atomicWrite(p, next2);
3229
+ return json(res, 200, { sha256: hash(next2) });
3230
+ } finally {
3231
+ unlock();
3464
3232
  }
3465
- mkdirSync(boardsDir, { recursive: true });
3466
- const incoming = body.board;
3467
- if (incoming && typeof incoming === "object" && current) try {
3468
- const disk = JSON.parse(current);
3469
- const valid = boardFields(disk, validName);
3470
- for (const k of AUTHOR_FIELDS) if (incoming[k] === void 0 && valid[k] !== void 0) incoming[k] = disk[k];
3471
- } catch {}
3472
- const next2 = JSON.stringify(body.board, null, 2) + "\n";
3473
- atomicWrite(p, next2);
3474
- return json(res, 200, { sha256: hash(next2) });
3475
3233
  }
3476
3234
  }
3477
3235
  if (path === "shot" && req.method === "GET") {
3478
- const { readDevInfo } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
3236
+ const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
3479
3237
  const token = readDevInfo(root)?.token;
3480
3238
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
3481
3239
  const frameId = url.searchParams.get("frame") ?? "";
@@ -3491,7 +3249,7 @@ function apiMiddleware(root, opts = {}) {
3491
3249
  };
3492
3250
  const asPng = url.searchParams.get("format") === "png";
3493
3251
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
3494
- const { shootFrame } = await import("./shot-Ch24tiMO.mjs").then((n) => n.u);
3252
+ const { shootFrame } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
3495
3253
  const r = await shootFrame({
3496
3254
  root,
3497
3255
  viewports: opts.viewports ?? {},
@@ -3525,7 +3283,7 @@ function apiMiddleware(root, opts = {}) {
3525
3283
  return res.end(png);
3526
3284
  }
3527
3285
  if (path === "shots" && req.method === "POST") {
3528
- const { readDevInfo } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
3286
+ const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
3529
3287
  const token = readDevInfo(root)?.token;
3530
3288
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
3531
3289
  const raw = await readBody(req);
@@ -3542,7 +3300,7 @@ function apiMiddleware(root, opts = {}) {
3542
3300
  if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
3543
3301
  const scale = body.scale === void 0 ? void 0 : body.scale;
3544
3302
  if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
3545
- const { resolveFrames, shootBatch } = await import("./shot-Ch24tiMO.mjs").then((n) => n.u);
3303
+ const { resolveFrames, shootBatch } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
3546
3304
  const sel = resolveFrames(root, body);
3547
3305
  if (!sel.ok) return json(res, sel.status, { error: sel.error });
3548
3306
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
@@ -3560,7 +3318,7 @@ function apiMiddleware(root, opts = {}) {
3560
3318
  }
3561
3319
  }
3562
3320
  if (path === "anchor" && req.method === "POST") {
3563
- const { readDevInfo } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
3321
+ const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
3564
3322
  const token = readDevInfo(root)?.token;
3565
3323
  if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
3566
3324
  const raw = await readBody(req);
@@ -3576,7 +3334,7 @@ function apiMiddleware(root, opts = {}) {
3576
3334
  if (typeof target === "string") return json(res, 400, { error: target });
3577
3335
  const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
3578
3336
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
3579
- const { checkAnchor, CheckInputError } = await import("./anchor-check-gkxkPAIv.mjs");
3337
+ const { checkAnchor, CheckInputError } = await import("./anchor-check-PHUOFj1N.mjs");
3580
3338
  try {
3581
3339
  return json(res, 200, await checkAnchor({
3582
3340
  root,
@@ -3626,7 +3384,7 @@ function apiMiddleware(root, opts = {}) {
3626
3384
  });
3627
3385
  docs.push(typeof a?.doc === "string" ? a.doc : void 0);
3628
3386
  }
3629
- const { docRev } = await import("./marks-CnCCfAbD.mjs").then((n) => n.i);
3387
+ const { docRev } = await import("./marks-Kmdab_5w.mjs").then((n) => n.i);
3630
3388
  const all = devManifest().frames;
3631
3389
  const pending = opts.settled ? !opts.settled() : false;
3632
3390
  const behind = docs.map((d, i) => d !== void 0 && (pending || d !== docRev(root, all, asks[i].frame)));
@@ -3684,8 +3442,8 @@ function apiMiddleware(root, opts = {}) {
3684
3442
  return json(res, 400, { error: "malformed JSON" });
3685
3443
  }
3686
3444
  const src = typeof b?.src === "string" ? b.src : "";
3687
- const { ensurePoster, isLocalClip } = await import("./poster-BNgafWMK.mjs");
3688
- const { isLocalAssetRef } = await import("./build-VgNg4rr8.mjs");
3445
+ const { ensurePoster, isLocalClip } = await import("./poster-DHi6I1fO.mjs");
3446
+ const { isLocalAssetRef } = await import("./build-BsAyLMT1.mjs");
3689
3447
  if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
3690
3448
  const r = await ensurePoster(join(root, "design", "assets"), src);
3691
3449
  if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
@@ -3728,7 +3486,7 @@ function apiMiddleware(root, opts = {}) {
3728
3486
  }
3729
3487
  if (path === "marks" || path === "marks/seen") {
3730
3488
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3731
- const { readMarks, markSeen } = await import("./marks-CnCCfAbD.mjs").then((n) => n.i);
3489
+ const { readMarks, markSeen } = await import("./marks-Kmdab_5w.mjs").then((n) => n.i);
3732
3490
  const manifest = devManifest();
3733
3491
  if (path === "marks" && req.method === "GET") return json(res, 200, readMarks(root, manifest));
3734
3492
  if (path === "marks/seen" && req.method === "POST") {
@@ -3748,14 +3506,14 @@ function apiMiddleware(root, opts = {}) {
3748
3506
  return json(res, 405, { error: "method not allowed" });
3749
3507
  }
3750
3508
  if (path === "work") {
3751
- const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
3509
+ const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
3752
3510
  const tokenOk = () => {
3753
3511
  const t = readDevInfo(root)?.token;
3754
3512
  return !!t && req.headers["x-mv-work"] === t;
3755
3513
  };
3756
3514
  if (req.method === "GET") {
3757
3515
  if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
3758
- const { boardsShowing, activityClock } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
3516
+ const { boardsShowing, activityClock } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
3759
3517
  const frames = workActivity.active();
3760
3518
  return json(res, 200, {
3761
3519
  frames,
@@ -3778,7 +3536,7 @@ function apiMiddleware(root, opts = {}) {
3778
3536
  if (!on && b.all === true) {
3779
3537
  const done = workActivity.active().filter((f) => workActivity.has(f, "cli"));
3780
3538
  if (done.length) {
3781
- (await import("./marks-CnCCfAbD.mjs").then((n) => n.i)).recordChanged(root, devFrames(), done, { doc: false });
3539
+ (await import("./marks-Kmdab_5w.mjs").then((n) => n.i)).recordChanged(root, devFrames(), done, { doc: false });
3782
3540
  opts.notify?.("sh:marks");
3783
3541
  }
3784
3542
  workActivity.clearAll("cli");
@@ -3798,7 +3556,7 @@ function apiMiddleware(root, opts = {}) {
3798
3556
  for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
3799
3557
  saveHolds(root, workActivity);
3800
3558
  if (!on) {
3801
- (await import("./marks-CnCCfAbD.mjs").then((n) => n.i)).recordChanged(root, devFrames(), frames, { doc: false });
3559
+ (await import("./marks-Kmdab_5w.mjs").then((n) => n.i)).recordChanged(root, devFrames(), frames, { doc: false });
3802
3560
  opts.notify?.("sh:marks");
3803
3561
  return json(res, 200, { frames: workActivity.active() });
3804
3562
  }
@@ -3837,7 +3595,8 @@ function apiMiddleware(root, opts = {}) {
3837
3595
  const { jamLive } = await import("./live-Cgzsicwi.mjs");
3838
3596
  return json(res, 200, jamLive.view?.() ?? {
3839
3597
  agent: null,
3840
- cards: []
3598
+ cards: [],
3599
+ unavailable: true
3841
3600
  });
3842
3601
  }
3843
3602
  if (path === "jam/card" && req.method === "POST") {
@@ -3850,7 +3609,7 @@ function apiMiddleware(root, opts = {}) {
3850
3609
  } catch {
3851
3610
  return json(res, 400, { error: "malformed JSON" });
3852
3611
  }
3853
- const { ACTIONS } = await import("./queue-CAM_vNmX.mjs");
3612
+ const { ACTIONS } = await import("./queue-c-6aTHEz.mjs");
3854
3613
  if (!b || typeof b.id !== "string" || !Number.isInteger(b.rev) || !ACTIONS.includes(b.action) || b.body !== void 0 && typeof b.body !== "string") return json(res, 400, { error: "expected { id, rev, action, body? }" });
3855
3614
  if ("kind" in b) return json(res, 400, { error: "a capture has no category" });
3856
3615
  const { jamLive } = await import("./live-Cgzsicwi.mjs");
@@ -3860,13 +3619,13 @@ function apiMiddleware(root, opts = {}) {
3860
3619
  }
3861
3620
  if (path === "jam/audio-ticket" && req.method === "POST") {
3862
3621
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3863
- const { issueTicket, speechLive } = await import("./audio-Dw1lfMdb.mjs");
3622
+ const { issueTicket, speechLive } = await import("./audio-DX4POHAj.mjs");
3864
3623
  if (!speechLive.svc) return json(res, 409, { error: "jam is not running here" });
3865
3624
  return json(res, 200, { ticket: issueTicket() });
3866
3625
  }
3867
3626
  if (path === "jam/voice" && (req.method === "GET" || req.method === "POST")) {
3868
3627
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3869
- const { speechLive } = await import("./audio-Dw1lfMdb.mjs");
3628
+ const { speechLive } = await import("./audio-DX4POHAj.mjs");
3870
3629
  const { downloadModels, downloadState, DOWNLOAD_MB } = await import("./speech-models-DomiLQcY.mjs");
3871
3630
  if (!speechLive.svc) return json(res, 409, { error: "jam is not running here" });
3872
3631
  if (req.method === "POST") {
@@ -3895,7 +3654,7 @@ function apiMiddleware(root, opts = {}) {
3895
3654
  if (!jamLive.session || !jamLive.view) return json(res, 409, { error: "jam is not running here" });
3896
3655
  if (req.method === "GET") {
3897
3656
  const ses = jamLive.view().session ?? null;
3898
- const { readTalk, talkMinutes, recordFile } = await import("./session-BAaJsK5c.mjs").then((n) => n.s);
3657
+ const { readTalk, talkMinutes, recordFile } = await import("./session-DyVE7cCk.mjs").then((n) => n.s);
3899
3658
  const folder = ses ? recordFile(root, ses.since, ses.id).replace(/[^/]+$/, "") : null;
3900
3659
  return json(res, 200, {
3901
3660
  session: ses,
@@ -3926,7 +3685,7 @@ function apiMiddleware(root, opts = {}) {
3926
3685
  });
3927
3686
  }
3928
3687
  if (b.action !== "start") {
3929
- const { speechLive } = await import("./audio-Dw1lfMdb.mjs");
3688
+ const { speechLive } = await import("./audio-DX4POHAj.mjs");
3930
3689
  if (!await (speechLive.svc?.finishTalk(b.id) ?? Promise.resolve(true)).catch(() => false) && b.action === "wrapup" && b.includeTalk !== false) return json(res, 409, {
3931
3690
  ok: false,
3932
3691
  error: "what was said is still being written down - write the record again in a moment (or leave what was said out)"
@@ -3943,8 +3702,95 @@ function apiMiddleware(root, opts = {}) {
3943
3702
  action: b.action,
3944
3703
  id: b.id
3945
3704
  });
3705
+ if (r.ok && b.action === "start") {
3706
+ const { ensureConnectors } = await import("./connectors-MR9d-EBP.mjs");
3707
+ const connectors = ensureConnectors(root);
3708
+ jamLive.connectors = connectors;
3709
+ return json(res, 200, {
3710
+ ...r,
3711
+ connectors
3712
+ });
3713
+ }
3946
3714
  return json(res, r.ok ? 200 : 409, r);
3947
3715
  }
3716
+ if (path === "jam/run" && req.method === "POST") {
3717
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3718
+ const raw = await readBody(req);
3719
+ if (raw == null) return json(res, 400, { error: "body too large" });
3720
+ let b;
3721
+ try {
3722
+ b = JSON.parse(raw);
3723
+ } catch {
3724
+ return json(res, 400, { error: "malformed JSON" });
3725
+ }
3726
+ if (!b || typeof b.batch !== "string" || !Number.isInteger(b.gen) || ![
3727
+ "again",
3728
+ "background",
3729
+ "drop"
3730
+ ].includes(b.action)) return json(res, 400, { error: "expected { batch, gen, action }" });
3731
+ const { jamLive } = await import("./live-Cgzsicwi.mjs");
3732
+ if (!jamLive.runAct) return json(res, 409, { error: "jam is not running here" });
3733
+ const r = await jamLive.runAct(b.batch, b.gen, b.action);
3734
+ jamLive.refresh?.();
3735
+ return json(res, r.ok ? 200 : 409, r);
3736
+ }
3737
+ if (path === "jam/prefs" && (req.method === "GET" || req.method === "POST")) {
3738
+ if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3739
+ const { readPrefs, writePrefs, validConnId } = await import("./conn-BMiHS42T.mjs").then((n) => n.a);
3740
+ const { ensureConnectors, present } = await import("./connectors-MR9d-EBP.mjs");
3741
+ const { jamLive } = await import("./live-Cgzsicwi.mjs");
3742
+ const tools = [
3743
+ "claude",
3744
+ "codex",
3745
+ "cursor"
3746
+ ].filter((a) => present(a));
3747
+ if (req.method === "GET") return json(res, 200, {
3748
+ prefs: readPrefs(root),
3749
+ tools,
3750
+ connectors: jamLive.connectors ?? []
3751
+ });
3752
+ const raw = await readBody(req);
3753
+ if (raw == null) return json(res, 400, { error: "body too large" });
3754
+ let b;
3755
+ try {
3756
+ b = JSON.parse(raw);
3757
+ } catch {
3758
+ return json(res, 400, { error: "malformed JSON" });
3759
+ }
3760
+ if (!b || typeof b !== "object") return json(res, 400, { error: "expected { mcp?, skills?, context?, others?, pick?, tool? }" });
3761
+ const p = readPrefs(root);
3762
+ for (const k of [
3763
+ "mcp",
3764
+ "skills",
3765
+ "others"
3766
+ ]) if (typeof b[k] === "boolean") p[k] = b[k];
3767
+ if (b.context === "fork" || b.context === "fresh") p.context = b.context;
3768
+ if (b.pick === null) delete p.pick;
3769
+ else if (validConnId(b.pick)) p.pick = b.pick;
3770
+ let force = [];
3771
+ if (b.tool && [
3772
+ "claude",
3773
+ "codex",
3774
+ "cursor"
3775
+ ].includes(b.tool.agent) && typeof b.tool.on === "boolean") {
3776
+ p.off = {
3777
+ ...p.off ?? {},
3778
+ [b.tool.agent]: !b.tool.on
3779
+ };
3780
+ if (b.tool.on) {
3781
+ delete p.off[b.tool.agent];
3782
+ force = [b.tool.agent];
3783
+ }
3784
+ }
3785
+ writePrefs(root, p);
3786
+ if (force.length) jamLive.connectors = ensureConnectors(root, { force });
3787
+ jamLive.refresh?.();
3788
+ return json(res, 200, {
3789
+ prefs: p,
3790
+ tools,
3791
+ connectors: jamLive.connectors ?? []
3792
+ });
3793
+ }
3948
3794
  if (path === "jam/capture-open" && req.method === "POST") {
3949
3795
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3950
3796
  const raw = await readBody(req);
@@ -3987,7 +3833,7 @@ function apiMiddleware(root, opts = {}) {
3987
3833
  }
3988
3834
  if (path === "jam/capture" && req.method === "GET") {
3989
3835
  if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
3990
- const { readCapture } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
3836
+ const { readCapture } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
3991
3837
  const id = url.searchParams.get("id") ?? "";
3992
3838
  const cap = readCapture(root, id);
3993
3839
  if (!cap) return json(res, 404, { error: "no such capture" });
@@ -4010,11 +3856,11 @@ function apiMiddleware(root, opts = {}) {
4010
3856
  } catch {
4011
3857
  return json(res, 400, { error: "malformed JSON" });
4012
3858
  }
4013
- const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
3859
+ const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
4014
3860
  if (!b || typeof b.capture !== "string" || !CAPTURE_ID.test(b.capture) || typeof b.frame !== "string") return json(res, 400, { error: "expected { capture, frame, theme?, viewport? }" });
4015
3861
  if (readCapture(root, b.capture)) return json(res, 409, { error: "that capture is sealed" });
4016
3862
  const theme = typeof b.theme === "string" && /^[a-z0-9-]+$/i.test(b.theme) ? b.theme : "light";
4017
- const { shootFrame } = await import("./shot-Ch24tiMO.mjs").then((n) => n.u);
3863
+ const { shootFrame } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
4018
3864
  const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
4019
3865
  const vp = typeof b.viewport === "string" ? opts.viewports?.[b.viewport] : void 0;
4020
3866
  const dim = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
@@ -4031,6 +3877,7 @@ function apiMiddleware(root, opts = {}) {
4031
3877
  frameId: b.frame,
4032
3878
  theme,
4033
3879
  origin,
3880
+ lane: "picture",
4034
3881
  ...size ? { size } : {}
4035
3882
  });
4036
3883
  if (!r.ok) return json(res, r.error.startsWith("unknown frame") ? 404 : 503, { error: r.error });
@@ -4048,7 +3895,7 @@ function apiMiddleware(root, opts = {}) {
4048
3895
  if (path === "jam/picture" && req.method === "GET") {
4049
3896
  const site = String(req.headers["sec-fetch-site"] ?? "");
4050
3897
  if (!ownerGated(req) && !(cookie(req, "mv_c") && (site === "same-origin" || site === "none"))) return json(res, 403, { error: "forbidden" });
4051
- const { picturePath } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
3898
+ const { picturePath } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
4052
3899
  const p = picturePath(root, url.searchParams.get("id") ?? "");
4053
3900
  if (!p) return json(res, 404, { error: "no such picture" });
4054
3901
  const png = readFileSync(p.path);
@@ -5118,7 +4965,7 @@ function marverPlugin(ctx) {
5118
4965
  });
5119
4966
  return;
5120
4967
  }
5121
- const { shootFrame, shootBatch, resolveFrames } = await import("./shot-Ch24tiMO.mjs").then((n) => n.u);
4968
+ const { shootFrame, shootBatch, resolveFrames } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
5122
4969
  if (ways[0] === "frame") {
5123
4970
  if (typeof spec.frame !== "string") {
5124
4971
  write({
@@ -5239,4 +5086,4 @@ async function tailwind3Css(root) {
5239
5086
  return null;
5240
5087
  }
5241
5088
  //#endregion
5242
- export { installedVersion as a, autoWidthOf as c, readSizes as d, loadConfig as f, publishLogo as i, keptSizes as l, tailwind3Css as n, ASK_MAX as o, tailwind4Plugin as r, bakeBatch as s, marverPlugin as t, measuringFrames as u };
5089
+ export { installedVersion as a, publishLogo as i, tailwind3Css as n, ASK_MAX as o, tailwind4Plugin as r, bakeBatch as s, marverPlugin as t };