feat(agents): add "Fit conversation to the window width" chat setting (#3455)

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>
This commit is contained in:
Deng Liu
2026-11-15 09:50:13 +08:00
committed by GitHub
co-authored by dengliu
parent 59fba1a65d
commit 8432bf9997
15 changed files with 186 additions and 4 deletions
+7
View File
@@ -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);
}
+91
View File
@@ -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<HTMLElement>("[class*='_conversation_']")!;
const column = root.querySelector<HTMLElement>("[class*='_agentMessage_']")!.getBoundingClientRect();
const bubble = root.querySelector<HTMLElement>("[class*='_user_']")!.getBoundingClientRect();
const composer = conversation.querySelector<HTMLElement>("[class*='_composerArea_']")!.getBoundingClientRect();
const question = conversation.querySelector<HTMLElement>("[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.");
+4
View File
@@ -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. */
+3
View File
@@ -17,6 +17,9 @@
flex-direction: column;
gap: 8px;
}
.fitWidth .inner {
width: 100%;
}
.heading {
margin: 0 0 10px;
font-size: 18px;
+16
View File
@@ -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(<HomeEditor />);
const root = container.querySelector(`.${homeStyles.home}`)!;
expect(root).not.toHaveClass(homeStyles.fitWidth!);
useProject.setState({ settings: { ...settings, agents: { ...settings?.agents, fitWindowWidth: true } } as never });
rerender(<HomeEditor />);
expect(root).toHaveClass(homeStyles.fitWidth!);
} finally {
useProject.setState({ settings });
}
});
+2 -2
View File
@@ -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<HTMLDivElement>(null);
const shown = useEditorShown();
@@ -127,7 +127,7 @@ export function HomeEditor({ docked = false }: { docked?: boolean; input?: Edito
};
return (
<div ref={homeRoot} className={clsx(styles.home, docked && styles.docked)}>
<div ref={homeRoot} className={clsx(styles.home, docked && styles.docked, fitWindowWidth && styles.fitWidth)}>
<div className={styles.inner}>
{!docked && (
<h1 className={styles.heading}>
+13
View File
@@ -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);
+7 -1
View File
@@ -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<HTMLDivElement>(null);
const canFocusInput = shown && !!task && task.status !== "archived" && !view;
const session = useMemo<FocusedSession>(
@@ -236,7 +237,12 @@ function TaskSession({ id, docked }: { id: string; docked: boolean }) {
return (
<div
ref={sessionRoot}
className={clsx(styles.session, docked && styles.docked, changesOpen && !docked && styles.withChanges)}
className={clsx(
styles.session,
docked && styles.docked,
changesOpen && !docked && styles.withChanges,
fitWindowWidth && styles.fitWidth,
)}
style={changesWidth}
onFocusCapture={() => shown && setFocusedSession(session)}
onBlurCapture={(e) => {
+1
View File
@@ -12,6 +12,7 @@ export const AGENT_SETTINGS_DEFAULTS: ResolvedAgentSettings = {
showCost: false,
foldTurns: true,
smoothText: true,
fitWindowWidth: false,
thinking: "auto",
toolCalls: "grouped",
expandToolOutput: false,
+26
View File
@@ -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(<SessionEditor input={input("A")} />);
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([
@@ -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", () => {
+2
View File
@@ -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),
+6
View File
@@ -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",
},
],
},
{
+1
View File
@@ -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",
+1
View File
@@ -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": "登录",