Files
crimson_leaf_publishing/templates/chapter_production.yml
David Baity 1bff66b674 fix: stop chapter_production from dispatching project_index mid-book
- Remove project_index dispatch from chapter_production.yml entirely.
  chapter_production should ONLY dispatch book_chapter. The project_index
  dispatch belongs to book_editorial (which already handles it correctly).
  This was the root cause of the CLM hallucination cascade:
    pulse_check -> project_review -> chapter_production -> project_index -> marketing_campaign (infinite loop)

- Add clm_dispatch_gate guard in project_index.yml. project_index now checks
  whether its task message is a real book-complete signal or a generic/none
  message. If gate is 'skip', clm_dispatch_content is 'none' and the enqueue
  call returns gracefully (optional: true). Only fires when triggered by
  book_editorial with a legitimate completion message.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-28 20:04:24 -04:00

116 lines
4.2 KiB
YAML

name: chapter_production
description: "CLP self-driving chapter dispatch -- checks project pipeline status and spawns the next unwritten chapter."
debug: true
model: power
system: agent_prompt
agent_prompt:
- "= identity.md"
sections:
- agent
- project
- deliverables
- rag
- message
- instructions
steps:
- type: tool
action: git_read_file
optional: true
output_key: book_outline_text
params:
path: "outline.md"
- type: think
max_tokens: 2000
output_key: next_chapter_decision
hint: |
You are {agent.name}, production manager for {project.name}.
Review the DELIVERABLES section above.
STEP 1 -- Count fully polished chapters (sequential):
Look for files matching: staging/polished/chapter-ch-XX.md
Walk the sequence from ch-01 upward. Count how many consecutive chapters
have a polished file. STOP counting at the first gap -- a missing polished
file breaks the sequence even if later chapters are polished.
Example: ch-01, ch-02, ch-03 exist but ch-04 missing -> sequential polished = 3
even if ch-05 polished file also exists.
STEP 2 -- Identify the next chapter needed:
NEXT_CHAPTER = the first chapter in the sequence that does NOT have a polished file.
This is always sequential_polished_count + 1.
Example: ch-01 through ch-05 polished, ch-06 missing -> NEXT_CHAPTER = ch-06
Even if ch-07 is already polished, ch-06 must be completed first.
STEP 3 -- Check if NEXT_CHAPTER is already in the pipeline:
Look in DELIVERABLES for any staging evidence for NEXT_CHAPTER:
- A draft file (e.g. Chapter_6_draft.md or Chapter_06_draft.md)
- Any review files (e.g. Chapter_6_review_a.md)
If staging evidence exists for NEXT_CHAPTER: it is ALREADY_IN_PIPELINE.
If no staging evidence at all: it is NEEDS_DRAFT.
STEP 4 -- Determine STATUS:
Check the BOOK OUTLINE for total chapter count (TOTAL_CHAPTERS).
If sequential_polished_count >= TOTAL_CHAPTERS: STATUS = COMPLETE
Otherwise: STATUS = NEEDS_CHAPTER
Output:
STATUS: NEEDS_CHAPTER or COMPLETE
NEXT_CHAPTER: ch-06 (or whichever, or N/A if COMPLETE)
CHAPTER_TITLE: <from outline if available>
SEQUENTIAL_POLISHED: <count of consecutive polished chapters from ch-01>
ALREADY_IN_PIPELINE: yes or no
PIPELINE_STAGE: draft-only / has-reviews / has-polish / none
- type: think
max_tokens: 100
output_key: production_status
hint: |
Read the STATUS line from the chapter production decision above.
Output EXACTLY one of these values, nothing else:
- NEEDS_CHAPTER
- COMPLETE
- type: think
max_tokens: 400
output_key: chapter_dispatch_message
hint: |
Read the next chapter decision above.
If STATUS is COMPLETE: output exactly: none
If STATUS is NEEDS_CHAPTER:
- If ALREADY_IN_PIPELINE is "yes": the chapter has a draft but is not polished.
Write a dispatch message instructing the author to pick up from the existing draft,
run the roundtable and polish sequence, and NOT re-draft from scratch.
Include: "Note: a draft already exists for this chapter in staging -- proceed directly
to chapter_roundtable using the existing draft. Do not re-write the draft."
- If ALREADY_IN_PIPELINE is "no": write a normal chapter dispatch message.
Always include:
- Book: {project.name} ({genre_name})
- Chapter to write: the NEXT_CHAPTER value from the decision
- Chapter title: the CHAPTER_TITLE value
- Characters: {character_profiles}
- Word count target: {chapter_target_words} words
- Instruction: check the most recent polished chapter for continuity,
then write this chapter following the outline
Output ONLY the dispatch message. No preamble.
# Dispatch the next chapter if NEEDS_CHAPTER
- type: tool
action: enqueue_strategy
optional: true
params:
company_slug: "crimson_leaf_publishing"
project_slug: "{project.slug}"
task_type: "book_chapter"
content: "{chapter_dispatch_message}"
- type: reply
target: channel
channel_name: "crimson_leaf_publishing:live-feed"
adjudication:
enabled: false