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
+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",
},
],
},
{