diff --git a/templates/book_chapter.yml b/templates/book_chapter.yml index 456c543e..9f8e1802 100644 --- a/templates/book_chapter.yml +++ b/templates/book_chapter.yml @@ -293,9 +293,26 @@ steps: Start the chapter directly with the chapter title and first line. No preamble or commentary within the chapter text. - # Commit chapter draft now -- last_text() = self-check output (step 2). Must come before - # PASS 3 think so the character-state extraction does not overwrite last_text(). + # Extract chapter_number and chapter_ref from the PASS 1 chapter text before any document + # steps run. Without this, {chapter_number}/{chapter_ref} are unresolved at document time + # and filenames become "Chapter_chapter-number_draft.md" (slug-cleaned literal key names). + # source_step: 1 = PASS 1 output, which begins "Chapter N: Title". Cheap call (max_tokens: 150). + - type: package + source_step: 1 + max_tokens: 150 + hint: | + The chapter draft above starts with a chapter title line such as "Chapter 5: Some Title". + Extract: + - chapter_number: the plain chapter number as a string (e.g. "5") + - chapter_ref: zero-padded two-digit format (e.g. "ch-05" for chapter 5) + schema: + chapter_number: string + chapter_ref: string + + # Commit chapter draft now. chapter_number is in ContextVars from the package step above. + # source_step: 2 = SELF-CHECK output (step 2); required because LastText() now = package JSON. - type: document + source_step: 2 filename: "Chapter_{chapter_number}_draft" primary_deliverable: true strip_before_marker: "---BEGIN CHAPTER---" @@ -416,14 +433,15 @@ steps: - type: rag_write asset_id: "character-state" - source_step: 4 # PASS 3 character-state extraction; explicit to avoid last_text() falling back to chapter text + source_step: 5 # PASS 3 character-state extraction; explicit to avoid last_text() falling back to chapter text max_chars: 4000 - type: document + source_step: 5 filename: "character-state-{chapter_ref}" - type: package - source_step: 4 # PASS 3 -- character-state extraction (compact, describes permanent changes) + source_step: 5 # PASS 3 -- character-state extraction (compact, describes permanent changes) max_tokens: 4000 hint: | The draft chapter has been written, self-checked, and committed.