// `hyperframes auto`'s offline steps on their own, for a sandbox that runs them as one bundled file without the // whole CLI: `node auto-steps.mjs [flags]`. Each prints the same JSON object as `hyperframes auto `. // Snapshots and transcripts still come from a HyperFrames CLI: HF_AUTO_CLI names it, else `hyperframes` on PATH, so pin // that CLI beside the bundle. `read` downloads hand and pose tracking into the cache on first use: ship it offline. import { parseArgs } from "node:util"; import { useCli } from "./auto/cutouts.js"; import { failureOf, type StepName, STEPS, StepUsageError, stepOutput, } from "./auto/stepCommands.js"; import { terminalText } from "./media-use/lib/terminal-text.mjs"; const OPTIONS = { work: { type: "string" }, project: { type: "string" }, library: { type: "string" }, out: { type: "string" }, style: { type: "string" }, note: { type: "string" }, "run-id": { type: "string" }, plan: { type: "string" }, fit: { type: "string" }, part: { type: "string" }, again: { type: "string" }, last: { type: "boolean" }, id: { type: "string" }, file: { type: "string" }, json: { type: "boolean" }, } as const; const isStep = (name: string | undefined): name is StepName => STEPS.some((step) => step === name); function flagsOf(args: string[]) { try { return parseArgs({ args, options: OPTIONS, allowPositionals: true }); } catch (err) { throw new StepUsageError(messageOf(err)); } } const messageOf = (err: unknown) => (err instanceof Error ? err.message : String(err)); function useNamedCli(named: string | undefined): void { if (named && /\.[cm]?js$/.test(named)) useCli(process.execPath, [named]); else useCli(named || "hyperframes"); } async function main(argv: string[]): Promise { const [name, ...rest] = argv; try { if (!isStep(name)) throw new StepUsageError(`the step is one of ${STEPS.join(", ")}`); const { values, positionals } = flagsOf(rest); useNamedCli(process.env.HF_AUTO_CLI); const status = (message: string) => console.error(terminalText(message)); const output = await stepOutput(name, { ...values, clip: positionals[0] }, status); console.log(JSON.stringify({ ok: true, ...output })); return 0; } catch (err) { console.log(JSON.stringify(failureOf(err, messageOf(err)))); return 1; } } const code = await main(process.argv.slice(2)); process.stdout.once("finish", () => process.exit(code)).end();