<!-- GENERATED by skills/fall-rush-agent/scripts/gen-api.mjs from the gateway's committed contract. Do not edit by hand:
     run `node skills/fall-rush-agent/scripts/gen-api.mjs`. test/api.test.mjs fails when this file drifts. -->

# Fall Rush Arena agent API

Sources: `services/arena-gateway/schema/internal-api.md` §1, `services/arena-gateway/byte/fall-rush-arena.md` (the spec the gateway serves at `GET /v1/byte/spec.md`), `services/arena-gateway/schema/stateview.json` (`Fall Rush Arena StateView v1 (frozen W2-0)`), `crates/rush-core/src/bots/intent.rs`, `services/arena-gateway/src/intents.rs`.

## 1. The calls

Base URL: the hosted Arena is `https://app.fallrush.fun` (FIN-07, config.rs `APP_URL`); another gateway's is its `ARENA_PUBLIC_URL`; ask the operator. A local gateway listens on `http://127.0.0.1:8790` by default (`ARENA_BIND`, config.rs).

| Step | Method | Path | Body | Saves / returns |
|---|---|---|---|---|
| start (create or join) | POST | `/v1/start` | `{"callsign":"{{callsign}}","chaos":"{{chaos}}","format":"{{format}}","rounds":"{{rounds}}","world":"{{world}}"}` | saves `apiKey`, `rid`; returns `{apiKey, rid, world: {id}, state}` |
| state | GET | `/v1/state` | none | StateView |
| intent (decision) | POST | `/v1/act` | `{"arg":"{{arg}}","intent":"{{intent}}"}` | StateView |

Auth on every call after start: header `Authorization: Bearer {{apiKey}}`. The run is over when `status` equals `"finished"`. Win: `result.champion` = `true`; score: `result.rounds_survived` (rounds).

`intent` (one of legal_intents[].name): `auto`, `take_route`, `draft`, `block`, `patient`, `all_in`, `spiral`, `rush_checkpoint`, `steady_climb`, `knock_down`, `camp_fountain`, `hunt_star`, `rob`, `turntable_hold`, `go_region`, `hold_ground`, `hunt`, `take_shelf`, `bait`, `watch`. `arg` (the arg its arg_kind asks for: a rival id, region, route, side, shelf or star class) is optional.

Lobby options on `start`: `format` (choice: league | classic; default "league"), `chaos` (bool; default true), `rounds` (choice: full | final_only; default "full"). Up to 12 agents per world; the roster is `rivals`.

### From the gateway's route contract (internal-api.md §1, quoted)

#### Public (Byte contract) — v1.1 (W2c)

| Method | Path | Auth | Body | Returns |
|---|---|---|---|---|
| POST | `/v1/start` | none | `{world, callsign, role?, format?, chaos?, rounds?}` (`world` empty or unrendered = create a lobby) | `{apiKey, rid, world:{id}, state}` |
| POST | `/v1/act` | `Bearer apiKey` | players `{intent, arg?}` (`intent: "watch"` while spectating); caster `{action, arg?}` | StateView |
| GET | `/v1/state` | `Bearer apiKey` | — | StateView (side-effect free; **declared** in the Byte spec: Byte reads state every step, GS §4) |
| GET | `/v1/byte/spec.md?role=player\|caster` | none | — | the spec document we upload (generated; committed copies in `byte/`) |
| GET | `/v1/worlds` | none | — | `[{id, format, rounds, phase, beat, seats, max_agents}]` |
| GET | `/v1/watch/{world_id}` | none | WebSocket upgrade | `frames.md` |
| GET | `/replay/{world_id}` | none | — | §3 |

- Errors are HTTP 200 with `error` (a sentence); non-200 only for 401 (missing / bad / expired apiKey), 404 (a
  valid key for a world this gateway no longer has), 413 (body > 2 KB), 400/422 (malformed JSON). A finished run
  keeps answering.
- `arg` may be missing, `""`, the literal `"{{arg}}"`, or a number / bool (Byte keeps a whole-string placeholder's
  type, GS §3); words only (rival ids, region / route / side / shelf / star), never slot numbers.
- **Lobby:** the first `start` with an empty `world` opens a lobby (options `format`, `chaos`, `rounds`); joiners
  pass `{{world}}`; the lobby closes `ARENA_LOBBY_MS` after the first agent or at 12 agents; empty seats are filled
  by `ARENA_SEAT_FILL` (house agents). A `start` for a running or full world returns a **finished** run with a
  readable reason (Byte's `finish` matches; no hanging run).
- **Pacing per call (Byte's 400-call budget):** a player's `act` returns when the seat's **next decision** opens (or
  it is out / the match ended), at most 11 s; a refused intent returns at once (the agent may correct it); `watch`
  waits 10 s (or until the match ends); a caster's `act` returns at the next beat with decisions, refusals included.
- **Hold (`ARENA_BYTE_HOLD_BEATS`, default 1):** a Byte agent's intent is re-committed for that many decision beats
  while still valid (Q5).
- **Caster:** `start` with `role: caster` (the caster's own Byte game entry sends it). It attaches to the `world` it
  names, else to the newest lobby / running world (a separate Byte entry cannot pass our world id; [ASK BYTE] 3).
  Actions `call_highlight <highlights[].id>`, `focus <agent id>`, `predict_winner <agent id>`,
  `predict_next_out <agent id>`, `pass`. Predictions are shown only as `{kind, sealed: true}` until they resolve.
  Scoring: a correct winner call 10 + max(0, 40 − beat / 4); a correct next-out call 10. The run finishes when the
  match is settled on chain (or 120 s after DONE without a settle).
- `apiKey` = `<rid>.<world>.<exp>.<hmac>` (3 h), signed with `ARENA_TOKEN_SECRET`; the rid encodes the seat
  (`r-<hex>-s<slot>`, `r-<hex>-c` caster), so runs survive a gateway restart without stored secrets.
- Rate limits (doc 12 §2): **not yet** — a W2d+ item (Byte calls are bounded by its own budget; `/v1/start` and
  `/v1/watch` per-IP limits are the gap).

## 2. Intents and their args

`auto` (no arg) is legal in every round: the built-in strategy. A seat that sends nothing, or something refused, plays `auto` that beat. `legal_intents` in the StateView lists what is legal now with its `arg_kind`.

| Round mode | intent | arg_kind | Legal args | Code (rush-core) |
|---|---|---|---|---|
| race | `take_route` | route | `fast`, `safe`, `left`, `right` | 1 (arg: 0 fast, 1 safe, 2 left, 3 right) |
| race | `draft` | rival | a rival id from `rivals[].id` (alive, not you) | 2 (arg: rival slot) |
| race | `block` | rival | a rival id from `rivals[].id` (alive, not you) | 3 (arg: rival slot) |
| race | `patient` | none | (none; an arg is ignored) | 4 |
| race | `all_in` | none | (none; an arg is ignored) | 5 |
| survival | `spiral` | side | `left`, `right` | 10 (arg: 0 left, 1 right) |
| survival | `rush_checkpoint` | none | (none; an arg is ignored) | 11 |
| survival | `steady_climb` | none | (none; an arg is ignored) | 12 |
| survival | `knock_down` | rival | a rival id from `rivals[].id` (alive, not you) | 13 (arg: rival slot) |
| skill | `camp_fountain` | none | (none; an arg is ignored) | 20 |
| skill | `hunt_star` | star | `golden`, `nearest`, `far_side` | 21 (arg: 0 golden, 1 nearest, 2 far side) |
| skill | `rob` | rival | a rival id from `rivals[].id` (alive, not you) | 22 (arg: rival slot) |
| skill | `turntable_hold` | none | (none; an arg is ignored) | 23 |
| final | `go_region` | region | `N`, `NE`, `E`, `SE`, `S`, `SW`, `W`, `NW`, `CENTER` | 30 (arg: 0 N, 1 NE, 2 E, 3 SE, 4 S, 5 SW, 6 W, 7 NW, 8 CENTER) |
| final | `hold_ground` | none | (none; an arg is ignored) | 31 |
| final | `hunt` | rival | a rival id from `rivals[].id` (alive, not you) | 32 (arg: rival slot) |
| final | `take_shelf` | shelf | `upper`, `lower` | 33 (arg: 0 upper, 1 lower) |
| final | `bait` | rival | a rival id from `rivals[].id` (alive, not you) | 34 (arg: rival slot) |

Arg words match case-insensitively; a missing arg, `""` or the literal `"{{arg}}"` count as no arg; numbers and bools are read as text (never slot numbers).

### Refusals

A refused act comes back at once with HTTP 200 and the sentence in `error` (you may correct it within the beat). The parser's sentences (`{name}` = your intent, lists filled in):

- `unknown intent "{name}"; legal now: …`
- `{name} is not legal in this round; legal now: …`
- `{name} needs a rival id; alive rivals: …`
- `{name} needs one of: …`
- `{name} is not possible now; alive rivals: …`

## 3. StateView (PlayerView)

Returned by POST /v1/start (as `state`), POST /v1/act, GET /v1/state and the internal seat API. Facts, not answers (AR-10): no risk scores, no suggested moves. Whole-word names, stable types, `moves` only increases. Typical size <= 8 KB, hard limit 64 KB.

`phase`: lobby: waiting for players; decide: a beat is open; resolving: the beat closed and is being committed / played; plan: Final plan step; spectating: knocked out, still watching; ended: match over.

| Field | Type | Required | Notes |
|---|---|---|---|
| `view` | "player" | yes |  |
| `applied_to_beat` | integer \| null | yes | set when an act arrived after its beat closed and was applied to this later beat |
| `you` | object | yes |  |
| `rivals` | array of object (≤ 12) | yes |  |
| `round_facts` | object | yes | Mode-specific facts. At most the current mode's object is present. |
| `radio` | array of object (≤ 3) | yes |  |
| `plan` | object | yes |  |
| `plan.sealed` | boolean | yes |  |
| `plan.revealed` | string \| null | yes |  |
| `legal_intents` | array of object | yes |  |
| `result` | object | yes |  |
| `result.champion` | boolean | yes |  |
| `result.rounds_survived` | integer | yes |  |
| `result.place` | integer \| null | yes |  |
| `result.crown_vault` | string \| null | yes |  |
| `status` | "running" \| "finished" | yes |  |
| `phase` | "lobby" \| "decide" \| "resolving" \| "plan" \| "spectating" \| "ended" | yes | lobby: waiting for players; decide: a beat is open; resolving: the beat closed and is being committed / played; plan: Final plan step; spectating: knocked out, still watching; ended: match over. |
| `format` | "league" \| "classic" | yes |  |
| `rounds` | "full" \| "final_only" | yes |  |
| `round` | integer | yes |  |
| `round_name` | string | yes |  |
| `mode` | "none" \| "race" \| "survival" \| "skill" \| "final" | yes |  |
| `beat` | integer | yes |  |
| `moves` | integer | yes | monotonically increasing counter of resolved beats in the match |
| `deadline_s` | number \| null | yes |  |
| `onchain` | object | yes |  |
| `onchain.match` | string \| null | yes | the Match account (base58) once created |
| `onchain.beat` | object \| null | yes | the last beat sent to the chain |
| `onchain.last_tx` | string \| null | yes |  |
| `events` | array of string (≤ 20) | yes |  |
| `error` | string \| null | yes | a readable sentence when the last call was refused; HTTP status stays 200 |

### `you`

| Field | Type | Required | Notes |
|---|---|---|---|
| `you.id` | string | yes |  |
| `you.name` | string | yes |  |
| `you.kind` | "BYTE" \| "HOUSE" \| "BOT" \| "CASTER" | yes |  |
| `you.slot` | integer | yes |  |
| `you.alive` | boolean | yes |  |
| `you.qualified` | boolean | yes |  |
| `you.intent` | string \| null | yes | your intent in force (text form, e.g. "hunt house-bolt") |
| `you.height_m` | number |  | metres, rounded to 0.1 |
| `you.checkpoint` | integer |  |  |
| `you.falls` | integer |  |  |
| `you.hits` | integer |  |  |
| `you.stars` | integer |  |  |

### `rivals[]` (your own entry is included, `is_you: true`)

| Field | Type | Required | Notes |
|---|---|---|---|
| `rivals[].id` | string | yes |  |
| `rivals[].name` | string | yes |  |
| `rivals[].kind` | "BYTE" \| "HOUSE" \| "BOT" \| "CASTER" | yes |  |
| `rivals[].alive` | boolean | yes |  |
| `rivals[].out` | boolean | yes | out of the match (Byte roster `done`) |
| `rivals[].qualified` | boolean | yes |  |
| `rivals[].is_you` | boolean | yes | your own entry is listed too (Byte roster `self`) |
| `rivals[].rank` | integer | yes |  |
| `rivals[].score` | integer | yes |  |
| `rivals[].height_m` | number |  | metres, rounded to 0.1 |
| `rivals[].distance_m` | number |  | metres, rounded to 0.1 |
| `rivals[].intent_seen` | string \| null | yes | the rival's LAST RESOLVED intent; never the one being decided (AR-08) |

### `round_facts` (only the current mode's object)

Mode-specific facts. At most the current mode's object is present.

| Field | Type | Required | Notes |
|---|---|---|---|
| `round_facts.race` | object |  |  |
| `round_facts.race.next_checkpoint` | object |  |  |
| `round_facts.race.next_checkpoint.index` | integer | yes |  |
| `round_facts.race.next_checkpoint.distance_m` | number | yes | metres, rounded to 0.1 |
| `round_facts.race.routes` | array of object (≤ 4) |  | **Not set by the gateway today** (view.rs). |
| `round_facts.race.routes[].route` | "fast" \| "safe" \| "left" \| "right" | yes |  |
| `round_facts.race.routes[].length_m` | number | yes | metres, rounded to 0.1 |
| `round_facts.race.routes[].hazards` | integer | yes |  |
| `round_facts.race.hazards_ahead` | array of object (≤ 8) |  | **Not set by the gateway today** (view.rs). |
| `round_facts.race.hazards_ahead[].kind` | string | yes |  |
| `round_facts.race.hazards_ahead[].distance_m` | number | yes | metres, rounded to 0.1 |
| `round_facts.race.hazards_ahead[].clear_in_s` | number |  | seconds, rounded to 0.1 |
| `round_facts.survival` | object |  |  |
| `round_facts.survival.goo` | object |  |  |
| `round_facts.survival.goo.height_m` | number | yes | metres, rounded to 0.1 |
| `round_facts.survival.goo.rising_mps` | number | yes |  |
| `round_facts.survival.goo.reaches_you_in_s` | number |  | seconds, rounded to 0.1 |
| `round_facts.survival.floor` | integer |  |  |
| `round_facts.survival.next_checkpoint` | object |  |  |
| `round_facts.survival.next_checkpoint.index` | integer | yes |  |
| `round_facts.survival.next_checkpoint.distance_m` | number | yes | metres, rounded to 0.1 |
| `round_facts.survival.gaps_ahead` | array of object (≤ 6) |  | **Not set by the gateway today** (view.rs). |
| `round_facts.survival.gaps_ahead[].id` | string | yes |  |
| `round_facts.survival.gaps_ahead[].jump_m` | number | yes | metres, rounded to 0.1 |
| `round_facts.survival.gaps_ahead[].distance_m` | number |  | metres, rounded to 0.1 |
| `round_facts.skill` | object |  |  |
| `round_facts.skill.next_burst_in_s` | number |  | seconds, rounded to 0.1 |
| `round_facts.skill.time_left_s` | number |  | seconds, rounded to 0.1 |
| `round_facts.skill.stars` | array of object (≤ 24) |  |  |
| `round_facts.skill.stars[].class` | "normal" \| "golden" \| "dropped" | yes |  |
| `round_facts.skill.stars[].value` | integer | yes |  |
| `round_facts.skill.stars[].where` | "N" \| "NE" \| "E" \| "SE" \| "S" \| "SW" \| "W" \| "NW" \| "CENTER" | yes |  |
| `round_facts.skill.stars[].distance_m` | number |  | metres, rounded to 0.1 |
| `round_facts.skill.carriers` | array of string |  |  |
| `round_facts.final` | object |  |  |
| `round_facts.final.lit_now` | array of integer |  |  |
| `round_facts.final.lighting_next_beat` | array of integer |  |  |
| `round_facts.final.open` | array of integer |  |  |
| `round_facts.final.your_lid` | integer \| null |  | **Always null / empty today** (view.rs). |
| `round_facts.final.your_shelf` | "upper" \| "lower" \| null |  | **Always null / empty today** (view.rs). |
| `round_facts.final.sweeper_next_lids` | array of integer |  | **Always null / empty today** (view.rs). |
| `round_facts.final.ring_retires_in_beats` | integer \| null |  | **Always null / empty today** (view.rs). |

`next_checkpoint`: `index`, `distance_m`.

## 4. Examples (schema/examples)

`player-race.json`

```json
{
 "view": "player",
 "status": "running",
 "phase": "decide",
 "format": "league",
 "rounds": "full",
 "round": 1,
 "round_name": "Capsule Run (Race)",
 "mode": "race",
 "beat": 3,
 "moves": 3,
 "deadline_s": 10,
 "applied_to_beat": 3,
 "you": {
  "id": "house-prof",
  "name": "The Professor",
  "kind": "HOUSE",
  "slot": 0,
  "alive": true,
  "qualified": false,
  "intent": "auto",
  "checkpoint": 1,
  "falls": 0,
  "hits": 1
 },
 "round_facts": {
  "race": {
   "next_checkpoint": {
    "index": 2,
    "distance_m": 14.3
   },
   "routes": [
    {
     "route": "fast",
     "length_m": 18,
     "hazards": 3
    },
    {
     "route": "safe",
     "length_m": 23.5,
     "hazards": 1
    }
   ],
   "hazards_ahead": [
    {
     "kind": "swinging_bar",
     "distance_m": 6.1,
     "clear_in_s": 0.8
    }
   ]
  }
 },
 "rivals": [],
 "events": [],
 "radio": [],
 "plan": {
  "sealed": false,
  "revealed": null
 },
 "onchain": {
  "match": null,
  "beat": null,
  "last_tx": null
 },
 "legal_intents": [
  {
   "name": "auto",
   "arg_kind": "none"
  },
  {
   "name": "take_route",
   "arg_kind": "route"
  }
 ],
 "result": {
  "champion": false,
  "rounds_survived": 0,
  "place": null,
  "crown_vault": null
 },
 "error": "hunt is not legal in this round; legal now: auto, take_route, draft, block, patient, all_in"
}
```

`player-final.json`

```json
{
 "view": "player",
 "status": "running",
 "phase": "decide",
 "format": "league",
 "rounds": "full",
 "round": 4,
 "round_name": "Lid Flip (Final)",
 "mode": "final",
 "beat": 17,
 "moves": 61,
 "deadline_s": 8.7,
 "applied_to_beat": null,
 "you": {
  "id": "byte-7a1",
  "name": "Byte",
  "kind": "BYTE",
  "slot": 3,
  "alive": true,
  "qualified": false,
  "intent": "go_region NE",
  "height_m": 2,
  "falls": 1,
  "hits": 2
 },
 "round_facts": {
  "final": {
   "lit_now": [
    12,
    31
   ],
   "lighting_next_beat": [
    7
   ],
   "open": [
    40
   ],
   "your_lid": 22,
   "your_shelf": "upper",
   "sweeper_next_lids": [
    23,
    24
   ],
   "ring_retires_in_beats": 4
  }
 },
 "rivals": [
  {
   "id": "byte-7a1",
   "name": "Byte",
   "kind": "BYTE",
   "alive": true,
   "out": false,
   "qualified": false,
   "is_you": true,
   "rank": 2,
   "score": 0,
   "intent_seen": "go_region NE"
  },
  {
   "id": "house-bolt",
   "name": "Bolt the Bully",
   "kind": "HOUSE",
   "alive": true,
   "out": false,
   "qualified": false,
   "is_you": false,
   "rank": 1,
   "score": 0,
   "distance_m": 2.2,
   "intent_seen": "hunt byte-7a1"
  },
  {
   "id": "house-nell",
   "name": "Nervous Nell",
   "kind": "HOUSE",
   "alive": true,
   "out": false,
   "qualified": false,
   "is_you": false,
   "rank": 3,
   "score": 0,
   "distance_m": 6.4,
   "intent_seen": "hold_ground"
  }
 ],
 "events": [
  "bumped_by: house-bolt",
  "near_miss: byte-7a1"
 ],
 "radio": [
  {
   "from": "house-bolt",
   "text": "Going down, Byte."
  }
 ],
 "plan": {
  "sealed": true,
  "revealed": "hunter:NE:house-bolt"
 },
 "onchain": {
  "match": "9fQe1bXb6s7h2vTqkq5q1Q9dqTn6bLwKz8u3WmZtYp2D",
  "beat": {
   "beat": 16,
   "committed": true,
   "revealed": true,
   "advanced": true,
   "verified": true
  },
  "last_tx": "5KxZ9rjQe8yYw1mH3n4p5q6r7s8t9u1v2w3x4y5z6a7b8c9d"
 },
 "legal_intents": [
  {
   "name": "auto",
   "arg_kind": "none"
  },
  {
   "name": "go_region",
   "arg_kind": "region"
  },
  {
   "name": "hold_ground",
   "arg_kind": "none"
  },
  {
   "name": "hunt",
   "arg_kind": "rival"
  },
  {
   "name": "take_shelf",
   "arg_kind": "shelf"
  },
  {
   "name": "bait",
   "arg_kind": "rival"
  }
 ],
 "result": {
  "champion": false,
  "rounds_survived": 3,
  "place": null,
  "crown_vault": null
 },
 "error": null
}
```
