A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(editor): the agent drawer behaves like its prototype, not just like its stylesheet
esengine774c1c74c25f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 506b9cbd2..97d7ac5af 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -39,6 +39,37 @@ published separately; it ships inside the editor.lands under the cursor.- **The viewport canvas is sized from its own layout box**, not `floor(clientWidth × dpr)`— which lost up to a pixel at fractional dpr, the case UI zoom makes ordinary.+- **A message typed while the agent was working is no longer lost.** The composer said+ "this will be the next message"; the host refuses a send mid-turn, and nobody held it —+ so the box cleared, the send was rejected, and what you typed was gone, replaced by a+ red banner. It is queued now, shown in the transcript while it waits, and sent when the+ turn ends. Stopping the turn drops the queue, because stopping means stop.+- **The agent's typing caret sits after the last character** instead of on its own line+ below the paragraph — it was rendered after the whole markdown block rather than inside+ it, which read as a stray blinking box rather than as text being written.+- **A tool row's result column says what came back.** It showed the first ~20 characters+ of the raw result, which for a JSON answer is `[{"id` — and the disclosure under it was+ the *same* string, flattened and cut at 160 characters, so expanding a row taught you+ nothing. The row now carries a one-cell summary (a list is its length, an object leads+ with its first named string) and the disclosure keeps the full result with its line+ structure intact.++### Changed++- **The agent transcript animates the way the prototype does.** Runs, reasoning, tool+ details and the change set all fold on a grid row rather than being unmounted, so+ nothing appears as a jump cut and an expanded detail keeps its scroll; a finished run+ folds itself to its header when the next one starts; new blocks rise in as they arrive;+ and a confirmation flashes once on arrival so it is not read past.+- **The agent has a mark.** Four facets that light in turn while it works — in the drawer+ head, the empty state and the status bar, so "still working" is legible with the drawer+ shut. It wears the editor's own violet, not a palette of its own.+- **A run's header says which model answered it** and what it left in the scene (`+7 ~1`).+ The composer's picker only ever says what the *next* message will use, and a+ conversation can switch models between runs.+- **A tool row's glyph says what kind of call it is** — reading, writing, or the one that+ cannot be taken back — instead of turning green on success. Tinting every finished row+ green made the rows that matter harder to find.## [0.39.0] - 2026-08-01diff --git a/desktop/electron/agent/host.ts b/desktop/electron/agent/host.tsindex d038423a0..409522080 100644--- a/desktop/electron/agent/host.ts+++ b/desktop/electron/agent/host.ts@@ -149,7 +149,7 @@ export function createAgentHost(deps: AgentHostDeps): AgentHost {// would be a second definition of "what the agent knows".const context = await editorContext(deps.driver).catch(() => null);await runTurn(- { driver: deps.driver, session: session!, confirm, emit },+ { driver: deps.driver, session: session!, model: model ?? '', confirm, emit },text,context,controller.signal,diff --git a/desktop/electron/agent/kernel.ts b/desktop/electron/agent/kernel.tsindex 432b88e8f..421564c62 100644--- a/desktop/electron/agent/kernel.ts+++ b/desktop/electron/agent/kernel.ts@@ -35,10 +35,17 @@ function confirmReason(tool: CatalogTool): ConfirmReason {: 'irreversible';}-/** Short enough to render as one transcript row; the model gets the full text. */+/**+ * The result as the transcript's disclosure shows it: bounded so a tool that+ * returns a megabyte cannot cost the renderer that much, but NOT flattened —+ * the shape of a scene tree or a diagnostics list is most of what makes it+ * readable, and squeezing it onto one line threw that away. The one-line+ * version beside the row is a rendering decision, made in the editor+ * (AgentStore's briefResult).+ */function summarize(text: string): string {- const flat = text.replace(/\s+/g, ' ').trim();- return flat.length > 160 ? `${flat.slice(0, 157)}…` : flat;+ const trimmed = text.trim();+ return trimmed.length > 4000 ? `${trimmed.slice(0, 3997)}…` : trimmed;}/**@@ -77,9 +84,9 @@ export async function runTurn(context: string | null,signal: AbortSignal,): Promise<{ mark: unknown; steps: number }> {- const { driver, session, emit } = deps;+ const { driver, session, emit, model } = deps;const mark = await driver('mark', []);- emit({ type: 'turn_start', prompt: text });+ emit({ type: 'turn_start', prompt: text, model });let reason: Extract<AgentEvent, { type: 'turn_end' }>['reason'] = 'end_turn';try {diff --git a/desktop/electron/agent/types.ts b/desktop/electron/agent/types.tsindex 4284b46c0..fa54ce7ca 100644--- a/desktop/electron/agent/types.ts+++ b/desktop/electron/agent/types.ts@@ -133,7 +133,9 @@ export interface ConfirmRequest {*/export type AgentEvent =| StepEvent- | { type: 'turn_start'; prompt: string }+ /** `model` because a conversation can change models between runs, and the+ * header of a past run has to say which one actually answered it. */+ | { type: 'turn_start'; prompt: string; model: string }| { type: 'tool_start'; call: ToolCall; effect: NonNullable<CatalogTool['effect']> }| { type: 'tool_end'; id: string; ok: boolean; summary: string; image?: string }| { type: 'awaiting_confirm'; request: ConfirmRequest }@@ -152,6 +154,9 @@ export interface KernelDeps {op(op: string, input?: Record<string, unknown>): Promise<unknown>;};session: AgentSession;+ /** What is behind `session`, for the transcript. The session abstraction has+ * no name for itself, and the host is where that name is known. */+ model: string;/** Ask the person. Resolving false means "declined", which the model is told. */confirm(request: ConfirmRequest): Promise<boolean>;emit(event: AgentEvent): void;diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 347637621..8752d8a9b 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -40,6 +40,7 @@ import {import { secretStatus, subscribeSecrets, secretRevision } from '@/store/SecretStore';import { useSettings } from '@/store/settingsStore';import { MarkdownView } from '@/components/MarkdownView';+import { AgentMark } from '@/components/AgentMark';import { dockApi } from '@/layout/dockApi';import { EditorHistory, type HistoryMark } from '@/engine/EditorHistory';import { useSelection } from '@/store/selectionStore';@@ -64,7 +65,7 @@ function ToolRow({ entry, onConfirm }: { entry: AgentToolEntry; onConfirm: (alloreturn (<><div- className={`ag-call ag-call--${entry.state}`}+ className={`ag-call ag-call--${entry.state} ag-call-e--${entry.effect ?? 'read'}`}onMouseEnter={() => touches.length && peekEntities(touches)}onMouseLeave={() => touches.length && peekEntities([])}>@@ -78,13 +79,15 @@ function ToolRow({ entry, onConfirm }: { entry: AgentToolEntry; onConfirm: (allo{entry.state === 'awaiting' && <TriangleAlert size={11} />}{entry.state === 'stopped' && t('agent.stopped')}{entry.state === 'declined' && t('agent.declined')}- {(entry.state === 'ok' || entry.state === 'error') && entry.summary}+ {(entry.state === 'ok' || entry.state === 'error') && entry.brief}</span></button>{/* What the agent looked at, shown without asking: a screenshot row thathides its screenshot is a row you have to click to learn anything from. */}{entry.image && <img className="ag-shot" src={entry.image} alt={entry.name} />}- {open && entry.summary && <div className="ag-call-detail">{entry.summary}</div>}+ {entry.summary && (+ <Fold open={open}><div className="ag-call-detail">{entry.summary}</div></Fold>+ )}</div>{entry.state === 'awaiting' && <ConfirmPassage entry={entry} onConfirm={onConfirm} />}</>@@ -123,6 +126,21 @@ function ConfirmPassage({ entry, onConfirm }: { entry: AgentToolEntry; onConfirm);}+/**+ * Everything that folds does it by animating a grid row from 0fr to 1fr, and+ * therefore keeps its content MOUNTED. Unmounting is the cheaper thing to write+ * and the wrong thing to see: a panel that appears instantly reads as a jump+ * cut, and one that has been scrolled or selected inside loses that on every+ * toggle.+ */+function Fold({ open, children }: { open: boolean; children: React.ReactNode }) {+ return (+ <div className={`ag-fold-w${open ? ' open' : ''}`}>+ <div className="ag-fold-i">{children}</div>+ </div>+ );+}+function Thinking({ text }: { text: string }) {const [open, setOpen] = useState(false);return (@@ -131,7 +149,7 @@ function Thinking({ text }: { text: string }) {<ChevronRight size={10} strokeWidth={2} className="ag-car" /><span>{t('agent.thinking')}</span></button>- {open && <div className="ag-think-body">{text}</div>}+ <Fold open={open}><div className="ag-think-body">{text}</div></Fold></div>);}@@ -140,10 +158,8 @@ function Prose({ text, streaming }: { text: string; streaming?: boolean }) {const [copied, setCopied] = useState(false);return (<div className="ag-say">- <MarkdownView text={text} entity={entityByName} />- {/* The caret rides the last paragraph while tokens are still arriving —- the difference between "thinking" and "finished" at a glance. */}- {streaming && <span className="ag-caret" />}+ {/* The caret rides the tail of the text itself — see MarkdownView. */}+ <MarkdownView text={text} entity={entityByName} caret={streaming} /><buttontype="button"className="ag-say-copy"@@ -241,13 +257,8 @@ function ChangeSet({ turn }: { turn: AgentTurn }) {useSyncExternalStore(EditorHistory.subscribe, EditorHistory.getVersion);const mark = turn.mark as HistoryMark | null;const changes = mark ? EditorHistory.changesSince(mark) : [];- if (changes.length === 0) return null;-- const counts = {- add: changes.filter((c) => c.kind === 'add').length,- modify: changes.filter((c) => c.kind === 'modify').length,- remove: changes.filter((c) => c.kind === 'remove').length,- };+ const counts = changeCounts(turn);+ if (!counts) return null;return (<div className={`ag-changes${open ? ' open' : ''}`}><button type="button" className="ag-changes-h" onClick={() => setOpen((o) => !o)}>@@ -258,7 +269,7 @@ function ChangeSet({ turn }: { turn: AgentTurn }) {{counts.modify > 0 && <span className="ag-mod">~{counts.modify}</span>}{counts.remove > 0 && <span className="ag-del">−{counts.remove}</span>}</button>- {open && (+ <Fold open={open}><div className="ag-changes-l">{changes.map((c, i) => (<div@@ -284,11 +295,23 @@ function ChangeSet({ turn }: { turn: AgentTurn }) {</div>))}</div>- )}+ </Fold></div>);}+/** Counts for the turn header: what the run left behind, in one glance. */+function changeCounts(turn: AgentTurn): { add: number; modify: number; remove: number } | null {+ const mark = turn.mark as HistoryMark | null;+ const changes = mark ? EditorHistory.changesSince(mark) : [];+ if (changes.length === 0) return null;+ return {+ add: changes.filter((c) => c.kind === 'add').length,+ modify: changes.filter((c) => c.kind === 'modify').length,+ remove: changes.filter((c) => c.kind === 'remove').length,+ };+}+/** A field value in one cell. Long values are cut — the row is a summary, and* the field itself is one click away in Details. */function brief(value: unknown): string {@@ -313,14 +336,16 @@ function Elapsed({ turn }: { turn: AgentTurn }) {}function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; running: boolean }) {- // Past runs arrive folded; the one you are in stays open. Local state so the- // user's own fold survives the next event landing in the store.+ // A finished run folds to its header: the stat line already IS the summary, so+ // the body becomes detail you ask for rather than detail you scroll past.+ // Keyed on isLast changing, which is the moment a run becomes history — after+ // that the fold is the user's, and re-opening one stays open.const [folded, setFolded] = useState(!isLast);- useEffect(() => {- if (isLast) setFolded(false);- }, [isLast]);+ useEffect(() => { setFolded(!isLast); }, [isLast]);+ useSyncExternalStore(EditorHistory.subscribe, EditorHistory.getVersion);const tokens = turn.inputTokens + turn.outputTokens;+ const counts = changeCounts(turn);const empty = turn.entries.length === 0;return (<div className={`ag-turn${folded ? ' folded' : ''}${isLast ? ' current' : ''}`}>@@ -344,15 +369,26 @@ function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; run)}</span><span className="ag-stat">+ {/* Which model answered THIS run. A conversation can switch between+ them, and the composer's picker only ever says what is next. */}+ {turn.model && <span className="ag-stat-model">{turn.model}</span>}+ <span className="ag-sp" /><Elapsed turn={turn} />{tokens > 0 && <span>↑{compact(turn.inputTokens)} ↓{compact(turn.outputTokens)}</span>}- <span className="ag-sp" />{turn.reason === 'aborted' && <span className="ag-warn">{t('agent.turn.aborted')}</span>}{turn.reason === 'refusal' && <span className="ag-warn">{t('agent.turn.refusal')}</span>}- {turn.steps > 0 && <span className="ag-add">{t('agent.checkpoint.steps', { count: turn.steps })}</span>}+ {/* What the run left in the scene — the number the summary is actually+ about, which is why it reads here and not only inside the fold. */}+ {counts && (+ <span className="ag-stat-chg">+ {counts.add > 0 && <span className="ag-add">+{counts.add}</span>}+ {counts.modify > 0 && <span className="ag-mod">~{counts.modify}</span>}+ {counts.remove > 0 && <span className="ag-del">−{counts.remove}</span>}+ </span>+ )}</span></button>- {!folded && (+ <Fold open={!folded}><div className="ag-tb">{empty && running && isLast ? <Skeleton /> : (<Entries entries={turn.entries} onConfirm={confirmAgentCall} streaming={running && isLast} />@@ -363,7 +399,7 @@ function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; run{running && isLast && turn.entries.length > 0 && lastIsSettled(turn.entries) && <Waiting />}{turn.reason !== null && <ChangeSet turn={turn} />}</div>- )}+ </Fold></div>);}@@ -390,6 +426,7 @@ function EmptyState() {];return (<div className="ag-empty">+ <AgentMark size={34} /><h4>{t('agent.empty.title')}</h4><p>{t('agent.empty.body')}</p><div className="ag-sugs">@@ -640,6 +677,7 @@ export function AgentPanel({ docked }: { docked?: boolean }) {const setOpen = useEditorStore((s) => s.setAgentDrawer);const turns = useAgent((s) => s.turns);const status = useAgent((s) => s.status);+ const queued = useAgent((s) => s.queued);const logRef = useRef<HTMLDivElement>(null);const stuck = useRef(true);// A question that has scrolled away is a turn that looks hung. Watched per@@ -662,13 +700,15 @@ export function AgentPanel({ docked }: { docked?: boolean }) {useLayoutEffect(() => {const el = logRef.current;if (el && stuck.current) el.scrollTop = el.scrollHeight;- }, [turns]);+ }, [turns, queued]);return (<div className="ag-panel"><div className={`ag-head${docked ? ' docked' : ''}`}>- {/* Docked, the tab already says Agent — a second title under it is the- same word twice and 40px of nothing. */}+ {/* The mark carries "working" even when the transcript is scrolled away+ from the row that would say so. Docked, the tab already says Agent —+ a second title under it is the same word twice and 40px of nothing. */}+ <AgentMark size={docked ? 13 : 15} live={status.phase !== 'idle'} />{!docked && <span className="ag-ttl">{t('agent.title')}</span>}<span className="ag-sp" /><button type="button" title={t('agent.newConversation')} onClick={() => void resetAgentSession()}>@@ -707,6 +747,11 @@ export function AgentPanel({ docked }: { docked?: boolean }) {: turns.map((turn, i) => (<Turn key={turn.id} turn={turn} isLast={i === turns.length - 1} running={status.phase !== 'idle'} />))}+ {/* Held until the run ends. Shown rather than merely promised: a message+ that vanished into a queue nobody can see is one you retype. */}+ {queued.map((text, i) => (+ <div className="ag-sys" key={i}>{t('agent.queued.msg', { text })}</div>+ ))}</div>{askOffscreen && (diff --git a/desktop/src/components/AgentMark.tsx b/desktop/src/components/AgentMark.tsxnew file mode 100644index 000000000..cd21356a2--- /dev/null+++ b/desktop/src/components/AgentMark.tsx@@ -0,0 +1,36 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file AgentMark.tsx+ * @brief The agent's mark: four facets around a centre.+ *+ * The ONE shape that means "the agent" — the drawer head, the empty state and+ * the status bar all wear it, so the same mark means the same thing wherever it+ * turns up. `live` lights the facets in turn, which is the thing a spinner in+ * the transcript cannot do: say that work is still happening from across the+ * window, with the drawer closed.+ *+ * Drawn in the editor's own violet (--nebula) rather than a palette of its own,+ * the same accent the Outliner dot and the viewport echo already use for "the+ * agent touched this".+ */+export function AgentMark({ size = 14, live, className }: {+ size?: number;+ live?: boolean;+ className?: string;+}) {+ return (+ <svg+ className={`ag-mark${live ? ' live' : ''}${className ? ` ${className}` : ''}`}+ width={size}+ height={size}+ viewBox="0 0 24 24"+ aria-hidden="true"+ >+ <path className="ag-p-n" d="M12 1.6 13.55 10.6 12 12 10.45 10.6Z" />+ <path className="ag-p-e" d="M22.4 12 13.4 13.55 12 12 13.4 10.45Z" />+ <path className="ag-p-s" d="M12 22.4 10.45 13.4 12 12 13.55 13.4Z" />+ <path className="ag-p-w" d="M1.6 12 10.6 10.45 12 12 10.6 13.55Z" />+ </svg>+ );+}diff --git a/desktop/src/components/MarkdownView.tsx b/desktop/src/components/MarkdownView.tsxindex 129cc22ed..abbee9ae9 100644--- a/desktop/src/components/MarkdownView.tsx+++ b/desktop/src/components/MarkdownView.tsx@@ -84,12 +84,23 @@ function CodeBlock({ block }: { block: Extract<Block, { kind: 'code' }> }) {);}-export function MarkdownView({ text, entity }: {+export function MarkdownView({ text, entity, caret }: {text: string;/** Resolve a code span to a scene entity, making it clickable. */entity?: (name: string) => number | null;+ /**+ * Tokens are still arriving, so ride the tail with a caret.+ *+ * It is rendered INSIDE the last block, after the last span, because the whole+ * effect is "the text is being typed": a caret placed after the markdown sits+ * on its own line under the paragraph, which reads as a stray blinking box+ * rather than as a cursor. A fenced block that is still open says so with its+ * own edge (.md-pre.open), so it takes no caret.+ */+ caret?: boolean;}) {const blocks = useMemo(() => parseBlocks(text), [text]);+ const tail = (i: number) => (caret && i === blocks.length - 1 ? <span className="md-caret" /> : null);return (<div className="md">{blocks.map((b, i) => {@@ -98,22 +109,23 @@ export function MarkdownView({ text, entity }: {return <CodeBlock key={i} block={b} />;case 'h': {const Tag = (`h${Math.min(b.level + 2, 6)}`) as 'h3';- return <Tag className="md-h" key={i}><Spans spans={b.spans} entity={entity} /></Tag>;+ return <Tag className="md-h" key={i}><Spans spans={b.spans} entity={entity} />{tail(i)}</Tag>;+ }+ case 'list': {+ const items = b.items.map((item, j) => (+ <li key={j}>+ <Spans spans={item} entity={entity} />+ {j === b.items.length - 1 && tail(i)}+ </li>+ ));+ return b.ordered+ ? <ol className="md-list" key={i}>{items}</ol>+ : <ul className="md-list" key={i}>{items}</ul>;}- case 'list':- return b.ordered ? (- <ol className="md-list" key={i}>- {b.items.map((item, j) => <li key={j}><Spans spans={item} entity={entity} /></li>)}- </ol>- ) : (- <ul className="md-list" key={i}>- {b.items.map((item, j) => <li key={j}><Spans spans={item} entity={entity} /></li>)}- </ul>- );case 'rule':return <hr className="md-rule" key={i} />;default:- return <p className="md-p" key={i}><Spans spans={b.spans} entity={entity} /></p>;+ return <p className="md-p" key={i}><Spans spans={b.spans} entity={entity} />{tail(i)}</p>;}})}</div>diff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.tsindex fbd5f890b..b4a21b779 100644--- a/desktop/src/i18n/messages/agent.ts+++ b/desktop/src/i18n/messages/agent.ts@@ -58,6 +58,7 @@ export const agentMessages = defineMessages({'agent.waiting': { en: 'Waiting for the model', zh: '等待模型响应' },'agent.thinking': { en: 'Thinking', zh: '正在思考' },'agent.queued': { en: 'queued', zh: '排队中' },+ 'agent.queued.msg': { en: 'Queued: {text}', zh: '已排队:{text}' },'agent.stopped': { en: 'stopped', zh: '已中止' },'agent.declined': { en: 'skipped', zh: '已跳过' },'agent.turn.aborted': { en: 'Stopped part-way.', zh: '中途停止。' },diff --git a/desktop/src/layout/StatusBar.tsx b/desktop/src/layout/StatusBar.tsxindex 6d382a1b6..f45195881 100644--- a/desktop/src/layout/StatusBar.tsx+++ b/desktop/src/layout/StatusBar.tsx@@ -1,9 +1,10 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport { useSyncExternalStore } from 'react';-import { Gauge, MousePointer2, Boxes, FolderOpen, MemoryStick, Cpu, Sparkles, Square, Scaling } from 'lucide-react';+import { Gauge, MousePointer2, Boxes, FolderOpen, MemoryStick, Cpu, Square, Scaling } from 'lucide-react';import { useEditorStore } from '@/store/editorStore';import { useSettings } from '@/store/settingsStore';+import { AgentMark } from '@/components/AgentMark';import { UI_SCALE_SETTING, ZOOM_DEFAULT, setUiZoom } from './uiZoom';import { useSelection } from '@/store/selectionStore';import { useAgent, stopAgentTurn } from '@/store/AgentStore';@@ -76,7 +77,9 @@ function AgentSegment() {return (<span className={`sitem ag-seg${waiting ? ' waiting' : ''}`}><button type="button" className="ag-seg-open" onClick={() => setDrawer(true)}>- <Sparkles size={11} strokeWidth={1.9} />+ {/* The same mark the drawer wears, lit while it works — this strip is+ what you can see with the drawer closed. */}+ <AgentMark size={11} live={!waiting} />{waiting ? t('agent.status.awaiting') : t('agent.status.running')}</button><button type="button" className="ag-seg-stop" title={t('agent.stop')} onClick={stopAgentTurn}>diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.tsindex fc1a433cf..a66a550b4 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -47,8 +47,10 @@ export interface AgentToolEntry {/** Known once it actually starts; the model's request does not say. */effect: AgentEffect | null;state: ToolState;- /** The result, shortened for one row. */+ /** The result in full, for the disclosure. */summary: string | null;+ /** The same result as one cell beside the row — see {@link briefResult}. */+ brief: string | null;/** A frame the call rendered — the transcript shows what the agent looked at. */image: string | null;/** The arguments as the model is WRITING them: raw JSON text, incomplete@@ -76,6 +78,8 @@ export interface AgentTurn {/** Position in the conversation; stable, so React keys are too. */id: number;prompt: string;+ /** Which model answered THIS run — the conversation can switch between them. */+ model: string;entries: AgentEntry[];inputTokens: number;outputTokens: number;@@ -110,6 +114,8 @@ interface AgentState {* naming `id: 7` means nothing until 7 lights up where you already look.*/peeked: readonly number[];+ /** Typed while a turn was running, waiting for it to end. See sendAgentMessage. */+ queued: readonly string[];/** The turn whose checkpoint bar has been answered — see AgentCheckpoint. */checkpointDone: number | null;/** What the user picked, or null for "whichever provider has a key". */@@ -117,7 +123,7 @@ interface AgentState {}export const useAgent = create<AgentState>(() => ({- status: IDLE, turns: [], driving: false, peeked: [], checkpointDone: null,+ status: IDLE, turns: [], driving: false, peeked: [], queued: [], checkpointDone: null,selection: loadSelection(),}));@@ -246,6 +252,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):return [...turns, {id: turns.length,prompt: event.prompt,+ model: event.model,entries: [],inputTokens: 0,outputTokens: 0,@@ -283,6 +290,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):effect: null,state: 'queued',summary: null,+ brief: null,image: null,argText: '',reason: null,@@ -310,7 +318,9 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):// decline as an ordinary failed call, and painting it as an error would// blame the tool for the user's answer.const state: ToolState = e.state === 'declined' ? 'declined' : event.ok ? 'ok' : 'error';- return { ...e, state, summary: event.summary, image: event.image ?? null };+ return {+ ...e, state, summary: event.summary, brief: briefResult(event.summary), image: event.image ?? null,+ };}));case 'usage':@@ -340,6 +350,36 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):}}+/**+ * A tool's result as the ONE cell beside its row: the "58" next to+ * `get_scene_tree`, not the tree. The full text stays in `summary`, one click+ * away — a row whose result column holds the first 20 characters of a JSON+ * blob tells you nothing and hides the count that would have.+ *+ * Three rules, because a fourth would be guessing at a catalog that keeps+ * growing: a list is its length, an object leads with its first named string+ * (`kind: "scene"` reads as "scene"), and anything else is its first line.+ */+export function briefResult(text: string): string {+ const trimmed = text.trim();+ if (!trimmed) return '';+ try {+ const value: unknown = JSON.parse(trimmed);+ if (Array.isArray(value)) return String(value.length);+ if (value && typeof value === 'object') {+ const first = Object.values(value).find((v) => typeof v === 'string' && v);+ if (typeof first === 'string') return clip(first);+ return clip(String(Object.keys(value).length));+ }+ return clip(String(value));+ } catch {+ /* not JSON — the tool answered in prose */+ }+ return clip(trimmed.split('\n')[0]);+}++const clip = (s: string): string => (s.length > 26 ? `${s.slice(0, 25)}…` : s);+/*** A conversation main still holds means this window is driving, whatever it* remembers — a renderer that reloaded mid-conversation would otherwise leave@@ -347,6 +387,8 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):*/function adoptStatus(status: AgentStatus): void {useAgent.setState((s) => ({ status, driving: s.driving || status.conversation }));+ // The turn that was refusing sends has ended — release what was held for it.+ if (status.phase === 'idle') drainQueue();}export function applyAgentMessage(message: AgentMessage): void {@@ -370,6 +412,14 @@ export function attachAgentBridge(): () => void {}export async function sendAgentMessage(text: string): Promise<void> {+ // The host REFUSES a send while a turn runs, so holding the message is this+ // side's job. Without it the composer's own promise ("this will be the next+ // message") was a lie that cost the person what they had typed: the box was+ // already cleared, and all they got back was a red banner.+ if (useAgent.getState().status.phase !== 'idle') {+ useAgent.setState((s) => ({ queued: [...s.queued, text] }));+ return;+ }// Before the IPC, not after: main drives this window through// `window.__estellaEditor`, which is published only while a driver is// authorized (engine/automationGate.ts) and this store is what says so for the@@ -380,6 +430,17 @@ export async function sendAgentMessage(text: string): Promise<void> {if (status) adoptStatus(status);}+/** Send what was held while the last turn ran, oldest first. */+function drainQueue(): void {+ const [next, ...rest] = useAgent.getState().queued;+ if (next === undefined) return;+ useAgent.setState({ queued: rest });+ void sendAgentMessage(next);+}++/** Nothing queued survives the turn being stopped: stopping means stop. */+export const clearAgentQueue = (): void => useAgent.setState({ queued: [] });+/*** Ask a turn again, discarding it and everything after it — on both sides. The* store truncates first so the transcript never shows runs the session has@@ -394,6 +455,7 @@ export async function retryAgentTurn(turnId: number): Promise<void> {}export function stopAgentTurn(): void {+ clearAgentQueue();void window.estella?.agent?.stop();}@@ -419,7 +481,7 @@ export function confirmAgentCall(callId: string, allow: boolean): void {/** Drop the conversation — a new one starts with the next message. */export async function resetAgentSession(): Promise<void> {- useAgent.setState({ turns: [], driving: false });+ useAgent.setState({ turns: [], driving: false, queued: [] });const status = await window.estella?.agent?.reset();if (status) useAgent.setState({ status }); // not adoptStatus: reset just ended it}diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex a932039dc..1b30d0600 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -72,6 +72,52 @@.ag-log { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; padding-bottom: 12px; }+/* ── The mark ───────────────────────────────────────────────────────────────+ Four facets around a centre, in the same violet the Outliner dot and the+ viewport echo use. Lit in turn while a turn runs: a transcript row can only+ say "working" to someone already reading it, and this has to say it from the+ status bar with the drawer shut. */+.ag-mark { display: block; flex: none; color: var(--nebula); }+.ag-mark path { fill: currentColor; }+.ag-p-n { opacity: 1; }+.ag-p-e { opacity: 0.78; }+.ag-p-s { opacity: 0.45; }+.ag-p-w { opacity: 0.62; }+@media (prefers-reduced-motion: no-preference) {+ .ag-mark.live path { animation: ag-facet 1.8s var(--e-out) infinite; }+ .ag-mark.live .ag-p-e { animation-delay: 0.45s; }+ .ag-mark.live .ag-p-s { animation-delay: 0.9s; }+ .ag-mark.live .ag-p-w { animation-delay: 1.35s; }+}+@keyframes ag-facet { 0%, 62%, 100% { opacity: 0.45; } 22% { opacity: 1; } }++/* ── Folding ────────────────────────────────────────────────────────────────+ 0fr→1fr on a grid row: the one way to animate to a height nobody measured.+ Content stays mounted (see the Fold component) — an expanded tool detail that+ was scrolled keeps its scroll, and nothing appears as a jump cut. */+.ag-fold-w { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--t-slow) var(--e-out); }+.ag-fold-w.open { grid-template-rows: 1fr; }+.ag-fold-i { overflow: hidden; min-height: 0; }+@media (prefers-reduced-motion: reduce) { .ag-fold-w { transition: none; } }++/* Each block arrives rather than appears — the transcript is being written, and+ a row that pops in at full opacity reads as a repaint. */+@media (prefers-reduced-motion: no-preference) {+ .ag-tb > * { animation: ag-rise 0.24s var(--e-out) both; }+}+@keyframes ag-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }++/* A note from the editor rather than from either party: queued, stopped,+ reverted. Centred between two hairlines so it reads as a break in the+ conversation, not as a message in it. */+.ag-sys {+ display: flex; align-items: center; gap: 10px;+ padding: 10px 14px;+ font-size: var(--fs-xs);+ color: var(--text-faint);+}+.ag-sys::before, .ag-sys::after { content: ''; height: 1px; background: var(--line); flex: 1; }+/* ── A run ─────────────────────────────────────────────────────────────────The unit of work, so it gets a header: what was asked plus the numbers thatget checked afterwards. Only the CURRENT run sticks — every past header@@ -106,6 +152,8 @@color: var(--text-faint);}.ag-stat .ag-sp { flex: 1; }+.ag-stat-model { max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+.ag-stat-chg { display: flex; gap: 7px; }.ag-add { color: var(--run); }.ag-warn { color: var(--warn); }@@ -191,7 +239,11 @@.ag-call--queued { opacity: 0.45; }.ag-call--stopped, .ag-call--declined { opacity: 0.5; }.ag-call--running .ag-call-nm { color: var(--text-hi); }-.ag-call--ok .ag-call-g { color: var(--run); }+/* The glyph says what KIND of call it is — reading, writing, or the one that+ cannot be taken back. Success is not a colour: it is the result in `out`, and+ tinting every finished row green makes the rows that matter harder to find. */+.ag-call-e--undoable .ag-call-g { color: var(--text-dim); }+.ag-call-e--irreversible .ag-call-g { color: var(--warn); }.ag-call--error .ag-call-g, .ag-call--error .ag-call-out { color: var(--error); }.ag-call--awaiting .ag-call-g, .ag-call--awaiting .ag-call-out { color: var(--warn); }.ag-call-detail {@@ -221,6 +273,12 @@}.ag-ask--confirm { --ag-tone: var(--warn); }.ag-ask--fail { --ag-tone: var(--error); }+/* Arriving in a transcript that has been scrolling on its own, a question that+ merely appeared is one you read past. It flashes ONCE, on arrival. */+@media (prefers-reduced-motion: no-preference) {+ .ag-ask--confirm { animation: ag-flash 1.1s var(--e-out); }+}+@keyframes ag-flash { 0%, 100% { background: transparent; } 40% { background: var(--hover); } }.ag-ask-g { color: var(--ag-tone); margin-top: 1px; }.ag-ask-hd { font-size: var(--fs-md); font-weight: 500; color: var(--text-hi); letter-spacing: -0.01em; line-height: 1.4; }.ag-ask-d { grid-column: 2; font-size: var(--fs-sm); color: var(--text-dim); margin-top: 5px; line-height: 1.65; }@@ -538,8 +596,9 @@/* Still being written — the closing fence has not arrived. */.md-pre.open { box-shadow: inset 2px 0 0 var(--nebula); }-/* The caret that rides the tail of the text while tokens arrive. */-.ag-caret {+/* The caret that rides the tail of the text while tokens arrive — inside the+ last block, so it sits after the last character rather than under it. */+.md-caret {display: inline-block;width: 6px; height: 13px;margin-left: 2px;diff --git a/desktop/tests/agent-queue.test.ts b/desktop/tests/agent-queue.test.tsnew file mode 100644index 000000000..0e8e27ac0--- /dev/null+++ b/desktop/tests/agent-queue.test.ts@@ -0,0 +1,88 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Messages typed while a turn is running.+ *+ * The host REFUSES a send mid-turn, so the composer's promise ("this will+ * be the next message") is kept on this side or not at all. It used to be+ * not at all: the box was cleared, the send was rejected, and what the+ * person typed was gone — a red banner in its place. These are the+ * regression tests for holding it instead.+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import { useAgent, sendAgentMessage, stopAgentTurn, applyAgentMessage } from '@/store/AgentStore';+import type { AgentStatus } from '../electron/agent/host';++const send = vi.fn(async (_text: string) => undefined);+const stop = vi.fn();++const status = (phase: AgentStatus['phase']): AgentStatus =>+ ({ ready: true, conversation: true, phase, model: 'opus-5', error: null });++/** What main pushes when a turn starts or ends. */+const pushStatus = (phase: AgentStatus['phase']) => applyAgentMessage({ kind: 'status', status: status(phase) });++beforeEach(() => {+ send.mockClear();+ stop.mockClear();+ (globalThis as { window?: unknown }).window = { estella: { agent: { send, stop } } };+ useAgent.setState({ status: status('idle'), turns: [], queued: [], driving: false });+});++afterEach(() => { delete (globalThis as { window?: unknown }).window; });++describe('messages typed while a turn runs', () => {+ it('sends straight through when nothing is running', async () => {+ await sendAgentMessage('add a pause menu');+ expect(send).toHaveBeenCalledWith('add a pause menu');+ expect(useAgent.getState().queued).toEqual([]);+ });++ it('holds the message instead of losing it to a refused send', async () => {+ useAgent.setState({ status: status('running') });+ await sendAgentMessage('and make the buttons bigger');+ expect(send).not.toHaveBeenCalled();+ expect(useAgent.getState().queued).toEqual(['and make the buttons bigger']);+ });++ it('holds one per message, in the order they were typed', async () => {+ useAgent.setState({ status: status('running') });+ await sendAgentMessage('first');+ await sendAgentMessage('second');+ expect(useAgent.getState().queued).toEqual(['first', 'second']);+ });++ // A confirmation is not the turn ending — the run still owns the session.+ it('keeps holding while the turn waits on a confirmation', async () => {+ useAgent.setState({ status: status('awaiting_confirm') });+ await sendAgentMessage('meanwhile, rename it');+ expect(send).not.toHaveBeenCalled();+ expect(useAgent.getState().queued).toEqual(['meanwhile, rename it']);+ });++ it('releases the oldest one when the turn ends', async () => {+ useAgent.setState({ status: status('running') });+ await sendAgentMessage('first');+ await sendAgentMessage('second');++ pushStatus('idle');+ await Promise.resolve();+ expect(send).toHaveBeenCalledTimes(1);+ expect(send).toHaveBeenCalledWith('first');+ expect(useAgent.getState().queued).toEqual(['second']);+ });++ // Stopping means stop: a queue that drained itself afterwards would start a+ // turn the person had just asked to end.+ it('drops what was held when the turn is stopped', async () => {+ useAgent.setState({ status: status('running') });+ await sendAgentMessage('never mind this one');+ stopAgentTurn();+ expect(useAgent.getState().queued).toEqual([]);+ expect(stop).toHaveBeenCalled();++ pushStatus('idle');+ await Promise.resolve();+ expect(send).not.toHaveBeenCalled();+ });+});diff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.tsindex b0244e964..71d4aba8f 100644--- a/desktop/tests/agent-transcript.test.ts+++ b/desktop/tests/agent-transcript.test.ts@@ -9,7 +9,7 @@*/import { describe, it, expect } from 'vitest';import {- applyAgentEvent, entitiesInInput, touchedEntities,+ applyAgentEvent, entitiesInInput, touchedEntities, briefResult,type AgentTurn, type AgentToolEntry,} from '../src/store/AgentStore';import type { AgentEvent, ToolCall } from '../electron/agent/types';@@ -17,7 +17,8 @@ import type { AgentEvent, ToolCall } from '../electron/agent/types';const fold = (...events: AgentEvent[]): AgentTurn[] =>events.reduce<AgentTurn[]>((turns, e) => applyAgentEvent(turns, e), []);-const started = (prompt = 'add a pause menu'): AgentEvent => ({ type: 'turn_start', prompt });+const started = (prompt = 'add a pause menu', model = 'opus-5'): AgentEvent =>+ ({ type: 'turn_start', prompt, model });const ended = (over: Partial<{ steps: number; mark: unknown; reason: 'end_turn' | 'aborted' | 'error' | 'refusal' }> = {}): AgentEvent =>({ type: 'turn_end', steps: 0, mark: null, reason: 'end_turn', ...over });const call = (name: string): ToolCall => ({ id: `c-${name}`, name, input: { a: 1 } });@@ -30,6 +31,13 @@ describe('the transcript projection', () => {expect(turns.map((t) => t.reason)).toEqual(['end_turn', null]);});+ // The header of a past run has to say which model answered IT — the picker in+ // the composer only ever says what the NEXT message will use.+ it('records the model that answered each run, not just the current one', () => {+ const turns = fold(started('one', 'opus-5'), ended(), started('two', 'haiku-4-5'));+ expect(turns.map((t) => t.model)).toEqual(['opus-5', 'haiku-4-5']);+ });+it('gathers a streamed answer into one paragraph', () => {const [turn] = fold(started(),@@ -229,3 +237,28 @@ describe('which entities a turn touched', () => {expect([...touchedEntities(turns, 1)]).toEqual([]);});});++// The row's result column is one cell wide. It used to hold the first 20+// characters of whatever the tool returned — for a JSON answer that is `[{"id`,+// which tells you nothing and hides the count that would have.+describe('a result as one cell', () => {+ it('counts a list', () => {+ expect(briefResult('[{"id":0,"name":"Camera"},{"id":1,"name":"Sprite0"}]')).toBe('2');+ });++ it('leads an object with its first named string', () => {+ expect(briefResult('{"kind":"scene","dirty":false,"path":"main.esscene"}')).toBe('scene');+ });++ it('falls back to the first line of prose', () => {+ expect(briefResult('ok\nnothing else to report')).toBe('ok');+ });++ it('clips a long line rather than letting it push the row', () => {+ expect(briefResult('x'.repeat(80))).toHaveLength(26);+ });++ it('says nothing for an empty result', () => {+ expect(briefResult(' ')).toBe('');+ });+});