Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai c144dd225a fix(agents): keep the toolbar fitting a narrow window with New Agent Task
Hide the button below 480px and drop its leading margin below 560px. Update the e2e specs that locate the Agents tool window's New Agent Task button and the toolbar layouts.
2026-12-03 23:26:06 +08:00
l0ng-ai 151b88aa89 feat(agents): add a New Agent Task button to the main toolbar
The main toolbar shows New Agent Task by default, with the selected agent's
icon. Its ▾ lists the installed agents to start a task with another one, and
More Agents…. It can be removed in Customize Main Toolbar.

Closes #4000
2026-12-03 23:26:05 +08:00
10 змінених файлів з 185 додано та 7 видалено

No files matched your search

+1 -1
Переглянути файл
@@ -169,7 +169,7 @@ test("short prompts fit before and after a completed agent exchange", async ({ w
await expect.poll(overflow).toEqual({ x: 0, y: 0 });
await page.getByRole("button", { name: "Agents", exact: true }).click();
await page.getByRole("button", { name: "New Agent Task", exact: true }).click();
await page.getByLabel("New Agent Task", { exact: true }).click();
await expect(box.locator(".cm-placeholder")).toBeVisible();
await expect(scroller).toHaveCSS("overflow-x", "hidden");
await expect.poll(overflow).toEqual({ x: 0, y: 0 });
+2 -2
Переглянути файл
@@ -52,7 +52,7 @@ test.beforeEach(async ({ workbench: page }) => {
});
});
await page.getByRole("button", { name: "Agents", exact: true }).click();
await page.getByRole("button", { name: "New Agent Task", exact: true }).click();
await page.getByLabel("New Agent Task", { exact: true }).click();
await expectVersion(page, "18.20.0");
});
@@ -71,7 +71,7 @@ test("refreshes an upgraded agent's version on window focus without losing the d
test("refreshes an upgraded agent's version when New Task is reopened", async ({ workbench: page }) => {
await page.getByRole("button", { name: "Close Tab", exact: true }).click();
await page.evaluate(() => window.dispatchEvent(new Event("test:agent-upgraded")));
await page.getByRole("button", { name: "New Agent Task", exact: true }).click();
await page.getByLabel("New Agent Task", { exact: true }).click();
await expectVersion(page, "18.20.2");
});
+1 -1
Переглянути файл
@@ -53,7 +53,7 @@ test("the main toolbar compresses long labels before a short branch name", async
await page.setViewportSize({ width: 1150, height: 620 });
const expanded = await Promise.all(labels.map(width));
await page.setViewportSize({ width: 690, height: 620 });
await page.setViewportSize({ width: 820, height: 620 });
// The label cap is applied in a ResizeObserver's animation frame, so wait until both long labels shrank.
await expect
.poll(async () => (await Promise.all([width(project), width(run)])).every((w) => w.shown < w.preferred))
+18 -3
Переглянути файл
@@ -84,7 +84,12 @@ test("the Center group is centred in the main toolbar", async ({ workbench: page
...settings,
appearance: {
...settings?.appearance,
mainToolbar: { left: [], center: ["project"], right: ["action:navigate.searchEverywhere"], hidden: [] },
mainToolbar: {
left: [],
center: ["project"],
right: ["action:navigate.searchEverywhere"],
hidden: ["agents.newTask"],
},
},
},
});
@@ -120,7 +125,12 @@ test("the project colour gradient follows the Project widget", async ({ workbenc
const settings = useProject.getState().settings;
useProject.setState({ settings: { ...settings, appearance: { ...settings?.appearance, mainToolbar } } });
}, mainToolbar);
await layout({ left: [], center: ["project"], right: ["action:navigate.searchEverywhere"], hidden: [] });
await layout({
left: [],
center: ["project"],
right: ["action:navigate.searchEverywhere"],
hidden: ["agents.newTask"],
});
for (const width of [1400, 900]) {
await page.setViewportSize({ width, height: 700 });
await expect(async () => {
@@ -132,7 +142,12 @@ test("the project colour gradient follows the Project widget", async ({ workbenc
await page.screenshot({ path: "test-results/project-gradient-center.png", animations: "disabled" });
// Without the widget the gradient goes back to the frame's corner.
await layout({ left: [], center: [], right: ["action:navigate.searchEverywhere"], hidden: ["project"] });
await layout({
left: [],
center: [],
right: ["action:navigate.searchEverywhere"],
hidden: ["project", "agents.newTask"],
});
await expect(icon).toHaveCount(0);
await expect.poll(anchor).toBe("");
});
+45
Переглянути файл
@@ -0,0 +1,45 @@
.root {
display: flex;
align-items: center;
min-width: 0;
gap: var(--space-0-5);
margin-inline-start: var(--space-3);
}
/* Splits the button from its ▾, as the toolbar's split buttons do. */
.root::after {
content: "";
order: 1;
flex: none;
width: 1px;
height: var(--space-4);
background: var(--border-strong);
}
.main {
min-width: 0;
margin: 0;
gap: var(--space-1-5);
font-size: var(--fs-chrome);
}
.label {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
.chevron {
order: 2;
width: var(--space-4);
height: var(--h-toolbar-widget);
border-radius: var(--radius-toolbar-button);
color: var(--fg-muted);
}
/* A narrow window keeps the toolbar's existing widgets; New Agent Task stays on ⇧⌘I and the Agents tool window. */
@media (max-width: 560px) {
.root {
margin-inline-start: 0;
}
}
@media (max-width: 480px) {
.root {
display: none;
}
}
+40
Переглянути файл
@@ -0,0 +1,40 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import type { AgentProvider } from "@/bindings";
import { registerActions } from "@/platform/actions";
import { NewTaskTitleItem } from "./NewTaskTitleItem";
import { useAgents } from "./store";
const store = vi.hoisted(() => ({ openHome: vi.fn() }));
vi.mock("./store", async (original) => ({
...(await original<typeof import("./store")>()),
openHome: store.openHome,
}));
const provider = (id: string, name: string, installed = true) => ({ id, name, installed }) as AgentProvider;
describe("NewTaskTitleItem", () => {
afterEach(() => vi.clearAllMocks());
it("starts a task with the selected agent, or picks another one from the menu", () => {
const newTask = vi.fn();
const dispose = registerActions([{ id: "agents.newTask", title: "New Agent Task", run: newTask }]);
useAgents.setState((s) => ({
providers: [provider("claude", "Claude Code"), provider("codex", "Codex"), provider("gemini", "Gemini", false)],
draft: { ...s.draft, provider: "claude" },
}));
render(<NewTaskTitleItem />);
const main = screen.getByRole("button", { name: "New Agent Task" });
expect(main).toHaveAttribute("data-tooltip", "New Agent Task with Claude Code");
fireEvent.click(main);
expect(newTask).toHaveBeenCalledOnce();
fireEvent.click(screen.getByRole("button", { name: "Choose Agent" }));
expect(screen.queryByText("Gemini")).toBeNull();
fireEvent.click(screen.getByText("Codex"));
expect(useAgents.getState().draft.provider).toBe("codex");
expect(store.openHome).toHaveBeenCalledOnce();
dispose();
});
});
+65
Переглянути файл
@@ -0,0 +1,65 @@
import { useRef, useState } from "react";
import { BarButton, Icon, IconButton, Menu, type MenuItem } from "@/ui";
import { executeAction } from "@/platform/actions";
import { useTx } from "@/platform/i18n";
import { shortcutLabel } from "@/platform/keymap";
import { useChromeIconSize } from "@/ui/density";
import { providerIcon } from "./model";
import { openHome, updateDraft, useAgents } from "./store";
import styles from "./NewTaskTitleItem.module.css";
/** Main toolbar: New Agent Task with the selected agent, and ▾ to start one with another agent. */
export function NewTaskTitleItem() {
const tx = useTx();
const iconSize = useChromeIconSize();
const providers = useAgents((s) => s.providers);
const selectedId = useAgents((s) => s.draft.provider);
const [open, setOpen] = useState(false);
const chevron = useRef<HTMLButtonElement>(null);
const installed = providers.filter((p) => p.installed);
const selected = providers.find((p) => p.id === selectedId) ?? providers[0];
const items: MenuItem[] = [
...installed.map((p) => ({
id: p.id,
label: p.name,
verbatim: true,
icon: providerIcon(p.id),
checked: p.id === selected?.id,
run: () => {
if (p.id !== selected?.id) updateDraft({ provider: p.id, config: {} });
openHome();
},
})),
...(installed.length ? [{ kind: "separator" } as const] : []),
{ kind: "action", action: "agents.addAgent" },
];
return (
<div className={styles.root}>
<BarButton
variant="title"
className={styles.main}
tooltip={selected ? tx`New Agent Task with ${selected.name}` : tx("New Agent Task")}
shortcut={shortcutLabel("agents.newTask")}
onClick={() => void executeAction("agents.newTask")}
>
<Icon name={selected ? providerIcon(selected.id) : "toolwindow-agents"} size={iconSize} />
<span className={styles.label} data-toolbar-label="">
{tx("New Agent Task")}
</span>
</BarButton>
<IconButton
ref={chevron}
icon="chevron-down"
iconSize={12}
className={styles.chevron}
title="Choose Agent"
aria-haspopup="menu"
aria-expanded={open}
onClick={() => setOpen((v) => !v)}
/>
<Menu open={open} onClose={() => setOpen(false)} anchor={chevron} items={items} aria-label="Choose Agent" />
</div>
);
}
+9
Переглянути файл
@@ -23,10 +23,12 @@ import {
registerOverlay,
registerRunningAgentTasksProvider,
registerStatusItem,
registerTitleItem,
registerToolWindow,
toolWindowService,
} from "@/workbench/contributions";
import { AgentsStatus } from "./AgentsStatus";
import { NewTaskTitleItem } from "./NewTaskTitleItem";
import { activateSettingsPages } from "./settingsPages";
import {
AUTOMATIONS_KIND,
@@ -265,6 +267,13 @@ export function activate(): () => void {
icon: "toolwindow-agents",
when: "projectOpen && vcsAvailable && commitAgentButton",
}),
registerTitleItem({
id: "agents.newTask",
title: "New Agent Task",
align: "right",
priority: 10,
component: NewTaskTitleItem,
}),
registerStatusItem({ id: "agents.status", align: "right", priority: 3, title: "Agents", component: AgentsStatus }),
registerMenuGroup({
id: "agents.send",
+2
Переглянути файл
@@ -2547,6 +2547,8 @@
"too old, needs JDK {version}+ · {path}": "too old, needs JDK {version}+ · {path}",
"Close Agent Task": "Close Agent Task",
"Close and New Agent Task": "Close and New Agent Task",
"New Agent Task with {name}": "New Agent Task with {name}",
"Choose Agent": "Choose Agent",
"Focus Agent Input": "Focus Agent Input",
"Focuses the message input of the current agent task, or of the one on screen when focus is elsewhere and no panel claims the shortcut, without moving the caret.": "Focuses the message input of the current agent task, or of the one on screen when focus is elsewhere and no panel claims the shortcut, without moving the caret.",
"Cycle Agent Effort": "Cycle Agent Effort",
+2
Переглянути файл
@@ -5267,6 +5267,8 @@
"New Agent Task": "新建 Agent 任务",
"Close Agent Task": "关闭 Agent 任务",
"Close and New Agent Task": "关闭并新建 Agent 任务",
"New Agent Task with {name}": "使用 {name} 新建 Agent 任务",
"Choose Agent": "选择 Agent",
"Focus Agent Input": "聚焦 Agent 输入框",
"Focuses the message input of the current agent task, or of the one on screen when focus is elsewhere and no panel claims the shortcut, without moving the caret.": "聚焦当前 Agent 任务的消息输入框;焦点在其他位置且没有面板占用该快捷键时,聚焦屏幕上显示的任务的输入框。不移动光标。",
"Cycle Agent Effort": "循环切换 Agent 思考强度",