mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 12:54:29 +00:00
* feat(media-use): color grading — grade/lut resolve, smart-grade, grade-compare CLI Add color grading to media-use as first-class resolve types plus a faithful comparison command. All local, offline, deterministic — no model, no GPU. - resolve -t grade / -t lut: produce a data-color-grading block (or a frozen .cube). Look cascade: core preset (no file) -> bundled .cube library -> parametric buildCube. Emitted .cube is Rec.709 and validated against core's colorLuts constraints (LUT_3D_SIZE <= 64) before it is frozen. - smart grade (grade --for <media>): ffmpeg signalstats -> adjust suggestion (exposure / contrast / white balance), surfaced with the measured evidence on stderr as a starting point; never auto-applied. - hyperframes grade-compare: renders N candidate grades onto a reference frame through the real runtime shader into one labeled comparison PNG, so an agent picks a look without opening Studio. Prepends an "original" baseline cell by default (--no-baseline to omit). Shares the headless-capture pipeline with snapshot via capture/captureCompositionFrame. - media-use SKILL: proactive "media opportunity pass" guidance (grounded signal -> offer, ask once, surface don't mutate). Verified: media-use 116/116, grade-compare 7/7, snapshot 9/9, lint + format clean, full build green, comparison renders end to end. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * test(cli): narrow grade-compare baseline assertion off unknown-typed grading Assert the whole cell via toEqual instead of reaching into .grading.preset / .grading.lut on the unknown-typed field, keeping the test typecheck-clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * feat(media-use): agent-authored LUTs via --params + validate --from cube; never-read-.cube guardrail - resolve -t lut / -t grade --params '<json>': build a parametric .cube from explicit params (bypassing the intent cascade), validate, and freeze in one step. --intent becomes the optional description. Lets an agent commit a look it computed itself. - --from <file.cube> now validates the ingested LUT for lut/grade types and rejects an invalid/oversized cube (no partial write) — the escape hatch for a LUT the agent generated with its own code. - SKILL.md: hard rule to never read a .cube body into context (~size^3 lines, zero legible signal) — inspect via grade-compare (see it) or cube-validate (ok/size), read the manifest description for meaning; plus both authoring paths and the parametric-vs-film-stock ceiling note. Verified: media-use 116/116, lint + format clean; smokes — --params builds a valid frozen cube, grade --params returns a lut block, bad JSON and an oversized --from cube are both rejected with no stray file. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * fix(cli): grade-compare validates referenced LUTs, warns on no-op cells, caps candidates Bug-bash follow-ups — grade-compare silently accepted bad input: - Validate LUT *content*, not just existence: each referenced .cube is parsed with core's parseCubeLut (now exported from @hyperframes/core) and rejected with a per-cell error ("LUT for \"<label>\" is not a valid .cube: ..."). A file that exists but isn't a valid cube no longer renders a silent no-op cell. - Warn on inactive cells: a grading that normalizes to inactive (e.g. a malformed {lut:12345}) emits a stderr warning naming the cell; the auto-prepended "original" baseline is intentionally inactive and stays silent. stdout remains valid JSON. - Cap candidates at 16 (excluding baseline): over-cap input renders the first N and reports {truncated:true, total:M} on stdout + a stderr note — no silent drop, no unbounded giant sheet. Verified: grade-compare 10/10; non-cube LUT → clear error; {lut:12345} → warning + ok; 20 cells → cells=17 truncated total=20; valid runs unchanged. Lint/format clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * feat(cli): general `hyperframes compare` visual-variant primitive Generalize grade-compare's "render N variants → one labeled sheet → the agent looks and picks" loop into a standalone command that works on ANY variation (font, layout, motion, grade, whole compositions) — the tool never needs to know what differs. - `hyperframes compare <path...> [--at <sec>] [--labels a,b,c] [--out] [--cols] [--json]`: renders each agent-authored composition variant through the real runtime (captureCompositionFrame) and stitches one labeled comparison sheet + JSON ({ok, sheet, rendered, variants, truncated?/total?}). 2+ paths required; caps at 16 with loud truncation. It presents, it does not judge — choosing is the caller's job. - Factored the shared "render a labeled set → contact sheet" path so compare, grade-compare, and snapshot all sit on it (no duplication). grade-compare is now the first color-specific specialization of this primitive. - New pathArgs util + contactSheet test; hyperframes-cli SKILL documents compare as the agent's "see your own renders and choose" primitive. Verified: 26/26 across compare + grade-compare + snapshot + contactSheet (no regressions); compare renders 3 variants into one visibly-distinct labeled sheet; 2+-path error path clean; lint/format clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * fix(ci): green the skills CI — skip ffmpeg tests when absent, oxfmt markdown The "Test: skills" CI job runs bare `node --test` with no ffmpeg on PATH (by design — skills tests are meant to be node-builtin-only). The grade-analyzer + smart-grade tests shell to ffmpeg and were failing there with ENOENT. Guard them to skip when ffmpeg isn't on PATH; they still run locally / where it is. Also oxfmt README.md + hyperframes/media-use SKILL.md (the whole-repo `oxfmt --check .` Format job caught markdown left unformatted by the rebase conflict resolution). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * fix(ci): skip core-conformance test when tsx is unavailable The "Test: skills" CI job installs no deps, so the normalizeHfColorGrading conformance test (which imports core's TS via `node --import tsx`) failed there. Guard it to skip when tsx can't resolve; runs locally / in the deps-installed Test job. Completes the skills-CI greening (the ffmpeg guards handled the rest). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * fix(cli): escape grade-compare src double-quotes (CodeQL XSS) + Windows-safe compare test - grade-compare built `<img src="...">` (double-quoted) with the single-quote escaper, leaving `"` unescaped — a `"` in the frame path could break out (CodeQL: incomplete HTML attribute sanitization). Use escapeXml for src. - compare label test hard-coded POSIX paths that can't match on Windows; assert the derived labels (the subject); path resolution is covered elsewhere. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * refactor(media-use): generate LUT library from params (drop committed .cube files) The 3 bundled .cube files were 733 lines each (2,199 total) and were themselves buildCube output — pure repo bloat. Replace with compact per-look params in luts/index.json, generated on resolve; add an optional `url` for future scanned LUTs to be CDN-hosted + downloaded on demand (freezeUrl) instead of committed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * feat(media-use): serve library LUTs from CDN on-demand (static.heygen.ai/luts), params fallback Looks now carry a CDN `url` (hosted at s3://heygen-public/luts → static.heygen.ai/luts/<id>.cube); resolve downloads + validates + freezes on demand, like bgm/image. `params` stays as the deterministic offline fallback (--local-only, or if the download fails), so resolution is never blocked on the network. Provider prefers url, falls back to params. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv * fix(media-use): address #2041 review — atomic LUT writes, compare telemetry, follow-ups - Atomic .cube writes: library provider (url + params) and the parametric generator now write to a .tmp path, validate, then rename, so a crash can never orphan an invalid .cube at the final path (was validate-after-write). - track("media_use_resolve") now emits provenance.via (url/params-fallback/params). - grade-compare + compare: --timeout flag (was hardcoded 5000) and a media_use_compare event (cells, truncated, total, render_ready_timed_out); openSettledCompositionPage now surfaces the render-ready timeout. - compare staging skips node_modules/.git; --for gets an upfront existence check. - Rec.709 luma comment; HYPERFRAMES_ANALYZE_TIMEOUT_MS override; measured note uses basename; LUT s3 hosting moved from index.json into luts/README.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5k87mPZ4d6yiFwcWSb8Vv --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
199 lines
5.9 KiB
JavaScript
199 lines
5.9 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Standalone mirror of packages/core/src/colorLuts.ts. media-use cannot import
|
|
// the TypeScript source at runtime, so cube-validate.test.mjs mirrors core
|
|
// parser cases to catch drift in accepted .cube files before freezing them.
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve as resolvePath } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
export const DEFAULT_MAX_CUBE_LUT_SIZE = 64;
|
|
|
|
const DEFAULT_DOMAIN_MIN = [0, 0, 0];
|
|
const DEFAULT_DOMAIN_MAX = [1, 1, 1];
|
|
|
|
class CubeValidateError extends Error {
|
|
constructor(message, lineNumber = null) {
|
|
super(lineNumber == null ? message : `${message} at line ${lineNumber}`);
|
|
this.name = "CubeValidateError";
|
|
this.lineNumber = lineNumber;
|
|
}
|
|
}
|
|
|
|
function stripComment(line) {
|
|
let inQuote = false;
|
|
for (let i = 0; i < line.length; i++) {
|
|
const char = line[i];
|
|
if (char === '"') inQuote = !inQuote;
|
|
if (char === "#" && !inQuote) return line.slice(0, i);
|
|
}
|
|
return line;
|
|
}
|
|
|
|
function parseFiniteNumber(value, lineNumber) {
|
|
const parsed = Number(value);
|
|
if (!Number.isFinite(parsed)) {
|
|
throw new CubeValidateError(`Invalid number "${value}"`, lineNumber);
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
function parseVec3(parts, keyword, lineNumber) {
|
|
if (parts.length !== 3) {
|
|
throw new CubeValidateError(`${keyword} expects three numbers`, lineNumber);
|
|
}
|
|
return [
|
|
parseFiniteNumber(parts[0], lineNumber),
|
|
parseFiniteNumber(parts[1], lineNumber),
|
|
parseFiniteNumber(parts[2], lineNumber),
|
|
];
|
|
}
|
|
|
|
function parseSize(value, keyword, lineNumber) {
|
|
if (!value) throw new CubeValidateError(`${keyword} expects a size`, lineNumber);
|
|
const parsed = Number(value);
|
|
if (!Number.isInteger(parsed) || parsed < 2) {
|
|
throw new CubeValidateError(`${keyword} must be an integer greater than 1`, lineNumber);
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
function validateDomain(domainMin, domainMax) {
|
|
if (
|
|
domainMax[0] <= domainMin[0] ||
|
|
domainMax[1] <= domainMin[1] ||
|
|
domainMax[2] <= domainMin[2]
|
|
) {
|
|
throw new CubeValidateError("DOMAIN_MAX values must be greater than DOMAIN_MIN values");
|
|
}
|
|
}
|
|
|
|
function isNumericDataLine(token) {
|
|
return /^[+-]?(?:\d|\.\d)/.test(token);
|
|
}
|
|
|
|
function parseCube(input, options = {}) {
|
|
const maxSize = options.maxSize ?? DEFAULT_MAX_CUBE_LUT_SIZE;
|
|
let domainMin = DEFAULT_DOMAIN_MIN;
|
|
let domainMax = DEFAULT_DOMAIN_MAX;
|
|
let lut1dSize = null;
|
|
let lut3dSize = null;
|
|
let rows = 0;
|
|
|
|
const lines = String(input)
|
|
.replace(/^\uFEFF/, "")
|
|
.split(/\r?\n/);
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const lineNumber = i + 1;
|
|
const line = stripComment(lines[i] ?? "").trim();
|
|
if (!line) continue;
|
|
const parts = line.split(/\s+/);
|
|
const keyword = (parts[0] ?? "").toUpperCase();
|
|
const rest = parts.slice(1);
|
|
|
|
if (keyword === "TITLE") continue;
|
|
if (keyword === "DOMAIN_MIN") {
|
|
domainMin = parseVec3(rest, keyword, lineNumber);
|
|
continue;
|
|
}
|
|
if (keyword === "DOMAIN_MAX") {
|
|
domainMax = parseVec3(rest, keyword, lineNumber);
|
|
continue;
|
|
}
|
|
if (keyword === "LUT_3D_INPUT_RANGE") {
|
|
if (rest.length !== 2) {
|
|
throw new CubeValidateError(`${keyword} expects two numbers`, lineNumber);
|
|
}
|
|
const min = parseFiniteNumber(rest[0], lineNumber);
|
|
const max = parseFiniteNumber(rest[1], lineNumber);
|
|
if (max <= min) {
|
|
throw new CubeValidateError("LUT_3D_INPUT_RANGE max must exceed min", lineNumber);
|
|
}
|
|
domainMin = [min, min, min];
|
|
domainMax = [max, max, max];
|
|
continue;
|
|
}
|
|
if (keyword === "LUT_1D_SIZE") {
|
|
lut1dSize = parseSize(rest[0], keyword, lineNumber);
|
|
continue;
|
|
}
|
|
if (keyword === "LUT_3D_SIZE") {
|
|
lut3dSize = parseSize(rest[0], keyword, lineNumber);
|
|
if (lut3dSize > maxSize) {
|
|
throw new CubeValidateError(`LUT_3D_SIZE ${lut3dSize} exceeds max ${maxSize}`, lineNumber);
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (!isNumericDataLine(keyword)) {
|
|
if (keyword.startsWith("LUT_")) {
|
|
throw new CubeValidateError(`Unsupported cube keyword ${keyword}`, lineNumber);
|
|
}
|
|
continue;
|
|
}
|
|
if (!lut3dSize) {
|
|
if (lut1dSize) {
|
|
throw new CubeValidateError("1D cube LUTs are not supported yet", lineNumber);
|
|
}
|
|
throw new CubeValidateError("LUT data appears before LUT_3D_SIZE", lineNumber);
|
|
}
|
|
if (parts.length !== 3) {
|
|
throw new CubeValidateError("LUT data rows must contain three numbers", lineNumber);
|
|
}
|
|
parseFiniteNumber(parts[0], lineNumber);
|
|
parseFiniteNumber(parts[1], lineNumber);
|
|
parseFiniteNumber(parts[2], lineNumber);
|
|
rows++;
|
|
}
|
|
|
|
if (lut1dSize && lut3dSize) {
|
|
throw new CubeValidateError("Mixed 1D and 3D cube LUTs are not supported yet");
|
|
}
|
|
if (!lut3dSize) {
|
|
if (lut1dSize) throw new CubeValidateError("1D cube LUTs are not supported yet");
|
|
throw new CubeValidateError("Missing LUT_3D_SIZE");
|
|
}
|
|
validateDomain(domainMin, domainMax);
|
|
|
|
const expectedRows = lut3dSize * lut3dSize * lut3dSize;
|
|
if (rows !== expectedRows) {
|
|
throw new CubeValidateError(
|
|
`Expected ${expectedRows} LUT rows for size ${lut3dSize}, found ${rows}`,
|
|
);
|
|
}
|
|
|
|
return { size: lut3dSize };
|
|
}
|
|
|
|
export function validateCube(input, options = {}) {
|
|
try {
|
|
const parsed = parseCube(input, options);
|
|
return { ok: true, size: parsed.size };
|
|
} catch (err) {
|
|
return { ok: false, error: err.message };
|
|
}
|
|
}
|
|
|
|
export function validateCubeFile(filePath, options = {}) {
|
|
return validateCube(readFileSync(filePath, "utf8"), options);
|
|
}
|
|
|
|
function main(argv) {
|
|
const file = argv[2];
|
|
if (!file) {
|
|
console.error("usage: cube-validate.mjs <file.cube>");
|
|
process.exit(2);
|
|
}
|
|
const result = validateCubeFile(file);
|
|
if (!result.ok) {
|
|
console.error(`error: ${result.error}`);
|
|
process.exit(1);
|
|
}
|
|
console.log(`ok: LUT_3D_SIZE ${result.size}`);
|
|
}
|
|
|
|
if (process.argv[1] && resolvePath(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
main(process.argv);
|
|
}
|