@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,270 @@
1
+ # Host System
2
+
3
+ The Air Jam host system manages game sessions and input routing. This page explains how hosts work in different modes and how input flows through the system.
4
+
5
+ ## Host Modes
6
+
7
+ ### Standalone Host
8
+
9
+ The simplest mode—your game connects directly to the Air Jam server.
10
+
11
+ <StandaloneHostDiagram />
12
+
13
+ **Usage:**
14
+
15
+ ```tsx filename="src/app.tsx"
16
+ import { createAirJamApp, env } from "@air-jam/sdk";
17
+ import { airjam as game } from "./airjam.config";
18
+
19
+ export const airjam = createAirJamApp(game, {
20
+ runtime: env.vite(import.meta.env),
21
+ });
22
+
23
+ const HostShell = () => (
24
+ <airjam.Host
25
+ onPlayerJoin={(player) => spawnPlayer(player)}
26
+ onPlayerLeave={(id) => removePlayer(id)}
27
+ >
28
+ <HostView />
29
+ </airjam.Host>
30
+ );
31
+
32
+ // Players' controls reach the game in its simulation steps:
33
+ // step: (sim, { input, players }) => players.forEach((p) => process(sim, input(p.id)))
34
+ const HostView = () => <GameCanvas />;
35
+ ```
36
+
37
+ `createAirJamApp` binds the game declaration from `src/airjam.config.ts` to the
38
+ browser and returns `Host`, `Controller` and `paths`.
39
+
40
+ ### Arcade Mode (Outer App + Embedded Game)
41
+
42
+ In arcade mode, the platform runs the outer Arcade app and your game runs as an embedded Air Jam host inside an iframe.
43
+
44
+ The important rule is:
45
+
46
+ 1. Arcade owns platform surface state
47
+ 2. your game owns gameplay state
48
+ 3. the room owns membership, seats and the latest copy of every channel
49
+
50
+ <ArcadeModeDiagram />
51
+
52
+ ## One Room, Served to Each Frame
53
+
54
+ The Arcade's shell is the room's only host. It never hands its connection to a
55
+ game: when it shows a game, it serves that game's frame a view of its room over
56
+ a `MessagePort`, and each game's controller page gets the same kind of view of
57
+ its phone's seat.
58
+
59
+ - A frame sees and publishes only its own channels: everything outside the
60
+ Arcade's own `arcade.*` channels, such as `airjam.room` and its stores
61
+ - A frame that reaches outside its scope is closed `unauthorised`; the room and
62
+ the shell carry on
63
+ - A new frame for the same surface replaces the old one, which closes as
64
+ `replaced`
65
+ - Which game is showing lives in the shell's `arcade.surface` channel; its
66
+ `epoch` identifies one showing of one game
67
+
68
+ Your game uses the normal input lane, replicated state lane and signal lane, as
69
+ it would standalone.
70
+
71
+ ## Connection Flow
72
+
73
+ ### 1. Arcade Launch
74
+
75
+ ```
76
+ [Arcade shell] [Room] [Phone]
77
+ │ │ │
78
+ │ hello (host key, seats) │ │
79
+ │ ───────────────────────────▶│ │
80
+ │ │ │
81
+ │ welcome { code: "ABCD" } │ │
82
+ │ ◀───────────────────────────│ │
83
+ │ │ │
84
+ │ Display QR Code │ │
85
+ │ with room code │ Scan QR Code │
86
+ │ │ ◀──────────────────────────│
87
+ │ │ │
88
+ │ │ hello (phone key) │
89
+ │ │ ◀──────────────────────────│
90
+ │ │ │
91
+ │ seats [p1] │ welcome { seat: p1 } │
92
+ │ ◀───────────────────────────│ ──────────────────────────▶│
93
+ ```
94
+
95
+ ### 2. Game Launch
96
+
97
+ ```
98
+ [Arcade shell] [Your Game] [Phone]
99
+ │ │ │
100
+ │ arcade.surface → { kind: "game" } │ │
101
+ │ ─────────────────────────────────────────────────────────▶│
102
+ │ │ │
103
+ │ Load iframe ─────────────────────────▶│ │
104
+ │ │ │
105
+ │ room bridge request (MessagePort) │ │
106
+ │ ◀─────────────────────────────────────│ │
107
+ │ │ │
108
+ │ serve a scoped view of the room ───▶│ │
109
+ │ │ │
110
+ │ │ Load game UI │
111
+ ```
112
+
113
+ ### 3. Active Gameplay
114
+
115
+ While the game shows, every seat's input reaches your game:
116
+
117
+ ```ts
118
+ // Your game's simulation reads controls as usual inside the mounted host runtime.
119
+ step: (sim, { input, players }) => {
120
+ for (const player of players) play(sim, player.id, input(player.id));
121
+ },
122
+ ```
123
+
124
+ #### When a phone drops
125
+
126
+ A phone that loses its connection keeps its seat while the room waits for it
127
+ to come back (two minutes by default). The game hears at once: the player stays
128
+ in `players` with `connected: false`, and becomes connected again when the
129
+ phone is back. The simulation step also gets `reconnectingPlayerIds`, so each
130
+ game decides whether to wait, let a bot cover or carry on:
131
+
132
+ ```ts
133
+ step: (sim, { players, reconnectingPlayerIds }) => {
134
+ if (reconnectingPlayerIds.length > 0) return; // hold until everyone is back
135
+ // ...
136
+ },
137
+ ```
138
+
139
+ Outside the simulation, `getReconnectingPlayerIds(players)` from
140
+ `@air-jam/sdk/core` gives the same list from `useAirJamHost()` state.
141
+
142
+ ### 4. Game Exit
143
+
144
+ ```
145
+ [Phone] [Arcade shell] [Your Game]
146
+ │ │ │
147
+ │ exit (arcade.surface request) │
148
+ │ ───────────────────▶│ │
149
+ │ │ arcade.surface → { kind: "browser" }│
150
+ │ │ Close the game's view ─────────────▶│
151
+ │ │ Drop the game's channels │
152
+ │ │ Destroy iframe ────────────────────▶│
153
+ │ ◀── Show Arcade controller │
154
+ ```
155
+
156
+ ## Host Registration
157
+
158
+ ### Standalone Mode
159
+
160
+ ```tsx
161
+ <airjam.Host roomId="GAME">
162
+ <HostView />
163
+ </airjam.Host>;
164
+
165
+ // Inside HostView:
166
+ const host = useAirJamHost();
167
+ // host.roomId contains the room code
168
+ // host.joinUrl contains full URL for QR code
169
+ ```
170
+
171
+ Opening the room stays automatic:
172
+
173
+ 1. local dev: no credential
174
+ 2. hosted rooms: the SDK fetches a short-lived grant from `hostGrantEndpoint`
175
+ for each room it opens, and sends render-crash reports to the platform
176
+ unless the app passes its own `reportError`
177
+ 3. after a reload, the host returns to its room with its key and keeps its
178
+ players
179
+
180
+ Game code does not change between those modes.
181
+
182
+ ### Embedded Game Mode (Arcade)
183
+
184
+ ```tsx
185
+ // The SDK detects that it is embedded and asks the page around it for the room.
186
+ // Game code should not parse the embedding params directly.
187
+ const host = useAirJamHost();
188
+
189
+ // Closing and switching games belong to the Arcade.
190
+ // Game hosts keep gameplay logic in host callbacks and simulation steps.
191
+ ```
192
+
193
+ ## Player Management
194
+
195
+ ### Player Lifecycle
196
+
197
+ ```tsx
198
+ const HostShell = () => (
199
+ <airjam.Host
200
+ onPlayerJoin={(player) => {
201
+ // player.id - The seat the room gave ("p1", "p2", …)
202
+ // player.label - Display name ("Player 1", or the name they chose)
203
+ // player.color - Assigned color ("#FF5733")
204
+ // player.kind - "phone", "preview" or "agent"
205
+ // player.connected - false while the phone is away
206
+ // player.avatarId - Optional chosen avatar
207
+ spawnPlayerEntity(player);
208
+ announceJoin(player.label);
209
+ }}
210
+ onPlayerLeave={(controllerId) => {
211
+ removePlayerEntity(controllerId);
212
+ }}
213
+ >
214
+ <HostView />
215
+ </airjam.Host>
216
+ );
217
+ ```
218
+
219
+ ### Accessing Players
220
+
221
+ ```tsx
222
+ // Current player list
223
+ host.players.forEach((player) => {
224
+ console.log(player.label, player.color);
225
+ });
226
+
227
+ // Player count
228
+ const playerCount = host.players.length;
229
+
230
+ // Find specific player
231
+ const player = host.players.find((p) => p.id === targetId);
232
+ ```
233
+
234
+ ## Controller Presentation State
235
+
236
+ The host publishes a small presentation for the phones: whether the game is
237
+ playing or paused, and how to hold the phone. Networked stores own the real
238
+ multiplayer state; a short message for the players is a toast signal or a
239
+ store field.
240
+
241
+ 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.
242
+
243
+ ```tsx
244
+ const host = useAirJamHost();
245
+ host.pauseRuntime();
246
+ host.resumeRuntime();
247
+
248
+ // Controllers read controller.runtimeState and controller.controllerOrientation
249
+ ```
250
+
251
+ ## Error Handling
252
+
253
+ ```tsx
254
+ const host = useAirJamHost();
255
+
256
+ // Reconnecting is automatic; show it while it happens
257
+ if (host.connectionStatus === "reconnecting") {
258
+ showReconnectUI();
259
+ }
260
+
261
+ // A busy hosted service queues new rooms
262
+ if (host.queuePosition !== null) {
263
+ showQueue(host.queuePosition);
264
+ }
265
+
266
+ // Check for errors
267
+ if (host.lastError) {
268
+ showError(host.lastError);
269
+ }
270
+ ```