@hyperframes/producer 0.9.37 → 0.9.38

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
@@ -67,7 +67,7 @@ import {
67
67
  referenceBackgroundResult,
68
68
  createReferenceBackgroundRecorder
69
69
  } from "@hyperframes/engine";
70
- import { join as join31, dirname as dirname13, resolve as resolve8 } from "path";
70
+ import { join as join32, dirname as dirname13, resolve as resolve8 } from "path";
71
71
  import { totalmem as totalmem2 } from "node:os";
72
72
  import { randomUUID } from "crypto";
73
73
  import { fileURLToPath as fileURLToPath4 } from "url";
@@ -756,7 +756,13 @@ function openRegularFile(filePath) {
756
756
  }
757
757
  }
758
758
  function createFileServer(options) {
759
- const { projectDir, compiledDir, port = 0, stripEmbeddedRuntime = true } = options;
759
+ const {
760
+ projectDir,
761
+ compiledDir,
762
+ port = 0,
763
+ stripEmbeddedRuntime = true,
764
+ allowOutsideProjectAssets = false
765
+ } = options;
760
766
  const preHeadScripts = [
761
767
  HF_EARLY_STUB,
762
768
  RENDER_CAPTURE_MODE_SHIM,
@@ -778,7 +784,8 @@ function createFileServer(options) {
778
784
  let file = null;
779
785
  for (const root of compiledDir ? [compiledDir, projectDir] : [projectDir]) {
780
786
  const candidate = join(root, relativePath);
781
- if (isPathInside(candidate, root)) file = openRegularFile(candidate);
787
+ const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
788
+ if (isPathInside(candidate, root, { resolveSymlinks })) file = openRegularFile(candidate);
782
789
  if (file) break;
783
790
  }
784
791
  if (!file) {
@@ -1037,6 +1044,7 @@ import {
1037
1044
  isAbsolute as nodeIsAbsolute
1038
1045
  } from "node:path";
1039
1046
  import { fileURLToPath as fileURLToPath2 } from "node:url";
1047
+ import { isSafePath } from "@hyperframes/core/safe-path";
1040
1048
  var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
1041
1049
  // resolves to a bogus renders dir.
1042
1050
  nodeResolve(fileURLToPath2(import.meta.url), "../../..", "renders");
@@ -1051,6 +1059,9 @@ function isPathInside2(childPath, parentPath, options = {}) {
1051
1059
  const rel = relativePath(absParent, absChild);
1052
1060
  return rel !== "" && !LEADING_PARENT_SEGMENT_RE.test(rel) && !isPathAbsolute(rel);
1053
1061
  }
1062
+ function escapesAssetRoot(path, assetRoot) {
1063
+ return assetRoot !== void 0 && !isSafePath(assetRoot, path);
1064
+ }
1054
1065
  function toExternalAssetKey(absPath) {
1055
1066
  if (absPath.startsWith("hf-ext/")) return absPath;
1056
1067
  let normalised = absPath.replace(/\\/g, "/");
@@ -6391,7 +6402,7 @@ function countAuthoredTimedClips(html) {
6391
6402
 
6392
6403
  // src/services/render/stages/compileStage.ts
6393
6404
  import { existsSync as existsSync12, writeFileSync as writeFileSync5 } from "node:fs";
6394
- import { join as join19 } from "node:path";
6405
+ import { join as join20, relative as relative3 } from "node:path";
6395
6406
  import { suggestMatchingPreset } from "@hyperframes/core";
6396
6407
  import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
6397
6408
  import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
@@ -6400,7 +6411,7 @@ import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolu
6400
6411
  import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
6401
6412
  import { createHash as createHash6 } from "node:crypto";
6402
6413
  import { createReadStream as createReadStream2, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
6403
- import { join as join18, dirname as dirname8, resolve as resolve7, basename as basename5, relative as relative2, sep as sep2 } from "path";
6414
+ import { join as join19, dirname as dirname8, resolve as resolve7, basename as basename5, relative as relative2, sep as sep2 } from "path";
6404
6415
  import { parseHTML as parseHTML5 } from "linkedom";
6405
6416
 
6406
6417
  // src/services/bundledScripts.ts
@@ -6712,7 +6723,8 @@ function resolveLocalImageSourcePath(src, options) {
6712
6723
  ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
6713
6724
  resolve5(options.downloadDir, normalizedBase)
6714
6725
  ];
6715
- return candidates.find((candidate) => existsSync9(candidate)) ?? null;
6726
+ const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) || !escapesAssetRoot(candidate, options.downloadDir);
6727
+ return candidates.find((candidate) => existsSync9(candidate) && allowed(candidate)) ?? null;
6716
6728
  }
6717
6729
  function isUsableFile(path) {
6718
6730
  try {
@@ -7302,6 +7314,7 @@ import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position
7302
7314
 
7303
7315
  // src/services/assetMediaType.ts
7304
7316
  import { existsSync as existsSync10 } from "node:fs";
7317
+ import { join as join18 } from "node:path";
7305
7318
  import {
7306
7319
  fingerprintElementId,
7307
7320
  isNotMediaPayload,
@@ -7348,6 +7361,21 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
7348
7361
  function isRemoteOrInlineSource(src) {
7349
7362
  return /^(?:https?:|data:|blob:|about:)/i.test(src.trim());
7350
7363
  }
7364
+ function dropMediaOutsideProject(input) {
7365
+ const { projectDir, workDir, composition, log } = input;
7366
+ const compiledDir = join18(workDir, "compiled");
7367
+ const roots = [projectDir, compiledDir, join18(workDir, "downloads")];
7368
+ const staysInside = ({ id, src }) => {
7369
+ if (!src || isRemoteOrInlineSource(src)) return true;
7370
+ const path = resolveProjectRelativeSrc2(src, projectDir, compiledDir);
7371
+ if (roots.some((root) => !escapesAssetRoot(path, root))) return true;
7372
+ log.warn(`[Render] Media "${id}" source is missing: it is outside the project folder`, { src });
7373
+ return false;
7374
+ };
7375
+ composition.videos = composition.videos.filter(staysInside);
7376
+ composition.audios = composition.audios.filter(staysInside);
7377
+ composition.images = composition.images.filter(staysInside);
7378
+ }
7351
7379
  async function preflightCompositionAssetMediaTypes(input) {
7352
7380
  const references = [
7353
7381
  ...input.composition.videos.map((asset) => ({
@@ -7470,8 +7498,12 @@ function normalizeCompositionSrcs(html, projectDir) {
7470
7498
  return `${name}${quote}${relative2(projectDir, file).split(sep2).join("/")}${quote}`;
7471
7499
  });
7472
7500
  }
7501
+ function resolveCompositionFile(projectDir, src, assetRoot) {
7502
+ const file = resolveCompositionSrc(projectDir, src);
7503
+ return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
7504
+ }
7473
7505
  var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder(projectDir, filePath, isVcsOrSecretPath);
7474
- function assertSubCompositionsUsable(html, projectDir, visited = /* @__PURE__ */ new Set()) {
7506
+ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
7475
7507
  const { document: document2 } = parseHTML5(html);
7476
7508
  const hosts = [...document2.querySelectorAll("[data-composition-src]")];
7477
7509
  const problems = [];
@@ -7479,7 +7511,7 @@ function assertSubCompositionsUsable(html, projectDir, visited = /* @__PURE__ */
7479
7511
  const srcPath = el.getAttribute("data-composition-src");
7480
7512
  if (!srcPath) continue;
7481
7513
  if (isUnresolvedAssetPlaceholder(srcPath)) continue;
7482
- const filePath = resolveCompositionSrc(projectDir, srcPath);
7514
+ const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
7483
7515
  if (filePath === null) {
7484
7516
  problems.push({ srcPath, detail: "it is outside the project folder" });
7485
7517
  continue;
@@ -7510,7 +7542,7 @@ function assertSubCompositionsUsable(html, projectDir, visited = /* @__PURE__ */
7510
7542
  const nestedVisited = new Set(visited);
7511
7543
  nestedVisited.add(filePath);
7512
7544
  try {
7513
- assertSubCompositionsUsable(fileHtml, projectDir, nestedVisited);
7545
+ assertSubCompositionsUsable(fileHtml, projectDir, assetRoot, nestedVisited);
7514
7546
  } catch (err) {
7515
7547
  if (err instanceof EmptyCompositionError) {
7516
7548
  problems.push(...err.problems);
@@ -7629,10 +7661,10 @@ function detectShaderTransitionUsage(html) {
7629
7661
  }
7630
7662
  return false;
7631
7663
  }
7632
- async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, probes) {
7664
+ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, probes, assetRoot) {
7633
7665
  let filePath = src;
7634
7666
  if (isHttpUrl(src)) {
7635
- const remoteDir = join18(downloadDir, REMOTE_MEDIA_SUBDIR);
7667
+ const remoteDir = join19(downloadDir, REMOTE_MEDIA_SUBDIR);
7636
7668
  if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
7637
7669
  try {
7638
7670
  filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
@@ -7643,7 +7675,8 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
7643
7675
  }
7644
7676
  } else {
7645
7677
  filePath = decodedUrlPath(src);
7646
- if (!filePath.startsWith("/")) filePath = join18(baseDir, filePath);
7678
+ if (!filePath.startsWith("/")) filePath = join19(baseDir, filePath);
7679
+ if (escapesAssetRoot(filePath, assetRoot)) return { duration: null, resolvedPath: filePath };
7647
7680
  filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
7648
7681
  if (!isHttpUrl(filePath) && namesAnotherNetworkRoot2(baseDir, filePath)) {
7649
7682
  return { duration: null, resolvedPath: filePath };
@@ -7719,7 +7752,7 @@ function markInferredVariableMediaDurations(html, unresolvedMedia) {
7719
7752
  }
7720
7753
  return changed ? document2.toString() : html;
7721
7754
  }
7722
- async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocalPath, probes) {
7755
+ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocalPath, probes, assetRoot) {
7723
7756
  const { html: staticCompiled, unresolved } = compileTimingAttrs(html);
7724
7757
  const mediaUnresolved = unresolved.filter(
7725
7758
  (el) => (el.tagName === "video" || el.tagName === "audio") && el.src
@@ -7737,7 +7770,8 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7737
7770
  el.id,
7738
7771
  log,
7739
7772
  urlByAbsentLocalPath,
7740
- probes
7773
+ probes,
7774
+ assetRoot
7741
7775
  ).then(({ duration }) => ({ id: el.id, duration }))
7742
7776
  )
7743
7777
  );
@@ -7760,7 +7794,8 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7760
7794
  el.id,
7761
7795
  log,
7762
7796
  void 0,
7763
- probes
7797
+ probes,
7798
+ assetRoot
7764
7799
  );
7765
7800
  return { id: el.id, tagName: el.tagName, duration: el.duration, maxDuration, src: el.src };
7766
7801
  })
@@ -7782,7 +7817,7 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7782
7817
  compiledHtml = compiledHtml.replace(/(<audio\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
7783
7818
  return { html: compiledHtml, unresolvedCompositions };
7784
7819
  }
7785
- async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes) {
7820
+ async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
7786
7821
  const subCompositions = /* @__PURE__ */ new Map();
7787
7822
  const { document: document2 } = parseHTML5(html);
7788
7823
  const compEls = document2.querySelectorAll("[data-composition-src]");
@@ -7790,7 +7825,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
7790
7825
  for (const el of compEls) {
7791
7826
  const srcPath = el.getAttribute("data-composition-src");
7792
7827
  if (!srcPath) continue;
7793
- const filePath = resolveCompositionSrc(projectDir, srcPath);
7828
+ const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
7794
7829
  if (filePath === null || isPrivateCompositionFile(projectDir, filePath)) continue;
7795
7830
  if (visited.has(filePath)) {
7796
7831
  continue;
@@ -7812,7 +7847,8 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
7812
7847
  downloadDir,
7813
7848
  void 0,
7814
7849
  urlByAbsentLocalPath,
7815
- probes
7850
+ probes,
7851
+ assetRoot
7816
7852
  );
7817
7853
  const nested = await parseSubCompositions(
7818
7854
  compiledSub,
@@ -7820,7 +7856,8 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
7820
7856
  downloadDir,
7821
7857
  item.nestedVisited,
7822
7858
  urlByAbsentLocalPath,
7823
- probes
7859
+ probes,
7860
+ assetRoot
7824
7861
  );
7825
7862
  return {
7826
7863
  srcPath: item.srcPath,
@@ -7957,7 +7994,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
7957
7994
  }
7958
7995
  return document2.toString();
7959
7996
  }
7960
- function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides = {}) {
7997
+ function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot) {
7961
7998
  const { document: document2 } = parseHTML5(html);
7962
7999
  const head = document2.querySelector("head");
7963
8000
  const body = document2.querySelector("body");
@@ -7987,7 +8024,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
7987
8024
  resolveHtml: (srcPath) => {
7988
8025
  let compHtml = subCompositions.get(srcPath) || null;
7989
8026
  if (!compHtml) {
7990
- const filePath = resolveCompositionSrc(projectDir, srcPath);
8027
+ const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
7991
8028
  const read = filePath && !isPrivateCompositionFile(projectDir, filePath) ? readProjectFile(filePath) : null;
7992
8029
  if (read?.kind === "file") {
7993
8030
  compHtml = rewriteUnresolvableGsapToCdn(read.text, projectDir, srcPath);
@@ -8291,7 +8328,7 @@ async function localizeRemoteMediaSources(html, downloadDir) {
8291
8328
  return downloadAndRewriteUrls(
8292
8329
  urlSet,
8293
8330
  html,
8294
- join18(downloadDir, REMOTE_MEDIA_SUBDIR),
8331
+ join19(downloadDir, REMOTE_MEDIA_SUBDIR),
8295
8332
  "Remote media download failed",
8296
8333
  "Localized remote media source(s)"
8297
8334
  );
@@ -8306,7 +8343,7 @@ async function localizeRemoteImageSources(html, downloadDir) {
8306
8343
  return downloadAndRewriteUrls(
8307
8344
  urlSet,
8308
8345
  html,
8309
- join18(downloadDir, REMOTE_MEDIA_SUBDIR),
8346
+ join19(downloadDir, REMOTE_MEDIA_SUBDIR),
8310
8347
  "Remote image download failed",
8311
8348
  "Localized remote image source(s)"
8312
8349
  );
@@ -8322,7 +8359,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
8322
8359
  return downloadAndRewriteUrls(
8323
8360
  urlSet,
8324
8361
  html,
8325
- join18(downloadDir, REMOTE_MEDIA_SUBDIR),
8362
+ join19(downloadDir, REMOTE_MEDIA_SUBDIR),
8326
8363
  "Remote background-image download failed",
8327
8364
  "Localized remote background-image(s)",
8328
8365
  // Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
@@ -8477,7 +8514,7 @@ function localizeFontFaceUrls(html, downloadDir) {
8477
8514
  return downloadAndRewriteUrls(
8478
8515
  collectFontFaceUrls(html),
8479
8516
  html,
8480
- join18(downloadDir, REMOTE_MEDIA_SUBDIR),
8517
+ join19(downloadDir, REMOTE_MEDIA_SUBDIR),
8481
8518
  "Remote font download failed",
8482
8519
  "Localized remote font face(s)",
8483
8520
  (h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
@@ -8502,7 +8539,7 @@ async function readLocalFont(absPath) {
8502
8539
  }
8503
8540
  return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
8504
8541
  }
8505
- async function embedLocalFontFaces(html, projectDir) {
8542
+ async function embedLocalFontFaces(html, projectDir, assetRoot) {
8506
8543
  const { fontToDataUri: toDataUri } = await import("@hyperframes/core/fonts/embed");
8507
8544
  const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
8508
8545
  const fontFaceRe = /@font-face\s*\{([^}]*)\}/gi;
@@ -8523,7 +8560,7 @@ async function embedLocalFontFaces(html, projectDir) {
8523
8560
  const localPath = urlMatch[1];
8524
8561
  if (!localPath || embeddedPaths.has(localPath)) continue;
8525
8562
  const absPath = localPath.startsWith("/") ? localPath : resolve7(projectDir, localPath);
8526
- if (!isPathInside2(absPath, projectDir)) continue;
8563
+ if (!isPathInside2(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
8527
8564
  const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
8528
8565
  try {
8529
8566
  if (fileBackedAbsolutePaths.has(absPath)) {
@@ -8630,12 +8667,16 @@ function bindVariableMediaSources(html, variables) {
8630
8667
  return changed ? document2.toString() : html;
8631
8668
  }
8632
8669
  async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
8670
+ const assetRoot = options.allowOutsideProjectAssets ? void 0 : projectDir;
8671
+ if (isPathInside2(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
8672
+ throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
8673
+ }
8633
8674
  const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
8634
8675
  const rawHtml = bindVariableMediaSources(
8635
8676
  normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
8636
8677
  options.variables ?? {}
8637
8678
  );
8638
- assertSubCompositionsUsable(rawHtml, projectDir);
8679
+ assertSubCompositionsUsable(rawHtml, projectDir, assetRoot);
8639
8680
  const probes = /* @__PURE__ */ new Map();
8640
8681
  const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
8641
8682
  rawHtml,
@@ -8643,7 +8684,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8643
8684
  downloadDir,
8644
8685
  options.log,
8645
8686
  options.urlByAbsentLocalPath,
8646
- probes
8687
+ probes,
8688
+ assetRoot
8647
8689
  );
8648
8690
  const { subCompositions } = await parseSubCompositions(
8649
8691
  compiledHtml,
@@ -8651,14 +8693,16 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8651
8693
  downloadDir,
8652
8694
  void 0,
8653
8695
  options.urlByAbsentLocalPath,
8654
- probes
8696
+ probes,
8697
+ assetRoot
8655
8698
  );
8656
8699
  const fullHtml = ensureFullDocument(compiledHtml);
8657
8700
  const inlinedHtml = inlineSubCompositions(
8658
8701
  fullHtml,
8659
8702
  subCompositions,
8660
8703
  projectDir,
8661
- options.variables ?? {}
8704
+ options.variables ?? {},
8705
+ assetRoot
8662
8706
  );
8663
8707
  const sanitizedHtml = inlinedHtml.replace(
8664
8708
  /(<(?:video|audio)\b[^>]*?)\s+preload\s*=\s*["']none["']/gi,
@@ -8714,7 +8758,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8714
8758
  downloadDir,
8715
8759
  cacheDir: options.animatedGifCacheDir,
8716
8760
  sourceAssets: remoteImageAssets,
8717
- timeoutMs: options.ffmpegProcessTimeout
8761
+ timeoutMs: options.ffmpegProcessTimeout,
8762
+ assetRoot
8718
8763
  });
8719
8764
  if (preparedHeifImages.length > 0) {
8720
8765
  defaultLogger.debug(`[Compiler] Converted ${preparedHeifImages.length} HEIC image(s) to JPEG`);
@@ -8729,13 +8774,14 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8729
8774
  downloadDir,
8730
8775
  cacheDir: options.animatedGifCacheDir,
8731
8776
  sourceAssets: gifSourceAssets,
8732
- timeoutMs: options.ffmpegProcessTimeout
8777
+ timeoutMs: options.ffmpegProcessTimeout,
8778
+ assetRoot
8733
8779
  });
8734
8780
  if (preparedGifs.length > 0) {
8735
8781
  defaultLogger.debug(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
8736
8782
  }
8737
- const embeddedHtml = await embedLocalFontFaces(htmlWithPreparedGifs, projectDir);
8738
- const { html, externalAssets } = collectExternalAssets(embeddedHtml, projectDir);
8783
+ const embeddedHtml = await embedLocalFontFaces(htmlWithPreparedGifs, projectDir, assetRoot);
8784
+ const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(embeddedHtml, projectDir) : { html: embeddedHtml, externalAssets: /* @__PURE__ */ new Map() };
8739
8785
  for (const [relPath, absPath] of remoteMediaAssets) {
8740
8786
  externalAssets.set(relPath, absPath);
8741
8787
  }
@@ -8760,7 +8806,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8760
8806
  for (const video of videos) {
8761
8807
  if (isHttpUrl(video.src)) continue;
8762
8808
  const videoPath = resolve7(projectDir, video.src);
8763
- if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath)) continue;
8809
+ if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot))
8810
+ continue;
8764
8811
  advised.add(videoPath);
8765
8812
  const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
8766
8813
  (async () => {
@@ -9139,10 +9186,18 @@ async function resolveCompositionDurations(page, unresolved) {
9139
9186
  }
9140
9187
  return resolutions;
9141
9188
  }
9142
- async function recompileWithResolutions(compiled, resolutions, projectDir, downloadDir) {
9189
+ async function recompileWithResolutions(compiled, resolutions, projectDir, downloadDir, assetRoot) {
9143
9190
  if (resolutions.length === 0) return compiled;
9144
9191
  const html = injectDurations(compiled.html, resolutions);
9145
- const { subCompositions } = await parseSubCompositions(html, projectDir, downloadDir);
9192
+ const { subCompositions } = await parseSubCompositions(
9193
+ html,
9194
+ projectDir,
9195
+ downloadDir,
9196
+ void 0,
9197
+ void 0,
9198
+ void 0,
9199
+ assetRoot
9200
+ );
9146
9201
  const { videos, audios, images } = compiled;
9147
9202
  const remaining = compiled.unresolvedCompositions.filter(
9148
9203
  (c) => !resolutions.some((r) => r.id === c.id)
@@ -9175,17 +9230,25 @@ function adaptAspectAgnosticResolution(requested, aspectAgnostic, width, height,
9175
9230
  }
9176
9231
  function resolveEntryHtmlPath(input) {
9177
9232
  const { projectDir, workDir, entryFile, log } = input;
9178
- const htmlPath = join19(projectDir, entryFile);
9179
- const rawEntry = readTextFile2(htmlPath);
9233
+ const readEntry = (path) => {
9234
+ if (escapesAssetRoot(path, input.assetRoot)) {
9235
+ throw new Error(
9236
+ `Entry file "${relative3(projectDir, path)}" leads outside the project folder`
9237
+ );
9238
+ }
9239
+ return readTextFile2(path);
9240
+ };
9241
+ const htmlPath = join20(projectDir, entryFile);
9242
+ const rawEntry = readEntry(htmlPath);
9180
9243
  if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
9181
- const projectIndexPath = join19(projectDir, "index.html");
9244
+ const projectIndexPath = join20(projectDir, "index.html");
9182
9245
  if (!existsSync12(projectIndexPath)) {
9183
9246
  throw new Error(
9184
9247
  `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
9185
9248
  );
9186
9249
  }
9187
9250
  const standaloneHtml = extractStandaloneEntryFromIndex(
9188
- readTextFile2(projectIndexPath),
9251
+ readEntry(projectIndexPath),
9189
9252
  entryFile,
9190
9253
  rawEntry
9191
9254
  );
@@ -9194,7 +9257,7 @@ function resolveEntryHtmlPath(input) {
9194
9257
  `Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`
9195
9258
  );
9196
9259
  }
9197
- const wrapperPath = join19(workDir, "standalone-entry.html");
9260
+ const wrapperPath = join20(workDir, "standalone-entry.html");
9198
9261
  writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
9199
9262
  log.info("Extracted standalone entry from index.html host context", { entryFile });
9200
9263
  return wrapperPath;
@@ -9221,9 +9284,10 @@ async function runCompileStage(input) {
9221
9284
  allowSystemFontCapture,
9222
9285
  abortSignal
9223
9286
  } = input;
9224
- const htmlPath = resolveEntryHtmlPath({ projectDir, workDir, entryFile, log });
9287
+ const assetRoot = job.config.allowOutsideProjectAssets ? void 0 : projectDir;
9288
+ const htmlPath = resolveEntryHtmlPath({ projectDir, workDir, entryFile, log, assetRoot });
9225
9289
  const compileStart = Date.now();
9226
- const compiled = await compileForRender(projectDir, htmlPath, join19(workDir, "downloads"), {
9290
+ const compiled = await compileForRender(projectDir, htmlPath, join20(workDir, "downloads"), {
9227
9291
  log,
9228
9292
  failClosedFontFetch: failClosedFontFetch === true,
9229
9293
  allowSystemFontCapture,
@@ -9231,8 +9295,9 @@ async function runCompileStage(input) {
9231
9295
  variables: input.variables,
9232
9296
  urlByAbsentLocalPath: input.urlByAbsentLocalPath,
9233
9297
  pageMotionBlur: input.pageMotionBlur,
9234
- animatedGifCacheDir: cfg.extractCacheDir ? join19(cfg.extractCacheDir, "animated-gif") : void 0,
9235
- ffmpegProcessTimeout: cfg.ffmpegProcessTimeout
9298
+ animatedGifCacheDir: cfg.extractCacheDir ? join20(cfg.extractCacheDir, "animated-gif") : void 0,
9299
+ ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
9300
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
9236
9301
  });
9237
9302
  assertNotAborted();
9238
9303
  const compileOnlyMs = Date.now() - compileStart;
@@ -9287,9 +9352,12 @@ async function runCompileStage(input) {
9287
9352
  width: compiled.width,
9288
9353
  height: compiled.height
9289
9354
  };
9355
+ if (!job.config.allowOutsideProjectAssets) {
9356
+ dropMediaOutsideProject({ projectDir, workDir, composition, log });
9357
+ }
9290
9358
  await preflightCompositionAssetMediaTypes({
9291
9359
  projectDir,
9292
- compiledDir: join19(workDir, "compiled"),
9360
+ compiledDir: join20(workDir, "compiled"),
9293
9361
  composition,
9294
9362
  signal: abortSignal
9295
9363
  });
@@ -9335,7 +9403,7 @@ async function runCompileStage(input) {
9335
9403
 
9336
9404
  // src/services/render/stages/probeStage.ts
9337
9405
  import { createHash as createHash7 } from "node:crypto";
9338
- import { basename as basename6, join as join20 } from "node:path";
9406
+ import { basename as basename6, join as join21 } from "node:path";
9339
9407
  import { parseHTML as parseHTML6 } from "linkedom";
9340
9408
  import {
9341
9409
  closeCaptureSession as closeCaptureSession4,
@@ -9561,10 +9629,11 @@ async function runProbeStage(input) {
9561
9629
  });
9562
9630
  fileServer = await createFileServer({
9563
9631
  projectDir,
9564
- compiledDir: join20(workDir, "compiled"),
9632
+ compiledDir: join21(workDir, "compiled"),
9565
9633
  port: 0,
9566
9634
  preHeadScripts: [VIRTUAL_TIME_SHIM],
9567
- fps: job.config.fps
9635
+ fps: job.config.fps,
9636
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
9568
9637
  });
9569
9638
  assertNotAborted();
9570
9639
  const motionBlur = job.config.motionBlur;
@@ -9596,7 +9665,7 @@ async function runProbeStage(input) {
9596
9665
  log.info("Creating capture session...", { attempt, maxAttempts: PROBE_MAX_ATTEMPTS });
9597
9666
  probeSession = await createCaptureSession4(
9598
9667
  fileServer.url,
9599
- join20(workDir, "probe"),
9668
+ join21(workDir, "probe"),
9600
9669
  captureOpts,
9601
9670
  null,
9602
9671
  probeCfg
@@ -9681,7 +9750,7 @@ async function runProbeStage(input) {
9681
9750
  });
9682
9751
  probeSession = await createCaptureSession4(
9683
9752
  fileServer.url,
9684
- join20(workDir, "probe-screenshot"),
9753
+ join21(workDir, "probe-screenshot"),
9685
9754
  captureOpts,
9686
9755
  null,
9687
9756
  { ...probeCfg, forceScreenshot: true }
@@ -9719,7 +9788,8 @@ async function runProbeStage(input) {
9719
9788
  compiled,
9720
9789
  resolutions,
9721
9790
  projectDir,
9722
- join20(workDir, "downloads")
9791
+ join21(workDir, "downloads"),
9792
+ job.config.allowOutsideProjectAssets ? void 0 : projectDir
9723
9793
  );
9724
9794
  assertNotAborted();
9725
9795
  composition.videos = compiled.videos;
@@ -9908,9 +9978,12 @@ async function runProbeStage(input) {
9908
9978
  }
9909
9979
  }
9910
9980
  }
9981
+ if (!job.config.allowOutsideProjectAssets) {
9982
+ dropMediaOutsideProject({ projectDir, workDir, composition, log });
9983
+ }
9911
9984
  await preflightCompositionAssetMediaTypes({
9912
9985
  projectDir,
9913
- compiledDir: join20(workDir, "compiled"),
9986
+ compiledDir: join21(workDir, "compiled"),
9914
9987
  composition,
9915
9988
  signal: abortSignal
9916
9989
  });
@@ -10078,7 +10151,7 @@ function validateDistributedDuration(input) {
10078
10151
 
10079
10152
  // src/services/render/stages/extractVideosStage.ts
10080
10153
  import { existsSync as existsSync13 } from "node:fs";
10081
- import { join as join21 } from "node:path";
10154
+ import { join as join22 } from "node:path";
10082
10155
  import {
10083
10156
  classifyVideoExtractionError,
10084
10157
  createFrameLookupTable as createFrameLookupTable3,
@@ -10424,14 +10497,14 @@ async function runExtractVideosStage(input) {
10424
10497
  // because short boundary counts can differ by one frame.
10425
10498
  {
10426
10499
  fps: job.config.fps,
10427
- outputDir: join21(compiledDir, "__hyperframes_video_frames"),
10500
+ outputDir: join22(compiledDir, "__hyperframes_video_frames"),
10428
10501
  format: job.config.videoFrameFormat ?? "auto",
10429
10502
  toneMapHdrToSdr: rendersSdrOnly(job.config, composition),
10430
10503
  timelineEnd: composition.duration,
10431
10504
  maxTransientRetries: extractionPolicy.maxTransientRetries,
10432
10505
  collectProbeFailures: extractionPolicy.failureMode === "enforce",
10433
10506
  deferRangeExtraction,
10434
- contentKeyedDirs: [join21(compiledDir, REMOTE_MEDIA_SUBDIR)],
10507
+ contentKeyedDirs: [join22(compiledDir, REMOTE_MEDIA_SUBDIR)],
10435
10508
  urlByAbsentLocalPath,
10436
10509
  onProgress: ({ planned = 0, done = 0 }) => {
10437
10510
  framesPlanned += planned;
@@ -10614,7 +10687,7 @@ async function planVideoLayerPassthrough(input) {
10614
10687
 
10615
10688
  // src/services/render/stages/audioStage.ts
10616
10689
  import { existsSync as existsSync16 } from "node:fs";
10617
- import { join as join24 } from "node:path";
10690
+ import { join as join25 } from "node:path";
10618
10691
  import {
10619
10692
  MIXED_AUDIO_FILENAME,
10620
10693
  audioFailureDiagnostics,
@@ -10625,7 +10698,7 @@ import {
10625
10698
 
10626
10699
  // src/services/render/audioDeliveryLimit.ts
10627
10700
  import { existsSync as existsSync15 } from "node:fs";
10628
- import { dirname as dirname10, join as join23 } from "node:path";
10701
+ import { dirname as dirname10, join as join24 } from "node:path";
10629
10702
  import {
10630
10703
  applyAudioFxChain,
10631
10704
  describeFfmpegFailure as describeFfmpegFailure3,
@@ -10635,7 +10708,7 @@ import {
10635
10708
 
10636
10709
  // src/services/render/audioPadTrim.ts
10637
10710
  import { spawn } from "node:child_process";
10638
- import { dirname as dirname9, join as join22 } from "node:path";
10711
+ import { dirname as dirname9, join as join23 } from "node:path";
10639
10712
  import {
10640
10713
  DEFAULT_CONFIG,
10641
10714
  describeFfmpegFailure as describeFfmpegFailure2,
@@ -10915,7 +10988,7 @@ async function constrainAacTruePeak(input) {
10915
10988
  }
10916
10989
  async function cutSource(input, scratchDir, attenuationDb) {
10917
10990
  if (!input.sourcePath || !input.rewriteSource) return true;
10918
- const cutPath = join22(scratchDir, "source.wav");
10991
+ const cutPath = join23(scratchDir, "source.wav");
10919
10992
  try {
10920
10993
  const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
10921
10994
  if (!result.success) throw new Error(result.error);
@@ -10930,7 +11003,7 @@ async function enforceAacTruePeak(input) {
10930
11003
  let scratchDir;
10931
11004
  try {
10932
11005
  scratchDir = createStagingDir3(dirname9(input.audioPath), ".true-peak-");
10933
- const correctedPath = join22(scratchDir, "audio.m4a");
11006
+ const correctedPath = join23(scratchDir, "audio.m4a");
10934
11007
  const measurements = [];
10935
11008
  let attenuationDb = 0;
10936
11009
  let sourcePeakDbfs;
@@ -11140,7 +11213,7 @@ async function limitDeliveryPeaks(input, deps = {
11140
11213
  const peak = await deps.measure(audioPath, { timeoutMs, signal });
11141
11214
  if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
11142
11215
  const alternating = ["a", "b"].map(
11143
- (k) => join23(dirname10(sourcePath), `audio-source-limited-${k}.wav`)
11216
+ (k) => join24(dirname10(sourcePath), `audio-source-limited-${k}.wav`)
11144
11217
  );
11145
11218
  let encodedFrom;
11146
11219
  let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
@@ -11212,7 +11285,7 @@ function runAudioStage(input) {
11212
11285
  }
11213
11286
  async function runAudioStageScoped(input) {
11214
11287
  const stageStart = Date.now();
11215
- const pcmSourcePath = join24(input.workDir, "audio-source.wav");
11288
+ const pcmSourcePath = join25(input.workDir, "audio-source.wav");
11216
11289
  const duration = input.totalFrames * input.fps.den / input.fps.num;
11217
11290
  let deliverySourcePath;
11218
11291
  try {
@@ -11277,7 +11350,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
11277
11350
  assertNotAborted,
11278
11351
  log
11279
11352
  } = input;
11280
- const audioOutputPath = join24(workDir, MIXED_AUDIO_FILENAME);
11353
+ const audioOutputPath = join25(workDir, MIXED_AUDIO_FILENAME);
11281
11354
  let hasAudio = false;
11282
11355
  let audioError;
11283
11356
  let audioFailures;
@@ -11288,7 +11361,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
11288
11361
  audioResult = await processCompositionAudio(
11289
11362
  audios,
11290
11363
  projectDir,
11291
- join24(workDir, "audio-work"),
11364
+ join25(workDir, "audio-work"),
11292
11365
  audioOutputPath,
11293
11366
  duration,
11294
11367
  abortSignal,
@@ -11357,7 +11430,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
11357
11430
 
11358
11431
  // src/services/render/stages/captureStage.ts
11359
11432
  import { existsSync as existsSync17, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
11360
- import { join as join25 } from "node:path";
11433
+ import { join as join26 } from "node:path";
11361
11434
  import {
11362
11435
  classifyCaptureFailure as classifyCaptureFailure2,
11363
11436
  frameFileExtension,
@@ -11430,13 +11503,13 @@ function measureCaptureFrameBytes(workDir, framesDir) {
11430
11503
  if (!existsSync17(workDir)) return total;
11431
11504
  for (const attempt of readdirSync4(workDir)) {
11432
11505
  if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
11433
- total += sampleDirectoryBytes(join25(workDir, attempt));
11506
+ total += sampleDirectoryBytes(join26(workDir, attempt));
11434
11507
  continue;
11435
11508
  }
11436
11509
  if (!/^capture-attempt-\d+$/.test(attempt)) continue;
11437
- const attemptDir = join25(workDir, attempt);
11510
+ const attemptDir = join26(workDir, attempt);
11438
11511
  for (const name of readdirSync4(attemptDir)) {
11439
- if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join25(attemptDir, name));
11512
+ if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join26(attemptDir, name));
11440
11513
  }
11441
11514
  }
11442
11515
  return total;
@@ -11735,7 +11808,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
11735
11808
 
11736
11809
  // src/services/render/stages/captureHdrStage.ts
11737
11810
  import { existsSync as existsSync19, mkdirSync as mkdirSync10 } from "node:fs";
11738
- import { join as join29 } from "node:path";
11811
+ import { join as join30 } from "node:path";
11739
11812
  import {
11740
11813
  closeCaptureSession as closeCaptureSession7,
11741
11814
  cloneCaptureWarnings as cloneCaptureWarnings2,
@@ -11807,7 +11880,7 @@ function createHdrImageTransferCache(options = {}) {
11807
11880
  }
11808
11881
 
11809
11882
  // src/services/render/stages/captureHdrSequentialLoop.ts
11810
- import { join as join26 } from "node:path";
11883
+ import { join as join27 } from "node:path";
11811
11884
  import {
11812
11885
  TRANSITIONS,
11813
11886
  crossfade
@@ -11932,7 +12005,7 @@ async function runSequentialLayeredFrameLoop(input) {
11932
12005
  );
11933
12006
  if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
11934
12007
  writeFileExclusiveSync(
11935
- join26(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
12008
+ join27(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
11936
12009
  normalCanvas
11937
12010
  );
11938
12011
  }
@@ -11964,7 +12037,7 @@ async function runSequentialLayeredFrameLoop(input) {
11964
12037
  }
11965
12038
 
11966
12039
  // src/services/render/stages/captureHdrHybridLoop.ts
11967
- import { join as join28 } from "node:path";
12040
+ import { join as join29 } from "node:path";
11968
12041
  import {
11969
12042
  TRANSITIONS as TRANSITIONS2,
11970
12043
  closeCaptureSession as closeCaptureSession6,
@@ -11978,7 +12051,7 @@ import {
11978
12051
  // src/services/shaderTransitionWorkerPool.ts
11979
12052
  import { Worker } from "node:worker_threads";
11980
12053
  import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
11981
- import { dirname as dirname11, join as join27 } from "node:path";
12054
+ import { dirname as dirname11, join as join28 } from "node:path";
11982
12055
  import { createRequire } from "node:module";
11983
12056
  import { existsSync as existsSync18 } from "node:fs";
11984
12057
  import { cpus as cpus2 } from "node:os";
@@ -11992,9 +12065,9 @@ function resolveWorkerEntry(explicit) {
11992
12065
  return { path: override, isTs };
11993
12066
  }
11994
12067
  const moduleDir = dirname11(fileURLToPath3(import.meta.url));
11995
- const jsPath = join27(moduleDir, "shaderTransitionWorker.js");
12068
+ const jsPath = join28(moduleDir, "shaderTransitionWorker.js");
11996
12069
  if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
11997
- const tsPath = join27(moduleDir, "shaderTransitionWorker.ts");
12070
+ const tsPath = join28(moduleDir, "shaderTransitionWorker.ts");
11998
12071
  return { path: tsPath, isTs: true };
11999
12072
  }
12000
12073
  function buildExecArgv(entryIsTs) {
@@ -12362,7 +12435,7 @@ async function runHybridLayeredFrameLoop(input) {
12362
12435
  );
12363
12436
  if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
12364
12437
  writeFileExclusiveSync(
12365
- join28(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
12438
+ join29(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
12366
12439
  canvas
12367
12440
  );
12368
12441
  }
@@ -12553,7 +12626,7 @@ async function runCaptureHdrStage(input) {
12553
12626
  if (hdrVideoFrameSources.has(v.id)) hdrVideoEndTimes.set(v.id, v.end);
12554
12627
  }
12555
12628
  const debugDumpEnabled = process.env.KEEP_TEMP === "1";
12556
- const debugDumpDir = debugDumpEnabled ? join29(framesDir, "debug-composite") : null;
12629
+ const debugDumpDir = debugDumpEnabled ? join30(framesDir, "debug-composite") : null;
12557
12630
  if (debugDumpDir && !existsSync19(debugDumpDir)) {
12558
12631
  mkdirSync10(debugDumpDir, { recursive: true });
12559
12632
  }
@@ -12720,7 +12793,7 @@ import {
12720
12793
  writeFileSync as writeFileSync6
12721
12794
  } from "node:fs";
12722
12795
  import { readFile as readFile2 } from "node:fs/promises";
12723
- import { dirname as dirname12, join as join30 } from "node:path";
12796
+ import { dirname as dirname12, join as join31 } from "node:path";
12724
12797
  import {
12725
12798
  encodeFramesChunkedConcat,
12726
12799
  encodeFramesFromDir,
@@ -12931,7 +13004,7 @@ function encodeWhileCapturing(input, totalFrames) {
12931
13004
  await new Promise((resolve13) => wake = resolve13);
12932
13005
  }
12933
13006
  if (signal.aborted) return;
12934
- const mergedPath = join30(input.framesDir, formatCaptureFrameName(next, "jpg"));
13007
+ const mergedPath = join31(input.framesDir, formatCaptureFrameName(next, "jpg"));
12935
13008
  const frame = await readLandedFrame(landed.get(next), mergedPath);
12936
13009
  landed.delete(next);
12937
13010
  if (!await stream.writeFrame(frame)) {
@@ -13014,11 +13087,11 @@ async function runEncodeStage(input) {
13014
13087
  );
13015
13088
  }
13016
13089
  captured.forEach((name, i) => {
13017
- const dst = join30(outputPath, formatExportFrameName(i, "png"));
13018
- copyFileSync4(join30(framesDir, name), dst);
13090
+ const dst = join31(outputPath, formatExportFrameName(i, "png"));
13091
+ copyFileSync4(join31(framesDir, name), dst);
13019
13092
  });
13020
13093
  if (hasAudio && audioOutputPath && existsSync20(audioOutputPath)) {
13021
- copyFileSync4(audioOutputPath, join30(outputPath, MIXED_AUDIO_FILENAME2));
13094
+ copyFileSync4(audioOutputPath, join31(outputPath, MIXED_AUDIO_FILENAME2));
13022
13095
  log.info(
13023
13096
  `[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
13024
13097
  );
@@ -13038,7 +13111,7 @@ async function runEncodeStage(input) {
13038
13111
  const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
13039
13112
  fps: job.config.fps,
13040
13113
  loop,
13041
- palettePath: join30(dirname12(videoOnlyPath), "gif-palette.png"),
13114
+ palettePath: join31(dirname12(videoOnlyPath), "gif-palette.png"),
13042
13115
  preserveAlpha: needsAlpha,
13043
13116
  signal: abortSignal,
13044
13117
  timeout: engineCfg.ffmpegEncodeTimeout
@@ -13249,7 +13322,7 @@ function sampleDirectoryBytes(dir) {
13249
13322
  continue;
13250
13323
  }
13251
13324
  for (const name of entries) {
13252
- const full = join31(current, name);
13325
+ const full = join32(current, name);
13253
13326
  try {
13254
13327
  const st = statSync9(full);
13255
13328
  if (st.isDirectory()) {
@@ -13405,7 +13478,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
13405
13478
  const ranges = [];
13406
13479
  let rangeStart = null;
13407
13480
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
13408
- const framePath = join31(framesDir, formatCaptureFrameName(frameIndex, frameExt));
13481
+ const framePath = join32(framesDir, formatCaptureFrameName(frameIndex, frameExt));
13409
13482
  const missing = !existsSync21(framePath) || statSync9(framePath).size <= 8;
13410
13483
  if (missing && rangeStart === null) {
13411
13484
  rangeStart = frameIndex;
@@ -13422,7 +13495,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
13422
13495
  function buildMissingFrameRetryBatches(ranges, maxWorkers, workDir, attempt, rangeStart = 0, stride = 1) {
13423
13496
  const workersPerBatch = Math.max(1, Math.floor(maxWorkers));
13424
13497
  const batches = [];
13425
- const outputDirFor = (batchIndex, workerId) => join31(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
13498
+ const outputDirFor = (batchIndex, workerId) => join32(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
13426
13499
  if (stride > 1) {
13427
13500
  const spans = /* @__PURE__ */ new Map();
13428
13501
  for (const range of ranges) {
@@ -13482,8 +13555,8 @@ function getNextRetryWorkerCount(currentWorkers) {
13482
13555
  return Math.max(1, Math.floor(currentWorkers / 2));
13483
13556
  }
13484
13557
  function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir2()) {
13485
- if (platform2 === "win32" || platform2 === "darwin") return join31(systemTempDir, "hf-render-");
13486
- return join31(dirname13(outputPath), `work-${jobId}-`);
13558
+ if (platform2 === "win32" || platform2 === "darwin") return join32(systemTempDir, "hf-render-");
13559
+ return join32(dirname13(outputPath), `work-${jobId}-`);
13487
13560
  }
13488
13561
  var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
13489
13562
  function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
@@ -13538,7 +13611,7 @@ The composition is too large for the available memory. To reduce memory pressure
13538
13611
  function countCapturedFrames(totalFrames, framesDir, frameExt) {
13539
13612
  let captured = 0;
13540
13613
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
13541
- const framePath = join31(framesDir, formatCaptureFrameName(frameIndex, frameExt));
13614
+ const framePath = join32(framesDir, formatCaptureFrameName(frameIndex, frameExt));
13542
13615
  if (existsSync21(framePath)) captured++;
13543
13616
  }
13544
13617
  return captured;
@@ -13564,7 +13637,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
13564
13637
  reason: attempt === 0 ? "initial" : pendingTransientRetry ? "transient-retry" : "retry"
13565
13638
  });
13566
13639
  pendingTransientRetry = false;
13567
- const attemptWorkDir = join31(options.workDir, `capture-attempt-${attempt}`);
13640
+ const attemptWorkDir = join32(options.workDir, `capture-attempt-${attempt}`);
13568
13641
  const batches = missingRanges ? buildMissingFrameRetryBatches(
13569
13642
  missingRanges,
13570
13643
  currentWorkers,
@@ -14197,7 +14270,7 @@ function deVerifyFallbackTelemetry(err) {
14197
14270
  }
14198
14271
  function resolveRenderDebugDir() {
14199
14272
  const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve8(process.env.PRODUCER_RENDERS_DIR, "..") : resolve8(dirname13(fileURLToPath4(import.meta.url)), "../..");
14200
- return join31(producerRoot, ".debug");
14273
+ return join32(producerRoot, ".debug");
14201
14274
  }
14202
14275
  async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
14203
14276
  validateHlsRenderConfig(job.config);
@@ -14206,10 +14279,10 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
14206
14279
  const debugDir = resolveRenderDebugDir();
14207
14280
  const outputDir = dirname13(outputPath);
14208
14281
  if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
14209
- const workDir = job.config.debug ? join31(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
14282
+ const workDir = job.config.debug ? join32(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
14210
14283
  const pipelineStart = Date.now();
14211
14284
  const baseLog = job.config.logger ?? defaultLogger;
14212
- const logPath = job.config.debug ? join31(workDir, "render.log") : null;
14285
+ const logPath = job.config.debug ? join32(workDir, "render.log") : null;
14213
14286
  const execution = new RenderExecutionContext({
14214
14287
  request: { renderJobId: job.id, projectDir, outputPath },
14215
14288
  logger: logPath ? createRenderFileLogger(logPath, baseLog) : baseLog,
@@ -14271,7 +14344,7 @@ async function executeRenderPipeline(input) {
14271
14344
  imageDecodeFailures: 0
14272
14345
  };
14273
14346
  let hdrPerf;
14274
- const perfOutputPath = join31(workDir, "perf-summary.json");
14347
+ const perfOutputPath = join32(workDir, "perf-summary.json");
14275
14348
  const cfg = { ...job.config.producerConfig ?? resolveConfig2() };
14276
14349
  const observability = new RenderObservabilityRecorder({
14277
14350
  pipelineStartMs: pipelineStart,
@@ -14376,7 +14449,7 @@ async function executeRenderPipeline(input) {
14376
14449
  requestedWorkers: job.config.workers ?? "auto"
14377
14450
  });
14378
14451
  const entryFile = job.config.entryFile || "index.html";
14379
- const htmlPath = join31(projectDir, entryFile);
14452
+ const htmlPath = join32(projectDir, entryFile);
14380
14453
  if (!existsSync21(htmlPath)) {
14381
14454
  throw new Error(`Entry file not found: ${htmlPath}`);
14382
14455
  }
@@ -14556,7 +14629,7 @@ async function executeRenderPipeline(input) {
14556
14629
  canvas: { width, height },
14557
14630
  page: probeSession.page,
14558
14631
  projectDir,
14559
- compiledDir: join31(workDir, "compiled")
14632
+ compiledDir: join32(workDir, "compiled")
14560
14633
  });
14561
14634
  if (videoLayerPlan.videoId === void 0) {
14562
14635
  log.info(`[Render] Video layer passthrough off: ${videoLayerPlan.reason}`);
@@ -14574,7 +14647,7 @@ async function executeRenderPipeline(input) {
14574
14647
  updateJobStatus(job, "preprocessing", "Extracting video frames", 10, onProgress, {
14575
14648
  code: "extract_video"
14576
14649
  });
14577
- const compiledDir = join31(workDir, "compiled");
14650
+ const compiledDir = join32(workDir, "compiled");
14578
14651
  const segmentsCapture = (layeredOrEffectRoute) => shouldSegmentCapture({
14579
14652
  env: process.env,
14580
14653
  durationSeconds: probeResult.duration,
@@ -14705,10 +14778,11 @@ async function executeRenderPipeline(input) {
14705
14778
  try {
14706
14779
  fileServer = await createFileServer({
14707
14780
  projectDir,
14708
- compiledDir: join31(workDir, "compiled"),
14781
+ compiledDir: join32(workDir, "compiled"),
14709
14782
  port: 0,
14710
14783
  preHeadScripts: [VIRTUAL_TIME_SHIM],
14711
- fps: job.config.fps
14784
+ fps: job.config.fps,
14785
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
14712
14786
  });
14713
14787
  assertNotAborted();
14714
14788
  observability.stageEnd("file_server", fileServerStart);
@@ -14723,7 +14797,7 @@ async function executeRenderPipeline(input) {
14723
14797
  if (!activeFileServer) {
14724
14798
  throw new Error("File server failed to initialize before frame capture");
14725
14799
  }
14726
- const framesDir = join31(workDir, "captured-frames");
14800
+ const framesDir = join32(workDir, "captured-frames");
14727
14801
  if (!existsSync21(framesDir)) mkdirSync12(framesDir, { recursive: true });
14728
14802
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
14729
14803
  code: "start_browsers"
@@ -15302,7 +15376,7 @@ async function executeRenderPipeline(input) {
15302
15376
  hls: ".mp4"
15303
15377
  };
15304
15378
  const videoExt = FORMAT_EXT[outputFormat] ?? ".mp4";
15305
- const videoOnlyPath = join31(workDir, `video-only${videoExt}`);
15379
+ const videoOnlyPath = join32(workDir, `video-only${videoExt}`);
15306
15380
  const usePageSideCompositingForTransitions = (cfg.enablePageSideCompositing || isGif) && compiled.hasShaderTransitions && !hasHdrContent && outputSupportsPageSideShaderCompositing(outputFormat);
15307
15381
  if (usePageSideCompositingForTransitions) {
15308
15382
  activeFileServer.addPreHeadScript(HF_PAGE_SIDE_COMPOSITING_STUB);
@@ -15591,7 +15665,7 @@ async function executeRenderPipeline(input) {
15591
15665
  pageMotionBlur: job.config.pageMotionBlur,
15592
15666
  captureQuality: captureOptions.quality
15593
15667
  });
15594
- const segmentDir = segmentDirFor(join31(projectDir, "renders"), segmentPlanHash);
15668
+ const segmentDir = segmentDirFor(join32(projectDir, "renders"), segmentPlanHash);
15595
15669
  let completedSegments = /* @__PURE__ */ new Set();
15596
15670
  if (job.config.resumeSegments === true) {
15597
15671
  const existing = readSegmentManifest(segmentDir);
@@ -16214,7 +16288,7 @@ async function executeRenderPipeline(input) {
16214
16288
  }
16215
16289
  if (job.config.debug) {
16216
16290
  if (!isPngSequence && !isHls && existsSync21(stagedOutputPath)) {
16217
- const debugOutput = join31(workDir, `output${videoExt}`);
16291
+ const debugOutput = join32(workDir, `output${videoExt}`);
16218
16292
  copyFileSync5(stagedOutputPath, debugOutput);
16219
16293
  }
16220
16294
  }
@@ -16329,14 +16403,14 @@ import {
16329
16403
  referenceBackgroundResult as referenceBackgroundResult6
16330
16404
  } from "@hyperframes/engine";
16331
16405
  import { mkdirSync as mkdirSync20, mkdtempSync, readFileSync as readFileSync15, rmSync as rmSync18 } from "node:fs";
16332
- import { join as join45 } from "node:path";
16406
+ import { join as join46 } from "node:path";
16333
16407
  import { tmpdir as tmpdir4 } from "node:os";
16334
16408
 
16335
16409
  // src/services/distributed/mp4Stitch.ts
16336
16410
  import { createReadStream as createReadStream3, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync13 } from "node:fs";
16337
16411
  import { open } from "node:fs/promises";
16338
16412
  import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
16339
- import { basename as basename7, dirname as dirname14, join as join32 } from "node:path";
16413
+ import { basename as basename7, dirname as dirname14, join as join33 } from "node:path";
16340
16414
  import { finished, pipeline } from "node:stream/promises";
16341
16415
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
16342
16416
  function boxAt(src, off, at, limit) {
@@ -16703,13 +16777,13 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
16703
16777
  const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
16704
16778
  mkdirSync13(dirname14(outputPath), { recursive: true });
16705
16779
  const workDir = createStagingDir4(dirname14(outputPath), `${basename7(outputPath)}.stitch-`);
16706
- const out = createWriteStream(join32(workDir, "out.mp4"));
16780
+ const out = createWriteStream(join33(workDir, "out.mp4"));
16707
16781
  try {
16708
16782
  out.write(header);
16709
16783
  for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
16710
16784
  out.end();
16711
16785
  await finished(out);
16712
- renameWithRetry7(join32(workDir, "out.mp4"), outputPath);
16786
+ renameWithRetry7(join33(workDir, "out.mp4"), outputPath);
16713
16787
  } finally {
16714
16788
  out.destroy();
16715
16789
  rmSync13(workDir, { recursive: true, force: true });
@@ -16732,11 +16806,12 @@ import {
16732
16806
  rmSync as rmSync14,
16733
16807
  writeFileSync as writeFileSync10
16734
16808
  } from "node:fs";
16735
- import { extname as extname6, isAbsolute as isAbsolute3, join as join40, relative as relative5, sep as sep3 } from "node:path";
16809
+ import { extname as extname6, isAbsolute as isAbsolute3, join as join41, relative as relative6, sep as sep3 } from "node:path";
16736
16810
  import {
16737
16811
  fpsToNumber as fpsToNumber9,
16738
16812
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
16739
16813
  } from "@hyperframes/core";
16814
+ import { isSafePath as isSafePath2 } from "@hyperframes/core/safe-path";
16740
16815
  import {
16741
16816
  getEncoderPreset as getEncoderPreset4,
16742
16817
  keyframeIntervalToGopSize as keyframeIntervalToGopSize3,
@@ -16748,7 +16823,7 @@ import {
16748
16823
  } from "@hyperframes/engine";
16749
16824
 
16750
16825
  // src/services/distributed/planFrameCost.ts
16751
- import { join as join35 } from "node:path";
16826
+ import { join as join36 } from "node:path";
16752
16827
  import {
16753
16828
  closeCaptureSession as closeCaptureSession9,
16754
16829
  createCaptureSession as createCaptureSession9,
@@ -16758,7 +16833,7 @@ import {
16758
16833
 
16759
16834
  // src/services/distributed/chunkFrames.ts
16760
16835
  import { existsSync as existsSync23, readdirSync as readdirSync7 } from "node:fs";
16761
- import { extname as extname4, join as join34 } from "node:path";
16836
+ import { extname as extname4, join as join35 } from "node:path";
16762
16837
  import {
16763
16838
  compositionRequiresWebGpu as compositionRequiresWebGpu3,
16764
16839
  createVideoFrameInjector as createVideoFrameInjector3,
@@ -16767,7 +16842,7 @@ import {
16767
16842
 
16768
16843
  // src/services/distributed/shared.ts
16769
16844
  import { execFile as execFileCallback } from "node:child_process";
16770
- import { dirname as dirname15, join as join33 } from "node:path";
16845
+ import { dirname as dirname15, join as join34 } from "node:path";
16771
16846
  import { existsSync as existsSync22, readFileSync as readFileSync10 } from "node:fs";
16772
16847
  import { fileURLToPath as fileURLToPath5 } from "node:url";
16773
16848
  import { promisify as promisify2 } from "node:util";
@@ -16783,7 +16858,7 @@ function isPlanAudioArtifactPath(path) {
16783
16858
  }
16784
16859
  function resolvePlanAudioPath(planDir) {
16785
16860
  for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
16786
- const candidate = join33(planDir, name);
16861
+ const candidate = join34(planDir, name);
16787
16862
  if (existsSync22(candidate)) return candidate;
16788
16863
  }
16789
16864
  return null;
@@ -17035,7 +17110,8 @@ function buildSyntheticRenderJob(input) {
17035
17110
  producerConfig: input.producerConfig,
17036
17111
  variables: input.variables,
17037
17112
  strictVariables: input.strictVariables,
17038
- pageMotionBlur: input.pageMotionBlur
17113
+ pageMotionBlur: input.pageMotionBlur,
17114
+ allowOutsideProjectAssets: input.allowOutsideProjectAssets
17039
17115
  };
17040
17116
  return createRenderJob(renderConfig);
17041
17117
  }
@@ -17045,7 +17121,7 @@ function readProducerVersion() {
17045
17121
  const startDir = dirname15(fileURLToPath5(import.meta.url));
17046
17122
  let current = startDir;
17047
17123
  for (let i = 0; i < 10; i++) {
17048
- const candidate = join33(current, "package.json");
17124
+ const candidate = join34(current, "package.json");
17049
17125
  if (existsSync22(candidate)) {
17050
17126
  try {
17051
17127
  const pkg = JSON.parse(readFileSync10(candidate, "utf-8"));
@@ -17100,7 +17176,7 @@ function frameNumberFromFileName(name) {
17100
17176
  function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
17101
17177
  const result = [];
17102
17178
  for (const v of videos) {
17103
- const outputDir = join34(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
17179
+ const outputDir = join35(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
17104
17180
  if (!existsSync23(outputDir)) {
17105
17181
  throw new Error(
17106
17182
  `[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
@@ -17119,7 +17195,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
17119
17195
  if (!frameName) continue;
17120
17196
  const frameNumber = indexMode === "sparse-v2" ? frameNumberFromFileName(frameName) : null;
17121
17197
  const frameIndex = frameNumber === null ? i : frameNumber - 1;
17122
- framePaths.set(frameIndex, join34(outputDir, frameName));
17198
+ framePaths.set(frameIndex, join35(outputDir, frameName));
17123
17199
  }
17124
17200
  result.push({
17125
17201
  videoId: v.videoId,
@@ -17199,7 +17275,7 @@ async function extractDeferredVideoFramesForChunk(input) {
17199
17275
  sourceOf: (video) => {
17200
17276
  const range = planned.get(video.videoId).deferredRange;
17201
17277
  const remoteUrl = remoteSources[range.sourcePath];
17202
- const sourcePath = remoteUrl ?? join34(input.planDir, ...range.sourcePath.split("/"));
17278
+ const sourcePath = remoteUrl ?? join35(input.planDir, ...range.sourcePath.split("/"));
17203
17279
  if (remoteUrl === void 0 && !existsSync23(sourcePath)) {
17204
17280
  throw new RenderChunkValidationError(
17205
17281
  MISSING_PLAN_ARTIFACT,
@@ -17230,12 +17306,12 @@ async function measurePlanSecondsPerFrame(input) {
17230
17306
  planVideos,
17231
17307
  frames: sampled,
17232
17308
  fps: fpsRatio,
17233
- outputRoot: join35(workDir, "frame-cost-video-frames"),
17309
+ outputRoot: join36(workDir, "frame-cost-video-frames"),
17234
17310
  cfg: input.cfg
17235
17311
  })
17236
17312
  ];
17237
17313
  const lookup = extracted.length > 0 ? createFrameLookupTable4(planVideos.videos, extracted, resolveRenderFpsConfig(fpsRatio).value) : null;
17238
- const compiledDir = join35(planDir, "compiled");
17314
+ const compiledDir = join36(planDir, "compiled");
17239
17315
  const fileServer = await createFileServer({
17240
17316
  projectDir: compiledDir,
17241
17317
  compiledDir,
@@ -17247,7 +17323,7 @@ async function measurePlanSecondsPerFrame(input) {
17247
17323
  try {
17248
17324
  session = await createCaptureSession9(
17249
17325
  fileServer.url,
17250
- join35(workDir, "frame-cost"),
17326
+ join36(workDir, "frame-cost"),
17251
17327
  buildChunkCaptureOptions({
17252
17328
  dimensions: { ...input, fpsNum: fps, fpsDen: 1 },
17253
17329
  encoder: input,
@@ -17344,7 +17420,7 @@ function buildWeightedChunkSlices(weights, chunkCount, minFrames, maxFrames) {
17344
17420
  }
17345
17421
 
17346
17422
  // src/services/render/planReferenceBackground.ts
17347
- import { join as join36 } from "node:path";
17423
+ import { join as join37 } from "node:path";
17348
17424
  import {
17349
17425
  closeCaptureSession as closeCaptureSession10,
17350
17426
  createCaptureSession as createCaptureSession10,
@@ -17357,14 +17433,14 @@ async function readPlanReferenceBackground(input) {
17357
17433
  try {
17358
17434
  server = await createFileServer({
17359
17435
  projectDir: input.projectDir,
17360
- compiledDir: join36(input.workDir, "compiled"),
17436
+ compiledDir: join37(input.workDir, "compiled"),
17361
17437
  port: 0,
17362
17438
  preHeadScripts: [VIRTUAL_TIME_SHIM],
17363
17439
  fps: input.options.fps
17364
17440
  });
17365
17441
  session = await createCaptureSession10(
17366
17442
  server.url,
17367
- join36(input.workDir, "reference"),
17443
+ join37(input.workDir, "reference"),
17368
17444
  {
17369
17445
  ...input.options,
17370
17446
  requiresWebGpu: false
@@ -17401,7 +17477,7 @@ async function readPlanReferenceBackground(input) {
17401
17477
 
17402
17478
  // src/services/render/stages/freezePlan.ts
17403
17479
  import { existsSync as existsSync24, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
17404
- import { join as join37, relative as relative3, resolve as resolve9 } from "node:path";
17480
+ import { join as join38, relative as relative4, resolve as resolve9 } from "node:path";
17405
17481
  import {
17406
17482
  REFERENCE_BACKGROUND_FIELD,
17407
17483
  referenceBackgroundResult as referenceBackgroundResult3
@@ -17619,12 +17695,12 @@ function listPlanFiles(planDir) {
17619
17695
  function walk(dir) {
17620
17696
  const entries = readdirSync8(dir, { withFileTypes: true });
17621
17697
  for (const entry of entries) {
17622
- const full = join37(dir, entry.name);
17698
+ const full = join38(dir, entry.name);
17623
17699
  if (entry.isDirectory()) {
17624
17700
  walk(full);
17625
17701
  } else if (entry.isFile()) {
17626
17702
  results.push({
17627
- planRelativePath: relative3(rootResolved, full).split(/[\\/]+/).join("/"),
17703
+ planRelativePath: relative4(rootResolved, full).split(/[\\/]+/).join("/"),
17628
17704
  absolutePath: full
17629
17705
  });
17630
17706
  }
@@ -17660,15 +17736,15 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
17660
17736
  function writePlanRemoteFiles(planDir, files) {
17661
17737
  if (files.length === 0) return;
17662
17738
  const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
17663
- writeFileSync8(join37(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
17739
+ writeFileSync8(join38(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
17664
17740
  }
17665
17741
  function readPlanRemoteFiles(planDir) {
17666
- const path = join37(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
17742
+ const path = join38(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
17667
17743
  return existsSync24(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
17668
17744
  }
17669
17745
  function recomputePlanHashFromPlanDir(planDir, digests) {
17670
- const planJsonPath = join37(planDir, "plan.json");
17671
- const encoderJsonPath = join37(planDir, "meta", "encoder.json");
17746
+ const planJsonPath = join38(planDir, "plan.json");
17747
+ const encoderJsonPath = join38(planDir, "meta", "encoder.json");
17672
17748
  if (!existsSync24(planJsonPath)) {
17673
17749
  throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
17674
17750
  }
@@ -17705,18 +17781,18 @@ async function freezePlan(input) {
17705
17781
  if (!existsSync24(planDir)) {
17706
17782
  throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
17707
17783
  }
17708
- const metaDir = join37(planDir, "meta");
17784
+ const metaDir = join38(planDir, "meta");
17709
17785
  if (!existsSync24(metaDir)) mkdirSync14(metaDir, { recursive: true });
17710
17786
  writeFileSync8(
17711
- join37(metaDir, "composition.json"),
17787
+ join38(metaDir, "composition.json"),
17712
17788
  `${JSON.stringify(composition, null, 2)}
17713
17789
  `,
17714
17790
  "utf-8"
17715
17791
  );
17716
17792
  const encoderForCanonical = stripUndefined(encoder);
17717
17793
  const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
17718
- writeFileSync8(join37(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
17719
- writeFileSync8(join37(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
17794
+ writeFileSync8(join38(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
17795
+ writeFileSync8(join38(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
17720
17796
  `, "utf-8");
17721
17797
  const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
17722
17798
  const planHash = computePlanHash({
@@ -17741,7 +17817,7 @@ async function freezePlan(input) {
17741
17817
  duration: durationSeconds,
17742
17818
  hasAudio
17743
17819
  };
17744
- const planJsonPath = join37(planDir, "plan.json");
17820
+ const planJsonPath = join38(planDir, "plan.json");
17745
17821
  writeFileSync8(planJsonPath, `${JSON.stringify(planJson, null, 2)}
17746
17822
  `, "utf-8");
17747
17823
  return { planJsonPath, planHash };
@@ -17785,7 +17861,7 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
17785
17861
  // src/services/distributed/chunkAudio.ts
17786
17862
  import { closeSync as closeSync6, existsSync as existsSync25, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync6, readFileSync as readFileSync12 } from "node:fs";
17787
17863
  import { writeFileSync as writeFileSync9, writeSync } from "node:fs";
17788
- import { join as join38 } from "node:path";
17864
+ import { join as join39 } from "node:path";
17789
17865
  import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
17790
17866
  function audioCutForChunk(grid, chunks, index, fps) {
17791
17867
  const firstPacketAt = (frame) => Math.min(
@@ -17873,7 +17949,7 @@ async function writeChunkAudioSlices(input) {
17873
17949
  });
17874
17950
  const bytes = readFileSync12(input.audioPath);
17875
17951
  const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
17876
- mkdirSync15(join38(input.planDir, SLICE_DIR), { recursive: true });
17952
+ mkdirSync15(join39(input.planDir, SLICE_DIR), { recursive: true });
17877
17953
  input.chunks.forEach((_, index) => {
17878
17954
  const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
17879
17955
  if (!cut) return;
@@ -17881,17 +17957,17 @@ async function writeChunkAudioSlices(input) {
17881
17957
  const start = offsets[cut.firstPacket];
17882
17958
  layout.partStarts[index] = start;
17883
17959
  const end = offsets[last] + track.sizes[last];
17884
- writeFileSync9(join38(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
17960
+ writeFileSync9(join39(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
17885
17961
  });
17886
17962
  const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
17887
- writeFileSync9(join38(input.planDir, SLICE_FRAME), Buffer.concat(frame));
17888
- writeFileSync9(join38(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
17963
+ writeFileSync9(join39(input.planDir, SLICE_FRAME), Buffer.concat(frame));
17964
+ writeFileSync9(join39(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
17889
17965
  }
17890
17966
  function chunkAudioSource(planDir, chunkIndex, scratchPath) {
17891
- const layoutPath = join38(planDir, SLICE_LAYOUT);
17967
+ const layoutPath = join39(planDir, SLICE_LAYOUT);
17892
17968
  if (!existsSync25(layoutPath)) return resolvePlanAudioPath(planDir);
17893
17969
  const layout = JSON.parse(readFileSync12(layoutPath, "utf-8"));
17894
- const frame = readFileSync12(join38(planDir, SLICE_FRAME));
17970
+ const frame = readFileSync12(join39(planDir, SLICE_FRAME));
17895
17971
  const fd = openSync6(scratchPath, "w");
17896
17972
  try {
17897
17973
  writeSync(fd, frame, 0, layout.payloadStart, 0);
@@ -17904,7 +17980,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
17904
17980
  );
17905
17981
  const start = layout.partStarts[chunkIndex];
17906
17982
  if (start !== void 0) {
17907
- const part = readFileSync12(join38(planDir, chunkAudioSlicePath(chunkIndex)));
17983
+ const part = readFileSync12(join39(planDir, chunkAudioSlicePath(chunkIndex)));
17908
17984
  writeSync(fd, part, 0, part.length, start);
17909
17985
  }
17910
17986
  ftruncateSync(fd, layout.sizeBytes);
@@ -17960,7 +18036,7 @@ async function muxChunkWithAudio(input) {
17960
18036
  // src/services/distributed/planSize.ts
17961
18037
  import { createHash as createHash9 } from "node:crypto";
17962
18038
  import { lstatSync as lstatSync2, readdirSync as readdirSync9 } from "node:fs";
17963
- import { extname as extname5, join as join39, relative as relative4 } from "node:path";
18039
+ import { extname as extname5, join as join40, relative as relative5 } from "node:path";
17964
18040
  var MAX_TOP_COMPONENTS = 10;
17965
18041
  var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
17966
18042
  ".aac",
@@ -18049,7 +18125,7 @@ function recordFile(result, components, rootDir, rootKind, filePath) {
18049
18125
  } catch {
18050
18126
  return;
18051
18127
  }
18052
- const rel = relative4(rootDir, filePath);
18128
+ const rel = relative5(rootDir, filePath);
18053
18129
  const segments = rel.split(/[\\/]+/).filter(Boolean);
18054
18130
  const classified = classifyFile(segments, rootKind);
18055
18131
  result.totalBytes += sizeBytes;
@@ -18072,7 +18148,7 @@ function walkRegularFiles(dir, visit) {
18072
18148
  return;
18073
18149
  }
18074
18150
  for (const entry of entries) {
18075
- const full = join39(dir, entry.name);
18151
+ const full = join40(dir, entry.name);
18076
18152
  if (entry.isDirectory()) {
18077
18153
  walkRegularFiles(full, visit);
18078
18154
  } else if (entry.isFile()) {
@@ -18288,13 +18364,13 @@ function assertPositiveInteger2(name, value) {
18288
18364
  }
18289
18365
  var FREEZE_OWNED_PLAN_FILES = [
18290
18366
  "plan.json",
18291
- join40("meta", "composition.json"),
18292
- join40("meta", "encoder.json"),
18293
- join40("meta", "chunks.json")
18367
+ join41("meta", "composition.json"),
18368
+ join41("meta", "encoder.json"),
18369
+ join41("meta", "chunks.json")
18294
18370
  ];
18295
18371
  function removeFreezeOwnedPlanFiles(planDir) {
18296
18372
  for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
18297
- rmSync14(join40(planDir, relativePath), { force: true });
18373
+ rmSync14(join41(planDir, relativePath), { force: true });
18298
18374
  }
18299
18375
  }
18300
18376
  function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
@@ -18433,7 +18509,7 @@ function resolveDistributedEngineConfig(config) {
18433
18509
  };
18434
18510
  }
18435
18511
  function pathInside(root, path) {
18436
- const rel = relative5(root, path);
18512
+ const rel = relative6(root, path);
18437
18513
  return rel === "" || rel.startsWith("..") || isAbsolute3(rel) ? null : rel;
18438
18514
  }
18439
18515
  function stableSourcePath(roots, srcPath) {
@@ -18449,19 +18525,19 @@ function createVideoSourceShipper(input) {
18449
18525
  const known = shipped.get(srcPath);
18450
18526
  if (known) return known;
18451
18527
  const stagedRel = pathInside(input.workVideoFramesDir, srcPath);
18452
- const current = stagedRel === null ? srcPath : join40(input.planDir, "video-frames", stagedRel);
18528
+ const current = stagedRel === null ? srcPath : join41(input.planDir, "video-frames", stagedRel);
18453
18529
  let result = null;
18454
18530
  for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
18455
18531
  const rel = pathInside(root, srcPath);
18456
- if (rel !== null && (existsSync26(join40(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
18532
+ if (rel !== null && (existsSync26(join41(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
18457
18533
  result = ["compiled", ...rel.split(sep3)].join("/");
18458
18534
  break;
18459
18535
  }
18460
18536
  }
18461
18537
  if (result === null) {
18462
18538
  result = `video-sources/${shipped.size}${extname6(current)}`;
18463
- const destination = join40(input.planDir, ...result.split("/"));
18464
- mkdirSync16(join40(input.planDir, "video-sources"), { recursive: true });
18539
+ const destination = join41(input.planDir, ...result.split("/"));
18540
+ mkdirSync16(join41(input.planDir, "video-sources"), { recursive: true });
18465
18541
  try {
18466
18542
  linkSync(current, destination);
18467
18543
  } catch {
@@ -18509,34 +18585,36 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
18509
18585
  producerConfig: cfg,
18510
18586
  variables: config.variables,
18511
18587
  strictVariables: config.strictVariables,
18512
- pageMotionBlur: config.pageMotionBlur
18588
+ pageMotionBlur: config.pageMotionBlur,
18589
+ allowOutsideProjectAssets: options.allowOutsideProjectAssets === true
18513
18590
  });
18514
18591
  const entryFile = config.entryFile ?? "index.html";
18515
- const htmlPath = join40(projectDir, entryFile);
18592
+ const htmlPath = join41(projectDir, entryFile);
18516
18593
  if (!existsSync26(htmlPath)) {
18517
18594
  throw new Error(`[plan] entry file not found: ${htmlPath}`);
18518
18595
  }
18519
- const workDir = join40(planDir, ".plan-work");
18596
+ const workDir = join41(planDir, ".plan-work");
18520
18597
  rmSync14(workDir, { recursive: true, force: true });
18521
18598
  mkdirSync16(workDir, { recursive: true });
18522
- const compiledDir = join40(workDir, "compiled");
18599
+ const compiledDir = join41(workDir, "compiled");
18523
18600
  mkdirSync16(compiledDir, { recursive: true });
18524
18601
  let stageStarted = Date.now();
18525
18602
  cpSync2(projectDir, compiledDir, {
18526
18603
  recursive: true,
18527
18604
  dereference: true,
18528
18605
  filter: (src) => {
18529
- const rel = relative5(projectDir, src);
18606
+ const rel = relative6(projectDir, src);
18530
18607
  if (rel === "" || rel.startsWith("..")) return true;
18608
+ if (!job.config.allowOutsideProjectAssets && !isSafePath2(projectDir, src)) return false;
18531
18609
  const firstSegment = rel.split(sep3, 1)[0];
18532
18610
  return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
18533
18611
  }
18534
18612
  });
18535
18613
  logPlanStage(log, "copy", stageStarted);
18536
- const finalCompiledDir = join40(planDir, "compiled");
18614
+ const finalCompiledDir = join41(planDir, "compiled");
18537
18615
  const needsAlpha = outputNeedsAlpha(config.format);
18538
18616
  const remoteFiles = Object.entries(options.remoteFiles ?? {});
18539
- const remoteLocalPath = (rel) => join40(projectDir, ...rel.split("/"));
18617
+ const remoteLocalPath = (rel) => join41(projectDir, ...rel.split("/"));
18540
18618
  for (const [, file] of remoteFiles) {
18541
18619
  declareContentAddressedUrl(file.url, file.sha256);
18542
18620
  if (file.probeFactsUrl) declareProbeFactsUrl(file.url, file.probeFactsUrl);
@@ -18740,10 +18818,10 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
18740
18818
  let stageStarted = Date.now();
18741
18819
  const extractResult = await extractPlanVideos(c, options.deferVideoExtraction);
18742
18820
  logPlanStage(log, "extract", stageStarted);
18743
- const stagedVideoFrames = join40(compiledDir, "__hyperframes_video_frames");
18744
- const videoFramesDst = join40(planDir, "video-frames");
18821
+ const stagedVideoFrames = join41(compiledDir, "__hyperframes_video_frames");
18822
+ const videoFramesDst = join41(planDir, "video-frames");
18745
18823
  if (existsSync26(videoFramesDst)) rmSync14(videoFramesDst, { recursive: true, force: true });
18746
- const videoSourcesDir = join40(planDir, "video-sources");
18824
+ const videoSourcesDir = join41(planDir, "video-sources");
18747
18825
  rmSync14(videoSourcesDir, { recursive: true, force: true });
18748
18826
  if (existsSync26(stagedVideoFrames)) {
18749
18827
  renameWithRetry8(stagedVideoFrames, videoFramesDst);
@@ -18780,7 +18858,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
18780
18858
  };
18781
18859
  })
18782
18860
  });
18783
- mkdirSync16(join40(planDir, "meta"), { recursive: true });
18861
+ mkdirSync16(join41(planDir, "meta"), { recursive: true });
18784
18862
  writePlanRemoteFiles(
18785
18863
  planDir,
18786
18864
  remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
@@ -18790,7 +18868,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
18790
18868
  }))
18791
18869
  );
18792
18870
  writeFileSync10(
18793
- join40(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
18871
+ join41(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
18794
18872
  JSON.stringify(planVideosJson, null, 2),
18795
18873
  "utf-8"
18796
18874
  );
@@ -18870,7 +18948,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
18870
18948
  if (audioResult?.audioError) {
18871
18949
  applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
18872
18950
  }
18873
- const planAudioPath = join40(planDir, PLAN_AUDIO_RELATIVE_PATH);
18951
+ const planAudioPath = join41(planDir, PLAN_AUDIO_RELATIVE_PATH);
18874
18952
  if (audioResult?.hasAudio && existsSync26(audioResult.audioOutputPath)) {
18875
18953
  renameWithRetry8(audioResult.audioOutputPath, planAudioPath);
18876
18954
  }
@@ -18996,7 +19074,7 @@ async function plan(projectDir, config, planDir, options = {}) {
18996
19074
  import { randomBytes } from "node:crypto";
18997
19075
  import { existsSync as existsSync29, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync13 } from "node:fs";
18998
19076
  import { cpus as cpus3 } from "node:os";
18999
- import { join as join44 } from "node:path";
19077
+ import { join as join45 } from "node:path";
19000
19078
  import {
19001
19079
  assertSwiftShader,
19002
19080
  BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
@@ -19031,7 +19109,7 @@ import {
19031
19109
  writeFileSync as writeFileSync12
19032
19110
  } from "node:fs";
19033
19111
  import { tmpdir as tmpdir3 } from "node:os";
19034
- import { dirname as dirname17, isAbsolute as isAbsolute4, join as join43, relative as relative6, resolve as resolve10, sep as sep4 } from "node:path";
19112
+ import { dirname as dirname17, isAbsolute as isAbsolute4, join as join44, relative as relative7, resolve as resolve10, sep as sep4 } from "node:path";
19035
19113
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
19036
19114
  import {
19037
19115
  createFrameLookupTable as createFrameLookupTable5,
@@ -19050,7 +19128,7 @@ import {
19050
19128
  writeFileSync as writeFileSync11
19051
19129
  } from "node:fs";
19052
19130
  import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
19053
- import { dirname as dirname16, join as join42 } from "node:path";
19131
+ import { dirname as dirname16, join as join43 } from "node:path";
19054
19132
 
19055
19133
  // src/services/distributed/planV2Errors.ts
19056
19134
  var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
@@ -19065,7 +19143,7 @@ var PlanV2IntegrityError = class extends Error {
19065
19143
  };
19066
19144
 
19067
19145
  // src/services/distributed/planV2Layout.ts
19068
- import { join as join41 } from "node:path";
19146
+ import { join as join42 } from "node:path";
19069
19147
  var SHA256_PATTERN = /^[0-9a-f]{64}$/;
19070
19148
  function assertPlanV2Sha256(value, field) {
19071
19149
  if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
@@ -19075,7 +19153,7 @@ function assertPlanV2Sha256(value, field) {
19075
19153
  }
19076
19154
  function planV2BlobPath(root, sha256) {
19077
19155
  const digest = assertPlanV2Sha256(sha256, "artifact sha256");
19078
- return join41(root, "artifacts", "sha256", digest.slice(0, 2), digest);
19156
+ return join42(root, "artifacts", "sha256", digest.slice(0, 2), digest);
19079
19157
  }
19080
19158
 
19081
19159
  // src/services/distributed/planV2Publisher.ts
@@ -19131,7 +19209,7 @@ var LocalPlanV2ArtifactPublisher = class {
19131
19209
  if (existsSync27(destinationPath)) return;
19132
19210
  mkdirSync17(dirname16(destinationPath), { recursive: true });
19133
19211
  const stagingDir = createStagingDir5(dirname16(destinationPath), ".plan-v2-blob-");
19134
- const temporaryPath = join42(stagingDir, "blob");
19212
+ const temporaryPath = join43(stagingDir, "blob");
19135
19213
  try {
19136
19214
  try {
19137
19215
  this.#linkFile(blob.sourcePath, temporaryPath);
@@ -19152,7 +19230,7 @@ var LocalPlanV2ArtifactPublisher = class {
19152
19230
  );
19153
19231
  }
19154
19232
  }
19155
- writeFileSync11(join42(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
19233
+ writeFileSync11(join43(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
19156
19234
  renameWithRetry9(this.temporaryDir, this.destinationDir);
19157
19235
  this.#committed = true;
19158
19236
  }
@@ -19198,12 +19276,12 @@ function listFiles(root) {
19198
19276
  const rootResolved = resolve10(root);
19199
19277
  function walk(dir) {
19200
19278
  for (const entry of readdirSync10(dir, { withFileTypes: true })) {
19201
- const absolutePath = join43(dir, entry.name);
19279
+ const absolutePath = join44(dir, entry.name);
19202
19280
  if (entry.isDirectory()) {
19203
19281
  walk(absolutePath);
19204
19282
  } else if (entry.isFile()) {
19205
19283
  files.push({
19206
- path: relative6(rootResolved, absolutePath).split(sep4).join("/"),
19284
+ path: relative7(rootResolved, absolutePath).split(sep4).join("/"),
19207
19285
  absolutePath
19208
19286
  });
19209
19287
  } else {
@@ -19225,13 +19303,13 @@ function assertValidExtractionCacheCompleteSentinel(path) {
19225
19303
  }
19226
19304
  }
19227
19305
  function validateExtractionCacheCompleteSentinels(executionPlanDir) {
19228
- const videoRoot = join43(executionPlanDir, "video-frames");
19306
+ const videoRoot = join44(executionPlanDir, "video-frames");
19229
19307
  if (!existsSync28(videoRoot)) return;
19230
19308
  for (const videoEntry of readdirSync10(videoRoot, { withFileTypes: true })) {
19231
19309
  if (!videoEntry.isDirectory()) continue;
19232
- const videoDir = join43(videoRoot, videoEntry.name);
19310
+ const videoDir = join44(videoRoot, videoEntry.name);
19233
19311
  if (readdirSync10(videoDir).includes(EXTRACTION_CACHE_COMPLETE_SENTINEL)) {
19234
- const sentinelPath = join43(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
19312
+ const sentinelPath = join44(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
19235
19313
  assertValidExtractionCacheCompleteSentinel(sentinelPath);
19236
19314
  }
19237
19315
  }
@@ -19278,7 +19356,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
19278
19356
  if (video.deferredRange) {
19279
19357
  const framePaths2 = /* @__PURE__ */ new Map();
19280
19358
  for (let index = 0; index < video.totalFrames; index++) {
19281
- framePaths2.set(index, join43(outputDir, String(index)));
19359
+ framePaths2.set(index, join44(outputDir, String(index)));
19282
19360
  }
19283
19361
  return { ...video, outputDir, framePaths: framePaths2, ownedByLookup: false };
19284
19362
  }
@@ -19286,7 +19364,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
19286
19364
  const framePaths = /* @__PURE__ */ new Map();
19287
19365
  for (const frameName of frameNames) {
19288
19366
  if (frameName === EXTRACTION_CACHE_COMPLETE_SENTINEL) {
19289
- assertValidExtractionCacheCompleteSentinel(join43(outputDir, frameName));
19367
+ assertValidExtractionCacheCompleteSentinel(join44(outputDir, frameName));
19290
19368
  continue;
19291
19369
  }
19292
19370
  const match = /(\d+)(?=\.[^.]+$)/.exec(frameName);
@@ -19305,7 +19383,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
19305
19383
  `duplicate extracted frame index ${frameIndex} in ${outputDir}`
19306
19384
  );
19307
19385
  }
19308
- framePaths.set(frameIndex, join43(outputDir, frameName));
19386
+ framePaths.set(frameIndex, join44(outputDir, frameName));
19309
19387
  }
19310
19388
  return {
19311
19389
  ...video,
@@ -19326,7 +19404,7 @@ function parsePlanVideosJson2(value) {
19326
19404
  }
19327
19405
  }
19328
19406
  function materializeExtractedVideoDirectories(planDir) {
19329
- const videosPath = join43(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
19407
+ const videosPath = join44(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
19330
19408
  if (!existsSync28(videosPath)) return;
19331
19409
  const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
19332
19410
  for (const video of videos.extracted) {
@@ -19360,13 +19438,13 @@ function parseChunkSlices(value) {
19360
19438
  });
19361
19439
  }
19362
19440
  function buildVideoChunkDependencies(executionPlanDir, dimensions) {
19363
- const videoRoot = join43(executionPlanDir, "video-frames");
19441
+ const videoRoot = join44(executionPlanDir, "video-frames");
19364
19442
  const hasExtractedFrames = existsSync28(videoRoot) && listFiles(videoRoot).length > 0;
19365
- const videosPath = join43(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
19443
+ const videosPath = join44(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
19366
19444
  if (!existsSync28(videosPath)) {
19367
19445
  return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
19368
19446
  }
19369
- const chunksPath = join43(executionPlanDir, "meta", "chunks.json");
19447
+ const chunksPath = join44(executionPlanDir, "meta", "chunks.json");
19370
19448
  const videos = readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH);
19371
19449
  const chunks = readJsonFile(chunksPath, "meta/chunks.json");
19372
19450
  const parsedVideos = parsePlanVideosJson2(videos);
@@ -19403,7 +19481,7 @@ function collectChunkVideoDependencies(input) {
19403
19481
  for (let frame = chunk.startFrame; frame < chunk.endFrame; frame++) {
19404
19482
  const globalTime = frame * input.fpsDen / input.fpsNum;
19405
19483
  for (const [videoId, payload] of input.table.getActiveFramePayloads(globalTime)) {
19406
- const path = input.deferredSources.get(videoId) ?? relative6(resolve10(input.executionPlanDir), payload.framePath).split(sep4).join("/");
19484
+ const path = input.deferredSources.get(videoId) ?? relative7(resolve10(input.executionPlanDir), payload.framePath).split(sep4).join("/");
19407
19485
  assertSafeRelativePath(path);
19408
19486
  const indexes = mutable.get(path) ?? /* @__PURE__ */ new Set();
19409
19487
  indexes.add(chunk.index);
@@ -19423,7 +19501,7 @@ function writeBlob(sourcePath, destinationPath) {
19423
19501
  if (existsSync28(destinationPath)) return;
19424
19502
  mkdirSync18(dirname17(destinationPath), { recursive: true });
19425
19503
  const temporaryDir = createStagingDir6(dirname17(destinationPath), ".plan-v2-blob-");
19426
- const temporaryPath = join43(temporaryDir, "blob");
19504
+ const temporaryPath = join44(temporaryDir, "blob");
19427
19505
  try {
19428
19506
  copyFileSync8(sourcePath, temporaryPath);
19429
19507
  renameWithRetry10(temporaryPath, destinationPath);
@@ -19459,7 +19537,7 @@ async function putTasks(tasks) {
19459
19537
  if (failure) throw failure.reason;
19460
19538
  }
19461
19539
  function buildPlanV2Publication(executionPlanDir, digests) {
19462
- const executionPlanPath = join43(executionPlanDir, "plan.json");
19540
+ const executionPlanPath = join44(executionPlanDir, "plan.json");
19463
19541
  if (!existsSync28(executionPlanPath)) {
19464
19542
  throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
19465
19543
  }
@@ -19487,7 +19565,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
19487
19565
  }
19488
19566
  validateExtractionCacheCompleteSentinels(executionPlanDir);
19489
19567
  const videoDependencyPlan = buildVideoChunkDependencies(executionPlanDir, dimensions);
19490
- const encoder = readJsonFile(join43(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
19568
+ const encoder = readJsonFile(join44(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
19491
19569
  const files = listFiles(executionPlanDir);
19492
19570
  const chunkAudio = !isRecord3(encoder) || encoder.chunksCarryAudio !== true ? "none" : files.some((file) => chunkAudioSliceTarget(file.path) !== null) ? "sliced" : "whole";
19493
19571
  for (const file of files) {
@@ -19554,7 +19632,7 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
19554
19632
  writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
19555
19633
  }
19556
19634
  writeFileSync12(
19557
- join43(tempDir, "plan.json"),
19635
+ join44(tempDir, "plan.json"),
19558
19636
  canonicalJsonStringify(publication.manifest),
19559
19637
  "utf-8"
19560
19638
  );
@@ -19606,7 +19684,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
19606
19684
  // artifactTargets ships every compiled/ file to all chunks, so each is in the manifest.
19607
19685
  whileAudioMixes: () => putBlobs(
19608
19686
  publisher,
19609
- listFiles(join43(stagingRoot, "compiled")).map(
19687
+ listFiles(join44(stagingRoot, "compiled")).map(
19610
19688
  (file) => publishBlobFor(file.absolutePath, digests)
19611
19689
  )
19612
19690
  ),
@@ -19644,7 +19722,7 @@ function resultFromManifest(planV2Dir, manifest) {
19644
19722
  isRecord3(executionPlan) ? executionPlan[REFERENCE_BACKGROUND_FIELD3] : void 0
19645
19723
  ),
19646
19724
  planDir: planV2Dir,
19647
- manifestPath: join43(planV2Dir, "plan.json"),
19725
+ manifestPath: join44(planV2Dir, "plan.json"),
19648
19726
  planProtocol: PLAN_PROTOCOL_V2,
19649
19727
  planHash: manifest.planHash,
19650
19728
  sourcePlanV1Hash: getPlanV2ExecutionPlanHash(manifest),
@@ -19780,7 +19858,7 @@ function parsePlanV2Manifest(value) {
19780
19858
  return parsed;
19781
19859
  }
19782
19860
  function readPlanV2Manifest(planV2Dir) {
19783
- const manifestPath = join43(planV2Dir, "plan.json");
19861
+ const manifestPath = join44(planV2Dir, "plan.json");
19784
19862
  if (!existsSync28(manifestPath)) {
19785
19863
  throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
19786
19864
  }
@@ -19829,13 +19907,13 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
19829
19907
  const tempDir = createStagingDir6(dirname17(destinationDir), ".plan-v2-materialize-");
19830
19908
  try {
19831
19909
  for (const { artifact, sourcePath } of verified) {
19832
- const destinationPath = join43(tempDir, ...artifact.path.split("/"));
19910
+ const destinationPath = join44(tempDir, ...artifact.path.split("/"));
19833
19911
  mkdirSync18(dirname17(destinationPath), { recursive: true });
19834
19912
  copyFileSync8(sourcePath, destinationPath);
19835
19913
  }
19836
19914
  if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
19837
19915
  writeFileSync12(
19838
- join43(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
19916
+ join44(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
19839
19917
  canonicalJsonStringify({
19840
19918
  manifest,
19841
19919
  target,
@@ -19858,7 +19936,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
19858
19936
  // Join the artifact's OWN name, not the current constant: a plan written
19859
19937
  // before the container change carries the legacy name, and materializing it
19860
19938
  // under the new one would point at a file that was never written.
19861
- audioPath: target.role === "assembler" ? audioArtifact ? join43(destinationDir, audioArtifact.path) : null : null
19939
+ audioPath: target.role === "assembler" ? audioArtifact ? join44(destinationDir, audioArtifact.path) : null : null
19862
19940
  };
19863
19941
  }
19864
19942
  function assertRemoteSources(remoteSources, artifacts) {
@@ -19877,7 +19955,7 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
19877
19955
  return readValidatedPlanV2Materialization(planDir, expectedTarget)?.manifest ?? null;
19878
19956
  }
19879
19957
  function readValidatedPlanV2Materialization(planDir, expectedTarget) {
19880
- const markerPath = join43(planDir, PLAN_V2_MATERIALIZATION_MARKER);
19958
+ const markerPath = join44(planDir, PLAN_V2_MATERIALIZATION_MARKER);
19881
19959
  if (!existsSync28(markerPath)) return null;
19882
19960
  const marker = readJsonFile(markerPath, "materialization marker");
19883
19961
  if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
@@ -19895,7 +19973,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
19895
19973
  assertRemoteSources(remoteSources, required);
19896
19974
  for (const artifact of required) {
19897
19975
  if (Object.hasOwn(remoteSources, artifact.path)) continue;
19898
- const path = join43(planDir, ...artifact.path.split("/"));
19976
+ const path = join44(planDir, ...artifact.path.split("/"));
19899
19977
  if (!existsSync28(path) || statSync11(path).size !== artifact.sizeBytes) {
19900
19978
  throw new PlanV2IntegrityError(
19901
19979
  `materialized artifact missing or truncated: ${artifact.path}`
@@ -20027,7 +20105,7 @@ function hashChunkOutput(outputPath, kind) {
20027
20105
  if (kind === "file") return sha256Hex(readFileSync14(outputPath));
20028
20106
  const entries = readdirSync11(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
20029
20107
  const lines = entries.map(
20030
- (name) => `${name}\0${sha256Hex(readFileSync14(join44(outputPath, name)))}`
20108
+ (name) => `${name}\0${sha256Hex(readFileSync14(join45(outputPath, name)))}`
20031
20109
  );
20032
20110
  return sha256Hex(lines.join("\0"));
20033
20111
  }
@@ -20044,9 +20122,9 @@ function resolveLockedVp9CpuUsed(lockedEncoder) {
20044
20122
  async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20045
20123
  const start = Date.now();
20046
20124
  const log = defaultLogger;
20047
- const planJsonPath = join44(planDir, "plan.json");
20048
- const encoderJsonPath = join44(planDir, "meta", "encoder.json");
20049
- const chunksJsonPath = join44(planDir, "meta", "chunks.json");
20125
+ const planJsonPath = join45(planDir, "plan.json");
20126
+ const encoderJsonPath = join45(planDir, "meta", "encoder.json");
20127
+ const chunksJsonPath = join45(planDir, "meta", "chunks.json");
20050
20128
  if (!existsSync29(planJsonPath)) {
20051
20129
  throw new RenderChunkValidationError(
20052
20130
  MISSING_PLAN_ARTIFACT,
@@ -20072,7 +20150,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20072
20150
  }
20073
20151
  const encoder = JSON.parse(readFileSync14(encoderJsonPath, "utf-8"));
20074
20152
  const chunks = JSON.parse(readFileSync14(chunksJsonPath, "utf-8"));
20075
- const videosJsonPath = join44(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
20153
+ const videosJsonPath = join45(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
20076
20154
  let planVideos = null;
20077
20155
  if (existsSync29(videosJsonPath)) {
20078
20156
  try {
@@ -20104,7 +20182,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20104
20182
  }
20105
20183
  const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
20106
20184
  const framesInChunk = range.endFrame - range.startFrame;
20107
- const compiledDir = join44(planDir, "compiled");
20185
+ const compiledDir = join45(planDir, "compiled");
20108
20186
  if (!existsSync29(compiledDir)) {
20109
20187
  throw new RenderChunkValidationError(
20110
20188
  MISSING_PLAN_ARTIFACT,
@@ -20163,7 +20241,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20163
20241
  };
20164
20242
  const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
20165
20243
  mkdirSync19(workDir, { recursive: true });
20166
- const framesDir = join44(workDir, "captured-frames");
20244
+ const framesDir = join45(workDir, "captured-frames");
20167
20245
  mkdirSync19(framesDir, { recursive: true });
20168
20246
  const videoFramesDir = `${workDir}.video-frames`;
20169
20247
  const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
@@ -20188,7 +20266,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20188
20266
  dimensions: plan2.dimensions,
20189
20267
  encoder,
20190
20268
  videoCount: planVideos?.videos.length ?? 0,
20191
- html: readFileSync14(join44(compiledDir, "index.html"), "utf-8"),
20269
+ html: readFileSync14(join45(compiledDir, "index.html"), "utf-8"),
20192
20270
  // The plan ships a deferred source only to chunks that show it; don't wait on the rest.
20193
20271
  skipReadinessVideoIds: deferredVideos.filter(
20194
20272
  (video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
@@ -20359,7 +20437,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20359
20437
  if (isPngSequence) {
20360
20438
  if (!existsSync29(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
20361
20439
  } else {
20362
- const outDir = join44(outputChunkPath, "..");
20440
+ const outDir = join45(outputChunkPath, "..");
20363
20441
  if (!existsSync29(outDir)) mkdirSync19(outDir, { recursive: true });
20364
20442
  }
20365
20443
  const encodeInput = {
@@ -20624,7 +20702,7 @@ function spanFrameRange(startSeconds, endSeconds, fps, totalFrames) {
20624
20702
  function throwIfAborted(signal) {
20625
20703
  if (signal?.aborted) throw new RenderCancelledError("render_cancelled", "user_cancelled");
20626
20704
  }
20627
- async function renderSpan(projectDir, config, span, outputPath) {
20705
+ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
20628
20706
  if (config.format !== "mp4") {
20629
20707
  throw new RenderSpanUnsupportedError(
20630
20708
  `--start/--end render mp4 only; ${config.format} is not supported for a range.`
@@ -20633,16 +20711,16 @@ async function renderSpan(projectDir, config, span, outputPath) {
20633
20711
  if (config.cfr === true) {
20634
20712
  throw new RenderSpanUnsupportedError("--start/--end cannot be combined with a cfr re-encode.");
20635
20713
  }
20636
- const workDir = mkdtempSync(join45(tmpdir4(), "hf-render-span-"));
20714
+ const workDir = mkdtempSync(join46(tmpdir4(), "hf-render-span-"));
20637
20715
  try {
20638
- const planDir = join45(workDir, "plan");
20639
- const partsDir = join45(workDir, "parts");
20716
+ const planDir = join46(workDir, "plan");
20717
+ const partsDir = join46(workDir, "parts");
20640
20718
  mkdirSync20(partsDir, { recursive: true });
20641
20719
  const planned = await plan(
20642
20720
  projectDir,
20643
20721
  { ...config, rejectOnSystemFonts: false, failClosedFontFetch: false },
20644
20722
  planDir,
20645
- { chunksCarryAudio: true }
20723
+ { chunksCarryAudio: true, allowOutsideProjectAssets: options.allowOutsideProjectAssets }
20646
20724
  );
20647
20725
  const { startFrame, endFrame } = spanFrameRange(
20648
20726
  span.startSeconds,
@@ -20651,7 +20729,7 @@ async function renderSpan(projectDir, config, span, outputPath) {
20651
20729
  planned.totalFrames
20652
20730
  );
20653
20731
  const slices = JSON.parse(
20654
- readFileSync15(join45(planDir, "meta", "chunks.json"), "utf-8")
20732
+ readFileSync15(join46(planDir, "meta", "chunks.json"), "utf-8")
20655
20733
  );
20656
20734
  const parts = [];
20657
20735
  for (const slice of slices) {
@@ -20661,7 +20739,7 @@ async function renderSpan(projectDir, config, span, outputPath) {
20661
20739
  };
20662
20740
  if (range.endFrame <= range.startFrame) continue;
20663
20741
  throwIfAborted(config.abortSignal);
20664
- const part = join45(partsDir, `part-${String(parts.length).padStart(4, "0")}.mp4`);
20742
+ const part = join46(partsDir, `part-${String(parts.length).padStart(4, "0")}.mp4`);
20665
20743
  await renderChunk(planDir, slice.index, part, { frameRange: range });
20666
20744
  parts.push(part);
20667
20745
  }
@@ -21168,7 +21246,8 @@ function renderConfigFromRequest(request, runtime = {}) {
21168
21246
  return {
21169
21247
  ...options,
21170
21248
  producerConfig: engineConfig,
21171
- logger: runtime.logger
21249
+ logger: runtime.logger,
21250
+ allowOutsideProjectAssets: runtime.allowOutsideProjectAssets === true
21172
21251
  };
21173
21252
  }
21174
21253
  function distributedFps(fps) {
@@ -21307,7 +21386,7 @@ import {
21307
21386
  rmSync as rmSync19,
21308
21387
  createReadStream as createReadStream5
21309
21388
  } from "node:fs";
21310
- import { resolve as resolve12, dirname as dirname19, join as join48 } from "node:path";
21389
+ import { resolve as resolve12, dirname as dirname19, join as join49 } from "node:path";
21311
21390
  import { tmpdir as tmpdir5 } from "node:os";
21312
21391
  import { parseArgs } from "node:util";
21313
21392
  import crypto from "node:crypto";
@@ -21330,7 +21409,7 @@ import {
21330
21409
  closeSync as closeSync7,
21331
21410
  constants as constants3
21332
21411
  } from "node:fs";
21333
- import { resolve as resolve11, join as join46, relative as relative7, isAbsolute as isAbsolute5, sep as sep5 } from "node:path";
21412
+ import { resolve as resolve11, join as join47, relative as relative8, isAbsolute as isAbsolute5, sep as sep5 } from "node:path";
21334
21413
  import { lintHyperframeHtml } from "@hyperframes/lint";
21335
21414
  function isStringRecord(value) {
21336
21415
  if (!value || typeof value !== "object" || Array.isArray(value)) {
@@ -21384,7 +21463,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile) {
21384
21463
  );
21385
21464
  for (const entryFile of entryCandidates) {
21386
21465
  const absoluteEntryPath = resolve11(absProjectDir, entryFile);
21387
- const entryRelativePath = relative7(absProjectDir, absoluteEntryPath);
21466
+ const entryRelativePath = relative8(absProjectDir, absoluteEntryPath);
21388
21467
  if (entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep5}`) || isAbsolute5(entryRelativePath)) {
21389
21468
  return { error: `Entry file must stay inside project directory: ${entryFile}` };
21390
21469
  }
@@ -21398,7 +21477,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile) {
21398
21477
  }
21399
21478
  }
21400
21479
  return {
21401
- error: `No HTML entry file found in project directory: ${join46(absProjectDir, preferredEntryFile || "index.html")}`
21480
+ error: `No HTML entry file found in project directory: ${join47(absProjectDir, preferredEntryFile || "index.html")}`
21402
21481
  };
21403
21482
  }
21404
21483
  function prepareHyperframeLintBody(body) {
@@ -21444,7 +21523,7 @@ async function runHyperframeLint(prepared) {
21444
21523
  // src/services/healthWorker.ts
21445
21524
  import { Worker as Worker2 } from "node:worker_threads";
21446
21525
  import { fileURLToPath as fileURLToPath6 } from "node:url";
21447
- import { dirname as dirname18, join as join47 } from "node:path";
21526
+ import { dirname as dirname18, join as join48 } from "node:path";
21448
21527
  import { existsSync as existsSync31 } from "node:fs";
21449
21528
  var DEFAULT_HEALTH_PORT = 9848;
21450
21529
  async function startHealthWorker(options = {}) {
@@ -21520,7 +21599,7 @@ function defaultLogger2() {
21520
21599
  }
21521
21600
  function resolveWorkerEntry2() {
21522
21601
  const here = dirname18(fileURLToPath6(import.meta.url));
21523
- const candidates = [join47(here, "healthWorkerThread.js"), join47(here, "healthWorkerThread.ts")];
21602
+ const candidates = [join48(here, "healthWorkerThread.js"), join48(here, "healthWorkerThread.ts")];
21524
21603
  for (const candidate of candidates) {
21525
21604
  if (existsSync31(candidate)) return candidate;
21526
21605
  }
@@ -21769,8 +21848,8 @@ async function resolveInlineRenderHtml(body) {
21769
21848
  }
21770
21849
  function materializeInlineProject(html, options) {
21771
21850
  const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir5();
21772
- const tempProjectDir = mkdtempSync2(join48(tempRoot, "producer-project-"));
21773
- writeFileSync14(join48(tempProjectDir, "index.html"), html, "utf-8");
21851
+ const tempProjectDir = mkdtempSync2(join49(tempRoot, "producer-project-"));
21852
+ writeFileSync14(join49(tempProjectDir, "index.html"), html, "utf-8");
21774
21853
  return {
21775
21854
  prepared: {
21776
21855
  input: { projectDir: tempProjectDir, ...options },
@@ -22267,7 +22346,7 @@ import { quantizeTimeToFrame, MEDIA_VISUAL_STYLE_PROPERTIES } from "@hyperframes
22267
22346
  // src/services/distributed/planV2Execution.ts
22268
22347
  import { mkdtempSync as mkdtempSync3, rmSync as rmSync21 } from "node:fs";
22269
22348
  import { tmpdir as tmpdir6 } from "node:os";
22270
- import { join as join50 } from "node:path";
22349
+ import { join as join51 } from "node:path";
22271
22350
 
22272
22351
  // src/services/distributed/assemble.ts
22273
22352
  import {
@@ -22284,7 +22363,7 @@ import {
22284
22363
  statSync as statSync14,
22285
22364
  writeFileSync as writeFileSync15
22286
22365
  } from "node:fs";
22287
- import { basename as basename8, dirname as dirname20, join as join49 } from "node:path";
22366
+ import { basename as basename8, dirname as dirname20, join as join50 } from "node:path";
22288
22367
  import {
22289
22368
  appendRateCapArgs as appendRateCapArgs2,
22290
22369
  appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
@@ -22354,7 +22433,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
22354
22433
  };
22355
22434
  try {
22356
22435
  const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
22357
- const finalPath = join49(workDir, `output.${format}`);
22436
+ const finalPath = join50(workDir, `output.${format}`);
22358
22437
  const audio = audioPath !== null && existsSync33(audioPath) ? audioPath : null;
22359
22438
  await writeJoined(ctx, videoSources, audio, finalPath);
22360
22439
  renameWithRetry11(finalPath, outputPath);
@@ -22383,8 +22462,8 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
22383
22462
  };
22384
22463
  }
22385
22464
  function readAssemblePlan(planDir, chunkPaths) {
22386
- const planJsonPath = join49(planDir, "plan.json");
22387
- const chunksJsonPath = join49(planDir, "meta", "chunks.json");
22465
+ const planJsonPath = join50(planDir, "plan.json");
22466
+ const chunksJsonPath = join50(planDir, "meta", "chunks.json");
22388
22467
  if (!existsSync33(planJsonPath)) {
22389
22468
  throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
22390
22469
  }
@@ -22435,7 +22514,7 @@ function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
22435
22514
  return args;
22436
22515
  }
22437
22516
  async function reencodeCfr(ctx, chunkPaths, encoder) {
22438
- const cfrOutputPath = join49(ctx.workDir, `cfr.${ctx.format}`);
22517
+ const cfrOutputPath = join50(ctx.workDir, `cfr.${ctx.format}`);
22439
22518
  const cfrArgs = cfrEncodeArgs(videoInputArgs(ctx, chunkPaths), encoder, ctx.fpsArg);
22440
22519
  appendRenderProvenanceArgs2(cfrArgs, cfrOutputPath);
22441
22520
  cfrArgs.push("-y", cfrOutputPath);
@@ -22462,7 +22541,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
22462
22541
  );
22463
22542
  return;
22464
22543
  }
22465
- const paddedAudioPath = join49(ctx.workDir, "audio-padded.m4a");
22544
+ const paddedAudioPath = join50(ctx.workDir, "audio-padded.m4a");
22466
22545
  const padTrimResult = await ctx.timed(
22467
22546
  "audioMs",
22468
22547
  () => padOrTrimAudioToVideoFrameCount({
@@ -22502,7 +22581,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
22502
22581
  }
22503
22582
  }
22504
22583
  function concatDemuxerInput(chunkPaths, workDir, fpsArg) {
22505
- const listPath = join49(workDir, "concat-list.txt");
22584
+ const listPath = join50(workDir, "concat-list.txt");
22506
22585
  const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
22507
22586
  writeFileSync15(listPath, `${body}
22508
22587
  `, "utf-8");
@@ -22540,11 +22619,11 @@ function stitchesSeparateAudio(planDir) {
22540
22619
  return lockedAudio(planDir).separateAudio === true;
22541
22620
  }
22542
22621
  function planFormat(planDir) {
22543
- const plan2 = JSON.parse(readFileSync17(join49(planDir, "plan.json"), "utf-8"));
22622
+ const plan2 = JSON.parse(readFileSync17(join50(planDir, "plan.json"), "utf-8"));
22544
22623
  return plan2.dimensions.format;
22545
22624
  }
22546
22625
  function lockedAudio(planDir) {
22547
- const encoderJsonPath = join49(planDir, "meta", "encoder.json");
22626
+ const encoderJsonPath = join50(planDir, "meta", "encoder.json");
22548
22627
  if (!existsSync33(encoderJsonPath)) return {};
22549
22628
  return JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
22550
22629
  }
@@ -22554,7 +22633,7 @@ function readCfrEncoder(planDir, format) {
22554
22633
  `[assemble] cfr=true is only supported for format="mp4" (got "${format}"). Stream-copy paths for webm and mov already produce exact avg_frame_rate; cfr re-encode is not needed.`
22555
22634
  );
22556
22635
  }
22557
- const encoderJsonPath = join49(planDir, "meta", "encoder.json");
22636
+ const encoderJsonPath = join50(planDir, "meta", "encoder.json");
22558
22637
  if (!existsSync33(encoderJsonPath)) {
22559
22638
  throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
22560
22639
  }
@@ -22581,8 +22660,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
22581
22660
  throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
22582
22661
  }
22583
22662
  for (const frame of frames) {
22584
- const dst = join49(outputPath, formatExportFrameName(globalIdx, "png"));
22585
- cpSync3(join49(chunkDir, frame), dst);
22663
+ const dst = join50(outputPath, formatExportFrameName(globalIdx, "png"));
22664
+ cpSync3(join50(chunkDir, frame), dst);
22586
22665
  globalIdx += 1;
22587
22666
  }
22588
22667
  }
@@ -22592,13 +22671,13 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
22592
22671
  );
22593
22672
  }
22594
22673
  if (audioPath !== null && existsSync33(audioPath)) {
22595
- const sidecar = join49(outputPath, MIXED_AUDIO_FILENAME4);
22674
+ const sidecar = join50(outputPath, MIXED_AUDIO_FILENAME4);
22596
22675
  cpSync3(audioPath, sidecar);
22597
22676
  }
22598
22677
  let fileSize = 0;
22599
22678
  for (const name of readdirSync12(outputPath)) {
22600
22679
  try {
22601
- fileSize += statSync14(join49(outputPath, name)).size;
22680
+ fileSize += statSync14(join50(outputPath, name)).size;
22602
22681
  } catch {
22603
22682
  }
22604
22683
  }
@@ -22612,8 +22691,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
22612
22691
 
22613
22692
  // src/services/distributed/planV2Execution.ts
22614
22693
  async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
22615
- const workRoot = mkdtempSync3(join50(tmpdir6(), "hf-plan-v2-chunk-"));
22616
- const materializedPlanDir = join50(workRoot, "plan");
22694
+ const workRoot = mkdtempSync3(join51(tmpdir6(), "hf-plan-v2-chunk-"));
22695
+ const materializedPlanDir = join51(workRoot, "plan");
22617
22696
  try {
22618
22697
  materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
22619
22698
  return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
@@ -22622,8 +22701,8 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
22622
22701
  }
22623
22702
  }
22624
22703
  async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
22625
- const workRoot = mkdtempSync3(join50(tmpdir6(), "hf-plan-v2-assembler-"));
22626
- const materializedPlanDir = join50(workRoot, "plan");
22704
+ const workRoot = mkdtempSync3(join51(tmpdir6(), "hf-plan-v2-assembler-"));
22705
+ const materializedPlanDir = join51(workRoot, "plan");
22627
22706
  try {
22628
22707
  const materialized = materializePlanV2Target(
22629
22708
  planV2Dir,