Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-agent-session

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Inspect live scenes and frames with devtools; read runtime diagnostics. Use for scoped session writes, pixel probes or duplicate requestId INVALID_ARGUMENT errors.

  • 9 files
  • 34.7 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-agent-session

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesagent-session.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from tools/debug/agent-session.ts, tools/dev/dev-server.cjs, examples/automation/main.ts, src/air/diagnostics.ts on 2026-10-10.

Agent session request protocol (devtools face)

Everything here lives in tools/debug/** and is served by the dev server. It is NOT on the cocosair runtime export and must not be imported from cocosair in shipped app code.

Attach

createAgentSession(options) is the explicit attach factory (tools/debug/agent-session.ts:935). The options shape is { app, writableScenes?, errorBufferLimit?, requestIdWindow?, captureTimeoutMs? } (tools/debug/agent-session.ts:139-149):

  • app is the AirApp instance, normally the same object the page published as window.__airApp.
  • writableScenes is the explicit write scope. Omitted or empty means read-only, and any write to a node outside the listed scenes fails with OUT_OF_SCOPE (tools/debug/agent-session.ts:141, :366-376).
  • Defaults: error buffer 200 (DEFAULT_ERROR_LIMIT, :163), requestId window 256 (DEFAULT_REQUEST_WINDOW, :164), capture timeout 5000ms (DEFAULT_CAPTURE_TIMEOUT, :165).

The dev server compiles these entries on demand and mounts them under /__debug/, keeping cocosair external so the session shares the page's single engine instance (tools/dev/dev-server.cjs:193, :207, :337-341). The automation example attaches with await import('/__debug/agent-session.js') (examples/automation/main.ts:50) and then createAgentSession({ app, writableScenes: [scene] }) (examples/automation/main.ts:89).

Single-request shape

One request is AgentRequest { requestId: string; action: string; targetId?: string; params?: Record<string, unknown> } (tools/debug/agent-session.ts:48-53). dispatch(request) returns a Promise<AgentResponse> where the response is a tagged union of two arms (tools/debug/agent-session.ts:665, :60-68): success is { requestId: string; ok: true; result: unknown }, and failure is { requestId: string; ok: false; error: { code: AgentErrorCode; message: string; cause?: { code?: string; message?: string } } }.

A missing or non-string requestId/action is itself rejected as INVALID_ARGUMENT (tools/debug/agent-session.ts:669-672). A closed session short-circuits every request to SESSION_CLOSED (tools/debug/agent-session.ts:666-668). Non-AgentSessionError throws from an action surface as LOAD_FAILED with the raw message preserved (tools/debug/agent-session.ts:697-705).

Error codes

AgentErrorCode is the frozen minimal set (tools/debug/agent-session.ts:31-38):

Code Meaning Source line
INVALID_ARGUMENT bad/missing params, whitelist miss, or a duplicate requestId tools/debug/agent-session.ts:32
STALE_TARGET unknown id, destroyed node, replaced scene, or no running scene tools/debug/agent-session.ts:33
OUT_OF_SCOPE write target is not inside writableScenes tools/debug/agent-session.ts:34
UNSUPPORTED_ACTION action not in the operation set, or asset lacks instantiate tools/debug/agent-session.ts:35
LOAD_FAILED asset load rejected (glTF code kept in cause) tools/debug/agent-session.ts:36
SESSION_CLOSED session already closed tools/debug/agent-session.ts:37
CAPTURE_FAILED captureFrame timeout, scene swap, or no PNG tools/debug/agent-session.ts:38

requestId retention and FIFO

The retention contract is the most-misread part:

  • A repeat requestId is rejected as INVALID_ARGUMENT while it is still running OR when it settled less than 60s ago (tools/debug/agent-session.ts:673-678; REQUEST_RETENTION_MS = 60_000 at :168). It is NOT an idempotent replay that hands back the original result.
  • Records outside the retention time are garbage-collected on each dispatch (tools/debug/agent-session.ts:680-682).
  • The log is hard-capped at requestIdWindow * 2 entries; over that the oldest key is dropped FIFO (tools/debug/agent-session.ts:683-686), with requestIdWindow defaulting to 256 (:164).

So "256" is the retention-window SIZE default and "60000ms" is the retention TIME; treat both as guardrails against blind write-retries, not as a replay cache.

Write actions

Only whitelisted actions run, dispatched serially so a failure never interleaves (tools/debug/agent-session.ts:151, :689-691):

  • createNode adds a node under a writable parent and returns { nodeId } (tools/debug/agent-session.ts:745-756).
  • addComponent accepts only the COMPONENT_WHITELIST types (MeshRenderer, Camera, DirectionalLight, PointLight, SphereLight, SpotLight, Animation), never an arbitrary string import, and returns { componentId, type } (tools/debug/agent-session.ts:153-161, :758-771).
  • setTransform validates every parameter before applying any, so an illegal request leaves no partial mutation, and it requires params.space to be local or world (tools/debug/agent-session.ts:773-824).
  • loadAsset goes through the public GLTFLoader, holds one session-owned addRef, and never destroys shared cache assets on close (tools/debug/agent-session.ts:826-863).
  • instantiateAsset instantiates a known asset and registers the instance for cleanup (tools/debug/agent-session.ts:865-893).

close() removes listeners and observation hooks, cancels pending captures, destroys session-owned nodes/instances, and only decRefs assets the session itself added; explicit edits made to pre-existing nodes are not rolled back (tools/debug/agent-session.ts:897-931).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "inspect the running scene or node",
  "apply a scoped change through an agent session",
  "capture a frame after drawing",
  "read runtime errors and diagnostics",
  "duplicate requestId is rejected"
]
owns
[
  "agent-session",
  "scene-inspection",
  "scoped-writes",
  "frame-capture",
  "pixel-probes",
  "runtime-diagnostics"
]
not_for
[
  "app startup or shutdown -> cocosair-application",
  "verification gates and release evidence -> cocosair-verification",
  "scene-tree implementation -> cocosair-scene-graph"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用开发工具观察运行时、按明确范围写入、捕获画面和读取诊断。用于实时应用检查或受控自动化,工具不属于默认运行时包。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-agent-session