Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

perf(reference-video-tools): build the mocked Run instead of drawing it

rponeawa91e5ad4e37c4
diff --git a/packages/reference-video-tools/package.json b/packages/reference-video-tools/package.json
index 1563550a..aece8a60 100644
--- a/packages/reference-video-tools/package.json
+++ b/packages/reference-video-tools/package.json
@@ -26,11 +26,9 @@
"@hypit/package-loader-node": "workspace:*",
"@hypit/program-space": "workspace:*",
"@hypit/protocol": "workspace:*",
- "@hypit/render-hyperframes": "workspace:*",
"@hypit/run-markup": "workspace:*",
"@hypit/runtime": "workspace:*",
"@hypit/provider-media-local": "workspace:*",
- "@hypit/provider-hyperframes-local": "workspace:*",
"@hypit/provider-hypihub": "workspace:*",
"@hypit/provider-vertex": "workspace:*",
"@hypit/script": "workspace:*",
diff --git a/packages/reference-video-tools/src/authoring.ts b/packages/reference-video-tools/src/authoring.ts
index 2b7658fd..c1a099b3 100644
--- a/packages/reference-video-tools/src/authoring.ts
+++ b/packages/reference-video-tools/src/authoring.ts
@@ -21,11 +21,8 @@ import { preview } from "@hypit/studio/src/programme.js";
import { loadStudioRun } from "@hypit/studio/src/run.js";
import { inspectStudioRun } from "@hypit/studio/src/studio-preflight.js";
import { realizePreviewMock } from "@hypit/preview-mock";
-import { EndpointRegistry, MemoryArtifactStore } from "@hypit/driver-node";
-import { mediaTypes } from "@hypit/media";
+import { EndpointRegistry } from "@hypit/driver-node";
import { createLocalMediaProvider } from "@hypit/provider-media-local";
-import { createLocalHyperframesProvider } from "@hypit/provider-hyperframes-local";
-import { renderHyperframesCapabilities } from "@hypit/render-hyperframes";
import { assert, ensureDir } from "./media.js";
import type { TranscriptFile } from "./types.js";
@@ -484,8 +481,8 @@ async function once(key: string, work: () => Promise<void>): Promise<void> {
export type RenderElementInput = {
/**
* A round of renders, run together. Each entry names its own element, stretch and output and
- * inherits `run` and `reference_id`. The full preview is realized and drawn once; entries then cut
- * their own windows from that shared frame cache in order.
+ * inherits `run` and `reference_id`. The preview is realized and built once; entries then cut
+ * their own windows out of that one film in order.
*/
readonly renders?: readonly RenderElementInput[];
/** Required for one render; a round carries them per entry and inherits `run` from the outer input. */
@@ -501,6 +498,11 @@ export type RenderElementInput = {
* preview timing, which is always the Source's own `estimate:Speech` policy.
*/
readonly reference_id?: string;
+ /**
+ * The Runtime Profile the preview Build runs under. Defaults to the project's own
+ * `hypit.runtime.json`, beside the Run.
+ */
+ readonly runtime?: string;
/** Optional workspace root used by package-owned preview Sources. */
readonly package_root?: string;
};
@@ -753,10 +755,11 @@ export async function renderElement(input: RenderElementInput): Promise<Record<s
const tokensArgument = input.tokens === undefined ? undefined : tokenWindow(input.tokens, "tokens");
const realized = await realizedOnce({
run,
+ ...(input.runtime === undefined ? {} : { runtime: input.runtime }),
...(input.package_root === undefined ? {} : { package_root: input.package_root }),
});
const {
- runPath, built, previewMock, programFrames, frameOfToken, selections, segmentTokenCounts,
+ runPath, runRoot, built, previewMock, programFrames, frameOfToken, selections, segmentTokenCounts,
} = realized;
const renderKey = createHash("sha256").update(`${resolve(runPath)}\u0000${input.reference_id ?? ""}`).digest("hex").slice(0, 12);
const compareRoot = previewMock.root;
@@ -806,49 +809,35 @@ export async function renderElement(input: RenderElementInput): Promise<Record<s
const clip = /\.(mp4|mov|webm)$/iu.test(outPath);
const program = join(compareRoot, "program.mp4");
- // The whole program, drawn once per Run and clock, however many windows are asked for.
+ // The mocked program, built once per Run and clock, however many windows are asked for.
//
// The picture does not depend on the element or the window — every window is cut out of this one
- // file — so a round of eight looks over one Source is one render and eight ffmpeg cuts. Rendering
- // per entry would draw the same program eight times.
+ // film — so a round of eight looks over one Source is one Build and eight ffmpeg cuts.
//
- // Drawn through the Provider a Build renders with, rather than by driving the HyperFrames CLI from
- // here. The staging layout, the browser flags and the output check belong to the render path, and a
- // preview that spawns its own copy of them is a second renderer to keep in step with the first: it
- // was already staging the document by a different file naming and drawing with flags the delivery
- // never takes. What preview still owns is the Run it draws — the mocked, estimate-timed one — not
- // how that Run is drawn.
+ // It is an ordinary Build of an ordinary Run. `preview.svrun` names a target and satisfies every
+ // generation with a mock file, so the only Needs it reaches are the local ones a Runtime Profile
+ // already configures, and what draws it is the render path itself rather than a preview's copy of
+ // it. The Source is the mocked one; the flow is the delivery's.
await once(`draw:${renderKey}`, async () => {
- const document = compileHyperframesDocument(built.composition, built.space as ProgramSpace);
- // The endpoint reads what the document names out of a store, so the served bytes are put in one.
- // They are the same bytes under the same digests, which is what makes the lookup find them.
- const artifacts = new MemoryArtifactStore();
- for (const file of built.served.values()) await artifacts.put(file.bytes, file.mediaType);
- const endpoints = new EndpointRegistry();
- // `auto` leaves the GPU decision to the runtime, which is what this render had before it went
- // through the Provider. The delivery default asks for hardware, and a preview is drawn on
- // whatever machine is authoring rather than on a render host chosen to have one.
- await createLocalHyperframesProvider({ browserGpu: "auto" }).install(endpoints);
- const need = {
- id: "preview-visual",
- capability: renderHyperframesCapabilities.renderVisual,
- returns: mediaTypes.renderedVisual,
- constraints: { document } as never,
- result: "preview-visual",
+ const hypit = join(repositoryRoot(), "bin", "hypit.mjs");
+ const profile = input.runtime === undefined ? join(runRoot, "hypit.runtime.json") : resolve(cwd, input.runtime);
+ assert(existsSync(profile), `the preview Build needs a Runtime Profile; ${profile} does not exist`);
+ const hypitRun = (argv: readonly string[]): string => {
+ const done = spawnSync(process.execPath, [hypit, ...argv, "--runtime", profile, "--json"],
+ { cwd: runRoot, encoding: "utf8", windowsHide: true, timeout: 3_600_000 });
+ assert(done.status === 0, `hypit ${argv[0]} refused: ${(done.stdout || done.stderr || "").trim().slice(-2000)}`);
+ return done.stdout ?? "";
};
- const registration = endpoints.resolve(need);
- assert(registration.status === "resolved" && registration.registration.kind === "immediate",
- "the local HyperFrames render endpoint did not resolve");
- const drawn = await registration.registration.handler({
- command: { kind: "fulfill-need", id: need.id, need }, need, artifacts, credentials: {},
- });
- assert(drawn.value.kind === "inline", "the HyperFrames endpoint returned no inline RenderedVisual");
- const rendered = drawn.value.value as { readonly artifact?: { readonly digest?: `sha256:${string}` } };
- const digest = rendered.artifact?.digest;
- assert(digest !== undefined, "the HyperFrames endpoint returned a RenderedVisual with no Artifact");
- const bytes = await artifacts.get(digest);
- assert(bytes !== undefined, `the HyperFrames endpoint kept no bytes for ${digest}`);
- await writeFile(program, bytes);
+ // The Author Source sits above the derived Run, so the workspace is the project rather than the
+ // preview directory the Run was written into.
+ const built = JSON.parse(hypitRun(["build", previewMock.previewRun, "--workspace", runRoot, "--follow"])) as {
+ readonly build?: string;
+ readonly goals?: readonly { readonly value?: { readonly digest?: string; readonly mediaType?: string } }[];
+ };
+ const goal = built.goals?.find((item) => item.value?.mediaType?.startsWith("video/"));
+ assert(built.build !== undefined && goal?.value?.digest !== undefined,
+ `the preview Build produced no video: ${JSON.stringify(built).slice(0, 2000)}`);
+ hypitRun(["get", built.build, "--artifact", goal.value.digest, "--to", program]);
});
const first = Math.min(window.startFrame, programFrames - 1);
diff --git a/packages/reference-video-tools/src/cli.ts b/packages/reference-video-tools/src/cli.ts
index 04570c22..39c33468 100644
--- a/packages/reference-video-tools/src/cli.ts
+++ b/packages/reference-video-tools/src/cli.ts
@@ -52,8 +52,8 @@ function usage(): string {
" hypit-reference-video-tools review_element --run <build.svrun> --element <id> --segment <id>|--selection <id>|--tokens <from:to> --video <path>|--image <path> --intent-file <path> [--question <scope>]",
" hypit-reference-video-tools review_element --run <build.svrun> --batch <reviews.json>",
" hypit-reference-video-tools record_review --run <build.svrun> --review-id <id> --text <text>|--text-file <path>",
- " hypit-reference-video-tools render_element <build.svrun> --element <id> --out <path.png|path.mp4> [--segment <id>] [--selection <id>] [--tokens <from:to>] [--reference-id <id>]",
- " hypit-reference-video-tools render_element <build.svrun> --batch <renders.json> [--reference-id <id>]",
+ " hypit-reference-video-tools render_element <build.svrun> --element <id> --out <path.png|path.mp4> [--segment <id>] [--selection <id>] [--tokens <from:to>] [--reference-id <id>] [--runtime <hypit.runtime.json>]",
+ " hypit-reference-video-tools render_element <build.svrun> --batch <renders.json> [--reference-id <id>] [--runtime <hypit.runtime.json>]",
" hypit-reference-video-tools render_previews <package-dir> [...]",
" hypit-reference-video-tools preview_check <build.svrun> [<hypit.runtime.json>]",
" hypit-reference-video-tools layout_check --run <build.svrun> [--runtime <hypit.runtime.json>]",
@@ -625,6 +625,7 @@ async function main(): Promise<void> {
result = await tools.render_element({
...(operands[0] === undefined ? {} : { run: operands[0] }),
...(one(flags, "reference-id") === undefined ? {} : { reference_id: one(flags, "reference-id") }),
+ ...(one(flags, "runtime") === undefined ? {} : { runtime: one(flags, "runtime") }),
renders: list,
} as RenderElementInput);
report(`${JSON.stringify(result, null, 2)}\n`);
@@ -640,6 +641,7 @@ async function main(): Promise<void> {
...(one(flags, "selection") === undefined ? {} : { selection: one(flags, "selection") }),
...(tokenRange(one(flags, "tokens")) === undefined ? {} : { tokens: tokenRange(one(flags, "tokens")) }),
...(one(flags, "reference-id") === undefined ? {} : { reference_id: one(flags, "reference-id") }),
+ ...(one(flags, "runtime") === undefined ? {} : { runtime: one(flags, "runtime") }),
};
result = await tools.render_element(input as RenderElementInput);
} else if (command === "render_previews") {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 13530cf8..c2e63cbc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2449,9 +2449,6 @@ importers:
'@hypit/protocol':
specifier: workspace:*
version: link:../protocol
- '@hypit/provider-hyperframes-local':
- specifier: workspace:*
- version: link:../provider-hyperframes-local
'@hypit/provider-hypihub':
specifier: workspace:*
version: link:../provider-hypihub
@@ -2461,9 +2458,6 @@ importers:
'@hypit/provider-vertex':
specifier: workspace:*
version: link:../provider-vertex
- '@hypit/render-hyperframes':
- specifier: workspace:*
- version: link:../render-hyperframes
'@hypit/run-markup':
specifier: workspace:*
version: link:../run-markup
diff --git a/skills/hypit/references/element-review.md b/skills/hypit/references/element-review.md
index a35b6e3b..fc71da2e 100644
--- a/skills/hypit/references/element-review.md
+++ b/skills/hypit/references/element-review.md
@@ -124,7 +124,7 @@ A mock lives only in this render. It is never written into the Source, and no ga
### The derived Run carries the mocks, and nothing else changes
-The mocks are substituted into a Run that names the project's own Source. The whole program is drawn
+The mocks are substituted into a Run that names the project's own Source. The whole program is built
and the window is cut out of it afterwards, so every element the Source places is present and
drawn wherever the Source puts it — what is on screen over the words being looked at is what the
delivery will put there.
diff --git a/skills/hypit/references/original-authoring/route.md b/skills/hypit/references/original-authoring/route.md
index 52d63eff..a7ca43d1 100644
--- a/skills/hypit/references/original-authoring/route.md
+++ b/skills/hypit/references/original-authoring/route.md
@@ -217,7 +217,7 @@ hypit-reference-video-tools authoring_check projects/<name>/build.svrun
```
Its `plan` is the list: each entry an element and a word range, with the reason. Feed it to
-`render_element --batch` — the program is drawn once and every entry is cut out of that one render.
+`render_element --batch` — the program is built once and every entry is cut out of that one film.
Keep `.hypit/layout-check.json` with the renders. The reader still decides whether visible text or
marks fit the intent and whether any measured offset, overlap or bleed is deliberate.
diff --git a/skills/hypit/references/preview.md b/skills/hypit/references/preview.md
index a7918d83..9475b2d3 100644
--- a/skills/hypit/references/preview.md
+++ b/skills/hypit/references/preview.md
@@ -102,9 +102,9 @@ extension writes one still from the middle of it.
A whole round is one call: `--batch <renders.json>`, an array of `{element, segment|selection|tokens,
out}` inheriting the Run, and the `renders` array `reconstruction_check` returns is exactly that.
-The program is realized and drawn once for the whole round, into one mp4 of the whole mocked
-program, then the entries are processed serially and cut from it. Asking for eight windows therefore
-costs one full draw and eight cuts without concurrent workers racing over the shared `preview.svrun`.
+The mocked program is realized and built once for the whole round, into one film, then the entries
+are processed serially and cut out of it. Asking for eight windows therefore costs one Build and
+eight cuts without concurrent workers racing over the shared `preview.svrun`.
The picture does not depend on `--element` — it is everything the Source places over those words — so
two elements over one stretch share the render as well.
diff --git a/skills/hypit/references/reconstruction/route.md b/skills/hypit/references/reconstruction/route.md
index 9b3a323f..88756035 100644
--- a/skills/hypit/references/reconstruction/route.md
+++ b/skills/hypit/references/reconstruction/route.md
@@ -390,7 +390,7 @@ hypit-reference-video-tools render_element projects/<name>/build.svrun --batch r
```
`comparison-round.md` uses preview-mock estimate timing; `--reference-id` selects comparison evidence, not mock timing.
-The program is realized and drawn once into one mp4 and entries are cut from it serially, so render
+The program is realized and built once into one film and entries are cut from it serially, so render
the whole list in one `--batch` call; the batch does not run concurrent preview staging workers.
Keep `.hypit/layout-check.json` beside the round. Its realized stable-state measurements remain