diff --git a/src/features/agents/NewTaskTitleItem.module.css b/src/features/agents/NewTaskTitleItem.module.css new file mode 100644 index 0000000000..3ac9be2dcc --- /dev/null +++ b/src/features/agents/NewTaskTitleItem.module.css @@ -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); +} diff --git a/src/features/agents/NewTaskTitleItem.test.tsx b/src/features/agents/NewTaskTitleItem.test.tsx new file mode 100644 index 0000000000..eec132e57d --- /dev/null +++ b/src/features/agents/NewTaskTitleItem.test.tsx @@ -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()), + 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(); + + 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(); + }); +}); diff --git a/src/features/agents/NewTaskTitleItem.tsx b/src/features/agents/NewTaskTitleItem.tsx new file mode 100644 index 0000000000..5a6c9387c5 --- /dev/null +++ b/src/features/agents/NewTaskTitleItem.tsx @@ -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(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 ( +
+ void executeAction("agents.newTask")} + > + + + {tx("New Agent Task")} + + + setOpen((v) => !v)} + /> + setOpen(false)} anchor={chevron} items={items} aria-label="Choose Agent" /> +
+ ); +} diff --git a/src/features/agents/index.ts b/src/features/agents/index.ts index 334f6ab266..3118ead0ee 100644 --- a/src/features/agents/index.ts +++ b/src/features/agents/index.ts @@ -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", diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 36ff907038..5e240adf53 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -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", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 8d00925861..cd39d467c9 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -5253,6 +5253,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 思考强度",