Skip to content

feat(self-driving): integrate first when the project has no PostHog - #760

Merged
sortafreel merged 3 commits into
mainfrom
vincent/wizard-self-driving-handoff
Jun 30, 2026
Merged

sortafreel merged 3 commits into
mainfrom
vincent/wizard-self-driving-handoff

Conversation

@gewenyu99

@gewenyu99 gewenyu99 commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Self-driving assumed the project already had a PostHog SDK. A project without one had nowhere to start — no events, no signals, nothing to drive.

Changes

When PostHog isn't found, the wizard sets it up first, then hands off to Self-driving:

intro → "No PostHog found" → auth → detect-and-pick → integration → handoff → Self-driving

  • Deterministic presence check picks the branch. Found → straight to Self-driving, no note. Not found → integrate first.
  • Agentic detect-and-pick screen after auth, mirroring source-maps: a Haiku agent scans the repo and the user picks which project to set PostHog up in. A monorepo can have several; a single project is still a one-item confirm. A detection failure falls back to the manual framework picker.
  • Integration runs scoped to the picked project — for a monorepo, the chosen sub-app rather than the repo root.
  • Handoff screen bridges to Self-driving ("PostHog is installed — now set up Self-driving"), with the integration report path.
  • One login. The integration and Self-driving phases reuse the credentials from the first auth instead of launching a second OAuth, which re-prompted and failed with a 400.
  • The in-program run-phase loop is one shared, id-agnostic helper (runInProgramPhases), used by both the runner and the snapshot harness.

Test plan

  • Manual run against a single-file Express app and a turborepo monorepo: detect → pick → integration → handoff → Self-driving.
  • pnpm test — offline flow-trace, router, step, and screen tests.
Screens Integration check Detect and pick Handoff

Self-driving needs interactive browser steps (the GitHub App install, issue-tracker OAuth), so it can't run to completion in the headless snapshot harness — hence the manual screens above rather than captured snapshots.

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci error-tracking-upload-source-maps
  • /wizard-ci mcp-analytics
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci error-tracking-upload-source-maps/android
  • /wizard-ci error-tracking-upload-source-maps/cicd-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-nested-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-single-stage-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-gitlab-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-monorepo-pnpm-node-react
  • /wizard-ci error-tracking-upload-source-maps/cicd-monorepo-raw-node-react
  • /wizard-ci error-tracking-upload-source-maps/cicd-ssh-vps-node-raw
  • /wizard-ci error-tracking-upload-source-maps/flutter
  • /wizard-ci error-tracking-upload-source-maps/ios
  • /wizard-ci error-tracking-upload-source-maps/next
  • /wizard-ci error-tracking-upload-source-maps/next-no-posthog
  • /wizard-ci error-tracking-upload-source-maps/node-raw
  • /wizard-ci error-tracking-upload-source-maps/node-rollup
  • /wizard-ci error-tracking-upload-source-maps/node-rollup-typescript-plugin
  • /wizard-ci error-tracking-upload-source-maps/node-webpack
  • /wizard-ci error-tracking-upload-source-maps/nuxt-3-6
  • /wizard-ci error-tracking-upload-source-maps/nuxt-4-3
  • /wizard-ci error-tracking-upload-source-maps/react-native
  • /wizard-ci error-tracking-upload-source-maps/react-vite
  • /wizard-ci error-tracking-upload-source-maps/rust
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

gewenyu99 commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

@gewenyu99
gewenyu99 force-pushed the vincent/wizard-self-driving-handoff branch 2 times, most recently from d881b04 to c13117a Compare June 29, 2026 18:11
@gewenyu99 gewenyu99 changed the title feat(self-driving): continue into self-driving from the base wizard feat(self-driving): integrate first when the project has no PostHog Jun 29, 2026
@gewenyu99
gewenyu99 force-pushed the vincent/wizard-self-driving-handoff branch from a259d79 to 0d5a549 Compare June 29, 2026 23:25
@gewenyu99
gewenyu99 force-pushed the vincent/wizard-self-driving-handoff branch 3 times, most recently from adb713c to 48dccdb Compare June 30, 2026 01:37
@gewenyu99
gewenyu99 marked this pull request as ready for review June 30, 2026 01:53
@gewenyu99
gewenyu99 requested review from a team and sortafreel June 30, 2026 01:53
@gewenyu99
gewenyu99 force-pushed the vincent/wizard-self-driving-handoff branch from 48dccdb to 3967468 Compare June 30, 2026 02:15
When the project has no PostHog, self-driving sets it up first, then runs
Self-driving — composed as steps in one program:

- After auth, the detect screen scans the repo and the user picks which
  project to set PostHog up in (a monorepo can have several).
- posthog-integration exports a self-contained run step; self-driving imports
  it and runs it in the picked project's dir, then a handoff screen, then its
  own run step.
- The runner walks the step list and runs each run step's own agent. One login:
  the bootstrap calls an idempotent authenticate() the second run reuses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gewenyu99
gewenyu99 force-pushed the vincent/wizard-self-driving-handoff branch from 3967468 to e8f3054 Compare June 30, 2026 02:37

@sortafreel sortafreel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, kudos! Added a couple of concerns, approving on a trust-me-bro basis :)

Comment thread src/commands/self-driving.ts Resolved
Comment thread src/lib/programs/self-driving/detect.ts Resolved
@sortafreel
sortafreel enabled auto-merge (squash) June 30, 2026 13:30
@sortafreel
sortafreel merged commit 3049d9c into main Jun 30, 2026
18 checks passed
@sortafreel
sortafreel deleted the vincent/wizard-self-driving-handoff branch June 30, 2026 13:31
rafaeelaudibert added a commit that referenced this pull request Jul 14, 2026
## What

Builds on the [#760](#760) self-driving "integrate first" flow. When self-driving falls back to **"no PostHog found"**, we now ask the user whether they already have a PostHog account, and route auth accordingly — instead of always assuming OAuth.

The merged integration-check screen now offers two answers (both still integrate the SDK first):

- **Yes — log me in** → authenticate via OAuth (unchanged default).
- **No — create one for me** → collect **email** + **cloud region**, flip `session.signup`, and let `authenticate()` take the **existing provisioning path** (`askForProvisioningSignup` → `provisionNewAccount`: create the account, email a login link). No `--signup` / `--email` flags needed — it's all interactive now.

## Why

A project with no PostHog SDK is often a project whose owner has no PostHog account yet. Previously that user hit OAuth and had to go create an account out-of-band first. Now the wizard provisions one for them in place.

## Notable detail — AI opt-in gate

A provisioning access token deliberately omits the `organization:read` scope (`WIZARD_PROVISIONING_SCOPES`), so `apiUser` stays `null` and `organization.is_ai_data_processing_approved` can never be read back. The AI opt-in gate (`session.ci || aiApproved`) would therefore **never clear** for a provisioned account and the run would hang. This treats `signup` as auto-consent alongside `ci` (they're already grouped as one non-interactive mode in `shouldDisableAsk`) — which also fixes the same latent hang in the base `wizard --signup` flow.

## Changes

- `SelfDrivingIntegrationCheckScreen.tsx` — rewritten to a 3-stage screen: ask → email input → region picker.
- `store.ts` — `chooseProvisionAccount(email, region)` sets `signup`/`email`/`region`/`integrate` in one atomic emit.
- `ai-opt-in-gate.ts` — `signup` auto-consents like `ci`.
- `self-driving.ts` — refreshed `--integrate` help text and the `--signup`-rejection message (points users at the interactive flow).
- `wizard-session.ts` — corrected the stale `integrate` doc comment.
- Tests in `store.test.ts` and `programs.test.ts`.

## Testing

`pnpm build` ✅ · `pnpm lint` ✅ (0 errors) · targeted unit tests ✅. The only failing tests in the full suite are 3 pre-existing `provision-cli.test.ts` failures present on `main` before this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants