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(phai): add the PostHog AI onboarding takeover (#81872)

Georgiy Tarasov9e166703a51a
diff --git a/frontend/public/posthog-ai-onboarding/connect.jpg b/frontend/public/posthog-ai-onboarding/connect.jpg
new file mode 100644
index 000000000000..1bb1788a4ceb
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/connect.jpg differ
diff --git a/frontend/public/posthog-ai-onboarding/connect.mp4 b/frontend/public/posthog-ai-onboarding/connect.mp4
new file mode 100644
index 000000000000..acc81421718a
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/connect.mp4 differ
diff --git a/frontend/public/posthog-ai-onboarding/delegate.jpg b/frontend/public/posthog-ai-onboarding/delegate.jpg
new file mode 100644
index 000000000000..f4ce6626301c
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/delegate.jpg differ
diff --git a/frontend/public/posthog-ai-onboarding/delegate.mp4 b/frontend/public/posthog-ai-onboarding/delegate.mp4
new file mode 100644
index 000000000000..43e882f09e62
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/delegate.mp4 differ
diff --git a/frontend/public/posthog-ai-onboarding/meet.jpg b/frontend/public/posthog-ai-onboarding/meet.jpg
new file mode 100644
index 000000000000..5b43360d68b2
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/meet.jpg differ
diff --git a/frontend/public/posthog-ai-onboarding/meet.mp4 b/frontend/public/posthog-ai-onboarding/meet.mp4
new file mode 100644
index 000000000000..c327d3b00148
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/meet.mp4 differ
diff --git a/frontend/public/posthog-ai-onboarding/skills.jpg b/frontend/public/posthog-ai-onboarding/skills.jpg
new file mode 100644
index 000000000000..958749d22e07
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/skills.jpg differ
diff --git a/frontend/public/posthog-ai-onboarding/skills.mp4 b/frontend/public/posthog-ai-onboarding/skills.mp4
new file mode 100644
index 000000000000..9842c97e4136
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/skills.mp4 differ
diff --git a/frontend/public/posthog-ai-onboarding/start.jpg b/frontend/public/posthog-ai-onboarding/start.jpg
new file mode 100644
index 000000000000..31500a384e90
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/start.jpg differ
diff --git a/frontend/public/posthog-ai-onboarding/start.mp4 b/frontend/public/posthog-ai-onboarding/start.mp4
new file mode 100644
index 000000000000..86e028a8b351
Binary files /dev/null and b/frontend/public/posthog-ai-onboarding/start.mp4 differ
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6d3f0c3b87f0..3ca312b093e7 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5120,6 +5120,22 @@ snapshots:
hash: v1.k794b7964.e893edaa31202a96439233ff254af446b1ae72107ca4d187a0ab27abc87db8ac.ClRtYW3AIl8tt8UNlaLx_52ymgYxs4FUUHPusEIzAs8
products-posthog-ai-composer--with-up-next-queue--light:
hash: v1.k794b7964.c6aa2aa587283120fba069845efe3f499ad93f57f01a44fe60714bf6de06aa77.sXADx8Z_E97Ez10RF94ejn6saVtul9mmzMW6g6F-M8U
+ products-posthog-ai-onboardingtakeover--awaiting-clip--dark:
+ hash: v1.k794b7964.ce34e421ee0ac8dc6b49c9bc2d52791298561b4ab0ae74add1780c7b1e82114f.QZzI-wxiMSzGEymlFhQuyVyPBJs10NJUpnH6GOxDlO0
+ products-posthog-ai-onboardingtakeover--awaiting-clip--light:
+ hash: v1.k794b7964.84aa042abbac1ee3cad0d476ef24208fe40d72f88d0d81602dcb26252d821f0e.c0kuQURgnTaBn4uhcROa0f01xvc9gxV0RlXtvTw6DT8
+ products-posthog-ai-onboardingtakeover--connect-step--dark:
+ hash: v1.k794b7964.ff359122aafe9b620d1fb602de323429de5ee861e95086d6e812f669c282ae61.gh10mc1wkfMWqEcO_qlzmKWtvkbLxC6pUxFmlhTcVfY
+ products-posthog-ai-onboardingtakeover--connect-step--light:
+ hash: v1.k794b7964.02ede31b9d5012426b8525c81b1d67629ebb526491c357513150862e0b687346.lRhfs6I891IOvbhmQhgxJf5E51c9b6Ds0RsWToZar_s
+ products-posthog-ai-onboardingtakeover--first-step--dark:
+ hash: v1.k794b7964.c7aa17cbb37d09ac3928f0f3f1e91d57c21255d469c80dc8564bfd76ca3b9db4.pQuCYozqf8ZXmx7XGGs43wAmbF5_ed95SPS6MXp5T_g
+ products-posthog-ai-onboardingtakeover--first-step--light:
+ hash: v1.k794b7964.c9709cb2fbc4cc9096d6a1dc45a7d88165ab91b51365baeff21a64435dd3314f.4fgG1gsMW_-f0ZttmB0pErd6KtjU78-xru6HOOAgl1I
+ products-posthog-ai-onboardingtakeover--start-step--dark:
+ hash: v1.k794b7964.4ca1129988e8d505656c9b1f1d88398516fdb24c8ffbdabab43251369514b1e6.0jyOb_I1ghN1euG9Pq-PrpA2WhttqN8WfGn2NZvAZ1g
+ products-posthog-ai-onboardingtakeover--start-step--light:
+ hash: v1.k794b7964.d1fadd3c1c5f4734cf0ae54b7ddc1f64e351cbd0ef1e7b16b78968f98ad51a44.1u2R4G2yaaKLW_puoLCQrIIPiZcZYN6UMWWziknTITk
products-posthog-ai-queuedmessagelist--empty--dark:
hash: v1.k794b7964.4313fbb59e762d6fc4a87fed828bb6c814697c489997e23111f95df3d84be347.VRvN01m1Gf36IcNO8lzu8q3mqxKWwSRROgPqtbxMiSU
products-posthog-ai-queuedmessagelist--empty--light:
@@ -7877,41 +7893,41 @@ snapshots:
scenes-app-surveys-surveyresponsekeysreference--webhook--light:
hash: v1.k794b7964.d1b5990c419ba81a718674107ef032126e0931aaffee0b2214f01caf425894c8.yjpNAjkX1uJIayGtXXge8xuVCAloNPgNhPIyEeeh8wQ
scenes-app-tasks--empty--dark:
- hash: v1.k794b7964.9b8d988ea244a5c98c663bb6ef469fcbb272541ae50b25a04de716b147a2e39a.-WPx0SKQ8sbgX9ln5yCNRXGMhj5nhLtmH0p96GW7ynE
+ hash: v1.k794b7964.f07f60f62995fe924bd5ed65850e10ab25f66df6c70c46409766ae2f48d217e5.P2c5ci8D9RWXC0hDE3piuXXbIbSSG92bDvajGX3L6iY
scenes-app-tasks--empty--light:
- hash: v1.k794b7964.af1763421e8b9aa81e741a91e469156aabed567ea88f91fc1f63b6c6539f997f.nWfcGXqL883ZI_ah56S5oZNjOaFp1PgnGK9rV6Ftv8A
+ hash: v1.k794b7964.2e639310c4944f76889d26101d347b00eae35c28cb21b73a7b37c1d9b5baf101.Eb9UOgFLoZzkHbWvrgY7zFLFTE3-_m1lZzYDNjRrYVQ
scenes-app-tasks--list-load-error--dark:
- hash: v1.k794b7964.9a4acf876cac2128e929b5bcbfe6a3a646edba55ee835ca06e795c9351234bea.enl-JQ-6pZGG5mj4V7SvzFTznSOcCg7WBdBZFNCTv2g
+ hash: v1.k794b7964.d53b40f13aeb3c390918ccf1fd2e4767bba43a856661a7201e9a4ab6a1855599.KPJeYWi038_pPOYak6FYunfOe_YpjSUL0t0nHchQco0
scenes-app-tasks--list-load-error--light:
- hash: v1.k794b7964.83d4d069731faf4c12870b70c2617fc44778c56c51980c0b8aa822c44f80dc0f.CCO1zM0lwBIrqevw7eUb1jyt68EBW3jzFZaBfjGx9_I
+ hash: v1.k794b7964.8fb5c1cbd8f30dfa93a15f1cf4ad157c01724b826c706e229392392d85fb6c0c.KGfwyP6m-yBY1OmmeOYg8pRM6FFwwcRGa1Ob3kcvZNM
scenes-app-tasks--list-with-composer--dark:
- hash: v1.k794b7964.a06a3aeabd0f2db5e38b365dc4a8bb850548a7f46cd37c9c5777eee40a861338.rBkSqxVlp-w5U_RN1gG0budNX0wcQSH8nl_vPvV2cN4
+ hash: v1.k794b7964.756e28a70d187a93123016bc701180742ca8ce8e38c27137551d1ad1a11136b4.XbeEUBERng61PLYJm1KKvkdNSEh9kxMrW6RO1hJQjn8
scenes-app-tasks--list-with-composer--light:
- hash: v1.k794b7964.70216bc573253b321f52878d5bacfb064761331bcc4acd2ab5ea184d45ea5522.cf1_x6o88dgo9txzmnrx5dy5hLM74fPopRdl-zmfFCY
+ hash: v1.k794b7964.9379caf3dc17b02b7ec3dd691de01481c897795c53d7e17246ee63e7354e81a6.1b8SeLm6Vf2O8Ydf9273V_wiRhVDhloCNtzQNf6HNUQ
scenes-app-tasks--loading--dark:
- hash: v1.k794b7964.f68d5bca36fcf378d4deda601e12dea8f6f0999c40a9bf3ffddb1a2cb9e8b11c.cEsHB5CJrV9U90DeHUO7JDn88deDCS-XmNsu4-BYYiM
+ hash: v1.k794b7964.dc58d14e704883628e5a2e448973c2bf40f998192dfc729e4936b4d2d2b71d67.KAxOfjwJ1dhSBLCnt3UeX7TX_cXo2mqGgTmWWtS13_c
scenes-app-tasks--loading--light:
- hash: v1.k794b7964.660376057c8573821ef3ceda49c76c8793650840d3fb9eee695509aaaf454a03.w4KtOHPpVK1RqVUHGIs84YBVtASff50o7xc98DrAkJQ
+ hash: v1.k794b7964.906dd83775961d29051f8e9aedf7a15aa92a3c4a47cb09c307e2853fbb302301.qihWUdFX63dpuA0oy-aFgIhM8i_ALfOxtv6aLTWXGV8
scenes-app-tasks--mobile-list--dark:
hash: v1.k794b7964.aa12d9283f2d371e340c367e042cc94b3368451aae7648d72a75604e50c32612.JvoQ6Mf3LGKxdkiERXq65fWkNggXdufEyGvsagLl5WE
scenes-app-tasks--mobile-list--light:
hash: v1.k794b7964.9fd49300ca0d02ce3fe8cf6ea7eb850af2f42332d19a821ac73a6108f33fd651.aHbvQ9EqCKA43njPMkK_xgXEq4rToiJ0U8zAsxjwEWA
scenes-app-tasks--mobile-new-task--dark:
- hash: v1.k794b7964.152028e19d3bfdd9a5b43056cc7a534f9306670b6378580c738d91ce8aa0f1ae.kpF88GS5QmzTmo2SghRIiNKvuyb37HLoHPyCl0TO1pw
+ hash: v1.k794b7964.5ec7cbf0273544a983f9eb54695debfeb9328356f25c9ecf497a67b76ffb519b.J0OsmJ_b0Egf48R-VZhYjS-sAEdRzD29UL-Fc4HHmdU
scenes-app-tasks--mobile-new-task--light:
- hash: v1.k794b7964.30f8365a26f5d40ce829f565fbd5e6ce1a46e91804667fe47847d95ba48a9260.u2eo4jAXtM3tsVq4nl03Q88ivKFl0E4D2si5BGfxtO8
+ hash: v1.k794b7964.5e5e1f065eddc09b14bc089a6c99118150a347c0d7ae50c05a88dd1ec3b3fffc.3ytBwe_ptE121gVzRRFFLyy5g0mnyxw2Re6Qv9vjZ9M
scenes-app-tasks--mobile-task-selected--dark:
hash: v1.k794b7964.db0156b3fd83b5c3494116788236075e0bc2c5ace019e4c1d9947d2b21fa70fb.4HfTdy-PBBkgEn0HFlUkrJm0D6GCiujf_ljrGGrLrsc
scenes-app-tasks--mobile-task-selected--light:
hash: v1.k794b7964.8de299235efc98c794efccb4501e490a0f77ee19c901ceaf672266cec2b5ada3.rce6dJ7kA184L-8c5CwwlsEO140N_TEYcHSO-_10d18
scenes-app-tasks--new-task--dark:
- hash: v1.k794b7964.a06a3aeabd0f2db5e38b365dc4a8bb850548a7f46cd37c9c5777eee40a861338.wPDxouoleQFuTYunxCumwqoo8eA_vBywWJt463oGnMw
+ hash: v1.k794b7964.756e28a70d187a93123016bc701180742ca8ce8e38c27137551d1ad1a11136b4.BJtOcYnQfGJ95pWUG9mb_4uPk-UUGwuXKZYER0z_pTY
scenes-app-tasks--new-task--light:
- hash: v1.k794b7964.70216bc573253b321f52878d5bacfb064761331bcc4acd2ab5ea184d45ea5522.-w7jAGK7f_wiev6IlAECrR88GMMOn5XAPDPJntF3wxM
+ hash: v1.k794b7964.9379caf3dc17b02b7ec3dd691de01481c897795c53d7e17246ee63e7354e81a6.dm0yw0i6qVGswZMSVV1fDRWcSxZ44LiJ9fjTgOXASvo
scenes-app-tasks--new-task-with-repository--dark:
- hash: v1.k794b7964.7ed39d8c33da473a740cdd612203bdc117ea7f4e5d1c73967f17b29e544cb993.qm4yEYcWfI7ND5WzORrtFy4CkojnJ2F9SO9_2BcPbjs
+ hash: v1.k794b7964.e6bd8d80073256a5ccfdd64bd55b5cfb12c44bba71739fdb50f9dc9e0a7054ee.dZCBGIl2eygiUiUSVDfxMJNG0-KCjMs-YTQwN4ZqQO8
scenes-app-tasks--new-task-with-repository--light:
- hash: v1.k794b7964.8a583297c357a16ab744f770c97f6f543ded85ba09fe619b946e0065944fe731.l1T_JTeOCHOcBSqCffYdQqxAtYTWXV_bTG9lZGvrWps
+ hash: v1.k794b7964.08a38b4245a1174f7ce20c5c2c506bbbd12bdb1ad34e9684eee26a56a191aeba.kxjvT-TynVb5pDWDLFAvUStnHtr6FhNiLEtkWgPlgzU
scenes-app-tasks--task-detail-loading--dark:
hash: v1.k794b7964.bb72909ac17aa66d816aad41006c66a4322781db3d4ab8fd60a82bbac50cee69.ETcygpHfNWRT-7UqS-FfnZLdrhpmdtIEAFc4C2ekROE
scenes-app-tasks--task-detail-loading--light:
diff --git a/frontend/src/layout/GlobalModals.tsx b/frontend/src/layout/GlobalModals.tsx
index 10d98244e67a..fddf3bfeb96c 100644
--- a/frontend/src/layout/GlobalModals.tsx
+++ b/frontend/src/layout/GlobalModals.tsx
@@ -14,6 +14,7 @@ import { useKeepMountedWhileOpen } from 'lib/hooks/useKeepMountedWhileOpen'
import { lazyWithRetry } from 'lib/utils/retryImport'
import { TwoFactorSetupModal } from 'scenes/authentication/two-factor-setup/TwoFactorSetupModal'
import { PaymentEntryModal } from 'scenes/billing/PaymentEntryModal'
+import { MaybePhaiOnboarding } from 'scenes/max/components/MaybePhaiOnboarding'
import { CreateOrganizationModal } from 'scenes/organization/CreateOrganizationModal'
import { CreateProjectModal } from 'scenes/project/CreateProjectModal'
import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'
@@ -86,6 +87,7 @@ export function GlobalModals(): JSX.Element {
{superpowersEnabled && <SuperpowersModal />}
<ConfigureHomeModal isOpen={isConfigureHomeModalOpen} onClose={hideConfigureHomeModal} />
<MaybeWelcomeDialog />
+ <MaybePhaiOnboarding />
<ComposeTicketModal />
</>
)
diff --git a/frontend/src/scenes/max/components/MaybePhaiOnboarding.tsx b/frontend/src/scenes/max/components/MaybePhaiOnboarding.tsx
new file mode 100644
index 000000000000..133072585180
--- /dev/null
+++ b/frontend/src/scenes/max/components/MaybePhaiOnboarding.tsx
@@ -0,0 +1,53 @@
+import { useValues } from 'kea'
+
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { sceneLogic } from 'scenes/sceneLogic'
+
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
+
+import { AiOnboarding } from 'products/posthog_ai/frontend/api/onboarding'
+
+import { maxGlobalLogic } from '../maxGlobalLogic'
+import { resolvePhaiOnboardingMounts } from './phaiOnboardingHost'
+import { MAX_SIDE_PANEL_ID } from './PhaiSidePanelChat'
+
+/**
+ * Mounts the PostHog AI onboarding takeover for whichever composers are on screen, and decides which of them
+ * may open it on its own. Lives here rather than in the surface because the answer depends on the runtime
+ * toggle and the entry point, neither of which `products/posthog_ai/frontend` is allowed to know about. The
+ * decision itself is in `resolvePhaiOnboardingMounts`, which is tested directly.
+ *
+ * Mounted from `GlobalModals` so the takeover can cover the whole app: it fires on the first open of the
+ * runner from any entry point, and a narrow side panel must not clip it.
+ */
+export function MaybePhaiOnboarding(): JSX.Element | null {
+ const { sceneId } = useValues(sceneLogic)
+ const { receivedFeatureFlags } = useValues(featureFlagLogic)
+ const { effectivePhaiView } = useValues(maxGlobalLogic)
+ const { sidePanelOpen, selectedTab } = useValues(sidePanelStateLogic)
+
+ const mounts = resolvePhaiOnboardingMounts({
+ sceneId,
+ receivedFeatureFlags,
+ effectivePhaiView,
+ sidePanelOpen,
+ selectedTab,
+ })
+
+ if (!mounts.length) {
+ return null
+ }
+
+ return (
+ <>
+ {mounts.map(({ host, autoOpen }) => (
+ // Both scenes run their composer under `taskTrackerSceneLogic`'s default `'scene'` key.
+ <AiOnboarding
+ key={host}
+ autoOpen={autoOpen}
+ panelId={host === 'side-panel' ? MAX_SIDE_PANEL_ID : undefined}
+ />
+ ))}
+ </>
+ )
+}
diff --git a/frontend/src/scenes/max/components/phaiOnboardingHost.test.ts b/frontend/src/scenes/max/components/phaiOnboardingHost.test.ts
new file mode 100644
index 000000000000..d259503dfe6d
--- /dev/null
+++ b/frontend/src/scenes/max/components/phaiOnboardingHost.test.ts
@@ -0,0 +1,77 @@
+import { Scene } from 'scenes/sceneTypes'
+
+import { SidePanelTab } from '~/types'
+
+import {
+ type PhaiOnboardingHostInput,
+ type PhaiOnboardingMount,
+ resolvePhaiOnboardingMounts,
+} from './phaiOnboardingHost'
+
+describe('resolvePhaiOnboardingMounts', () => {
+ const base: PhaiOnboardingHostInput = {
+ sceneId: Scene.Dashboards,
+ receivedFeatureFlags: true,
+ effectivePhaiView: 'legacy',
+ sidePanelOpen: false,
+ selectedTab: null,
+ }
+
+ const cases: [string, Partial<PhaiOnboardingHostInput>, PhaiOnboardingMount[]][] = [
+ [
+ 'the AI scene on the new view',
+ { sceneId: Scene.Max, effectivePhaiView: 'new' },
+ [{ host: 'scene', autoOpen: true }],
+ ],
+ ['the AI scene on the legacy view', { sceneId: Scene.Max }, []],
+ [
+ 'the AI scene before the flags land',
+ { sceneId: Scene.Max, effectivePhaiView: 'new', receivedFeatureFlags: false },
+ [],
+ ],
+ [
+ 'the side panel on the new view',
+ { effectivePhaiView: 'new', sidePanelOpen: true, selectedTab: SidePanelTab.Max },
+ [{ host: 'side-panel', autoOpen: true }],
+ ],
+ ['the side panel on the legacy view', { sidePanelOpen: true, selectedTab: SidePanelTab.Max }, []],
+ [
+ 'the AI scene with the side panel open too',
+ { sceneId: Scene.Max, effectivePhaiView: 'new', sidePanelOpen: true, selectedTab: SidePanelTab.Max },
+ [{ host: 'scene', autoOpen: true }],
+ ],
+ [
+ 'the tasks scene without the PostHog AI view',
+ { sceneId: Scene.TaskTracker },
+ [{ host: 'scene', autoOpen: false }],
+ ],
+ [
+ 'the tasks scene on the new view',
+ { sceneId: Scene.TaskTracker, effectivePhaiView: 'new' },
+ [{ host: 'scene', autoOpen: false }],
+ ],
+ [
+ 'the tasks scene with the side panel open',
+ {
+ sceneId: Scene.TaskTracker,
+ effectivePhaiView: 'new',
+ sidePanelOpen: true,
+ selectedTab: SidePanelTab.Max,
+ },
+ [
+ { host: 'side-panel', autoOpen: true },
+ { host: 'scene', autoOpen: false },
+ ],
+ ],
+ ['another scene on the new view', { effectivePhaiView: 'new' }, []],
+ [
+ 'another side panel tab on the new view',
+ { effectivePhaiView: 'new', sidePanelOpen: true, selectedTab: SidePanelTab.Support },
+ [],
+ ],
+ ]
+
+ it.each(cases)('resolves %s to %j', (_name, overrides, expected) => {
+ expect(resolvePhaiOnboardingMounts({ ...base, ...overrides })).toEqual(expected)
+ })
+})
diff --git a/frontend/src/scenes/max/components/phaiOnboardingHost.ts b/frontend/src/scenes/max/components/phaiOnboardingHost.ts
new file mode 100644
index 000000000000..9ac8d56387ed
--- /dev/null
+++ b/frontend/src/scenes/max/components/phaiOnboardingHost.ts
@@ -0,0 +1,72 @@
+import { Scene } from 'scenes/sceneTypes'
+
+import { SidePanelTab } from '~/types'
+
+import type { PhaiViewMode } from '../maxGlobalLogic'
+
+/** The composer a takeover targets. */
+export type PhaiOnboardingHost = 'scene' | 'side-panel'
+
+export interface PhaiOnboardingMount {
+ host: PhaiOnboardingHost
+ /** Whether this surface may open the takeover on its own, rather than only through the replay button. */
+ autoOpen: boolean
+}
+
+export interface PhaiOnboardingHostInput {
+ sceneId: string | null
+ receivedFeatureFlags: boolean
+ effectivePhaiView: PhaiViewMode
+ sidePanelOpen: boolean
+ selectedTab: SidePanelTab | null
+}
+
+/** The surface that may open the takeover by itself, on a first open of the new PostHog AI. */
+function resolveAutoOpenHost({
+ sceneId,
+ receivedFeatureFlags,
+ effectivePhaiView,
+ sidePanelOpen,
+ selectedTab,
+}: PhaiOnboardingHostInput): PhaiOnboardingHost | null {
+ // Flags re-resolve during a session (identify, reloadFeatureFlags). Acting before they land would let a
+ // dismissal write the "seen" flag for a user who never saw the new surface at all.
+ if (!receivedFeatureFlags || effectivePhaiView !== 'new') {
+ return null
+ }
+
+ // A scene wins when the side panel is open as well: it's the surface the user is looking at, and it's
+ // where a chosen starter prompt should land.
+ if (sceneId === Scene.Max) {
+ return 'scene'
+ }
+
+ if (sidePanelOpen && selectedTab === SidePanelTab.Max) {
+ return 'side-panel'
+ }
+
+ return null
+}
+
+/**
+ * Every takeover the current surfaces need. A surface belongs here whenever it renders the runner's
+ * composer, because the composer carries the replay button — leaving one out would show a button that opens
+ * nothing. Only a first open of the new PostHog AI opens the takeover by itself; `/tasks` mounts it purely
+ * so its replay button works.
+ */
+export function resolvePhaiOnboardingMounts(input: PhaiOnboardingHostInput): PhaiOnboardingMount[] {
+ const mounts: PhaiOnboardingMount[] = []
+
+ const autoOpenHost = resolveAutoOpenHost(input)
+ if (autoOpenHost) {
+ mounts.push({ host: autoOpenHost, autoOpen: true })
+ }
+
+ // `/tasks` reaches everyone who can open the scene, whatever their PostHog AI view mode, so a takeover
+ // opening there wouldn't line up with a first look at the new PostHog AI. It waits for the replay button.
+ if (input.sceneId === Scene.TaskTracker && autoOpenHost !== 'scene') {
+ mounts.push({ host: 'scene', autoOpen: false })
+ }
+
+ return mounts
+}
diff --git a/products/posthog_ai/frontend/api/onboarding.ts b/products/posthog_ai/frontend/api/onboarding.ts
new file mode 100644
index 000000000000..a0b6e49346e7
--- /dev/null
+++ b/products/posthog_ai/frontend/api/onboarding.ts
@@ -0,0 +1,22 @@
+// Tier 1 — the PostHog AI onboarding takeover: the full-screen "what changed" walkthrough a user sees once
+// on their first open of the new PostHog AI, plus the replay affordance that reopens it.
+//
+// `AiOnboarding` is the lazy wrapper: the dialog pulls quill's dialog chunk and the step media, and the host
+// that mounts it (`GlobalModals`) is downloaded on every logged-in page, so the impl is reached only through
+// its dynamic `import()`. The logic and the replay button are light and exported eagerly — the button lives
+// inside the already-loaded composer, and the logic is what the host reads to decide whether to render.
+//
+// Part of the `products/posthog_ai/frontend/api/<module>` public surface — import from here, not from deep
+// `../components/*` paths. See ../README.md for the tier model and ../AGENTS.md for the coupling rule.
+
+export { AiOnboarding } from '../components/onboarding/AiOnboarding'
+export type { AiOnboardingProps } from '../components/onboarding/AiOnboarding'
+
+export { OnboardingReplayButton } from '../components/onboarding/OnboardingReplayButton'
+export type { OnboardingReplayButtonProps } from '../components/onboarding/OnboardingReplayButton'
+
+export { aiOnboardingLogic, POSTHOG_AI_ONBOARDING_SEEN_KEY } from '../logics/aiOnboardingLogic'
+export type { AiOnboardingLogicProps } from '../logics/aiOnboardingLogic'
+
+export { DEFAULT_ONBOARDING_STEPS } from '../components/onboarding/onboardingSteps'
+export type { OnboardingStep, OnboardingStepKey } from '../components/onboarding/onboardingSteps'
diff --git a/products/posthog_ai/frontend/components/onboarding/AiOnboarding.tsx b/products/posthog_ai/frontend/components/onboarding/AiOnboarding.tsx
new file mode 100644
index 000000000000..9312dad9657e
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/AiOnboarding.tsx
@@ -0,0 +1,25 @@
+import { Suspense } from 'react'
+
+import { lazyWithRetry } from 'lib/utils/retryImport'
+
+import type { AiOnboardingProps } from './AiOnboardingImpl'
+
+export type { AiOnboardingProps } from './AiOnboardingImpl'
+
+// The takeover pulls quill's dialog chunk, the step manifest and the media leaf. Its host (`GlobalModals`)
+// is downloaded on every logged-in page, so the impl is reached only through this dynamic `import()` — the
+// type import above is erased, so the chunk genuinely splits. There's no fallback UI: a modal that hasn't
+// loaded yet should show nothing rather than flash a skeleton over the page.
+const Lazy = lazyWithRetry(() => import('./AiOnboardingImpl').then((m) => ({ default: m.AiOnboarding })))
+
+/**
+ * The PostHog AI onboarding takeover, code-split. Renders nothing until the host marks the user eligible
+ * (`autoOpen`) or the replay button opens it.
+ */
+export function AiOnboarding(props: AiOnboardingProps): JSX.Element {
+ return (
+ <Suspense fallback={null}>
+ <Lazy {...props} />
+ </Suspense>
+ )
+}
diff --git a/products/posthog_ai/frontend/components/onboarding/AiOnboardingImpl.tsx b/products/posthog_ai/frontend/components/onboarding/AiOnboardingImpl.tsx
new file mode 100644
index 000000000000..7f95b5b72007
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/AiOnboardingImpl.tsx
@@ -0,0 +1,127 @@
+import { BindLogic, useActions, useValues } from 'kea'
+import { useEffect, useMemo } from 'react'
+
+import { IconGithub } from '@posthog/icons'
+import { Badge, Button, Text } from '@posthog/quill-primitives'
+
+import api from 'lib/api'
+import { urls } from 'scenes/urls'
+
+import { type AiOnboardingLogicProps, aiOnboardingLogic } from '../../logics/aiOnboardingLogic'
+import { DEFAULT_ONBOARDING_STEPS } from './onboardingSteps'
+import { OnboardingTakeover } from './OnboardingTakeover'
+
+const GITHUB_AUTHORIZE_URL = api.integrations.authorizeUrl({ kind: 'github', next: urls.ai() })
+
+function ConnectGithubAction(): JSX.Element {
+ const { githubConnected, repositoryCount } = useValues(aiOnboardingLogic)
+ const { clickGithubCta } = useActions(aiOnboardingLogic)
+
+ if (githubConnected) {
+ return (
+ <div className="flex items-center gap-2">
+ <Badge variant="success">Connected</Badge>
+ <Text size="sm" variant="muted">
+ {repositoryCount === 1
+ ? 'One GitHub organization is connected.'
+ : `${repositoryCount} GitHub organizations are connected.`}
+ </Text>
+ </div>
+ )
+ }
+
+ return (
+ <div className="flex flex-wrap items-center gap-2">
+ <Button
+ variant="outline"
+ onClick={() => {
+ clickGithubCta()
+ // A full navigation rather than a link: this leaves the app for GitHub's OAuth consent
+ // screen, and an in-app <Link> would be a Lemon component inside a quill surface.
+ window.location.href = GITHUB_AUTHORIZE_URL
+ }}
+ data-attr="posthog-ai-onboarding-connect-github"
+ >
+ <IconGithub />
+ Connect GitHub
+ </Button>
+ </div>
+ )
+}
+
+function StarterPromptsAction(): JSX.Element {
+ const { starterPrompts } = useValues(aiOnboardingLogic)
+ const { selectStarterPrompt } = useActions(aiOnboardingLogic)
+
+ return (
+ <div className="flex flex-col gap-2">
+ {starterPrompts.map((prompt) => (
+ <Button
+ key={prompt}
+ variant="outline"
+ // Buttons are nowrap by default, which on a narrow viewport widens the whole column to
+ // the longest prompt and scrolls the dialog sideways.
+ className="h-auto justify-start whitespace-normal py-1.5 text-start"
+ onClick={() => selectStarterPrompt(prompt)}
+ data-attr="posthog-ai-onboarding-starter-prompt"
+ >
+ {prompt}
+ </Button>
+ ))}
+ </div>
+ )
+}
+
+export interface AiOnboardingProps extends AiOnboardingLogicProps {
+ /**
+ * Whether the host surface is showing PostHog AI to a user who hasn't seen the takeover. The host owns
+ * this because the answer depends on the runtime and the entry point, neither of which this surface
+ * knows about.
+ */
+ autoOpen: boolean
+}
+
+/**
+ * The onboarding takeover wired to its logic. Opens itself once when the host says the user is eligible,
+ * and afterwards only via the replay button.
+ */
+export function AiOnboarding({ panelId, autoOpen }: AiOnboardingProps): JSX.Element | null {
+ const logicProps: AiOnboardingLogicProps = useMemo(() => ({ panelId }), [panelId])
+ const { isOpen, stepIndex, hasSeenOnboarding, user } = useValues(aiOnboardingLogic(logicProps))
+ const { openOnboarding, closeOnboarding, finishOnboarding, setStepIndex, replayMedia } = useActions(
+ aiOnboardingLogic(logicProps)
+ )
+
+ useEffect(() => {
+ // `user` gates the whole thing: the seen flag lives on it, so acting before it resolves would show
+ // the takeover again to someone who already dismissed it.
+ if (autoOpen && user && !hasSeenOnboarding && !isOpen) {
+ openOnboarding()
+ }
+ // Only the eligibility edge should open it. `isOpen` is deliberately excluded: including it would
+ // re-open the takeover the moment the user dismisses it, since the seen flag round-trips the server.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [autoOpen, user, hasSeenOnboarding, openOnboarding])
+
+ if (!isOpen) {
+ return null
+ }
+
+ return (
+ <BindLogic logic={aiOnboardingLogic} props={logicProps}>
+ <OnboardingTakeover
+ open={isOpen}
+ steps={DEFAULT_ONBOARDING_STEPS}
+ stepIndex={stepIndex}
+ onStepIndexChange={setStepIndex}
+ onDismiss={closeOnboarding}
+ onFinish={finishOnboarding}
+ onReplayMedia={replayMedia}
+ stepActions={{
+ connect: <ConnectGithubAction />,
+ start: <StarterPromptsAction />,
+ }}
+ />
+ </BindLogic>
+ )
+}
diff --git a/products/posthog_ai/frontend/components/onboarding/OnboardingReplayButton.tsx b/products/posthog_ai/frontend/components/onboarding/OnboardingReplayButton.tsx
new file mode 100644
index 000000000000..43e3edd61803
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/OnboardingReplayButton.tsx
@@ -0,0 +1,35 @@
+import { useActions } from 'kea'
+
+import { IconInfo } from '@posthog/icons'
+import { LemonButton } from '@posthog/lemon-ui'
+
+import { aiOnboardingLogic } from '../../logics/aiOnboardingLogic'
+
+export interface OnboardingReplayButtonProps {
+ /** The composer's panel key, so a starter prompt chosen on replay reaches the right composer. */
+ panelId?: string
+}
+
+/**
+ * Reopens the onboarding takeover. Temporary: this exists for the migration to the new PostHog AI, so
+ * people who dismissed the takeover can still find what changed. Delete this component and its call site
+ * once the migration is done.
+ *
+ * Lemon rather than quill: it sits inside the Lemon composer welcome area, and the two libraries must not be
+ * mixed within one surface's internals.
+ */
+export function OnboardingReplayButton({ panelId }: OnboardingReplayButtonProps): JSX.Element {
+ const { openOnboarding } = useActions(aiOnboardingLogic({ panelId }))
+
+ return (
+ <LemonButton
+ type="tertiary"
+ size="xsmall"
+ icon={<IconInfo />}
+ onClick={() => openOnboarding(true)}
+ data-attr="posthog-ai-onboarding-replay"
+ >
+ What's new in PostHog AI
+ </LemonButton>
+ )
+}
diff --git a/products/posthog_ai/frontend/components/onboarding/OnboardingStepMedia.tsx b/products/posthog_ai/frontend/components/onboarding/OnboardingStepMedia.tsx
new file mode 100644
index 000000000000..33ac34c86ac7
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/OnboardingStepMedia.tsx
@@ -0,0 +1,238 @@
+import { memo, useCallback, useEffect, useRef, useState } from 'react'
+
+import { Button } from '@posthog/quill-primitives'
+
+import { cn } from 'lib/utils/css-classes'
+import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
+
+import type { OnboardingStep } from './onboardingSteps'
+
+// One wrapper for both branches, so a recorded clip drops into the same box the glyph occupied and the
+// dialog does not resize when the media lands.
+const PANEL = 'PhaiOnboardingTakeover__media relative w-full overflow-hidden rounded-md aspect-video'
+// Every step's clip is stacked in that box; only the current one is opaque.
+const LAYER = 'absolute inset-0 motion-safe:transition-opacity motion-safe:duration-150'
+/**
+ * How long a clip holds its first frame after its step arrives, so the headline gets the eye first. Every
+ * clip opens on a picture rather than a blank stage, so the wait costs nothing and the opening beats are
+ * no longer spent while the reader is still on the text above them.
+ */
+const PLAYBACK_DELAY_MS = 550
+
+function prefersReducedMotion(): boolean {
+ return (
+ typeof window !== 'undefined' &&
+ typeof window.matchMedia === 'function' &&
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches
+ )
+}
+
+function inStorybookEnvironment(): boolean {
+ return inStorybook() || inStorybookTestRunner()
+}
+
+// Hold every clip on its poster frame under Storybook so visual snapshots don't race the decoder.
+function shouldAutoplay(): boolean {
+ return !prefersReducedMotion() && !inStorybookEnvironment()
+}
+
+/**
+ * The play control is the reduced-motion accommodation, so it follows the preference rather than whatever
+ * suppressed autoplay. Storybook suppresses autoplay too, and gating the button on that would paint it into
+ * every visual snapshot of a panel that no reader sees it on.
+ */
+function showsPlayControl(): boolean {
+ return prefersReducedMotion() && !inStorybookEnvironment()
+}
+
+export interface OnboardingMediaPanelProps {
+ steps: readonly OnboardingStep[]
+ stepIndex: number
+ /** Clips play only while the dialog is open. */
+ open: boolean
+ onReplay?: (step: OnboardingStep) => void
+}
+
+/**
+ * The dialog's media panel: every step's clip at once, stacked, with the current one faded up.
+ *
+ * Mounting them all is what makes stepping between slides clean. Pointing a single `<video>` at a new `src`
+ * tears down the element's media state, so the panel would paint the incoming clip's poster, wait on the
+ * network, and only then cut to its first frame. Held side by side the clips are already decoded and parked
+ * on frame 0, so a step change is a crossfade between two live frames. The set is about 1.7 MB, fetched once
+ * when the dialog opens.
+ */
+export const OnboardingMediaPanel = memo(function OnboardingMediaPanel({
+ steps,
+ stepIndex,
+ open,
+ onReplay,
+}: OnboardingMediaPanelProps): JSX.Element {
+ return (
+ <div className={PANEL}>
+ {steps.map((step, index) => (
+ <OnboardingStepMedia
+ key={step.key}
+ step={step}
+ visible={index === stepIndex}
+ active={open && index === stepIndex}
+ onReplay={onReplay}
+ />
+ ))}
+ </div>
+ )
+})
+
+interface OnboardingStepMediaProps {
+ step: OnboardingStep
+ /** The one layer the reader sees. The rest sit under it at zero opacity, still loaded. */
+ visible: boolean
+ /** The clip only plays while its own step is the visible one. */
+ active: boolean
+ onReplay?: (step: OnboardingStep) => void
+}
+
+/**
+ * One step's looping demo clip. Follows the desktop app's onboarding card (`FeatureBentoCard`): the clip is
+ * parked on its poster frame, playback is driven imperatively rather than via `autoplay`/`loop`, and it
+ * loops back to `startTime` instead of 0 so the rest position always matches the poster. When motion is
+ * reduced the clip holds the still and offers an explicit play control.
+ */
+const OnboardingStepMedia = memo(function OnboardingStepMedia({
+ step,
+ visible,
+ active,
+ onReplay,
+}: OnboardingStepMediaProps): JSX.Element {
+ const videoRef = useRef<HTMLVideoElement>(null)
+ const [manuallyPlaying, setManuallyPlaying] = useState(false)
+ const media = step.media
+ const startTime = media?.startTime ?? 0
+
+ const play = useCallback((video: HTMLVideoElement): void => {
+ try {
+ // jsdom stubs `play()` to return undefined rather than a promise, so this can't assume one.
+ void video.play()?.catch(() => {
+ // play() rejects if the element isn't ready yet; the next effect run retries.
+ })
+ } catch {
+ // No media support at all (jsdom throws outright on some versions).
+ }
+ }, [])
+
+ const seekToStart = useCallback(
+ (video: HTMLVideoElement): void => {
+ try {
+ video.currentTime = startTime
+ } catch {
+ // Seeking before metadata is ready is a no-op; `loadedmetadata` retries it.
+ }
+ },
+ [startTime]
+ )
+
+ useEffect(() => {
+ const video = videoRef.current
+ if (!video) {
+ return
+ }
+ if (video.readyState >= 1) {
+ seekToStart(video)
+ return
+ }
+ const handler = (): void => seekToStart(video)
+ video.addEventListener('loadedmetadata', handler, { once: true })
+ return () => video.removeEventListener('loadedmetadata', handler)
+ }, [media?.src, seekToStart])
+
+ useEffect(() => {
+ const video = videoRef.current
+ if (!video) {
+ return
+ }
+ if (!active) {
+ // Paused where it stood, not rewound: the outgoing clip holds its last frame through the
+ // crossfade, and rewinding is the incoming clip's job below.
+ video.pause()
+ setManuallyPlaying(false)
+ return
+ }
+ seekToStart(video)
+ if (!shouldAutoplay()) {
+ return
+ }
+ // Cleared when the step changes, so stepping quickly through the dialog never starts a clip the
+ // reader has already moved past.
+ const timer = window.setTimeout(() => play(video), PLAYBACK_DELAY_MS)
+ return () => window.clearTimeout(timer)
+ // `manuallyPlaying` is deliberately not a dependency: it's reset here, and including it would make
+ // this effect cancel the very playback the play button just started.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [active, play, seekToStart])
+
+ const handleEnded = useCallback((): void => {
+ const video = videoRef.current
+ if (!video) {
+ return
+ }
+ seekToStart(video)
+ if (active && shouldAutoplay()) {
+ play(video)
+ } else {
+ setManuallyPlaying(false)
+ }
+ }, [active, play, seekToStart])
+
+ const handlePlayClick = useCallback((): void => {
+ const video = videoRef.current
+ if (!video) {
+ return
+ }
+ setManuallyPlaying(true)
+ play(video)
+ onReplay?.(step)
+ }, [onReplay, play, step])
+
+ if (!media) {
+ return (
+ <div
+ className={cn(LAYER, 'flex items-center justify-center', !visible && 'pointer-events-none opacity-0')}
+ aria-hidden
+ >
+ {/* Large and low-contrast: a small faint mark in a 306px panel reads as a missing asset,
+ the same mark at this scale reads as the step's own artwork. */}
+ <span className="text-[6rem] leading-none text-[var(--foreground)] opacity-15">{step.icon}</span>
+ </div>
+ )
+ }
+
+ return (
+ <div className={cn(LAYER, !visible && 'pointer-events-none opacity-0')} aria-hidden={!visible}>
+ <video
+ ref={videoRef}
+ className="block h-full w-full object-cover"
+ src={media.src}
+ poster={media.poster}
+ muted
+ playsInline
+ // Every clip is decoded up front so that stepping between slides never waits on the network.
+ preload="auto"
+ aria-label={step.headline}
+ onEnded={handleEnded}
+ />
+ {visible && showsPlayControl() && !manuallyPlaying && (
+ <Button
+ variant="primary"
+ size="sm"
+ // Bottom-left, because every clip now carries the composer, whose send button sits in
+ // the bottom-right corner of the frame.
+ className="absolute bottom-2 start-2"
+ onClick={handlePlayClick}
+ data-attr="posthog-ai-onboarding-play-clip"
+ >
+ Play
+ </Button>
+ )}
+ </div>
+ )
+})
diff --git a/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.scss b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.scss
new file mode 100644
index 000000000000..b8a4930cd22e
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.scss
@@ -0,0 +1,48 @@
+/*
+ * Width for the onboarding dialog.
+ *
+ * Quill clamps `.quill-dialog__content` to `max-width: 24rem` above 640px, and that rule lives in
+ * `@layer components` (packages/quill/packages/primitives/src/dialog.css). This override is deliberately
+ * unlayered so it wins the cascade outright rather than depending on where the app's utility layer sorts,
+ * which is the approach lemon-skin.scss documents. Everything else about the dialog is quill's own.
+ */
+.PhaiOnboardingTakeover {
+ /*
+ * `min()` keeps quill's own viewport gutter, which this override would otherwise beat as well: quill
+ * sets `max-width: calc(100vw - 3rem)` on the same property, so a bare 36rem would run the dialog edge
+ * to edge on a narrow screen.
+ */
+ max-width: min(36rem, calc(100vw - 3rem));
+}
+
+/*
+ * Quill assumes a header/body/footer dialog and hard-codes `auto minmax(0, 1fr) auto` whenever a
+ * `DialogBody` is present. This dialog has no header row, so that template would hand the `1fr` to the
+ * footer and stretch it. Two rows: the body takes the space, the footer stays its own height.
+ */
+.PhaiOnboardingTakeover:has([data-slot='dialog-body']) {
+ grid-template-rows: minmax(0, 1fr) auto;
+}
+
+/*
+ * Room for quill's close button, which is positioned against the dialog rather than against any row. With
+ * no header here the body starts at the top of the dialog, so the button would otherwise sit on the media
+ * panel — over a clip, on a surface that is light in both themes.
+ */
+.PhaiOnboardingTakeover [data-slot='dialog-body'] > [data-slot='scroll-area-viewport'] {
+ padding-top: 2.75rem;
+}
+
+/*
+ * The media panel. `--muted` sits too close to `--background` in both themes to read as a distinct slot, so
+ * mix the foreground in directly: one rule that steps down from the dialog surface by the same amount
+ * whether the page is light or dark.
+ *
+ * No top fade. Masking the panel's top edge to transparent hands it whatever is behind the dialog, which
+ * in dark mode is a dark band laid over a light clip and reads as a shadow rather than as a fade. A clip
+ * that needs its earliest messages to dissolve rather than cut has to fade them into its own surface,
+ * inside the recording, where the color is the one the clip was shot against.
+ */
+.PhaiOnboardingTakeover__media {
+ background: color-mix(in oklab, var(--foreground) 6%, var(--background));
+}
diff --git a/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.stories.tsx b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.stories.tsx
new file mode 100644
index 000000000000..d8d3c5e4da5f
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.stories.tsx
@@ -0,0 +1,88 @@
+import type { Meta, StoryObj } from '@storybook/react'
+import { useState } from 'react'
+
+import { IconGithub } from '@posthog/icons'
+import { Button } from '@posthog/quill-primitives'
+
+import { DEFAULT_ONBOARDING_STEPS, DEFAULT_STARTER_PROMPTS } from './onboardingSteps'
+import { OnboardingTakeover, type OnboardingTakeoverProps } from './OnboardingTakeover'
+
+// Logic-free and controlled — the story owns the step index, exactly as `AiOnboardingImpl` does. The dialog
+// portals to the document body and covers the viewport, so these stories have no surrounding layout.
+const meta: Meta<OnboardingTakeoverProps> = {
+ title: 'Products/PostHog AI/OnboardingTakeover',
+ component: OnboardingTakeover,
+ tags: ['autodocs'],
+ parameters: { layout: 'fullscreen' },
+ render: ({ steps, stepIndex: initialStepIndex, stepActions }) => {
+ const [stepIndex, setStepIndex] = useState(initialStepIndex)
+ return (
+ <OnboardingTakeover
+ open
+ steps={steps}
+ stepIndex={stepIndex}
+ onStepIndexChange={setStepIndex}
+ stepActions={stepActions}
+ onDismiss={() => {}}
+ onFinish={() => {}}
+ />
+ )
+ },
+}
+export default meta
+
+type Story = StoryObj<OnboardingTakeoverProps>
+
+const starterPromptsAction = (
+ <div className="flex flex-col gap-2">
+ {DEFAULT_STARTER_PROMPTS.map((prompt) => (
+ <Button key={prompt} variant="outline" className="h-auto justify-start whitespace-normal py-1.5 text-start">
+ {prompt}
+ </Button>
+ ))}
+ </div>
+)
+
+/** The opening step, which has to reset what a returning user expects of the old assistant. */
+export const FirstStep: Story = {
+ args: { steps: DEFAULT_ONBOARDING_STEPS, stepIndex: 0 },
+}
+
+/** The GitHub step, the one conversion in the flow. Its action block is supplied by the host. */
+export const ConnectStep: Story = {
+ args: {
+ steps: DEFAULT_ONBOARDING_STEPS,
+ stepIndex: DEFAULT_ONBOARDING_STEPS.findIndex((step) => step.key === 'connect'),
+ stepActions: {
+ connect: (
+ <div className="flex flex-wrap items-center gap-2">
+ <Button variant="outline">
+ <IconGithub />
+ Connect GitHub
+ </Button>
+ </div>
+ ),
+ },
+ },
+}
+
+/** The last step. There is no Next button — the starter prompts are the call to action. */
+export const StartStep: Story = {
+ args: {
+ steps: DEFAULT_ONBOARDING_STEPS,
+ stepIndex: DEFAULT_ONBOARDING_STEPS.length - 1,
+ stepActions: { start: starterPromptsAction },
+ },
+}
+
+/**
+ * A step whose clip has not been recorded yet. Its media panel holds the step's own glyph in exactly the
+ * box a clip would occupy, so the dialog is the same size either way. Every default step ships a clip, so
+ * this one is synthesized.
+ */
+export const AwaitingClip: Story = {
+ args: {
+ steps: DEFAULT_ONBOARDING_STEPS.map((step, index) => (index === 0 ? { ...step, media: undefined } : step)),
+ stepIndex: 0,
+ },
+}
diff --git a/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.test.tsx b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.test.tsx
new file mode 100644
index 000000000000..2733c5941b05
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.test.tsx
@@ -0,0 +1,57 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { DEFAULT_ONBOARDING_STEPS, type OnboardingStep } from './onboardingSteps'
+import { OnboardingTakeover } from './OnboardingTakeover'
+
+describe('OnboardingTakeover', () => {
+ afterEach(cleanup)
+
+ function renderTakeover(props: Partial<Parameters<typeof OnboardingTakeover>[0]> = {}): void {
+ render(
+ <OnboardingTakeover
+ open
+ steps={DEFAULT_ONBOARDING_STEPS}
+ stepIndex={0}
+ onStepIndexChange={() => {}}
+ onDismiss={() => {}}
+ onFinish={() => {}}
+ {...props}
+ />
+ )
+ }
+
+ // The last step's call to action is the starter prompts, not a Next button. A stale `isLastStep` check
+ // would leave a Next button that advances past the end and strands the user on an empty step.
+ it('replaces Next with the step action on the last step', () => {
+ renderTakeover({
+ stepIndex: DEFAULT_ONBOARDING_STEPS.length - 1,
+ stepActions: { start: <button type="button">What changed this week?</button> },
+ })
+
+ expect(screen.queryByText('Next')).not.toBeInTheDocument()
+ expect(screen.getByText('What changed this week?')).toBeInTheDocument()
+ })
+
+ // Not every step has a clip, and steps can be overridden by the host. A <video> with an undefined src
+ // would show a broken player, and dropping the panel entirely would resize the dialog between steps.
+ it('holds the media panel with the step glyph for a step with no clip', () => {
+ // Every default step ships a clip, so the no-clip case has to be built rather than looked up.
+ const withoutMedia: OnboardingStep = { ...DEFAULT_ONBOARDING_STEPS[0], media: undefined }
+ renderTakeover({ steps: [withoutMedia] })
+
+ expect(document.querySelector('video')).toBeNull()
+ expect(document.querySelector('.aspect-video')).not.toBeNull()
+
+ cleanup()
+
+ const withMedia: OnboardingStep = {
+ ...DEFAULT_ONBOARDING_STEPS[0],
+ media: { src: '/static/posthog-ai-onboarding/meet.mp4' },
+ }
+ renderTakeover({ steps: [withMedia] })
+
+ expect(document.querySelector('video')).toHaveAttribute('src', '/static/posthog-ai-onboarding/meet.mp4')
+ })
+})
diff --git a/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.tsx b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.tsx
new file mode 100644
index 000000000000..5ec9fe1c0634
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/OnboardingTakeover.tsx
@@ -0,0 +1,157 @@
+import './OnboardingTakeover.scss'
+
+import { type ReactNode, useCallback } from 'react'
+
+import {
+ Button,
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogFooter,
+ DialogTitle,
+ Dot,
+ Heading,
+ Text,
+} from '@posthog/quill-primitives'
+
+import { cn } from 'lib/utils/css-classes'
+
+import { OnboardingMediaPanel } from './OnboardingStepMedia'
+import type { OnboardingStep, OnboardingStepKey } from './onboardingSteps'
+
+// Logic-free onboarding dialog that walks one step at a time. The caller owns the step index, what
+// "dismiss" persists, and the interactive blocks for the steps that need live state (the GitHub CTA on
+// CONNECT, the starter prompts on START) — this component only presents.
+
+export interface OnboardingTakeoverProps {
+ open: boolean
+ steps: readonly OnboardingStep[]
+ stepIndex: number
+ onStepIndexChange: (stepIndex: number) => void
+ /** Rendered under the body copy of the matching step. The one seam for steps that read live state. */
+ stepActions?: Partial<Record<OnboardingStepKey, ReactNode>>
+ /** Fires on the close button, Esc, and the backdrop. */
+ onDismiss: () => void
+ /** Fires when the user advances past the last step. */
+ onFinish: () => void
+ /** Fires when the user replays a step's clip by hand (only reachable when motion is reduced). */
+ onReplayMedia?: (step: OnboardingStep) => void
+}
+
+export function OnboardingTakeover({
+ open,
+ steps,
+ stepIndex,
+ onStepIndexChange,
+ stepActions,
+ onDismiss,
+ onFinish,
+ onReplayMedia,
+}: OnboardingTakeoverProps): JSX.Element | null {
+ const step = steps[stepIndex]
+ const isFirstStep = stepIndex === 0
+ const isLastStep = stepIndex === steps.length - 1
+
+ const handleOpenChange = useCallback(
+ (nextOpen: boolean): void => {
+ if (!nextOpen) {
+ onDismiss()
+ }
+ },
+ [onDismiss]
+ )
+
+ const handleNext = useCallback((): void => {
+ if (isLastStep) {
+ onFinish()
+ } else {
+ onStepIndexChange(stepIndex + 1)
+ }
+ }, [isLastStep, onFinish, onStepIndexChange, stepIndex])
+
+ if (!step) {
+ return null
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={handleOpenChange}>
+ <DialogContent
+ className="PhaiOnboardingTakeover"
+ data-attr="posthog-ai-onboarding"
+ aria-label="What's new in PostHog AI"
+ >
+ {/* No DialogHeader: the media panel leads, so the headline sits below it inside the body
+ rather than in a pinned row above. */}
+ <DialogBody>
+ <div className="flex w-full flex-col gap-4">
+ <OnboardingMediaPanel
+ steps={steps}
+ stepIndex={stepIndex}
+ open={open}
+ onReplay={onReplayMedia}
+ />
+ <DialogTitle render={<Heading size="lg" />}>{step.headline}</DialogTitle>
+ <Text size="sm" variant="muted">
+ {step.body}
+ </Text>
+ {stepActions?.[step.key]}
+ </div>
+ </DialogBody>
+
+ {/* A three-column grid, not `justify-between`: the left group is wider than the right, so
+ space-between would push the step dots off the dialog's centerline. Also keeps the bar a
+ single row, where quill's footer would stack it in reverse order below `sm`. */}
+ <DialogFooter className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
+ <div className="justify-self-start">
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={() => onStepIndexChange(stepIndex - 1)}
+ disabled={isFirstStep}
+ data-attr="posthog-ai-onboarding-back"
+ >
+ Back
+ </Button>
+ </div>
+
+ {/* Plain buttons, not a tablist: there are no tab panels here, only a step the whole
+ dialog swaps to, so `aria-current` describes it honestly. Each button's only child
+ is a decorative Dot, so the headline has to supply the accessible name. */}
+ <div className="flex items-center gap-1.5">
+ {steps.map((indicatorStep, index) => (
+ <button
+ key={indicatorStep.key}
+ type="button"
+ aria-current={index === stepIndex ? 'step' : undefined}
+ aria-label={indicatorStep.headline}
+ className="flex items-center p-1"
+ onClick={() => onStepIndexChange(index)}
+ data-attr={`posthog-ai-onboarding-step-${indicatorStep.key}`}
+ >
+ <Dot
+ variant={index === stepIndex ? 'info' : 'default'}
+ className={cn(index !== stepIndex && 'opacity-40')}
+ />
+ </button>
+ ))}
+ </div>
+
+ {/* The last step's action block carries the call to action, so there's no Next to show.
+ The grid cell stays either way, so the dots do not shift on the final step. */}
+ <div className="justify-self-end">
+ {!isLastStep && (
+ <Button
+ variant="primary"
+ size="sm"
+ onClick={handleNext}
+ data-attr="posthog-ai-onboarding-next"
+ >
+ Next
+ </Button>
+ )}
+ </div>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/products/posthog_ai/frontend/components/onboarding/onboardingSteps.tsx b/products/posthog_ai/frontend/components/onboarding/onboardingSteps.tsx
new file mode 100644
index 000000000000..9b5c511ecd1b
--- /dev/null
+++ b/products/posthog_ai/frontend/components/onboarding/onboardingSteps.tsx
@@ -0,0 +1,93 @@
+import { IconBolt, IconBook, IconGithub, IconList, IconSparkles } from '@posthog/icons'
+
+// Default, overridable content for the PostHog AI onboarding takeover. Five steps, in order: reset the
+// user's prediction of the old assistant, then one step per capability, ending on a real prompt. Pass your
+// own array to override.
+
+export type OnboardingStepKey = 'meet' | 'delegate' | 'connect' | 'skills' | 'start'
+
+export interface OnboardingStepMediaSpec {
+ /** Served from `frontend/public/`, referenced as a `/static/…` path so the clip stays out of the bundle. */
+ src: string
+ /** Still shown while the clip loads. It is the frame at `startTime`, so the swap to video is invisible. */
+ poster?: string
+ /** Seconds into the clip that `poster` was taken from; playback starts and loops here. */
+ startTime?: number
+}
+
+export interface OnboardingStep {
+ key: OnboardingStepKey
+ headline: string
+ body: string
+ /** Stands in for the clip until one is recorded, and gives each step a face of its own either way. */
+ icon: JSX.Element
+ /**
+ * Absent when a step has no clip, in which case the media panel shows `icon` instead. Clips live in
+ * `frontend/public/posthog-ai-onboarding/` and are committed as output: what composes them is not in
+ * this repo, so they cannot be re-rendered from a clone.
+ */
+ media?: OnboardingStepMediaSpec
+}
+
+export const DEFAULT_ONBOARDING_STEPS: readonly OnboardingStep[] = [
+ {
+ key: 'meet',
+ icon: <IconSparkles />,
+ headline: 'PostHog AI is a different agent now',
+ body: 'It is a coding agent, and it works across every PostHog product.',
+ media: { src: '/static/posthog-ai-onboarding/meet.mp4', poster: '/static/posthog-ai-onboarding/meet.jpg' },
+ },
+ {
+ key: 'delegate',
+ icon: <IconList />,
+ headline: 'Hand it a hard problem',
+ body: 'It writes a plan, you approve it, then it works in the background.',
+ media: {
+ src: '/static/posthog-ai-onboarding/delegate.mp4',
+ poster: '/static/posthog-ai-onboarding/delegate.jpg',
+ },
+ },
+ {
+ key: 'skills',
+ icon: <IconBook />,
+ headline: 'Skills teach it how your team works',
+ body: 'Ask it to write the skill, then it follows that every time.',
+ media: { src: '/static/posthog-ai-onboarding/skills.mp4', poster: '/static/posthog-ai-onboarding/skills.jpg' },
+ },
+ // Connect sits directly before the starter prompts: it is the one step with lasting value, and one of
+ // those prompts ends in a pull request when GitHub is connected.
+ {
+ key: 'connect',
+ icon: <IconGithub />,
+ headline: 'Connect GitHub, so it can see how your product actually works',
+ body: 'It reads your code and opens any fix it finds as a pull request.',
+ media: {
+ src: '/static/posthog-ai-onboarding/connect.mp4',
+ poster: '/static/posthog-ai-onboarding/connect.jpg',
+ },
+ },
+ {
+ key: 'start',
+ icon: <IconBolt />,
+ headline: 'Start with something real',
+ body: 'The same agent is in Slack and behind the MCP. Pick a question below.',
+ media: { src: '/static/posthog-ai-onboarding/start.mp4', poster: '/static/posthog-ai-onboarding/start.jpg' },
+ },
+]
+
+/** One starter prompt per Job from the onboarding research: decide, fix the bug, build the practice. */
+export const DEFAULT_STARTER_PROMPTS: readonly string[] = [
+ 'What changed in my product this week that I should know about?',
+ 'Find the biggest issue in my product right now and fix it.',
+ 'Build me a report on how my product is used and show where each number comes from.',
+]
+
+/**
+ * Shown instead when the project has no events yet. The default prompts all read the project's data, so on a
+ * brand-new org every one of them would dead-end on an empty result.
+ */
+export const EMPTY_PROJECT_STARTER_PROMPTS: readonly string[] = [
+ 'Set up PostHog tracking in my codebase.',
+ 'What events should I track for a product like mine?',
+ 'Add error tracking and show me the first issues.',
+]
diff --git a/products/posthog_ai/frontend/logics/aiOnboardingLogic.test.ts b/products/posthog_ai/frontend/logics/aiOnboardingLogic.test.ts
new file mode 100644
index 000000000000..62fe407d55fe
--- /dev/null
+++ b/products/posthog_ai/frontend/logics/aiOnboardingLogic.test.ts
@@ -0,0 +1,122 @@
+import { MOCK_DEFAULT_ORGANIZATION, MOCK_DEFAULT_TEAM, MOCK_DEFAULT_USER } from 'lib/api.mock'
+
+import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
+
+import { userLogic } from 'scenes/userLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+import type { OrganizationType, TeamType } from '~/types'
+
+import { DEFAULT_STARTER_PROMPTS, EMPTY_PROJECT_STARTER_PROMPTS } from '../components/onboarding/onboardingSteps'
+import { POSTHOG_AI_ONBOARDING_SEEN_KEY, aiOnboardingLogic } from './aiOnboardingLogic'
+import { composerSeedLogic } from './composerSeedLogic'
+
+describe('aiOnboardingLogic', () => {
+ let logic: ReturnType<typeof aiOnboardingLogic.build>
+ let seedLogic: ReturnType<typeof composerSeedLogic.build>
+ let userUpdates: Record<string, any>[]
+
+ beforeEach(() => {
+ userUpdates = []
+ useMocks({
+ patch: {
+ '/api/users/@me/': async ({ request }) => {
+ const body = (await request.json()) as Record<string, any>
+ userUpdates.push(body)
+ return { ...MOCK_DEFAULT_USER, ...body }
+ },
+ },
+ })
+ })
+
+ function mountLogic({
+ ingestedEvent = true,
+ aiApproved = true,
+ }: { ingestedEvent?: boolean; aiApproved?: boolean } = {}): void {
+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, ingested_event: ingestedEvent } as TeamType, undefined, {
+ ...MOCK_DEFAULT_ORGANIZATION,
+ is_ai_data_processing_approved: aiApproved,
+ } as OrganizationType)
+ logic = aiOnboardingLogic()
+ logic.mount()
+ seedLogic = composerSeedLogic({})
+ seedLogic.mount()
+ }
+
+ afterEach(() => {
+ seedLogic?.unmount()
+ logic?.unmount()
+ })
+
+ // A brand-new org has no events, so the default prompts would all come back empty. Inverting this
+ // selector is the difference between an onboarding that works on a fresh project and three dead ends.
+ it.each([
+ [true, DEFAULT_STARTER_PROMPTS],
+ [false, EMPTY_PROJECT_STARTER_PROMPTS],
+ ])('offers the right starter prompts when ingested_event is %s', (ingestedEvent, expected) => {
+ mountLogic({ ingestedEvent })
+
+ expect(logic.values.starterPrompts).toEqual(expected)
+ })
+
+ // Auto-submitting without org AI-data-processing approval pops the consent flow on top of the
+ // onboarding and the run never starts. Without approval the prompt must only prefill the composer.
+ it.each([
+ [true, true],
+ [false, false],
+ ])('sets autoSubmit to %s when AI data processing approval is %s', async (aiApproved, expectedAutoSubmit) => {
+ mountLogic({ aiApproved })
+
+ await expectLogic(logic, () => {
+ logic.actions.selectStarterPrompt('Audit my event tracking.')
+ }).toFinishAllListeners()
+
+ expect(seedLogic.values.seed).toEqual({
+ prompt: 'Audit my event tracking.',
+ autoSubmit: expectedAutoSubmit,
+ })
+ })
+
+ // `has_seen_product_intro_for` is one shared map across every product intro. Writing the onboarding key
+ // without spreading the existing entries would silently re-trigger every other product's intro.
+ it('records the seen flag without dropping other product intros', async () => {
+ mountLogic()
+ userLogic
+ .findMounted()
+ ?.actions.loadUserSuccess({ ...MOCK_DEFAULT_USER, has_seen_product_intro_for: { session_replay: true } })
+
+ await expectLogic(logic, () => {
+ logic.actions.closeOnboarding()
+ }).toFinishAllListeners()
+
+ expect(userUpdates).toHaveLength(1)
+ expect(userUpdates[0].has_seen_product_intro_for).toEqual({
+ session_replay: true,
+ [POSTHOG_AI_ONBOARDING_SEEN_KEY]: true,
+ })
+ })
+
+ // Which step a user bails on is the segment signal the onboarding exists to collect. Stepping back and
+ // forth must not inflate it, or the per-step funnel stops meaning anything.
+ it('reports each step view only once per opening', async () => {
+ mountLogic()
+ const captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)
+
+ try {
+ await expectLogic(logic, () => {
+ logic.actions.openOnboarding()
+ logic.actions.setStepIndex(1)
+ logic.actions.setStepIndex(0)
+ logic.actions.setStepIndex(1)
+ }).toFinishAllListeners()
+
+ const stepViews = captureSpy.mock.calls.filter((call) => call[0] === 'posthog ai onboarding step viewed')
+ expect(stepViews).toHaveLength(1)
+ expect(stepViews[0][1]).toEqual(expect.objectContaining({ step_key: 'delegate', step_index: 1 }))
+ } finally {
+ captureSpy.mockRestore()
+ }
+ })
+})
diff --git a/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts b/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts
new file mode 100644
index 000000000000..85eceaa9403c
--- /dev/null
+++ b/products/posthog_ai/frontend/logics/aiOnboardingLogic.ts
@@ -0,0 +1,293 @@
+import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import posthog from 'posthog-js'
+
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'
+import { teamLogic } from 'scenes/teamLogic'
+import { userLogic } from 'scenes/userLogic'
+
+import type { IntegrationType, TeamPublicType, TeamType, UserType } from '~/types'
+
+import {
+ DEFAULT_ONBOARDING_STEPS,
+ DEFAULT_STARTER_PROMPTS,
+ EMPTY_PROJECT_STARTER_PROMPTS,
+ type OnboardingStep,
+} from '../components/onboarding/onboardingSteps'
+import { type ComposerSeed, composerSeedLogic } from './composerSeedLogic'
+
+/**
+ * Key into `user.has_seen_product_intro_for`. That map is a plain `Record<string, boolean>` end to end, so a
+ * non-`ProductKey` key is fine — web analytics already stores its own composed key there the same way.
+ */
+export const POSTHOG_AI_ONBOARDING_SEEN_KEY = 'posthog_ai_onboarding'
+
+export interface AiOnboardingLogicProps {
+ /** The embedded composer's panel key, so a chosen starter prompt reaches the right composer. */
+ panelId?: string
+}
+
+export interface OnboardingReportProperties {
+ step_key: string
+ step_index: number
+ step_count: number
+ is_replay: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface aiOnboardingLogicValues {
+ dataProcessingAccepted: boolean // aiConsentLogic
+ githubIntegrations: IntegrationType[] // integrationsLogic
+ integrationsLoading: boolean // integrationsLogic
+ currentTeam: TeamPublicType | TeamType | null // teamLogic
+ user: UserType | null // userLogic
+ currentStep: OnboardingStep | null
+ githubConnected: boolean
+ hasSeenOnboarding: boolean
+ isOpen: boolean
+ isReplay: boolean
+ projectHasData: boolean
+ reportProperties: OnboardingReportProperties
+ repositoryCount: number
+ starterPrompts: readonly string[]
+ stepIndex: number
+ viewedStepKeys: Record<string, true>
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface aiOnboardingLogicActions {
+ setSeed: (seed: ComposerSeed) => {
+ seed: ComposerSeed
+ } // composerSeedLogic
+ updateUser: (
+ user: Partial<UserType>,
+ successCallback?: (() => void) | undefined
+ ) => {
+ successCallback: (() => void) | undefined
+ user: Partial<UserType>
+ } // userLogic
+ clickGithubCta: () => {
+ value: true
+ }
+ closeOnboarding: () => {
+ value: true
+ }
+ finishOnboarding: () => {
+ value: true
+ }
+ markOnboardingSeen: () => {
+ value: true
+ }
+ markStepViewed: (stepKey: string) => {
+ stepKey: string
+ }
+ openOnboarding: (isReplay?: boolean) => {
+ isReplay: boolean
+ }
+ replayMedia: () => {
+ value: true
+ }
+ selectStarterPrompt: (prompt: string) => {
+ prompt: string
+ }
+ setStepIndex: (stepIndex: number) => {
+ stepIndex: number
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface aiOnboardingLogicMeta {
+ key: string
+ __keaTypeGenInternalSelectorTypes: {
+ currentStep: (stepIndex: number) => OnboardingStep | null
+ hasSeenOnboarding: (user: UserType | null) => boolean
+ projectHasData: (currentTeam: TeamPublicType | TeamType | null) => boolean
+ starterPrompts: (projectHasData: boolean) => readonly string[]
+ githubConnected: (githubIntegrations: IntegrationType[]) => boolean
+ repositoryCount: (githubIntegrations: IntegrationType[]) => number
+ reportProperties: (
+ currentStep: OnboardingStep | null,
+ stepIndex: number,
+ isReplay: boolean
+ ) => OnboardingReportProperties
+ }
+}
+
+export type aiOnboardingLogicType = MakeLogicType<
+ aiOnboardingLogicValues,
+ aiOnboardingLogicActions,
+ AiOnboardingLogicProps,
+ aiOnboardingLogicMeta
+>
+
+/**
+ * State and telemetry for the PostHog AI onboarding takeover: which step is showing, what a dismissal
+ * persists, and what a chosen starter prompt does. Deliberately host-agnostic — it does not know whether
+ * PostHog AI was opened on `/ai` or in the side panel, nor which runtime is active. The host decides when to
+ * mount it (see `MaybePhaiOnboarding` in `scenes/max`) and passes the composer's `panelId`.
+ *
+ * "Seen" is stored per user on the server rather than per device, so the takeover shows exactly once no
+ * matter where the user signs in. The replay button re-opens it without clearing that flag.
+ */
+export const aiOnboardingLogic = kea<aiOnboardingLogicType>([
+ path(['products', 'posthog_ai', 'frontend', 'logics', 'aiOnboardingLogic']),
+ props({} as AiOnboardingLogicProps),
+ key((props) => props.panelId ?? 'scene'),
+
+ connect((props: AiOnboardingLogicProps) => ({
+ values: [
+ userLogic,
+ ['user'],
+ teamLogic,
+ ['currentTeam'],
+ integrationsLogic,
+ ['githubIntegrations', 'integrationsLoading'],
+ aiConsentLogic,
+ ['dataProcessingAccepted'],
+ ],
+ actions: [userLogic, ['updateUser'], composerSeedLogic({ panelId: props.panelId }), ['setSeed']],
+ })),
+
+ actions({
+ openOnboarding: (isReplay: boolean = false) => ({ isReplay }),
+ closeOnboarding: true,
+ finishOnboarding: true,
+ setStepIndex: (stepIndex: number) => ({ stepIndex }),
+ markStepViewed: (stepKey: string) => ({ stepKey }),
+ selectStarterPrompt: (prompt: string) => ({ prompt }),
+ clickGithubCta: true,
+ replayMedia: true,
+ markOnboardingSeen: true,
+ }),
+
+ reducers({
+ isOpen: [
+ false,
+ {
+ openOnboarding: () => true,
+ closeOnboarding: () => false,
+ finishOnboarding: () => false,
+ selectStarterPrompt: () => false,
+ },
+ ],
+ isReplay: [
+ false,
+ {
+ openOnboarding: (_, { isReplay }) => isReplay,
+ },
+ ],
+ stepIndex: [
+ 0,
+ {
+ openOnboarding: () => 0,
+ setStepIndex: (_, { stepIndex }) => stepIndex,
+ },
+ ],
+ // Fire-once guard so re-entering a step (via Back, or the dot row) doesn't re-report it.
+ viewedStepKeys: [
+ {} as Record<string, true>,
+ {
+ openOnboarding: () => ({}),
+ markStepViewed: (state, { stepKey }) => ({ ...state, [stepKey]: true }),
+ },
+ ],
+ }),
+
+ selectors({
+ currentStep: [
+ (s) => [s.stepIndex],
+ (stepIndex: number): OnboardingStep | null => DEFAULT_ONBOARDING_STEPS[stepIndex] ?? null,
+ ],
+ hasSeenOnboarding: [
+ (s) => [s.user],
+ (user: UserType | null): boolean => !!user?.has_seen_product_intro_for?.[POSTHOG_AI_ONBOARDING_SEEN_KEY],
+ ],
+ // `TeamPublicType` has no `ingested_event`, so read it defensively rather than casting.
+ projectHasData: [
+ (s) => [s.currentTeam],
+ (currentTeam: TeamPublicType | TeamType | null): boolean =>
+ !!currentTeam && 'ingested_event' in currentTeam && !!currentTeam.ingested_event,
+ ],
+ starterPrompts: [
+ (s) => [s.projectHasData],
+ (projectHasData: boolean): readonly string[] =>
+ projectHasData ? DEFAULT_STARTER_PROMPTS : EMPTY_PROJECT_STARTER_PROMPTS,
+ ],
+ githubConnected: [
+ (s) => [s.githubIntegrations],
+ (githubIntegrations: IntegrationType[]): boolean => githubIntegrations.length > 0,
+ ],
+ repositoryCount: [
+ (s) => [s.githubIntegrations],
+ (githubIntegrations: IntegrationType[]): number => githubIntegrations.length,
+ ],
+ reportProperties: [
+ (s) => [s.currentStep, s.stepIndex, s.isReplay],
+ (currentStep: OnboardingStep | null, stepIndex: number, isReplay: boolean): OnboardingReportProperties => ({
+ step_key: currentStep?.key ?? 'unknown',
+ step_index: stepIndex,
+ step_count: DEFAULT_ONBOARDING_STEPS.length,
+ is_replay: isReplay,
+ }),
+ ],
+ }),
+
+ listeners(({ actions, values }) => ({
+ openOnboarding: () => {
+ posthog.capture('posthog ai onboarding shown', values.reportProperties)
+ if (values.currentStep) {
+ actions.markStepViewed(values.currentStep.key)
+ }
+ },
+ setStepIndex: () => {
+ const step = values.currentStep
+ if (!step || values.viewedStepKeys[step.key]) {
+ return
+ }
+ actions.markStepViewed(step.key)
+ posthog.capture('posthog ai onboarding step viewed', values.reportProperties)
+ },
+ closeOnboarding: () => {
+ // Which step a user bails on is the segment signal the onboarding research relies on, so the
+ // skip event carries the step it happened on rather than only reporting that a dismissal occurred.
+ posthog.capture('posthog ai onboarding step skipped', values.reportProperties)
+ posthog.capture('posthog ai onboarding dismissed', values.reportProperties)
+ actions.markOnboardingSeen()
+ },
+ finishOnboarding: () => {
+ posthog.capture('posthog ai onboarding completed', values.reportProperties)
+ actions.markOnboardingSeen()
+ },
+ selectStarterPrompt: ({ prompt }) => {
+ posthog.capture('posthog ai onboarding starter prompt clicked', {
+ ...values.reportProperties,
+ prompt,
+ })
+ // Same org-level AI data-processing gate the other seed producers use: without approval the
+ // prompt only prefills, so the consent popover never fires on top of the onboarding. The user's
+ // own send then goes through the composer's normal consent flow.
+ actions.setSeed({ prompt, autoSubmit: values.dataProcessingAccepted })
+ actions.markOnboardingSeen()
+ },
+ clickGithubCta: () => {
+ posthog.capture('posthog ai onboarding github cta clicked', {
+ ...values.reportProperties,
+ github_connected: values.githubConnected,
+ })
+ },
+ replayMedia: () => {
+ posthog.capture('posthog ai onboarding media replayed', values.reportProperties)
+ },
+ markOnboardingSeen: () => {
+ if (values.hasSeenOnboarding) {
+ return
+ }
+ actions.updateUser({
+ has_seen_product_intro_for: {
+ ...values.user?.has_seen_product_intro_for,
+ [POSTHOG_AI_ONBOARDING_SEEN_KEY]: true,
+ },
+ })
+ },
+ })),
+])
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx
index 465fb70c3496..f7c7aa30acb4 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx
@@ -1,4 +1,4 @@
-import { useActions, useValues } from 'kea'
+import { useActions, useMountedLogic, useValues } from 'kea'
import { router } from 'kea-router'
import { useRef } from 'react'
@@ -24,6 +24,7 @@ import { ComposerModelEffortPickers } from '../../../components/composer/Compose
import { ComposerModePicker } from '../../../components/composer/ComposerModePicker'
import { ComposerModeShortcut } from '../../../components/composer/ComposerModeShortcut'
import { useDebouncedDraft } from '../../../components/composer/useDebouncedDraft'
+import { OnboardingReplayButton } from '../../../components/onboarding/OnboardingReplayButton'
import { taskTrackerSceneLogic } from '../taskTrackerSceneLogic'
import { RepositorySelector } from './RepositorySelector'
@@ -36,6 +37,10 @@ export function TaskComposer(): JSX.Element {
// Permission modes belong to the harness, so they follow the picked model.
const composerAdapter = getRuntimeAdapterForModel(catalogue, newTaskData.model)
+ // The bound instance's key — 'scene' on `/ai` and `/tasks`, the panel key when embedded. The onboarding
+ // takeover is keyed the same way, so a starter prompt chosen on replay reaches this composer.
+ const panelId = useMountedLogic(taskTrackerSceneLogic).props.panelId
+
// Buffer the description locally and debounce the write to kea so each keystroke is a cheap, isolated
// re-render instead of a store dispatch. `Composer.Root` already blocks send on an empty `draft.value`
// internally, so there's no need to pass a `disabledReason` derived from the logic's debounced value.
@@ -53,7 +58,11 @@ export function TaskComposer(): JSX.Element {
return (
<div className="flex flex-col h-full min-h-0 items-center justify-center overflow-y-auto p-4">
<div className="w-full max-w-2xl flex flex-col items-center gap-4">
- <Welcome headline={displayHeadline} />
+ <Welcome headline={displayHeadline}>
+ {/* Temporary migration affordance — delete with the rest of the onboarding takeover
+ once everyone is on the new PostHog AI. */}
+ <OnboardingReplayButton panelId={panelId} />
+ </Welcome>
<Suggestions.Root
activeGroup={activeSuggestionGroup}