Skip to content

Play against the default Omarchy agent - #14

Open
dhh wants to merge 1 commit into
masterfrom
agent-opponent
Open

dhh wants to merge 1 commit into
masterfrom
agent-opponent

Conversation

@dhh

@dhh dhh commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

New game gains a third opponent: the user's default Omarchy agent, offered by name ("Play against Claude Code") when one is chosen and can answer on its own.

How it works

  • The choice is read from ~/.config/omarchy/defaults/agent, where omarchy default agent writes it, each time the dialog opens.
  • Omarchy only opens agents in a terminal, so each turn runs the harness's own one-shot mode: claude -p, codex exec, opencode run and so on. Fifteen harnesses are mapped (claude, codex, opencode, kilo, pi, omp, grok, crush, copilot, cursor-agent, agy, qwen, kimi, amp, ori). The others aren't offered.
  • The prompt carries the FEN, the moves so far and the legal moves, and asks for one move from the list. The last legal move in the answer is played, in coordinates (e7e5) or as the game writes it (Nf6).
  • The process is asynchronous, runs in an empty temp folder rather than among the user's files, and is stopped by undo or a new game.
  • An answer naming no legal move is asked about once more. After that, or when the agent exits with an error or takes over three minutes, its reason is shown in the window and the game waits: Ask again, undo, or start over. It never falls back to the built-in player silently.
  • The opponent is saved with the game. Undo takes back both moves, as against the computer.

Testing

bin/test passes. New tests cover the command table, the prompt and answer parsing, and a full game loop against scripted stand-ins: a good answer, nonsense twice, a failing exit, a timeout, cancelling mid-thought, and save/restore. The window test checks the dialog offers the agent.

One live check: claude -p with the app's prompt answered e7e5 in under four seconds. Only Claude Code was tried live; the other fourteen commands come from each harness's documented one-shot flag and are untested here.

Not in this PR

  • The README doesn't mention it yet, to stay clear of Slim the README and show the four sets #13, which rewrites the same lines.
  • Every agent move spends the user's tokens, and nothing in the UI says so.
  • The mapping from harness to one-shot command arguably belongs in Omarchy as a headless omarchy agent ask, so apps don't each keep a copy.

🤖 Generated with Claude Code

New game offers the user's default agent by name when it can answer on
its own. Each of its turns runs the harness's one-shot mode with the
position, the moves so far and the legal moves, in an empty folder of its
own, and plays the last legal move the answer names. An answer without
one is asked about once more; after that, or when the agent fails or
takes too long, the reason is shown and the game waits for Ask again,
undo or a new game.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 2/5

[Medium impact] The change reaches the chess-game workflow and calls the user's selected local agent.

Fix the wrong-move cases and the unrequested agent retry before merging.

Findings

  1. P1 The final choice is ignored ▶
  2. P1 The wrong castle is played ▶
  3. P1 An old timer asks again ▶

Summary

Adds the default Omarchy agent as a third opponent.

  • Checkmate asks a one-shot agent for each opponent move.
  • Players can choose their available Omarchy agent by name.

Acknowledged scope:

  • dhh noted that only Claude Code was tried live; the other fourteen commands remain untested.
  • dhh explicitly deferred the token-cost warning.
  • dhh explicitly deferred README coverage to avoid overlap with Slim the README and show the four sets #13.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Player moves] --> B[Delayed call]
  B --> C[Ask default agent]
  C --> D{Answer}
  D -->|Legal move| E[Apply move and save]
  D -->|No legal move| F[Retry once]
  F --> D
  D -->|Error or timeout| G[Show failure]
  G --> H[Ask again, undo, or new game]
Loading

Reviews (1) · Last reviewed commit: "Play against the default Omarchy agent" · Reviewed by Greptile

Comment thread src/agentplayer.cpp
const auto match = found.next();
for (auto candidate : legal) if (coordinates(candidate) == match.captured(1).toLower() && match.capturedStart() > best) { best = match.capturedStart(); *move = candidate; }
}
if (best >= 0) return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The final choice is ignored

parse() returns after finding a legal coordinate move, before checking later moves written as SAN. After e4, an answer such as “I considered e7e5, but my move is Nf6” plays e5, not the final choice. Compare both forms before choosing the last legal move.

Comment thread src/agentplayer.cpp
Comment on lines +87 to +90
const QRegularExpression written("(?<![A-Za-z0-9])" + QRegularExpression::escape(san) + "(?![A-Za-z0-9=])");
for (auto found = written.globalMatch(answer); found.hasNext();) {
const auto match = found.next();
if (match.capturedStart() > best) { best = match.capturedStart(); *move = candidate; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The wrong castle is played

When both castles are legal, answering O-O-O selects O-O. The shorter pattern matches the start of O-O-O because its boundary allows -. legal() lists the short castle first, and the strict position comparison prevents the full match from replacing it. Match the whole castle name and add a test with both castles legal.

Comment thread src/backend.cpp
Comment on lines +116 to +119
if (m_agent) {
// The agent answers in its own time, in a process of its own; its move or its failure comes back as a signal.
m_agentPlayer.ask(position(),m_notation);
emit changed();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 An old timer asks again

scheduleComputer() can ask a stalled agent again without the player choosing “Ask again.” Each applied move leaves a timer behind. If the player moves within 420 ms of the previous agent move, two timers can remain: the first starts the next request, and the second restarts it if it fails quickly.

That restart leaves m_agentStalled set, so a successful answer does not clear the stalled UI. Stop here when m_agentStalled is true, or discard timers from older turns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant