@posthog/wizard 2.23.0 → 2.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +61 -2
  2. package/dist/{AiOptInRequiredScreen-BOMyYFep.js → AiOptInRequiredScreen-_33FOcVo.js} +148 -685
  3. package/dist/AiOptInRequiredScreen-_33FOcVo.js.map +1 -0
  4. package/dist/{add-mcp-server-to-clients-BEziI3z9.js → add-mcp-server-to-clients-CfwEQT_z.js} +4 -4
  5. package/dist/{add-mcp-server-to-clients-BEziI3z9.js.map → add-mcp-server-to-clients-CfwEQT_z.js.map} +1 -1
  6. package/dist/{agent-interface-DjMPlXl0.js → agent-interface-D1vtN6Wn.js} +6 -7
  7. package/dist/agent-interface-D1vtN6Wn.js.map +1 -0
  8. package/dist/{agent-runner-Bv-7z-pQ.js → agent-runner-CBbkS0Ro.js} +8 -8
  9. package/dist/{agent-runner-Bv-7z-pQ.js.map → agent-runner-CBbkS0Ro.js.map} +1 -1
  10. package/dist/{analytics-9D4eGgmT.js → analytics-CUr82BDl.js} +11 -2
  11. package/dist/{analytics-9D4eGgmT.js.map → analytics-CUr82BDl.js.map} +1 -1
  12. package/dist/{api-Dwd0B-E9.js → api-CI3Z74NG.js} +3 -3
  13. package/dist/{api-Dwd0B-E9.js.map → api-CI3Z74NG.js.map} +1 -1
  14. package/dist/bin.js +887 -465
  15. package/dist/bin.js.map +1 -1
  16. package/dist/{ci-install-DGXCpvKh.js → ci-install-D_kxNmbJ.js} +5 -5
  17. package/dist/{ci-install-DGXCpvKh.js.map → ci-install-D_kxNmbJ.js.map} +1 -1
  18. package/dist/{debug-CgT5MmVB.js → debug-DxA_f5QT.js} +2 -2
  19. package/dist/{debug-CgT5MmVB.js.map → debug-DxA_f5QT.js.map} +1 -1
  20. package/dist/{debug-DayHBBST.js → debug-zMvpNYb2.js} +1 -1
  21. package/dist/{environment-CI2pTYTG.js → environment-CyS37cmM.js} +3 -3
  22. package/dist/{environment-CI2pTYTG.js.map → environment-CyS37cmM.js.map} +1 -1
  23. package/dist/{interactive-D52p_opJ.js → interactive-CG6FFqSw.js} +3 -3
  24. package/dist/{interactive-D52p_opJ.js.map → interactive-CG6FFqSw.js.map} +1 -1
  25. package/dist/{mcp-prompt-streaming-tdoy9UJ2.js → mcp-prompt-streaming-DQz4FSb1.js} +4 -4
  26. package/dist/{mcp-prompt-streaming-tdoy9UJ2.js.map → mcp-prompt-streaming-DQz4FSb1.js.map} +1 -1
  27. package/dist/{non-interactive-6hadW20x.js → non-interactive-DWtHX3ZR.js} +2 -2
  28. package/dist/{non-interactive-6hadW20x.js.map → non-interactive-DWtHX3ZR.js.map} +1 -1
  29. package/dist/{package-manager-BI0J5E7t.js → package-manager-BWUS4CP0.js} +2 -2
  30. package/dist/{package-manager-BI0J5E7t.js.map → package-manager-BWUS4CP0.js.map} +1 -1
  31. package/dist/{playground-z4A5dHPv.js → playground-D7AhMMF5.js} +9 -20
  32. package/dist/playground-D7AhMMF5.js.map +1 -0
  33. package/dist/{posthog-integration-BWbZU9Xq.js → posthog-integration-DexZ2uHU.js} +18 -18
  34. package/dist/{posthog-integration-BWbZU9Xq.js.map → posthog-integration-DexZ2uHU.js.map} +1 -1
  35. package/dist/{provisioning-B30Be2NA.js → provisioning-9c-AQbsa.js} +3 -3
  36. package/dist/{provisioning-B30Be2NA.js.map → provisioning-9c-AQbsa.js.map} +1 -1
  37. package/dist/{registry-CD_DplSQ.js → registry-CO7JVZyE.js} +4 -4
  38. package/dist/{registry-CD_DplSQ.js.map → registry-CO7JVZyE.js.map} +1 -1
  39. package/dist/{setup-utils-Dwgkk8AQ.js → setup-utils-0U-_Md2G.js} +8 -8
  40. package/dist/{setup-utils-Dwgkk8AQ.js.map → setup-utils-0U-_Md2G.js.map} +1 -1
  41. package/dist/{start-tui-SLeEzlJs.js → start-tui-WNb3ET14.js} +206 -1205
  42. package/dist/start-tui-WNb3ET14.js.map +1 -0
  43. package/dist/{steps-B1gzyRkC.js → steps-BAUXDCC4.js} +6 -6
  44. package/dist/{steps-B1gzyRkC.js.map → steps-BAUXDCC4.js.map} +1 -1
  45. package/dist/{telemetry-5rkeTd2_.js → telemetry-ycqCpNPr.js} +3 -3
  46. package/dist/{telemetry-5rkeTd2_.js.map → telemetry-ycqCpNPr.js.map} +1 -1
  47. package/dist/{urls-Cb4SI9kf.js → urls-C8aJWvgh.js} +2 -2
  48. package/dist/{urls-Cb4SI9kf.js.map → urls-C8aJWvgh.js.map} +1 -1
  49. package/dist/{wizard-abort-DovHQa-j.js → wizard-abort-C6gRLxUE.js} +3 -3
  50. package/dist/{wizard-abort-DovHQa-j.js.map → wizard-abort-C6gRLxUE.js.map} +1 -1
  51. package/dist/{wizard-abort-DW2-ZjiS.js → wizard-abort-DWXyJdws.js} +1 -1
  52. package/package.json +1 -1
  53. package/dist/AiOptInRequiredScreen-BOMyYFep.js.map +0 -1
  54. package/dist/agent-interface-DjMPlXl0.js.map +0 -1
  55. package/dist/playground-z4A5dHPv.js.map +0 -1
  56. package/dist/start-tui-SLeEzlJs.js.map +0 -1
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","names":["POSTHOG_SDKS","getContentBlocks","baseConfig","DOCS_URL","REPORT_FILE","DOCS_URL","getContentBlocks","agentSkillContentBlocks"],"sources":["../src/commands/command.ts","../src/wizard.ts","../src/commands/provision.ts","../src/commands/basic-integration/index.ts","../src/lib/programs/shared/package-scanning.ts","../src/lib/programs/revenue-analytics/detect.ts","../src/lib/programs/revenue-analytics/steps.ts","../src/lib/programs/agent-skill/content/index.tsx","../src/lib/programs/revenue-analytics/index.ts","../src/lib/programs/agent-skill/steps.ts","../src/lib/programs/agent-skill/index.ts","../src/lib/programs/audit/detect.ts","../src/lib/programs/audit/seed.ts","../src/lib/programs/audit/index.ts","../src/lib/programs/events-audit/steps.ts","../src/lib/programs/events-audit/seed.ts","../src/lib/programs/events-audit/index.ts","../src/lib/programs/audit-3000/index.ts","../src/lib/programs/posthog-doctor/steps.ts","../src/lib/programs/posthog-doctor/types.ts","../src/lib/programs/posthog-doctor/fetch.ts","../src/lib/programs/posthog-doctor/kind-metadata.ts","../src/lib/programs/posthog-doctor/index.ts","../src/lib/programs/web-analytics-doctor/detect.ts","../src/lib/programs/web-analytics-doctor/steps.ts","../src/lib/programs/web-analytics-doctor/index.ts","../src/lib/programs/migration/steps.ts","../src/lib/programs/migration/content/vendor-stack.tsx","../src/lib/programs/migration/content/free-tier.tsx","../src/lib/programs/migration/content/pricing-structure.tsx","../src/lib/programs/migration/content/index.tsx","../src/lib/programs/migration/index.ts","../src/lib/programs/error-tracking-upload-source-maps/detect.ts","../src/lib/programs/error-tracking-upload-source-maps/steps.ts","../src/lib/programs/error-tracking-upload-source-maps/prompt.ts","../src/lib/programs/error-tracking-upload-source-maps/content/index.tsx","../src/lib/programs/error-tracking-upload-source-maps/index.ts","../src/lib/programs/mcp/index.ts","../src/lib/programs/slack/index.ts","../src/lib/programs/program-registry.ts","../src/commands/mcp/add.ts","../src/commands/mcp/remove.ts","../src/commands/mcp/tutorial.ts","../src/commands/mcp/index.ts","../src/lib/runners/resolve-no-telemetry.ts","../src/lib/runners/run-wizard.ts","../src/lib/runners/run-wizard-ci.ts","../src/commands/skill-program-options.ts","../src/commands/integrate.ts","../src/commands/audit.ts","../src/commands/audit-3000.ts","../src/commands/doctor.ts","../src/commands/migrate.ts","../src/commands/events-audit.ts","../src/commands/revenue.ts","../src/commands/slack.ts","../src/commands/upload-sourcemaps.ts","../src/commands/basic-integration/skill.ts","../src/commands/skill.ts","../bin.ts"],"sourcesContent":["import type { Arguments, Argv, CommandModule, Options } from 'yargs';\nimport { setEntryCommand } from '@utils/links';\n\nexport interface Command {\n /** Yargs command name. Use `['$0']` for the default command. */\n name: string | readonly string[];\n description: string;\n /** Flags exposed by this command. Same shape as yargs `.options()`. */\n options?: Record<string, Options>;\n /** Nested subcommands. */\n children?: readonly Command[];\n /** `--help` examples shown for this command. */\n examples?: ReadonlyArray<readonly [string, string]>;\n /**\n * Called synchronously by yargs when the command matches. Wrap async work in\n * `void (async () => { ... })()`. Optional only when `children` is set — in\n * that case yargs requires the user to pick a subcommand.\n */\n handler?: (argv: Arguments) => void;\n /**\n * Cross-flag validation run by yargs after parsing. Throw to reject (yargs\n * prints the message and exits non-zero); return `true` to accept. Prefer\n * this over per-option `conflicts` for mutually exclusive flags: yargs\n * counts a `default`-valued flag as \"present\", so `conflicts` misfires on\n * boolean flags that default to `false` — a hand-written predicate only\n * sees what you test for (e.g. truthiness).\n */\n check?: (argv: Arguments) => boolean;\n}\n\n/** Extract the bare command word(s) from a yargs name spec, dropping positionals and aliases' arg syntax. */\nexport function commandKeys(name: string | readonly string[]): string[] {\n const list: readonly string[] = typeof name === 'string' ? [name] : name;\n return list.map((n) => n.trim().split(/\\s+/)[0]);\n}\n\nexport function toCommandModule(\n cmd: Command,\n parentPath: readonly string[],\n): CommandModule {\n // `wizard slack` → 'slack', `wizard mcp add` → 'mcp-add'. The default\n // `$0` resolves to '' and is skipped — its handler reports itself.\n const entryCommand = [...parentPath, commandKeys(cmd.name)[0]]\n .filter((key) => key !== '$0')\n .join('-');\n return {\n command: cmd.name,\n describe: cmd.description,\n builder: (y: Argv) => {\n let next = cmd.options ? y.options(cmd.options) : y;\n if (cmd.check) next = next.check(cmd.check);\n for (const [usage, description] of cmd.examples ?? []) {\n next = next.example(usage, description);\n }\n const ownPath = [...parentPath, commandKeys(cmd.name)[0]];\n for (const child of cmd.children ?? []) {\n next = next.command(toCommandModule(child, ownPath));\n }\n if (cmd.children?.length && !cmd.handler) {\n next = next.demandCommand(1);\n }\n return next;\n },\n handler: (argv: Arguments) => {\n if (entryCommand) setEntryCommand(entryCommand);\n cmd.handler?.(argv);\n },\n };\n}\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\nimport type { Argv } from 'yargs';\nimport { IS_PRODUCTION_BUILD } from '@env';\nimport { toCommandModule, type Command } from './commands/command';\n\n/**\n * Global yargs options applied to every command. These are read from the\n * `POSTHOG_WIZARD` env prefix as well as flags.\n */\nexport const GLOBAL_OPTIONS = {\n debug: {\n default: false,\n describe: 'Enable verbose logging\\nenv: POSTHOG_WIZARD_DEBUG',\n type: 'boolean' as const,\n },\n region: {\n describe: 'PostHog cloud region\\nenv: POSTHOG_WIZARD_REGION',\n choices: ['us', 'eu'] as const,\n type: 'string' as const,\n },\n signup: {\n default: false,\n describe:\n 'Create a new PostHog account during setup\\nenv: POSTHOG_WIZARD_SIGNUP',\n type: 'boolean' as const,\n },\n 'local-mcp': {\n default: false,\n describe:\n 'Use local MCP server at http://localhost:8787/mcp\\nenv: POSTHOG_WIZARD_LOCAL_MCP',\n type: 'boolean' as const,\n },\n telemetry: {\n default: true,\n describe:\n 'Send wizard run state to PostHog (pass --no-telemetry to disable)\\nenv: POSTHOG_WIZARD_TELEMETRY',\n type: 'boolean' as const,\n },\n 'api-key': {\n describe:\n 'PostHog personal API key (phx_xxx) for authentication\\nenv: POSTHOG_WIZARD_API_KEY',\n type: 'string' as const,\n },\n 'project-id': {\n describe:\n 'PostHog project ID to use (optional; when not set, uses default from API key or OAuth)\\nenv: POSTHOG_WIZARD_PROJECT_ID',\n type: 'string' as const,\n },\n email: {\n describe:\n 'Email address for signup (used with --signup)\\nenv: POSTHOG_WIZARD_EMAIL',\n type: 'string' as const,\n },\n};\n\nexport class Wizard {\n private cli: Argv;\n\n private constructor() {\n let cli = yargs(hideBin(process.argv))\n .env('POSTHOG_WIZARD')\n .options(GLOBAL_OPTIONS);\n\n // CI mode (--ci) is only supported in dev/test. It is left undeclared in\n // published builds (NODE_ENV==='production'), so .strictOptions() rejects\n // it there as an unknown argument — exactly like any other unrecognized\n // flag. init() additionally detects it up front to print a clearer message.\n if (!IS_PRODUCTION_BUILD) {\n cli = cli.option('ci', {\n default: false,\n describe:\n 'Enable CI mode for non-interactive execution\\nenv: POSTHOG_WIZARD_CI',\n type: 'boolean',\n });\n }\n\n this.cli = cli\n .strictOptions()\n // Print the error first (bright red) and the usage below it, instead of\n // yargs' default of burying the message under the full help output.\n .fail((msg, err, parser) => {\n const text = msg || (err && err.message) || 'Invalid arguments';\n process.stderr.write(`\\n\\x1b[1;91m✖ ${text}\\x1b[0m\\n\\n`);\n parser.showHelp();\n process.exit(1);\n })\n .help()\n .alias('help', 'h')\n .version()\n .alias('version', 'v');\n }\n\n /** Start a chain; equivalent to `new Wizard().use(...cmds)`. */\n static use(...cmds: Command[]): Wizard {\n return new Wizard().use(...cmds);\n }\n\n /** Register one or more commands with yargs. */\n use(...cmds: Command[]): this {\n for (const cmd of cmds) {\n this.cli = this.cli.command(toCommandModule(cmd, []));\n }\n return this;\n }\n\n /** Parse argv and dispatch to the matching registered command. */\n init(): void {\n // In published builds, `--ci` is undeclared, so yargs would reject it as\n // an unknown argument — accurate but unhelpful, since --help doesn't list\n // --ci either and the user has no path forward. POSTHOG_WIZARD_CI silently\n // no-ops for the same reason (yargs only resolves env vars for declared\n // options). Detect both up front and exit with a message that explains why.\n if (IS_PRODUCTION_BUILD) {\n const args = process.argv.slice(2);\n const argvHasCI = args.some(\n (a) => a === '--ci' || a === '--no-ci' || a.startsWith('--ci='),\n );\n const envHasCI =\n process.env.POSTHOG_WIZARD_CI != null &&\n process.env.POSTHOG_WIZARD_CI !== '';\n if (argvHasCI || envHasCI) {\n process.stderr.write(\n `\\n\\x1b[1;91m✖ CI mode is not currently supported in published builds.\\x1b[0m\\n\\n`,\n );\n process.exit(1);\n }\n }\n void this.cli.wrap(process.stdout.isTTY ? this.cli.terminalWidth() : 80)\n .argv;\n }\n}\n","import type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport type { ProvisioningResult } from '@utils/provisioning';\nimport type { Command } from './command';\n\nexport const provisionCommand: Command = {\n name: 'provision',\n description: 'Create a new PostHog account (headless, no TUI)',\n options: {\n email: {\n describe: 'Email address for the new account',\n type: 'string',\n demandOption: true,\n },\n region: {\n describe: 'Cloud region (us or eu)',\n choices: ['us', 'eu'] as const,\n default: 'us',\n },\n name: {\n describe: 'Name for the new account',\n type: 'string',\n default: '',\n },\n json: {\n describe:\n 'Emit JSON result to stdout (defaults to true when stdout is not a TTY)',\n type: 'boolean',\n },\n },\n examples: [\n ['wizard provision --email matt+test@posthog.com --region us', ''],\n ['wizard provision --email user@example.com --region eu --json', ''],\n ],\n handler: runProvision,\n};\n\nfunction runProvision(argv: Arguments): void {\n const jsonMode =\n argv.json === undefined ? !process.stdout.isTTY : Boolean(argv.json);\n if (!jsonMode) setUI(new LoggingUI());\n\n void provision({\n email: argv.email as string,\n region: (argv.region as string).toUpperCase() as 'US' | 'EU',\n name: (argv.name as string) ?? '',\n jsonMode,\n });\n}\n\ntype ProvisionArgs = {\n email: string;\n region: 'US' | 'EU';\n name: string;\n jsonMode: boolean;\n};\n\nasync function provision({\n email,\n region,\n name,\n jsonMode,\n}: ProvisionArgs): Promise<void> {\n try {\n const { provisionNewAccount } = await import('@utils/provisioning');\n if (!jsonMode) {\n getUI().log.info(`Provisioning account for ${email} in ${region}...`);\n }\n const result = await provisionNewAccount(email, name, region);\n emitResult(result, jsonMode);\n process.exit(0);\n } catch (error) {\n emitError(error, jsonMode);\n process.exit(1);\n }\n}\n\nfunction emitResult(result: ProvisioningResult, jsonMode: boolean): void {\n if (jsonMode) {\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n return;\n }\n getUI().log.success('Account provisioned successfully:');\n getUI().log.info(` API Key: ${result.projectApiKey}`);\n getUI().log.info(` Host: ${result.host}`);\n getUI().log.info(` Project ID: ${result.projectId}`);\n getUI().log.info(` Account ID: ${result.accountId}`);\n getUI().log.info(` Access Token: ${result.accessToken}`);\n getUI().log.info(` Refresh Token: ${result.refreshToken}`);\n if (result.personalApiKey) {\n getUI().log.info(` Personal API Key: ${result.personalApiKey}`);\n }\n}\n\nfunction emitError(error: unknown, jsonMode: boolean): void {\n const msg = error instanceof Error ? error.message : String(error);\n const code = msg.includes('already associated')\n ? 'email_exists'\n : 'provisioning_failed';\n if (jsonMode) {\n process.stderr.write(`${JSON.stringify({ error: msg, code })}\\n`);\n return;\n }\n getUI().log.error(`Provisioning failed: ${msg}`);\n}\n","import { isNonInteractiveEnvironment } from '@utils/environment';\nimport { setEntryCommand } from '@utils/links';\nimport { provisionCommand } from '../provision';\nimport type { Command } from '../command';\n\nexport const basicIntegrationCommand: Command = {\n name: ['$0'],\n description: 'Run the PostHog setup wizard',\n // provision is a one-shot HTTP call tied to the base flow, not a wizard\n // program — it rides under the base command rather than as a peer.\n children: [provisionCommand],\n options: {\n 'install-dir': {\n describe:\n 'Directory to install PostHog in\\nenv: POSTHOG_WIZARD_INSTALL_DIR',\n type: 'string',\n },\n playground: {\n default: false,\n describe: 'Launch the TUI primitives playground',\n type: 'boolean',\n },\n benchmark: {\n default: false,\n describe:\n 'Run in benchmark mode with per-phase token tracking\\nenv: POSTHOG_WIZARD_BENCHMARK',\n type: 'boolean',\n },\n 'yara-report': {\n default: false,\n describe:\n 'Print YARA scanner summary after the agent run\\nenv: POSTHOG_WIZARD_YARA_REPORT',\n type: 'boolean',\n hidden: true,\n },\n name: {\n describe:\n 'Name for account creation with --ci --signup\\nenv: POSTHOG_WIZARD_NAME',\n type: 'string',\n },\n },\n check: (argv) => {\n // --playground is the standalone TUI demo; it can't combine with --ci.\n if (argv.playground && argv.ci) {\n throw new Error('--playground cannot be combined with --ci.');\n }\n return true;\n },\n handler: (argv) => {\n // The bare run is the integrate flow.\n setEntryCommand('integrate');\n // Each mode file is loaded only when its branch is taken, so a plain\n // `npx @posthog/wizard` never pulls in the CI or playground paths.\n void (async () => {\n if (argv.ci) {\n const { runCIInstall } = await import('./ci-install');\n return runCIInstall(argv);\n }\n if (isNonInteractiveEnvironment()) {\n const { failNonInteractive } = await import('./non-interactive');\n return failNonInteractive();\n }\n if (argv.playground) {\n const { runPlayground } = await import('./playground');\n return runPlayground();\n }\n const { runInteractive } = await import('./interactive');\n runInteractive(argv);\n })();\n },\n};\n","import type { Dirent } from 'fs';\nimport { readFileSync, readdirSync } from 'fs';\nimport { join, relative } from 'path';\nimport { IGNORED_DIRS } from '@utils/file-utils';\n\nexport const POSTHOG_SDKS = [\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n];\n\nexport const STRIPE_SDKS = [\n 'stripe',\n '@stripe/stripe-js',\n '@stripe/react-stripe-js',\n];\n\nexport interface PackageMatch {\n /** Path to the package.json relative to installDir */\n path: string;\n posthogSdks: string[];\n stripeSdks: string[];\n}\n\n/**\n * Recursively find all package.json files under installDir (max depth 3),\n * skipping common ignored directories. Returns matches with detected SDKs.\n */\nexport function findPackageJsons(\n installDir: string,\n maxDepth = 3,\n): PackageMatch[] {\n const matches: PackageMatch[] = [];\n\n function scan(dir: string, depth: number): void {\n if (depth > maxDepth) return;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.name !== '.') continue;\n if (IGNORED_DIRS.has(entry.name)) continue;\n\n const fullPath = join(dir, entry.name);\n\n if (entry.isFile() && entry.name === 'package.json') {\n try {\n const pkg = JSON.parse(readFileSync(fullPath, 'utf-8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const depNames = [\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ];\n const posthogSdks = depNames.filter((d) => POSTHOG_SDKS.includes(d));\n const stripeSdks = depNames.filter((d) => STRIPE_SDKS.includes(d));\n matches.push({\n path: relative(installDir, fullPath) || 'package.json',\n posthogSdks,\n stripeSdks,\n });\n } catch {\n // Skip malformed package.json\n }\n } else if (entry.isDirectory()) {\n scan(fullPath, depth + 1);\n }\n }\n }\n\n scan(installDir, 0);\n return matches;\n}\n","/**\n * Revenue analytics prerequisite detection.\n *\n * Scans the project for PostHog + Stripe SDKs and writes results\n * into frameworkContext for the intro screen to render.\n */\n\nimport { existsSync, statSync } from 'fs';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { findPackageJsons } from '@lib/programs/shared/package-scanning';\n\nexport {\n findPackageJsons,\n POSTHOG_SDKS,\n STRIPE_SDKS,\n type PackageMatch,\n} from '@lib/programs/shared/package-scanning';\n\n/**\n * Structured detection errors. The screen renders each kind into JSX\n * with proper formatting — keeps error data separate from presentation.\n */\nexport type RevenueDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-package-json' }\n | { kind: 'no-sdks'; scannedCount: number }\n | { kind: 'missing-posthog'; foundStripe: string[] }\n | { kind: 'missing-stripe'; foundPosthog: string[] };\n\n/** `[ABORT] <reason>` cases the revenue analytics skill can emit. */\nexport const REVENUE_ABORT_CASES: AbortCase[] = [\n {\n // Skill emits: [ABORT] Could not find a PostHog distinct_id\n match: /^could not find a posthog distinct_id$/i,\n message: 'Could not find a PostHog distinct_id',\n body:\n 'The agent could not find PostHog distinct_id usage in your codebase. ' +\n 'Your users must be identified in PostHog before they can be tagged in Stripe. ' +\n 'Please identify your users and try again.',\n docsUrl: 'https://posthog.com/docs/product-analytics/identify',\n },\n {\n // Skill emits: [ABORT] Could not find a Stripe integration\n match: /^could not find a stripe integration$/i,\n message: 'Could not find a Stripe integration',\n body:\n 'The Wizard could not find an existing Stripe customer, charge, ' +\n 'subscription, or other Stripe operations. Please run the Revenue ' +\n 'Analytics Wizard on a project with an existing Stripe integration.',\n docsUrl: 'https://posthog.com/docs/revenue-analytics',\n },\n];\n\n/**\n * Scan `session.installDir` for PostHog + Stripe SDKs. Writes detection\n * results into frameworkContext via the callback — either the detected\n * SDK lists (for the intro screen) or a `RevenueDetectError` on failure.\n *\n * The skill install happens later in the bootstrap runner, not here.\n */\nexport function detectRevenuePrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: RevenueDetectError) =>\n setFrameworkContext('detectError', error);\n\n const installDir = session.installDir;\n\n // Verify the install directory exists and is readable\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n // Find all package.json files (root + monorepo subpackages)\n const matches = findPackageJsons(installDir);\n\n if (matches.length === 0) {\n fail({ kind: 'no-package-json' });\n return;\n }\n\n // Aggregate detected SDKs across all package.json files\n const allPosthogSdks = new Set<string>();\n const allStripeSdks = new Set<string>();\n for (const match of matches) {\n for (const sdk of match.posthogSdks) allPosthogSdks.add(sdk);\n for (const sdk of match.stripeSdks) allStripeSdks.add(sdk);\n }\n\n const detectedPosthogSdks = [...allPosthogSdks];\n const detectedStripeSdks = [...allStripeSdks];\n\n if (detectedPosthogSdks.length === 0 && detectedStripeSdks.length === 0) {\n fail({ kind: 'no-sdks', scannedCount: matches.length });\n return;\n }\n\n if (detectedPosthogSdks.length === 0) {\n fail({ kind: 'missing-posthog', foundStripe: detectedStripeSdks });\n return;\n }\n\n if (detectedStripeSdks.length === 0) {\n fail({ kind: 'missing-stripe', foundPosthog: detectedPosthogSdks });\n return;\n }\n\n setFrameworkContext('detectedPosthogSdks', detectedPosthogSdks);\n setFrameworkContext('detectedStripeSdks', detectedStripeSdks);\n setFrameworkContext(\n 'detectedPackagePaths',\n matches\n .filter((m) => m.posthogSdks.length > 0 || m.stripeSdks.length > 0)\n .map((m) => m.path),\n );\n}\n","/**\n * Revenue analytics program step list.\n *\n * The detect step checks for PostHog + Stripe SDKs. The skill install\n * and agent run live in the program runner (see agent-runner.ts).\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\nimport { detectRevenuePrerequisites } from './detect.js';\n\nexport const REVENUE_ANALYTICS_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting prerequisites',\n // Headless step: no screen, no gate. onReady fires after bin.ts\n // assigns the session — the hook scans for PostHog + Stripe SDKs\n // and writes the results (or a detectError) to frameworkContext\n // for the intro screen to render.\n onReady: (ctx) =>\n detectRevenuePrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'revenue-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Revenue analytics',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","/**\n * Agent-skill learn-deck — the short three-line sequence shown while a\n * skill-based program (audit, revenue-analytics, agent-skill, etc.)\n * runs. Skill programs don't need the full PostHog onboarding narrative.\n */\n\nimport { Text } from 'ink';\nimport type { WizardStore } from '@ui/tui/store';\nimport { TextRevealMode } from '@ui/tui/primitives/TextBlock';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] => {\n const skillId = store?.session.skillId ?? 'unknown';\n return [\n {\n content: 'Welcome.',\n pause: 3000,\n mode: TextRevealMode.Typewriter,\n animationInterval: 160,\n },\n { content: 'The Wizard is an agent.', pause: 4000 },\n {\n pause: 60000,\n content: (\n <Text>\n Running the <Text color=\"cyan\">{skillId}</Text> skill...\n </Text>\n ),\n },\n ];\n};\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { REVENUE_ANALYTICS_PROGRAM } from './steps.js';\nimport { REVENUE_ABORT_CASES } from './detect.js';\nimport { getContentBlocks } from './content/index.js';\n\nexport const revenueAnalyticsConfig: ProgramConfig = {\n command: 'revenue',\n description: 'Set up PostHog revenue analytics (e.g. Stripe integration)',\n id: 'revenue-analytics-setup',\n steps: REVENUE_ANALYTICS_PROGRAM,\n getContentBlocks,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n run: {\n skillId: 'revenue-analytics-setup',\n integrationLabel: 'revenue-analytics-setup',\n customPrompt: () => 'Set up revenue analytics for this project.',\n successMessage: 'Revenue analytics configured!',\n reportFile: 'posthog-revenue-report.md',\n docsUrl: 'https://posthog.com/docs/revenue-analytics',\n spinnerMessage: 'Setting up revenue analytics...',\n estimatedDurationMinutes: 5,\n abortCases: REVENUE_ABORT_CASES,\n },\n requires: ['posthog-integration'],\n};\n\nexport { REVENUE_ANALYTICS_PROGRAM } from './steps.js';\nexport {\n detectRevenuePrerequisites,\n POSTHOG_SDKS,\n STRIPE_SDKS,\n type RevenueDetectError,\n} from './detect.js';\n","/**\n * Generic agent skill step list.\n *\n * Minimal flow: intro → health-check → auth → run → outro → skills.\n * No detection, no setup, no MCP.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nexport const AGENT_SKILL_STEPS: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'agent-skill-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Running',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","/**\n * Generic agent skill program factory.\n *\n * Creates a ProgramConfig for any context-mill skill. Provide a\n * skill ID and basic UI config — the factory handles the rest.\n *\n * Usage:\n * createSkillProgram({\n * skillId: 'error-tracking-setup',\n * command: 'errors',\n * id: 'error-tracking',\n * description: 'Set up PostHog error tracking',\n * integrationLabel: 'error-tracking',\n * successMessage: 'Error tracking configured!',\n * reportFile: 'posthog-error-tracking-report.md',\n * docsUrl: 'https://posthog.com/docs/error-tracking',\n * spinnerMessage: 'Setting up error tracking...',\n * estimatedDurationMinutes: 5,\n * })\n */\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun, AbortCase } from '@lib/agent/agent-runner';\nimport { AGENT_SKILL_STEPS } from './steps.js';\nimport { getContentBlocks } from './content/index.js';\n\nexport interface SkillProgramOptions {\n /** Context-mill skill ID to install */\n skillId: string;\n /** CLI subcommand name */\n command: string;\n /** Unique flow key — must match a Program enum entry */\n id: string;\n /** CLI description shown in --help */\n description: string;\n /** Analytics integration label */\n integrationLabel: string;\n /** Custom prompt instruction. Appended after default project prompt. */\n customPrompt?: string;\n successMessage: string;\n reportFile: string;\n docsUrl: string;\n spinnerMessage: string;\n estimatedDurationMinutes: number;\n /** Other program ids that must be satisfied first */\n requires?: string[];\n /** Override the default outro. Receives the same args as ProgramRun.buildOutroData. */\n buildOutroData?: ProgramRun['buildOutroData'];\n /** Known `[ABORT] <reason>` cases the skill can emit. */\n abortCases?: AbortCase[];\n}\n\nexport function createSkillProgram(opts: SkillProgramOptions): ProgramConfig {\n return {\n command: opts.command,\n description: opts.description,\n id: opts.id,\n skillId: opts.skillId,\n steps: AGENT_SKILL_STEPS,\n reportFile: opts.reportFile,\n getContentBlocks,\n run: {\n skillId: opts.skillId,\n integrationLabel: opts.integrationLabel,\n customPrompt: opts.customPrompt ? () => opts.customPrompt! : undefined,\n successMessage: opts.successMessage,\n reportFile: opts.reportFile,\n docsUrl: opts.docsUrl,\n spinnerMessage: opts.spinnerMessage,\n estimatedDurationMinutes: opts.estimatedDurationMinutes,\n buildOutroData: opts.buildOutroData,\n abortCases: opts.abortCases,\n },\n requires: opts.requires,\n };\n}\n\nexport { AGENT_SKILL_STEPS } from './steps.js';\n","import type { AbortCase } from '@lib/agent/agent-runner';\n\n/** `[ABORT] <reason>` cases the audit skill can emit. Reason strings are\n * defined in the skill's `Abort statuses` section. */\nexport const AUDIT_ABORT_CASES: AbortCase[] = [\n {\n match: /^no posthog sdk found$/i,\n message: 'No PostHog SDK found',\n body:\n 'The audit needs an existing PostHog integration to review. No PostHog ' +\n 'SDK appears in this project’s dependency manifests. Run the basic ' +\n 'integration program to install PostHog first, then re-run the audit.',\n docsUrl: 'https://posthog.com/docs/getting-started/install',\n },\n];\n","import fs from 'fs';\nimport path from 'path';\nimport { logToFile } from '@utils/debug';\nimport { AUDIT_CHECKS_FILE, type AuditCheck } from './types.js';\n\n/**\n * The 10 data-integrity checks the audit runs, plus one workflow row for the\n * notebook upload at the end (so the skill's `audit_resolve_checks` call for\n * `upload-notebook` succeeds — the skill writes the report to a PostHog\n * notebook as its final step).\n */\nexport const AUDIT_SEED_CHECKS: AuditCheck[] = [\n {\n id: 'sdk-installed',\n area: 'Installation',\n label: 'PostHog SDK installed',\n status: 'pending',\n },\n {\n id: 'sdk-up-to-date',\n area: 'Installation',\n label: 'SDK version up to date',\n status: 'pending',\n },\n {\n id: 'init-correct',\n area: 'Installation',\n label: 'Initialization is correct',\n status: 'pending',\n },\n {\n id: 'identify-stable-distinct-id',\n area: 'Identification',\n label: 'Stable distinct_id (not session UUID)',\n status: 'pending',\n },\n {\n id: 'identify-not-late',\n area: 'Identification',\n label: 'identify() called before captures / flag evals',\n status: 'pending',\n },\n {\n id: 'cross-runtime-distinct-id',\n area: 'Identification',\n label: 'Same distinct_id across client and server',\n status: 'pending',\n },\n {\n id: 'identify-reset-on-logout',\n area: 'Identification',\n label: 'reset() called on logout / account switch',\n status: 'pending',\n },\n {\n id: 'capture-event-names-static',\n area: 'Event Capture',\n label: 'Event names are static and consistent',\n status: 'pending',\n },\n {\n id: 'capture-uses-proxy',\n area: 'Event Capture',\n label: 'Captures route through a reverse proxy',\n status: 'pending',\n },\n {\n id: 'capture-growth-events',\n area: 'Event Capture',\n label: 'Key activation events captured',\n status: 'pending',\n },\n {\n id: 'write-report',\n area: 'Write report',\n label: 'Create posthog-audit-report.md',\n status: 'pending',\n },\n {\n id: 'upload-notebook',\n area: 'Upload notebook',\n label: 'Write the report into a PostHog notebook',\n status: 'pending',\n },\n];\n\n/**\n * Atomically write a seeded ledger to the project's audit checks file.\n *\n * Each audit-flavored program (doctor, events-audit) owns its own seed\n * shape — pass the seed in so this writer stays program-agnostic.\n */\nexport function seedAuditLedger(\n installDir: string,\n checks: AuditCheck[] = AUDIT_SEED_CHECKS,\n): void {\n const target = path.join(installDir, AUDIT_CHECKS_FILE);\n const tmp = `${target}.tmp`;\n fs.writeFileSync(tmp, JSON.stringify(checks, null, 2), 'utf8');\n fs.renameSync(tmp, target);\n logToFile(`seedAuditLedger: wrote ${checks.length} entries to ${target}`);\n}\n","import {\n AGENT_SKILL_STEPS,\n createSkillProgram,\n} from '@lib/programs/agent-skill/index';\nimport type { ProgramStep, ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { OutroKind } from '@lib/wizard-session';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { getCloudUrlFromRegion } from '@utils/urls';\nimport { AUDIT_ABORT_CASES } from './detect.js';\nimport { AUDIT_CHECKS_KEY, AUDIT_REPORT_FILE } from './types.js';\nimport { AUDIT_SEED_CHECKS, seedAuditLedger } from './seed.js';\n\n/** Audit-specific screens for the shared agent-skill pipeline. */\nconst AUDIT_SCREEN_BY_STEP: Record<string, string> = {\n intro: 'audit-intro',\n run: 'audit-run',\n outro: 'audit-outro',\n};\n\nconst seedBeforeAuditRun = (session: WizardSession): void => {\n seedAuditLedger(session.installDir);\n session.frameworkContext[AUDIT_CHECKS_KEY] = AUDIT_SEED_CHECKS;\n};\n\nconst withAuditScreens = (steps: ProgramStep[]): ProgramStep[] =>\n steps.map((step) => {\n const override = AUDIT_SCREEN_BY_STEP[step.id];\n return override ? { ...step, screenId: override } : step;\n });\n\nconst auditSteps: ProgramStep[] = withAuditScreens(AGENT_SKILL_STEPS);\n\nconst baseConfig = createSkillProgram({\n skillId: 'audit',\n command: 'audit',\n id: 'audit',\n description:\n 'Audit an existing PostHog integration for correctness and best practices',\n integrationLabel: 'audit',\n customPrompt:\n 'Run a comprehensive audit of the existing PostHog integration. Follow the skill program steps in order. Do not modify any project files — only create the final audit report.',\n successMessage:\n 'Audit complete! You can view the audit report at ./posthog-audit-report.md',\n reportFile: AUDIT_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/product-analytics/best-practices',\n spinnerMessage: 'Auditing PostHog integration...',\n estimatedDurationMinutes: 5,\n requires: ['posthog-integration'],\n abortCases: AUDIT_ABORT_CASES,\n});\n\nconst auditRun = async (session: WizardSession): Promise<ProgramRun> => {\n seedBeforeAuditRun(session);\n\n if (!baseConfig.run) {\n throw new Error('Audit program has no run configuration.');\n }\n\n const baseRun =\n typeof baseConfig.run === 'function'\n ? await baseConfig.run(session)\n : baseConfig.run;\n\n return {\n ...baseRun,\n // Override the default outro so the dashboard + notebook URLs the\n // agent emits via `[DASHBOARD_URL]` / `[NOTEBOOK_URL]` are surfaced\n // on the post-run screen.\n buildOutroData: (sess, _credentials, cloudRegion) => {\n const cloudUrl = cloudRegion\n ? getCloudUrlFromRegion(cloudRegion)\n : undefined;\n const continueUrl =\n sess.signup && cloudUrl\n ? `${cloudUrl}/products?source=wizard`\n : undefined;\n\n // Note: `sess` here is the agent-runner's snapshot of session at\n // runAgent() invocation time. Any URL emissions during the run land\n // on the live store, NOT on this snapshot. The UI layer\n // (InkUI.setOutroData) merges live URLs in on top of this return\n // value, so it's safe to leave dashboardUrl/notebookUrl as undefined\n // here when the snapshot doesn't have them.\n return {\n kind: OutroKind.Success as const,\n message: baseRun.successMessage,\n reportFile: baseRun.reportFile,\n docsUrl: baseRun.docsUrl,\n continueUrl,\n dashboardUrl: sess.dashboardUrl ?? undefined,\n notebookUrl: sess.notebookUrl ?? undefined,\n };\n },\n };\n};\n\nexport const auditConfig: ProgramConfig = {\n ...baseConfig,\n steps: auditSteps,\n run: auditRun,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n};\n","/**\n * Events-audit program.\n *\n * Mirrors the posthog-integration step list, except:\n * - The initial framework detection step is omitted — the events-audit\n * skill handles detection at agent run time.\n * - The intro step uses the audit intro screen (no framework selection\n * logic) instead of the integration intro.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nfunction needsSetup(session: WizardSession): boolean {\n const config = session.frameworkConfig;\n if (!config?.metadata.setup?.questions) return false;\n\n return config.metadata.setup.questions.some(\n (q: { key: string }) => !(q.key in session.frameworkContext),\n );\n}\n\nexport const EVENTS_AUDIT_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'audit-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'setup',\n label: 'Setup',\n screenId: 'setup',\n show: needsSetup,\n isComplete: (session) => !needsSetup(session),\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Events audit',\n screenId: 'audit-run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'mcp',\n label: 'MCP servers',\n screenId: 'mcp',\n isComplete: (session) => session.mcpComplete,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'audit-outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'keep-skills',\n label: 'Keep Skills',\n screenId: 'keep-skills',\n },\n];\n","import type { AuditCheck } from '@lib/programs/audit/types';\n\n/**\n * The 7 phases the events-audit skill marches through. One check per area\n * so PendingChecksList renders a clean linear pipeline (area = bold header,\n * single row = the active spinner).\n *\n * Phase ids match what the skill's step files resolve via\n * `mcp__wizard-tools__audit_resolve_checks` as each phase completes. The\n * skill's step 1 also seeds these same ids — keep both in sync so the\n * wizard pre-seed and the skill's MCP seed agree.\n */\nexport const EVENTS_AUDIT_SEED_CHECKS: AuditCheck[] = [\n {\n id: 'detect-sdk',\n area: 'Detect SDK',\n label: 'Identify PostHog SDK(s) in dependencies',\n status: 'pending',\n },\n {\n id: 'scan-sites',\n area: 'Scan capture sites',\n label: 'Grep capture/identify/group call sites',\n status: 'pending',\n },\n {\n id: 'enrich-sites',\n area: 'Enrich',\n label: 'Subagent fan-out to read capture files',\n status: 'pending',\n },\n {\n id: 'query-volume',\n area: 'Query PostHog',\n label: '30-day volume + last_seen via MCP',\n status: 'pending',\n },\n {\n id: 'write-report',\n area: 'Write report',\n label: 'Create posthog-events-audit-report.md',\n status: 'pending',\n },\n {\n id: 'create-dashboard',\n area: 'Create dashboard',\n label: 'Optional: dashboard for resolved events',\n status: 'pending',\n },\n {\n id: 'upload-notebook',\n area: 'Upload notebook',\n label: 'Write the report into a PostHog notebook',\n status: 'pending',\n },\n];\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { OutroKind } from '@lib/wizard-session';\nimport { SPINNER_MESSAGE } from '@lib/framework-config';\nimport { isUsingTypeScript } from '@utils/setup-utils';\nimport { getCloudUrlFromRegion } from '@utils/urls';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { EVENTS_AUDIT_PROGRAM } from './steps.js';\nimport { AUDIT_CHECKS_KEY } from '@lib/programs/audit/types';\nimport { seedAuditLedger } from '@lib/programs/audit/seed';\nimport { EVENTS_AUDIT_SEED_CHECKS } from './seed.js';\n\nexport const SETUP_REPORT_FILE = 'posthog-events-audit-report.md';\n\nconst DOCS_URL = 'https://posthog.com/docs/product-analytics/best-practices';\n\nexport const eventsAuditConfig: ProgramConfig = {\n command: 'events-audit',\n description: 'Audit PostHog event tracking in this project',\n id: 'events-audit',\n skillId: 'events-audit',\n steps: EVENTS_AUDIT_PROGRAM,\n // Top-level reportFile so AuditRunScreen can resolve the report path\n // synchronously without unwrapping the deferred `run` function.\n reportFile: SETUP_REPORT_FILE,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n\n run: (session: WizardSession): Promise<ProgramRun> => {\n const typeScriptDetected = isUsingTypeScript({\n installDir: session.installDir,\n });\n session.typescript = typeScriptDetected;\n\n // Seed the audit ledger so AuditRunScreen has something to render\n // before the agent emits its first check update. The events-audit\n // ledger is the 6-phase pipeline, not the doctor's 10 integrity checks.\n seedAuditLedger(session.installDir, EVENTS_AUDIT_SEED_CHECKS);\n session.frameworkContext[AUDIT_CHECKS_KEY] = EVENTS_AUDIT_SEED_CHECKS;\n\n return Promise.resolve({\n skillId: 'events-audit',\n integrationLabel: 'events-audit',\n spinnerMessage: SPINNER_MESSAGE,\n successMessage:\n 'Events audit complete! You can view the report at ./posthog-events-audit-report.md',\n estimatedDurationMinutes: 5,\n reportFile: SETUP_REPORT_FILE,\n docsUrl: DOCS_URL,\n errorMessage: 'Events audit failed',\n additionalFeatureQueue: session.additionalFeatureQueue,\n\n customPrompt: (ctx) =>\n `Audit PostHog event capture in this project. Do not modify any project files — produce a read-only report only.\n\nProject context:\n- PostHog Project ID: ${ctx.projectId}\n- TypeScript: ${typeScriptDetected ? 'Yes' : 'No'}\n- PostHog public token: ${ctx.projectApiKey}\n- PostHog Host: ${ctx.host}\n`,\n\n buildOutroData: (sess, _credentials, cloudRegion) => {\n const cloudUrl = cloudRegion\n ? getCloudUrlFromRegion(cloudRegion)\n : undefined;\n const continueUrl =\n sess.signup && cloudUrl\n ? `${cloudUrl}/products?source=wizard`\n : undefined;\n // The agent emits `[DASHBOARD_URL] <url>` once it creates the\n // dashboard; the SDK-message interceptor stores it on the session.\n // Fall back to the dashboards index if nothing was emitted.\n const dashboardUrl =\n sess.dashboardUrl ?? (cloudUrl ? `${cloudUrl}/dashboard` : undefined);\n\n // The agent emits `[NOTEBOOK_URL] <url>` once it uploads the report\n // to a PostHog notebook. No fallback: if the notebook upload was\n // skipped (e.g. MCP unavailable) we just don't show a link.\n const notebookUrl = sess.notebookUrl ?? undefined;\n\n return {\n kind: OutroKind.Success as const,\n message: 'Your events audit was successful',\n reportFile: SETUP_REPORT_FILE,\n changes: [],\n docsUrl: DOCS_URL,\n continueUrl,\n dashboardUrl,\n notebookUrl,\n };\n },\n });\n },\n};\n\nexport { EVENTS_AUDIT_PROGRAM } from './steps.js';\n","import fs from 'fs';\nimport path from 'path';\nimport {\n AGENT_SKILL_STEPS,\n createSkillProgram,\n} from '@lib/programs/agent-skill/index';\nimport type { ProgramStep, ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { AUDIT_ABORT_CASES } from '@lib/programs/audit/detect';\nimport {\n AUDIT_CHECKS_FILE,\n AUDIT_CHECKS_KEY,\n type AuditCheck,\n} from '@lib/programs/audit/types';\nimport { AUDIT_SEED_CHECKS } from '@lib/programs/audit/seed';\nimport { logToFile } from '@utils/debug';\n\nconst AUDIT3000_REPORT_FILE = 'posthog-audit-3000-report.md';\n\n// Extra checks the v3000 audit adds on top of the base 10. IDs must match\n// those referenced in the audit-3000 skill's step files (Event Quality,\n// stale feature-flag review, session replay [fix + optimize], per-product\n// use-case expansion, and phase markers for the post-flags chain).\nconst AUDIT3000_EXTRA_CHECKS: AuditCheck[] = [\n // ── Event Quality (Step 5) ──\n {\n id: 'event-naming-standardization',\n area: 'Event Quality',\n label: 'Event naming convention is consistent',\n status: 'pending',\n },\n {\n id: 'event-duplicates-and-bloat',\n area: 'Event Quality',\n label: 'No duplicate or bloated event capture',\n status: 'pending',\n },\n {\n id: 'event-quality-context-review',\n area: 'Event Quality',\n label: 'Event property context reviewed',\n status: 'pending',\n },\n {\n id: 'event-usage-coverage',\n area: 'Event Quality',\n label: 'Captured events match insights / dashboards usage',\n status: 'pending',\n },\n // ── Feature Flags (Step 6) ──\n {\n id: 'stale-feature-flags-reviewed',\n area: 'Feature Flags',\n label: 'Stale feature flags reviewed',\n status: 'pending',\n },\n // ── Session Replay — fix (Step 6b) ──\n {\n id: 'replay-minimum-duration-set',\n area: 'Session Replay',\n label: 'Minimum duration set on init',\n status: 'pending',\n },\n {\n id: 'replay-mask-config',\n area: 'Session Replay',\n label: 'Mask config covers sensitive surfaces',\n status: 'pending',\n },\n {\n id: 'replay-disabled-in-test-envs',\n area: 'Session Replay',\n label: 'Disabled in test / CI environments',\n status: 'pending',\n },\n {\n id: 'replay-strict-minimum-duration',\n area: 'Session Replay',\n label: 'Strict minimum duration enforced',\n status: 'pending',\n },\n // ── Session Replay — optimize (Step 6b cost wave) ──\n {\n id: 'replay-sampling-rate',\n area: 'Session Replay — Optimize',\n label: 'Sampling rate tuned for cost',\n status: 'pending',\n },\n {\n id: 'replay-triggers-configured',\n area: 'Session Replay — Optimize',\n label: 'Triggers configured (event / URL / flag)',\n status: 'pending',\n },\n {\n id: 'replay-network-recording-filtered',\n area: 'Session Replay — Optimize',\n label: 'Network recording filtered',\n status: 'pending',\n },\n {\n id: 'replay-mobile-sampling',\n area: 'Session Replay — Optimize',\n label: 'Mobile sampling configured',\n status: 'pending',\n },\n // ── Use Case: Expansion (Step 9) ──\n {\n id: 'expansion-product-analytics',\n area: 'Use Case: Expansion',\n label: 'Product analytics coverage',\n status: 'pending',\n },\n {\n id: 'expansion-error-tracking',\n area: 'Use Case: Expansion',\n label: 'Error tracking coverage',\n status: 'pending',\n },\n {\n id: 'expansion-llm-observability',\n area: 'Use Case: Expansion',\n label: 'LLM observability coverage',\n status: 'pending',\n },\n {\n id: 'expansion-session-replay',\n area: 'Use Case: Expansion',\n label: 'Session replay coverage',\n status: 'pending',\n },\n {\n id: 'expansion-feature-flags',\n area: 'Use Case: Expansion',\n label: 'Feature flags coverage',\n status: 'pending',\n },\n {\n id: 'expansion-surveys',\n area: 'Use Case: Expansion',\n label: 'Surveys coverage',\n status: 'pending',\n },\n {\n id: 'expansion-logs',\n area: 'Use Case: Expansion',\n label: 'Logs coverage',\n status: 'pending',\n },\n {\n id: 'expansion-web-analytics',\n area: 'Use Case: Expansion',\n label: 'Web analytics coverage',\n status: 'pending',\n },\n // ── Additional Sections (Steps 7, 8, 10 phase markers) ──\n // Tracked in the ledger so the UI can surface \"did it run / was it\n // skipped\" alongside the regular checks. use-case-expansion is omitted\n // because the eight `expansion-*` checks above cover that phase.\n {\n id: 'customer-enrichment',\n area: 'Additional Sections',\n label: 'Customer enrichment (Harmonic + PDL)',\n status: 'pending',\n },\n {\n id: 'use-case-match',\n area: 'Additional Sections',\n label: 'Use-case match',\n status: 'pending',\n },\n {\n id: 'final-report',\n area: 'Additional Sections',\n label: 'Final audit report written',\n status: 'pending',\n },\n];\n\nconst AUDIT3000_SEED_CHECKS: AuditCheck[] = [\n ...AUDIT_SEED_CHECKS,\n ...AUDIT3000_EXTRA_CHECKS,\n];\n\n// Audit-3000 has its own arcade-flavoured intro / run / outro screens. The\n// shared audit screens stay reserved for the original `audit` program.\nconst AUDIT3000_SCREEN_BY_STEP: Record<string, string> = {\n intro: 'audit-3000-intro',\n run: 'audit-3000-run',\n outro: 'audit-3000-outro',\n};\n\nconst seedAudit3000Ledger = (installDir: string): void => {\n const target = path.join(installDir, AUDIT_CHECKS_FILE);\n const tmp = `${target}.tmp`;\n fs.writeFileSync(tmp, JSON.stringify(AUDIT3000_SEED_CHECKS, null, 2), 'utf8');\n fs.renameSync(tmp, target);\n logToFile(\n `seedAudit3000Ledger: wrote ${AUDIT3000_SEED_CHECKS.length} entries to ${target}`,\n );\n};\n\nconst seedBeforeAudit3000Run = (session: WizardSession): void => {\n seedAudit3000Ledger(session.installDir);\n session.frameworkContext[AUDIT_CHECKS_KEY] = AUDIT3000_SEED_CHECKS;\n};\n\nconst withAudit3000Screens = (steps: ProgramStep[]): ProgramStep[] =>\n steps.map((step) => {\n const override = AUDIT3000_SCREEN_BY_STEP[step.id];\n return override ? { ...step, screenId: override } : step;\n });\n\nconst audit3000Steps: ProgramStep[] = withAudit3000Screens(AGENT_SKILL_STEPS);\n\nconst baseConfig = createSkillProgram({\n skillId: 'audit-3000',\n command: 'audit-3000',\n id: 'audit-3000',\n description:\n 'Audit an existing PostHog integration (v3000 — adds event quality, stale-flag hygiene, customer enrichment, use-case match)',\n integrationLabel: 'audit-3000',\n customPrompt:\n 'Run the audit-3000 skill end-to-end. Follow the step chain starting at references/1-version.md. Do not modify any project files — only create the final audit report and (when enrichment is enabled) the enrichment report.',\n successMessage: `Audit complete! View the report at ./${AUDIT3000_REPORT_FILE}`,\n reportFile: AUDIT3000_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/product-analytics/best-practices',\n spinnerMessage: 'Running PostHog Audit 3000...',\n estimatedDurationMinutes: 6,\n requires: ['posthog-integration'],\n abortCases: AUDIT_ABORT_CASES,\n});\n\nconst audit3000Run = async (session: WizardSession): Promise<ProgramRun> => {\n seedBeforeAudit3000Run(session);\n\n if (!baseConfig.run) {\n throw new Error('audit-3000 program has no run configuration.');\n }\n\n return typeof baseConfig.run === 'function'\n ? baseConfig.run(session)\n : baseConfig.run;\n};\n\nexport const audit3000Config: ProgramConfig = {\n ...baseConfig,\n steps: audit3000Steps,\n run: audit3000Run,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n};\n","import type { ProgramStep } from '@lib/programs/program-step';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nexport const POSTHOG_DOCTOR_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'doctor-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'report',\n label: 'Doctor report',\n screenId: 'doctor-report',\n isComplete: (session) => session.outroData !== null,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n];\n","import { z } from 'zod';\n\nexport const HealthIssueSeveritySchema = z.enum([\n 'critical',\n 'warning',\n 'info',\n]);\nexport type HealthIssueSeverity = z.infer<typeof HealthIssueSeveritySchema>;\n\nexport const HealthIssueStatusSchema = z.enum(['active', 'resolved']);\n\nexport const HealthIssueSchema = z.object({\n id: z.string(),\n kind: z.string(),\n severity: HealthIssueSeveritySchema,\n status: HealthIssueStatusSchema,\n dismissed: z.boolean(),\n created_at: z.string(),\n updated_at: z.string(),\n resolved_at: z.string().nullable().optional(),\n});\nexport type HealthIssue = z.infer<typeof HealthIssueSchema>;\n\nexport const HealthIssueListResponseSchema = z.object({\n results: z.array(HealthIssueSchema),\n count: z.number().optional(),\n next: z.string().nullable().optional(),\n previous: z.string().nullable().optional(),\n});\nexport type HealthIssueListResponse = z.infer<\n typeof HealthIssueListResponseSchema\n>;\n\nexport interface HealthIssueSummary {\n total: number;\n by_severity: Record<HealthIssueSeverity, number>;\n}\n","import axios from 'axios';\nimport { analytics } from '@utils/analytics';\nimport { handleApiError } from '@lib/api';\nimport { WIZARD_USER_AGENT } from '@lib/constants';\nimport { HealthIssueListResponseSchema, type HealthIssue } from './types';\n\nexport async function fetchHealthIssues(\n accessToken: string,\n baseUrl: string,\n projectId: number,\n): Promise<HealthIssue[]> {\n const endpoint = `/api/environments/${projectId}/health_issues/`;\n const url = `${baseUrl}${endpoint}?status=active&dismissed=false&limit=250`;\n try {\n const response = await axios.get(url, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'User-Agent': WIZARD_USER_AGENT,\n },\n });\n return HealthIssueListResponseSchema.parse(response.data).results;\n } catch (error) {\n const apiError = handleApiError(error, 'fetch health issues');\n analytics.captureException(apiError, { endpoint, baseUrl, projectId });\n throw apiError;\n }\n}\n","import { POSTHOG_DOCS_URL } from '@lib/constants';\n\nexport interface KindMeta {\n title: string;\n description: string;\n docsUrl: string;\n}\n\nexport const KIND_METADATA: Record<string, KindMeta> = {\n ingestion_lag: {\n title: 'Ingestion is delayed',\n description:\n 'Events are being received but are taking longer than usual to appear.',\n docsUrl: `${POSTHOG_DOCS_URL}/support/troubleshooting`,\n },\n ingestion_warning: {\n title: 'Ingestion warnings on recent events',\n description:\n 'Some recent events were rejected or flagged by the ingestion pipeline.',\n docsUrl: `${POSTHOG_DOCS_URL}/support/troubleshooting`,\n },\n sdk_outdated: {\n title: 'SDK version is out of date',\n description:\n 'One or more SDKs are running an old version. Upgrade to get the latest fixes.',\n docsUrl: `${POSTHOG_DOCS_URL}/libraries`,\n },\n no_live_events: {\n title: 'No $pageview or $screen events in the last 30 days',\n description:\n 'PostHog is not receiving page or screen events from this project.',\n docsUrl: `${POSTHOG_DOCS_URL}/getting-started/install`,\n },\n no_pageleave_events: {\n title: '$pageleave events not being sent',\n description:\n 'Enable pageleave tracking to power bounce rate and session duration.',\n docsUrl: `${POSTHOG_DOCS_URL}/libraries/js#config`,\n },\n scroll_depth: {\n title: 'Scroll depth tracking disabled',\n description:\n 'Turn on scroll depth to capture how far users read each page.',\n docsUrl: `${POSTHOG_DOCS_URL}/libraries/js#config`,\n },\n authorized_urls: {\n title: 'No authorized URLs configured',\n description:\n 'Some web analytics filters require at least one authorized URL to work.',\n docsUrl: `${POSTHOG_DOCS_URL}/web-analytics/faq`,\n },\n reverse_proxy: {\n title: 'No reverse proxy detected',\n description: 'A reverse proxy reduces data loss from ad blockers.',\n docsUrl: `${POSTHOG_DOCS_URL}/advanced/proxy`,\n },\n web_vitals: {\n title: 'Web Vitals tracking disabled',\n description:\n 'Enable Web Vitals to capture LCP, CLS and other performance metrics.',\n docsUrl: `${POSTHOG_DOCS_URL}/web-analytics/web-vitals`,\n },\n materialized_view_failure: {\n title: 'A materialized view is failing',\n description: 'A data modeling pipeline failed its most recent run.',\n docsUrl: `${POSTHOG_DOCS_URL}/data-warehouse`,\n },\n external_data_failure: {\n title: 'External data source is failing',\n description: 'An external data source sync failed and data may be stale.',\n docsUrl: `${POSTHOG_DOCS_URL}/data-warehouse/sources`,\n },\n};\n\nexport const UNKNOWN_KIND_META: KindMeta = {\n title: 'Unknown issue',\n description:\n 'PostHog reported an issue kind the wizard does not yet recognize.',\n docsUrl: POSTHOG_DOCS_URL,\n};\n\nexport function getKindMeta(kind: string): KindMeta {\n return KIND_METADATA[kind] ?? { ...UNKNOWN_KIND_META, title: kind };\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { POSTHOG_DOCTOR_PROGRAM } from './steps.js';\n\nexport const posthogDoctorConfig: ProgramConfig = {\n command: 'doctor',\n description:\n 'Diagnose your PostHog project for configuration issues and setup warnings',\n id: 'posthog-doctor',\n requiresAi: false,\n steps: POSTHOG_DOCTOR_PROGRAM,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n};\n\nexport { POSTHOG_DOCTOR_PROGRAM } from './steps.js';\nexport { fetchHealthIssues } from './fetch.js';\nexport { getKindMeta, KIND_METADATA } from './kind-metadata.js';\nexport type { KindMeta } from './kind-metadata.js';\nexport type {\n HealthIssue,\n HealthIssueSeverity,\n HealthIssueSummary,\n} from './types.js';\n","import { existsSync, statSync } from 'fs';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { findPackageJsons } from '@lib/programs/shared/package-scanning';\n\nexport type WebAnalyticsDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-package-json' }\n | { kind: 'no-posthog'; scannedCount: number };\n\nexport const WEB_ANALYTICS_ABORT_CASES: AbortCase[] = [\n {\n match: /^no web analytics events$/i,\n message: 'No web analytics events',\n body:\n 'The doctor found no $pageview events in the last 30 days, so there is ' +\n 'nothing to audit yet. Make sure PostHog is initialized and capturing ' +\n 'pageviews, then run the doctor again.',\n docsUrl: 'https://posthog.com/docs/web-analytics/getting-started',\n },\n {\n match: /^insufficient permissions$/i,\n message: 'Insufficient permissions',\n body:\n 'The doctor could not query your project — the authenticated token is ' +\n 'missing query access. Re-run the wizard to sign in again, or use a key ' +\n 'with read access to your events.',\n docsUrl: 'https://posthog.com/docs/web-analytics',\n },\n {\n match: /^posthog sdk not installed$/i,\n message: 'PostHog SDK not installed',\n body:\n 'The doctor could not find a PostHog SDK in this project. Install and ' +\n 'configure PostHog first (run `npx @posthog/wizard`), then run the ' +\n 'doctor to check your web analytics setup.',\n docsUrl: 'https://posthog.com/docs/libraries/js',\n },\n];\n\nexport function detectWebAnalyticsPrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: WebAnalyticsDetectError) =>\n setFrameworkContext('detectError', error);\n\n const installDir = session.installDir;\n\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n const matches = findPackageJsons(installDir);\n\n if (matches.length === 0) {\n fail({ kind: 'no-package-json' });\n return;\n }\n\n const sdks = [...new Set(matches.flatMap((m) => m.posthogSdks))];\n\n if (sdks.length === 0) {\n fail({ kind: 'no-posthog', scannedCount: matches.length });\n return;\n }\n\n setFrameworkContext('detectedPosthogSdks', sdks);\n}\n","import type { ProgramStep } from '@lib/programs/program-step';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/steps';\nimport { detectWebAnalyticsPrerequisites } from './detect.js';\n\nexport const WEB_ANALYTICS_DOCTOR_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting prerequisites',\n onReady: (ctx) =>\n detectWebAnalyticsPrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n ...AGENT_SKILL_STEPS,\n];\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { createSkillProgram } from '../agent-skill/index.js';\nimport { WEB_ANALYTICS_DOCTOR_PROGRAM } from './steps.js';\nimport { WEB_ANALYTICS_ABORT_CASES } from './detect.js';\n\nconst REPORT_FILE = 'posthog-web-analytics-report.md';\nconst DOCS_URL = 'https://posthog.com/docs/web-analytics';\n\nexport const webAnalyticsDoctorConfig: ProgramConfig = {\n ...createSkillProgram({\n skillId: 'web-analytics-doctor',\n command: 'web-analytics',\n id: 'web-analytics-doctor',\n description: 'Audit and fix your PostHog web analytics setup',\n integrationLabel: 'web-analytics-doctor',\n customPrompt:\n \"Run the web-analytics-doctor skill to check this project's PostHog web \" +\n 'analytics setup. Audit read-only first, then present the findings to the ' +\n 'user with a single wizard_ask multi-select and apply only the fixes they ' +\n 'choose — editing project code and/or PostHog project settings via the ' +\n 'MCP — before writing the report.',\n successMessage:\n 'Web analytics check complete! You can view the report at ./posthog-web-analytics-report.md',\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Checking your web analytics setup...',\n estimatedDurationMinutes: 5,\n requires: ['posthog-integration'],\n abortCases: WEB_ANALYTICS_ABORT_CASES,\n }),\n steps: WEB_ANALYTICS_DOCTOR_PROGRAM,\n parentCommand: 'audit',\n};\n\nexport { WEB_ANALYTICS_DOCTOR_PROGRAM } from './steps.js';\nexport {\n detectWebAnalyticsPrerequisites,\n WEB_ANALYTICS_ABORT_CASES,\n type WebAnalyticsDetectError,\n} from './detect.js';\n","import type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nexport const MIGRATION_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'migration-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Migration',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","/**\n * Vendor cost stack — the multi-tool baseline a typical migration target has\n * before consolidating onto PostHog. Numbers from each vendor's published\n * starter pricing.\n */\n\nimport { Text } from 'ink';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const VENDOR_STACK_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 600,\n pause: 9000,\n lines: [\n <Text bold>{' Typical pre-migration stack'}</Text>,\n <Text> </Text>,\n <Text>\n <Text color=\"gray\">{' Sentry'}</Text>\n <Text>{' error tracking '}</Text>\n <Text color=\"red\">{'$26/mo+'}</Text>\n </Text>,\n <Text>\n <Text color=\"gray\">{' LaunchDarkly'}</Text>\n <Text>{' feature flags '}</Text>\n <Text color=\"red\">{'$8.33/mo+'}</Text>\n </Text>,\n <Text>\n <Text color=\"gray\">{' Amplitude'}</Text>\n <Text>{' product analytics '}</Text>\n <Text color=\"red\">{'$49/mo+'}</Text>\n </Text>,\n <Text>\n <Text color=\"gray\">{' Braintrust'}</Text>\n <Text>{' LLM analytics '}</Text>\n <Text color=\"red\">{'$50/mo+'}</Text>\n </Text>,\n <Text color=\"gray\">{' ─────────────────────────────────────'}</Text>,\n <Text>\n <Text>{' Total'}</Text>\n <Text>{' '}</Text>\n <Text bold color=\"red\">\n {'$133/mo+'}\n </Text>\n </Text>,\n <Text dimColor>{' plus ~450KB of JavaScript SDKs'}</Text>,\n ],\n};\n","/**\n * PostHog free-tier highlights — the numbers a migrating team gets back when\n * they consolidate. Sourced from posthog.com/pricing.md.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const FREE_TIER_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 400,\n pause: 9000,\n lines: [\n <Text bold>{' Free every month, on every product'}</Text>,\n <Text> </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,000,000 '}</Text>\n <Text>events </Text>\n <Text dimColor>product analytics</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,000,000 '}</Text>\n <Text>requests </Text>\n <Text dimColor>feature flags + experiments</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 5,000 '}</Text>\n <Text>recordings </Text>\n <Text dimColor>session replay</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 100,000 '}</Text>\n <Text>exceptions </Text>\n <Text dimColor>error tracking</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 100,000 '}</Text>\n <Text>events </Text>\n <Text dimColor>LLM analytics</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 50 GB '}</Text>\n <Text>logs </Text>\n <Text dimColor>logs</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,500 '}</Text>\n <Text>responses </Text>\n <Text dimColor>surveys</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,000,000 '}</Text>\n <Text>rows </Text>\n <Text dimColor>data warehouse</Text>\n </Text>,\n ],\n};\n","/**\n * Pricing structure block — what happens after the free tier.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const PRICING_STRUCTURE_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 500,\n pause: 8000,\n lines: [\n <Text bold>{' After the free tier'}</Text>,\n <Text> </Text>,\n <Text>\n <Text color={Colors.accent}>{' $0 '}</Text>\n <Text>base price · pay only for what you use</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>per-event prices decrease with volume</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>no per-seat charges — your whole team is included</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>web analytics bundled with product analytics</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>experiments bundled with feature flags</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>revenue analytics bundled with data warehouse</Text>\n </Text>,\n ],\n};\n","/**\n * Migration learn deck (statsig variant). Statsig is the only `migrate`\n * variant today, so this deck plays as-is when the wizard runs\n * `migrate --product=statsig`. Three movements:\n *\n * 1. Welcome and reassure.\n * 2. What to expect — the migration is replacement-only, takes a few\n * minutes, leaves the build green.\n * 3. What's a little different — how flags and experiments work in\n * PostHog, presented as right-way guidance rather than gotchas.\n *\n * FF/experiments guidance paraphrased from PostHog public docs:\n * - posthog.com/docs/feature-flags/best-practices\n * - posthog.com/docs/feature-flags/common-questions\n * - posthog.com/docs/experiments/best-practices\n */\n\nimport { Text } from 'ink';\nimport type { WizardStore } from '@ui/tui/store';\nimport { Colors } from '@ui/tui/styles';\nimport { TextRevealMode } from '@ui/tui/primitives/TextBlock';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\nimport { StatusPeekTrigger } from '@ui/tui/components/StatusPeekTrigger';\nimport { PRODUCT_SUITE_BLOCK } from '@lib/programs/posthog-integration/content/product-suite';\nimport { LINE_CHART_BLOCK } from '@lib/programs/posthog-integration/content/line-chart';\nimport { FUNNEL_BLOCK } from '@lib/programs/posthog-integration/content/funnel';\nimport { VENDOR_STACK_BLOCK } from './vendor-stack.js';\nimport { FREE_TIER_BLOCK } from './free-tier.js';\nimport { PRICING_STRUCTURE_BLOCK } from './pricing-structure.js';\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] => [\n // ── Welcome ────────────────────────────────────────────────────────────\n {\n content: 'Hello.',\n pause: 3000,\n mode: TextRevealMode.Typewriter,\n animationInterval: 160,\n },\n\n { content: 'The Wizard is an agent.', pause: 4000 },\n\n {\n content:\n 'As we speak, it’s making a plan to migrate from Statsig to PostHog.',\n pause: 6000,\n },\n\n {\n content: 'PostHog covers the cost of running this agent.',\n pause: 4000,\n },\n\n { type: 'clear', pause: 2000 },\n\n {\n pause: 5000,\n persist: true,\n content: <StatusPeekTrigger store={store} />,\n },\n\n {\n pause: 6000,\n persist: true,\n content: (\n <Text>\n Press{' '}\n <Text color={Colors.accent} bold>\n S\n </Text>{' '}\n to expand or collapse the status.\n </Text>\n ),\n },\n\n { type: 'clear', pause: 2000 },\n\n // ── What to expect ─────────────────────────────────────────────────────\n { content: 'Here’s what to expect.', pause: 3000 },\n\n { content: 'The migration takes about ten minutes.', pause: 3000 },\n\n {\n content:\n 'Every Statsig call gets replaced in place with its PostHog equivalent.',\n pause: 5500,\n },\n\n {\n content:\n 'Nothing new gets added. No extra captures, no surprise instrumentation.',\n pause: 5500,\n },\n\n {\n content:\n 'The Statsig package gets removed at the end. We’ll run build and lint to clean up after ourselves.',\n pause: 6500,\n },\n\n { type: 'clear', pause: 2000 },\n\n // ── What's a little different ─────────────────────────────────────────\n {\n content: 'A few things work a little differently in PostHog.',\n pause: 4500,\n },\n\n {\n content: (\n <Text>\n Flags evaluate against a stable user. Call{' '}\n <Text bold color={Colors.accent}>\n identify()\n </Text>{' '}\n first, then check the flag.\n </Text>\n ),\n pause: 6000,\n persist: true,\n },\n\n {\n content:\n 'For anything in the first paint, evaluate server-side and bootstrap the values into the client.',\n pause: 6500,\n },\n\n {\n content: (\n <Text>\n In production, route requests through a reverse proxy to avoid ad\n blockers breaking your flags.{'\\n'}\n <Text dimColor>https://posthog.com/docs/advanced/proxy</Text>\n </Text>\n ),\n pause: 6500,\n persist: true,\n },\n\n {\n content:\n 'When a flag reaches 100% rollout, retire it. Flags are signals, not switches.',\n pause: 5500,\n },\n\n {\n content: (\n <Text>\n Name flags descriptively. No double negatives. Reflect the return type.{' '}\n <Text dimColor>For example </Text>\n <Text bold>show-new-checkout</Text>\n <Text dimColor>.</Text>\n </Text>\n ),\n pause: 6500,\n persist: true,\n },\n\n { type: 'clear', pause: 1500 },\n\n // ── Experiments ────────────────────────────────────────────────────────\n {\n content: (\n <Text bold color={Colors.accent}>\n Experiments\n </Text>\n ),\n pause: 2500,\n persist: true,\n },\n\n {\n content:\n 'Change one thing per variant. Multiple changes in one variant blur the result.',\n pause: 5500,\n },\n\n {\n content:\n 'Decide the running time up front. PostHog includes a sample-size and duration calculator in the setup flow.',\n pause: 6500,\n },\n\n {\n content: 'Roll out to 5–10% first. Watch the metrics. Then increase.',\n pause: 5000,\n },\n\n {\n content:\n 'Exclude users who already completed the flow. They can’t be affected by the test.',\n pause: 5500,\n },\n\n { type: 'clear', pause: 1500 },\n\n // ── Close ──────────────────────────────────────────────────────────────\n {\n content: 'Flags and experiments live alongside the rest of your data.',\n pause: 4500,\n },\n\n {\n content: 'Ship behind a flag, watch replays, check analytics for impact.',\n pause: 4500,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content:\n 'PostHog also provides every other analytics and AI tool to build your product.',\n pause: 4500,\n },\n\n PRODUCT_SUITE_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'And consolidating onto one platform saves real money.',\n pause: 4500,\n },\n\n { content: 'Here’s the math.', pause: 1500 },\n\n VENDOR_STACK_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'Pricing is usage-based, with a generous free tier.',\n pause: 4000,\n },\n\n FREE_TIER_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n PRICING_STRUCTURE_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'Gain clarity and really understand your users.',\n pause: 4000,\n },\n\n { content: 'Use trends to measure growth.', pause: 2500 },\n\n LINE_CHART_BLOCK,\n\n { type: 'clear', pause: 500 },\n\n { content: 'Use funnels to reveal bottlenecks.', pause: 2500 },\n\n FUNNEL_BLOCK,\n];\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { MIGRATION_PROGRAM } from './steps.js';\nimport { getContentBlocks } from './content/index.js';\n\nconst MIGRATION_REPORT_FILE = 'migration-report.md';\n\nconst MIGRATION_ABORT_CASES: AbortCase[] = [\n {\n match: /^no source-sdk calls found$/i,\n message: 'No source-SDK calls found',\n body:\n 'The migration needs an existing third-party SDK to migrate from. No ' +\n 'calls to the source SDK appear anywhere in this project. If you ' +\n \"haven't installed PostHog yet, you don't need this command — run \" +\n '`npx @posthog/wizard@latest` to add PostHog from scratch.',\n },\n];\n\n/**\n * Map each `--product=<id>` choice to the context-mill skill ID that handles\n * it. Adding a variant: drop a new row here. The CLI `choices` and the\n * runtime lookup both read from this map, so the two stay in sync.\n */\nconst PRODUCT_TO_SKILL_ID = {\n statsig: 'migrate-statsig',\n} as const;\n\ntype MigrateProduct = keyof typeof PRODUCT_TO_SKILL_ID;\nconst MIGRATE_PRODUCTS = Object.keys(PRODUCT_TO_SKILL_ID) as MigrateProduct[];\n\nexport const migrationConfig: ProgramConfig = {\n command: 'migrate',\n description: 'Migrate to PostHog from another analytics provider',\n id: 'migration',\n skillId: PRODUCT_TO_SKILL_ID.statsig,\n steps: MIGRATION_PROGRAM,\n reportFile: MIGRATION_REPORT_FILE,\n getContentBlocks,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n cliOptions: {\n product: {\n describe: 'Source SDK to migrate from',\n type: 'string',\n choices: MIGRATE_PRODUCTS,\n demandOption: true,\n },\n },\n mapCliOptions: (argv) => ({\n skillId: PRODUCT_TO_SKILL_ID[argv.product as MigrateProduct],\n }),\n run: {\n skillId: PRODUCT_TO_SKILL_ID.statsig,\n integrationLabel: 'migration',\n customPrompt: () =>\n 'Migrate this project from its existing third-party analytics, ' +\n 'feature-flag, and observability tools to PostHog. Run the `migrate` ' +\n 'skill end-to-end: follow the step chain starting at ' +\n 'references/1-presence.md. Only replace existing source-SDK call sites ' +\n 'with PostHog equivalents — make zero unrelated changes and no ' +\n `net-new instrumentation. The final report is written to ./${MIGRATION_REPORT_FILE}.`,\n successMessage: `Migration complete! View the report at ./${MIGRATION_REPORT_FILE}`,\n reportFile: MIGRATION_REPORT_FILE,\n docsUrl: '',\n spinnerMessage: 'Migrating to PostHog...',\n estimatedDurationMinutes: 8,\n abortCases: MIGRATION_ABORT_CASES,\n },\n requires: ['posthog-integration'],\n};\n\nexport { MIGRATION_PROGRAM } from './steps.js';\n","/**\n * Source maps upload prerequisite detection.\n *\n * Scans the project for signals that identify the platform and build system,\n * then maps to one of the context-mill `error-tracking-upload-source-maps-*`\n * skill variants. Results are written to frameworkContext for the intro\n * screen to render and for the agent prompt to consume.\n */\n\nimport type { Dirent } from 'fs';\nimport { readFileSync, readdirSync, existsSync, statSync } from 'fs';\nimport { join, relative } from 'path';\nimport { IGNORED_DIRS } from '@utils/file-utils';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\n\n/**\n * Skill variants published under the `error-tracking-upload-source-maps`\n * category in context-mill. The agent loads\n * `error-tracking-upload-source-maps-<variant>`.\n */\nexport type SkillVariant =\n | 'web'\n | 'nextjs'\n | 'node'\n | 'react'\n | 'angular'\n | 'nuxt'\n | 'react-native'\n | 'android'\n | 'flutter'\n | 'ios'\n | 'vite'\n | 'webpack'\n | 'rollup';\n\nconst DISPLAY_NAME: Record<SkillVariant, string> = {\n web: 'Web (JavaScript)',\n nextjs: 'Next.js',\n node: 'Node.js',\n react: 'React',\n angular: 'Angular',\n nuxt: 'Nuxt',\n 'react-native': 'React Native',\n android: 'Android',\n flutter: 'Flutter',\n ios: 'iOS',\n vite: 'Vite',\n webpack: 'Webpack',\n rollup: 'Rollup',\n};\n\nconst POSTHOG_SDKS = [\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n];\n\n/**\n * Structured detection errors. The screen renders each kind into JSX\n * with proper formatting — keeps error data separate from presentation.\n */\nexport type SourceMapsDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-project-files' }\n | { kind: 'unsupported-platform'; detected: string }\n | { kind: 'no-posthog-sdk'; platform: SkillVariant };\n\n/** `[ABORT] <reason>` cases the source maps skill can emit. */\nexport const SOURCE_MAPS_ABORT_CASES: AbortCase[] = [\n {\n match: /^no posthog sdk detected$/i,\n message: 'No PostHog SDK detected',\n body:\n 'The agent could not find a PostHog SDK in your project. ' +\n 'Source map upload requires the SDK to already be installed so it can ' +\n 'report errors. Run `npx @posthog/wizard` first to install the SDK.',\n docsUrl: 'https://posthog.com/docs/error-tracking',\n },\n {\n match: /^build command not found$/i,\n message: 'Build command not found',\n body:\n 'The agent could not identify how to build your project. Source map ' +\n 'upload runs as part of the production build. Add a build script to ' +\n 'your project and run this wizard again.',\n docsUrl: 'https://posthog.com/docs/error-tracking/upload-source-maps',\n },\n];\n\n// ── File / dependency probes ─────────────────────────────────────────\n\ninterface ProjectSignals {\n packageJsons: Array<{ path: string; deps: Set<string> }>;\n hasXcodeProject: boolean;\n hasPodfile: boolean;\n hasSwiftPackage: boolean;\n hasGradle: boolean;\n hasPubspec: boolean;\n scannedFileCount: number;\n}\n\nfunction collectSignals(installDir: string, maxDepth = 3): ProjectSignals {\n const signals: ProjectSignals = {\n packageJsons: [],\n hasXcodeProject: false,\n hasPodfile: false,\n hasSwiftPackage: false,\n hasGradle: false,\n hasPubspec: false,\n scannedFileCount: 0,\n };\n\n function scan(dir: string, depth: number): void {\n if (depth > maxDepth) return;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.name !== '.') continue;\n if (IGNORED_DIRS.has(entry.name)) continue;\n\n const fullPath = join(dir, entry.name);\n\n if (entry.isFile()) {\n signals.scannedFileCount += 1;\n if (entry.name === 'package.json') {\n try {\n const pkg = JSON.parse(readFileSync(fullPath, 'utf-8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const deps = new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n signals.packageJsons.push({\n path: relative(installDir, fullPath) || 'package.json',\n deps,\n });\n } catch {\n // skip malformed package.json\n }\n } else if (entry.name === 'Podfile') {\n signals.hasPodfile = true;\n } else if (entry.name === 'Package.swift') {\n signals.hasSwiftPackage = true;\n } else if (entry.name === 'pubspec.yaml') {\n signals.hasPubspec = true;\n } else if (\n entry.name === 'build.gradle' ||\n entry.name === 'build.gradle.kts' ||\n entry.name === 'settings.gradle' ||\n entry.name === 'settings.gradle.kts'\n ) {\n signals.hasGradle = true;\n }\n } else if (entry.isDirectory()) {\n if (entry.name.endsWith('.xcodeproj')) {\n signals.hasXcodeProject = true;\n } else {\n scan(fullPath, depth + 1);\n }\n }\n }\n }\n\n scan(installDir, 0);\n return signals;\n}\n\n// ── Skill selection ──────────────────────────────────────────────────\n\nfunction pickJsVariant(deps: Set<string>): SkillVariant {\n // Opinionated full-stack frameworks first — they own their build pipeline\n // and have dedicated skill variants, so bundler detection underneath\n // them is irrelevant.\n if (deps.has('react-native')) return 'react-native';\n if (deps.has('nuxt')) return 'nuxt';\n if (deps.has('next')) return 'nextjs';\n if (deps.has('@angular/core')) return 'angular';\n // Bundlers next — prefer these over the bare `react` variant because\n // their skills are simpler (one bundler-plugin config) than wiring\n // posthog-cli into an arbitrary React setup.\n if (deps.has('vite')) return 'vite';\n if (deps.has('webpack')) return 'webpack';\n if (deps.has('rollup')) return 'rollup';\n // Plain React with no recognised bundler.\n if (deps.has('react')) return 'react';\n // Server-only Node project\n if (deps.has('posthog-node')) return 'node';\n // Fallback: generic web\n return 'web';\n}\n\nfunction selectVariant(signals: ProjectSignals): SkillVariant | null {\n // Mobile / native first — they don't coexist with JS bundlers in the\n // detection signals we look at.\n if (signals.hasPubspec) return 'flutter';\n if (signals.hasXcodeProject || signals.hasPodfile || signals.hasSwiftPackage)\n return 'ios';\n if (signals.hasGradle) return 'android';\n\n if (signals.packageJsons.length > 0) {\n // Union all deps across package.json files (covers monorepos)\n const allDeps = new Set<string>();\n for (const pkg of signals.packageJsons) {\n for (const dep of pkg.deps) allDeps.add(dep);\n }\n return pickJsVariant(allDeps);\n }\n\n return null;\n}\n\nfunction hasPostHogSdk(signals: ProjectSignals): boolean {\n for (const pkg of signals.packageJsons) {\n for (const sdk of POSTHOG_SDKS) {\n if (pkg.deps.has(sdk)) return true;\n }\n }\n // For native platforms the PostHog SDK lives outside package.json and\n // is detected by the agent during the skill run. Assume present here.\n return (\n signals.hasXcodeProject ||\n signals.hasPodfile ||\n signals.hasSwiftPackage ||\n signals.hasGradle ||\n signals.hasPubspec\n );\n}\n\n// ── Entry point ──────────────────────────────────────────────────────\n\nexport const SOURCE_MAPS_CONTEXT_KEYS = {\n skillVariant: 'sourceMapsSkillVariant',\n displayName: 'sourceMapsDisplayName',\n packagePaths: 'sourceMapsPackagePaths',\n detectError: 'detectError',\n} as const;\n\n/**\n * Scan `session.installDir` for platform / build-system signals. Writes\n * detection results into frameworkContext via the callback — either the\n * picked skill variant + display name, or a `SourceMapsDetectError`.\n *\n * The skill install happens later in the agent run, not here. This step\n * only picks which variant the prompt should ask the agent to load.\n */\nexport function detectSourceMapsPrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: SourceMapsDetectError) =>\n setFrameworkContext(SOURCE_MAPS_CONTEXT_KEYS.detectError, error);\n\n const installDir = session.installDir;\n\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n const signals = collectSignals(installDir);\n const variant = selectVariant(signals);\n\n // This program currently targets JS-like stacks only. Avoid selecting native\n // platforms until dedicated skill variants are available.\n if (\n variant &&\n ['react-native', 'flutter', 'ios', 'android'].includes(variant)\n ) {\n fail({ kind: 'unsupported-platform', detected: variant });\n return;\n }\n\n if (!variant) {\n if (signals.scannedFileCount === 0) {\n fail({ kind: 'no-project-files' });\n } else {\n fail({ kind: 'unsupported-platform', detected: 'unknown' });\n }\n return;\n }\n\n if (!hasPostHogSdk(signals)) {\n fail({ kind: 'no-posthog-sdk', platform: variant });\n return;\n }\n\n setFrameworkContext(SOURCE_MAPS_CONTEXT_KEYS.skillVariant, variant);\n setFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.displayName,\n DISPLAY_NAME[variant],\n );\n setFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.packagePaths,\n signals.packageJsons.map((p) => p.path),\n );\n}\n\nexport { DISPLAY_NAME as VARIANT_DISPLAY_NAME };\n","/**\n * Error tracking source maps upload program step list.\n *\n * Detection runs headless via onReady, then the user sees a custom intro\n * showing the picked skill variant. Auth → agent run → outro mirrors the\n * other programs.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { RunPhase } from '@lib/wizard-session';\nimport {\n evaluateWizardReadiness,\n WizardReadiness,\n SIGNUP_WIZARD_READINESS_CONFIG,\n getBlockingServiceKeys,\n} from '@lib/health-checks/readiness';\nimport { detectSourceMapsPrerequisites } from './detect.js';\n\nfunction healthCheckReady(session: WizardSession): boolean {\n if (!session.readinessResult) return false;\n\n if (session.signup) {\n const hardBlocking = getBlockingServiceKeys(\n session.readinessResult.health,\n SIGNUP_WIZARD_READINESS_CONFIG,\n );\n const defaultBlocking = getBlockingServiceKeys(\n session.readinessResult.health,\n );\n if (hardBlocking.length === 0 && defaultBlocking.length === 0) return true;\n return session.outageDismissed;\n }\n\n if (session.readinessResult.decision === WizardReadiness.No) {\n return session.outageDismissed;\n }\n return true;\n}\n\nexport const ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting platform',\n // Headless: scans for platform / build-system signals and picks the\n // matching context-mill skill variant. Writes either the variant or\n // a detectError to frameworkContext.\n onReady: (ctx) =>\n detectSourceMapsPrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'source-maps-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'health-check',\n label: 'Health check',\n screenId: 'health-check',\n gate: healthCheckReady,\n onInit: (ctx) => {\n evaluateWizardReadiness()\n .then((readiness) => {\n ctx.setReadinessResult(readiness);\n })\n .catch(() => {\n ctx.setReadinessResult({\n decision: WizardReadiness.Yes,\n health: {} as never,\n reasons: [],\n });\n });\n },\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Upload source maps',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'source-maps-outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","import { AgentSignals } from '@lib/agent/agent-interface';\nimport type { SkillVariant } from './detect.js';\n\nexport type SourceMapsUploadPromptParams = {\n displayName: string | undefined;\n variant: SkillVariant;\n skillId: string;\n projectId: number;\n host: string;\n settingsUrl: string;\n uiHost: string;\n};\n\nexport const SOURCE_MAPS_DETECTION_FAILED_PROMPT = `Detection did not pick a source maps skill variant for this project.\nEmit: ${AgentSignals.ABORT} unsupported-platform\nThen halt.`;\n\nexport function buildSourceMapsUploadPrompt(\n params: SourceMapsUploadPromptParams,\n): string {\n const {\n displayName,\n variant,\n skillId,\n projectId,\n host,\n settingsUrl,\n uiHost,\n } = params;\n const platformLabel = displayName ?? variant;\n\n return `You are wiring up PostHog Error Tracking source map upload for this ${platformLabel} project.\n\nProject context:\n- PostHog Project ID: ${projectId}\n- PostHog Host: ${host}\n- Detected platform: ${platformLabel}\n- Skill to use: ${skillId}\n- Personal API keys settings page: ${settingsUrl}\n\nThe skill you install in STEP 2 is the source of truth for the HOW of every\nstep: its \"## Steps\" section has an overview, tips and per-technology\nexamples for each named step, and its reference files carry the exact\nper-framework API. The STEPS below give the order, the conditionals, and the\nwizard-specific mechanics (which MCP tool to call, signals to emit) — read\nthe matching skill step (named in parentheses) before doing the work, and do\nnot invent steps the skill doesn't describe.\n\nFollow these steps IN ORDER. Do not skip or reorder.\n\nYour FIRST message must contain ONLY parallel tool calls, in this order:\n - the STEP 1 wizard_ask call FIRST — tool calls execute as they stream,\n so this puts the API-key prompt in front of the user within seconds —\n then\n - one TaskCreate call PER task below, all in this same message (the tool\n takes a single task per call). The TUI shows only the subject, so keep\n every description to a few words — never a sentence.\nDo not read files, explore the project, or write any text first, and keep\nany thinking before the calls to a single short sentence.\n\nUse exactly these tasks, in this order — do not collapse, rename, or omit\nany of them. Getting the API key is NOT a task — its prompt is already on\nscreen by the time the list renders:\n 1. Install source maps skill\n 2. Apply build-config changes (per skill)\n 3. Make credentials readable at build time\n 4. Write keys to .env\n 5. Identify build & run commands\n 6. Set up CI for auto-upload\n 7. Test the local setup\n 8. Summarise & hand off\nDrive the list with TaskUpdate — mark a task in_progress when you start it\nand completed when done. ALWAYS keep task 7 (\"Test the local setup\") in the\nlist even if the user declines it in STEP 8: mark it completed rather than\ndeleting it, so the user can see it was offered.\n\nSTEP 1 — Get a personal API key from the user. (skill: \"Get a personal API key\")\n This wizard_ask call ships in your FIRST message, per the rule above.\n The wizard cannot mint keys — never call the PostHog API or any tool to\n create one. Ask the user with the wizard_ask MCP tool; you receive the\n answer as a vaulted secretRef (never the raw value), which you reuse in\n STEP 5:\n {\n id: \"api-key\",\n prompt: \"Paste your PostHog personal API key below.\\\\n\\\\nDon't have one yet? Create one here:\\\\n${settingsUrl}\\\\n\\\\nWhen creating the key, choose the 'Source map upload' preset, then come back and paste it here.\",\n kind: \"text\",\n sensitive: true\n }\n Keep the \\\\n line breaks exactly as written — Ink's <Text> renders them\n as separate lines. The answer is { secretRef: \"secret:...\" }.\n If wizard_ask is unavailable (CI / non-interactive), emit\n ${AgentSignals.ABORT} requires-interactive-mode and halt.\n\nSTEP 2 — Install the skill.\n Call install_skill (wizard-tools MCP server) with skillId \"${skillId}\".\n Do NOT run shell commands to install skills. Then read the installed\n SKILL.md and its reference files — they drive STEPS 3-9.\n If install fails, emit ${AgentSignals.ERROR_RESOURCE_MISSING} skill ${skillId} could not be installed.\n\nSTEP 3 — Apply build-config changes. (skill: \"Apply build-config changes\")\n Make the bundler / build-config changes the skill's step instructs. The\n skill and its reference are the source of truth for this platform.\n\nSTEP 4 — Make the credentials readable at build time. (skill: \"Make credentials available at build time\")\n Follow the skill's step. Wizard-specific: if it calls for a loader (e.g.\n \\`dotenv\\`), install it SILENTLY — do NOT ask the user or call wizard_ask.\n Skip this step entirely if the platform already auto-loads .env.\n\nSTEP 5 — Write the credentials to the env file. (skill: \"Write credentials to the env file\")\n Use the wizard-tools MCP server. Reuse the env file the skill tells you to\n pick — the prerequisite PostHog integration usually already wrote\n POSTHOG_* vars to one, so seed your keys alongside them.\n - First call check_env_keys on that file (returns present/absent, never\n values — don't read the file directly).\n - Then call set_env_values, passing the STEP 1 secretRef as a value\n object, not a literal string:\n values: {\n \"POSTHOG_CLI_API_KEY\": { secretRef: \"<the ref from STEP 1>\" },\n \"POSTHOG_CLI_PROJECT_ID\": \"${projectId}\",\n \"POSTHOG_CLI_HOST\": \"${host}\"\n }\n Variable names follow the skill's per-uploader conventions. The wizard\n resolves the ref locally before writing, so you never see the key value.\n\nSTEP 6 — Identify the build AND run commands. (skill: \"Identify the build and run commands\")\n Per the skill, resolve the production BUILD command and the RUN command\n for THIS project (use detect_package_manager for the package manager). Do\n NOT run either yourself — the user runs them. If you cannot identify a\n build command, emit ${AgentSignals.ABORT} build command not found.\n\nSTEP 7 — Set up CI for automatic uploads. (skill: \"Set up CI for automatic uploads\")\n Source maps only upload when the production build runs, so the build's\n CI/CD must carry the same upload credentials you wrote in STEP 5. Do this\n step without asking — there is no opt-in question for it. Follow the\n skill's \"Set up CI for automatic uploads\" step — it is the source of\n truth for tracing where the production build runs and wiring the\n credentials through every layer, whatever the CI provider.\n Wizard-specific rules on top:\n - Trace the deploy path by reading the project's files — do NOT ask the\n user, and do NOT invent config that isn't there.\n - Carry every manual follow-up the skill has you hand off (secrets the\n user must create, an untraceable build path) into STEP 9.\n\nSTEP 8 — Offer to test the local setup. (skill: \"Test the local setup\")\n Call wizard_ask:\n {\n id: \"test-affordance\",\n prompt: \"Want me to help you test your local setup? I'll add a temporary test button (or route) to your app so you can confirm errors show up in Error Tracking with readable stack traces after your next build. I'll remove it once you've confirmed it works.\",\n kind: \"single\",\n options: [\n { label: \"Yes, help me test it\", value: \"yes\" },\n { label: \"No, I'll test on my own later\", value: \"no\" }\n ]\n }\n\n If \"no\", skip to STEP 9.\n\n If \"yes\", follow the skill's \"Test the local setup\" step for the\n platform-appropriate affordance, the captureException shape, the\n placement, and the read-before-edit / always-revert rules. Then pause for\n the user with wizard_ask, baking the EXACT build and run commands from\n STEP 6 (and the exact button label / route) into the prompt as literal,\n copy-pasteable steps. Separate each numbered step with \\\\n\\\\n so the TUI\n renders them as distinct lines:\n {\n id: \"test-done\",\n prompt: \"1) Run \\`<your detected build command>\\` to upload source maps and build the app with the test affordance.\\\\n\\\\n2) Start the app with \\`<your detected run command>\\`, then click the \\\\\"<your test button label>\\\\\" button (or hit \\`<your test route>\\`).\\\\n\\\\n3) Open Error Tracking in PostHog (${uiHost}/project/${projectId}/error_tracking) and confirm the test error appears with a source-resolved stack trace pointing at real source files (not minified bundle paths).\\\\n\\\\nWhen you're done, select Continue and I'll revert the test code.\",\n kind: \"single\",\n options: [{ label: \"Continue (revert test code)\", value: \"continue\" }]\n }\n After the user continues, revert the test code per the skill's rules and\n surface any failure in STEP 9.\n\nSTEP 9 — Summarise and hand off. (skill: \"Verify and hand off\")\n Follow the skill's \"Verify and hand off\" step. The Symbol sets page for\n this project — where the user confirms the upload landed — is:\n ${uiHost}/project/${projectId}/error_tracking/configuration\n`;\n}\n","/**\n * Source-maps learn-deck — the narrative played in the run screen's left\n * pane (LearnCard) while the agent wires source-map upload into the build.\n *\n * It educates the user on what source maps are and why uploading them\n * matters, built around a before/after stack-trace contrast: a minified\n * production trace nobody can read, then the same trace resolved back to\n * real source. Program-owned; wired onto the program's getContentBlocks.\n *\n * Lines stay narrow (~36 cols) because this renders in the left half of a\n * split pane — see LearnCard's paneWidth math.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { WizardStore } from '@ui/tui/store';\nimport { TextRevealMode } from '@ui/tui/primitives/TextBlock';\nimport {\n isClearBlock,\n type ContentBlock,\n} from '@ui/tui/primitives/content-types';\nimport { StatusPeekTrigger } from '@ui/tui/components/StatusPeekTrigger';\n\n/**\n * Per-slide dwell multiplier. Each block stays on screen for `pause * SLIDE_PACE`\n * ms after it finishes animating, before the deck advances. Bump this single\n * knob to give every slide more reading time. Clear (page-break) blocks are\n * left untouched so the blank gap between slides stays snappy.\n */\nconst SLIDE_PACE = 1.5;\n\nconst withPace = (block: ContentBlock): ContentBlock => {\n if (typeof block === 'string' || isClearBlock(block) || block.pause == null) {\n return block;\n }\n return { ...block, pause: Math.round(block.pause * SLIDE_PACE) };\n};\n\n/** Apply the dwell multiplier to every block in a deck. */\nconst pace = (blocks: ContentBlock[]): ContentBlock[] => blocks.map(withPace);\n\n/**\n * A minified production stack trace — the problem source maps solve. Framed as\n * a labelled, muted example (no error-red ✘) so a glance reads it as\n * illustrative content, not as the wizard itself having errored mid-run.\n */\nconst MINIFIED_TRACE: ContentBlock = {\n type: 'lines',\n interval: 400,\n pause: 7000,\n lines: [\n <Text dimColor>{'example — minified production trace'}</Text>,\n <Text color={Colors.muted}>{' TypeError: cart is undefined'}</Text>,\n <Text dimColor>{' at t.min.js:1:48213'}</Text>,\n <Text dimColor>{' at t.min.js:1:9402'}</Text>,\n <Text dimColor>{' at t.min.js:1:71150'}</Text>,\n ],\n};\n\n/** The same trace, resolved through uploaded source maps. */\nconst RESOLVED_TRACE: ContentBlock = {\n type: 'lines',\n interval: 400,\n pause: 8000,\n lines: [\n <Text dimColor>{'example — resolved with source maps'}</Text>,\n <Text color={Colors.success}>{' ✔ TypeError: cart is undefined'}</Text>,\n <Text>\n <Text dimColor>{' at '}</Text>\n <Text color=\"cyan\">Cart.tsx:42</Text>\n <Text dimColor>{' loadCart'}</Text>\n </Text>,\n <Text>\n <Text dimColor>{' at '}</Text>\n <Text color=\"cyan\">App.tsx:88</Text>\n <Text dimColor>{' render'}</Text>\n </Text>,\n <Text>\n <Text dimColor>{' at '}</Text>\n <Text color=\"cyan\">index.tsx:5</Text>\n <Text dimColor>{' main'}</Text>\n </Text>,\n ],\n};\n\n/**\n * How a bundle is tied to its map: PostHog injects a chunk-ID marker into the\n * built JS and stamps the matching source map with the same ID.\n */\nconst CHUNK_ID_LINK: ContentBlock = {\n type: 'lines',\n interval: 450,\n pause: 7500,\n lines: [\n <Text dimColor>app.min.js</Text>,\n <Text dimColor>{' …minified code…'}</Text>,\n <Text>\n <Text color=\"cyan\">{' //# chunkId=a1b2c3d4'}</Text>\n <Text dimColor>{' ← injected'}</Text>\n </Text>,\n <Text dimColor>{' ↕ matched by id'}</Text>,\n <Text>\n <Text dimColor>app.min.js.map</Text>\n <Text dimColor>{' ← uploaded'}</Text>\n </Text>,\n ],\n};\n\n/** Many similar exceptions collapse into a single issue. */\nconst GROUPING: ContentBlock = {\n type: 'lines',\n interval: 450,\n pause: 7000,\n lines: [\n <Text dimColor>{'exception ─┐'}</Text>,\n <Text>\n <Text dimColor>{'exception ─┼──→ '}</Text>\n <Text color={Colors.accent} bold>\n 1 issue\n </Text>\n </Text>,\n <Text dimColor>{'exception ─┘'}</Text>,\n ],\n};\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] =>\n pace([\n {\n content: 'Welcome.',\n pause: 3000,\n mode: TextRevealMode.Typewriter,\n animationInterval: 160,\n },\n\n {\n content: \"I'm wiring PostHog Error Tracking into your build.\",\n pause: 5000,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'When you ship to production, your code gets minified.',\n pause: 5000,\n },\n {\n content: 'Thousands of readable lines collapse into one dense bundle.',\n pause: 5000,\n },\n {\n content: 'So a thrown error gives you a stack trace like this:',\n pause: 2000,\n },\n\n MINIFIED_TRACE,\n\n { content: 'Just offsets into a file no human can read.', pause: 5000 },\n\n { type: 'clear', pause: 1500 },\n\n { content: 'Source maps are the key.', pause: 3500 },\n {\n content:\n 'They map every position in that bundle back to your original source — the real file, line, and function.',\n pause: 6000,\n },\n {\n content:\n \"Right now I'm hooking source-map generation and upload into your build, tied to each release you ship.\",\n pause: 6000,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'But how does PostHog know which map belongs to which build?',\n pause: 4500,\n },\n {\n content:\n 'During the build, it injects a unique chunk ID into each bundle:',\n pause: 2500,\n },\n\n CHUNK_ID_LINK,\n\n {\n content:\n 'The matching source map is stamped with that same ID before it ships to PostHog.',\n pause: 6000,\n },\n {\n content:\n 'When an error comes in, PostHog reads the chunk ID off the bundle, finds the map with the exact same ID, and uses it to map each frame back to your source — even for a release you shipped weeks ago.',\n pause: 8000,\n },\n\n { type: 'clear', pause: 1500 },\n\n { content: 'So that same error becomes:', pause: 2000 },\n\n RESOLVED_TRACE,\n\n {\n content: 'Readable stack traces, straight from production.',\n pause: 5000,\n },\n {\n content: 'You debug a live error like it happened on your own machine.',\n pause: 6000,\n },\n\n { type: 'clear', pause: 1500 },\n\n { content: 'Zooming out — this is how Error Tracking works.', pause: 4000 },\n {\n content: 'Every error your app throws is captured as an exception.',\n pause: 5000,\n },\n {\n content: 'PostHog groups similar exceptions into a single issue:',\n pause: 2500,\n },\n\n GROUPING,\n\n {\n content:\n 'So a bug that fires ten thousand times is one issue to triage — not ten thousand alerts.',\n pause: 6500,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'And this is where source maps earn their keep again.',\n pause: 4500,\n },\n {\n content:\n 'Grouping reads the stack trace. Minified frames all look alike — so unrelated crashes get merged, and one real bug scatters across many issues.',\n pause: 8000,\n },\n {\n content:\n 'With source maps, PostHog groups on your real frames — so each distinct bug lands as one clean issue.',\n pause: 7000,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n pause: 5000,\n persist: true,\n content: <StatusPeekTrigger store={store} />,\n },\n {\n pause: 90000,\n content: (\n <Text>\n Press{' '}\n <Text color={Colors.accent} bold>\n S\n </Text>{' '}\n to follow along — or sit tight, I'll let you know when it's done.\n </Text>\n ),\n },\n ]);\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { OutroKind } from '@lib/wizard-session';\nimport { ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM } from './steps.js';\nimport {\n buildSourceMapsUploadPrompt,\n SOURCE_MAPS_DETECTION_FAILED_PROMPT,\n} from './prompt.js';\nimport {\n SOURCE_MAPS_ABORT_CASES,\n SOURCE_MAPS_CONTEXT_KEYS,\n type SkillVariant,\n} from './detect.js';\nimport { getContentBlocks } from './content/index.js';\nimport { getUiHostFromHost } from '@utils/urls';\n\nconst REPORT_FILE = 'posthog-source-maps-report.md';\nconst DOCS_URL = 'https://posthog.com/docs/error-tracking/upload-source-maps';\n\nexport const errorTrackingUploadSourceMapsConfig: ProgramConfig = {\n command: 'upload-source-maps',\n description: 'Upload source maps to PostHog Error Tracking',\n id: 'error-tracking-upload-source-maps',\n requiresAi: true,\n steps: ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM,\n reportFile: REPORT_FILE,\n getContentBlocks,\n requires: ['posthog-integration'],\n\n run: (session: WizardSession): Promise<ProgramRun> => {\n const variant = session.frameworkContext[\n SOURCE_MAPS_CONTEXT_KEYS.skillVariant\n ] as SkillVariant | undefined;\n const displayName = session.frameworkContext[\n SOURCE_MAPS_CONTEXT_KEYS.displayName\n ] as string | undefined;\n\n const skillId = variant\n ? `error-tracking-upload-source-maps-${variant}`\n : undefined;\n\n return Promise.resolve({\n integrationLabel: 'error-tracking-upload-source-maps',\n // Skill is installed by the agent (after the API-key choice is made)\n // rather than pre-installed by the runner, so leave skillId unset.\n successMessage: 'Source maps wired up!',\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Wiring up source maps...',\n estimatedDurationMinutes: 3,\n abortCases: SOURCE_MAPS_ABORT_CASES,\n // The flow parks on wizard_ask while the user does slow work — create\n // a personal API key in the browser (STEP 1), or run a production\n // build, trigger the test error, and check Error Tracking (STEP 8).\n // The 5-minute default cancels the question mid-task and the agent\n // wraps up to the outro, so give these answers half an hour.\n askTimeoutMs: 30 * 60 * 1000,\n\n customPrompt: (ctx) => {\n if (!skillId || !variant) {\n // Detection failed but the user got past the intro somehow.\n // Tell the agent to abort with a structured signal so the runner\n // renders a friendly outro.\n return SOURCE_MAPS_DETECTION_FAILED_PROMPT;\n }\n\n const uiHost = getUiHostFromHost(ctx.host).replace(/\\/$/, '');\n\n return buildSourceMapsUploadPrompt({\n displayName,\n variant,\n skillId,\n projectId: ctx.projectId,\n host: ctx.host,\n settingsUrl: `${uiHost}/project/${ctx.projectId}/settings/user-api-keys`,\n uiHost,\n });\n },\n\n postRun: (sess) => {\n // Stash a hint for the outro about what variant we shipped.\n if (variant) {\n sess.frameworkContext['sourceMapsCompletedVariant'] = variant;\n }\n return Promise.resolve();\n },\n\n buildOutroData: () => {\n // SourceMapsOutroScreen renders static \"what we did + how it works\"\n // guidance, so no per-run `changes` list is needed here.\n return {\n kind: OutroKind.Success as const,\n message: 'Source maps wired up!',\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n };\n },\n });\n },\n};\n\nexport { ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM } from './steps.js';\nexport {\n detectSourceMapsPrerequisites,\n SOURCE_MAPS_ABORT_CASES,\n SOURCE_MAPS_CONTEXT_KEYS,\n VARIANT_DISPLAY_NAME,\n type SkillVariant,\n type SourceMapsDetectError,\n} from './detect.js';\n","/**\n * MCP add / remove / tutorial programs.\n *\n * None of these run the agent pipeline — they're TUI-only flows invoked\n * by the `mcp add` / `mcp remove` / `mcp tutorial` subcommands in\n * bin.ts. They live in the program registry so the screen sequence is\n * derived alongside every other program (no special-cases in\n * screen-sequences.ts).\n */\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport { McpOutcome } from '@lib/wizard-session';\n\nexport const mcpAddConfig: ProgramConfig = {\n id: 'mcp-add',\n requiresAi: false,\n description: 'Add PostHog MCP server to supported clients',\n steps: [\n {\n id: 'mcp-add',\n label: 'Add MCP server',\n screenId: 'mcp-add',\n isComplete: (s) => s.mcpComplete,\n },\n {\n id: 'mcp-suggested-prompts',\n label: 'Suggested prompts',\n screenId: 'mcp-suggested-prompts',\n // Only render after a successful install — no-clients, skipped,\n // and failed outcomes go straight to program end. The screen has\n // no value without a working MCP for the user to log in against.\n show: (s) => s.mcpOutcome === McpOutcome.Installed,\n isComplete: (s) => s.mcpSuggestedPromptsDismissed,\n },\n {\n id: 'slack-connect',\n label: 'Connect Slack',\n screenId: 'slack-connect',\n // Gate on the same successful-install signal as the tutorial step,\n // so the \"what's next\" Slack prompt only appears once the user has\n // a working MCP. No-clients / skipped / failed installs end here.\n show: (s) => s.mcpOutcome === McpOutcome.Installed,\n isComplete: (s) => s.slackStepDismissed,\n },\n ],\n};\n\n/**\n * `wizard mcp remove` — single-step uninstall flow.\n *\n * DO NOT append `mcp-suggested-prompts` (or any other tutorial-shaped\n * step) here. A user who just removed MCP is opting OUT of the agent\n * having access to PostHog; immediately pivoting into a tutorial that\n * asks them to log in and try prompts is wrong on intent and confusing\n * on UX. The screen also reads `session.mcpInstalledClients` for its\n * Choose-phase copy (\"MCP is installed for X\") — that array is empty\n * post-remove, so the copy would be a lie.\n *\n * If you want a \"did you mean to keep it?\" confirmation, build that as\n * a screen earlier in this program — don't reuse the tutorial.\n */\nexport const mcpRemoveConfig: ProgramConfig = {\n id: 'mcp-remove',\n requiresAi: false,\n description: 'Remove PostHog MCP server from supported clients',\n steps: [\n {\n id: 'mcp-remove',\n label: 'Remove MCP server',\n screenId: 'mcp-remove',\n isComplete: (s) => s.mcpComplete,\n },\n ],\n};\n\n/**\n * Standalone tutorial flow — boots directly into the Choose phase of\n * McpSuggestedPromptsScreen without going through MCP install first.\n * Useful for users who already installed MCP and want to revisit the\n * tutorial, or anyone who just wants to try the agent against PostHog\n * without touching their IDE config.\n *\n * The screen handles its own OAuth (via services.performLogin) so this\n * program doesn't pre-populate credentials.\n */\nexport const mcpTutorialConfig: ProgramConfig = {\n id: 'mcp-tutorial',\n requiresAi: false,\n description: 'Try the PostHog MCP with your agent — no install needed',\n steps: [\n {\n id: 'mcp-suggested-prompts',\n label: 'MCP tutorial',\n screenId: 'mcp-suggested-prompts',\n isComplete: (s) => s.mcpSuggestedPromptsDismissed,\n },\n {\n id: 'slack-connect',\n label: 'Connect Slack',\n screenId: 'slack-connect',\n isComplete: (s) => s.slackStepDismissed,\n },\n ],\n};\n","/**\n * Slack connect program — TUI-only flow invoked by `wizard slack`. One\n * step: the same Connect Slack screen the MCP flows end on. OAuth kicks\n * off from `onInit` while the screen renders the auth-wait state; the\n * connected poll starts once credentials land.\n */\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport { getOrAskForProjectData } from '@utils/setup-utils';\nimport { getUI } from '@ui';\nimport { analytics } from '@utils/analytics';\n\nexport const slackConnectConfig: ProgramConfig = {\n id: 'slack',\n description: 'Connect PostHog to your Slack',\n steps: [\n {\n id: 'slack-connect',\n label: 'Connect Slack',\n screenId: 'slack-connect',\n isComplete: (s) => s.slackStepDismissed,\n onInit: loginForSlackConnect,\n },\n ],\n};\n\n/** OAuth for the standalone flow. The screen shows the auth-wait state\n * (and the login URL) until the credentials land in the store. */\nfunction loginForSlackConnect(): void {\n void (async () => {\n try {\n const data = await getOrAskForProjectData({\n signup: false,\n ci: false,\n apiKey: undefined,\n projectId: undefined,\n programId: 'slack',\n });\n const ui = getUI();\n ui.setCredentials({\n accessToken: data.accessToken,\n projectApiKey: data.projectApiKey,\n host: data.host,\n projectId: data.projectId,\n });\n ui.setRoleAtOrganization(data.roleAtOrganization);\n ui.setApiUser(data.user);\n ui.setLoginUrl(null);\n } catch (err) {\n analytics.captureException(\n err instanceof Error ? err : new Error(String(err)),\n { step: 'slack_connect_login' },\n );\n getUI().log.error(\n `Login failed. ${err instanceof Error ? err.message : String(err)}`,\n );\n process.exit(1);\n }\n })();\n}\n","/**\n * Central registry of all wizard programs.\n *\n * Adding a new program:\n * 1. Create src/lib/programs/<name>/ with index.ts exporting a ProgramConfig\n * 2. Import and add it to PROGRAM_REGISTRY below\n * 3. (If custom intro screen) add to src/ui/tui/screen-registry.tsx\n *\n * screen-sequences.ts, store.ts, and bin.ts all derive their wiring from\n * this array — no need to touch those files when adding a program.\n */\n\nimport type { ProgramConfig } from './program-step.js';\nimport { posthogIntegrationConfig } from './posthog-integration/index.js';\nimport { revenueAnalyticsConfig } from './revenue-analytics/index.js';\nimport { auditConfig } from './audit/index.js';\nimport { eventsAuditConfig } from './events-audit/index.js';\nimport { audit3000Config } from './audit-3000/index.js';\nimport { posthogDoctorConfig } from './posthog-doctor/index.js';\nimport { webAnalyticsDoctorConfig } from './web-analytics-doctor/index.js';\nimport { migrationConfig } from './migration/index.js';\nimport { errorTrackingUploadSourceMapsConfig } from './error-tracking-upload-source-maps/index.js';\nimport { AGENT_SKILL_STEPS } from './agent-skill/index.js';\nimport { getContentBlocks as agentSkillContentBlocks } from './agent-skill/content/index.js';\nimport {\n mcpAddConfig,\n mcpRemoveConfig,\n mcpTutorialConfig,\n} from './mcp/index.js';\nimport { slackConnectConfig } from './slack/index.js';\n\n// Generic skill program — invoked when the wizard runs an arbitrary\n// context-mill skill chosen at runtime (session.skillId) rather than a\n// registered named program. No CLI command, no run config.\nconst agentSkillConfig: ProgramConfig = {\n id: 'agent-skill',\n description: 'Run an arbitrary context-mill skill',\n steps: AGENT_SKILL_STEPS,\n getContentBlocks: agentSkillContentBlocks,\n allowedTools: ['Agent'],\n};\n\nexport const PROGRAM_REGISTRY = [\n posthogIntegrationConfig,\n revenueAnalyticsConfig,\n errorTrackingUploadSourceMapsConfig,\n auditConfig,\n eventsAuditConfig,\n audit3000Config,\n posthogDoctorConfig,\n webAnalyticsDoctorConfig,\n migrationConfig,\n agentSkillConfig,\n mcpAddConfig,\n mcpRemoveConfig,\n mcpTutorialConfig,\n slackConnectConfig,\n] as const satisfies readonly ProgramConfig[];\n\n/**\n * Typed program names. Values come from each config's `id`, so there's\n * no parallel string list to keep in sync — adding `Program.Foo` here is\n * just exposing `fooConfig.id` under a friendly name for call sites.\n */\nexport const Program = {\n PostHogIntegration: posthogIntegrationConfig.id,\n RevenueAnalyticsSetup: revenueAnalyticsConfig.id,\n ErrorTrackingUploadSourceMaps: errorTrackingUploadSourceMapsConfig.id,\n Migration: migrationConfig.id,\n Audit: auditConfig.id,\n EventsAudit: eventsAuditConfig.id,\n Audit3000: audit3000Config.id,\n PosthogDoctor: posthogDoctorConfig.id,\n WebAnalyticsDoctor: webAnalyticsDoctorConfig.id,\n AgentSkill: agentSkillConfig.id,\n McpAdd: mcpAddConfig.id,\n McpRemove: mcpRemoveConfig.id,\n McpTutorial: mcpTutorialConfig.id,\n SlackConnect: slackConnectConfig.id,\n} as const;\n\n/** Compile-time union of every registered program id. */\nexport type ProgramId = (typeof PROGRAM_REGISTRY)[number]['id'];\n\n/**\n * Look up a program config by its id. `ProgramId` is a union of every\n * registered id, so the lookup is statically guaranteed to find a match\n * — the `!` is a load-bearing assertion of that invariant, not a hope.\n */\nexport function getProgramConfig(id: ProgramId): ProgramConfig {\n return PROGRAM_REGISTRY.find((c) => c.id === id)!;\n}\n\n/** A program config that is exposed as a CLI subcommand. */\nexport type SubcommandProgram = ProgramConfig & { command: string };\n\n/** All program configs that are exposed as CLI subcommands. */\nexport function getSubcommandPrograms(): SubcommandProgram[] {\n return PROGRAM_REGISTRY.filter(\n (c): c is SubcommandProgram => c.command != null,\n );\n}\n","import type { Arguments } from 'yargs';\nimport { setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\n\nexport const mcpAddCommand: Command = {\n name: 'add',\n description: 'Install PostHog MCP server to supported clients',\n options: {\n local: {\n default: false,\n describe: 'Add local development MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n features: {\n describe: 'Comma-separated list of features to enable (default: all)',\n type: 'string',\n },\n 'api-key': {\n describe: 'PostHog personal API key (phx_xxx) for MCP authentication',\n type: 'string',\n },\n },\n handler: runMcpAdd,\n};\n\nfunction runMcpAdd(argv: Arguments): void {\n const features = parseFeatures(argv.features);\n void (async () => {\n const { readApiKeyFromEnv } = await import('@utils/env-api-key');\n const apiKey = (argv.apiKey as string | undefined) || readApiKeyFromEnv();\n const debug = argv.debug as boolean | undefined;\n const localMcp = argv.local as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.McpAdd);\n tui.store.session = buildSession({\n debug,\n localMcp,\n mcpFeatures: features,\n apiKey,\n });\n } catch (error) {\n if (!isTUIUnavailable(error)) throw error;\n setUI(new LoggingUI());\n const { addMCPServerToClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n await addMCPServerToClientsStep({ local: localMcp, features, apiKey });\n }\n })();\n}\n\n/**\n * Ink throws \"Raw mode is not supported\" when stdin has no TTY (piped input,\n * CI, some IDE terminals). That is the only TUI failure we degrade to\n * LoggingUI for — any other error from the TUI path is a real bug and must\n * surface rather than be silently swallowed.\n */\nfunction isTUIUnavailable(error: unknown): boolean {\n return (\n error instanceof Error && /raw mode is not supported/i.test(error.message)\n );\n}\n\nfunction parseFeatures(raw: unknown): string[] | undefined {\n if (typeof raw !== 'string') return undefined;\n return raw\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n}\n","import type { Arguments } from 'yargs';\nimport { setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\n\nexport const mcpRemoveCommand: Command = {\n name: 'remove',\n description: 'Remove PostHog MCP server from supported clients',\n options: {\n local: {\n default: false,\n describe: 'Remove local development MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n },\n handler: runMcpRemove,\n};\n\nfunction runMcpRemove(argv: Arguments): void {\n void (async () => {\n const debug = argv.debug as boolean | undefined;\n const localMcp = argv.local as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.McpRemove);\n tui.store.session = buildSession({ debug, localMcp });\n } catch {\n setUI(new LoggingUI());\n const { removeMCPServerFromClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n await removeMCPServerFromClientsStep({ local: localMcp });\n }\n })();\n}\n","import type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\n\nexport const mcpTutorialCommand: Command = {\n name: 'tutorial',\n description: 'Try the PostHog MCP with your agent (no install needed)',\n options: {\n local: {\n default: false,\n describe:\n 'Point the tutorial at the local MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n },\n handler: runMcpTutorial,\n};\n\nfunction runMcpTutorial(argv: Arguments): void {\n void (async () => {\n const debug = argv.debug as boolean | undefined;\n const localMcp = argv.local as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.McpTutorial);\n tui.store.session = buildSession({ debug, localMcp });\n } catch (err) {\n // TUI unavailable — the tutorial has no headless fallback.\n setUI(new LoggingUI());\n getUI().log.error(\n `The MCP tutorial requires an interactive terminal. ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n process.exit(1);\n }\n })();\n}\n","import { mcpAddCommand } from './add';\nimport { mcpRemoveCommand } from './remove';\nimport { mcpTutorialCommand } from './tutorial';\nimport type { Command } from '../command';\n\nexport const mcpCommand: Command = {\n name: 'mcp',\n description: 'MCP server management commands',\n children: [mcpAddCommand, mcpRemoveCommand, mcpTutorialCommand],\n};\n","/**\n * `--no-telemetry` flips `telemetry: false` via yargs negation;\n * `POSTHOG_WIZARD_NO_TELEMETRY` is honoured separately so the env-var\n * form documented in the README keeps working.\n */\nexport function resolveNoTelemetry(options: Record<string, unknown>): boolean {\n if (options.telemetry === false) return true;\n const env = process.env.POSTHOG_WIZARD_NO_TELEMETRY;\n if (env == null || env === '') return false;\n const norm = env.toLowerCase();\n return norm !== '0' && norm !== 'false';\n}\n","import { VERSION } from '@lib/version';\nimport { logToFile, getLogFilePath } from '@utils/debug';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { startTUI as StartTUIFn } from '@ui/tui/start-tui';\nimport type { TaskStreamPush as TaskStreamPushClass } from '@lib/task-stream/task-stream-push';\nimport { resolveNoTelemetry } from './resolve-no-telemetry';\nimport { runCleanups } from '@utils/wizard-abort';\n\nconst WIZARD_VERSION = VERSION;\n\n/**\n * Run a full wizard program in the TUI. Handles the full lifecycle: start TUI,\n * build session, run detection, wait for intro gate, execute the\n * agent pipeline, wait for outro dismissal, then exit.\n */\nexport function runWizard(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n let tui: ReturnType<typeof StartTUIFn> | null = null;\n let taskStream: TaskStreamPushClass | null = null;\n let onSignal: (() => void) | null = null;\n let exitInProgress = false;\n\n void (async () => {\n try {\n const installDir = (options.installDir as string) || process.cwd();\n\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession, RunPhase } = await import('@lib/wizard-session');\n const { TaskStreamPush } = await import('@lib/task-stream/index');\n const { PostHogDestination } = await import(\n '@lib/task-stream/destinations/posthog'\n );\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n tui = startTUI(WIZARD_VERSION, config.id as any);\n const activeTui = tui;\n\n const session = buildSession({\n debug: options.debug as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n installDir,\n ci: false,\n signup: options.signup as boolean | undefined,\n apiKey: options.apiKey as string | undefined,\n projectId: options.projectId as string | undefined,\n email: options.email as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n });\n session.programLabel = config.id;\n if (options.skillId) {\n session.skillId = options.skillId as string;\n } else if (config.skillId) {\n session.skillId = config.skillId;\n }\n\n activeTui.store.session = session;\n\n const taskStreamEnabled = !session.noTelemetry;\n taskStream = new TaskStreamPush({\n store: activeTui.store,\n programId: config.id,\n destinations: [\n new PostHogDestination({\n getCredentials: () => activeTui.store.session.credentials,\n onError: (err) => logToFile('[task-stream-push]', err.message),\n }),\n ],\n enabled: taskStreamEnabled,\n });\n const activeStream = taskStream;\n activeStream.attach();\n\n // Flush a terminal-phase push on Ctrl-C so the web app sees the\n // run ended in error rather than hanging on the last \"running\"\n // snapshot.\n let signalled = false;\n onSignal = (): void => {\n if (signalled || exitInProgress) return;\n signalled = true;\n logToFile('[run-wizard] signal received, flushing task stream');\n // Run cleanups synchronously first — settings restore is sync fs work\n // and must complete even if the stream shutdown below times out.\n runCleanups();\n if (activeTui.store.session.runPhase === RunPhase.Running) {\n activeTui.store.setRunPhase(RunPhase.Error);\n }\n void activeStream\n .shutdown(2000)\n .catch((e) =>\n logToFile('[run-wizard] task stream shutdown error on signal:', e),\n )\n .finally(() => {\n try {\n activeTui.unmount();\n } catch {\n // terminal may already be torn down\n }\n process.exit(130);\n });\n };\n process.on('SIGINT', onSignal);\n process.on('SIGTERM', onSignal);\n\n await activeTui.store.runReadyHooks();\n await activeTui.store.getGate('intro');\n await activeTui.store.getGate('health-check');\n\n const skipAgent = config.run == null;\n\n if (skipAgent) {\n const { getOrAskForProjectData } = await import('@utils/setup-utils');\n const { projectApiKey, host, accessToken, projectId } =\n await getOrAskForProjectData({\n signup: session.signup,\n ci: session.ci,\n apiKey: session.apiKey,\n projectId: session.projectId,\n programId: config.id,\n });\n activeTui.store.setCredentials({\n accessToken,\n projectApiKey,\n host,\n projectId,\n });\n } else {\n const { runAgent } = await import('@lib/agent/agent-runner');\n await runAgent(config, activeTui.store.session);\n }\n\n const isDone = (): boolean =>\n skipAgent\n ? activeTui.store.session.outroDismissed\n : activeTui.store.session.skillsComplete;\n\n await new Promise<void>((resolve) => {\n const unsub = activeTui.store.subscribe(() => {\n if (isDone()) {\n unsub();\n resolve();\n }\n });\n if (isDone()) {\n unsub();\n resolve();\n }\n });\n\n exitInProgress = true;\n await activeStream.shutdown(2000);\n process.off('SIGINT', onSignal);\n process.off('SIGTERM', onSignal);\n activeTui.unmount();\n process.exit(0);\n } catch (err) {\n // File-log first — the cleanup below can throw or exit.\n logToFile('[run-wizard] FATAL:', err);\n // Run cleanups before anything async so settings are restored even if\n // the stream shutdown hangs.\n runCleanups();\n // The task-stream debounce timer keeps the event loop alive, so\n // we have to drain it before exiting on the error path.\n exitInProgress = true;\n if (onSignal) {\n process.off('SIGINT', onSignal);\n process.off('SIGTERM', onSignal);\n }\n if (taskStream) {\n try {\n await taskStream.shutdown(2000);\n } catch {\n // ignore\n }\n }\n if (tui) {\n try {\n tui.unmount();\n } catch {\n // ignore\n }\n }\n // Print after unmount — anything printed into the alt screen is wiped.\n // eslint-disable-next-line no-console\n console.error('Wizard run failed:', err);\n // eslint-disable-next-line no-console\n console.error(`Full logs: ${getLogFilePath()}`);\n process.exit(1);\n }\n })();\n}\n","import { POSTHOG_DOCS_URL } from '@lib/constants';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport { analytics } from '@utils/analytics';\nimport { resolveNoTelemetry } from './resolve-no-telemetry';\n\n/**\n * The single CI validation layer: defaults region and requires api-key and\n * install-dir. Every CI entry point routes through `runWizardCI`, so this is\n * the one place these checks live. UI must be initialized before calling.\n */\nexport function validateCiOptions(options: Record<string, unknown>): void {\n if (!options.region) options.region = 'us';\n if (!options.apiKey) {\n getUI().intro('PostHog Wizard');\n getUI().log.error('CI mode requires --api-key (personal API key phx_xxx)');\n process.exit(1);\n }\n if (!options.installDir) {\n getUI().intro('PostHog Wizard');\n getUI().log.error(\n 'CI mode requires --install-dir (directory to install in)',\n );\n process.exit(1);\n }\n}\n\n/**\n * CI-mode pipeline shared by every non-interactive entry point.\n *\n * Validates flags, builds a `ci:true` session, runs `config.ciPreRun` (or the\n * program's `onReady` hooks by default), executes `runAgent`, and routes any\n * failure through `wizardAbort`. `wizardAbort` owns all exits — never add a\n * raw `process.exit` here.\n */\nexport function runWizardCI(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n setUI(new LoggingUI());\n validateCiOptions(options);\n // Every CI entry point routes through here — upgrade the non-prod\n // build tag from 'dev' to 'ci'.\n analytics.setTag('build', 'ci');\n\n void (async () => {\n const path = await import('path');\n const { buildSession } = await import('@lib/wizard-session');\n const { readEnvironment } = await import('@utils/environment');\n const { readApiKeyFromEnv } = await import('@utils/env-api-key');\n const { configureLogFileFromEnvironment, logToFile } = await import(\n '@utils/debug'\n );\n const { wizardAbort, WizardError } = await import('@utils/wizard-abort');\n\n configureLogFileFromEnvironment();\n\n const env = readEnvironment();\n const apiKey =\n (options.apiKey as string) ?? readApiKeyFromEnv() ?? undefined;\n const installDir = path.isAbsolute(options.installDir as string)\n ? (options.installDir as string)\n : path.join(process.cwd(), options.installDir as string);\n\n const session = buildSession({\n debug: options.debug as boolean | undefined,\n installDir,\n ci: true,\n signup: options.signup as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n apiKey,\n email: options.email as string | undefined,\n projectId: options.projectId as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n ...env,\n });\n session.programLabel = config.id;\n if (config.skillId) {\n session.skillId = config.skillId;\n }\n const runDef = typeof config.run === 'object' ? config.run : null;\n\n getUI().intro('Welcome to the PostHog setup wizard');\n getUI().log.info(`Running ${config.id} in CI mode`);\n\n try {\n if (config.ciPreRun) {\n await config.ciPreRun(session);\n } else {\n const readyCtx = {\n session,\n setFrameworkContext: (key: string, value: unknown) => {\n session.frameworkContext[key] = value;\n },\n setFrameworkConfig: () => undefined,\n setDetectedFramework: () => undefined,\n // CI session is a plain object (no nanostore copy-on-write),\n // so direct assignment is safe here.\n setSkillId: (skillId: string | null) => {\n session.skillId = skillId;\n },\n setUnsupportedVersion: () => undefined,\n addDiscoveredFeature: () => undefined,\n setDetectionComplete: () => undefined,\n };\n for (const step of config.steps) {\n if (step.onReady) {\n await step.onReady(readyCtx);\n }\n }\n\n const detectError = session.frameworkContext.detectError as\n | { kind: string; [k: string]: unknown }\n | undefined;\n if (detectError) {\n await wizardAbort({\n message: `Prerequisites not met: ${detectError.kind}\\n\\nSee ${\n runDef?.docsUrl ?? POSTHOG_DOCS_URL\n }`,\n error: new WizardError(`${config.id} prerequisites failed`, {\n integration: config.id,\n detect_error_kind: detectError.kind,\n }),\n });\n }\n }\n\n const { runAgent } = await import('@lib/agent/agent-runner');\n await runAgent(config, session);\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n const errorStack =\n error instanceof Error && error.stack ? error.stack : undefined;\n\n logToFile(`[bin.ts CI] ERROR: ${errorMessage}`);\n if (errorStack) logToFile(`[bin.ts CI] STACK: ${errorStack}`);\n\n const debugInfo = session.debug && errorStack ? `\\n\\n${errorStack}` : '';\n const docsUrl =\n session.frameworkConfig?.metadata.docsUrl ??\n runDef?.docsUrl ??\n POSTHOG_DOCS_URL;\n await wizardAbort({\n message: `Something went wrong: ${errorMessage}\\n\\nYou can read the documentation at ${docsUrl} to set up manually.${debugInfo}`,\n error: error as Error,\n });\n }\n })().catch(() => {\n process.exit(1);\n });\n}\n","/** Flags shared by every skill-based program command (integrate, audit, …). */\nexport const skillProgramOptions = {\n debug: {\n default: false,\n describe: 'Enable verbose logging',\n type: 'boolean' as const,\n },\n 'install-dir': {\n describe: 'Directory to install in',\n type: 'string' as const,\n },\n 'local-mcp': {\n default: false,\n describe: 'Use local MCP server',\n type: 'boolean' as const,\n },\n benchmark: {\n default: false,\n describe: 'Run in benchmark mode',\n type: 'boolean' as const,\n },\n 'yara-report': {\n default: false,\n describe: 'Print YARA scanner summary',\n type: 'boolean' as const,\n hidden: true,\n },\n};\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { posthogIntegrationConfig } from '@lib/programs/posthog-integration/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const integrateCommand: Command = {\n name: 'integrate',\n description: posthogIntegrationConfig.description,\n options: {\n ...skillProgramOptions,\n ...(posthogIntegrationConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n posthogIntegrationConfig.mapCliOptions?.(\n argv as Record<string, unknown>,\n ) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(posthogIntegrationConfig, options);\n } else {\n runWizard(posthogIntegrationConfig, options);\n }\n },\n};\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { auditConfig } from '@lib/programs/audit/index';\nimport { webAnalyticsDoctorConfig } from '@lib/programs/web-analytics-doctor/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nconst dispatchProgram = (\n config: typeof auditConfig | typeof webAnalyticsDoctorConfig,\n argv: Record<string, unknown>,\n): void => {\n const extras = config.mapCliOptions?.(argv) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(config, options);\n } else {\n runWizard(config, options);\n }\n};\n\nconst webAnalyticsCommand: Command = {\n name: webAnalyticsDoctorConfig.command!,\n description: webAnalyticsDoctorConfig.description,\n options: {\n ...skillProgramOptions,\n ...(webAnalyticsDoctorConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n dispatchProgram(webAnalyticsDoctorConfig, argv as Record<string, unknown>);\n },\n};\n\nexport const auditCommand: Command = {\n name: 'audit',\n description: auditConfig.description,\n children: [webAnalyticsCommand],\n options: {\n ...skillProgramOptions,\n ...(auditConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n dispatchProgram(auditConfig, argv as Record<string, unknown>);\n },\n};\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { audit3000Config } from '@lib/programs/audit-3000/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const audit3000Command: Command = {\n name: 'audit-3000',\n description: audit3000Config.description,\n options: {\n ...skillProgramOptions,\n ...(audit3000Config.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n audit3000Config.mapCliOptions?.(argv as Record<string, unknown>) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(audit3000Config, options);\n } else {\n runWizard(audit3000Config, options);\n }\n },\n};\n","import { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { readApiKeyFromEnv } from '@utils/env-api-key';\nimport { runWizard } from '@lib/runners';\nimport {\n posthogDoctorConfig,\n fetchHealthIssues,\n getKindMeta,\n} from '@lib/programs/posthog-doctor/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const doctorCommand: Command = {\n name: 'doctor',\n description: posthogDoctorConfig.description,\n options: {\n ...skillProgramOptions,\n ...(posthogDoctorConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n posthogDoctorConfig.mapCliOptions?.(argv as Record<string, unknown>) ??\n {};\n const options = { ...argv, ...extras };\n // doctor is otherwise a TUI-only diagnostic (it has no agent run); in CI we\n // fetch the project's health issues headlessly and report them instead.\n if (options.ci) {\n void runDoctorCI(options);\n } else {\n runWizard(posthogDoctorConfig, options);\n }\n },\n};\n\nconst SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 } as const;\n\nasync function runDoctorCI(options: Record<string, unknown>): Promise<void> {\n setUI(new LoggingUI());\n const apiKey = (options.apiKey as string) ?? readApiKeyFromEnv() ?? undefined;\n if (!apiKey) {\n getUI().intro('PostHog Wizard');\n getUI().log.error('CI mode requires --api-key (personal API key phx_xxx)');\n process.exit(1);\n }\n\n getUI().intro('Welcome to the PostHog setup wizard');\n getUI().log.info('Running posthog-doctor in CI mode');\n\n try {\n const { getOrAskForProjectData } = await import('@utils/setup-utils');\n const { host, accessToken, projectId } = await getOrAskForProjectData({\n signup: false,\n ci: true,\n apiKey,\n projectId: options.projectId\n ? Number(options.projectId as string)\n : undefined,\n });\n\n const issues = await fetchHealthIssues(accessToken, host, projectId);\n if (issues.length === 0) {\n getUI().log.success('No active issues — your project looks healthy.');\n process.exit(0);\n }\n\n const sorted = [...issues].sort(\n (a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity],\n );\n getUI().log.warn(\n `${issues.length} active issue${issues.length === 1 ? '' : 's'} found:`,\n );\n for (const issue of sorted) {\n getUI().log.info(\n ` • [${issue.severity}] ${getKindMeta(issue.kind).title}`,\n );\n }\n process.exit(1);\n } catch (error) {\n const { ApiError } = await import('@lib/api');\n const message =\n error instanceof ApiError && error.statusCode === 401\n ? 'Your PostHog API key is invalid or expired.'\n : error instanceof Error\n ? error.message\n : String(error);\n getUI().log.error(`Doctor failed: ${message}`);\n process.exit(1);\n }\n}\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { migrationConfig } from '@lib/programs/migration/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const migrateCommand: Command = {\n name: 'migrate',\n description: migrationConfig.description,\n options: {\n ...skillProgramOptions,\n ...(migrationConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n migrationConfig.mapCliOptions?.(argv as Record<string, unknown>) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(migrationConfig, options);\n } else {\n runWizard(migrationConfig, options);\n }\n },\n};\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { eventsAuditConfig } from '@lib/programs/events-audit/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const eventsAuditCommand: Command = {\n name: 'events-audit',\n description: eventsAuditConfig.description,\n options: {\n ...skillProgramOptions,\n ...(eventsAuditConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n eventsAuditConfig.mapCliOptions?.(argv as Record<string, unknown>) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(eventsAuditConfig, options);\n } else {\n runWizard(eventsAuditConfig, options);\n }\n },\n};\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { revenueAnalyticsConfig } from '@lib/programs/revenue-analytics/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const revenueCommand: Command = {\n name: 'revenue',\n description: revenueAnalyticsConfig.description,\n options: {\n ...skillProgramOptions,\n ...(revenueAnalyticsConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n revenueAnalyticsConfig.mapCliOptions?.(argv as Record<string, unknown>) ??\n {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(revenueAnalyticsConfig, options);\n } else {\n runWizard(revenueAnalyticsConfig, options);\n }\n },\n};\n","import type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from './command';\n\nexport const slackCommand: Command = {\n name: 'slack',\n description: 'Connect PostHog to your Slack',\n handler: runSlackConnect,\n // Mirrors the mcp command family shape: `wizard slack` and\n // `wizard slack add` run the same connect flow.\n children: [\n {\n name: 'add',\n description: 'Connect PostHog to your Slack',\n handler: runSlackConnect,\n },\n ],\n};\n\nfunction runSlackConnect(argv: Arguments): void {\n void (async () => {\n const debug = argv.debug as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.SlackConnect);\n tui.store.session = buildSession({ debug });\n } catch (err) {\n // TUI unavailable — connecting Slack has no headless fallback.\n setUI(new LoggingUI());\n getUI().log.error(\n `Connecting Slack requires an interactive terminal. ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n process.exit(1);\n }\n })();\n}\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { errorTrackingUploadSourceMapsConfig } from '@lib/programs/error-tracking-upload-source-maps/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const uploadSourcemapsCommand: Command = {\n // Must match ProgramConfig.command; legacy alias kept for #489 regression.\n name: [errorTrackingUploadSourceMapsConfig.command!, 'upload-sourcemaps'],\n description: errorTrackingUploadSourceMapsConfig.description,\n options: {\n ...skillProgramOptions,\n ...(errorTrackingUploadSourceMapsConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n errorTrackingUploadSourceMapsConfig.mapCliOptions?.(\n argv as Record<string, unknown>,\n ) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(errorTrackingUploadSourceMapsConfig, options);\n } else {\n runWizard(errorTrackingUploadSourceMapsConfig, options);\n }\n },\n};\n","import type { Arguments } from 'yargs';\nimport { POSTHOG_DOCS_URL } from '@lib/constants';\nimport { runWizard, runWizardCI } from '@lib/runners';\nimport { createSkillProgram } from '@lib/programs/agent-skill/index';\n\n/** Run an arbitrary context-mill skill by id (`wizard skill <id>`, headless with `--ci`). */\nexport function runSkillMode(argv: Arguments): void {\n const skillId = argv.skill as string;\n const config = createSkillProgram({\n skillId,\n command: 'skill',\n id: 'agent-skill',\n description: `Run skill: ${skillId}`,\n integrationLabel: skillId,\n successMessage: `${skillId} completed!`,\n reportFile: `posthog-${skillId}-report.md`,\n docsUrl: POSTHOG_DOCS_URL,\n spinnerMessage: `Running ${skillId}...`,\n estimatedDurationMinutes: 5,\n });\n const options = { ...argv, skillId };\n if (argv.ci) {\n runWizardCI(config, options);\n } else {\n runWizard(config, options);\n }\n}\n","import type { Arguments } from 'yargs';\nimport { runSkillMode } from './basic-integration/skill';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\n/** Read the `<skill-name>` positional (yargs camelCases the hyphenated key). */\nfunction readSkillName(argv: Arguments): string {\n return String(argv.skillName ?? argv['skill-name'] ?? '').trim();\n}\n\n/**\n * `wizard skill <skill-name>` — run a single context-mill skill by id.\n *\n * Replaces the old `--skill=<id>` flag on the default command. The skill id\n * is fetched from context-mill's release at runtime (same mechanism the flag\n * used), so any published skill id works. Pass `--ci` to run headlessly.\n */\nexport const skillCommand: Command = {\n name: 'skill <skill-name>',\n description: 'Run a specific context-mill skill by name',\n options: {\n ...skillProgramOptions,\n },\n // yargs already requires the positional, but an explicitly-empty value\n // (`wizard skill \"\"`) would otherwise slip through to a broken run with no\n // skill id. Reject it with the same friendly message the old flag gave.\n check: (argv) => {\n if (!readSkillName(argv)) {\n throw new Error(\n 'skill needs a skill name, e.g. `wizard skill audit-events`',\n );\n }\n return true;\n },\n handler: (argv) => {\n // runSkillMode reads `argv.skill`; bridge the positional onto it.\n runSkillMode({ ...argv, skill: readSkillName(argv) });\n },\n};\n","#!/usr/bin/env node\nimport { satisfies } from 'semver';\n\nconst NODE_VERSION_RANGE = '>=18.17.0';\n\n// Have to run this above the other imports because they are importing clack that\n// has the problematic imports.\nif (!satisfies(process.version, NODE_VERSION_RANGE)) {\n // eslint-disable-next-line no-console\n console.log(\n `PostHog wizard requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`,\n );\n process.exit(1);\n}\n\n// Test mock server — only loaded when NODE_ENV is 'test'.\n// In production builds, tsdown replaces process.env.NODE_ENV with 'production',\n// making this block dead code.\nif (process.env.NODE_ENV === 'test') {\n void (async () => {\n try {\n const { server } = await import('./e2e-tests/mocks/server.js');\n server.listen({\n onUnhandledRequest: 'bypass',\n });\n } catch (error) {\n // Mock server import failed - this can happen during non-E2E tests\n }\n })();\n}\n\nimport { Wizard } from './src/wizard';\nimport { basicIntegrationCommand } from './src/commands/basic-integration';\nimport { mcpCommand } from './src/commands/mcp';\nimport { integrateCommand } from './src/commands/integrate';\nimport { auditCommand } from './src/commands/audit';\nimport { audit3000Command } from './src/commands/audit-3000';\nimport { doctorCommand } from './src/commands/doctor';\nimport { migrateCommand } from './src/commands/migrate';\nimport { eventsAuditCommand } from './src/commands/events-audit';\nimport { revenueCommand } from './src/commands/revenue';\nimport { slackCommand } from './src/commands/slack';\nimport { uploadSourcemapsCommand } from './src/commands/upload-sourcemaps';\nimport { skillCommand } from './src/commands/skill';\nimport { recoverOrphanedSettingsBackups } from './src/lib/agent/claude-settings';\n\n// Heal any .claude/settings backup a previous interrupted run left orphaned,\n// before anything else reads Claude settings — conflict detection, OAuth, and\n// the agent all need to see the user's real settings file. The install dir is\n// read directly from argv/env because yargs hasn't parsed yet.\nrecoverOrphanedSettingsBackups(resolveInstallDir());\n\nfunction resolveInstallDir(): string {\n const args = process.argv.slice(2);\n const flagIndex = args.indexOf('--install-dir');\n if (flagIndex !== -1 && args[flagIndex + 1]) return args[flagIndex + 1];\n const inline = args.find((a) => a.startsWith('--install-dir='));\n if (inline) return inline.slice('--install-dir='.length);\n return process.env.POSTHOG_WIZARD_INSTALL_DIR ?? process.cwd();\n}\n\nWizard.use(basicIntegrationCommand)\n .use(mcpCommand)\n .use(integrateCommand)\n .use(auditCommand)\n .use(audit3000Command)\n .use(doctorCommand)\n .use(migrateCommand)\n .use(eventsAuditCommand)\n .use(revenueCommand)\n .use(slackCommand)\n .use(uploadSourcemapsCommand)\n .use(skillCommand)\n .init();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,YAAY,MAA4C;AAEtE,SADgC,OAAO,SAAS,WAAW,CAAC,KAAK,GAAG,MACxD,KAAK,MAAM,EAAE,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG;;AAGlD,SAAgB,gBACd,KACA,YACe;CAGf,MAAM,eAAe,CAAC,GAAG,YAAY,YAAY,IAAI,KAAK,CAAC,GAAG,CAC3D,QAAQ,QAAQ,QAAQ,KAAK,CAC7B,KAAK,IAAI;AACZ,QAAO;EACL,SAAS,IAAI;EACb,UAAU,IAAI;EACd,UAAU,MAAY;GACpB,IAAI,OAAO,IAAI,UAAU,EAAE,QAAQ,IAAI,QAAQ,GAAG;AAClD,OAAI,IAAI,MAAO,QAAO,KAAK,MAAM,IAAI,MAAM;AAC3C,QAAK,MAAM,CAAC,OAAO,gBAAgB,IAAI,YAAY,EAAE,CACnD,QAAO,KAAK,QAAQ,OAAO,YAAY;GAEzC,MAAM,UAAU,CAAC,GAAG,YAAY,YAAY,IAAI,KAAK,CAAC,GAAG;AACzD,QAAK,MAAM,SAAS,IAAI,YAAY,EAAE,CACpC,QAAO,KAAK,QAAQ,gBAAgB,OAAO,QAAQ,CAAC;AAEtD,OAAI,IAAI,UAAU,UAAU,CAAC,IAAI,QAC/B,QAAO,KAAK,cAAc,EAAE;AA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AM,OAAO,cAAc,KAAK;GAAE,CAAC;;CAExD;;;ACnCD,MAAM,qBAAqB;AAI3B,IAAI,CAAC,UAAU,QAAQ,SAAS,mBAAmB,EAAE;AAEnD,SAAQ,IACN,mCAAmC,mBAAmB,0BAA0B,QAAQ,QAAQ,wCACjG;AACD,SAAQ,KAAK,EAAE;;AAsCjB,+BAA+B,mBAAmB,CAAC;AAEnD,SAAS,oBAA4B;CACnC,MAAM,OAAO,QAAQ,KAAK,MAAM,EAAE;CAClC,MAAM,YAAY,KAAK,QAAQ,gBAAgB;AAC/C,KAAI,cAAc,MAAM,KAAK,YAAY,GAAI,QAAO,KAAK,YAAY;CACrE,MAAM,SAAS,KAAK,MAAM,MAAM,EAAE,WAAW,iBAAiB,CAAC;AAC/D,KAAI,OAAQ,QAAO,OAAO,MAAM,GAAwB;AACxD,QAAO,QAAQ,IAAI,8BAA8B,QAAQ,KAAK;;AAGhE,OAAO,IAAI,wBAAwB,CAChC,IAAI,WAAW,CACf,IAAI,iBAAiB,CACrB,IAAI,aAAa,CACjB,IAAI,iBAAiB,CACrB,IAAI,cAAc,CAClB,IAAI,eAAe,CACnB,IAAI,mBAAmB,CACvB,IAAI,eAAe,CACnB,IAAI,aAAa,CACjB,IAAI,wBAAwB,CAC5B,IAAI,aAAa,CACjB,MAAM"}
1
+ {"version":3,"file":"bin.js","names":["POSTHOG_SDKS","getContentBlocks","DOCS_URL","REPORT_FILE","DOCS_URL","getContentBlocks","agentSkillContentBlocks"],"sources":["../src/commands/command.ts","../src/wizard.ts","../src/commands/provision.ts","../src/commands/basic-integration/index.ts","../src/lib/programs/shared/package-scanning.ts","../src/lib/programs/revenue-analytics/detect.ts","../src/lib/programs/revenue-analytics/steps.ts","../src/lib/programs/agent-skill/content/index.tsx","../src/lib/programs/revenue-analytics/index.ts","../src/lib/programs/agent-skill/steps.ts","../src/lib/programs/agent-skill/index.ts","../src/lib/programs/audit/detect.ts","../src/lib/programs/audit/seed.ts","../src/lib/programs/audit/index.ts","../src/lib/programs/events-audit/steps.ts","../src/lib/programs/events-audit/seed.ts","../src/lib/programs/events-audit/index.ts","../src/lib/programs/posthog-doctor/steps.ts","../src/lib/programs/posthog-doctor/types.ts","../src/lib/programs/posthog-doctor/fetch.ts","../src/lib/programs/posthog-doctor/kind-metadata.ts","../src/lib/programs/posthog-doctor/index.ts","../src/lib/programs/web-analytics-doctor/detect.ts","../src/lib/programs/web-analytics-doctor/steps.ts","../src/lib/programs/web-analytics-doctor/index.ts","../src/lib/programs/migration/steps.ts","../src/lib/programs/migration/content/vendor-stack.tsx","../src/lib/programs/migration/content/free-tier.tsx","../src/lib/programs/migration/content/pricing-structure.tsx","../src/lib/programs/migration/content/index.tsx","../src/lib/programs/migration/index.ts","../src/lib/programs/error-tracking-upload-source-maps/detect.ts","../src/lib/programs/error-tracking-upload-source-maps/steps.ts","../src/lib/programs/error-tracking-upload-source-maps/prompt.ts","../src/lib/programs/error-tracking-upload-source-maps/content/index.tsx","../src/lib/programs/error-tracking-upload-source-maps/index.ts","../src/lib/programs/mcp/index.ts","../src/lib/programs/slack/index.ts","../src/lib/programs/program-registry.ts","../src/commands/mcp/add.ts","../src/commands/mcp/remove.ts","../src/commands/mcp/tutorial.ts","../src/commands/mcp/index.ts","../src/lib/runners/resolve-no-telemetry.ts","../src/lib/runners/run-wizard.ts","../src/lib/runners/run-wizard-ci.ts","../src/commands/skill-program-options.ts","../src/commands/factories/shared.ts","../src/lib/programs/dispatch-family.ts","../src/ui/tui/primitives/PromptLabel.tsx","../src/ui/tui/hooks/keyboard-hints-utils.ts","../src/ui/tui/hooks/useKeyboardHints.tsx","../src/ui/tui/hooks/useKeyBindings.ts","../src/ui/tui/primitives/PickerMenu.tsx","../src/commands/factories/family-picker.tsx","../src/commands/factories/family-command-factory.ts","../src/commands/audit.ts","../src/commands/doctor.ts","../src/commands/factories/native-command-factory.ts","../src/commands/migrate.ts","../src/commands/revenue.ts","../src/commands/slack.ts","../src/commands/upload-sourcemaps.ts","../src/commands/basic-integration/skill.ts","../src/commands/skill.ts","../bin.ts"],"sourcesContent":["import type {\n Arguments,\n Argv,\n CommandModule,\n Options,\n PositionalOptions,\n} from 'yargs';\nimport { setEntryCommand } from '@utils/links';\n\nexport interface Command {\n /** Yargs command name. Use `['$0']` for the default command. */\n name: string | readonly string[];\n description: string;\n /** Flags exposed by this command. Same shape as yargs `.options()`. */\n options?: Record<string, Options>;\n /**\n * Positional arguments declared in `name` (e.g. the `id` in `skill [id]`).\n * Under `.strictOptions()`, yargs only treats a positional as a known\n * argument once it's registered via `.positional()` — a command-string\n * positional alone is rejected as `Unknown argument`. Declare each one here\n * so an optional positional like `skill [id]` actually accepts its value.\n */\n positionals?: Record<string, PositionalOptions>;\n /** Nested subcommands. */\n children?: readonly Command[];\n /** `--help` examples shown for this command. */\n examples?: ReadonlyArray<readonly [string, string]>;\n /**\n * Called synchronously by yargs when the command matches. Wrap async work in\n * `void (async () => { ... })()`. Optional only when `children` is set — in\n * that case yargs requires the user to pick a subcommand (or to set\n * `interactiveDefault` for an in-process picker).\n */\n handler?: (argv: Arguments) => void;\n /**\n * Cross-flag validation run by yargs after parsing. Throw to reject (yargs\n * prints the message and exits non-zero); return `true` to accept. Prefer\n * this over per-option `conflicts` for mutually exclusive flags: yargs\n * counts a `default`-valued flag as \"present\", so `conflicts` misfires on\n * boolean flags that default to `false` — a hand-written predicate only\n * sees what you test for (e.g. truthiness).\n */\n check?: (argv: Arguments) => boolean;\n /**\n * Optional handler invoked when this command has `children` but the user\n * supplied no subcommand. Use it to mount an interactive picker over the\n * children so `wizard audit` (no leaf) opens a TUI menu instead of yargs\n * help. When set, suppresses the implicit `demandCommand(1)`.\n *\n * May return a Promise — yargs awaits the result before exiting.\n */\n interactiveDefault?: (argv: Arguments) => void | Promise<void>;\n /**\n * When true, this child is the \"default\" leaf in its family: the\n * family picker pre-highlights it so a single Enter runs it. The picker\n * still always opens — this never auto-runs the child. At most one child\n * per parent should be marked. Propagated from the context-mill manifest\n * entry's `default` flag through `skillCommandFactory`.\n */\n default?: boolean;\n}\n\n/** Extract the bare command word(s) from a yargs name spec, dropping positionals and aliases' arg syntax. */\nexport function commandKeys(name: string | readonly string[]): string[] {\n const list: readonly string[] = typeof name === 'string' ? [name] : name;\n return list.map((n) => n.trim().split(/\\s+/)[0]);\n}\n\nexport function toCommandModule(\n cmd: Command,\n parentPath: readonly string[],\n): CommandModule {\n // `wizard slack` → 'slack', `wizard mcp add` → 'mcp-add'. The default\n // `$0` resolves to '' and is skipped — its handler reports itself.\n const entryCommand = [...parentPath, commandKeys(cmd.name)[0]]\n .filter((key) => key !== '$0')\n .join('-');\n return {\n command: cmd.name,\n describe: cmd.description,\n builder: (y: Argv) => {\n let next = cmd.options ? y.options(cmd.options) : y;\n for (const [key, opts] of Object.entries(cmd.positionals ?? {})) {\n next = next.positional(key, opts);\n }\n if (cmd.check) next = next.check(cmd.check);\n for (const [usage, description] of cmd.examples ?? []) {\n next = next.example(usage, description);\n }\n const ownPath = [...parentPath, commandKeys(cmd.name)[0]];\n for (const child of cmd.children ?? []) {\n next = next.command(toCommandModule(child, ownPath));\n }\n if (cmd.children?.length && !cmd.handler && !cmd.interactiveDefault) {\n next = next.demandCommand(1);\n }\n return next;\n },\n handler: (argv: Arguments) => {\n if (entryCommand) setEntryCommand(entryCommand);\n const run = cmd.handler ?? cmd.interactiveDefault ?? (() => undefined);\n run(argv);\n },\n };\n}\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\nimport type { Argv } from 'yargs';\nimport { IS_PRODUCTION_BUILD } from '@env';\nimport { toCommandModule, type Command } from './commands/command';\n\n/**\n * Global yargs options applied to every command. These are read from the\n * `POSTHOG_WIZARD` env prefix as well as flags.\n *\n * Options with `hidden: true` are \"internal modes\" — they don't show up in\n * `--help` but are still accepted on every command. The catalog of internal\n * flags and what each one does lives in CONTRIBUTING.md.\n */\nexport const GLOBAL_OPTIONS = {\n debug: {\n default: false,\n describe: 'Enable verbose logging\\nenv: POSTHOG_WIZARD_DEBUG',\n type: 'boolean' as const,\n },\n region: {\n describe: 'PostHog cloud region\\nenv: POSTHOG_WIZARD_REGION',\n choices: ['us', 'eu'] as const,\n type: 'string' as const,\n },\n signup: {\n default: false,\n describe:\n 'Create a new PostHog account during setup\\nenv: POSTHOG_WIZARD_SIGNUP',\n type: 'boolean' as const,\n },\n telemetry: {\n default: true,\n describe:\n 'Send wizard run state to PostHog (pass --no-telemetry to disable)\\nenv: POSTHOG_WIZARD_TELEMETRY',\n type: 'boolean' as const,\n },\n 'api-key': {\n describe:\n 'PostHog personal API key (phx_xxx) for authentication\\nenv: POSTHOG_WIZARD_API_KEY',\n type: 'string' as const,\n },\n 'project-id': {\n describe:\n 'PostHog project ID to use (optional; when not set, uses default from API key or OAuth)\\nenv: POSTHOG_WIZARD_PROJECT_ID',\n type: 'string' as const,\n },\n email: {\n describe:\n 'Email address for signup (used with --signup)\\nenv: POSTHOG_WIZARD_EMAIL',\n type: 'string' as const,\n },\n // ── Internal modes ─────────────────────────────────────────────────\n // Hidden from `--help`. See CONTRIBUTING.md for what each one does.\n 'local-mcp': {\n default: false,\n describe:\n 'Use local MCP server at http://localhost:8787/mcp\\nenv: POSTHOG_WIZARD_LOCAL_MCP',\n type: 'boolean' as const,\n hidden: true,\n },\n benchmark: {\n default: false,\n describe:\n 'Run in benchmark mode with per-phase token tracking\\nenv: POSTHOG_WIZARD_BENCHMARK',\n type: 'boolean' as const,\n hidden: true,\n },\n 'yara-report': {\n default: false,\n describe:\n 'Print YARA scanner summary after the agent run\\nenv: POSTHOG_WIZARD_YARA_REPORT',\n type: 'boolean' as const,\n hidden: true,\n },\n};\n\nexport class Wizard {\n private cli: Argv;\n\n private constructor() {\n let cli = yargs(hideBin(process.argv))\n .env('POSTHOG_WIZARD')\n .options(GLOBAL_OPTIONS);\n\n // CI mode (--ci) is only supported in dev/test. It is left undeclared in\n // published builds (NODE_ENV==='production'), so .strictOptions() rejects\n // it there as an unknown argument — exactly like any other unrecognized\n // flag. init() additionally detects it up front to print a clearer message.\n if (!IS_PRODUCTION_BUILD) {\n cli = cli.option('ci', {\n default: false,\n describe:\n 'Enable CI mode for non-interactive execution\\nenv: POSTHOG_WIZARD_CI',\n type: 'boolean',\n hidden: true,\n });\n }\n\n this.cli = cli\n .strictOptions()\n // Reject unrecognized commands (e.g. `wizard bogus`) instead of letting\n // them fall through to the default `$0` integration flow.\n .strictCommands()\n // Print a concise error and point to `--help`, instead of yargs' default\n // of dumping the entire usage screen under every failure.\n .fail((msg, err) => {\n const text = msg || (err && err.message) || 'Invalid arguments';\n process.stderr.write(\n `\\n\\x1b[1;91m✖ ${text}\\x1b[0m\\n` +\n ` Run \\`wizard --help\\` to see available commands and options.\\n\\n`,\n );\n process.exit(1);\n })\n .help()\n .alias('help', 'h')\n .version()\n .alias('version', 'v');\n }\n\n /** Start a chain; equivalent to `new Wizard().use(...cmds)`. */\n static use(...cmds: Command[]): Wizard {\n return new Wizard().use(...cmds);\n }\n\n /** Register one or more commands with yargs. */\n use(...cmds: Command[]): this {\n for (const cmd of cmds) {\n this.cli = this.cli.command(toCommandModule(cmd, []));\n }\n return this;\n }\n\n /** Parse argv and dispatch to the matching registered command. */\n init(): void {\n // In published builds, `--ci` is undeclared, so yargs would reject it as\n // an unknown argument — accurate but unhelpful, since --help doesn't list\n // --ci either and the user has no path forward. POSTHOG_WIZARD_CI silently\n // no-ops for the same reason (yargs only resolves env vars for declared\n // options). Detect both up front and exit with a message that explains why.\n if (IS_PRODUCTION_BUILD) {\n const args = process.argv.slice(2);\n const argvHasCI = args.some(\n (a) => a === '--ci' || a === '--no-ci' || a.startsWith('--ci='),\n );\n const envHasCI =\n process.env.POSTHOG_WIZARD_CI != null &&\n process.env.POSTHOG_WIZARD_CI !== '';\n if (argvHasCI || envHasCI) {\n process.stderr.write(\n `\\n\\x1b[1;91m✖ CI mode is not currently supported in published builds.\\x1b[0m\\n\\n`,\n );\n process.exit(1);\n }\n }\n void this.cli.wrap(process.stdout.isTTY ? this.cli.terminalWidth() : 80)\n .argv;\n }\n}\n","import type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport type { ProvisioningResult } from '@utils/provisioning';\nimport type { Command } from './command';\n\nexport const provisionCommand: Command = {\n name: 'provision',\n description: 'Create a new PostHog account (headless, no TUI)',\n options: {\n email: {\n describe: 'Email address for the new account',\n type: 'string',\n demandOption: true,\n },\n region: {\n describe: 'Cloud region (us or eu)',\n choices: ['us', 'eu'] as const,\n default: 'us',\n },\n name: {\n describe: 'Name for the new account',\n type: 'string',\n default: '',\n },\n json: {\n describe:\n 'Emit JSON result to stdout (defaults to true when stdout is not a TTY)',\n type: 'boolean',\n },\n },\n examples: [\n ['wizard provision --email matt+test@posthog.com --region us', ''],\n ['wizard provision --email user@example.com --region eu --json', ''],\n ],\n handler: runProvision,\n};\n\nfunction runProvision(argv: Arguments): void {\n const jsonMode =\n argv.json === undefined ? !process.stdout.isTTY : Boolean(argv.json);\n if (!jsonMode) setUI(new LoggingUI());\n\n void provision({\n email: argv.email as string,\n region: (argv.region as string).toUpperCase() as 'US' | 'EU',\n name: (argv.name as string) ?? '',\n jsonMode,\n });\n}\n\ntype ProvisionArgs = {\n email: string;\n region: 'US' | 'EU';\n name: string;\n jsonMode: boolean;\n};\n\nasync function provision({\n email,\n region,\n name,\n jsonMode,\n}: ProvisionArgs): Promise<void> {\n try {\n const { provisionNewAccount } = await import('@utils/provisioning');\n if (!jsonMode) {\n getUI().log.info(`Provisioning account for ${email} in ${region}...`);\n }\n const result = await provisionNewAccount(email, name, region);\n emitResult(result, jsonMode);\n process.exit(0);\n } catch (error) {\n emitError(error, jsonMode);\n process.exit(1);\n }\n}\n\nfunction emitResult(result: ProvisioningResult, jsonMode: boolean): void {\n if (jsonMode) {\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n return;\n }\n getUI().log.success('Account provisioned successfully:');\n getUI().log.info(` API Key: ${result.projectApiKey}`);\n getUI().log.info(` Host: ${result.host}`);\n getUI().log.info(` Project ID: ${result.projectId}`);\n getUI().log.info(` Account ID: ${result.accountId}`);\n getUI().log.info(` Access Token: ${result.accessToken}`);\n getUI().log.info(` Refresh Token: ${result.refreshToken}`);\n if (result.personalApiKey) {\n getUI().log.info(` Personal API Key: ${result.personalApiKey}`);\n }\n}\n\nfunction emitError(error: unknown, jsonMode: boolean): void {\n const msg = error instanceof Error ? error.message : String(error);\n const code = msg.includes('already associated')\n ? 'email_exists'\n : 'provisioning_failed';\n if (jsonMode) {\n process.stderr.write(`${JSON.stringify({ error: msg, code })}\\n`);\n return;\n }\n getUI().log.error(`Provisioning failed: ${msg}`);\n}\n","import { isNonInteractiveEnvironment } from '@utils/environment';\nimport { setEntryCommand } from '@utils/links';\nimport { provisionCommand } from '../provision';\nimport type { Command } from '../command';\n\nexport const basicIntegrationCommand: Command = {\n name: ['$0'],\n description: 'Run the PostHog setup wizard',\n // provision is a one-shot HTTP call tied to the base flow, not a wizard\n // program — it rides under the base command rather than as a peer.\n children: [provisionCommand],\n options: {\n 'install-dir': {\n describe:\n 'Directory to install PostHog in\\nenv: POSTHOG_WIZARD_INSTALL_DIR',\n type: 'string',\n },\n name: {\n describe:\n 'Name for account creation with --ci --signup\\nenv: POSTHOG_WIZARD_NAME',\n type: 'string',\n },\n // ── Internal modes ───────────────────────────────────────────────\n // Hidden from `--help`. See CONTRIBUTING.md for what each one does.\n playground: {\n default: false,\n describe: 'Launch the TUI primitives playground',\n type: 'boolean',\n hidden: true,\n },\n },\n check: (argv) => {\n // --playground is the standalone TUI demo; it can't combine with --ci.\n if (argv.playground && argv.ci) {\n throw new Error('--playground cannot be combined with --ci.');\n }\n return true;\n },\n handler: (argv) => {\n // The bare run is the integrate flow.\n setEntryCommand('integrate');\n // Each mode file is loaded only when its branch is taken, so a plain\n // `npx @posthog/wizard` never pulls in the CI or playground paths.\n void (async () => {\n if (argv.ci) {\n const { runCIInstall } = await import('./ci-install');\n return runCIInstall(argv);\n }\n if (isNonInteractiveEnvironment()) {\n const { failNonInteractive } = await import('./non-interactive');\n return failNonInteractive();\n }\n if (argv.playground) {\n const { runPlayground } = await import('./playground');\n return runPlayground();\n }\n const { runInteractive } = await import('./interactive');\n runInteractive(argv);\n })();\n },\n};\n","import type { Dirent } from 'fs';\nimport { readFileSync, readdirSync } from 'fs';\nimport { join, relative } from 'path';\nimport { IGNORED_DIRS } from '@utils/file-utils';\n\nexport const POSTHOG_SDKS = [\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n];\n\nexport const STRIPE_SDKS = [\n 'stripe',\n '@stripe/stripe-js',\n '@stripe/react-stripe-js',\n];\n\nexport interface PackageMatch {\n /** Path to the package.json relative to installDir */\n path: string;\n posthogSdks: string[];\n stripeSdks: string[];\n}\n\n/**\n * Recursively find all package.json files under installDir (max depth 3),\n * skipping common ignored directories. Returns matches with detected SDKs.\n */\nexport function findPackageJsons(\n installDir: string,\n maxDepth = 3,\n): PackageMatch[] {\n const matches: PackageMatch[] = [];\n\n function scan(dir: string, depth: number): void {\n if (depth > maxDepth) return;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.name !== '.') continue;\n if (IGNORED_DIRS.has(entry.name)) continue;\n\n const fullPath = join(dir, entry.name);\n\n if (entry.isFile() && entry.name === 'package.json') {\n try {\n const pkg = JSON.parse(readFileSync(fullPath, 'utf-8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const depNames = [\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ];\n const posthogSdks = depNames.filter((d) => POSTHOG_SDKS.includes(d));\n const stripeSdks = depNames.filter((d) => STRIPE_SDKS.includes(d));\n matches.push({\n path: relative(installDir, fullPath) || 'package.json',\n posthogSdks,\n stripeSdks,\n });\n } catch {\n // Skip malformed package.json\n }\n } else if (entry.isDirectory()) {\n scan(fullPath, depth + 1);\n }\n }\n }\n\n scan(installDir, 0);\n return matches;\n}\n","/**\n * Revenue analytics prerequisite detection.\n *\n * Scans the project for PostHog + Stripe SDKs and writes results\n * into frameworkContext for the intro screen to render.\n */\n\nimport { existsSync, statSync } from 'fs';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { findPackageJsons } from '@lib/programs/shared/package-scanning';\n\nexport {\n findPackageJsons,\n POSTHOG_SDKS,\n STRIPE_SDKS,\n type PackageMatch,\n} from '@lib/programs/shared/package-scanning';\n\n/**\n * Structured detection errors. The screen renders each kind into JSX\n * with proper formatting — keeps error data separate from presentation.\n */\nexport type RevenueDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-package-json' }\n | { kind: 'no-sdks'; scannedCount: number }\n | { kind: 'missing-posthog'; foundStripe: string[] }\n | { kind: 'missing-stripe'; foundPosthog: string[] };\n\n/** `[ABORT] <reason>` cases the revenue analytics skill can emit. */\nexport const REVENUE_ABORT_CASES: AbortCase[] = [\n {\n // Skill emits: [ABORT] Could not find a PostHog distinct_id\n match: /^could not find a posthog distinct_id$/i,\n message: 'Could not find a PostHog distinct_id',\n body:\n 'The agent could not find PostHog distinct_id usage in your codebase. ' +\n 'Your users must be identified in PostHog before they can be tagged in Stripe. ' +\n 'Please identify your users and try again.',\n docsUrl: 'https://posthog.com/docs/product-analytics/identify',\n },\n {\n // Skill emits: [ABORT] Could not find a Stripe integration\n match: /^could not find a stripe integration$/i,\n message: 'Could not find a Stripe integration',\n body:\n 'The Wizard could not find an existing Stripe customer, charge, ' +\n 'subscription, or other Stripe operations. Please run the Revenue ' +\n 'Analytics Wizard on a project with an existing Stripe integration.',\n docsUrl: 'https://posthog.com/docs/revenue-analytics',\n },\n];\n\n/**\n * Scan `session.installDir` for PostHog + Stripe SDKs. Writes detection\n * results into frameworkContext via the callback — either the detected\n * SDK lists (for the intro screen) or a `RevenueDetectError` on failure.\n *\n * The skill install happens later in the bootstrap runner, not here.\n */\nexport function detectRevenuePrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: RevenueDetectError) =>\n setFrameworkContext('detectError', error);\n\n const installDir = session.installDir;\n\n // Verify the install directory exists and is readable\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n // Find all package.json files (root + monorepo subpackages)\n const matches = findPackageJsons(installDir);\n\n if (matches.length === 0) {\n fail({ kind: 'no-package-json' });\n return;\n }\n\n // Aggregate detected SDKs across all package.json files\n const allPosthogSdks = new Set<string>();\n const allStripeSdks = new Set<string>();\n for (const match of matches) {\n for (const sdk of match.posthogSdks) allPosthogSdks.add(sdk);\n for (const sdk of match.stripeSdks) allStripeSdks.add(sdk);\n }\n\n const detectedPosthogSdks = [...allPosthogSdks];\n const detectedStripeSdks = [...allStripeSdks];\n\n if (detectedPosthogSdks.length === 0 && detectedStripeSdks.length === 0) {\n fail({ kind: 'no-sdks', scannedCount: matches.length });\n return;\n }\n\n if (detectedPosthogSdks.length === 0) {\n fail({ kind: 'missing-posthog', foundStripe: detectedStripeSdks });\n return;\n }\n\n if (detectedStripeSdks.length === 0) {\n fail({ kind: 'missing-stripe', foundPosthog: detectedPosthogSdks });\n return;\n }\n\n setFrameworkContext('detectedPosthogSdks', detectedPosthogSdks);\n setFrameworkContext('detectedStripeSdks', detectedStripeSdks);\n setFrameworkContext(\n 'detectedPackagePaths',\n matches\n .filter((m) => m.posthogSdks.length > 0 || m.stripeSdks.length > 0)\n .map((m) => m.path),\n );\n}\n","/**\n * Revenue analytics program step list.\n *\n * The detect step checks for PostHog + Stripe SDKs. The skill install\n * and agent run live in the program runner (see agent-runner.ts).\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\nimport { detectRevenuePrerequisites } from './detect.js';\n\nexport const REVENUE_ANALYTICS_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting prerequisites',\n // Headless step: no screen, no gate. onReady fires after bin.ts\n // assigns the session — the hook scans for PostHog + Stripe SDKs\n // and writes the results (or a detectError) to frameworkContext\n // for the intro screen to render.\n onReady: (ctx) =>\n detectRevenuePrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'revenue-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Revenue analytics',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","/**\n * Agent-skill learn-deck — the short three-line sequence shown while a\n * skill-based program (audit, revenue-analytics, agent-skill, etc.)\n * runs. Skill programs don't need the full PostHog onboarding narrative.\n */\n\nimport { Text } from 'ink';\nimport type { WizardStore } from '@ui/tui/store';\nimport { TextRevealMode } from '@ui/tui/primitives/TextBlock';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] => {\n const skillId = store?.session.skillId ?? 'unknown';\n return [\n {\n content: 'Welcome.',\n pause: 3000,\n mode: TextRevealMode.Typewriter,\n animationInterval: 160,\n },\n { content: 'The Wizard is an agent.', pause: 4000 },\n {\n pause: 60000,\n content: (\n <Text>\n Running the <Text color=\"cyan\">{skillId}</Text> skill...\n </Text>\n ),\n },\n ];\n};\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { REVENUE_ANALYTICS_PROGRAM } from './steps.js';\nimport { REVENUE_ABORT_CASES } from './detect.js';\nimport { getContentBlocks } from './content/index.js';\n\nexport const revenueAnalyticsConfig: ProgramConfig = {\n command: 'revenue-analytics',\n description: 'Set up PostHog revenue analytics (e.g. Stripe integration)',\n id: 'revenue-analytics-setup',\n skillId: 'revenue-analytics-setup',\n steps: REVENUE_ANALYTICS_PROGRAM,\n getContentBlocks,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n run: {\n skillId: 'revenue-analytics-setup',\n integrationLabel: 'revenue-analytics-setup',\n customPrompt: () => 'Set up revenue analytics for this project.',\n successMessage: 'Revenue analytics configured!',\n reportFile: 'posthog-revenue-report.md',\n docsUrl: 'https://posthog.com/docs/revenue-analytics',\n spinnerMessage: 'Setting up revenue analytics...',\n estimatedDurationMinutes: 5,\n abortCases: REVENUE_ABORT_CASES,\n },\n requires: ['posthog-integration'],\n};\n\nexport { REVENUE_ANALYTICS_PROGRAM } from './steps.js';\nexport {\n detectRevenuePrerequisites,\n POSTHOG_SDKS,\n STRIPE_SDKS,\n type RevenueDetectError,\n} from './detect.js';\n","/**\n * Generic agent skill step list.\n *\n * Minimal flow: intro → health-check → auth → run → outro → skills.\n * No detection, no setup, no MCP.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nexport const AGENT_SKILL_STEPS: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'agent-skill-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Running',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","/**\n * Generic agent skill program factory.\n *\n * Creates a ProgramConfig for any context-mill skill. Provide a\n * skill ID and basic UI config — the factory handles the rest.\n *\n * Usage:\n * createSkillProgram({\n * skillId: 'error-tracking-setup',\n * command: 'errors',\n * id: 'error-tracking',\n * description: 'Set up PostHog error tracking',\n * integrationLabel: 'error-tracking',\n * successMessage: 'Error tracking configured!',\n * reportFile: 'posthog-error-tracking-report.md',\n * docsUrl: 'https://posthog.com/docs/error-tracking',\n * spinnerMessage: 'Setting up error tracking...',\n * estimatedDurationMinutes: 5,\n * })\n */\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun, AbortCase } from '@lib/agent/agent-runner';\nimport { AGENT_SKILL_STEPS } from './steps.js';\nimport { getContentBlocks } from './content/index.js';\n\nexport interface SkillProgramOptions {\n /** Context-mill skill ID to install */\n skillId: string;\n /** CLI subcommand name */\n command: string;\n /** Unique flow key — must match a Program enum entry */\n id: string;\n /** CLI description shown in --help */\n description: string;\n /** Analytics integration label */\n integrationLabel: string;\n /** Custom prompt instruction. Appended after default project prompt. */\n customPrompt?: string;\n successMessage: string;\n reportFile: string;\n docsUrl: string;\n spinnerMessage: string;\n estimatedDurationMinutes: number;\n /** Other program ids that must be satisfied first */\n requires?: string[];\n /** Override the default outro. Receives the same args as ProgramRun.buildOutroData. */\n buildOutroData?: ProgramRun['buildOutroData'];\n /** Known `[ABORT] <reason>` cases the skill can emit. */\n abortCases?: AbortCase[];\n}\n\nexport function createSkillProgram(opts: SkillProgramOptions): ProgramConfig {\n return {\n command: opts.command,\n description: opts.description,\n id: opts.id,\n skillId: opts.skillId,\n steps: AGENT_SKILL_STEPS,\n reportFile: opts.reportFile,\n getContentBlocks,\n run: {\n skillId: opts.skillId,\n integrationLabel: opts.integrationLabel,\n customPrompt: opts.customPrompt ? () => opts.customPrompt! : undefined,\n successMessage: opts.successMessage,\n reportFile: opts.reportFile,\n docsUrl: opts.docsUrl,\n spinnerMessage: opts.spinnerMessage,\n estimatedDurationMinutes: opts.estimatedDurationMinutes,\n buildOutroData: opts.buildOutroData,\n abortCases: opts.abortCases,\n },\n requires: opts.requires,\n };\n}\n\nexport { AGENT_SKILL_STEPS } from './steps.js';\n","import type { AbortCase } from '@lib/agent/agent-runner';\n\n/** `[ABORT] <reason>` cases the audit skill can emit. Reason strings are\n * defined in the skill's `Abort statuses` section. */\nexport const AUDIT_ABORT_CASES: AbortCase[] = [\n {\n match: /^no posthog sdk found$/i,\n message: 'No PostHog SDK found',\n body:\n 'The audit needs an existing PostHog integration to review. No PostHog ' +\n 'SDK appears in this project’s dependency manifests. Run the basic ' +\n 'integration program to install PostHog first, then re-run the audit.',\n docsUrl: 'https://posthog.com/docs/getting-started/install',\n },\n];\n","import fs from 'fs';\nimport path from 'path';\nimport { logToFile } from '@utils/debug';\nimport { AUDIT_CHECKS_FILE, type AuditCheck } from './types.js';\n\n/**\n * The 10 data-integrity checks the audit runs, plus one workflow row for the\n * notebook upload at the end (so the skill's `audit_resolve_checks` call for\n * `upload-notebook` succeeds — the skill writes the report to a PostHog\n * notebook as its final step).\n */\nexport const AUDIT_SEED_CHECKS: AuditCheck[] = [\n {\n id: 'sdk-installed',\n area: 'Installation',\n label: 'PostHog SDK installed',\n status: 'pending',\n },\n {\n id: 'sdk-up-to-date',\n area: 'Installation',\n label: 'SDK version up to date',\n status: 'pending',\n },\n {\n id: 'init-correct',\n area: 'Installation',\n label: 'Initialization is correct',\n status: 'pending',\n },\n {\n id: 'identify-stable-distinct-id',\n area: 'Identification',\n label: 'Stable distinct_id (not session UUID)',\n status: 'pending',\n },\n {\n id: 'identify-not-late',\n area: 'Identification',\n label: 'identify() called before captures / flag evals',\n status: 'pending',\n },\n {\n id: 'cross-runtime-distinct-id',\n area: 'Identification',\n label: 'Same distinct_id across client and server',\n status: 'pending',\n },\n {\n id: 'identify-reset-on-logout',\n area: 'Identification',\n label: 'reset() called on logout / account switch',\n status: 'pending',\n },\n {\n id: 'capture-event-names-static',\n area: 'Event Capture',\n label: 'Event names are static and consistent',\n status: 'pending',\n },\n {\n id: 'capture-uses-proxy',\n area: 'Event Capture',\n label: 'Captures route through a reverse proxy',\n status: 'pending',\n },\n {\n id: 'capture-growth-events',\n area: 'Event Capture',\n label: 'Key activation events captured',\n status: 'pending',\n },\n {\n id: 'write-report',\n area: 'Write report',\n label: 'Create posthog-audit-report.md',\n status: 'pending',\n },\n {\n id: 'upload-notebook',\n area: 'Upload notebook',\n label: 'Write the report into a PostHog notebook',\n status: 'pending',\n },\n];\n\n/**\n * Atomically write a seeded ledger to the project's audit checks file.\n *\n * Each audit-flavored program (doctor, events-audit) owns its own seed\n * shape — pass the seed in so this writer stays program-agnostic.\n */\nexport function seedAuditLedger(\n installDir: string,\n checks: AuditCheck[] = AUDIT_SEED_CHECKS,\n): void {\n const target = path.join(installDir, AUDIT_CHECKS_FILE);\n const tmp = `${target}.tmp`;\n fs.writeFileSync(tmp, JSON.stringify(checks, null, 2), 'utf8');\n fs.renameSync(tmp, target);\n logToFile(`seedAuditLedger: wrote ${checks.length} entries to ${target}`);\n}\n","import {\n AGENT_SKILL_STEPS,\n createSkillProgram,\n} from '@lib/programs/agent-skill/index';\nimport type { ProgramStep, ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { OutroKind } from '@lib/wizard-session';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { getCloudUrlFromRegion } from '@utils/urls';\nimport { AUDIT_ABORT_CASES } from './detect.js';\nimport { AUDIT_CHECKS_KEY, AUDIT_REPORT_FILE } from './types.js';\nimport { AUDIT_SEED_CHECKS, seedAuditLedger } from './seed.js';\n\n/** Audit-specific screens for the shared agent-skill pipeline. */\nconst AUDIT_SCREEN_BY_STEP: Record<string, string> = {\n intro: 'audit-intro',\n run: 'audit-run',\n outro: 'audit-outro',\n};\n\nconst seedBeforeAuditRun = (session: WizardSession): void => {\n seedAuditLedger(session.installDir);\n session.frameworkContext[AUDIT_CHECKS_KEY] = AUDIT_SEED_CHECKS;\n};\n\nconst withAuditScreens = (steps: ProgramStep[]): ProgramStep[] =>\n steps.map((step) => {\n const override = AUDIT_SCREEN_BY_STEP[step.id];\n return override ? { ...step, screenId: override } : step;\n });\n\nconst auditSteps: ProgramStep[] = withAuditScreens(AGENT_SKILL_STEPS);\n\nconst baseConfig = createSkillProgram({\n skillId: 'audit',\n command: 'audit',\n id: 'audit',\n description:\n 'Audit an existing PostHog integration for correctness and best practices',\n integrationLabel: 'audit',\n customPrompt:\n 'Run a comprehensive audit of the existing PostHog integration. Follow the skill program steps in order. Do not modify any project files — only create the final audit report.',\n successMessage:\n 'Audit complete! You can view the audit report at ./posthog-audit-report.md',\n reportFile: AUDIT_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/product-analytics/best-practices',\n spinnerMessage: 'Auditing PostHog integration...',\n estimatedDurationMinutes: 5,\n requires: ['posthog-integration'],\n abortCases: AUDIT_ABORT_CASES,\n});\n\nconst auditRun = async (session: WizardSession): Promise<ProgramRun> => {\n seedBeforeAuditRun(session);\n\n if (!baseConfig.run) {\n throw new Error('Audit program has no run configuration.');\n }\n\n const baseRun =\n typeof baseConfig.run === 'function'\n ? await baseConfig.run(session)\n : baseConfig.run;\n\n return {\n ...baseRun,\n // Override the default outro so the dashboard + notebook URLs the\n // agent emits via `[DASHBOARD_URL]` / `[NOTEBOOK_URL]` are surfaced\n // on the post-run screen.\n buildOutroData: (sess, _credentials, cloudRegion) => {\n const cloudUrl = cloudRegion\n ? getCloudUrlFromRegion(cloudRegion)\n : undefined;\n const continueUrl =\n sess.signup && cloudUrl\n ? `${cloudUrl}/products?source=wizard`\n : undefined;\n\n // Note: `sess` here is the agent-runner's snapshot of session at\n // runAgent() invocation time. Any URL emissions during the run land\n // on the live store, NOT on this snapshot. The UI layer\n // (InkUI.setOutroData) merges live URLs in on top of this return\n // value, so it's safe to leave dashboardUrl/notebookUrl as undefined\n // here when the snapshot doesn't have them.\n return {\n kind: OutroKind.Success as const,\n message: baseRun.successMessage,\n reportFile: baseRun.reportFile,\n docsUrl: baseRun.docsUrl,\n continueUrl,\n dashboardUrl: sess.dashboardUrl ?? undefined,\n notebookUrl: sess.notebookUrl ?? undefined,\n };\n },\n };\n};\n\nexport const auditConfig: ProgramConfig = {\n ...baseConfig,\n steps: auditSteps,\n run: auditRun,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n};\n","/**\n * Events-audit program.\n *\n * Mirrors the posthog-integration step list, except:\n * - The initial framework detection step is omitted — the events-audit\n * skill handles detection at agent run time.\n * - The intro step uses the audit intro screen (no framework selection\n * logic) instead of the integration intro.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nfunction needsSetup(session: WizardSession): boolean {\n const config = session.frameworkConfig;\n if (!config?.metadata.setup?.questions) return false;\n\n return config.metadata.setup.questions.some(\n (q: { key: string }) => !(q.key in session.frameworkContext),\n );\n}\n\nexport const EVENTS_AUDIT_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'audit-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'setup',\n label: 'Setup',\n screenId: 'setup',\n show: needsSetup,\n isComplete: (session) => !needsSetup(session),\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Events audit',\n screenId: 'audit-run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'mcp',\n label: 'MCP servers',\n screenId: 'mcp',\n isComplete: (session) => session.mcpComplete,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'audit-outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'keep-skills',\n label: 'Keep Skills',\n screenId: 'keep-skills',\n },\n];\n","import type { AuditCheck } from '@lib/programs/audit/types';\n\n/**\n * The 7 phases the events-audit skill marches through. One check per area\n * so PendingChecksList renders a clean linear pipeline (area = bold header,\n * single row = the active spinner).\n *\n * Phase ids match what the skill's step files resolve via\n * `mcp__wizard-tools__audit_resolve_checks` as each phase completes. The\n * skill's step 1 also seeds these same ids — keep both in sync so the\n * wizard pre-seed and the skill's MCP seed agree.\n */\nexport const EVENTS_AUDIT_SEED_CHECKS: AuditCheck[] = [\n {\n id: 'detect-sdk',\n area: 'Detect SDK',\n label: 'Identify PostHog SDK(s) in dependencies',\n status: 'pending',\n },\n {\n id: 'scan-sites',\n area: 'Scan capture sites',\n label: 'Grep capture/identify/group call sites',\n status: 'pending',\n },\n {\n id: 'enrich-sites',\n area: 'Enrich',\n label: 'Subagent fan-out to read capture files',\n status: 'pending',\n },\n {\n id: 'query-volume',\n area: 'Query PostHog',\n label: '30-day volume + last_seen via MCP',\n status: 'pending',\n },\n {\n id: 'write-report',\n area: 'Write report',\n label: 'Create posthog-events-audit-report.md',\n status: 'pending',\n },\n {\n id: 'create-dashboard',\n area: 'Create dashboard',\n label: 'Optional: dashboard for resolved events',\n status: 'pending',\n },\n {\n id: 'upload-notebook',\n area: 'Upload notebook',\n label: 'Write the report into a PostHog notebook',\n status: 'pending',\n },\n];\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { OutroKind } from '@lib/wizard-session';\nimport { SPINNER_MESSAGE } from '@lib/framework-config';\nimport { isUsingTypeScript } from '@utils/setup-utils';\nimport { getCloudUrlFromRegion } from '@utils/urls';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { EVENTS_AUDIT_PROGRAM } from './steps.js';\nimport { AUDIT_CHECKS_KEY } from '@lib/programs/audit/types';\nimport { seedAuditLedger } from '@lib/programs/audit/seed';\nimport { EVENTS_AUDIT_SEED_CHECKS } from './seed.js';\n\nexport const SETUP_REPORT_FILE = 'posthog-events-audit-report.md';\n\nconst DOCS_URL = 'https://posthog.com/docs/product-analytics/best-practices';\n\nexport const eventsAuditConfig: ProgramConfig = {\n command: 'events-audit',\n description: 'Audit PostHog event tracking in this project',\n id: 'events-audit',\n skillId: 'events-audit',\n steps: EVENTS_AUDIT_PROGRAM,\n // Top-level reportFile so AuditRunScreen can resolve the report path\n // synchronously without unwrapping the deferred `run` function.\n reportFile: SETUP_REPORT_FILE,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n\n run: (session: WizardSession): Promise<ProgramRun> => {\n const typeScriptDetected = isUsingTypeScript({\n installDir: session.installDir,\n });\n session.typescript = typeScriptDetected;\n\n // Seed the audit ledger so AuditRunScreen has something to render\n // before the agent emits its first check update. The events-audit\n // ledger is the 6-phase pipeline, not the doctor's 10 integrity checks.\n seedAuditLedger(session.installDir, EVENTS_AUDIT_SEED_CHECKS);\n session.frameworkContext[AUDIT_CHECKS_KEY] = EVENTS_AUDIT_SEED_CHECKS;\n\n return Promise.resolve({\n skillId: 'events-audit',\n integrationLabel: 'events-audit',\n spinnerMessage: SPINNER_MESSAGE,\n successMessage:\n 'Events audit complete! You can view the report at ./posthog-events-audit-report.md',\n estimatedDurationMinutes: 5,\n reportFile: SETUP_REPORT_FILE,\n docsUrl: DOCS_URL,\n errorMessage: 'Events audit failed',\n additionalFeatureQueue: session.additionalFeatureQueue,\n\n customPrompt: (ctx) =>\n `Audit PostHog event capture in this project. Do not modify any project files — produce a read-only report only.\n\nProject context:\n- PostHog Project ID: ${ctx.projectId}\n- TypeScript: ${typeScriptDetected ? 'Yes' : 'No'}\n- PostHog public token: ${ctx.projectApiKey}\n- PostHog Host: ${ctx.host}\n`,\n\n buildOutroData: (sess, _credentials, cloudRegion) => {\n const cloudUrl = cloudRegion\n ? getCloudUrlFromRegion(cloudRegion)\n : undefined;\n const continueUrl =\n sess.signup && cloudUrl\n ? `${cloudUrl}/products?source=wizard`\n : undefined;\n // The agent emits `[DASHBOARD_URL] <url>` once it creates the\n // dashboard; the SDK-message interceptor stores it on the session.\n // Fall back to the dashboards index if nothing was emitted.\n const dashboardUrl =\n sess.dashboardUrl ?? (cloudUrl ? `${cloudUrl}/dashboard` : undefined);\n\n // The agent emits `[NOTEBOOK_URL] <url>` once it uploads the report\n // to a PostHog notebook. No fallback: if the notebook upload was\n // skipped (e.g. MCP unavailable) we just don't show a link.\n const notebookUrl = sess.notebookUrl ?? undefined;\n\n return {\n kind: OutroKind.Success as const,\n message: 'Your events audit was successful',\n reportFile: SETUP_REPORT_FILE,\n changes: [],\n docsUrl: DOCS_URL,\n continueUrl,\n dashboardUrl,\n notebookUrl,\n };\n },\n });\n },\n};\n\nexport { EVENTS_AUDIT_PROGRAM } from './steps.js';\n","import type { ProgramStep } from '@lib/programs/program-step';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nexport const POSTHOG_DOCTOR_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'doctor-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'report',\n label: 'Doctor report',\n screenId: 'doctor-report',\n isComplete: (session) => session.outroData !== null,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n];\n","import { z } from 'zod';\n\nexport const HealthIssueSeveritySchema = z.enum([\n 'critical',\n 'warning',\n 'info',\n]);\nexport type HealthIssueSeverity = z.infer<typeof HealthIssueSeveritySchema>;\n\nexport const HealthIssueStatusSchema = z.enum(['active', 'resolved']);\n\nexport const HealthIssueSchema = z.object({\n id: z.string(),\n kind: z.string(),\n severity: HealthIssueSeveritySchema,\n status: HealthIssueStatusSchema,\n dismissed: z.boolean(),\n created_at: z.string(),\n updated_at: z.string(),\n resolved_at: z.string().nullable().optional(),\n});\nexport type HealthIssue = z.infer<typeof HealthIssueSchema>;\n\nexport const HealthIssueListResponseSchema = z.object({\n results: z.array(HealthIssueSchema),\n count: z.number().optional(),\n next: z.string().nullable().optional(),\n previous: z.string().nullable().optional(),\n});\nexport type HealthIssueListResponse = z.infer<\n typeof HealthIssueListResponseSchema\n>;\n\nexport interface HealthIssueSummary {\n total: number;\n by_severity: Record<HealthIssueSeverity, number>;\n}\n","import axios from 'axios';\nimport { analytics } from '@utils/analytics';\nimport { handleApiError } from '@lib/api';\nimport { WIZARD_USER_AGENT } from '@lib/constants';\nimport { HealthIssueListResponseSchema, type HealthIssue } from './types';\n\nexport async function fetchHealthIssues(\n accessToken: string,\n baseUrl: string,\n projectId: number,\n): Promise<HealthIssue[]> {\n const endpoint = `/api/environments/${projectId}/health_issues/`;\n const url = `${baseUrl}${endpoint}?status=active&dismissed=false&limit=250`;\n try {\n const response = await axios.get(url, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'User-Agent': WIZARD_USER_AGENT,\n },\n });\n return HealthIssueListResponseSchema.parse(response.data).results;\n } catch (error) {\n const apiError = handleApiError(error, 'fetch health issues');\n analytics.captureException(apiError, { endpoint, baseUrl, projectId });\n throw apiError;\n }\n}\n","import { POSTHOG_DOCS_URL } from '@lib/constants';\n\nexport interface KindMeta {\n title: string;\n description: string;\n docsUrl: string;\n}\n\nexport const KIND_METADATA: Record<string, KindMeta> = {\n ingestion_lag: {\n title: 'Ingestion is delayed',\n description:\n 'Events are being received but are taking longer than usual to appear.',\n docsUrl: `${POSTHOG_DOCS_URL}/support/troubleshooting`,\n },\n ingestion_warning: {\n title: 'Ingestion warnings on recent events',\n description:\n 'Some recent events were rejected or flagged by the ingestion pipeline.',\n docsUrl: `${POSTHOG_DOCS_URL}/support/troubleshooting`,\n },\n sdk_outdated: {\n title: 'SDK version is out of date',\n description:\n 'One or more SDKs are running an old version. Upgrade to get the latest fixes.',\n docsUrl: `${POSTHOG_DOCS_URL}/libraries`,\n },\n no_live_events: {\n title: 'No $pageview or $screen events in the last 30 days',\n description:\n 'PostHog is not receiving page or screen events from this project.',\n docsUrl: `${POSTHOG_DOCS_URL}/getting-started/install`,\n },\n no_pageleave_events: {\n title: '$pageleave events not being sent',\n description:\n 'Enable pageleave tracking to power bounce rate and session duration.',\n docsUrl: `${POSTHOG_DOCS_URL}/libraries/js#config`,\n },\n scroll_depth: {\n title: 'Scroll depth tracking disabled',\n description:\n 'Turn on scroll depth to capture how far users read each page.',\n docsUrl: `${POSTHOG_DOCS_URL}/libraries/js#config`,\n },\n authorized_urls: {\n title: 'No authorized URLs configured',\n description:\n 'Some web analytics filters require at least one authorized URL to work.',\n docsUrl: `${POSTHOG_DOCS_URL}/web-analytics/faq`,\n },\n reverse_proxy: {\n title: 'No reverse proxy detected',\n description: 'A reverse proxy reduces data loss from ad blockers.',\n docsUrl: `${POSTHOG_DOCS_URL}/advanced/proxy`,\n },\n web_vitals: {\n title: 'Web Vitals tracking disabled',\n description:\n 'Enable Web Vitals to capture LCP, CLS and other performance metrics.',\n docsUrl: `${POSTHOG_DOCS_URL}/web-analytics/web-vitals`,\n },\n materialized_view_failure: {\n title: 'A materialized view is failing',\n description: 'A data modeling pipeline failed its most recent run.',\n docsUrl: `${POSTHOG_DOCS_URL}/data-warehouse`,\n },\n external_data_failure: {\n title: 'External data source is failing',\n description: 'An external data source sync failed and data may be stale.',\n docsUrl: `${POSTHOG_DOCS_URL}/data-warehouse/sources`,\n },\n};\n\nexport const UNKNOWN_KIND_META: KindMeta = {\n title: 'Unknown issue',\n description:\n 'PostHog reported an issue kind the wizard does not yet recognize.',\n docsUrl: POSTHOG_DOCS_URL,\n};\n\nexport function getKindMeta(kind: string): KindMeta {\n return KIND_METADATA[kind] ?? { ...UNKNOWN_KIND_META, title: kind };\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { POSTHOG_DOCTOR_PROGRAM } from './steps.js';\n\nexport const posthogDoctorConfig: ProgramConfig = {\n command: 'doctor',\n description:\n 'Diagnose your PostHog project for configuration issues and setup warnings',\n id: 'posthog-doctor',\n requiresAi: false,\n steps: POSTHOG_DOCTOR_PROGRAM,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n};\n\nexport { POSTHOG_DOCTOR_PROGRAM } from './steps.js';\nexport { fetchHealthIssues } from './fetch.js';\nexport { getKindMeta, KIND_METADATA } from './kind-metadata.js';\nexport type { KindMeta } from './kind-metadata.js';\nexport type {\n HealthIssue,\n HealthIssueSeverity,\n HealthIssueSummary,\n} from './types.js';\n","import { existsSync, statSync } from 'fs';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { findPackageJsons } from '@lib/programs/shared/package-scanning';\n\nexport type WebAnalyticsDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-package-json' }\n | { kind: 'no-posthog'; scannedCount: number };\n\nexport const WEB_ANALYTICS_ABORT_CASES: AbortCase[] = [\n {\n match: /^no web analytics events$/i,\n message: 'No web analytics events',\n body:\n 'The doctor found no $pageview events in the last 30 days, so there is ' +\n 'nothing to audit yet. Make sure PostHog is initialized and capturing ' +\n 'pageviews, then run the doctor again.',\n docsUrl: 'https://posthog.com/docs/web-analytics/getting-started',\n },\n {\n match: /^insufficient permissions$/i,\n message: 'Insufficient permissions',\n body:\n 'The doctor could not query your project — the authenticated token is ' +\n 'missing query access. Re-run the wizard to sign in again, or use a key ' +\n 'with read access to your events.',\n docsUrl: 'https://posthog.com/docs/web-analytics',\n },\n {\n match: /^posthog sdk not installed$/i,\n message: 'PostHog SDK not installed',\n body:\n 'The doctor could not find a PostHog SDK in this project. Install and ' +\n 'configure PostHog first (run `npx @posthog/wizard`), then run the ' +\n 'doctor to check your web analytics setup.',\n docsUrl: 'https://posthog.com/docs/libraries/js',\n },\n];\n\nexport function detectWebAnalyticsPrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: WebAnalyticsDetectError) =>\n setFrameworkContext('detectError', error);\n\n const installDir = session.installDir;\n\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n const matches = findPackageJsons(installDir);\n\n if (matches.length === 0) {\n fail({ kind: 'no-package-json' });\n return;\n }\n\n const sdks = [...new Set(matches.flatMap((m) => m.posthogSdks))];\n\n if (sdks.length === 0) {\n fail({ kind: 'no-posthog', scannedCount: matches.length });\n return;\n }\n\n setFrameworkContext('detectedPosthogSdks', sdks);\n}\n","import type { ProgramStep } from '@lib/programs/program-step';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/steps';\nimport { detectWebAnalyticsPrerequisites } from './detect.js';\n\nexport const WEB_ANALYTICS_DOCTOR_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting prerequisites',\n onReady: (ctx) =>\n detectWebAnalyticsPrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n ...AGENT_SKILL_STEPS,\n];\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { createSkillProgram } from '../agent-skill/index.js';\nimport { WEB_ANALYTICS_DOCTOR_PROGRAM } from './steps.js';\nimport { WEB_ANALYTICS_ABORT_CASES } from './detect.js';\n\nconst REPORT_FILE = 'posthog-web-analytics-report.md';\nconst DOCS_URL = 'https://posthog.com/docs/web-analytics';\n\nexport const webAnalyticsDoctorConfig: ProgramConfig = {\n ...createSkillProgram({\n skillId: 'web-analytics-doctor',\n command: 'web-analytics',\n id: 'web-analytics-doctor',\n description: 'Audit and fix your PostHog web analytics setup',\n integrationLabel: 'web-analytics-doctor',\n customPrompt:\n \"Run the web-analytics-doctor skill to check this project's PostHog web \" +\n 'analytics setup. Audit read-only first, then present the findings to the ' +\n 'user with a single wizard_ask multi-select and apply only the fixes they ' +\n 'choose — editing project code and/or PostHog project settings via the ' +\n 'MCP — before writing the report.',\n successMessage:\n 'Web analytics check complete! You can view the report at ./posthog-web-analytics-report.md',\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Checking your web analytics setup...',\n estimatedDurationMinutes: 5,\n requires: ['posthog-integration'],\n abortCases: WEB_ANALYTICS_ABORT_CASES,\n }),\n steps: WEB_ANALYTICS_DOCTOR_PROGRAM,\n parentCommand: 'audit',\n};\n\nexport { WEB_ANALYTICS_DOCTOR_PROGRAM } from './steps.js';\nexport {\n detectWebAnalyticsPrerequisites,\n WEB_ANALYTICS_ABORT_CASES,\n type WebAnalyticsDetectError,\n} from './detect.js';\n","import type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\n\nexport const MIGRATION_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'migration-intro',\n gate: (session) => session.setupConfirmed,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Migration',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","/**\n * Vendor cost stack — the multi-tool baseline a typical migration target has\n * before consolidating onto PostHog. Numbers from each vendor's published\n * starter pricing.\n */\n\nimport { Text } from 'ink';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const VENDOR_STACK_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 600,\n pause: 9000,\n lines: [\n <Text bold>{' Typical pre-migration stack'}</Text>,\n <Text> </Text>,\n <Text>\n <Text color=\"gray\">{' Sentry'}</Text>\n <Text>{' error tracking '}</Text>\n <Text color=\"red\">{'$26/mo+'}</Text>\n </Text>,\n <Text>\n <Text color=\"gray\">{' LaunchDarkly'}</Text>\n <Text>{' feature flags '}</Text>\n <Text color=\"red\">{'$8.33/mo+'}</Text>\n </Text>,\n <Text>\n <Text color=\"gray\">{' Amplitude'}</Text>\n <Text>{' product analytics '}</Text>\n <Text color=\"red\">{'$49/mo+'}</Text>\n </Text>,\n <Text>\n <Text color=\"gray\">{' Braintrust'}</Text>\n <Text>{' LLM analytics '}</Text>\n <Text color=\"red\">{'$50/mo+'}</Text>\n </Text>,\n <Text color=\"gray\">{' ─────────────────────────────────────'}</Text>,\n <Text>\n <Text>{' Total'}</Text>\n <Text>{' '}</Text>\n <Text bold color=\"red\">\n {'$133/mo+'}\n </Text>\n </Text>,\n <Text dimColor>{' plus ~450KB of JavaScript SDKs'}</Text>,\n ],\n};\n","/**\n * PostHog free-tier highlights — the numbers a migrating team gets back when\n * they consolidate. Sourced from posthog.com/pricing.md.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const FREE_TIER_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 400,\n pause: 9000,\n lines: [\n <Text bold>{' Free every month, on every product'}</Text>,\n <Text> </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,000,000 '}</Text>\n <Text>events </Text>\n <Text dimColor>product analytics</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,000,000 '}</Text>\n <Text>requests </Text>\n <Text dimColor>feature flags + experiments</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 5,000 '}</Text>\n <Text>recordings </Text>\n <Text dimColor>session replay</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 100,000 '}</Text>\n <Text>exceptions </Text>\n <Text dimColor>error tracking</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 100,000 '}</Text>\n <Text>events </Text>\n <Text dimColor>LLM analytics</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 50 GB '}</Text>\n <Text>logs </Text>\n <Text dimColor>logs</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,500 '}</Text>\n <Text>responses </Text>\n <Text dimColor>surveys</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' 1,000,000 '}</Text>\n <Text>rows </Text>\n <Text dimColor>data warehouse</Text>\n </Text>,\n ],\n};\n","/**\n * Pricing structure block — what happens after the free tier.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const PRICING_STRUCTURE_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 500,\n pause: 8000,\n lines: [\n <Text bold>{' After the free tier'}</Text>,\n <Text> </Text>,\n <Text>\n <Text color={Colors.accent}>{' $0 '}</Text>\n <Text>base price · pay only for what you use</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>per-event prices decrease with volume</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>no per-seat charges — your whole team is included</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>web analytics bundled with product analytics</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>experiments bundled with feature flags</Text>\n </Text>,\n <Text>\n <Text color={Colors.accent}>{' ◆ '}</Text>\n <Text>revenue analytics bundled with data warehouse</Text>\n </Text>,\n ],\n};\n","/**\n * Migration learn deck (statsig variant). Statsig is the only `migrate`\n * variant today, so this deck plays as-is when the wizard runs\n * `migrate --product=statsig`. Three movements:\n *\n * 1. Welcome and reassure.\n * 2. What to expect — the migration is replacement-only, takes a few\n * minutes, leaves the build green.\n * 3. What's a little different — how flags and experiments work in\n * PostHog, presented as right-way guidance rather than gotchas.\n *\n * FF/experiments guidance paraphrased from PostHog public docs:\n * - posthog.com/docs/feature-flags/best-practices\n * - posthog.com/docs/feature-flags/common-questions\n * - posthog.com/docs/experiments/best-practices\n */\n\nimport { Text } from 'ink';\nimport type { WizardStore } from '@ui/tui/store';\nimport { Colors } from '@ui/tui/styles';\nimport { TextRevealMode } from '@ui/tui/primitives/TextBlock';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\nimport { StatusPeekTrigger } from '@ui/tui/components/StatusPeekTrigger';\nimport { PRODUCT_SUITE_BLOCK } from '@lib/programs/posthog-integration/content/product-suite';\nimport { LINE_CHART_BLOCK } from '@lib/programs/posthog-integration/content/line-chart';\nimport { FUNNEL_BLOCK } from '@lib/programs/posthog-integration/content/funnel';\nimport { VENDOR_STACK_BLOCK } from './vendor-stack.js';\nimport { FREE_TIER_BLOCK } from './free-tier.js';\nimport { PRICING_STRUCTURE_BLOCK } from './pricing-structure.js';\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] => [\n // ── Welcome ────────────────────────────────────────────────────────────\n {\n content: 'Hello.',\n pause: 3000,\n mode: TextRevealMode.Typewriter,\n animationInterval: 160,\n },\n\n { content: 'The Wizard is an agent.', pause: 4000 },\n\n {\n content:\n 'As we speak, it’s making a plan to migrate from Statsig to PostHog.',\n pause: 6000,\n },\n\n {\n content: 'PostHog covers the cost of running this agent.',\n pause: 4000,\n },\n\n { type: 'clear', pause: 2000 },\n\n {\n pause: 5000,\n persist: true,\n content: <StatusPeekTrigger store={store} />,\n },\n\n {\n pause: 6000,\n persist: true,\n content: (\n <Text>\n Press{' '}\n <Text color={Colors.accent} bold>\n S\n </Text>{' '}\n to expand or collapse the status.\n </Text>\n ),\n },\n\n { type: 'clear', pause: 2000 },\n\n // ── What to expect ─────────────────────────────────────────────────────\n { content: 'Here’s what to expect.', pause: 3000 },\n\n { content: 'The migration takes about ten minutes.', pause: 3000 },\n\n {\n content:\n 'Every Statsig call gets replaced in place with its PostHog equivalent.',\n pause: 5500,\n },\n\n {\n content:\n 'Nothing new gets added. No extra captures, no surprise instrumentation.',\n pause: 5500,\n },\n\n {\n content:\n 'The Statsig package gets removed at the end. We’ll run build and lint to clean up after ourselves.',\n pause: 6500,\n },\n\n { type: 'clear', pause: 2000 },\n\n // ── What's a little different ─────────────────────────────────────────\n {\n content: 'A few things work a little differently in PostHog.',\n pause: 4500,\n },\n\n {\n content: (\n <Text>\n Flags evaluate against a stable user. Call{' '}\n <Text bold color={Colors.accent}>\n identify()\n </Text>{' '}\n first, then check the flag.\n </Text>\n ),\n pause: 6000,\n persist: true,\n },\n\n {\n content:\n 'For anything in the first paint, evaluate server-side and bootstrap the values into the client.',\n pause: 6500,\n },\n\n {\n content: (\n <Text>\n In production, route requests through a reverse proxy to avoid ad\n blockers breaking your flags.{'\\n'}\n <Text dimColor>https://posthog.com/docs/advanced/proxy</Text>\n </Text>\n ),\n pause: 6500,\n persist: true,\n },\n\n {\n content:\n 'When a flag reaches 100% rollout, retire it. Flags are signals, not switches.',\n pause: 5500,\n },\n\n {\n content: (\n <Text>\n Name flags descriptively. No double negatives. Reflect the return type.{' '}\n <Text dimColor>For example </Text>\n <Text bold>show-new-checkout</Text>\n <Text dimColor>.</Text>\n </Text>\n ),\n pause: 6500,\n persist: true,\n },\n\n { type: 'clear', pause: 1500 },\n\n // ── Experiments ────────────────────────────────────────────────────────\n {\n content: (\n <Text bold color={Colors.accent}>\n Experiments\n </Text>\n ),\n pause: 2500,\n persist: true,\n },\n\n {\n content:\n 'Change one thing per variant. Multiple changes in one variant blur the result.',\n pause: 5500,\n },\n\n {\n content:\n 'Decide the running time up front. PostHog includes a sample-size and duration calculator in the setup flow.',\n pause: 6500,\n },\n\n {\n content: 'Roll out to 5–10% first. Watch the metrics. Then increase.',\n pause: 5000,\n },\n\n {\n content:\n 'Exclude users who already completed the flow. They can’t be affected by the test.',\n pause: 5500,\n },\n\n { type: 'clear', pause: 1500 },\n\n // ── Close ──────────────────────────────────────────────────────────────\n {\n content: 'Flags and experiments live alongside the rest of your data.',\n pause: 4500,\n },\n\n {\n content: 'Ship behind a flag, watch replays, check analytics for impact.',\n pause: 4500,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content:\n 'PostHog also provides every other analytics and AI tool to build your product.',\n pause: 4500,\n },\n\n PRODUCT_SUITE_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'And consolidating onto one platform saves real money.',\n pause: 4500,\n },\n\n { content: 'Here’s the math.', pause: 1500 },\n\n VENDOR_STACK_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'Pricing is usage-based, with a generous free tier.',\n pause: 4000,\n },\n\n FREE_TIER_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n PRICING_STRUCTURE_BLOCK,\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'Gain clarity and really understand your users.',\n pause: 4000,\n },\n\n { content: 'Use trends to measure growth.', pause: 2500 },\n\n LINE_CHART_BLOCK,\n\n { type: 'clear', pause: 500 },\n\n { content: 'Use funnels to reveal bottlenecks.', pause: 2500 },\n\n FUNNEL_BLOCK,\n];\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { WIZARD_TOOL_NAMES } from '@lib/wizard-tools';\nimport { MIGRATION_PROGRAM } from './steps.js';\nimport { getContentBlocks } from './content/index.js';\n\nconst MIGRATION_REPORT_FILE = 'migration-report.md';\n\nconst MIGRATION_ABORT_CASES: AbortCase[] = [\n {\n match: /^no source-sdk calls found$/i,\n message: 'No source-SDK calls found',\n body:\n 'The migration needs an existing third-party SDK to migrate from. No ' +\n 'calls to the source SDK appear anywhere in this project. If you ' +\n \"haven't installed PostHog yet, you don't need this command — run \" +\n '`npx @posthog/wizard@latest` to add PostHog from scratch.',\n },\n];\n\n// Default skill id when nothing else picks one. The `wizard migrate <vendor>`\n// subcommands override this via skillCommandFactory using each manifest\n// entry's skillId, so this default only kicks in for legacy callers (e.g.\n// programmatic uses of migrationConfig directly).\nconst DEFAULT_MIGRATE_SKILL_ID = 'migrate-statsig';\n\nexport const migrationConfig: ProgramConfig = {\n command: 'migrate',\n description: 'Migrate to PostHog from another analytics provider',\n id: 'migration',\n skillId: DEFAULT_MIGRATE_SKILL_ID,\n steps: MIGRATION_PROGRAM,\n reportFile: MIGRATION_REPORT_FILE,\n getContentBlocks,\n allowedTools: ['Agent'],\n disallowedTools: [WIZARD_TOOL_NAMES.wizardAsk],\n run: {\n skillId: DEFAULT_MIGRATE_SKILL_ID,\n integrationLabel: 'migration',\n customPrompt: () =>\n 'Migrate this project from its existing third-party analytics, ' +\n 'feature-flag, and observability tools to PostHog. Run the `migrate` ' +\n 'skill end-to-end: follow the step chain starting at ' +\n 'references/1-presence.md. Only replace existing source-SDK call sites ' +\n 'with PostHog equivalents — make zero unrelated changes and no ' +\n `net-new instrumentation. The final report is written to ./${MIGRATION_REPORT_FILE}.`,\n successMessage: `Migration complete! View the report at ./${MIGRATION_REPORT_FILE}`,\n reportFile: MIGRATION_REPORT_FILE,\n docsUrl: '',\n spinnerMessage: 'Migrating to PostHog...',\n estimatedDurationMinutes: 8,\n abortCases: MIGRATION_ABORT_CASES,\n },\n requires: ['posthog-integration'],\n};\n\nexport { MIGRATION_PROGRAM } from './steps.js';\n","/**\n * Source maps upload prerequisite detection.\n *\n * Scans the project for signals that identify the platform and build system,\n * then maps to one of the context-mill `error-tracking-upload-source-maps-*`\n * skill variants. Results are written to frameworkContext for the intro\n * screen to render and for the agent prompt to consume.\n */\n\nimport type { Dirent } from 'fs';\nimport { readFileSync, readdirSync, existsSync, statSync } from 'fs';\nimport { join, relative } from 'path';\nimport { IGNORED_DIRS } from '@utils/file-utils';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\n\n/**\n * Skill variants published under the `error-tracking-upload-source-maps`\n * category in context-mill. The agent loads\n * `error-tracking-upload-source-maps-<variant>`.\n */\nexport type SkillVariant =\n | 'web'\n | 'nextjs'\n | 'node'\n | 'react'\n | 'angular'\n | 'nuxt'\n | 'react-native'\n | 'android'\n | 'flutter'\n | 'ios'\n | 'vite'\n | 'webpack'\n | 'rollup';\n\nconst DISPLAY_NAME: Record<SkillVariant, string> = {\n web: 'Web (JavaScript)',\n nextjs: 'Next.js',\n node: 'Node.js',\n react: 'React',\n angular: 'Angular',\n nuxt: 'Nuxt',\n 'react-native': 'React Native',\n android: 'Android',\n flutter: 'Flutter',\n ios: 'iOS',\n vite: 'Vite',\n webpack: 'Webpack',\n rollup: 'Rollup',\n};\n\nconst POSTHOG_SDKS = [\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n];\n\n/**\n * Structured detection errors. The screen renders each kind into JSX\n * with proper formatting — keeps error data separate from presentation.\n */\nexport type SourceMapsDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-project-files' }\n | { kind: 'unsupported-platform'; detected: string }\n | { kind: 'no-posthog-sdk'; platform: SkillVariant };\n\n/** `[ABORT] <reason>` cases the source maps skill can emit. */\nexport const SOURCE_MAPS_ABORT_CASES: AbortCase[] = [\n {\n match: /^no posthog sdk detected$/i,\n message: 'No PostHog SDK detected',\n body:\n 'The agent could not find a PostHog SDK in your project. ' +\n 'Source map upload requires the SDK to already be installed so it can ' +\n 'report errors. Run `npx @posthog/wizard` first to install the SDK.',\n docsUrl: 'https://posthog.com/docs/error-tracking',\n },\n {\n match: /^build command not found$/i,\n message: 'Build command not found',\n body:\n 'The agent could not identify how to build your project. Source map ' +\n 'upload runs as part of the production build. Add a build script to ' +\n 'your project and run this wizard again.',\n docsUrl: 'https://posthog.com/docs/error-tracking/upload-source-maps',\n },\n];\n\n// ── File / dependency probes ─────────────────────────────────────────\n\ninterface ProjectSignals {\n packageJsons: Array<{ path: string; deps: Set<string> }>;\n hasXcodeProject: boolean;\n hasPodfile: boolean;\n hasSwiftPackage: boolean;\n hasGradle: boolean;\n hasPubspec: boolean;\n scannedFileCount: number;\n}\n\nfunction collectSignals(installDir: string, maxDepth = 3): ProjectSignals {\n const signals: ProjectSignals = {\n packageJsons: [],\n hasXcodeProject: false,\n hasPodfile: false,\n hasSwiftPackage: false,\n hasGradle: false,\n hasPubspec: false,\n scannedFileCount: 0,\n };\n\n function scan(dir: string, depth: number): void {\n if (depth > maxDepth) return;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.name !== '.') continue;\n if (IGNORED_DIRS.has(entry.name)) continue;\n\n const fullPath = join(dir, entry.name);\n\n if (entry.isFile()) {\n signals.scannedFileCount += 1;\n if (entry.name === 'package.json') {\n try {\n const pkg = JSON.parse(readFileSync(fullPath, 'utf-8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const deps = new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n signals.packageJsons.push({\n path: relative(installDir, fullPath) || 'package.json',\n deps,\n });\n } catch {\n // skip malformed package.json\n }\n } else if (entry.name === 'Podfile') {\n signals.hasPodfile = true;\n } else if (entry.name === 'Package.swift') {\n signals.hasSwiftPackage = true;\n } else if (entry.name === 'pubspec.yaml') {\n signals.hasPubspec = true;\n } else if (\n entry.name === 'build.gradle' ||\n entry.name === 'build.gradle.kts' ||\n entry.name === 'settings.gradle' ||\n entry.name === 'settings.gradle.kts'\n ) {\n signals.hasGradle = true;\n }\n } else if (entry.isDirectory()) {\n if (entry.name.endsWith('.xcodeproj')) {\n signals.hasXcodeProject = true;\n } else {\n scan(fullPath, depth + 1);\n }\n }\n }\n }\n\n scan(installDir, 0);\n return signals;\n}\n\n// ── Skill selection ──────────────────────────────────────────────────\n\nfunction pickJsVariant(deps: Set<string>): SkillVariant {\n // Opinionated full-stack frameworks first — they own their build pipeline\n // and have dedicated skill variants, so bundler detection underneath\n // them is irrelevant.\n if (deps.has('react-native')) return 'react-native';\n if (deps.has('nuxt')) return 'nuxt';\n if (deps.has('next')) return 'nextjs';\n if (deps.has('@angular/core')) return 'angular';\n // Bundlers next — prefer these over the bare `react` variant because\n // their skills are simpler (one bundler-plugin config) than wiring\n // posthog-cli into an arbitrary React setup.\n if (deps.has('vite')) return 'vite';\n if (deps.has('webpack')) return 'webpack';\n if (deps.has('rollup')) return 'rollup';\n // Plain React with no recognised bundler.\n if (deps.has('react')) return 'react';\n // Server-only Node project\n if (deps.has('posthog-node')) return 'node';\n // Fallback: generic web\n return 'web';\n}\n\nfunction selectVariant(signals: ProjectSignals): SkillVariant | null {\n // Mobile / native first — they don't coexist with JS bundlers in the\n // detection signals we look at.\n if (signals.hasPubspec) return 'flutter';\n if (signals.hasXcodeProject || signals.hasPodfile || signals.hasSwiftPackage)\n return 'ios';\n if (signals.hasGradle) return 'android';\n\n if (signals.packageJsons.length > 0) {\n // Union all deps across package.json files (covers monorepos)\n const allDeps = new Set<string>();\n for (const pkg of signals.packageJsons) {\n for (const dep of pkg.deps) allDeps.add(dep);\n }\n return pickJsVariant(allDeps);\n }\n\n return null;\n}\n\nfunction hasPostHogSdk(signals: ProjectSignals): boolean {\n for (const pkg of signals.packageJsons) {\n for (const sdk of POSTHOG_SDKS) {\n if (pkg.deps.has(sdk)) return true;\n }\n }\n // For native platforms the PostHog SDK lives outside package.json and\n // is detected by the agent during the skill run. Assume present here.\n return (\n signals.hasXcodeProject ||\n signals.hasPodfile ||\n signals.hasSwiftPackage ||\n signals.hasGradle ||\n signals.hasPubspec\n );\n}\n\n// ── Entry point ──────────────────────────────────────────────────────\n\nexport const SOURCE_MAPS_CONTEXT_KEYS = {\n skillVariant: 'sourceMapsSkillVariant',\n displayName: 'sourceMapsDisplayName',\n packagePaths: 'sourceMapsPackagePaths',\n detectError: 'detectError',\n} as const;\n\n/**\n * Scan `session.installDir` for platform / build-system signals. Writes\n * detection results into frameworkContext via the callback — either the\n * picked skill variant + display name, or a `SourceMapsDetectError`.\n *\n * The skill install happens later in the agent run, not here. This step\n * only picks which variant the prompt should ask the agent to load.\n */\nexport function detectSourceMapsPrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: SourceMapsDetectError) =>\n setFrameworkContext(SOURCE_MAPS_CONTEXT_KEYS.detectError, error);\n\n const installDir = session.installDir;\n\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n const signals = collectSignals(installDir);\n const variant = selectVariant(signals);\n\n // This program currently targets JS-like stacks only. Avoid selecting native\n // platforms until dedicated skill variants are available.\n if (\n variant &&\n ['react-native', 'flutter', 'ios', 'android'].includes(variant)\n ) {\n fail({ kind: 'unsupported-platform', detected: variant });\n return;\n }\n\n if (!variant) {\n if (signals.scannedFileCount === 0) {\n fail({ kind: 'no-project-files' });\n } else {\n fail({ kind: 'unsupported-platform', detected: 'unknown' });\n }\n return;\n }\n\n if (!hasPostHogSdk(signals)) {\n fail({ kind: 'no-posthog-sdk', platform: variant });\n return;\n }\n\n setFrameworkContext(SOURCE_MAPS_CONTEXT_KEYS.skillVariant, variant);\n setFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.displayName,\n DISPLAY_NAME[variant],\n );\n setFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.packagePaths,\n signals.packageJsons.map((p) => p.path),\n );\n}\n\nexport { DISPLAY_NAME as VARIANT_DISPLAY_NAME };\n","/**\n * Error tracking source maps upload program step list.\n *\n * Detection runs headless via onReady, then the user sees a custom intro\n * showing the picked skill variant. Auth → agent run → outro mirrors the\n * other programs.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { RunPhase } from '@lib/wizard-session';\nimport {\n evaluateWizardReadiness,\n WizardReadiness,\n SIGNUP_WIZARD_READINESS_CONFIG,\n getBlockingServiceKeys,\n} from '@lib/health-checks/readiness';\nimport { detectSourceMapsPrerequisites } from './detect.js';\n\nfunction healthCheckReady(session: WizardSession): boolean {\n if (!session.readinessResult) return false;\n\n if (session.signup) {\n const hardBlocking = getBlockingServiceKeys(\n session.readinessResult.health,\n SIGNUP_WIZARD_READINESS_CONFIG,\n );\n const defaultBlocking = getBlockingServiceKeys(\n session.readinessResult.health,\n );\n if (hardBlocking.length === 0 && defaultBlocking.length === 0) return true;\n return session.outageDismissed;\n }\n\n if (session.readinessResult.decision === WizardReadiness.No) {\n return session.outageDismissed;\n }\n return true;\n}\n\nexport const ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting platform',\n // Headless: scans for platform / build-system signals and picks the\n // matching context-mill skill variant. Writes either the variant or\n // a detectError to frameworkContext.\n onReady: (ctx) =>\n detectSourceMapsPrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'source-maps-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'health-check',\n label: 'Health check',\n screenId: 'health-check',\n gate: healthCheckReady,\n onInit: (ctx) => {\n evaluateWizardReadiness()\n .then((readiness) => {\n ctx.setReadinessResult(readiness);\n })\n .catch(() => {\n ctx.setReadinessResult({\n decision: WizardReadiness.Yes,\n health: {} as never,\n reasons: [],\n });\n });\n },\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Upload source maps',\n screenId: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'outro',\n label: 'Done',\n screenId: 'source-maps-outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screenId: 'keep-skills',\n },\n];\n","import { AgentSignals } from '@lib/agent/agent-interface';\nimport type { SkillVariant } from './detect.js';\n\nexport type SourceMapsUploadPromptParams = {\n displayName: string | undefined;\n variant: SkillVariant;\n skillId: string;\n projectId: number;\n host: string;\n settingsUrl: string;\n uiHost: string;\n};\n\nexport const SOURCE_MAPS_DETECTION_FAILED_PROMPT = `Detection did not pick a source maps skill variant for this project.\nEmit: ${AgentSignals.ABORT} unsupported-platform\nThen halt.`;\n\nexport function buildSourceMapsUploadPrompt(\n params: SourceMapsUploadPromptParams,\n): string {\n const {\n displayName,\n variant,\n skillId,\n projectId,\n host,\n settingsUrl,\n uiHost,\n } = params;\n const platformLabel = displayName ?? variant;\n\n return `You are wiring up PostHog Error Tracking source map upload for this ${platformLabel} project.\n\nProject context:\n- PostHog Project ID: ${projectId}\n- PostHog Host: ${host}\n- Detected platform: ${platformLabel}\n- Skill to use: ${skillId}\n- Personal API keys settings page: ${settingsUrl}\n\nThe skill you install in STEP 2 is the source of truth for the HOW of every\nstep: its \"## Steps\" section has an overview, tips and per-technology\nexamples for each named step, and its reference files carry the exact\nper-framework API. The STEPS below give the order, the conditionals, and the\nwizard-specific mechanics (which MCP tool to call, signals to emit) — read\nthe matching skill step (named in parentheses) before doing the work, and do\nnot invent steps the skill doesn't describe.\n\nFollow these steps IN ORDER. Do not skip or reorder.\n\nYour FIRST message must contain ONLY parallel tool calls, in this order:\n - the STEP 1 wizard_ask call FIRST — tool calls execute as they stream,\n so this puts the API-key prompt in front of the user within seconds —\n then\n - one TaskCreate call PER task below, all in this same message (the tool\n takes a single task per call). The TUI shows only the subject, so keep\n every description to a few words — never a sentence.\nDo not read files, explore the project, or write any text first, and keep\nany thinking before the calls to a single short sentence.\n\nUse exactly these tasks, in this order — do not collapse, rename, or omit\nany of them. Getting the API key is NOT a task — its prompt is already on\nscreen by the time the list renders:\n 1. Install source maps skill\n 2. Apply build-config changes (per skill)\n 3. Make credentials readable at build time\n 4. Write keys to .env\n 5. Identify build & run commands\n 6. Set up CI for auto-upload\n 7. Test the local setup\n 8. Summarise & hand off\nDrive the list with TaskUpdate — mark a task in_progress when you start it\nand completed when done. ALWAYS keep task 7 (\"Test the local setup\") in the\nlist even if the user declines it in STEP 8: mark it completed rather than\ndeleting it, so the user can see it was offered.\n\nSTEP 1 — Get a personal API key from the user. (skill: \"Get a personal API key\")\n This wizard_ask call ships in your FIRST message, per the rule above.\n The wizard cannot mint keys — never call the PostHog API or any tool to\n create one. Ask the user with the wizard_ask MCP tool; you receive the\n answer as a vaulted secretRef (never the raw value), which you reuse in\n STEP 5:\n {\n id: \"api-key\",\n prompt: \"Paste your PostHog personal API key below.\\\\n\\\\nDon't have one yet? Create one here:\\\\n${settingsUrl}\\\\n\\\\nWhen creating the key, choose the 'Source map upload' preset, then come back and paste it here.\",\n kind: \"text\",\n sensitive: true\n }\n Keep the \\\\n line breaks exactly as written — Ink's <Text> renders them\n as separate lines. The answer is { secretRef: \"secret:...\" }.\n If wizard_ask is unavailable (CI / non-interactive), emit\n ${AgentSignals.ABORT} requires-interactive-mode and halt.\n\nSTEP 2 — Install the skill.\n Call install_skill (wizard-tools MCP server) with skillId \"${skillId}\".\n Do NOT run shell commands to install skills. Then read the installed\n SKILL.md and its reference files — they drive STEPS 3-9.\n If install fails, emit ${AgentSignals.ERROR_RESOURCE_MISSING} skill ${skillId} could not be installed.\n\nSTEP 3 — Apply build-config changes. (skill: \"Apply build-config changes\")\n Make the bundler / build-config changes the skill's step instructs. The\n skill and its reference are the source of truth for this platform.\n\nSTEP 4 — Make the credentials readable at build time. (skill: \"Make credentials available at build time\")\n Follow the skill's step. Wizard-specific: if it calls for a loader (e.g.\n \\`dotenv\\`), install it SILENTLY — do NOT ask the user or call wizard_ask.\n Skip this step entirely if the platform already auto-loads .env.\n\nSTEP 5 — Write the credentials to the env file. (skill: \"Write credentials to the env file\")\n Use the wizard-tools MCP server. Reuse the env file the skill tells you to\n pick — the prerequisite PostHog integration usually already wrote\n POSTHOG_* vars to one, so seed your keys alongside them.\n - First call check_env_keys on that file (returns present/absent, never\n values — don't read the file directly).\n - Then call set_env_values, passing the STEP 1 secretRef as a value\n object, not a literal string:\n values: {\n \"POSTHOG_CLI_API_KEY\": { secretRef: \"<the ref from STEP 1>\" },\n \"POSTHOG_CLI_PROJECT_ID\": \"${projectId}\",\n \"POSTHOG_CLI_HOST\": \"${host}\"\n }\n Variable names follow the skill's per-uploader conventions. The wizard\n resolves the ref locally before writing, so you never see the key value.\n\nSTEP 6 — Identify the build AND run commands. (skill: \"Identify the build and run commands\")\n Per the skill, resolve the production BUILD command and the RUN command\n for THIS project (use detect_package_manager for the package manager). Do\n NOT run either yourself — the user runs them. If you cannot identify a\n build command, emit ${AgentSignals.ABORT} build command not found.\n\nSTEP 7 — Set up CI for automatic uploads. (skill: \"Set up CI for automatic uploads\")\n Source maps only upload when the production build runs, so the build's\n CI/CD must carry the same upload credentials you wrote in STEP 5. Do this\n step without asking — there is no opt-in question for it. Follow the\n skill's \"Set up CI for automatic uploads\" step — it is the source of\n truth for tracing where the production build runs and wiring the\n credentials through every layer, whatever the CI provider.\n Wizard-specific rules on top:\n - Trace the deploy path by reading the project's files — do NOT ask the\n user, and do NOT invent config that isn't there.\n - Carry every manual follow-up the skill has you hand off (secrets the\n user must create, an untraceable build path) into STEP 9.\n\nSTEP 8 — Offer to test the local setup. (skill: \"Test the local setup\")\n Call wizard_ask:\n {\n id: \"test-affordance\",\n prompt: \"Want me to help you test your local setup? I'll add a temporary test button (or route) to your app so you can confirm errors show up in Error Tracking with readable stack traces after your next build. I'll remove it once you've confirmed it works.\",\n kind: \"single\",\n options: [\n { label: \"Yes, help me test it\", value: \"yes\" },\n { label: \"No, I'll test on my own later\", value: \"no\" }\n ]\n }\n\n If \"no\", skip to STEP 9.\n\n If \"yes\", follow the skill's \"Test the local setup\" step for the\n platform-appropriate affordance, the captureException shape, the\n placement, and the read-before-edit / always-revert rules. Then pause for\n the user with wizard_ask, baking the EXACT build and run commands from\n STEP 6 (and the exact button label / route) into the prompt as literal,\n copy-pasteable steps. Separate each numbered step with \\\\n\\\\n so the TUI\n renders them as distinct lines:\n {\n id: \"test-done\",\n prompt: \"1) Run \\`<your detected build command>\\` to upload source maps and build the app with the test affordance.\\\\n\\\\n2) Start the app with \\`<your detected run command>\\`, then click the \\\\\"<your test button label>\\\\\" button (or hit \\`<your test route>\\`).\\\\n\\\\n3) Open Error Tracking in PostHog (${uiHost}/project/${projectId}/error_tracking) and confirm the test error appears with a source-resolved stack trace pointing at real source files (not minified bundle paths).\\\\n\\\\nWhen you're done, select Continue and I'll revert the test code.\",\n kind: \"single\",\n options: [{ label: \"Continue (revert test code)\", value: \"continue\" }]\n }\n After the user continues, revert the test code per the skill's rules and\n surface any failure in STEP 9.\n\nSTEP 9 — Summarise and hand off. (skill: \"Verify and hand off\")\n Follow the skill's \"Verify and hand off\" step. The Symbol sets page for\n this project — where the user confirms the upload landed — is:\n ${uiHost}/project/${projectId}/error_tracking/configuration\n`;\n}\n","/**\n * Source-maps learn-deck — the narrative played in the run screen's left\n * pane (LearnCard) while the agent wires source-map upload into the build.\n *\n * It educates the user on what source maps are and why uploading them\n * matters, built around a before/after stack-trace contrast: a minified\n * production trace nobody can read, then the same trace resolved back to\n * real source. Program-owned; wired onto the program's getContentBlocks.\n *\n * Lines stay narrow (~36 cols) because this renders in the left half of a\n * split pane — see LearnCard's paneWidth math.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { WizardStore } from '@ui/tui/store';\nimport { TextRevealMode } from '@ui/tui/primitives/TextBlock';\nimport {\n isClearBlock,\n type ContentBlock,\n} from '@ui/tui/primitives/content-types';\nimport { StatusPeekTrigger } from '@ui/tui/components/StatusPeekTrigger';\n\n/**\n * Per-slide dwell multiplier. Each block stays on screen for `pause * SLIDE_PACE`\n * ms after it finishes animating, before the deck advances. Bump this single\n * knob to give every slide more reading time. Clear (page-break) blocks are\n * left untouched so the blank gap between slides stays snappy.\n */\nconst SLIDE_PACE = 1.5;\n\nconst withPace = (block: ContentBlock): ContentBlock => {\n if (typeof block === 'string' || isClearBlock(block) || block.pause == null) {\n return block;\n }\n return { ...block, pause: Math.round(block.pause * SLIDE_PACE) };\n};\n\n/** Apply the dwell multiplier to every block in a deck. */\nconst pace = (blocks: ContentBlock[]): ContentBlock[] => blocks.map(withPace);\n\n/**\n * A minified production stack trace — the problem source maps solve. Framed as\n * a labelled, muted example (no error-red ✘) so a glance reads it as\n * illustrative content, not as the wizard itself having errored mid-run.\n */\nconst MINIFIED_TRACE: ContentBlock = {\n type: 'lines',\n interval: 400,\n pause: 7000,\n lines: [\n <Text dimColor>{'example — minified production trace'}</Text>,\n <Text color={Colors.muted}>{' TypeError: cart is undefined'}</Text>,\n <Text dimColor>{' at t.min.js:1:48213'}</Text>,\n <Text dimColor>{' at t.min.js:1:9402'}</Text>,\n <Text dimColor>{' at t.min.js:1:71150'}</Text>,\n ],\n};\n\n/** The same trace, resolved through uploaded source maps. */\nconst RESOLVED_TRACE: ContentBlock = {\n type: 'lines',\n interval: 400,\n pause: 8000,\n lines: [\n <Text dimColor>{'example — resolved with source maps'}</Text>,\n <Text color={Colors.success}>{' ✔ TypeError: cart is undefined'}</Text>,\n <Text>\n <Text dimColor>{' at '}</Text>\n <Text color=\"cyan\">Cart.tsx:42</Text>\n <Text dimColor>{' loadCart'}</Text>\n </Text>,\n <Text>\n <Text dimColor>{' at '}</Text>\n <Text color=\"cyan\">App.tsx:88</Text>\n <Text dimColor>{' render'}</Text>\n </Text>,\n <Text>\n <Text dimColor>{' at '}</Text>\n <Text color=\"cyan\">index.tsx:5</Text>\n <Text dimColor>{' main'}</Text>\n </Text>,\n ],\n};\n\n/**\n * How a bundle is tied to its map: PostHog injects a chunk-ID marker into the\n * built JS and stamps the matching source map with the same ID.\n */\nconst CHUNK_ID_LINK: ContentBlock = {\n type: 'lines',\n interval: 450,\n pause: 7500,\n lines: [\n <Text dimColor>app.min.js</Text>,\n <Text dimColor>{' …minified code…'}</Text>,\n <Text>\n <Text color=\"cyan\">{' //# chunkId=a1b2c3d4'}</Text>\n <Text dimColor>{' ← injected'}</Text>\n </Text>,\n <Text dimColor>{' ↕ matched by id'}</Text>,\n <Text>\n <Text dimColor>app.min.js.map</Text>\n <Text dimColor>{' ← uploaded'}</Text>\n </Text>,\n ],\n};\n\n/** Many similar exceptions collapse into a single issue. */\nconst GROUPING: ContentBlock = {\n type: 'lines',\n interval: 450,\n pause: 7000,\n lines: [\n <Text dimColor>{'exception ─┐'}</Text>,\n <Text>\n <Text dimColor>{'exception ─┼──→ '}</Text>\n <Text color={Colors.accent} bold>\n 1 issue\n </Text>\n </Text>,\n <Text dimColor>{'exception ─┘'}</Text>,\n ],\n};\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] =>\n pace([\n {\n content: 'Welcome.',\n pause: 3000,\n mode: TextRevealMode.Typewriter,\n animationInterval: 160,\n },\n\n {\n content: \"I'm wiring PostHog Error Tracking into your build.\",\n pause: 5000,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'When you ship to production, your code gets minified.',\n pause: 5000,\n },\n {\n content: 'Thousands of readable lines collapse into one dense bundle.',\n pause: 5000,\n },\n {\n content: 'So a thrown error gives you a stack trace like this:',\n pause: 2000,\n },\n\n MINIFIED_TRACE,\n\n { content: 'Just offsets into a file no human can read.', pause: 5000 },\n\n { type: 'clear', pause: 1500 },\n\n { content: 'Source maps are the key.', pause: 3500 },\n {\n content:\n 'They map every position in that bundle back to your original source — the real file, line, and function.',\n pause: 6000,\n },\n {\n content:\n \"Right now I'm hooking source-map generation and upload into your build, tied to each release you ship.\",\n pause: 6000,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'But how does PostHog know which map belongs to which build?',\n pause: 4500,\n },\n {\n content:\n 'During the build, it injects a unique chunk ID into each bundle:',\n pause: 2500,\n },\n\n CHUNK_ID_LINK,\n\n {\n content:\n 'The matching source map is stamped with that same ID before it ships to PostHog.',\n pause: 6000,\n },\n {\n content:\n 'When an error comes in, PostHog reads the chunk ID off the bundle, finds the map with the exact same ID, and uses it to map each frame back to your source — even for a release you shipped weeks ago.',\n pause: 8000,\n },\n\n { type: 'clear', pause: 1500 },\n\n { content: 'So that same error becomes:', pause: 2000 },\n\n RESOLVED_TRACE,\n\n {\n content: 'Readable stack traces, straight from production.',\n pause: 5000,\n },\n {\n content: 'You debug a live error like it happened on your own machine.',\n pause: 6000,\n },\n\n { type: 'clear', pause: 1500 },\n\n { content: 'Zooming out — this is how Error Tracking works.', pause: 4000 },\n {\n content: 'Every error your app throws is captured as an exception.',\n pause: 5000,\n },\n {\n content: 'PostHog groups similar exceptions into a single issue:',\n pause: 2500,\n },\n\n GROUPING,\n\n {\n content:\n 'So a bug that fires ten thousand times is one issue to triage — not ten thousand alerts.',\n pause: 6500,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n content: 'And this is where source maps earn their keep again.',\n pause: 4500,\n },\n {\n content:\n 'Grouping reads the stack trace. Minified frames all look alike — so unrelated crashes get merged, and one real bug scatters across many issues.',\n pause: 8000,\n },\n {\n content:\n 'With source maps, PostHog groups on your real frames — so each distinct bug lands as one clean issue.',\n pause: 7000,\n },\n\n { type: 'clear', pause: 1500 },\n\n {\n pause: 5000,\n persist: true,\n content: <StatusPeekTrigger store={store} />,\n },\n {\n pause: 90000,\n content: (\n <Text>\n Press{' '}\n <Text color={Colors.accent} bold>\n S\n </Text>{' '}\n to follow along — or sit tight, I'll let you know when it's done.\n </Text>\n ),\n },\n ]);\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { OutroKind } from '@lib/wizard-session';\nimport { ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM } from './steps.js';\nimport {\n buildSourceMapsUploadPrompt,\n SOURCE_MAPS_DETECTION_FAILED_PROMPT,\n} from './prompt.js';\nimport {\n SOURCE_MAPS_ABORT_CASES,\n SOURCE_MAPS_CONTEXT_KEYS,\n type SkillVariant,\n} from './detect.js';\nimport { getContentBlocks } from './content/index.js';\nimport { getUiHostFromHost } from '@utils/urls';\n\nconst REPORT_FILE = 'posthog-source-maps-report.md';\nconst DOCS_URL = 'https://posthog.com/docs/error-tracking/upload-source-maps';\n\nexport const errorTrackingUploadSourceMapsConfig: ProgramConfig = {\n command: 'upload-source-maps',\n description: 'Upload source maps to PostHog Error Tracking',\n id: 'error-tracking-upload-source-maps',\n requiresAi: true,\n steps: ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM,\n reportFile: REPORT_FILE,\n getContentBlocks,\n requires: ['posthog-integration'],\n\n run: (session: WizardSession): Promise<ProgramRun> => {\n const variant = session.frameworkContext[\n SOURCE_MAPS_CONTEXT_KEYS.skillVariant\n ] as SkillVariant | undefined;\n const displayName = session.frameworkContext[\n SOURCE_MAPS_CONTEXT_KEYS.displayName\n ] as string | undefined;\n\n const skillId = variant\n ? `error-tracking-upload-source-maps-${variant}`\n : undefined;\n\n return Promise.resolve({\n integrationLabel: 'error-tracking-upload-source-maps',\n // Skill is installed by the agent (after the API-key choice is made)\n // rather than pre-installed by the runner, so leave skillId unset.\n successMessage: 'Source maps wired up!',\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Wiring up source maps...',\n estimatedDurationMinutes: 3,\n abortCases: SOURCE_MAPS_ABORT_CASES,\n // The flow parks on wizard_ask while the user does slow work — create\n // a personal API key in the browser (STEP 1), or run a production\n // build, trigger the test error, and check Error Tracking (STEP 8).\n // The 5-minute default cancels the question mid-task and the agent\n // wraps up to the outro, so give these answers half an hour.\n askTimeoutMs: 30 * 60 * 1000,\n\n customPrompt: (ctx) => {\n if (!skillId || !variant) {\n // Detection failed but the user got past the intro somehow.\n // Tell the agent to abort with a structured signal so the runner\n // renders a friendly outro.\n return SOURCE_MAPS_DETECTION_FAILED_PROMPT;\n }\n\n const uiHost = getUiHostFromHost(ctx.host).replace(/\\/$/, '');\n\n return buildSourceMapsUploadPrompt({\n displayName,\n variant,\n skillId,\n projectId: ctx.projectId,\n host: ctx.host,\n settingsUrl: `${uiHost}/project/${ctx.projectId}/settings/user-api-keys`,\n uiHost,\n });\n },\n\n postRun: (sess) => {\n // Stash a hint for the outro about what variant we shipped.\n if (variant) {\n sess.frameworkContext['sourceMapsCompletedVariant'] = variant;\n }\n return Promise.resolve();\n },\n\n buildOutroData: () => {\n // SourceMapsOutroScreen renders static \"what we did + how it works\"\n // guidance, so no per-run `changes` list is needed here.\n return {\n kind: OutroKind.Success as const,\n message: 'Source maps wired up!',\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n };\n },\n });\n },\n};\n\nexport { ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM } from './steps.js';\nexport {\n detectSourceMapsPrerequisites,\n SOURCE_MAPS_ABORT_CASES,\n SOURCE_MAPS_CONTEXT_KEYS,\n VARIANT_DISPLAY_NAME,\n type SkillVariant,\n type SourceMapsDetectError,\n} from './detect.js';\n","/**\n * MCP add / remove / tutorial programs.\n *\n * None of these run the agent pipeline — they're TUI-only flows invoked\n * by the `mcp add` / `mcp remove` / `mcp tutorial` subcommands in\n * bin.ts. They live in the program registry so the screen sequence is\n * derived alongside every other program (no special-cases in\n * screen-sequences.ts).\n */\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport { McpOutcome } from '@lib/wizard-session';\n\nexport const mcpAddConfig: ProgramConfig = {\n id: 'mcp-add',\n requiresAi: false,\n description: 'Add PostHog MCP server to supported clients',\n // Order: install → Slack → tutorial. Slack runs before the tutorial\n // because it renders gracefully without credentials (no surprise\n // OAuth on the loginless install path). The tutorial is last so its\n // explicit \"Start tutorial\" opt-in is the moment OAuth fires — and\n // skipping the tutorial doesn't bury Slack discovery behind a\n // dismissal screen.\n steps: [\n {\n id: 'mcp-add',\n label: 'Add MCP server',\n screenId: 'mcp-add',\n isComplete: (s) => s.mcpComplete,\n },\n {\n id: 'slack-connect',\n label: 'Connect Slack',\n screenId: 'slack-connect',\n // Gate on a successful install so no-clients / skipped / failed\n // outcomes go straight to program end without a \"what's next\" prompt.\n show: (s) => s.mcpOutcome === McpOutcome.Installed,\n isComplete: (s) => s.slackStepDismissed,\n },\n {\n id: 'mcp-suggested-prompts',\n label: 'Suggested prompts',\n screenId: 'mcp-suggested-prompts',\n // Same install gate — without a working MCP there's nothing to\n // talk to from the tutorial.\n show: (s) => s.mcpOutcome === McpOutcome.Installed,\n isComplete: (s) => s.mcpSuggestedPromptsDismissed,\n },\n ],\n};\n\n/**\n * `wizard mcp remove` — single-step uninstall flow.\n *\n * DO NOT append `mcp-suggested-prompts` (or any other tutorial-shaped\n * step) here. A user who just removed MCP is opting OUT of the agent having\n * access to PostHog; immediately pivoting into a tutorial that asks\n * them to log in and try prompts is wrong on intent and confusing on\n * UX. The screen also reads `session.mcpInstalledClients` for its\n * Choose-phase copy (\"MCP is installed for X\") — that array is empty\n * post-remove, so the copy would be a lie.\n *\n * If you want a \"did you mean to keep it?\" confirmation, build that as\n * a screen earlier in this program — don't reuse the tutorial.\n */\nexport const mcpRemoveConfig: ProgramConfig = {\n id: 'mcp-remove',\n requiresAi: false,\n description: 'Remove PostHog MCP server from supported clients',\n steps: [\n {\n id: 'mcp-remove',\n label: 'Remove MCP server',\n screenId: 'mcp-remove',\n isComplete: (s) => s.mcpComplete,\n },\n ],\n};\n\n/**\n * Standalone tutorial flow — boots directly into the Choose phase of\n * McpSuggestedPromptsScreen without going through MCP install first.\n * Useful for users who already installed MCP and want to revisit the\n * tutorial, or anyone who just wants to try the agent against PostHog\n * without touching their IDE config.\n *\n * The screen handles its own OAuth (via services.performLogin) so this\n * program doesn't pre-populate credentials.\n */\nexport const mcpTutorialConfig: ProgramConfig = {\n id: 'mcp-tutorial',\n requiresAi: false,\n description: 'Try the PostHog MCP with your agent — no install needed',\n steps: [\n {\n id: 'mcp-suggested-prompts',\n label: 'MCP tutorial',\n screenId: 'mcp-suggested-prompts',\n isComplete: (s) => s.mcpSuggestedPromptsDismissed,\n },\n {\n id: 'slack-connect',\n label: 'Connect Slack',\n screenId: 'slack-connect',\n isComplete: (s) => s.slackStepDismissed,\n },\n ],\n};\n","/**\n * Slack connect program — TUI-only flow invoked by `wizard slack`. One\n * step: the same Connect Slack screen the MCP flows end on. The screen\n * renders the no-creds nudge (marketing copy + \"Open Slack setup\" link);\n * we deliberately don't force OAuth here because connecting Slack itself\n * happens in the browser, so a wizard login adds nothing for the user.\n */\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\n\nexport const slackConnectConfig: ProgramConfig = {\n id: 'slack',\n description: 'Connect PostHog to your Slack',\n steps: [\n {\n id: 'slack-connect',\n label: 'Connect Slack',\n screenId: 'slack-connect',\n isComplete: (s) => s.slackStepDismissed,\n },\n ],\n};\n","/**\n * Central registry of all wizard programs.\n *\n * Adding a new program:\n * 1. Create src/lib/programs/<name>/ with index.ts exporting a ProgramConfig\n * 2. Import and add it to PROGRAM_REGISTRY below\n * 3. (If custom intro screen) add to src/ui/tui/screen-registry.tsx\n *\n * screen-sequences.ts, store.ts, and bin.ts all derive their wiring from\n * this array — no need to touch those files when adding a program.\n */\n\nimport type { ProgramConfig } from './program-step.js';\nimport { POSTHOG_DOCS_URL } from '../constants.js';\nimport { posthogIntegrationConfig } from './posthog-integration/index.js';\nimport { revenueAnalyticsConfig } from './revenue-analytics/index.js';\nimport { auditConfig } from './audit/index.js';\nimport { eventsAuditConfig } from './events-audit/index.js';\nimport { posthogDoctorConfig } from './posthog-doctor/index.js';\nimport { webAnalyticsDoctorConfig } from './web-analytics-doctor/index.js';\nimport { migrationConfig } from './migration/index.js';\nimport { errorTrackingUploadSourceMapsConfig } from './error-tracking-upload-source-maps/index.js';\nimport { AGENT_SKILL_STEPS } from './agent-skill/index.js';\nimport { getContentBlocks as agentSkillContentBlocks } from './agent-skill/content/index.js';\nimport {\n mcpAddConfig,\n mcpRemoveConfig,\n mcpTutorialConfig,\n} from './mcp/index.js';\nimport { slackConnectConfig } from './slack/index.js';\n\n// Generic skill program — runs an arbitrary context-mill skill chosen at\n// dispatch time (session.skillId) rather than a registered named program.\n// Backs `wizard skill <name>` and the narrow `audit` leaves (events,\n// feature-flags, identify, session-replay, autocapture); each injects its\n// skillId onto the config, which lands on session.skillId before the run.\n//\n// The `run` recipe is a function rather than a static block because the\n// skillId isn't known until dispatch. Without a `run` recipe the runner's\n// `skipAgent` guard (run-wizard.ts) fires and the skill never executes — so we\n// derive generic run metadata from the resolved skill id at run time.\nexport const agentSkillConfig: ProgramConfig = {\n id: 'agent-skill',\n description: 'Run an arbitrary context-mill skill',\n steps: AGENT_SKILL_STEPS,\n getContentBlocks: agentSkillContentBlocks,\n allowedTools: ['Agent'],\n run: (session) => {\n const skillId = session.skillId ?? 'agent-skill';\n return Promise.resolve({\n skillId,\n integrationLabel: skillId,\n spinnerMessage: `Running ${skillId}...`,\n successMessage: `${skillId} complete!`,\n estimatedDurationMinutes: 5,\n reportFile: `posthog-${skillId}-report.md`,\n docsUrl: POSTHOG_DOCS_URL,\n });\n },\n};\n\nexport const PROGRAM_REGISTRY = [\n posthogIntegrationConfig,\n revenueAnalyticsConfig,\n errorTrackingUploadSourceMapsConfig,\n auditConfig,\n eventsAuditConfig,\n posthogDoctorConfig,\n webAnalyticsDoctorConfig,\n migrationConfig,\n agentSkillConfig,\n mcpAddConfig,\n mcpRemoveConfig,\n mcpTutorialConfig,\n slackConnectConfig,\n] as const satisfies readonly ProgramConfig[];\n\n/**\n * Typed program names. Values come from each config's `id`, so there's\n * no parallel string list to keep in sync — adding `Program.Foo` here is\n * just exposing `fooConfig.id` under a friendly name for call sites.\n */\nexport const Program = {\n PostHogIntegration: posthogIntegrationConfig.id,\n RevenueAnalyticsSetup: revenueAnalyticsConfig.id,\n ErrorTrackingUploadSourceMaps: errorTrackingUploadSourceMapsConfig.id,\n Migration: migrationConfig.id,\n Audit: auditConfig.id,\n EventsAudit: eventsAuditConfig.id,\n PosthogDoctor: posthogDoctorConfig.id,\n WebAnalyticsDoctor: webAnalyticsDoctorConfig.id,\n AgentSkill: agentSkillConfig.id,\n McpAdd: mcpAddConfig.id,\n McpRemove: mcpRemoveConfig.id,\n McpTutorial: mcpTutorialConfig.id,\n SlackConnect: slackConnectConfig.id,\n} as const;\n\n/** Compile-time union of every registered program id. */\nexport type ProgramId = (typeof PROGRAM_REGISTRY)[number]['id'];\n\n/**\n * Look up a program config by its id. `ProgramId` is a union of every\n * registered id, so the lookup is statically guaranteed to find a match\n * — the `!` is a load-bearing assertion of that invariant, not a hope.\n */\nexport function getProgramConfig(id: ProgramId): ProgramConfig {\n return PROGRAM_REGISTRY.find((c) => c.id === id)!;\n}\n\n/** A program config that is exposed as a CLI subcommand. */\nexport type SubcommandProgram = ProgramConfig & { command: string };\n\n/** All program configs that are exposed as CLI subcommands. */\nexport function getSubcommandPrograms(): SubcommandProgram[] {\n return PROGRAM_REGISTRY.filter(\n (c): c is SubcommandProgram => c.command != null,\n );\n}\n","import type { Arguments } from 'yargs';\nimport { setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\n\nexport const mcpAddCommand: Command = {\n name: 'add',\n description: 'Install PostHog MCP server to supported clients',\n options: {\n local: {\n default: false,\n describe: 'Add local development MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n features: {\n describe: 'Comma-separated list of features to enable (default: all)',\n type: 'string',\n },\n 'api-key': {\n describe: 'PostHog personal API key (phx_xxx) for MCP authentication',\n type: 'string',\n },\n },\n handler: runMcpAdd,\n};\n\nfunction runMcpAdd(argv: Arguments): void {\n const features = parseFeatures(argv.features);\n void (async () => {\n const { readApiKeyFromEnv } = await import('@utils/env-api-key');\n const apiKey = (argv.apiKey as string | undefined) || readApiKeyFromEnv();\n const debug = argv.debug as boolean | undefined;\n const localMcp = argv.local as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.McpAdd);\n tui.store.session = buildSession({\n debug,\n localMcp,\n mcpFeatures: features,\n apiKey,\n });\n } catch (error) {\n if (!isTUIUnavailable(error)) throw error;\n setUI(new LoggingUI());\n const { addMCPServerToClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n await addMCPServerToClientsStep({ local: localMcp, features, apiKey });\n }\n })();\n}\n\n/**\n * Ink throws \"Raw mode is not supported\" when stdin has no TTY (piped input,\n * CI, some IDE terminals). That is the only TUI failure we degrade to\n * LoggingUI for — any other error from the TUI path is a real bug and must\n * surface rather than be silently swallowed.\n */\nfunction isTUIUnavailable(error: unknown): boolean {\n return (\n error instanceof Error && /raw mode is not supported/i.test(error.message)\n );\n}\n\nfunction parseFeatures(raw: unknown): string[] | undefined {\n if (typeof raw !== 'string') return undefined;\n return raw\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n}\n","import type { Arguments } from 'yargs';\nimport { setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\n\nexport const mcpRemoveCommand: Command = {\n name: 'remove',\n description: 'Remove PostHog MCP server from supported clients',\n options: {\n local: {\n default: false,\n describe: 'Remove local development MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n },\n handler: runMcpRemove,\n};\n\nfunction runMcpRemove(argv: Arguments): void {\n void (async () => {\n const debug = argv.debug as boolean | undefined;\n const localMcp = argv.local as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.McpRemove);\n tui.store.session = buildSession({ debug, localMcp });\n } catch {\n setUI(new LoggingUI());\n const { removeMCPServerFromClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n await removeMCPServerFromClientsStep({ local: localMcp });\n }\n })();\n}\n","import type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\n\nexport const mcpTutorialCommand: Command = {\n name: 'tutorial',\n description: 'Try the PostHog MCP with your agent (no install needed)',\n options: {\n local: {\n default: false,\n describe:\n 'Point the tutorial at the local MCP server (http://localhost:8787)',\n type: 'boolean',\n },\n },\n handler: runMcpTutorial,\n};\n\nfunction runMcpTutorial(argv: Arguments): void {\n void (async () => {\n const debug = argv.debug as boolean | undefined;\n const localMcp = argv.local as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.McpTutorial);\n tui.store.session = buildSession({ debug, localMcp });\n } catch (err) {\n // TUI unavailable — the tutorial has no headless fallback.\n setUI(new LoggingUI());\n getUI().log.error(\n `The MCP tutorial requires an interactive terminal. ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n process.exit(1);\n }\n })();\n}\n","import { mcpAddCommand } from './add';\nimport { mcpRemoveCommand } from './remove';\nimport { mcpTutorialCommand } from './tutorial';\nimport type { Command } from '../command';\n\nexport const mcpCommand: Command = {\n name: 'mcp',\n description: 'MCP server management commands',\n children: [mcpAddCommand, mcpRemoveCommand, mcpTutorialCommand],\n};\n","/**\n * `--no-telemetry` flips `telemetry: false` via yargs negation;\n * `POSTHOG_WIZARD_NO_TELEMETRY` is honoured separately so the env-var\n * form documented in the README keeps working.\n */\nexport function resolveNoTelemetry(options: Record<string, unknown>): boolean {\n if (options.telemetry === false) return true;\n const env = process.env.POSTHOG_WIZARD_NO_TELEMETRY;\n if (env == null || env === '') return false;\n const norm = env.toLowerCase();\n return norm !== '0' && norm !== 'false';\n}\n","import { VERSION } from '@lib/version';\nimport { logToFile, getLogFilePath } from '@utils/debug';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { startTUI as StartTUIFn } from '@ui/tui/start-tui';\nimport type { TaskStreamPush as TaskStreamPushClass } from '@lib/task-stream/task-stream-push';\nimport { resolveNoTelemetry } from './resolve-no-telemetry';\nimport { runCleanups } from '@utils/wizard-abort';\n\nconst WIZARD_VERSION = VERSION;\n\n/**\n * Run a full wizard program in the TUI. Handles the full lifecycle: start TUI,\n * build session, run detection, wait for intro gate, execute the\n * agent pipeline, wait for outro dismissal, then exit.\n */\nexport function runWizard(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n let tui: ReturnType<typeof StartTUIFn> | null = null;\n let taskStream: TaskStreamPushClass | null = null;\n let onSignal: (() => void) | null = null;\n let exitInProgress = false;\n\n void (async () => {\n try {\n const installDir = (options.installDir as string) || process.cwd();\n\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession, RunPhase } = await import('@lib/wizard-session');\n const { TaskStreamPush } = await import('@lib/task-stream/index');\n const { PostHogDestination } = await import(\n '@lib/task-stream/destinations/posthog'\n );\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n tui = startTUI(WIZARD_VERSION, config.id as any);\n const activeTui = tui;\n\n const session = buildSession({\n debug: options.debug as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n installDir,\n ci: false,\n signup: options.signup as boolean | undefined,\n apiKey: options.apiKey as string | undefined,\n projectId: options.projectId as string | undefined,\n email: options.email as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n });\n session.programLabel = config.id;\n if (options.skillId) {\n session.skillId = options.skillId as string;\n } else if (config.skillId) {\n session.skillId = config.skillId;\n }\n\n activeTui.store.session = session;\n\n const taskStreamEnabled = !session.noTelemetry;\n taskStream = new TaskStreamPush({\n store: activeTui.store,\n programId: config.id,\n destinations: [\n new PostHogDestination({\n getCredentials: () => activeTui.store.session.credentials,\n onError: (err) => logToFile('[task-stream-push]', err.message),\n }),\n ],\n enabled: taskStreamEnabled,\n });\n const activeStream = taskStream;\n activeStream.attach();\n\n // Flush a terminal-phase push on Ctrl-C so the web app sees the\n // run ended in error rather than hanging on the last \"running\"\n // snapshot.\n let signalled = false;\n onSignal = (): void => {\n if (signalled || exitInProgress) return;\n signalled = true;\n logToFile('[run-wizard] signal received, flushing task stream');\n // Run cleanups synchronously first — settings restore is sync fs work\n // and must complete even if the stream shutdown below times out.\n runCleanups();\n if (activeTui.store.session.runPhase === RunPhase.Running) {\n activeTui.store.setRunPhase(RunPhase.Error);\n }\n void activeStream\n .shutdown(2000)\n .catch((e) =>\n logToFile('[run-wizard] task stream shutdown error on signal:', e),\n )\n .finally(() => {\n try {\n activeTui.unmount();\n } catch {\n // terminal may already be torn down\n }\n process.exit(130);\n });\n };\n process.on('SIGINT', onSignal);\n process.on('SIGTERM', onSignal);\n\n await activeTui.store.runReadyHooks();\n await activeTui.store.getGate('intro');\n await activeTui.store.getGate('health-check');\n\n const skipAgent = config.run == null;\n\n if (skipAgent) {\n const { getOrAskForProjectData } = await import('@utils/setup-utils');\n const { projectApiKey, host, accessToken, projectId } =\n await getOrAskForProjectData({\n signup: session.signup,\n ci: session.ci,\n apiKey: session.apiKey,\n projectId: session.projectId,\n programId: config.id,\n });\n activeTui.store.setCredentials({\n accessToken,\n projectApiKey,\n host,\n projectId,\n });\n } else {\n const { runAgent } = await import('@lib/agent/agent-runner');\n await runAgent(config, activeTui.store.session);\n }\n\n const isDone = (): boolean =>\n skipAgent\n ? activeTui.store.session.outroDismissed\n : activeTui.store.session.skillsComplete;\n\n await new Promise<void>((resolve) => {\n const unsub = activeTui.store.subscribe(() => {\n if (isDone()) {\n unsub();\n resolve();\n }\n });\n if (isDone()) {\n unsub();\n resolve();\n }\n });\n\n exitInProgress = true;\n await activeStream.shutdown(2000);\n process.off('SIGINT', onSignal);\n process.off('SIGTERM', onSignal);\n activeTui.unmount();\n process.exit(0);\n } catch (err) {\n // File-log first — the cleanup below can throw or exit.\n logToFile('[run-wizard] FATAL:', err);\n // Run cleanups before anything async so settings are restored even if\n // the stream shutdown hangs.\n runCleanups();\n // The task-stream debounce timer keeps the event loop alive, so\n // we have to drain it before exiting on the error path.\n exitInProgress = true;\n if (onSignal) {\n process.off('SIGINT', onSignal);\n process.off('SIGTERM', onSignal);\n }\n if (taskStream) {\n try {\n await taskStream.shutdown(2000);\n } catch {\n // ignore\n }\n }\n if (tui) {\n try {\n tui.unmount();\n } catch {\n // ignore\n }\n }\n // Print after unmount — anything printed into the alt screen is wiped.\n // eslint-disable-next-line no-console\n console.error('Wizard run failed:', err);\n // eslint-disable-next-line no-console\n console.error(`Full logs: ${getLogFilePath()}`);\n process.exit(1);\n }\n })();\n}\n","import { POSTHOG_DOCS_URL } from '@lib/constants';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport { analytics } from '@utils/analytics';\nimport { resolveNoTelemetry } from './resolve-no-telemetry';\n\n/**\n * The single CI validation layer: defaults region and requires api-key and\n * install-dir. Every CI entry point routes through `runWizardCI`, so this is\n * the one place these checks live. UI must be initialized before calling.\n */\nexport function validateCiOptions(options: Record<string, unknown>): void {\n if (!options.region) options.region = 'us';\n if (!options.apiKey) {\n getUI().intro('PostHog Wizard');\n getUI().log.error('CI mode requires --api-key (personal API key phx_xxx)');\n process.exit(1);\n }\n if (!options.installDir) {\n getUI().intro('PostHog Wizard');\n getUI().log.error(\n 'CI mode requires --install-dir (directory to install in)',\n );\n process.exit(1);\n }\n}\n\n/**\n * CI-mode pipeline shared by every non-interactive entry point.\n *\n * Validates flags, builds a `ci:true` session, runs `config.ciPreRun` (or the\n * program's `onReady` hooks by default), executes `runAgent`, and routes any\n * failure through `wizardAbort`. `wizardAbort` owns all exits — never add a\n * raw `process.exit` here.\n */\nexport function runWizardCI(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n setUI(new LoggingUI());\n validateCiOptions(options);\n // Every CI entry point routes through here — upgrade the non-prod\n // build tag from 'dev' to 'ci'.\n analytics.setTag('build', 'ci');\n\n void (async () => {\n const path = await import('path');\n const { buildSession } = await import('@lib/wizard-session');\n const { readEnvironment } = await import('@utils/environment');\n const { readApiKeyFromEnv } = await import('@utils/env-api-key');\n const { configureLogFileFromEnvironment, logToFile } = await import(\n '@utils/debug'\n );\n const { wizardAbort, WizardError } = await import('@utils/wizard-abort');\n\n configureLogFileFromEnvironment();\n\n const env = readEnvironment();\n const apiKey =\n (options.apiKey as string) ?? readApiKeyFromEnv() ?? undefined;\n const installDir = path.isAbsolute(options.installDir as string)\n ? (options.installDir as string)\n : path.join(process.cwd(), options.installDir as string);\n\n const session = buildSession({\n debug: options.debug as boolean | undefined,\n installDir,\n ci: true,\n signup: options.signup as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n apiKey,\n email: options.email as string | undefined,\n projectId: options.projectId as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n ...env,\n });\n session.programLabel = config.id;\n if (config.skillId) {\n session.skillId = config.skillId;\n }\n const runDef = typeof config.run === 'object' ? config.run : null;\n\n getUI().intro('Welcome to the PostHog setup wizard');\n getUI().log.info(`Running ${config.id} in CI mode`);\n\n try {\n if (config.ciPreRun) {\n await config.ciPreRun(session);\n } else {\n const readyCtx = {\n session,\n setFrameworkContext: (key: string, value: unknown) => {\n session.frameworkContext[key] = value;\n },\n setFrameworkConfig: () => undefined,\n setDetectedFramework: () => undefined,\n // CI session is a plain object (no nanostore copy-on-write),\n // so direct assignment is safe here.\n setSkillId: (skillId: string | null) => {\n session.skillId = skillId;\n },\n setUnsupportedVersion: () => undefined,\n addDiscoveredFeature: () => undefined,\n setDetectionComplete: () => undefined,\n };\n for (const step of config.steps) {\n if (step.onReady) {\n await step.onReady(readyCtx);\n }\n }\n\n const detectError = session.frameworkContext.detectError as\n | { kind: string; [k: string]: unknown }\n | undefined;\n if (detectError) {\n await wizardAbort({\n message: `Prerequisites not met: ${detectError.kind}\\n\\nSee ${\n runDef?.docsUrl ?? POSTHOG_DOCS_URL\n }`,\n error: new WizardError(`${config.id} prerequisites failed`, {\n integration: config.id,\n detect_error_kind: detectError.kind,\n }),\n });\n }\n }\n\n const { runAgent } = await import('@lib/agent/agent-runner');\n await runAgent(config, session);\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n const errorStack =\n error instanceof Error && error.stack ? error.stack : undefined;\n\n logToFile(`[bin.ts CI] ERROR: ${errorMessage}`);\n if (errorStack) logToFile(`[bin.ts CI] STACK: ${errorStack}`);\n\n const debugInfo = session.debug && errorStack ? `\\n\\n${errorStack}` : '';\n const docsUrl =\n session.frameworkConfig?.metadata.docsUrl ??\n runDef?.docsUrl ??\n POSTHOG_DOCS_URL;\n await wizardAbort({\n message: `Something went wrong: ${errorMessage}\\n\\nYou can read the documentation at ${docsUrl} to set up manually.${debugInfo}`,\n error: error as Error,\n });\n }\n })().catch(() => {\n process.exit(1);\n });\n}\n","/**\n * Per-command options shared by every skill-based program command\n * (`audit events`, `migrate statsig`, `revenue`, `source-maps`, …).\n *\n * Only flags that are unique to skill commands live here. Global flags\n * (`--debug`, `--local-mcp`, `--benchmark`, `--yara-report`, `--ci`) are\n * declared once in `wizard.ts::GLOBAL_OPTIONS` and apply automatically\n * across every command — no need to repeat them per subcommand.\n */\nexport const skillProgramOptions = {\n 'install-dir': {\n describe: 'Directory to install in',\n type: 'string' as const,\n },\n};\n","import type { Arguments, Options } from 'yargs';\n\nimport { runWizard, runWizardCI } from '@lib/runners';\nimport type { ProgramConfig } from '@lib/programs/program-step';\n\nimport { skillProgramOptions } from '../skill-program-options';\n\n/**\n * Dispatch a parsed yargs invocation to the wizard runner. Applies the\n * program's `mapCliOptions` transform, then routes to `runWizard` or\n * `runWizardCI` based on the `--ci` flag.\n *\n * Every command file used to inline this; the factories call it instead.\n */\n/**\n * Run a command's async body as fire-and-forget while still surfacing failures.\n * yargs handlers are synchronous, so async work kicks off a detached promise —\n * without this, a rejection becomes an unhandled promise rejection (no message,\n * wrong exit code). This awaits the work and turns any error into a clean\n * message + non-zero exit.\n */\nexport function runCommandHandler(work: () => void | Promise<void>): void {\n void (async () => {\n try {\n await work();\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n process.stderr.write(`\\n\\x1b[1;91m✖ ${msg}\\x1b[0m\\n\\n`);\n process.exit(1);\n }\n })();\n}\n\nexport function dispatchProgram(config: ProgramConfig, argv: Arguments): void {\n const argvRecord = argv as unknown as Record<string, unknown>;\n const extras = config.mapCliOptions?.(argvRecord) ?? {};\n const options = { ...argvRecord, ...extras };\n if (options.ci) {\n runWizardCI(config, options);\n } else {\n runWizard(config, options);\n }\n}\n\n/**\n * Merge the standard skill-program flags (`--debug`, `--install-dir`, etc.)\n * with any program-specific options declared on `cliOptions`.\n *\n * Program-specific options shadow the standard ones — that's intentional, so\n * a program can override a default flag if it ever needs to.\n */\nexport function mergeCommandOptions(\n config: ProgramConfig,\n): Record<string, Options> {\n return {\n ...skillProgramOptions,\n ...((config.cliOptions ?? {}) as Record<string, Options>),\n };\n}\n","import type { Arguments } from 'yargs';\n\nimport { auditConfig } from '@lib/programs/audit/index';\nimport { agentSkillConfig } from '@lib/programs/program-registry';\nimport { webAnalyticsDoctorConfig } from '@lib/programs/web-analytics-doctor/index';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport { getSkillsBaseUrl } from '@lib/constants';\nimport { fetchSkillMenu, type CliEntry } from '@lib/wizard-tools';\nimport { analytics } from '@utils/analytics';\n\nimport { dispatchProgram } from '../../commands/factories/shared';\nimport type { Command } from '../../commands/command';\n\n/**\n * Capture a CLI dispatch error, flush analytics, and exit. The wizard never\n * starts a run from these paths — use flush() (not shutdown()) so we don't\n * fire a \"setup wizard finished\" event for a parse error that didn't run.\n */\nasync function exitDispatchError(\n reason: string,\n properties: Record<string, unknown>,\n message: string,\n code = 1,\n): Promise<never> {\n analytics.wizardCapture('cli dispatch error', { reason, ...properties });\n try {\n await analytics.flush();\n } catch {\n /* flush is best-effort; never block the exit */\n }\n process.stderr.write(message);\n return process.exit(code);\n}\n\n/**\n * Family commands (`wizard audit`, `wizard migrate`, ...) resolve their\n * subcommands at runtime against the published `cliEntries` inside\n * `skill-menu.json`. Adding a subcommand is a context-mill release — no\n * wizard release needed.\n *\n * Wizard-native subcommands (programs that aren't backed by a single skill,\n * e.g. `wizard audit web-analytics`) live here in code, dispatched directly\n * without touching the registry. Adding a native is a wizard PR.\n */\n\n/** Wizard-native subcommands keyed by family. */\nconst NATIVE_HANDLERS: Record<string, Record<string, ProgramConfig>> = {\n audit: { 'web-analytics': webAnalyticsDoctorConfig },\n};\n\n/**\n * Resolve a fetched CliEntry to the ProgramConfig that actually runs it.\n * Most entries run via the generic agent-skill program with the entry's\n * `skillId` injected. The comprehensive `audit all` is the one exception —\n * skillId 'audit' triggers the specialized auditConfig (custom hooks,\n * content blocks, screens).\n */\nfunction configForCliEntry(entry: CliEntry): ProgramConfig {\n if (entry.skillId === 'audit') return auditConfig;\n return { ...agentSkillConfig, skillId: entry.skillId };\n}\n\nfunction familyEntries(family: string, entries: CliEntry[]): CliEntry[] {\n return entries.filter(\n (e) =>\n e.role === 'command' && e.parentCommand === family && Boolean(e.command),\n );\n}\n\n/**\n * Dispatch `wizard <family> <sub>` to the right program.\n *\n * Order:\n * 1. Native handler for (family, sub) — runs immediately, no network.\n * 2. Fetched CliEntry — runs the resolved skill.\n * 3. Unknown — prints the available list and exits non-zero.\n */\nexport async function dispatchFamily(\n family: string,\n argv: Arguments,\n): Promise<void> {\n const sub = (argv.skill as string | undefined)?.trim();\n if (!sub) {\n // Reached only in non-TTY/CI — an interactive terminal routes the no-sub\n // case to the picker before this runs, so don't suggest opening it here.\n return exitDispatchError(\n 'missing subcommand',\n { family },\n `\\n\\x1b[1;91m✖ \\`wizard ${family}\\` requires a subcommand.\\x1b[0m\\n` +\n ` Pass one (e.g. \\`wizard ${family} <subcommand>\\`), or run it in an interactive terminal to pick from a menu.\\n\\n`,\n );\n }\n\n const native = NATIVE_HANDLERS[family]?.[sub];\n if (native) {\n dispatchProgram(native, argv);\n return;\n }\n\n const skillsBaseUrl = getSkillsBaseUrl(Boolean(argv['local-mcp']));\n const menu = await fetchSkillMenu(skillsBaseUrl);\n if (!menu) {\n return exitDispatchError(\n 'registry unreachable',\n { family, sub, skillsBaseUrl },\n `\\n\\x1b[1;91m✖ Couldn't reach the skill registry at ${skillsBaseUrl}.\\x1b[0m\\n` +\n ` Check your network connection and try again.\\n\\n`,\n );\n }\n\n const entries = menu.cliEntries ?? [];\n const entry = familyEntries(family, entries).find((e) => e.command === sub);\n if (entry) {\n dispatchProgram(configForCliEntry(entry), argv);\n return;\n }\n\n const available = [\n ...Object.keys(NATIVE_HANDLERS[family] ?? {}),\n ...familyEntries(family, entries).map((e) => e.command!),\n ].sort();\n return exitDispatchError(\n 'unknown subcommand',\n { family, sub, available },\n `\\n\\x1b[1;91m✖ Unknown subcommand \"${sub}\" under \\`${family}\\`.\\x1b[0m\\n` +\n (available.length\n ? ` Available: ${available.join(', ')}\\n\\n`\n : ` No subcommands published for \"${family}\" yet.\\n\\n`),\n );\n}\n\n/**\n * Build the children list shown in the family's interactive picker.\n * Combines native handlers with skill-backed entries from the live registry.\n * Used by `familyCommandFactory`'s `interactiveDefault`.\n */\nexport function buildFamilyPickerChildren(\n family: string,\n entries: CliEntry[],\n): Command[] {\n const natives: Command[] = Object.entries(NATIVE_HANDLERS[family] ?? {}).map(\n ([cmd, program]) => ({\n name: cmd,\n description: program.description,\n handler: (argv: Arguments) => dispatchProgram(program, argv),\n }),\n );\n const live: Command[] = familyEntries(family, entries).map((entry) => ({\n name: entry.command!,\n description: entry.description,\n handler: (argv: Arguments) => {\n void dispatchFamily(family, {\n ...argv,\n skill: entry.command,\n } as Arguments);\n },\n default: entry.default,\n }));\n return [...natives, ...live];\n}\n\n/**\n * The children the family picker shows **today**: only the leaf marked\n * `default` (e.g. `audit events`). Every other subcommand stays runnable\n * directly (`wizard audit <name>`) — they just aren't listed in the picker yet.\n * Falls back to all children when nothing is marked `default`.\n *\n * Temporary: when we're ready to surface the full menu, return `children`\n * unchanged (and delete this note).\n */\nexport function pickerChildrenToShow(children: readonly Command[]): Command[] {\n const defaults = children.filter((c) => c.default);\n return defaults.length > 0 ? [...defaults] : [...children];\n}\n","/**\n * PromptLabel — Compact inline label for input prompts.\n *\n * Renders: [!] message\n * where [!] is black text on accent background.\n */\n\nimport { Box, Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\n\ninterface PromptLabelProps {\n message?: string;\n}\n\nexport const PromptLabel = ({ message }: PromptLabelProps) => {\n return (\n <Box>\n <Text bold color={Colors.accent}>\n {' '}\n {message}\n </Text>\n </Box>\n );\n};\n","/**\n * Pure utility functions for keyboard hints — no React or Ink dependencies.\n * Extracted for testability in a node Jest environment.\n */\n\nexport interface KeyboardHint {\n label: string;\n action: string;\n priority: number;\n}\n\n/** Well-known key matches corresponding to Ink's key.* properties. */\nexport enum KeyMatch {\n UpArrow = 'upArrow',\n DownArrow = 'downArrow',\n LeftArrow = 'leftArrow',\n RightArrow = 'rightArrow',\n Return = 'return',\n Escape = 'escape',\n Space = 'space',\n}\n\n/** A key match: either a KeyMatch enum value or a literal character string (e.g. 'a', 's'). */\nexport type KeyMatchOrChar = KeyMatch | (string & NonNullable<unknown>);\n\n/** Default priorities by key type. */\nconst DEFAULT_PRIORITY: Record<string, number> = {\n [KeyMatch.UpArrow]: 0,\n [KeyMatch.DownArrow]: 0,\n [KeyMatch.LeftArrow]: 1,\n [KeyMatch.RightArrow]: 1,\n [KeyMatch.Space]: 10,\n [KeyMatch.Escape]: 20,\n [KeyMatch.Return]: 21,\n};\n\n/** Get the default display priority for a key match. */\nexport function getDefaultPriority(\n match: KeyMatchOrChar | KeyMatchOrChar[],\n): number {\n const first = Array.isArray(match) ? match[0] : match;\n return DEFAULT_PRIORITY[first] ?? 15;\n}\n\n/** Check if a KeyMatchOrChar matches the given input string and key flags. */\nexport function matchesKey(\n m: KeyMatchOrChar,\n input: string,\n key: { [k: string]: unknown },\n): boolean {\n switch (m) {\n case KeyMatch.UpArrow:\n return !!key.upArrow;\n case KeyMatch.DownArrow:\n return !!key.downArrow;\n case KeyMatch.LeftArrow:\n return !!key.leftArrow;\n case KeyMatch.RightArrow:\n return !!key.rightArrow;\n case KeyMatch.Return:\n return !!key.return;\n case KeyMatch.Escape:\n return !!key.escape;\n case KeyMatch.Space:\n return input === ' ';\n default:\n return input === m;\n }\n}\n\n/** Serialize hints for comparison. */\nexport function hintsKey(hints: KeyboardHint[]): string {\n return hints.map((h) => `${h.label}:${h.action}`).join('|');\n}\n\n/** Deduplicate hints by label+action and sort by priority. */\nexport function deduplicateAndSort(hints: KeyboardHint[]): KeyboardHint[] {\n const seen = new Set<string>();\n const deduped: KeyboardHint[] = [];\n for (const hint of hints) {\n const k = `${hint.label}:${hint.action}`;\n if (!seen.has(k)) {\n seen.add(k);\n deduped.push(hint);\n }\n }\n deduped.sort((a, b) => a.priority - b.priority);\n return deduped;\n}\n","/**\n * KeyboardHintsProvider — Context for collecting and displaying keyboard hints.\n *\n * Input components register their hints via useKeyBindings. The provider\n * flattens, deduplicates, and sorts them. The hints bar stays visible for as\n * long as a screen has registered hints — it never auto-dismisses.\n */\n\nimport {\n createContext,\n useCallback,\n useContext,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport {\n hintsKey,\n deduplicateAndSort,\n type KeyboardHint,\n} from './keyboard-hints-utils.js';\n\nexport type { KeyboardHint } from './keyboard-hints-utils.js';\n\ninterface KeyboardHintsContextValue {\n register(id: string, hints: KeyboardHint[]): void;\n unregister(id: string): void;\n hints: KeyboardHint[];\n}\n\nconst KeyboardHintsContext = createContext<KeyboardHintsContextValue>({\n register: () => undefined,\n unregister: () => undefined,\n hints: [],\n});\n\nexport const useKeyboardHintsContext = () => useContext(KeyboardHintsContext);\n\nexport const KeyboardHintsProvider = ({\n children,\n}: {\n children: ReactNode;\n}) => {\n const registrationsRef = useRef(new Map<string, KeyboardHint[]>());\n const [hints, setHints] = useState<KeyboardHint[]>([]);\n const prevHintsKeyRef = useRef('');\n\n const recompute = useCallback(() => {\n const all: KeyboardHint[] = [];\n for (const h of registrationsRef.current.values()) {\n all.push(...h);\n }\n const deduped = deduplicateAndSort(all);\n\n const newKey = hintsKey(deduped);\n if (newKey !== prevHintsKeyRef.current) {\n prevHintsKeyRef.current = newKey;\n setHints(deduped);\n }\n }, []);\n\n const register = useCallback(\n (id: string, h: KeyboardHint[]) => {\n registrationsRef.current.set(id, h);\n recompute();\n },\n [recompute],\n );\n\n const unregister = useCallback(\n (id: string) => {\n registrationsRef.current.delete(id);\n recompute();\n },\n [recompute],\n );\n\n return (\n <KeyboardHintsContext.Provider value={{ register, unregister, hints }}>\n {children}\n </KeyboardHintsContext.Provider>\n );\n};\n","/**\n * useKeyBindings — Declarative keyboard input + automatic hint registration.\n *\n * Replaces raw `useInput` in input components. Define bindings as data;\n * the hook wires up the Ink input handler AND registers hints in the\n * KeyboardHintsProvider. One source of truth for keys and their labels.\n */\n\nimport { useInput, type Key } from 'ink';\nimport { useEffect, useRef } from 'react';\nimport { useKeyboardHintsContext } from './useKeyboardHints.js';\nimport {\n matchesKey,\n getDefaultPriority,\n KeyMatch,\n type KeyboardHint,\n type KeyMatchOrChar,\n} from './keyboard-hints-utils.js';\n\nexport { KeyMatch };\nexport type { KeyMatchOrChar } from './keyboard-hints-utils.js';\n\nexport interface KeyBinding {\n /** Which key(s) trigger this binding. Array = multiple keys, one hint. */\n match: KeyMatchOrChar | KeyMatchOrChar[];\n /** Display label in hints bar (e.g. \"↑↓\", \"space\", \"enter\") */\n label: string;\n /** Description in hints bar (e.g. \"navigate\", \"toggle\") */\n action: string;\n /** Ordering priority (lower = further left). Defaults based on key type. */\n priority?: number;\n /** Handler called when the key matches. */\n handler: (input: string, key: Key) => void;\n}\n\n/**\n * Declarative key bindings hook. Replaces `useInput` in input components.\n * Registers hints automatically with the KeyboardHintsProvider.\n *\n * @param id Unique identifier for this component's hints registration\n * @param bindings Array of key binding definitions\n */\nexport function useKeyBindings(id: string, bindings: KeyBinding[]): void {\n const ctx = useKeyboardHintsContext();\n\n // Extract hints and register. Use a serialized key to avoid unnecessary updates.\n const hintsRef = useRef<string>('');\n const hints: KeyboardHint[] = bindings.map((b) => ({\n label: b.label,\n action: b.action,\n priority: b.priority ?? getDefaultPriority(b.match),\n }));\n const serialized = hints\n .map((h) => `${h.label}:${h.action}:${h.priority}`)\n .join('|');\n\n useEffect(() => {\n if (serialized !== hintsRef.current) {\n hintsRef.current = serialized;\n ctx.register(id, hints);\n }\n return () => ctx.unregister(id);\n // eslint-disable-next-line\n }, [id, serialized]);\n\n // Wire up input handling\n useInput((input, key) => {\n for (const binding of bindings) {\n const matches = Array.isArray(binding.match)\n ? binding.match\n : [binding.match];\n if (matches.some((m) => matchesKey(m, input, key))) {\n binding.handler(input, key);\n return;\n }\n }\n });\n}\n","/**\n * PickerMenu — Single and multi select.\n * Single mode: custom renderer with small triangle indicator.\n * Multi mode: checkbox glyphs with space to toggle.\n *\n * Key bindings are declared via useKeyBindings, which auto-registers\n * hints in the KeyboardHintsBar.\n */\n\nimport { Box, Text } from 'ink';\nimport { useEffect, useState } from 'react';\nimport { Icons, Colors } from '@ui/tui/styles';\nimport { PromptLabel } from './PromptLabel.js';\nimport {\n useKeyBindings,\n KeyMatch,\n type KeyBinding,\n} from '@ui/tui/hooks/useKeyBindings';\n\ninterface PickerOption<T> {\n label: string;\n value: T;\n hint?: string;\n /** Glyph rendered before the label, in its own color — unaffected by\n * focus and disabled styling. */\n icon?: { glyph: string; color?: string };\n /** Dimmed and unselectable; navigation skips over it. */\n disabled?: boolean;\n /**\n * Multi-select only: marks this option mutually exclusive with every other\n * option. Selecting it clears all other picks; selecting any non-exclusive\n * option clears it. Used e.g. for a browser connector that can't be\n * installed alongside local editors.\n */\n exclusive?: boolean;\n}\n\n/**\n * Step through a column's options in `dir`, wrapping, until an enabled\n * option is found. Returns `from` unchanged if the column is entirely\n * disabled.\n */\nfunction stepEnabled<T>(\n options: PickerOption<T>[],\n rows: number,\n from: number,\n dir: 1 | -1,\n): number {\n const col = Math.floor(from / rows);\n const colStart = col * rows;\n const colLen = Math.min(rows, options.length - colStart);\n let row = from % rows;\n for (let i = 0; i < colLen; i++) {\n row = (row + dir + colLen) % colLen;\n const idx = colStart + row;\n if (!options[idx]?.disabled) return idx;\n }\n return from;\n}\n\n/** Index of the first enabled option, for the initial focus. */\nfunction firstEnabled<T>(options: PickerOption<T>[]): number {\n const idx = options.findIndex((o) => !o.disabled);\n return idx === -1 ? 0 : idx;\n}\n\ninterface PickerMenuProps<T> {\n message?: string;\n options: PickerOption<T>[];\n mode?: 'single' | 'multi';\n centered?: boolean;\n columns?: 1 | 2 | 3 | 4;\n /**\n * Vertical space between options, in TUI rows. Defaults to 0 — i.e.\n * options stack tightly. Set to 1+ when the option labels are long\n * (wrap across multiple lines) or for visual breathing room.\n */\n optionMarginBottom?: number;\n onSelect: (value: T | T[]) => void;\n}\n\nexport const PickerMenu = <T,>({\n message,\n options,\n mode = 'single',\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n onSelect,\n}: PickerMenuProps<T>) => {\n if (mode === 'multi') {\n return (\n <MultiPickerMenu\n message={message}\n options={options}\n centered={centered}\n columns={columns}\n optionMarginBottom={optionMarginBottom}\n onSelect={onSelect}\n />\n );\n }\n\n return (\n <SinglePickerMenu\n message={message}\n options={options}\n centered={centered}\n columns={columns}\n optionMarginBottom={optionMarginBottom}\n onSelect={onSelect}\n />\n );\n};\n\n/** Custom single-select with triangle indicator and accent highlight. */\nconst SinglePickerMenu = <T,>({\n message,\n options,\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n onSelect,\n}: {\n message?: string;\n options: PickerOption<T>[];\n centered?: boolean;\n columns?: number;\n optionMarginBottom?: number;\n onSelect: (value: T | T[]) => void;\n}) => {\n const [focused, setFocused] = useState(() => firstEnabled(options));\n const rows = Math.ceil(options.length / columns);\n\n // Re-validate focus when the options change while mounted \\u2014 a list\n // that shrinks or disables entries can leave `focused` pointing at a\n // missing or disabled option, which would make enter a no-op.\n useEffect(() => {\n if (focused >= options.length || options[focused]?.disabled) {\n setFocused(firstEnabled(options));\n }\n }, [options, focused]);\n\n const bindings: KeyBinding[] = [\n {\n match: [KeyMatch.UpArrow, KeyMatch.DownArrow],\n label: '\\u2191\\u2193',\n action: 'navigate',\n handler: (_input, key) => {\n if (key.upArrow) {\n setFocused(stepEnabled(options, rows, focused, -1));\n }\n if (key.downArrow) {\n setFocused(stepEnabled(options, rows, focused, 1));\n }\n },\n },\n {\n match: KeyMatch.Return,\n label: 'enter',\n action: 'select',\n handler: () => {\n const selected = options[focused];\n if (selected && !selected.disabled) {\n onSelect(selected.value);\n }\n },\n },\n ];\n\n if (columns > 1) {\n bindings.splice(1, 0, {\n match: [KeyMatch.LeftArrow, KeyMatch.RightArrow],\n label: '\\u2190\\u2192',\n action: 'navigate',\n handler: (_input, key) => {\n const col = Math.floor(focused / rows);\n const row = focused % rows;\n\n let next = focused;\n if (key.leftArrow) {\n const prevCol = col > 0 ? col - 1 : columns - 1;\n next = Math.min(prevCol * rows + row, options.length - 1);\n }\n if (key.rightArrow) {\n const nextCol = col < columns - 1 ? col + 1 : 0;\n next = Math.min(nextCol * rows + row, options.length - 1);\n }\n // Landing on a disabled option slides to the column's nearest\n // enabled one.\n if (options[next]?.disabled) {\n next = stepEnabled(options, rows, next, 1);\n }\n setFocused(next);\n },\n });\n }\n\n useKeyBindings('single-picker', bindings);\n\n // Chunk options into columns (column-first ordering)\n const columnArrays: PickerOption<T>[][] = [];\n for (let c = 0; c < columns; c++) {\n columnArrays.push(options.slice(c * rows, c * rows + rows));\n }\n\n const align = centered ? 'center' : undefined;\n\n return (\n <Box flexDirection=\"column\" alignItems={align}>\n <PromptLabel message={message} />\n <Box flexDirection=\"row\" gap={4}>\n {columnArrays.map((colOpts, colIdx) => (\n <Box key={colIdx} flexDirection=\"column\">\n {colOpts.map((opt, rowIdx) => {\n const flatIdx = colIdx * rows + rowIdx;\n const isFocused = flatIdx === focused;\n const label = opt.hint ? `${opt.label} (${opt.hint})` : opt.label;\n return (\n <Box key={flatIdx} gap={1} marginBottom={optionMarginBottom}>\n <Text\n color={isFocused ? Colors.accent : undefined}\n dimColor={!isFocused}\n >\n {isFocused ? Icons.triangleSmallRight : ' '}\n </Text>\n {opt.icon && (\n <Text color={opt.icon.color}>{opt.icon.glyph}</Text>\n )}\n <Text\n color={\n opt.disabled\n ? Colors.muted\n : isFocused\n ? Colors.accent\n : undefined\n }\n bold={isFocused && !opt.disabled}\n dimColor={!isFocused || opt.disabled}\n >\n {label}\n </Text>\n </Box>\n );\n })}\n </Box>\n ))}\n </Box>\n </Box>\n );\n};\n\n/** Custom multi-select with checkbox glyphs and accent highlight. */\nconst MultiPickerMenu = <T,>({\n message,\n options,\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n onSelect,\n}: {\n message?: string;\n options: PickerOption<T>[];\n centered?: boolean;\n columns?: number;\n optionMarginBottom?: number;\n onSelect: (value: T | T[]) => void;\n}) => {\n const [focused, setFocused] = useState(() => firstEnabled(options));\n const [selected, setSelected] = useState<Set<number>>(new Set());\n const rows = Math.ceil(options.length / columns);\n\n // Re-validate focus when the options change while mounted — a list\n // that shrinks or disables entries can leave `focused` pointing at a\n // missing or disabled option, which would make enter a no-op.\n useEffect(() => {\n if (focused >= options.length || options[focused]?.disabled) {\n setFocused(firstEnabled(options));\n }\n }, [options, focused]);\n\n const bindings: KeyBinding[] = [\n {\n match: [KeyMatch.UpArrow, KeyMatch.DownArrow],\n label: '\\u2191\\u2193',\n action: 'navigate',\n handler: (_input, key) => {\n if (key.upArrow) {\n setFocused(stepEnabled(options, rows, focused, -1));\n }\n if (key.downArrow) {\n setFocused(stepEnabled(options, rows, focused, 1));\n }\n },\n },\n {\n match: KeyMatch.Space,\n label: 'space',\n action: 'toggle',\n handler: () => {\n if (options[focused]?.disabled) return;\n setSelected((prev) => {\n const next = new Set(prev);\n if (next.has(focused)) {\n next.delete(focused);\n return next;\n }\n // Enforce mutual exclusivity: an exclusive option clears every other\n // pick; any other option clears previously-picked exclusive ones.\n if (options[focused]?.exclusive) {\n return new Set([focused]);\n }\n for (const i of next) {\n if (options[i]?.exclusive) {\n next.delete(i);\n }\n }\n next.add(focused);\n return next;\n });\n },\n },\n {\n match: KeyMatch.Return,\n label: 'enter',\n action: 'confirm',\n handler: () => {\n if (selected.size === 0) {\n const hovered = options[focused];\n if (hovered && !hovered.disabled) {\n onSelect(hovered.value);\n }\n } else {\n const values = [...selected].sort().map((i) => options[i].value);\n onSelect(values);\n }\n },\n },\n ];\n\n if (columns > 1) {\n bindings.splice(1, 0, {\n match: [KeyMatch.LeftArrow, KeyMatch.RightArrow],\n label: '\\u2190\\u2192',\n action: 'navigate',\n handler: (_input, key) => {\n const col = Math.floor(focused / rows);\n const row = focused % rows;\n\n let next = focused;\n if (key.leftArrow) {\n const prevCol = col > 0 ? col - 1 : columns - 1;\n next = Math.min(prevCol * rows + row, options.length - 1);\n }\n if (key.rightArrow) {\n const nextCol = col < columns - 1 ? col + 1 : 0;\n next = Math.min(nextCol * rows + row, options.length - 1);\n }\n // Landing on a disabled option slides to the column's nearest\n // enabled one.\n if (options[next]?.disabled) {\n next = stepEnabled(options, rows, next, 1);\n }\n setFocused(next);\n },\n });\n }\n\n useKeyBindings('multi-picker', bindings);\n\n const columnArrays: PickerOption<T>[][] = [];\n for (let c = 0; c < columns; c++) {\n columnArrays.push(options.slice(c * rows, c * rows + rows));\n }\n\n return (\n <Box flexDirection=\"column\" alignItems={centered ? 'center' : undefined}>\n <PromptLabel message={message} />\n <Box\n flexDirection=\"row\"\n gap={4}\n marginLeft={centered ? 0 : 2}\n marginTop={1}\n >\n {columnArrays.map((colOpts, colIdx) => (\n <Box key={colIdx} flexDirection=\"column\">\n {colOpts.map((opt, rowIdx) => {\n const flatIdx = colIdx * rows + rowIdx;\n const isFocused = flatIdx === focused;\n const isSelected = selected.has(flatIdx);\n const label = opt.hint ? `${opt.label} (${opt.hint})` : opt.label;\n const checkbox = isSelected\n ? Icons.squareFilled\n : Icons.squareOpen;\n return (\n <Box key={flatIdx} gap={1} marginBottom={optionMarginBottom}>\n <Text\n color={isSelected ? 'white' : Colors.muted}\n dimColor={!isFocused && !isSelected}\n >\n {checkbox}\n </Text>\n {opt.icon && (\n <Text color={opt.icon.color}>{opt.icon.glyph}</Text>\n )}\n <Text\n color={\n opt.disabled\n ? Colors.muted\n : isFocused\n ? Colors.accent\n : undefined\n }\n bold={isFocused && !opt.disabled}\n dimColor={!isFocused || opt.disabled}\n >\n {label}\n </Text>\n </Box>\n );\n })}\n </Box>\n ))}\n </Box>\n </Box>\n );\n};\n","/**\n * Mount an Ink picker over a command's `children` and dispatch the\n * selected child's handler.\n *\n * Used as the `interactiveDefault` for family parents like\n * `wizard audit` — when the user invokes the parent without a leaf, this\n * shows a TUI menu instead of yargs's `demandCommand(1)` help dump.\n *\n * The picker opens when a family surfaces more than one option; the `default`\n * flag controls which one is pre-highlighted. When a family surfaces a single\n * option (today `audit` → `events`), `familyCommandFactory` runs it directly\n * instead, so the user lands on its intro screen rather than a one-item menu.\n *\n * Single-option commands aren't families — they should be flat\n * commands wired with `skillCommandFactory` / `nativeCommandFactory`\n * directly, not run through this module.\n */\n\nimport type { Arguments } from 'yargs';\nimport { Box, Text, render } from 'ink';\nimport { createElement } from 'react';\n\nimport { Colors } from '@ui/tui/styles';\nimport { PickerMenu } from '@ui/tui/primitives/PickerMenu';\n\nimport { commandKeys, type Command } from '../command';\n\ninterface FamilyPickerAppProps {\n parentLabel: string;\n options: { label: string; value: Command; hint?: string }[];\n onSelect: (cmd: Command) => void;\n}\n\nfunction FamilyPickerApp(props: FamilyPickerAppProps) {\n return createElement(\n Box,\n { flexDirection: 'column', paddingX: 1, paddingY: 1 },\n createElement(\n Text,\n { bold: true, color: Colors.accent },\n props.parentLabel,\n ),\n createElement(Box, { height: 1 }),\n createElement(PickerMenu<Command>, {\n message: 'Pick a subcommand',\n options: props.options,\n optionMarginBottom: 1,\n onSelect: (value) => {\n // PickerMenu in single mode returns one value; only the multi-mode\n // signature is the array variant. Narrow defensively.\n const cmd = Array.isArray(value) ? value[0] : value;\n if (cmd) props.onSelect(cmd);\n },\n }),\n );\n}\n\nfunction describe(child: Command): string {\n // Strip positional syntax (`search <query>` → `search`) for the picker label.\n return commandKeys(child.name)[0] ?? '';\n}\n\n/**\n * Reorder children so the `default`-marked entry is first, while\n * preserving the relative order of the rest. The picker's initial\n * focus is index 0, so this is what makes \"press Enter on\n * `wizard audit`\" run the default leaf (today `audit events`).\n *\n * Exported for testability — the ordering logic stays pure and\n * inspectable without mounting Ink.\n */\nexport function orderFamilyChildren(children: readonly Command[]): Command[] {\n const selectable = children.filter((c) => c.handler || c.children?.length);\n const defaults = selectable.filter((c) => c.default);\n const rest = selectable.filter((c) => !c.default);\n return [...defaults, ...rest];\n}\n\n/**\n * Render the picker. Resolves once the user has selected a child;\n * dispatching the child's handler is the caller's responsibility (so this\n * function stays pure-UI and easy to test by stubbing `render`).\n */\nexport function chooseFamilyChild(\n parentLabel: string,\n children: readonly Command[],\n): Promise<Command | null> {\n const ordered = orderFamilyChildren(children);\n if (ordered.length === 0) return Promise.resolve(null);\n\n const options = ordered.map((child) => ({\n label: describe(child),\n value: child,\n hint: child.description,\n }));\n\n return new Promise((resolve) => {\n let app: ReturnType<typeof render> | null = null;\n const handleSelect = (cmd: Command): void => {\n app?.unmount();\n resolve(cmd);\n };\n app = render(\n createElement(FamilyPickerApp, {\n parentLabel,\n options,\n onSelect: handleSelect,\n }),\n );\n });\n}\n\n/**\n * Returns an `interactiveDefault` handler for a family parent's no-leaf\n * invocation. Always opens the picker; the `default`-marked child is\n * shown first (pre-highlighted), so a single Enter keystroke runs it.\n *\n * Discovery + consent in one extra keystroke vs. auto-running silently.\n *\n * Wire onto a family parent:\n * export const auditCommand: Command = {\n * name: 'audit',\n * description: '...',\n * children: [...],\n * interactiveDefault: createFamilyPickerDefault('audit', auditChildren),\n * };\n */\nexport function createFamilyPickerDefault(\n parentLabel: string,\n children: readonly Command[],\n chooser: (\n label: string,\n children: readonly Command[],\n ) => Promise<Command | null> = chooseFamilyChild,\n): (argv: Arguments) => Promise<void> {\n return async (argv) => {\n const chosen = await chooser(parentLabel, children);\n if (!chosen) return;\n // We forward the PARENT's parsed argv straight to the chosen child. The\n // child's own option defaults and `check` validator do NOT run on this\n // path — they only run when the leaf is invoked directly\n // (`wizard audit events`). Harmless while leaves declare neither, but if a\n // leaf ever grows a `check` or a defaulted option, this path will skip it.\n await Promise.resolve(chosen.handler?.(argv));\n };\n}\n","import type { Arguments } from 'yargs';\n\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport {\n buildFamilyPickerChildren,\n dispatchFamily,\n pickerChildrenToShow,\n} from '@lib/programs/dispatch-family';\nimport { getSkillsBaseUrl } from '@lib/constants';\nimport { fetchSkillMenu } from '@lib/wizard-tools';\n\nimport type { Command } from '../command';\nimport { createFamilyPickerDefault } from './family-picker';\nimport { mergeCommandOptions, runCommandHandler } from './shared';\n\nexport interface FamilyCommandFactoryOpts {\n /** The family's CLI name (e.g. 'audit'). */\n family: string;\n /** Help text for `wizard <family> --help`. */\n description: string;\n /**\n * Source for shared CLI options (e.g. --install-dir) merged onto the\n * family parent. Usually the family's flagship native config, or the\n * generic agent-skill config.\n */\n optionsFrom: ProgramConfig;\n}\n\n/**\n * Build a yargs `Command` for a family parent (`wizard audit`, etc.).\n *\n * - `wizard <family> <sub>` — `dispatchFamily` resolves `<sub>` against\n * native handlers first, then the live `cliEntries` from\n * `skill-menu.json`. Unknown subs error with the available list.\n * - `wizard <family>` (no positional) — in an interactive terminal, runs the\n * family's single shown entry directly (today `audit events`, so the user\n * lands on its intro screen); opens the picker once a family shows more than\n * one. In non-TTY/CI, falls through to `dispatchFamily`, which prints\n * \"requires a subcommand\" rather than running something unprompted.\n *\n * No static yargs children. New skill-backed subcommands appear after a\n * context-mill release without a wizard release. New *native* subcommands\n * (rare) are added by updating `NATIVE_HANDLERS` in `dispatch-family.ts`.\n */\nexport function familyCommandFactory({\n family,\n description,\n optionsFrom,\n}: FamilyCommandFactoryOpts): Command {\n // Bare `wizard <family>` in an interactive terminal. With a single option\n // today (e.g. `audit events`), skip the picker and run it directly so the\n // user lands on its own intro screen rather than a one-item menu. When a\n // family grows past one shown option, this opens the picker instead — no\n // wiring change needed.\n const openFamilyEntry = async (argv: Arguments): Promise<void> => {\n const skillsBaseUrl = getSkillsBaseUrl(Boolean(argv['local-mcp']));\n const menu = await fetchSkillMenu(skillsBaseUrl);\n const children = buildFamilyPickerChildren(family, menu?.cliEntries ?? []);\n const toShow = pickerChildrenToShow(children);\n if (toShow.length === 1 && toShow[0]?.handler) {\n await Promise.resolve(toShow[0].handler(argv));\n return;\n }\n const picker = createFamilyPickerDefault(`wizard ${family}`, toShow);\n await picker(argv);\n };\n\n return {\n name: `${family} [skill]`,\n description,\n options: mergeCommandOptions(optionsFrom),\n positionals: {\n skill: {\n type: 'string',\n describe: 'Subcommand to run (omit to run the default)',\n },\n },\n handler: (argv: Arguments) => {\n const sub = (argv.skill as string | undefined)?.trim();\n // With a subcommand, resolve and run it. Without one, run the family's\n // default entry (or open the picker if there's more than one) — but only\n // in an interactive terminal. In non-TTY/CI, fall through to\n // dispatchFamily, which prints \"requires a subcommand\" rather than\n // running something unprompted or hanging on a picker that can't render.\n // runCommandHandler awaits the async work so a rejection surfaces as a\n // clean error instead of an unhandled promise rejection.\n runCommandHandler(() =>\n sub || !process.stdout.isTTY\n ? dispatchFamily(family, argv)\n : openFamilyEntry(argv),\n );\n },\n interactiveDefault: openFamilyEntry,\n };\n}\n","import { auditConfig } from '@lib/programs/audit/index';\n\nimport type { Command } from './command';\nimport { familyCommandFactory } from './factories/family-command-factory';\n\n/**\n * The `wizard audit` family.\n *\n * Subcommands are resolved at runtime: the wizard fetches `cliEntries` from\n * `skill-menu.json` and dispatches based on `parentCommand: 'audit'`. The\n * wizard-native handler for `web-analytics` lives in `NATIVE_HANDLERS` over\n * in `dispatch-family.ts`. `wizard audit` with no positional opens the\n * family picker, which combines native + live entries.\n *\n * Adding a new skill-backed audit subcommand is a context-mill release —\n * no wizard release needed.\n */\nexport const auditCommand: Command = familyCommandFactory({\n family: 'audit',\n description: auditConfig.description,\n optionsFrom: auditConfig,\n});\n","import { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { readApiKeyFromEnv } from '@utils/env-api-key';\nimport { runWizard } from '@lib/runners';\nimport {\n posthogDoctorConfig,\n fetchHealthIssues,\n getKindMeta,\n} from '@lib/programs/posthog-doctor/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const doctorCommand: Command = {\n name: 'doctor',\n description: posthogDoctorConfig.description,\n options: {\n ...skillProgramOptions,\n ...(posthogDoctorConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n posthogDoctorConfig.mapCliOptions?.(argv as Record<string, unknown>) ??\n {};\n const options = { ...argv, ...extras };\n // doctor is otherwise a TUI-only diagnostic (it has no agent run); in CI we\n // fetch the project's health issues headlessly and report them instead.\n if (options.ci) {\n void runDoctorCI(options);\n } else {\n runWizard(posthogDoctorConfig, options);\n }\n },\n};\n\nconst SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 } as const;\n\nasync function runDoctorCI(options: Record<string, unknown>): Promise<void> {\n setUI(new LoggingUI());\n const apiKey = (options.apiKey as string) ?? readApiKeyFromEnv() ?? undefined;\n if (!apiKey) {\n getUI().intro('PostHog Wizard');\n getUI().log.error('CI mode requires --api-key (personal API key phx_xxx)');\n process.exit(1);\n }\n\n getUI().intro('Welcome to the PostHog setup wizard');\n getUI().log.info('Running posthog-doctor in CI mode');\n\n try {\n const { getOrAskForProjectData } = await import('@utils/setup-utils');\n const { host, accessToken, projectId } = await getOrAskForProjectData({\n signup: false,\n ci: true,\n apiKey,\n projectId: options.projectId\n ? Number(options.projectId as string)\n : undefined,\n });\n\n const issues = await fetchHealthIssues(accessToken, host, projectId);\n if (issues.length === 0) {\n getUI().log.success('No active issues — your project looks healthy.');\n process.exit(0);\n }\n\n const sorted = [...issues].sort(\n (a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity],\n );\n getUI().log.warn(\n `${issues.length} active issue${issues.length === 1 ? '' : 's'} found:`,\n );\n for (const issue of sorted) {\n getUI().log.info(\n ` • [${issue.severity}] ${getKindMeta(issue.kind).title}`,\n );\n }\n process.exit(1);\n } catch (error) {\n const { ApiError } = await import('@lib/api');\n const message =\n error instanceof ApiError && error.statusCode === 401\n ? 'Your PostHog API key is invalid or expired.'\n : error instanceof Error\n ? error.message\n : String(error);\n getUI().log.error(`Doctor failed: ${message}`);\n process.exit(1);\n }\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\n\nimport type { Command } from '../command';\n\nimport { dispatchProgram, mergeCommandOptions } from './shared';\n\nexport interface NativeCommandFactoryOpts {\n /** Subcommands nested under this command. */\n children?: readonly Command[];\n}\n\n/**\n * Build a yargs `Command` from a wizard-native `ProgramConfig`.\n *\n * Collapses the previously duplicated boilerplate (read `config.command`,\n * merge skill-program flags with program-specific options, dispatch via\n * `runWizard` / `runWizardCI`) into a single call.\n */\nexport function nativeCommandFactory(\n config: ProgramConfig,\n opts: NativeCommandFactoryOpts = {},\n): Command {\n if (!config.command) {\n throw new Error(\n `nativeCommandFactory: program \"${config.id}\" has no \\`command\\` — wizard-native programs must declare a CLI name`,\n );\n }\n return {\n name: config.command,\n description: config.description,\n options: mergeCommandOptions(config),\n children: opts.children,\n handler: (argv) => dispatchProgram(config, argv),\n };\n}\n","import { migrationConfig } from '@lib/programs/migration/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard migrate` — flat skill command, Statsig today.\n *\n * Stays flat while there's only one vendor. When a second vendor lands,\n * restructure into a family with `familyCommandFactory` and publish each\n * vendor as a `cliEntries` entry with `parentCommand: 'migrate'` from\n * context-mill. That move is a deliberate breaking change for users\n * (`wizard migrate` stops running Statsig directly), so do it explicitly\n * when the second vendor arrives, not pre-emptively.\n */\nexport const migrateCommand: Command = nativeCommandFactory(migrationConfig);\n","import { revenueAnalyticsConfig } from '@lib/programs/revenue-analytics/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard revenue-analytics` — flat skill command, Stripe today.\n *\n * Stays flat while there's only one provider. Restructure into a family\n * if/when a second provider lands.\n */\nexport const revenueCommand: Command = nativeCommandFactory(\n revenueAnalyticsConfig,\n);\n","import type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from './command';\n\nexport const slackCommand: Command = {\n name: 'slack',\n description: 'Connect PostHog to your Slack',\n handler: runSlackConnect,\n // Mirrors the mcp command family shape: `wizard slack` and\n // `wizard slack add` run the same connect flow.\n children: [\n {\n name: 'add',\n description: 'Connect PostHog to your Slack',\n handler: runSlackConnect,\n },\n ],\n};\n\nfunction runSlackConnect(argv: Arguments): void {\n void (async () => {\n const debug = argv.debug as boolean | undefined;\n\n try {\n const { startTUI } = await import('@ui/tui/start-tui');\n const { buildSession } = await import('@lib/wizard-session');\n const tui = startTUI(VERSION, Program.SlackConnect);\n tui.store.session = buildSession({ debug });\n } catch (err) {\n // TUI unavailable — connecting Slack has no headless fallback.\n setUI(new LoggingUI());\n getUI().log.error(\n `Connecting Slack requires an interactive terminal. ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n process.exit(1);\n }\n })();\n}\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { errorTrackingUploadSourceMapsConfig } from '@lib/programs/error-tracking-upload-source-maps/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const uploadSourcemapsCommand: Command = {\n // Must match ProgramConfig.command; legacy alias kept for #489 regression.\n name: [errorTrackingUploadSourceMapsConfig.command!, 'upload-sourcemaps'],\n description: errorTrackingUploadSourceMapsConfig.description,\n options: {\n ...skillProgramOptions,\n ...(errorTrackingUploadSourceMapsConfig.cliOptions ?? {}),\n },\n handler: (argv) => {\n const extras =\n errorTrackingUploadSourceMapsConfig.mapCliOptions?.(\n argv as Record<string, unknown>,\n ) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(errorTrackingUploadSourceMapsConfig, options);\n } else {\n runWizard(errorTrackingUploadSourceMapsConfig, options);\n }\n },\n};\n","import type { Arguments } from 'yargs';\nimport { POSTHOG_DOCS_URL } from '@lib/constants';\nimport { runWizard, runWizardCI } from '@lib/runners';\nimport { createSkillProgram } from '@lib/programs/agent-skill/index';\n\n/** Run an arbitrary context-mill skill by id (`wizard skill <id>`, headless with `--ci`). */\nexport function runSkillMode(argv: Arguments): void {\n const skillId = argv.skill as string;\n const config = createSkillProgram({\n skillId,\n command: 'skill',\n id: 'agent-skill',\n description: `Run skill: ${skillId}`,\n integrationLabel: skillId,\n successMessage: `${skillId} completed!`,\n reportFile: `posthog-${skillId}-report.md`,\n docsUrl: POSTHOG_DOCS_URL,\n spinnerMessage: `Running ${skillId}...`,\n estimatedDurationMinutes: 5,\n });\n const options = { ...argv, skillId };\n if (argv.ci) {\n runWizardCI(config, options);\n } else {\n runWizard(config, options);\n }\n}\n","import type { Arguments } from 'yargs';\n\nimport { getSkillsBaseUrl } from '@lib/constants';\nimport { fetchSkillMenu, type CliEntry } from '@lib/wizard-tools';\nimport { analytics } from '@utils/analytics';\n\nimport { runSkillMode } from './basic-integration/skill';\nimport { skillProgramOptions } from './skill-program-options';\nimport { runCommandHandler } from './factories/shared';\nimport type { Command } from './command';\n\n/** Read the `<skill-name>` positional (yargs camelCases the hyphenated key). */\nfunction readSkillName(argv: Arguments): string {\n return String(argv.skillName ?? argv['skill-name'] ?? '').trim();\n}\n\nconst BROWSABLE_ROLES: ReadonlySet<CliEntry['role']> = new Set([\n 'command',\n 'skill',\n]);\n\nfunction formatEntry(entry: CliEntry): string {\n const path = entry.parentCommand\n ? `wizard ${entry.parentCommand} ${entry.command}`\n : entry.command\n ? `wizard ${entry.command}`\n : `wizard skill ${entry.skillId}`;\n return ` ${entry.skillId.padEnd(38)} ${path.padEnd(36)} ${\n entry.description\n }`;\n}\n\n/**\n * `wizard skill list` — fetch and print every browsable skill in the catalog.\n *\n * Reads the live `skill-menu.json` so new skills appear immediately after a\n * context-mill release. `internal` skills are excluded from the listing.\n */\nconst listCommand: Command = {\n name: 'list',\n description: 'List every browsable skill in the catalog',\n handler: (argv) => {\n runCommandHandler(async () => {\n const skillsBaseUrl = getSkillsBaseUrl(Boolean(argv['local-mcp']));\n const menu = await fetchSkillMenu(skillsBaseUrl);\n if (!menu) {\n analytics.wizardCapture('cli dispatch error', {\n reason: 'registry unreachable',\n family: 'skill',\n sub: 'list',\n skillsBaseUrl,\n });\n try {\n await analytics.flush();\n } catch {\n /* best-effort */\n }\n process.stderr.write(\n `\\n\\x1b[1;91m✖ Couldn't reach the skill registry.\\x1b[0m\\n` +\n ` Check your network connection and try again.\\n\\n`,\n );\n process.exit(1);\n }\n const entries = (menu.cliEntries ?? []).filter((e) =>\n BROWSABLE_ROLES.has(e.role),\n );\n if (entries.length === 0) {\n process.stdout.write('No skills found.\\n');\n return;\n }\n process.stdout.write(\n `${entries.length} skill${entries.length === 1 ? '' : 's'}:\\n`,\n );\n process.stdout.write(\n ` ${'SKILL ID'.padEnd(38)} ${'COMMAND'.padEnd(36)} DESCRIPTION\\n`,\n );\n for (const entry of entries) {\n process.stdout.write(`${formatEntry(entry)}\\n`);\n }\n });\n },\n};\n\n/**\n * `wizard skill <skill-name>` — run a single context-mill skill by id.\n * `wizard skill list` — list every browsable skill in the catalog.\n *\n * Replaces the old `--skill=<id>` flag on the default command. The skill id\n * is fetched from context-mill's release at runtime (same mechanism the flag\n * used), so any published skill id works. Pass `--ci` to run headlessly.\n */\nexport const skillCommand: Command = {\n name: 'skill <skill-name>',\n description: 'Run a specific context-mill skill by name (or `list` them)',\n children: [listCommand],\n options: {\n ...skillProgramOptions,\n },\n // yargs already enforces the `<skill-name>` positional, but an\n // explicitly-empty value (`wizard skill \"\"`) would otherwise slip\n // through to a broken run. Reject it with the same friendly message\n // the old --skill flag gave. When `wizard skill list` matched the\n // child instead, yargs leaves the positional unset — the `null` guard\n // keeps the check from rejecting that route.\n check: (argv) => {\n if (argv.skillName == null && argv['skill-name'] == null) return true;\n if (!readSkillName(argv)) {\n throw new Error(\n 'skill needs a skill name, e.g. `wizard skill audit-events`',\n );\n }\n return true;\n },\n handler: (argv) => {\n // runSkillMode reads `argv.skill`; bridge the positional onto it.\n runSkillMode({ ...argv, skill: readSkillName(argv) });\n },\n};\n","#!/usr/bin/env node\nimport { satisfies } from 'semver';\n\nconst NODE_VERSION_RANGE = '>=18.17.0';\n\n// Have to run this above the other imports because they are importing clack that\n// has the problematic imports.\nif (!satisfies(process.version, NODE_VERSION_RANGE)) {\n // eslint-disable-next-line no-console\n console.log(\n `PostHog wizard requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`,\n );\n process.exit(1);\n}\n\n// Test mock server — only loaded when NODE_ENV is 'test'.\n// In production builds, tsdown replaces process.env.NODE_ENV with 'production',\n// making this block dead code.\nif (process.env.NODE_ENV === 'test') {\n void (async () => {\n try {\n const { server } = await import('./e2e-tests/mocks/server.js');\n server.listen({\n onUnhandledRequest: 'bypass',\n });\n } catch (error) {\n // Mock server import failed - this can happen during non-E2E tests\n }\n })();\n}\n\nimport { Wizard } from './src/wizard';\nimport { basicIntegrationCommand } from './src/commands/basic-integration';\nimport { mcpCommand } from './src/commands/mcp';\nimport { auditCommand } from './src/commands/audit';\nimport { doctorCommand } from './src/commands/doctor';\nimport { migrateCommand } from './src/commands/migrate';\nimport { revenueCommand } from './src/commands/revenue';\nimport { slackCommand } from './src/commands/slack';\nimport { uploadSourcemapsCommand } from './src/commands/upload-sourcemaps';\nimport { skillCommand } from './src/commands/skill';\nimport { recoverOrphanedSettingsBackups } from './src/lib/agent/claude-settings';\n\n// Heal any .claude/settings backup a previous interrupted run left orphaned,\n// before anything else reads Claude settings — conflict detection, OAuth, and\n// the agent all need to see the user's real settings file. The install dir is\n// read directly from argv/env because yargs hasn't parsed yet.\nrecoverOrphanedSettingsBackups(resolveInstallDir());\n\nfunction resolveInstallDir(): string {\n const args = process.argv.slice(2);\n const flagIndex = args.indexOf('--install-dir');\n if (flagIndex !== -1 && args[flagIndex + 1]) return args[flagIndex + 1];\n const inline = args.find((a) => a.startsWith('--install-dir='));\n if (inline) return inline.slice('--install-dir='.length);\n return process.env.POSTHOG_WIZARD_INSTALL_DIR ?? process.cwd();\n}\n\nWizard.use(basicIntegrationCommand)\n .use(mcpCommand)\n .use(auditCommand)\n .use(doctorCommand)\n .use(migrateCommand)\n .use(revenueCommand)\n .use(slackCommand)\n .use(uploadSourcemapsCommand)\n .use(skillCommand)\n .init();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,YAAY,MAA4C;AAEtE,SADgC,OAAO,SAAS,WAAW,CAAC,KAAK,GAAG,MACxD,KAAK,MAAM,EAAE,M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