@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,223 @@
1
+ <!-- Generated from content/docs/how-it-works/architecture/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/how-it-works/architecture -->
3
+
4
+ # Architecture
5
+
6
+ Air Jam's open framework has three core components: the room server, game SDK,
7
+ and creator harness. Reference games show how they work together for multiplayer
8
+ gaming with smartphone controllers.
9
+
10
+ The important current rule is that Air Jam has one framework model, not one model for standalone games and a different model for Arcade.
11
+
12
+ Arcade is an Air Jam app around another Air Jam app.
13
+
14
+ ## Components
15
+
16
+ The Arcade and Studio at [airjam.io](https://airjam.io) are a separately operated
17
+ product, not an application in this public repository. Their hosted services
18
+ compose the same open runtime; standalone games need neither that product nor
19
+ its database. The diagrams include hosted surfaces to show how embedding works.
20
+
21
+ ### 1. Room server (`packages/server`)
22
+
23
+ **Role:** Keeps rooms: it seats phones, carries their controls to the game's
24
+ host and the host's state to the phones
25
+
26
+ **Technology:** Node.js and `ws`; the room itself is plain synchronous code
27
+ (`@air-jam/server/room`), so the hosted Arcade runs the same rooms elsewhere
28
+
29
+ Every device holds one WebSocket to its room. A game's host connects to
30
+ `/v1/host` and gets a room code; a phone connects to `/v1/play/CODE` and gets
31
+ a seat (`p1`, `p2`, …). The room speaks the room protocol
32
+ (`@air-jam/sdk/room-protocol`):
33
+
34
+ - **Hello and welcome.** Each device sends a key that only it knows; the same
35
+ key gets the same place back after a reload or a dropped network.
36
+ - **Channels.** The host publishes named state documents (the room's
37
+ presentation, each networked store); the room keeps the latest copy and
38
+ sends phones what changed.
39
+ - **Requests and signals.** A phone asks the host to run an action and gets
40
+ one answer; the host sends haptics, toasts and sounds to one seat or all.
41
+ - **Input.** Controls travel in small binary frames; the room delivers the
42
+ latest of each seat's to the host.
43
+
44
+ ### 2. SDK (`packages/sdk`)
45
+
46
+ **Role:** Developer toolkit for building Air Jam games
47
+
48
+ **Technology:** TypeScript, Zustand, Zod; React for the binding
49
+
50
+ **Architecture:**
51
+
52
+ The SDK is one runtime in two layers:
53
+
54
+ 1. **The core** (`@air-jam/sdk/core`) owns a room: the connection, players,
55
+ input, networked stores and their sync, the game's simulation on the SDK
56
+ clock, signals and the agent contract. It imports no React and no DOM, so
57
+ the same game runs in a browser, in Node without drawing, or faster than
58
+ real time in headless tests.
59
+ 2. **The React binding** (`@air-jam/sdk`) starts the core for a host or a
60
+ controller page and lets components read it: `useAirJamHost`,
61
+ `useAirJamController`, `useAirJamStore`, `useSimulationFrame`. Hooks
62
+ subscribe to the core; they never keep a second copy of the runtime.
63
+
64
+ A game declares metadata, stores, simulation, controls and its agent contract
65
+ once in `src/airjam.config.ts` with `defineAirJamGame` from core.
66
+ `app.tsx` binds it with `createAirJamApp(airjam, { runtime })`. Store
67
+ definitions and simulations import from `@air-jam/sdk/core`; components import
68
+ from `@air-jam/sdk`.
69
+
70
+ **Entry points.** Each import path has one purpose:
71
+
72
+ | Import path | Purpose |
73
+ | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
74
+ | `@air-jam/sdk` | React binding: host and controller surfaces and hooks, audio and platform settings |
75
+ | `@air-jam/sdk/core` | Framework-free game declaration, agent helpers, networked stores, simulations and runtimes |
76
+ | `@air-jam/sdk/ui` | Ready-made React components for host and controller shells |
77
+ | `@air-jam/sdk/styles.css` | Styles for those components |
78
+ | `@air-jam/sdk/metadata` | The game's catalog metadata declaration |
79
+ | `@air-jam/sdk/prefabs` | Placeable scene pieces with previews |
80
+ | `@air-jam/sdk/preview` | Preview controllers shown beside a host during development |
81
+ | `@air-jam/sdk/protocol` | Shared schemas: players, actions, leased control, runtime reports |
82
+ | `@air-jam/sdk/room-protocol` | The room protocol: frames, close codes, channels and the input codec |
83
+ | `@air-jam/sdk/room-session` | A host's or phone's session in a room, and connectors for WebSockets and embedded frames |
84
+ | `@air-jam/sdk/runtime-topology` | Where a runtime connects in each run mode |
85
+ | `@air-jam/sdk/runtime-control` | Calling a running host: agent requests, actions and observations |
86
+ | `@air-jam/sdk/runtime-inspection` | Reading what a running host or controller publishes for tools |
87
+ | `@air-jam/sdk/agent-tooling` | Checking and evaluating a game's agent contract |
88
+ | `@air-jam/sdk/controller-bridge` | Serving an embedded controller page its seat from the page around it |
89
+ | `@air-jam/sdk/arcade/*` | Embedding games in the Arcade: `bridge/host`, `bridge/controller`, `bridge/iframe`, `host`, `runtime`, `surface`, `url` |
90
+ | `@air-jam/sdk/release`, `@air-jam/sdk/platform-machine` | Contracts with the hosted platform for releases and the CLI |
91
+
92
+ Games use the first five or six; the rest serve the CLI, MCP server, devtools,
93
+ the server and the hosted platform.
94
+
95
+ ### 3. Creator Harness
96
+
97
+ The public CLI, MCP server and harness packages support project creation,
98
+ development, semantic game sessions, visual inspection and release preparation.
99
+ The same contracts work with external agents and the managed Studio; creator
100
+ tools do not depend on private application source.
101
+
102
+ ### Reference Game: Air Capture (`games/air-capture`)
103
+
104
+ **Role:** Reference implementation showcasing SDK capabilities
105
+
106
+ **Technology:** React, Vite, React Three Fiber, Rapier Physics
107
+
108
+ **Demonstrates:**
109
+
110
+ - Host-side game logic with physics
111
+ - Controller UI with joystick and buttons
112
+ - Player spawning/despawning on join/leave
113
+ - Haptic feedback on collisions
114
+ - Multiple game modes (CTF, survival)
115
+
116
+ ## Core Lane Model
117
+
118
+ Air Jam uses three lanes and they should stay separate:
119
+
120
+ 1. **Input lane** for players' controls: declared with `defineAirJamInput`, filled by phone controls, agents or replays, and read once per simulation step
121
+ 2. **Replicated state lane** for replayable shared state via `createAirJamStore`
122
+ 3. **Signal / command lane** for coarse UX/runtime messages such as haptics, toasts, pause, and exit
123
+
124
+ This is the same model in standalone games and in Arcade-embedded games.
125
+
126
+ ## Run Modes
127
+
128
+ The SDK automatically detects and adapts to different deployment scenarios:
129
+
130
+ ### Standalone Mode
131
+
132
+ Your game connects straight to a room server over a WebSocket.
133
+
134
+ ```
135
+ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
136
+ │ Your Game │◀───▶│ AirJam │◀───▶│ Controller │
137
+ │ (Host) │ │ Server │ │ (Phone) │
138
+ └──────────────┘ └──────────────┘ └──────────────┘
139
+ ```
140
+
141
+ **Use case:** Self-hosted games, development, custom deployments
142
+
143
+ ### Arcade Mode
144
+
145
+ Game runs inside an iframe on the Air Jam Platform.
146
+
147
+ ```
148
+ ┌─────────────────────────────────────────┐
149
+ │ Air Jam Platform (Parent) │
150
+ │ ┌───────────────────────────────────┐ │
151
+ │ │ Your Game (iframe) │ │
152
+ │ │ • Room served by the Arcade │ │
153
+ │ │ • Same room, its own channels │ │
154
+ │ └───────────────────────────────────┘ │
155
+ └─────────────────────────────────────────┘
156
+ ```
157
+
158
+ **Use case:** Featured on Air Jam arcade, game discovery
159
+
160
+ ### Bridge Mode
161
+
162
+ Controller runs inside platform's runtime wrapper (iframe communication).
163
+
164
+ ```
165
+ ┌─────────────────────────────────────────┐
166
+ │ Platform Controller Runtime (Parent) │
167
+ │ ┌───────────────────────────────────┐ │
168
+ │ │ Your Controller UI (iframe) │ │
169
+ │ │ • Seat served via MessagePort │ │
170
+ │ │ • Seamless game switching │ │
171
+ │ └───────────────────────────────────┘ │
172
+ └─────────────────────────────────────────┘
173
+ ```
174
+
175
+ **Use case:** Arcade mode controllers, persistent session
176
+
177
+ ### Input Path (Controller → Game)
178
+
179
+ ```
180
+ 1. Player holds a stick or button rendered by the SDK's phone controls
181
+ 2. The controller's input lane updates the declared control's state
182
+ 3. Once per display frame, if anything changed, the SDK sends one binary
183
+ input frame
184
+ 4. The room passes each seat's latest frame to the host
185
+ 5. The host's input lane decodes it against the declared controls
186
+ 6. Before each simulation step, the host samples every player's controls and
187
+ applies each kind's meaning (a pressed button reads true for one step)
188
+ 7. The step reads input(playerId)
189
+ ```
190
+
191
+ ### Signal Path (Game → Controller)
192
+
193
+ ```
194
+ 1. Game detects collision
195
+ 2. Host calls sendSignal("HAPTIC", { pattern: "heavy" }, playerId)
196
+ 3. The host's session sends a signal to that seat
197
+ 4. The room delivers it to the seat's phone
198
+ 5. Controller SDK receives signal
199
+ 6. SDK triggers navigator.vibrate() with pattern
200
+ 7. Player feels haptic feedback
201
+ ```
202
+
203
+ ### Opening a room
204
+
205
+ - A host's hello may carry a credential for the server's gate; a local server
206
+ needs none, and a self-hosted production server composes its own gate
207
+ (`createRoomServer({ gate })`) or runs open to any host
208
+ - A host returning to its room proves itself with its key alone, so a reload
209
+ keeps the room and its players
210
+ - An embedded game never opens a room of its own: the Arcade serves it the
211
+ Arcade's room over a MessagePort, scoped to that game's channels
212
+
213
+ ### Room Isolation
214
+
215
+ - Each room has a unique code
216
+ - Phones can only join with the code, and hold their seat by their key
217
+ - Input reaches only the room's host
218
+
219
+ ### Input Validation
220
+
221
+ - Every incoming input is checked against the game's declared controls
222
+ - Invalid input is dropped with an `AJ_INPUT_INVALID` diagnostic
223
+ - Agents' input passes the same check before they take a seat
@@ -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.
@@ -0,0 +1,102 @@
1
+ <!-- Generated from content/docs/for-agents/controller-ui/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/for-agents/controller-ui -->
3
+
4
+ # Controller UI
5
+
6
+ Controller UI should feel like a game controller first and a webpage second.
7
+
8
+ The main failure mode is borrowing desktop web-app patterns for active gameplay surfaces.
9
+
10
+ ## Gameplay Controller Rules
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
+
14
+ For active gameplay:
15
+
16
+ 1. use an absolute `inset-0` root
17
+ 2. avoid scroll
18
+ 3. disable accidental text selection
19
+ 4. use large touch targets
20
+ 5. keep controls visually obvious and single-purpose
21
+ 6. minimize text and dense hierarchy
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
+
52
+ ## Lobby Rules
53
+
54
+ Lobby screens can be slightly more flexible, but should still prefer:
55
+
56
+ 1. simple layout
57
+ 2. large controls
58
+ 3. minimal friction
59
+ 4. scroll only when it actually helps the flow
60
+
61
+ ## Interaction Rules
62
+
63
+ Avoid:
64
+
65
+ 1. tiny toggles
66
+ 2. multi-purpose buttons with unclear affordance
67
+ 3. deeply nested control groups
68
+ 4. layouts that assume precise pointer interaction
69
+
70
+ ## Visual Rules
71
+
72
+ Prefer:
73
+
74
+ 1. sparse game-like hierarchy
75
+ 2. fluid layout over hard-coded widths and heights
76
+ 3. obvious action grouping
77
+ 4. strong contrast and immediate readability
78
+
79
+ Avoid:
80
+
81
+ 1. card-heavy dashboard styling for active gameplay
82
+ 2. emoji-as-icon UI
83
+ 3. cluttered web-app chrome
84
+
85
+ ## Icon Rule
86
+
87
+ For template and starter work, a practical split is:
88
+
89
+ 1. a general UI and system icon pack for shell actions
90
+ 2. a gameplay-oriented icon set for abilities, pickups, and status effects
91
+
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.
@@ -0,0 +1,165 @@
1
+ <!-- Generated from content/docs/getting-started/debugging/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/getting-started/debugging -->
3
+
4
+ # Debugging and Logs
5
+
6
+ When local Air Jam development breaks, the fastest fix is usually knowing which surface is failing:
7
+
8
+ 1. game host
9
+ 2. controller
10
+ 3. local Air Jam server
11
+ 4. Arcade embed/runtime wiring
12
+
13
+ This page explains the practical debugging loop.
14
+
15
+ ## The Canonical Stream
16
+
17
+ Before you start jumping between browser tabs and terminals, remember that Air Jam has one canonical local dev stream:
18
+
19
+ - [.airjam/logs/dev-latest.ndjson](./unified-dev-logs.md)
20
+
21
+ That stream is the intended first place to inspect issues that cross:
22
+
23
+ 1. server lifecycle
24
+ 2. host runtime
25
+ 3. controller runtime
26
+ 4. embedded runtime edges
27
+
28
+ Read the dedicated guide here:
29
+
30
+ 1. [Unified Dev Logs](./unified-dev-logs.md)
31
+
32
+ ## 1. Start With The Canonical Local Loop
33
+
34
+ For scaffolded games, the default local command is:
35
+
36
+ ```bash
37
+ pnpm run dev
38
+ ```
39
+
40
+ That gives you the most useful first signal:
41
+
42
+ 1. server logs in the same terminal
43
+ 2. Vite host output
44
+ 3. QR/join flow using the same local runtime shape the template expects
45
+
46
+ If that terminal is not healthy, fix it before debugging the controller UI.
47
+
48
+ ## 2. Check The Local Server First
49
+
50
+ The local server should answer:
51
+
52
+ [http://localhost:4000/health](http://localhost:4000/health)
53
+
54
+ If `/health` is down:
55
+
56
+ 1. your local runtime server is not running
57
+ 2. the game will not create or join rooms
58
+ 3. controller QR flow will fail no matter what the UI shows
59
+
60
+ ## 3. Know Which Console To Inspect
61
+
62
+ Use the right browser console for the right problem:
63
+
64
+ 1. **Host tab** for room creation, host bootstrap, input consumption, and gameplay errors
65
+ 2. **Controller tab/phone remote inspector** for join failures, input publishing, haptics, and controller UI state
66
+ 3. **Server terminal** for room lifecycle, dropped connections, refused hosts and phones
67
+
68
+ Do not debug everything from only one surface.
69
+
70
+ ### Host boots but no room appears
71
+
72
+ Check:
73
+
74
+ 1. server terminal is running
75
+ 2. host browser console has no bootstrap/config errors
76
+ 3. `VITE_AIR_JAM_SERVER_URL` is correct for your environment
77
+ 4. production/static deploy has a valid `VITE_AIR_JAM_APP_ID`
78
+
79
+ ### Controller cannot join
80
+
81
+ Check:
82
+
83
+ 1. QR or join URL contains the right room code
84
+ 2. host and controller are talking to the same server origin
85
+ 3. SPA rewrites are enabled for `/controller?room=XXXX`
86
+ 4. phone can actually reach the host URL you are showing
87
+
88
+ If local phone testing is the issue, use:
89
+
90
+ ```bash
91
+ pnpm run dev -- --secure
92
+ ```
93
+
94
+ ### Input arrives late or not at all
95
+
96
+ Check:
97
+
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
103
+
104
+ ### Store actions do nothing
105
+
106
+ Check:
107
+
108
+ 1. actions are dispatched via `gameStore.actions` and the store is declared in `defineAirJamGame({ stores })`
109
+ 2. payloads are plain serializable objects
110
+ 3. your controller is connected before dispatching
111
+ 4. identity-dependent actions use `ctx.actorId` on the host side
112
+
113
+ ### Arcade embed works in standalone but breaks in platform
114
+
115
+ Check:
116
+
117
+ 1. game code is not parsing Arcade runtime params directly
118
+ 2. gameplay state lives in the game's own store, not in local iframe lifecycle state
119
+ 3. you are treating the bridge as transport only, not as app-state truth
120
+
121
+ ## 5. Use SDK Diagnostics In Development
122
+
123
+ Air Jam exposes structured diagnostics for common misuse paths:
124
+
125
+ ```tsx
126
+ import { onAirJamDiagnostic, setAirJamDiagnosticsEnabled } from "@air-jam/sdk";
127
+
128
+ setAirJamDiagnosticsEnabled(true);
129
+
130
+ const unsubscribe = onAirJamDiagnostic((diagnostic) => {
131
+ console.log(diagnostic.code, diagnostic.message, diagnostic.details);
132
+ });
133
+ ```
134
+
135
+ This is especially useful for:
136
+
137
+ 1. missing provider/session scope
138
+ 2. invalid input payload shape
139
+ 3. state-action dispatch before session readiness
140
+ 4. runtime config mistakes
141
+
142
+ ## 6. Use The Reference Games As Sanity Checks
143
+
144
+ If you are unsure whether the framework or your game is the problem, compare your approach against:
145
+
146
+ 1. `pong` for the small canonical starter path
147
+ 2. `air-capture` for the heavier reference-app path
148
+
149
+ If your code disagrees with both patterns, your code is probably the outlier.
150
+
151
+ ## 7. Query The Unified Stream
152
+
153
+ Scaffolded games should use:
154
+
155
+ ```bash
156
+ pnpm exec air-jam-server logs
157
+ ```
158
+
159
+ Inside the Air Jam monorepo, the equivalent maintainer command is:
160
+
161
+ ```bash
162
+ pnpm run repo -- workspace logs
163
+ ```
164
+
165
+ Both commands read the same canonical local observability model.