@hyperframes/producer 0.9.69 → 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.
@@ -18,11 +18,11 @@ function requireOutputDimensions(expected, width, height) {
18
18
 
19
19
  // src/server.ts
20
20
  import {
21
- existsSync as existsSync26,
21
+ existsSync as existsSync25,
22
22
  mkdirSync as mkdirSync13,
23
23
  statSync as statSync12,
24
24
  mkdtempSync,
25
- writeFileSync as writeFileSync8,
25
+ writeFileSync as writeFileSync7,
26
26
  rmSync as rmSync13,
27
27
  createReadStream as createReadStream4
28
28
  } from "node:fs";
@@ -39,17 +39,17 @@ import {
39
39
  REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD3,
40
40
  referenceBackgroundResult as referenceBackgroundResult5
41
41
  } from "@hyperframes/engine";
42
- import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
42
+ import { isSafePath as isSafePath4 } from "@hyperframes/core/safe-path";
43
43
 
44
44
  // src/services/renderOrchestrator.ts
45
45
  import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
46
46
  import {
47
- existsSync as existsSync22,
47
+ existsSync as existsSync21,
48
48
  mkdirSync as mkdirSync12,
49
49
  readdirSync as readdirSync6,
50
50
  rmSync as rmSync12,
51
51
  statSync as statSync10,
52
- writeFileSync as writeFileSync7,
52
+ writeFileSync as writeFileSync6,
53
53
  copyFileSync as copyFileSync5,
54
54
  appendFileSync
55
55
  } from "fs";
@@ -2624,7 +2624,7 @@ function replanAfterFailure(plan, failure) {
2624
2624
  }
2625
2625
 
2626
2626
  // src/services/render/stages/captureSegmentedStage.ts
2627
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
2627
+ import { existsSync as existsSync7, mkdirSync as mkdirSync4, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
2628
2628
  import { join as join12 } from "node:path";
2629
2629
  import {
2630
2630
  captureFrameToBuffer as captureFrameToBuffer2,
@@ -4356,16 +4356,25 @@ function createSegmentQueue(slices) {
4356
4356
  // src/services/render/segmentManifest.ts
4357
4357
  import { createHash as createHash2, createHmac, timingSafeEqual } from "node:crypto";
4358
4358
  import {
4359
+ closeSync as closeSync4,
4360
+ constants as constants3,
4359
4361
  createReadStream as createReadStream2,
4360
- existsSync as existsSync7,
4362
+ fstatSync as fstatSync3,
4361
4363
  lstatSync as lstatSync3,
4362
4364
  mkdirSync as mkdirSync3,
4363
- readFileSync as readFileSync4,
4364
- writeFileSync as writeFileSync3
4365
+ openSync as openSync4,
4366
+ readFileSync as readFileSync4
4365
4367
  } from "node:fs";
4366
4368
  import { join as join10 } from "node:path";
4369
+ import {
4370
+ assertPrivateCachePath,
4371
+ ensurePrivateCacheDir,
4372
+ hyperframesCacheDir
4373
+ } from "@hyperframes/core/cache-dir";
4374
+ import { isSafePath as isSafePath2, realpath } from "@hyperframes/core/safe-path";
4375
+ import { isPathInside as isPathInside3 } from "@hyperframes/parsers/asset-paths";
4367
4376
  import { previewToken } from "@hyperframes/core/preview-proof";
4368
- import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
4377
+ import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
4369
4378
  var MANIFEST_FILENAME = "segments.json";
4370
4379
  function computeSegmentPlanHash(input) {
4371
4380
  const ordered = [
@@ -4391,8 +4400,20 @@ function computeSegmentPlanHash(input) {
4391
4400
  if (delivery.some((v) => v !== "")) ordered.push(...delivery.map(String));
4392
4401
  return createHash2("sha256").update(ordered.join(" ")).digest("hex").slice(0, 16);
4393
4402
  }
4394
- function segmentDirFor(projectRendersDir, planHash) {
4395
- return join10(projectRendersDir, ".hf-segments", planHash);
4403
+ function segmentDirFor(projectDir, planHash) {
4404
+ const root = hyperframesCacheDir();
4405
+ const projectKey = createHash2("sha256").update(realpath(projectDir)).digest("hex");
4406
+ const parent = join10(root, "segments", projectKey);
4407
+ const dir = join10(parent, planHash);
4408
+ if (isPathInside3(root, projectDir) || isSafePath2(projectDir, root) || isSafePath2(projectDir, parent) || isSafePath2(projectDir, dir)) {
4409
+ throw new Error("Segmented capture requires HYPERFRAMES_CACHE_DIR outside the project.");
4410
+ }
4411
+ assertPrivateCachePath(root, root);
4412
+ ensurePrivateCacheDir(parent, root);
4413
+ if (!isSafePath2(parent, dir) || lstatSync3(dir, { throwIfNoEntry: false })?.isSymbolicLink()) {
4414
+ throw new Error("Invalid segment cache directory");
4415
+ }
4416
+ return dir;
4396
4417
  }
4397
4418
  function hasNumber(value, key) {
4398
4419
  return key in value && typeof Reflect.get(value, key) === "number";
@@ -4411,12 +4432,22 @@ function isManifest(value) {
4411
4432
  }
4412
4433
  function readSegmentManifest(segmentDir) {
4413
4434
  const path = join10(segmentDir, MANIFEST_FILENAME);
4414
- if (!existsSync7(path)) return null;
4435
+ let fd;
4415
4436
  try {
4416
- const parsed = JSON.parse(readFileSync4(path, "utf-8"));
4437
+ fd = openSync4(
4438
+ path,
4439
+ constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0)
4440
+ );
4441
+ const opened = fstatSync3(fd);
4442
+ if (!opened.isFile() || opened.nlink !== 1) return null;
4443
+ const named = lstatSync3(path);
4444
+ if (!named.isFile() || named.dev !== opened.dev || named.ino !== opened.ino) return null;
4445
+ const parsed = JSON.parse(readFileSync4(fd, "utf-8"));
4417
4446
  return isManifest(parsed) ? parsed : null;
4418
4447
  } catch {
4419
4448
  return null;
4449
+ } finally {
4450
+ if (fd !== void 0) closeSync4(fd);
4420
4451
  }
4421
4452
  }
4422
4453
  function segmentManifestKey(token = previewToken()) {
@@ -4449,9 +4480,11 @@ async function hashSegmentFile(path) {
4449
4480
  }
4450
4481
  function writeSegmentManifest(segmentDir, manifest, key) {
4451
4482
  mkdirSync3(segmentDir, { recursive: true });
4452
- const tmp = join10(segmentDir, `${MANIFEST_FILENAME}.${process.pid}.tmp`);
4453
- writeFileSync3(tmp, JSON.stringify(signSegmentManifest(manifest, key), null, 2), "utf-8");
4454
- renameWithRetry2(tmp, join10(segmentDir, MANIFEST_FILENAME));
4483
+ replaceFileAtomically(
4484
+ join10(segmentDir, MANIFEST_FILENAME),
4485
+ JSON.stringify(signSegmentManifest(manifest, key), null, 2),
4486
+ 384
4487
+ );
4455
4488
  }
4456
4489
  async function probeSegmentFrameCount(path, probe) {
4457
4490
  try {
@@ -4471,19 +4504,27 @@ function plannedSlice(entry, plan) {
4471
4504
  }
4472
4505
  return slice;
4473
4506
  }
4474
- function isPlainFileOfSize(path, bytes) {
4475
- const stat = lstatSync3(path, { throwIfNoEntry: false });
4476
- return stat !== void 0 && stat.isFile() && stat.size > 0 && stat.size === bytes;
4507
+ async function matchesSegmentFile(path, entry) {
4508
+ try {
4509
+ const stat = lstatSync3(path, { throwIfNoEntry: false });
4510
+ if (!stat?.isFile() || stat.nlink !== 1 || stat.size <= 0 || stat.size !== entry.bytes) {
4511
+ return false;
4512
+ }
4513
+ return await hashSegmentFile(path) === entry.sha256;
4514
+ } catch {
4515
+ return false;
4516
+ }
4477
4517
  }
4478
4518
  async function validateCompletedSegments(manifest, check) {
4479
4519
  const ok = /* @__PURE__ */ new Set();
4480
- if (manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key)) return ok;
4520
+ if (manifest.totalFrames !== check.totalFrames || manifest.segmentFrames !== check.segmentFrames || manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key))
4521
+ return ok;
4522
+ const plan = planSegments(check.totalFrames, check.segmentFrames);
4481
4523
  for (const entry of manifest.completed) {
4482
- const slice = plannedSlice(entry, check.plan);
4524
+ const slice = plannedSlice(entry, plan);
4483
4525
  if (!slice) continue;
4484
4526
  const path = segmentOutputPath(check.segmentDir, slice.index);
4485
- if (!isPlainFileOfSize(path, entry.bytes)) continue;
4486
- if (await hashSegmentFile(path) !== entry.sha256) continue;
4527
+ if (entry.path !== path || !await matchesSegmentFile(path, entry)) continue;
4487
4528
  const frames = await check.probeFrames(path);
4488
4529
  if (frames !== slice.endFrame - slice.startFrame) continue;
4489
4530
  ok.add(slice.index);
@@ -5374,6 +5415,7 @@ async function captureSegment(ctx, segment) {
5374
5415
  }
5375
5416
  async function captureSegmentToEncoder(ctx, segment) {
5376
5417
  const segmentPath = segmentOutputPath(ctx.segmentDir, segment.index);
5418
+ rmSync6(segmentPath, { force: true });
5377
5419
  let encoder;
5378
5420
  try {
5379
5421
  encoder = await ctx.spawnEncoder(
@@ -5402,8 +5444,8 @@ async function captureSegmentToEncoder(ctx, segment) {
5402
5444
  path: segmentPath,
5403
5445
  // Recorded so resume can prove the file on disk is the one that
5404
5446
  // finished; absent only in unit tests, whose fake encoder writes none.
5405
- bytes: existsSync8(segmentPath) ? statSync4(segmentPath).size : 0,
5406
- sha256: existsSync8(segmentPath) ? await hashSegmentFile(segmentPath) : ""
5447
+ bytes: existsSync7(segmentPath) ? statSync4(segmentPath).size : 0,
5448
+ sha256: existsSync7(segmentPath) ? await hashSegmentFile(segmentPath) : ""
5407
5449
  });
5408
5450
  return encodeResult;
5409
5451
  } finally {
@@ -7066,7 +7108,7 @@ function countAuthoredTimedClips(html) {
7066
7108
  }
7067
7109
 
7068
7110
  // src/services/render/stages/compileStage.ts
7069
- import { existsSync as existsSync13, writeFileSync as writeFileSync5 } from "node:fs";
7111
+ import { existsSync as existsSync12, writeFileSync as writeFileSync4 } from "node:fs";
7070
7112
  import { join as join22, relative as relative4 } from "node:path";
7071
7113
  import { privateCacheRoot } from "@hyperframes/engine";
7072
7114
  import { suggestMatchingPreset } from "@hyperframes/core";
@@ -7078,7 +7120,7 @@ import { statSync as statSync6 } from "node:fs";
7078
7120
  var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
7079
7121
  var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
7080
7122
  var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
7081
- var MAX_EXPANDED_COMPOSITION_BYTES = 2 * MAX_COMPOSITION_HTML_BYTES;
7123
+ var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
7082
7124
  var MAX_COMPOSITION_MOUNTS = 1e4;
7083
7125
  var CompositionTooLargeError = class extends Error {
7084
7126
  constructor(message, publicMetadata) {
@@ -7175,12 +7217,12 @@ import {
7175
7217
  stylesheetLinkMatches
7176
7218
  } from "@hyperframes/parsers/css-url-scans";
7177
7219
  import { createHash as createHash6 } from "node:crypto";
7178
- import { createReadStream as createReadStream3, existsSync as existsSync12, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
7220
+ import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
7179
7221
  import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
7180
7222
  import { parseHTML as parseHTML5 } from "linkedom";
7181
7223
 
7182
7224
  // src/services/bundledScripts.ts
7183
- import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
7225
+ import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
7184
7226
  import { join as join17 } from "node:path";
7185
7227
  import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
7186
7228
  var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
@@ -7188,7 +7230,7 @@ function bundledScript(url) {
7188
7230
  const dir = process.env[GSAP_VENDOR_DIR_ENV];
7189
7231
  if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
7190
7232
  const file = join17(dir, "gsap.min.js");
7191
- return existsSync9(file) ? readFileSync5(file) : null;
7233
+ return existsSync8(file) ? readFileSync5(file) : null;
7192
7234
  }
7193
7235
 
7194
7236
  // src/services/htmlCompiler.ts
@@ -7446,7 +7488,7 @@ import {
7446
7488
 
7447
7489
  // src/services/animatedGifPrep.ts
7448
7490
  import { createHash as createHash4 } from "node:crypto";
7449
- import { copyFileSync as copyFileSync2, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
7491
+ import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
7450
7492
  import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
7451
7493
  import { parseHTML as parseHTML3 } from "linkedom";
7452
7494
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
@@ -7454,7 +7496,7 @@ import {
7454
7496
  DEFAULT_VP9_CPU_USED,
7455
7497
  isPrivateUnderAssetRoots,
7456
7498
  runFfmpeg as runFfmpeg2,
7457
- renameWithRetry as renameWithRetry3,
7499
+ renameWithRetry as renameWithRetry2,
7458
7500
  urlInputArgs as urlInputArgs2
7459
7501
  } from "@hyperframes/engine";
7460
7502
  import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
@@ -7492,7 +7534,7 @@ function resolveLocalImageSourcePath(src, options) {
7492
7534
  const { basePath } = splitUrlSuffix(trimmed);
7493
7535
  const normalizedBase = normalizeRelPath(basePath);
7494
7536
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
7495
- if (mapped && existsSync10(mapped)) return mapped;
7537
+ if (mapped && existsSync9(mapped)) return mapped;
7496
7538
  if (isHttpUrl(trimmed)) return null;
7497
7539
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
7498
7540
  const candidates = [
@@ -7501,7 +7543,7 @@ function resolveLocalImageSourcePath(src, options) {
7501
7543
  ];
7502
7544
  const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
7503
7545
  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));
7504
- return candidates.find((candidate) => allowed(candidate) && existsSync10(candidate)) ?? null;
7546
+ return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
7505
7547
  }
7506
7548
  function isUsableFile(path) {
7507
7549
  try {
@@ -7613,10 +7655,10 @@ async function runAnimatedGifTranscode(request) {
7613
7655
  throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
7614
7656
  }
7615
7657
  async function ensurePreparedWebm(input) {
7616
- if (!existsSync10(dirname6(input.cachePath))) {
7658
+ if (!existsSync9(dirname6(input.cachePath))) {
7617
7659
  mkdirSync7(dirname6(input.cachePath), { recursive: true });
7618
7660
  }
7619
- if (!existsSync10(dirname6(input.outputPath))) {
7661
+ if (!existsSync9(dirname6(input.outputPath))) {
7620
7662
  mkdirSync7(dirname6(input.outputPath), { recursive: true });
7621
7663
  }
7622
7664
  if (!isUsableFile(input.cachePath)) {
@@ -7639,7 +7681,7 @@ async function ensurePreparedWebm(input) {
7639
7681
  throw new Error("Animated GIF transcode produced an empty output");
7640
7682
  }
7641
7683
  if (!isUsableFile(input.cachePath)) {
7642
- renameWithRetry3(tmpPath, input.cachePath);
7684
+ renameWithRetry2(tmpPath, input.cachePath);
7643
7685
  } else {
7644
7686
  rmSync9(tmpPath, { force: true });
7645
7687
  }
@@ -7763,19 +7805,19 @@ async function prepareAnimatedGifInputs(html, options) {
7763
7805
  // src/services/heifImagePrep.ts
7764
7806
  import { createHash as createHash5 } from "node:crypto";
7765
7807
  import {
7766
- closeSync as closeSync4,
7808
+ closeSync as closeSync5,
7767
7809
  copyFileSync as copyFileSync3,
7768
7810
  mkdirSync as mkdirSync8,
7769
- openSync as openSync4,
7811
+ openSync as openSync5,
7770
7812
  readFileSync as readFileSync7,
7771
7813
  readSync as readSync3,
7772
7814
  rmSync as rmSync10,
7773
7815
  statSync as statSync8,
7774
- writeFileSync as writeFileSync4
7816
+ writeFileSync as writeFileSync3
7775
7817
  } from "node:fs";
7776
7818
  import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
7777
7819
  import { parseHTML as parseHTML4 } from "linkedom";
7778
- import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
7820
+ import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
7779
7821
 
7780
7822
  // src/services/heifRotation.ts
7781
7823
  function* boxes(buf, start, end) {
@@ -7922,13 +7964,13 @@ function isHeifBytes(head) {
7922
7964
  function readHead(path) {
7923
7965
  let fd;
7924
7966
  try {
7925
- fd = openSync4(path, "r");
7967
+ fd = openSync5(path, "r");
7926
7968
  const buf = Buffer.alloc(4096);
7927
7969
  return buf.subarray(0, readSync3(fd, buf, 0, buf.length, 0));
7928
7970
  } catch {
7929
7971
  return null;
7930
7972
  } finally {
7931
- if (fd !== void 0) closeSync4(fd);
7973
+ if (fd !== void 0) closeSync5(fd);
7932
7974
  }
7933
7975
  }
7934
7976
  async function probeJson(path, withGroups) {
@@ -8027,14 +8069,14 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
8027
8069
  const inlinePath = `${tmpPath}.heic`;
8028
8070
  const inputPath = source.path ?? inlinePath;
8029
8071
  try {
8030
- if (!source.path) writeFileSync4(inlinePath, source.bytes);
8072
+ if (!source.path) writeFileSync3(inlinePath, source.bytes);
8031
8073
  await (options.transcode ?? convertHeifToJpeg)({
8032
8074
  inputPath,
8033
8075
  outputPath: tmpPath,
8034
8076
  timeoutMs: options.timeoutMs
8035
8077
  });
8036
8078
  if (!isUsableFile2(tmpPath)) throw new Error("conversion produced an empty file");
8037
- renameWithRetry4(tmpPath, cachePath);
8079
+ renameWithRetry3(tmpPath, cachePath);
8038
8080
  } catch (error) {
8039
8081
  const reason = error instanceof Error ? error.message : String(error);
8040
8082
  throw TOOL_FAILURE_RE.test(reason) ? new HeifToolUnavailableError(source.label, reason) : new HeifImageConversionError(source.label, reason);
@@ -8095,7 +8137,7 @@ import {
8095
8137
  import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
8096
8138
 
8097
8139
  // src/services/assetMediaType.ts
8098
- import { existsSync as existsSync11 } from "node:fs";
8140
+ import { existsSync as existsSync10 } from "node:fs";
8099
8141
  import { dirname as dirname8, join as join20 } from "node:path";
8100
8142
  import {
8101
8143
  fingerprintElementId,
@@ -8208,7 +8250,7 @@ async function preflightCompositionAssetMediaTypes(input) {
8208
8250
  input.projectDir,
8209
8251
  input.compiledDir
8210
8252
  );
8211
- if (!existsSync11(resolvedPath)) continue;
8253
+ if (!existsSync10(resolvedPath)) continue;
8212
8254
  byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
8213
8255
  }
8214
8256
  const mismatches = [];
@@ -8505,7 +8547,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
8505
8547
  let filePath = src;
8506
8548
  if (isHttpUrl(src)) {
8507
8549
  const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
8508
- if (!existsSync12(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
8550
+ if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
8509
8551
  try {
8510
8552
  filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
8511
8553
  onTelemetry: logRemoteDownloadTelemetry
@@ -8524,7 +8566,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
8524
8566
  return { duration: null, resolvedPath: filePath };
8525
8567
  }
8526
8568
  }
8527
- if (!isHttpUrl(filePath) && !existsSync12(filePath)) {
8569
+ if (!isHttpUrl(filePath) && !existsSync11(filePath)) {
8528
8570
  return { duration: null, resolvedPath: filePath };
8529
8571
  }
8530
8572
  const withSrcContext = (error) => {
@@ -9156,7 +9198,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
9156
9198
  return null;
9157
9199
  }
9158
9200
  const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
9159
- if (!onShare && !existsSync12(absPath)) return null;
9201
+ if (!onShare && !existsSync11(absPath)) return null;
9160
9202
  const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
9161
9203
  if (refusal) {
9162
9204
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
@@ -9209,7 +9251,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
9209
9251
  var REMOTE_MEDIA_SUBDIR = "_remote_media";
9210
9252
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
9211
9253
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
9212
- if (!existsSync12(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
9254
+ if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
9213
9255
  const urlToLocal = /* @__PURE__ */ new Map();
9214
9256
  await Promise.all(
9215
9257
  [...urlSet].map(async (url) => {
@@ -9395,13 +9437,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
9395
9437
  const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
9396
9438
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
9397
9439
  const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
9398
- if (!isPathInside(sheet, projectDir) || !existsSync12(sheet)) continue;
9440
+ if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
9399
9441
  for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
9400
9442
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
9401
9443
  const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
9402
9444
  const path = decodedUrlPath(url);
9403
9445
  const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname9(sheet), path);
9404
- return isPathInside(file, projectDir) && existsSync12(file);
9446
+ return isPathInside(file, projectDir) && existsSync11(file);
9405
9447
  });
9406
9448
  if (family && shipsFile) families.push(family);
9407
9449
  }
@@ -9550,7 +9592,7 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
9550
9592
  let gsapDist;
9551
9593
  const exists = (path) => {
9552
9594
  const file = resolve8(projectDir, path);
9553
- return !namesAnotherNetworkRoot2(projectDir, file) && existsSync12(file);
9595
+ return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
9554
9596
  };
9555
9597
  return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
9556
9598
  if (/^https?:\/\//i.test(src)) return full;
@@ -9786,7 +9828,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9786
9828
  for (const video of videos) {
9787
9829
  if (isHttpUrl(video.src)) continue;
9788
9830
  const videoPath = resolve8(projectDir, video.src);
9789
- if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync12(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
9831
+ if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
9790
9832
  continue;
9791
9833
  advised.add(videoPath);
9792
9834
  const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
@@ -10233,7 +10275,7 @@ function resolveEntryHtmlPath(input) {
10233
10275
  const rawEntry = readEntry(htmlPath);
10234
10276
  if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
10235
10277
  const projectIndexPath = join22(projectDir, "index.html");
10236
- if (!existsSync13(projectIndexPath)) {
10278
+ if (!existsSync12(projectIndexPath)) {
10237
10279
  throw new Error(
10238
10280
  `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
10239
10281
  );
@@ -10249,7 +10291,7 @@ function resolveEntryHtmlPath(input) {
10249
10291
  );
10250
10292
  }
10251
10293
  const wrapperPath = join22(workDir, "standalone-entry.html");
10252
- writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
10294
+ writeFileSync4(wrapperPath, standaloneHtml, "utf-8");
10253
10295
  log.info("Extracted standalone entry from index.html host context", { entryFile });
10254
10296
  return wrapperPath;
10255
10297
  }
@@ -11210,7 +11252,7 @@ function validateRenderDuration(input) {
11210
11252
  }
11211
11253
 
11212
11254
  // src/services/render/stages/extractVideosStage.ts
11213
- import { existsSync as existsSync14 } from "node:fs";
11255
+ import { existsSync as existsSync13 } from "node:fs";
11214
11256
  import { join as join24 } from "node:path";
11215
11257
  import {
11216
11258
  classifyVideoExtractionError,
@@ -11658,7 +11700,7 @@ function isPublicHttpsUrl(url) {
11658
11700
  }
11659
11701
  }
11660
11702
  function opensLocally(path, assetRoots) {
11661
- return existsSync14(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
11703
+ return existsSync13(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
11662
11704
  }
11663
11705
  function localProbeSource(src, input) {
11664
11706
  const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
@@ -11711,7 +11753,7 @@ async function appendVideoAudioFromProbe(input) {
11711
11753
  }
11712
11754
 
11713
11755
  // src/services/render/videoLayerPassthroughPlan.ts
11714
- import { existsSync as existsSync15 } from "node:fs";
11756
+ import { existsSync as existsSync14 } from "node:fs";
11715
11757
  import {
11716
11758
  buildVideoLayerInput,
11717
11759
  isHttpUrl as isHttpUrl4,
@@ -11779,7 +11821,7 @@ async function planVideoLayerPassthrough(input) {
11779
11821
  const { video } = q;
11780
11822
  if (isHttpUrl4(video.src)) return { reason: "remote_source" };
11781
11823
  const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
11782
- if (!existsSync15(path)) return { reason: "source_missing" };
11824
+ if (!existsSync14(path)) return { reason: "source_missing" };
11783
11825
  const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
11784
11826
  if ("reason" in layout) return layout;
11785
11827
  const layer = await buildVideoLayerInput(
@@ -11794,7 +11836,7 @@ async function planVideoLayerPassthrough(input) {
11794
11836
  }
11795
11837
 
11796
11838
  // src/services/render/stages/audioStage.ts
11797
- import { existsSync as existsSync17 } from "node:fs";
11839
+ import { existsSync as existsSync16 } from "node:fs";
11798
11840
  import { join as join27 } from "node:path";
11799
11841
  import {
11800
11842
  MIXED_AUDIO_FILENAME,
@@ -11806,16 +11848,17 @@ import {
11806
11848
  } from "@hyperframes/engine";
11807
11849
 
11808
11850
  // src/services/render/audioDeliveryLimit.ts
11809
- import { existsSync as existsSync16 } from "node:fs";
11851
+ import { existsSync as existsSync15 } from "node:fs";
11810
11852
  import { dirname as dirname11, join as join26 } from "node:path";
11811
11853
  import {
11812
11854
  applyAudioFxChain,
11813
11855
  describeFfmpegFailure as describeFfmpegFailure3,
11814
11856
  encodeAac as encodeAac2,
11815
- renameWithRetry as renameWithRetry6
11857
+ renameWithRetry as renameWithRetry5
11816
11858
  } from "@hyperframes/engine";
11817
11859
 
11818
11860
  // src/services/render/audioPadTrim.ts
11861
+ import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
11819
11862
  import { spawn } from "node:child_process";
11820
11863
  import { dirname as dirname10, join as join25 } from "node:path";
11821
11864
  import {
@@ -11826,7 +11869,7 @@ import {
11826
11869
  getFfprobeBinary,
11827
11870
  ManagedChildProcess,
11828
11871
  removeScratch,
11829
- renameWithRetry as renameWithRetry5,
11872
+ renameWithRetry as renameWithRetry4,
11830
11873
  runFfmpeg as runFfmpeg5,
11831
11874
  trackChildProcess,
11832
11875
  withPublicOnlyProxy
@@ -11967,10 +12010,10 @@ function sanitizeProbeFailure(reason, paths) {
11967
12010
  }
11968
12011
  async function padOrTrimAudioToVideoFrameCount(input) {
11969
12012
  const probeVideo = input.probeVideoFrameInfo ?? ((videoPath) => defaultProbeVideoFrameInfo(videoPath, input.signal));
11970
- const probeAudio = input.probeAudioInfo ?? defaultProbeAudioInfo;
12013
+ const probeAudio = input.probeAudioInfo ?? ((path, signal) => defaultProbeAudioInfo(path, signal, input.audioContainer));
11971
12014
  const timeoutMs = input.timeoutMs ?? DEFAULT_CONFIG.ffmpegProcessTimeout;
11972
12015
  const runner = input.runFfmpeg ?? ((args) => defaultRunFfmpeg(args, timeoutMs, input.signal));
11973
- const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath);
12016
+ const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath, input.audioContainer);
11974
12017
  const probeTruePeak = input.probeAudioTruePeakDbfs ?? (input.runFfmpeg || input.encodeAac ? void 0 : (audioPath, signal) => measureTruePeakDbfs(audioPath, { timeoutMs, signal }));
11975
12018
  const [videoResult, audioResult] = await Promise.allSettled([
11976
12019
  probeVideo(input.videoPath),
@@ -12018,7 +12061,7 @@ async function padOrTrimAudioToVideoFrameCount(input) {
12018
12061
  );
12019
12062
  try {
12020
12063
  for (const step of plan.steps) {
12021
- const ffmpegResult = step.kind === "copy" ? await runner(step.args) : await encode(
12064
+ const ffmpegResult = step.kind === "copy" ? await runner([...localContainerInputArgs(input.audioContainer), ...step.args]) : await encode(
12022
12065
  input.sourcePath ?? input.audioPath,
12023
12066
  input.outputPath,
12024
12067
  targetDurationSeconds,
@@ -12102,7 +12145,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
12102
12145
  try {
12103
12146
  const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
12104
12147
  if (!result.success) throw new Error(result.error);
12105
- renameWithRetry5(cutPath, input.sourcePath, { copyFallback: true });
12148
+ renameWithRetry4(cutPath, input.sourcePath, { copyFallback: true });
12106
12149
  return true;
12107
12150
  } catch {
12108
12151
  removeScratch(input.sourcePath);
@@ -12129,7 +12172,7 @@ async function enforceAacTruePeak(input) {
12129
12172
  if (truePeakDbfs <= AAC_DELIVERY_TRUE_PEAK_DBFS) {
12130
12173
  if (measuredPath !== correctedPath) return { success: true };
12131
12174
  const sourceCut = await cutSource(input, scratchDir, attenuationDb);
12132
- renameWithRetry5(correctedPath, input.audioPath, { copyFallback: true });
12175
+ renameWithRetry4(correctedPath, input.audioPath, { copyFallback: true });
12133
12176
  const loweredDb = Number((-attenuationDb).toFixed(2));
12134
12177
  return sourceCut ? { success: true, loweredDb } : { success: true, loweredDb, sourceStale: true };
12135
12178
  }
@@ -12184,7 +12227,8 @@ function failResult(outputPath, target, source, error) {
12184
12227
  error
12185
12228
  };
12186
12229
  }
12187
- async function defaultProbeVideoFrameInfo(videoPath, signal) {
12230
+ async function defaultProbeVideoFrameInfo(videoPath, signal, container) {
12231
+ const inputArgs = localContainerInputArgs(container);
12188
12232
  const fastInfo = await runFfprobeJson(
12189
12233
  [
12190
12234
  "-v",
@@ -12195,6 +12239,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
12195
12239
  "stream=nb_frames,r_frame_rate",
12196
12240
  "-of",
12197
12241
  "json",
12242
+ ...inputArgs,
12198
12243
  "--",
12199
12244
  videoPath
12200
12245
  ],
@@ -12216,6 +12261,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
12216
12261
  "stream=nb_read_packets,r_frame_rate",
12217
12262
  "-of",
12218
12263
  "json",
12264
+ ...inputArgs,
12219
12265
  "--",
12220
12266
  videoPath
12221
12267
  ],
@@ -12238,8 +12284,8 @@ function parseFrameRate(rate) {
12238
12284
  }
12239
12285
  return { fpsNum, fpsDen };
12240
12286
  }
12241
- async function defaultProbeAudioInfo(audioPath, signal) {
12242
- const metadata = await extractAudioMetadata3(audioPath, { signal });
12287
+ async function defaultProbeAudioInfo(audioPath, signal, inputContainer) {
12288
+ const metadata = await extractAudioMetadata3(audioPath, { signal, inputContainer });
12243
12289
  return {
12244
12290
  durationSeconds: metadata.durationSeconds,
12245
12291
  sampleRate: metadata.sampleRate,
@@ -12250,9 +12296,9 @@ async function defaultProbeAudioInfo(audioPath, signal) {
12250
12296
  async function defaultRunFfmpeg(args, timeoutMs, signal) {
12251
12297
  return toStepResult(await runFfmpeg5(args, { signal, timeout: timeoutMs }), timeoutMs);
12252
12298
  }
12253
- function defaultAacEncoder(timeoutMs, signal, pcmSourcePath) {
12299
+ function defaultAacEncoder(timeoutMs, signal, pcmSourcePath, inputContainer) {
12254
12300
  return async (inputPath, outputPath, durationSeconds, filter) => {
12255
- const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1 };
12301
+ const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1, inputContainer };
12256
12302
  return toStepResult(
12257
12303
  await encodeAac(pcmSourcePath ?? inputPath, outputPath, durationSeconds, options),
12258
12304
  timeoutMs
@@ -12325,8 +12371,8 @@ async function limitDeliveryPeaks(input, deps = {
12325
12371
  measure: measureTruePeakDbfs,
12326
12372
  applyChain: applyAudioFxChain,
12327
12373
  encode: encodeAac2,
12328
- rename: renameWithRetry6,
12329
- sourceExists: existsSync16
12374
+ rename: renameWithRetry5,
12375
+ sourceExists: existsSync15
12330
12376
  }) {
12331
12377
  const { audioPath, sourcePath, signal, timeoutMs } = input;
12332
12378
  if (!deps.sourceExists(sourcePath)) return { success: true };
@@ -12422,7 +12468,7 @@ async function runAudioStageScoped(input) {
12422
12468
  );
12423
12469
  audioLoweredDb = guard.loweredDb;
12424
12470
  input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
12425
- if (input.keepDeliverySource && !guard.sourceStale && existsSync17(pcmSourcePath)) {
12471
+ if (input.keepDeliverySource && !guard.sourceStale && existsSync16(pcmSourcePath)) {
12426
12472
  deliverySourcePath = pcmSourcePath;
12427
12473
  }
12428
12474
  }
@@ -12551,7 +12597,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
12551
12597
  }
12552
12598
 
12553
12599
  // src/services/render/stages/captureStage.ts
12554
- import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
12600
+ import { existsSync as existsSync17, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
12555
12601
  import { join as join28 } from "node:path";
12556
12602
  import {
12557
12603
  classifyCaptureFailure as classifyCaptureFailure2,
@@ -12622,7 +12668,7 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
12622
12668
  }
12623
12669
  function measureCaptureFrameBytes(workDir, framesDir) {
12624
12670
  let total = sampleDirectoryBytes(framesDir);
12625
- if (!existsSync18(workDir)) return total;
12671
+ if (!existsSync17(workDir)) return total;
12626
12672
  for (const attempt of readdirSync4(workDir)) {
12627
12673
  if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
12628
12674
  total += sampleDirectoryBytes(join28(workDir, attempt));
@@ -12929,7 +12975,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
12929
12975
  }
12930
12976
 
12931
12977
  // src/services/render/stages/captureHdrStage.ts
12932
- import { existsSync as existsSync20, mkdirSync as mkdirSync10 } from "node:fs";
12978
+ import { existsSync as existsSync19, mkdirSync as mkdirSync10 } from "node:fs";
12933
12979
  import { join as join32 } from "node:path";
12934
12980
  import {
12935
12981
  closeCaptureSession as closeCaptureSession7,
@@ -13176,7 +13222,7 @@ import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
13176
13222
  import { dirname as dirname12, join as join30 } from "node:path";
13177
13223
  import { createRequire } from "node:module";
13178
13224
  import { usableCpuCount } from "@hyperframes/engine";
13179
- import { existsSync as existsSync19 } from "node:fs";
13225
+ import { existsSync as existsSync18 } from "node:fs";
13180
13226
  function resolveWorkerEntry(explicit) {
13181
13227
  if (explicit && explicit.length > 0) {
13182
13228
  return { path: explicit, isTs: explicit.endsWith(".ts") };
@@ -13188,7 +13234,7 @@ function resolveWorkerEntry(explicit) {
13188
13234
  }
13189
13235
  const moduleDir = dirname12(fileURLToPath3(import.meta.url));
13190
13236
  const jsPath = join30(moduleDir, "shaderTransitionWorker.js");
13191
- if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
13237
+ if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
13192
13238
  const tsPath = join30(moduleDir, "shaderTransitionWorker.ts");
13193
13239
  return { path: tsPath, isTs: true };
13194
13240
  }
@@ -13754,7 +13800,7 @@ async function runCaptureHdrStage(input) {
13754
13800
  }
13755
13801
  const debugDumpEnabled = process.env.KEEP_TEMP === "1";
13756
13802
  const debugDumpDir = debugDumpEnabled ? join32(framesDir, "debug-composite") : null;
13757
- if (debugDumpDir && !existsSync20(debugDumpDir)) {
13803
+ if (debugDumpDir && !existsSync19(debugDumpDir)) {
13758
13804
  mkdirSync10(debugDumpDir, { recursive: true });
13759
13805
  }
13760
13806
  const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
@@ -13913,13 +13959,13 @@ async function runCaptureHdrStage(input) {
13913
13959
  // src/services/render/stages/encodeStage.ts
13914
13960
  import {
13915
13961
  copyFileSync as copyFileSync4,
13916
- existsSync as existsSync21,
13962
+ existsSync as existsSync20,
13917
13963
  mkdirSync as mkdirSync11,
13918
13964
  readdirSync as readdirSync5,
13919
13965
  readFileSync as readFileSync9,
13920
13966
  rmSync as rmSync11,
13921
13967
  statSync as statSync9,
13922
- writeFileSync as writeFileSync6
13968
+ writeFileSync as writeFileSync5
13923
13969
  } from "node:fs";
13924
13970
  import { readFile as readFile2 } from "node:fs/promises";
13925
13971
  import { dirname as dirname13, join as join33 } from "node:path";
@@ -14015,7 +14061,7 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
14015
14061
  const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
14016
14062
  return gifEncodeFailure(startTime, outputPath, error);
14017
14063
  }
14018
- writeFileSync6(outputPath, gif);
14064
+ writeFileSync5(outputPath, gif);
14019
14065
  return null;
14020
14066
  }
14021
14067
  async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
@@ -14047,7 +14093,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
14047
14093
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
14048
14094
  if (failure) return failure;
14049
14095
  }
14050
- const fileSize = existsSync21(outputPath) ? statSync9(outputPath).size : 0;
14096
+ const fileSize = existsSync20(outputPath) ? statSync9(outputPath).size : 0;
14051
14097
  return {
14052
14098
  success: true,
14053
14099
  outputPath,
@@ -14216,7 +14262,7 @@ async function runEncodeStage(input) {
14216
14262
  const stage5Start = Date.now();
14217
14263
  if (isPngSequence) {
14218
14264
  const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
14219
- if (!existsSync21(outputPath)) mkdirSync11(outputPath, { recursive: true });
14265
+ if (!existsSync20(outputPath)) mkdirSync11(outputPath, { recursive: true });
14220
14266
  const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
14221
14267
  if (captured.length === 0) {
14222
14268
  throw new Error(
@@ -14227,7 +14273,7 @@ async function runEncodeStage(input) {
14227
14273
  const dst = join33(outputPath, formatExportFrameName(i, "png"));
14228
14274
  copyFileSync4(join33(framesDir, name), dst);
14229
14275
  });
14230
- if (hasAudio && audioOutputPath && existsSync21(audioOutputPath)) {
14276
+ if (hasAudio && audioOutputPath && existsSync20(audioOutputPath)) {
14231
14277
  copyFileSync4(audioOutputPath, join33(outputPath, MIXED_AUDIO_FILENAME2));
14232
14278
  log.info(
14233
14279
  `[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
@@ -14618,7 +14664,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
14618
14664
  let rangeStart = null;
14619
14665
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
14620
14666
  const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
14621
- const missing = !existsSync22(framePath) || statSync10(framePath).size <= 8;
14667
+ const missing = !existsSync21(framePath) || statSync10(framePath).size <= 8;
14622
14668
  if (missing && rangeStart === null) {
14623
14669
  rangeStart = frameIndex;
14624
14670
  } else if (!missing && rangeStart !== null) {
@@ -14751,7 +14797,7 @@ function countCapturedFrames(totalFrames, framesDir, frameExt) {
14751
14797
  let captured = 0;
14752
14798
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
14753
14799
  const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
14754
- if (existsSync22(framePath)) captured++;
14800
+ if (existsSync21(framePath)) captured++;
14755
14801
  }
14756
14802
  return captured;
14757
14803
  }
@@ -15432,7 +15478,7 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
15432
15478
  validateChromaSubsamplingConfig(job.config);
15433
15479
  const debugDir = resolveRenderDebugDir();
15434
15480
  const outputDir = dirname14(outputPath);
15435
- if (!existsSync22(outputDir)) mkdirSync12(outputDir, { recursive: true });
15481
+ if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
15436
15482
  const workDir = job.config.debug ? join34(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
15437
15483
  const pipelineStart = Date.now();
15438
15484
  const baseLog = job.config.logger ?? defaultLogger;
@@ -15589,7 +15635,7 @@ async function executeRenderPipeline(input) {
15589
15635
  job.startedAt = /* @__PURE__ */ new Date();
15590
15636
  assertNotAborted();
15591
15637
  assertConfiguredFfmpegBinariesExist();
15592
- if (!existsSync22(workDir)) mkdirSync12(workDir, { recursive: true });
15638
+ if (!existsSync21(workDir)) mkdirSync12(workDir, { recursive: true });
15593
15639
  if (job.config.debug) {
15594
15640
  log.info("[Render] Debug artifacts enabled", { workDir, logPath });
15595
15641
  }
@@ -15619,7 +15665,7 @@ async function executeRenderPipeline(input) {
15619
15665
  });
15620
15666
  const entryFile = job.config.entryFile || "index.html";
15621
15667
  const htmlPath = join34(projectDir, entryFile);
15622
- if (!existsSync22(htmlPath)) {
15668
+ if (!existsSync21(htmlPath)) {
15623
15669
  throw new Error(`Entry file not found: ${htmlPath}`);
15624
15670
  }
15625
15671
  assertNotAborted();
@@ -15987,7 +16033,7 @@ async function executeRenderPipeline(input) {
15987
16033
  throw new Error("File server failed to initialize before frame capture");
15988
16034
  }
15989
16035
  const framesDir = join34(workDir, "captured-frames");
15990
- if (!existsSync22(framesDir)) mkdirSync12(framesDir, { recursive: true });
16036
+ if (!existsSync21(framesDir)) mkdirSync12(framesDir, { recursive: true });
15991
16037
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
15992
16038
  code: "start_browsers"
15993
16039
  });
@@ -16884,29 +16930,8 @@ async function executeRenderPipeline(input) {
16884
16930
  pageMotionBlur: job.config.pageMotionBlur,
16885
16931
  captureQuality: captureOptions.quality
16886
16932
  });
16887
- const segmentDir = segmentDirFor(join34(projectDir, "renders"), segmentPlanHash);
16933
+ const segmentDir = segmentDirFor(projectDir, segmentPlanHash);
16888
16934
  const manifestKey = loadResumeKeyOrWarn(job.config.resumeSegments === true, log);
16889
- let completedSegments = /* @__PURE__ */ new Set();
16890
- if (job.config.resumeSegments === true) {
16891
- const existing = readSegmentManifest(segmentDir);
16892
- if (existing) {
16893
- completedSegments = await validateCompletedSegments(existing, {
16894
- expectedHash: segmentPlanHash,
16895
- segmentDir,
16896
- plan: planSegments(totalFrames, segmentFrames),
16897
- key: manifestKey,
16898
- probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
16899
- });
16900
- log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
16901
- segmentDir
16902
- });
16903
- }
16904
- if (completedSegments.size === 0) {
16905
- rmSync12(segmentDir, { recursive: true, force: true });
16906
- }
16907
- } else {
16908
- rmSync12(segmentDir, { recursive: true, force: true });
16909
- }
16910
16935
  const emptySegmentManifest = () => ({
16911
16936
  version: 1,
16912
16937
  planHash: segmentPlanHash,
@@ -16914,7 +16939,26 @@ async function executeRenderPipeline(input) {
16914
16939
  segmentFrames,
16915
16940
  completed: []
16916
16941
  });
16917
- let segmentManifest = readSegmentManifest(segmentDir) ?? emptySegmentManifest();
16942
+ let segmentManifest = emptySegmentManifest();
16943
+ let completedSegments = /* @__PURE__ */ new Set();
16944
+ const existing = job.config.resumeSegments ? readSegmentManifest(segmentDir) : null;
16945
+ if (existing) {
16946
+ completedSegments = await validateCompletedSegments(existing, {
16947
+ expectedHash: segmentPlanHash,
16948
+ segmentDir,
16949
+ totalFrames,
16950
+ segmentFrames,
16951
+ key: manifestKey,
16952
+ probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
16953
+ });
16954
+ segmentManifest.completed = existing.completed.filter(
16955
+ (entry) => completedSegments.has(entry.index)
16956
+ );
16957
+ log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
16958
+ segmentDir
16959
+ });
16960
+ }
16961
+ if (completedSegments.size === 0) rmSync12(segmentDir, { recursive: true, force: true });
16918
16962
  const invokeSegmented = () => {
16919
16963
  if (capturePlan.kind !== "sdr_segmented") {
16920
16964
  throw new Error(`Cannot invoke segmented stage with ${capturePlan.kind} plan`);
@@ -17431,7 +17475,7 @@ async function executeRenderPipeline(input) {
17431
17475
  })
17432
17476
  );
17433
17477
  const totalElapsed = Date.now() - pipelineStart;
17434
- const tmpPeakBytes = existsSync22(workDir) ? sampleDirectoryBytes(workDir) : 0;
17478
+ const tmpPeakBytes = existsSync21(workDir) ? sampleDirectoryBytes(workDir) : 0;
17435
17479
  recordTransientRetryObservability();
17436
17480
  observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
17437
17481
  const observabilitySummary = observability.summary({
@@ -17503,7 +17547,7 @@ async function executeRenderPipeline(input) {
17503
17547
  job.perfSummary = perfSummary;
17504
17548
  if (job.config.debug) {
17505
17549
  try {
17506
- writeFileSync7(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
17550
+ writeFileSync6(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
17507
17551
  } catch (err) {
17508
17552
  log.debug("Failed to write perf summary", {
17509
17553
  perfOutputPath,
@@ -17512,7 +17556,7 @@ async function executeRenderPipeline(input) {
17512
17556
  }
17513
17557
  }
17514
17558
  if (job.config.debug) {
17515
- if (!isPngSequence && !isHls && existsSync22(stagedOutputPath)) {
17559
+ if (!isPngSequence && !isHls && existsSync21(stagedOutputPath)) {
17516
17560
  const debugOutput = join34(workDir, `output${videoExt}`);
17517
17561
  copyFileSync5(stagedOutputPath, debugOutput);
17518
17562
  }
@@ -17628,13 +17672,13 @@ async function executeRenderPipeline(input) {
17628
17672
 
17629
17673
  // src/services/hyperframeLint.ts
17630
17674
  import {
17631
- existsSync as existsSync23,
17675
+ existsSync as existsSync22,
17632
17676
  readFileSync as readFileSync10,
17633
17677
  statSync as statSync11,
17634
- openSync as openSync5,
17635
- fstatSync as fstatSync3,
17636
- closeSync as closeSync5,
17637
- constants as constants3
17678
+ openSync as openSync6,
17679
+ fstatSync as fstatSync4,
17680
+ closeSync as closeSync6,
17681
+ constants as constants4
17638
17682
  } from "node:fs";
17639
17683
  import { resolve as resolve10, join as join35, relative as relative5, isAbsolute as isAbsolute4, sep as sep5, dirname as dirname15 } from "node:path";
17640
17684
  import { fileURLToPath as fileURLToPath5 } from "node:url";
@@ -17667,7 +17711,7 @@ function pickEntryFile(files, preferredEntryFile) {
17667
17711
  function readEntryHtml(filePath) {
17668
17712
  let fd;
17669
17713
  try {
17670
- fd = openSync5(filePath, constants3.O_RDONLY | constants3.O_NONBLOCK);
17714
+ fd = openSync6(filePath, constants4.O_RDONLY | constants4.O_NONBLOCK);
17671
17715
  } catch (error) {
17672
17716
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
17673
17717
  return null;
@@ -17675,10 +17719,10 @@ function readEntryHtml(filePath) {
17675
17719
  throw error;
17676
17720
  }
17677
17721
  try {
17678
- if (!fstatSync3(fd).isFile()) return null;
17722
+ if (!fstatSync4(fd).isFile()) return null;
17679
17723
  return readFileSync10(fd, "utf-8");
17680
17724
  } finally {
17681
- closeSync5(fd);
17725
+ closeSync6(fd);
17682
17726
  }
17683
17727
  }
17684
17728
  function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
@@ -17687,7 +17731,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
17687
17731
  }
17688
17732
  function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
17689
17733
  const absProjectDir = resolve10(projectDir);
17690
- if (!existsSync23(absProjectDir) || !statSync11(absProjectDir).isDirectory()) {
17734
+ if (!existsSync22(absProjectDir) || !statSync11(absProjectDir).isDirectory()) {
17691
17735
  return { error: `Project directory not found: ${absProjectDir}` };
17692
17736
  }
17693
17737
  const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
@@ -17778,7 +17822,7 @@ function resolveLintWorkerEntry() {
17778
17822
  const here = dirname15(fileURLToPath5(import.meta.url));
17779
17823
  for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
17780
17824
  const candidate = join35(here, name);
17781
- if (existsSync23(candidate)) return candidate;
17825
+ if (existsSync22(candidate)) return candidate;
17782
17826
  }
17783
17827
  return void 0;
17784
17828
  }
@@ -17849,7 +17893,7 @@ async function runHyperframeLint(prepared, options = {}) {
17849
17893
  import { Worker as Worker3 } from "node:worker_threads";
17850
17894
  import { fileURLToPath as fileURLToPath6 } from "node:url";
17851
17895
  import { dirname as dirname16, join as join36 } from "node:path";
17852
- import { existsSync as existsSync24 } from "node:fs";
17896
+ import { existsSync as existsSync23 } from "node:fs";
17853
17897
  var DEFAULT_HEALTH_PORT = 9848;
17854
17898
  async function startHealthWorker(options = {}) {
17855
17899
  const log = options.logger ?? defaultLogger2();
@@ -17926,7 +17970,7 @@ function resolveWorkerEntry2() {
17926
17970
  const here = dirname16(fileURLToPath6(import.meta.url));
17927
17971
  const candidates = [join36(here, "healthWorkerThread.js"), join36(here, "healthWorkerThread.ts")];
17928
17972
  for (const candidate of candidates) {
17929
- if (existsSync24(candidate)) return candidate;
17973
+ if (existsSync23(candidate)) return candidate;
17930
17974
  }
17931
17975
  return void 0;
17932
17976
  }
@@ -17971,14 +18015,14 @@ import {
17971
18015
  fpsToNumber as fpsToNumber9,
17972
18016
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
17973
18017
  } from "@hyperframes/core";
17974
- import { isSafePath as isSafePath2 } from "@hyperframes/core/safe-path";
18018
+ import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
17975
18019
  import {
17976
18020
  getEncoderPreset as getEncoderPreset4,
17977
18021
  keyframeIntervalToGopSize as keyframeIntervalToGopSize3,
17978
18022
  normalizeVp9CpuUsed,
17979
18023
  resolveConfig as resolveConfig3,
17980
18024
  declareContentAddressedUrl,
17981
- renameWithRetry as renameWithRetry8,
18025
+ renameWithRetry as renameWithRetry7,
17982
18026
  declareProbeFactsUrl
17983
18027
  } from "@hyperframes/engine";
17984
18028
 
@@ -18000,7 +18044,7 @@ import {
18000
18044
  // src/services/distributed/shared.ts
18001
18045
  import { execFile as execFileCallback } from "node:child_process";
18002
18046
  import { dirname as dirname17, join as join37 } from "node:path";
18003
- import { existsSync as existsSync25, readFileSync as readFileSync11 } from "node:fs";
18047
+ import { existsSync as existsSync24, readFileSync as readFileSync11 } from "node:fs";
18004
18048
  import { fileURLToPath as fileURLToPath7 } from "node:url";
18005
18049
  import { promisify as promisify2 } from "node:util";
18006
18050
  import {
@@ -18016,7 +18060,7 @@ function readProducerVersion() {
18016
18060
  let current = startDir;
18017
18061
  for (let i = 0; i < 10; i++) {
18018
18062
  const candidate = join37(current, "package.json");
18019
- if (existsSync25(candidate)) {
18063
+ if (existsSync24(candidate)) {
18020
18064
  try {
18021
18065
  const pkg = JSON.parse(readFileSync11(candidate, "utf-8"));
18022
18066
  if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
@@ -18092,7 +18136,7 @@ var FIELD_DELIMITER = Buffer.from([0]);
18092
18136
  import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
18093
18137
 
18094
18138
  // src/services/distributed/mp4Stitch.ts
18095
- import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
18139
+ import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
18096
18140
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
18097
18141
  var SCAN_BYTES = 64 * 1024;
18098
18142
 
@@ -18538,12 +18582,12 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
18538
18582
  const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
18539
18583
  if (confineOutput) {
18540
18584
  mkdirSync13(rendersDir, { recursive: true });
18541
- if (!isSafePath3(rendersDir, absoluteOutputPath)) {
18585
+ if (!isSafePath4(rendersDir, absoluteOutputPath)) {
18542
18586
  throw new Error("outputPath must be inside the renders directory");
18543
18587
  }
18544
18588
  }
18545
18589
  const outputDir = dirname18(absoluteOutputPath);
18546
- if (!existsSync26(outputDir)) mkdirSync13(outputDir, { recursive: true });
18590
+ if (!existsSync25(outputDir)) mkdirSync13(outputDir, { recursive: true });
18547
18591
  return { input, cleanupProjectDir, absoluteOutputPath };
18548
18592
  }
18549
18593
  function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
@@ -18611,22 +18655,22 @@ function resolveRenderRequestPolicy(options) {
18611
18655
  };
18612
18656
  }
18613
18657
  function isAllowedProjectPath(projectsDir, path) {
18614
- return isSafePath3(projectsDir, path) && !isSafePath3(resolveRenderDebugDir(), path);
18658
+ return isSafePath4(projectsDir, path) && !isSafePath4(resolveRenderDebugDir(), path);
18615
18659
  }
18616
18660
  function isAllowedEntryPath(policy, projectDir, path) {
18617
- return isSafePath3(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
18661
+ return isSafePath4(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
18618
18662
  }
18619
18663
  function prepareProjectDirectory(projectDir, options, policy) {
18620
18664
  const candidate = nonEmptyString(projectDir);
18621
18665
  if (!candidate) return null;
18622
18666
  const absProjectDir = policy ? resolve11(policy.projectsDir, candidate) : resolve11(candidate);
18623
18667
  const shown = policy ? candidate : absProjectDir;
18624
- if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync26(absProjectDir) || !statSync12(absProjectDir).isDirectory()) {
18668
+ if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync25(absProjectDir) || !statSync12(absProjectDir).isDirectory()) {
18625
18669
  return { error: `Project directory not found: ${shown}` };
18626
18670
  }
18627
18671
  const entry = options.entryFile || "index.html";
18628
18672
  const entryPath = resolve11(absProjectDir, entry);
18629
- if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync26(entryPath)) {
18673
+ if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync25(entryPath)) {
18630
18674
  return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
18631
18675
  }
18632
18676
  return { prepared: { input: { projectDir: absProjectDir, ...options } } };
@@ -18648,7 +18692,7 @@ async function resolveInlineRenderHtml(body) {
18648
18692
  function materializeInlineProject(html, options) {
18649
18693
  const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir4();
18650
18694
  const tempProjectDir = mkdtempSync(join39(tempRoot, "producer-project-"));
18651
- writeFileSync8(join39(tempProjectDir, "index.html"), html, "utf-8");
18695
+ writeFileSync7(join39(tempProjectDir, "index.html"), html, "utf-8");
18652
18696
  return {
18653
18697
  prepared: {
18654
18698
  input: { projectDir: tempProjectDir, ...options },
@@ -18724,7 +18768,7 @@ function publicPerfSummary(job) {
18724
18768
  return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
18725
18769
  }
18726
18770
  function outputFileSize(path) {
18727
- return existsSync26(path) ? statSync12(path).size : 0;
18771
+ return existsSync25(path) ? statSync12(path).size : 0;
18728
18772
  }
18729
18773
  function createBlockingProgressReporter(log, requestId) {
18730
18774
  let lastLoggedPct = -10;
@@ -19051,7 +19095,7 @@ function createRenderHandlers(options = {}) {
19051
19095
  if (!artifact) {
19052
19096
  return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
19053
19097
  }
19054
- if (!existsSync26(artifact.path)) {
19098
+ if (!existsSync25(artifact.path)) {
19055
19099
  store.delete(token);
19056
19100
  return c.json({ success: false, error: "Output artifact file missing" }, 404);
19057
19101
  }