@hyperframes/producer 0.9.86 → 0.9.88

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.
@@ -8,13 +8,13 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
8
8
  import {
9
9
  copyFileSync as copyFileSync6,
10
10
  cpSync as cpSync2,
11
- existsSync as existsSync19,
11
+ existsSync as existsSync20,
12
12
  linkSync,
13
13
  mkdirSync as mkdirSync10,
14
14
  rmSync as rmSync7,
15
15
  writeFileSync as writeFileSync8
16
16
  } from "node:fs";
17
- import { extname as extname4, isAbsolute as isAbsolute3, join as join27, relative as relative6, sep as sep4 } from "node:path";
17
+ import { extname as extname4, isAbsolute as isAbsolute3, join as join28, relative as relative6, sep as sep4 } from "node:path";
18
18
  import {
19
19
  fpsToNumber as fpsToNumber9,
20
20
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
@@ -145,7 +145,7 @@ function formatExportFrameName(index, ext) {
145
145
  // src/services/renderOrchestrator.ts
146
146
  import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
147
147
  import {
148
- existsSync as existsSync14,
148
+ existsSync as existsSync15,
149
149
  mkdirSync as mkdirSync6,
150
150
  readdirSync as readdirSync3,
151
151
  rmSync as rmSync5,
@@ -376,7 +376,7 @@ import {
376
376
  referenceBackgroundResult,
377
377
  createReferenceBackgroundRecorder
378
378
  } from "@hyperframes/engine";
379
- import { join as join18, dirname as dirname11, resolve as resolve7 } from "path";
379
+ import { join as join19, dirname as dirname12, resolve as resolve7 } from "path";
380
380
  import { randomUUID } from "crypto";
381
381
 
382
382
  // src/services/fileServer.ts
@@ -1409,12 +1409,12 @@ var workerPhasesByJob = /* @__PURE__ */ new WeakMap();
1409
1409
  function forgetWorkerPhases(job) {
1410
1410
  workerPhasesByJob.delete(job);
1411
1411
  }
1412
- var staticDedupActivityByJob = /* @__PURE__ */ new WeakMap();
1413
- function noteStaticDedupActivity(job) {
1414
- staticDedupActivityByJob.set(job, (staticDedupActivityByJob.get(job) ?? 0) + 1);
1412
+ var captureActivityByJob = /* @__PURE__ */ new WeakMap();
1413
+ function noteCaptureActivity(job) {
1414
+ captureActivityByJob.set(job, (captureActivityByJob.get(job) ?? 0) + 1);
1415
1415
  }
1416
- function staticDedupActivity(job) {
1417
- return staticDedupActivityByJob.get(job) ?? 0;
1416
+ function captureActivity(job) {
1417
+ return captureActivityByJob.get(job) ?? 0;
1418
1418
  }
1419
1419
  function describeWorkerPhases(job) {
1420
1420
  const phases = workerPhasesByJob.get(job);
@@ -2034,7 +2034,8 @@ async function extractDeferredFrames(input) {
2034
2034
  outputDir: input.outputRoot,
2035
2035
  format: range.format,
2036
2036
  frameRanges: contiguousRuns(indexes),
2037
- shownBox: input.shownBoxes?.get(video.videoId)
2037
+ shownBox: input.shownBoxes?.get(video.videoId),
2038
+ ...input.onProgress && { onProgress: input.onProgress }
2038
2039
  },
2039
2040
  input.signal,
2040
2041
  input.cfg
@@ -2453,14 +2454,20 @@ function requireOutputDimensions(expected, width, height) {
2453
2454
  }
2454
2455
 
2455
2456
  // src/services/render/stages/compileStage.ts
2456
- import { existsSync as existsSync8, writeFileSync as writeFileSync3 } from "node:fs";
2457
- import { join as join10, relative as relative3 } from "node:path";
2457
+ import { existsSync as existsSync9, writeFileSync as writeFileSync3 } from "node:fs";
2458
+ import { join as join11, relative as relative3 } from "node:path";
2458
2459
  import { privateCacheRoot } from "@hyperframes/engine";
2459
2460
  import { suggestMatchingPreset } from "@hyperframes/core";
2460
2461
  import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
2461
2462
  import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
2462
2463
  import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperframes/core/compiler";
2463
2464
 
2465
+ // src/services/compileInWorker.ts
2466
+ import { existsSync as existsSync8 } from "node:fs";
2467
+ import { dirname as dirname8, join as join10 } from "node:path";
2468
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
2469
+ import { Worker } from "node:worker_threads";
2470
+
2464
2471
  // src/services/htmlCompiler.ts
2465
2472
  import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
2466
2473
  import {
@@ -5773,11 +5780,119 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
5773
5780
  };
5774
5781
  }
5775
5782
 
5783
+ // src/services/compileInWorker.ts
5784
+ var DEFAULT_COMPILE_TIMEOUT_MS = 10 * 60 * 1e3;
5785
+ var TERMINATE_GRACE_MS = 2e3;
5786
+ var ADVISORY_GRACE_MS = 3e4;
5787
+ var MAX_TIMER_MS = 2 ** 31 - 1;
5788
+ var CompileTimeoutError = class extends Error {
5789
+ code = "COMPILE_TIMEOUT";
5790
+ owner = "user";
5791
+ retryable = false;
5792
+ publicMetadata;
5793
+ constructor(timeoutMs) {
5794
+ super(
5795
+ `Compiling the composition took longer than ${Math.round(timeoutMs / 1e3)} s, so it was stopped. Very large pages, or pages with very many style rules or media tags, are the usual cause.`
5796
+ );
5797
+ this.name = "CompileTimeoutError";
5798
+ this.publicMetadata = { timeoutMs };
5799
+ }
5800
+ };
5801
+ function compileTimeoutMs() {
5802
+ const fromEnv = Number(process.env.HYPERFRAMES_COMPILE_TIMEOUT_MS);
5803
+ return Number.isInteger(fromEnv) && fromEnv > 0 ? Math.min(fromEnv, MAX_TIMER_MS) : DEFAULT_COMPILE_TIMEOUT_MS;
5804
+ }
5805
+ var warnedMissingEntry = false;
5806
+ function resolveCompileWorkerEntry(explicit, log) {
5807
+ if (explicit) return explicit;
5808
+ const fromEnv = process.env.HF_COMPILE_WORKER_ENTRY;
5809
+ if (fromEnv) {
5810
+ if (existsSync8(fromEnv)) return fromEnv;
5811
+ if (!warnedMissingEntry) {
5812
+ warnedMissingEntry = true;
5813
+ log?.warn(
5814
+ "[Compiler] HF_COMPILE_WORKER_ENTRY names a missing file, so compiles run on the main thread with no deadline",
5815
+ { entry: fromEnv }
5816
+ );
5817
+ }
5818
+ return void 0;
5819
+ }
5820
+ const sibling = join10(dirname8(fileURLToPath3(import.meta.url)), "compileWorker.js");
5821
+ return existsSync8(sibling) ? sibling : void 0;
5822
+ }
5823
+ function rebuildError({ name, message, stack, props }) {
5824
+ const error = Object.assign(new Error(message), props);
5825
+ error.name = name;
5826
+ if (stack) error.stack = stack;
5827
+ return error;
5828
+ }
5829
+ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, options = {}, worker = {}) {
5830
+ const { log, abortSignal, ...cloneable } = options;
5831
+ const entry = resolveCompileWorkerEntry(worker.entry, log);
5832
+ if (!entry) return compileForRender(projectDir, htmlPath, downloadDir, options);
5833
+ abortSignal?.throwIfAborted();
5834
+ const timeoutMs = worker.timeoutMs ?? compileTimeoutMs();
5835
+ return new Promise((resolve10, reject) => {
5836
+ const thread = new Worker(entry, {
5837
+ workerData: { projectDir, htmlPath, downloadDir, options: cloneable }
5838
+ });
5839
+ let settled = false;
5840
+ const settle = (finish) => {
5841
+ if (settled) return;
5842
+ settled = true;
5843
+ clearTimeout(timer);
5844
+ abortSignal?.removeEventListener("abort", onAbort);
5845
+ finish();
5846
+ };
5847
+ const stop = () => {
5848
+ thread.postMessage({ type: "abort" });
5849
+ setTimeout(() => void thread.terminate(), TERMINATE_GRACE_MS).unref();
5850
+ };
5851
+ const timer = setTimeout(() => {
5852
+ stop();
5853
+ settle(() => reject(new CompileTimeoutError(timeoutMs)));
5854
+ }, timeoutMs);
5855
+ const onAbort = () => {
5856
+ stop();
5857
+ settle(() => reject(abortSignal?.reason ?? new Error("Compile aborted")));
5858
+ };
5859
+ abortSignal?.addEventListener("abort", onAbort, { once: true });
5860
+ const retire = (graceMs) => {
5861
+ thread.unref();
5862
+ setTimeout(() => void thread.terminate(), graceMs).unref();
5863
+ };
5864
+ thread.on(
5865
+ "message",
5866
+ (message) => {
5867
+ if (message.type === "log" && message.level) {
5868
+ log?.[message.level](message.message ?? "", message.meta);
5869
+ } else if (message.type === "result" && message.compiled) {
5870
+ const { compiled } = message;
5871
+ settle(() => resolve10(compiled));
5872
+ retire(ADVISORY_GRACE_MS);
5873
+ } else if (message.type === "error" && message.error) {
5874
+ const { error } = message;
5875
+ settle(() => reject(rebuildError(error)));
5876
+ thread.postMessage({ type: "abort" });
5877
+ retire(TERMINATE_GRACE_MS);
5878
+ }
5879
+ }
5880
+ );
5881
+ thread.on("error", (error) => settle(() => reject(error)));
5882
+ thread.on(
5883
+ "exit",
5884
+ (code) => settle(
5885
+ () => reject(new Error(`The compile worker exited with code ${code} before answering`))
5886
+ )
5887
+ );
5888
+ });
5889
+ }
5890
+
5776
5891
  // src/services/render/stages/compileStage.ts
5777
5892
  function animatedGifCacheDir(extractCacheDir) {
5778
5893
  try {
5779
5894
  const root = extractCacheDir && privateCacheRoot(extractCacheDir);
5780
- return root ? join10(root, "animated-gif") : void 0;
5895
+ return root ? join11(root, "animated-gif") : void 0;
5781
5896
  } catch {
5782
5897
  return void 0;
5783
5898
  }
@@ -5805,11 +5920,11 @@ function resolveEntryHtmlPath(input) {
5805
5920
  assertCompositionFileSize2(path, relative3(projectDir, path));
5806
5921
  return readTextFile2(path);
5807
5922
  };
5808
- const htmlPath = join10(projectDir, entryFile);
5923
+ const htmlPath = join11(projectDir, entryFile);
5809
5924
  const rawEntry = readEntry(htmlPath);
5810
5925
  if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
5811
- const projectIndexPath = join10(projectDir, "index.html");
5812
- if (!existsSync8(projectIndexPath)) {
5926
+ const projectIndexPath = join11(projectDir, "index.html");
5927
+ if (!existsSync9(projectIndexPath)) {
5813
5928
  throw new Error(
5814
5929
  `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
5815
5930
  );
@@ -5824,7 +5939,7 @@ function resolveEntryHtmlPath(input) {
5824
5939
  `Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`
5825
5940
  );
5826
5941
  }
5827
- const wrapperPath = join10(workDir, "standalone-entry.html");
5942
+ const wrapperPath = join11(workDir, "standalone-entry.html");
5828
5943
  writeFileSync3(wrapperPath, standaloneHtml, "utf-8");
5829
5944
  log.info("Extracted standalone entry from index.html host context", { entryFile });
5830
5945
  return wrapperPath;
@@ -5854,19 +5969,24 @@ async function runCompileStage(input) {
5854
5969
  const assetRoot = job.config.allowOutsideProjectAssets ? void 0 : projectDir;
5855
5970
  const htmlPath = resolveEntryHtmlPath({ projectDir, workDir, entryFile, log, assetRoot });
5856
5971
  const compileStart = Date.now();
5857
- const compiled = await compileForRender(projectDir, htmlPath, join10(workDir, "downloads"), {
5858
- log,
5859
- failClosedFontFetch: failClosedFontFetch === true,
5860
- allowSystemFontCapture,
5861
- abortSignal,
5862
- variables: input.variables,
5863
- urlByAbsentLocalPath: input.urlByAbsentLocalPath,
5864
- pageMotionBlur: input.pageMotionBlur,
5865
- animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
5866
- ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
5867
- allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
5868
- includeOutsideScripts: job.config.includeOutsideScripts
5869
- });
5972
+ const compiled = await compileForRenderInWorker(
5973
+ projectDir,
5974
+ htmlPath,
5975
+ join11(workDir, "downloads"),
5976
+ {
5977
+ log,
5978
+ failClosedFontFetch: failClosedFontFetch === true,
5979
+ allowSystemFontCapture,
5980
+ abortSignal,
5981
+ variables: input.variables,
5982
+ urlByAbsentLocalPath: input.urlByAbsentLocalPath,
5983
+ pageMotionBlur: input.pageMotionBlur,
5984
+ animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
5985
+ ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
5986
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
5987
+ includeOutsideScripts: job.config.includeOutsideScripts
5988
+ }
5989
+ );
5870
5990
  assertNotAborted();
5871
5991
  const compileOnlyMs = Date.now() - compileStart;
5872
5992
  let deCompileGate;
@@ -5929,7 +6049,7 @@ async function runCompileStage(input) {
5929
6049
  });
5930
6050
  await preflightCompositionAssetMediaTypes({
5931
6051
  projectDir,
5932
- compiledDir: join10(workDir, "compiled"),
6052
+ compiledDir: join11(workDir, "compiled"),
5933
6053
  composition,
5934
6054
  signal: abortSignal
5935
6055
  });
@@ -5977,7 +6097,7 @@ async function runCompileStage(input) {
5977
6097
 
5978
6098
  // src/services/render/stages/probeStage.ts
5979
6099
  import { createHash as createHash6 } from "node:crypto";
5980
- import { basename as basename4, join as join11 } from "node:path";
6100
+ import { basename as basename4, join as join12 } from "node:path";
5981
6101
  import { parseHTML as parseHTML6 } from "linkedom";
5982
6102
  import {
5983
6103
  closeCaptureSession as closeCaptureSession4,
@@ -6327,7 +6447,7 @@ async function runProbeStage(input) {
6327
6447
  });
6328
6448
  fileServer = await createFileServer({
6329
6449
  projectDir,
6330
- compiledDir: join11(workDir, "compiled"),
6450
+ compiledDir: join12(workDir, "compiled"),
6331
6451
  port: 0,
6332
6452
  preHeadScripts: [VIRTUAL_TIME_SHIM],
6333
6453
  fps: job.config.fps,
@@ -6341,7 +6461,7 @@ async function runProbeStage(input) {
6341
6461
  composition.videos,
6342
6462
  compiled.html,
6343
6463
  projectDir,
6344
- join11(workDir, "compiled")
6464
+ join12(workDir, "compiled")
6345
6465
  ),
6346
6466
  recordReferenceBackground: input.recordReferenceBackground,
6347
6467
  width,
@@ -6361,7 +6481,7 @@ async function runProbeStage(input) {
6361
6481
  staticDedupMemo,
6362
6482
  compositionHash: computeCompositionObservabilityHash(compiled.html),
6363
6483
  deferStaticDedup: true,
6364
- onStaticDedupActivity: () => noteStaticDedupActivity(job)
6484
+ onStaticDedupActivity: () => noteCaptureActivity(job)
6365
6485
  };
6366
6486
  const PROBE_MAX_ATTEMPTS = 2;
6367
6487
  for (let attempt = 1; attempt <= PROBE_MAX_ATTEMPTS; attempt++) {
@@ -6370,7 +6490,7 @@ async function runProbeStage(input) {
6370
6490
  log.info("Creating capture session...", { attempt, maxAttempts: PROBE_MAX_ATTEMPTS });
6371
6491
  probeSession = await createCaptureSession4(
6372
6492
  fileServer.url,
6373
- join11(workDir, "probe"),
6493
+ join12(workDir, "probe"),
6374
6494
  captureOpts,
6375
6495
  null,
6376
6496
  probeCfg
@@ -6456,7 +6576,7 @@ async function runProbeStage(input) {
6456
6576
  });
6457
6577
  probeSession = await createCaptureSession4(
6458
6578
  fileServer.url,
6459
- join11(workDir, "probe-screenshot"),
6579
+ join12(workDir, "probe-screenshot"),
6460
6580
  captureOpts,
6461
6581
  null,
6462
6582
  { ...probeCfg, forceScreenshot: true }
@@ -6500,7 +6620,7 @@ async function runProbeStage(input) {
6500
6620
  compiled,
6501
6621
  resolutions,
6502
6622
  projectDir,
6503
- join11(workDir, "downloads"),
6623
+ join12(workDir, "downloads"),
6504
6624
  job.config.allowOutsideProjectAssets ? void 0 : projectDir,
6505
6625
  { includeScripts: job.config.includeOutsideScripts }
6506
6626
  );
@@ -6706,7 +6826,7 @@ async function runProbeStage(input) {
6706
6826
  });
6707
6827
  await preflightCompositionAssetMediaTypes({
6708
6828
  projectDir,
6709
- compiledDir: join11(workDir, "compiled"),
6829
+ compiledDir: join12(workDir, "compiled"),
6710
6830
  composition,
6711
6831
  signal: abortSignal
6712
6832
  });
@@ -6873,8 +6993,8 @@ function validateDistributedDuration(input) {
6873
6993
  }
6874
6994
 
6875
6995
  // src/services/render/stages/extractVideosStage.ts
6876
- import { existsSync as existsSync9 } from "node:fs";
6877
- import { join as join12 } from "node:path";
6996
+ import { existsSync as existsSync10 } from "node:fs";
6997
+ import { join as join13 } from "node:path";
6878
6998
  import {
6879
6999
  classifyVideoExtractionError,
6880
7000
  createFrameLookupTable as createFrameLookupTable3,
@@ -7244,7 +7364,7 @@ async function runExtractVideosStage(input) {
7244
7364
  // because short boundary counts can differ by one frame.
7245
7365
  {
7246
7366
  fps: job.config.fps,
7247
- outputDir: join12(compiledDir, "__hyperframes_video_frames"),
7367
+ outputDir: join13(compiledDir, "__hyperframes_video_frames"),
7248
7368
  format: job.config.videoFrameFormat ?? "auto",
7249
7369
  toneMapHdrToSdr: rendersSdrOnly(job.config, composition),
7250
7370
  timelineEnd: composition.duration,
@@ -7252,7 +7372,7 @@ async function runExtractVideosStage(input) {
7252
7372
  collectProbeFailures: extractionPolicy.failureMode === "enforce",
7253
7373
  deferRangeExtraction,
7254
7374
  shownBoxes,
7255
- contentKeyedDirs: [join12(compiledDir, REMOTE_MEDIA_SUBDIR)],
7375
+ contentKeyedDirs: [join13(compiledDir, REMOTE_MEDIA_SUBDIR)],
7256
7376
  urlByAbsentLocalPath,
7257
7377
  assetRoots,
7258
7378
  onProgress: ({ planned = 0, done = 0 }) => {
@@ -7332,7 +7452,7 @@ function isPublicHttpsUrl(url) {
7332
7452
  }
7333
7453
  }
7334
7454
  function opensLocally(path, assetRoots) {
7335
- return existsSync9(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
7455
+ return existsSync10(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
7336
7456
  }
7337
7457
  function localProbeSource(src, input) {
7338
7458
  const path = resolveProjectRelativeSrc5(src, input.projectDir, input.compiledDir);
@@ -7344,7 +7464,7 @@ async function remoteProbeSource(video, input) {
7344
7464
  if (!isPublicHttpsUrl(video.src)) return null;
7345
7465
  if (!resolveRestrictPageNetwork()) return video.src;
7346
7466
  if (!video.hasAudio || video.hidden) return null;
7347
- const downloadDir = input.downloadDir ?? join12(input.compiledDir, REMOTE_MEDIA_SUBDIR);
7467
+ const downloadDir = input.downloadDir ?? join13(input.compiledDir, REMOTE_MEDIA_SUBDIR);
7348
7468
  try {
7349
7469
  return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
7350
7470
  onTelemetry: writeUrlDownloadTelemetry2
@@ -7393,8 +7513,8 @@ import {
7393
7513
  } from "@hyperframes/engine";
7394
7514
 
7395
7515
  // src/services/render/stages/audioStage.ts
7396
- import { existsSync as existsSync11 } from "node:fs";
7397
- import { join as join15 } from "node:path";
7516
+ import { existsSync as existsSync12 } from "node:fs";
7517
+ import { join as join16 } from "node:path";
7398
7518
  import {
7399
7519
  MIXED_AUDIO_FILENAME,
7400
7520
  audioFailureDiagnostics,
@@ -7405,8 +7525,8 @@ import {
7405
7525
  } from "@hyperframes/engine";
7406
7526
 
7407
7527
  // src/services/render/audioDeliveryLimit.ts
7408
- import { existsSync as existsSync10 } from "node:fs";
7409
- import { dirname as dirname9, join as join14 } from "node:path";
7528
+ import { existsSync as existsSync11 } from "node:fs";
7529
+ import { dirname as dirname10, join as join15 } from "node:path";
7410
7530
  import {
7411
7531
  applyAudioFxChain,
7412
7532
  describeFfmpegFailure as describeFfmpegFailure3,
@@ -7417,7 +7537,7 @@ import {
7417
7537
  // src/services/render/audioPadTrim.ts
7418
7538
  import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
7419
7539
  import { spawn } from "node:child_process";
7420
- import { dirname as dirname8, join as join13 } from "node:path";
7540
+ import { dirname as dirname9, join as join14 } from "node:path";
7421
7541
  import {
7422
7542
  DEFAULT_CONFIG,
7423
7543
  describeFfmpegFailure as describeFfmpegFailure2,
@@ -7698,7 +7818,7 @@ async function constrainAacTruePeak(input) {
7698
7818
  }
7699
7819
  async function cutSource(input, scratchDir, attenuationDb) {
7700
7820
  if (!input.sourcePath || !input.rewriteSource) return true;
7701
- const cutPath = join13(scratchDir, "source.wav");
7821
+ const cutPath = join14(scratchDir, "source.wav");
7702
7822
  try {
7703
7823
  const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
7704
7824
  if (!result.success) throw new Error(result.error);
@@ -7712,8 +7832,8 @@ async function cutSource(input, scratchDir, attenuationDb) {
7712
7832
  async function enforceAacTruePeak(input) {
7713
7833
  let scratchDir;
7714
7834
  try {
7715
- scratchDir = createStagingDir3(dirname8(input.audioPath), ".true-peak-");
7716
- const correctedPath = join13(scratchDir, "audio.m4a");
7835
+ scratchDir = createStagingDir3(dirname9(input.audioPath), ".true-peak-");
7836
+ const correctedPath = join14(scratchDir, "audio.m4a");
7717
7837
  const measurements = [];
7718
7838
  let attenuationDb = 0;
7719
7839
  let sourcePeakDbfs;
@@ -7929,14 +8049,14 @@ async function limitDeliveryPeaks(input, deps = {
7929
8049
  applyChain: applyAudioFxChain,
7930
8050
  encode: encodeAac2,
7931
8051
  rename: renameWithRetry5,
7932
- sourceExists: existsSync10
8052
+ sourceExists: existsSync11
7933
8053
  }) {
7934
8054
  const { audioPath, sourcePath, signal, timeoutMs } = input;
7935
8055
  if (!deps.sourceExists(sourcePath)) return { success: true };
7936
8056
  const peak = await deps.measure(audioPath, { timeoutMs, signal });
7937
8057
  if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
7938
8058
  const alternating = ["a", "b"].map(
7939
- (k) => join14(dirname9(sourcePath), `audio-source-limited-${k}.wav`)
8059
+ (k) => join15(dirname10(sourcePath), `audio-source-limited-${k}.wav`)
7940
8060
  );
7941
8061
  let encodedFrom;
7942
8062
  let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
@@ -8009,7 +8129,7 @@ function runAudioStage(input) {
8009
8129
  }
8010
8130
  async function runAudioStageScoped(input) {
8011
8131
  const stageStart = Date.now();
8012
- const pcmSourcePath = join15(input.workDir, "audio-source.wav");
8132
+ const pcmSourcePath = join16(input.workDir, "audio-source.wav");
8013
8133
  const duration = input.totalFrames * input.fps.den / input.fps.num;
8014
8134
  let deliverySourcePath;
8015
8135
  try {
@@ -8025,7 +8145,7 @@ async function runAudioStageScoped(input) {
8025
8145
  );
8026
8146
  audioLoweredDb = guard.loweredDb;
8027
8147
  input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
8028
- if (input.keepDeliverySource && !guard.sourceStale && existsSync11(pcmSourcePath)) {
8148
+ if (input.keepDeliverySource && !guard.sourceStale && existsSync12(pcmSourcePath)) {
8029
8149
  deliverySourcePath = pcmSourcePath;
8030
8150
  }
8031
8151
  }
@@ -8074,7 +8194,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
8074
8194
  assertNotAborted,
8075
8195
  log
8076
8196
  } = input;
8077
- const audioOutputPath = join15(workDir, MIXED_AUDIO_FILENAME);
8197
+ const audioOutputPath = join16(workDir, MIXED_AUDIO_FILENAME);
8078
8198
  let hasAudio = false;
8079
8199
  let audioError;
8080
8200
  let audioFailures;
@@ -8154,8 +8274,8 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
8154
8274
  }
8155
8275
 
8156
8276
  // src/services/render/stages/captureStage.ts
8157
- import { existsSync as existsSync12, readdirSync, statfsSync } from "node:fs";
8158
- import { join as join16 } from "node:path";
8277
+ import { existsSync as existsSync13, readdirSync, statfsSync } from "node:fs";
8278
+ import { join as join17 } from "node:path";
8159
8279
  import {
8160
8280
  classifyCaptureFailure as classifyCaptureFailure2,
8161
8281
  frameFileExtension,
@@ -8206,16 +8326,16 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
8206
8326
  }
8207
8327
  function measureCaptureFrameBytes(workDir, framesDir) {
8208
8328
  let total = sampleDirectoryBytes(framesDir);
8209
- if (!existsSync12(workDir)) return total;
8329
+ if (!existsSync13(workDir)) return total;
8210
8330
  for (const attempt of readdirSync(workDir)) {
8211
8331
  if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
8212
- total += sampleDirectoryBytes(join16(workDir, attempt));
8332
+ total += sampleDirectoryBytes(join17(workDir, attempt));
8213
8333
  continue;
8214
8334
  }
8215
8335
  if (!/^capture-attempt-\d+$/.test(attempt)) continue;
8216
- const attemptDir = join16(workDir, attempt);
8336
+ const attemptDir = join17(workDir, attempt);
8217
8337
  for (const name of readdirSync(attemptDir)) {
8218
- if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join16(attemptDir, name));
8338
+ if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join17(attemptDir, name));
8219
8339
  }
8220
8340
  }
8221
8341
  return total;
@@ -8550,7 +8670,7 @@ import { usableCpuCount } from "@hyperframes/engine";
8550
8670
  // src/services/render/stages/encodeStage.ts
8551
8671
  import {
8552
8672
  copyFileSync as copyFileSync4,
8553
- existsSync as existsSync13,
8673
+ existsSync as existsSync14,
8554
8674
  mkdirSync as mkdirSync5,
8555
8675
  readdirSync as readdirSync2,
8556
8676
  readFileSync as readFileSync6,
@@ -8559,7 +8679,7 @@ import {
8559
8679
  writeFileSync as writeFileSync4
8560
8680
  } from "node:fs";
8561
8681
  import { readFile as readFile2 } from "node:fs/promises";
8562
- import { dirname as dirname10, join as join17 } from "node:path";
8682
+ import { dirname as dirname11, join as join18 } from "node:path";
8563
8683
  import {
8564
8684
  encodeFramesChunkedConcat,
8565
8685
  encodeFramesFromDir,
@@ -8684,7 +8804,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
8684
8804
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
8685
8805
  if (failure) return failure;
8686
8806
  }
8687
- const fileSize = existsSync13(outputPath) ? statSync6(outputPath).size : 0;
8807
+ const fileSize = existsSync14(outputPath) ? statSync6(outputPath).size : 0;
8688
8808
  return {
8689
8809
  success: true,
8690
8810
  outputPath,
@@ -8778,7 +8898,7 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
8778
8898
  await new Promise((resolve10) => wake = resolve10);
8779
8899
  }
8780
8900
  if (signal.aborted) return;
8781
- const mergedPath = join17(input.framesDir, formatCaptureFrameName(next, "jpg"));
8901
+ const mergedPath = join18(input.framesDir, formatCaptureFrameName(next, "jpg"));
8782
8902
  const frame = await readLandedFrame(landed.get(next), mergedPath);
8783
8903
  landed.delete(next);
8784
8904
  if (!await stream.writeFrame(frame)) {
@@ -8853,7 +8973,7 @@ async function runEncodeStage(input) {
8853
8973
  const stage5Start = Date.now();
8854
8974
  if (isPngSequence) {
8855
8975
  const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
8856
- if (!existsSync13(outputPath)) mkdirSync5(outputPath, { recursive: true });
8976
+ if (!existsSync14(outputPath)) mkdirSync5(outputPath, { recursive: true });
8857
8977
  const captured = readdirSync2(framesDir).filter((name) => name.endsWith(".png")).sort();
8858
8978
  if (captured.length === 0) {
8859
8979
  throw new Error(
@@ -8861,11 +8981,11 @@ async function runEncodeStage(input) {
8861
8981
  );
8862
8982
  }
8863
8983
  captured.forEach((name, i) => {
8864
- const dst = join17(outputPath, formatExportFrameName(i, "png"));
8865
- copyFileSync4(join17(framesDir, name), dst);
8984
+ const dst = join18(outputPath, formatExportFrameName(i, "png"));
8985
+ copyFileSync4(join18(framesDir, name), dst);
8866
8986
  });
8867
- if (hasAudio && audioOutputPath && existsSync13(audioOutputPath)) {
8868
- copyFileSync4(audioOutputPath, join17(outputPath, MIXED_AUDIO_FILENAME2));
8987
+ if (hasAudio && audioOutputPath && existsSync14(audioOutputPath)) {
8988
+ copyFileSync4(audioOutputPath, join18(outputPath, MIXED_AUDIO_FILENAME2));
8869
8989
  log.info(
8870
8990
  `[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
8871
8991
  );
@@ -8885,7 +9005,7 @@ async function runEncodeStage(input) {
8885
9005
  const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
8886
9006
  fps: job.config.fps,
8887
9007
  loop,
8888
- palettePath: join17(dirname10(videoOnlyPath), "gif-palette.png"),
9008
+ palettePath: join18(dirname11(videoOnlyPath), "gif-palette.png"),
8889
9009
  preserveAlpha: needsAlpha,
8890
9010
  signal: abortSignal,
8891
9011
  timeout: engineCfg.ffmpegEncodeTimeout
@@ -8944,7 +9064,7 @@ function sampleDirectoryBytes(dir) {
8944
9064
  continue;
8945
9065
  }
8946
9066
  for (const name of entries) {
8947
- const full = join18(current, name);
9067
+ const full = join19(current, name);
8948
9068
  try {
8949
9069
  const st = statSync7(full);
8950
9070
  if (st.isDirectory()) {
@@ -9026,8 +9146,8 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
9026
9146
  const ranges = [];
9027
9147
  let rangeStart = null;
9028
9148
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
9029
- const framePath = join18(framesDir, formatCaptureFrameName(frameIndex, frameExt));
9030
- const missing = !existsSync14(framePath) || statSync7(framePath).size <= 8;
9149
+ const framePath = join19(framesDir, formatCaptureFrameName(frameIndex, frameExt));
9150
+ const missing = !existsSync15(framePath) || statSync7(framePath).size <= 8;
9031
9151
  if (missing && rangeStart === null) {
9032
9152
  rangeStart = frameIndex;
9033
9153
  } else if (!missing && rangeStart !== null) {
@@ -9043,7 +9163,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
9043
9163
  function buildMissingFrameRetryBatches(ranges, maxWorkers, workDir, attempt, rangeStart = 0, stride = 1) {
9044
9164
  const workersPerBatch = Math.max(1, Math.floor(maxWorkers));
9045
9165
  const batches = [];
9046
- const outputDirFor = (batchIndex, workerId) => join18(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
9166
+ const outputDirFor = (batchIndex, workerId) => join19(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
9047
9167
  if (stride > 1) {
9048
9168
  const spans = /* @__PURE__ */ new Map();
9049
9169
  for (const range of ranges) {
@@ -9111,7 +9231,7 @@ function frameStallRule(job, totalFrames, probeStartupMs) {
9111
9231
  tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
9112
9232
  detail: () => describeWorkerPhases(job),
9113
9233
  attemptOpened: () => forgetWorkerPhases(job),
9114
- activity: () => staticDedupActivity(job)
9234
+ activity: () => captureActivity(job)
9115
9235
  };
9116
9236
  }
9117
9237
  function isRecoverableParallelCaptureError(error) {
@@ -9124,8 +9244,8 @@ function isRecoverableParallelCaptureError(error) {
9124
9244
  function countCapturedFrames(totalFrames, framesDir, frameExt) {
9125
9245
  let captured = 0;
9126
9246
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
9127
- const framePath = join18(framesDir, formatCaptureFrameName(frameIndex, frameExt));
9128
- if (existsSync14(framePath)) captured++;
9247
+ const framePath = join19(framesDir, formatCaptureFrameName(frameIndex, frameExt));
9248
+ if (existsSync15(framePath)) captured++;
9129
9249
  }
9130
9250
  return captured;
9131
9251
  }
@@ -9150,7 +9270,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
9150
9270
  reason: attempt === 0 ? "initial" : pendingTransientRetry ? "transient-retry" : "retry"
9151
9271
  });
9152
9272
  pendingTransientRetry = false;
9153
- const attemptWorkDir = join18(options.workDir, `capture-attempt-${attempt}`);
9273
+ const attemptWorkDir = join19(options.workDir, `capture-attempt-${attempt}`);
9154
9274
  const batches = missingRanges ? buildMissingFrameRetryBatches(
9155
9275
  missingRanges,
9156
9276
  currentWorkers,
@@ -9343,7 +9463,7 @@ function explainStreamingEncodeGate(cfg, outputFormat, workerCount, durationSeco
9343
9463
  var DEFAULT_SEGMENTED_MIN_SECONDS = Number.POSITIVE_INFINITY;
9344
9464
 
9345
9465
  // src/services/distributed/planFrameCost.ts
9346
- import { join as join21 } from "node:path";
9466
+ import { join as join22 } from "node:path";
9347
9467
  import {
9348
9468
  closeCaptureSession as closeCaptureSession9,
9349
9469
  createCaptureSession as createCaptureSession9,
@@ -9352,8 +9472,8 @@ import {
9352
9472
  } from "@hyperframes/engine";
9353
9473
 
9354
9474
  // src/services/distributed/chunkFrames.ts
9355
- import { existsSync as existsSync16, readdirSync as readdirSync4 } from "node:fs";
9356
- import { extname as extname2, join as join20 } from "node:path";
9475
+ import { existsSync as existsSync17, readdirSync as readdirSync4 } from "node:fs";
9476
+ import { extname as extname2, join as join21 } from "node:path";
9357
9477
  import {
9358
9478
  compositionRequiresWebGpu as compositionRequiresWebGpu3,
9359
9479
  createVideoFrameInjector as createVideoFrameInjector3,
@@ -9362,9 +9482,9 @@ import {
9362
9482
 
9363
9483
  // src/services/distributed/shared.ts
9364
9484
  import { execFile as execFileCallback } from "node:child_process";
9365
- import { dirname as dirname12, join as join19 } from "node:path";
9366
- import { existsSync as existsSync15, readFileSync as readFileSync7 } from "node:fs";
9367
- import { fileURLToPath as fileURLToPath3 } from "node:url";
9485
+ import { dirname as dirname13, join as join20 } from "node:path";
9486
+ import { existsSync as existsSync16, readFileSync as readFileSync7 } from "node:fs";
9487
+ import { fileURLToPath as fileURLToPath4 } from "node:url";
9368
9488
  import { promisify as promisify2 } from "node:util";
9369
9489
  import {
9370
9490
  getFfmpegBinary,
@@ -9378,8 +9498,8 @@ function isPlanAudioArtifactPath(path) {
9378
9498
  }
9379
9499
  function resolvePlanAudioPath(planDir) {
9380
9500
  for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
9381
- const candidate = join19(planDir, name);
9382
- if (existsSync15(candidate)) return candidate;
9501
+ const candidate = join20(planDir, name);
9502
+ if (existsSync16(candidate)) return candidate;
9383
9503
  }
9384
9504
  return null;
9385
9505
  }
@@ -9640,11 +9760,11 @@ function buildSyntheticRenderJob(input) {
9640
9760
  var cachedProducerVersion = null;
9641
9761
  function readProducerVersion() {
9642
9762
  if (cachedProducerVersion !== null) return cachedProducerVersion;
9643
- const startDir = dirname12(fileURLToPath3(import.meta.url));
9763
+ const startDir = dirname13(fileURLToPath4(import.meta.url));
9644
9764
  let current = startDir;
9645
9765
  for (let i = 0; i < 10; i++) {
9646
- const candidate = join19(current, "package.json");
9647
- if (existsSync15(candidate)) {
9766
+ const candidate = join20(current, "package.json");
9767
+ if (existsSync16(candidate)) {
9648
9768
  try {
9649
9769
  const pkg = JSON.parse(readFileSync7(candidate, "utf-8"));
9650
9770
  if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
@@ -9654,7 +9774,7 @@ function readProducerVersion() {
9654
9774
  } catch {
9655
9775
  }
9656
9776
  }
9657
- const parent = dirname12(current);
9777
+ const parent = dirname13(current);
9658
9778
  if (parent === current) break;
9659
9779
  current = parent;
9660
9780
  }
@@ -9698,8 +9818,8 @@ function frameNumberFromFileName(name) {
9698
9818
  function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
9699
9819
  const result = [];
9700
9820
  for (const v of videos) {
9701
- const outputDir = join20(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
9702
- if (!existsSync16(outputDir)) {
9821
+ const outputDir = join21(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
9822
+ if (!existsSync17(outputDir)) {
9703
9823
  throw new Error(
9704
9824
  `[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
9705
9825
  );
@@ -9717,7 +9837,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
9717
9837
  if (!frameName) continue;
9718
9838
  const frameNumber = indexMode === "sparse-v2" ? frameNumberFromFileName(frameName) : null;
9719
9839
  const frameIndex = frameNumber === null ? i : frameNumber - 1;
9720
- framePaths.set(frameIndex, join20(outputDir, frameName));
9840
+ framePaths.set(frameIndex, join21(outputDir, frameName));
9721
9841
  }
9722
9842
  result.push({
9723
9843
  videoId: v.videoId,
@@ -9794,11 +9914,12 @@ async function extractDeferredVideoFramesForChunk(input) {
9794
9914
  outputRoot: input.outputRoot,
9795
9915
  cfg: input.cfg,
9796
9916
  shownBoxes: input.shownBoxes,
9917
+ ...input.onProgress && { onProgress: input.onProgress },
9797
9918
  sourceOf: (video) => {
9798
9919
  const range = planned.get(video.videoId).deferredRange;
9799
9920
  const remoteUrl = remoteSources[range.sourcePath];
9800
- const sourcePath = remoteUrl ?? join20(input.planDir, ...range.sourcePath.split("/"));
9801
- if (remoteUrl === void 0 && !existsSync16(sourcePath)) {
9921
+ const sourcePath = remoteUrl ?? join21(input.planDir, ...range.sourcePath.split("/"));
9922
+ if (remoteUrl === void 0 && !existsSync17(sourcePath)) {
9802
9923
  throw new RenderChunkValidationError(
9803
9924
  MISSING_PLAN_ARTIFACT,
9804
9925
  `[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
@@ -9828,12 +9949,12 @@ async function measurePlanSecondsPerFrame(input) {
9828
9949
  planVideos,
9829
9950
  frames: sampled,
9830
9951
  fps: fpsRatio,
9831
- outputRoot: join21(workDir, "frame-cost-video-frames"),
9952
+ outputRoot: join22(workDir, "frame-cost-video-frames"),
9832
9953
  cfg: input.cfg
9833
9954
  })
9834
9955
  ];
9835
9956
  const lookup = extracted.length > 0 ? createFrameLookupTable4(planVideos.videos, extracted, resolveRenderFpsConfig(fpsRatio).value) : null;
9836
- const compiledDir = join21(planDir, "compiled");
9957
+ const compiledDir = join22(planDir, "compiled");
9837
9958
  const fileServer = await createFileServer({
9838
9959
  projectDir: compiledDir,
9839
9960
  compiledDir,
@@ -9845,7 +9966,7 @@ async function measurePlanSecondsPerFrame(input) {
9845
9966
  try {
9846
9967
  session = await createCaptureSession9(
9847
9968
  fileServer.url,
9848
- join21(workDir, "frame-cost"),
9969
+ join22(workDir, "frame-cost"),
9849
9970
  buildChunkCaptureOptions({
9850
9971
  dimensions: { ...input, fpsNum: fps, fpsDen: 1 },
9851
9972
  encoder: input,
@@ -9942,7 +10063,7 @@ function buildWeightedChunkSlices(weights, chunkCount, minFrames, maxFrames) {
9942
10063
  }
9943
10064
 
9944
10065
  // src/services/render/planReferenceBackground.ts
9945
- import { join as join22 } from "node:path";
10066
+ import { join as join23 } from "node:path";
9946
10067
  import {
9947
10068
  closeCaptureSession as closeCaptureSession10,
9948
10069
  createCaptureSession as createCaptureSession10,
@@ -9955,14 +10076,14 @@ async function readPlanReferenceBackground(input) {
9955
10076
  try {
9956
10077
  server = await createFileServer({
9957
10078
  projectDir: input.projectDir,
9958
- compiledDir: join22(input.workDir, "compiled"),
10079
+ compiledDir: join23(input.workDir, "compiled"),
9959
10080
  port: 0,
9960
10081
  preHeadScripts: [VIRTUAL_TIME_SHIM],
9961
10082
  fps: input.options.fps
9962
10083
  });
9963
10084
  session = await createCaptureSession10(
9964
10085
  server.url,
9965
- join22(input.workDir, "reference"),
10086
+ join23(input.workDir, "reference"),
9966
10087
  {
9967
10088
  ...input.options,
9968
10089
  requiresWebGpu: false
@@ -9998,8 +10119,8 @@ async function readPlanReferenceBackground(input) {
9998
10119
  }
9999
10120
 
10000
10121
  // src/services/render/stages/freezePlan.ts
10001
- import { existsSync as existsSync17, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync5, writeFileSync as writeFileSync6 } from "node:fs";
10002
- import { join as join23, relative as relative4, resolve as resolve8 } from "node:path";
10122
+ import { existsSync as existsSync18, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync5, writeFileSync as writeFileSync6 } from "node:fs";
10123
+ import { join as join24, relative as relative4, resolve as resolve8 } from "node:path";
10003
10124
  import {
10004
10125
  REFERENCE_BACKGROUND_FIELD,
10005
10126
  referenceBackgroundResult as referenceBackgroundResult3
@@ -10192,7 +10313,7 @@ function planFileSha256(absolutePath, digests) {
10192
10313
  return sha256;
10193
10314
  }
10194
10315
  async function prehashPlanFiles(dir, digests) {
10195
- if (!existsSync17(dir)) return;
10316
+ if (!existsSync18(dir)) return;
10196
10317
  for (const { absolutePath } of listPlanFiles(dir)) {
10197
10318
  if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
10198
10319
  }
@@ -10217,7 +10338,7 @@ function listPlanFiles(planDir) {
10217
10338
  function walk(dir) {
10218
10339
  const entries = readdirSync5(dir, { withFileTypes: true });
10219
10340
  for (const entry of entries) {
10220
- const full = join23(dir, entry.name);
10341
+ const full = join24(dir, entry.name);
10221
10342
  if (entry.isDirectory()) {
10222
10343
  walk(full);
10223
10344
  } else if (entry.isFile()) {
@@ -10258,19 +10379,19 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
10258
10379
  function writePlanRemoteFiles(planDir, files) {
10259
10380
  if (files.length === 0) return;
10260
10381
  const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
10261
- writeFileSync6(join23(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
10382
+ writeFileSync6(join24(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
10262
10383
  }
10263
10384
  function readPlanRemoteFiles(planDir) {
10264
- const path = join23(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
10265
- return existsSync17(path) ? JSON.parse(readFileSync8(path, "utf-8")) : [];
10385
+ const path = join24(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
10386
+ return existsSync18(path) ? JSON.parse(readFileSync8(path, "utf-8")) : [];
10266
10387
  }
10267
10388
  function recomputePlanHashFromPlanDir(planDir, digests) {
10268
- const planJsonPath = join23(planDir, "plan.json");
10269
- const encoderJsonPath = join23(planDir, "meta", "encoder.json");
10270
- if (!existsSync17(planJsonPath)) {
10389
+ const planJsonPath = join24(planDir, "plan.json");
10390
+ const encoderJsonPath = join24(planDir, "meta", "encoder.json");
10391
+ if (!existsSync18(planJsonPath)) {
10271
10392
  throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
10272
10393
  }
10273
- if (!existsSync17(encoderJsonPath)) {
10394
+ if (!existsSync18(encoderJsonPath)) {
10274
10395
  throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
10275
10396
  }
10276
10397
  const planJson = JSON.parse(readFileSync8(planJsonPath, "utf-8"));
@@ -10300,21 +10421,21 @@ async function freezePlan(input) {
10300
10421
  hasAudio,
10301
10422
  digests
10302
10423
  } = input;
10303
- if (!existsSync17(planDir)) {
10424
+ if (!existsSync18(planDir)) {
10304
10425
  throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
10305
10426
  }
10306
- const metaDir = join23(planDir, "meta");
10307
- if (!existsSync17(metaDir)) mkdirSync7(metaDir, { recursive: true });
10427
+ const metaDir = join24(planDir, "meta");
10428
+ if (!existsSync18(metaDir)) mkdirSync7(metaDir, { recursive: true });
10308
10429
  writeFileSync6(
10309
- join23(metaDir, "composition.json"),
10430
+ join24(metaDir, "composition.json"),
10310
10431
  `${JSON.stringify(composition, null, 2)}
10311
10432
  `,
10312
10433
  "utf-8"
10313
10434
  );
10314
10435
  const encoderForCanonical = stripUndefined(encoder);
10315
10436
  const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
10316
- writeFileSync6(join23(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
10317
- writeFileSync6(join23(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
10437
+ writeFileSync6(join24(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
10438
+ writeFileSync6(join24(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
10318
10439
  `, "utf-8");
10319
10440
  const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
10320
10441
  const planHash = computePlanHash({
@@ -10339,7 +10460,7 @@ async function freezePlan(input) {
10339
10460
  duration: durationSeconds,
10340
10461
  hasAudio
10341
10462
  };
10342
- const planJsonPath = join23(planDir, "plan.json");
10463
+ const planJsonPath = join24(planDir, "plan.json");
10343
10464
  writeFileSync6(planJsonPath, `${JSON.stringify(planJson, null, 2)}
10344
10465
  `, "utf-8");
10345
10466
  return { planJsonPath, planHash };
@@ -10381,16 +10502,16 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
10381
10502
  }
10382
10503
 
10383
10504
  // src/services/distributed/chunkAudio.ts
10384
- import { closeSync as closeSync4, existsSync as existsSync18, ftruncateSync, mkdirSync as mkdirSync9, openSync as openSync4, readFileSync as readFileSync9 } from "node:fs";
10505
+ import { closeSync as closeSync4, existsSync as existsSync19, ftruncateSync, mkdirSync as mkdirSync9, openSync as openSync4, readFileSync as readFileSync9 } from "node:fs";
10385
10506
  import { writeFileSync as writeFileSync7, writeSync } from "node:fs";
10386
- import { join as join25 } from "node:path";
10507
+ import { join as join26 } from "node:path";
10387
10508
  import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
10388
10509
 
10389
10510
  // src/services/distributed/mp4Stitch.ts
10390
10511
  import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync8, rmSync as rmSync6 } from "node:fs";
10391
10512
  import { open } from "node:fs/promises";
10392
10513
  import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
10393
- import { basename as basename5, dirname as dirname13, join as join24 } from "node:path";
10514
+ import { basename as basename5, dirname as dirname14, join as join25 } from "node:path";
10394
10515
  import { finished, pipeline } from "node:stream/promises";
10395
10516
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
10396
10517
  function boxAt(src, off, at, limit) {
@@ -10755,15 +10876,15 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
10755
10876
  const sourcePaths = audioPath ? [audioPath, ...chunkPaths] : chunkPaths;
10756
10877
  const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
10757
10878
  const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
10758
- mkdirSync8(dirname13(outputPath), { recursive: true });
10759
- const workDir = createStagingDir4(dirname13(outputPath), `${basename5(outputPath)}.stitch-`);
10760
- const out = createWriteStream(join24(workDir, "out.mp4"));
10879
+ mkdirSync8(dirname14(outputPath), { recursive: true });
10880
+ const workDir = createStagingDir4(dirname14(outputPath), `${basename5(outputPath)}.stitch-`);
10881
+ const out = createWriteStream(join25(workDir, "out.mp4"));
10761
10882
  try {
10762
10883
  out.write(header);
10763
10884
  for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
10764
10885
  out.end();
10765
10886
  await finished(out);
10766
- renameWithRetry6(join24(workDir, "out.mp4"), outputPath);
10887
+ renameWithRetry6(join25(workDir, "out.mp4"), outputPath);
10767
10888
  } finally {
10768
10889
  out.destroy();
10769
10890
  rmSync6(workDir, { recursive: true, force: true });
@@ -10857,7 +10978,7 @@ async function writeChunkAudioSlices(input) {
10857
10978
  });
10858
10979
  const bytes = readFileSync9(input.audioPath);
10859
10980
  const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
10860
- mkdirSync9(join25(input.planDir, SLICE_DIR), { recursive: true });
10981
+ mkdirSync9(join26(input.planDir, SLICE_DIR), { recursive: true });
10861
10982
  input.chunks.forEach((_, index) => {
10862
10983
  const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
10863
10984
  if (!cut) return;
@@ -10865,17 +10986,17 @@ async function writeChunkAudioSlices(input) {
10865
10986
  const start = offsets[cut.firstPacket];
10866
10987
  layout.partStarts[index] = start;
10867
10988
  const end = offsets[last] + track.sizes[last];
10868
- writeFileSync7(join25(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
10989
+ writeFileSync7(join26(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
10869
10990
  });
10870
10991
  const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
10871
- writeFileSync7(join25(input.planDir, SLICE_FRAME), Buffer.concat(frame));
10872
- writeFileSync7(join25(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
10992
+ writeFileSync7(join26(input.planDir, SLICE_FRAME), Buffer.concat(frame));
10993
+ writeFileSync7(join26(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
10873
10994
  }
10874
10995
  function chunkAudioSource(planDir, chunkIndex, scratchPath) {
10875
- const layoutPath = join25(planDir, SLICE_LAYOUT);
10876
- if (!existsSync18(layoutPath)) return resolvePlanAudioPath(planDir);
10996
+ const layoutPath = join26(planDir, SLICE_LAYOUT);
10997
+ if (!existsSync19(layoutPath)) return resolvePlanAudioPath(planDir);
10877
10998
  const layout = JSON.parse(readFileSync9(layoutPath, "utf-8"));
10878
- const frame = readFileSync9(join25(planDir, SLICE_FRAME));
10999
+ const frame = readFileSync9(join26(planDir, SLICE_FRAME));
10879
11000
  const fd = openSync4(scratchPath, "w");
10880
11001
  try {
10881
11002
  writeSync(fd, frame, 0, layout.payloadStart, 0);
@@ -10888,7 +11009,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
10888
11009
  );
10889
11010
  const start = layout.partStarts[chunkIndex];
10890
11011
  if (start !== void 0) {
10891
- const part = readFileSync9(join25(planDir, chunkAudioSlicePath(chunkIndex)));
11012
+ const part = readFileSync9(join26(planDir, chunkAudioSlicePath(chunkIndex)));
10892
11013
  writeSync(fd, part, 0, part.length, start);
10893
11014
  }
10894
11015
  ftruncateSync(fd, layout.sizeBytes);
@@ -10944,7 +11065,7 @@ async function muxChunkWithAudio(input) {
10944
11065
  // src/services/distributed/planSize.ts
10945
11066
  import { createHash as createHash8 } from "node:crypto";
10946
11067
  import { lstatSync, readdirSync as readdirSync6 } from "node:fs";
10947
- import { extname as extname3, join as join26, relative as relative5 } from "node:path";
11068
+ import { extname as extname3, join as join27, relative as relative5 } from "node:path";
10948
11069
  var MAX_TOP_COMPONENTS = 10;
10949
11070
  var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
10950
11071
  ".aac",
@@ -11056,7 +11177,7 @@ function walkRegularFiles(dir, visit) {
11056
11177
  return;
11057
11178
  }
11058
11179
  for (const entry of entries) {
11059
- const full = join26(dir, entry.name);
11180
+ const full = join27(dir, entry.name);
11060
11181
  if (entry.isDirectory()) {
11061
11182
  walkRegularFiles(full, visit);
11062
11183
  } else if (entry.isFile()) {
@@ -11276,13 +11397,13 @@ function assertPositiveInteger(name, value) {
11276
11397
  }
11277
11398
  var FREEZE_OWNED_PLAN_FILES = [
11278
11399
  "plan.json",
11279
- join27("meta", "composition.json"),
11280
- join27("meta", "encoder.json"),
11281
- join27("meta", "chunks.json")
11400
+ join28("meta", "composition.json"),
11401
+ join28("meta", "encoder.json"),
11402
+ join28("meta", "chunks.json")
11282
11403
  ];
11283
11404
  function removeFreezeOwnedPlanFiles(planDir) {
11284
11405
  for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
11285
- rmSync7(join27(planDir, relativePath), { force: true });
11406
+ rmSync7(join28(planDir, relativePath), { force: true });
11286
11407
  }
11287
11408
  }
11288
11409
  function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
@@ -11440,19 +11561,19 @@ function createVideoSourceShipper(input) {
11440
11561
  const known = shipped.get(srcPath);
11441
11562
  if (known) return known;
11442
11563
  const stagedRel = pathInside(input.workVideoFramesDir, srcPath);
11443
- const current = stagedRel === null ? srcPath : join27(input.planDir, "video-frames", stagedRel);
11564
+ const current = stagedRel === null ? srcPath : join28(input.planDir, "video-frames", stagedRel);
11444
11565
  let result = null;
11445
11566
  for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
11446
11567
  const rel = pathInside(root, srcPath);
11447
- if (rel !== null && (existsSync19(join27(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
11568
+ if (rel !== null && (existsSync20(join28(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
11448
11569
  result = ["compiled", ...rel.split(sep4)].join("/");
11449
11570
  break;
11450
11571
  }
11451
11572
  }
11452
11573
  if (result === null) {
11453
11574
  result = `video-sources/${shipped.size}${extname4(current)}`;
11454
- const destination = join27(input.planDir, ...result.split("/"));
11455
- mkdirSync10(join27(input.planDir, "video-sources"), { recursive: true });
11575
+ const destination = join28(input.planDir, ...result.split("/"));
11576
+ mkdirSync10(join28(input.planDir, "video-sources"), { recursive: true });
11456
11577
  try {
11457
11578
  linkSync(current, destination);
11458
11579
  } catch {
@@ -11472,7 +11593,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
11472
11593
  useGpu: false,
11473
11594
  browserGpuMode: "software"
11474
11595
  });
11475
- if (!existsSync19(planDir)) mkdirSync10(planDir, { recursive: true });
11596
+ if (!existsSync20(planDir)) mkdirSync10(planDir, { recursive: true });
11476
11597
  const log = config.logger ?? defaultLogger;
11477
11598
  const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
11478
11599
  const abortSignal = config.abortSignal;
@@ -11506,14 +11627,14 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
11506
11627
  includeOutsideScripts: options.includeOutsideScripts === true
11507
11628
  });
11508
11629
  const entryFile = config.entryFile ?? "index.html";
11509
- const htmlPath = join27(projectDir, entryFile);
11510
- if (!existsSync19(htmlPath)) {
11630
+ const htmlPath = join28(projectDir, entryFile);
11631
+ if (!existsSync20(htmlPath)) {
11511
11632
  throw new Error(`[plan] entry file not found: ${htmlPath}`);
11512
11633
  }
11513
- const workDir = join27(planDir, ".plan-work");
11634
+ const workDir = join28(planDir, ".plan-work");
11514
11635
  rmSync7(workDir, { recursive: true, force: true });
11515
11636
  mkdirSync10(workDir, { recursive: true });
11516
- const compiledDir = join27(workDir, "compiled");
11637
+ const compiledDir = join28(workDir, "compiled");
11517
11638
  mkdirSync10(compiledDir, { recursive: true });
11518
11639
  let stageStarted = Date.now();
11519
11640
  cpSync2(projectDir, compiledDir, {
@@ -11533,10 +11654,10 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
11533
11654
  }
11534
11655
  });
11535
11656
  logPlanStage(log, "copy", stageStarted);
11536
- const finalCompiledDir = join27(planDir, "compiled");
11657
+ const finalCompiledDir = join28(planDir, "compiled");
11537
11658
  const needsAlpha = outputNeedsAlpha(config.format);
11538
11659
  const remoteFiles = Object.entries(options.remoteFiles ?? {});
11539
- const remoteLocalPath = (rel) => join27(projectDir, ...rel.split("/"));
11660
+ const remoteLocalPath = (rel) => join28(projectDir, ...rel.split("/"));
11540
11661
  for (const [, file] of remoteFiles) {
11541
11662
  declareContentAddressedUrl(file.url, file.sha256);
11542
11663
  if (file.probeFactsUrl) declareProbeFactsUrl(file.url, file.probeFactsUrl);
@@ -11741,17 +11862,17 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
11741
11862
  let stageStarted = Date.now();
11742
11863
  const extractResult = await extractPlanVideos(c, options.deferVideoExtraction);
11743
11864
  logPlanStage(log, "extract", stageStarted);
11744
- const stagedVideoFrames = join27(compiledDir, "__hyperframes_video_frames");
11745
- const videoFramesDst = join27(planDir, "video-frames");
11746
- if (existsSync19(videoFramesDst)) rmSync7(videoFramesDst, { recursive: true, force: true });
11747
- const videoSourcesDir = join27(planDir, "video-sources");
11865
+ const stagedVideoFrames = join28(compiledDir, "__hyperframes_video_frames");
11866
+ const videoFramesDst = join28(planDir, "video-frames");
11867
+ if (existsSync20(videoFramesDst)) rmSync7(videoFramesDst, { recursive: true, force: true });
11868
+ const videoSourcesDir = join28(planDir, "video-sources");
11748
11869
  rmSync7(videoSourcesDir, { recursive: true, force: true });
11749
- if (existsSync19(stagedVideoFrames)) {
11870
+ if (existsSync20(stagedVideoFrames)) {
11750
11871
  renameWithRetry7(stagedVideoFrames, videoFramesDst);
11751
11872
  } else {
11752
11873
  mkdirSync10(videoFramesDst, { recursive: true });
11753
11874
  }
11754
- if (existsSync19(finalCompiledDir)) rmSync7(finalCompiledDir, { recursive: true, force: true });
11875
+ if (existsSync20(finalCompiledDir)) rmSync7(finalCompiledDir, { recursive: true, force: true });
11755
11876
  renameWithRetry7(compiledDir, finalCompiledDir);
11756
11877
  const shipVideoSource = createVideoSourceShipper({
11757
11878
  planDir,
@@ -11781,7 +11902,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
11781
11902
  };
11782
11903
  })
11783
11904
  });
11784
- mkdirSync10(join27(planDir, "meta"), { recursive: true });
11905
+ mkdirSync10(join28(planDir, "meta"), { recursive: true });
11785
11906
  writePlanRemoteFiles(
11786
11907
  planDir,
11787
11908
  remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
@@ -11791,7 +11912,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
11791
11912
  }))
11792
11913
  );
11793
11914
  writeFileSync8(
11794
- join27(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
11915
+ join28(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
11795
11916
  JSON.stringify(planVideosJson, null, 2),
11796
11917
  "utf-8"
11797
11918
  );
@@ -11871,11 +11992,11 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
11871
11992
  if (audioResult?.audioError) {
11872
11993
  applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
11873
11994
  }
11874
- const planAudioPath = join27(planDir, PLAN_AUDIO_RELATIVE_PATH);
11875
- if (audioResult?.hasAudio && existsSync19(audioResult.audioOutputPath)) {
11995
+ const planAudioPath = join28(planDir, PLAN_AUDIO_RELATIVE_PATH);
11996
+ if (audioResult?.hasAudio && existsSync20(audioResult.audioOutputPath)) {
11876
11997
  renameWithRetry7(audioResult.audioOutputPath, planAudioPath);
11877
11998
  }
11878
- if (chunksCarryAudio && existsSync19(planAudioPath)) {
11999
+ if (chunksCarryAudio && existsSync20(planAudioPath)) {
11879
12000
  if (options.sliceChunkAudio) {
11880
12001
  stageStarted = Date.now();
11881
12002
  await writeChunkAudioSlices({
@@ -11995,7 +12116,7 @@ async function buildPlanAudio(projectDir, config, workRoot, outputPath, options
11995
12116
  if (mixed.audioError) {
11996
12117
  applyDistributedAudioWarningPolicy(c.job, mixed.audioError, mixed.audioFailures, c.log);
11997
12118
  }
11998
- if (!mixed.hasAudio || !existsSync19(mixed.audioOutputPath)) return { hasAudio: false };
12119
+ if (!mixed.hasAudio || !existsSync20(mixed.audioOutputPath)) return { hasAudio: false };
11999
12120
  renameWithRetry7(mixed.audioOutputPath, outputPath);
12000
12121
  return { hasAudio: true };
12001
12122
  } finally {
@@ -12010,7 +12131,7 @@ import {
12010
12131
  } from "@hyperframes/engine";
12011
12132
  import {
12012
12133
  copyFileSync as copyFileSync8,
12013
- existsSync as existsSync21,
12134
+ existsSync as existsSync22,
12014
12135
  lstatSync as lstatSync2,
12015
12136
  mkdirSync as mkdirSync12,
12016
12137
  readFileSync as readFileSync10,
@@ -12020,7 +12141,7 @@ import {
12020
12141
  writeFileSync as writeFileSync10
12021
12142
  } from "node:fs";
12022
12143
  import { tmpdir } from "node:os";
12023
- import { dirname as dirname15, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep5 } from "node:path";
12144
+ import { dirname as dirname16, isAbsolute as isAbsolute4, join as join31, relative as relative7, resolve as resolve9, sep as sep5 } from "node:path";
12024
12145
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
12025
12146
  import {
12026
12147
  createFrameLookupTable as createFrameLookupTable5,
@@ -12031,7 +12152,7 @@ import {
12031
12152
  // src/services/distributed/planV2Publisher.ts
12032
12153
  import {
12033
12154
  copyFileSync as copyFileSync7,
12034
- existsSync as existsSync20,
12155
+ existsSync as existsSync21,
12035
12156
  linkSync as linkSync2,
12036
12157
  mkdirSync as mkdirSync11,
12037
12158
  rmSync as rmSync8,
@@ -12039,7 +12160,7 @@ import {
12039
12160
  writeFileSync as writeFileSync9
12040
12161
  } from "node:fs";
12041
12162
  import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
12042
- import { dirname as dirname14, join as join29 } from "node:path";
12163
+ import { dirname as dirname15, join as join30 } from "node:path";
12043
12164
 
12044
12165
  // src/services/distributed/planV2Errors.ts
12045
12166
  var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
@@ -12054,7 +12175,7 @@ var PlanV2IntegrityError = class extends Error {
12054
12175
  };
12055
12176
 
12056
12177
  // src/services/distributed/planV2Layout.ts
12057
- import { join as join28 } from "node:path";
12178
+ import { join as join29 } from "node:path";
12058
12179
  var SHA256_PATTERN = /^[0-9a-f]{64}$/;
12059
12180
  function assertPlanV2Sha256(value, field) {
12060
12181
  if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
@@ -12064,7 +12185,7 @@ function assertPlanV2Sha256(value, field) {
12064
12185
  }
12065
12186
  function planV2BlobPath(root, sha256) {
12066
12187
  const digest = assertPlanV2Sha256(sha256, "artifact sha256");
12067
- return join28(root, "artifacts", "sha256", digest.slice(0, 2), digest);
12188
+ return join29(root, "artifacts", "sha256", digest.slice(0, 2), digest);
12068
12189
  }
12069
12190
 
12070
12191
  // src/services/distributed/planV2Publisher.ts
@@ -12095,13 +12216,13 @@ var LocalPlanV2ArtifactPublisher = class {
12095
12216
  #linkFile;
12096
12217
  #committed = false;
12097
12218
  constructor(destinationDir, options = {}) {
12098
- if (existsSync20(destinationDir)) {
12219
+ if (existsSync21(destinationDir)) {
12099
12220
  throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
12100
12221
  }
12101
12222
  this.destinationDir = destinationDir;
12102
12223
  this.#linkFile = options.linkFile ?? linkSync2;
12103
- mkdirSync11(dirname14(destinationDir), { recursive: true });
12104
- this.temporaryDir = createStagingDir5(dirname14(destinationDir), ".plan-v2-publish-");
12224
+ mkdirSync11(dirname15(destinationDir), { recursive: true });
12225
+ this.temporaryDir = createStagingDir5(dirname15(destinationDir), ".plan-v2-publish-");
12105
12226
  }
12106
12227
  async putBlob(blob) {
12107
12228
  const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
@@ -12112,10 +12233,10 @@ var LocalPlanV2ArtifactPublisher = class {
12112
12233
  );
12113
12234
  }
12114
12235
  const destinationPath = planV2BlobPath(this.temporaryDir, digest);
12115
- if (existsSync20(destinationPath)) return;
12116
- mkdirSync11(dirname14(destinationPath), { recursive: true });
12117
- const stagingDir = createStagingDir5(dirname14(destinationPath), ".plan-v2-blob-");
12118
- const temporaryPath = join29(stagingDir, "blob");
12236
+ if (existsSync21(destinationPath)) return;
12237
+ mkdirSync11(dirname15(destinationPath), { recursive: true });
12238
+ const stagingDir = createStagingDir5(dirname15(destinationPath), ".plan-v2-blob-");
12239
+ const temporaryPath = join30(stagingDir, "blob");
12119
12240
  try {
12120
12241
  try {
12121
12242
  this.#linkFile(blob.sourcePath, temporaryPath);
@@ -12130,13 +12251,13 @@ var LocalPlanV2ArtifactPublisher = class {
12130
12251
  }
12131
12252
  async commitManifest(manifestBytes) {
12132
12253
  for (const digest of new Set(manifestDigests(manifestBytes))) {
12133
- if (!existsSync20(planV2BlobPath(this.temporaryDir, digest))) {
12254
+ if (!existsSync21(planV2BlobPath(this.temporaryDir, digest))) {
12134
12255
  throw new PlanV2IntegrityError(
12135
12256
  `cannot commit manifest before referenced blob is durable: ${digest}`
12136
12257
  );
12137
12258
  }
12138
12259
  }
12139
- writeFileSync9(join29(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
12260
+ writeFileSync9(join30(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
12140
12261
  renameWithRetry8(this.temporaryDir, this.destinationDir);
12141
12262
  this.#committed = true;
12142
12263
  }
@@ -12182,7 +12303,7 @@ function listFiles(root) {
12182
12303
  const rootResolved = resolve9(root);
12183
12304
  function walk(dir) {
12184
12305
  for (const entry of readdirSync7(dir, { withFileTypes: true })) {
12185
- const absolutePath = join30(dir, entry.name);
12306
+ const absolutePath = join31(dir, entry.name);
12186
12307
  if (entry.isDirectory()) {
12187
12308
  walk(absolutePath);
12188
12309
  } else if (entry.isFile()) {
@@ -12209,13 +12330,13 @@ function assertValidExtractionCacheCompleteSentinel(path) {
12209
12330
  }
12210
12331
  }
12211
12332
  function validateExtractionCacheCompleteSentinels(executionPlanDir) {
12212
- const videoRoot = join30(executionPlanDir, "video-frames");
12213
- if (!existsSync21(videoRoot)) return;
12333
+ const videoRoot = join31(executionPlanDir, "video-frames");
12334
+ if (!existsSync22(videoRoot)) return;
12214
12335
  for (const videoEntry of readdirSync7(videoRoot, { withFileTypes: true })) {
12215
12336
  if (!videoEntry.isDirectory()) continue;
12216
- const videoDir = join30(videoRoot, videoEntry.name);
12337
+ const videoDir = join31(videoRoot, videoEntry.name);
12217
12338
  if (readdirSync7(videoDir).includes(EXTRACTION_CACHE_COMPLETE_SENTINEL)) {
12218
- const sentinelPath = join30(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
12339
+ const sentinelPath = join31(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
12219
12340
  assertValidExtractionCacheCompleteSentinel(sentinelPath);
12220
12341
  }
12221
12342
  }
@@ -12262,7 +12383,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
12262
12383
  if (video.deferredRange) {
12263
12384
  const framePaths2 = /* @__PURE__ */ new Map();
12264
12385
  for (let index = 0; index < video.totalFrames; index++) {
12265
- framePaths2.set(index, join30(outputDir, String(index)));
12386
+ framePaths2.set(index, join31(outputDir, String(index)));
12266
12387
  }
12267
12388
  return { ...video, outputDir, framePaths: framePaths2, ownedByLookup: false };
12268
12389
  }
@@ -12270,7 +12391,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
12270
12391
  const framePaths = /* @__PURE__ */ new Map();
12271
12392
  for (const frameName of frameNames) {
12272
12393
  if (frameName === EXTRACTION_CACHE_COMPLETE_SENTINEL) {
12273
- assertValidExtractionCacheCompleteSentinel(join30(outputDir, frameName));
12394
+ assertValidExtractionCacheCompleteSentinel(join31(outputDir, frameName));
12274
12395
  continue;
12275
12396
  }
12276
12397
  const match = /(\d+)(?=\.[^.]+$)/.exec(frameName);
@@ -12289,7 +12410,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
12289
12410
  `duplicate extracted frame index ${frameIndex} in ${outputDir}`
12290
12411
  );
12291
12412
  }
12292
- framePaths.set(frameIndex, join30(outputDir, frameName));
12413
+ framePaths.set(frameIndex, join31(outputDir, frameName));
12293
12414
  }
12294
12415
  return {
12295
12416
  ...video,
@@ -12310,8 +12431,8 @@ function parsePlanVideosJson2(value) {
12310
12431
  }
12311
12432
  }
12312
12433
  function materializeExtractedVideoDirectories(planDir) {
12313
- const videosPath = join30(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
12314
- if (!existsSync21(videosPath)) return;
12434
+ const videosPath = join31(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
12435
+ if (!existsSync22(videosPath)) return;
12315
12436
  const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
12316
12437
  for (const video of videos.extracted) {
12317
12438
  mkdirSync12(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
@@ -12344,13 +12465,13 @@ function parseChunkSlices(value) {
12344
12465
  });
12345
12466
  }
12346
12467
  function buildVideoChunkDependencies(executionPlanDir, dimensions) {
12347
- const videoRoot = join30(executionPlanDir, "video-frames");
12348
- const hasExtractedFrames = existsSync21(videoRoot) && listFiles(videoRoot).length > 0;
12349
- const videosPath = join30(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
12350
- if (!existsSync21(videosPath)) {
12468
+ const videoRoot = join31(executionPlanDir, "video-frames");
12469
+ const hasExtractedFrames = existsSync22(videoRoot) && listFiles(videoRoot).length > 0;
12470
+ const videosPath = join31(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
12471
+ if (!existsSync22(videosPath)) {
12351
12472
  return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
12352
12473
  }
12353
- const chunksPath = join30(executionPlanDir, "meta", "chunks.json");
12474
+ const chunksPath = join31(executionPlanDir, "meta", "chunks.json");
12354
12475
  const videos = readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH);
12355
12476
  const chunks = readJsonFile(chunksPath, "meta/chunks.json");
12356
12477
  const parsedVideos = parsePlanVideosJson2(videos);
@@ -12404,10 +12525,10 @@ function computeManifestHash(manifest) {
12404
12525
  return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
12405
12526
  }
12406
12527
  function writeBlob(sourcePath, destinationPath) {
12407
- if (existsSync21(destinationPath)) return;
12408
- mkdirSync12(dirname15(destinationPath), { recursive: true });
12409
- const temporaryDir = createStagingDir6(dirname15(destinationPath), ".plan-v2-blob-");
12410
- const temporaryPath = join30(temporaryDir, "blob");
12528
+ if (existsSync22(destinationPath)) return;
12529
+ mkdirSync12(dirname16(destinationPath), { recursive: true });
12530
+ const temporaryDir = createStagingDir6(dirname16(destinationPath), ".plan-v2-blob-");
12531
+ const temporaryPath = join31(temporaryDir, "blob");
12411
12532
  try {
12412
12533
  copyFileSync8(sourcePath, temporaryPath);
12413
12534
  renameWithRetry9(temporaryPath, destinationPath);
@@ -12443,8 +12564,8 @@ async function putTasks(tasks) {
12443
12564
  if (failure) throw failure.reason;
12444
12565
  }
12445
12566
  function buildPlanV2Publication(executionPlanDir, digests) {
12446
- const executionPlanPath = join30(executionPlanDir, "plan.json");
12447
- if (!existsSync21(executionPlanPath)) {
12567
+ const executionPlanPath = join31(executionPlanDir, "plan.json");
12568
+ if (!existsSync22(executionPlanPath)) {
12448
12569
  throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
12449
12570
  }
12450
12571
  const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
@@ -12471,7 +12592,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
12471
12592
  }
12472
12593
  validateExtractionCacheCompleteSentinels(executionPlanDir);
12473
12594
  const videoDependencyPlan = buildVideoChunkDependencies(executionPlanDir, dimensions);
12474
- const encoder = readJsonFile(join30(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
12595
+ const encoder = readJsonFile(join31(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
12475
12596
  const files = listFiles(executionPlanDir);
12476
12597
  const chunkAudio = !isRecord3(encoder) || encoder.chunksCarryAudio !== true ? "none" : files.some((file) => chunkAudioSliceTarget(file.path) !== null) ? "sliced" : "whole";
12477
12598
  for (const file of files) {
@@ -12524,21 +12645,21 @@ function buildPlanV2Publication(executionPlanDir, digests) {
12524
12645
  };
12525
12646
  }
12526
12647
  function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
12527
- if (existsSync21(planV2Dir)) {
12648
+ if (existsSync22(planV2Dir)) {
12528
12649
  throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
12529
12650
  }
12530
12651
  const publication = buildPlanV2Publication(executionPlanDir);
12531
12652
  if (publication.storedBlobs.length > 0) {
12532
12653
  throw new PlanV2IntegrityError("a local plan v2 directory cannot reference remote files");
12533
12654
  }
12534
- mkdirSync12(dirname15(planV2Dir), { recursive: true });
12535
- const tempDir = createStagingDir6(dirname15(planV2Dir), ".plan-v2-build-");
12655
+ mkdirSync12(dirname16(planV2Dir), { recursive: true });
12656
+ const tempDir = createStagingDir6(dirname16(planV2Dir), ".plan-v2-build-");
12536
12657
  try {
12537
12658
  for (const blob of publication.blobs) {
12538
12659
  writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
12539
12660
  }
12540
12661
  writeFileSync10(
12541
- join30(tempDir, "plan.json"),
12662
+ join31(tempDir, "plan.json"),
12542
12663
  canonicalJsonStringify(publication.manifest),
12543
12664
  "utf-8"
12544
12665
  );
@@ -12590,7 +12711,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
12590
12711
  // artifactTargets ships every compiled/ file to all chunks, so each is in the manifest.
12591
12712
  whileAudioMixes: () => putBlobs(
12592
12713
  publisher,
12593
- listFiles(join30(stagingRoot, "compiled")).map(
12714
+ listFiles(join31(stagingRoot, "compiled")).map(
12594
12715
  (file) => publishBlobFor(file.absolutePath, digests)
12595
12716
  )
12596
12717
  ),
@@ -12614,12 +12735,12 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
12614
12735
  }
12615
12736
  }
12616
12737
  async function planV2(projectDir, config, planV2Dir) {
12617
- if (existsSync21(planV2Dir)) {
12738
+ if (existsSync22(planV2Dir)) {
12618
12739
  throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
12619
12740
  }
12620
12741
  const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
12621
12742
  const manifest = await planV2WithPublisher(projectDir, config, publisher, {
12622
- stagingParentDir: dirname15(planV2Dir)
12743
+ stagingParentDir: dirname16(planV2Dir)
12623
12744
  });
12624
12745
  return resultFromManifest(planV2Dir, manifest);
12625
12746
  }
@@ -12631,7 +12752,7 @@ function resultFromManifest(planV2Dir, manifest) {
12631
12752
  isRecord3(executionPlan) ? executionPlan[REFERENCE_BACKGROUND_FIELD3] : void 0
12632
12753
  ),
12633
12754
  planDir: planV2Dir,
12634
- manifestPath: join30(planV2Dir, "plan.json"),
12755
+ manifestPath: join31(planV2Dir, "plan.json"),
12635
12756
  planProtocol: PLAN_PROTOCOL_V2,
12636
12757
  planHash: manifest.planHash,
12637
12758
  sourcePlanV1Hash: getPlanV2ExecutionPlanHash(manifest),
@@ -12767,8 +12888,8 @@ function parsePlanV2Manifest(value) {
12767
12888
  return parsed;
12768
12889
  }
12769
12890
  function readPlanV2Manifest(planV2Dir) {
12770
- const manifestPath = join30(planV2Dir, "plan.json");
12771
- if (!existsSync21(manifestPath)) {
12891
+ const manifestPath = join31(planV2Dir, "plan.json");
12892
+ if (!existsSync22(manifestPath)) {
12772
12893
  throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
12773
12894
  }
12774
12895
  const value = readJsonFile(manifestPath, "v2 manifest");
@@ -12787,7 +12908,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
12787
12908
  }
12788
12909
  function verifyBlob(planV2Dir, artifact) {
12789
12910
  const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
12790
- if (!existsSync21(sourcePath)) {
12911
+ if (!existsSync22(sourcePath)) {
12791
12912
  throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
12792
12913
  }
12793
12914
  const stats = statSync9(sourcePath);
@@ -12800,7 +12921,7 @@ function verifyBlob(planV2Dir, artifact) {
12800
12921
  return sourcePath;
12801
12922
  }
12802
12923
  function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
12803
- if (existsSync21(destinationDir)) {
12924
+ if (existsSync22(destinationDir)) {
12804
12925
  throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
12805
12926
  }
12806
12927
  const manifest = readPlanV2Manifest(planV2Dir);
@@ -12812,17 +12933,17 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
12812
12933
  artifact,
12813
12934
  sourcePath: verifyBlob(planV2Dir, artifact)
12814
12935
  }));
12815
- mkdirSync12(dirname15(destinationDir), { recursive: true });
12816
- const tempDir = createStagingDir6(dirname15(destinationDir), ".plan-v2-materialize-");
12936
+ mkdirSync12(dirname16(destinationDir), { recursive: true });
12937
+ const tempDir = createStagingDir6(dirname16(destinationDir), ".plan-v2-materialize-");
12817
12938
  try {
12818
12939
  for (const { artifact, sourcePath } of verified) {
12819
- const destinationPath = join30(tempDir, ...artifact.path.split("/"));
12820
- mkdirSync12(dirname15(destinationPath), { recursive: true });
12940
+ const destinationPath = join31(tempDir, ...artifact.path.split("/"));
12941
+ mkdirSync12(dirname16(destinationPath), { recursive: true });
12821
12942
  copyFileSync8(sourcePath, destinationPath);
12822
12943
  }
12823
12944
  if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
12824
12945
  writeFileSync10(
12825
- join30(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
12946
+ join31(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
12826
12947
  canonicalJsonStringify({
12827
12948
  manifest,
12828
12949
  target,
@@ -12845,7 +12966,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
12845
12966
  // Join the artifact's OWN name, not the current constant: a plan written
12846
12967
  // before the container change carries the legacy name, and materializing it
12847
12968
  // under the new one would point at a file that was never written.
12848
- audioPath: target.role === "assembler" ? audioArtifact ? join30(destinationDir, audioArtifact.path) : null : null
12969
+ audioPath: target.role === "assembler" ? audioArtifact ? join31(destinationDir, audioArtifact.path) : null : null
12849
12970
  };
12850
12971
  }
12851
12972
  function assertRemoteSources(remoteSources, artifacts) {
@@ -12864,8 +12985,8 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
12864
12985
  return readValidatedPlanV2Materialization(planDir, expectedTarget)?.manifest ?? null;
12865
12986
  }
12866
12987
  function readValidatedPlanV2Materialization(planDir, expectedTarget) {
12867
- const markerPath = join30(planDir, PLAN_V2_MATERIALIZATION_MARKER);
12868
- if (!existsSync21(markerPath)) return null;
12988
+ const markerPath = join31(planDir, PLAN_V2_MATERIALIZATION_MARKER);
12989
+ if (!existsSync22(markerPath)) return null;
12869
12990
  const marker = readJsonFile(markerPath, "materialization marker");
12870
12991
  if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
12871
12992
  throw new PlanV2IntegrityError("malformed materialization marker");
@@ -12882,8 +13003,8 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
12882
13003
  assertRemoteSources(remoteSources, required);
12883
13004
  for (const artifact of required) {
12884
13005
  if (Object.hasOwn(remoteSources, artifact.path)) continue;
12885
- const path = join30(planDir, ...artifact.path.split("/"));
12886
- if (!existsSync21(path) || statSync9(path).size !== artifact.sizeBytes) {
13006
+ const path = join31(planDir, ...artifact.path.split("/"));
13007
+ if (!existsSync22(path) || statSync9(path).size !== artifact.sizeBytes) {
12887
13008
  throw new PlanV2IntegrityError(
12888
13009
  `materialized artifact missing or truncated: ${artifact.path}`
12889
13010
  );
@@ -12898,7 +13019,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
12898
13019
  // src/services/distributed/planV2Execution.ts
12899
13020
  import { mkdtempSync, rmSync as rmSync12 } from "node:fs";
12900
13021
  import { tmpdir as tmpdir2 } from "node:os";
12901
- import { join as join33 } from "node:path";
13022
+ import { join as join34 } from "node:path";
12902
13023
 
12903
13024
  // src/services/distributed/assemble.ts
12904
13025
  import {
@@ -12907,7 +13028,7 @@ import {
12907
13028
  } from "@hyperframes/engine";
12908
13029
  import {
12909
13030
  cpSync as cpSync3,
12910
- existsSync as existsSync22,
13031
+ existsSync as existsSync23,
12911
13032
  mkdirSync as mkdirSync13,
12912
13033
  readFileSync as readFileSync11,
12913
13034
  readdirSync as readdirSync8,
@@ -12915,7 +13036,7 @@ import {
12915
13036
  statSync as statSync10
12916
13037
  } from "node:fs";
12917
13038
  import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
12918
- import { basename as basename6, dirname as dirname16, join as join31 } from "node:path";
13039
+ import { basename as basename6, dirname as dirname17, join as join32 } from "node:path";
12919
13040
  import {
12920
13041
  appendRateCapArgs as appendRateCapArgs2,
12921
13042
  writeVideoConcatList,
@@ -12964,10 +13085,10 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
12964
13085
  }
12965
13086
  const format = plan.dimensions.format;
12966
13087
  const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
12967
- if (!existsSync22(dirname16(outputPath))) {
12968
- mkdirSync13(dirname16(outputPath), { recursive: true });
13088
+ if (!existsSync23(dirname17(outputPath))) {
13089
+ mkdirSync13(dirname17(outputPath), { recursive: true });
12969
13090
  }
12970
- const workDir = createStagingDir7(dirname16(outputPath), `${basename6(outputPath)}.assemble-work-`);
13091
+ const workDir = createStagingDir7(dirname17(outputPath), `${basename6(outputPath)}.assemble-work-`);
12971
13092
  const fps = { num: plan.dimensions.fpsNum, den: plan.dimensions.fpsDen };
12972
13093
  const stageMs = {};
12973
13094
  const ctx = {
@@ -12987,8 +13108,8 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
12987
13108
  };
12988
13109
  try {
12989
13110
  const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
12990
- const finalPath = join31(workDir, `output.${format}`);
12991
- const audio = audioPath !== null && existsSync22(audioPath) ? audioPath : null;
13111
+ const finalPath = join32(workDir, `output.${format}`);
13112
+ const audio = audioPath !== null && existsSync23(audioPath) ? audioPath : null;
12992
13113
  await writeJoined(ctx, videoSources, audio, finalPath);
12993
13114
  renameWithRetry10(finalPath, outputPath);
12994
13115
  log.info("[assemble] stage timings", {
@@ -13006,7 +13127,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
13006
13127
  });
13007
13128
  }
13008
13129
  }
13009
- const fileSize = existsSync22(outputPath) ? statSync10(outputPath).size : 0;
13130
+ const fileSize = existsSync23(outputPath) ? statSync10(outputPath).size : 0;
13010
13131
  return {
13011
13132
  ...referenceBackgroundResult6(plan[REFERENCE_BACKGROUND_FIELD4]),
13012
13133
  outputPath,
@@ -13016,15 +13137,15 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
13016
13137
  };
13017
13138
  }
13018
13139
  function readAssemblePlan(planDir, chunkPaths) {
13019
- const planJsonPath = join31(planDir, "plan.json");
13020
- const chunksJsonPath = join31(planDir, "meta", "chunks.json");
13021
- if (!existsSync22(planJsonPath)) {
13140
+ const planJsonPath = join32(planDir, "plan.json");
13141
+ const chunksJsonPath = join32(planDir, "meta", "chunks.json");
13142
+ if (!existsSync23(planJsonPath)) {
13022
13143
  throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
13023
13144
  }
13024
13145
  const plan = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
13025
13146
  readPlanProtocolV1(plan, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
13026
13147
  validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
13027
- if (!existsSync22(chunksJsonPath)) {
13148
+ if (!existsSync23(chunksJsonPath)) {
13028
13149
  throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
13029
13150
  }
13030
13151
  const chunks = JSON.parse(readFileSync11(chunksJsonPath, "utf-8"));
@@ -13039,7 +13160,7 @@ function readAssemblePlan(planDir, chunkPaths) {
13039
13160
  }
13040
13161
  }
13041
13162
  for (const path of chunkPaths.flat()) {
13042
- if (!existsSync22(path)) {
13163
+ if (!existsSync23(path)) {
13043
13164
  throw new Error(`[assemble] chunk path does not exist: ${path}`);
13044
13165
  }
13045
13166
  }
@@ -13072,7 +13193,7 @@ function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
13072
13193
  return args;
13073
13194
  }
13074
13195
  async function reencodeCfr(ctx, chunkPaths, encoder) {
13075
- const cfrOutputPath = join31(ctx.workDir, `cfr.${ctx.format}`);
13196
+ const cfrOutputPath = join32(ctx.workDir, `cfr.${ctx.format}`);
13076
13197
  const cfrArgs = cfrEncodeArgs(videoInputArgs(ctx, chunkPaths), encoder, ctx.fpsArg);
13077
13198
  appendRenderProvenanceArgs2(cfrArgs, cfrOutputPath);
13078
13199
  cfrArgs.push("-y", cfrOutputPath);
@@ -13099,7 +13220,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
13099
13220
  );
13100
13221
  return;
13101
13222
  }
13102
- const paddedAudioPath = join31(ctx.workDir, "audio-padded.m4a");
13223
+ const paddedAudioPath = join32(ctx.workDir, "audio-padded.m4a");
13103
13224
  const padTrimResult = await ctx.timed(
13104
13225
  "audioMs",
13105
13226
  () => padOrTrimAudioToVideoFrameCount({
@@ -13174,12 +13295,12 @@ function stitchesSeparateAudio(planDir) {
13174
13295
  return lockedAudio(planDir).separateAudio === true;
13175
13296
  }
13176
13297
  function planFormat(planDir) {
13177
- const plan = JSON.parse(readFileSync11(join31(planDir, "plan.json"), "utf-8"));
13298
+ const plan = JSON.parse(readFileSync11(join32(planDir, "plan.json"), "utf-8"));
13178
13299
  return plan.dimensions.format;
13179
13300
  }
13180
13301
  function lockedAudio(planDir) {
13181
- const encoderJsonPath = join31(planDir, "meta", "encoder.json");
13182
- if (!existsSync22(encoderJsonPath)) return {};
13302
+ const encoderJsonPath = join32(planDir, "meta", "encoder.json");
13303
+ if (!existsSync23(encoderJsonPath)) return {};
13183
13304
  return JSON.parse(readFileSync11(encoderJsonPath, "utf-8"));
13184
13305
  }
13185
13306
  function readCfrEncoder(planDir, format) {
@@ -13188,8 +13309,8 @@ function readCfrEncoder(planDir, format) {
13188
13309
  `[assemble] cfr=true is only supported for format="mp4" (got "${format}"). Stream-copy paths for webm and mov already produce exact avg_frame_rate; cfr re-encode is not needed.`
13189
13310
  );
13190
13311
  }
13191
- const encoderJsonPath = join31(planDir, "meta", "encoder.json");
13192
- if (!existsSync22(encoderJsonPath)) {
13312
+ const encoderJsonPath = join32(planDir, "meta", "encoder.json");
13313
+ if (!existsSync23(encoderJsonPath)) {
13193
13314
  throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
13194
13315
  }
13195
13316
  const encoderJson = JSON.parse(readFileSync11(encoderJsonPath, "utf-8"));
@@ -13201,7 +13322,7 @@ function readCfrEncoder(planDir, format) {
13201
13322
  return encoderJson;
13202
13323
  }
13203
13324
  function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
13204
- if (existsSync22(outputPath)) rmSync10(outputPath, { recursive: true, force: true });
13325
+ if (existsSync23(outputPath)) rmSync10(outputPath, { recursive: true, force: true });
13205
13326
  mkdirSync13(outputPath, { recursive: true });
13206
13327
  let globalIdx = 0;
13207
13328
  for (const chunkDir of chunkPaths) {
@@ -13215,8 +13336,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
13215
13336
  throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
13216
13337
  }
13217
13338
  for (const frame of frames) {
13218
- const dst = join31(outputPath, formatExportFrameName(globalIdx, "png"));
13219
- cpSync3(join31(chunkDir, frame), dst);
13339
+ const dst = join32(outputPath, formatExportFrameName(globalIdx, "png"));
13340
+ cpSync3(join32(chunkDir, frame), dst);
13220
13341
  globalIdx += 1;
13221
13342
  }
13222
13343
  }
@@ -13225,14 +13346,14 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
13225
13346
  `[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
13226
13347
  );
13227
13348
  }
13228
- if (audioPath !== null && existsSync22(audioPath)) {
13229
- const sidecar = join31(outputPath, MIXED_AUDIO_FILENAME4);
13349
+ if (audioPath !== null && existsSync23(audioPath)) {
13350
+ const sidecar = join32(outputPath, MIXED_AUDIO_FILENAME4);
13230
13351
  cpSync3(audioPath, sidecar);
13231
13352
  }
13232
13353
  let fileSize = 0;
13233
13354
  for (const name of readdirSync8(outputPath)) {
13234
13355
  try {
13235
- fileSize += statSync10(join31(outputPath, name)).size;
13356
+ fileSize += statSync10(join32(outputPath, name)).size;
13236
13357
  } catch {
13237
13358
  }
13238
13359
  }
@@ -13246,8 +13367,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
13246
13367
 
13247
13368
  // src/services/distributed/renderChunk.ts
13248
13369
  import { randomBytes } from "node:crypto";
13249
- import { existsSync as existsSync23, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync11 } from "node:fs";
13250
- import { join as join32 } from "node:path";
13370
+ import { existsSync as existsSync24, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync11 } from "node:fs";
13371
+ import { join as join33 } from "node:path";
13251
13372
  import {
13252
13373
  assertSwiftShader,
13253
13374
  BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
@@ -13383,7 +13504,7 @@ function hashChunkOutput(outputPath, kind) {
13383
13504
  if (kind === "file") return sha256Hex(readFileSync12(outputPath));
13384
13505
  const entries = readdirSync9(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
13385
13506
  const lines = entries.map(
13386
- (name) => `${name}\0${sha256Hex(readFileSync12(join32(outputPath, name)))}`
13507
+ (name) => `${name}\0${sha256Hex(readFileSync12(join33(outputPath, name)))}`
13387
13508
  );
13388
13509
  return sha256Hex(lines.join("\0"));
13389
13510
  }
@@ -13400,10 +13521,10 @@ function resolveLockedVp9CpuUsed(lockedEncoder) {
13400
13521
  async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13401
13522
  const start = Date.now();
13402
13523
  const log = defaultLogger;
13403
- const planJsonPath = join32(planDir, "plan.json");
13404
- const encoderJsonPath = join32(planDir, "meta", "encoder.json");
13405
- const chunksJsonPath = join32(planDir, "meta", "chunks.json");
13406
- if (!existsSync23(planJsonPath)) {
13524
+ const planJsonPath = join33(planDir, "plan.json");
13525
+ const encoderJsonPath = join33(planDir, "meta", "encoder.json");
13526
+ const chunksJsonPath = join33(planDir, "meta", "chunks.json");
13527
+ if (!existsSync24(planJsonPath)) {
13407
13528
  throw new RenderChunkValidationError(
13408
13529
  MISSING_PLAN_ARTIFACT,
13409
13530
  `[renderChunk] planDir is missing required artifact: ${planJsonPath}`
@@ -13419,7 +13540,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13419
13540
  const v2Manifest = v2Materialization?.manifest ?? null;
13420
13541
  const remoteSources = v2Materialization?.remoteSources ?? {};
13421
13542
  for (const required of [encoderJsonPath, chunksJsonPath]) {
13422
- if (!existsSync23(required)) {
13543
+ if (!existsSync24(required)) {
13423
13544
  throw new RenderChunkValidationError(
13424
13545
  MISSING_PLAN_ARTIFACT,
13425
13546
  `[renderChunk] planDir is missing required artifact: ${required}`
@@ -13428,9 +13549,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13428
13549
  }
13429
13550
  const encoder = JSON.parse(readFileSync12(encoderJsonPath, "utf-8"));
13430
13551
  const chunks = JSON.parse(readFileSync12(chunksJsonPath, "utf-8"));
13431
- const videosJsonPath = join32(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
13552
+ const videosJsonPath = join33(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
13432
13553
  let planVideos = null;
13433
- if (existsSync23(videosJsonPath)) {
13554
+ if (existsSync24(videosJsonPath)) {
13434
13555
  try {
13435
13556
  planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync12(videosJsonPath, "utf-8")));
13436
13557
  } catch (err) {
@@ -13460,8 +13581,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13460
13581
  }
13461
13582
  const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
13462
13583
  const framesInChunk = range.endFrame - range.startFrame;
13463
- const compiledDir = join32(planDir, "compiled");
13464
- if (!existsSync23(compiledDir)) {
13584
+ const compiledDir = join33(planDir, "compiled");
13585
+ if (!existsSync24(compiledDir)) {
13465
13586
  throw new RenderChunkValidationError(
13466
13587
  MISSING_PLAN_ARTIFACT,
13467
13588
  `[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
@@ -13519,7 +13640,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13519
13640
  };
13520
13641
  const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
13521
13642
  mkdirSync14(workDir, { recursive: true });
13522
- const framesDir = join32(workDir, "captured-frames");
13643
+ const framesDir = join33(workDir, "captured-frames");
13523
13644
  mkdirSync14(framesDir, { recursive: true });
13524
13645
  const videoFramesDir = `${workDir}.video-frames`;
13525
13646
  const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
@@ -13544,7 +13665,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13544
13665
  dimensions: plan.dimensions,
13545
13666
  encoder,
13546
13667
  videoCount: planVideos?.videos.length ?? 0,
13547
- html: readFileSync12(join32(compiledDir, "index.html"), "utf-8"),
13668
+ html: readFileSync12(join33(compiledDir, "index.html"), "utf-8"),
13548
13669
  // The plan ships a deferred source only to chunks that show it; don't wait on the rest.
13549
13670
  skipReadinessVideoIds: deferredVideos.filter(
13550
13671
  (video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
@@ -13553,7 +13674,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13553
13674
  deferredVideos.filter((video) => remoteVideoIds.has(video.videoId))
13554
13675
  )
13555
13676
  });
13556
- captureOptions.onStaticDedupActivity = () => noteStaticDedupActivity(job);
13677
+ captureOptions.onStaticDedupActivity = () => noteCaptureActivity(job);
13557
13678
  const captureFrames = effectiveChunkFrames(framesInChunk, slice.captureCost);
13558
13679
  const chunkWorkerCount = resolveChunkCaptureWorkers(
13559
13680
  captureFrames,
@@ -13670,7 +13791,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13670
13791
  outputRoot: videoFramesDir,
13671
13792
  cfg,
13672
13793
  remoteSources,
13673
- shownBoxes
13794
+ shownBoxes,
13795
+ onProgress: () => noteCaptureActivity(job)
13674
13796
  }).then((frames) => {
13675
13797
  videoExtractMs = Date.now() - extractStarted;
13676
13798
  return frames;
@@ -13713,10 +13835,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13713
13835
  const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
13714
13836
  const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
13715
13837
  if (isPngSequence) {
13716
- if (!existsSync23(outputChunkPath)) mkdirSync14(outputChunkPath, { recursive: true });
13838
+ if (!existsSync24(outputChunkPath)) mkdirSync14(outputChunkPath, { recursive: true });
13717
13839
  } else {
13718
- const outDir = join32(outputChunkPath, "..");
13719
- if (!existsSync23(outDir)) mkdirSync14(outDir, { recursive: true });
13840
+ const outDir = join33(outputChunkPath, "..");
13841
+ if (!existsSync24(outDir)) mkdirSync14(outDir, { recursive: true });
13720
13842
  }
13721
13843
  const encodeInput = {
13722
13844
  job,
@@ -13962,8 +14084,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13962
14084
 
13963
14085
  // src/services/distributed/planV2Execution.ts
13964
14086
  async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
13965
- const workRoot = mkdtempSync(join33(tmpdir2(), "hf-plan-v2-chunk-"));
13966
- const materializedPlanDir = join33(workRoot, "plan");
14087
+ const workRoot = mkdtempSync(join34(tmpdir2(), "hf-plan-v2-chunk-"));
14088
+ const materializedPlanDir = join34(workRoot, "plan");
13967
14089
  try {
13968
14090
  materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
13969
14091
  return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
@@ -13972,8 +14094,8 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
13972
14094
  }
13973
14095
  }
13974
14096
  async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
13975
- const workRoot = mkdtempSync(join33(tmpdir2(), "hf-plan-v2-assembler-"));
13976
- const materializedPlanDir = join33(workRoot, "plan");
14097
+ const workRoot = mkdtempSync(join34(tmpdir2(), "hf-plan-v2-assembler-"));
14098
+ const materializedPlanDir = join34(workRoot, "plan");
13977
14099
  try {
13978
14100
  const materialized = materializePlanV2Target(
13979
14101
  planV2Dir,
@@ -14295,7 +14417,7 @@ function validateIntDimension(field, value) {
14295
14417
  // src/services/distributed/projectHash.ts
14296
14418
  import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync11 } from "node:fs";
14297
14419
  import { createHash as createHash9 } from "node:crypto";
14298
- import { join as join34, sep as sep6 } from "node:path";
14420
+ import { join as join35, sep as sep6 } from "node:path";
14299
14421
  import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
14300
14422
  var SITE_ID_SCHEME = "site-v2\0";
14301
14423
  var READ_CHUNK_BYTES = 256 * 1024;
@@ -14329,7 +14451,7 @@ function listSiteFiles(projectDir, onPrivate, onOutside = () => {
14329
14451
  function walk(dir, rel) {
14330
14452
  for (const name of readdirSync10(dir).sort()) {
14331
14453
  if (rel === "" && PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(name)) continue;
14332
- visit(join34(dir, name), rel === "" ? name : `${rel}/${name}`);
14454
+ visit(join35(dir, name), rel === "" ? name : `${rel}/${name}`);
14333
14455
  }
14334
14456
  }
14335
14457
  walk(projectDir, "");
@@ -14368,7 +14490,7 @@ function hashProjectDir(projectDir, files = listSiteFiles(projectDir)) {
14368
14490
  for (const rel of files) {
14369
14491
  hash.update(rel);
14370
14492
  hash.update("\0");
14371
- const fd = openSync5(join34(projectDir, rel), "r");
14493
+ const fd = openSync5(join35(projectDir, rel), "r");
14372
14494
  try {
14373
14495
  let read2;
14374
14496
  while ((read2 = readSync4(fd, chunk, 0, chunk.length, null)) > 0) {