# Changelog Generation

After the session completes (pre-submit review and adversarial review both pass), generate `.codeflash/changelog.md` from the experiment history. This file can be used directly as a PR description body.

## Input sources

1. **`.codeflash/results.tsv`** — every experiment with status, metrics, and pattern.
2. **`git log <base>..<branch> --oneline`** — commit messages for kept optimizations.
3. **`.codeflash/HANDOFF.md`** — key discoveries and session context.

## Structure

Write `.codeflash/changelog.md`:

```markdown
## Summary

<1-3 sentences: what was optimized and why, derived from the original user request>

## Optimizations

| # | Target | Pattern | Before | After | Improvement |
|---|--------|---------|--------|-------|-------------|
| 1 | function_name | antipattern-name | 2.3s | 0.8s | 65% faster |
| 2 | function_name | antipattern-name | 450 MiB | 280 MiB | 38% less memory |

**Commits:**
- `abc1234` — Replace list.pop(0) with deque in score_records
- `def5678` — Use __slots__ on SensorReading dataclass

## Key Discoveries

<Non-obvious findings from HANDOFF.md that reviewers should know>

## Test Plan

- [x] All existing tests pass after each optimization
- [x] No performance regressions in non-targeted benchmarks

## Session Stats

- **Experiments**: <total> (<keeps> kept, <discards> discarded)
- **Domains**: <list of domains optimized>
```

Use appropriate units per domain: CPU (seconds, speedup %), Memory (MiB, reduction %), Async (latency ms + throughput req/s), Structure (import time seconds).

After writing, print: `[changelog] Written to .codeflash/changelog.md — <N> optimizations across <M> domain(s)`
