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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(play): the first Play runs the code on disk, not the code from project-open
esenginebd23952b6bb7
diff --git a/desktop/electron/agent/kernel.ts b/desktop/electron/agent/kernel.tsindex 983a4ce22..6c87a4619 100644--- a/desktop/electron/agent/kernel.ts+++ b/desktop/electron/agent/kernel.ts@@ -245,12 +245,26 @@ export async function runTurn(if (calls.length === 0) {if (builtSomething && !sawPixels && !askedToLook) {askedToLook = true;+ // What to ask for depends on what this model can perceive. Told to+ // "capture_viewport" a model that cannot receive images did the only+ // sensible thing with the request — it re-read its own source — and+ // reported a game whose ball never launched. A screenshot it cannot+ // see is not verification; running the thing and reading values back+ // is, and that door is open to every model.session.pushContext(- '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, '- + 'drive it with play_input and screenshot that. Then fix what you see, or report.',+ acceptsImages+ ? '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, '+ + '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. You cannot receive images, so '+ + 'do not spend a call on capture_viewport — RUN it instead: toggle_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, '+ + 'and play_probe again to prove they did something. get_logs shows what the '+ + 'running game complained about. Reading your own source again is not this: it '+ + 'is the thing that already convinced you it works.',);continue;}@@ -472,9 +486,14 @@ async function execute(return { outcome, mutated: mutates(tool) && !outcome.isError };}-/** The tools that put PIXELS in front of the model — the only answer to "does it- * look right", which no diagnostic can give. */-const LOOKING_TOOLS = new Set(['capture_viewport', 'screenshot']);+/**+ * The tools that check work against something other than the code that produced+ * it: pixels for a model that can see them, and the running game for every model.+ * No diagnostic answers "does it actually do the thing".+ */+const LOOKING_TOOLS = new Set([+ 'capture_viewport', 'screenshot', 'toggle_play', 'play_probe', 'play_input',+]);/** The scene's outstanding validation issues as one line of context, or null* when there are none (silence is the "still clean" signal). */diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.tsindex da8f67505..a0da447db 100644--- a/desktop/src/playHost.ts+++ b/desktop/src/playHost.ts@@ -443,8 +443,18 @@ async function boot(msg: InitMessage): Promise<void> {// Register the project's own components/systems FIRST (side-effect import; its// `import 'esengine'` resolves through the import map to the shared instance).// Absent (a project with no scripts) → builtin-only, which is fine.+ //+ // Cache-busted like the rebuild path, and for the same reason: the prewarm+ // (`warm()`) imported this URL when the project opened, and an ES module is+ // evaluated ONCE per URL. Everything written between that moment and the+ // first Play — which, in a project being built, is all of it — was already in+ // the bundle on disk and still absent from the realm. The scene then loaded+ // referencing components nothing had registered, and the loader dropped them+ // with a per-entity warning: a board of bricks that draws perfectly and has no+ // Brick on it, every system idle, nothing failed.+ clearUserComponents();try {- await import(/* @vite-ignore */ bundleUrl);+ await import(/* @vite-ignore */ `${bundleUrl}?v=${++reloadSeq}`);} catch {/* no project bundle — builtin components/systems only */}diff --git a/desktop/tests/agent-kernel.test.ts b/desktop/tests/agent-kernel.test.tsindex 4bece8666..d2bcfb054 100644--- a/desktop/tests/agent-kernel.test.ts+++ b/desktop/tests/agent-kernel.test.ts@@ -609,3 +609,47 @@ describe('running out of rounds', () => {expect(warnings).toHaveLength(1);});});++describe('what verification means for a model that cannot see', () => {+ const mkDriver = () => {+ const d = vi.fn(async (method: string) => {+ if (method === 'mark') return { seq: 1 };+ if (method === 'stepsSince') return 0;+ if (method === 'getDiagnostics') return [];+ return null;+ }) as ReturnType<typeof vi.fn> & { js: unknown; op: unknown };+ (d as { js: unknown }).js = vi.fn(async () => null);+ (d as { op: unknown }).op = vi.fn(async () => null);+ return d;+ };++ it('asks a text-only model to RUN the game, not to screenshot it', async () => {+ // Told to capture_viewport, a model that cannot receive images did the only+ // sensible thing with the request — re-read its own source — and reported a+ // game whose ball never launched. A screenshot it cannot see is not a check.+ const s = fakeSession([asks(call('add_entity')), ends(), ends()]);+ await runTurn({+ driver: mkDriver() as never, session: s, model: 'text-only', acceptsImages: false,+ confirm: (async () => ({ answer: 'once' })) as never, emit: () => {},+ }, '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('play_probe');+ expect(nudge).not.toContain('capture_viewport now');+ });++ 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(),+ ]);+ await runTurn({+ driver: mkDriver() as never, session: s, model: 'm', acceptsImages,+ confirm: (async () => ({ answer: 'once' })) as never, emit: () => {},+ }, 'build', null, new AbortController().signal);+ expect([acceptsImages, s.context.some((c) => c.includes('never ran it') || c.includes('not looked at it'))])+ .toEqual([acceptsImages, false]);+ }+ });+});