demoman 0.9.4 → 0.9.5

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/dist/cli.mjs CHANGED
@@ -10,8 +10,8 @@ console.debug = toStderr.debug.bind(toStderr);
10
10
 
11
11
  // src/main.ts
12
12
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
13
- import { homedir as homedir4, tmpdir as tmpdir8 } from "node:os";
14
- import { join as join56, relative as relative6, resolve as resolve9 } from "node:path";
13
+ import { homedir as homedir4, tmpdir as tmpdir9 } from "node:os";
14
+ import { join as join57, relative as relative6, resolve as resolve9 } from "node:path";
15
15
  import { createInterface } from "node:readline";
16
16
  import { fileURLToPath as fileURLToPath7 } from "node:url";
17
17
  import { parseArgs as parseArgs4 } from "node:util";
@@ -271,6 +271,19 @@ var HeldPressSchema = z2.object({
271
271
  pressMs: z2.number().nonnegative(),
272
272
  releaseMs: z2.number().nonnegative()
273
273
  });
274
+ var PageScreenSchema = z2.object({
275
+ after: z2.number().int().min(0),
276
+ sourceTimeMs: z2.number(),
277
+ ref: z2.string(),
278
+ width: z2.number().int().positive(),
279
+ height: z2.number().int().positive(),
280
+ heldAnimations: z2.number().int().min(0),
281
+ waitedMs: z2.number().min(0),
282
+ unsettled: z2.string().optional()
283
+ }).refine((s) => s.ref !== "" || s.unsettled !== void 0, {
284
+ message: 'a page screen with no bytes (ref "") must say why in `unsettled`',
285
+ path: ["unsettled"]
286
+ });
274
287
  var ViewportTransformSchema = z2.object({
275
288
  sourceTimeMs: z2.number().nonnegative(),
276
289
  scale: z2.number().positive(),
@@ -396,7 +409,27 @@ var DegradationSchema = z2.object({
396
409
  // A native drag's picture could not be drawn in the page (the element
397
410
  // the page named for it was gone, or copying it threw). The drag still
398
411
  // ran; the film shows the card jump to its drop instead of travelling.
399
- "dragPictureMissing"
412
+ "dragPictureMissing",
413
+ // A step's page had not settled when the cap ran out (requests in
414
+ // flight, an animation running, the DOM still changing) or showed a
415
+ // caret it would not hide: the page's own doing. The video is
416
+ // unaffected; refresh cannot compare that screen. The note names the
417
+ // step and the conditions.
418
+ "stepUnsettled",
419
+ // As `stepUnsettled`, but at least one condition was this machine's:
420
+ // the first paint never came, the settle probe or the page screen
421
+ // failed, requests could not be watched. Recording again may change
422
+ // it, so refresh does (DEM-55); the note names the step and the
423
+ // conditions, the page's beside the machine's.
424
+ "stepSettleFailed",
425
+ // A step's settle left out a request open since more than a request cap
426
+ // before the step began (a long poll): its own step waited for it. The
427
+ // screen counts as settled; the note names the step and how many.
428
+ "requestNotWaited",
429
+ // A page screen's hold (caret hidden, endless animations held) could not
430
+ // be undone after the capture: the video after that step may show no
431
+ // caret and frozen spinners. About the video, so not forgiven.
432
+ "pageHoldNotReleased"
400
433
  ]),
401
434
  note: z2.string()
402
435
  });
@@ -458,6 +491,9 @@ var FrameBundleSchema = z2.object({
458
491
  // 2026-10-11 carries none, and identity is what they were drawn as.
459
492
  // See `ViewportTransformSchema`.
460
493
  viewportTransforms: z2.array(ViewportTransformSchema).optional(),
494
+ // Optional, and absent is none: a sampled replay, a capture, and every
495
+ // bundle written before 2026-11-10 carry none.
496
+ pageScreens: z2.array(PageScreenSchema).optional(),
461
497
  markers: z2.array(MarkerSchema),
462
498
  degradations: z2.array(DegradationSchema),
463
499
  /**
@@ -5741,7 +5777,7 @@ function reportForSave(args2) {
5741
5777
  width: args2.target.width,
5742
5778
  height: args2.target.height,
5743
5779
  fps: args2.target.fps,
5744
- screens: args2.screens,
5780
+ ...args2.screens === void 0 ? {} : { screens: args2.screens },
5745
5781
  warnings: warningsOf({
5746
5782
  logoWarning: file.logoWarning ?? null,
5747
5783
  ...file.wallpaperWarning === void 0 ? {} : { wallpaperWarning: file.wallpaperWarning },
@@ -6208,6 +6244,158 @@ function servedRefusal(r) {
6208
6244
  return out;
6209
6245
  }
6210
6246
 
6247
+ // ../../packages/run-core/dist/kept/file.js
6248
+ var KEPT_VERSION = 2;
6249
+ var KEPT_V1 = 1;
6250
+ var FLOWS_DIR = ".demoman/flows";
6251
+ var LEGACY_FLOWS_DIR = ".demoman/videos";
6252
+ function judgedOutput(outputs) {
6253
+ const wide = (o) => o.aspect !== "9:16";
6254
+ const mp4 = (o) => o.fileType === "mp4";
6255
+ for (const pick of [
6256
+ (o) => wide(o) && mp4(o),
6257
+ wide,
6258
+ mp4,
6259
+ () => true
6260
+ ]) {
6261
+ const i = outputs.findIndex(pick);
6262
+ if (i >= 0)
6263
+ return i;
6264
+ }
6265
+ return 0;
6266
+ }
6267
+ var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
6268
+ var repoRelative = (p) => typeof p === "string" && p !== "" && !p.startsWith("/") && !/^[A-Za-z]:/.test(p) && !p.includes("\\") && !p.split("/").includes("..");
6269
+ var bareName = (p) => repoRelative(p) && !p.includes("/");
6270
+ function parseKept(text2, file) {
6271
+ const bad = (what) => ({
6272
+ ok: false,
6273
+ detail: `${file}: ${what}`
6274
+ });
6275
+ let raw;
6276
+ try {
6277
+ raw = JSON.parse(text2);
6278
+ } catch (e) {
6279
+ return bad(`is not valid JSON (${e instanceof Error ? e.message : e})`);
6280
+ }
6281
+ if (!isObj2(raw))
6282
+ return bad("is not a JSON object");
6283
+ const v1 = raw.keptVersion === KEPT_V1;
6284
+ if (!v1 && raw.keptVersion !== KEPT_VERSION)
6285
+ return bad(unreadVersion("keptVersion", raw.keptVersion, [KEPT_V1, KEPT_VERSION]));
6286
+ if (typeof raw.name !== "string" || raw.name === "")
6287
+ return bad("name must be a non-empty string");
6288
+ const script = DemoScriptSchema.safeParse(raw.script);
6289
+ if (!script.success) {
6290
+ const i = script.error.issues[0];
6291
+ return bad(`script.${(i?.path ?? []).join(".")}: ${i?.message ?? "refused by the script schema"}`);
6292
+ }
6293
+ if (typeof raw.scale !== "number" || !(raw.scale > 0))
6294
+ return bad("scale must be a positive number");
6295
+ if (raw.logo !== null && !repoRelative(raw.logo))
6296
+ return bad("logo must be null or a repo-relative path without ..");
6297
+ const wallpaper = raw.wallpaper ?? null;
6298
+ if (wallpaper !== null && !repoRelative(wallpaper))
6299
+ return bad("wallpaper must be null or a repo-relative path without ..");
6300
+ const deliver2 = v1 ? "commit" : raw.deliver;
6301
+ if (deliver2 !== "commit" && deliver2 !== "files")
6302
+ return bad('deliver must be "commit" or "files"');
6303
+ const pathOk = deliver2 === "files" ? bareName : repoRelative;
6304
+ const pathRule = deliver2 === "files" ? "a bare file name (no /, no ..)" : "repo-relative, posix, without ..";
6305
+ if (raw.report !== null && !pathOk(raw.report))
6306
+ return bad(`report must be null or ${pathRule}`);
6307
+ let flow;
6308
+ if (v1) {
6309
+ const f = raw.from;
6310
+ if (!isObj2(f) || typeof f.videoId !== "string" || typeof f.takeId !== "string" || typeof f.recordedRevision !== "string")
6311
+ return bad("from needs string videoId, takeId and recordedRevision");
6312
+ if (!isFlowId(f.videoId))
6313
+ return bad(`from.videoId ${JSON.stringify(f.videoId)} is not a flow id`);
6314
+ flow = f.videoId;
6315
+ } else {
6316
+ if (typeof raw.flow !== "string" || !isFlowId(raw.flow))
6317
+ return bad(`flow ${JSON.stringify(raw.flow)} is not a flow id`);
6318
+ flow = raw.flow;
6319
+ }
6320
+ if (!Array.isArray(raw.outputs) || raw.outputs.length === 0)
6321
+ return bad("outputs must list at least one output");
6322
+ const outputs = [];
6323
+ for (const [i, o] of raw.outputs.entries()) {
6324
+ if (!isObj2(o))
6325
+ return bad(`outputs[${i}] is not an object`);
6326
+ if (!pathOk(o.path))
6327
+ return bad(`outputs[${i}].path must be ${pathRule}; got ${JSON.stringify(o.path)}`);
6328
+ if (o.fileType !== "mp4" && o.fileType !== "gif")
6329
+ return bad(`outputs[${i}].fileType must be "mp4" or "gif"`);
6330
+ if (o.aspect !== "auto" && o.aspect !== "16:9" && o.aspect !== "9:16")
6331
+ return bad(`outputs[${i}].aspect must be "auto", "16:9" or "9:16"`);
6332
+ if (!EXPORT_QUALITY_VALUES.includes(o.quality))
6333
+ return bad(`outputs[${i}].quality must be one of ${EXPORT_QUALITY_VALUES.join(", ")}`);
6334
+ outputs.push({
6335
+ path: o.path,
6336
+ fileType: o.fileType,
6337
+ aspect: o.aspect,
6338
+ quality: o.quality
6339
+ });
6340
+ }
6341
+ let migrated = null;
6342
+ if (v1) {
6343
+ const f = raw.from;
6344
+ migrated = {
6345
+ receiptVersion: 1,
6346
+ screensDir: null,
6347
+ flow,
6348
+ video: f.takeId,
6349
+ filmedAt: null,
6350
+ filmedCode: { none: "kept before receipts were recorded" },
6351
+ screens: null,
6352
+ recordedRevision: f.recordedRevision
6353
+ };
6354
+ }
6355
+ return {
6356
+ ok: true,
6357
+ kept: {
6358
+ keptVersion: KEPT_VERSION,
6359
+ flow,
6360
+ name: raw.name,
6361
+ script: script.data,
6362
+ scale: raw.scale,
6363
+ logo: raw.logo,
6364
+ wallpaper,
6365
+ deliver: deliver2,
6366
+ outputs,
6367
+ report: raw.report
6368
+ },
6369
+ migrated
6370
+ };
6371
+ }
6372
+ var videoSlug = (name) => name.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "") || "video";
6373
+ function keptFileName(name) {
6374
+ return `${videoSlug(name)}.json`;
6375
+ }
6376
+ function serializeKept(k) {
6377
+ const ordered = {
6378
+ keptVersion: k.keptVersion,
6379
+ flow: k.flow,
6380
+ name: k.name,
6381
+ script: k.script,
6382
+ scale: k.scale,
6383
+ logo: k.logo,
6384
+ // Only when there is one: a file kept before wallpapers reads the same.
6385
+ ...k.wallpaper === null ? {} : { wallpaper: k.wallpaper },
6386
+ deliver: k.deliver,
6387
+ outputs: k.outputs.map((o) => ({
6388
+ path: o.path,
6389
+ fileType: o.fileType,
6390
+ aspect: o.aspect,
6391
+ quality: o.quality
6392
+ })),
6393
+ report: k.report
6394
+ };
6395
+ return `${JSON.stringify(ordered, null, 2)}
6396
+ `;
6397
+ }
6398
+
6211
6399
  // ../../packages/replay-engine/dist/constants.js
6212
6400
  var SETTLE_MS = 300;
6213
6401
  var TYPE_KEY_MS = 70;
@@ -6241,6 +6429,9 @@ var REPLAY_HOLD_TTL_MS = 30 * 60 * 1e3;
6241
6429
  var RENDER_ESTIMATE_FALLBACK_BYTES = 50 * 1024 * 1024;
6242
6430
  var NAVIGATE_TIMEOUT_MS = 15e3;
6243
6431
  var ACT_CEILING_MS = 1e3;
6432
+ var STEP_QUIET_MS = 200;
6433
+ var STEP_SETTLE_CAP_MS = 2e3;
6434
+ var STEP_REQUEST_CAP_MS = 6e3;
6244
6435
 
6245
6436
  // ../../packages/replay-engine/dist/act-end.js
6246
6437
  function actEndOf(verbEndMs, lastMotionMs) {
@@ -7127,6 +7318,13 @@ function jpegSize(bytes) {
7127
7318
  }
7128
7319
  throw new Error("screenshot is not a JPEG this parser understands");
7129
7320
  }
7321
+ function pngSize(bytes) {
7322
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
7323
+ const signed = bytes.length >= 24 && view.getUint32(0) === 2303741511 && view.getUint32(12) === 1229472850;
7324
+ if (!signed)
7325
+ throw new Error("screenshot is not a PNG this parser understands");
7326
+ return { width: view.getUint32(16), height: view.getUint32(20) };
7327
+ }
7130
7328
 
7131
7329
  // ../../packages/replay-engine/dist/frame-change.js
7132
7330
  function lumaBlocks(bytes) {
@@ -7764,6 +7962,80 @@ function pathPointAt(segment, elapsedMs) {
7764
7962
  return sampleSegment(segment, easings[segment.easing](progress));
7765
7963
  }
7766
7964
 
7965
+ // ../../packages/replay-engine/dist/requests.js
7966
+ var COUNTED = /* @__PURE__ */ new Set(["Fetch", "XHR"]);
7967
+ var POLL_MS = 25;
7968
+ async function trackRequests(cdp, now) {
7969
+ const open3 = /* @__PURE__ */ new Map();
7970
+ const forget = (frame) => {
7971
+ if (frame === void 0)
7972
+ return;
7973
+ for (const [id, r] of open3)
7974
+ if (r.frame === frame)
7975
+ open3.delete(id);
7976
+ };
7977
+ const offs = [
7978
+ cdp.on("Network.requestWillBeSent", (p) => {
7979
+ const id = String(p.requestId);
7980
+ if (COUNTED.has(String(p.type)) && !open3.has(id))
7981
+ open3.set(id, { at: now(), frame: p.frameId });
7982
+ }),
7983
+ cdp.on("Network.loadingFinished", (p) => void open3.delete(String(p.requestId))),
7984
+ cdp.on("Network.loadingFailed", (p) => void open3.delete(String(p.requestId))),
7985
+ // A new document in a frame: the old one's requests died with it, and
7986
+ // Chrome does not always say so with `loadingFailed`. Left counted, each
7987
+ // would cost the step the whole cap and read as in flight when it was
7988
+ // not. A new top document takes its frames' requests with it too.
7989
+ cdp.on("Page.frameNavigated", (p) => {
7990
+ const frame = p.frame;
7991
+ if (frame === void 0)
7992
+ return;
7993
+ if (frame.parentId === void 0)
7994
+ open3.clear();
7995
+ else
7996
+ forget(frame.id);
7997
+ }),
7998
+ // A frame removed from the page: its requests went with it.
7999
+ cdp.on("Page.frameDetached", (p) => forget(p.frameId))
8000
+ ];
8001
+ const dispose = () => {
8002
+ for (const off of offs)
8003
+ off();
8004
+ };
8005
+ try {
8006
+ await cdp.send("Network.enable", {
8007
+ maxTotalBufferSize: 0,
8008
+ maxResourceBufferSize: 0,
8009
+ maxPostDataSize: 0
8010
+ });
8011
+ } catch (err) {
8012
+ dispose();
8013
+ throw err;
8014
+ }
8015
+ const inFlight = (openedAfter = Number.NEGATIVE_INFINITY) => {
8016
+ let n = 0;
8017
+ for (const r of open3.values())
8018
+ if (r.at > openedAfter)
8019
+ n++;
8020
+ return n;
8021
+ };
8022
+ return {
8023
+ inFlight,
8024
+ async idle(deadlineMs, sleep3, openedAfter) {
8025
+ while (inFlight(openedAfter) > 0) {
8026
+ if (now() >= deadlineMs)
8027
+ return false;
8028
+ await sleep3(POLL_MS);
8029
+ }
8030
+ return true;
8031
+ },
8032
+ dispose() {
8033
+ dispose();
8034
+ void cdp.send("Network.disable").catch(() => void 0);
8035
+ }
8036
+ };
8037
+ }
8038
+
7767
8039
  // ../../packages/replay-engine/dist/scroll.js
7768
8040
  var SCROLL_MARKER = "__demomanScrollIntoView";
7769
8041
  function scrollIntoViewFunction(aim, timeoutMs) {
@@ -7913,6 +8185,140 @@ function settlePaintExpression(timeoutMs, quietTimeoutMs = SETTLE_QUIET_TIMEOUT_
7913
8185
  })()`;
7914
8186
  }
7915
8187
 
8188
+ // ../../packages/replay-engine/dist/step-settle.js
8189
+ var STEP_SETTLE_MARKER = "__demomanStepSettle";
8190
+ function stepSettleExpression(quietMs, capMs) {
8191
+ return `(() => {
8192
+ const ${STEP_SETTLE_MARKER} = true;
8193
+ const t0 = Date.now();
8194
+ let lastChange = t0;
8195
+ let painted = false;
8196
+ let animations = 0;
8197
+ let watcher = null;
8198
+ // An animation read that failed is unknown, not zero: never quiet.
8199
+ let failed = false;
8200
+ // Set once answered: a loop the backstop beat must not read the page's
8201
+ // animations every frame for the rest of the take.
8202
+ let done = false;
8203
+ const countAnimations = () => {
8204
+ try {
8205
+ if (!document.getAnimations) { failed = true; return 0; }
8206
+ return document.getAnimations().filter((a) => {
8207
+ if (a.playState !== "running") return false;
8208
+ const t = a.effect && a.effect.getComputedTiming();
8209
+ return !t || t.iterations !== Infinity;
8210
+ }).length;
8211
+ } catch (e) { failed = true; return 0; }
8212
+ };
8213
+ const quietNow = () => Date.now() - lastChange >= ${quietMs};
8214
+ const reply = (stopped) => {
8215
+ done = true;
8216
+ if (watcher) watcher.disconnect();
8217
+ // Settled as the loop saw it; at the cap, the page as it is then.
8218
+ if (stopped === "cap") {
8219
+ animations = countAnimations();
8220
+ if (painted && !failed && animations === 0 && quietNow()) stopped = "quiet";
8221
+ }
8222
+ if (failed) stopped = "animationReadFailed";
8223
+ return {
8224
+ painted,
8225
+ animations,
8226
+ quiet: stopped === "quiet",
8227
+ waitedMs: Date.now() - t0,
8228
+ stopped,
8229
+ };
8230
+ };
8231
+ try {
8232
+ watcher = new MutationObserver(() => { lastChange = Date.now(); });
8233
+ watcher.observe(document, {
8234
+ subtree: true, childList: true, attributes: true, characterData: true,
8235
+ });
8236
+ } catch (e) { return Promise.resolve(reply("unwatched")); }
8237
+ const frame = () => new Promise((r) => requestAnimationFrame(() => r()));
8238
+ const work = (async () => {
8239
+ await frame();
8240
+ painted = true;
8241
+ for (;;) {
8242
+ if (done) return "done";
8243
+ const n = countAnimations();
8244
+ if (failed) return "animationReadFailed";
8245
+ if (n === 0 && quietNow()) return "quiet";
8246
+ await frame();
8247
+ }
8248
+ })();
8249
+ const backstop = new Promise((r) => setTimeout(() => r("cap"), ${capMs}));
8250
+ return Promise.race([work, backstop]).then(reply);
8251
+ })()`;
8252
+ }
8253
+ var CARET_STYLE_ID = "__demomanCaretHold";
8254
+ var CARET_RULE = "*{caret-color:transparent!important}";
8255
+ var PAGE_CAPTURE_HOLD = `(() => {
8256
+ if (!document.getElementById("${CARET_STYLE_ID}") && !window.__demomanCaretSheet) {
8257
+ if (!window.__demomanCaretRefused) {
8258
+ const s = document.createElement("style");
8259
+ s.id = "${CARET_STYLE_ID}";
8260
+ s.textContent = "${CARET_RULE}";
8261
+ (document.head || document.documentElement).append(s);
8262
+ if (!s.sheet) {
8263
+ s.remove();
8264
+ window.__demomanCaretRefused = true;
8265
+ }
8266
+ }
8267
+ if (window.__demomanCaretRefused) {
8268
+ try {
8269
+ const c = new CSSStyleSheet();
8270
+ c.replaceSync("${CARET_RULE}");
8271
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, c];
8272
+ window.__demomanCaretSheet = c;
8273
+ } catch (e) {} // said below: the caret is still shown
8274
+ }
8275
+ }
8276
+ let f = document.activeElement;
8277
+ while (f && f.shadowRoot && f.shadowRoot.activeElement) f = f.shadowRoot.activeElement;
8278
+ const caretShown = !!f && (f.tagName === "IFRAME" || f.tagName === "FRAME" ||
8279
+ ((f.isContentEditable || f.tagName === "INPUT" || f.tagName === "TEXTAREA") &&
8280
+ getComputedStyle(f).caretColor !== "rgba(0, 0, 0, 0)"));
8281
+ const held = window.__demomanHeld || (window.__demomanHeld = []);
8282
+ for (const a of document.getAnimations ? document.getAnimations() : []) {
8283
+ const t = a.effect && a.effect.getComputedTiming();
8284
+ if (a.playState !== "running" || !t || t.iterations !== Infinity) continue;
8285
+ held.push({ a, t: a.currentTime });
8286
+ a.pause();
8287
+ a.currentTime = 0;
8288
+ }
8289
+ return {
8290
+ held: held.length, caretShown, x: scrollX, y: scrollY,
8291
+ width: innerWidth, height: innerHeight, dpr: devicePixelRatio,
8292
+ };
8293
+ })()`;
8294
+ var PAGE_CAPTURE_RELEASE = `(() => {
8295
+ const s = document.getElementById("${CARET_STYLE_ID}");
8296
+ if (s) s.remove();
8297
+ const c = window.__demomanCaretSheet;
8298
+ if (c) {
8299
+ document.adoptedStyleSheets = document.adoptedStyleSheets.filter((x) => x !== c);
8300
+ delete window.__demomanCaretSheet;
8301
+ }
8302
+ const held = window.__demomanHeld || [];
8303
+ for (const { a, t } of held) { a.currentTime = t; a.play(); }
8304
+ window.__demomanHeld = [];
8305
+ return held.length;
8306
+ })()`;
8307
+ var STRAY_WINDOW_MS = 250;
8308
+ var ECHO_WINDOW_MS = 100;
8309
+ function capturedAway(paintedMs, size, capture) {
8310
+ if (capture === null || paintedMs < capture.fromMs)
8311
+ return false;
8312
+ if (capture.toMs === null || paintedMs <= capture.toMs)
8313
+ return true;
8314
+ const echoEnds = Math.min(capture.toMs + ECHO_WINDOW_MS, capture.inputMs ?? Number.POSITIVE_INFINITY);
8315
+ if (paintedMs <= echoEnds)
8316
+ return true;
8317
+ if (capture.size === null || paintedMs > capture.toMs + STRAY_WINDOW_MS)
8318
+ return false;
8319
+ return size() !== capture.size;
8320
+ }
8321
+
7916
8322
  // ../../packages/replay-engine/dist/visibility.js
7917
8323
  function seenNow(el) {
7918
8324
  if (!el.checkVisibility({ opacityProperty: true, visibilityProperty: true })) {
@@ -8023,6 +8429,34 @@ function describeSettleError(error) {
8023
8429
  return error.message;
8024
8430
  return String(error);
8025
8431
  }
8432
+ function evaluatedValue(reply) {
8433
+ const thrown = reply.exceptionDetails;
8434
+ if (thrown !== void 0) {
8435
+ throw new Error(thrown.exception?.description ?? thrown.text ?? "the page threw");
8436
+ }
8437
+ return reply.result?.value;
8438
+ }
8439
+ var pageMade = (words) => ({ words, machine: false });
8440
+ var machineMade = (words) => ({ words, machine: true });
8441
+ function unsettledWords(report) {
8442
+ if (report.quiet === true)
8443
+ return [];
8444
+ if (report.stopped === "unwatched")
8445
+ return [machineMade("the page's changes could not be watched")];
8446
+ if (report.stopped === "animationReadFailed")
8447
+ return [machineMade("the page's animations could not be read")];
8448
+ const words = [];
8449
+ const animations = report.animations ?? 0;
8450
+ if (report.painted !== true)
8451
+ words.push(machineMade("its first paint never came"));
8452
+ if (animations > 0)
8453
+ words.push(pageMade(`${animations} animation(s) still running`));
8454
+ if (report.painted === true && animations === 0)
8455
+ words.push(pageMade("the DOM never went quiet"));
8456
+ return words;
8457
+ }
8458
+ var PAGE_NOT_ASKED = pageMade("the page was not asked (the cap ran out first)");
8459
+ var STILL_LOADING = pageMade("the page was still loading");
8026
8460
  function replayOutcome(completed, total) {
8027
8461
  return completed === total ? "complete" : "partial";
8028
8462
  }
@@ -8030,6 +8464,7 @@ async function runWalk(source, deps, config) {
8030
8464
  const { page: page2, encoder, store, clock } = deps;
8031
8465
  const answering = withAnswerDeadline(deps.cdp);
8032
8466
  const { cdp } = answering;
8467
+ const screening = withAnswerDeadline(cdp, STILL_DRAIN_MS);
8033
8468
  const { sceneId, viewport, total, device } = config;
8034
8469
  const empty = (reason2) => ({
8035
8470
  bundle: null,
@@ -8123,7 +8558,14 @@ async function runWalk(source, deps, config) {
8123
8558
  const applyMetrics = async () => {
8124
8559
  await cdp.send("Emulation.setDeviceMetricsOverride", device === null ? desktopMetrics(viewport) : deviceMetrics(device));
8125
8560
  };
8126
- const gate = deps.inputGate ?? createInputGate();
8561
+ const sharedGate = deps.inputGate ?? createInputGate();
8562
+ const gate = {
8563
+ section: (input) => sharedGate.section(() => {
8564
+ pageFrames.inputBegan();
8565
+ return input();
8566
+ }),
8567
+ capture: (take) => sharedGate.capture(take)
8568
+ };
8127
8569
  const takeShot = async (actionId) => {
8128
8570
  const reply = await gate.capture(() => cdp.send("Page.captureScreenshot", {
8129
8571
  format: "jpeg",
@@ -8156,8 +8598,17 @@ async function runWalk(source, deps, config) {
8156
8598
  };
8157
8599
  let shooting = Promise.resolve();
8158
8600
  let sealed = false;
8601
+ let stillsWaiting = 0;
8602
+ const counted = (run2) => {
8603
+ stillsWaiting++;
8604
+ const done = () => {
8605
+ stillsWaiting--;
8606
+ };
8607
+ void run2.then(done, done);
8608
+ };
8159
8609
  const shot = (actionId, stillWanted = () => true) => {
8160
8610
  const run2 = shooting.then(() => stillWanted() ? takeShot(actionId) : void 0);
8611
+ counted(run2);
8161
8612
  shooting = run2.catch(() => void 0);
8162
8613
  return run2;
8163
8614
  };
@@ -8197,6 +8648,7 @@ async function runWalk(source, deps, config) {
8197
8648
  return takeShot(actionId);
8198
8649
  await fileStill(bytes, actionId, frame.atMs);
8199
8650
  });
8651
+ counted(run2);
8200
8652
  shooting = run2.catch(() => void 0);
8201
8653
  return run2;
8202
8654
  };
@@ -8239,6 +8691,235 @@ async function runWalk(source, deps, config) {
8239
8691
  }
8240
8692
  return drained;
8241
8693
  };
8694
+ const pageFrames = /* @__PURE__ */ (() => {
8695
+ let capture = null;
8696
+ const sizeOf2 = (data) => {
8697
+ try {
8698
+ const { width, height } = jpegSize(decodeBase64(data));
8699
+ return `${width}x${height}`;
8700
+ } catch {
8701
+ return null;
8702
+ }
8703
+ };
8704
+ let latest = null;
8705
+ return {
8706
+ seen(data) {
8707
+ latest = data;
8708
+ },
8709
+ hold() {
8710
+ capture = {
8711
+ fromMs: clock.now(),
8712
+ toMs: null,
8713
+ inputMs: null,
8714
+ size: latest === null ? null : sizeOf2(latest)
8715
+ };
8716
+ },
8717
+ release() {
8718
+ if (capture !== null)
8719
+ capture.toMs = clock.now();
8720
+ },
8721
+ inputBegan() {
8722
+ if (capture !== null && capture.toMs !== null && capture.inputMs === null)
8723
+ capture.inputMs = clock.now();
8724
+ },
8725
+ dropping(data, paintedMs) {
8726
+ return capturedAway(paintedMs, () => sizeOf2(data), capture);
8727
+ }
8728
+ };
8729
+ })();
8730
+ let tracker = null;
8731
+ let untracked = "they were never asked about";
8732
+ const pageScreens = [];
8733
+ const settlePage = async (deadline) => {
8734
+ for (; ; ) {
8735
+ while (topLoading && at2() < deadline)
8736
+ await clock.sleep(50);
8737
+ const capMs = deadline - at2();
8738
+ if (capMs <= 0) {
8739
+ return [...topLoading ? [STILL_LOADING] : [], PAGE_NOT_ASKED];
8740
+ }
8741
+ const navs = navigationsSeen;
8742
+ let report;
8743
+ let failure3 = null;
8744
+ try {
8745
+ report = evaluatedValue(await cdp.send("Runtime.evaluate", {
8746
+ expression: stepSettleExpression(STEP_QUIET_MS, capMs),
8747
+ awaitPromise: true,
8748
+ returnByValue: true
8749
+ }));
8750
+ } catch (error) {
8751
+ failure3 = error;
8752
+ }
8753
+ if ((navigationsSeen !== navs || topLoading) && at2() < deadline) {
8754
+ continue;
8755
+ }
8756
+ const words = topLoading ? [STILL_LOADING] : [];
8757
+ if (failure3 !== null) {
8758
+ return [
8759
+ ...words,
8760
+ machineMade(`the settle probe failed (${describeSettleError(failure3)})`)
8761
+ ];
8762
+ }
8763
+ if (report === void 0 || typeof report.quiet !== "boolean") {
8764
+ return [
8765
+ ...words,
8766
+ machineMade("the settle probe answered with nothing readable")
8767
+ ];
8768
+ }
8769
+ return [...words, ...unsettledWords(report)];
8770
+ }
8771
+ };
8772
+ const settleWords = async (requestBy, openedAfter) => {
8773
+ for (; ; ) {
8774
+ if (tracker === null) {
8775
+ return [
8776
+ machineMade(`requests could not be watched (${untracked})`),
8777
+ ...await settlePage(at2() + STEP_SETTLE_CAP_MS)
8778
+ ];
8779
+ }
8780
+ if (!await tracker.idle(requestBy, clock.sleep, openedAfter)) {
8781
+ return [
8782
+ pageMade(`${tracker.inFlight(openedAfter)} request(s) in flight`),
8783
+ PAGE_NOT_ASKED
8784
+ ];
8785
+ }
8786
+ const page3 = await settlePage(at2() + STEP_SETTLE_CAP_MS);
8787
+ if (tracker.inFlight(openedAfter) === 0)
8788
+ return page3;
8789
+ if (at2() >= requestBy) {
8790
+ return [
8791
+ pageMade(`${tracker.inFlight(openedAfter)} request(s) in flight`),
8792
+ ...page3
8793
+ ];
8794
+ }
8795
+ }
8796
+ };
8797
+ const stillLineFree = async () => {
8798
+ let free = stillsWaiting === 0;
8799
+ if (!free) {
8800
+ await Promise.race([
8801
+ shooting.then(() => {
8802
+ free = true;
8803
+ }),
8804
+ clock.sleep(STILL_DRAIN_MS)
8805
+ ]);
8806
+ }
8807
+ return free;
8808
+ };
8809
+ const STILL_LINE_STUCK = `a still ahead of it was still being taken after ${STILL_DRAIN_MS / 1e3} s; the page had most likely stopped painting`;
8810
+ const capturePage = async () => {
8811
+ if (!await stillLineFree())
8812
+ throw new Error(STILL_LINE_STUCK);
8813
+ const run2 = shooting.then(() => gate.capture(async () => {
8814
+ let taken = null;
8815
+ let failure3 = null;
8816
+ pageFrames.hold();
8817
+ try {
8818
+ const g = evaluatedValue(await cdp.send("Runtime.evaluate", {
8819
+ expression: PAGE_CAPTURE_HOLD,
8820
+ returnByValue: true
8821
+ }));
8822
+ const { held, x, y, width, height, dpr } = g ?? {};
8823
+ if (held === void 0 || x === void 0 || y === void 0 || width === void 0 || height === void 0 || dpr === void 0) {
8824
+ throw new Error("the capture hold answered with nothing readable");
8825
+ }
8826
+ const shot2 = await screening.cdp.send("Page.captureScreenshot", {
8827
+ format: "png",
8828
+ clip: { x, y, width, height, scale: 1 / dpr }
8829
+ });
8830
+ captureEndedMs = at2();
8831
+ taken = {
8832
+ bytes: decodeBase64(String(shot2.data ?? "")),
8833
+ held,
8834
+ atMs: captureEndedMs,
8835
+ // Unreadable counts as shown: a hidden caret is never assumed.
8836
+ caretShown: g?.caretShown !== false
8837
+ };
8838
+ } catch (error) {
8839
+ failure3 = error;
8840
+ }
8841
+ let releaseFailed = null;
8842
+ try {
8843
+ evaluatedValue(await cdp.send("Runtime.evaluate", {
8844
+ expression: PAGE_CAPTURE_RELEASE,
8845
+ returnByValue: true
8846
+ }));
8847
+ } catch (error) {
8848
+ releaseFailed = describeSettleError(error);
8849
+ }
8850
+ pageFrames.release();
8851
+ return { taken, failure: failure3, releaseFailed };
8852
+ }));
8853
+ shooting = run2.then(() => void 0, () => void 0);
8854
+ return run2;
8855
+ };
8856
+ const settleAndCapture = async (after, actionId, pointerStep = false) => {
8857
+ const from = at2();
8858
+ const openedAfter = from - STEP_REQUEST_CAP_MS;
8859
+ const moved2 = [];
8860
+ if (pointerStep && cursorSamples.length > 0) {
8861
+ try {
8862
+ if (!await stillLineFree())
8863
+ throw new Error(STILL_LINE_STUCK);
8864
+ await gate.section(() => cdp.send("Input.dispatchMouseEvent", {
8865
+ type: "mouseMoved",
8866
+ x: cursor2.x,
8867
+ y: cursor2.y
8868
+ }));
8869
+ } catch (error) {
8870
+ moved2.push(machineMade(`the pointer's hover could not be renewed (${describeSettleError(error)})`));
8871
+ }
8872
+ }
8873
+ const unsettled = [
8874
+ ...moved2,
8875
+ ...await settleWords(from + STEP_REQUEST_CAP_MS, openedAfter)
8876
+ ];
8877
+ const waitedMs = Math.max(0, at2() - from);
8878
+ const leftOut = tracker === null ? 0 : tracker.inFlight() - tracker.inFlight(openedAfter);
8879
+ const place2 = actionId === null ? "the opening page" : `the page after step ${actionId}`;
8880
+ if (leftOut > 0) {
8881
+ degradations.push(degradation("requestNotWaited", from, at2(), `${place2}: ${leftOut} request${leftOut === 1 ? "" : "s"} opened more than ${STEP_REQUEST_CAP_MS / 1e3} s before this step's wait began ${leftOut === 1 ? "was" : "were"} not waited for`));
8882
+ }
8883
+ let screen2 = null;
8884
+ try {
8885
+ const { taken, failure: failure3, releaseFailed } = await capturePage();
8886
+ if (releaseFailed !== null) {
8887
+ degradations.push(degradation("pageHoldNotReleased", from, at2(), `${place2}: the caret and held animations may not have been put back (${releaseFailed})`));
8888
+ }
8889
+ if (taken === null)
8890
+ throw failure3;
8891
+ if (taken.caretShown) {
8892
+ unsettled.push(pageMade("a focused field's caret could not be hidden"));
8893
+ }
8894
+ const size = pngSize(taken.bytes);
8895
+ screen2 = {
8896
+ after,
8897
+ sourceTimeMs: taken.atMs,
8898
+ ref: await store.putPageScreen(sceneId, after, taken.bytes),
8899
+ width: size.width,
8900
+ height: size.height,
8901
+ heldAnimations: taken.held,
8902
+ waitedMs
8903
+ };
8904
+ } catch (error) {
8905
+ unsettled.push(machineMade(`the page screen could not be taken (${describeSettleError(error)})`));
8906
+ }
8907
+ screen2 ??= {
8908
+ after,
8909
+ sourceTimeMs: at2(),
8910
+ ref: "",
8911
+ width: viewport.width,
8912
+ height: viewport.height,
8913
+ heldAnimations: 0,
8914
+ waitedMs
8915
+ };
8916
+ if (unsettled.length > 0) {
8917
+ screen2.unsettled = unsettled.map((u) => u.words).join("; ");
8918
+ degradations.push(degradation(unsettled.some((u) => u.machine) ? "stepSettleFailed" : "stepUnsettled", from, at2(), `${place2}: ${screen2.unsettled}`));
8919
+ }
8920
+ pageScreens.push(screen2);
8921
+ roomAdded += at2() - from;
8922
+ };
8242
8923
  const recorder = createMotionRecorder({
8243
8924
  encoder,
8244
8925
  clock,
@@ -8263,9 +8944,18 @@ async function runWalk(source, deps, config) {
8263
8944
  });
8264
8945
  const offFrame = cdp.on("Page.screencastFrame", (params) => {
8265
8946
  void cdp.send("Page.screencastFrameAck", { sessionId: params.sessionId }).catch(() => void 0);
8266
- if (continuous && !filming)
8947
+ const data = String(params.data ?? "");
8948
+ if (continuous && !filming) {
8949
+ pageFrames.seen(data);
8267
8950
  return;
8268
- const seen = { data: String(params.data ?? ""), atMs: at2() };
8951
+ }
8952
+ const arrived = clock.now();
8953
+ const stamp = params.metadata?.timestamp;
8954
+ const painted = typeof stamp === "number" ? stamp * 1e3 : arrived;
8955
+ if (pageFrames.dropping(data, painted))
8956
+ return;
8957
+ pageFrames.seen(data);
8958
+ const seen = { data: String(params.data ?? ""), atMs: arrived - started };
8269
8959
  priorFrame = newestFrame;
8270
8960
  newestFrame = seen;
8271
8961
  for (const waiter of frameWaiters.splice(0))
@@ -8816,6 +9506,13 @@ async function runWalk(source, deps, config) {
8816
9506
  quality: 80,
8817
9507
  everyNthFrame: 1
8818
9508
  });
9509
+ if (continuous) {
9510
+ try {
9511
+ tracker = await trackRequests(cdp, at2);
9512
+ } catch (error) {
9513
+ untracked = describeSettleError(error);
9514
+ }
9515
+ }
8819
9516
  const navsBeforeStart = navigationsSeen;
8820
9517
  await deps.occlusion?.install();
8821
9518
  const unsettled = await settlePaint();
@@ -8828,6 +9525,8 @@ async function runWalk(source, deps, config) {
8828
9525
  } else {
8829
9526
  await shot(null);
8830
9527
  filming = true;
9528
+ if (continuous)
9529
+ await settleAndCapture(0, null);
8831
9530
  }
8832
9531
  navsAtThisStep = navsBeforeStart;
8833
9532
  for await (const step of signedOut === null ? source.steps() : NO_STEPS) {
@@ -8879,6 +9578,8 @@ async function runWalk(source, deps, config) {
8879
9578
  };
8880
9579
  markers.push(waitMarker);
8881
9580
  await stepStill(step.action.id);
9581
+ if (continuous)
9582
+ await settleAndCapture(completed + 1, step.action.id);
8882
9583
  completed++;
8883
9584
  lastCompletedActionId = step.action.id;
8884
9585
  inFlight = null;
@@ -8924,6 +9625,8 @@ async function runWalk(source, deps, config) {
8924
9625
  verbs++;
8925
9626
  if (room !== void 0)
8926
9627
  pendingAct = { marker: marker2, verbEndMs: at2() };
9628
+ if (continuous)
9629
+ await settleAndCapture(completed + 1, keyAction.id);
8927
9630
  completed++;
8928
9631
  lastCompletedActionId = keyAction.id;
8929
9632
  inFlight = null;
@@ -9060,7 +9763,7 @@ async function runWalk(source, deps, config) {
9060
9763
  lastHeldUntil = lastZoom?.arrivalMs ?? null;
9061
9764
  await stepStill(step.action.id);
9062
9765
  if (continuous) {
9063
- const clicked = await gate.section(() => dragPlan !== null ? performDrag(step.action.id, dragPlan, handle.objectId, device?.touch === true) : performVerb(step.action, text2, cdp, cursor2, device?.touch === true, handle.objectId, sightings, clock.sleep, step.onFieldRead));
9766
+ const clicked = await gate.section(() => dragPlan !== null ? performDrag(step.action.id, dragPlan, handle.objectId, device?.touch === true) : performVerb(step.action, text2, cdp, cursor2, device?.touch === true, handle.objectId, sightings, clock.sleep, step.onFieldRead, step.onLastKeyUnpainted));
9064
9767
  stillOwed = true;
9065
9768
  verbs++;
9066
9769
  if (clickStopped(step.action.kind, clicked))
@@ -9075,7 +9778,7 @@ async function runWalk(source, deps, config) {
9075
9778
  }
9076
9779
  } else {
9077
9780
  recorder.open();
9078
- const clicked = await gate.section(() => dragPlan !== null ? performDrag(step.action.id, dragPlan, handle.objectId, device?.touch === true) : performVerb(step.action, text2, cdp, cursor2, device?.touch === true, handle.objectId, sightings, clock.sleep, step.onFieldRead));
9781
+ const clicked = await gate.section(() => dragPlan !== null ? performDrag(step.action.id, dragPlan, handle.objectId, device?.touch === true) : performVerb(step.action, text2, cdp, cursor2, device?.touch === true, handle.objectId, sightings, clock.sleep, step.onFieldRead, step.onLastKeyUnpainted));
9079
9782
  const spansBefore = motionSpans.length;
9080
9783
  await recorder.close();
9081
9784
  if (clickStopped(step.action.kind, clicked))
@@ -9085,6 +9788,8 @@ async function runWalk(source, deps, config) {
9085
9788
  }
9086
9789
  await shot(null);
9087
9790
  }
9791
+ if (continuous)
9792
+ await settleAndCapture(completed + 1, step.action.id, true);
9088
9793
  completed++;
9089
9794
  lastCompletedActionId = step.action.id;
9090
9795
  inFlight = null;
@@ -9127,11 +9832,13 @@ async function runWalk(source, deps, config) {
9127
9832
  offStarted();
9128
9833
  offStopped();
9129
9834
  await cdp.send("Page.stopScreencast").catch(() => void 0);
9835
+ tracker?.dispose();
9130
9836
  await recorder.teardown();
9131
9837
  if (!sealed)
9132
9838
  await drainShots();
9133
9839
  sealed = true;
9134
9840
  await sightings.stop();
9841
+ screening.stop();
9135
9842
  answering.stop();
9136
9843
  }
9137
9844
  if (continuous) {
@@ -9169,6 +9876,7 @@ async function runWalk(source, deps, config) {
9169
9876
  cursorGaps: [],
9170
9877
  anchorRects,
9171
9878
  ...heldPresses.length === 0 ? {} : { heldPresses },
9879
+ ...pageScreens.length === 0 ? {} : { pageScreens },
9172
9880
  ...viewportTransforms.length === 0 ? {} : { viewportTransforms },
9173
9881
  markers,
9174
9882
  degradations,
@@ -9215,7 +9923,7 @@ async function runWalk(source, deps, config) {
9215
9923
  counters
9216
9924
  };
9217
9925
  }
9218
- async function performVerb(action, text2, cdp, cursor2, touch, objectId, sightings, sleep3, onFieldRead) {
9926
+ async function performVerb(action, text2, cdp, cursor2, touch, objectId, sightings, sleep3, onFieldRead, onLastKeyUnpainted) {
9219
9927
  const click = async () => {
9220
9928
  const probe = await placeClickProbe(cdp, objectId, action.id);
9221
9929
  try {
@@ -9274,6 +9982,9 @@ async function performVerb(action, text2, cdp, cursor2, touch, objectId, sightin
9274
9982
  }
9275
9983
  const typed = typeof text2 === "string" ? text2 : "";
9276
9984
  await typeKeys(typed, cdp, sleep3);
9985
+ const unpainted = await lastKeyPainted(cdp, objectId);
9986
+ if (unpainted !== null)
9987
+ onLastKeyUnpainted?.(unpainted);
9277
9988
  if (onFieldRead !== void 0) {
9278
9989
  try {
9279
9990
  const reply = await cdp.send("Runtime.callFunctionOn", {
@@ -9331,6 +10042,28 @@ async function typeKeys(text2, cdp, sleep3) {
9331
10042
  await cdp.send("Input.insertText", { text: key });
9332
10043
  }
9333
10044
  }
10045
+ async function lastKeyPainted(cdp, objectId) {
10046
+ try {
10047
+ const drawn = evaluatedValue(await cdp.send("Runtime.callFunctionOn", {
10048
+ objectId,
10049
+ functionDeclaration: `function () { const w = this.ownerDocument.defaultView; return new Promise((r) => { const t = w.setTimeout(() => r(false), ${ACT_CEILING_MS}); w.requestAnimationFrame(() => w.requestAnimationFrame(() => { w.clearTimeout(t); r(true); })); }); }`,
10050
+ awaitPromise: true,
10051
+ returnByValue: true
10052
+ }));
10053
+ if (drawn === true)
10054
+ return null;
10055
+ if (drawn === false) {
10056
+ return `the page drew no frame within ${ACT_CEILING_MS} ms of the last key`;
10057
+ }
10058
+ return "the paint check answered with nothing readable";
10059
+ } catch (error) {
10060
+ const message2 = error instanceof Error ? error.message : String(error);
10061
+ if (DOCUMENT_GONE.test(message2))
10062
+ return null;
10063
+ return `the paint check failed (${message2})`;
10064
+ }
10065
+ }
10066
+ var DOCUMENT_GONE = /Execution context was destroyed|Cannot find context with specified id|Could not find object with given id|Inspected target navigated or closed/;
9334
10067
  function blankCounters(viewport, total) {
9335
10068
  return {
9336
10069
  actions: total,
@@ -9693,6 +10426,11 @@ function createAuthoredRun(script, deps, viewport) {
9693
10426
  // where the walk's own measurement says the target is.
9694
10427
  segment: VERBS[action.kind].cursorTravels ? segmentTo(cursor2, anchor2.fingerprint.boundingRect, action.kind === "click" ? action.at : void 0, segments, previousActionId, action.id) : void 0,
9695
10428
  text: step.do === "type" ? step.text : null,
10429
+ ...step.do === "type" ? {
10430
+ onLastKeyUnpainted: (why2) => {
10431
+ record.lastKeyPaint = { unconfirmed: why2 };
10432
+ }
10433
+ } : {},
9696
10434
  // Never read for a credential field: its value is kept nowhere.
9697
10435
  ...step.do === "type" && record.textHidden === null ? {
9698
10436
  onFieldRead: (read2) => {
@@ -10398,6 +11136,7 @@ function toStepReport(step) {
10398
11136
  ...step.waitSaw === void 0 ? {} : { waitSaw: step.waitSaw },
10399
11137
  ...step.fieldHolds === void 0 ? {} : { fieldHolds: step.fieldHolds },
10400
11138
  ...step.fieldRead === void 0 ? {} : { fieldRead: step.fieldRead },
11139
+ ...step.lastKeyPaint === void 0 ? {} : { lastKeyPaint: step.lastKeyPaint },
10401
11140
  ...step.loadSeen === void 0 ? {} : { loadSeen: step.loadSeen }
10402
11141
  };
10403
11142
  }
@@ -10649,15 +11388,17 @@ function verdictLine(report) {
10649
11388
  // write-back alone does not call the take incomplete.
10650
11389
  unstored.every((w) => w.what === "session") ? "The run's video is in the library, but the site's session could not be saved back" : "The run's video is in the library, but part of its record is not"
10651
11390
  );
10652
- return `${take}: ${said2}. ${runVerdictLine(report)}${framesClause(report)}${lookClause(report)}${otherRepoClause(report)}`;
11391
+ const intact = unstored.every((w) => w.what === "session") && framesClause(report) === "";
11392
+ return `${take}: ${said2}. ${runVerdictLine(report)}${framesClause(report)}${screensClause(report, intact)}${lookClause(report)}${otherRepoClause(report)}`;
10653
11393
  }
10654
- return `${runVerdictLine(report)}${framesClause(report)}${lookClause(report)}${otherRepoClause(report)}`;
11394
+ return `${runVerdictLine(report)}${framesClause(report)}${screensClause(report, framesClause(report) === "")}${lookClause(report)}${otherRepoClause(report)}`;
10655
11395
  }
10656
11396
  function prVerdict(report) {
10657
11397
  const n = report.steps.length;
10658
11398
  const clean = `matches all ${n} step${n === 1 ? "" : "s"}`;
10659
11399
  const clause = prClause(report, clean);
10660
- return { clause, details: clause === clean ? null : verdictLine(report) };
11400
+ const quiet = clause === clean && screensClause(report, true) === "";
11401
+ return { clause, details: quiet ? null : verdictLine(report) };
10661
11402
  }
10662
11403
  function stoppedWhere(at2) {
10663
11404
  return at2.scriptStep != null && at2.scriptSteps != null ? `at script step ${at2.scriptStep} of ${at2.scriptSteps}` : `after step ${at2.index ?? "?"} of ${at2.of ?? "?"}`;
@@ -10679,7 +11420,7 @@ function prClause(report, clean) {
10679
11420
  const k = report.verdict.diverged.length;
10680
11421
  return `${k} step${k === 1 ? "" : "s"} not shown as scripted`;
10681
11422
  }
10682
- const noted = sessionOnly || report.frames.degradations.length > 0 || report.frames.storageRefused || (report.look?.brandKitError ?? null) !== null || (report.look?.wallpaperError ?? null) !== null;
11423
+ const noted = sessionOnly || report.frames.degradations.some((k) => !SCREENS_ONLY.has(k)) || report.frames.storageRefused || (report.look?.brandKitError ?? null) !== null || (report.look?.wallpaperError ?? null) !== null;
10683
11424
  return noted ? `${clean}, with notes` : clean;
10684
11425
  }
10685
11426
  var DEGRADATION_WORDS = {
@@ -10702,7 +11443,11 @@ var DEGRADATION_WORDS = {
10702
11443
  motionReclaimed: "motion was reclaimed to free storage",
10703
11444
  pacingUnplaced: "a pause could not be placed on its step",
10704
11445
  notDragged: "a drag reached the page and changed nothing on screen, so the page may not take drags this way",
10705
- dragPictureMissing: "a native drag's picture could not be drawn, so the dragged item jumps to its drop in the video instead of travelling"
11446
+ dragPictureMissing: "a native drag's picture could not be drawn, so the dragged item jumps to its drop in the video instead of travelling",
11447
+ stepUnsettled: "a step's page had not settled when the next began, so refresh cannot compare that screen",
11448
+ stepSettleFailed: "a step's settle or page screen failed on this machine (a paint that never came, a probe or capture that failed), so refresh cannot compare that screen",
11449
+ pageHoldNotReleased: "a page screen's hold could not be undone, so the video after that step may show no caret and frozen animations",
11450
+ requestNotWaited: `a request opened more than ${STEP_REQUEST_CAP_MS / 1e3} seconds before a step's wait began (a long poll, say) was not waited for, so that step's page screen may have been taken before it answered`
10706
11451
  };
10707
11452
  function otherRepoClause(report) {
10708
11453
  const said2 = report.videoVersion?.otherRepo;
@@ -10712,13 +11457,23 @@ function lookClause(report) {
10712
11457
  return [report.look?.brandKitError, report.look?.wallpaperError].map((error) => error == null ? "" : ` ${error}.`).join("");
10713
11458
  }
10714
11459
  function framesClause(report) {
10715
- const kinds = [...new Set(report.frames.degradations)];
11460
+ const kinds = [...new Set(report.frames.degradations)].filter((k) => !SCREENS_ONLY.has(k));
10716
11461
  const said2 = kinds.map((kind) => `${DEGRADATION_WORDS[kind]} (${kind})`);
10717
11462
  if (report.frames.storageRefused) {
10718
11463
  said2.push("the frame store refused frames during the run (storageRefused)");
10719
11464
  }
10720
11465
  return said2.length === 0 ? "" : ` But not everything was kept: ${said2.join("; ")}.`;
10721
11466
  }
11467
+ var SCREENS_ONLY = /* @__PURE__ */ new Set([
11468
+ "stepUnsettled",
11469
+ "stepSettleFailed",
11470
+ "requestNotWaited"
11471
+ ]);
11472
+ function screensClause(report, intact) {
11473
+ const kinds = [...new Set(report.frames.degradations)].filter((k) => SCREENS_ONLY.has(k));
11474
+ const said2 = kinds.map((kind) => `${DEGRADATION_WORDS[kind]} (${kind})`);
11475
+ return said2.length === 0 ? "" : intact ? ` The video is intact, but for refresh: ${said2.join("; ")}.` : ` For refresh: ${said2.join("; ")}.`;
11476
+ }
10722
11477
  function runVerdictLine(report) {
10723
11478
  const line2 = runOutcomeLine(report);
10724
11479
  const opening = report.opening;
@@ -10769,72 +11524,43 @@ function whyStopped(report) {
10769
11524
  }
10770
11525
 
10771
11526
  // ../../packages/run-core/dist/kept/receipt.js
10772
- var RECEIPT_VERSION = 2;
11527
+ var RECEIPT_VERSION = 3;
10773
11528
  var RECEIPT_DIR = ".demoman/receipts";
10774
11529
  function screensDirOf(receiptFile) {
10775
11530
  const base = receiptFile.split(/[\\/]/).pop() ?? receiptFile;
10776
11531
  return `${base.replace(/\.json$/, "")}.screens`;
10777
11532
  }
10778
- var isWholePixels = (v) => Number.isInteger(v) && v > 0;
10779
- var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
10780
- function parseScreens(sc, at2) {
11533
+ var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
11534
+ function parsePageScreens(sc, at2) {
10781
11535
  const bad = (what) => ({ ok: false, detail: what });
10782
- if (!isObj2(sc))
11536
+ if (!isObj3(sc))
10783
11537
  return bad(`${at2} is not an object`);
10784
- if (!Number.isInteger(sc.steps) || sc.steps < 0)
11538
+ const { steps: steps3 } = sc;
11539
+ if (!Number.isInteger(steps3) || steps3 < 0)
10785
11540
  return bad(`${at2}.steps must be a whole number of steps`);
10786
- if (!Array.isArray(sc.moments) || sc.moments.length === 0)
10787
- return bad(`${at2}.moments must list at least one still screen`);
10788
- const moments = [];
11541
+ if (!Array.isArray(sc.screens) || sc.screens.length === 0)
11542
+ return bad(`${at2}.screens must list at least one screen`);
11543
+ const screens = [];
10789
11544
  const seen = /* @__PURE__ */ new Set();
10790
- for (const [i, m] of sc.moments.entries()) {
10791
- const mAt = `${at2}.moments[${i}]`;
10792
- if (!isObj2(m))
10793
- return bad(`${mAt} is not an object`);
10794
- if (typeof m.ms !== "number" || !Number.isFinite(m.ms) || m.ms < 0)
10795
- return bad(`${mAt}.ms must be a non-negative number`);
10796
- if (m.ms <= (moments[i - 1]?.ms ?? -1))
10797
- return bad(`${mAt}.ms must be greater than the one before it`);
10798
- if (m.step !== null) {
10799
- if (!Number.isInteger(m.step) || m.step < 0)
10800
- return bad(`${mAt}.step must be null or a whole step number`);
10801
- if (m.step >= sc.steps)
10802
- return bad(`${mAt}.step ${m.step} is not below ${at2}.steps ${sc.steps}`);
10803
- if (seen.has(m.step))
10804
- return bad(`${mAt}.step ${m.step} is named by an earlier moment`);
10805
- seen.add(m.step);
11545
+ for (const [i, s] of sc.screens.entries()) {
11546
+ const sAt = `${at2}.screens[${i}]`;
11547
+ if (!isObj3(s))
11548
+ return bad(`${sAt} is not an object`);
11549
+ if (s.step !== null) {
11550
+ if (!Number.isInteger(s.step) || s.step < 0)
11551
+ return bad(`${sAt}.step must be null or a whole step number`);
11552
+ if (s.step >= steps3)
11553
+ return bad(`${sAt}.step ${s.step} is not below ${at2}.steps ${steps3}`);
11554
+ if (seen.has(s.step))
11555
+ return bad(`${sAt}.step ${s.step} is named by an earlier screen`);
10806
11556
  } else if (seen.has(null))
10807
- return bad(`${mAt}.step is a second final screen`);
10808
- else
10809
- seen.add(null);
10810
- const w = m.window;
10811
- if (w !== void 0) {
10812
- if (!isObj2(w))
10813
- return bad(`${mAt}.window is not an object`);
10814
- for (const [key, least] of [
10815
- ["x", null],
10816
- ["y", null],
10817
- ["width", "positive"],
10818
- ["height", "positive"],
10819
- ["radius", "0 or more"]
10820
- ]) {
10821
- const v = w[key];
10822
- if (typeof v !== "number" || !Number.isFinite(v) || least === "positive" && v <= 0 || least === "0 or more" && v < 0)
10823
- return bad(`${mAt}.window.${key} must be a finite number${least === null ? "" : `, ${least}`}`);
10824
- }
10825
- }
10826
- moments.push({
10827
- step: m.step,
10828
- ms: m.ms,
10829
- ...isObj2(w) ? {
10830
- window: {
10831
- x: w.x,
10832
- y: w.y,
10833
- width: w.width,
10834
- height: w.height,
10835
- radius: w.radius
10836
- }
10837
- } : {}
11557
+ return bad(`${sAt}.step is a second final screen`);
11558
+ seen.add(s.step);
11559
+ if (s.unsettled !== void 0 && (typeof s.unsettled !== "string" || s.unsettled === ""))
11560
+ return bad(`${sAt}.unsettled must be a non-empty string`);
11561
+ screens.push({
11562
+ step: s.step,
11563
+ ...s.unsettled === void 0 ? {} : { unsettled: s.unsettled }
10838
11564
  });
10839
11565
  }
10840
11566
  if (sc.look !== void 0 && (typeof sc.look !== "string" || sc.look === ""))
@@ -10842,8 +11568,8 @@ function parseScreens(sc, at2) {
10842
11568
  return {
10843
11569
  ok: true,
10844
11570
  screens: {
10845
- steps: sc.steps,
10846
- moments,
11571
+ steps: steps3,
11572
+ screens,
10847
11573
  ...typeof sc.look === "string" ? { look: sc.look } : {}
10848
11574
  }
10849
11575
  };
@@ -10859,11 +11585,11 @@ function parseReceipt(text2, file) {
10859
11585
  } catch (e) {
10860
11586
  return bad(`is not valid JSON (${e instanceof Error ? e.message : e})`);
10861
11587
  }
10862
- if (!isObj2(raw))
11588
+ if (!isObj3(raw))
10863
11589
  return bad("is not a JSON object");
10864
- if (raw.receiptVersion !== 1 && raw.receiptVersion !== 2)
10865
- return bad(unreadVersion("receiptVersion", raw.receiptVersion, [1, 2]));
10866
- const receiptVersion = raw.receiptVersion === 2 ? 2 : 1;
11590
+ const receiptVersion = raw.receiptVersion;
11591
+ if (receiptVersion !== 1 && receiptVersion !== 2 && receiptVersion !== 3)
11592
+ return bad(unreadVersion("receiptVersion", receiptVersion, [1, 2, 3]));
10867
11593
  if (typeof raw.flow !== "string" || !isFlowId(raw.flow))
10868
11594
  return bad("flow must be a flow id");
10869
11595
  if (typeof raw.video !== "string" || raw.video === "")
@@ -10877,22 +11603,21 @@ function parseReceipt(text2, file) {
10877
11603
  const recordedRevision = raw.recordedRevision;
10878
11604
  if (recordedRevision !== null && typeof recordedRevision !== "string")
10879
11605
  return bad("recordedRevision must be a string or null");
10880
- const screens = parseScreens(raw.screens, "screens");
10881
- if (!screens.ok)
10882
- return bad(screens.detail);
11606
+ let screens = null;
11607
+ if (receiptVersion === 3) {
11608
+ const sc = parsePageScreens(raw.screens, "screens");
11609
+ if (!sc.ok)
11610
+ return bad(sc.detail);
11611
+ screens = sc.screens;
11612
+ }
10883
11613
  let screensDir = null;
10884
- let screensSize = null;
10885
- if (receiptVersion === 2) {
11614
+ if (receiptVersion !== 1) {
10886
11615
  const dir = raw.screensDir;
10887
11616
  if (typeof dir !== "string" || dir === "" || dir.startsWith("/") || dir.split(/[\\/]/).includes(".."))
10888
11617
  return bad("screensDir must be a folder beside the receipt");
10889
- const size = raw.screensSize;
10890
- if (!isObj2(size) || !isWholePixels(size.width) || !isWholePixels(size.height))
10891
- return bad("screensSize must be { width, height } in whole pixels");
10892
11618
  screensDir = dir;
10893
- screensSize = { width: size.width, height: size.height };
10894
- } else if (raw.screensDir !== void 0 || raw.screensSize !== void 0)
10895
- return bad("screensDir needs receiptVersion 2");
11619
+ } else if (raw.screensDir !== void 0)
11620
+ return bad("screensDir needs receiptVersion 2 or 3");
10896
11621
  const digest = raw.scriptDigest;
10897
11622
  if (digest !== void 0 && (typeof digest !== "string" || digest === ""))
10898
11623
  return bad("scriptDigest must be a non-empty string");
@@ -10907,21 +11632,19 @@ function parseReceipt(text2, file) {
10907
11632
  video: raw.video,
10908
11633
  filmedAt,
10909
11634
  filmedCode,
10910
- screens: screens.screens,
11635
+ screens,
10911
11636
  recordedRevision,
10912
11637
  screensDir,
10913
- screensSize,
10914
11638
  ...digest === void 0 ? {} : { scriptDigest: digest },
10915
11639
  ...pinned === void 0 ? {} : { pinnedNow: pinned }
10916
11640
  }
10917
11641
  };
10918
11642
  }
10919
11643
  function serializeReceipt(r) {
10920
- if (r.screensDir === null !== (r.screensSize === null))
10921
- throw new Error("a receipt names its screen folder and size together, or neither");
11644
+ if (r.screens === null || r.screensDir === null)
11645
+ throw new Error(`the receipt of video ${r.video} predates page screens, so it is not written again; the next refresh records it again and replaces it`);
10922
11646
  const ordered = {
10923
- // Version 2 only when it names a folder, so no receipt names one nobody wrote.
10924
- receiptVersion: r.screensDir === null ? 1 : RECEIPT_VERSION,
11647
+ receiptVersion: RECEIPT_VERSION,
10925
11648
  flow: r.flow,
10926
11649
  video: r.video,
10927
11650
  filmedAt: r.filmedAt,
@@ -10929,22 +11652,13 @@ function serializeReceipt(r) {
10929
11652
  recordedRevision: r.recordedRevision,
10930
11653
  ...r.scriptDigest === void 0 ? {} : { scriptDigest: r.scriptDigest },
10931
11654
  ...r.pinnedNow === void 0 ? {} : { pinnedNow: r.pinnedNow },
10932
- ...r.screensDir === null || r.screensSize === null ? {} : { screensDir: r.screensDir, screensSize: r.screensSize },
10933
- // `window` and `look` only when recorded, as the recipe once wrote them.
11655
+ screensDir: r.screensDir,
11656
+ // `unsettled` and `look` only when recorded.
10934
11657
  screens: {
10935
11658
  steps: r.screens.steps,
10936
- moments: r.screens.moments.map((m) => ({
10937
- step: m.step,
10938
- ms: m.ms,
10939
- ...m.window === void 0 ? {} : {
10940
- window: {
10941
- x: m.window.x,
10942
- y: m.window.y,
10943
- width: m.window.width,
10944
- height: m.window.height,
10945
- radius: m.window.radius
10946
- }
10947
- }
11659
+ screens: r.screens.screens.map((s) => ({
11660
+ step: s.step,
11661
+ ...s.unsettled === void 0 ? {} : { unsettled: s.unsettled }
10948
11662
  })),
10949
11663
  ...r.screens.look === void 0 ? {} : { look: r.screens.look }
10950
11664
  }
@@ -10953,164 +11667,6 @@ function serializeReceipt(r) {
10953
11667
  `;
10954
11668
  }
10955
11669
 
10956
- // ../../packages/run-core/dist/kept/file.js
10957
- var KEPT_VERSION = 2;
10958
- var KEPT_V1 = 1;
10959
- var FLOWS_DIR = ".demoman/flows";
10960
- var LEGACY_FLOWS_DIR = ".demoman/videos";
10961
- function judgedOutput(outputs) {
10962
- const wide = (o) => o.aspect !== "9:16";
10963
- const mp4 = (o) => o.fileType === "mp4";
10964
- for (const pick of [
10965
- (o) => wide(o) && mp4(o),
10966
- wide,
10967
- mp4,
10968
- () => true
10969
- ]) {
10970
- const i = outputs.findIndex(pick);
10971
- if (i >= 0)
10972
- return i;
10973
- }
10974
- return 0;
10975
- }
10976
- var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
10977
- var repoRelative = (p) => typeof p === "string" && p !== "" && !p.startsWith("/") && !/^[A-Za-z]:/.test(p) && !p.includes("\\") && !p.split("/").includes("..");
10978
- var bareName = (p) => repoRelative(p) && !p.includes("/");
10979
- function parseKept(text2, file) {
10980
- const bad = (what) => ({
10981
- ok: false,
10982
- detail: `${file}: ${what}`
10983
- });
10984
- let raw;
10985
- try {
10986
- raw = JSON.parse(text2);
10987
- } catch (e) {
10988
- return bad(`is not valid JSON (${e instanceof Error ? e.message : e})`);
10989
- }
10990
- if (!isObj3(raw))
10991
- return bad("is not a JSON object");
10992
- const v1 = raw.keptVersion === KEPT_V1;
10993
- if (!v1 && raw.keptVersion !== KEPT_VERSION)
10994
- return bad(unreadVersion("keptVersion", raw.keptVersion, [KEPT_V1, KEPT_VERSION]));
10995
- if (typeof raw.name !== "string" || raw.name === "")
10996
- return bad("name must be a non-empty string");
10997
- const script = DemoScriptSchema.safeParse(raw.script);
10998
- if (!script.success) {
10999
- const i = script.error.issues[0];
11000
- return bad(`script.${(i?.path ?? []).join(".")}: ${i?.message ?? "refused by the script schema"}`);
11001
- }
11002
- if (typeof raw.scale !== "number" || !(raw.scale > 0))
11003
- return bad("scale must be a positive number");
11004
- if (raw.logo !== null && !repoRelative(raw.logo))
11005
- return bad("logo must be null or a repo-relative path without ..");
11006
- const wallpaper = raw.wallpaper ?? null;
11007
- if (wallpaper !== null && !repoRelative(wallpaper))
11008
- return bad("wallpaper must be null or a repo-relative path without ..");
11009
- const deliver2 = v1 ? "commit" : raw.deliver;
11010
- if (deliver2 !== "commit" && deliver2 !== "files")
11011
- return bad('deliver must be "commit" or "files"');
11012
- const pathOk = deliver2 === "files" ? bareName : repoRelative;
11013
- const pathRule = deliver2 === "files" ? "a bare file name (no /, no ..)" : "repo-relative, posix, without ..";
11014
- if (raw.report !== null && !pathOk(raw.report))
11015
- return bad(`report must be null or ${pathRule}`);
11016
- let flow;
11017
- if (v1) {
11018
- const f = raw.from;
11019
- if (!isObj3(f) || typeof f.videoId !== "string" || typeof f.takeId !== "string" || typeof f.recordedRevision !== "string")
11020
- return bad("from needs string videoId, takeId and recordedRevision");
11021
- if (!isFlowId(f.videoId))
11022
- return bad(`from.videoId ${JSON.stringify(f.videoId)} is not a flow id`);
11023
- flow = f.videoId;
11024
- } else {
11025
- if (typeof raw.flow !== "string" || !isFlowId(raw.flow))
11026
- return bad(`flow ${JSON.stringify(raw.flow)} is not a flow id`);
11027
- flow = raw.flow;
11028
- }
11029
- if (!Array.isArray(raw.outputs) || raw.outputs.length === 0)
11030
- return bad("outputs must list at least one output");
11031
- const outputs = [];
11032
- for (const [i, o] of raw.outputs.entries()) {
11033
- if (!isObj3(o))
11034
- return bad(`outputs[${i}] is not an object`);
11035
- if (!pathOk(o.path))
11036
- return bad(`outputs[${i}].path must be ${pathRule}; got ${JSON.stringify(o.path)}`);
11037
- if (o.fileType !== "mp4" && o.fileType !== "gif")
11038
- return bad(`outputs[${i}].fileType must be "mp4" or "gif"`);
11039
- if (o.aspect !== "auto" && o.aspect !== "16:9" && o.aspect !== "9:16")
11040
- return bad(`outputs[${i}].aspect must be "auto", "16:9" or "9:16"`);
11041
- if (!EXPORT_QUALITY_VALUES.includes(o.quality))
11042
- return bad(`outputs[${i}].quality must be one of ${EXPORT_QUALITY_VALUES.join(", ")}`);
11043
- outputs.push({
11044
- path: o.path,
11045
- fileType: o.fileType,
11046
- aspect: o.aspect,
11047
- quality: o.quality
11048
- });
11049
- }
11050
- let migrated = null;
11051
- if (v1) {
11052
- if (!isObj3(raw.screens))
11053
- return bad(`${raw.name} has no screens \u2014 it was kept before they were recorded; run \`demoman add ${raw.name}\` again to record them`);
11054
- const sc = parseScreens(raw.screens, "screens");
11055
- if (!sc.ok)
11056
- return bad(sc.detail);
11057
- const f = raw.from;
11058
- migrated = {
11059
- receiptVersion: 1,
11060
- screensDir: null,
11061
- screensSize: null,
11062
- flow,
11063
- video: f.takeId,
11064
- filmedAt: null,
11065
- filmedCode: { none: "kept before receipts were recorded" },
11066
- screens: sc.screens,
11067
- recordedRevision: f.recordedRevision
11068
- };
11069
- }
11070
- return {
11071
- ok: true,
11072
- kept: {
11073
- keptVersion: KEPT_VERSION,
11074
- flow,
11075
- name: raw.name,
11076
- script: script.data,
11077
- scale: raw.scale,
11078
- logo: raw.logo,
11079
- wallpaper,
11080
- deliver: deliver2,
11081
- outputs,
11082
- report: raw.report
11083
- },
11084
- migrated
11085
- };
11086
- }
11087
- var videoSlug = (name) => name.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "") || "video";
11088
- function keptFileName(name) {
11089
- return `${videoSlug(name)}.json`;
11090
- }
11091
- function serializeKept(k) {
11092
- const ordered = {
11093
- keptVersion: k.keptVersion,
11094
- flow: k.flow,
11095
- name: k.name,
11096
- script: k.script,
11097
- scale: k.scale,
11098
- logo: k.logo,
11099
- // Only when there is one: a file kept before wallpapers reads the same.
11100
- ...k.wallpaper === null ? {} : { wallpaper: k.wallpaper },
11101
- deliver: k.deliver,
11102
- outputs: k.outputs.map((o) => ({
11103
- path: o.path,
11104
- fileType: o.fileType,
11105
- aspect: o.aspect,
11106
- quality: o.quality
11107
- })),
11108
- report: k.report
11109
- };
11110
- return `${JSON.stringify(ordered, null, 2)}
11111
- `;
11112
- }
11113
-
11114
11670
  // ../../packages/run-core/dist/logo-file.js
11115
11671
  var LOGO_MAX_BYTES = 2 * 1024 * 1024;
11116
11672
  var ACCEPTED = /* @__PURE__ */ new Set([
@@ -13622,7 +14178,7 @@ import { randomBytes as randomBytes2 } from "node:crypto";
13622
14178
  import { connect } from "node:net";
13623
14179
  import { setTimeout as delay } from "node:timers/promises";
13624
14180
  var MAX_NOW_AGE_DAYS = 7;
13625
- var POLL_MS = 250;
14181
+ var POLL_MS2 = 250;
13626
14182
  var PROBE_MS = 2e3;
13627
14183
  var KILL_WAIT_MS = 5e3;
13628
14184
  var DRAIN_MS = 500;
@@ -13850,7 +14406,7 @@ ${tail}`}`
13850
14406
  if (status === "unhealthy" || d.now() >= deadline2) {
13851
14407
  return refuse6("appServiceFailed", `the ${service} service (${s.image}) did not become healthy within ${app.timeoutSeconds} s (last health: ${status || h.stderr.trim() || "unknown"}); check its health command in ${APP_FILE}, then run again`, h.stderr);
13852
14408
  }
13853
- await d.sleep(POLL_MS);
14409
+ await d.sleep(POLL_MS2);
13854
14410
  }
13855
14411
  }
13856
14412
  }
@@ -13879,7 +14435,7 @@ ${tail}`}`
13879
14435
  if (d.now() >= deadline) {
13880
14436
  return refuse6("appNeverAnswered", `nothing answered at ${app.url} within ${app.timeoutSeconds} s of \`${app.start}\`${ex ? " (it exited with code 0)" : ""}; check the URL and timeoutSeconds in ${APP_FILE}, then run again`, started.output());
13881
14437
  }
13882
- await (ex ? d.sleep(POLL_MS) : Promise.race([d.sleep(POLL_MS), started.exited]));
14438
+ await (ex ? d.sleep(POLL_MS2) : Promise.race([d.sleep(POLL_MS2), started.exited]));
13883
14439
  }
13884
14440
  return {
13885
14441
  reused: false,
@@ -14807,11 +15363,13 @@ function pageCapture(page2, log2) {
14807
15363
  return e.captureHere(i);
14808
15364
  }, [EXECUTOR_ENTRY_GLOBAL, intent, NO_ENTRY]), "a step's capture");
14809
15365
  } catch (error) {
15366
+ if (page2.isClosed())
15367
+ throw error;
14810
15368
  const said2 = messageOf(error);
14811
15369
  const at2 = page2.url();
14812
15370
  const pageUrl = scrubUrl(at2);
14813
15371
  const here = pageKey(at2);
14814
- if (isNavigationRace(error) && !page2.isClosed()) {
15372
+ if (isNavigationRace(error)) {
14815
15373
  log2(`a step's capture met a navigation, looking again \u2014 ${said2}`);
14816
15374
  return {
14817
15375
  anchor: null,
@@ -15548,7 +16106,7 @@ async function releaseIfMine(path, text2) {
15548
16106
  // ../runner/dist/executor/account-signin.js
15549
16107
  var SIGN_IN_DEADLINE_MS = 6e4;
15550
16108
  var LOCK_WAIT_MS = 12e4;
15551
- var POLL_MS2 = 200;
16109
+ var POLL_MS3 = 200;
15552
16110
  var LOCK_POLL_MS = 250;
15553
16111
  var STEP_WAIT_MS = 1e4;
15554
16112
  function describeStep(step) {
@@ -15586,7 +16144,7 @@ async function mark(page2, target, id, want, until) {
15586
16144
  if (want === "visible" ? shown2 : !shown2)
15587
16145
  return;
15588
16146
  last = answer2.found ? "found but not shown" : answer2.why ?? "not found";
15589
- await wait(POLL_MS2);
16147
+ await wait(POLL_MS3);
15590
16148
  }
15591
16149
  throw new StepFailed("signInFailed", want === "visible" ? `its element never appeared (${last})` : "its element never went away");
15592
16150
  }
@@ -15604,10 +16162,15 @@ async function runSteps(page2, steps3, origin, resolve10, until, nav) {
15604
16162
  nav.loaded = 0;
15605
16163
  nav.failed = 0;
15606
16164
  }
16165
+ const pathNow = () => {
16166
+ if (i === lastAction)
16167
+ nav.pathBefore = originAndPath(page2.url());
16168
+ };
15607
16169
  const stepUntil = Math.min(until, Date.now() + STEP_WAIT_MS);
15608
16170
  try {
15609
16171
  switch (step.do) {
15610
16172
  case "goto":
16173
+ pathNow();
15611
16174
  await page2.goto(step.url, { waitUntil: "load", timeout: left() });
15612
16175
  break;
15613
16176
  case "waitForLoad":
@@ -15621,6 +16184,7 @@ async function runSteps(page2, steps3, origin, resolve10, until, nav) {
15621
16184
  break;
15622
16185
  case "click":
15623
16186
  await mark(page2, step.on, String(i), "visible", stepUntil);
16187
+ pathNow();
15624
16188
  await page2.locator(`[${SIGN_IN_MARK}="${i}"]`).click({ timeout: left() });
15625
16189
  break;
15626
16190
  case "type": {
@@ -15632,6 +16196,7 @@ async function runSteps(page2, steps3, origin, resolve10, until, nav) {
15632
16196
  if (here !== origin && /\{secret:/.test(step.text)) {
15633
16197
  throw new StepFailed("secretOffOrigin", here === null ? `the field's page could not be told, so the secret was not typed \u2014 a sign-in never types a secret off its own site` : `the page is on ${here}, not ${origin}, so the secret was not typed \u2014 a sign-in never types a secret off its own site`);
15634
16198
  }
16199
+ pathNow();
15635
16200
  await handle.fill(resolve10(step.text), { timeout: left() });
15636
16201
  } finally {
15637
16202
  await handle.dispose().catch(() => void 0);
@@ -15779,7 +16344,7 @@ async function signInAccount(chosen, deps) {
15779
16344
  } catch (error) {
15780
16345
  return fail("signInFailed", `signing in as ${name} on ${origin}: ${account.checkUrl} (checkUrl) could not be opened signed out (${messageOf(error)})`);
15781
16346
  }
15782
- const nav = { documents: 0, loaded: 0, failed: 0 };
16347
+ const nav = { documents: 0, loaded: 0, failed: 0, pathBefore: "" };
15783
16348
  const mainNavigation = (request2) => request2.isNavigationRequest() && request2.frame() === page2.mainFrame();
15784
16349
  page2.on("request", (request2) => {
15785
16350
  if (mainNavigation(request2))
@@ -15812,14 +16377,13 @@ async function signInAccount(chosen, deps) {
15812
16377
  };
15813
16378
  try {
15814
16379
  const navUntil = Math.min(deadline, Date.now() + STEP_WAIT_MS);
15815
- const pathBefore = originAndPath(page2.url());
15816
16380
  let signedInPlace = false;
15817
16381
  let lastLook = 0;
15818
16382
  while (nav.documents === 0 && Date.now() < navUntil) {
15819
16383
  if (Date.now() - lastLook >= 250) {
15820
16384
  lastLook = Date.now();
15821
16385
  const facts2 = await readLandingFacts(page2, page2.url()).catch(() => null);
15822
- if (facts2 !== null && !facts2.passwordFieldVisible && originAndPath(facts2.landedUrl) !== pathBefore) {
16386
+ if (facts2 !== null && !facts2.passwordFieldVisible && originAndPath(facts2.landedUrl) !== nav.pathBefore) {
15823
16387
  signedInPlace = true;
15824
16388
  break;
15825
16389
  }
@@ -15899,12 +16463,17 @@ async function signInAccount(chosen, deps) {
15899
16463
  import { randomUUID as randomUUID3 } from "node:crypto";
15900
16464
  import { copyFile as copyFile2, mkdir as mkdir5, rm as rm6, writeFile as writeFile5 } from "node:fs/promises";
15901
16465
  import { tmpdir as tmpdir3 } from "node:os";
15902
- import { basename as basename3, join as join17 } from "node:path";
16466
+ import { basename as basename3, join as join16 } from "node:path";
15903
16467
 
15904
16468
  // ../runner/dist/executor/export.js
15905
16469
  import { randomUUID as randomUUID2 } from "node:crypto";
15906
16470
  import { stat as stat5 } from "node:fs/promises";
15907
- import { join as join16 } from "node:path";
16471
+ import { join as join15 } from "node:path";
16472
+
16473
+ // ../../packages/run-core/dist/render/output.js
16474
+ function screenImageName(step) {
16475
+ return step === null ? "final.png" : `step-${step}.png`;
16476
+ }
15908
16477
 
15909
16478
  // ../runner/dist/render.js
15910
16479
  import { createServer } from "node:http";
@@ -16029,7 +16598,7 @@ function createRenderServer(store, allowed) {
16029
16598
  });
16030
16599
  }
16031
16600
  async function renderToFiles(input) {
16032
- const { scene, bundle, store, page: page2, target, fileType, logo, wallpaper, onFrame, gifBudget, mp4Cap, stills, outputTimesMs, screensOnly, times } = input;
16601
+ const { scene, bundle, store, page: page2, target, fileType, logo, wallpaper, onFrame, gifBudget, mp4Cap, stills, outputTimesMs, times } = input;
16033
16602
  const stamped = {
16034
16603
  ...scene,
16035
16604
  meta: {
@@ -16070,8 +16639,7 @@ async function renderToFiles(input) {
16070
16639
  ...gifBudget === void 0 ? {} : { gifBudget },
16071
16640
  ...mp4Cap === void 0 ? {} : { mp4Cap },
16072
16641
  ...stills === void 0 ? {} : { stills },
16073
- ...outputTimesMs === void 0 ? {} : { outputTimesMs },
16074
- ...screensOnly === void 0 ? {} : { screensOnly }
16642
+ ...outputTimesMs === void 0 ? {} : { outputTimesMs }
16075
16643
  });
16076
16644
  times?.mark("render");
16077
16645
  const { renderMs, framesMs, frameReads, sink } = facts.timing;
@@ -16139,11 +16707,11 @@ function stageTimes(now = () => performance.now()) {
16139
16707
  let last = start;
16140
16708
  const stages = [];
16141
16709
  const notes = [];
16142
- const secs2 = (ms) => `${(ms / 1e3).toFixed(2)}s`;
16710
+ const secs = (ms) => `${(ms / 1e3).toFixed(2)}s`;
16143
16711
  return {
16144
16712
  mark(stage) {
16145
16713
  const t = now();
16146
- stages.push(`${stage} ${secs2(t - last)}`);
16714
+ stages.push(`${stage} ${secs(t - last)}`);
16147
16715
  last = t;
16148
16716
  },
16149
16717
  note(text2) {
@@ -16151,7 +16719,7 @@ function stageTimes(now = () => performance.now()) {
16151
16719
  },
16152
16720
  line(what) {
16153
16721
  const tail = notes.length > 0 ? `; ${notes.join("; ")}` : "";
16154
- return `timing ${what}: ${stages.join(", ")}; total ${secs2(last - start)}${tail}`;
16722
+ return `timing ${what}: ${stages.join(", ")}; total ${secs(last - start)}${tail}`;
16155
16723
  }
16156
16724
  };
16157
16725
  }
@@ -16488,286 +17056,10 @@ async function readLogo(home, ref) {
16488
17056
  return { ok: true, bytes: new Uint8Array(bytes), contentType: type };
16489
17057
  }
16490
17058
 
16491
- // ../runner/dist/executor/same-picture.js
16492
- import { readFile as readFile9 } from "node:fs/promises";
16493
- import { createServer as createServer2 } from "node:http";
16494
- import { join as join13 } from "node:path";
16495
- import { fileURLToPath as fileURLToPath5 } from "node:url";
16496
-
16497
- // ../../packages/run-core/dist/render/output.js
16498
- function screenImageName(step) {
16499
- return step === null ? "final.png" : `step-${step}.png`;
16500
- }
16501
-
16502
- // ../runner/dist/executor/same-picture.js
16503
- var LOOKS = [
16504
- { name: "sharply", block: 2, levels: 60, allowed: 8e-6 },
16505
- { name: "faintly", block: 8, levels: 13, allowed: 17e-5 }
16506
- ];
16507
- var WINDOW_INSET_PX = 2;
16508
- var STILL_LOOKS = LOOKS;
16509
- var PICTURE_OPTIONS = {
16510
- width: 1280,
16511
- looks: LOOKS.map(({ block, levels }) => ({ block, levels })),
16512
- inset: WINDOW_INSET_PX
16513
- };
16514
- var STILL_PICTURE_OPTIONS = {
16515
- ...PICTURE_OPTIONS,
16516
- looks: STILL_LOOKS.map(({ block, levels }) => ({ block, levels }))
16517
- };
16518
- var WINDOW_MOVED_PX = 1;
16519
- var LOOK_CHANGED = "the look changed: the background, padding or logo round the window is not the one the committed video was filmed with";
16520
- var ENTRY_PATH4 = fileURLToPath5(new URL(import.meta.url.endsWith(".ts") ? "../decode-probe-entry.ts" : "../decode-probe-entry.js", import.meta.url));
16521
- async function samePicture(committed, fresh, fileType, committedScreens, freshScreens, deps) {
16522
- if (committedScreens.steps !== freshScreens.steps) {
16523
- return {
16524
- same: false,
16525
- detail: `the video's steps changed, ${committedScreens.steps} to ${freshScreens.steps}`
16526
- };
16527
- }
16528
- if (committedScreens.look !== void 0 && freshScreens.look !== void 0 && committedScreens.look !== freshScreens.look) {
16529
- return {
16530
- same: false,
16531
- detail: LOOK_CHANGED
16532
- };
16533
- }
16534
- const shared = sharedScreens(committedScreens, freshScreens);
16535
- if (shared.length === 0)
16536
- return { uncomparable: "no screen of the video is still in both films" };
16537
- const type = fileType === "gif" ? "image/gif" : "video/mp4";
16538
- const files = /* @__PURE__ */ new Map([
16539
- ["/a", await readFile9(committed)],
16540
- ["/b", await readFile9(fresh)]
16541
- ]);
16542
- const work = await deps.session.openWorkPage();
16543
- if (!work.ok)
16544
- throw new Error(`no page to decode on: ${work.detail}`);
16545
- const server = createServer2((req, res) => {
16546
- const bytes = files.get(req.url ?? "");
16547
- if (bytes === void 0) {
16548
- res.writeHead(200, { "content-type": "text/html" });
16549
- res.end("<!doctype html><meta charset=utf-8><title>compare</title>");
16550
- return;
16551
- }
16552
- res.writeHead(200, {
16553
- "content-type": type,
16554
- "content-length": String(bytes.byteLength)
16555
- });
16556
- res.end(bytes);
16557
- });
16558
- let diff;
16559
- try {
16560
- const origin = await listenOnLoopback(server);
16561
- await work.page.goto(origin);
16562
- await work.page.addScriptTag({ content: await bundleEntry(ENTRY_PATH4) });
16563
- diff = await work.page.evaluate(([name, mime, msA, msB, windows, options]) => {
16564
- const entry = globalThis[name];
16565
- if (entry === void 0)
16566
- throw new Error(`${name} is not installed`);
16567
- return entry.screensDiff("/a", "/b", mime, msA, msB, windows, options);
16568
- }, [
16569
- DECODE_PROBE_GLOBAL,
16570
- type,
16571
- shared.map((s) => s.msA),
16572
- shared.map((s) => s.msB),
16573
- // The committed film's window: a fresh one that moved is a change
16574
- // (`comparePictures`), so either reads the same pixels.
16575
- shared.map((s) => s.windowB === void 0 ? null : s.windowA ?? null),
16576
- PICTURE_OPTIONS
16577
- ]);
16578
- } finally {
16579
- server.close();
16580
- await work.page.close().catch((error) => {
16581
- deps.log(`refresh: the comparison's page would not close (${messageOf(error)})`);
16582
- });
16583
- }
16584
- if ("unreadable" in diff) {
16585
- return {
16586
- undecodable: diff.unreadable === "a" ? "committed" : "new",
16587
- detail: diff.error
16588
- };
16589
- }
16590
- return comparePictures(diff, shared, freshScreens.steps + 1, deps.steps);
16591
- }
16592
- async function sameScreens(committed, fresh, deps) {
16593
- if (committed.screens.steps !== fresh.screens.steps) {
16594
- return {
16595
- same: false,
16596
- detail: `the video's steps changed, ${committed.screens.steps} to ${fresh.screens.steps}`
16597
- };
16598
- }
16599
- if (committed.screens.look !== void 0 && fresh.screens.look !== void 0 && committed.screens.look !== fresh.screens.look) {
16600
- return { same: false, detail: LOOK_CHANGED };
16601
- }
16602
- const shared = sharedScreens(committed.screens, fresh.screens);
16603
- if (shared.length === 0)
16604
- return { uncomparable: "no screen of the video is still in both films" };
16605
- const files = /* @__PURE__ */ new Map();
16606
- const paths = /* @__PURE__ */ new Map();
16607
- for (const [prefix, side] of [
16608
- ["/a/", committed],
16609
- ["/b/", fresh]
16610
- ]) {
16611
- for (const s of shared) {
16612
- const name = screenImageName(s.step);
16613
- const path = join13(side.dir, name);
16614
- paths.set(`${prefix}${name}`, path);
16615
- try {
16616
- files.set(`${prefix}${name}`, await readFile9(path));
16617
- } catch (error) {
16618
- return {
16619
- uncomparable: error.code === "ENOENT" ? `${path} is missing` : `${path} could not be read (${messageOf(error)})`
16620
- };
16621
- }
16622
- }
16623
- }
16624
- const urls = (prefix) => shared.map((s) => `${prefix}${screenImageName(s.step)}`);
16625
- const work = await deps.session.openWorkPage();
16626
- if (!work.ok)
16627
- throw new Error(`no page to decode on: ${work.detail}`);
16628
- const server = createServer2((req, res) => {
16629
- const bytes = files.get(req.url ?? "");
16630
- if (bytes === void 0) {
16631
- res.writeHead(200, { "content-type": "text/html" });
16632
- res.end("<!doctype html><meta charset=utf-8><title>compare</title>");
16633
- return;
16634
- }
16635
- res.writeHead(200, {
16636
- "content-type": "image/png",
16637
- "content-length": String(bytes.byteLength)
16638
- });
16639
- res.end(bytes);
16640
- });
16641
- let diff;
16642
- try {
16643
- const origin = await listenOnLoopback(server);
16644
- await work.page.goto(origin);
16645
- await work.page.addScriptTag({ content: await bundleEntry(ENTRY_PATH4) });
16646
- diff = await work.page.evaluate(([name, a, b, sizeA, sizeB, windows, options]) => {
16647
- const entry = globalThis[name];
16648
- if (entry === void 0)
16649
- throw new Error(`${name} is not installed`);
16650
- return entry.imagesDiff(a, b, sizeA, sizeB, windows, options);
16651
- }, [
16652
- DECODE_PROBE_GLOBAL,
16653
- urls("/a/"),
16654
- urls("/b/"),
16655
- committed.size,
16656
- fresh.size,
16657
- shared.map((s) => s.windowB === void 0 ? null : s.windowA ?? null),
16658
- STILL_PICTURE_OPTIONS
16659
- ]);
16660
- } finally {
16661
- server.close();
16662
- await work.page.close().catch((error) => {
16663
- deps.log(`refresh: the comparison's page would not close (${messageOf(error)})`);
16664
- });
16665
- }
16666
- if ("unreadable" in diff) {
16667
- const at2 = diff.error.indexOf(": ");
16668
- const url = diff.error.slice(0, at2);
16669
- return {
16670
- uncomparable: `${paths.get(url) ?? url} could not be read as a PNG (${diff.error.slice(at2 + 2)})`
16671
- };
16672
- }
16673
- return comparePictures(diff, shared, fresh.screens.steps + 1, deps.steps, STILL_LOOKS);
16674
- }
16675
- var secs = (ms) => `${(ms / 1e3).toFixed(2)}s`;
16676
- function scriptStep(steps3, action) {
16677
- let seen = -1;
16678
- for (const [i, step] of steps3.entries()) {
16679
- if (step.do !== "pause")
16680
- seen++;
16681
- if (seen === action)
16682
- return i;
16683
- }
16684
- return null;
16685
- }
16686
- function before(action, steps3) {
16687
- const i = steps3 === void 0 ? null : scriptStep(steps3, action);
16688
- return i === null ? `before action ${action + 1}` : `before step ${i + 1}`;
16689
- }
16690
- function sharedScreens(a, b) {
16691
- return a.moments.flatMap((m) => {
16692
- const other = b.moments.find((n) => n.step === m.step);
16693
- return other === void 0 ? [] : [
16694
- {
16695
- step: m.step,
16696
- msA: m.ms,
16697
- msB: other.ms,
16698
- ...m.window === void 0 ? {} : { windowA: m.window },
16699
- ...other.window === void 0 ? {} : { windowB: other.window }
16700
- }
16701
- ];
16702
- });
16703
- }
16704
- function comparePictures(diff, shared, total, steps3, looks = LOOKS) {
16705
- const { a, b, changed } = diff;
16706
- if (a.width !== b.width || a.height !== b.height) {
16707
- return {
16708
- same: false,
16709
- detail: `the frame size changed, ${a.width}x${a.height} to ${b.width}x${b.height}`
16710
- };
16711
- }
16712
- const k = PICTURE_OPTIONS.width / a.width;
16713
- for (const s2 of shared) {
16714
- const [wa, wb] = [s2.windowA, s2.windowB];
16715
- if (wa === void 0 || wb === void 0)
16716
- continue;
16717
- const keys = ["x", "y", "width", "height", "radius"];
16718
- if (keys.every((key) => Math.abs(wa[key] - wb[key]) * k <= WINDOW_MOVED_PX))
16719
- continue;
16720
- const place3 = s2.step === null ? "on the final screen" : before(s2.step, steps3);
16721
- return {
16722
- same: false,
16723
- // Each video's own moment beside its own window: the two reach a
16724
- // screen at different times, and one time for both sent DEM-63 to the
16725
- // wrong frame of the committed video.
16726
- detail: `the window moved ${place3}: the committed video has it at ${rectText(wa)} at ${secs(s2.msA)}, the new one at ${rectText(wb)} at ${secs(s2.msB)}`
16727
- };
16728
- }
16729
- for (const [i, shares] of changed.entries()) {
16730
- if (shares !== null)
16731
- continue;
16732
- const s2 = shared[i];
16733
- const past = s2.msA / 1e3 >= a.length;
16734
- return {
16735
- uncomparable: `the ${past ? "committed" : "new"} video ends at ${(past ? a : b).length.toFixed(3)}s, before its screen at ${((past ? s2.msA : s2.msB) / 1e3).toFixed(3)}s`
16736
- };
16737
- }
16738
- const pct = (share) => `${(share * 100).toFixed(4)}%`;
16739
- const worst = looks.map((look, j) => {
16740
- let share = 0;
16741
- let at2 = 0;
16742
- for (const [i, shares] of changed.entries()) {
16743
- const v = shares[j];
16744
- if (v > share) {
16745
- share = v;
16746
- at2 = i;
16747
- }
16748
- }
16749
- return { look, share, at: at2, over: share / look.allowed };
16750
- });
16751
- const where2 = `${shared.length} of ${total} screens`;
16752
- const most = worst.reduce((x, y) => y.over > x.over ? y : x);
16753
- if (most.over <= 1)
16754
- return {
16755
- same: true,
16756
- detail: `at most ${worst.map((w) => `${pct(w.share)} ${w.look.name}`).join(" and ")} of the picture changed, over ${where2}`
16757
- };
16758
- const s = shared[most.at];
16759
- const place2 = s.step === null ? "on the final screen" : before(s.step, steps3);
16760
- return {
16761
- same: false,
16762
- detail: `${pct(most.share)} of the picture changed ${most.look.name} ${place2} at ${secs(s.msA)} in the committed video and ${secs(s.msB)} in the new one, over the ${pct(most.look.allowed)} allowed, of ${where2}`
16763
- };
16764
- }
16765
- var rectText = (w) => `${Math.round(w.x)},${Math.round(w.y)} ${Math.round(w.width)}x${Math.round(w.height)}`;
16766
-
16767
17059
  // ../runner/dist/executor/save.js
16768
17060
  import { constants as constants2 } from "node:fs";
16769
17061
  import { access as access2, mkdir as mkdir4, rm as rm5, writeFile as writeFile4 } from "node:fs/promises";
16770
- import { basename as basename2, join as join14 } from "node:path";
17062
+ import { basename as basename2, join as join13 } from "node:path";
16771
17063
  var MAX_UNIQUIFY = 100;
16772
17064
  var code2 = (error) => error?.code;
16773
17065
  async function saveExport(dir, name, bytes) {
@@ -16784,7 +17076,7 @@ async function saveExport(dir, name, bytes) {
16784
17076
  const ext = dot === -1 ? "" : name.slice(dot);
16785
17077
  for (let n = 0; n <= MAX_UNIQUIFY; n++) {
16786
17078
  const candidate = n === 0 ? name : `${stem} (${n})${ext}`;
16787
- const path = join14(dir, candidate);
17079
+ const path = join13(dir, candidate);
16788
17080
  try {
16789
17081
  await writeFile4(path, bytes, { flag: "wx" });
16790
17082
  return { kind: "saved", downloadId: null, savedAs: candidate, path };
@@ -16827,7 +17119,7 @@ async function saveStillsFolder(dir, folderName, files, write = (path, bytes) =>
16827
17119
  }
16828
17120
  let folder = null;
16829
17121
  for (let n = 0; n <= MAX_UNIQUIFY && folder === null; n++) {
16830
- const candidate = join14(dir, n === 0 ? folderName : `${folderName} (${n})`);
17122
+ const candidate = join13(dir, n === 0 ? folderName : `${folderName} (${n})`);
16831
17123
  try {
16832
17124
  await mkdir4(candidate);
16833
17125
  folder = candidate;
@@ -16848,7 +17140,7 @@ async function saveStillsFolder(dir, folderName, files, write = (path, bytes) =>
16848
17140
  }
16849
17141
  const written = [];
16850
17142
  for (const [index, file] of files.entries()) {
16851
- const path = join14(folder, file.name);
17143
+ const path = join13(folder, file.name);
16852
17144
  try {
16853
17145
  await write(path, file.bytes);
16854
17146
  written.push(file.name);
@@ -16901,8 +17193,8 @@ async function checkExportFolder(dir) {
16901
17193
  }
16902
17194
 
16903
17195
  // ../runner/dist/executor/user-settings.js
16904
- import { readFile as readFile10 } from "node:fs/promises";
16905
- import { join as join15 } from "node:path";
17196
+ import { readFile as readFile9 } from "node:fs/promises";
17197
+ import { join as join14 } from "node:path";
16906
17198
  var settingsWith = (settings, problems) => {
16907
17199
  const said2 = [problems.exportQuality, problems.pullRequests].filter((p) => p !== void 0);
16908
17200
  if (said2.length === 0)
@@ -16910,14 +17202,14 @@ var settingsWith = (settings, problems) => {
16910
17202
  return { ...settings, problems, unreadable: [...new Set(said2)].join("; ") };
16911
17203
  };
16912
17204
  async function readUserSettings(home) {
16913
- const path = join15(home, "settings.json");
17205
+ const path = join14(home, "settings.json");
16914
17206
  const defaults = {
16915
17207
  exportQuality: DEFAULT_EXPORT_QUALITY,
16916
17208
  pullRequests: null
16917
17209
  };
16918
17210
  let text2;
16919
17211
  try {
16920
- text2 = await readFile10(path, "utf8");
17212
+ text2 = await readFile9(path, "utf8");
16921
17213
  } catch (error) {
16922
17214
  if (error.code === "ENOENT")
16923
17215
  return defaults;
@@ -17051,6 +17343,9 @@ async function exportTake(args2, deps, onProgress) {
17051
17343
  if (bundle === null) {
17052
17344
  return refused2("noFrames", `video ${takeId} has no frames to render \u2014 run its script again${videoUnread}`);
17053
17345
  }
17346
+ if (screensOnly && (bundle.pageScreens ?? []).length === 0) {
17347
+ return refused2("noFrames", `video ${takeId} has no page screens to compare: it was recorded before page screens \u2014 record it again`);
17348
+ }
17054
17349
  let lease;
17055
17350
  try {
17056
17351
  lease = await library.lease(takeId, {
@@ -17090,7 +17385,7 @@ async function exportTake(args2, deps, onProgress) {
17090
17385
  }
17091
17386
  async function sceneFileExists(library, takeId) {
17092
17387
  try {
17093
- await stat5(join16(library.takeDir(takeId), "scene.json"));
17388
+ await stat5(join15(library.takeDir(takeId), "scene.json"));
17094
17389
  return true;
17095
17390
  } catch (error) {
17096
17391
  if (error.code === "ENOENT")
@@ -17226,6 +17521,44 @@ async function exportLeased(a) {
17226
17521
  fileType: asked
17227
17522
  });
17228
17523
  }
17524
+ const look = lookDigest(scene.branding, {
17525
+ logo: logo?.ok ? fileDigest(logo.bytes) : null,
17526
+ wallpaper: wallpaper?.ok ? fileDigest(wallpaper.bytes) : null
17527
+ });
17528
+ if (screensOnly) {
17529
+ const screens = await pageScreensOf(takeId, scene, bundle, store, look);
17530
+ if ("error" in screens)
17531
+ return withSummary({
17532
+ outcome: "renderFailed",
17533
+ takeId,
17534
+ error: screens.error
17535
+ });
17536
+ const saved2 = await saveStillsFolder(deps.outDir, `${takeId} screens`, screens.files);
17537
+ if (saved2.kind === "failed") {
17538
+ return withSummary({
17539
+ outcome: "saveFailed",
17540
+ takeId,
17541
+ error: saved2.error,
17542
+ fileType: asked
17543
+ });
17544
+ }
17545
+ return {
17546
+ outcome: "saved",
17547
+ fileType: "screens",
17548
+ takeId,
17549
+ folder: { path: saved2.path },
17550
+ screens: screens.screens,
17551
+ // What the render would say of them: the look records what was read.
17552
+ warnings: {
17553
+ logo: logo === null || logo.ok ? null : `The logo was left out: ${logo.error}`,
17554
+ wallpaperWarning: wallpaper === null || wallpaper.ok ? null : {
17555
+ kind: "leftOut",
17556
+ sentence: `The wallpaper was left out: ${wallpaper.error}; the video uses the plain gradient.`
17557
+ }
17558
+ },
17559
+ summary: `Copied ${saved2.files.length} page screens of video ${takeId} into ${saved2.path}.`
17560
+ };
17561
+ }
17229
17562
  times.mark("prepare");
17230
17563
  onProgress({ outcome: "exporting", phase: "rendering", done: 0, total: 0 });
17231
17564
  const work = await deps.session.openWorkPage();
@@ -17252,10 +17585,7 @@ async function exportLeased(a) {
17252
17585
  fileType: asked,
17253
17586
  logo,
17254
17587
  wallpaper,
17255
- // Screens render at the target itself: a budget or a cap sizes a
17256
- // file, and screens make none, only images as wide as the
17257
- // comparison reads.
17258
- ...screensOnly ? { screensOnly: { width: PICTURE_OPTIONS.width } } : asked === "gif" ? (
17588
+ ...asked === "gif" ? (
17259
17589
  // As wide as fits: sharp on a Retina screen when the take is
17260
17590
  // short, narrower (and said) when it is long.
17261
17591
  { gifBudget: { maxBytes: GIF_BUDGET_BYTES } }
@@ -17263,7 +17593,7 @@ async function exportLeased(a) {
17263
17593
  // A cap steps down to the share target, then this take's 1080p share
17264
17594
  // frame (the floor), then a bitrate that fits (`capLadder`): Auto's
17265
17595
  // frames are its own, re-solved.
17266
- ...maxBytes === null || screensOnly ? {} : {
17596
+ ...maxBytes === null ? {} : {
17267
17597
  mp4Cap: {
17268
17598
  maxBytes,
17269
17599
  share: targetFor(asked, aspect, bundle, frameOf(scene), {
@@ -17305,47 +17635,6 @@ async function exportLeased(a) {
17305
17635
  }
17306
17636
  }
17307
17637
  onProgress({ outcome: "exporting", phase: "saving", done: 0, total: 0 });
17308
- const look = lookDigest(scene.branding, {
17309
- logo: logo?.ok ? fileDigest(logo.bytes) : null,
17310
- wallpaper: wallpaper?.ok ? fileDigest(wallpaper.bytes) : null
17311
- });
17312
- if (screensOnly) {
17313
- const named2 = rendered.files.flatMap((f) => f.name === null ? [] : [{ name: f.name, bytes: f.bytes }]);
17314
- if (rendered.screens === void 0 || named2.length !== rendered.files.length || named2.length !== rendered.screens.moments.length) {
17315
- return withSummary({
17316
- outcome: "renderFailed",
17317
- takeId,
17318
- error: `the ${asked} screens render made ${named2.length} named images of ${rendered.files.length} for ${rendered.screens?.moments.length ?? "no"} screens`
17319
- });
17320
- }
17321
- const saved2 = await saveStillsFolder(deps.outDir, `${takeId} screens`, named2);
17322
- times.mark("save");
17323
- deps.log(times.line(`export ${takeId} screens`));
17324
- if (saved2.kind === "failed") {
17325
- return withSummary({
17326
- outcome: "saveFailed",
17327
- takeId,
17328
- error: saved2.error,
17329
- fileType: asked
17330
- });
17331
- }
17332
- return {
17333
- outcome: "saved",
17334
- fileType: "screens",
17335
- takeId,
17336
- folder: { path: saved2.path },
17337
- screens: { ...rendered.screens, look },
17338
- size: {
17339
- width: rendered.rendered.width,
17340
- height: rendered.rendered.height
17341
- },
17342
- warnings: {
17343
- logo: rendered.logoWarning,
17344
- wallpaperWarning: rendered.wallpaperWarning
17345
- },
17346
- summary: `Rendered ${saved2.files.length} screen images of video ${takeId} into ${saved2.path}.`
17347
- };
17348
- }
17349
17638
  const tagger = await taggerFor(takeId, deps);
17350
17639
  const base = exportBaseName(tagger.videoName ?? sceneLabel(scene.meta));
17351
17640
  const warnings = {
@@ -17408,13 +17697,6 @@ async function exportLeased(a) {
17408
17697
  error: "the render produced no file"
17409
17698
  });
17410
17699
  }
17411
- if (rendered.screens === void 0) {
17412
- return withSummary({
17413
- outcome: "renderFailed",
17414
- takeId,
17415
- error: `the ${asked} render reported no screens`
17416
- });
17417
- }
17418
17700
  const name = exportFileName(asked, aspect, base);
17419
17701
  const bytes = tagger.apply(asked, file.bytes);
17420
17702
  const saved = await saveExport(deps.outDir, name, bytes);
@@ -17441,7 +17723,9 @@ async function exportLeased(a) {
17441
17723
  ...warnings,
17442
17724
  ...tagger.untagged,
17443
17725
  ...tagger.taggedWithoutCommit,
17444
- screens: { ...rendered.screens, look },
17726
+ // Said as the render found them; refresh compares the take's page
17727
+ // screens (`screensOnly`), never these.
17728
+ ...rendered.screens === void 0 ? {} : { screens: { ...rendered.screens, look } },
17445
17729
  ...rendered.gifBudget === void 0 ? {} : { gifSize: rendered.gifBudget },
17446
17730
  // An MP4 says what it was made at and how big it came out; a GIF or
17447
17731
  // stills export sets neither, so its summary stays as it was.
@@ -17527,6 +17811,39 @@ function stillsOptionsOf(given, fileType) {
17527
17811
  return options;
17528
17812
  }
17529
17813
  var MIN_STILL_WIDTH = 320;
17814
+ async function pageScreensOf(takeId, scene, bundle, store, look) {
17815
+ const steps3 = scene.actions.length;
17816
+ const screens = [];
17817
+ const files = [];
17818
+ for (const p of bundle.pageScreens ?? []) {
17819
+ const step = p.after < steps3 ? p.after : null;
17820
+ const name = screenImageName(step);
17821
+ if (screens.some((s) => s.step === step))
17822
+ return {
17823
+ error: `video ${takeId} has two page screens named ${name} (its scene has ${steps3} steps)`
17824
+ };
17825
+ screens.push({
17826
+ step,
17827
+ ...p.unsettled === void 0 ? {} : { unsettled: p.unsettled }
17828
+ });
17829
+ if (p.unsettled !== void 0)
17830
+ continue;
17831
+ let bytes;
17832
+ try {
17833
+ bytes = await store.getPageScreen(p.ref);
17834
+ } catch (error) {
17835
+ return {
17836
+ error: `video ${takeId}'s page screen ${p.ref} could not be read (${messageOf(error)})`
17837
+ };
17838
+ }
17839
+ if (bytes === null)
17840
+ return {
17841
+ error: `video ${takeId}'s page screen ${p.ref} is missing from its frames`
17842
+ };
17843
+ files.push({ name, bytes });
17844
+ }
17845
+ return { screens: { steps: steps3, screens, look }, files };
17846
+ }
17530
17847
 
17531
17848
  // ../runner/dist/executor/attach.js
17532
17849
  var BY_HAND = "To attach it by hand, export({ videoId, maxMB: 9.5 }) and give the user that file.path to drag into the PR; the browser refuses video over 10 MB on a free plan.";
@@ -17706,8 +18023,8 @@ async function attachTake(raw, deps, onProgress) {
17706
18023
  const { file } = exported;
17707
18024
  const label = await labelOf(a.takeId, deps, file.path);
17708
18025
  const into = a.into;
17709
- const folder = join17(deps.tmpDir ?? tmpdir3(), `demoman-attach-${randomUUID3()}`);
17710
- const posted = join17(folder, plainName(file.path));
18026
+ const folder = join16(deps.tmpDir ?? tmpdir3(), `demoman-attach-${randomUUID3()}`);
18027
+ const posted = join16(folder, plainName(file.path));
17711
18028
  try {
17712
18029
  try {
17713
18030
  await mkdir5(folder, { recursive: true });
@@ -17747,7 +18064,7 @@ ${line2.details}`;
17747
18064
  if (into === "description") {
17748
18065
  said2 = {
17749
18066
  text: line2.line,
17750
- ...await writeLine(pr.number, "unreadable" in after ? "" : after.body, assetUrl, block, line2.line, join17(folder, "body.md"), gh)
18067
+ ...await writeLine(pr.number, "unreadable" in after ? "" : after.body, assetUrl, block, line2.line, join16(folder, "body.md"), gh)
17751
18068
  };
17752
18069
  } else {
17753
18070
  const holder = "unreadable" in after ? void 0 : after.comments.find((c) => c.body.includes(assetUrl));
@@ -18050,18 +18367,19 @@ async function deriveOp(library, args2) {
18050
18367
 
18051
18368
  // ../runner/dist/executor/expiry.js
18052
18369
  import { randomUUID as randomUUID5 } from "node:crypto";
18053
- import { lstat as lstat2, mkdir as mkdir7, readdir as readdir5, readFile as readFile12, rename as rename3, rm as rm8, writeFile as writeFile7 } from "node:fs/promises";
18054
- import { dirname as dirname6, join as join20 } from "node:path";
18370
+ import { lstat as lstat2, mkdir as mkdir7, readdir as readdir5, readFile as readFile11, rename as rename3, rm as rm8, writeFile as writeFile7 } from "node:fs/promises";
18371
+ import { dirname as dirname6, join as join19 } from "node:path";
18055
18372
 
18056
18373
  // ../runner/dist/executor/library.js
18057
18374
  import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
18058
- import { chmod, mkdir as mkdir6, readdir as readdir4, readFile as readFile11, rename as rename2, rm as rm7, stat as stat6, writeFile as writeFile6 } from "node:fs/promises";
18059
- import { join as join19, sep as sep2 } from "node:path";
18375
+ import { chmod, mkdir as mkdir6, readdir as readdir4, readFile as readFile10, rename as rename2, rm as rm7, stat as stat6, writeFile as writeFile6 } from "node:fs/promises";
18376
+ import { join as join18, sep as sep2 } from "node:path";
18060
18377
 
18061
18378
  // ../runner/dist/frame-store.js
18062
18379
  import { promises as fs } from "node:fs";
18063
- import { dirname as dirname5, join as join18 } from "node:path";
18380
+ import { dirname as dirname5, join as join17 } from "node:path";
18064
18381
  var BUNDLES_DIR = "bundles";
18382
+ var PAGE_SCREENS_DIR = "page-screens";
18065
18383
  function fileNameOf(ref) {
18066
18384
  return encodeURIComponent(ref);
18067
18385
  }
@@ -18097,9 +18415,10 @@ async function removeBlob(path) {
18097
18415
  }
18098
18416
  }
18099
18417
  function createFileFrameStore(root) {
18100
- const bundlesDir = join18(root, BUNDLES_DIR);
18101
- const blobPath = (ref) => join18(root, fileNameOf(ref));
18102
- const bundlePath = (sceneId) => join18(bundlesDir, `${fileNameOf(sceneId)}.json`);
18418
+ const bundlesDir = join17(root, BUNDLES_DIR);
18419
+ const blobPath = (ref) => join17(root, fileNameOf(ref));
18420
+ const bundlePath = (sceneId) => join17(bundlesDir, `${fileNameOf(sceneId)}.json`);
18421
+ const pageScreenPath = (ref) => join17(root, PAGE_SCREENS_DIR, `${fileNameOf(ref)}.png`);
18103
18422
  async function writeBlob(ref, bytes) {
18104
18423
  const path = blobPath(ref);
18105
18424
  await ensureDir(dirname5(path));
@@ -18123,6 +18442,22 @@ function createFileFrameStore(root) {
18123
18442
  await writeBlob(ref, bytes);
18124
18443
  return ref;
18125
18444
  },
18445
+ async putPageScreen(sceneId, after, bytes) {
18446
+ const ref = `ps:${sceneId}:${after}`;
18447
+ const path = pageScreenPath(ref);
18448
+ await ensureDir(dirname5(path));
18449
+ await fs.writeFile(path, bytes, { mode: 384 });
18450
+ return ref;
18451
+ },
18452
+ async getPageScreen(ref) {
18453
+ try {
18454
+ return new Uint8Array(await fs.readFile(pageScreenPath(ref)));
18455
+ } catch (error) {
18456
+ if (error.code === "ENOENT")
18457
+ return null;
18458
+ throw error;
18459
+ }
18460
+ },
18126
18461
  async putSpan(ref, bytes) {
18127
18462
  await writeBlob(ref, bytes);
18128
18463
  },
@@ -18186,6 +18521,10 @@ function createFileFrameStore(root) {
18186
18521
  for (const ref of blobRefsOf(bundle)) {
18187
18522
  await removeBlob(blobPath(ref));
18188
18523
  }
18524
+ for (const screen2 of bundle.pageScreens ?? []) {
18525
+ if (screen2.ref !== "")
18526
+ await removeBlob(pageScreenPath(screen2.ref));
18527
+ }
18189
18528
  await removeBlob(bundlePath(sceneId));
18190
18529
  },
18191
18530
  async load(ref) {
@@ -18219,7 +18558,7 @@ var isMissing = (error) => error?.code === "ENOENT";
18219
18558
  async function readOutputRows(file) {
18220
18559
  let text2;
18221
18560
  try {
18222
- text2 = await readFile11(file, "utf8");
18561
+ text2 = await readFile10(file, "utf8");
18223
18562
  } catch (error) {
18224
18563
  if (isMissing(error))
18225
18564
  return [];
@@ -18247,11 +18586,11 @@ async function readLeases(dir) {
18247
18586
  }
18248
18587
  const found = [];
18249
18588
  for (const name of names.filter((n) => n.endsWith(".json"))) {
18250
- const file = join19(dir, name);
18589
+ const file = join18(dir, name);
18251
18590
  try {
18252
18591
  found.push({
18253
18592
  file,
18254
- holder: JSON.parse(await readFile11(file, "utf8"))
18593
+ holder: JSON.parse(await readFile10(file, "utf8"))
18255
18594
  });
18256
18595
  } catch (error) {
18257
18596
  throw new LibraryError("libraryUnreadable", `could not read the lease ${file} (${messageOf(error)})`);
@@ -18264,7 +18603,7 @@ async function ownHome(home) {
18264
18603
  await chmod(home, 448);
18265
18604
  }
18266
18605
  function createLibrary(home, options = {}) {
18267
- const root = join19(home, "takes");
18606
+ const root = join18(home, "takes");
18268
18607
  const isTakeId = (id) => !(id === "" || // `.`, `..`, and the library's own `.trash-*` folders.
18269
18608
  id.startsWith(".") || id.includes("/") || id.includes("\\") || id.includes(sep2));
18270
18609
  const guard = (id, reason) => {
@@ -18274,13 +18613,13 @@ function createLibrary(home, options = {}) {
18274
18613
  };
18275
18614
  const takeDir = (id) => {
18276
18615
  guard(id, "libraryUnreadable");
18277
- return join19(root, id);
18616
+ return join18(root, id);
18278
18617
  };
18279
18618
  async function readTakeRaw(id) {
18280
- const path = join19(takeDir(id), "scene.json");
18619
+ const path = join18(takeDir(id), "scene.json");
18281
18620
  let text2;
18282
18621
  try {
18283
- text2 = await readFile11(path, "utf8");
18622
+ text2 = await readFile10(path, "utf8");
18284
18623
  } catch (error) {
18285
18624
  if (isMissing(error))
18286
18625
  return null;
@@ -18303,12 +18642,12 @@ function createLibrary(home, options = {}) {
18303
18642
  const read2 = await readTakeRaw(id);
18304
18643
  return read2 === null ? null : untitleTimestampName(read2.doc);
18305
18644
  }
18306
- const busyDir = (id) => join19(takeDir(id), ".busy");
18645
+ const busyDir = (id) => join18(takeDir(id), ".busy");
18307
18646
  const holdersOf = (id) => readLeases(busyDir(id));
18308
18647
  async function write(path, text2) {
18309
18648
  const temp = `${path}.${process.pid}.${Date.now()}.${randomUUID4()}.tmp`;
18310
18649
  try {
18311
- await mkdir6(join19(path, ".."), { recursive: true, mode: 448 });
18650
+ await mkdir6(join18(path, ".."), { recursive: true, mode: 448 });
18312
18651
  await writeFile6(temp, text2, { mode: 384 });
18313
18652
  await rename2(temp, path);
18314
18653
  } catch (error) {
@@ -18320,10 +18659,10 @@ function createLibrary(home, options = {}) {
18320
18659
  root,
18321
18660
  isTakeId,
18322
18661
  takeDir,
18323
- frameStore: (id) => createFileFrameStore(join19(takeDir(id), "frames")),
18662
+ frameStore: (id) => createFileFrameStore(join18(takeDir(id), "frames")),
18324
18663
  async putScene(doc) {
18325
18664
  guard(doc.meta.id, "libraryUnwritable");
18326
- await write(join19(takeDir(doc.meta.id), "scene.json"), JSON.stringify(doc));
18665
+ await write(join18(takeDir(doc.meta.id), "scene.json"), JSON.stringify(doc));
18327
18666
  },
18328
18667
  getScene: readTake,
18329
18668
  async getSceneRead(id) {
@@ -18336,10 +18675,10 @@ function createLibrary(home, options = {}) {
18336
18675
  },
18337
18676
  async putSceneIf(doc, ifMatch) {
18338
18677
  guard(doc.meta.id, "libraryUnwritable");
18339
- const path = join19(takeDir(doc.meta.id), "scene.json");
18678
+ const path = join18(takeDir(doc.meta.id), "scene.json");
18340
18679
  let current;
18341
18680
  try {
18342
- current = sha256(await readFile11(path, "utf8"));
18681
+ current = sha256(await readFile10(path, "utf8"));
18343
18682
  } catch (error) {
18344
18683
  if (!isMissing(error)) {
18345
18684
  throw new LibraryError("libraryUnreadable", `could not read ${path} (${messageOf(error)})`);
@@ -18359,7 +18698,7 @@ function createLibrary(home, options = {}) {
18359
18698
  pid: process.pid,
18360
18699
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
18361
18700
  };
18362
- const file = join19(busyDir(id), `${full.pid}-${full.jobId}.json`);
18701
+ const file = join18(busyDir(id), `${full.pid}-${full.jobId}.json`);
18363
18702
  await write(file, JSON.stringify(full));
18364
18703
  return {
18365
18704
  async release() {
@@ -18373,7 +18712,7 @@ function createLibrary(home, options = {}) {
18373
18712
  },
18374
18713
  async deleteTake(id) {
18375
18714
  guard(id, "libraryUnwritable");
18376
- const path = join19(root, id);
18715
+ const path = join18(root, id);
18377
18716
  try {
18378
18717
  await stat6(path);
18379
18718
  } catch (error) {
@@ -18397,7 +18736,7 @@ function createLibrary(home, options = {}) {
18397
18736
  }
18398
18737
  if (holders.length > 0)
18399
18738
  return { ok: false, holders };
18400
- const trash = join19(root, `.trash-${id}-${Date.now()}`);
18739
+ const trash = join18(root, `.trash-${id}-${Date.now()}`);
18401
18740
  try {
18402
18741
  await rename2(path, trash);
18403
18742
  } catch (error) {
@@ -18412,7 +18751,7 @@ function createLibrary(home, options = {}) {
18412
18751
  },
18413
18752
  async appendOutput(id, row) {
18414
18753
  guard(id, "libraryUnwritable");
18415
- const file = join19(takeDir(id), "outputs.json");
18754
+ const file = join18(takeDir(id), "outputs.json");
18416
18755
  const lock = `${file}.lock`;
18417
18756
  const taken = await takePidLock(lock, LOCK_WAIT_MS2);
18418
18757
  if (!taken.ok) {
@@ -18439,7 +18778,7 @@ function createLibrary(home, options = {}) {
18439
18778
  throw failure3;
18440
18779
  },
18441
18780
  async outputs(id) {
18442
- const rows = await readOutputRows(join19(takeDir(id), "outputs.json"));
18781
+ const rows = await readOutputRows(join18(takeDir(id), "outputs.json"));
18443
18782
  const listed3 = [];
18444
18783
  for (const row of rows) {
18445
18784
  let exists4 = true;
@@ -18457,14 +18796,14 @@ function createLibrary(home, options = {}) {
18457
18796
  },
18458
18797
  async putJson(id, name, value) {
18459
18798
  guard(id, "libraryUnwritable");
18460
- await write(join19(takeDir(id), name), JSON.stringify(value, null, 2));
18799
+ await write(join18(takeDir(id), name), JSON.stringify(value, null, 2));
18461
18800
  },
18462
18801
  async getJson(id, name) {
18463
18802
  guard(id, "libraryUnreadable");
18464
- const path = join19(takeDir(id), name);
18803
+ const path = join18(takeDir(id), name);
18465
18804
  let text2;
18466
18805
  try {
18467
- text2 = await readFile11(path, "utf8");
18806
+ text2 = await readFile10(path, "utf8");
18468
18807
  } catch (error) {
18469
18808
  if (isMissing(error))
18470
18809
  return { missing: true };
@@ -18479,10 +18818,10 @@ function createLibrary(home, options = {}) {
18479
18818
  /** `script.json`: none (an old or extension take), one, or one that
18480
18819
  * will not read — never the same answer for the last two. */
18481
18820
  async getSkeleton(id) {
18482
- const path = join19(takeDir(id), "script.json");
18821
+ const path = join18(takeDir(id), "script.json");
18483
18822
  let text2;
18484
18823
  try {
18485
- text2 = await readFile11(path, "utf8");
18824
+ text2 = await readFile10(path, "utf8");
18486
18825
  } catch (error) {
18487
18826
  if (isMissing(error))
18488
18827
  return { kind: "none" };
@@ -18505,7 +18844,7 @@ function createLibrary(home, options = {}) {
18505
18844
  },
18506
18845
  async removeTake(id) {
18507
18846
  guard(id, "libraryUnwritable");
18508
- const path = join19(root, id);
18847
+ const path = join18(root, id);
18509
18848
  try {
18510
18849
  await rm7(path, { recursive: true, force: true });
18511
18850
  } catch (error) {
@@ -18531,7 +18870,7 @@ function createLibrary(home, options = {}) {
18531
18870
  } catch (error) {
18532
18871
  unreadable2.push({
18533
18872
  id,
18534
- unreadable: `${error instanceof LibraryError ? error.message : messageOf(error)} \u2014 remove ${join19(root, id)} if the video is not wanted`
18873
+ unreadable: `${error instanceof LibraryError ? error.message : messageOf(error)} \u2014 remove ${join18(root, id)} if the video is not wanted`
18535
18874
  });
18536
18875
  continue;
18537
18876
  }
@@ -18557,7 +18896,7 @@ function createLibrary(home, options = {}) {
18557
18896
  var EXPIRE_AFTER_MS = 30 * 864e5;
18558
18897
  var MIN_INTERVAL_MS = 36e5;
18559
18898
  var isMissing2 = (e) => e.code === "ENOENT";
18560
- var statePath = (library) => join20(dirname6(library.root), "videos", ".expiry.json");
18899
+ var statePath = (library) => join19(dirname6(library.root), "videos", ".expiry.json");
18561
18900
  async function sizeOf(path) {
18562
18901
  let s;
18563
18902
  try {
@@ -18571,7 +18910,7 @@ async function sizeOf(path) {
18571
18910
  return s.size;
18572
18911
  let total = 0;
18573
18912
  for (const name of await readdir5(path))
18574
- total += await sizeOf(join20(path, name));
18913
+ total += await sizeOf(join19(path, name));
18575
18914
  return total;
18576
18915
  }
18577
18916
  async function keptOf(versions, library) {
@@ -18594,7 +18933,7 @@ async function keptOf(versions, library) {
18594
18933
  return kept;
18595
18934
  }
18596
18935
  async function readState(library) {
18597
- const text2 = await readFile12(statePath(library), "utf8").catch((e) => {
18936
+ const text2 = await readFile11(statePath(library), "utf8").catch((e) => {
18598
18937
  if (isMissing2(e))
18599
18938
  return null;
18600
18939
  throw e;
@@ -18664,12 +19003,12 @@ async function expire(store, library, now, tally) {
18664
19003
  if (!(now.getTime() - Date.parse(v.createdAt) > EXPIRE_AFTER_MS))
18665
19004
  continue;
18666
19005
  const dir = library.takeDir(v.takeId);
18667
- const leases = await readLeases(join20(dir, ".busy"));
19006
+ const leases = await readLeases(join19(dir, ".busy"));
18668
19007
  if (leases.some((l) => pidAlive(l.holder.pid))) {
18669
19008
  tally.skippedLeased++;
18670
19009
  continue;
18671
19010
  }
18672
- const paths = [join20(dir, "frames"), join20(dir, "thumbs")];
19011
+ const paths = [join19(dir, "frames"), join19(dir, "thumbs")];
18673
19012
  let bytes = 0;
18674
19013
  for (const path of paths) {
18675
19014
  try {
@@ -18697,7 +19036,7 @@ async function expire(store, library, now, tally) {
18697
19036
 
18698
19037
  // ../runner/dist/executor/final-still.js
18699
19038
  import { chmod as chmod2, writeFile as writeFile8 } from "node:fs/promises";
18700
- import { join as join21 } from "node:path";
19039
+ import { join as join20 } from "node:path";
18701
19040
  var STILL_MAX_WIDTH = 1280;
18702
19041
  function stillTarget(target) {
18703
19042
  const k = Math.min(1, STILL_MAX_WIDTH / target.width);
@@ -18747,7 +19086,7 @@ async function renderFinalStill(args2) {
18747
19086
  if (file === void 0) {
18748
19087
  return { unavailable: "the render produced no still" };
18749
19088
  }
18750
- const path = join21(library.takeDir(takeId), "final-still.png");
19089
+ const path = join20(library.takeDir(takeId), "final-still.png");
18751
19090
  await writeFile8(path, file.bytes, { mode: 384 });
18752
19091
  await chmod2(path, 384);
18753
19092
  return { path };
@@ -19095,6 +19434,197 @@ async function refilmFromVideo(store, library, video, leftOut = []) {
19095
19434
  };
19096
19435
  }
19097
19436
 
19437
+ // ../runner/dist/executor/same-picture.js
19438
+ import { readFile as readFile12 } from "node:fs/promises";
19439
+ import { createServer as createServer2 } from "node:http";
19440
+ import { join as join21 } from "node:path";
19441
+ import { fileURLToPath as fileURLToPath5 } from "node:url";
19442
+ var STILL_LOOKS = [
19443
+ { name: "sharply", block: 1, levels: 40, allowed: 8e-6 },
19444
+ { name: "faintly", block: 8, levels: 13, allowed: 17e-5 }
19445
+ ];
19446
+ var LOOK_CHANGED = "the look changed: the background, padding or logo round the window is not the one the committed video was recorded with";
19447
+ var ENTRY_PATH4 = fileURLToPath5(new URL(import.meta.url.endsWith(".ts") ? "../decode-probe-entry.ts" : "../decode-probe-entry.js", import.meta.url));
19448
+ function screensNote(screens, steps3) {
19449
+ if (screens === null || screens === void 0)
19450
+ return "no screens";
19451
+ const unsettled = screens.screens.filter((s) => s.unsettled !== void 0);
19452
+ return [
19453
+ `${screens.screens.length - unsettled.length} of ${screens.steps + 1} screens settled`,
19454
+ ...unsettled.map((s) => `${screenPlace(s.step, steps3)}: ${s.unsettled}`)
19455
+ ].join("; ");
19456
+ }
19457
+ function pairScreens(committed, fresh, steps3) {
19458
+ const pairs = [];
19459
+ const skipped = [];
19460
+ const where2 = (step) => screenPlace(step, steps3);
19461
+ for (const a of committed.screens) {
19462
+ const b = fresh.screens.find((s) => s.step === a.step);
19463
+ if (b === void 0) {
19464
+ skipped.push(`${where2(a.step)}: no screen in the new video`);
19465
+ } else if (a.unsettled === void 0 && b.unsettled === void 0) {
19466
+ pairs.push(a.step);
19467
+ } else if (b.unsettled === void 0) {
19468
+ skipped.push(`${where2(a.step)}: ${a.unsettled} in the committed video`);
19469
+ } else if (a.unsettled === void 0) {
19470
+ skipped.push(`${where2(a.step)}: ${b.unsettled} in the new video`);
19471
+ } else {
19472
+ skipped.push(a.unsettled === b.unsettled ? `${where2(a.step)}: ${a.unsettled}` : `${where2(a.step)}: ${a.unsettled} in the committed video, ${b.unsettled} in the new one`);
19473
+ }
19474
+ }
19475
+ for (const b of fresh.screens) {
19476
+ if (!committed.screens.some((a) => a.step === b.step))
19477
+ skipped.push(`${where2(b.step)}: no screen in the committed video`);
19478
+ }
19479
+ return { pairs, skipped };
19480
+ }
19481
+ async function sameScreens(committed, fresh, deps) {
19482
+ if (committed.screens.steps !== fresh.screens.steps) {
19483
+ return {
19484
+ same: false,
19485
+ detail: `the video's steps changed, ${committed.screens.steps} to ${fresh.screens.steps}`,
19486
+ skipped: []
19487
+ };
19488
+ }
19489
+ if (committed.screens.look !== void 0 && fresh.screens.look !== void 0 && committed.screens.look !== fresh.screens.look) {
19490
+ return { same: false, detail: LOOK_CHANGED, skipped: [] };
19491
+ }
19492
+ const { pairs, skipped } = pairScreens(committed.screens, fresh.screens, deps.steps);
19493
+ const withSkipped = (detail) => skipped.length === 0 ? detail : `${detail}; ${skipped.join("; ")}`;
19494
+ if (pairs.length === 0)
19495
+ return {
19496
+ uncomparable: withSkipped("no screen settled in both the committed video and the new one")
19497
+ };
19498
+ const files = /* @__PURE__ */ new Map();
19499
+ const paths = /* @__PURE__ */ new Map();
19500
+ for (const step of pairs) {
19501
+ const name = screenImageName(step);
19502
+ const sizes = [];
19503
+ for (const [prefix, side] of [
19504
+ ["/a/", committed],
19505
+ ["/b/", fresh]
19506
+ ]) {
19507
+ const path = join21(side.dir, name);
19508
+ paths.set(`${prefix}${name}`, path);
19509
+ let bytes;
19510
+ try {
19511
+ bytes = await readFile12(path);
19512
+ } catch (error) {
19513
+ return {
19514
+ uncomparable: error.code === "ENOENT" ? `${path} is missing` : `${path} could not be read (${messageOf(error)})`
19515
+ };
19516
+ }
19517
+ try {
19518
+ const { width, height } = pngSize(bytes);
19519
+ sizes.push(`${width}x${height}`);
19520
+ } catch (error) {
19521
+ return {
19522
+ uncomparable: `${path} could not be read as a PNG (${messageOf(error)})`
19523
+ };
19524
+ }
19525
+ files.set(`${prefix}${name}`, bytes);
19526
+ }
19527
+ if (sizes[0] !== sizes[1])
19528
+ return {
19529
+ same: false,
19530
+ detail: withSkipped(`the page size changed, ${sizes[0]} to ${sizes[1]}, ${screenPlace(step, deps.steps)}`),
19531
+ skipped
19532
+ };
19533
+ }
19534
+ const urls = (prefix) => pairs.map((step) => `${prefix}${screenImageName(step)}`);
19535
+ const work = await deps.session.openWorkPage();
19536
+ if (!work.ok)
19537
+ throw new Error(`no page to decode on: ${work.detail}`);
19538
+ const server = createServer2((req, res) => {
19539
+ const bytes = files.get(req.url ?? "");
19540
+ if (bytes === void 0) {
19541
+ res.writeHead(200, { "content-type": "text/html" });
19542
+ res.end("<!doctype html><meta charset=utf-8><title>compare</title>");
19543
+ return;
19544
+ }
19545
+ res.writeHead(200, {
19546
+ "content-type": "image/png",
19547
+ "content-length": String(bytes.byteLength)
19548
+ });
19549
+ res.end(bytes);
19550
+ });
19551
+ let diff;
19552
+ try {
19553
+ const origin = await listenOnLoopback(server);
19554
+ await work.page.goto(origin);
19555
+ await work.page.addScriptTag({ content: await bundleEntry(ENTRY_PATH4) });
19556
+ diff = await work.page.evaluate(([name, a, b, looks]) => {
19557
+ const entry = globalThis[name];
19558
+ if (entry === void 0)
19559
+ throw new Error(`${name} is not installed`);
19560
+ return entry.imagesDiff(a, b, looks);
19561
+ }, [
19562
+ DECODE_PROBE_GLOBAL,
19563
+ urls("/a/"),
19564
+ urls("/b/"),
19565
+ STILL_LOOKS.map(({ block, levels }) => ({ block, levels }))
19566
+ ]);
19567
+ } finally {
19568
+ server.close();
19569
+ await work.page.close().catch((error) => {
19570
+ deps.log(`refresh: the comparison's page would not close (${messageOf(error)})`);
19571
+ });
19572
+ }
19573
+ if ("unreadable" in diff) {
19574
+ const at2 = diff.error.indexOf(": ");
19575
+ const url = diff.error.slice(0, at2);
19576
+ return {
19577
+ uncomparable: `${paths.get(url) ?? url} could not be read as a PNG (${diff.error.slice(at2 + 2)})`
19578
+ };
19579
+ }
19580
+ const judged = comparePictures(diff.changed, pairs, fresh.screens.steps + 1, deps.steps);
19581
+ return { ...judged, detail: withSkipped(judged.detail), skipped };
19582
+ }
19583
+ function scriptStep(steps3, action) {
19584
+ let seen = -1;
19585
+ for (const [i, step] of steps3.entries()) {
19586
+ if (step.do !== "pause")
19587
+ seen++;
19588
+ if (seen === action)
19589
+ return i;
19590
+ }
19591
+ return null;
19592
+ }
19593
+ function before(action, steps3) {
19594
+ const i = steps3 === void 0 ? null : scriptStep(steps3, action);
19595
+ return i === null ? `before action ${action + 1}` : `before step ${i + 1}`;
19596
+ }
19597
+ function screenPlace(step, steps3) {
19598
+ return step === null ? "on the final screen" : before(step, steps3);
19599
+ }
19600
+ function comparePictures(changed, pairs, total, steps3, looks = STILL_LOOKS) {
19601
+ const pct = (share) => `${(share * 100).toFixed(4)}%`;
19602
+ const worst = looks.map((look, j) => {
19603
+ let share = 0;
19604
+ let at2 = 0;
19605
+ for (const [i, shares] of changed.entries()) {
19606
+ const v = shares[j];
19607
+ if (v > share) {
19608
+ share = v;
19609
+ at2 = i;
19610
+ }
19611
+ }
19612
+ return { look, share, at: at2, over: share / look.allowed };
19613
+ });
19614
+ const where2 = `${pairs.length} of ${total} screens`;
19615
+ const most = worst.reduce((x, y) => y.over > x.over ? y : x);
19616
+ if (most.over <= 1)
19617
+ return {
19618
+ same: true,
19619
+ detail: `at most ${worst.map((w) => `${pct(w.share)} ${w.look.name}`).join(" and ")} of the picture changed, over ${where2}`
19620
+ };
19621
+ const place2 = screenPlace(pairs[most.at], steps3);
19622
+ return {
19623
+ same: false,
19624
+ detail: `${pct(most.share)} of the picture changed ${most.look.name} ${place2}, over the ${pct(most.look.allowed)} allowed, of ${where2}`
19625
+ };
19626
+ }
19627
+
19098
19628
  // ../runner/dist/executor/video-match.js
19099
19629
  var sameName = (a, b) => normaliseName(a) === normaliseName(b);
19100
19630
  function similarNames(a, b) {
@@ -19897,33 +20427,11 @@ async function keepVideo(args2, deps) {
19897
20427
  try {
19898
20428
  const rendered = [];
19899
20429
  const judged = judgedOutput(base.outputs);
19900
- for (const o of deliver2 === "files" ? [] : base.outputs) {
19901
- deps.log(`add: exporting ${o.path}`);
19902
- const answer2 = await exportTake({
19903
- takeId: built.takeId,
19904
- fileType: o.fileType,
19905
- aspect: o.aspect,
19906
- // Its file is renamed into the repo; no row names the temp one.
19907
- unlisted: true,
19908
- // A GIF has no quality to choose; export refuses one.
19909
- ...o.fileType === "mp4" ? { quality: o.quality } : {}
19910
- }, { ...deps.export, outDir: temp }, () => void 0);
19911
- if (answer2.outcome !== "saved" || answer2.fileType === "stills") {
19912
- return refuse6("exportFailed", `${o.path}: ${answer2.summary}`);
19913
- }
19914
- if (answer2.warnings.logo !== null) {
19915
- return refuse6("logoUnreadable", `${o.path} was rendered without its logo: ${answer2.warnings.logo}`);
19916
- }
19917
- if (answer2.warnings.wallpaperWarning?.kind === "leftOut") {
19918
- return refuse6("wallpaperUnreadable", `${o.path} was rendered without its wallpaper: ${answer2.warnings.wallpaperWarning.sentence}`);
19919
- }
19920
- rendered.push(await readFile14(answer2.file.path));
19921
- }
19922
20430
  let screens;
19923
20431
  let shots = null;
19924
20432
  if (deliver2 === "commit") {
19925
20433
  const o = base.outputs[judged];
19926
- deps.log(`add: rendering the screens of ${o.path}`);
20434
+ deps.log(`add: copying the page screens of ${o.path}`);
19927
20435
  const shot = await exportTake({
19928
20436
  takeId: built.takeId,
19929
20437
  fileType: o.fileType,
@@ -19936,23 +20444,44 @@ async function keepVideo(args2, deps) {
19936
20444
  return refuse6("exportFailed", `${o.path}'s screens: ${shot.summary}`);
19937
20445
  }
19938
20446
  if (shot.warnings.logo !== null) {
19939
- return refuse6("logoUnreadable", `${o.path}'s screens were rendered without the logo: ${shot.warnings.logo}`);
20447
+ return refuse6("logoUnreadable", `${o.path}'s page screens would be kept with a look that leaves out the logo: ${shot.warnings.logo}`);
19940
20448
  }
19941
20449
  if (shot.warnings.wallpaperWarning?.kind === "leftOut") {
19942
- return refuse6("wallpaperUnreadable", `${o.path}'s screens were rendered without the wallpaper: ${shot.warnings.wallpaperWarning.sentence}`);
20450
+ return refuse6("wallpaperUnreadable", `${o.path}'s page screens would be kept with a look that leaves out the wallpaper: ${shot.warnings.wallpaperWarning.sentence}`);
19943
20451
  }
19944
20452
  screens = shot.screens;
19945
- shots = { dir: shot.folder.path, size: shot.size };
20453
+ shots = { dir: shot.folder.path };
19946
20454
  }
19947
- if (deliver2 === "commit" && (screens === void 0 || screens.moments.length === 0)) {
19948
- return refuse6("exportFailed", `${base.outputs[judged]?.path}, the output a refresh judges, has no still screen to compare against \u2014 a refresh would have nothing to check; nothing was written`);
20455
+ if (deliver2 === "commit" && !screens?.screens.some((s) => s.unsettled === void 0)) {
20456
+ return refuse6("exportFailed", `${base.outputs[judged]?.path}, the output a refresh judges, has no settled screen to compare against (${screensNote(screens, base.script.steps)}) \u2014 a refresh would have nothing to check; nothing was written`);
20457
+ }
20458
+ for (const o of deliver2 === "files" ? [] : base.outputs) {
20459
+ deps.log(`add: exporting ${o.path}`);
20460
+ const answer2 = await exportTake({
20461
+ takeId: built.takeId,
20462
+ fileType: o.fileType,
20463
+ aspect: o.aspect,
20464
+ // Its file is renamed into the repo; no row names the temp one.
20465
+ unlisted: true,
20466
+ // A GIF has no quality to choose; export refuses one.
20467
+ ...o.fileType === "mp4" ? { quality: o.quality } : {}
20468
+ }, { ...deps.export, outDir: temp }, () => void 0);
20469
+ if (answer2.outcome !== "saved" || answer2.fileType === "stills") {
20470
+ return refuse6("exportFailed", `${o.path}: ${answer2.summary}`);
20471
+ }
20472
+ if (answer2.warnings.logo !== null) {
20473
+ return refuse6("logoUnreadable", `${o.path} was rendered without its logo: ${answer2.warnings.logo}`);
20474
+ }
20475
+ if (answer2.warnings.wallpaperWarning?.kind === "leftOut") {
20476
+ return refuse6("wallpaperUnreadable", `${o.path} was rendered without its wallpaper: ${answer2.warnings.wallpaperWarning.sentence}`);
20477
+ }
20478
+ rendered.push(await readFile14(answer2.file.path));
19949
20479
  }
19950
20480
  const kept = base;
19951
20481
  const runReport = deliver2 === "files" ? null : await deps.library.getJson(built.takeId, "report.json");
19952
20482
  const receipt = deliver2 === "files" || screens === void 0 ? null : {
19953
20483
  receiptVersion: RECEIPT_VERSION,
19954
20484
  screensDir: screensDirOf(receiptRel),
19955
- screensSize: shots?.size ?? null,
19956
20485
  flow: video.id,
19957
20486
  video: built.takeId,
19958
20487
  filmedAt: filmedAtOf(runReport),
@@ -20033,7 +20562,7 @@ async function keepVideo(args2, deps) {
20033
20562
  key: repo.ok ? repo.repo.key : null,
20034
20563
  receipt,
20035
20564
  ...receipt === null ? {} : {
20036
- screensNote: `${receipt.screens.moments.length} of ${receipt.screens.steps + 1} screens are still`
20565
+ screensNote: screensNote(receipt.screens, kept.script.steps)
20037
20566
  },
20038
20567
  ...markNote === void 0 ? {} : { markNote },
20039
20568
  written,
@@ -20231,6 +20760,7 @@ async function buildKept(a, deps) {
20231
20760
  scaleGuess
20232
20761
  };
20233
20762
  }
20763
+ var ownReceiptNotWritten = (rel) => `${rel}: its own receipt predates page screens and is not written out; the next refresh records it again and replaces its outputs`;
20234
20764
  async function rewriteKept(repoRoot, videoId, deps, notNow) {
20235
20765
  const root = resolve3(repoRoot);
20236
20766
  const rootReal = await realpath2(root);
@@ -20315,7 +20845,7 @@ async function rewriteKept(repoRoot, videoId, deps, notNow) {
20315
20845
  }, deps);
20316
20846
  if (!made.ok)
20317
20847
  return { refused: `${rel} was not rewritten: ${made.detail}` };
20318
- let receipt = null;
20848
+ let predates = null;
20319
20849
  if (old.deliver === "commit") {
20320
20850
  const had = await readReceiptFile(join23(root, receiptFile), receiptFile);
20321
20851
  if ("detail" in had || "missing" in had && parsed2.migrated === null) {
@@ -20324,7 +20854,7 @@ async function rewriteKept(repoRoot, videoId, deps, notNow) {
20324
20854
  };
20325
20855
  }
20326
20856
  if ("missing" in had)
20327
- receipt = parsed2.migrated;
20857
+ predates = ownReceiptNotWritten(rel);
20328
20858
  }
20329
20859
  try {
20330
20860
  if (made.kept.logo !== null && made.logoBytes !== null) {
@@ -20333,9 +20863,6 @@ async function rewriteKept(repoRoot, videoId, deps, notNow) {
20333
20863
  if (made.kept.wallpaper !== null && made.wallpaperBytes !== null) {
20334
20864
  await place(join23(root, made.kept.wallpaper), made.wallpaperBytes);
20335
20865
  }
20336
- if (receipt !== null) {
20337
- await place(join23(root, receiptFile), serializeReceipt(receipt));
20338
- }
20339
20866
  await place(join23(root, rel), serializeKept(made.kept));
20340
20867
  } catch (error) {
20341
20868
  return {
@@ -20344,6 +20871,8 @@ async function rewriteKept(repoRoot, videoId, deps, notNow) {
20344
20871
  }
20345
20872
  for (const u of unreadable2)
20346
20873
  deps.log(`refresh: ${u}`);
20874
+ if (predates !== null)
20875
+ deps.log(`refresh: ${predates}`);
20347
20876
  if (made.scaleGuess !== null)
20348
20877
  deps.log(`refresh: ${rel}: ${made.scaleGuess}`);
20349
20878
  return { rewritten: rel };
@@ -20399,16 +20928,15 @@ async function renameKept(a, deps) {
20399
20928
  }
20400
20929
  if ("receipt" in had && moves && receipt !== oldReceipt) {
20401
20930
  carry = () => rename5(join23(root, oldReceipt), join23(root, receipt));
20402
- if (had.receipt.screensDir !== null) {
20931
+ const exists4 = (dir2) => lstat3(join23(root, RECEIPT_DIR, dir2)).then(() => true, () => false);
20932
+ const dir = had.receipt.screensDir === null ? null : had.receipt.screens !== null || await exists4(had.receipt.screensDir) ? had.receipt.screensDir : await exists4(screensDirOf(oldReceipt)) ? screensDirOf(oldReceipt) : null;
20933
+ if (dir !== null) {
20403
20934
  screens = {
20404
- from: `${RECEIPT_DIR}/${had.receipt.screensDir}`,
20935
+ from: `${RECEIPT_DIR}/${dir}`,
20405
20936
  to: `${RECEIPT_DIR}/${screensDirOf(receipt)}`,
20406
20937
  receipt: had.receipt
20407
20938
  };
20408
20939
  }
20409
- } else if ("missing" in had && parsed2.migrated !== null) {
20410
- const migrated = parsed2.migrated;
20411
- carry = () => place(join23(root, receipt), serializeReceipt(migrated));
20412
20940
  }
20413
20941
  }
20414
20942
  const legacy = `${LEGACY_FLOWS_DIR}/${keptFileName(a.name)}`;
@@ -20445,13 +20973,17 @@ async function renameKept(a, deps) {
20445
20973
  });
20446
20974
  }
20447
20975
  if (screens !== null) {
20448
- const { from, to, receipt: r } = screens;
20976
+ const { from, to } = screens;
20449
20977
  steps3.push({
20450
20978
  what: `move ${from} to ${to}`,
20451
20979
  run: () => rename5(join23(root, from), join23(root, to)),
20452
20980
  undo: () => rename5(join23(root, to), join23(root, from)),
20453
20981
  left: `the screens are left at ${to}`
20454
- }, {
20982
+ });
20983
+ }
20984
+ if (screens !== null && screens.receipt.screens !== null) {
20985
+ const { to, receipt: r } = screens;
20986
+ steps3.push({
20455
20987
  what: `point ${receipt} at ${to}`,
20456
20988
  run: () => place(join23(root, receipt), serializeReceipt({ ...r, screensDir: screensDirOf(receipt) })),
20457
20989
  undo: () => place(join23(root, receipt), serializeReceipt(r)),
@@ -20504,6 +21036,8 @@ async function renameKept(a, deps) {
20504
21036
  }
20505
21037
  done.push(step);
20506
21038
  }
21039
+ if (old.deliver === "commit" && "missing" in had && parsed2.migrated !== null)
21040
+ deps.log(`rename: ${ownReceiptNotWritten(a.file)}`);
20507
21041
  return { ok: true, file };
20508
21042
  }
20509
21043
  async function readReceiptFile(path, rel) {
@@ -21424,7 +21958,8 @@ function discardingFilm() {
21424
21958
  },
21425
21959
  store: {
21426
21960
  putKeyframe: async (_sceneId, index) => `discarded:${index}`,
21427
- putBundle: async () => void 0
21961
+ putBundle: async () => void 0,
21962
+ putPageScreen: async (_sceneId, after) => `discarded:ps:${after}`
21428
21963
  }
21429
21964
  };
21430
21965
  }
@@ -23724,7 +24259,12 @@ var FORGIVEN = /* @__PURE__ */ new Set([
23724
24259
  "stillFailed",
23725
24260
  "scrollUnsettled",
23726
24261
  "budgetBreach",
23727
- "keyframeOnly"
24262
+ "keyframeOnly",
24263
+ // The video is right; only that step's page screen cannot be compared.
24264
+ "stepUnsettled",
24265
+ "stepSettleFailed",
24266
+ // The video is right; a long poll was not waited for, and said.
24267
+ "requestNotWaited"
23728
24268
  ]);
23729
24269
  var STILLS_ONLY = "no motion was recorded: the video is its stills only";
23730
24270
  function runVerdict(answer2) {
@@ -23751,11 +24291,17 @@ function runVerdict(answer2) {
23751
24291
  detail: problems.length === 0 ? line2 : `${line2} \u2014 ${problems.join("; ")}`
23752
24292
  };
23753
24293
  }
24294
+ var pageOnly = (problems) => problems.every((p) => p.endsWith("(stepUnsettled)") || p.endsWith("(requestNotWaited)"));
24295
+ function degradedNote(problems) {
24296
+ return pageOnly(problems) ? `recorded with problems the page itself made, which a second run would not change: ${problems.join("; ")}` : `recorded with problems Demoman could not avoid on this machine: ${problems.join("; ")}`;
24297
+ }
23754
24298
  async function recordWithRetry(run2, name, log2) {
23755
24299
  const first = await run2();
23756
24300
  const verdict = runVerdict(first);
23757
24301
  if (verdict.kind !== "degraded")
23758
24302
  return { answer: first, verdict };
24303
+ if (pageOnly(verdict.problems))
24304
+ return { answer: first, verdict };
23759
24305
  log2(`refresh: "${name}" recorded with ${verdict.problems.join("; ")}; trying it once more`);
23760
24306
  const answer2 = await run2();
23761
24307
  const second = runVerdict(answer2);
@@ -23998,7 +24544,7 @@ async function filmOne(job, root, executor, home, deps) {
23998
24544
  if (verdict.kind === "failed")
23999
24545
  return { failed: verdict.detail };
24000
24546
  if (verdict.kind === "degraded")
24001
- job.notes.push(`recorded with problems Demoman could not avoid on this machine: ${verdict.problems.join("; ")}`);
24547
+ job.notes.push(degradedNote(verdict.problems));
24002
24548
  const report = answer2;
24003
24549
  const takeId = report.provenance.takeId;
24004
24550
  if (takeId === null)
@@ -24021,8 +24567,7 @@ async function filmOne(job, root, executor, home, deps) {
24021
24567
  aspect: o.aspect,
24022
24568
  // Its file is renamed into the repo; no row names the temp one.
24023
24569
  unlisted: true,
24024
- // A GIF has no quality to choose; export refuses one. The screens
24025
- // render at the target the output's own export renders at.
24570
+ // A GIF has no quality to choose; export refuses one.
24026
24571
  ...o.fileType === "mp4" ? { quality: o.quality } : {},
24027
24572
  ...screensOnly ? { screensOnly: true } : {}
24028
24573
  });
@@ -24033,11 +24578,11 @@ async function filmOne(job, root, executor, home, deps) {
24033
24578
  return { failed: `${o.path}: ${exported.summary ?? exported.outcome}` };
24034
24579
  if (exported.warnings.logo !== null)
24035
24580
  return {
24036
- failed: `${o.path} was rendered without its logo: ${exported.warnings.logo}`
24581
+ failed: screensOnly ? `${o.path}'s page screens would be judged by a look that leaves out its logo: ${exported.warnings.logo}` : `${o.path} was rendered without its logo: ${exported.warnings.logo}`
24037
24582
  };
24038
24583
  if (exported.warnings.wallpaperWarning?.kind === "leftOut")
24039
24584
  return {
24040
- failed: `${o.path} was rendered without its wallpaper: ${exported.warnings.wallpaperWarning.sentence}`
24585
+ failed: screensOnly ? `${o.path}'s page screens would be judged by a look that leaves out its wallpaper: ${exported.warnings.wallpaperWarning.sentence}` : `${o.path} was rendered without its wallpaper: ${exported.warnings.wallpaperWarning.sentence}`
24041
24586
  };
24042
24587
  return exported;
24043
24588
  };
@@ -24049,18 +24594,18 @@ async function filmOne(job, root, executor, home, deps) {
24049
24594
  times.mark("screens");
24050
24595
  const shots = {
24051
24596
  screens: shot.screens,
24052
- dir: shot.folder.path,
24053
- size: shot.size
24597
+ dir: shot.folder.path
24054
24598
  };
24055
24599
  const said2 = [];
24056
24600
  const rendered = /* @__PURE__ */ new Map();
24057
- const fullScreens = /* @__PURE__ */ new Map();
24601
+ let predates = false;
24058
24602
  const filmed = (same2, toWrite2 = [], failure3 = null) => ({
24059
24603
  job,
24060
24604
  report,
24061
24605
  takeId,
24062
24606
  rendered,
24063
24607
  shots,
24608
+ predates,
24064
24609
  same: same2,
24065
24610
  failure: failure3,
24066
24611
  toWrite: toWrite2,
@@ -24069,8 +24614,8 @@ async function filmOne(job, root, executor, home, deps) {
24069
24614
  datesOnScreen,
24070
24615
  times
24071
24616
  });
24072
- if (shots.screens.moments.length === 0)
24073
- return filmed(null, [], `${judged.path}, the output a refresh judges, has no still screen to compare against \u2014 a refresh would have nothing to check; nothing was written`);
24617
+ if (!shots.screens.screens.some((sc) => sc.unsettled === void 0))
24618
+ return filmed(null, [], `${judged.path}, the output a refresh judges, has no settled screen to compare against (${screensNote(shots.screens, kept.script.steps)}) \u2014 a refresh would have nothing to check; nothing was written`);
24074
24619
  const exportAll = async (which) => {
24075
24620
  for (const i of which) {
24076
24621
  if (rendered.has(i))
@@ -24080,7 +24625,6 @@ async function filmOne(job, root, executor, home, deps) {
24080
24625
  if ("failed" in exported)
24081
24626
  return exported;
24082
24627
  rendered.set(i, exported.file.path);
24083
- fullScreens.set(i, exported.screens);
24084
24628
  times.mark(`export ${o.fileType}`);
24085
24629
  }
24086
24630
  return null;
@@ -24096,36 +24640,16 @@ async function filmOne(job, root, executor, home, deps) {
24096
24640
  if (previous === null) {
24097
24641
  } else if (!await exists4(judged.path)) {
24098
24642
  job.notes.push(`${judged.path} is missing`);
24099
- } else if (previous.screensDir === null || previous.screensSize === null) {
24100
- job.notes.push(`${job.previousAt} had no screen images, so this refresh exported to compare; the next one compares its screens`);
24101
- const failed3 = await exportAll(kept.outputs.map((_, i) => i));
24102
- if (failed3 !== null)
24103
- return failed3;
24104
- let cmp;
24105
- try {
24106
- cmp = await (deps.samePicture ?? samePicture)(join30(from, judged.path), rendered.get(j), judged.fileType, previous.screens, fullScreens.get(j), compareDeps);
24107
- } catch (error) {
24108
- return filmed(null, [], uncompared("export", messageOf(error)));
24109
- }
24110
- times.mark("compare");
24111
- if ("uncomparable" in cmp)
24112
- return filmed(null, [], uncompared("export", cmp.uncomparable));
24113
- if ("undecodable" in cmp) {
24114
- if (cmp.undecodable === "new")
24115
- return filmed(null, [], `${judged.path}'s new export could not be decoded as ${judged.fileType.toUpperCase()} (${cmp.detail}), so nothing was replaced`);
24116
- job.notes.push(`${judged.path} was replaced without a comparison: the committed file could not be decoded (${cmp.detail})`);
24117
- } else {
24118
- same = cmp.same;
24119
- said2.push(`${judged.path}: ${cmp.detail}`);
24120
- }
24643
+ } else if (previous.screens === null || previous.screensDir === null) {
24644
+ predates = true;
24645
+ job.notes.push(`${job.previousAt} predates page screens`);
24121
24646
  } else {
24122
24647
  let cmp;
24123
24648
  try {
24124
24649
  cmp = await (deps.sameScreens ?? sameScreens)({
24125
24650
  // The folder is named relative to the receipt's own.
24126
24651
  dir: join30(from, dirname9(receiptFile), previous.screensDir),
24127
- screens: previous.screens,
24128
- size: previous.screensSize
24652
+ screens: previous.screens
24129
24653
  }, shots, compareDeps);
24130
24654
  } catch (error) {
24131
24655
  return filmed(null, [], uncompared("screens", messageOf(error)));
@@ -24137,7 +24661,7 @@ async function filmOne(job, root, executor, home, deps) {
24137
24661
  said2.push(`${judged.path}: ${cmp.detail}`);
24138
24662
  }
24139
24663
  if (same === null)
24140
- said2.push("nothing to compare against; delivered as new");
24664
+ said2.push(predates ? "recorded again and not compared" : "nothing to compare against; delivered as new");
24141
24665
  const toWrite = [];
24142
24666
  for (const [i, o] of kept.outputs.entries()) {
24143
24667
  if (same !== true)
@@ -24152,7 +24676,7 @@ async function filmOne(job, root, executor, home, deps) {
24152
24676
  return failed2;
24153
24677
  return filmed(same, toWrite);
24154
24678
  }
24155
- async function deliverOne({ job, report, takeId, rendered, shots, same, failure: failure3, toWrite, said: said2, stored, datesOnScreen, times }, deps) {
24679
+ async function deliverOne({ job, report, takeId, rendered, shots, predates, same, failure: failure3, toWrite, said: said2, stored, datesOnScreen, times }, deps) {
24156
24680
  const { kept, previous, receiptFile, file, to } = job;
24157
24681
  times.mark("queued");
24158
24682
  const notes = [...job.notes];
@@ -24175,7 +24699,8 @@ async function deliverOne({ job, report, takeId, rendered, shots, same, failure:
24175
24699
  notes,
24176
24700
  video: takeId,
24177
24701
  filmedCode,
24178
- sameAs: (outcome === "unchanged" || outcome === "added") && previous !== null ? { video: previous.video } : null,
24702
+ // A replaced old receipt's video was not compared, so nothing matched.
24703
+ sameAs: (outcome === "unchanged" || outcome === "added") && previous !== null && !predates ? { video: previous.video } : null,
24179
24704
  // The list names files; the images' folder goes with its receipt.
24180
24705
  files: outputs.filter((path) => path !== screensAt).map((path) => {
24181
24706
  const o = kept.outputs.find((k) => k.path === path);
@@ -24188,7 +24713,7 @@ async function deliverOne({ job, report, takeId, rendered, shots, same, failure:
24188
24713
  said2.splice(0, said2.length, failure3);
24189
24714
  return answer2("failed", [], null);
24190
24715
  }
24191
- const writeReceipt = same !== true || previous !== null && previous.screensDir === null;
24716
+ const writeReceipt = same !== true;
24192
24717
  if (toWrite.length === 0 && !writeReceipt)
24193
24718
  return answer2("unchanged", [], null);
24194
24719
  const written = [];
@@ -24216,20 +24741,17 @@ async function deliverOne({ job, report, takeId, rendered, shots, same, failure:
24216
24741
  deps.log(`refresh: renamed ${relative4(to, temp)} over ${screensAt}`);
24217
24742
  written.push(screensAt);
24218
24743
  await put(receiptFile, serializeReceipt({
24219
- ...same === true && previous !== null ? previous : {
24220
- flow: kept.flow,
24221
- video: takeId,
24222
- filmedAt: filmedAtOf({ value: report }),
24223
- filmedCode: receiptCode,
24224
- // The take is in a library thrown away after: no library
24225
- // holds a revision of it to be ahead of.
24226
- recordedRevision: null,
24227
- ...report.pinnedNow === void 0 ? {} : { pinnedNow: report.pinnedNow }
24228
- },
24744
+ flow: kept.flow,
24745
+ video: takeId,
24746
+ filmedAt: filmedAtOf({ value: report }),
24747
+ filmedCode: receiptCode,
24748
+ // The take is in a library thrown away after: no library holds a
24749
+ // revision of it to be ahead of.
24750
+ recordedRevision: null,
24751
+ ...report.pinnedNow === void 0 ? {} : { pinnedNow: report.pinnedNow },
24229
24752
  receiptVersion: RECEIPT_VERSION,
24230
24753
  screens,
24231
24754
  screensDir,
24232
- screensSize: shots.size,
24233
24755
  // The committed files now show this script, whichever take made them.
24234
24756
  scriptDigest: scriptDigest(kept.script)
24235
24757
  }));
@@ -24245,7 +24767,7 @@ async function deliverOne({ job, report, takeId, rendered, shots, same, failure:
24245
24767
  notes.push(note2);
24246
24768
  deps.log(`refresh: "${kept.name}": ${note2}`);
24247
24769
  }
24248
- return answer2(same === null ? "uncompared" : same ? "added" : "changed", written, line2);
24770
+ return answer2(same === null ? predates ? "added" : "uncompared" : same ? "added" : "changed", written, line2);
24249
24771
  }
24250
24772
 
24251
24773
  // ../runner/dist/executor/refresh-app.js
@@ -27921,7 +28443,7 @@ function createRoutes(o) {
27921
28443
  detail: `${kept.unknown}, so the flow keeps its name.`
27922
28444
  };
27923
28445
  }
27924
- return renameKept({ root: kept.root, file: kept.file, name: name.trim() }, { videos });
28446
+ return renameKept({ root: kept.root, file: kept.file, name: name.trim() }, { videos, log: log2 });
27925
28447
  });
27926
28448
  if (done.ok) {
27927
28449
  lastFollow = null;
@@ -30393,23 +30915,27 @@ async function setSecrets(gh, slug, values, replace, existing) {
30393
30915
 
30394
30916
  // src/ci-tool.ts
30395
30917
  import { mkdir as mkdir20, readFile as readFile30, writeFile as writeFile19 } from "node:fs/promises";
30396
- import { join as join54 } from "node:path";
30918
+ import { join as join55 } from "node:path";
30397
30919
 
30398
30920
  // src/ci-setup.ts
30399
30921
  import { access as access4, mkdir as mkdir19, readdir as readdir10, readFile as readFile29, writeFile as writeFile18 } from "node:fs/promises";
30400
- import { join as join53 } from "node:path";
30922
+ import { join as join54 } from "node:path";
30401
30923
 
30402
30924
  // src/ci-workflow.ts
30403
- import { join as join52 } from "node:path";
30925
+ import { join as join53 } from "node:path";
30404
30926
  import { parseArgs } from "node:util";
30405
30927
 
30406
30928
  // src/deliver.ts
30929
+ import { mkdtemp as mkdtemp7, rm as rm20 } from "node:fs/promises";
30930
+ import { tmpdir as tmpdir8 } from "node:os";
30931
+ import { join as join52 } from "node:path";
30407
30932
  var COMMIT_SUBJECT = "Refresh demo videos";
30408
30933
  var BRANCH2 = "demoman/refresh";
30409
30934
  var BOT_NAME = "github-actions[bot]";
30410
30935
  var BOT_EMAIL = "41898282+github-actions[bot]@users.noreply.github.com";
30411
30936
  var BOT = ["-c", `user.name=${BOT_NAME}`, "-c", `user.email=${BOT_EMAIL}`];
30412
30937
  var NOT_PERMITTED = /not permitted to create or approve pull requests/i;
30938
+ var BEHIND = /\[rejected\][^\n]*\((?:fetch first|non-fast-forward)\)/;
30413
30939
  var said = (r) => r.stderr.trim() || r.stdout.trim() || `exit ${r.code}`;
30414
30940
  var toCommit = (v) => v.deliver === "commit" && (v.outcome === "changed" || v.outcome === "added" || v.outcome === "uncompared");
30415
30941
  async function offBase(repoRoot, deps, named2) {
@@ -30505,6 +31031,9 @@ async function deliver(args2, deps) {
30505
31031
  const git = (a) => deps.git(a, repoRoot);
30506
31032
  const paths = [...new Set(updated.flatMap((v) => v.outputs))];
30507
31033
  const bodyText = updated.map((v) => `- ${v.name}`).join("\n");
31034
+ const message2 = ["-m", COMMIT_SUBJECT, "-m", `${bodyText}
31035
+
31036
+ [skip demoman]`];
30508
31037
  const here = await git(["rev-parse", "--abbrev-ref", "HEAD"]);
30509
31038
  if (here.code !== 0) return fail("git rev-parse", here);
30510
31039
  const base = here.stdout.trim();
@@ -30533,12 +31062,7 @@ async function deliver(args2, deps) {
30533
31062
  const commit = await git([
30534
31063
  ...BOT,
30535
31064
  "commit",
30536
- "-m",
30537
- COMMIT_SUBJECT,
30538
- "-m",
30539
- `${bodyText}
30540
-
30541
- [skip demoman]`,
31065
+ ...message2,
30542
31066
  "--only",
30543
31067
  "--",
30544
31068
  ...paths
@@ -30546,12 +31070,24 @@ async function deliver(args2, deps) {
30546
31070
  if (commit.code !== 0) return fail("git commit", commit);
30547
31071
  if (route === "main") {
30548
31072
  const push2 = await git(["push", "origin", "HEAD"]);
30549
- if (push2.code !== 0) return fail("git push", push2);
30550
- return {
30551
- delivered: "main",
30552
- ok: true,
30553
- detail: `committed ${updated.length} video(s) on ${base}`
30554
- };
31073
+ if (push2.code === 0)
31074
+ return {
31075
+ delivered: "main",
31076
+ ok: true,
31077
+ detail: `committed ${updated.length} video(s) on ${base}`
31078
+ };
31079
+ if (base === "HEAD" || !BEHIND.test(push2.stderr))
31080
+ return fail("git push", push2);
31081
+ return onMovedBranch({
31082
+ git: deps.git,
31083
+ repoRoot,
31084
+ base,
31085
+ paths,
31086
+ message: message2,
31087
+ videos: updated.length,
31088
+ push: push2,
31089
+ refused: fail("git push", push2)
31090
+ });
30555
31091
  }
30556
31092
  const push = await git(["push", "--force", "origin", BRANCH2]);
30557
31093
  if (push.code !== 0) return fail("git push", push);
@@ -30648,6 +31184,107 @@ async function deliver(args2, deps) {
30648
31184
  };
30649
31185
  }
30650
31186
  }
31187
+ async function onMovedBranch(a) {
31188
+ const { base, paths, push } = a;
31189
+ const git = (args2, env) => a.git(args2, a.repoRoot, env);
31190
+ const failed2 = (step, r) => ({
31191
+ delivered: "nothing",
31192
+ ok: false,
31193
+ detail: `the first push was refused (${said(push)}), then ${step} failed: ${said(r)}`
31194
+ });
31195
+ const fetched = await git(["fetch", "origin", base]);
31196
+ if (fetched.code !== 0) return failed2(`git fetch origin ${base}`, fetched);
31197
+ const shas = await git(["rev-parse", "HEAD", "HEAD~1", "FETCH_HEAD"]);
31198
+ if (shas.code !== 0) return failed2("git rev-parse", shas);
31199
+ const [ours = "", start = "", tip = ""] = shas.stdout.trim().split("\n");
31200
+ if (start === tip) return a.refused;
31201
+ const on = await git(["merge-base", "--is-ancestor", start, tip]);
31202
+ if (on.code === 1)
31203
+ return {
31204
+ delivered: "nothing",
31205
+ ok: false,
31206
+ detail: `origin/${base} no longer contains the commit this run started from (${start.slice(0, 7)}): it was rewritten, or this checkout has commits origin does not; nothing was pushed (the first push said: ${said(push)})`
31207
+ };
31208
+ if (on.code !== 0) return failed2("git merge-base", on);
31209
+ const count = await git(["rev-list", "--count", `${start}..${tip}`]);
31210
+ if (count.code !== 0) return failed2("git rev-list", count);
31211
+ const past = `${count.stdout.trim()} commit(s) past the commit this run started from`;
31212
+ const touched = await git([
31213
+ "diff",
31214
+ "--name-status",
31215
+ "--no-renames",
31216
+ "-z",
31217
+ start,
31218
+ tip,
31219
+ "--",
31220
+ ...paths
31221
+ ]);
31222
+ if (touched.code !== 0)
31223
+ return failed2("git diff of the moved branch", touched);
31224
+ const deleted = [];
31225
+ const changed = [];
31226
+ const fields = touched.stdout.split("\0");
31227
+ for (let i = 0; i + 1 < fields.length; i += 2)
31228
+ (fields[i] === "D" ? deleted : changed).push(fields[i + 1] ?? "");
31229
+ const leftOut = deleted.length === 0 ? "" : `; left out ${deleted.join(", ")} that those commits deleted`;
31230
+ const catchUp = async (to) => {
31231
+ const reset = await git(["reset", "-q", "--keep", to]);
31232
+ return reset.code === 0 ? "" : `; the checkout stays at ${ours.slice(0, 7)} because ${said(reset)}: pull to catch up`;
31233
+ };
31234
+ const dir = await mkdtemp7(join52(tmpdir8(), "demoman-index-"));
31235
+ try {
31236
+ const env = { GIT_INDEX_FILE: join52(dir, "index") };
31237
+ const read2 = await git(["read-tree", tip], env);
31238
+ if (read2.code !== 0) return failed2("git read-tree", read2);
31239
+ const keep = paths.filter((p) => !deleted.includes(p));
31240
+ if (keep.length > 0) {
31241
+ const add2 = await git(
31242
+ ["add", "--", ...keep, ...deleted.map((d) => `:(exclude,literal)${d}`)],
31243
+ env
31244
+ );
31245
+ if (add2.code !== 0) return failed2("git add on the moved branch", add2);
31246
+ }
31247
+ const written = await git(["write-tree"], env);
31248
+ if (written.code !== 0) return failed2("git write-tree", written);
31249
+ const tree = written.stdout.trim();
31250
+ const differ = await git([
31251
+ "diff",
31252
+ "--name-only",
31253
+ "--no-renames",
31254
+ "-z",
31255
+ tip,
31256
+ tree
31257
+ ]);
31258
+ if (differ.code !== 0) return failed2("git diff of the new tree", differ);
31259
+ const differs = differ.stdout.split("\0").filter(Boolean);
31260
+ if (differs.length === 0)
31261
+ return {
31262
+ delivered: "main",
31263
+ ok: true,
31264
+ detail: `committed nothing: origin/${base}, which had moved ${past}, already holds every file this run would commit${leftOut}${await catchUp(tip)}`
31265
+ };
31266
+ const made = await git([
31267
+ ...BOT,
31268
+ "commit-tree",
31269
+ tree,
31270
+ "-p",
31271
+ tip,
31272
+ ...a.message
31273
+ ]);
31274
+ if (made.code !== 0) return failed2("git commit-tree", made);
31275
+ const sha = made.stdout.trim();
31276
+ const again = await git(["push", "origin", `${sha}:refs/heads/${base}`]);
31277
+ if (again.code !== 0) return failed2("the second push", again);
31278
+ const replaced = changed.filter((f) => differs.includes(f));
31279
+ return {
31280
+ delivered: "main",
31281
+ ok: true,
31282
+ detail: `committed ${a.videos} video(s) on ${base} on top of origin/${base}, which had moved ${past}${replaced.length === 0 ? "" : `; replaced ${replaced.join(", ")} that those commits had also changed`}${leftOut}${await catchUp(sha)}`
31283
+ };
31284
+ } finally {
31285
+ await rm20(dir, { recursive: true, force: true });
31286
+ }
31287
+ }
30651
31288
 
30652
31289
  // src/ci-workflow.ts
30653
31290
  var CI_WORKFLOW_PATH = ".github/workflows/demoman.yml";
@@ -31110,7 +31747,7 @@ async function ciSetup(args2, io) {
31110
31747
  choices.appBy = "person";
31111
31748
  } else if (plan.reason === "secretMissing" && plan.secrets !== void 0) {
31112
31749
  let missing = plan.secrets;
31113
- const path = flags["env-file"] ?? (ask !== null && io.exists(".env") ? join52(root, ".env") : void 0);
31750
+ const path = flags["env-file"] ?? (ask !== null && io.exists(".env") ? join53(root, ".env") : void 0);
31114
31751
  let chosen = [];
31115
31752
  if (path !== void 0) {
31116
31753
  let names;
@@ -31306,9 +31943,9 @@ var orMissing = (p) => p.catch((e) => {
31306
31943
  var readOrNull = (path) => orMissing(readFile29(path));
31307
31944
  async function draftLeft(root, step, app) {
31308
31945
  if (step !== "app" || app === null || app.source.kind === "file") return "";
31309
- const path = join53(root, APP_FILE);
31946
+ const path = join54(root, APP_FILE);
31310
31947
  try {
31311
- await mkdir19(join53(root, ".demoman"), { recursive: true });
31948
+ await mkdir19(join54(root, ".demoman"), { recursive: true });
31312
31949
  await writeFile18(path, app.text, { flag: "wx" });
31313
31950
  } catch (error) {
31314
31951
  if (error.code === "EEXIST") return "";
@@ -31328,7 +31965,7 @@ async function flowFiles(root, file, kept) {
31328
31965
  );
31329
31966
  if (kept.deliver !== "commit") return { paths: script, scriptOnly: null };
31330
31967
  const receiptFile = `${RECEIPT_DIR}/${file.split("/").pop()}`;
31331
- const text2 = await readOrNull(join53(root, receiptFile));
31968
+ const text2 = await readOrNull(join54(root, receiptFile));
31332
31969
  if (text2 === null)
31333
31970
  return { paths: script, scriptOnly: `${receiptFile} is missing` };
31334
31971
  const parsed2 = parseReceipt(text2.toString("utf8"), receiptFile);
@@ -31344,7 +31981,7 @@ async function flowFiles(root, file, kept) {
31344
31981
  const screens = [];
31345
31982
  if (receipt.screensDir !== null) {
31346
31983
  const dir = `${RECEIPT_DIR}/${receipt.screensDir}`;
31347
- const names = await orMissing(readdir10(join53(root, dir)));
31984
+ const names = await orMissing(readdir10(join54(root, dir)));
31348
31985
  if (names === null)
31349
31986
  return { paths: script, scriptOnly: `${dir} is missing` };
31350
31987
  screens.push(...names.sort().map((n) => `${dir}/${n}`));
@@ -31354,7 +31991,7 @@ async function flowFiles(root, file, kept) {
31354
31991
  ...kept.report === null ? [] : [kept.report]
31355
31992
  ];
31356
31993
  for (const o of outputs) {
31357
- if (await orMissing(access4(join53(root, o))) === null)
31994
+ if (await orMissing(access4(join54(root, o))) === null)
31358
31995
  return { paths: script, scriptOnly: `${o} is missing` };
31359
31996
  }
31360
31997
  return {
@@ -31484,7 +32121,7 @@ async function makePlan(root, choices, deps, values) {
31484
32121
  text: serializeApp(choices.app)
31485
32122
  };
31486
32123
  } else {
31487
- const raw = await readOrNull(join53(root, APP_FILE));
32124
+ const raw = await readOrNull(join54(root, APP_FILE));
31488
32125
  if (raw !== null) {
31489
32126
  const parsed2 = parseApp(raw.toString("utf8"), APP_FILE);
31490
32127
  if (!parsed2.ok)
@@ -31638,7 +32275,7 @@ async function makePlan(root, choices, deps, values) {
31638
32275
  }
31639
32276
  }
31640
32277
  }
31641
- const accounts = await readFile29(join53(root, ACCOUNTS_FILE), "utf8").catch(
32278
+ const accounts = await readFile29(join54(root, ACCOUNTS_FILE), "utf8").catch(
31642
32279
  () => null
31643
32280
  );
31644
32281
  if (accounts !== null) {
@@ -31650,7 +32287,7 @@ async function makePlan(root, choices, deps, values) {
31650
32287
  }
31651
32288
  }
31652
32289
  let gitignore = null;
31653
- const ignores = await readFile29(join53(root, ".gitignore"), "utf8").catch(
32290
+ const ignores = await readFile29(join54(root, ".gitignore"), "utf8").catch(
31654
32291
  () => null
31655
32292
  );
31656
32293
  if (ignores !== null && await ignoresSecrets(ignores)) {
@@ -31780,7 +32417,7 @@ async function fileTexts(root, paths, workflow, app, gitignore) {
31780
32417
  files.push({ path, text: app.text });
31781
32418
  else {
31782
32419
  try {
31783
- files.push({ path, text: await readFile29(join53(root, path)) });
32420
+ files.push({ path, text: await readFile29(join54(root, path)) });
31784
32421
  } catch (e) {
31785
32422
  return {
31786
32423
  failed: `${path} could not be read (${messageOf9(e)}), so nothing was done; check it is there, then run setup again`
@@ -32008,13 +32645,13 @@ function createCiTool(io) {
32008
32645
  };
32009
32646
  app = parsed2.app;
32010
32647
  const text2 = serializeApp(app);
32011
- await mkdir20(join54(root, ".demoman"), { recursive: true });
32648
+ await mkdir20(join55(root, ".demoman"), { recursive: true });
32012
32649
  try {
32013
- await writeFile19(join54(root, APP_FILE), text2, { flag: "wx" });
32650
+ await writeFile19(join55(root, APP_FILE), text2, { flag: "wx" });
32014
32651
  appFile = `wrote ${APP_FILE} in the working tree from app, uncommitted`;
32015
32652
  } catch (error) {
32016
32653
  if (error.code !== "EEXIST") throw error;
32017
- if (await readFile30(join54(root, APP_FILE), "utf8") !== text2)
32654
+ if (await readFile30(join55(root, APP_FILE), "utf8") !== text2)
32018
32655
  return {
32019
32656
  reason: "appInvalid",
32020
32657
  detail: `${APP_FILE} is already in the working tree and differs from app, and is never overwritten; nothing was written. Call ci without app to plan from that file, or show the person the difference and edit the file with their yes`
@@ -32140,7 +32777,7 @@ function stopped(s, values) {
32140
32777
  }
32141
32778
 
32142
32779
  // src/ci-watch.ts
32143
- var POLL_MS3 = 1e4;
32780
+ var POLL_MS4 = 1e4;
32144
32781
  var BLIPS = 5;
32145
32782
  async function watchSetupRun(a, deps) {
32146
32783
  const { gh, sleep: sleep3, now, progress } = deps;
@@ -32194,7 +32831,7 @@ async function watchSetupRun(a, deps) {
32194
32831
  }
32195
32832
  };
32196
32833
  }
32197
- await sleep3(POLL_MS3);
32834
+ await sleep3(POLL_MS4);
32198
32835
  }
32199
32836
  const lines = [];
32200
32837
  const say = (l) => {
@@ -32265,7 +32902,7 @@ async function watchSetupRun(a, deps) {
32265
32902
  );
32266
32903
  let failedRuns = null;
32267
32904
  for (let n = 0; n < BLIPS && failedRuns === null; n++) {
32268
- if (n > 0) await sleep3(POLL_MS3);
32905
+ if (n > 0) await sleep3(POLL_MS4);
32269
32906
  const opened = await read2([
32270
32907
  "pr",
32271
32908
  "list",
@@ -32338,7 +32975,7 @@ async function watchSetupRun(a, deps) {
32338
32975
  }
32339
32976
  };
32340
32977
  }
32341
- await sleep3(POLL_MS3);
32978
+ await sleep3(POLL_MS4);
32342
32979
  }
32343
32980
  }
32344
32981
 
@@ -33447,7 +34084,7 @@ import {
33447
34084
  writeFileSync
33448
34085
  } from "node:fs";
33449
34086
  import { constants as constants4, homedir as homedir3 } from "node:os";
33450
- import { dirname as dirname14, isAbsolute as isAbsolute12, join as join55 } from "node:path";
34087
+ import { dirname as dirname14, isAbsolute as isAbsolute12, join as join56 } from "node:path";
33451
34088
  import {
33452
34089
  confirm,
33453
34090
  isCancel,
@@ -33554,7 +34191,7 @@ function linkTarget(path) {
33554
34191
  } catch {
33555
34192
  return at2;
33556
34193
  }
33557
- at2 = isAbsolute12(link2) ? link2 : join55(dirname14(at2), link2);
34194
+ at2 = isAbsolute12(link2) ? link2 : join56(dirname14(at2), link2);
33558
34195
  }
33559
34196
  return at2;
33560
34197
  }
@@ -33562,15 +34199,15 @@ function stableNodeBin(execPath, pathEnv, realpath6) {
33562
34199
  for (const dir of pathEnv.split(":")) {
33563
34200
  if (dir === "" || dir.includes("/fnm_multishells/")) continue;
33564
34201
  try {
33565
- realpath6(join55(dir, "npx"));
33566
- if (realpath6(join55(dir, "node")) === execPath) return dir;
34202
+ realpath6(join56(dir, "npx"));
34203
+ if (realpath6(join56(dir, "node")) === execPath) return dir;
33567
34204
  } catch {
33568
34205
  }
33569
34206
  }
33570
34207
  return dirname14(execPath);
33571
34208
  }
33572
34209
  function readSkill(distDir) {
33573
- const path = join55(distDir, "skills", "record-demo", "SKILL.md");
34210
+ const path = join56(distDir, "skills", "record-demo", "SKILL.md");
33574
34211
  const read2 = readTextFile(path);
33575
34212
  if ("missing" in read2) return { error: `${path} is missing` };
33576
34213
  if ("error" in read2) return read2;
@@ -33583,14 +34220,14 @@ function claudePaths(home, configDir, platform = process.platform) {
33583
34220
  const managed = platform === "linux" ? CLAUDE_MANAGED_SETTINGS_LINUX : CLAUDE_MANAGED_SETTINGS;
33584
34221
  if (configDir === void 0 || configDir === "") {
33585
34222
  return {
33586
- settings: join55(home, ".claude", "settings.json"),
33587
- config: join55(home, ".claude.json"),
34223
+ settings: join56(home, ".claude", "settings.json"),
34224
+ config: join56(home, ".claude.json"),
33588
34225
  managed
33589
34226
  };
33590
34227
  }
33591
34228
  return {
33592
- settings: join55(configDir, "settings.json"),
33593
- config: join55(configDir, ".claude.json"),
34229
+ settings: join56(configDir, "settings.json"),
34230
+ config: join56(configDir, ".claude.json"),
33594
34231
  managed
33595
34232
  };
33596
34233
  }
@@ -33664,7 +34301,7 @@ function realSetupDeps(version, distDir, io = {
33664
34301
  chromiumDeps: chromiumDeps(),
33665
34302
  browserLaunches,
33666
34303
  home,
33667
- codexHome: process.env.CODEX_HOME || join55(home, ".codex"),
34304
+ codexHome: process.env.CODEX_HOME || join56(home, ".codex"),
33668
34305
  env: process.env,
33669
34306
  claude: claudePaths(home, process.env.CLAUDE_CONFIG_DIR),
33670
34307
  nodeBin: stableNodeBin(
@@ -33969,7 +34606,7 @@ async function callerProject(cwd, git = execGit) {
33969
34606
  }
33970
34607
 
33971
34608
  // src/version.ts
33972
- var VERSION = "0.9.4";
34609
+ var VERSION = "0.9.5";
33973
34610
 
33974
34611
  // src/main.ts
33975
34612
  var log = (line2) => {
@@ -33982,11 +34619,11 @@ var WALLPAPERS_DIR = fileURLToPath7(
33982
34619
  var REINSTALL = `reinstall with \`npx --prefix ~/ ${PACKAGE_NAME}@${VERSION} setup\``;
33983
34620
  function requirePageBundles(pages, say) {
33984
34621
  const missing = PAGE_ENTRIES.filter(
33985
- (n) => !existsSync5(join56(pages, `${n}.js`))
34622
+ (n) => !existsSync5(join57(pages, `${n}.js`))
33986
34623
  );
33987
34624
  if (missing.length > 0) {
33988
34625
  say(
33989
- `this install is missing ${missing.map((n) => join56(pages, `${n}.js`)).join(", ")} \u2014 ${REINSTALL}`
34626
+ `this install is missing ${missing.map((n) => join57(pages, `${n}.js`)).join(", ")} \u2014 ${REINSTALL}`
33990
34627
  );
33991
34628
  process.exit(1);
33992
34629
  }
@@ -34054,13 +34691,13 @@ async function mcp(args2) {
34054
34691
  process.exit(2);
34055
34692
  }
34056
34693
  const here = fileURLToPath7(new URL(".", import.meta.url));
34057
- const pages = join56(here, "page");
34694
+ const pages = join57(here, "page");
34058
34695
  requirePageBundles(pages, (line2) => log(line2));
34059
34696
  let recipe;
34060
34697
  try {
34061
- recipe = readFileSync2(join56(here, "recipe.md"), "utf8");
34698
+ recipe = readFileSync2(join57(here, "recipe.md"), "utf8");
34062
34699
  if (recipe.trim() === "") {
34063
- throw new Error(`${join56(here, "recipe.md")} is empty`);
34700
+ throw new Error(`${join57(here, "recipe.md")} is empty`);
34064
34701
  }
34065
34702
  } catch (error) {
34066
34703
  log(
@@ -34168,17 +34805,17 @@ ${USAGE}`);
34168
34805
  process.exit(1);
34169
34806
  }
34170
34807
  const here = fileURLToPath7(new URL(".", import.meta.url));
34171
- requirePageBundles(join56(here, "page"), (line2) => log(line2));
34172
- const pagesDir = join56(here, "studio");
34173
- if (!existsSync5(join56(pagesDir, "library.html"))) {
34808
+ requirePageBundles(join57(here, "page"), (line2) => log(line2));
34809
+ const pagesDir = join57(here, "studio");
34810
+ if (!existsSync5(join57(pagesDir, "library.html"))) {
34174
34811
  log(
34175
- `this install is missing ${join56(pagesDir, "library.html")} \u2014 ${REINSTALL}`
34812
+ `this install is missing ${join57(pagesDir, "library.html")} \u2014 ${REINSTALL}`
34176
34813
  );
34177
34814
  process.exit(1);
34178
34815
  }
34179
34816
  await runServe({
34180
34817
  home,
34181
- outDir: join56(homedir4(), "Downloads"),
34818
+ outDir: join57(homedir4(), "Downloads"),
34182
34819
  pagesDir,
34183
34820
  version: VERSION,
34184
34821
  executablePath: fullChromiumPath(),
@@ -34239,7 +34876,7 @@ ${USAGE}`);
34239
34876
  const root = repo.repo.root;
34240
34877
  const inRoot = (p) => relative6(root, resolve9(p));
34241
34878
  requirePageBundles(
34242
- join56(fileURLToPath7(new URL(".", import.meta.url)), "page"),
34879
+ join57(fileURLToPath7(new URL(".", import.meta.url)), "page"),
34243
34880
  (line2) => fail(line2)
34244
34881
  );
34245
34882
  const answer2 = await keepInRepo(
@@ -34299,7 +34936,7 @@ async function keepInRepo(root, args2, log2) {
34299
34936
  home,
34300
34937
  wallpapersDir: WALLPAPERS_DIR,
34301
34938
  // Each output renders into a temp folder of keep's own.
34302
- outDir: tmpdir8(),
34939
+ outDir: tmpdir9(),
34303
34940
  log: log2
34304
34941
  }
34305
34942
  }
@@ -34517,7 +35154,7 @@ ${USAGE}`);
34517
35154
  );
34518
35155
  }
34519
35156
  requirePageBundles(
34520
- join56(fileURLToPath7(new URL(".", import.meta.url)), "page"),
35157
+ join57(fileURLToPath7(new URL(".", import.meta.url)), "page"),
34521
35158
  (line2) => fail(line2)
34522
35159
  );
34523
35160
  const target = route === "pr" ? await offBase(
@@ -34669,7 +35306,7 @@ switch (command) {
34669
35306
  case "setup": {
34670
35307
  if (rest.includes("--ci")) {
34671
35308
  requirePageBundles(
34672
- join56(fileURLToPath7(new URL(".", import.meta.url)), "page"),
35309
+ join57(fileURLToPath7(new URL(".", import.meta.url)), "page"),
34673
35310
  (line2) => log(line2)
34674
35311
  );
34675
35312
  const say = (l) => void process.stdout.write(`${l}
@@ -34685,7 +35322,7 @@ switch (command) {
34685
35322
  return r.ok ? { root: r.repo.root } : { none: r.none };
34686
35323
  },
34687
35324
  deps: (root) => ciDeps(root, say),
34688
- exists: (p) => existsSync5(join56(ciRoot, p)),
35325
+ exists: (p) => existsSync5(join57(ciRoot, p)),
34689
35326
  onInterrupt: (stop2) => {
34690
35327
  process.on("SIGINT", stop2);
34691
35328
  return () => void process.off("SIGINT", stop2);
@@ -34748,7 +35385,7 @@ ${USAGE}`
34748
35385
  process.exit(2);
34749
35386
  }
34750
35387
  requirePageBundles(
34751
- join56(fileURLToPath7(new URL(".", import.meta.url)), "page"),
35388
+ join57(fileURLToPath7(new URL(".", import.meta.url)), "page"),
34752
35389
  (line2) => process.stderr.write(`demoman signin: ${line2}
34753
35390
  `)
34754
35391
  );