diff --git a/packages/protocol/src/agent-attention-notification.test.ts b/packages/protocol/src/agent-attention-notification.test.ts index 04aabceb2..9166d907d 100644 --- a/packages/protocol/src/agent-attention-notification.test.ts +++ b/packages/protocol/src/agent-attention-notification.test.ts @@ -71,6 +71,25 @@ describe("buildAgentAttentionNotificationPayload", () => { }); }); + it("includes the tool input when a permission has a reason but no title", () => { + const payload = buildAgentAttentionNotificationPayload({ + reason: "permission", + serverId: "srv-1", + workspaceId: "workspace-1", + agentId: "agent-1", + permissionRequest: { + id: "perm-1", + provider: "claude", + name: "Bash", + kind: "tool", + input: { command: "echo hello" }, + description: "Hook requires approval", + }, + }); + + expect(payload.body).toBe('{"command":"echo hello"} - Hook requires approval'); + }); + it("uses error-specific defaults when reason is error", () => { const payload = buildAgentAttentionNotificationPayload({ reason: "error", diff --git a/packages/protocol/src/agent-attention-notification.ts b/packages/protocol/src/agent-attention-notification.ts index 961e864d8..5b9d229d4 100644 --- a/packages/protocol/src/agent-attention-notification.ts +++ b/packages/protocol/src/agent-attention-notification.ts @@ -115,6 +115,11 @@ const buildPermissionDetails = ( if (title) { details.push(title); + } else if (description && request.input) { + const inputPreview = safeStringify(request.input); + if (inputPreview) { + details.push(inputPreview); + } } if (description && description !== title) { details.push(description); diff --git a/packages/server/src/server/agent/providers/claude/agent.test.ts b/packages/server/src/server/agent/providers/claude/agent.test.ts index 3aa96635f..43632a0cd 100644 --- a/packages/server/src/server/agent/providers/claude/agent.test.ts +++ b/packages/server/src/server/agent/providers/claude/agent.test.ts @@ -998,6 +998,43 @@ describe("ClaudeAgentSession features", () => { } }); + test("carries the SDK decision reason onto the permission request description", async () => { + const { queryFactory } = createQueryMock(); + const session = await new ClaudeAgentClient({ + logger, + queryFactory, + resolveBinary: async () => "/test/claude/bin", + }).createSession({ provider: "claude", cwd: process.cwd(), modeId: "bypassPermissions" }); + const events: AgentStreamEvent[] = []; + const unsubscribe = session.subscribe((event) => events.push(event)); + + try { + await session.startTurn("run the tool"); + const canUseTool = queryFactory.mock.calls[0]?.[0].options.canUseTool; + if (!canUseTool) throw new Error("Expected canUseTool callback"); + canUseTool( + "Bash", + { command: "printf test" }, + { + toolUseID: "tool-hook-ask", + decisionReason: + "\u001b[33mHeredoc input to python3 -- cannot statically verify safety\u001b[0m", + }, + ).catch(() => undefined); + + expect(events.find((event) => event.type === "permission_requested")).toMatchObject({ + type: "permission_requested", + request: { + name: "Bash", + description: "Heredoc input to python3 -- cannot statically verify safety", + }, + }); + } finally { + unsubscribe(); + await session.close(); + } + }); + test("passes exact configured Fable 5 IDs through to Claude Code", async () => { const { queryFactory, queryMock } = createQueryMock(); const client = new ClaudeAgentClient({ diff --git a/packages/server/src/server/agent/providers/claude/agent.ts b/packages/server/src/server/agent/providers/claude/agent.ts index bee13ed78..ace2320de 100644 --- a/packages/server/src/server/agent/providers/claude/agent.ts +++ b/packages/server/src/server/agent/providers/claude/agent.ts @@ -9,6 +9,7 @@ import fs from "node:fs"; import { promises } from "node:fs"; import path from "node:path"; import { LRUCache } from "lru-cache"; +import stripAnsi from "strip-ansi"; import { createImportDescriptorScheduler } from "./import-descriptor-scheduler.js"; import { type AgentDefinition, @@ -5330,6 +5331,7 @@ class ClaudeAgentSession implements AgentSession { provider: "claude", name: toolName, kind, + description: readNonEmptyString(stripAnsi(options.decisionReason ?? ""))?.trim(), ...buildClaudeQuestionPermissionSummary(toolName, input), input: requestInput, detail: toolDetail,