Repository navigation
Conversation
The old MCP bridge polls a browser tab and rebuilds state from the UI. For automated play and tests, run the ordinary runtime and WASM core in Node worker threads instead, and observe through the core's structured output (knowledge frames, inventory JSON, glances) and the displayed map. - src/headless: Node asset loading, a frozen clock so a seed replays the same game, one game per thread, and AgentSession, which turns runtime events into typed prompts and acts until the game waits for input again. - scripts/headless/game-client.mjs bundles the worker with esbuild and starts each game in its own worker thread. - scripts/mcp/headless-server.mjs exposes new_game, observe, act, inventory and end_game over stdio. - LocalNetHackRuntime.isMultiSelectMenuActive() tells pickup-style menus apart. - src/headless is type-checked with Node types in tsconfig.headless.json. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For headless play and tests: - sys_random_seed() takes globalThis.nh3dHeadless.seed when the shell sets it, as a weak seed so reseed_random() leaves the game reproducible. - parse() queues "shim_command_ready" (turn, hero x, y) before reading a command, so the shell can tell a command prompt from any other key the game reads and knows the turn even when the map did not change. - The #nh3dinventory request "reveal" publishes "shim_reveal" in debug mode only: true terrain (secret doors and corridors included), every monster, floor object and trap, and luck, alignment, prayer timeout, god anger and nutrition. It reads level data directly, without the random number generators, and takes no time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A key the game reads while choosing a position moves the cursor or picks, but the window port cannot tell such a key request from any other. The shell needs to know to show a position prompt (teleport, travel, farlook, targeting) and where the cursor starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
public/nethack-5.js and public/nethack-5.wasm come from the game-core-wasm artifact of Build game core (WASM) run 45813280145, which also checked that saves from the previous core load in this one. The glyph catalog is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The runtime turns the core's shim_command_ready, shim_getpos and
shim_reveal notifications into command_ready, getpos and reveal events.
The session uses them to tell a command prompt from a key read inside a
command ("key"), and to show position prompts with the cursor that
getpos() last placed.
- Seeds go to the core (0 to 4294967295); the clock stays frozen on an
ordinary day for the moon and the calendar.
- New actions: position (move the cursor with hjkl/HJKL and pick),
inventory (whole item actions by letter or object id through
#nh3dinventory), and reveal. Cursor descriptions are left out of the
messages while a position action moves the cursor.
- HeadlessGame records every action. A snapshot is the setup, the actions
and a fingerprint of what the hero sees; starting from one replays it
and refuses a replay that does not match.
- Debug mode helpers: reveal, wish, create a monster, teleport, level
teleport, map; and travel in any mode.
- The MCP server runs up to eight games by id, saves and loads snapshots
as JSON files inside the working directory, and adds list_games,
travel, snapshot, reveal and debug.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The headless server replaces it for automated play and tests. Removed: scripts/mcp/server.mjs and its smoke client and test, src/automation, the title-screen MCP control and its app controller, the engine's automation surface (getAutomationContext, submitAutomationAction and the observers behind them) and the worker bridge's automation claims. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both sides changed the core. The C sources merge cleanly; the shipped public/nethack-5.* and glyph catalog are main's for now and are replaced by a build of the merged sources in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
public/nethack-5.js and public/nethack-5.wasm come from the game-core-wasm artifact of Build game core (WASM) run 45817268849, built from main's core changes and this branch's together; that run also checked that saves from the previous core load. The glyph catalog is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the last death question the runtime emits game_over_complete and the core asks for nothing more, so a session waiting for the next input request timed out and showed no prompt. The session now treats it as the end: prompt game_over, gameOver.complete with the death message and tombstone, and further actions fail. Found by playing eight seeded games for up to 1500 random actions each; with this, none timed out and both deaths ended cleanly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both sides changed the core again. The C sources merge cleanly; public/ nethack-5.* and the glyph catalog are main's until the merged sources are built. The floor panel comment is main's, which moved the panel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
public/nethack-5.js and public/nethack-5.wasm come from the game-core-wasm artifact of Build game core (WASM) run 45899191432, built from main's core changes and this branch's together; that run also checked that saves from the previous core load. The glyph catalog is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A headless way to play Polypiled for automated play and tests: an MCP server and a test client. Each game runs the ordinary
LocalNetHackRuntimeand the WASM core in a Node worker thread. Observations come from the core's structured output and the displayed map, not from the UI. The old browser bridge is removed.MCP tools (
node scripts/mcp/headless-server.mjs):new_gamelist_gamesobserveacttravelinventorysnapshotnew_gamereplays it into an identical copy.reveal(debug mode)debug(debug mode)end_gamescripts/headless/game-client.mjsexposes the same operations to Node tests. Design notes are indocs/mcp-headless.md.Core changes (built and shipped)
sys_random_seed()takesglobalThis.nh3dHeadless.seedas a weak seed, soreseed_random()keeps games reproducible.parse()queuesshim_command_ready(turn, hero position). The shell can then tell a command prompt from any other key the game reads.getpos()is wrapped to queueshim_getposat start and end, with the cursor's square.#nh3dinventoryrequestreveal(debug mode only) publishesshim_reveal. It reads level data without the random number generators and takes no time.public/nethack-5.*come from Build game core (WASM) run 45813280145. That run also checked that saves from the previous core load in this one. The glyph catalog is regenerated.The app ignores the new events. The only runtime additions are three event translations, one menu accessor and the
revealinventory operation.Removed
scripts/mcp/server.mjsand its smoke client and testsrc/automationgetAutomationContext/submitAutomationActionand their observersNotes for review
getpos()last placed it (map_cursor). They do not use@, because farlook treats@as picking the spot. Autodescribe messages are left out while the cursor moves.wizard, because the injected sysconf allows only that name.src/headlessis checked bytsconfig.headless.jsonwith Node types.check:tscruns both configs.@types/nodeare used as installed today, through other packages. They are not added as explicit devDependencies.Testing
npm run test:headless(13 tests against the real core, about 4 s):#quit) through togame_overand the tombstonenpx vitest run: 2103 passed, 4 skipped. This includesAgentSessionunit tests for the core marks, getpos cursor keys and inventory operations.npm run check:tscpasses.🤖 Generated with Claude Code