# goodhart-labs/beat-stockfish architecture

> Architecture diagram of the GitHub repository goodhart-labs/beat-stockfish, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/goodhart-labs/beat-stockfish
- Repository: https://github.com/goodhart-labs/beat-stockfish

## Overview

This repository packages a chess-playing evaluation: the runner creates isolated episodes, sets up the task, lets a model act through a bash tool, then runs the shipped grader and records a score. Within an episode, the agent uses the arena client to communicate with the authoritative match service; that service tracks the game and can relay UCI engine traffic. Grading checks the service-written state against a shared contract. The graph focuses on runtime behavior, not image construction. Some runner-to-episode details are documented rather than fully visible in the excerpts.

Main entry points: [`run/rollout.py`](https://github.com/goodhart-labs/beat-stockfish/blob/main/run/rollout.py) (Episode runner), [`task_assets/matchd.py`](https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/matchd.py) (Match service), [`task.py`](https://github.com/goodhart-labs/beat-stockfish/blob/main/task.py) (Task setup), [`bases/inspect-runner/shim-src/run_grader.py`](https://github.com/goodhart-labs/beat-stockfish/blob/main/bases/inspect-runner/shim-src/run_grader.py) (Grader launcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_evaluation["Evaluation runner"]
  node_runner["Episode runner<br/>[rollout.py]"]
  node_variant_config["Variant manifest"]
end

subgraph group_episode["Episode interaction"]
  node_agent(("Playing agent"))
  node_task_setup["Task setup<br/>[task.py]"]
  node_arena["Arena client<br/>[arena.py]"]
  node_bash_tool["Bash tool<br/>[rollout.py]"]
end

subgraph group_match["Match services"]
  node_match_service["Match service<br/>[matchd.py]"]
  node_match_state[("Authoritative match state")]
  node_opponent_engine["Opponent engine"]
  node_engine_relay["UCI engine relay<br/>[matchd.py]"]
end

subgraph group_grading["Grading"]
  node_state_contract["State contract"]
  node_grader_shim["Grader launcher<br/>[run_grader.py]"]
  node_grader["Episode grader<br/>[grader.py]"]
  node_grade_result["Recorded grade"]
end

node_operator(("Evaluation operator"))
node_model(("Model provider"))

node_operator -->|"starts runs"| node_runner
node_runner -->|"reads variants"| node_variant_config
node_runner -->|"requests completions"| node_model
node_runner -->|"runs setup"| node_task_setup
node_task_setup -->|"starts service"| node_match_service
node_task_setup -->|"renders prompt"| node_agent
node_runner -->|"provides tool"| node_bash_tool
node_agent -->|"issues commands"| node_bash_tool
node_agent -->|"uses client"| node_arena
node_arena -->|"requests game actions"| node_match_service
node_match_service -->|"writes state"| node_match_state
node_match_service -->|"uses state shape"| node_state_contract
node_match_service -->|"runs opponent"| node_opponent_engine
node_match_service -->|"serves UCI relay"| node_engine_relay
node_engine_relay -->|"starts engine"| node_opponent_engine
node_runner -->|"runs grading"| node_grader_shim
node_grader_shim -->|"invokes grader"| node_grader
node_grader -->|"imports contract"| node_state_contract
node_grader -->|"reads state"| node_match_state
node_grader_shim -->|"writes grade"| node_grade_result
node_runner -->|"reads score"| node_grade_result

click node_runner "https://github.com/goodhart-labs/beat-stockfish/blob/main/run/rollout.py"
click node_variant_config "https://github.com/goodhart-labs/beat-stockfish/blob/main/generated/runtime-variants.json"
click node_task_setup "https://github.com/goodhart-labs/beat-stockfish/blob/main/task.py"
click node_arena "https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/arena.py"
click node_match_service "https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/matchd.py"
click node_state_contract "https://github.com/goodhart-labs/beat-stockfish/blob/main/grader/submission_contract.py"
click node_engine_relay "https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/matchd.py"
click node_grader_shim "https://github.com/goodhart-labs/beat-stockfish/blob/main/bases/inspect-runner/shim-src/run_grader.py"
click node_grader "https://github.com/goodhart-labs/beat-stockfish/blob/main/grader/grader.py"
click node_bash_tool "https://github.com/goodhart-labs/beat-stockfish/blob/main/run/rollout.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_variant_config toneBlue
class node_agent,node_task_setup,node_arena,node_bash_tool toneAmber
class node_match_service,node_match_state,node_opponent_engine,node_engine_relay toneMint
class node_state_contract,node_grader_shim,node_grader,node_grade_result toneRose
class node_operator,node_model toneIndigo
```

## Components

### Evaluation runner

- [Episode runner](https://github.com/goodhart-labs/beat-stockfish/blob/main/run/rollout.py): `run/rollout.py`
- [Variant manifest](https://github.com/goodhart-labs/beat-stockfish/blob/main/generated/runtime-variants.json): `generated/runtime-variants.json`

### Episode interaction

- **Playing agent**
- [Task setup](https://github.com/goodhart-labs/beat-stockfish/blob/main/task.py): `task.py`
- [Arena client](https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/arena.py): `task_assets/arena.py`
- [Bash tool](https://github.com/goodhart-labs/beat-stockfish/blob/main/run/rollout.py): `run/rollout.py`

### Match services

- [Match service](https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/matchd.py): `task_assets/matchd.py`
- **Authoritative match state**
- **Opponent engine**
- [UCI engine relay](https://github.com/goodhart-labs/beat-stockfish/blob/main/task_assets/matchd.py): `task_assets/matchd.py`

### Grading

- [State contract](https://github.com/goodhart-labs/beat-stockfish/blob/main/grader/submission_contract.py): `grader/submission_contract.py`
- [Grader launcher](https://github.com/goodhart-labs/beat-stockfish/blob/main/bases/inspect-runner/shim-src/run_grader.py): `bases/inspect-runner/shim-src/run_grader.py`
- [Episode grader](https://github.com/goodhart-labs/beat-stockfish/blob/main/grader/grader.py): `grader/grader.py`
- **Recorded grade**

### Other components

- **Evaluation operator**
- **Model provider**

## Connections

- Evaluation operator → Episode runner: starts runs (evidence: `README.md`)
- Episode runner → Variant manifest: reads variants (evidence: `run/rollout.py`)
- Episode runner → Model provider: requests completions (evidence: `run/rollout.py`)
- Episode runner → Task setup: runs setup (evidence: `run/rollout.py`)
- Task setup → Match service: starts service (evidence: `task.py`)
- Task setup → Playing agent: renders prompt (evidence: `task.py`)
- Episode runner → Bash tool: provides tool (evidence: `run/rollout.py`)
- Playing agent → Bash tool: issues commands (evidence: `README.md`)
- Playing agent → Arena client: uses client
- Arena client → Match service: requests game actions (evidence: `task_assets/arena.py`)
- Match service → Authoritative match state: writes state
- Match service → State contract: uses state shape (evidence: `task_assets/matchd.py`)
- Match service → Opponent engine: runs opponent (evidence: `task_assets/matchd.py`)
- Match service → UCI engine relay: serves UCI relay (evidence: `task_assets/matchd.py`)
- UCI engine relay → Opponent engine: starts engine (evidence: `task_assets/matchd.py`)
- Episode runner → Grader launcher: runs grading (evidence: `run/rollout.py`)
- Grader launcher → Episode grader: invokes grader (evidence: `bases/inspect-runner/shim-src/run_grader.py`)
- Episode grader → State contract: imports contract (evidence: `grader/grader.py`)
- Episode grader → Authoritative match state: reads state (evidence: `grader/grader.py`)
- Grader launcher → Recorded grade: writes grade (evidence: `bases/inspect-runner/shim-src/run_grader.py`)
- Episode runner → Recorded grade: reads score (evidence: `run/rollout.py`)
