: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(posthog-ai): quill task history and a header slot for the side panel chat (#119010)
Adam Leith198fdac213fa
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsxindex a2d2ec009873..9a01b1907c6f 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx@@ -6,11 +6,11 @@ import { sidePanelMaxLogic } from 'scenes/max/maxLogic'// into the shell chunk. SidePanel already wraps panel content in a Suspense boundary.const MaxInstance = lazyWithRetry(() => import('scenes/max/Max').then((m) => ({ default: m.MaxInstance })))-export function SidePanelMax(): JSX.Element | null {+export function SidePanelMax({ header }: { header?: JSX.Element | null }): JSX.Element | null {// Closing the panel unmounts this tree, so hold the chat logic to keep the open chat and draft.useOnMountEffect(() => {sidePanelMaxLogic()})- return <MaxInstance sidePanel />+ return <MaxInstance sidePanel header={header} />}diff --git a/frontend/src/scenes/max/Max.tsx b/frontend/src/scenes/max/Max.tsxindex cf902d500389..684b634dfc49 100644--- a/frontend/src/scenes/max/Max.tsx+++ b/frontend/src/scenes/max/Max.tsx@@ -138,9 +138,15 @@ export function Max({ tabId }: MaxProps): JSX.Element {export interface MaxInstanceProps {sidePanel?: booleantabId?: string+ /** Replaces the side panel header. Pass `null` when the host draws its own header. */+ header?: JSX.Element | null}-export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }: MaxInstanceProps): JSX.Element {+export const MaxInstance = React.memo(function MaxInstance({+ sidePanel,+ tabId,+ header: headerOverride,+}: MaxInstanceProps): JSX.Element {// `sidePanel` here is presentational (side panel chrome/layout) and is independent of the logic// identity we bind: a tabId identifies a scene tab (or a Storybook instance rendered with side// panel chrome), while the real side panel — which has no tabId — binds the side panel panelId.@@ -326,8 +332,12 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:content must stay clamped to the panel height — without `min-h-0` its `min-height: auto`grows it to fit the whole thread and no scroller ever engages. The legacy view is theopposite: it relies on this container growing so the outer viewport scrolls it. */}- <SidePanelContentContainer contentClassName={cn('flex flex-col flex-1', isTaskView && 'min-h-0')}>- {header}+ <SidePanelContentContainer+ // A host that draws its own header also draws the frame, so the focus ring would double its edges.+ className={cn(headerOverride !== undefined && 'focus-within:ring-0')}+ contentClassName={cn('flex flex-col flex-1', isTaskView && 'min-h-0')}+ >+ {headerOverride !== undefined ? headerOverride : header}{content}</SidePanelContentContainer></>diff --git a/products/posthog_ai/frontend/components/quill/QuillTaskHistoryList.tsx b/products/posthog_ai/frontend/components/quill/QuillTaskHistoryList.tsxnew file mode 100644index 000000000000..76c8ffb2bd3f--- /dev/null+++ b/products/posthog_ai/frontend/components/quill/QuillTaskHistoryList.tsx@@ -0,0 +1,91 @@+import { useActions, useValues } from 'kea'++import { IconArchive } from '@posthog/icons'+import {+ Button,+ Empty,+ EmptyHeader,+ EmptyTitle,+ Skeleton,+ Spinner,+ Text,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill-primitives'++import { taskHistoryLogic } from '../../logics/taskHistoryLogic'+import { tasksLogic } from '../../logics/tasksLogic'+import { compactTimeAgo, isTaskInProgress } from '../../scenes/TaskTracker/components/taskHistoryUtils'+import { taskTrackerSceneLogic } from '../../scenes/TaskTracker/taskTrackerSceneLogic'++export function QuillTaskHistoryList(): JSX.Element {+ const { history, historyLoading } = useValues(taskHistoryLogic)+ const { openExistingTask } = useActions(taskTrackerSceneLogic)+ const { deleteTask } = useActions(tasksLogic)++ if (historyLoading && !history.length) {+ return (+ <div className="flex w-full flex-col gap-2">+ <Skeleton className="h-11" />+ <Skeleton className="h-11 opacity-80" />+ <Skeleton className="h-11 opacity-60" />+ </div>+ )+ }++ if (!history.length) {+ return (+ <Empty>+ <EmptyHeader>+ <EmptyTitle>No tasks yet</EmptyTitle>+ </EmptyHeader>+ </Empty>+ )+ }++ return (+ <div className="flex w-full flex-col">+ {history.map((task) => (+ // The archive button sits beside the row, not inside it, since a button can't nest in another.+ // It takes the time's place while the row is hovered or focused.+ <div key={task.id} className="group/row relative flex items-center">+ <Button+ size="sm"+ left+ className="w-full min-w-0 justify-between gap-2"+ onClick={() => openExistingTask(task)}+ data-attr="task-open-history-card"+ >+ <span className="min-w-0 truncate">{task.title || task.slug}</span>+ <span className="shrink-0 group-focus-within/row:invisible group-hover/row:invisible">+ {isTaskInProgress(task) ? (+ <Spinner aria-label="Working" />+ ) : (+ <Text size="xs" variant="muted" render={<span translate="no" />}>+ {compactTimeAgo(task.updated_at)}+ </Text>+ )}+ </span>+ </Button>+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <Button+ size="icon-xs"+ aria-label="Archive task"+ className="absolute end-1 text-muted-foreground opacity-0 group-focus-within/row:opacity-100 group-hover/row:opacity-100 hover:text-foreground"+ onClick={() => deleteTask({ taskId: task.id })}+ />+ }+ >+ <IconArchive />+ </TooltipTrigger>+ <TooltipContent>Archive task</TooltipContent>+ </Tooltip>+ </div>+ ))}+ </div>+ )+}diff --git a/products/posthog_ai/frontend/components/quill/QuillTaskHistoryPanel.tsx b/products/posthog_ai/frontend/components/quill/QuillTaskHistoryPanel.tsxnew file mode 100644index 000000000000..2ab19f82b3d6--- /dev/null+++ b/products/posthog_ai/frontend/components/quill/QuillTaskHistoryPanel.tsx@@ -0,0 +1,25 @@+import { useActions } from 'kea'++import { IconArrowLeft } from '@posthog/icons'+import { Button } from '@posthog/quill-primitives'++import { taskTrackerSceneLogic } from '../../scenes/TaskTracker/taskTrackerSceneLogic'+import { QuillTaskHistoryList } from './QuillTaskHistoryList'++export function QuillTaskHistoryPanel(): JSX.Element {+ const { toggleHistory } = useActions(taskTrackerSceneLogic)++ return (+ <div className="flex h-full min-h-0 flex-col">+ <div className="flex shrink-0 items-center border-b border-border px-2 py-1">+ <Button onClick={() => toggleHistory()} data-attr="task-history-back">+ <IconArrowLeft />+ Back+ </Button>+ </div>+ <div className="min-h-0 flex-1 overflow-y-auto px-2 py-2">+ <QuillTaskHistoryList />+ </div>+ </div>+ )+}diff --git a/products/posthog_ai/frontend/components/quill/QuillTaskHistoryPreview.tsx b/products/posthog_ai/frontend/components/quill/QuillTaskHistoryPreview.tsxnew file mode 100644index 000000000000..2f7aa767ab71--- /dev/null+++ b/products/posthog_ai/frontend/components/quill/QuillTaskHistoryPreview.tsx@@ -0,0 +1,70 @@+import { useActions, useValues } from 'kea'++import { Button, ButtonGroup, Skeleton, Spinner, Text } from '@posthog/quill-primitives'++import { urls } from 'scenes/urls'++import { taskHistoryLogic } from '../../logics/taskHistoryLogic'+import { compactTimeAgo, isTaskInProgress } from '../../scenes/TaskTracker/components/taskHistoryUtils'+import { taskTrackerSceneLogic } from '../../scenes/TaskTracker/taskTrackerSceneLogic'++export function QuillTaskHistoryPreview(): JSX.Element | null {+ const { history, historyLoading } = useValues(taskHistoryLogic)+ const { toggleHistory, openExistingTask } = useActions(taskTrackerSceneLogic)++ if (!history.length && !historyLoading) {+ return null+ }++ return (+ <div className="flex w-full max-w-120 flex-col gap-1 self-center px-3">+ <div className="flex items-center justify-between gap-2">+ <Text size="xs" weight="medium" variant="muted" render={<h3 className="m-0" />}>+ Recent tasks+ </Text>+ <Button onClick={() => toggleHistory()} data-attr="task-view-all-history">+ View all+ </Button>+ </div>+ {historyLoading && !history.length ? (+ <div className="flex flex-col gap-2">+ <Skeleton className="h-5" />+ <Skeleton className="h-5" />+ <Skeleton className="h-5" />+ </div>+ ) : (+ <ButtonGroup orientation="vertical" className="w-full">+ {history.slice(0, 3).map((task) => (+ <Button+ key={task.id}+ variant="outline"+ nativeButton={false}+ // The app's global link color would tint the row, so it keeps the button's text color.+ className="w-full justify-between gap-2 text-foreground hover:text-foreground"+ render={+ // eslint-disable-next-line react/forbid-elements+ <a+ href={urls.taskDetail(task.id)}+ onClick={(event) => {+ event.preventDefault()+ openExistingTask(task)+ }}+ data-attr="task-open-history-preview"+ />+ }+ >+ <span className="min-w-0 truncate">{task.title || task.slug}</span>+ {isTaskInProgress(task) ? (+ <Spinner aria-label="Working" />+ ) : (+ <Text size="xs" variant="muted" render={<span translate="no" />}>+ {compactTimeAgo(task.updated_at)}+ </Text>+ )}+ </Button>+ ))}+ </ButtonGroup>+ )}+ </div>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.test.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.test.tsxindex c9714942fa79..4db824071bdb 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.test.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.test.tsx@@ -20,7 +20,7 @@ jest.mock('./TaskComposer', () => ({ TaskComposer: () => <div data-attr="task-cojest.mock('./TaskRunChat', () => ({ TaskRunChat: () => <div data-attr="task-run-chat" /> }))jest.mock('./StartupRunChat', () => ({ StartupRunChat: () => <div data-attr="startup-run-chat" /> }))jest.mock('./TaskHistory', () => ({- TaskHistoryList: () => <div data-attr="task-history-list" />,+ TaskHistoryPanel: () => <div data-attr="task-history-list" />,TaskHistoryPreview: () => <div data-attr="task-history-preview" />,}))diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.tsxindex b99781a80c03..5ec8ec863d56 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/SidePanelRunnerImpl.tsx@@ -1,18 +1,20 @@import { BindLogic, useActions, useValues } from 'kea'import { ReactNode, useRef } from 'react'-import { IconArrowLeft } from '@posthog/icons'-import { LemonButton, LemonDivider } from '@posthog/lemon-ui'+import { LemonDivider } from '@posthog/lemon-ui'++import { cn } from 'lib/utils/css-classes'import { useAttachedContext } from '../../../hooks/useAttachedContext'import { useForegroundStream } from '../../../hooks/useForegroundStream'+import { useThreadSkin } from '../../../hooks/useThreadSkin'import type { ComposerOverride } from '../../../logics/composerOverrideLogic'import type { AttachedContextItem } from '../../../types/contextTypes'import { AGENT_TOOL_APPLY_BACK_CONTEXT_ITEM } from '../../../utils/posthogContextBlock'import { taskTrackerSceneLogic } from '../taskTrackerSceneLogic'import { StartupRunChat } from './StartupRunChat'import { TaskComposer } from './TaskComposer'-import { TaskHistoryList, TaskHistoryPreview } from './TaskHistory'+import { TaskHistoryPanel, TaskHistoryPreview } from './TaskHistory'import { TaskRunChat } from './TaskRunChat'export interface SidePanelRunnerImplProps {@@ -66,8 +68,10 @@ function SidePanelRunnerContent({historyExpanded,effectiveComposerOverride: composerOverride,} = useValues(taskTrackerSceneLogic)- const { toggleHistory, updateActiveCreationRun, setStartupDraft } = useActions(taskTrackerSceneLogic)+ const { updateActiveCreationRun, setStartupDraft } = useActions(taskTrackerSceneLogic)const startupFocusedRef = useRef(false)+ // The quill host draws its own frame and header divider, and its thread carries no outer margin.+ const lemonChrome = useThreadSkin() === 'lemon'// This compact surface renders only in Max's side panel, so the run it shows is a foreground// stream. Register its `streamKey` (cleared when the panel drops back to the composer/history, and@@ -83,18 +87,7 @@ function SidePanelRunnerContent({// panel state is shared across hosts — so an expanded history left behind by another one must not// take the place of that composer.if (!activeCreation && historyExpanded && !composer) {- return (- <div className="flex flex-col h-full min-h-0">- <div className="flex items-center shrink-0 border-b border-primary px-2 py-1">- <LemonButton size="small" icon={<IconArrowLeft />} onClick={() => toggleHistory()}>- Back- </LemonButton>- </div>- <div className="flex-1 min-h-0 overflow-y-auto px-4 py-2">- <TaskHistoryList />- </div>- </div>- )+ return <TaskHistoryPanel />}if (!activeCreation) {@@ -117,12 +110,12 @@ function SidePanelRunnerContent({return (<div className="flex flex-col h-full min-h-0">- <LemonDivider className="my-0" />+ {lemonChrome && <LemonDivider className="my-0" />}{activeCreation.taskId && activeCreation.runId ? (// `TaskRunChat`'s inner container compensates for the `/tasks` scene's own horizontal margin// with `-mx-4`; a `px-4` wrapper here neutralizes that bleed instead of editing the shared// component, so it renders flush with the panel edge like the composer and pending states.- <div className="flex-1 min-h-0 px-4">+ <div className={cn('flex-1 min-h-0', lemonChrome && 'px-4')}><TaskRunChattaskId={activeCreation.taskId}runId={activeCreation.runId}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskHistory.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskHistory.tsxindex f693280d7f52..d535c8c40dac 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskHistory.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskHistory.tsx@@ -1,33 +1,25 @@import { useActions, useValues } from 'kea'-import { IconArchive } from '@posthog/icons'+import { IconArchive, IconArrowLeft } from '@posthog/icons'import { LemonButton, LemonSkeleton, Link, Spinner } from '@posthog/lemon-ui'-import { dayjs } from 'lib/dayjs'-import { humanFriendlyDuration } from 'lib/utils/durations'import { urls } from 'scenes/urls'+import { QuillTaskHistoryList } from '../../../components/quill/QuillTaskHistoryList'+import { QuillTaskHistoryPanel } from '../../../components/quill/QuillTaskHistoryPanel'+import { QuillTaskHistoryPreview } from '../../../components/quill/QuillTaskHistoryPreview'+import { useThreadSkin } from '../../../hooks/useThreadSkin'import { taskHistoryLogic } from '../../../logics/taskHistoryLogic'import { tasksLogic } from '../../../logics/tasksLogic'-import { Task, TaskRunStatus } from '../../../types/taskTypes'+import { Task } from '../../../types/taskTypes'import { taskTrackerSceneLogic } from '../taskTrackerSceneLogic'+import { compactTimeAgo, isTaskInProgress } from './taskHistoryUtils'-const IN_PROGRESS_STATUSES = new Set<TaskRunStatus>([TaskRunStatus.QUEUED, TaskRunStatus.IN_PROGRESS])--// Compact "time ago" using a single largest unit, e.g. 18m, 1h, 7d.-function compactTimeAgo(iso: string): string {- const seconds = dayjs().diff(dayjs(iso), 'second')- if (seconds < 60) {- return 'now'- }- return humanFriendlyDuration(seconds, { maxUnits: 1 })-}--function isTaskInProgress(task: Task): boolean {- return task.latest_run ? IN_PROGRESS_STATUSES.has(task.latest_run.status) : false+export function TaskHistoryPreview(): JSX.Element | null {+ return useThreadSkin() === 'quill' ? <QuillTaskHistoryPreview /> : <LemonTaskHistoryPreview />}-export function TaskHistoryPreview(): JSX.Element | null {+function LemonTaskHistoryPreview(): JSX.Element | null {const { history, historyLoading } = useValues(taskHistoryLogic)const { toggleHistory, openExistingTask } = useActions(taskTrackerSceneLogic)@@ -97,6 +89,10 @@ function TaskHistoryPreviewRow({ task, onOpen }: TaskHistoryRowProps): JSX.Eleme}export function TaskHistoryList(): JSX.Element {+ return useThreadSkin() === 'quill' ? <QuillTaskHistoryList /> : <LemonTaskHistoryList />+}++function LemonTaskHistoryList(): JSX.Element {const { history, historyLoading } = useValues(taskHistoryLogic)const { openExistingTask } = useActions(taskTrackerSceneLogic)@@ -164,3 +160,24 @@ function TaskHistoryCard({ task, onOpen }: TaskHistoryRowProps): JSX.Element {</div>)}++export function TaskHistoryPanel(): JSX.Element {+ return useThreadSkin() === 'quill' ? <QuillTaskHistoryPanel /> : <LemonTaskHistoryPanel />+}++function LemonTaskHistoryPanel(): JSX.Element {+ const { toggleHistory } = useActions(taskTrackerSceneLogic)++ return (+ <div className="flex flex-col h-full min-h-0">+ <div className="flex items-center shrink-0 border-b border-primary px-2 py-1">+ <LemonButton size="small" icon={<IconArrowLeft />} onClick={() => toggleHistory()}>+ Back+ </LemonButton>+ </div>+ <div className="flex-1 min-h-0 overflow-y-auto px-4 py-2">+ <LemonTaskHistoryList />+ </div>+ </div>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/taskHistoryUtils.ts b/products/posthog_ai/frontend/scenes/TaskTracker/components/taskHistoryUtils.tsnew file mode 100644index 000000000000..6892417a968d--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/taskHistoryUtils.ts@@ -0,0 +1,19 @@+import { dayjs } from 'lib/dayjs'+import { humanFriendlyDuration } from 'lib/utils/durations'++import { Task, TaskRunStatus } from '../../../types/taskTypes'++const IN_PROGRESS_STATUSES = new Set<TaskRunStatus>([TaskRunStatus.QUEUED, TaskRunStatus.IN_PROGRESS])++// Compact "time ago" using a single largest unit, e.g. 18m, 1h, 7d.+export function compactTimeAgo(iso: string): string {+ const seconds = dayjs().diff(dayjs(iso), 'second')+ if (seconds < 60) {+ return 'now'+ }+ return humanFriendlyDuration(seconds, { maxUnits: 1 })+}++export function isTaskInProgress(task: Task): boolean {+ return task.latest_run ? IN_PROGRESS_STATUSES.has(task.latest_run.status) : false+}