@hyperframes/producer 0.9.31 → 0.9.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
8
8
  import {
9
9
  copyFileSync as copyFileSync6,
10
10
  cpSync as cpSync2,
11
- existsSync as existsSync20,
11
+ existsSync as existsSync19,
12
12
  linkSync,
13
13
  mkdirSync as mkdirSync10,
14
14
  rmSync as rmSync7,
@@ -66,12 +66,14 @@ function createConsoleLogger(level = "info") {
66
66
  }
67
67
  };
68
68
  }
69
- var defaultLogger = createConsoleLogger("info");
69
+ var defaultLogger = createConsoleLogger(
70
+ process.env.HF_DEBUG_RENDER === "1" ? "debug" : "info"
71
+ );
70
72
 
71
73
  // src/services/renderOrchestrator.ts
72
74
  import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
73
75
  import {
74
- existsSync as existsSync15,
76
+ existsSync as existsSync14,
75
77
  mkdirSync as mkdirSync6,
76
78
  readdirSync as readdirSync3,
77
79
  rmSync as rmSync5,
@@ -953,7 +955,7 @@ function chunkGopFrames(framesInChunk, intervalFrames) {
953
955
  import {
954
956
  copyFileSync,
955
957
  cpSync,
956
- existsSync as existsSync4,
958
+ existsSync as existsSync3,
957
959
  mkdirSync,
958
960
  rmSync,
959
961
  symlinkSync,
@@ -964,6 +966,9 @@ import {
964
966
  CANVAS_DIMENSIONS,
965
967
  checkOutputResolutionCompatibility
966
968
  } from "@hyperframes/core";
969
+ import {
970
+ mediaIdPathSegment
971
+ } from "@hyperframes/engine";
967
972
 
968
973
  // src/utils/paths.ts
969
974
  import {
@@ -973,9 +978,7 @@ import {
973
978
  relative as nodeRelative,
974
979
  isAbsolute as nodeIsAbsolute
975
980
  } from "node:path";
976
- import { existsSync as existsSync3 } from "node:fs";
977
981
  import { fileURLToPath as fileURLToPath2 } from "node:url";
978
- import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
979
982
  var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
980
983
  // resolves to a bogus renders dir.
981
984
  nodeResolve(fileURLToPath2(import.meta.url), "../../..", "renders");
@@ -1006,13 +1009,6 @@ function formatCaptureFrameName(index, ext) {
1006
1009
  function formatExportFrameName(index, ext) {
1007
1010
  return `frame_${String(index + 1).padStart(6, "0")}.${ext}`;
1008
1011
  }
1009
- function resolveCompositionSrc(projectDir, src) {
1010
- const rooted = (value) => nodeResolve(projectDir, value.replace(/^(?:\.?[\\/])+/, ""));
1011
- const decoded = rooted(decodedUrlPath(src));
1012
- if (!isPathInside2(decoded, projectDir)) return null;
1013
- const raw = rooted(src);
1014
- return !existsSync3(decoded) && isPathInside2(raw, projectDir) && existsSync3(raw) ? raw : decoded;
1015
- }
1016
1012
 
1017
1013
  // src/services/render/shared.ts
1018
1014
  var BROWSER_MEDIA_EPSILON = 1e-4;
@@ -1041,6 +1037,10 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1041
1037
  writeFileSync(join3(compileDir, "index.html"), compiled.html, "utf-8");
1042
1038
  for (const [srcPath, html] of compiled.subCompositions) {
1043
1039
  const outPath = join3(compileDir, srcPath);
1040
+ if (!isPathInside2(outPath, compileDir)) {
1041
+ console.warn(`[Render] Skipping sub-composition with unsafe path: ${srcPath}`);
1042
+ continue;
1043
+ }
1044
1044
  mkdirSync(dirname2(outPath), { recursive: true });
1045
1045
  writeFileSync(outPath, html, "utf-8");
1046
1046
  }
@@ -1158,6 +1158,13 @@ var workerPhasesByJob = /* @__PURE__ */ new WeakMap();
1158
1158
  function forgetWorkerPhases(job) {
1159
1159
  workerPhasesByJob.delete(job);
1160
1160
  }
1161
+ var staticDedupActivityByJob = /* @__PURE__ */ new WeakMap();
1162
+ function noteStaticDedupActivity(job) {
1163
+ staticDedupActivityByJob.set(job, (staticDedupActivityByJob.get(job) ?? 0) + 1);
1164
+ }
1165
+ function staticDedupActivity(job) {
1166
+ return staticDedupActivityByJob.get(job) ?? 0;
1167
+ }
1161
1168
  function describeWorkerPhases(job) {
1162
1169
  const phases = workerPhasesByJob.get(job);
1163
1170
  if (!phases?.size) return void 0;
@@ -1191,7 +1198,7 @@ var materializePathModule = {
1191
1198
  isAbsolute
1192
1199
  };
1193
1200
  var materializeFileSystem = {
1194
- existsSync: existsSync4,
1201
+ existsSync: existsSync3,
1195
1202
  mkdirSync,
1196
1203
  symlinkSync,
1197
1204
  cpSync,
@@ -1251,7 +1258,7 @@ function materializeExtractedFramesForCompiledDir(extracted, compiledDir, option
1251
1258
  for (const ext of extracted) {
1252
1259
  const resolvedOut = pathModule.resolve(ext.outputDir);
1253
1260
  if (isPathInside2(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
1254
- const linkPath = pathModule.join(compiledFrameRoot, ext.videoId);
1261
+ const linkPath = pathModule.join(compiledFrameRoot, mediaIdPathSegment(ext.videoId));
1255
1262
  if (!fileSystem.existsSync(linkPath)) {
1256
1263
  fileSystem.mkdirSync(pathModule.dirname(linkPath), { recursive: true });
1257
1264
  stageExtractedFrameDir(
@@ -1703,6 +1710,7 @@ import { dirname as dirname3, join as join4 } from "node:path";
1703
1710
  import {
1704
1711
  createFrameLookupTable,
1705
1712
  extractVideoFramesRange,
1713
+ mediaIdPathSegment as mediaIdPathSegment2,
1706
1714
  runVideoExtractionWithRetry
1707
1715
  } from "@hyperframes/engine";
1708
1716
  function contiguousRuns(sortedIndexes) {
@@ -1743,7 +1751,7 @@ async function extractDeferredFrames(input) {
1743
1751
  const shown = shownDeferredFrameIndexes(input, input.frames, input.fps);
1744
1752
  return Promise.all(
1745
1753
  deferred.map(async (video) => {
1746
- const outputDir = join4(input.outputRoot, video.videoId);
1754
+ const outputDir = join4(input.outputRoot, mediaIdPathSegment2(video.videoId));
1747
1755
  const indexes = [...shown.get(video.videoId) ?? []].sort((a, b) => a - b);
1748
1756
  if (indexes.length === 0) {
1749
1757
  return { ...video, outputDir, framePaths: /* @__PURE__ */ new Map(), ownedByLookup: false };
@@ -1803,6 +1811,7 @@ function resolveVideoCaptureBeyondViewport(videoCount) {
1803
1811
  }
1804
1812
 
1805
1813
  // src/services/render/observability.ts
1814
+ import { createHash as createHash2 } from "node:crypto";
1806
1815
  import { redactTelemetryString } from "@hyperframes/core";
1807
1816
  import { CaptureFailure as CaptureFailure2 } from "@hyperframes/engine";
1808
1817
  var MAX_EVENTS = 160;
@@ -1848,6 +1857,9 @@ var RESERVED_LOG_KEYS = /* @__PURE__ */ new Set([
1848
1857
  function sanitizeObservationMessage(value) {
1849
1858
  return redactTelemetryString(value);
1850
1859
  }
1860
+ function computeCompositionObservabilityHash(compiledHtml) {
1861
+ return createHash2("sha256").update(compiledHtml, "utf8").digest("hex").slice(0, 16);
1862
+ }
1851
1863
  function sanitizeObservationData(data) {
1852
1864
  if (!data) return void 0;
1853
1865
  const sanitized = {};
@@ -2050,26 +2062,26 @@ var STALL_POLL_MS = 5e3;
2050
2062
  function watchStall(phase, rule) {
2051
2063
  const detail = rule.detail ?? (() => void 0);
2052
2064
  let last = rule.progress();
2065
+ let lastActivity = rule.activity?.();
2053
2066
  let budgetMs = rule.firstProgressMs;
2054
2067
  const silence = createStallClock();
2055
2068
  const pollMs = Math.min(STALL_POLL_MS, rule.noProgressMs, rule.firstProgressMs);
2056
2069
  let attempt;
2057
2070
  let timer;
2058
2071
  let inTail = false;
2072
+ const activityMoved = () => {
2073
+ const activity = rule.activity?.();
2074
+ if (activity === lastActivity) return false;
2075
+ lastActivity = activity;
2076
+ return true;
2077
+ };
2059
2078
  const restartWindow = (ms) => {
2060
2079
  last = rule.progress();
2061
2080
  budgetMs = ms;
2062
2081
  silence.reset();
2063
2082
  };
2064
2083
  const tripped = new Promise((_, reject) => {
2065
- timer = setInterval(() => {
2066
- const current = rule.progress();
2067
- if (rule.complete?.() && !inTail) {
2068
- inTail = true;
2069
- return restartWindow(rule.tailMs ?? rule.noProgressMs);
2070
- }
2071
- if (current !== last) return restartWindow(rule.noProgressMs);
2072
- if (silence.idle(pollMs) < budgetMs) return;
2084
+ const trip = (current) => {
2073
2085
  const error = new RenderStageStalledError(phase, budgetMs, current, detail());
2074
2086
  if (attempt && !attempt.signal.aborted) {
2075
2087
  attempt.abort(error);
@@ -2077,6 +2089,16 @@ function watchStall(phase, rule) {
2077
2089
  }
2078
2090
  clearInterval(timer);
2079
2091
  reject(error);
2092
+ };
2093
+ timer = setInterval(() => {
2094
+ const current = rule.progress();
2095
+ if (rule.complete?.() && !inTail) {
2096
+ inTail = true;
2097
+ return restartWindow(rule.tailMs ?? rule.noProgressMs);
2098
+ }
2099
+ if (current !== last) return restartWindow(rule.noProgressMs);
2100
+ if (activityMoved()) return silence.reset();
2101
+ if (silence.idle(pollMs) >= budgetMs) trip(current);
2080
2102
  }, pollMs);
2081
2103
  });
2082
2104
  const openAttempt = (parent) => {
@@ -2144,21 +2166,21 @@ import {
2144
2166
  } from "@hyperframes/engine";
2145
2167
 
2146
2168
  // src/services/render/stages/compileStage.ts
2147
- import { existsSync as existsSync9, writeFileSync as writeFileSync3 } from "node:fs";
2169
+ import { existsSync as existsSync8, writeFileSync as writeFileSync3 } from "node:fs";
2148
2170
  import { join as join9 } from "node:path";
2149
2171
  import { suggestMatchingPreset } from "@hyperframes/core";
2150
2172
  import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
2151
2173
  import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
2152
2174
 
2153
2175
  // src/services/htmlCompiler.ts
2154
- import { decodedUrlPath as decodedUrlPath2 } from "@hyperframes/parsers/asset-paths";
2155
- import { createHash as createHash4 } from "node:crypto";
2156
- import { createReadStream as createReadStream2, existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
2176
+ import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
2177
+ import { createHash as createHash5 } from "node:crypto";
2178
+ import { createReadStream as createReadStream2, existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
2157
2179
  import { join as join8, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep2 } from "path";
2158
2180
  import { parseHTML as parseHTML5 } from "linkedom";
2159
2181
 
2160
2182
  // src/services/bundledScripts.ts
2161
- import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
2183
+ import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
2162
2184
  import { join as join5 } from "node:path";
2163
2185
  import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
2164
2186
  var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
@@ -2166,7 +2188,7 @@ function bundledScript(url) {
2166
2188
  const dir = process.env[GSAP_VENDOR_DIR_ENV];
2167
2189
  if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
2168
2190
  const file = join5(dir, "gsap.min.js");
2169
- return existsSync5(file) ? readFileSync2(file) : null;
2191
+ return existsSync4(file) ? readFileSync2(file) : null;
2170
2192
  }
2171
2193
 
2172
2194
  // src/services/htmlCompiler.ts
@@ -2206,6 +2228,7 @@ import {
2206
2228
  emitRootCompositionVariableStyles,
2207
2229
  readDeclaredDefaults,
2208
2230
  parseHostVariableValues,
2231
+ boundMediaSrc,
2209
2232
  headStyleRuns,
2210
2233
  isAlwaysAppliedStyle,
2211
2234
  dedupeFontFaceRules,
@@ -2220,8 +2243,10 @@ import {
2220
2243
  } from "@hyperframes/parsers/sub-composition-validity";
2221
2244
  import {
2222
2245
  isUnresolvedAssetPlaceholder,
2246
+ namesAnotherNetworkRoot as namesAnotherNetworkRoot2,
2223
2247
  readProjectFile,
2224
- readTextFile
2248
+ readTextFile,
2249
+ resolveCompositionSrc
2225
2250
  } from "@hyperframes/parsers/asset-resolution";
2226
2251
 
2227
2252
  // src/services/renderMediaCollector.ts
@@ -2413,12 +2438,13 @@ import {
2413
2438
  } from "@hyperframes/core/fonts/embed";
2414
2439
 
2415
2440
  // src/services/animatedGifPrep.ts
2416
- import { createHash as createHash2 } from "node:crypto";
2417
- import { copyFileSync as copyFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
2441
+ import { createHash as createHash3 } from "node:crypto";
2442
+ import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
2418
2443
  import { dirname as dirname4, isAbsolute as isAbsolute2, join as join6, resolve as resolve4 } from "node:path";
2419
2444
  import { parseHTML as parseHTML3 } from "linkedom";
2420
2445
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
2421
2446
  import { DEFAULT_VP9_CPU_USED, runFfmpeg as runFfmpeg2, renameWithRetry as renameWithRetry3 } from "@hyperframes/engine";
2447
+ import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
2422
2448
  var PREPARED_GIF_SUBDIR = "_animated_gif";
2423
2449
  var CACHE_SCHEMA = "hfgif-v1";
2424
2450
  function splitUrlSuffix(src) {
@@ -2453,14 +2479,15 @@ function resolveLocalImageSourcePath(src, options) {
2453
2479
  const { basePath } = splitUrlSuffix(trimmed);
2454
2480
  const normalizedBase = normalizeRelPath(basePath);
2455
2481
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
2456
- if (mapped && existsSync6(mapped)) return mapped;
2482
+ if (mapped && existsSync5(mapped)) return mapped;
2457
2483
  if (isHttpUrl(trimmed)) return null;
2484
+ const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
2458
2485
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
2459
2486
  const candidates = [
2460
- isAbsolute2(basePath) ? basePath : resolve4(options.projectDir, projectRelative),
2487
+ ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve4(options.projectDir, projectRelative)],
2461
2488
  resolve4(options.downloadDir, normalizedBase)
2462
2489
  ];
2463
- return candidates.find((candidate) => existsSync6(candidate)) ?? null;
2490
+ return candidates.find((candidate) => existsSync5(candidate)) ?? null;
2464
2491
  }
2465
2492
  function isUsableFile(path) {
2466
2493
  try {
@@ -2471,7 +2498,7 @@ function isUsableFile(path) {
2471
2498
  }
2472
2499
  }
2473
2500
  function computePreparedGifHash(bytes, loopIterations, padSeconds) {
2474
- return createHash2("sha256").update(CACHE_SCHEMA).update("\0").update(String(loopIterations)).update("\0").update(String(padSeconds)).update("\0").update(bytes).digest("hex");
2501
+ return createHash3("sha256").update(CACHE_SCHEMA).update("\0").update(String(loopIterations)).update("\0").update(String(padSeconds)).update("\0").update(bytes).digest("hex");
2475
2502
  }
2476
2503
  function resolveLoop(metadata, override) {
2477
2504
  if (override != null) return override;
@@ -2571,10 +2598,10 @@ async function runAnimatedGifTranscode(request) {
2571
2598
  throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
2572
2599
  }
2573
2600
  async function ensurePreparedWebm(input) {
2574
- if (!existsSync6(dirname4(input.cachePath))) {
2601
+ if (!existsSync5(dirname4(input.cachePath))) {
2575
2602
  mkdirSync2(dirname4(input.cachePath), { recursive: true });
2576
2603
  }
2577
- if (!existsSync6(dirname4(input.outputPath))) {
2604
+ if (!existsSync5(dirname4(input.outputPath))) {
2578
2605
  mkdirSync2(dirname4(input.outputPath), { recursive: true });
2579
2606
  }
2580
2607
  if (!isUsableFile(input.cachePath)) {
@@ -2719,7 +2746,7 @@ async function prepareAnimatedGifInputs(html, options) {
2719
2746
  }
2720
2747
 
2721
2748
  // src/services/heifImagePrep.ts
2722
- import { createHash as createHash3 } from "node:crypto";
2749
+ import { createHash as createHash4 } from "node:crypto";
2723
2750
  import {
2724
2751
  closeSync as closeSync2,
2725
2752
  copyFileSync as copyFileSync3,
@@ -3017,7 +3044,7 @@ async function prepareHeifImageInputs(html, options) {
3017
3044
  const src = (img.getAttribute("src") || "").trim();
3018
3045
  const source = src ? resolveImageSource(src, options) : null;
3019
3046
  if (!source) continue;
3020
- const hash = createHash3("sha256").update(CACHE_SCHEMA2).update("\0").update(source.bytes).digest("hex");
3047
+ const hash = createHash4("sha256").update(CACHE_SCHEMA2).update("\0").update(source.bytes).digest("hex");
3021
3048
  found.push({ img, src, source, filename: `${CACHE_SCHEMA2}-${hash.slice(0, 24)}.jpg` });
3022
3049
  }
3023
3050
  if (found.length === 0) return { html, preparedAssets, preparedImages };
@@ -3049,7 +3076,7 @@ import { createStudioPositionSeekReapplyScript } from "@hyperframes/studio-serve
3049
3076
  import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
3050
3077
 
3051
3078
  // src/services/assetMediaType.ts
3052
- import { existsSync as existsSync7 } from "node:fs";
3079
+ import { existsSync as existsSync6 } from "node:fs";
3053
3080
  import {
3054
3081
  fingerprintElementId,
3055
3082
  isNotMediaPayload,
@@ -3122,7 +3149,7 @@ async function preflightCompositionAssetMediaTypes(input) {
3122
3149
  input.projectDir,
3123
3150
  input.compiledDir
3124
3151
  );
3125
- if (!existsSync7(resolvedPath)) continue;
3152
+ if (!existsSync6(resolvedPath)) continue;
3126
3153
  byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
3127
3154
  }
3128
3155
  const mismatches = [];
@@ -3162,7 +3189,7 @@ async function preflightCompositionAssetMediaTypes(input) {
3162
3189
 
3163
3190
  // src/services/htmlCompiler.ts
3164
3191
  function logRemoteDownloadTelemetry(event) {
3165
- defaultLogger.info("[Compiler] Remote asset download integrity", { ...event });
3192
+ defaultLogger.debug("[Compiler] Remote asset download integrity", { ...event });
3166
3193
  }
3167
3194
  var INFERRED_MEDIA_DURATION_ATTR = "data-hf-inferred-duration";
3168
3195
  function parseSubCompHtmlForValidity(html) {
@@ -3376,7 +3403,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
3376
3403
  let filePath = src;
3377
3404
  if (isHttpUrl(src)) {
3378
3405
  const remoteDir = join8(downloadDir, REMOTE_MEDIA_SUBDIR);
3379
- if (!existsSync8(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
3406
+ if (!existsSync7(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
3380
3407
  try {
3381
3408
  filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
3382
3409
  onTelemetry: logRemoteDownloadTelemetry
@@ -3385,11 +3412,14 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
3385
3412
  return { duration: null, resolvedPath: src };
3386
3413
  }
3387
3414
  } else {
3388
- filePath = decodedUrlPath2(src);
3415
+ filePath = decodedUrlPath(src);
3389
3416
  if (!filePath.startsWith("/")) filePath = join8(baseDir, filePath);
3390
3417
  filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
3418
+ if (!isHttpUrl(filePath) && namesAnotherNetworkRoot2(baseDir, filePath)) {
3419
+ return { duration: null, resolvedPath: filePath };
3420
+ }
3391
3421
  }
3392
- if (!isHttpUrl(filePath) && !existsSync8(filePath)) {
3422
+ if (!isHttpUrl(filePath) && !existsSync7(filePath)) {
3393
3423
  return { duration: null, resolvedPath: filePath };
3394
3424
  }
3395
3425
  const withSrcContext = (error) => {
@@ -3738,7 +3768,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
3738
3768
  parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
3739
3769
  // Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
3740
3770
  // against its own directory, project-root refs stay as authored.
3741
- assetExists: (path) => existsSync8(resolve6(projectDir, path)),
3771
+ assetExists: (path) => existsSync7(resolve6(projectDir, path)),
3742
3772
  // Preserve the authored root wrapper as a child of the host, matching
3743
3773
  // the preview bundler's shape (htmlBundler.ts's prepareFlattenedInnerRoot,
3744
3774
  // which the runtime compositionLoader mirrors with its own copy for the
@@ -3863,7 +3893,7 @@ function matchesScriptIntegrity(bytes, metadata) {
3863
3893
  (alg) => hashes.some((hash) => hash[1]?.toLowerCase() === alg)
3864
3894
  );
3865
3895
  if (!strongest) return true;
3866
- const actual = createHash4(strongest).update(bytes).digest();
3896
+ const actual = createHash5(strongest).update(bytes).digest();
3867
3897
  return hashes.some(
3868
3898
  (hash) => hash[1]?.toLowerCase() === strongest && actual.equals(Buffer.from(hash[2], "base64"))
3869
3899
  );
@@ -3914,7 +3944,7 @@ ${safeText}
3914
3944
  //# sourceURL=${new URL(src).href}
3915
3945
  `;
3916
3946
  el.replaceWith(inlineScript);
3917
- defaultLogger.info(`[Compiler] Inlined CDN script: ${src}`);
3947
+ defaultLogger.debug(`[Compiler] Inlined CDN script: ${src}`);
3918
3948
  } else {
3919
3949
  if (download.reason instanceof ScriptIntegrityError) throw download.reason;
3920
3950
  defaultLogger.warn(
@@ -3934,7 +3964,7 @@ function collectExternalAssets(html, projectDir) {
3934
3964
  if (isPathInside2(absPath, absProjectDir)) {
3935
3965
  return null;
3936
3966
  }
3937
- if (!existsSync8(absPath)) return null;
3967
+ if (!existsSync7(absPath)) return null;
3938
3968
  const safeKey = toExternalAssetKey(absPath);
3939
3969
  externalAssets.set(safeKey, absPath);
3940
3970
  return safeKey;
@@ -3969,7 +3999,7 @@ function collectExternalAssets(html, projectDir) {
3969
3999
  if (rewritten !== style) el.setAttribute("style", rewritten);
3970
4000
  }
3971
4001
  if (externalAssets.size > 0) {
3972
- defaultLogger.info(
4002
+ defaultLogger.debug(
3973
4003
  `[Compiler] Found ${externalAssets.size} asset(s) outside project directory, will copy to render output`
3974
4004
  );
3975
4005
  }
@@ -3984,7 +4014,7 @@ var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["
3984
4014
  var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
3985
4015
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
3986
4016
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
3987
- if (!existsSync8(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
4017
+ if (!existsSync7(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
3988
4018
  const urlToLocal = /* @__PURE__ */ new Map();
3989
4019
  await Promise.all(
3990
4020
  [...urlSet].map(async (url) => {
@@ -4016,7 +4046,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
4016
4046
  result = result.replaceAll(`"${url}"`, `"${relPath}"`).replaceAll(`'${url}'`, `'${relPath}'`);
4017
4047
  if (extraRewrite) result = extraRewrite(result, url, relPath);
4018
4048
  }
4019
- defaultLogger.info(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
4049
+ defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
4020
4050
  return { html: result, remoteMediaAssets };
4021
4051
  }
4022
4052
  async function localizeRemoteMediaSources(html, downloadDir) {
@@ -4153,7 +4183,7 @@ async function inlineExternalFontStylesheets(html) {
4153
4183
  ${fontFaceBlocks.join("\n")}
4154
4184
  </style>`;
4155
4185
  result = result.replace(fullMatch, inlineStyle);
4156
- defaultLogger.info("[Compiler] Inlined external @font-face rule(s)", {
4186
+ defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
4157
4187
  count: fontFaceBlocks.length,
4158
4188
  urlFingerprint: identity.urlFingerprint,
4159
4189
  host: identity.host
@@ -4166,14 +4196,14 @@ function projectStylesheetFontFamilies(html, projectDir) {
4166
4196
  for (const [tag] of html.matchAll(/<link\b[^>]*\brel=["']stylesheet["'][^>]*>/gi)) {
4167
4197
  const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
4168
4198
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
4169
- const sheet = resolve6(projectDir, decodedUrlPath2(href).replace(/^(?:\.?\/)+/, ""));
4170
- if (!isPathInside2(sheet, projectDir) || !existsSync8(sheet)) continue;
4199
+ const sheet = resolve6(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
4200
+ if (!isPathInside2(sheet, projectDir) || !existsSync7(sheet)) continue;
4171
4201
  for (const face of extractFontFaceBlocks(readFileSync5(sheet, "utf8"))) {
4172
4202
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
4173
4203
  const shipsFile = [...face.matchAll(LOCAL_FONTFACE_URL_RE)].some(([, url = ""]) => {
4174
- const path = decodedUrlPath2(url);
4204
+ const path = decodedUrlPath(url);
4175
4205
  const file = path.startsWith("/") ? resolve6(projectDir, `.${path}`) : resolve6(dirname6(sheet), path);
4176
- return isPathInside2(file, projectDir) && existsSync8(file);
4206
+ return isPathInside2(file, projectDir) && existsSync7(file);
4177
4207
  });
4178
4208
  if (family && shipsFile) families.push(family);
4179
4209
  }
@@ -4272,7 +4302,7 @@ async function embedLocalFontFaces(html, projectDir) {
4272
4302
  const font = await readLocalFont(absPath);
4273
4303
  if (font.kind === "file-backed") {
4274
4304
  fileBackedAbsolutePaths.add(absPath);
4275
- defaultLogger.info(
4305
+ defaultLogger.debug(
4276
4306
  `[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
4277
4307
  );
4278
4308
  embeddedPaths.add(localPath);
@@ -4280,7 +4310,7 @@ async function embedLocalFontFaces(html, projectDir) {
4280
4310
  }
4281
4311
  dataUri = await toDataUri(font.buffer, ext, { compressToWoff2: false });
4282
4312
  dataUriByAbsolutePath.set(absPath, dataUri);
4283
- defaultLogger.info(
4313
+ defaultLogger.debug(
4284
4314
  `[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
4285
4315
  );
4286
4316
  }
@@ -4308,14 +4338,17 @@ function renderGsapDist() {
4308
4338
  }
4309
4339
  function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
4310
4340
  let gsapDist;
4311
- const exists = (path) => existsSync8(resolve6(projectDir, path));
4341
+ const exists = (path) => {
4342
+ const file = resolve6(projectDir, path);
4343
+ return !namesAnotherNetworkRoot2(projectDir, file) && existsSync7(file);
4344
+ };
4312
4345
  return html.replace(
4313
4346
  /(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
4314
4347
  (full, prefix, src, file, suffix) => {
4315
4348
  if (/^https?:\/\//i.test(src)) return full;
4316
4349
  if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
4317
4350
  gsapDist ??= renderGsapDist();
4318
- defaultLogger.info(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
4351
+ defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
4319
4352
  return `${prefix}${gsapDist}${file}${suffix}`;
4320
4353
  }
4321
4354
  );
@@ -4325,7 +4358,7 @@ function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
4325
4358
  const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
4326
4359
  if (!entryPath.includes("/")) return html;
4327
4360
  const { document: document2 } = parseHTML5(html);
4328
- const assetExists = (path) => existsSync8(resolve6(projectDir, path));
4361
+ const assetExists = (path) => existsSync7(resolve6(projectDir, path));
4329
4362
  rewriteAssetPaths(
4330
4363
  document2.querySelectorAll("[src], [href], [srcset]"),
4331
4364
  entryPath,
@@ -4345,11 +4378,29 @@ function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
4345
4378
  }
4346
4379
  return document2.toString();
4347
4380
  }
4381
+ function bindVariableMediaSources(html, variables) {
4382
+ if (!html.includes("data-var-src")) return html;
4383
+ const { document: document2 } = parseHTML5(html);
4384
+ const declared = {};
4385
+ for (const el of document2.querySelectorAll("[data-composition-variables]")) {
4386
+ Object.assign(declared, readDeclaredDefaults(el));
4387
+ }
4388
+ const values = { ...declared, ...variables };
4389
+ let changed = false;
4390
+ for (const el of document2.querySelectorAll("video[data-var-src], audio[data-var-src]")) {
4391
+ if (el.closest("[data-variable-values]")) continue;
4392
+ const src = boundMediaSrc(el, values);
4393
+ if (src === null || el.getAttribute("src") === src) continue;
4394
+ el.setAttribute("src", src);
4395
+ changed = true;
4396
+ }
4397
+ return changed ? document2.toString() : html;
4398
+ }
4348
4399
  async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
4349
4400
  const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
4350
- const rawHtml = normalizeCompositionSrcs(
4351
- rewriteUnresolvableGsapToCdn(entryHtml, projectDir),
4352
- projectDir
4401
+ const rawHtml = bindVariableMediaSources(
4402
+ normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
4403
+ options.variables ?? {}
4353
4404
  );
4354
4405
  assertSubCompositionsUsable(rawHtml, projectDir);
4355
4406
  const probes = /* @__PURE__ */ new Map();
@@ -4433,7 +4484,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
4433
4484
  timeoutMs: options.ffmpegProcessTimeout
4434
4485
  });
4435
4486
  if (preparedHeifImages.length > 0) {
4436
- defaultLogger.info(`[Compiler] Converted ${preparedHeifImages.length} HEIC image(s) to JPEG`);
4487
+ defaultLogger.debug(`[Compiler] Converted ${preparedHeifImages.length} HEIC image(s) to JPEG`);
4437
4488
  }
4438
4489
  const gifSourceAssets = new Map(remoteImageAssets);
4439
4490
  const {
@@ -4448,7 +4499,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
4448
4499
  timeoutMs: options.ffmpegProcessTimeout
4449
4500
  });
4450
4501
  if (preparedGifs.length > 0) {
4451
- defaultLogger.info(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
4502
+ defaultLogger.debug(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
4452
4503
  }
4453
4504
  const embeddedHtml = await embedLocalFontFaces(htmlWithPreparedGifs, projectDir);
4454
4505
  const { html, externalAssets } = collectExternalAssets(embeddedHtml, projectDir);
@@ -4476,7 +4527,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
4476
4527
  for (const video of videos) {
4477
4528
  if (isHttpUrl(video.src)) continue;
4478
4529
  const videoPath = resolve6(projectDir, video.src);
4479
- if (advised.has(videoPath)) continue;
4530
+ if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath)) continue;
4480
4531
  advised.add(videoPath);
4481
4532
  const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
4482
4533
  (async () => {
@@ -4895,7 +4946,7 @@ function resolveEntryHtmlPath(input) {
4895
4946
  const rawEntry = readTextFile2(htmlPath);
4896
4947
  if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
4897
4948
  const projectIndexPath = join9(projectDir, "index.html");
4898
- if (!existsSync9(projectIndexPath)) {
4949
+ if (!existsSync8(projectIndexPath)) {
4899
4950
  throw new Error(
4900
4951
  `Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
4901
4952
  );
@@ -4915,6 +4966,14 @@ function resolveEntryHtmlPath(input) {
4915
4966
  log.info("Extracted standalone entry from index.html host context", { entryFile });
4916
4967
  return wrapperPath;
4917
4968
  }
4969
+ function applyChroma444Gate(cfg, chromaSubsampling, gate, log) {
4970
+ if (!cfg.useDrawElement || chromaSubsampling !== "444") return gate;
4971
+ cfg.useDrawElement = false;
4972
+ log.info(
4973
+ "[Render] Fast capture: chromaSubsampling 444 captures lossless PNG frames, so disabling drawElementImage for this render. Capture uses the platform's baseline route."
4974
+ );
4975
+ return "chroma_444";
4976
+ }
4918
4977
  async function runCompileStage(input) {
4919
4978
  const {
4920
4979
  projectDir,
@@ -4966,6 +5025,7 @@ async function runCompileStage(input) {
4966
5025
  "[Render] Fast capture: composition uses shader transitions, so disabling drawElementImage so page-side compositing stays available."
4967
5026
  );
4968
5027
  }
5028
+ deCompileGate = applyChroma444Gate(cfg, job.config.chromaSubsampling, deCompileGate, log);
4969
5029
  if (!cfg.useDrawElement && cfg.pageSideCompositingAutoDisabled) {
4970
5030
  cfg.enablePageSideCompositing = true;
4971
5031
  cfg.pageSideCompositingAutoDisabled = false;
@@ -5041,7 +5101,7 @@ async function runCompileStage(input) {
5041
5101
  }
5042
5102
 
5043
5103
  // src/services/render/stages/probeStage.ts
5044
- import { createHash as createHash5 } from "node:crypto";
5104
+ import { createHash as createHash6 } from "node:crypto";
5045
5105
  import { basename as basename4, join as join10 } from "node:path";
5046
5106
  import { parseHTML as parseHTML6 } from "linkedom";
5047
5107
  import {
@@ -5077,11 +5137,19 @@ function isActionableProbeFailure(line) {
5077
5137
 
5078
5138
  // src/services/render/captureImageFormat.ts
5079
5139
  function resolveCaptureImageFormat(input) {
5080
- return input.needsAlpha || input.motionBlur ? "png" : "jpeg";
5140
+ return input.needsAlpha || input.motionBlur || input.chromaSubsampling === "444" ? "png" : "jpeg";
5081
5141
  }
5082
5142
  function resolveCaptureJpegQuality(quality) {
5083
5143
  return quality === "draft" ? 80 : 100;
5084
5144
  }
5145
+ function resolveCaptureSurface(input, quality) {
5146
+ const format = resolveCaptureImageFormat(input);
5147
+ return {
5148
+ format,
5149
+ quality: format === "png" ? void 0 : resolveCaptureJpegQuality(quality),
5150
+ transparent: input.needsAlpha
5151
+ };
5152
+ }
5085
5153
 
5086
5154
  // src/services/render/stages/probeStage.ts
5087
5155
  var FRAME_BOUNDARY_EPSILON = 1e-3;
@@ -5193,7 +5261,7 @@ function reportedLengthSource(source) {
5193
5261
  if (!source) return null;
5194
5262
  if (source.from !== "media") return { from: source.from };
5195
5263
  const name = basename4(source.src.split(/[?#]/, 1)[0] ?? "");
5196
- const srcHash = createHash5("sha256").update(name).digest("hex").slice(0, 12);
5264
+ const srcHash = createHash6("sha256").update(name).digest("hex").slice(0, 12);
5197
5265
  return { from: "media", tag: source.tag, trimmed: source.trimmed, srcHash };
5198
5266
  }
5199
5267
  async function runProbeStage(input) {
@@ -5211,7 +5279,8 @@ async function runProbeStage(input) {
5211
5279
  height,
5212
5280
  needsAlpha,
5213
5281
  deviceScaleFactor,
5214
- subTimelineWaitMemo
5282
+ subTimelineWaitMemo,
5283
+ staticDedupMemo
5215
5284
  } = input;
5216
5285
  let { compiled } = input;
5217
5286
  const probeCfg = cfg.forceScreenshot === forceScreenshot ? cfg : { ...cfg, forceScreenshot };
@@ -5258,21 +5327,25 @@ async function runProbeStage(input) {
5258
5327
  });
5259
5328
  assertNotAborted();
5260
5329
  const motionBlur = job.config.motionBlur;
5261
- const captureFormat = resolveCaptureImageFormat({ needsAlpha, motionBlur });
5262
5330
  const captureOpts = {
5263
5331
  recordReferenceBackground: input.recordReferenceBackground,
5264
5332
  width,
5265
5333
  height,
5266
5334
  fps: job.config.fps,
5267
- format: captureFormat,
5268
- transparent: needsAlpha,
5269
- quality: captureFormat === "png" ? void 0 : resolveCaptureJpegQuality(job.config.quality),
5335
+ ...resolveCaptureSurface(
5336
+ { needsAlpha, motionBlur, chromaSubsampling: job.config.chromaSubsampling },
5337
+ job.config.quality
5338
+ ),
5270
5339
  variables: job.config.variables,
5271
5340
  deviceScaleFactor,
5272
5341
  motionBlur,
5273
5342
  pageMotionBlur: job.config.pageMotionBlur,
5274
5343
  requiresWebGpu: compositionRequiresWebGpu(compiled.html),
5275
- subTimelineWaitMemo
5344
+ subTimelineWaitMemo,
5345
+ staticDedupMemo,
5346
+ compositionHash: computeCompositionObservabilityHash(compiled.html),
5347
+ deferStaticDedup: true,
5348
+ onStaticDedupActivity: () => noteStaticDedupActivity(job)
5276
5349
  };
5277
5350
  const PROBE_MAX_ATTEMPTS = 2;
5278
5351
  for (let attempt = 1; attempt <= PROBE_MAX_ATTEMPTS; attempt++) {
@@ -5761,7 +5834,7 @@ function validateDistributedDuration(input) {
5761
5834
  }
5762
5835
 
5763
5836
  // src/services/render/stages/extractVideosStage.ts
5764
- import { existsSync as existsSync10 } from "node:fs";
5837
+ import { existsSync as existsSync9 } from "node:fs";
5765
5838
  import { join as join11 } from "node:path";
5766
5839
  import {
5767
5840
  classifyVideoExtractionError,
@@ -6036,7 +6109,7 @@ async function runExtractVideosStage(input) {
6036
6109
  const probeFailures = await Promise.all(
6037
6110
  composition.videos.map(async (v) => {
6038
6111
  const videoPath = resolveProjectRelativeSrc3(v.src, projectDir, compiledDir);
6039
- if (!existsSync10(videoPath)) return null;
6112
+ if (!existsSync9(videoPath)) return null;
6040
6113
  try {
6041
6114
  const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata3(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata3(videoPath), {
6042
6115
  signal: abortSignal,
@@ -6074,7 +6147,7 @@ async function runExtractVideosStage(input) {
6074
6147
  const probed = await Promise.all(
6075
6148
  composition.images.map(async (img) => {
6076
6149
  const imgPath = resolveProjectRelativeSrc3(img.src, projectDir, compiledDir);
6077
- if (!existsSync10(imgPath)) return null;
6150
+ if (!existsSync9(imgPath)) return null;
6078
6151
  const colorSpace = await probeColorSpaceSafely(imgPath, log);
6079
6152
  if (isHdrColorSpace2(colorSpace)) {
6080
6153
  nativeHdrImageIds.add(img.id);
@@ -6194,7 +6267,7 @@ async function appendVideoAudioFromProbe(input) {
6194
6267
  videos.map(async (video) => {
6195
6268
  const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc3(video.src, projectDir, compiledDir);
6196
6269
  const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
6197
- if (!isHttpUrl2(readFrom) && !existsSync10(readFrom)) return null;
6270
+ if (!isHttpUrl2(readFrom) && !existsSync9(readFrom)) return null;
6198
6271
  const metadata = await extractMediaMetadata3(readFrom);
6199
6272
  const window2 = await resolveFinalFrameExtractionWindow2(
6200
6273
  readFrom,
@@ -6222,7 +6295,7 @@ import {
6222
6295
  } from "@hyperframes/engine";
6223
6296
 
6224
6297
  // src/services/render/stages/audioStage.ts
6225
- import { existsSync as existsSync12 } from "node:fs";
6298
+ import { existsSync as existsSync11 } from "node:fs";
6226
6299
  import { join as join14 } from "node:path";
6227
6300
  import {
6228
6301
  MIXED_AUDIO_FILENAME,
@@ -6233,7 +6306,7 @@ import {
6233
6306
  } from "@hyperframes/engine";
6234
6307
 
6235
6308
  // src/services/render/audioDeliveryLimit.ts
6236
- import { existsSync as existsSync11 } from "node:fs";
6309
+ import { existsSync as existsSync10 } from "node:fs";
6237
6310
  import { dirname as dirname8, join as join13 } from "node:path";
6238
6311
  import {
6239
6312
  applyAudioFxChain,
@@ -6742,7 +6815,7 @@ async function limitDeliveryPeaks(input, deps = {
6742
6815
  applyChain: applyAudioFxChain,
6743
6816
  encode: encodeAac2,
6744
6817
  rename: renameWithRetry6,
6745
- sourceExists: existsSync11
6818
+ sourceExists: existsSync10
6746
6819
  }) {
6747
6820
  const { audioPath, sourcePath, signal, timeoutMs } = input;
6748
6821
  if (!deps.sourceExists(sourcePath)) return { success: true };
@@ -6837,7 +6910,7 @@ async function runAudioStageScoped(input) {
6837
6910
  );
6838
6911
  audioLoweredDb = guard.loweredDb;
6839
6912
  input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
6840
- if (input.keepDeliverySource && !guard.sourceStale && existsSync12(pcmSourcePath)) {
6913
+ if (input.keepDeliverySource && !guard.sourceStale && existsSync11(pcmSourcePath)) {
6841
6914
  deliverySourcePath = pcmSourcePath;
6842
6915
  }
6843
6916
  }
@@ -6965,7 +7038,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
6965
7038
  }
6966
7039
 
6967
7040
  // src/services/render/stages/captureStage.ts
6968
- import { existsSync as existsSync13, readdirSync, statfsSync } from "node:fs";
7041
+ import { existsSync as existsSync12, readdirSync, statfsSync } from "node:fs";
6969
7042
  import { join as join15 } from "node:path";
6970
7043
  import {
6971
7044
  classifyCaptureFailure as classifyCaptureFailure2,
@@ -7017,7 +7090,7 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
7017
7090
  }
7018
7091
  function measureCaptureFrameBytes(workDir, framesDir) {
7019
7092
  let total = sampleDirectoryBytes(framesDir);
7020
- if (!existsSync13(workDir)) return total;
7093
+ if (!existsSync12(workDir)) return total;
7021
7094
  for (const attempt of readdirSync(workDir)) {
7022
7095
  if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
7023
7096
  total += sampleDirectoryBytes(join15(workDir, attempt));
@@ -7199,7 +7272,7 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
7199
7272
  captureBeyondViewport = session.options.captureBeyondViewport;
7200
7273
  try {
7201
7274
  if (probeSession) {
7202
- prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
7275
+ await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
7203
7276
  probeSession = null;
7204
7277
  }
7205
7278
  await ensureSessionReady(session, {
@@ -7358,7 +7431,7 @@ import {
7358
7431
  // src/services/render/stages/encodeStage.ts
7359
7432
  import {
7360
7433
  copyFileSync as copyFileSync4,
7361
- existsSync as existsSync14,
7434
+ existsSync as existsSync13,
7362
7435
  mkdirSync as mkdirSync5,
7363
7436
  readdirSync as readdirSync2,
7364
7437
  readFileSync as readFileSync6,
@@ -7492,7 +7565,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
7492
7565
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
7493
7566
  if (failure) return failure;
7494
7567
  }
7495
- const fileSize = existsSync14(outputPath) ? statSync4(outputPath).size : 0;
7568
+ const fileSize = existsSync13(outputPath) ? statSync4(outputPath).size : 0;
7496
7569
  return {
7497
7570
  success: true,
7498
7571
  outputPath,
@@ -7653,7 +7726,7 @@ async function runEncodeStage(input) {
7653
7726
  const stage5Start = Date.now();
7654
7727
  if (isPngSequence) {
7655
7728
  const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
7656
- if (!existsSync14(outputPath)) mkdirSync5(outputPath, { recursive: true });
7729
+ if (!existsSync13(outputPath)) mkdirSync5(outputPath, { recursive: true });
7657
7730
  const captured = readdirSync2(framesDir).filter((name) => name.endsWith(".png")).sort();
7658
7731
  if (captured.length === 0) {
7659
7732
  throw new Error(
@@ -7664,7 +7737,7 @@ async function runEncodeStage(input) {
7664
7737
  const dst = join16(outputPath, formatExportFrameName(i, "png"));
7665
7738
  copyFileSync4(join16(framesDir, name), dst);
7666
7739
  });
7667
- if (hasAudio && audioOutputPath && existsSync14(audioOutputPath)) {
7740
+ if (hasAudio && audioOutputPath && existsSync13(audioOutputPath)) {
7668
7741
  copyFileSync4(audioOutputPath, join16(outputPath, MIXED_AUDIO_FILENAME2));
7669
7742
  log.info(
7670
7743
  `[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
@@ -7827,7 +7900,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
7827
7900
  let rangeStart = null;
7828
7901
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
7829
7902
  const framePath = join17(framesDir, formatCaptureFrameName(frameIndex, frameExt));
7830
- const missing = !existsSync15(framePath) || statSync5(framePath).size <= 8;
7903
+ const missing = !existsSync14(framePath) || statSync5(framePath).size <= 8;
7831
7904
  if (missing && rangeStart === null) {
7832
7905
  rangeStart = frameIndex;
7833
7906
  } else if (!missing && rangeStart !== null) {
@@ -7893,17 +7966,25 @@ function captureAttemptMadeProgress(attemptTargetFrameCount, remainingFrameCount
7893
7966
  return remainingFrameCount < attemptTargetFrameCount;
7894
7967
  }
7895
7968
  var FIRST_FRAME_STALL_MS = 3e5;
7969
+ var FIRST_FRAME_STARTUP_FACTOR = 2;
7970
+ var FIRST_FRAME_STALL_CEILING_MS = 9e5;
7896
7971
  var TAIL_STALL_MS = FIRST_FRAME_STALL_MS;
7897
- function frameStallRule(job, totalFrames) {
7972
+ function firstFrameWindowMs(probeStartupMs) {
7973
+ const fromStartup = (probeStartupMs ?? 0) * FIRST_FRAME_STARTUP_FACTOR;
7974
+ if (!Number.isFinite(fromStartup)) return FIRST_FRAME_STALL_MS;
7975
+ return Math.max(FIRST_FRAME_STALL_MS, Math.min(FIRST_FRAME_STALL_CEILING_MS, fromStartup));
7976
+ }
7977
+ function frameStallRule(job, totalFrames, probeStartupMs) {
7898
7978
  const noProgressMs = resolveCaptureStallTimeoutMs();
7899
7979
  return {
7900
7980
  progress: () => job.framesRendered ?? 0,
7901
7981
  noProgressMs,
7902
- firstProgressMs: Math.max(FIRST_FRAME_STALL_MS, noProgressMs),
7982
+ firstProgressMs: Math.max(firstFrameWindowMs(probeStartupMs), noProgressMs),
7903
7983
  complete: () => (job.framesRendered ?? 0) >= totalFrames,
7904
7984
  tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
7905
7985
  detail: () => describeWorkerPhases(job),
7906
- attemptOpened: () => forgetWorkerPhases(job)
7986
+ attemptOpened: () => forgetWorkerPhases(job),
7987
+ activity: () => staticDedupActivity(job)
7907
7988
  };
7908
7989
  }
7909
7990
  function isRecoverableParallelCaptureError(error) {
@@ -7917,7 +7998,7 @@ function countCapturedFrames(totalFrames, framesDir, frameExt) {
7917
7998
  let captured = 0;
7918
7999
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
7919
8000
  const framePath = join17(framesDir, formatCaptureFrameName(frameIndex, frameExt));
7920
- if (existsSync15(framePath)) captured++;
8001
+ if (existsSync14(framePath)) captured++;
7921
8002
  }
7922
8003
  return captured;
7923
8004
  }
@@ -8144,17 +8225,18 @@ import {
8144
8225
  } from "@hyperframes/engine";
8145
8226
 
8146
8227
  // src/services/distributed/chunkFrames.ts
8147
- import { existsSync as existsSync17, readdirSync as readdirSync4 } from "node:fs";
8228
+ import { existsSync as existsSync16, readdirSync as readdirSync4 } from "node:fs";
8148
8229
  import { extname as extname2, join as join19 } from "node:path";
8149
8230
  import {
8150
8231
  compositionRequiresWebGpu as compositionRequiresWebGpu3,
8151
- createVideoFrameInjector as createVideoFrameInjector3
8232
+ createVideoFrameInjector as createVideoFrameInjector3,
8233
+ mediaIdPathSegment as mediaIdPathSegment3
8152
8234
  } from "@hyperframes/engine";
8153
8235
 
8154
8236
  // src/services/distributed/shared.ts
8155
8237
  import { execFile as execFileCallback } from "node:child_process";
8156
8238
  import { dirname as dirname11, join as join18 } from "node:path";
8157
- import { existsSync as existsSync16, readFileSync as readFileSync7 } from "node:fs";
8239
+ import { existsSync as existsSync15, readFileSync as readFileSync7 } from "node:fs";
8158
8240
  import { fileURLToPath as fileURLToPath3 } from "node:url";
8159
8241
  import { promisify as promisify2 } from "node:util";
8160
8242
  import {
@@ -8170,7 +8252,7 @@ function isPlanAudioArtifactPath(path) {
8170
8252
  function resolvePlanAudioPath(planDir) {
8171
8253
  for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
8172
8254
  const candidate = join18(planDir, name);
8173
- if (existsSync16(candidate)) return candidate;
8255
+ if (existsSync15(candidate)) return candidate;
8174
8256
  }
8175
8257
  return null;
8176
8258
  }
@@ -8431,7 +8513,7 @@ function readProducerVersion() {
8431
8513
  let current = startDir;
8432
8514
  for (let i = 0; i < 10; i++) {
8433
8515
  const candidate = join18(current, "package.json");
8434
- if (existsSync16(candidate)) {
8516
+ if (existsSync15(candidate)) {
8435
8517
  try {
8436
8518
  const pkg = JSON.parse(readFileSync7(candidate, "utf-8"));
8437
8519
  if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
@@ -8485,8 +8567,8 @@ function frameNumberFromFileName(name) {
8485
8567
  function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
8486
8568
  const result = [];
8487
8569
  for (const v of videos) {
8488
- const outputDir = join19(planDir, "video-frames", v.videoId);
8489
- if (!existsSync17(outputDir)) {
8570
+ const outputDir = join19(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
8571
+ if (!existsSync16(outputDir)) {
8490
8572
  throw new Error(
8491
8573
  `[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
8492
8574
  );
@@ -8585,7 +8667,7 @@ async function extractDeferredVideoFramesForChunk(input) {
8585
8667
  const range = planned.get(video.videoId).deferredRange;
8586
8668
  const remoteUrl = remoteSources[range.sourcePath];
8587
8669
  const sourcePath = remoteUrl ?? join19(input.planDir, ...range.sourcePath.split("/"));
8588
- if (remoteUrl === void 0 && !existsSync17(sourcePath)) {
8670
+ if (remoteUrl === void 0 && !existsSync16(sourcePath)) {
8589
8671
  throw new RenderChunkValidationError(
8590
8672
  MISSING_PLAN_ARTIFACT,
8591
8673
  `[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
@@ -8785,7 +8867,7 @@ async function readPlanReferenceBackground(input) {
8785
8867
  }
8786
8868
 
8787
8869
  // src/services/render/stages/freezePlan.ts
8788
- import { existsSync as existsSync18, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync5, writeFileSync as writeFileSync6 } from "node:fs";
8870
+ import { existsSync as existsSync17, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync5, writeFileSync as writeFileSync6 } from "node:fs";
8789
8871
  import { join as join22, relative as relative3, resolve as resolve8 } from "node:path";
8790
8872
  import {
8791
8873
  REFERENCE_BACKGROUND_FIELD,
@@ -8884,12 +8966,12 @@ function readPlanProtocolV1(planJson, capabilities = DISTRIBUTED_RENDER_CAPABILI
8884
8966
  }
8885
8967
 
8886
8968
  // src/services/render/stages/planHash.ts
8887
- import { createHash as createHash6 } from "node:crypto";
8969
+ import { createHash as createHash7 } from "node:crypto";
8888
8970
  import { closeSync as closeSync3, createReadStream as createReadStream3, openSync as openSync3, readSync as readSync2 } from "node:fs";
8889
8971
  var PLAN_HASH_SCHEMA_PREFIX = "hyperframes-plan-hash-v1\0";
8890
8972
  var FIELD_DELIMITER = Buffer.from([0]);
8891
8973
  function computePlanHash(input) {
8892
- const hash = createHash6("sha256");
8974
+ const hash = createHash7("sha256");
8893
8975
  hash.update(PLAN_HASH_SCHEMA_PREFIX, "utf8");
8894
8976
  hash.update(input.compositionHtml);
8895
8977
  hash.update(FIELD_DELIMITER);
@@ -8936,12 +9018,12 @@ function canonicalJsonStringify(value) {
8936
9018
  throw new TypeError(`canonicalJsonStringify: unsupported value type ${typeof value}`);
8937
9019
  }
8938
9020
  function sha256Hex(bytes) {
8939
- const h = createHash6("sha256");
9021
+ const h = createHash7("sha256");
8940
9022
  h.update(bytes);
8941
9023
  return h.digest("hex");
8942
9024
  }
8943
9025
  function sha256File(path) {
8944
- const hash = createHash6("sha256");
9026
+ const hash = createHash7("sha256");
8945
9027
  const buffer = Buffer.allocUnsafe(1024 * 1024);
8946
9028
  const fd = openSync3(path, "r");
8947
9029
  try {
@@ -8956,7 +9038,7 @@ function sha256File(path) {
8956
9038
  return hash.digest("hex");
8957
9039
  }
8958
9040
  async function sha256FileAsync(path) {
8959
- const hash = createHash6("sha256");
9041
+ const hash = createHash7("sha256");
8960
9042
  for await (const chunk of createReadStream3(path, { highWaterMark: 1024 * 1024 })) {
8961
9043
  hash.update(chunk);
8962
9044
  }
@@ -8979,7 +9061,7 @@ function planFileSha256(absolutePath, digests) {
8979
9061
  return sha256;
8980
9062
  }
8981
9063
  async function prehashPlanFiles(dir, digests) {
8982
- if (!existsSync18(dir)) return;
9064
+ if (!existsSync17(dir)) return;
8983
9065
  for (const { absolutePath } of listPlanFiles(dir)) {
8984
9066
  if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
8985
9067
  }
@@ -9049,15 +9131,15 @@ function writePlanRemoteFiles(planDir, files) {
9049
9131
  }
9050
9132
  function readPlanRemoteFiles(planDir) {
9051
9133
  const path = join22(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
9052
- return existsSync18(path) ? JSON.parse(readFileSync8(path, "utf-8")) : [];
9134
+ return existsSync17(path) ? JSON.parse(readFileSync8(path, "utf-8")) : [];
9053
9135
  }
9054
9136
  function recomputePlanHashFromPlanDir(planDir, digests) {
9055
9137
  const planJsonPath = join22(planDir, "plan.json");
9056
9138
  const encoderJsonPath = join22(planDir, "meta", "encoder.json");
9057
- if (!existsSync18(planJsonPath)) {
9139
+ if (!existsSync17(planJsonPath)) {
9058
9140
  throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
9059
9141
  }
9060
- if (!existsSync18(encoderJsonPath)) {
9142
+ if (!existsSync17(encoderJsonPath)) {
9061
9143
  throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
9062
9144
  }
9063
9145
  const planJson = JSON.parse(readFileSync8(planJsonPath, "utf-8"));
@@ -9087,11 +9169,11 @@ async function freezePlan(input) {
9087
9169
  hasAudio,
9088
9170
  digests
9089
9171
  } = input;
9090
- if (!existsSync18(planDir)) {
9172
+ if (!existsSync17(planDir)) {
9091
9173
  throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
9092
9174
  }
9093
9175
  const metaDir = join22(planDir, "meta");
9094
- if (!existsSync18(metaDir)) mkdirSync7(metaDir, { recursive: true });
9176
+ if (!existsSync17(metaDir)) mkdirSync7(metaDir, { recursive: true });
9095
9177
  writeFileSync6(
9096
9178
  join22(metaDir, "composition.json"),
9097
9179
  `${JSON.stringify(composition, null, 2)}
@@ -9168,7 +9250,7 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
9168
9250
  }
9169
9251
 
9170
9252
  // src/services/distributed/chunkAudio.ts
9171
- import { closeSync as closeSync4, existsSync as existsSync19, ftruncateSync, mkdirSync as mkdirSync9, openSync as openSync4, readFileSync as readFileSync9 } from "node:fs";
9253
+ import { closeSync as closeSync4, existsSync as existsSync18, ftruncateSync, mkdirSync as mkdirSync9, openSync as openSync4, readFileSync as readFileSync9 } from "node:fs";
9172
9254
  import { writeFileSync as writeFileSync7, writeSync } from "node:fs";
9173
9255
  import { join as join24 } from "node:path";
9174
9256
  import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
@@ -9660,7 +9742,7 @@ async function writeChunkAudioSlices(input) {
9660
9742
  }
9661
9743
  function chunkAudioSource(planDir, chunkIndex, scratchPath) {
9662
9744
  const layoutPath = join24(planDir, SLICE_LAYOUT);
9663
- if (!existsSync19(layoutPath)) return resolvePlanAudioPath(planDir);
9745
+ if (!existsSync18(layoutPath)) return resolvePlanAudioPath(planDir);
9664
9746
  const layout = JSON.parse(readFileSync9(layoutPath, "utf-8"));
9665
9747
  const frame = readFileSync9(join24(planDir, SLICE_FRAME));
9666
9748
  const fd = openSync4(scratchPath, "w");
@@ -9729,7 +9811,7 @@ async function muxChunkWithAudio(input) {
9729
9811
  }
9730
9812
 
9731
9813
  // src/services/distributed/planSize.ts
9732
- import { createHash as createHash7 } from "node:crypto";
9814
+ import { createHash as createHash8 } from "node:crypto";
9733
9815
  import { lstatSync, readdirSync as readdirSync6 } from "node:fs";
9734
9816
  import { extname as extname3, join as join25, relative as relative4 } from "node:path";
9735
9817
  var MAX_TOP_COMPONENTS = 10;
@@ -9759,7 +9841,7 @@ var PLAN_ROOT_CATEGORY = {
9759
9841
  "plan.json": "metadata"
9760
9842
  };
9761
9843
  function hashComponent(value) {
9762
- return createHash7("sha256").update(value).digest("hex").slice(0, 12);
9844
+ return createHash8("sha256").update(value).digest("hex").slice(0, 12);
9763
9845
  }
9764
9846
  function classifyFile(segments, rootKind) {
9765
9847
  const rootName = segments[0] ?? "";
@@ -10228,7 +10310,7 @@ function createVideoSourceShipper(input) {
10228
10310
  let result = null;
10229
10311
  for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
10230
10312
  const rel = pathInside(root, srcPath);
10231
- if (rel !== null && (existsSync20(join26(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
10313
+ if (rel !== null && (existsSync19(join26(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
10232
10314
  result = ["compiled", ...rel.split(sep3)].join("/");
10233
10315
  break;
10234
10316
  }
@@ -10256,7 +10338,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
10256
10338
  useGpu: false,
10257
10339
  browserGpuMode: "software"
10258
10340
  });
10259
- if (!existsSync20(planDir)) mkdirSync10(planDir, { recursive: true });
10341
+ if (!existsSync19(planDir)) mkdirSync10(planDir, { recursive: true });
10260
10342
  const log = config.logger ?? defaultLogger;
10261
10343
  const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
10262
10344
  const abortSignal = config.abortSignal;
@@ -10287,7 +10369,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
10287
10369
  });
10288
10370
  const entryFile = config.entryFile ?? "index.html";
10289
10371
  const htmlPath = join26(projectDir, entryFile);
10290
- if (!existsSync20(htmlPath)) {
10372
+ if (!existsSync19(htmlPath)) {
10291
10373
  throw new Error(`[plan] entry file not found: ${htmlPath}`);
10292
10374
  }
10293
10375
  const workDir = join26(planDir, ".plan-work");
@@ -10515,15 +10597,15 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
10515
10597
  logPlanStage(log, "extract", stageStarted);
10516
10598
  const stagedVideoFrames = join26(compiledDir, "__hyperframes_video_frames");
10517
10599
  const videoFramesDst = join26(planDir, "video-frames");
10518
- if (existsSync20(videoFramesDst)) rmSync7(videoFramesDst, { recursive: true, force: true });
10600
+ if (existsSync19(videoFramesDst)) rmSync7(videoFramesDst, { recursive: true, force: true });
10519
10601
  const videoSourcesDir = join26(planDir, "video-sources");
10520
10602
  rmSync7(videoSourcesDir, { recursive: true, force: true });
10521
- if (existsSync20(stagedVideoFrames)) {
10603
+ if (existsSync19(stagedVideoFrames)) {
10522
10604
  renameWithRetry8(stagedVideoFrames, videoFramesDst);
10523
10605
  } else {
10524
10606
  mkdirSync10(videoFramesDst, { recursive: true });
10525
10607
  }
10526
- if (existsSync20(finalCompiledDir)) rmSync7(finalCompiledDir, { recursive: true, force: true });
10608
+ if (existsSync19(finalCompiledDir)) rmSync7(finalCompiledDir, { recursive: true, force: true });
10527
10609
  renameWithRetry8(compiledDir, finalCompiledDir);
10528
10610
  const shipVideoSource = createVideoSourceShipper({
10529
10611
  planDir,
@@ -10644,10 +10726,10 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
10644
10726
  applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
10645
10727
  }
10646
10728
  const planAudioPath = join26(planDir, PLAN_AUDIO_RELATIVE_PATH);
10647
- if (audioResult?.hasAudio && existsSync20(audioResult.audioOutputPath)) {
10729
+ if (audioResult?.hasAudio && existsSync19(audioResult.audioOutputPath)) {
10648
10730
  renameWithRetry8(audioResult.audioOutputPath, planAudioPath);
10649
10731
  }
10650
- if (chunksCarryAudio && existsSync20(planAudioPath)) {
10732
+ if (chunksCarryAudio && existsSync19(planAudioPath)) {
10651
10733
  if (options.sliceChunkAudio) {
10652
10734
  stageStarted = Date.now();
10653
10735
  await writeChunkAudioSlices({
@@ -10760,7 +10842,7 @@ async function buildPlanAudio(projectDir, config, workRoot, outputPath, options
10760
10842
  if (mixed.audioError) {
10761
10843
  applyDistributedAudioWarningPolicy(c.job, mixed.audioError, mixed.audioFailures, c.log);
10762
10844
  }
10763
- if (!mixed.hasAudio || !existsSync20(mixed.audioOutputPath)) return { hasAudio: false };
10845
+ if (!mixed.hasAudio || !existsSync19(mixed.audioOutputPath)) return { hasAudio: false };
10764
10846
  renameWithRetry8(mixed.audioOutputPath, outputPath);
10765
10847
  return { hasAudio: true };
10766
10848
  } finally {
@@ -10775,7 +10857,7 @@ import {
10775
10857
  } from "@hyperframes/engine";
10776
10858
  import {
10777
10859
  copyFileSync as copyFileSync8,
10778
- existsSync as existsSync22,
10860
+ existsSync as existsSync21,
10779
10861
  lstatSync as lstatSync2,
10780
10862
  mkdirSync as mkdirSync12,
10781
10863
  readFileSync as readFileSync10,
@@ -10787,12 +10869,16 @@ import {
10787
10869
  import { tmpdir } from "node:os";
10788
10870
  import { dirname as dirname14, isAbsolute as isAbsolute4, join as join29, relative as relative6, resolve as resolve9, sep as sep4 } from "node:path";
10789
10871
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
10790
- import { createFrameLookupTable as createFrameLookupTable5, renameWithRetry as renameWithRetry10 } from "@hyperframes/engine";
10872
+ import {
10873
+ createFrameLookupTable as createFrameLookupTable5,
10874
+ mediaIdPathSegment as mediaIdPathSegment4,
10875
+ renameWithRetry as renameWithRetry10
10876
+ } from "@hyperframes/engine";
10791
10877
 
10792
10878
  // src/services/distributed/planV2Publisher.ts
10793
10879
  import {
10794
10880
  copyFileSync as copyFileSync7,
10795
- existsSync as existsSync21,
10881
+ existsSync as existsSync20,
10796
10882
  linkSync as linkSync2,
10797
10883
  mkdirSync as mkdirSync11,
10798
10884
  rmSync as rmSync8,
@@ -10861,7 +10947,7 @@ var LocalPlanV2ArtifactPublisher = class {
10861
10947
  #linkFile;
10862
10948
  #committed = false;
10863
10949
  constructor(destinationDir, options = {}) {
10864
- if (existsSync21(destinationDir)) {
10950
+ if (existsSync20(destinationDir)) {
10865
10951
  throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
10866
10952
  }
10867
10953
  this.destinationDir = destinationDir;
@@ -10878,7 +10964,7 @@ var LocalPlanV2ArtifactPublisher = class {
10878
10964
  );
10879
10965
  }
10880
10966
  const destinationPath = planV2BlobPath(this.temporaryDir, digest);
10881
- if (existsSync21(destinationPath)) return;
10967
+ if (existsSync20(destinationPath)) return;
10882
10968
  mkdirSync11(dirname13(destinationPath), { recursive: true });
10883
10969
  const stagingDir = createStagingDir5(dirname13(destinationPath), ".plan-v2-blob-");
10884
10970
  const temporaryPath = join28(stagingDir, "blob");
@@ -10896,7 +10982,7 @@ var LocalPlanV2ArtifactPublisher = class {
10896
10982
  }
10897
10983
  async commitManifest(manifestBytes) {
10898
10984
  for (const digest of new Set(manifestDigests(manifestBytes))) {
10899
- if (!existsSync21(planV2BlobPath(this.temporaryDir, digest))) {
10985
+ if (!existsSync20(planV2BlobPath(this.temporaryDir, digest))) {
10900
10986
  throw new PlanV2IntegrityError(
10901
10987
  `cannot commit manifest before referenced blob is durable: ${digest}`
10902
10988
  );
@@ -10976,7 +11062,7 @@ function assertValidExtractionCacheCompleteSentinel(path) {
10976
11062
  }
10977
11063
  function validateExtractionCacheCompleteSentinels(executionPlanDir) {
10978
11064
  const videoRoot = join29(executionPlanDir, "video-frames");
10979
- if (!existsSync22(videoRoot)) return;
11065
+ if (!existsSync21(videoRoot)) return;
10980
11066
  for (const videoEntry of readdirSync7(videoRoot, { withFileTypes: true })) {
10981
11067
  if (!videoEntry.isDirectory()) continue;
10982
11068
  const videoDir = join29(videoRoot, videoEntry.name);
@@ -10992,7 +11078,7 @@ function isExtractionCacheCompleteSentinelPath(path) {
10992
11078
  }
10993
11079
  function resolveExtractedVideoOutputDir(planDir, videoId) {
10994
11080
  const videoRoot = resolve9(planDir, "video-frames");
10995
- const outputDir = resolve9(videoRoot, videoId);
11081
+ const outputDir = resolve9(videoRoot, mediaIdPathSegment4(videoId));
10996
11082
  if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep4}`)) {
10997
11083
  throw new PlanV2IntegrityError(`unsafe extracted video id: ${JSON.stringify(videoId)}`);
10998
11084
  }
@@ -11077,7 +11163,7 @@ function parsePlanVideosJson2(value) {
11077
11163
  }
11078
11164
  function materializeExtractedVideoDirectories(planDir) {
11079
11165
  const videosPath = join29(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
11080
- if (!existsSync22(videosPath)) return;
11166
+ if (!existsSync21(videosPath)) return;
11081
11167
  const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
11082
11168
  for (const video of videos.extracted) {
11083
11169
  mkdirSync12(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
@@ -11111,9 +11197,9 @@ function parseChunkSlices(value) {
11111
11197
  }
11112
11198
  function buildVideoChunkDependencies(executionPlanDir, dimensions) {
11113
11199
  const videoRoot = join29(executionPlanDir, "video-frames");
11114
- const hasExtractedFrames = existsSync22(videoRoot) && listFiles(videoRoot).length > 0;
11200
+ const hasExtractedFrames = existsSync21(videoRoot) && listFiles(videoRoot).length > 0;
11115
11201
  const videosPath = join29(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
11116
- if (!existsSync22(videosPath)) {
11202
+ if (!existsSync21(videosPath)) {
11117
11203
  return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
11118
11204
  }
11119
11205
  const chunksPath = join29(executionPlanDir, "meta", "chunks.json");
@@ -11170,7 +11256,7 @@ function computeManifestHash(manifest) {
11170
11256
  return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
11171
11257
  }
11172
11258
  function writeBlob(sourcePath, destinationPath) {
11173
- if (existsSync22(destinationPath)) return;
11259
+ if (existsSync21(destinationPath)) return;
11174
11260
  mkdirSync12(dirname14(destinationPath), { recursive: true });
11175
11261
  const temporaryDir = createStagingDir6(dirname14(destinationPath), ".plan-v2-blob-");
11176
11262
  const temporaryPath = join29(temporaryDir, "blob");
@@ -11210,7 +11296,7 @@ async function putTasks(tasks) {
11210
11296
  }
11211
11297
  function buildPlanV2Publication(executionPlanDir, digests) {
11212
11298
  const executionPlanPath = join29(executionPlanDir, "plan.json");
11213
- if (!existsSync22(executionPlanPath)) {
11299
+ if (!existsSync21(executionPlanPath)) {
11214
11300
  throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
11215
11301
  }
11216
11302
  const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
@@ -11290,7 +11376,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
11290
11376
  };
11291
11377
  }
11292
11378
  function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
11293
- if (existsSync22(planV2Dir)) {
11379
+ if (existsSync21(planV2Dir)) {
11294
11380
  throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
11295
11381
  }
11296
11382
  const publication = buildPlanV2Publication(executionPlanDir);
@@ -11376,7 +11462,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
11376
11462
  }
11377
11463
  }
11378
11464
  async function planV2(projectDir, config, planV2Dir) {
11379
- if (existsSync22(planV2Dir)) {
11465
+ if (existsSync21(planV2Dir)) {
11380
11466
  throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
11381
11467
  }
11382
11468
  const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
@@ -11530,7 +11616,7 @@ function parsePlanV2Manifest(value) {
11530
11616
  }
11531
11617
  function readPlanV2Manifest(planV2Dir) {
11532
11618
  const manifestPath = join29(planV2Dir, "plan.json");
11533
- if (!existsSync22(manifestPath)) {
11619
+ if (!existsSync21(manifestPath)) {
11534
11620
  throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
11535
11621
  }
11536
11622
  const value = readJsonFile(manifestPath, "v2 manifest");
@@ -11549,7 +11635,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
11549
11635
  }
11550
11636
  function verifyBlob(planV2Dir, artifact) {
11551
11637
  const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
11552
- if (!existsSync22(sourcePath)) {
11638
+ if (!existsSync21(sourcePath)) {
11553
11639
  throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
11554
11640
  }
11555
11641
  const stats = statSync7(sourcePath);
@@ -11562,7 +11648,7 @@ function verifyBlob(planV2Dir, artifact) {
11562
11648
  return sourcePath;
11563
11649
  }
11564
11650
  function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
11565
- if (existsSync22(destinationDir)) {
11651
+ if (existsSync21(destinationDir)) {
11566
11652
  throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
11567
11653
  }
11568
11654
  const manifest = readPlanV2Manifest(planV2Dir);
@@ -11627,7 +11713,7 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
11627
11713
  }
11628
11714
  function readValidatedPlanV2Materialization(planDir, expectedTarget) {
11629
11715
  const markerPath = join29(planDir, PLAN_V2_MATERIALIZATION_MARKER);
11630
- if (!existsSync22(markerPath)) return null;
11716
+ if (!existsSync21(markerPath)) return null;
11631
11717
  const marker = readJsonFile(markerPath, "materialization marker");
11632
11718
  if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
11633
11719
  throw new PlanV2IntegrityError("malformed materialization marker");
@@ -11645,7 +11731,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
11645
11731
  for (const artifact of required) {
11646
11732
  if (Object.hasOwn(remoteSources, artifact.path)) continue;
11647
11733
  const path = join29(planDir, ...artifact.path.split("/"));
11648
- if (!existsSync22(path) || statSync7(path).size !== artifact.sizeBytes) {
11734
+ if (!existsSync21(path) || statSync7(path).size !== artifact.sizeBytes) {
11649
11735
  throw new PlanV2IntegrityError(
11650
11736
  `materialized artifact missing or truncated: ${artifact.path}`
11651
11737
  );
@@ -11669,7 +11755,7 @@ import {
11669
11755
  } from "@hyperframes/engine";
11670
11756
  import {
11671
11757
  cpSync as cpSync3,
11672
- existsSync as existsSync23,
11758
+ existsSync as existsSync22,
11673
11759
  mkdirSync as mkdirSync13,
11674
11760
  readFileSync as readFileSync11,
11675
11761
  readdirSync as readdirSync8,
@@ -11724,7 +11810,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11724
11810
  }
11725
11811
  const format = plan.dimensions.format;
11726
11812
  const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
11727
- if (!existsSync23(dirname15(outputPath))) {
11813
+ if (!existsSync22(dirname15(outputPath))) {
11728
11814
  mkdirSync13(dirname15(outputPath), { recursive: true });
11729
11815
  }
11730
11816
  const workDir = createStagingDir7(dirname15(outputPath), `${basename6(outputPath)}.assemble-work-`);
@@ -11748,7 +11834,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11748
11834
  try {
11749
11835
  const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
11750
11836
  const finalPath = join30(workDir, `output.${format}`);
11751
- const audio = audioPath !== null && existsSync23(audioPath) ? audioPath : null;
11837
+ const audio = audioPath !== null && existsSync22(audioPath) ? audioPath : null;
11752
11838
  await writeJoined(ctx, videoSources, audio, finalPath);
11753
11839
  renameWithRetry11(finalPath, outputPath);
11754
11840
  log.info("[assemble] stage timings", {
@@ -11766,7 +11852,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11766
11852
  });
11767
11853
  }
11768
11854
  }
11769
- const fileSize = existsSync23(outputPath) ? statSync8(outputPath).size : 0;
11855
+ const fileSize = existsSync22(outputPath) ? statSync8(outputPath).size : 0;
11770
11856
  return {
11771
11857
  ...referenceBackgroundResult6(plan[REFERENCE_BACKGROUND_FIELD4]),
11772
11858
  outputPath,
@@ -11778,13 +11864,13 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11778
11864
  function readAssemblePlan(planDir, chunkPaths) {
11779
11865
  const planJsonPath = join30(planDir, "plan.json");
11780
11866
  const chunksJsonPath = join30(planDir, "meta", "chunks.json");
11781
- if (!existsSync23(planJsonPath)) {
11867
+ if (!existsSync22(planJsonPath)) {
11782
11868
  throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
11783
11869
  }
11784
11870
  const plan = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
11785
11871
  readPlanProtocolV1(plan, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
11786
11872
  validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
11787
- if (!existsSync23(chunksJsonPath)) {
11873
+ if (!existsSync22(chunksJsonPath)) {
11788
11874
  throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
11789
11875
  }
11790
11876
  const chunks = JSON.parse(readFileSync11(chunksJsonPath, "utf-8"));
@@ -11799,7 +11885,7 @@ function readAssemblePlan(planDir, chunkPaths) {
11799
11885
  }
11800
11886
  }
11801
11887
  for (const path of chunkPaths.flat()) {
11802
- if (!existsSync23(path)) {
11888
+ if (!existsSync22(path)) {
11803
11889
  throw new Error(`[assemble] chunk path does not exist: ${path}`);
11804
11890
  }
11805
11891
  }
@@ -11938,7 +12024,7 @@ function planFormat(planDir) {
11938
12024
  }
11939
12025
  function lockedAudio(planDir) {
11940
12026
  const encoderJsonPath = join30(planDir, "meta", "encoder.json");
11941
- if (!existsSync23(encoderJsonPath)) return {};
12027
+ if (!existsSync22(encoderJsonPath)) return {};
11942
12028
  return JSON.parse(readFileSync11(encoderJsonPath, "utf-8"));
11943
12029
  }
11944
12030
  function readCfrEncoder(planDir, format) {
@@ -11948,7 +12034,7 @@ function readCfrEncoder(planDir, format) {
11948
12034
  );
11949
12035
  }
11950
12036
  const encoderJsonPath = join30(planDir, "meta", "encoder.json");
11951
- if (!existsSync23(encoderJsonPath)) {
12037
+ if (!existsSync22(encoderJsonPath)) {
11952
12038
  throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
11953
12039
  }
11954
12040
  const encoderJson = JSON.parse(readFileSync11(encoderJsonPath, "utf-8"));
@@ -11960,7 +12046,7 @@ function readCfrEncoder(planDir, format) {
11960
12046
  return encoderJson;
11961
12047
  }
11962
12048
  function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
11963
- if (existsSync23(outputPath)) rmSync10(outputPath, { recursive: true, force: true });
12049
+ if (existsSync22(outputPath)) rmSync10(outputPath, { recursive: true, force: true });
11964
12050
  mkdirSync13(outputPath, { recursive: true });
11965
12051
  let globalIdx = 0;
11966
12052
  for (const chunkDir of chunkPaths) {
@@ -11984,7 +12070,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
11984
12070
  `[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
11985
12071
  );
11986
12072
  }
11987
- if (audioPath !== null && existsSync23(audioPath)) {
12073
+ if (audioPath !== null && existsSync22(audioPath)) {
11988
12074
  const sidecar = join30(outputPath, MIXED_AUDIO_FILENAME4);
11989
12075
  cpSync3(audioPath, sidecar);
11990
12076
  }
@@ -12005,7 +12091,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
12005
12091
 
12006
12092
  // src/services/distributed/renderChunk.ts
12007
12093
  import { randomBytes } from "node:crypto";
12008
- import { existsSync as existsSync24, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync12 } from "node:fs";
12094
+ import { existsSync as existsSync23, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync12 } from "node:fs";
12009
12095
  import { cpus } from "node:os";
12010
12096
  import { join as join31 } from "node:path";
12011
12097
  import {
@@ -12162,7 +12248,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12162
12248
  const planJsonPath = join31(planDir, "plan.json");
12163
12249
  const encoderJsonPath = join31(planDir, "meta", "encoder.json");
12164
12250
  const chunksJsonPath = join31(planDir, "meta", "chunks.json");
12165
- if (!existsSync24(planJsonPath)) {
12251
+ if (!existsSync23(planJsonPath)) {
12166
12252
  throw new RenderChunkValidationError(
12167
12253
  MISSING_PLAN_ARTIFACT,
12168
12254
  `[renderChunk] planDir is missing required artifact: ${planJsonPath}`
@@ -12178,7 +12264,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12178
12264
  const v2Manifest = v2Materialization?.manifest ?? null;
12179
12265
  const remoteSources = v2Materialization?.remoteSources ?? {};
12180
12266
  for (const required of [encoderJsonPath, chunksJsonPath]) {
12181
- if (!existsSync24(required)) {
12267
+ if (!existsSync23(required)) {
12182
12268
  throw new RenderChunkValidationError(
12183
12269
  MISSING_PLAN_ARTIFACT,
12184
12270
  `[renderChunk] planDir is missing required artifact: ${required}`
@@ -12189,7 +12275,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12189
12275
  const chunks = JSON.parse(readFileSync12(chunksJsonPath, "utf-8"));
12190
12276
  const videosJsonPath = join31(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
12191
12277
  let planVideos = null;
12192
- if (existsSync24(videosJsonPath)) {
12278
+ if (existsSync23(videosJsonPath)) {
12193
12279
  try {
12194
12280
  planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync12(videosJsonPath, "utf-8")));
12195
12281
  } catch (err) {
@@ -12220,7 +12306,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12220
12306
  const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
12221
12307
  const framesInChunk = range.endFrame - range.startFrame;
12222
12308
  const compiledDir = join31(planDir, "compiled");
12223
- if (!existsSync24(compiledDir)) {
12309
+ if (!existsSync23(compiledDir)) {
12224
12310
  throw new RenderChunkValidationError(
12225
12311
  MISSING_PLAN_ARTIFACT,
12226
12312
  `[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
@@ -12312,6 +12398,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12312
12398
  deferredVideos.filter((video) => remoteVideoIds.has(video.videoId))
12313
12399
  )
12314
12400
  });
12401
+ captureOptions.onStaticDedupActivity = () => noteStaticDedupActivity(job);
12315
12402
  const captureFrames = effectiveChunkFrames(framesInChunk, slice.captureCost);
12316
12403
  const chunkWorkerCount = resolveChunkCaptureWorkers(
12317
12404
  captureFrames,
@@ -12471,10 +12558,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12471
12558
  const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
12472
12559
  const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
12473
12560
  if (isPngSequence) {
12474
- if (!existsSync24(outputChunkPath)) mkdirSync14(outputChunkPath, { recursive: true });
12561
+ if (!existsSync23(outputChunkPath)) mkdirSync14(outputChunkPath, { recursive: true });
12475
12562
  } else {
12476
12563
  const outDir = join31(outputChunkPath, "..");
12477
- if (!existsSync24(outDir)) mkdirSync14(outDir, { recursive: true });
12564
+ if (!existsSync23(outDir)) mkdirSync14(outDir, { recursive: true });
12478
12565
  }
12479
12566
  const encodeInput = {
12480
12567
  job,
@@ -12581,7 +12668,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
12581
12668
  openAttempt,
12582
12669
  verifyFirstSession: forceScreenshot || !verifyInWorker ? void 0 : verifyFirstWorker
12583
12670
  }),
12584
- { stall: frameStallRule(job, framesInChunk) }
12671
+ { stall: frameStallRule(job, framesInChunk, void 0) }
12585
12672
  ).catch(async (captureError) => {
12586
12673
  await overlap.current?.abort();
12587
12674
  overlap.current = null;
@@ -12936,6 +13023,13 @@ function validateDistributedRenderConfig(config) {
12936
13023
  `distributed mode supports only ${ALLOWED_HDR_MODES.join(", ")}; got ${String(config.hdrMode)}`
12937
13024
  );
12938
13025
  }
13026
+ const chromaSubsampling = config.chromaSubsampling;
13027
+ if (chromaSubsampling !== void 0 && chromaSubsampling !== "420") {
13028
+ throw new InvalidConfigError(
13029
+ "config.chromaSubsampling",
13030
+ `distributed mode encodes 4:2:0 only; got ${String(chromaSubsampling)}`
13031
+ );
13032
+ }
12939
13033
  if (config.variables !== void 0) {
12940
13034
  validateVariablesPayload(config.variables);
12941
13035
  }
@@ -13033,16 +13127,18 @@ function validateIntDimension(field, value) {
13033
13127
 
13034
13128
  // src/services/distributed/projectHash.ts
13035
13129
  import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync9 } from "node:fs";
13036
- import { createHash as createHash8 } from "node:crypto";
13130
+ import { createHash as createHash9 } from "node:crypto";
13037
13131
  import { join as join33 } from "node:path";
13038
13132
  var SITE_ID_SCHEME = "site-v2\0";
13039
13133
  var READ_CHUNK_BYTES = 256 * 1024;
13134
+ var ENV_FILE = /^\.env([._-].*|rc)?$/i;
13135
+ var leftOut = (rel, name) => rel === "" && PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(name) || ENV_FILE.test(name);
13040
13136
  function listSiteFiles(projectDir) {
13041
13137
  const files = [];
13042
13138
  const ancestors = /* @__PURE__ */ new Set([realpathSync2(projectDir)]);
13043
13139
  function walk(dir, rel) {
13044
13140
  for (const name of readdirSync10(dir).sort()) {
13045
- if (rel === "" && PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(name)) continue;
13141
+ if (leftOut(rel, name)) continue;
13046
13142
  const full = join33(dir, name);
13047
13143
  const relPath = rel === "" ? name : `${rel}/${name}`;
13048
13144
  let stat;
@@ -13068,7 +13164,7 @@ function listSiteFiles(projectDir) {
13068
13164
  return files;
13069
13165
  }
13070
13166
  function hashProjectDir(projectDir, files = listSiteFiles(projectDir)) {
13071
- const hash = createHash8("sha256").update(SITE_ID_SCHEME);
13167
+ const hash = createHash9("sha256").update(SITE_ID_SCHEME);
13072
13168
  const chunk = Buffer.allocUnsafe(READ_CHUNK_BYTES);
13073
13169
  for (const rel of files) {
13074
13170
  hash.update(rel);