@marver-design/marver 0.28.0 → 0.30.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.
- package/CHANGELOG.md +103 -0
- package/README.md +4 -3
- package/dist/{anchor-check-PHUOFj1N.mjs → anchor-check-c52IDkiQ.mjs} +1 -1
- package/dist/{build-BsAyLMT1.mjs → build-C3mUtjEn.mjs} +7 -4
- package/dist/{capture-DdZ6xgoz.mjs → capture-DEtM4qm5.mjs} +168 -5
- package/dist/cli.mjs +11 -11
- package/dist/{comments-CrBHPEQl.mjs → comments-XNhMmSSu.mjs} +2 -2
- package/dist/{connectors-MR9d-EBP.mjs → connectors-DekQvKt9.mjs} +3 -1
- package/dist/{daemon-C5dg2R-V.mjs → daemon-B0Wi1OQ3.mjs} +30 -29
- package/dist/{dev-D7YS7iT2.mjs → dev-5dlxoW28.mjs} +19 -14
- package/dist/{init-WE5lQkQL.mjs → init-CYlFaRzG.mjs} +1 -1
- package/dist/logo-CXY-1yrn.mjs +305 -0
- package/dist/{ls-BZ5TAtd5.mjs → ls-NqmePKOf.mjs} +1 -1
- package/dist/{marks-Kmdab_5w.mjs → marks-BnNANic9.mjs} +20 -1
- package/dist/{marks-Dyn6tmjp.mjs → marks-DBp3h1Mc.mjs} +2 -5
- package/dist/{marver-id-gate-D-R0hSt_.mjs → marver-id-gate-vBLb_Icb.mjs} +1 -1
- package/dist/{perf-Cn5LiRaY.mjs → perf-6MOTHxay.mjs} +751 -122
- package/dist/perf-BCxAo0IS.mjs +1743 -0
- package/dist/{plugin-C_0yb-Fq.mjs → plugin-CXRoMA8g.mjs} +1382 -810
- package/dist/{poster-DHi6I1fO.mjs → poster-CYmCa00B.mjs} +1 -1
- package/dist/{profile-jIS6BcAs.mjs → profile-B1FKOM1e.mjs} +1 -1
- package/dist/{publish-bakes-r4PEZuPl.mjs → publish-bakes-C_2ZtHou.mjs} +3 -3
- package/dist/{queue-c-6aTHEz.mjs → queue-DeSQm24g.mjs} +29 -14
- package/dist/{recover-nrLEVLyJ.mjs → recover-XD8iXJOj.mjs} +2 -2
- package/dist/{serve-Dp3nHstu.mjs → serve-DQv3Ti6X.mjs} +8 -4
- package/dist/{session-DyVE7cCk.mjs → session-VDJfXEEm.mjs} +1 -1
- package/dist/{share-Ce4tP7ji.mjs → share-Bu_kuOKL.mjs} +1 -1
- package/dist/{shot-BrRtqaiS.mjs → shot-CRRGgxru.mjs} +3 -3
- package/dist/{slots-CFNnegCc.mjs → slots-Dn4Onb0V.mjs} +101 -3
- package/dist/{sync-CQdGARJ9.mjs → sync-CMozOwZ0.mjs} +1 -1
- package/docs/app.md +194 -0
- package/docs/boards-and-folders.md +11 -0
- package/docs/jam-session.md +12 -3
- package/docs/live-jam.md +3 -0
- package/docs/performance.md +99 -19
- package/docs/publish.md +7 -0
- package/package.json +1 -1
- package/src/client/frame-host/bridge.js +17 -8
- package/src/client/frame-host/inplace.ts +124 -0
- package/src/client/frame-host/inspect.d.ts +1 -0
- package/src/client/frame-host/inspect.js +13 -4
- package/src/client/frame-host/main.tsx +12 -3
- package/src/client/frame-host/messages.ts +85 -0
- package/src/client/frame-host/signals.d.ts +15 -0
- package/src/client/frame-host/signals.js +219 -0
- package/src/client/recorder-level.ts +41 -0
- package/src/client/shell/App.tsx +158 -88
- package/src/client/shell/BoardList.tsx +103 -48
- package/src/client/shell/Comments.tsx +71 -46
- package/src/client/shell/ContextMenu.tsx +8 -6
- package/src/client/shell/JamSurface.tsx +187 -71
- package/src/client/shell/LockedApp.tsx +19 -3
- package/src/client/shell/Play.tsx +110 -62
- package/src/client/shell/StatusPicker.tsx +19 -9
- package/src/client/shell/Toolbar.tsx +15 -7
- package/src/client/shell/api.ts +25 -7
- package/src/client/shell/app-bridge.ts +23 -9
- package/src/client/shell/app-perf.ts +31 -1
- package/src/client/shell/canvas/Canvas.tsx +17 -6
- package/src/client/shell/canvas/FrameNode.tsx +25 -12
- package/src/client/shell/canvas/Sticky.tsx +4 -2
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/ready-watch.ts +4 -0
- package/src/client/shell/canvas/sleep.ts +2 -0
- package/src/client/shell/canvas/updates.ts +13 -6
- package/src/client/shell/commands.ts +765 -0
- package/src/client/shell/comments-store.ts +56 -27
- package/src/client/shell/goto.ts +15 -9
- package/src/client/shell/jam-capture.ts +39 -15
- package/src/client/shell/jam-keys.ts +303 -111
- package/src/client/shell/jam-lane.tsx +19 -12
- package/src/client/shell/jam-lines.ts +10 -1
- package/src/client/shell/jam-panel.tsx +68 -53
- package/src/client/shell/jam-queue.ts +6 -1
- package/src/client/shell/jam-session.tsx +41 -37
- package/src/client/shell/jam-state.ts +28 -5
- package/src/client/shell/jam-surface-parts.tsx +8 -6
- package/src/client/shell/jam-ui.tsx +12 -5
- package/src/client/shell/jam-voice.ts +4 -2
- package/src/client/shell/live-picture.ts +134 -0
- package/src/client/shell/main.tsx +7 -1
- package/src/client/shell/marks-ui.tsx +11 -0
- package/src/client/shell/open-item.ts +83 -0
- package/src/client/shell/open-resolve.ts +50 -0
- package/src/client/shell/perf.ts +51 -5
- package/src/client/shell/recorder-core.ts +4 -1
- package/src/client/shell/recorder-hmr.ts +36 -0
- package/src/client/shell/recorder-reloads.ts +264 -0
- package/src/client/shell/recorder-seams.ts +116 -0
- package/src/client/shell/recorder-self.ts +73 -0
- package/src/client/shell/recorder-signals-core.ts +139 -0
- package/src/client/shell/recorder-signals.ts +485 -0
- package/src/client/shell/recorder.ts +115 -41
- package/src/client/shell/store.ts +62 -24
- package/src/client/shell/styles.css +2 -0
- package/src/client/shell/whiteout-probes.ts +3 -1
- package/src/client/stage/main.tsx +39 -12
- package/src/shared/app-api.ts +201 -9
- package/src/shared/app-perf.ts +103 -8
- package/src/shared/app-report.ts +586 -0
- package/src/shared/perf-records.ts +445 -0
- package/src/shared/perf-run.ts +6 -2
- package/templates/instructions/jam.md +4 -0
- package/dist/live-Cgzsicwi.mjs +0 -4
- package/dist/perf-jam-QxD_UnzN.mjs +0 -635
|
@@ -3,18 +3,21 @@ import { a as ROUTE, i as PKG, r as NAME } from "./cli.mjs";
|
|
|
3
3
|
import { a as checkBoardsDir, c as listBoardFiles, d as pinFrames, g as tryFileLock, h as takeFileLock, i as boardLock, l as nodeExists, m as readRegistry, p as readMembership, r as boardFields, s as isRegularFile, t as AUTHOR_FIELDS, u as parseBoard, v as withRegistryLock, y as hash } from "./boards-EH2onUXM.mjs";
|
|
4
4
|
import { A as resolveType, D as readReason, E as readCapability, O as readStatusWord, S as HAS_STATUS, _ as validateWire, a as buildTree, c as folderMap, g as readTitle, h as readDescription, j as settableStatuses, k as readType, n as BOARD_NAME, r as FOLDERS_FILE, t as ALL_SCENES, v as wireKids } from "./board-tree-BXR8dw4b.mjs";
|
|
5
5
|
import { c as setSceneTitle, d as annotateBoards, f as planNames, m as readContextFacts, n as isNoteFile, p as planWithStage, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-DPZ3WNg_.mjs";
|
|
6
|
-
import { r as boardsChanged } from "./work-DJxH7cCX.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { a as workActivity, r as boardsChanged } from "./work-DJxH7cCX.mjs";
|
|
7
|
+
import { r as replay, t as asks } from "./events-CLH4ijKP.mjs";
|
|
8
|
+
import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
|
|
9
|
+
import { g as LIVE_WIRE, h as LIVE_BOUNDS, i as marverHome, o as originOf, v as workspaceId } from "./slots-Dn4Onb0V.mjs";
|
|
10
|
+
import { n as localProfile, t as isConnected } from "./profile-B1FKOM1e.mjs";
|
|
11
|
+
import { c as recordChanged, i as initMarks, n as docRevs, o as observe, r as freshFrames, t as docRev } from "./marks-BnNANic9.mjs";
|
|
12
|
+
import { C as WRITE_MATCH_MS, S as WRITER_HEADERS, _ as ID12, b as RELOAD_BOUNDS, c as takePageBatch, l as takeReloadBatch, n as appendRun, r as logReloadLines, t as PAGE_BODY_MAX, u as tidyPerfDir, v as RECORDER_LEVELS, w as decodeCmds, y as RECORDER_PARAM } from "./perf-BCxAo0IS.mjs";
|
|
11
13
|
import { n as loadConfig } from "./config-BezZTiov.mjs";
|
|
12
14
|
import { a as mergeSizes, c as serializeSizes, i as measuringFrames, l as sizesPath, n as autoWidthOf, o as readSizes, r as keptSizes, s as readSizesFile } from "./sizes-wjXDev3b.mjs";
|
|
13
|
-
import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-
|
|
14
|
-
import {
|
|
15
|
+
import { c as pool, d as withBrowser, f as Browser, l as shotConcurrency, m as launchFlags, r as SURFACE, t as AREA } from "./shot-CRRGgxru.mjs";
|
|
16
|
+
import { a as appProofOk, o as proofHeaders, r as logoRoute } from "./logo-CXY-1yrn.mjs";
|
|
17
|
+
import { closeSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, watch, writeFileSync } from "node:fs";
|
|
15
18
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
16
19
|
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { createHash,
|
|
20
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
18
21
|
import { arch, cpus, totalmem } from "node:os";
|
|
19
22
|
import { execFile } from "node:child_process";
|
|
20
23
|
import { stat } from "node:fs/promises";
|
|
@@ -87,25 +90,45 @@ function framesFor(root, manifest, file, modules, skipFirst = false) {
|
|
|
87
90
|
touched: [...touched]
|
|
88
91
|
};
|
|
89
92
|
}
|
|
93
|
+
/** The hook that runs first on every hot update (spec 30 #8): this run takes its file's oldest open token, and its
|
|
94
|
+
* bracket opens. Ordered `pre`, so a plugin's own hook (Tailwind's full-reload) runs inside it. */
|
|
95
|
+
function updatesBeginPlugin(changes) {
|
|
96
|
+
return {
|
|
97
|
+
name: "marver:updates-begin",
|
|
98
|
+
hotUpdate: {
|
|
99
|
+
order: "pre",
|
|
100
|
+
handler(opts) {
|
|
101
|
+
if (this.environment.name === "client") changes.begin(opts.file, opts.timestamp);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
90
106
|
/** The hook that runs last on every hot update of the client environment. */
|
|
91
|
-
function updatesPlugin(root, manifest, hooks, landed) {
|
|
107
|
+
function updatesPlugin(root, manifest, hooks, landed, changes) {
|
|
92
108
|
return {
|
|
93
109
|
name: "marver:updates",
|
|
94
110
|
hotUpdate: {
|
|
95
111
|
order: "post",
|
|
96
112
|
handler(opts) {
|
|
97
113
|
landed(opts.file);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
try {
|
|
115
|
+
if (this.environment.name !== "client") return;
|
|
116
|
+
const h = hooks();
|
|
117
|
+
if (!h) return;
|
|
118
|
+
const t = framesFor(root, manifest(), opts.file, opts.modules);
|
|
119
|
+
if (t.doc.length || t.touched.length) {
|
|
120
|
+
const token = changes.run(opts.file, opts.timestamp);
|
|
121
|
+
h.onFrames(t, "update", token ? { token } : changes.ofFile(opts.file));
|
|
122
|
+
}
|
|
123
|
+
} finally {
|
|
124
|
+
changes.landed(opts.file, opts.timestamp);
|
|
125
|
+
}
|
|
103
126
|
}
|
|
104
127
|
}
|
|
105
128
|
};
|
|
106
129
|
}
|
|
107
130
|
/** Wraps the client's hot channel: the reload guard and refused refreshes. */
|
|
108
|
-
function guardUpdates(server, root, manifest, hooks) {
|
|
131
|
+
function guardUpdates(server, root, manifest, hooks, changes) {
|
|
109
132
|
const env = server.environments.client;
|
|
110
133
|
const wrap = (ch) => {
|
|
111
134
|
const send = ch.send.bind(ch);
|
|
@@ -113,12 +136,13 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
113
136
|
const p = a[0];
|
|
114
137
|
if (typeof p === "object" && p?.type === "full-reload") {
|
|
115
138
|
const passed = p.path === "*" && !p.triggeredBy;
|
|
139
|
+
const by = passed ? void 0 : p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
140
|
+
const at = passed ? void 0 : by ? changes.ofFile(by) : changes.pathless();
|
|
116
141
|
hooks.onReload({
|
|
117
142
|
triggeredBy: p.triggeredBy,
|
|
118
143
|
path: p.path
|
|
119
|
-
}, passed);
|
|
144
|
+
}, passed, at);
|
|
120
145
|
if (!passed) {
|
|
121
|
-
const by = p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
122
146
|
const mods = by ? env.moduleGraph.getModulesByFile(by) : void 0;
|
|
123
147
|
const all = manifest().frames.map((f) => f.id);
|
|
124
148
|
const t = by ? framesFor(root, manifest(), by, mods ?? []) : {
|
|
@@ -127,7 +151,7 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
127
151
|
touched: [],
|
|
128
152
|
unattributed: true
|
|
129
153
|
};
|
|
130
|
-
if (t.doc.length || t.touched.length) hooks.onFrames(t, "reload");
|
|
154
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "reload", at);
|
|
131
155
|
return;
|
|
132
156
|
}
|
|
133
157
|
}
|
|
@@ -143,10 +167,290 @@ function guardUpdates(server, root, manifest, hooks) {
|
|
|
143
167
|
if (refused.get(mod.url) === mod.lastHMRTimestamp) return;
|
|
144
168
|
refused.set(mod.url, mod.lastHMRTimestamp);
|
|
145
169
|
const t = framesFor(root, manifest(), mod.file, [mod], true);
|
|
146
|
-
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate");
|
|
170
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate", changes.refused(mod.lastHMRTimestamp));
|
|
147
171
|
});
|
|
148
172
|
}
|
|
149
173
|
//#endregion
|
|
174
|
+
//#region src/server/changes.ts
|
|
175
|
+
/**
|
|
176
|
+
* An edit's identity, from the watcher to the send (spec 30 R1 #8-#12). Every watcher event mints an immutable token;
|
|
177
|
+
* the hot-update run that comes for it takes the file's oldest open token and opens its bracket; whatever that run
|
|
178
|
+
* causes keeps the token in its own closure, so a line deferred past `setTimeout` and `whenSettled` writes the token it
|
|
179
|
+
* was given - never a lookup, and never a guess. What cannot be known says so (R0): a page-wide reload with no path
|
|
180
|
+
* inside one bracket is that change, inside two is `ambiguous`, outside any is `unknown` (#11); a refused refresh has
|
|
181
|
+
* no identity of its own (#8). Lines the dev server writes name no page: a change belongs to every page.
|
|
182
|
+
*
|
|
183
|
+
* Kept apart from plugin.ts so the attribution rules run under test with a fake clock (test/r30-edits-changes.test.ts).
|
|
184
|
+
*/
|
|
185
|
+
/** A list in lines of at most `idsPerLine` (#10, #12): none for an empty one. */
|
|
186
|
+
function chunks(list) {
|
|
187
|
+
const out = [];
|
|
188
|
+
for (let i = 0; i < list.length; i += RELOAD_BOUNDS.idsPerLine) out.push(list.slice(i, i + RELOAD_BOUNDS.idsPerLine));
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
const bounded = (ids) => ({
|
|
192
|
+
ids: ids.slice(0, RELOAD_BOUNDS.candidates),
|
|
193
|
+
n: ids.length
|
|
194
|
+
});
|
|
195
|
+
function createChanges(o) {
|
|
196
|
+
const boot = o.boot ?? randomBytes(4).toString("hex");
|
|
197
|
+
const now = o.now ?? Date.now;
|
|
198
|
+
let n = 0;
|
|
199
|
+
/** each file's open tokens, oldest first: a run takes the oldest whose hooks have not begun */
|
|
200
|
+
const open = /* @__PURE__ */ new Map();
|
|
201
|
+
/** minted, not ended */
|
|
202
|
+
const flying = /* @__PURE__ */ new Set();
|
|
203
|
+
/** its hooks are running now (several files' runs can overlap; Vite awaits one run's hooks in sequence) */
|
|
204
|
+
const brackets = /* @__PURE__ */ new Set();
|
|
205
|
+
/** a run's identity, shared by its environments' hooks: file and timestamp */
|
|
206
|
+
const runs = /* @__PURE__ */ new Map();
|
|
207
|
+
const runKey = (file, ts) => `${ts}|${file}`;
|
|
208
|
+
/** `hmrTs -> change`, the last 512: a refused refresh's candidates (#8) */
|
|
209
|
+
const history = [];
|
|
210
|
+
const rel = (file) => relative(o.root, file).split(sep).join("/");
|
|
211
|
+
const ids = (ts) => [...ts].map((t) => t.change);
|
|
212
|
+
function writeChange(t) {
|
|
213
|
+
o.write([{
|
|
214
|
+
kind: "change",
|
|
215
|
+
change: t.change,
|
|
216
|
+
file: rel(t.file),
|
|
217
|
+
event: t.event,
|
|
218
|
+
at: t.at,
|
|
219
|
+
...t.hmrTs !== void 0 ? { hmrTs: t.hmrTs } : { outcome: "no-hook" },
|
|
220
|
+
flightMs: t.flightMs,
|
|
221
|
+
reloadN: t.reload.size,
|
|
222
|
+
inPlaceN: t.inPlace.size,
|
|
223
|
+
...t.fullReload ? { fullReload: t.fullReload } : {}
|
|
224
|
+
}]);
|
|
225
|
+
}
|
|
226
|
+
/** A token's end: its hooks landed in every environment, or the 10 s safety path. Its line follows at once, or when
|
|
227
|
+
* the last deferred line that holds it has written. */
|
|
228
|
+
function end(t) {
|
|
229
|
+
if (t.ended) return;
|
|
230
|
+
t.ended = true;
|
|
231
|
+
t.flightMs = now() - t.at;
|
|
232
|
+
flying.delete(t);
|
|
233
|
+
brackets.delete(t);
|
|
234
|
+
if (t.hmrTs !== void 0) runs.delete(runKey(t.file, t.hmrTs));
|
|
235
|
+
const q = open.get(t.file);
|
|
236
|
+
if (q?.includes(t)) {
|
|
237
|
+
q.splice(q.indexOf(t), 1);
|
|
238
|
+
if (!q.length) open.delete(t.file);
|
|
239
|
+
}
|
|
240
|
+
if (t.pending === 0) writeChange(t);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
/** `watchChange`: a watcher event. */
|
|
244
|
+
watch(file, event) {
|
|
245
|
+
const t = {
|
|
246
|
+
change: `${boot}:${++n}`,
|
|
247
|
+
file,
|
|
248
|
+
event,
|
|
249
|
+
at: now(),
|
|
250
|
+
hits: 0,
|
|
251
|
+
ended: false,
|
|
252
|
+
pending: 0,
|
|
253
|
+
reload: /* @__PURE__ */ new Set(),
|
|
254
|
+
inPlace: /* @__PURE__ */ new Set()
|
|
255
|
+
};
|
|
256
|
+
flying.add(t);
|
|
257
|
+
const q = open.get(file);
|
|
258
|
+
if (q) q.push(t);
|
|
259
|
+
else open.set(file, [t]);
|
|
260
|
+
return t;
|
|
261
|
+
},
|
|
262
|
+
/** The `pre` hook, in the client environment (it runs first): this run takes the file's oldest open token. */
|
|
263
|
+
begin(file, hmrTs) {
|
|
264
|
+
const t = open.get(file)?.find((x) => x.hmrTs === void 0);
|
|
265
|
+
if (!t) return void 0;
|
|
266
|
+
t.hmrTs = hmrTs;
|
|
267
|
+
brackets.add(t);
|
|
268
|
+
runs.set(runKey(file, hmrTs), t);
|
|
269
|
+
history.push({
|
|
270
|
+
hmrTs,
|
|
271
|
+
change: t.change
|
|
272
|
+
});
|
|
273
|
+
if (history.length > RELOAD_BOUNDS.hmrHistory) history.shift();
|
|
274
|
+
return t;
|
|
275
|
+
},
|
|
276
|
+
/** The token of the run these hook options belong to, if it has one. */
|
|
277
|
+
run: (file, hmrTs) => runs.get(runKey(file, hmrTs)),
|
|
278
|
+
/** The `post` hook, per environment: the last one closes the bracket, and the token ends a tick later (Vite finishes
|
|
279
|
+
* the update after the hooks). */
|
|
280
|
+
landed(file, hmrTs) {
|
|
281
|
+
const t = runs.get(runKey(file, hmrTs));
|
|
282
|
+
if (!t || ++t.hits < o.envs()) return;
|
|
283
|
+
brackets.delete(t);
|
|
284
|
+
setTimeout(() => end(t), 0);
|
|
285
|
+
},
|
|
286
|
+
/** The 10 s safety path (plugin.ts `flying`): every token of the file still in flight ends. One whose hooks never
|
|
287
|
+
* began says so: the watcher coalesced it, or Vite never brought it to the hooks. */
|
|
288
|
+
expire(file) {
|
|
289
|
+
for (const t of [...open.get(file) ?? []]) end(t);
|
|
290
|
+
},
|
|
291
|
+
/** #11, at the guard: a page-wide reload that named nothing. */
|
|
292
|
+
pathless() {
|
|
293
|
+
if (brackets.size === 1) return {
|
|
294
|
+
token: [...brackets][0],
|
|
295
|
+
by: "hook"
|
|
296
|
+
};
|
|
297
|
+
if (brackets.size > 1) return {
|
|
298
|
+
by: "ambiguous",
|
|
299
|
+
candidates: bounded(ids(brackets))
|
|
300
|
+
};
|
|
301
|
+
return {
|
|
302
|
+
by: "unknown",
|
|
303
|
+
candidates: bounded(ids(flying))
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
/** A page-wide reload that names its file (Vite's dead end, an HTML page), sent after the file's hooks: that file's
|
|
307
|
+
* token still in flight - no time-window guess. */
|
|
308
|
+
ofFile(file) {
|
|
309
|
+
const ts = open.get(file) ?? [];
|
|
310
|
+
if (ts.length === 1) return { token: ts[0] };
|
|
311
|
+
return { candidates: bounded(ids(ts.length ? ts : flying)) };
|
|
312
|
+
},
|
|
313
|
+
/** #8: a refused refresh. `graphTs` is the module's timestamp as read, which a later save has already replaced: the
|
|
314
|
+
* change it names and those of the 10 s before it are candidates - never attributed to one. */
|
|
315
|
+
refused(graphTs) {
|
|
316
|
+
const named = history.filter((h) => h.hmrTs === graphTs);
|
|
317
|
+
const before = history.filter((h) => h.hmrTs < graphTs && h.hmrTs >= graphTs - RELOAD_BOUNDS.lookBackMs).reverse();
|
|
318
|
+
return {
|
|
319
|
+
graphTs,
|
|
320
|
+
candidates: bounded([...named, ...before].map((h) => h.change))
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
/** A line deferred past the hooks keeps the token: it holds the `change` line back until `release`. */
|
|
324
|
+
hold(at) {
|
|
325
|
+
const t = at.token;
|
|
326
|
+
if (!t) return () => {};
|
|
327
|
+
t.pending++;
|
|
328
|
+
return () => {
|
|
329
|
+
if (--t.pending === 0 && t.ended) writeChange(t);
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
/** #10: the `update` line, full membership in `update-ids` parts. */
|
|
333
|
+
update(cause, file, reload, inPlace, at) {
|
|
334
|
+
const r = chunks(reload), p = chunks(inPlace);
|
|
335
|
+
const parts = Math.max(1, r.length, p.length);
|
|
336
|
+
const change = at.token?.change ?? "unknown";
|
|
337
|
+
const lines = [{
|
|
338
|
+
kind: "update",
|
|
339
|
+
cause,
|
|
340
|
+
file: file ? rel(file) : null,
|
|
341
|
+
reload: r[0] ?? [],
|
|
342
|
+
inPlace: p[0] ?? [],
|
|
343
|
+
change,
|
|
344
|
+
reloadN: reload.length,
|
|
345
|
+
inPlaceN: inPlace.length,
|
|
346
|
+
...at.graphTs !== void 0 ? { graphTs: at.graphTs } : {},
|
|
347
|
+
...at.candidates ? { candidates: at.candidates } : {},
|
|
348
|
+
...parts > 1 ? { parts } : {}
|
|
349
|
+
}];
|
|
350
|
+
for (let i = 1; i < parts; i++) lines.push({
|
|
351
|
+
kind: "update-ids",
|
|
352
|
+
change,
|
|
353
|
+
part: i + 1,
|
|
354
|
+
parts,
|
|
355
|
+
...r[i] ? { reload: r[i] } : {},
|
|
356
|
+
...p[i] ? { inPlace: p[i] } : {}
|
|
357
|
+
});
|
|
358
|
+
o.write(lines);
|
|
359
|
+
if (at.token) {
|
|
360
|
+
for (const id of reload) at.token.reload.add(id);
|
|
361
|
+
for (const id of inPlace) at.token.inPlace.add(id);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
/** #11: every page-wide reload Vite or a plugin tried to send, and what it knows of its change. */
|
|
365
|
+
fullReload(p, passed, at) {
|
|
366
|
+
if (at?.token) at.token.fullReload ??= passed ? "passed" : "dropped";
|
|
367
|
+
o.write([{
|
|
368
|
+
kind: "full-reload",
|
|
369
|
+
passed,
|
|
370
|
+
triggeredBy: p.triggeredBy ?? null,
|
|
371
|
+
path: p.path ?? null,
|
|
372
|
+
...at?.by ? { by: at.by } : {},
|
|
373
|
+
...at?.token ? {
|
|
374
|
+
change: at.token.change,
|
|
375
|
+
file: rel(at.token.file)
|
|
376
|
+
} : {},
|
|
377
|
+
...at?.candidates ? { candidates: at.candidates } : {}
|
|
378
|
+
}]);
|
|
379
|
+
},
|
|
380
|
+
/** #12: the send, with every change it carries - many to many, every edge kept in `invalidate-ids` parts. */
|
|
381
|
+
invalidate(revision, frames, changes) {
|
|
382
|
+
const c = chunks(changes);
|
|
383
|
+
const parts = Math.max(1, c.length);
|
|
384
|
+
const lines = [{
|
|
385
|
+
kind: "invalidate",
|
|
386
|
+
revision,
|
|
387
|
+
frames,
|
|
388
|
+
changes: c[0] ?? [],
|
|
389
|
+
...parts > 1 ? { parts } : {}
|
|
390
|
+
}];
|
|
391
|
+
for (let i = 1; i < parts; i++) lines.push({
|
|
392
|
+
kind: "invalidate-ids",
|
|
393
|
+
revision,
|
|
394
|
+
part: i + 1,
|
|
395
|
+
parts,
|
|
396
|
+
changes: c[i]
|
|
397
|
+
});
|
|
398
|
+
o.write(lines);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/server/board-writes.ts
|
|
404
|
+
/**
|
|
405
|
+
* Who may have written a board file (spec 30 #18). Every shell request that can write a board names its page and the
|
|
406
|
+
* commands folded into it (`x-mv-page`, `x-mv-cmds`); the server keeps, per board, the hashes it wrote in the last 10 s
|
|
407
|
+
* with them. The watcher reads the file after a debounce, so a matching hash proves matching bytes, not the writer - an
|
|
408
|
+
* editor can write the same bytes back. `sh:board` therefore carries a match as a candidate, never as proof: one match
|
|
409
|
+
* is `candidate`, two or more `ambiguous`, none `unknown` (an agent, the CLI, an editor, a write the server did not see).
|
|
410
|
+
*/
|
|
411
|
+
/** by project root: the middleware and the watcher share a process, not an object */
|
|
412
|
+
const written = /* @__PURE__ */ new Map();
|
|
413
|
+
/** The page and commands a request names; null when it names no page (the CLI, an agent): nothing to remember. */
|
|
414
|
+
function writerFrom(headers) {
|
|
415
|
+
const page = headers[WRITER_HEADERS.page];
|
|
416
|
+
if (typeof page !== "string" || !ID12.test(page)) return null;
|
|
417
|
+
return {
|
|
418
|
+
page,
|
|
419
|
+
cmds: decodeCmds(headers[WRITER_HEADERS.cmds] ?? "") ?? {
|
|
420
|
+
ids: [],
|
|
421
|
+
n: 0
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const fresh = (root, now) => {
|
|
426
|
+
const kept = (written.get(root) ?? []).filter((w) => now - w.at < WRITE_MATCH_MS);
|
|
427
|
+
if (kept.length) written.set(root, kept);
|
|
428
|
+
else written.delete(root);
|
|
429
|
+
return kept;
|
|
430
|
+
};
|
|
431
|
+
/** A board write this server made, once it landed. */
|
|
432
|
+
function noteWrite(root, board, sha, who, now = Date.now()) {
|
|
433
|
+
written.set(root, [...fresh(root, now), {
|
|
434
|
+
...who,
|
|
435
|
+
board,
|
|
436
|
+
sha,
|
|
437
|
+
at: now
|
|
438
|
+
}]);
|
|
439
|
+
}
|
|
440
|
+
/** What the writes of the last 10 s say about these bytes of this board. */
|
|
441
|
+
function writerOf(root, board, sha, now = Date.now()) {
|
|
442
|
+
const match = fresh(root, now).filter((w) => w.board === board && w.sha === sha);
|
|
443
|
+
if (!match.length) return { writer: "unknown" };
|
|
444
|
+
return {
|
|
445
|
+
writer: match.length === 1 ? "candidate" : "ambiguous",
|
|
446
|
+
candidates: match.slice(-RELOAD_BOUNDS.candidates).map((w) => ({
|
|
447
|
+
page: w.page,
|
|
448
|
+
cmds: w.cmds.ids,
|
|
449
|
+
n: w.cmds.n
|
|
450
|
+
}))
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
150
454
|
//#region src/shared/perf-run.ts
|
|
151
455
|
/** A run's own generated id: the same in the URL, the request headers and the output line (A3.4). */
|
|
152
456
|
const RUN_ID = /^[0-9a-f]{16}$/;
|
|
@@ -462,7 +766,7 @@ async function bakeIn(b, opts) {
|
|
|
462
766
|
const deadline = setTimeout(() => {
|
|
463
767
|
timedOut = true;
|
|
464
768
|
b.abort(me, TIMED_OUT);
|
|
465
|
-
}, DEADLINE_MS);
|
|
769
|
+
}, bakeSeams.deadlineMs ?? DEADLINE_MS);
|
|
466
770
|
const closeTarget = async (id) => {
|
|
467
771
|
let t;
|
|
468
772
|
await Promise.race([b.send("Target.closeTarget", { targetId: id }).catch(() => {}), new Promise((r) => {
|
|
@@ -947,11 +1251,13 @@ function endRunBakes(owner) {
|
|
|
947
1251
|
* looks at a COMPILING outlast any held compile (A3.8 r1 #4's case, added by the review of a3-runs). */
|
|
948
1252
|
const bakeSeams = {};
|
|
949
1253
|
const holdMs = () => {
|
|
950
|
-
return
|
|
1254
|
+
if (bakeSeams.holdMs !== void 0) return bakeSeams.holdMs;
|
|
1255
|
+
const v = process.env.MARVER_SLOT_BASE ? Number(process.env.MV_BAKE_HOLD_MS) : NaN;
|
|
1256
|
+
return Number.isFinite(v) && v > 0 ? Math.min(v, 6e4) : 0;
|
|
951
1257
|
};
|
|
952
1258
|
/** The suite's answer for a compile still running, under MV_BAKE_STOP_ASKING (above). */
|
|
953
1259
|
const STOP_ASKING = "still compiling - the suite asks the page to stop asking";
|
|
954
|
-
const stillCompiling = () => COMPILING;
|
|
1260
|
+
const stillCompiling = () => bakeSeams.stopAsking ?? (!!process.env.MARVER_SLOT_BASE && process.env.MV_BAKE_STOP_ASKING === "1") ? STOP_ASKING : COMPILING;
|
|
955
1261
|
/** Compiles in flight, by generation and key: identical asks - inside one request or across
|
|
956
1262
|
* concurrent ones - share one compile. */
|
|
957
1263
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -1271,7 +1577,7 @@ async function inputPaths(root, w, urls) {
|
|
|
1271
1577
|
}
|
|
1272
1578
|
/** These paths' fingerprint: each file's path from the root (`../` for one outside it), size and mtime. A path that
|
|
1273
1579
|
* is gone or no file counts for nothing - so one deleted since changes it. */
|
|
1274
|
-
async function hashInputs(root, paths) {
|
|
1580
|
+
async function hashInputs(root, paths, level = "full") {
|
|
1275
1581
|
const lines = [];
|
|
1276
1582
|
for (let i = 0; i < paths.length; i += 64) {
|
|
1277
1583
|
const got = await Promise.all(paths.slice(i, i + 64).map(async (p) => {
|
|
@@ -1281,9 +1587,10 @@ async function hashInputs(root, paths) {
|
|
|
1281
1587
|
for (const l of got) if (l) lines.push(l);
|
|
1282
1588
|
}
|
|
1283
1589
|
lines.sort();
|
|
1590
|
+
if (level === "core") lines.push("\0recorder\0core");
|
|
1284
1591
|
return {
|
|
1285
1592
|
hash: createHash("sha256").update(lines.join("\n")).digest("hex").slice(0, 16),
|
|
1286
|
-
files: lines.length
|
|
1593
|
+
files: lines.length - (level === "core" ? 1 : 0)
|
|
1287
1594
|
};
|
|
1288
1595
|
}
|
|
1289
1596
|
/** The fingerprint of every watched file, plus the board files and `_sizes.json`; null before the watcher is ready. */
|
|
@@ -1612,6 +1919,22 @@ const RUN_T = {
|
|
|
1612
1919
|
runMs: 42e4
|
|
1613
1920
|
};
|
|
1614
1921
|
/** The page's own bound on `flush()` (recorder.ts): the driver waits that long, and `callMs` more. */
|
|
1922
|
+
/** Spec 30's error sources that do not make a run invalid (above), and the drops under a source's own limit: none of them is
|
|
1923
|
+
* a frame, a move or an error the run counts. */
|
|
1924
|
+
const SOFT_SOURCES = /* @__PURE__ */ new Set([
|
|
1925
|
+
"console",
|
|
1926
|
+
"api",
|
|
1927
|
+
"resource"
|
|
1928
|
+
]);
|
|
1929
|
+
const OWN_LIMITS = /* @__PURE__ */ new Set([
|
|
1930
|
+
"errors",
|
|
1931
|
+
"console",
|
|
1932
|
+
"api",
|
|
1933
|
+
"resource",
|
|
1934
|
+
"cmd",
|
|
1935
|
+
"theme",
|
|
1936
|
+
"mode"
|
|
1937
|
+
]);
|
|
1615
1938
|
const FLUSH_MS = 15e3;
|
|
1616
1939
|
const RECORDS_MAX = 2e4;
|
|
1617
1940
|
const live = /* @__PURE__ */ new Map();
|
|
@@ -1710,10 +2033,21 @@ const runSeams = {};
|
|
|
1710
2033
|
/** RUN_T, with the suite's overrides: `runSeams.t` in-process, `MV_PERF_RUN_T` (JSON) for a dev server a test starts -
|
|
1711
2034
|
* both read only with MARVER_SLOT_BASE set (the suite's marker). */
|
|
1712
2035
|
function runT() {
|
|
1713
|
-
|
|
2036
|
+
const t = { ...RUN_T };
|
|
2037
|
+
if (!process.env.MARVER_SLOT_BASE) return t;
|
|
2038
|
+
let env = {};
|
|
2039
|
+
try {
|
|
2040
|
+
env = JSON.parse(process.env.MV_PERF_RUN_T ?? "{}");
|
|
2041
|
+
} catch {}
|
|
2042
|
+
for (const src of [env, runSeams.t ?? {}]) for (const k of Object.keys(t)) {
|
|
2043
|
+
const v = src[k];
|
|
2044
|
+
if (typeof v === "number" && v >= 0) t[k] = v;
|
|
2045
|
+
}
|
|
2046
|
+
return t;
|
|
1714
2047
|
}
|
|
1715
|
-
/** The shell's address for a run's load: its run id, the warm-up's mark, the
|
|
1716
|
-
|
|
2048
|
+
/** The shell's address for a run's load: its run id, the warm-up's mark, the recorder's level when not `full` (spec 30
|
|
2049
|
+
* #58: the shell reads it, `withWs()` carries it to the frames), the board. */
|
|
2050
|
+
const runUrl = (origin, board, id, warm, recorder = "full") => `${origin}/?${RUN_PARAM}=${id}${warm ? `&${WARM_PARAM}=1` : ""}${recorder === "core" ? `&${RECORDER_PARAM}=core` : ""}#/b/${encodeURIComponent(board)}`;
|
|
1717
2051
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1718
2052
|
/** The last runs' own input paths, for `GET /api/perf/inputs?run=<id>` (the review of a3-runs' fixes): a run's set
|
|
1719
2053
|
* outside the root is its page's, which no request without the run can rebuild. Module state, the newest 32. */
|
|
@@ -1777,6 +2111,7 @@ async function openPage(b, o) {
|
|
|
1777
2111
|
}
|
|
1778
2112
|
};
|
|
1779
2113
|
function call(m, p = {}, sid, ms = T.callMs) {
|
|
2114
|
+
runSeams.cdp?.(m, p);
|
|
1780
2115
|
const sent = b.send(m, p, sid, own);
|
|
1781
2116
|
let t;
|
|
1782
2117
|
const late = new Promise((_, reject) => {
|
|
@@ -1840,6 +2175,7 @@ async function openPage(b, o) {
|
|
|
1840
2175
|
async function closePage(b, page) {
|
|
1841
2176
|
page.stop();
|
|
1842
2177
|
const bounded = async (m, p, sid) => {
|
|
2178
|
+
runSeams.cdp?.(m, p);
|
|
1843
2179
|
let t;
|
|
1844
2180
|
await Promise.race([b.send(m, p, sid).catch(() => {}), new Promise((r) => {
|
|
1845
2181
|
t = setTimeout(r, 2e3);
|
|
@@ -2007,9 +2343,9 @@ function runLine(reg, s) {
|
|
|
2007
2343
|
const own = load ? recs.filter((r) => r.load === load.request) : [];
|
|
2008
2344
|
const commit = own.find((r) => r.kind === "commit"), settled = own.find((r) => r.kind === "settled");
|
|
2009
2345
|
const moves = own.filter((r) => r.kind === "move");
|
|
2010
|
-
const errors = recs.filter((r) => r.kind === "error").length;
|
|
2346
|
+
const errors = recs.filter((r) => r.kind === "error" && !SOFT_SOURCES.has(r.source)).length;
|
|
2011
2347
|
const badFrames = settled ? (settled.missing ?? 0) + (settled.neverReady ?? 0) : 0;
|
|
2012
|
-
const lost = recs.filter((r) => r.kind === "dropped" && r.reason
|
|
2348
|
+
const lost = recs.filter((r) => r.kind === "dropped" && !OWN_LIMITS.has(r.reason)).reduce((n, r) => n + (typeof r.n === "number" && r.n > 0 ? r.n : 1), 0) + (reg.overflow ?? 0);
|
|
2013
2349
|
const reasons = [
|
|
2014
2350
|
["cancelled", s.cancelled],
|
|
2015
2351
|
["crash", s.crashed],
|
|
@@ -2041,6 +2377,7 @@ function runLine(reg, s) {
|
|
|
2041
2377
|
host: s.host,
|
|
2042
2378
|
power: s.power,
|
|
2043
2379
|
slow: s.slow,
|
|
2380
|
+
recorder: s.recorder ?? "full",
|
|
2044
2381
|
bakes: s.bakes,
|
|
2045
2382
|
postersMissing: s.postersSkipped,
|
|
2046
2383
|
saved: commit ? {
|
|
@@ -2078,6 +2415,7 @@ async function runOnce(o) {
|
|
|
2078
2415
|
id,
|
|
2079
2416
|
board: o.board,
|
|
2080
2417
|
slow: o.slow,
|
|
2418
|
+
recorder: o.recorder ?? "full",
|
|
2081
2419
|
startedAt: reg.startedAt,
|
|
2082
2420
|
inputs: null,
|
|
2083
2421
|
inputsEnd: null,
|
|
@@ -2103,7 +2441,7 @@ async function runOnce(o) {
|
|
|
2103
2441
|
const paths = o.watch ? await inputPaths(o.root, o.watch, urls) : null;
|
|
2104
2442
|
if (!paths) return;
|
|
2105
2443
|
set.paths = paths;
|
|
2106
|
-
seen.inputs = await hashInputs(o.root, paths);
|
|
2444
|
+
seen.inputs = await hashInputs(o.root, paths, o.recorder);
|
|
2107
2445
|
};
|
|
2108
2446
|
const requested = /* @__PURE__ */ new Set();
|
|
2109
2447
|
let offRequests = () => {};
|
|
@@ -2157,7 +2495,7 @@ async function runOnce(o) {
|
|
|
2157
2495
|
const url = m.sessionId === warmSession && m.method === "Network.requestWillBeSent" ? m.params?.request?.url : void 0;
|
|
2158
2496
|
if (typeof url === "string" && url.startsWith(`${o.origin}/`)) requested.add(url);
|
|
2159
2497
|
});
|
|
2160
|
-
await page.send("Page.navigate", { url: runUrl(o.origin, o.board, id, true) });
|
|
2498
|
+
await page.send("Page.navigate", { url: runUrl(o.origin, o.board, id, true, o.recorder) });
|
|
2161
2499
|
const warm = await until(page, (s) => loadEnded(s) && bakeIdle(id)(s), T.warmMs, halt(page));
|
|
2162
2500
|
seen.bakes = warm.ok ? "warm" : "cold";
|
|
2163
2501
|
seen.refusedInPage += warm.status?.refused ?? 0;
|
|
@@ -2196,7 +2534,7 @@ async function runOnce(o) {
|
|
|
2196
2534
|
};
|
|
2197
2535
|
const heapTimer = setInterval(sampleHeap, T.heapMs);
|
|
2198
2536
|
try {
|
|
2199
|
-
await p.send("Page.navigate", { url: runUrl(o.origin, o.board, id, false) });
|
|
2537
|
+
await p.send("Page.navigate", { url: runUrl(o.origin, o.board, id, false, o.recorder) });
|
|
2200
2538
|
sampleHeap();
|
|
2201
2539
|
const loaded = await until(p, loadEnded, T.settleMs, hp);
|
|
2202
2540
|
if (!loaded.ok || loaded.status?.load?.state === "cut") seen.cut = loaded.status?.load?.reason ?? (p.crashed ? "crash" : "timeout");
|
|
@@ -2255,7 +2593,7 @@ async function runOnce(o) {
|
|
|
2255
2593
|
lingering.add(id);
|
|
2256
2594
|
}
|
|
2257
2595
|
await sleep(T.watcherLagMs);
|
|
2258
|
-
seen.inputsEnd = set.paths ? (await hashInputs(o.root, set.paths)).hash : null;
|
|
2596
|
+
seen.inputsEnd = set.paths ? (await hashInputs(o.root, set.paths, o.recorder)).hash : null;
|
|
2259
2597
|
const done = runs.end(id) ?? reg;
|
|
2260
2598
|
seen.cancelled ||= o.signal.aborted;
|
|
2261
2599
|
const line = runLine(done, seen);
|
|
@@ -2301,7 +2639,7 @@ function readRunRequest(raw, boards) {
|
|
|
2301
2639
|
}
|
|
2302
2640
|
if (!b || typeof b !== "object" || Array.isArray(b)) return {
|
|
2303
2641
|
ok: false,
|
|
2304
|
-
error: "expected { board, slow?, repeat? }"
|
|
2642
|
+
error: "expected { board, slow?, repeat?, recorder? }"
|
|
2305
2643
|
};
|
|
2306
2644
|
if (typeof b.board !== "string" || !boards.includes(b.board)) return {
|
|
2307
2645
|
ok: false,
|
|
@@ -2316,12 +2654,17 @@ function readRunRequest(raw, boards) {
|
|
|
2316
2654
|
ok: false,
|
|
2317
2655
|
error: "repeat must be 1-5"
|
|
2318
2656
|
};
|
|
2657
|
+
if (b.recorder !== void 0 && !RECORDER_LEVELS.includes(b.recorder)) return {
|
|
2658
|
+
ok: false,
|
|
2659
|
+
error: "recorder must be core or full"
|
|
2660
|
+
};
|
|
2319
2661
|
return {
|
|
2320
2662
|
ok: true,
|
|
2321
2663
|
req: {
|
|
2322
2664
|
board: b.board,
|
|
2323
2665
|
slow: b.slow === true,
|
|
2324
|
-
repeat
|
|
2666
|
+
repeat,
|
|
2667
|
+
recorder: b.recorder === "core" ? "core" : "full"
|
|
2325
2668
|
}
|
|
2326
2669
|
};
|
|
2327
2670
|
}
|
|
@@ -2357,12 +2700,13 @@ async function serveRun(req, res, o) {
|
|
|
2357
2700
|
};
|
|
2358
2701
|
const beat = setInterval(() => write({ heartbeat: Date.now() }), T.heartbeatMs);
|
|
2359
2702
|
try {
|
|
2360
|
-
const drive = runOnce;
|
|
2703
|
+
const drive = runSeams.driver ?? runOnce;
|
|
2361
2704
|
for (let i = 0; i < asked.req.repeat && !ac.signal.aborted; i++) write({ line: await drive({
|
|
2362
2705
|
root: o.root,
|
|
2363
2706
|
origin: o.origin,
|
|
2364
2707
|
board: asked.req.board,
|
|
2365
2708
|
slow: asked.req.slow,
|
|
2709
|
+
recorder: asked.req.recorder,
|
|
2366
2710
|
signal: ac.signal,
|
|
2367
2711
|
progress: write,
|
|
2368
2712
|
watch: o.watch
|
|
@@ -2420,6 +2764,32 @@ function readBody(req, limit = BODY_LIMIT) {
|
|
|
2420
2764
|
req.on("error", () => done(null));
|
|
2421
2765
|
});
|
|
2422
2766
|
}
|
|
2767
|
+
/** A raw body (A4.6 #37): `limit` counted as the bytes arrive, never trusting `content-length` - past it `large`, and
|
|
2768
|
+
* nothing more is kept; `stop` ends the read where it stands. The socket is left alone, so the answer still goes out. */
|
|
2769
|
+
function readBytes(req, limit, stop) {
|
|
2770
|
+
return new Promise((done) => {
|
|
2771
|
+
let size = 0, settled = false;
|
|
2772
|
+
const chunks = [];
|
|
2773
|
+
const end = (v) => {
|
|
2774
|
+
if (!settled) {
|
|
2775
|
+
settled = true;
|
|
2776
|
+
chunks.length = 0;
|
|
2777
|
+
done(v);
|
|
2778
|
+
}
|
|
2779
|
+
};
|
|
2780
|
+
req.on("data", (c) => {
|
|
2781
|
+
if (settled) return;
|
|
2782
|
+
size += c.length;
|
|
2783
|
+
if (size > limit) end("large");
|
|
2784
|
+
else chunks.push(c);
|
|
2785
|
+
});
|
|
2786
|
+
req.on("end", () => end(Buffer.concat(chunks)));
|
|
2787
|
+
req.on("error", () => end("error"));
|
|
2788
|
+
stop?.addEventListener("abort", () => end("stopped"), { once: true });
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
/** A live picture's bytes at most (A4.6 #37): a 4096 px image of a design is well under it. */
|
|
2792
|
+
const LIVE_PICTURE_MAX = 8388608;
|
|
2423
2793
|
/** Atomic write: random temp name (no predictable symlink target), rename, and a
|
|
2424
2794
|
* copy-fallback only for the Windows rename errors - anything else rethrows. */
|
|
2425
2795
|
function atomicWrite(file, content) {
|
|
@@ -2506,9 +2876,40 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2506
2876
|
const notSymlink = (p) => !nodeExists(p) || isRegularFile(p);
|
|
2507
2877
|
const nodeExists$1 = nodeExists;
|
|
2508
2878
|
let sizesWarned = false;
|
|
2879
|
+
/** A board file this request wrote (spec 30 #18), with the page and commands it names - the watcher's `sh:board`
|
|
2880
|
+
* matches these bytes against it, as a candidate, never as proof. */
|
|
2881
|
+
const wroteBoard = (req, board, content) => {
|
|
2882
|
+
const who = writerFrom(req.headers);
|
|
2883
|
+
if (who) noteWrite(root, board, hash(content), who);
|
|
2884
|
+
};
|
|
2509
2885
|
try {
|
|
2510
2886
|
for (const f of readdirSync(boardsDir)) if (f.endsWith(".tmp")) rmSync(join(boardsDir, f), { force: true });
|
|
2511
2887
|
} catch {}
|
|
2888
|
+
/** `POST jam/picture/live?capture=&frame=` (A4.6 #37), in order: a PNG body, a capture id, a frame of the manifest, a
|
|
2889
|
+
* capture not sealed; then the bytes, 8 MB at most as they arrive, their signature and the whole PNG; and the capture
|
|
2890
|
+
* still not sealed, just before it is stored. Nothing is stored once `stop` (the deadline) has fired. */
|
|
2891
|
+
const livePicture = async (req, url, stop) => {
|
|
2892
|
+
const { CAPTURE_ID, addPictureBytes, checkPng, isPng, readCapture, sweepPictures } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
|
|
2893
|
+
if (String(req.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase() !== "image/png") return [415, { error: "expected image/png" }];
|
|
2894
|
+
const capture = url.searchParams.get("capture") ?? "", frame = url.searchParams.get("frame") ?? "";
|
|
2895
|
+
if (!CAPTURE_ID.test(capture)) return [400, { error: "bad capture id" }];
|
|
2896
|
+
if (!devFrames().some((f) => f.id === frame)) return [404, { error: "unknown frame" }];
|
|
2897
|
+
if (readCapture(root, capture)) return [409, { error: "that capture is sealed" }];
|
|
2898
|
+
const png = await readBytes(req, LIVE_PICTURE_MAX, stop);
|
|
2899
|
+
if (png === "large") return [413, { error: `a live picture is ${LIVE_PICTURE_MAX / 2 ** 20} MB at most` }];
|
|
2900
|
+
if (typeof png === "string") return [400, { error: "the picture did not arrive whole" }];
|
|
2901
|
+
if (!isPng(png)) return [415, { error: "not a PNG" }];
|
|
2902
|
+
const checked = await checkPng(png);
|
|
2903
|
+
if (typeof checked === "string") return [400, { error: `not a picture it takes: ${checked}` }];
|
|
2904
|
+
if (stop.aborted) return [408, { error: "the picture took too long" }];
|
|
2905
|
+
if (readCapture(root, capture)) return [409, { error: "that capture is sealed" }];
|
|
2906
|
+
sweepPictures(root);
|
|
2907
|
+
return [200, { id: addPictureBytes(root, png, {
|
|
2908
|
+
frame,
|
|
2909
|
+
capture,
|
|
2910
|
+
source: "live"
|
|
2911
|
+
}) }];
|
|
2912
|
+
};
|
|
2512
2913
|
return async (req, res, next) => {
|
|
2513
2914
|
const url = new URL(req.url ?? "/", "http://x");
|
|
2514
2915
|
if (!url.pathname.startsWith(`/__mv/api/`)) return next();
|
|
@@ -2700,6 +3101,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2700
3101
|
}
|
|
2701
3102
|
renameSync(tmp, w.file);
|
|
2702
3103
|
done.push(w);
|
|
3104
|
+
if (!w.plan) wroteBoard(req, name, w.next);
|
|
2703
3105
|
} catch (err) {
|
|
2704
3106
|
if (tmp) discard(tmp);
|
|
2705
3107
|
const stuck = undo();
|
|
@@ -2726,7 +3128,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2726
3128
|
};
|
|
2727
3129
|
if (path === "perf/reload" && req.method === "POST") {
|
|
2728
3130
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
2729
|
-
const raw = await readBody(req);
|
|
3131
|
+
const raw = await readBody(req, PAGE_BODY_MAX);
|
|
2730
3132
|
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
2731
3133
|
let b;
|
|
2732
3134
|
try {
|
|
@@ -2734,19 +3136,9 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2734
3136
|
} catch {
|
|
2735
3137
|
return json(res, 400, { error: "malformed JSON" });
|
|
2736
3138
|
}
|
|
2737
|
-
|
|
2738
|
-
const
|
|
2739
|
-
|
|
2740
|
-
(await import("./perf-jam-QxD_UnzN.mjs").then((n) => n.c)).logReload(root, {
|
|
2741
|
-
kind: str(b.kind),
|
|
2742
|
-
tab: str(b.tab),
|
|
2743
|
-
node: str(b.node),
|
|
2744
|
-
frame: str(b.frame),
|
|
2745
|
-
cause: str(b.cause),
|
|
2746
|
-
shown: str(b.shown),
|
|
2747
|
-
ms: num(b.ms)
|
|
2748
|
-
});
|
|
2749
|
-
return json(res, 200, { ok: true });
|
|
3139
|
+
if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
|
|
3140
|
+
const answer = takeReloadBatch(root, b.records);
|
|
3141
|
+
return json(res, "error" in answer ? 503 : 200, answer);
|
|
2750
3142
|
}
|
|
2751
3143
|
if (path === "perf/jam" && req.method === "POST") {
|
|
2752
3144
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
@@ -2759,7 +3151,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2759
3151
|
return json(res, 400, { error: "malformed JSON" });
|
|
2760
3152
|
}
|
|
2761
3153
|
if (!b || b.kind !== "capture" && b.kind !== "upload") return json(res, 400, { error: "kind must be capture or upload" });
|
|
2762
|
-
(await import("./perf-
|
|
3154
|
+
(await import("./perf-BCxAo0IS.mjs").then((n) => n.f)).logJam(root, b);
|
|
2763
3155
|
return json(res, 200, { ok: true });
|
|
2764
3156
|
}
|
|
2765
3157
|
if (path === "perf/page" && req.method === "POST") {
|
|
@@ -2775,13 +3167,11 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2775
3167
|
return json(res, 400, { error: "malformed JSON" });
|
|
2776
3168
|
}
|
|
2777
3169
|
if (!Array.isArray(b?.records)) return json(res, 400, { error: "expected { records: [...] }" });
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
} : {})
|
|
2784
|
-
});
|
|
3170
|
+
const answer = takePageBatch(root, b.records, run ? {
|
|
3171
|
+
run,
|
|
3172
|
+
kept: (recs) => runs.records(run, recs)
|
|
3173
|
+
} : {});
|
|
3174
|
+
return json(res, "error" in answer ? 503 : 200, answer);
|
|
2785
3175
|
}
|
|
2786
3176
|
if (path === "perf/run" && req.method === "POST" || path === "perf/inputs" && req.method === "GET") {
|
|
2787
3177
|
const { readDevInfo } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
|
|
@@ -2894,7 +3284,9 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2894
3284
|
const frames = Array.isArray(parsed?.frames) ? parsed.frames.filter((f) => typeof f === "string" && live.includes(f)) : [];
|
|
2895
3285
|
if (!validName(parsed?.board) || !frames.length) return json(res, 400, { error: "a board and frames on this canvas" });
|
|
2896
3286
|
try {
|
|
2897
|
-
|
|
3287
|
+
const pinned = pinFrames(root, parsed.board, frames, live);
|
|
3288
|
+
if (pinned.added.length) wroteBoard(req, parsed.board, readFileSync(join(boardsDir, `${parsed.board}.json`), "utf8"));
|
|
3289
|
+
return json(res, 200, pinned);
|
|
2898
3290
|
} catch (err) {
|
|
2899
3291
|
return json(res, 409, { error: err.message });
|
|
2900
3292
|
}
|
|
@@ -2968,12 +3360,14 @@ function apiMiddleware(root, opts = {}) {
|
|
|
2968
3360
|
return json(res, 200, { name: to });
|
|
2969
3361
|
}
|
|
2970
3362
|
rmSync(fromPath);
|
|
3363
|
+
if (next !== void 0) wroteBoard(req, to, next);
|
|
2971
3364
|
return json(res, 200, {
|
|
2972
3365
|
name: to,
|
|
2973
3366
|
...next !== void 0 ? { sha256: hash(next) } : {}
|
|
2974
3367
|
});
|
|
2975
3368
|
}
|
|
2976
3369
|
atomicWrite(toPath, next);
|
|
3370
|
+
wroteBoard(req, to, next);
|
|
2977
3371
|
return json(res, 200, {
|
|
2978
3372
|
name: to,
|
|
2979
3373
|
sha256: hash(next)
|
|
@@ -3139,6 +3533,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3139
3533
|
else delete w.obj.folder;
|
|
3140
3534
|
const next = JSON.stringify(w.obj, null, 2) + "\n";
|
|
3141
3535
|
atomicWrite(w.path, next);
|
|
3536
|
+
wroteBoard(req, w.name, next);
|
|
3142
3537
|
sha256[w.name] = hash(next);
|
|
3143
3538
|
}
|
|
3144
3539
|
mkdirSync(boardsDir, { recursive: true });
|
|
@@ -3226,6 +3621,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3226
3621
|
} catch {}
|
|
3227
3622
|
const next2 = JSON.stringify(body.board, null, 2) + "\n";
|
|
3228
3623
|
atomicWrite(p, next2);
|
|
3624
|
+
wroteBoard(req, boardMatch[1], next2);
|
|
3229
3625
|
return json(res, 200, { sha256: hash(next2) });
|
|
3230
3626
|
} finally {
|
|
3231
3627
|
unlock();
|
|
@@ -3249,7 +3645,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3249
3645
|
};
|
|
3250
3646
|
const asPng = url.searchParams.get("format") === "png";
|
|
3251
3647
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3252
|
-
const { shootFrame } = await import("./shot-
|
|
3648
|
+
const { shootFrame } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
3253
3649
|
const r = await shootFrame({
|
|
3254
3650
|
root,
|
|
3255
3651
|
viewports: opts.viewports ?? {},
|
|
@@ -3300,7 +3696,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3300
3696
|
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
|
|
3301
3697
|
const scale = body.scale === void 0 ? void 0 : body.scale;
|
|
3302
3698
|
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
|
|
3303
|
-
const { resolveFrames, shootBatch } = await import("./shot-
|
|
3699
|
+
const { resolveFrames, shootBatch } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
3304
3700
|
const sel = resolveFrames(root, body);
|
|
3305
3701
|
if (!sel.ok) return json(res, sel.status, { error: sel.error });
|
|
3306
3702
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
@@ -3334,7 +3730,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3334
3730
|
if (typeof target === "string") return json(res, 400, { error: target });
|
|
3335
3731
|
const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
|
|
3336
3732
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3337
|
-
const { checkAnchor, CheckInputError } = await import("./anchor-check-
|
|
3733
|
+
const { checkAnchor, CheckInputError } = await import("./anchor-check-c52IDkiQ.mjs");
|
|
3338
3734
|
try {
|
|
3339
3735
|
return json(res, 200, await checkAnchor({
|
|
3340
3736
|
root,
|
|
@@ -3384,7 +3780,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3384
3780
|
});
|
|
3385
3781
|
docs.push(typeof a?.doc === "string" ? a.doc : void 0);
|
|
3386
3782
|
}
|
|
3387
|
-
const { docRev } = await import("./marks-
|
|
3783
|
+
const { docRev } = await import("./marks-BnNANic9.mjs").then((n) => n.a);
|
|
3388
3784
|
const all = devManifest().frames;
|
|
3389
3785
|
const pending = opts.settled ? !opts.settled() : false;
|
|
3390
3786
|
const behind = docs.map((d, i) => d !== void 0 && (pending || d !== docRev(root, all, asks[i].frame)));
|
|
@@ -3442,8 +3838,8 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3442
3838
|
return json(res, 400, { error: "malformed JSON" });
|
|
3443
3839
|
}
|
|
3444
3840
|
const src = typeof b?.src === "string" ? b.src : "";
|
|
3445
|
-
const { ensurePoster, isLocalClip } = await import("./poster-
|
|
3446
|
-
const { isLocalAssetRef } = await import("./build-
|
|
3841
|
+
const { ensurePoster, isLocalClip } = await import("./poster-CYmCa00B.mjs");
|
|
3842
|
+
const { isLocalAssetRef } = await import("./build-C3mUtjEn.mjs");
|
|
3447
3843
|
if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
|
|
3448
3844
|
const r = await ensurePoster(join(root, "design", "assets"), src);
|
|
3449
3845
|
if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
|
|
@@ -3486,7 +3882,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3486
3882
|
}
|
|
3487
3883
|
if (path === "marks" || path === "marks/seen") {
|
|
3488
3884
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
3489
|
-
const { readMarks, markSeen } = await import("./marks-
|
|
3885
|
+
const { readMarks, markSeen } = await import("./marks-BnNANic9.mjs").then((n) => n.a);
|
|
3490
3886
|
const manifest = devManifest();
|
|
3491
3887
|
if (path === "marks" && req.method === "GET") return json(res, 200, readMarks(root, manifest));
|
|
3492
3888
|
if (path === "marks/seen" && req.method === "POST") {
|
|
@@ -3536,7 +3932,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3536
3932
|
if (!on && b.all === true) {
|
|
3537
3933
|
const done = workActivity.active().filter((f) => workActivity.has(f, "cli"));
|
|
3538
3934
|
if (done.length) {
|
|
3539
|
-
(await import("./marks-
|
|
3935
|
+
(await import("./marks-BnNANic9.mjs").then((n) => n.a)).recordChanged(root, devFrames(), done, { doc: false });
|
|
3540
3936
|
opts.notify?.("sh:marks");
|
|
3541
3937
|
}
|
|
3542
3938
|
workActivity.clearAll("cli");
|
|
@@ -3556,7 +3952,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3556
3952
|
for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
|
|
3557
3953
|
saveHolds(root, workActivity);
|
|
3558
3954
|
if (!on) {
|
|
3559
|
-
(await import("./marks-
|
|
3955
|
+
(await import("./marks-BnNANic9.mjs").then((n) => n.a)).recordChanged(root, devFrames(), frames, { doc: false });
|
|
3560
3956
|
opts.notify?.("sh:marks");
|
|
3561
3957
|
return json(res, 200, { frames: workActivity.active() });
|
|
3562
3958
|
}
|
|
@@ -3592,7 +3988,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3592
3988
|
}
|
|
3593
3989
|
if (path === "jam/queue" && req.method === "GET") {
|
|
3594
3990
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
3595
|
-
const { jamLive } = await
|
|
3991
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3596
3992
|
return json(res, 200, jamLive.view?.() ?? {
|
|
3597
3993
|
agent: null,
|
|
3598
3994
|
cards: [],
|
|
@@ -3609,10 +4005,10 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3609
4005
|
} catch {
|
|
3610
4006
|
return json(res, 400, { error: "malformed JSON" });
|
|
3611
4007
|
}
|
|
3612
|
-
const { ACTIONS } = await import("./queue-
|
|
4008
|
+
const { ACTIONS } = await import("./queue-DeSQm24g.mjs");
|
|
3613
4009
|
if (!b || typeof b.id !== "string" || !Number.isInteger(b.rev) || !ACTIONS.includes(b.action) || b.body !== void 0 && typeof b.body !== "string") return json(res, 400, { error: "expected { id, rev, action, body? }" });
|
|
3614
4010
|
if ("kind" in b) return json(res, 400, { error: "a capture has no category" });
|
|
3615
|
-
const { jamLive } = await
|
|
4011
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3616
4012
|
if (!jamLive.act) return json(res, 409, { error: "jam is not running here" });
|
|
3617
4013
|
const r = await jamLive.act(b.id, b.rev, b.action, b.body);
|
|
3618
4014
|
return json(res, r.ok ? 200 : 409, r);
|
|
@@ -3650,11 +4046,11 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3650
4046
|
}
|
|
3651
4047
|
if (path === "jam/session" && (req.method === "GET" || req.method === "POST")) {
|
|
3652
4048
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
3653
|
-
const { jamLive } = await
|
|
4049
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3654
4050
|
if (!jamLive.session || !jamLive.view) return json(res, 409, { error: "jam is not running here" });
|
|
3655
4051
|
if (req.method === "GET") {
|
|
3656
4052
|
const ses = jamLive.view().session ?? null;
|
|
3657
|
-
const { readTalk, talkMinutes, recordFile } = await import("./session-
|
|
4053
|
+
const { readTalk, talkMinutes, recordFile } = await import("./session-VDJfXEEm.mjs").then((n) => n.s);
|
|
3658
4054
|
const folder = ses ? recordFile(root, ses.since, ses.id).replace(/[^/]+$/, "") : null;
|
|
3659
4055
|
return json(res, 200, {
|
|
3660
4056
|
session: ses,
|
|
@@ -3703,7 +4099,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3703
4099
|
id: b.id
|
|
3704
4100
|
});
|
|
3705
4101
|
if (r.ok && b.action === "start") {
|
|
3706
|
-
const { ensureConnectors } = await import("./connectors-
|
|
4102
|
+
const { ensureConnectors } = await import("./connectors-DekQvKt9.mjs");
|
|
3707
4103
|
const connectors = ensureConnectors(root);
|
|
3708
4104
|
jamLive.connectors = connectors;
|
|
3709
4105
|
return json(res, 200, {
|
|
@@ -3728,7 +4124,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3728
4124
|
"background",
|
|
3729
4125
|
"drop"
|
|
3730
4126
|
].includes(b.action)) return json(res, 400, { error: "expected { batch, gen, action }" });
|
|
3731
|
-
const { jamLive } = await
|
|
4127
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3732
4128
|
if (!jamLive.runAct) return json(res, 409, { error: "jam is not running here" });
|
|
3733
4129
|
const r = await jamLive.runAct(b.batch, b.gen, b.action);
|
|
3734
4130
|
jamLive.refresh?.();
|
|
@@ -3737,8 +4133,8 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3737
4133
|
if (path === "jam/prefs" && (req.method === "GET" || req.method === "POST")) {
|
|
3738
4134
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
3739
4135
|
const { readPrefs, writePrefs, validConnId } = await import("./conn-BMiHS42T.mjs").then((n) => n.a);
|
|
3740
|
-
const { ensureConnectors, present } = await import("./connectors-
|
|
3741
|
-
const { jamLive } = await
|
|
4136
|
+
const { ensureConnectors, present } = await import("./connectors-DekQvKt9.mjs");
|
|
4137
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3742
4138
|
const tools = [
|
|
3743
4139
|
"claude",
|
|
3744
4140
|
"codex",
|
|
@@ -3800,7 +4196,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3800
4196
|
} catch {
|
|
3801
4197
|
return json(res, 400, { error: "malformed JSON" });
|
|
3802
4198
|
}
|
|
3803
|
-
const { jamLive } = await
|
|
4199
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3804
4200
|
if (!jamLive.captureOpen) return json(res, 409, { error: "jam is not running here" });
|
|
3805
4201
|
if (typeof b?.capture !== "string" || typeof b?.session !== "string") return json(res, 400, { error: "expected { capture, session, on }" });
|
|
3806
4202
|
return jamLive.captureOpen(b.capture, b.session, b.on === true) === "ended" ? json(res, 409, {
|
|
@@ -3811,7 +4207,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3811
4207
|
}
|
|
3812
4208
|
if (path === "jam/record" && req.method === "GET") {
|
|
3813
4209
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
3814
|
-
const { jamLive } = await
|
|
4210
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3815
4211
|
const r = jamLive.record?.(url.searchParams.get("id") ?? "");
|
|
3816
4212
|
return r ? json(res, 200, r) : json(res, 404, { error: "no such record" });
|
|
3817
4213
|
}
|
|
@@ -3826,18 +4222,18 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3826
4222
|
return json(res, 400, { error: "malformed JSON" });
|
|
3827
4223
|
}
|
|
3828
4224
|
if (b?.workspace !== void 0 && b.workspace !== ws) return json(res, 409, { error: "this capture was made in another workspace" });
|
|
3829
|
-
const { jamLive } = await
|
|
4225
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3830
4226
|
if (!jamLive.capture) return json(res, 409, { error: "jam is not running here" });
|
|
3831
4227
|
const r = await jamLive.capture(b?.record);
|
|
3832
4228
|
return json(res, r.ok ? 200 : 400, r);
|
|
3833
4229
|
}
|
|
3834
4230
|
if (path === "jam/capture" && req.method === "GET") {
|
|
3835
4231
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
3836
|
-
const { readCapture } = await import("./capture-
|
|
4232
|
+
const { readCapture } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
|
|
3837
4233
|
const id = url.searchParams.get("id") ?? "";
|
|
3838
4234
|
const cap = readCapture(root, id);
|
|
3839
4235
|
if (!cap) return json(res, 404, { error: "no such capture" });
|
|
3840
|
-
const { jamLive } = await
|
|
4236
|
+
const { jamLive } = await Promise.resolve().then(() => live_exports);
|
|
3841
4237
|
const card = jamLive.view?.().cards.find((c) => c.id === id);
|
|
3842
4238
|
return json(res, 200, {
|
|
3843
4239
|
record: cap.record,
|
|
@@ -3856,11 +4252,11 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3856
4252
|
} catch {
|
|
3857
4253
|
return json(res, 400, { error: "malformed JSON" });
|
|
3858
4254
|
}
|
|
3859
|
-
const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-
|
|
4255
|
+
const { CAPTURE_ID, readCapture, addPicture, sweepPictures } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
|
|
3860
4256
|
if (!b || typeof b.capture !== "string" || !CAPTURE_ID.test(b.capture) || typeof b.frame !== "string") return json(res, 400, { error: "expected { capture, frame, theme?, viewport? }" });
|
|
3861
4257
|
if (readCapture(root, b.capture)) return json(res, 409, { error: "that capture is sealed" });
|
|
3862
4258
|
const theme = typeof b.theme === "string" && /^[a-z0-9-]+$/i.test(b.theme) ? b.theme : "light";
|
|
3863
|
-
const { shootFrame } = await import("./shot-
|
|
4259
|
+
const { shootFrame } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
3864
4260
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
3865
4261
|
const vp = typeof b.viewport === "string" ? opts.viewports?.[b.viewport] : void 0;
|
|
3866
4262
|
const dim = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
|
|
@@ -3892,10 +4288,24 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3892
4288
|
...unchecked ? { unchecked: true } : {}
|
|
3893
4289
|
});
|
|
3894
4290
|
}
|
|
4291
|
+
if (path === "jam/picture/live" && req.method === "POST") {
|
|
4292
|
+
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
4293
|
+
const stop = new AbortController();
|
|
4294
|
+
let timer;
|
|
4295
|
+
const late = new Promise((done) => {
|
|
4296
|
+
timer = setTimeout(() => {
|
|
4297
|
+
stop.abort();
|
|
4298
|
+
done([408, { error: "the picture took too long" }]);
|
|
4299
|
+
}, opts.livePictureMs ?? 1e4);
|
|
4300
|
+
});
|
|
4301
|
+
const [status, body] = await Promise.race([livePicture(req, url, stop.signal), late]).finally(() => clearTimeout(timer));
|
|
4302
|
+
if (status === 408 || status === 413) res.setHeader("connection", "close");
|
|
4303
|
+
return json(res, status, body);
|
|
4304
|
+
}
|
|
3895
4305
|
if (path === "jam/picture" && req.method === "GET") {
|
|
3896
4306
|
const site = String(req.headers["sec-fetch-site"] ?? "");
|
|
3897
4307
|
if (!ownerGated(req) && !(cookie(req, "mv_c") && (site === "same-origin" || site === "none"))) return json(res, 403, { error: "forbidden" });
|
|
3898
|
-
const { picturePath } = await import("./capture-
|
|
4308
|
+
const { picturePath } = await import("./capture-DEtM4qm5.mjs").then((n) => n.i);
|
|
3899
4309
|
const p = picturePath(root, url.searchParams.get("id") ?? "");
|
|
3900
4310
|
if (!p) return json(res, 404, { error: "no such picture" });
|
|
3901
4311
|
const png = readFileSync(p.path);
|
|
@@ -3946,13 +4356,13 @@ function apiMiddleware(root, opts = {}) {
|
|
|
3946
4356
|
const fresh = appendEvents(dir, cm[1], stamped);
|
|
3947
4357
|
const { record } = await import("./ledger-D54iROST.mjs").then((n) => n.n);
|
|
3948
4358
|
for (const ev of fresh) if (ev.type === "create" || ev.type === "reply" || ev.type === "edit") record(root, cm[1], ev.id);
|
|
3949
|
-
(await
|
|
4359
|
+
(await Promise.resolve().then(() => live_exports)).jamLive.poke?.();
|
|
3950
4360
|
backgroundPush(root);
|
|
3951
4361
|
return json(res, 200, { accepted: fresh.length });
|
|
3952
4362
|
}
|
|
3953
4363
|
}
|
|
3954
4364
|
if (path === "sync" && req.method === "POST") {
|
|
3955
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
4365
|
+
const { loadCollab, syncOnce } = await import("./sync-CMozOwZ0.mjs").then((n) => n.o);
|
|
3956
4366
|
const collab = loadCollab(root);
|
|
3957
4367
|
if (!collab) return json(res, 200, { connected: false });
|
|
3958
4368
|
try {
|
|
@@ -3981,42 +4391,13 @@ function backgroundPush(root) {
|
|
|
3981
4391
|
pushTimer = setTimeout(async () => {
|
|
3982
4392
|
pushTimer = null;
|
|
3983
4393
|
try {
|
|
3984
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
4394
|
+
const { loadCollab, syncOnce } = await import("./sync-CMozOwZ0.mjs").then((n) => n.o);
|
|
3985
4395
|
const collab = loadCollab(root);
|
|
3986
4396
|
if (collab) await syncOnce(root, collab);
|
|
3987
4397
|
} catch {}
|
|
3988
4398
|
}, 1500);
|
|
3989
4399
|
}
|
|
3990
4400
|
//#endregion
|
|
3991
|
-
//#region src/server/proof.ts
|
|
3992
|
-
/**
|
|
3993
|
-
* The document proof (spec 28 A1.4). The Mac app puts a fresh nonce on every main-frame request to a
|
|
3994
|
-
* local canvas (`x-mv-nonce`) and checks the answer before the document commits; only the canvas
|
|
3995
|
-
* holding the slot file's key can sign it, so the privileges the app grants belong to that exact
|
|
3996
|
-
* document. The proof rides the very response the app commits - the check and the load can never
|
|
3997
|
-
* reach different listeners.
|
|
3998
|
-
*
|
|
3999
|
-
* Pinned exactly, so the app (A2.3 `proof.ts`) computes the same: the key is the slot file's 32 bytes
|
|
4000
|
-
* (base64url there), HMAC-SHA256 over UTF-8 `doc|<nonce>|<port>` (port in decimal), base64url without
|
|
4001
|
-
* padding. Requests from the app itself carry `app|<port>` the same way, and the logo the app fetches
|
|
4002
|
-
* (`GET /__mv/logo`, spec 28 A2.4) `logo|<nonce>|<port>`: a listener that took the port after the tab was
|
|
4003
|
-
* verified can never hand it a logo.
|
|
4004
|
-
*/
|
|
4005
|
-
/** 16-64 base64url characters - anything else is not a nonce, and is ignored. */
|
|
4006
|
-
const NONCE = /^[A-Za-z0-9_-]{16,64}$/;
|
|
4007
|
-
const sign$1 = (key, msg) => createHmac("sha256", key).update(msg, "utf8").digest("base64url");
|
|
4008
|
-
const docProof = (key, nonce, port) => sign$1(key, `doc|${nonce}|${port}`);
|
|
4009
|
-
const logoProof = (key, nonce, port) => sign$1(key, `logo|${nonce}|${port}`);
|
|
4010
|
-
/** The two headers for a request carrying a well-formed `x-mv-nonce`, else null: over the shell's document
|
|
4011
|
-
* (`doc`), or over the logo (`logo`). */
|
|
4012
|
-
function proofHeaders(p, nonce, kind = "doc") {
|
|
4013
|
-
if (!p || typeof nonce !== "string" || !NONCE.test(nonce)) return null;
|
|
4014
|
-
return {
|
|
4015
|
-
"x-mv-instance": p.instance,
|
|
4016
|
-
"x-mv-proof": (kind === "logo" ? logoProof : docProof)(p.key, nonce, p.port)
|
|
4017
|
-
};
|
|
4018
|
-
}
|
|
4019
|
-
//#endregion
|
|
4020
4401
|
//#region src/server/routes.ts
|
|
4021
4402
|
function routesMiddleware(server, clientDir, stamps, proof) {
|
|
4022
4403
|
const page = (dir) => {
|
|
@@ -4085,229 +4466,6 @@ function routesMiddleware(server, clientDir, stamps, proof) {
|
|
|
4085
4466
|
}
|
|
4086
4467
|
};
|
|
4087
4468
|
}
|
|
4088
|
-
/** The type each sniffed logo is served with. */
|
|
4089
|
-
const LOGO_MIME = {
|
|
4090
|
-
png: "image/png",
|
|
4091
|
-
ico: "image/x-icon",
|
|
4092
|
-
svg: "image/svg+xml"
|
|
4093
|
-
};
|
|
4094
|
-
const PNG = [
|
|
4095
|
-
137,
|
|
4096
|
-
80,
|
|
4097
|
-
78,
|
|
4098
|
-
71,
|
|
4099
|
-
13,
|
|
4100
|
-
10,
|
|
4101
|
-
26,
|
|
4102
|
-
10
|
|
4103
|
-
];
|
|
4104
|
-
/** The logo type these bytes are, or null when they are none of the three. */
|
|
4105
|
-
function sniffLogo(b) {
|
|
4106
|
-
if (b.length >= PNG.length && PNG.every((x, i) => b[i] === x)) return "png";
|
|
4107
|
-
if (b.length >= 4 && b[0] === 0 && b[1] === 0 && b[2] === 1 && b[3] === 0) return "ico";
|
|
4108
|
-
return svgRoot(b) ? "svg" : null;
|
|
4109
|
-
}
|
|
4110
|
-
/** Is this UTF-8 text an SVG document: its root element `<svg`, with only the prolog A2.14 #24 allows before it? */
|
|
4111
|
-
function svgRoot(b) {
|
|
4112
|
-
let s;
|
|
4113
|
-
try {
|
|
4114
|
-
s = new TextDecoder("utf-8", { fatal: true }).decode(b);
|
|
4115
|
-
} catch {
|
|
4116
|
-
return false;
|
|
4117
|
-
}
|
|
4118
|
-
let i = s.charCodeAt(0) === 65279 ? 1 : 0;
|
|
4119
|
-
const space = () => {
|
|
4120
|
-
while (i < s.length && /\s/.test(s[i])) i++;
|
|
4121
|
-
};
|
|
4122
|
-
space();
|
|
4123
|
-
if (s.startsWith("<?xml", i) && /[\s?]/.test(s[i + 5] ?? "")) {
|
|
4124
|
-
const end = s.indexOf("?>", i);
|
|
4125
|
-
if (end < 0) return false;
|
|
4126
|
-
i = end + 2;
|
|
4127
|
-
}
|
|
4128
|
-
let doctype = false;
|
|
4129
|
-
for (;;) {
|
|
4130
|
-
space();
|
|
4131
|
-
if (s.startsWith("<!--", i)) {
|
|
4132
|
-
const end = s.indexOf("-->", i + 4);
|
|
4133
|
-
if (end < 0) return false;
|
|
4134
|
-
i = end + 3;
|
|
4135
|
-
continue;
|
|
4136
|
-
}
|
|
4137
|
-
if (s.startsWith("<!DOCTYPE", i)) {
|
|
4138
|
-
if (doctype) return false;
|
|
4139
|
-
doctype = true;
|
|
4140
|
-
const end = doctypeEnd(s, i + 9);
|
|
4141
|
-
if (end < 0) return false;
|
|
4142
|
-
i = end;
|
|
4143
|
-
continue;
|
|
4144
|
-
}
|
|
4145
|
-
break;
|
|
4146
|
-
}
|
|
4147
|
-
return s.startsWith("<svg", i) && /[\s>/]/.test(s[i + 4] ?? "");
|
|
4148
|
-
}
|
|
4149
|
-
/** Just past the `>` that closes a `<!DOCTYPE svg ...>` whose body starts at `i`, or -1: another root name, an
|
|
4150
|
-
* internal subset (`[` outside quotes) or no end. Quoted public and system ids may hold anything but their quote. */
|
|
4151
|
-
function doctypeEnd(s, i) {
|
|
4152
|
-
if (!/\s/.test(s[i] ?? "")) return -1;
|
|
4153
|
-
while (i < s.length && /\s/.test(s[i])) i++;
|
|
4154
|
-
if (!s.startsWith("svg", i) || !/[\s>]/.test(s[i + 3] ?? "")) return -1;
|
|
4155
|
-
i += 3;
|
|
4156
|
-
while (i < s.length) {
|
|
4157
|
-
const c = s[i];
|
|
4158
|
-
if (c === ">") return i + 1;
|
|
4159
|
-
if (c === "[") return -1;
|
|
4160
|
-
if (c === "\"" || c === "'") {
|
|
4161
|
-
const close = s.indexOf(c, i + 1);
|
|
4162
|
-
if (close < 0) return -1;
|
|
4163
|
-
i = close + 1;
|
|
4164
|
-
continue;
|
|
4165
|
-
}
|
|
4166
|
-
i++;
|
|
4167
|
-
}
|
|
4168
|
-
return -1;
|
|
4169
|
-
}
|
|
4170
|
-
//#endregion
|
|
4171
|
-
//#region src/server/logo.ts
|
|
4172
|
-
const LOGO_LADDER = [
|
|
4173
|
-
"design/logo.svg",
|
|
4174
|
-
"design/logo.png",
|
|
4175
|
-
"public/logo.svg",
|
|
4176
|
-
"public/logo.png",
|
|
4177
|
-
"public/favicon.svg",
|
|
4178
|
-
"public/favicon.png",
|
|
4179
|
-
"public/favicon.ico"
|
|
4180
|
-
];
|
|
4181
|
-
/** The first candidate that passes every check, read whole; null when none does. `warn` hears why a `share.logo`
|
|
4182
|
-
* was ignored (the ladder's own entries are tried quietly: most repos have none of them). */
|
|
4183
|
-
function findLogo(root, shareLogo, warn) {
|
|
4184
|
-
let realRoot;
|
|
4185
|
-
try {
|
|
4186
|
-
realRoot = realpathSync(root);
|
|
4187
|
-
} catch {
|
|
4188
|
-
return null;
|
|
4189
|
-
}
|
|
4190
|
-
const own = typeof shareLogo === "string" && shareLogo !== "" ? shareLogo : null;
|
|
4191
|
-
for (const cand of new Set(own ? [own, ...LOGO_LADDER] : LOGO_LADDER)) {
|
|
4192
|
-
const r = readLogo(realRoot, resolve(realRoot, cand));
|
|
4193
|
-
if (typeof r !== "string") return {
|
|
4194
|
-
...r,
|
|
4195
|
-
from: cand
|
|
4196
|
-
};
|
|
4197
|
-
if (cand === own) warn?.(`share.logo ${own} is ignored: ${r}`);
|
|
4198
|
-
}
|
|
4199
|
-
return null;
|
|
4200
|
-
}
|
|
4201
|
-
/** One candidate: its bytes and type, or why it does not count. */
|
|
4202
|
-
function readLogo(realRoot, file) {
|
|
4203
|
-
let st;
|
|
4204
|
-
try {
|
|
4205
|
-
st = lstatSync(file);
|
|
4206
|
-
} catch (e) {
|
|
4207
|
-
return e.code === "ENOENT" || e.code === "ENOTDIR" ? "no such file" : "unreadable";
|
|
4208
|
-
}
|
|
4209
|
-
if (st.isSymbolicLink()) return "a symlink";
|
|
4210
|
-
if (!st.isFile()) return "not a file";
|
|
4211
|
-
if (!/\.(svg|png|ico)$/i.test(file)) return "not .svg, .png or .ico";
|
|
4212
|
-
if (st.size > 262144) return "over 256 KB";
|
|
4213
|
-
let real;
|
|
4214
|
-
try {
|
|
4215
|
-
real = realpathSync(file);
|
|
4216
|
-
} catch {
|
|
4217
|
-
return "unreadable";
|
|
4218
|
-
}
|
|
4219
|
-
if (!real.startsWith(realRoot + sep)) return "outside the repo";
|
|
4220
|
-
let fd;
|
|
4221
|
-
try {
|
|
4222
|
-
fd = openSync(real, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
4223
|
-
} catch {
|
|
4224
|
-
return "unreadable";
|
|
4225
|
-
}
|
|
4226
|
-
try {
|
|
4227
|
-
const f = fstatSync(fd);
|
|
4228
|
-
if (!f.isFile() || f.ino !== st.ino || f.dev !== st.dev) return "changed while it was read";
|
|
4229
|
-
const buf = Buffer.alloc(262145);
|
|
4230
|
-
let n = 0;
|
|
4231
|
-
for (let k = 1; k > 0 && n < buf.length; n += k) k = readSync(fd, buf, n, buf.length - n, null);
|
|
4232
|
-
if (n > 262144) return "over 256 KB";
|
|
4233
|
-
const bytes = Buffer.from(buf.subarray(0, n));
|
|
4234
|
-
const type = sniffLogo(bytes);
|
|
4235
|
-
return type ? {
|
|
4236
|
-
type,
|
|
4237
|
-
bytes
|
|
4238
|
-
} : "not an image (PNG, ICO or SVG)";
|
|
4239
|
-
} catch {
|
|
4240
|
-
return "unreadable";
|
|
4241
|
-
} finally {
|
|
4242
|
-
closeSync(fd);
|
|
4243
|
-
}
|
|
4244
|
-
}
|
|
4245
|
-
/** `marver build`: the logo into `<outDir>/__mv/logo.<type>` (an `.ico` as `logo.ico`), by its bytes - never a copy
|
|
4246
|
-
* that follows a link. Its published path, or undefined when the repo has none. */
|
|
4247
|
-
function publishLogo(root, shareLogo, outDir, warn) {
|
|
4248
|
-
const logo = findLogo(root, shareLogo, warn);
|
|
4249
|
-
if (!logo) return void 0;
|
|
4250
|
-
const dir = join(outDir, ROUTE.slice(1));
|
|
4251
|
-
mkdirSync(dir, { recursive: true });
|
|
4252
|
-
writeFileSync(join(dir, `logo.${logo.type}`), logo.bytes);
|
|
4253
|
-
return `${ROUTE}/logo.${logo.type}`;
|
|
4254
|
-
}
|
|
4255
|
-
/** A strong `ETag` for these bytes. */
|
|
4256
|
-
const logoTag = (bytes) => `"${createHash("sha256").update(bytes).digest("base64url").slice(0, 22)}"`;
|
|
4257
|
-
/** Does an `If-None-Match` name this tag (a list, a weak tag, or `*`)? */
|
|
4258
|
-
function matches(header, tag) {
|
|
4259
|
-
if (typeof header !== "string") return false;
|
|
4260
|
-
return header.split(",").map((t) => t.trim().replace(/^W\//, "")).some((t) => t === "*" || t === tag);
|
|
4261
|
-
}
|
|
4262
|
-
/**
|
|
4263
|
-
* `marver dev`'s `GET|HEAD /__mv/logo`. Read once per request (256 KB at most), checked, and answered with its sniffed
|
|
4264
|
-
* type, an `ETag` and `Cache-Control: no-cache`; `x-content-type-options: nosniff` and a CSP that runs nothing, so an
|
|
4265
|
-
* SVG opened as a page is a picture. A request carrying a well-formed `x-mv-nonce` gets the logo proof
|
|
4266
|
-
* (`x-mv-instance`, `x-mv-proof` over `logo|<nonce>|<port>`), on a 200 and a 304 alike. 404 when the repo has none.
|
|
4267
|
-
*/
|
|
4268
|
-
function logoRoute(root, shareLogo, proof) {
|
|
4269
|
-
const warned = /* @__PURE__ */ new Set();
|
|
4270
|
-
const warn = (m) => {
|
|
4271
|
-
if (warned.has(m)) return;
|
|
4272
|
-
warned.add(m);
|
|
4273
|
-
console.warn(` marver: ${m}`);
|
|
4274
|
-
};
|
|
4275
|
-
return (req, res, next) => {
|
|
4276
|
-
let path;
|
|
4277
|
-
try {
|
|
4278
|
-
path = new URL(req.url ?? "/", "http://x").pathname;
|
|
4279
|
-
} catch {
|
|
4280
|
-
return next();
|
|
4281
|
-
}
|
|
4282
|
-
if (path !== `/__mv/logo`) return next();
|
|
4283
|
-
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
4284
|
-
res.statusCode = 405;
|
|
4285
|
-
res.setHeader("allow", "GET, HEAD");
|
|
4286
|
-
return res.end();
|
|
4287
|
-
}
|
|
4288
|
-
const logo = findLogo(root, shareLogo(), warn);
|
|
4289
|
-
if (!logo) {
|
|
4290
|
-
res.statusCode = 404;
|
|
4291
|
-
res.setHeader("cache-control", "no-store");
|
|
4292
|
-
return res.end();
|
|
4293
|
-
}
|
|
4294
|
-
const tag = logoTag(logo.bytes);
|
|
4295
|
-
res.setHeader("content-type", LOGO_MIME[logo.type]);
|
|
4296
|
-
res.setHeader("etag", tag);
|
|
4297
|
-
res.setHeader("cache-control", "no-cache");
|
|
4298
|
-
res.setHeader("vary", "x-mv-nonce");
|
|
4299
|
-
res.setHeader("x-content-type-options", "nosniff");
|
|
4300
|
-
res.setHeader("content-security-policy", "default-src 'none'; style-src 'unsafe-inline'");
|
|
4301
|
-
const signed = proofHeaders(proof, req.headers["x-mv-nonce"], "logo");
|
|
4302
|
-
if (signed) for (const [k, v] of Object.entries(signed)) res.setHeader(k, v);
|
|
4303
|
-
if (matches(req.headers["if-none-match"], tag)) {
|
|
4304
|
-
res.statusCode = 304;
|
|
4305
|
-
return res.end();
|
|
4306
|
-
}
|
|
4307
|
-
res.setHeader("content-length", String(logo.bytes.length));
|
|
4308
|
-
res.end(req.method === "HEAD" ? void 0 : logo.bytes);
|
|
4309
|
-
};
|
|
4310
|
-
}
|
|
4311
4469
|
//#endregion
|
|
4312
4470
|
//#region src/server/guard.ts
|
|
4313
4471
|
/** A workspace key as marver writes it: 16 hex. A frame's own `ws` query in another shape is the
|
|
@@ -4392,6 +4550,337 @@ function elsewhere(res) {
|
|
|
4392
4550
|
res.end(JSON.stringify({ error: "another workspace" }));
|
|
4393
4551
|
}
|
|
4394
4552
|
//#endregion
|
|
4553
|
+
//#region src/server/app-live.ts
|
|
4554
|
+
/**
|
|
4555
|
+
* The live stream (spec 28 A4.1, A4.6 #4-#15): what waits on the owner in this canvas, for the Mac app's marks and
|
|
4556
|
+
* notices. `GET /__mv/app/live` is an event stream of whole snapshots (`LiveEvent` v1, src/shared/app-api.ts), proved
|
|
4557
|
+
* both ways - the request by `x-mv-app`, the answer by `liveProof` over the app's fresh nonce - so only the slot key's
|
|
4558
|
+
* holder is answered, and a listener that took the port after a canvas stopped can never put words into a notice.
|
|
4559
|
+
*
|
|
4560
|
+
* Four parts, each pure or nearly: the selector `liveSnapshot(input)` (#7-#11), the id hash (#9), the encoder with its
|
|
4561
|
+
* byte budget (#11, r1 #4), and the hub `createLiveHub` with its clients (#14), behind the route `liveRoute` (#5, #6).
|
|
4562
|
+
* The adapters that read the real sources - the comment logs, the marks, the Jam view, `marver work`'s leases - stay in
|
|
4563
|
+
* plugin.ts as the hub's `read()`. Erasable TypeScript, no Vite, only `node:crypto`, `./proof.ts` and the shared
|
|
4564
|
+
* contracts: the Mac app's fake canvas runs it under Node's type stripping over a scripted `read()`, so the app's cases
|
|
4565
|
+
* meet this code, not a copy (#4).
|
|
4566
|
+
*/
|
|
4567
|
+
/** An item's id (#9): its kind and the first 20 hex of a sha256 over the occurrence's persisted parts, NUL-joined. */
|
|
4568
|
+
const liveId = (kind, ...parts) => `${kind}:${createHash("sha256").update(parts.map(String).join("\0")).digest("hex").slice(0, 20)}`;
|
|
4569
|
+
/** One line of at most `max` UTF-16 units: whitespace collapsed, control characters gone, never cut inside a pair. A
|
|
4570
|
+
* log is data: a body that is not a string (a hand edit, a dev POST) reads as none, never stopping the stream. */
|
|
4571
|
+
function oneLine(s, max = LIVE_BOUNDS.title) {
|
|
4572
|
+
const t = (typeof s === "string" ? s : "").replace(/\s+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").trim();
|
|
4573
|
+
if (t.length <= max) return t;
|
|
4574
|
+
const cut = t.slice(0, max);
|
|
4575
|
+
return /[\ud800-\udbff]$/.test(cut) ? cut.slice(0, -1) : cut;
|
|
4576
|
+
}
|
|
4577
|
+
/** Every ref an item carries is at most `LIVE_BOUNDS.ref`: one past it can never be shown, so it is counted, never sent. */
|
|
4578
|
+
const refsFit = (i) => [
|
|
4579
|
+
i.board,
|
|
4580
|
+
i.frame,
|
|
4581
|
+
i.thread,
|
|
4582
|
+
i.msg,
|
|
4583
|
+
i.batch,
|
|
4584
|
+
...i.cards ?? []
|
|
4585
|
+
].every((r) => r === void 0 || r.length <= LIVE_BOUNDS.ref);
|
|
4586
|
+
const byMade = (a, b) => a.made - b.made || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
4587
|
+
const firstFrame = (c) => c.frames[0];
|
|
4588
|
+
/**
|
|
4589
|
+
* What waits on the owner now (#7, #8, #10, #12): one item per need, newest first, at most `LIVE_BOUNDS.items`, with
|
|
4590
|
+
* exact counts. Pure and deterministic - the same input gives the same bytes. `ask` from the threads alone (a Jam card
|
|
4591
|
+
* in `asks` is the same question, carried as its target); `review`, `failed` and `stalled` from Jam's view, each
|
|
4592
|
+
* failed or stalled run one item; unseen frames a count; `working` from `marver work`'s leases and the runs at work.
|
|
4593
|
+
*/
|
|
4594
|
+
function liveSnapshot(input) {
|
|
4595
|
+
const view = input.jam;
|
|
4596
|
+
const cards = view?.cards ?? [];
|
|
4597
|
+
const threadOf = /* @__PURE__ */ new Map();
|
|
4598
|
+
for (const { board, threads } of input.boards) for (const t of threads) threadOf.set(`${board}\0${t.id}`, t);
|
|
4599
|
+
const items = [];
|
|
4600
|
+
for (const { board, threads } of input.boards) for (const t of threads) {
|
|
4601
|
+
if (t.resolved || !(t.agent || t.replies.some((r) => r.agent))) continue;
|
|
4602
|
+
const last = t.replies.length ? t.replies[t.replies.length - 1] : t;
|
|
4603
|
+
if (!last.agent || !asks(last, last === t)) continue;
|
|
4604
|
+
const msg = last === t ? t.id : last.id;
|
|
4605
|
+
const card = cards.filter((c) => c.state === "asks" && c.board === board && c.thread === t.id).sort(byMade).map((c) => c.id);
|
|
4606
|
+
items.push({
|
|
4607
|
+
id: liveId("ask", board, t.id, msg),
|
|
4608
|
+
kind: "ask",
|
|
4609
|
+
board,
|
|
4610
|
+
title: oneLine(last.body),
|
|
4611
|
+
at: last.ts,
|
|
4612
|
+
...t.frame ? { frame: t.frame } : {},
|
|
4613
|
+
thread: t.id,
|
|
4614
|
+
msg,
|
|
4615
|
+
...card.length ? { cards: card.slice(0, LIVE_BOUNDS.cards) } : {}
|
|
4616
|
+
});
|
|
4617
|
+
}
|
|
4618
|
+
const titleOf = (c) => oneLine(c.kind === "comment" ? (c.thread ? threadOf.get(`${c.board}\0${c.thread}`)?.body : void 0) ?? c.title : c.title);
|
|
4619
|
+
const thread = (c) => c.kind === "comment" && c.thread ? { thread: c.thread } : {};
|
|
4620
|
+
for (const c of cards.filter((x) => x.state === "review").sort(byMade)) {
|
|
4621
|
+
const occ = c.att ?? 0;
|
|
4622
|
+
items.push({
|
|
4623
|
+
id: liveId("review", c.id, occ),
|
|
4624
|
+
kind: "review",
|
|
4625
|
+
board: c.board,
|
|
4626
|
+
title: titleOf(c),
|
|
4627
|
+
at: c.at,
|
|
4628
|
+
...firstFrame(c) ? { frame: firstFrame(c) } : {},
|
|
4629
|
+
...thread(c),
|
|
4630
|
+
cards: [c.id],
|
|
4631
|
+
...c.batch ? { batch: c.batch } : {},
|
|
4632
|
+
occ
|
|
4633
|
+
});
|
|
4634
|
+
}
|
|
4635
|
+
const failed = /* @__PURE__ */ new Map();
|
|
4636
|
+
for (const c of cards.filter((x) => x.state === "failed").sort(byMade)) {
|
|
4637
|
+
const k = c.batch ? `b\0${c.batch}` : `c\0${c.id}`;
|
|
4638
|
+
failed.set(k, [...failed.get(k) ?? [], c]);
|
|
4639
|
+
}
|
|
4640
|
+
for (const [k, group] of failed) {
|
|
4641
|
+
const c = group[0];
|
|
4642
|
+
const run = k.startsWith("b\0");
|
|
4643
|
+
const occ = run ? c.fails ?? 0 : c.att ?? 0;
|
|
4644
|
+
items.push({
|
|
4645
|
+
id: run ? liveId("failed", c.batch, occ) : liveId("failed", c.id, occ),
|
|
4646
|
+
kind: "failed",
|
|
4647
|
+
board: c.board,
|
|
4648
|
+
title: titleOf(c),
|
|
4649
|
+
...c.note ? { note: oneLine(c.note, LIVE_BOUNDS.note) } : {},
|
|
4650
|
+
at: Math.max(...group.map((x) => x.at)),
|
|
4651
|
+
...firstFrame(c) ? { frame: firstFrame(c) } : {},
|
|
4652
|
+
...thread(c),
|
|
4653
|
+
cards: group.map((x) => x.id).slice(0, LIVE_BOUNDS.cards),
|
|
4654
|
+
...run ? { batch: c.batch } : {},
|
|
4655
|
+
occ
|
|
4656
|
+
});
|
|
4657
|
+
}
|
|
4658
|
+
const stalled = /* @__PURE__ */ new Map();
|
|
4659
|
+
for (const c of cards.filter((x) => x.state === "working" && x.runner?.kind === "session" && x.runner.state === "stalled").sort(byMade)) {
|
|
4660
|
+
const k = c.runner.batch;
|
|
4661
|
+
stalled.set(k, [...stalled.get(k) ?? [], c]);
|
|
4662
|
+
}
|
|
4663
|
+
for (const [batch, group] of stalled) {
|
|
4664
|
+
const c = group[0];
|
|
4665
|
+
const gen = c.runner.gen ?? 0, occ = c.runner.stalls ?? 0;
|
|
4666
|
+
items.push({
|
|
4667
|
+
id: liveId("stalled", batch, gen, occ),
|
|
4668
|
+
kind: "stalled",
|
|
4669
|
+
board: c.board,
|
|
4670
|
+
title: titleOf(c),
|
|
4671
|
+
at: Math.max(...group.map((x) => x.at)),
|
|
4672
|
+
...firstFrame(c) ? { frame: firstFrame(c) } : {},
|
|
4673
|
+
...thread(c),
|
|
4674
|
+
cards: group.map((x) => x.id).slice(0, LIVE_BOUNDS.cards),
|
|
4675
|
+
batch,
|
|
4676
|
+
gen,
|
|
4677
|
+
occ
|
|
4678
|
+
});
|
|
4679
|
+
}
|
|
4680
|
+
const counts = {
|
|
4681
|
+
ask: 0,
|
|
4682
|
+
review: 0,
|
|
4683
|
+
failed: 0,
|
|
4684
|
+
stalled: 0
|
|
4685
|
+
};
|
|
4686
|
+
for (const i of items) counts[i.kind]++;
|
|
4687
|
+
const shown = items.filter(refsFit).sort((a, b) => b.at - a.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
4688
|
+
const working = input.cli.length > 0 || cards.some((c) => c.state === "working" && (!c.runner || !c.runner.state || c.runner.state === "claimed"));
|
|
4689
|
+
return {
|
|
4690
|
+
jam: view ? "on" : "off",
|
|
4691
|
+
items: shown.slice(0, LIVE_BOUNDS.items),
|
|
4692
|
+
cut: Math.max(0, shown.length - LIVE_BOUNDS.items),
|
|
4693
|
+
counts,
|
|
4694
|
+
unseen: input.fresh.length,
|
|
4695
|
+
working,
|
|
4696
|
+
session: !!view?.session
|
|
4697
|
+
};
|
|
4698
|
+
}
|
|
4699
|
+
const block = (e) => `event: ${LIVE_WIRE.event}\ndata: ${JSON.stringify(e)}\n\n`;
|
|
4700
|
+
/**
|
|
4701
|
+
* The event as written (#11, r1 #4): `event: live`, one `data:` line, a blank line - within `LIVE_BOUNDS.eventBytes`
|
|
4702
|
+
* in UTF-8. While it is over, the oldest whole items go (the end of `items`), counted in `cut`; `counts` stay exact.
|
|
4703
|
+
*/
|
|
4704
|
+
function encodeLive(e) {
|
|
4705
|
+
let text = block(e);
|
|
4706
|
+
if (Buffer.byteLength(text) <= LIVE_BOUNDS.eventBytes) return text;
|
|
4707
|
+
const sizes = e.items.map((i) => Buffer.byteLength(JSON.stringify(i)) + 1);
|
|
4708
|
+
let over = Buffer.byteLength(text) - LIVE_BOUNDS.eventBytes;
|
|
4709
|
+
let keep = e.items.length;
|
|
4710
|
+
while (keep > 0 && over > 0) over -= sizes[--keep];
|
|
4711
|
+
for (;;) {
|
|
4712
|
+
text = block({
|
|
4713
|
+
...e,
|
|
4714
|
+
items: e.items.slice(0, keep),
|
|
4715
|
+
cut: e.cut + e.items.length - keep
|
|
4716
|
+
});
|
|
4717
|
+
if (keep === 0 || Buffer.byteLength(text) <= LIVE_BOUNDS.eventBytes) return text;
|
|
4718
|
+
keep--;
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
/** `seq`: per server process, rising across Vite restarts - one counter for every hub this module makes (#11, #14). */
|
|
4722
|
+
const SEQ = { n: 0 };
|
|
4723
|
+
const hubs = /* @__PURE__ */ new Set();
|
|
4724
|
+
/** A source the stream reads changed - beside each place the server already tells pages (#13). Pokes every open hub. */
|
|
4725
|
+
function liveChanged() {
|
|
4726
|
+
for (const h of hubs) h.changed();
|
|
4727
|
+
}
|
|
4728
|
+
const LIVE_DEBOUNCE_MAX_MS = 1e3;
|
|
4729
|
+
/**
|
|
4730
|
+
* One hub per server (#14). It computes only while a client is connected, and writes only a snapshot that differs
|
|
4731
|
+
* from the last one written, `seq` one higher. A new client gets the snapshot at once - alone, when nothing changed.
|
|
4732
|
+
* A heartbeat `: hb` every 30 s recomputes too, so a missed hook costs 30 s at most. A fifth client ends the oldest; a
|
|
4733
|
+
* client with more than 64 KiB unsent is destroyed before the next write (it reconnects for a fresh snapshot). `on`
|
|
4734
|
+
* subscribes the hub to a source that tells it of changes itself (workActivity), unsubscribed at close.
|
|
4735
|
+
*/
|
|
4736
|
+
function createLiveHub(o) {
|
|
4737
|
+
const now = o.clock ?? Date.now;
|
|
4738
|
+
const seq = o.seq ?? SEQ;
|
|
4739
|
+
const clients = [];
|
|
4740
|
+
let last = null;
|
|
4741
|
+
let text = "";
|
|
4742
|
+
let timer;
|
|
4743
|
+
let first = 0;
|
|
4744
|
+
let beat;
|
|
4745
|
+
let closed = false;
|
|
4746
|
+
/** no client left: no timer runs */
|
|
4747
|
+
const idle = () => {
|
|
4748
|
+
if (!clients.length) {
|
|
4749
|
+
clearInterval(beat);
|
|
4750
|
+
beat = void 0;
|
|
4751
|
+
clearTimeout(timer);
|
|
4752
|
+
timer = void 0;
|
|
4753
|
+
}
|
|
4754
|
+
};
|
|
4755
|
+
const remove = (res) => {
|
|
4756
|
+
const i = clients.indexOf(res);
|
|
4757
|
+
if (i >= 0) clients.splice(i, 1);
|
|
4758
|
+
idle();
|
|
4759
|
+
};
|
|
4760
|
+
const write = (res, chunk) => {
|
|
4761
|
+
if (res.writableLength > LIVE_WIRE.slowBytes) {
|
|
4762
|
+
remove(res);
|
|
4763
|
+
res.destroy();
|
|
4764
|
+
return;
|
|
4765
|
+
}
|
|
4766
|
+
res.write(chunk);
|
|
4767
|
+
};
|
|
4768
|
+
/** Read the sources; a changed snapshot goes to every client. False when the read failed (nothing written). */
|
|
4769
|
+
const recompute = () => {
|
|
4770
|
+
let body;
|
|
4771
|
+
try {
|
|
4772
|
+
body = o.read();
|
|
4773
|
+
} catch {
|
|
4774
|
+
return false;
|
|
4775
|
+
}
|
|
4776
|
+
const key = JSON.stringify(body);
|
|
4777
|
+
if (key === last) return true;
|
|
4778
|
+
last = key;
|
|
4779
|
+
text = encodeLive({
|
|
4780
|
+
v: 1,
|
|
4781
|
+
instance: o.instance,
|
|
4782
|
+
seq: ++seq.n,
|
|
4783
|
+
...body
|
|
4784
|
+
});
|
|
4785
|
+
for (const c of [...clients]) write(c, text);
|
|
4786
|
+
return true;
|
|
4787
|
+
};
|
|
4788
|
+
const fire = () => {
|
|
4789
|
+
timer = void 0;
|
|
4790
|
+
if (clients.length && !closed) recompute();
|
|
4791
|
+
};
|
|
4792
|
+
const hub = {
|
|
4793
|
+
changed() {
|
|
4794
|
+
if (closed || !clients.length) return;
|
|
4795
|
+
const t = now();
|
|
4796
|
+
if (timer === void 0) first = t;
|
|
4797
|
+
clearTimeout(timer);
|
|
4798
|
+
timer = setTimeout(fire, Math.max(0, Math.min(150, first + LIVE_DEBOUNCE_MAX_MS - t)));
|
|
4799
|
+
},
|
|
4800
|
+
push() {
|
|
4801
|
+
clearTimeout(timer);
|
|
4802
|
+
timer = void 0;
|
|
4803
|
+
if (!closed) recompute();
|
|
4804
|
+
},
|
|
4805
|
+
add(res) {
|
|
4806
|
+
if (closed) {
|
|
4807
|
+
res.end();
|
|
4808
|
+
return;
|
|
4809
|
+
}
|
|
4810
|
+
while (clients.length >= LIVE_WIRE.clients) clients.shift().end();
|
|
4811
|
+
clients.push(res);
|
|
4812
|
+
res.on("close", () => remove(res));
|
|
4813
|
+
res.on("error", () => remove(res));
|
|
4814
|
+
const was = last;
|
|
4815
|
+
if (recompute() && last === was && text) write(res, text);
|
|
4816
|
+
beat ??= setInterval(() => {
|
|
4817
|
+
recompute();
|
|
4818
|
+
for (const c of [...clients]) write(c, `${LIVE_WIRE.heartbeat}\n\n`);
|
|
4819
|
+
}, LIVE_WIRE.heartbeatMs);
|
|
4820
|
+
beat.unref?.();
|
|
4821
|
+
},
|
|
4822
|
+
clients: () => clients.length,
|
|
4823
|
+
drop() {
|
|
4824
|
+
for (const c of clients.splice(0)) c.destroy();
|
|
4825
|
+
idle();
|
|
4826
|
+
},
|
|
4827
|
+
close() {
|
|
4828
|
+
if (closed) return;
|
|
4829
|
+
closed = true;
|
|
4830
|
+
hubs.delete(hub);
|
|
4831
|
+
off?.();
|
|
4832
|
+
for (const c of clients.splice(0)) try {
|
|
4833
|
+
c.end();
|
|
4834
|
+
} catch {}
|
|
4835
|
+
clearInterval(beat);
|
|
4836
|
+
beat = void 0;
|
|
4837
|
+
clearTimeout(timer);
|
|
4838
|
+
timer = void 0;
|
|
4839
|
+
}
|
|
4840
|
+
};
|
|
4841
|
+
const off = o.on?.(() => hub.changed());
|
|
4842
|
+
hubs.add(hub);
|
|
4843
|
+
return hub;
|
|
4844
|
+
}
|
|
4845
|
+
const refuse = (res, status, extra = {}) => {
|
|
4846
|
+
res.writeHead(status, {
|
|
4847
|
+
"content-type": "text/plain; charset=utf-8",
|
|
4848
|
+
"cache-control": "no-store",
|
|
4849
|
+
...extra
|
|
4850
|
+
});
|
|
4851
|
+
res.end(String(status));
|
|
4852
|
+
};
|
|
4853
|
+
/**
|
|
4854
|
+
* `GET /__mv/app/live` (#5, #6): mounted right after the workspace guard (an `x-mv-ws` naming another workspace is a
|
|
4855
|
+
* 409 before anything is read) and the perf barrier. Another method 405; an `x-mv-app` that is not `appProof(key,
|
|
4856
|
+
* port)` 403, and a missing or malformed `x-mv-nonce` 400 - before anything is read or computed. The 200 carries
|
|
4857
|
+
* `x-mv-instance` and `x-mv-proof` = `liveProof`. No hub or no proof (no slot: an in-process plugin, a test server):
|
|
4858
|
+
* 404. Proved, the stream admits nothing else: it never makes a document trusted.
|
|
4859
|
+
*/
|
|
4860
|
+
function liveRoute(hub, proof) {
|
|
4861
|
+
return (req, res, next) => {
|
|
4862
|
+
if ((req.url ?? "").split("?")[0] !== LIVE_WIRE.path) return next();
|
|
4863
|
+
if (!hub || !proof) return refuse(res, 404);
|
|
4864
|
+
if (req.method !== "GET") return refuse(res, 405, { allow: "GET" });
|
|
4865
|
+
if (!appProofOk(proof, req.headers["x-mv-app"])) return refuse(res, 403);
|
|
4866
|
+
const signed = proofHeaders(proof, req.headers["x-mv-nonce"], "live");
|
|
4867
|
+
if (!signed) return refuse(res, 400);
|
|
4868
|
+
res.writeHead(200, {
|
|
4869
|
+
"content-type": `${LIVE_WIRE.type}; charset=utf-8`,
|
|
4870
|
+
"cache-control": "no-store",
|
|
4871
|
+
"x-content-type-options": "nosniff",
|
|
4872
|
+
...signed
|
|
4873
|
+
});
|
|
4874
|
+
res.socket?.setNoDelay(true);
|
|
4875
|
+
res.flushHeaders?.();
|
|
4876
|
+
hub.add(res);
|
|
4877
|
+
};
|
|
4878
|
+
}
|
|
4879
|
+
//#endregion
|
|
4880
|
+
//#region src/server/jam/live.ts
|
|
4881
|
+
var live_exports = /* @__PURE__ */ __exportAll({ jamLive: () => jamLive });
|
|
4882
|
+
const jamLive = {};
|
|
4883
|
+
//#endregion
|
|
4395
4884
|
//#region src/server/plugin.ts
|
|
4396
4885
|
const VIRTUAL_THEME = "virtual:sh-theme";
|
|
4397
4886
|
const VIRTUAL_CONFIG = "virtual:sh-config";
|
|
@@ -4433,24 +4922,35 @@ function marverPlugin(ctx) {
|
|
|
4433
4922
|
return s ? loadedFiles(urls, s.config.root, s.environments?.client?.moduleGraph ?? null, s.config.base) : [];
|
|
4434
4923
|
}
|
|
4435
4924
|
};
|
|
4925
|
+
const live = liveSources(root);
|
|
4436
4926
|
const bootId = String(process.hrtime.bigint());
|
|
4437
4927
|
let invRev = 0;
|
|
4438
4928
|
const pendingInv = /* @__PURE__ */ new Set();
|
|
4929
|
+
const pendingChanges = /* @__PURE__ */ new Set();
|
|
4439
4930
|
const flushInv = debounce(() => {
|
|
4440
4931
|
if (!devServer || !pendingInv.size) return;
|
|
4441
4932
|
const frameIds = [...pendingInv];
|
|
4442
4933
|
pendingInv.clear();
|
|
4934
|
+
const carried = [...pendingChanges];
|
|
4935
|
+
pendingChanges.clear();
|
|
4936
|
+
const revision = `${bootId}:${++invRev}`;
|
|
4443
4937
|
const docs = docRevs(root, manifest.frames);
|
|
4444
4938
|
devServer.ws.send("sh:frame-invalidated", {
|
|
4445
4939
|
frameIds,
|
|
4446
|
-
revision
|
|
4940
|
+
revision,
|
|
4447
4941
|
epoch: docs?.epoch,
|
|
4448
4942
|
docs: docs ? Object.fromEntries(frameIds.map((id) => [id, docs.doc[id] ?? 0])) : void 0
|
|
4449
4943
|
});
|
|
4944
|
+
changes.invalidate(revision, frameIds.length, carried);
|
|
4450
4945
|
}, 120);
|
|
4451
4946
|
const inFlight = /* @__PURE__ */ new Map();
|
|
4452
4947
|
const late = /* @__PURE__ */ new Map();
|
|
4453
4948
|
const envs = () => Object.keys(devServer?.environments ?? { client: 1 }).length;
|
|
4949
|
+
const changes = createChanges({
|
|
4950
|
+
root,
|
|
4951
|
+
envs,
|
|
4952
|
+
write: (lines) => logReloadLines(root, lines)
|
|
4953
|
+
});
|
|
4454
4954
|
const waiting = [];
|
|
4455
4955
|
const settled = () => inFlight.size === 0;
|
|
4456
4956
|
const whenSettled = (fn) => {
|
|
@@ -4484,6 +4984,7 @@ function marverPlugin(ctx) {
|
|
|
4484
4984
|
for (const env of Object.values(devServer?.environments ?? {})) env.moduleGraph.invalidateAll();
|
|
4485
4985
|
late.set(file, (late.get(file) ?? 0) + f.events * envs() - f.hits);
|
|
4486
4986
|
inFlight.delete(file);
|
|
4987
|
+
changes.expire(file);
|
|
4487
4988
|
drain();
|
|
4488
4989
|
}, 1e4);
|
|
4489
4990
|
inFlight.set(file, f);
|
|
@@ -4507,22 +5008,27 @@ function marverPlugin(ctx) {
|
|
|
4507
5008
|
};
|
|
4508
5009
|
const observeMarks = () => observed(observe(root, manifest.frames));
|
|
4509
5010
|
const observeLater = () => whenSettled(() => {
|
|
4510
|
-
if (observeMarks())
|
|
5011
|
+
if (observeMarks()) {
|
|
5012
|
+
devServer?.ws.send("sh:marks", {});
|
|
5013
|
+
liveChanged();
|
|
5014
|
+
}
|
|
4511
5015
|
});
|
|
4512
5016
|
const hooks = {
|
|
4513
|
-
onFrames: (t, cause) => {
|
|
4514
|
-
|
|
5017
|
+
onFrames: (t, cause, at) => {
|
|
5018
|
+
const release = changes.hold(at);
|
|
5019
|
+
setTimeout(() => whenSettled(() => {
|
|
5020
|
+
try {
|
|
5021
|
+
record(t, cause, at);
|
|
5022
|
+
} finally {
|
|
5023
|
+
release();
|
|
5024
|
+
}
|
|
5025
|
+
}), 0);
|
|
4515
5026
|
},
|
|
4516
|
-
onReload(p, passed) {
|
|
4517
|
-
|
|
4518
|
-
kind: "full-reload",
|
|
4519
|
-
passed,
|
|
4520
|
-
triggeredBy: p.triggeredBy ?? null,
|
|
4521
|
-
path: p.path ?? null
|
|
4522
|
-
});
|
|
5027
|
+
onReload(p, passed, at) {
|
|
5028
|
+
changes.fullReload(p, passed, at);
|
|
4523
5029
|
}
|
|
4524
5030
|
};
|
|
4525
|
-
function record(t, cause) {
|
|
5031
|
+
function record(t, cause, at) {
|
|
4526
5032
|
const seen = observe(root, manifest.frames, t.file ? { file: t.file } : {});
|
|
4527
5033
|
const doc = t.unattributed ? [] : t.doc.filter((id) => !seen.doc.includes(id));
|
|
4528
5034
|
const touched = t.touched.filter((id) => !seen.doc.includes(id) && !seen.note.includes(id) && !doc.includes(id));
|
|
@@ -4530,15 +5036,13 @@ function marverPlugin(ctx) {
|
|
|
4530
5036
|
if (touched.length) recordChanged(root, manifest.frames, touched, { doc: false });
|
|
4531
5037
|
const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
|
|
4532
5038
|
for (const id of reload) pendingInv.add(id);
|
|
5039
|
+
if (reload.length && at.token) pendingChanges.add(at.token.change);
|
|
4533
5040
|
flushInv();
|
|
4534
|
-
if (reload.length || touched.length || seen.note.length)
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
reload,
|
|
4540
|
-
inPlace: t.touched
|
|
4541
|
-
});
|
|
5041
|
+
if (reload.length || touched.length || seen.note.length) {
|
|
5042
|
+
devServer?.ws.send("sh:marks", {});
|
|
5043
|
+
liveChanged();
|
|
5044
|
+
}
|
|
5045
|
+
changes.update(cause, t.file, reload, t.touched, at);
|
|
4542
5046
|
}
|
|
4543
5047
|
/** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
|
|
4544
5048
|
* Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
|
|
@@ -4552,488 +5056,556 @@ function marverPlugin(ctx) {
|
|
|
4552
5056
|
if (ctx.detectedThemeCss && existsSync(join(root, ctx.detectedThemeCss))) return join(root, ctx.detectedThemeCss);
|
|
4553
5057
|
return null;
|
|
4554
5058
|
};
|
|
4555
|
-
return [
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
if (
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
html
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
type: "module",
|
|
4623
|
-
src: bridge
|
|
5059
|
+
return [
|
|
5060
|
+
{
|
|
5061
|
+
name: "marver",
|
|
5062
|
+
watchChange(id, change) {
|
|
5063
|
+
if (devServer) {
|
|
5064
|
+
flying(id);
|
|
5065
|
+
changes.watch(id, change.event);
|
|
5066
|
+
}
|
|
5067
|
+
},
|
|
5068
|
+
enforce: "pre",
|
|
5069
|
+
resolveId(id) {
|
|
5070
|
+
if (id === VIRTUAL_THEME) return themeFile() ?? "\0virtual:sh-theme.css";
|
|
5071
|
+
if (id === VIRTUAL_CONFIG) return "\0virtual:sh-config";
|
|
5072
|
+
if (id === VIRTUAL_DATA) return "\0virtual:sh-data";
|
|
5073
|
+
},
|
|
5074
|
+
load(id) {
|
|
5075
|
+
if (id === "\0virtual:sh-theme.css") {
|
|
5076
|
+
if (themeMissing()) console.warn("[marver] no theme detected - frames render unstyled. Create design/theme.css importing your app's stylesheet (or set `theme` in design/config.ts).");
|
|
5077
|
+
return "/* marver: no theme configured */";
|
|
5078
|
+
}
|
|
5079
|
+
if (id === "\0virtual:sh-config") {
|
|
5080
|
+
const setupPending = (() => {
|
|
5081
|
+
try {
|
|
5082
|
+
const s = readFileSync(join(root, "design", "instructions", "setup.md"), "utf8");
|
|
5083
|
+
return s.startsWith("# Setup required") && s.includes("marver init");
|
|
5084
|
+
} catch {
|
|
5085
|
+
return false;
|
|
5086
|
+
}
|
|
5087
|
+
})();
|
|
5088
|
+
return `export default ${JSON.stringify({
|
|
5089
|
+
viewports: config.viewports,
|
|
5090
|
+
themes: config.themes,
|
|
5091
|
+
zoomSpeed: config.zoomSpeed,
|
|
5092
|
+
noTheme: themeFile() == null,
|
|
5093
|
+
setup: setupPending,
|
|
5094
|
+
projectName: config.share.name || basename(root),
|
|
5095
|
+
branding: config.share.branding,
|
|
5096
|
+
jam: config.jam ? {
|
|
5097
|
+
chime: config.jam.chime,
|
|
5098
|
+
capture: config.jam.capture,
|
|
5099
|
+
names: config.jam.names && config.jam.agent === "claude"
|
|
5100
|
+
} : null,
|
|
5101
|
+
workspace: ws,
|
|
5102
|
+
version: installedVersion() ?? "0.0.0"
|
|
5103
|
+
})}`;
|
|
5104
|
+
}
|
|
5105
|
+
if (id === "\0virtual:sh-data") return "export default null";
|
|
5106
|
+
},
|
|
5107
|
+
/** HTML frames: inject theme + bridge into any design/**.html Vite serves.
|
|
5108
|
+
* Inline scripts go through vite's html-proxy import-analysis: bare specifiers resolve
|
|
5109
|
+
* through plugins (so `virtual:sh-theme` works); `/@id/` URLs are rejected there. */
|
|
5110
|
+
transformIndexHtml: {
|
|
5111
|
+
order: "pre",
|
|
5112
|
+
handler(html, hctx) {
|
|
5113
|
+
const path = (hctx.originalUrl ?? hctx.path ?? "").split("?")[0];
|
|
5114
|
+
if (!path.startsWith("/design/")) return;
|
|
5115
|
+
const bridge = "/@fs/" + join(clientDir, "frame-host", "bridge.js").split("\\").join("/") + "?html=1";
|
|
5116
|
+
const frame = manifest.frames.find((f) => "/" + f.file === path);
|
|
5117
|
+
const stamp = frame ? docRev(root, manifest.frames, frame.id) : "";
|
|
5118
|
+
return {
|
|
5119
|
+
html,
|
|
5120
|
+
tags: [
|
|
5121
|
+
{
|
|
5122
|
+
tag: "script",
|
|
5123
|
+
attrs: { type: "module" },
|
|
5124
|
+
children: `import '${VIRTUAL_THEME}'`,
|
|
5125
|
+
injectTo: "head-prepend"
|
|
4624
5126
|
},
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
5127
|
+
{
|
|
5128
|
+
tag: "script",
|
|
5129
|
+
attrs: {
|
|
5130
|
+
type: "module",
|
|
5131
|
+
src: bridge
|
|
5132
|
+
},
|
|
5133
|
+
injectTo: "head-prepend"
|
|
4632
5134
|
},
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
5135
|
+
...stamp ? [{
|
|
5136
|
+
tag: "meta",
|
|
5137
|
+
attrs: {
|
|
5138
|
+
name: "mv-doc",
|
|
5139
|
+
content: stamp
|
|
5140
|
+
},
|
|
5141
|
+
injectTo: "head-prepend"
|
|
5142
|
+
}] : []
|
|
5143
|
+
]
|
|
5144
|
+
};
|
|
5145
|
+
}
|
|
5146
|
+
},
|
|
5147
|
+
configureServer(server) {
|
|
5148
|
+
const closers = [];
|
|
5149
|
+
const onClose = (fn) => {
|
|
5150
|
+
closers.push(fn);
|
|
4636
5151
|
};
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
withdraw?.();
|
|
4652
|
-
closeAll();
|
|
4653
|
-
});
|
|
4654
|
-
if (served++) {
|
|
4655
|
-
manifest = scanFrames(root, projectInfo());
|
|
4656
|
-
observeLater();
|
|
4657
|
-
runs.restarted();
|
|
4658
|
-
}
|
|
4659
|
-
server.middlewares.use(guardMiddleware(ws));
|
|
4660
|
-
server.middlewares.use(perfRunBarrier());
|
|
4661
|
-
const viteWatcher = server.watcher;
|
|
4662
|
-
watching.server = server;
|
|
4663
|
-
watching.watcher = viteWatcher;
|
|
4664
|
-
watching.ready = viteWatcher._readyEmitted === true;
|
|
4665
|
-
viteWatcher.once("ready", () => {
|
|
4666
|
-
if (watching.watcher !== viteWatcher) return;
|
|
4667
|
-
watching.ready = true;
|
|
4668
|
-
for (const w of watching.waiters) w();
|
|
4669
|
-
watching.waiters.clear();
|
|
4670
|
-
});
|
|
4671
|
-
viteWatcher.on("all", (_event, file) => runs.changed(file));
|
|
4672
|
-
let bakeGen = Date.now();
|
|
4673
|
-
server.middlewares.use((req, res, next) => {
|
|
4674
|
-
if (req.url && req.url.includes("/frame-host/registry.ts")) {
|
|
4675
|
-
const orig = res.setHeader.bind(res);
|
|
4676
|
-
res.setHeader = ((name, value) => orig(name, String(name).toLowerCase() === "cache-control" ? "no-cache" : value));
|
|
5152
|
+
const closeAll = () => {
|
|
5153
|
+
for (const fn of closers.splice(0).reverse()) try {
|
|
5154
|
+
fn();
|
|
5155
|
+
} catch {}
|
|
5156
|
+
};
|
|
5157
|
+
const withdraw = ctx.startup?.defer(closeAll, server);
|
|
5158
|
+
server.httpServer?.once("close", () => {
|
|
5159
|
+
withdraw?.();
|
|
5160
|
+
closeAll();
|
|
5161
|
+
});
|
|
5162
|
+
if (served++) {
|
|
5163
|
+
manifest = scanFrames(root, projectInfo());
|
|
5164
|
+
observeLater();
|
|
5165
|
+
runs.restarted();
|
|
4677
5166
|
}
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
if (
|
|
5167
|
+
server.middlewares.use(guardMiddleware(ws));
|
|
5168
|
+
server.middlewares.use(perfRunBarrier());
|
|
5169
|
+
const hub = ctx.proof ? createLiveHub({
|
|
5170
|
+
instance: ctx.proof.instance,
|
|
5171
|
+
read: () => liveSnapshot(live.read(manifest.frames)),
|
|
5172
|
+
on: (fn) => workActivity.onChange(fn)
|
|
5173
|
+
}) : null;
|
|
5174
|
+
if (hub) onClose(() => hub.close());
|
|
5175
|
+
server.middlewares.use(liveRoute(hub, ctx.proof));
|
|
5176
|
+
const viteWatcher = server.watcher;
|
|
5177
|
+
watching.server = server;
|
|
5178
|
+
watching.watcher = viteWatcher;
|
|
5179
|
+
watching.ready = viteWatcher._readyEmitted === true;
|
|
5180
|
+
viteWatcher.once("ready", () => {
|
|
5181
|
+
if (watching.watcher !== viteWatcher) return;
|
|
5182
|
+
watching.ready = true;
|
|
5183
|
+
for (const w of watching.waiters) w();
|
|
5184
|
+
watching.waiters.clear();
|
|
5185
|
+
});
|
|
5186
|
+
viteWatcher.on("all", (_event, file) => runs.changed(file));
|
|
5187
|
+
let bakeGen = Date.now();
|
|
5188
|
+
server.middlewares.use((req, res, next) => {
|
|
5189
|
+
if (req.url && req.url.includes("/frame-host/registry.ts")) {
|
|
5190
|
+
const orig = res.setHeader.bind(res);
|
|
5191
|
+
res.setHeader = ((name, value) => orig(name, String(name).toLowerCase() === "cache-control" ? "no-cache" : value));
|
|
5192
|
+
}
|
|
5193
|
+
next();
|
|
5194
|
+
});
|
|
5195
|
+
const update = checkUpdate(root).catch(() => null);
|
|
4686
5196
|
update.then((latest) => {
|
|
4687
|
-
|
|
4688
|
-
res.setHeader("cache-control", "no-store");
|
|
4689
|
-
res.end(JSON.stringify({
|
|
4690
|
-
latest,
|
|
4691
|
-
current: installedVersion()
|
|
4692
|
-
}));
|
|
5197
|
+
if (latest) console.log(`\n update: ${PKG} ${latest} is out (installed ${installedVersion() ?? "?"}) → npm i -D ${PKG}@latest && npx ${NAME} init\n`);
|
|
4693
5198
|
});
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
onClose(regen.cancel);
|
|
4741
|
-
const watched = [join(root, "design", "scenes"), join(root, "design", "components")];
|
|
4742
|
-
const inScope = (file) => watched.some((w) => file.startsWith(w));
|
|
4743
|
-
const themeModules = () => {
|
|
4744
|
-
const f = themeFile();
|
|
4745
|
-
if (!f) return [];
|
|
4746
|
-
const out = [];
|
|
4747
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4748
|
-
const walk = (mod) => {
|
|
4749
|
-
if (!mod || seen.has(mod)) return;
|
|
4750
|
-
seen.add(mod);
|
|
4751
|
-
out.push(mod);
|
|
4752
|
-
for (const im of mod.clientImportedModules ?? mod.importedModules ?? []) if (String(im.id ?? "").split("?")[0].endsWith(".css")) walk(im);
|
|
5199
|
+
server.middlewares.use((req, res, next) => {
|
|
5200
|
+
if (new URL(req.url ?? "/", "http://x").pathname !== `/__mv/api/update`) return next();
|
|
5201
|
+
update.then((latest) => {
|
|
5202
|
+
res.setHeader("content-type", "application/json");
|
|
5203
|
+
res.setHeader("cache-control", "no-store");
|
|
5204
|
+
res.end(JSON.stringify({
|
|
5205
|
+
latest,
|
|
5206
|
+
current: installedVersion()
|
|
5207
|
+
}));
|
|
5208
|
+
});
|
|
5209
|
+
});
|
|
5210
|
+
const listeningOrigin = () => originOf(server.httpServer?.address());
|
|
5211
|
+
initMarks(root, manifest.frames);
|
|
5212
|
+
tidyPerfDir(root);
|
|
5213
|
+
server.middlewares.use(apiMiddleware(root, {
|
|
5214
|
+
viewports: config.viewports,
|
|
5215
|
+
origin: listeningOrigin,
|
|
5216
|
+
bakeGen: () => bakeGen,
|
|
5217
|
+
notify: (event) => {
|
|
5218
|
+
server.ws.send(event, {});
|
|
5219
|
+
liveChanged();
|
|
5220
|
+
},
|
|
5221
|
+
manifest: () => manifest,
|
|
5222
|
+
settled,
|
|
5223
|
+
workspace: ws,
|
|
5224
|
+
inputs
|
|
5225
|
+
}));
|
|
5226
|
+
server.middlewares.use(logoRoute(root, () => config.share.logo, ctx.proof));
|
|
5227
|
+
server.middlewares.use(routesMiddleware(server, clientDir, {
|
|
5228
|
+
doc: (id) => docRev(root, manifest.frames, id),
|
|
5229
|
+
docs: () => docRevs(root, manifest.frames)
|
|
5230
|
+
}, ctx.proof));
|
|
5231
|
+
const before = devServer;
|
|
5232
|
+
devServer = server;
|
|
5233
|
+
onClose(() => {
|
|
5234
|
+
if (devServer === server) devServer = before;
|
|
5235
|
+
});
|
|
5236
|
+
guardUpdates(server, root, () => manifest, hooks, changes);
|
|
5237
|
+
let framesKey = JSON.stringify(manifest.frames);
|
|
5238
|
+
let scenesKey = JSON.stringify(manifest.scenes);
|
|
5239
|
+
let unplacedKey = "";
|
|
5240
|
+
const sayUnplaced = () => {
|
|
5241
|
+
const { unplaced } = readMembership(root, manifest.frames.map((f) => f.id));
|
|
5242
|
+
const key = unplaced.join(",");
|
|
5243
|
+
if (key && key !== unplacedKey) console.log(`[${NAME}] not on a board (${unplaced.length}): ${unplaced.join(", ")} - every frame goes on the board it belongs to: npx ${NAME} boards pin <board> <scene/frame ...>`);
|
|
5244
|
+
unplacedKey = key;
|
|
4753
5245
|
};
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
if (f.startsWith(localDir) || f.startsWith(boardsDirGen) || f === manifestPath || f.includes("/node_modules/")) return;
|
|
4768
|
-
bakeGen++;
|
|
4769
|
-
prune();
|
|
4770
|
-
};
|
|
4771
|
-
const pruning = /* @__PURE__ */ new Set();
|
|
4772
|
-
const prune = () => {
|
|
4773
|
-
const t = setTimeout(async () => {
|
|
4774
|
-
pruning.delete(t);
|
|
4775
|
-
try {
|
|
4776
|
-
(await Promise.resolve().then(() => bake_exports)).pruneBakes(root, bakeGen);
|
|
4777
|
-
} catch {}
|
|
4778
|
-
}, 500);
|
|
4779
|
-
pruning.add(t);
|
|
4780
|
-
};
|
|
4781
|
-
onClose(() => {
|
|
4782
|
-
for (const t of pruning) clearTimeout(t);
|
|
4783
|
-
});
|
|
4784
|
-
prune();
|
|
4785
|
-
server.watcher.on("add", bumpGen);
|
|
4786
|
-
server.watcher.on("unlink", bumpGen);
|
|
4787
|
-
server.watcher.on("change", bumpGen);
|
|
4788
|
-
server.watcher.on("add", (f) => {
|
|
4789
|
-
if (inScope(f)) {
|
|
4790
|
-
regen();
|
|
4791
|
-
rescanTheme();
|
|
4792
|
-
}
|
|
4793
|
-
});
|
|
4794
|
-
server.watcher.on("unlink", (f) => {
|
|
4795
|
-
if (inScope(f)) {
|
|
4796
|
-
regen();
|
|
4797
|
-
rescanTheme();
|
|
4798
|
-
}
|
|
4799
|
-
});
|
|
4800
|
-
const contextDir = join(root, "context") + sep;
|
|
4801
|
-
let statusTimer;
|
|
4802
|
-
onClose(() => clearTimeout(statusTimer));
|
|
4803
|
-
const restatus = (f) => {
|
|
4804
|
-
if (!f.startsWith(contextDir) && !(inScope(f) && f.endsWith("_brief.md"))) return;
|
|
4805
|
-
clearTimeout(statusTimer);
|
|
4806
|
-
statusTimer = setTimeout(() => {
|
|
4807
|
-
server.ws.send("sh:boards", {});
|
|
4808
|
-
regen();
|
|
5246
|
+
sayUnplaced();
|
|
5247
|
+
const regen = debounce(() => {
|
|
5248
|
+
manifest = scanFrames(root, projectInfo());
|
|
5249
|
+
sayUnplaced();
|
|
5250
|
+
const changed = writeManifest(root, manifest);
|
|
5251
|
+
observeLater();
|
|
5252
|
+
const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
|
|
5253
|
+
if (changed && key !== framesKey) {
|
|
5254
|
+
server.ws.send("sh:manifest", manifest);
|
|
5255
|
+
liveChanged();
|
|
5256
|
+
} else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
|
|
5257
|
+
framesKey = key;
|
|
5258
|
+
scenesKey = sKey;
|
|
4809
5259
|
}, 150);
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
});
|
|
4824
|
-
const configFile = join(root, "design", "config.ts");
|
|
4825
|
-
server.watcher.on("change", (f) => {
|
|
4826
|
-
if (f !== configFile) return;
|
|
4827
|
-
loadConfig(root).then((c) => {
|
|
4828
|
-
project = {
|
|
4829
|
-
name: c.share.name || basename(root),
|
|
4830
|
-
description: c.description
|
|
5260
|
+
onClose(regen.cancel);
|
|
5261
|
+
const watched = [join(root, "design", "scenes"), join(root, "design", "components")];
|
|
5262
|
+
const inScope = (file) => watched.some((w) => file.startsWith(w));
|
|
5263
|
+
const themeModules = () => {
|
|
5264
|
+
const f = themeFile();
|
|
5265
|
+
if (!f) return [];
|
|
5266
|
+
const out = [];
|
|
5267
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5268
|
+
const walk = (mod) => {
|
|
5269
|
+
if (!mod || seen.has(mod)) return;
|
|
5270
|
+
seen.add(mod);
|
|
5271
|
+
out.push(mod);
|
|
5272
|
+
for (const im of mod.clientImportedModules ?? mod.importedModules ?? []) if (String(im.id ?? "").split("?")[0].endsWith(".css")) walk(im);
|
|
4831
5273
|
};
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
});
|
|
4835
|
-
writeManifest(root, manifest);
|
|
4836
|
-
const boardsDir = join(root, "design", "boards");
|
|
4837
|
-
try {
|
|
4838
|
-
mkdirSync(boardsDir, { recursive: true });
|
|
4839
|
-
const timers = /* @__PURE__ */ new Map();
|
|
4840
|
-
const badBoards = /* @__PURE__ */ new Map();
|
|
4841
|
-
const reportBad = (file, content, error) => {
|
|
4842
|
-
if (badBoards.get(file) === hash(content)) return;
|
|
4843
|
-
badBoards.set(file, hash(content));
|
|
4844
|
-
console.warn(`[marver] design/boards/${file} is not valid JSON - ${error}`);
|
|
5274
|
+
for (const mod of server.moduleGraph.getModulesByFile(f) ?? []) walk(mod);
|
|
5275
|
+
return out;
|
|
4845
5276
|
};
|
|
4846
|
-
|
|
4847
|
-
for (const
|
|
4848
|
-
}
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
5277
|
+
const pushTheme = debounce(() => {
|
|
5278
|
+
for (const mod of themeModules()) server.reloadModule(mod).catch(() => {});
|
|
5279
|
+
}, 150);
|
|
5280
|
+
onClose(pushTheme.cancel);
|
|
5281
|
+
const rescanTheme = () => {
|
|
5282
|
+
for (const mod of themeModules()) server.moduleGraph.invalidateModule(mod);
|
|
5283
|
+
pushTheme();
|
|
5284
|
+
};
|
|
5285
|
+
const localDir = join(root, "design", ".local"), boardsDirGen = join(root, "design", "boards"), manifestPath = join(root, "design", "manifest.json");
|
|
5286
|
+
const bumpGen = (f) => {
|
|
5287
|
+
if (f.startsWith(localDir) || f.startsWith(boardsDirGen) || f === manifestPath || f.includes("/node_modules/")) return;
|
|
5288
|
+
bakeGen++;
|
|
5289
|
+
prune();
|
|
5290
|
+
};
|
|
5291
|
+
const pruning = /* @__PURE__ */ new Set();
|
|
5292
|
+
const prune = () => {
|
|
5293
|
+
const t = setTimeout(async () => {
|
|
5294
|
+
pruning.delete(t);
|
|
5295
|
+
try {
|
|
5296
|
+
(await Promise.resolve().then(() => bake_exports)).pruneBakes(root, bakeGen);
|
|
5297
|
+
} catch {}
|
|
5298
|
+
}, 500);
|
|
5299
|
+
pruning.add(t);
|
|
5300
|
+
};
|
|
5301
|
+
onClose(() => {
|
|
5302
|
+
for (const t of pruning) clearTimeout(t);
|
|
5303
|
+
});
|
|
5304
|
+
prune();
|
|
5305
|
+
server.watcher.on("add", bumpGen);
|
|
5306
|
+
server.watcher.on("unlink", bumpGen);
|
|
5307
|
+
server.watcher.on("change", bumpGen);
|
|
5308
|
+
server.watcher.on("add", (f) => {
|
|
5309
|
+
if (inScope(f)) {
|
|
5310
|
+
regen();
|
|
5311
|
+
rescanTheme();
|
|
5312
|
+
}
|
|
5313
|
+
});
|
|
5314
|
+
server.watcher.on("unlink", (f) => {
|
|
5315
|
+
if (inScope(f)) {
|
|
5316
|
+
regen();
|
|
5317
|
+
rescanTheme();
|
|
5318
|
+
}
|
|
5319
|
+
});
|
|
5320
|
+
const contextDir = join(root, "context") + sep;
|
|
5321
|
+
let statusTimer;
|
|
5322
|
+
onClose(() => clearTimeout(statusTimer));
|
|
5323
|
+
const restatus = (f) => {
|
|
5324
|
+
if (!f.startsWith(contextDir) && !(inScope(f) && f.endsWith("_brief.md"))) return;
|
|
5325
|
+
clearTimeout(statusTimer);
|
|
5326
|
+
statusTimer = setTimeout(() => {
|
|
4856
5327
|
server.ws.send("sh:boards", {});
|
|
4857
5328
|
regen();
|
|
4858
|
-
boardsChanged(root);
|
|
4859
5329
|
}, 150);
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
return;
|
|
4874
|
-
}
|
|
4875
|
-
badBoards.delete(file);
|
|
4876
|
-
server.ws.send("sh:board", {
|
|
4877
|
-
name: file.replace(/\.json$/, ""),
|
|
4878
|
-
sha256: hash(content)
|
|
4879
|
-
});
|
|
4880
|
-
}, 120));
|
|
4881
|
-
}));
|
|
4882
|
-
onClose(() => {
|
|
4883
|
-
watcher.close();
|
|
4884
|
-
clearTimeout(listTimer);
|
|
4885
|
-
for (const t of timers.values()) clearTimeout(t);
|
|
5330
|
+
};
|
|
5331
|
+
server.watcher.on("add", restatus);
|
|
5332
|
+
server.watcher.on("unlink", restatus);
|
|
5333
|
+
server.watcher.on("change", restatus);
|
|
5334
|
+
server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
|
|
5335
|
+
const marksChanged = debounce(observeLater, 300);
|
|
5336
|
+
onClose(marksChanged.cancel);
|
|
5337
|
+
for (const ev of [
|
|
5338
|
+
"add",
|
|
5339
|
+
"change",
|
|
5340
|
+
"unlink"
|
|
5341
|
+
]) server.watcher.on(ev, (f) => {
|
|
5342
|
+
if (!f.startsWith(localDir) && !f.startsWith(boardsDirGen)) marksChanged();
|
|
4886
5343
|
});
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
}
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
};
|
|
4920
|
-
|
|
5344
|
+
const configFile = join(root, "design", "config.ts");
|
|
5345
|
+
server.watcher.on("change", (f) => {
|
|
5346
|
+
if (f !== configFile) return;
|
|
5347
|
+
loadConfig(root).then((c) => {
|
|
5348
|
+
project = {
|
|
5349
|
+
name: c.share.name || basename(root),
|
|
5350
|
+
description: c.description
|
|
5351
|
+
};
|
|
5352
|
+
regen();
|
|
5353
|
+
}).catch(() => {});
|
|
5354
|
+
});
|
|
5355
|
+
writeManifest(root, manifest);
|
|
5356
|
+
const boardsDir = join(root, "design", "boards");
|
|
5357
|
+
try {
|
|
5358
|
+
mkdirSync(boardsDir, { recursive: true });
|
|
5359
|
+
const timers = /* @__PURE__ */ new Map();
|
|
5360
|
+
const badBoards = /* @__PURE__ */ new Map();
|
|
5361
|
+
const reportBad = (file, content, error) => {
|
|
5362
|
+
if (badBoards.get(file) === hash(content)) return;
|
|
5363
|
+
badBoards.set(file, hash(content));
|
|
5364
|
+
console.warn(`[marver] design/boards/${file} is not valid JSON - ${error}`);
|
|
5365
|
+
};
|
|
5366
|
+
if (!checkBoardsDir(root, boardsDir)) {
|
|
5367
|
+
for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
|
|
5368
|
+
}
|
|
5369
|
+
if (nodeExists(join(boardsDir, `all-scenes.json`))) console.log(`[${NAME}] design/boards/${ALL_SCENES}.json is left over from the All Scenes board, gone since 0.25 - nothing reads it any more; delete it when you like (its threads stay in design/comments/)`);
|
|
5370
|
+
let listTimer;
|
|
5371
|
+
const watcher = guarded(watch(boardsDir, (_event, file) => {
|
|
5372
|
+
if (file?.endsWith(".json")) runs.changed(join(boardsDir, file));
|
|
5373
|
+
if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
|
|
5374
|
+
clearTimeout(listTimer);
|
|
5375
|
+
listTimer = setTimeout(() => {
|
|
5376
|
+
server.ws.send("sh:boards", {});
|
|
5377
|
+
regen();
|
|
5378
|
+
boardsChanged(root);
|
|
5379
|
+
}, 150);
|
|
5380
|
+
clearTimeout(timers.get(file));
|
|
5381
|
+
timers.set(file, setTimeout(() => {
|
|
5382
|
+
timers.delete(file);
|
|
5383
|
+
let content;
|
|
5384
|
+
if (!isRegularFile(join(boardsDir, file))) return;
|
|
4921
5385
|
try {
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
} catch (err) {
|
|
4925
|
-
write({
|
|
4926
|
-
ok: false,
|
|
4927
|
-
error: `malformed request - ${err.message}`
|
|
4928
|
-
});
|
|
4929
|
-
return;
|
|
4930
|
-
}
|
|
4931
|
-
const theme = spec.theme === void 0 ? "light" : spec.theme;
|
|
4932
|
-
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) {
|
|
4933
|
-
write({
|
|
4934
|
-
ok: false,
|
|
4935
|
-
error: "invalid theme"
|
|
4936
|
-
});
|
|
4937
|
-
return;
|
|
4938
|
-
}
|
|
4939
|
-
const scale = spec.scale === void 0 ? void 0 : spec.scale;
|
|
4940
|
-
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) {
|
|
4941
|
-
write({
|
|
4942
|
-
ok: false,
|
|
4943
|
-
error: "invalid scale"
|
|
4944
|
-
});
|
|
5386
|
+
content = readFileSync(join(boardsDir, file), "utf8");
|
|
5387
|
+
} catch {
|
|
4945
5388
|
return;
|
|
4946
5389
|
}
|
|
4947
|
-
const
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
"scene",
|
|
4951
|
-
"all"
|
|
4952
|
-
].filter((k) => spec[k] !== void 0);
|
|
4953
|
-
if (ways.length !== 1) {
|
|
4954
|
-
write({
|
|
4955
|
-
ok: false,
|
|
4956
|
-
error: "name the frames one way: frame (an id), frames (an array of ids), scene (a name) or all (true)"
|
|
4957
|
-
});
|
|
5390
|
+
const { error } = parseBoard(content);
|
|
5391
|
+
if (error) {
|
|
5392
|
+
if (!checkBoardsDir(root, boardsDir)) reportBad(file, content, error);
|
|
4958
5393
|
return;
|
|
4959
5394
|
}
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
5395
|
+
badBoards.delete(file);
|
|
5396
|
+
const name = file.replace(/\.json$/, ""), sha256 = hash(content);
|
|
5397
|
+
server.ws.send("sh:board", {
|
|
5398
|
+
name,
|
|
5399
|
+
sha256,
|
|
5400
|
+
...writerOf(root, name, sha256)
|
|
5401
|
+
});
|
|
5402
|
+
}, 120));
|
|
5403
|
+
}));
|
|
5404
|
+
onClose(() => {
|
|
5405
|
+
watcher.close();
|
|
5406
|
+
clearTimeout(listTimer);
|
|
5407
|
+
for (const t of timers.values()) clearTimeout(t);
|
|
5408
|
+
});
|
|
5409
|
+
} catch {}
|
|
5410
|
+
try {
|
|
5411
|
+
const inbox = join(root, "design", ".local", "shots");
|
|
5412
|
+
mkdirSync(inbox, { recursive: true });
|
|
5413
|
+
const origin = listeningOrigin;
|
|
5414
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
5415
|
+
const processRequest = (file) => {
|
|
5416
|
+
if (!file.endsWith(".request.json") || inFlight.has(file)) return;
|
|
5417
|
+
const reqPath = join(inbox, file);
|
|
5418
|
+
if (!existsSync(reqPath)) return;
|
|
5419
|
+
inFlight.add(file);
|
|
5420
|
+
setTimeout(async () => {
|
|
5421
|
+
const base = file.replace(/\.request\.json$/, "");
|
|
5422
|
+
const resultPath = join(inbox, `${base}.result.json`);
|
|
5423
|
+
const claimed = join(inbox, `.${base}.${process.pid}.${Date.now().toString(36)}.claimed`);
|
|
5424
|
+
try {
|
|
5425
|
+
renameSync(reqPath, claimed);
|
|
5426
|
+
} catch {
|
|
5427
|
+
inFlight.delete(file);
|
|
4966
5428
|
return;
|
|
4967
5429
|
}
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
5430
|
+
try {
|
|
5431
|
+
const write = (r) => {
|
|
5432
|
+
const tmp = join(inbox, `.${base}.${process.pid}.tmp`);
|
|
5433
|
+
try {
|
|
5434
|
+
writeFileSync(tmp, JSON.stringify(r, null, 2));
|
|
5435
|
+
renameSync(tmp, resultPath);
|
|
5436
|
+
} catch {
|
|
5437
|
+
try {
|
|
5438
|
+
rmSync(tmp, { force: true });
|
|
5439
|
+
} catch {}
|
|
5440
|
+
}
|
|
5441
|
+
};
|
|
5442
|
+
let spec;
|
|
5443
|
+
try {
|
|
5444
|
+
spec = JSON.parse(readFileSync(claimed, "utf8"));
|
|
5445
|
+
if (!spec || typeof spec !== "object" || Array.isArray(spec)) throw new Error("expected an object");
|
|
5446
|
+
} catch (err) {
|
|
4971
5447
|
write({
|
|
4972
5448
|
ok: false,
|
|
4973
|
-
error:
|
|
5449
|
+
error: `malformed request - ${err.message}`
|
|
4974
5450
|
});
|
|
4975
5451
|
return;
|
|
4976
5452
|
}
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
}
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
}
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
5453
|
+
const theme = spec.theme === void 0 ? "light" : spec.theme;
|
|
5454
|
+
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) {
|
|
5455
|
+
write({
|
|
5456
|
+
ok: false,
|
|
5457
|
+
error: "invalid theme"
|
|
5458
|
+
});
|
|
5459
|
+
return;
|
|
5460
|
+
}
|
|
5461
|
+
const scale = spec.scale === void 0 ? void 0 : spec.scale;
|
|
5462
|
+
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) {
|
|
5463
|
+
write({
|
|
5464
|
+
ok: false,
|
|
5465
|
+
error: "invalid scale"
|
|
5466
|
+
});
|
|
5467
|
+
return;
|
|
5468
|
+
}
|
|
5469
|
+
const ways = [
|
|
5470
|
+
"frame",
|
|
5471
|
+
"frames",
|
|
5472
|
+
"scene",
|
|
5473
|
+
"all"
|
|
5474
|
+
].filter((k) => spec[k] !== void 0);
|
|
5475
|
+
if (ways.length !== 1) {
|
|
5476
|
+
write({
|
|
5477
|
+
ok: false,
|
|
5478
|
+
error: "name the frames one way: frame (an id), frames (an array of ids), scene (a name) or all (true)"
|
|
5479
|
+
});
|
|
5480
|
+
return;
|
|
5481
|
+
}
|
|
5482
|
+
const o = origin();
|
|
5483
|
+
if (!o) {
|
|
5484
|
+
write({
|
|
5485
|
+
ok: false,
|
|
5486
|
+
error: "dev server has no address yet - retry"
|
|
5487
|
+
});
|
|
5488
|
+
return;
|
|
5489
|
+
}
|
|
5490
|
+
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-CRRGgxru.mjs").then((n) => n.u);
|
|
5491
|
+
if (ways[0] === "frame") {
|
|
5492
|
+
if (typeof spec.frame !== "string") {
|
|
5493
|
+
write({
|
|
5494
|
+
ok: false,
|
|
5495
|
+
error: "frame must be a frame id"
|
|
5496
|
+
});
|
|
5497
|
+
return;
|
|
5498
|
+
}
|
|
5499
|
+
write(await shootFrame({
|
|
4999
5500
|
root,
|
|
5000
5501
|
viewports: config.viewports,
|
|
5001
|
-
|
|
5502
|
+
frameId: spec.frame,
|
|
5002
5503
|
theme,
|
|
5003
5504
|
origin: o,
|
|
5004
5505
|
scale
|
|
5005
|
-
})
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5506
|
+
}));
|
|
5507
|
+
return;
|
|
5508
|
+
}
|
|
5509
|
+
const sel = resolveFrames(root, spec);
|
|
5510
|
+
if (!sel.ok) {
|
|
5511
|
+
write({
|
|
5512
|
+
ok: false,
|
|
5513
|
+
error: sel.error
|
|
5514
|
+
});
|
|
5515
|
+
return;
|
|
5516
|
+
}
|
|
5517
|
+
try {
|
|
5518
|
+
write({
|
|
5519
|
+
ok: true,
|
|
5520
|
+
results: await shootBatch({
|
|
5521
|
+
root,
|
|
5522
|
+
viewports: config.viewports,
|
|
5523
|
+
frames: sel.frames,
|
|
5524
|
+
theme,
|
|
5525
|
+
origin: o,
|
|
5526
|
+
scale
|
|
5527
|
+
})
|
|
5528
|
+
});
|
|
5529
|
+
} catch (err) {
|
|
5530
|
+
write({
|
|
5531
|
+
ok: false,
|
|
5532
|
+
error: err.message
|
|
5533
|
+
});
|
|
5534
|
+
}
|
|
5535
|
+
} finally {
|
|
5536
|
+
try {
|
|
5537
|
+
rmSync(claimed, { force: true });
|
|
5538
|
+
} catch {}
|
|
5539
|
+
inFlight.delete(file);
|
|
5012
5540
|
}
|
|
5013
|
-
}
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
}
|
|
5028
|
-
}
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5541
|
+
}, 60);
|
|
5542
|
+
};
|
|
5543
|
+
const inboxWatcher = guarded(watch(inbox, { persistent: false }, (_e, file) => {
|
|
5544
|
+
if (file) processRequest(file);
|
|
5545
|
+
}));
|
|
5546
|
+
const sweep = setInterval(() => {
|
|
5547
|
+
try {
|
|
5548
|
+
for (const f of readdirSync(inbox)) processRequest(f);
|
|
5549
|
+
} catch {}
|
|
5550
|
+
}, 1e3);
|
|
5551
|
+
sweep.unref?.();
|
|
5552
|
+
onClose(() => {
|
|
5553
|
+
inboxWatcher.close();
|
|
5554
|
+
clearInterval(sweep);
|
|
5555
|
+
});
|
|
5556
|
+
} catch {}
|
|
5557
|
+
}
|
|
5558
|
+
},
|
|
5559
|
+
updatesBeginPlugin(changes),
|
|
5560
|
+
updatesPlugin(root, () => manifest, () => devServer && hooks, landed, changes)
|
|
5561
|
+
];
|
|
5562
|
+
}
|
|
5563
|
+
/**
|
|
5564
|
+
* The live stream's four adapters (spec 28 A4.6 #7), the hub's `read()`: every board's comment log replayed - cached by
|
|
5565
|
+
* its `size:mtimeMs`, so a recompute re-reads only a log that changed (the logs only grow); the frames new now, from the
|
|
5566
|
+
* running server's marks (`freshFrames`); Jam's view (`jamLive.view()`, absent when Jam is off or its lock is held
|
|
5567
|
+
* elsewhere); and `marver work`'s own leases - never `active()`, which holds the Jam daemon's too (A4.6 r2 #3).
|
|
5568
|
+
*/
|
|
5569
|
+
function liveSources(root) {
|
|
5570
|
+
const dir = join(root, "design", "comments");
|
|
5571
|
+
const cache = /* @__PURE__ */ new Map();
|
|
5572
|
+
let reads = 0;
|
|
5573
|
+
return {
|
|
5574
|
+
read(frames) {
|
|
5575
|
+
const names = listBoards(dir);
|
|
5576
|
+
for (const b of cache.keys()) if (!names.includes(b)) cache.delete(b);
|
|
5577
|
+
const boards = [];
|
|
5578
|
+
for (const board of names) {
|
|
5579
|
+
let key;
|
|
5580
|
+
try {
|
|
5581
|
+
const st = statSync(join(dir, `${board}.jsonl`));
|
|
5582
|
+
key = `${st.size}:${st.mtimeMs}`;
|
|
5583
|
+
} catch {
|
|
5584
|
+
continue;
|
|
5585
|
+
}
|
|
5586
|
+
let c = cache.get(board);
|
|
5587
|
+
if (c?.key !== key) {
|
|
5588
|
+
reads++;
|
|
5589
|
+
c = {
|
|
5590
|
+
key,
|
|
5591
|
+
threads: replay(readLog(dir, board))
|
|
5592
|
+
};
|
|
5593
|
+
cache.set(board, c);
|
|
5594
|
+
}
|
|
5595
|
+
boards.push({
|
|
5596
|
+
board,
|
|
5597
|
+
threads: c.threads
|
|
5033
5598
|
});
|
|
5034
|
-
}
|
|
5035
|
-
|
|
5036
|
-
|
|
5599
|
+
}
|
|
5600
|
+
return {
|
|
5601
|
+
boards,
|
|
5602
|
+
fresh: freshFrames(root, frames),
|
|
5603
|
+
jam: jamLive.view?.(),
|
|
5604
|
+
cli: workActivity.leases("cli").map(([f]) => f)
|
|
5605
|
+
};
|
|
5606
|
+
},
|
|
5607
|
+
reads: () => reads
|
|
5608
|
+
};
|
|
5037
5609
|
}
|
|
5038
5610
|
/** The marks look at the frames on disk; true when they recorded something. */
|
|
5039
5611
|
function observed(r) {
|
|
@@ -5086,4 +5658,4 @@ async function tailwind3Css(root) {
|
|
|
5086
5658
|
return null;
|
|
5087
5659
|
}
|
|
5088
5660
|
//#endregion
|
|
5089
|
-
export {
|
|
5661
|
+
export { live_exports as a, ASK_MAX as c, jamLive as i, bakeBatch as l, tailwind3Css as n, liveChanged as o, tailwind4Plugin as r, installedVersion as s, marverPlugin as t };
|