Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(agent): driving the game is not something to ask permission for

esenginef5a087312d3f
diff --git a/desktop/electron/agent/kernel.ts b/desktop/electron/agent/kernel.ts
index 51f8b9205..d200eb663 100644
--- a/desktop/electron/agent/kernel.ts
+++ b/desktop/electron/agent/kernel.ts
@@ -121,7 +121,7 @@ export interface ContributedTool {
name: string;
description: string;
schema: unknown;
- effect: 'read' | 'undoable' | 'journaled' | 'irreversible';
+ effect: 'read' | 'ephemeral' | 'undoable' | 'journaled' | 'irreversible';
}
/** Why `tool` needs saying out loud. A code — the editor renders the sentence,
@@ -339,9 +339,9 @@ export async function runTurn(
? 'You changed the scene this turn and have not looked at it once. Diagnostics only '
+ 'cover what the editor can name — whether the content is ON CAMERA, whether it '
+ 'reads, whether it is where you meant, are all things only the picture answers. '
- + 'capture_viewport now; if it is something that has to be PLAYED, toggle_play, '
+ + 'capture_viewport now; if it is something that has to be PLAYED, set_play, '
+ 'drive it with play_input and screenshot that. Then fix what you see, or report.'
- : 'You changed the scene this turn and never ran it. RUN it: toggle_play, then '
+ : 'You changed the scene this turn and never ran it. RUN it: set_play, then '
+ 'play_probe to read the state back (`find(NAME)` gives every entity carrying a '
+ 'component, with its data), play_input to drive the controls a player would use, '
+ 'step to advance the frames, and play_probe again to prove they did something. '
@@ -645,7 +645,7 @@ async function execute(
* No diagnostic answers "does it actually do the thing".
*/
const LOOKING_TOOLS = new Set([
- 'capture_viewport', 'screenshot', 'toggle_play', 'play_probe', 'play_input',
+ 'capture_viewport', 'screenshot', 'set_play', 'play_probe', 'play_input',
]);
/** The scene's outstanding validation issues as one line of context, or null
diff --git a/desktop/electron/agent/prompt.ts b/desktop/electron/agent/prompt.ts
index 61d900786..ca7f7d7e7 100644
--- a/desktop/electron/agent/prompt.ts
+++ b/desktop/electron/agent/prompt.ts
@@ -35,7 +35,7 @@ Working style:
- Look before you edit. get_scene_tree, get_inspector and get_document cost one round trip and are the difference between editing the right entity and editing a plausible one.
- You can see the result: capture_viewport renders what the user is looking at, and screenshot takes in the whole window including a running game — as a picture, or, with \`format: 'grid'\`, as a coarse colour grid in TEXT, which is the form to ask for when images cannot reach you. LOOK before you call a visual change done — a material, an effect, a layout, anything whose whole point is what it looks like. Reading back the data you just wrote proves you wrote it, not that it did anything; the difference between "the component says 1.0" and "the sprite is gone" is the entire job.
- To read the RUNNING game, ask by name before you write a probe. find_entities says which entities there are and what each carries; inspect_entity gives ONE of them whole — every component with its live data, which is where physics, AI, animation and UI state all are, because they ARE components. list_resources gives the state that belongs to no entity, and get_systems what runs each frame. None of them is confirmed. play_probe is the escape hatch for what they do not answer, and it costs the user a prompt every time.
-- A game you have built is not tested until you have PLAYED it: toggle_play, then step to advance it (its loop is throttled to about a frame a second whenever the editor window is not the focused one, so waiting shows you a frozen picture of a healthy game), play_input to press the keys a player would, play_probe to read what the game now thinks, and screenshot to see what a player would see. Step-look-step is the loop; twenty probes without a screenshot is how a project ships game-over-on-arrival with every component reporting exactly the value it should.
+- A game you have built is not tested until you have PLAYED it: set_play, then step to advance it BY FRAMES — never by waiting. Its loop is throttled to about a frame a second whenever the editor window is not focused, so waiting shows you a frozen picture of a healthy game; \`step\` moves it exactly and deterministically, and three seconds of game time is step 180, not a pause. Set it \`paused\` first when you want to stage a situation and then advance it a frame at a time. play_input presses the keys a player would, find_entities / inspect_entity read what the game now thinks, and screenshot shows what a player would see. Step-look-step is the loop; twenty probes without a screenshot is how a project ships game-over-on-arrival with every component reporting exactly the value it should.
- Prefer one apply_scene_ops over many small calls when building something: it is one undo step for the user and one round trip for you, and it is the ONE write the user sees BEFORE it lands — they get a line-by-line preview and can strike parts of it out. A dozen set_field calls give them no such chance, so build with a batch and save the single writes for genuinely single changes.
- Units are the editor's: 1 world unit = 1 design pixel. Y is up in the world, and UI is laid out top-down. The world's ORIGIN IS THE CENTRE OF THE VIEW, not a corner: a default camera on a W×H design resolution sees y from −H/2 to +H/2 (its \`orthoSize\` is H/2) and x at least −W/2 to +W/2, wider when the window is. So the bottom of the screen is y = −H/2 and the top is +H/2 — a HUD placed at y = H − 20, or a floor at y = 0, is written in SCREEN coordinates and lands off camera or halfway up. Nothing errors: the entity is there, the fields read back what you wrote, and the picture is empty, which is why the FIRST screenshot of anything you positioned by arithmetic is worth more than the next ten probes.
- Game content lives in the WORLD: a board, its pieces, a character are Sprite / ShapeRenderer entities you place with Transform.position. A Canvas and its UINodes are for HUD and menus, and their placement is the layout's OUTPUT — a Transform.position written on a UI node is overwritten at the next relayout, which looks like nothing happened. Move those with layout inputs instead (UINode.position = Absolute, then left/top), or let the flow place them.
diff --git a/desktop/electron/agent/types.ts b/desktop/electron/agent/types.ts
index cff742b2e..87c8d7d77 100644
--- a/desktop/electron/agent/types.ts
+++ b/desktop/electron/agent/types.ts
@@ -21,7 +21,7 @@ export interface CatalogTool {
name: string;
description: string;
schema: Record<string, unknown>;
- effect?: 'read' | 'undoable' | 'journaled' | 'irreversible';
+ effect?: 'read' | 'ephemeral' | 'undoable' | 'journaled' | 'irreversible';
}
/** One call the model wants made. */
diff --git a/desktop/scripts/editor-capabilities-e2e.mjs b/desktop/scripts/editor-capabilities-e2e.mjs
index eebfe9405..589173244 100644
--- a/desktop/scripts/editor-capabilities-e2e.mjs
+++ b/desktop/scripts/editor-capabilities-e2e.mjs
@@ -151,7 +151,7 @@ const failures = await withEditor(async (ed) => {
check(typeof played?.picture === 'string' && played.picture.length > 20,
`playtest brought back no text picture: ${JSON.stringify(played?.picture)?.slice(0, 120)}`);
console.log(`playtest OK — entered play, probed, ${String(played.picture).length} chars of picture`);
- await ed.call('toggle_play', {}, 60000);
+ await ed.call('set_play', { state: 'playing' }, 60000);
// A capability's failure names the step, not just the message.
const bad = await ed.call('configure_physics_body', { entity: 999999, body: 'dynamic' }, 30000).catch((e) => ({ text: String(e) }));
diff --git a/desktop/scripts/editor-checks/play-stepping.mjs b/desktop/scripts/editor-checks/play-stepping.mjs
index d657abc13..3bdd83c8d 100644
--- a/desktop/scripts/editor-checks/play-stepping.mjs
+++ b/desktop/scripts/editor-checks/play-stepping.mjs
@@ -35,7 +35,7 @@ export async function run(ed) {
const check = checker();
await ed.open(root, 'assets/scenes/main.esscene');
- await ed.call('toggle_play', {}, 120000);
+ await ed.call('set_play', { state: 'playing' }, 120000);
// Ready before stepping: a realm still booting has no app to advance.
let ready = false;
diff --git a/desktop/scripts/editor-checks/soak.mjs b/desktop/scripts/editor-checks/soak.mjs
index b0b39746f..abd037e11 100644
--- a/desktop/scripts/editor-checks/soak.mjs
+++ b/desktop/scripts/editor-checks/soak.mjs
@@ -59,7 +59,7 @@ export async function run(ed) {
const samples = [];
for (let cycle = 0; cycle < CYCLES; cycle++) {
- await ed.call('toggle_play', {}, 120000);
+ await ed.call('set_play', { state: 'playing' }, 120000);
let ready = false;
for (let i = 0; i < 40 && !ready; i++) {
ready = (await ed.json('get_play_state', {}))?.ready === true;
@@ -68,7 +68,7 @@ export async function run(ed) {
if (!check(ready, `cycle ${cycle}: the play realm never reported ready`)) return check.failures;
await ed.call('step', { frames: 10, dt: 1 / 60 }, 60000);
- await ed.call('toggle_play', {}, 120000);
+ await ed.call('set_play', { state: 'playing' }, 120000);
let stopped = false;
for (let i = 0; i < 40 && !stopped; i++) {
stopped = (await ed.json('get_play_state', {}))?.playing === false;
diff --git a/desktop/scripts/editor-mcp-editor-e2e.mjs b/desktop/scripts/editor-mcp-editor-e2e.mjs
index 9f30de1e1..f9a552672 100644
--- a/desktop/scripts/editor-mcp-editor-e2e.mjs
+++ b/desktop/scripts/editor-mcp-editor-e2e.mjs
@@ -282,7 +282,7 @@ try {
await fail('unpack_prefab left the prefab link in place');
console.log('revert_prefab + unpack_prefab OK — re-synced, then detached');
- await call('toggle_play', {}, 60_000);
+ await call('set_play', { state: 'playing' }, 60_000);
let play = null;
for (let i = 0; i < 60; i++) {
play = JSON.parse((await call('get_play_state')).text);
@@ -343,7 +343,7 @@ try {
}
console.log(`schema change OK — fingerprint gate forced a clean restart (${s2.v} -> ${s3.v})`);
- await call('toggle_play', {}, 60_000);
+ await call('set_play', { state: 'playing' }, 60_000);
console.log('play OK — realm ready, screenshot + probe captured, hot reload exercised, stopped');
if (process.env.ESTELLA_E2E_EXPORT === '1') {
diff --git a/desktop/shared/capabilityCatalog.mjs b/desktop/shared/capabilityCatalog.mjs
index b8c32e896..2429226c5 100644
--- a/desktop/shared/capabilityCatalog.mjs
+++ b/desktop/shared/capabilityCatalog.mjs
@@ -152,7 +152,7 @@ export const CAPABILITIES = [
async run(input, call) {
const before = await call('get_play_state', {});
const wasPlaying = before?.playing === true;
- if (!wasPlaying) await call('toggle_play', {});
+ if (!wasPlaying) await call('set_play', { state: 'playing' });
for (const one of input.input ?? []) await call('play_input', one);
diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjs
index a7ac52b94..43fc6de6d 100644
--- a/desktop/shared/toolCatalog.mjs
+++ b/desktop/shared/toolCatalog.mjs
@@ -32,6 +32,11 @@
* STOPS WORKING — which is what makes them actionable rather than decorative:
*
* read observes only. Never gated, never confirmed.
+ * ephemeral drives the PLAY REALM — enters it, steps it, feeds it input.
+ * That realm is thrown away on Stop and the edit World is never
+ * touched, so going back is what Stop already does. Runs
+ * unasked; it is not `read` because it does move something, and
+ * a remote client without writes should not be running games.
* undoable mutates the document through EditorHistory. A built-in agent
* runs these freely: the turn is bracketed by a history
* checkpoint, so one Undo is the whole approval mechanism.
@@ -44,6 +49,12 @@
* (an editor command, a probe evaluated in the running game).
* A built-in agent must get explicit confirmation.
*
+ * `ephemeral` was carved out of the same mistake as `journaled`: three tools
+ * that drive a simulation declared themselves `read`, which is the one thing
+ * they are not, and a fourth sat in `irreversible` for doing something a Stop
+ * undoes. Both readings came from tiering by "does it act" instead of "can it
+ * be taken back".
+ *
* The line between the last two moved once already, and it is worth saying why.
* A file write was called irreversible for as long as nobody kept the bytes it
* overwrote — a property of the editor, not of writing files. Keeping them
@@ -191,16 +202,17 @@ const ATOMS = [
description: 'Viewport pick: the entity a click at (clientX, clientY) would select, or null.',
schema: obj({ clientX: { type: 'number' }, clientY: { type: 'number' } }, ['clientX', 'clientY']),
method: 'pick', args: (i) => [i.clientX, i.clientY] },
- { name: 'set_run_mode',
+ { name: 'set_run_mode', effect: 'ephemeral',
description: 'Run gameplay against the EDIT World (Stop rebuilds it from the model). This is the headless host\'s play; '
- + "in the editor app the project's scripts live in the play realm and not in this World, so there it refuses and names toggle_play — "
+ + "in the editor app the project's scripts live in the play realm and not in this World, so there it refuses and names set_play — "
+ 'which is the one to reach for when the question is "does the game work".',
schema: obj({ playing: { type: 'boolean' }, paused: { type: 'boolean' } }, ['playing']),
method: 'setRunMode', args: (i) => [i.playing, i.paused] },
- { name: 'step',
+ { name: 'step', effect: 'ephemeral',
description: 'Advance by N frames of fixed dt, deterministically — the RUNNING GAME when one is playing, otherwise the edit World. Answers { world: "play" | "edit", frames, dt }, so you can tell which one moved. '
+ 'This is how you watch a game do something: the realm\'s own loop is wall-clock and the editor window is not focused while you drive it, which throttles it to roughly one frame a second — two probes a second apart read identical and a healthy game looks frozen. '
- + 'Step, then read (play_probe) or look (screenshot). A pressed edge from play_input lasts exactly one frame, so step 1 right after it.',
+ + 'Step, then read (inspect_entity) or look (screenshot). A pressed edge from play_input lasts exactly one frame, so step 1 right after it. '
+ + 'Three seconds of game time is `step 180`, never a wait. Verify it moved by reading a value the GAME changes, not `frameCount` — that counts loop frames and keeps counting while a paused realm sits still.',
schema: obj({ frames: { type: 'number' }, dt: { type: 'number' } }),
method: 'step', args: (i) => [i.frames, i.dt] },
{ name: 'resize_viewport',
@@ -539,12 +551,20 @@ const ATOMS = [
}, ['template']),
method: 'createEntity',
args: (i) => [i.template, { parent: i.parent ?? null, x: i.x, y: i.y, name: i.name }], root: 'editor' },
- { name: 'toggle_play',
- description: 'Enter or leave play mode, AWAITED — it resolves once the game realm is ready (or gone) and answers with its state, so there is nothing to poll afterwards. '
- + 'Play runs the game in an isolated realm and never dirties the edit scene. Once in: `step` advances it, `play_input` drives it, `play_probe` reads it, `screenshot` shows it.',
- schema: obj({}), method: 'play', args: () => [], root: 'editor' },
+ { name: 'set_play', effect: 'ephemeral',
+ description: "Put the game in a NAMED state and get the one it reached: 'playing', 'paused', or 'stopped'. AWAITED — it resolves once the realm is up (or gone), so there is nothing to poll. "
+ + "A named state rather than a toggle because a toggle needs you to know where it started, and called twice it is a no-op that reads as a failure. 'paused' from stopped boots the realm and freezes it, which is the state to set up in before stepping. "
+ + 'Play runs the game in an isolated realm and never dirties the edit scene. Once in: `step` advances it by exact frames, `play_input` drives it, `find_entities` / `inspect_entity` read it, `screenshot` shows it.',
+ schema: obj({ state: { type: 'string', description: "'playing' | 'paused' | 'stopped'" } }, ['state']),
+ method: 'setPlay', args: (i) => [i.state], root: 'editor' },
+ { name: 'set_time_scale', effect: 'ephemeral',
+ description: 'How fast the running game\'s clock advances: 1 is normal, 0.25 quarter speed, 0 frozen. Clamped to [0, 16]. '
+ + 'Reach for this to WATCH something too fast to see; to CHECK something, pause and `step` instead — exact frames are deterministic and waiting is not.',
+ schema: obj({ scale: { type: 'number' } }, ['scale']),
+ method: 'setTimeScale', args: (i) => [i.scale], root: 'editor' },
{ name: 'get_play_state',
- description: 'The play realm state: { playing, ready, error, fps, frameCount }. '
+ description: 'The play realm state: { playing, ready, paused, error, fps, frameCount }. '
+ + 'frameCount counts LOOP frames, not simulated ones — a paused realm keeps counting while nothing in the game moves, so it cannot tell you a step happened. To check that, read a value the game changes (inspect_entity / list_resources) before and after. '
+ 'CHECK `fps` BEFORE CONCLUDING ANYTHING FROM A PROBE: the realm runs in an out-of-process iframe whose rAF Chromium throttles to ~1/s while the editor window is unfocused, '
+ 'so a game that looks frozen (an animation that never advances, a tween stuck at its start) is usually a background window, not a bug. `fps` is null until the first heartbeat (~0.5s after Play).',
schema: obj({}), method: 'playState', args: () => [], root: 'editor' },
@@ -650,7 +670,7 @@ const ATOMS = [
+ 'Use play_input, not synthetic DOM events, to drive input. frame picks the realm in multiplayer previews (0 = host).',
schema: obj({ code: { type: 'string' }, frame: { type: 'number' } }, ['code']),
op: 'play_probe' },
- { name: 'play_input', effect: 'irreversible',
+ { name: 'play_input', effect: 'ephemeral',
description: 'Deliver a pointer or key event to the RUNNING game — the only way to exercise the input a game actually ships with. '
+ "`kind`: 'click' (down+up at x,y), 'move', 'down', 'up', 'wheel', 'key_down', 'key_up', 'tap' (touch down+up). "
+ 'x/y are SCREEN pixels, canvas-relative, y DOWN — the same numbers a real pointer event carries and what `Input.mouseX/mouseY` then read; '
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsx
index 9f289b118..0ee1e5f99 100644
--- a/desktop/src/components/AgentDrawer.tsx
+++ b/desktop/src/components/AgentDrawer.tsx
@@ -25,7 +25,7 @@
*/
import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
import {
- X, Plus, PanelRight, ArrowUp, Square, ChevronRight, ChevronDown, Check, TriangleAlert,
+ X, Plus, PanelRight, ArrowUp, Square, ChevronRight, ChevronDown, Check, TriangleAlert, Play,
Loader, Copy, Pencil, Eye, FileText, KeyRound, Boxes, Stethoscope, Image as ImageIcon, ImageOff, RotateCcw,
File as FileIcon, ArrowRight, History as HistoryIcon, Trash2, FoldVertical,
} from 'lucide-react';
@@ -101,6 +101,7 @@ const ASKING = 'ag-asking';
// which is why it is not the amber warning.
const TOOL_ICON: Record<string, typeof Eye> = {
read: Eye,
+ ephemeral: Play,
undoable: Pencil,
journaled: FileText,
irreversible: TriangleAlert,
diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.ts
index 8b75ac4be..2922d905f 100644
--- a/desktop/src/engine/EditorControlSurface.ts
+++ b/desktop/src/engine/EditorControlSurface.ts
@@ -368,12 +368,12 @@ export class EditorControlSurfaceImpl {
// flips, so "playing" here starts a world with no gameplay in it — and the
// honest `false` it returned (it means "no Stop rebuild happened", not
// "failed") reads as a refusal, so a caller retries, then reaches for
- // toggle_play, and by then both notions of play are half-on. Say which door
+ // set_play, and by then both notions of play are half-on. Say which door
// it is. The headless host has no realm and keeps this one.
if (typeof window !== 'undefined' && '__estellaEditor' in window) {
throw new Error(
'set_run_mode drives the edit World, which does not have the project\'s game scripts — '
- + "in the editor they are bundled into the play realm. Use toggle_play to run the game "
+ + "in the editor they are bundled into the play realm. Use set_play to run the game "
+ '(get_play_state reports it, screenshot sees it), and step() to advance the edit World '
+ 'a frame without playing.',
);
diff --git a/desktop/src/engine/PlayRealm.ts b/desktop/src/engine/PlayRealm.ts
index acc5dcba0..f9bf8e8f2 100644
--- a/desktop/src/engine/PlayRealm.ts
+++ b/desktop/src/engine/PlayRealm.ts
@@ -47,6 +47,9 @@ function withTimeout<T>(p: Promise<T>, ms: number, message: string): Promise<T>
export interface PlayRealmSnapshot {
playing: boolean;
ready: boolean;
+ /** Frozen where it stands — the realm is up, its loop is not advancing. A
+ * paused realm still answers every query and still takes `step`. */
+ paused: boolean;
error: string | null;
/** Frames per second the realm is ACTUALLY running, from its own heartbeat. An
* unfocused window has the realm's rAF throttled to about 1 — which looks exactly
@@ -73,7 +76,7 @@ export class PlayRealmInstance {
private warm = false;
private warmedResolve: (() => void) | null = null;
private readonly store = createStore<PlayRealmSnapshot>(() => ({
- playing: false, ready: false, error: null, fps: null, frameCount: 0,
+ playing: false, ready: false, paused: false, error: null, fps: null, frameCount: 0,
}));
constructor(readonly id: number) {}
@@ -142,7 +145,7 @@ export class PlayRealmInstance {
async start(payload: PlayPayload, netPorts?: MessagePort[]): Promise<void> {
this.payload = payload;
this.netPorts = netPorts ?? null;
- this.set({ playing: true, ready: false, error: null });
+ this.set({ playing: true, ready: false, paused: false, error: null });
// Time Play-click → first frame. Only the primary realm profiles (a
// multiplayer session's client realms would clobber the shared singleton).
if (this.id === 0) bootProfiler.begin('play (click → first frame)');
@@ -210,7 +213,7 @@ export class PlayRealmInstance {
if (this.warm && this.id === 0) {
if (this.iframe) this.iframe.style.visibility = 'hidden';
this.setPaused(true); // freeze the world so a hidden realm doesn't keep simulating
- this.set({ playing: false, ready: false, error: null, fps: null, frameCount: 0 });
+ this.set({ playing: false, ready: false, paused: false, error: null, fps: null, frameCount: 0 });
return;
}
if (this.iframe) {
@@ -218,7 +221,7 @@ export class PlayRealmInstance {
this.iframe.src = 'about:blank';
}
this.warm = false;
- this.set({ playing: false, ready: false, error: null, fps: null, frameCount: 0 });
+ this.set({ playing: false, ready: false, paused: false, error: null, fps: null, frameCount: 0 });
}
/** Drop the staged realm but keep the iframe + listener (reusable): cold
@@ -243,7 +246,14 @@ export class PlayRealmInstance {
this.iframe = null;
}
+ /** How fast this realm's clock runs; 1 is normal. Not a pause — a scale of 0
+ * still runs the loop, and `step` still moves it by exact frames. */
+ setTimeScale(scale: number): void {
+ this.post({ type: 'estella:play:setTimeScale', scale });
+ }
+
setPaused(paused: boolean): void {
+ this.set({ paused });
this.post({ type: 'estella:play:setPaused', paused });
}
@@ -340,7 +350,14 @@ export class PlayRealmInstance {
if (!this.iframe?.contentWindow || !this.store.getState().ready) return Promise.resolve(null);
const reqId = ++this.reqSeq;
return new Promise((resolve) => {
- this.pending.set(reqId, (data) => resolve((data as PlayStepReply) ?? null));
+ this.pending.set(reqId, (data) => {
+ const reply = (data as PlayStepReply) ?? null;
+ // The counter otherwise comes only from the loop's heartbeat, which a
+ // PAUSED realm stops sending — so a hand-stepped realm reported the
+ // count it froze at, and a step measured through it measured nothing.
+ if (reply?.frameCount !== undefined) this.set({ frameCount: reply.frameCount });
+ resolve(reply);
+ });
this.post({ type: 'estella:play:query', kind: 'step', reqId, frames, dt });
setTimeout(() => { if (this.pending.delete(reqId)) resolve(null); }, 30000);
});
@@ -526,6 +543,11 @@ class PlayRealmsManager {
this.bumpSession();
}
+ setTimeScale(scale: number): void {
+ this.primary.setTimeScale(scale);
+ for (const c of this.clients_) c.setTimeScale(scale);
+ }
+
setPaused(paused: boolean): void {
this.primary.setPaused(paused);
for (const c of this.clients_) c.setPaused(paused);
diff --git a/desktop/src/engine/playProtocol.ts b/desktop/src/engine/playProtocol.ts
index 9f679f2f1..ac9fa2df2 100644
--- a/desktop/src/engine/playProtocol.ts
+++ b/desktop/src/engine/playProtocol.ts
@@ -159,6 +159,9 @@ export type PlayOutbound =
// is a warm scene load, not a cold engine bring-up. Replied with `warmed`.
| { type: 'estella:play:warm' }
| { type: 'estella:play:setPaused'; paused: boolean }
+ // How fast the realm's clock advances; 1 is normal. Distinct from paused:
+ // a scale of 0 still runs the loop, and `step` still moves it by frames.
+ | { type: 'estella:play:setTimeScale'; scale: number }
| { type: 'estella:play:reload' }
// `withTree: false` = detail-only snapshot (skip the O(entities) tree walk).
| {
diff --git a/desktop/src/main.tsx b/desktop/src/main.tsx
index f2a25be72..b0b6af62f 100644
--- a/desktop/src/main.tsx
+++ b/desktop/src/main.tsx
@@ -297,6 +297,43 @@ function buildEditorAutomation(): unknown {
await new Promise((r) => setTimeout(r, 100));
}
},
+ /**
+ * Put the game in a NAMED state and answer with the one it reached. A
+ * toggle needs the caller to know where it started, and called twice reads
+ * as a failure. `paused` from stopped boots the realm and freezes it, so
+ * "set up, then step" is one call rather than a race.
+ */
+ setPlay: async (state: 'playing' | 'paused' | 'stopped') => {
+ const now = () => PlayRealm.getSnapshot();
+ const settle = async (done: () => boolean) => {
+ const deadline = Date.now() + 60_000;
+ while (!done() && !now().error && Date.now() < deadline) {
+ await new Promise((r) => setTimeout(r, 100));
+ }
+ };
+ // Awaited like the other direction. Reading the state straight after the
+ // toggle answered `playing: true` to someone who had just asked for it to
+ // stop, which is a lie they then act on.
+ if (state === 'stopped') {
+ if (now().playing) useEditorStore.getState().togglePlay();
+ await settle(() => !now().playing);
+ return now();
+ }
+ if (!now().playing) {
+ useEditorStore.getState().togglePlay();
+ await settle(() => now().playing && now().ready);
+ }
+ // Paused LAST, so it applies to a realm that is up rather than to one
+ // still booting, which would come up running.
+ PlayRealm.setPaused(state === 'paused');
+ return now();
+ },
+ /**
+ * How fast the running game's clock advances: 1 is normal, 0.25 quarter
+ * speed. It does NOT stop the loop — `paused` does that, and `step` moves a
+ * paused realm by exact frames, which is what a deterministic check wants.
+ */
+ setTimeScale: (scale: number) => PlayRealm.setTimeScale(scale),
playState: () => PlayRealm.getSnapshot(),
/**
* Where the picture worth taking is, in CSS pixels, with the window's own size so
diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.ts
index 883a5fe48..5cb5cb3ad 100644
--- a/desktop/src/playHost.ts
+++ b/desktop/src/playHost.ts
@@ -790,6 +790,11 @@ window.addEventListener('message', (e: MessageEvent) => {
case 'estella:play:setPaused':
app?.setPaused(!!data.paused);
break;
+ case 'estella:play:setTimeScale':
+ // Clamped: a negative clock runs the game backwards through systems that
+ // assume dt > 0, and a huge one spends the frame budget in one step.
+ app?.setPlaySpeed(Math.max(0, Math.min(16, Number(data.scale ?? 1))));
+ break;
case 'estella:play:reload':
void reload();
break;
diff --git a/desktop/src/plugins/types.ts b/desktop/src/plugins/types.ts
index c6283e1fc..55a0d4f44 100644
--- a/desktop/src/plugins/types.ts
+++ b/desktop/src/plugins/types.ts
@@ -387,7 +387,7 @@ export interface AgentToolContribution {
* Declare it honestly — nothing verifies it. A tool calling itself
* `journaled` while writing outside `ctx.fs` claims a net not holding it.
*/
- effect?: 'read' | 'undoable' | 'journaled' | 'irreversible';
+ effect?: 'read' | 'ephemeral' | 'undoable' | 'journaled' | 'irreversible';
/** Do the work. Whatever it returns is JSON-encoded for the model; throwing
* reports the message as a failed call, which the model can act on. */
run(input: unknown): unknown | Promise<unknown>;
diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.ts
index c1890ccd8..c48ed0349 100644
--- a/desktop/src/store/AgentStore.ts
+++ b/desktop/src/store/AgentStore.ts
@@ -34,7 +34,7 @@ import { t } from '@/i18n';
export type { AgentStatus, AgentEvent };
-export type AgentEffect = 'read' | 'undoable' | 'journaled' | 'irreversible';
+export type AgentEffect = 'read' | 'ephemeral' | 'undoable' | 'journaled' | 'irreversible';
/**
* Where a call is. `queued` is the model having asked for it while an earlier
diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.css
index 5495f1185..03666bc6c 100644
--- a/desktop/src/theme/agent.css
+++ b/desktop/src/theme/agent.css
@@ -288,6 +288,7 @@
that reached the disk, and the one that cannot be taken back. Success is not
a colour — it is the result in `out`, and tinting every finished row green
makes the rows that matter harder to find. */
+.ag-call-e--ephemeral .ag-call-g { color: var(--run); }
.ag-call-e--undoable .ag-call-g { color: var(--text-dim); }
.ag-call-e--journaled .ag-call-g { color: var(--text); }
.ag-call-e--irreversible .ag-call-g { color: var(--warn); }
diff --git a/desktop/tests/agent-brief-compiles.test.ts b/desktop/tests/agent-brief-compiles.test.ts
index 9f638f307..93083b79f 100644
--- a/desktop/tests/agent-brief-compiles.test.ts
+++ b/desktop/tests/agent-brief-compiles.test.ts
@@ -91,7 +91,7 @@ describe("the agent's brief", () => {
// A Breakout dogfood spent 75 of its 158 calls probing component data and none
// looking, and delivered a game that is GAME OVER within half a second — every
// value it read was exactly what it should have been.
- for (const taught of ['toggle_play', 'step', 'play_input', 'play_probe', 'screenshot']) {
+ for (const taught of ['set_play', 'step', 'play_input', 'inspect_entity', 'screenshot']) {
expect([taught, SYSTEM_PROMPT.includes(taught)]).toEqual([taught, true]);
}
expect(SYSTEM_PROMPT).toMatch(/not tested until you have PLAYED it/);
diff --git a/desktop/tests/agent-kernel.test.ts b/desktop/tests/agent-kernel.test.ts
index 7e87da652..10644fd49 100644
--- a/desktop/tests/agent-kernel.test.ts
+++ b/desktop/tests/agent-kernel.test.ts
@@ -967,7 +967,7 @@ describe('what verification means for a model that cannot see', () => {
}, 'build a game', null, new AbortController().signal);
const nudge = s.context.find((c) => c.includes('never ran it'));
expect(nudge).toBeTruthy();
- expect(nudge).toContain('toggle_play');
+ expect(nudge).toContain('set_play');
expect(nudge).toContain('play_probe');
expect(nudge).not.toContain('capture_viewport now');
});
@@ -975,7 +975,7 @@ describe('what verification means for a model that cannot see', () => {
it('counts running the game as having checked, for either kind of model', async () => {
for (const acceptsImages of [true, false]) {
const s = fakeSession([
- asks(call('add_entity')), asks(call('toggle_play')), asks(call('play_probe')), ends(),
+ asks(call('add_entity')), asks(call('set_play', { state: 'playing' })), asks(call('play_probe')), ends(),
]);
await runTurn({
driver: mkDriver() as never, session: s, model: 'm', acceptsImages,
diff --git a/desktop/tests/capabilities.test.ts b/desktop/tests/capabilities.test.ts
index 3b8feb71d..82e9a95d9 100644
--- a/desktop/tests/capabilities.test.ts
+++ b/desktop/tests/capabilities.test.ts
@@ -63,7 +63,7 @@ describe('the capability catalog', () => {
});
it('declares an effect no gentler than the steps it runs', () => {
- const severity: Record<string, number> = { read: 0, undoable: 1, journaled: 2, irreversible: 3 };
+ const severity: Record<string, number> = { read: 0, ephemeral: 1, undoable: 2, journaled: 3, irreversible: 4 };
const byName = new Map((ATOMS as Tool[]).map((t) => [t.name, t]));
for (const { name, effect, steps } of capabilityStepNames() as Array<{ name: string; effect: string; steps: string[] }>) {
for (const step of steps) {
@@ -292,7 +292,7 @@ describe('playtest', () => {
});
expect(calls.map((c) => c.method)).toEqual([
- 'playState', 'play', 'play_input', 'step', 'play_probe', 'screenshot',
+ 'playState', 'setPlay', 'play_input', 'step', 'play_probe', 'screenshot',
]);
expect(JSON.parse(text(res))).toMatchObject({ enteredPlay: true, probe: '42', picture: 'AAAA\nBBBB' });
});
diff --git a/desktop/tests/editor-mcp-tools.test.ts b/desktop/tests/editor-mcp-tools.test.ts
index 91c2f13e7..6a7845af4 100644
--- a/desktop/tests/editor-mcp-tools.test.ts
+++ b/desktop/tests/editor-mcp-tools.test.ts
@@ -147,7 +147,7 @@ describe('editor MCP tool registry', () => {
// tool that reaches the FILESYSTEM is on the side undo cannot rescue.
it('every tool declares a tier the gates understand', () => {
for (const t of TOOLS as Array<{ name: string; effect?: string }>) {
- expect(['read', 'undoable', 'journaled', 'irreversible', undefined]).toContain(t.effect);
+ expect(['read', 'ephemeral', 'undoable', 'journaled', 'irreversible', undefined]).toContain(t.effect);
}
});
@@ -165,6 +165,19 @@ describe('editor MCP tool registry', () => {
}
});
+ // Not a read and not irreversible: the realm is thrown away on Stop, so
+ // going back is what Stop already does. Three of these declared `read` while
+ // moving something; one charged a prompt for what a Stop undoes.
+ it('tiers driving the play realm as ephemeral', () => {
+ for (const name of ['set_play', 'step', 'play_input', 'set_time_scale', 'set_run_mode']) {
+ expect([name, toolNamed(name).effect]).toEqual([name, 'ephemeral']);
+ // Still a mutation for the remote gate — a read-only client is not one
+ // that gets to boot somebody's game.
+ expect([name, mutates(toolNamed(name))]).toEqual([name, true]);
+ expect([name, irreversible(toolNamed(name))]).toEqual([name, false]);
+ }
+ });
+
it('what leaves the project, or runs code nobody enumerated, stays irreversible', () => {
// A new project tree elsewhere and a build output are outside the root the
// journal is scoped to; the arbitrary-code doors do whatever the caller
diff --git a/tools/check-capabilities.mjs b/tools/check-capabilities.mjs
index f5cc38d29..f3a052e64 100644
--- a/tools/check-capabilities.mjs
+++ b/tools/check-capabilities.mjs
@@ -36,7 +36,7 @@ const { CAPABILITIES, capabilityStepNames } = await import(
pathToFileURL(path.join(SHARED, 'capabilityCatalog.mjs')).href
);
-const SEVERITY = { read: 0, undoable: 1, journaled: 2, irreversible: 3 };
+const SEVERITY = { read: 0, ephemeral: 1, undoable: 2, journaled: 3, irreversible: 4 };
const atomByName = new Map(ATOMS.map((t) => [t.name, t]));
const problems = [];