Skip to content

About

Tempo: an interactive chess tutor in the browser. Play Stockfish with move-by-move feedback, learn and drill openings, solve rated puzzles.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Tempo

An interactive chess tutor that runs entirely in the browser. Live at https://labs.keshwani.io/chess-tutor/. No account, no server: the engine, the opening book and the puzzles are all static files.

  • Play against human-like opponents. Maia networks, each trained to predict the moves of people at one rating (1100 to 1900), run in the browser, so mistakes look like human mistakes. Stockfish 19 covers 2200 and full strength, and grades your moves.
  • Opening coach, with no language model. Play freely and every opening move is labeled (main line, book move, steers into another opening, off book) and explained from facts on the board. Leave theory and the coach plays out how the opponent punishes it as a side line on the board, with a one-sentence payoff. Try any move without committing it (What if?), peek at the book moves, or ask what the opponent threatens.
  • Your own openings. The coach records which openings you reach and the positions you keep getting wrong ("leaks"), then drills those positions with spaced repetition.
  • Course: 25 annotated openings (110 lines). Studying one is a free game in which the opponent follows the lesson's lines. Each line can also be recalled idea by idea, with the reason as the cue for the move.
  • Explorer over the 3,865 named lines of the Lichess openings database.
  • Puzzles: 6,000 rated tactics from the Lichess puzzle database, picked to match your puzzle rating, with 46 theme filters, hints and solutions.
  • Analysis: a free board with three engine lines, an evaluation bar, opening names, book moves and FEN/PGN import and export.
  • Four skins (Walnut, Hall, Midnight, Parchment) and four piece sets, switchable at any time.

Quick start

Requires Node 22 or newer.

npm install
npm run dev        # http://localhost:5173
npm test           # unit and engine integration tests (Vitest)
npm run build      # typecheck and production build into dist/
npm run preview    # serve the production build

dist/ is a static site with relative asset paths, so it can be served from any host or subdirectory.

Engines

  • Maia (opponents rated 1100 to 1900). One forward pass of a small policy network picks the move, with no search, through onnxruntime-web in a worker. Each level is a 3.5MB download on first use, plus the runtime once (about 3.8MB gzipped). Inference takes about 2ms.
  • Stockfish 19 (analysis, grading and the two strongest opponents). The dev and preview servers send Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp, which lets the multi-threaded build run. On a host that does not send those headers the app falls back to the single-threaded build automatically. Both are the "lite" network (about 1.7MB), which is far stronger than any human.

Deploy

Served at https://labs.keshwani.io/chess-tutor/ through the labs router from the Cloudflare Pages project chess-tutor.

npm run deploy     # builds, then: npx wrangler pages deploy dist --project-name chess-tutor --branch main

public/_headers sets the cross-origin isolation headers on Pages, so the deployed site runs the multi-threaded engine.

Project layout

src/
  chess/      Shared chess types and chess.js helpers (UCI, SAN, EPD, replay)
  engine/     Stockfish client: UCI parsing, request sequencing, strength levels, scores
  opponent/   Opponent roster; Maia inference (lc0 input encoding, policy mapping, move sampling)
  coach/      Opening coach: move facts, explanations, punishments, threats, repertoire and leaks
  openings/   Opening book (trie + EPD index) and the annotated course content
  puzzles/    Puzzle loading and selection, themes, rating
  board/      Chessground wrapper, promotion picker, piece sets
  ui/         Skin-aware UI kit (buttons, panels, move list, eval bar, ...)
  app/        Shell: hash router, settings, layout, home page
  views/      One folder per area: play, openings, puzzles, analysis
  styles/     Design tokens and the four skins
  lib/        Persisted signals, sound, small utilities
scripts/      Data builders and the engine copy step
public/data/  Generated openings and puzzles (committed)
tests/        Vitest suites

Each area keeps its logic in framework-free modules (state plus transition functions) that the tests exercise directly; the Preact components on top are thin. State is held in @preact/signals, so an engine update redraws the evaluation readout and nothing else.

A few design choices worth knowing:

  • The coach is rule-based. src/coach reads facts off the board (development, attacks, pins, forks, static exchanges, what a move neglects), combines them with the openings database, the course notes and engine lines, and builds sentences from templates. Nothing is generated by a language model, so the same position always gets the same explanation.
  • A punishment is the engine's own line. The search that grades a move also yields the best reply sequence, which the coach trims to a quiet point, captions step by step and summarizes by what it wins: material, the king, development, the center or time.
  • Two engine workers. The opponent and the tutor's analysis each get their own Stockfish worker, so one never cancels the other. Within a worker, requests are strictly sequenced: a new search sends stop and waits for the old search's bestmove before issuing the next position, which keeps stale output from leaking into the new result.
  • The opening book does no chess at load. UCI moves, SAN and the final EPD of every line are precomputed, so building the index takes a few milliseconds. Names are looked up by position, which means transposed move orders are still recognized.
  • Views load on demand. The entry chunk has no chess code; each area is a separate chunk that is preloaded when you hover its link. Puzzles are split into twelve rating bands of about 25KB gzipped, fetched as needed.
  • The board is controlled. It derives legal moves from the FEN it is given and snaps a piece back if the parent does not accept the move, which is how the trainer and puzzles reject wrong answers.

Regenerating the data

The generated files under public/data/ are committed, so this is only needed to refresh them.

npm run data:openings   # downloads the lichess-org/chess-openings TSV files
npm run data:puzzles    # streams the first 64MB of the Lichess puzzle dump and samples 6,000
npm run data:validate   # replays every opening line and puzzle for legality

Raw downloads are cached in .cache/; pass --refresh to fetch them again. Behind a proxy, set NODE_USE_ENV_PROXY=1.

Credits and licenses

Tempo is free software under the GNU General Public License, version 3 or later.

Component Source License
Engine Stockfish via stockfish.js GPL-3.0
Human-like opponents Maia networks (CSSLab, University of Toronto), ONNX exports listed in public/maia/README.md GPL-3.0
Inference onnxruntime-web MIT
Board chessground GPL-3.0
Rules chess.js BSD-2-Clause
Openings lichess-org/chess-openings CC0
Puzzles Lichess puzzle database CC0
Piece sets cburnett, merida, chessnut, mpchess from lila See public/pieces/LICENSES.md
Fonts Fraunces, IBM Plex Sans, IBM Plex Mono via Fontsource SIL OFL 1.1

The opening course text was written for this project. Its lines were checked for legality and screened with Stockfish, but it has not been reviewed by a titled player. The coach's computed explanations are conservative by design and stay silent when they have nothing concrete to say.

About

Tempo: an interactive chess tutor in the browser. Play Stockfish with move-by-move feedback, learn and drill openings, solve rated puzzles.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages