Derived from the cocosair-agent-session 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
Runtime face (shipped on the cocosair entry):
AirDiagnosticsis an opt-in bounded view of the native diagnostic stream, declared on the main entry (src/air/diagnostics.ts:14; in the SDK declarations it appears onAirAppas an optionaldiagnosticsfield,build/cocosair.module.d.ts, currently :55725). It exposessnapshot(),onMessage(),clear()anddestroy()(src/air/diagnostics.ts:16-20).- Each message is truncated to 600 characters (
src/air/diagnostics.ts:33) and the channel evicts to 80 distinct entries FIFO-style (src/air/diagnostics.ts:42); identical repeats bumpoccurrenceson one bounded record (src/air/diagnostics.ts:37-39). - The factory
createAirDiagnosticsis marked@engineInternal(src/air/diagnostics.ts:23-24) and is NOT exported in the SDK declarations, so app code consumesapp.diagnosticsbut never constructs the channel itself.
Devtools face (tools/debug/**, NOT on the runtime export; validated against source, not the .d.ts):
- Request contract:
AgentRequestis{ requestId, action, targetId?, params? }(tools/debug/agent-session.ts:48-53) and everydispatchresolves to{ requestId, ok: true, result }or{ requestId, ok: false, error: { code, message, cause? } }(tools/debug/agent-session.ts:60-68). Error codes areINVALID_ARGUMENT / STALE_TARGET / OUT_OF_SCOPE / UNSUPPORTED_ACTION / LOAD_FAILED / SESSION_CLOSED, plusCAPTURE_FAILEDfor capture (tools/debug/agent-session.ts:31-38). - Duplicate
requestIdis REJECTED asINVALID_ARGUMENT, not idempotently replayed: a repeat that is still running OR settled within the 60s retention window fails (tools/debug/agent-session.ts:673-678;REQUEST_RETENTION_MS = 60_000at:168). The window count default isDEFAULT_REQUEST_WINDOW = 256(tools/debug/agent-session.ts:164, overridable viarequestIdWindow); records past the retention time are cleared FIFO and the log is hard-capped atrequestIdWindow * 2entries (tools/debug/agent-session.ts:680-686). So 256 is the retention window SIZE, the 60000ms value is the retention TIME, and a blind write-retry never returns the original result. inspectScene()returns aSceneSummarydistinguishingnodeCount,componentCount,componentsByType, camera/light/renderer counts,uniqueAssetCountand a flatnodeslist truncated atINSPECT_ROWS_LIMIT = 500with atruncatedflag (tools/debug/agent-session.ts:451, interface:71-84, limit:167).inspectNode(targetId)returns aNodeSummarywith stable session-localid, parent/children ids, active/layer, component list, local/world transforms and optionalvisualobservations (tools/debug/agent-session.ts:505, interface:86-108).- IDs are stable within a session and keyed by object identity, so two same-named nodes get different ids; a destroyed node or a replaced scene yields
STALE_TARGET(tools/debug/agent-session.ts:399-440). A read-only session mustinspectScenefirst to get its OWN ids before it can address a write (examples/automation/main.ts:170-178). captureFrame()samples on the AFTER_DRAW hook: it subscribes tocc.director'sEVENT_AFTER_DRAW(tools/debug/agent-session.ts:598,:641), which is theDirectorEvent.AFTER_DRAWalias (src/cocos/game/director.ts:109, aliased:240). It snapshots the scene at request time and fails withCAPTURE_FAILEDif the scene was replaced before the draw, times out (default 5000ms), or the canvas yields no PNG (tools/debug/agent-session.ts:606-638).getRuntimeErrors({ since, limit })reads a capacity-bounded ringCollectorkeyed on the app canvas; default limitDEFAULT_ERROR_LIMIT = 200(tools/debug/agent-session.ts:647,:163,:194), returning{ errors, dropped }wheredroppedcounts evictions (tools/debug/agent-session.ts:293-313). Categories includewindow-error,unhandled-rejection,shader,link,session-load,engine-warning,engine-error(tools/debug/agent-session.ts:130-137). The collector prefers the sharedwindow.__airErrorHubdispatch channel and only installs its own window/WebGL hooks when the hub is absent (tools/debug/agent-session.ts:231-278).- Wiring is dev-only:
createAgentSession(options)is the explicit attach factory (tools/debug/agent-session.ts:935); the dev server bundlestools/debug/**entries on demand and serves them under/__debug/, leavingcocosairexternal so the session shares the page's single engine instance (tools/dev/dev-server.cjs:193,:207,:337-341). Theautomationexample demonstrates the full loop, attaching withawait import('/__debug/agent-session.js')(examples/automation/main.ts:50,:89).