@marver-design/marver 0.26.1 → 0.27.2
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.
- package/CHANGELOG.md +198 -0
- package/README.md +12 -4
- package/dist/{anchor-check-l-ny3UzH.mjs → anchor-check-gkxkPAIv.mjs} +1 -1
- package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
- package/dist/{boards-CGg6piKF.mjs → boards-BHKP5yhI.mjs} +1 -1
- package/dist/{boards-DYG22tOe.mjs → boards-BqUqKNW8.mjs} +4 -4
- package/dist/{build-BDRiO_mP.mjs → build-VgNg4rr8.mjs} +8 -23
- package/dist/cli.mjs +45 -19
- package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
- package/dist/{comments-BqXua-XL.mjs → comments-YEU1Zhv9.mjs} +4 -4
- package/dist/{context-HQ4Giw58.mjs → context-Ccjrhr1J.mjs} +3 -3
- package/dist/{daemon-DL6Fwq6D.mjs → daemon-Dc9AH0M3.mjs} +9 -7
- package/dist/detect-C0wpaePX.mjs +125 -0
- package/dist/dev-lock-C_FC70Mu.mjs +65 -0
- package/dist/dev-ri6nAlRp.mjs +1273 -0
- package/dist/exclusive-B1RtpeeP.mjs +150 -0
- package/dist/{init-D8DtrK_F.mjs → init-W0nxR1OY.mjs} +8 -6
- package/dist/{link-BNzLvdhI.mjs → link-CdTgn94Y.mjs} +23 -11
- package/dist/ls-BZ5TAtd5.mjs +38 -0
- package/dist/{manifest-Nl3KSVOk.mjs → manifest-aFyDmL8C.mjs} +2 -2
- package/dist/{marks-DyWMv_Z1.mjs → marks-BF9pNEgH.mjs} +3 -3
- package/dist/{marks-CKgzucHZ.mjs → marks-CnCCfAbD.mjs} +3 -3
- package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
- package/dist/perf-DkAUFT6W.mjs +1319 -0
- package/dist/perf-jam-BaH3Lg0m.mjs +635 -0
- package/dist/plugin-B8UghYuF.mjs +5242 -0
- package/dist/{poster-BdtSKMDm.mjs → poster-BNgafWMK.mjs} +1 -1
- package/dist/{profile-WU9qcbIo.mjs → profile-jIS6BcAs.mjs} +1 -1
- package/dist/{publish-bakes-9RzRToXV.mjs → publish-bakes-38Nja78p.mjs} +3 -3
- package/dist/{queue-29ok5_eZ.mjs → queue-CAM_vNmX.mjs} +1 -1
- package/dist/recover-B8AiI29B.mjs +66 -0
- package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
- package/dist/{share--oFJ1bCI.mjs → share-Ce4tP7ji.mjs} +1 -1
- package/dist/{shot-XQV7HC9A.mjs → shot-CMQgMVZm.mjs} +1 -1
- package/dist/{shot-DQeR_Pfn.mjs → shot-Ch24tiMO.mjs} +36 -5
- package/dist/slots-CFNnegCc.mjs +478 -0
- package/dist/{sync-DKk-yT1V.mjs → sync-CQdGARJ9.mjs} +4 -3
- package/dist/{work-VvX_JIgl.mjs → work-Bxz-ObF3.mjs} +4 -2
- package/dist/{work-F5u-twpJ.mjs → work-CNhFF9pU.mjs} +5 -3
- package/docs/boards-and-folders.md +3 -1
- package/docs/jam-session.md +57 -2
- package/docs/performance.md +424 -0
- package/package.json +2 -2
- package/src/client/content/index.tsx +3 -0
- package/src/client/content/video.tsx +16 -4
- package/src/client/frame-host/bridge.js +22 -6
- package/src/client/frame-host/main.tsx +17 -5
- package/src/client/shell/App.tsx +188 -26
- package/src/client/shell/BoardList.tsx +5 -5
- package/src/client/shell/Comments.tsx +8 -5
- package/src/client/shell/ContextMenu.tsx +5 -3
- package/src/client/shell/JamSurface.tsx +4 -2
- package/src/client/shell/LockedApp.tsx +8 -5
- package/src/client/shell/Play.tsx +20 -10
- package/src/client/shell/Tip.tsx +3 -1
- package/src/client/shell/Toolbar.tsx +12 -1
- package/src/client/shell/api.ts +233 -0
- package/src/client/shell/app-bridge.ts +254 -0
- package/src/client/shell/app-perf.ts +92 -0
- package/src/client/shell/canvas/Canvas.tsx +141 -21
- package/src/client/shell/canvas/FrameNode.tsx +22 -9
- package/src/client/shell/canvas/admission.ts +31 -9
- package/src/client/shell/canvas/camera-broadcast.ts +15 -5
- package/src/client/shell/canvas/ctl.ts +8 -0
- package/src/client/shell/canvas/frame-registry.ts +28 -2
- package/src/client/shell/canvas/sleep.ts +60 -17
- package/src/client/shell/canvas/updates.ts +2 -1
- package/src/client/shell/comments-store.ts +12 -4
- package/src/client/shell/goto.ts +22 -10
- package/src/client/shell/inset.ts +44 -0
- package/src/client/shell/jam-capture.ts +41 -22
- package/src/client/shell/jam-keys.ts +12 -3
- package/src/client/shell/jam-panel.tsx +9 -3
- package/src/client/shell/jam-queue.ts +3 -3
- package/src/client/shell/jam-session.tsx +14 -8
- package/src/client/shell/jam-voice.ts +55 -15
- package/src/client/shell/legacy-links.ts +2 -2
- package/src/client/shell/main.tsx +18 -1
- package/src/client/shell/marks-ui.tsx +5 -3
- package/src/client/shell/marver-app.ts +21 -0
- package/src/client/shell/notes.ts +8 -1
- package/src/client/shell/perf-run-probe.ts +34 -0
- package/src/client/shell/perf-run.ts +70 -0
- package/src/client/shell/perf.ts +80 -58
- package/src/client/shell/recorder-core.ts +183 -0
- package/src/client/shell/recorder.ts +607 -0
- package/src/client/shell/store.ts +294 -110
- package/src/client/shell/styles.css +72 -15
- package/src/client/shell/unsaved.ts +81 -0
- package/src/client/shell/whiteout-probes.ts +141 -0
- package/src/shared/app-api.ts +205 -0
- package/src/shared/app-perf.ts +308 -0
- package/src/shared/logo-sniff.ts +86 -0
- package/src/shared/machine.ts +132 -0
- package/src/shared/perf-run.ts +177 -0
- package/templates/AGENTS-embedded.md +25 -4
- package/templates/AGENTS-studio.md +25 -4
- package/templates/demo/dark.tsx +1 -1
- package/templates/demo/welcome.tsx +1 -1
- package/templates/instructions/boards.md +3 -1
- package/templates/instructions/welcome.md +6 -3
- package/dist/bake-C-awKgLA.mjs +0 -786
- package/dist/config-Cf7EjAMf.mjs +0 -292
- package/dist/dev-Bw_qYWWq.mjs +0 -755
- package/dist/dev-lock-DWSpa6nj.mjs +0 -179
- package/dist/perf-C75MZ73h.mjs +0 -167
- package/dist/perf-DPbLGhhO.mjs +0 -49
- package/dist/perf-jam-BU3TVrZu.mjs +0 -239
- package/dist/plugin-DkGmZs_r.mjs +0 -2423
|
@@ -0,0 +1,1273 @@
|
|
|
1
|
+
import { i as PKG, r as NAME } from "./cli.mjs";
|
|
2
|
+
import { a as notePrefer, c as ranDevBefore, f as startedWhere, i as marverHome, m as runIdentity, o as originOf, p as stopPrefer, s as place, t as forgetDevTraces } from "./slots-CFNnegCc.mjs";
|
|
3
|
+
import { t as detectHost } from "./detect-C0wpaePX.mjs";
|
|
4
|
+
import { a as installedVersion, f as loadConfig, n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-B8UghYuF.mjs";
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeSync } from "node:fs";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { createLogger, createServer, parseAst, parseSync, searchForWorkspaceRoot } from "vite";
|
|
10
|
+
import react from "@vitejs/plugin-react";
|
|
11
|
+
import MagicString from "magic-string";
|
|
12
|
+
//#region src/server/icons.ts
|
|
13
|
+
/**
|
|
14
|
+
* Icon barrels, unrolled.
|
|
15
|
+
*
|
|
16
|
+
* `import { Truck } from '@phosphor-icons/react'` makes Vite hand the frame the WHOLE prebundled
|
|
17
|
+
* package - 3000 icons, 6.5 MB of JavaScript - and every frame on a board is its own realm, so every
|
|
18
|
+
* frame parses and evaluates all of it: ~400 ms, the whole boot of a lo-fi frame (measured,
|
|
19
|
+
* research/hifi/frameres.ts: the scene import is 530 of a 550 ms boot; a board of 128 frames spends
|
|
20
|
+
* 50 s on it). The packages ship one module per icon and their barrel says which: this reads the
|
|
21
|
+
* INSTALLED barrel once (every alias, whatever the version), rewrites the import declarations of
|
|
22
|
+
* design sources to the per-icon modules, one line for one line, and names those modules to the
|
|
23
|
+
* dependency optimizer at server start so nothing is discovered - and reloaded for - on first use.
|
|
24
|
+
* A name the barrel does not map, a default or namespace import, a re-export: left as it is.
|
|
25
|
+
*/
|
|
26
|
+
const LIBS = [{
|
|
27
|
+
barrel: "@phosphor-icons/react",
|
|
28
|
+
spec: (rel) => {
|
|
29
|
+
const m = rel.match(/^\.\/csr\/([\w-]+)\.es\.js$/);
|
|
30
|
+
return m ? `@phosphor-icons/react/dist/csr/${m[1]}` : null;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
barrel: "lucide-react",
|
|
34
|
+
spec: (rel) => {
|
|
35
|
+
const m = rel.match(/^\.\/icons\/([\w-]+\.m?js)$/);
|
|
36
|
+
return m ? `lucide-react/dist/esm/icons/${m[1]}` : null;
|
|
37
|
+
}
|
|
38
|
+
}];
|
|
39
|
+
/** The map read from a barrel's source: `import { A as x } from './f'` + `export { x as Name }`
|
|
40
|
+
* (phosphor) and `export { default as Name } from './f'` (lucide). */
|
|
41
|
+
function parseBarrel(source, lib) {
|
|
42
|
+
const map = /* @__PURE__ */ new Map();
|
|
43
|
+
const locals = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const m of source.matchAll(/import\s*\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
45
|
+
const spec = lib.spec(m[2]);
|
|
46
|
+
if (!spec) continue;
|
|
47
|
+
for (const s of m[1].split(",")) {
|
|
48
|
+
const [name, local = name] = s.trim().split(/\s+as\s+/);
|
|
49
|
+
if (name) locals.set(local, {
|
|
50
|
+
spec,
|
|
51
|
+
name
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const m of source.matchAll(/export\s*\{([^}]*)\}(?:\s*from\s*["']([^"']+)["'])?/g)) {
|
|
56
|
+
const spec = m[2] ? lib.spec(m[2]) : null;
|
|
57
|
+
if (m[2] && !spec) continue;
|
|
58
|
+
for (const s of m[1].split(",")) {
|
|
59
|
+
const [name, exported = name] = s.trim().split(/\s+as\s+/);
|
|
60
|
+
if (!name) continue;
|
|
61
|
+
if (spec) map.set(exported, {
|
|
62
|
+
spec,
|
|
63
|
+
name
|
|
64
|
+
});
|
|
65
|
+
else {
|
|
66
|
+
const l = locals.get(name);
|
|
67
|
+
if (l) map.set(exported, l);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return map;
|
|
72
|
+
}
|
|
73
|
+
const maps = /* @__PURE__ */ new Map();
|
|
74
|
+
/** The maps for every icon package installed under `root` (read once per server). */
|
|
75
|
+
function iconMaps(root) {
|
|
76
|
+
let m = maps.get(root);
|
|
77
|
+
if (m) return m;
|
|
78
|
+
m = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const lib of LIBS) {
|
|
80
|
+
const dir = join(root, "node_modules", lib.barrel);
|
|
81
|
+
try {
|
|
82
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
83
|
+
const dot = pkg.exports?.["."];
|
|
84
|
+
const entry = (typeof dot === "object" ? dot.import : typeof dot === "string" ? dot : void 0) ?? pkg.module;
|
|
85
|
+
if (!entry) continue;
|
|
86
|
+
const map = parseBarrel(readFileSync(join(dir, entry), "utf8"), lib);
|
|
87
|
+
if (map.size) m.set(lib.barrel, map);
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
maps.set(root, m);
|
|
91
|
+
return m;
|
|
92
|
+
}
|
|
93
|
+
/** The code with every mapped icon import unrolled and the per-icon specifiers it now imports;
|
|
94
|
+
* null when nothing changed. Real import declarations only (a template literal is content). */
|
|
95
|
+
function unrollIcons(code, maps) {
|
|
96
|
+
if (![...maps.keys()].some((b) => code.includes(b))) return null;
|
|
97
|
+
let ast;
|
|
98
|
+
try {
|
|
99
|
+
ast = parseAst(code);
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const edits = [];
|
|
104
|
+
const modules = [];
|
|
105
|
+
for (const node of ast.body) {
|
|
106
|
+
if (node.type !== "ImportDeclaration" || !node.source) continue;
|
|
107
|
+
const map = maps.get(node.source.value);
|
|
108
|
+
if (!map || !node.specifiers?.length) continue;
|
|
109
|
+
const lines = [], keep = [];
|
|
110
|
+
let icons = 0;
|
|
111
|
+
for (const s of node.specifiers) {
|
|
112
|
+
const imported = s.type === "ImportSpecifier" ? s.imported?.name ?? s.imported?.value : void 0;
|
|
113
|
+
const hit = imported ? map.get(imported) : void 0;
|
|
114
|
+
if (!hit) {
|
|
115
|
+
if (s.type !== "ImportSpecifier") {
|
|
116
|
+
lines.length = 0;
|
|
117
|
+
icons = 0;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
keep.push(imported === s.local.name ? imported : `${imported} as ${s.local.name}`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
icons++;
|
|
124
|
+
modules.push(hit.spec);
|
|
125
|
+
lines.push(hit.name === "default" ? `import ${s.local.name} from '${hit.spec}';` : `import { ${hit.name === s.local.name ? hit.name : `${hit.name} as ${s.local.name}`} } from '${hit.spec}';`);
|
|
126
|
+
}
|
|
127
|
+
if (!icons) continue;
|
|
128
|
+
if (keep.length) lines.push(`import { ${keep.join(", ")} } from '${node.source.value}';`);
|
|
129
|
+
const original = code.slice(node.start, node.end);
|
|
130
|
+
edits.push({
|
|
131
|
+
start: node.start,
|
|
132
|
+
end: node.end,
|
|
133
|
+
text: lines.join(" ") + "\n".repeat((original.match(/\n/g) ?? []).length)
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (!edits.length) return null;
|
|
137
|
+
let out = "", at = 0;
|
|
138
|
+
for (const e of edits) {
|
|
139
|
+
out += code.slice(at, e.start) + e.text;
|
|
140
|
+
at = e.end;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
code: out + code.slice(at),
|
|
144
|
+
modules
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Every per-icon module the design sources import (for the optimizer, at server start). Raw
|
|
148
|
+
* TypeScript is scanned by a plain pattern; only names the barrel maps count. */
|
|
149
|
+
function iconModules(root) {
|
|
150
|
+
const m = iconMaps(root);
|
|
151
|
+
if (!m.size) return [];
|
|
152
|
+
const found = /* @__PURE__ */ new Set();
|
|
153
|
+
const walk = (dir) => {
|
|
154
|
+
let names;
|
|
155
|
+
try {
|
|
156
|
+
names = readdirSync(dir);
|
|
157
|
+
} catch {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
for (const n of names) {
|
|
161
|
+
if (n === "node_modules" || n.startsWith(".")) continue;
|
|
162
|
+
const p = join(dir, n);
|
|
163
|
+
let st;
|
|
164
|
+
try {
|
|
165
|
+
st = statSync(p);
|
|
166
|
+
} catch {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (st.isDirectory()) walk(p);
|
|
170
|
+
else if (/\.[jt]sx?$/.test(n)) {
|
|
171
|
+
const src = readFileSync(p, "utf8").replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, (c) => " ".repeat(c.length));
|
|
172
|
+
for (const im of src.matchAll(/import\s*\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g)) {
|
|
173
|
+
const map = m.get(im[2]);
|
|
174
|
+
if (!map) continue;
|
|
175
|
+
for (const s of im[1].split(",")) {
|
|
176
|
+
const name = s.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0];
|
|
177
|
+
const hit = map.get(name);
|
|
178
|
+
if (hit) found.add(hit.spec);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
walk(join(root, "design"));
|
|
185
|
+
return [...found].sort();
|
|
186
|
+
}
|
|
187
|
+
/** The Vite plugin: design sources only, after the TS/JSX transform (a normal plugin runs after
|
|
188
|
+
* the core ones), before import analysis resolves the specifiers. The rewrite keeps every line
|
|
189
|
+
* where it was, so the file's map still lands (no map of its own). */
|
|
190
|
+
function iconsPlugin(root) {
|
|
191
|
+
const design = join(root, "design") + "/";
|
|
192
|
+
return {
|
|
193
|
+
name: "marver:icons",
|
|
194
|
+
transform(code, id) {
|
|
195
|
+
if (!id.startsWith(design) || !/\.[jt]sx?(\?|$)/.test(id)) return;
|
|
196
|
+
const r = unrollIcons(code, iconMaps(root));
|
|
197
|
+
return r ? {
|
|
198
|
+
code: r.code,
|
|
199
|
+
map: null
|
|
200
|
+
} : void 0;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/server/loc.ts
|
|
206
|
+
/**
|
|
207
|
+
* Every element knows its source (spec 27, Part 6). A dev-only transform on design files adds
|
|
208
|
+
* `data-mv-loc="<path>:<line>:<col>"` to every HOST JSX element - a lowercase plain name (`<div>`,
|
|
209
|
+
* `<button>`, `<my-el>`). Components (`<Card>`) and member names (`<motion.div>`) are skipped: they
|
|
210
|
+
* may not pass attributes on. The laser and a capture's bundles already read `dataset.mvLoc` into
|
|
211
|
+
* `source` (frame-host/inspect.js), so a pick names its file and line and the agent goes there first.
|
|
212
|
+
*
|
|
213
|
+
* It parses with Vite's own `parseSync` (oxc), so anything Vite compiles it reads, and inserts the
|
|
214
|
+
* attribute right after the tag name - FIRST, so an explicit `data-mv-loc` or a spread later in the
|
|
215
|
+
* tag wins. Edits go through magic-string, whose hires map composes with Vite's.
|
|
216
|
+
*
|
|
217
|
+
* Location: the `<` of the opening tag in the ORIGINAL source, 1-based line and 1-based column, the
|
|
218
|
+
* column in UTF-16 code units - what JS string indices, source maps and editors' column counters
|
|
219
|
+
* (VS Code included) use, so an emoji before the tag counts 2.
|
|
220
|
+
*/
|
|
221
|
+
const DESIGN_FILE = /\.(tsx|jsx)$/;
|
|
222
|
+
/** Line starts of `code`, so an offset becomes a 1-based line and column. */
|
|
223
|
+
function lineIndex(code) {
|
|
224
|
+
const starts = [0];
|
|
225
|
+
for (let i = 0; i < code.length; i++) if (code.charCodeAt(i) === 10) starts.push(i + 1);
|
|
226
|
+
return (offset) => {
|
|
227
|
+
let lo = 0, hi = starts.length - 1;
|
|
228
|
+
while (lo < hi) {
|
|
229
|
+
const mid = lo + hi + 1 >> 1;
|
|
230
|
+
if (starts[mid] <= offset) lo = mid;
|
|
231
|
+
else hi = mid - 1;
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
line: lo + 1,
|
|
235
|
+
col: offset - starts[lo] + 1
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** Add `data-mv-loc` to every host element of one design file. `file` is the path the attribute
|
|
240
|
+
* names (relative to the repo root, forward slashes). Null when there is nothing to add or the
|
|
241
|
+
* file does not parse - Vite then reports the error as it would have. */
|
|
242
|
+
function addSourceLocations(code, file) {
|
|
243
|
+
if (!code.includes("<")) return null;
|
|
244
|
+
const parsed = parseSync(file, code, {
|
|
245
|
+
lang: file.endsWith(".jsx") ? "jsx" : "tsx",
|
|
246
|
+
sourceType: "module"
|
|
247
|
+
});
|
|
248
|
+
if (parsed.errors.length) return null;
|
|
249
|
+
const at = lineIndex(code);
|
|
250
|
+
const s = new MagicString(code);
|
|
251
|
+
let added = 0;
|
|
252
|
+
const walk = (n) => {
|
|
253
|
+
if (!n || typeof n !== "object") return;
|
|
254
|
+
if (Array.isArray(n)) {
|
|
255
|
+
for (const x of n) walk(x);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const node = n;
|
|
259
|
+
if (node.type === "JSXOpeningElement" && node.name?.type === "JSXIdentifier" && /^[a-z]/.test(node.name.name ?? "") && typeof node.start === "number" && typeof node.name.end === "number") {
|
|
260
|
+
const { line, col } = at(node.start);
|
|
261
|
+
s.appendLeft(node.name.end, ` data-mv-loc={${JSON.stringify(`${file}:${line}:${col}`)}}`);
|
|
262
|
+
added++;
|
|
263
|
+
}
|
|
264
|
+
for (const k in node) if (k !== "parent") walk(node[k]);
|
|
265
|
+
};
|
|
266
|
+
walk(parsed.program);
|
|
267
|
+
if (!added) return null;
|
|
268
|
+
return {
|
|
269
|
+
code: s.toString(),
|
|
270
|
+
map: s.generateMap({
|
|
271
|
+
hires: true,
|
|
272
|
+
source: file,
|
|
273
|
+
includeContent: true
|
|
274
|
+
})
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/** The dev server's plugin: design/**\/*.tsx|jsx only, never node_modules, never the published
|
|
278
|
+
* build (dev.ts adds it; build.ts does not). Ids are real paths, so the root is matched both ways. */
|
|
279
|
+
function locPlugin(root) {
|
|
280
|
+
const roots = [.../* @__PURE__ */ new Set([root, safeReal$1(root)])];
|
|
281
|
+
const repoPath = (id) => {
|
|
282
|
+
const file = id.split("?")[0];
|
|
283
|
+
if (!DESIGN_FILE.test(file) || file.includes(`${sep}node_modules${sep}`) || file.includes("/node_modules/")) return null;
|
|
284
|
+
for (const r of roots) {
|
|
285
|
+
const rel = relative(r, file);
|
|
286
|
+
if (!rel.startsWith("..") && (rel.startsWith(`design${sep}`) || rel.startsWith("design/"))) return rel.split(sep).join("/");
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
};
|
|
290
|
+
return {
|
|
291
|
+
name: "marver:loc",
|
|
292
|
+
enforce: "pre",
|
|
293
|
+
apply: "serve",
|
|
294
|
+
transform(code, id) {
|
|
295
|
+
const file = repoPath(id);
|
|
296
|
+
return file ? addSourceLocations(code, file) : null;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function safeReal$1(p) {
|
|
301
|
+
try {
|
|
302
|
+
return realpathSync(p);
|
|
303
|
+
} catch {
|
|
304
|
+
return p;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/server/startup.ts
|
|
309
|
+
/**
|
|
310
|
+
* Startup as one transaction (spec 28 A1.1): everything `marver dev` holds on its way up belongs to one
|
|
311
|
+
* Startup, and goes back in reverse order on any way out - a failed start, a close, an exit, a signal.
|
|
312
|
+
* Each thing is registered the moment it is taken, so whatever is held when a way out comes is given
|
|
313
|
+
* back, and nothing else. Two kinds, because the ways out differ:
|
|
314
|
+
* - claims: files (dev.lock, the slot file, dev.json, the preference file's stop). Released
|
|
315
|
+
* synchronously, so `exit` and a signal, which cannot wait, give them back too (a dying process frees its
|
|
316
|
+
* sockets with it); on a close, last - once everything that could still bind or serve has closed, a server a
|
|
317
|
+
* restart was making included (dev.ts) - so a starter never finds a slot free while a socket of this start
|
|
318
|
+
* is bound, or about to be.
|
|
319
|
+
* - closers: what runs (Marver's watchers, sweeps and timers, the Vite server). Closed, awaited, on a
|
|
320
|
+
* failed start or a close; an exit or a signal ends them with the process.
|
|
321
|
+
* A close says so first, before anything closes (`onClose`: the slot file rewritten as `closing`, dev.ts), since
|
|
322
|
+
* its claims stay until the end and what it waits for can take long: no reader takes a canvas whose serving has
|
|
323
|
+
* ended for one that serves. An exit or a signal gives the claims back at once, so it has nothing to say.
|
|
324
|
+
* A Vite restart (an .env edit) is no way out: it replaces the server and keeps the start (dev.ts).
|
|
325
|
+
*/
|
|
326
|
+
const SIGNALS = [
|
|
327
|
+
"SIGINT",
|
|
328
|
+
"SIGTERM",
|
|
329
|
+
"SIGHUP"
|
|
330
|
+
];
|
|
331
|
+
var Startup = class {
|
|
332
|
+
claims = [];
|
|
333
|
+
closers = [];
|
|
334
|
+
closing = null;
|
|
335
|
+
hooked = null;
|
|
336
|
+
say = null;
|
|
337
|
+
marks = [];
|
|
338
|
+
/** What a signal says before it ends the process (dev.ts: once the canvas serves, that it stopped). Synchronous. */
|
|
339
|
+
onSignal(say) {
|
|
340
|
+
this.say = say;
|
|
341
|
+
}
|
|
342
|
+
/** What a close says first, as it is asked for and before anything closes (dev.ts: the slot file, `closing`).
|
|
343
|
+
* Synchronous; each runs once, and a failure to say it never holds the close. */
|
|
344
|
+
onClose(mark) {
|
|
345
|
+
this.marks.push(mark);
|
|
346
|
+
}
|
|
347
|
+
/** A file held: given back on every way out. */
|
|
348
|
+
claim(release) {
|
|
349
|
+
this.claims.push(release);
|
|
350
|
+
}
|
|
351
|
+
/** Something running: closed on a failed start or a close. The answer withdraws it, for what has closed on
|
|
352
|
+
* its own first - the Vite server a restart replaced, and the watchers that went with it. */
|
|
353
|
+
defer(close) {
|
|
354
|
+
this.closers.push(close);
|
|
355
|
+
return () => {
|
|
356
|
+
const i = this.closers.indexOf(close);
|
|
357
|
+
if (i >= 0) this.closers.splice(i, 1);
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/** Give back every claim, newest first. Synchronous; each runs once. */
|
|
361
|
+
release() {
|
|
362
|
+
for (const r of this.claims.splice(0).reverse()) try {
|
|
363
|
+
r();
|
|
364
|
+
} catch {}
|
|
365
|
+
}
|
|
366
|
+
/** Say it is closing (synchronously, in this call), close what runs, newest first and awaited, then what `until`
|
|
367
|
+
* waits for (dev.ts: every restart's own server, to its last cleanup), and only then give back the claims.
|
|
368
|
+
* Idempotent: Vite's own SIGTERM path and an embedding caller's `server.close()` can both reach it - the first
|
|
369
|
+
* close's `until` is the one. */
|
|
370
|
+
close(until) {
|
|
371
|
+
this.closing ??= (async () => {
|
|
372
|
+
for (const m of this.marks.splice(0)) try {
|
|
373
|
+
m();
|
|
374
|
+
} catch {}
|
|
375
|
+
for (const c of this.closers.splice(0).reverse()) try {
|
|
376
|
+
await c();
|
|
377
|
+
} catch {}
|
|
378
|
+
if (until) try {
|
|
379
|
+
await until();
|
|
380
|
+
} catch {}
|
|
381
|
+
this.release();
|
|
382
|
+
this.unhook();
|
|
383
|
+
})();
|
|
384
|
+
return this.closing;
|
|
385
|
+
}
|
|
386
|
+
/** From the first step: an exit gives the claims back; SIGINT, SIGTERM and SIGHUP give them back and
|
|
387
|
+
* raise the signal again, so the process still ends the way it was told to. */
|
|
388
|
+
hookProcess() {
|
|
389
|
+
if (this.hooked) return;
|
|
390
|
+
const exit = () => this.release();
|
|
391
|
+
const signal = (sig) => {
|
|
392
|
+
try {
|
|
393
|
+
this.say?.();
|
|
394
|
+
} catch {}
|
|
395
|
+
this.release();
|
|
396
|
+
this.unhook();
|
|
397
|
+
process.kill(process.pid, sig);
|
|
398
|
+
};
|
|
399
|
+
process.once("exit", exit);
|
|
400
|
+
for (const s of SIGNALS) process.once(s, signal);
|
|
401
|
+
this.hooked = {
|
|
402
|
+
exit,
|
|
403
|
+
signal
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
unhook() {
|
|
407
|
+
if (!this.hooked) return;
|
|
408
|
+
process.off("exit", this.hooked.exit);
|
|
409
|
+
for (const s of SIGNALS) process.off(s, this.hooked.signal);
|
|
410
|
+
this.hooked = null;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/server/dev.ts
|
|
415
|
+
/** packageDir = the installed marver package root (dist/cli.js lives one level down). */
|
|
416
|
+
function packageDir() {
|
|
417
|
+
return join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
418
|
+
}
|
|
419
|
+
/** realpath, or the path itself when it cannot be resolved (never throws at boot). */
|
|
420
|
+
const safeReal = (p) => {
|
|
421
|
+
try {
|
|
422
|
+
return realpathSync(p);
|
|
423
|
+
} catch {
|
|
424
|
+
return p;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* What the dev server must never hand out, however deep in the repo it sits.
|
|
429
|
+
*
|
|
430
|
+
* `marver dev` puts the whole repository on the web so frames can import from it.
|
|
431
|
+
* The collaboration credential no longer lives in there - it moved to
|
|
432
|
+
* ~/.marver/canvases/ precisely because guarding it here could not be finished -
|
|
433
|
+
* but design/.local still holds the local profile and whatever a previous version
|
|
434
|
+
* left behind, and none of that is anybody's business but the author's.
|
|
435
|
+
*
|
|
436
|
+
* Vite's own defaults are restated rather than assumed. `fs.deny` REPLACES the
|
|
437
|
+
* default list, so an array containing only our own rule quietly re-exposes
|
|
438
|
+
* `.env`, private keys, `.npmrc` and `.git` - a much larger hole than the one
|
|
439
|
+
* being closed, opened by closing it. Kept as an exported constant so a test can
|
|
440
|
+
* hold both halves.
|
|
441
|
+
*/
|
|
442
|
+
const FS_DENY = [
|
|
443
|
+
".env",
|
|
444
|
+
".env.*",
|
|
445
|
+
"*.{crt,pem,key,p12,pfx,cer,der}",
|
|
446
|
+
".npmrc",
|
|
447
|
+
".yarnrc.yml",
|
|
448
|
+
"**/.git/**",
|
|
449
|
+
".dev.vars",
|
|
450
|
+
".dev.vars.*",
|
|
451
|
+
"**/design/.local/**"
|
|
452
|
+
];
|
|
453
|
+
/**
|
|
454
|
+
* The half of the credential guard that globs cannot do.
|
|
455
|
+
*
|
|
456
|
+
* `fs.deny` matches the REQUEST path, lexically, and then Vite stats and streams
|
|
457
|
+
* whatever that path resolves to. So a repository containing
|
|
458
|
+
* `leak.json -> design/.local/anything` serves that file at `/leak.json` to any
|
|
459
|
+
* authored frame that asks - the deny rule never sees the name it is looking for.
|
|
460
|
+
* Verified against a real dev server before this existed.
|
|
461
|
+
*
|
|
462
|
+
* More patterns cannot fix that; only resolving can. This runs BEFORE Vite's own
|
|
463
|
+
* middlewares (a `configureServer` hook that does not return a function is
|
|
464
|
+
* installed first) and refuses any request whose real file lands inside
|
|
465
|
+
* design/.local, whatever route it took to get there.
|
|
466
|
+
*
|
|
467
|
+
* "Whatever route" means every place Vite would look, not just the project root.
|
|
468
|
+
* `public/` is mapped onto `/`, so `public/leak.json -> ../design/.local/x` is
|
|
469
|
+
* served at `/leak.json` - and Vite skips its own deny checks entirely for public
|
|
470
|
+
* files, so that spelling was reachable even with the root candidate guarded.
|
|
471
|
+
* Each candidate is resolved; if any lands in design/.local, the request is
|
|
472
|
+
* refused.
|
|
473
|
+
*
|
|
474
|
+
* The boundary this does NOT claim: a repository that can write symlinks can also
|
|
475
|
+
* write `design/config.ts`, which `marver dev` imports and RUNS in this process
|
|
476
|
+
* before any of the above exists. Running `dev` on a repository you do not trust
|
|
477
|
+
* hands it your machine long before it hands it a file, so a symlink is not the
|
|
478
|
+
* interesting way in. What this closes is the frame-in-a-trusted-repo case: a
|
|
479
|
+
* component that runs in the browser, same-origin, that can only ask for URLs and
|
|
480
|
+
* cannot create a file to ask for.
|
|
481
|
+
*
|
|
482
|
+
* The registry is guarded the same way (spec 28 A1.13 #5): ~/.marver/running/ holds each running
|
|
483
|
+
* canvas's proof key and canvases/ the collaboration credentials, and a host whose workspace root is the
|
|
484
|
+
* home folder - or a MARVER_HOME inside the repository - would otherwise put them in reach of `/@fs/`.
|
|
485
|
+
* Both are guarded when MARVER_HOME moves this run's: the one it writes, and the one in the home folder.
|
|
486
|
+
* Guarded at every way Vite finds a file, not only at the request's own path: Vite resolves an
|
|
487
|
+
* extensionless `?import` (`/.mv-home/running/slot-1?import` is slot-1.json) and a directory's index, so the
|
|
488
|
+
* guard looks where a missing path would land; and the homes are in `fs.deny` (registryDeny) and refused by
|
|
489
|
+
* this plugin's own `load`, so no query (`?import`, `?raw`, `?url`, `?inline`) and no spelling of the id that
|
|
490
|
+
* reaches Vite's module pipeline (`/@fs/`, `/@id/`) loads one of their files.
|
|
491
|
+
*/
|
|
492
|
+
function denyLocalSecrets(root) {
|
|
493
|
+
const guardedAt = join(root, "design", ".local");
|
|
494
|
+
const homes = registryHomes();
|
|
495
|
+
const publicAt = join(root, "public");
|
|
496
|
+
const real = (d) => {
|
|
497
|
+
try {
|
|
498
|
+
return realpathSync(d);
|
|
499
|
+
} catch {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
/** what a resolved path is inside: design/.local, a registry home, or nothing */
|
|
504
|
+
const refusal = (reals) => {
|
|
505
|
+
const local = real(guardedAt);
|
|
506
|
+
if (local && reals.some((r) => inside(r, local))) return "design/.local holds this canvas's credentials and is never served";
|
|
507
|
+
for (const h of homes) {
|
|
508
|
+
const home = real(h);
|
|
509
|
+
if (home && reals.some((r) => inside(r, home))) return "the canvas registry (~/.marver) is never served";
|
|
510
|
+
}
|
|
511
|
+
return null;
|
|
512
|
+
};
|
|
513
|
+
return {
|
|
514
|
+
name: "marver:deny-local-secrets",
|
|
515
|
+
configureServer(server) {
|
|
516
|
+
server.middlewares.use((req, res, next) => {
|
|
517
|
+
let pathname;
|
|
518
|
+
try {
|
|
519
|
+
pathname = decodeURIComponent((req.url ?? "/").split("?")[0].split("#")[0]);
|
|
520
|
+
} catch {
|
|
521
|
+
return next();
|
|
522
|
+
}
|
|
523
|
+
const rel = "." + (pathname.startsWith("/") ? pathname : `/${pathname}`);
|
|
524
|
+
const id = pathname.startsWith("/@id/") ? pathname.slice(5) : null;
|
|
525
|
+
const bases = pathname.startsWith("/@fs/") ? [pathname.slice(4)] : id !== null ? [...id.startsWith("/") ? [resolve(id)] : [], resolve(root, "." + (id.startsWith("/") ? id : `/${id}`))] : [resolve(root, rel), resolve(publicAt, rel)];
|
|
526
|
+
const why = refusal(bases.flatMap(resolvedAs));
|
|
527
|
+
if (!why) return next();
|
|
528
|
+
res.statusCode = 403;
|
|
529
|
+
res.setHeader("content-type", "text/plain; charset=utf-8");
|
|
530
|
+
res.end(why);
|
|
531
|
+
});
|
|
532
|
+
},
|
|
533
|
+
load: {
|
|
534
|
+
order: "pre",
|
|
535
|
+
handler(id) {
|
|
536
|
+
const file = id.split("?")[0].split("#")[0];
|
|
537
|
+
if (!isAbsolute(file)) return null;
|
|
538
|
+
const at = landing(file);
|
|
539
|
+
const why = at === null ? null : refusal([at]);
|
|
540
|
+
if (why) throw new Error(why);
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/** Vite's default `resolve.extensions`: an extensionless import is tried with each, in this order. */
|
|
547
|
+
const VITE_EXTENSIONS = [
|
|
548
|
+
".mjs",
|
|
549
|
+
".js",
|
|
550
|
+
".mts",
|
|
551
|
+
".ts",
|
|
552
|
+
".jsx",
|
|
553
|
+
".tsx",
|
|
554
|
+
".json"
|
|
555
|
+
];
|
|
556
|
+
const inside = (real, dir) => {
|
|
557
|
+
const rel = relative(dir, real);
|
|
558
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
559
|
+
};
|
|
560
|
+
/**
|
|
561
|
+
* Where a path lands once links are followed, whether or not it exists: the real path of its nearest
|
|
562
|
+
* existing folder with the rest of the path after it. Vite's resolution only ever adds to the last name
|
|
563
|
+
* (an extension, `/index`), so a path whose folder is inside a guarded one lands inside it, whatever
|
|
564
|
+
* Vite then tries.
|
|
565
|
+
*/
|
|
566
|
+
function landing(p) {
|
|
567
|
+
let dir = p;
|
|
568
|
+
let rest = "";
|
|
569
|
+
for (;;) {
|
|
570
|
+
try {
|
|
571
|
+
return rest ? join(realpathSync(dir), rest) : realpathSync(dir);
|
|
572
|
+
} catch {}
|
|
573
|
+
const up = dirname(dir);
|
|
574
|
+
if (up === dir) return null;
|
|
575
|
+
rest = rest ? join(basename(dir), rest) : basename(dir);
|
|
576
|
+
dir = up;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* The real files a request path can be served as. Vite derives more paths than it is asked for: a
|
|
581
|
+
* missing `/leak` can resolve to `leak.html` or, as an import, `leak.json` (every one of Vite's
|
|
582
|
+
* extensions); a folder to its `index` (`index.html`, `index.json`, ...). Enumerating a bundler's
|
|
583
|
+
* resolution rules is not a game anyone wins, which is why the credential itself lives outside the
|
|
584
|
+
* repository and the registry is also in `fs.deny` and refused at `load` - this list is depth, not the
|
|
585
|
+
* defence. It covers the derivations Vite actually applies, and where a missing path would land.
|
|
586
|
+
*/
|
|
587
|
+
function resolvedAs(base) {
|
|
588
|
+
const at = (p) => {
|
|
589
|
+
try {
|
|
590
|
+
return realpathSync(p);
|
|
591
|
+
} catch {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const isDir = (p) => {
|
|
596
|
+
try {
|
|
597
|
+
return statSync(p).isDirectory();
|
|
598
|
+
} catch {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
const found = at(base);
|
|
603
|
+
if (found !== null) {
|
|
604
|
+
if (!isDir(found)) return [found];
|
|
605
|
+
return [found, ...[
|
|
606
|
+
"",
|
|
607
|
+
".html",
|
|
608
|
+
...VITE_EXTENSIONS
|
|
609
|
+
].map((e) => at(join(base, `index${e}`))).filter((r) => r !== null)];
|
|
610
|
+
}
|
|
611
|
+
const lands = landing(base);
|
|
612
|
+
return [...lands ? [lands] : [], ...[".html", ...VITE_EXTENSIONS].map((e) => at(`${base}${e}`)).filter((r) => r !== null)];
|
|
613
|
+
}
|
|
614
|
+
/** The registry's homes (A1.13 #5): this run's MARVER_HOME and the ~/.marver in the home folder, each as
|
|
615
|
+
* given and as its real path (a request names the one, Vite resolves ids to the other). */
|
|
616
|
+
function registryHomes() {
|
|
617
|
+
return [...new Set([marverHome(), join(homedir(), ".marver")].flatMap((h) => [resolve(h), safeReal(resolve(h))]))];
|
|
618
|
+
}
|
|
619
|
+
/** The homes as `fs.deny` globs - each folder and everything in it, its name matched literally - so Vite's
|
|
620
|
+
* own file serving and module loading refuse them too, by the resolved path it checks. */
|
|
621
|
+
function registryDeny(homes = registryHomes()) {
|
|
622
|
+
const literal = (p) => p.replace(/[\\*?[\]{}()!+@|]/g, "\\$&");
|
|
623
|
+
return homes.flatMap((h) => [literal(h), `${literal(h)}/**`]);
|
|
624
|
+
}
|
|
625
|
+
/** The canvas did not start: what failed, said - everything the start held is given back first. */
|
|
626
|
+
var DevStartError = class extends Error {};
|
|
627
|
+
/** A canvas already runs in this folder (or one is starting): the line says where, or what to do. */
|
|
628
|
+
var DevLockError = class extends DevStartError {};
|
|
629
|
+
/** The line for a file watcher that fails: `fs.watch` in a sandbox (Codex's: every one fails with EMFILE), or a
|
|
630
|
+
* system's watch limit. */
|
|
631
|
+
const cannotWatch = (err) => `${NAME} dev cannot watch this folder (${err?.message ?? err}) - in a sandbox? ask the person to run npx ${NAME} dev in their own terminal`;
|
|
632
|
+
function watchGuard(onFail) {
|
|
633
|
+
let failed = null;
|
|
634
|
+
let close = null;
|
|
635
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
636
|
+
const fail = (err) => {
|
|
637
|
+
if (failed) return;
|
|
638
|
+
const e = failed = new DevStartError(cannotWatch(err), { cause: err });
|
|
639
|
+
if (close) close().catch(() => {}).then(() => (onFail ?? ((x) => console.error(`\n ${x.message}\n`)))(e));
|
|
640
|
+
};
|
|
641
|
+
return {
|
|
642
|
+
add(w) {
|
|
643
|
+
if (!seen.has(w)) {
|
|
644
|
+
seen.add(w);
|
|
645
|
+
w.on("error", fail);
|
|
646
|
+
}
|
|
647
|
+
return w;
|
|
648
|
+
},
|
|
649
|
+
check() {
|
|
650
|
+
if (failed) throw failed;
|
|
651
|
+
},
|
|
652
|
+
serving(c) {
|
|
653
|
+
close = c;
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
/** Said when a signal (Ctrl-C, a kill) stops a canvas that served: an open tab holds its edits until it is back. */
|
|
658
|
+
const STOPPED = "canvas stopped - open tabs keep their edits and save when it is back";
|
|
659
|
+
/**
|
|
660
|
+
* Start the canvas (spec 28 A1.1): 1. dev.lock, 2. an address - a slot, a port of its own, or
|
|
661
|
+
* --recover's - held as a file, 3. Vite's server, 4. listening on exactly that port, 5. published: the
|
|
662
|
+
* slot file as ready, dev.json, 6. the close (the slot file `closing` first). Every step's claims belong to one Startup, so a failure
|
|
663
|
+
* anywhere closes what was made and gives back what was held, and `dev()` rejects with a DevStartError -
|
|
664
|
+
* it never ends the process itself (the CLI does, A1.13 #4), so an embedding caller is left clean.
|
|
665
|
+
*/
|
|
666
|
+
async function dev(root, opts = {}) {
|
|
667
|
+
const t = new Startup();
|
|
668
|
+
t.hookProcess();
|
|
669
|
+
const watch = watchGuard(opts.onFail);
|
|
670
|
+
let served = false;
|
|
671
|
+
try {
|
|
672
|
+
const { takeDevLock } = await import("./dev-lock-C_FC70Mu.mjs");
|
|
673
|
+
const lock = await takeDevLock(root, { onTaken: (release) => t.claim(release) });
|
|
674
|
+
if (!lock.ok) throw new DevLockError(lock.message);
|
|
675
|
+
const ranBefore = ranDevBefore(root);
|
|
676
|
+
t.claim(() => {
|
|
677
|
+
if (!served && !ranBefore) forgetDevTraces(root);
|
|
678
|
+
});
|
|
679
|
+
await opts.at?.("locked");
|
|
680
|
+
const server = await boot(root, opts, lock.instance, t, {
|
|
681
|
+
ranBefore,
|
|
682
|
+
watch
|
|
683
|
+
});
|
|
684
|
+
watch.check();
|
|
685
|
+
watch.serving(() => server.close());
|
|
686
|
+
t.onSignal(() => {
|
|
687
|
+
try {
|
|
688
|
+
writeSync(1, `\n ${STOPPED}\n\n`);
|
|
689
|
+
} catch {}
|
|
690
|
+
});
|
|
691
|
+
served = true;
|
|
692
|
+
return server;
|
|
693
|
+
} catch (err) {
|
|
694
|
+
await t.close();
|
|
695
|
+
if (err instanceof DevStartError) throw err;
|
|
696
|
+
throw new DevStartError(`the canvas could not start: ${err?.message ?? err}`, { cause: err });
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
async function boot(root, opts, instance, t, ctx) {
|
|
700
|
+
const { watch: watch$1 } = ctx;
|
|
701
|
+
const config = await loadConfig(root);
|
|
702
|
+
const host = detectHost(root);
|
|
703
|
+
const pkgDir = packageDir();
|
|
704
|
+
const clientDir = join(pkgDir, "src", "client");
|
|
705
|
+
const projectName = basename(root);
|
|
706
|
+
const run = runIdentity(root, opts.recover?.ws);
|
|
707
|
+
const fromConfig = opts.port === void 0 && !opts.recover && config.port !== 5199 ? config.port : void 0;
|
|
708
|
+
const explicitPort = opts.port ?? fromConfig;
|
|
709
|
+
const placed = await place({
|
|
710
|
+
root: run.root,
|
|
711
|
+
name: config.share.name || basename(run.root),
|
|
712
|
+
version: installedVersion() ?? "0.0.0",
|
|
713
|
+
id: run.id,
|
|
714
|
+
ws: run.ws,
|
|
715
|
+
instance,
|
|
716
|
+
onHold: (release) => t.claim(release),
|
|
717
|
+
...opts.recover ? { recover: { port: opts.recover.port } } : explicitPort !== void 0 ? { explicit: {
|
|
718
|
+
port: explicitPort,
|
|
719
|
+
from: fromConfig !== void 0 ? "config" : "flag"
|
|
720
|
+
} } : {}
|
|
721
|
+
});
|
|
722
|
+
if (!placed.ok) throw new DevStartError(placed.message);
|
|
723
|
+
const { claim } = placed;
|
|
724
|
+
t.onClose(() => claim.closing());
|
|
725
|
+
for (const n of placed.notes) console.log(` ${n}`);
|
|
726
|
+
await opts.at?.("claimed", { port: claim.port });
|
|
727
|
+
const esc = (p) => join(p, "design").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
728
|
+
const designDir = new RegExp(`^(${[.../* @__PURE__ */ new Set([root, safeReal(root)])].map(esc).join("|")})[/\\\\]`);
|
|
729
|
+
const plugins = [denyLocalSecrets(root), react({ exclude: [/\/node_modules\//, designDir] })];
|
|
730
|
+
if (config.jam?.loc !== false) plugins.unshift(locPlugin(root));
|
|
731
|
+
if (host.tailwind === 4) {
|
|
732
|
+
const tw = await tailwind4Plugin(root);
|
|
733
|
+
if (tw) plugins.push(...tw);
|
|
734
|
+
else console.warn(`[marver] tailwindcss v4 detected but @tailwindcss/vite could not be loaded - utility classes WILL be missing from frames. Fix: npm i -D @tailwindcss/vite (used only by the canvas, never by your app's build).`);
|
|
735
|
+
}
|
|
736
|
+
let css;
|
|
737
|
+
if (host.tailwind === 3) css = await tailwind3Css(root) ?? void 0;
|
|
738
|
+
const constructions = /* @__PURE__ */ new WeakMap();
|
|
739
|
+
let latest = null;
|
|
740
|
+
let closeVite = async () => {};
|
|
741
|
+
let inPlace = false;
|
|
742
|
+
/** the start's end, once asked for (step 6) */
|
|
743
|
+
let ending = null;
|
|
744
|
+
/** the restart whose Vite run is on its way (step 6): its new server being made, put in place, listening */
|
|
745
|
+
let replacing = null;
|
|
746
|
+
/** every restart not over yet, from its start to its last cleanup - a failed construction's close included (step 6) */
|
|
747
|
+
const restarts = /* @__PURE__ */ new Set();
|
|
748
|
+
const dispose = async (c) => {
|
|
749
|
+
if (opts.at) await opts.at("dispose");
|
|
750
|
+
if (c.close) await c.close().catch(() => {});
|
|
751
|
+
else {
|
|
752
|
+
await Promise.allSettled([...c.envs].map(async (env) => {
|
|
753
|
+
try {
|
|
754
|
+
await env.close();
|
|
755
|
+
} catch {
|
|
756
|
+
await env.depsOptimizer?.close();
|
|
757
|
+
}
|
|
758
|
+
}));
|
|
759
|
+
await Promise.allSettled([...c.parts].map(async (p) => p.close()));
|
|
760
|
+
}
|
|
761
|
+
for (const fn of [...c.mine].reverse()) try {
|
|
762
|
+
await fn();
|
|
763
|
+
} catch {}
|
|
764
|
+
if (opts.at) await opts.at("disposed");
|
|
765
|
+
};
|
|
766
|
+
const own = (c) => {
|
|
767
|
+
if (!c.left && !ending) c.withdraw ??= t.defer(() => dispose(c));
|
|
768
|
+
};
|
|
769
|
+
/** A construction is over: its server serves (the start's place closes it from now - at once, in this turn), or it
|
|
770
|
+
* never will - it threw, or the start ended while a restart made it (closed now). */
|
|
771
|
+
const settle = (c, serves) => {
|
|
772
|
+
c.withdraw?.();
|
|
773
|
+
c.withdraw = null;
|
|
774
|
+
if (serves) c.mine.clear();
|
|
775
|
+
else return dispose(c);
|
|
776
|
+
};
|
|
777
|
+
plugins.push(...marverPlugin({
|
|
778
|
+
root,
|
|
779
|
+
clientDir,
|
|
780
|
+
config,
|
|
781
|
+
detectedThemeCss: host.themeCss,
|
|
782
|
+
workspace: run.ws,
|
|
783
|
+
startup: {
|
|
784
|
+
defer(fn, vite) {
|
|
785
|
+
const c = vite ? constructions.get(vite.config) : void 0;
|
|
786
|
+
if (!c) return t.defer(fn);
|
|
787
|
+
let done = false;
|
|
788
|
+
const once = () => {
|
|
789
|
+
if (done) return;
|
|
790
|
+
done = true;
|
|
791
|
+
c.mine.delete(once);
|
|
792
|
+
return fn();
|
|
793
|
+
};
|
|
794
|
+
c.mine.add(once);
|
|
795
|
+
const withdraw = t.defer(once);
|
|
796
|
+
return () => {
|
|
797
|
+
c.mine.delete(once);
|
|
798
|
+
withdraw();
|
|
799
|
+
};
|
|
800
|
+
},
|
|
801
|
+
watch: watch$1.add
|
|
802
|
+
},
|
|
803
|
+
proof: {
|
|
804
|
+
instance,
|
|
805
|
+
key: claim.key,
|
|
806
|
+
port: claim.port
|
|
807
|
+
}
|
|
808
|
+
}), iconsPlugin(root));
|
|
809
|
+
plugins.unshift({
|
|
810
|
+
name: "marver:startup-owns-server",
|
|
811
|
+
configResolved(resolved) {
|
|
812
|
+
const c = {
|
|
813
|
+
envs: /* @__PURE__ */ new Set(),
|
|
814
|
+
parts: /* @__PURE__ */ new Set(),
|
|
815
|
+
close: null,
|
|
816
|
+
mine: /* @__PURE__ */ new Set(),
|
|
817
|
+
withdraw: null,
|
|
818
|
+
left: false
|
|
819
|
+
};
|
|
820
|
+
constructions.set(resolved, c);
|
|
821
|
+
latest = c;
|
|
822
|
+
for (const env of Object.values(resolved.environments)) {
|
|
823
|
+
const make = env.dev?.createEnvironment;
|
|
824
|
+
if (!make) continue;
|
|
825
|
+
env.dev.createEnvironment = async (name, config, context) => {
|
|
826
|
+
const made = await make(name, config, context);
|
|
827
|
+
own(c);
|
|
828
|
+
c.envs.add(made);
|
|
829
|
+
if (context.ws) c.parts.add(context.ws);
|
|
830
|
+
const init = made.init.bind(made);
|
|
831
|
+
made.init = (o) => {
|
|
832
|
+
if (o?.watcher) {
|
|
833
|
+
c.parts.add(o.watcher);
|
|
834
|
+
watch$1.add(o.watcher);
|
|
835
|
+
}
|
|
836
|
+
return init(o);
|
|
837
|
+
};
|
|
838
|
+
return made;
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
},
|
|
842
|
+
configureServer: {
|
|
843
|
+
order: "pre",
|
|
844
|
+
handler(vite) {
|
|
845
|
+
const c = constructions.get(vite.config);
|
|
846
|
+
if (!c) return;
|
|
847
|
+
c.close = vite.close.bind(vite);
|
|
848
|
+
own(c);
|
|
849
|
+
const http = vite.httpServer;
|
|
850
|
+
if (http) {
|
|
851
|
+
const listen = http.listen;
|
|
852
|
+
http.listen = function(...args) {
|
|
853
|
+
if (!ending) return listen.apply(this, args);
|
|
854
|
+
process.nextTick(() => http.emit("error", /* @__PURE__ */ new Error("the canvas has closed")));
|
|
855
|
+
return this;
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
if (inPlace) return;
|
|
859
|
+
inPlace = true;
|
|
860
|
+
closeVite = c.close;
|
|
861
|
+
c.withdraw?.();
|
|
862
|
+
c.withdraw = null;
|
|
863
|
+
t.defer(() => closeVite());
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
if (opts.at) {
|
|
868
|
+
let env = false;
|
|
869
|
+
plugins.push({
|
|
870
|
+
name: "marver:startup-probe",
|
|
871
|
+
configResolved() {
|
|
872
|
+
env = false;
|
|
873
|
+
},
|
|
874
|
+
async options() {
|
|
875
|
+
if (!env) {
|
|
876
|
+
env = true;
|
|
877
|
+
await opts.at("env");
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
async configureServer() {
|
|
881
|
+
await opts.at("configure");
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
const logger = createLogger("info");
|
|
886
|
+
const noise = (msg) => /Sourcemap for .*node_modules.*points to/.test(msg);
|
|
887
|
+
const warnBase = logger.warn.bind(logger);
|
|
888
|
+
const warnOnceBase = logger.warnOnce.bind(logger);
|
|
889
|
+
logger.warn = (msg, opts) => {
|
|
890
|
+
if (!noise(msg)) warnBase(msg, opts);
|
|
891
|
+
};
|
|
892
|
+
logger.warnOnce = (msg, opts) => {
|
|
893
|
+
if (!noise(msg)) warnOnceBase(msg, opts);
|
|
894
|
+
};
|
|
895
|
+
const server = await createServer({
|
|
896
|
+
configFile: false,
|
|
897
|
+
root,
|
|
898
|
+
cacheDir: join(root, "node_modules", ".vite-marver"),
|
|
899
|
+
css,
|
|
900
|
+
customLogger: logger,
|
|
901
|
+
plugins,
|
|
902
|
+
server: {
|
|
903
|
+
port: claim.port,
|
|
904
|
+
strictPort: true,
|
|
905
|
+
...opts.recover?.host ? { host: opts.recover.host } : {},
|
|
906
|
+
hmr: { overlay: false },
|
|
907
|
+
fs: {
|
|
908
|
+
allow: [.../* @__PURE__ */ new Set([
|
|
909
|
+
root,
|
|
910
|
+
safeReal(root),
|
|
911
|
+
pkgDir,
|
|
912
|
+
safeReal(pkgDir),
|
|
913
|
+
searchForWorkspaceRoot(root)
|
|
914
|
+
])],
|
|
915
|
+
deny: [...FS_DENY, ...registryDeny()]
|
|
916
|
+
},
|
|
917
|
+
watch: { ignored: [
|
|
918
|
+
"**/design/manifest.json",
|
|
919
|
+
"**/design/boards/**",
|
|
920
|
+
"**/design/.local/**",
|
|
921
|
+
"**/design/.dist/**",
|
|
922
|
+
"**/design/comments/**",
|
|
923
|
+
"**/.next/**",
|
|
924
|
+
"**/.turbo/**",
|
|
925
|
+
"**/.vercel/**",
|
|
926
|
+
"**/.output/**",
|
|
927
|
+
"**/dist/**",
|
|
928
|
+
"**/build/**",
|
|
929
|
+
"**/out/**",
|
|
930
|
+
"**/coverage/**",
|
|
931
|
+
"**/.gstack/**",
|
|
932
|
+
"**/.git/**",
|
|
933
|
+
"**/.playwright-mcp/**",
|
|
934
|
+
"**/context/map.json",
|
|
935
|
+
"**/context/sync/**"
|
|
936
|
+
] },
|
|
937
|
+
warmup: { clientFiles: [
|
|
938
|
+
join(clientDir, "frame-host", "main.tsx"),
|
|
939
|
+
join(clientDir, "frame-host", "bridge.js"),
|
|
940
|
+
join(clientDir, "content", "index.tsx"),
|
|
941
|
+
join(clientDir, "content", "diagram.tsx"),
|
|
942
|
+
join(clientDir, "content", "md.ts")
|
|
943
|
+
] }
|
|
944
|
+
},
|
|
945
|
+
resolve: {
|
|
946
|
+
dedupe: ["react", "react-dom"],
|
|
947
|
+
tsconfigPaths: true
|
|
948
|
+
},
|
|
949
|
+
optimizeDeps: {
|
|
950
|
+
exclude: [PKG],
|
|
951
|
+
include: [
|
|
952
|
+
"react",
|
|
953
|
+
"react-dom",
|
|
954
|
+
"react-dom/client",
|
|
955
|
+
"react/jsx-runtime",
|
|
956
|
+
"react/jsx-dev-runtime",
|
|
957
|
+
`${PKG} > marked`,
|
|
958
|
+
`${PKG} > mermaid`,
|
|
959
|
+
`${PKG} > roughjs`,
|
|
960
|
+
`${PKG} > html-to-image`,
|
|
961
|
+
`${PKG} > echarts/core`,
|
|
962
|
+
`${PKG} > echarts/renderers`,
|
|
963
|
+
`${PKG} > echarts/charts`,
|
|
964
|
+
`${PKG} > echarts/components`,
|
|
965
|
+
...iconModules(root)
|
|
966
|
+
],
|
|
967
|
+
entries: [join(clientDir, "frame-host", "index.html"), "design/**/*.{tsx,jsx}"]
|
|
968
|
+
},
|
|
969
|
+
logLevel: "info"
|
|
970
|
+
});
|
|
971
|
+
const first = constructions.get(server.config);
|
|
972
|
+
if (first) settle(first, true);
|
|
973
|
+
/** what holds the HTTP server itself, put back on the new one after a restart (step 6) */
|
|
974
|
+
const onRestart = [];
|
|
975
|
+
await opts.at?.("created");
|
|
976
|
+
watch$1.check();
|
|
977
|
+
try {
|
|
978
|
+
await server.listen();
|
|
979
|
+
} catch (err) {
|
|
980
|
+
if (opts.recover) throw new DevStartError(`--recover could not bind ${opts.recover.bind}: ${err?.message ?? err} - it never takes another address`, { cause: err });
|
|
981
|
+
if (/is already in use/.test(String(err?.message)) || err?.code === "EADDRINUSE") throw new DevStartError(`port ${claim.port} was just taken by another program - start again`, { cause: err });
|
|
982
|
+
throw err;
|
|
983
|
+
}
|
|
984
|
+
await opts.at?.("listening");
|
|
985
|
+
watch$1.check();
|
|
986
|
+
const port = claim.port;
|
|
987
|
+
const origin = originOf(server.httpServer?.address()) ?? `http://localhost:${port}`;
|
|
988
|
+
claim.ready(origin);
|
|
989
|
+
const { workActivity, writeDevInfo, removeDevInfo, boardsShowing, onBoardsChanged, nextActivitySeq } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
|
|
990
|
+
t.claim(() => removeDevInfo(root, instance));
|
|
991
|
+
writeDevInfo(root, port, instance);
|
|
992
|
+
await opts.at?.("published");
|
|
993
|
+
watch$1.check();
|
|
994
|
+
if (placed.fellBackFrom) console.log(`\n port ${placed.fellBackFrom} is in use - serving "${projectName}" on slot ${claim.slot} instead`);
|
|
995
|
+
console.log(`\n ${NAME} · ${projectName} → http://localhost:${port}/\n`);
|
|
996
|
+
const address = {
|
|
997
|
+
slot: claim.slot,
|
|
998
|
+
url: claim.url,
|
|
999
|
+
bind: origin,
|
|
1000
|
+
ws: run.ws
|
|
1001
|
+
};
|
|
1002
|
+
if (opts.recover) console.log(` recovering: open ${opts.recover.url} in the browser that made the capture (the app loads ${opts.recover.bind}) - with Live Jam on, a capture waiting there sends itself; then stop this canvas (Ctrl-C)\n`);
|
|
1003
|
+
else try {
|
|
1004
|
+
const { first, previous } = notePrefer(run.id, address);
|
|
1005
|
+
t.claim(() => stopPrefer(run.id, address));
|
|
1006
|
+
const lines = startedWhere({
|
|
1007
|
+
root,
|
|
1008
|
+
run: address,
|
|
1009
|
+
port,
|
|
1010
|
+
first,
|
|
1011
|
+
previous,
|
|
1012
|
+
ranBefore: ctx.ranBefore
|
|
1013
|
+
});
|
|
1014
|
+
if (lines.length) console.log(`${lines.map((l) => ` ${l}`).join("\n")}\n`);
|
|
1015
|
+
} catch (err) {
|
|
1016
|
+
console.warn(`[${NAME}] could not record this canvas's address (${err.message}) - it runs; next time it may take another slot`);
|
|
1017
|
+
}
|
|
1018
|
+
if (fromConfig !== void 0 && !placed.fellBackFrom) console.log(` this canvas keeps its own port (${fromConfig} in design/config.ts); remove it to use the slots\n`);
|
|
1019
|
+
setTimeout(async () => {
|
|
1020
|
+
try {
|
|
1021
|
+
await (await import("./shot-Ch24tiMO.mjs").then((n) => n.u)).sweepGhosts((m) => console.log(` ${m}`));
|
|
1022
|
+
} catch {}
|
|
1023
|
+
}, 0);
|
|
1024
|
+
try {
|
|
1025
|
+
const { staleManagedInstructions } = await import("./managed-HwHVNI3h.mjs");
|
|
1026
|
+
const stale = staleManagedInstructions(root);
|
|
1027
|
+
if (stale.length) {
|
|
1028
|
+
const shown = stale.slice(0, 4).join(", ") + (stale.length > 4 ? `, +${stale.length - 4} more` : "");
|
|
1029
|
+
const v = installedVersion();
|
|
1030
|
+
console.log(` instructions predate ${v ? NAME + " " + v : "the installed version"} (${shown}) - run: npx ${NAME} init\n`);
|
|
1031
|
+
}
|
|
1032
|
+
} catch {}
|
|
1033
|
+
try {
|
|
1034
|
+
if (!existsSync(join(root, "context"))) {
|
|
1035
|
+
const n = (await import("./manifest-aFyDmL8C.mjs").then((n) => n.i)).statusBoards(root).length;
|
|
1036
|
+
if (n) console.log(` ${n} feature/project board${n === 1 ? "" : "s"}, no context/ - every status reads Backlog. To start it, tell your agent: "Set up our context."\n`);
|
|
1037
|
+
}
|
|
1038
|
+
} catch {}
|
|
1039
|
+
const { loadCollab, syncOnce } = await import("./sync-CQdGARJ9.mjs").then((n) => n.o);
|
|
1040
|
+
if (loadCollab(root)) console.log(` comments: syncing with the published canvas\n`);
|
|
1041
|
+
let syncing = false;
|
|
1042
|
+
const tick = async () => {
|
|
1043
|
+
if (syncing) return;
|
|
1044
|
+
syncing = true;
|
|
1045
|
+
try {
|
|
1046
|
+
const collab = loadCollab(root);
|
|
1047
|
+
if (collab) await syncOnce(root, collab).catch(() => {});
|
|
1048
|
+
} finally {
|
|
1049
|
+
syncing = false;
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
tick();
|
|
1053
|
+
const syncTimer = setInterval(tick, 3e4);
|
|
1054
|
+
syncTimer.unref();
|
|
1055
|
+
t.defer(() => clearInterval(syncTimer));
|
|
1056
|
+
let sent = "";
|
|
1057
|
+
const broadcast = (frames) => {
|
|
1058
|
+
const state = {
|
|
1059
|
+
frames: [...frames].sort(),
|
|
1060
|
+
boards: boardsShowing(root, frames)
|
|
1061
|
+
};
|
|
1062
|
+
const key = JSON.stringify(state);
|
|
1063
|
+
if (key === sent) return;
|
|
1064
|
+
sent = key;
|
|
1065
|
+
server.ws.send("sh:jam-activity", {
|
|
1066
|
+
...state,
|
|
1067
|
+
seq: nextActivitySeq()
|
|
1068
|
+
});
|
|
1069
|
+
};
|
|
1070
|
+
const unsubscribe = workActivity.onChange(broadcast);
|
|
1071
|
+
const offBoards = onBoardsChanged((r) => {
|
|
1072
|
+
if (r === root) broadcast(workActivity.active());
|
|
1073
|
+
});
|
|
1074
|
+
const sweep = setInterval(() => workActivity.sweep(), 15e3);
|
|
1075
|
+
sweep.unref?.();
|
|
1076
|
+
t.defer(() => {
|
|
1077
|
+
unsubscribe();
|
|
1078
|
+
offBoards();
|
|
1079
|
+
clearInterval(sweep);
|
|
1080
|
+
});
|
|
1081
|
+
{
|
|
1082
|
+
const dir = join(root, "design", "comments");
|
|
1083
|
+
const due = /* @__PURE__ */ new Map();
|
|
1084
|
+
try {
|
|
1085
|
+
mkdirSync(dir, { recursive: true });
|
|
1086
|
+
const w = watch$1.add(watch(dir, { persistent: false }, (_e, file) => {
|
|
1087
|
+
const m = typeof file === "string" ? file.match(/^([a-z0-9][a-z0-9-]*)\.jsonl$/) : null;
|
|
1088
|
+
if (!m) return;
|
|
1089
|
+
clearTimeout(due.get(m[1]));
|
|
1090
|
+
due.set(m[1], setTimeout(() => {
|
|
1091
|
+
due.delete(m[1]);
|
|
1092
|
+
server.ws.send("sh:jam-comment", { board: m[1] });
|
|
1093
|
+
}, 120));
|
|
1094
|
+
}));
|
|
1095
|
+
t.defer(() => {
|
|
1096
|
+
w.close();
|
|
1097
|
+
for (const x of due.values()) clearTimeout(x);
|
|
1098
|
+
});
|
|
1099
|
+
} catch {}
|
|
1100
|
+
}
|
|
1101
|
+
if (config.jam) {
|
|
1102
|
+
const { startJam } = await import("./daemon-Dc9AH0M3.mjs");
|
|
1103
|
+
const { checkAnchor } = await import("./anchor-check-gkxkPAIv.mjs");
|
|
1104
|
+
const jam = startJam(root, config.jam, (m) => console.log(m), (board) => server.ws.send("sh:jam-comment", { board }), (frameId, target, others, look) => checkAnchor({
|
|
1105
|
+
root,
|
|
1106
|
+
viewports: config.viewports,
|
|
1107
|
+
origin: `http://localhost:${port}`,
|
|
1108
|
+
frameId,
|
|
1109
|
+
target,
|
|
1110
|
+
others,
|
|
1111
|
+
...look
|
|
1112
|
+
}), (() => {
|
|
1113
|
+
let due = null;
|
|
1114
|
+
return () => {
|
|
1115
|
+
due ??= setTimeout(async () => {
|
|
1116
|
+
due = null;
|
|
1117
|
+
const { jamLive } = await import("./live-Cgzsicwi.mjs");
|
|
1118
|
+
server.ws.send("sh:jam-queue", jamLive.view?.() ?? { cards: [] });
|
|
1119
|
+
}, 60);
|
|
1120
|
+
};
|
|
1121
|
+
})(), async (frameId, theme, entry, size) => {
|
|
1122
|
+
const { shootFrame } = await import("./shot-Ch24tiMO.mjs").then((n) => n.u);
|
|
1123
|
+
const r = await shootFrame({
|
|
1124
|
+
root,
|
|
1125
|
+
viewports: config.viewports,
|
|
1126
|
+
frameId,
|
|
1127
|
+
theme,
|
|
1128
|
+
origin: `http://localhost:${port}`,
|
|
1129
|
+
...size ? { size } : {}
|
|
1130
|
+
});
|
|
1131
|
+
if (!r.ok) return null;
|
|
1132
|
+
const { addPicture } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
|
|
1133
|
+
return addPicture(root, r.path, {
|
|
1134
|
+
frame: frameId,
|
|
1135
|
+
...entry,
|
|
1136
|
+
.../not checked for a stale surface/.test(r.note ?? "") ? { unchecked: true } : {}
|
|
1137
|
+
});
|
|
1138
|
+
}, watch$1.add);
|
|
1139
|
+
if (jam) {
|
|
1140
|
+
t.defer(() => jam.stop());
|
|
1141
|
+
const { createSpeech, speechLive } = await import("./audio-Dw1lfMdb.mjs");
|
|
1142
|
+
const { appendTalk } = await import("./session-BAaJsK5c.mjs").then((n) => n.s);
|
|
1143
|
+
const { logJam } = await import("./perf-jam-BaH3Lg0m.mjs").then((n) => n.n);
|
|
1144
|
+
const speech = createSpeech({
|
|
1145
|
+
onTalk: (t) => appendTalk(root, t.session, t.words),
|
|
1146
|
+
onTiming: (t) => logJam(root, {
|
|
1147
|
+
kind: "words",
|
|
1148
|
+
...t
|
|
1149
|
+
})
|
|
1150
|
+
});
|
|
1151
|
+
const attach = () => {
|
|
1152
|
+
if (server.httpServer) speech.attach(server.httpServer);
|
|
1153
|
+
};
|
|
1154
|
+
attach();
|
|
1155
|
+
onRestart.push(attach);
|
|
1156
|
+
speechLive.svc = speech;
|
|
1157
|
+
t.defer(() => {
|
|
1158
|
+
speech.stop();
|
|
1159
|
+
speechLive.svc = void 0;
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
} else if (config.jamOff === "no-agent") console.log(` jam: no agent CLI on PATH (claude, codex, cursor, droid, opencode, grok, or pi) - install one and tag @${NAME} in a comment\n`);
|
|
1163
|
+
const end = (self) => {
|
|
1164
|
+
const others = () => Promise.all([...restarts].filter((x) => x !== self).map((x) => x.over));
|
|
1165
|
+
ending ??= (async () => {
|
|
1166
|
+
const r = replacing;
|
|
1167
|
+
const made = r && latest !== r.from ? latest : null;
|
|
1168
|
+
if (made) {
|
|
1169
|
+
made.withdraw?.();
|
|
1170
|
+
made.withdraw = null;
|
|
1171
|
+
made.left = true;
|
|
1172
|
+
}
|
|
1173
|
+
await t.close(others);
|
|
1174
|
+
})();
|
|
1175
|
+
return ending.then(others).then(() => {});
|
|
1176
|
+
};
|
|
1177
|
+
/** Vite's own close and restart of the server on this object: the first server's, then those each restart put in place */
|
|
1178
|
+
const live = {
|
|
1179
|
+
close: server.close,
|
|
1180
|
+
restart: server.restart
|
|
1181
|
+
};
|
|
1182
|
+
const close = (() => {
|
|
1183
|
+
const r = replacing;
|
|
1184
|
+
if (r?.oldClose) {
|
|
1185
|
+
r.oldClose = false;
|
|
1186
|
+
return ending ? Promise.reject(/* @__PURE__ */ new Error("the canvas has closed")) : live.close.call(server);
|
|
1187
|
+
}
|
|
1188
|
+
return end();
|
|
1189
|
+
});
|
|
1190
|
+
let restarting = null;
|
|
1191
|
+
const restart = ((forceOptimize) => restarting ??= (async () => {
|
|
1192
|
+
if (ending) return;
|
|
1193
|
+
let failed;
|
|
1194
|
+
let over = () => {};
|
|
1195
|
+
const r = replacing = {
|
|
1196
|
+
from: latest,
|
|
1197
|
+
handed: false,
|
|
1198
|
+
armed: false,
|
|
1199
|
+
oldClose: false,
|
|
1200
|
+
over: new Promise((res) => {
|
|
1201
|
+
over = res;
|
|
1202
|
+
})
|
|
1203
|
+
};
|
|
1204
|
+
restarts.add(r);
|
|
1205
|
+
try {
|
|
1206
|
+
try {
|
|
1207
|
+
await live.restart.call(server, forceOptimize);
|
|
1208
|
+
} catch (err) {
|
|
1209
|
+
failed = err ?? /* @__PURE__ */ new Error("restart failed");
|
|
1210
|
+
} finally {
|
|
1211
|
+
restarting = null;
|
|
1212
|
+
replacing = null;
|
|
1213
|
+
}
|
|
1214
|
+
const made = latest !== r.from ? latest : null;
|
|
1215
|
+
if (ending) {
|
|
1216
|
+
if (made) await settle(made, false);
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
if (!r.handed) {
|
|
1220
|
+
if (made) await settle(made, false);
|
|
1221
|
+
if (failed !== void 0) throw failed;
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
if (made) settle(made, true);
|
|
1225
|
+
closeVite = live.close.bind(server);
|
|
1226
|
+
if (failed === void 0) {
|
|
1227
|
+
for (const f of onRestart) f();
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
console.error(`\n the canvas stopped: it could not restart on port ${port} (${failed?.message ?? failed}) - start it again\n`);
|
|
1231
|
+
await end(r);
|
|
1232
|
+
throw failed;
|
|
1233
|
+
} finally {
|
|
1234
|
+
restarts.delete(r);
|
|
1235
|
+
over();
|
|
1236
|
+
}
|
|
1237
|
+
})());
|
|
1238
|
+
Object.defineProperty(server, "close", {
|
|
1239
|
+
configurable: true,
|
|
1240
|
+
enumerable: true,
|
|
1241
|
+
get: () => close,
|
|
1242
|
+
set: (fn) => {
|
|
1243
|
+
live.close = fn;
|
|
1244
|
+
if (replacing) replacing.handed = true;
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
Object.defineProperty(server, "restart", {
|
|
1248
|
+
configurable: true,
|
|
1249
|
+
enumerable: true,
|
|
1250
|
+
get: () => restart,
|
|
1251
|
+
set: (fn) => {
|
|
1252
|
+
live.restart = fn;
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
let shortcuts = server._shortcutsState;
|
|
1256
|
+
Object.defineProperty(server, "_shortcutsState", {
|
|
1257
|
+
configurable: true,
|
|
1258
|
+
enumerable: true,
|
|
1259
|
+
get: () => shortcuts,
|
|
1260
|
+
set: (v) => {
|
|
1261
|
+
shortcuts = v;
|
|
1262
|
+
const r = replacing;
|
|
1263
|
+
if (!r || r.handed || r.armed || v !== void 0) return;
|
|
1264
|
+
r.armed = r.oldClose = true;
|
|
1265
|
+
queueMicrotask(() => {
|
|
1266
|
+
r.oldClose = false;
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
return server;
|
|
1271
|
+
}
|
|
1272
|
+
//#endregion
|
|
1273
|
+
export { DevLockError, DevStartError, dev };
|