@hyperframes/producer 0.9.93 → 0.9.94

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/index.js CHANGED
@@ -10,11 +10,11 @@ import {
10
10
  import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
11
11
  import {
12
12
  existsSync as existsSync22,
13
- mkdirSync as mkdirSync12,
13
+ mkdirSync as mkdirSync13,
14
14
  readdirSync as readdirSync6,
15
15
  rmSync as rmSync13,
16
16
  statSync as statSync10,
17
- writeFileSync as writeFileSync6,
17
+ writeFileSync as writeFileSync7,
18
18
  copyFileSync as copyFileSync5,
19
19
  appendFileSync
20
20
  } from "fs";
@@ -339,6 +339,7 @@ import {
339
339
  LOW_MEMORY_TOTAL_MB_THRESHOLD,
340
340
  assertConfiguredFfmpegBinariesExist,
341
341
  resolveBrowserGpuMode,
342
+ probedHardwareGpu,
342
343
  resolveHeadlessShellPath,
343
344
  compositionRequiresWebGpu as compositionRequiresWebGpu2,
344
345
  applyConcreteGpuScreenshotClamp,
@@ -360,7 +361,7 @@ import {
360
361
  referenceBackgroundResult,
361
362
  createReferenceBackgroundRecorder
362
363
  } from "@hyperframes/engine";
363
- import { join as join35, dirname as dirname15, resolve as resolve9 } from "path";
364
+ import { join as join35, dirname as dirname16, resolve as resolve9 } from "path";
364
365
  import { totalmem as totalmem2 } from "node:os";
365
366
  import { randomUUID as randomUUID3 } from "crypto";
366
367
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -390,7 +391,7 @@ import {
390
391
  serviceWorkerScriptFetch
391
392
  } from "@hyperframes/core/studio-preview-mark";
392
393
  import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
393
- import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
394
+ import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
394
395
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
395
396
  import { openRangeEnd } from "@hyperframes/studio-server/media-range";
396
397
 
@@ -532,7 +533,7 @@ import {
532
533
  } from "node:path";
533
534
  import { statSync } from "node:fs";
534
535
  import { fileURLToPath as fileURLToPath2 } from "node:url";
535
- import { isSafePath } from "@hyperframes/core/safe-path";
536
+ import { isPrivateFileUnder, isSafePath, isStudioPrivatePath } from "@hyperframes/core/safe-path";
536
537
  import {
537
538
  isCopiedOutsideFileType,
538
539
  isPrivateOutsideFile,
@@ -559,7 +560,10 @@ function escapesAssetRoot(path, assetRoot) {
559
560
  return assetRoot !== void 0 && !isSafePath(assetRoot, path);
560
561
  }
561
562
  function outsideAssetRefusal(projectDir, path, policy = {}) {
562
- if (!linksOutside(projectDir, path)) return null;
563
+ if (!linksOutside(projectDir, path)) {
564
+ const privateByAnotherSpelling = !isPathInside(path, projectDir) && isPrivateFileUnder(projectDir, path, isStudioPrivatePath);
565
+ return privateByAnotherSpelling ? "blocklisted" : null;
566
+ }
563
567
  if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
564
568
  const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
565
569
  if (folder || isUploadedOutsideFileType(path)) return null;
@@ -1185,7 +1189,7 @@ function createFileServer(options) {
1185
1189
  const candidate = join2(root, relativePath);
1186
1190
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
1187
1191
  if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
1188
- if (isPrivateFileUnder(root, candidate, isStudioPrivatePath)) continue;
1192
+ if (isPrivateFileUnder2(root, candidate, isStudioPrivatePath2)) continue;
1189
1193
  const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
1190
1194
  if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut, outsidePolicy)) continue;
1191
1195
  file = openRegularFile(candidate);
@@ -4129,12 +4133,12 @@ function distributeLayeredHybridFrameRanges(totalFrames, workerCount) {
4129
4133
  }
4130
4134
  return ranges;
4131
4135
  }
4132
- function partitionTransitionFrames(transitionRanges, totalFrames) {
4136
+ function partitionTransitionFrames(transitionRanges, totalFrames, firstFrame = 0) {
4133
4137
  const frames = /* @__PURE__ */ new Set();
4134
4138
  if (totalFrames <= 0) return frames;
4135
4139
  for (const range of transitionRanges) {
4136
- const start = Math.max(0, range.startFrame);
4137
- const end = Math.min(totalFrames - 1, range.endFrame);
4140
+ const start = Math.max(firstFrame, range.startFrame);
4141
+ const end = Math.min(firstFrame + totalFrames - 1, range.endFrame);
4138
4142
  for (let i = start; i <= end; i++) frames.add(i);
4139
4143
  }
4140
4144
  return frames;
@@ -4344,6 +4348,18 @@ function cleanupEndedHdrVideos(args) {
4344
4348
  }
4345
4349
  }
4346
4350
  }
4351
+ function transitionAtFrame(transitionRanges, frame) {
4352
+ return transitionRanges.find((t) => frame >= t.startFrame && frame <= t.endFrame);
4353
+ }
4354
+ function cleanupHdrVideosEndedBefore(firstFrame, fps, transitionRanges, state) {
4355
+ for (let frame = 0; frame < firstFrame; frame++) {
4356
+ cleanupEndedHdrVideos({
4357
+ ...state,
4358
+ time: frame * fps.den / fps.num,
4359
+ activeTransition: transitionAtFrame(transitionRanges, frame)
4360
+ });
4361
+ }
4362
+ }
4347
4363
 
4348
4364
  // src/services/render/segmentPlan.ts
4349
4365
  import { join as join9 } from "node:path";
@@ -6001,10 +6017,15 @@ function estimateMeasuredCaptureCostMultiplier(samples) {
6001
6017
  function shouldCalibrateSoftwareGpu(requestedMode, resolvedMode, hardware) {
6002
6018
  return requestedMode === "auto" && resolvedMode === "hardware" && hardware !== void 0 && hardware.multiplier > 1 && hardware.p95Ms !== void 0;
6003
6019
  }
6004
- function pickAutoGpuModeFromCalibration(hardware, software) {
6005
- if (hardware.p95Ms === void 0 || software?.p95Ms === void 0) return "hardware";
6020
+ function settleAutoGpuChoice(hardware, software) {
6021
+ if (hardware?.p95Ms === void 0) return void 0;
6022
+ if (hardware.multiplier <= 1) return "hardware";
6023
+ if (software?.p95Ms === void 0) return void 0;
6006
6024
  return software.p95Ms < hardware.p95Ms ? "software" : "hardware";
6007
6025
  }
6026
+ function pickAutoGpuModeFromCalibration(hardware, software) {
6027
+ return settleAutoGpuChoice(hardware, software) ?? "hardware";
6028
+ }
6008
6029
  function selectCaptureCalibrationFrames(totalFrames) {
6009
6030
  if (totalFrames <= 0) return [];
6010
6031
  const lastFrame = totalFrames - 1;
@@ -6019,8 +6040,8 @@ function selectCaptureCalibrationFrames(totalFrames) {
6019
6040
  new Set(candidates.map((frame) => Math.max(0, Math.min(lastFrame, frame))))
6020
6041
  ).sort((a, b) => a - b);
6021
6042
  }
6022
- async function measureCaptureCostFromSession(session, totalFrames, fps, log) {
6023
- const sampledFrames = selectCaptureCalibrationFrames(totalFrames);
6043
+ async function measureCaptureCostFromSession(session, totalFrames, fps, log, firstFrame = 0) {
6044
+ const sampledFrames = selectCaptureCalibrationFrames(totalFrames).map((i) => firstFrame + i);
6024
6045
  const samples = [];
6025
6046
  const totalSamples = sampledFrames.length;
6026
6047
  const savedStaticFrames = session.staticFrames;
@@ -6116,7 +6137,13 @@ async function runCaptureCalibration(input) {
6116
6137
  }
6117
6138
  assertNotAborted();
6118
6139
  log.info("Calibration session ready, capturing test frames...");
6119
- const result = await measureCaptureCostFromSession(session, totalFrames, fps, log);
6140
+ const result = await measureCaptureCostFromSession(
6141
+ session,
6142
+ totalFrames,
6143
+ fps,
6144
+ log,
6145
+ job.frameWindow?.startFrame
6146
+ );
6120
6147
  logCaptureCalibrationResult(result, log);
6121
6148
  return result;
6122
6149
  };
@@ -6677,6 +6704,57 @@ function resolveVideoCaptureBeyondViewport(videoCount) {
6677
6704
  return true;
6678
6705
  }
6679
6706
 
6707
+ // src/services/render/gpuChoice.ts
6708
+ import { mkdirSync as mkdirSync7, readFileSync as readFileSync5, renameSync, writeFileSync as writeFileSync3 } from "node:fs";
6709
+ import { dirname as dirname6 } from "node:path";
6710
+ function gpuChoiceStore(cfg, gpu) {
6711
+ if (!cfg.gpuChoiceFile || !cfg.hyperframesVersion || !gpu) return void 0;
6712
+ return { file: cfg.gpuChoiceFile, key: `${cfg.hyperframesVersion} | ${gpu}` };
6713
+ }
6714
+ function readGpuChoice(store) {
6715
+ let record;
6716
+ try {
6717
+ record = JSON.parse(readFileSync5(store.file, "utf8"));
6718
+ } catch {
6719
+ return void 0;
6720
+ }
6721
+ if (record?.key !== store.key) return void 0;
6722
+ return record.mode === "software" || record.mode === "hardware" ? record.mode : void 0;
6723
+ }
6724
+ function writeGpuChoice(store, mode, measured) {
6725
+ mkdirSync7(dirname6(store.file), { recursive: true });
6726
+ const temp = `${store.file}.${process.pid}.tmp`;
6727
+ const record = { key: store.key, mode, ...measured, measuredAt: (/* @__PURE__ */ new Date()).toISOString() };
6728
+ writeFileSync3(temp, `${JSON.stringify(record, null, 2)}
6729
+ `);
6730
+ renameSync(temp, store.file);
6731
+ }
6732
+
6733
+ // src/services/render/frameWindow.ts
6734
+ function resolveFrameWindow(range, fps, filmFrames) {
6735
+ const frameAt = (seconds) => Math.round(seconds * fps.num / fps.den);
6736
+ const startFrame = frameAt(range.startSeconds);
6737
+ const endFrame = Math.min(
6738
+ range.endSeconds === void 0 ? filmFrames : frameAt(range.endSeconds),
6739
+ filmFrames
6740
+ );
6741
+ if (!(endFrame > startFrame)) {
6742
+ throw new Error(
6743
+ `The range ${range.startSeconds}s to ${range.endSeconds ?? "the end"}s holds no frame: the film has ${filmFrames} frames at ${fps.num}/${fps.den} fps.`
6744
+ );
6745
+ }
6746
+ return { startFrame, endFrame };
6747
+ }
6748
+ function windowStartFrame(frameWindow) {
6749
+ return frameWindow?.startFrame ?? 0;
6750
+ }
6751
+ function assertRangeSupported(frameWindow, route) {
6752
+ if (!frameWindow || route === "sdr_disk" || route === "hdr_layered") return;
6753
+ throw new Error(
6754
+ `This composition renders on the "${route}" capture route, which renders the whole film only; render it without a start or end.`
6755
+ );
6756
+ }
6757
+
6680
6758
  // src/services/render/observability.ts
6681
6759
  import { createHash as createHash3 } from "node:crypto";
6682
6760
  import { redactTelemetryString } from "@hyperframes/core";
@@ -7048,7 +7126,7 @@ function emitFallbackCaptureProfile(recorder, perfSummaries, env = process.env)
7048
7126
  }
7049
7127
 
7050
7128
  // src/services/render/videoFrameCoverage.ts
7051
- import { parseHTML } from "linkedom";
7129
+ import { parseHTML } from "@hyperframes/parsers/linkedom";
7052
7130
  import {
7053
7131
  fpsToNumber as fpsToNumber5,
7054
7132
  normalizeRateSpec,
@@ -7063,7 +7141,6 @@ var SHORT_CLIP_ONE_FRAME_TOLERANCE_MIN_EXPECTED_FRAMES = 14;
7063
7141
  var SHORT_CLIP_ONE_FRAME_TOLERANCE_MAX_EXPECTED_FRAMES = 20;
7064
7142
  var VideoFrameCoverageError = class extends Error {
7065
7143
  // Read structurally by isVideoFrameCoverageError and cross-module callers.
7066
- // fallow-ignore-next-line unused-class-member
7067
7144
  hyperframesVideoFrameCoverageError = true;
7068
7145
  threshold;
7069
7146
  worst;
@@ -7166,7 +7243,7 @@ function requireOutputDimensions(expected, width, height) {
7166
7243
  }
7167
7244
 
7168
7245
  // src/services/render/stages/compileStage.ts
7169
- import { existsSync as existsSync13, writeFileSync as writeFileSync4 } from "node:fs";
7246
+ import { existsSync as existsSync13, writeFileSync as writeFileSync5 } from "node:fs";
7170
7247
  import { join as join23, relative as relative5 } from "node:path";
7171
7248
  import { privateCacheRoot } from "@hyperframes/engine";
7172
7249
  import { suggestMatchingPreset } from "@hyperframes/core";
@@ -7176,7 +7253,7 @@ import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperf
7176
7253
 
7177
7254
  // src/services/compileInWorker.ts
7178
7255
  import { existsSync as existsSync12, rmSync as rmSync11 } from "node:fs";
7179
- import { dirname as dirname10, isAbsolute as isAbsolute4, join as join22, relative as relative4, resolve as resolvePath } from "node:path";
7256
+ import { dirname as dirname11, isAbsolute as isAbsolute4, join as join22, relative as relative4, resolve as resolvePath } from "node:path";
7180
7257
  import { fileURLToPath as fileURLToPath3 } from "node:url";
7181
7258
  import { Worker } from "node:worker_threads";
7182
7259
 
@@ -7196,17 +7273,17 @@ import {
7196
7273
  stylesheetLinkMatches
7197
7274
  } from "@hyperframes/parsers/css-url-scans";
7198
7275
  import { createHash as createHash6 } from "node:crypto";
7199
- import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8, statSync as statSync8 } from "fs";
7200
- import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
7201
- import { parseHTML as parseHTML5 } from "linkedom";
7276
+ import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync10, readFileSync as readFileSync9, statSync as statSync8 } from "fs";
7277
+ import { join as join21, dirname as dirname10, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
7278
+ import { parseHTML as parseHTML5 } from "@hyperframes/parsers/linkedom";
7202
7279
 
7203
7280
  // src/services/bundledScripts.ts
7204
- import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
7281
+ import { existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
7205
7282
  import { join as join17 } from "node:path";
7206
7283
  import { GSAP_CDN_VERSION } from "@hyperframes/core/gsap-cdn";
7207
7284
  var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
7208
7285
  var DEFAULT_CDN_GSAP_3 = /^https:\/\/cdn\.jsdelivr\.net\/npm\/gsap@(3\.\d+\.\d+)\/dist\/([A-Za-z]+\.min\.js)$/;
7209
- var read = (file) => existsSync8(file) ? readFileSync5(file) : null;
7286
+ var read = (file) => existsSync8(file) ? readFileSync6(file) : null;
7210
7287
  function bundledScript(url) {
7211
7288
  const dir = process.env[GSAP_VENDOR_DIR_ENV];
7212
7289
  const [, version, file] = DEFAULT_CDN_GSAP_3.exec(url) ?? [];
@@ -7280,7 +7357,7 @@ import {
7280
7357
  readTextFile,
7281
7358
  resolveCompositionSrc
7282
7359
  } from "@hyperframes/parsers/asset-resolution";
7283
- import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
7360
+ import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
7284
7361
  import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
7285
7362
  import {
7286
7363
  assertCompositionFileSize,
@@ -7291,7 +7368,7 @@ import {
7291
7368
  } from "@hyperframes/core/compiler";
7292
7369
 
7293
7370
  // src/services/renderMediaCollector.ts
7294
- import { parseHTML as parseHTML2 } from "linkedom";
7371
+ import { parseHTML as parseHTML2 } from "@hyperframes/parsers/linkedom";
7295
7372
  import {
7296
7373
  MEDIA_RENDER_ID_ATTR,
7297
7374
  normalizeRateSpec as normalizeRateSpec2,
@@ -7483,9 +7560,9 @@ import {
7483
7560
 
7484
7561
  // src/services/animatedGifPrep.ts
7485
7562
  import { createHash as createHash4, randomUUID } from "node:crypto";
7486
- import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
7487
- import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
7488
- import { parseHTML as parseHTML3 } from "linkedom";
7563
+ import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync7, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
7564
+ import { dirname as dirname7, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
7565
+ import { parseHTML as parseHTML3 } from "@hyperframes/parsers/linkedom";
7489
7566
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
7490
7567
  import {
7491
7568
  DEFAULT_VP9_CPU_USED,
@@ -7537,7 +7614,11 @@ function resolveLocalImageSourcePath(src, options) {
7537
7614
  resolve6(options.downloadDir, normalizedBase)
7538
7615
  ];
7539
7616
  const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
7540
- const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7617
+ const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(
7618
+ candidate,
7619
+ [options.projectDir, options.downloadDir],
7620
+ options.allowOutsideFiles
7621
+ ) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7541
7622
  return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
7542
7623
  }
7543
7624
  function isUsableFile(path) {
@@ -7666,11 +7747,11 @@ async function runAnimatedGifTranscode(request) {
7666
7747
  throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
7667
7748
  }
7668
7749
  async function ensurePreparedWebm(input) {
7669
- if (!existsSync9(dirname6(input.cachePath))) {
7670
- mkdirSync7(dirname6(input.cachePath), { recursive: true });
7750
+ if (!existsSync9(dirname7(input.cachePath))) {
7751
+ mkdirSync8(dirname7(input.cachePath), { recursive: true });
7671
7752
  }
7672
- if (!existsSync9(dirname6(input.outputPath))) {
7673
- mkdirSync7(dirname6(input.outputPath), { recursive: true });
7753
+ if (!existsSync9(dirname7(input.outputPath))) {
7754
+ mkdirSync8(dirname7(input.outputPath), { recursive: true });
7674
7755
  }
7675
7756
  if (!isUsableFile(input.cachePath)) {
7676
7757
  const tmpPath = `${input.cachePath}.tmp-${process.pid}-${randomUUID()}`;
@@ -7771,7 +7852,7 @@ async function prepareAnimatedGifInputs(html, options) {
7771
7852
  if (!hasGifExtension(src)) continue;
7772
7853
  const sourcePath = resolveLocalImageSourcePath(src, options);
7773
7854
  if (!sourcePath) continue;
7774
- const bytes = readFileSync6(sourcePath);
7855
+ const bytes = readFileSync7(sourcePath);
7775
7856
  const metadata = parseAnimatedGifMetadata(bytes);
7776
7857
  if (!metadata?.animated) continue;
7777
7858
  const loopOverride = readLoopOverride(img);
@@ -7823,16 +7904,16 @@ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypt
7823
7904
  import {
7824
7905
  closeSync as closeSync5,
7825
7906
  copyFileSync as copyFileSync3,
7826
- mkdirSync as mkdirSync8,
7907
+ mkdirSync as mkdirSync9,
7827
7908
  openSync as openSync5,
7828
- readFileSync as readFileSync7,
7909
+ readFileSync as readFileSync8,
7829
7910
  readSync as readSync3,
7830
7911
  rmSync as rmSync10,
7831
7912
  statSync as statSync7,
7832
- writeFileSync as writeFileSync3
7913
+ writeFileSync as writeFileSync4
7833
7914
  } from "node:fs";
7834
- import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
7835
- import { parseHTML as parseHTML4 } from "linkedom";
7915
+ import { dirname as dirname8, join as join19, resolve as resolve7 } from "node:path";
7916
+ import { parseHTML as parseHTML4 } from "@hyperframes/parsers/linkedom";
7836
7917
  import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
7837
7918
 
7838
7919
  // src/services/heifRotation.ts
@@ -8016,7 +8097,7 @@ function primaryGrid(probed) {
8016
8097
  async function convertHeifToJpeg(request) {
8017
8098
  const probed = await probeJson(request.inputPath, true);
8018
8099
  const grid = primaryGrid(probed);
8019
- const rotation = readHeifPrimaryRotation(readFileSync7(request.inputPath));
8100
+ const rotation = readHeifPrimaryRotation(readFileSync8(request.inputPath));
8020
8101
  const filters = [];
8021
8102
  let inputs = [];
8022
8103
  let size = probed.streams?.[0];
@@ -8080,7 +8161,7 @@ function resolveImageSource(src, options) {
8080
8161
  const path = resolveLocalImageSourcePath(src, options);
8081
8162
  const head = path ? readHead(path) : null;
8082
8163
  if (!path || !head || !isHeifBytes(head)) return null;
8083
- return { path, bytes: readFileSync7(path), label: `"${splitUrlSuffix(src).basePath}"` };
8164
+ return { path, bytes: readFileSync8(path), label: `"${splitUrlSuffix(src).basePath}"` };
8084
8165
  }
8085
8166
  function isUsableFile2(path) {
8086
8167
  try {
@@ -8090,14 +8171,14 @@ function isUsableFile2(path) {
8090
8171
  }
8091
8172
  }
8092
8173
  async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
8093
- mkdirSync8(dirname7(cachePath), { recursive: true });
8094
- mkdirSync8(dirname7(outputPath), { recursive: true });
8174
+ mkdirSync9(dirname8(cachePath), { recursive: true });
8175
+ mkdirSync9(dirname8(outputPath), { recursive: true });
8095
8176
  if (!isUsableFile2(cachePath)) {
8096
8177
  const tmpPath = `${cachePath}.tmp-${process.pid}-${randomUUID2()}`;
8097
8178
  const inlinePath = `${tmpPath}.heic`;
8098
8179
  const inputPath = source.path ?? inlinePath;
8099
8180
  try {
8100
- if (!source.path) writeFileSync3(inlinePath, source.bytes);
8181
+ if (!source.path) writeFileSync4(inlinePath, source.bytes);
8101
8182
  await (options.transcode ?? convertHeifToJpeg)({
8102
8183
  inputPath,
8103
8184
  outputPath: tmpPath,
@@ -8170,7 +8251,7 @@ import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position
8170
8251
 
8171
8252
  // src/services/assetMediaType.ts
8172
8253
  import { existsSync as existsSync10 } from "node:fs";
8173
- import { dirname as dirname8, join as join20 } from "node:path";
8254
+ import { dirname as dirname9, join as join20 } from "node:path";
8174
8255
  import {
8175
8256
  fingerprintElementId,
8176
8257
  isHttpUrl as isHttpUrl2,
@@ -8224,7 +8305,7 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
8224
8305
  ]);
8225
8306
  }
8226
8307
  function mediaAssetRoots(projectDir, compiledDir) {
8227
- return [projectDir, compiledDir, join20(dirname8(compiledDir), "downloads")];
8308
+ return [projectDir, compiledDir, join20(dirname9(compiledDir), "downloads")];
8228
8309
  }
8229
8310
  function dropMediaOutsideProject(input) {
8230
8311
  const { projectDir, workDir, composition, log } = input;
@@ -8233,7 +8314,7 @@ function dropMediaOutsideProject(input) {
8233
8314
  const staysInside = ({ id, src }) => {
8234
8315
  if (!src || isHttpUrl2(src)) return true;
8235
8316
  const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
8236
- if (isPrivateUnderAssetRoots2(path, roots)) {
8317
+ if (isPrivateUnderAssetRoots2(path, roots, input.allowOutsideProjectAssets)) {
8237
8318
  log.warn(`[Render] Media "${id}" source is missing: it is a private project file`, { src });
8238
8319
  return false;
8239
8320
  }
@@ -8403,7 +8484,7 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
8403
8484
  throw new EmptyCompositionError([{ srcPath, detail: OUTSIDE_COMPOSITION_NEEDS_FLAG }]);
8404
8485
  }
8405
8486
  }
8406
- var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
8487
+ var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder3(projectDir, filePath, isStudioPrivatePath3);
8407
8488
  function compositionSrcsIn(html) {
8408
8489
  const { document: document2 } = parseHTML5(html);
8409
8490
  const mounts = [];
@@ -8729,7 +8810,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
8729
8810
  let filePath = src;
8730
8811
  if (isHttpUrl(src)) {
8731
8812
  const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
8732
- if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
8813
+ if (!existsSync11(remoteDir)) mkdirSync10(remoteDir, { recursive: true });
8733
8814
  run?.assets.reserve([src]);
8734
8815
  try {
8735
8816
  filePath = await downloadAsset(src, remoteDir, run?.assets);
@@ -8740,7 +8821,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
8740
8821
  } else {
8741
8822
  filePath = decodedUrlPath(src);
8742
8823
  if (!filePath.startsWith("/")) filePath = join21(baseDir, filePath);
8743
- if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir])) {
8824
+ if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir], assetRoot === void 0)) {
8744
8825
  return { duration: null, resolvedPath: filePath };
8745
8826
  }
8746
8827
  filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
@@ -8923,7 +9004,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
8923
9004
  const { html: compiledSub } = await compileHtmlFile(
8924
9005
  rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
8925
9006
  projectDir,
8926
- dirname9(item.filePath),
9007
+ dirname10(item.filePath),
8927
9008
  downloadDir,
8928
9009
  void 0,
8929
9010
  urlByAbsentLocalPath,
@@ -9496,7 +9577,7 @@ var REMOTE_MEDIA_SUBDIR = "_remote_media";
9496
9577
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, assets, extraRewrite) {
9497
9578
  assets?.reserve(urlSet);
9498
9579
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
9499
- if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
9580
+ if (!existsSync11(remoteDir)) mkdirSync10(remoteDir, { recursive: true });
9500
9581
  const urlToLocal = /* @__PURE__ */ new Map();
9501
9582
  await Promise.all(
9502
9583
  [...urlSet].map(async (url) => {
@@ -9693,11 +9774,11 @@ function projectStylesheetFontFamilies(html, projectDir) {
9693
9774
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
9694
9775
  const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
9695
9776
  if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
9696
- for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
9777
+ for (const face of extractFontFaceBlocks(readFileSync9(sheet, "utf8"))) {
9697
9778
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
9698
9779
  const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
9699
9780
  const path = decodedUrlPath(url);
9700
- const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname9(sheet), path);
9781
+ const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname10(sheet), path);
9701
9782
  return isPathInside(file, projectDir) && existsSync11(file);
9702
9783
  });
9703
9784
  if (family && shipsFile) families.push(family);
@@ -10143,7 +10224,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
10143
10224
  for (const video of videos) {
10144
10225
  if (isHttpUrl(video.src)) continue;
10145
10226
  const videoPath = resolve8(projectDir, video.src);
10146
- if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
10227
+ if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir], assetRoot === void 0))
10147
10228
  continue;
10148
10229
  advised.add(videoPath);
10149
10230
  const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
@@ -10609,7 +10690,7 @@ function resolveCompileWorkerEntry(explicit, log) {
10609
10690
  }
10610
10691
  return void 0;
10611
10692
  }
10612
- const sibling = join22(dirname10(fileURLToPath3(import.meta.url)), "compileWorker.js");
10693
+ const sibling = join22(dirname11(fileURLToPath3(import.meta.url)), "compileWorker.js");
10613
10694
  return existsSync12(sibling) ? sibling : void 0;
10614
10695
  }
10615
10696
  function rebuildError({ name, message, stack, props }) {
@@ -10761,7 +10842,7 @@ function resolveEntryHtmlPath(input) {
10761
10842
  );
10762
10843
  }
10763
10844
  const wrapperPath = join23(workDir, "standalone-entry.html");
10764
- writeFileSync4(wrapperPath, standaloneHtml, "utf-8");
10845
+ writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
10765
10846
  log.info("Extracted standalone entry from index.html host context", { entryFile });
10766
10847
  return wrapperPath;
10767
10848
  }
@@ -10919,7 +11000,7 @@ async function runCompileStage(input) {
10919
11000
  // src/services/render/stages/probeStage.ts
10920
11001
  import { createHash as createHash7 } from "node:crypto";
10921
11002
  import { basename as basename7, join as join24 } from "node:path";
10922
- import { parseHTML as parseHTML6 } from "linkedom";
11003
+ import { parseHTML as parseHTML6 } from "@hyperframes/parsers/linkedom";
10923
11004
  import {
10924
11005
  closeCaptureSession as closeCaptureSession4,
10925
11006
  compositionRequiresWebGpu,
@@ -12426,7 +12507,7 @@ import {
12426
12507
 
12427
12508
  // src/services/render/audioDeliveryLimit.ts
12428
12509
  import { existsSync as existsSync16 } from "node:fs";
12429
- import { dirname as dirname12, join as join27 } from "node:path";
12510
+ import { dirname as dirname13, join as join27 } from "node:path";
12430
12511
  import {
12431
12512
  applyAudioFxChain,
12432
12513
  describeFfmpegFailure as describeFfmpegFailure3,
@@ -12437,7 +12518,7 @@ import {
12437
12518
  // src/services/render/audioPadTrim.ts
12438
12519
  import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
12439
12520
  import { spawn } from "node:child_process";
12440
- import { dirname as dirname11, join as join26 } from "node:path";
12521
+ import { dirname as dirname12, join as join26 } from "node:path";
12441
12522
  import {
12442
12523
  DEFAULT_CONFIG,
12443
12524
  describeFfmpegFailure as describeFfmpegFailure2,
@@ -12732,7 +12813,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
12732
12813
  async function enforceAacTruePeak(input) {
12733
12814
  let scratchDir;
12734
12815
  try {
12735
- scratchDir = createStagingDir3(dirname11(input.audioPath), ".true-peak-");
12816
+ scratchDir = createStagingDir3(dirname12(input.audioPath), ".true-peak-");
12736
12817
  const correctedPath = join26(scratchDir, "audio.m4a");
12737
12818
  const measurements = [];
12738
12819
  let attenuationDb = 0;
@@ -12956,7 +13037,7 @@ async function limitDeliveryPeaks(input, deps = {
12956
13037
  const peak = await deps.measure(audioPath, { timeoutMs, signal });
12957
13038
  if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
12958
13039
  const alternating = ["a", "b"].map(
12959
- (k) => join27(dirname12(sourcePath), `audio-source-limited-${k}.wav`)
13040
+ (k) => join27(dirname13(sourcePath), `audio-source-limited-${k}.wav`)
12960
13041
  );
12961
13042
  let encodedFrom;
12962
13043
  let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
@@ -13030,10 +13111,15 @@ function runAudioStage(input) {
13030
13111
  async function runAudioStageScoped(input) {
13031
13112
  const stageStart = Date.now();
13032
13113
  const pcmSourcePath = join28(input.workDir, "audio-source.wav");
13033
- const duration = input.totalFrames * input.fps.den / input.fps.num;
13114
+ const seconds = (frames) => frames * input.fps.den / input.fps.num;
13115
+ const duration = seconds(input.totalFrames);
13116
+ const window2 = input.frameWindow && {
13117
+ startSeconds: seconds(input.frameWindow.startFrame),
13118
+ durationSeconds: seconds(input.frameWindow.endFrame - input.frameWindow.startFrame)
13119
+ };
13034
13120
  let deliverySourcePath;
13035
13121
  try {
13036
- const result = await mixAudioForDelivery(input, duration, pcmSourcePath);
13122
+ const result = await mixAudioForDelivery(input, duration, pcmSourcePath, window2);
13037
13123
  let audioLoweredDb;
13038
13124
  if (result.hasAudio) {
13039
13125
  const guardStart = Date.now();
@@ -13041,7 +13127,7 @@ async function runAudioStageScoped(input) {
13041
13127
  input,
13042
13128
  result.audioOutputPath,
13043
13129
  pcmSourcePath,
13044
- duration
13130
+ window2?.durationSeconds ?? duration
13045
13131
  );
13046
13132
  audioLoweredDb = guard.loweredDb;
13047
13133
  input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
@@ -13079,7 +13165,7 @@ async function guardDeliveryPeaks(input, audioPath, sourcePath, duration) {
13079
13165
  if (!peak.success) throw encoderFailureError("Audio true-peak check failed", peak);
13080
13166
  return { loweredDb: peak.loweredDb, sourceStale: peak.sourceStale };
13081
13167
  }
13082
- async function mixAudioForDelivery(input, duration, pcmSourcePath) {
13168
+ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
13083
13169
  const {
13084
13170
  projectDir,
13085
13171
  workDir,
@@ -13116,6 +13202,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
13116
13202
  urlByAbsentLocalPath,
13117
13203
  audioSidecarUrlByLocalPath,
13118
13204
  keepEncoderInputAt: pcmSourcePath,
13205
+ window: window2,
13119
13206
  assetRoots: input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir)
13120
13207
  },
13121
13208
  compiledDir
@@ -13523,7 +13610,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
13523
13610
  assertNotAborted();
13524
13611
  const absoluteIdx = rangeStart + i;
13525
13612
  const time = absoluteIdx * job.config.fps.den / job.config.fps.num;
13526
- const { encodeResult } = await captureFrameToBufferPipelined2(session, i, time);
13613
+ const { encodeResult } = await captureFrameToBufferPipelined2(session, absoluteIdx, time);
13527
13614
  await drainPrev();
13528
13615
  prev = { fileIndex: i, encodeResult };
13529
13616
  }
@@ -13533,7 +13620,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
13533
13620
  assertNotAborted();
13534
13621
  const absoluteIdx = rangeStart + i;
13535
13622
  const time = absoluteIdx * job.config.fps.den / job.config.fps.num;
13536
- await captureFrame(session, i, time);
13623
+ await captureFrame(session, absoluteIdx, time, i);
13537
13624
  reportFrame(i);
13538
13625
  }
13539
13626
  }
@@ -13552,7 +13639,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
13552
13639
  }
13553
13640
 
13554
13641
  // src/services/render/stages/captureHdrStage.ts
13555
- import { existsSync as existsSync20, mkdirSync as mkdirSync10 } from "node:fs";
13642
+ import { existsSync as existsSync20, mkdirSync as mkdirSync11 } from "node:fs";
13556
13643
  import { join as join33 } from "node:path";
13557
13644
  import {
13558
13645
  closeCaptureSession as closeCaptureSession7,
@@ -13664,9 +13751,18 @@ async function runSequentialLayeredFrameLoop(input) {
13664
13751
  output: Buffer.alloc(bufSize)
13665
13752
  } : null;
13666
13753
  const normalCanvas = Buffer.alloc(bufSize);
13754
+ const firstFrame = windowStartFrame(job.frameWindow);
13755
+ cleanupHdrVideosEndedBefore(firstFrame, job.config.fps, transitionRanges, {
13756
+ hdrVideoEndTimes,
13757
+ cleanedUpVideos,
13758
+ hdrVideoFrameSources,
13759
+ sceneElements,
13760
+ log
13761
+ });
13667
13762
  for (let i = 0; i < totalFrames; i++) {
13668
13763
  assertNotAborted();
13669
- const time = i * job.config.fps.den / job.config.fps.num;
13764
+ const frame = firstFrame + i;
13765
+ const time = frame * job.config.fps.den / job.config.fps.num;
13670
13766
  if (hdrPerf) hdrPerf.frames += 1;
13671
13767
  const stackingInfo = await seekInjectAndQueryStacking(
13672
13768
  domSession.page,
@@ -13678,11 +13774,11 @@ async function runSequentialLayeredFrameLoop(input) {
13678
13774
  "frameInjectMs",
13679
13775
  "stackingQueryMs"
13680
13776
  );
13681
- const activeTransition = transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame);
13777
+ const activeTransition = transitionAtFrame(transitionRanges, frame);
13682
13778
  if (i % 30 === 0 && (log.isLevelEnabled?.("debug") ?? true)) {
13683
13779
  const hdrEl = stackingInfo.find((e) => e.isHdr);
13684
13780
  log.debug("[Render] HDR layer composite frame", {
13685
- frame: i,
13781
+ frame,
13686
13782
  time: time.toFixed(2),
13687
13783
  hdrElement: hdrEl ? { z: hdrEl.zIndex, visible: hdrEl.visible, width: hdrEl.width } : null,
13688
13784
  stackingCount: stackingInfo.length,
@@ -13692,7 +13788,7 @@ async function runSequentialLayeredFrameLoop(input) {
13692
13788
  if (activeTransition && transitionBuffers) {
13693
13789
  if (hdrPerf) hdrPerf.transitionFrames += 1;
13694
13790
  const transitionTimingStart = Date.now();
13695
- const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (i - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
13791
+ const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (frame - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
13696
13792
  const sceneAIds = new Set(sceneElements[activeTransition.fromScene] ?? []);
13697
13793
  const sceneBIds = new Set(sceneElements[activeTransition.toScene] ?? []);
13698
13794
  timeHdrPhase(hdrPerf, "canvasClearMs", () => {
@@ -13721,7 +13817,7 @@ async function runSequentialLayeredFrameLoop(input) {
13721
13817
  hdrTargetTransfer,
13722
13818
  hdrPerf,
13723
13819
  log,
13724
- frameIdx: i
13820
+ frameIdx: frame
13725
13821
  });
13726
13822
  }
13727
13823
  const shaderName = activeTransition.shader;
@@ -13746,7 +13842,7 @@ async function runSequentialLayeredFrameLoop(input) {
13746
13842
  await timeHdrPhaseAsync(
13747
13843
  hdrPerf,
13748
13844
  "normalCompositeMs",
13749
- () => compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, void 0, i)
13845
+ () => compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, void 0, frame)
13750
13846
  );
13751
13847
  if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
13752
13848
  writeFileExclusiveSync(
@@ -13796,7 +13892,7 @@ import {
13796
13892
  // src/services/shaderTransitionWorkerPool.ts
13797
13893
  import { Worker as Worker2 } from "node:worker_threads";
13798
13894
  import { fileURLToPath as fileURLToPath4, pathToFileURL } from "node:url";
13799
- import { dirname as dirname13, join as join31 } from "node:path";
13895
+ import { dirname as dirname14, join as join31 } from "node:path";
13800
13896
  import { createRequire } from "node:module";
13801
13897
  import { usableCpuCount } from "@hyperframes/engine";
13802
13898
  import { existsSync as existsSync19 } from "node:fs";
@@ -13809,7 +13905,7 @@ function resolveWorkerEntry(explicit) {
13809
13905
  const isTs = override.endsWith(".ts");
13810
13906
  return { path: override, isTs };
13811
13907
  }
13812
- const moduleDir = dirname13(fileURLToPath4(import.meta.url));
13908
+ const moduleDir = dirname14(fileURLToPath4(import.meta.url));
13813
13909
  const jsPath = join31(moduleDir, "shaderTransitionWorker.js");
13814
13910
  if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
13815
13911
  const tsPath = join31(moduleDir, "shaderTransitionWorker.ts");
@@ -14017,7 +14113,8 @@ async function runHybridLayeredFrameLoop(input) {
14017
14113
  assertNotAborted,
14018
14114
  onProgress
14019
14115
  } = input;
14020
- const transitionFramesSet = partitionTransitionFrames(transitionRanges, totalFrames);
14116
+ const firstFrame = windowStartFrame(job.frameWindow);
14117
+ const transitionFramesSet = partitionTransitionFrames(transitionRanges, totalFrames, firstFrame);
14021
14118
  const hasTransitions = transitionRanges.length > 0;
14022
14119
  const bufSize = width * height * 6;
14023
14120
  const workerSessions = [];
@@ -14108,8 +14205,9 @@ async function runHybridLayeredFrameLoop(input) {
14108
14205
  for (let i = range.start; i < range.end; i++) {
14109
14206
  throwIfFailed();
14110
14207
  assertNotAborted();
14111
- const time = i * job.config.fps.den / job.config.fps.num;
14112
- const activeTransition = transitionFramesSet.has(i) ? transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame) : void 0;
14208
+ const frame = firstFrame + i;
14209
+ const time = frame * job.config.fps.den / job.config.fps.num;
14210
+ const activeTransition = transitionFramesSet.has(frame) ? transitionAtFrame(transitionRanges, frame) : void 0;
14113
14211
  if (activeTransition && ring) {
14114
14212
  const slot = nextRingIdx;
14115
14213
  nextRingIdx = (nextRingIdx + 1) % TRANSITION_RING_DEPTH;
@@ -14120,7 +14218,7 @@ async function runHybridLayeredFrameLoop(input) {
14120
14218
  if (!buffers) continue;
14121
14219
  await captureTransitionFrameOnWorker({
14122
14220
  session,
14123
- frameIdx: i,
14221
+ frameIdx: frame,
14124
14222
  time,
14125
14223
  transition: activeTransition,
14126
14224
  buffers,
@@ -14135,7 +14233,7 @@ async function runHybridLayeredFrameLoop(input) {
14135
14233
  hdrPerf,
14136
14234
  log
14137
14235
  });
14138
- const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (i - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
14236
+ const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (frame - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
14139
14237
  const frameIdx = i;
14140
14238
  const shaderName = activeTransition.shader;
14141
14239
  const dispatch = (async () => {
@@ -14186,7 +14284,7 @@ async function runHybridLayeredFrameLoop(input) {
14186
14284
  await timeHdrPhaseAsync(
14187
14285
  hdrPerf,
14188
14286
  "normalCompositeMs",
14189
- () => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
14287
+ () => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, frame)
14190
14288
  );
14191
14289
  if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
14192
14290
  writeFileExclusiveSync(
@@ -14396,7 +14494,7 @@ async function runCaptureHdrStage(input) {
14396
14494
  const debugDumpEnabled = process.env.KEEP_TEMP === "1";
14397
14495
  const debugDumpDir = debugDumpEnabled ? join33(framesDir, "debug-composite") : null;
14398
14496
  if (debugDumpDir && !existsSync20(debugDumpDir)) {
14399
- mkdirSync10(debugDumpDir, { recursive: true });
14497
+ mkdirSync11(debugDumpDir, { recursive: true });
14400
14498
  }
14401
14499
  const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
14402
14500
  const hdrTargetTransfer = compositeTransfer === "srgb" ? void 0 : compositeTransfer;
@@ -14424,7 +14522,11 @@ async function runCaptureHdrStage(input) {
14424
14522
  hdrPerf
14425
14523
  };
14426
14524
  const effectiveWorkerCount = Math.max(1, workerCount);
14427
- const transitionFrameCount = partitionTransitionFrames(transitionRanges, totalFrames).size;
14525
+ const transitionFrameCount = partitionTransitionFrames(
14526
+ transitionRanges,
14527
+ totalFrames,
14528
+ windowStartFrame(job.frameWindow)
14529
+ ).size;
14428
14530
  const useHybrid = shouldUseHybridLayeredPath({
14429
14531
  hasHdrContent,
14430
14532
  transitionFramesCount: transitionFrameCount,
@@ -14555,15 +14657,15 @@ async function runCaptureHdrStage(input) {
14555
14657
  import {
14556
14658
  copyFileSync as copyFileSync4,
14557
14659
  existsSync as existsSync21,
14558
- mkdirSync as mkdirSync11,
14660
+ mkdirSync as mkdirSync12,
14559
14661
  readdirSync as readdirSync5,
14560
- readFileSync as readFileSync9,
14662
+ readFileSync as readFileSync10,
14561
14663
  rmSync as rmSync12,
14562
14664
  statSync as statSync9,
14563
- writeFileSync as writeFileSync5
14665
+ writeFileSync as writeFileSync6
14564
14666
  } from "node:fs";
14565
14667
  import { readFile as readFile2 } from "node:fs/promises";
14566
- import { dirname as dirname14, join as join34 } from "node:path";
14668
+ import { dirname as dirname15, join as join34 } from "node:path";
14567
14669
  import {
14568
14670
  encodeFramesChunkedConcat,
14569
14671
  encodeFramesFromDir,
@@ -14651,12 +14753,12 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
14651
14753
  const error = formatFfmpegError(result.exitCode, result.stderr);
14652
14754
  return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
14653
14755
  }
14654
- const gif = readFileSync9(outputPath);
14756
+ const gif = readFileSync10(outputPath);
14655
14757
  if (!clearGifFramesBeforeNext(gif)) {
14656
14758
  const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
14657
14759
  return gifEncodeFailure(startTime, outputPath, error);
14658
14760
  }
14659
- writeFileSync5(outputPath, gif);
14761
+ writeFileSync6(outputPath, gif);
14660
14762
  return null;
14661
14763
  }
14662
14764
  async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
@@ -14684,7 +14786,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
14684
14786
  return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
14685
14787
  }
14686
14788
  }
14687
- if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(readFileSync9(outputPath)) !== false) {
14789
+ if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(readFileSync10(outputPath)) !== false) {
14688
14790
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
14689
14791
  if (failure) return failure;
14690
14792
  }
@@ -14857,7 +14959,7 @@ async function runEncodeStage(input) {
14857
14959
  const stage5Start = Date.now();
14858
14960
  if (isPngSequence) {
14859
14961
  const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
14860
- if (!existsSync21(outputPath)) mkdirSync11(outputPath, { recursive: true });
14962
+ if (!existsSync21(outputPath)) mkdirSync12(outputPath, { recursive: true });
14861
14963
  const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
14862
14964
  if (captured.length === 0) {
14863
14965
  throw new Error(
@@ -14889,7 +14991,7 @@ async function runEncodeStage(input) {
14889
14991
  const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
14890
14992
  fps: job.config.fps,
14891
14993
  loop,
14892
- palettePath: join34(dirname14(videoOnlyPath), "gif-palette.png"),
14994
+ palettePath: join34(dirname15(videoOnlyPath), "gif-palette.png"),
14893
14995
  preserveAlpha: needsAlpha,
14894
14996
  signal: abortSignal,
14895
14997
  timeout: engineCfg.ffmpegEncodeTimeout
@@ -15343,7 +15445,7 @@ function getNextRetryWorkerCount(currentWorkers) {
15343
15445
  }
15344
15446
  function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir3()) {
15345
15447
  if (platform2 === "win32" || platform2 === "darwin") return join35(systemTempDir, "hf-render-");
15346
- return join35(dirname15(outputPath), `work-${jobId}-`);
15448
+ return join35(dirname16(outputPath), `work-${jobId}-`);
15347
15449
  }
15348
15450
  var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
15349
15451
  function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
@@ -16071,7 +16173,7 @@ function deVerifyFallbackTelemetry(err) {
16071
16173
  };
16072
16174
  }
16073
16175
  function resolveRenderDebugDir() {
16074
- const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(dirname15(fileURLToPath5(import.meta.url)), "../..");
16176
+ const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(dirname16(fileURLToPath5(import.meta.url)), "../..");
16075
16177
  return join35(producerRoot, ".debug");
16076
16178
  }
16077
16179
  async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
@@ -16079,8 +16181,8 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
16079
16181
  validateDeliveryEncoderConfig(job.config);
16080
16182
  validateChromaSubsamplingConfig(job.config);
16081
16183
  const debugDir = resolveRenderDebugDir();
16082
- const outputDir = dirname15(outputPath);
16083
- if (!existsSync22(outputDir)) mkdirSync12(outputDir, { recursive: true });
16184
+ const outputDir = dirname16(outputPath);
16185
+ if (!existsSync22(outputDir)) mkdirSync13(outputDir, { recursive: true });
16084
16186
  const workDir = job.config.debug ? join35(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
16085
16187
  const pipelineStart = Date.now();
16086
16188
  const baseLog = job.config.logger ?? defaultLogger;
@@ -16237,7 +16339,7 @@ async function executeRenderPipeline(input) {
16237
16339
  job.startedAt = /* @__PURE__ */ new Date();
16238
16340
  assertNotAborted();
16239
16341
  assertConfiguredFfmpegBinariesExist();
16240
- if (!existsSync22(workDir)) mkdirSync12(workDir, { recursive: true });
16342
+ if (!existsSync22(workDir)) mkdirSync13(workDir, { recursive: true });
16241
16343
  if (job.config.debug) {
16242
16344
  log.info("[Render] Debug artifacts enabled", { workDir, logPath });
16243
16345
  }
@@ -16406,15 +16508,18 @@ async function executeRenderPipeline(input) {
16406
16508
  if (resolvedCaptureBeyondViewport !== void 0) {
16407
16509
  updateCaptureObservability({ captureBeyondViewport: resolvedCaptureBeyondViewport });
16408
16510
  }
16409
- job.duration = probeResult.duration;
16410
- job.totalFrames = probeResult.totalFrames;
16411
- const totalFrames = probeResult.totalFrames;
16412
- captureTotalFrames = totalFrames;
16413
16511
  validateRenderDuration({
16414
16512
  duration: probeResult.duration,
16415
- totalFrames,
16513
+ totalFrames: probeResult.totalFrames,
16416
16514
  fps: fpsToNumber8(job.config.fps)
16417
16515
  });
16516
+ const frameWindow = job.config.range ? resolveFrameWindow(job.config.range, job.config.fps, probeResult.totalFrames) : void 0;
16517
+ job.frameWindow = frameWindow;
16518
+ if (frameWindow) cfg.enableStreamingEncode = false;
16519
+ const totalFrames = frameWindow ? frameWindow.endFrame - frameWindow.startFrame : probeResult.totalFrames;
16520
+ job.totalFrames = totalFrames;
16521
+ job.duration = frameWindow ? totalFrames * job.config.fps.den / job.config.fps.num : probeResult.duration;
16522
+ captureTotalFrames = totalFrames;
16418
16523
  const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(
16419
16524
  probeSession.page,
16420
16525
  largerThanCanvas,
@@ -16595,6 +16700,7 @@ async function executeRenderPipeline(input) {
16595
16700
  workDir,
16596
16701
  compiledDir,
16597
16702
  totalFrames: probeResult.totalFrames,
16703
+ ...frameWindow && { frameWindow },
16598
16704
  fps: job.config.fps,
16599
16705
  ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
16600
16706
  audioGain: cfg.audioGain,
@@ -16641,7 +16747,7 @@ async function executeRenderPipeline(input) {
16641
16747
  throw new Error("File server failed to initialize before frame capture");
16642
16748
  }
16643
16749
  const framesDir = join35(workDir, "captured-frames");
16644
- if (!existsSync22(framesDir)) mkdirSync12(framesDir, { recursive: true });
16750
+ if (!existsSync22(framesDir)) mkdirSync13(framesDir, { recursive: true });
16645
16751
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
16646
16752
  code: "start_browsers"
16647
16753
  });
@@ -16649,6 +16755,23 @@ async function executeRenderPipeline(input) {
16649
16755
  chromePath: resolveHeadlessShellPath(cfg),
16650
16756
  browserTimeout: cfg.browserTimeout
16651
16757
  });
16758
+ const closeProbeSession = async () => {
16759
+ if (!probeSession) return;
16760
+ lastBrowserConsole = probeSession.browserConsoleBuffer;
16761
+ await closeCaptureSession8(probeSession).catch(() => {
16762
+ });
16763
+ probeSession = null;
16764
+ };
16765
+ const gpuStore = cfg.browserGpuMode === "auto" && resolvedBrowserGpuMode === "hardware" ? gpuChoiceStore(cfg, await probedHardwareGpu()) : void 0;
16766
+ const storedGpuChoice = gpuStore && readGpuChoice(gpuStore);
16767
+ if (gpuStore && storedGpuChoice === "software") {
16768
+ log.info("[Render] Auto GPU mode: rendering in software, as measured on this machine.", {
16769
+ file: gpuStore.file
16770
+ });
16771
+ cfg.browserGpuMode = "software";
16772
+ resolvedBrowserGpuMode = "software";
16773
+ await closeProbeSession();
16774
+ }
16652
16775
  startingFrameCapture();
16653
16776
  captureForceScreenshot = applyConcreteGpuScreenshotClamp(
16654
16777
  captureForceScreenshot,
@@ -16885,6 +17008,10 @@ async function executeRenderPipeline(input) {
16885
17008
  totalMemoryMb: Math.round(totalmem2() / (1024 * 1024)),
16886
17009
  minMemoryMb: deParallelMinMemoryMb
16887
17010
  });
17011
+ if (frameWindow) {
17012
+ deInversionEligible = false;
17013
+ deParallelRouterEligible = false;
17014
+ }
16888
17015
  if (probeSession === null && (deInversionEligible || deParallelRouterEligible)) {
16889
17016
  try {
16890
17017
  probeSession = await createCaptureSession8(
@@ -16949,7 +17076,9 @@ async function executeRenderPipeline(input) {
16949
17076
  return "beginFrame";
16950
17077
  }
16951
17078
  });
16952
- if (job.config.workers === void 0 && totalFrames >= 60 && !htmlInCanvasDetected && !cfg.lowMemoryMode && !deInversionEligible && !deParallelRouterEligible) {
17079
+ const sizeByCalibration = job.config.workers === void 0 && totalFrames >= 60 && !htmlInCanvasDetected && !cfg.lowMemoryMode && !deInversionEligible && !deParallelRouterEligible;
17080
+ const measureGpuChoice = gpuStore !== void 0 && storedGpuChoice === void 0;
17081
+ if (sizeByCalibration || measureGpuChoice) {
16953
17082
  updateJobStatus(job, "rendering", "Measuring capture speed", 25, onProgress, {
16954
17083
  code: "start_browsers"
16955
17084
  });
@@ -16989,7 +17118,7 @@ async function executeRenderPipeline(input) {
16989
17118
  probeSession
16990
17119
  });
16991
17120
  probeSession = result.probeSession;
16992
- if (shouldCalibrateSoftwareGpu(
17121
+ if (storedGpuChoice === void 0 && shouldCalibrateSoftwareGpu(
16993
17122
  cfg.browserGpuMode,
16994
17123
  resolvedBrowserGpuMode,
16995
17124
  result.calibration?.estimate
@@ -17014,7 +17143,7 @@ async function executeRenderPipeline(input) {
17014
17143
  calibrationFrames?.release();
17015
17144
  }
17016
17145
  startingFrameCapture();
17017
- captureCalibration = outcome.calibration;
17146
+ if (sizeByCalibration) captureCalibration = outcome.calibration;
17018
17147
  calibrationEvaluateTimedOut = outcome.calibrationEvaluateTimedOut;
17019
17148
  captureForceScreenshot = outcome.forceScreenshot;
17020
17149
  updateCaptureObservability({ forceScreenshot: captureForceScreenshot });
@@ -17034,19 +17163,31 @@ async function executeRenderPipeline(input) {
17034
17163
  );
17035
17164
  cfg.browserGpuMode = "software";
17036
17165
  resolvedBrowserGpuMode = "software";
17037
- captureCalibration = softwareOutcome.calibration;
17166
+ if (sizeByCalibration) captureCalibration = softwareOutcome.calibration;
17038
17167
  captureForceScreenshot = softwareOutcome.forceScreenshot;
17039
- if (probeSession) {
17040
- lastBrowserConsole = probeSession.browserConsoleBuffer;
17041
- await closeCaptureSession8(probeSession).catch(() => {
17042
- });
17043
- probeSession = null;
17044
- }
17168
+ await closeProbeSession();
17045
17169
  updateCaptureObservability({
17046
17170
  browserGpuMode: resolvedBrowserGpuMode,
17047
17171
  forceScreenshot: captureForceScreenshot
17048
17172
  });
17049
17173
  }
17174
+ const settledGpuChoice = measureGpuChoice ? settleAutoGpuChoice(outcome.calibration?.estimate, softwareOutcome?.calibration?.estimate) : void 0;
17175
+ if (gpuStore && settledGpuChoice) {
17176
+ try {
17177
+ writeGpuChoice(gpuStore, settledGpuChoice, {
17178
+ hardwareP95Ms: outcome.calibration?.estimate.p95Ms,
17179
+ softwareP95Ms: softwareOutcome?.calibration?.estimate.p95Ms
17180
+ });
17181
+ } catch (error) {
17182
+ log.warn(
17183
+ "[Render] Could not save the measured GPU choice; the next render measures again.",
17184
+ {
17185
+ file: gpuStore.file,
17186
+ error: error instanceof Error ? error.message : String(error)
17187
+ }
17188
+ );
17189
+ }
17190
+ }
17050
17191
  observability.checkpoint("capture_calibration", "resolved", {
17051
17192
  forceScreenshot: captureForceScreenshot,
17052
17193
  browserGpuMode: resolvedBrowserGpuMode,
@@ -17402,6 +17543,7 @@ async function executeRenderPipeline(input) {
17402
17543
  });
17403
17544
  const syncCapturePlan = () => {
17404
17545
  assertMotionBlurSupported(job.config.motionBlur, capturePlan.kind);
17546
+ assertRangeSupported(job.frameWindow, capturePlan.kind);
17405
17547
  assertOutputScaleSupported(deviceScaleFactor, capturePlan.kind);
17406
17548
  workerCount = capturePlan.workerCount;
17407
17549
  captureForceScreenshot = capturePlan.forceScreenshot;
@@ -17987,6 +18129,7 @@ async function executeRenderPipeline(input) {
17987
18129
  framesDir,
17988
18130
  job,
17989
18131
  totalFrames,
18132
+ ...job.frameWindow && { frameRange: job.frameWindow },
17990
18133
  cfg,
17991
18134
  plan: diskPlan,
17992
18135
  log,
@@ -18027,7 +18170,7 @@ async function executeRenderPipeline(input) {
18027
18170
  "drawElement capture failed; retrying with a fresh screenshot session"
18028
18171
  );
18029
18172
  rmSync13(framesDir, { recursive: true, force: true });
18030
- mkdirSync12(framesDir, { recursive: true });
18173
+ mkdirSync13(framesDir, { recursive: true });
18031
18174
  resetCaptureAttemptProgress(job);
18032
18175
  dedupPerfs.length = 0;
18033
18176
  cfg.useDrawElement = false;
@@ -18206,7 +18349,7 @@ async function executeRenderPipeline(input) {
18206
18349
  job.perfSummary = perfSummary;
18207
18350
  if (job.config.debug) {
18208
18351
  try {
18209
- writeFileSync6(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
18352
+ writeFileSync7(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
18210
18353
  } catch (err) {
18211
18354
  log.debug("Failed to write perf summary", {
18212
18355
  perfOutputPath,
@@ -18335,15 +18478,15 @@ import {
18335
18478
  REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD4,
18336
18479
  referenceBackgroundResult as referenceBackgroundResult6
18337
18480
  } from "@hyperframes/engine";
18338
- import { mkdirSync as mkdirSync20, mkdtempSync, readFileSync as readFileSync15, rmSync as rmSync19 } from "node:fs";
18481
+ import { mkdirSync as mkdirSync21, mkdtempSync, readFileSync as readFileSync16, rmSync as rmSync19 } from "node:fs";
18339
18482
  import { join as join49 } from "node:path";
18340
18483
  import { tmpdir as tmpdir5 } from "node:os";
18341
18484
 
18342
18485
  // src/services/distributed/mp4Stitch.ts
18343
- import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync14 } from "node:fs";
18486
+ import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync14, rmSync as rmSync14 } from "node:fs";
18344
18487
  import { open } from "node:fs/promises";
18345
18488
  import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
18346
- import { basename as basename8, dirname as dirname16, join as join36 } from "node:path";
18489
+ import { basename as basename8, dirname as dirname17, join as join36 } from "node:path";
18347
18490
  import { finished, pipeline } from "node:stream/promises";
18348
18491
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
18349
18492
  function boxAt(src, off, at, limit) {
@@ -18708,8 +18851,8 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
18708
18851
  const sourcePaths = audioPath ? [audioPath, ...chunkPaths] : chunkPaths;
18709
18852
  const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
18710
18853
  const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
18711
- mkdirSync13(dirname16(outputPath), { recursive: true });
18712
- const workDir = createStagingDir4(dirname16(outputPath), `${basename8(outputPath)}.stitch-`);
18854
+ mkdirSync14(dirname17(outputPath), { recursive: true });
18855
+ const workDir = createStagingDir4(dirname17(outputPath), `${basename8(outputPath)}.stitch-`);
18713
18856
  const out = createWriteStream(join36(workDir, "out.mp4"));
18714
18857
  try {
18715
18858
  out.write(header);
@@ -18735,9 +18878,9 @@ import {
18735
18878
  cpSync as cpSync2,
18736
18879
  existsSync as existsSync27,
18737
18880
  linkSync,
18738
- mkdirSync as mkdirSync16,
18881
+ mkdirSync as mkdirSync17,
18739
18882
  rmSync as rmSync15,
18740
- writeFileSync as writeFileSync9
18883
+ writeFileSync as writeFileSync10
18741
18884
  } from "node:fs";
18742
18885
  import { extname as extname6, isAbsolute as isAbsolute5, join as join44, relative as relative8, sep as sep5 } from "node:path";
18743
18886
  import {
@@ -18775,8 +18918,8 @@ import {
18775
18918
 
18776
18919
  // src/services/distributed/shared.ts
18777
18920
  import { execFile as execFileCallback } from "node:child_process";
18778
- import { dirname as dirname17, join as join37 } from "node:path";
18779
- import { existsSync as existsSync23, readFileSync as readFileSync10 } from "node:fs";
18921
+ import { dirname as dirname18, join as join37 } from "node:path";
18922
+ import { existsSync as existsSync23, readFileSync as readFileSync11 } from "node:fs";
18780
18923
  import { fileURLToPath as fileURLToPath6 } from "node:url";
18781
18924
  import { promisify as promisify2 } from "node:util";
18782
18925
  import {
@@ -19053,13 +19196,13 @@ function buildSyntheticRenderJob(input) {
19053
19196
  var cachedProducerVersion = null;
19054
19197
  function readProducerVersion() {
19055
19198
  if (cachedProducerVersion !== null) return cachedProducerVersion;
19056
- const startDir = dirname17(fileURLToPath6(import.meta.url));
19199
+ const startDir = dirname18(fileURLToPath6(import.meta.url));
19057
19200
  let current = startDir;
19058
19201
  for (let i = 0; i < 10; i++) {
19059
19202
  const candidate = join37(current, "package.json");
19060
19203
  if (existsSync23(candidate)) {
19061
19204
  try {
19062
- const pkg = JSON.parse(readFileSync10(candidate, "utf-8"));
19205
+ const pkg = JSON.parse(readFileSync11(candidate, "utf-8"));
19063
19206
  if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
19064
19207
  cachedProducerVersion = pkg.version;
19065
19208
  return pkg.version;
@@ -19067,7 +19210,7 @@ function readProducerVersion() {
19067
19210
  } catch {
19068
19211
  }
19069
19212
  }
19070
- const parent = dirname17(current);
19213
+ const parent = dirname18(current);
19071
19214
  if (parent === current) break;
19072
19215
  current = parent;
19073
19216
  }
@@ -19412,7 +19555,7 @@ async function readPlanReferenceBackground(input) {
19412
19555
  }
19413
19556
 
19414
19557
  // src/services/render/stages/freezePlan.ts
19415
- import { existsSync as existsSync25, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync7 } from "node:fs";
19558
+ import { existsSync as existsSync25, mkdirSync as mkdirSync15, readFileSync as readFileSync12, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
19416
19559
  import { join as join41, relative as relative6, resolve as resolve10 } from "node:path";
19417
19560
  import {
19418
19561
  REFERENCE_BACKGROUND_FIELD,
@@ -19652,7 +19795,7 @@ function collectPlanAssetShas(planDir, digests) {
19652
19795
  const assets = [];
19653
19796
  for (const file of files) {
19654
19797
  if (file.planRelativePath === COMPILED_INDEX_RELATIVE_PATH) {
19655
- compositionHtml = readFileSync11(file.absolutePath);
19798
+ compositionHtml = readFileSync12(file.absolutePath);
19656
19799
  continue;
19657
19800
  }
19658
19801
  if (HASH_EXCLUDED_PLAN_FILES.has(file.planRelativePath)) continue;
@@ -19672,11 +19815,11 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
19672
19815
  function writePlanRemoteFiles(planDir, files) {
19673
19816
  if (files.length === 0) return;
19674
19817
  const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
19675
- writeFileSync7(join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
19818
+ writeFileSync8(join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
19676
19819
  }
19677
19820
  function readPlanRemoteFiles(planDir) {
19678
19821
  const path = join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
19679
- return existsSync25(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
19822
+ return existsSync25(path) ? JSON.parse(readFileSync12(path, "utf-8")) : [];
19680
19823
  }
19681
19824
  function recomputePlanHashFromPlanDir(planDir, digests) {
19682
19825
  const planJsonPath = join41(planDir, "plan.json");
@@ -19687,8 +19830,8 @@ function recomputePlanHashFromPlanDir(planDir, digests) {
19687
19830
  if (!existsSync25(encoderJsonPath)) {
19688
19831
  throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
19689
19832
  }
19690
- const planJson = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
19691
- const encoderConfigCanonicalJson = readFileSync11(encoderJsonPath, "utf-8");
19833
+ const planJson = JSON.parse(readFileSync12(planJsonPath, "utf-8"));
19834
+ const encoderConfigCanonicalJson = readFileSync12(encoderJsonPath, "utf-8");
19692
19835
  const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
19693
19836
  return computePlanHash({
19694
19837
  compositionHtml,
@@ -19718,8 +19861,8 @@ async function freezePlan(input) {
19718
19861
  throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
19719
19862
  }
19720
19863
  const metaDir = join41(planDir, "meta");
19721
- if (!existsSync25(metaDir)) mkdirSync14(metaDir, { recursive: true });
19722
- writeFileSync7(
19864
+ if (!existsSync25(metaDir)) mkdirSync15(metaDir, { recursive: true });
19865
+ writeFileSync8(
19723
19866
  join41(metaDir, "composition.json"),
19724
19867
  `${JSON.stringify(composition, null, 2)}
19725
19868
  `,
@@ -19727,8 +19870,8 @@ async function freezePlan(input) {
19727
19870
  );
19728
19871
  const encoderForCanonical = stripUndefined(encoder);
19729
19872
  const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
19730
- writeFileSync7(join41(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
19731
- writeFileSync7(join41(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
19873
+ writeFileSync8(join41(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
19874
+ writeFileSync8(join41(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
19732
19875
  `, "utf-8");
19733
19876
  const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
19734
19877
  const planHash = computePlanHash({
@@ -19754,7 +19897,7 @@ async function freezePlan(input) {
19754
19897
  hasAudio
19755
19898
  };
19756
19899
  const planJsonPath = join41(planDir, "plan.json");
19757
- writeFileSync7(planJsonPath, `${JSON.stringify(planJson, null, 2)}
19900
+ writeFileSync8(planJsonPath, `${JSON.stringify(planJson, null, 2)}
19758
19901
  `, "utf-8");
19759
19902
  return { planJsonPath, planHash };
19760
19903
  }
@@ -19795,8 +19938,8 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
19795
19938
  }
19796
19939
 
19797
19940
  // src/services/distributed/chunkAudio.ts
19798
- import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync7, readFileSync as readFileSync12 } from "node:fs";
19799
- import { writeFileSync as writeFileSync8, writeSync } from "node:fs";
19941
+ import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync16, openSync as openSync7, readFileSync as readFileSync13 } from "node:fs";
19942
+ import { writeFileSync as writeFileSync9, writeSync } from "node:fs";
19800
19943
  import { join as join42 } from "node:path";
19801
19944
  import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
19802
19945
  function audioCutForChunk(grid, chunks, index, fps) {
@@ -19883,9 +20026,9 @@ async function writeChunkAudioSlices(input) {
19883
20026
  offset += track.sizes[offsets.length - 1];
19884
20027
  }
19885
20028
  });
19886
- const bytes = readFileSync12(input.audioPath);
20029
+ const bytes = readFileSync13(input.audioPath);
19887
20030
  const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
19888
- mkdirSync15(join42(input.planDir, SLICE_DIR), { recursive: true });
20031
+ mkdirSync16(join42(input.planDir, SLICE_DIR), { recursive: true });
19889
20032
  input.chunks.forEach((_, index) => {
19890
20033
  const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
19891
20034
  if (!cut) return;
@@ -19893,17 +20036,17 @@ async function writeChunkAudioSlices(input) {
19893
20036
  const start = offsets[cut.firstPacket];
19894
20037
  layout.partStarts[index] = start;
19895
20038
  const end = offsets[last] + track.sizes[last];
19896
- writeFileSync8(join42(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
20039
+ writeFileSync9(join42(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
19897
20040
  });
19898
20041
  const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
19899
- writeFileSync8(join42(input.planDir, SLICE_FRAME), Buffer.concat(frame));
19900
- writeFileSync8(join42(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
20042
+ writeFileSync9(join42(input.planDir, SLICE_FRAME), Buffer.concat(frame));
20043
+ writeFileSync9(join42(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
19901
20044
  }
19902
20045
  function chunkAudioSource(planDir, chunkIndex, scratchPath) {
19903
20046
  const layoutPath = join42(planDir, SLICE_LAYOUT);
19904
20047
  if (!existsSync26(layoutPath)) return resolvePlanAudioPath(planDir);
19905
- const layout = JSON.parse(readFileSync12(layoutPath, "utf-8"));
19906
- const frame = readFileSync12(join42(planDir, SLICE_FRAME));
20048
+ const layout = JSON.parse(readFileSync13(layoutPath, "utf-8"));
20049
+ const frame = readFileSync13(join42(planDir, SLICE_FRAME));
19907
20050
  const fd = openSync7(scratchPath, "w");
19908
20051
  try {
19909
20052
  writeSync(fd, frame, 0, layout.payloadStart, 0);
@@ -19916,7 +20059,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
19916
20059
  );
19917
20060
  const start = layout.partStarts[chunkIndex];
19918
20061
  if (start !== void 0) {
19919
- const part = readFileSync12(join42(planDir, chunkAudioSlicePath(chunkIndex)));
20062
+ const part = readFileSync13(join42(planDir, chunkAudioSlicePath(chunkIndex)));
19920
20063
  writeSync(fd, part, 0, part.length, start);
19921
20064
  }
19922
20065
  ftruncateSync(fd, layout.sizeBytes);
@@ -20476,7 +20619,7 @@ function createVideoSourceShipper(input) {
20476
20619
  if (result === null) {
20477
20620
  result = `video-sources/${shipped.size}${extname6(current)}`;
20478
20621
  const destination = join44(input.planDir, ...result.split("/"));
20479
- mkdirSync16(join44(input.planDir, "video-sources"), { recursive: true });
20622
+ mkdirSync17(join44(input.planDir, "video-sources"), { recursive: true });
20480
20623
  try {
20481
20624
  linkSync(current, destination);
20482
20625
  } catch {
@@ -20496,7 +20639,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
20496
20639
  useGpu: false,
20497
20640
  browserGpuMode: "software"
20498
20641
  });
20499
- if (!existsSync27(planDir)) mkdirSync16(planDir, { recursive: true });
20642
+ if (!existsSync27(planDir)) mkdirSync17(planDir, { recursive: true });
20500
20643
  const log = config.logger ?? defaultLogger;
20501
20644
  const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
20502
20645
  const abortSignal = config.abortSignal;
@@ -20536,9 +20679,9 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
20536
20679
  }
20537
20680
  const workDir = join44(planDir, ".plan-work");
20538
20681
  rmSync15(workDir, { recursive: true, force: true });
20539
- mkdirSync16(workDir, { recursive: true });
20682
+ mkdirSync17(workDir, { recursive: true });
20540
20683
  const compiledDir = join44(workDir, "compiled");
20541
- mkdirSync16(compiledDir, { recursive: true });
20684
+ mkdirSync17(compiledDir, { recursive: true });
20542
20685
  let stageStarted = Date.now();
20543
20686
  cpSync2(projectDir, compiledDir, {
20544
20687
  recursive: true,
@@ -20773,7 +20916,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
20773
20916
  if (existsSync27(stagedVideoFrames)) {
20774
20917
  renameWithRetry7(stagedVideoFrames, videoFramesDst);
20775
20918
  } else {
20776
- mkdirSync16(videoFramesDst, { recursive: true });
20919
+ mkdirSync17(videoFramesDst, { recursive: true });
20777
20920
  }
20778
20921
  if (existsSync27(finalCompiledDir)) rmSync15(finalCompiledDir, { recursive: true, force: true });
20779
20922
  renameWithRetry7(compiledDir, finalCompiledDir);
@@ -20805,7 +20948,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
20805
20948
  };
20806
20949
  })
20807
20950
  });
20808
- mkdirSync16(join44(planDir, "meta"), { recursive: true });
20951
+ mkdirSync17(join44(planDir, "meta"), { recursive: true });
20809
20952
  writePlanRemoteFiles(
20810
20953
  planDir,
20811
20954
  remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
@@ -20814,7 +20957,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
20814
20957
  sizeBytes
20815
20958
  }))
20816
20959
  );
20817
- writeFileSync9(
20960
+ writeFileSync10(
20818
20961
  join44(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
20819
20962
  JSON.stringify(planVideosJson, null, 2),
20820
20963
  "utf-8"
@@ -21021,7 +21164,7 @@ async function plan(projectDir, config, planDir, options = {}) {
21021
21164
 
21022
21165
  // src/services/distributed/renderChunk.ts
21023
21166
  import { randomBytes } from "node:crypto";
21024
- import { existsSync as existsSync30, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync18, writeFileSync as writeFileSync12 } from "node:fs";
21167
+ import { existsSync as existsSync30, mkdirSync as mkdirSync20, readFileSync as readFileSync15, readdirSync as readdirSync11, rmSync as rmSync18, writeFileSync as writeFileSync13 } from "node:fs";
21025
21168
  import { join as join48 } from "node:path";
21026
21169
  import {
21027
21170
  assertSwiftShader,
@@ -21050,15 +21193,15 @@ import {
21050
21193
  copyFileSync as copyFileSync8,
21051
21194
  existsSync as existsSync29,
21052
21195
  lstatSync as lstatSync5,
21053
- mkdirSync as mkdirSync18,
21054
- readFileSync as readFileSync13,
21196
+ mkdirSync as mkdirSync19,
21197
+ readFileSync as readFileSync14,
21055
21198
  readdirSync as readdirSync10,
21056
21199
  rmSync as rmSync17,
21057
21200
  statSync as statSync12,
21058
- writeFileSync as writeFileSync11
21201
+ writeFileSync as writeFileSync12
21059
21202
  } from "node:fs";
21060
21203
  import { tmpdir as tmpdir4 } from "node:os";
21061
- import { dirname as dirname19, isAbsolute as isAbsolute6, join as join47, relative as relative9, resolve as resolve11, sep as sep6 } from "node:path";
21204
+ import { dirname as dirname20, isAbsolute as isAbsolute6, join as join47, relative as relative9, resolve as resolve11, sep as sep6 } from "node:path";
21062
21205
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
21063
21206
  import {
21064
21207
  createFrameLookupTable as createFrameLookupTable5,
@@ -21071,13 +21214,13 @@ import {
21071
21214
  copyFileSync as copyFileSync7,
21072
21215
  existsSync as existsSync28,
21073
21216
  linkSync as linkSync2,
21074
- mkdirSync as mkdirSync17,
21217
+ mkdirSync as mkdirSync18,
21075
21218
  rmSync as rmSync16,
21076
21219
  statSync as statSync11,
21077
- writeFileSync as writeFileSync10
21220
+ writeFileSync as writeFileSync11
21078
21221
  } from "node:fs";
21079
21222
  import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
21080
- import { dirname as dirname18, join as join46 } from "node:path";
21223
+ import { dirname as dirname19, join as join46 } from "node:path";
21081
21224
 
21082
21225
  // src/services/distributed/planV2Errors.ts
21083
21226
  var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
@@ -21138,8 +21281,8 @@ var LocalPlanV2ArtifactPublisher = class {
21138
21281
  }
21139
21282
  this.destinationDir = destinationDir;
21140
21283
  this.#linkFile = options.linkFile ?? linkSync2;
21141
- mkdirSync17(dirname18(destinationDir), { recursive: true });
21142
- this.temporaryDir = createStagingDir5(dirname18(destinationDir), ".plan-v2-publish-");
21284
+ mkdirSync18(dirname19(destinationDir), { recursive: true });
21285
+ this.temporaryDir = createStagingDir5(dirname19(destinationDir), ".plan-v2-publish-");
21143
21286
  }
21144
21287
  async putBlob(blob) {
21145
21288
  const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
@@ -21151,8 +21294,8 @@ var LocalPlanV2ArtifactPublisher = class {
21151
21294
  }
21152
21295
  const destinationPath = planV2BlobPath(this.temporaryDir, digest);
21153
21296
  if (existsSync28(destinationPath)) return;
21154
- mkdirSync17(dirname18(destinationPath), { recursive: true });
21155
- const stagingDir = createStagingDir5(dirname18(destinationPath), ".plan-v2-blob-");
21297
+ mkdirSync18(dirname19(destinationPath), { recursive: true });
21298
+ const stagingDir = createStagingDir5(dirname19(destinationPath), ".plan-v2-blob-");
21156
21299
  const temporaryPath = join46(stagingDir, "blob");
21157
21300
  try {
21158
21301
  try {
@@ -21174,7 +21317,7 @@ var LocalPlanV2ArtifactPublisher = class {
21174
21317
  );
21175
21318
  }
21176
21319
  }
21177
- writeFileSync10(join46(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
21320
+ writeFileSync11(join46(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
21178
21321
  renameWithRetry8(this.temporaryDir, this.destinationDir);
21179
21322
  this.#committed = true;
21180
21323
  }
@@ -21200,7 +21343,7 @@ function isNonNegativeIntegerArray(value) {
21200
21343
  return Array.isArray(value) && value.every((item) => typeof item === "number" && Number.isInteger(item) && item >= 0);
21201
21344
  }
21202
21345
  function readJsonFile(path, label) {
21203
- const contents = readFileSync13(path, "utf-8");
21346
+ const contents = readFileSync14(path, "utf-8");
21204
21347
  try {
21205
21348
  const parsed = JSON.parse(contents);
21206
21349
  return parsed;
@@ -21352,7 +21495,7 @@ function materializeExtractedVideoDirectories(planDir) {
21352
21495
  if (!existsSync29(videosPath)) return;
21353
21496
  const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
21354
21497
  for (const video of videos.extracted) {
21355
- mkdirSync18(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
21498
+ mkdirSync19(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
21356
21499
  }
21357
21500
  }
21358
21501
  function parseChunkSlices(value) {
@@ -21443,8 +21586,8 @@ function computeManifestHash(manifest) {
21443
21586
  }
21444
21587
  function writeBlob(sourcePath, destinationPath) {
21445
21588
  if (existsSync29(destinationPath)) return;
21446
- mkdirSync18(dirname19(destinationPath), { recursive: true });
21447
- const temporaryDir = createStagingDir6(dirname19(destinationPath), ".plan-v2-blob-");
21589
+ mkdirSync19(dirname20(destinationPath), { recursive: true });
21590
+ const temporaryDir = createStagingDir6(dirname20(destinationPath), ".plan-v2-blob-");
21448
21591
  const temporaryPath = join47(temporaryDir, "blob");
21449
21592
  try {
21450
21593
  copyFileSync8(sourcePath, temporaryPath);
@@ -21569,13 +21712,13 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
21569
21712
  if (publication.storedBlobs.length > 0) {
21570
21713
  throw new PlanV2IntegrityError("a local plan v2 directory cannot reference remote files");
21571
21714
  }
21572
- mkdirSync18(dirname19(planV2Dir), { recursive: true });
21573
- const tempDir = createStagingDir6(dirname19(planV2Dir), ".plan-v2-build-");
21715
+ mkdirSync19(dirname20(planV2Dir), { recursive: true });
21716
+ const tempDir = createStagingDir6(dirname20(planV2Dir), ".plan-v2-build-");
21574
21717
  try {
21575
21718
  for (const blob of publication.blobs) {
21576
21719
  writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
21577
21720
  }
21578
- writeFileSync11(
21721
+ writeFileSync12(
21579
21722
  join47(tempDir, "plan.json"),
21580
21723
  canonicalJsonStringify(publication.manifest),
21581
21724
  "utf-8"
@@ -21657,7 +21800,7 @@ async function planV2(projectDir, config, planV2Dir) {
21657
21800
  }
21658
21801
  const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
21659
21802
  const manifest = await planV2WithPublisher(projectDir, config, publisher, {
21660
- stagingParentDir: dirname19(planV2Dir)
21803
+ stagingParentDir: dirname20(planV2Dir)
21661
21804
  });
21662
21805
  return resultFromManifest(planV2Dir, manifest);
21663
21806
  }
@@ -21850,16 +21993,16 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
21850
21993
  artifact,
21851
21994
  sourcePath: verifyBlob(planV2Dir, artifact)
21852
21995
  }));
21853
- mkdirSync18(dirname19(destinationDir), { recursive: true });
21854
- const tempDir = createStagingDir6(dirname19(destinationDir), ".plan-v2-materialize-");
21996
+ mkdirSync19(dirname20(destinationDir), { recursive: true });
21997
+ const tempDir = createStagingDir6(dirname20(destinationDir), ".plan-v2-materialize-");
21855
21998
  try {
21856
21999
  for (const { artifact, sourcePath } of verified) {
21857
22000
  const destinationPath = join47(tempDir, ...artifact.path.split("/"));
21858
- mkdirSync18(dirname19(destinationPath), { recursive: true });
22001
+ mkdirSync19(dirname20(destinationPath), { recursive: true });
21859
22002
  copyFileSync8(sourcePath, destinationPath);
21860
22003
  }
21861
22004
  if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
21862
- writeFileSync11(
22005
+ writeFileSync12(
21863
22006
  join47(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
21864
22007
  canonicalJsonStringify({
21865
22008
  manifest,
@@ -22049,10 +22192,10 @@ async function beginFrameSessionNeedsScreenshotFallback(session, probe = probeBe
22049
22192
  return !await probe(session.page, timeoutMs, probeTick, session.beginFrameIntervalMs);
22050
22193
  }
22051
22194
  function hashChunkOutput(outputPath, kind) {
22052
- if (kind === "file") return sha256Hex(readFileSync14(outputPath));
22195
+ if (kind === "file") return sha256Hex(readFileSync15(outputPath));
22053
22196
  const entries = readdirSync11(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
22054
22197
  const lines = entries.map(
22055
- (name) => `${name}\0${sha256Hex(readFileSync14(join48(outputPath, name)))}`
22198
+ (name) => `${name}\0${sha256Hex(readFileSync15(join48(outputPath, name)))}`
22056
22199
  );
22057
22200
  return sha256Hex(lines.join("\0"));
22058
22201
  }
@@ -22078,7 +22221,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22078
22221
  `[renderChunk] planDir is missing required artifact: ${planJsonPath}`
22079
22222
  );
22080
22223
  }
22081
- const plan2 = JSON.parse(readFileSync14(planJsonPath, "utf-8"));
22224
+ const plan2 = JSON.parse(readFileSync15(planJsonPath, "utf-8"));
22082
22225
  readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.chunk);
22083
22226
  const planHashStarted = Date.now();
22084
22227
  const v2Materialization = readValidatedPlanV2Materialization(planDir, {
@@ -22095,13 +22238,13 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22095
22238
  );
22096
22239
  }
22097
22240
  }
22098
- const encoder = JSON.parse(readFileSync14(encoderJsonPath, "utf-8"));
22099
- const chunks = JSON.parse(readFileSync14(chunksJsonPath, "utf-8"));
22241
+ const encoder = JSON.parse(readFileSync15(encoderJsonPath, "utf-8"));
22242
+ const chunks = JSON.parse(readFileSync15(chunksJsonPath, "utf-8"));
22100
22243
  const videosJsonPath = join48(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
22101
22244
  let planVideos = null;
22102
22245
  if (existsSync30(videosJsonPath)) {
22103
22246
  try {
22104
- planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync14(videosJsonPath, "utf-8")));
22247
+ planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync15(videosJsonPath, "utf-8")));
22105
22248
  } catch (err) {
22106
22249
  if (err instanceof RenderChunkValidationError) throw err;
22107
22250
  throw new RenderChunkValidationError(
@@ -22187,9 +22330,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22187
22330
  forceScreenshotExplicitlyOptedOut: !encoder.forceScreenshot
22188
22331
  };
22189
22332
  const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
22190
- mkdirSync19(workDir, { recursive: true });
22333
+ mkdirSync20(workDir, { recursive: true });
22191
22334
  const framesDir = join48(workDir, "captured-frames");
22192
- mkdirSync19(framesDir, { recursive: true });
22335
+ mkdirSync20(framesDir, { recursive: true });
22193
22336
  const videoFramesDir = `${workDir}.video-frames`;
22194
22337
  const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
22195
22338
  const chunkFps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
@@ -22213,7 +22356,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22213
22356
  dimensions: plan2.dimensions,
22214
22357
  encoder,
22215
22358
  videoCount: planVideos?.videos.length ?? 0,
22216
- html: readFileSync14(join48(compiledDir, "index.html"), "utf-8"),
22359
+ html: readFileSync15(join48(compiledDir, "index.html"), "utf-8"),
22217
22360
  // The plan ships a deferred source only to chunks that show it; don't wait on the rest.
22218
22361
  skipReadinessVideoIds: deferredVideos.filter(
22219
22362
  (video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
@@ -22383,10 +22526,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22383
22526
  const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
22384
22527
  const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
22385
22528
  if (isPngSequence) {
22386
- if (!existsSync30(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
22529
+ if (!existsSync30(outputChunkPath)) mkdirSync20(outputChunkPath, { recursive: true });
22387
22530
  } else {
22388
22531
  const outDir = join48(outputChunkPath, "..");
22389
- if (!existsSync30(outDir)) mkdirSync19(outDir, { recursive: true });
22532
+ if (!existsSync30(outDir)) mkdirSync20(outDir, { recursive: true });
22390
22533
  }
22391
22534
  const encodeInput = {
22392
22535
  job,
@@ -22507,7 +22650,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22507
22650
  resetForScreenshotRetry: () => {
22508
22651
  rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
22509
22652
  boxesMeasured();
22510
- mkdirSync19(framesDir, { recursive: true });
22653
+ mkdirSync20(framesDir, { recursive: true });
22511
22654
  capturePerfs.length = 0;
22512
22655
  captureAttempts.length = 0;
22513
22656
  job.framesRendered = 0;
@@ -22599,7 +22742,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22599
22742
  producerVersion: plan2.producerVersion,
22600
22743
  ffmpegVersion
22601
22744
  };
22602
- writeFileSync12(perfPath, `${JSON.stringify(perfPayload, null, 2)}
22745
+ writeFileSync13(perfPath, `${JSON.stringify(perfPayload, null, 2)}
22603
22746
  `, "utf-8");
22604
22747
  try {
22605
22748
  rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
@@ -22666,7 +22809,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
22666
22809
  try {
22667
22810
  const planDir = join49(workDir, "plan");
22668
22811
  const partsDir = join49(workDir, "parts");
22669
- mkdirSync20(partsDir, { recursive: true });
22812
+ mkdirSync21(partsDir, { recursive: true });
22670
22813
  const planned = await plan(
22671
22814
  projectDir,
22672
22815
  { ...config, rejectOnSystemFonts: false, failClosedFontFetch: false },
@@ -22684,7 +22827,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
22684
22827
  planned.totalFrames
22685
22828
  );
22686
22829
  const slices = JSON.parse(
22687
- readFileSync15(join49(planDir, "meta", "chunks.json"), "utf-8")
22830
+ readFileSync16(join49(planDir, "meta", "chunks.json"), "utf-8")
22688
22831
  );
22689
22832
  const parts = [];
22690
22833
  for (const slice of slices) {
@@ -23356,16 +23499,16 @@ import {
23356
23499
  existsSync as existsSync33,
23357
23500
  fstatSync as fstatSync5,
23358
23501
  lstatSync as lstatSync6,
23359
- mkdirSync as mkdirSync21,
23502
+ mkdirSync as mkdirSync22,
23360
23503
  openSync as openSync9,
23361
23504
  statSync as statSync14,
23362
23505
  mkdtempSync as mkdtempSync2,
23363
- writeFileSync as writeFileSync13,
23506
+ writeFileSync as writeFileSync14,
23364
23507
  rmSync as rmSync20,
23365
23508
  createReadStream as createReadStream6
23366
23509
  } from "node:fs";
23367
23510
  import { AsyncLocalStorage } from "node:async_hooks";
23368
- import { basename as basename9, resolve as resolve13, dirname as dirname22, join as join52 } from "node:path";
23511
+ import { basename as basename9, resolve as resolve13, dirname as dirname23, join as join52 } from "node:path";
23369
23512
  import { homedir, tmpdir as tmpdir6 } from "node:os";
23370
23513
  import { parseArgs } from "node:util";
23371
23514
  import { isIP } from "node:net";
@@ -23384,14 +23527,14 @@ import { foreignWritablePath } from "@hyperframes/core/cache-dir";
23384
23527
  // src/services/hyperframeLint.ts
23385
23528
  import {
23386
23529
  existsSync as existsSync31,
23387
- readFileSync as readFileSync16,
23530
+ readFileSync as readFileSync17,
23388
23531
  statSync as statSync13,
23389
23532
  openSync as openSync8,
23390
23533
  fstatSync as fstatSync4,
23391
23534
  closeSync as closeSync8,
23392
23535
  constants as constants4
23393
23536
  } from "node:fs";
23394
- import { resolve as resolve12, join as join50, relative as relative10, isAbsolute as isAbsolute7, sep as sep7, dirname as dirname20 } from "node:path";
23537
+ import { resolve as resolve12, join as join50, relative as relative10, isAbsolute as isAbsolute7, sep as sep7, dirname as dirname21 } from "node:path";
23395
23538
  import { fileURLToPath as fileURLToPath7 } from "node:url";
23396
23539
  import { Worker as Worker3 } from "node:worker_threads";
23397
23540
  function isStringRecord(value) {
@@ -23431,7 +23574,7 @@ function readEntryHtml(filePath) {
23431
23574
  }
23432
23575
  try {
23433
23576
  if (!fstatSync4(fd).isFile()) return null;
23434
- return readFileSync16(fd, "utf-8");
23577
+ return readFileSync17(fd, "utf-8");
23435
23578
  } finally {
23436
23579
  closeSync8(fd);
23437
23580
  }
@@ -23530,7 +23673,7 @@ function freeLintSlot() {
23530
23673
  waiting.shift()?.();
23531
23674
  }
23532
23675
  function resolveLintWorkerEntry() {
23533
- const here = dirname20(fileURLToPath7(import.meta.url));
23676
+ const here = dirname21(fileURLToPath7(import.meta.url));
23534
23677
  for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
23535
23678
  const candidate = join50(here, name);
23536
23679
  if (existsSync31(candidate)) return candidate;
@@ -23603,7 +23746,7 @@ async function runHyperframeLint(prepared, options = {}) {
23603
23746
  // src/services/healthWorker.ts
23604
23747
  import { Worker as Worker4 } from "node:worker_threads";
23605
23748
  import { fileURLToPath as fileURLToPath8 } from "node:url";
23606
- import { dirname as dirname21, join as join51 } from "node:path";
23749
+ import { dirname as dirname22, join as join51 } from "node:path";
23607
23750
  import { existsSync as existsSync32 } from "node:fs";
23608
23751
  var DEFAULT_HEALTH_PORT = 9848;
23609
23752
  async function startHealthWorker(options = {}) {
@@ -23678,7 +23821,7 @@ function defaultLogger2() {
23678
23821
  };
23679
23822
  }
23680
23823
  function resolveWorkerEntry2() {
23681
- const here = dirname21(fileURLToPath8(import.meta.url));
23824
+ const here = dirname22(fileURLToPath8(import.meta.url));
23682
23825
  const candidates = [join51(here, "healthWorkerThread.js"), join51(here, "healthWorkerThread.ts")];
23683
23826
  for (const candidate of candidates) {
23684
23827
  if (existsSync32(candidate)) return candidate;
@@ -23846,9 +23989,9 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
23846
23989
  const serverNamed = input.outputPath == null;
23847
23990
  const outputCandidate = input.outputPath ?? join52(rendersDir, `${basename9(resolve13(input.projectDir))}-${crypto.randomUUID()}.mp4`);
23848
23991
  const absoluteOutputPath = resolveOutputPath(input.projectDir, outputCandidate, rendersDir, log);
23849
- const outputDir = dirname22(absoluteOutputPath);
23992
+ const outputDir = dirname23(absoluteOutputPath);
23850
23993
  if (confineOutput) {
23851
- mkdirSync21(rendersDir, { recursive: true, mode: SERVER_FOLDER_MODE });
23994
+ mkdirSync22(rendersDir, { recursive: true, mode: SERVER_FOLDER_MODE });
23852
23995
  if (!isSafePath4(rendersDir, absoluteOutputPath)) {
23853
23996
  throw new Error("outputPath must be inside the renders directory");
23854
23997
  }
@@ -23859,7 +24002,7 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
23859
24002
  );
23860
24003
  }
23861
24004
  }
23862
- if (!existsSync33(outputDir)) mkdirSync21(outputDir, { recursive: true, mode: SERVER_FOLDER_MODE });
24005
+ if (!existsSync33(outputDir)) mkdirSync22(outputDir, { recursive: true, mode: SERVER_FOLDER_MODE });
23863
24006
  return { input, cleanupProjectDir, absoluteOutputPath, serverNamed };
23864
24007
  }
23865
24008
  var STICKY_BIT = 512;
@@ -23971,7 +24114,7 @@ async function resolveInlineRenderHtml(body) {
23971
24114
  function materializeInlineProject(html, options) {
23972
24115
  const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
23973
24116
  const tempProjectDir = mkdtempSync2(join52(tempRoot, "producer-project-"));
23974
- writeFileSync13(join52(tempProjectDir, "index.html"), html, "utf-8");
24117
+ writeFileSync14(join52(tempProjectDir, "index.html"), html, "utf-8");
23975
24118
  return {
23976
24119
  prepared: {
23977
24120
  input: { projectDir: tempProjectDir, ...options },
@@ -24564,9 +24707,9 @@ function serverAuth(options, hostname2, port) {
24564
24707
  options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join52(homedir(), ".hyperframes", "producer", `${port}.token`)
24565
24708
  );
24566
24709
  const token = crypto.randomBytes(32).toString("base64url");
24567
- mkdirSync21(dirname22(file), { recursive: true, mode: 448 });
24710
+ mkdirSync22(dirname23(file), { recursive: true, mode: 448 });
24568
24711
  rmSync20(file, { force: true });
24569
- writeFileSync13(file, `${token}
24712
+ writeFileSync14(file, `${token}
24570
24713
  `, { flag: "wx", mode: 384 });
24571
24714
  return { token, generatedFile: file };
24572
24715
  }
@@ -24656,14 +24799,14 @@ import {
24656
24799
  import {
24657
24800
  cpSync as cpSync3,
24658
24801
  existsSync as existsSync34,
24659
- mkdirSync as mkdirSync22,
24660
- readFileSync as readFileSync17,
24802
+ mkdirSync as mkdirSync23,
24803
+ readFileSync as readFileSync18,
24661
24804
  readdirSync as readdirSync12,
24662
24805
  rmSync as rmSync21,
24663
24806
  statSync as statSync15
24664
24807
  } from "node:fs";
24665
24808
  import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
24666
- import { basename as basename10, dirname as dirname23, join as join53 } from "node:path";
24809
+ import { basename as basename10, dirname as dirname24, join as join53 } from "node:path";
24667
24810
  import {
24668
24811
  appendRateCapArgs as appendRateCapArgs2,
24669
24812
  writeVideoConcatList,
@@ -24712,10 +24855,10 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
24712
24855
  }
24713
24856
  const format = plan2.dimensions.format;
24714
24857
  const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
24715
- if (!existsSync34(dirname23(outputPath))) {
24716
- mkdirSync22(dirname23(outputPath), { recursive: true });
24858
+ if (!existsSync34(dirname24(outputPath))) {
24859
+ mkdirSync23(dirname24(outputPath), { recursive: true });
24717
24860
  }
24718
- const workDir = createStagingDir7(dirname23(outputPath), `${basename10(outputPath)}.assemble-work-`);
24861
+ const workDir = createStagingDir7(dirname24(outputPath), `${basename10(outputPath)}.assemble-work-`);
24719
24862
  const fps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
24720
24863
  const stageMs = {};
24721
24864
  const ctx = {
@@ -24769,13 +24912,13 @@ function readAssemblePlan(planDir, chunkPaths) {
24769
24912
  if (!existsSync34(planJsonPath)) {
24770
24913
  throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
24771
24914
  }
24772
- const plan2 = JSON.parse(readFileSync17(planJsonPath, "utf-8"));
24915
+ const plan2 = JSON.parse(readFileSync18(planJsonPath, "utf-8"));
24773
24916
  readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
24774
24917
  validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
24775
24918
  if (!existsSync34(chunksJsonPath)) {
24776
24919
  throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
24777
24920
  }
24778
- const chunks = JSON.parse(readFileSync17(chunksJsonPath, "utf-8"));
24921
+ const chunks = JSON.parse(readFileSync18(chunksJsonPath, "utf-8"));
24779
24922
  if (chunkPaths.length !== chunks.length) {
24780
24923
  throw new Error(
24781
24924
  `[assemble] chunkPaths length (${chunkPaths.length}) does not match chunks.json length (${chunks.length}). Adapters must pass one path per chunk, ordered by index.`
@@ -24922,13 +25065,13 @@ function stitchesSeparateAudio(planDir) {
24922
25065
  return lockedAudio(planDir).separateAudio === true;
24923
25066
  }
24924
25067
  function planFormat(planDir) {
24925
- const plan2 = JSON.parse(readFileSync17(join53(planDir, "plan.json"), "utf-8"));
25068
+ const plan2 = JSON.parse(readFileSync18(join53(planDir, "plan.json"), "utf-8"));
24926
25069
  return plan2.dimensions.format;
24927
25070
  }
24928
25071
  function lockedAudio(planDir) {
24929
25072
  const encoderJsonPath = join53(planDir, "meta", "encoder.json");
24930
25073
  if (!existsSync34(encoderJsonPath)) return {};
24931
- return JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
25074
+ return JSON.parse(readFileSync18(encoderJsonPath, "utf-8"));
24932
25075
  }
24933
25076
  function readCfrEncoder(planDir, format) {
24934
25077
  if (format !== "mp4") {
@@ -24940,7 +25083,7 @@ function readCfrEncoder(planDir, format) {
24940
25083
  if (!existsSync34(encoderJsonPath)) {
24941
25084
  throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
24942
25085
  }
24943
- const encoderJson = JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
25086
+ const encoderJson = JSON.parse(readFileSync18(encoderJsonPath, "utf-8"));
24944
25087
  if (encoderJson.encoder === "libx265-software") {
24945
25088
  throw new Error(
24946
25089
  `[assemble] cfr=true is not yet supported with codec: "h265". The cfr re-encode pass uses libx264 and would silently transcode the h265 chunks. Either disable cfr or render with codec: "h264".`
@@ -24950,7 +25093,7 @@ function readCfrEncoder(planDir, format) {
24950
25093
  }
24951
25094
  function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
24952
25095
  if (existsSync34(outputPath)) rmSync21(outputPath, { recursive: true, force: true });
24953
- mkdirSync22(outputPath, { recursive: true });
25096
+ mkdirSync23(outputPath, { recursive: true });
24954
25097
  let globalIdx = 0;
24955
25098
  for (const chunkDir of chunkPaths) {
24956
25099
  if (!statSync15(chunkDir).isDirectory()) {
@@ -25025,7 +25168,7 @@ async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
25025
25168
  }
25026
25169
 
25027
25170
  // src/services/distributed/projectHash.ts
25028
- import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
25171
+ import { isPrivateFileUnder as isPrivateFileUnder4, isStudioPrivatePath as isStudioPrivatePath4 } from "@hyperframes/core/safe-path";
25029
25172
  var READ_CHUNK_BYTES = 256 * 1024;
25030
25173
 
25031
25174
  // src/services/distributed/audioSidecar.ts