@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,674 @@
1
+ <!-- Generated from content/docs/getting-started/migrating-legacy-games/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/getting-started/migrating-legacy-games -->
3
+
4
+ # Migrating Legacy Games
5
+
6
+ This guide is for older Air Jam games that still use the pre-v1 app shape.
7
+
8
+ If you are starting fresh, use [Quick Start](./quick-start.md) instead.
9
+
10
+ If you are using an LLM to help with the migration, copy this guide into the
11
+ conversation first. Codex or Claude are the best fit for this kind of
12
+ repo-wide migration work.
13
+
14
+ ## Node.js Minimum
15
+
16
+ Air Jam 1.0 authoring requires Node.js 22.15 or newer for devtools, the CLI and MCP,
17
+ create-airjam and generated projects. The declaration loader uses synchronous
18
+ module hooks to enforce its framework-free boundary through imports, `require`
19
+ and `createRequire`. The SDK and server retain their Node.js 22.0 minimum.
20
+
21
+ ## When You Need This Guide
22
+
23
+ You are likely on the old shape if your game still has some of these patterns:
24
+
25
+ - `AirJamProvider` in `App.tsx`
26
+ - flat files like `src/host-view.tsx`, `src/controller-view.tsx`, and `src/store.ts`
27
+ - `HostShell` / `ControllerShell`
28
+ - old store actions like `joinTeam(team, playerId?)`
29
+ - controller code that calls `controller.sendInput(...)` directly in a loop
30
+
31
+ The v1 goal is not “make old code barely compile”.
32
+
33
+ The goal is:
34
+
35
+ 1. move to the canonical v1 runtime shape
36
+ 2. keep boundaries clean between runtime, replicated state, and game logic
37
+ 3. remove old shell/provider assumptions instead of carrying them forward
38
+
39
+ ## Prerelease Local Migration Note
40
+
41
+ If you are migrating an old game against a local unreleased Air Jam workspace before packages are published, keep the setup split clean:
42
+
43
+ 1. install `@air-jam/sdk` from the local package or a local tarball
44
+ 2. do not depend on `@air-jam/server` through a direct `file:` package reference if it still carries monorepo-only `workspace:*` internals
45
+ 3. for prerelease local dev, resolve `air-jam-server` from your nearby Air Jam workspace checkout or use tarballs once you are doing package validation
46
+
47
+ This is only a prerelease migration concern. The release goal is published packages or tarball validation, not permanent cross-repo path coupling.
48
+
49
+ ## The Target Shape
50
+
51
+ The current canonical app shape looks like this:
52
+
53
+ ```text
54
+ src/
55
+ airjam.config.ts
56
+ app.tsx
57
+ routes/
58
+ host-view.tsx
59
+ controller-view.tsx
60
+ game/
61
+ input.ts
62
+ store.ts
63
+ ...
64
+ ```
65
+
66
+ Not every migrated game must match that exact folder tree.
67
+
68
+ What matters is the boundary model:
69
+
70
+ 1. `defineAirJamGame(...)` declares the game in core; `createAirJamApp(game, options)` binds its browser runtime
71
+ 2. `app.tsx` owns route-level `<airjam.Host>` and `<airjam.Controller>` wrappers
72
+ 3. host/controller runtime owner hooks mount only in those route entry files
73
+ 4. replicated state uses the current `createAirJamStore` action contract
74
+ 5. host-local simulation stays separate from replicated store state
75
+
76
+ ## Migration Checklist
77
+
78
+ Use this order. Do not jump around randomly.
79
+
80
+ 1. Replace `AirJamProvider` bootstrap with `createAirJamApp`
81
+ 2. Move host/controller ownership into route wrappers
82
+ 3. Migrate replicated store actions to `(ctx, payload)`
83
+ 4. Remove `HostShell` / `ControllerShell`
84
+ 5. Decide what belongs in replicated store state versus host-local simulation
85
+ 6. Modernize controller input only if the game actually has continuous input
86
+ 7. Clean up old shell/theme workarounds and dead legacy branches
87
+ 8. Re-run local validation before changing game behavior
88
+
89
+ ## Step 1: Move Runtime Setup Into `airjam.config.ts`
90
+
91
+ Old shape:
92
+
93
+ ```tsx filename="src/App.tsx"
94
+ import { AirJamProvider } from "@air-jam/sdk";
95
+ import { gameInputSchema } from "./types";
96
+
97
+ export function App() {
98
+ return (
99
+ <AirJamProvider
100
+ serverUrl={import.meta.env.VITE_AIR_JAM_SERVER_URL}
101
+ publicHost={import.meta.env.VITE_AIR_JAM_PUBLIC_HOST}
102
+ input={{
103
+ schema: gameInputSchema,
104
+ latch: {
105
+ booleanFields: ["action"],
106
+ },
107
+ }}
108
+ >
109
+ ...
110
+ </AirJamProvider>
111
+ );
112
+ }
113
+ ```
114
+
115
+ Target shape:
116
+
117
+ ```ts filename="src/airjam.config.ts"
118
+ import { defineAirJamGame } from "@air-jam/sdk/core";
119
+ import { gameInput } from "./game/input";
120
+ import { simulation } from "./game/simulation";
121
+
122
+ export const airjam = defineAirJamGame({
123
+ metadata: {
124
+ slug: "space-game",
125
+ name: "Space Game",
126
+ tagline: "Fly together and defend the fleet.",
127
+ category: "arcade",
128
+ minPlayers: 1,
129
+ maxPlayers: 4,
130
+ inputModalities: ["buttons", "touch"],
131
+ supportedSdkRange: "^1.0.0",
132
+ maintainer: { name: "Air Jam" },
133
+ version: 1,
134
+ },
135
+ controllerPath: "/controller",
136
+ simulation,
137
+ input: gameInput,
138
+ });
139
+ ```
140
+
141
+ This removes runtime wiring noise from your app tree and gives you one canonical config surface.
142
+
143
+ ## Step 2: Move Host And Controller Ownership Into `app.tsx`
144
+
145
+ Old shape:
146
+
147
+ ```tsx filename="src/App.tsx"
148
+ <Routes>
149
+ <Route path="/" element={<HostView />} />
150
+ <Route path="/controller" element={<ControllerView />} />
151
+ </Routes>
152
+ ```
153
+
154
+ Target shape:
155
+
156
+ ```tsx filename="src/app.tsx"
157
+ import { Route, Routes } from "react-router-dom";
158
+ import { createAirJamApp, env } from "@air-jam/sdk";
159
+ import { airjam as game } from "./airjam.config";
160
+
161
+ const airjam = createAirJamApp(game, { runtime: env.vite(import.meta.env) });
162
+
163
+ export function App() {
164
+ return (
165
+ <Routes>
166
+ <Route
167
+ path="/"
168
+ element={
169
+ <airjam.Host>
170
+ <HostView />
171
+ </airjam.Host>
172
+ }
173
+ />
174
+ <Route
175
+ path={airjam.paths.controller}
176
+ element={
177
+ <airjam.Controller>
178
+ <ControllerView />
179
+ </airjam.Controller>
180
+ }
181
+ />
182
+ </Routes>
183
+ );
184
+ }
185
+ ```
186
+
187
+ This is the runtime boundary. Keep it explicit.
188
+
189
+ ## Step 3: Fix Store Actions First
190
+
191
+ This is the most important migration after bootstrap.
192
+
193
+ Old actions often looked like this:
194
+
195
+ ```tsx filename="src/store.ts"
196
+ actions: {
197
+ joinTeam: (team, playerId) => {
198
+ if (!playerId) return;
199
+ ...
200
+ },
201
+ setReady: (ready, playerId) => {
202
+ if (!playerId) return;
203
+ ...
204
+ },
205
+ }
206
+ ```
207
+
208
+ The current action model is:
209
+
210
+ The `src/game/stores/game-store.ts` path below is a starter-friendly example.
211
+ If your project already uses a different store module layout, keep the same action contract and ownership rules while migrating.
212
+
213
+ ```tsx filename="src/game/stores/game-store.ts"
214
+ actions: {
215
+ joinTeam: ({ actorId, connectedPlayerIds }, { team }) =>
216
+ set((state) => {
217
+ if (!actorId) return state;
218
+ ...
219
+ }),
220
+
221
+ setReady: ({ actorId }, { ready }) =>
222
+ set((state) => {
223
+ if (!actorId) return state;
224
+ ...
225
+ }),
226
+ }
227
+ ```
228
+
229
+ Controller-side dispatch should always look like:
230
+
231
+ ```tsx filename="src/routes/controller-view.tsx"
232
+ gameStore.actions.joinTeam({ team: "team1" });
233
+ gameStore.actions.setReady({ ready: true });
234
+ ```
235
+
236
+ Do not keep trailing `playerId` arguments around.
237
+
238
+ For the full store model, see [Networked State](./networked-state.md).
239
+
240
+ ## Step 4: Remove `HostShell` And `ControllerShell`
241
+
242
+ Treat the old shell components as migration targets, not as permanent app structure.
243
+
244
+ Why:
245
+
246
+ 1. they hide app-owned layout inside generic wrappers
247
+ 2. they can leak presentational concerns into the app
248
+ 3. they make theme and layout cleanup harder than it should be
249
+
250
+ Use app-owned layout instead.
251
+
252
+ If you still need a narrow layout helper, use one intentionally, for example `SurfaceViewport` for shared full-screen controller or host UI scaling.
253
+
254
+ Do not rebuild your app around a generic shell.
255
+
256
+ ## Step 5: Choose The Right Migration Branch
257
+
258
+ Not every legacy game should be migrated the same way.
259
+
260
+ ### Branch A: Flat Legacy App
261
+
262
+ If your app still looks like:
263
+
264
+ ```text
265
+ src/
266
+ App.tsx
267
+ host-view.tsx
268
+ controller-view.tsx
269
+ store.ts
270
+ types.ts
271
+ ```
272
+
273
+ then do the full cleanup:
274
+
275
+ 1. add `src/airjam.config.ts`
276
+ 2. rename to `src/app.tsx`
277
+ 3. move runtime entry files to `src/routes/`
278
+ 4. move input/store/domain files into `src/game/`
279
+
280
+ This is the cleanest migration for older minimal apps.
281
+
282
+ ### Branch B: Already Modular Legacy App
283
+
284
+ If your app already has good structure like:
285
+
286
+ ```text
287
+ src/
288
+ features/
289
+ store/
290
+ hooks/
291
+ components/
292
+ ```
293
+
294
+ then do not force a cosmetic rewrite just to match a template.
295
+
296
+ Instead:
297
+
298
+ 1. modernize bootstrap and route ownership
299
+ 2. modernize the store action contract
300
+ 3. keep healthy feature/domain modules mostly where they are
301
+
302
+ The migration guide is about boundaries, not folder cosplay.
303
+
304
+ ### Branch C: Host-Simulation-Heavy App
305
+
306
+ If most of the game logic lives in a host-side hook or `useHostTick` loop, move it into a declared simulation (`defineAirJamSimulation`, declared with `defineAirJamGame({ simulation })`). `useHostTick` is removed.
307
+
308
+ 1. replicated store state owns shared, synchronized state
309
+ 2. the simulation owns timers, positions, physics and outcomes; it reads input from its step context, uses the step's `random` and game time instead of `Math.random()` and `Date.now()`, and dispatches store actions for outcomes such as scores
310
+ 3. the host view draws with `useSimulationFrame`, plays sounds and toasts from `useSimulationEvents`, and keeps media loading and draw caches
311
+ 4. what agents see moves from `useHostAgentObservation` into the simulation's `observe`
312
+
313
+ This is usually cleaner than trying to stuff the whole game loop into the replicated store, and it lets the game's tests run headless.
314
+
315
+ ## Step 6: Migrate Input Based On Input Type
316
+
317
+ Do not overgeneralize input migration.
318
+
319
+ ### Continuous Input Games
320
+
321
+ If your controller sends directional or analog-style input, declare those
322
+ controls and let the SDK's phone controls send them:
323
+
324
+ ```tsx filename="src/game/input.ts"
325
+ import { button, defineAirJamInput, stick } from "@air-jam/sdk/core";
326
+
327
+ export const gameInput = defineAirJamInput({
328
+ move: stick(),
329
+ action: button("held"),
330
+ });
331
+ ```
332
+
333
+ ```tsx filename="src/controller/index.tsx"
334
+ import { ControlButton, Stick } from "@air-jam/sdk/ui";
335
+ import { gameInput } from "../game/input";
336
+
337
+ export function ControllerView() {
338
+ return (
339
+ <div className="grid h-full grid-cols-2 gap-3 p-3">
340
+ <Stick control={gameInput.move} />
341
+ <ControlButton control={gameInput.action}>Action</ControlButton>
342
+ </div>
343
+ );
344
+ }
345
+ ```
346
+
347
+ The simulation reads them each step with `input(playerId)`. Remove the old
348
+ send loop, input writer and any timestamp field.
349
+
350
+ ### Action-Only Or Choice-Driven Games
351
+
352
+ If the controller mainly sends taps, choices, or store actions, do not add per-frame input machinery just because another game needed it.
353
+
354
+ Use the simpler model that matches your game.
355
+
356
+ For more input details, see [Input System](./input-system.md).
357
+
358
+ ## Step 7: Replace `latch` And Input Behavior Lists
359
+
360
+ Older games configure input through `latch` or `input.behavior` lists of
361
+ `pulse`, `hold` and `latest` fields. Both are gone: each control's kind carries
362
+ its meaning. A tap-safe boolean becomes `button("pressed")`, a held boolean
363
+ `button("held")`, a sticky vector `stick({ keepDirection: true })`, and any
364
+ other number an `axis()`.
365
+
366
+ ## Step 8: Remove Legacy Workarounds
367
+
368
+ After bootstrap, shell, and action migration, remove old hacks that only existed because of the old shape.
369
+
370
+ Common examples:
371
+
372
+ 1. theme fixes that fight shell-injected classes
373
+ 2. old child-mode or shell-mode presentation branches
374
+ 3. duplicated route aliases like `/host` unless you truly still need them
375
+ 4. stale README instructions that still describe the old app shape
376
+
377
+ This step matters. A migration is not complete if the old assumptions are still quietly shaping the code.
378
+
379
+ ## Identity Rules To Recheck
380
+
381
+ During migration, be explicit about identity.
382
+
383
+ You should know:
384
+
385
+ 1. what is the Air Jam controller/session identity
386
+ 2. what is the in-game avatar or character identity
387
+ 3. which store keys use which identity
388
+
389
+ Do not leave this implicit.
390
+
391
+ This becomes especially important when:
392
+
393
+ 1. controllers are assigned to in-game characters
394
+ 2. bots exist
395
+ 3. host simulation uses different IDs than controller presence
396
+
397
+ ## Validation Checklist
398
+
399
+ Before calling a migration done, verify:
400
+
401
+ 1. host route boots cleanly with `<airjam.Host>`
402
+ 2. controller route joins cleanly with `<airjam.Controller>`
403
+ 3. store actions no longer rely on trailing `playerId` arguments
404
+ 4. no child component mounts a second runtime owner hook
405
+ 5. shell-removal cleanup is complete
406
+ 6. README and local dev commands match the migrated app shape
407
+ 7. `pnpm run typecheck`
408
+ 8. `pnpm run build`
409
+ 9. the game still behaves correctly in local host/controller play
410
+
411
+ ## Recommended Order For Real Migrations
412
+
413
+ When migrating multiple games, do them in this order:
414
+
415
+ 1. smallest flat app first
416
+ 2. host-simulation-heavy app second
417
+ 3. already-modular app third
418
+
419
+ That order usually sharpens the guide fastest:
420
+
421
+ 1. first app proves the basic recipe
422
+ 2. second app forces the harder boundary decisions
423
+ 3. third app benefits from the refined guide and should migrate more cleanly
424
+
425
+ ## From 0.9 To 1.0
426
+
427
+ Games written against the 0.9 SDK, including agent-made Studio games, move
428
+ mechanically with the mappings below. Each removal fails typecheck, so work
429
+ through the compiler errors with this section open.
430
+
431
+ ### The game is declared in core
432
+
433
+ `src/airjam.config.ts` exports only the named `airjam = defineAirJamGame(...)`
434
+ declaration from `@air-jam/sdk/core`. Move metadata into its `metadata` field;
435
+ remove the separate metadata export. Its entire import graph must stay free of
436
+ React, the SDK root, TSX and CSS. The loader names the importing file with
437
+ `AJ_DECLARATION_NOT_FRAMEWORK_FREE` when that boundary is crossed.
438
+
439
+ Move `createAirJamApp` to `app.tsx` and call
440
+ `createAirJamApp(airjam, { runtime: env.vite(import.meta.env) })`. The binding
441
+ returns `Host`, `Controller`, `paths` and `session`; game data stays on the
442
+ declaration. Passing the former options object as the first argument fails
443
+ with an error naming `defineAirJamGame` as its replacement.
444
+
445
+ Import agent helpers and their types from `@air-jam/sdk/core`. A declared
446
+ `testing` path, relative to the config, names the development module:
447
+
448
+ ```ts
449
+ import { defineAirJamTesting } from "@air-jam/devtools/testing";
450
+ import { gamePlayer } from "./player";
451
+
452
+ export const testing = defineAirJamTesting({
453
+ player: gamePlayer,
454
+ profiles: { scoring, diagnostics },
455
+ // Optional: visual: { scenarios: [...] }, using the game's declared agent.
456
+ });
457
+ ```
458
+
459
+ The declared player is offered as `model` in every profile. Remove each
460
+ profile's manually created model policy; the name is reserved and fails with
461
+ `AJ_TEST_POLICY_RESERVED` when authored. Visual packs no longer declare their
462
+ own agent. Tools read the game through `airjam.inspect_game` and its
463
+ `declaration.agent` field.
464
+
465
+ Remove capacity from runtime options. `metadata.maxPlayers` is the capacity
466
+ for both browser and headless rooms: a four-player game refuses a fifth phone.
467
+ Remove identity fields from `airjam-template.json`; it now holds only scaffold
468
+ and export flags. Regenerate template catalogs after changing declarations.
469
+
470
+ ### Stores Are Plain Objects
471
+
472
+ `createAirJamStore` moved to `@air-jam/sdk/core` and returns a store object,
473
+ not a hook. Declare every store in the app; reading an undeclared store throws
474
+ `AJ_STORE_NOT_DECLARED`.
475
+
476
+ ```ts
477
+ // 0.9
478
+ import { createAirJamStore } from "@air-jam/sdk";
479
+ export const useGameStore = createAirJamStore<GameState>((set) => ({ ... }));
480
+
481
+ // 1.0
482
+ import { createAirJamStore } from "@air-jam/sdk/core";
483
+ export const gameStore = createAirJamStore<GameState>((set) => ({ ... }));
484
+ // airjam.config.ts
485
+ defineAirJamGame({ stores: [gameStore], ... });
486
+ ```
487
+
488
+ | 0.9 | 1.0 |
489
+ | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
490
+ | `useGameStore((s) => s.score)` | `useAirJamStore(gameStore, (s) => s.score)` from `@air-jam/sdk` |
491
+ | `useGameStore.useActions().joinTeam(...)` | `gameStore.actions.joinTeam(...)` |
492
+ | `useGameStore.asPlayer(id)` | `gameStore.asPlayer(id)` |
493
+ | `useGameStore.getState()`, `.subscribe` | `gameStore.getState()`, `gameStore.subscribe` |
494
+ | `useGameStore.useHostActionListener(listener)` | `useHostActionListener(gameStore, listener)` from `@air-jam/sdk` |
495
+ | `useGameStore.useLiveStateRef().current` | `gameStore.getState()`, always current |
496
+ | `acceptAirJamAction`, `rejectAirJamAction`, `AirJamActionContext` and the other store types from `@air-jam/sdk` | the same names from `@air-jam/sdk/core` |
497
+ | `createAirJamStore(init, { storeDomain })` | unchanged, from `@air-jam/sdk/core` |
498
+ | `Date.now()` inside an action | `ctx.now`, the game time the action runs at |
499
+
500
+ Shells that compose runtimes themselves, such as the Arcade, pass their
501
+ stores to `AirJamHostRuntime` and `AirJamControllerRuntime` from
502
+ `@air-jam/sdk/arcade/runtime` with the `stores` prop.
503
+
504
+ ### Settings are declared
505
+
506
+ Move tunable speed, force, damage, health, duration and count constants into
507
+ `defineAirJamSettings` from `@air-jam/sdk/core`, and pass the result as the
508
+ `settings` field of `defineAirJamGame`. Keep a leaf settings module and infer
509
+ its values with `AirJamSettingsValues<typeof gameSettings>`. Delete the old
510
+ constants. Lobby choices remain store state.
511
+
512
+ Read `settings` in simulation create, step and observe contexts, and in
513
+ `AirJamActionContext<GameSettings>`. Supply the fourth simulation type parameter
514
+ for typed values. Host drawing uses `useAirJamSettings(gameSettings)`; copy any
515
+ phone display values into the store rather than reading settings on controllers.
516
+
517
+ Only settings declared `live: true` can change during a host's lifetime.
518
+ `airjam.read_game_settings` returns the current values and revision;
519
+ `airjam.update_game_settings` takes an atomic patch and `expectedRevision`.
520
+ Unknown, invalid, stale and non-live updates fail with `AJ_SETTING_UNKNOWN`,
521
+ `AJ_SETTING_INVALID`, `AJ_SETTING_STALE` and `AJ_SETTING_NOT_LIVE` respectively.
522
+ Start a new room through `airjam.start_game_run({ settings: { ... }, ... })`
523
+ for a non-live value. Input logs now require version 2, resolved initial
524
+ settings and the ordered settings events; version 1 logs must be recorded again.
525
+
526
+ See [Game Settings](./settings.md) for declarations, host hooks and CLI
527
+ commands.
528
+
529
+ ### Assets and theme are declared
530
+
531
+ Move sound manifests into `defineAirJamAssets` from `@air-jam/sdk/core` and
532
+ pass the result as `assets` in `defineAirJamGame`. Import `SoundConfig` from
533
+ `@air-jam/sdk/core`. Declare images and other loaded files there too, using
534
+ served paths under `public/`. Read their paths
535
+ from the object and remove old manifests and path imports. Use sound `surface`
536
+ marks for host-only or controller-only audio. Remove game-owned `<AudioRuntime>`
537
+ mounts; the binding supplies it on each surface. Keep playlist and playback
538
+ logic inside that binding.
539
+
540
+ Move colours and font families into `defineAirJamTheme` and pass it as `theme`.
541
+ Map existing Tailwind names to `--airjam-color-*` and `--airjam-font-*` with
542
+ `@theme inline`. Canvas and 3D drawing read the same theme object. Remove
543
+ repeated colour and font literals; shadows and gradients remain CSS.
544
+ Inspection now fails `AJ_ASSET_MISSING` for a declared file that is absent.
545
+
546
+ See [Game Assets and Theme](./assets-and-theme.md) for the complete shapes.
547
+
548
+ ### The SDK Owns The Loop
549
+
550
+ `useHostTick` is removed. Per-step game logic moves into a declared
551
+ simulation; components only draw it.
552
+
553
+ ```tsx
554
+ // 0.9
555
+ useHostTick({
556
+ mode: "fixed",
557
+ intervalMs: 16,
558
+ onTick: ({ deltaSeconds }) => stepGame(world, deltaSeconds),
559
+ });
560
+
561
+ // 1.0: src/game/simulation.ts
562
+ export const simulation = defineAirJamSimulation<World, GameInput, GameEvent>({
563
+ stepMs: 16,
564
+ create: ({ random }) => createWorld(random),
565
+ step: (world, { dtSeconds, input, players, random, emit }) =>
566
+ stepGame(world, dtSeconds),
567
+ observe: (world) => ({ score: world.score }),
568
+ });
569
+ // airjam.config.ts
570
+ defineAirJamGame({ simulation, ... });
571
+ ```
572
+
573
+ | 0.9 | 1.0 |
574
+ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
575
+ | `useHostTick({ onTick })` | the simulation's `step` |
576
+ | `useHostTick({ onFrame })`, `fixedStepAlpha` | `useSimulationFrame(({ sim, alpha }) => draw(sim, alpha))` |
577
+ | `HostTickInfo.deltaSeconds`, `.tick` | the step context's `dtSeconds`, `tick` |
578
+ | `Math.random()` in game logic | the step context's `random` |
579
+ | `useHostAgentObservation({ read, capture })` | `read` becomes the simulation's `observe`; `useHostAgentCapture(draw)` draws into the supplied canvas, and its returned function runs after the game renders |
580
+ | UI state derived from the world | `useSimulationSelector((sim) => value)` |
581
+ | one-off feedback such as sounds | `emit` in `step`, `useSimulationEvents` in a component |
582
+
583
+ ### Input Is Declared
584
+
585
+ The `input: { schema, behavior }` config, controller send loops and the host's
586
+ `getInput` are removed. A game declares its controls, the SDK's phone controls
587
+ send them, and the simulation reads them each step.
588
+
589
+ ```tsx
590
+ // 0.9: src/game/contracts/input.ts
591
+ export const gameInputSchema = z.object({ direction: z.number(), fire: z.boolean() });
592
+ // airjam.config.ts
593
+ createAirJamApp({ input: { schema: gameInputSchema, behavior: { pulse: ["fire"] } }, ... });
594
+ // controller
595
+ const writeInput = useInputWriter();
596
+ useControllerTick(() => writeInput({ direction: directionRef.current, fire: fireRef.current }), {
597
+ intervalMs: 16,
598
+ });
599
+ <button onPointerDown={() => (directionRef.current = -1)} onPointerUp={() => (directionRef.current = 0)}>Up</button>
600
+ // host
601
+ const { direction, fire } = host.getInput(playerId) ?? { direction: 0, fire: false };
602
+
603
+ // 1.0: src/game/contracts/input.ts
604
+ import { axis, button, defineAirJamInput } from "@air-jam/sdk/core";
605
+ export const gameInput = defineAirJamInput({ direction: axis(), fire: button("pressed") });
606
+ // airjam.config.ts
607
+ defineAirJamGame({ input: gameInput, simulation, ... });
608
+ // controller
609
+ import { AxisButton, ControlButton } from "@air-jam/sdk/ui";
610
+ <AxisButton control={gameInput.direction} value={-1}>Up</AxisButton>
611
+ <ControlButton control={gameInput.fire}>Fire</ControlButton>
612
+ // simulation step
613
+ step: (sim, { input, players }) => {
614
+ for (const player of players) {
615
+ const { direction, fire } = input(player.id);
616
+ }
617
+ },
618
+ ```
619
+
620
+ | 0.9 | 1.0 |
621
+ | --------------------------------------------------------- | ------------------------------------------------------------------------------ |
622
+ | a boolean in `behavior.pulse` or `latch` | `button("pressed")`: true for exactly one step per press |
623
+ | any other boolean | `button("held")` |
624
+ | a number from -1 to 1 | `axis()`, sent by `AxisButton` with a `value` |
625
+ | a `{ x, y }` vector | `stick()`, or `stick({ keepDirection: true })` for a vector in `behavior.hold` |
626
+ | a timestamp or sequence field | nothing: the SDK orders input by step |
627
+ | buttons with pointer handlers writing refs | `ControlButton`, `AxisButton` and `Stick`, styled through `data-active` |
628
+ | `useInputWriter` and `useControllerTick` send loops | nothing: the controller runtime sends on change, once per frame |
629
+ | `host.getInput(playerId)` or `useGetInput` in a host tick | `input(playerId)` in the simulation's `step`; it always returns every control |
630
+ | `z.infer<typeof gameInputSchema>` | `AirJamInputValues<typeof gameInput>` from `@air-jam/sdk/core` |
631
+
632
+ Choices, menus and other taps that are not per-step play stay store actions.
633
+
634
+ ### Removed Exports
635
+
636
+ These exports are gone; use the replacement.
637
+
638
+ | Removed | Use instead |
639
+ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
640
+ | `@air-jam/sdk/arcade`, `@air-jam/sdk/arcade/bridge` | the leaf that owns the concept, such as `@air-jam/sdk/arcade/bridge/host` |
641
+ | `useHostTick`, `HostTickInfo`, `HostTickOptions`, `HostFrameInfo` | a declared simulation, above |
642
+ | `useHostAgentObservation` | the simulation's `observe` and `useHostAgentCapture` |
643
+ | `AirJamSyncedStoreHook` | `AirJamStore` from `@air-jam/sdk/core` |
644
+ | `useConnectionStatus()` | `useAirJamHost((s) => s.connectionStatus)` or `useAirJamController((s) => s.connectionStatus)` |
645
+ | `usePlayers()` | `useAirJamHost((s) => s.players)` |
646
+ | `isActiveMatchPhase`, `isEndedMatchPhase`, `isStandardMatchPhase`, `standardMatchPhases` | compare the phase directly; `toShellMatchPhase` stays |
647
+ | `AirJamErrorBoundary`, `PlatformSettingsBoundary` | nothing: `createAirJamApp` and the session runtimes mount both |
648
+ | `getEffectiveAudioVolume`, `useAudioCategoryVolume`, `mergeRoomPlatformSettingsSnapshot` | `useMusicVolume`, `usePlatformAudioSettings` |
649
+ | `parseAirJamGameMetadata` | `airJamGameMetadataSchema.safeParse` |
650
+ | `RoomCode`, `RunMode`, `SignalPayload`, `SignalType`, `ControllerStatePayload`, `ControllerUpdatePlayerProfileAck`, `AirJamActionAccepted`, `AirJamActionRejected` from `@air-jam/sdk` | the same types from `@air-jam/sdk/protocol` |
651
+ | `isInternalActionName`, `resolveControllerJoinSource`, `JoinUrlStatus` from `@air-jam/sdk/core` | internal; `JoinUrlStatus` comes from `@air-jam/sdk` |
652
+ | `buttonVariants`, `getPlayerAvatarImageUrl`, `resolvePlayerAvatarSeed` from `@air-jam/sdk/ui` | `Button`, `PlayerAvatar` |
653
+ | `useInputWriter`, `useControllerTick`, `ControllerTickInfo`, `ControllerTickOptions` | declared controls and the SDK's phone controls, above |
654
+ | `useGetInput`, the host's `getInput` | `input(playerId)` in a simulation step |
655
+
656
+ Tool and platform paths also dropped helpers only the SDK itself used:
657
+ `arcade/bridge/controller` (`AIRJAM_CONTROLLER_BRIDGE_RESPONSE`,
658
+ `AIRJAM_CONTROLLER_PRESENTATION_SYNC`, `createControllerPresentationSyncMessage`,
659
+ `parseControllerBridgeResponseMessage`), `arcade/bridge/host`
660
+ (`AIRJAM_HOST_BRIDGE_RESPONSE`), `arcade/bridge/iframe` (the bridge init and
661
+ settings sync messages), `arcade/surface` (implicit store domain resolution),
662
+ `arcade/url` (`urlBuilder`, `arcadeSurfaceRuntimeUrlParams`, which stays in
663
+ `arcade/surface`), `controller-bridge`, `preview`, `runtime-control`,
664
+ `runtime-inspection`, `agent-tooling` and `metadata`. The
665
+ [architecture guide](./architecture.md) lists what each path
666
+ keeps.
667
+
668
+ ## Related Docs
669
+
670
+ 1. [Quick Start](./quick-start.md)
671
+ 2. [Debugging and Logs](./debugging-and-logs.md)
672
+ 3. [Input System](./input-system.md)
673
+ 4. [Networked State](./networked-state.md)
674
+ 5. [Hooks](./sdk-hooks.md)