opencode-bench/README.md
KaKi87 69fdc6bb27 Add a script that keeps the Pinggy tunnel open and records each new address
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 11:36:50 +01:00

98 lines
5.7 KiB
Markdown

# opencode-bench
Runs a set of LLM benchmarks against every free OpenCode Go model. Each task runs the host's `opencode` inside a Docker container. Results go to SQLite. A CLI and a dark web UI show progress, charts and past runs.
## Requirements
- Bun 1.4 or newer
- Docker (the `python:3.12-slim` image is pulled on first use)
- `opencode` on the host, in `PATH` or at `~/.opencode/bin/opencode`
## Long runs
`scripts/monitor.sh <run> [concurrency] [interval]` keeps a run going in a tmux session named `bench-run-<run>` and logs progress, running containers and free disk space to `data/monitor-<run>.log`. If the session dies with tasks left, it starts the run again, at most once every 15 minutes. Start it in tmux too:
tmux new -d -s bench-monitor 'scripts/monitor.sh 2 8'
tmux attach -t bench-run-2 # watch the run
## Public link
`scripts/tunnel.sh [port]` opens a free Pinggy tunnel to the read-only server (`BENCH_READONLY=1 bun src/cli.ts serve --port 3056`, which refuses every request that is not a GET). Free tunnels last 60 minutes, so the script opens a new one each time the old one stops. It writes each address to `data/tunnel-url.txt` and `data/tunnel.log`.
BENCH_READONLY=1 tmux new -d -s bench-public 'bun src/cli.ts serve --port 3056'
tmux new -d -s bench-tunnel 'scripts/tunnel.sh 3056'
cat data/tunnel-url.txt
## Usage
bun install
bun src/cli.ts models # free `opencode-go/*-free` models, discovered from `opencode models`
bun src/cli.ts benchmarks
bun src/cli.ts run --name first # all models, all benchmarks
bun src/cli.ts run --detach --limit 3 # background run, 3 tasks per benchmark
bun src/cli.ts status --watch # live progress of the latest run
bun src/cli.ts index --run 1,2 # intelligence index table
bun src/cli.ts serve --port 3000 # web UI
`runs`, `resume <id>`, `cancel <id>` and `results` are also available. `index`, `results` and `status` accept `--run`, `--model` and `--benchmark` filters (comma separated).
## How a task runs
1. The task's files are written to `data/artifacts/<run>/<result>/work`.
2. A container starts with that directory at `/work` and the host `opencode` binary mounted read-only. It runs `opencode run --format json --auto -m <model> "<prompt>"`.
3. The JSON event stream gives steps (`step_finish` events) and tokens (input, cache, output, reasoning).
4. A second container with no network runs the task's Python grader against `/work`. Exit code 0 scores 1. A final `SCORE: x` line gives partial credit.
The container uses `--dns 1.1.1.1` because Docker's default resolver fails on hosts that use systemd-resolved. Override with `BENCH_DNS`.
## Benchmarks
| id | tasks | what it checks |
|---|---|---|
| humaneval-lite | 10 | Python functions against hidden unit tests |
| gsm-lite | 12 | math word problems with numeric answers |
| ifeval-lite | 10 | verifiable instruction constraints |
| logic-lite | 10 | short reasoning puzzles |
| agentic-files | 6 | debugging, refactoring, file transforms, search in a workspace |
| needle-long | 3 | one fact hidden in 400, 3000 and 12000 line files |
The `-lite` suites and `agentic-files` are compact and ship with the repo. The full public datasets download on demand:
bun src/cli.ts import humaneval # 164 tasks
bun src/cli.ts import mbpp # 500 tasks
bun src/cli.ts import gsm8k # 1319 tasks
bun src/cli.ts import mmlu # 1000 tasks, spread evenly over the 14042 test questions
bun src/cli.ts import arc # 1172 tasks, ARC-Challenge test split
bun src/cli.ts import bbh # 540 tasks, 20 from each of the 27 BIG-Bench Hard tasks
bun src/cli.ts import math # 500 tasks, MATH-500
bun src/cli.ts import ifeval # 510 tasks, the 541 prompts minus the 31 that ask for a response language
bun src/cli.ts import livecodebench # 175 tasks, release v6, up to 12 tests each
Imported datasets land in `data/datasets/` and then show up in `benchmarks` and in the New run dialog. Use `--limit` to sample them. Answers are compared exactly, except MATH, which normalises LaTeX first, and IFEval, which uses ports of the original checkers with approximate word and sentence splitting. LiveCodeBench keeps at most 12 tests per problem. SWE-bench and the other suites that need a Docker image per task are not ported. Add a benchmark by exporting a `Benchmark` from `src/benchmarks/` and listing it in `src/benchmarks/index.ts`.
## Scoring
- Benchmark score: mean task score, 0 to 100. Tasks that failed for infrastructure reasons (container or API error) have no score and are left out. Timeouts are also left out of every score and average (index, time, tokens, steps). A model with timeouts or pending tasks counts as partial and is drawn striped.
- Intelligence index: mean of a model's benchmark scores. Benchmarks with no finished task yet are skipped, so the index of a running run is partial and moves as results arrive.
- Efficiency: average tokens, steps and seconds per scored task.
## Web UI
Charts: intelligence index, index across runs, intelligence vs tokens, steps and time, task status, one chart per benchmark, and tokens, steps and time per task. The Run, Model and Benchmark filters apply to every chart and the results table, and live in the URL. The page refreshes when the runner writes to the database. "New run" starts a run from the browser.
## Configuration
| variable | default |
|---|---|
| `BENCH_DB` | `data/bench.sqlite` |
| `BENCH_ARTIFACTS` | `data/artifacts/` |
| `BENCH_IMAGE` | `python:3.12-slim` |
| `BENCH_DNS` | `1.1.1.1` |
| `BENCH_TASK_TIMEOUT` | `600` (seconds) |
| `OPENCODE_BIN` | `opencode` from `PATH` |
## Tests
bun test
Checks that every grader fails on an untouched workspace and that event parsing sums tokens correctly.