[PR #50] [MERGED] Agent control: a game-playing CLI (horizon-ctl) and MCP server #2298

Closed
opened 2026-11-02 15:54:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/50
Author: @ludovic111
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @ludovic111

Base: main ← Head: agent-control


📝 Commits (8)

  • 2df60cd Control socket: a token-guarded localhost TCP transport beside the Unix socket
  • 7bb3347 Agent control: observe and act from the control socket
  • 24a70e8 horizon-ctl: help for every command, launch from the launcher, MCP server
  • 772e0a7 tools/agent_control_e2e.py: play a survival start through the CLI and MCP
  • 601fbb5 Ship horizon-ctl in the release folders
  • 6716b0d Docs: agent control with horizon-ctl and its MCP server
  • c0f468a horizon-ctl: horizon-ctl - returns the last failure's status
  • 502c8b9 agent_control_e2e: pick up a drop from within a block (it can land under the trunk)

📊 Changes

21 files changed (+4242 additions, -286 deletions)

View changed files

📝 .github/workflows/release.yml (+10 -5)
📝 README.md (+16 -2)
➖ crates/horizon-client/src/bin/horizon-ctl.rs (+0 -204)
➕ crates/horizon-client/src/bin/horizon-ctl/commands.rs (+578 -0)
➕ crates/horizon-client/src/bin/horizon-ctl/launch.rs (+386 -0)
➕ crates/horizon-client/src/bin/horizon-ctl/main.rs (+481 -0)
➕ crates/horizon-client/src/bin/horizon-ctl/mcp.rs (+238 -0)
📝 crates/horizon-client/src/control.rs (+259 -52)
📝 crates/horizon-client/src/game.rs (+4 -0)
➕ crates/horizon-client/src/game/agent.rs (+1725 -0)
📝 crates/horizon-client/src/game/control.rs (+8 -0)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/title.rs (+1 -0)
📝 crates/horizon-client/src/ui.rs (+1 -0)
📝 crates/horizon-client/src/ui_theme.rs (+6 -0)
➕ crates/horizon-client/src/widgets.rs (+120 -0)
📝 docs/native-client.md (+83 -21)
📝 packaging/PLAY.txt (+9 -0)
📝 packaging/package.sh (+10 -1)
➕ tools/agent_control_e2e.py (+302 -0)

...and 1 more files

📄 Description

AI agents and scripts can now play Horizon: horizon-ctl is a complete game-control CLI and horizon-ctl mcp serves the same commands as an MCP server. Every existing control command and its reply is unchanged (save_roundtrip passes).

Commands

horizon-ctl help lists them by group; horizon-ctl COMMAND --help explains one with examples; horizon-ctl help --game lists the running game's own (test hooks included).

  • Session: launch [--world W] [--seed N] [--creative] [--version TAG] [--game PATH] [--wait], wait-ready, open, save, quit, screenshot, status
  • Observe: state (position, block_pos, eye, yaw/pitch, velocity, on_ground, health, food, saturation, XP, effects, gamemode, dimension, time, weather, screen/title menu, held item, crosshair target, running action), looking-at (block with face/point/distance, or entity), entities [RADIUS] [TYPE], block X Y Z, blocks X1 Y1 Z1 X2 Y2 Z2, find-block BLOCK [RADIUS], inventory (hotbar, main, armor, offhand, carried, counts, components as SNBT), screen (buttons, slots with click-slot ids, title menu mode/worlds/fields), messages (chat, title, subtitle, action bar)
  • Move: move DIR SECONDS [--sprint] [--sneak] [--jump], goto X Y Z [--near R] [--sprint] [--direct] [--timeout S] (A* over standable blocks, then steering; fails at once when there is no path), jump, look, turn, look-at X Y Z | block X Y Z [FACE] | entity ID, tp
  • Act: break X Y Z (holds attack until it breaks; replies with drops, pickups and where unpicked drops lie), place X Y Z [--item ITEM], interact X Y Z [FACE], use-item [--hold S], attack [ID], select SLOT|ITEM, drop [all], key, hold, mouse, stop
  • Screens: open-inventory, click-slot SLOT [right] [shift], close, click-button LABEL, click-at X Y, type [--field name|seed] [--replace] TEXT, chat, command, respawn, pause, resume
  • World: give, time, setblock, summon, wait TICKS, effect, render-distance; benchmarks bench, stats, fly
  • Scripting: script [FILE] [--keep-going] (shell-like quoting, # comments, sleep), horizon-ctl - (old form), mcp

Actions block until done or timed out and reply with the outcome. Errors are {"error": ...} JSON; exit status 0 ok, 1 game error, 2 usage, 3 game unreachable / launch failed.

Design

  • Game side (game/agent.rs, new): observation and action commands; actions that take time are a task advanced every frame (one at a time; stop cancels and releases keys). Hooked into game/control.rs with 8 lines (dispatch, per-frame advance, help).
  • Buttons by label, on any screen and either menu style: widgets.rs records the labelled buttons drawn each frame (one-line hooks in ui::button, the classic title buttons and Horizon's Ui::button); click-button synthesizes a real pointer move + press/release through window_event (winit's safe dummy device id), so it behaves exactly like the mouse.
  • Transport: Unix socket on Linux/macOS (unchanged default). On Windows — or any endpoint path ending in .json — the game listens on a random 127.0.0.1 port and writes {"transport":"tcp","port":N,"token":"<128-bit>"} (mode 0600) to the path; a client's first line must be auth TOKEN (constant-time compare). control::connect / Stream serve both; the stale-endpoint check and cleanup work for both.
  • CLI (bin/horizon-ctl/): one command table (commands.rs) drives help, --help and the MCP tool list with JSON schemas, so they can't drift. launch (launch.rs) uses --game, else a horizon-client beside horizon-ctl (dev build or release folder), else the newest launcher install (<launcher home>/versions/<tag>, .installed), with its prepared resources and the game home as cwd — mirroring launcher/src/backend.rs.
  • MCP (mcp.rs): stdio JSON-RPC in the launcher's style, 48 tools, screenshot returned as an image content block, launch waits for the world by default.
  • Shipping: release.yml builds horizon-ctl (import-checked), packaging/package.sh copies it from beside the client and refuses to package without it (the hand-made macOS folders go through it too), package_native_client.py adds it. README "Agent control" section (removed from the roadmap), native client guide, PLAY.txt.

Evidence

  • tools/agent_control_e2e.py on vscreen (lavapipe, HORIZON_NO_AUDIO=1): creates a world through the title menus (click-button Singleplayer → Create New World → type --field name --replace / --field seed → Create New World), finds a tree, goto --near 2.5, breaks the bottom log, picks it up, checks inventory, crafts planks in the inventory screen's 2x2 grid with click-slot, closes, places a plank and reads it back with block and looking-at. Passed in both CLI and MCP modes on 4 runs (~20 s each); the MCP run gets the screenshot as an image.
  • TCP transport with a real game (--socket ….json): endpoint file 0600, bound to 127.0.0.1 only, removed on quit; wrong tokens refused (unit test).
  • cargo check --target x86_64-pc-windows-msvc -p horizon-client --lib --bins is clean.
  • Unit tests: argument parsing (game and CLI), MCP argument → command line conversion and schemas, script line splitting, launch discovery (version order, beside-ctl, unprepared), base64, TCP round trip / bad token, widget lookup.
  • tools/gate.py --quick passes (public tree, rustfmt, clippy -D warnings, Python tests). save_roundtrip (the harness driving the socket) passes. The 58 harnesses whose inputs these changes touch (tools/parity.py --hosts macmini) all pass.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/50 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `agent-control` --- ### 📝 Commits (8) - [`2df60cd`](https://github.com/horizon-rust/horizon/commit/2df60cd388661399513bb45d0ae025a43893de4f) Control socket: a token-guarded localhost TCP transport beside the Unix socket - [`7bb3347`](https://github.com/horizon-rust/horizon/commit/7bb3347edd6e5035fabd9fd76f7f03cb2c3ad3db) Agent control: observe and act from the control socket - [`24a70e8`](https://github.com/horizon-rust/horizon/commit/24a70e84a86f5ad315610e7bb023ffc45ea7a907) horizon-ctl: help for every command, launch from the launcher, MCP server - [`772e0a7`](https://github.com/horizon-rust/horizon/commit/772e0a7070957d5d22934d904ba1e6fb5abacbe2) tools/agent_control_e2e.py: play a survival start through the CLI and MCP - [`601fbb5`](https://github.com/horizon-rust/horizon/commit/601fbb533a051e92f0ad3df327f686948c602d79) Ship horizon-ctl in the release folders - [`6716b0d`](https://github.com/horizon-rust/horizon/commit/6716b0d9531fdfcf072b8ddc4bdae990b245019d) Docs: agent control with horizon-ctl and its MCP server - [`c0f468a`](https://github.com/horizon-rust/horizon/commit/c0f468a8718887f081f55696db4b253e246a7b27) horizon-ctl: horizon-ctl - returns the last failure's status - [`502c8b9`](https://github.com/horizon-rust/horizon/commit/502c8b9311f6c2ac17ee64a830c4d211cfcc0579) agent_control_e2e: pick up a drop from within a block (it can land under the trunk) ### 📊 Changes **21 files changed** (+4242 additions, -286 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/release.yml` (+10 -5) 📝 `README.md` (+16 -2) ➖ `crates/horizon-client/src/bin/horizon-ctl.rs` (+0 -204) ➕ `crates/horizon-client/src/bin/horizon-ctl/commands.rs` (+578 -0) ➕ `crates/horizon-client/src/bin/horizon-ctl/launch.rs` (+386 -0) ➕ `crates/horizon-client/src/bin/horizon-ctl/main.rs` (+481 -0) ➕ `crates/horizon-client/src/bin/horizon-ctl/mcp.rs` (+238 -0) 📝 `crates/horizon-client/src/control.rs` (+259 -52) 📝 `crates/horizon-client/src/game.rs` (+4 -0) ➕ `crates/horizon-client/src/game/agent.rs` (+1725 -0) 📝 `crates/horizon-client/src/game/control.rs` (+8 -0) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/title.rs` (+1 -0) 📝 `crates/horizon-client/src/ui.rs` (+1 -0) 📝 `crates/horizon-client/src/ui_theme.rs` (+6 -0) ➕ `crates/horizon-client/src/widgets.rs` (+120 -0) 📝 `docs/native-client.md` (+83 -21) 📝 `packaging/PLAY.txt` (+9 -0) 📝 `packaging/package.sh` (+10 -1) ➕ `tools/agent_control_e2e.py` (+302 -0) _...and 1 more files_ </details> ### 📄 Description AI agents and scripts can now **play** Horizon: `horizon-ctl` is a complete game-control CLI and `horizon-ctl mcp` serves the same commands as an MCP server. Every existing control command and its reply is unchanged (`save_roundtrip` passes). ## Commands `horizon-ctl help` lists them by group; `horizon-ctl COMMAND --help` explains one with examples; `horizon-ctl help --game` lists the running game's own (test hooks included). - **Session:** `launch [--world W] [--seed N] [--creative] [--version TAG] [--game PATH] [--wait]`, `wait-ready`, `open`, `save`, `quit`, `screenshot`, `status` - **Observe:** `state` (position, block_pos, eye, yaw/pitch, velocity, on_ground, health, food, saturation, XP, effects, gamemode, dimension, time, weather, screen/title menu, held item, crosshair target, running action), `looking-at` (block with face/point/distance, or entity), `entities [RADIUS] [TYPE]`, `block X Y Z`, `blocks X1 Y1 Z1 X2 Y2 Z2`, `find-block BLOCK [RADIUS]`, `inventory` (hotbar, main, armor, offhand, carried, counts, components as SNBT), `screen` (buttons, slots with click-slot ids, title menu mode/worlds/fields), `messages` (chat, title, subtitle, action bar) - **Move:** `move DIR SECONDS [--sprint] [--sneak] [--jump]`, `goto X Y Z [--near R] [--sprint] [--direct] [--timeout S]` (A* over standable blocks, then steering; fails at once when there is no path), `jump`, `look`, `turn`, `look-at X Y Z | block X Y Z [FACE] | entity ID`, `tp` - **Act:** `break X Y Z` (holds attack until it breaks; replies with drops, pickups and where unpicked drops lie), `place X Y Z [--item ITEM]`, `interact X Y Z [FACE]`, `use-item [--hold S]`, `attack [ID]`, `select SLOT|ITEM`, `drop [all]`, `key`, `hold`, `mouse`, `stop` - **Screens:** `open-inventory`, `click-slot SLOT [right] [shift]`, `close`, `click-button LABEL`, `click-at X Y`, `type [--field name|seed] [--replace] TEXT`, `chat`, `command`, `respawn`, `pause`, `resume` - **World:** `give`, `time`, `setblock`, `summon`, `wait TICKS`, `effect`, `render-distance`; benchmarks `bench`, `stats`, `fly` - **Scripting:** `script [FILE] [--keep-going]` (shell-like quoting, `#` comments, `sleep`), `horizon-ctl -` (old form), `mcp` Actions block until done or timed out and reply with the outcome. Errors are `{"error": ...}` JSON; exit status 0 ok, 1 game error, 2 usage, 3 game unreachable / launch failed. ## Design - **Game side** (`game/agent.rs`, new): observation and action commands; actions that take time are a task advanced every frame (one at a time; `stop` cancels and releases keys). Hooked into `game/control.rs` with 8 lines (dispatch, per-frame advance, help). - **Buttons by label, on any screen and either menu style:** `widgets.rs` records the labelled buttons drawn each frame (one-line hooks in `ui::button`, the classic title buttons and Horizon's `Ui::button`); `click-button` synthesizes a real pointer move + press/release through `window_event` (winit's safe dummy device id), so it behaves exactly like the mouse. - **Transport:** Unix socket on Linux/macOS (unchanged default). On Windows — or any endpoint path ending in `.json` — the game listens on a random `127.0.0.1` port and writes `{"transport":"tcp","port":N,"token":"<128-bit>"}` (mode 0600) to the path; a client's first line must be `auth TOKEN` (constant-time compare). `control::connect` / `Stream` serve both; the stale-endpoint check and cleanup work for both. - **CLI** (`bin/horizon-ctl/`): one command table (`commands.rs`) drives `help`, `--help` and the MCP tool list with JSON schemas, so they can't drift. `launch` (`launch.rs`) uses `--game`, else a `horizon-client` beside horizon-ctl (dev build or release folder), else the newest launcher install (`<launcher home>/versions/<tag>`, `.installed`), with its prepared resources and the game home as cwd — mirroring `launcher/src/backend.rs`. - **MCP** (`mcp.rs`): stdio JSON-RPC in the launcher's style, 48 tools, `screenshot` returned as an `image` content block, `launch` waits for the world by default. - **Shipping:** `release.yml` builds horizon-ctl (import-checked), `packaging/package.sh` copies it from beside the client and refuses to package without it (the hand-made macOS folders go through it too), `package_native_client.py` adds it. README "Agent control" section (removed from the roadmap), native client guide, PLAY.txt. ## Evidence - `tools/agent_control_e2e.py` on vscreen (lavapipe, `HORIZON_NO_AUDIO=1`): creates a world through the title menus (`click-button Singleplayer` → `Create New World` → `type --field name --replace` / `--field seed` → `Create New World`), finds a tree, `goto --near 2.5`, `break`s the bottom log, picks it up, checks `inventory`, crafts planks in the inventory screen's 2x2 grid with `click-slot`, `close`s, `place`s a plank and reads it back with `block` and `looking-at`. Passed in **both CLI and MCP modes** on 4 runs (~20 s each); the MCP run gets the screenshot as an image. - TCP transport with a real game (`--socket ….json`): endpoint file 0600, bound to 127.0.0.1 only, removed on quit; wrong tokens refused (unit test). - `cargo check --target x86_64-pc-windows-msvc -p horizon-client --lib --bins` is clean. - Unit tests: argument parsing (game and CLI), MCP argument → command line conversion and schemas, script line splitting, launch discovery (version order, beside-ctl, unprepared), base64, TCP round trip / bad token, widget lookup. - `tools/gate.py --quick` passes (public tree, rustfmt, clippy `-D warnings`, Python tests). `save_roundtrip` (the harness driving the socket) passes. The 58 harnesses whose inputs these changes touch (`tools/parity.py --hosts macmini`) all pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:54:44 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2298
No description provided.