Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat(daemon,shared,community): canonical tool_call audit shape — `{name, target?}`
Gus1aa476a49774
diff --git a/AGENTS.md b/AGENTS.mdindex 68562d3ce..ce0c794bf 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -14,6 +14,8 @@ Alook's main purpose is to make the cli agent always on, and give it a email add- run `pnpm typecheck`, `pnpm test` as the final check when you think the code is ready.- service must be STATELESS! All the state must be in DB or local, never put important states in memory.- scope the queries before, not check the ownership after. don't query data then check if the data belongs to a workspace, use workspace id ahead to query the data.+- respect others' works, don't reset any other git changes just because it's not done by you, others may working at the same time, never revert anything without asking the user.+ - don't stash others' works, you can wait, but stash others' work will cause many problems.## Release — Unified Version BumpAll workspace packages share one version. Use `pnpm bump` to release:@@ -126,4 +128,4 @@ Always use the `thin-scrollbar` class alongside `overflow-y-auto` or `overflow-x```## UIUX-read @DESIGN.md\ No newline at end of file+read @DESIGN.mddiff --git a/src/daemon/src/daemon/createDaemon.ts b/src/daemon/src/daemon/createDaemon.tsindex 315956708..523080ba5 100644--- a/src/daemon/src/daemon/createDaemon.ts+++ b/src/daemon/src/daemon/createDaemon.ts@@ -181,7 +181,7 @@ export async function createDaemon(opts: CreateDaemonOptions): Promise<RunningDaagentId: string,event:| { kind: "cli_invocation"; payload: { subcommand: string } }- | { kind: "tool_call"; payload: { name: string; command?: string } }+ | { kind: "tool_call"; payload: { name: string; target?: string } }| { kind: "thinking"; payload: { text: string; truncated: boolean; chars: number } },context?: { sessionId?: string | null; launchId?: string | null }) => {diff --git a/src/daemon/src/manager/managerRuntime.test.ts b/src/daemon/src/manager/managerRuntime.test.tsindex cbb00e773..3b83e8b64 100644--- a/src/daemon/src/manager/managerRuntime.test.ts+++ b/src/daemon/src/manager/managerRuntime.test.ts@@ -2,8 +2,10 @@ import { describe, it, expect, vi } from "vitest";import {AgentProcessManager,truncateThinking,- extractBashCommandSummary,- isAlookShellCommand,+ canonicalToolName,+ extractToolAudit,+ isAlookShellInvocation,+ truncateTargetToCodeUnits,type ManagedSession,type SessionFactory,} from "./managerRuntime.js";@@ -781,7 +783,6 @@ describe("AgentProcessManager — bot audit event emission", () => {const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });- // A reasoning block buffers until a non-thinking event flushes it.session.fire("runtime_event", { kind: "thinking", text: "think about it" });expect(onBotAuditEvent).not.toHaveBeenCalled();session.fire("runtime_event", { kind: "turn_end" });@@ -805,13 +806,11 @@ describe("AgentProcessManager — bot audit event emission", () => {const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });- // Delta-streaming drivers (codex/pi) emit token fragments + empty markers.session.fire("runtime_event", { kind: "thinking", text: "" });session.fire("runtime_event", { kind: "thinking", text: "let me " });session.fire("runtime_event", { kind: "thinking", text: "count" });session.fire("runtime_event", { kind: "thinking", text: "" });- // Flush on the following tool_call.- session.fire("runtime_event", { kind: "tool_call", name: "Read", input: {} });+ session.fire("runtime_event", { kind: "tool_call", name: "Read", input: { file_path: "/x" } });const thinkingCalls = onBotAuditEvent.mock.calls.filter(([, ev]) => (ev as { kind?: string })?.kind === "thinking"@@ -825,16 +824,16 @@ describe("AgentProcessManager — bot audit event emission", () => {);});- it("emits `tool_call` with name only (strips input)", () => {+ it("emits `tool_call` with canonical name + resolved target", () => {const onBotAuditEvent = vi.fn();const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });- session.fire("runtime_event", { kind: "tool_call", name: "Read", input: { path: "/etc/passwd" } });+ session.fire("runtime_event", { kind: "tool_call", name: "Read", input: { file_path: "/etc/passwd" } });expect(onBotAuditEvent).toHaveBeenCalledWith("a1",- { kind: "tool_call", payload: { name: "Read" } },+ { kind: "tool_call", payload: { name: "read", target: "/etc/passwd" } },expect.objectContaining({ sessionId: null, launchId: null }));});@@ -844,18 +843,17 @@ describe("AgentProcessManager — bot audit event emission", () => {const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });- // Learn the runtime session id from the handshake.session.fire("runtime_event", { kind: "session_init", sessionId: "s_abc" });- session.fire("runtime_event", { kind: "tool_call", name: "Read", input: {} });+ session.fire("runtime_event", { kind: "tool_call", name: "Read", input: { file_path: "/x" } });expect(onBotAuditEvent).toHaveBeenCalledWith("a1",- { kind: "tool_call", payload: { name: "Read" } },+ { kind: "tool_call", payload: { name: "read", target: "/x" } },{ sessionId: "s_abc", launchId: null });});- it("DROPS `Bash` tool_call whose command is `alook <sub>` (proxy is authoritative)", () => {+ it("DROPS bash-family tool_call whose command is `alook <sub>` for BOTH capitalized and lowercase names", () => {const onBotAuditEvent = vi.fn();const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });@@ -867,7 +865,7 @@ describe("AgentProcessManager — bot audit event emission", () => {});session.fire("runtime_event", {kind: "tool_call",- name: "Bash",+ name: "bash",input: { command: " alook message send @gus hi" },});session.fire("runtime_event", {@@ -875,6 +873,11 @@ describe("AgentProcessManager — bot audit event emission", () => {name: "Bash",input: { command: "alook" },});+ session.fire("runtime_event", {+ kind: "tool_call",+ name: "shell",+ input: { command: "alook inbox pull" },+ });const bashCalls = onBotAuditEvent.mock.calls.filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call"@@ -882,39 +885,28 @@ describe("AgentProcessManager — bot audit event emission", () => {expect(bashCalls).toHaveLength(0);});- it("EMITS `Bash` tool_call for non-alook shell work (rm, sed, git, echo)", () => {+ it("EMITS bash tool_call for non-alook shell work with canonical `bash` name + target", () => {const onBotAuditEvent = vi.fn();const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });- session.fire("runtime_event", {- kind: "tool_call",- name: "Bash",- input: { command: "rm -rf /tmp/xxx" },- });- session.fire("runtime_event", {- kind: "tool_call",- name: "Bash",- input: { command: "sed -i '' '/pattern/d' todo.md" },- });- session.fire("runtime_event", {- kind: "tool_call",- name: "Bash",- input: { command: "echo -n > todo.md" },- });+ session.fire("runtime_event", { kind: "tool_call", name: "Bash", input: { command: "rm -rf /tmp/xxx" } });+ session.fire("runtime_event", { kind: "tool_call", name: "bash", input: { command: "sed -i '' '/pattern/d' todo.md" } });+ session.fire("runtime_event", { kind: "tool_call", name: "Bash", input: { command: "echo -n > todo.md" } });const bashCalls = onBotAuditEvent.mock.calls.filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call");expect(bashCalls).toHaveLength(3);- expect((bashCalls[0]![1] as { payload: { command?: string } }).payload.command).toBe("rm -rf /tmp/xxx");- expect((bashCalls[1]![1] as { payload: { command?: string } }).payload.command).toBe(- "sed -i '' '/pattern/d' todo.md",- );- expect((bashCalls[2]![1] as { payload: { command?: string } }).payload.command).toBe("echo -n > todo.md");+ for (const call of bashCalls) {+ expect((call![1] as { payload: { name: string } }).payload.name).toBe("bash");+ }+ expect((bashCalls[0]![1] as { payload: { target?: string } }).payload.target).toBe("rm -rf /tmp/xxx");+ expect((bashCalls[1]![1] as { payload: { target?: string } }).payload.target).toBe("sed -i '' '/pattern/d' todo.md");+ expect((bashCalls[2]![1] as { payload: { target?: string } }).payload.target).toBe("echo -n > todo.md");});- it("truncates a long Bash command to <= 200 chars with an ellipsis", () => {+ it("truncates a long Bash target to <= 200 chars with an ellipsis", () => {const onBotAuditEvent = vi.fn();const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });@@ -925,12 +917,12 @@ describe("AgentProcessManager — bot audit event emission", () => {const [call] = onBotAuditEvent.mock.calls.filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call",);- const cmd = (call![1] as { payload: { command?: string } }).payload.command!;- expect([...cmd].length).toBeLessThanOrEqual(200);- expect(cmd.endsWith("…")).toBe(true);+ const target = (call![1] as { payload: { target?: string } }).payload.target!;+ expect(target.length).toBeLessThanOrEqual(200);+ expect(target.endsWith("…")).toBe(true);});- it("emits a `Bash` tool_call without `command` when input has no command string", () => {+ it("emits bash tool_call without `target` when input has no command string", () => {const onBotAuditEvent = vi.fn();const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });@@ -940,22 +932,30 @@ describe("AgentProcessManager — bot audit event emission", () => {const [call] = onBotAuditEvent.mock.calls.filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call",);- expect((call![1] as { payload: unknown }).payload).toEqual({ name: "Bash" });+ expect((call![1] as { payload: unknown }).payload).toEqual({ name: "bash" });});- it("emits non-Bash tool_calls (Edit, Write, MultiEdit, Grep, Glob) with name only", () => {+ it("canonicalizes tool names on tool_calls (Edit → edit, MultiEdit → edit, Grep → grep, Glob → glob) with resolved target", () => {const onBotAuditEvent = vi.fn();const { mgr, session } = makeManager({ onBotAuditEvent });mgr.deliver("a1", { seq: 1, text: "hello" });- for (const name of ["Edit", "Write", "MultiEdit", "Grep", "Glob"]) {- session.fire("runtime_event", { kind: "tool_call", name, input: { path: "/x" } });- }+ session.fire("runtime_event", { kind: "tool_call", name: "Edit", input: { file_path: "/x" } });+ session.fire("runtime_event", { kind: "tool_call", name: "Write", input: { file_path: "/y" } });+ session.fire("runtime_event", { kind: "tool_call", name: "MultiEdit", input: { file_path: "/z" } });+ session.fire("runtime_event", { kind: "tool_call", name: "Grep", input: { pattern: "TODO" } });+ session.fire("runtime_event", { kind: "tool_call", name: "Glob", input: { pattern: "**/*.ts" } });- const names = onBotAuditEvent.mock.calls+ const payloads = onBotAuditEvent.mock.calls.filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call")- .map(([, ev]) => (ev as { payload: { name: string } }).payload.name);- expect(names).toEqual(["Edit", "Write", "MultiEdit", "Grep", "Glob"]);+ .map(([, ev]) => (ev as { payload: { name: string; target?: string } }).payload);+ expect(payloads).toEqual([+ { name: "edit", target: "/x" },+ { name: "write", target: "/y" },+ { name: "edit", target: "/z" },+ { name: "grep", target: "TODO" },+ { name: "glob", target: "**/*.ts" },+ ]);});it("does NOT emit for non-audit event kinds (session_init, text, turn_end)", () => {@@ -969,58 +969,388 @@ describe("AgentProcessManager — bot audit event emission", () => {expect(onBotAuditEvent).not.toHaveBeenCalled();});++ it("payload never contains extra fields beyond {name, target?} (T11)", () => {+ const onBotAuditEvent = vi.fn();+ const { mgr, session } = makeManager({ onBotAuditEvent });+ mgr.deliver("a1", { seq: 1, text: "hello" });++ session.fire("runtime_event", { kind: "tool_call", name: "Edit", input: { file_path: "/x", oldText: "a", newText: "b", edits: [] } });+ session.fire("runtime_event", { kind: "tool_call", name: "Bash", input: { command: "rm x", stdin: "secret" } });++ const payloads = onBotAuditEvent.mock.calls+ .filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call")+ .map(([, ev]) => (ev as { payload: Record<string, unknown> }).payload);+ for (const p of payloads) {+ const keys = Object.keys(p);+ for (const k of keys) expect(["name", "target"]).toContain(k);+ }+ });});-describe("extractBashCommandSummary", () => {- it("returns the command verbatim when it fits", () => {- expect(extractBashCommandSummary({ command: "rm -rf tmp" })).toBe("rm -rf tmp");+describe("canonicalToolName", () => {+ it("canonicalizes bash/shell to bash (case-insensitive)", () => {+ expect(canonicalToolName("Bash")).toBe("bash");+ expect(canonicalToolName("bash")).toBe("bash");+ expect(canonicalToolName("BASH")).toBe("bash");+ expect(canonicalToolName("shell")).toBe("bash");});+ it("canonicalizes file-target tools", () => {+ expect(canonicalToolName("Read")).toBe("read");+ expect(canonicalToolName("read")).toBe("read");+ expect(canonicalToolName("Edit")).toBe("edit");+ expect(canonicalToolName("MultiEdit")).toBe("edit");+ expect(canonicalToolName("file_change")).toBe("edit");+ expect(canonicalToolName("Write")).toBe("write");+ expect(canonicalToolName("LS")).toBe("ls");+ expect(canonicalToolName("NotebookEdit")).toBe("notebook_edit");+ });+ it("canonicalizes pattern tools", () => {+ expect(canonicalToolName("Grep")).toBe("grep");+ expect(canonicalToolName("Glob")).toBe("glob");+ expect(canonicalToolName("Find")).toBe("find");+ });+ it("canonicalizes web + todo tools", () => {+ expect(canonicalToolName("WebSearch")).toBe("web_search");+ expect(canonicalToolName("web_search")).toBe("web_search");+ expect(canonicalToolName("WebFetch")).toBe("web_fetch");+ expect(canonicalToolName("TodoWrite")).toBe("todo_write");+ });+ it("falls through to lowercase for unknown names", () => {+ expect(canonicalToolName("mcp_search")).toBe("mcp_search");+ expect(canonicalToolName("Frobnicate")).toBe("frobnicate");+ expect(canonicalToolName("collab_tool_call")).toBe("collab_tool_call");+ });+});- it("returns the first non-empty line", () => {- expect(extractBashCommandSummary({ command: "\n\n git commit -m 'wip' \nfoo" })).toBe(- "git commit -m 'wip'",- );+describe("extractToolAudit — shell class", () => {+ it("Anthropic Bash + non-alook command yields {name: 'bash', target, suppressed: false}", () => {+ expect(extractToolAudit("Bash", { command: "rm -rf tmp" })).toEqual({+ name: "bash",+ target: "rm -rf tmp",+ suppressed: false,+ });+ });+ it("pi lowercase bash + non-alook command yields the same shape", () => {+ expect(extractToolAudit("bash", { command: "sed -i '' '/x/d' todo.md" })).toEqual({+ name: "bash",+ target: "sed -i '' '/x/d' todo.md",+ suppressed: false,+ });+ });+ it("suppresses alook invocations for capitalized Bash", () => {+ expect(extractToolAudit("Bash", { command: "alook inbox pull" }).suppressed).toBe(true);+ });+ it("suppresses alook invocations for lowercase bash (pi)", () => {+ expect(extractToolAudit("bash", { command: "alook" }).suppressed).toBe(true);+ });+ it("suppresses even with leading whitespace (raw command trimmed for the check)", () => {+ expect(extractToolAudit("Bash", { command: " alook message send" }).suppressed).toBe(true);+ });+ it("codex shell (string command) — driver already unwrapped params.item", () => {+ expect(extractToolAudit("shell", { command: "pnpm test" })).toEqual({+ name: "bash",+ target: "pnpm test",+ suppressed: false,+ });+ });+ it("codex shell (array command) — joined with spaces, noisy-but-honest form", () => {+ expect(extractToolAudit("shell", { command: ["bash", "-lc", "rm -rf tmp"] })).toEqual({+ name: "bash",+ target: "bash -lc rm -rf tmp",+ suppressed: false,+ });+ });+ it("codex shell array wrapping `alook …` inside `bash -lc` does NOT suppress — outer shell is real work", () => {+ const out = extractToolAudit("shell", { command: ["bash", "-lc", "alook inbox pull"] });+ expect(out.suppressed).toBe(false);+ expect(out.name).toBe("bash");+ expect(out.target).toBe("bash -lc alook inbox pull");+ });+});++describe("extractToolAudit — file-target class", () => {+ it("Anthropic Read → file_path", () => {+ expect(extractToolAudit("Read", { file_path: "/etc/passwd" })).toEqual({+ name: "read",+ target: "/etc/passwd",+ suppressed: false,+ });+ });+ it("pi read → path", () => {+ expect(extractToolAudit("read", { path: "AGENTS.md" })).toEqual({+ name: "read",+ target: "AGENTS.md",+ suppressed: false,+ });+ });+ it("Edit picks file_path, ignoring other keys", () => {+ expect(extractToolAudit("Edit", { file_path: "src/foo.ts", oldText: "x", newText: "y" })).toEqual({+ name: "edit",+ target: "src/foo.ts",+ suppressed: false,+ });+ });+ it("pi edit → path", () => {+ expect(extractToolAudit("edit", { path: "plans/x.md", edits: [] })).toEqual({+ name: "edit",+ target: "plans/x.md",+ suppressed: false,+ });+ });+ it("Write / pi write → file_path / path", () => {+ expect(extractToolAudit("Write", { file_path: "x.md", content: "..." }).target).toBe("x.md");+ expect(extractToolAudit("write", { path: "x.md", content: "..." }).target).toBe("x.md");+ });+ it("MultiEdit → edit + file_path (semantic collapse)", () => {+ expect(extractToolAudit("MultiEdit", { file_path: "x.ts", edits: [] })).toEqual({+ name: "edit",+ target: "x.ts",+ suppressed: false,+ });+ });+ it("NotebookEdit → notebook_path", () => {+ expect(extractToolAudit("NotebookEdit", { notebook_path: "nb.ipynb" })).toEqual({+ name: "notebook_edit",+ target: "nb.ipynb",+ suppressed: false,+ });+ });+ it("LS → path", () => {+ expect(extractToolAudit("LS", { path: "src/" })).toEqual({+ name: "ls",+ target: "src/",+ suppressed: false,+ });+ });+ it("codex file_change → edit + path (already-unwrapped params.item)", () => {+ expect(extractToolAudit("file_change", { path: "src/x.ts" })).toEqual({+ name: "edit",+ target: "src/x.ts",+ suppressed: false,+ });});+});- it("handles codex-shaped `input.item.command` string", () => {- expect(extractBashCommandSummary({ item: { command: "ls -la" } })).toBe("ls -la");+describe("extractToolAudit — pattern class", () => {+ it("Grep with pattern + path picks pattern", () => {+ expect(extractToolAudit("Grep", { pattern: "TODO", path: "src/" }).target).toBe("TODO");});+ it("pi grep with pattern only", () => {+ expect(extractToolAudit("grep", { pattern: "TODO" }).target).toBe("TODO");+ });+ it("Glob picks pattern", () => {+ expect(extractToolAudit("Glob", { pattern: "**/*.tsx" }).target).toBe("**/*.tsx");+ });+ it("find picks pattern", () => {+ expect(extractToolAudit("find", { pattern: "*.ts", path: "src" }).target).toBe("*.ts");+ });+ it("grep falls back to path when no pattern is set", () => {+ expect(extractToolAudit("grep", { path: "src" }).target).toBe("src");+ });+});- it("handles codex-shaped `input.item.command` array", () => {- expect(extractBashCommandSummary({ item: { command: ["bash", "-lc", "echo hi"] } })).toBe(- "bash -lc echo hi",- );+describe("extractToolAudit — fallthrough / MCP / web", () => {+ it("WebFetch → url", () => {+ expect(extractToolAudit("WebFetch", { url: "https://example.com" })).toEqual({+ name: "web_fetch",+ target: "https://example.com",+ suppressed: false,+ });});+ it("mcp_search stays as mcp_search + query target", () => {+ expect(extractToolAudit("mcp_search", { query: "foo" })).toEqual({+ name: "mcp_search",+ target: "foo",+ suppressed: false,+ });+ });+ it("web_search → query", () => {+ expect(extractToolAudit("web_search", { query: "cats" })).toEqual({+ name: "web_search",+ target: "cats",+ suppressed: false,+ });+ });+ it("collab_tool_call → name (from input.name)", () => {+ expect(extractToolAudit("collab_tool_call", { name: "x" }).target).toBe("x");+ });+ it("TodoWrite → no target", () => {+ expect(extractToolAudit("TodoWrite", { todos: [] })).toEqual({+ name: "todo_write",+ suppressed: false,+ });+ });+ it("Unknown tool falls through as lowercased name + no target", () => {+ expect(extractToolAudit("Frobnicate", {})).toEqual({+ name: "frobnicate",+ suppressed: false,+ });+ });+});- it("returns undefined when no command string is present", () => {- expect(extractBashCommandSummary({})).toBeUndefined();- expect(extractBashCommandSummary(null)).toBeUndefined();- expect(extractBashCommandSummary({ item: {} })).toBeUndefined();+describe("extractToolAudit — non-object input guard", () => {+ it("null / undefined / string / number / array — all return no target without throwing", () => {+ expect(extractToolAudit("Bash", null)).toEqual({ name: "bash", suppressed: false });+ expect(extractToolAudit("Bash", undefined)).toEqual({ name: "bash", suppressed: false });+ expect(extractToolAudit("Bash", "raw string")).toEqual({ name: "bash", suppressed: false });+ expect(extractToolAudit("Bash", 42)).toEqual({ name: "bash", suppressed: false });+ expect(extractToolAudit("Bash", ["a", "b"])).toEqual({ name: "bash", suppressed: false });+ });+ it("copilot stringified-JSON recovery: input is a JSON string that decodes to a record", () => {+ expect(extractToolAudit("Bash", '{"command":"rm -rf tmp"}')).toEqual({+ name: "bash",+ target: "rm -rf tmp",+ suppressed: false,+ });+ });+ it("invalid JSON string — no throw, returns no target", () => {+ expect(extractToolAudit("Bash", "not json{")).toEqual({ name: "bash", suppressed: false });+ });+ it("JSON string that decodes to a non-object — no throw, returns no target", () => {+ expect(extractToolAudit("Bash", "42")).toEqual({ name: "bash", suppressed: false });+ expect(extractToolAudit("Bash", '["a","b"]')).toEqual({ name: "bash", suppressed: false });});+});- it("truncates to <=200 chars with an ellipsis", () => {- const long = "echo " + "y".repeat(400);- const out = extractBashCommandSummary({ command: long })!;- expect([...out].length).toBeLessThanOrEqual(200);+describe("truncateTargetToCodeUnits", () => {+ it("passes short strings through unchanged", () => {+ expect(truncateTargetToCodeUnits("hello")).toBe("hello");+ });+ it("truncates a 300-unit ASCII string to <=200 units + ellipsis", () => {+ const out = truncateTargetToCodeUnits("a".repeat(300));+ expect(out.length).toBeLessThanOrEqual(200);+ expect(out.endsWith("…")).toBe(true);+ });+ it("emoji-heavy: never emits a lone surrogate + round-trips clean UTF-8", () => {+ const emoji = "😀";+ const s = emoji.repeat(200);+ const out = truncateTargetToCodeUnits(s);+ expect(out.length).toBeLessThanOrEqual(200);expect(out.endsWith("…")).toBe(true);+ expect(Buffer.from(out, "utf8").toString("utf8")).toBe(out);});});-describe("isAlookShellCommand", () => {+describe("isAlookShellInvocation", () => {it("matches `alook <sub>` and bare `alook`", () => {- expect(isAlookShellCommand("alook")).toBe(true);- expect(isAlookShellCommand("alook inbox pull")).toBe(true);- expect(isAlookShellCommand(" alook message send")).toBe(true);+ expect(isAlookShellInvocation("alook")).toBe(true);+ expect(isAlookShellInvocation("alook inbox pull")).toBe(true);+ expect(isAlookShellInvocation(" alook message send")).toBe(true);});-it("does NOT match commands that merely mention alook", () => {- expect(isAlookShellCommand("rm alook.log")).toBe(false);- expect(isAlookShellCommand("echo alook")).toBe(false);- expect(isAlookShellCommand("alookalike")).toBe(false);+ expect(isAlookShellInvocation("rm alook.log")).toBe(false);+ expect(isAlookShellInvocation("echo alook")).toBe(false);+ expect(isAlookShellInvocation("alookalike")).toBe(false);});-it("returns false for missing input", () => {- expect(isAlookShellCommand(undefined)).toBe(false);- expect(isAlookShellCommand("")).toBe(false);+ expect(isAlookShellInvocation(undefined)).toBe(false);+ expect(isAlookShellInvocation("")).toBe(false);+ });+});++describe("extractToolAudit — driver coverage matrix", () => {+ const cases: Array<{ driver: string; rawName: string; rawInput: unknown; expected: { name: string; target?: string; suppressed: boolean } }> = [+ { driver: "claude", rawName: "Bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "claude", rawName: "Read", rawInput: { file_path: "/x" }, expected: { name: "read", target: "/x", suppressed: false } },+ { driver: "claude", rawName: "Edit", rawInput: { file_path: "/x" }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "claude", rawName: "MultiEdit", rawInput: { file_path: "/y" }, expected: { name: "edit", target: "/y", suppressed: false } },+ { driver: "claude", rawName: "Write", rawInput: { file_path: "/x" }, expected: { name: "write", target: "/x", suppressed: false } },+ { driver: "claude", rawName: "Grep", rawInput: { pattern: "TODO" }, expected: { name: "grep", target: "TODO", suppressed: false } },+ { driver: "claude", rawName: "Glob", rawInput: { pattern: "**/*" }, expected: { name: "glob", target: "**/*", suppressed: false } },+ { driver: "claude", rawName: "LS", rawInput: { path: "/src" }, expected: { name: "ls", target: "/src", suppressed: false } },+ { driver: "claude", rawName: "NotebookEdit", rawInput: { notebook_path: "nb.ipynb" }, expected: { name: "notebook_edit", target: "nb.ipynb", suppressed: false } },+ { driver: "claude", rawName: "WebSearch", rawInput: { query: "cats" }, expected: { name: "web_search", target: "cats", suppressed: false } },+ { driver: "claude", rawName: "WebFetch", rawInput: { url: "https://x" }, expected: { name: "web_fetch", target: "https://x", suppressed: false } },+ { driver: "claude", rawName: "TodoWrite", rawInput: { todos: [] }, expected: { name: "todo_write", suppressed: false } },++ { driver: "cursor", rawName: "Bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },++ { driver: "pi", rawName: "bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "pi", rawName: "read", rawInput: { path: "/x" }, expected: { name: "read", target: "/x", suppressed: false } },+ { driver: "pi", rawName: "edit", rawInput: { path: "/x", edits: [] }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "pi", rawName: "write", rawInput: { path: "/x", content: "" }, expected: { name: "write", target: "/x", suppressed: false } },+ { driver: "pi", rawName: "grep", rawInput: { pattern: "TODO" }, expected: { name: "grep", target: "TODO", suppressed: false } },+ { driver: "pi", rawName: "find", rawInput: { pattern: "*.ts" }, expected: { name: "find", target: "*.ts", suppressed: false } },+ { driver: "pi", rawName: "ls", rawInput: { path: "/src" }, expected: { name: "ls", target: "/src", suppressed: false } },++ { driver: "codex", rawName: "shell", rawInput: { command: "pnpm test" }, expected: { name: "bash", target: "pnpm test", suppressed: false } },+ { driver: "codex", rawName: "shell", rawInput: { command: ["bash", "-lc", "rm tmp"] }, expected: { name: "bash", target: "bash -lc rm tmp", suppressed: false } },+ { driver: "codex", rawName: "file_change", rawInput: { path: "/x" }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "codex", rawName: "web_search", rawInput: { query: "cats" }, expected: { name: "web_search", target: "cats", suppressed: false } },+ { driver: "codex", rawName: "mcp_search", rawInput: { query: "foo" }, expected: { name: "mcp_search", target: "foo", suppressed: false } },+ { driver: "codex", rawName: "collab_tool_call", rawInput: { name: "x" }, expected: { name: "collab_tool_call", target: "x", suppressed: false } },++ { driver: "gemini", rawName: "bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "gemini", rawName: "read", rawInput: { path: "/x" }, expected: { name: "read", target: "/x", suppressed: false } },+ { driver: "gemini", rawName: "edit", rawInput: { file_path: "/x" }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "gemini", rawName: "write", rawInput: { path: "/x" }, expected: { name: "write", target: "/x", suppressed: false } },+ { driver: "gemini", rawName: "grep", rawInput: { pattern: "TODO" }, expected: { name: "grep", target: "TODO", suppressed: false } },++ { driver: "kimi", rawName: "bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "kimi", rawName: "read", rawInput: { path: "/x" }, expected: { name: "read", target: "/x", suppressed: false } },+ { driver: "kimi", rawName: "edit", rawInput: { file_path: "/x" }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "kimi", rawName: "write", rawInput: { path: "/x" }, expected: { name: "write", target: "/x", suppressed: false } },+ { driver: "kimi", rawName: "grep", rawInput: { pattern: "TODO" }, expected: { name: "grep", target: "TODO", suppressed: false } },++ { driver: "opencode", rawName: "bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "opencode", rawName: "read", rawInput: { file_path: "/x" }, expected: { name: "read", target: "/x", suppressed: false } },+ { driver: "opencode", rawName: "edit", rawInput: { file_path: "/x" }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "opencode", rawName: "write", rawInput: { file_path: "/x" }, expected: { name: "write", target: "/x", suppressed: false } },+ { driver: "opencode", rawName: "grep", rawInput: { pattern: "TODO" }, expected: { name: "grep", target: "TODO", suppressed: false } },++ { driver: "copilot", rawName: "bash", rawInput: '{"command":"rm tmp"}', expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "copilot", rawName: "bash", rawInput: { command: "rm tmp" }, expected: { name: "bash", target: "rm tmp", suppressed: false } },+ { driver: "copilot", rawName: "read", rawInput: { file_path: "/x" }, expected: { name: "read", target: "/x", suppressed: false } },+ { driver: "copilot", rawName: "edit", rawInput: { file_path: "/x" }, expected: { name: "edit", target: "/x", suppressed: false } },+ { driver: "copilot", rawName: "write", rawInput: { file_path: "/x" }, expected: { name: "write", target: "/x", suppressed: false } },+ { driver: "copilot", rawName: "grep", rawInput: { pattern: "TODO" }, expected: { name: "grep", target: "TODO", suppressed: false } },+ ];+ it.each(cases)("$driver × $rawName produces canonical shape", ({ rawName, rawInput, expected }) => {+ expect(extractToolAudit(rawName, rawInput)).toEqual(expected);+ });+});++describe("onBotAuditEvent — integration through onRuntimeEvent (T9/T10)", () => {+ it("emits canonical lowercase name for every driver × tool combo", () => {+ const onBotAuditEvent = vi.fn();+ const { mgr, session } = makeManager({ onBotAuditEvent });+ mgr.deliver("a1", { seq: 1, text: "hello" });++ const combos: Array<{ name: string; input: unknown; expect: { name: string; target?: string } }> = [+ { name: "Bash", input: { command: "rm" }, expect: { name: "bash", target: "rm" } },+ { name: "bash", input: { command: "rm" }, expect: { name: "bash", target: "rm" } },+ { name: "Read", input: { file_path: "x" }, expect: { name: "read", target: "x" } },+ { name: "read", input: { path: "x" }, expect: { name: "read", target: "x" } },+ { name: "Edit", input: { file_path: "x" }, expect: { name: "edit", target: "x" } },+ { name: "edit", input: { path: "x" }, expect: { name: "edit", target: "x" } },+ { name: "Grep", input: { pattern: "TODO" }, expect: { name: "grep", target: "TODO" } },+ { name: "shell", input: { command: "pnpm test" }, expect: { name: "bash", target: "pnpm test" } },+ { name: "file_change", input: { path: "src/x.ts" }, expect: { name: "edit", target: "src/x.ts" } },+ ];++ for (const c of combos) {+ session.fire("runtime_event", { kind: "tool_call", name: c.name, input: c.input });+ }++ const payloads = onBotAuditEvent.mock.calls+ .filter(([, ev]) => (ev as { kind?: string })?.kind === "tool_call")+ .map(([, ev]) => (ev as { payload: { name: string; target?: string } }).payload);+ expect(payloads).toEqual(combos.map((c) => c.expect));+ });++ it("alook-shell suppression fires for Bash, pi bash, AND codex shell", () => {+ const onBotAuditEvent = vi.fn();+ const { mgr, session } = makeManager({ onBotAuditEvent });+ mgr.deliver("a1", { seq: 1, text: "hello" });++ session.fire("runtime_event", { kind: "tool_call", name: "Bash", input: { command: "alook inbox pull" } });+ session.fire("runtime_event", { kind: "tool_call", name: "bash", input: { command: "alook" } });+ session.fire("runtime_event", { kind: "tool_call", name: "shell", input: { command: "alook message send" } });++ const toolCalls = onBotAuditEvent.mock.calls.filter(+ ([, ev]) => (ev as { kind?: string })?.kind === "tool_call"+ );+ expect(toolCalls).toHaveLength(0);});});diff --git a/src/daemon/src/manager/managerRuntime.ts b/src/daemon/src/manager/managerRuntime.tsindex 19a48f144..0b33a779d 100644--- a/src/daemon/src/manager/managerRuntime.ts+++ b/src/daemon/src/manager/managerRuntime.ts@@ -102,18 +102,21 @@ export interface ManagerRuntimeOpts {/*** Notified whenever a runtime `thinking` or `tool_call` event lands. Wired* in `createDaemon` to send a `bot_audit_event` frame through the WS- * control channel. `Bash` tool_calls whose `input.command` starts with- * `alook ` are dropped inside `onRuntimeEvent` — the credential-proxy- * `cli_invocation` sighting is authoritative for those. Every other `Bash`- * call arrives here with a truncated `command` summary attached.+ * control channel. Tool calls flow through `extractToolAudit`, which+ * canonicalizes the tool name to lowercase (`Bash` → `bash`, codex+ * `shell` → `bash`, codex `file_change` → `edit`, etc.), picks a+ * `target` field driver-agnostically (file path / shell command /+ * pattern / url / mcp name), and suppresses any bash-family call whose+ * resolved command is `alook <sub>` — the credential-proxy+ * `cli_invocation` sighting is authoritative for those.** `thinking` payloads carry truncated `text` + original `chars`; the audit- * log does not record raw tool input beyond the optional `command`.+ * log does not record raw tool input beyond the optional `target`.*/onBotAuditEvent?: (agentId: string,event:- | { kind: "tool_call"; payload: { name: string; command?: string } }+ | { kind: "tool_call"; payload: { name: string; target?: string } }| { kind: "thinking"; payload: { text: string; truncated: boolean; chars: number } },context: { sessionId: string | null; launchId: string | null }) => void;@@ -194,61 +197,225 @@ export interface TimelineRecorder {const THINKING_MAX_BYTES = 4096;/**- * Max UTF-16 code units for a `Bash` tool_call's `command` summary. The wire- * schema caps `command` at 240 chars (see `AuditLogToolCallPayloadSchema`) and- * Zod's `.max()` measures UTF-16 length — so we truncate on the same unit an- * astral character (emoji) counts as 2. Truncating on codepoints would let an- * emoji-heavy command exceed 240 UTF-16 units and get rejected at the wire.+ * Max UTF-16 code units for a tool_call's `target` field. The wire schema+ * caps `target` at 240 (see `AuditLogToolCallPayloadSchema`) and Zod's+ * `.max()` measures UTF-16 length — the extractor truncates at 200 to keep+ * 40 units of headroom for any future producer that stamps a suffix before+ * wire validation. Truncating on codepoints would let an emoji-heavy target+ * exceed 240 UTF-16 units and get rejected at the wire.*/-const BASH_COMMAND_SUMMARY_MAX_CHARS = 200;+const MAX_TARGET_CODE_UNITS = 200;/**- * Extract a short command summary from a tool_call's `input`. Bash-family- * tools carry a `command` string in most drivers (claude, cursor, kimi,- * opencode) — codex wraps it inside `input.item.command` or a `type:- * "commandExecution"` variant. Best-effort extraction: return the first- * non-empty line trimmed and truncated to `BASH_COMMAND_SUMMARY_MAX_CHARS`- * UTF-16 code units (ellipsis if cut, walking back one unit if the boundary- * would split a surrogate pair). Returns `undefined` if no plausible command- * string is present.+ * Canonicalize a driver-raw tool name to the lowercase tag the audit log+ * stores. The map is case-insensitive on the input: `Bash|bash|BASH → bash`,+ * codex's `shell → bash` and `file_change → edit`, `MultiEdit → edit`+ * (intentional semantic collapse — every MultiEdit acts on one file),+ * `NotebookEdit → notebook_edit`, `LS → ls`, `WebSearch → web_search`,+ * `WebFetch → web_fetch`, `TodoWrite → todo_write`. Anything else falls+ * through to its lowercased original (e.g. `mcp_search` stays `mcp_search`,+ * an unknown `Frobnicate` becomes `frobnicate`) so new drivers don't need+ * this table updated to surface.*/-export function extractBashCommandSummary(input: unknown): string | undefined {- const raw = pickCommandString(input);- if (typeof raw !== "string") return undefined;- const firstLine = raw.split("\n").map((s) => s.trim()).find((s) => s.length > 0);- if (!firstLine) return undefined;- if (firstLine.length <= BASH_COMMAND_SUMMARY_MAX_CHARS) return firstLine;- let end = BASH_COMMAND_SUMMARY_MAX_CHARS - 1;- const cu = firstLine.charCodeAt(end - 1);- if (cu >= 0xd800 && cu <= 0xdbff) end -= 1;- return firstLine.slice(0, end) + "…";+export function canonicalToolName(rawName: string): string {+ const lower = rawName.toLowerCase();+ switch (lower) {+ case "bash":+ case "shell":+ return "bash";+ case "read":+ return "read";+ case "edit":+ case "multiedit":+ case "file_change":+ return "edit";+ case "write":+ return "write";+ case "grep":+ return "grep";+ case "glob":+ return "glob";+ case "find":+ return "find";+ case "ls":+ return "ls";+ case "notebookedit":+ case "notebook_edit":+ return "notebook_edit";+ case "websearch":+ case "web_search":+ return "web_search";+ case "webfetch":+ case "web_fetch":+ return "web_fetch";+ case "todowrite":+ case "todo_write":+ return "todo_write";+ default:+ return lower;+ }}-function pickCommandString(input: unknown): string | undefined {- if (!input || typeof input !== "object") return undefined;- const rec = input as Record<string, unknown>;- if (typeof rec.command === "string") return rec.command;- // codex `commandExecution` shape: input.item.command (array or string)- const item = rec.item as Record<string, unknown> | undefined;- if (item) {- if (typeof item.command === "string") return item.command;- if (Array.isArray(item.command)) return item.command.filter((v) => typeof v === "string").join(" ");+type ToolClass = "shell" | "file_target" | "pattern" | "fallthrough";++function classify(canonicalName: string): ToolClass {+ switch (canonicalName) {+ case "bash":+ return "shell";+ case "read":+ case "edit":+ case "write":+ case "ls":+ case "notebook_edit":+ return "file_target";+ case "grep":+ case "glob":+ case "find":+ return "pattern";+ default:+ return "fallthrough";}+}++/**+ * Coerce a runtime-emitted `input` to a plain record for field-picking.+ * Non-object inputs (null, undefined, array, number, boolean) become+ * `undefined`. As a special case, string inputs get a single `JSON.parse`+ * attempt: copilot's OpenAI-style tool-call `arguments` reaches this layer+ * as a stringified JSON blob when the driver's `arguments ?? parameters ??+ * input ?? {}` fallback picks the raw string up unparsed. If the parse+ * succeeds and yields a record, that record is returned; on any failure+ * (non-JSON string, JSON that decodes to a non-object) we return+ * `undefined` — never throw. One parse attempt per event, so an adversarial+ * huge string is bounded by the runtime's own event size limits.+ */+function coerceInputRecord(input: unknown): Record<string, unknown> | undefined {+ if (typeof input === "string") {+ try {+ const parsed = JSON.parse(input);+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {+ return parsed as Record<string, unknown>;+ }+ } catch {+ return undefined;+ }+ return undefined;+ }+ if (!input || typeof input !== "object" || Array.isArray(input)) return undefined;+ return input as Record<string, unknown>;+}++/**+ * Extract a raw command string from a shell-class tool_call's `input`. Every+ * driver reduces to a root `input.command` after its normalizer runs+ * (Anthropic, cursor, kimi, opencode, pi, gemini, copilot, and codex — the+ * codex normalizer unwraps `params.item`, so `command` is already flat).+ * String or array (`["bash", "-lc", "..."]` from codex) — arrays get+ * space-joined, keeping the honest form the runtime saw. Returns+ * `undefined` when no plausible command is present.+ */+export function pickCommandString(input: unknown): string | undefined {+ const rec = coerceInputRecord(input);+ if (!rec) return undefined;+ if (typeof rec.command === "string") return rec.command;+ if (Array.isArray(rec.command)) return rec.command.filter((v) => typeof v === "string").join(" ");+ return undefined;+}++function pickFileTarget(input: unknown): string | undefined {+ const rec = coerceInputRecord(input);+ if (!rec) return undefined;+ if (typeof rec.file_path === "string") return rec.file_path;+ if (typeof rec.path === "string") return rec.path;+ if (typeof rec.notebook_path === "string") return rec.notebook_path;+ return undefined;+}++function pickPatternTarget(input: unknown): string | undefined {+ const rec = coerceInputRecord(input);+ if (!rec) return undefined;+ if (typeof rec.pattern === "string") return rec.pattern;+ if (typeof rec.query === "string") return rec.query;+ if (typeof rec.path === "string") return rec.path;+ return undefined;+}++function pickFallthroughTarget(input: unknown): string | undefined {+ const rec = coerceInputRecord(input);+ if (!rec) return undefined;+ if (typeof rec.url === "string") return rec.url;+ if (typeof rec.query === "string") return rec.query;+ if (typeof rec.path === "string") return rec.path;+ if (typeof rec.name === "string") return rec.name;return undefined;}/**- * A `Bash` tool_call is the daemon proxy's shadow when — and only when — the- * command is `alook` or `alook <sub …>`. In that case the credential proxy- * emits an authoritative `cli_invocation` audit row and the tool_call would- * duplicate it. Any other Bash command (rm, sed, git, pnpm, echo, …) is user+ * A bash-family tool_call is the daemon proxy's shadow when — and only when+ * — the resolved command is `alook` or `alook <sub …>`. In that case the+ * credential proxy emits an authoritative `cli_invocation` audit row and+ * the tool_call would duplicate it. Any other command (rm, sed, git, pnpm,+ * echo, `bash -lc "alook …"` — the outer shell is real work) is user* intent and must surface.*/-export function isAlookShellCommand(command: string | undefined): boolean {+export function isAlookShellInvocation(command: string | undefined): boolean {if (!command) return false;return /^alook(\s|$)/.test(command.trimStart());}+/**+ * Truncate a target to at most `MAX_TARGET_CODE_UNITS` UTF-16 code units,+ * appending `…` when cut. Walks back one unit if the boundary lands on a+ * high surrogate (never emits a lone surrogate).+ */+export function truncateTargetToCodeUnits(s: string): string {+ if (s.length <= MAX_TARGET_CODE_UNITS) return s;+ let end = MAX_TARGET_CODE_UNITS - 1;+ const cu = s.charCodeAt(end - 1);+ if (cu >= 0xd800 && cu <= 0xdbff) end -= 1;+ return s.slice(0, end) + "…";+}++/**+ * Driver-agnostic tool_call extractor. Given a runtime-raw `(name, input)`+ * pair, returns the canonical lowercase `name`, an optional short `target`+ * summary (file path / shell command / pattern / url / mcp name), and a+ * `suppressed` flag that's true for bash-family calls whose command is+ * `alook <sub>` (the credential proxy's `cli_invocation` is authoritative+ * for those).+ *+ * The returned object contains ONLY `{name, target?, suppressed}`. Raw+ * `input` is NEVER returned. Callers must destructure — never spread — so+ * a future extractor field addition cannot accidentally leak sensitive tool+ * args onto the wire.+ */+export function extractToolAudit(+ rawName: string,+ rawInput: unknown+): { name: string; target?: string; suppressed: boolean } {+ const name = canonicalToolName(rawName);+ const cls = classify(name);+ if (cls === "shell") {+ const raw = pickCommandString(rawInput);+ if (isAlookShellInvocation(raw)) {+ return { name, suppressed: true };+ }+ const firstLine = typeof raw === "string"+ ? raw.split("\n").map((s) => s.trim()).find((s) => s.length > 0)+ : undefined;+ if (!firstLine) return { name, suppressed: false };+ return { name, target: truncateTargetToCodeUnits(firstLine), suppressed: false };+ }+ let target: string | undefined;+ if (cls === "file_target") target = pickFileTarget(rawInput);+ else if (cls === "pattern") target = pickPatternTarget(rawInput);+ else target = pickFallthroughTarget(rawInput);+ if (typeof target !== "string" || target.length === 0) {+ return { name, suppressed: false };+ }+ return { name, target: truncateTargetToCodeUnits(target), suppressed: false };+}+/*** Truncate a `thinking` string to at most `THINKING_MAX_BYTES` UTF-8 bytes* without splitting a multi-byte sequence. Exported for tests. Callers get the@@ -747,20 +914,15 @@ export class AgentProcessManager {// first so the audit log preserves thinking→action ordering.this.flushThinkingAudit(agentId);if (ev.kind === "tool_call" && typeof ev.name === "string") {- // Bash-command suppression — a Bash call whose command is `alook`- // (or `alook <sub …>`) is already covered by the credential-proxy- // `cli_invocation` audit row; emitting a second `tool_call` here- // would double-count the same action. Every other Bash command- // (rm, sed, git, pnpm, echo …) is real user-visible work and must- // surface as a `tool_call` row with a short command summary.- const isBash = ev.name === "Bash";- const command = isBash ? extractBashCommandSummary(ev.input) : undefined;- const suppressed = isBash && isAlookShellCommand(command);- if (!suppressed) {+ const audit = extractToolAudit(ev.name, ev.input);+ if (!audit.suppressed) {+ const payload = audit.target !== undefined+ ? { name: audit.name, target: audit.target }+ : { name: audit.name };try {this.opts.onBotAuditEvent(agentId, {kind: "tool_call",- payload: command ? { name: ev.name, command } : { name: ev.name },+ payload,}, {sessionId: this.liveSessions.get(agentId) ?? null,launchId: this.launchIds.get(agentId) ?? null,diff --git a/src/daemon/src/server/wsControlChannel.test.ts b/src/daemon/src/server/wsControlChannel.test.tsindex dd9a93ba6..5a1201d52 100644--- a/src/daemon/src/server/wsControlChannel.test.ts+++ b/src/daemon/src/server/wsControlChannel.test.ts@@ -251,7 +251,7 @@ describe("WsControlChannel — bot audit event reports", () => {ch.reportBotAuditEvent({type: "bot_audit_event",agentId: "bot_1",- event: { kind: "tool_call", payload: { name: "Read" } },+ event: { kind: "tool_call", payload: { name: "read", target: "AGENTS.md" } },})).resolves.toBeUndefined();expect(sockets[0].frames().some((f) => f.type === "bot_audit_event")).toBe(false);diff --git a/src/shared/src/community-cli-contract.ts b/src/shared/src/community-cli-contract.tsindex d519c9d2a..427596f0e 100644--- a/src/shared/src/community-cli-contract.ts+++ b/src/shared/src/community-cli-contract.ts@@ -602,7 +602,7 @@ export type AgentActivityState = "idle" | "starting" | "running" | "stopping";*/export type BotAuditEventPayload =| { kind: "cli_invocation"; payload: { subcommand: string } }- | { kind: "tool_call"; payload: { name: string } }+ | { kind: "tool_call"; payload: { name: string; target?: string } }| { kind: "thinking"; payload: { text: string; truncated: boolean; chars: number } };export interface HostBotAuditEventFrame {diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.tsindex d89823659..bef81fbd2 100644--- a/src/shared/src/schemas.ts+++ b/src/shared/src/schemas.ts@@ -1206,11 +1206,24 @@ export type CommunityAgentJoinServerRequest = z.infer<// discriminated branches.//// - cli_invocation → the daemon's credential proxy handled an alook subcommand-// - tool_call → the runtime invoked a tool. `Bash` calls whose command-// starts with `alook ` are suppressed here (the proxy-// emits the authoritative `cli_invocation` for those); any-// other `Bash` command lands here with an optional-// `command` summary attached.+// - tool_call → the runtime invoked a tool. `name` is a canonical+// lowercase tag (`bash`, `read`, `edit`, `write`, `grep`,+// `glob`, `find`, `ls`, `notebook_edit`, `web_search`,+// `web_fetch`, `todo_write`, `mcp_*`, `collab_tool_call`,+// …) — case-collapsed on the daemon write side so a mixed+// stream of `Bash` and `bash` reads as one shape.+// Bash-family calls whose resolved command is+// `alook <sub>` are suppressed here (the credential proxy+// emits the authoritative `cli_invocation` for those);+// every other tool call lands here with an optional+// `target` — the file path, shell command, search+// pattern, url, or MCP tool name that the call acts on.+// Historical rows written before this convention keep+// whatever `name` they were persisted with; unknown keys+// (e.g. the pre-shipping `command` field from a local+// dev branch) are silently dropped by Zod's default+// strip-unknown behavior, so a legacy `{name, command}`+// row parses as `{name}` — rendered as name-only.// - thinking → excerpted thinking text, truncated at 4096 UTF-8 bytesexport const AuditLogCliInvocationPayloadSchema = z.object({@@ -1218,8 +1231,17 @@ export const AuditLogCliInvocationPayloadSchema = z.object({});export const AuditLogToolCallPayloadSchema = z.object({name: z.string().min(1),- /** First non-empty line of `input.command` for Bash-family tool_calls, truncated. */- command: z.string().max(240).optional(),+ /**+ * Short human-facing summary of what the tool acted on — file path for+ * file-target tools, first non-empty line of the shell command for+ * `bash`, `pattern` for search tools, `url` / `query` / MCP name for+ * fallthrough tools. Absent for tools that have no meaningful entity+ * (e.g. `todo_write`) or when the runtime emitted an input we couldn't+ * pick a field from. Capped at 240 UTF-16 code units to match the wire+ * budget; the daemon truncates to 200 code units + `…` before sending+ * so future producers have headroom.+ */+ target: z.string().max(240).optional(),});export const AuditLogThinkingPayloadSchema = z.object({text: z.string(),diff --git a/src/web/src/app/api/community/bots/[id]/audit-log/route.test.ts b/src/web/src/app/api/community/bots/[id]/audit-log/route.test.tsindex 3524e8c85..66f37a608 100644--- a/src/web/src/app/api/community/bots/[id]/audit-log/route.test.ts+++ b/src/web/src/app/api/community/bots/[id]/audit-log/route.test.ts@@ -111,6 +111,26 @@ describe("GET /api/community/bots/[id]/audit-log", () => {expect(body.nextCursor).toBe(null)})+ it("round-trips a canonical tool_call row: name is lowercased, target survives", async () => {+ mockGetBotOwnedBy.mockResolvedValue({ id: "b1" })+ mockListBotActivityEvents.mockResolvedValue([+ {+ id: "bae_1",+ botId: "b1",+ sessionId: null,+ launchId: null,+ kind: "tool_call",+ payload: JSON.stringify({ name: "read", target: "AGENTS.md" }),+ createdAt: "2025-01-01T00:00:00.000Z",+ },+ ])+ const res = await GET(req(), ctx("b1"))+ expect(res.status).toBe(200)+ const body = (await res.json()) as { events: Array<{ payload: { name: string; target?: string } }> }+ expect(body.events[0]!.payload.name).toBe("read")+ expect(body.events[0]!.payload.target).toBe("AGENTS.md")+ })+it("returns a composite nextCursor when the page fills to the limit", async () => {mockGetBotOwnedBy.mockResolvedValue({ id: "b1" })const rows = Array.from({ length: 2 }).map((_, i) => ({diff --git a/src/web/src/components/community/bots/bot-activity-modal.tsx b/src/web/src/components/community/bots/bot-activity-modal.tsxindex 99bca2739..2f67c0202 100644--- a/src/web/src/components/community/bots/bot-activity-modal.tsx+++ b/src/web/src/components/community/bots/bot-activity-modal.tsx@@ -159,6 +159,7 @@ export function BotActivityModal({return (<Dialog open={open} onOpenChange={onOpenChange}><DialogContent+ data-testid="bot-activity-modal"showCloseButton={false}className="flex h-[72vh] max-h-170 w-full max-w-2xl flex-col gap-0 overflow-hidden p-0 sm:max-w-2xl">diff --git a/src/web/src/components/community/bots/bot-activity-row.tsx b/src/web/src/components/community/bots/bot-activity-row.tsxindex d5d922e1b..bb0217472 100644--- a/src/web/src/components/community/bots/bot-activity-row.tsx+++ b/src/web/src/components/community/bots/bot-activity-row.tsx@@ -21,7 +21,10 @@ export function BotActivityRow({ event }: { event: AuditEvent }) {const [expanded, setExpanded] = useState(false)return (- <div className="group grid grid-cols-[64px_56px_1fr] items-baseline gap-x-3 px-4 py-1.5 hover:bg-accent/30">+ <div+ data-testid="bot-activity-row"+ className="group grid grid-cols-[64px_56px_1fr] items-baseline gap-x-3 px-4 py-1.5 hover:bg-accent/30"+ ><timedateTime={event.createdAt}title={new Date(event.createdAt).toLocaleString()}@@ -77,19 +80,16 @@ function RowBody({)}if (event.kind === "tool_call") {- const p = event.payload as { name?: string; command?: string } | null- const name = p?.name ?? "?"- // Bash-family calls carry a short command summary. Show it inline so the- // owner can distinguish `rm -rf tmp` from `git commit`; without it, all- // shell activity would collapse into an indistinguishable pile of "Bash".- if (p?.command) {+ const p = event.payload as { name?: string; target?: string } | null+ const name = (p?.name ?? "?").toLowerCase()+ if (p?.target) {return (<div- title={p.command}+ title={p.target}className="truncate font-mono text-[13px] text-foreground">{name} <span className="text-muted-foreground/60">·</span>{" "}- <span className="text-muted-foreground">{p.command}</span>+ <span className="text-muted-foreground">{p.target}</span></div>)}diff --git a/src/web/src/lib/community/audit-log-payload.test.ts b/src/web/src/lib/community/audit-log-payload.test.tsindex 68b9077fc..900a9ef38 100644--- a/src/web/src/lib/community/audit-log-payload.test.ts+++ b/src/web/src/lib/community/audit-log-payload.test.ts@@ -6,23 +6,31 @@ describe("parseAuditLogPayload", () => {const p = parseAuditLogPayload("cli_invocation", JSON.stringify({ subcommand: "send" }))expect(p).toEqual({ subcommand: "send" })})- it("parses a well-shaped tool_call payload", () => {- const p = parseAuditLogPayload("tool_call", JSON.stringify({ name: "Read" }))- expect(p).toEqual({ name: "Read" })+ it("parses a well-shaped tool_call payload (name only)", () => {+ const p = parseAuditLogPayload("tool_call", JSON.stringify({ name: "read" }))+ expect(p).toEqual({ name: "read" })})- it("parses a Bash tool_call payload with a `command` summary", () => {+ it("parses a bash tool_call payload with a `target` at the 240-char cap", () => {+ const t = "x".repeat(240)const p = parseAuditLogPayload("tool_call",- JSON.stringify({ name: "Bash", command: "rm -rf tmp" }),+ JSON.stringify({ name: "bash", target: t }),)- expect(p).toEqual({ name: "Bash", command: "rm -rf tmp" })+ expect(p).toEqual({ name: "bash", target: t })})- it("rejects a tool_call `command` longer than 240 chars", () => {+ it("rejects a tool_call `target` longer than 240 chars", () => {const long = "x".repeat(241)- expect(parseAuditLogPayload("tool_call", JSON.stringify({ name: "Bash", command: long }))).toBe(+ expect(parseAuditLogPayload("tool_call", JSON.stringify({ name: "bash", target: long }))).toBe(null,)})+ it("gracefully strips a legacy `command` field (Zod strip-unknown)", () => {+ const p = parseAuditLogPayload(+ "tool_call",+ JSON.stringify({ name: "bash", command: "rm -rf tmp" }),+ )+ expect(p).toEqual({ name: "bash" })+ })it("parses a well-shaped thinking payload", () => {const p = parseAuditLogPayload("thinking",