---
estimated_steps: 13
estimated_files: 2
skills_used: []
---

# T01: Write stage5_compose.txt composition prompt

Create the composition prompt that instructs the LLM to merge new video moments into an existing technique page. The prompt receives three inputs: existing page JSON, new moments list, and creator name. Must define merge semantics (preserve existing prose, integrate new material into existing sections or create new ones), deduplication rules (enrich rather than repeat), citation re-indexing scheme (existing [0]-[N-1], new [N]-[N+M-1]), and output format (same SynthesisResult/SynthesizedPage v2 schema as synthesis).

Steps:
1. Read `prompts/stage5_synthesis.txt` to understand voice/tone rules and v2 output format — the compose prompt must reference the same writing standards but NOT duplicate them (the compose prompt is self-contained).
2. Write `prompts/stage5_compose.txt` with these sections:
   - Role/context preamble explaining the composition task
   - Input format: `<existing_page>`, `<existing_moments>`, `<new_moments>`, `<creator>` XML tags
   - Merge rules: preserve existing prose verbatim where correct; add new sections for genuinely new territory; enrich existing sections with new detail where topics overlap
   - Deduplication guidance with examples of 'enriching' vs 'duplicating'
   - Citation re-indexing rules: existing moments keep indices [0]-[N-1], new moments get [N]-[N+M-1], composed output uses the unified index space
   - Section ordering: maintain workflow-order rule from synthesis
   - Output format: same SynthesisResult JSON with v2 body_sections (list[BodySection])
   - Include a concrete JSON example showing composed output with mixed old/new citations
3. Validate the prompt structurally: check that the JSON example parses as valid SynthesisResult, citation rules section mentions the dual-index scheme, merge rules section is present.

## Inputs

- ``prompts/stage5_synthesis.txt` — voice/tone rules and v2 output format to reference`
- ``backend/pipeline/schemas.py` — SynthesisResult/SynthesizedPage/BodySection schema definitions`

## Expected Output

- ``prompts/stage5_compose.txt` — complete composition prompt with merge rules, citation re-indexing, dedup guidance, and v2 output example`

## Verification

python3 -c "
import json, pathlib, re
p = pathlib.Path('prompts/stage5_compose.txt')
assert p.exists(), 'prompt file missing'
txt = p.read_text()
assert len(txt) > 2000, f'prompt too short: {len(txt)} chars'
for section in ['existing_page', 'new_moments', 'existing_moments', 'creator', 'Citation', 'dedup', 'Merge']:
    assert any(s.lower() in txt.lower() for s in [section]), f'missing section: {section}'
# Check JSON example is valid
json_match = re.search(r'```json\n(.*?)```', txt, re.DOTALL)
assert json_match, 'no JSON example found'
json.loads(json_match.group(1))
print('All structural checks passed')
"
