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
refactor(editor): one word per thing in the agent transcript
esenginedae977e79e74
diff --git a/desktop/electron/agent/anthropic.ts b/desktop/electron/agent/anthropic.tsindex 68107b98d..49f3a2e6b 100644--- a/desktop/electron/agent/anthropic.ts+++ b/desktop/electron/agent/anthropic.ts@@ -24,7 +24,9 @@ import Anthropic from '@anthropic-ai/sdk';import type {AgentProvider, AgentSession, CatalogTool, StepEvent, ToolOutcome, UserImage,} from './types';-import { DEFAULT_MODEL, DEFAULT_CONTEXT_WINDOW, COMPACT_AT, KEEP_WHOLE_RUNS } from '../../src/settings/agentIds';+import {+ DEFAULT_MODEL, DEFAULT_CONTEXT_WINDOW, KEEP_WHOLE_RUNS, shouldCompact,+} from '../../src/settings/agentIds';/** Agentic work is what `xhigh` is for; it is also the depth Claude Code runs at. */export const DEFAULT_EFFORT = 'xhigh';@@ -432,7 +434,7 @@ class AnthropicSession implements AgentSession {* show for it is the thing this number exists to end.*/private compactIfNeeded(): number {- if (this.contextUsed() <= this.opts.contextWindow * COMPACT_AT) return 0;+ if (!shouldCompact(this.contextUsed(), this.opts.contextWindow)) return 0;const next = compactHistory(this.messages, this.turnStarts, this.dropped, KEEP_WHOLE_RUNS, this.folded,);diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 592b9609c..d430479e9 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -37,7 +37,7 @@ import {addAgentAttachments, removeAgentAttachment, latestContext,type AgentTurn, type AgentEntry, type AgentToolEntry, type AgentProseEntry,} from '@/store/AgentStore';-import { COMPACT_AT } from '@/settings/agentIds';+import { COMPACT_AT, shouldCompact } from '@/settings/agentIds';import type { ConfirmAnswer } from '../../electron/agent/types';import {agentProviders, agentProvider, agentKeyId, parseModelList, subscribeProviders, providersRevision,@@ -462,17 +462,17 @@ function Entries({ entries, streaming, onRerun }: {<span className="ag-ask-hd">{entry.message}</span></div>,);- } else if (entry.kind === 'folded') {+ } else if (entry.kind === 'compacted') {// Where the model stopped remembering. The runs it lost are still on// screen above this line, which is exactly why the line has to be here:// a transcript that shows them and a model that cannot answer about them// otherwise disagree with nothing to explain it.out.push(- <div className="ag-folded" key={i}>+ <div className="ag-compacted" key={i}><FoldVertical size={13} strokeWidth={1.8} /><span>- {entry.runs === 1 ? t('agent.folded.one') : t('agent.folded', { count: entry.runs })}- <span className="ag-folded-w">{t('agent.folded.why')}</span>+ {entry.runs === 1 ? t('agent.compacted.one') : t('agent.compacted', { count: entry.runs })}+ <span className="ag-compacted-w">{t('agent.compacted.why')}</span></span></div>,);@@ -1039,7 +1039,7 @@ function ContextMeter() {const pct = Math.min(100, Math.round((context.used / context.window) * 100));return (<span- className={`ag-ctx${context.used > context.window * COMPACT_AT ? ' near' : ''}`}+ className={`ag-ctx${shouldCompact(context.used, context.window) ? ' near' : ''}`}title={t('agent.context.why', {used: compact(context.used),window: compact(context.window),@@ -1328,10 +1328,11 @@ 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. */}+ {/* Runs this WINDOW no longer holds — the opposite of the compaction+ note inside a run, which is about runs the model 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>)}@@ -1413,7 +1414,10 @@ function entityByName(name: string): number | null {return hits.length === 1 ? hits[0].id : null;}-const compact = (n: number): string => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));+/** Thousands as `1.2k`, and as `200k` where the tenth would be a zero — a+ * context window written "200.0k" claims a precision it does not have. */+const compact = (n: number): string =>+ (n >= 1000 ? `${(n / 1000).toFixed(1).replace(/\.0$/, '')}k` : String(n));/** One line of the call's arguments — enough to tell two calls apart. */function summarizeInput(input: Record<string, unknown>): string {diff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.tsindex 88193fd09..8a3fa782a 100644--- a/desktop/src/i18n/messages/agent.ts+++ b/desktop/src/i18n/messages/agent.ts@@ -95,23 +95,27 @@ export const agentMessages = defineMessages({'agent.thinking': { en: 'Thinking', zh: '正在思考' },'agent.queued': { en: 'queued', zh: '排队中' },'agent.queued.msg': { en: 'Queued: {text}', zh: '已排队:{text}' },+ // The two ways a transcript and a conversation come apart, and they are+ // OPPOSITES: this one is on screen and remembered, that one is remembered+ // and not on screen. Each names the side that lost it, because the risk is+ // reading either as the other.'agent.earlier': {- en: '{count} earlier runs are no longer shown here',- zh: '更早的 {count} 轮已不在此窗口',+ en: '{count} earlier runs are not shown in this window',+ zh: '更早的 {count} 轮不在此窗口显示',},// Once a conversation is past the threshold every further run folds exactly// one, so the singular is the COMMON case rather than the edge one.- 'agent.folded.one': {+ 'agent.compacted.one': {en: 'The earliest run was folded out of the model’s memory',zh: '最早的一轮已折叠出模型的记忆',},- 'agent.folded': {+ 'agent.compacted': {en: 'The earliest {count} runs were folded out of the model’s memory',zh: '最早的 {count} 轮已折叠出模型的记忆',},- 'agent.folded.why': {- en: 'The conversation outgrew the context window. What you asked is kept word for word; the tool calls and their results are gone — have it re-read the scene rather than trusting what it said about them.',- zh: '对话超出了上下文窗口。你问过的话原样保留,工具调用和结果已丢弃 —— 让它重新读一遍场景,别信它对那些内容的转述。',+ 'agent.compacted.why': {+ en: 'Still on screen above, but out of the model’s reach. What you asked is kept word for word; the tool calls and their results are gone — have it re-read the scene rather than trusting what it said about them.',+ zh: '内容仍显示在上方,但模型已经读不到了。你问过的话原样保留,工具调用和结果已丢弃 —— 让它重新读一遍场景,别信它对那些内容的转述。',},'agent.context': { en: '{pct}% context', zh: '上下文 {pct}%' },'agent.context.why': {diff --git a/desktop/src/settings/agentIds.ts b/desktop/src/settings/agentIds.tsindex e8a9670ed..0978f99fd 100644--- a/desktop/src/settings/agentIds.ts+++ b/desktop/src/settings/agentIds.ts@@ -32,3 +32,15 @@ export const DEFAULT_CONTEXT_WINDOW = 128_000;*/export const COMPACT_AT = 0.75;export const KEEP_WHOLE_RUNS = 3;++/**+ * Whether a conversation this full is past that line.+ *+ * The rule lives with the number because two sides ask it and they must not+ * drift apart: the session, deciding whether to fold before its next call, and+ * the editor's meter, saying that the next run is where the folding starts. A+ * comparison written out twice is one edit away from a gauge that promises what+ * the session is not about to do.+ */+export const shouldCompact = (used: number, contextWindow: number): boolean =>+ used > contextWindow * COMPACT_AT;diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.tsindex 8a3e03a69..4106c3e87 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -85,13 +85,19 @@ export interface AgentErrorEntry {* mid-run, between two tool calls — and the runs it took away are still on* screen above it. Reading the transcript afterwards, this is the line that* explains why the model cannot answer about them.+ *+ * Named for the event it comes from, like every other entry here, and NOT for+ * the fold that produced it: "folded" is already what a collapsed run and a+ * collapsed disclosure are called in the drawer, and a third meaning in the+ * same file is one that has to be worked out from context every time.*/-export interface AgentFoldEntry {- kind: 'folded';+export interface AgentCompactedEntry {+ kind: 'compacted';runs: number;}-export type AgentEntry = AgentProseEntry | AgentToolEntry | AgentErrorEntry | AgentFoldEntry;+export type AgentEntry =+ AgentProseEntry | AgentToolEntry | AgentErrorEntry | AgentCompactedEntry;export type TurnReason = 'end_turn' | 'aborted' | 'error' | 'refusal' | 'max_rounds';@@ -490,7 +496,7 @@ export function applyAgentEvent(turns: readonly AgentTurn[], event: AgentEvent):return patchLast(turns, { context: { used: event.used, window: event.window } });case 'compacted':- return withEntries(turns, [...closeProse(open.entries), { kind: 'folded', runs: event.runs }]);+ return withEntries(turns, [...closeProse(open.entries), { kind: 'compacted', runs: event.runs }]);case 'error':return withEntries(turns, [...closeProse(open.entries), { kind: 'error', message: event.message }]);diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex 8e9a19a72..5a8e56f90 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -125,11 +125,13 @@}.ag-sys::before, .ag-sys::after { content: ''; height: 1px; background: var(--line); flex: 1; }-/* Where the model stopped remembering its earliest runs. Not one of the- hairline notes above: those are asides about a message, and this one is about- the conversation itself — it needs a second sentence, because "folded away"- without "your questions are kept" reads as the agent having lost the plot. */-.ag-folded {+/* Where the model stopped remembering its earliest runs.+ Deliberately UNLIKE the hairline note above, which says the opposite thing+ about the opposite side ("this window is not showing every run"). They are the+ two ways a transcript and a conversation come apart, and the whole risk is+ reading one as the other — so the quiet aside stays an aside, and the one+ about the model's own memory gets a block and a second sentence. */+.ag-compacted {display: flex; gap: 9px;padding: 10px 14px;border-top: 1px solid var(--line);@@ -137,8 +139,8 @@font-size: var(--fs-xs);color: var(--text-dim);}-.ag-folded > svg { flex: none; margin-top: 2px; color: var(--text-faint); }-.ag-folded-w { display: block; margin-top: 3px; color: var(--text-faint); }+.ag-compacted > svg { flex: none; margin-top: 2px; color: var(--text-faint); }+.ag-compacted-w { display: block; margin-top: 3px; color: var(--text-faint); }/* ── A run ─────────────────────────────────────────────────────────────────The unit of work, so it gets a header: what was asked plus the numbers thatdiff --git a/desktop/tests/agent-transcript.test.ts b/desktop/tests/agent-transcript.test.tsindex 02065efe7..0625d9e7d 100644--- a/desktop/tests/agent-transcript.test.ts+++ b/desktop/tests/agent-transcript.test.ts@@ -207,8 +207,8 @@ describe('the transcript projection', () => {{ type: 'compacted', runs: 4 },{ type: 'text', delta: 'Carrying on.' },);- expect(turn.entries.map((e) => e.kind)).toEqual(['thinking', 'folded', 'text']);- expect(turn.entries[1]).toEqual({ kind: 'folded', runs: 4 });+ expect(turn.entries.map((e) => e.kind)).toEqual(['thinking', 'compacted', 'text']);+ expect(turn.entries[1]).toEqual({ kind: 'compacted', runs: 4 });// The block above it is over: a fold is something else beginning.expect((turn.entries[0] as AgentProseEntry).endedAt).not.toBeNull();});