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
Цей коміт міститься в:
l0ng-ai committed 2026-12-03 23:26:05 +08:00
1 джерело 437008c517
коміт 151b88aa89
6 files changed
+152

No files matched your search

+34
Переглянути файл
@@ -0,0 +1,34 @@
.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);
}
+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 思考强度",