chess webCLI

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.

In: an invite link (or nothing, for a game on this device).
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

ModeWho movesWhat leaves the device
Play the computerYou, and the local engineNothing
Pass and playTwo people taking turns on one deviceNothing
Analysis boardEither side; load FEN or PGNNothing
RoomThe two seated players; anyone else watchesMoves and chat to the people in the room; introductions via relays

A room

Ann (White)room creator Bob (Black)seated by Ann's browser Cat (watching) Nostr relays: introductions only signed moves, directly (WebRTC)
  1. 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.
  2. 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.
  3. Connect. Each pair of people opens a WebRTC data channel. Moves, offers and chat go over it, encrypted (DTLS).
  4. 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 seat event. Everyone after that watches.
  5. 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:

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:

LevelDepthPositionsTimeRandomness
1 Beginner120,0000.3 spicks among moves within 2.2 pawns of the best
2 Casual260,0000.5 swithin 1.2 pawns
3 Club3200,0001 swithin 0.4 pawns
4 Strong club4600,0002 snone
5 Strongest62,000,0004 snone

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.

  1. Notation (e4, Nxe5, O-O, e7e8q) is played at once.
  2. 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.
  3. 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

PurposeHostWhen
Page, scripts, lib/the origin you loaded it fromalways
Introduction relaysno.str.cr, relay.wavlake.com, nostr.hifish.org, relay.notoshi.win, relay.dwadziesciajeden.plrooms only
STUNstun.cloudflare.com:3478rooms only; off with LAN only
TURNnonenever built in
Peerseach person in the room, directlyrooms only
Model weightshuggingface.co (redirects to *.hf.co)only when you press Load model
Model GPU libraryraw.githubusercontent.comonly 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

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.