@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
@@ -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
  ```