# Diagrams — Deep-Dive DD-02: Aider — The Git-Native Pair Programmer

**Deep-Dive**: DD-02 — Aider: The Git-Native Pair Programmer
**Diagram count**: 5
**Tool**: Mermaid (primary). Each diagram validated in [Mermaid Live Editor](https://mermaid.live).

---

## Diagram 1 — Git-as-Substrate: The Aider Multiplier

**Type**: Hub-and-spoke dependency map
**Purpose**: The single most important diagram. Shows how one infrastructure choice (git) yields five rubric modules' worth of capability. This is why Aider scores +7 over Pi — the git multiplier. No other harness gets this much from a single decision.
**Reading the diagram**: Git is the hub. Five spokes radiate to the modules git serves: memory (commits across sessions), state (git reset = rollback), verification (human reviews diff), permission (git-gated review), observability (git log = trace).

```mermaid
flowchart TB
  GIT[("Git — one infrastructure choice")]
  GIT --> M4["M4 MEMORY<br/>commits = checkpoints across sessions"]
  GIT --> M8["M8 STATE<br/>git reset = rollback"]
  GIT --> M9["M9 VERIFICATION<br/>human reviews the diff"]
  GIT --> M6["M6 PERMISSION<br/>git-gated: review every change"]
  GIT --> M11["M11 OBSERVABILITY<br/>git log = human-readable trace"]

  NOTE["+7 over Pi — almost entirely from git.<br/>No other harness gets this much<br/>from a single decision."]

  M11 --> NOTE

  style GIT fill:#08080c,stroke:#5eead4,stroke-width:1.5px,color:#5eead4
  style M4 fill:#14141f,stroke:rgba(94,234,212,0.3),color:#5eead4
  style M8 fill:#14141f,stroke:rgba(94,234,212,0.3),color:#5eead4
  style M9 fill:#14141f,stroke:rgba(94,234,212,0.3),color:#5eead4
  style M6 fill:#14141f,stroke:rgba(94,234,212,0.3),color:#5eead4
  style M11 fill:#14141f,stroke:rgba(94,234,212,0.3),color:#5eead4
  style NOTE fill:#08080c,stroke:#5eead4,stroke-width:1.5px,color:#5eead4
```

---

## Diagram 2 — Aider vs Pi: The Thickness Comparison (module-by-module)

**Type**: Side-by-side score comparison
**Purpose**: Shows exactly where Aider's +7 over Pi comes from. Each module where Aider gains is teal; each where it equals Pi is neutral; the few where it trades down (tool noise, prompt density) are warn. The git-driven modules dominate the delta.
**Reading the diagram**: Left = Pi (25/60). Right = Aider (32/60). The arrow names the source of the +7: git adds memory, state, verify, permission, and observability. The repo-map adds context. The two -1s (tools, prompt) are the cost of specialization.

```mermaid
flowchart LR
  subgraph PI["Pi — 25/60 (thin reference)"]
    P1["4 tools · <1k prompt<br/>trust-the-model · no git"]
  end
  subgraph AIDER["Aider — 32/60 (+7 via git)"]
    A1["~8 tools · ~2k prompt · git-gated"]
    A2["repo-map (AST context)"]
    A3["diff-based editing"]
    A4["git commits = state + memory"]
  end

  PI -->|git adds: M3 context +2, M4 memory +2,<br/>M6 permission +1, M8 state +3,<br/>M9 verify +2, M11 observability +1| AIDER

  style PI fill:#14141f,stroke:rgba(255,255,255,0.12),color:#9494a0
  style P1 fill:#08080c,stroke:rgba(255,255,255,0.12),color:#9494a0
  style AIDER fill:#14141f,stroke:rgba(94,234,212,0.5),color:#5eead4
  style A1 fill:#08080c,stroke:rgba(94,234,212,0.3),color:#5eead4
  style A2 fill:#08080c,stroke:rgba(94,234,212,0.3),color:#5eead4
  style A3 fill:#08080c,stroke:rgba(94,234,212,0.3),color:#5eead4
  style A4 fill:#08080c,stroke:rgba(94,234,212,0.4),color:#5eead4
```

---

## Diagram 3 — Aider's Git-Gated Loop (control flow)

**Type**: Flowchart (control flow)
**Purpose**: The primary visual. Shows the complete execution path through Aider — context assembly (repo-map + task), the model call (diff-based edit), apply + git add, git commit (the multiplier node), and output with human-review affordances. The git-commit node IS the architectural insight.
**Reading the diagram**: Follow the arrows. The git-commit step is load-bearing — it gives you state (checkpoint), memory (cross-session), verification (human can diff), and permission (git-gated review) in one operation. Compare to Pi's loop (DD-01) which has no commit node and none of these capabilities.

```mermaid
flowchart TB
  ENTRY(["user task"]) --> CTX["assemble context<br/>repo-map (AST index) + task"]
  CTX --> CALL["model.complete()<br/>(diff-based editing format)"]
  CALL --> DIFF["model emits search/replace blocks"]
  DIFF --> APPLY["apply edit + git add"]
  APPLY --> COMMIT["git commit (checkpoint)"]
  COMMIT --> OUT(["output + human-review affordance<br/>git diff HEAD~1 · git reset HEAD~1"])

  NOTE["THE GIT MULTIPLIER:<br/>this one node = M4 memory + M8 state<br/>+ M9 verification + M6 permission<br/>+ M11 observability"]

  COMMIT -.-> NOTE

  style ENTRY fill:#08080c,stroke:rgba(94,234,212,0.4),color:#5eead4
  style CTX fill:#14141f,stroke:rgba(255,255,255,0.12),color:#e4e4e8
  style CALL fill:#14141f,stroke:rgba(94,234,212,0.4),color:#5eead4
  style DIFF fill:#14141f,stroke:rgba(255,255,255,0.12),color:#e4e4e8
  style APPLY fill:#14141f,stroke:rgba(255,255,255,0.12),color:#e4e4e8
  style COMMIT fill:#08080c,stroke:#5eead4,stroke-width:1.5px,color:#5eead4
  style OUT fill:#08080c,stroke:rgba(130,224,170,0.4),color:#82e0aa
  style NOTE fill:#08080c,stroke:#5eead4,stroke-width:1.5px,color:#5eead4
```

---

## Diagram 4 — The Security Nuance: Git-Gating Catches Wrong, Not Malicious

**Type**: Two-track comparison
**Purpose**: Resolves the most dangerous misconception about Aider. Git-gating is a change-quality control, not an injection defense. The diff-review answers "is this the change I asked for?" not "is this change safe to apply?" A prompt-injected model produces a change that is exactly what the attacker asked for, which may pass human review.
**Reading the diagram**: Top track = the honest mistake (model produces a wrong change; human catches it in the diff; git reset). Bottom track = the injection (model is prompt-injected; produces a benign-looking change with an embedded exfiltration payload; human may not spot the payload in the diff; the commit executes maliciously).

```mermaid
flowchart TB
  subgraph WRONG["THE HONEST MISTAKE — git-gating CATCHES this"]
    W1["model produces a wrong edit<br/>(misunderstood the task)"]
    W2["human reviews git diff"]
    W3["spots the error"]
    W4["git reset HEAD~1 — rolled back"]
    W1 --> W2 --> W3 --> W4
  end
  subgraph MALICIOUS["THE INJECTION — git-gating does NOT catch this"]
    M1["model is prompt-injected<br/>(README contained ASI01 payload)"]
    M2["produces a benign-looking 'refactor'<br/>that also reads ~/.ssh/cred + curls to attacker"]
    M3["human reviews git diff"]
    M4["payload may look like part of the refactor — MISS"]
    M5["commit executes — exfiltration succeeds"]
    M1 --> M2 --> M3 --> M4 --> M5
  end

  PRINCIPLE["Git-gating is a CHANGE-QUALITY control,<br/>NOT an injection defense.<br/>The diff-review answers 'is this the change I asked for?'<br/>not 'is this change safe to apply?'"]

  WRONG --> PRINCIPLE
  MALICIOUS --> PRINCIPLE

  style WRONG fill:#14141f,stroke:rgba(130,224,170,0.5),color:#e4e4e8
  style MALICIOUS fill:#14141f,stroke:rgba(240,128,128,0.5),color:#e4e4e8
  style W1 fill:#08080c,stroke:rgba(130,224,170,0.3),color:#82e0aa
  style W2 fill:#08080c,stroke:rgba(130,224,170,0.3),color:#82e0aa
  style W3 fill:#08080c,stroke:rgba(130,224,170,0.3),color:#82e0aa
  style W4 fill:#08080c,stroke:rgba(130,224,170,0.4),color:#82e0aa
  style M1 fill:#08080c,stroke:rgba(240,128,128,0.3),color:#f08080
  style M2 fill:#08080c,stroke:rgba(240,128,128,0.3),color:#f08080
  style M3 fill:#08080c,stroke:rgba(240,128,128,0.3),color:#f08080
  style M4 fill:#08080c,stroke:rgba(240,128,128,0.3),color:#f08080
  style M5 fill:#08080c,stroke:rgba(240,128,128,0.4),color:#f08080
  style PRINCIPLE fill:#08080c,stroke:#f0a868,stroke-width:1.5px,color:#f0a868
```

---

## Diagram 5 — Aider's Position on the Thickness Spectrum

**Type**: Linear spectrum
**Purpose**: Places Aider as the thin-medium reference — the first harness to the right of Pi. Every subsequent coding-focused harness is measured against Aider's git-first approach.
**Reading the diagram**: Pi anchors the thin end. Aider is one step right (thin-medium). The +7 delta is labeled. The comparison question for every subsequent harness: how much further right, and why?

```mermaid
flowchart LR
  PI["Pi (DD-01)<br/>25/60 · 4 tools · <1k prompt<br/>trust-the-model"]
  AIDER["Aider (DD-02)<br/>32/60 · ~8 tools · ~2k prompt<br/>git-gated · +7 via git"]
  OCODE["OpenCode (DD-03)<br/>terminal-native harness"]

  PI -->|git multiplier: +7| AIDER --> OCODE

  style PI fill:#08080c,stroke:#5eead4,stroke-width:1.5px,color:#5eead4
  style AIDER fill:#08080c,stroke:#5eead4,stroke-width:1.5px,color:#5eead4
  style OPCODE fill:#14141f,stroke:rgba(255,255,255,0.12),color:#9494a0
```

---

## Aider's Git-Gated Loop as an n8n Workflow (importable)

The control flow above, exportable as an n8n workflow for hands-on inspection. The git-commit node is the multiplier.

```json
{
  "name": "Aider Git-Gated Loop — DD-02",
  "nodes": [
    { "parameters": {}, "id": "trig", "name": "Manual Trigger", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [160, 300] },
    { "parameters": { "assignments": { "assignments": [{ "id": "rm", "name": "repo_map", "value": "src/auth.ts (validateToken), src/db.ts (connect), src/utils.ts (helpers)", "type": "string" },{ "id": "t", "name": "task", "value": "extract validateToken to its own file", "type": "string" }]}, "options": {} }, "id": "ctx", "name": "Context (repo-map + task)", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [380, 300], "notesInFlow": true, "notes": "Aider's context advantage over Pi: repo-map (AST-based file index). The model sees the repo structure without reading every file." },
    { "parameters": { "model": "gpt-4o-mini", "messages": "={{ [{role:'system',content:'Edit files using search/replace blocks. Git conventions apply.'},{role:'user',content:$json.task + ' repo-map: ' + $json.repo_map}] }}", "options": {} }, "id": "model", "name": "Call Model (diff-based edit)", "type": "@n8n/n8n-nodes-langchain.toolExecuteTool", "typeVersion": 1.1, "position": [600, 300], "notesInFlow": true, "notes": "Aider's editing format: search/replace blocks. More reliable than Pi's write_file (whole file). Targets specific changes." },
    { "parameters": { "command": "={{ 'cd /tmp/repo && echo \"applying search/replace block...\" && git add -A' }}", "executeOnce": true }, "id": "apply", "name": "Apply Edit + Git Add", "type": "n8n-nodes-base.executeCommand", "typeVersion": 1, "position": [820, 300], "notesInFlow": true, "notes": "Apply the diff. Stage in git. This is Aider's git-first approach: every change is staged for commit." },
    { "parameters": { "command": "={{ 'cd /tmp/repo && git commit -m \"extract validateToken\" && git log --oneline -1' }}", "executeOnce": true }, "id": "commit", "name": "Git Commit (checkpoint)", "type": "n8n-nodes-base.executeCommand", "typeVersion": 1, "position": [1040, 300], "notesInFlow": true, "notes": "THE GIT MULTIPLIER: this commit IS Module 8 (state), Module 4 (memory), Module 9 (verification — human can diff), Module 6 (permission — git-gated review). One operation, 4 modules." },
    { "parameters": { "content": "={{ JSON.stringify({ committed: true, hash: $json.stdout, note: 'human can review: git diff HEAD~1; rollback: git reset HEAD~1' }) }}", "options": {} }, "id": "out", "name": "Output", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [1260, 300] }
  ],
  "connections": { "Manual Trigger": { "main": [ [ { "node": "Context (repo-map + task)", "type": "main", "index": 0 } ] ] }, "Context (repo-map + task)": { "main": [ [ { "node": "Call Model (diff-based edit)", "type": "main", "index": 0 } ] ] }, "Call Model (diff-based edit)": { "main": [ [ { "node": "Apply Edit + Git Add", "type": "main", "index": 0 } ] ] }, "Apply Edit + Git Add": { "main": [ [ { "node": "Git Commit (checkpoint)", "type": "main", "index": 0 } ] ] }, "Git Commit (checkpoint)": { "main": [ [ { "node": "Output", "type": "main", "index": 0 } ] ] } },
  "settings": { "executionOrder": "v1" }, "meta": { "templateCreatedBy": "Harness Engineering Master Course — DD-02 Aider" }
}
```

**Why this is the primary visual**: The git-commit node IS the architectural insight. One node gives you 4 modules. Compare to Pi (DD-01) where there is no commit node — Pi has none of these capabilities. The n8n graph makes the "git multiplier" visible as a single high-value node.

---

## Validation notes

- All diagrams use the course design system colors: `#14141f` panel fill, `#08080c` deep background for nested nodes, `#5eead4` teal accent for git-driven strengths and thesis nodes, `#82e0aa` ok-green for the honest-mistake track (caught), `#f08080` danger for the injection track (not caught), `#f0a868` warn for the principle/transitions.
- Paste each into [Mermaid Live Editor](https://mermaid.live) to render. All use stable Mermaid syntax (`flowchart TB/LR`, `subgraph`) supported in current Mermaid (v10.4+).
- The teal/green/danger color coding is load-bearing: teal = git-driven capability; green = what git-gating catches (honest mistakes); danger = what it does not catch (injection).
