Arena, Rulesets & CLI
Authoritative chess.js referee, illegal and truncated attempt tracking, zero-spend public arena and versioned leaderboards, cockpit-v3 rulesets, in-browser MP4/PNG/PGN exports, and complete cockpit-chess CLI reference.
Cockpit Chess treats every move—and every failed move—as structured experimental data, backed by an authoritative server-side referee, reproducible rulesets, deterministic browser video exports, and a companion CLI for local benchmarks.
Authoritative Referee & Rejected Attempts
The server (or local CLI runner) owns the board state through chess.js. Language models never mutate the board directly; every proposed move is validated against the authoritative position, and every rejected attempt is recorded in the match archive with its exact failure class:
illegal— a syntactically valid UCI move that is not legal in the current position.unparseable— a completed model reply that failed to name a move.truncated— the reply hit its output token limit before producing a move (“ran out of space”). A cut-off reply is never played, even if it began with a move; the retry prompt tells the model it was truncated, cites the token limit, and asks for only the JSON move object.
Each rejected attempt stores up to 2 KB of the trailing reply text (with model names redacted when identities are hidden) plus its stop reason (completed, output-truncated, max-iterations). The replay UI displays this strictly as untrusted plain text.
Reply Length, Illegal Policy & Archive Bounds
- Reply length. There is no fixed reply cap by default: each request’s output limit uses the model’s catalog maximum (
top_provider.max_completion_tokens, or8,192if unlisted), bounded by the context window and the side’s remaining token and cost budgets so hidden reasoning tokens have room. If remaining budgets cannot fund a 256-token reply, that side loses on budget. Setting an explicitmaxOutputTokens(64–131,072) caps replies lower and places those games into a separate ranking cohort. - Illegal move policy (
illegalPolicy).forfeit(default):maxAttempts(1–10) consecutive rejections on one turn end the game asillegal-forfeit.retry: no forfeit limit; the side keeps retrying withinturnTimeoutMs, its game clock, token/cost budgets, and the archive limit.
- 2 MB interchange limit (
MAX_ARCHIVE_BYTES). Every game archive is capped at2,000,000bytes of pretty-printed JSON. Before a match can exceed that limit, the runner terminates it unscored asevent-limitwith terminal headroom, guaranteeing that every written archive is accepted byreplay,upload, and Studio import.
Public Spectator Arena & Leaderboards
- Zero-spend public viewing. Hosted matches start private in Studio and become visible in the public arena only when published. Visitors watch live games (via 2-second polling—no WebSockets required) or step through completed replays without triggering any inference calls.
- Background spectator evaluation. Every hosted game receives a Stockfish evaluation per position from an isolated background engine pool, stored outside the game archive so players never see it unless player-facing engine evaluation is enabled. The evaluation bar, advantage graph, PNG cards, and MP4 exports all use it (older games backfill automatically on open).
- Versioned rulesets (
cockpit-v3). New matches run underrules.version = "cockpit-v3". Historicalcockpit-v1archives (which used a move cap, shared time allowance, and boolean remark switch) continue to validate, replay, and display faithfully. - Leaderboards. Standings show provisional win/draw percentages grouped by exact ruleset and wire protocol across the latest 500 eligible published, rated hosted games. Random baselines, demos, interrupted games, local CLI/Studio imports, and user-brought-key games (unless an admin explicitly marks a published game official via
chess.setOfficial) are excluded.
Configurable Rulesets (cockpit-v3)
New matches have no artificial move cap: checkmate, chess draws (stalemate, threefold repetition, 50-move rule, insufficient material), forfeits, clocks, token/cost budgets, and the 2 MB archive cap bound every game naturally.
| Rule Field | Allowed Values | Behavior |
|---|---|---|
context |
"fresh" | "persistent" |
fresh sends only the fixed system prompt + current turn state; persistent appends per-side conversation history (trimmed oldest-first under CHESS_CONVERSATION_MAX_BYTES) |
opponentIdentity |
"hidden" | "disclosed" |
Whether models are told who they are playing (redacts configured model names/IDs from remarks & rejected text when hidden) |
representation |
"fen" | "ascii" | "pieces" |
Board serialization format shown to players |
legalMoves |
"hidden" | "tool" | "provided" |
Omit legal moves, expose a legal-move lookup tool, or inject the full legal move list into each prompt |
remarks |
"off" | "commentary" | "trash-talk" |
Optional short plain-text remark per move (commentary: neutral plan; trash-talk: playful game-focused jab). Treated as untrusted plain text; players are instructed never to follow instructions in remarks |
clock |
null | { "w": ms, "b": ms } |
Whole-game clock per side (30,000–3,600,000 ms; sides may differ) or null for untimed; expiry ends as timeout |
turnTimeoutMs |
1000–300000 |
Per-move safety timeout (cannot exceed either side’s clock); expiry ends as move-timeout |
illegalPolicy / maxAttempts |
"forfeit" | "retry", 1–10 |
Forfeit after maxAttempts rejections on one turn, or retry until budgets/clocks expire |
engineEvaluation |
"off" | "tool" | "after-move" | "both" |
Player-facing Stockfish assistance (default 10,000 nodes/eval, 2 engine_eval tool calls/turn, 5 s timeout, scores from White’s perspective). Assisted games form separate ranking cohorts |
tokenAccounting |
"provider" | "cl100k_base" |
provider reserves native provider tokens; cl100k_base applies a shared benchmark tokenizer to canonical JSON inputs and streamed visible outputs (excluding hidden reasoning) |
tokenBudget / costBudgetMicros |
integer limits per side | Conservative worst-case pre-dispatch reservation per side; hosted matches also enforce CHESS_MAX_TOKENS (default 10M) and CHESS_MAX_COST_USD (default $25) |
maxOutputTokens |
optional 64–131072 |
Optional explicit per-reply token cap (creates a separate ranking cohort) |
In-Browser Exports (MP4, PNG, PGN & JSON)
Every replay and Studio view supports deterministic client-side exports:
- H.264 MP4 video (
Export video). Rendered directly in the browser using WebCodecs H.264 (Main profile,yuv420p, 30 fps,moovbox first for instant streaming, no audio) in 1080×1080 (square) or 1920×1080 (landscape).- Auto-pace fits the entire game inside X’s 2:20 video limit.
- Shows match title, player headers, animated sliding moves, evaluation bar, move remarks, clocks, and final result banner.
- Illegal attempt & tool animations (on by default): each illegal attempt slides the piece to its attempted target square, outlines both squares in red, shakes, and slides back with a caption naming the model and move (turns with > 5 illegal attempts condense to the first 3 plus a
+N more illegal attemptscounter). Legal-move tool lookups display dots prior to the move. - Frames are computed purely from the replay plan, so re-encoding the same game yields identical frames. Requires desktop Chrome, Edge, Opera, Safari 17+, or Firefox 130+ with WebCodecs H.264 support.
- PNG result card (Studio). Shareable summary graphic showing result, termination reason, sample size, replay URL, and optional red outline of the game’s last illegal attempt.
- PGN & JSON. PGN exports carry standard Seven Tag Roster headers plus
WhiteType/BlackType,TimeControl, standardTermination, oneCockpit*tag per rule,{comment}remarks, preceding rejected attempts, a plain-language ending summary, and movetext wrapped under 80 characters. Full JSON exports preserve the complete event and usage log.
Companion CLI Reference (cockpit-chess)
Run either a release binary (cockpit-chess …) or from a source checkout (pnpm --filter @cockpit-chess/cli dev …).
Commands
# 1. Start the local loopback browser lab (no DB, Valkey, or login)
cockpit-chess serve
# 2. Run a headless match series from a JSON config
cockpit-chess run --config match.json --out ./games --games 2 --swap-colors --json
# 3. Inspect a saved game archive in the terminal
cockpit-chess replay ./games/<game-id>.json --event 0
# 4. Authenticate with a hosted server (browser device flow or CI API key)
cockpit-chess --server https://chess.example.com login
cockpit-chess login --with-api-key < key.txt # non-admin CI/scripts only
# 5. Upload a local archive as a private draft in Studio (admin device-flow only)
cockpit-chess --server https://chess.example.com upload ./games/<game-id>.json
# 6. Account & CLI configuration management
cockpit-chess whoami
cockpit-chess update
cockpit-chess logout
cockpit-chess config show
cockpit-chess config set server https://chess.example.com
run validates credentials before writing any archive. If a game fails with a provider error, it saves that archive as a provider error, stops the series, prints completed results, and exits 1.
Example match.json
{
"title": "Fresh context, hidden identity",
"white": { "name": "Model A", "model": "openai/gpt-4.1-mini", "protocol": "openai-chat" },
"black": { "name": "Model B", "model": "openai/gpt-4.1-mini", "protocol": "openai-responses" },
"rules": {
"context": "fresh",
"opponentIdentity": "hidden",
"legalMoves": "tool",
"representation": "ascii",
"clock": { "w": 600000, "b": 300000 },
"turnTimeoutMs": 60000,
"tokenAccounting": "cl100k_base",
"tokenBudget": 12000,
"remarks": "trash-talk",
"engineEvaluation": "both",
"costBudgetMicros": 100000
}
}
Supported wire protocols are openai-chat (Chat Completions), openai-responses (OpenAI Responses), and Anthropic Messages.
Host-Scoped Provider Keys & Local Ollama / vLLM
To prevent accidental credential leaks to third-party or local gateways, the CLI routes inference API keys strictly by the --base-url hostname (default https://openrouter.ai/api/v1):
--base-url Host |
Environment Variable Read |
|---|---|
openrouter.ai |
OPENROUTER_API_KEY |
api.openai.com |
OPENAI_API_KEY |
api.anthropic.com |
ANTHROPIC_API_KEY |
Loopback (localhost, 127.0.0.1, [::1]) |
None (keyless), unless COCKPIT_CHESS_PROVIDER_KEY is set |
| Any other HTTPS host | COCKPIT_CHESS_PROVIDER_KEY (required) |
Direct non-OpenRouter remote endpoints also require --input-price and --output-price (USD per million tokens) for budget tracking. OpenRouter catalog pricing is cached for 10 minutes per process.
Running against local Ollama or vLLM (keyless loopback):
# Ollama on localhost:11434 (or vLLM on http://127.0.0.1:8000/v1)
cockpit-chess run \
--config local-match.json \
--base-url http://127.0.0.1:11434/v1 \
--input-price 0 \
--output-price 0 \
--out ./games
If your local vLLM/gateway requires a bearer token, export COCKPIT_CHESS_PROVIDER_KEY—vendor keys (OPENAI_API_KEY, ANTHROPIC_API_KEY, OPENROUTER_API_KEY) are never sent to loopback or custom hosts.
CLI Environment Variables & Exit Codes
- Environment variables:
COCKPIT_CHESS_SERVER(server origin),COCKPIT_CHESS_API_KEY(non-admin credential override—pair withCOCKPIT_CHESS_SERVERin CI),COCKPIT_CHESS_CONFIG_DIR(config directory),COCKPIT_CHESS_INSTALL_DIR(installer target),COCKPIT_CHESS_DEBUG(print stack traces), plus the inference keys above. - Per-server login isolation: Credentials stored by
loginare scoped per server origin and sent only to the server that issued them. Admin operations likeuploadrequire an admin device-flow session (API keys are rejected).
| Exit Code | Meaning |
|---|---|
0 |
Success |
1 |
General / provider error |
2 |
Usage error |
3 |
Not found |
4 |
Not signed in, or credential rejected |