: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(signals): start a PR in one press, steer from the chevron (#91943)
Chris Volzer5bf28858b6c1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 5d62afb8d0e4..538bab5c5b7d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6945,9 +6945,13 @@ snapshots:scenes-app-inbox-cards--skeleton--light:hash: v1.k794b7964.24c19ab5df1e4ccb843b1ad726752e3a98aeadaa08595e66cb4b41aff1a9e9a1.Y3z44tkU4jsAYUyXxfl72fTuZ0MKA6_S6TTNCKt5jSgscenes-app-inbox-createprbutton--default--dark:- hash: v1.k794b7964.48c126cb2fbf7e2ff90a961fec1dbe587726b4fe10346c933e7948f0c5722fc6.o3rRliF1DHQt7OSgtsMeThXxAYCAkiUcKqRxRRaqvMg+ hash: v1.k794b7964.ed3dcef6d62105108f3ce66a23623a5ce7ab39405dfd5b58cfbdf4e48130accb.8ndY7EDwZWW7bkU8B31ICU2QZIK6Og4NxbVBPBeSn1cscenes-app-inbox-createprbutton--default--light:- hash: v1.k794b7964.afd9c8a70584e887de98dc27361817c64057c32da340ceb85f4584212bfb2dad.J1FNKAVCovRg8LIuY9uoXEFCuQ6MlUp1kFs6aJ33X5Y+ hash: v1.k794b7964.451bf28e6745e87d652309ff7e700df19787f6a8eb1caea6511b3e167e267066.4wCG_I6-hdtHnB3OoYj3gV851OxePPZfWws6tpJ2mDk+ scenes-app-inbox-createprbutton--steering--dark:+ hash: v1.k794b7964.ed2c06f0785093b47269ea129ee4394971e399fe288dc9a394520a402456b260.moDVSzdoUZiJ8U-tm2T24s9NiTehnObGxIHlVOZOi24+ scenes-app-inbox-createprbutton--steering--light:+ hash: v1.k794b7964.90e380944266cf30b04a4066e14121297ea3b2a184face92194ec23350a384f1.As5SqMtAtiDIaP486BIfIfDUzkbg6xMi-ths87o8MeEscenes-app-inbox-detail--pull-request--dark:hash: v1.k794b7964.e3d35a1f32d39211cf8bd41914c83ec6e4ed9e0251e8b883a8fa62c048dc4165.na0HIQko2FwF9KTcKxD66kvttld6IbR_S0bejyK_1hsscenes-app-inbox-detail--pull-request--light:diff --git a/products/signals/frontend/inbox/components/detail/CreatePrButton.stories.tsx b/products/signals/frontend/inbox/components/detail/CreatePrButton.stories.tsxindex dc4ab3cb79aa..61694e38b273 100644--- a/products/signals/frontend/inbox/components/detail/CreatePrButton.stories.tsx+++ b/products/signals/frontend/inbox/components/detail/CreatePrButton.stories.tsx@@ -8,26 +8,31 @@ import { CreatePrButton } from './CreatePrButton'const meta: Meta<typeof CreatePrButton> = {title: 'Scenes-App/Inbox/CreatePrButton',component: CreatePrButton,- parameters: { layout: 'centered', testOptions: { snapshotTargetSelector: '.Popover' } },+ parameters: { layout: 'centered' },}export default metatype Story = StoryObj<typeof CreatePrButton>-// The popover is closed until the trigger is pressed, so the story opens it — otherwise the-// snapshot is of the same small button and the note box under review never renders. `findByText`-// rather than `getByText`: the trigger mounts a kea logic chain reaching organization and user-// state, so on a slow runner the play function can reach an empty canvas and fail the story.-const openPopover: Story['play'] = async ({ canvasElement }) => {- await userEvent.click(await within(canvasElement).findByText('Create PR'))- await waitFor(() => {- if (!document.querySelector('.Popover')) {- throw new Error('popover not open yet')- }- })-}+const report = makeReport({ title: 'Exceptions spiked after the 18 June deploy' })+/** The resting split button. The divider is the only cue that the chevron does something else. */export const Default: Story = {- render: () => <CreatePrButton report={makeReport({ title: 'Exceptions spiked after the 18 June deploy' })} />,- play: openPopover,+ render: () => <CreatePrButton report={report} />,+}++// The note box is closed until the chevron is pressed, so the story opens it. `findByLabelText`+// rather than `getByLabelText`: the button mounts a kea logic chain reaching organization and user+// state, so on a slow runner the play function can reach an empty canvas and fail the story.+export const Steering: Story = {+ parameters: { testOptions: { snapshotTargetSelector: '.Popover' } },+ render: () => <CreatePrButton report={report} />,+ play: async ({ canvasElement }) => {+ await userEvent.click(await within(canvasElement).findByLabelText('Add direction for the agent'))+ await waitFor(() => {+ if (!document.querySelector('.Popover')) {+ throw new Error('note box not open yet')+ }+ })+ },}diff --git a/products/signals/frontend/inbox/components/detail/CreatePrButton.test.tsx b/products/signals/frontend/inbox/components/detail/CreatePrButton.test.tsxindex 48e4ca35e918..09849bf77dae 100644--- a/products/signals/frontend/inbox/components/detail/CreatePrButton.test.tsx+++ b/products/signals/frontend/inbox/components/detail/CreatePrButton.test.tsx@@ -1,6 +1,6 @@import '@testing-library/jest-dom'-import { cleanup, render, screen } from '@testing-library/react'+import { cleanup, render, screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { initKeaTests } from '~/test/init'@@ -47,17 +47,31 @@ describe('CreatePrButton', () => {jest.restoreAllMocks()})- async function openPopover(): Promise<ReturnType<typeof userEvent.setup>> {+ async function openNoteBox(): Promise<ReturnType<typeof userEvent.setup>> {const user = userEvent.setup()render(<CreatePrButton report={makeReport()} />)- await user.click(screen.getByText('Create PR'))+ await user.click(screen.getByTestId('inbox-report-create-pr-steer'))+ await waitFor(() => expect(screen.getByRole('textbox')).toHaveFocus())return user}+ it('starts an unsteered run from the main half, with no note box in the way', async () => {+ // The point of the split: the common case is one press. A regression that routes the main+ // half back into the popover shows up here as a missing call.+ const user = userEvent.setup()+ render(<CreatePrButton report={makeReport()} />)++ await user.click(screen.getByTestId('inbox-report-create-pr'))++ expect(createPrFromReport).toHaveBeenCalledWith(expect.objectContaining({ id: 'report-1' }), undefined)+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument()+ expect(jest.mocked(captureInboxReportAction).mock.calls[0][0].extra).toEqual({ has_feedback: false })+ })+it('passes a typed note to the agent and marks the action as steered', async () => {// The whole feature: a note in the box has to reach the prompt, or steering does nothing. The// `has_feedback` flag is how we compare steered runs against unsteered ones.- const user = await openPopover()+ const user = await openNoteBox()await user.type(screen.getByRole('textbox'), ' Put the fix behind a flag. ')await user.click(screen.getByTestId('inbox-report-create-pr-submit'))@@ -69,13 +83,13 @@ describe('CreatePrButton', () => {expect(jest.mocked(captureInboxReportAction).mock.calls[0][0].extra).toEqual({ has_feedback: true })})- it('fires with no note when the box is empty, exactly as the old button did', async () => {- // Empty is the common case and must stay a one-press action, with no feedback appended.- const user = await openPopover()+ it('submits the note on Enter without moving focus first', async () => {+ // Guards the two halves of the shortcut at once: the box takes focus when it opens, and plain+ // Enter submits. `onPressCmdEnter` would leave both typing and Enter with nothing to act on.+ const user = await openNoteBox()- await user.click(screen.getByTestId('inbox-report-create-pr-submit'))+ await user.keyboard('Backend only.{Enter}')- expect(createPrFromReport).toHaveBeenCalledWith(expect.objectContaining({ id: 'report-1' }), undefined)- expect(jest.mocked(captureInboxReportAction).mock.calls[0][0].extra).toEqual({ has_feedback: false })+ expect(createPrFromReport).toHaveBeenCalledWith(expect.objectContaining({ id: 'report-1' }), 'Backend only.')})})diff --git a/products/signals/frontend/inbox/components/detail/CreatePrButton.tsx b/products/signals/frontend/inbox/components/detail/CreatePrButton.tsxindex 886a29c4d4ed..8bc94221157c 100644--- a/products/signals/frontend/inbox/components/detail/CreatePrButton.tsx+++ b/products/signals/frontend/inbox/components/detail/CreatePrButton.tsx@@ -1,11 +1,10 @@import { useActions, useValues } from 'kea'-import { useRef, useState } from 'react'+import { useState } from 'react'-import { IconChevronDown, IconPullRequest } from '@posthog/icons'+import { IconPullRequest } from '@posthog/icons'import { LemonButton, lemonToast } from '@posthog/lemon-ui'import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'-import { Popover } from 'lib/lemon-ui/Popover'import { captureInboxReportAction } from '../../inboxAnalytics'import { inboxTaskKickoffLogic } from '../../inboxTaskKickoffLogic'@@ -16,20 +15,22 @@ import { SignalReport } from '../../types'const PLACEHOLDER = 'Add direction for the agent (optional)…'/**- * The detail-pane "Create PR" action. It opens a popover with an optional note instead of firing on- * click, so the reader can steer the agent (behind a flag, backend only, skip the migration) at the- * moment they have the most context. An empty note behaves exactly as the old fire-on-click button.+ * The detail-pane "Create PR" action, as a split button.+ *+ * The main half starts the run immediately, because an unsteered run is the common case. The+ * chevron half opens a note box, so the reader can steer the agent (behind a flag, backend only,+ * skip the migration) at the moment they have the most context. A note is optional, so both halves+ * reach the same action and only the note differs.** A component, not a `ReportDetailAction`, because actions collapse into a `LemonMenu` on narrow- * layouts and a menu item can't own a popover — this mirrors `DiscussReportButton` for the same reason.+ * layouts and a menu item cannot own a popover. `DiscussReportButton` is a component for the same+ * reason.*/export function CreatePrButton({ report }: { report: SignalReport }): JSX.Element {const { isCreatingPr, aiConsentDisabledReason } = useValues(inboxTaskKickoffLogic)// Already mounted by `ReportDetail`, so this reads the loaded value rather than starting a fetch.const { hasLiveImplementationTask } = useValues(inboxReportDetailLogic({ reportId: report.id, report }))const { createPrFromReport } = useActions(inboxTaskKickoffLogic)- const buttonRef = useRef<HTMLButtonElement>(null)- const [isOpen, setIsOpen] = useState(false)const [feedback, setFeedback] = useState('')const disabledReason =@@ -38,9 +39,9 @@ export function CreatePrButton({ report }: { report: SignalReport }): JSX.Elemen? 'A PR task already exists for this report. Open it in the task log to continue.': undefined)- const submit = (): void => {- // Cmd/Ctrl + Enter submits straight from the textarea, so it never sees the trigger's- // `disabledReason` — each guard has to hold here too, or a press fires a paid run anyway.+ const submit = (note: string): void => {+ // Enter submits straight from the textarea, so it never sees the button's `disabledReason`.+ // Each guard has to hold here too, or a keypress starts a paid run anyway.if (isCreatingPr || hasLiveImplementationTask) {return}@@ -48,74 +49,73 @@ export function CreatePrButton({ report }: { report: SignalReport }): JSX.ElemenlemonToast.error(aiConsentDisabledReason)return}- const trimmed = feedback.trim()+ const trimmed = note.trim()captureInboxReportAction({report,actionType: 'create_pr',surface: 'detail_pane',extra: { has_feedback: trimmed.length > 0 },})- // The popover stays open on its spinner until the run is created and we navigate to it, so a- // failure leaves the note to retry with.createPrFromReport(report, trimmed || undefined)}return (- <Popover- visible={isOpen}- onClickOutside={(event) => {- if (event.target instanceof Node && buttonRef.current?.contains(event.target)) {- return- }- setIsOpen(false)+ <LemonButton+ type="primary"+ size="small"+ icon={<IconPullRequest />}+ onClick={() => submit('')}+ loading={isCreatingPr}+ disabledReason={disabledReason}+ tooltip="Have Self-driving open a pull request for this report"+ data-attr="inbox-report-create-pr"+ sideAction={{+ tooltip: 'Add direction before the agent starts',+ 'aria-label': 'Add direction for the agent',+ 'data-attr': 'inbox-report-create-pr-steer',+ dropdown: {+ placement: 'bottom-end',+ // The box holds a textarea, so a click inside it must not close the popover. The+ // popover also stays open on its spinner until the run is created and we navigate+ // to it, which leaves the note to retry with after a failure.+ closeOnClickInside: false,+ overlay: (+ <div className="flex flex-col gap-2 p-2 w-96">+ <LemonTextArea+ value={feedback}+ onChange={setFeedback}+ onPressEnter={submit}+ placeholder={PLACEHOLDER}+ maxLength={4000}+ rows={4}+ autoFocus+ // The hint goes in the left slot so the character counter, which+ // `maxLength` puts in the right one, has room of its own.+ actions={[+ <span key="shortcut" className="text-xs text-tertiary">+ Enter to create PR, Shift + Enter for a new line+ </span>,+ ]}+ />+ <div className="flex justify-end">+ <LemonButton+ type="primary"+ size="small"+ icon={<IconPullRequest />}+ onClick={() => submit(feedback)}+ loading={isCreatingPr}+ disabledReason={disabledReason}+ data-attr="inbox-report-create-pr-submit"+ >+ Create PR+ </LemonButton>+ </div>+ </div>+ ),+ },}}- placement="bottom-end"- overlay={- <div className="flex flex-col gap-2 p-2 w-[22rem]">- <LemonTextArea- value={feedback}- onChange={setFeedback}- onPressCmdEnter={submit}- placeholder={PLACEHOLDER}- maxLength={4000}- rows={4}- autoFocus- rightFooter={<span className="text-xs text-tertiary">Cmd/Ctrl + Enter to create PR</span>}- />- <div className="flex justify-end">- <LemonButton- type="primary"- size="small"- icon={<IconPullRequest />}- onClick={submit}- loading={isCreatingPr}- disabledReason={disabledReason}- data-attr="inbox-report-create-pr-submit"- >- Create PR- </LemonButton>- </div>- </div>- }>- <LemonButton- ref={buttonRef}- type="primary"- size="small"- icon={<IconPullRequest />}- // Keeps the chevron the plain button never had, so a returning reader sees it now- // opens a note box before it fires.- sideIcon={<IconChevronDown />}- active={isOpen}- loading={isCreatingPr}- // The trigger always opens, even when consent is missing or a PR task already exists;- // the reason sits on the submit inside, next to the thing it blocks.- tooltip="Have Self-driving open a pull request for this report"- onClick={() => setIsOpen((open) => !open)}- data-attr="inbox-report-create-pr"- >- Create PR- </LemonButton>- </Popover>+ Create PR+ </LemonButton>)}