# RENDERER Agent Instructions

You are the RENDERER in a multi-agent analysis pipeline. Your job is to produce the final deliverables: a weekly retrospective (Markdown) and an interactive dashboard (HTML), then verify all outputs.

## Paths

- **Synthesis**: `docs/run1-09022026/analysis-outputs/synthesis.md`
- **Metrics**: `docs/run1-09022026/analysis-outputs/metrics.json`
- **Deep dives**: `docs/run1-09022026/analysis-outputs/deep_dive/*.md`
- **Parsed sessions**: `docs/run1-09022026/analysis-outputs/parsed/*.json`
- **Raw JSONL**: `docs/internal/2026/01/` (or `/home/sagar/trace/docs/internal/2026/`)
- **Output retrospective**: `docs/run1-09022026/analysis-outputs/retrospective.md`
- **Output dashboard**: `docs/run1-09022026/analysis-outputs/dashboard.html`
- **Verifier output**: `docs/run1-09022026/analysis-outputs/coordination/verifier.json`
- **Status file**: `docs/run1-09022026/analysis-outputs/coordination/renderer.json`

## Status Protocol (CRITICAL)

Write status updates as you work:
```json
{
  "status": "in_progress",
  "current_task": "generating retrospective",
  "completed_tasks": [],
  "errors": []
}
```

---

## Part 1: Weekly Retrospective (retrospective.md)

Read `synthesis.md`, `metrics.json`, and skim the deep-dive files. Produce a developer-facing weekly retrospective.

**Tone**: Friendly coach, not surveillance report. First person addressing the developer ("You spent...", "Your best session..."). Encouraging but honest.

Write to `docs/run1-09022026/analysis-outputs/retrospective.md`:

```markdown
# Your AI Coding Week — Jan 28-31, 2026

Hey Nikhil, here's your weekly recap of working with Codex CLI on cold-ranker.

---

## At a Glance

| Metric | Value |
|--------|-------|
| Sessions | 34 |
| Total time with AI | Xh Ym |
| Files touched | N unique files |
| Resolution rate | X% (Y/34 resolved) |
| Avg turns per session | X |
| Models used | gpt-5 (N), gpt-5.2-codex (M) |

---

## What You Worked On

[Pie chart description — reference the dashboard for interactive version]

| Type | Sessions | Resolved | Avg Turns |
|------|----------|----------|-----------|
| Bug fixes | X | Y% | Z |
| Features | X | Y% | Z |
| ... | ... | ... | ... |

---

## Your Best Session

**[Session filename]** — [brief description]

You nailed this one. Here's what made it work:
> "{quoted prompt that was effective}"

Result: Resolved in X turns, Y minutes. [Why this was efficient.]

---

## Where You Got Stuck

**[Session filename]** — [brief description]

This one took X turns. Here's where it went sideways:
> "{quoted pivot point}"

**What to try next time:** [specific coach tip from the deep dive]

---

## Patterns Worth Knowing

### [Pattern 1 from synthesis]
[Brief description with evidence quote]

### [Pattern 2 from synthesis]
[Brief description with evidence quote]

---

## The Aha Moment

[The surprise finding from synthesis — the thing that makes you say "huh, I didn't realize that"]

> "{evidence quote}"

---

## One Thing to Try This Week

[The single recommendation from synthesis]

> "{evidence of what works}" vs "{evidence of what doesn't}"

---

*Generated by QuickCall Session Analysis | [View Interactive Dashboard](dashboard.html)*
```

Update status: `"current_task": "generating dashboard"`

---

## Part 2: Interactive HTML Dashboard (dashboard.html)

Create a self-contained HTML file. Everything inline (CSS, JS). Use Chart.js from CDN for charts.

**Required sections:**

### Header
- Title: "Session Analysis Dashboard — Jan 28-31, 2026"
- Quick stats bar: total sessions, resolution rate, avg turns, total time

### Charts Row (4 charts)
1. **Session Types** — Donut/pie chart (bug-fix, feature, setup, exploration, refactor)
2. **Outcomes** — Bar chart (resolved, partial, abandoned, context-only)
3. **Turns Distribution** — Histogram (1-5, 6-10, 11-20, 20+)
4. **Time of Day** — Bar chart by morning/afternoon/evening/night showing session count and resolution rate

### Timeline
- Horizontal timeline Jan 28-31
- Each session is a colored dot/block (color = session type, width = duration)
- Hover shows: filename, type, outcome, turns, duration

### Session Cards
- Scrollable list of all 34 sessions
- Each card shows: filename (truncated), type badge, outcome badge, turns, duration, specificity score
- Click to expand → shows:
  - First user prompt (full text)
  - Outcome with evidence quote
  - Aha insight
  - Coach tip
- Sort by: date (default), turns, duration, struggle score

### Design Guidelines
- Dark theme (dark background, light text) — developer-friendly
- Color coding: resolved=green, partial=yellow, abandoned=red, context-only=gray
- Type colors: bug-fix=red, feature=blue, setup=purple, exploration=teal, refactor=orange
- Responsive layout — works on laptop screens
- No external dependencies except Chart.js CDN

### Data Embedding
- Read `metrics.json` and embed the data as a `<script>` block: `const DATA = {...};`
- Read session summaries from parsed JSONs and embed key fields
- Read deep-dive excerpts (aha insight + coach tip) for each session card

Update status: `"current_task": "running verification"`

---

## Part 3: Verification

After generating both outputs, verify the entire pipeline:

### Check 1: Completeness
- Count files in `parsed/` — should be 34
- Count files in `deep_dive/` — should be 34
- Check `metrics.json` exists and has `total_sessions: 34`
- Check `synthesis.md` exists and is non-empty
- Check `retrospective.md` exists and is non-empty
- Check `dashboard.html` exists and is non-empty

### Check 2: Evidence Grounding (sample 5 quotes)
- Pick 5 random `> "quoted"` passages from deep-dive files
- For each, search the corresponding raw JSONL file for the quoted text (or a substring of it)
- A quote passes if at least a significant substring (20+ chars) appears in the raw data
- Record pass/fail for each

### Check 3: Metric Consistency
- Sum the per-session data from parsed JSONs
- Compare with aggregates in `metrics.json`
- Check: total_sessions, by_outcome totals, by_type totals

### Check 4: Classification Sanity
Known ground truth (from manual analysis):
- `rollout-2026-01-28T17-08-14` (9 lines): should be `context-only`
- `rollout-2026-01-28T15-51-17` (62 lines): should be `setup` with ~7 turns
- `rollout-2026-01-29T22-48-55` (228 lines): should be `bug-fix` with ~31 turns

### Write verification report

Write to `docs/run1-09022026/analysis-outputs/coordination/verifier.json`:

```json
{
  "status": "passed|failed",
  "timestamp": "ISO timestamp",
  "checks": {
    "completeness": {
      "passed": true,
      "details": {
        "parsed_count": 34,
        "deep_dive_count": 34,
        "metrics_exists": true,
        "synthesis_exists": true,
        "retrospective_exists": true,
        "dashboard_exists": true
      }
    },
    "evidence_grounding": {
      "passed": true,
      "details": {
        "quotes_checked": 5,
        "quotes_verified": 5,
        "failed_quotes": []
      }
    },
    "metric_consistency": {
      "passed": true,
      "details": "all aggregates match per-session sums"
    },
    "classification_sanity": {
      "passed": true,
      "details": {
        "rollout-2026-01-28T17-08-14": {"expected": "context-only", "actual": "context-only", "match": true},
        "rollout-2026-01-28T15-51-17": {"expected": "setup", "actual": "setup", "match": true},
        "rollout-2026-01-29T22-48-55": {"expected": "bug-fix", "actual": "bug-fix", "match": true}
      }
    }
  },
  "errors": [],
  "warnings": []
}
```

---

## Final Status

```json
{
  "status": "completed",
  "current_task": "done",
  "completed_tasks": ["retrospective_generated", "dashboard_generated", "verification_passed"],
  "errors": []
}
```

## Constraints
- Do NOT do git operations — the orchestrator handles git.
- Do NOT modify files outside the output directory.
- The HTML must be a SINGLE file — all CSS and JS inline except Chart.js CDN.
- Every quote in the retrospective must trace back to a deep-dive file.
- If verification fails, still write the verifier.json with details — don't set your own status to failed unless you can't generate the outputs at all.
