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 transcript stops growing without a ceiling
esengineddd12bd6799a
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 13f5ef2c4..43a9db7a4 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -140,16 +140,22 @@ 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.+ * Everything that folds does it by animating a grid row from 0fr to 1fr.+ *+ * Once opened it stays MOUNTED, because unmounting is the cheaper thing to write+ * and the wrong thing to see: a panel that reappears instantly reads as a jump+ * cut, and one that had been scrolled inside loses that on every toggle.+ *+ * Until then it holds nothing. A conversation carries every run it ever had, and+ * mounting the body of each so it could animate open — when most are folded and+ * will never be opened — is paying for all of them to get the animation on one.*/function Fold({ open, children }: { open: boolean; children: React.ReactNode }) {+ const [everOpen, setEverOpen] = useState(open);+ useEffect(() => { if (open) setEverOpen(true); }, [open]);return (<div className={`ag-fold-w${open ? ' open' : ''}`}>- <div className="ag-fold-i">{children}</div>+ <div className="ag-fold-i">{everOpen ? children : null}</div></div>);}@@ -818,6 +824,13 @@ export function AgentPanel({ docked }: { docked?: boolean }) {stuck.current = el.scrollHeight - el.scrollTop - el.clientHeight < 24;}}>+ {/* Runs the window no longer holds. Absolute ids make this free to know:+ the first one it has says how many came before it. Said out loud+ because a transcript that starts mid-conversation, silently, reads as+ one that lost something. */}+ {turns.length > 0 && turns[0].id > 0 && (+ <div className="ag-sys">{t('agent.earlier', { count: turns[0].id })}</div>+ )}{turns.length === 0? <EmptyState />: turns.map((turn, i) => (diff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.tsindex 3ecab174f..e12b9b279 100644--- a/desktop/src/i18n/messages/agent.ts+++ b/desktop/src/i18n/messages/agent.ts@@ -59,6 +59,10 @@ export const agentMessages = defineMessages({'agent.thinking': { en: 'Thinking', zh: '正在思考' },'agent.queued': { en: 'queued', zh: '排队中' },'agent.queued.msg': { en: 'Queued: {text}', zh: '已排队:{text}' },+ 'agent.earlier': {+ en: '{count} earlier runs are no longer shown here',+ zh: '更早的 {count} 轮已不在此窗口',+ },'agent.stopped': { en: 'stopped', zh: '已中止' },'agent.declined': { en: 'skipped', zh: '已跳过' },'agent.turn.aborted': { en: 'Stopped part-way.', zh: '中途停止。' },diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.tsindex 744a85fbb..a940f4b4c 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -100,6 +100,9 @@ export interface AgentTurn {endedAt: number | null;}+/** Runs this window keeps. Past it the oldest go, the way main's log does. */+const MAX_TURNS = 100;+const IDLE: AgentStatus = {ready: false, conversation: false, phase: 'idle', model: null, error: null,};@@ -274,7 +277,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):// Idempotent, so replaying the stream over a transcript that already has// some of it cannot double a run (see attachAgentBridge).if (turns.some((t) => t.id === event.index)) return turns as AgentTurn[];- return [...turns, {+ const opened: AgentTurn[] = [...turns, {// The SESSION's coordinate, not this array's position. They agree while a// window sees every run, and stop agreeing the moment one reloads — after// which numbering here would aim "re-ask run 0" at the wrong turn.@@ -290,6 +293,11 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):startedAt: Date.now(),endedAt: null,}];+ // Bounded the way main's own log is (it trims by whole runs at 4000 events);+ // a mirror that grew forever would be the one side of this that does. Safe+ // to drop from the front only because a run's identity is its session index+ // and not its position here, so what is left still names itself correctly.+ return opened.length > MAX_TURNS ? opened.slice(-MAX_TURNS) : opened;}const open = openTurn(turns);diff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.tsindex cf27697fd..3759da4f1 100644--- a/desktop/tests/agent-transcript.test.ts+++ b/desktop/tests/agent-transcript.test.ts@@ -232,6 +232,21 @@ describe('the transcript projection', () => {const before = fold(started());expect(applyAgentEvent(before, { type: 'stop', reason: 'tool_use' })).toEqual(before);});++ // main's log trims by whole runs at its own ceiling; a mirror that grew+ // without one would be the side of this that leaks. Dropping from the front+ // is only safe because identity is the session's index, not the position.+ it('keeps a bounded number of runs, oldest out first', () => {+ let turns: AgentTurn[] = [];+ for (let i = 0; i < 130; i++) {+ turns = applyAgentEvent(turns, started(`run ${i}`, i));+ turns = applyAgentEvent(turns, ended());+ }+ expect(turns).toHaveLength(100);+ // What is left still names itself the way the session does.+ expect(turns[0].id).toBe(30);+ expect(turns.at(-1)!.id).toBe(129);+ });});// The Outliner echo. Read off the catalog's own argument names rather than a