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): criteria declared late are priced, not refused
yhh4f249c53ff03
diff --git a/desktop/electron/agent/acceptance.ts b/desktop/electron/agent/acceptance.tsindex b9fbfb4fa..d461da4a2 100644--- a/desktop/electron/agent/acceptance.ts+++ b/desktop/electron/agent/acceptance.ts@@ -212,20 +212,25 @@ async function declaredChecks(}/**- * 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.+ * Ask each criterion the moment it is declared: one already answering true is a+ * guard on what worked before, not evidence of this turn. `afterWork` inverts+ * the benefit of the doubt — a claim made once the work exists counts only+ * where this could show it FALSE then, unmeasurable ones included.*/export async function markBaseline(deps: KernelDeps,criteria: readonly Criterion[],+ afterWork = false,): Promise<DeclaredCriterion[]> {const probes = criteria.filter((c) => c.probe);- if (probes.length === 0 || !await isPlaying(deps)) return criteria.map((c) => ({ ...c }));+ const playing = probes.length > 0 && await isPlaying(deps);+ const unmeasured = (c: Criterion): DeclaredCriterion =>+ (afterWork ? { ...c, heldBefore: true } : { ...c });+ if (!playing) return criteria.map(unmeasured);+const out: DeclaredCriterion[] = [];for (const c of criteria) {- if (!c.probe) { out.push({ ...c }); continue; }+ if (!c.probe) { out.push(unmeasured(c)); continue; }const asked = await runProbe(deps, c, 'turn');out.push(asked.state === 'held' ? { ...c, heldBefore: true } : { ...c });}diff --git a/desktop/electron/agent/kernel.ts b/desktop/electron/agent/kernel.tsindex 982c21693..b7bd39bca 100644--- a/desktop/electron/agent/kernel.ts+++ b/desktop/electron/agent/kernel.ts@@ -88,9 +88,9 @@ interface TurnState {/*** Answer {@link ACCEPTANCE_TOOL}: keep the claims, or refuse and say which rule.*- * Refused after the first write on purpose. Criteria written once the work- * exists are shaped by whatever got built, which is the failure mode the whole- * mechanism is there to close.+ * Claims made once the work exists are shaped by what got built — so they are+ * priced rather than refused: {@link markBaseline} keeps only what it can show+ * false at that moment, and the rest becomes a guard that proves nothing.*/async function declare(deps: KernelDeps,@@ -102,25 +102,24 @@ async function declare(emit({ type: 'tool_end', id: call.id, ok: false, summary: content });return { outcome: { id: call.id, content, isError: true }, mutated: false };};- if (turn.wroteAnything) {- return refuse(- 'too late — this turn has already changed something, and criteria written after the work '- + 'are shaped by the work. Say in your answer what you would have claimed, and declare it '- + 'first next time.',- );- }const problem = criteriaProblem((call.input as { criteria?: unknown }).criteria);if (problem) return refuse(problem);- turn.criteria = await markBaseline(deps, (call.input as { criteria: Criterion[] }).criteria);+ const late = turn.wroteAnything;+ turn.criteria = await markBaseline(+ deps, (call.input as { criteria: Criterion[] }).criteria, late,+ );// 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.');+ + (late ? '. Declared AFTER this turn changed something, so each one counts only where it '+ + 'could be shown false at this moment — anything already true, or that nothing here can '+ + 'settle, is a guard rather than evidence. Declare first next time.' : '')+ + (already.length === 0 ? '' : ` ${already.length} of them cannot show this turn achieved `+ + `anything: ${already.map((c) => `"${c.says}"`).join(', ')}. 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 };}diff --git a/desktop/electron/agent/prompt.ts b/desktop/electron/agent/prompt.tsindex 4e1ec7752..ad03f4e5c 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. 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\`.+- 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 declared after you have changed something they are still taken, but each one then counts only where the editor can show it false at that moment. 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 36c1b46be..644e97db5 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -276,7 +276,7 @@ const ATOMS = [+ '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.',+ + 'Call it BEFORE your first write. Declared afterwards it is still taken, but each criterion then counts only where the editor can show it FALSE at that moment — anything already true by then, or that nothing can settle right then, is recorded as a guard and proves nothing about your work. That is the cost of describing the finish line once you have started building toward it.',schema: obj({criteria: {type: 'array',diff --git a/desktop/tests/agent-acceptance.test.ts b/desktop/tests/agent-acceptance.test.tsindex 6dd0a4ba9..ef77df8e5 100644--- a/desktop/tests/agent-acceptance.test.ts+++ b/desktop/tests/agent-acceptance.test.ts@@ -207,6 +207,34 @@ describe('a claim that already held when it was declared', () => {expect(await markBaseline(deps, [guard])).toEqual([{ ...guard }]);});+ /**+ * Declared once the work exists, the benefit of the doubt goes the other way:+ * a claim shaped by what got built is the failure this guards, so it counts+ * only where it could be shown false at that moment.+ */+ describe('and declared after the turn had already changed something', () => {+ it('still counts one that was false when it was declared', async () => {+ const deps = fakeDriver({ probe: () => false });+ expect(await markBaseline(deps, [guard], true)).toEqual([{ ...guard }]);+ });++ it('discounts one that already held', async () => {+ const deps = fakeDriver({ probe: () => true });+ expect(await markBaseline(deps, [guard], true)).toEqual([{ ...guard, heldBefore: true }]);+ });++ it('discounts one nothing could settle at the time', async () => {+ const deps = fakeDriver({ playing: false, probe: () => false });+ expect(await markBaseline(deps, [guard], true)).toEqual([{ ...guard, heldBefore: true }]);+ });++ it('discounts one only a person can settle', async () => {+ const manual = { says: 'it reads well', manual: 'a judgement about legibility' };+ expect(await markBaseline(fakeDriver(), [manual], true))+ .toEqual([{ ...manual, heldBefore: true }]);+ });+ });+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 }]);diff --git a/desktop/tests/agent-kernel.test.ts b/desktop/tests/agent-kernel.test.tsindex e462de062..539d73e04 100644--- a/desktop/tests/agent-kernel.test.ts+++ b/desktop/tests/agent-kernel.test.ts@@ -788,7 +788,8 @@ describe('the verdict on the work', () => {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'));+ const told = events.find((e) => e.type === 'tool_end'+ && e.summary.includes('cannot show this turn achieved anything'));expect(told).toBeTruthy();});@@ -909,9 +910,12 @@ describe('the verdict on the work', () => {});describe('declaring what done means', () => {- // Criteria written once the work exists are shaped by whatever got built,- // which is the failure the whole mechanism is there to close.- it('is refused after the turn has already changed something', async () => {+ /**+ * Claims made once the work exists are shaped by what got built, and the+ * price for that is paid per criterion rather than by refusing the call:+ * kept only where it could be shown false at that moment.+ */+ it('takes one declared after the work, and says what that costs', async () => {const s = fakeSession([asks(call('add_entity')),asks(declare({ says: 'the bar starts full', probe: 'ok' })),@@ -920,11 +924,44 @@ describe('the verdict on the work', () => {]);await runTurn(deps(s), 'health bar', null, new AbortController().signal);const outcome = s.results.flat().find((o) => o.id === 'cdone_when');- expect(outcome).toMatchObject({ isError: true });- expect(outcome!.content).toContain('too late');+ expect(outcome).toMatchObject({ isError: false });+ expect(outcome!.content).toContain('AFTER this turn changed something');+ });++ it('cannot be carried to passed by one it could not show false', async () => {+ // The probe answers true throughout, so nothing here shows the work did it.+ const s = fakeSession([+ asks(call('add_entity')),+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);expect(ended().acceptance.verdict).toBe('unverified');});+ it('counts one that WAS false when it was declared', async () => {+ let asked = 0;+ probe = () => ++asked > 1;+ const s = fakeSession([+ asks(call('add_entity')),+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect(ended().acceptance.verdict).toBe('passed');+ });++ it('discounts a late claim nothing could settle at the time', async () => {+ playing = false;+ const s = fakeSession([+ asks(call('add_entity')),+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect(ended().acceptance.verdict).not.toBe('passed');+ });+it('refuses a claim that names nothing to settle it, and says which rule', async () => {const s = fakeSession([asks(declare({ says: 'it feels good' })), ends()]);await runTurn(deps(s), 'health bar', null, new AbortController().signal);