@air-jam/cli 0.9.3 → 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 (94) hide show
  1. package/README.md +128 -0
  2. package/dist/auth-profile.d.ts +5 -0
  3. package/dist/auth-profile.js +7 -0
  4. package/dist/auth-profile.js.map +1 -0
  5. package/dist/auth-sessions.d.ts +5 -0
  6. package/dist/auth-sessions.js +7 -0
  7. package/dist/auth-sessions.js.map +1 -0
  8. package/dist/chunk-7D4AYBAV.js +64 -0
  9. package/dist/chunk-7D4AYBAV.js.map +1 -0
  10. package/dist/chunk-LH7UO57C.js +23 -0
  11. package/dist/chunk-LH7UO57C.js.map +1 -0
  12. package/dist/chunk-PKTLVQXZ.js +82 -0
  13. package/dist/chunk-PKTLVQXZ.js.map +1 -0
  14. package/dist/chunk-SQE4NPZP.js +31 -0
  15. package/dist/chunk-SQE4NPZP.js.map +1 -0
  16. package/dist/{chunk-A4V2N4LX.js → chunk-U6V3HEBB.js} +6 -5
  17. package/dist/chunk-U6V3HEBB.js.map +1 -0
  18. package/dist/chunk-VEHNFPEO.js +224 -0
  19. package/dist/chunk-VEHNFPEO.js.map +1 -0
  20. package/dist/development.d.ts +4 -0
  21. package/dist/development.js +1 -1
  22. package/dist/game-analytics.d.ts +5 -0
  23. package/dist/game-analytics.js +7 -0
  24. package/dist/game-analytics.js.map +1 -0
  25. package/dist/game-app-id.d.ts +5 -0
  26. package/dist/game-app-id.js +7 -0
  27. package/dist/game-app-id.js.map +1 -0
  28. package/dist/game-media.d.ts +5 -0
  29. package/dist/game-media.js +7 -0
  30. package/dist/game-media.js.map +1 -0
  31. package/dist/index.js +688 -404
  32. package/dist/index.js.map +1 -1
  33. package/package.json +8 -4
  34. package/runtime/local-network.d.mts +4 -6
  35. package/runtime/public-assets.mjs +62 -0
  36. package/runtime/source-fence.mjs +182 -0
  37. package/runtime/vite-config.d.mts +2 -1
  38. package/runtime/vite-config.mjs +6 -2
  39. package/runtime/vite-dev.mjs +18 -0
  40. package/runtime/vite-https.mjs +2 -3
  41. package/template-assets/bootstrap/AGENTS.md +56 -14
  42. package/template-assets/bootstrap/CLAUDE.md +0 -8
  43. package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +44 -0
  44. package/template-assets/bootstrap/skills/controller-ui/SKILL.md +2 -0
  45. package/template-assets/bootstrap/skills/game-architecture/SKILL.md +47 -3
  46. package/template-assets/bootstrap/skills/index.md +1 -1
  47. package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +10 -0
  48. package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +10 -0
  49. package/template-assets/documentation/for-agents/controller-ui/page.mdx +41 -2
  50. package/template-assets/documentation/for-agents/page.mdx +24 -2
  51. package/template-assets/documentation/for-agents/project-structure/page.mdx +0 -2
  52. package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +0 -2
  53. package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
  54. package/template-assets/documentation/getting-started/debugging/page.mdx +7 -8
  55. package/template-assets/documentation/getting-started/dev-logs/page.mdx +0 -2
  56. package/template-assets/documentation/getting-started/game-ideas/page.mdx +1 -3
  57. package/template-assets/documentation/getting-started/introduction/page.mdx +71 -54
  58. package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +308 -62
  59. package/template-assets/documentation/getting-started/quick-start/page.mdx +56 -79
  60. package/template-assets/documentation/how-it-works/architecture/page.mdx +91 -50
  61. package/template-assets/documentation/how-it-works/host-system/page.mdx +112 -109
  62. package/template-assets/documentation/manifest.json +112 -42
  63. package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
  64. package/template-assets/documentation/sdk/hooks/page.mdx +106 -171
  65. package/template-assets/documentation/sdk/input-system/page.mdx +201 -231
  66. package/template-assets/documentation/sdk/networked-state/page.mdx +134 -52
  67. package/template-assets/documentation/sdk/settings/page.mdx +155 -0
  68. package/template-assets/documentation/sdk/ui-components/page.mdx +45 -4
  69. package/template-assets/managed/.airjam/ai-pack.json +61 -43
  70. package/template-assets/managed/docs/airjam/agent-gold-path.md +55 -7
  71. package/template-assets/managed/docs/airjam/agent-mcp.md +44 -0
  72. package/template-assets/managed/docs/airjam/debug-and-testing.md +18 -0
  73. package/template-assets/managed/docs/airjam/docs-index.md +18 -12
  74. package/template-assets/managed/docs/airjam/generated/architecture.md +91 -46
  75. package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
  76. package/template-assets/managed/docs/airjam/generated/controller-ui.md +41 -0
  77. package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +7 -6
  78. package/template-assets/managed/docs/airjam/generated/for-agents.md +24 -0
  79. package/template-assets/managed/docs/airjam/generated/game-ideas.md +1 -1
  80. package/template-assets/managed/docs/airjam/generated/host-system.md +112 -102
  81. package/template-assets/managed/docs/airjam/generated/input-system.md +199 -218
  82. package/template-assets/managed/docs/airjam/generated/introduction.md +71 -51
  83. package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +308 -60
  84. package/template-assets/managed/docs/airjam/generated/networked-state.md +134 -50
  85. package/template-assets/managed/docs/airjam/generated/quick-start.md +56 -79
  86. package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +106 -166
  87. package/template-assets/managed/docs/airjam/generated/settings.md +158 -0
  88. package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
  89. package/template-assets/managed/docs/airjam/generated/ui-components.md +45 -2
  90. package/template-assets/managed/docs/airjam/prefab-authoring.md +100 -0
  91. package/template-assets/managed/docs/airjam/preview-controllers.md +4 -1
  92. package/template-assets/managed/docs/airjam/r3f-3d-scene.md +66 -0
  93. package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +15 -20
  94. package/dist/chunk-A4V2N4LX.js.map +0 -1
@@ -0,0 +1,188 @@
1
+ <!-- Generated from content/docs/sdk/assets-and-theme/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/sdk/assets-and-theme -->
3
+
4
+ # Game Assets and Theme
5
+
6
+ Declare a game's sounds, images, other loaded files, colours and fonts in its
7
+ React-free game declaration. Tools read them through `airjam.inspect_game` in
8
+ `declaration.assets` and `declaration.theme`.
9
+
10
+ ## Declare loaded files
11
+
12
+ Keep the assets in a leaf module so rendering and audio code can import them
13
+ without importing the config back again.
14
+
15
+ ```ts filename="src/game/assets.ts"
16
+ import { defineAirJamAssets } from "@air-jam/sdk/core";
17
+
18
+ export const gameAssets = defineAirJamAssets({
19
+ sounds: {
20
+ hit: { src: ["/sounds/hit.wav"], volume: 0.55 },
21
+ music: {
22
+ src: ["/music/theme.mp3"],
23
+ category: "music",
24
+ html5: true,
25
+ surface: "host",
26
+ },
27
+ },
28
+ images: { player: { src: "/images/player.png" } },
29
+ files: { animation: { src: "/animations/fire.json" } },
30
+ });
31
+ ```
32
+
33
+ Pass it as `defineAirJamGame({ assets: gameAssets, ... })`. Every source is a
34
+ served path under the game's `public/` directory: it starts with `/` and has no
35
+ parent segments, query or hash. A sound takes a nonempty `src` array and optional
36
+ `volume` (0 to 1), `loop`, `html5`, `sprite` and `category` (`music` or `sfx`).
37
+ A sprite maps its name to `[offsetMilliseconds, durationMilliseconds]`.
38
+ `surface` selects `host` or `controller`; omitting it makes the sound available
39
+ on both. Images and files each take `{ src }`.
40
+
41
+ The React binding mounts audio for each surface automatically. Remove your
42
+ own `<AudioRuntime>` wrappers. Existing `useAudio` calls and `MusicPlaylist`
43
+ components use the binding's runtime. Host-only music never loads on a phone.
44
+ Read image and file paths from the object, for example
45
+ `gameAssets.images.player.src`, rather than repeating URL strings.
46
+
47
+ Inspection checks every declared source exists and fails with
48
+ `AJ_ASSET_MISSING`, naming the game, entry and missing path. This checks file
49
+ presence, not whether code loads an undeclared URL. Arcade cover, thumbnail and
50
+ preview media remain outside this declaration.
51
+
52
+ ## Declare colours and fonts
53
+
54
+ ```ts filename="src/game/theme.ts"
55
+ import { defineAirJamTheme } from "@air-jam/sdk/core";
56
+
57
+ export const gameTheme = defineAirJamTheme({
58
+ colors: { background: "#050816", team1: "#f97316", team2: "#38bdf8" },
59
+ fonts: { display: '"Avenir Next", "Trebuchet MS", sans-serif' },
60
+ });
61
+ ```
62
+
63
+ Pass it as `defineAirJamGame({ theme: gameTheme, ... })`. Keys are lower camel
64
+ case. Colours use hex, `rgb()`, `rgba()`, `hsl()` or `oklch()`; fonts are CSS
65
+ font-family lists. Font files still load through your existing CSS imports or
66
+ declared file paths.
67
+
68
+ The binding renders a `<style>` with each surface on its first render. It
69
+ exposes `--airjam-color-background`, `--airjam-color-team1` and
70
+ `--airjam-font-display`; camel case keys become kebab case. No generation step
71
+ or effect is needed. Map the variables to existing Tailwind names:
72
+
73
+ ```css filename="src/index.css"
74
+ @import "tailwindcss";
75
+
76
+ @theme inline {
77
+ --color-game-bg: var(--airjam-color-background);
78
+ --color-game-orange: var(--airjam-color-team1);
79
+ --font-game: var(--airjam-font-display);
80
+ }
81
+ ```
82
+
83
+ Existing classes such as `bg-game-bg` keep their names. Canvas and 3D code read
84
+ `gameTheme.colors.team1` and `gameTheme.fonts.display` directly. Remove the
85
+ literals they replace. Shadows, gradients and layout remain handwritten CSS.
86
+
87
+ Both fields are optional; an omitted field is described as empty maps.
88
+ The declaration graph must remain free of React, the DOM and CSS imports.
89
+
90
+ ## Isolated assets and states
91
+
92
+ Prefabs are the catalog identity. Declare `space` and, for animated assets, named
93
+ `states`. `space` is optional: it defaults to `"3d"` when `preview.camera` is set,
94
+ otherwise `"2d"`. A rendered `PrefabDefinition` requires `render`; a renderer-free
95
+ `PrefabDeclaration` omits it. Omitting states creates one static state (`static`). State time is in
96
+ seconds; the SDK owns playback and seeking, while the game draws that exact time.
97
+ A state without `seconds` is a static pose. `loop: true` wraps a timed state;
98
+ otherwise it pauses at the end.
99
+
100
+ ```ts filename="src/airjam.config.ts"
101
+ import { defineAirJamGame } from "@air-jam/sdk/core";
102
+ import { createPrefabCatalog, definePrefab } from "@air-jam/sdk/prefabs";
103
+ import { z } from "zod";
104
+
105
+ export const dotProps = z.object({ radius: z.number().positive() });
106
+ export const dot = definePrefab({
107
+ id: "dot",
108
+ label: "Dot",
109
+ category: "effect",
110
+ description: "Pulsing circle",
111
+ tags: ["effect"],
112
+ space: "2d",
113
+ configSchema: dotProps,
114
+ defaultProps: { radius: 40 },
115
+ states: [{ id: "pulse", label: "Pulse", seconds: 1, loop: true }],
116
+ });
117
+ // Add to your existing definition, retaining its metadata and other declarations:
118
+ export const game = defineAirJamGame({
119
+ metadata,
120
+ prefabs: createPrefabCatalog([dot]),
121
+ });
122
+ ```
123
+
124
+ Keep this declaration module free of React and renderer imports. In the host
125
+ application, the stage selects the renderer for the declared prefab:
126
+
127
+ ```tsx filename="src/prefab-stage.tsx"
128
+ import {
129
+ createAirJamApp,
130
+ drawAgentCanvas,
131
+ useHostAgentCapture,
132
+ usePrefabInspection,
133
+ } from "@air-jam/sdk";
134
+ import { resolvePrefab2DTransform } from "@air-jam/sdk/prefabs";
135
+ import { useLayoutEffect, useRef } from "react";
136
+ import { dot, dotProps, game } from "./airjam.config";
137
+
138
+ function Stage() {
139
+ const canvas = useRef<HTMLCanvasElement>(null);
140
+ const { prefab, props, time, view } = usePrefabInspection();
141
+ if (prefab.id !== dot.id) throw new Error(`Unknown prefab: ${prefab.id}`);
142
+ const { radius } = dotProps.parse(props);
143
+ useHostAgentCapture((image, options) =>
144
+ drawAgentCanvas(canvas.current, image, options),
145
+ );
146
+ useLayoutEffect(() => {
147
+ const context = canvas.current?.getContext("2d");
148
+ if (!context) return;
149
+ const { scale, translate } = resolvePrefab2DTransform(view, 512);
150
+ context.resetTransform();
151
+ context.clearRect(0, 0, 512, 512);
152
+ context.translate(256 + translate[0], 256 + translate[1]);
153
+ context.scale(scale, scale);
154
+ context.beginPath();
155
+ context.arc(
156
+ 0,
157
+ 0,
158
+ radius * (1 + 0.2 * Math.sin(time * Math.PI * 2)),
159
+ 0,
160
+ Math.PI * 2,
161
+ );
162
+ context.fillStyle = "#ff6a35";
163
+ context.fill();
164
+ }, [radius, time, view]);
165
+ return <canvas ref={canvas} width={512} height={512} />;
166
+ }
167
+ const app = createAirJamApp(game);
168
+ // In the existing host route (LiveGame is your game's live component):
169
+ <app.Host prefabStage={Stage}>
170
+ <LiveGame />
171
+ </app.Host>;
172
+ ```
173
+
174
+ For R3F, use `resolvePrefabOrbitCamera(prefab.preview?.camera, view)` and apply its
175
+ `position`, `target` and `fov` to the game's camera. Capture through
176
+ `useHostAgentCapture`: render the R3F scene immediately before copying `gl.domElement`
177
+ with `drawAgentCanvas`, because WebGL drawing buffers need not survive a frame.
178
+ The helper has no Three dependency. Zoom 1 keeps default framing; yaw/pitch use
179
+ degrees relative to the preview camera. Pan uses fractions of view height, right/up
180
+ positive. The 2D helper returns pixel translation and scale around default framing;
181
+ yaw and pitch have no effect in 2D.
182
+
183
+ Open `?airjamInspect=1&prefab=dot&state=pulse&time=0.3` for a paused isolated frame.
184
+ Stages read parsed default props, state, time, playing and view from
185
+ `usePrefabInspection()`. They must draw only that prefab, without reading live room
186
+ stores, starting physics or advancing their own animation clock. The SDK reports
187
+ missing catalogs, missing stages and rendering errors. `@air-jam/sdk/prefab-inspection`
188
+ exports the validated parent client for lists, selection and batch canvas captures.
@@ -9,6 +9,8 @@ The main failure mode is borrowing desktop web-app patterns for active gameplay
9
9
 
10
10
  ## Gameplay Controller Rules
11
11
 
12
+ 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.
13
+
12
14
  For active gameplay:
13
15
 
14
16
  1. use an absolute `inset-0` root
@@ -18,6 +20,35 @@ For active gameplay:
18
20
  5. keep controls visually obvious and single-purpose
19
21
  6. minimize text and dense hierarchy
20
22
 
23
+ ## Sideways Controllers
24
+
25
+ A sideways phone is held like a gamepad, so its controls use the screen like one. Compose them in `GamepadLayout`:
26
+
27
+ 1. the stick goes in `left` and the actions in `right`; both get the same square, so they carry the same weight and mirror each other about the centre, each centred in its thumb zone on one line
28
+ 2. a single action fills its square; several actions share it as one cluster, as phone action games do, rather than starting a third column: the main action sits at the square's centre under the resting thumb at about half the square's width, each other action is about two thirds of the main one's size on a tight arc around its inner side (below, toward the centre, above) with the most used nearest, a rarely used utility goes smaller on the outer side, and every button stays inside the thumb zone
29
+ 3. a button with a cooldown shows it on itself: a dark sweep over the icon that shrinks as it recovers, the seconds left when the wait is over a second, and full colour once it is ready again
30
+ 4. buttons show icons, not words, drawn as one family: the same grid, the same stroke width with round caps and joins (or all filled), the same optical size of about half the button, one simple silhouette each and no detail finer than the stroke; judge them at real size on a phone
31
+ 5. `center` holds only what a player reads at a glance: a round, a number, a word, a few icons; it never wraps into squeezed lines
32
+ 6. a longer message goes in the header bar above the layout, or stays on the TV
33
+
34
+ ```tsx
35
+ import { ControlButton, GamepadLayout, Stick } from "@air-jam/sdk/ui";
36
+
37
+ // Before: a big stick, a small button pushed to the edge, a sentence wrapping between them.
38
+ <div className="flex h-full items-center justify-between px-6">
39
+ <Stick control={gameInput.move} className="size-56" />
40
+ <p className="max-w-48 text-2xl">Splash! Back next round</p>
41
+ <ControlButton control={gameInput.dash} className="size-28">Dash</ControlButton>
42
+ </div>
43
+
44
+ // After: equal mirrored thumbs, a glanceable centre, the sentence in the header.
45
+ <GamepadLayout
46
+ left={<Stick control={gameInput.move} className="rounded-full bg-white/10" />}
47
+ center={<span className="text-xs uppercase">Round 1</span>}
48
+ right={<ControlButton control={gameInput.dash} className="rounded-full bg-sky-400">Dash</ControlButton>}
49
+ />
50
+ ```
51
+
21
52
  ## Lobby Rules
22
53
 
23
54
  Lobby screens can be slightly more flexible, but should still prefer:
@@ -59,3 +90,13 @@ For template and starter work, a practical split is:
59
90
  2. a gameplay-oriented icon set for abilities, pickups, and status effects
60
91
 
61
92
  Keep icon usage behind local wrappers where practical so the project can curate or replace icons later.
93
+
94
+ ## Private player screens and word games
95
+
96
+ Keep secret words or cards in a per-controller map declared with
97
+ `createAirJamStore`'s `privateField`; read that phone's entry with
98
+ `useAirJamPrivateState`. The public store excludes this field and each phone
99
+ receives only its own entry. Test a reveal with `studio_press_phone`'s hold action.
100
+
101
+ A decision-model seat (Jev) answers choice questions only. Give model seats authored
102
+ candidate clues or answers as options; people can type freely into phone fields.
@@ -63,7 +63,7 @@ Use the right browser console for the right problem:
63
63
 
64
64
  1. **Host tab** for room creation, host bootstrap, input consumption, and gameplay errors
65
65
  2. **Controller tab/phone remote inspector** for join failures, input publishing, haptics, and controller UI state
66
- 3. **Server terminal** for room lifecycle, socket disconnects, auth/bootstrap problems, and routing issues
66
+ 3. **Server terminal** for room lifecycle, dropped connections, refused hosts and phones
67
67
 
68
68
  Do not debug everything from only one surface.
69
69
 
@@ -95,16 +95,17 @@ pnpm run dev -- --secure
95
95
 
96
96
  Check:
97
97
 
98
- 1. controller is publishing input via `useControllerTick` + `useInputWriter`
99
- 2. host is reading input via `getInput` or `useGetInput`
100
- 3. you are not trying to send per-frame input through store actions
101
- 4. the input schema still matches the payload shape
98
+ 1. the game declares its controls with `defineAirJamGame({ input })`
99
+ 2. the controller renders the SDK's phone controls bound to those controls
100
+ 3. the simulation reads them in its step with `input(playerId)`
101
+ 4. you are not trying to send per-frame input through store actions
102
+ 5. the dev log shows no `AJ_INPUT_INVALID` diagnostic
102
103
 
103
104
  ### Store actions do nothing
104
105
 
105
106
  Check:
106
107
 
107
- 1. actions are dispatched via `useActions()`
108
+ 1. actions are dispatched via `gameStore.actions` and the store is declared in `defineAirJamGame({ stores })`
108
109
  2. payloads are plain serializable objects
109
110
  3. your controller is connected before dispatching
110
111
  4. identity-dependent actions use `ctx.actorId` on the host side
@@ -44,6 +44,8 @@ the server. `mcp doctor` distinguishes project declarations from detected client
44
44
  registrations. Confirm that the connected client discovers Air Jam's tools before
45
45
  treating the connection as working.
46
46
 
47
+ [Supported Agents](./supported-agents.md) lists the clients tested end to end.
48
+
47
49
  ## Operate and Evaluate
48
50
 
49
51
  For gameplay assertions, use `airjam.open_game_session`,
@@ -52,6 +54,12 @@ For gameplay assertions, use `airjam.open_game_session`,
52
54
  do not guess game-specific action IDs. `airjam.capture_game_session_visuals`
53
55
  adds host and phone-controller screenshots to the same session.
54
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
+
55
63
  MCP is optional. A terminal agent can use the same services:
56
64
 
57
65
  ```bash
@@ -73,6 +81,22 @@ The [Quick Start publishing guide](https://airjam.io/docs/getting-started/quick-
73
81
  covers CLI authentication, hosted release submission, inspection, and explicit
74
82
  publication. Local development and evaluation do not require hosted publishing.
75
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
+
76
100
  ## Read These First
77
101
 
78
102
  1. [Introduction](./introduction.md)
@@ -3,7 +3,7 @@
3
3
 
4
4
  # Game Ideas for Air Jam
5
5
 
6
- A collection of game concepts that leverage Air Jam's unique architecture: **High-Frequency Input Streams** (Socket.IO) + **Reliable Shared State** (AirJam Store).
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
7
 
8
8
  ---
9
9
 
@@ -11,9 +11,13 @@ The simplest mode—your game connects directly to the Air Jam server.
11
11
 
12
12
  **Usage:**
13
13
 
14
- ```tsx filename="src/components/HostView.tsx"
15
- import { useAirJamHost } from "@air-jam/sdk";
16
- import { airjam } from "../airjam.config";
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
+ });
17
21
 
18
22
  const HostShell = () => (
19
23
  <airjam.Host
@@ -24,21 +28,14 @@ const HostShell = () => (
24
28
  </airjam.Host>
25
29
  );
26
30
 
27
- const HostView = () => {
28
- const host = useAirJamHost();
29
-
30
- // Host receives all input directly
31
- useFrame(() => {
32
- host.players.forEach((p) => {
33
- const input = host.getInput(p.id);
34
- processInput(p.id, input);
35
- });
36
- });
37
-
38
- return <GameCanvas />;
39
- };
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 />;
40
34
  ```
41
35
 
36
+ `createAirJamApp` binds the game declaration from `src/airjam.config.ts` to the
37
+ browser and returns `Host`, `Controller` and `paths`.
38
+
42
39
  ### Arcade Mode (Outer App + Embedded Game)
43
40
 
44
41
  In arcade mode, the platform runs the outer Arcade app and your game runs as an embedded Air Jam host inside an iframe.
@@ -47,100 +44,108 @@ The important rule is:
47
44
 
48
45
  1. Arcade owns platform surface state
49
46
  2. your game owns gameplay state
50
- 3. the server owns room membership, focus routing, and runtime invariants
47
+ 3. the room owns membership, seats and the latest copy of every channel
51
48
 
52
- ## Server-Authoritative Focus System
49
+ ## One Room, Served to Each Frame
53
50
 
54
- The server maintains authoritative control over which host receives controller inputs through a **focus** state:
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
55
 
56
- ### Why Server-Authoritative?
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
57
64
 
58
- 1. **Security** - Prevents rogue games from stealing input
59
- 2. **Reliability** - Single source of truth for focus state
60
- 3. **Consistency** - All controllers route to same host
61
-
62
- This focus system does not replace the normal Air Jam model. It only decides which host currently receives controller input. Your game still uses the normal input lane, replicated state lane, and signal lane.
65
+ Your game uses the normal input lane, replicated state lane and signal lane, as
66
+ it would standalone.
63
67
 
64
68
  ### 1. Arcade Launch
65
69
 
66
70
  ```
67
- [Platform] [Server] [Controller]
71
+ [Arcade shell] [Room] [Phone]
68
72
  │ │ │
69
- │ host:createRoom │ │
70
- │ { maxPlayers: 8 } │ │
73
+ │ hello (host key, seats) │ │
71
74
  │ ───────────────────────────▶│ │
72
75
  │ │ │
73
- │ ack: { ok, roomId: "ABCD" } │ │
76
+ │ welcome { code: "ABCD" } │ │
74
77
  │ ◀───────────────────────────│ │
75
78
  │ │ │
76
79
  │ Display QR Code │ │
77
80
  │ with room code │ Scan QR Code │
78
81
  │ │ ◀──────────────────────────│
79
82
  │ │ │
80
- │ │ controller:join │
83
+ │ │ hello (phone key) │
81
84
  │ │ ◀──────────────────────────│
82
85
  │ │ │
83
- │ server:controllerJoined │ server:welcome │
86
+ │ seats [p1] │ welcome { seat: p1 } │
84
87
  │ ◀───────────────────────────│ ──────────────────────────▶│
85
88
  ```
86
89
 
87
90
  ### 2. Game Launch
88
91
 
89
92
  ```
90
- [Arcade] [Server] [Your Game] [Controller]
91
- │ │ │ │
92
- │ system:launchGame │ │ │
93
- │ ───────────────────▶│ │ │
94
- │ │ │ │
95
- │ ack: { launchCapability } │ │ │
96
- │ ◀────────────────── │ │ │
97
- │ │ │ │
98
- │ Load iframe ───────────────────────────────▶│ │
99
- │ │ │ │
100
- │ │ host:joinAsChild │ │
101
- │ │◀───────────────────── │ │
102
- │ │ │ │
103
- │ │ Focus → GAME │ │
104
- │ │ │ │
105
- │ │ Redirect controller │ │
106
- │ │ ─────────────────────────────────────────▶│
107
- │ │ │ │
108
- │ │ │ Load game UI │
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 │
109
106
  ```
110
107
 
111
108
  ### 3. Active Gameplay
112
109
 
113
- With focus set to `GAME`, all controller input routes to your game:
110
+ While the game shows, every seat's input reaches your game:
114
111
 
115
- ```tsx
116
- // Your game receives input normally inside the mounted host runtime.
117
- const host = useAirJamHost();
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
118
 
119
- useFrame(() => {
120
- host.players.forEach((player) => {
121
- const input = host.getInput(player.id);
122
- // Process gameplay...
123
- });
124
- });
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
+ },
125
132
  ```
126
133
 
134
+ Outside the simulation, `getReconnectingPlayerIds(players)` from
135
+ `@air-jam/sdk/core` gives the same list from `useAirJamHost()` state.
136
+
127
137
  ### 4. Game Exit
128
138
 
129
139
  ```
130
- [Your Game] [Server] [Arcade] [Controller]
131
- │ │ │ │
132
- │ host:exit │ │ │
133
- │ ───────────────────▶│ │ │
134
- │ │ │ │
135
- │ │ Focus → SYSTEM │ │
136
- │ │ │ │
137
- │ │ server:gameEnded │ │
138
- │ │ ─────────────────────▶│ │
139
- │ │ │ │
140
- │ Destroy iframe ◀────────────── │ │
141
- │ │ │ │
142
- │ │ Restore arcade UI │ │
143
- │ │ ─────────────────────────────────────────▶│
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 │
144
149
  ```
145
150
 
146
151
  ### Standalone Mode
@@ -156,23 +161,26 @@ const host = useAirJamHost();
156
161
  // host.joinUrl contains full URL for QR code
157
162
  ```
158
163
 
159
- Production bootstrap remains automatic here:
164
+ Opening the room stays automatic:
160
165
 
161
- 1. local dev: no auth ceremony
162
- 2. static deploy: SDK bootstraps with your `appId`
163
- 3. optional signed mode: SDK fetches a host grant from `hostGrantEndpoint` before bootstrap
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
164
172
 
165
173
  Game code does not change between those modes.
166
174
 
167
175
  ### Embedded Game Mode (Arcade)
168
176
 
169
177
  ```tsx
170
- // SDK auto-detects embedded runtime context from platform-injected params.
171
- // Game code should not parse those params directly.
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.
172
180
  const host = useAirJamHost();
173
181
 
174
- // Embedded close/lifecycle handling is owned by the arcade platform adapter.
175
- // Game hosts should keep gameplay logic in host callbacks/input loops only.
182
+ // Closing and switching games belong to the Arcade.
183
+ // Game hosts keep gameplay logic in host callbacks and simulation steps.
176
184
  ```
177
185
 
178
186
  ### Player Lifecycle
@@ -181,10 +189,12 @@ const host = useAirJamHost();
181
189
  const HostShell = () => (
182
190
  <airjam.Host
183
191
  onPlayerJoin={(player) => {
184
- // player.id - Unique identifier
185
- // player.label - Display name ("Player 1", etc.)
192
+ // player.id - The seat the room gave ("p1", "p2", …)
193
+ // player.label - Display name ("Player 1", or the name they chose)
186
194
  // player.color - Assigned color ("#FF5733")
187
- // player.nickname - Optional custom name
195
+ // player.kind - "phone", "preview" or "agent"
196
+ // player.connected - false while the phone is away
197
+ // player.avatarId - Optional chosen avatar
188
198
  spawnPlayerEntity(player);
189
199
  announceJoin(player.label);
190
200
  }}
@@ -214,21 +224,19 @@ const player = host.players.find((p) => p.id === targetId);
214
224
 
215
225
  ## Controller Presentation State
216
226
 
217
- Use `sendState` for lightweight controller presentation metadata, not
218
- authoritative gameplay sync. Networked stores should own the real multiplayer
219
- state; this path is for controller-facing hints such as orientation, pause/play
220
- status, and short messages.
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.
221
233
 
222
234
  ```tsx
223
- // Update controller presentation
224
- host.sendState({
225
- runtimeState: "playing", // "playing" | "paused"
226
- orientation: "landscape", // "portrait" | "landscape"
227
- message: "Round 3 - Fight!",
228
- });
235
+ const host = useAirJamHost();
236
+ host.pauseRuntime();
237
+ host.resumeRuntime();
229
238
 
230
- // Controllers receive via onState callback
231
- // or controller.runtimeState / controller.controllerOrientation / controller.stateMessage
239
+ // Controllers read controller.runtimeState and controller.controllerOrientation
232
240
  ```
233
241
 
234
242
  ## Error Handling
@@ -236,16 +244,18 @@ host.sendState({
236
244
  ```tsx
237
245
  const host = useAirJamHost();
238
246
 
239
- // Check connection
240
- if (host.connectionStatus === "disconnected") {
247
+ // Reconnecting is automatic; show it while it happens
248
+ if (host.connectionStatus === "reconnecting") {
241
249
  showReconnectUI();
242
250
  }
243
251
 
252
+ // A busy hosted service queues new rooms
253
+ if (host.queuePosition !== null) {
254
+ showQueue(host.queuePosition);
255
+ }
256
+
244
257
  // Check for errors
245
258
  if (host.lastError) {
246
259
  showError(host.lastError);
247
260
  }
248
-
249
- // Force reconnection
250
- host.reconnect();
251
261
  ```