---
estimated_steps: 22
estimated_files: 1
skills_used: []
---

# T02: Rewrite stage 5 prompt output format for nested sections and citations

Rewrite the output format section of `prompts/stage5_synthesis.txt` to produce the new list-of-objects body_sections structure with inline [N] citation markers. Preserve all voice, tone, synthesis philosophy, and body section naming guidance. Back up the current prompt before editing.

## Steps

1. Back up: `cp prompts/stage5_synthesis.txt prompts/stage5_synthesis.$(date +%Y%m%d_%H%M%S).bak`
2. Read the full prompt file.
3. Update the `## Body sections structure` section (line ~46): add a paragraph about H3 subsections. Sections can contain 2-3 subsections when a topic has distinct sub-aspects. Subsections are optional — flat sections (no subsections) are fine when the topic doesn't warrant splitting.
4. Add a new `## Citation rules` section after `## Body sections structure`:
   - `[N]` after specific factual claims (settings, values, frequencies, routing decisions) where N is the zero-indexed moment from the input.
   - `[N,M]` when a claim draws from multiple moments.
   - Place citation at end of sentence before period: "Set the LFO to 3/16th timing [2]."
   - Every section must have at least one citation.
   - Citations only on technical/factual claims, not general observations.
   - A moment can be cited multiple times.
5. Rewrite `## Output format` section (line ~163): replace the JSON example with new structure using `body_sections` as a list of objects with heading/content/subsections. Include citation markers in the example prose. Add `body_sections_format: "v2"` field.
6. Update `## Field rules` section (line ~199): change body_sections description from "Dict of section_name → prose" to "List of section objects with heading, content, and optional subsections. Each section's content contains inline [N] citation markers."
7. Verify: the prompt file is valid text, contains the new JSON example structure, has citation rules, and all other sections (voice, tone, plugin rules, etc.) are unchanged.

## Must-Haves

- [ ] Current prompt backed up before changes
- [ ] body_sections in JSON example is a list of objects with heading/content/subsections
- [ ] Citation rules section exists with [N] and [N,M] format
- [ ] body_sections_format: "v2" in JSON example
- [ ] All non-output-format sections preserved unchanged
- [ ] Subsections shown as optional (empty array or omitted in some example sections)

## Inputs

- ``prompts/stage5_synthesis.txt` — current v4 prompt (206 lines)`

## Expected Output

- ``prompts/stage5_synthesis.txt` — rewritten with nested sections format, citation rules, and v2 JSON example`

## Verification

cd /home/aux/projects/content-to-kb-automator && python -c "import json; t=open('prompts/stage5_synthesis.txt').read(); assert 'body_sections_format' in t; assert 'Citation rules' in t or 'citation rules' in t.lower(); assert '\"subsections\"' in t; print('Prompt v5 structure OK')"
