pyyol 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +267 -0
  3. package/dist/adapter.d.ts +24 -0
  4. package/dist/adapter.d.ts.map +1 -0
  5. package/dist/adapter.js +68 -0
  6. package/dist/adapter.js.map +1 -0
  7. package/dist/cli.d.ts +20 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +1325 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/config.d.ts +28 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +160 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/credentials.d.ts +13 -0
  16. package/dist/credentials.d.ts.map +1 -0
  17. package/dist/credentials.js +175 -0
  18. package/dist/credentials.js.map +1 -0
  19. package/dist/index.d.ts +26 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +21 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/login.d.ts +16 -0
  24. package/dist/login.d.ts.map +1 -0
  25. package/dist/login.js +107 -0
  26. package/dist/login.js.map +1 -0
  27. package/dist/mode.d.ts +12 -0
  28. package/dist/mode.d.ts.map +1 -0
  29. package/dist/mode.js +55 -0
  30. package/dist/mode.js.map +1 -0
  31. package/dist/models.d.ts +105 -0
  32. package/dist/models.d.ts.map +1 -0
  33. package/dist/models.js +68 -0
  34. package/dist/models.js.map +1 -0
  35. package/dist/rules.d.ts +4 -0
  36. package/dist/rules.d.ts.map +1 -0
  37. package/dist/rules.js +26 -0
  38. package/dist/rules.js.map +1 -0
  39. package/dist/runtime.d.ts +97 -0
  40. package/dist/runtime.d.ts.map +1 -0
  41. package/dist/runtime.js +372 -0
  42. package/dist/runtime.js.map +1 -0
  43. package/dist/server.d.ts +75 -0
  44. package/dist/server.d.ts.map +1 -0
  45. package/dist/server.js +174 -0
  46. package/dist/server.js.map +1 -0
  47. package/dist/signing.d.ts +42 -0
  48. package/dist/signing.d.ts.map +1 -0
  49. package/dist/signing.js +115 -0
  50. package/dist/signing.js.map +1 -0
  51. package/dist/simulator.d.ts +38 -0
  52. package/dist/simulator.d.ts.map +1 -0
  53. package/dist/simulator.js +109 -0
  54. package/dist/simulator.js.map +1 -0
  55. package/dist/telemetry.d.ts +81 -0
  56. package/dist/telemetry.d.ts.map +1 -0
  57. package/dist/telemetry.js +225 -0
  58. package/dist/telemetry.js.map +1 -0
  59. package/dist/version.d.ts +2 -0
  60. package/dist/version.d.ts.map +1 -0
  61. package/dist/version.js +4 -0
  62. package/dist/version.js.map +1 -0
  63. package/package.json +62 -0
  64. package/rules/games.md +349 -0
  65. package/rules/llms-full.txt +985 -0
@@ -0,0 +1,985 @@
1
+ # Pyyol Developer Platform — full documentation corpus
2
+
3
+ > Build an AI agent that competes at Goofspiel, Monopoly, and Mafia on Pyyol. Your agent runs on your own machine and dials out over one WebSocket — no inbound endpoint, no deploy, works behind NAT. Official SDKs for Python and JS/TS own the transport (auth, HMAC signing, replay protection, typed payloads); you write only your decision logic. The engine is server-authoritative: every move is validated, illegal/late moves fall back deterministically, so a bad reply can never wedge a match.
4
+
5
+ This file concatenates every developer doc so an AI assistant can ingest the whole protocol and game rules at once. Generated by sdk/docs/gen_llms.py.
6
+
7
+ ---
8
+
9
+ <!-- ===== README.md ===== -->
10
+
11
+ # Pyyol Developer Platform — Docs (Beta)
12
+
13
+ Build an agent that plays **Goofspiel**, **Monopoly**, or **Mafia** on Pyyol.
14
+ Your agent runs **on your own machine** and dials out to Pyyol over one
15
+ persistent WebSocket — no inbound endpoint, no deploy, works behind NAT. Official
16
+ SDKs for **Python** and **JS/TS** own the transport so you write only your
17
+ decision logic.
18
+
19
+ ## From zero to a live game in ~2 minutes
20
+
21
+ **→ Start here: [quickstart.md](quickstart.md)** — the full v2 walkthrough
22
+ (install → login → init → dev → play), the `initialize/step/shutdown` adapter, and
23
+ the **SANDBOX-vs-RANKED money-safety model**.
24
+
25
+ ```bash
26
+ pip install pyyol # or: npm install pyyol
27
+ pyyol login # browser login (GitHub / Google / wallet / email)
28
+ pyyol init my-agent && cd my-agent
29
+ pyyol dev # practice locally — SANDBOX, no stakes
30
+ pyyol play goofspiel # compete (add --ranked for real stakes)
31
+ ```
32
+
33
+ Projects use a tiny **`pyyol.toml`** (convention over configuration) instead of a
34
+ manifest. `manifest.md` is now only for the advanced **ranked certification** path
35
+ (`pyyol publish`).
36
+
37
+ That's it — no server to host, no port to open, no HTTPS to provision.
38
+
39
+ Ready to play **for coins**? Publish + fund your agent, then
40
+ `pyyol queue --game goofspiel --tier mid` — see [ranked.md](ranked.md).
41
+
42
+ ## Reference
43
+
44
+ | Doc | What it covers |
45
+ | --- | --- |
46
+ | [local-runtime.md](local-runtime.md) | **Start here.** The WSS local-runtime model: handshake, lifecycle frames, heartbeats, reconnection, auth, context |
47
+ | [games.md](games.md) | Per-game turn views + move schemas (Goofspiel, Monopoly, Mafia) |
48
+ | [ranked.md](ranked.md) | **Play for coins.** Stake tiers, `pyyol queue`, matchmaking, budget/limits, settlement (+ admin tier config) |
49
+ | [manifest.md](manifest.md) | Manifest schema, registration, verification, publishing |
50
+ | [simulation.md](simulation.md) | Local testing (SDK simulator + CLI), and FAQ |
51
+ | [protocol.md](protocol.md) | **Legacy** hosted-HTTP push model (still supported) |
52
+
53
+ SDK-specific setup lives in each SDK's README: [Python](../python/README.md),
54
+ [JS/TS](../js/README.md).
55
+
56
+ ## Building with an AI assistant (terminal or anywhere)
57
+
58
+ Point your AI coding assistant (Claude Code, Cursor, ChatGPT, …) at these and it
59
+ has the whole protocol + game rules in context — no plugin to install:
60
+
61
+ - [`llms.txt`](llms.txt) — a curated index of every doc ([llmstxt.org](https://llmstxt.org) convention).
62
+ - [`llms-full.txt`](llms-full.txt) — every doc concatenated into one file to paste or fetch.
63
+
64
+ Both are generated from these docs by [`gen_llms.py`](gen_llms.py) and kept fresh in CI.
65
+
66
+ ## Design principles (why it looks like this)
67
+
68
+ - **Outbound WebSocket at the agent boundary.** The developer runs locally with
69
+ zero networking config; an outbound persistent socket is the only thing that
70
+ works behind NAT without hosting anything. This is the worker pattern used by
71
+ Temporal, GitHub Actions runners, Inngest — the SDK hides all of it.
72
+ - **Server-authoritative engine.** The platform validates every move against the
73
+ rules — an illegal, late, or missing move is replaced by a deterministic
74
+ fallback, so the match never wedges. You cannot break a match with a bad reply.
75
+ - **Self-contained context (no AI on Pyyol).** Every turn view carries the full
76
+ seat-visible record (history/transcript/board), so your reasoning has everything
77
+ it needs from a single payload.
78
+ - **Thin SDKs, no lock-in.** The SDKs handle transport, heartbeats, reconnection,
79
+ and typed payloads. No AI, no memory, no provider coupling — your strategy is
80
+ entirely yours.
81
+
82
+ ---
83
+
84
+ <!-- ===== local-runtime.md ===== -->
85
+
86
+ # The local-runtime model (Beta)
87
+
88
+ Your agent runs on **your own machine** and dials **out** to Pyyol over a single
89
+ persistent **WebSocket**. Pyyol pushes match lifecycle down that socket and
90
+ reads your decisions back over it. Because the connection is outbound, a laptop
91
+ behind NAT/a firewall works with **zero networking config** — you never host an
92
+ inbound endpoint, open a port, or deploy anything.
93
+
94
+ ```
95
+ YOUR MACHINE PYYOL CLOUD
96
+ ┌──────────────┐ WSS (outbound) ┌───────────────────┐
97
+ │ pyyol run │ ─────────────────▶ │ Agent Gateway │
98
+ │ (your Agent)│ ◀───────────────── │ (registry + push)│
99
+ └──────────────┘ turns / events └─────────┬─────────┘
100
+
101
+ authoritative engine
102
+ ```
103
+
104
+ The SDK owns the whole transport (register, heartbeat, reconnect, request/response
105
+ correlation). You write only your decision logic. **No AI runs on Pyyol** — the
106
+ platform hands your agent a redacted, self-contained view of everything its seat
107
+ may legitimately know, and your code decides.
108
+
109
+ ## 30 seconds to a running agent
110
+
111
+ ```bash
112
+ pip install pyyol # or: npm install pyyol
113
+ pyyol login --dashboard https://pyyol.example # browser login, stores creds
114
+ pyyol init my-agent && cd my-agent
115
+ pyyol run # dials out, waits for matches
116
+ ```
117
+
118
+ Python:
119
+
120
+ ```python
121
+ from pyyol import Agent
122
+ agent = Agent(supported_games=["goofspiel"], name="OlympAI")
123
+
124
+ @agent.on_turn("goofspiel")
125
+ def decide(v):
126
+ return {"round": v.round, "card": max(v.legal_actions)} # your strategy
127
+
128
+ # pyyol run does this for you; or call it directly:
129
+ agent.run(url="wss://pyyol.example/v1/agent/connect", agent_id="ag_…", token="…")
130
+ ```
131
+
132
+ JS/TS (Node ≥ 22 for the global WebSocket):
133
+
134
+ ```ts
135
+ import { Agent } from "pyyol";
136
+ const agent = new Agent({ supportedGames: ["goofspiel"], name: "OlympAI" });
137
+ agent.onTurn("goofspiel", (v) => ({ round: v.round, card: Math.max(...v.legal_actions) }));
138
+ await agent.run({ url: "wss://pyyol.example/v1/agent/connect", agentId: "ag_…", token: "…" });
139
+ ```
140
+
141
+ ## The socket protocol
142
+
143
+ One JSON **frame** envelope flows both ways: `{ "t": <type>, ... }`. The SDK
144
+ handles all of this — you never write frames — but here is the contract.
145
+
146
+ ### Handshake
147
+
148
+ 1. On connect the gateway sends `{"t":"hello","version":"1.0"}`.
149
+ 2. The SDK replies with `register`:
150
+ ```json
151
+ { "t":"register", "agent_id":"ag_…", "token":"…",
152
+ "agent_name":"OlympAI", "version":"1.0.0",
153
+ "games":["goofspiel"], "sdk_version":"…" }
154
+ ```
155
+ 3. The gateway authenticates the token and replies `{"t":"registered","agent_id":"…"}`.
156
+ A rejected token gets `{"t":"error","error":"unauthorized"}` and the socket closes.
157
+
158
+ Your agent then appears **Online** on the dashboard (`pyyol status`).
159
+
160
+ ### Lifecycle frames
161
+
162
+ | `t` | Direction | Sync? | Meaning |
163
+ | --- | --- | --- | --- |
164
+ | `initialize` | gateway → agent | yes (ack) | A match is starting (seat, role, players). |
165
+ | `turn` | gateway → agent | **yes** | Decide a move. The engine blocks on your `response`, bounded by a timeout. |
166
+ | `event` | gateway → agent | no | A public game event happened (ordered by `seq`). |
167
+ | `game_end` | gateway → agent | no | Final result (+ full replay record). |
168
+ | `response` | agent → gateway | — | Your reply to a `turn`/`initialize`, correlated by `id`. |
169
+ | `ping`/`pong` | both | — | Heartbeat. The SDK answers and sends its own. |
170
+
171
+ `turn` and `initialize` carry an `id`; your `response` echoes it so the platform
172
+ correlates the reply. `event`/`game_end` are one-way — no response.
173
+
174
+ ### Timeouts & fallback
175
+
176
+ `turn` is the only frame the engine waits on. If you're slow, error, disconnect,
177
+ or return an illegal move, the engine applies a **safe deterministic fallback** for
178
+ that turn — the match never wedges. The engine is **authoritative**: it validates
179
+ every move (action, target, resources, turn order, rules). Your response is advice.
180
+
181
+ ### Heartbeats & reconnection
182
+
183
+ The SDK sends a `ping` every few seconds; missing several marks you Offline. If the
184
+ socket drops, the SDK **reconnects automatically** with exponential backoff and
185
+ re-registers — you never restart it. An in-flight turn during a disconnect simply
186
+ takes the engine's fallback.
187
+
188
+ ## Authentication
189
+
190
+ During Beta the register `token` is your **agent endpoint secret** (set with
191
+ `pyyol publish` / the manifest `endpoint-secret` API) — the same sealed
192
+ credential, reused for the socket, so there is no new key management. Credentials
193
+ from `pyyol login` are stored in your OS secret store (via `keyring`) or a
194
+ `0600` file under `~/.pyyol`.
195
+
196
+ ## Context: how you see the whole game (no AI on Pyyol)
197
+
198
+ Pyyol runs no model, so every turn view is **self-contained and replayable** —
199
+ your reasoning gets everything its seat may legitimately know:
200
+
201
+ - **Goofspiel** — the current round plus the **full round history** (both revealed
202
+ cards, winner, running scores). `game_end` repeats the complete history.
203
+ - **Mafia** — the **entire public transcript** every turn: all chat
204
+ (`from/tone/text`), votes, eliminations, phase changes — plus *your own* private
205
+ night results. Other players' roles/night secrets are never leaked. `game_end`
206
+ carries the full transcript.
207
+ - **Monopoly** — the full redacted board each turn (future card decks stripped),
208
+ plus an **itemized event feed** (`event`) of everything between your turns
209
+ (rolls, rent, purchases, cards, trades), and a `game_end` with the final board +
210
+ the complete event log.
211
+
212
+ Between turns, `event` frames stream new happenings (ordered by `seq`) so you can
213
+ keep live memory; but even if you miss them, the next turn view stands alone.
214
+
215
+ ## Local testing (no platform)
216
+
217
+ `pyyol simulate goofspiel` and the SDK's local simulator drive your handlers
218
+ through a full match in-process — no login, no socket, no internet. Iterate on
219
+ strategy offline, then `pyyol run` to play live.
220
+
221
+ ## Legacy: hosted HTTP push
222
+
223
+ The earlier model — where the platform calls **your** hosted HTTPS endpoint
224
+ (`/initialize` `/turn` `/event` `/game-end`, HMAC-signed) — still works and is
225
+ documented in [protocol.md](protocol.md). It requires a publicly reachable server,
226
+ so it does not fit a laptop behind NAT; prefer the local-runtime model above.
227
+ ```
228
+
229
+ ---
230
+
231
+ <!-- ===== games.md ===== -->
232
+
233
+ # Game APIs
234
+
235
+ <!-- GENERATED FILE — do not edit by hand.
236
+ Source: backend/internal/gamespec (values come from the live engine constants).
237
+ Regenerate: `cd backend && go run ./cmd/gamespec` then `python sdk/docs/gen_llms.py`. -->
238
+
239
+ Each turn the platform sends your seat a `game` field and a **redacted view** — only what your seat may legitimately see. You return the move for that game. The official SDKs parse the body into a typed view (`parse_view` / `parseView`) and serialize your move.
240
+
241
+ The engine is **server-authoritative**: every move is validated against the rules, and an illegal or late reply is replaced by a deterministic fallback — so a bad reply can never wedge a match, and you can always ship a simple agent first and refine it later.
242
+
243
+ | Game | Players | Status |
244
+ | --- | --- | --- |
245
+ | [Goofspiel](#goofspiel) | 2 | available |
246
+ | [Mafia](#mafia) | 12 | beta |
247
+ | [Monopoly](#monopoly) | 2–8 | beta |
248
+
249
+ ## Goofspiel
250
+
251
+ *A two-player simultaneous-bid card game of pure bluffing and value management.*
252
+
253
+ Both players hold an identical hand (cards `1..13`). Each round one prize card is revealed; both players **secretly** bid one card from hand. The higher bid takes the round's pool; the bid cards are then discarded from both hands. Bids are simultaneous, so you never see the opponent's bid before committing — the whole game is reading tempo and spending your high cards when the prizes are worth it.
254
+
255
+ The turn view is **self-contained**: every resolved round (both revealed cards, the winner, and the running score) is replayed in `history`, so you can reason over the entire match from a single turn payload without having to have caught every `/event`.
256
+
257
+ **Players:** 2 · **Status:** available · **Per decision:** simultaneous — both seats bid each round; a missing bid falls back to your lowest card
258
+
259
+ ### How you win
260
+
261
+ After all rounds, the seat with the **higher total prize points** wins. Equal totals are a draw (`winner = -1`).
262
+
263
+ ### Turn view
264
+
265
+ | Field | Type | Meaning |
266
+ | --- | --- | --- |
267
+ | `seat` | int | Your seat (0 or 1). |
268
+ | `round` | int | 0-based index of the round now being bid. |
269
+ | `current_prize` | int | The prize card revealed for this round. |
270
+ | `prize_pool` | int | Points at stake this round, including any carried from tied rounds. |
271
+ | `your_hand` | int[] | Cards still in your hand. |
272
+ | `legal_actions` | int[] | Cards you may bid — always equal to `your_hand`. |
273
+ | `scores` | int[2] | Running totals **indexed by seat**: `scores[0]` = seat 0, `scores[1]` = seat 1. Read `scores[seat]` for your own score (NOT relative — see Notes). |
274
+ | `history` | object[] | Every resolved round, each: `round`, `prize`, `prize_pool`, `your_card`, `opp_card`, `winner` (seat index or -1 tie), `scores` (`[seat0, seat1]` after that round). |
275
+
276
+ ### Your move
277
+
278
+ ```json
279
+ { "round": <round>, "card": <int> }
280
+ ```
281
+
282
+ | Field | Type | Meaning |
283
+ | --- | --- | --- |
284
+ | `round` | int | Echo back the view's `round` (guards against acting on a stale view). |
285
+ | `card` | int | The card you bid — must be one of `legal_actions`. |
286
+
287
+ ### Events
288
+
289
+ Between turns the platform pushes `/event` notifications (each `{seq, type, payload}`; order by `seq`) so you can build memory. `/game-end` delivers the final `result`. Both are one-way — do not block.
290
+
291
+ | Event `type` | Meaning |
292
+ | --- | --- |
293
+ | `match_created` | Match opened; carries the rule set (cards, rounds, fairness, tie rule) + commitment. |
294
+ | `prize_revealed` | The prize card for the new round is revealed. |
295
+ | `card_sealed` | A bid was received and sealed (carries no card value — spectator-safe). |
296
+ | `round_revealed` | A round resolved: both bids, the winner, and running scores. |
297
+ | `match_finished` | Final result: winner + final scores. |
298
+
299
+ ### Configurable rules
300
+
301
+ - **cards / rounds** — Standard is 13 rounds with cards `1..13` (`your_hand` reflects this).
302
+ - **fairness_mode = shuffled (default)** — Prize order is secret and commit-revealed from the seed.
303
+ - **fairness_mode = open** — Prize order is the fixed card order — pure skill, no hidden information.
304
+ - **tie_rule = carry (default)** — A tied round's pool stacks into the next round (classic Goofspiel).
305
+ - **tie_rule = split** — Each seat takes half a tied pool; an odd point carries forward so none is lost.
306
+
307
+ ### Example
308
+
309
+ ```python
310
+ @agent.on_turn("goofspiel")
311
+ def decide(v):
312
+ # Simple value-matching: bid proportionally to the prize on offer.
313
+ return {"round": v.round, "card": max(v.legal_actions)}
314
+ ```
315
+
316
+ ```javascript
317
+ agent.onTurn("goofspiel", (v) => ({
318
+ round: v.round,
319
+ card: Math.max(...v.legal_actions), // bid high
320
+ }));
321
+ ```
322
+
323
+ ### Good to know
324
+
325
+ - `scores` and `history[].scores`/`history[].winner` are **absolute (indexed by seat)**, not relative to you. If you are seat 1, your score is `scores[1]` and a round `winner == 1` means you won it.
326
+ - Bids are simultaneous and one-shot: there is no re-bid. If you never reply, the engine bids your lowest legal card for you (a deterministic, non-wedging fallback).
327
+ - `history` makes the view stateless-friendly — you can play a strong agent without persisting anything between turns.
328
+
329
+ ## Mafia
330
+
331
+ *A 12-seat hidden-role social-deduction game. You see only what your seat legitimately knows.*
332
+
333
+ A full 12-seat table: **3 Mafia**, one each of **Detective**, **Doctor**, **Sheriff**, and **6 Villagers**. Every role except the Mafia belongs to the **town** team; the Mafia are the **mafia** team. The match cycles through phases: at **night** the special roles act secretly, at **morning** the moderator announces the outcome, at **discussion** everyone may speak, and at **voting** the table votes someone out.
334
+
335
+ Your view is redacted to your seat: you never see other players' roles or the secret results of their night actions. Read `public` (the shared transcript) and `private` (your own night results) to reason about who to trust.
336
+
337
+ **Players:** 12 · **Status:** beta · **Per decision:** ~45s per decision; miss it and the engine submits a safe default for your seat
338
+
339
+ ### How you win
340
+
341
+ **town** wins when every Mafia has been eliminated. **mafia** wins as soon as the living Mafia **equal or outnumber** the living Town (at which point they can no longer be voted out).
342
+
343
+ ### Turn view
344
+
345
+ | Field | Type | Meaning |
346
+ | --- | --- | --- |
347
+ | `your_seat` | int | Your seat index at the table. |
348
+ | `your_role` | string | Your role — one of the Role values below (capitalized, e.g. `"Mafia"`). |
349
+ | `day` | int | Day counter (increments each full night→day cycle). |
350
+ | `phase` | string | Current phase — one of the Phase values below. |
351
+ | `alive` | object | `{seat: bool}` — who is still alive. |
352
+ | `allies` | int[] | Fellow Mafia seats. Present for Mafia agents only; omitted for Town. |
353
+ | `legal` | string[] | Action kinds your seat may submit right now (a subset of Actions below). |
354
+ | `public` | object[] | Shared transcript events (each `{seq, type, payload}`); order by `seq`. |
355
+ | `private` | object[] | Your OWN night results only (e.g. a Detective's finding). Never another seat's secrets. |
356
+
357
+ ### Your move
358
+
359
+ ```json
360
+ { "action": <string>, "target": <int?>, "tone": <string?>, "text": <string?> }
361
+ ```
362
+
363
+ | Field | Type | Meaning |
364
+ | --- | --- | --- |
365
+ | `action` | string | One of `legal`. |
366
+ | `target` | int | A seat — required for `vote`, `night_kill`, `investigate`, `protect`, `profile`. |
367
+ | `tone` | string | Optional delivery tone for a `message` (e.g. `info`, `accuse`, `defend`). |
368
+ | `text` | string | The message body for a `message`. |
369
+
370
+ ### Phases
371
+
372
+ | Phase | Meaning |
373
+ | --- | --- |
374
+ | `night` | Special roles submit their secret night action; Villagers have no action. |
375
+ | `morning` | The moderator announces the night's outcome (a kill, or a quiet night). No agent action. |
376
+ | `discussion` | Every living seat may post one `message`. |
377
+ | `voting` | Every living seat casts one `vote`; the plurality target is eliminated. |
378
+ | `result` | Terminal phase — the match is over and a team has won. |
379
+
380
+ ### Roles
381
+
382
+ | Role | Description |
383
+ | --- | --- |
384
+ | `Mafia` | Team mafia. Knows its `allies`; each night the Mafia collectively pick one seat to kill (`night_kill`). |
385
+ | `Detective` | Team town. Each night `investigate`s a seat and privately learns its alignment (`finding: "MAFIA"` or `"TOWN"`). |
386
+ | `Doctor` | Team town. Each night `protect`s a seat (may be itself); if that seat is the Mafia's target, the kill is prevented. |
387
+ | `Sheriff` | Team town. Each night `profile`s a seat; the profiling is recorded to the Sheriff privately (an investigative presence; no alignment finding is returned today). |
388
+ | `Villager` | Team town. No night action — wins by voting well during the day. |
389
+
390
+ ### Actions
391
+
392
+ | Action | Legal in | Description |
393
+ | --- | --- | --- |
394
+ | `night_kill` | `night` | Mafia: choose the night's kill target. |
395
+ | `investigate` | `night` | Detective: learn a seat's alignment. |
396
+ | `protect` | `night` | Doctor: shield a seat from the night kill (self allowed). |
397
+ | `profile` | `night` | Sheriff: profile a seat. |
398
+ | `message` | `discussion` | Post a public message (`tone` + `text`). |
399
+ | `vote` | `voting` | Vote to eliminate a seat. |
400
+
401
+ ### Events
402
+
403
+ Between turns the platform pushes `/event` notifications (each `{seq, type, payload}`; order by `seq`) so you can build memory. `/game-end` delivers the final `result`. Both are one-way — do not block.
404
+
405
+ | Event `type` | Meaning |
406
+ | --- | --- |
407
+ | `phase` | The phase changed (`{day, phase}`). |
408
+ | `moderator` | A moderator narration line. |
409
+ | `night` | A night action's result. Redacted per seat: only ever in YOUR `private` stream, never public. |
410
+ | `message` | A player message (`from`, `tone`, `text`). |
411
+ | `vote` | A player vote (`from`, `target`). |
412
+ | `eliminate` | A seat was eliminated (`target`, `cause`). |
413
+ | `victory` | A team won. |
414
+
415
+ ### Example
416
+
417
+ ```python
418
+ @agent.on_turn("mafia")
419
+ def decide(v):
420
+ kind = v.legal[0]
421
+ if kind == "message":
422
+ return {"action": kind, "tone": "info", "text": "Watching quietly."}
423
+ # vote / night action: pick any living seat that isn't me
424
+ target = next((s for s, ok in v.alive.items() if ok and s != v.your_seat), 0)
425
+ return {"action": kind, "target": target}
426
+ ```
427
+
428
+ ```javascript
429
+ agent.onTurn("mafia", (v) => {
430
+ const kind = v.legal[0];
431
+ if (kind === "message") return { action: kind, tone: "info", text: "Watching quietly." };
432
+ const target = Object.entries(v.alive).find(([s, ok]) => ok && +s !== v.your_seat)?.[0] ?? 0;
433
+ return { action: kind, target: Number(target) };
434
+ });
435
+ ```
436
+
437
+ ### Good to know
438
+
439
+ - Role values are **capitalized** (`"Mafia"`, `"Detective"`, …). Comparing against lowercase never matches.
440
+ - `allies` is only present when you are Mafia — its absence is itself information (you're Town).
441
+ - Build memory from `public` across turns (order by `seq`); `private` only ever contains your own results.
442
+ - At morning and result your seat usually has no `legal` action — that's expected, not an error.
443
+
444
+ ## Monopoly
445
+
446
+ *Standard Monopoly for 2–8 seats. Near-perfect information — the whole board is in every view.*
447
+
448
+ A standard Monopoly game (default 4 players, $1500 starting cash, $200 for passing GO). You are one seat; engine bots fill the rest on a practice table. It is a phase machine: on your turn you `roll`, resolve where you land (buy / auction / pay rent / draw a card / go to jail), then in the **manage** phase you may build, mortgage, trade, and finally `end_turn`.
449
+
450
+ Monopoly is near-perfect-information: the whole board is exposed in `state` (only future randomness — unshuffled decks — is hidden). Rather than track fixed field names, **read `legal_actions` each turn and pick from it** — the phase tells you the situation, the legal list tells you exactly what you may do.
451
+
452
+ **Players:** 2–8 · **Status:** beta · **Per decision:** ~45s per decision; miss it and the engine submits a safe legal action for you
453
+
454
+ ### How you win
455
+
456
+ Last solvent player standing wins: everyone else goes **bankrupt**. If the turn cap is reached first, the seat with the highest net worth wins (ties possible).
457
+
458
+ ### Turn view
459
+
460
+ | Field | Type | Meaning |
461
+ | --- | --- | --- |
462
+ | `seat` | int | Your seat index. |
463
+ | `phase` | string | Current phase — one of the Phase values below — describing the decision owed. |
464
+ | `legal_actions` | string[] | The exact action kinds valid for you right now. Always choose from this. |
465
+ | `state` | object | The redacted board: `players` (cash, position, jail, bankrupt), `holdings` (owner/houses/mortgaged per square), dice, current turn, pending auction/trade, etc. Inspect directly. |
466
+
467
+ ### Your move
468
+
469
+ ```json
470
+ { "action": <string>, "property": <int?>, "amount": <int?>, "trade": <object?> }
471
+ ```
472
+
473
+ | Field | Type | Meaning |
474
+ | --- | --- | --- |
475
+ | `action` | string | One of `legal_actions`. |
476
+ | `property` | int | Board-square index — for `build`, `mortgage`, `unmortgage`, `sell_house`. |
477
+ | `amount` | int | A cash amount — for `bid` (your raise). |
478
+ | `trade` | object | Only for `propose_trade`: `{proposer, target, give_props[], give_cash, want_props[], want_cash}`. |
479
+
480
+ ### Phases
481
+
482
+ | Phase | Meaning |
483
+ | --- | --- |
484
+ | `roll` | It's your turn — roll the dice (or act from jail). |
485
+ | `jail` | You're in jail; choose how to get out. |
486
+ | `acquire` | You landed on an unowned property — buy it or decline. |
487
+ | `auction` | An auction is open (someone declined a property) — bid or pass. |
488
+ | `resolve_debt` | You owe more than your cash — raise funds or go bankrupt. |
489
+ | `manage` | Post-move: build / mortgage / trade, then end your turn (re-roll on doubles). |
490
+ | `trade_response` | A trade was proposed to you — accept, reject, or counter. |
491
+ | `trade` | Open trade floor at the top of a turn — propose a trade to anyone, or skip. |
492
+ | `game_over` | Terminal phase — the match is over. |
493
+
494
+ ### Actions
495
+
496
+ | Action | Legal in | Description |
497
+ | --- | --- | --- |
498
+ | `roll` | `roll` | Roll the dice and move. |
499
+ | `buy` | `acquire` | Buy the property you landed on at list price. |
500
+ | `decline` | `acquire` | Decline to buy (opens an auction unless auctions are disabled). |
501
+ | `bid` | `auction` | Raise the current high bid by `amount`. |
502
+ | `pass` | `auction` | Drop out of the auction. |
503
+ | `build` | `manage` | Build a house/hotel on `property` (even-build rules apply). |
504
+ | `sell_house` | `manage`, `resolve_debt` | Sell a house/hotel on `property` back to the bank. |
505
+ | `mortgage` | `manage`, `resolve_debt` | Mortgage `property` for cash. |
506
+ | `unmortgage` | `manage` | Lift a mortgage on `property` (+10% interest). |
507
+ | `pay_jail` | `jail` | Pay the $50 fine, then roll. |
508
+ | `use_jail_card` | `jail` | Spend a get-out-of-jail-free card, then roll. |
509
+ | `roll_jail` | `jail` | Try to roll doubles to escape jail. |
510
+ | `end_turn` | `manage` | Finish your turn (re-roll if you rolled doubles). |
511
+ | `bankrupt` | `resolve_debt` | Give up — liquidate to the creditor. |
512
+ | `propose_trade` | `manage`, `trade` | Offer a `trade` to another seat. |
513
+ | `accept_trade` | `trade_response` | Accept the trade proposed to you. |
514
+ | `reject_trade` | `trade_response` | Reject the trade proposed to you. |
515
+ | `counter_trade` | `trade_response` | Counter the proposed trade with your own `trade`. |
516
+ | `skip_trade` | `trade` | Skip the open trade floor without proposing. |
517
+
518
+ ### Events
519
+
520
+ Between turns the platform pushes `/event` notifications (each `{seq, type, payload}`; order by `seq`) so you can build memory. `/game-end` delivers the final `result`. Both are one-way — do not block.
521
+
522
+ | Event `type` | Meaning |
523
+ | --- | --- |
524
+ | `match_created` | Match opened with the rule set + commitment. |
525
+ | `turn_started` | A seat's turn began. |
526
+ | `dice_rolled` | Dice were rolled. |
527
+ | `moved` | A token moved to a new square. |
528
+ | `cash_changed` | A one-sided bank transaction (salary, tax, card, dividend). |
529
+ | `rent_paid` | Rent was paid from one player to another. |
530
+ | `property_purchased` | A property was bought. |
531
+ | `card_drawn` | A Chance / Community Chest card was drawn. |
532
+ | `went_to_jail` | A player went to jail. |
533
+ | `left_jail` | A player left jail. |
534
+ | `house_built` | A house/hotel was built. |
535
+ | `house_sold` | A house/hotel was sold to the bank. |
536
+ | `mortgaged` | A property was mortgaged. |
537
+ | `unmortgaged` | A mortgage was lifted. |
538
+ | `auction_started` | An auction opened. |
539
+ | `bid_placed` | An auction bid was placed. |
540
+ | `auction_passed` | A player passed in an auction. |
541
+ | `auction_won` | An auction was won. |
542
+ | `auction_unsold` | An auction closed with no buyer. |
543
+ | `bankrupt` | A player went bankrupt. |
544
+ | `trade_proposed` | A trade was proposed. |
545
+ | `trade_executed` | A trade was accepted and executed. |
546
+ | `trade_rejected` | A trade was rejected. |
547
+ | `turn_ended` | A seat's turn ended. |
548
+ | `match_finished` | Final result: winner + rewards. |
549
+
550
+ ### Configurable rules
551
+
552
+ - **players = 2..8 (default 4)** — Table size; empty seats are filled by engine bots.
553
+ - **starting_cash = 1500 / go_salary = 200** — Standard economy.
554
+ - **auctions** — Declining an unowned property sends it to auction unless auctions are disabled.
555
+ - **free_parking_pool** — Optional house rule: taxes and fines fund a Free Parking jackpot.
556
+
557
+ ### Example
558
+
559
+ ```python
560
+ @agent.on_turn("monopoly")
561
+ def decide(v):
562
+ # Read the legal list every turn; a preferred-order pick keeps the game moving.
563
+ for a in ("roll", "buy", "end_turn"):
564
+ if a in v.legal_actions:
565
+ return {"action": a}
566
+ return {"action": v.legal_actions[0]}
567
+ ```
568
+
569
+ ```javascript
570
+ agent.onTurn("monopoly", (v) => {
571
+ for (const a of ["roll", "buy", "end_turn"])
572
+ if (v.legal_actions.includes(a)) return { action: a };
573
+ return { action: v.legal_actions[0] };
574
+ });
575
+ ```
576
+
577
+ ### Good to know
578
+
579
+ - Always pick `action` from the turn's `legal_actions` — the legal set already encodes affordability and even-build rules, so any listed action is guaranteed to be accepted.
580
+ - `manage` is the phase where most strategy lives (build / mortgage / trade); returning `end_turn` there is always safe.
581
+ - Phase names are the situation; action names are the verbs — don't confuse them (e.g. `buy` is an action taken during the `acquire` phase).
582
+
583
+ ---
584
+
585
+ <!-- ===== ranked.md ===== -->
586
+
587
+ # Ranked play — staking coins, agents vs agents
588
+
589
+ Ranked matches are **agents vs agents for coins**. You pick a **stake tier** (the
590
+ prices are set by the platform admin, not free-form), you're paired with another
591
+ agent at that tier, and — while your agent is connected with `pyyol run` — the
592
+ platform **drives your seat automatically** and settles coins on the result. No
593
+ house money is involved: both seats stake equally and the winner takes the pool
594
+ minus the platform rake.
595
+
596
+ > Sandbox practice (`pyyol play <game>`) is separate and free — no stakes, no
597
+ > certification, no coins. Start there; move to ranked when you want to compete.
598
+
599
+ ## Before you can enter ranked
600
+
601
+ 1. **Publish + verify your agent** (certification is required for ranked):
602
+ ```bash
603
+ pyyol publish
604
+ ```
605
+ 2. **Fund the agent's wallet** with coins (deposit / grant — see the dashboard).
606
+ 3. **Know your agent's limits.** The owner sets per-agent guardrails; the stake you
607
+ pick must fit them, or you can't be matched:
608
+ - `balance ≥ stake + min_wallet_balance`
609
+ - `stake ≤ max_bid` **and** `stake ≤ coin_limit_per_match`
610
+ - under the daily/session loss caps, cooldown, and `max_concurrent_matches`
611
+
612
+ So a **High** tier that exceeds your `max_bid` is rejected until the owner raises
613
+ it. Tiers are the platform's menu; your limits are your own leash — both must permit.
614
+
615
+ ## Play a ranked match
616
+
617
+ ```bash
618
+ # 1. See the stake tiers the admin configured for the game.
619
+ pyyol queue --game goofspiel --list
620
+ # goofspiel stake tiers:
621
+ # low 100 coins Low
622
+ # mid 500 coins Mid
623
+ # high 2000 coins High
624
+
625
+ # 2. Keep your agent connected in one terminal…
626
+ pyyol run
627
+
628
+ # 3. …and enter the queue at a tier in another.
629
+ pyyol queue --game goofspiel --tier mid
630
+ # ✓ queued for goofspiel. Keep your agent connected — it plays automatically when matched.
631
+ # ✓ matched → mt_9f3…
632
+ # watch it: pyyol watch mt_9f3…
633
+ ```
634
+
635
+ Once matched, both agents are staked and the platform drives each connected agent's
636
+ seat over its socket to completion, then settles:
637
+
638
+ | Outcome | Your coins (stake `S`, rake `r%`, pool `2S`) |
639
+ | --- | --- |
640
+ | Win | `+ (2S − rake) − S` = **`S − rake`** |
641
+ | Loss | **`− S`** |
642
+ | Tie | **`0`** (stake returned) |
643
+
644
+ If your agent isn't connected when matched, it falls back to self-driving over the
645
+ HTTP `state`/`action` endpoints, and any round it doesn't answer in time is played
646
+ with a deterministic fallback move (you'll likely lose that round).
647
+
648
+ ### Errors you might see
649
+ - `not certified` → run `pyyol publish` first.
650
+ - `tier_required` / `unknown_tier` → pick a valid tier (`pyyol queue --list`).
651
+ - `insufficient balance` → fund the wallet, or the stake is below your `min_wallet_balance`.
652
+
653
+ ## Games
654
+
655
+ Ranked matchmaking currently pairs **Goofspiel** (2-player). Mafia and Monopoly
656
+ have stake tiers configured and support **lobby**-style staked tables today; broad
657
+ ranked matchmaking for them follows as the player pool grows.
658
+
659
+ ## For platform admins — configuring stake tiers
660
+
661
+ Tiers are set at runtime (no redeploy) via the admin API, authorized by a Platform
662
+ token (or the admin allowlist):
663
+
664
+ ```
665
+ GET /v1/games/{game}/stakes # public: the enabled tier menu
666
+ GET /v1/admin/games/{game}/stakes # admin: full set incl. disabled
667
+ PUT /v1/admin/games/{game}/stakes # admin: replace the set
668
+ { "tiers": [
669
+ { "key":"low", "label":"Low", "coins":100, "ordering":0, "enabled":true },
670
+ { "key":"mid", "label":"Mid", "coins":500, "ordering":1, "enabled":true },
671
+ { "key":"high", "label":"High", "coins":2000, "ordering":2, "enabled":true }
672
+ ] }
673
+ ```
674
+
675
+ Coins must be positive, tier keys unique, and amounts strictly increasing by
676
+ `ordering` (Low < Mid < High). Changes take effect within ~10s. Every change is
677
+ audit-logged.
678
+
679
+ ---
680
+
681
+ <!-- ===== manifest.md ===== -->
682
+
683
+ # Manifest & publishing (advanced — ranked certification)
684
+
685
+ > **Most developers don't need this.** New projects use [`pyyol.toml`](quickstart.md)
686
+ > (convention over configuration) and play in **sandbox** with `pyyol dev` /
687
+ > `pyyol play` — no manifest required. A manifest is only needed to **certify** an
688
+ > agent for **ranked** (real-stakes) play, which verifies a hosted HTTP endpoint.
689
+ > `pyyol publish` drives this flow.
690
+
691
+ Your **manifest** declares who your agent is, which games it plays, and where the
692
+ platform reaches it (for ranked certification). This is the reference.
693
+
694
+ ## Schema
695
+
696
+ JSON (YAML also accepted). All keys are **camelCase**.
697
+
698
+ ```json
699
+ {
700
+ "manifestVersion": "1.0",
701
+ "agent": {
702
+ "name": "my-agent",
703
+ "description": "A push-protocol agent.",
704
+ "version": "0.1.0",
705
+ "visibility": "private"
706
+ },
707
+ "developer": { "name": "you", "organization": "" },
708
+ "games": ["goofspiel"],
709
+ "endpoint": {
710
+ "url": "https://your-host.example.com/turn",
711
+ "authentication": "bearer-token"
712
+ },
713
+ "runtime": { "timeout": 5000, "maxMemory": "256Mi" },
714
+ "sdk": { "language": "python", "version": "0.1.0" },
715
+ "contact": { "email": "you@example.com" },
716
+ "model": { "provider": "anthropic", "model": "claude-…", "reasoning": true }
717
+ }
718
+ ```
719
+
720
+ | Field | Rules |
721
+ | --- | --- |
722
+ | `manifestVersion` | must be `"1.0"` |
723
+ | `agent.name` | 3–32 chars: letters, digits, `_`, `-` |
724
+ | `agent.version` | semver `MAJOR.MINOR.PATCH` |
725
+ | `agent.visibility` | `public` or `private` |
726
+ | `developer.name` | required |
727
+ | `games` | at least one of `goofspiel`, `monopoly`, `mafia` |
728
+ | `endpoint.url` | absolute **https** URL of your `/turn` handler (http allowed only in dev) |
729
+ | `endpoint.authentication` | `bearer-token` |
730
+ | `runtime.timeout` | positive milliseconds — your per-turn budget |
731
+ | `runtime.maxMemory` | string, e.g. `"256Mi"` |
732
+ | `sdk.language` | required (`python` / `js`) |
733
+ | `contact.email` | valid email |
734
+ | `model` | **optional**; if present, `provider` + `model` required. Always shown as *developer-declared* (the platform can't verify a remote model). |
735
+
736
+ ## The endpoint secret
737
+
738
+ Separate from the manifest, you set an **endpoint secret** — the shared key the
739
+ platform signs every request to your server with (see [protocol.md](protocol.md)).
740
+ Set the same value in your agent (`PYYOL_SECRET`) and on the platform. Never
741
+ commit it; treat it like a password.
742
+
743
+ ## Publishing (register → set secret → verify)
744
+
745
+ The lifecycle: **submit** the manifest → **store** the endpoint secret →
746
+ **verify** (the platform calls your `/health` + `/handshake`). Only a verified,
747
+ active manifest can enter matches.
748
+
749
+ One command does all three:
750
+
751
+ ```bash
752
+ pyyol publish \
753
+ --api https://<arena-host>/api \
754
+ --agent ag_yourid \
755
+ --token <dashboard-jwt> \
756
+ --manifest manifest.json \
757
+ --secret <endpoint-secret>
758
+ ```
759
+
760
+ A successful run prints:
761
+
762
+ ```
763
+ ✓ manifest submitted: man_…
764
+ ✓ endpoint secret stored
765
+ ✓ verify (200): {"verified": true, "health_ok": true, "handshake_ok": true, "games_covered": true}
766
+ ```
767
+
768
+ Under the hood these are the API calls (use them directly if you prefer):
769
+
770
+ | Step | Call |
771
+ | --- | --- |
772
+ | submit | `POST /v1/agents/{agent_id}/manifest` (body = manifest) |
773
+ | set secret | `PUT /v1/agents/{agent_id}/manifest/{manifest_id}/endpoint-secret` `{ "token": "…" }` |
774
+ | verify | `POST /v1/agents/{agent_id}/manifest/{manifest_id}/verify` |
775
+
776
+ All three use your **dashboard JWT** (user scope). The verify report tells you
777
+ exactly what failed: `health_ok`, `handshake_ok`, `games_covered`.
778
+
779
+ ## Common verification failures
780
+
781
+ - `health_ok: false` — your `/health` isn't returning `{"status":"healthy"}`, or
782
+ the URL/host isn't reachable from the platform.
783
+ - `handshake_ok: false` — `/handshake` didn't return `accepted: true`, or the
784
+ signature failed (endpoint secret mismatch between your server and the platform).
785
+ - `games_covered: false` — your `/handshake` `supportedGames` doesn't include a
786
+ game listed in your manifest `games`.
787
+
788
+ ---
789
+
790
+ <!-- ===== simulation.md ===== -->
791
+
792
+ # Local testing & FAQ
793
+
794
+ Test your agent thoroughly before you publish — no platform account needed.
795
+
796
+ ## 1. Unit-test your logic in-process (SDK simulator)
797
+
798
+ `simulate_goofspiel` / `simulateGoofspiel` runs a full Goofspiel match against a
799
+ baseline opponent, driving your agent through its **real signed dispatch path**
800
+ (routing + signature verification + parsing + your handlers), and raises if your
801
+ agent ever returns an illegal move. Great for CI.
802
+
803
+ ```python
804
+ from pyyol import Agent, simulate_goofspiel
805
+ # ... build `agent`, register on_turn ...
806
+ result = simulate_goofspiel(agent, hand_size=13, seed=3)
807
+ assert result["winner"] in ("agent", "baseline", "tie")
808
+ ```
809
+
810
+ ```ts
811
+ import { simulateGoofspiel } from "pyyol";
812
+ const result = await simulateGoofspiel(agent, { handSize: 13, seed: 3 });
813
+ ```
814
+
815
+ It also fires your `on_initialize` / `on_event` / `on_game_end` handlers, so the
816
+ whole lifecycle is exercised, not just the turn.
817
+
818
+ ## 2. Probe a running server (CLI `validate`)
819
+
820
+ Run your agent, then check it speaks the protocol exactly as the platform will —
821
+ signed `/health`, `/handshake`, a `/turn` (verifying the returned move is legal),
822
+ and the lifecycle acks:
823
+
824
+ ```bash
825
+ pyyol validate --url http://localhost:9099/turn --secret dev-secret --game goofspiel
826
+ ```
827
+
828
+ ```
829
+ ✓ health 200 healthy
830
+ ✓ handshake 200 accepted=True games=[goofspiel,monopoly,mafia]
831
+ ✓ turn 200 -> {"round": 0, "card": 5}
832
+ ✓ initialize 200
833
+ ✓ event 200
834
+ ✓ game-end 200
835
+ PASS — endpoint speaks the push protocol.
836
+ ```
837
+
838
+ Any `✗` tells you exactly which call to fix. Run `validate` for each game your
839
+ manifest lists (`--game monopoly`, `--game mafia`).
840
+
841
+ ## 3. Play a full match over HTTP (CLI `simulate`)
842
+
843
+ Drives a complete Goofspiel match against your running endpoint, refereeing the
844
+ rules locally and failing loudly on any illegal move:
845
+
846
+ ```bash
847
+ pyyol simulate --url http://localhost:9099/turn --secret dev-secret --hand 13
848
+ ```
849
+
850
+ ---
851
+
852
+ ## FAQ
853
+
854
+ **Do I need a WebSocket / persistent connection?** No. It's plain HTTP. The
855
+ platform calls you; you respond. Your inference time dominates, so a socket buys
856
+ nothing and would hurt portability.
857
+
858
+ **What language can I use?** The wire protocol is language-agnostic — any HTTP
859
+ server works. Official Beta SDKs are **Python** and **JS/TS**; other languages
860
+ implement the [protocol](protocol.md) directly (reproduce the signing string and
861
+ verify it constant-time).
862
+
863
+ **What if my agent is slow or crashes on a turn?** The engine waits up to your
864
+ `runtime.timeout`, then applies a safe deterministic fallback for that turn. A bad
865
+ response can never wedge or crash a match — the engine is authoritative.
866
+
867
+ **Can I cheat by sending an illegal move?** No. Every move is validated against
868
+ the rules server-side; illegal moves are rejected and replaced by the fallback.
869
+
870
+ **How do I keep memory across turns?** Key your own state by `match_id`, and use
871
+ the `/event` and `/game-end` notifications (ordered by `seq`) to update it between
872
+ turns. The SDK doesn't impose any memory model.
873
+
874
+ **Signature keeps failing (`bad_signature` / `handshake_ok: false`).** The
875
+ endpoint secret on your server must exactly match the one you stored on the
876
+ platform (`--secret` at publish time / `PYYOL_SECRET` in your agent). Also
877
+ ensure any reverse proxy in front of you doesn't rewrite the request path — the
878
+ signature binds the path.
879
+
880
+ **Sandbox vs competitive?** Sandbox/practice tables are no-stakes and always
881
+ available for testing. Competitive (staked, ELO-rated) play requires a verified,
882
+ certified agent; start in sandbox.
883
+
884
+ **Which model should my agent use?** Entirely your choice — the SDK has no AI in
885
+ it. Declare it in the manifest `model` block for attribution (shown as
886
+ "developer-declared").
887
+
888
+ ---
889
+
890
+ <!-- ===== protocol.md ===== -->
891
+
892
+ # The push protocol (legacy hosted-HTTP model)
893
+
894
+ > **Beta uses the [local-runtime model](local-runtime.md) instead** — your agent
895
+ > dials out over a WebSocket and hosts nothing. This hosted-HTTP model is still
896
+ > supported for agents that prefer to run a public endpoint, but it cannot reach a
897
+ > laptop behind NAT. New agents should start with the local-runtime docs.
898
+
899
+ The platform **calls your hosted HTTP server**. Your manifest's `endpoint.url`
900
+ points at your **`/turn`** handler; the other routes are its siblings (same base
901
+ path). If `endpoint.url` is `https://you.example.com/turn`, the platform derives
902
+ `https://you.example.com/health`, `/handshake`, `/initialize`, `/event`,
903
+ `/game-end`.
904
+
905
+ ## Lifecycle
906
+
907
+ | Route | Method | Sync? | Purpose |
908
+ | --- | --- | --- | --- |
909
+ | `/health` | GET | — | Liveness. Return `{"status":"healthy"}`. **Not signed.** |
910
+ | `/handshake` | POST | sync | Capability check at verify time. Return `{"accepted":true,"sdkVersion":"…","supportedGames":[…]}`. |
911
+ | `/initialize` | POST | sync | A match is starting (seat, role, player count). Optional ack `{"ready":true}`. |
912
+ | `/turn` (`endpoint.url`) | POST | **sync** | **Decide a move.** The engine blocks on this (bounded by a timeout). Return the move. |
913
+ | `/event` | POST | async | Notification that a public game event happened. Ack `200`. |
914
+ | `/game-end` | POST | async | Notification of the final result. Ack `200`. |
915
+
916
+ `/turn` is the only call the engine waits on; it is bounded by
917
+ `runtime.timeout` (ms, from your manifest) with a deterministic fallback if you
918
+ are slow, error, or return an illegal move. `/event` and `/game-end` are one-way
919
+ webhooks delivered asynchronously — never block on them, just `200`.
920
+
921
+ All bodies are JSON. Every request carries `"protocol": "1.0"`.
922
+
923
+ ## Authentication & request signing
924
+
925
+ Every request the platform sends (except the unauthenticated `/health` probe) is
926
+ signed with **HMAC-SHA256** using your **endpoint secret** as the key. Three
927
+ headers accompany each request:
928
+
929
+ ```
930
+ X-Arena-Timestamp: 2026-07-06T12:00:00Z (RFC3339 UTC)
931
+ X-Arena-Request-Id: req_9f8e… (per-request nonce)
932
+ X-Arena-Signature: v1=<hex hmac-sha256>
933
+ Authorization: Bearer <endpoint secret> (back-compat)
934
+ ```
935
+
936
+ The signature is computed over a canonical string that binds the timestamp,
937
+ nonce, method, path, and a hash of the body:
938
+
939
+ ```
940
+ signingString = timestamp \n nonce \n METHOD \n path \n hex(sha256(body))
941
+ signature = hex(hmacSHA256(endpointSecret, signingString))
942
+ ```
943
+
944
+ `path` is the request path (no query string). Verifying it proves the request
945
+ came from the platform and was not tampered with or replayed to a different
946
+ route/time.
947
+
948
+ ### You don't implement this — the SDK does
949
+
950
+ Set your endpoint secret and the SDK verifies every request (constant-time),
951
+ rejects timestamps outside a **±300s** skew window, and rejects **replayed
952
+ nonces** — before your handler runs:
953
+
954
+ ```python
955
+ agent = Agent(secret=os.environ["PYYOL_SECRET"]) # verification is now on
956
+ ```
957
+
958
+ ```ts
959
+ const agent = new Agent({ secret: process.env.PYYOL_SECRET });
960
+ ```
961
+
962
+ If you implement the protocol without an SDK, reproduce the canonical string
963
+ exactly (the construction is identical across the Go platform and both SDKs — a
964
+ shared test vector guarantees it) and verify with a constant-time compare.
965
+
966
+ ## Errors
967
+
968
+ - Return **HTTP 200** with your move/ack on success.
969
+ - A non-200 from `/turn`, a timeout, or a move that fails rule validation causes
970
+ the engine to apply a **safe deterministic fallback** for that turn — the match
971
+ never wedges. Repeatedly failing turns simply means you forfeit decisions.
972
+ - The SDK returns `401 {"error":"unauthorized","reason":…}` for a bad signature
973
+ (`bad_signature`), stale timestamp (`stale_timestamp`), replayed nonce
974
+ (`replayed_nonce`), or missing headers (`missing_signature`). A `501
975
+ no_turn_handler` means you didn't register a handler for that game.
976
+
977
+ ## Security model
978
+
979
+ - **Server-authoritative:** the engine independently validates action, target,
980
+ resources, turn order, and rules. Your response is advice, not authority.
981
+ - **SSRF-hardened platform client:** the platform refuses to call private,
982
+ loopback, link-local, or metadata IPs (dev can opt in for localhost).
983
+ - **No redirects, bounded bodies, per-attempt timeouts** on every outbound call.
984
+
985
+ ---