name: book_outline
description: "Boardroom debate to lock the book concept, produce a character bible (for fiction) + full chapter outline, then spawn chapter writing tasks."
debug: true
system: agent_prompt
step_pause_mode: true
context_builders:
  - markov_names

participant_prompt:
  - "= identity.md"

agent_prompt:
  - "= identity.md"

sections:
  - agent
  - project
  - history
  - rag
  - deliverables
  - participants
  - participants_prompt
  - message
  - instructions

steps:
  - type: think
    rotate_participants: true
    loop:
      max_iterations: 4
    hint: |
      You are {agent.name}. This is round {task.iteration} of the creative boardroom.

      GENRE: {genre_name|[infer from project description if blank]}
      AUDIENCE: {genre_audience|[infer from project description if blank]}
      STRUCTURE GUIDE: {outline_structure|[use standard 3-act structure with chapter hooks if blank]}

      The room is deciding on ONE book concept to write. The trend research
      is in the DELIVERABLES and RAG above — everyone has read it.

      ═══════════════════════════════════════════════
      PRE-ASSIGNED CHARACTER NAMES (fiction projects — use these exactly)
      ═══════════════════════════════════════════════
      These names were generated for this project. Do NOT substitute generic defaults
      like Jax, Elara, Ryder, Quinn, Lyra, Knox, or Zane.

        Protagonist:    {protagonist_name}
        Love interest:  {love_interest_name}
        Antagonist:     {antagonist_name}
        Supporting:     {supporting_1}, {supporting_2}, {supporting_3}
        Setting/Town:   {place_name}

      (Non-fiction projects: ignore the character names above — they are not applicable.)
      ═══════════════════════════════════════════════

      From YOUR area of expertise, argue for (or against) a specific concept:
        - Which of the research concepts has the strongest hook for this audience?
        - What protagonist archetype will readers obsess over?
        - What central conflict creates the best chapter-to-chapter tension?
        - What's the opening chapter hook that makes a reader continue?
        - What should the chapter length and structure be?

      React to what prior speakers argued. Push back on weak ideas. Build on strong ones.
      Be specific — no vague enthusiasm. Name the concept, argue WHY.

      When the group has agreed on ONE specific concept (title, hook, protagonist, conflict, structure):
      "consensus_reached: true"

  - type: think
    agent: first_available
    hint: |
      The boardroom has selected ONE concept. Your job is to write the SINGLE CANONICAL outline.

      ⚠️ CRITICAL RULES:
      - Do NOT present multiple options, alternatives, or "Option A / Option B" variants.
      - Do NOT include chapter ideas from the deliberation rounds that were NOT selected.
      - Write ONE definitive chapter list. If the project calls for 10 chapters, write EXACTLY 10.
      - Every chapter entry must follow the exact format: "- Chapter N: [Title]" (sequential, no gaps).

      Synthesize the agreed concept into a COMPLETE BOOK OUTLINE document.

      ═══════════════════════════════════════════════
      PART 1: CHARACTER BIBLE (fiction only — omit entirely for non-fiction)
      ═══════════════════════════════════════════════
      If this is a fiction project, write a Character Bible FIRST:

      # [Book Title] — Character Bible

      ## {protagonist_name}
      - Age:
      - Voice: [describe the internal narrative voice — e.g., "sardonic, first-person, teen"]
      - Background: [2 sentences]
      - Want: [what they think they want]
      - Need: [what they actually need to grow]
      - Fatal flaw: [the trait that creates conflict]
      - Speech pattern: [how they talk — with examples]

      ## {love_interest_name}
      - Age:
      - Role in story:
      - Why readers root for them:
      - Dynamic with protagonist:
      - Secret or wound they carry:

      ## {antagonist_name}
      - Type: [person / institution / supernatural / internal]
      - Motivation:
      - How they challenge the protagonist:

      ## Supporting Characters
      - {supporting_1}: [role and relationship to protagonist]
      - {supporting_2}: [role and relationship to protagonist]
      - {supporting_3}: [role and relationship to protagonist]

      ## World Rules (if paranormal/fantasy/speculative)
      - [Powers, systems, constraints — be precise]
      - [What limits them? What are the costs?]

      ## Voice Signatures
      (REQUIRED for fiction — this section is injected into every chapter to enforce consistent character voice.
      Think carefully: these are NON-NEGOTIABLE identifiers the polisher will enforce.)

      ### [Protagonist name] — Voice Signature
      - Curse/stress expression scale: "[mild phrase]" = minor irritation | "[mid phrase]" = upset | "[strong phrase]" = furious
      - Verbal tic or sarcasm tell: [e.g., "says 'obviously' when meaning the opposite"]
      - Speech pattern when excited: [e.g., "interrupts own sentences mid-thought"]
      - What they REACH FOR in descriptions: [e.g., "tactile/kinesthetic — touches things to understand them"]
      - What they NEVER say or do in dialogue: [e.g., "never apologizes directly — fixes things instead"]
      - Sentence pattern: [e.g., "short declaratives when focused; long run-ons when arguing"]

      ### [Love interest name] — Voice Signature
      - Formality scale (INVERSELY maps to severity): "[mild formal phrase]" = small problem | "[very formal/archaic phrase]" = disaster
      - What they NEVER say: [e.g., "never says 'I think' — says 'the evidence suggests' or 'it is probable that'"]
      - Superlative rule: [e.g., "never uses superlatives except for things that matter deeply — when they do, it stops the room"]
      - Sentence completeness tell: [e.g., "always grammatically complete — EXCEPT when flustered by protagonist, then fragments"]
      - Speech pattern: [e.g., "precise, no wasted words; anger shows through subject choice and word order, not volume"]

      ═══════════════════════════════════════════════
      PART 2: CHAPTER OUTLINE (all projects)
      ═══════════════════════════════════════════════

      ## Factions
      (REQUIRED for fantasy/speculative — define named factions so NPCs have memory chapter-to-chapter.
      These entries are compiled into factions.rag.md and injected into each chapter's world state.)

      ### [Faction Name]
      - Home location: [specific -- city, building, region, planet -- not vague]
      - Leader: [name and title]
      - Key NPCs: [name (role/function at this location), name (role), ...]
      - Initial attitude toward protagonist: [ALLIED / NEUTRAL / WATCHFUL / HOSTILE] -- [one sentence reason]
      - Initial attitude toward love interest: [same]
      - What they want: [one sentence faction goal]
      - What would make them hostile: [threshold / trigger]
      - What would make them allied: [threshold / trigger]

      (Repeat for every faction in the story -- at minimum: protagonist's school/home,
      antagonist's faction, any neutral third party with named NPCs)

      ---

      # [Book Title]
      ## Concept Summary
      - Hook: one sentence that sells the book
      - Genre: {genre_name}
      - Protagonist: name, age, background, flaw, want vs need
      - Antagonist / Central Conflict: what stands in their way
      - Setting: world, time, atmosphere
      - Format: target chapter length ~{chapter_target_words} words, POV (1st/3rd)
      - Target audience: {genre_audience}

      ## Chapter Outline
      For each chapter (target {chapter_count} chapters):
        - Chapter N: [Title]
        - Summary: 2–3 sentences of what happens
        - Emotional beat: what the reader feels
        - Hook / cliffhanger: the exact last image or line that makes readers continue
        - Opens at: [location / setting at chapter start]
        - Character state: [protagonist's emotional and physical state as the chapter opens]
        - Dominant tension: [the active conflict or pressure driving this chapter]

      ## Voice & Tone Guide
      Write the Voice & Tone Guide as HARD OPERATING CONSTRAINTS, not aspirations.
      This guide will be copied verbatim into every chapter task as {prose_style} —
      treat it as rules the author must follow on every page, not a mood description.

      PROSE STYLE: {prose_style}

      Format the Voice & Tone Guide as:
        - POV and tense: [e.g., "First-person present tense throughout."]
        - Sentence rhythm: [e.g., "Vary sentence length; no more than two consecutive complex
          sentences. Short sentences for impact. Fragments allowed for interiority."]
        - Anti-overpolish rules: [e.g., "Not every paragraph needs a memorable line. Use
          functional connective prose. Let observation precede interpretation — show the moment
          before naming what it means. Avoid clustering aphorisms. Prefer scene motion over
          thesis delivery."]
        - Voice don'ts: [e.g., "No head-hopping. No passive construction during action beats.
          No normalizing the protagonist's distinctive voice."]
        - One example opening sentence that demonstrates all of the above.

      ## Publishing Notes
      Why this book fits the genre and target audience.

  - type: document
    filename: "{{task_name_slug}}"

  - type: think
    agent: first_available
    hint: |
      Extract a CLEAN CHAPTER LIST from the outline document above.
      Output ONLY the chapter list in this exact format — no other text:

      Chapter [Title]
        Summary: [2-3 sentence summary]
        POV: [character name or "narrator"]

      Chapter [Title]
        Summary: [2-3 sentence summary]
        POV: [character name or "narrator"]

      Rules:
      - One "Chapter [Title]" line per chapter, in order
      - Indented metadata lines underneath each chapter (Summary, POV)
      - Do NOT include chapter numbers — just the title
      - Do NOT include any markdown headers, bullet points, or extra formatting
      - This output will be parsed by StoryForge's outline sync engine

  - type: package
    packet_type: IntakeResponse
    hint: |
      You are the Project Manager serializing the FINAL OUTLINE DOCUMENT above into chapter tasks.

      ⚠️ STRICT DEDUPLICATION RULES:
      - Use ONLY the chapters listed in PART 2: CHAPTER OUTLINE of the document above.
      - IGNORE all chapter suggestions from the boardroom deliberation rounds.
      - Count ONLY entries formatted as "- Chapter N:" in PART 2. That count = your action count.
      - A 10-chapter outline = exactly 10 actions. A 12-chapter outline = exactly 12 actions.
      - If you produce more actions than chapter entries in PART 2, you have made an error — recount.

      For each chapter in PART 2 (and ONLY those chapters), create one create_task action:

      CRITICAL — Fill in these values from the outline document:
        - genre_name: the exact genre (e.g., "YA Romance", "Science Fiction", "Literary Fiction")
        - genre_audience: the target audience (e.g., "Young adults 14–18", "Adult romance readers")
        - prose_style: copy the 3-sentence Voice & Tone Guide from the outline exactly
        - chapter_target_words: the target word count per chapter as a number string (e.g., "3500")
        - chapter_ref: zero-padded two-digit chapter number, e.g. "ch-01", "ch-02", ... "ch-18"
        - chapter_number: plain chapter number as a string, e.g. "1", "2", ... "18"
        - character_profiles: copy the COMPLETE "## Voice Signatures" section from PART 1 of
          the outline verbatim. Include every named character's Voice Signature entry.
          If no Voice Signatures section exists, copy the full character entries (## Name blocks)
          from the Character Bible in Part 1. If this is a non-fiction project, leave empty.

      Rules:
      - EXACTLY one action per chapter from PART 2 of the outline — no more, no less
      - task_name format: "Write Chapter N: [Chapter Title]" (N is a plain number, 1, 2, 3...)
      - agent_name: always "Iris"
      - task_type: choose based on genre_name from the outline:
          * "ya_chapter"           → if genre_name contains "YA" or "Young Adult"
          * "romance_chapter"      → if genre_name contains "Romance" or "Contemporary Romance"
          * "scifi_chapter"        → if genre_name contains "Science Fiction" or "Sci-Fi" or "Space Opera"
          * "cozy_mystery_chapter" → if genre_name contains "Cozy Mystery" or "Mystery"
          * "adult_novel_chapter"  → if genre_name contains "Adult" and not YA
          * "book_chapter"         → all other genres (default)
      - description: >
          Include the chapter summary, POV character, emotional beat, cliffhanger, character state,
          dominant tension, and opening location from the chapter outline.
          Start with: "You are writing Chapter N of [Book Title]. [chapter summary].
          POV: [character name]. Opens at: [location]. [Character name] enters this chapter
          [character state]. Dominant tension: [tension]. Closes with: [cliffhanger hook]."
          Also include the Voice & Tone Guide from the outline as the prose_style value —
          copy it exactly. This is a hard constraint for every sentence of the chapter.
      - depends_on: the exact task_name of the PREVIOUS chapter (empty string for Chapter 1)

      The depends_on chain creates sequential writing — each chapter waits for the previous to be committed.
    schema:
      actions:
        - type: create_task
          task_name: "string"
          agent_name: "string"
          task_type: "string"
          description: "string"
          depends_on: "string"
          context:
            genre_name: "string"
            genre_audience: "string"
            prose_style: "string"
            chapter_target_words: "string"
            chapter_ref: "string"
            chapter_number: "string"
            character_profiles: "string"

  - type: package
    packet_type: IntakeResponse
    hint: |
      SPAWN CHARACTER SHEET TASKS

      From the "## Character Bible" section of PART 1 (or the Voice Signatures section),
      identify every NAMED character who has a speaking role or significant story function.

      For EACH named character, emit one create_task action:
        - task_name: "Character Sheet: [character full name]"
        - task_type: character_sheet
        - agent_name: Iris
        - context.character_name: exact canonical name as used in the outline
        - context.character_name_slug: lowercase, spaces-to-hyphens, remove non-alphanumeric

      Example for a character named "Emmeline Voss":
        task_name: "Character Sheet: Emmeline Voss"
        task_type: character_sheet
        agent_name: Iris
        context.character_name: "Emmeline Voss"
        context.character_name_slug: "emmeline-voss"

      Do NOT include unnamed background characters or characters mentioned only in passing.
      Include at minimum: protagonist(s), love interest(s), antagonist(s), and any character
      with more than one scene.
    schema:
      actions:
        - type: create_task
          task_name: "string"
          agent_name: Iris
          task_type: character_sheet
          context:
            character_name: "string"
            character_name_slug: "string"

  - type: close
    rag_update: true

adjudication:
  enabled: false
