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: structure reference reconstruction skill

rpone2b71d7736347
diff --git a/.agents/skills/hypit/SKILL.md b/.agents/skills/hypit/SKILL.md
index 56fc251a..3172c656 100644
--- a/.agents/skills/hypit/SKILL.md
+++ b/.agents/skills/hypit/SKILL.md
@@ -18,14 +18,51 @@ Source, and the declarative `hypit.runtime.json` Runtime Profile separate.
- Production craft or format choice → read `references/playbooks/index.md`,
`references/playbooks/craft/production-gates.md`, and
`references/playbooks/craft/visual-continuity.md`, then the relevant craft/format file.
-- Reference-video reconstruction → read `references/reference-vlm.md`; emit `main.svml`, optional
- `studio.svs`, and `build.svrun` directly.
+- Reference-video reconstruction → read `references/reference-vlm.md`; use the three reference-video
+ MCP tools, then author `main.svml`, `studio.svs`, and `build.svrun` yourself.
- Showing an author what they have so far → start the SVML Playground and send them the link.
See "Show the work" below.
- Execution, Runtime control, Build inspection, or output retrieval → read
`references/runtime.md`; diagnose and start the durable Runtime, `check` Author Source, `plan`
before paid work, then submit, inspect, and retrieve the Build.
+## Reference-video reconstruction workflow
+
+When the user asks to reproduce, reverse, reconstruct, or analyze a reference video, this is a
+tool-driven task rather than an ordinary hand-authored video task.
+
+1. Read `references/reference-vlm.md` completely.
+2. Call `prepare_reference` with the local video path.
+3. Call `observe_reference` for the full reference. It prepares the previous tail frame, previous
+ audio tail, whole-reference people, voice, and product context automatically and observes shots
+ in parallel.
+4. Read every failed or unresolved observation. Ask `observe_reference` a narrow follow-up only
+ where evidence conflicts or remains uncertain.
+5. Choose the packages needed by the observed video and call `inspect_svml_vocabulary` before
+ writing any component, attribute, child, port, or Recipe.
+6. Write one complete `main.svml`, one `studio.svs`, and one `build.svrun`. Do not write one partial
+ SVML fragment per shot and concatenate them.
+7. Run the existing `pnpm hypit check` command and repair the sources until the project is legal.
+
+Gemini is only the eyes and ears. It returns natural-language evidence, never SVML, SVS, SVRun,
+component declarations, prompts containing package syntax, or a final structural decision. The
+calling agent owns the synthesis and all final files.
+
+The reconstruction invariants are mandatory:
+
+- The person who is speaking owns base; the lowest or largest picture does not.
+- Picture ownership and sound ownership are separate. Full-screen B-roll can cover the picture
+ while the previous speaker remains the sound owner and base.
+- A B-roll person who appears to speak but whose B-roll is silent cannot take over the speaker,
+ sound, or base.
+- A shot with no visible person can still carry the previous speaker's continuing sound.
+- The same overlay continuing across a cut remains one visual track; a cut alone never creates a
+ replacement overlay.
+- Merge incorrectly split continuous shots only when the observations confirm one shot and the
+ combined duration is at most 15 seconds. Three-shot continuity requires explicit evidence too.
+- Reuse the full-reference people, voice, and product evidence. Describe a promoted product once;
+ do not invent a new product description in every shot.
+
## Read the package README before writing its syntax
Before writing any element from a package, read that package's README. The import
diff --git a/.agents/skills/hypit/agents/openai.yaml b/.agents/skills/hypit/agents/openai.yaml
index c5f9ed6c..a2246918 100644
--- a/.agents/skills/hypit/agents/openai.yaml
+++ b/.agents/skills/hypit/agents/openai.yaml
@@ -1,4 +1,4 @@
interface:
display_name: "Hypit"
- short_description: "Build SVML videos with production playbooks"
- default_prompt: "Use $hypit to author, validate, or refine native SVML video sources and production craft."
+ short_description: "Build SVML videos and reconstruct reference videos with MCP tools"
+ default_prompt: "Use $hypit to author, validate, or refine native SVML video sources; for reference-video reconstruction, call prepare_reference, observe_reference, and inspect_svml_vocabulary before writing complete SVML, SVS, and SVRun sources."
diff --git a/.agents/skills/hypit/references/reference-vlm.md b/.agents/skills/hypit/references/reference-vlm.md
index d4d3e2bb..f4b6aa8d 100644
--- a/.agents/skills/hypit/references/reference-vlm.md
+++ b/.agents/skills/hypit/references/reference-vlm.md
@@ -1,32 +1,51 @@
-# Reference video VLM to SVML
-
-Write `main.svml`, optional `studio.svs`, and `build.svrun` directly.
-
-- Write all VLM instructions and generated image/video prompts in English. Preserve original language
- only for verbatim dialogue/transcript/sample lines.
-- Analyze active video clips, not stills alone. Split on RGB content distance, keep clips at or below
- 15 seconds, and share one reference across continuous parts.
-- Keep photographed base and editorial overlays complementary. Treat exact UI/screenshots/charts as
- provided media; generated live-action PIP/B-roll may be real generated media.
-- Anchor recurring people/products/locations at the clearest shot and reuse references topologically.
-- Listen to audio for voice design. Transcribe speech, not burned-in captions.
-- Before hand-writing a Seedance prompt, select an official vendored Kit when the format matches:
- `speaker-v1`, `broll-v1`, `podcast-v1`, `call-v1`, `street-interview-v1`,
- `motion-reference-v1`, or `camera-reference-v1`. Supply only Recipe axes and dynamic slots.
-- Author the transcript as Script; keep reusable prompt copy in `copy:Value`/`copy:Render`; generate
- media with `seedance:TextVideo`, `seedance:FrameVideo`, or `seedance:ReferenceVideo`; declare
- supplied assets with `media:Image`/`media:Audio` or place them with `media-track:Item`; establish
- timing with `speech:Spine` and `whisperx:Alignment`; build captions with an exact font,
- `caption-fine:Style`, `caption:Program`, `caption-ai:Planner`, and `caption-fine:Track`; put
- editorial text on `typo:Track`; then assemble with `film:Film`, render with `render:Video`, and
- demand the desired outputs in `build.svrun`.
-- Route every generated reference image through `playbooks/craft/production-gates.md`. Explicitly reuse
- each accepted image or take in the next Build with `.svrun` `build-record` and `satisfy`.
-
-Generated image prompt structure: an English reality contract matching the observed capture medium,
-the exact visible subject/story, camera geometry, and the role of every reference. Keep lighting,
-skin/material texture, focus, and photographic finish consistent with the reference format.
-
-When no official Kit applies, include this hygiene block in a freeform motion prompt:
-
-`Do not add subtitles or any on-screen text. Do not add stickers, labels, captions, floating words, or other graphic overlays. Preserve text that is physically printed on the product, device, or screen as part of the filmed content.`
+# Reference video reconstruction
+
+Use this only when the task is to reproduce or reverse a complete reference video into usable
+Hypit sources. The public interface is exactly three MCP tools in
+`@hypit/reference-video-tools`:
+
+- `prepare_reference({ video_path, rebuild? })` prepares the local video once, splits shots at or
+ below 15 seconds, extracts every clip, representative frame, tail frame, and audio tail, and
+ performs the one whole-reference people/product analysis and one whole-reference voice analysis.
+- `observe_reference({ reference_id, shot_ids?, question?, refresh? })` observes all selected shots in
+ parallel. It automatically supplies the previous shot's tail frame and audio tail, the whole
+ reference people/voice/product evidence, and all neighboring boundaries. It returns natural
+ language picture, sound, camera-continuity, overlay-continuity, and any three-shot or follow-up
+ evidence.
+- `inspect_svml_vocabulary({ package_names, tags?, include_previews? })` reads the selected packages'
+ current declarations and previews. It does not call Gemini and it does not know which component
+ a visual observation should become.
+
+The fixed loop is:
+
+```text
+prepare_reference
+→ observe_reference for all shots
+→ observe_reference with one narrow follow-up for each unresolved conflict
+→ inspect_svml_vocabulary for the packages actually needed
+→ main agent writes complete main.svml, studio.svs, build.svrun
+→ pnpm hypit check
+→ repair source syntax and run pnpm hypit check again
+```
+
+Never ask Gemini to write SVML, SVS, SVRun, a reference plan, component names, or package syntax.
+Gemini's output is evidence in natural language; the main agent decides the final source structure.
+Do not send vocabulary declarations or previews to Gemini.
+
+The reconstruction must preserve these facts:
+
+- Whoever is speaking is base. Visual layer order and screen area never decide base.
+- Picture and sound ownership are independent. Full-screen B-roll, a media insert, or a ranking
+ typewriter may cover the frame while the previous speaker's base and sound continue.
+- A silent B-roll person who appears to speak cannot become the speaker or base.
+- A continuing voice survives a shot with no visible person.
+- One overlay that continues across a cut stays one visual track. Do not duplicate it in every shot.
+- Combine two or three incorrectly split shots only when the natural-language continuity evidence
+ confirms one shot and the combined duration is no more than 15 seconds.
+- Reuse whole-reference people, voice, and product descriptions. A promoted product is described
+ once and reused consistently.
+
+After observations, read the selected package README as syntax authority as well as the dynamic
+vocabulary returned by `inspect_svml_vocabulary`. Author one complete dependency graph, not separate
+per-shot source fragments. Use only declared tags, attributes, children, ports, Recipe properties,
+and admitted values. Use the existing `pnpm hypit check`; do not add or invent a check wrapper.
diff --git a/packages/reference-video-tools/package.json b/packages/reference-video-tools/package.json
index 2a3e48ae..0c8fbc57 100644
--- a/packages/reference-video-tools/package.json
+++ b/packages/reference-video-tools/package.json
@@ -12,11 +12,9 @@
},
"dependencies": {
"@google/genai": "1.52.0",
- "@hypit/artifact-store-fs": "workspace:*",
"@hypit/markup": "workspace:*",
"@hypit/package-loader-node": "workspace:*",
"@hypit/protocol": "workspace:*",
- "@hypit/runtime": "workspace:*",
"@modelcontextprotocol/sdk": "1.30.0",
"zod": "3.25.76"
},
diff --git a/packages/reference-video-tools/src/tools.ts b/packages/reference-video-tools/src/tools.ts
index c83cf55b..e92c55fc 100644
--- a/packages/reference-video-tools/src/tools.ts
+++ b/packages/reference-video-tools/src/tools.ts
@@ -206,31 +206,48 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
const reference = await referenceId(videoPath);
const root = stateRoot(workspaceRoot, reference);
const statePath = join(root, "state.json");
+ let existing = await readJson<ReferenceState>(statePath);
if (!input.rebuild) {
- const existing = await readJson<ReferenceState>(statePath);
- if (existing !== undefined) return publicPrepare(existing);
+ if (existing !== undefined && existing.people_and_product?.status === "complete" && existing.voices?.status === "complete") return publicPrepare(existing);
}
await ensureDir(root);
- const info = await probe(videoPath);
- const media = await prepareMedia(videoPath, root, info.duration);
- const shots = await Promise.all(media.bounds.map((bound, index) => shotFromBound(root, index, bound)));
- const state: ReferenceState = {
- reference_id: reference,
- video_path: videoPath,
- root,
- video: { duration_seconds: Number(info.duration.toFixed(3)), width: info.width, height: info.height, has_audio: info.hasAudio },
- shots,
- storyboard_ref: media.storyboard,
- analysis_video_ref: media.analysisVideo,
+ const info = existing?.video === undefined ? await probe(videoPath) : {
+ duration: existing.video.duration_seconds,
+ width: existing.video.width,
+ height: existing.video.height,
+ hasAudio: existing.video.has_audio,
};
- await writeJson(statePath, state);
+ let state: ReferenceState;
+ let analysisVideo: string;
+ if (existing !== undefined && !input.rebuild && existing.shots.length > 0) {
+ state = existing;
+ analysisVideo = existing.analysis_video_ref;
+ } else {
+ const media = await prepareMedia(videoPath, root, info.duration);
+ const shots = await Promise.all(media.bounds.map((bound, index) => shotFromBound(root, index, bound)));
+ state = {
+ reference_id: reference,
+ video_path: videoPath,
+ root,
+ video: { duration_seconds: Number(info.duration.toFixed(3)), width: info.width, height: info.height, has_audio: info.hasAudio },
+ shots,
+ storyboard_ref: media.storyboard,
+ analysis_video_ref: media.analysisVideo,
+ };
+ analysisVideo = media.analysisVideo;
+ await writeJson(statePath, state);
+ }
const generate = await generator();
- const globalParts: Part[] = [await mediaPart(media.analysisVideo)];
+ const globalParts: Part[] = [await mediaPart(analysisVideo)];
const [people, voices] = await Promise.all([
- 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."),
- 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."),
+ state.people_and_product?.status === "complete" && !input.rebuild
+ ? 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
+ ? 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."),
]);
- const complete = { ...state, people_and_product: people, voices };
+ const complete: ReferenceState = { ...state, people_and_product: people, voices };
await writeJson(statePath, complete);
return publicPrepare(complete);
},
@@ -335,7 +352,7 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
tag: implementation.tag,
mode: implementation.mode,
outputs: implementation.outputs,
- vocabulary: input.include_previews === false ? withoutPreview(implementation.vocabulary) : implementation.vocabulary,
+ vocabulary: vocabularyForResult(input.include_previews === false ? withoutPreview(implementation.vocabulary) : implementation.vocabulary),
readme_path: readmePath(pack.specifier, packageRoot),
});
}
@@ -345,6 +362,16 @@ export function createReferenceVideoTools(options: ToolOptions = {}): ReferenceV
};
}
+function vocabularyForResult(value: SurfaceVocabulary | undefined): unknown {
+ if (value === undefined) return undefined;
+ return {
+ ...value,
+ ...(value.preview === undefined ? {} : {
+ preview: { mediaType: value.preview.mediaType, path: value.preview.path },
+ }),
+ };
+}
+
function withoutPreview(value: SurfaceVocabulary | undefined): SurfaceVocabulary | undefined {
if (value === undefined) return undefined;
const { preview: _preview, ...rest } = value;
@@ -354,7 +381,16 @@ function withoutPreview(value: SurfaceVocabulary | undefined): SurfaceVocabulary
function readmePath(specifier: string, root: string): string | undefined {
try {
const require = createRequire(join(root, "__hypit_reference_tools__.cjs"));
- const packageJson = require.resolve(`${specifier}/package.json`) as string;
- return join(dirname(packageJson), "README.md");
+ const entry = require.resolve(specifier) as string;
+ let cursor = dirname(entry);
+ while (cursor !== dirname(cursor)) {
+ try {
+ const candidate = join(cursor, "package.json");
+ const packageJson = require(candidate) as { name?: string };
+ if (packageJson.name === specifier) return join(cursor, "README.md");
+ } catch { /* keep walking */ }
+ cursor = dirname(cursor);
+ }
+ return undefined;
} catch { return undefined; }
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9b1b9c9e..485b2e8d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2084,9 +2084,6 @@ importers:
'@google/genai':
specifier: 1.52.0
version: 1.52.0(@modelcontextprotocol/[email protected]([email protected]))
- '@hypit/artifact-store-fs':
- specifier: workspace:*
- version: link:../artifact-store-fs
'@hypit/markup':
specifier: workspace:*
version: link:../markup
@@ -2096,9 +2093,6 @@ importers:
'@hypit/protocol':
specifier: workspace:*
version: link:../protocol
- '@hypit/runtime':
- specifier: workspace:*
- version: link:../runtime
'@modelcontextprotocol/sdk':
specifier: 1.30.0
version: 1.30.0([email protected])