π Stories Maker V4 β Kitchen Pipeline
Multi-genre content engine with deterministic quality gates β 11 phases, 17 gates, 7 genres, 71 tests
System Overview
Design Pillars
| Determinism | SHA-256 gate tokens β identical inputs = identical decisions |
| Sequential | _PHASE_ORDER list β no skipping allowed |
| Separation | Auditors evaluate β Arbiter decides β Gates enforce β Writer creates |
| Immutability | Bible locked after G3 β tokens append-only JSONL |
| Fail-safe | Policy violation β immediate ABORT |
| Cost-conscious | Hard cost limits per mode β escalations abort, not loop |
βοΈ 11 Pipeline Phases (0-10)
-
Phase 0 β IDEATION
Writespolicy_bundle.mdto disk. Gate G0 validates policy loaded.
Auto G0 -
Phase 1 β RESEARCH
Source quality check.source_analysis.quality_score β₯ 0.7
Auto G1 -
Phase 2 β BIBLE DRAFT
Originality screen.outline_data.originality_score β₯ 0.85. Character bible + V4 expanded character sheet (archetype, villain layers, visual cards).
Auto G2 -
Phase 3 β BIBLE LOCK π
Bible schema validation βPENDING_HUMAN. Rio approves β bible locked (immutable, checksum-protected). Cannot be modified after G3.
β Human Gate G3 -
Phase 4 β OUTLINE
Scene spec validation (G3.5) + parallel audits: canon consistency (G4A), timeline causality (G4B), originality pre-screen (G4C).
Auto G3.5 G4A G4B G4C -
Phase 5 β SCENE LOOP β Core Loop
For each scene: Writer β 6 Auditors (parallel) β Gate5 Tier1 (binary) + Tier2 (numeric). Max 3 rewrites per scene. Backstory placement per mode. Villain layer2 reveal. Thesis delivery.
Auto G5 ΓN scenes -
Phase 6 β ASSEMBLY
Cross-scene batch audit (G6). Assembly word-count + structure check (G7).
Auto G6 G7 -
Phase 7 β OUTPUT
Final QA: quality scores vsSCRIPT_STANDARDS.PENDING_HUMANfor Rio approval.
β Human Gate G8 -
Phase 8 β THUMBNAIL & SEO
SEO package generation: title, tags, description, thumbnail.
Auto G8.5 -
Phase 9 β UPLOAD
Output package complete (G9) + upload confirmed (G9.5).
Auto G9 G9.5 -
Phase 10 β MONITORING
Post-publish analytics started. Performance tracking begins.
Auto G10
π¦ Gate System β 17 Gates
Mα»i gate issue mα»t GateToken (SHA-256 checksum, append-only JSONL). bypass_allowed structurally = False. Self-pass prevention: Writer khΓ΄ng thα» issue token cho chΓnh mΓ¬nh.
| Gate | Phase | Type | Issuer | Description |
|---|---|---|---|---|
G0 | 0 β Ideation | Auto | Arbiter | Policy bundle loaded |
G1 | 1 β Research | Auto | Arbiter | Source quality β₯ 0.7 |
G2 | 2 β Bible Draft | Auto | Arbiter | Originality score β₯ 0.85 |
G3 | 3 β Bible Lock | β Human | Human | Bible approved by Rio |
G3.5 | 4 β Outline | Auto | Arbiter | Scene spec JSON schema valid |
G4A | 4 β Outline | Auto | Arbiter | Canon consistency |
G4B | 4 β Outline | Auto | Arbiter | Timeline causality |
G4C | 4 β Outline | Auto | Arbiter | Originality pre-screen |
G4 | 4 β Outline | Auto | Arbiter | Combined G4A+B+C summary |
G5 | 5 β Scene Loop | Auto | Arbiter | Per-scene quality (ΓN scenes) |
G6 | 6 β Assembly | Auto | Arbiter | Cross-scene batch audit |
G7 | 6 β Assembly | Auto | Arbiter | Assembly word-count + structure |
G8 | 7 β Output | β Human | Human | Final QA approved by Rio |
G8.5 | 8 β Thumb/SEO | Auto | Arbiter | SEO package generated |
G9 | 9 β Upload | Auto | Arbiter | Output package complete |
G9.5 | 9 β Upload | Auto | Arbiter | Upload confirmed |
G10 | 10 β Monitor | Auto | Arbiter | Post-publish analytics started |
Gate 5 β Two-Tier Decision System
Tier 1 β Binary Decision (6 dimensions)
| Rule | Condition | Decision |
|---|---|---|
| 1 | Policy = FAIL | ABORT (no recovery) |
| 2 | All 6 = PASS | β Advance to Tier 2 |
| 3 | 1-2 non-policy FAILs, attempt < max | REWRITE |
| 4 | 3+ non-policy FAILs | ESCALATE |
| 5 | Any FAIL, attempt β₯ max | ESCALATE (Guided) / ABORT (Auto) |
Tier 2 β Quality Score Thresholds
| Dimension | Minimum |
|---|---|
| Consistency | 9.0 |
| Originality | 8.5 |
| Hook | 8.5 |
| Cliffhanger | 8.0 |
| Emotional | 8.5 |
| TTS | 9.0 |
Any score below minimum β REWRITE (even if all Tier-1 passed). All scores β₯ minimum β PASS β G5 token issued.
π Genre Registry β 7 Genres (V4)
| Genre | Label | Default Archetype | Villain Layers | Backstory | Thesis |
|---|---|---|---|---|---|
revenge | Family Revenge / Betrayal | betrayed_victim | 1 | front_loaded | narrator |
healing | Healing / Recovery | wounded_survivor | 1 | front_loaded | narrator |
redemption | Redemption / Invisible Good | invisible_giver | 1 | woven | environmental |
hidden_identity | Hidden Identity / Competence Reveal | suppressed_identity | 2 | earned | character_spoken |
injustice | Injustice / Wrongful Accusation | wrongly_accused | 2 | revelation | protagonist_earned |
transformation | Transformation / Underdog Rise | underdog | 1 | woven | environmental |
default | Default (Legacy) | betrayed_victim | 1 | front_loaded | narrator |
Required Beats per Genre
π‘οΈ Revenge
betrayal β discovery β confrontation β resolution
π Healing
wound β breakdown β turning_point β acceptance
ποΈ Redemption
selfless_act β unrewarded_stretch β unfair_opponent_rise β opponent_fall β quiet_payoff
π Hidden Identity
hidden_state β crisis_trigger β competence_reveal β backstory_earn β villain_layer2_exposed β identity_restored
βοΈ Injustice
accusation β isolation β ally_appears β evidence_found β true_villain_exposed β vindication
π¦ Transformation
low_point β catalyst β first_win β setback β mastery β proving_moment
π€ Archetype Registry β 7 Protagonist Types
| Archetype | Label | Traits | Compatible Genres |
|---|---|---|---|
betrayed_victim | Victim of Betrayal | Trusting β discovers betrayal β fights back | revenge, healing |
wounded_survivor | Wounded Survivor | Deep wound β survival mode β healing journey | healing, transformation |
invisible_giver | Invisible Giver | Gives without expectation β unrewarded β quiet payoff | redemption |
suppressed_identity | Suppressed Identity | Hides true self β crisis forces reveal β identity restored | hidden_identity, transformation |
wrongly_accused | Wrongly Accused | Falsely blamed β fights system β truth emerges | injustice |
underdog | Underdog | Overlooked β catalyst event β rises through effort | transformation, redemption |
hidden_competence | Hidden Competence | Appears ordinary β forced to act β reveals expertise | hidden_identity |
π Backstory Delivery Modes β 4 Modes
π Front-loaded
Backstory told in Act 1, action follows.
π Earned
Protagonist acts first β audience earns backstory later.
Rule: Protagonist MUST demonstrate competence BEFORE backstory revealed
π§΅ Woven
Backstory fragments woven throughout, building incrementally.
Fragments: 3-5 flashback moments
π₯ Revelation
True backstory only revealed near climax β reframes everything.
Rule: Early scenes MUST work WITHOUT backstory context
π‘ Thesis Delivery Modes β 4 Modes
| Mode | Description | Strength | Compatible Genres |
|---|---|---|---|
narrator | Narrator directly delivers moral/theme | Clear but can feel preachy | revenge, healing |
character_spoken | Supporting character delivers core truth | Feels earned β from within story | hidden_identity |
protagonist_earned | Protagonist realizes truth through experience | Most powerful β earned through action | injustice, transformation |
environmental | No one states thesis β shown through contrasting actions | Most subtle β audience concludes | redemption |
π Auditor System β 6 Dimensions
All 6 auditors run concurrently via asyncio.gather(). Each returns AuditResult with verdict (PASS/FAIL), error code, severity, quality scores.
| Auditor | Dimension | Error Code | What It Checks |
|---|---|---|---|
| Canon | Character consistency | CANON_CONFLICT | Characters match bible traits, arcs, relationships |
| Timeline | Causality + temporal | TIMELINE_ERROR | Event ordering, prerequisites, temporal logic |
| Fact | Factual verification | FACT_DRIFT | Claims match fact ledger, no contradictions |
| Originality | Duplicate detection | LOW_ORIGINALITY | Content uniqueness, no plagiarism |
| Policy | Content compliance | POLICY_VIOLATION | No dark psych, no celebrity images, ethical content |
| Style | Voice + tone | STYLE_DRIFT | Narrator persona consistency, tone matching |
Conflict Resolution Priority (highest β lowest)
1. FACT β 2. CANON β 3. TIMELINE β 4. ORIGINALITY β 5. STYLE β 6. POLICY (always ABORT)
When auditors disagree on same dimension: FAIL verdict wins (conservative).
βοΈ Rewrite Engine
Scope Escalation Ladder
| Attempt | Scope | Description | Context Loaded |
|---|---|---|---|
| 1 | L1/L2 | Minimal fix (word/sentence) | Target sentence or paragraph |
| 2 | L3 | Paragraph rewrite | Scene section + bible cast summary |
| 3 | L4 | Full scene rewrite (final attempt) | Full bible, timeline, fact ledger, scene spec |
Cost Containment
- Max 3 attempts β hard cap per scene
- Scope escalation β smaller scopes first = fewer tokens
- Early exit β Policy violation = ABORT immediately (no retries)
- Fail-fast β 3+ simultaneous failures = ESCALATE (don't waste tokens)
π Villain Architecture β 2-Layer System
Layer 1 β Visible Antagonist
Always present. Direct opposition to protagonist.
Arc: escalate β overreach β exposed
Example: "Tristan" (Hidden Identity)
Layer 2 β Hidden Architect
Optional (for hidden_identity, injustice). Creates "second twist".
Arc: invisible β hints β full exposure Act 3
Reveal: Scene 60-90% of story
Example: "Ashford Sr." (Hidden Identity)
π₯ Intake Schema V2 β New Fields
# input_intake.yaml β V2 Schema
genre: "hidden_identity" # 7 options tα»« GENRE_REGISTRY
protagonist:
name: "Elena Vasquez"
archetype: "suppressed_identity" # tα»« ARCHETYPE_REGISTRY
visible_persona: "Quiet cleaning lady"
hidden_truth: "Former international translator"
villain_architecture:
layers: 2
layer_1: { name: "Tristan", role: "executor" }
layer_2: { name: "Ashford", role: "architect", reveal_timing: 0.75 }
backstory_mode: "earned" # 4 modes
thesis:
mode: "character_spoken" # 4 modes
core_message: "Identity isn't what they took..."
speaker: "Elena's mother"
unfair_opponent: # Optional (redemption genre)
name: "Jerome"
philosophy: "Take everything, give nothing"
emotional_curve_override: null # null = use genre default
Validation Rules
- Genre must be in
GENRE_REGISTRY - Archetype must be compatible with genre
- Villain layers must match genre default or be justified
- Backstory mode must be compatible with genre
- Thesis mode must be compatible with genre
- If unfair_opponent β genre should be "redemption"
- If villain layers == 2 β layer_2.reveal_timing must be 0.6-0.9
πΎ State Management β 5 Persistent Objects
| Object | File | Lifecycle | Key Feature |
|---|---|---|---|
| Bible Lock | story_bible_lock.json | Created Phase 3 β locked forever | SHA-256 checksum, immutable after G3 |
| Fact Ledger | fact_ledger.json | Updated Phase 1-5 | FACT/INFERENCE/CREATIVE/UNKNOWN labels |
| Timeline Grid | timeline_grid.json | Updated Phase 1-5 | Causality validation via prerequisites |
| Scene Spec | scene_specs/{id}.json | Created Phase 4, read-only Phase 5 | Goal, beats, emotional turn, hooks |
| Scene Log | scene_logs/{id}.json | Append-only Phase 5 | Version history, scores, rewrite tasks |
π Guided vs Auto Mode
| Behaviour | Guided | Auto |
|---|---|---|
| G3 (Bible Lock) | Pauses β PENDING_HUMAN | No pause |
| G8 (Final QA) | Pauses β PENDING_HUMAN | No pause |
| ESCALATE in scene | Pauses β PENDING_HUMAN | Returns ABORTED |
| Model strategy | claude-opus-4.6 (all agents) | Hybrid (haiku auditors, sonnet writer) |
| Cost limit (soft/hard) | $200 / $300 | $100 / $150 |
| Max rewrites | 15 per scene | 15 per scene |
π° Cost Optimisation Strategy
Model Selection Matrix
| Agent Role | Guided Model | Auto Model |
|---|---|---|
| Scene Writer | claude-opus-4.6 | claude-sonnet-4 |
| Canon Auditor | claude-opus-4.6 | claude-haiku-3 |
| Timeline Auditor | claude-opus-4.6 | claude-haiku-3 |
| Fact Auditor | claude-opus-4.6 | claude-sonnet-4 |
| Originality Auditor | claude-opus-4.6 | claude-haiku-3 |
| Policy Auditor | claude-opus-4.6 | claude-haiku-3 |
| Style Auditor | claude-opus-4.6 | claude-haiku-3 |
Budget Safeguards
Per-run cost flow:
tokens_used (per scene version in SceneLog)
β
credits_used (accumulated)
β
soft_limit reached β WARNING, continue
β
hard_limit reached β ABORTED("Cost limit exceeded")
π§© Component Map
orchestrator_v2/
βββ main.py # Orchestrator FSM entry point
βββ config.py # GENRE_REGISTRY, ARCHETYPE_REGISTRY, modes, thresholds
β
βββ gates/ # Gate enforcement layer
β βββ token_engine.py # GateToken + SHA-256 checksums
β βββ gate_5.py # Tier-1 binary + Tier-2 numeric
β βββ gates_0_3.py # G0, G1, G2, G3
β βββ gates_4.py # G3.5, G4A, G4B, G4C
β βββ gates_6_8.py # G6, G7, G8
β
βββ arbiter/ # Decision engine
β βββ decision_engine.py
β βββ phase2_mode.py # AUTO escalation handler
β
βββ auditors/ # 6 quality auditors
β βββ canon_auditor.py
β βββ timeline_auditor.py
β βββ fact_auditor.py
β βββ originality_auditor.py
β βββ policy_auditor.py
β βββ style_auditor.py
β
βββ agents/ # Sub-agent integration
β βββ intake_validator.py # V4 cross-validation
β βββ bible_builder.py # Expanded character sheet
β βββ scene_builder.py # Backstory placement, villain reveal
β βββ scene_writer.py
β βββ story_architect.py
β βββ renderer.py
β βββ thumbnail_generator.py
β βββ youtube_uploader.py
β
βββ state/ # Persistent state objects
β βββ bible_lock.py
β βββ fact_ledger.py
β βββ timeline_grid.py
β βββ scene_spec.py
β βββ scene_log.py
β
βββ rewrite/
β βββ rewrite_engine.py
β
βββ context/
β βββ context_manager.py
β
βββ dashboard/ # Dashboard connector
β βββ dashboard_connector.py
β
βββ tests/ # 71 passing tests
AVA Stories Maker V4 β Kitchen Pipeline Documentation
Last updated: 2026-03-24 | Branch: dev | Commit: cc91ff2