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.

feat: add minimal reference rerun controls

rponee4a544c912f8
diff --git a/.agents/skills/hypit/references/reference-video/workflow.md b/.agents/skills/hypit/references/reference-video/workflow.md
index 8d40c4f9..6b35e34f 100644
--- a/.agents/skills/hypit/references/reference-video/workflow.md
+++ b/.agents/skills/hypit/references/reference-video/workflow.md
@@ -8,6 +8,20 @@ hypit-reference-video-tools observe_reference --reference-id <reference-id>
hypit-reference-video-tools inspect_svml_vocabulary --package <package> --tag <tag>
```
+Defaults are sufficient for normal use. When a completed preparation stage needs to be rerun, use
+one of the small `--redo` values:
+
+```bash
+hypit-reference-video-tools prepare_reference --video-path <path> --redo people
+```
+
+Use `--redo media` to rebuild shot media and clear derived observations, `--redo voices` for the
+whole-reference voice pass, or `--redo all` for every preparation stage. For observation, omit shot
+IDs to process all unfinished work. Supplying `--shot-id` one or more times forces those shots and
+their adjacent continuity boundaries to run again; three continuous IDs also trigger the three-shot
+continuity review. Add one `--question` for a narrow follow-up. The tool always attaches the
+preceding tail frame, audio tail and full-reference people/voice/product evidence automatically.
+
Each also accepts `--input <json>`. Follow this sequence:
```text
@@ -31,4 +45,5 @@ plan, component names or TypeScript. It is evidence, not the final decision make
Inspect every failed or unresolved result. Follow up with one narrow question over one to three
relevant shots rather than repeating the entire analysis. Preserve successful cached observations
-unless the evidence itself must be refreshed.
+unless the selected shot or preparation stage must be refreshed. Do not pass model, concurrency,
+rate-limit or temperature settings; temperature is fixed at `1.0`.
diff --git a/packages/reference-video-tools/README.md b/packages/reference-video-tools/README.md
index 2214d135..8dfb220f 100644
--- a/packages/reference-video-tools/README.md
+++ b/packages/reference-video-tools/README.md
@@ -12,7 +12,10 @@ Run the CLI from the repository or an installed package:
```bash
pnpm hypit-reference-video-tools prepare_reference --video-path ./reference.mp4
+pnpm hypit-reference-video-tools prepare_reference --video-path ./reference.mp4 --redo people
pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id>
+pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007
+pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007 --shot-id shot-008
pnpm hypit-reference-video-tools inspect_svml_vocabulary --package @hypit/media-track --tag Track
```
@@ -20,6 +23,16 @@ For automation, every command also accepts `--input '{"...":"..."}'` with the co
object. This is useful when the calling agent already has a structured request.
`prepare_reference` requires a local video path and stores derived media under the project's
-gitignored `.hypit/reference-video-tools/` directory. Gemini uses the existing Vertex environment
-variables `GOOGLE_CLOUD_PROJECT` and `GOOGLE_APPLICATION_CREDENTIALS_JSON`; the location defaults to
-`global` and the model defaults to `gemini-3.1-pro-preview`.
+gitignored `.hypit/reference-video-tools/` directory. Without `--redo`, completed stages are
+reused. Use `--redo media` to rebuild shot media and clear derived observations, or `--redo people`,
+`--redo voices`, or `--redo all` to rerun only the selected full-reference analysis stages.
+
+`observe_reference` without shot IDs observes all unfinished work. Supplying one or more shot IDs
+forces those shots and their adjacent continuity boundaries to run again; supplying three
+continuous shots also requests the three-shot continuity review. The preceding tail frame, audio
+tail and full-reference context are always attached automatically. `--question` adds one narrow
+follow-up for the selected shots.
+
+Gemini uses the existing Vertex environment variables `GOOGLE_CLOUD_PROJECT` and
+`GOOGLE_APPLICATION_CREDENTIALS_JSON`; the location defaults to `global` and the model defaults to
+`gemini-3.1-pro-preview`.
diff --git a/packages/reference-video-tools/src/cli.ts b/packages/reference-video-tools/src/cli.ts
index 90f7ffd5..c851e9dc 100644
--- a/packages/reference-video-tools/src/cli.ts
+++ b/packages/reference-video-tools/src/cli.ts
@@ -6,8 +6,8 @@ type Flags = ReadonlyMap<string, string | readonly string[] | boolean>;
function usage(): string {
return [
"Usage:",
- " hypit-reference-video-tools prepare_reference --video-path <path> [--rebuild]",
- " hypit-reference-video-tools observe_reference --reference-id <id> [--shot-id <id> ...] [--question <text>] [--refresh]",
+ " hypit-reference-video-tools prepare_reference --video-path <path> [--redo media|people|voices|all]",
+ " hypit-reference-video-tools observe_reference --reference-id <id> [--shot-id <id> ...] [--question <text>]",
" hypit-reference-video-tools inspect_svml_vocabulary --package <name> [--package <name> ...] [--tag <tag> ...] [--without-previews]",
"",
"Every command prints one JSON result to stdout. Use --input <json> instead of flags when a complete input object is easier to pass.",
@@ -65,23 +65,25 @@ function inputObject(flags: Flags): Record<string, unknown> | undefined {
async function main(): Promise<void> {
const { command, flags } = parse(process.argv.slice(2));
+ if (flags.has("rebuild") || flags.has("refresh")) {
+ throw new Error("--rebuild and --refresh were removed; use --redo or selected --shot-id values");
+ }
const tools = createReferenceVideoTools();
const supplied = inputObject(flags);
let result: unknown;
if (command === "prepare_reference") {
const input = supplied ?? {
video_path: required(flags, "video-path"),
- ...(flags.get("rebuild") === true ? { rebuild: true } : {}),
+ ...(one(flags, "redo") === undefined ? {} : { redo: one(flags, "redo") }),
};
- result = await tools.prepare_reference(input as { video_path: string; rebuild?: boolean });
+ result = await tools.prepare_reference(input as { video_path: string; redo?: "media" | "people" | "voices" | "all" });
} else if (command === "observe_reference") {
const input = supplied ?? {
reference_id: required(flags, "reference-id"),
...(many(flags, "shot-id").length === 0 ? {} : { shot_ids: many(flags, "shot-id") }),
...(one(flags, "question") === undefined ? {} : { question: one(flags, "question") }),
- ...(flags.get("refresh") === true ? { refresh: true } : {}),
};
- result = await tools.observe_reference(input as { reference_id: string; shot_ids?: readonly string[]; question?: string; refresh?: boolean });
+ result = await tools.observe_reference(input as { reference_id: string; shot_ids?: readonly string[]; question?: string });
} else if (command === "inspect_svml_vocabulary") {
const packages = many(flags, "package");
const input = supplied ?? {
diff --git a/packages/reference-video-tools/src/tools.ts b/packages/reference-video-tools/src/tools.ts
index e92c55fc..6052480d 100644
--- a/packages/reference-video-tools/src/tools.ts
+++ b/packages/reference-video-tools/src/tools.ts
@@ -1,6 +1,6 @@
import { GoogleGenAI } from "@google/genai";
import type { Part } from "@google/genai";
-import { access, stat } from "node:fs/promises";
+import { access, stat, writeFile } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import { createRequire } from "node:module";
import { loadNodePackageSelection } from "@hypit/package-loader-node";
@@ -18,12 +18,14 @@ import {
} from "./media.js";
import type { Observation, PrepareResult, ReferenceState, Shot } from "./types.js";
-export type PrepareReferenceInput = { readonly video_path: string; readonly rebuild?: boolean };
+export type PrepareReferenceInput = {
+ readonly video_path: string;
+ readonly redo?: "media" | "people" | "voices" | "all";
+};
export type ObserveReferenceInput = {
readonly reference_id: string;
readonly shot_ids?: readonly string[];
readonly question?: string;
- readonly refresh?: boolean;
};
export type InspectVocabularyInput = {
readonly package_names: readonly string[];
@@ -135,13 +137,13 @@ async function pacedMap<T, R>(items: readonly T[], concurrency: number, gapMs: n
async function runObservationTasks(
root: string,
tasks: readonly ObservationTask[],
- refresh: boolean,
+ forcedKeys: ReadonlySet<string>,
concurrency: number,
gapMs: number,
): Promise<ReadonlyMap<string, Observation>> {
const path = join(root, "observations.json");
const cache = await readJson<Record<string, Observation>>(path) ?? {};
- const pending = tasks.filter((task) => refresh || cache[task.key]?.status !== "complete");
+ const pending = tasks.filter((task) => forcedKeys.has(task.key) || cache[task.key]?.status !== "complete");
const completed = await pacedMap(pending, concurrency, gapMs, async (task) => ({ key: task.key, value: await task.run() }));
for (const item of completed) cache[item.key] = item.value;
await writeJson(path, cache);
@@ -200,6 +202,7 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
return {
async prepare_reference(input): Promise<PrepareResult> {
+ assert(input.redo === undefined || input.redo === "media" || input.redo === "people" || input.redo === "voices" || input.redo === "all", "redo must be one of: media, people, voices, all");
const videoPath = resolve(input.video_path);
const file = await stat(videoPath).catch(() => undefined);
assert(file?.isFile(), `video_path is not a file: ${videoPath}`);
@@ -207,11 +210,14 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
const root = stateRoot(workspaceRoot, reference);
const statePath = join(root, "state.json");
let existing = await readJson<ReferenceState>(statePath);
- if (!input.rebuild) {
+ const redoMedia = input.redo === "media" || input.redo === "all";
+ const redoPeople = input.redo === "people" || input.redo === "all";
+ const redoVoices = input.redo === "voices" || input.redo === "all";
+ if (input.redo === undefined) {
if (existing !== undefined && existing.people_and_product?.status === "complete" && existing.voices?.status === "complete") return publicPrepare(existing);
}
await ensureDir(root);
- const info = existing?.video === undefined ? await probe(videoPath) : {
+ const info = existing?.video === undefined || redoMedia ? await probe(videoPath) : {
duration: existing.video.duration_seconds,
width: existing.video.width,
height: existing.video.height,
@@ -219,7 +225,7 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
};
let state: ReferenceState;
let analysisVideo: string;
- if (existing !== undefined && !input.rebuild && existing.shots.length > 0) {
+ if (existing !== undefined && !redoMedia && existing.shots.length > 0) {
state = existing;
analysisVideo = existing.analysis_video_ref;
} else {
@@ -233,17 +239,20 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
shots,
storyboard_ref: media.storyboard,
analysis_video_ref: media.analysisVideo,
+ ...(existing?.people_and_product === undefined ? {} : { people_and_product: existing.people_and_product }),
+ ...(existing?.voices === undefined ? {} : { voices: existing.voices }),
};
analysisVideo = media.analysisVideo;
await writeJson(statePath, state);
+ await writeFile(join(root, "observations.json"), "{}\n", "utf8");
}
const generate = await generator();
const globalParts: Part[] = [await mediaPart(analysisVideo)];
const [people, voices] = await Promise.all([
- state.people_and_product?.status === "complete" && !input.rebuild
+ state.people_and_product?.status === "complete" && !redoPeople
? Promise.resolve(state.people_and_product)
: callSafely(generate, [...globalParts, { text: "Describe the recurring people and the promoted product in this complete reference video. Return natural language only. Identify stable visual traits and distinguish recurring speakers from incidental people in inserts. Describe the product once, comprehensively, for reuse." }], "You only observe a reference video. Return natural language evidence only. Do not write code, markup, SVML, or component names."),
- state.voices?.status === "complete" && !input.rebuild
+ state.voices?.status === "complete" && !redoVoices
? Promise.resolve(state.voices)
: callSafely(generate, [...globalParts, { text: "Listen to this complete reference video and describe the distinct voices, their order, overlap, off-screen speech, and likely correspondence to visible people. Do not assign a voice merely because a person appears in a B-roll image. Return natural language only." }], "You only listen to a reference video. Return natural language evidence only. Do not write code, markup, SVML, or component names."),
]);
@@ -293,10 +302,18 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
return await callSafely(generate, parts, "Analyze overlay continuity only. Do not name SVML components or write code.");
}}));
const allTasks = [...visualTasks, ...audioTasks, ...sameTakeTasks, ...overlayTasks];
- const observations = await runObservationTasks(state.root, allTasks, input.refresh === true, concurrency, gapMs);
+ const forcedKeys = input.shot_ids === undefined
+ ? new Set<string>()
+ : new Set(allTasks
+ .filter((task) => selectedIds.has(task.key.split(":")[1]!) || boundaryRights.some((right) => task.key.endsWith(`:${right.shot_id}`)))
+ .map((task) => task.key));
+ const observations = await runObservationTasks(state.root, allTasks, forcedKeys, concurrency, gapMs);
const unresolved: string[] = [];
const boundaryText = boundaryRights.map((right) => `${observations.get(`same-take:${right.shot_id}`)?.text ?? ""}\n${observations.get(`overlay:${right.shot_id}`)?.text ?? ""}`).join("\n");
- const needsThreeShotReview = selected.length >= 3 && /uncertain|unknown|possibly|may be|contin(?:ue|ues)|same take|same shot/iu.test(boundaryText);
+ const needsThreeShotReview = selected.length >= 3 && (
+ input.shot_ids !== undefined ||
+ /uncertain|unknown|possibly|may be|contin(?:ue|ues)|same take|same shot/iu.test(boundaryText)
+ );
const windows = (needsThreeShotReview
? selected.flatMap((_, index) => index + 2 < selected.length ? [selected.slice(index, index + 3)] : [])
: []).map((items) => items as unknown as readonly [Shot, Shot, Shot]);