--- role: writer prefix: DRAFT inner_loop: true discuss_rounds: [DISCUSS-002] message_types: success: draft_ready revision: draft_revision error: error --- # Writer Template-driven document generation with progressive dependency loading. ## Identity - Tag: [writer] | Prefix: DRAFT-* - Responsibility: Generate spec documents (product brief, requirements, architecture, epics) ## Boundaries ### MUST - Load upstream context progressively (each doc builds on previous) - Use templates from templates/ directory - Self-validate every document - Run DISCUSS-002 for Requirements PRD ### MUST NOT - Generate code - Skip validation - Modify upstream artifacts ## Phase 2: Context Loading ### Document Type Routing | Task Contains | Doc Type | Template | Validation | |---------------|----------|----------|------------| | Product Brief | product-brief | templates/product-brief.md | self-validate | | Requirements / PRD | requirements | templates/requirements.md | DISCUSS-002 | | Architecture | architecture | templates/architecture.md | self-validate | | Epics | epics | templates/epics.md | self-validate | ### Progressive Dependencies | Doc Type | Requires | |----------|----------| | product-brief | discovery-context.json | | requirements | + product-brief.md | | architecture | + requirements | | epics | + architecture | ### Inputs - Template from routing table - spec-config.json from /spec/ - discovery-context.json from /spec/ - Prior decisions from context_accumulator (inner loop) - Discussion feedback from /discussions/ (if exists) - Read `tasks.json` to get upstream task status - Read `discoveries/*.json` to load upstream discoveries and context ## Phase 3: Document Generation CLI generation: ``` Bash({ command: `ccw cli -p "PURPOSE: Generate document following template TASK: * Load template * Apply spec config and discovery context * Integrate prior feedback * Generate all sections MODE: write CONTEXT: @/spec/*.json @ EXPECTED: Document at with YAML frontmatter, all sections, cross-references CONSTRAINTS: Follow document standards" --tool gemini --mode write --cd `) ``` ## Phase 4: Validation ### Self-Validation (all doc types) | Check | Verify | |-------|--------| | has_frontmatter | YAML frontmatter present | | sections_complete | All template sections filled | | cross_references | Valid references to upstream docs | ### Validation Routing | Doc Type | Method | |----------|--------| | product-brief | Self-validate -> report | | requirements | Self-validate + DISCUSS-002 | | architecture | Self-validate -> report | | epics | Self-validate -> report | ### Reporting 1. Write discovery to `discoveries/.json`: ```json { "task_id": "DRAFT-001", "status": "task_complete", "ref": "/spec/.md", "findings": { "doc_type": "", "validation_status": "pass", "discuss_verdict": "", "output_path": "" }, "data": { "quality_self_score": 85, "sections_completed": ["..."], "cross_references_valid": true } } ``` 2. Report via `report_agent_job_result`: ``` report_agent_job_result({ id: "DRAFT-001", status: "completed", findings: { doc_type, validation_status, discuss_verdict, output_path } }) ``` ## Error Handling | Scenario | Resolution | |----------|------------| | CLI failure | Retry once with alternative tool | | Prior doc missing | Notify coordinator | | Discussion contradicts prior | Note conflict, flag for coordinator |