Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): let an agent offer actions as buttons in a session (#86894)

Adam Bowker68d2331baa17
diff --git a/products/desktop/packages/agent/src/adapters/claude/mcp/local-tools.test.ts b/products/desktop/packages/agent/src/adapters/claude/mcp/local-tools.test.ts
index ed66813da98a..c14999a39233 100644
--- a/products/desktop/packages/agent/src/adapters/claude/mcp/local-tools.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/mcp/local-tools.test.ts
@@ -44,12 +44,28 @@ describe("createLocalToolsMcpServer", () => {
await client.close();
});
- it("registers no server on a desktop run with narration off (no tools pass their gate)", () => {
+ it("still exposes show_actions on a desktop run with no gate meta at all", async () => {
const server = createLocalToolsMcpServer(
{ cwd: "/repo", token: "ghs_x" },
undefined,
);
- expect(server).toBeUndefined();
+ if (!server) {
+ throw new Error("expected the local-tools server to be registered");
+ }
+
+ const [clientTransport, serverTransport] =
+ InMemoryTransport.createLinkedPair();
+ await server.instance.connect(serverTransport);
+ const client = new Client({ name: "test", version: "1.0.0" });
+ await client.connect(clientTransport);
+
+ const { tools } = await client.listTools();
+ const names = tools.map((t) => t.name);
+ expect(names).toContain("show_actions");
+ expect(names).not.toContain("speak");
+ expect(names).not.toContain("git_signed_commit");
+
+ await client.close();
});
it("exposes git_signed_commit over MCP in a cloud run with a token", async () => {
diff --git a/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.test.ts b/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.test.ts
index f52079bb6d4b..89b9493ad89f 100644
--- a/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.test.ts
@@ -169,6 +169,34 @@ describe("canUseTool MCP approval enforcement", () => {
expect(context.client.requestPermission).not.toHaveBeenCalled();
});
+ it("auto-allows the show_actions tool without prompting", async () => {
+ const context = createContext("mcp__posthog-code-tools__show_actions", {
+ toolInput: {
+ actions: [{ kind: "compose", label: "Add PostHog", prompt: "/x" }],
+ },
+ });
+ const result = await canUseTool(context);
+
+ expect(result.behavior).toBe("allow");
+ expect(context.client.requestPermission).not.toHaveBeenCalled();
+ });
+
+ it("blocks show_actions when its approval state is do_not_use", async () => {
+ setMcpToolApprovalStates({
+ "mcp__posthog-code-tools__show_actions": "do_not_use",
+ });
+
+ const context = createContext("mcp__posthog-code-tools__show_actions", {
+ toolInput: {
+ actions: [{ kind: "compose", label: "Add PostHog", prompt: "/x" }],
+ },
+ });
+ const result = await canUseTool(context);
+
+ expect(result.behavior).toBe("deny");
+ expect(context.client.requestPermission).not.toHaveBeenCalled();
+ });
+
it("blocks speak when its approval state is do_not_use", async () => {
setMcpToolApprovalStates({
"mcp__posthog-code-tools__speak": "do_not_use",
diff --git a/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.ts b/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.ts
index 80caa469cd96..e175d4860f3b 100644
--- a/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/permissions/permission-handlers.ts
@@ -16,6 +16,7 @@ import {
import { text } from "../../../utils/acp-content";
import type { Logger } from "../../../utils/logger";
import { qualifiedLocalToolName } from "../../local-tools";
+import { SHOW_ACTIONS_TOOL_NAME } from "../../local-tools/tools/show-actions";
import { SPEAK_TOOL_NAME } from "../../local-tools/tools/speak";
import { toolInfoFromToolUse } from "../conversion/tool-use-to-acp";
import {
@@ -42,7 +43,13 @@ import {
buildPermissionOptions,
} from "./permission-options";
-const SPEAK_TOOL_ID = qualifiedLocalToolName(SPEAK_TOOL_NAME);
+// Local tools whose handler only acknowledges: the agent process cannot reach the user's
+// speakers or window, so the desktop renderer does the work off the surfaced call. Prompting
+// for these asks the user to approve something that has already happened to them.
+const NO_OP_LOCAL_TOOL_IDS = new Set([
+ qualifiedLocalToolName(SPEAK_TOOL_NAME),
+ qualifiedLocalToolName(SHOW_ACTIONS_TOOL_NAME),
+]);
export type ToolPermissionResult =
| {
@@ -826,10 +833,8 @@ export async function canUseTool(
return { behavior: "deny", message, interrupt: false };
}
- // Narration is a fire-and-forget no-op on the agent side; a permission
- // prompt for it interrupts the user to approve a line they may never hear.
// An explicit do_not_use block above still wins.
- if (toolName === SPEAK_TOOL_ID) {
+ if (NO_OP_LOCAL_TOOL_IDS.has(toolName)) {
return {
behavior: "allow",
updatedInput: toolInput as Record<string, unknown>,
diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/local-tools-mcp.test.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/local-tools-mcp.test.ts
index 0b53b4ceacc7..8d6097156b25 100644
--- a/products/desktop/packages/agent/src/adapters/codex-app-server/local-tools-mcp.test.ts
+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/local-tools-mcp.test.ts
@@ -123,11 +123,19 @@ describe("buildLocalToolsServer", () => {
expect(names).not.toContain("git_signed_commit");
});
- it("returns null on a desktop run with narration off (no tools pass their gate)", () => {
+ it("still exposes show_actions on a desktop run with narration off", () => {
process.env.GH_TOKEN = "ghs_test";
- expect(
- buildLocalToolsServer({ cwd: "/repo" }, { environment: "local" }),
- ).toBeNull();
+ const server = buildLocalToolsServer(
+ { cwd: "/repo" },
+ { environment: "local" },
+ );
+ const enabled =
+ server?.env.find((e) => e.name === "POSTHOG_LOCAL_TOOLS_ENABLED")
+ ?.value ?? "";
+ const names = enabled.split(",");
+ expect(names).toContain("show_actions");
+ expect(names).not.toContain("speak");
+ expect(names).not.toContain("git_signed_commit");
});
});
diff --git a/products/desktop/packages/agent/src/adapters/local-tools/index.ts b/products/desktop/packages/agent/src/adapters/local-tools/index.ts
index e691b89cf962..f221b1677020 100644
--- a/products/desktop/packages/agent/src/adapters/local-tools/index.ts
+++ b/products/desktop/packages/agent/src/adapters/local-tools/index.ts
@@ -4,6 +4,7 @@ import { finishTool } from "./tools/finish";
import { listAgentsTool } from "./tools/list-agents";
import { listReposTool } from "./tools/list-repos";
import { sendAgentMessageTool } from "./tools/send-agent-message";
+import { showActionsTool } from "./tools/show-actions";
import { signedCommitTool } from "./tools/signed-commit";
import { signedMergeTool } from "./tools/signed-merge";
import { signedRewriteTool } from "./tools/signed-rewrite";
@@ -27,6 +28,7 @@ export const LOCAL_TOOLS: LocalTool[] = [
listReposTool,
cloneRepoTool,
speakTool,
+ showActionsTool,
uploadArtifactTool,
finishTool,
listAgentsTool,
diff --git a/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.test.ts b/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.test.ts
new file mode 100644
index 000000000000..831caf3c4bde
--- /dev/null
+++ b/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.test.ts
@@ -0,0 +1,65 @@
+import { describe, expect, it } from "vitest";
+import { enabledLocalTools } from "../index";
+import { SHOW_ACTIONS_TOOL_NAME, showActionsSchema } from "./show-actions";
+
+describe("show_actions tool", () => {
+ // The tool exists because a gated tool the agent never sees cannot be offered.
+ // Every gate meta a session can carry must still expose it.
+ it.each([
+ { name: "a local session", meta: { environment: "local" as const } },
+ {
+ name: "a headless cloud run",
+ meta: { environment: "cloud" as const, background: true },
+ },
+ { name: "a channel session", meta: { channelMode: true } },
+ { name: "no gate meta at all", meta: undefined },
+ ])("is exposed in $name", ({ meta }) => {
+ const tools = enabledLocalTools({ cwd: "/repo" }, meta);
+ expect(tools.some((t) => t.name === SHOW_ACTIONS_TOOL_NAME)).toBe(true);
+ });
+
+ it.each([
+ {
+ name: "an empty list",
+ actions: [],
+ },
+ {
+ name: "more than four actions",
+ actions: Array.from({ length: 5 }, () => ({
+ kind: "compose",
+ label: "Do it",
+ prompt: "Do it",
+ })),
+ },
+ {
+ name: "a label over 60 characters",
+ actions: [{ kind: "compose", label: "x".repeat(61), prompt: "Do it" }],
+ },
+ {
+ name: "a url instead of a verb",
+ actions: [{ kind: "open_url", label: "Open", url: "https://evil.test" }],
+ },
+ ])("rejects $name", ({ actions }) => {
+ expect(showActionsSchema.actions.safeParse(actions).success).toBe(false);
+ });
+
+ it("accepts one of each verb", () => {
+ expect(
+ showActionsSchema.actions.safeParse([
+ {
+ kind: "compose",
+ label: "Fix it",
+ prompt: "Fix the bug",
+ repo: "a/b",
+ },
+ { kind: "open_space", label: "Open space", channel_id: "chan" },
+ {
+ kind: "open_canvas",
+ label: "Open canvas",
+ channel_id: "chan",
+ canvas_id: "dash",
+ },
+ ]).success,
+ ).toBe(true);
+ });
+});
diff --git a/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.ts b/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.ts
new file mode 100644
index 000000000000..57e0ff91f605
--- /dev/null
+++ b/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.ts
@@ -0,0 +1,47 @@
+import { showActionSchema } from "@posthog/shared";
+import { z } from "zod";
+import { defineLocalTool, type LocalToolResult } from "../registry";
+
+export const SHOW_ACTIONS_TOOL_NAME = "show_actions";
+
+export const showActionsSchema = {
+ actions: z
+ .array(showActionSchema)
+ .min(1)
+ .max(4)
+ .describe("One to four actions, in the order they should appear."),
+};
+
+export const SHOW_ACTIONS_TOOL_DESCRIPTION =
+ "Show the user a card of clickable buttons in PostHog Desktop, so they can " +
+ "act on what you just told them without retyping it. Pass 1 to 4 actions. " +
+ "Each action is a typed verb, never a URL: there is no URL parameter and " +
+ "free-form URLs are not accepted. " +
+ "`compose` opens the new-task composer prefilled with `prompt` (and `repo` " +
+ "when given). The user reads, edits and sends it themselves, so it does NOT " +
+ "start a task and does NOT send anything on click. " +
+ "`open_space` opens a channel's feed. `open_canvas` opens a canvas inside a " +
+ "channel, and needs both `channel_id` and `canvas_id`. " +
+ "Offer only what the person actually wants to do next, in the order they " +
+ "would want it. Buttons that decorate an answer are noise, so skip the call " +
+ "entirely when there is nothing worth clicking.";
+
+/**
+ * Offers the user buttons; it does not press them. The handler only
+ * acknowledges — the desktop renderer draws them off the surfaced `tool_call`
+ * and builds the link from the typed action when a button is clicked, so
+ * nothing here can reach the user's window anyway.
+ *
+ * Ungated on purpose. A button the agent never learns it can offer is the
+ * whole failure this tool exists to avoid, so it is exposed in every session.
+ */
+export const showActionsTool = defineLocalTool({
+ name: SHOW_ACTIONS_TOOL_NAME,
+ description: SHOW_ACTIONS_TOOL_DESCRIPTION,
+ schema: showActionsSchema,
+ alwaysLoad: true,
+ isEnabled: () => true,
+ handler: async (): Promise<LocalToolResult> => {
+ return { content: [{ type: "text", text: "ok" }] };
+ },
+});
diff --git a/products/desktop/packages/core/src/sessions/showActions.test.ts b/products/desktop/packages/core/src/sessions/showActions.test.ts
new file mode 100644
index 000000000000..15d239d0b57b
--- /dev/null
+++ b/products/desktop/packages/core/src/sessions/showActions.test.ts
@@ -0,0 +1,55 @@
+import { posthogToolMeta } from "@posthog/shared";
+import { describe, expect, it } from "vitest";
+import { isUploadArtifactCall } from "./inlineArtifacts";
+import { isShowActionsCall, readShowActions } from "./showActions";
+
+function localToolMeta(tool: string) {
+ return posthogToolMeta({
+ toolName: `mcp__posthog-code-tools__${tool}`,
+ mcp: { server: "posthog-code-tools", tool },
+ });
+}
+
+describe("isShowActionsCall", () => {
+ // Both tools ride the same local server, and both draw a card instead of a
+ // tool row, so telling them apart is what keeps each card on its own call.
+ it("tells show_actions apart from its sibling local tools", () => {
+ expect(isShowActionsCall(localToolMeta("show_actions"))).toBe(true);
+ expect(isShowActionsCall(localToolMeta("upload_artifact"))).toBe(false);
+ expect(isUploadArtifactCall(localToolMeta("show_actions"))).toBe(false);
+ });
+
+ it("ignores a show_actions tool from a different MCP server", () => {
+ const foreign = posthogToolMeta({
+ toolName: "mcp__another-server__show_actions",
+ mcp: { server: "another-server", tool: "show_actions" },
+ });
+ expect(isShowActionsCall(foreign)).toBe(false);
+ });
+});
+
+describe("readShowActions", () => {
+ it("drops an action the host would refuse to open", () => {
+ const buttons = readShowActions({
+ actions: [
+ { kind: "compose", label: "Add PostHog", prompt: "/instrument" },
+ { kind: "open_space", label: "Open the space", channel_id: " " },
+ { kind: "open_website", label: "Go", url: "https://evil.example" },
+ ],
+ });
+
+ expect(buttons).toEqual([
+ {
+ label: "Add PostHog",
+ action: { kind: "compose", prompt: "/instrument" },
+ },
+ ]);
+ });
+
+ it.each([undefined, null, {}, { actions: "nope" }])(
+ "returns nothing for %s",
+ (rawInput) => {
+ expect(readShowActions(rawInput)).toEqual([]);
+ },
+ );
+});
diff --git a/products/desktop/packages/core/src/sessions/showActions.ts b/products/desktop/packages/core/src/sessions/showActions.ts
new file mode 100644
index 000000000000..9b3f5713debd
--- /dev/null
+++ b/products/desktop/packages/core/src/sessions/showActions.ts
@@ -0,0 +1,44 @@
+import {
+ readMcpToolDescriptor,
+ type ShowActionButton,
+ showActionSchema,
+ splitShowAction,
+} from "@posthog/shared";
+import { z } from "zod";
+
+const SHOW_ACTIONS_TOOL = "show_actions";
+// The local-tools MCP server that hosts show_actions. Mirrors the agent's
+// LOCAL_TOOLS_MCP_NAME, hardcoded so core need not import @posthog/agent (same
+// reason as SPEAK_TOOL_QUALIFIED_NAME). Matching the server as well as the tool
+// keeps a third-party tool that happens to be named "show_actions" out of the
+// action-buttons card, where its arguments would fail the schema and the whole
+// tool row would vanish from the conversation.
+const LOCAL_TOOLS_SERVER = "posthog-code-tools";
+
+/** The agent's `show_actions` call, which offers the user buttons to click. */
+export function isShowActionsCall(meta: unknown): boolean {
+ const descriptor = readMcpToolDescriptor(meta);
+ return (
+ descriptor?.server === LOCAL_TOOLS_SERVER &&
+ descriptor.tool === SHOW_ACTIONS_TOOL
+ );
+}
+
+// The envelope only has to be an object holding an array; each entry is judged
+// on its own below, so one bad action does not discard the rest.
+const showActionsInputSchema = z.object({ actions: z.array(z.unknown()) });
+
+/**
+ * The buttons to draw for a `show_actions` call. An action that fails the shared
+ * schema is dropped rather than drawn, so a button the host would refuse to open
+ * is never offered in the first place.
+ */
+export function readShowActions(rawInput: unknown): ShowActionButton[] {
+ const envelope = showActionsInputSchema.safeParse(rawInput);
+ if (!envelope.success) return [];
+
+ return envelope.data.actions.flatMap((entry) => {
+ const parsed = showActionSchema.safeParse(entry);
+ return parsed.success ? [splitShowAction(parsed.data)] : [];
+ });
+}
diff --git a/products/desktop/packages/host-router/src/routers/deep-link.router.ts b/products/desktop/packages/host-router/src/routers/deep-link.router.ts
index 7a9236666024..f6f09f59d315 100644
--- a/products/desktop/packages/host-router/src/routers/deep-link.router.ts
+++ b/products/desktop/packages/host-router/src/routers/deep-link.router.ts
@@ -53,6 +53,7 @@ import {
type IDeepLinkRegistry,
} from "@posthog/platform/deep-link";
import type { NotificationTarget } from "@posthog/platform/notifications";
+import { buildActionUrl, openAgentActionInput } from "@posthog/shared";
import { z } from "zod";
export const deepLinkRouter = router({
@@ -67,6 +68,18 @@ export const deepLinkRouter = router({
.handleUrl(input.url),
),
+ // A typed verb rather than a url, unlike `open` above: the agent names the
+ // action and the host builds the link, so nothing an agent writes decides
+ // where a click lands.
+ openAgentAction: publicProcedure
+ .input(openAgentActionInput)
+ .mutation(({ ctx, input }) => {
+ const deepLinks = ctx.container.get<IDeepLinkRegistry>(DEEP_LINK_SERVICE);
+ return deepLinks.handleUrl(
+ buildActionUrl(input.action, deepLinks.getProtocol()),
+ );
+ }),
+
onOpenTask: publicProcedure.subscription(async function* (opts) {
const service = opts.ctx.container.get<TaskLinkService>(TASK_LINK_SERVICE);
const iterable = service.toIterable(TaskLinkEvent.OpenTask, {
diff --git a/products/desktop/packages/shared/src/agent-actions.test.ts b/products/desktop/packages/shared/src/agent-actions.test.ts
new file mode 100644
index 000000000000..d74ab5e8ca2a
--- /dev/null
+++ b/products/desktop/packages/shared/src/agent-actions.test.ts
@@ -0,0 +1,154 @@
+import { describe, expect, it } from "vitest";
+import { type AgentAction, buildActionUrl } from "./agent-actions";
+
+describe("buildActionUrl", () => {
+ const PROD = "posthog-code";
+ const DEV = "posthog-code-dev";
+
+ function parse(url: string): {
+ protocol: string;
+ host: string;
+ pathname: string;
+ params: URLSearchParams;
+ } {
+ const parsed = new URL(url);
+ return {
+ protocol: parsed.protocol,
+ host: parsed.host,
+ pathname: parsed.pathname,
+ params: parsed.searchParams,
+ };
+ }
+
+ describe("compose", () => {
+ it("builds a new-task link with only the prompt when no repo is given", () => {
+ expect(
+ buildActionUrl({ kind: "compose", prompt: "Fix the login bug" }, PROD),
+ ).toBe("posthog-code://new?prompt=Fix%20the%20login%20bug");
+ });
+
+ it("appends the repo when one is given", () => {
+ expect(
+ buildActionUrl(
+ {
+ kind: "compose",
+ prompt: "Fix the login bug",
+ repo: "posthog/posthog",
+ },
+ PROD,
+ ),
+ ).toBe(
+ "posthog-code://new?prompt=Fix%20the%20login%20bug&repo=posthog%2Fposthog",
+ );
+ });
+
+ it.each<[string, string]>([
+ ["ampersand and query separators", "Ship A & B? #now"],
+ ["a plus sign", "Bump limit from 1+1 to 3"],
+ ["an injected extra parameter", "hi&repo=evil/repo"],
+ ["a scheme-looking string", "go to https://evil.example/?x=1#f"],
+ ["newlines and quotes", 'Line one\nLine "two"'],
+ ])("round-trips a prompt containing %s", (_label, prompt) => {
+ const url = buildActionUrl({ kind: "compose", prompt }, PROD);
+
+ const { protocol, host, params } = parse(url);
+ expect(protocol).toBe("posthog-code:");
+ expect(host).toBe("new");
+ expect(params.get("prompt")).toBe(prompt);
+ expect(params.get("repo")).toBeNull();
+ });
+
+ it("round-trips a repo containing characters that need encoding", () => {
+ const repo = "posthog/pos hog+1&x";
+ const url = buildActionUrl(
+ { kind: "compose", prompt: "Do it", repo },
+ PROD,
+ );
+
+ expect(parse(url).params.get("repo")).toBe(repo);
+ });
+ });
+
+ describe("open_space", () => {
+ it("builds the channel link", () => {
+ expect(
+ buildActionUrl(
+ {
+ kind: "open_space",
+ channel_id: "019ebc38-d862-77f2-9e56-c5ec42965758",
+ },
+ PROD,
+ ),
+ ).toBe("posthog-code://channel/019ebc38-d862-77f2-9e56-c5ec42965758");
+ });
+
+ it("percent-encodes the channel id so it cannot add path segments", () => {
+ const url = buildActionUrl(
+ { kind: "open_space", channel_id: "a/../b?c#d" },
+ PROD,
+ );
+
+ expect(url).toBe("posthog-code://channel/a%2F..%2Fb%3Fc%23d");
+ expect(decodeURIComponent(parse(url).pathname.slice(1))).toBe(
+ "a/../b?c#d",
+ );
+ });
+ });
+
+ describe("open_canvas", () => {
+ it("builds the two-segment canvas link", () => {
+ expect(
+ buildActionUrl(
+ {
+ kind: "open_canvas",
+ channel_id: "019ebc38-d862-77f2-9e56-c5ec42965758",
+ canvas_id: "dash_abc123",
+ },
+ PROD,
+ ),
+ ).toBe(
+ "posthog-code://canvas/019ebc38-d862-77f2-9e56-c5ec42965758/dash_abc123",
+ );
+ });
+
+ it("percent-encodes both ids so neither can add path segments", () => {
+ const url = buildActionUrl(
+ {
+ kind: "open_canvas",
+ channel_id: "chan/1?x",
+ canvas_id: "canvas/2#y",
+ },
+ PROD,
+ );
+
+ expect(url).toBe("posthog-code://canvas/chan%2F1%3Fx/canvas%2F2%23y");
+ const segments = parse(url).pathname.slice(1).split("/");
+ expect(segments.map((segment) => decodeURIComponent(segment))).toEqual([
+ "chan/1?x",
+ "canvas/2#y",
+ ]);
+ });
+ });
+
+ describe("dev scheme", () => {
+ it.each<[string, AgentAction, string]>([
+ [
+ "compose",
+ { kind: "compose", prompt: "Do it" },
+ "posthog-code-dev://new?prompt=Do%20it",
+ ],
+ [
+ "open_space",
+ { kind: "open_space", channel_id: "chan" },
+ "posthog-code-dev://channel/chan",
+ ],
+ [
+ "open_canvas",
+ { kind: "open_canvas", channel_id: "chan", canvas_id: "dash" },
+ "posthog-code-dev://canvas/chan/dash",
+ ],
+ ])("uses the scheme it is given for %s", (_label, action, expected) => {
+ expect(buildActionUrl(action, DEV)).toBe(expected);
+ });
+ });
+});
diff --git a/products/desktop/packages/shared/src/agent-actions.ts b/products/desktop/packages/shared/src/agent-actions.ts
new file mode 100644
index 000000000000..321b22b323e2
--- /dev/null
+++ b/products/desktop/packages/shared/src/agent-actions.ts
@@ -0,0 +1,106 @@
+import { z } from "zod";
+
+/**
+ * An action an agent offers the user as a button. It names a verb and the verb's
+ * own fields rather than a URL, and the host builds the link itself with
+ * {@link buildActionUrl}. Agent output can carry text from anywhere, so a URL it
+ * picked and the user was invited to click would be a phishing primitive.
+ *
+ * Declared once here because three packages need the same shape and none of them
+ * can import the others: the agent's tool schema, the renderer that draws the
+ * buttons, and the host procedure that opens one. `describe` text is written for
+ * the model reading the tool schema; the other two ignore it.
+ */
+const requiredField = z.string().trim().min(1);
+
+const composeFields = {
+ kind: z.literal("compose"),
+ prompt: requiredField.describe(
+ "Text to prefill the new-task composer with. The user reads it and sends " +
+ "it themselves, so nothing runs on click.",
+ ),
+ repo: requiredField
+ .optional()
+ .describe(
+ "Repository slug to preselect, e.g. `posthog/posthog`. Omit when the " +
+ "task has no repository.",
+ ),
+};
+
+const openSpaceFields = {
+ kind: z.literal("open_space"),
+ channel_id: requiredField.describe("Id of the channel whose feed to open."),
+};
+
+const openCanvasFields = {
+ kind: z.literal("open_canvas"),
+ channel_id: requiredField.describe(
+ "Id of the channel the canvas lives in. Required.",
+ ),
+ canvas_id: requiredField.describe("Id of the canvas to open. Required."),
+};
+
+/** What the host accepts and {@link buildActionUrl} turns into a link. */
+export const agentActionSchema = z.discriminatedUnion("kind", [
+ z.object(composeFields),
+ z.object(openSpaceFields),
+ z.object(openCanvasFields),
+]);
+
+export type AgentAction = z.infer<typeof agentActionSchema>;
+
+export const labelSchema = z
+ .string()
+ .trim()
+ .min(1)
+ .max(60)
+ .describe(
+ "Button text. Short and in sentence case, naming what the button does.",
+ );
+
+/**
+ * One button as the agent offers it: an action plus the text on it. `label`
+ * never reaches a link, which is why {@link agentActionSchema} leaves it out.
+ */
+export const showActionSchema = z.discriminatedUnion("kind", [
+ z.object({ ...composeFields, label: labelSchema }),
+ z.object({ ...openSpaceFields, label: labelSchema }),
+ z.object({ ...openCanvasFields, label: labelSchema }),
+]);
+
+export type ShowAction = z.infer<typeof showActionSchema>;
+
+export const openAgentActionInput = z.object({ action: agentActionSchema });
+
+/** One button as the renderer draws it: its text, and the verb behind it. */
+export interface ShowActionButton {
+ label: string;
+ action: AgentAction;
+}
+
+/** Split a button back into the text on it and the verb behind it. */
+export function splitShowAction(button: ShowAction): ShowActionButton {
+ const { label, ...action } = button;
+ return { label, action };
+}
+
+/**
+ * The action is already validated by {@link agentActionSchema}, which rejects a
+ * blank required field, so every branch can build a whole link. Keep that
+ * guarantee at the schema rather than returning a partial link from here.
+ */
+export function buildActionUrl(action: AgentAction, scheme: string): string {
+ switch (action.kind) {
+ case "compose": {
+ const prompt = `prompt=${encodeURIComponent(action.prompt)}`;
+ const query = action.repo
+ ? `${prompt}&repo=${encodeURIComponent(action.repo)}`
+ : prompt;
+ return `${scheme}://new?${query}`;
+ }
+ case "open_space":
+ return `${scheme}://channel/${encodeURIComponent(action.channel_id)}`;
+ case "open_canvas":
+ return `${scheme}://canvas/${encodeURIComponent(action.channel_id)}/${encodeURIComponent(action.canvas_id)}`;
+ }
+}
diff --git a/products/desktop/packages/shared/src/index.ts b/products/desktop/packages/shared/src/index.ts
index d18fb8e2a969..e2e84b46adee 100644
--- a/products/desktop/packages/shared/src/index.ts
+++ b/products/desktop/packages/shared/src/index.ts
@@ -1,4 +1,15 @@
export * from "./adapter";
+export {
+ type AgentAction,
+ agentActionSchema,
+ buildActionUrl,
+ labelSchema,
+ openAgentActionInput,
+ type ShowAction,
+ type ShowActionButton,
+ showActionSchema,
+ splitShowAction,
+} from "./agent-actions";
export type {
AgentAudioContent,
AgentBlobResource,
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsx
new file mode 100644
index 000000000000..4e1556e1835d
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsx
@@ -0,0 +1,57 @@
+import type { ToolCall } from "@posthog/ui/features/sessions/types";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { render, screen, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { describe, expect, it, vi } from "vitest";
+
+const openAgentAction = vi.hoisted(() => vi.fn());
+
+vi.mock("@posthog/host-router/react", () => ({
+ useHostTRPC: () => ({
+ deepLink: {
+ openAgentAction: {
+ mutationOptions: () => ({ mutationFn: openAgentAction }),
+ },
+ },
+ }),
+}));
+
+import { ShowActionsRow } from "./ShowActionsRow";
+
+function renderCard(actions: unknown[]) {
+ const toolCall = { toolCallId: "tc", rawInput: { actions } } as ToolCall;
+ return render(
+ <QueryClientProvider client={new QueryClient()}>
+ <ShowActionsRow toolCall={toolCall} turnComplete />
+ </QueryClientProvider>,
+ );
+}
+
+describe("ShowActionsRow", () => {
+ it("draws a button per usable action and drops one that cannot open anything", () => {
+ renderCard([
+ { kind: "compose", label: "Fix the bug", prompt: "Fix the login bug" },
+ { kind: "open_space", label: "Open the space", channel_id: "chan" },
+ // No canvas id, so this one could only ever build a broken link.
+ { kind: "open_canvas", label: "Open the canvas", channel_id: "chan" },
+ ]);
+
+ expect(screen.getAllByRole("button")).toHaveLength(2);
+ expect(screen.getByText("Fix the bug")).toBeTruthy();
+ expect(screen.getByText("Open the space")).toBeTruthy();
+ expect(screen.queryByText("Open the canvas")).toBeNull();
+ });
+
+ it("hands the host a typed action, never a url", async () => {
+ renderCard([
+ { kind: "open_space", label: "Open the space", channel_id: "chan" },
+ ]);
+
+ await userEvent.click(screen.getByText("Open the space"));
+
+ await waitFor(() => expect(openAgentAction).toHaveBeenCalled());
+ expect(openAgentAction.mock.calls[0]?.[0]).toEqual({
+ action: { kind: "open_space", channel_id: "chan" },
+ });
+ });
+});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsx
new file mode 100644
index 000000000000..983929c48631
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsx
@@ -0,0 +1,46 @@
+import { readShowActions } from "@posthog/core/sessions/showActions";
+import { useHostTRPC } from "@posthog/host-router/react";
+import { Button } from "@posthog/quill";
+import type { ToolViewProps } from "@posthog/ui/features/sessions/components/session-update/toolCallUtils";
+import { toast } from "@posthog/ui/primitives/toast";
+import { useMutation } from "@tanstack/react-query";
+
+/**
+ * The buttons a `show_actions` call offered, drawn where the agent offered them.
+ * A click sends the typed action to the host, which builds the link and opens
+ * it, so nothing here ever sees or chooses a url.
+ */
+export function ShowActionsRow({ toolCall }: ToolViewProps) {
+ const trpc = useHostTRPC();
+ // A click that opens nothing is the failure this tool exists to avoid. One
+ // handler covers both ways it happens: the call rejecting leaves `opened`
+ // undefined, and the host finding no handler for the link answers false.
+ const openAction = useMutation(
+ trpc.deepLink.openAgentAction.mutationOptions({
+ onSettled: (opened) => {
+ if (!opened) toast.error("Couldn't open that");
+ },
+ }),
+ );
+ const buttons = readShowActions(toolCall.rawInput);
+
+ if (buttons.length === 0) return null;
+
+ // No surrounding card: the buttons sit in the conversation, which already
+ // frames them. A box around them would draw a second frame around nothing.
+ return (
+ <div className="flex flex-wrap gap-2">
+ {buttons.map(({ label, action }, index) => (
+ <Button
+ key={`${index}-${label}`}
+ variant="outline"
+ size="sm"
+ disabled={openAction.isPending}
+ onClick={() => openAction.mutate({ action })}
+ >
+ {label}
+ </Button>
+ ))}
+ </div>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx
index 757d38a96158..bf42d9df9134 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.test.tsx
@@ -128,4 +128,33 @@ describe("ToolCallBlock codex routing", () => {
expect(screen.getByText("Wait for subagents")).toBeInTheDocument();
expect(screen.queryByText(/^Subagent/)).not.toBeInTheDocument();
});
+
+ it("shows the failure instead of live buttons when a show_actions call is denied", () => {
+ renderBlock({
+ toolCallId: "tc-show-denied",
+ title: "show_actions",
+ kind: "other",
+ status: "failed",
+ rawInput: {
+ actions: [
+ { kind: "open_space", label: "Open the space", channel_id: "chan" },
+ ],
+ },
+ content: [
+ {
+ type: "content",
+ content: { type: "text", text: "This tool has been blocked." },
+ },
+ ],
+ _meta: posthogToolMeta({
+ toolName: "mcp__local__show_actions",
+ mcp: { server: "local", tool: "show_actions" },
+ }),
+ });
+
+ // The standard tool view renders its failure marker...
+ expect(screen.getByText("(Failed)")).toBeInTheDocument();
+ // ...rather than the clickable button the block was supposed to withhold.
+ expect(screen.queryByText("Open the space")).toBeNull();
+ });
});
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.tsx
index a3d9a7f7a02b..73027cf0afea 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ToolCallBlock.tsx
@@ -1,3 +1,4 @@
+import { isShowActionsCall } from "@posthog/core/sessions/showActions";
import { useServiceOptional } from "@posthog/di/react";
import { readAgentToolName, readMcpToolName } from "@posthog/shared";
import { DeleteToolView } from "@posthog/ui/features/sessions/components/session-update/DeleteToolView";
@@ -11,7 +12,10 @@ import { ReadToolView } from "@posthog/ui/features/sessions/components/session-u
import { SearchToolView } from "@posthog/ui/features/sessions/components/session-update/SearchToolView";
import { ThinkToolView } from "@posthog/ui/features/sessions/components/session-update/ThinkToolView";
import { ToolCallView } from "@posthog/ui/features/sessions/components/session-update/ToolCallView";
-import type { ToolViewProps } from "@posthog/ui/features/sessions/components/session-update/toolCallUtils";
+import {
+ type ToolViewProps,
+ useToolCallStatus,
+} from "@posthog/ui/features/sessions/components/session-update/toolCallUtils";
import type { ToolCall } from "@posthog/ui/features/sessions/types";
import { Box } from "@radix-ui/themes";
import type { ConversationItem, TurnContext } from "../buildConversationItems";
@@ -23,6 +27,7 @@ import {
type McpToolBlockComponent,
} from "./identifiers";
import { isUploadArtifactCall, readCreatedPrUrl } from "./inlineArtifacts";
+import { ShowActionsRow } from "./ShowActionsRow";
import { SubagentToolView } from "./SubagentToolView";
interface ToolCallBlockProps extends ToolViewProps {
@@ -43,6 +48,11 @@ export function ToolCallBlock({
const toolName = readAgentToolName(toolCall._meta);
const mcpToolName = readMcpToolName(toolCall._meta);
const chatChrome = useChatThreadChrome();
+ const { isComplete } = useToolCallStatus(
+ toolCall.status,
+ turnCancelled,
+ turnComplete,
+ );
if (toolName === "EnterPlanMode") {
return null;
@@ -60,6 +70,18 @@ export function ToolCallBlock({
);
}
+ // The buttons are the point of the call, not a step it took, so a completed
+ // call takes the row instead of a tool header the user would have to expand.
+ // A denied, failed, or cancelled call falls through to the standard view,
+ // which shows why it failed rather than live buttons the block never stopped.
+ if (isShowActionsCall(toolCall._meta) && isComplete) {
+ return (
+ <div className={chatChrome ? "my-1" : "my-1 pl-3"}>
+ <ShowActionsRow {...props} />
+ </div>
+ );
+ }
+
const createdPrUrl = readCreatedPrUrl(toolCall);
if (isSubagentSpawnTool(toolName)) {