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 turn ends with a verdict it did not write
esengine3e89f01c0d4b
diff --git a/desktop/electron/agent/acceptance.ts b/desktop/electron/agent/acceptance.tsnew file mode 100644index 000000000..6d18a2442--- /dev/null+++ b/desktop/electron/agent/acceptance.ts@@ -0,0 +1,227 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file acceptance.ts+ * @brief Whether the work HELD — asked of the project, not of the model that+ * did it.+ *+ * The turn already reported how it stopped. Nothing reported whether it worked,+ * so the only answer anyone had was the model's own closing paragraph, written+ * by the same reasoning that produced the work. This asks something else.+ *+ * It is `tools/releaseGate.mjs` one level down, deliberately: that file settled+ * how this repo states a claim, and the doctrine is worth exactly as much for a+ * turn as for a release. A criterion NAMES the thing that settles it. One only a+ * person can settle is allowed, as `manual`, saying why a machine cannot. A+ * criterion with neither is refused rather than recorded as passing.+ */+import type { KernelDeps } from './types';++/** One claim about the finished work, and the thing that settles it. */+export interface Criterion {+ /** What is claimed, in the words the user would use. */+ says: string;+ /** A JS expression evaluated in the RUNNING game; truthy means it held. */+ probe?: string;+ /** Only a person can settle this one. Says why a machine cannot. */+ manual?: string;+}++/** What became of one criterion. `unsettled` is neither pass nor fail: nothing+ * was in a position to answer it. */+export interface CriterionResult {+ says: string;+ state: 'held' | 'broke' | 'unsettled';+ /** What it answered, or why nothing could answer it. */+ detail?: string;+ /** The editor's own checks, which no turn declares — see {@link FLOOR}. */+ floor?: boolean;+}++/**+ * `failed` — something the turn claimed, or the editor itself, did not hold.+ * `passed` — every claim that could be settled held, and at least one was.+ * `unverified` — nothing settled anything: none were declared, or the ones+ * declared all need a person or a running game there was not.+ */+export type Verdict = 'passed' | 'failed' | 'unverified';++export interface Acceptance {+ verdict: Verdict;+ results: readonly CriterionResult[];+}++/** How many claims one turn may make. Enough for a feature, few enough that a+ * list of them is still something a person reads. */+export const MAX_CRITERIA = 12;++/**+ * Reject a declaration that cannot mean anything, naming the rule it broke.+ * Null when it is well-formed.+ */+export function criteriaProblem(criteria: unknown): string | null {+ if (!Array.isArray(criteria) || criteria.length === 0) {+ return 'give at least one criterion, as `criteria: [{ says, probe }]`';+ }+ if (criteria.length > MAX_CRITERIA) {+ return `at most ${MAX_CRITERIA} criteria — pick the ones that would actually be checked`;+ }+ for (const c of criteria as Criterion[]) {+ if (!c || typeof c.says !== 'string' || c.says.trim() === '') {+ return 'every criterion needs `says`: what is claimed, in the words the user would use';+ }+ const settled = [c.probe, c.manual].filter((v) => typeof v === 'string' && v.trim() !== '');+ if (settled.length === 0) {+ return `"${c.says}" names nothing that settles it. Give \`probe\` — an expression `+ + 'evaluated in the running game that is true when the claim holds — or `manual`, '+ + 'saying why only a person can judge it. A claim nothing can check is not a claim.';+ }+ if (settled.length > 1) {+ return `"${c.says}" gives both \`probe\` and \`manual\`; one criterion, one thing that settles it`;+ }+ }+ return null;+}++/**+ * What the editor checks whatever the turn claims. It can only ever FAIL a+ * turn: a project with nothing wrong is not a project where the work happened,+ * so a passing floor never counts towards a verdict.+ */+const FLOOR = 'floor';++/** Run every criterion and say what became of the work. */+export async function evaluate(+ deps: KernelDeps,+ criteria: readonly Criterion[],+): Promise<Acceptance> {+ const results: CriterionResult[] = [+ ...await editorChecks(deps),+ ...await declaredChecks(deps, criteria),+ ];+ const claims = results.filter((r) => !r.floor);+ const verdict: Verdict = results.some((r) => r.state === 'broke') ? 'failed'+ : claims.some((r) => r.state === 'held') ? 'passed'+ : 'unverified';+ return { verdict, results };+}++async function editorChecks(deps: KernelDeps): Promise<CriterionResult[]> {+ const out: CriterionResult[] = [];++ try {+ const issues = await deps.driver('getDiagnostics', []) as Array<{+ entityName: string; problem: string; detail: string;+ }>;+ const errors = issues.filter((i) => i.problem !== 'notice');+ out.push(errors.length === 0+ ? { says: 'the editor flags nothing in the scene', state: 'held', floor: true }+ : {+ says: 'the editor flags nothing in the scene',+ state: 'broke',+ floor: true,+ detail: errors.slice(0, 6).map((i) => `${i.entityName}: ${i.detail}`).join('; '),+ });+ } catch {+ // No scene open, or an editor mid-reload. Not something to fail a turn over.+ }++ try {+ const res = await deps.driver.op('check_scripts', {}) as {+ diagnostics?: Array<{ file: string; line: number; message: string; category?: string }>;+ };+ const errors = (res?.diagnostics ?? []).filter((d) => d.category !== 'warning');+ out.push(errors.length === 0+ ? { says: "the project's scripts compile", state: 'held', floor: true }+ : {+ says: "the project's scripts compile",+ state: 'broke',+ floor: true,+ detail: errors.slice(0, 6).map((d) => `${d.file}:${d.line} ${d.message}`).join('; '),+ });+ } catch {+ // A project with no scripts, or no project at all.+ }+ return out;+}++async function declaredChecks(+ deps: KernelDeps,+ criteria: readonly Criterion[],+): Promise<CriterionResult[]> {+ if (criteria.length === 0) return [];+ const probes = criteria.filter((c) => c.probe);+ // Asked once for the whole set rather than per probe, and asked BEFORE+ // running any: a probe against a realm that is not up answers with an error+ // about the realm, which reads as the claim having broken.+ const playing = probes.length > 0 && await isPlaying(deps);++ const out: CriterionResult[] = [];+ for (const c of criteria) {+ if (c.manual) {+ out.push({ says: c.says, state: 'unsettled', detail: `only a person can settle this: ${c.manual}` });+ continue;+ }+ if (!playing) {+ out.push({ says: c.says, state: 'unsettled', detail: 'the game was not running, so nothing could answer this' });+ continue;+ }+ out.push(await runProbe(deps, c));+ }+ return out;+}++async function isPlaying(deps: KernelDeps): Promise<boolean> {+ try {+ const state = await deps.driver('playState', [], 'editor') as { playing?: boolean; ready?: boolean };+ return state?.playing === true && state?.ready !== false;+ } catch {+ return false;+ }+}++/**+ * A probe answers with a VALUE, and anything but a truthy one is the claim not+ * holding. The value is reported either way — "it broke" that cannot say what it+ * got is a verdict nobody can act on.+ */+async function runProbe(deps: KernelDeps, c: Criterion): Promise<CriterionResult> {+ try {+ const value = await deps.driver.op('play_probe', { code: c.probe });+ const answered = unwrap(value);+ return answered+ ? { says: c.says, state: 'held' }+ : { says: c.says, state: 'broke', detail: `the probe answered ${brief(answered ?? value)}` };+ } catch (e) {+ return { says: c.says, state: 'broke', detail: (e as Error)?.message ?? String(e) };+ }+}++/** The op answers in MCP's content-block wrapper; the value is inside it. */+function unwrap(value: unknown): unknown {+ const content = (value as { content?: Array<{ text?: string }> })?.content;+ if (!Array.isArray(content)) return value;+ const text = content.map((c) => c.text ?? '').join('').trim();+ try {+ return JSON.parse(text);+ } catch {+ // A probe that answered with a bare word — `true`, `undefined`, a message.+ return text === 'true' ? true : text === '' || text === 'false' || text === 'undefined' ? false : text;+ }+}++function brief(value: unknown): string {+ const text = typeof value === 'string' ? value : JSON.stringify(value) ?? String(value);+ return text.length > 200 ? `${text.slice(0, 197)}…` : text;+}++/** The failures, as the model is told them so it can fix them. Null when there+ * is nothing to fix. */+export function failureReport(acceptance: Acceptance): string | null {+ const broke = acceptance.results.filter((r) => r.state === 'broke');+ if (broke.length === 0) return null;+ const lines = broke.map((r) => `- ${r.says}${r.detail ? ` — ${r.detail}` : ''}`);+ return `${broke.length} of the things this work has to do are not holding:\n${lines.join('\n')}\n`+ + 'Fix them and check again. If one of them is wrong about what was asked for, say so rather '+ + 'than reporting the work as done.';+}diff --git a/desktop/electron/agent/host.ts b/desktop/electron/agent/host.tsindex 4251b375a..ac4b01343 100644--- a/desktop/electron/agent/host.ts+++ b/desktop/electron/agent/host.ts@@ -357,7 +357,7 @@ export function createAgentHost(deps: AgentHostDeps): AgentHost {// path is reached BEFORE the turn starts (runTurn takes its checkpoint// outside its own try), so there is no turn for it to be part of.error = (e as Error)?.message ?? String(e);- emit({ type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], reason: 'error' });+ emit({ type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'error' });} finally {settlePending();// The run is over either way — errors included, since a conversationdiff --git a/desktop/electron/agent/kernel.ts b/desktop/electron/agent/kernel.tsindex 40f4ae9bd..51f8b9205 100644--- a/desktop/electron/agent/kernel.ts+++ b/desktop/electron/agent/kernel.ts@@ -15,6 +15,9 @@import type {AgentEvent, CatalogTool, ConfirmReason, KernelDeps, ToolCall, ToolOutcome, UserImage,} from './types';+import {+ criteriaProblem, evaluate, failureReport, type Acceptance, type Criterion,+} from './acceptance';// Plain .mjs, shared with the MCP fronts — esbuild bundles it into main.// @ts-expect-error untyped shared moduleimport { TOOLS, runTool, mutates, irreversible, journaled } from '../../shared/toolCatalog.mjs';@@ -70,6 +73,49 @@ export function agentTools(contributed: readonly ContributedTool[] = []): readon/** One generic door on `window.__estellaEditor` for every contributed tool. */const PLUGIN_TOOL_METHOD = 'runPluginTool';+/** The tool the kernel answers itself — it declares what the TURN has to hold,+ * which is loop state and reaches no editor door. See acceptance.ts. */+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[];+ wroteAnything: boolean;+}++/**+ * 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.+ */+function declare(+ call: ToolCall,+ turn: TurnState,+ emit: KernelDeps['emit'],+): { outcome: ToolOutcome; mutated: boolean } {+ 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 };+ };+ 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 = [...(call.input as { criteria: Criterion[] }).criteria];+ const summary = `${turn.criteria.length} criteria — checked at the end of this turn`;+ emit({ type: 'tool_end', id: call.id, ok: true, summary });+ return { outcome: { id: call.id, content: summary, isError: false }, mutated: false };+}+/** What the window says a plugin contributed. The handler stays over there. */export interface ContributedTool {name: string;@@ -170,7 +216,7 @@ export async function runTurn(context: string | null,signal: AbortSignal,images?: readonly UserImage[],-): Promise<{ mark: unknown; endMark: unknown; steps: number; tx: string | null }> {+): Promise<{ mark: unknown; endMark: unknown; steps: number; tx: string | null; acceptance: Acceptance }> {const { driver, session, emit, model, acceptsImages } = deps;const mark = await driver('mark', []);// Opened before the first call and closed once, in the finally below: a@@ -187,6 +233,9 @@ export async function runTurn(const allowed = new Set<string>();// Undo steps this turn is responsible for, so a jump beyond it is the person.let ours = 0;+ // The last evaluation, which is the one the verdict comes from. Out here+ // because turn_end reports it however the turn ended.+ let accepted: Acceptance | null = null;try {if (context) session.pushContext(context);if (!acceptsImages) {@@ -210,6 +259,8 @@ export async function runTurn(// that just crossed the line — see REPEAT_LIMIT.const failing = new Map<string, number>();const stuck: string[] = [];+ const turn: TurnState = { criteria: [], wroteAnything: false };+ let toldFailures = false;let round = 0;for (; round < MAX_ROUNDS; round++) {// The editor is not frozen while a turn runs: the person can drag an@@ -302,6 +353,21 @@ export async function runTurn();continue;}+ // A turn that changed nothing and claimed nothing has no work to+ // accept, and asking the editor about a project it did not touch buys a+ // verdict about someone else's state.+ if (builtSomething || turn.criteria.length > 0) {+ // Taken HERE rather than after the loop, so a turn that broke its own+ // criteria gets one chance to fix them — the same shape as the+ // diagnostics feed. Told once, and the reading it ends on is reported.+ accepted = await evaluate(deps, turn.criteria);+ const failures = failureReport(accepted);+ if (failures && !toldFailures) {+ toldFailures = true;+ session.pushContext(failures);+ continue;+ }+ }break;}@@ -316,8 +382,8 @@ export async function runTurn(let end = i;while (end < calls.length && isRead(calls[end])) end++;const batch = end - i > 1- ? await Promise.all(calls.slice(i, end).map((c) => execute(deps, c, allowed, signal, tx !== null)))- : [await execute(deps, calls[i], allowed, signal, tx !== null)];+ ? await Promise.all(calls.slice(i, end).map((c) => execute(deps, c, allowed, signal, tx !== null, turn)))+ : [await execute(deps, calls[i], allowed, signal, tx !== null, turn)];const slice = calls.slice(i, i + batch.length);for (const done of batch) {outcomes.push(done.outcome);@@ -332,6 +398,7 @@ export async function runTurn(if (batch[k].outcome.isError) stuckOn(failing, slice[k], stuck);}builtSomething ||= wrote;+ turn.wroteAnything ||= wrote;i += batch.length;}if (signal.aborted) break;@@ -380,8 +447,11 @@ export async function runTurn(// one, so the newest run claims every edit the person makes after it.const endMark = await driver('mark', []).catch(() => null);const files = tx ? deps.journal?.changes(tx) ?? [] : [];- emit({ type: 'turn_end', steps, mark, endMark, tx, files, reason });- return { mark, endMark, steps, tx };+ // A turn that never reached the point of answering — stopped, or out of+ // rounds — was never evaluated, and `unverified` is the honest word for it.+ const acceptance: Acceptance = accepted ?? { verdict: 'unverified', results: [] };+ emit({ type: 'turn_end', steps, mark, endMark, tx, files, reason, acceptance });+ return { mark, endMark, steps, tx, acceptance };}/**@@ -490,6 +560,7 @@ async function execute(allowed: Set<string>,signal: AbortSignal,journalling: boolean,+ turn: TurnState,): Promise<{ outcome: ToolOutcome; mutated: boolean }> {const { emit, driver, confirm } = deps;const tool = byName.get(call.name);@@ -502,6 +573,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);// 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 2c848ab89..5513fbf4e 100644--- a/desktop/electron/agent/prompt.ts+++ b/desktop/electron/agent/prompt.ts@@ -26,6 +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.- 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.Working style:diff --git a/desktop/electron/agent/types.ts b/desktop/electron/agent/types.tsindex aa65f9148..7c942722b 100644--- a/desktop/electron/agent/types.ts+++ b/desktop/electron/agent/types.ts@@ -14,6 +14,7 @@* about a vendor reaches the kernel, and no editor policy reaches a provider.*/import type { HistoryMark } from '../../src/engine/EditorHistory';+import type { Acceptance } from './acceptance';/** A tool as the catalog declares it (the .mjs registry is untyped). */export interface CatalogTool {@@ -281,6 +282,10 @@ export type AgentEvent =tx: string | null;files: readonly FileChange[];reason: 'end_turn' | 'aborted' | 'error' | 'refusal' | 'max_rounds';+ /** Whether the WORK held, asked of the project rather than of the model —+ * see agent/acceptance.ts. `reason` says how the turn stopped; this says+ * whether what it stopped on is any good. */+ acceptance: Acceptance;}| { type: 'error'; message: string };@@ -330,3 +335,4 @@ export interface FileChange {}export type { HistoryMark };+export type { Acceptance, Criterion, CriterionResult, Verdict } from './acceptance';diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex 496ae0796..ed097ab24 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -252,6 +252,23 @@ const ATOMS = [{ name: 'get_subsystems',description: 'Lifecycle + liveness of every engine subsystem (physics, audio, …): phase and activity.',schema: obj({}), method: 'getSubsystems', args: () => [] },+ // The one tool the KERNEL serves rather than the editor. `loopOnly` keeps it+ // off the MCP fronts — a client with no turn loop has nothing to declare+ // against — while one registry keeps `check-tool-calls` able to read it.+ { name: 'done_when', loopOnly: true,+ 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. '+ + 'A claim with neither is refused: something nothing can check is not a claim. '+ + '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({+ criteria: {+ type: 'array',+ description: 'array of { says, probe } or { says, manual }',+ },+ }, ['criteria']) },{ name: 'undo', effect: 'undoable', description: 'Undo the last edit.', schema: obj({}), method: 'undo', args: () => [] },{ name: 'redo', effect: 'undoable', description: 'Redo the last undone edit.', schema: obj({}), method: 'redo', args: () => [] },@@ -655,7 +672,9 @@ export const RESOURCES = [/** The MCP `tools/list` payload — name, description, JSON-Schema inputSchema.* Without `allowWrites`, mutating tools are omitted entirely (not just refused). */export function listTools(allowWrites = false) {- return TOOLS.filter((t) => !mutates(t) || allowWrites)+ // `loopOnly` tools belong to the built-in kernel's turn loop, which a remote+ // client does not have — offering one would be offering a door onto nothing.+ return TOOLS.filter((t) => !t.loopOnly && (!mutates(t) || allowWrites)).map((t) => ({ name: t.name, description: t.description, inputSchema: t.schema }));}diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 383764f1c..c4f53f807 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -514,6 +514,49 @@ function Skeleton() {);}+/**+ * Whether the work HELD — the one line of a finished run the model did not+ * write, which is why it sits above the change set rather than in it.+ *+ * A turn that claimed nothing says so: silence would read as a pass, and+ * "nobody checked" is the thing most worth knowing about a long run.+ */+function Verdict({ turn }: { turn: AgentTurn }) {+ const [open, setOpen] = useState(false);+ const { verdict, results } = turn.acceptance;+ const claims = results.filter((r) => !r.floor);+ if (verdict === 'unverified' && claims.length === 0 && results.length === 0) return null;+ const broke = results.filter((r) => r.state === 'broke').length;+ return (+ <div className={`ag-verdict v-${verdict}${open ? ' open' : ''}`}>+ <button type="button" className="ag-verdict-h" onClick={() => setOpen((o) => !o)}>+ <ChevronRight size={11} strokeWidth={2} className="ag-car" />+ {verdict === 'passed' && <Check size={12} strokeWidth={2.2} />}+ {verdict === 'failed' && <TriangleAlert size={12} strokeWidth={2} />}+ {verdict === 'unverified' && <Eye size={12} strokeWidth={1.9} />}+ <span className="ag-verdict-t">{t(`agent.verdict.${verdict}` as const)}</span>+ <span className="ag-sp" />+ {broke > 0 && <span className="ag-del">{broke}</span>}+ </button>+ <Fold open={open}>+ <div className="ag-verdict-l">+ {results.map((r, i) => (+ <div className={`ag-claim s-${r.state}`} key={i}>+ <span className="ag-claim-s">+ {r.state === 'held' ? '✓' : r.state === 'broke' ? '✗' : '·'}+ </span>+ <span className="ag-claim-t">+ {r.says}+ {r.detail && <span className="ag-claim-d">{r.detail}</span>}+ </span>+ </div>+ ))}+ </div>+ </Fold>+ </div>+ );+}+/*** What the turn actually changed — the work product of a run, so it gets* first-class presentation rather than a popover hung off the undo bar.@@ -759,6 +802,7 @@ const Turn = memo(function Turn({ turn, isLast, running }: {<ArrowRight size={13} strokeWidth={2} />{t('agent.continue')}</button>)}+ {turn.reason !== null && <Verdict turn={turn} />}{turn.reason !== null && <ChangeSet turn={turn} />}</div></Fold>diff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.tsindex 2e1556e84..d638b715d 100644--- a/desktop/src/i18n/messages/agent.ts+++ b/desktop/src/i18n/messages/agent.ts@@ -210,6 +210,13 @@ export const agentMessages = defineMessages({},'agent.jump': { en: 'One waiting on you', zh: '有一条待确认' },+ // — Whether the work held (electron/agent/acceptance.ts) —+ 'agent.verdict.passed': { en: 'Everything it claimed held', zh: '声明的都成立了' },+ 'agent.verdict.failed': { en: 'Something it claimed did not hold', zh: '有声明没有成立' },+ // Not a failure — an absence, and the absence is the point. A long run that+ // nobody checked is the thing most worth saying out loud.+ 'agent.verdict.unverified': { en: 'Nothing checked this work', zh: '没有任何东西检查过这份工作' },+// — The checkpoint a finished turn leaves behind —'agent.checkpoint.undo': { en: 'Undo', zh: '撤销' },'agent.checkpoint.keep': { en: 'Keep', zh: '保留' },diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.tsindex 56a7599cc..c1890ccd8 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -19,7 +19,7 @@import { create } from 'zustand';import type { AgentStatus, AgentMessage } from '../../electron/agent/host';import type {- AgentEvent, ConfirmAnswer, ConfirmReason, ConfirmRequest, FileChange,+ Acceptance, AgentEvent, ConfirmAnswer, ConfirmReason, ConfirmRequest, FileChange,} from '../../electron/agent/types';import {agentProviders, agentProvider, agentKeyId, parseModelList, protocolOf,@@ -152,6 +152,12 @@ export interface AgentTurn {*/tx: string | null;files: readonly FileChange[];+ /**+ * Whether the WORK held — the one thing about a turn the model does not get+ * to report. `reason` says how it stopped; this says whether what it stopped+ * on is any good. See electron/agent/acceptance.ts.+ */+ acceptance: Acceptance;/** null while the turn is still running. */reason: TurnReason | null;/** Wall clock, stamped here rather than in main: it is what the person waited,@@ -498,6 +504,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):endMark: null,tx: null,files: [],+ acceptance: { verdict: 'unverified', results: [] },reason: null,startedAt: Date.now(),endedAt: null,@@ -593,6 +600,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):endMark: event.endMark,tx: event.tx,files: event.files,+ acceptance: event.acceptance,endedAt: Date.now(),// Nothing will report on these now. Neither failed nor succeeded.entries: closeProse(open.entries).map((e) =>diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex e1e9eb874..f91c2fb54 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -963,6 +963,49 @@.ag-changes .ag-car { color: var(--text-faint); transition: transform var(--t) var(--e-out); }.ag-changes.open .ag-car { transform: rotate(90deg); }.ag-changes-l { padding: 4px 0 2px; }++/* The verdict. Colour carries it: green held, amber broke, plain for the one+ that says nobody checked — which is neither good news nor bad, and painting+ it either way is the misreading this line exists to prevent. */+.ag-verdict { margin: 8px 0 2px; }+.ag-verdict-h {+ display: flex;+ align-items: center;+ gap: 7px;+ width: 100%;+ padding: 5px 8px;+ border: 1px solid var(--border);+ border-radius: var(--r-sm);+ background: none;+ color: var(--text);+ text-align: left;+ cursor: pointer;+ font: var(--fs-xs) var(--font-ui);+}+.ag-verdict-h:hover { background: var(--hover); }+.ag-verdict.v-passed .ag-verdict-h { color: var(--run); border-color: color-mix(in srgb, var(--run) 40%, transparent); }+.ag-verdict.v-failed .ag-verdict-h { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }+.ag-verdict.v-unverified .ag-verdict-h { color: var(--text-dim); }+.ag-verdict .ag-car { color: var(--text-faint); transition: transform var(--t) var(--e-out); }+.ag-verdict.open .ag-car { transform: rotate(90deg); }+.ag-verdict-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+.ag-verdict-l { padding: 5px 0 2px 8px; }+.ag-claim {+ display: grid;+ grid-template-columns: 12px minmax(0, 1fr);+ gap: 7px;+ padding: 3px 4px;+ font: var(--fs-2xs) var(--font-mono);+ color: var(--text-dim);+}+.ag-claim-s { text-align: center; font-weight: 600; }+.ag-claim.s-held .ag-claim-s { color: var(--run); }+.ag-claim.s-broke .ag-claim-s { color: var(--warn); }+.ag-claim.s-unsettled .ag-claim-s { color: var(--text-faint); }+.ag-claim.s-broke .ag-claim-t { color: var(--text); }+/* The reason on its own line: a probe's answer or a compiler message is where+ the whole value is, and clipping it to a cell is where it used to go. */+.ag-claim-d { display: block; color: var(--text-faint); margin-top: 2px; }.ag-chg {display: grid;grid-template-columns: 14px minmax(0, 1fr) auto;diff --git a/desktop/tests/agent-acceptance.test.ts b/desktop/tests/agent-acceptance.test.tsnew file mode 100644index 000000000..ee05b4de3--- /dev/null+++ b/desktop/tests/agent-acceptance.test.ts@@ -0,0 +1,184 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file The verdict on a turn's work, and the rule that a claim must name what+ * settles it (tools/releaseGate.mjs, one level down).+ *+ * The property under test is the one the whole thing exists for: the verdict+ * comes from the project, and no answer the model could write changes it.+ */+import { describe, it, expect, vi } from 'vitest';+import {+ criteriaProblem, evaluate, failureReport, MAX_CRITERIA,+} from '../electron/agent/acceptance';+import type { KernelDeps } from '../electron/agent/types';++/** A driver whose editor is clean and whose game answers `probe` with `answer`. */+function fakeDriver(over: {+ diagnostics?: unknown[];+ scripts?: unknown;+ playing?: boolean;+ probe?: (code: string) => unknown;+} = {}) {+ const driver = vi.fn(async (method: string) => {+ if (method === 'getDiagnostics') return over.diagnostics ?? [];+ if (method === 'playState') return { playing: over.playing ?? true, ready: true };+ return null;+ }) as unknown as KernelDeps['driver'];+ (driver as { op: unknown }).op = vi.fn(async (op: string, input?: Record<string, unknown>) => {+ if (op === 'check_scripts') return over.scripts ?? { diagnostics: [] };+ if (op === 'play_probe') {+ const value = over.probe?.(String(input?.code)) ?? false;+ if (value instanceof Error) throw value;+ return { content: [{ type: 'text', text: JSON.stringify(value) }] };+ }+ return null;+ });+ (driver as { js: unknown }).js = vi.fn(async () => null);+ return { driver } as unknown as KernelDeps;+}++describe('a claim has to name what settles it', () => {+ it('refuses a claim with nothing that settles it', () => {+ expect(criteriaProblem([{ says: 'it feels good' }]))+ .toMatch(/names nothing that settles it/);+ });++ it('refuses a claim that names two things', () => {+ expect(criteriaProblem([{ says: 'x', probe: 'true', manual: 'because' }]))+ .toMatch(/one criterion, one thing that settles it/);+ });++ it('refuses a claim that says nothing', () => {+ expect(criteriaProblem([{ probe: 'true' }])).toMatch(/needs `says`/);+ expect(criteriaProblem([{ says: ' ', probe: 'true' }])).toMatch(/needs `says`/);+ });++ it('refuses an empty list — declaring none is not declaring', () => {+ expect(criteriaProblem([])).toMatch(/at least one/);+ expect(criteriaProblem(undefined)).toMatch(/at least one/);+ });++ it('refuses more than a person would read', () => {+ const many = Array.from({ length: MAX_CRITERIA + 1 }, (_, i) => ({ says: `c${i}`, probe: 'true' }));+ expect(criteriaProblem(many)).toMatch(/at most/);+ });++ it('accepts a probe, and accepts a reason only a person can judge', () => {+ expect(criteriaProblem([{ says: 'the bar empties', probe: 'true' }])).toBeNull();+ expect(criteriaProblem([{ says: 'it reads at 1080p', manual: 'a judgement about legibility' }])).toBeNull();+ });+});++describe('the verdict', () => {+ const held = { says: 'the bar starts full', probe: 'find("Health")[0].data.current === 100' };++ it('passes when every claim held', async () => {+ const deps = fakeDriver({ probe: () => true });+ const out = await evaluate(deps, [held]);+ expect(out.verdict).toBe('passed');+ });++ it('fails when a claim did not hold, and says what the probe answered', async () => {+ const deps = fakeDriver({ probe: () => 0 });+ const out = await evaluate(deps, [held]);+ expect(out.verdict).toBe('failed');+ expect(out.results.find((r) => r.says === held.says)?.detail).toContain('0');+ });++ it('fails when the probe threw', async () => {+ const deps = fakeDriver({ probe: () => new Error('Health is not a component') });+ const out = await evaluate(deps, [held]);+ expect(out.verdict).toBe('failed');+ expect(out.results.find((r) => r.says === held.says)?.detail).toContain('not a component');+ });++ // A turn that claimed nothing is not a turn that succeeded. This is the whole+ // point: the absence of a check is reported as an absence.+ it('is unverified when nothing was claimed', async () => {+ const out = await evaluate(fakeDriver(), []);+ expect(out.verdict).toBe('unverified');+ });++ // The editor's own checks can only ever fail a turn. A project with nothing+ // wrong is not a project where the work happened.+ it('does not pass a turn on the editor checks alone', async () => {+ const out = await evaluate(fakeDriver(), []);+ expect(out.results.every((r) => r.floor)).toBe(true);+ expect(out.results.some((r) => r.state === 'held')).toBe(true);+ expect(out.verdict).toBe('unverified');+ });++ it('fails a turn whose scene the editor flags, whatever it claimed', async () => {+ const deps = fakeDriver({+ probe: () => true,+ diagnostics: [{ entityName: 'HealthBar', problem: 'error', detail: 'texture is missing' }],+ });+ const out = await evaluate(deps, [held]);+ expect(out.verdict).toBe('failed');+ expect(failureReport(out)).toContain('texture is missing');+ });++ it('fails a turn whose scripts do not compile', async () => {+ const deps = fakeDriver({+ probe: () => true,+ scripts: { diagnostics: [{ file: 'src/HP.ts', line: 4, message: "Cannot find name 'foo'" }] },+ });+ expect((await evaluate(deps, [held])).verdict).toBe('failed');+ });++ // A warning is not a broken build, and failing turns on one teaches the+ // person to stop reading the verdict.+ it('does not fail on a script warning', async () => {+ const deps = fakeDriver({+ probe: () => true,+ scripts: { diagnostics: [{ file: 'src/HP.ts', line: 4, message: 'unused', category: 'warning' }] },+ });+ expect((await evaluate(deps, [held])).verdict).toBe('passed');+ });+});++describe('what nothing was in a position to answer', () => {+ it('leaves a probe unsettled when the game was not running', async () => {+ const deps = fakeDriver({ playing: false, probe: () => true });+ const out = await evaluate(deps, [{ says: 'the bar empties', probe: 'true' }]);+ expect(out.verdict).toBe('unverified');+ expect(out.results.find((r) => !r.floor)).toMatchObject({ state: 'unsettled' });+ expect(out.results.find((r) => !r.floor)?.detail).toContain('not running');+ });++ // Owned by a person, and reported as owned — never quietly counted as passed,+ // which is the failure `manual` exists to prevent.+ it('reports a claim only a person can settle as theirs', async () => {+ const deps = fakeDriver();+ const out = await evaluate(deps, [{ says: 'it reads at 1080p', manual: 'a judgement about legibility' }]);+ expect(out.verdict).toBe('unverified');+ expect(out.results.find((r) => !r.floor)?.detail).toContain('only a person');+ });++ it('still passes on the claims a machine could settle', 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');+ });+});++describe('what the model is told to fix', () => {+ it('is nothing when nothing broke', async () => {+ expect(failureReport(await evaluate(fakeDriver({ probe: () => true }), []))).toBeNull();+ });++ it('names each broken claim, and does not name the ones that held', async () => {+ const deps = fakeDriver({ probe: (code) => code.includes('good') });+ const out = await evaluate(deps, [+ { says: 'the good one', probe: 'good' },+ { says: 'the bad one', probe: 'bad' },+ ]);+ const report = failureReport(out)!;+ expect(report).toContain('the bad one');+ expect(report).not.toContain('the good one');+ });+});diff --git a/desktop/tests/agent-host.test.ts b/desktop/tests/agent-host.test.tsindex 7c7f542b6..6045f86e8 100644--- a/desktop/tests/agent-host.test.ts+++ b/desktop/tests/agent-host.test.ts@@ -393,7 +393,7 @@ describe('a conversation that outlives the session', () => {endpoint: 'fake',events: [{ type: 'turn_start', prompt: 'yesterday', model: 'fake-model', index: 0 },- { type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], reason: 'end_turn' },+ { type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn' },],memory: { asked: ['yesterday'] },};diff --git a/desktop/tests/agent-kernel.test.ts b/desktop/tests/agent-kernel.test.tsindex 0cf0763fa..7e87da652 100644--- a/desktop/tests/agent-kernel.test.ts+++ b/desktop/tests/agent-kernel.test.ts@@ -91,7 +91,7 @@ describe('the agent turn', () => {// what was asked, and the point an Undo would go back to.expect(events.at(0)).toEqual({ type: 'turn_start', prompt: 'hi', model: 'fake-model', index: 0 });expect(events.at(-1)).toEqual({- type: 'turn_end', steps: 3, mark: { seq: 7 }, endMark: { seq: 7 }, tx: null, files: [], reason: 'end_turn',+ type: 'turn_end', steps: 3, mark: { seq: 7 }, endMark: { seq: 7 }, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn',});});@@ -704,6 +704,156 @@ describe('looking before reporting', () => {});});+// The one thing about a turn the model does not get to report. `reason` says+// how it stopped; the verdict says whether what it stopped on is any good, and+// it is computed from the project rather than from the closing paragraph.+describe('the verdict on the work', () => {+ let events: AgentEvent[];+ let driver: ReturnType<typeof vi.fn> & { js: unknown; op: unknown };+ let probe: (code: string) => unknown;+ let playing: boolean;++ const deps = (session: AgentSession) => ({+ driver: driver as never, session, model: 'fake-model', acceptsImages: true,+ confirm: (async () => ({ answer: 'once' })) as never,+ emit: (e: AgentEvent) => { events.push(e); },+ });+ const ended = () => events.at(-1) as Extract<AgentEvent, { type: 'turn_end' }>;+ const declare = (...criteria: unknown[]) => call('done_when', { criteria });++ beforeEach(() => {+ events = [];+ probe = () => true;+ playing = true;+ driver = vi.fn(async (method: string) => {+ if (method === 'mark') return { seq: 0 };+ if (method === 'stepsSince') return 1;+ if (method === 'getDiagnostics') return [];+ if (method === 'playState') return { playing, ready: true };+ return null;+ }) as never;+ (driver as { js: unknown }).js = vi.fn(async () => null);+ (driver as { op: unknown }).op = vi.fn(async (op: string, input?: Record<string, unknown>) => {+ if (op === 'check_scripts') return { diagnostics: [] };+ if (op === 'play_probe') return { content: [{ text: JSON.stringify(probe(String(input?.code))) }] };+ return null;+ });+ });++ it('passes a turn whose claims held', async () => {+ const s = fakeSession([+ asks(declare({ says: 'the bar starts full', 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('passed');+ });++ // 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 () => {+ probe = () => false;+ const s = fakeSession([+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ asks(call('add_entity')),+ asks(call('capture_viewport')),+ ends(), ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect(ended().acceptance.verdict).toBe('failed');+ });++ it('tells the model what broke, once, so it can fix it', async () => {+ probe = () => false;+ const s = fakeSession([+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ asks(call('add_entity')),+ asks(call('capture_viewport')),+ ends(), ends(), ends(),+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect(s.context.filter((c) => c.includes('are not holding'))).toHaveLength(1);+ });++ // Evaluated again after the model has had its one chance to fix things, and+ // the LAST reading is the one reported — a verdict fixed at the first failure+ // would call every repaired turn broken.+ it('reports the state it ends on, not the one it was told about', async () => {+ let asked = 0;+ probe = () => ++asked > 1;+ const s = fakeSession([+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ asks(call('add_entity')),+ asks(call('capture_viewport')),+ ends(), // broke — told once+ ends(), // fixed; this evaluation is the one reported+ ]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect(asked).toBe(2);+ expect(ended().acceptance.verdict).toBe('passed');+ });++ it('is unverified when the turn claimed nothing', async () => {+ const s = fakeSession([asks(call('add_entity')), asks(call('capture_viewport')), ends()]);+ await runTurn(deps(s), 'add one', null, new AbortController().signal);+ expect(ended().acceptance.verdict).toBe('unverified');+ });++ // A turn that only answered a question has no work to accept, and asking the+ // editor about a project it did not touch buys a verdict about someone else.+ it('checks nothing on a turn that changed nothing', async () => {+ const s = fakeSession([asks(call('get_scene_tree')), ends()]);+ await runTurn(deps(s), 'what is here?', null, new AbortController().signal);+ expect(driver).not.toHaveBeenCalledWith('getDiagnostics', expect.anything());+ expect(ended().acceptance.results).toEqual([]);+ });++ it('is unverified when the turn was stopped before it could be checked', async () => {+ const controller = new AbortController();+ const s = fakeSession([asks(call('add_entity')), ends()]);+ controller.abort();+ await runTurn(deps(s), 'health bar', null, controller.signal);+ expect(ended()).toMatchObject({ reason: 'aborted', acceptance: { verdict: 'unverified' } });+ });++ 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 () => {+ const s = fakeSession([+ asks(call('add_entity')),+ asks(declare({ says: 'the bar starts full', probe: 'ok' })),+ asks(call('capture_viewport')),+ ends(),+ ]);+ 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(ended().acceptance.verdict).toBe('unverified');+ });++ 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);+ const outcome = s.results.flat().find((o) => o.id === 'cdone_when');+ expect(outcome).toMatchObject({ isError: true });+ expect(outcome!.content).toContain('names nothing that settles it');+ });++ // It is loop state, not editor state: dispatching it would be asking the+ // editor about something the editor has never heard of.+ it('never reaches the editor', async () => {+ const s = fakeSession([asks(declare({ says: 'x', probe: 'ok' })), ends()]);+ await runTurn(deps(s), 'health bar', null, new AbortController().signal);+ expect((driver as { js: ReturnType<typeof vi.fn> }).js).not.toHaveBeenCalled();+ expect(driver).not.toHaveBeenCalledWith('done_when', expect.anything(), expect.anything());+ });+ });+});+// The round cap is a spend limit, not a signal: a model re-issuing a call that// keeps failing reaches 128 rounds without anyone telling it why.describe('a call that keeps failing the same way', () => {diff --git a/desktop/tests/agent-queue.test.ts b/desktop/tests/agent-queue.test.tsindex 35f8643f2..538b20c0b 100644--- a/desktop/tests/agent-queue.test.ts+++ b/desktop/tests/agent-queue.test.ts@@ -114,7 +114,7 @@ describe('messages typed while a turn runs', () => {describe('asking a run again', () => {const turn = (id: number, prompt: string) => ({id, prompt, model: 'm', entries: [], inputTokens: 0, outputTokens: 0, context: null,- steps: 0, mark: null, endMark: null, tx: null, files: [], reason: 'end_turn' as const, startedAt: 0, endedAt: 1,+ steps: 0, mark: null, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified' as const, results: [] }, reason: 'end_turn' as const, startedAt: 0, endedAt: 1,});beforeEach(() => {diff --git a/desktop/tests/agent-replay.test.ts b/desktop/tests/agent-replay.test.tsindex b4407a007..1cfe7ab03 100644--- a/desktop/tests/agent-replay.test.ts+++ b/desktop/tests/agent-replay.test.ts@@ -21,10 +21,10 @@ const status: AgentStatus =const conversation = (from = 0): AgentEvent[] => [{ type: 'turn_start', prompt: 'add a pause menu', model: 'opus-5', index: from },{ type: 'text', delta: 'Building it.' },- { type: 'turn_end', steps: 7, mark: { seq: 1 }, endMark: null, tx: null, files: [], reason: 'end_turn' },+ { type: 'turn_end', steps: 7, mark: { seq: 1 }, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn' },{ type: 'turn_start', prompt: 'bigger buttons', model: 'opus-5', index: from + 1 },{ type: 'text', delta: 'Done.' },- { type: 'turn_end', steps: 3, mark: { seq: 2 }, endMark: null, tx: null, files: [], reason: 'end_turn' },+ { type: 'turn_end', steps: 3, mark: { seq: 2 }, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn' },];let transcript: AgentEvent[];diff --git a/desktop/tests/agent-revert-scope.test.ts b/desktop/tests/agent-revert-scope.test.tsindex e73afb880..d9c627468 100644--- a/desktop/tests/agent-revert-scope.test.ts+++ b/desktop/tests/agent-revert-scope.test.ts@@ -14,7 +14,7 @@ import type { FileChange } from '../electron/agent/types';const turn = (over: Partial<AgentTurn>): AgentTurn => ({id: 0, prompt: 'add a health bar', model: 'opus-5', entries: [],inputTokens: 0, outputTokens: 0, context: null,- steps: 0, mark: { seq: 1 }, endMark: null, tx: null, files: [],+ steps: 0, mark: { seq: 1 }, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] },reason: 'end_turn', startedAt: 0, endedAt: 1,...over,});diff --git a/desktop/tests/agent-store.test.ts b/desktop/tests/agent-store.test.tsindex 6b59dc9be..84ca1fe2c 100644--- a/desktop/tests/agent-store.test.ts+++ b/desktop/tests/agent-store.test.ts@@ -21,7 +21,7 @@ afterEach(async () => { await rm(root, { recursive: true, force: true }); });const turn = (index: number, prompt: string): AgentEvent[] => [{ type: 'turn_start', prompt, model: 'fake-model', index },{ type: 'text', delta: 'sure' },- { type: 'turn_end', steps: 1, mark: { seq: index }, endMark: null, tx: null, files: [], reason: 'end_turn' },+ { type: 'turn_end', steps: 1, mark: { seq: index }, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn' },];const conversation = (over: Partial<Parameters<typeof saveConversation>[1]> = {}) => ({@@ -63,7 +63,7 @@ describe('keeping a conversation', () => {const withShot: AgentEvent[] = [{ type: 'turn_start', prompt: 'look', model: 'm', index: 0 },{ type: 'tool_end', id: 'c1', ok: true, summary: 'screenshot attached', image: 'data:image/png;base64,AAAA' },- { type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], reason: 'end_turn' },+ { type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn' },];await saveConversation(root, conversation({ events: withShot }));const back = await loadConversation(root, 'abc-123');diff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.tsindex c444b35b5..b260e7066 100644--- a/desktop/tests/agent-transcript.test.ts+++ b/desktop/tests/agent-transcript.test.ts@@ -20,7 +20,7 @@ const fold = (...events: AgentEvent[]): AgentTurn[] =>const started = (prompt = 'add a pause menu', index = 0, model = 'opus-5'): AgentEvent =>({ type: 'turn_start', prompt, model, index });const ended = (over: Partial<{ steps: number; mark: unknown; reason: 'end_turn' | 'aborted' | 'error' | 'refusal' }> = {}): AgentEvent =>- ({ type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], reason: 'end_turn', ...over });+ ({ type: 'turn_end', steps: 0, mark: null, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn', ...over });const call = (name: string): ToolCall => ({ id: `c-${name}`, name, input: { a: 1 } });const tools = (t: AgentTurn): AgentToolEntry[] => t.entries.filter((e): e is AgentToolEntry => e.kind === 'tool');@@ -300,7 +300,7 @@ describe('which entities a turn touched', () => {});const turn = (entries: AgentToolEntry[], id = 0): AgentTurn => ({id, prompt: 'p', model: 'opus-5', entries, inputTokens: 0, outputTokens: 0, context: null,- steps: 1, mark: { seq: 1 }, endMark: null, tx: null, files: [], reason: 'end_turn', startedAt: 0, endedAt: 1,+ steps: 1, mark: { seq: 1 }, endMark: null, tx: null, files: [], acceptance: { verdict: 'unverified', results: [] }, reason: 'end_turn', startedAt: 0, endedAt: 1,});it('reads the ids out of the argument names the catalog uses', () => {diff --git a/desktop/tests/editor-mcp-tools.test.ts b/desktop/tests/editor-mcp-tools.test.tsindex 9b39b02ce..917a70781 100644--- a/desktop/tests/editor-mcp-tools.test.ts+++ b/desktop/tests/editor-mcp-tools.test.ts@@ -12,11 +12,17 @@ const toolNamed = (name: string) => TOOLS.find((t: { name: string }) => t.name =describe('editor MCP tool registry', () => {it('every tool has a unique name and a surface method, renderer code, or host op', () => {const names = new Set<string>();- for (const t of TOOLS as Array<{ name: string; method?: string; args?: unknown; js?: unknown; op?: unknown; run?: unknown }>) {+ for (const t of TOOLS as Array<{+ name: string; method?: string; args?: unknown; js?: unknown; op?: unknown;+ run?: unknown; loopOnly?: boolean;+ }>) {// A capability carries `run` instead: a program over the atoms below it.if (t.run) expect(typeof t.run).toBe('function');else if (t.js) expect(typeof t.js).toBe('function');else if (t.op) expect(typeof t.op).toBe('string');+ // A `loopOnly` tool is the kernel's own — it declares what a TURN has to+ // hold and reaches no editor door, so it has nothing to dispatch to.+ else if (t.loopOnly) expect(t.method).toBeUndefined();else {expect(typeof t.method).toBe('string');expect(typeof t.args).toBe('function');@@ -27,6 +33,15 @@ describe('editor MCP tool registry', () => {expect(TOOLS.length).toBeGreaterThan(10);});+ // The exception is worth one test of its own, because it is the exception to+ // the file header's "each tool is a transport over the editor surface".+ it('serves the kernel-only tools to nobody remote', () => {+ const loop = (TOOLS as Array<{ name: string; loopOnly?: boolean }>).filter((t) => t.loopOnly);+ expect(loop.map((t) => t.name)).toEqual(['done_when']);+ const listed = listTools(true).map((t: { name: string }) => t.name);+ for (const t of loop) expect(listed).not.toContain(t.name);+ });+it('editor-root tools pass their root through to the driver', async () => {const driver = vi.fn(async () => 3);const createEntity = TOOLS.find((t: { name: string }) => t.name === 'create_entity');@@ -118,7 +133,9 @@ describe('editor MCP tool registry', () => {it('listTools advertises every tool with a description + JSON-Schema inputSchema', () => {const listed = listTools(true);- expect(listed.map((t: { name: string }) => t.name)).toEqual((TOOLS as Array<{ name: string }>).map((t) => t.name));+ const servable = (TOOLS as Array<{ name: string; loopOnly?: boolean }>)+ .filter((t) => !t.loopOnly).map((t) => t.name);+ expect(listed.map((t: { name: string }) => t.name)).toEqual(servable);for (const t of listed as Array<{ description: string; inputSchema: { type: string } }>) {expect(typeof t.description).toBe('string');expect(t.inputSchema.type).toBe('object');diff --git a/desktop/tests/history-groups.test.ts b/desktop/tests/history-groups.test.tsindex d694333f2..5f61bc655 100644--- a/desktop/tests/history-groups.test.ts+++ b/desktop/tests/history-groups.test.ts@@ -22,7 +22,8 @@ const step = (id: number, label = `step ${id}`, undone = false): HistoryStep =>const turn = (id: number, from: number, to: number, over: Partial<AgentTurn> = {}): AgentTurn => ({id, prompt: `turn ${id}`, model: 'opus-5', entries: [],inputTokens: 0, outputTokens: 0, context: null,- steps: to - from, mark: { seq: from }, endMark: { seq: to }, tx: null, files: [],+ steps: to - from, mark: { seq: from }, endMark: { seq: to }, tx: null, files: [],+ acceptance: { verdict: 'unverified', results: [] },reason: 'end_turn', startedAt: 0, endedAt: 1,...over,});