: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(tasks): embed flags and cohorts, list documents with files (#110206)
Shy Alter6110d2beb290
diff --git a/frontend/src/styles/quill-bridge.scss b/frontend/src/styles/quill-bridge.scssindex 2cab6cc3833c..2928b535b91e 100644--- a/frontend/src/styles/quill-bridge.scss+++ b/frontend/src/styles/quill-bridge.scss@@ -326,3 +326,15 @@--color-border-primary: var(--color-neutral-cool-800);--color-border-secondary: var(--color-neutral-cool-600);}++/*+ * Quill also names two of its status fills `--success` and `--warning`, and tokens.scoped.css+ * sets them on every element under [data-quill], not only on the wrapper. So the hatch must+ * set Lemon's values on each descendant too, or LemonTag and LemonBanner text turns pale.+ * base.scss gives these one value for both themes.+ */+[data-quill] [data-not-quill],+[data-quill] [data-not-quill] * {+ --success: #388600;+ --warning: #f7a501;+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsxindex 34b439c8a7ef..f2a6d710759e 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx@@ -4,6 +4,7 @@ import { HttpResponse } from 'msw'import { ReactNode, useEffect } from 'react'import { FEATURE_FLAGS } from 'lib/constants'+import FEATURE_FLAGS_FIXTURE from 'scenes/feature-flags/__mocks__/feature_flags.json'import { urls } from 'scenes/urls'import { userLogic } from 'scenes/userLogic'@@ -13,6 +14,7 @@ import { todayShellLogic } from '~/layout/today/todayShellLogic'import { mswDecorator } from '~/mocks/browser'import TRENDS_LINE_INSIGHT from '~/mocks/fixtures/api/projects/team_id/insights/trendsLine.json'import type { MockSignature } from '~/mocks/utils'+import { NodeKind } from '~/queries/schema/schema-general'import type {TaskRunArtifactResponseApi,@@ -203,7 +205,7 @@ const WALKTHROUGH_WEBM_BASE64 =function objectReference(id: string,name: string,- objectKind: 'insight' | 'dashboard' | 'flag',+ objectKind: 'insight' | 'dashboard' | 'flag' | 'experiment' | 'cohort' | 'survey',objectId: string,uploadedAt: string): TaskRunArtifactResponseApi {@@ -228,18 +230,76 @@ const OBJECT_REFERENCES = [objectReference('phref_trial_funnel', 'Trial funnel by step', 'insight', 'aBcD1234', '2026-09-28T18:12:00Z'),objectReference('phref_growth', 'Growth review', 'dashboard', '42', '2026-09-28T18:11:00Z'),objectReference('phref_flag', 'new-plan-picker', 'flag', '7', '2026-09-28T18:10:00Z'),+ objectReference('phref_experiment', 'Plan picker layout test', 'experiment', '12', '2026-09-28T18:09:00Z'),+ objectReference('phref_cohort', 'Trial starters on laptops', 'cohort', '3', '2026-09-28T18:08:00Z'),+ objectReference('phref_survey', 'Plan picker feedback', 'survey', 'survey-plan-picker', '2026-09-28T18:07:00Z'),]const CITED_INSIGHT = { ...TRENDS_LINE_INSIGHT, short_id: 'aBcD1234', name: 'Trial funnel by step' }-// The live insight embed loads the saved insight, then runs its query.-const INSIGHT_MOCKS = {+const CITED_FLAG = {+ ...FEATURE_FLAGS_FIXTURE.results[0],+ id: 7,+ key: 'new-plan-picker',+ name: 'Pin the start trial button to the top of the plan table',+ active: true,+ filters: {+ groups: [+ {+ properties: [{ key: 'email', type: 'person', value: 'example.com', operator: 'icontains' }],+ rollout_percentage: 100,+ description: 'Internal testers',+ },+ { properties: [], rollout_percentage: 50 },+ ],+ multivariate: null,+ payloads: {},+ },+}++const CITED_COHORT = {+ id: 3,+ name: 'Trial starters on laptops',+ count: 1009,+ is_static: false,+ is_calculating: false,+ last_calculation: '2026-09-28T17:00:00Z',+ created_at: '2026-09-21T10:00:00Z',+ deleted: false,+ filters: { properties: { type: 'AND', values: [] } },+}++const COHORT_PEOPLE = ['[email protected]', '[email protected]', '[email protected]', '[email protected]']++/** The insight and cohort embeds each run their own query through the same endpoint. */+async function queryByKind({ request }: { request: Request }): Promise<Record<string, unknown>> {+ const { query } = (await request.json()) as { query: { kind: string; source?: { kind: string } } }+ if (query.kind === NodeKind.ActorsQuery || query.source?.kind === NodeKind.ActorsQuery) {+ return {+ columns: ['person_display_name -- Person', 'id', 'created_at'],+ results: COHORT_PEOPLE.map((email, index) => [+ { display_name: email, id: `person-${index}` },+ `person-${index}`,+ '2026-09-21T10:00:00Z',+ ]),+ hasMore: false,+ }+ }+ return { results: CITED_INSIGHT.result }+}++// Each live embed loads its object, then runs the queries its own page runs.+const OBJECT_MOCKS = {get: {'/api/environments/:team_id/insights/': { count: 1, results: [CITED_INSIGHT] },'/api/projects/:team_id/insights/': { count: 1, results: [CITED_INSIGHT] },+ '/api/projects/:team_id/feature_flags/7/': CITED_FLAG,+ '/api/projects/:team_id/feature_flags/7/status': { status: 'active', reason: 'Feature flag is active' },+ '/api/projects/:team_id/cohorts/3/': CITED_COHORT,},post: {- '/api/environments/:team_id/query/': { results: CITED_INSIGHT.result },+ '/api/environments/:team_id/query/': queryByKind,+ '/api/environments/:team_id/query/:kind': queryByKind,},}@@ -484,7 +544,7 @@ export const Video: Story = {function objectMocks(): ReturnType<typeof taskMocks> {const mocks = taskMocks([...ARTIFACTS, ...OBJECT_REFERENCES])- return { get: { ...mocks.get, ...INSIGHT_MOCKS.get }, post: { ...mocks.post, ...INSIGHT_MOCKS.post } }+ return { get: { ...mocks.get, ...OBJECT_MOCKS.get }, post: { ...mocks.post, ...OBJECT_MOCKS.post } }}export const PostHogObjects: Story = {@@ -492,11 +552,21 @@ export const PostHogObjects: Story = {render: () => <StoryPage fileName="phref_trial_funnel" />,}-export const PostHogObjectWithoutEmbed: Story = {+export const PostHogObjectFlag: Story = {parameters: { msw: { mocks: objectMocks() } },render: () => <StoryPage fileName="phref_flag" />,}+export const PostHogObjectCohort: Story = {+ parameters: { msw: { mocks: objectMocks() } },+ render: () => <StoryPage fileName="phref_cohort" />,+}++export const PostHogObjectWithoutEmbed: Story = {+ parameters: { msw: { mocks: objectMocks() } },+ render: () => <StoryPage fileName="phref_survey" />,+}+export const Versions: Story = {parameters: { msw: { mocks: taskMocks([...ARTIFACTS, ...REPORT_OLDER_VERSIONS]) } },render: () => <StoryPage fileName={REPORT_FILE_NAME} />,@@ -574,12 +644,12 @@ function livingMocks(): ReturnType<typeof taskMocks> {return {get: {...mocks.get,- ...INSIGHT_MOCKS.get,+ ...OBJECT_MOCKS.get,[`/api/projects/:team_id/tasks/${TASK_ID}/runs/:run_id/living_artifacts/`]: {artifacts: LIVING_DOCUMENTS,},},- post: { ...mocks.post, ...INSIGHT_MOCKS.post },+ post: { ...mocks.post, ...OBJECT_MOCKS.post },}}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactObjectEmbed.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactObjectEmbed.tsxindex f37caa56b886..932e483965a9 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactObjectEmbed.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactObjectEmbed.tsx@@ -1,4 +1,13 @@+import { useValues } from 'kea'++import { NotFound } from 'lib/components/NotFound'+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'+import { humanFriendlyNumber } from 'lib/utils/numbers'+import { cohortEditLogic } from 'scenes/cohorts/cohortEditLogic'import { Dashboard } from 'scenes/dashboard/Dashboard'+import { featureFlagLogic } from 'scenes/feature-flags/featureFlagLogic'+import { FeatureFlagReleaseConditionsReadonly } from 'scenes/feature-flags/FeatureFlagReleaseConditionsReadonly'+import { FlagActiveToggleTag } from 'scenes/feature-flags/FlagActiveToggleTag'import { SessionRecordingPlayer } from 'scenes/session-recordings/player/SessionRecordingPlayer'import { SessionRecordingPlayerMode } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'@@ -8,11 +17,70 @@ import { DashboardPlacement, InsightShortId } from '~/types'import type { PostHogObjectRef } from '../taskRunArtifacts'-/**- * The live object a reference points at, rendered with the same components its own page uses.- * Kept in its own module so the insight, dashboard and replay code loads only when one opens.- */-export default function ArtifactObjectEmbed({ objectKind, objectId }: PostHogObjectRef): JSX.Element | null {+function EmbedLoading(): JSX.Element {+ return (+ <div className="flex flex-col gap-2 p-4">+ <LemonSkeleton className="h-6 w-48" />+ <LemonSkeleton className="h-32" />+ </div>+ )+}++function FlagEmbed({ id }: { id: number }): JSX.Element {+ const { featureFlag, featureFlagLoading, featureFlagMissing } = useValues(featureFlagLogic({ id }))+ if (featureFlagMissing) {+ return <NotFound object="feature flag" />+ }+ if (featureFlagLoading && !featureFlag.id) {+ return <EmbedLoading />+ }+ return (+ <div className="flex flex-col gap-4 p-4">+ <div className="flex flex-wrap items-center gap-2">+ <span className="font-semibold">{featureFlag.key}</span>+ <FlagActiveToggleTag active={featureFlag.active} />+ </div>+ {featureFlag.is_remote_configuration ? (+ <p className="m-0 text-sm text-secondary">Remote config flags do not use release conditions.</p>+ ) : (+ <FeatureFlagReleaseConditionsReadonly+ id={String(featureFlag.id)}+ filters={featureFlag.filters}+ isDisabled={!featureFlag.active}+ evaluationRuntime={featureFlag.evaluation_runtime}+ />+ )}+ </div>+ )+}++function CohortEmbed({ id }: { id: number }): JSX.Element {+ const { cohort, cohortLoading, cohortMissing, query } = useValues(cohortEditLogic({ id }))+ if (cohortMissing) {+ return <NotFound object="cohort" />+ }+ if (cohortLoading && cohort.id !== id) {+ return <EmbedLoading />+ }+ return (+ <div className="flex flex-col gap-3 p-4">+ {cohort.count != null ? (+ <span className="text-sm text-secondary">+ {humanFriendlyNumber(cohort.count)} {cohort.count === 1 ? 'person' : 'persons'}+ </span>+ ) : null}+ <div className="overflow-hidden rounded-md border border-primary bg-surface-primary">+ <Query+ uniqueKey={`task-artifact-cohort-${id}`}+ query={{ ...query, full: false, embedded: true, showOpenEditorButton: false }}+ readOnly+ />+ </div>+ </div>+ )+}++function EmbedBody({ objectKind, objectId }: PostHogObjectRef): JSX.Element | null {if (objectKind === 'insight') {return (<div className="flex min-h-full flex-col p-4">@@ -60,5 +128,24 @@ export default function ArtifactObjectEmbed({ objectKind, objectId }: PostHogObj</div>)}+ if (objectKind === 'flag') {+ return <FlagEmbed id={Number(objectId)} />+ }+ if (objectKind === 'cohort') {+ return <CohortEmbed id={Number(objectId)} />+ }return null}++/**+ * The live object a reference points at, rendered with the same components its own page uses.+ * Kept in its own module so the insight, dashboard and replay code loads only when one opens.+ */+export function ArtifactObjectEmbed(ref: PostHogObjectRef): JSX.Element {+ // These are LemonUI page components inside the quill artifacts pane, so they need PostHog's own color tokens back.+ return (+ <div data-not-quill className="h-full">+ <EmbedBody {...ref} />+ </div>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsxindex 5abcecd9404b..fef25ad9529f 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx@@ -106,7 +106,9 @@ import { ArtifactImageViewer } from './ArtifactImageViewer'const MAX_CSV_ROWS = 500-const ArtifactObjectEmbed = lazy(() => import('./ArtifactObjectEmbed'))+const ArtifactObjectEmbed = lazy(() =>+ import('./ArtifactObjectEmbed').then((m) => ({ default: m.ArtifactObjectEmbed }))+)type PreviewMode = 'rendered' | 'source'@@ -504,7 +506,6 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {const { selectArtifact } = useActions(taskRunArtifactsLogic({ taskId }))// Cited PostHog objects sit under their own label, after the files.const objects = files.filter((file) => !!postHogObjectRef(file.latest))- const livingDocuments = files.filter((file) => !!file.latest.living)const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {const target = event.target as HTMLElementif (event.altKey || event.ctrlKey || event.metaKey || target.getAttribute('role') !== 'option') {@@ -557,7 +558,7 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {Files</Text><Text size="xs" variant="muted" render={<span />} className="tabular-nums">- {files.length - objects.length - livingDocuments.length}+ {files.length - objects.length}</Text></div><div@@ -566,7 +567,7 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {onKeyDown={onKeyDown}className="flex min-h-0 flex-1 flex-col gap-px overflow-y-auto p-1.5">- {files.filter((file) => !postHogObjectRef(file.latest) && !file.latest.living).map(renderRow)}+ {files.filter((file) => !postHogObjectRef(file.latest)).map(renderRow)}{objects.length > 0 && (<div role="group" aria-label="In PostHog" className="flex flex-col gap-px"><Text@@ -581,20 +582,6 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {{objects.map(renderRow)}</div>)}- {livingDocuments.length > 0 && (- <div role="group" aria-label="Living documents" className="flex flex-col gap-px">- <Text- size="xs"- weight="medium"- variant="muted"- render={<span aria-hidden />}- className="px-2 pt-3 pb-1"- >- Living documents- </Text>- {livingDocuments.map(renderRow)}- </div>- )}</div></aside>)diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.tsindex bd48e1e4161b..ff7c231f6988 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts@@ -33,7 +33,14 @@ export interface PostHogObjectRef {}/** Object kinds the preview shows live, with the components their own pages use. Others show a card. */-export const LIVE_OBJECT_KINDS: ReadonlySet<string> = new Set(['insight', 'hogql', 'dashboard', 'replay'])+export const LIVE_OBJECT_KINDS: ReadonlySet<string> = new Set([+ 'insight',+ 'hogql',+ 'dashboard',+ 'replay',+ 'flag',+ 'cohort',+])export function postHogObjectRef(artifact: TaskRunArtifactResponseApi): PostHogObjectRef | null {const metadata = artifact.metadatadiff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.tsindex 691a2f64a52d..ced4c99c64b0 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts@@ -44,6 +44,7 @@ import {isTextPreview,livingArtifactFiles,livingArtifactsFromResponse,+ postHogObjectRef,} from './taskRunArtifacts'export interface TaskRunArtifactsLogicProps {@@ -434,13 +435,14 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([(livingArtifacts: TaskRunLivingArtifactResponseApi[]): ArtifactFile[] =>livingArtifactFiles(livingArtifacts),],- // Living documents come last, after the files and cited objects, so the list and the stepper share one order.+ // Documents the agent updates sit with the files, before cited objects, so the list and the stepper keep one order.files: [(s) => [s.artifacts, s.livingFiles],- (artifacts: RunArtifact[], livingFiles: ArtifactFile[]): ArtifactFile[] => [- ...groupArtifactVersions(artifacts),- ...livingFiles,- ],+ (artifacts: RunArtifact[], livingFiles: ArtifactFile[]): ArtifactFile[] => {+ const grouped = groupArtifactVersions(artifacts)+ const objects = grouped.filter((file) => !!postHogObjectRef(file.latest))+ return [...grouped.filter((file) => !postHogObjectRef(file.latest)), ...livingFiles, ...objects]+ },],selectedIndex: [(s) => [s.files, s.selectedFileKey],