@hyperframes/producer 0.9.68 → 0.9.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,12 +9,12 @@ import {
9
9
  // src/services/renderOrchestrator.ts
10
10
  import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
11
11
  import {
12
- existsSync as existsSync22,
12
+ existsSync as existsSync21,
13
13
  mkdirSync as mkdirSync12,
14
14
  readdirSync as readdirSync6,
15
15
  rmSync as rmSync12,
16
16
  statSync as statSync10,
17
- writeFileSync as writeFileSync7,
17
+ writeFileSync as writeFileSync6,
18
18
  copyFileSync as copyFileSync5,
19
19
  appendFileSync
20
20
  } from "fs";
@@ -2593,7 +2593,7 @@ function replanAfterFailure(plan2, failure) {
2593
2593
  }
2594
2594
 
2595
2595
  // src/services/render/stages/captureSegmentedStage.ts
2596
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
2596
+ import { existsSync as existsSync7, mkdirSync as mkdirSync4, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
2597
2597
  import { join as join12 } from "node:path";
2598
2598
  import {
2599
2599
  captureFrameToBuffer as captureFrameToBuffer2,
@@ -4325,16 +4325,25 @@ function createSegmentQueue(slices) {
4325
4325
  // src/services/render/segmentManifest.ts
4326
4326
  import { createHash as createHash2, createHmac, timingSafeEqual } from "node:crypto";
4327
4327
  import {
4328
+ closeSync as closeSync4,
4329
+ constants as constants3,
4328
4330
  createReadStream as createReadStream2,
4329
- existsSync as existsSync7,
4331
+ fstatSync as fstatSync3,
4330
4332
  lstatSync as lstatSync3,
4331
4333
  mkdirSync as mkdirSync3,
4332
- readFileSync as readFileSync4,
4333
- writeFileSync as writeFileSync3
4334
+ openSync as openSync4,
4335
+ readFileSync as readFileSync4
4334
4336
  } from "node:fs";
4335
4337
  import { join as join10 } from "node:path";
4338
+ import {
4339
+ assertPrivateCachePath,
4340
+ ensurePrivateCacheDir,
4341
+ hyperframesCacheDir
4342
+ } from "@hyperframes/core/cache-dir";
4343
+ import { isSafePath as isSafePath2, realpath } from "@hyperframes/core/safe-path";
4344
+ import { isPathInside as isPathInside3 } from "@hyperframes/parsers/asset-paths";
4336
4345
  import { previewToken } from "@hyperframes/core/preview-proof";
4337
- import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
4346
+ import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
4338
4347
  var MANIFEST_FILENAME = "segments.json";
4339
4348
  function computeSegmentPlanHash(input) {
4340
4349
  const ordered = [
@@ -4360,8 +4369,20 @@ function computeSegmentPlanHash(input) {
4360
4369
  if (delivery.some((v) => v !== "")) ordered.push(...delivery.map(String));
4361
4370
  return createHash2("sha256").update(ordered.join(" ")).digest("hex").slice(0, 16);
4362
4371
  }
4363
- function segmentDirFor(projectRendersDir, planHash) {
4364
- return join10(projectRendersDir, ".hf-segments", planHash);
4372
+ function segmentDirFor(projectDir, planHash) {
4373
+ const root = hyperframesCacheDir();
4374
+ const projectKey = createHash2("sha256").update(realpath(projectDir)).digest("hex");
4375
+ const parent = join10(root, "segments", projectKey);
4376
+ const dir = join10(parent, planHash);
4377
+ if (isPathInside3(root, projectDir) || isSafePath2(projectDir, root) || isSafePath2(projectDir, parent) || isSafePath2(projectDir, dir)) {
4378
+ throw new Error("Segmented capture requires HYPERFRAMES_CACHE_DIR outside the project.");
4379
+ }
4380
+ assertPrivateCachePath(root, root);
4381
+ ensurePrivateCacheDir(parent, root);
4382
+ if (!isSafePath2(parent, dir) || lstatSync3(dir, { throwIfNoEntry: false })?.isSymbolicLink()) {
4383
+ throw new Error("Invalid segment cache directory");
4384
+ }
4385
+ return dir;
4365
4386
  }
4366
4387
  function hasNumber(value, key) {
4367
4388
  return key in value && typeof Reflect.get(value, key) === "number";
@@ -4380,12 +4401,22 @@ function isManifest(value) {
4380
4401
  }
4381
4402
  function readSegmentManifest(segmentDir) {
4382
4403
  const path = join10(segmentDir, MANIFEST_FILENAME);
4383
- if (!existsSync7(path)) return null;
4404
+ let fd;
4384
4405
  try {
4385
- const parsed = JSON.parse(readFileSync4(path, "utf-8"));
4406
+ fd = openSync4(
4407
+ path,
4408
+ constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0)
4409
+ );
4410
+ const opened = fstatSync3(fd);
4411
+ if (!opened.isFile() || opened.nlink !== 1) return null;
4412
+ const named = lstatSync3(path);
4413
+ if (!named.isFile() || named.dev !== opened.dev || named.ino !== opened.ino) return null;
4414
+ const parsed = JSON.parse(readFileSync4(fd, "utf-8"));
4386
4415
  return isManifest(parsed) ? parsed : null;
4387
4416
  } catch {
4388
4417
  return null;
4418
+ } finally {
4419
+ if (fd !== void 0) closeSync4(fd);
4389
4420
  }
4390
4421
  }
4391
4422
  function segmentManifestKey(token = previewToken()) {
@@ -4418,9 +4449,11 @@ async function hashSegmentFile(path) {
4418
4449
  }
4419
4450
  function writeSegmentManifest(segmentDir, manifest, key) {
4420
4451
  mkdirSync3(segmentDir, { recursive: true });
4421
- const tmp = join10(segmentDir, `${MANIFEST_FILENAME}.${process.pid}.tmp`);
4422
- writeFileSync3(tmp, JSON.stringify(signSegmentManifest(manifest, key), null, 2), "utf-8");
4423
- renameWithRetry2(tmp, join10(segmentDir, MANIFEST_FILENAME));
4452
+ replaceFileAtomically(
4453
+ join10(segmentDir, MANIFEST_FILENAME),
4454
+ JSON.stringify(signSegmentManifest(manifest, key), null, 2),
4455
+ 384
4456
+ );
4424
4457
  }
4425
4458
  async function probeSegmentFrameCount(path, probe) {
4426
4459
  try {
@@ -4440,19 +4473,27 @@ function plannedSlice(entry, plan2) {
4440
4473
  }
4441
4474
  return slice;
4442
4475
  }
4443
- function isPlainFileOfSize(path, bytes) {
4444
- const stat = lstatSync3(path, { throwIfNoEntry: false });
4445
- return stat !== void 0 && stat.isFile() && stat.size > 0 && stat.size === bytes;
4476
+ async function matchesSegmentFile(path, entry) {
4477
+ try {
4478
+ const stat = lstatSync3(path, { throwIfNoEntry: false });
4479
+ if (!stat?.isFile() || stat.nlink !== 1 || stat.size <= 0 || stat.size !== entry.bytes) {
4480
+ return false;
4481
+ }
4482
+ return await hashSegmentFile(path) === entry.sha256;
4483
+ } catch {
4484
+ return false;
4485
+ }
4446
4486
  }
4447
4487
  async function validateCompletedSegments(manifest, check) {
4448
4488
  const ok = /* @__PURE__ */ new Set();
4449
- if (manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key)) return ok;
4489
+ if (manifest.totalFrames !== check.totalFrames || manifest.segmentFrames !== check.segmentFrames || manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key))
4490
+ return ok;
4491
+ const plan2 = planSegments(check.totalFrames, check.segmentFrames);
4450
4492
  for (const entry of manifest.completed) {
4451
- const slice = plannedSlice(entry, check.plan);
4493
+ const slice = plannedSlice(entry, plan2);
4452
4494
  if (!slice) continue;
4453
4495
  const path = segmentOutputPath(check.segmentDir, slice.index);
4454
- if (!isPlainFileOfSize(path, entry.bytes)) continue;
4455
- if (await hashSegmentFile(path) !== entry.sha256) continue;
4496
+ if (entry.path !== path || !await matchesSegmentFile(path, entry)) continue;
4456
4497
  const frames = await check.probeFrames(path);
4457
4498
  if (frames !== slice.endFrame - slice.startFrame) continue;
4458
4499
  ok.add(slice.index);
@@ -5343,6 +5384,7 @@ async function captureSegment(ctx, segment) {
5343
5384
  }
5344
5385
  async function captureSegmentToEncoder(ctx, segment) {
5345
5386
  const segmentPath = segmentOutputPath(ctx.segmentDir, segment.index);
5387
+ rmSync6(segmentPath, { force: true });
5346
5388
  let encoder;
5347
5389
  try {
5348
5390
  encoder = await ctx.spawnEncoder(
@@ -5371,8 +5413,8 @@ async function captureSegmentToEncoder(ctx, segment) {
5371
5413
  path: segmentPath,
5372
5414
  // Recorded so resume can prove the file on disk is the one that
5373
5415
  // finished; absent only in unit tests, whose fake encoder writes none.
5374
- bytes: existsSync8(segmentPath) ? statSync4(segmentPath).size : 0,
5375
- sha256: existsSync8(segmentPath) ? await hashSegmentFile(segmentPath) : ""
5416
+ bytes: existsSync7(segmentPath) ? statSync4(segmentPath).size : 0,
5417
+ sha256: existsSync7(segmentPath) ? await hashSegmentFile(segmentPath) : ""
5376
5418
  });
5377
5419
  return encodeResult;
5378
5420
  } finally {
@@ -7051,7 +7093,7 @@ function requireOutputDimensions(expected, width, height) {
7051
7093
  }
7052
7094
 
7053
7095
  // src/services/render/stages/compileStage.ts
7054
- import { existsSync as existsSync13, writeFileSync as writeFileSync5 } from "node:fs";
7096
+ import { existsSync as existsSync12, writeFileSync as writeFileSync4 } from "node:fs";
7055
7097
  import { join as join22, relative as relative4 } from "node:path";
7056
7098
  import { privateCacheRoot } from "@hyperframes/engine";
7057
7099
  import { suggestMatchingPreset } from "@hyperframes/core";
@@ -7063,7 +7105,7 @@ import { statSync as statSync6 } from "node:fs";
7063
7105
  var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
7064
7106
  var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
7065
7107
  var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
7066
- var MAX_EXPANDED_COMPOSITION_BYTES = 2 * MAX_COMPOSITION_HTML_BYTES;
7108
+ var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
7067
7109
  var MAX_COMPOSITION_MOUNTS = 1e4;
7068
7110
  var CompositionTooLargeError = class extends Error {
7069
7111
  constructor(message, publicMetadata) {
@@ -7160,12 +7202,12 @@ import {
7160
7202
  stylesheetLinkMatches
7161
7203
  } from "@hyperframes/parsers/css-url-scans";
7162
7204
  import { createHash as createHash6 } from "node:crypto";
7163
- import { createReadStream as createReadStream3, existsSync as existsSync12, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
7205
+ import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
7164
7206
  import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
7165
7207
  import { parseHTML as parseHTML5 } from "linkedom";
7166
7208
 
7167
7209
  // src/services/bundledScripts.ts
7168
- import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
7210
+ import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
7169
7211
  import { join as join17 } from "node:path";
7170
7212
  import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
7171
7213
  var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
@@ -7173,7 +7215,7 @@ function bundledScript(url) {
7173
7215
  const dir = process.env[GSAP_VENDOR_DIR_ENV];
7174
7216
  if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
7175
7217
  const file = join17(dir, "gsap.min.js");
7176
- return existsSync9(file) ? readFileSync5(file) : null;
7218
+ return existsSync8(file) ? readFileSync5(file) : null;
7177
7219
  }
7178
7220
 
7179
7221
  // src/services/htmlCompiler.ts
@@ -7431,7 +7473,7 @@ import {
7431
7473
 
7432
7474
  // src/services/animatedGifPrep.ts
7433
7475
  import { createHash as createHash4 } from "node:crypto";
7434
- import { copyFileSync as copyFileSync2, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
7476
+ import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
7435
7477
  import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
7436
7478
  import { parseHTML as parseHTML3 } from "linkedom";
7437
7479
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
@@ -7439,7 +7481,7 @@ import {
7439
7481
  DEFAULT_VP9_CPU_USED,
7440
7482
  isPrivateUnderAssetRoots,
7441
7483
  runFfmpeg as runFfmpeg2,
7442
- renameWithRetry as renameWithRetry3,
7484
+ renameWithRetry as renameWithRetry2,
7443
7485
  urlInputArgs as urlInputArgs2
7444
7486
  } from "@hyperframes/engine";
7445
7487
  import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
@@ -7477,7 +7519,7 @@ function resolveLocalImageSourcePath(src, options) {
7477
7519
  const { basePath } = splitUrlSuffix(trimmed);
7478
7520
  const normalizedBase = normalizeRelPath(basePath);
7479
7521
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
7480
- if (mapped && existsSync10(mapped)) return mapped;
7522
+ if (mapped && existsSync9(mapped)) return mapped;
7481
7523
  if (isHttpUrl(trimmed)) return null;
7482
7524
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
7483
7525
  const candidates = [
@@ -7486,7 +7528,7 @@ function resolveLocalImageSourcePath(src, options) {
7486
7528
  ];
7487
7529
  const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
7488
7530
  const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7489
- return candidates.find((candidate) => allowed(candidate) && existsSync10(candidate)) ?? null;
7531
+ return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
7490
7532
  }
7491
7533
  function isUsableFile(path) {
7492
7534
  try {
@@ -7598,10 +7640,10 @@ async function runAnimatedGifTranscode(request) {
7598
7640
  throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
7599
7641
  }
7600
7642
  async function ensurePreparedWebm(input) {
7601
- if (!existsSync10(dirname6(input.cachePath))) {
7643
+ if (!existsSync9(dirname6(input.cachePath))) {
7602
7644
  mkdirSync7(dirname6(input.cachePath), { recursive: true });
7603
7645
  }
7604
- if (!existsSync10(dirname6(input.outputPath))) {
7646
+ if (!existsSync9(dirname6(input.outputPath))) {
7605
7647
  mkdirSync7(dirname6(input.outputPath), { recursive: true });
7606
7648
  }
7607
7649
  if (!isUsableFile(input.cachePath)) {
@@ -7624,7 +7666,7 @@ async function ensurePreparedWebm(input) {
7624
7666
  throw new Error("Animated GIF transcode produced an empty output");
7625
7667
  }
7626
7668
  if (!isUsableFile(input.cachePath)) {
7627
- renameWithRetry3(tmpPath, input.cachePath);
7669
+ renameWithRetry2(tmpPath, input.cachePath);
7628
7670
  } else {
7629
7671
  rmSync9(tmpPath, { force: true });
7630
7672
  }
@@ -7748,19 +7790,19 @@ async function prepareAnimatedGifInputs(html, options) {
7748
7790
  // src/services/heifImagePrep.ts
7749
7791
  import { createHash as createHash5 } from "node:crypto";
7750
7792
  import {
7751
- closeSync as closeSync4,
7793
+ closeSync as closeSync5,
7752
7794
  copyFileSync as copyFileSync3,
7753
7795
  mkdirSync as mkdirSync8,
7754
- openSync as openSync4,
7796
+ openSync as openSync5,
7755
7797
  readFileSync as readFileSync7,
7756
7798
  readSync as readSync3,
7757
7799
  rmSync as rmSync10,
7758
7800
  statSync as statSync8,
7759
- writeFileSync as writeFileSync4
7801
+ writeFileSync as writeFileSync3
7760
7802
  } from "node:fs";
7761
7803
  import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
7762
7804
  import { parseHTML as parseHTML4 } from "linkedom";
7763
- import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
7805
+ import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
7764
7806
 
7765
7807
  // src/services/heifRotation.ts
7766
7808
  function* boxes(buf, start, end) {
@@ -7907,13 +7949,13 @@ function isHeifBytes(head) {
7907
7949
  function readHead(path) {
7908
7950
  let fd;
7909
7951
  try {
7910
- fd = openSync4(path, "r");
7952
+ fd = openSync5(path, "r");
7911
7953
  const buf = Buffer.alloc(4096);
7912
7954
  return buf.subarray(0, readSync3(fd, buf, 0, buf.length, 0));
7913
7955
  } catch {
7914
7956
  return null;
7915
7957
  } finally {
7916
- if (fd !== void 0) closeSync4(fd);
7958
+ if (fd !== void 0) closeSync5(fd);
7917
7959
  }
7918
7960
  }
7919
7961
  async function probeJson(path, withGroups) {
@@ -8012,14 +8054,14 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
8012
8054
  const inlinePath = `${tmpPath}.heic`;
8013
8055
  const inputPath = source.path ?? inlinePath;
8014
8056
  try {
8015
- if (!source.path) writeFileSync4(inlinePath, source.bytes);
8057
+ if (!source.path) writeFileSync3(inlinePath, source.bytes);
8016
8058
  await (options.transcode ?? convertHeifToJpeg)({
8017
8059
  inputPath,
8018
8060
  outputPath: tmpPath,
8019
8061
  timeoutMs: options.timeoutMs
8020
8062
  });
8021
8063
  if (!isUsableFile2(tmpPath)) throw new Error("conversion produced an empty file");
8022
- renameWithRetry4(tmpPath, cachePath);
8064
+ renameWithRetry3(tmpPath, cachePath);
8023
8065
  } catch (error) {
8024
8066
  const reason = error instanceof Error ? error.message : String(error);
8025
8067
  throw TOOL_FAILURE_RE.test(reason) ? new HeifToolUnavailableError(source.label, reason) : new HeifImageConversionError(source.label, reason);
@@ -8073,11 +8115,14 @@ async function prepareHeifImageInputs(html, options) {
8073
8115
  }
8074
8116
 
8075
8117
  // src/services/htmlCompiler.ts
8076
- import { createStudioPositionSeekReapplyScript } from "@hyperframes/studio-server/manual-edits-render-script";
8118
+ import {
8119
+ createStudioPositionSeekReapplyScript,
8120
+ htmlHasStudioPositionEdits
8121
+ } from "@hyperframes/studio-server/manual-edits-render-script";
8077
8122
  import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
8078
8123
 
8079
8124
  // src/services/assetMediaType.ts
8080
- import { existsSync as existsSync11 } from "node:fs";
8125
+ import { existsSync as existsSync10 } from "node:fs";
8081
8126
  import { dirname as dirname8, join as join20 } from "node:path";
8082
8127
  import {
8083
8128
  fingerprintElementId,
@@ -8190,7 +8235,7 @@ async function preflightCompositionAssetMediaTypes(input) {
8190
8235
  input.projectDir,
8191
8236
  input.compiledDir
8192
8237
  );
8193
- if (!existsSync11(resolvedPath)) continue;
8238
+ if (!existsSync10(resolvedPath)) continue;
8194
8239
  byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
8195
8240
  }
8196
8241
  const mismatches = [];
@@ -8487,7 +8532,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
8487
8532
  let filePath = src;
8488
8533
  if (isHttpUrl(src)) {
8489
8534
  const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
8490
- if (!existsSync12(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
8535
+ if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
8491
8536
  try {
8492
8537
  filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
8493
8538
  onTelemetry: logRemoteDownloadTelemetry
@@ -8506,7 +8551,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
8506
8551
  return { duration: null, resolvedPath: filePath };
8507
8552
  }
8508
8553
  }
8509
- if (!isHttpUrl(filePath) && !existsSync12(filePath)) {
8554
+ if (!isHttpUrl(filePath) && !existsSync11(filePath)) {
8510
8555
  return { duration: null, resolvedPath: filePath };
8511
8556
  }
8512
8557
  const withSrcContext = (error) => {
@@ -9138,7 +9183,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
9138
9183
  return null;
9139
9184
  }
9140
9185
  const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
9141
- if (!onShare && !existsSync12(absPath)) return null;
9186
+ if (!onShare && !existsSync11(absPath)) return null;
9142
9187
  const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
9143
9188
  if (refusal) {
9144
9189
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
@@ -9191,7 +9236,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
9191
9236
  var REMOTE_MEDIA_SUBDIR = "_remote_media";
9192
9237
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
9193
9238
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
9194
- if (!existsSync12(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
9239
+ if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
9195
9240
  const urlToLocal = /* @__PURE__ */ new Map();
9196
9241
  await Promise.all(
9197
9242
  [...urlSet].map(async (url) => {
@@ -9377,13 +9422,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
9377
9422
  const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
9378
9423
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
9379
9424
  const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
9380
- if (!isPathInside(sheet, projectDir) || !existsSync12(sheet)) continue;
9425
+ if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
9381
9426
  for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
9382
9427
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
9383
9428
  const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
9384
9429
  const path = decodedUrlPath(url);
9385
9430
  const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname9(sheet), path);
9386
- return isPathInside(file, projectDir) && existsSync12(file);
9431
+ return isPathInside(file, projectDir) && existsSync11(file);
9387
9432
  });
9388
9433
  if (family && shipsFile) families.push(family);
9389
9434
  }
@@ -9535,7 +9580,7 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
9535
9580
  let gsapDist;
9536
9581
  const exists = (path) => {
9537
9582
  const file = resolve8(projectDir, path);
9538
- return !namesAnotherNetworkRoot2(projectDir, file) && existsSync12(file);
9583
+ return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
9539
9584
  };
9540
9585
  return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
9541
9586
  if (/^https?:\/\//i.test(src)) return full;
@@ -9686,14 +9731,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9686
9731
  abortSignal: options.abortSignal
9687
9732
  });
9688
9733
  const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
9689
- const HF_POSITION_ATTRS = [
9690
- 'data-hf-studio-path-offset="true"',
9691
- 'data-hf-studio-box-size="true"',
9692
- 'data-hf-studio-rotation="true"',
9693
- 'data-hf-studio-motion="'
9694
- ];
9695
- const hasPositionEdits = HF_POSITION_ATTRS.some((attr) => assembledHtml.includes(attr));
9696
- const htmlWithPositionScript = hasPositionEdits ? insertBeforeCloseTag(
9734
+ const htmlWithPositionScript = htmlHasStudioPositionEdits(assembledHtml) ? insertBeforeCloseTag(
9697
9735
  assembledHtml,
9698
9736
  "body",
9699
9737
  `<script>${createStudioPositionSeekReapplyScript()}
@@ -9778,7 +9816,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9778
9816
  for (const video of videos) {
9779
9817
  if (isHttpUrl(video.src)) continue;
9780
9818
  const videoPath = resolve8(projectDir, video.src);
9781
- if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync12(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
9819
+ if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
9782
9820
  continue;
9783
9821
  advised.add(videoPath);
9784
9822
  const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
@@ -10225,7 +10263,7 @@ function resolveEntryHtmlPath(input) {
10225
10263
  const rawEntry = readEntry(htmlPath);
10226
10264
  if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
10227
10265
  const projectIndexPath = join22(projectDir, "index.html");
10228
- if (!existsSync13(projectIndexPath)) {
10266
+ if (!existsSync12(projectIndexPath)) {
10229
10267
  throw new Error(
10230
10268
  `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
10231
10269
  );
@@ -10241,7 +10279,7 @@ function resolveEntryHtmlPath(input) {
10241
10279
  );
10242
10280
  }
10243
10281
  const wrapperPath = join22(workDir, "standalone-entry.html");
10244
- writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
10282
+ writeFileSync4(wrapperPath, standaloneHtml, "utf-8");
10245
10283
  log.info("Extracted standalone entry from index.html host context", { entryFile });
10246
10284
  return wrapperPath;
10247
10285
  }
@@ -11234,7 +11272,7 @@ function validateDistributedDuration(input) {
11234
11272
  }
11235
11273
 
11236
11274
  // src/services/render/stages/extractVideosStage.ts
11237
- import { existsSync as existsSync14 } from "node:fs";
11275
+ import { existsSync as existsSync13 } from "node:fs";
11238
11276
  import { join as join24 } from "node:path";
11239
11277
  import {
11240
11278
  classifyVideoExtractionError,
@@ -11687,7 +11725,7 @@ function isPublicHttpsUrl(url) {
11687
11725
  }
11688
11726
  }
11689
11727
  function opensLocally(path, assetRoots) {
11690
- return existsSync14(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
11728
+ return existsSync13(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
11691
11729
  }
11692
11730
  function localProbeSource(src, input) {
11693
11731
  const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
@@ -11740,7 +11778,7 @@ async function appendVideoAudioFromProbe(input) {
11740
11778
  }
11741
11779
 
11742
11780
  // src/services/render/videoLayerPassthroughPlan.ts
11743
- import { existsSync as existsSync15 } from "node:fs";
11781
+ import { existsSync as existsSync14 } from "node:fs";
11744
11782
  import {
11745
11783
  buildVideoLayerInput,
11746
11784
  isHttpUrl as isHttpUrl4,
@@ -11808,7 +11846,7 @@ async function planVideoLayerPassthrough(input) {
11808
11846
  const { video } = q;
11809
11847
  if (isHttpUrl4(video.src)) return { reason: "remote_source" };
11810
11848
  const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
11811
- if (!existsSync15(path)) return { reason: "source_missing" };
11849
+ if (!existsSync14(path)) return { reason: "source_missing" };
11812
11850
  const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
11813
11851
  if ("reason" in layout) return layout;
11814
11852
  const layer = await buildVideoLayerInput(
@@ -11823,7 +11861,7 @@ async function planVideoLayerPassthrough(input) {
11823
11861
  }
11824
11862
 
11825
11863
  // src/services/render/stages/audioStage.ts
11826
- import { existsSync as existsSync17 } from "node:fs";
11864
+ import { existsSync as existsSync16 } from "node:fs";
11827
11865
  import { join as join27 } from "node:path";
11828
11866
  import {
11829
11867
  MIXED_AUDIO_FILENAME,
@@ -11835,16 +11873,17 @@ import {
11835
11873
  } from "@hyperframes/engine";
11836
11874
 
11837
11875
  // src/services/render/audioDeliveryLimit.ts
11838
- import { existsSync as existsSync16 } from "node:fs";
11876
+ import { existsSync as existsSync15 } from "node:fs";
11839
11877
  import { dirname as dirname11, join as join26 } from "node:path";
11840
11878
  import {
11841
11879
  applyAudioFxChain,
11842
11880
  describeFfmpegFailure as describeFfmpegFailure3,
11843
11881
  encodeAac as encodeAac2,
11844
- renameWithRetry as renameWithRetry6
11882
+ renameWithRetry as renameWithRetry5
11845
11883
  } from "@hyperframes/engine";
11846
11884
 
11847
11885
  // src/services/render/audioPadTrim.ts
11886
+ import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
11848
11887
  import { spawn } from "node:child_process";
11849
11888
  import { dirname as dirname10, join as join25 } from "node:path";
11850
11889
  import {
@@ -11855,7 +11894,7 @@ import {
11855
11894
  getFfprobeBinary,
11856
11895
  ManagedChildProcess,
11857
11896
  removeScratch,
11858
- renameWithRetry as renameWithRetry5,
11897
+ renameWithRetry as renameWithRetry4,
11859
11898
  runFfmpeg as runFfmpeg5,
11860
11899
  trackChildProcess,
11861
11900
  withPublicOnlyProxy
@@ -11996,10 +12035,10 @@ function sanitizeProbeFailure(reason, paths) {
11996
12035
  }
11997
12036
  async function padOrTrimAudioToVideoFrameCount(input) {
11998
12037
  const probeVideo = input.probeVideoFrameInfo ?? ((videoPath) => defaultProbeVideoFrameInfo(videoPath, input.signal));
11999
- const probeAudio = input.probeAudioInfo ?? defaultProbeAudioInfo;
12038
+ const probeAudio = input.probeAudioInfo ?? ((path, signal) => defaultProbeAudioInfo(path, signal, input.audioContainer));
12000
12039
  const timeoutMs = input.timeoutMs ?? DEFAULT_CONFIG.ffmpegProcessTimeout;
12001
12040
  const runner = input.runFfmpeg ?? ((args) => defaultRunFfmpeg(args, timeoutMs, input.signal));
12002
- const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath);
12041
+ const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath, input.audioContainer);
12003
12042
  const probeTruePeak = input.probeAudioTruePeakDbfs ?? (input.runFfmpeg || input.encodeAac ? void 0 : (audioPath, signal) => measureTruePeakDbfs(audioPath, { timeoutMs, signal }));
12004
12043
  const [videoResult, audioResult] = await Promise.allSettled([
12005
12044
  probeVideo(input.videoPath),
@@ -12047,7 +12086,7 @@ async function padOrTrimAudioToVideoFrameCount(input) {
12047
12086
  );
12048
12087
  try {
12049
12088
  for (const step of plan2.steps) {
12050
- const ffmpegResult = step.kind === "copy" ? await runner(step.args) : await encode(
12089
+ const ffmpegResult = step.kind === "copy" ? await runner([...localContainerInputArgs(input.audioContainer), ...step.args]) : await encode(
12051
12090
  input.sourcePath ?? input.audioPath,
12052
12091
  input.outputPath,
12053
12092
  targetDurationSeconds,
@@ -12131,7 +12170,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
12131
12170
  try {
12132
12171
  const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
12133
12172
  if (!result.success) throw new Error(result.error);
12134
- renameWithRetry5(cutPath, input.sourcePath, { copyFallback: true });
12173
+ renameWithRetry4(cutPath, input.sourcePath, { copyFallback: true });
12135
12174
  return true;
12136
12175
  } catch {
12137
12176
  removeScratch(input.sourcePath);
@@ -12158,7 +12197,7 @@ async function enforceAacTruePeak(input) {
12158
12197
  if (truePeakDbfs <= AAC_DELIVERY_TRUE_PEAK_DBFS) {
12159
12198
  if (measuredPath !== correctedPath) return { success: true };
12160
12199
  const sourceCut = await cutSource(input, scratchDir, attenuationDb);
12161
- renameWithRetry5(correctedPath, input.audioPath, { copyFallback: true });
12200
+ renameWithRetry4(correctedPath, input.audioPath, { copyFallback: true });
12162
12201
  const loweredDb = Number((-attenuationDb).toFixed(2));
12163
12202
  return sourceCut ? { success: true, loweredDb } : { success: true, loweredDb, sourceStale: true };
12164
12203
  }
@@ -12213,7 +12252,8 @@ function failResult(outputPath, target, source, error) {
12213
12252
  error
12214
12253
  };
12215
12254
  }
12216
- async function defaultProbeVideoFrameInfo(videoPath, signal) {
12255
+ async function defaultProbeVideoFrameInfo(videoPath, signal, container) {
12256
+ const inputArgs = localContainerInputArgs(container);
12217
12257
  const fastInfo = await runFfprobeJson(
12218
12258
  [
12219
12259
  "-v",
@@ -12224,6 +12264,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
12224
12264
  "stream=nb_frames,r_frame_rate",
12225
12265
  "-of",
12226
12266
  "json",
12267
+ ...inputArgs,
12227
12268
  "--",
12228
12269
  videoPath
12229
12270
  ],
@@ -12245,6 +12286,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
12245
12286
  "stream=nb_read_packets,r_frame_rate",
12246
12287
  "-of",
12247
12288
  "json",
12289
+ ...inputArgs,
12248
12290
  "--",
12249
12291
  videoPath
12250
12292
  ],
@@ -12267,8 +12309,8 @@ function parseFrameRate(rate) {
12267
12309
  }
12268
12310
  return { fpsNum, fpsDen };
12269
12311
  }
12270
- async function defaultProbeAudioInfo(audioPath, signal) {
12271
- const metadata = await extractAudioMetadata3(audioPath, { signal });
12312
+ async function defaultProbeAudioInfo(audioPath, signal, inputContainer) {
12313
+ const metadata = await extractAudioMetadata3(audioPath, { signal, inputContainer });
12272
12314
  return {
12273
12315
  durationSeconds: metadata.durationSeconds,
12274
12316
  sampleRate: metadata.sampleRate,
@@ -12279,9 +12321,9 @@ async function defaultProbeAudioInfo(audioPath, signal) {
12279
12321
  async function defaultRunFfmpeg(args, timeoutMs, signal) {
12280
12322
  return toStepResult(await runFfmpeg5(args, { signal, timeout: timeoutMs }), timeoutMs);
12281
12323
  }
12282
- function defaultAacEncoder(timeoutMs, signal, pcmSourcePath) {
12324
+ function defaultAacEncoder(timeoutMs, signal, pcmSourcePath, inputContainer) {
12283
12325
  return async (inputPath, outputPath, durationSeconds, filter) => {
12284
- const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1 };
12326
+ const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1, inputContainer };
12285
12327
  return toStepResult(
12286
12328
  await encodeAac(pcmSourcePath ?? inputPath, outputPath, durationSeconds, options),
12287
12329
  timeoutMs
@@ -12354,8 +12396,8 @@ async function limitDeliveryPeaks(input, deps = {
12354
12396
  measure: measureTruePeakDbfs,
12355
12397
  applyChain: applyAudioFxChain,
12356
12398
  encode: encodeAac2,
12357
- rename: renameWithRetry6,
12358
- sourceExists: existsSync16
12399
+ rename: renameWithRetry5,
12400
+ sourceExists: existsSync15
12359
12401
  }) {
12360
12402
  const { audioPath, sourcePath, signal, timeoutMs } = input;
12361
12403
  if (!deps.sourceExists(sourcePath)) return { success: true };
@@ -12451,7 +12493,7 @@ async function runAudioStageScoped(input) {
12451
12493
  );
12452
12494
  audioLoweredDb = guard.loweredDb;
12453
12495
  input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
12454
- if (input.keepDeliverySource && !guard.sourceStale && existsSync17(pcmSourcePath)) {
12496
+ if (input.keepDeliverySource && !guard.sourceStale && existsSync16(pcmSourcePath)) {
12455
12497
  deliverySourcePath = pcmSourcePath;
12456
12498
  }
12457
12499
  }
@@ -12580,7 +12622,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
12580
12622
  }
12581
12623
 
12582
12624
  // src/services/render/stages/captureStage.ts
12583
- import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
12625
+ import { existsSync as existsSync17, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
12584
12626
  import { join as join28 } from "node:path";
12585
12627
  import {
12586
12628
  classifyCaptureFailure as classifyCaptureFailure2,
@@ -12651,7 +12693,7 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
12651
12693
  }
12652
12694
  function measureCaptureFrameBytes(workDir, framesDir) {
12653
12695
  let total = sampleDirectoryBytes(framesDir);
12654
- if (!existsSync18(workDir)) return total;
12696
+ if (!existsSync17(workDir)) return total;
12655
12697
  for (const attempt of readdirSync4(workDir)) {
12656
12698
  if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
12657
12699
  total += sampleDirectoryBytes(join28(workDir, attempt));
@@ -12958,7 +13000,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
12958
13000
  }
12959
13001
 
12960
13002
  // src/services/render/stages/captureHdrStage.ts
12961
- import { existsSync as existsSync20, mkdirSync as mkdirSync10 } from "node:fs";
13003
+ import { existsSync as existsSync19, mkdirSync as mkdirSync10 } from "node:fs";
12962
13004
  import { join as join32 } from "node:path";
12963
13005
  import {
12964
13006
  closeCaptureSession as closeCaptureSession7,
@@ -13205,7 +13247,7 @@ import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
13205
13247
  import { dirname as dirname12, join as join30 } from "node:path";
13206
13248
  import { createRequire } from "node:module";
13207
13249
  import { usableCpuCount } from "@hyperframes/engine";
13208
- import { existsSync as existsSync19 } from "node:fs";
13250
+ import { existsSync as existsSync18 } from "node:fs";
13209
13251
  function resolveWorkerEntry(explicit) {
13210
13252
  if (explicit && explicit.length > 0) {
13211
13253
  return { path: explicit, isTs: explicit.endsWith(".ts") };
@@ -13217,7 +13259,7 @@ function resolveWorkerEntry(explicit) {
13217
13259
  }
13218
13260
  const moduleDir = dirname12(fileURLToPath3(import.meta.url));
13219
13261
  const jsPath = join30(moduleDir, "shaderTransitionWorker.js");
13220
- if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
13262
+ if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
13221
13263
  const tsPath = join30(moduleDir, "shaderTransitionWorker.ts");
13222
13264
  return { path: tsPath, isTs: true };
13223
13265
  }
@@ -13783,7 +13825,7 @@ async function runCaptureHdrStage(input) {
13783
13825
  }
13784
13826
  const debugDumpEnabled = process.env.KEEP_TEMP === "1";
13785
13827
  const debugDumpDir = debugDumpEnabled ? join32(framesDir, "debug-composite") : null;
13786
- if (debugDumpDir && !existsSync20(debugDumpDir)) {
13828
+ if (debugDumpDir && !existsSync19(debugDumpDir)) {
13787
13829
  mkdirSync10(debugDumpDir, { recursive: true });
13788
13830
  }
13789
13831
  const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
@@ -13942,13 +13984,13 @@ async function runCaptureHdrStage(input) {
13942
13984
  // src/services/render/stages/encodeStage.ts
13943
13985
  import {
13944
13986
  copyFileSync as copyFileSync4,
13945
- existsSync as existsSync21,
13987
+ existsSync as existsSync20,
13946
13988
  mkdirSync as mkdirSync11,
13947
13989
  readdirSync as readdirSync5,
13948
13990
  readFileSync as readFileSync9,
13949
13991
  rmSync as rmSync11,
13950
13992
  statSync as statSync9,
13951
- writeFileSync as writeFileSync6
13993
+ writeFileSync as writeFileSync5
13952
13994
  } from "node:fs";
13953
13995
  import { readFile as readFile2 } from "node:fs/promises";
13954
13996
  import { dirname as dirname13, join as join33 } from "node:path";
@@ -14044,7 +14086,7 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
14044
14086
  const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
14045
14087
  return gifEncodeFailure(startTime, outputPath, error);
14046
14088
  }
14047
- writeFileSync6(outputPath, gif);
14089
+ writeFileSync5(outputPath, gif);
14048
14090
  return null;
14049
14091
  }
14050
14092
  async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
@@ -14076,7 +14118,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
14076
14118
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
14077
14119
  if (failure) return failure;
14078
14120
  }
14079
- const fileSize = existsSync21(outputPath) ? statSync9(outputPath).size : 0;
14121
+ const fileSize = existsSync20(outputPath) ? statSync9(outputPath).size : 0;
14080
14122
  return {
14081
14123
  success: true,
14082
14124
  outputPath,
@@ -14245,7 +14287,7 @@ async function runEncodeStage(input) {
14245
14287
  const stage5Start = Date.now();
14246
14288
  if (isPngSequence) {
14247
14289
  const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
14248
- if (!existsSync21(outputPath)) mkdirSync11(outputPath, { recursive: true });
14290
+ if (!existsSync20(outputPath)) mkdirSync11(outputPath, { recursive: true });
14249
14291
  const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
14250
14292
  if (captured.length === 0) {
14251
14293
  throw new Error(
@@ -14256,7 +14298,7 @@ async function runEncodeStage(input) {
14256
14298
  const dst = join33(outputPath, formatExportFrameName(i, "png"));
14257
14299
  copyFileSync4(join33(framesDir, name), dst);
14258
14300
  });
14259
- if (hasAudio && audioOutputPath && existsSync21(audioOutputPath)) {
14301
+ if (hasAudio && audioOutputPath && existsSync20(audioOutputPath)) {
14260
14302
  copyFileSync4(audioOutputPath, join33(outputPath, MIXED_AUDIO_FILENAME2));
14261
14303
  log.info(
14262
14304
  `[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
@@ -14647,7 +14689,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
14647
14689
  let rangeStart = null;
14648
14690
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
14649
14691
  const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
14650
- const missing = !existsSync22(framePath) || statSync10(framePath).size <= 8;
14692
+ const missing = !existsSync21(framePath) || statSync10(framePath).size <= 8;
14651
14693
  if (missing && rangeStart === null) {
14652
14694
  rangeStart = frameIndex;
14653
14695
  } else if (!missing && rangeStart !== null) {
@@ -14780,7 +14822,7 @@ function countCapturedFrames(totalFrames, framesDir, frameExt) {
14780
14822
  let captured = 0;
14781
14823
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
14782
14824
  const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
14783
- if (existsSync22(framePath)) captured++;
14825
+ if (existsSync21(framePath)) captured++;
14784
14826
  }
14785
14827
  return captured;
14786
14828
  }
@@ -15461,7 +15503,7 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
15461
15503
  validateChromaSubsamplingConfig(job.config);
15462
15504
  const debugDir = resolveRenderDebugDir();
15463
15505
  const outputDir = dirname14(outputPath);
15464
- if (!existsSync22(outputDir)) mkdirSync12(outputDir, { recursive: true });
15506
+ if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
15465
15507
  const workDir = job.config.debug ? join34(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
15466
15508
  const pipelineStart = Date.now();
15467
15509
  const baseLog = job.config.logger ?? defaultLogger;
@@ -15618,7 +15660,7 @@ async function executeRenderPipeline(input) {
15618
15660
  job.startedAt = /* @__PURE__ */ new Date();
15619
15661
  assertNotAborted();
15620
15662
  assertConfiguredFfmpegBinariesExist();
15621
- if (!existsSync22(workDir)) mkdirSync12(workDir, { recursive: true });
15663
+ if (!existsSync21(workDir)) mkdirSync12(workDir, { recursive: true });
15622
15664
  if (job.config.debug) {
15623
15665
  log.info("[Render] Debug artifacts enabled", { workDir, logPath });
15624
15666
  }
@@ -15648,7 +15690,7 @@ async function executeRenderPipeline(input) {
15648
15690
  });
15649
15691
  const entryFile = job.config.entryFile || "index.html";
15650
15692
  const htmlPath = join34(projectDir, entryFile);
15651
- if (!existsSync22(htmlPath)) {
15693
+ if (!existsSync21(htmlPath)) {
15652
15694
  throw new Error(`Entry file not found: ${htmlPath}`);
15653
15695
  }
15654
15696
  assertNotAborted();
@@ -16016,7 +16058,7 @@ async function executeRenderPipeline(input) {
16016
16058
  throw new Error("File server failed to initialize before frame capture");
16017
16059
  }
16018
16060
  const framesDir = join34(workDir, "captured-frames");
16019
- if (!existsSync22(framesDir)) mkdirSync12(framesDir, { recursive: true });
16061
+ if (!existsSync21(framesDir)) mkdirSync12(framesDir, { recursive: true });
16020
16062
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
16021
16063
  code: "start_browsers"
16022
16064
  });
@@ -16913,29 +16955,8 @@ async function executeRenderPipeline(input) {
16913
16955
  pageMotionBlur: job.config.pageMotionBlur,
16914
16956
  captureQuality: captureOptions.quality
16915
16957
  });
16916
- const segmentDir = segmentDirFor(join34(projectDir, "renders"), segmentPlanHash);
16958
+ const segmentDir = segmentDirFor(projectDir, segmentPlanHash);
16917
16959
  const manifestKey = loadResumeKeyOrWarn(job.config.resumeSegments === true, log);
16918
- let completedSegments = /* @__PURE__ */ new Set();
16919
- if (job.config.resumeSegments === true) {
16920
- const existing = readSegmentManifest(segmentDir);
16921
- if (existing) {
16922
- completedSegments = await validateCompletedSegments(existing, {
16923
- expectedHash: segmentPlanHash,
16924
- segmentDir,
16925
- plan: planSegments(totalFrames, segmentFrames),
16926
- key: manifestKey,
16927
- probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
16928
- });
16929
- log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
16930
- segmentDir
16931
- });
16932
- }
16933
- if (completedSegments.size === 0) {
16934
- rmSync12(segmentDir, { recursive: true, force: true });
16935
- }
16936
- } else {
16937
- rmSync12(segmentDir, { recursive: true, force: true });
16938
- }
16939
16960
  const emptySegmentManifest = () => ({
16940
16961
  version: 1,
16941
16962
  planHash: segmentPlanHash,
@@ -16943,7 +16964,26 @@ async function executeRenderPipeline(input) {
16943
16964
  segmentFrames,
16944
16965
  completed: []
16945
16966
  });
16946
- let segmentManifest = readSegmentManifest(segmentDir) ?? emptySegmentManifest();
16967
+ let segmentManifest = emptySegmentManifest();
16968
+ let completedSegments = /* @__PURE__ */ new Set();
16969
+ const existing = job.config.resumeSegments ? readSegmentManifest(segmentDir) : null;
16970
+ if (existing) {
16971
+ completedSegments = await validateCompletedSegments(existing, {
16972
+ expectedHash: segmentPlanHash,
16973
+ segmentDir,
16974
+ totalFrames,
16975
+ segmentFrames,
16976
+ key: manifestKey,
16977
+ probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
16978
+ });
16979
+ segmentManifest.completed = existing.completed.filter(
16980
+ (entry) => completedSegments.has(entry.index)
16981
+ );
16982
+ log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
16983
+ segmentDir
16984
+ });
16985
+ }
16986
+ if (completedSegments.size === 0) rmSync12(segmentDir, { recursive: true, force: true });
16947
16987
  const invokeSegmented = () => {
16948
16988
  if (capturePlan.kind !== "sdr_segmented") {
16949
16989
  throw new Error(`Cannot invoke segmented stage with ${capturePlan.kind} plan`);
@@ -17460,7 +17500,7 @@ async function executeRenderPipeline(input) {
17460
17500
  })
17461
17501
  );
17462
17502
  const totalElapsed = Date.now() - pipelineStart;
17463
- const tmpPeakBytes = existsSync22(workDir) ? sampleDirectoryBytes(workDir) : 0;
17503
+ const tmpPeakBytes = existsSync21(workDir) ? sampleDirectoryBytes(workDir) : 0;
17464
17504
  recordTransientRetryObservability();
17465
17505
  observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
17466
17506
  const observabilitySummary = observability.summary({
@@ -17532,7 +17572,7 @@ async function executeRenderPipeline(input) {
17532
17572
  job.perfSummary = perfSummary;
17533
17573
  if (job.config.debug) {
17534
17574
  try {
17535
- writeFileSync7(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
17575
+ writeFileSync6(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
17536
17576
  } catch (err) {
17537
17577
  log.debug("Failed to write perf summary", {
17538
17578
  perfOutputPath,
@@ -17541,7 +17581,7 @@ async function executeRenderPipeline(input) {
17541
17581
  }
17542
17582
  }
17543
17583
  if (job.config.debug) {
17544
- if (!isPngSequence && !isHls && existsSync22(stagedOutputPath)) {
17584
+ if (!isPngSequence && !isHls && existsSync21(stagedOutputPath)) {
17545
17585
  const debugOutput = join34(workDir, `output${videoExt}`);
17546
17586
  copyFileSync5(stagedOutputPath, debugOutput);
17547
17587
  }
@@ -17667,7 +17707,7 @@ import { tmpdir as tmpdir5 } from "node:os";
17667
17707
  // src/services/distributed/mp4Stitch.ts
17668
17708
  import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync13 } from "node:fs";
17669
17709
  import { open } from "node:fs/promises";
17670
- import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
17710
+ import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
17671
17711
  import { basename as basename8, dirname as dirname15, join as join35 } from "node:path";
17672
17712
  import { finished, pipeline } from "node:stream/promises";
17673
17713
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
@@ -18041,7 +18081,7 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
18041
18081
  for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
18042
18082
  out.end();
18043
18083
  await finished(out);
18044
- renameWithRetry7(join35(workDir, "out.mp4"), outputPath);
18084
+ renameWithRetry6(join35(workDir, "out.mp4"), outputPath);
18045
18085
  } finally {
18046
18086
  out.destroy();
18047
18087
  rmSync13(workDir, { recursive: true, force: true });
@@ -18058,25 +18098,25 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
18058
18098
  import {
18059
18099
  copyFileSync as copyFileSync6,
18060
18100
  cpSync as cpSync2,
18061
- existsSync as existsSync27,
18101
+ existsSync as existsSync26,
18062
18102
  linkSync,
18063
18103
  mkdirSync as mkdirSync16,
18064
18104
  rmSync as rmSync14,
18065
- writeFileSync as writeFileSync10
18105
+ writeFileSync as writeFileSync9
18066
18106
  } from "node:fs";
18067
18107
  import { extname as extname6, isAbsolute as isAbsolute4, join as join43, relative as relative7, sep as sep5 } from "node:path";
18068
18108
  import {
18069
18109
  fpsToNumber as fpsToNumber9,
18070
18110
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
18071
18111
  } from "@hyperframes/core";
18072
- import { isSafePath as isSafePath2 } from "@hyperframes/core/safe-path";
18112
+ import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
18073
18113
  import {
18074
18114
  getEncoderPreset as getEncoderPreset4,
18075
18115
  keyframeIntervalToGopSize as keyframeIntervalToGopSize3,
18076
18116
  normalizeVp9CpuUsed,
18077
18117
  resolveConfig as resolveConfig3,
18078
18118
  declareContentAddressedUrl,
18079
- renameWithRetry as renameWithRetry8,
18119
+ renameWithRetry as renameWithRetry7,
18080
18120
  declareProbeFactsUrl
18081
18121
  } from "@hyperframes/engine";
18082
18122
 
@@ -18090,7 +18130,7 @@ import {
18090
18130
  } from "@hyperframes/engine";
18091
18131
 
18092
18132
  // src/services/distributed/chunkFrames.ts
18093
- import { existsSync as existsSync24, readdirSync as readdirSync7 } from "node:fs";
18133
+ import { existsSync as existsSync23, readdirSync as readdirSync7 } from "node:fs";
18094
18134
  import { extname as extname4, join as join37 } from "node:path";
18095
18135
  import {
18096
18136
  compositionRequiresWebGpu as compositionRequiresWebGpu3,
@@ -18101,7 +18141,7 @@ import {
18101
18141
  // src/services/distributed/shared.ts
18102
18142
  import { execFile as execFileCallback } from "node:child_process";
18103
18143
  import { dirname as dirname16, join as join36 } from "node:path";
18104
- import { existsSync as existsSync23, readFileSync as readFileSync10 } from "node:fs";
18144
+ import { existsSync as existsSync22, readFileSync as readFileSync10 } from "node:fs";
18105
18145
  import { fileURLToPath as fileURLToPath5 } from "node:url";
18106
18146
  import { promisify as promisify2 } from "node:util";
18107
18147
  import {
@@ -18117,7 +18157,7 @@ function isPlanAudioArtifactPath(path) {
18117
18157
  function resolvePlanAudioPath(planDir) {
18118
18158
  for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
18119
18159
  const candidate = join36(planDir, name);
18120
- if (existsSync23(candidate)) return candidate;
18160
+ if (existsSync22(candidate)) return candidate;
18121
18161
  }
18122
18162
  return null;
18123
18163
  }
@@ -18382,7 +18422,7 @@ function readProducerVersion() {
18382
18422
  let current = startDir;
18383
18423
  for (let i = 0; i < 10; i++) {
18384
18424
  const candidate = join36(current, "package.json");
18385
- if (existsSync23(candidate)) {
18425
+ if (existsSync22(candidate)) {
18386
18426
  try {
18387
18427
  const pkg = JSON.parse(readFileSync10(candidate, "utf-8"));
18388
18428
  if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
@@ -18437,7 +18477,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
18437
18477
  const result = [];
18438
18478
  for (const v of videos) {
18439
18479
  const outputDir = join37(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
18440
- if (!existsSync24(outputDir)) {
18480
+ if (!existsSync23(outputDir)) {
18441
18481
  throw new Error(
18442
18482
  `[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
18443
18483
  );
@@ -18536,7 +18576,7 @@ async function extractDeferredVideoFramesForChunk(input) {
18536
18576
  const range = planned.get(video.videoId).deferredRange;
18537
18577
  const remoteUrl = remoteSources[range.sourcePath];
18538
18578
  const sourcePath = remoteUrl ?? join37(input.planDir, ...range.sourcePath.split("/"));
18539
- if (remoteUrl === void 0 && !existsSync24(sourcePath)) {
18579
+ if (remoteUrl === void 0 && !existsSync23(sourcePath)) {
18540
18580
  throw new RenderChunkValidationError(
18541
18581
  MISSING_PLAN_ARTIFACT,
18542
18582
  `[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
@@ -18736,7 +18776,7 @@ async function readPlanReferenceBackground(input) {
18736
18776
  }
18737
18777
 
18738
18778
  // src/services/render/stages/freezePlan.ts
18739
- import { existsSync as existsSync25, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
18779
+ import { existsSync as existsSync24, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync7 } from "node:fs";
18740
18780
  import { join as join40, relative as relative5, resolve as resolve10 } from "node:path";
18741
18781
  import {
18742
18782
  REFERENCE_BACKGROUND_FIELD,
@@ -18836,7 +18876,7 @@ function readPlanProtocolV1(planJson, capabilities = DISTRIBUTED_RENDER_CAPABILI
18836
18876
 
18837
18877
  // src/services/render/stages/planHash.ts
18838
18878
  import { createHash as createHash8 } from "node:crypto";
18839
- import { closeSync as closeSync5, createReadStream as createReadStream5, openSync as openSync5, readSync as readSync5 } from "node:fs";
18879
+ import { closeSync as closeSync6, createReadStream as createReadStream5, openSync as openSync6, readSync as readSync5 } from "node:fs";
18840
18880
  var PLAN_HASH_SCHEMA_PREFIX = "hyperframes-plan-hash-v1\0";
18841
18881
  var FIELD_DELIMITER = Buffer.from([0]);
18842
18882
  function computePlanHash(input) {
@@ -18894,7 +18934,7 @@ function sha256Hex(bytes) {
18894
18934
  function sha256File(path) {
18895
18935
  const hash = createHash8("sha256");
18896
18936
  const buffer = Buffer.allocUnsafe(1024 * 1024);
18897
- const fd = openSync5(path, "r");
18937
+ const fd = openSync6(path, "r");
18898
18938
  try {
18899
18939
  let bytesRead = 0;
18900
18940
  do {
@@ -18902,7 +18942,7 @@ function sha256File(path) {
18902
18942
  if (bytesRead > 0) hash.update(buffer.subarray(0, bytesRead));
18903
18943
  } while (bytesRead > 0);
18904
18944
  } finally {
18905
- closeSync5(fd);
18945
+ closeSync6(fd);
18906
18946
  }
18907
18947
  return hash.digest("hex");
18908
18948
  }
@@ -18930,7 +18970,7 @@ function planFileSha256(absolutePath, digests) {
18930
18970
  return sha256;
18931
18971
  }
18932
18972
  async function prehashPlanFiles(dir, digests) {
18933
- if (!existsSync25(dir)) return;
18973
+ if (!existsSync24(dir)) return;
18934
18974
  for (const { absolutePath } of listPlanFiles(dir)) {
18935
18975
  if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
18936
18976
  }
@@ -18996,19 +19036,19 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
18996
19036
  function writePlanRemoteFiles(planDir, files) {
18997
19037
  if (files.length === 0) return;
18998
19038
  const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
18999
- writeFileSync8(join40(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
19039
+ writeFileSync7(join40(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
19000
19040
  }
19001
19041
  function readPlanRemoteFiles(planDir) {
19002
19042
  const path = join40(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
19003
- return existsSync25(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
19043
+ return existsSync24(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
19004
19044
  }
19005
19045
  function recomputePlanHashFromPlanDir(planDir, digests) {
19006
19046
  const planJsonPath = join40(planDir, "plan.json");
19007
19047
  const encoderJsonPath = join40(planDir, "meta", "encoder.json");
19008
- if (!existsSync25(planJsonPath)) {
19048
+ if (!existsSync24(planJsonPath)) {
19009
19049
  throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
19010
19050
  }
19011
- if (!existsSync25(encoderJsonPath)) {
19051
+ if (!existsSync24(encoderJsonPath)) {
19012
19052
  throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
19013
19053
  }
19014
19054
  const planJson = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
@@ -19038,12 +19078,12 @@ async function freezePlan(input) {
19038
19078
  hasAudio,
19039
19079
  digests
19040
19080
  } = input;
19041
- if (!existsSync25(planDir)) {
19081
+ if (!existsSync24(planDir)) {
19042
19082
  throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
19043
19083
  }
19044
19084
  const metaDir = join40(planDir, "meta");
19045
- if (!existsSync25(metaDir)) mkdirSync14(metaDir, { recursive: true });
19046
- writeFileSync8(
19085
+ if (!existsSync24(metaDir)) mkdirSync14(metaDir, { recursive: true });
19086
+ writeFileSync7(
19047
19087
  join40(metaDir, "composition.json"),
19048
19088
  `${JSON.stringify(composition, null, 2)}
19049
19089
  `,
@@ -19051,8 +19091,8 @@ async function freezePlan(input) {
19051
19091
  );
19052
19092
  const encoderForCanonical = stripUndefined(encoder);
19053
19093
  const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
19054
- writeFileSync8(join40(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
19055
- writeFileSync8(join40(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
19094
+ writeFileSync7(join40(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
19095
+ writeFileSync7(join40(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
19056
19096
  `, "utf-8");
19057
19097
  const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
19058
19098
  const planHash = computePlanHash({
@@ -19078,7 +19118,7 @@ async function freezePlan(input) {
19078
19118
  hasAudio
19079
19119
  };
19080
19120
  const planJsonPath = join40(planDir, "plan.json");
19081
- writeFileSync8(planJsonPath, `${JSON.stringify(planJson, null, 2)}
19121
+ writeFileSync7(planJsonPath, `${JSON.stringify(planJson, null, 2)}
19082
19122
  `, "utf-8");
19083
19123
  return { planJsonPath, planHash };
19084
19124
  }
@@ -19119,8 +19159,8 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
19119
19159
  }
19120
19160
 
19121
19161
  // src/services/distributed/chunkAudio.ts
19122
- import { closeSync as closeSync6, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync6, readFileSync as readFileSync12 } from "node:fs";
19123
- import { writeFileSync as writeFileSync9, writeSync } from "node:fs";
19162
+ import { closeSync as closeSync7, existsSync as existsSync25, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync7, readFileSync as readFileSync12 } from "node:fs";
19163
+ import { writeFileSync as writeFileSync8, writeSync } from "node:fs";
19124
19164
  import { join as join41 } from "node:path";
19125
19165
  import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
19126
19166
  function audioCutForChunk(grid, chunks, index, fps) {
@@ -19217,18 +19257,18 @@ async function writeChunkAudioSlices(input) {
19217
19257
  const start = offsets[cut.firstPacket];
19218
19258
  layout.partStarts[index] = start;
19219
19259
  const end = offsets[last] + track.sizes[last];
19220
- writeFileSync9(join41(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
19260
+ writeFileSync8(join41(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
19221
19261
  });
19222
19262
  const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
19223
- writeFileSync9(join41(input.planDir, SLICE_FRAME), Buffer.concat(frame));
19224
- writeFileSync9(join41(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
19263
+ writeFileSync8(join41(input.planDir, SLICE_FRAME), Buffer.concat(frame));
19264
+ writeFileSync8(join41(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
19225
19265
  }
19226
19266
  function chunkAudioSource(planDir, chunkIndex, scratchPath) {
19227
19267
  const layoutPath = join41(planDir, SLICE_LAYOUT);
19228
- if (!existsSync26(layoutPath)) return resolvePlanAudioPath(planDir);
19268
+ if (!existsSync25(layoutPath)) return resolvePlanAudioPath(planDir);
19229
19269
  const layout = JSON.parse(readFileSync12(layoutPath, "utf-8"));
19230
19270
  const frame = readFileSync12(join41(planDir, SLICE_FRAME));
19231
- const fd = openSync6(scratchPath, "w");
19271
+ const fd = openSync7(scratchPath, "w");
19232
19272
  try {
19233
19273
  writeSync(fd, frame, 0, layout.payloadStart, 0);
19234
19274
  writeSync(
@@ -19245,7 +19285,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
19245
19285
  }
19246
19286
  ftruncateSync(fd, layout.sizeBytes);
19247
19287
  } finally {
19248
- closeSync6(fd);
19288
+ closeSync7(fd);
19249
19289
  }
19250
19290
  return scratchPath;
19251
19291
  }
@@ -19792,7 +19832,7 @@ function createVideoSourceShipper(input) {
19792
19832
  let result = null;
19793
19833
  for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
19794
19834
  const rel = pathInside(root, srcPath);
19795
- if (rel !== null && (existsSync27(join43(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
19835
+ if (rel !== null && (existsSync26(join43(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
19796
19836
  result = ["compiled", ...rel.split(sep5)].join("/");
19797
19837
  break;
19798
19838
  }
@@ -19820,7 +19860,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
19820
19860
  useGpu: false,
19821
19861
  browserGpuMode: "software"
19822
19862
  });
19823
- if (!existsSync27(planDir)) mkdirSync16(planDir, { recursive: true });
19863
+ if (!existsSync26(planDir)) mkdirSync16(planDir, { recursive: true });
19824
19864
  const log = config.logger ?? defaultLogger;
19825
19865
  const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
19826
19866
  const abortSignal = config.abortSignal;
@@ -19855,7 +19895,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
19855
19895
  });
19856
19896
  const entryFile = config.entryFile ?? "index.html";
19857
19897
  const htmlPath = join43(projectDir, entryFile);
19858
- if (!existsSync27(htmlPath)) {
19898
+ if (!existsSync26(htmlPath)) {
19859
19899
  throw new Error(`[plan] entry file not found: ${htmlPath}`);
19860
19900
  }
19861
19901
  const workDir = join43(planDir, ".plan-work");
@@ -19875,7 +19915,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
19875
19915
  const warn = (line) => log.warn(`[Plan] ${line}`);
19876
19916
  const policy = { includeScripts: job.config.includeOutsideScripts };
19877
19917
  if (refusesOutsideLink(projectDir, src, warn, policy)) return false;
19878
- } else if (!isSafePath2(projectDir, src)) return false;
19918
+ } else if (!isSafePath3(projectDir, src)) return false;
19879
19919
  const firstSegment = rel.split(sep5, 1)[0];
19880
19920
  return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
19881
19921
  }
@@ -20091,16 +20131,16 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
20091
20131
  logPlanStage(log, "extract", stageStarted);
20092
20132
  const stagedVideoFrames = join43(compiledDir, "__hyperframes_video_frames");
20093
20133
  const videoFramesDst = join43(planDir, "video-frames");
20094
- if (existsSync27(videoFramesDst)) rmSync14(videoFramesDst, { recursive: true, force: true });
20134
+ if (existsSync26(videoFramesDst)) rmSync14(videoFramesDst, { recursive: true, force: true });
20095
20135
  const videoSourcesDir = join43(planDir, "video-sources");
20096
20136
  rmSync14(videoSourcesDir, { recursive: true, force: true });
20097
- if (existsSync27(stagedVideoFrames)) {
20098
- renameWithRetry8(stagedVideoFrames, videoFramesDst);
20137
+ if (existsSync26(stagedVideoFrames)) {
20138
+ renameWithRetry7(stagedVideoFrames, videoFramesDst);
20099
20139
  } else {
20100
20140
  mkdirSync16(videoFramesDst, { recursive: true });
20101
20141
  }
20102
- if (existsSync27(finalCompiledDir)) rmSync14(finalCompiledDir, { recursive: true, force: true });
20103
- renameWithRetry8(compiledDir, finalCompiledDir);
20142
+ if (existsSync26(finalCompiledDir)) rmSync14(finalCompiledDir, { recursive: true, force: true });
20143
+ renameWithRetry7(compiledDir, finalCompiledDir);
20104
20144
  const shipVideoSource = createVideoSourceShipper({
20105
20145
  planDir,
20106
20146
  projectDir,
@@ -20138,7 +20178,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
20138
20178
  sizeBytes
20139
20179
  }))
20140
20180
  );
20141
- writeFileSync10(
20181
+ writeFileSync9(
20142
20182
  join43(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
20143
20183
  JSON.stringify(planVideosJson, null, 2),
20144
20184
  "utf-8"
@@ -20220,10 +20260,10 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
20220
20260
  applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
20221
20261
  }
20222
20262
  const planAudioPath = join43(planDir, PLAN_AUDIO_RELATIVE_PATH);
20223
- if (audioResult?.hasAudio && existsSync27(audioResult.audioOutputPath)) {
20224
- renameWithRetry8(audioResult.audioOutputPath, planAudioPath);
20263
+ if (audioResult?.hasAudio && existsSync26(audioResult.audioOutputPath)) {
20264
+ renameWithRetry7(audioResult.audioOutputPath, planAudioPath);
20225
20265
  }
20226
- if (chunksCarryAudio && existsSync27(planAudioPath)) {
20266
+ if (chunksCarryAudio && existsSync26(planAudioPath)) {
20227
20267
  if (options.sliceChunkAudio) {
20228
20268
  stageStarted = Date.now();
20229
20269
  await writeChunkAudioSlices({
@@ -20345,7 +20385,7 @@ async function plan(projectDir, config, planDir, options = {}) {
20345
20385
 
20346
20386
  // src/services/distributed/renderChunk.ts
20347
20387
  import { randomBytes } from "node:crypto";
20348
- import { existsSync as existsSync30, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync13 } from "node:fs";
20388
+ import { existsSync as existsSync29, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync12 } from "node:fs";
20349
20389
  import { join as join47 } from "node:path";
20350
20390
  import {
20351
20391
  assertSwiftShader,
@@ -20372,14 +20412,14 @@ import {
20372
20412
  } from "@hyperframes/engine";
20373
20413
  import {
20374
20414
  copyFileSync as copyFileSync8,
20375
- existsSync as existsSync29,
20415
+ existsSync as existsSync28,
20376
20416
  lstatSync as lstatSync5,
20377
20417
  mkdirSync as mkdirSync18,
20378
20418
  readFileSync as readFileSync13,
20379
20419
  readdirSync as readdirSync10,
20380
20420
  rmSync as rmSync16,
20381
20421
  statSync as statSync12,
20382
- writeFileSync as writeFileSync12
20422
+ writeFileSync as writeFileSync11
20383
20423
  } from "node:fs";
20384
20424
  import { tmpdir as tmpdir4 } from "node:os";
20385
20425
  import { dirname as dirname18, isAbsolute as isAbsolute5, join as join46, relative as relative8, resolve as resolve11, sep as sep6 } from "node:path";
@@ -20387,20 +20427,20 @@ import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
20387
20427
  import {
20388
20428
  createFrameLookupTable as createFrameLookupTable5,
20389
20429
  mediaIdPathSegment as mediaIdPathSegment4,
20390
- renameWithRetry as renameWithRetry10
20430
+ renameWithRetry as renameWithRetry9
20391
20431
  } from "@hyperframes/engine";
20392
20432
 
20393
20433
  // src/services/distributed/planV2Publisher.ts
20394
20434
  import {
20395
20435
  copyFileSync as copyFileSync7,
20396
- existsSync as existsSync28,
20436
+ existsSync as existsSync27,
20397
20437
  linkSync as linkSync2,
20398
20438
  mkdirSync as mkdirSync17,
20399
20439
  rmSync as rmSync15,
20400
20440
  statSync as statSync11,
20401
- writeFileSync as writeFileSync11
20441
+ writeFileSync as writeFileSync10
20402
20442
  } from "node:fs";
20403
- import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
20443
+ import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
20404
20444
  import { dirname as dirname17, join as join45 } from "node:path";
20405
20445
 
20406
20446
  // src/services/distributed/planV2Errors.ts
@@ -20457,7 +20497,7 @@ var LocalPlanV2ArtifactPublisher = class {
20457
20497
  #linkFile;
20458
20498
  #committed = false;
20459
20499
  constructor(destinationDir, options = {}) {
20460
- if (existsSync28(destinationDir)) {
20500
+ if (existsSync27(destinationDir)) {
20461
20501
  throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
20462
20502
  }
20463
20503
  this.destinationDir = destinationDir;
@@ -20474,7 +20514,7 @@ var LocalPlanV2ArtifactPublisher = class {
20474
20514
  );
20475
20515
  }
20476
20516
  const destinationPath = planV2BlobPath(this.temporaryDir, digest);
20477
- if (existsSync28(destinationPath)) return;
20517
+ if (existsSync27(destinationPath)) return;
20478
20518
  mkdirSync17(dirname17(destinationPath), { recursive: true });
20479
20519
  const stagingDir = createStagingDir5(dirname17(destinationPath), ".plan-v2-blob-");
20480
20520
  const temporaryPath = join45(stagingDir, "blob");
@@ -20485,21 +20525,21 @@ var LocalPlanV2ArtifactPublisher = class {
20485
20525
  if (!cannotHardLink(error)) throw error;
20486
20526
  copyFileSync7(blob.sourcePath, temporaryPath);
20487
20527
  }
20488
- renameWithRetry9(temporaryPath, destinationPath);
20528
+ renameWithRetry8(temporaryPath, destinationPath);
20489
20529
  } finally {
20490
20530
  rmSync15(stagingDir, { recursive: true, force: true });
20491
20531
  }
20492
20532
  }
20493
20533
  async commitManifest(manifestBytes) {
20494
20534
  for (const digest of new Set(manifestDigests(manifestBytes))) {
20495
- if (!existsSync28(planV2BlobPath(this.temporaryDir, digest))) {
20535
+ if (!existsSync27(planV2BlobPath(this.temporaryDir, digest))) {
20496
20536
  throw new PlanV2IntegrityError(
20497
20537
  `cannot commit manifest before referenced blob is durable: ${digest}`
20498
20538
  );
20499
20539
  }
20500
20540
  }
20501
- writeFileSync11(join45(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
20502
- renameWithRetry9(this.temporaryDir, this.destinationDir);
20541
+ writeFileSync10(join45(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
20542
+ renameWithRetry8(this.temporaryDir, this.destinationDir);
20503
20543
  this.#committed = true;
20504
20544
  }
20505
20545
  async abort() {
@@ -20572,7 +20612,7 @@ function assertValidExtractionCacheCompleteSentinel(path) {
20572
20612
  }
20573
20613
  function validateExtractionCacheCompleteSentinels(executionPlanDir) {
20574
20614
  const videoRoot = join46(executionPlanDir, "video-frames");
20575
- if (!existsSync29(videoRoot)) return;
20615
+ if (!existsSync28(videoRoot)) return;
20576
20616
  for (const videoEntry of readdirSync10(videoRoot, { withFileTypes: true })) {
20577
20617
  if (!videoEntry.isDirectory()) continue;
20578
20618
  const videoDir = join46(videoRoot, videoEntry.name);
@@ -20673,7 +20713,7 @@ function parsePlanVideosJson2(value) {
20673
20713
  }
20674
20714
  function materializeExtractedVideoDirectories(planDir) {
20675
20715
  const videosPath = join46(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
20676
- if (!existsSync29(videosPath)) return;
20716
+ if (!existsSync28(videosPath)) return;
20677
20717
  const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
20678
20718
  for (const video of videos.extracted) {
20679
20719
  mkdirSync18(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
@@ -20707,9 +20747,9 @@ function parseChunkSlices(value) {
20707
20747
  }
20708
20748
  function buildVideoChunkDependencies(executionPlanDir, dimensions) {
20709
20749
  const videoRoot = join46(executionPlanDir, "video-frames");
20710
- const hasExtractedFrames = existsSync29(videoRoot) && listFiles(videoRoot).length > 0;
20750
+ const hasExtractedFrames = existsSync28(videoRoot) && listFiles(videoRoot).length > 0;
20711
20751
  const videosPath = join46(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
20712
- if (!existsSync29(videosPath)) {
20752
+ if (!existsSync28(videosPath)) {
20713
20753
  return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
20714
20754
  }
20715
20755
  const chunksPath = join46(executionPlanDir, "meta", "chunks.json");
@@ -20766,13 +20806,13 @@ function computeManifestHash(manifest) {
20766
20806
  return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
20767
20807
  }
20768
20808
  function writeBlob(sourcePath, destinationPath) {
20769
- if (existsSync29(destinationPath)) return;
20809
+ if (existsSync28(destinationPath)) return;
20770
20810
  mkdirSync18(dirname18(destinationPath), { recursive: true });
20771
20811
  const temporaryDir = createStagingDir6(dirname18(destinationPath), ".plan-v2-blob-");
20772
20812
  const temporaryPath = join46(temporaryDir, "blob");
20773
20813
  try {
20774
20814
  copyFileSync8(sourcePath, temporaryPath);
20775
- renameWithRetry10(temporaryPath, destinationPath);
20815
+ renameWithRetry9(temporaryPath, destinationPath);
20776
20816
  } finally {
20777
20817
  rmSync16(temporaryDir, { recursive: true, force: true });
20778
20818
  }
@@ -20806,7 +20846,7 @@ async function putTasks(tasks) {
20806
20846
  }
20807
20847
  function buildPlanV2Publication(executionPlanDir, digests) {
20808
20848
  const executionPlanPath = join46(executionPlanDir, "plan.json");
20809
- if (!existsSync29(executionPlanPath)) {
20849
+ if (!existsSync28(executionPlanPath)) {
20810
20850
  throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
20811
20851
  }
20812
20852
  const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
@@ -20886,7 +20926,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
20886
20926
  };
20887
20927
  }
20888
20928
  function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
20889
- if (existsSync29(planV2Dir)) {
20929
+ if (existsSync28(planV2Dir)) {
20890
20930
  throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
20891
20931
  }
20892
20932
  const publication = buildPlanV2Publication(executionPlanDir);
@@ -20899,12 +20939,12 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
20899
20939
  for (const blob of publication.blobs) {
20900
20940
  writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
20901
20941
  }
20902
- writeFileSync12(
20942
+ writeFileSync11(
20903
20943
  join46(tempDir, "plan.json"),
20904
20944
  canonicalJsonStringify(publication.manifest),
20905
20945
  "utf-8"
20906
20946
  );
20907
- renameWithRetry10(tempDir, planV2Dir);
20947
+ renameWithRetry9(tempDir, planV2Dir);
20908
20948
  return resultFromManifest(planV2Dir, publication.manifest);
20909
20949
  } catch (error) {
20910
20950
  rmSync16(tempDir, { recursive: true, force: true });
@@ -20976,7 +21016,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
20976
21016
  }
20977
21017
  }
20978
21018
  async function planV2(projectDir, config, planV2Dir) {
20979
- if (existsSync29(planV2Dir)) {
21019
+ if (existsSync28(planV2Dir)) {
20980
21020
  throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
20981
21021
  }
20982
21022
  const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
@@ -21130,7 +21170,7 @@ function parsePlanV2Manifest(value) {
21130
21170
  }
21131
21171
  function readPlanV2Manifest(planV2Dir) {
21132
21172
  const manifestPath = join46(planV2Dir, "plan.json");
21133
- if (!existsSync29(manifestPath)) {
21173
+ if (!existsSync28(manifestPath)) {
21134
21174
  throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
21135
21175
  }
21136
21176
  const value = readJsonFile(manifestPath, "v2 manifest");
@@ -21149,7 +21189,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
21149
21189
  }
21150
21190
  function verifyBlob(planV2Dir, artifact) {
21151
21191
  const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
21152
- if (!existsSync29(sourcePath)) {
21192
+ if (!existsSync28(sourcePath)) {
21153
21193
  throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
21154
21194
  }
21155
21195
  const stats = statSync12(sourcePath);
@@ -21162,7 +21202,7 @@ function verifyBlob(planV2Dir, artifact) {
21162
21202
  return sourcePath;
21163
21203
  }
21164
21204
  function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
21165
- if (existsSync29(destinationDir)) {
21205
+ if (existsSync28(destinationDir)) {
21166
21206
  throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
21167
21207
  }
21168
21208
  const manifest = readPlanV2Manifest(planV2Dir);
@@ -21183,7 +21223,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
21183
21223
  copyFileSync8(sourcePath, destinationPath);
21184
21224
  }
21185
21225
  if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
21186
- writeFileSync12(
21226
+ writeFileSync11(
21187
21227
  join46(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
21188
21228
  canonicalJsonStringify({
21189
21229
  manifest,
@@ -21192,7 +21232,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
21192
21232
  }),
21193
21233
  "utf-8"
21194
21234
  );
21195
- renameWithRetry10(tempDir, destinationDir);
21235
+ renameWithRetry9(tempDir, destinationDir);
21196
21236
  } catch (error) {
21197
21237
  rmSync16(tempDir, { recursive: true, force: true });
21198
21238
  throw error;
@@ -21227,7 +21267,7 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
21227
21267
  }
21228
21268
  function readValidatedPlanV2Materialization(planDir, expectedTarget) {
21229
21269
  const markerPath = join46(planDir, PLAN_V2_MATERIALIZATION_MARKER);
21230
- if (!existsSync29(markerPath)) return null;
21270
+ if (!existsSync28(markerPath)) return null;
21231
21271
  const marker = readJsonFile(markerPath, "materialization marker");
21232
21272
  if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
21233
21273
  throw new PlanV2IntegrityError("malformed materialization marker");
@@ -21245,7 +21285,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
21245
21285
  for (const artifact of required) {
21246
21286
  if (Object.hasOwn(remoteSources, artifact.path)) continue;
21247
21287
  const path = join46(planDir, ...artifact.path.split("/"));
21248
- if (!existsSync29(path) || statSync12(path).size !== artifact.sizeBytes) {
21288
+ if (!existsSync28(path) || statSync12(path).size !== artifact.sizeBytes) {
21249
21289
  throw new PlanV2IntegrityError(
21250
21290
  `materialized artifact missing or truncated: ${artifact.path}`
21251
21291
  );
@@ -21396,7 +21436,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21396
21436
  const planJsonPath = join47(planDir, "plan.json");
21397
21437
  const encoderJsonPath = join47(planDir, "meta", "encoder.json");
21398
21438
  const chunksJsonPath = join47(planDir, "meta", "chunks.json");
21399
- if (!existsSync30(planJsonPath)) {
21439
+ if (!existsSync29(planJsonPath)) {
21400
21440
  throw new RenderChunkValidationError(
21401
21441
  MISSING_PLAN_ARTIFACT,
21402
21442
  `[renderChunk] planDir is missing required artifact: ${planJsonPath}`
@@ -21412,7 +21452,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21412
21452
  const v2Manifest = v2Materialization?.manifest ?? null;
21413
21453
  const remoteSources = v2Materialization?.remoteSources ?? {};
21414
21454
  for (const required of [encoderJsonPath, chunksJsonPath]) {
21415
- if (!existsSync30(required)) {
21455
+ if (!existsSync29(required)) {
21416
21456
  throw new RenderChunkValidationError(
21417
21457
  MISSING_PLAN_ARTIFACT,
21418
21458
  `[renderChunk] planDir is missing required artifact: ${required}`
@@ -21423,7 +21463,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21423
21463
  const chunks = JSON.parse(readFileSync14(chunksJsonPath, "utf-8"));
21424
21464
  const videosJsonPath = join47(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
21425
21465
  let planVideos = null;
21426
- if (existsSync30(videosJsonPath)) {
21466
+ if (existsSync29(videosJsonPath)) {
21427
21467
  try {
21428
21468
  planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync14(videosJsonPath, "utf-8")));
21429
21469
  } catch (err) {
@@ -21454,7 +21494,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21454
21494
  const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
21455
21495
  const framesInChunk = range.endFrame - range.startFrame;
21456
21496
  const compiledDir = join47(planDir, "compiled");
21457
- if (!existsSync30(compiledDir)) {
21497
+ if (!existsSync29(compiledDir)) {
21458
21498
  throw new RenderChunkValidationError(
21459
21499
  MISSING_PLAN_ARTIFACT,
21460
21500
  `[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
@@ -21706,10 +21746,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21706
21746
  const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
21707
21747
  const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
21708
21748
  if (isPngSequence) {
21709
- if (!existsSync30(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
21749
+ if (!existsSync29(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
21710
21750
  } else {
21711
21751
  const outDir = join47(outputChunkPath, "..");
21712
- if (!existsSync30(outDir)) mkdirSync19(outDir, { recursive: true });
21752
+ if (!existsSync29(outDir)) mkdirSync19(outDir, { recursive: true });
21713
21753
  }
21714
21754
  const encodeInput = {
21715
21755
  job,
@@ -21922,7 +21962,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
21922
21962
  producerVersion: plan2.producerVersion,
21923
21963
  ffmpegVersion
21924
21964
  };
21925
- writeFileSync13(perfPath, `${JSON.stringify(perfPayload, null, 2)}
21965
+ writeFileSync12(perfPath, `${JSON.stringify(perfPayload, null, 2)}
21926
21966
  `, "utf-8");
21927
21967
  try {
21928
21968
  rmSync17(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
@@ -22673,11 +22713,11 @@ import {
22673
22713
 
22674
22714
  // src/server.ts
22675
22715
  import {
22676
- existsSync as existsSync33,
22716
+ existsSync as existsSync32,
22677
22717
  mkdirSync as mkdirSync21,
22678
22718
  statSync as statSync14,
22679
22719
  mkdtempSync as mkdtempSync2,
22680
- writeFileSync as writeFileSync14,
22720
+ writeFileSync as writeFileSync13,
22681
22721
  rmSync as rmSync19,
22682
22722
  createReadStream as createReadStream6
22683
22723
  } from "node:fs";
@@ -22694,17 +22734,17 @@ import {
22694
22734
  REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD5,
22695
22735
  referenceBackgroundResult as referenceBackgroundResult7
22696
22736
  } from "@hyperframes/engine";
22697
- import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
22737
+ import { isSafePath as isSafePath4 } from "@hyperframes/core/safe-path";
22698
22738
 
22699
22739
  // src/services/hyperframeLint.ts
22700
22740
  import {
22701
- existsSync as existsSync31,
22741
+ existsSync as existsSync30,
22702
22742
  readFileSync as readFileSync16,
22703
22743
  statSync as statSync13,
22704
- openSync as openSync7,
22705
- fstatSync as fstatSync3,
22706
- closeSync as closeSync7,
22707
- constants as constants3
22744
+ openSync as openSync8,
22745
+ fstatSync as fstatSync4,
22746
+ closeSync as closeSync8,
22747
+ constants as constants4
22708
22748
  } from "node:fs";
22709
22749
  import { resolve as resolve12, join as join49, relative as relative9, isAbsolute as isAbsolute6, sep as sep7, dirname as dirname19 } from "node:path";
22710
22750
  import { fileURLToPath as fileURLToPath6 } from "node:url";
@@ -22737,7 +22777,7 @@ function pickEntryFile(files, preferredEntryFile) {
22737
22777
  function readEntryHtml(filePath) {
22738
22778
  let fd;
22739
22779
  try {
22740
- fd = openSync7(filePath, constants3.O_RDONLY | constants3.O_NONBLOCK);
22780
+ fd = openSync8(filePath, constants4.O_RDONLY | constants4.O_NONBLOCK);
22741
22781
  } catch (error) {
22742
22782
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
22743
22783
  return null;
@@ -22745,10 +22785,10 @@ function readEntryHtml(filePath) {
22745
22785
  throw error;
22746
22786
  }
22747
22787
  try {
22748
- if (!fstatSync3(fd).isFile()) return null;
22788
+ if (!fstatSync4(fd).isFile()) return null;
22749
22789
  return readFileSync16(fd, "utf-8");
22750
22790
  } finally {
22751
- closeSync7(fd);
22791
+ closeSync8(fd);
22752
22792
  }
22753
22793
  }
22754
22794
  function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
@@ -22757,7 +22797,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
22757
22797
  }
22758
22798
  function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
22759
22799
  const absProjectDir = resolve12(projectDir);
22760
- if (!existsSync31(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
22800
+ if (!existsSync30(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
22761
22801
  return { error: `Project directory not found: ${absProjectDir}` };
22762
22802
  }
22763
22803
  const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
@@ -22848,7 +22888,7 @@ function resolveLintWorkerEntry() {
22848
22888
  const here = dirname19(fileURLToPath6(import.meta.url));
22849
22889
  for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
22850
22890
  const candidate = join49(here, name);
22851
- if (existsSync31(candidate)) return candidate;
22891
+ if (existsSync30(candidate)) return candidate;
22852
22892
  }
22853
22893
  return void 0;
22854
22894
  }
@@ -22919,7 +22959,7 @@ async function runHyperframeLint(prepared, options = {}) {
22919
22959
  import { Worker as Worker3 } from "node:worker_threads";
22920
22960
  import { fileURLToPath as fileURLToPath7 } from "node:url";
22921
22961
  import { dirname as dirname20, join as join50 } from "node:path";
22922
- import { existsSync as existsSync32 } from "node:fs";
22962
+ import { existsSync as existsSync31 } from "node:fs";
22923
22963
  var DEFAULT_HEALTH_PORT = 9848;
22924
22964
  async function startHealthWorker(options = {}) {
22925
22965
  const log = options.logger ?? defaultLogger2();
@@ -22996,7 +23036,7 @@ function resolveWorkerEntry2() {
22996
23036
  const here = dirname20(fileURLToPath7(import.meta.url));
22997
23037
  const candidates = [join50(here, "healthWorkerThread.js"), join50(here, "healthWorkerThread.ts")];
22998
23038
  for (const candidate of candidates) {
22999
- if (existsSync32(candidate)) return candidate;
23039
+ if (existsSync31(candidate)) return candidate;
23000
23040
  }
23001
23041
  return void 0;
23002
23042
  }
@@ -23161,12 +23201,12 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
23161
23201
  const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
23162
23202
  if (confineOutput) {
23163
23203
  mkdirSync21(rendersDir, { recursive: true });
23164
- if (!isSafePath3(rendersDir, absoluteOutputPath)) {
23204
+ if (!isSafePath4(rendersDir, absoluteOutputPath)) {
23165
23205
  throw new Error("outputPath must be inside the renders directory");
23166
23206
  }
23167
23207
  }
23168
23208
  const outputDir = dirname21(absoluteOutputPath);
23169
- if (!existsSync33(outputDir)) mkdirSync21(outputDir, { recursive: true });
23209
+ if (!existsSync32(outputDir)) mkdirSync21(outputDir, { recursive: true });
23170
23210
  return { input, cleanupProjectDir, absoluteOutputPath };
23171
23211
  }
23172
23212
  function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
@@ -23234,22 +23274,22 @@ function resolveRenderRequestPolicy(options) {
23234
23274
  };
23235
23275
  }
23236
23276
  function isAllowedProjectPath(projectsDir, path) {
23237
- return isSafePath3(projectsDir, path) && !isSafePath3(resolveRenderDebugDir(), path);
23277
+ return isSafePath4(projectsDir, path) && !isSafePath4(resolveRenderDebugDir(), path);
23238
23278
  }
23239
23279
  function isAllowedEntryPath(policy, projectDir, path) {
23240
- return isSafePath3(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
23280
+ return isSafePath4(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
23241
23281
  }
23242
23282
  function prepareProjectDirectory(projectDir, options, policy) {
23243
23283
  const candidate = nonEmptyString(projectDir);
23244
23284
  if (!candidate) return null;
23245
23285
  const absProjectDir = policy ? resolve13(policy.projectsDir, candidate) : resolve13(candidate);
23246
23286
  const shown = policy ? candidate : absProjectDir;
23247
- if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync33(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
23287
+ if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync32(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
23248
23288
  return { error: `Project directory not found: ${shown}` };
23249
23289
  }
23250
23290
  const entry = options.entryFile || "index.html";
23251
23291
  const entryPath = resolve13(absProjectDir, entry);
23252
- if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync33(entryPath)) {
23292
+ if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync32(entryPath)) {
23253
23293
  return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
23254
23294
  }
23255
23295
  return { prepared: { input: { projectDir: absProjectDir, ...options } } };
@@ -23271,7 +23311,7 @@ async function resolveInlineRenderHtml(body) {
23271
23311
  function materializeInlineProject(html, options) {
23272
23312
  const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
23273
23313
  const tempProjectDir = mkdtempSync2(join51(tempRoot, "producer-project-"));
23274
- writeFileSync14(join51(tempProjectDir, "index.html"), html, "utf-8");
23314
+ writeFileSync13(join51(tempProjectDir, "index.html"), html, "utf-8");
23275
23315
  return {
23276
23316
  prepared: {
23277
23317
  input: { projectDir: tempProjectDir, ...options },
@@ -23347,7 +23387,7 @@ function publicPerfSummary(job) {
23347
23387
  return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
23348
23388
  }
23349
23389
  function outputFileSize(path) {
23350
- return existsSync33(path) ? statSync14(path).size : 0;
23390
+ return existsSync32(path) ? statSync14(path).size : 0;
23351
23391
  }
23352
23392
  function createBlockingProgressReporter(log, requestId) {
23353
23393
  let lastLoggedPct = -10;
@@ -23674,7 +23714,7 @@ function createRenderHandlers(options = {}) {
23674
23714
  if (!artifact) {
23675
23715
  return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
23676
23716
  }
23677
- if (!existsSync33(artifact.path)) {
23717
+ if (!existsSync32(artifact.path)) {
23678
23718
  store.delete(token);
23679
23719
  return c.json({ success: false, error: "Output artifact file missing" }, 404);
23680
23720
  }
@@ -23874,17 +23914,18 @@ import {
23874
23914
  } from "@hyperframes/engine";
23875
23915
  import {
23876
23916
  cpSync as cpSync3,
23877
- existsSync as existsSync34,
23917
+ existsSync as existsSync33,
23878
23918
  mkdirSync as mkdirSync22,
23879
23919
  readFileSync as readFileSync17,
23880
23920
  readdirSync as readdirSync12,
23881
23921
  rmSync as rmSync20,
23882
- statSync as statSync15,
23883
- writeFileSync as writeFileSync15
23922
+ statSync as statSync15
23884
23923
  } from "node:fs";
23924
+ import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
23885
23925
  import { basename as basename9, dirname as dirname22, join as join52 } from "node:path";
23886
23926
  import {
23887
23927
  appendRateCapArgs as appendRateCapArgs2,
23928
+ writeVideoConcatList,
23888
23929
  appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
23889
23930
  concatListInputArgs,
23890
23931
  describeFfmpegFailure as describeFfmpegFailure5,
@@ -23894,7 +23935,7 @@ import {
23894
23935
  resolveConfig as resolveConfig7,
23895
23936
  runFfmpeg as runFfmpeg8,
23896
23937
  appendSoftwareEncoderThreadsArg,
23897
- renameWithRetry as renameWithRetry11
23938
+ renameWithRetry as renameWithRetry10
23898
23939
  } from "@hyperframes/engine";
23899
23940
  import { fpsToFfmpegArg as fpsToFfmpegArg3 } from "@hyperframes/core";
23900
23941
  import { createStagingDir as createStagingDir7 } from "@hyperframes/core/atomic-file";
@@ -23930,7 +23971,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
23930
23971
  }
23931
23972
  const format = plan2.dimensions.format;
23932
23973
  const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
23933
- if (!existsSync34(dirname22(outputPath))) {
23974
+ if (!existsSync33(dirname22(outputPath))) {
23934
23975
  mkdirSync22(dirname22(outputPath), { recursive: true });
23935
23976
  }
23936
23977
  const workDir = createStagingDir7(dirname22(outputPath), `${basename9(outputPath)}.assemble-work-`);
@@ -23954,9 +23995,9 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
23954
23995
  try {
23955
23996
  const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
23956
23997
  const finalPath = join52(workDir, `output.${format}`);
23957
- const audio = audioPath !== null && existsSync34(audioPath) ? audioPath : null;
23998
+ const audio = audioPath !== null && existsSync33(audioPath) ? audioPath : null;
23958
23999
  await writeJoined(ctx, videoSources, audio, finalPath);
23959
- renameWithRetry11(finalPath, outputPath);
24000
+ renameWithRetry10(finalPath, outputPath);
23960
24001
  log.info("[assemble] stage timings", {
23961
24002
  ...stageMs,
23962
24003
  chunks: chunkPaths.length,
@@ -23972,7 +24013,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
23972
24013
  });
23973
24014
  }
23974
24015
  }
23975
- const fileSize = existsSync34(outputPath) ? statSync15(outputPath).size : 0;
24016
+ const fileSize = existsSync33(outputPath) ? statSync15(outputPath).size : 0;
23976
24017
  return {
23977
24018
  ...referenceBackgroundResult8(plan2[REFERENCE_BACKGROUND_FIELD6]),
23978
24019
  outputPath,
@@ -23984,13 +24025,13 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
23984
24025
  function readAssemblePlan(planDir, chunkPaths) {
23985
24026
  const planJsonPath = join52(planDir, "plan.json");
23986
24027
  const chunksJsonPath = join52(planDir, "meta", "chunks.json");
23987
- if (!existsSync34(planJsonPath)) {
24028
+ if (!existsSync33(planJsonPath)) {
23988
24029
  throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
23989
24030
  }
23990
24031
  const plan2 = JSON.parse(readFileSync17(planJsonPath, "utf-8"));
23991
24032
  readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
23992
24033
  validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
23993
- if (!existsSync34(chunksJsonPath)) {
24034
+ if (!existsSync33(chunksJsonPath)) {
23994
24035
  throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
23995
24036
  }
23996
24037
  const chunks = JSON.parse(readFileSync17(chunksJsonPath, "utf-8"));
@@ -24005,14 +24046,18 @@ function readAssemblePlan(planDir, chunkPaths) {
24005
24046
  }
24006
24047
  }
24007
24048
  for (const path of chunkPaths.flat()) {
24008
- if (!existsSync34(path)) {
24049
+ if (!existsSync33(path)) {
24009
24050
  throw new Error(`[assemble] chunk path does not exist: ${path}`);
24010
24051
  }
24011
24052
  }
24012
24053
  return plan2;
24013
24054
  }
24014
24055
  function videoInputArgs(ctx, videoSources) {
24015
- return videoSources.length === 1 ? ["-i", videoSources[0]] : concatDemuxerInput(videoSources, ctx.workDir, ctx.fpsArg);
24056
+ return videoSources.length === 1 ? [
24057
+ ...localContainerInputArgs2(ctx.format === "webm" ? "matroska" : "mov"),
24058
+ "-i",
24059
+ videoSources[0]
24060
+ ] : ["-r", ctx.fpsArg, ...concatListInputArgs(writeVideoConcatList(ctx.workDir, videoSources))];
24016
24061
  }
24017
24062
  function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
24018
24063
  const args = [
@@ -24066,8 +24111,9 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
24066
24111
  "audioMs",
24067
24112
  () => padOrTrimAudioToVideoFrameCount({
24068
24113
  videoPath: videoSources[0],
24069
- probeVideoFrameInfo: () => probeJoinedFrameInfo(videoSources, ctx.fps, ctx.signal),
24114
+ probeVideoFrameInfo: () => probeJoinedFrameInfo(videoSources, ctx),
24070
24115
  audioPath,
24116
+ audioContainer: "mov",
24071
24117
  outputPath: paddedAudioPath,
24072
24118
  signal: ctx.signal,
24073
24119
  timeoutMs: ctx.timeout
@@ -24090,6 +24136,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
24090
24136
  ctx.signal,
24091
24137
  {
24092
24138
  audioCodec: "aac",
24139
+ audioContainer: "mov",
24093
24140
  ffmpegProcessTimeout: ctx.timeout,
24094
24141
  videoInputArgs: videoInputArgs(ctx, videoSources)
24095
24142
  },
@@ -24100,21 +24147,16 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
24100
24147
  throw encoderFailureError("[assemble] audio mux failed", muxResult);
24101
24148
  }
24102
24149
  }
24103
- function concatDemuxerInput(chunkPaths, workDir, fpsArg) {
24104
- const listPath = join52(workDir, "concat-list.txt");
24105
- const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
24106
- writeFileSync15(listPath, `${body}
24107
- `, "utf-8");
24108
- return ["-r", fpsArg, ...concatListInputArgs(listPath)];
24109
- }
24110
- async function probeJoinedFrameInfo(videoPaths, fps, signal) {
24150
+ async function probeJoinedFrameInfo(videoPaths, ctx) {
24111
24151
  const infos = await Promise.all(
24112
- videoPaths.map((path) => defaultProbeVideoFrameInfo(path, signal))
24152
+ videoPaths.map(
24153
+ (path) => defaultProbeVideoFrameInfo(path, ctx.signal, ctx.format === "webm" ? "matroska" : "mov")
24154
+ )
24113
24155
  );
24114
24156
  return {
24115
24157
  frameCount: infos.reduce((sum2, info) => sum2 + info.frameCount, 0),
24116
- fpsNum: fps.num,
24117
- fpsDen: fps.den
24158
+ fpsNum: ctx.fps.num,
24159
+ fpsDen: ctx.fps.den
24118
24160
  };
24119
24161
  }
24120
24162
  async function runAssembleFfmpeg(args, step, signal, timeout) {
@@ -24144,7 +24186,7 @@ function planFormat(planDir) {
24144
24186
  }
24145
24187
  function lockedAudio(planDir) {
24146
24188
  const encoderJsonPath = join52(planDir, "meta", "encoder.json");
24147
- if (!existsSync34(encoderJsonPath)) return {};
24189
+ if (!existsSync33(encoderJsonPath)) return {};
24148
24190
  return JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
24149
24191
  }
24150
24192
  function readCfrEncoder(planDir, format) {
@@ -24154,7 +24196,7 @@ function readCfrEncoder(planDir, format) {
24154
24196
  );
24155
24197
  }
24156
24198
  const encoderJsonPath = join52(planDir, "meta", "encoder.json");
24157
- if (!existsSync34(encoderJsonPath)) {
24199
+ if (!existsSync33(encoderJsonPath)) {
24158
24200
  throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
24159
24201
  }
24160
24202
  const encoderJson = JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
@@ -24166,7 +24208,7 @@ function readCfrEncoder(planDir, format) {
24166
24208
  return encoderJson;
24167
24209
  }
24168
24210
  function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
24169
- if (existsSync34(outputPath)) rmSync20(outputPath, { recursive: true, force: true });
24211
+ if (existsSync33(outputPath)) rmSync20(outputPath, { recursive: true, force: true });
24170
24212
  mkdirSync22(outputPath, { recursive: true });
24171
24213
  let globalIdx = 0;
24172
24214
  for (const chunkDir of chunkPaths) {
@@ -24190,7 +24232,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
24190
24232
  `[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
24191
24233
  );
24192
24234
  }
24193
- if (audioPath !== null && existsSync34(audioPath)) {
24235
+ if (audioPath !== null && existsSync33(audioPath)) {
24194
24236
  const sidecar = join52(outputPath, MIXED_AUDIO_FILENAME4);
24195
24237
  cpSync3(audioPath, sidecar);
24196
24238
  }