Skip to content

Your lightweight open-source personal agent.

fix(webui): use file-type icons in file change activity

chengyongru8de03ac0a281
diff --git a/webui/src/components/FileReferenceChip.tsx b/webui/src/components/FileReferenceChip.tsx
index ff4539ae3..cbf1a8e20 100644
--- a/webui/src/components/FileReferenceChip.tsx
+++ b/webui/src/components/FileReferenceChip.tsx
@@ -31,6 +31,7 @@ interface FileReferenceChipProps {
path: string;
tooltipPath?: string;
display?: "name" | "path";
+ showIcon?: boolean;
active?: boolean;
className?: string;
textClassName?: string;
@@ -43,6 +44,7 @@ export function FileReferenceChip({
path,
tooltipPath,
display = "name",
+ showIcon = true,
active = false,
className,
textClassName,
@@ -97,7 +99,7 @@ export function FileReferenceChip({
],
)}
>
- <FileReferenceIcon kind={kind} className="translate-y-[0.12em]" />
+ {showIcon ? <FileReferenceIcon kind={kind} className="translate-y-[0.12em]" /> : null}
<span
data-sheen-text={active ? displayText : undefined}
className={cn(
@@ -258,6 +260,10 @@ const FILE_ICONS = {
video: FileVideo2,
} satisfies Record<FileReferenceKind, LucideIcon>;
+export function fileIconForPath(path: string): LucideIcon {
+ return FILE_ICONS[fileKindForPath(path)];
+}
+
/** The same file silhouette and stroke in replies, tabs, and attachment tiles. */
export function FileReferenceIcon({ kind, className }: { kind: FileReferenceKind; className?: string }) {
const Icon = FILE_ICONS[kind];
diff --git a/webui/src/components/thread/activity/ActivityStep.tsx b/webui/src/components/thread/activity/ActivityStep.tsx
index 8933cfa6b..12cdf690a 100644
--- a/webui/src/components/thread/activity/ActivityStep.tsx
+++ b/webui/src/components/thread/activity/ActivityStep.tsx
@@ -3,7 +3,7 @@ import type { LucideIcon } from "lucide-react";
import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen";
import { formControlFocusClassName } from "@/components/ui/form-control";
-import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
+import { HoverHint, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
export type ActivityStepTone = "neutral" | "active" | "success" | "error";
@@ -11,6 +11,7 @@ export type ActivityStepTone = "neutral" | "active" | "success" | "error";
export interface ActivityStepProps {
icon?: LucideIcon;
marker?: ReactNode;
+ markerLabel?: string;
showMarker?: boolean;
label: ReactNode;
detail?: string;
@@ -30,6 +31,7 @@ export interface ActivityStepProps {
export function ActivityStep({
icon: Icon,
marker,
+ markerLabel,
showMarker = true,
label,
detail,
@@ -48,6 +50,30 @@ export function ActivityStep({
const lineRef = useRef<HTMLDivElement>(null);
const [hintOpen, setHintOpen] = useState(false);
const textLabel = typeof label === "string" ? [label, detail].filter(Boolean).join("\n") : undefined;
+ const activityMarker = (
+ <span
+ className={cn(
+ "flex h-5 w-[1.125rem] shrink-0 items-start justify-center pt-[3px]",
+ markerLabel && ["rounded-sm", formControlFocusClassName],
+ )}
+ aria-hidden={markerLabel ? undefined : true}
+ role={markerLabel ? "img" : undefined}
+ aria-label={markerLabel}
+ tabIndex={markerLabel ? 0 : undefined}
+ >
+ {marker ?? (
+ <span
+ className={cn(
+ "grid h-3.5 w-3.5 place-items-center transition-colors",
+ tone === "error" ? "text-destructive/[0.78]" : "text-muted-foreground",
+ markerClassName,
+ )}
+ >
+ {Icon ? <Icon className="h-3.5 w-3.5" strokeWidth={1.75} aria-hidden /> : null}
+ </span>
+ )}
+ </span>
+ );
const line = (
<div
ref={lineRef}
@@ -92,26 +118,9 @@ export function ActivityStep({
)}
style={style}
>
- {showMarker ? (
- <span
- className={cn(
- "flex h-5 w-[1.125rem] shrink-0 items-start justify-center pt-[3px]",
- )}
- aria-hidden
- >
- {marker ?? (
- <span
- className={cn(
- "grid h-3.5 w-3.5 place-items-center transition-colors",
- tone === "error" ? "text-destructive/[0.78]" : "text-muted-foreground",
- markerClassName,
- )}
- >
- {Icon ? <Icon className="h-3.5 w-3.5" strokeWidth={1.75} /> : null}
- </span>
- )}
- </span>
- ) : null}
+ {showMarker ? markerLabel ? (
+ <HoverHint content={markerLabel}>{activityMarker}</HoverHint>
+ ) : activityMarker : null}
<div className={cn("min-w-0", contentClassName)}>
{typeof label === "string" ? (
<TooltipProvider>
diff --git a/webui/src/components/thread/activity/FileEditRow.tsx b/webui/src/components/thread/activity/FileEditRow.tsx
index 1b4ed83ff..49e19325d 100644
--- a/webui/src/components/thread/activity/FileEditRow.tsx
+++ b/webui/src/components/thread/activity/FileEditRow.tsx
@@ -6,9 +6,9 @@ import {
ChevronUp,
ExternalLink,
} from "lucide-react";
-import { Trans, useTranslation } from "react-i18next";
+import { useTranslation } from "react-i18next";
-import { FileReferenceChip } from "@/components/FileReferenceChip";
+import { FileReferenceChip, fileIconForPath } from "@/components/FileReferenceChip";
import { codeLanguageFromPath } from "@/lib/code-language";
import {
hasRenderableFileDiff,
@@ -98,7 +98,8 @@ function FileEditRow({
return (
<div className="min-w-0">
<ActivityStep
- showMarker={false}
+ icon={fileIconForPath(edit.absolute_path || edit.path)}
+ markerLabel={action}
active={editing}
tone={failed ? "error" : editing ? "active" : "success"}
className="text-xs"
@@ -107,24 +108,16 @@ function FileEditRow({
? t("message.fileEditPreparing", { defaultValue: "Preparing file edit…" })
: (
<span className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap">
- <Trans
- i18nKey="message.agentActivity.actionTargetRich"
- values={{ action }}
- components={{
- action: <span className={cn("shrink-0", failed && "text-destructive/80")} />,
- target: (
- <FileReferenceChip
- path={edit.path}
- previewPath={edit.absolute_path || edit.path}
- onOpen={onOpenFilePreview}
- display="path"
- active={editing}
- className="min-w-0"
- textClassName="truncate text-[12px]"
- testId="activity-file-reference"
- />
- ),
- }}
+ <FileReferenceChip
+ path={edit.path}
+ previewPath={edit.absolute_path || edit.path}
+ onOpen={onOpenFilePreview}
+ display="path"
+ showIcon={false}
+ active={editing}
+ className="min-w-0"
+ textClassName="truncate text-[12px]"
+ testId="activity-file-reference"
/>
{hasCountedDiff ? <DiffPair added={edit.added} deleted={edit.deleted} /> : null}
</span>
diff --git a/webui/src/dev/gallery/shared-views.tsx b/webui/src/dev/gallery/shared-views.tsx
index 7502b5563..c3285edbc 100644
--- a/webui/src/dev/gallery/shared-views.tsx
+++ b/webui/src/dev/gallery/shared-views.tsx
@@ -73,14 +73,21 @@ function ActivityPreview() {
function FilesPreview() {
const [state, setState] = useState<"done" | "editing" | "error">("done");
+ const [operation, setOperation] = useState<"create" | "edit" | "delete">("edit");
const [display, setDisplay] = useState<"summary" | "diff" | "collapsed_diff">("diff");
const [opened, setOpened] = useState("");
+ const diffs = {
+ create: '@@ -0,0 +1 @@\n+export const greeting = "Hello, Nanobot";\n',
+ edit: '@@ -1,2 +1,2 @@\n-export const greeting = "Hello";\n+export const greeting = "Hello, Nanobot";\n export const ready = true;\n',
+ delete: '@@ -1 +0,0 @@\n-export const greeting = "Hello";\n',
+ };
const edit: FileEditSummary = {
- key: "example-edit", path: "src/greeting.ts", added: 1, deleted: 1, approximate: false, binary: false,
- status: state, pending: state === "editing", operation: "edit", error: state === "error" ? "Example edit could not be applied." : undefined,
- diff: { format: "unified", text: '@@ -1,2 +1,2 @@\n-export const greeting = "Hello";\n+export const greeting = "Hello, Nanobot";\n export const ready = true;\n' },
+ key: "example-edit", path: "src/greeting.ts", added: operation === "delete" ? 0 : 1, deleted: operation === "create" ? 0 : 1, approximate: false, binary: false,
+ status: state, pending: state === "editing", operation, error: state === "error" ? "Example edit could not be applied." : undefined,
+ diff: { format: "unified", text: diffs[operation] },
};
return <><StatePicker label="File edit state" value={state} options={["done", "editing", "error"]} onChange={setState} />
+ <StatePicker label="File operation" value={operation} options={["create", "edit", "delete"]} onChange={setOperation} />
<StatePicker label="Diff display" value={display} options={["summary", "diff", "collapsed_diff"]} onChange={setDisplay} />
<FileEditGroup edits={[edit]} displayMode={display} onOpenFilePreview={setOpened} />
<p role="status" className="mt-4 text-xs text-muted-foreground">{opened ? `Selected file: ${opened}` : "Select a file reference to exercise its callback."}</p></>;
diff --git a/webui/src/tests/activity-step.test.tsx b/webui/src/tests/activity-step.test.tsx
index 930d27cc6..604a94453 100644
--- a/webui/src/tests/activity-step.test.tsx
+++ b/webui/src/tests/activity-step.test.tsx
@@ -1,10 +1,14 @@
-import { cleanup, render, screen, within } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
-import { afterEach, expect, it } from "vitest";
+import { FileCode2 } from "lucide-react";
+import { afterEach, expect, it, vi } from "vitest";
import { ActivityStep } from "@/components/thread/activity/ActivityStep";
-afterEach(cleanup);
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
it("animates a running label with details and keeps the completed activity readable", () => {
const { rerender } = render(<ActivityStep label="Running Blender" detail="--json project new" active />);
@@ -32,3 +36,29 @@ it("keeps truncated activity details available on keyboard focus", async () => {
const tooltip = await screen.findByRole("tooltip");
expect(within(tooltip).getByText(/Used Blender/)).toHaveTextContent("--json project new");
});
+
+it("describes a named operation marker on keyboard focus before the file action", async () => {
+ render(<ActivityStep icon={FileCode2} markerLabel="Created" label={<button>src/app.tsx</button>} />);
+
+ await userEvent.tab();
+
+ const marker = screen.getByRole("img", { name: "Created" });
+ expect(marker).toHaveFocus();
+ expect(marker.closest('[aria-hidden="true"]')).toBeNull();
+ expect(screen.getByRole("tooltip")).toHaveTextContent("Created");
+
+ await userEvent.tab();
+ expect(screen.getByRole("button", { name: "src/app.tsx" })).toHaveFocus();
+});
+
+it("uses the shared hover delay for a named operation marker", () => {
+ vi.useFakeTimers();
+ render(<ActivityStep icon={FileCode2} markerLabel="Created" label={<span>src/app.tsx</span>} />);
+ const marker = screen.getByRole("img", { name: "Created" });
+
+ fireEvent.pointerMove(marker, { pointerType: "mouse" });
+ act(() => vi.advanceTimersByTime(499));
+ expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
+ act(() => vi.advanceTimersByTime(1));
+ expect(screen.getByRole("tooltip")).toHaveTextContent("Created");
+});
diff --git a/webui/src/tests/agent-activity-cluster.test.tsx b/webui/src/tests/agent-activity-cluster.test.tsx
index 7c2e952cd..440ca8e20 100644
--- a/webui/src/tests/agent-activity-cluster.test.tsx
+++ b/webui/src/tests/agent-activity-cluster.test.tsx
@@ -162,7 +162,7 @@ describe("AgentActivityCluster", () => {
expect(screen.getByText(`Reading file ${path}`)).toBeInTheDocument();
expect(screen.getByLabelText("Using Blender, --json --background scene.blend")).toBeInTheDocument();
expect(screen.getByLabelText("Opening example.com, Browserbase")).toBeInTheDocument();
- expect(screen.getByText("Edited")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
await act(async () => setAppLanguage("zh-CN"));
@@ -171,7 +171,7 @@ describe("AgentActivityCluster", () => {
expect(screen.getByText(`正在读取文件 ${path}`)).toBeInTheDocument();
expect(screen.getByLabelText("正在使用 Blender, --json --background scene.blend")).toBeInTheDocument();
expect(screen.getByLabelText("正在打开 example.com, Browserbase")).toBeInTheDocument();
- expect(screen.getByText("编辑")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "编辑", exact: true })).toBeInTheDocument();
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
await act(async () => setAppLanguage("ja"));
@@ -180,8 +180,9 @@ describe("AgentActivityCluster", () => {
expect(screen.getByText(`${path} ファイルを読み取り中`)).toBeInTheDocument();
expect(screen.getByLabelText("Blender を使用中, --json --background scene.blend")).toBeInTheDocument();
expect(screen.getByLabelText("example.com 開いています, Browserbase")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "編集", exact: true })).toBeInTheDocument();
expect(screen.getByTestId("activity-file-reference").closest('[data-testid="activity-step"]'))
- .toHaveTextContent(`${path} 編集`);
+ .toHaveAttribute("aria-label", `${path} 編集`);
});
it("loads deferred trace details only after completed activity is expanded", async () => {
@@ -535,7 +536,7 @@ describe("AgentActivityCluster", () => {
/>,
);
- assertBetween(screen.getByText("Editing"));
+ assertBetween(screen.getByRole("img", { name: "Editing", exact: true }));
rerender(
<AgentActivityCluster
@@ -545,7 +546,7 @@ describe("AgentActivityCluster", () => {
/>,
);
- assertBetween(screen.getByText("Edited"));
+ assertBetween(screen.getByRole("img", { name: "Edited", exact: true }));
});
it.each(["diff", "collapsed_diff"] as const)(
@@ -676,7 +677,7 @@ describe("AgentActivityCluster", () => {
expect(screen.getByTestId("file-edit-diff")).toBeInTheDocument();
expect(screen.getByText("return <Old />;")).toBeInTheDocument();
expect(screen.getByText("return <New />;")).toBeInTheDocument();
- expect(screen.getByText("Edited")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
expect(screen.getAllByTestId("activity-diff-pair")).toHaveLength(1);
@@ -684,7 +685,7 @@ describe("AgentActivityCluster", () => {
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "summary" });
});
expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument();
- expect(screen.getByText("Edited")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
act(() => {
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "diff" });
@@ -977,9 +978,10 @@ describe("AgentActivityCluster", () => {
hasBodyBelow={false}
/>,
);
- expect(screen.getByText("Created")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Created", exact: true }).querySelector("svg"))
+ .toHaveClass("lucide-file-text");
expect(screen.getByLabelText("Created tmp.txt")).toBeInTheDocument();
- expect(screen.queryByText("Edited")).not.toBeInTheDocument();
+ expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument();
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("tmp.txt");
expect(!!screen.queryByTestId("file-edit-diff")).toBe(hasDiff);
} finally {
@@ -1015,8 +1017,9 @@ describe("AgentActivityCluster", () => {
);
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
- expect(screen.getByText("Deleted")).toBeInTheDocument();
- expect(screen.queryByText("Edited")).not.toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Deleted", exact: true }).querySelector("svg"))
+ .toHaveClass("lucide-file-code2");
+ expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument();
});
it("renders file-only edits without a redundant disclosure", () => {
@@ -1048,8 +1051,11 @@ describe("AgentActivityCluster", () => {
expect(screen.queryByRole("button", { name: /edited app\.tsx/i })).not.toBeInTheDocument();
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
- expect(screen.getByText("Edited")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
expect(screen.queryByTestId("activity-header-file-reference")).not.toBeInTheDocument();
+ const marker = screen.getByRole("img", { name: "Edited", exact: true });
+ expect(marker.querySelector("svg")).toHaveClass("lucide-file-code2");
+ expect(marker.closest('[data-testid="activity-step"]')?.querySelectorAll("svg")).toHaveLength(1);
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
expect(screen.getByText("+12")).toBeInTheDocument();
expect(screen.getByText("-3")).toBeInTheDocument();
@@ -1798,7 +1804,7 @@ describe("AgentActivityCluster", () => {
);
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
- expect(screen.getByText("Edited")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
expect(screen.queryByText("+0")).not.toBeInTheDocument();
expect(screen.queryByText("-0")).not.toBeInTheDocument();
});
@@ -1893,7 +1899,7 @@ describe("AgentActivityCluster", () => {
);
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
- const row = screen.getByText("Could not edit").closest('[data-testid="activity-step"]');
+ const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]');
expect(row).toBeInTheDocument();
expect(row).not.toHaveAttribute("title");
expect(screen.queryByText("Target text was not found in angry-birds.html.")).not.toBeInTheDocument();
@@ -1927,7 +1933,7 @@ describe("AgentActivityCluster", () => {
);
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
- const row = screen.getByText("Could not edit").closest('[data-testid="activity-step"]');
+ const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]');
expect(row).toBeInTheDocument();
expect(row).not.toHaveAttribute("title");
expect(screen.queryByText("No permission to change this location.")).not.toBeInTheDocument();
@@ -2008,7 +2014,7 @@ describe("AgentActivityCluster", () => {
const fileRefs = screen.getAllByTestId("activity-file-reference");
expect(fileRefs).toHaveLength(3);
expect(fileRefs.every((ref) => ref.textContent?.includes("minecraft-fps/index.html"))).toBe(true);
- const failedRow = screen.getByText("Could not edit").closest(
+ const failedRow = screen.getByRole("img", { name: "Could not edit", exact: true }).closest(
'[data-testid="activity-step"]',
);
expect(failedRow).toBeInTheDocument();
@@ -2066,8 +2072,8 @@ describe("AgentActivityCluster", () => {
);
fireEvent.click(screen.getByRole("button", { name: /^Worked/ }));
- expect(screen.getByText("Edited")).toBeInTheDocument();
- expect(screen.getByText("Could not edit")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Could not edit", exact: true })).toBeInTheDocument();
expect(screen.getAllByTestId("activity-file-reference")).toHaveLength(2);
});
diff --git a/webui/src/tests/file-reference-icon.test.tsx b/webui/src/tests/file-reference-icon.test.tsx
index ae2f4e0ff..c3fde7d40 100644
--- a/webui/src/tests/file-reference-icon.test.tsx
+++ b/webui/src/tests/file-reference-icon.test.tsx
@@ -63,6 +63,19 @@ describe("shared file icons", () => {
},
);
+ it("keeps iconless activity references named and keyboard-operable", () => {
+ const open = vi.fn();
+ render(<FileReferenceChip path="src/app.tsx" previewPath="/repo/src/app.tsx"
+ display="path" showIcon={false} onOpen={open} />);
+
+ const reference = screen.getByRole("button", { name: "src/app.tsx" });
+ expect(reference).toHaveTextContent("src/app.tsx");
+ expect(reference.querySelector("svg")).toBeNull();
+ expect(reference).toHaveAttribute("tabindex", "0");
+ fireEvent.keyDown(reference, { key: "Enter" });
+ expect(open).toHaveBeenCalledWith("/repo/src/app.tsx");
+ });
+
it.each(["image", "video"] as const)("retains %s identity when its attachment is unavailable", (kind) => {
const { container } = render(<AttachmentTile attachment={{ kind, name: "Unavailable" }} />);
expect(container.querySelector("svg")).toHaveClass(kind === "image" ? "lucide-file-image" : "lucide-file-video2");
diff --git a/webui/src/tests/thread-messages.test.tsx b/webui/src/tests/thread-messages.test.tsx
index 4d5ea23c5..87deb5983 100644
--- a/webui/src/tests/thread-messages.test.tsx
+++ b/webui/src/tests/thread-messages.test.tsx
@@ -86,7 +86,7 @@ describe("ThreadMessages", () => {
const assertIndependentDiff = () => {
const diff = screen.getByTestId("file-edit-diff");
expect(diff).toBeVisible();
- expect(screen.getByText("Edited")).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument();
expect(diff.closest('[aria-hidden="true"], [inert], [data-testid="agent-activity-content"]'))
.toBeNull();
expect(screen.getByText("File updated")).toBeVisible();