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(replay-vision): mark the scanner goal overview as a draft to review (#127621)

Kim Svatos Dugan9a4b1ba3c286
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 3c8b2d5e8e53..1c19ca7af75d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -15083,9 +15083,9 @@ snapshots:
scenes-app-replay-vision--scanner-editor-goal-overview-long-filters--light:
hash: v1.k794b7964.7a8ee25c52a654a3714bfa0f25ff8e64c5752dd25f878678e9db4a70690e0615.Qm6ln1Dyw24XjxE87KRXp-qqMO0dxdjOrOSvBJvjCZU
scenes-app-replay-vision--scanner-editor-goal-overview-recordings-first--dark:
- hash: v1.k794b7964.63bd74ec2abd193ab3cb0d04509713d41897c883aa6ba25db3c9a271a0cd275d.JqhvghWMvId3J4gZxKzd1vOyBgODIGntn3iHjwFhNiM
+ hash: v1.k794b7964.8f7a8a0f99884efce84d267995fa014f9e6c83eff1f3b3f9418c26559c9c954b.usrBEwfdIF5oNSO4VjRkqKy-EyQXhaSNI7iuXk4UXRk
scenes-app-replay-vision--scanner-editor-goal-overview-recordings-first--light:
- hash: v1.k794b7964.100ca576d8fbc2e0c19e9e34859d7b6425d3f4518a26d0643cc1f1fad53f4d16.NOL4t1PGpUq4JIzjKuq06FD1dC5smr3FlrZQK5eMiN8
+ hash: v1.k794b7964.53baca9d4ae7b53e5b0c37137a8d6899ef441c069576c570aed0f786688a0611.REuQy8DrwaQkdccJ2RdLAVuSSB4J0zgVfSjPfNyoqQM
scenes-app-replay-vision--scanner-editor-triggers--dark:
hash: v1.k794b7964.9f1bb49fff5845e0b4fa240c76f160d11f6c3191fd9a70e818f6381ccbf73233.4oEBUb1L-2niWMCoHVODRY57bXqKEUrEnBKF0tdmsCc
scenes-app-replay-vision--scanner-editor-triggers--light:
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.test.ts b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.test.ts
index 4d2ed4c04141..e5e25c1c4936 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.test.ts
@@ -61,23 +61,32 @@ describe('eligibleFilterGroups', () => {
])
})
- it('gives each page filter its own row, so a page added to a chosen one does not merge into it', () => {
- const page = (value: string): AnyPropertyFilter => ({
- type: PropertyFilterType.Recording,
- key: 'visited_page',
- value: [value],
- operator: PropertyOperator.Regex,
- })
+ it.each([
+ [false, 'Page'],
+ [true, 'Visited page'],
+ ])(
+ 'gives each page filter its own row, so a page added to a chosen one does not merge into it (recordingsFirst=%s)',
+ (recordingsFirst, label) => {
+ const page = (value: string): AnyPropertyFilter => ({
+ type: PropertyFilterType.Recording,
+ key: 'visited_page',
+ value: [value],
+ operator: PropertyOperator.Regex,
+ })
- const groups = eligibleFilterGroups(
- scanner({ query: { kind: NodeKind.RecordingsQuery, properties: [page('/checkout'), page('/billing')] } })
- )
+ const groups = eligibleFilterGroups(
+ scanner({
+ query: { kind: NodeKind.RecordingsQuery, properties: [page('/checkout'), page('/billing')] },
+ }),
+ { recordingsFirst }
+ )
- expect(groups).toEqual([
- { key: 'page:0', label: 'Page', values: ['/checkout'] },
- { key: 'page:1', label: 'Page', values: ['/billing'] },
- ])
- })
+ expect(groups).toEqual([
+ { key: 'page:0', label, values: ['/checkout'] },
+ { key: 'page:1', label, values: ['/billing'] },
+ ])
+ }
+ )
it('names an experiment and a cohort it cannot resolve yet', () => {
// Both load separately from the form, so the row has to stand on its own until they arrive.
@@ -195,7 +204,7 @@ describe('eligibleFilterGroups', () => {
})
describe('goalOverviewSectionLabels', () => {
- it('reviews the eligible recordings before the prompt in the recordings-first arm', () => {
+ it('reviews the target recordings before the prompt, under the wizard step names, in the recordings-first arm', () => {
expect(goalOverviewSectionLabels(false)).toEqual([
'What it understood',
'Name',
@@ -204,11 +213,10 @@ describe('goalOverviewSectionLabels', () => {
'Sampling and budget',
])
expect(goalOverviewSectionLabels(true)).toEqual([
- 'What it understood',
'Name',
- 'Eligible recordings',
- 'What it will ask',
- 'Sampling and limits',
+ 'Target recordings',
+ 'Prompt & output',
+ 'Sampling & limits',
])
})
})
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.tsx
index dbc52ef76973..1d01388aaf47 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalOverview.tsx
@@ -3,9 +3,11 @@ import { router } from 'kea-router'
import { useEffect, useState } from 'react'
import { TextMorph } from 'torph/react'
-import { IconInfo, IconSparkles, IconWarning } from '@posthog/icons'
+import * as researchPng from '@posthog/brand/hoggies/png/research'
+import { IconChevronDown, IconChevronRight, IconInfo, IconSparkles, IconWarning } from '@posthog/icons'
import { LemonBanner, LemonButton, LemonSkeleton, LemonSnack, LemonTag, Spinner, Tooltip } from '@posthog/lemon-ui'
+import { pngHoggie } from 'lib/brand/hoggies'
import { formatPropertyLabel } from 'lib/components/PropertyFilters/utils'
import { LoadingBar } from 'lib/lemon-ui/LoadingBar'
import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
@@ -58,6 +60,52 @@ function activityFilterLabel(mode: string): string {
return 'All recordings'
}
+const HedgehogResearch = pngHoggie(researchPng)
+
+/** Says the overview is a draft to check, with the agent's reasoning one click away. */
+function DraftReviewHeader(): JSX.Element {
+ return (
+ <div className="flex items-start gap-3 pb-1">
+ <HedgehogResearch className="h-16 w-auto shrink-0" />
+ <div className="min-w-0 flex-1 space-y-1">
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="text-base font-semibold">Review your draft scanner</span>
+ <LemonTag type="highlight">Draft</LemonTag>
+ </div>
+ <div className="text-sm text-muted">
+ The agent drafted this from your goal. Check each section and edit anything that is not right.
+ Nothing runs until you click Create scanner.
+ </div>
+ </div>
+ </div>
+ )
+}
+
+/** The agent's reasoning as a card like the others, closed because it mostly restates the goal. */
+function RationaleSection({ rationale }: { rationale: string }): JSX.Element {
+ const [isOpen, setIsOpen] = useState(false)
+ return (
+ <div className="bg-bg-light border rounded-lg p-4 space-y-2">
+ <button
+ type="button"
+ className="flex items-center gap-1 text-xs text-tertiary uppercase tracking-wide cursor-pointer hover:text-primary"
+ onClick={() => setIsOpen(!isOpen)}
+ aria-expanded={isOpen}
+ aria-controls="vision-goal-overview-rationale-text"
+ data-attr="vision-goal-overview-rationale"
+ >
+ {isOpen ? <IconChevronDown className="text-sm" /> : <IconChevronRight className="text-sm" />}
+ <span>Why the agent chose this setup</span>
+ </button>
+ {isOpen ? (
+ <div id="vision-goal-overview-rationale-text" className="text-sm">
+ {rationale}
+ </div>
+ ) : null}
+ </div>
+ )
+}
+
/** One label:value row in the eligible-recordings and sampling blocks. */
function StatRow({ label, children }: { label: string; children: React.ReactNode }): JSX.Element {
return (
@@ -235,14 +283,20 @@ function topLevelPropertyGroups(scanner: ReplayScanner): EligibleFilterGroup[] {
*/
export function eligibleFilterGroups(
scanner: ReplayScanner,
- { experimentName, cohortNames }: { experimentName?: string; cohortNames?: Record<string, string> } = {}
+ {
+ experimentName,
+ cohortNames,
+ recordingsFirst,
+ }: { experimentName?: string; cohortNames?: Record<string, string>; recordingsFirst?: boolean } = {}
): EligibleFilterGroup[] {
+ // The recordings-first experiment arm uses the filter's own name from the recordings filter.
+ const [pageSingular, pagePlural] = recordingsFirst ? ['Visited page', 'Visited pages'] : ['Page', 'Pages']
const kinds: [key: string, singular: string, plural: string, values: string[]][] = [
['experiment', 'Experiment', 'Experiments', experimentValues(scanner, experimentName)],
...pageValueLists(scanner).map((values, index): [string, string, string, string[]] => [
`page:${index}`,
- 'Page',
- 'Pages',
+ pageSingular,
+ pagePlural,
values,
]),
['event', 'Event', 'Events', namedQueryEntities(scanner, 'events')],
@@ -277,6 +331,7 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
} = useValues(logic)
const { freeCreditsAllowance } = useValues(visionQuotaLogic)
const { recordingsFirst, stepLabels } = useValues(scannerEditorSceneLogic)
+ const sectionLabels = goalOverviewSectionTitles(recordingsFirst)
// Names the drafted cohort, which the query carries only by id.
const { cohortsById } = useValues(cohortsModel)
const { submitScanner, loadScannerEstimate } = useActions(logic)
@@ -296,6 +351,7 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
const filterGroups = eligibleFilterGroups(scanner, {
experimentName: experimentContext?.experiment.name,
cohortNames,
+ recordingsFirst,
})
// Read against the form, so an addition the person removed by hand is not credited to the AI.
const currentFilterValues = new Set(filterGroups.flatMap((group) => group.values))
@@ -337,7 +393,7 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
// The recordings-first experiment arm reviews what the scanner watches before what it asks.
const askSection = (
- <OverviewSection label="What it will ask" editStep="configure" scannerId={scannerId}>
+ <OverviewSection label={sectionLabels.configure} editStep="configure" scannerId={scannerId}>
<div className="space-y-3">
<LemonTag type={SCANNER_TYPE_TAG_TYPE[scanner.scanner_type]}>
{scannerTypeLabel(scanner.scanner_type)}
@@ -360,11 +416,20 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
</OverviewSection>
)
+ const rationale = goalDraft?.rationale?.trim()
+
return (
<div className="flex flex-col gap-3">
- <OverviewSection label="What it understood" scannerId={scannerId}>
- <div className="text-sm">{goalDraft?.rationale?.trim() || scanner.description}</div>
- </OverviewSection>
+ {recordingsFirst ? (
+ <>
+ <DraftReviewHeader />
+ {rationale ? <RationaleSection rationale={rationale} /> : null}
+ </>
+ ) : (
+ <OverviewSection label="What it understood" scannerId={scannerId}>
+ <div className="text-sm">{rationale || scanner.description}</div>
+ </OverviewSection>
+ )}
<OverviewSection label="Name" editStep="details" scannerId={scannerId}>
<div className="text-sm font-medium">{scanner.name}</div>
@@ -373,7 +438,7 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
{recordingsFirst ? null : askSection}
- <OverviewSection label="Eligible recordings" editStep="triggers" scannerId={scannerId}>
+ <OverviewSection label={sectionLabels.triggers} editStep="triggers" scannerId={scannerId}>
{filterGroups.length > 0 ? (
<div className="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-1 text-sm">
{filterGroups.map((group) => (
@@ -424,7 +489,7 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
{recordingsFirst ? askSection : null}
<OverviewSection
- label={recordingsFirst ? 'Sampling and limits' : 'Sampling and budget'}
+ label={sectionLabels.budget}
info="Estimated from your last 7 days of recordings, projected to a month. Your real volume follows your future traffic, so treat this as a guide."
editStep="budget"
scannerId={scannerId}
@@ -493,7 +558,7 @@ export function ScannerGoalOverview({ scannerId }: { scannerId: string }): JSX.E
) : overBudget ? (
<LemonBanner type="warning">
Your budget won't last the month at about <span>{monthlyObservations?.toLocaleString()}</span>{' '}
- recordings a month. Narrow the eligible recordings above.
+ recordings a month. Narrow the {sectionLabels.triggers.toLowerCase()} above.
</LemonBanner>
) : null}
</OverviewSection>
@@ -569,11 +634,21 @@ function DraftLoadingBar(): JSX.Element {
)
}
+/** Each overview section's title. The recordings-first experiment arm uses its wizard step names. */
+export function goalOverviewSectionTitles(
+ recordingsFirst: boolean
+): Record<'configure' | 'triggers' | 'budget', string> {
+ return recordingsFirst
+ ? { triggers: 'Target recordings', configure: 'Prompt & output', budget: 'Sampling & limits' }
+ : { triggers: 'Eligible recordings', configure: 'What it will ask', budget: 'Sampling and budget' }
+}
+
/** The overview's section titles in render order, which the recordings-first experiment arm changes. */
export function goalOverviewSectionLabels(recordingsFirst: boolean): string[] {
+ const titles = goalOverviewSectionTitles(recordingsFirst)
return recordingsFirst
- ? ['What it understood', 'Name', 'Eligible recordings', 'What it will ask', 'Sampling and limits']
- : ['What it understood', 'Name', 'What it will ask', 'Eligible recordings', 'Sampling and budget']
+ ? ['Name', titles.triggers, titles.configure, titles.budget]
+ : ['What it understood', 'Name', titles.configure, titles.triggers, titles.budget]
}
/** The overview's shape while the draft is still generating, so navigating there reads as progress. */