From 8432bf9997ea906e4766ea7b59e58246e324ba95 Mon Sep 17 00:00:00 2001 From: Deng Liu Date: Sat, 14 Nov 2026 17:50:13 -0800 Subject: [PATCH] feat(agents): add "Fit conversation to the window width" chat setting (#3455) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings › Agents › Chat › Conversation gets an opt-in toggle (agents.fitWindowWidth, off by default). When on, the conversation stream, composer, question card, user message bubbles and the New Task page drop their max-width caps and follow the pane width; when off, the readable 900 px column stays. Co-authored-by: dengliu <5108773+dengliu@users.noreply.github.com> --- crates/ide-core/src/settings.rs | 7 ++ e2e/agentMarkdown.spec.ts | 91 +++++++++++++++++++ src/bindings.ts | 4 + src/features/agents/Home.module.css | 3 + src/features/agents/HomeEditor.test.tsx | 16 ++++ src/features/agents/HomeEditor.tsx | 4 +- src/features/agents/Session.module.css | 13 +++ src/features/agents/SessionEditor.tsx | 8 +- src/features/agents/agentSettings.ts | 1 + src/features/agents/sessionState.test.tsx | 26 ++++++ .../settings/__tests__/agents.test.ts | 7 +- src/features/settings/model/schema.ts | 2 + src/features/settings/pages/tools.tsx | 6 ++ src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + 15 files changed, 186 insertions(+), 4 deletions(-) diff --git a/crates/ide-core/src/settings.rs b/crates/ide-core/src/settings.rs index 5912c8894..e9855f598 100644 --- a/crates/ide-core/src/settings.rs +++ b/crates/ide-core/src/settings.rs @@ -86,6 +86,8 @@ pub struct AgentSettings { pub fold_turns: bool, /// Streaming text is revealed at a steady pace rather than chunk by chunk. pub smooth_text: bool, + /// Conversations and the composer expand to the full width of the pane instead of staying in a centred column. + pub fit_window_width: bool, #[serde(deserialize_with = "or_default")] #[specta(type = ThinkingDisplay)] pub thinking: ThinkingDisplay, @@ -127,6 +129,7 @@ impl Default for AgentSettings { show_cost: false, fold_turns: true, smooth_text: true, + fit_window_width: false, thinking: ThinkingDisplay::Auto, tool_calls: ToolCallDisplay::Grouped, expand_tool_output: false, @@ -1715,11 +1718,15 @@ mod tests { let old: Settings = serde_json::from_str(r#"{"agents":{"showCost":true}}"#).unwrap(); 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!(!Settings::default().agents.show_cost); + assert!(!Settings::default().agents.fit_window_width); let mut settings = Settings::default(); settings.agents.show_usage_limits = false; + settings.agents.fit_window_width = true; let json = serde_json::to_value(&settings).unwrap(); assert_eq!(json["agents"]["showUsageLimits"], false); + assert_eq!(json["agents"]["fitWindowWidth"], true); let restored: Settings = serde_json::from_value(json).unwrap(); assert_eq!(restored.agents, settings.agents); } diff --git a/e2e/agentMarkdown.spec.ts b/e2e/agentMarkdown.spec.ts index 5a4505096..16f9f3bc4 100644 --- a/e2e/agentMarkdown.spec.ts +++ b/e2e/agentMarkdown.spec.ts @@ -372,6 +372,97 @@ test("keeps chat history readable and selections free of timestamps and status l expect(narrow.reply).toBeLessThanOrEqual((narrow.width - narrow.padding) * 0.96); }); +test("fits conversation stream, composer, question card and user bubbles to window width when enabled", async ({ + page, +}) => { + await page.setViewportSize({ width: 1800, height: 1000 }); + await openReply(page, "Initial reply"); + await page.evaluate(async (task) => { + const storePath = "/src/features/agents/store.ts"; + const store = await import(storePath); + store.useAgents.setState({ + tasks: new Map([[task.id, { ...task, status: "needsInput" as const }]]), + entries: new Map([ + [ + task.id, + [ + { + type: "user", + text: "Long prompt ".repeat(40), + attachments: [], + sentMs: 1, + doneMs: 2, + steered: false, + }, + { type: "agent", text: "Wide reply body." }, + { + type: "permission", + id: 1, + title: "Choose layout", + options: [], + chosen: null, + questions: [ + { + header: "Width", + question: "Use full window width?", + multiSelect: false, + options: [{ label: "Yes", description: "Fill the pane", preview: null }], + }, + ], + }, + ], + ], + ]), + }); + store.openTaskInEditorLocation(task.id); + }, TASK); + + const stream = page.locator("[class*='_stream_']:visible"); + await expect(page.getByRole("form", { name: "Choose layout" })).toBeVisible(); + + const measure = () => + stream.evaluate((root) => { + const conversation = root.closest("[class*='_conversation_']")!; + const column = root.querySelector("[class*='_agentMessage_']")!.getBoundingClientRect(); + const bubble = root.querySelector("[class*='_user_']")!.getBoundingClientRect(); + const composer = conversation.querySelector("[class*='_composerArea_']")!.getBoundingClientRect(); + const question = conversation.querySelector("[class*='_questionCard_']")!.getBoundingClientRect(); + const padding = + Number.parseFloat(getComputedStyle(root).paddingLeft) + Number.parseFloat(getComputedStyle(root).paddingRight); + return { + conversationWidth: conversation.clientWidth, + streamInnerWidth: root.clientWidth - padding, + columnWidth: column.width, + bubbleWidth: bubble.width, + composerWidth: composer.width, + questionWidth: question.width, + }; + }); + + const capped = await measure(); + expect(capped.conversationWidth).toBeGreaterThan(1000); + expect(Math.abs(capped.columnWidth - 900)).toBeLessThan(1); + expect(Math.abs(capped.bubbleWidth - 720)).toBeLessThan(1); + expect(Math.abs(capped.composerWidth - 924)).toBeLessThan(1); + expect(Math.abs(capped.questionWidth - 900)).toBeLessThan(1); + + await page.evaluate(async () => { + const projectPath = "/src/platform/project.ts"; + const { useProject } = await import(projectPath); + const settings = useProject.getState().settings; + useProject.setState({ + settings: { ...settings, agents: { ...settings?.agents, fitWindowWidth: true } } as never, + }); + }); + + const fitted = await measure(); + expect(Math.abs(fitted.columnWidth - fitted.streamInnerWidth)).toBeLessThan(1); + expect(fitted.bubbleWidth).toBeGreaterThan(720); + expect(Math.abs(fitted.bubbleWidth - fitted.streamInnerWidth * 0.8)).toBeLessThan(1); + expect(Math.abs(fitted.composerWidth - fitted.conversationWidth)).toBeLessThan(1); + expect(Math.abs(fitted.questionWidth - fitted.streamInnerWidth)).toBeLessThan(1); +}); + test("keeps hover actions reachable when the pointer leaves the message body", async ({ page, context }) => { await context.grantPermissions(["clipboard-read", "clipboard-write"]); const reply = await openReply(page, "A short answer."); diff --git a/src/bindings.ts b/src/bindings.ts index c1bb8acae..11cef2445 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -2253,6 +2253,8 @@ export type AgentSettings_Deserialize = { foldTurns?: boolean, /** Streaming text is revealed at a steady pace rather than chunk by chunk. */ smoothText?: boolean, + /** Conversations and the composer expand to the full width of the pane instead of staying in a centred column. */ + fitWindowWidth?: boolean, thinking?: ThinkingDisplay, toolCalls?: ToolCallDisplay, /** A tool call's output (a command's, a diff) is shown without opening it. */ @@ -2291,6 +2293,8 @@ export type AgentSettings_Serialize = { foldTurns: boolean, /** Streaming text is revealed at a steady pace rather than chunk by chunk. */ smoothText: boolean, + /** Conversations and the composer expand to the full width of the pane instead of staying in a centred column. */ + fitWindowWidth: boolean, thinking: ThinkingDisplay, toolCalls: ToolCallDisplay, /** A tool call's output (a command's, a diff) is shown without opening it. */ diff --git a/src/features/agents/Home.module.css b/src/features/agents/Home.module.css index 0a096f71a..bb3598b4e 100644 --- a/src/features/agents/Home.module.css +++ b/src/features/agents/Home.module.css @@ -17,6 +17,9 @@ flex-direction: column; gap: 8px; } +.fitWidth .inner { + width: 100%; +} .heading { margin: 0 0 10px; font-size: 18px; diff --git a/src/features/agents/HomeEditor.test.tsx b/src/features/agents/HomeEditor.test.tsx index f870d60e0..0d676c46a 100644 --- a/src/features/agents/HomeEditor.test.tsx +++ b/src/features/agents/HomeEditor.test.tsx @@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import type { AgentConfigOption, AgentProvider, NewAgentTask } from "@/bindings"; import { useProject } from "@/platform/project"; import { HomeEditor } from "./HomeEditor"; +import homeStyles from "./Home.module.css"; import { HOME, disconnect, savedDraft, updateComposer, useAgents } from "./store"; const backend = vi.hoisted(() => ({ providers: [] as AgentProvider[], create: vi.fn() })); @@ -150,3 +151,18 @@ it.each([ useProject.setState({ settings }); } }); + +it("applies fitWidth on the New Task page only when fitWindowWidth is enabled", () => { + const settings = useProject.getState().settings; + try { + useProject.setState({ settings: { ...settings, agents: { ...settings?.agents, fitWindowWidth: false } } as never }); + const { container, rerender } = render(); + const root = container.querySelector(`.${homeStyles.home}`)!; + expect(root).not.toHaveClass(homeStyles.fitWidth!); + useProject.setState({ settings: { ...settings, agents: { ...settings?.agents, fitWindowWidth: true } } as never }); + rerender(); + expect(root).toHaveClass(homeStyles.fitWidth!); + } finally { + useProject.setState({ settings }); + } +}); diff --git a/src/features/agents/HomeEditor.tsx b/src/features/agents/HomeEditor.tsx index 142be3994..c9041487b 100644 --- a/src/features/agents/HomeEditor.tsx +++ b/src/features/agents/HomeEditor.tsx @@ -93,7 +93,7 @@ export function HomeEditor({ docked = false }: { docked?: boolean; input?: Edito window.addEventListener("focus", refresh); return () => window.removeEventListener("focus", refresh); }, [provider?.id, provider?.installed, launch, project?.root]); - const defaults = useAgentSettings().defaults; + const { defaults, fitWindowWidth } = useAgentSettings(); const config = draftConfig(provider, draft, (provider && defaults[provider.id]) || {}); const homeRoot = useRef(null); const shown = useEditorShown(); @@ -127,7 +127,7 @@ export function HomeEditor({ docked = false }: { docked?: boolean; input?: Edito }; return ( -
+
{!docked && (

diff --git a/src/features/agents/Session.module.css b/src/features/agents/Session.module.css index 11f93054d..d8b77c0ba 100644 --- a/src/features/agents/Session.module.css +++ b/src/features/agents/Session.module.css @@ -66,6 +66,19 @@ .withChanges { grid-template-columns: minmax(min(240px, 50%), 1fr) minmax(0, var(--agent-changes-width, 280px)); } +.fitWidth .stream > * { + width: 100%; +} +.fitWidth .userMessage > .user { + max-width: var(--session-card-width); +} +.fitWidth .composerArea { + max-width: none; +} +.fitWidth .questionCard { + width: calc(100% - var(--space-3) * 2); + max-width: none; +} .providerIcon { color: var(--fg-muted); diff --git a/src/features/agents/SessionEditor.tsx b/src/features/agents/SessionEditor.tsx index 33e319113..4095417ac 100644 --- a/src/features/agents/SessionEditor.tsx +++ b/src/features/agents/SessionEditor.tsx @@ -209,6 +209,7 @@ function TaskSession({ id, docked }: { id: string; docked: boolean }) { const [finding, setFinding] = useState(false); const [findFocus, setFindFocus] = useState(0); const [inputFocus, setInputFocus] = useState(0); + const { fitWindowWidth } = useAgentSettings(); const sessionRoot = useRef(null); const canFocusInput = shown && !!task && task.status !== "archived" && !view; const session = useMemo( @@ -236,7 +237,12 @@ function TaskSession({ id, docked }: { id: string; docked: boolean }) { return (
shown && setFocusedSession(session)} onBlurCapture={(e) => { diff --git a/src/features/agents/agentSettings.ts b/src/features/agents/agentSettings.ts index 3ef579557..c71fd0d16 100644 --- a/src/features/agents/agentSettings.ts +++ b/src/features/agents/agentSettings.ts @@ -12,6 +12,7 @@ export const AGENT_SETTINGS_DEFAULTS: ResolvedAgentSettings = { showCost: false, foldTurns: true, smoothText: true, + fitWindowWidth: false, thinking: "auto", toolCalls: "grouped", expandToolOutput: false, diff --git a/src/features/agents/sessionState.test.tsx b/src/features/agents/sessionState.test.tsx index cf3e2a26c..bded8d0cf 100644 --- a/src/features/agents/sessionState.test.tsx +++ b/src/features/agents/sessionState.test.tsx @@ -1817,6 +1817,32 @@ describe("meters in the task header", () => { expect(screen.getByText("$0.42")).toBeInTheDocument(); }); + it("toggles fitWidth on the session root from settings.agents.fitWindowWidth", () => { + const { container } = render(); + const root = container.querySelector(`.${styles.session}`)!; + expect(root).not.toHaveClass(styles.fitWidth!); + act(() => + useProject.setState({ + settings: { + agents: { + fitWindowWidth: true, + }, + } as never, + }), + ); + expect(root).toHaveClass(styles.fitWidth!); + act(() => + useProject.setState({ + settings: { + agents: { + fitWindowWidth: false, + }, + } as never, + }), + ); + expect(root).not.toHaveClass(styles.fitWidth!); + }); + it("hides the status-bar Terminal button in the local checkout and opens the worktree's terminal otherwise", async () => { const opened: unknown[] = []; const disposeTerminal = registerActions([ diff --git a/src/features/settings/__tests__/agents.test.ts b/src/features/settings/__tests__/agents.test.ts index 482eb2f0f..a7de5649c 100644 --- a/src/features/settings/__tests__/agents.test.ts +++ b/src/features/settings/__tests__/agents.test.ts @@ -10,6 +10,7 @@ describe("agent chat settings", () => { showCost: false, foldTurns: true, smoothText: true, + fitWindowWidth: false, thinking: "auto", toolCalls: "grouped", expandToolOutput: false, @@ -19,13 +20,17 @@ describe("agent chat settings", () => { defaults: {}, mcpServers: {}, }); - const stored = validateSettings({ agents: { showUsageLimits: false, showCost: true, showWorkTime: "no" } }).agents; + const stored = validateSettings({ + agents: { showUsageLimits: false, showCost: true, showWorkTime: "no", fitWindowWidth: true }, + }).agents; expect(stored).toMatchObject({ showContextUsage: true, showWorkTime: true, showUsageLimits: false, showCost: true, + fitWindowWidth: true, }); + expect(validateSettings({ agents: { fitWindowWidth: "yes" } }).agents.fitWindowWidth).toBe(false); }); it("keeps valid chat choices and per-agent defaults", () => { diff --git a/src/features/settings/model/schema.ts b/src/features/settings/model/schema.ts index a19046e9b..1c8a119a3 100644 --- a/src/features/settings/model/schema.ts +++ b/src/features/settings/model/schema.ts @@ -212,6 +212,7 @@ export const DEFAULT_SETTINGS: ValidSettings = { showCost: false, foldTurns: true, smoothText: true, + fitWindowWidth: false, thinking: "auto", toolCalls: "grouped", expandToolOutput: false, @@ -391,6 +392,7 @@ export function validateSettings(raw: Settings | unknown): ValidSettings { showCost: bool(agents.showCost, d.agents.showCost), foldTurns: bool(agents.foldTurns, d.agents.foldTurns), smoothText: bool(agents.smoothText, d.agents.smoothText), + fitWindowWidth: bool(agents.fitWindowWidth, d.agents.fitWindowWidth), thinking: oneOf(agents.thinking, ["auto", "expanded", "collapsed"] as const, d.agents.thinking), toolCalls: oneOf(agents.toolCalls, ["grouped", "each"] as const, d.agents.toolCalls), expandToolOutput: bool(agents.expandToolOutput, d.agents.expandToolOutput), diff --git a/src/features/settings/pages/tools.tsx b/src/features/settings/pages/tools.tsx index 025ebe0fb..d03212d08 100644 --- a/src/features/settings/pages/tools.tsx +++ b/src/features/settings/pages/tools.tsx @@ -672,6 +672,7 @@ export const TOOLS_PAGES: PageSpec[] = [ "approval", "permission", "bypass", + "width", ], sections: [ { @@ -727,6 +728,11 @@ export const TOOLS_PAGES: PageSpec[] = [ label: "Reveal streaming text smoothly", hint: "Text appears at a steady pace instead of in bursts", }, + { + kind: "toggle", + key: "agents.fitWindowWidth", + label: "Fit conversation to the window width", + }, ], }, { diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 516c7dd09..73ef7cbb3 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1160,6 +1160,7 @@ "Show tool output without opening it": "Show tool output without opening it", "Reveal streaming text smoothly": "Reveal streaming text smoothly", "Text appears at a steady pace instead of in bursts": "Text appears at a steady pace instead of in bursts", + "Fit conversation to the window width": "Fit conversation to the window width", "⌘Enter": "⌘Enter", "No checksum provided: the download can't be verified.": "No checksum provided: the download can't be verified.", "Sign In": "Sign In", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index b6c1f54ea..3d6066ced 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -7530,6 +7530,7 @@ "Show tool output without opening it": "默认展开工具输出", "Reveal streaming text smoothly": "平滑显示生成中的文字", "Text appears at a steady pace instead of in bursts": "文字匀速出现,而不是一段一段地跳出", + "Fit conversation to the window width": "对话适应窗口宽度", "⌘Enter": "⌘Enter", "No checksum provided: the download can't be verified.": "未提供校验和:无法校验下载的文件。", "Sign In": "登录",