mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(parsers): find helper programs by walking PATH in-process The trusted lookup ran `which` by name through the full PATH before applying the trusted-folder rule, so a relative or project-local PATH entry could supply the lookup program itself. Walk the trusted PATH folders in-process on every platform, as Windows already did, for findTrustedExecutable, findFfBinary and the doctor's unzip check. The walk keeps what `which` did for valid installs: first match in PATH order, regular files only, and a leading `~` in a PATH entry read as the home folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): start the media-use engine with the Windows working-directory lookup off mediaUseEngineEnv now sets NoDefaultCurrentDirectoryInExePath for the engine on Windows itself instead of relying on the CLI's own environment, and keeps a value the person set. When no PATH folder passes the trusted rule, PATH names a folder that is never created rather than an empty value, which a shell or execvp reads as the working directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(skills): helper scripts skip the Windows working-directory program lookup On Windows a program started by name is looked up in the working directory before PATH. The plugin launcher and the media-use, hyperframes and figma helper scripts run inside project folders and start ffmpeg, ffprobe, Python and other tools by name, either through the launcher or directly from a standalone skill install. Each skill now ships a small module that sets NoDefaultCurrentDirectoryInExePath for the process (keeping a value the person set), and every script that starts programs imports it first, so the helpers and every program they start skip the working directory. Tools installed on PATH resolve as before; macOS and Linux are unaffected. A test checks that each such script loads the module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): ship the Windows lookup guard with the CLI's media-use scripts The CLI build replaces the published media-use scripts/lib folder with packages/cli/src/media-use/lib. That folder had no windows-exe-search.mjs, so every bundled media-use script that imports it, including the engine behind `hyperframes media-use`, failed to load on every platform. The guard is now a generated copy in the CLI lib, next to the skill copies. A parity test checks that each scripts/lib module a published media-use script imports exists in the CLI lib. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(skills): load the win32 stub by file URL so the launcher test runs on Windows On Windows, `node --import D:\...` reads the drive letter as a URL scheme and fails before the launcher starts. The test now passes a file URL and reports the child's stderr when it exits non-zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(skills): resolve the Python helper's ffmpeg and drop relative PATH entries extract-audio-data.py ran ffmpeg by bare name, which Windows looks up in the working directory first. It now runs the absolute path that trusted_program.find_program finds in absolute PATH folders outside the working directory. A miss raises the same FileNotFoundError as before. On macOS and Linux the shared guard now drops relative and empty PATH entries, which point into the project folder, and leaves absolute ones in order. If none is absolute, PATH is unset rather than left empty. The guard census now also requires every skill Python script that imports subprocess to resolve programs through trusted_program. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(skills): satisfy the Python UTF-8 and ffprobe argv sweeps trusted_program.py carries the same UTF-8 stdio pin as every skill Python script. The guard test's planted-program probe uses a literal-only argv, which the ffprobe argv contract test reads as a capability check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
5.0 KiB
JavaScript
155 lines
5.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Objective fidelity gate for figma-motion imports (skill step 2b).
|
|
*
|
|
* Compares the HyperFrames render against Figma's own `export_video` output
|
|
* using MOTION-ENERGY deltas: for each sample window [t, t+interval], the
|
|
* frame difference ref(t+i)-ref(t) is compared (PSNR) against
|
|
* render(t+i)-render(t). Static import divergence (fonts, rasterized edges,
|
|
* subpixel geometry — the hybrid-fidelity ceiling) cancels out of both
|
|
* deltas, so the score isolates choreography: trajectories, timing, easing.
|
|
*
|
|
* Calibration (SDS "Unlocked" card, 2026-07): a faithful translation scored
|
|
* min 20.3dB / mean 27.7dB; a diverging one (invented retract keyframes,
|
|
* wrong durations) scored min 5.0dB / mean 23.1dB. Default threshold 15dB
|
|
* sits between with margin on both sides.
|
|
*
|
|
* node verify-motion.mjs --reference figma-export.mp4 --render out.mp4 \
|
|
* [--crop WxH+X+Y] [--interval 0.2] [--min-motion-psnr 15]
|
|
*
|
|
* --crop selects the card region inside the (usually larger) composition
|
|
* frame. Measure it from the render (the card's left/top edge + scaled
|
|
* size), don't guess: a wrong crop reads as motion divergence.
|
|
*/
|
|
import "./lib/windows-exe-search.mjs";
|
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
function arg(name, fallback) {
|
|
const i = process.argv.indexOf(`--${name}`);
|
|
return i > -1 ? process.argv[i + 1] : fallback;
|
|
}
|
|
const reference = arg("reference");
|
|
const render = arg("render");
|
|
if (!reference || !render) {
|
|
console.error(
|
|
"usage: verify-motion.mjs --reference ref.mp4 --render out.mp4 [--crop WxH+X+Y] [--interval 0.2] [--min-motion-psnr 15]",
|
|
);
|
|
process.exit(2);
|
|
}
|
|
const crop = arg("crop", null);
|
|
const interval = Number(arg("interval", "0.2"));
|
|
const minMotion = Number(arg("min-motion-psnr", "15"));
|
|
|
|
const ffprobe = (file) =>
|
|
Number(
|
|
execFileSync("ffprobe", [
|
|
"-v",
|
|
"error",
|
|
"-show_entries",
|
|
"format=duration",
|
|
"-of",
|
|
"csv=p=0",
|
|
"--",
|
|
file,
|
|
])
|
|
.toString()
|
|
.trim(),
|
|
);
|
|
const refDur = ffprobe(reference);
|
|
const renderDur = ffprobe(render);
|
|
const end = Math.min(refDur, renderDur) - interval - 0.01;
|
|
|
|
const dims = execFileSync("ffprobe", [
|
|
"-v",
|
|
"error",
|
|
"-select_streams",
|
|
"v",
|
|
"-show_entries",
|
|
"stream=width,height",
|
|
"-of",
|
|
"csv=p=0",
|
|
"--",
|
|
reference,
|
|
])
|
|
.toString()
|
|
.trim()
|
|
.split(",")
|
|
.map(Number);
|
|
const [rw, rh] = dims;
|
|
|
|
let cropFilter = "";
|
|
if (crop) {
|
|
const m = crop.match(/^(\d+)x(\d+)\+(\d+)\+(\d+)$/);
|
|
if (!m) {
|
|
console.error("bad --crop, expected WxH+X+Y");
|
|
process.exit(2);
|
|
}
|
|
cropFilter = `crop=${m[1]}:${m[2]}:${m[3]}:${m[4]},`;
|
|
}
|
|
|
|
const dir = mkdtempSync(join(tmpdir(), "verify-motion-"));
|
|
const frame = (src, t, vf, dst) => {
|
|
const args = ["-y", "-v", "error", "-ss", String(t), "-i", src, "-frames:v", "1"];
|
|
if (vf) args.push("-vf", vf);
|
|
execFileSync("ffmpeg", args.concat(dst));
|
|
};
|
|
const diff = (a, b, dst) =>
|
|
execFileSync("ffmpeg", [
|
|
"-y",
|
|
"-v",
|
|
"error",
|
|
"-i",
|
|
a,
|
|
"-i",
|
|
b,
|
|
"-filter_complex",
|
|
"blend=all_mode=difference",
|
|
dst,
|
|
]);
|
|
const psnr = (a, b) => {
|
|
// spawnSync with array args (no shell): psnr stats land on stderr
|
|
const r = spawnSync("ffmpeg", ["-i", a, "-i", b, "-lavfi", "psnr", "-f", "null", "-"], {
|
|
encoding: "utf8",
|
|
});
|
|
const m = (r.stderr || "").match(/average:([\d.]+|inf)/);
|
|
return m ? (m[1] === "inf" ? 99 : Number(m[1])) : NaN;
|
|
};
|
|
|
|
const renderVf = `${cropFilter}scale=${rw}:${rh}`;
|
|
const results = [];
|
|
for (let t = 0; t <= end; t = Math.round((t + interval) * 1000) / 1000) {
|
|
const t1 = Math.round((t + interval) * 1000) / 1000;
|
|
frame(reference, t, null, join(dir, "ra.png"));
|
|
frame(reference, t1, null, join(dir, "rb.png"));
|
|
frame(render, t, renderVf, join(dir, "oa.png"));
|
|
frame(render, t1, renderVf, join(dir, "ob.png"));
|
|
diff(join(dir, "ra.png"), join(dir, "rb.png"), join(dir, "rd.png"));
|
|
diff(join(dir, "oa.png"), join(dir, "ob.png"), join(dir, "od.png"));
|
|
results.push({
|
|
t,
|
|
motion: psnr(join(dir, "rd.png"), join(dir, "od.png")),
|
|
abs: psnr(join(dir, "rb.png"), join(dir, "ob.png")),
|
|
});
|
|
}
|
|
rmSync(dir, { recursive: true, force: true });
|
|
|
|
const min = Math.min(...results.map((r) => r.motion));
|
|
const mean = results.reduce((s, r) => s + r.motion, 0) / results.length;
|
|
for (const r of results)
|
|
console.log(
|
|
`window ${r.t.toFixed(2)}s→${(r.t + interval).toFixed(2)}s motion-psnr=${r.motion.toFixed(2)}dB (abs=${r.abs.toFixed(1)}dB)${r.motion < minMotion ? " <-- BELOW THRESHOLD" : ""}`,
|
|
);
|
|
console.log(
|
|
`\nwindows=${results.length} min-motion=${min.toFixed(2)}dB mean-motion=${mean.toFixed(2)}dB threshold=${minMotion}dB`,
|
|
);
|
|
if (min < minMotion) {
|
|
console.log(
|
|
"VERDICT: FAIL — choreography diverges from the Figma export (check timings, invented keyframes, durations)",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
console.log("VERDICT: PASS — motion matches the Figma export within the static-fidelity ceiling");
|