@air-jam/cli 0.9.3 → 1.0.0-beta.10

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 (99) 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/dist/scaffold.d.ts +8 -1
  34. package/dist/scaffold.js +6 -1
  35. package/dist/scaffold.js.map +1 -1
  36. package/package.json +8 -4
  37. package/runtime/local-network.d.mts +4 -6
  38. package/runtime/public-assets.mjs +62 -0
  39. package/runtime/source-fence.mjs +182 -0
  40. package/runtime/vite-config.d.mts +2 -1
  41. package/runtime/vite-config.mjs +6 -2
  42. package/runtime/vite-dev.mjs +18 -0
  43. package/runtime/vite-https.mjs +2 -3
  44. package/template-assets/bootstrap/AGENTS.md +56 -14
  45. package/template-assets/bootstrap/CLAUDE.md +0 -8
  46. package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +44 -0
  47. package/template-assets/bootstrap/skills/controller-ui/SKILL.md +2 -0
  48. package/template-assets/bootstrap/skills/game-architecture/SKILL.md +47 -3
  49. package/template-assets/bootstrap/skills/index.md +1 -1
  50. package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +10 -0
  51. package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +10 -0
  52. package/template-assets/documentation/for-agents/controller-ui/page.mdx +41 -2
  53. package/template-assets/documentation/for-agents/page.mdx +24 -2
  54. package/template-assets/documentation/for-agents/project-structure/page.mdx +0 -2
  55. package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +19 -2
  56. package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
  57. package/template-assets/documentation/getting-started/debugging/page.mdx +7 -8
  58. package/template-assets/documentation/getting-started/dev-logs/page.mdx +0 -2
  59. package/template-assets/documentation/getting-started/game-ideas/page.mdx +1 -3
  60. package/template-assets/documentation/getting-started/introduction/page.mdx +71 -54
  61. package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +308 -62
  62. package/template-assets/documentation/getting-started/quick-start/page.mdx +56 -79
  63. package/template-assets/documentation/how-it-works/architecture/page.mdx +91 -50
  64. package/template-assets/documentation/how-it-works/host-system/page.mdx +112 -109
  65. package/template-assets/documentation/manifest.json +112 -42
  66. package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
  67. package/template-assets/documentation/sdk/hooks/page.mdx +108 -172
  68. package/template-assets/documentation/sdk/input-system/page.mdx +201 -231
  69. package/template-assets/documentation/sdk/networked-state/page.mdx +134 -52
  70. package/template-assets/documentation/sdk/settings/page.mdx +166 -0
  71. package/template-assets/documentation/sdk/ui-components/page.mdx +38 -27
  72. package/template-assets/managed/.airjam/ai-pack.json +65 -47
  73. package/template-assets/managed/docs/airjam/agent-gold-path.md +55 -7
  74. package/template-assets/managed/docs/airjam/agent-mcp.md +44 -0
  75. package/template-assets/managed/docs/airjam/composition-shell-contract.md +4 -0
  76. package/template-assets/managed/docs/airjam/debug-and-testing.md +18 -0
  77. package/template-assets/managed/docs/airjam/docs-index.md +18 -12
  78. package/template-assets/managed/docs/airjam/generated/architecture.md +91 -46
  79. package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
  80. package/template-assets/managed/docs/airjam/generated/controller-ui.md +41 -0
  81. package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +7 -6
  82. package/template-assets/managed/docs/airjam/generated/for-agents.md +24 -0
  83. package/template-assets/managed/docs/airjam/generated/game-ideas.md +1 -1
  84. package/template-assets/managed/docs/airjam/generated/host-system.md +112 -102
  85. package/template-assets/managed/docs/airjam/generated/input-system.md +199 -218
  86. package/template-assets/managed/docs/airjam/generated/introduction.md +71 -51
  87. package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +308 -60
  88. package/template-assets/managed/docs/airjam/generated/networked-state.md +134 -50
  89. package/template-assets/managed/docs/airjam/generated/quick-start.md +56 -79
  90. package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +108 -167
  91. package/template-assets/managed/docs/airjam/generated/settings.md +169 -0
  92. package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +19 -0
  93. package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
  94. package/template-assets/managed/docs/airjam/generated/ui-components.md +38 -25
  95. package/template-assets/managed/docs/airjam/prefab-authoring.md +100 -0
  96. package/template-assets/managed/docs/airjam/preview-controllers.md +5 -2
  97. package/template-assets/managed/docs/airjam/r3f-3d-scene.md +66 -0
  98. package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +15 -20
  99. package/dist/chunk-A4V2N4LX.js.map +0 -1
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  # Networked State
4
2
 
5
3
  `createAirJamStore` is the canonical shared-state lane for Air Jam:
@@ -10,17 +8,63 @@
10
8
 
11
9
  Use this lane for replicated game state, not per-frame input.
12
10
 
11
+ A store is a plain object from `@air-jam/sdk/core`, so game logic can use it
12
+ without React. Components read it with `useAirJamStore`.
13
+
14
+ ## Private per-player state
15
+
16
+ A store can declare one `privateField`: a map keyed by `controllerId`. Use it for
17
+ hidden hands, roles or shopping lists. The host keeps every entry. The room's
18
+ public state broadcast never contains this field; each phone receives only its
19
+ own entry through targeted delivery, including after a reconnect.
20
+
21
+ ```tsx
22
+ import { createAirJamStore } from "@air-jam/sdk/core";
23
+ import { useAirJamPrivateState } from "@air-jam/sdk";
24
+
25
+ type MarketState = {
26
+ round: number;
27
+ secrets: Record<string, { shoppingList: string[] }>;
28
+ actions: {};
29
+ };
30
+
31
+ const marketStore = createAirJamStore<MarketState, "secrets">(
32
+ () => ({ round: 1, secrets: {}, actions: {} }),
33
+ { privateField: "secrets" },
34
+ );
35
+
36
+ function ShoppingList() {
37
+ const ownEntry = useAirJamPrivateState(marketStore);
38
+ return <p>{ownEntry?.shoppingList.join(", ") ?? "Waiting for your list"}</p>;
39
+ }
40
+ ```
41
+
42
+ When supplying an explicit state type, name the private field as the second type
43
+ argument so the hook infers that entry even when the store has other maps.
44
+ Declare this store in the game just like a public store. The hook returns
45
+ `undefined` until this controller's entry arrives, and when the host removes it.
46
+ Host actions update the map normally. Only changed entries are sent; public-only
47
+ changes do not resend private data. Embedded controllers use the same private
48
+ lane through their MessagePort bridge.
49
+
50
+ Agent `projectSnapshot` receives the public fields and a private map containing
51
+ only the requested controller's entry (an empty map without a controller).
52
+ Host-authority `rawStores` and host restore retain the whole map. Keep private
53
+ values out of other public fields and explicitly author any end-of-round reveal.
54
+ Private state derives from the replicated store, so headless runs and replays use
55
+ the same authoritative state; it is not a separate RPC or an encrypted channel.
56
+
13
57
  ## Canonical Action Model
14
58
 
15
59
  Actions always use this shape on the host:
16
60
 
17
- 1. First argument: `ctx` (identity and role)
61
+ 1. First argument: `ctx` (identity, role, connected players and game time `now`)
18
62
  2. Second argument: `payload` (either `undefined` or one typed plain-object payload)
19
63
 
20
- Controller-side dispatch always uses:
64
+ Dispatch always goes through the store's `actions`:
21
65
 
22
- 1. `const actions = useGameStore.useActions()`
23
- 2. `actions.someAction()` or `actions.someAction({ ...payload })`
66
+ 1. `gameStore.actions.someAction()`
67
+ 2. `gameStore.actions.someAction({ ...payload })`
24
68
 
25
69
  No trailing `controllerId` arguments and no multi-argument action payloads.
26
70
  No primitive, array, or event-like root payloads.
@@ -31,7 +75,7 @@ This example uses a starter-friendly `stores/` folder shape.
31
75
  The important contract is the action model and ownership boundary, not the exact filename.
32
76
 
33
77
  ```tsx filename="src/game/stores/game-store.ts"
34
- import { createAirJamStore } from "@air-jam/sdk";
78
+ import { createAirJamStore, type AirJamActionContext } from "@air-jam/sdk/core";
35
79
 
36
80
  type Team = "team1" | "team2";
37
81
 
@@ -40,22 +84,16 @@ interface GameState {
40
84
  teamAssignments: Record<string, Team>;
41
85
  scores: { team1: number; team2: number };
42
86
  actions: {
43
- joinTeam: (
44
- ctx: { actorId: string; role: "controller" | "host" },
45
- payload: { team: Team },
46
- ) => void;
47
- scorePoint: (
48
- _ctx: { actorId: string; role: "controller" | "host" },
49
- payload: { team: Team },
50
- ) => void;
87
+ joinTeam: (ctx: AirJamActionContext, payload: { team: Team }) => void;
88
+ scorePoint: (ctx: AirJamActionContext, payload: { team: Team }) => void;
51
89
  setPhase: (
52
- _ctx: { actorId: string; role: "controller" | "host" },
90
+ ctx: AirJamActionContext,
53
91
  payload: { phase: "lobby" | "playing" },
54
92
  ) => void;
55
93
  };
56
94
  }
57
95
 
58
- export const useGameStore = createAirJamStore<GameState>((set) => ({
96
+ export const gameStore = createAirJamStore<GameState>((set) => ({
59
97
  phase: "lobby",
60
98
  teamAssignments: {},
61
99
  scores: { team1: 0, team2: 0 },
@@ -79,19 +117,51 @@ export const useGameStore = createAirJamStore<GameState>((set) => ({
79
117
  }));
80
118
  ```
81
119
 
120
+ ## Declare the Store
121
+
122
+ The host and controllers sync a store only when the app declares it:
123
+
124
+ ```ts filename="src/airjam.config.ts"
125
+ import { defineAirJamGame } from "@air-jam/sdk/core";
126
+ import { gameStore } from "./game/stores/game-store";
127
+
128
+ export const airjam = defineAirJamGame({
129
+ metadata: {
130
+ slug: "space-game",
131
+ name: "Space Game",
132
+ tagline: "Fly together and defend the fleet.",
133
+ category: "arcade",
134
+ minPlayers: 1,
135
+ maxPlayers: 4,
136
+ inputModalities: ["buttons", "touch"],
137
+ supportedSdkRange: "^1.0.0",
138
+ maintainer: { name: "Air Jam" },
139
+ version: 1,
140
+ },
141
+ controllerPath: "/controller",
142
+ stores: [gameStore],
143
+ });
144
+ ```
145
+
146
+ A declared store syncs for as long as the host or controller runs, whether or
147
+ not any component is reading it. Reading a store the app does not declare
148
+ throws `AJ_STORE_NOT_DECLARED`.
149
+
82
150
  ## Use on Controller
83
151
 
84
152
  This controller example matches the starter template surface layout.
85
153
  It assumes your app has already mounted `airjam.Controller`.
86
154
 
87
155
  ```tsx filename="src/controller/index.tsx"
88
- import { useAirJamController } from "@air-jam/sdk";
89
- import { useGameStore } from "../game/stores/game-store";
156
+ import { useAirJamController, useAirJamStore } from "@air-jam/sdk";
157
+ import { gameStore } from "../game/stores/game-store";
90
158
 
91
159
  export const ControllerView = () => {
92
160
  const controller = useAirJamController();
93
- const actions = useGameStore.useActions();
94
- const teamAssignments = useGameStore((state) => state.teamAssignments);
161
+ const teamAssignments = useAirJamStore(
162
+ gameStore,
163
+ (state) => state.teamAssignments,
164
+ );
95
165
 
96
166
  const myTeam = controller.controllerId
97
167
  ? teamAssignments[controller.controllerId]
@@ -100,7 +170,7 @@ export const ControllerView = () => {
100
170
  return (
101
171
  <div>
102
172
  <p>My team: {myTeam ?? "unassigned"}</p>
103
- <button onClick={() => actions.joinTeam({ team: "team1" })}>
173
+ <button onClick={() => gameStore.actions.joinTeam({ team: "team1" })}>
104
174
  Join Team 1
105
175
  </button>
106
176
  </div>
@@ -114,12 +184,12 @@ This host example also matches the starter template surface layout.
114
184
  It assumes your app has already mounted `airjam.Host`.
115
185
 
116
186
  ```tsx filename="src/host/index.tsx"
117
- import { useGameStore } from "../game/stores/game-store";
187
+ import { useAirJamStore } from "@air-jam/sdk";
188
+ import { gameStore } from "../game/stores/game-store";
118
189
 
119
190
  export const HostView = () => {
120
- const phase = useGameStore((state) => state.phase);
121
- const scores = useGameStore((state) => state.scores);
122
- const actions = useGameStore.useActions();
191
+ const phase = useAirJamStore(gameStore, (state) => state.phase);
192
+ const scores = useAirJamStore(gameStore, (state) => state.scores);
123
193
 
124
194
  return (
125
195
  <div>
@@ -127,10 +197,10 @@ export const HostView = () => {
127
197
  <p>
128
198
  {scores.team1} - {scores.team2}
129
199
  </p>
130
- <button onClick={() => actions.setPhase({ phase: "playing" })}>
200
+ <button onClick={() => gameStore.actions.setPhase({ phase: "playing" })}>
131
201
  Start
132
202
  </button>
133
- <button onClick={() => actions.scorePoint({ team: "team1" })}>
203
+ <button onClick={() => gameStore.actions.scorePoint({ team: "team1" })}>
134
204
  Team 1 +1
135
205
  </button>
136
206
  </div>
@@ -141,24 +211,29 @@ export const HostView = () => {
141
211
  ## Action Flow
142
212
 
143
213
  1. Controller calls `actions.someAction()` or `actions.someAction({ ...payload })`.
144
- 2. SDK emits `controller:action_rpc`.
145
- 3. Server validates and injects actor identity from socket ownership.
146
- 4. Host receives `airjam:action_rpc` with `{ actor, payload }`.
147
- 5. Host executes action handler `(ctx, payload)` and updates state.
148
- 6. Host emits `host:state_sync`; controllers receive `airjam:state_sync`.
214
+ 2. The phone's session sends a request on the store's channel.
215
+ 3. The room stamps it with the phone's seat, which becomes `ctx.actorId`.
216
+ 4. Host executes action handler `(ctx, payload)`, updates state and answers.
217
+ 5. Host publishes what changed; the room keeps the latest copy and sends each
218
+ phone the change, with only its own private entry.
219
+ 6. If the phone's connection drops before the answer arrives, the action
220
+ resolves `unconfirmed`: it may or may not have run, and the state the phone
221
+ mirrors shows which.
149
222
 
150
223
  ## Rules
151
224
 
152
225
  1. Keep all networked mutations inside `actions`.
153
- 2. Always dispatch via `useActions()`; do not call `state.actions.*` directly.
226
+ 2. Always dispatch via `store.actions`; do not call `store.getState().actions.*` directly.
154
227
  3. Use one payload object per action for stable evolution.
155
228
  4. Root payloads must be omitted or plain objects.
156
229
  5. `T | undefined` payload unions are not valid roots. If an action has no payload, omit it entirely.
157
230
  6. Nested values must stay RPC-serializable.
158
231
  7. Use `ctx.actorId` for identity-aware actions (team join, ownership, etc.).
159
- 8. `ctx.actorId` is always the dispatcher identity. If host code dispatches through `useActions()`, then `ctx.actorId` is the host.
160
- 9. If the host intentionally needs to run the same semantic player action as controller `X`, use `useStore.asPlayer("X")` instead of inventing a target payload for an actor-owned action.
161
- 10. Keep per-frame gameplay input in `useInputWriter` / `host.getInput`, not in this store.
232
+ 8. `ctx.actorId` is always the dispatcher identity. If host code dispatches through `store.actions`, then `ctx.actorId` is the host.
233
+ 9. Read time as `ctx.now`, never `Date.now()`: it is game time, the simulation's when the game declares one, so headless runs and replays see the same time. Store deadlines in it and let the simulation act on them; phones show what the host writes to the store, such as whole seconds left, because they cannot read the host's clock.
234
+ 10. If the host intentionally needs to run the same semantic player action as controller `X`, use `store.asPlayer("X")` instead of inventing a target payload for an actor-owned action.
235
+ 11. Keep per-frame gameplay input in declared controls, read in simulation steps, not in this store.
236
+ 12. For a host-only side effect of an action, such as a sound, use `useHostActionListener(store, listener)`.
162
237
 
163
238
  ## Accept And Reject Examples
164
239
 
@@ -171,21 +246,24 @@ import {
171
246
  acceptAirJamAction,
172
247
  createAirJamStore,
173
248
  rejectAirJamAction,
174
- } from "@air-jam/sdk";
249
+ } from "@air-jam/sdk/core";
175
250
 
176
- export const useGameStore = createAirJamStore((set) => ({
251
+ export const gameStore = createAirJamStore((set, get) => ({
177
252
  aliveByPlayerId: {} as Record<string, boolean>,
178
253
  cooldownMsByPlayerId: {} as Record<string, number>,
179
254
  actions: {
180
- fire: ({ actorId }) =>
181
- set((state) => {
182
- if (!actorId || state.aliveByPlayerId[actorId] === false) {
183
- return rejectAirJamAction("player_dead", "Dead players cannot fire.");
184
- }
185
-
186
- const cooldownMs = 4500;
187
- return acceptAirJamAction({ cooldownMs });
188
- }),
255
+ fire: ({ actorId }) => {
256
+ if (!actorId || get().aliveByPlayerId[actorId] === false)
257
+ return rejectAirJamAction("player_dead", "Dead players cannot fire.");
258
+ const cooldownMs = 4500;
259
+ set((state) => ({
260
+ cooldownMsByPlayerId: {
261
+ ...state.cooldownMsByPlayerId,
262
+ [actorId]: cooldownMs,
263
+ },
264
+ }));
265
+ return acceptAirJamAction({ cooldownMs });
266
+ },
189
267
  },
190
268
  }));
191
269
  ```
@@ -204,10 +282,14 @@ The SDK/runtime automatically resolves the correct replicated store domain from
204
282
 
205
283
  ## API Summary
206
284
 
207
- `createAirJamStore<T>(initializer)` returns:
285
+ `createAirJamStore<T>(initializer)` from `@air-jam/sdk/core` returns a store to
286
+ declare in `defineAirJamGame({ stores })`. It provides:
287
+
288
+ 1. `actions`, dispatching with `() => Promise` or `(payloadObject) => Promise` signatures.
289
+ 2. `getState()` and `subscribe()` for logic outside React.
290
+ 3. `asPlayer(controllerId)`, a host-only dispatch map for explicit player impersonation of semantic actions.
208
291
 
209
- 1. Zustand-compatible hook for selectors.
210
- 2. `useActions()` dispatch map with `() => void` or `(payloadObject) => void` signatures.
211
- 3. `asPlayer(controllerId)` host-only dispatch map for explicit player impersonation of semantic actions.
292
+ React reads it with `useAirJamStore(store, selector)` and listens to host-applied
293
+ actions with `useHostActionListener(store, listener)`.
212
294
 
213
295
  `T` must include an `actions` object with host handlers `(ctx, payload) => void`, where `payload` is `undefined` or a plain object.
@@ -0,0 +1,166 @@
1
+ # Game Settings
2
+
3
+ Declare the numbers, switches and choices a creator tunes while playtesting in
4
+ `airjam.config.ts`. The host owns their values and revision. A live update takes
5
+ effect between simulation steps and is recorded for exact replay. While a
6
+ simulation declared as a loader is still loading, updates are refused, so a
7
+ replay starts from the settings the simulation was created with.
8
+
9
+ ## Declare settings in core
10
+
11
+ Keep the declaration in a leaf module so the simulation can import its type
12
+ without importing the game config back again.
13
+
14
+ ```ts filename="src/game/contracts/settings.ts"
15
+ import {
16
+ defineAirJamSettings,
17
+ setting,
18
+ type AirJamSettingsValues,
19
+ } from "@air-jam/sdk/core";
20
+
21
+ export const pongSettings = defineAirJamSettings({
22
+ ballSpeed: setting.number({
23
+ default: 360,
24
+ min: 180,
25
+ max: 720,
26
+ step: 10,
27
+ live: true,
28
+ label: "Ball speed",
29
+ unit: "px/s",
30
+ description: "How fast the ball crosses the court.",
31
+ }),
32
+ });
33
+ export type PongSettings = AirJamSettingsValues<typeof pongSettings>;
34
+ ```
35
+
36
+ Pass it as `defineAirJamGame({ settings: pongSettings, ... })`. Remove the
37
+ module constants it replaces. A lobby choice players make, such as
38
+ `pointsToWin`, remains replicated store state.
39
+
40
+ Keys are lower camel case. `setting.number` requires `default`, `min` and
41
+ `max`, with an optional positive `step`; use `step: 1` for whole numbers.
42
+ Steps are multiples of zero. `setting.boolean` requires a boolean `default`.
43
+ `setting.choice` takes a nonempty string tuple in `options` and a `default`
44
+ from that tuple; its value type is the union of those strings.
45
+ Every kind accepts `label`, `description` and `live`, which defaults to false;
46
+ numbers also accept a `unit` shown after the value.
47
+
48
+ The Air Jam platform draws every declared setting in its settings dialog under
49
+ the game's name, on the big screen and on phones, with no settings code in the
50
+ game: a switch for a boolean, segments for a few choices or steps, and a slider
51
+ with its value for a range. A setting that is not `live` waits for the game to
52
+ restart. The screen remembers the values per game and launches the game with
53
+ them next time; a remembered value the game no longer accepts reads as its
54
+ default.
55
+ `defineAirJamSettings` validates defaults immediately. The description returned
56
+ by `airjam.inspect_game` includes these descriptors in `declaration.settings`.
57
+
58
+ ## Read the current values
59
+
60
+ Use the settings type as the fourth simulation type parameter:
61
+
62
+ ```ts
63
+ defineAirJamSimulation<State, Input, Event, PongSettings>({
64
+ stepMs: 1000 / 60,
65
+ create: ({ settings }) => createState(settings.ballSpeed),
66
+ step: (state, { settings, stepMs }) => {
67
+ state.x += (settings.ballSpeed * stepMs) / 1000;
68
+ },
69
+ observe: (state, { settings }) => ({
70
+ x: state.x,
71
+ ballSpeed: settings.ballSpeed,
72
+ }),
73
+ });
74
+ ```
75
+
76
+ Store actions read the same values through
77
+ `AirJamActionContext<PongSettings>.settings`. Host rendering calls
78
+ `useAirJamSettings(pongSettings)` from `@air-jam/sdk`; the hook subscribes to
79
+ the host runtime and returns the typed values. Controllers have no settings
80
+ hook. Copy any value a phone must display into replicated store state.
81
+
82
+ ## Set initial values and tune a live room
83
+
84
+ `HostRuntimeOptions.settings` accepts a partial set of initial values and fills
85
+ the rest from defaults. `airjam.start_game_run` accepts the same `settings`
86
+ object when creating a new room, for browser and headless runs. Initial values
87
+ may include non-live settings. They are fixed for the host's lifetime.
88
+
89
+ Open a game session with host authority, then call:
90
+
91
+ ```json
92
+ {
93
+ "tool": "airjam.read_game_settings",
94
+ "arguments": { "gameSessionId": "<session id>" }
95
+ }
96
+ ```
97
+
98
+ The result contains `values` and `revision`, initially zero. Update using that
99
+ revision:
100
+
101
+ ```json
102
+ {
103
+ "tool": "airjam.update_game_settings",
104
+ "arguments": {
105
+ "gameSessionId": "<session id>",
106
+ "patch": { "ballSpeed": 700 },
107
+ "expectedRevision": 0
108
+ }
109
+ }
110
+ ```
111
+
112
+ A successful update returns the complete values and the next revision. The
113
+ whole patch is validated before any value changes. Both tools have the same
114
+ host authority requirements as semantic host actions. The runtime contract is
115
+ `settings-read` with `{ roomId, runtimeId }`, and `settings-update` with those
116
+ fields plus `patch` and `expectedRevision`.
117
+
118
+ The CLI uses the same operations:
119
+
120
+ ```bash
121
+ pnpm exec airjam session settings-read <session-id>
122
+ pnpm exec airjam session settings-update <session-id> --patch '{"ballSpeed":700}' --expected-revision 0
123
+ ```
124
+
125
+ Both commands print JSON. Use `airjam run start --settings '{"ballSpeed":600}'` with the other required
126
+ run options to start a fresh room at a chosen speed. Attaching a run to an
127
+ existing room does not replace its initial settings.
128
+
129
+ ## Errors and replay
130
+
131
+ `AJ_SETTING_UNKNOWN` names an undeclared key. `AJ_SETTING_INVALID` means a
132
+ value violates its type, range, step or choices. `AJ_SETTING_STALE` means
133
+ another update changed the revision; read again before applying a new patch.
134
+ `AJ_SETTING_NOT_LIVE` means the setting requires a new room with that initial
135
+ value. Rejected updates leave all values and the revision unchanged.
136
+
137
+ Input logs use `version: 3`, with resolved initial `settings` and ordered
138
+ `settings` events containing each accepted `patch` and `revision`.
139
+ They share the stream with inputs and actions. `replayAirJamInputLog` creates
140
+ the host with the initial values and applies each update in order before its
141
+ recorded step. Use the same seed and game code to reproduce the final state.
142
+
143
+ ## Keeping a value
144
+
145
+ A live change lasts for the current room. To make a chosen value the default for
146
+ future rooms and test runs, keep it in the game's declaration:
147
+
148
+ ```bash
149
+ pnpm exec airjam game settings keep --set ballSpeed=400 --json
150
+ ```
151
+
152
+ Use `--dir <game>` from another directory, and repeat `--set` for several values.
153
+ The command requires the game's own `typescript` dependency and rewrites only
154
+ literal `default:` values in the selected `defineAirJamSettings({...})`, even
155
+ when it is imported from another game module. Imported settings must resolve to
156
+ one `const` directly initialized by `defineAirJamSettings`; named and default
157
+ exports and explicit re-export aliases are resolved to that binding. Mutable or
158
+ ambiguous bindings are refused. The config must export the `defineAirJamGame`
159
+ binding as `airjam`, so an unused game declaration is never selected. Comments
160
+ and formatting stay in
161
+ place; the declaration remains the only source of defaults. Commit the change
162
+ as ordinary game source. Shared or computed defaults, ambiguous declarations,
163
+ unknown keys and values outside their declared type, range, step or options are
164
+ refused before writing. The JSON result names the file and each `{ key, from,
165
+ to }`; equal values write nothing. Studio's Keep operation uses this same
166
+ transform and captures the source change in history.
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  # SDK UI Components
4
2
 
5
3
  `@air-jam/sdk` is headless by default. `@air-jam/sdk/ui` provides optional, composable UI primitives you can drop into your own game layout.
@@ -9,7 +7,6 @@ import {
9
7
  SurfaceViewport,
10
8
  PlayerAvatar,
11
9
  RoomQrCode,
12
- VolumeControls,
13
10
  Button,
14
11
  Slider,
15
12
  } from "@air-jam/sdk/ui";
@@ -19,7 +16,7 @@ import {
19
16
 
20
17
  ### `RoomQrCode`
21
18
 
22
- Render a room join QR code from any URL string.
19
+ Render a phone join QR code from `host.joinUrl`. An absent or loopback URL shows a short explanation instead of a QR code.
23
20
 
24
21
  ```tsx
25
22
  import { RoomQrCode } from "@air-jam/sdk/ui";
@@ -28,10 +25,6 @@ import { useAirJamHost } from "@air-jam/sdk";
28
25
  const LobbyQr = () => {
29
26
  const host = useAirJamHost();
30
27
 
31
- if (host.joinUrlStatus !== "ready") {
32
- return null;
33
- }
34
-
35
28
  return (
36
29
  <RoomQrCode
37
30
  value={host.joinUrl}
@@ -43,11 +36,11 @@ const LobbyQr = () => {
43
36
  };
44
37
  ```
45
38
 
46
- If you are rendering before the join URL has been resolved, prefer gating with `host.joinUrlStatus === "ready"` and show your own loading state until then.
39
+ You can show your own loading state while `host.joinUrlStatus === "loading"`. Pass the unavailable value through to `RoomQrCode` so it can explain why phones cannot join.
47
40
 
48
41
  Props:
49
42
 
50
- - `value: string` (required)
43
+ - `value: string | null | undefined` (required)
51
44
  - `size?: number` default `180`
52
45
  - `padding?: number` default `1`
53
46
  - `foregroundColor?: string` default `#111111`
@@ -97,6 +90,8 @@ Use it for:
97
90
 
98
91
  ### `SurfaceViewport`
99
92
 
93
+ 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.
94
+
100
95
  Own safe-area, orientation, and page-level UI scaling for a game surface.
101
96
  It should fill the available screen while scaling the UI system proportionally, rather than letterboxing a fixed contained stage.
102
97
  Internally it publishes a local `--airjam-ui-scale` into Tailwind's own spacing, text, radius, and container variables so normal Tailwind utilities keep working.
@@ -104,7 +99,7 @@ Internally it publishes a local `--airjam-ui-scale` into Tailwind's own spacing,
104
99
  ```tsx
105
100
  import { SurfaceViewport } from "@air-jam/sdk/ui";
106
101
 
107
- <SurfaceViewport orientation="portrait" className="bg-zinc-950">
102
+ <SurfaceViewport className="bg-zinc-950">
108
103
  <ControllerView />
109
104
  </SurfaceViewport>;
110
105
  ```
@@ -137,30 +132,46 @@ Avoid:
137
132
 
138
133
  ---
139
134
 
140
- ### `VolumeControls`
135
+ ## Phone Controls
141
136
 
142
- Ready-made control block for master/music/sfx sliders bound to the shared platform settings runtime.
137
+ `ControlButton`, `AxisButton` and `Stick` bind phone UI to the game's declared
138
+ controls and send them; see [Input System](/docs/sdk/input-system).
143
139
 
144
140
  ```tsx
145
- import { VolumeControls } from "@air-jam/sdk/ui";
141
+ import { AxisButton, ControlButton, Stick } from "@air-jam/sdk/ui";
146
142
 
147
- <VolumeControls className="w-full max-w-xs" compact />;
143
+ <Stick control={shipInput.move} knobClassName="bg-white/30" />
144
+ <AxisButton control={pongInput.direction} value={-1}>Up</AxisButton>
145
+ <ControlButton control={shipInput.fire} className="data-[active=true]:ring-2">
146
+ Fire
147
+ </ControlButton>
148
148
  ```
149
149
 
150
- Mount it below `PlatformSettingsRuntime` when you want slider changes to persist in Arcade and inherit into embedded games.
150
+ Each sets `data-active` while held. `Stick` takes `directions="4-way"`,
151
+ `deadzone`, `knob`, `knobClassName`, and a function child that draws the whole
152
+ stick from `{ value, active }`.
151
153
 
152
- Props:
154
+ ### `GamepadLayout`
153
155
 
154
- - `className?: string`
155
- - `compact?: boolean`
156
+ Lays out a sideways controller like a gamepad: `left` and `right` thumb
157
+ squares of the same size, sized from the phone's short side and mirrored about
158
+ the centre, with a compact `center` column between them. `right` holds one
159
+ action, or several as a cluster around the main one. It fills its parent, so
160
+ put a header above it. See [Controller UI](/docs/for-agents/controller-ui#sideways-controllers).
156
161
 
157
- Use it for:
158
-
159
- - in-game settings overlays
160
- - pause/settings drawers
161
- - Arcade- or platform-owned settings panels
162
-
163
- ---
162
+ ```tsx
163
+ import { ControlButton, GamepadLayout, Stick } from "@air-jam/sdk/ui";
164
+
165
+ <GamepadLayout
166
+ left={<Stick control={gameInput.move} className="rounded-full bg-white/10" />}
167
+ center={<span className="text-xs uppercase">Round 1</span>}
168
+ right={
169
+ <ControlButton control={gameInput.action} className="rounded-full">
170
+ Go
171
+ </ControlButton>
172
+ }
173
+ />;
174
+ ```
164
175
 
165
176
  ## Base Primitives
166
177
 
@@ -222,6 +233,6 @@ Combine:
222
233
 
223
234
  ## Anti-Patterns
224
235
 
225
- - Do not build gameplay input on UI components; keep input lane in `useInputWriter` / `useGetInput`.
236
+ - Do not build gameplay input on `Button`; bind controls with `ControlButton`, `AxisButton` and `Stick`.
226
237
  - Do not rely on UI primitives for room/session lifecycle; lifecycle stays in headless SDK hooks.
227
238
  - Do not fork component behavior in each game if composition solves it; prefer small wrappers around canonical primitives.