: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(phai): declutter the permission mode picker menu (#72324)
Georgiy Tarasovdd8bf8836f7b
diff --git a/products/posthog_ai/frontend/components/composer/ComposerModePicker.test.tsx b/products/posthog_ai/frontend/components/composer/ComposerModePicker.test.tsxindex b89880426a0b..925c624d52ec 100644--- a/products/posthog_ai/frontend/components/composer/ComposerModePicker.test.tsx+++ b/products/posthog_ai/frontend/components/composer/ComposerModePicker.test.tsx@@ -11,35 +11,60 @@ describe('ComposerModePicker', () => {cleanup()})- it('shows the three product modes with their safety guidance and emits their server values', () => {+ it('shows the three product modes with one description at a time and emits their server values', () => {const onModeChange = jest.fn()render(<ComposerModePicker selectedMode={InitialPermissionModeEnumApi.Auto} onModeChange={onModeChange} />)fireEvent.click(screen.getByLabelText('Mode'))+ expect(screen.queryByText('Default')).not.toBeInTheDocument()+ expect(screen.queryByText('Accept edits')).not.toBeInTheDocument()++ // The footer describes the selected mode on open; the other descriptions stay out of the menu.expect(screen.getByText('Accepts file edits and shell commands automatically. Always asks before PostHog tools that change live data. Creating or publishing content asks only while you watch the run.')).toBeInTheDocument()expect(- screen.getByText(- 'Bypasses all permissions. Safe in the sandbox, but the agent can modify or delete data without asking.'- )- ).toBeInTheDocument()- expect(- screen.getByText(- 'Recommended for complex work such as research or implementation. Create a plan now, then execute it later.'- )- ).toBeInTheDocument()- expect(screen.queryByText('Default')).not.toBeInTheDocument()- expect(screen.queryByText('Accept edits')).not.toBeInTheDocument()+ screen.queryByText('Never asks. The agent can change or delete live data on its own.')+ ).not.toBeInTheDocument()+ // Hovering another option swaps the footer to its description. This breaks if ModeItemRow+ // stops forwarding Base UI's ref — the item then never registers for hover highlighting.const fullAutoOption = screen.getByText('Full auto').closest('[role="option"]')expect(fullAutoOption).not.toBeNull()+ fireEvent.mouseMove(fullAutoOption!)+ expect(screen.getByText('Never asks. The agent can change or delete live data on its own.')).toBeInTheDocument()+ expect(+ screen.queryByText(+ 'Accepts file edits and shell commands automatically. Always asks before PostHog tools that change live data. Creating or publishing content asks only while you watch the run.'+ )+ ).not.toBeInTheDocument()+fireEvent.pointerDown(fullAutoOption!, { pointerType: 'mouse' })fireEvent.click(fullAutoOption!)expect(onModeChange).toHaveBeenCalledWith(InitialPermissionModeEnumApi.BypassPermissions)})++ it('never describes a mode the narrowed menu does not offer', () => {+ render(+ <ComposerModePicker+ selectedMode={InitialPermissionModeEnumApi.Auto}+ onModeChange={jest.fn()}+ modes={[InitialPermissionModeEnumApi.Plan, InitialPermissionModeEnumApi.BypassPermissions]}+ />+ )++ fireEvent.click(screen.getByLabelText('Mode'))++ // The selected mode is filtered out, so the footer falls back to an offered mode's description.+ expect(screen.getByText('Never asks. The agent can change or delete live data on its own.')).toBeInTheDocument()+ expect(+ screen.queryByText(+ 'Accepts file edits and shell commands automatically. Always asks before PostHog tools that change live data. Creating or publishing content asks only while you watch the run.'+ )+ ).not.toBeInTheDocument()+ })})diff --git a/products/posthog_ai/frontend/components/composer/ComposerModePicker.tsx b/products/posthog_ai/frontend/components/composer/ComposerModePicker.tsxindex ff5ebff867cd..b5a12c6deb4d 100644--- a/products/posthog_ai/frontend/components/composer/ComposerModePicker.tsx+++ b/products/posthog_ai/frontend/components/composer/ComposerModePicker.tsx@@ -1,16 +1,7 @@+import { forwardRef, useEffect, useState, type HTMLAttributes } from 'react'+import { IconPause, IconShield, IconUnlock } from '@posthog/icons'-import {- ItemContent,- ItemDescription,- ItemTitle,- Select,- SelectContent,- SelectGroup,- SelectGroupLabel,- SelectItem,- SelectTrigger,- SelectValue,-} from '@posthog/quill-primitives'+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@posthog/quill-primitives'import { getModeOption, MODE_OPTIONS, type PermissionMode } from 'products/posthog_ai/frontend/utils/composerModes'import { InitialPermissionModeEnumApi } from 'products/tasks/frontend/generated/api.schemas'@@ -26,6 +17,30 @@ const MODE_STYLES: Record<PermissionMode, ModeStyle> = {[InitialPermissionModeEnumApi.Plan]: { icon: <IconPause />, className: 'text-warning' },}+interface ModeItemRowProps extends HTMLAttributes<HTMLDivElement> {+ highlighted: boolean+ mode: PermissionMode+ onHighlight: (mode: PermissionMode) => void+}++/**+ * Row body for a mode option. Rendered through the item's `render` prop so it can watch Base UI's+ * `highlighted` state — both pointer hover and keyboard navigation — and report it up for the+ * description footer. Must forward the ref: Base UI registers the element into its item list through+ * it, and an unregistered item is invisible to hover highlighting.+ */+const ModeItemRow = forwardRef<HTMLDivElement, ModeItemRowProps>(function ModeItemRow(+ { highlighted, mode, onHighlight, ...divProps },+ ref+): JSX.Element {+ useEffect(() => {+ if (highlighted) {+ onHighlight(mode)+ }+ }, [highlighted, mode, onHighlight])+ return <div ref={ref} {...divProps} />+})+export interface ComposerModePickerProps {selectedMode: PermissionModeonModeChange: (mode: PermissionMode) => void@@ -37,13 +52,29 @@ export interface ComposerModePickerProps {* Controlled, logic-free permission-mode picker for a composer footer, styled to match the adjacent* model/effort pickers. The caller owns the selection and its side effects. Also reused by the plan-approval* card, where `modes` narrows the menu to the wire-offered modes.+ *+ * The menu keeps each option to one line (icon + label); the highlighted option's description renders in+ * a footer strip pinned to two lines of height, so the menu never jumps while moving between modes.*/export function ComposerModePicker({ selectedMode, onModeChange, modes }: ComposerModePickerProps): JSX.Element {const options = modes ? MODE_OPTIONS.filter((option) => modes.includes(option.value)) : MODE_OPTIONSconst selectedOption = getModeOption(selectedMode)+ // The mode whose description the footer shows. Base UI highlights the selected item on open, which+ // seeds this; reset on open so a hover from the previous open can't leak into the next one.+ const [highlightedMode, setHighlightedMode] = useState<PermissionMode | null>(null)+ // Resolve against `options`, not all modes: when `modes` narrows the menu, the footer must never+ // describe a mode that isn't offered (e.g. a selected mode the plan-approval card filtered out).+ const footerOption =+ options.find((option) => option.value === highlightedMode) ??+ options.find((option) => option.value === selectedMode) ??+ options[0]return (- <Select value={selectedMode} onValueChange={(mode: PermissionMode | null) => mode && onModeChange(mode)}>+ <Select+ value={selectedMode}+ onValueChange={(mode: PermissionMode | null) => mode && onModeChange(mode)}+ onOpenChange={() => setHighlightedMode(null)}+ ><SelectTrigger size="sm" aria-label="Mode"><SelectValue>{selectedOption ? (@@ -58,21 +89,29 @@ export function ComposerModePicker({ selectedMode, onModeChange, modes }: Compos)}</SelectValue></SelectTrigger>- <SelectContent align="start" alignItemWithTrigger={false} className="max-w-96">- <SelectGroup>- <SelectGroupLabel>Mode</SelectGroupLabel>- {options.map((option) => (- <SelectItem key={option.value} value={option.value}>- <span className={MODE_STYLES[option.value].className}>- {MODE_STYLES[option.value].icon}- </span>- <ItemContent variant="menuItem">- <ItemTitle>{option.label}</ItemTitle>- <ItemDescription>{option.description}</ItemDescription>- </ItemContent>- </SelectItem>- ))}- </SelectGroup>+ <SelectContent align="start" alignItemWithTrigger={false}>+ {options.map((option) => (+ <SelectItem+ key={option.value}+ value={option.value}+ render={(props, state) => (+ <ModeItemRow+ {...props}+ highlighted={state.highlighted}+ mode={option.value}+ onHighlight={setHighlightedMode}+ />+ )}+ >+ <span className={MODE_STYLES[option.value].className}>{MODE_STYLES[option.value].icon}</span>+ {option.label}+ </SelectItem>+ ))}+ {footerOption && (+ <div className="-mx-1 -mb-1 mt-1 flex min-h-[3.25rem] w-60 items-center border-t px-3 py-1.5 text-xs text-secondary">+ {footerOption.description}+ </div>+ )}</SelectContent></Select>)diff --git a/products/posthog_ai/frontend/utils/composerModes.ts b/products/posthog_ai/frontend/utils/composerModes.tsindex c8a2580a5afc..6c71888348bc 100644--- a/products/posthog_ai/frontend/utils/composerModes.ts+++ b/products/posthog_ai/frontend/utils/composerModes.ts@@ -25,14 +25,12 @@ export const MODE_OPTIONS: ComposerModeOption[] = [{value: InitialPermissionModeEnumApi.BypassPermissions,label: 'Full auto',- description:- 'Bypasses all permissions. Safe in the sandbox, but the agent can modify or delete data without asking.',+ description: 'Never asks. The agent can change or delete live data on its own.',},{value: InitialPermissionModeEnumApi.Plan,label: 'Plan',- description:- 'Recommended for complex work such as research or implementation. Create a plan now, then execute it later.',+ description: 'Plans the work first. Nothing runs until you approve the plan.',},]