Derived from the cocosair-application skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.
Contracts
- Canvas admission: the browser main entry may be imported before canvas creation. Pass a selected attached canvas to createAirApp; parameter admission precedes PAL screen/input binding. Custom IDs are retained; do not assign pre-import globals or use removed light package entries.
- One runtime per document: admission state lives in
globalThis[Symbol.for('cocosair.bootstrap.v1')]with statusidle | initializing | ready | failed | closed(src/air/app-config.ts:16-30). Identical normalized options share the init Promise and the app; any difference in the compared fields rejectsAIR_E_APP_CONFLICT;closedrejectsAIR_E_APP_CLOSED;failedrejectsAIR_E_APP_RELOAD_REQUIRED(:149-157).equalAirOptions(:114-121) compares thecanvas/containerelements and thecontextLoss.reload/contextLoss.onEventcallbacks by identity, the remaining scalars and the threedesignResolutionnumbers by value, so a fresh inline arrow in a secondcreateAirAppcall rejectsAIR_E_APP_CONFLICT- pass a stable options object. Rebuilding the low-level runtime requires a whole-page reload. - Option ranges are hard, not advisory:
renderModemust be an integer 0..3 (engineWEBGPU = 4is rejected at the AIR surface, and1/CANVASpasses validation but starts no device - see the renderMode rows in app-options.md and startup-errors.md),pixelRatioCapa finite positive number (default 2, or a usable__CCDPR_CAP__),designResolution.policyone of 0..4 with finite positive width/height (src/air/app-config.ts:63-75). Out of range throws; nothing is clamped or ignored. - Startup is a fixed pipeline, and the DPR cap only counts when it lands before the PAL evaluates: context-health attach -> diagnostics channel -> physics selector ->
game.init->view.setDesignResolutionSize-> the caller's firstrun(), with teardown before rethrow on init failure, theAIR_E_PIXEL_RATIO_IMPORT_ORDER/AIR_E_CANVAS_IMPORT_ORDERchecks and theround(CSS size * min(devicePixelRatio, cap))buffer formula all line-cited in app-options.md (Startup order). - Lifecycle gates in
run()fire in this code order (src/air/app.ts:135-159): closed ->AIR_E_APP_CLOSED; release in flight ->AIR_E_SCENE_RELEASING; previous release failed ->AIR_E_SCENE_RELEASE_FAILED; not a valid nativeScene->AIR_E_SCENE; re-running the current scene -> silent no-op (:140), checked before the ownership gate; only a replacement scene then meetsAIR_E_SCENE_RELEASE_REQUIREDwhile the current scope owns cleanup callbacks (:141-143).close()pauses the loop, releases the scene, destroys context-health and diagnostics listeners and marks the registry closed only when this app is the registry's app (src/air/app.ts:202-203); it does not restore a lost GL context and does not make the document reusable. Tables: app-options.md and startup-errors.md. - Cleanup is cooperative with a hard deadline and context health never self-heals:
session.dispose()defaults to 5000 ms and accepts only(0, 5000], andown()returns a function that unregisters the callback and never runs it (src/air/session-scope.ts:50-55,:66-71; session-scope.md);webglcontextrestoredtransitionsrestoringthen immediatelyfailed, because no GPU resource is rebuilt (src/air/context-health.ts:171-177; context-health.md). - Capability layers stay separate: consult build/cocosair.module.d.ts and the installed main exports for API shape; source/bundle presence does not establish current browser verification. There are no separate startup declarations.