@air-jam/cli 0.0.0-stage → 1.0.0-beta.1

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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +273 -2
  3. package/bin/airjam.mjs +66 -0
  4. package/dist/ai-pack.d.ts +44 -0
  5. package/dist/ai-pack.js +15 -0
  6. package/dist/ai-pack.js.map +1 -0
  7. package/dist/auth-profile.d.ts +5 -0
  8. package/dist/auth-profile.js +7 -0
  9. package/dist/auth-profile.js.map +1 -0
  10. package/dist/auth-sessions.d.ts +5 -0
  11. package/dist/auth-sessions.js +7 -0
  12. package/dist/auth-sessions.js.map +1 -0
  13. package/dist/chunk-7D4AYBAV.js +64 -0
  14. package/dist/chunk-7D4AYBAV.js.map +1 -0
  15. package/dist/chunk-J5MAU4QZ.js +102 -0
  16. package/dist/chunk-J5MAU4QZ.js.map +1 -0
  17. package/dist/chunk-LH7UO57C.js +23 -0
  18. package/dist/chunk-LH7UO57C.js.map +1 -0
  19. package/dist/chunk-N7AI7HZK.js +529 -0
  20. package/dist/chunk-N7AI7HZK.js.map +1 -0
  21. package/dist/chunk-PKTLVQXZ.js +82 -0
  22. package/dist/chunk-PKTLVQXZ.js.map +1 -0
  23. package/dist/chunk-SQE4NPZP.js +31 -0
  24. package/dist/chunk-SQE4NPZP.js.map +1 -0
  25. package/dist/chunk-U6V3HEBB.js +939 -0
  26. package/dist/chunk-U6V3HEBB.js.map +1 -0
  27. package/dist/chunk-VEHNFPEO.js +224 -0
  28. package/dist/chunk-VEHNFPEO.js.map +1 -0
  29. package/dist/development.d.ts +102 -0
  30. package/dist/development.js +33 -0
  31. package/dist/development.js.map +1 -0
  32. package/dist/documentation.d.ts +27 -0
  33. package/dist/documentation.js +7 -0
  34. package/dist/documentation.js.map +1 -0
  35. package/dist/game-analytics.d.ts +5 -0
  36. package/dist/game-analytics.js +7 -0
  37. package/dist/game-analytics.js.map +1 -0
  38. package/dist/game-app-id.d.ts +5 -0
  39. package/dist/game-app-id.js +7 -0
  40. package/dist/game-app-id.js.map +1 -0
  41. package/dist/game-media.d.ts +5 -0
  42. package/dist/game-media.js +7 -0
  43. package/dist/game-media.js.map +1 -0
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +2468 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/scaffold.d.ts +6 -0
  48. package/dist/scaffold.js +20 -0
  49. package/dist/scaffold.js.map +1 -0
  50. package/package.json +82 -3
  51. package/runtime/local-network.d.mts +6 -0
  52. package/runtime/local-network.mjs +9 -0
  53. package/runtime/public-assets.mjs +62 -0
  54. package/runtime/source-fence.mjs +182 -0
  55. package/runtime/vite-config.d.mts +43 -0
  56. package/runtime/vite-config.mjs +134 -0
  57. package/runtime/vite-dev.mjs +18 -0
  58. package/runtime/vite-https.d.mts +11 -0
  59. package/runtime/vite-https.mjs +40 -0
  60. package/template-assets/bootstrap/.claude/launch.json +12 -0
  61. package/template-assets/bootstrap/AGENTS.md +290 -0
  62. package/template-assets/bootstrap/CLAUDE.md +55 -0
  63. package/template-assets/bootstrap/_gitignore +6 -0
  64. package/template-assets/bootstrap/skills/airjam-docs-workflow/SKILL.md +49 -0
  65. package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +100 -0
  66. package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
  67. package/template-assets/bootstrap/skills/controller-ui/SKILL.md +71 -0
  68. package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
  69. package/template-assets/bootstrap/skills/game-architecture/SKILL.md +102 -0
  70. package/template-assets/bootstrap/skills/game-state-and-rendering/SKILL.md +44 -0
  71. package/template-assets/bootstrap/skills/host-surface/SKILL.md +52 -0
  72. package/template-assets/bootstrap/skills/index.md +36 -0
  73. package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +58 -0
  74. package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +61 -0
  75. package/template-assets/documentation/for-agents/controller-ui/page.mdx +99 -0
  76. package/template-assets/documentation/for-agents/page.mdx +120 -0
  77. package/template-assets/documentation/for-agents/project-structure/page.mdx +170 -0
  78. package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +77 -0
  79. package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
  80. package/template-assets/documentation/getting-started/debugging/page.mdx +164 -0
  81. package/template-assets/documentation/getting-started/dev-logs/page.mdx +169 -0
  82. package/template-assets/documentation/getting-started/game-ideas/page.mdx +114 -0
  83. package/template-assets/documentation/getting-started/introduction/page.mdx +200 -0
  84. package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +673 -0
  85. package/template-assets/documentation/getting-started/quick-start/page.mdx +310 -0
  86. package/template-assets/documentation/how-it-works/architecture/page.mdx +230 -0
  87. package/template-assets/documentation/how-it-works/host-system/page.mdx +270 -0
  88. package/template-assets/documentation/manifest.json +500 -0
  89. package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
  90. package/template-assets/documentation/sdk/hooks/page.mdx +435 -0
  91. package/template-assets/documentation/sdk/input-system/page.mdx +240 -0
  92. package/template-assets/documentation/sdk/networked-state/page.mdx +295 -0
  93. package/template-assets/documentation/sdk/settings/page.mdx +155 -0
  94. package/template-assets/documentation/sdk/ui-components/page.mdx +268 -0
  95. package/template-assets/managed/.airjam/ai-pack.json +209 -0
  96. package/template-assets/managed/docs/airjam/agent-gold-path.md +115 -0
  97. package/template-assets/managed/docs/airjam/agent-mcp.md +179 -0
  98. package/template-assets/managed/docs/airjam/canvas-2d-gameplay.md +82 -0
  99. package/template-assets/managed/docs/airjam/composition-shell-contract.md +87 -0
  100. package/template-assets/managed/docs/airjam/debug-and-testing.md +104 -0
  101. package/template-assets/managed/docs/airjam/development-loop.md +51 -0
  102. package/template-assets/managed/docs/airjam/docs-index.md +64 -0
  103. package/template-assets/managed/docs/airjam/generated/architecture.md +223 -0
  104. package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
  105. package/template-assets/managed/docs/airjam/generated/controller-ui.md +102 -0
  106. package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +165 -0
  107. package/template-assets/managed/docs/airjam/generated/for-agents.md +123 -0
  108. package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
  109. package/template-assets/managed/docs/airjam/generated/host-system.md +261 -0
  110. package/template-assets/managed/docs/airjam/generated/input-system.md +241 -0
  111. package/template-assets/managed/docs/airjam/generated/introduction.md +195 -0
  112. package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +674 -0
  113. package/template-assets/managed/docs/airjam/generated/networked-state.md +298 -0
  114. package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
  115. package/template-assets/managed/docs/airjam/generated/quick-start.md +311 -0
  116. package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +430 -0
  117. package/template-assets/managed/docs/airjam/generated/settings.md +158 -0
  118. package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
  119. package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
  120. package/template-assets/managed/docs/airjam/generated/ui-components.md +265 -0
  121. package/template-assets/managed/docs/airjam/generated/unified-dev-logs.md +170 -0
  122. package/template-assets/managed/docs/airjam/iconography.md +55 -0
  123. package/template-assets/managed/docs/airjam/prefab-authoring.md +212 -0
  124. package/template-assets/managed/docs/airjam/preview-controllers.md +129 -0
  125. package/template-assets/managed/docs/airjam/r3f-3d-scene.md +163 -0
  126. package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +101 -0
  127. package/template-assets/managed/docs/airjam/visual-system.md +103 -0
@@ -0,0 +1,123 @@
1
+ <!-- Generated from content/docs/for-agents/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/for-agents -->
3
+
4
+ # For Agents
5
+
6
+ This page is the fastest entrypoint for LLM agents and automation tools.
7
+
8
+ ## What Air Jam Is
9
+
10
+ Air Jam is an open AI-native framework for multiplayer games controlled by
11
+ phones.
12
+ Hosts run in your game, inputs are routed through the Air Jam server, and both
13
+ humans and agents work against typed controller, runtime, state, and release
14
+ surfaces instead of guessing through UI only.
15
+
16
+ Air Jam is the harness around your existing coding agent, not a separate hosted
17
+ editor. Local project instructions, CLI commands, MCP tools, runtime observations,
18
+ and hosted release services form one development path.
19
+
20
+ ## Connect to a Project
21
+
22
+ Run these commands from a generated game project with dependencies installed:
23
+
24
+ ```bash
25
+ pnpm exec airjam --help
26
+ pnpm exec airjam mcp doctor --dir . --json
27
+ pnpm exec airjam mcp config --profile portable --dir .
28
+ ```
29
+
30
+ New projects include `.mcp.json`. If a project has no declaration, use
31
+ `pnpm exec airjam mcp init --dir .`; it does not overwrite an existing declaration
32
+ unless you explicitly pass `--force`.
33
+
34
+ Some clients use their own registration formats instead of reading `.mcp.json`:
35
+
36
+ ```bash
37
+ pnpm exec airjam mcp config --profile codex --dir .
38
+ pnpm exec airjam mcp config --profile claude-desktop --dir .
39
+ ```
40
+
41
+ These commands render configuration; they do not install it into the client.
42
+ Use the rendered command, arguments, and absolute project directory when adding
43
+ the server. `mcp doctor` distinguishes project declarations from detected client
44
+ registrations. Confirm that the connected client discovers Air Jam's tools before
45
+ treating the connection as working.
46
+
47
+ [Supported Agents](./supported-agents.md) lists the clients tested end to end.
48
+
49
+ ## Operate and Evaluate
50
+
51
+ For gameplay assertions, use `airjam.open_game_session`,
52
+ `airjam.read_game_session`, `airjam.invoke_game_session_action`, and
53
+ `airjam.close_game_session`. Read each session's published actions and state;
54
+ do not guess game-specific action IDs. `airjam.capture_game_session_visuals`
55
+ adds host and phone-controller screenshots to the same session.
56
+
57
+ In Studio, `studio_press_phone` taps, holds or types on one named mounted Studio phone
58
+ and returns its private screen in the same call. Coordinates are fractions 0..1 of
59
+ `studio_observe_current_game`'s `surface=phone` image. Tap a field before typing;
60
+ a hold captures while pressed, then releases. Reuse the requestId UUID for retries.
61
+ Guest/real phones and older runtimes return an explicit unavailable reason.
62
+
63
+ MCP is optional. A terminal agent can use the same services:
64
+
65
+ ```bash
66
+ pnpm exec airjam session open --dir .
67
+ pnpm exec airjam session read <session-id> --dir .
68
+ pnpm exec airjam session invoke <session-id> <action-id> --payload '{}'
69
+ pnpm exec airjam session capture <session-id> --dir .
70
+ pnpm exec airjam session close <session-id> --dir .
71
+ ```
72
+
73
+ A session starts or reuses the canonical development process. If you start it
74
+ yourself, use `pnpm run dev`, not raw Vite. Use semantic state for repeatable
75
+ gameplay checks and rendered screenshots or browser interaction for visual polish.
76
+ During editing, run the relevant focused checks. Before sharing a completed game,
77
+ run `pnpm exec airjam evaluate --dir .` or the `airjam.evaluate` tool for the complete
78
+ typecheck, lint, test, and build result.
79
+
80
+ The [Quick Start publishing guide](https://airjam.io/docs/getting-started/quick-start#terminal-or-agent-publishing)
81
+ covers CLI authentication, hosted release submission, inspection, and explicit
82
+ publication. Local development and evaluation do not require hosted publishing.
83
+
84
+ ## Decision-model Players
85
+
86
+ An `AirJamPlayerContract` from `@air-jam/devtools/testing` describes play with
87
+ `brief` and `turn`. A turn returns `{ state, question, options }` or `null` when
88
+ the seat has nothing to do. Offer 1 to 16 named options, each with a plain-language
89
+ `when` and its `control`. Zero options is invalid; use `null` to wait.
90
+
91
+ A single sensible move is allowed: for example, a lobby turn can offer only
92
+ `join` with `control: { kind: "action", actionId: "join_match" }`. The run owner
93
+ takes that control directly without calling a decision model or incurring model
94
+ cost. Do not invent a second option to satisfy validation. Multiple options ask
95
+ the run's model to choose. Automatic answers retain the choice and control in the
96
+ trace, marked `Only option; no model asked.`, and count toward the seat's optional
97
+ `answers.automatic` summary. The policy receives the choice just like a model
98
+ answer on its next step.
99
+
100
+ ## Read These First
101
+
102
+ 1. [Introduction](./introduction.md)
103
+ 2. [Quick Start](./quick-start.md)
104
+ 3. [Architecture](./architecture.md)
105
+ 4. [Host System](./host-system.md)
106
+ 5. [Project Structure](./project-structure.md)
107
+ 6. [Controller UI](./controller-ui.md)
108
+ 7. [State and Rendering](./state-and-rendering.md)
109
+ 8. [SDK Hooks](./sdk-hooks.md)
110
+ 9. [Debugging and Logs](./debugging-and-logs.md)
111
+ 10. [Unified Dev Logs](./unified-dev-logs.md)
112
+
113
+ ## SDK Focus Areas
114
+
115
+ - [Input System](./input-system.md)
116
+ - [Networked State](./networked-state.md)
117
+
118
+ ## Machine Discovery
119
+
120
+ - [AI Pack Manifest](/ai-pack/manifest.json)
121
+ - [LLMs Index](https://airjam.io/llms.txt)
122
+ - [Sitemap](https://airjam.io/sitemap.xml)
123
+ - [Robots](https://airjam.io/robots.txt)
@@ -0,0 +1,107 @@
1
+ <!-- Generated from content/docs/getting-started/game-ideas/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/getting-started/game-ideas -->
3
+
4
+ # Game Ideas for Air Jam
5
+
6
+ A collection of game concepts that leverage Air Jam's unique architecture: **High-Frequency Input Streams** (declared controls) + **Reliable Shared State** (AirJam Store).
7
+
8
+ ---
9
+
10
+ ### Neon Tanks
11
+
12
+ - Top-down arena shooter (4-8 players)
13
+ - Dual stick controls: movement + turret aiming
14
+ - Tap to fire
15
+ - **Key Feature:** Demonstrates dual stick capability on touchscreen
16
+
17
+ ### Super Sumo Balls
18
+
19
+ - Rolling balls on tilting platform
20
+ - Use phone gyroscope/accelerometer to tilt
21
+ - Haptic feedback on collisions
22
+ - **Key Feature:** Phone sensors + haptic signals
23
+
24
+ ---
25
+
26
+ ### The Traitor (Among Us style)
27
+
28
+ - 8 players: 6 crew, 2 traitors
29
+ - Hidden roles shown only on phone
30
+ - Task minigames on controller
31
+ - Voting UI on phone
32
+ - **Key Feature:** Secret information per player (killer app for phone controllers)
33
+
34
+ ### Sketchy Business (Pictionary style)
35
+
36
+ - Draw prompts on phone canvas
37
+ - Drawings appear on TV
38
+ - **Key Feature:** Touchscreen as natural drawing pad
39
+
40
+ ### Quiz Show Royale
41
+
42
+ - Fastest finger first trivia
43
+ - Personalized feedback (green/red + vibration)
44
+ - **Key Feature:** Input timestamping for speed
45
+
46
+ ---
47
+
48
+ ### Starship Bridge Simulator
49
+
50
+ - 4 players with different roles
51
+ - Each player gets different UI on phone
52
+ - Asymmetrical gameplay
53
+ - **Key Feature:** Different React components per controller
54
+
55
+ ### Ghost Hunter
56
+
57
+ - 1 vs 3 asymmetrical gameplay
58
+ - Ghost sees minimap on phone only
59
+ - Hunters use joysticks on TV
60
+ - **Key Feature:** Private screen advantage
61
+
62
+ ---
63
+
64
+ ### Poker Night / Blackjack
65
+
66
+ - Private cards on phone
67
+ - Betting UI on phone
68
+ - Public table on TV
69
+ - **Key Feature:** Hidden information per player
70
+
71
+ ### Artillery Wars (Worms style)
72
+
73
+ - Turn-based tank battle
74
+ - Aiming interface on phone (angle/power sliders)
75
+ - Weapon selection on phone
76
+ - **Key Feature:** Complex menus on touchscreen
77
+
78
+ ---
79
+
80
+ ### The Crowd Pixel (r/place style)
81
+
82
+ - 50+ players
83
+ - Each controls a pixel/cursor
84
+ - Collaborative painting
85
+ - **Key Feature:** Tests scalability
86
+
87
+ ### Minority Report UI
88
+
89
+ - Phone as trackpad
90
+ - Gesture controls
91
+ - **Key Feature:** Phone as input device
92
+
93
+ ---
94
+
95
+ ## Key Mechanics Enabled
96
+
97
+ ```
98
+ | Mechanic | Example | Technical Feature |
99
+ |-------------------|-------------------|-----------------------------------------|
100
+ | Secret Roles | Mafia / Traitor | `useSharedState` (filter by `playerId`) |
101
+ | Private Inventory | RPG / Poker | Shared Store + React UI on Phone |
102
+ | Motion Steering | Racing / Rolling | Device Accelerometer → Input Stream |
103
+ | Fastest Finger | Quiz Show | Input Latching (Timestamps) |
104
+ | Physical Feedback | Fighting / Action | `host.sendSignal("HAPTIC")` |
105
+ | Drawing | Pictionary | Canvas API + Data Packet |
106
+ | Asymmetry | Ghost Hunter | Different Views per Role |
107
+ ```
@@ -0,0 +1,261 @@
1
+ <!-- Generated from content/docs/how-it-works/host-system/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/how-it-works/host-system -->
3
+
4
+ # Host System
5
+
6
+ The Air Jam host system manages game sessions and input routing. This page explains how hosts work in different modes and how input flows through the system.
7
+
8
+ ### Standalone Host
9
+
10
+ The simplest mode—your game connects directly to the Air Jam server.
11
+
12
+ **Usage:**
13
+
14
+ ```tsx filename="src/app.tsx"
15
+ import { createAirJamApp, env } from "@air-jam/sdk";
16
+ import { airjam as game } from "./airjam.config";
17
+
18
+ export const airjam = createAirJamApp(game, {
19
+ runtime: env.vite(import.meta.env),
20
+ });
21
+
22
+ const HostShell = () => (
23
+ <airjam.Host
24
+ onPlayerJoin={(player) => spawnPlayer(player)}
25
+ onPlayerLeave={(id) => removePlayer(id)}
26
+ >
27
+ <HostView />
28
+ </airjam.Host>
29
+ );
30
+
31
+ // Players' controls reach the game in its simulation steps:
32
+ // step: (sim, { input, players }) => players.forEach((p) => process(sim, input(p.id)))
33
+ const HostView = () => <GameCanvas />;
34
+ ```
35
+
36
+ `createAirJamApp` binds the game declaration from `src/airjam.config.ts` to the
37
+ browser and returns `Host`, `Controller` and `paths`.
38
+
39
+ ### Arcade Mode (Outer App + Embedded Game)
40
+
41
+ In arcade mode, the platform runs the outer Arcade app and your game runs as an embedded Air Jam host inside an iframe.
42
+
43
+ The important rule is:
44
+
45
+ 1. Arcade owns platform surface state
46
+ 2. your game owns gameplay state
47
+ 3. the room owns membership, seats and the latest copy of every channel
48
+
49
+ ## One Room, Served to Each Frame
50
+
51
+ The Arcade's shell is the room's only host. It never hands its connection to a
52
+ game: when it shows a game, it serves that game's frame a view of its room over
53
+ a `MessagePort`, and each game's controller page gets the same kind of view of
54
+ its phone's seat.
55
+
56
+ - A frame sees and publishes only its own channels: everything outside the
57
+ Arcade's own `arcade.*` channels, such as `airjam.room` and its stores
58
+ - A frame that reaches outside its scope is closed `unauthorised`; the room and
59
+ the shell carry on
60
+ - A new frame for the same surface replaces the old one, which closes as
61
+ `replaced`
62
+ - Which game is showing lives in the shell's `arcade.surface` channel; its
63
+ `epoch` identifies one showing of one game
64
+
65
+ Your game uses the normal input lane, replicated state lane and signal lane, as
66
+ it would standalone.
67
+
68
+ ### 1. Arcade Launch
69
+
70
+ ```
71
+ [Arcade shell] [Room] [Phone]
72
+ │ │ │
73
+ │ hello (host key, seats) │ │
74
+ │ ───────────────────────────▶│ │
75
+ │ │ │
76
+ │ welcome { code: "ABCD" } │ │
77
+ │ ◀───────────────────────────│ │
78
+ │ │ │
79
+ │ Display QR Code │ │
80
+ │ with room code │ Scan QR Code │
81
+ │ │ ◀──────────────────────────│
82
+ │ │ │
83
+ │ │ hello (phone key) │
84
+ │ │ ◀──────────────────────────│
85
+ │ │ │
86
+ │ seats [p1] │ welcome { seat: p1 } │
87
+ │ ◀───────────────────────────│ ──────────────────────────▶│
88
+ ```
89
+
90
+ ### 2. Game Launch
91
+
92
+ ```
93
+ [Arcade shell] [Your Game] [Phone]
94
+ │ │ │
95
+ │ arcade.surface → { kind: "game" } │ │
96
+ │ ─────────────────────────────────────────────────────────▶│
97
+ │ │ │
98
+ │ Load iframe ─────────────────────────▶│ │
99
+ │ │ │
100
+ │ room bridge request (MessagePort) │ │
101
+ │ ◀─────────────────────────────────────│ │
102
+ │ │ │
103
+ │ serve a scoped view of the room ───▶│ │
104
+ │ │ │
105
+ │ │ Load game UI │
106
+ ```
107
+
108
+ ### 3. Active Gameplay
109
+
110
+ While the game shows, every seat's input reaches your game:
111
+
112
+ ```ts
113
+ // Your game's simulation reads controls as usual inside the mounted host runtime.
114
+ step: (sim, { input, players }) => {
115
+ for (const player of players) play(sim, player.id, input(player.id));
116
+ },
117
+ ```
118
+
119
+ #### When a phone drops
120
+
121
+ A phone that loses its connection keeps its seat while the room waits for it
122
+ to come back (two minutes by default). The game hears at once: the player stays
123
+ in `players` with `connected: false`, and becomes connected again when the
124
+ phone is back. The simulation step also gets `reconnectingPlayerIds`, so each
125
+ game decides whether to wait, let a bot cover or carry on:
126
+
127
+ ```ts
128
+ step: (sim, { players, reconnectingPlayerIds }) => {
129
+ if (reconnectingPlayerIds.length > 0) return; // hold until everyone is back
130
+ // ...
131
+ },
132
+ ```
133
+
134
+ Outside the simulation, `getReconnectingPlayerIds(players)` from
135
+ `@air-jam/sdk/core` gives the same list from `useAirJamHost()` state.
136
+
137
+ ### 4. Game Exit
138
+
139
+ ```
140
+ [Phone] [Arcade shell] [Your Game]
141
+ │ │ │
142
+ │ exit (arcade.surface request) │
143
+ │ ───────────────────▶│ │
144
+ │ │ arcade.surface → { kind: "browser" }│
145
+ │ │ Close the game's view ─────────────▶│
146
+ │ │ Drop the game's channels │
147
+ │ │ Destroy iframe ────────────────────▶│
148
+ │ ◀── Show Arcade controller │
149
+ ```
150
+
151
+ ### Standalone Mode
152
+
153
+ ```tsx
154
+ <airjam.Host roomId="GAME">
155
+ <HostView />
156
+ </airjam.Host>;
157
+
158
+ // Inside HostView:
159
+ const host = useAirJamHost();
160
+ // host.roomId contains the room code
161
+ // host.joinUrl contains full URL for QR code
162
+ ```
163
+
164
+ Opening the room stays automatic:
165
+
166
+ 1. local dev: no credential
167
+ 2. hosted rooms: the SDK fetches a short-lived grant from `hostGrantEndpoint`
168
+ for each room it opens, and sends render-crash reports to the platform
169
+ unless the app passes its own `reportError`
170
+ 3. after a reload, the host returns to its room with its key and keeps its
171
+ players
172
+
173
+ Game code does not change between those modes.
174
+
175
+ ### Embedded Game Mode (Arcade)
176
+
177
+ ```tsx
178
+ // The SDK detects that it is embedded and asks the page around it for the room.
179
+ // Game code should not parse the embedding params directly.
180
+ const host = useAirJamHost();
181
+
182
+ // Closing and switching games belong to the Arcade.
183
+ // Game hosts keep gameplay logic in host callbacks and simulation steps.
184
+ ```
185
+
186
+ ### Player Lifecycle
187
+
188
+ ```tsx
189
+ const HostShell = () => (
190
+ <airjam.Host
191
+ onPlayerJoin={(player) => {
192
+ // player.id - The seat the room gave ("p1", "p2", …)
193
+ // player.label - Display name ("Player 1", or the name they chose)
194
+ // player.color - Assigned color ("#FF5733")
195
+ // player.kind - "phone", "preview" or "agent"
196
+ // player.connected - false while the phone is away
197
+ // player.avatarId - Optional chosen avatar
198
+ spawnPlayerEntity(player);
199
+ announceJoin(player.label);
200
+ }}
201
+ onPlayerLeave={(controllerId) => {
202
+ removePlayerEntity(controllerId);
203
+ }}
204
+ >
205
+ <HostView />
206
+ </airjam.Host>
207
+ );
208
+ ```
209
+
210
+ ### Accessing Players
211
+
212
+ ```tsx
213
+ // Current player list
214
+ host.players.forEach((player) => {
215
+ console.log(player.label, player.color);
216
+ });
217
+
218
+ // Player count
219
+ const playerCount = host.players.length;
220
+
221
+ // Find specific player
222
+ const player = host.players.find((p) => p.id === targetId);
223
+ ```
224
+
225
+ ## Controller Presentation State
226
+
227
+ The host publishes a small presentation for the phones: whether the game is
228
+ playing or paused, and how to hold the phone. Networked stores own the real
229
+ multiplayer state; a short message for the players is a toast signal or a
230
+ store field.
231
+
232
+ A game whose `inputModalities` include `'joystick'` always gets a landscape controller; the SDK applies it, so do not set orientation; lay it out with `GamepadLayout` from `@air-jam/sdk/ui`: the stick under the left thumb, the actions under the right in a square the same size, and only short status between them.
233
+
234
+ ```tsx
235
+ const host = useAirJamHost();
236
+ host.pauseRuntime();
237
+ host.resumeRuntime();
238
+
239
+ // Controllers read controller.runtimeState and controller.controllerOrientation
240
+ ```
241
+
242
+ ## Error Handling
243
+
244
+ ```tsx
245
+ const host = useAirJamHost();
246
+
247
+ // Reconnecting is automatic; show it while it happens
248
+ if (host.connectionStatus === "reconnecting") {
249
+ showReconnectUI();
250
+ }
251
+
252
+ // A busy hosted service queues new rooms
253
+ if (host.queuePosition !== null) {
254
+ showQueue(host.queuePosition);
255
+ }
256
+
257
+ // Check for errors
258
+ if (host.lastError) {
259
+ showError(host.lastError);
260
+ }
261
+ ```