Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

fix(daemon): title tool activities with the call's status, not always 'Running'

danielgap30df5d57d614
diff --git a/packages/daemon/src/bridge.ts b/packages/daemon/src/bridge.ts
index 0325214..ba2ee8f 100644
--- a/packages/daemon/src/bridge.ts
+++ b/packages/daemon/src/bridge.ts
@@ -1150,7 +1150,7 @@ export class DotBridge {
this.broadcast({
type: "activity",
messageId: this.assistantId,
- activity: { id, ...describeTool(String(event.toolName ?? ""), event.args), status },
+ activity: { id, ...describeTool(String(event.toolName ?? ""), event.args, status), status },
});
}
diff --git a/packages/daemon/src/conversations.ts b/packages/daemon/src/conversations.ts
index 160a471..476da5e 100644
--- a/packages/daemon/src/conversations.ts
+++ b/packages/daemon/src/conversations.ts
@@ -206,8 +206,7 @@ function activitiesOf(message: AgentMessage, failed: Set<string>): Activity[] {
const b = block as { type?: string; id?: string; name?: string; arguments?: unknown };
if (b?.type !== "toolCall" || typeof b.name !== "string") return [];
const id = b.id ?? b.name;
- return [
- { id, ...describeTool(b.name, b.arguments), status: failed.has(id) ? "failed" : "done" } as Activity,
- ];
+ const status = failed.has(id) ? "failed" : "done";
+ return [{ id, ...describeTool(b.name, b.arguments, status), status } as Activity];
});
}
diff --git a/packages/daemon/src/presentation.ts b/packages/daemon/src/presentation.ts
index ef98dca..086cfe8 100644
--- a/packages/daemon/src/presentation.ts
+++ b/packages/daemon/src/presentation.ts
@@ -1,30 +1,59 @@
import { basename } from "node:path";
import type { ActivityKind } from "@gentle-dot/protocol";
+/** The life cycle of one tool call, as the activity list shows it. */
+export type ActivityStatus = "running" | "done" | "failed";
+
+/** The titles of one tool family: while it runs, once it succeeded, once it failed. */
+type Tense = readonly [running: string, done: string, failed: string];
+
/**
* Turns an internal tool call into a neutral activity. Tool names never reach
- * the user; only the kind and a short human title do.
+ * the user; only the kind and a short human title do. The title matches the
+ * call's status, so a finished or failed call never shows as still running.
*/
-export function describeTool(toolName: string, args: unknown): { kind: ActivityKind; title: string } {
+export function describeTool(
+ toolName: string,
+ args: unknown,
+ status: ActivityStatus = "running",
+): { kind: ActivityKind; title: string } {
const name = toolName.toLowerCase();
const file = fileOf(args);
- if (name === "read") return { kind: "read", title: file ? `Reading ${file}` : "Reading a file" };
+ const titled = (kind: ActivityKind, titles: Tense): { kind: ActivityKind; title: string } => ({
+ kind,
+ title: status === "running" ? titles[0] : status === "done" ? titles[1] : titles[2],
+ });
+ if (name === "read")
+ return titled(
+ "read",
+ file
+ ? ([`Reading ${file}`, `Read ${file}`, `Could not read ${file}`] as const)
+ : (["Reading a file", "Read a file", "Could not read a file"] as const),
+ );
if (name === "write" || name === "edit")
- return { kind: "edit", title: file ? `Editing ${file}` : "Editing a file" };
- if (name === "bash") return { kind: "run", title: "Running a command" };
- if (name.startsWith("mem_save") || name === "mem_update" || name === "mem_session_summary") {
- return { kind: "memory", title: "Saving a note" };
- }
- if (name.startsWith("mem_")) return { kind: "memory", title: "Checking my notes" };
- if (name.startsWith("subagent_")) return { kind: "delegate", title: "Asking a helper" };
- if (["web_search", "fetch_content", "get_search_content", "source_check"].includes(name)) {
- return { kind: "search", title: "Looking things up online" };
- }
- if (["grep", "find", "ls"].includes(name) || name.startsWith("codegraph")) {
- return { kind: "search", title: "Searching files" };
- }
- if (name.startsWith("ask_user")) return { kind: "other", title: "Asking you" };
- return { kind: "other", title: "Working" };
+ return titled(
+ "edit",
+ file
+ ? ([`Editing ${file}`, `Edited ${file}`, `Could not edit ${file}`] as const)
+ : (["Editing a file", "Edited a file", "Could not edit a file"] as const),
+ );
+ if (name === "bash") return titled("run", ["Running a command", "Ran a command", "A command failed"]);
+ if (name.startsWith("mem_save") || name === "mem_update" || name === "mem_session_summary")
+ return titled("memory", ["Saving a note", "Saved a note", "Could not save a note"]);
+ if (name.startsWith("mem_"))
+ return titled("memory", ["Checking my notes", "Checked my notes", "Could not check my notes"]);
+ if (name.startsWith("subagent_"))
+ return titled("delegate", ["Asking a helper", "Asked a helper", "Could not ask a helper"]);
+ if (["web_search", "fetch_content", "get_search_content", "source_check"].includes(name))
+ return titled("search", [
+ "Looking things up online",
+ "Looked things up online",
+ "Could not look things up online",
+ ]);
+ if (["grep", "find", "ls"].includes(name) || name.startsWith("codegraph"))
+ return titled("search", ["Searching files", "Searched files", "Could not search files"]);
+ if (name.startsWith("ask_user")) return titled("other", ["Asking you", "Asked you", "Could not ask you"]);
+ return titled("other", ["Working", "Finished", "Failed"]);
}
function fileOf(args: unknown): string | undefined {
diff --git a/packages/daemon/test/presentation.test.ts b/packages/daemon/test/presentation.test.ts
new file mode 100644
index 0000000..4754a39
--- /dev/null
+++ b/packages/daemon/test/presentation.test.ts
@@ -0,0 +1,62 @@
+import { describe, expect, it } from "vitest";
+import { describeTool } from "../src/presentation.ts";
+
+describe("describeTool", () => {
+ it("titles a bash call by its status", () => {
+ expect(describeTool("bash", {}, "running")).toEqual({ kind: "run", title: "Running a command" });
+ expect(describeTool("bash", {}, "done")).toEqual({ kind: "run", title: "Ran a command" });
+ expect(describeTool("bash", {}, "failed")).toEqual({ kind: "run", title: "A command failed" });
+ });
+
+ it("titles a read call with its file and tense", () => {
+ expect(describeTool("read", { path: "/tmp/a.md" }, "running")).toEqual({
+ kind: "read",
+ title: "Reading a.md",
+ });
+ expect(describeTool("read", { path: "/tmp/a.md" }, "done")).toEqual({ kind: "read", title: "Read a.md" });
+ expect(describeTool("read", { path: "/tmp/a.md" }, "failed")).toEqual({
+ kind: "read",
+ title: "Could not read a.md",
+ });
+ });
+
+ it("titles a read call without a file", () => {
+ expect(describeTool("read", {}, "done")).toEqual({ kind: "read", title: "Read a file" });
+ });
+
+ it("titles an edit call with its file and tense", () => {
+ expect(describeTool("edit", { path: "/tmp/a.ts" }, "running")).toEqual({
+ kind: "edit",
+ title: "Editing a.ts",
+ });
+ expect(describeTool("write", { path: "/tmp/a.ts" }, "done")).toEqual({
+ kind: "edit",
+ title: "Edited a.ts",
+ });
+ expect(describeTool("edit", { path: "/tmp/a.ts" }, "failed")).toEqual({
+ kind: "edit",
+ title: "Could not edit a.ts",
+ });
+ });
+
+ it("titles memory, delegate, search, and ask calls by their status", () => {
+ expect(describeTool("mem_save", {}, "done").title).toBe("Saved a note");
+ expect(describeTool("mem_search", {}, "done").title).toBe("Checked my notes");
+ expect(describeTool("mem_save", {}, "failed").title).toBe("Could not save a note");
+ expect(describeTool("subagent_run", {}, "done").title).toBe("Asked a helper");
+ expect(describeTool("web_search", {}, "done").title).toBe("Looked things up online");
+ expect(describeTool("grep", { pattern: "x" }, "done").title).toBe("Searched files");
+ expect(describeTool("codegraph_query", {}, "failed").title).toBe("Could not search files");
+ expect(describeTool("ask_user_choice", {}, "done").title).toBe("Asked you");
+ });
+
+ it("defaults to the running tense for callers that have no status yet", () => {
+ expect(describeTool("bash", {})).toEqual({ kind: "run", title: "Running a command" });
+ });
+
+ it("titles unknown tools in all three tenses", () => {
+ expect(describeTool("mystery", {}, "running").title).toBe("Working");
+ expect(describeTool("mystery", {}, "done").title).toBe("Finished");
+ expect(describeTool("mystery", {}, "failed").title).toBe("Failed");
+ });
+});
diff --git a/packages/ui/test/components.test.tsx b/packages/ui/test/components.test.tsx
index c3186af..aecf873 100644
--- a/packages/ui/test/components.test.tsx
+++ b/packages/ui/test/components.test.tsx
@@ -110,9 +110,9 @@ describe("MessageList", () => {
text: "All **good**",
streaming: false,
activities: [
- { id: "a", kind: "read", title: "Reading a.md", status: "done" },
- { id: "b", kind: "read", title: "Reading b.md", status: "done" },
- { id: "c", kind: "run", title: "Running a command", status: "failed" },
+ { id: "a", kind: "read", title: "Read a.md", status: "done" },
+ { id: "b", kind: "read", title: "Read b.md", status: "done" },
+ { id: "c", kind: "run", title: "A command failed", status: "failed" },
],
},
]}
@@ -121,7 +121,8 @@ describe("MessageList", () => {
expect(screen.getByText("good").tagName).toBe("STRONG");
const summary = screen.getByRole("button", { name: /Read 2 files · Ran 1 command/ });
await userEvent.click(summary);
- expect(screen.getByText("Reading b.md")).toBeInTheDocument();
+ expect(screen.getByText("Read b.md")).toBeInTheDocument();
+ expect(screen.getByText("A command failed")).toBeInTheDocument();
});
});