Skip to content

Development source guide · workspace 0.1.0

Inspect and test a running game

The native control harness lets you pause a game, inject device-style inputs, advance updates, request state and capture output. It is especially useful for answering a narrow question such as “does one press change this value?” without relying on a timed sequence of desktop clicks.

The harness must be enabled when the game starts. It is not an always-running remote service, and it is not available as a native socket server inside browser builds.

Start a controlled native session

After creating the first scene, run this from the original working folder:

AIGAME_HARNESS=auto AIGameEngine run --project ./first-game

Keep that game process running. In another shell, make the same CLI available, return to the same working folder and request state:

AIGameEngine ctl ./first-game state

auto derives an address from the game's working directory. The CLI's project run uses the project directory, so passing that same project to ctl selects the intended address. On Unix the automatic address is a private local socket; other native environments use a loopback address. Explicit socket paths or loopback TCP addresses can also be supplied.

Warning. Do not launch concurrent controlled games with the same address. The Unix listener replaces an existing socket pathname at startup. A successful game window does not prove its listener bound successfully; check the launch output if connection fails.

Pause, press, advance and release

Begin with separate commands so each reply is easy to inspect:

AIGameEngine ctl ./first-game pause
AIGameEngine ctl ./first-game k ArrowRight d
AIGameEngine ctl ./first-game step 60
AIGameEngine ctl ./first-game k ArrowRight u
AIGameEngine ctl ./first-game state

For the first-scene example, the intended result is 60 controlled updates with the right arrow held, moving the cube by approximately two world units along X. That follows from the example's speed and the harness's fixed 1/60-second updates; it was not measured in a runtime session for this guide.

Release held controls even if an experiment fails. Disconnecting ctl does not clear injected input. To continue normal updates:

AIGameEngine ctl ./first-game resume

Understand the timing rules

Command Effect
pause Stops game updates while rendering can continue
step n For positive n, pauses, advances n host updates and remains paused
wait n Advances n updates while retaining the current playing/paused status
resume or harness play Returns to playing updates
step 0 or wait 0 Immediate acknowledgment; step 0 does not pause

A host update includes game update, any linked physics synchronization, input cleanup and tick advancement. Several paused steps can execute before the next presented image; stepping 60 updates is not a promise to render or capture 60 intermediate frames.

A tap presses immediately and releases after the next update. When already paused, a tap does not advance time by itself. Step between separate taps if you want the game to consume each one distinctly.

Real window input can still arrive during a controlled session. Avoid touching controls during a reproducibility experiment. Fixed update time improves repeatability; it does not automatically control every game's randomness or restore all of its state.

Inspect text before pictures

state asks the game for its state description. A custom game can return a useful domain-specific snapshot. The standard fallback contains a tick, an entity count and rounded positions of existing transform objects; it is not a full game save.

frame writes the game's textual frame description:

AIGameEngine ctl ./first-game frame frame.txt

The default description is empty. A useful UI/render summary requires the game to implement it. A description cached during drawing can also lag an immediately preceding step, so do not assume it reflects a new render that has not happened yet.

For a controlled image, pause first, then request:

AIGameEngine ctl ./first-game shot capture.png

The capture is fulfilled after rendering. Check the reply for a capture or filesystem error. Relative paths are relative to the running game's working directory, so this example writes inside first-game. Neither frame nor shot creates missing parent folders. Choose new filenames if you need to preserve previous diagnostics.

Use a short command script

A harness script contains protocol commands, not shell commands:

pause
k ArrowRight d
step 60
k ArrowRight u
state
shot capture.png

Save it as a UTF-8 file such as steps.txt. On a Linux environment with the required virtual-display tools, the CLI can manage a separate temporary session:

AIGameEngine play --project ./first-game --script ./steps.txt

This is a launch-and-control workflow, not an attach command. It builds unless an explicit executable is selected, starts a virtual display, pauses the game, runs the script and closes or kills its game process afterward. The default script source is stdin; the default display size is 1280×720. Use ctl instead when you want to keep an existing window running.

In development. The virtual-display helpers have shared-resource/concurrency limitations. Use one such diagnostic session at a time. Do not treat them as an isolated multi-job test farm.

Recognize errors and limits

The command protocol returns one reply per line: ok, err ... or state text. ctl prints an error reply without necessarily turning it into a failing process exit. Inspect the reply, not only the shell status. Managed scripts can continue after invalid commands.

The CLI can split a command argument on semicolons, but shell separators must be quoted. Avoid this shorthand for JSON or filenames containing semicolons because the splitter does not understand their meaning. Separate invocations are clearer while learning.

There are device-injection commands for mouse, gamepad and touch; see the reference. There is no generic harness command that supplies your game's missing combat, inventory, spawn or teleport implementation.

Finally, a screenshot proves an image was captured, not that all gameplay works. A state response proves only what that game's state hook reports. Understand snapshot and save limits before relying on a restored test state.