diff --git a/src/features/agents/Session.module.css b/src/features/agents/Session.module.css index b24da06778..77a13c09f9 100644 --- a/src/features/agents/Session.module.css +++ b/src/features/agents/Session.module.css @@ -1916,6 +1916,18 @@ flex: none; color: var(--fg-muted); } +.toolDir { + flex: none; + max-width: 140px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + padding: 0 4px; + border-radius: var(--radius-small); + background: var(--bg-hover); + color: var(--fg-muted); + font-size: var(--agent-fs-small, var(--fs-small)); +} .toolPath { flex: none; max-width: 180px; diff --git a/src/features/agents/session/ProcessRows.tsx b/src/features/agents/session/ProcessRows.tsx index 51ba70c330..adb2228244 100644 --- a/src/features/agents/session/ProcessRows.tsx +++ b/src/features/agents/session/ProcessRows.tsx @@ -17,7 +17,7 @@ import { type TurnRow, } from "./conversationRows"; import { Fold } from "./Folds"; -import { samePropsExcept, shortTitle } from "./shared"; +import { commandTitle, samePropsExcept, shortTitle } from "./shared"; import { ThoughtEntry, ToolEntry } from "./toolEntries"; /** "Edited 2 files ยท Read 4 files": what a run of work did; "Reasoning" when it only thought. */ @@ -124,7 +124,9 @@ export const ProcessRun = memo(function ProcessRun({ const live = [...tools].reverse().find(({ entry }) => liveTool(entry))?.entry; const last = row.entries.at(-1)!.entry; const current = live - ? shortTitle(task, live.title || live.kind) + ? live.kind === "execute" + ? commandTitle(task, live.title || live.kind).title + : shortTitle(task, live.title || live.kind) : working && last.type === "thought" ? tx("Thinking") : null; diff --git a/src/features/agents/session/shared.test.ts b/src/features/agents/session/shared.test.ts new file mode 100644 index 0000000000..247388b0b3 --- /dev/null +++ b/src/features/agents/session/shared.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "vitest"; +import type { AgentTask } from "@/bindings"; +import { commandTitle } from "./shared"; + +const task = { cwd: "/repo/app" } as AgentTask; + +describe("commandTitle", () => { + it("drops a cd into the task's own folder", () => { + expect(commandTitle(task, "cd /repo/app && git grep -n foo")).toEqual({ title: "git grep -n foo", dir: null }); + expect(commandTitle(task, "cd . ; ls")).toEqual({ title: "ls", dir: null }); + }); + + it("keeps another folder as the place the command ran", () => { + expect(commandTitle(task, "cd /repo/app-icons && pnpm test")).toEqual({ + title: "pnpm test", + dir: "/repo/app-icons", + }); + expect(commandTitle(task, `cd "/repo/my app/" && ls`)).toEqual({ title: "ls", dir: "/repo/my app" }); + }); + + it("leaves commands without a leading cd, or that are only a cd, as they are", () => { + expect(commandTitle(task, "git status && cd x && ls")).toEqual({ title: "git status && cd x && ls", dir: null }); + expect(commandTitle(task, "cd /tmp")).toEqual({ title: "cd /tmp", dir: null }); + expect(commandTitle(task, "cat /repo/app/src/a.ts")).toEqual({ title: "cat src/a.ts", dir: null }); + }); +}); diff --git a/src/features/agents/session/shared.ts b/src/features/agents/session/shared.ts index 447b17ebaf..246c035ef1 100644 --- a/src/features/agents/session/shared.ts +++ b/src/features/agents/session/shared.ts @@ -21,6 +21,21 @@ export type UserEntry = Extract; /** Agent-written titles with the task's own folder dropped from paths. */ export const shortTitle = (task: AgentTask, title: string) => title.replaceAll(`${task.cwd}/`, ""); +/** A leading `cd &&` (or `;`), with the directory quoted or bare. */ +const LEADING_CD = /^\s*cd\s+("[^"]+"|'[^']+'|\S+)\s*(?:&&|;)\s*/; + +/** + * A command's title without the `cd &&` agents put before every call, and the folder it + * moved to when that is not the task's own: the command is what tells calls apart. + */ +export function commandTitle(task: AgentTask, title: string): { title: string; dir: string | null } { + const match = LEADING_CD.exec(title); + if (!match || match[0].length === title.length) return { title: shortTitle(task, title), dir: null }; + const dir = match[1]!.replace(/^(["'])(.*)\1$/, "$2").replace(/\/+$/, ""); + const rest = shortTitle(task, title.slice(match[0].length)); + return { title: rest, dir: dir === task.cwd || dir === "." ? null : dir }; +} + /** * `memo`'s comparison for props rebuilt with every render without changing: a prop named in * `by` is equal when its rule says so, any other prop when it is the same value. diff --git a/src/features/agents/session/toolEntries.tsx b/src/features/agents/session/toolEntries.tsx index 1fe698e7f8..0d72387312 100644 --- a/src/features/agents/session/toolEntries.tsx +++ b/src/features/agents/session/toolEntries.tsx @@ -16,7 +16,7 @@ import { cancelTask } from "../store"; import { openChangeDiff } from "./ChangesTab"; import { Fold } from "./Folds"; import { liveTool } from "./conversationRows"; -import { shortTitle, useNow } from "./shared"; +import { commandTitle, shortTitle, useNow } from "./shared"; /** A location as the agent reported it: absolute on any platform, or relative to the task's folder. */ const isAbsolute = (path: string) => path.startsWith("/") || /^[A-Za-z]:[\\/]/.test(path) || path.startsWith("\\\\"); @@ -104,13 +104,22 @@ export const ToolEntry = memo(function ToolEntry({ const live = liveTool(entry); const took = toolDuration(entry); const run = entry.kind === "execute" ? toolRun(entry) : null; - const title = shortTitle(task, entry.title || entry.kind); + // Commands lose the `cd &&` agents start them with; another folder shows as a tag. + const { title, dir } = + entry.kind === "execute" + ? commandTitle(task, entry.title || entry.kind) + : { title: shortTitle(task, entry.title || entry.kind), dir: null }; // A title that already names the file ("Read pom.xml") needs no second link to it. const links = entry.kind === "execute" ? [] : entry.locations.slice(0, 3).filter((path) => !title.includes(basename(path))); const head = ( <> + {dir && ( + + {basename(dir)} + + )} {title}