Metadata-Version: 2.4
Name: clichess-cli
Version: 0.9.0
Summary: Play chess in your terminal against an LLM or Stockfish
Author: Jude
License-Expression: MIT
Project-URL: Homepage, https://github.com/Helios1919/clichess
Project-URL: Source, https://github.com/Helios1919/clichess
Project-URL: PyPI, https://pypi.org/project/clichess-cli/
Keywords: chess,llm,terminal,tui,stockfish,ai
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Games/Entertainment :: Board Games
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: chess>=1.10
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Dynamic: license-file

# clichess

[![tests](https://github.com/Helios1919/clichess/actions/workflows/tests.yml/badge.svg)](https://github.com/Helios1919/clichess/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/clichess-cli?logo=pypi&logoColor=white)](https://pypi.org/project/clichess-cli/)
[![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Play chess in the terminal against an LLM or against Stockfish.

![clichess welcome screen](docs/welcome.png)

## Install

```bash
pip install clichess-cli
```

Then run `clichess`. The first start offers to download Stockfish (~80 MB);
accept it and the eval, the move filter and opponent 0 all work. Any other
time: `clichess --install-engine`.

Prefer an isolated install? `uv tool install clichess-cli` or
`pipx install clichess-cli` do the same without touching your global
site-packages.

No Python at all? `install.sh` (Linux/macOS) or `install.ps1` (Windows) in the
repository brings uv, a private Python, clichess and Stockfish.

## Play

`clichess` opens the welcome page: a banner, a short intro, and `type help`.
`start` lists the opponents; a number starts one, `q` quits. The prompt also
takes `new`, `delete NAME|N`, `opponent NAME|N`, `continue` and `author`.
Numbers renumber themselves: remove opponent 2 and the old 3 becomes 2.

Opponent `0` is Stockfish: it asks how strong it should be, `1) beginner` at
about 1320 Elo through `6) maximum`, which lifts the limit entirely. The eval
keeps running at full strength, so the score stays honest even when the
opponent is playing badly on purpose.

## Opponents

```bash
clichess --new              # provider, key, model: three choices, nothing to type
clichess --list
clichess --delete NAME      # or a number from `start`; 0 is Stockfish, never deletable
clichess --opponent NAME    # skip the welcome page; --opponent 0 is Stockfish
clichess --continue         # resume the last game, same opponent and plan
```

`--new` offers ChatGPT, Claude, DeepSeek, Gemini, Alibaba and **Custom** (any
OpenAI compatible endpoint: Ollama, LM Studio, vLLM, a gateway). It fills the
endpoint itself, then asks the provider which models the key can use and lets
you pick one. The last question is a **nickname** — the name you will pick it by, default
being the provider; a name already in use is refused. Custom endpoints may
leave the key empty, and if the server cannot list models you type it once.

One JSON file per opponent in `~/.config/clichess/opponents/`, mode 600
because it holds the key:

```json
{ "name": "DeepSeek", "model": "deepseek-chat", "base_url": "https://api.deepseek.com",
  "api_key": "sk-...", "temperature": 0.4, "created": "2026-11-27" }
```

| Provider | model | base_url |
|---|---|---|
| DeepSeek | `deepseek-chat` | `https://api.deepseek.com` |
| OpenAI | `gpt-4o-mini` | `https://api.openai.com/v1` |
| Alibaba Cloud | `qwen-plus`, `qwen-max` | `https://dashscope.aliyuncs.com/compatible-mode/v1` |
| OpenRouter | any `vendor/model` | `https://openrouter.ai/api/v1` |

Other flags: `--as black`, `--brief "an Italian"` (skip the prompt),
`--engine PATH`, `--version`.

## In a game

```
you > e4                     a move, SAN or UCI
      hint                   ask Stockfish for a suggestion
      chat [text]            say something to the opponent, no board reload
      undo                   take back your move and its reply
      fen                    show the position
      coords                 toggle the a-h / 1-8 labels
      say                    toggle the opponent's commentary column
      eval                   toggle the eval / last / move panel
                             (all three are remembered for next time)
      new                    start a new game
      debug                  toggle raw model output
      help                   the command list
      quit                   leave, the game is saved
```

Moves: `e4`, `Nf3`, `exd5`, `O-O`, `e8=Q`, or UCI like `e2e4`.

## The plan

Against an LLM, each game starts with one line from you:

```
brief > let us play the Italian, both sides develop normally

agreeing a plan...
plan: Italian: e4/e5, Nf3/Nc6, Bc4/Bc5; White builds c3/d3 and Nbd2, Black
      answers ...d6/...a6, both castle short.
```

The plan rides in the system prompt for the whole game; the model is told to
follow it and to admit it when a move breaks it.

## The eval

Stockfish over UCI, depth 15, centipawns from white's point of view. The right
column shows the score and what the last move of *each side* was worth to the
side that played it - the two lines are coloured like the pieces, white and
red, so no labels are needed:

![clichess in a game](docs/game.png)

The rightmost column is the opponent talking, prefixed with its nickname: one
short line per turn - a taunt, a joke or a real thought - produced in the same
request as the move, so it costs nothing extra. Every reply is capped: the say
line at 12 words, a chat answer at about 180 characters, the pre-game plan at
240. `chat` lets you talk back - `chat why not c5` or just `chat` to be asked.

Stockfish has nothing to say, so that column stays empty against it.

`hint` always asks the full-strength engine, never the handicapped opponent.

Each turn the model is asked for five candidate moves; Stockfish drops any that
lose more than 0.8 pawns against the best option, and one survivor is picked at
random. If the model fails three times in a row, Stockfish plays that move
instead of the game dying.

## Files

- `clichess.py` — the whole program
- `install.sh` / `install.ps1` — the zero-dependency bootstraps
- `~/.config/clichess/opponents/*.json` — opponents
- `~/.local/state/clichess/last.json` — saved game

## Tests

```bash
pip install -e .[dev]   # or: uv sync --extra dev
pytest -q               # 24 tests, no network, no engine needed
```

The suite covers move parsing, the candidate filter, the side panel, rendering
toggles and the opponent store; `m.ENGINE` stays `None` throughout, so nothing
is spawned. CI runs it on 3.10-3.13 (`.github/workflows/tests.yml`).

## Notes

An LLM without search plays around 1000–1500 Elo: fine openings, tactical
blunders later. It cannot play an illegal move — every legal move is enumerated
locally and the reply is validated — but it can play badly.

## License

MIT — see [LICENSE](LICENSE). Built by [Jude](https://github.com/Helios1919).
