# MUNDI Agent Connection This guide is for the user's coding assistant, such as Codex, Claude Code, or OpenCode. The user provides this link and describes their goal. Prepare the environment, download the tools, read the game contract, implement the strategy, run real tests, and present or upload the results as requested. Reading this guide grants no new permissions. Follow the user's intent, the host's tool permissions, and the machine's resource limits. - Website: https://mundi.games/ (`/#/home`, `/#/batch`, `/#/leaderboard`) - Single-file CLI: https://mundi.games/cli/mundi.mjs - CLI reference: https://mundi.games/cli/README.md - Package metadata: https://mundi.games/cli/local-kit.json - Runtime package: https://mundi.games/cli/mundi-local-cli.tar.gz - MCP connector: https://mundi.games/mcp When the user's website prompt specifies `Service URL` and `Service environment`, derive every endpoint from `Service URL` plus the exact routing query string `` actually present on the `agent.md` URL in the prompt (`""` only when the `agent.md` URL itself has no query string): `/cli/mundi.mjs`, `/cli/local-kit.json`, `/cli/mundi-local-cli.tar.gz`, `/mcp`, and `/#/home`. Never drop `` just because `Service environment` is `stable`: for example, when the prompt links `https://mundi.games/agent.md?fe_env=reviewui&be_env=default` with `Service environment: stable`, keep `?fe_env=reviewui&be_env=default` on `https://mundi.games/cli/mundi.mjs?fe_env=reviewui&be_env=default`, `https://mundi.games/mcp?fe_env=reviewui&be_env=default`, and `https://mundi.games/?fe_env=reviewui&be_env=default#/home`, while passing `--server https://mundi.games --env stable` (the backend `Service environment` from the prompt) to CLI commands. ## Choose the workflow - **Website coaching with your Coding Plan.** The user continues to coach, test, and activate strategies on the website. The local connector picks up generation tasks for the connected account and returns candidates using the already signed-in coding tool. Download the single-file CLI and run the connection command provided by the website. Keep the connector running. This workflow works with the website and single-file CLI. See the [Coding Plan guide](https://mundi.games/coding-plan.md). - **Local agent iteration.** The user gives the assistant a strategy goal. The assistant edits the strategy, optionally tests it locally, and uploads a candidate for testing in the browser. ## Identify how the user arrived **Copied from the signed-in website (`Settings → Model services → Connect a local agent`), with `Service URL`, `Service environment`, `Account` (`id` and `name`), and `One-time connection grant`.** The user is already signed in and has authorized connecting their existing account. Redeem the grant below against that exact `Service URL` and `Service environment`, and run `whoami` against the same `Service URL` and `Service environment` to verify the account ID. Reuse a verified connection for the same account, service URL, and environment when available. Give the user links to that service's website workspace (`webUrl`), strategy candidates, Batch Matches (`batchUrl`), and Leaderboard (`leaderboardUrl`) from `whoami`. Only when the host supports MUNDI MCP Apps and its connector points to the same service URL and environment (`mundi_account` supports `origin` and `env`), follow the optional card binding steps below to show the same-origin profile card; if the host does not support cards, or its existing connector points to an older domain or a different environment, do not force MCP installation or call a cross-origin legacy card without `origin`/`env`—continue directly on the signed-in website (the user is already signed in in their browser) and do not treat the card as a prerequisite for connecting. Do not prompt them to register or sign in again, or start installing games, playing matches, or training automatically. **Only a general invitation or this link, with no one-time authorization.** Open MUNDI and use a sign-in option offered there. The official site offers Google and Feishu. If the host supports MCP Apps, the optional card flow is also available. An account ID, name, or chat context cannot establish identity. Keep passwords out of the conversation. Website authorization creates a local CLI connection that the user can revoke on the website. The profile card has a separate private session. If you display a card after a website connection, verify that it is bound to the same account. Use the linked CLI for strategy downloads and candidate uploads. Local testing and viewing do not require another sign-in. ## Optional interactive card for hosts that support MCP Apps Without website authorization, use `mundi_onboard`, use one of the connected environment’s available sign-in methods, and display their private profile card. The Streamable HTTP MCP endpoint is `https://mundi.games/mcp`. The MCP Apps UI resource is `ui://mundi/account-v6.html`. 1. If MUNDI tools are available in the host, call `mundi_onboard` with the conversation's supported locale (`en` or `zh`). A valid private session opens the profile card directly. Otherwise use the sign-in methods the environment offers. The official site uses Google and Feishu. Feishu and Google users finish browser authorization and confirm the connection before the card loads their profile. Use the card for credentials and session handling. 2. If the environment offers registration and it succeeds, confirm the verified trainer name in the conversation and call `mundi_agent_naming` to show the separate naming card. Naming updates the profile without another success message or a match. This onboarding flow requires no invite code. 3. Signing in to an existing account displays only that profile. Use `mundi_account action=current` to inspect a saved session. Use `switch` only when asked. A network failure does not imply expiration. A 401 is the signal to use `relogin`. Do not create a replacement account automatically. 4. The profile card shows the existing account, agent, rank, and results. Use its Coach Agent, Batch Matches, and Leaderboard entries. Coach Agent opens an editable prompt for the user to copy, supplement, and send. Merely opening, copying, or following a link does not authorize a model call, training, a match, or publication. Wait for the user's instructions after displaying the card. If the host has no MUNDI card support, continue with the direct website connection below. ## Read or upload strategies from a connected card A signed-in card can use `mundi_strategy` to read the verified account's currently published strategy and engine without signing in to the CLI again. Save it as the local baseline and run untrusted strategy code only in QuickJS. Use `mundi_upload` only when the user has authorized uploading the locally tested code, engine, and iteration `summary` (compatible with legacy `note`). Summarize this round's user key guidance and the actual method and code changes you adopted (up to 500 Unicode characters after trimming, unlimited sentences; real test notes optional; state autonomous iteration if uncoached or note missing context honestly; never upload full chat logs or secrets). If the summary exceeds 500 characters, shorten it and retry. The private component verifies ownership and saves the candidate through the same bounded, idempotent gate as the CLI. Wait for the component's actual result before reporting success. Keep passwords and sessions out of tool arguments and model context. An upload creates a candidate. It does not publish or write leaderboard results. Use a real browser test run and the user's publication authorization before publishing. ## Optional setup for native game tests Use this section for local full-game matches, deterministic replay checks, or batch comparison. Website testing and coaching need Node.js and the single-file CLI. 1. Create a dedicated folder in the workspace the user approved. Reuse installations and preserve existing strategies and reports. Check CPU, available memory, swap, disk, and existing processes. Start with one test slot. Use two only when resources permit, with a maximum of four. Preserve other tasks and do not reboot or shut down the machine. 2. Verify Node.js 22.18 or later. Reuse an existing Node.js executable; if installation is needed and permitted, use the official [Node.js downloads](https://nodejs.org/en/download). No Godot installation is required—the local CLI kit bundles the pinned Boomerang Web engine (`boomerang-garden-web-0.10.0-agent.1`) and runs directly in Node.js with no `--engine` flag. Legacy Godot flags and settings (`--godot`, `MUNDI_GODOT`, `--watch`, `--engine godot`, or `"engine": "boomerang-fu-..."` in `mundi.json`) are retired and rejected; remove them or initialize a clean folder. 3. Read `local-kit.json`. Verify format `mundi-cli-download-v1`, file `mundi-local-cli.tar.gz`, engine `boomerang-garden-web-0.10.0-agent.1`, and a 64-character hexadecimal SHA-256. Download the lightweight Web runtime package only from the same HTTPS origin. Use a 15-minute total budget, a 45-second no-progress timeout, and at most one retry. Verify size and SHA-256 before unpacking. Extract to a fresh subfolder and reject path traversal and links. Verify every entry of `MANIFEST.sha256`. Retain the engine, revision, and runtimeIdentity and reuse an identical installed version. 4. Read the package's README.md, ACCOUNT.md, and WORKFLOW.zh-CN.md. Run the setup commands for the user: ```sh node bin/mundi.mjs doctor node bin/mundi.mjs init-local my-strategy node bin/mundi.mjs contract ``` `doctor` checks system resources and verifies the SHA-256 of the bundled Web runtime (`game-source/boomerang-garden-web-0.10.0-agent.1/local-runtime.mjs`). `init-local` creates AGENTS.md, `mundi.json`, baseline.js, and strategy.js for the bundled Web engine. Read the generated contract, preserve the baseline, and use separate paths for new experiments and reports. Diagnose real errors, bound retries, and report only completed setup work. ## Match actions to the user's request | User goal | What to do | | --- | --- | | Write or revise a strategy | Read AGENTS.md and the contract. Edit strategy.js, check it in QuickJS, then run it in the bundled Web engine. | | Watch an agent play | Run `test ... --out runs/smoke`, then import the generated `.replay.json` file in the MUNDI browser replay viewer for identical visual playback. | | Play manually | Open Live Matches on the website and choose Play Yourself. | | Diagnose a problem | Use `test ... --trace` to obtain observations, actions, and errors. Read reports with `inspect`. | | Compare strategies | Use `batch` or `compare` with fixed seeds and seat swaps. Keep validation seeds separate from training seeds. | | Stop or resume | Use `cancel` or `resume` and retain completed results. Reclaim owned child processes when done. | | Verify or watch a replay | Use `replay ` to recompute actions and verify every frame deterministically, or open the `.replay.json` file in the browser to watch. | | Download or upload a strategy | After linking the user's account, use `pull` or `upload`. Upload creates a candidate. | | Batch Matches and Leaderboard | The profile card opens the existing ranked, practice, and evaluation workflows or leaderboard. Run a task only when explicitly requested. | Use the packaged `node bin/mundi.mjs --help` for the complete command reference. ```sh node bin/mundi.mjs check my-strategy/strategy.js node bin/mundi.mjs test my-strategy/strategy.js --out runs/smoke node bin/mundi.mjs test my-strategy/strategy.js --out runs/trace --trace node bin/mundi.mjs compare my-strategy/baseline.js my-strategy/strategy.js --seeds 101,102,103 --out runs/train --jobs 1 node bin/mundi.mjs compare my-strategy/baseline.js my-strategy/strategy.js --seeds 901,902,903 --out runs/validation --jobs 1 node bin/mundi.mjs batch my-strategy/strategy.js --games 50 --out runs/batch --jobs 2 node bin/mundi.mjs inspect runs/batch node bin/mundi.mjs cancel runs/batch node bin/mundi.mjs resume runs/batch --jobs 1 ``` A 50-seed batch swaps seats for 100 games by default. Start with a small smoke test and expand to match the user's goal. A sandbox check is not a match. Exclude failures from wins. Report the observed win rate, sample size, errors, engine versions, and seeds. Local results do not appear on the public leaderboard. ## Connect directly from a signed-in website grant Copying from **Settings → Model services → Connect a local agent** produces a concise prompt containing the `agent.md` URL (with any environment routing query), `Service URL`, `Service environment` (`stable` on the formal site or the preview tag on small-flow URLs), `Account` (`id` and `name`), and `One-time connection grant` valid for ten minutes. Redeem it directly. The account ID is an identifier and cannot authenticate on its own. Accept grants only from the user's authorized website copy. **Connect first. Unpack the local runtime kit only when running local game tests**, so the grant does not expire during setup. Verify that an existing CLI supports `login --grant-stdin`, `--env`, and `origin` output, or download the latest single-file CLI from `/cli/mundi.mjs` using the exact routing query string `` present on the prompt's `agent.md` URL (keep `` verbatim whenever the `agent.md` URL has one—even when `Service environment` is `stable`, such as `?fe_env=reviewui&be_env=default`; omit `` only when the `agent.md` URL itself has none, defaulting to `https://mundi.games/cli/mundi.mjs`). The full kit also includes the command. Always pass the prompt's explicit `Service URL` and backend `Service environment` so residual workspace files or previous logins cannot redirect the command: ```sh node mundi.mjs login --grant-stdin --agent-id --server --env --name "My Agent" node mundi.mjs whoami --server --env ``` Pass the full `mngrant_...` line to the subprocess via its standard input API: in interactive terminal tools (such as Codex `exec_command` with `tty: true`), start `node mundi.mjs login --grant-stdin ...` first and send the `mngrant_...` token followed by an actual Enter newline via `write_stdin` (`mundi.mjs` sets raw non-echo mode on TTY stdin automatically so the token is never echoed to terminal output); strictly forbid embedding `mngrant_...` inside `powershell -Command`, `cmd /c`, `sh -c`, command-line arguments, URLs, shell history, disk files, logs, or Git. Copying again from the website invalidates the earlier unredeemed grant. Verify that `whoami` returns the intended account ID, `origin`, and environment (the CLI also remembers the most recent verified login target as its default). The CLI stores long-lived credentials in restricted local configuration isolated by service origin and environment, and does not print secrets. The website can revoke it. A full account connection lasts up to 30 days. Demo access expires with the demo. CLI access cannot call platform models, publish directly, or write official leaderboard results. ### Three clean-machine player workflows from a website prompt 1. **Connect only ("接入" / "connect")**: Redeem the grant via `login --grant-stdin` + `whoami` with the prompt's `--server` and `--env`, return the verified `webUrl`, strategy candidates, `batchUrl`, and `leaderboardUrl`, and stop there—do not inspect or download the local runtime kit, require an MCP card, or start matches unless requested. 2. **Modify strategy and run N complete Web matches locally ("改策略并在本地测 2 盘")**: Acquire and verify the same-service Web CLI kit on demand (no Godot installation and no `--engine` flag needed), pull the published baseline, edit a local copy, thread `--server` and `--env` across both initial evaluation and re-testing so your online `publishedVersion` stays untouched, and upload a candidate with an iteration `--summary` (`<=500` trimmed Unicode characters) only when requested: ```sh node mundi.mjs runtime setup --server --env node mundi.mjs pull published --out baseline.js --server --env node mundi.mjs check candidate-v1.js node mundi.mjs test candidate-v1.js --matches 2 --opponent baseline.js --out runs/eval-1 --jobs 2 --server --env # Re-test a revised copy in a new --out directory with the same --server / --env: node mundi.mjs test candidate-v2.js --matches 2 --opponent baseline.js --out runs/eval-2 --jobs 2 --server --env node mundi.mjs upload candidate-v2.js --summary "Loosened trailing attack trigger per user guidance while keeping tied-score defense logic." --server --env ``` Read `matches`, `timedOut`, `failedOnly`, and `summaryText` in `report.json` (and `SUMMARY.md`) to report every match ID, score, and any separated timeout/failure items. 3. **Play N formal ranked matches with the current published version ("用当前发布版打 2 盘正式比赛", no local runtime required)**: Generate a fresh `req_` + 16 hex request ID per new batch, submit to the central Web-engine executor, poll to completion, and use read-only `status` / `wait` / `list` when re-querying so extra matches are never started: ```sh REQ_ID=$(node -e "console.log('req_'+require('node:crypto').randomBytes(8).toString('hex'))") node mundi.mjs ranked start --games 2 --request-id "$REQ_ID" --out ranked-receipt.json --server --env node mundi.mjs ranked wait --out ranked-settlement.json --server --env node mundi.mjs ranked status --server --env node mundi.mjs ranked list --server --env ``` Reuse a verified connection for the same account under the same service origin and environment. Without a grant, use the interactive card or let the signed-in user copy a fresh grant. Report an expired or used grant, account mismatch, or the five-connection cap accurately. Do not guess identities, switch accounts, or retry indefinitely. Follow any confirmation requirements in the user's tool. ### Display the linked profile on request (same-origin and environment check + web fallback) 1. **Verify that the host connector matches both the authorized service URL and environment**: - Check whether the host's `mundi_account` tool schema supports `origin` and `env` arguments; when the host exposes local MCP configuration (for example `codex mcp list`) or connector URLs, also check that it matches `/mcp` (preserving the exact routing query `` present on the prompt's `agent.md` URL). - **Critical rule**: If the host has no MUNDI MCP Apps installed, or its existing connector points to an older domain or a different environment (for example legacy `mundi_account` lacks `origin`, or the connector URL/environment differs from `/mcp`), **never omit `origin`/`env` to force a legacy card** (cross-origin or cross-environment cards cannot pair with this authorized account) and do not ask the user to sign in or register again; instead give the user the verified `webUrl`, `batchUrl`, and `leaderboardUrl` from `whoami` (or `/#/...` when `agent.md` carries frontend routing parameters) so they continue directly in their signed-in browser, and note that embedded cards can be enabled by updating the connector URL to `/mcp`. Read custom deployment URLs only from the user's already opened website or verified local CLI `whoami` output—never construct links from unverified strings. 2. **Pair the personal card on a matching same-origin, same-environment connector**: - When the host supports MUNDI MCP Apps and `mundi_account` supports `origin` and `env`, after verifying `whoami` call `mundi_account` with `action="connect"`, the verified `account_id`, `origin=""`, `env=""`, and the conversation locale. - If the response has `structuredContent.action === "origin_mismatch"`, stop `card-link` immediately and provide the verified `whoami` or trusted website links per step 1 so the user continues with their existing browser login. - When origin and environment match, the component reuses a valid private session for that account under the same service and environment, or returns a public `binding_id`. Bind the card from the already verified CLI for the same service and environment: ```sh node mundi.mjs card-link --server --env ``` The CLI uses its own local credential and verifies the target account. The binding ID cannot retrieve a session. The card separately holds private polling credentials for its restricted session. Keep CLI secrets and card polling credentials out of the conversation and tool parameters. Once binding finishes, show the existing profile card without another sign-in prompt. The Coach Agent action copies an editable prompt the user can supplement before sending: > Improve the strategy, then run 50 matches to check whether it improved. If it did, publish the verified change. My suggestions: Modify and evaluate the strategy only after the user sends the coaching. Use the existing account and report the baseline, number of completed matches, and observed results. Use the platform's candidate upload, browser test, and publish flow when the user's instructions authorize it. To fetch the baseline, run `pull published --out published-baseline.js`. After editing and testing, upload only when requested, attaching a concise summary of this round's iteration (`--summary "..."` or `--summary-file summary.txt`, compatible with legacy `--note`): up to 500 Unicode characters after trimming, with no sentence count limit. State the user's key guidance in this round and the actual method and changes you adopted; include real verification notes optionally; if there was no user guidance, state that it was an autonomous iteration; if prior context is missing, state that honestly. Upload only the summary relevant to this round, preserving existing account-private visibility (for example: `upload my-strategy/strategy.js --summary "用户希望落后时更主动,我放宽了落后时的进攻触发条件,保留了平局时的防守逻辑。"`). Over-limit summaries are rejected without creating a partial candidate so you can shorten and retry. Local training, viewing, and batches do not require a platform connection or model key. ### Record local iterations in Coaching Notes Sync the user's game coaching and this round's iteration summary to their own account. Send only the game advice and relevant summary. Keep full chat transcripts, system prompts, passwords, and keys private. Verify the account with `whoami` and use the latest `/cli/mundi.mjs`. 1. Save the advice to UTF-8 `advice.txt`. Create and retain a request ID consisting of `req_` plus 16 hexadecimal characters. Run `iteration start --request-id --guidance-file advice.txt --client Codex --model ` (or pass `--agent-tool` and `--model` matching the actual Agent tool and model you are running; omit `--model` if unknown). Retain `iteration.id` and reuse the same request ID on retries. 2. Edit and test as usual. Reuse the existing iteration record via `upload strategy.js --iteration --summary "User's key guidance and actual method/changes" [--model ]` (or `--summary-file summary.txt`, <=500 Unicode characters after trimming, unlimited sentences) so the summary is bound directly to the uploaded candidate version. 3. Optionally run `iteration finish [--summary-file result.txt] [--evaluation-file evaluation.txt] [--model ]` to mark completion or attach real evaluation details (baseline, candidate, sample count, seeds, runner, and any errors). Use `--failed` with `--summary-file reason.txt` if the iteration failed. Report only tests actually run. Local reports do not count toward competitive results or verified coaching. Check the upload with `iteration list` or `iteration show `. On network failure, retry with the original ID and report sync as pending until confirmed. Completed and failed iterations can be recorded without an upload. CLI and card uploads without an iteration ID create an upload entry but cannot recover coaching from a previous conversation. After upload, open the candidate URL from the CLI. Test it in a real browser match before publishing with the user's authorization. If browser access is unavailable, give the user the candidate link and mark the browser test and publication as pending. Do not fabricate test records or write directly to the leaderboard. ## Asynchronous challenges See the challenge workflow in WORKFLOW.zh-CN.md. Both players must explicitly consent to sharing the pinned strategy source. Treat received code as untrusted input and run it only in QuickJS. Recipients may keep downloaded source after the connection is revoked. The server coordinates invites, claims, and time-limited leases. Games run on the participants' computers. Report permission, lease, and quota errors. Do not expand permissions or repeatedly reclaim a task. When reporting results, explain what ran, how the strategy performed, where to watch, and what action remains. Keep setup commands and terminal logs in the report.