From 4466a059b3af18bba3058fc0f8df996abdc7b6a3 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 2 Dec 2026 21:35:18 +0800 Subject: [PATCH] fix(agents): replace send with stop and simplify header (#7526) While a session is running and there is nothing to send, the Send/Queue button becomes Stop; with a draft, Queue stays and Stop moves into the message actions menu. The Automations clock leaves the Agents header (Automations stays in the Options menu), and the gear opens Agent Settings instead of MCP Connections. --- e2e/agentAutomations.spec.ts | 44 ++++++++++++++++++- src/features/agents/AgentsView.test.tsx | 17 ++++++- src/features/agents/AgentsView.tsx | 10 +---- src/features/agents/Automations.module.css | 17 ------- src/features/agents/SubmitButton.tsx | 4 +- src/features/agents/messageEditing.test.tsx | 33 +++++++++++--- .../agents/session/SessionComposer.tsx | 43 +++++++++++++----- src/platform/locales/text/en.json | 2 + src/platform/locales/text/zh.json | 2 + 9 files changed, 125 insertions(+), 47 deletions(-) diff --git a/e2e/agentAutomations.spec.ts b/e2e/agentAutomations.spec.ts index ef50f0b1d2..251f378e31 100644 --- a/e2e/agentAutomations.spec.ts +++ b/e2e/agentAutomations.spec.ts @@ -442,13 +442,17 @@ test("creates, validates cron, runs, inspects provenance, exports/imports .autom await page.setViewportSize({ width: 1320, height: 860 }); await installAutomationDesktopHarness(page); - // Open Agents tool window and click the Automations header button + // Open Agents tool window and use the existing Automations options entry await page.evaluate(async () => { const actionsModule = "/src/platform/actions.ts"; const { executeAction } = await import(/* @vite-ignore */ actionsModule); await executeAction("agents.showToolWindow"); }); - await page.getByRole("button", { name: "Agent Automations" }).click(); + const header = page.locator('[data-toolwindow="agents"] header'); + await expect(header.getByRole("button", { name: "Agent Automations", exact: true })).toHaveCount(0); + await expect(header.getByRole("button", { name: "Agent Settings", exact: true })).toBeVisible(); + await header.getByRole("button", { name: "Options", exact: true }).click(); + await page.getByRole("menuitem", { name: "Automations…", exact: true }).click(); const editor = page.getByTestId("automations-editor"); await expect(editor).toBeVisible(); @@ -614,6 +618,42 @@ test("supports SameTask rolling continuity, NeedsInput approval flow, and sideba await expect(taskTree).not.toContainText("Quiet Clean Sweep (#1)"); }); +test("running composer replaces Send with Stop and keeps the Agents header focused", async ({ + workbench: page, +}, testInfo) => { + await page.setViewportSize({ width: 1280, height: 840 }); + await installAutomationDesktopHarness(page); + await page.evaluate(async () => { + const storeModule = "/src/features/agents/store.ts"; + const actionsModule = "/src/platform/actions.ts"; + const { executeAction } = await import(/* @vite-ignore */ actionsModule); + const store = await import(/* @vite-ignore */ storeModule); + await executeAction("agents.showToolWindow"); + const task = store.useAgents.getState().tasks.get("manual-session-1"); + store.useAgents.setState((s: { tasks: Map }) => ({ + tasks: new Map(s.tasks).set(task.id, { ...task, status: "running" }), + })); + store.openTask(task.id); + }); + await expect(page.getByRole("button", { name: "Agent Settings", exact: true })).toBeVisible(); + await expect(page.getByRole("button", { name: "Agent Automations", exact: true })).toHaveCount(0); + const stop = page.getByRole("button", { name: "Stop", exact: true }); + await expect(stop).toBeEnabled(); + await expect(page.getByRole("button", { name: "Queue", exact: true })).toHaveCount(0); + await page.locator('[data-toolwindow="agents"] header').hover(); + await page.screenshot({ path: testInfo.outputPath("running-composer.png"), animations: "disabled" }); + const before = (await stop.boundingBox())!; + await page.getByRole("textbox", { name: "Message" }).fill("Follow up"); + const queue = page.getByRole("button", { name: "Queue", exact: true }); + await expect(queue).toBeEnabled(); + await expect(stop).toHaveCount(0); + const after = (await queue.boundingBox())!; + expect(after.x).toBeCloseTo(before.x, 0); + expect(after.width).toBeCloseTo(before.width, 0); + await page.getByRole("button", { name: "Message Actions" }).click(); + await expect(page.getByRole("menuitem", { name: "Stop", exact: true })).toBeVisible(); +}); + test("schedules in-session Send Later, /loop recurring prompts, and /automate from SessionComposer", async ({ workbench: page, }) => { diff --git a/src/features/agents/AgentsView.test.tsx b/src/features/agents/AgentsView.test.tsx index e0cf663e27..0e2779f721 100644 --- a/src/features/agents/AgentsView.test.tsx +++ b/src/features/agents/AgentsView.test.tsx @@ -8,7 +8,7 @@ import { confirm, confirmChecked, showError } from "@/workbench/messages"; import { promptInput } from "@/workbench/inputDialogs"; import { ContextMenuHost, dragSession, hideContextMenu } from "@/ui"; import { AgentsHeaderActions, AgentsView } from "./AgentsView"; -import { GROUP_DRAG, SESSION_KIND, TASK_DRAG } from "./model"; +import { GROUP_DRAG, REGISTRY_PAGE, SESSION_KIND, TASK_DRAG } from "./model"; import { usePlatform } from "@/platform/platformInfo"; import { archiveTask, unarchiveTask, deleteTask, dockTask, openTask, useAgents } from "./store"; import { taskActions, taskMenu, useAgentsHeaderMenu } from "./taskActions"; @@ -143,6 +143,21 @@ function setup() { ); } +it("removes the redundant Automations header button and opens Agent Settings from the gear", () => { + const settings = vi.fn(); + const unregister = registerActions([{ id: "file.settings", title: "Settings…", run: settings }]); + try { + const { container } = render(); + expect(container.querySelectorAll("button")).toHaveLength(2); + const gear = screen.getByRole("button", { name: "Agent Settings" }); + expect(gear).toHaveAttribute("data-tooltip", "Agent Settings"); + fireEvent.click(gear); + expect(actions.executeAction).toHaveBeenCalledWith("file.settings", REGISTRY_PAGE); + } finally { + unregister(); + } +}); + describe("Agents selection", () => { it.each([SESSION_KIND, "file"])("right-clicking a task keeps the current %s view open", (kind) => { editor.active = { kind, key: "current", data: { task: "one" } }; diff --git a/src/features/agents/AgentsView.tsx b/src/features/agents/AgentsView.tsx index 148498520a..a91599eccf 100644 --- a/src/features/agents/AgentsView.tsx +++ b/src/features/agents/AgentsView.tsx @@ -20,6 +20,7 @@ import { } from "@/ui"; import { GROUP_DRAG, + REGISTRY_PAGE, SESSION_KIND, TASK_DRAG, age, @@ -64,22 +65,15 @@ import { SessionEditor } from "./SessionEditor"; import { HomeEditor } from "./HomeEditor"; import { automatedTaskVisible, useAutomations, useAutomationsSync } from "./automationsModel"; import styles from "./Agents.module.css"; -import autoStyles from "./Automations.module.css"; import { basename, useProject } from "@/platform/project"; import { useTx } from "@/platform/i18n"; import { executeAction } from "@/platform/actions"; export function AgentsHeaderActions() { - const host = useAutomations((s) => s.snapshot.host); - const hasAttention = host.unreadRuns > 0 || host.needsInputRuns > 0; return ( <> - - - {hasAttention && - + ); } diff --git a/src/features/agents/Automations.module.css b/src/features/agents/Automations.module.css index bf2e20585e..a8db3c7c64 100644 --- a/src/features/agents/Automations.module.css +++ b/src/features/agents/Automations.module.css @@ -584,23 +584,6 @@ font-size: var(--fs-small); } -/* Sidebar tool window header badge dot for unread/attention runs. */ -.headerBadgeWrap { - position: relative; - display: inline-flex; -} - -.headerBadgeDot { - position: absolute; - top: 4px; - right: 4px; - width: 6px; - height: 6px; - border-radius: 50%; - background: var(--accent); - pointer-events: none; -} - /* Session provenance banner & schedule strip */ .provenanceBanner { display: flex; diff --git a/src/features/agents/SubmitButton.tsx b/src/features/agents/SubmitButton.tsx index 090b4e025a..97288668b5 100644 --- a/src/features/agents/SubmitButton.tsx +++ b/src/features/agents/SubmitButton.tsx @@ -8,7 +8,7 @@ export function SubmitButton({ variant = "primary", ...props }: Pick & { - label: "Start" | "Starting…" | "Send" | "Queue"; + label: "Start" | "Starting…" | "Send" | "Queue" | "Stop"; pending?: boolean; }) { const tx = useTx(); @@ -22,7 +22,7 @@ export function SubmitButton({ aria-label={name} {...tooltipAttrs(name)} > - {pending ? : } + {pending ? : } ); } diff --git a/src/features/agents/messageEditing.test.tsx b/src/features/agents/messageEditing.test.tsx index 1be1da90c5..e09b6585bc 100644 --- a/src/features/agents/messageEditing.test.tsx +++ b/src/features/agents/messageEditing.test.tsx @@ -43,6 +43,7 @@ vi.mock("@tauri-apps/api/webview", () => ({ }), })); +import { ContextMenuHost } from "@/ui"; import { SessionEditor } from "./SessionEditor"; import styles from "./Session.module.css"; import { textOf, typeIn } from "./composerTesting"; @@ -521,16 +522,34 @@ describe("session composer submission", () => { expect(textOf(box)).toBe(""); }); - it("keeps Queue named and shows icon-only Stop actions while the agent works", async () => { + it("replaces disabled Send with Stop while working and switches the same button to Queue for a draft", async () => { useAgents.setState({ tasks: new Map([[task.id, { ...task, status: "running" }]]), }); - render(); - const queue = screen.getByRole("button", { name: "Queue" }); - expect(queue.textContent).toBe(""); - expect(queue).toHaveAttribute("data-tooltip", "Queue"); - expect(queue).toBeDisabled(); - expect(screen.getAllByRole("button", { name: "Stop" }).every((button) => button.textContent === "")).toBe(true); + render( + <> + + + , + ); + const stop = screen.getByRole("button", { name: "Stop" }); + expect(stop.textContent).toBe(""); + expect(stop).toHaveAttribute("data-tooltip", "Stop"); + expect(stop).toBeEnabled(); + expect(screen.queryByRole("button", { name: "Queue" })).toBeNull(); + fireEvent.click(stop); + await waitFor(() => expect(ipc.cancel).toHaveBeenCalledWith(task.id, null)); + + const box = screen.getByRole("textbox", { name: "Message" }); + typeIn(box, "Follow up"); + expect(screen.getByRole("button", { name: "Queue" })).toBe(stop); + expect(stop).toHaveAttribute("data-tooltip", "Queue"); + expect(stop).toBeEnabled(); + expect(screen.queryByRole("button", { name: "Stop" })).toBeNull(); + fireEvent.click(screen.getByRole("button", { name: "Message Actions" })); + fireEvent.click(screen.getByRole("menuitem", { name: "Stop" })); + await waitFor(() => expect(ipc.cancel).toHaveBeenCalledTimes(2)); + expect(textOf(box)).toBe("Follow up"); await screen.findByText("Original message"); }); }); diff --git a/src/features/agents/session/SessionComposer.tsx b/src/features/agents/session/SessionComposer.tsx index 5a47e3b11e..df23db0f7d 100644 --- a/src/features/agents/session/SessionComposer.tsx +++ b/src/features/agents/session/SessionComposer.tsx @@ -387,6 +387,9 @@ export function SessionComposer({ }, [rawAgentCommands]); const busy = isBusy(task.status); const shellRunning = useAgents((s) => s.shellRunning.has(task.id)); + const canStop = busy || shellRunning; + const submitDisabled = !canSend(composer) || sending || configuring !== null || task.status === "archived"; + const showStop = canStop && submitDisabled; // ↑ recalls this conversation's messages, newest first (excluding synthetic recovery turns). const history = useMemo( () => (entries ?? []).flatMap((e) => (e.type === "user" && !e.recovery && e.text ? [e.text] : [])).reverse(), @@ -604,14 +607,18 @@ export function SessionComposer({ } actions={ <> - {(busy || shellRunning) && void stopTask(task.id)} />} - + send(false)} + label={showStop ? "Stop" : busy ? "Queue" : "Send"} + pending={!showStop && sending} + variant={canStop ? "secondary" : "primary"} + disabled={!showStop && submitDisabled} + onClick={() => (showStop ? void stopTask(task.id) : send(false))} /> } @@ -707,7 +714,17 @@ function QueueRow({ task, item }: { task: string; item: AgentQueued }) { ); } -function ScheduleSendButton({ task, draftText, disabled }: { task: AgentTask; draftText: string; disabled?: boolean }) { +function ScheduleSendButton({ + task, + draftText, + disabled, + stopInMenu, +}: { + task: AgentTask; + draftText: string; + disabled?: boolean; + stopInMenu: boolean; +}) { const tx = useTx(); const hasDraft = !!draftText.trim(); @@ -752,6 +769,12 @@ function ScheduleSendButton({ task, draftText, disabled }: { task: AgentTask; dr }; const items: MenuItem[] = [ + ...(stopInMenu + ? [ + { kind: "item" as const, id: "stop", label: "Stop", icon: "stop", run: () => void stopTask(task.id) }, + { kind: "separator" as const }, + ] + : []), { kind: "item", id: "later-15m", @@ -817,8 +840,8 @@ function ScheduleSendButton({ task, draftText, disabled }: { task: AgentTask; dr showContextMenu(e, items)} /> diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index d48a0d3183..297616c89e 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2189,6 +2189,8 @@ "sse (Server-Sent Events)": "sse (Server-Sent Events)", "One KEY=VALUE entry per line.": "One KEY=VALUE entry per line.", "One Header=Value entry per line.": "One Header=Value entry per line.", + "Agent Settings": "Agent Settings", + "Message Actions": "Message Actions", "MCP Connections…": "MCP Connections…", "Configure the MCP servers that agents can use.": "Configure the MCP servers that agents can use.", "No matching remote branches": "No matching remote branches", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 0f8c9892c2..c178b078b8 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -9023,6 +9023,8 @@ "One KEY=VALUE entry per line.": "每行一个 KEY=VALUE 条目。", "One Header=Value entry per line.": "每行一个 Header=Value 条目。", "Maven project could not be configured": "无法配置 Maven 项目", + "Agent Settings": "智能体设置", + "Message Actions": "消息操作", "MCP Connections…": "MCP 连接…", "Configure the MCP servers that agents can use.": "配置智能体可以使用的 MCP 服务器。", "Type:": "类型:",