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(signals): add agent handoffs to inbox (#101203)

Mikayla Thompson44a142d4291a
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 1cccd1065dae..de1b864f6582 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8128,6 +8128,10 @@ snapshots:
hash: v1.k794b7964.7b457e88868510c008646ab0ed37de232ec66ccbd001e82256e156e44a4cfa23.38qy-CrE1s8-psQTdpOZqMVW5alFzYnH7On3bETCnGU
scenes-app-inbox-detail--report-minimal--light:
hash: v1.k794b7964.1ec199f350734471b4a0b1463ff94a4654a30424276fc64c115c3d65db3cdb41.Tc9W_NbKBqiZUS8nJ_J48f161oSMbOpTNtd99CK-a5I
+ scenes-app-inbox-detail--report-ready-to-implement--dark:
+ hash: v1.k794b7964.0516b8985888b92018506cee3a0cf40c7f7499027455fb8f6957853a91440557.m5kKe7m4ITNuyQyusa72o9rk-dyF5d5QOps4_rNLuRM
+ scenes-app-inbox-detail--report-ready-to-implement--light:
+ hash: v1.k794b7964.f42eb359e62e037d7b75d0348f507dea76b69e442f80adc8b54736e0edcd8da5.CnKeyAMmz5IP5UQXp6G_6mWUR0C0BmaCm5qSIt7egqU
scenes-app-inbox-detail--report-with-metrics--dark:
hash: v1.k794b7964.90a96dde882ddfb529a258d651ce9701878bfa46ab5a7de6718aa96298ca84de.m7fGQx62WwLVg35wZgG7MsKHRzQovXeepkAqKTT4-WU
scenes-app-inbox-detail--report-with-metrics--light:
@@ -8161,9 +8165,9 @@ snapshots:
scenes-app-inbox-hotkeyradio--with-selection--light:
hash: v1.k794b7964.3e50641442cc87cebfb5e0380042c05c0e5f15e238011e5aab24f8e69da5ea8e.IarzlyKga2lc-4CZ8UpBjuU1D_75I4SRnyKDESA9drk
scenes-app-inbox-implementbutton--choices--dark:
- hash: v1.k794b7964.f92d5686aae66110b8d50afdb16572300047046f49f2a1ecc9c44235d86218e5.nS3wP7CmKoWWDO2gXGzHUOiQMiI2VmTtPRzyJuDGrBA
+ hash: v1.k794b7964.04e3f5a9e20f0032cff25e7878e16328871b41813d2a4e3064e731f91d3b876c.hVFY_MWjWZDX4fr9y2vacAy3wHZuNHwp5cYjveu_KfE
scenes-app-inbox-implementbutton--choices--light:
- hash: v1.k794b7964.a5e76b4728730d9ad98eab8e787718804ff25619a38fce6acbe6354ac7f04ae8.CU7kUOfZ59HG6vxqJDQSywe8luerIxfx7w16zcz92Pc
+ hash: v1.k794b7964.a179eeb16be74806e49a273f5e2df6c06e6c729f4696b7ea08806c515c508a5d.oPurfCP4WUVbo_EKSrjGF6FooFGZbvNcJjXEp9VK-R8
scenes-app-inbox-implementbutton--default--dark:
hash: v1.k794b7964.f2b5351f205a0abb1531706c02950c727ede9d9f7cf220869b571442805a5a24.NvzH40X-7cVbDTiW0u9CRIwI3ENeZ37ePippBtcZg2M
scenes-app-inbox-implementbutton--default--light:
diff --git a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx
index fdfe40214288..54e3ef18426c 100644
--- a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx
+++ b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx
@@ -8,6 +8,8 @@ import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
import {
DropdownMenu,
DropdownMenuContent,
+ DropdownMenuGroup,
+ DropdownMenuItem,
DropdownMenuItemIndicator,
DropdownMenuLabel,
DropdownMenuRadioGroup,
@@ -35,6 +37,8 @@ export interface AgentPromptAction {
buildPrompt: () => string
}
+export type AgentPromptDestination = 'posthog-ai' | 'posthog-code' | 'claude-code' | 'cursor' | 'codex' | 'clipboard'
+
/** Quill button sizes, minus the icon-only variants (the dropdown trigger derives those automatically). */
type AgentPromptButtonSize = Exclude<NonNullable<QuillButtonProps['size']>, 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg'>
@@ -51,7 +55,9 @@ export interface AgentPromptButtonProps {
/** Content selected when nothing is stored yet. Falls back to the first action. */
defaultActionKey?: string
/** Destination selected when nothing is stored yet. Falls back to the first agent. */
- defaultAgentKey?: string
+ defaultAgentKey?: AgentPromptDestination
+ agentKeys?: AgentPromptDestination[]
+ agentSelectionMode?: 'select' | 'run'
size?: AgentPromptButtonSize
variant?: NonNullable<QuillButtonProps['variant']>
/** Renders the dropdown open on first paint. Useful for visual regression snapshots. */
@@ -69,7 +75,7 @@ interface RememberedCombo {
}
interface AgentDef {
- key: string
+ key: AgentPromptDestination
name: string
/** Either a brand SVG URL (string from `import foo from './logos/foo.svg'`) or a React node */
logo: string | React.ReactElement
@@ -105,6 +111,24 @@ export function buildPostHogCodeDeepLink(prompt: string, repository?: string): s
return `posthog-code://new?prompt=${encodeURIComponent(prompt)}${repoParam}`
}
+export function buildClaudeCodeDeepLink(prompt: string, repository?: string): string {
+ const query = withLimit(prompt, LIMIT_CLAUDE, (text) => encodeURIComponent(text))
+ const repoParam = repository ? `repo=${encodeURIComponent(repository)}&` : ''
+ return `claude-cli://open?${repoParam}q=${query}`
+}
+
+export function buildCursorDeepLink(prompt: string): string {
+ return withLimit(
+ prompt,
+ LIMIT_LONG,
+ (text) => `cursor://anysphere.cursor-deeplink/prompt?text=${encodeURIComponent(encodeURIComponent(text))}`
+ )
+}
+
+export function buildCodexDeepLink(prompt: string): string {
+ return withLimit(prompt, LIMIT_SHORT, (text) => `codex://new?prompt=${encodeURIComponent(text)}`)
+}
+
const AGENTS: AgentDef[] = [
{
key: 'posthog-ai',
@@ -125,11 +149,7 @@ const AGENTS: AgentDef[] = [
name: 'Claude Code',
logo: claudeLogo,
verb: 'Open',
- open: (prompt, { repository }) => {
- const query = withLimit(prompt, LIMIT_CLAUDE, (t) => encodeURIComponent(t))
- const repoParam = repository ? `repo=${encodeURIComponent(repository)}&` : ''
- window.open(`claude-cli://open?${repoParam}q=${query}`, '_blank')
- },
+ open: (prompt, { repository }) => window.open(buildClaudeCodeDeepLink(prompt, repository), '_blank'),
},
{
key: 'cursor',
@@ -138,21 +158,15 @@ const AGENTS: AgentDef[] = [
// Cursor wordmark is solid black; invert in dark mode so it stays visible
logoClassName: 'dark:invert',
verb: 'Open',
- open: openDeepLink((p) =>
- // Cursor decodes the full deeplink before parsing query params, so reserved chars need an extra escape layer.
- withLimit(
- p,
- LIMIT_LONG,
- (t) => `cursor://anysphere.cursor-deeplink/prompt?text=${encodeURIComponent(encodeURIComponent(t))}`
- )
- ),
+ // Cursor decodes the full deeplink before parsing query params, so reserved chars need an extra escape layer.
+ open: openDeepLink(buildCursorDeepLink),
},
{
key: 'codex',
name: 'Codex',
logo: openaiLogo,
verb: 'Open',
- open: openDeepLink((p) => withLimit(p, LIMIT_SHORT, (t) => `codex://new?prompt=${encodeURIComponent(t)}`)),
+ open: openDeepLink(buildCodexDeepLink),
},
{
key: 'clipboard',
@@ -170,6 +184,8 @@ export function AgentPromptButton({
storageKey,
defaultActionKey,
defaultAgentKey,
+ agentKeys,
+ agentSelectionMode = 'select',
size = 'default',
variant = 'default',
defaultOpen = false,
@@ -186,8 +202,9 @@ export function AgentPromptButton({
const [remembered, setRemembered] = useLocalStorage<RememberedCombo | null>(`${resolvedStorageKey}:combo`, null)
const [open, setOpen] = useState(defaultOpen)
const { askSidePanelMax } = useActions(maxGlobalLogic)
+ const availableAgents = agentKeys ? AGENTS.filter((agent) => agentKeys.includes(agent.key)) : AGENTS
- if (actions.length === 0) {
+ if (actions.length === 0 || availableAgents.length === 0) {
return null
}
@@ -195,10 +212,12 @@ export function AgentPromptButton({
(remembered ? actions.find((a) => a.key === remembered.actionKey) : null) ??
actions.find((a) => a.key === defaultActionKey) ??
actions[0]
+ const defaultAgent = availableAgents.find((a) => a.key === defaultAgentKey) ?? availableAgents[0]
const activeAgent =
- (remembered?.agentKey ? AGENTS.find((a) => a.key === remembered.agentKey) : null) ??
- AGENTS.find((a) => a.key === defaultAgentKey) ??
- AGENTS[0]
+ agentSelectionMode === 'run'
+ ? defaultAgent
+ : ((remembered?.agentKey ? availableAgents.find((a) => a.key === remembered.agentKey) : null) ??
+ defaultAgent)
const buttonLabel = `${activeAgent.verb} ${activeAction.label}`
const selectAction = (actionKey: string): void => {
@@ -209,7 +228,7 @@ export function AgentPromptButton({
const action = actions.find((a) => a.key === actionKey) ?? actions[0]
const prompt = action.buildPrompt()
onRun?.({ actionKey, agentKey })
- const agent = AGENTS.find((a) => a.key === agentKey)
+ const agent = availableAgents.find((a) => a.key === agentKey)
if (!agent) {
return
}
@@ -218,6 +237,11 @@ export function AgentPromptButton({
const selectAgent = (agentKey: string): void => {
const actionKey = remembered?.actionKey ?? actions[0].key
+ if (agentSelectionMode === 'run') {
+ runCombo(actionKey, agentKey)
+ setOpen(false)
+ return
+ }
setRemembered({ actionKey, agentKey })
setOpen(false)
}
@@ -246,6 +270,9 @@ export function AgentPromptButton({
variant={variant}
size={size === 'default' ? 'icon' : `icon-${size}`}
className="border-0"
+ aria-label={
+ agentSelectionMode === 'run' ? 'Open prompt in an agent' : 'Choose prompt and destination'
+ }
>
<IconChevronDown className="size-4 text-current" />
</QuillButton>
@@ -277,18 +304,33 @@ export function AgentPromptButton({
<DropdownMenuSeparator className="mx-0" />
</>
)}
- <DropdownMenuLabel>Destination</DropdownMenuLabel>
- <DropdownMenuRadioGroup value={activeAgent.key} onValueChange={selectAgent}>
- {AGENTS.map((agent) => (
- <DropdownMenuRadioItem key={agent.key} value={agent.key} asChild>
- <ButtonPrimitive menuItem className="gap-1.5">
- <AgentLogo logo={agent.logo} logoClassName={agent.logoClassName} />
- <span className="truncate flex-1">{agent.name}</span>
- <DropdownMenuItemIndicator intent="radio" />
- </ButtonPrimitive>
- </DropdownMenuRadioItem>
- ))}
- </DropdownMenuRadioGroup>
+ <DropdownMenuLabel>{agentSelectionMode === 'run' ? 'Open in' : 'Destination'}</DropdownMenuLabel>
+ {agentSelectionMode === 'run' ? (
+ <DropdownMenuGroup>
+ {availableAgents
+ .filter((agent) => agent.key !== activeAgent.key)
+ .map((agent) => (
+ <DropdownMenuItem key={agent.key} asChild onSelect={() => selectAgent(agent.key)}>
+ <ButtonPrimitive menuItem className="gap-1.5">
+ <AgentLogo logo={agent.logo} logoClassName={agent.logoClassName} />
+ <span className="truncate flex-1">{agent.name}</span>
+ </ButtonPrimitive>
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuGroup>
+ ) : (
+ <DropdownMenuRadioGroup value={activeAgent.key} onValueChange={selectAgent}>
+ {availableAgents.map((agent) => (
+ <DropdownMenuRadioItem key={agent.key} value={agent.key} asChild>
+ <ButtonPrimitive menuItem className="gap-1.5">
+ <AgentLogo logo={agent.logo} logoClassName={agent.logoClassName} />
+ <span className="truncate flex-1">{agent.name}</span>
+ <DropdownMenuItemIndicator intent="radio" />
+ </ButtonPrimitive>
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ )}
</DropdownMenuContent>
</DropdownMenu>
)
diff --git a/frontend/src/lib/components/AgentPromptButton/index.ts b/frontend/src/lib/components/AgentPromptButton/index.ts
index ea22d7d839b9..2304e0faf611 100644
--- a/frontend/src/lib/components/AgentPromptButton/index.ts
+++ b/frontend/src/lib/components/AgentPromptButton/index.ts
@@ -1,2 +1,8 @@
-export type { AgentPromptAction, AgentPromptButtonProps } from './AgentPromptButton'
-export { AgentPromptButton } from './AgentPromptButton'
+export type { AgentPromptAction, AgentPromptButtonProps, AgentPromptDestination } from './AgentPromptButton'
+export {
+ AgentPromptButton,
+ buildClaudeCodeDeepLink,
+ buildCodexDeepLink,
+ buildCursorDeepLink,
+ buildPostHogCodeDeepLink,
+} from './AgentPromptButton'
diff --git a/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx b/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx
index ae1a31a1fb1a..fc6526490831 100644
--- a/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx
+++ b/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx
@@ -47,6 +47,7 @@ describe('ImplementButton', () => {
beforeEach(() => {
initKeaTests()
+ window.localStorage.removeItem('inbox-report-implementation-prompt:combo')
inboxTaskKickoffLogic.mount()
createPrFromReport = jest.fn()
jest.spyOn(inboxTaskKickoffLogic.actions, 'createPrFromReport').mockImplementation(createPrFromReport)
@@ -146,9 +147,37 @@ describe('ImplementButton', () => {
expect(prompt).toContain('claim the report with inbox-reports-claim')
expect(prompt).toContain('pr_url to attach it')
expect(prompt).toContain('release=true')
- expect(copyToClipboard).toHaveBeenCalledWith(prompt, 'implementation prompt')
+ expect(copyToClipboard).toHaveBeenCalledWith(prompt, 'prompt for your agent')
expect(captureInboxReportAction).toHaveBeenCalledWith(
- expect.objectContaining({ actionType: 'copy_implementation_prompt' })
+ expect.objectContaining({
+ actionType: 'copy_implementation_prompt',
+ extra: { agent: 'clipboard' },
+ })
+ )
+ })
+
+ it('opens the implementation prompt from the agent list without changing the copy action', async () => {
+ const user = await openMenu()
+ const open = jest.spyOn(window, 'open').mockImplementation()
+
+ await user.click(screen.getByLabelText('Open prompt in an agent'))
+
+ expect(screen.queryByText('PostHog AI')).not.toBeInTheDocument()
+ await user.click(screen.getByText('Claude Code'))
+
+ expect(open).toHaveBeenCalledWith(expect.stringMatching(/^claude-cli:\/\/open\?q=/), '_blank')
+ expect(captureInboxReportAction).toHaveBeenCalledWith(
+ expect.objectContaining({
+ actionType: 'copy_implementation_prompt',
+ extra: { agent: 'claude-code' },
+ })
+ )
+
+ await user.click(screen.getByTestId('inbox-report-copy-implementation-prompt'))
+
+ expect(copyToClipboard).toHaveBeenCalledWith(
+ expect.stringContaining('report ID: report-1'),
+ 'prompt for your agent'
)
})
})
diff --git a/products/signals/frontend/inbox/components/detail/ImplementButton.tsx b/products/signals/frontend/inbox/components/detail/ImplementButton.tsx
index 94df3d2f2ba7..91368a4e23f9 100644
--- a/products/signals/frontend/inbox/components/detail/ImplementButton.tsx
+++ b/products/signals/frontend/inbox/components/detail/ImplementButton.tsx
@@ -1,9 +1,17 @@
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { IconCopy, IconPullRequest } from '@posthog/icons'
-import { LemonButton, lemonToast } from '@posthog/lemon-ui'
+import { IconCopy, IconLogomark, IconPullRequest } from '@posthog/icons'
+import { LemonButton, LemonMenuOverlay, lemonToast } from '@posthog/lemon-ui'
+import {
+ buildClaudeCodeDeepLink,
+ buildCodexDeepLink,
+ buildCursorDeepLink,
+ buildPostHogCodeDeepLink,
+} from 'lib/components/AgentPromptButton'
+import type { AgentPromptDestination } from 'lib/components/AgentPromptButton'
+import { AgentLogo, claudeLogo, cursorLogo, openaiLogo } from 'lib/components/AgentPromptButton/AgentLogo'
import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { addProjectIdIfMissing } from 'lib/utils/kea-router'
@@ -20,6 +28,38 @@ const SLOT_CLAIM_DISABLED_REASON: Record<ImplementationSlotClaim, string> = {
shipped_pr: 'This report already has a pull request. Open it in the task log to continue it.',
}
+const IMPLEMENTATION_AGENTS: {
+ key: AgentPromptDestination
+ name: string
+ icon: JSX.Element
+ buildDeepLink: (prompt: string) => string
+}[] = [
+ {
+ key: 'posthog-code',
+ name: 'PostHog Desktop',
+ icon: <IconLogomark />,
+ buildDeepLink: buildPostHogCodeDeepLink,
+ },
+ {
+ key: 'claude-code',
+ name: 'Claude Code',
+ icon: <AgentLogo logo={claudeLogo} />,
+ buildDeepLink: buildClaudeCodeDeepLink,
+ },
+ {
+ key: 'cursor',
+ name: 'Cursor',
+ icon: <AgentLogo logo={cursorLogo} logoClassName="dark:invert" />,
+ buildDeepLink: buildCursorDeepLink,
+ },
+ {
+ key: 'codex',
+ name: 'Codex',
+ icon: <AgentLogo logo={openaiLogo} />,
+ buildDeepLink: buildCodexDeepLink,
+ },
+]
+
export function ImplementButton({ report }: { report: SignalReport }): JSX.Element {
const { isCreatingPr, isDiscussing, createPrDisabledReason } = useValues(inboxTaskKickoffLogic)
const { implementationSlotClaim, reportTaskToOpen } = useValues(
@@ -52,18 +92,15 @@ export function ImplementButton({ report }: { report: SignalReport }): JSX.Eleme
createPrFromReport(report, trimmed || undefined)
}
- const copyImplementationPrompt = async (): Promise<void> => {
- const copied = await copyToClipboard(
- buildReportImplementationPrompt(report, reportUrl),
- 'implementation prompt'
- )
- if (copied) {
- captureInboxReportAction({
- report,
- actionType: 'copy_implementation_prompt',
- surface: 'detail_pane',
- })
- }
+ const runImplementationPrompt = (agentKey: AgentPromptDestination, run: (prompt: string) => void): void => {
+ const prompt = buildReportImplementationPrompt(report, reportUrl)
+ captureInboxReportAction({
+ report,
+ actionType: 'copy_implementation_prompt',
+ surface: 'detail_pane',
+ extra: { agent: agentKey },
+ })
+ run(prompt)
}
if (reportTaskToOpen?.task.latest_run) {
@@ -105,7 +142,7 @@ export function ImplementButton({ report }: { report: SignalReport }): JSX.Eleme
placement: 'bottom-end',
closeOnClickInside: false,
overlay: (
- <div className="flex w-120 flex-col gap-2 p-2">
+ <div className="flex w-128 flex-col gap-2 p-2">
<span className="text-xs font-semibold text-tertiary">
Add instructions for the PostHog agent
</span>
@@ -127,8 +164,32 @@ export function ImplementButton({ report }: { report: SignalReport }): JSX.Eleme
<LemonButton
type="secondary"
icon={<IconCopy />}
- onClick={() => void copyImplementationPrompt()}
+ onClick={() =>
+ runImplementationPrompt('clipboard', (prompt) => {
+ void copyToClipboard(prompt, 'prompt for your agent')
+ })
+ }
data-attr="inbox-report-copy-implementation-prompt"
+ sideAction={{
+ tooltip: 'Open prompt in an agent',
+ 'aria-label': 'Open prompt in an agent',
+ dropdown: {
+ placement: 'bottom-start',
+ overlay: (
+ <LemonMenuOverlay
+ items={IMPLEMENTATION_AGENTS.map((agent) => ({
+ key: agent.key,
+ label: agent.name,
+ icon: agent.icon,
+ onClick: () =>
+ runImplementationPrompt(agent.key, (prompt) => {
+ window.open(agent.buildDeepLink(prompt), '_blank')
+ }),
+ }))}
+ />
+ ),
+ },
+ }}
>
Copy prompt for your agent
</LemonButton>
diff --git a/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx b/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx
index 57fe7cdf0c78..b469f0de07c1 100644
--- a/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx
+++ b/products/signals/frontend/inbox/components/detail/InboxDetail.stories.tsx
@@ -117,6 +117,21 @@ const detailMocks = mswDecorator({
},
})
+const readyToImplementMocks = mswDecorator({
+ get: {
+ '/api/projects/:id/signals/reports/:reportId/artefacts': (req) => {
+ const artefacts = mockArtefacts(req.params.reportId as string)
+ return [
+ 200,
+ {
+ ...artefacts,
+ results: artefacts.results.filter((artefact) => artefact.type !== 'task_run'),
+ },
+ ]
+ },
+ },
+})
+
const meta: Meta = {
title: 'Scenes-App/Inbox/Detail',
parameters: {
@@ -143,6 +158,15 @@ export const Report: Story = {
),
}
+export const ReportReadyToImplement: Story = {
+ decorators: [readyToImplementMocks],
+ render: () => (
+ <Frame>
+ <ReportDetail report={reportTabReports[0]} />
+ </Frame>
+ ),
+}
+
export const ReportWithMetrics: Story = {
render: () => (
<Frame>