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.

referencesvisual-probes.md

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

Derived from tools/debug/agent-session.ts, src/cocos/game/director.ts, tools/debug/pixel-regions.mjs, tools/debug/panel.ts on 2026-10-10.

Visual probes: capture timing and pixel regions

These are devtools-side observation helpers. They are not on the runtime export; drive them from a session attached through the dev server.

captureFrame and the AFTER_DRAW hook

session.captureFrame() returns a Promise<FrameCapture> sampled at a controlled point after the engine has committed a draw (tools/debug/agent-session.ts:589). The timing hook is the director's AFTER_DRAW event: the session subscribes to cc.director's EVENT_AFTER_DRAW and reads the canvas inside that callback (tools/debug/agent-session.ts:598, :641). AFTER_DRAW is the DirectorEvent.AFTER_DRAW value emitted once per tick after the draw pass (src/cocos/game/director.ts:109, aliased as Director.EVENT_AFTER_DRAW at :240, emitted at :821).

Guarantees encoded in the implementation:

  • The scene is snapshotted at request time; if it is replaced before the draw fires, capture rejects with CAPTURE_FAILED rather than returning another scene's frame (tools/debug/agent-session.ts:592, :616-619).
  • A timer rejects with CAPTURE_FAILED if no rendered frame arrives within captureTimeoutMs (default 5000ms) (tools/debug/agent-session.ts:606-609, :148).
  • The PNG is read via canvas.toDataURL('image/png'); a non-PNG result throws and is reported as CAPTURE_FAILED (tools/debug/agent-session.ts:622-625).
  • Closing the session cancels any pending capture (listener and timer) and rejects it with SESSION_CLOSED (tools/debug/agent-session.ts:612-614, :906-910).
  • The result carries png, width, height, sceneId, a monotonic frameIndex, and sampledAt (tools/debug/agent-session.ts:626-633, interface :120-128).

The frame-diff discipline: capture before and after a known-visible change and assert the two PNGs differ and frameIndex advanced, so a stale screenshot can never stand in for a new frame (examples/automation/main.ts:182-201). The panel exposes capture as an explicit AFTER_DRAW read (tools/debug/panel.ts:212).

Pixel-region conventions (tools/debug/pixel-regions.mjs)

measurePixelRegions(image, regions, options) is a dependency-free metric over RGBA bytes; it is a devtool helper, not a runtime API (tools/debug/pixel-regions.mjs:5).

  • Input image must be { width, height, data } with data.length === width * height * 4 (tools/debug/pixel-regions.mjs:7-8).
  • Rectangles are { x, y, w, h }; x/y must be finite and w/h positive, and each is clamped to the image bounds (tools/debug/pixel-regions.mjs:13-18).
  • Origin: screenshot bytes use a top-left origin (the default); raw gl.readPixels bytes use bottom-left because GL rows are inverted (tools/debug/pixel-regions.mjs:5, :9, :11). measureCanvasRegions reads the WebGL2 framebuffer and forces bottom-left for you (tools/debug/pixel-regions.mjs:47-54).
  • lit is not absolute brightness: for each region the modal (dominant, 4-bit-binned, sampled on a 2px stride) background is computed, and litPixels counts samples whose RGB distance from that background exceeds distance (default 30) (tools/debug/pixel-regions.mjs:19-40). The result per region is { rect, litRatio, litPixels, background } (tools/debug/pixel-regions.mjs:41-42).
  • A canvas read must happen after a committed engine draw, before the browser discards the buffer, which is exactly the AFTER_DRAW window the session capture uses (tools/debug/pixel-regions.mjs:46).

Rule of thumb: pass a screenshot PNG through measurePixelRegions with the default top-left origin, and pass a live canvas through measureCanvasRegions (it handles the bottom-left flip); never mix the two origins.

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