Skip to content

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

feat(agent): the claim only a person can settle is one a person is now asked

yhh668c7220e51d
diff --git a/desktop/electron/agent/acceptance.ts b/desktop/electron/agent/acceptance.ts
index d3d5cec30..b9fbfb4fa 100644
--- a/desktop/electron/agent/acceptance.ts
+++ b/desktop/electron/agent/acceptance.ts
@@ -50,6 +50,9 @@ export type CriterionOwner = 'editor' | 'project' | 'turn';
* `unsettled` is neither pass nor fail: nothing was in a position to answer it.
*/
export interface CriterionResult extends DeclaredCriterion {
+ /** A person answered this one. Only ever true on a `manual` claim, which is
+ * the only kind waiting for them. */
+ settled?: boolean;
state: 'held' | 'broke' | 'unsettled';
/** What it answered, or why nothing could answer it. */
detail?: string;
diff --git a/desktop/electron/agent/host.ts b/desktop/electron/agent/host.ts
index c6799f1da..11b833cdc 100644
--- a/desktop/electron/agent/host.ts
+++ b/desktop/electron/agent/host.ts
@@ -114,6 +114,12 @@ export interface AgentHost {
/** Answer a pending confirmation. Unknown ids are ignored — the turn it
* belonged to may have been aborted between the ask and the click. */
confirm(callId: string, answer: ConfirmAnswer, declined?: readonly number[]): void;
+ /**
+ * Answer a claim of run `turn` that only a person could settle. Recorded on
+ * the stream, so the run's verdict says the same thing after a reload as it
+ * did when the answer was given.
+ */
+ settle(turn: number, index: number, held: boolean): void;
/** Drop the conversation and start over; the next turn re-reads the key. */
reset(): AgentStatus;
/** Put a saved conversation back — transcript and memory both. */
@@ -395,6 +401,9 @@ export function createAgentHost(deps: AgentHostDeps): AgentHost {
// not interrupt — it is waiting on us, not on the model.
settlePending();
},
+ settle: (turn, index, held) => {
+ record({ type: 'claim_settled', turn, index, held });
+ },
confirm: (callId, answer, declined) => {
const resolve = pending.get(callId);
if (!resolve) return;
diff --git a/desktop/electron/agent/types.ts b/desktop/electron/agent/types.ts
index 8ffd60056..d0fede96f 100644
--- a/desktop/electron/agent/types.ts
+++ b/desktop/electron/agent/types.ts
@@ -287,6 +287,14 @@ export type AgentEvent =
* whether what it stopped on is any good. */
acceptance: Acceptance;
}
+ /**
+ * A claim only a person could settle, answered by one. `turn` is the run's
+ * session index and `index` the claim's position in that run's results.
+ *
+ * An event rather than window state: the drawer's runs are a fold over this
+ * stream, so an answer kept anywhere else is one a reload throws away.
+ */
+ | { type: 'claim_settled'; turn: number; index: number; held: boolean }
| { type: 'error'; message: string };
/** Everything the kernel needs from outside, so it runs under a test with none
diff --git a/desktop/electron/main.ts b/desktop/electron/main.ts
index e6d29960d..68777e4d0 100644
--- a/desktop/electron/main.ts
+++ b/desktop/electron/main.ts
@@ -793,6 +793,10 @@ ipcMain.handle(
'agent:confirm',
(_e, callId: string, answer: ConfirmAnswer, declined?: number[]) => agentHost.confirm(callId, answer, declined),
);
+ipcMain.handle(
+ 'agent:settleClaim',
+ (_e, turn: number, index: number, held: boolean) => agentHost.settle(turn, index, held),
+);
/**
* Put back the project files one or more runs wrote, and tell the window which
* paths moved so its ordinary external-change path picks them up. A LIST
diff --git a/desktop/electron/preload.ts b/desktop/electron/preload.ts
index 5ea53caf4..638c4b279 100644
--- a/desktop/electron/preload.ts
+++ b/desktop/electron/preload.ts
@@ -130,6 +130,10 @@ const api = {
/** Answer the pending confirmation for an irreversible tool. */
confirm: (callId: string, answer: ConfirmAnswer, declined?: readonly number[]): Promise<void> =>
ipcRenderer.invoke('agent:confirm', callId, answer, declined),
+ /** Answer a claim of that run only a person could settle, by its position
+ * in the run's results. */
+ settleClaim: (turn: number, index: number, held: boolean): Promise<void> =>
+ ipcRenderer.invoke('agent:settleClaim', turn, index, held),
/** Put back the project files these runs wrote (their file-journal
* transactions) and say what came back. The DOCUMENT half is this window's
* own undo — see src/engine/rewind.ts. */
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsx
index 9023e1208..e8d476dec 100644
--- a/desktop/src/components/AgentDrawer.tsx
+++ b/desktop/src/components/AgentDrawer.tsx
@@ -543,7 +543,7 @@ function Verdict({ turn }: { turn: AgentTurn }) {
</button>
<Fold open={open}>
<div className="ag-verdict-l">
- {results.map((r, i) => <Claim key={i} result={r} />)}
+ {results.map((r, i) => <Claim key={i} result={r} turnId={turn.id} index={i} />)}
</div>
</Fold>
</div>
@@ -569,9 +569,12 @@ const CHECK: Record<string, string> = {
scripts: t('hist.check.scripts'),
};
-function Claim({ result }: { result: CriterionResult }) {
+function Claim({ result, turnId, index }: { result: CriterionResult; turnId: number; index: number }) {
const [kept, setKept] = useState(false);
const canKeep = result.owner === 'turn' && result.state === 'held' && !kept;
+ // The only claims waiting on anybody. Until one is answered the run is not
+ // passed, which is what stops `manual` being the cheap way past the verdict.
+ const asking = result.owner === 'turn' && result.state === 'unsettled' && !!result.manual;
return (
<div className={`ag-claim s-${result.state} o-${result.owner}`}>
<span className="ag-claim-s">
@@ -579,9 +582,30 @@ function Claim({ result }: { result: CriterionResult }) {
</span>
<span className="ag-claim-t">
{result.owner !== 'turn' && <span className="ag-claim-o">{OWNER[result.owner]}</span>}
+ {result.settled && <span className="ag-claim-o">{t('agent.claim.yours')}</span>}
{(result.check && CHECK[result.check]) ?? result.says}
{result.detail && <span className="ag-claim-d">{result.detail}</span>}
</span>
+ {asking && (
+ <span className="ag-claim-ask">
+ <button
+ type="button"
+ className="ag-claim-yes"
+ title={t('agent.claim.ask')}
+ onClick={() => void window.estella?.agent?.settleClaim?.(turnId, index, true)}
+ >
+ {t('agent.claim.held')}
+ </button>
+ <button
+ type="button"
+ className="ag-claim-no"
+ title={t('agent.claim.ask')}
+ onClick={() => void window.estella?.agent?.settleClaim?.(turnId, index, false)}
+ >
+ {t('agent.claim.broke')}
+ </button>
+ </span>
+ )}
{canKeep && (
<button
type="button"
diff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.ts
index f8d270b32..32916a534 100644
--- a/desktop/src/i18n/messages/agent.ts
+++ b/desktop/src/i18n/messages/agent.ts
@@ -223,6 +223,16 @@ export const agentMessages = defineMessages({
// nobody checked is the thing most worth saying out loud.
'agent.verdict.unverified': { en: 'Nothing checked this work', zh: '没有任何东西检查过这份工作' },
+ // A claim the run said only a person could settle. Until one does, the run
+ // is not passed — which is what keeps `manual` from being the way past it.
+ 'agent.claim.ask': {
+ en: 'The run says only you can settle this one',
+ zh: '这一条这轮说只有你能判',
+ },
+ 'agent.claim.held': { en: 'It holds', zh: '成立' },
+ 'agent.claim.broke': { en: 'It does not', zh: '不成立' },
+ 'agent.claim.yours': { en: 'you', 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.ts
index 866df8402..c827a8718 100644
--- a/desktop/src/store/AgentStore.ts
+++ b/desktop/src/store/AgentStore.ts
@@ -18,6 +18,9 @@
*/
import { create } from 'zustand';
import type { AgentStatus, AgentMessage } from '../../electron/agent/host';
+// The rule that turns results into a verdict, not a second reading of it: a
+// claim settled here has to come to the same answer the kernel would.
+import { verdictOf } from '../../electron/agent/acceptance';
import type {
Acceptance, AgentEvent, ConfirmAnswer, ConfirmReason, ConfirmRequest, FileChange,
} from '../../electron/agent/types';
@@ -517,6 +520,18 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):
// would make the next turn_start look like a repeat of one already held.
if (event.type === 'conversation_reset') return [];
+ // Aimed at a FINISHED run by its own coordinate — the claim it answers is one
+ // the turn could not settle itself, so the answer necessarily arrives later.
+ if (event.type === 'claim_settled') {
+ return turns.map((t) => {
+ if (t.id !== event.turn) return t;
+ const results = t.acceptance.results.map((r, i) => (i === event.index
+ ? { ...r, state: event.held ? 'held' as const : 'broke' as const, settled: true, detail: undefined }
+ : r));
+ return { ...t, acceptance: { verdict: verdictOf(results), results } };
+ });
+ }
+
if (event.type === 'turn_start') {
// Idempotent, so replaying the stream over a transcript that already has
// some of it cannot double a run (see attachAgentBridge).
diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.css
index 03666bc6c..9b7cc6a16 100644
--- a/desktop/src/theme/agent.css
+++ b/desktop/src/theme/agent.css
@@ -1030,6 +1030,22 @@
while reading, and a row of buttons down the list would read as the point. */
.ag-claim:hover .ag-claim-keep { opacity: 1; }
.ag-claim-keep:hover { color: var(--text-hi); border-color: var(--text-dim); }
+/* Always shown, unlike Keep: the run is asking, and an ask that appears on
+ hover is one nobody knows is there. */
+.ag-claim-ask { align-self: start; display: flex; gap: 4px; margin-top: -1px; }
+.ag-claim-ask > button {
+ padding: 1px 7px;
+ border: 1px solid var(--border);
+ border-radius: var(--r-sm);
+ background: none;
+ color: var(--text-dim);
+ font: var(--fs-2xs) var(--font-ui);
+ cursor: pointer;
+ transition: color var(--t-fast), border-color var(--t-fast);
+}
+/* The same two colours the row's own sigil uses for held and broke. */
+.ag-claim-yes:hover { color: var(--run); border-color: var(--run); }
+.ag-claim-no:hover { color: var(--warn); border-color: var(--warn); }
.ag-chg {
display: grid;
grid-template-columns: 14px minmax(0, 1fr) auto;
diff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.ts
index b260e7066..0c97f5c03 100644
--- a/desktop/tests/agent-transcript.test.ts
+++ b/desktop/tests/agent-transcript.test.ts
@@ -369,4 +369,52 @@ describe('a result as one cell', () => {
it('says nothing for an empty result', () => {
expect(briefResult(' ')).toBe('');
});
-});
\ No newline at end of file
+});
+/**
+ * A claim only a person could settle, answered by one.
+ *
+ * It arrives as an EVENT because the drawer's runs are a fold over the stream:
+ * an answer kept beside it would be one a window reload throws away, leaving a
+ * run whose verdict disagrees with the answer the user gave it.
+ */
+describe('settling a claim the run left to a person', () => {
+ const withClaim = (): AgentEvent => ({
+ type: 'turn_end',
+ steps: 0, mark: null, endMark: null, tx: null, files: [], reason: 'end_turn',
+ acceptance: {
+ verdict: 'unverified',
+ results: [
+ { says: 'the bar empties', probe: 'x', state: 'held', owner: 'turn' },
+ { says: 'it reads at 1080p', manual: 'legibility', state: 'unsettled', owner: 'turn' },
+ ],
+ },
+ });
+
+ it('passes the run once the person says it holds', () => {
+ const [turn] = fold(started(), withClaim(), { type: 'claim_settled', turn: 0, index: 1, held: true });
+ expect(turn.acceptance.results[1]).toMatchObject({ state: 'held', settled: true });
+ expect(turn.acceptance.verdict).toBe('passed');
+ });
+
+ it('fails the run when they say it does not', () => {
+ const [turn] = fold(started(), withClaim(), { type: 'claim_settled', turn: 0, index: 1, held: false });
+ expect(turn.acceptance.verdict).toBe('failed');
+ });
+
+ it('leaves the run unverified while nobody has answered', () => {
+ const [turn] = fold(started(), withClaim());
+ expect(turn.acceptance.verdict).toBe('unverified');
+ });
+
+ // Runs are addressed by the SESSION's coordinate, and an answer aimed at one
+ // run must not land on whichever happens to be open.
+ it('answers the run it names, not the open one', () => {
+ const turns = fold(
+ started('first', 0), withClaim(),
+ started('second', 1),
+ { type: 'claim_settled', turn: 0, index: 1, held: true },
+ );
+ expect(turns[0].acceptance.verdict).toBe('passed');
+ expect(turns[1].acceptance.verdict).toBe('unverified');
+ });
+});