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): a run's change count is that run's, not everything since it
esenginee2c5e245e45a
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 3df878885..13f5ef2c4 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -278,12 +278,12 @@ function Skeleton() {* declared nothing contribute nothing, so this is a floor — which is why an* empty one renders nothing at all rather than "no changes".*/-function ChangeSet({ turn }: { turn: AgentTurn }) {+function ChangeSet({ turn, until }: { turn: AgentTurn; until: HistoryMark | null }) {const [open, setOpen] = useState(true);useSyncExternalStore(EditorHistory.subscribe, EditorHistory.getVersion);const mark = turn.mark as HistoryMark | null;- const changes = mark ? EditorHistory.changesSince(mark) : [];- const counts = changeCounts(turn);+ const changes = mark ? EditorHistory.changesSince(mark, until) : [];+ const counts = changeCounts(turn, until);if (!counts) return null;return (<div className={`ag-changes${open ? ' open' : ''}`}>@@ -326,10 +326,17 @@ function ChangeSet({ turn }: { turn: AgentTurn }) {);}-/** Counts for the turn header: what the run left behind, in one glance. */-function changeCounts(turn: AgentTurn): { add: number; modify: number; remove: number } | null {+/**+ * Counts for the turn header: what THIS run left behind, in one glance.+ *+ * Bounded above by where the next run started. Without that bound an older run+ * reports everything that happened after it — the runs that followed, and the+ * edits the person made in between — so its header would keep growing while it+ * sat there finished.+ */+function changeCounts(turn: AgentTurn, until: HistoryMark | null): { add: number; modify: number; remove: number } | null {const mark = turn.mark as HistoryMark | null;- const changes = mark ? EditorHistory.changesSince(mark) : [];+ const changes = mark ? EditorHistory.changesSince(mark, until) : [];if (changes.length === 0) return null;return {add: changes.filter((c) => c.kind === 'add').length,@@ -361,7 +368,13 @@ function Elapsed({ from, to, className }: { from: number; to: number | null; clareturn <span className={`${className ?? ''}${live ? ' ag-live' : ''}`.trim()}>{formatElapsed(ms)}</span>;}-function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; running: boolean }) {+function Turn({ turn, isLast, running, until }: {+ turn: AgentTurn;+ isLast: boolean;+ running: boolean;+ /** Where the NEXT run started, so this one counts only its own steps. */+ until: HistoryMark | null;+}) {// 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@@ -371,7 +384,7 @@ function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; runuseSyncExternalStore(EditorHistory.subscribe, EditorHistory.getVersion);const tokens = turn.inputTokens + turn.outputTokens;- const counts = changeCounts(turn);+ const counts = changeCounts(turn, until);const empty = turn.entries.length === 0;return (<div className={`ag-turn${folded ? ' folded' : ''}${isLast ? ' current' : ''}`}>@@ -434,7 +447,7 @@ function Turn({ turn, isLast, running }: { turn: AgentTurn; isLast: boolean; runwho just pressed Stop is asking. */}{turn.reason === 'aborted' && <div className="ag-sys">{t('agent.turn.aborted.note')}</div>}{turn.reason === 'refusal' && <div className="ag-sys">{t('agent.turn.refusal.note')}</div>}- {turn.reason !== null && <ChangeSet turn={turn} />}+ {turn.reason !== null && <ChangeSet turn={turn} until={until} />}</div></Fold></div>@@ -808,7 +821,13 @@ export function AgentPanel({ docked }: { docked?: boolean }) {{turns.length === 0? <EmptyState />: turns.map((turn, i) => (- <Turn key={turn.id} turn={turn} isLast={i === turns.length - 1} running={status.phase !== 'idle'} />+ <Turn+ key={turn.id}+ turn={turn}+ isLast={i === turns.length - 1}+ running={status.phase !== 'idle'}+ until={(turns[i + 1]?.mark as HistoryMark | undefined) ?? null}+ />))}{/* Held until the run ends. Shown rather than merely promised: a messagethat vanished into a queue nobody can see is one you retype. */}diff --git a/desktop/src/engine/EditorHistory.ts b/desktop/src/engine/EditorHistory.tsindex 96759ad52..7fc2e6937 100644--- a/desktop/src/engine/EditorHistory.ts+++ b/desktop/src/engine/EditorHistory.ts@@ -249,15 +249,19 @@ export class EditorHistoryImpl {* newest, which {@link stepsSince} plus a version bump is enough to detect.*//**- * What every step since `mark` declared, oldest first — the review of an agent- * turn. Steps that declared nothing contribute nothing, so this is a FLOOR on- * what happened rather than a claim to be the whole of it. Reads the undo- * stack, so an undone step stops being listed.+ * What every step in `(from, until]` declared, oldest first — the review of an+ * agent turn. Steps that declared nothing contribute nothing, so this is a+ * FLOOR on what happened rather than a claim to be the whole of it. Reads the+ * undo stack, so an undone step stops being listed.+ *+ * `until` is what makes it a RUN's changes rather than "everything since": for+ * any run but the newest, the steps after it belong to the runs that followed+ * and to whatever the user did in between. Omit it only for the newest.*/- changesSince(mark: HistoryMark): HistoryChange[] {+ changesSince(mark: HistoryMark, until?: HistoryMark | null): HistoryChange[] {const out: HistoryChange[] = [];for (const entry of this.undoStack) {- if (entry.id > mark.seq) out.push(...entry.changes);+ if (entry.id > mark.seq && (!until || entry.id <= until.seq)) out.push(...entry.changes);}return out;}diff --git a/desktop/tests/history-changes.test.ts b/desktop/tests/history-changes.test.tsindex 74be0f260..90d088395 100644--- a/desktop/tests/history-changes.test.ts+++ b/desktop/tests/history-changes.test.ts@@ -75,4 +75,36 @@ describe('describing a step', () => {history.undo();expect(history.changesSince(mark)).toEqual([]);});++ // A run's header reports what THAT run did. Without an upper bound an older+ // run keeps absorbing everything after it — the runs that followed, and the+ // edits the person made in between — so its count grows while it sits there+ // finished, which is the opposite of a summary.+ it('reports only the window between two marks', () => {+ const first = history.mark();+ history.describe({ kind: 'add', entity: 1, name: 'FromFirstRun' });+ history.record('first run', noop, noop);++ const second = history.mark();+ history.describe({ kind: 'add', entity: 2, name: 'FromSecondRun' });+ history.record('second run', noop, noop);++ expect(history.changesSince(first, second).map((c) => c.name)).toEqual(['FromFirstRun']);+ expect(history.changesSince(second, null).map((c) => c.name)).toEqual(['FromSecondRun']);+ // Unbounded is still "everything since" — what the newest run wants.+ expect(history.changesSince(first).map((c) => c.name))+ .toEqual(['FromFirstRun', 'FromSecondRun']);+ });++ it('excludes the user\'s own edits from the run that preceded them', () => {+ const run = history.mark();+ history.describe({ kind: 'add', entity: 1, name: 'ByTheAgent' });+ history.record('agent step', noop, noop);++ const after = history.mark();+ history.describe({ kind: 'modify', entity: 1, name: 'ByHand' });+ history.record('user edit', noop, noop);++ expect(history.changesSince(run, after).map((c) => c.name)).toEqual(['ByTheAgent']);+ });});