How chess-webCLI works
Chess rooms you open with a link, played directly between browsers, with a local engine and an optional on-device language model that is bounded to the legal moves. Part of the webCLI family.
Out: a game, saved as PGN on your device if you want it.
Not: a rated server, a matchmaking service or an anti-cheat system.
Egress: none for games on this device. For rooms, the introduction relays, a STUN server and the people in the room. For the model, two download hosts, once, when you press Load.
Four ways to play
| Mode | Who moves | What leaves the device |
|---|---|---|
| Play the computer | You, and the local engine | Nothing |
| Pass and play | Two people taking turns on one device | Nothing |
| Analysis board | Either side; load FEN or PGN | Nothing |
| Room | The two seated players; anyone else watches | Moves and chat to the people in the room; introductions via relays |
A room
- Create. Your browser makes a 128-bit room secret and a seat key (ECDSA P-256). The link is
https://…/#k=<secret>&s=<your key id>. Everything after#stays in the browser; it is never sent to a server. - Introduce. The relay topic is
SHA-256("chess-webCLI/v1/topic" ‖ secret), and connection offers are encrypted with a key derived from the secret (HKDF). Relays see a topic hash and ciphertext, never the secret or a move. - Connect. Each pair of people opens a WebRTC data channel. Moves, offers and chat go over it, encrypted (DTLS).
- Seat. Each newcomer proves it holds its own key. The creator's browser seats the first one in the open colour by writing a signed
seatevent. Everyone after that watches. - Play. Every move is an event signed by the seat to move, chained to the one before by hash. Every browser in the room replays every event through the rules engine and checks every signature.
The signed log
There is no server to say what the position is, so the game is an append-only log that every peer holds and checks. The position is whatever the log replays to.
init {color, pub, name, tc} signed by the creator; its key id must match the link
seat {color, pub, name} signed by the creator
move {by, uci, clk} signed by the seat to move
offer {by, kind} draw | takeback | rematch
reply {by, kind, accept} signed by the other seat: consent is a signature
resign {by}
flag {by, color} a clock ran out
every event: i, prev = hash(previous event), sig
What that gives you, and what it does not:
- Nobody can move for a seat they do not hold, make an illegal move, or accept a takeback, draw or rematch on the other player's behalf. A tampered or reordered event fails its signature or its chain, and the browser names the first bad event.
- If two events are written at the same moment (a resignation and a move, say), the logs fork. Every browser keeps the branch whose first differing event has the lower hash, so all of them land on the same one.
- The creator's key is pinned by the link. A newcomer who arrives while the creator is away trusts the other people present for who the second player is; if two of them disagree, the newcomer is told.
- Clocks are self-reported: each move carries the mover's own remaining time, capped at what they had plus the increment. A modified page can stall its own clock display; it cannot give itself more time than the cap. A flag is claimed by the flagged player's browser, or by the opponent's after 1.5 s of grace.
- This is not anti-cheat. Nothing can stop someone consulting an engine in another tab. The page itself turns its engine off for seated players during a live room game.
The local engine
A small alpha-beta search (iterative deepening, quiescence on captures, MVV-LVA ordering, piece-square tables) in a Web Worker. No neural network, no opening book, no download. Each level is bounded three ways, and each answer says which bound stopped it:
| Level | Depth | Positions | Time | Randomness |
|---|---|---|---|---|
| 1 Beginner | 1 | 20,000 | 0.3 s | picks among moves within 2.2 pawns of the best |
| 2 Casual | 2 | 60,000 | 0.5 s | within 1.2 pawns |
| 3 Club | 3 | 200,000 | 1 s | within 0.4 pawns |
| 4 Strong club | 4 | 600,000 | 2 s | none |
| 5 Strongest | 6 | 2,000,000 | 4 s | none |
The labels are descriptive, not measured ratings. The randomness is seeded from the position, so the same game always gets the same replies.
The bounded AI
Following Strata: the deterministic layer does the work, and a model only handles the fuzzy residue.
- Notation (
e4,Nxe5,O-O,e7e8q) is played at once. - Plain words go through a fixed grammar (
js/intent.js): "knight to f3", "take the queen", "castle long", "kingside knight out", "pawn takes d5". It filters the legal-move list, so its answer is legal by construction. One match is proposed for you to confirm; several are offered as buttons. - Only if you loaded a model, wording the grammar cannot place goes to it, with these bounds, all enforced in code (
js/ai.js):- Closed output: decoding is constrained by a JSON schema whose one field is an enum of the legal moves, a few commands and "none". The reply is parsed and checked against the list anyway.
- Re-validated: a chosen move is looked up in the rules engine again.
- At most 3 attempts, 40 tokens each, temperature 0.
- Proposal only: nothing is played, sent, offered or resigned until you press the button.
- Narrowed: if the grammar found candidates, the model chooses among only those.
- Advice-free: the model is never shown an evaluation and never asked which move is good.
The models (Qwen2.5 1.5B and 0.5B Instruct, Llama 3.2 1B Instruct, WebLLM builds) run in your browser through WebGPU. The library (lib/web-llm.js) is self-hosted and hash-pinned; the weights come from Hugging Face and the compiled model library from GitHub, once. None of these models has been evaluated on this task yet, and the model path has not been run on a real GPU in testing; the bounds are tested with scripted fake models.
Privacy and egress
| Purpose | Host | When |
|---|---|---|
Page, scripts, lib/ | the origin you loaded it from | always |
| Introduction relays | no.str.cr, relay.wavlake.com, nostr.hifish.org, relay.notoshi.win, relay.dwadziesciajeden.pl | rooms only |
| STUN | stun.cloudflare.com:3478 | rooms only; off with LAN only |
| TURN | none | never built in |
| Peers | each person in the room, directly | rooms only |
| Model weights | huggingface.co (redirects to *.hf.co) | only when you press Load model |
| Model GPU library | raw.githubusercontent.com | only when you press Load model |
The page's Content-Security-Policy allows exactly these (plus ws://localhost for development); nothing else can be reached. /egress in the console prints the declared list next to the hosts the page has actually contacted. People in a room see each other's IP addresses, and so do the relays and the STUN server.
Nothing is kept beyond this tab: your name, settings, seat key and the game log live in sessionStorage, which the browser drops when the tab closes. A reload keeps them (so you keep your seat); Leave deletes them. A saved .pgn is a file on your device; a downloaded model stays in the browser cache until you clear site data.
What it is and is not
- No server means no referee. There is no rating, no matchmaking, no adjudication and no anti-cheat. It is for playing people you know.
- A game lives as long as its players. If a player closes their tab, their seat key is gone and that game cannot be finished. A reload is fine.
- Networks that keep devices apart (some guest, venue and corporate networks) stop peer-to-peer connections, and there is no relay server to fall back on.
- Clocks are trusted, within the cap described above.
- The engine is modest: a few hundred thousand positions per move, no book. Good for practice, not for analysis of master games.
- Pieces are Unicode glyphs, so their look depends on your fonts.
- Not yet run on real devices across real networks. The room tests use real Chrome pages and real WebRTC, with a mock relay.
Console
Every control has a console command, and the other way round: /move, /flip, /takeback, /draw, /accept, /decline, /resign, /rematch, /new, /hint, /eval, /level, /describe, /fen, /pgn, /load, /first /prev /next /last, /seats, /peers, /chat, /invite, /qr, /ai, /sounds, /egress, /about, /leave.
Web-CLI architecture: The Web-CLI: Verifiable Privacy for Tools, Models, and Inference Engines in the Browser, Tejaswi Gowda, Arizona State University.