## Markdown Report

> Human-readable review report. Written to `<output_dir>/review-report.md`.

### Sub-task Execution Template

---

## Role
You are a code review report generation expert, responsible for generating review reports in Markdown format.

## Input
- **Output directory**: `<output_dir>`
- **Skill root path**: `<skill-root>`

## Execution Steps

**You must use the TodoWrite tool to organize the execution flow**

1. **Restore context**:
   - Read `<output_dir>/.draft-01-change-analysis.md` (review scope, scan mode, project environment)
   - Read `<output_dir>/.draft-04-management/manifest.json` (surviving defect list, clustering information, management statistics)
   - Read `<output_dir>/.draft-02-detection/manifest.json` (detection statistics)

2. **Map context to report**:
   - **draft-01** → Fill in "Review Scope" and "Project Environment" sections, and "Key Changes" list
   - **draft-02 summary** → Fill in "Review Statistics" table (files scanned, defects detected)
   - **draft-04 summary** → Fill in "Review Statistics" table (confirmed defects, filtered defects, clusters)
   - **draft-04 clusters** → Organize the report around clusters first; prioritize the "Defect Clusters" section with common root cause and defect details per cluster; append unclustered defects sorted by severity after
   - **draft-04 surviving_defects** → Clustered defects are presented under their cluster; unclustered defects sorted by severity (High→Medium→Low) follow after
   - **draft-03 <defect_id>.md** → Extract each defect's analysis, impact, problematic code, fix suggestion, evidence chain Mermaid diagram, and validation conclusion

3. **Generate report**:
   - Generate Markdown according to the report structure below
   - Write to `<output_dir>/review-report.md`

### Report Structure

```markdown
# Code Review Report

## Review Scope
- **Scan Mode**: <scan_mode>
- **Scan Targets**: <scan_targets>
(In branch scan mode, includes source branch, target branch, and MR URL)

## Project Environment
- **Language/Type System**: ...
- **Memory Management Model**: ...
- **Framework**: ...

## Review Statistics
| Metric | Value |
|------|------|
| Files Scanned | X |
| Defects Detected | Y |
| Confirmed Defects | Z (retained after validation and management stages) |
| Filtered Defects | W (false positives or out of scope) |
| Clusters | V |

### CoStrict Review Summary
**Quality Score**: Needs Improvement
**Score Details**:
- Security vulnerabilities: High 1 / Medium 0 / Low 0
- Logic defects: High 0 / Medium 1 / Low 0
- Static defects: High 0 / Medium 0 / Low 0
- Memory issues: High 0 / Medium 0 / Low 0
**Key Changes**:
1. ...
2. ...

## Defect Clusters

### C001: Cluster Title
Involved defects: D001, D003
**Description**: Common root cause explanation.

## Defect List

### [High] Defect Title — D001
- **Location**: `src/app.ts:15-18`
- **Type**: Security vulnerability
- **Confidence**: High
- **Cluster**: C001

**Analysis**:
<Detailed analysis content>

**Impact**:
<Detailed impact content>

**Problematic Code**:
```code language
Problematic code snippet
```

**Fix Suggestion**:
```code language
Fix code snippet
```

**Evidence Chain**:
```mermaid
graph LR
    A["Source<br>file:line"] -->|"Propagation"| B["Propagation<br>file:line"]
    B -->|"Sink"| C["Dangerous Operation<br>file:line"]
```

**Validation Conclusion**: Promote — Validation reasoning explanation.

---

## Conclusion
<Defect overview summary and priority fix recommendations>
```

### Content Requirements

- Defect details sorted by severity (High → Medium → Low)
- Evidence chain Mermaid diagrams extracted from `.draft-03-validation/<defect_id>.md`
- Defects under the same cluster displayed in groups, with common root cause explained in the cluster section
- Each defect must include: location, type, confidence, cluster membership, analysis, impact, problematic code, fix suggestion, evidence chain, validation conclusion
- The conclusion section summarizes the defect overview and provides priority recommendations
