@marver-design/marver 0.22.1 → 0.23.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 (61) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +13 -9
  3. package/dist/agent-BsieQGTD.mjs +99 -0
  4. package/dist/{bake-CvY8QR3L.mjs → bake-l6N12qgx.mjs} +1 -1
  5. package/dist/{board-status-CWGHIdo_.mjs → board-status-D_lHZZ09.mjs} +69 -610
  6. package/dist/{boards-BwKI0qWd.mjs → boards-CahYhF5B.mjs} +2 -1
  7. package/dist/boards-DbVJlbd5.mjs +612 -0
  8. package/dist/{build-B1kavcpc.mjs → build-CuRhHXcY.mjs} +10 -6
  9. package/dist/cli.mjs +20 -11
  10. package/dist/{comments-ClVgfQib.mjs → comments-0d3e274b.mjs} +71 -9
  11. package/dist/{config-DJxMRVD8.mjs → config-g-J8NrPn.mjs} +5 -97
  12. package/dist/{context-D4t59wDi.mjs → context-fAtQLHt2.mjs} +3 -2
  13. package/dist/{daemon-PmNqoOAk.mjs → daemon-DZ367fiM.mjs} +75 -17
  14. package/dist/{dev-Cf4wLGe2.mjs → dev-R6zvwbqX.mjs} +50 -10
  15. package/dist/{init-C_K-cjBQ.mjs → init-DAnBlt-V.mjs} +4 -3
  16. package/dist/{ledger-Bu0BjqIe.mjs → ledger-BNXW14Xw.mjs} +1 -6
  17. package/dist/link-CcfAfKY-.mjs +132 -0
  18. package/dist/{manifest-CcdWx7ud.mjs → manifest-BkjJ5OQk.mjs} +50 -5
  19. package/dist/{plugin-C5u07Yhv.mjs → plugin-C1avHL7g.mjs} +357 -31
  20. package/dist/{poster-BduzQBYz.mjs → poster-Bc4-3DlQ.mjs} +1 -1
  21. package/dist/{profile-BjAPAJSb.mjs → profile-CrZohD6g.mjs} +1 -1
  22. package/dist/{publish-bakes-b0jUwvM_.mjs → publish-bakes-DQWn14IY.mjs} +2 -2
  23. package/dist/{share--bdSc4G5.mjs → share-BD-wcDQq.mjs} +1 -1
  24. package/dist/{shot-BFEuYbaz.mjs → shot-C1YR_Sqx.mjs} +1 -1
  25. package/dist/{shot-BAR8hmU9.mjs → shot-CVOlQHUr.mjs} +2 -2
  26. package/dist/{sync-BZaCWqK-.mjs → sync-DoA1vf4u.mjs} +15 -1
  27. package/dist/{work-0YopuMt9.mjs → work-CJ8OIpBD.mjs} +9 -3
  28. package/dist/{work-CLrmY-vQ.mjs → work-CiUvBVa6.mjs} +72 -1
  29. package/docs/boards-and-folders.md +54 -6
  30. package/docs/context.md +10 -2
  31. package/docs/live-jam.md +11 -0
  32. package/package.json +1 -1
  33. package/src/client/content/diagram.tsx +7 -1
  34. package/src/client/content/img-lod.ts +12 -2
  35. package/src/client/content/index.tsx +69 -6
  36. package/src/client/frame-host/inspect.js +23 -0
  37. package/src/client/shell/App.tsx +19 -9
  38. package/src/client/shell/BoardList.tsx +21 -6
  39. package/src/client/shell/LockedApp.tsx +2 -2
  40. package/src/client/shell/Play.tsx +5 -1
  41. package/src/client/shell/StatusPicker.tsx +12 -5
  42. package/src/client/shell/Tip.tsx +25 -5
  43. package/src/client/shell/board-icons.tsx +15 -1
  44. package/src/client/shell/canvas/Canvas.tsx +42 -6
  45. package/src/client/shell/canvas/anchor.ts +41 -0
  46. package/src/client/shell/canvas/ctl.ts +6 -0
  47. package/src/client/shell/comments-store.ts +8 -5
  48. package/src/client/shell/goto.ts +52 -3
  49. package/src/client/shell/hash.ts +24 -3
  50. package/src/client/shell/store.ts +242 -28
  51. package/src/client/shell/styles.css +19 -2
  52. package/src/shared/board-types.ts +10 -6
  53. package/src/shared/status.ts +17 -8
  54. package/templates/AGENTS-embedded.md +43 -8
  55. package/templates/AGENTS-studio.md +43 -8
  56. package/templates/instructions/boards.md +13 -3
  57. package/templates/instructions/context.md +6 -2
  58. package/templates/instructions/iterate.md +29 -16
  59. package/templates/instructions/jam.md +9 -2
  60. package/templates/instructions/reference/deck-layouts.md +2 -1
  61. package/templates/instructions/reference/deck-story.md +2 -1
@@ -1,5 +1,6 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { $ as readCapability, B as folderMap, D as boardFields, E as addFolders, H as isBoardName, J as FOLDER_MODULES, L as buildTree, N as readRegistry, O as checkBoardsDir, Q as knownType, R as flatten, V as humanize, a as STATUS_LABEL, j as listBoardFiles, k as checkRealDirs, q as BOARD_TYPES, r as PHASE_LABEL, rt as resolveType, t as annotateBoards } from "./board-status-CWGHIdo_.mjs";
2
+ import { A as readCapability, C as BOARD_TYPES, P as resolveType, T as FOLDER_MODULES, _ as humanize, a as checkRealDirs, g as folderMap, i as checkBoardsDir, k as knownType, l as readRegistry, m as flatten, n as addFolders, p as buildTree, r as boardFields, s as listBoardFiles, v as isBoardName } from "./boards-DbVJlbd5.mjs";
3
+ import { a as PHASE_LABEL, s as STATUS_LABEL, t as annotateBoards } from "./board-status-D_lHZZ09.mjs";
3
4
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
4
5
  import { join } from "node:path";
5
6
  //#region src/cli/boards.ts
@@ -0,0 +1,612 @@
1
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import { join, sep } from "node:path";
3
+ import { createHash } from "node:crypto";
4
+ //#region src/server/hash.ts
5
+ /** sha256 hex of a string - the CAS token for board files, the registry, the manifest. */
6
+ const hash = (s) => createHash("sha256").update(s).digest("hex");
7
+ //#endregion
8
+ //#region src/shared/board-types.ts
9
+ /**
10
+ * Board types (spec 20) - what a board is FOR in the workspace, one vocabulary every canvas
11
+ * shares so any sidebar reads at a glance. A board states its own `"type"`, or wears the type of
12
+ * the nearest typed folder above it (its folder, then that folder's parent), else it is plain.
13
+ * Moving a board changes an inherited type, never one the board states itself.
14
+ *
15
+ * Pure and shared: the dev API, the manifest, the build, the shell and the CLI all read types
16
+ * through here, so a type means one thing everywhere.
17
+ */
18
+ const BOARD_TYPES = [
19
+ "start",
20
+ "feature",
21
+ "surface",
22
+ "project",
23
+ "feedback",
24
+ "context",
25
+ "deck",
26
+ "archive"
27
+ ];
28
+ /** The grammar a stored type keeps to. Any on-grammar word survives a write - a newer Marver's
29
+ * type is never dropped by an older shell - while only the known ones are drawn. */
30
+ const TYPE_GRAMMAR = /^[a-z][a-z-]{0,31}$/;
31
+ /** A type off a file: the word when it is on-grammar, else absent. */
32
+ const readType = (v) => typeof v === "string" && TYPE_GRAMMAR.test(v) ? v : void 0;
33
+ /** A type this Marver draws. */
34
+ const knownType = (v) => BOARD_TYPES.includes(v) ? v : void 0;
35
+ /** A board's type: its own when it states one (an unknown word reads as plain - the board spoke
36
+ * for itself), else its folder's, else that folder's parent's, else plain. */
37
+ function resolveType(own, folder, parent) {
38
+ if (readType(own)) return knownType(own) ?? "plain";
39
+ return knownType(folder) ?? knownType(parent) ?? "plain";
40
+ }
41
+ /** The publish type a board's type proposes when its publish row names none - how a board
42
+ * PRESENTS when published, a separate question from what it is for. */
43
+ const PROPOSED_PUBLISH = {
44
+ deck: "slides",
45
+ context: "refs",
46
+ project: "doc",
47
+ feature: "mix",
48
+ surface: "mix"
49
+ };
50
+ /** The types that carry a status (spec 20, open question 2: features and projects - the others
51
+ * have no lifecycle of their own). */
52
+ const HAS_STATUS = ["feature", "project"];
53
+ /** The decisions a board may state by hand. `done` is never one: Done comes only from the shipped
54
+ * record. `todo`, `backlog`, `in-progress` and `building` count only where there is no `context/`. */
55
+ const DECISIONS = [
56
+ "archived",
57
+ "paused",
58
+ "blocked"
59
+ ];
60
+ const BY_HAND = [
61
+ "in-progress",
62
+ "building",
63
+ "todo",
64
+ "backlog"
65
+ ];
66
+ const STATUS_WORDS = [
67
+ ...DECISIONS,
68
+ ...BY_HAND,
69
+ "done"
70
+ ];
71
+ const readStatusWord = (v) => STATUS_WORDS.includes(v) ? v : void 0;
72
+ /** The statuses a person may set on a feature or project board, in the order a picker lists them:
73
+ * the three decisions always; Backlog, To do, In progress and Building where there is no `context/`
74
+ * (with it they are read from the evidence). With it, In progress and Building where an open plan
75
+ * names the capability - choosing one writes that plan's `stage`, the evidence they are read from.
76
+ * Never Done - that is the shipped record's alone. */
77
+ const settableStatuses = (contextPresent, openPlan = false) => contextPresent ? [
78
+ ...openPlan ? ["in-progress", "building"] : [],
79
+ "blocked",
80
+ "paused",
81
+ "archived"
82
+ ] : [
83
+ "backlog",
84
+ "todo",
85
+ "in-progress",
86
+ "building",
87
+ "blocked",
88
+ "paused",
89
+ "archived"
90
+ ];
91
+ /** A capability slug - the same grammar as a board name, so a feature board and its contract
92
+ * share it. */
93
+ const readCapability = (v) => typeof v === "string" && /^[a-z0-9][a-z0-9-]{0,63}$/.test(v) ? v : void 0;
94
+ const readReason = (v) => {
95
+ if (typeof v !== "string") return void 0;
96
+ return v.trim().replace(/\s+/g, " ").slice(0, 300) || void 0;
97
+ };
98
+ /** The sidebar every canvas shares (spec 19, The canvas): folder modules, each typed, so a board
99
+ * made inside one wears its type. `marver init --kind` creates a kind's set on a fresh canvas;
100
+ * `marver folders add <module>` adds one later. Names are slugs; only Start here needs a title. */
101
+ const FOLDER_MODULES = {
102
+ start: {
103
+ name: "start-here",
104
+ title: "Start here",
105
+ type: "start"
106
+ },
107
+ features: {
108
+ name: "features",
109
+ type: "feature"
110
+ },
111
+ surfaces: {
112
+ name: "surfaces",
113
+ type: "surface"
114
+ },
115
+ projects: {
116
+ name: "projects",
117
+ type: "project"
118
+ },
119
+ feedback: {
120
+ name: "feedback",
121
+ type: "feedback"
122
+ },
123
+ context: {
124
+ name: "context",
125
+ type: "context"
126
+ },
127
+ decks: {
128
+ name: "decks",
129
+ type: "deck"
130
+ },
131
+ archive: {
132
+ name: "archive",
133
+ type: "archive"
134
+ }
135
+ };
136
+ /** A kind of work's folders, in sidebar order: the core (Start here, Feedback, Context, Archive)
137
+ * around the kind's own modules. Decks are an add-on for either. */
138
+ const KIND_FOLDERS = {
139
+ product: [
140
+ "start",
141
+ "features",
142
+ "surfaces",
143
+ "feedback",
144
+ "context",
145
+ "archive"
146
+ ],
147
+ knowledge: [
148
+ "start",
149
+ "projects",
150
+ "feedback",
151
+ "context",
152
+ "archive"
153
+ ]
154
+ };
155
+ //#endregion
156
+ //#region src/shared/board-tree.ts
157
+ /**
158
+ * Board folders - the pure tree shared by the sidebar, the dev API, the build and the
159
+ * tests. Files are the truth: a board says which folder it sits in (`folder` on the
160
+ * board file - one slug, the folder it sits in directly), ranked among its siblings by
161
+ * `order`, and `design/boards/_folders.json` says which folders exist, where they rank, and
162
+ * which folder holds which (`parent`). Two levels: a folder holds boards and folders, a
163
+ * folder inside a folder (a sub-folder) holds boards only. `all-scenes` never enters the
164
+ * tree - callers pin it last.
165
+ */
166
+ /** The on-disk name grammar shared by boards and folders (a board name is a filename). */
167
+ const BOARD_NAME = /^[a-z0-9][a-z0-9-]*$/;
168
+ const isBoardName = (n) => typeof n === "string" && n.length >= 1 && n.length <= 64 && BOARD_NAME.test(n);
169
+ /** The folder registry beside the boards - underscore = infrastructure, never a board. */
170
+ const FOLDERS_FILE = "_folders.json";
171
+ /** Is this basename in design/boards/ a board file? `_folders.json`, temp files and any
172
+ * off-grammar name are not - every lister (dev API, build, watcher) shares this rule. */
173
+ const isBoardFile = (f) => f.endsWith(".json") && isBoardName(f.slice(0, -5));
174
+ const readDescription = (v) => {
175
+ if (typeof v !== "string") return void 0;
176
+ return v.trim().replace(/\s+/g, " ").slice(0, 300) || void 0;
177
+ };
178
+ const readTitle = (v) => {
179
+ if (typeof v !== "string") return void 0;
180
+ return Array.from(v.replace(/[\u0000-\u001f\u007f]/g, " ").trim().replace(/\s+/g, " ")).slice(0, 120).join("").trim() || void 0;
181
+ };
182
+ /** Title Case off a slug - the display when no title is set ("old-stuff" → "Old Stuff"). */
183
+ const humanize = (s) => s.replace(/-/g, " ").replace(/(^|\s)\S/g, (c) => c.toUpperCase());
184
+ const rank = (o) => typeof o === "number" && Number.isFinite(o) ? o : Infinity;
185
+ /** A folder's title, description and type, present only when set. */
186
+ const folderExtras = (it) => ({
187
+ ...it.title ? { title: it.title } : {},
188
+ ...it.description ? { description: it.description } : {},
189
+ ...readType(it.type) ? { type: it.type } : {}
190
+ });
191
+ /** The registry file's shape. Returns the rows, or a string naming what is wrong - a
192
+ * malformed registry is an ERROR the human must fix (silently reading it as empty, or
193
+ * flattening a broken nesting, would let the next drag overwrite their folders), while a
194
+ * missing file is simply no folders. */
195
+ function parseFolders(raw) {
196
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return "expected an object";
197
+ const { version, folders } = raw;
198
+ if (version !== void 0 && version !== 1 && version !== 2) return `unsupported version ${String(version)}`;
199
+ if (!Array.isArray(folders)) return "expected a \"folders\" array";
200
+ const out = [];
201
+ const seen = /* @__PURE__ */ new Set();
202
+ for (const f of folders) {
203
+ const name = f?.name;
204
+ if (!isBoardName(name)) return "a folder needs a name - lowercase letters, numbers and dashes";
205
+ if (seen.has(name)) return `folder "${name}" is listed twice`;
206
+ seen.add(name);
207
+ const o = f.order;
208
+ const p = f.parent;
209
+ if (p !== void 0 && !isBoardName(p)) return `folder "${name}" has an invalid parent - a folder name`;
210
+ const t = readTitle(f.title);
211
+ const d = readDescription(f.description);
212
+ const ty = readType(f.type);
213
+ out.push({
214
+ name,
215
+ ...typeof o === "number" && Number.isFinite(o) ? { order: o } : {},
216
+ ...p !== void 0 ? { parent: p } : {},
217
+ ...t ? { title: t } : {},
218
+ ...d ? { description: d } : {},
219
+ ...ty ? { type: ty } : {}
220
+ });
221
+ }
222
+ const byName = new Map(out.map((f) => [f.name, f]));
223
+ for (const f of out) {
224
+ if (f.parent === void 0) continue;
225
+ if (version !== 2) return `folder "${f.name}" names a parent - nested folders need "version": 2`;
226
+ if (f.parent === f.name) return `folder "${f.name}" cannot be its own parent`;
227
+ const p = byName.get(f.parent);
228
+ if (!p) return `folder "${f.name}" names an unknown parent "${f.parent}"`;
229
+ if (p.parent !== void 0) return `folder "${f.name}" would sit three levels deep - folders nest one level only`;
230
+ }
231
+ return out;
232
+ }
233
+ /** Sidebar order from the files. At every level the boards and folders there share one
234
+ * sequence, ranked by `order`, then kind (board before folder), then name; unranked sorts
235
+ * after ranked. The root holds root boards and top-level folders (registered without a
236
+ * parent, or implied by a board that names an unregistered folder); a top-level folder holds
237
+ * its boards and its sub-folders; a sub-folder holds its boards. A folder's title and
238
+ * description and type ride on its item (they live in the registry a tree write rewrites); a board's
239
+ * title stays with its row - it lives in the board's own file. */
240
+ function buildTree(boards, folders) {
241
+ const reg = /* @__PURE__ */ new Map();
242
+ for (const f of folders) if (isBoardName(f.name) && !reg.has(f.name)) reg.set(f.name, f);
243
+ const parentOf = (n) => {
244
+ const p = reg.get(n)?.parent;
245
+ return p !== void 0 && p !== n && reg.has(p) && reg.get(p).parent === void 0 ? p : void 0;
246
+ };
247
+ const members = /* @__PURE__ */ new Map();
248
+ const implied = [];
249
+ const rootBoards = [];
250
+ for (const b of boards) {
251
+ if (!isBoardName(b.name) || b.name === "all-scenes") continue;
252
+ const folder = isBoardName(b.folder) ? b.folder : void 0;
253
+ if (!folder) {
254
+ rootBoards.push(b);
255
+ continue;
256
+ }
257
+ if (!reg.has(folder) && !implied.includes(folder)) implied.push(folder);
258
+ const list = members.get(folder) ?? [];
259
+ list.push(b);
260
+ members.set(folder, list);
261
+ }
262
+ const sorted = (xs) => xs.sort((a, b) => rank(a.order) - rank(b.order) || (a.item.kind === b.item.kind ? 0 : a.item.kind === "board" ? -1 : 1) || a.item.name.localeCompare(b.item.name)).map((r) => r.item);
263
+ const boardsHere = (name) => (name === null ? rootBoards : members.get(name) ?? []).map((b) => ({
264
+ item: {
265
+ kind: "board",
266
+ name: b.name
267
+ },
268
+ order: b.order
269
+ }));
270
+ const folder = (name, kids) => ({
271
+ item: {
272
+ kind: "folder",
273
+ name,
274
+ items: sorted(kids),
275
+ ...folderExtras(reg.get(name) ?? {})
276
+ },
277
+ order: reg.get(name)?.order
278
+ });
279
+ const subsOf = (top) => [...reg.keys()].filter((n) => parentOf(n) === top);
280
+ const tops = [...[...reg.keys()].filter((n) => !parentOf(n)), ...implied];
281
+ return sorted([...boardsHere(null), ...tops.map((t) => folder(t, [...boardsHere(t), ...subsOf(t).map((s) => folder(s, boardsHere(s)))]))]);
282
+ }
283
+ /** Every board in reading order, depth-first - the order the switchers and the landing pick use. */
284
+ function flatten(tree) {
285
+ const out = [];
286
+ const walk = (items) => {
287
+ for (const it of items) if (it.kind === "board") out.push(it.name);
288
+ else walk(it.items);
289
+ };
290
+ walk(tree);
291
+ return out;
292
+ }
293
+ const wireKids = (w) => w.items ?? w.boards ?? [];
294
+ function validateWire(wire) {
295
+ if (!Array.isArray(wire)) return "invalid tree";
296
+ const boards = /* @__PURE__ */ new Set(), folders = /* @__PURE__ */ new Set();
297
+ const board = (n) => {
298
+ if (!isBoardName(n) || n === "all-scenes") return "invalid board name in tree";
299
+ if (boards.has(n)) return `board "${n}" appears twice`;
300
+ boards.add(n);
301
+ return null;
302
+ };
303
+ const walk = (list, depth) => {
304
+ for (const w of list) {
305
+ if (typeof w === "string") {
306
+ const e = board(w);
307
+ if (e) return e;
308
+ continue;
309
+ }
310
+ if (!w || typeof w !== "object" || Array.isArray(w)) return "invalid tree item";
311
+ if (depth >= 2) return "folders nest one level only";
312
+ const { folder, items, boards: legacy, title, description, type } = w;
313
+ if (!isBoardName(folder)) return "invalid folder name in tree";
314
+ if (title !== void 0 && (typeof title !== "string" || Array.from(title).length > 120)) return "invalid folder title";
315
+ if (description !== void 0 && (typeof description !== "string" || description.length > 300)) return "invalid folder description";
316
+ if (type !== void 0 && !readType(type)) return "invalid folder type";
317
+ if (folders.has(folder)) return `folder "${folder}" appears twice`;
318
+ folders.add(folder);
319
+ const kids = items ?? legacy;
320
+ if (!Array.isArray(kids)) return "invalid folder in tree";
321
+ if (items === void 0 && kids.some((k) => typeof k !== "string")) return "invalid folder in tree";
322
+ const e = walk(kids, depth + 1);
323
+ if (e) return e;
324
+ }
325
+ return null;
326
+ };
327
+ const e = walk(wire, 0);
328
+ if (e) return e;
329
+ if (boards.size > 200 || folders.size > 50) return "tree too large";
330
+ return null;
331
+ }
332
+ /** Every folder with the folder it sits in (null = the root), top-level folders first in
333
+ * reading order, each followed by its sub-folders. */
334
+ function folderEntries(t) {
335
+ const out = [];
336
+ for (const it of t) {
337
+ if (it.kind !== "folder") continue;
338
+ out.push({
339
+ folder: it,
340
+ parent: null
341
+ });
342
+ for (const k of it.items) if (k.kind === "folder") out.push({
343
+ folder: k,
344
+ parent: it.name
345
+ });
346
+ }
347
+ return out;
348
+ }
349
+ /** Every board's folder, in one pass - for callers that ask for many boards (folderOf walks the tree). */
350
+ function folderMap(t) {
351
+ const out = /* @__PURE__ */ new Map();
352
+ for (const { folder } of folderEntries(t)) for (const k of folder.items) if (k.kind === "board") out.set(k.name, folder.name);
353
+ return out;
354
+ }
355
+ //#endregion
356
+ //#region src/server/boards.ts
357
+ /**
358
+ * Reading design/boards/ safely - the one enumerator the dev API, the build and the tests
359
+ * share. Only REGULAR files on the board-name grammar count as boards (a symlink, dangling or
360
+ * live, could read or publish JSON from outside the project - it is skipped, and reported so
361
+ * the build can fail closed). The folder registry is read the same way: absent = no folders,
362
+ * malformed = an error the human must fix, never a silently empty registry.
363
+ */
364
+ /** Does realpath(dir) stay inside realpath(root)? A symlinked design/boards can't escape. */
365
+ function underRoot(root, dir) {
366
+ try {
367
+ const rr = realpathSync(root);
368
+ const rd = realpathSync(dir);
369
+ return rd === rr || rd.startsWith(rr + sep);
370
+ } catch {
371
+ return false;
372
+ }
373
+ }
374
+ /** Is design/boards a directory we may read and write? It must not be a symlink at all (a
375
+ * link to the repo root would list package.json as a board and let a tree write rewrite
376
+ * it; a link outside would publish foreign JSON) and must resolve inside the root. Absent
377
+ * is fine (no boards yet). Returns the error, or null. */
378
+ function checkBoardsDir(root, boardsDir) {
379
+ return checkRealDirs(root, [[join(boardsDir, ".."), "design"], [boardsDir, "design/boards"]]);
380
+ }
381
+ /** Every EXISTING path in `dirs` (root-down order) must be a real directory inside the root -
382
+ * a symlinked `design` with no boards dir yet would otherwise be followed by the mkdir that
383
+ * creates it; a symlinked `design/scenes` would let a brief write land outside the project.
384
+ * An absent one ends the walk (nothing beneath it exists either). Returns the error, or null. */
385
+ function checkRealDirs(root, dirs) {
386
+ for (const [p, label] of dirs) {
387
+ try {
388
+ if (lstatSync(p).isSymbolicLink()) return `${label} must be a real directory, not a symlink`;
389
+ } catch {
390
+ return null;
391
+ }
392
+ if (!underRoot(root, p)) return `${label} escapes the project`;
393
+ }
394
+ return null;
395
+ }
396
+ /** A regular file (lstat: a symlink is never followed, a dangling one is not "absent"). */
397
+ const isRegularFile = (p) => {
398
+ try {
399
+ return lstatSync(p).isFile();
400
+ } catch {
401
+ return false;
402
+ }
403
+ };
404
+ /** Is there ANY node at p (a dangling symlink counts)? */
405
+ const nodeExists = (p) => {
406
+ try {
407
+ lstatSync(p);
408
+ return true;
409
+ } catch {
410
+ return false;
411
+ }
412
+ };
413
+ /** Every board file: name, raw content, hash, and its JSON (null when malformed). `skipped`
414
+ * names the entries that looked like boards but were not regular files. */
415
+ function listBoardFiles(boardsDir) {
416
+ const boards = [], skipped = [];
417
+ if (!existsSync(boardsDir)) return {
418
+ boards,
419
+ skipped
420
+ };
421
+ for (const f of readdirSync(boardsDir)) {
422
+ if (!isBoardFile(f)) continue;
423
+ const file = join(boardsDir, f);
424
+ if (!isRegularFile(file)) {
425
+ skipped.push(f);
426
+ continue;
427
+ }
428
+ const content = readFileSync(file, "utf8");
429
+ let json = null;
430
+ try {
431
+ json = JSON.parse(content);
432
+ } catch {}
433
+ boards.push({
434
+ name: f.slice(0, -5),
435
+ file,
436
+ content,
437
+ sha256: hash(content),
438
+ json
439
+ });
440
+ }
441
+ return {
442
+ boards,
443
+ skipped
444
+ };
445
+ }
446
+ function boardFields(json, validName) {
447
+ const o = json;
448
+ const title = readTitle(o?.title);
449
+ const description = readDescription(o?.description);
450
+ const type = readType(o?.type), capability = readCapability(o?.capability), status = readStatusWord(o?.status), reason = readReason(o?.reason);
451
+ return {
452
+ ...typeof o?.order === "number" && Number.isFinite(o.order) ? { order: o.order } : {},
453
+ ...validName(o?.folder) ? { folder: o.folder } : {},
454
+ ...title ? { title } : {},
455
+ ...description ? { description } : {},
456
+ ...type ? { type } : {},
457
+ ...capability ? { capability } : {},
458
+ ...status ? { status } : {},
459
+ ...reason ? { reason } : {}
460
+ };
461
+ }
462
+ /** The fields a board's file owns that the shell's save shape never carries: an autosave keeps
463
+ * each one from disk when the incoming board omits it (spec 20 - the fields survive every write). */
464
+ const AUTHOR_FIELDS = [
465
+ "order",
466
+ "folder",
467
+ "title",
468
+ "description",
469
+ "type",
470
+ "capability",
471
+ "status",
472
+ "reason"
473
+ ];
474
+ /** The folder registry. `sha256` is the CAS token a tree write must echo (null = "there was
475
+ * no file"), so a write can never silently replace a registry it never saw. */
476
+ function readRegistry(boardsDir) {
477
+ const p = join(boardsDir, FOLDERS_FILE);
478
+ if (!nodeExists(p)) return {
479
+ state: "absent",
480
+ folders: [],
481
+ sha256: null
482
+ };
483
+ if (!isRegularFile(p)) return {
484
+ state: "malformed",
485
+ error: `design/boards/${FOLDERS_FILE} must be a regular file, not a symlink`,
486
+ sha256: null
487
+ };
488
+ const content = readFileSync(p, "utf8");
489
+ let raw;
490
+ try {
491
+ raw = JSON.parse(content);
492
+ } catch {
493
+ return {
494
+ state: "malformed",
495
+ error: `design/boards/${FOLDERS_FILE} is not valid JSON - fix the file`,
496
+ sha256: hash(content)
497
+ };
498
+ }
499
+ const parsed = parseFolders(raw);
500
+ if (typeof parsed === "string") return {
501
+ state: "malformed",
502
+ error: `design/boards/${FOLDERS_FILE}: ${parsed}`,
503
+ sha256: hash(content)
504
+ };
505
+ return {
506
+ state: "ok",
507
+ folders: parsed,
508
+ sha256: hash(content)
509
+ };
510
+ }
511
+ /** The registry's write lock - one writer at a time across processes (the dev server's tree write,
512
+ * `folders add`, `init --kind`), so a read-modify-write of `_folders.json` is atomic among Marver's
513
+ * writers. A lock older than 10 s is a crashed writer's and is taken over. `wait` = how long to
514
+ * try (the CLI waits; the dev server never blocks its event loop - it answers 409 instead). */
515
+ const REGISTRY_LOCK = ".folders.lock";
516
+ function withRegistryLock(dir, wait, fn) {
517
+ const lock = join(dir, REGISTRY_LOCK);
518
+ const t0 = Date.now();
519
+ for (;;) try {
520
+ writeFileSync(lock, `${process.pid} ${Date.now()}\n`, { flag: "wx" });
521
+ break;
522
+ } catch (e) {
523
+ if (e.code !== "EEXIST") throw e;
524
+ try {
525
+ if (Date.now() - lstatSync(lock).mtimeMs > 1e4) {
526
+ rmSync(lock, { force: true });
527
+ continue;
528
+ }
529
+ } catch {
530
+ continue;
531
+ }
532
+ if (Date.now() - t0 >= wait) return null;
533
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
534
+ }
535
+ try {
536
+ return fn();
537
+ } finally {
538
+ rmSync(lock, { force: true });
539
+ }
540
+ }
541
+ /** Append typed folders to the registry (spec 20: `init --kind`, `folders add`). Never renames,
542
+ * moves or retypes a folder that exists - a name already registered is skipped and reported - and
543
+ * never drops a field of an existing entry it does not manage. New folders rank after everything
544
+ * already at the root. The write is compare-and-swap: the registry is re-read just before the
545
+ * atomic rename, and a change since the first read (the shell's drag, another agent) starts the
546
+ * append over from the new file. A malformed registry is an error, never overwritten. */
547
+ function addFolders(root, folders) {
548
+ const dir = join(root, "design", "boards");
549
+ const de = checkBoardsDir(root, dir);
550
+ if (de) throw new Error(de);
551
+ mkdirSync(dir, { recursive: true });
552
+ const file = join(dir, FOLDERS_FILE);
553
+ const done = withRegistryLock(dir, 5e3, () => appendFolders(dir, file, folders));
554
+ if (!done) throw new Error(`design/boards/${FOLDERS_FILE} is being written by another process - try again`);
555
+ return done;
556
+ }
557
+ function appendFolders(dir, file, folders) {
558
+ for (let attempt = 0; attempt < 5; attempt++) {
559
+ const before = nodeExists(file) ? readFileSync(file, "utf8") : null;
560
+ const reg = readRegistry(dir);
561
+ if (reg.state === "malformed") throw new Error(reg.error);
562
+ let raw = [];
563
+ if (before !== null) {
564
+ const j = JSON.parse(before);
565
+ raw = Array.isArray(j.folders) ? j.folders : [];
566
+ }
567
+ const have = new Set(raw.map((f) => f.name));
568
+ const rootRanks = [...raw.filter((f) => f.parent === void 0).map((f) => f.order), ...listBoardFiles(dir).boards.map((b) => {
569
+ const o = b.json;
570
+ return o?.folder ? void 0 : o?.order;
571
+ })].filter((o) => typeof o === "number" && Number.isFinite(o));
572
+ let next = rootRanks.length ? Math.max(...rootRanks) + 1 : 0;
573
+ const added = [], existing = [];
574
+ const rows = [...raw];
575
+ for (const f of folders) {
576
+ if (have.has(f.name)) {
577
+ existing.push(f.name);
578
+ continue;
579
+ }
580
+ rows.push({
581
+ name: f.name,
582
+ order: next++,
583
+ ...f.title ? { title: f.title } : {},
584
+ ...f.type ? { type: f.type } : {}
585
+ });
586
+ have.add(f.name);
587
+ added.push(f.name);
588
+ }
589
+ if (!added.length) return {
590
+ added,
591
+ existing
592
+ };
593
+ const version = rows.some((f) => f.parent !== void 0) ? 2 : 1;
594
+ const tmp = `${file}.${process.pid}.${Date.now()}.${attempt}.tmp`;
595
+ writeFileSync(tmp, JSON.stringify({
596
+ version,
597
+ folders: rows
598
+ }, null, 2) + "\n", { flag: "wx" });
599
+ if ((nodeExists(file) ? readFileSync(file, "utf8") : null) !== before) {
600
+ rmSync(tmp, { force: true });
601
+ continue;
602
+ }
603
+ renameSync(tmp, file);
604
+ return {
605
+ added,
606
+ existing
607
+ };
608
+ }
609
+ throw new Error(`design/boards/${FOLDERS_FILE} kept changing while folders were added - try again`);
610
+ }
611
+ //#endregion
612
+ export { readCapability as A, BOARD_TYPES as C, KIND_FOLDERS as D, HAS_STATUS as E, settableStatuses as F, hash as I, readStatusWord as M, readType as N, PROPOSED_PUBLISH as O, resolveType as P, wireKids as S, FOLDER_MODULES as T, humanize as _, checkRealDirs as a, readTitle as b, nodeExists as c, BOARD_NAME as d, FOLDERS_FILE as f, folderMap as g, folderEntries as h, checkBoardsDir as i, readReason as j, knownType as k, readRegistry as l, flatten as m, addFolders as n, isRegularFile as o, buildTree as p, boardFields as r, listBoardFiles as s, AUTHOR_FIELDS as t, withRegistryLock as u, isBoardName as v, DECISIONS as w, validateWire as x, readDescription as y };
@@ -1,8 +1,9 @@
1
1
  import { a as ROUTE, r as NAME } from "./cli.mjs";
2
- import { D as boardFields, H as isBoardName, L as buildTree, N as readRegistry, O as checkBoardsDir, R as flatten, Z as PROPOSED_PUBLISH, i as PUBLISHABLE, j as listBoardFiles, o as publishableStatus } from "./board-status-CWGHIdo_.mjs";
3
- import { i as scanFrames } from "./manifest-CcdWx7ud.mjs";
4
- import { i as detectHost, n as loadConfig } from "./config-DJxMRVD8.mjs";
5
- import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-C5u07Yhv.mjs";
2
+ import { O as PROPOSED_PUBLISH, i as checkBoardsDir, l as readRegistry, m as flatten, p as buildTree, r as boardFields, s as listBoardFiles, v as isBoardName } from "./boards-DbVJlbd5.mjs";
3
+ import { c as publishableStatus, o as PUBLISHABLE } from "./board-status-D_lHZZ09.mjs";
4
+ import { o as scanFrames } from "./manifest-BkjJ5OQk.mjs";
5
+ import { n as loadConfig, r as detectHost } from "./config-g-J8NrPn.mjs";
6
+ import { a as autoWidthOf, c as readSizes, n as tailwind3Css, o as keptSizes, r as tailwind4Plugin, s as measuringFrames, t as marverPlugin } from "./plugin-C1avHL7g.mjs";
6
7
  import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
7
8
  import { basename, dirname, join, sep } from "node:path";
8
9
  import { fileURLToPath } from "node:url";
@@ -611,6 +612,8 @@ async function buildSite(root, boardsFlag, allBoardsFlag, embedSeeds, textures =
611
612
  ...b.status ? { status: b.status } : {}
612
613
  }]] : []));
613
614
  const bakeGen = textures ? Date.now() : void 0;
615
+ const pubIds = new Set(frames.map((f) => f.id));
616
+ const sizes = Object.fromEntries(Object.entries(keptSizes(readSizes(root), autoWidthOf(manifest.frames, config.viewports), measuringFrames(root, manifest.frames))).filter(([k]) => pubIds.has(k.slice(0, k.lastIndexOf("@")))));
614
617
  const data = {
615
618
  bakes: bakeGen,
616
619
  manifest: pubManifest,
@@ -619,6 +622,7 @@ async function buildSite(root, boardsFlag, allBoardsFlag, embedSeeds, textures =
619
622
  tree,
620
623
  ...Object.keys(titles).length ? { titles } : {},
621
624
  ...Object.keys(meta).length ? { meta } : {},
625
+ ...Object.keys(sizes).length ? { sizes } : {},
622
626
  ...Object.values(meta).some((m) => m.status) ? { statusAsOf: (/* @__PURE__ */ new Date()).toISOString() } : {},
623
627
  default: publishedNames.find((n) => n !== "all-scenes") ?? publishedNames[0],
624
628
  rights,
@@ -754,7 +758,7 @@ async function buildSite(root, boardsFlag, allBoardsFlag, embedSeeds, textures =
754
758
  const realAssets = existsSync(assetsDir) ? realpathSync(assetsDir) : null;
755
759
  for (const r of refs) {
756
760
  if (!isLocalAssetRef(r) || !r.endsWith(".poster.png") || existsSync(join(assetsDir, r))) continue;
757
- const { ensurePoster } = await import("./poster-BduzQBYz.mjs");
761
+ const { ensurePoster } = await import("./poster-Bc4-3DlQ.mjs");
758
762
  const g = await ensurePoster(assetsDir, r.slice(0, -11));
759
763
  if (!g.ok) throw new Error(`design/assets/${r}: ${g.error}`);
760
764
  console.log(` poster: rendered design/assets/${r} (${g.width}×${g.height})`);
@@ -821,7 +825,7 @@ async function buildSite(root, boardsFlag, allBoardsFlag, embedSeeds, textures =
821
825
  }));
822
826
  let textureLine = " textures: skipped (--no-textures)";
823
827
  if (textures && bakeGen) {
824
- const { bakePublished } = await import("./publish-bakes-b0jUwvM_.mjs");
828
+ const { bakePublished } = await import("./publish-bakes-DQWn14IY.mjs");
825
829
  const pubFrameFile = new Map(pubFrames.map((f) => [f.id, f]));
826
830
  const r = await bakePublished({
827
831
  root,