← Files Map Animation StudioARCHIVED FILE
evaluations/score.mjs
3.58 KB · Dec 1, 2026 · 00:16 UTC
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
export const cases = JSON.parse(readFileSync(new URL("./cases.json", import.meta.url), "utf8"));
// motion: whether scenes move and land their claims, or play as a slideshow of static holds.
const dimensions = ["framing", "readability", "continuity", "pacing", "motion"];
const text = (value) => typeof value === "string" && value.trim().length > 0;
/** Scores recorded evidence claims; does not independently see frames or execute a model. */
export function scoreRun(run) {
if (!run || typeof run !== "object" || Array.isArray(run)) {
throw new TypeError("Provide one captured run object.");
}
const fixture = cases.find((item) => item.id === run.case_id);
if (!fixture) {
throw new TypeError("Unknown case_id.");
}
for (const key of ["client", "model", "server_version", "reviewer"]) {
if (!text(run[key])) {
throw new TypeError(`Missing ${key}; do not infer a run's environment or reviewer.`);
}
}
if (!Number.isInteger(run.trial) || run.trial < 1) {
throw new TypeError("trial must be a positive integer.");
}
if (!Array.isArray(run.artifact_refs) || run.artifact_refs.length === 0 || !run.artifact_refs.every(text)) {
throw new TypeError("Record trace/frame/document artifact references; a summary alone is insufficient.");
}
const failed = fixture.checks.filter((key) => {
const check = run.checks?.[key];
return check?.passed !== true || !text(check.evidence);
});
const ratings = {};
if (fixture.visual_review) {
for (const key of dimensions) {
const rating = run.ratings?.[key];
if (!Number.isInteger(rating) || rating < 1 || rating > 5) {
failed.push(`rating:${key}:missing_or_invalid`);
} else {
ratings[key] = rating;
if (rating < 3) {
failed.push(`rating:${key}:below_threshold`);
}
}
}
}
const metrics = {};
for (const key of ["tool_calls", "preview_calls", "elapsed_ms", "estimated_cost_usd"]) {
const value = run.metrics?.[key];
if (value !== undefined && (typeof value !== "number" || !Number.isFinite(value) || value < 0)) {
throw new TypeError(`Invalid metric ${key}.`);
}
metrics[key] = value ?? null;
}
return {
case_id: fixture.id,
trial: run.trial,
client: run.client,
passed: failed.length === 0,
failed_checks: failed,
ratings,
metrics,
evidence_basis: "recorded_reviewer_claims_not_independent_render_verification",
note: "Tool-call count is telemetry, not a quality reward. Compare repeated runs and blinded artifacts.",
};
}
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
try {
if (process.argv.length !== 3) {
throw new TypeError("Usage: node evaluations/score.mjs recorded-run.json");
}
const input = readFileSync(process.argv[2], "utf8");
if (Buffer.byteLength(input) > 2 * 1024 * 1024) {
throw new RangeError("Run metadata exceeds 2 MiB; keep large artifacts in referenced files.");
}
const result = scoreRun(JSON.parse(input));
console.log(JSON.stringify(result, null, 4));
process.exitCode = result.passed ? 0 : 1;
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 2;
}
}
SHA-256: 2a01db3c313e73a337302e72fa72c924dfa2578cf044c87cfc02e863f176f1eb