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