-
Notifications
You must be signed in to change notification settings - Fork 70
feat(chat): add compact tool UI mode for executed tool blocks (#322) #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fd5ecdd
d356ab6
e9068ea
8f2079e
a6a2f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,6 +71,7 @@ import { | |||||||
| Split, | ||||||||
| ArrowRight, | ||||||||
| Check, | ||||||||
| ChevronRight, | ||||||||
| } from "lucide-react" | ||||||||
| import { cn } from "@/lib/utils" | ||||||||
| import { PathTooltip } from "../ui/PathTooltip" | ||||||||
|
|
@@ -182,8 +183,16 @@ export const ChatRowContent = ({ | |||||||
| }: ChatRowContentProps) => { | ||||||||
| const { t, i18n } = useTranslation() | ||||||||
|
|
||||||||
| const { mcpServers, alwaysAllowMcp, currentCheckpoint, mode, apiConfiguration, clineMessages, currentTaskItem } = | ||||||||
| useExtensionState() | ||||||||
| const { | ||||||||
| mcpServers, | ||||||||
| alwaysAllowMcp, | ||||||||
| currentCheckpoint, | ||||||||
| mode, | ||||||||
| apiConfiguration, | ||||||||
| clineMessages, | ||||||||
| currentTaskItem, | ||||||||
| compactToolUI, | ||||||||
| } = useExtensionState() | ||||||||
| const { info: model } = useSelectedModel(apiConfiguration) | ||||||||
| const [isEditing, setIsEditing] = useState(false) | ||||||||
| const [editedContent, setEditedContent] = useState("") | ||||||||
|
|
@@ -1405,6 +1414,28 @@ export const ChatRowContent = ({ | |||||||
| const sayTool = safeJsonParse<ClineSayTool>(message.text) | ||||||||
| if (!sayTool) return null | ||||||||
|
|
||||||||
| // Compact mode (#322): collapse executed (history) tool blocks to a single | ||||||||
| // clickable line, hiding verbose params/payloads until expanded. Only applies | ||||||||
| // to `say` tool rows here — approval prompts (`ask`) are never compacted. | ||||||||
| if (compactToolUI && !isExpanded) { | ||||||||
| const compactLabel = sayTool.path ? `${sayTool.tool}: ${sayTool.path}` : sayTool.tool | ||||||||
| return ( | ||||||||
| <button | ||||||||
| type="button" | ||||||||
| onClick={handleToggleExpand} | ||||||||
| aria-expanded={false} | ||||||||
| className="flex items-center gap-2 py-0.5 cursor-pointer text-vscode-descriptionForeground hover:text-vscode-foreground bg-transparent border-none text-inherit w-full text-left" | ||||||||
| data-testid="compact-tool-row" | ||||||||
| title={t("chat:compactTool.expandHint")}> | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would adding
Suggested change
|
||||||||
| <ChevronRight className="w-3.5 h-3.5 shrink-0" /> | ||||||||
| <PocketKnife className="w-3.5 h-3.5 shrink-0" /> | ||||||||
| <span className="truncate text-sm"> | ||||||||
| {t("chat:compactTool.label", { tool: compactLabel })} | ||||||||
| </span> | ||||||||
| </button> | ||||||||
| ) | ||||||||
| } | ||||||||
|
|
||||||||
| switch (sayTool.tool) { | ||||||||
| case "runSlashCommand": { | ||||||||
| const slashCommandInfo = sayTool | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import React from "react" | ||
| import { fireEvent, render, screen } from "@/utils/test-utils" | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query" | ||
| import type { ClineMessage } from "@roo-code/types" | ||
| import { ChatRowContent } from "../ChatRow" | ||
|
|
||
| const mockPostMessage = vi.fn() | ||
| const mockOnToggleExpand = vi.fn() | ||
|
|
||
| vi.mock("@src/utils/vscode", () => ({ | ||
| vscode: { | ||
| postMessage: (...args: unknown[]) => mockPostMessage(...args), | ||
| }, | ||
| })) | ||
|
|
||
| // Mock i18n | ||
| vi.mock("react-i18next", () => ({ | ||
| useTranslation: () => ({ | ||
| t: (key: string, opts?: Record<string, string>) => { | ||
| const map: Record<string, string> = { | ||
| "chat:compactTool.expandHint": "Click to expand", | ||
| "chat:compactTool.label": opts?.tool ? `tool: ${opts.tool}` : "tool", | ||
| } | ||
| return map[key] || key | ||
| }, | ||
| }), | ||
| Trans: ({ children }: { children?: React.ReactNode }) => <>{children}</>, | ||
| initReactI18next: { type: "3rdParty", init: () => {} }, | ||
| })) | ||
|
|
||
| // Mock CodeBlock (avoid ESM/highlighter costs) | ||
| vi.mock("@src/components/common/CodeBlock", () => ({ | ||
| default: () => null, | ||
| })) | ||
|
|
||
| // Mock useExtensionState to enable compactToolUI | ||
| vi.mock("@src/context/ExtensionStateContext", () => ({ | ||
| useExtensionState: () => ({ | ||
| mcpServers: [], | ||
| alwaysAllowMcp: false, | ||
| currentCheckpoint: undefined, | ||
| mode: "code", | ||
| apiConfiguration: {}, | ||
| clineMessages: [], | ||
| currentTaskItem: undefined, | ||
| compactToolUI: true, | ||
| }), | ||
| ExtensionStateContextProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| })) | ||
|
|
||
| const queryClient = new QueryClient() | ||
|
|
||
| function createSayToolMessage(toolPayload: Record<string, unknown>): ClineMessage { | ||
| return { | ||
| type: "say", | ||
| say: "tool" as any, | ||
| ts: Date.now(), | ||
| text: JSON.stringify(toolPayload), | ||
| } | ||
| } | ||
|
|
||
| function renderChatRow(message: ClineMessage, isExpanded = false) { | ||
| return render( | ||
| <QueryClientProvider client={queryClient}> | ||
| <ChatRowContent | ||
| message={message} | ||
| isExpanded={isExpanded} | ||
| isLast={false} | ||
| isStreaming={false} | ||
| onToggleExpand={mockOnToggleExpand} | ||
| onSuggestionClick={() => {}} | ||
| onBatchFileResponse={() => {}} | ||
| onFollowUpUnmount={() => {}} | ||
| isFollowUpAnswered={false} | ||
| /> | ||
| </QueryClientProvider>, | ||
| ) | ||
| } | ||
|
|
||
| describe("ChatRow - compact tool UI", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockOnToggleExpand.mockClear() | ||
| }) | ||
|
|
||
| it("renders the compact row when compactToolUI is true and not expanded", () => { | ||
| const message = createSayToolMessage({ tool: "readFile", path: "src/file.ts" }) | ||
| renderChatRow(message, false) | ||
|
|
||
| expect(screen.getByTestId("compact-tool-row")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("calls onToggleExpand when the compact row is clicked", () => { | ||
| const message = createSayToolMessage({ tool: "readFile", path: "src/file.ts" }) | ||
| renderChatRow(message, false) | ||
|
|
||
| fireEvent.click(screen.getByTestId("compact-tool-row")) | ||
|
|
||
| expect(mockOnToggleExpand).toHaveBeenCalledWith(message.ts) | ||
| }) | ||
|
|
||
| it("has aria-expanded=false on the compact button", () => { | ||
| const message = createSayToolMessage({ tool: "readFile", path: "src/file.ts" }) | ||
| renderChatRow(message, false) | ||
|
|
||
| expect(screen.getByTestId("compact-tool-row")).toHaveAttribute("aria-expanded", "false") | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,7 @@ describe("ContextManagementSettings", () => { | |
| maxOpenTabsContext: 20, | ||
| maxWorkspaceFiles: 200, | ||
| showRooIgnoredFiles: false, | ||
| compactToolUI: false, | ||
| profileThresholds: {}, | ||
| includeDiagnosticMessages: true, | ||
| maxDiagnosticMessages: 50, | ||
|
|
@@ -150,6 +151,23 @@ describe("ContextManagementSettings", () => { | |
| }) | ||
| }) | ||
|
|
||
| it("renders the compact tool UI toggle", () => { | ||
| render(<ContextManagementSettings {...defaultProps} />) | ||
| expect(screen.getByTestId("compact-tool-ui-checkbox")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("calls setCachedStateField when the compact tool UI checkbox is toggled", async () => { | ||
| const setCachedStateField = vi.fn() | ||
| render(<ContextManagementSettings {...defaultProps} setCachedStateField={setCachedStateField} />) | ||
|
|
||
| const checkbox = screen.getByTestId("compact-tool-ui-checkbox").querySelector("input")! | ||
| fireEvent.click(checkbox) | ||
|
|
||
| await waitFor(() => { | ||
| expect(setCachedStateField).toHaveBeenCalledWith("compactToolUI", true) | ||
| }) | ||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These cover the settings toggle nicely. Would it be worth also adding a test that mounts |
||
|
|
||
| it("calls setCachedStateField when max diagnostic messages slider is changed", async () => { | ||
| const setCachedStateField = vi.fn() | ||
| render(<ContextManagementSettings {...defaultProps} setCachedStateField={setCachedStateField} />) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.