name: chapter_roundtable
description: >
  Editorial roundtable -- available editors debate the chapter in 2-3 structured rounds.
  Each round, each participant responds to the others' most recent positions.
  The output is a categorized consensus (MUST APPLY / OPTIONAL / PRESERVE) for the
  bounded editorial polish step.

debug: true
rag_exclude: [business_plan, charter]
system: agent_prompt

agent_prompt:
  - "= identity.md"

participant_prompt:
  - "= identity.md"

iteration_limit: 3
convergence_signal: "CONSENSUS REACHED"

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

steps:
  - type: think
    rotate_participants: true
    loop:
      max_iterations: 5
    hint: |
      You are {agent.name}, an editor in the editorial roundtable for this chapter.
      {agent.identity}

      CHAPTER REFERENCE: {chapter_ref}
      GENRE: {genre_name}  |  AUDIENCE: {genre_audience}

      ---
      CHAPTER TEXT:
      {chapter_text}
      ---

      Round {task.iteration} of the editorial debate.

      Read the chapter carefully from your editorial perspective.
      React to what other editors have written in prior rounds above.
      Where you agree, say so clearly. Where you disagree, argue your position
      with QUOTED EVIDENCE from the text -- do not make claims about the prose
      without quoting the specific passage you are referring to.
      If you have changed your mind, say so and quote what changed it.

      Cover the areas most relevant to your role:
        - Story structure and pacing
        - Character voice and consistency -- if character_profiles is populated below,
          check each speaking character against their voice constraints and quote any
          violations you find
          {character_profiles}
        - Line-level clarity and prose quality
        - Continuity with prior chapters and world rules

      Before calling CONSENSUS REACHED, ensure the group has resolved any disagreements.
      If two editors disagree on whether a change is required (one says MUST, one says optional),
      the MUST position prevails unless the other editor can argue it would damage the chapter.
      The polish step cannot reconcile unresolved debate -- resolve it here.

      When the group has reached sufficient consensus for the polish step,
      end your response with this EXACT block -- no variations, no paraphrasing:

      CONSENSUS REACHED
      CRITIQUE: [One concise paragraph summarizing the full editorial consensus]
      MUST APPLY:
      - [Must-fix item 1 -- continuity error, clarity issue, or structural problem only]
      - [Must-fix item 2 -- if applicable]
      OPTIONAL (only if explicitly agreed by majority as low-risk):
      - [Optional craft suggestion -- clearly labeled, not required]
      PRESERVE:
      - [Strength or intentional voice choice that must NOT be changed]
      - [Additional preserve item if applicable]
      VERDICT: [PASS / REVISE]

      VERDICT rules:
      - PASS: no MUST APPLY items remain after the debate
      - REVISE: one or more MUST APPLY items require correction
      - Do NOT use REWRITE as a verdict -- the polish step is surgical, not a rebuild.
        If the chapter is so broken that only a full rewrite would fix it, flag that in CRITIQUE
        and set VERDICT to REVISE so the polish step addresses what it can.

      Once any participant outputs CONSENSUS REACHED, the debate is over.
      Do NOT continue to another round after CONSENSUS REACHED has been written.

  - type: package
    schema:
      consensus_critique: string
      chapter_verdict: string
      key_changes: string
    hint: |
      Extract the consensus fields from the CONSENSUS REACHED block above.
      - consensus_critique: the full CRITIQUE paragraph
      - chapter_verdict: PASS or REVISE (never REWRITE)
      - key_changes: the complete MUST APPLY section as a single string, including any
        OPTIONAL items that were agreed upon and any PRESERVE notes, clearly labeled.
        This field is the full contract for chapter_polish -- include all sections.
    spawn:
      - task_type: chapter_polish
        task_name: "Polish: {chapter_ref}"
        agent_name: Iris
        context:
          chapter_text: "{chapter_text}"
          consensus_critique: "{consensus_critique}"
          key_changes: "{key_changes}"
          chapter_verdict: "{chapter_verdict}"
          genre_name: "{genre_name}"
          genre_audience: "{genre_audience}"
          chapter_ref: "{chapter_ref}"
          chapter_number: "{chapter_number}"
          chapter_target_words: "{chapter_target_words}"
          character_profiles: "{character_profiles}"

adjudication:
  enabled: false
