From 87ce01d25195b27ab3516a51536c3f2076c026fa Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 25 Nov 2026 15:12:37 +0800 Subject: [PATCH] fix(agents): use default arrow cursors on controls and refine tool call folding (#5804) Keep the default arrow cursor on non-link controls and disclosure summaries across src/features/agents/, reserving pointer cursors for links. Refine conversation folding so edits, commands, and interim messages remain visible by default: - Default agents.foldTurns (fold_turns) to false across Rust and frontend settings - Restrict grouped ProcessRun folding to consecutive reasoning and read-only exploration tool calls (read, search, fetch, think without diffs) - When foldTurns is enabled, fold only earlier turns (leaving the latest turn open) and flatten grouped runs inside a folded turn to avoid nested folds - Keep turn-folding test coverage active in unit, E2E, and Rust settings tests --- crates/ide-core/src/settings.rs | 4 +- e2e/agentToolImages.spec.ts | 11 +++ src/features/agents/Agents.module.css | 2 - src/features/agents/Composer.module.css | 7 -- src/features/agents/McpServers.module.css | 2 - src/features/agents/ReferenceChip.module.css | 7 +- src/features/agents/Session.module.css | 20 ++---- src/features/agents/SessionAssets.module.css | 2 - src/features/agents/SessionPicker.module.css | 2 - src/features/agents/SettingsPage.module.css | 2 - src/features/agents/SkillsPage.module.css | 1 - src/features/agents/agentSettings.ts | 2 +- src/features/agents/session/Stream.tsx | 4 +- .../agents/session/conversationRows.test.ts | 58 +++++++++++++--- .../agents/session/conversationRows.ts | 16 +++-- src/features/agents/sessionState.test.tsx | 69 ++++++++++++++++--- src/features/agents/timeline.test.ts | 29 ++++---- src/features/agents/timeline.ts | 13 ++-- .../settings/__tests__/agents.test.ts | 2 +- src/features/settings/model/schema.ts | 2 +- 20 files changed, 166 insertions(+), 89 deletions(-) diff --git a/crates/ide-core/src/settings.rs b/crates/ide-core/src/settings.rs index 86703c0cf8..37e10f20e4 100644 --- a/crates/ide-core/src/settings.rs +++ b/crates/ide-core/src/settings.rs @@ -145,7 +145,7 @@ impl Default for AgentSettings { show_work_time: true, show_usage_limits: true, show_cost: false, - fold_turns: true, + fold_turns: false, smooth_text: true, fit_window_width: false, thinking: ThinkingDisplay::Auto, @@ -2113,8 +2113,10 @@ mod tests { assert!(old.agents.show_cost); assert!(old.agents.show_context_usage && old.agents.show_work_time && old.agents.show_usage_limits); assert!(!old.agents.fit_window_width); + assert!(!old.agents.fold_turns); assert!(!Settings::default().agents.show_cost); assert!(!Settings::default().agents.fit_window_width); + assert!(!Settings::default().agents.fold_turns); let mut settings = Settings::default(); settings.agents.show_usage_limits = false; settings.agents.fit_window_width = true; diff --git a/e2e/agentToolImages.spec.ts b/e2e/agentToolImages.spec.ts index 1a26a21fce..058c04777e 100644 --- a/e2e/agentToolImages.spec.ts +++ b/e2e/agentToolImages.spec.ts @@ -61,6 +61,15 @@ const entries: AgentEntry[] = [ diffs: [], }, { type: "agent", text: "The preview is ready: front, side and back." }, + { + type: "user", + text: "Looks good.", + attachments: [], + sentMs: 3000, + doneMs: 4000, + steered: false, + }, + { type: "agent", text: "Glad it helped." }, ]; async function showImages(page: Page, foldTurns = true) { @@ -103,6 +112,8 @@ for (const foldTurns of [true, false]) { expect(box.x + box.width).toBeLessThanOrEqual(page.viewportSize()!.width); const fold = page.locator("details").first(); await expect(fold).not.toHaveAttribute("open"); + if (foldTurns) await expect(fold.locator("summary").first()).toContainText("1s"); + else await expect(fold.locator("summary").first()).not.toContainText("1s"); await preview.click(); const dialog = page.getByRole("dialog", { name: "Image", exact: true }); await expect(dialog.getByRole("img")).toHaveJSProperty("naturalWidth", 900); diff --git a/src/features/agents/Agents.module.css b/src/features/agents/Agents.module.css index d42d8cfcdd..c017ede220 100644 --- a/src/features/agents/Agents.module.css +++ b/src/features/agents/Agents.module.css @@ -119,7 +119,6 @@ background: none; color: var(--fg-subtle); --icon-color: currentColor; - cursor: pointer; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); @@ -176,7 +175,6 @@ background: none; color: inherit; font: inherit; - cursor: pointer; } .statusItem:hover { background: var(--bg-hover); diff --git a/src/features/agents/Composer.module.css b/src/features/agents/Composer.module.css index 00ad4f365a..b03b1d46c6 100644 --- a/src/features/agents/Composer.module.css +++ b/src/features/agents/Composer.module.css @@ -222,14 +222,12 @@ background: transparent; color: var(--fg); font: inherit; - cursor: pointer; } .refreshModels:hover:not(:disabled) { color: var(--fg-strong); } .refreshModels:disabled { color: var(--fg-muted); - cursor: default; } .quickSettings { display: flex; @@ -265,7 +263,6 @@ border-radius: var(--radius-small); background: transparent; color: var(--fg-muted); - cursor: pointer; } .modelRowConfigure:hover, .modelRowConfigure:focus-visible { @@ -309,7 +306,6 @@ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - cursor: pointer; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); @@ -465,7 +461,6 @@ background: var(--bg-popup); box-shadow: 0 0 0 1px var(--border); color: var(--fg); - cursor: pointer; opacity: 0; } .image:hover .removeImage, @@ -501,7 +496,6 @@ outline: 1px dashed var(--border-strong); outline-offset: -1px; color: var(--fg-muted); - cursor: pointer; transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); @@ -529,7 +523,6 @@ border-radius: var(--radius-small); background: none; color: var(--fg-muted); - cursor: pointer; } .removeChip:hover { background: var(--bg-hover); diff --git a/src/features/agents/McpServers.module.css b/src/features/agents/McpServers.module.css index f8fb38dbd2..f941187138 100644 --- a/src/features/agents/McpServers.module.css +++ b/src/features/agents/McpServers.module.css @@ -251,7 +251,6 @@ color: var(--fg-muted); font: inherit; font-size: var(--fs-small); - cursor: pointer; } .segmentActive { @@ -278,7 +277,6 @@ color: var(--fg-secondary); font: inherit; font-size: var(--fs-small); - cursor: pointer; } .agentChip:hover { diff --git a/src/features/agents/ReferenceChip.module.css b/src/features/agents/ReferenceChip.module.css index 7be2618e58..dc0b0a1d2e 100644 --- a/src/features/agents/ReferenceChip.module.css +++ b/src/features/agents/ReferenceChip.module.css @@ -15,7 +15,7 @@ font-size: var(--agent-fs-small, var(--fs-small)); line-height: calc(20px + max(0px, var(--agent-font-zoom, 0px)) * 1.4); white-space: nowrap; - cursor: pointer; + cursor: default; user-select: none; transition: background var(--dur-fast) var(--ease), @@ -58,7 +58,6 @@ border-radius: var(--radius-small); background: none; color: var(--fg-muted); - cursor: pointer; } .chipRemove:hover { background: var(--bg-hover); @@ -227,7 +226,6 @@ border-radius: var(--radius-small); background: none; color: var(--fg-muted); - cursor: pointer; } .codeRemove:hover, .codeCopy:hover { @@ -265,9 +263,6 @@ background: var(--bg-hover); } /* In the composer: the card opens as text on a click. */ -.codeCard[title] { - cursor: pointer; -} .codeCard[title]:hover { box-shadow: inset 0 0 0 1px var(--border-strong); } diff --git a/src/features/agents/Session.module.css b/src/features/agents/Session.module.css index 237eba9d42..6fb8a235bb 100644 --- a/src/features/agents/Session.module.css +++ b/src/features/agents/Session.module.css @@ -127,7 +127,6 @@ font-size: var(--fs-small); font-variant-numeric: tabular-nums; white-space: nowrap; - cursor: pointer; } .statusChip:hover { background: var(--bg-toolbar-hover); @@ -253,7 +252,6 @@ border-radius: var(--radius-toolbar-button); background: var(--bg-app); color: var(--fg-muted); - cursor: pointer; } /* Over the stream's text: keep it opaque against the icon button's translucent hover fill. */ .streamArea .jumpToLatest:not(:disabled):hover { @@ -568,7 +566,6 @@ border-radius: var(--radius-small); background: var(--bg-elev); color: var(--fg-secondary); - cursor: pointer; opacity: 0; -webkit-user-select: none; user-select: none; @@ -747,7 +744,6 @@ background: var(--bg-elev); color: var(--fg-secondary); font: inherit; - cursor: pointer; } .loadImage:hover { background: var(--bg-toolbar-hover); @@ -771,7 +767,7 @@ } .thought summary, .toolDetails > summary { - cursor: pointer; + cursor: default; list-style: none; } .thought summary::-webkit-details-marker, @@ -863,7 +859,6 @@ background: none; padding: 0 4px; border-radius: var(--radius-small); - cursor: pointer; white-space: nowrap; } .toolDiff:hover { @@ -872,7 +867,7 @@ /* Reasoning and tool calls between messages, folded as one block per turn. */ .processRun > summary { - cursor: pointer; + cursor: default; list-style: none; } .processRun > summary::-webkit-details-marker { @@ -1233,7 +1228,6 @@ background: var(--bg-popup); box-shadow: 0 0 0 1px var(--border); color: var(--fg); - cursor: pointer; } /* Opaque on hover too: the icon button's own hover fill is translucent over the image. */ .imageItem .removeImage:not(:disabled):hover { @@ -1384,7 +1378,6 @@ color: var(--fg); font: inherit; text-align: left; - cursor: pointer; } .subagentOpen:hover { background: var(--bg-hover); @@ -1427,7 +1420,7 @@ padding-left: 22px; color: var(--fg-muted); font-size: var(--agent-fs-small, var(--fs-small)); - cursor: pointer; + cursor: default; list-style: none; } .subagentSection > summary::-webkit-details-marker { @@ -1524,7 +1517,6 @@ color: var(--fg-secondary); font: inherit; font-size: var(--fs-small); - cursor: pointer; } .subagentChip:hover { background: var(--bg-toolbar-hover); @@ -1774,7 +1766,7 @@ /* A finished turn's work, folded under its message. */ .turnFold > summary { - cursor: pointer; + cursor: default; list-style: none; } .turnFold > summary::-webkit-details-marker { @@ -1822,7 +1814,6 @@ color: var(--fg-secondary); font: inherit; font-size: var(--fs-small); - cursor: pointer; } .trayChip:hover, .trayChip[aria-expanded="true"] { @@ -1943,7 +1934,6 @@ } .meterButton { composes: meter; - cursor: pointer; color: inherit; font: inherit; border: 0; @@ -2005,7 +1995,7 @@ flex-basis: 0; } .contextDetails summary { - cursor: pointer; + cursor: default; color: var(--fg); } .contextDetails ul { diff --git a/src/features/agents/SessionAssets.module.css b/src/features/agents/SessionAssets.module.css index fa5d39efc9..76035a45e9 100644 --- a/src/features/agents/SessionAssets.module.css +++ b/src/features/agents/SessionAssets.module.css @@ -24,7 +24,6 @@ font-size: var(--fs-small); font-variant-numeric: tabular-nums; white-space: nowrap; - cursor: pointer; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), @@ -99,7 +98,6 @@ font: inherit; font-size: var(--fs-ui); text-align: left; - cursor: pointer; } .rowMain:focus-visible { diff --git a/src/features/agents/SessionPicker.module.css b/src/features/agents/SessionPicker.module.css index c383a849ed..e02b11b3fd 100644 --- a/src/features/agents/SessionPicker.module.css +++ b/src/features/agents/SessionPicker.module.css @@ -11,7 +11,6 @@ color: var(--fg-secondary); font: inherit; white-space: nowrap; - cursor: pointer; transition: background var(--dur-fast) var(--ease); } @@ -195,7 +194,6 @@ color: var(--fg-secondary); font: inherit; font-size: var(--fs-tiny); - cursor: pointer; } .inlineLink:hover { diff --git a/src/features/agents/SettingsPage.module.css b/src/features/agents/SettingsPage.module.css index e35ddfbcef..bd59bc10cf 100644 --- a/src/features/agents/SettingsPage.module.css +++ b/src/features/agents/SettingsPage.module.css @@ -109,7 +109,6 @@ font: inherit; font-weight: 600; text-align: left; - cursor: pointer; } .chevron { @@ -190,7 +189,6 @@ color: inherit; font: inherit; text-align: left; - cursor: pointer; } .cardMain { diff --git a/src/features/agents/SkillsPage.module.css b/src/features/agents/SkillsPage.module.css index f0cd155d22..ed4ac4f25a 100644 --- a/src/features/agents/SkillsPage.module.css +++ b/src/features/agents/SkillsPage.module.css @@ -97,7 +97,6 @@ background: var(--bg-elev); color: var(--fg); font-size: var(--fs-small); - cursor: pointer; } .candidateBtn:hover { diff --git a/src/features/agents/agentSettings.ts b/src/features/agents/agentSettings.ts index d05bd46bc0..149ea393e3 100644 --- a/src/features/agents/agentSettings.ts +++ b/src/features/agents/agentSettings.ts @@ -10,7 +10,7 @@ export const AGENT_SETTINGS_DEFAULTS: ResolvedAgentSettings = { showWorkTime: true, showUsageLimits: true, showCost: false, - foldTurns: true, + foldTurns: false, smoothText: true, fitWindowWidth: false, thinking: "auto", diff --git a/src/features/agents/session/Stream.tsx b/src/features/agents/session/Stream.tsx index 8e8486a02e..e09a16f2ef 100644 --- a/src/features/agents/session/Stream.tsx +++ b/src/features/agents/session/Stream.tsx @@ -506,8 +506,8 @@ export function Stream({ const rows = useMemo(() => { if (!entries) return []; const rows = conversationRows(entries, start, toolCalls === "grouped"); - return foldTurns && !finding ? foldTurnRows(rows, foldedTurns(entries, start, busy)) : rows; - }, [entries, start, busy, foldTurns, toolCalls, finding]); + return foldTurns && !finding ? foldTurnRows(rows, foldedTurns(entries, start)) : rows; + }, [entries, start, foldTurns, toolCalls, finding]); const authorHeaders = useMemo(() => { const headers = new Set(); const byAgent = (row: ConversationRow) => diff --git a/src/features/agents/session/conversationRows.test.ts b/src/features/agents/session/conversationRows.test.ts index fef40bac0c..966c1a5a96 100644 --- a/src/features/agents/session/conversationRows.test.ts +++ b/src/features/agents/session/conversationRows.test.ts @@ -12,24 +12,62 @@ const user = (text: string): AgentEntry => ({ doneMs: 5000, }); const agent = (text: string): AgentEntry => ({ type: "agent", text }); -const tool = (id: string, added = 0): AgentEntry => ({ +const tool = (id: string, kind = "read", added = 0): AgentEntry => ({ type: "tool", id, title: id, - kind: "edit", + kind, status: "completed", locations: [], output: null, diffs: added ? [{ path: `/${id}.ts`, added, removed: 0 }] : [], }); -const rowsOf = (entries: AgentEntry[], busy = false) => { +const rowsOf = (entries: AgentEntry[]) => { const rows = conversationRows(entries, 0); - return foldTurnRows(rows, foldedTurns(entries, 0, busy)); + return foldTurnRows(rows, foldedTurns(entries, 0)); }; +describe("conversationRows", () => { + it("groups consecutive read-only exploration entries and keeps edits and commands separate", () => { + const entries: AgentEntry[] = [ + user("a"), + { type: "thought", text: "inspect" }, + tool("r1", "read"), + tool("s1", "search"), + tool("e1", "edit", 3), + tool("cmd1", "execute"), + tool("f1", "fetch"), + tool("r2", "read"), + agent("done"), + ]; + const rows = conversationRows(entries, 0); + expect(rows.map((row) => row.kind)).toEqual(["entry", "process", "entry", "entry", "process", "entry"]); + expect(rows[1]!.kind === "process" ? rows[1]!.entries.length : 0).toBe(3); + expect(rows[4]!.kind === "process" ? rows[4]!.entries.length : 0).toBe(2); + }); + + it("flattens grouped runs inside a folded turn to avoid nested folds", () => { + const entries: AgentEntry[] = [ + user("a"), + tool("r1", "read"), + tool("r2", "search"), + tool("e1", "edit", 2), + agent("done"), + user("b"), + agent("next"), + ]; + const rows = rowsOf(entries); + const turn = rows[1]!; + expect(turn.kind).toBe("turn"); + if (turn.kind === "turn") { + expect(turn.rows.map((r) => r.kind)).toEqual(["entry", "entry", "entry"]); + } + }); +}); + describe("sameRow", () => { - const entries = [user("a"), tool("t1"), tool("t2"), agent("done"), user("b"), agent("streaming")]; + const entries = [user("a"), tool("t1", "edit"), tool("t2", "edit"), agent("done"), user("b"), agent("streaming")]; it("sees the rows of the same conversation as the same, whichever copy it was built from", () => { const again = rowsOf(entries); @@ -38,20 +76,20 @@ describe("sameRow", () => { }); it("leaves the rows a streamed chunk did not touch the same and the grown one different", () => { - const before = rowsOf(entries, true); - const after = rowsOf([...entries.slice(0, -1), agent("streaming on")], true); + const before = rowsOf(entries); + const after = rowsOf([...entries.slice(0, -1), agent("streaming on")]); expect(after.map((row, i) => sameRow(before[i]!, row))).toEqual([true, true, true, true, false]); }); it("tells a turn whose work changed from one whose work did not", () => { const [, turn] = rowsOf(entries); - const [, edited] = rowsOf([entries[0]!, tool("t1"), tool("t2", 7), ...entries.slice(3)]); + const [, edited] = rowsOf([entries[0]!, tool("t1", "edit"), tool("t2", "edit", 7), ...entries.slice(3)]); expect(sameRow(turn!, edited!)).toBe(false); }); it("tells a run that gained a call from the run before", () => { - const run = conversationRows([user("a"), tool("t1"), tool("t2")], 0)[1]!; - const longer = conversationRows([user("a"), tool("t1"), tool("t2"), tool("t3")], 0)[1]!; + const run = conversationRows([user("a"), tool("t1", "read"), tool("t2", "read")], 0)[1]!; + const longer = conversationRows([user("a"), tool("t1", "read"), tool("t2", "read"), tool("t3", "read")], 0)[1]!; expect(run.kind).toBe("process"); expect(sameRow(run, longer)).toBe(false); }); diff --git a/src/features/agents/session/conversationRows.ts b/src/features/agents/session/conversationRows.ts index fcb4a65b2a..0340b3a1fe 100644 --- a/src/features/agents/session/conversationRows.ts +++ b/src/features/agents/session/conversationRows.ts @@ -20,11 +20,15 @@ export type TurnRow = Extract; export const liveTool = (entry: AgentEntry) => entry.type === "tool" && (entry.status === "running" || entry.status === "pending"); +const EXPLORATION_KINDS = new Set(["read", "search", "fetch", "think"]); + /** - * Reasoning and tool calls fold together, running ones included: the run keeps its place while - * a call finishes, and its summary line says what is running. + * Reasoning and read-only exploration tool calls fold together, running ones included: the run + * keeps its place while a call finishes, and its summary line says what is running. Edits, + * commands and other side-effecting calls stay visible as their own rows. */ -export const isProcessEntry = (entry: AgentEntry) => entry.type === "thought" || entry.type === "tool"; +export const isProcessEntry = (entry: AgentEntry) => + entry.type === "thought" || (entry.type === "tool" && EXPLORATION_KINDS.has(entry.kind) && entry.diffs.length === 0); /** * The conversation's rows from `from`: a run of reasoning and finished tool calls becomes @@ -57,7 +61,11 @@ export function foldTurnRows(rows: ConversationRow[], turns: ReadonlyMap | null = null; for (const row of rows) { if (open && row.index < open.turn.reply) { - open.rows.push(row); + if (row.kind === "process") { + for (const item of row.entries) open.rows.push({ kind: "entry", ...item }); + } else { + open.rows.push(row); + } continue; } open = null; diff --git a/src/features/agents/sessionState.test.tsx b/src/features/agents/sessionState.test.tsx index df043b6734..d0f2c6d06e 100644 --- a/src/features/agents/sessionState.test.tsx +++ b/src/features/agents/sessionState.test.tsx @@ -482,10 +482,13 @@ describe("tool result images", () => { tool("preview", { images: [image] }), tool("inspect", { output: "Preview ready" }), { type: "agent", text: "Here is the result." }, + { type: "user", text: "Thanks", attachments: [], steered: false, sentMs: 3000, doneMs: 4000 }, + { type: "agent", text: "You're welcome." }, ]); useAgents.setState({ entries: new Map(backend.entries) }); render(); await screen.findByText("Here is the result."); + expect(!!stream().querySelector(`.${styles.turnFold}`)).toBe(foldTurns); const preview = screen.getByRole("img", { name: "Image" }); expect(preview).toHaveAttribute("src", "data:image/png;base64,aW1hZ2U="); expect(preview.closest("details")).toBeNull(); @@ -499,7 +502,7 @@ describe("tool result images", () => { }); describe("turn folding", () => { - it("folds a finished turn's work under its message and keeps the reply", async () => { + it("keeps a finished turn's interim text and tools visible by default", async () => { backend.entries.set("A", [ { type: "user", @@ -517,7 +520,43 @@ describe("turn folding", () => { ]); useAgents.setState({ entries: new Map(backend.entries) }); render(); - await screen.findByText("Final reply"); + expect(await screen.findByText("Interim note")).toBeInTheDocument(); + expect(screen.getByText("two")).toBeInTheDocument(); + expect(screen.getByText("Final reply")).toBeInTheDocument(); + expect(stream().querySelector(`.${styles.turnFold}`)).toBeNull(); + }); + + it("folds earlier turns when foldTurns is enabled, keeping the latest turn open and flattening runs inside", async () => { + useProject.setState({ settings: { agents: { foldTurns: true } } as never }); + backend.entries.set("A", [ + { + type: "user", + text: "Question", + attachments: [], + steered: false, + sentMs: 1000, + doneMs: 13000, + }, + { type: "thought", text: "think" }, + tool("one"), + { type: "agent", text: "Interim note" }, + tool("two", { kind: "execute" }), + { type: "agent", text: "Final reply" }, + { + type: "user", + text: "Follow up", + attachments: [], + steered: false, + sentMs: 14000, + doneMs: 15000, + }, + tool("latest", { kind: "execute" }), + { type: "agent", text: "Latest reply" }, + ]); + useAgents.setState({ entries: new Map(backend.entries) }); + render(); + await screen.findByText("Latest reply"); + expect(screen.getByText("latest")).toBeInTheDocument(); const summary = screen.getByText("Ran 1 command · Read 1 file · 1 message"); const fold = summary.closest("details")!; expect(fold).toHaveClass(styles.turnFold!); @@ -526,9 +565,12 @@ describe("turn folding", () => { fold.open = true; fireEvent(fold, new Event("toggle")); expect(await screen.findByText("Interim note")).toBeInTheDocument(); + expect(screen.getByText("one")).toBeInTheDocument(); + expect(fold.querySelector(`.${styles.processRun}`)).toBeNull(); }); it("leaves the turn the agent works on open", async () => { + useProject.setState({ settings: { agents: { foldTurns: true } } as never }); backend.entries.set("A", [ { type: "user", @@ -589,7 +631,7 @@ describe("working status", () => { }); describe("opened runs", () => { - it("stay open when the finished turn folds them away and is opened again", async () => { + it("stay open while the run grows and when the turn finishes", async () => { const asked = { type: "user", text: "Question", @@ -631,9 +673,6 @@ describe("opened runs", () => { ...setTask("ready"), }), ); - const turn = screen.getByText("Read 2 files · 1 message").closest("details")!; - expect(turn).toHaveClass(styles.turnFold!); - toggle(turn); expect(screen.getByText("Read 2 files").closest("details")!.open).toBe(true); }); }); @@ -1256,19 +1295,27 @@ describe("tool calls", () => { expect(screen.queryByText("Reading files…")).toBeNull(); }); - it("folds consecutive finished tool calls into one collapsed row", async () => { + it("folds consecutive exploration calls into one collapsed row while keeping edits visible", async () => { const edit = (id: string) => tool(id, { kind: "edit", diffs: [{ path: "/project/a.ts", added: 2, removed: 1 }], }); - backend.entries.set("A", [edit("one"), edit("two"), { type: "agent", text: "Answer A" }]); + backend.entries.set("A", [ + tool("r1", { kind: "read" }), + tool("s1", { kind: "search" }), + edit("one"), + edit("two"), + { type: "agent", text: "Answer A" }, + ]); useAgents.setState({ entries: new Map(backend.entries) }); render(); - const summary = await screen.findByText("Edited 1 file"); + const summary = await screen.findByText("Read 1 file · Searched once"); expect(summary.closest("details")!.open).toBe(false); - expect(screen.getByText("+4")).toBeInTheDocument(); - expect(screen.getByText("−2")).toBeInTheDocument(); + expect(screen.getByText("one")).toBeInTheDocument(); + expect(screen.getByText("two")).toBeInTheDocument(); + expect(screen.getAllByText("+2")).toHaveLength(2); + expect(screen.getAllByText("−1")).toHaveLength(2); }); }); diff --git a/src/features/agents/timeline.test.ts b/src/features/agents/timeline.test.ts index 13d32ef410..30ea441b30 100644 --- a/src/features/agents/timeline.test.ts +++ b/src/features/agents/timeline.test.ts @@ -48,21 +48,26 @@ describe("summarizeWork", () => { }); describe("foldedTurns", () => { - it("folds a finished turn's work before its reply", () => { + it("folds earlier finished turns' work before their reply and keeps the latest turn open", () => { const entries = [user("q"), tool("read"), agent("mid"), tool("edit"), agent("done"), user("next"), agent("ok")]; - expect([...foldedTurns(entries, 0, false).values()]).toEqual([{ user: 0, reply: 4, sentMs: 1000, doneMs: 5000 }]); + expect([...foldedTurns(entries, 0).values()]).toEqual([{ user: 0, reply: 4, sentMs: 1000, doneMs: 5000 }]); }); - it("leaves the turn in progress, turns without work, and turns ending otherwise open", () => { - const working = [user("q"), tool("read"), agent("a")]; - expect(foldedTurns(working, 0, true).size).toBe(0); - expect(foldedTurns(working, 0, false).size).toBe(1); - expect(foldedTurns([user("q"), agent("a")], 0, false).size).toBe(0); - expect(foldedTurns([user("q"), tool("read")], 0, false).size).toBe(0); - expect(foldedTurns([user("q"), tool("read"), agent("a"), { type: "error", message: "x" }], 0, false).size).toBe(0); - expect(foldedTurns([user("q"), { type: "error", message: "x" }, tool("read"), agent("a")], 0, false).size).toBe(0); - expect(foldedTurns([user("q"), tool("read"), user("more", { steered: true }), agent("a")], 0, false).size).toBe(0); - expect(foldedTurns([user("q"), tool("read"), agent("a")], 1, false).size).toBe(0); + it("leaves the latest turn, turns without work, and turns ending otherwise open", () => { + const latestOnly = [user("q"), tool("read"), agent("a")]; + expect(foldedTurns(latestOnly, 0).size).toBe(0); + expect(foldedTurns([user("q"), agent("a"), user("next")], 0).size).toBe(0); + expect(foldedTurns([user("q"), tool("read"), user("next")], 0).size).toBe(0); + expect( + foldedTurns([user("q"), tool("read"), agent("a"), { type: "error", message: "x" }, user("next")], 0).size, + ).toBe(0); + expect( + foldedTurns([user("q"), { type: "error", message: "x" }, tool("read"), agent("a"), user("next")], 0).size, + ).toBe(0); + expect( + foldedTurns([user("q"), tool("read"), user("more", { steered: true }), agent("a"), user("next")], 0).size, + ).toBe(0); + expect(foldedTurns([user("q"), tool("read"), agent("a"), user("next")], 1).size).toBe(0); }); }); diff --git a/src/features/agents/timeline.ts b/src/features/agents/timeline.ts index 25e6b03337..bf38d07b52 100644 --- a/src/features/agents/timeline.ts +++ b/src/features/agents/timeline.ts @@ -101,13 +101,12 @@ export interface FoldedTurn { } /** - * The finished turns whose work before their last reply folds into one line. A turn - * folds when it has ended, ended with a reply, and did something before that reply (and - * neither the user sent anything into it nor it ran into an error meanwhile); the - * latest turn stays open while the agent works. Turns asked before `from` aren't shown - * and so don't fold. + * The earlier finished turns whose work before their last reply folds into one line. A turn + * folds once a later turn has started, when it ended with a reply and did something before + * that reply (and neither the user sent anything into it nor it ran into an error meanwhile); + * the latest turn always stays open. Turns asked before `from` aren't shown and so don't fold. */ -export function foldedTurns(entries: readonly AgentEntry[], from: number, busy: boolean): Map { +export function foldedTurns(entries: readonly AgentEntry[], from: number): Map { const turns = new Map(); const starts: number[] = []; entries.forEach((e, i) => { @@ -116,7 +115,7 @@ export function foldedTurns(entries: readonly AgentEntry[], from: number, busy: starts.forEach((user, k) => { const end = starts[k + 1] ?? entries.length; const last = k === starts.length - 1; - if (last && busy) return; + if (last) return; const asked = entries[user] as Extract; let reply = -1; for (let i = end - 1; i > user; i--) { diff --git a/src/features/settings/__tests__/agents.test.ts b/src/features/settings/__tests__/agents.test.ts index 0f9c6cb0dc..5c26dcbafe 100644 --- a/src/features/settings/__tests__/agents.test.ts +++ b/src/features/settings/__tests__/agents.test.ts @@ -8,7 +8,7 @@ describe("agent chat settings", () => { showWorkTime: true, showUsageLimits: true, showCost: false, - foldTurns: true, + foldTurns: false, smoothText: true, fitWindowWidth: false, thinking: "auto", diff --git a/src/features/settings/model/schema.ts b/src/features/settings/model/schema.ts index cc00265b90..af7efb44bc 100644 --- a/src/features/settings/model/schema.ts +++ b/src/features/settings/model/schema.ts @@ -240,7 +240,7 @@ export const DEFAULT_SETTINGS: ValidSettings = { showWorkTime: true, showUsageLimits: true, showCost: false, - foldTurns: true, + foldTurns: false, smoothText: true, fitWindowWidth: false, thinking: "auto",