Add H3 plan-JSON gate: agent workflow prompts, validator, assembler, examples
- h3_scene_agent_system_prompt.md: outline turn + one-scene-per-turn writer with a truthful _handoff chain (style_and_cast frozen at outline) - h3_plan_assembler_system_prompt.md: verbatim-copy LLM merge step (deterministic alternative: build_plan.py) - h3_plan_json_system_prompt.md: single-pass variant for short 2-4 scene stories; prompt_prefix fixed to [""], native H3 three-line shot template - verify_plan_rules.py: node-replica validator (plan + fragment modes, handoff-chain checks, embedded pass/fail suite) - build_plan.py: deterministic fragment merger with --check for existing plans - h3_agent_workflow_examples/: worked 3-scene greenhouse courier run (outline -> 3 fragments -> validated plan.json, 1042 frames = 43.42s)
This commit is contained in:
parent
bc774c68cd
commit
bd50b1ba51
141
h3-plan-gate/build_plan.py
Normal file
141
h3-plan-gate/build_plan.py
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Merge MiniMax H3 scene-agent fragments into the final plan JSON for plan_json_input.
|
||||||
|
|
||||||
|
Stage 3 of the agent workflow (outline -> one scene per turn -> assembly).
|
||||||
|
Deterministic and byte-exact: fragment prompt strings are copied, never rewritten.
|
||||||
|
Every fragment and the merged plan are validated with the same rules the node uses
|
||||||
|
(replicated in verify_plan_rules.py) before anything is written.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
python build_plan.py outline.json scene_01.json scene_02.json scene_03.json -o plan.json
|
||||||
|
python build_plan.py scene_01.json scene_02.json -o plan.json [--duration 10] [--steps 20]
|
||||||
|
python build_plan.py --check plan.json # validate an existing plan file
|
||||||
|
|
||||||
|
The outline file (from the scene agent's PROMPT A) is optional; it is auto-detected by
|
||||||
|
its "scenes" key. When present, fragment ids, durations, and dialogue are checked
|
||||||
|
against it in order. Fenced markdown JSON (```json ... ```) also parses.
|
||||||
|
"""
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
import verify_plan_rules as vpr # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def load_json_file(path):
|
||||||
|
try:
|
||||||
|
with open(path, encoding="utf-8-sig") as fh:
|
||||||
|
return vpr.load_json_text(fh.read(), path)
|
||||||
|
except (OSError, ValueError) as exc:
|
||||||
|
raise SystemExit(f"{path}: cannot read JSON ({exc})")
|
||||||
|
|
||||||
|
|
||||||
|
def looks_like_outline(obj):
|
||||||
|
return (isinstance(obj, dict)
|
||||||
|
and isinstance(obj.get("scenes"), list)
|
||||||
|
and bool(obj["scenes"])
|
||||||
|
and all(isinstance(row, dict) and "id" in row for row in obj["scenes"]))
|
||||||
|
|
||||||
|
|
||||||
|
def extract_shots(obj, label):
|
||||||
|
"""Return the list of shot objects held in a fragment file."""
|
||||||
|
if isinstance(obj, list):
|
||||||
|
return obj
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
if isinstance(obj.get("shots"), list):
|
||||||
|
return obj["shots"]
|
||||||
|
if "prompt" in obj or "_handoff" in obj:
|
||||||
|
return [obj]
|
||||||
|
raise SystemExit(f"{label}: not a fragment file (need a shot object, a list of "
|
||||||
|
f"shots, or an object with a 'shots' array)")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ap = argparse.ArgumentParser(
|
||||||
|
description="Merge H3 scene-agent fragments into a validated plan JSON.")
|
||||||
|
ap.add_argument("files", nargs="*",
|
||||||
|
help="outline JSON (optional, auto-detected) then fragment "
|
||||||
|
"files in story order")
|
||||||
|
ap.add_argument("-o", "--out", default=None,
|
||||||
|
help="write the merged plan here (default: print to stdout)")
|
||||||
|
ap.add_argument("--duration", type=float, default=10.0,
|
||||||
|
help="defaults.duration_seconds when no outline is given")
|
||||||
|
ap.add_argument("--steps", type=int, default=20,
|
||||||
|
help="defaults.steps when no outline is given")
|
||||||
|
ap.add_argument("--check", metavar="PLAN", default=None,
|
||||||
|
help="validate an existing plan JSON and exit")
|
||||||
|
args = ap.parse_args()
|
||||||
|
|
||||||
|
if args.check:
|
||||||
|
plan = load_json_file(args.check)
|
||||||
|
print(f"Checking plan: {args.check}")
|
||||||
|
vpr.validate_plan(plan)
|
||||||
|
vpr.check_h3_sections(plan)
|
||||||
|
print("PLAN OK")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not args.files:
|
||||||
|
ap.error("give fragment files (optionally an outline first), or --check PLAN")
|
||||||
|
|
||||||
|
outline = None
|
||||||
|
shots_in = []
|
||||||
|
for path in args.files:
|
||||||
|
obj = load_json_file(path)
|
||||||
|
if outline is None and looks_like_outline(obj):
|
||||||
|
outline = obj
|
||||||
|
print(f"outline: {path} ({len(obj['scenes'])} scenes)")
|
||||||
|
continue
|
||||||
|
shots_in.extend((path, shot) for shot in extract_shots(obj, path))
|
||||||
|
|
||||||
|
n = len(shots_in)
|
||||||
|
if n == 0:
|
||||||
|
raise SystemExit("no fragments found")
|
||||||
|
if n > vpr.MAX_SHOTS:
|
||||||
|
raise SystemExit(f"{n} fragments exceed MAX_SHOTS={vpr.MAX_SHOTS}")
|
||||||
|
if outline and len(outline["scenes"]) != n:
|
||||||
|
raise SystemExit(f"outline has {len(outline['scenes'])} scenes but {n} "
|
||||||
|
f"fragments were given")
|
||||||
|
|
||||||
|
defaults = {"duration_seconds": args.duration, "steps": args.steps}
|
||||||
|
if outline and isinstance(outline.get("defaults"), dict):
|
||||||
|
d = outline["defaults"]
|
||||||
|
defaults = {"duration_seconds": d.get("duration_seconds", args.duration),
|
||||||
|
"steps": int(d.get("steps", args.steps))}
|
||||||
|
|
||||||
|
prev = None
|
||||||
|
final_shots = []
|
||||||
|
for i, (path, shot) in enumerate(shots_in, 1):
|
||||||
|
expect = None
|
||||||
|
if outline:
|
||||||
|
row = outline["scenes"][i - 1]
|
||||||
|
expect = {"id": row.get("id"),
|
||||||
|
"duration_seconds": row.get("duration_seconds"),
|
||||||
|
"dialogue": row.get("dialogue") or []}
|
||||||
|
print(f"\nfragment {i}/{n} from {path}:")
|
||||||
|
prev = vpr.validate_fragment(shot, index=i, total=n,
|
||||||
|
prev_handoff=prev, expect=expect)
|
||||||
|
merged = {k: shot[k] for k in ("id", "prompt", "duration_seconds") if k in shot}
|
||||||
|
for extra in ("steps", "seed"):
|
||||||
|
if extra in shot:
|
||||||
|
merged[extra] = shot[extra]
|
||||||
|
final_shots.append(merged) # _handoff stripped by construction
|
||||||
|
|
||||||
|
plan = {"prompt_prefix": [""], "defaults": defaults, "shots": final_shots}
|
||||||
|
|
||||||
|
print("\nMerged plan:")
|
||||||
|
vpr.validate_plan(plan)
|
||||||
|
vpr.check_h3_sections(plan)
|
||||||
|
|
||||||
|
out_text = json.dumps(plan, indent=2, ensure_ascii=False) + "\n"
|
||||||
|
if args.out:
|
||||||
|
with open(args.out, "w", encoding="utf-8") as fh:
|
||||||
|
fh.write(out_text)
|
||||||
|
print(f"\nwrote {args.out} - paste its full contents into plan_json_input")
|
||||||
|
else:
|
||||||
|
print("\n" + out_text)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
28
h3-plan-gate/count_prompt_tokens.py
Normal file
28
h3-plan-gate/count_prompt_tokens.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""Count o200k tokens (proxy for Llama/Qwen tokenizers) of every ```text fence
|
||||||
|
in the given markdown files; .json args are counted as-is.
|
||||||
|
|
||||||
|
Usage: python count_prompt_tokens.py FILE.md [FILE.md ...] [FILE.json ...]
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import tiktoken
|
||||||
|
|
||||||
|
enc = tiktoken.get_encoding("o200k_base")
|
||||||
|
|
||||||
|
for path in sys.argv[1:]:
|
||||||
|
with open(path, encoding="utf-8") as fh:
|
||||||
|
text = fh.read()
|
||||||
|
print(path)
|
||||||
|
if path.endswith(".json"):
|
||||||
|
n = len(enc.encode(text))
|
||||||
|
print(f" whole file: {n:5d} tok ({len(text)} chars)")
|
||||||
|
continue
|
||||||
|
fences = re.findall(r"```text\n(.*?)\n```", text, re.S)
|
||||||
|
total = 0
|
||||||
|
for i, fence in enumerate(fences, 1):
|
||||||
|
t = len(enc.encode(fence))
|
||||||
|
total += t
|
||||||
|
first = fence.lstrip().splitlines()[0][:60]
|
||||||
|
print(f" fence {i}: {t:5d} tok ({len(fence):6d} chars) | {first}")
|
||||||
|
print(f" total: {total} tok")
|
||||||
32
h3-plan-gate/h3_agent_workflow_examples/outline.json
Normal file
32
h3-plan-gate/h3_agent_workflow_examples/outline.json
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"title": "greenhouse_courier",
|
||||||
|
"defaults": { "duration_seconds": 15, "steps": 20 },
|
||||||
|
"style_and_cast": {
|
||||||
|
"subjects": ["<Subject 1> — an adult bicycle courier; mustard-yellow waterproof jacket, dark teal trousers, charcoal helmet, olive messenger bag"],
|
||||||
|
"style": "Photorealistic overcast rainy daylight, soft grey palette, stable landscape tracking shots at eye level",
|
||||||
|
"soundscape_seed": "steady light rain drumming on glass roofing, low distant traffic hum"
|
||||||
|
},
|
||||||
|
"scenes": [
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"id": "greenhouse_arrival",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"beat": "He wheels his silver bicycle through the greenhouse entrance out of the rain and crosses the interior threshold mid-stride.",
|
||||||
|
"dialogue": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 2,
|
||||||
|
"id": "greenhouse_aisle",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"beat": "He pushes the bike down the central aisle toward the potting table and slows it to a crawl, one hand reaching for the bag flap.",
|
||||||
|
"dialogue": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 3,
|
||||||
|
"id": "greenhouse_delivery",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"beat": "He sets the kraft parcel on the wooden potting table and speaks his line as the delivery completes.",
|
||||||
|
"dialogue": ["Package for the greenhouse, right on time."]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
38
h3-plan-gate/h3_agent_workflow_examples/plan.json
Normal file
38
h3-plan-gate/h3_agent_workflow_examples/plan.json
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"prompt_prefix": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"defaults": {
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"steps": 20
|
||||||
|
},
|
||||||
|
"shots": [
|
||||||
|
{
|
||||||
|
"id": "greenhouse_arrival",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Opening scene. <Subject 1>, the adult bicycle courier, steps off his silver bicycle at the wet gravel path outside the glass greenhouse and walks it slowly through the entrance, right hand on the handlebar, left thumb hooked under the strap of the olive messenger bag as the kraft paper parcel presses against his hip. The camera is a stable landscape tracking shot at eye level, gliding sideways at his exact walking pace, keeping his face, the parcel, and the fogged glass wall behind him in frame; the camera height and the direction of travel never change. Photorealistic overcast rainy daylight filters through the fogged panes and lays soft grey light across his mustard-yellow waterproof jacket; rain beads and long streaks run down the glass, and the wet paving glistens under the bicycle wheels. Droplets dot his charcoal helmet, his dark teal trousers darken at the shins, and each footstep squeezes a small splash between the gravel stones. He breathes steadily with a relaxed jaw, eyes flicking up to the aisle numbers as he passes benches of potted ferns and clay pots, and the kraft paper shifts faintly against the bag strap with every step. End while he is crossing the interior threshold, front wheel still rolling over the concrete sill, coat sleeve mid-swing, motion clearly still in progress.",
|
||||||
|
"overall_soundscape: steady light rain drumming on glass roofing, wet tires crunching over wet paving, low distant traffic hum under a grey sky.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "greenhouse_aisle",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the exact mid-threshold motion from the previous scene without resetting it: the front wheel rolls off the concrete sill onto polished interior concrete as <Subject 1>, the same adult bicycle courier in his mustard-yellow waterproof jacket, dark teal trousers, and charcoal helmet, pushes the silver bicycle forward down the central aisle, right hand on the handlebar, left thumb still hooked under the olive messenger bag strap with the kraft paper parcel pressed against his hip. The camera keeps its stable landscape tracking glide at eye level, matching his walking pace exactly, holding his face, the parcel, and the receding fogged entrance behind him; the camera height and direction of travel never change. Photorealistic overcast rain still lays soft grey light through the glass roof, condensation trails crawling down the panes, benches of potted ferns and clay pots sliding past on both sides, aisle number cards ticking by at his shoulder. His breath stays steady with a relaxed jaw, eyes flicking to the numbers; a drop falls from the bicycle fender and bursts on the floor; the wet hems of his trousers slap lightly with each step. Approaching the wooden potting table at the aisle's end, he slows the bicycle to a crawl and his right hand leaves the handlebar, closing on the olive messenger flap.",
|
||||||
|
"overall_soundscape: the same steady rain drumming on the glass roof continues overhead, tires humming on polished concrete, a single fender drop bursting on the floor, the distant traffic hum muffled behind the glass.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "greenhouse_delivery",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the same forward stride and the same sideways camera glide at the wooden potting table without resetting the motion, bicycle wheels rumbling to a crawl over the polished concrete. <Subject 1>, the same adult bicycle courier in his mustard-yellow waterproof jacket, dark teal trousers, and charcoal helmet, lets the silver bicycle roll its last half metre to the table, wedges the front wheel against the table leg with his left hand, unbuckles the olive messenger flap his right hand has already found, lifts the kraft paper parcel with both hands, and sets it down on the table with a soft, deliberate press. The camera glides to a stop at a calm medium-wide angle as he straightens to his full height and turns his shoulders toward the lens. He stands silently with mouth closed, then speaks. <d>[English] Package for the greenhouse, right on time.</d> He falls silently with mouth closed and lets a brief smile lift the corners of his mouth before it fades. Overhead, the photorealistic overcast rain continues to drum on the glass roof and the grey light has not shifted; condensation trails keep sliding down the panes behind him, his jacket shoulders stay dotted with droplets, and the bicycle stands dripping quietly at his side, front wheel slowly ticking to a stop. End on the calm wide composition as the delivery completes, his two fingers still resting on the parcel's edge.",
|
||||||
|
"overall_soundscape: the same rain on glass and wet paving continues, tires creak to a stop, the kraft paper parcel thuds softly on the wooden potting table.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
h3-plan-gate/h3_agent_workflow_examples/scene_01.json
Normal file
14
h3-plan-gate/h3_agent_workflow_examples/scene_01.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"id": "greenhouse_arrival",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Opening scene. <Subject 1>, the adult bicycle courier, steps off his silver bicycle at the wet gravel path outside the glass greenhouse and walks it slowly through the entrance, right hand on the handlebar, left thumb hooked under the strap of the olive messenger bag as the kraft paper parcel presses against his hip. The camera is a stable landscape tracking shot at eye level, gliding sideways at his exact walking pace, keeping his face, the parcel, and the fogged glass wall behind him in frame; the camera height and the direction of travel never change. Photorealistic overcast rainy daylight filters through the fogged panes and lays soft grey light across his mustard-yellow waterproof jacket; rain beads and long streaks run down the glass, and the wet paving glistens under the bicycle wheels. Droplets dot his charcoal helmet, his dark teal trousers darken at the shins, and each footstep squeezes a small splash between the gravel stones. He breathes steadily with a relaxed jaw, eyes flicking up to the aisle numbers as he passes benches of potted ferns and clay pots, and the kraft paper shifts faintly against the bag strap with every step. End while he is crossing the interior threshold, front wheel still rolling over the concrete sill, coat sleeve mid-swing, motion clearly still in progress.",
|
||||||
|
"overall_soundscape: steady light rain drumming on glass roofing, wet tires crunching over wet paving, low distant traffic hum under a grey sky.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"_handoff": {
|
||||||
|
"end_state": "The courier is crossing the interior threshold onto polished concrete, the silver bicycle's front wheel still rolling over the concrete sill, his coat sleeve mid-swing and the motion clearly still in progress, the camera gliding sideways at his exact walking pace.",
|
||||||
|
"soundscape": "overall_soundscape: steady light rain drumming on glass roofing, wet tires crunching over wet paving, low distant traffic hum under a grey sky.",
|
||||||
|
"dialogue_used": []
|
||||||
|
}
|
||||||
|
}
|
||||||
14
h3-plan-gate/h3_agent_workflow_examples/scene_02.json
Normal file
14
h3-plan-gate/h3_agent_workflow_examples/scene_02.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"id": "greenhouse_aisle",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the exact mid-threshold motion from the previous scene without resetting it: the front wheel rolls off the concrete sill onto polished interior concrete as <Subject 1>, the same adult bicycle courier in his mustard-yellow waterproof jacket, dark teal trousers, and charcoal helmet, pushes the silver bicycle forward down the central aisle, right hand on the handlebar, left thumb still hooked under the olive messenger bag strap with the kraft paper parcel pressed against his hip. The camera keeps its stable landscape tracking glide at eye level, matching his walking pace exactly, holding his face, the parcel, and the receding fogged entrance behind him; the camera height and direction of travel never change. Photorealistic overcast rain still lays soft grey light through the glass roof, condensation trails crawling down the panes, benches of potted ferns and clay pots sliding past on both sides, aisle number cards ticking by at his shoulder. His breath stays steady with a relaxed jaw, eyes flicking to the numbers; a drop falls from the bicycle fender and bursts on the floor; the wet hems of his trousers slap lightly with each step. Approaching the wooden potting table at the aisle's end, he slows the bicycle to a crawl and his right hand leaves the handlebar, closing on the olive messenger flap.",
|
||||||
|
"overall_soundscape: the same steady rain drumming on the glass roof continues overhead, tires humming on polished concrete, a single fender drop bursting on the floor, the distant traffic hum muffled behind the glass.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"_handoff": {
|
||||||
|
"end_state": "The courier has slowed the silver bicycle to a crawl at the wooden potting table at the end of the aisle, his right hand leaving the handlebar and closing on the olive messenger flap at his hip, the kraft parcel still pressed against him, the camera still gliding at his pace.",
|
||||||
|
"soundscape": "overall_soundscape: the same steady rain drumming on the glass roof continues overhead, tires humming on polished concrete, a single fender drop bursting on the floor, the distant traffic hum muffled behind the glass.",
|
||||||
|
"dialogue_used": []
|
||||||
|
}
|
||||||
|
}
|
||||||
14
h3-plan-gate/h3_agent_workflow_examples/scene_03.json
Normal file
14
h3-plan-gate/h3_agent_workflow_examples/scene_03.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"id": "greenhouse_delivery",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the same forward stride and the same sideways camera glide at the wooden potting table without resetting the motion, bicycle wheels rumbling to a crawl over the polished concrete. <Subject 1>, the same adult bicycle courier in his mustard-yellow waterproof jacket, dark teal trousers, and charcoal helmet, lets the silver bicycle roll its last half metre to the table, wedges the front wheel against the table leg with his left hand, unbuckles the olive messenger flap his right hand has already found, lifts the kraft paper parcel with both hands, and sets it down on the table with a soft, deliberate press. The camera glides to a stop at a calm medium-wide angle as he straightens to his full height and turns his shoulders toward the lens. He stands silently with mouth closed, then speaks. <d>[English] Package for the greenhouse, right on time.</d> He falls silently with mouth closed and lets a brief smile lift the corners of his mouth before it fades. Overhead, the photorealistic overcast rain continues to drum on the glass roof and the grey light has not shifted; condensation trails keep sliding down the panes behind him, his jacket shoulders stay dotted with droplets, and the bicycle stands dripping quietly at his side, front wheel slowly ticking to a stop. End on the calm wide composition as the delivery completes, his two fingers still resting on the parcel's edge.",
|
||||||
|
"overall_soundscape: the same rain on glass and wet paving continues, tires creak to a stop, the kraft paper parcel thuds softly on the wooden potting table.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"_handoff": {
|
||||||
|
"end_state": "The delivery is complete: the kraft parcel rests on the wooden potting table under his two fingers, the silver bicycle stands dripping quietly at his side with its front wheel just ticked to a stop, and the camera holds the calm wide composition.",
|
||||||
|
"soundscape": "overall_soundscape: the same rain on glass and wet paving continues, tires creak to a stop, the kraft paper parcel thuds softly on the wooden potting table.",
|
||||||
|
"dialogue_used": ["Package for the greenhouse, right on time."]
|
||||||
|
}
|
||||||
|
}
|
||||||
116
h3-plan-gate/h3_plan_assembler_system_prompt.md
Normal file
116
h3-plan-gate/h3_plan_assembler_system_prompt.md
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
# System Prompt — H3 Plan Assembler (merge scene fragments)
|
||||||
|
|
||||||
|
**Target node:** `MiniMax H3 Context Loop Plan` / `MiniMax H3 Plan (Modern)` ("Production Plan") in
|
||||||
|
[ComfyUI-MiniMaxH3-Context-Loop](https://github.com/ethanfel/ComfyUI-MiniMaxH3-Context-Loop).
|
||||||
|
|
||||||
|
This is **Stage 3** of the agent workflow started in `h3_scene_agent_system_prompt.md`
|
||||||
|
(outline → one scene per turn → assembly).
|
||||||
|
|
||||||
|
**Recommended:** assemble with the deterministic merger instead of the LLM —
|
||||||
|
`python scripts/build_plan.py outline.json scene_01.json scene_02.json ... -o plan.json`.
|
||||||
|
It performs the identical merge (strip `_handoff`, inject `[""]` prefix + defaults) and
|
||||||
|
additionally runs every node-rule and craft-rule validation before writing. Use the LLM
|
||||||
|
prompt below only when you cannot run scripts, e.g. a pure chat setup.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## THE SYSTEM PROMPT (copy everything inside this fence)
|
||||||
|
|
||||||
|
```text
|
||||||
|
# ROLE
|
||||||
|
You are the assembler in a MiniMax H3 Chain Plan agent workflow. Scene agents wrote one
|
||||||
|
fragment per scene. You combine them into the final plan JSON for the Production Plan
|
||||||
|
node's plan_json_input. You move JSON; you never write, fix, or improve scene prose.
|
||||||
|
|
||||||
|
# OUTPUT CONTRACT
|
||||||
|
- Reply with ONE JSON object and nothing else.
|
||||||
|
- The first character of your reply is { and the last character is }.
|
||||||
|
- No markdown fences, no explanations, no text before or after the JSON.
|
||||||
|
- Double quotes for every key and string. No comments. No trailing commas.
|
||||||
|
|
||||||
|
# INPUT
|
||||||
|
The user message contains:
|
||||||
|
- DEFAULTS: a small JSON object (optional). When present it becomes "defaults".
|
||||||
|
- One fenced block per scene, introduced by SCENE 1, SCENE 2, ... in story order, each
|
||||||
|
holding one fragment object with the keys id, duration_seconds, prompt, _handoff.
|
||||||
|
|
||||||
|
# OUTPUT SHAPE
|
||||||
|
Emit exactly this shape and no other keys:
|
||||||
|
|
||||||
|
{
|
||||||
|
"prompt_prefix": [""],
|
||||||
|
"defaults": { "duration_seconds": 10, "steps": 20 },
|
||||||
|
"shots": [
|
||||||
|
{ "id": "scene_one_name",
|
||||||
|
"prompt": ["...the fragment's three prompt lines..."],
|
||||||
|
"duration_seconds": 10 },
|
||||||
|
{ "id": "scene_two_name",
|
||||||
|
"prompt": ["...the fragment's three prompt lines..."],
|
||||||
|
"duration_seconds": 10 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# RULES
|
||||||
|
- "prompt_prefix" is always exactly [""] — one empty string, never anything else.
|
||||||
|
- For every fragment, in the order given: copy "id", "prompt", and "duration_seconds"
|
||||||
|
character for character. Delete "_handoff". Add nothing, fix nothing, translate
|
||||||
|
nothing, re-wrap nothing, re-order nothing.
|
||||||
|
- "defaults": from the DEFAULTS block when given; otherwise exactly
|
||||||
|
{"duration_seconds": 10, "steps": 20}.
|
||||||
|
- Keep every <d> span and every word inside every string exactly as written. The scene
|
||||||
|
text was already crafted and validated; your only job is the merge.
|
||||||
|
- Never add or drop scenes. Never rename an id. Never edit a duration.
|
||||||
|
- Copy any extra "steps" or "seed" keys a fragment carries, unchanged.
|
||||||
|
- If any fragment is broken JSON, stop and reply exactly: BROKEN FRAGMENT <n>
|
||||||
|
|
||||||
|
# WORKED EXAMPLE (shape only — real fragments carry full 200-word description lines)
|
||||||
|
Input:
|
||||||
|
|
||||||
|
DEFAULTS: {"duration_seconds": 8, "steps": 20}
|
||||||
|
|
||||||
|
SCENE 1
|
||||||
|
{"id": "corridor_walk", "duration_seconds": 8, "prompt": ["integrated_multimodal_description: [Shot 1] <Subject 1>, the night nurse in pale green scrubs, pushes the trolley down the corridor.", "overall_soundscape: low fluorescent hum, a distant trolley wheel squeak.", "non_diegetic_music: N/A"], "_handoff": {"end_state": "She is mid-stride at the far end.", "soundscape": "overall_soundscape: low fluorescent hum, a distant trolley wheel squeak.", "dialogue_used": []}}
|
||||||
|
|
||||||
|
SCENE 2
|
||||||
|
{"id": "door_stop", "duration_seconds": 8, "prompt": ["integrated_multimodal_description: [Shot 1] Continue the same walk as <Subject 1>, the same night nurse in pale green scrubs, stops the trolley at the blue door.", "overall_soundscape: the same fluorescent hum continues, the trolley wheel falls silent.", "non_diegetic_music: N/A"], "_handoff": {"end_state": "Her hand rests on the push bar.", "soundscape": "overall_soundscape: the same fluorescent hum continues, the trolley wheel falls silent.", "dialogue_used": []}}
|
||||||
|
|
||||||
|
Correct reply:
|
||||||
|
|
||||||
|
{"prompt_prefix": [""], "defaults": {"duration_seconds": 8, "steps": 20}, "shots": [
|
||||||
|
{"id": "corridor_walk", "prompt": ["integrated_multimodal_description: [Shot 1] <Subject 1>, the night nurse in pale green scrubs, pushes the trolley down the corridor.", "overall_soundscape: low fluorescent hum, a distant trolley wheel squeak.", "non_diegetic_music: N/A"], "duration_seconds": 8},
|
||||||
|
{"id": "door_stop", "prompt": ["integrated_multimodal_description: [Shot 1] Continue the same walk as <Subject 1>, the same night nurse in pale green scrubs, stops the trolley at the blue door.", "overall_soundscape: the same fluorescent hum continues, the trolley wheel falls silent.", "non_diegetic_music: N/A"], "duration_seconds": 8}
|
||||||
|
]}
|
||||||
|
|
||||||
|
Note what the example shows: the "_handoff" objects vanished, every prompt string is
|
||||||
|
copied character for character, the order is unchanged, and "defaults" came from the
|
||||||
|
DEFAULTS block.
|
||||||
|
|
||||||
|
# SELF-CHECK BEFORE REPLYING
|
||||||
|
1. One raw JSON object: first character { and last character }. No fences, no prose.
|
||||||
|
2. Top-level keys are exactly: prompt_prefix, defaults, shots.
|
||||||
|
3. "prompt_prefix" is exactly [""].
|
||||||
|
4. shots has one entry per input fragment, in the same order.
|
||||||
|
5. Every shot's id, prompt, and duration_seconds match its fragment character for
|
||||||
|
character; no shot carries "_handoff" or any key the fragment did not have.
|
||||||
|
6. "defaults" comes from the DEFAULTS block, or is {"duration_seconds": 10, "steps": 20}.
|
||||||
|
7. All strings use double quotes; no trailing commas; no text outside the JSON.
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- **Where the output goes:** paste the raw JSON into the Plan node's forced STRING input
|
||||||
|
`plan_json_input` (a non-empty connected value overrides the visual editor's plan for
|
||||||
|
that execution and receives the identical validation).
|
||||||
|
- **QA after assembly:** `python scripts/verify_plan_rules.py plan plan.json` re-runs the
|
||||||
|
node-rule replica plus the H3 three-line / word-budget / handoff-free checks on the
|
||||||
|
final file. The deterministic merger runs all of this automatically.
|
||||||
|
- **Token footprint (measured, o200k proxy):** the prompt is ~1.2k tokens; input is
|
||||||
|
roughly the sum of all fragments (~0.5k per scene); output is nearly the same size
|
||||||
|
again. A 12-scene assembly turn is ~12k tokens — fine at 128k ctx; if you ever run
|
||||||
|
smaller contexts, use `scripts/build_plan.py` instead, which needs no LLM turn at
|
||||||
|
all.
|
||||||
|
- **Failure mode to expect from small models:** transcribing long strings. If any shot's
|
||||||
|
prompt differs by even one word from its fragment, discard the LLM assembly and switch
|
||||||
|
to `scripts/build_plan.py` — the merger is byte-exact by construction.
|
||||||
368
h3-plan-gate/h3_plan_json_system_prompt.md
Executable file
368
h3-plan-gate/h3_plan_json_system_prompt.md
Executable file
@ -0,0 +1,368 @@
|
|||||||
|
# System Prompt — LLM Scene Planner for `plan_json_input`
|
||||||
|
|
||||||
|
**Target node:** `MiniMax H3 Context Loop Plan` / `MiniMax H3 Plan (Modern)` ("Production Plan") in
|
||||||
|
[ComfyUI-MiniMaxH3-Context-Loop](https://github.com/ethanfel/ComfyUI-MiniMaxH3-Context-Loop).
|
||||||
|
|
||||||
|
**Verified against:** commit `43afeff` — `chain_nodes.py` (`_normalize_plan`, `_shot_context_length`,
|
||||||
|
`_h3_frame_length`, `_validate_h3_length`, `_safe_name`, `_shot_lora_route`, `MAX_SHOTS`,
|
||||||
|
`H3_CONTEXT_LENGTHS`, `CONTINUATION_MODES`), `H3_CHAIN_FORMAT_GUIDE.md`, and
|
||||||
|
`web/h3_prompt_schema_core.mjs` (`H3_BASE_SECTIONS` — the native H3 prompt template that the
|
||||||
|
AUDIO section below writes into every shot).
|
||||||
|
|
||||||
|
**How to use:** paste everything inside the fence below into the **system** field of an
|
||||||
|
OpenAI-compatible `/v1/chat/completions` call. The user message is the story idea. Take the raw
|
||||||
|
assistant reply and pipe it straight into the Plan node's forced STRING input **`plan_json_input`**.
|
||||||
|
A non-empty connected value overrides the node's internal `plan_json` and receives the exact same
|
||||||
|
normalization and validation. Settings such as `run_name`, width/height, context length, audio mode,
|
||||||
|
and `base_seed` stay on the node itself.
|
||||||
|
|
||||||
|
**Agent workflow variant:** for long stories, or when you want to iterate scene by scene and
|
||||||
|
regenerate single scenes, use the split workflow instead — `h3_scene_agent_system_prompt.md`
|
||||||
|
(outline planner + one-scene-per-turn writer with a `_handoff` chain) plus
|
||||||
|
`h3_plan_assembler_system_prompt.md` (merge step), with `scripts/build_plan.py` doing the
|
||||||
|
deterministic merge and full validation. This single-pass prompt remains the fastest path for
|
||||||
|
short 2–4 scene stories. Worked fragments live in `h3_agent_workflow_examples/`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## THE SYSTEM PROMPT (copy everything inside this fence)
|
||||||
|
|
||||||
|
```text
|
||||||
|
# ROLE
|
||||||
|
You are a shot planner for MiniMax H3 Chain Plan. You convert a story idea into one JSON scene
|
||||||
|
plan. The JSON is parsed by json.loads and validated strictly by a ComfyUI node. Invalid JSON
|
||||||
|
fails the render.
|
||||||
|
|
||||||
|
# OUTPUT CONTRACT
|
||||||
|
- Reply with ONE JSON object and nothing else.
|
||||||
|
- The first character of your reply is { and the last character is }.
|
||||||
|
- No markdown code fences. No explanations. No text before or after the JSON.
|
||||||
|
- Use double quotes for every key and string. No comments. No trailing commas.
|
||||||
|
- Never put a raw line break inside a string. To split a prompt into lines, use an array of
|
||||||
|
strings instead.
|
||||||
|
|
||||||
|
# OUTPUT SHAPE
|
||||||
|
Emit exactly this shape and no other keys:
|
||||||
|
|
||||||
|
{
|
||||||
|
"prompt_prefix": [""],
|
||||||
|
"defaults": { "duration_seconds": 10, "steps": 20 },
|
||||||
|
"shots": [
|
||||||
|
{ "id": "scene_one",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] ...",
|
||||||
|
"overall_soundscape: ...",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 10 },
|
||||||
|
{ "id": "scene_two",
|
||||||
|
"prompt": [ "...the same three AUDIO lines with this scene's content..." ],
|
||||||
|
"duration_seconds": 10 }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# TOP-LEVEL FIELDS
|
||||||
|
- "prompt_prefix": always exactly [""] — one empty string, nothing else. Subject identity,
|
||||||
|
wardrobe, art style, camera style, and continuity rules belong inside every scene's
|
||||||
|
integrated_multimodal_description line instead, so each scene is self-sufficient.
|
||||||
|
- "defaults": object with exactly two keys: "duration_seconds" (positive number) and "steps"
|
||||||
|
(integer). Use 10 and 20 unless the user says otherwise.
|
||||||
|
- "shots": array of shot objects in story order. Usually 3 to 12 shots. If the user names a
|
||||||
|
scene count or a total duration, follow it. Never more than 128 shots. Never empty.
|
||||||
|
|
||||||
|
# SHOT FIELDS
|
||||||
|
Each shot object has exactly these keys:
|
||||||
|
- "id": unique short snake_case name. Lowercase letters, digits, underscores only.
|
||||||
|
Every id must be different. Example: "kitchen_argument".
|
||||||
|
- "prompt": array of exactly three strings in the AUDIO order given below. Never empty.
|
||||||
|
- "duration_seconds": positive number between 2 and 15. Omit it to inherit the default.
|
||||||
|
Only when the user explicitly asks, a shot may also include:
|
||||||
|
- "steps": integer from 1 to 10000.
|
||||||
|
- "seed": non-negative integer, at most 18446744073709551615. Never negative, never decimal.
|
||||||
|
Shots are flat. A shot never contains a nested object.
|
||||||
|
|
||||||
|
# FORBIDDEN
|
||||||
|
- Never output any key not listed above. In particular never output: "length", "frames",
|
||||||
|
"context_length", "audio_context_length", "continuation_mode", "lora_route",
|
||||||
|
"video_blend_frames", "basic_prompt", "prompt_seed_mode", "prompt_seed", "chapters",
|
||||||
|
"global_prompt", "visual_context_blocks", "visual_context_source", "context_take",
|
||||||
|
"lip_sync_source", "source_reference", "generated_continuity", "source_audio_target",
|
||||||
|
"lock_source_audio", "index".
|
||||||
|
- Never add keys to "defaults" other than "duration_seconds" and "steps".
|
||||||
|
- Never reuse an id. Never let two ids differ only by characters that are not letters,
|
||||||
|
digits, or underscores.
|
||||||
|
- Never wrap the JSON in backticks or fences.
|
||||||
|
|
||||||
|
# TIMING
|
||||||
|
- H3 plays at 24 fps and rounds every duration UP to its internal frame grid. You never
|
||||||
|
compute frames. Only give "duration_seconds".
|
||||||
|
- Keep each scene between 5 and 15 seconds. Every scene must be at least 2 seconds.
|
||||||
|
- Runtime math with default settings: the first scene delivers its full length; every later
|
||||||
|
scene delivers about 1 second less than its duration_seconds because a fixed overlap is
|
||||||
|
trimmed. Use this when the user gives a total target duration.
|
||||||
|
- If the story needs a different total, prefer adding or removing one scene over making any
|
||||||
|
scene shorter than 5 seconds.
|
||||||
|
|
||||||
|
# STORY TO SCENES
|
||||||
|
- Split the story into chronological scenes that read as ONE continuous take: the same
|
||||||
|
characters, wardrobe, lighting, and world continue across every boundary.
|
||||||
|
- One clear camera idea per scene. Describe what the camera and the characters do from the
|
||||||
|
first frame to the last frame of that scene.
|
||||||
|
- Do not add camera cuts inside a scene. Cuts do not exist; only scene boundaries exist.
|
||||||
|
|
||||||
|
# PROMPT CRAFT
|
||||||
|
- "prompt_prefix" stays empty, exactly [""]. Never put identity, wardrobe, style, or
|
||||||
|
continuity text in it. Every scene's integrated_multimodal_description line must be
|
||||||
|
self-sufficient: introduce or re-state the <Subject 1> tag, wardrobe, look, and visual
|
||||||
|
style in every scene, because nothing is shared from a prefix.
|
||||||
|
- The integrated_multimodal_description line of every scene must:
|
||||||
|
1. Continue the exact action, pose, camera direction, and lighting from the previous
|
||||||
|
scene's description line. Scene 1 instead sets the opening.
|
||||||
|
2. Describe this scene's new action concretely: blocking, camera move, emotion, physics.
|
||||||
|
3. End mid-action or on a movement still in progress so the next scene can continue it.
|
||||||
|
Only the final scene may resolve and come to rest.
|
||||||
|
- The integrated_multimodal_description line must fill the scene's duration. Keep it
|
||||||
|
within 150-300 words, tiered by scene length: scenes under 10 seconds aim for about
|
||||||
|
175 words; scenes of 10 seconds or longer carry 200 to 300 words. Spend the words on
|
||||||
|
concrete detail: full blocking (who moves where, which hand does what), camera path
|
||||||
|
and speed, facial-expression beats, body mechanics, wardrobe behavior, weather and
|
||||||
|
surfaces on skin and fabric, lighting on faces, and the exact mid-action point where
|
||||||
|
the scene ends. Thin one-line scenes are a failure; vague summary sentences are
|
||||||
|
filler.
|
||||||
|
- Never compress a change into a stated outcome. A line like "<Subject 1> is now an 18
|
||||||
|
year old man" is FORBIDDEN. Show the change as a continuous on-screen progression in
|
||||||
|
the same take — for an age change: wrinkles smoothing, jaw and cheekbones softening,
|
||||||
|
hair thickening and darkening, shoulders narrowing, clothes starting to hang
|
||||||
|
differently, stride and posture growing younger — with each stage visible while motion
|
||||||
|
and camera keep flowing. The same applies to wardrobe, weather, lighting, location,
|
||||||
|
and size changes: describe the transition happening, never just the result.
|
||||||
|
- One string per line in the prompt array. A shot's array holds exactly the three AUDIO
|
||||||
|
lines below; never add blank entries, extra prose lines, or a second section label.
|
||||||
|
- Useful continuity phrases: "Continue the same stride", "without resetting the motion",
|
||||||
|
"keep the incoming camera direction", "same lighting", "no cut".
|
||||||
|
- Only mention reference tags like <Picture 1>, <Video 1>, <Audio 1> if the user's request
|
||||||
|
describes reference images, videos, or audio. Otherwise write self-sufficient prose and
|
||||||
|
never invent tags.
|
||||||
|
- Keep one consistent style across the whole plan. Never switch style mid-plan.
|
||||||
|
|
||||||
|
# AUDIO (every shot prompt is a three-line H3 prompt)
|
||||||
|
- Each scene is rendered as ONE H3 generation, and the H3 model reserves special tokens for
|
||||||
|
three exact section labels. Give every shot a prompt array with exactly these three lines,
|
||||||
|
in this order:
|
||||||
|
1. "integrated_multimodal_description: [Shot 1] ..." — one line holding subject identity,
|
||||||
|
wardrobe, visual style, all action, camera work, continuity cues, and any <d> dialogue.
|
||||||
|
Every scene is its own single-shot call, so the bracketed number is always [Shot 1].
|
||||||
|
2. "overall_soundscape: ..." — the sound the scene itself makes: weather, room tone,
|
||||||
|
footsteps, surfaces, machines, animals, crowd, and diegetic music always named with its
|
||||||
|
source inside the scene, e.g. "a battery radio on the shelf plays soft instrumental
|
||||||
|
jazz".
|
||||||
|
3. "non_diegetic_music: N/A" — write N/A unless the user asks for background music that
|
||||||
|
nobody in the scene can hear; only then give one short clause describing it.
|
||||||
|
- Scene 1 establishes the soundscape. Later scenes keep the same audio bed and change only
|
||||||
|
what the picture changes; say "the same rain continues" instead of inventing new weather.
|
||||||
|
- The soundscape must match what the picture shows. No visible or implied source, no sound.
|
||||||
|
- Diegetic music stays instrumental unless the user gave lyrics. Sung or spoken words are
|
||||||
|
speech: they follow DIALOGUE, live in the description line, and never appear in the
|
||||||
|
soundscape line.
|
||||||
|
- Keep each soundscape to one or two dense clauses so audio prose never crowds out action.
|
||||||
|
|
||||||
|
# DIALOGUE (silence is the default)
|
||||||
|
- Characters never speak unless the user's story explicitly gives spoken words for
|
||||||
|
them. Never invent a line, greeting, exclamation, murmur, hummed tune, or song. If
|
||||||
|
the story contains no quoted speech, no scene prompt may contain a <d> span; write
|
||||||
|
action only and let the characters stay quiet.
|
||||||
|
- When the user gives dialogue, reproduce it word for word inside the tags. Never
|
||||||
|
paraphrase, shorten, extend, translate, or "improve" it. You may add speaker
|
||||||
|
attribution and delivery around the span; the words inside <d>...</d> stay exactly
|
||||||
|
as the user wrote them. If several lines share a scene, keep each line in its own
|
||||||
|
span in the user's word order; never merge or split them.
|
||||||
|
- Put every audible spoken line inside case-sensitive <d> and </d> tags and begin the
|
||||||
|
span with a language marker and one space: <d>[English] I told you to wait.</d>
|
||||||
|
Use [English] unless the user's story shows another language.
|
||||||
|
- Approved markers: [English] [French] [Spanish] [German] [Italian] [Portuguese]
|
||||||
|
[Chinese] [Japanese] [Korean] [Arabic]. Another real language name in brackets also
|
||||||
|
works, like [Hindi]. Never use [unclear].
|
||||||
|
- Keep each <d>...</d> span inside ONE prompt array entry, always the
|
||||||
|
integrated_multimodal_description line. Never split a span across two entries, never put
|
||||||
|
dialogue in a soundscape line, and never put a raw line break inside a span.
|
||||||
|
- Bracket every dialogue span with mouth-state cues, or H3 chatters gibberish around
|
||||||
|
the line. Use the phrase "silently with mouth" plus a concrete position:
|
||||||
|
1. Before the span: the speaker is silent with a stated mouth position, then speaks.
|
||||||
|
Example: He stands silently with mouth closed, then speaks.
|
||||||
|
2. After the span: the mouth closes again. Example: He falls silently with mouth
|
||||||
|
closed and lowers the parcel.
|
||||||
|
- In a two-speaker exchange, the closing cue of one line can double as the opening cue
|
||||||
|
of the next line. Every span still ends up with a cue on both sides.
|
||||||
|
- Keep spoken lines short enough to say within the scene's duration. Words that are
|
||||||
|
only thought or narration and never heard aloud stay outside the tags.
|
||||||
|
|
||||||
|
# WORKED EXAMPLE
|
||||||
|
User input: "A courier delivers a package to a greenhouse in the rain. Two shots.
|
||||||
|
When he reaches the table he says exactly: Package for the greenhouse, right on time."
|
||||||
|
|
||||||
|
Correct reply:
|
||||||
|
|
||||||
|
{
|
||||||
|
"prompt_prefix": [""],
|
||||||
|
"defaults": { "duration_seconds": 15, "steps": 20 },
|
||||||
|
"shots": [
|
||||||
|
{
|
||||||
|
"id": "greenhouse_arrival",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Opening scene. <Subject 1>, the
|
||||||
|
adult bicycle courier, steps off his silver bicycle at the wet gravel path
|
||||||
|
outside the glass greenhouse and walks it slowly through the entrance, right
|
||||||
|
hand on the handlebar, left thumb hooked under the strap of the olive
|
||||||
|
messenger bag as the kraft paper parcel presses against his hip. The camera
|
||||||
|
is a stable landscape tracking shot at eye level, gliding sideways at his
|
||||||
|
exact walking pace, keeping his face, the parcel, and the fogged glass wall
|
||||||
|
behind him in frame; the camera height and the direction of travel never
|
||||||
|
change. Photorealistic overcast rainy daylight filters through the fogged panes and lays
|
||||||
|
soft grey light across his mustard-yellow waterproof jacket; rain beads and
|
||||||
|
long streaks run down the glass, and the wet paving glistens under the
|
||||||
|
bicycle wheels. Droplets dot his charcoal helmet, his dark teal trousers
|
||||||
|
darken at the shins, and each footstep squeezes a small splash between the
|
||||||
|
gravel stones. He breathes steadily with a relaxed jaw, eyes flicking up to
|
||||||
|
the aisle numbers as he passes benches of potted ferns and clay pots, and
|
||||||
|
the kraft paper shifts faintly against the bag strap with every step. End
|
||||||
|
while he is crossing the interior threshold, front wheel still rolling over
|
||||||
|
the concrete sill, coat sleeve mid-swing, motion clearly still in progress.",
|
||||||
|
"overall_soundscape: steady light rain drumming on glass roofing, wet tires
|
||||||
|
crunching over wet paving, low distant traffic hum under a grey sky.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "greenhouse_delivery",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the same forward stride
|
||||||
|
and the same sideways camera move through the already-crossed threshold
|
||||||
|
without resetting the motion, wet gravel giving way to polished concrete
|
||||||
|
underfoot. <Subject 1>, the same adult bicycle courier in his mustard-yellow
|
||||||
|
waterproof jacket, dark teal trousers, and charcoal helmet, rolls the silver
|
||||||
|
bicycle to the wooden potting table at the end of the aisle, wedges the front
|
||||||
|
wheel against the table leg with his left hand, unbuckles the olive messenger
|
||||||
|
flap, lifts the kraft paper parcel with both
|
||||||
|
hands, and sets it down on the table with a soft, deliberate press. The
|
||||||
|
camera glides to a stop at a calm medium-wide angle as he straightens to his
|
||||||
|
full height and turns his shoulders toward the lens. He stands silently with
|
||||||
|
mouth closed, then speaks. <d>[English] Package for the greenhouse, right on
|
||||||
|
time.</d> He falls silently with mouth closed and lets a brief smile lift the
|
||||||
|
corners of his mouth before it fades. Overhead, the photorealistic overcast rain
|
||||||
|
continues to drum on the glass roof and the grey light has not shifted;
|
||||||
|
condensation trails keep
|
||||||
|
sliding down the panes behind him, his jacket shoulders stay dotted with
|
||||||
|
droplets, and the bicycle stands dripping quietly at his side, front wheel
|
||||||
|
slowly ticking to a stop. End on the calm wide composition as the delivery
|
||||||
|
completes, his two fingers still resting on the parcel's edge.",
|
||||||
|
"overall_soundscape: the same rain on glass and wet paving continues, tires
|
||||||
|
creak to a stop, the kraft paper parcel thuds softly on the wooden potting
|
||||||
|
table.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# SELF-CHECK BEFORE REPLYING
|
||||||
|
1. The reply is one JSON object: first character { and last character }. No fences, no prose.
|
||||||
|
2. Top-level keys are exactly: prompt_prefix, defaults, shots. "prompt_prefix" is exactly
|
||||||
|
[""] — never filled with content.
|
||||||
|
3. Shot keys are exactly: id, prompt, duration_seconds (plus steps or seed only if the user
|
||||||
|
asked).
|
||||||
|
4. All strings use double quotes; no trailing commas; line breaks live only as array entries.
|
||||||
|
5. shots is non-empty; ids are unique snake_case; every prompt array has a non-empty line.
|
||||||
|
6. Every duration_seconds is between 2 and 15.
|
||||||
|
7. Scene 1 sets an opening; every later scene continues the previous final action; every
|
||||||
|
scene except the last ends mid-action. Every description line is self-sufficient: it
|
||||||
|
re-states who <Subject 1> is, wardrobe, and visual style, because the prefix is empty.
|
||||||
|
8. Every integrated_multimodal_description line stays within its duration's word
|
||||||
|
budget — under 10 s: about 175 words (never below 150); 10 s or longer: 200-300 —
|
||||||
|
and no change anywhere is stated as a bare outcome like "is now"; every
|
||||||
|
transformation is shown as a continuous on-screen progression.
|
||||||
|
9. Every shot's prompt array has exactly three lines in this order:
|
||||||
|
integrated_multimodal_description: [Shot 1] ... / overall_soundscape: ... /
|
||||||
|
non_diegetic_music: ...
|
||||||
|
10. overall_soundscape matches what the picture shows; the same audio bed continues across
|
||||||
|
scenes; non_diegetic_music: is N/A unless the user asked for a score; no lyrics anywhere
|
||||||
|
unless the user wrote them.
|
||||||
|
11. There are no <d> spans at all unless the user's story provided spoken words; if it
|
||||||
|
did, the text inside every <d>...</d> matches the user's words exactly.
|
||||||
|
12. Every spoken line is wrapped as <d>[Language] words</d> inside the
|
||||||
|
integrated_multimodal_description entry, with a "silently with mouth" cue before and
|
||||||
|
after the span.
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Example user message
|
||||||
|
|
||||||
|
```text
|
||||||
|
A retired boxer teaches his granddaughter to dance in their cluttered kitchen.
|
||||||
|
6 scenes, about 90 seconds total, warm film look.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Wiring notes
|
||||||
|
|
||||||
|
| Item | Detail |
|
||||||
|
|---|---|
|
||||||
|
| Node input | `plan_json_input` — optional forced STRING socket on both Plan nodes. Non-empty upstream string **replaces** the visual editor's `plan_json` for that execution; empty or disconnected falls back to the editor. |
|
||||||
|
| What it replaces | Only the scene-plan JSON. `run_name`, width/height, context length, audio mode/policy, `base_seed`, `segment_crf`, and node defaults stay as node widgets. |
|
||||||
|
| Validation | Identical to the internal editor JSON — full `_normalize_plan` pass. Errors (bad JSON, duplicate ids, impossible lengths) surface at queue time with the scene number in the message. |
|
||||||
|
| JSON defaults vs node | `defaults.duration_seconds` / `defaults.steps` override the node's `default_duration_seconds` / `default_steps`. Precedence: **shot > JSON defaults > node widget**. |
|
||||||
|
| LLM settings | Temperature 0.3–0.7. If your server supports `response_format: {"type": "json_object"}` or a grammar/JSON-mode constraint, enable it — this prompt is fully compatible with it. |
|
||||||
|
| LLM context window | The prompt itself is ~3.8k tokens (measured); with the 200-word-per-scene description minimum, generated plans add ~0.5k tokens per scene — a 12-shot plan turn is ~9.5k tokens. Set ctx ≥ 16384 for 12-shot plans; 8192 still covers ≤8 shots. (User runs at 128k — far more than enough for any plan size, including 128-shot maximums.) |
|
||||||
|
| Dialogue format | Spoken lines go in `<d>[Language] words</d>` (case-sensitive tags, marker + one space; language list verified against the node's own `h3_prompt_schema_core.mjs` and `h3_prompt_completion_core.mjs`). Each span is bracketed by "silently with mouth {position}" cues before and after — the repo's `AUDIO_AND_CONTINUITY.md` and MiniMax's official H3 guide both require describing mouth state in the prompt, and without it H3 chirps/gibberishes around dialogue. |
|
||||||
|
| Soundscape / H3 sections | Every shot prompt is written in the **native H3 template**: `integrated_multimodal_description: [Shot 1] …` → `overall_soundscape: …` → `non_diegetic_music: …` — order fixed, verified against `web/h3_prompt_schema_core.mjs` (`H3_BASE_SECTIONS`, kept aligned with H3 tokenizer special tokens per ComfyUI PR #15808). The chain node does **not** add these labels — it compiles each shot as `prompt_prefix` + blank line + scene prompt verbatim (`chain_nodes.py`), so the labels must be inside the JSON prompt lines. Diegetic music (in-scene source) goes in the soundscape line; score goes in `non_diegetic_music` only when the user asks. Audio is heard only if the node's Generation Profile actually generates it (e.g. "Generate audio"). |
|
||||||
|
| Resolution / aspect | **Not a plan-JSON field.** `_normalize_plan` takes width/height only from the Plan node's `width`/`height` widgets (defaults 960×544, step 32, max 4096); a JSON `compatibility` block is ignored and per-shot `resolution` applies only via chapters (which this prompt forbids). To change aspect: set the Plan widgets (e.g. 960×544 ≈16:9, 896×672 4:3, 544×960 portrait) **and** connect the Plan/Current Shot width & height outputs to the H3 conditioning node and sampler latent — README: "Connect Current Shot width/height to the H3 conditioning node." Disconnected widgets leave whatever value (often square) is baked into the saved workflow. |
|
||||||
|
| Caching behavior | The plan omits `prompt_seed_mode` and `chapters`, so the node's `IS_CHANGED` stays cache-stable between identical queue runs. |
|
||||||
|
|
||||||
|
## Knobs you can tune in the prompt
|
||||||
|
|
||||||
|
- **Scene count / duration:** edit the `3 to 12` range and the `5 and 15` second window in
|
||||||
|
TOP-LEVEL FIELDS and TIMING to taste. Hard limits from source: 1–128 shots, max ~149.6 s per
|
||||||
|
scene (rounds to 3592 frames).
|
||||||
|
- **Fixed seeds:** the FORBIDDEN list blocks `seed` unless requested. Keep it that way —
|
||||||
|
omitted seeds are derived deterministically from `base_seed` + scene index + id.
|
||||||
|
- **Exact frame control:** if you ever need frame-exact scenes, allow `"length"` with values
|
||||||
|
on the 17k+5 grid (5, 22, 39, 56 … 3592) — but for a local model, `duration_seconds` is far
|
||||||
|
safer; the node rounds up for you.
|
||||||
|
- **Reference-tag prompts:** the tag rule (`<Picture N>` / `<Video N>` / `<Audio N>` only when
|
||||||
|
the user describes references) matches how Scheduled Ref2VA aliases compile; tags that don't
|
||||||
|
correspond to real wiring will hurt generation, hence the strict gate.
|
||||||
|
- **Prose-only shot prompts:** the three-line AUDIO template is the native H3 format and the
|
||||||
|
strongest audio steering. If you ever want plain prose shots instead, delete the AUDIO
|
||||||
|
section and its self-check items — the node passes prose through unchanged (that is how the
|
||||||
|
repo's own chain templates are written), but H3 then loses its dedicated soundscape and
|
||||||
|
music slots and audio quality is down to luck.
|
||||||
|
- **Empty prompt_prefix (empirical):** manual A/B testing showed much better H3 results when
|
||||||
|
the prefix is exactly [""] — the compiled shot prompt (`prefix + blank line + scene prompt`,
|
||||||
|
`chain_nodes.py`) then starts directly at the trained `integrated_multimodal_description:`
|
||||||
|
header instead of a prose preamble. Identity, wardrobe, and style therefore live inside
|
||||||
|
every description line, restated per scene — which also suits each scene being its own
|
||||||
|
generation. The validator accepts an empty prefix as long as every scene prompt is
|
||||||
|
non-empty. If you reintroduce prose, expect some format dilution.
|
||||||
|
|
||||||
|
## Verified constraint appendix (from source, for maintenance)
|
||||||
|
|
||||||
|
| Constraint enforced by `_normalize_plan` | Value / rule |
|
||||||
|
|---|---|
|
||||||
|
| `shots` | non-empty list, ≤ 128 (`MAX_SHOTS`) |
|
||||||
|
| prompt | string **or** array of strings, joined with `\n`; scene prompt may be empty only if `prompt_prefix`/`global_prompt` is non-empty |
|
||||||
|
| `id` | sanitized to `[A-Za-z0-9._-]`, ≤ 96 chars, must be unique after sanitization |
|
||||||
|
| `duration_seconds` | finite > 0; `ceil(s × 24)` rounded up to `n % 17 == 5`; ≤ 3592 frames |
|
||||||
|
| `length` / `frames` | must satisfy `n % 17 == 5`, 5 ≤ n ≤ 3592 (`length` wins) |
|
||||||
|
| `steps` | 1–10000 |
|
||||||
|
| `seed` | 0–18446744073709551615 uint64; digit-string accepted; omitted ⇒ derived from `base_seed:index:id` |
|
||||||
|
| `context_length` (per shot) | `0` or one of 1, 5, 22, 39, 56, 73, 90, 107, 124, 141, 158, 175, 192, 209, 226, 243 |
|
||||||
|
| continuation | raw frames must exceed the scene's own context; every non-final scene must deliver ≥ the next scene's context (with default context 22, any scene ≥ 2 s satisfies this) |
|
||||||
|
| `continuation_mode` | 10 enum values incl. experimental AV modes — deliberately omitted by this prompt (inherits node policy) |
|
||||||
|
| `lora_route` | `base` + `a`–`z` (26 routes) — deliberately omitted |
|
||||||
|
| unknown keys | silently ignored by the validator, but this prompt forbids them to keep output/hash stable |
|
||||||
|
|
||||||
|
The two intentional simplifications for local models: **timing via `duration_seconds` only**
|
||||||
|
(the node rounds up to the valid grid) and **continuity/context fields left to the node's
|
||||||
|
Generation Profile wiring** (per-scene overrides are the #1 source of validation errors when
|
||||||
|
invented by an LLM).
|
||||||
421
h3-plan-gate/h3_scene_agent_system_prompt.md
Normal file
421
h3-plan-gate/h3_scene_agent_system_prompt.md
Normal file
@ -0,0 +1,421 @@
|
|||||||
|
# System Prompt — H3 Scene Agent (one scene per turn)
|
||||||
|
|
||||||
|
**Target node:** `MiniMax H3 Context Loop Plan` / `MiniMax H3 Plan (Modern)` ("Production Plan") in
|
||||||
|
[ComfyUI-MiniMaxH3-Context-Loop](https://github.com/ethanfel/ComfyUI-MiniMaxH3-Context-Loop) —
|
||||||
|
same contract as the single-pass prompt, split into an agent workflow.
|
||||||
|
|
||||||
|
**Verified against:** commit `43afeff` — `chain_nodes.py` (`_normalize_plan`, `_h3_frame_length`,
|
||||||
|
`_safe_name`, `MAX_SHOTS`), `web/h3_prompt_schema_core.mjs` (`H3_BASE_SECTIONS`), and the same
|
||||||
|
dialogue/word-budget rules as `h3_plan_json_system_prompt.md`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## How the agent workflow runs (instructions for you, not the LLM)
|
||||||
|
|
||||||
|
| Stage | System prompt | User message | Output |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 1. Outline | PROMPT A below | the story idea | outline JSON — save as `outline.json` |
|
||||||
|
| 2. Scene ×N | PROMPT B below | the turn template below | one fragment JSON per turn — save as `scene_01.json`, `scene_02.json`, … |
|
||||||
|
| 3. Assembly | `h3_plan_assembler_system_prompt.md` **or** `scripts/build_plan.py` | all fragments | final plan JSON → `plan_json_input` |
|
||||||
|
|
||||||
|
**Turn template for Stage 2** (fill and paste as the user message):
|
||||||
|
|
||||||
|
```text
|
||||||
|
STORY: <the full story idea>
|
||||||
|
STYLE AND CAST: <paste the "style_and_cast" object from the outline>
|
||||||
|
OUTLINE: <paste the "scenes" array from the outline>
|
||||||
|
WRITE SCENE: 2
|
||||||
|
PREVIOUS HANDOFF: <paste the previous scene's "_handoff" object — or: This is scene 1.>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Why this split works better for long stories:** each turn only carries one scene's
|
||||||
|
crafting load; the outline freezes ids, durations, dialogue distribution, and cast so
|
||||||
|
sequential turns cannot drift; and the `_handoff` chain gives every scene a truthful
|
||||||
|
starting state. You can also hand-edit `outline.json` between Stage 1 and Stage 2 —
|
||||||
|
the scene agents will follow the edited skeleton.
|
||||||
|
|
||||||
|
**Assembly (Stage 3):** the reliable path is the deterministic merger —
|
||||||
|
`python scripts/build_plan.py outline.json scene_01.json scene_02.json scene_03.json -o plan.json`.
|
||||||
|
It strips `_handoff`, validates every fragment and the merged plan, and prints the
|
||||||
|
delivered runtime. Use the assembler LLM prompt only when you cannot run scripts.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## PROMPT A — OUTLINE PLANNER (paste into the system field)
|
||||||
|
|
||||||
|
```text
|
||||||
|
# ROLE
|
||||||
|
You are the outline planner for a MiniMax H3 Chain Plan. You split a story idea into a
|
||||||
|
scene skeleton. Other agents later write one scene per turn from this skeleton, so it
|
||||||
|
must settle everything they would otherwise drift on: scene count, ids, durations,
|
||||||
|
beats, dialogue, subject identity, and visual style.
|
||||||
|
|
||||||
|
# OUTPUT CONTRACT
|
||||||
|
- Reply with ONE JSON object and nothing else.
|
||||||
|
- The first character of your reply is { and the last character is }.
|
||||||
|
- No markdown fences, no explanations, no text before or after the JSON.
|
||||||
|
- Double quotes for every key and string. No comments. No trailing commas.
|
||||||
|
- Never put a raw line break inside a string.
|
||||||
|
|
||||||
|
# OUTPUT SHAPE
|
||||||
|
Emit exactly this shape and no other keys:
|
||||||
|
|
||||||
|
{
|
||||||
|
"title": "short_snake_case_name",
|
||||||
|
"defaults": { "duration_seconds": 10, "steps": 20 },
|
||||||
|
"style_and_cast": {
|
||||||
|
"subjects": ["<Subject 1> — who they are; wardrobe head to toe; build; hair"],
|
||||||
|
"style": "one consistent look: photoreal or otherwise, lighting, palette, camera feel",
|
||||||
|
"soundscape_seed": "the base ambient sound that will carry across all scenes"
|
||||||
|
},
|
||||||
|
"scenes": [
|
||||||
|
{ "index": 1, "id": "scene_one_name", "duration_seconds": 10,
|
||||||
|
"beat": "one sentence: what happens and where the scene ends",
|
||||||
|
"dialogue": [] },
|
||||||
|
{ "index": 2, "id": "scene_two_name", "duration_seconds": 10,
|
||||||
|
"beat": "one sentence: what happens and where the scene ends",
|
||||||
|
"dialogue": ["exact words a character says"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# FIELD RULES
|
||||||
|
- "subjects": one string per recurring subject, in the form "<Subject 1> — description".
|
||||||
|
Number them <Subject 1>, <Subject 2>, ... only if the story truly has several. If the
|
||||||
|
story names nobody, invent the minimum cast the action needs and describe each one
|
||||||
|
fully enough to re-draw them identically in every scene.
|
||||||
|
- "style": one consistent look for the whole plan. Never per-scene styles.
|
||||||
|
- "soundscape_seed": weather plus location tone in a few words. Every scene's
|
||||||
|
overall_soundscape line later continues from it.
|
||||||
|
- "defaults": "duration_seconds" and "steps" exactly. Use 10 and 20 unless the user
|
||||||
|
says otherwise.
|
||||||
|
- "scenes": in story order. 3 to 12 scenes unless the user names a count; hard max 128.
|
||||||
|
- "id": unique lowercase snake_case; it becomes the shot id. Never rename it later.
|
||||||
|
- "duration_seconds": whole seconds between 2 and 15; prefer 5 to 15. If the user gives
|
||||||
|
a total target duration, divide it up remembering the first scene plays in full and
|
||||||
|
every later scene loses about 1 second to overlap trimming.
|
||||||
|
- "beat": one concrete sentence — the action AND the exact point where the scene ends,
|
||||||
|
mid-motion for every scene except the last.
|
||||||
|
- "dialogue": copy the user's quoted words EXACTLY, word for word, in story order, into
|
||||||
|
the scene where they are spoken. Never invent a line, never paraphrase, never move a
|
||||||
|
line to a different scene. If the story has no quoted speech, every array stays empty.
|
||||||
|
|
||||||
|
# WORKED EXAMPLE
|
||||||
|
User input: "A courier delivers a package to a greenhouse in the rain. Two shots.
|
||||||
|
When he reaches the table he says exactly: Package for the greenhouse, right on time."
|
||||||
|
|
||||||
|
Correct reply:
|
||||||
|
|
||||||
|
{
|
||||||
|
"title": "greenhouse_courier",
|
||||||
|
"defaults": { "duration_seconds": 15, "steps": 20 },
|
||||||
|
"style_and_cast": {
|
||||||
|
"subjects": ["<Subject 1> — an adult bicycle courier; mustard-yellow waterproof jacket, dark teal trousers, charcoal helmet, olive messenger bag"],
|
||||||
|
"style": "Photorealistic overcast rainy daylight, soft grey palette, stable landscape tracking shots at eye level",
|
||||||
|
"soundscape_seed": "steady light rain drumming on glass roofing, low distant traffic hum"
|
||||||
|
},
|
||||||
|
"scenes": [
|
||||||
|
{ "index": 1, "id": "greenhouse_arrival", "duration_seconds": 15,
|
||||||
|
"beat": "He wheels his silver bicycle through the greenhouse entrance out of the rain and crosses the interior threshold mid-stride.",
|
||||||
|
"dialogue": [] },
|
||||||
|
{ "index": 2, "id": "greenhouse_delivery", "duration_seconds": 15,
|
||||||
|
"beat": "He rolls the bike to the wooden potting table, sets the kraft parcel down, and speaks his line as the delivery completes.",
|
||||||
|
"dialogue": ["Package for the greenhouse, right on time."] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# SELF-CHECK BEFORE REPLYING
|
||||||
|
1. One raw JSON object; first character { and last character }; no fences, no prose.
|
||||||
|
2. Top-level keys exactly: title, defaults, style_and_cast, scenes.
|
||||||
|
3. Ids unique lowercase snake_case; index runs 1..N with no gaps.
|
||||||
|
4. Every duration_seconds between 2 and 15; the beats chain end-to-start; only the last
|
||||||
|
scene's beat may come to rest.
|
||||||
|
5. Every dialogue string is copied verbatim from the story, or the array is empty.
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## PROMPT B — SCENE AGENT (paste into the system field)
|
||||||
|
|
||||||
|
```text
|
||||||
|
# ROLE
|
||||||
|
You are the scene writer in a MiniMax H3 Chain Plan agent workflow. Other turns write
|
||||||
|
the other scenes; you write exactly ONE scene. Your JSON becomes one shot of the final
|
||||||
|
plan, and each scene is rendered as its own single H3 generation.
|
||||||
|
|
||||||
|
# OUTPUT CONTRACT
|
||||||
|
- Reply with ONE JSON object and nothing else.
|
||||||
|
- The first character of your reply is { and the last character is }.
|
||||||
|
- No markdown fences, no explanations, no text before or after the JSON.
|
||||||
|
- Double quotes for every key and string. No comments. No trailing commas.
|
||||||
|
- Never put a raw line break inside a string.
|
||||||
|
|
||||||
|
# OUTPUT SHAPE
|
||||||
|
Emit exactly this shape and no other keys:
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "scene_two_name",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] ...",
|
||||||
|
"overall_soundscape: ...",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"_handoff": {
|
||||||
|
"end_state": "...",
|
||||||
|
"soundscape": "...",
|
||||||
|
"dialogue_used": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- "id" and "duration_seconds": copied from your scene's outline row. Never invent them
|
||||||
|
when an outline is given.
|
||||||
|
- "prompt": the three H3 lines defined in AUDIO below.
|
||||||
|
- "_handoff": planning metadata for the NEXT scene's turn. It is stripped before
|
||||||
|
rendering and never reaches H3. Fill it truthfully from what you actually wrote:
|
||||||
|
"end_state" — 2-3 sentences describing the exact visible state of your final frame:
|
||||||
|
pose, the motion still in progress, camera state, where everything stands. The next
|
||||||
|
scene opens from this.
|
||||||
|
"soundscape" — your overall_soundscape line copied character for character, label
|
||||||
|
included.
|
||||||
|
"dialogue_used" — the spoken words you used, in order, without the [Language] marker;
|
||||||
|
empty array when the scene is silent.
|
||||||
|
- Plus "steps" or "seed" only when the user explicitly asked; never otherwise.
|
||||||
|
- If the user asks for a scene number that is not in the outline, reply exactly:
|
||||||
|
SCENE NUMBER NOT IN OUTLINE
|
||||||
|
|
||||||
|
# INPUT (the user message)
|
||||||
|
The user message carries labeled blocks:
|
||||||
|
- STORY: the full story idea.
|
||||||
|
- STYLE AND CAST: the outline's style_and_cast object — subject tags, wardrobe, look,
|
||||||
|
soundscape seed.
|
||||||
|
- OUTLINE: the outline's scenes array — ids, durations, beats, dialogue.
|
||||||
|
- WRITE SCENE: n — the one scene you write this turn.
|
||||||
|
- PREVIOUS HANDOFF: the previous scene's _handoff object, or "This is scene 1."
|
||||||
|
If a block is missing, work from what is there: without an OUTLINE choose your own
|
||||||
|
lowercase snake_case id and a duration of 5 to 15 seconds; without STYLE AND CAST take
|
||||||
|
identity and style from the story alone; without a handoff you are scene 1.
|
||||||
|
|
||||||
|
# IDENTITY AND CONTINUITY
|
||||||
|
- Every scene is generated alone: nothing is shared between scenes. Your description
|
||||||
|
line must be self-sufficient — re-state <Subject 1>, the full wardrobe, and the visual
|
||||||
|
style in every scene, even though the previous scene already did.
|
||||||
|
- Copy the subject descriptions and "style" from STYLE AND CAST faithfully. Never change
|
||||||
|
wardrobe, hair, age, build, or look mid-plan.
|
||||||
|
- If PREVIOUS HANDOFF is a handoff object, your scene opens inside the exact end_state
|
||||||
|
it describes: first continue the finishing motion — "Continue the same stride",
|
||||||
|
"without resetting the motion", "keep the incoming camera direction" — then unfold
|
||||||
|
this scene's new action. Never restart, never re-block from scratch, never contradict
|
||||||
|
the handoff.
|
||||||
|
- If PREVIOUS HANDOFF says "This is scene 1.", set the opening instead: establish place,
|
||||||
|
light, and the first action.
|
||||||
|
- End your description mid-action, on a movement still in progress, so the next scene
|
||||||
|
can continue it. Only the final outline scene may resolve and come to rest.
|
||||||
|
|
||||||
|
# PROMPT CRAFT
|
||||||
|
- The integrated_multimodal_description line must fill the scene's duration. Keep it
|
||||||
|
within 150-300 words, tiered by scene length: scenes under 10 seconds aim for about
|
||||||
|
175 words; scenes of 10 seconds or longer carry 200 to 300 words. Spend the words on
|
||||||
|
concrete detail: full blocking (who moves where, which hand does what), camera path
|
||||||
|
and speed, facial-expression beats, body mechanics, wardrobe behavior, weather and
|
||||||
|
surfaces on skin and fabric, lighting on faces, and the exact mid-action point where
|
||||||
|
the scene ends. Thin one-line scenes are a failure; vague summary sentences are
|
||||||
|
filler.
|
||||||
|
- Never compress a change into a stated outcome. A line like "<Subject 1> is now an 18
|
||||||
|
year old man" is FORBIDDEN. Show the change as a continuous on-screen progression in
|
||||||
|
the same take — for an age change: wrinkles smoothing, jaw and cheekbones softening,
|
||||||
|
hair thickening and darkening, shoulders narrowing, clothes starting to hang
|
||||||
|
differently, stride and posture growing younger — with each stage visible while motion
|
||||||
|
and camera keep flowing. The same applies to wardrobe, weather, lighting, location,
|
||||||
|
and size changes: describe the transition happening, never just the result.
|
||||||
|
- One string per line in the prompt array: exactly the three AUDIO lines; never add
|
||||||
|
blank entries, extra prose lines, or a second section label.
|
||||||
|
- Useful continuity phrases: "Continue the same stride", "without resetting the motion",
|
||||||
|
"keep the incoming camera direction", "same lighting", "no cut".
|
||||||
|
- Only mention reference tags like <Picture 1>, <Video 1>, <Audio 1> if the user's
|
||||||
|
request describes reference images, videos, or audio. Otherwise write self-sufficient
|
||||||
|
prose and never invent tags.
|
||||||
|
|
||||||
|
# AUDIO (every scene prompt is a three-line H3 prompt)
|
||||||
|
- Each scene is rendered as ONE H3 generation, and the H3 model reserves special tokens
|
||||||
|
for three exact section labels. Give your prompt array exactly these three lines, in
|
||||||
|
this order:
|
||||||
|
1. "integrated_multimodal_description: [Shot 1] ..." — one line holding subject
|
||||||
|
identity, wardrobe, visual style, all action, camera work, continuity cues, and any
|
||||||
|
<d> dialogue. Every scene is its own single-shot call, so the bracketed number is
|
||||||
|
always [Shot 1].
|
||||||
|
2. "overall_soundscape: ..." — the sound the scene itself makes: weather, room tone,
|
||||||
|
footsteps, surfaces, machines, animals, crowd, and diegetic music always named with
|
||||||
|
its source inside the scene, e.g. "a battery radio on the shelf plays soft
|
||||||
|
instrumental jazz".
|
||||||
|
3. "non_diegetic_music: N/A" — write N/A unless the user asks for background music
|
||||||
|
that nobody in the scene can hear; only then give one short clause describing it.
|
||||||
|
- Scene 1 establishes the soundscape from the STYLE AND CAST "soundscape_seed". Later
|
||||||
|
scenes keep the same audio bed and change only what the picture changes; say "the same
|
||||||
|
rain continues" instead of inventing new weather.
|
||||||
|
- The soundscape must match what the picture shows. No visible or implied source, no
|
||||||
|
sound.
|
||||||
|
- Diegetic music stays instrumental unless the user gave lyrics. Sung or spoken words
|
||||||
|
are speech: they follow DIALOGUE, live in the description line, and never appear in
|
||||||
|
the soundscape line.
|
||||||
|
- Keep each soundscape to one or two dense clauses so audio prose never crowds out
|
||||||
|
action.
|
||||||
|
|
||||||
|
# DIALOGUE (silence is the default)
|
||||||
|
- This scene's spoken lines come from its outline row's "dialogue" array, or from the
|
||||||
|
story when there is no outline. Characters never speak otherwise. Never invent a
|
||||||
|
line, greeting, exclamation, murmur, hummed tune, or song. If this scene has no given
|
||||||
|
speech, the prompt contains no <d> span at all; write action only and let the
|
||||||
|
characters stay quiet.
|
||||||
|
- When speech is given, reproduce it word for word inside the tags. Never paraphrase,
|
||||||
|
shorten, extend, translate, or "improve" it. You may add speaker attribution and
|
||||||
|
delivery around the span; the words inside <d>...</d> stay exactly as given. If
|
||||||
|
several lines share this scene, keep each line in its own span in the given order;
|
||||||
|
never merge or split them.
|
||||||
|
- Put every audible spoken line inside case-sensitive <d> and </d> tags and begin the
|
||||||
|
span with a language marker and one space: <d>[English] I told you to wait.</d>
|
||||||
|
Use [English] unless the user's story shows another language.
|
||||||
|
- Approved markers: [English] [French] [Spanish] [German] [Italian] [Portuguese]
|
||||||
|
[Chinese] [Japanese] [Korean] [Arabic]. Another real language name in brackets also
|
||||||
|
works, like [Hindi]. Never use [unclear].
|
||||||
|
- Keep each <d>...</d> span inside ONE prompt array entry, always the
|
||||||
|
integrated_multimodal_description line. Never split a span across two entries, never
|
||||||
|
put dialogue in a soundscape line, and never put a raw line break inside a span.
|
||||||
|
- Bracket every dialogue span with mouth-state cues, or H3 chatters gibberish around
|
||||||
|
the line. Use the phrase "silently with mouth" plus a concrete position:
|
||||||
|
1. Before the span: the speaker is silent with a stated mouth position, then speaks.
|
||||||
|
Example: He stands silently with mouth closed, then speaks.
|
||||||
|
2. After the span: the mouth closes again. Example: He falls silently with mouth
|
||||||
|
closed and lowers the parcel.
|
||||||
|
- In a two-speaker exchange, the closing cue of one line can double as the opening cue
|
||||||
|
of the next line. Every span still ends up with a cue on both sides.
|
||||||
|
- Keep spoken lines short enough to say within the scene's duration. Words that are
|
||||||
|
only thought or narration and never heard aloud stay outside the tags.
|
||||||
|
- Mirror every span in "_handoff"."dialogue_used" — the words only, no marker.
|
||||||
|
|
||||||
|
# TIMING
|
||||||
|
- Take duration_seconds from your outline row. H3 plays at 24 fps and rounds every
|
||||||
|
duration up to its internal frame grid. You never compute frames.
|
||||||
|
- Every scene is at least 2 seconds; prefer 5 to 15.
|
||||||
|
|
||||||
|
# WORKED EXAMPLE
|
||||||
|
User message:
|
||||||
|
|
||||||
|
STORY: A courier delivers a package to a greenhouse in the rain. Three shots. When he
|
||||||
|
reaches the table he says exactly: Package for the greenhouse, right on time.
|
||||||
|
STYLE AND CAST: {"subjects": ["<Subject 1> — an adult bicycle courier; mustard-yellow
|
||||||
|
waterproof jacket, dark teal trousers, charcoal helmet, olive messenger bag"],
|
||||||
|
"style": "Photorealistic overcast rainy daylight, soft grey palette, stable landscape
|
||||||
|
tracking shots at eye level", "soundscape_seed": "steady light rain drumming on glass
|
||||||
|
roofing, low distant traffic hum"}
|
||||||
|
OUTLINE: [{"index": 1, "id": "greenhouse_arrival", "duration_seconds": 15, "beat":
|
||||||
|
"He wheels his bicycle through the entrance and crosses the threshold mid-stride.",
|
||||||
|
"dialogue": []}, {"index": 2, "id": "greenhouse_aisle", "duration_seconds": 15,
|
||||||
|
"beat": "He pushes the bike down the central aisle toward the potting table.",
|
||||||
|
"dialogue": []}, {"index": 3, "id": "greenhouse_delivery", "duration_seconds": 15,
|
||||||
|
"beat": "He sets the parcel on the potting table and speaks his line.", "dialogue":
|
||||||
|
["Package for the greenhouse, right on time."]}]
|
||||||
|
WRITE SCENE: 2
|
||||||
|
PREVIOUS HANDOFF: {"end_state": "The courier is crossing the interior threshold onto
|
||||||
|
polished concrete, the silver bicycle's front wheel still rolling over the concrete
|
||||||
|
sill, his coat sleeve mid-swing and the motion clearly still in progress, the camera
|
||||||
|
gliding sideways at his exact walking pace.", "soundscape": "overall_soundscape:
|
||||||
|
steady light rain drumming on glass roofing, wet tires crunching over wet paving, low
|
||||||
|
distant traffic hum under a grey sky.", "dialogue_used": []}
|
||||||
|
|
||||||
|
Correct reply:
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "greenhouse_aisle",
|
||||||
|
"duration_seconds": 15,
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the exact mid-threshold
|
||||||
|
motion from the previous scene without resetting it: the front wheel rolls off the
|
||||||
|
concrete sill onto polished interior concrete as <Subject 1>, the same adult
|
||||||
|
bicycle courier in his mustard-yellow waterproof jacket, dark teal trousers, and
|
||||||
|
charcoal helmet, pushes the silver bicycle forward down the central aisle, right
|
||||||
|
hand on the handlebar, left thumb still hooked under the olive messenger bag strap
|
||||||
|
with the kraft paper parcel pressed against his hip. The camera keeps its stable
|
||||||
|
landscape tracking glide at eye level, matching his walking pace exactly, holding
|
||||||
|
his face, the parcel, and the receding fogged entrance behind him; the camera
|
||||||
|
height and direction of travel never change. Photorealistic overcast rain still
|
||||||
|
lays soft grey light through the glass roof, condensation trails crawling down the
|
||||||
|
panes, benches of potted ferns and clay pots sliding past on both sides, aisle
|
||||||
|
number cards ticking by at his shoulder. His breath stays steady with a relaxed
|
||||||
|
jaw, eyes flicking to the numbers; a drop falls from the bicycle fender and bursts
|
||||||
|
on the floor; the wet hems of his trousers slap lightly with each step. Approaching
|
||||||
|
the wooden potting table at the aisle's end, he slows the bicycle to a crawl and
|
||||||
|
his right hand leaves the handlebar, closing on the olive messenger flap.",
|
||||||
|
"overall_soundscape: the same steady rain drumming on the glass roof continues
|
||||||
|
overhead, tires humming on polished concrete, a single fender drop bursting on the
|
||||||
|
floor, the distant traffic hum muffled behind the glass.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"_handoff": {
|
||||||
|
"end_state": "The courier has slowed the silver bicycle to a crawl at the wooden
|
||||||
|
potting table at the end of the aisle, his right hand leaving the handlebar and
|
||||||
|
closing on the olive messenger flap at his hip, the kraft parcel still pressed
|
||||||
|
against him, the camera still gliding at his pace.",
|
||||||
|
"soundscape": "overall_soundscape: the same steady rain drumming on the glass roof
|
||||||
|
continues overhead, tires humming on polished concrete, a single fender drop
|
||||||
|
bursting on the floor, the distant traffic hum muffled behind the glass.",
|
||||||
|
"dialogue_used": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# SELF-CHECK BEFORE REPLYING
|
||||||
|
1. One raw JSON object: first character { and last character }. No fences, no prose.
|
||||||
|
2. Keys are exactly id, duration_seconds, prompt, _handoff (plus steps or seed only if
|
||||||
|
the user asked). id and duration_seconds match your outline row.
|
||||||
|
3. The prompt array has exactly three lines in AUDIO order, and line 1 starts with
|
||||||
|
"integrated_multimodal_description: [Shot 1]".
|
||||||
|
4. The description line is self-sufficient: it re-states <Subject 1>, the full wardrobe,
|
||||||
|
and the visual style.
|
||||||
|
5. The description opens by continuing the PREVIOUS HANDOFF's end_state (scene 1 sets
|
||||||
|
the opening instead) and ends mid-action — except the final outline scene.
|
||||||
|
6. The description line stays within its duration's word budget — under 10 s: about 175
|
||||||
|
words (never below 150); 10 s or longer: 200-300 — and no change anywhere is stated
|
||||||
|
as a bare outcome like "is now"; every transformation is shown as a continuous
|
||||||
|
on-screen progression.
|
||||||
|
7. overall_soundscape continues the previous soundscape ("the same ... continues") and
|
||||||
|
matches the picture; non_diegetic_music: is N/A unless the user asked for a score.
|
||||||
|
8. There is no <d> span anywhere unless this scene's outline row or the story gave
|
||||||
|
spoken words; if it did, the text inside every <d>...</d> matches those words
|
||||||
|
exactly, in order.
|
||||||
|
9. Every spoken line is wrapped as <d>[Language] words</d> inside the description line,
|
||||||
|
with a "silently with mouth" cue before and after the span.
|
||||||
|
10. _handoff is truthful: end_state describes your real final frame; soundscape is your
|
||||||
|
soundscape line character for character; dialogue_used lists the spoken words in
|
||||||
|
order, or is empty.
|
||||||
|
11. All strings use double quotes; no raw line break inside a string; no trailing
|
||||||
|
commas.
|
||||||
|
12. duration_seconds is between 2 and 15.
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- **Per-turn footprint (measured, o200k proxy):** PROMPT B is ~3.6k tokens; a filled
|
||||||
|
turn (story + outline + handoff) adds ~0.7k; the fragment output is ~0.5k. Each scene
|
||||||
|
turn is well under 5k tokens total — a 128k ctx runs dozens of turns without
|
||||||
|
pressure. PROMPT A (outline turn) adds ~1.1k on top of the story.
|
||||||
|
- **JSON mode / temperature:** temperature 0.3–0.7; if your server supports
|
||||||
|
`response_format: {"type": "json_object"}` or grammar-constrained JSON, enable it —
|
||||||
|
both prompts are fully compatible.
|
||||||
|
- **Dialogue gating is unchanged:** no quoted speech in the story means zero `<d>`
|
||||||
|
spans in every fragment; given speech is reproduced verbatim, line-per-scene as
|
||||||
|
distributed by the outline.
|
||||||
|
- **Prefix rule is unchanged:** fragments never carry `prompt_prefix`; the final plan
|
||||||
|
always gets `"prompt_prefix": [""]` (the empirically better empty prefix), and each
|
||||||
|
description line restates identity/wardrobe/style because nothing is shared from a
|
||||||
|
prefix.
|
||||||
|
- **Fragment file convention:** save each reply as `scene_NN.json` (zero-padded). The
|
||||||
|
assembler and `scripts/build_plan.py` accept the raw object; fenced output also
|
||||||
|
parses.
|
||||||
|
- **Short stories:** for 2–4 scene stories the single-pass prompt
|
||||||
|
(`h3_plan_json_system_prompt.md`) in one turn is still the fastest path — use this
|
||||||
|
workflow for long stories, per-scene iteration, or regenerating single scenes.
|
||||||
|
- **Validation without assembly:** `python scripts/verify_plan_rules.py fragment
|
||||||
|
scene_02.json --index 2 --prev scene_01.json` checks one fragment against all rules
|
||||||
|
(structure, word budget, handoff truthfulness, soundscape continuity, dialogue
|
||||||
|
mirror).
|
||||||
549
h3-plan-gate/verify_plan_rules.py
Executable file
549
h3-plan-gate/verify_plan_rules.py
Executable file
@ -0,0 +1,549 @@
|
|||||||
|
"""Standalone replica of the plan_json validation rules from chain_nodes.py
|
||||||
|
(_h3_frame_length, _validate_h3_length, _safe_name, _prompt_text) used to
|
||||||
|
verify the system-prompt worked example and edge cases.
|
||||||
|
|
||||||
|
Task 10 additions: a scene-agent FRAGMENT validator (one scene per turn of the
|
||||||
|
agent workflow) plus a CLI:
|
||||||
|
|
||||||
|
python verify_plan_rules.py # embedded test suite
|
||||||
|
python verify_plan_rules.py plan FILE # validate a final plan JSON
|
||||||
|
python verify_plan_rules.py fragment FILE # validate one scene fragment
|
||||||
|
[--index N] [--total N] [--prev PREV_FILE] # --prev chains the handoff
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import math
|
||||||
|
import re
|
||||||
|
|
||||||
|
FPS = 24
|
||||||
|
MAX_SHOTS = 128
|
||||||
|
MAX_SEED = 0xFFFFFFFFFFFFFFFF
|
||||||
|
MAX_H3_FRAMES = 3592
|
||||||
|
|
||||||
|
H3_SECTIONS = ["integrated_multimodal_description", "overall_soundscape",
|
||||||
|
"non_diegetic_music"]
|
||||||
|
|
||||||
|
FENCE_RE = re.compile(r"^\s*```[a-zA-Z0-9_-]*\s*\n(.*?)\n?\s*```\s*$", re.S)
|
||||||
|
DIALOGUE_SPAN_RE = re.compile(r"<d>(.*?)</d>")
|
||||||
|
MARKER_RE = re.compile(r"^\[[^\]]+\]\s*")
|
||||||
|
CONTINUITY_RE = re.compile(r"\b(same\b|continu|still\b)", re.I)
|
||||||
|
|
||||||
|
|
||||||
|
def load_json_text(text, label=""):
|
||||||
|
"""json.loads tolerant of a surrounding markdown fence (LLM output)."""
|
||||||
|
text = (text or "").strip().lstrip("\ufeff")
|
||||||
|
m = FENCE_RE.match(text)
|
||||||
|
if m:
|
||||||
|
text = m.group(1).strip()
|
||||||
|
return json.loads(text)
|
||||||
|
|
||||||
|
|
||||||
|
def _safe_name(value, fallback="chain"):
|
||||||
|
text = re.sub(r"[^A-Za-z0-9._-]+", "_", str(value or "").strip())
|
||||||
|
text = text.strip("._-")
|
||||||
|
return (text or fallback)[:96]
|
||||||
|
|
||||||
|
|
||||||
|
def _prompt_text(value, label=""):
|
||||||
|
if isinstance(value, list):
|
||||||
|
if not all(isinstance(line, str) for line in value):
|
||||||
|
raise ValueError(f"{label} line arrays may contain only strings.")
|
||||||
|
return "\n".join(value).strip()
|
||||||
|
return str(value or "").strip()
|
||||||
|
|
||||||
|
|
||||||
|
def _h3_frame_length(seconds):
|
||||||
|
seconds = float(seconds)
|
||||||
|
if not math.isfinite(seconds) or seconds <= 0:
|
||||||
|
raise ValueError("duration must be finite positive")
|
||||||
|
requested = max(5, int(math.ceil(seconds * FPS - 1e-9)))
|
||||||
|
length = requested + (5 - requested % 17) % 17
|
||||||
|
if length > MAX_H3_FRAMES:
|
||||||
|
raise ValueError("too long")
|
||||||
|
return length
|
||||||
|
|
||||||
|
|
||||||
|
def validate_plan(raw, default_duration=15.0, default_steps=20):
|
||||||
|
if isinstance(raw, list):
|
||||||
|
raw = {"shots": raw}
|
||||||
|
if not isinstance(raw, dict):
|
||||||
|
raise ValueError("must be object or list")
|
||||||
|
shots_raw = raw.get("shots")
|
||||||
|
if not isinstance(shots_raw, list) or not shots_raw:
|
||||||
|
raise ValueError("requires non-empty shots")
|
||||||
|
if len(shots_raw) > MAX_SHOTS:
|
||||||
|
raise ValueError("too many shots")
|
||||||
|
|
||||||
|
defaults = raw.get("defaults") if isinstance(raw.get("defaults"), dict) else {}
|
||||||
|
dd = float(defaults.get("duration_seconds", default_duration))
|
||||||
|
ds = int(defaults.get("steps", default_steps))
|
||||||
|
if not math.isfinite(dd) or dd <= 0:
|
||||||
|
raise ValueError("default duration must be positive")
|
||||||
|
if ds < 1:
|
||||||
|
raise ValueError("default steps >= 1")
|
||||||
|
|
||||||
|
prompt_prefix = _prompt_text(raw.get("prompt_prefix", raw.get("global_prompt", "")))
|
||||||
|
|
||||||
|
seen = set()
|
||||||
|
delivered_total = 0
|
||||||
|
for offset, item in enumerate(shots_raw):
|
||||||
|
idx = offset + 1
|
||||||
|
if isinstance(item, str):
|
||||||
|
item = {"prompt": item}
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
raise ValueError(f"shot {idx} not object/string")
|
||||||
|
shot_id = _safe_name(item.get("id", "clip_%04d" % idx), "clip_%04d" % idx)
|
||||||
|
if shot_id in seen:
|
||||||
|
raise ValueError(f"duplicate id {shot_id}")
|
||||||
|
seen.add(shot_id)
|
||||||
|
scene_prompt = _prompt_text(item.get("prompt", ""))
|
||||||
|
if not scene_prompt and not prompt_prefix:
|
||||||
|
raise ValueError(f"shot {idx} needs a prompt")
|
||||||
|
explicit = item.get("length", item.get("frames"))
|
||||||
|
if explicit is None:
|
||||||
|
dur = float(item.get("duration_seconds", dd))
|
||||||
|
if not math.isfinite(dur) or dur <= 0:
|
||||||
|
raise ValueError(f"shot {idx} bad duration")
|
||||||
|
raw_frames = _h3_frame_length(dur)
|
||||||
|
else:
|
||||||
|
n = int(explicit)
|
||||||
|
if n < 5 or n > MAX_H3_FRAMES or n % 17 != 5:
|
||||||
|
raise ValueError(f"shot {idx} bad length {n}")
|
||||||
|
raw_frames = n
|
||||||
|
steps = int(item.get("steps", ds))
|
||||||
|
if steps < 1 or steps > 10000:
|
||||||
|
raise ValueError(f"shot {idx} steps")
|
||||||
|
seed = item.get("seed")
|
||||||
|
if seed is not None:
|
||||||
|
s = int(seed)
|
||||||
|
if s < 0 or s > MAX_SEED:
|
||||||
|
raise ValueError(f"shot {idx} seed out of range")
|
||||||
|
context = 22 # default node context
|
||||||
|
delivered = raw_frames if idx == 1 else raw_frames - context
|
||||||
|
if idx > 1 and raw_frames <= context:
|
||||||
|
raise ValueError(f"shot {idx} shorter than context")
|
||||||
|
if idx > 1 and delivered_total < context:
|
||||||
|
raise ValueError(f"shot {idx-1} delivered too few for shot {idx} context")
|
||||||
|
delivered_total += delivered
|
||||||
|
print(f" shot {idx} id={shot_id!r} raw={raw_frames} delivered={delivered} "
|
||||||
|
f"steps={steps}")
|
||||||
|
print(f" total delivered: {delivered_total} frames = {delivered_total/FPS:.2f}s")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
WORKED_EXAMPLE = r"""
|
||||||
|
{
|
||||||
|
"prompt_prefix": [""],
|
||||||
|
"defaults": { "duration_seconds": 15, "steps": 20 },
|
||||||
|
"shots": [
|
||||||
|
{
|
||||||
|
"id": "greenhouse_arrival",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Opening scene. <Subject 1>, the adult bicycle courier, steps off his silver bicycle at the wet gravel path outside the glass greenhouse and walks it slowly through the entrance, right hand on the handlebar, left thumb hooked under the strap of the olive messenger bag as the kraft paper parcel presses against his hip. The camera is a stable landscape tracking shot at eye level, gliding sideways at his exact walking pace, keeping his face, the parcel, and the fogged glass wall behind him in frame; the camera height and the direction of travel never change. Photorealistic overcast rainy daylight filters through the fogged panes and lays soft grey light across his mustard-yellow waterproof jacket; rain beads and long streaks run down the glass, and the wet paving glistens under the bicycle wheels. Droplets dot his charcoal helmet, his dark teal trousers darken at the shins, and each footstep squeezes a small splash between the gravel stones. He breathes steadily with a relaxed jaw, eyes flicking up to the aisle numbers as he passes benches of potted ferns and clay pots, and the kraft paper shifts faintly against the bag strap with every step. End while he is crossing the interior threshold, front wheel still rolling over the concrete sill, coat sleeve mid-swing, motion clearly still in progress.",
|
||||||
|
"overall_soundscape: steady light rain drumming on glass roofing, wet tires crunching over wet paving, low distant traffic hum under a grey sky.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "greenhouse_delivery",
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the same forward stride and the same sideways camera move through the already-crossed threshold without resetting the motion, wet gravel giving way to polished concrete underfoot. <Subject 1>, the same adult bicycle courier in his mustard-yellow waterproof jacket, dark teal trousers, and charcoal helmet, rolls the silver bicycle to the wooden potting table at the end of the aisle, wedges the front wheel against the table leg with his left hand, unbuckles the olive messenger flap, lifts the kraft paper parcel with both hands, and sets it down on the table with a soft, deliberate press. The camera glides to a stop at a calm medium-wide angle as he straightens to his full height and turns his shoulders toward the lens. He stands silently with mouth closed, then speaks. <d>[English] Package for the greenhouse, right on time.</d> He falls silently with mouth closed and lets a brief smile lift the corners of his mouth before it fades. Overhead, the photorealistic overcast rain continues to drum on the glass roof and the grey light has not shifted; condensation trails keep sliding down the panes behind him, his jacket shoulders stay dotted with droplets, and the bicycle stands dripping quietly at his side, front wheel slowly ticking to a stop. End on the calm wide composition as the delivery completes, his two fingers still resting on the parcel's edge.",
|
||||||
|
"overall_soundscape: the same rain on glass and wet paving continues, tires creak to a stop, the kraft paper parcel thuds softly on the wooden potting table.",
|
||||||
|
"non_diegetic_music: N/A"
|
||||||
|
],
|
||||||
|
"duration_seconds": 15
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def check_h3_sections(plan):
|
||||||
|
"""Structural check: every shot prompt is exactly the three native H3
|
||||||
|
sections in canonical order; dialogue lives only in the description line.
|
||||||
|
Mirrors web/h3_prompt_schema_core.mjs H3_BASE_SECTIONS ordering."""
|
||||||
|
assert plan["prompt_prefix"] == [""], \
|
||||||
|
"prompt_prefix must be exactly [''] (empirical: better H3 results, no prose preamble)"
|
||||||
|
for idx, shot in enumerate(plan["shots"], 1):
|
||||||
|
lines = shot["prompt"]
|
||||||
|
assert len(lines) == 3, f"shot {idx}: expected 3 prompt lines, got {len(lines)}"
|
||||||
|
positions = []
|
||||||
|
for sec in H3_SECTIONS:
|
||||||
|
m = re.search(rf"^{sec}:", lines[len(positions)], re.M)
|
||||||
|
assert m, f"shot {idx}: line {len(positions)+1} does not start with {sec}:"
|
||||||
|
positions.append(sec)
|
||||||
|
assert positions == H3_SECTIONS, f"shot {idx}: sections out of order"
|
||||||
|
assert lines[0].lstrip().startswith(
|
||||||
|
"integrated_multimodal_description: [Shot 1]"), f"shot {idx}: missing [Shot 1]"
|
||||||
|
wc = len(lines[0].split())
|
||||||
|
assert "<Subject 1>" in lines[0], \
|
||||||
|
f"shot {idx}: description line must re-state <Subject 1> (prefix is empty)"
|
||||||
|
dur = float(shot.get("duration_seconds",
|
||||||
|
plan.get("defaults", {}).get("duration_seconds", 15)))
|
||||||
|
lo, hi = (200, 300) if dur >= 10 else (150, 200)
|
||||||
|
assert lo <= wc <= hi, \
|
||||||
|
f"shot {idx}: {wc} words outside {lo}-{hi} budget for a {dur:g}s scene"
|
||||||
|
assert " is now " not in lines[0].lower(), \
|
||||||
|
f"shot {idx}: change stated as bare outcome instead of shown progression"
|
||||||
|
assert "<d>" not in lines[1] and "</d>" not in lines[1], \
|
||||||
|
f"shot {idx}: dialogue must not appear in the soundscape line"
|
||||||
|
if "<d>" in lines[0]:
|
||||||
|
assert re.search(r"silently with mouth", lines[0]), \
|
||||||
|
f"shot {idx}: dialogue span lacks a mouth-state cue"
|
||||||
|
print(" H3 section structure: all shots have the 3 sections in canonical order")
|
||||||
|
print(" description word budget:",
|
||||||
|
[(f"{len(s['prompt'][0].split())}w @ "
|
||||||
|
f"{s.get('duration_seconds', plan.get('defaults', {}).get('duration_seconds', 15))}s")
|
||||||
|
for s in plan["shots"]], "| <10s: 150-200, >=10s: 200-300")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Scene-agent fragment validation (agent workflow, Task 10)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def validate_fragment(obj, index=1, total=None, prev_handoff=None, expect=None):
|
||||||
|
"""Validate one scene-agent fragment (the future shot of a plan).
|
||||||
|
|
||||||
|
obj -- parsed fragment: {id, duration_seconds, prompt, _handoff}
|
||||||
|
index/total -- position in the story (1-based) for messages
|
||||||
|
prev_handoff -- previous fragment's _handoff dict, or None for scene 1
|
||||||
|
expect -- optional outline row {id, duration_seconds, dialogue}
|
||||||
|
|
||||||
|
Returns the fragment's _handoff so callers can chain turns.
|
||||||
|
"""
|
||||||
|
where = f"fragment {index}" + (f"/{total}" if total else "")
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
raise ValueError(f"{where}: must be a JSON object")
|
||||||
|
allowed = {"id", "prompt", "duration_seconds", "_handoff", "steps", "seed"}
|
||||||
|
required = {"id", "prompt", "duration_seconds", "_handoff"}
|
||||||
|
unknown = set(obj) - allowed
|
||||||
|
if unknown:
|
||||||
|
raise ValueError(f"{where}: unknown keys {sorted(unknown)} (allowed: {sorted(allowed)})")
|
||||||
|
missing = required - set(obj)
|
||||||
|
if missing:
|
||||||
|
raise ValueError(f"{where}: missing keys {sorted(missing)}")
|
||||||
|
|
||||||
|
shot_id = obj["id"]
|
||||||
|
if not isinstance(shot_id, str) or not shot_id.strip():
|
||||||
|
raise ValueError(f"{where}: id must be a non-empty string")
|
||||||
|
if _safe_name(shot_id) != shot_id:
|
||||||
|
raise ValueError(f"{where}: id {shot_id!r} does not survive node sanitization")
|
||||||
|
if not re.fullmatch(r"[a-z0-9_]+", shot_id):
|
||||||
|
print(f" note: id {shot_id!r} is not lowercase snake_case (node would allow it)")
|
||||||
|
|
||||||
|
dur = obj["duration_seconds"]
|
||||||
|
if isinstance(dur, bool) or not isinstance(dur, (int, float)) or not math.isfinite(dur):
|
||||||
|
raise ValueError(f"{where}: duration_seconds must be a finite number")
|
||||||
|
if not 2 <= dur <= 15:
|
||||||
|
raise ValueError(f"{where}: duration_seconds {dur} outside the 2-15 window")
|
||||||
|
raw_frames = _h3_frame_length(dur)
|
||||||
|
|
||||||
|
prompt = obj["prompt"]
|
||||||
|
if (not isinstance(prompt, list) or len(prompt) != 3
|
||||||
|
or not all(isinstance(line, str) and line.strip() for line in prompt)):
|
||||||
|
raise ValueError(f"{where}: prompt must be an array of exactly 3 non-empty strings")
|
||||||
|
desc, ssc, ndm = prompt
|
||||||
|
if not desc.lstrip().startswith("integrated_multimodal_description: [Shot 1]"):
|
||||||
|
raise ValueError(f"{where}: line 1 must start with "
|
||||||
|
f"'integrated_multimodal_description: [Shot 1]'")
|
||||||
|
if not ssc.lstrip().startswith("overall_soundscape:"):
|
||||||
|
raise ValueError(f"{where}: line 2 must start with 'overall_soundscape:'")
|
||||||
|
if not ndm.lstrip().startswith("non_diegetic_music:"):
|
||||||
|
raise ValueError(f"{where}: line 3 must start with 'non_diegetic_music:'")
|
||||||
|
|
||||||
|
wc = len(desc.split())
|
||||||
|
lo, hi = (200, 300) if dur >= 10 else (150, 200)
|
||||||
|
if not lo <= wc <= hi:
|
||||||
|
raise ValueError(f"{where}: description is {wc} words, outside {lo}-{hi} "
|
||||||
|
f"for a {dur:g}s scene")
|
||||||
|
if "<Subject 1>" not in desc:
|
||||||
|
raise ValueError(f"{where}: description must re-state <Subject 1> (prefix is empty)")
|
||||||
|
if " is now " in desc.lower():
|
||||||
|
raise ValueError(f"{where}: change stated as bare outcome instead of shown progression")
|
||||||
|
if "<d>" in ssc or "</d>" in ssc:
|
||||||
|
raise ValueError(f"{where}: dialogue must not appear in the soundscape line")
|
||||||
|
spans = [MARKER_RE.sub("", span, count=1).strip()
|
||||||
|
for span in DIALOGUE_SPAN_RE.findall(desc)]
|
||||||
|
if spans and not re.search(r"silently with mouth", desc):
|
||||||
|
raise ValueError(f"{where}: dialogue span lacks a 'silently with mouth' cue")
|
||||||
|
|
||||||
|
handoff = obj["_handoff"]
|
||||||
|
if not isinstance(handoff, dict):
|
||||||
|
raise ValueError(f"{where}: _handoff must be an object")
|
||||||
|
for key in ("end_state", "soundscape", "dialogue_used"):
|
||||||
|
if key not in handoff:
|
||||||
|
raise ValueError(f"{where}: _handoff missing {key!r}")
|
||||||
|
end_state = handoff["end_state"]
|
||||||
|
if not isinstance(end_state, str) or len(end_state.split()) < 5:
|
||||||
|
raise ValueError(f"{where}: _handoff.end_state must describe the final frame "
|
||||||
|
f"(>= 5 words)")
|
||||||
|
if handoff["soundscape"] != ssc:
|
||||||
|
raise ValueError(f"{where}: _handoff.soundscape must copy the overall_soundscape "
|
||||||
|
f"line character for character")
|
||||||
|
used = handoff["dialogue_used"]
|
||||||
|
if not isinstance(used, list) or not all(isinstance(x, str) for x in used):
|
||||||
|
raise ValueError(f"{where}: _handoff.dialogue_used must be a list of strings")
|
||||||
|
if sorted(used) != sorted(spans):
|
||||||
|
raise ValueError(f"{where}: _handoff.dialogue_used {used} does not mirror the "
|
||||||
|
f"<d> spans {spans}")
|
||||||
|
|
||||||
|
if prev_handoff is not None:
|
||||||
|
prev_line = ""
|
||||||
|
if isinstance(prev_handoff, dict):
|
||||||
|
prev_line = str(prev_handoff.get("soundscape", ""))
|
||||||
|
if prev_line and not CONTINUITY_RE.search(ssc):
|
||||||
|
raise ValueError(f"{where}: soundscape does not continue the previous audio "
|
||||||
|
f"bed (say 'the same ... continues')")
|
||||||
|
if expect is not None:
|
||||||
|
if expect.get("id") not in (None, shot_id):
|
||||||
|
raise ValueError(f"{where}: outline says id {expect.get('id')!r}, "
|
||||||
|
f"fragment says {shot_id!r}")
|
||||||
|
exp_dur = expect.get("duration_seconds")
|
||||||
|
if exp_dur is not None and float(exp_dur) != float(dur):
|
||||||
|
raise ValueError(f"{where}: outline says duration {exp_dur}, fragment says {dur}")
|
||||||
|
exp_dialogue = list(expect.get("dialogue") or [])
|
||||||
|
if exp_dialogue != list(used):
|
||||||
|
raise ValueError(f"{where}: outline dialogue {exp_dialogue} != "
|
||||||
|
f"dialogue_used {used}")
|
||||||
|
if "steps" in obj and not 1 <= int(obj["steps"]) <= 10000:
|
||||||
|
raise ValueError(f"{where}: steps out of range")
|
||||||
|
if "seed" in obj:
|
||||||
|
s = int(obj["seed"])
|
||||||
|
if s < 0 or s > MAX_SEED:
|
||||||
|
raise ValueError(f"{where}: seed out of range")
|
||||||
|
|
||||||
|
print(f" {where} id={shot_id!r} dur={dur:g}s raw={raw_frames} frames "
|
||||||
|
f"words={wc} (band {lo}-{hi}) handoff ok"
|
||||||
|
+ (f" dialogue={len(spans)}" if spans else ""))
|
||||||
|
return handoff
|
||||||
|
|
||||||
|
|
||||||
|
NURSE_OK = {
|
||||||
|
"id": "corridor_walk",
|
||||||
|
"duration_seconds": 8,
|
||||||
|
"prompt": [
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the same walk along the "
|
||||||
|
"corridor without resetting the motion. <Subject 1>, the same night nurse in "
|
||||||
|
"pale green scrubs and white sneakers, pushes the steel trolley forward with "
|
||||||
|
"both hands, its wheels squeaking softly on the linoleum, a paper cup and a "
|
||||||
|
"clipped chart riding on top. The camera keeps a steady over-the-shoulder "
|
||||||
|
"framing at her shoulder height, gliding at her pace, fluorescent panels "
|
||||||
|
"passing overhead in even rhythm, the corridor walls sliding past in soft "
|
||||||
|
"focus. Her sneakers land heel first and roll to the toe, the cup's surface "
|
||||||
|
"trembling with each push, and the hem of her scrub top sways in counterpoint "
|
||||||
|
"to the trolley's roll. Her jaw stays set, eyes forward, one loose strand of "
|
||||||
|
"hair lifting with each step; the trolley's shadow stretches and compresses "
|
||||||
|
"under each ceiling panel. Reaching the blue door at the corridor's end, she "
|
||||||
|
"slows the trolley to a stop and her right hand leaves the handle, closing on "
|
||||||
|
"the door's cold push bar.",
|
||||||
|
"overall_soundscape: the same low fluorescent hum and distant trolley squeak "
|
||||||
|
"continue, a soft draught breathing under the far door.",
|
||||||
|
"non_diegetic_music: N/A",
|
||||||
|
],
|
||||||
|
"_handoff": {
|
||||||
|
"end_state": "She is stopped at the blue door at the corridor's end, right "
|
||||||
|
"hand closing on the cold push bar, trolley at her hip, camera "
|
||||||
|
"still at her shoulder.",
|
||||||
|
"soundscape": "overall_soundscape: the same low fluorescent hum and distant "
|
||||||
|
"trolley squeak continue, a soft draught breathing under the far "
|
||||||
|
"door.",
|
||||||
|
"dialogue_used": [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _short_fragment(**over):
|
||||||
|
base = json.loads(json.dumps(NURSE_OK)) # deep copy
|
||||||
|
base.update(over)
|
||||||
|
return base
|
||||||
|
|
||||||
|
|
||||||
|
def run_fragment_suite():
|
||||||
|
print("Fragment edge cases that must PASS:")
|
||||||
|
handoff = validate_fragment(dict(NURSE_OK), index=1, total=2)
|
||||||
|
validate_fragment(_short_fragment(id="door_stop"), index=2, total=2,
|
||||||
|
prev_handoff=handoff)
|
||||||
|
spoken = _short_fragment(
|
||||||
|
id="door_words",
|
||||||
|
prompt=[
|
||||||
|
"integrated_multimodal_description: [Shot 1] Continue the same corridor "
|
||||||
|
"motion without resetting it as <Subject 1>, the same night nurse in pale "
|
||||||
|
"green scrubs and white sneakers, halts the steel trolley at the blue "
|
||||||
|
"door, its wheels settling with a last squeak on the linoleum. She stands "
|
||||||
|
"silently with mouth closed, then speaks. <d>[English] Room four, your "
|
||||||
|
"tea is ready.</d> She falls silently with mouth closed and turns the "
|
||||||
|
"chart toward the door. The camera holds its over-the-shoulder framing "
|
||||||
|
"while her shoulders settle, the paper cup's surface stilling on the "
|
||||||
|
"trolley top, and the fluorescent panels hum their even rhythm above; "
|
||||||
|
"one loose strand of hair drifts as she exhales, the hem of her scrub "
|
||||||
|
"top sways once and hangs, and the corridor walls keep their soft focus "
|
||||||
|
"behind the steel frame. Her right hand stays flat on the trolley "
|
||||||
|
"handle, knuckles easing, while the door's cold push bar waits an inch "
|
||||||
|
"from her left palm and the draught under the door lifts the corner of "
|
||||||
|
"the clipped chart.",
|
||||||
|
NURSE_OK["prompt"][1],
|
||||||
|
"non_diegetic_music: N/A",
|
||||||
|
],
|
||||||
|
_handoff={
|
||||||
|
"end_state": "She stands at the blue door with the trolley at her hip.",
|
||||||
|
"soundscape": NURSE_OK["prompt"][1],
|
||||||
|
"dialogue_used": ["Room four, your tea is ready."],
|
||||||
|
})
|
||||||
|
validate_fragment(spoken, index=1, total=1)
|
||||||
|
print(" all fragment PASS cases ok")
|
||||||
|
|
||||||
|
print("\nFragment edge cases that must FAIL:")
|
||||||
|
prev = dict(NURSE_OK["_handoff"])
|
||||||
|
no_continuity = _short_fragment(
|
||||||
|
prompt=[NURSE_OK["prompt"][0],
|
||||||
|
"overall_soundscape: seagulls cry over fresh surf and a busker's "
|
||||||
|
"guitar plinks somewhere on the promenade.",
|
||||||
|
"non_diegetic_music: N/A"])
|
||||||
|
no_continuity["_handoff"] = dict(no_continuity["_handoff"],
|
||||||
|
soundscape=no_continuity["prompt"][1])
|
||||||
|
bad_spans = _short_fragment()
|
||||||
|
bad_spans["_handoff"] = dict(bad_spans["_handoff"],
|
||||||
|
dialogue_used=["A line nobody said."])
|
||||||
|
bad_ssc_copy = _short_fragment()
|
||||||
|
bad_ssc_copy["_handoff"] = dict(bad_ssc_copy["_handoff"],
|
||||||
|
soundscape="overall_soundscape: different text.")
|
||||||
|
cases = [
|
||||||
|
("missing _handoff", {k: v for k, v in NURSE_OK.items() if k != "_handoff"}, {}),
|
||||||
|
("duration outside 2-15", _short_fragment(duration_seconds=20), {}),
|
||||||
|
("description far under word budget",
|
||||||
|
_short_fragment(prompt=["integrated_multimodal_description: [Shot 1] "
|
||||||
|
"<Subject 1> walks on. End mid-stride.",
|
||||||
|
NURSE_OK["prompt"][1], "non_diegetic_music: N/A"]), {}),
|
||||||
|
("bare 'is now' outcome",
|
||||||
|
_short_fragment(prompt=[NURSE_OK["prompt"][0].replace(
|
||||||
|
"Her jaw stays set", "Her face is now old"), NURSE_OK["prompt"][1],
|
||||||
|
"non_diegetic_music: N/A"]), {}),
|
||||||
|
("handoff.soundscape not the soundscape line", bad_ssc_copy, {}),
|
||||||
|
("dialogue_used does not mirror spans", bad_spans, {}),
|
||||||
|
("soundscape ignores previous audio bed", no_continuity,
|
||||||
|
{"prev_handoff": prev}),
|
||||||
|
("id disagrees with outline row", _short_fragment(id="hallway_walk"),
|
||||||
|
{"expect": {"id": "door_stop", "duration_seconds": 8, "dialogue": []}}),
|
||||||
|
("steps out of range", _short_fragment(steps=0), {}),
|
||||||
|
]
|
||||||
|
for i, (label, obj, kwargs) in enumerate(cases, 1):
|
||||||
|
try:
|
||||||
|
validate_fragment(obj, index=1, total=1, **kwargs)
|
||||||
|
print(f" case {i} ({label}) UNEXPECTEDLY PASSED <-- BUG")
|
||||||
|
except (ValueError, AssertionError) as exc:
|
||||||
|
print(f" case {i} ({label}) rejected: {exc}")
|
||||||
|
|
||||||
|
|
||||||
|
# The 90-second, 6-scene example user message -> plausible LLM output
|
||||||
|
SIX_SCENE = {
|
||||||
|
"prompt_prefix": ["<Subject 1> is the same retired boxer...",
|
||||||
|
"Warm film look, one continuous take."],
|
||||||
|
"defaults": {"duration_seconds": 15, "steps": 20},
|
||||||
|
"shots": [{"id": f"kitchen_dance_{i:02d}", "prompt": ["Continue..."],
|
||||||
|
"duration_seconds": 15} for i in range(1, 7)],
|
||||||
|
}
|
||||||
|
|
||||||
|
# Edge cases that must PASS
|
||||||
|
edge_ok = [
|
||||||
|
{"shots": ["Opening scene.", "Continue through the doorway."]}, # bare strings
|
||||||
|
{"prompt_prefix": "Shared style.", "shots": [{"id": "a", "length": 362},
|
||||||
|
{"id": "b", "frames": 124}]}, # exact frames
|
||||||
|
{"prompt_prefix": "p", "shots": [{"id": "a", "prompt": ["x"], "duration_seconds": 7.5},
|
||||||
|
{"id": "b", "prompt": ["y"], "context_length": 0},
|
||||||
|
{"id": "c", "prompt": ["z"], "context_length": 0}]},
|
||||||
|
]
|
||||||
|
# Edge cases that must FAIL
|
||||||
|
edge_bad = [
|
||||||
|
{"prompt_prefix": "p", "shots": [{"id": "a", "length": 360}]}, # invalid grid
|
||||||
|
{"prompt_prefix": "p", "shots": [{"id": "a", "prompt": "x", "duration_seconds": 200}]},
|
||||||
|
{"shots": [{"id": "a", "prompt": "x"}, {"id": "a", "prompt": "y"}]}, # dup id
|
||||||
|
{"shots": []}, # empty shots
|
||||||
|
{"shots": [{"id": "a"}]}, # no prompt anywhere
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def run_embedded_suite():
|
||||||
|
plan = json.loads(WORKED_EXAMPLE)
|
||||||
|
print("Worked example from system prompt:")
|
||||||
|
validate_plan(plan)
|
||||||
|
check_h3_sections(plan)
|
||||||
|
|
||||||
|
print("\nRepo I2V Studio example (with length/frames + string seeds):")
|
||||||
|
repo = {
|
||||||
|
"defaults": {"steps": 20},
|
||||||
|
"shots": [
|
||||||
|
{"id": "greenhouse_arrival", "prompt": "p", "length": 362,
|
||||||
|
"steps": 20, "seed": "6101"},
|
||||||
|
{"id": "greenhouse_delivery", "prompt": "p", "length": 362,
|
||||||
|
"steps": 20, "seed": "6102"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
validate_plan(repo)
|
||||||
|
|
||||||
|
print("\n6-scene 90s story example:")
|
||||||
|
validate_plan(SIX_SCENE)
|
||||||
|
|
||||||
|
print("\nEdge cases that must PASS:")
|
||||||
|
for i, case in enumerate(edge_ok):
|
||||||
|
validate_plan(case)
|
||||||
|
print(f" case {i} OK")
|
||||||
|
|
||||||
|
print("\nEdge cases that must FAIL:")
|
||||||
|
for i, case in enumerate(edge_bad):
|
||||||
|
try:
|
||||||
|
validate_plan(case)
|
||||||
|
print(f" case {i} UNEXPECTEDLY PASSED <-- BUG")
|
||||||
|
except ValueError as exc:
|
||||||
|
print(f" case {i} rejected: {exc}")
|
||||||
|
|
||||||
|
print()
|
||||||
|
run_fragment_suite()
|
||||||
|
|
||||||
|
# delivered-duration math check used in the TIMING section
|
||||||
|
print("\nTiming table (raw frames from duration):")
|
||||||
|
for s in (0.2, 1, 2, 5, 10, 15, 30, 149.666, 149.667):
|
||||||
|
try:
|
||||||
|
print(f" {s}s -> {_h3_frame_length(s)} raw frames")
|
||||||
|
except ValueError as exc:
|
||||||
|
print(f" {s}s -> rejected ({exc})")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Validate H3 plan JSONs and scene-agent fragments "
|
||||||
|
"(replica of chain_nodes.py rules).")
|
||||||
|
sub = parser.add_subparsers(dest="cmd")
|
||||||
|
p_plan = sub.add_parser("plan", help="validate a final plan JSON")
|
||||||
|
p_plan.add_argument("file")
|
||||||
|
p_frag = sub.add_parser("fragment", help="validate one scene-agent fragment")
|
||||||
|
p_frag.add_argument("file")
|
||||||
|
p_frag.add_argument("--index", type=int, default=1)
|
||||||
|
p_frag.add_argument("--total", type=int, default=None)
|
||||||
|
p_frag.add_argument("--prev", default=None,
|
||||||
|
help="previous fragment file; chains the soundscape handoff")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.cmd is None:
|
||||||
|
run_embedded_suite()
|
||||||
|
return
|
||||||
|
with open(args.file, encoding="utf-8-sig") as fh:
|
||||||
|
raw = load_json_text(fh.read(), args.file)
|
||||||
|
if args.cmd == "plan":
|
||||||
|
validate_plan(raw)
|
||||||
|
check_h3_sections(raw)
|
||||||
|
else:
|
||||||
|
prev = None
|
||||||
|
if args.prev:
|
||||||
|
with open(args.prev, encoding="utf-8-sig") as fh:
|
||||||
|
pf = load_json_text(fh.read(), args.prev)
|
||||||
|
if isinstance(pf, dict) and isinstance(pf.get("shots"), list) and pf["shots"]:
|
||||||
|
pf = pf["shots"][-1]
|
||||||
|
prev = pf.get("_handoff") if isinstance(pf, dict) else None
|
||||||
|
validate_fragment(raw, index=args.index, total=args.total, prev_handoff=prev)
|
||||||
|
print("OK")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user