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
feat(agent): a claim left for a person, and one that was already true, stop carrying a turn
yhha04d4a7fcc11
diff --git a/desktop/electron/agent/acceptance.ts b/desktop/electron/agent/acceptance.tsindex 7e76abb14..d3d5cec30 100644--- a/desktop/electron/agent/acceptance.ts+++ b/desktop/electron/agent/acceptance.ts@@ -24,6 +24,16 @@ import type { AcceptanceCriterion } from '../../src/project/format';*/export type Criterion = AcceptanceCriterion;+/**+ * A criterion as the TURN declared it, plus what asking it at that moment+ * answered. `heldBefore` is a claim that was already true before any work: it+ * still gets checked, and it can still break, but it cannot be the thing that+ * says the work happened.+ */+export interface DeclaredCriterion extends Criterion {+ heldBefore?: boolean;+}+/*** Who the claim belongs to, which is what decides whether it can PASS a turn.*@@ -39,7 +49,7 @@ export type CriterionOwner = 'editor' | 'project' | 'turn';* because keeping one means writing it into the project as it stands.* `unsettled` is neither pass nor fail: nothing was in a position to answer it.*/-export interface CriterionResult extends Criterion {+export interface CriterionResult extends DeclaredCriterion {state: 'held' | 'broke' | 'unsettled';/** What it answered, or why nothing could answer it. */detail?: string;@@ -106,7 +116,7 @@ export function criteriaProblem(criteria: unknown): string | null {*/export async function evaluate(deps: KernelDeps,- criteria: readonly Criterion[],+ criteria: readonly DeclaredCriterion[],): Promise<Acceptance> {const standing = deps.standing?.() ?? [];const results: CriterionResult[] = [@@ -114,11 +124,20 @@ export async function evaluate(...await declaredChecks(deps, standing, 'project'),...await declaredChecks(deps, criteria, 'turn'),];+ return { verdict: verdictOf(results), results };+}++/**+ * The verdict a set of results comes to: `passed` needs a claim of the turn's+ * OWN that held and was not already holding, and nothing of the turn's left+ * hanging. Exported because a claim only a person can settle is settled later,+ * in the window, and a second reading of the rule there is a second answer.+ */+export function verdictOf(results: readonly CriterionResult[]): Verdict {const claims = results.filter((r) => r.owner === 'turn');- const verdict: Verdict = results.some((r) => r.state === 'broke') ? 'failed'- : claims.some((r) => r.state === 'held') ? 'passed'- : 'unverified';- return { verdict, results };+ if (results.some((r) => r.state === 'broke')) return 'failed';+ if (claims.some((r) => r.state === 'unsettled')) return 'unverified';+ return claims.some((r) => r.state === 'held' && !r.heldBefore) ? 'passed' : 'unverified';}async function editorChecks(deps: KernelDeps): Promise<CriterionResult[]> {@@ -164,7 +183,7 @@ async function editorChecks(deps: KernelDeps): Promise<CriterionResult[]> {async function declaredChecks(deps: KernelDeps,- criteria: readonly Criterion[],+ criteria: readonly DeclaredCriterion[],owner: CriterionOwner,): Promise<CriterionResult[]> {if (criteria.length === 0) return [];@@ -189,6 +208,27 @@ async function declaredChecks(return out;}+/**+ * Ask the criteria BEFORE the work and mark the ones that already hold: one+ * that answers true against the untouched project is a guard, not evidence.+ * Declaring is always pre-write (the tool refuses it after), so this is the one+ * moment it can be asked. Nothing is claimed when the game is not up.+ */+export async function markBaseline(+ deps: KernelDeps,+ criteria: readonly Criterion[],+): Promise<DeclaredCriterion[]> {+ const probes = criteria.filter((c) => c.probe);+ if (probes.length === 0 || !await isPlaying(deps)) return criteria.map((c) => ({ ...c }));+ const out: DeclaredCriterion[] = [];+ for (const c of criteria) {+ if (!c.probe) { out.push({ ...c }); continue; }+ const asked = await runProbe(deps, c, 'turn');+ out.push(asked.state === 'held' ? { ...c, heldBefore: true } : { ...c });+ }+ return out;+}+async function isPlaying(deps: KernelDeps): Promise<boolean> {try {const state = await deps.driver('playState', [], 'editor') as { playing?: boolean; ready?: boolean };diff --git a/desktop/electron/agent/kernel.ts b/desktop/electron/agent/kernel.tsindex c0340294f..6aabf155d 100644--- a/desktop/electron/agent/kernel.ts+++ b/desktop/electron/agent/kernel.ts@@ -16,7 +16,8 @@ import type {AgentEvent, CatalogTool, ConfirmReason, KernelDeps, ToolCall, ToolOutcome, UserImage,} from './types';import {- criteriaProblem, evaluate, failureReport, type Acceptance, type Criterion,+ criteriaProblem, evaluate, failureReport, markBaseline,+ type Acceptance, type Criterion, type DeclaredCriterion,} from './acceptance';// Plain .mjs, shared with the MCP fronts — esbuild bundles it into main.// @ts-expect-error untyped shared module@@ -80,7 +81,7 @@ const ACCEPTANCE_TOOL = 'done_when';/** What the turn has claimed and whether it has written yet. Held by runTurn* and threaded down, because both facts belong to the turn and not to a call. */interface TurnState {- criteria: Criterion[];+ criteria: DeclaredCriterion[];wroteAnything: boolean;}@@ -91,11 +92,12 @@ interface TurnState {* exists are shaped by whatever got built, which is the failure mode the whole* mechanism is there to close.*/-function declare(+async function declare(+ deps: KernelDeps,call: ToolCall,turn: TurnState,- emit: KernelDeps['emit'],-): { outcome: ToolOutcome; mutated: boolean } {+): Promise<{ outcome: ToolOutcome; mutated: boolean }> {+ const emit = deps.emit;const refuse = (content: string) => {emit({ type: 'tool_end', id: call.id, ok: false, summary: content });return { outcome: { id: call.id, content, isError: true }, mutated: false };@@ -110,8 +112,15 @@ function declare(const problem = criteriaProblem((call.input as { criteria?: unknown }).criteria);if (problem) return refuse(problem);- turn.criteria = [...(call.input as { criteria: Criterion[] }).criteria];- const summary = `${turn.criteria.length} criteria — checked at the end of this turn`;+ turn.criteria = await markBaseline(deps, (call.input as { criteria: Criterion[] }).criteria);+ // Said now, while there is still time to claim something else: a criterion+ // that answers true against the untouched project is a guard on what already+ // works, and cannot be what shows this turn did anything.+ const already = turn.criteria.filter((c) => c.heldBefore);+ const summary = `${turn.criteria.length} criteria — checked at the end of this turn`+ + (already.length === 0 ? '' : `. ${already.length} of them ALREADY HOLD, with none of the `+ + `work done: ${already.map((c) => `"${c.says}"`).join(', ')}. Those cannot show this turn `+ + 'achieved anything — declare at least one that is false right now and true once you are done.');emit({ type: 'tool_end', id: call.id, ok: true, summary });return { outcome: { id: call.id, content: summary, isError: false }, mutated: false };}@@ -574,7 +583,7 @@ async function execute(const effect = tool.effect ?? 'read';emit({ type: 'tool_start', call, effect });- if (call.name === ACCEPTANCE_TOOL) return declare(call, turn, emit);+ if (call.name === ACCEPTANCE_TOOL) return declare(deps, call, turn);// The one gate. Everything the turn's checkpoint covers runs unasked. The flag// is why the tier is not enough: journaled with NO transaction open isdiff --git a/desktop/electron/agent/prompt.ts b/desktop/electron/agent/prompt.tsindex 1cf9b7696..145b9ea7b 100644--- a/desktop/electron/agent/prompt.ts+++ b/desktop/electron/agent/prompt.ts@@ -26,7 +26,7 @@ How work lands here:- Your turn is bracketed by a checkpoint over BOTH halves of what you can change: the scene, and the project's files. Scene edits are undo steps; every file you write is captured beforehand, so the user takes the whole turn back — script, prefab, scene and all — with one gesture. You therefore do not need permission to edit or to write, and should make the change rather than describing the change you would make.- What still stops to ask is what the checkpoint does not reach: making a project somewhere else, building an export, running code you wrote (run_editor_command, play_probe). If the user declines, do not retry: work around it, or say what you need and why.- Do not treat that safety net as licence to be careless. It puts the project back, not the user's attention — a turn they have to take back has cost them the time they spent reading it.-- Before your first write, say what would prove the work done: \`done_when\` with a few criteria, each naming the thing that settles it — \`probe\`, an expression evaluated in the running game that is true when the claim holds, or \`manual\` for something only a person can judge, saying why. A claim nothing can check is refused. This is the ONE part of the turn you do not grade: the editor runs them at the end and reports the verdict, and it is what the user reads instead of your closing paragraph. Declare it first — criteria written after the work are shaped by whatever you happened to build, and the tool refuses them once you have changed something.+- Before your first write, say what would prove the work done: \`done_when\` with a few criteria, each naming the thing that settles it — \`probe\`, an expression evaluated in the running game that is true when the claim holds, or \`manual\` for something only a person can judge, saying why. A claim nothing can check is refused. This is the ONE part of the turn you do not grade: the editor runs them at the end and reports the verdict, and it is what the user reads instead of your closing paragraph. Declare it first — criteria written after the work are shaped by whatever you happened to build, and the tool refuses them once you have changed something. Two things decide whether a criterion is worth declaring: it has to be FALSE right now and true when you are done (one that already holds is reported as a guard and proves nothing about your work), and \`manual\` is for what a PERSON must look at — the turn is not passed until they answer, so anything you would check yourself with a tool is a \`probe\`.- The project may already make claims of its OWN (its manifest's \`acceptance\`), kept there by the user. Every turn is measured against them and you cannot add to, weaken or remove one — breaking a standing claim fails your turn no matter how well your own did. Read them (read_project_file on project.esproject) before you change anything they are about.- After you change the scene you will be shown any problems the editor now flags. Silence means it is clean. Fix what you broke before reporting the work as done.diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex b5ebe3db3..48233cc41 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -271,8 +271,10 @@ const ATOMS = [description: 'State what would prove this work done, BEFORE you change anything — the editor checks it at the end of the turn and reports whether it held. '+ 'Each criterion is { says, probe } or { says, manual }. `says` is the claim in the words the user would use ("the bar empties as the player takes damage"). '+ '`probe` is an expression evaluated in the RUNNING game, true when the claim holds — the same scope play_probe gives you (`find`, `get`, `resource`), e.g. '- + '`find("Health")[0].data.current < 100`. `manual` is for a claim only a person can settle ("it reads well at 1080p"), and says why; those are reported as owned by them, not as passed. '+ + '`find("Health")[0].data.current < 100`. `manual` is for a claim only a PERSON can settle ("it reads well at 1080p"), and says why. '+ + 'If you intend to check it yourself with a tool, it is a `probe`, not a `manual` — and a turn whose claims are left for a person is not passed until that person answers, so `manual` spends their attention rather than saving you writing an expression. '+ 'A claim with neither is refused: something nothing can check is not a claim. '+ + 'Declare something that is FALSE right now and true when you are done: a criterion that already holds against the untouched project is a guard on what already worked, it is reported as such, and it can never be what shows this turn achieved anything. '+ 'This is the ONE thing in the turn you do not get to grade — the verdict is computed from these, not from what you say about the work. '+ 'It must be called before your first write, because criteria written afterwards are shaped by whatever you happened to build.',schema: obj({diff --git a/desktop/tests/agent-acceptance.test.ts b/desktop/tests/agent-acceptance.test.tsindex 19aeb6112..6dd0a4ba9 100644--- a/desktop/tests/agent-acceptance.test.ts+++ b/desktop/tests/agent-acceptance.test.ts@@ -9,7 +9,7 @@*/import { describe, it, expect, vi } from 'vitest';import {- criteriaProblem, evaluate, failureReport, MAX_CRITERIA,+ criteriaProblem, evaluate, failureReport, markBaseline, verdictOf, MAX_CRITERIA,} from '../electron/agent/acceptance';import type { Criterion, KernelDeps } from '../electron/agent/types';@@ -157,13 +157,67 @@ describe('what nothing was in a position to answer', () => {expect(out.results.find((r) => r.owner === 'turn')?.detail).toContain('only a person');});- it('still passes on the claims a machine could settle', async () => {+ // Passing on the machine-checkable half is what made `manual` the cheap way+ // out: declare the hard claim as theirs, grade it yourself in the closing+ // paragraph, and the verdict still reads passed with nobody ever asked.+ it('does not pass while a claim is still waiting on a person', async () => {const deps = fakeDriver({ probe: () => true });const out = await evaluate(deps, [{ says: 'the bar empties', probe: 'true' },{ says: 'it reads at 1080p', manual: 'a judgement about legibility' },]);- expect(out.verdict).toBe('passed');+ expect(out.verdict).toBe('unverified');+ });++ it('passes once the person has settled theirs', () => {+ expect(verdictOf([+ { says: 'the bar empties', probe: 'true', state: 'held', owner: 'turn' },+ { says: 'it reads at 1080p', manual: 'legibility', state: 'held', owner: 'turn' },+ ])).toBe('passed');+ });++ it('fails when the person says it did not hold', () => {+ expect(verdictOf([+ { says: 'the bar empties', probe: 'true', state: 'held', owner: 'turn' },+ { says: 'it reads at 1080p', manual: 'legibility', state: 'broke', owner: 'turn' },+ ])).toBe('failed');+ });+});++/**+ * A claim that was already true before the work is a guard on what already+ * worked. It is worth keeping and it can still break — what it cannot be is the+ * thing that says this turn achieved something.+ */+describe('a claim that already held when it was declared', () => {+ const guard = { says: 'the player has a collider', probe: 'true' };++ it('is marked at declaration, while there is still time to claim something else', async () => {+ const deps = fakeDriver({ probe: () => true });+ expect(await markBaseline(deps, [guard])).toEqual([{ ...guard, heldBefore: true }]);+ });++ it('claims nothing either way when the game is not up', async () => {+ const deps = fakeDriver({ playing: false, probe: () => true });+ expect(await markBaseline(deps, [guard])).toEqual([{ ...guard }]);+ });++ it('leaves a claim that is false right now alone', async () => {+ const deps = fakeDriver({ probe: () => false });+ expect(await markBaseline(deps, [guard])).toEqual([{ ...guard }]);+ });++ it('does not carry a turn to passed on its own', async () => {+ const deps = fakeDriver({ probe: () => true });+ const out = await evaluate(deps, [{ ...guard, heldBefore: true }]);+ expect(out.results.find((r) => r.owner === 'turn')?.state).toBe('held');+ expect(out.verdict).toBe('unverified');+ });++ it('still fails the turn when it breaks', async () => {+ const deps = fakeDriver({ probe: () => false });+ const out = await evaluate(deps, [{ ...guard, heldBefore: true }]);+ expect(out.verdict).toBe('failed');});});diff --git a/desktop/tests/agent-kernel.test.ts b/desktop/tests/agent-kernel.test.tsindex fb08d66f8..07b0ccd15 100644--- a/desktop/tests/agent-kernel.test.ts+++ b/desktop/tests/agent-kernel.test.ts@@ -754,6 +754,10 @@ describe('the verdict on the work', () => {});it('passes a turn whose claims held', async () => {+ // False when it was declared, true at the end — which is what a criterion+ // about the work looks like. The first ask is the baseline.+ let asked = 0;+ probe = () => ++asked > 1;const s = fakeSession([asks(declare({ says: 'the bar starts full', probe: 'ok' })),asks(call('add_entity')),@@ -764,6 +768,30 @@ describe('the verdict on the work', () => {expect(ended().acceptance.verdict).toBe('passed');});+ // The airJumpsLeft === 1 claim, from a real run: the field's own default,+ // true the moment it existed, and it carried the turn to `passed` while the+ // claim that mattered was handed to the person and graded in prose.+ it('does not pass on a claim that was already true before the work', async () => {+ const s = fakeSession([+ asks(declare({ says: 'the player has a collider', probe: 'ok' })),+ asks(call('add_entity')),+ asks(call('capture_viewport')),+ ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect(ended().acceptance.verdict).toBe('unverified');+ });++ it('says so at declaration, while there is still time to claim something else', async () => {+ const s = fakeSession([+ asks(declare({ says: 'the player has a collider', probe: 'ok' })),+ ends(), ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ const told = events.find((e) => e.type === 'tool_end' && e.summary.includes('ALREADY HOLD'));+ expect(told).toBeTruthy();+ });+// The whole point: the turn ends with a verdict the model never wrote, so a// confident closing paragraph over broken work reads as `failed` anyway.it('fails a turn whose claims did not, however it answers', async () => {