@posthog/wizard 2.73.0 → 2.73.2
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.
- package/dist/{add-mcp-server-to-clients-B8t2xAPf.js → add-mcp-server-to-clients-BaVuIyoj.js} +4 -4
- package/dist/{add-mcp-server-to-clients-B8t2xAPf.js.map → add-mcp-server-to-clients-BaVuIyoj.js.map} +1 -1
- package/dist/{agent-interface-tcCEmyPQ.js → agent-interface-Dm28tBj-.js} +8 -8
- package/dist/agent-interface-Dm28tBj-.js.map +1 -0
- package/dist/{agent-prompt-loader-V2smIztP.js → agent-prompt-loader-Dv9HIHm1.js} +5 -5
- package/dist/{agent-prompt-loader-V2smIztP.js.map → agent-prompt-loader-Dv9HIHm1.js.map} +1 -1
- package/dist/{agent-runner-DUyO1Ehj.js → agent-runner-C1Dwg9sa.js} +14 -14
- package/dist/{agent-runner-DUyO1Ehj.js.map → agent-runner-C1Dwg9sa.js.map} +1 -1
- package/dist/{analytics-DsMH06jo.js → analytics-BY4qZ0AC.js} +2 -2
- package/dist/{analytics-DsMH06jo.js.map → analytics-BY4qZ0AC.js.map} +1 -1
- package/dist/analytics-Bhw7ODc0.js +2 -0
- package/dist/{api-R6bXIwII.js → api-DwWMv1Qc.js} +3 -3
- package/dist/{api-R6bXIwII.js.map → api-DwWMv1Qc.js.map} +1 -1
- package/dist/bin.js +45 -45
- package/dist/bin.js.map +1 -1
- package/dist/{bounded-fs-BV-KhOtU.js → bounded-fs-DIYnGoSv.js} +3 -3
- package/dist/{bounded-fs-BV-KhOtU.js.map → bounded-fs-DIYnGoSv.js.map} +1 -1
- package/dist/{ci-install-mR8CeIt2.js → ci-install-BL5ObQ3S.js} +4 -4
- package/dist/{ci-install-mR8CeIt2.js.map → ci-install-BL5ObQ3S.js.map} +1 -1
- package/dist/{debug-aXxgvtal.js → debug-BrWB-OAq.js} +3 -3
- package/dist/{debug-aXxgvtal.js.map → debug-BrWB-OAq.js.map} +1 -1
- package/dist/{debug-PfLVvLhT.js → debug-CY2VLyCW.js} +1 -1
- package/dist/{env-api-key-_lBt9tHl.js → env-api-key-C6XP1N9g.js} +2 -2
- package/dist/{env-api-key-_lBt9tHl.js.map → env-api-key-C6XP1N9g.js.map} +1 -1
- package/dist/{environment-DRhZbhxU.js → environment-CXxQd0SR.js} +4 -4
- package/dist/{environment-DRhZbhxU.js.map → environment-CXxQd0SR.js.map} +1 -1
- package/dist/{file-watcher-BZw1_Y84.js → file-watcher-Duj0RMwi.js} +2 -2
- package/dist/{file-watcher-BZw1_Y84.js.map → file-watcher-Duj0RMwi.js.map} +1 -1
- package/dist/{headless-ui-Cdqfufhk.js → headless-ui-B1hA9Rx8.js} +2 -2
- package/dist/{headless-ui-Cdqfufhk.js.map → headless-ui-B1hA9Rx8.js.map} +1 -1
- package/dist/{interactive-BCI9b-dp.js → interactive-B2OUN9yB.js} +2 -2
- package/dist/{interactive-BCI9b-dp.js.map → interactive-B2OUN9yB.js.map} +1 -1
- package/dist/{mcp-CzB3lWsm.js → mcp-BkHaEmEn.js} +2 -2
- package/dist/{mcp-CzB3lWsm.js.map → mcp-BkHaEmEn.js.map} +1 -1
- package/dist/{mcp-prompt-streaming-RZGAH4YO.js → mcp-prompt-streaming-hV0rkw9s.js} +4 -4
- package/dist/{mcp-prompt-streaming-RZGAH4YO.js.map → mcp-prompt-streaming-hV0rkw9s.js.map} +1 -1
- package/dist/{non-interactive-CgjTZZ9J.js → non-interactive-ByaO-qoX.js} +2 -2
- package/dist/{non-interactive-CgjTZZ9J.js.map → non-interactive-ByaO-qoX.js.map} +1 -1
- package/dist/{orchestrator-tools-OWgPinUt.js → orchestrator-tools-pBKJnRjl.js} +3 -3
- package/dist/{orchestrator-tools-OWgPinUt.js.map → orchestrator-tools-pBKJnRjl.js.map} +1 -1
- package/dist/{package-manager-B-Z3IVYu.js → package-manager-CIm2MNel.js} +2 -2
- package/dist/{package-manager-B-Z3IVYu.js.map → package-manager-CIm2MNel.js.map} +1 -1
- package/dist/{pi-CLLkGrND.js → pi-Dj0EHErj.js} +11 -11
- package/dist/{pi-CLLkGrND.js.map → pi-Dj0EHErj.js.map} +1 -1
- package/dist/{playground-D1TgX0EU.js → playground-UJyt6uLu.js} +6 -6
- package/dist/{playground-D1TgX0EU.js.map → playground-UJyt6uLu.js.map} +1 -1
- package/dist/{posthog-CMef8KLR.js → posthog-BuIPmmdp.js} +2 -2
- package/dist/{posthog-CMef8KLR.js.map → posthog-BuIPmmdp.js.map} +1 -1
- package/dist/{posthog-integration-wiunwp8X.js → posthog-integration-HXLZnann.js} +12 -12
- package/dist/{posthog-integration-wiunwp8X.js.map → posthog-integration-HXLZnann.js.map} +1 -1
- package/dist/{provisioning-94OneD64.js → provisioning-B9kEzRE_.js} +3 -3
- package/dist/{provisioning-94OneD64.js.map → provisioning-B9kEzRE_.js.map} +1 -1
- package/dist/{queue-tools--k2v8QYY.js → queue-tools-CDqueOnz.js} +3 -3
- package/dist/{queue-tools--k2v8QYY.js.map → queue-tools-CDqueOnz.js.map} +1 -1
- package/dist/{registry-C60oJv02.js → registry-Cl77fAHR.js} +5 -5
- package/dist/{registry-C60oJv02.js.map → registry-Cl77fAHR.js.map} +1 -1
- package/dist/{security-DnOP36w-.js → security-CfoEOKN4.js} +5 -5
- package/dist/{security-DnOP36w-.js.map → security-CfoEOKN4.js.map} +1 -1
- package/dist/{setup-utils-BwX6QmL_.js → setup-utils-BVQaFad8.js} +8 -8
- package/dist/{setup-utils-BwX6QmL_.js.map → setup-utils-BVQaFad8.js.map} +1 -1
- package/dist/{start-tui-C3PdKFtP.js → start-tui-DJGq1bFx.js} +20 -20
- package/dist/{start-tui-C3PdKFtP.js.map → start-tui-DJGq1bFx.js.map} +1 -1
- package/dist/{steps-BpCRk8Ef.js → steps-BLrL5Kst.js} +7 -7
- package/dist/{steps-BpCRk8Ef.js.map → steps-BLrL5Kst.js.map} +1 -1
- package/dist/{store-EzqWyb60.js → store-l1aCLB7H.js} +4 -4
- package/dist/{store-EzqWyb60.js.map → store-l1aCLB7H.js.map} +1 -1
- package/dist/{subagent-DwdrVprk.js → subagent-BAU9BElX.js} +2 -2
- package/dist/{subagent-DwdrVprk.js.map → subagent-BAU9BElX.js.map} +1 -1
- package/dist/{task-CrXgNEUB.js → task-B7LbltJW.js} +12 -12
- package/dist/{task-CrXgNEUB.js.map → task-B7LbltJW.js.map} +1 -1
- package/dist/{task-stream-ZBbfHo7l.js → task-stream-Du_99Tv-.js} +4 -4
- package/dist/{task-stream-ZBbfHo7l.js.map → task-stream-Du_99Tv-.js.map} +1 -1
- package/dist/{tasks-CbMEKWZ9.js → tasks-7XjlfAbk.js} +2 -2
- package/dist/{tasks-CbMEKWZ9.js.map → tasks-7XjlfAbk.js.map} +1 -1
- package/dist/{telemetry-B2dz2-PT.js → telemetry-CW5a6Bog.js} +3 -3
- package/dist/{telemetry-B2dz2-PT.js.map → telemetry-CW5a6Bog.js.map} +1 -1
- package/dist/{terminal-DTe59M4j.js → terminal-DMZIApv7.js} +11 -11
- package/dist/{terminal-DTe59M4j.js.map → terminal-DMZIApv7.js.map} +1 -1
- package/dist/{tools-DZ9lZgJI.js → tools-CIkbTll3.js} +6 -6
- package/dist/{tools-DZ9lZgJI.js.map → tools-CIkbTll3.js.map} +1 -1
- package/dist/{wizard-abort-CUT8MXXt.js → wizard-abort-DcuNitMi.js} +3 -3
- package/dist/{wizard-abort-CUT8MXXt.js.map → wizard-abort-DcuNitMi.js.map} +1 -1
- package/dist/{wizard-abort-CfKnrSlX.js → wizard-abort-serrH83C.js} +1 -1
- package/dist/{yara-hooks-VvwkZn5s.js → yara-hooks-BKhDtn2N.js} +4 -4
- package/dist/{yara-hooks-VvwkZn5s.js.map → yara-hooks-BKhDtn2N.js.map} +1 -1
- package/dist/yara-hooks-rZT6WNop.js +2 -0
- package/package.json +2 -2
- package/dist/agent-interface-tcCEmyPQ.js.map +0 -1
- package/dist/analytics-DEL7clQK.js +0 -2
- package/dist/yara-hooks-CLeMu2EY.js +0 -2
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":["getContentBlocks","DOCS_URL","REPORT_FILE","DOCS_URL","getContentBlocks","getContentBlocks","fs","path","REPORT_FILE","DOCS_URL","agentSkillContentBlocks","join","join","path"],"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/warehouse-source/steps.ts","../src/lib/programs/warehouse-source/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/steps/install-cli-steering/index.ts","../src/lib/programs/error-tracking-upload-source-maps/index.ts","../src/lib/programs/self-driving/detect.ts","../src/lib/programs/self-driving/detect-agentic.ts","../src/lib/programs/self-driving/steps.ts","../src/lib/programs/self-driving/prompt.ts","../src/lib/programs/self-driving/step-keys.ts","../src/lib/programs/self-driving/content/pricing.ts","../src/lib/programs/self-driving/content/tips.ts","../src/lib/programs/self-driving/content/pipeline-diagram.tsx","../src/lib/programs/self-driving/content/index.tsx","../src/lib/programs/self-driving/index.ts","../src/lib/programs/mcp/index.ts","../src/lib/programs/mcp-analytics/index.ts","../src/lib/programs/replay-vision/index.ts","../src/lib/programs/ai-observability/index.ts","../src/lib/programs/metrics/index.ts","../src/lib/programs/slack/index.ts","../src/lib/programs/program-registry.ts","../src/commands/mcp/tui-availability.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-non-interactive.ts","../src/lib/runners/run-wizard-ci.ts","../src/lib/runners/run-wizard-headless.ts","../src/commands/skill-program-options.ts","../src/commands/factories/shared.ts","../src/commands/factories/native-command-factory.ts","../src/commands/mcp-analytics.ts","../src/commands/replay-vision.ts","../src/commands/ai-observability.ts","../src/commands/metrics.ts","../src/lib/programs/dispatch-family.ts","../src/ui/tui/primitives/picker-filter.ts","../src/ui/tui/primitives/PromptLabel.tsx","../src/ui/tui/primitives/ConfirmButton.tsx","../src/ui/tui/hooks/useStdoutDimensions.ts","../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/migrate.ts","../src/commands/revenue.ts","../src/commands/warehouse.ts","../src/commands/self-driving.ts","../src/commands/slack.ts","../src/commands/upload-sourcemaps.ts","../src/commands/basic-integration/skill.ts","../src/commands/skill.ts","../src/commands/cli/add.ts","../src/commands/cli/index.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 { Harness, Sequence } from '@lib/constants';\nimport { regionOption } from '@lib/headless-mode';\nimport { initLocalDev, localMcpSkillsNotice } from '@lib/local-dev';\nimport { toCommandModule, type Command } from './commands/command';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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 `--local-*` flags live\n * in the constructor's `!IS_PRODUCTION_BUILD` block instead, so published\n * builds reject them; see `docs/local-dev.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 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`.\n // NB: the experimental headless flag is deliberately NOT global — it's\n // declared per-command (basic integration + audit) via `headlessOption`\n // in @lib/headless-mode, so no other command accepts it.\n 'base-url': {\n describe:\n 'Override the PostHog base URL (e.g. http://localhost:8010), bypassing region resolution. Pins the API host, cloud URL, and OAuth server.\\nenv: POSTHOG_WIZARD_BASE_URL',\n type: 'string' 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 // The published-build, non-interactive path is the experimental headless\n // flag, declared per-command on basic integration + audit via\n // `headlessOption` (see @lib/headless-mode), so no other command accepts\n // it. CI needs `region` globally because the workbench passes it to every\n // command. --ci and headless stay separate so their behavior can diverge.\n if (!IS_PRODUCTION_BUILD) {\n cli = cli\n .options(regionOption)\n .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 // Runner overrides — dev/test only, same lifecycle as --ci.\n .option('harness', {\n describe:\n 'Override the agent harness (anthropic | pi). Wins over the PostHog runner flag.\\nenv: POSTHOG_WIZARD_HARNESS',\n choices: Object.values(Harness),\n type: 'string',\n hidden: true,\n })\n .option('sequence', {\n describe:\n 'Override the runner sequence (linear | orchestrator). Wins over the PostHog orchestrator flag.\\nenv: POSTHOG_WIZARD_SEQUENCE',\n choices: Object.values(Sequence),\n type: 'string',\n hidden: true,\n })\n .option('model', {\n describe:\n 'Override the agent model (gateway id, e.g. claude-sonnet-4-6 | openai/gpt-5). Wins over the binding default.\\nenv: POSTHOG_WIZARD_MODEL',\n type: 'string',\n hidden: true,\n })\n .option('capture-aio', {\n default: false,\n describe:\n \"Capture wizard LLM calls as $ai_generation events in the authenticated project's AI Observability tab.\\nenv: POSTHOG_WIZARD_CAPTURE_AIO\",\n type: 'boolean',\n hidden: true,\n })\n // ── Local dev targets (see docs/local-dev.md) ──────────────────\n // Not `hidden`: the build gate already keeps them from users, so\n // hiding them would only cost the dev-build help row. Deliberately not\n // named `--local`, which `wizard mcp add` already uses for something\n // unrelated.\n .option('local-dev', {\n default: false,\n describe:\n 'Point context-mill, MCP, and PostHog at local dev servers\\nenv: POSTHOG_WIZARD_LOCAL_DEV',\n type: 'boolean',\n })\n // No `default` on the three below — they must stay `undefined` when\n // absent for resolveLocalDev() to honour the umbrella and `--no-*`.\n .option('local-context-mill', {\n describe:\n 'Fetch skills from the local context-mill server (http://localhost:8765)\\nenv: POSTHOG_WIZARD_LOCAL_CONTEXT_MILL',\n type: 'boolean',\n })\n .option('local-mcp', {\n describe:\n 'Use the local MCP server (http://localhost:8787/mcp). Affects MCP only — use --local-context-mill for skills.\\nenv: POSTHOG_WIZARD_LOCAL_MCP',\n type: 'boolean',\n })\n .option('local-posthog', {\n describe:\n 'Point every PostHog origin (API, app, OAuth, gateway) at http://localhost:8010\\nenv: POSTHOG_WIZARD_LOCAL_POSTHOG',\n type: 'boolean',\n });\n }\n\n this.cli = cli\n // Middleware rather than an argv scan so the env path is covered too,\n // and it runs before any TUI takes the terminal.\n .middleware((argv) => {\n // The one place local targets are resolved; everything downstream reads\n // getLocalDev().\n initLocalDev(argv);\n\n // Temporary.\n const notice = localMcpSkillsNotice({\n localDev: argv.localDev as boolean | undefined,\n localMcp: argv.localMcp as boolean | undefined,\n localContextMill: argv.localContextMill as boolean | undefined,\n });\n if (notice) {\n process.stderr.write(`\\n\\x1b[33m! ${notice}\\x1b[0m\\n\\n`);\n }\n })\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 emitWizardError({ code: ErrorCodes.CliBadArgs, message: text });\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 emitWizardError({\n code: ErrorCodes.CliFlagUnavailable,\n message: 'CI mode is not supported in published builds.',\n });\n process.exit(1);\n }\n\n // --harness / --sequence / --model / --capture-aio are dev/test-only.\n // In published builds the env vars would silently no-op, so reject them\n // explicitly instead.\n const argvHasOverride = args.some(\n (a) =>\n a === '--harness' ||\n a.startsWith('--harness=') ||\n a === '--sequence' ||\n a.startsWith('--sequence=') ||\n a === '--model' ||\n a.startsWith('--model=') ||\n a === '--capture-aio' ||\n a === '--no-capture-aio' ||\n a.startsWith('--capture-aio='),\n );\n const envHasOverride =\n (process.env.POSTHOG_WIZARD_HARNESS != null &&\n process.env.POSTHOG_WIZARD_HARNESS !== '') ||\n (process.env.POSTHOG_WIZARD_SEQUENCE != null &&\n process.env.POSTHOG_WIZARD_SEQUENCE !== '') ||\n (process.env.POSTHOG_WIZARD_MODEL != null &&\n process.env.POSTHOG_WIZARD_MODEL !== '') ||\n (process.env.POSTHOG_WIZARD_CAPTURE_AIO != null &&\n process.env.POSTHOG_WIZARD_CAPTURE_AIO !== '');\n if (argvHasOverride || envHasOverride) {\n process.stderr.write(\n `\\n\\x1b[1;91m✖ The --harness, --sequence, --model, and --capture-aio overrides are not available in published builds.\\x1b[0m\\n\\n`,\n );\n emitWizardError({\n code: ErrorCodes.CliFlagUnavailable,\n message:\n 'The --harness, --sequence, --model, and --capture-aio overrides are not available in published builds.',\n });\n process.exit(1);\n }\n\n // `--local-mcp` used to be declared unconditionally, so published builds\n // accepted it and quietly aimed the run at localhost. Reject explicitly.\n const argvHasLocalTarget = args.some((a) =>\n LOCAL_TARGET_FLAGS.some(\n (f) => a === `--${f}` || a === `--no-${f}` || a.startsWith(`--${f}=`),\n ),\n );\n const envHasLocalTarget = LOCAL_TARGET_ENV_VARS.some(\n (k) => process.env[k] != null && process.env[k] !== '',\n );\n if (argvHasLocalTarget || envHasLocalTarget) {\n process.stderr.write(\n `\\n\\x1b[1;91m✖ The --local-dev, --local-context-mill, --local-mcp, and --local-posthog targets are not available in published builds.\\x1b[0m\\n` +\n ` They point the wizard at development servers on localhost.\\n\\n`,\n );\n emitWizardError({\n code: ErrorCodes.CliFlagUnavailable,\n message:\n 'The --local-dev, --local-context-mill, --local-mcp, and --local-posthog targets are not available in published builds.',\n });\n process.exit(1);\n }\n }\n void this.cli.wrap(process.stdout.isTTY ? this.cli.terminalWidth() : 80)\n .argv;\n }\n}\n\n/** Excludes bare `local`: `wizard mcp add --local` stays available in prod. */\nconst LOCAL_TARGET_FLAGS = [\n 'local-dev',\n 'local-context-mill',\n 'local-mcp',\n 'local-posthog',\n] as const;\n\nconst LOCAL_TARGET_ENV_VARS = [\n 'POSTHOG_WIZARD_LOCAL_DEV',\n 'POSTHOG_WIZARD_LOCAL_CONTEXT_MILL',\n 'POSTHOG_WIZARD_LOCAL_MCP',\n 'POSTHOG_WIZARD_LOCAL_POSTHOG',\n] as const;\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 baseUrl: argv.baseUrl as string | undefined,\n jsonMode,\n });\n}\n\ntype ProvisionArgs = {\n email: string;\n region: 'US' | 'EU';\n name: string;\n baseUrl?: string;\n jsonMode: boolean;\n};\n\nasync function provision({\n email,\n region,\n name,\n baseUrl,\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, { baseUrl });\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 { headlessOption, isHeadless, regionOption } from '@lib/headless-mode';\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 // The experimental headless flag — declared here (and on `audit`) rather\n // than globally. Routed by this command's handler via runHeadlessInstall.\n ...headlessOption,\n ...regionOption,\n },\n check: (argv) => {\n // --playground is the standalone TUI demo; it can't combine with a\n // non-interactive run (either --ci or the experimental headless flag).\n if (argv.playground && (argv.ci || isHeadless(argv))) {\n throw new Error('--playground cannot be combined with a headless run.');\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 // ── The CI / headless division ───────────────────────────────────\n // --ci (dev/test only) and the experimental headless flag (the\n // published-build, non-interactive path; see @lib/headless-mode) both\n // request a non-interactive install, but route to dedicated entry points\n // — runHeadlessInstall vs runCIInstall (and below them runWizardHeadless\n // vs runWizardCI). Both share one pipeline today but are separate\n // functions end-to-end, so headless can diverge later without touching\n // the CI path or its callers.\n if (isHeadless(argv)) {\n const { runHeadlessInstall } = await import('./ci-install');\n return runHeadlessInstall(argv);\n }\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 { relative } from 'path';\nimport { safeReadFile, walkProjectFiles } from '@utils/bounded-fs';\n\nexport const POSTHOG_SDKS = new Set([\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n]);\n\nexport const STRIPE_SDKS = new Set([\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// At most this many matches retained, regardless of monorepo package count.\nconst MAX_PACKAGE_MATCHES = 500;\n\n/**\n * Find all package.json files under installDir via the shared bounded walk\n * (depth cap, ignored dirs, symlink-loop protection, per-dir entry cap).\n * Returns matches with detected SDKs.\n */\nexport function findPackageJsons(\n installDir: string,\n maxDepth = 3,\n): PackageMatch[] {\n const matches: PackageMatch[] = [];\n\n walkProjectFiles(\n installDir,\n (name, fullPath) => {\n if (name !== 'package.json' || matches.length >= MAX_PACKAGE_MATCHES) {\n return;\n }\n const content = safeReadFile(fullPath);\n if (content === null) return;\n try {\n const pkg = JSON.parse(content) 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.has(d));\n const stripeSdks = depNames.filter((d) => STRIPE_SDKS.has(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 },\n maxDepth,\n );\n\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 * Warehouse-source program step list.\n *\n * The detect step scans for warehouse-source signals. The skill install and\n * agent run live in the program runner (see agent-runner.ts). The skill drives\n * both in-CLI source creation and deep-link emission per detected source.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { detectWarehousePrerequisites } from './detect.js';\n\nexport const WAREHOUSE_SOURCE_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting data sources',\n // Headless step: no screen. onReady scans installDir and writes the\n // detected sources (or a detectError) to frameworkContext for the\n // intro screen to render.\n onReady: (ctx) =>\n detectWarehousePrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'warehouse-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Data warehouse',\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","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { WAREHOUSE_SOURCE_PROGRAM } from './steps.js';\nimport {\n WAREHOUSE_ABORT_CASES,\n getDetectedWarehouseSources,\n} from './detect.js';\nimport { getContentBlocks } from './content/index.js';\n\n/**\n * Inject the detected sources (and their creation mode) into the prompt so the\n * skill knows what to set up. The *how* — in-CLI creation vs deep-link, field\n * collection, validation — lives in the skill, not here.\n */\nfunction buildPrompt(session: WizardSession): string {\n const sources = getDetectedWarehouseSources(session);\n if (sources.length === 0) {\n return 'Set up a data warehouse source for this project.';\n }\n\n const lines = sources.map(\n (s) =>\n `- ${s.label} (kind: ${s.kind}, mode: ${s.mode}) — ${s.matchedSignal}`,\n );\n\n return [\n 'The wizard detected the following data warehouse sources in this project:',\n ...lines,\n '',\n 'Each signal names the file it came from. Trust that path — the wizard ' +\n 'read it. To confirm a key is set, call `check_env_keys` with the key ' +\n 'names and no `filePath`; it scans every `.env` file in the project.',\n '',\n 'Set these up in PostHog following the skill instructions: create `in-cli` ' +\n 'sources directly via the PostHog MCP after collecting credentials; for ' +\n '`deep-link` sources, provide the user the pre-filled new-source URL.',\n 'Use the `kind` string exactly as printed above for `source_type` — ' +\n 'PostHog rejects the display label.',\n ].join('\\n');\n}\n\nexport const warehouseSourceConfig: ProgramConfig = {\n command: 'warehouse',\n description:\n 'Detect and connect a data warehouse source (Postgres, Stripe, …)',\n id: 'warehouse-source',\n skillId: 'data-warehouse-source-setup',\n steps: WAREHOUSE_SOURCE_PROGRAM,\n getContentBlocks,\n reportFile: 'posthog-warehouse-report.md',\n allowedTools: ['Agent'],\n run: (session: WizardSession): Promise<ProgramRun> =>\n Promise.resolve({\n skillId: 'data-warehouse-source-setup',\n integrationLabel: 'data-warehouse-source-setup',\n customPrompt: () => buildPrompt(session),\n successMessage: 'Data warehouse source connected!',\n reportFile: 'posthog-warehouse-report.md',\n docsUrl: 'https://posthog.com/docs/data-warehouse',\n spinnerMessage: 'Connecting your data source...',\n estimatedDurationMinutes: 5,\n abortCases: WAREHOUSE_ABORT_CASES,\n }),\n requires: ['posthog-integration'],\n};\n\nexport { WAREHOUSE_SOURCE_PROGRAM } from './steps.js';\nexport {\n detectWarehousePrerequisites,\n getDetectedWarehouseSources,\n DETECTED_WAREHOUSE_SOURCES_KEY,\n WAREHOUSE_ABORT_CASES,\n type WarehouseDetectError,\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';\nimport { ErrorCodes } from '@lib/errors';\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 errorCode: ErrorCodes.DetectNoPosthogSdk,\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 path from 'path';\nimport { writeJsonAtomic } from '@utils/atomic-ledger';\nimport { logToFile } from '@utils/debug';\nimport { AUDIT_CHECKS_FILE, type AuditCheck } from './types.js';\n\n/**\n * The 10 source-tree checks the audit runs, plus one row for the PostHog-side\n * sweep and two workflow rows at the end (so the skill's\n * `audit_resolve_checks` calls for `write-report` and `upload-notebook`\n * succeed — the skill writes the report to disk, then mirrors it into a\n * PostHog notebook as its final step).\n *\n * `posthog-side-findings` is a sweep row, not a rule: the skill reads what\n * PostHog itself already computed for this project (error-tracking\n * recommendations, health issues) and appends one row per open finding via\n * `audit_add_checks`. That's why the seed can't enumerate them — the list is\n * whatever the project's data says today, and it grows as PostHog ships new\n * checks, with no wizard release needed.\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: 'live-data-findings',\n // Area is capped at COL_AREA_WIDTH (18) in the checks viewer and never\n // flexes, so it has to fit. Labels get the flexed column.\n area: 'Live Data',\n label: 'Open findings in PostHog',\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 writeJsonAtomic(target, checks);\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 { headlessOption, regionOption } from '@lib/headless-mode';\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) => {\n const cloudUrl = credentials.host.appHost;\n const continueUrl = sess.signup\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: session.dashboardUrl ?? undefined,\n notebookUrl: session.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 // The experimental headless flag — declared on `audit` (and basic\n // integration) rather than globally. mergeCommandOptions lands it on the\n // `wizard audit` command; dispatchProgram routes it to runWizardHeadless.\n cliOptions: { ...headlessOption, ...regionOption },\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 { 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\n// SETUP_REPORT_FILE is also re-exported for backward compat with existing\n// imports from `@lib/programs/events-audit`. EVENT_INVENTORY_FILE and\n// EVENT_INVENTORY_PART_PATTERN are only used by yara-hooks, which imports\n// them directly from `./constants` — no re-export needed.\nimport { SETUP_REPORT_FILE } from './constants.js';\nexport { SETUP_REPORT_FILE };\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.apiHost}\n`,\n\n buildOutroData: (sess, credentials) => {\n const cloudUrl = credentials.host.appHost;\n const continueUrl = sess.signup\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 { ErrorCodes } from '@lib/errors';\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 errorCode: ErrorCodes.AuthMissingScope,\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 errorCode: ErrorCodes.DetectNoPosthogSdk,\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>{' AI observability '}</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>AI observability</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 { readdirSync, existsSync, statSync } from 'fs';\nimport { join, relative } from 'path';\nimport {\n IGNORED_DIRS,\n MAX_DIR_ENTRIES,\n MAX_WALK_FILES,\n safeReadFile,\n} from '@utils/bounded-fs';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { ErrorCodes } from '@lib/errors';\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 | 'go'\n | 'rust';\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 go: 'Go',\n rust: 'Rust',\n};\n\n/**\n * Variants the wizard can wire up source-map upload for automatically. Go and\n * Rust upload native debug symbols (`posthog-cli symbol-sets upload`) instead\n * of source maps, but the wiring is the same shape.\n *\n * Invariant: every variant listed here must have a published\n * `error-tracking-upload-source-maps-<variant>` skill in context-mill —\n * STEP 2 of the run installs that exact id, so an entry without a shipped\n * skill fails every run for that stack.\n */\nexport const AUTOMATABLE_VARIANTS: readonly SkillVariant[] = [\n 'android',\n 'ios',\n 'react-native',\n 'flutter',\n 'go',\n 'rust',\n 'web',\n 'nextjs',\n 'node',\n 'react',\n 'angular',\n 'nuxt',\n 'vite',\n 'webpack',\n 'rollup',\n];\n\n/**\n * Variants the wizard pre-installs a machine-global `posthog-cli` for — their\n * build shells out to it with no npx / local-dep fallback. Web JS variants stay\n * out. React Native counts as native here — its Xcode build phases and Gradle\n * tasks invoke the global CLI. Flutter counts too despite emitting plain\n * `.js.map` files: a Flutter project has no `package.json`, so there is no npx\n * or local dependency to fall back to when the post-build step invokes the CLI.\n */\nexport const VARIANTS_REQUIRING_POSTHOG_CLI: ReadonlySet<SkillVariant> =\n new Set(['ios', 'android', 'react-native', 'flutter', 'go', 'rust']);\n\n/**\n * Automatable variants whose SDK the wizard's default flow cannot install —\n * remediation for a missing SDK is a manual install (posthog-go /\n * posthog-rs), not `npx @posthog/wizard`. Drives the missing-SDK copy in the\n * picker and the classifier.\n */\nexport const MANUAL_SDK_INSTALL: Partial<Record<SkillVariant, string>> = {\n go: 'add the posthog-go module first',\n rust: 'add the posthog-rs crate first',\n};\n\nexport const MANUAL_SDK_VARIANTS: readonly SkillVariant[] = Object.keys(\n MANUAL_SDK_INSTALL,\n) as SkillVariant[];\n\n/** Dependency string that identifies the Rust SDK in Cargo.toml. */\nexport const RUST_SDK_CRATE = 'posthog-rs';\n\n/** Module path that identifies the Go SDK in go.mod. */\nexport const GO_SDK_MODULE = 'github.com/posthog/posthog-go';\n\nconst POSTHOG_SDKS = new Set([\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n]);\n\nconst GRADLE_FILES = new Set([\n 'build.gradle',\n 'build.gradle.kts',\n 'settings.gradle',\n 'settings.gradle.kts',\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 errorCode: ErrorCodes.DetectNoPosthogSdk,\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 '(for Go and Rust, add posthog-go / posthog-rs by hand first — the ' +\n 'wizard cannot install the SDK for those stacks yet).',\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 match: /^bare react native not supported$/i,\n errorCode: ErrorCodes.DetectUnsupportedPlatform,\n message: 'Bare React Native is not supported',\n body:\n 'Source-map upload for React Native requires Expo, and this project ' +\n 'has no `expo` package. Bare React Native builds cannot inject the ' +\n 'chunk IDs PostHog needs to resolve stack traces.',\n docsUrl:\n 'https://posthog.com/docs/error-tracking/upload-source-maps/react-native',\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 // Explicit stack — no call-stack recursion.\n const stack: Array<{ dir: string; depth: number }> = [\n { dir: installDir, depth: 0 },\n ];\n\n while (stack.length > 0 && signals.scannedFileCount < MAX_WALK_FILES) {\n const { dir, depth } = stack.pop()!;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n continue;\n }\n // A directory contributes at most MAX_DIR_ENTRIES entries.\n if (entries.length > MAX_DIR_ENTRIES) entries.length = MAX_DIR_ENTRIES;\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 const content = safeReadFile(fullPath);\n if (content === null) continue;\n try {\n const pkg = JSON.parse(content) 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 (GRADLE_FILES.has(entry.name)) {\n signals.hasGradle = true;\n }\n } else if (entry.isDirectory()) {\n if (entry.name.endsWith('.xcodeproj')) {\n signals.hasXcodeProject = true;\n } else if (depth < maxDepth) {\n stack.push({ dir: fullPath, depth: depth + 1 });\n }\n }\n }\n }\n\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 // Set by the agentic picker once the user chooses a project to instrument.\n selectedVariant: 'sourceMapsSelectedVariant',\n selectedDisplayName: 'sourceMapsSelectedDisplayName',\n selectedPath: 'sourceMapsSelectedPath',\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 // The legacy filesystem detector does not automate native platforms. The\n // live source-map picker uses detectSourceMapsProjects instead.\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 * Flow: a static intro (no detection yet) → login → an agentic detect+pick\n * screen that scans the repo on Haiku and lets the user choose a project →\n * agent run → outro. Detection runs after auth because the detection agent\n * needs credentials.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { RunPhase } from '@lib/wizard-session';\nimport { SOURCE_MAPS_CONTEXT_KEYS } from './detect.js';\n\nfunction projectSelected(session: WizardSession): boolean {\n return (\n session.frameworkContext[SOURCE_MAPS_CONTEXT_KEYS.selectedVariant] != null\n );\n}\n\nexport const ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'source-maps-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'detect',\n label: 'Detecting projects',\n // The Haiku agent scans the repo, surfaces an instrumentable / not-yet map,\n // and the user picks the project to wire up. Advances once a project is\n // chosen (its variant is written to frameworkContext). The gate lets the\n // agent runner park after auth until the pick lands, so the run prompt sees\n // the chosen variant.\n screenId: 'source-maps-detect',\n isComplete: projectSelected,\n gate: projectSelected,\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 /** Project to instrument, relative to the wizard working directory (\".\" or undefined = root). */\n projectPath?: string;\n projectId: number;\n host: string;\n settingsUrl: string;\n uiHost: string;\n /** Hand-off report the agent writes in STEP 9; the outro points the user at it. */\n reportFile: 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 projectPath,\n projectId,\n host,\n settingsUrl,\n uiHost,\n reportFile,\n } = params;\n const platformLabel = displayName ?? variant;\n const inSubproject = projectPath != null && projectPath !== '.';\n const projectLine = inSubproject\n ? `- Project directory (relative to the wizard's working directory): ${projectPath}`\n : \"- Project directory: the wizard's working directory (even when it sits inside a larger git repo, this directory is the project root)\";\n const envFilePathGuidance = inSubproject\n ? `Tool filePaths are relative to the wizard's working directory, not the selected project directory. Treat the skill's env path as relative to the selected project and prefix it with \\`${projectPath}/\\` when calling the tools: for example, pass \\`${projectPath}/.env\\`, not \\`.env\\` (which would target the wizard's working directory).${\n variant === 'rust'\n ? ` Cargo workspace exception: when the skill places the env file at the workspace root instead, pass the path of the ROOT manifest's directory relative to the wizard's working directory (e.g. \\`rust/.env\\` for a workspace root at \\`rust/\\`, or plain \\`.env\\` when the workspace root IS the working directory) — not the member path.`\n : ''\n }`\n : `Tool filePaths are relative to the wizard's working directory. For an env file at this project root, pass \\`.env\\`; never prefix it with this directory's path inside an ancestor repository.`;\n\n const credentialSteps = `STEP 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 with the key names and that file as filePath.\n It answers { status: \"present\" | \"missing\", foundIn: [paths] } per key —\n names and paths only, never values, so don't read the file directly.\n \"present\" means a real env file sets the key; a key found only in a\n committed template (.env.example and friends) reads as \"missing\",\n because a template documents a key rather than setting it.\n - Env tool path rule: ${envFilePathGuidance}\n - Then call set_env_values, passing the STEP 1 secretRef as a value\n object, not a literal string. Take the three variable NAMES from the\n skill's per-uploader list in \"Write credentials to the env file\" — they\n differ by uploader, and only the shape below is fixed:\n values: {\n \"<key var for the uploader you wired>\": { secretRef: \"<the ref from STEP 1>\" },\n \"<project id var>\": \"${projectId}\",\n \"<host var>\": \"${uiHost}\"\n }\n Write that one set only. Do not also write another uploader's variables\n as a fallback — a credential nothing reads is an unused secret sitting\n in the user's env file.\n The wizard resolves the ref locally before writing, so you never see the\n key value.`;\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${projectLine}\n- Personal API keys settings page: ${settingsUrl}\n\nAll file changes, build/run commands, and config edits target the project directory above${\n inSubproject\n ? ` — this is a monorepo, so scope your work to \\`${projectPath}\\` and do not touch other packages`\n : ''\n }.${\n variant === 'rust' && inSubproject\n ? `\nCargo workspace exception: if the selected project is a member of a Cargo\nworkspace (resolve the root with \\`cargo locate-project --workspace\n--message-format plain\\`), the workspace root's Cargo.toml (for \\`[profile.*]\\`\nedits), the workspace-level \\`target/\\` directory, and a \\`.env\\` next to the\nroot manifest are IN SCOPE — treat them as part of the selected project, and\nfollow the skill's workspace guidance for which paths to use. Every other\npackage stays off-limits.`\n : ''\n }\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 ${\n AgentSignals.ERROR_RESOURCE_MISSING\n } 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\n${credentialSteps}\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 build-and-run flow (and the exact\n button label / route) into the prompt as literal, copy-pasteable\n numbered steps:\n - Steps 1-2: the production build, then launching the app and\n triggering the test affordance. Source them from STEP 6 and the\n skill's \"Test the local setup\" step — when the skill gives the\n platform's test flow as verbatim steps (IDE-driven platforms like\n Xcode do), use its wording and do NOT invent CLI build commands,\n debugger steps, or relaunch steps it doesn't state. Quote CLI\n commands verbatim. When build and run are one action (an IDE Run),\n fold them into step 1 and make step 2 just triggering the affordance.\n - The last step is always the Error Tracking check, exactly as in the\n template.\n Separate each numbered step with \\\\n\\\\n so the TUI renders them as\n distinct lines:\n {\n id: \"test-done\",\n prompt: \"1) <production build step — it uploads source maps and builds the app with the test affordance>\\\\n\\\\n2) <run step>, 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. Write the hand-off to\n \\`${reportFile}\\` at the WIZARD'S WORKING DIRECTORY — pass exactly\n \\`${reportFile}\\` as the file path, never prefixed with the selected\n project directory; this file is the one exception to the project-scope\n rule above. Cover: the files you changed (paths only), the exact build\n and upload commands, every CI secret the user still has to create, and\n how to verify the upload — then give the same summary in chat. Never\n write secret values into the report, only variable names. The success\n screen points the user at this file, so do not skip it. The Symbol sets page for this project — where the user\n 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 { spawnSync } from 'node:child_process';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\n\nimport { debug } from '@utils/debug';\n\n/**\n * A coding agent whose global instructions file the PostHog CLI steering\n * snippet can be installed into. Project-level installs are handled by\n * `posthog-cli api agents-md install` in the target repo; this step only\n * manages the per-user (global) instruction files.\n */\nexport interface CliSteeringTarget {\n id: string;\n name: string;\n /** Global agent instructions file the steering snippet is written to. */\n instructionsPath(): string;\n /** Whether the agent appears to be installed on this machine. */\n isDetected(): boolean;\n}\n\nconst dirExists = (...segments: string[]): boolean => {\n try {\n return fs.existsSync(path.join(os.homedir(), ...segments));\n } catch {\n return false;\n }\n};\n\nexport const CLI_STEERING_TARGETS: readonly CliSteeringTarget[] = [\n {\n id: 'claude-code',\n name: 'Claude Code',\n instructionsPath: () => path.join(os.homedir(), '.claude', 'CLAUDE.md'),\n isDetected: () => dirExists('.claude'),\n },\n {\n id: 'codex',\n name: 'Codex',\n instructionsPath: () => path.join(os.homedir(), '.codex', 'AGENTS.md'),\n isDetected: () => dirExists('.codex'),\n },\n {\n id: 'gemini',\n name: 'Gemini CLI',\n instructionsPath: () => path.join(os.homedir(), '.gemini', 'GEMINI.md'),\n isDetected: () => dirExists('.gemini'),\n },\n];\n\nexport function findTarget(id: string): CliSteeringTarget | undefined {\n return CLI_STEERING_TARGETS.find((target) => target.id === id);\n}\n\nexport function detectTargets(): CliSteeringTarget[] {\n return CLI_STEERING_TARGETS.filter((target) => target.isDetected());\n}\n\nexport interface SteeringInstallResult {\n success: boolean;\n filePath: string;\n error?: string;\n}\n\nexport interface CliInstallResult {\n success: boolean;\n error?: string;\n /**\n * The underlying failure as an Error, for callers that report to error\n * tracking. Carries the real spawn error (with its stack) when npm couldn't\n * launch; a synthesized Error for a non-zero exit. Set whenever success is\n * false.\n */\n errorObject?: Error;\n}\n\nconst spawnOptions = {\n encoding: 'utf-8' as const,\n // npm/posthog-cli are npm.cmd/posthog-cli.cmd on Windows; spawnSync only\n // resolves them through a shell.\n shell: process.platform === 'win32',\n};\n\n/**\n * Install or update the PostHog CLI in the user's environment. `npm install\n * --global @posthog/cli@latest` covers both first-time installs and upgrades\n * for existing npm-installed CLIs.\n */\nexport function installOrUpdatePostHogCli(): CliInstallResult {\n const args = ['install', '--global', '@posthog/cli@latest'];\n debug(`Running npm ${args.join(' ')}`);\n\n const result = spawnSync('npm', args, spawnOptions);\n\n if (result.error) {\n return {\n success: false,\n error: `Failed to run npm: ${result.error.message}. Is Node.js installed?`,\n errorObject: result.error,\n };\n }\n if (result.status !== 0) {\n const detail = (result.stderr || result.stdout || '').trim();\n const message =\n detail ||\n `npm install --global @posthog/cli@latest exited with status ${\n result.status ?? 'unknown'\n }`;\n return {\n success: false,\n error: message,\n errorObject: new Error(message),\n };\n }\n return { success: true };\n}\n\n/**\n * Delegate the actual write to the installed `posthog-cli api agents-md\n * install`. The steering snippet lives in the CLI (its single source of truth),\n * so the command should run only after `installOrUpdatePostHogCli` refreshes\n * the CLI to the latest release.\n */\nexport function installSteeringSnippet(\n filePath: string,\n): SteeringInstallResult {\n const args = ['api', 'agents-md', 'install', '--path', filePath];\n debug(`Running posthog-cli ${args.join(' ')}`);\n\n const result = spawnSync('posthog-cli', args, {\n ...spawnOptions,\n env: { ...process.env, POSTHOG_CLI_EXPERIMENTAL_API: '1' },\n });\n\n if (result.error) {\n return {\n success: false,\n filePath,\n error: `Failed to run posthog-cli: ${result.error.message}. Make sure npm's global bin directory is on your PATH.`,\n };\n }\n if (result.status !== 0) {\n const detail = (result.stderr || result.stdout || '').trim();\n return {\n success: false,\n filePath,\n error:\n detail ||\n `posthog-cli exited with status ${result.status ?? 'unknown'}`,\n };\n }\n return { success: true, filePath };\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 VARIANTS_REQUIRING_POSTHOG_CLI,\n type SkillVariant,\n} from './detect.js';\nimport { getContentBlocks } from './content/index.js';\nimport { getUI } from '@ui';\nimport { installOrUpdatePostHogCli } from '@steps/install-cli-steering';\nimport { analytics } from '@utils/analytics';\n\nconst REPORT_FILE = 'posthog-source-maps-report.md';\nconst DOCS_URL = 'https://posthog.com/docs/error-tracking/upload-source-maps';\n\nlet postHogCliInstallAttempted = false;\n\n/**\n * Pre-install posthog-cli for variants that need a machine-global copy\n * (`VARIANTS_REQUIRING_POSTHOG_CLI`). The agent can't — warlock blocks\n * `npm install -g` — so the wizard does it in-process. Warn, don't fail.\n */\nfunction ensurePostHogCli(variant: SkillVariant): void {\n if (postHogCliInstallAttempted) return;\n postHogCliInstallAttempted = true;\n\n const result = installOrUpdatePostHogCli();\n if (!result.success) {\n analytics.wizardCapture('source maps posthog-cli preinstall failed', {\n variant,\n error: String(result.error).slice(0, 500),\n });\n analytics.captureException(\n result.errorObject ??\n new Error(`posthog-cli pre-install failed: ${result.error}`),\n { source: 'source_maps_cli_preinstall', variant },\n );\n getUI().log.warn(\n `Could not pre-install posthog-cli (${result.error}). Your release build ` +\n `will fail to upload debug symbols until it's installed: npm install -g @posthog/cli@latest`,\n );\n }\n}\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 // Read the picked project LIVE at prompt-build time, not here: the picker\n // screen runs AFTER this run config is resolved (post-auth), and the store\n // forks the session reference, so the `session` passed in never sees the\n // choice. getUI().getFrameworkContext reads the live store session.\n const readSelection = () => {\n const variant = getUI().getFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.selectedVariant,\n ) as SkillVariant | undefined;\n const displayName = getUI().getFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.selectedDisplayName,\n ) as string | undefined;\n const projectPath = getUI().getFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.selectedPath,\n ) as string | undefined;\n const skillId = variant\n ? `error-tracking-upload-source-maps-${variant}`\n : undefined;\n return { variant, displayName, projectPath, skillId };\n };\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 const { variant, displayName, projectPath, skillId } = readSelection();\n if (!skillId || !variant) {\n // No project was selected — abort with a structured signal so the\n // runner renders a friendly outro.\n return SOURCE_MAPS_DETECTION_FAILED_PROMPT;\n }\n\n if (VARIANTS_REQUIRING_POSTHOG_CLI.has(variant))\n ensurePostHogCli(variant);\n\n const uiHost = ctx.host.appHost.replace(/\\/$/, '');\n\n return buildSourceMapsUploadPrompt({\n displayName,\n variant,\n skillId,\n projectPath,\n projectId: ctx.projectId,\n host: ctx.host.apiHost,\n settingsUrl: `${uiHost}/project/${ctx.projectId}/settings/user-api-keys`,\n uiHost,\n reportFile: REPORT_FILE,\n });\n },\n\n postRun: () => {\n // Stash a hint for the outro about what variant we shipped.\n const { variant } = readSelection();\n if (variant) {\n getUI().setFrameworkContext('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 MANUAL_SDK_VARIANTS,\n type SkillVariant,\n type SourceMapsDetectError,\n} from './detect.js';\n","/**\n * Self-driving prerequisite detection + abort vocabulary.\n *\n * The only thing worth verifying before auth is local and cheap: that\n * `session.installDir` is a real, readable directory. We deliberately do\n * NOT require the base posthog-integration report to be present — it is a\n * report many users never commit, and `requires: ['posthog-integration']`\n * is metadata, not a hard runtime gate.\n *\n * Self-driving is now in OPEN beta — available to every team — so STEP 1\n * no longer probes the Signals API as an access gate; it completes\n * instantly so the run opens with a fast first checkmark. The\n * `self-driving is not available for this project` abort below is kept\n * only as a safety net: if the Signals API genuinely can't be reached\n * during the run (a hard error that is unexpected in open beta), the skill\n * emits it and the wizard renders a friendly \"try again\" screen — now with\n * open-beta wording, not the old closed, per-team \"join the beta\" copy. The\n * PostHog-side flags (`product-autonomy`, `signals-scout`) are unchanged by\n * the wizard-side \"self-driving\" rename.\n */\n\nimport {\n existsSync,\n statSync,\n readFileSync,\n readdirSync,\n type Dirent,\n} from 'fs';\nimport { join } from 'path';\nimport { analytics } from '@utils/analytics';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { ErrorCodes } from '@lib/errors';\nimport { detectWarehouseSources } from '@lib/warehouse-sources/detect';\nimport type { DetectedSource } from '@lib/warehouse-sources/types';\n\n/** frameworkContext key holding the deterministic PostHog-presence result. */\nexport const POSTHOG_PRESENT_KEY = 'postHogPresent';\n\n/**\n * frameworkContext key holding the repo-relative path of the project the user\n * picked on the integration-detect screen (\".\" for the repo root). The\n * integrate-run phase scopes its install dir to this so a monorepo integrates\n * into the chosen sub-app, not the root.\n */\nexport const SELF_DRIVING_INTEGRATE_PATH_KEY = 'selfDrivingIntegratePath';\n\n/** Self-driving's own detected-tools key — not the warehouse one, which the integration program reads. */\nexport const SELF_DRIVING_DETECTED_TOOLS_KEY = 'selfDrivingDetectedTools';\n\n/** Read the detected tools out of frameworkContext. */\nexport function getSelfDrivingDetectedTools(\n session: WizardSession,\n): DetectedSource[] {\n return (\n (session.frameworkContext[SELF_DRIVING_DETECTED_TOOLS_KEY] as\n | DetectedSource[]\n | undefined) ?? []\n );\n}\n\n// Matches `posthog` at a dependency boundary (line start, or after \"'/=:.@ or\n// whitespace): catches `com.posthog:posthog-android` and `@posthog/ai`, skips\n// substrings inside other words.\nconst POSTHOG_PACKAGE_RE = /(^|[\"'\\s/=:.@])posthog/im;\n\n// Manifests grepped for a posthog dependency. Distinct from PROJECT_MANIFESTS\n// in @lib/detection/agentic (project-root discovery); keep the two in sync\n// (a test asserts the shared ecosystem names appear in both). Exported for it.\nexport const POSTHOG_MANIFESTS = [\n 'package.json',\n 'requirements.txt',\n 'pyproject.toml',\n 'Pipfile',\n 'setup.py',\n 'Gemfile',\n 'go.mod',\n 'composer.json',\n 'pubspec.yaml',\n // Apple: SPM manifest, CocoaPods (+ lockfile), XcodeGen spec.\n 'Package.swift',\n 'Podfile',\n 'Podfile.lock',\n 'project.yml',\n // Android / JVM (libs.versions.toml holds gradle coordinates).\n 'build.gradle',\n 'build.gradle.kts',\n 'gradle/libs.versions.toml',\n 'pom.xml',\n // Elixir / Rust.\n 'mix.exs',\n 'Cargo.toml',\n];\n\n// Named sub-app dirs always checked (ios/android: RN/Flutter native shells).\n// scanDirs unions these with a bounded depth-2 walk of the install dir.\nconst POSTHOG_DIRS = [\n '.',\n 'app',\n 'frontend',\n 'backend',\n 'ios',\n 'android',\n 'android/app',\n];\n\n// Heavy or vendored trees the shallow walk never descends into — they hold\n// dependencies, not a project's own manifest, and would false-positive on a\n// bundled posthog package.\nconst WALK_SKIP_DIRS = new Set([\n 'node_modules',\n 'Pods',\n 'Carthage',\n 'DerivedData',\n '.build',\n 'build',\n 'dist',\n 'out',\n '.next',\n 'coverage',\n 'vendor',\n '.venv',\n 'site-packages',\n 'target',\n '.git',\n]);\n\n// How deep below the install dir the shallow walk goes. 2 covers the common\n// monorepo shape (apps/<name>, packages/<name>) without a full tree walk.\nconst WALK_MAX_DEPTH = 2;\n\n/**\n * The install dir plus every directory within WALK_MAX_DEPTH levels (skipping\n * heavy/vendored trees and dotdirs), unioned with the explicit POSTHOG_DIRS. A\n * full shallow walk on top of the named dirs, so a monorepo's nested apps\n * (e.g. `apps/mobile`) are seen without hardcoding the path.\n */\nfunction scanDirs(installDir: string): string[] {\n const rels = new Set<string>(POSTHOG_DIRS);\n // Explicit stack — no call-stack recursion.\n const stack: Array<{ rel: string; depth: number }> = [{ rel: '.', depth: 0 }];\n while (stack.length > 0) {\n const { rel, depth } = stack.pop()!;\n rels.add(rel);\n if (depth >= WALK_MAX_DEPTH) continue;\n let entries: Dirent[];\n try {\n entries = readdirSync(join(installDir, rel), { withFileTypes: true });\n } catch {\n continue;\n }\n for (const e of entries) {\n if (!e.isDirectory()) continue;\n if (e.name.startsWith('.') || WALK_SKIP_DIRS.has(e.name)) continue;\n // .xcodeproj/.xcworkspace are inspected via projectFileHasPostHog at the\n // parent dir — descending into the wrapper finds nothing useful.\n if (e.name.endsWith('.xcodeproj') || e.name.endsWith('.xcworkspace')) {\n continue;\n }\n stack.push({\n rel: rel === '.' ? e.name : `${rel}/${e.name}`,\n depth: depth + 1,\n });\n }\n }\n return [...rels];\n}\n\n/**\n * True if a `*.xcodeproj/project.pbxproj` or `*.csproj`/`*.fsproj` in\n * `dirPath` references PostHog.\n */\nfunction projectFileHasPostHog(dirPath: string): boolean {\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch {\n return false;\n }\n for (const entry of entries) {\n const target = entry.endsWith('.xcodeproj')\n ? join(dirPath, entry, 'project.pbxproj')\n : entry.endsWith('.csproj') || entry.endsWith('.fsproj')\n ? join(dirPath, entry)\n : null;\n if (!target || !existsSync(target)) continue;\n try {\n if (POSTHOG_PACKAGE_RE.test(readFileSync(target, 'utf8'))) return true;\n } catch {\n /* unreadable — ignore */\n }\n }\n return false;\n}\n\n/**\n * Deterministic, offline check: does the project already have a PostHog SDK?\n * Scans the common dependency manifests at the install dir for a `posthog`\n * package — the same signal the agentic detector reports as `hasPostHog`, but\n * instant and credential-free. Drives whether self-driving asks to integrate\n * first (\"not found\") or proceeds straight to setup (\"found\").\n */\nexport function detectPostHogPresent(installDir: string): boolean {\n for (const dir of scanDirs(installDir)) {\n const dirPath = join(installDir, dir);\n for (const name of POSTHOG_MANIFESTS) {\n const path = join(dirPath, name);\n if (!existsSync(path)) continue;\n try {\n if (POSTHOG_PACKAGE_RE.test(readFileSync(path, 'utf8'))) return true;\n } catch {\n /* unreadable — ignore */\n }\n }\n // Variably-named project files (.xcodeproj, .csproj/.fsproj).\n if (projectFileHasPostHog(dirPath)) return true;\n }\n return false;\n}\n\n/**\n * Structured detection errors. The intro screen renders each kind into\n * JSX — keeps error data separate from presentation.\n */\nexport type SelfDrivingDetectError = {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n};\n\n/**\n * `[ABORT] <reason>` cases the self-driving skill can emit. The\n * reason strings are part of the skill contract — the context-mill\n * `self-driving-setup` skill emits these exact strings.\n */\n/** Headline shown when the run ends because GitHub was not connected. */\nexport const GITHUB_REQUIRED_MESSAGE = 'GitHub connection required';\n\n/** Body for {@link GITHUB_REQUIRED_MESSAGE}. Shared by the pre-run gate and the abort case. */\nexport const GITHUB_REQUIRED_BODY =\n 'Self-driving needs GitHub access to research issues in your code and ' +\n 'open fixes, so setup cannot finish without it. Nothing was changed. ' +\n 'When you are ready to install the PostHog GitHub App, run the wizard again.';\n\nexport const SELF_DRIVING_ABORT_CASES: AbortCase[] = [\n {\n // Skill emits: [ABORT] self-driving is not available for this project\n match: /^self-driving is not available for this project$/i,\n message: 'PostHog Self-driving is not available for this project',\n body:\n 'Self-driving is in open beta and available to every team, so this ' +\n 'is unexpected — the PostHog Signals API could not be reached for ' +\n 'this project. Nothing was changed. Try again in a moment, and if it ' +\n 'keeps happening reach out to wizard@posthog.com.',\n },\n {\n // Retained as a safety net: the GitHub gate now runs before the agent, but\n // a cached older skill can still emit this mid-run.\n match: /^github connection declined$/i,\n message: GITHUB_REQUIRED_MESSAGE,\n body: GITHUB_REQUIRED_BODY,\n },\n {\n // Skill emits: [ABORT] requires-interactive-mode\n match: /^requires-interactive-mode$/i,\n errorCode: ErrorCodes.CliInteractiveRequired,\n message: 'Interactive terminal required',\n body:\n 'Self-driving setup asks questions along the way (GitHub and ' +\n 'issue trackers), so it needs an interactive terminal. Run ' +\n 'the wizard outside CI / non-interactive mode.',\n },\n {\n // The wizard_ask tool's own error texts (non-interactive host, ask cap\n // reached) instruct the agent to emit this reason — cover it so those\n // paths render a friendly screen instead of the generic abort outro.\n match: /^requirements-incomplete$/i,\n message: 'Setup needs your input',\n body:\n 'The wizard could not collect the answers this setup needs (the ' +\n 'environment was non-interactive, or the question budget ran out). ' +\n 'Nothing was left half-configured. Run the wizard again in an ' +\n 'interactive terminal.',\n },\n];\n\n/**\n * Verify `session.installDir` is a readable directory. Writes a\n * `SelfDrivingDetectError` to frameworkContext on failure — the intro\n * screen renders it and blocks.\n */\nexport function detectSelfDrivingPrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: SelfDrivingDetectError) =>\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 // Deterministic PostHog-presence check — drives the integration-check\n // screen: found → skip straight to self-driving; not found → ask to set up\n // PostHog first.\n setFrameworkContext(POSTHOG_PRESENT_KEY, detectPostHogPresent(installDir));\n\n detectConnectedTools(installDir, setFrameworkContext);\n}\n\n/** Step 5's ask options intersected with `SOURCE_DETECTORS` — reconcile when the skill's catalog grows. */\nexport const SELF_DRIVING_TOOL_KINDS: ReadonlySet<string> = new Set([\n // Issue trackers / code hosts\n 'Github',\n 'GitLab',\n 'Gitea',\n 'Linear',\n 'Jira',\n 'Shortcut',\n // Error tracking\n 'Sentry',\n 'Rollbar',\n 'Bugsnag',\n 'Honeybadger',\n 'Raygun',\n // Support desks\n 'Zendesk',\n 'Freshdesk',\n 'Front',\n 'Gorgias',\n 'Kustomer',\n 'Plain',\n // Security scanners\n 'Snyk',\n // Product feedback\n 'Canny',\n 'Productboard',\n // Search analytics\n 'GoogleSearchConsole',\n]);\n\n/** Scan for inbox-connectable tools so STEP 5 can surface them first. Best-effort — never blocks detection. */\nfunction detectConnectedTools(\n installDir: string,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n try {\n const tools = detectWarehouseSources(installDir).filter((s) =>\n SELF_DRIVING_TOOL_KINDS.has(s.kind),\n );\n\n // Tagged even at zero, so \"found nothing\" is distinguishable from \"never ran\".\n analytics.setTag('connected_tools_detected_count', tools.length);\n if (tools.length === 0) return;\n\n analytics.setTag(\n 'connected_tools_detected',\n tools.map((s) => s.kind).join(','),\n );\n setFrameworkContext(SELF_DRIVING_DETECTED_TOOLS_KEY, tools);\n } catch (error) {\n // -1, not absent, so a failed scan stays distinguishable from one that never ran.\n analytics.setTag('connected_tools_detected_count', -1);\n analytics.captureException(\n error instanceof Error ? error : new Error(String(error)),\n { step: 'detectConnectedTools' },\n );\n }\n}\n","/**\n * Agentic (Haiku) detection for self-driving's integration phase.\n *\n * Mirrors source-maps: the integration-detect screen runs `detectSelfDriving-\n * IntegrationProjects` (the shared integration scan from\n * @lib/detection/project-scope), shows a project map, and the user picks one.\n * This file maps the result back to `Integration`s and classifies each project\n * as instrumentable (a framework the wizard supports that doesn't already have\n * PostHog). The screen writes the choice to the session; `prepSelfDriving-\n * Integration` then gathers the chosen project's framework context before the\n * integration agent runs (the runner scopes the install dir).\n */\n\nimport type {\n AgenticDetectionReport,\n DetectEvent,\n} from '@lib/detection/agentic';\nimport { detectIntegrationProjects } from '@lib/detection/project-scope';\nimport { gatherFrameworkContext } from '@lib/detection/index';\nimport { Integration } from '@lib/constants';\nimport type { WizardSession } from '@lib/wizard-session';\n\nexport type { DetectEvent };\n\nconst INTEGRATION_IDS = new Set<string>(Object.values(Integration));\n\n/** One project, classified for a PostHog SDK integration. */\nexport type IntegrationProject = {\n /** Path relative to the repo root (\".\" for the root). */\n path: string;\n /** Human-readable framework the agent detected (e.g. \"Next.js\"). */\n framework: string;\n /** A supported framework when it matches one, else null. */\n integration: Integration | null;\n /** Whether a PostHog SDK is already installed in this project. */\n hasPostHog: boolean;\n /** integration != null && !hasPostHog — PostHog can be set up here. */\n instrumentable: boolean;\n /** hasPostHog: skip integration and continue straight to Self-driving. */\n continuable: boolean;\n /** Why the project can't be set up (only when !instrumentable). */\n reason?: string;\n};\n\nexport type IntegrationDetectionReport = {\n repoType: 'monorepo' | 'single';\n projects: IntegrationProject[];\n};\n\nfunction classify(\n integration: Integration | null,\n hasPostHog: boolean,\n): { instrumentable: boolean; reason?: string } {\n if (integration == null) {\n return {\n instrumentable: false,\n reason: 'Not a framework the wizard can set up yet',\n };\n }\n if (hasPostHog) {\n return { instrumentable: false, reason: 'Already has the PostHog SDK' };\n }\n return { instrumentable: true };\n}\n\n/** Map a detection report into classified projects (exported for tests). */\nexport function toIntegrationReport(\n report: AgenticDetectionReport,\n): IntegrationDetectionReport {\n return {\n repoType: report.repoType,\n projects: report.projects.map((p) => {\n const integration =\n p.targetId && INTEGRATION_IDS.has(p.targetId)\n ? (p.targetId as Integration)\n : null;\n return {\n path: p.path,\n framework: p.framework,\n integration,\n hasPostHog: p.hasPostHog,\n continuable: p.hasPostHog,\n ...classify(integration, p.hasPostHog),\n };\n }),\n };\n}\n\n/** Run the Haiku detector over the repo and classify projects for integration. */\nexport async function detectSelfDrivingIntegrationProjects(\n session: WizardSession,\n onEvent?: DetectEvent,\n): Promise<IntegrationDetectionReport> {\n const report = await detectIntegrationProjects(session, {\n programId: 'self-driving',\n onEvent,\n });\n return toIntegrationReport(report);\n}\n\n/**\n * Prepare the integration phase after the user picked a project on the\n * integration-detect screen (which set `session.integration`, `frameworkConfig`,\n * and the chosen path). Scopes `installDir` to the chosen project — so a\n * monorepo integrates into the picked sub-app — and gathers that project's\n * framework context, mirroring posthog-integration's `ciPreRun`. Used as the\n * integrate-run step's `onRunPrep`.\n */\nexport async function prepSelfDrivingIntegration(\n session: WizardSession,\n): Promise<void> {\n // `session` is the phase's derived session — its installDir is already the\n // picked project (the integrate-run step's `targetDir`), so just gather that\n // project's framework context.\n const frameworkConfig = session.frameworkConfig;\n if (!frameworkConfig) return;\n\n const context = await gatherFrameworkContext(frameworkConfig, {\n installDir: session.installDir,\n debug: session.debug,\n signup: session.signup,\n ci: session.ci,\n benchmark: session.benchmark,\n yaraReport: session.yaraReport,\n });\n for (const [key, value] of Object.entries(context)) {\n if (!(key in session.frameworkContext)) {\n session.frameworkContext[key] = value;\n }\n }\n}\n","/**\n * Self-driving program step list.\n *\n * detect → intro → integration-check → health-check → auth → integrate-detect →\n * integrate-run → self-driving-handoff → self-driving-github → run → outro. A deterministic check in\n * `detect` decides whether PostHog is already in the project: found → the\n * integration screens are skipped and the integrate-run phase never shows; not\n * found → integration-check reports it and the only action sets up PostHog.\n * After auth, `integrate-detect` runs the Haiku detector and has the user pick\n * which project to set PostHog up in (a monorepo can have several);\n * `integrate-run` then runs the real integration program's agent (its own task\n * list) in that project. `self-driving-handoff` then bridges to Self-driving\n * (\"PostHog is installed — now set up Self-driving\"), then `self-driving-github`\n * gates on the GitHub App connection the run cannot proceed without. No keep-skills step: the setup skill is transient, so postRun removes it.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { resolveProjectDir } from '@lib/detection/agentic';\nimport { RunPhase, type WizardSession } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\nimport { integrationRunStep } from '@lib/programs/posthog-integration/index';\nimport {\n detectSelfDrivingPrerequisites,\n POSTHOG_PRESENT_KEY,\n SELF_DRIVING_INTEGRATE_PATH_KEY,\n} from './detect.js';\nimport { prepSelfDrivingIntegration } from './detect-agentic.js';\n\n/** True once detection found PostHog already present in the project. */\nconst postHogPresent = (session: WizardSession): boolean =>\n session.frameworkContext[POSTHOG_PRESENT_KEY] === true;\n\n/** Absolute dir to integrate into: the picked sub-app (LLM output — the shared resolver clamps escapes), else the repo root. */\nconst integrationDir = (session: WizardSession): string =>\n resolveProjectDir(\n session.installDir,\n session.frameworkContext[SELF_DRIVING_INTEGRATE_PATH_KEY],\n );\n\nexport const SELF_DRIVING_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting prerequisites',\n // Headless: validates the install dir and runs the deterministic\n // PostHog-presence check (writes frameworkContext.postHogPresent).\n onReady: (ctx) =>\n detectSelfDrivingPrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'self-driving-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n // Shown only when PostHog wasn't detected and the decision is still open:\n // \"Set up PostHog first?\". On \"yes\" the integrate-run phase runs the\n // integration. When PostHog is already present (or `--integrate` pre-set\n // it), this is skipped. The gate lets run-wizard settle the decision —\n // resolved immediately when no question is needed.\n id: 'integration-check',\n label: 'Integration',\n screenId: 'self-driving-integration-check',\n show: (session) => !postHogPresent(session) && session.integrate === null,\n isComplete: (session) =>\n postHogPresent(session) || session.integrate !== null,\n gate: (session) => postHogPresent(session) || session.integrate !== null,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n // After auth, before the integration runs: the detector scans the repo and\n // the user picks which project to set PostHog up in — a single project or\n // the repo root is still a one-item confirm. The pick writes the framework +\n // path to the session. Shown only while integrating and undecided; complete\n // once a project is picked (the orchestrator waits on this live).\n id: 'integrate-detect',\n label: 'Detecting',\n screenId: 'self-driving-integration-detect',\n show: (session) =>\n session.integrate === true && session.integration == null,\n // Complete on a picked project OR \"continue with existing\"\n // (integrate=false); without the latter the orchestrator's waitUntil hangs.\n isComplete: (session) =>\n session.integration != null || session.integrate === false,\n },\n {\n // The integration's own run step, imported and composed here: it runs the\n // integration agent (its prompt, tools, task list) in the picked project's\n // dir. Shown only when integrating; prep gathers that project's framework\n // context. Completion is tracked via `completedRuns`, separate from the\n // Self-driving run's `runPhase`.\n ...integrationRunStep,\n id: 'integrate-run',\n onRunPrep: prepSelfDrivingIntegration,\n targetDir: integrationDir,\n show: (session) => session.integrate === true,\n isComplete: (session) => session.completedRuns.includes('integrate-run'),\n },\n {\n // Handoff after the integration run: \"PostHog is installed — now set up\n // Self-driving\". Only in the integrate path; the already-has-PostHog path\n // skips it. Complete once acknowledged (the orchestrator waits on this).\n id: 'self-driving-handoff',\n label: 'Ready',\n screenId: 'self-driving-handoff',\n show: (session) => session.integrate === true,\n isComplete: (session) => session.selfDrivingHandoffConfirmed,\n },\n {\n // Hard gate before the agent starts: Self-driving cannot research findings\n // or open fixes without repo access. Asking here rather than mid-run means\n // a user who steps away isn't read as declining, and a user who won't\n // connect hasn't paid for an agent start. Complete once GitHub is\n // connected, or once the user says they can't — which hides `run` below.\n id: 'self-driving-github',\n label: 'GitHub',\n screenId: 'self-driving-github',\n isComplete: (session) =>\n session.githubConnected === true || session.githubDeclined,\n gate: (session) =>\n session.githubConnected === true || session.githubDeclined,\n },\n {\n id: 'run',\n label: 'Self-driving',\n screenId: 'run',\n show: (session) => !session.githubDeclined,\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","import { AgentSignals } from '@lib/agent/agent-interface';\nimport type { PromptContext } from '@lib/agent/agent-runner';\nimport type { DetectedSource } from '@lib/warehouse-sources/types';\n\n/**\n * Render the deterministic codebase-tool scan for the prompt. STEP 4 and\n * STEP 5 read this instead of the agent doing its own flaky \"light scan\":\n * enable the matching signal sources, and surface detected tools first in the\n * connected-tools ask rather than dumping the full ~500-source catalog. When\n * nothing is detected we still say so explicitly, so the agent falls back to\n * the skill's default ordering instead of inventing a scan.\n */\nfunction renderDetectedTools(sources: DetectedSource[]): string {\n if (sources.length === 0) {\n return `Tools detected in this codebase: none found by the dependency + env scan. Use the skill's default ordering for STEP 5.`;\n }\n\n const lines = sources.map(\n (s) => `- ${s.label} (source_type: ${s.kind}) — ${s.matchedSignal}`,\n );\n return [\n 'Tools detected in this codebase (deterministic dependency + env-key scan — this is evidence, not a guess):',\n ...lines,\n '',\n 'Use this list in STEP 4 (enable the matching signal sources) and STEP 5 ' +\n '(surface these detected tools first in the connected-tools ask, ahead ' +\n 'of the SaaS basics and the \"others\" option), exactly as the skill ' +\n 'describes. Never enable or pre-select a tool the user has not confirmed.',\n ].join('\\n');\n}\n\n/**\n * Build the self-driving run prompt. The installed\n * `self-driving-setup` skill is the source of truth for the HOW of\n * every step (which MCP tools to call, which sources/scouts apply, how\n * to verify); this prompt carries the order, the wizard-specific\n * mechanics (wizard_ask, abort signals), and the project URLs.\n *\n * `detectedSources` is the deterministic codebase scan (from the detect step);\n * it drives STEP 4/STEP 5 tool prioritisation. Empty is fine — the block then\n * tells the agent to use the skill's default ordering.\n *\n * Integration (when the project has no PostHog yet) runs as a separate phase\n * before this — the real integration program, with its own screens and task\n * list — so this prompt only covers the Self-driving steps.\n */\nexport function buildSelfDrivingPrompt(\n ctx: PromptContext,\n detectedSources: DetectedSource[] = [],\n): string {\n const uiHost = ctx.host.appHost.replace(/\\/$/, '');\n const projectBase = `${uiHost}/project/${ctx.projectId}`;\n const integrationsSettingsUrl = `${projectBase}/settings/environment-integrations`;\n const orgAiSettingsUrl = `${uiHost}/settings/organization#organization-ai-consent`;\n const newWarehouseSourceUrl = `${projectBase}/pipeline/new/source`;\n const inboxUrl = `${projectBase}/inbox`;\n const optIn = (value: boolean | null | undefined): string =>\n value === true ? 'ON' : value === false ? 'OFF' : 'unknown';\n const optIns = ctx.teamProductOptIns;\n\n return `You are setting up PostHog Self-driving for this project: you will enable the right signal sources, tune the scout troop, design custom scouts for what this product uniquely needs, put Replay Vision scanners on its key flows, and hand the user a configured inbox.\n\nProject URLs:\n- Integrations settings: ${integrationsSettingsUrl}\n- Organization AI settings: ${orgAiSettingsUrl}\n- New data warehouse source (Linear / Zendesk / GitHub issues / pganalyze): ${newWarehouseSourceUrl}\n- Self-driving inbox: ${inboxUrl}\n\nProject state read at auth time (PostHog project settings — authoritative\nfor whether a product is enabled, regardless of what this repo\ninstruments; products are often instrumented from other repos or the\nsnippet, so repo evidence may rule a product IN but never OUT):\n- Session replay recording: ${optIn(optIns?.sessionReplay)}\n- Exception autocapture (error tracking): ${optIn(optIns?.exceptionAutocapture)}\n- Surveys: ${optIn(optIns?.surveys)}\n\n${renderDetectedTools(detectedSources)}\n\nThe installed skill is the source of truth for the HOW of every step:\nwhich MCP tools to call, which sources and scouts apply to this product,\nand how to verify each change. The STEPS below give the order and the\nwizard-specific mechanics — read the matching skill reference before\ndoing the work, and do not invent steps the skill doesn't describe.\n\nBefore doing any work, create your FULL task list in a single TaskCreate\ncall so the user can follow your progress in the TUI. Use exactly these\ntasks, in this order:\n 1. Check Self-driving access\n 2. Read project and current Self-driving state\n 3. Enable products (replay, error tracking, support)\n 4. Enable signal sources\n 5. Offer issue-tracker integrations\n 6. Configure the scout troop\n 6b. Design custom scouts\n 6c. Set up Replay Vision scanners\n 7. Write report and hand off\nDrive the list with TaskUpdate — mark a task in_progress when you start\nit and completed when done. If a step turns out to be a no-op (e.g. a\nproduct is already enabled), still mark its task completed.\n\nThe PostHog GitHub App is already connected — the wizard verified it\nbefore this run started, so never ask the user to connect or install it.\n\nWizard mechanics:\n- Ask the user things ONLY with the wizard_ask MCP tool, and batch\n related questions (e.g. one multi-select for all issue trackers, not\n one ask per tool). The per-run ask budget is limited.\n- If wizard_ask is unavailable (CI / non-interactive), emit\n ${AgentSignals.ABORT} requires-interactive-mode and halt.\n- When a step requires the user to do something in the browser, give\n them the exact URL inside the wizard_ask prompt text — do not try to\n open a browser yourself.\n- Emit ${AgentSignals.STATUS} lines as you complete each step so the\n user sees progress.\n\nFollow these steps IN ORDER. Do not skip or reorder.\n\nSTEP 1 — Check Self-driving access. (skill: \"Check access\")\n Self-driving is in open beta and available to every team, so there is\n no access gate to probe. Do NOT call any MCP tool here — mark this task\n in_progress and then completed right away and emit the\n ${AgentSignals.STATUS} line, so the user sees an immediate first step.\n Only if the Signals API later turns out to be genuinely unreachable for\n this project (a hard error on every Signals call, unexpected in open\n beta) should you emit\n ${AgentSignals.ABORT} self-driving is not available for this project\n and halt.\n\nSTEP 2 — Read project and current Signals state. (skill: \"Read context\")\n If ./posthog-setup-report.md exists, read it as a strong hint for what\n THIS repo instruments — but it is often absent (users frequently don't\n commit it), so do NOT depend on it. Combine whatever you find with the\n project-state block above and the skill's server-side usage probes —\n repo evidence rules products in, never out. Do a light scan ONLY for\n what neither covers. List the currently enabled signal sources so every\n later write is idempotent.\n\nSTEP 3 — Enable products. (skill: \"Enable products\")\n Turn ON the PostHog products Signals reads from — Session Replay,\n Error Tracking, and Support — so the sources you enable next, and the\n Replay Vision scanners in STEP 6c, have data to read. These are\n server-side enables with conservative defaults (owned by the server,\n not you). The project-state block above covers\n only Session Replay and Error Tracking, so you can skip those if they\n are already ON; it does not show Support, but every enable is idempotent\n so enabling any of them again is safe regardless. For a web app, also\n make sure this repo's posthog-js\n init doesn't disable them; for a pure backend or mobile app the server\n flip is inert, so just record that for the report and move on. The skill\n names the exact tool and the per-platform detail.\n\nSTEP 4 — Enable signal sources. (skill: \"Enable sources\")\n Enable the sources that match what this product actually uses, per\n the skill. Never enable a source for a tool the user hasn't\n confirmed they use.\n\nSTEP 5 — Offer issue-tracker integrations. (skill: \"Connected tools\")\n One batched multi-select wizard_ask for the external tools the skill\n lists. Order it per the skill: the tools from the \"Tools detected in\n this codebase\" list above come first, then the SaaS basics, then an\n \"others\" option for the long tail — never dump the whole catalog.\n The run auto-connects the ones it can (GitHub Issues, and\n Linear via a one-click OAuth link), verifying each with a single\n silent check — never nudge. For GitHub Issues: when the GitHub\n integration has exactly one repository connected, use that repo by\n default and skip repo research entirely — research which repo\n matches this project only when several are connected. It arms the\n rest as dormant responders to\n finish later: for tools it can't auto-connect (Zendesk, pganalyze) it\n never sends the user to paste credentials and never re-prompts. Enable\n a source only for a tool the user picked.\n\nSTEP 6 — Configure the scout troop. (skill: \"Scouts\")\n Materialize the troop, read the project's enforced scout-run budget\n (100 runs a day by default), then enable a selective set — the\n \"general\" scout plus the three to five specialists for the products\n this project uses most — and disable the rest, per the skill. The\n whole troop, including step 6b's custom scouts, stays at or under\n ten enabled scouts.\n\n Then tell the user what the troop is, before STEP 6b asks them to add\n to it. Scouts are PostHog's built-in ones, and the user has not seen\n the list: without it, STEP 6b asks them to approve additions to a\n baseline they cannot picture. Send one short message naming each\n scout you enabled with a plain one-line description of what it\n watches, and say how many you left disabled and that they can turn\n those on later from the inbox. No wizard_ask here, it is not a\n question. Keep each line to one sentence and do not restate the\n skill's internals.\n\nSTEP 6b — Design custom scouts for this product. (skill: \"Custom scouts\")\n You are the only actor that has read this repo — turn that into\n coverage per the skill: a real gap analysis of the project's\n watchable surfaces against what the built-in troop already covers,\n then custom scouts for the uncovered ones. Start the gap analysis\n from the repo's for-agents context when present (AGENTS.md,\n CLAUDE.md, ARCHITECTURE.md, .cursor/rules, agent-facing docs) — it\n is a maintained map of the product's surfaces and vocabulary, so\n read it before scanning source. Keep scout bodies\n high-level: describe the behavior and signal conditions to watch,\n referencing repo evidence by file/function name — never paste raw\n source, secrets, env values, or customer data into a scout body.\n Never edit built-in scout bodies. Propose all candidates in ONE\n batched wizard_ask\n before creating anything; the user declining everything (or finding\n no gap at all) is a valid outcome, not an abort. Mark the task\n completed either way.\n\nSTEP 6c — Set up Replay Vision scanners. (skill: \"Replay Vision scanners\")\n Create the scanner skeletons the skill defines, filling the per-product\n blanks it leaves you from this repo's code. Scanners need Session Replay\n on (STEP 3). Every failure here — no recordings yet, a backend-only\n project, the scanner API missing — is a follow-up, never an abort; mark\n the task completed regardless.\n\nSTEP 7 — Write the report and hand off. (skill: \"Report\")\n Write the report per the skill, including follow-ups for anything\n deferred. Tell the user findings will start appearing in their inbox\n at ${inboxUrl} within about 30 minutes.`;\n}\n","/**\n * Canonical step keys for the Self-driving run's `wizard: step` analytics.\n *\n * The agent writes its own task labels, so the same step reaches analytics under whatever wording\n * that run's model picked — \"Enable products\", \"Enabling products\" and \"Turn on PostHog products\"\n * are all STEP 3. A funnel keyed on that label silently loses runs the moment the wording drifts,\n * which is invisible: the number just drops.\n *\n * These rules map a label back to the step it belongs to, so a funnel can key on `step_key` and stay\n * correct across rewordings. `step_name` still ships alongside it, unchanged, for anything that wants\n * the label the user actually saw.\n */\n\n/**\n * Canonical keys, in the order the prompt's STEPs run. Frozen: these are event property values.\n * `connect_github` is retained for historical runs — the GitHub App is now connected on a wizard\n * screen before the agent starts, so no current run emits it.\n */\nexport const SELF_DRIVING_STEP_KEYS = [\n 'check_access',\n 'read_context',\n 'connect_github',\n 'enable_products',\n 'enable_signal_sources',\n 'connect_issue_trackers',\n 'configure_scouts',\n 'design_custom_scouts',\n 'setup_replay_vision',\n 'write_report',\n] as const;\n\nexport type SelfDrivingStepKey = (typeof SELF_DRIVING_STEP_KEYS)[number];\n\n/**\n * First match wins, so order is the rule. Entity words come before verbs: \"Checking GitHub\n * connection\" is the GitHub step, not the access-check step, and \"Connecting issue trackers\" must\n * not fall through to GitHub just because a later run words it \"Connecting GitHub issues\".\n */\nconst RULES: readonly { key: SelfDrivingStepKey; match: RegExp }[] = [\n { key: 'connect_issue_trackers', match: /issue[\\s-]?track/i },\n { key: 'setup_replay_vision', match: /replay vision|vision scanner/i },\n { key: 'design_custom_scouts', match: /custom scout|designing scout/i },\n {\n key: 'configure_scouts',\n match: /scout troop|tun(e|ing) .*scout|configur\\w* .*scout/i,\n },\n { key: 'enable_signal_sources', match: /signal source/i },\n { key: 'connect_github', match: /github/i },\n { key: 'enable_products', match: /product/i },\n { key: 'write_report', match: /report/i },\n { key: 'check_access', match: /access/i },\n { key: 'read_context', match: /read|context|project state/i },\n];\n\n/**\n * The canonical key for an agent-authored step label, or `undefined` when nothing matches — an\n * unmatched step is left unkeyed rather than bucketed, so a new step shows up as a gap to name\n * instead of quietly inflating whichever key it landed nearest.\n */\nexport function resolveSelfDrivingStepKey(\n stepName: string | undefined,\n): SelfDrivingStepKey | undefined {\n if (!stepName) return undefined;\n return RULES.find((rule) => rule.match.test(stepName))?.key;\n}\n","/**\n * Self-driving pricing, in one place. It's stated at six points across the run (intro, tips,\n * learn deck, outro), and a price quoted six ways is a price the reader stops trusting.\n *\n * Careful with the word \"free\". The tracking this wizard installs bills as ordinary PostHog\n * usage, and scouts are heading for usage-based pricing too — so anything called free here is\n * a promise with an expiry date. State what the PR costs and leave the rest to usage-based\n * billing, which stays true either side of that change.\n */\n\n/** Flat USD charge per report that ships a pull request. */\nexport const PRICE_PER_PR_USD = 15;\n\n/** One line, for a screen that only has room to say what it costs. */\nexport const PRICING_SHORT = `Agents charge a flat $${PRICE_PER_PR_USD} per pull request they ship.`;\n\n/** The same fact at length, plus the bit people are surprised by later. */\nexport const PRICING_LONG =\n `A report that ships a pull request costs a flat $${PRICE_PER_PR_USD}. ` +\n `Everything else follows your usual PostHog usage-based pricing.`;\n\n/**\n * Nothing caps the spend unless you set it, which is worth saying out loud. Checked against\n * billing: `custom_limits_map` starts empty and a product with no custom limit resolves to\n * `usage_limit: None`, i.e. uncapped. A free plan is capped by its own allocation instead,\n * hence the qualifier.\n */\nexport const NO_DEFAULT_LIMIT =\n 'A paid plan has no monthly cap until you set one. Add a PR limit in your inbox sidebar, ' +\n 'and agents pause when they hit it.';\n","import { NO_DEFAULT_LIMIT, PRICING_LONG } from './pricing.js';\n\n/**\n * Sidebar tips for the self-driving run — short footnotes on the\n * vocabulary ladder (signal source → scout → signal → report → measured\n * loop). The learn deck (`./index.tsx`) carries the teaching; these stay\n * one to two lines each so the pane never overflows.\n *\n * Product knowledge lives here in the program, not in the generic\n * `TipsCard`. Wired onto the program's `getTips`.\n */\n\nimport type { Tip } from '@ui/tui/components/TipsCard';\n\nexport const SELF_DRIVING_TIPS: Tip[] = [\n {\n id: 'signal-source',\n title: 'Signal source',\n description:\n 'A stream PostHog watches: errors, replays, support, GitHub or Linear issues.',\n },\n {\n id: 'scout',\n title: 'Scout',\n description:\n 'An agent on a schedule, watching your sources for anomalies and patterns. Your project gets up to 100 scout runs a day by default.',\n },\n {\n id: 'scanner',\n title: 'Scanner',\n description:\n 'Where a scout reads your data, a scanner watches session recordings — an LLM spotting what broke on screen. It spends Replay Vision quota, so it stays scoped to your key flows.',\n },\n {\n id: 'signal-report',\n title: 'Signal → report',\n description:\n 'One finding with evidence and a suggested action. Signals group into prioritized reports in your inbox.',\n },\n {\n id: 'the-loop',\n title: 'The loop',\n description:\n 'After a fix ships, PostHog measures the result. If the pattern persists, a new signal reopens the work.',\n },\n {\n id: 'pricing',\n title: 'What it costs',\n description: `${PRICING_LONG} ${NO_DEFAULT_LIMIT}`,\n },\n {\n id: 'work-anywhere',\n title: 'Work anywhere',\n description:\n 'Your inbox is in the PostHog app, Slack (tag @PostHog), and MCP. You can work from anywhere.',\n },\n];\n\nexport const getTips = (): Tip[] => SELF_DRIVING_TIPS;\n","/**\n * PIPELINE_BLOCK — ASCII diagram of the Self-driving loop: sources feed\n * scouts, scouts raise signals, signals group into reports, reports land\n * in the inbox, shipped fixes get measured, and misses loop back as new\n * signals. Kept under ~38 chars wide so it fits the LearnCard pane at an\n * 80-column terminal.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const PIPELINE_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 300,\n pause: 8000,\n lines: [\n <Text>\n {' '}\n <Text bold color=\"cyan\">\n signal sources\n </Text>\n </Text>,\n <Text dimColor>{' errors · replays · support'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n scouts\n </Text>\n </Text>,\n <Text dimColor>{' watching on a schedule'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n signals\n </Text>\n </Text>,\n <Text dimColor>{' finding + evidence + action'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n reports\n </Text>\n </Text>,\n <Text dimColor>{' grouped and prioritized'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color=\"green\">\n your inbox\n </Text>\n </Text>,\n <Text dimColor>{' investigate · tag · ship a PR'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n measured\n </Text>\n </Text>,\n <Text>\n <Text color=\"cyan\">{' ↺ '}</Text>\n <Text dimColor>didn't fix it? a new signal</Text>\n </Text>,\n ],\n};\n","import { NO_DEFAULT_LIMIT, PRICING_LONG } from './pricing.js';\n/**\n * Self-driving learn-deck — the narrative script played while the agent\n * sets up Self-driving. Teaches the vocabulary ladder (signal source →\n * scout → signal → report → action → measured loop) before the agent's\n * questions use those nouns, and explains why GitHub is required before\n * the connect ask lands.\n *\n * One deck for every self-driving run. On the integrate path it plays\n * during the install run (the pane belongs to whichever run screen shows\n * first), so it doubles as the wait-time read.\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 type { ContentBlock } from '@ui/tui/primitives/content-types';\nimport { StatusPeekTrigger } from '@ui/tui/components/StatusPeekTrigger';\nimport { PIPELINE_BLOCK } from './pipeline-diagram.js';\n\nconst CLEAR: ContentBlock = { type: 'clear', pause: 2000 };\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] => {\n return [\n // Scene 1 — orient\n {\n content: 'Welcome.',\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: \"It's setting up PostHog Self-driving for this project.\",\n pause: 5000,\n },\n\n {\n content: \"We'll occasionally need your input. Stick around.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 2 — controls\n {\n pause: 5000,\n persist: true,\n content: <StatusPeekTrigger store={store} />,\n },\n\n {\n pause: 6000,\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 CLEAR,\n\n // Scene 3 — platform story\n {\n content: 'Your PostHog tools all share one data layer.',\n pause: 4000,\n },\n\n {\n content:\n 'Analytics, replays, errors, flags: they all share the same users, mapped across every tool.',\n pause: 6000,\n },\n\n {\n content: 'Together, they show how people really use your product.',\n pause: 5000,\n },\n\n {\n content:\n \"Piecing that together used to be manual work. That's what Self-driving automates.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 4 — the differentiator, and why GitHub\n {\n content:\n 'A coding agent sees your code, but not how your product is used.',\n pause: 5000,\n },\n\n { content: 'PostHog knows what your users actually do.', pause: 4000 },\n\n { content: 'Self-driving puts an agent in the loop.', pause: 5000 },\n\n {\n content:\n \"That's why setup will ask to connect GitHub: so Self-driving can access your code and your context, together.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 5 — signal sources\n {\n content: 'Each PostHog tool you enable is a signal source.',\n pause: 4000,\n },\n\n {\n content:\n \"Errors, replays, support tickets, GitHub or Linear issues: they're all streams of product usage.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 6 — scouts\n {\n content: 'Scouts are agents that watch those sources on a schedule.',\n pause: 5000,\n },\n\n {\n content:\n 'They look for anomalies and patterns: a spike in errors or a funnel quietly dropping.',\n pause: 6000,\n },\n\n { content: 'Setup tunes your scouts to fit your product.', pause: 4000 },\n\n CLEAR,\n\n // Scene 7 — signals and reports\n {\n content:\n \"When a scout finds something worth your attention, that's a signal.\",\n pause: 5000,\n },\n\n {\n content:\n 'Each signal carries the finding, the evidence, and a suggested action.',\n pause: 5000,\n },\n\n {\n content: 'Related signals group into reports, sorted by priority.',\n pause: 4000,\n },\n\n CLEAR,\n\n { content: \"Here's the whole loop.\", pause: 1000 },\n\n PIPELINE_BLOCK,\n\n CLEAR,\n\n // Scene 8 — payoff: the inbox\n { content: 'Reports land in your Self-driving inbox.', pause: 4000 },\n\n {\n content: 'Investigate with the agent, tag teammates, or kick off a PR.',\n pause: 6000,\n },\n\n {\n // No lead-in: PRICING_LONG already names the PR as what's charged, and the\n // pane only fits ~148 chars per beat.\n content: PRICING_LONG,\n pause: 5000,\n },\n\n {\n content: NO_DEFAULT_LIMIT,\n pause: 5000,\n },\n\n CLEAR,\n\n // Scene 9 — the loop kicker\n {\n content: 'And after the PR ships, PostHog measures the result.',\n pause: 5000,\n },\n\n { content: 'Did the fix actually address the pattern?', pause: 4000 },\n\n {\n content: 'If not, a new signal surfaces, and the loop keeps working.',\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 10 — surfaces + closer\n {\n content: 'Work with Self-driving wherever you already are:',\n pause: 2000,\n },\n\n {\n type: 'lines',\n interval: 800,\n pause: 6000,\n lines: [\n <Text>\n <Text color=\"cyan\">{' ◆ '}</Text>\n <Text bold>Inbox</Text>\n <Text dimColor>{' the PostHog web app'}</Text>\n </Text>,\n <Text>\n <Text color=\"cyan\">{' ◆ '}</Text>\n <Text bold>Slack</Text>\n <Text dimColor>{' tag @PostHog'}</Text>\n </Text>,\n <Text>\n <Text color=\"cyan\">{' ◆ '}</Text>\n <Text bold>MCP</Text>\n <Text dimColor>{' your agents and editors'}</Text>\n </Text>,\n ],\n },\n\n {\n content: 'Product usage data becomes real, shippable change.',\n pause: 5000,\n },\n\n { content: 'Your product drives itself.', pause: 10000 },\n ];\n};\n","import { join } from 'path';\nimport { access, rm } from 'node:fs/promises';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport { OutroKind, type WizardSession } from '@lib/wizard-session';\nimport { createSkillProgram } from '../agent-skill/index.js';\nimport { SELF_DRIVING_PROGRAM } from './steps.js';\nimport {\n SELF_DRIVING_ABORT_CASES,\n getSelfDrivingDetectedTools,\n} from './detect.js';\nimport { buildSelfDrivingPrompt } from './prompt.js';\nimport { resolveSelfDrivingStepKey } from './step-keys.js';\nimport {\n NO_DEFAULT_LIMIT,\n PRICE_PER_PR_USD,\n PRICING_LONG,\n} from './content/pricing.js';\nimport { getTips } from './content/tips.js';\nimport { getContentBlocks } from './content/index.js';\n\nexport const SELF_DRIVING_SKILL_ID = 'self-driving-setup';\nconst REPORT_FILE = 'posthog-self-driving-report.md';\nconst DOCS_URL = 'https://posthog.com/docs';\nconst SUCCESS_MESSAGE =\n 'Self-driving is on. PostHog is scanning your project; first findings ' +\n 'hit your inbox within ~30 minutes.';\nconst WIZARD_MARKER = '.posthog-wizard';\n\n/**\n * Remove the installed setup skill. It is transient orchestration\n * knowledge (unlike integration skills such as the Next.js one, which\n * are worth keeping for the user's coding agents), so the program\n * cleans it up instead of showing the keep-skills prompt. Marker-\n * guarded: only directories the wizard installed are touched.\n */\nasync function removeInstalledSkill(installDir: string): Promise<void> {\n const skillDir = join(installDir, '.claude', 'skills', SELF_DRIVING_SKILL_ID);\n try {\n await access(join(skillDir, WIZARD_MARKER));\n } catch {\n return;\n }\n await rm(skillDir, { recursive: true, force: true }).catch(() => undefined);\n}\n\n// A session closure (not a static object) so `customPrompt` can read the\n// tools detected in the codebase — written to frameworkContext by the detect\n// step — and hand them to the prompt for STEP 4/STEP 5 prioritisation.\nconst buildRun = (session: WizardSession): Promise<ProgramRun> =>\n Promise.resolve({\n skillId: SELF_DRIVING_SKILL_ID,\n integrationLabel: SELF_DRIVING_SKILL_ID,\n customPrompt: (ctx) =>\n buildSelfDrivingPrompt(ctx, getSelfDrivingDetectedTools(session)),\n successMessage: SUCCESS_MESSAGE,\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Setting up PostHog Self-driving...',\n estimatedDurationMinutes: 10,\n abortCases: SELF_DRIVING_ABORT_CASES,\n // The flow legitimately needs several interactions (GitHub connect +\n // verify, issue-tracker picks, the scout-tailoring proposal), so raise\n // the wizard_ask budget a little above the default 10.\n maxQuestions: 13,\n // This flow hands the user long OAuth/authorize URLs (Linear, GitHub\n // fallback, Zendesk) in wizard_ask prompts. Render them as OSC 8\n // hyperlinks + clipboard copy so the overlay's line wrapping can't break\n // the click target. Scoped to this program only.\n richLinks: true,\n // STEP 3 (GitHub App install) and STEP 5 (Linear OAuth) park on wizard_ask\n // while the user does slow browser work; a first-time GitHub App install\n // routinely exceeds the 5-min default, and a timeout is indistinguishable\n // from a decline (both resolve to __cancelled__). Match upload-source-maps.\n askTimeoutMs: 30 * 60 * 1000,\n\n // Emit a `wizard: step` analytics event on each agent task transition so we\n // can build a step-level drop-off funnel (where a run stops — GitHub connect,\n // scout enable, etc.), including silent steps with no wizard_ask. Opt-in, so\n // only self-driving runs emit these; every other program is unchanged.\n trackStepProgress: true,\n\n // Key those events by step as well as by label, so a funnel over them (GitHub connect\n // conversion, scout enable rate) keeps counting when a run words its tasks differently.\n resolveStepKey: resolveSelfDrivingStepKey,\n\n postRun: async (session) => {\n await removeInstalledSkill(session.installDir);\n },\n\n buildOutroData: (_session, credentials) => {\n const uiHost = credentials.host.appHost.replace(/\\/$/, '');\n const inboxUrl = `${uiHost}/project/${credentials.projectId}/inbox`;\n return {\n kind: OutroKind.Success as const,\n message: SUCCESS_MESSAGE,\n primaryLink: { label: 'Your Self-driving inbox', url: inboxUrl },\n nextSteps: {\n heading: 'In your inbox you can:',\n items: [\n 'Investigate reports with the agent',\n 'Tag teammates to loop them in',\n `Kick off a PR when you like the proposed fix ($${PRICE_PER_PR_USD} flat)`,\n 'Cap the spend with a monthly PR limit in the sidebar',\n 'Or work from Slack (tag @PostHog) and MCP',\n ],\n },\n body: `${PRICING_LONG} ${NO_DEFAULT_LIMIT}`,\n reportFile: REPORT_FILE,\n };\n },\n });\n\nexport const selfDrivingConfig: ProgramConfig = {\n ...createSkillProgram({\n skillId: SELF_DRIVING_SKILL_ID,\n command: 'self-driving',\n id: 'self-driving',\n description: 'Set up PostHog Self-driving for this project',\n integrationLabel: SELF_DRIVING_SKILL_ID,\n successMessage: SUCCESS_MESSAGE,\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Setting up PostHog Self-driving...',\n estimatedDurationMinutes: 10,\n requires: ['posthog-integration'],\n abortCases: SELF_DRIVING_ABORT_CASES,\n }),\n steps: SELF_DRIVING_PROGRAM,\n run: buildRun,\n getTips,\n getContentBlocks,\n};\n\nexport { SELF_DRIVING_PROGRAM } from './steps.js';\nexport {\n detectSelfDrivingPrerequisites,\n SELF_DRIVING_ABORT_CASES,\n type SelfDrivingDetectError,\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 // This step *is* the tutorial, so it reports there rather than to\n // `mcp-add`. Literal avoids a runtime cycle with the program registry;\n // the `ProgramId` type still catches a rename.\n reportsAsProgramId: 'mcp-tutorial',\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","import type { AbortCase } from '@lib/agent/agent-runner';\nimport { ErrorCodes } from '@lib/errors';\nimport { createSkillProgram } from '@lib/programs/agent-skill/index';\n\nconst MCP_ANALYTICS_REPORT_FILE = 'posthog-mcp-analytics-report.md';\n\n/**\n * `[ABORT]` reasons the mcp-analytics skill emits when the project can't be\n * instrumented. Kept in sync with the stop conditions in the skill's\n * `description.md` (context-mill `context/skills/mcp-analytics`).\n */\nexport const MCP_ANALYTICS_ABORT_CASES: AbortCase[] = [\n {\n match: /^unsupported language for mcp analytics$/i,\n errorCode: ErrorCodes.DetectUnsupportedPlatform,\n message: 'Unsupported language for MCP analytics',\n body:\n 'MCP analytics supports TypeScript/JavaScript (`@posthog/mcp`) and Python ' +\n '(`posthog.mcp`, shipped inside the `posthog` package). This project ' +\n \"doesn't look like either, so there's nothing to instrument. \" +\n 'See https://posthog.com/docs/mcp-analytics for the supported setups.',\n },\n {\n match: /^no mcp server found$/i,\n message: 'No MCP server found',\n body:\n 'This command instruments an existing MCP server with PostHog analytics, ' +\n 'but no MCP server was found in this project. If you just want PostHog ' +\n 'product analytics, run `npx @posthog/wizard` instead.',\n },\n {\n match: /^could not locate the server entry point$/i,\n message: 'Could not locate the MCP server entry point',\n body:\n \"This project has MCP signals, but the agent couldn't find where the \" +\n \"server is constructed or requests are dispatched, so there's nowhere \" +\n 'safe to add instrumentation. See https://posthog.com/docs/mcp-analytics ' +\n 'for the supported server styles, or point the wizard at the package ' +\n \"that defines the server if it's in a monorepo subdirectory.\",\n },\n];\n\n/**\n * `wizard mcp-analytics` — flat skill command.\n *\n * Instruments the user's own MCP server with the `@posthog/mcp` SDK so it\n * reports `$mcp_*` analytics about itself. This is the opposite of\n * `wizard mcp add` (which installs the PostHog MCP *server* into a coding\n * agent) — keep the two distinct.\n *\n * Flat while instrumenting is the only action. If an uninstrument / `remove`\n * leaf ever lands, restructure into a family with `familyCommandFactory` and\n * publish each leaf as a `cliEntries` entry with `parentCommand:\n * 'mcp-analytics'` from context-mill — a deliberate breaking change, done then,\n * not pre-emptively.\n */\nexport const mcpAnalyticsConfig = createSkillProgram({\n skillId: 'mcp-analytics',\n command: 'mcp-analytics',\n id: 'mcp-analytics',\n description: 'Add PostHog MCP analytics to your MCP server',\n integrationLabel: 'mcp-analytics',\n customPrompt:\n \"Instrument this project's MCP server with PostHog MCP analytics. Run the \" +\n '`mcp-analytics` skill end-to-end: detect the server style, install ' +\n '`@posthog/mcp` and `posthog-node`, wrap the server (or use `PostHogMCP` ' +\n 'for a custom dispatcher), wire the project API key and host, and verify. ' +\n 'Make only additive changes — do not alter tool behavior. The final report ' +\n `is written to ./${MCP_ANALYTICS_REPORT_FILE}.`,\n successMessage: `MCP analytics configured! View the report at ./${MCP_ANALYTICS_REPORT_FILE}`,\n reportFile: MCP_ANALYTICS_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/mcp-analytics',\n spinnerMessage: 'Setting up MCP analytics...',\n estimatedDurationMinutes: 5,\n abortCases: MCP_ANALYTICS_ABORT_CASES,\n});\n","import type { AbortCase } from '@lib/agent/agent-runner';\nimport { Integration } from '@lib/constants';\nimport { detectFramework, gatherFrameworkContext } from '@lib/detection/index';\nimport { scopeInstallDirToProject } from '@lib/detection/project-scope';\nimport { FRAMEWORK_REGISTRY } from '@lib/registry';\nimport { createSkillProgram } from '@lib/programs/agent-skill/index';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/steps';\nimport { detectPostHogIntegration } from '@lib/programs/posthog-integration/detect';\nimport type {\n ProgramConfig,\n ProgramReadyContext,\n ProgramStep,\n} from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { analytics } from '@utils/analytics';\nimport { wizardAbort } from '@utils/wizard-abort';\nimport { ErrorCodes } from '@lib/errors';\n\nconst REPLAY_VISION_REPORT_FILE = 'posthog-replay-vision-report.md';\n\n/**\n * The platforms session replay can actually record on. Replay vision watches\n * recordings, so a platform with no recordings has nothing to set up — the\n * run must stop before any work, not after a pointless agent run.\n *\n * Web frameworks record through posthog-js (server-rendered frameworks\n * included — they serve pages), and the mobile SDKs with replay support are\n * React Native, Android, iOS, and Flutter. Excluded: pure backend targets\n * (`javascript_node`, `python`, `ruby`) and KMP, which has no replay support\n * yet.\n */\nexport const REPLAY_VISION_SUPPORTED: ReadonlySet<Integration> = new Set([\n Integration.nextjs,\n Integration.nuxt,\n Integration.vue,\n Integration.reactRouter,\n Integration.tanstackStart,\n Integration.tanstackRouter,\n Integration.angular,\n Integration.astro,\n Integration.sveltekit,\n Integration.javascript_web,\n Integration.django,\n Integration.flask,\n Integration.fastapi,\n Integration.laravel,\n Integration.rails,\n Integration.reactNative,\n Integration.android,\n Integration.swift,\n Integration.flutter,\n]);\n\nasync function abortUnsupportedPlatform(\n integration: Integration,\n): Promise<void> {\n const name = FRAMEWORK_REGISTRY[integration]?.metadata.name ?? integration;\n await wizardAbort({\n code: ErrorCodes.DetectUnsupportedPlatform,\n message:\n `Session replay isn't available for ${name} projects, and Replay ` +\n 'vision needs session recordings to watch — so there is nothing to ' +\n 'set up here.\\n\\n' +\n 'If this repo also contains a web or mobile app, run the command from ' +\n 'that project directory instead. See what replay supports at:\\n' +\n ' https://posthog.com/docs/session-replay',\n error: new Error(`Replay vision unsupported platform: ${integration}`),\n });\n}\n\n/**\n * `[ABORT]` reasons the replay-vision skill emits when the run can't proceed.\n * Kept in sync with the stop conditions in the skill's `description.md`\n * (context-mill `context/skills/replay-vision`).\n */\nexport const REPLAY_VISION_ABORT_CASES: AbortCase[] = [\n {\n match: /^replay vision not available for this project$/i,\n message: 'Replay vision is not available for this project',\n body:\n 'Every Replay vision scanner endpoint reported that the feature is not ' +\n 'available here yet. Session replay setup done so far is kept. See ' +\n 'https://posthog.com/docs/replay-vision for availability.',\n },\n];\n\n/**\n * Framework detection ahead of the run, exactly like the default integration\n * program. The orchestrator requires it: `session.skillId` must hold the\n * detected framework id before the run arm starts, because the runner\n * resolves the reference integration skill and every task's mini-skill\n * variants (`integration-v2-install`, `integration-v2-init`, …) against it in\n * preflight. Without this step the session would still carry the program's\n * own skill id and preflight would abort.\n */\nconst DETECT_STEP: ProgramStep = {\n id: 'detect',\n label: 'Detecting framework',\n // The platform gate runs on a direct detectFramework call BEFORE the full\n // detect writes to the store: store setters replace the session with a\n // shallow copy, so `ctx.session` read after detectPostHogIntegration would\n // be the stale pre-copy object (see the warning in detect.ts).\n onReady: async (ctx: ProgramReadyContext) => {\n const integration = await detectFramework(ctx.session.installDir);\n if (integration && !REPLAY_VISION_SUPPORTED.has(integration)) {\n await abortUnsupportedPlatform(integration);\n return;\n }\n await detectPostHogIntegration(ctx);\n },\n};\n\nconst base = createSkillProgram({\n // The menu ids this skill `<dir>-<variant>`, and context-mill's\n // `replay-vision/config.yaml` declares a single variant, `setup`. The bare\n // `replay-vision` id does not exist — the orchestrator never installs this\n // (it resolves per-task mini-skills instead), but the linear path does, and\n // aborts `skill-not-found` on a miss.\n skillId: 'replay-vision-setup',\n command: 'replay-vision',\n id: 'replay-vision',\n description: 'Set up PostHog Replay vision scanners for your product',\n integrationLabel: 'replay-vision',\n customPrompt:\n 'Set up PostHog Replay vision. Run the `replay-vision` skill end-to-end: ' +\n 'make sure session replay is recording (server-side enable plus a ' +\n 'posthog-js init check), then create the vision scanners the skill ' +\n \"defines, scoped to this product's key flows read out of the repo. If \" +\n 'PostHog is not integrated yet, install and initialize the SDK first as ' +\n 'the skill instructs — do not abort. The final report is written to ' +\n `./${REPLAY_VISION_REPORT_FILE}.`,\n successMessage: `Replay vision configured! View the report at ./${REPLAY_VISION_REPORT_FILE}`,\n reportFile: REPLAY_VISION_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/replay-vision',\n spinnerMessage: 'Setting up Replay vision...',\n estimatedDurationMinutes: 6,\n abortCases: REPLAY_VISION_ABORT_CASES,\n});\n\n/**\n * `wizard replay-vision` — flat skill command on the orchestrator sequence.\n *\n * Makes session replay record (server toggle + client init check), then\n * creates vision scanners scoped to the product's key flows, read out of the\n * repo. The orchestrator runs the `replay-vision` agent flow (context-mill\n * `context/agents/replay-vision`): the seed enqueues the install/init tasks\n * (copied from integration-v2, sharing its step-skills) when the project has\n * no PostHog yet, so the command works on uninstrumented repos instead of\n * aborting.\n *\n * Departures from a plain `createSkillProgram`:\n * - `DETECT_STEP` in front, so `session.skillId` carries the framework id the\n * orchestrator's preflight resolves reference + mini-skill variants with.\n * - `agentFlow` pinned (the id would default to the same value — explicit so\n * renaming the program can't silently detach the flow).\n * - `ciPreRun` mirrors the default integration program: scope the install dir\n * to the right project (monorepos), then detect the framework — the\n * headless equivalent of the detect step's onReady hook.\n */\nexport const replayVisionConfig: ProgramConfig = {\n ...base,\n agentFlow: 'replay-vision',\n steps: [DETECT_STEP, ...AGENT_SKILL_STEPS],\n\n ciPreRun: async (session: WizardSession): Promise<void> => {\n await scopeInstallDirToProject(session);\n\n const integration = await detectFramework(session.installDir);\n if (!integration) {\n await wizardAbort({\n code: ErrorCodes.DetectNoFramework,\n message: 'Could not auto-detect your framework for this project.',\n });\n return;\n }\n if (!REPLAY_VISION_SUPPORTED.has(integration)) {\n await abortUnsupportedPlatform(integration);\n return;\n }\n session.integration = integration;\n analytics.setTag('integration', integration);\n\n const frameworkConfig = FRAMEWORK_REGISTRY[integration];\n session.frameworkConfig = frameworkConfig;\n session.skillId = integration;\n\n const context = await gatherFrameworkContext(frameworkConfig, {\n installDir: session.installDir,\n debug: session.debug,\n signup: session.signup,\n ci: true,\n benchmark: session.benchmark,\n yaraReport: session.yaraReport,\n });\n for (const [key, value] of Object.entries(context)) {\n if (!(key in session.frameworkContext)) {\n session.frameworkContext[key] = value;\n }\n }\n },\n};\n","import type { ProgramConfig, ProgramStep } from '@lib/programs/program-step';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/index';\nimport { getContentBlocks } from '@lib/programs/agent-skill/content/index';\n\nconst AI_OBSERVABILITY_STEPS: ProgramStep[] = AGENT_SKILL_STEPS.map((step) =>\n step.id === 'intro' ? { ...step, screenId: 'ai-observability-intro' } : step,\n);\n\nconst AI_OBSERVABILITY_REPORT_FILE = 'posthog-ai-observability-report.md';\n\n/**\n * `wizard ai-observability` — wrap the project's LLM client calls so they emit\n * `$ai_generation` events into LLM Analytics.\n *\n * No `run.skillId`: the context-mill `ai-observability` group ships one variant\n * per (LLM provider × language) and the wizard does no provider detection —\n * the agent loads the menu, matches the manifest's vendor SDK, and installs\n * the right variant itself (see `customPrompt`). Stays flat while a single\n * \"add AIO to a project\" flow is the only action.\n */\nexport const aiObservabilityConfig: ProgramConfig = {\n command: 'ai-observability',\n description: 'Add PostHog AI Observability to your LLM calls',\n id: 'ai-observability',\n steps: AI_OBSERVABILITY_STEPS,\n reportFile: AI_OBSERVABILITY_REPORT_FILE,\n getContentBlocks,\n run: {\n integrationLabel: 'ai-observability',\n // No `skillId`: linear.ts skips its pre-install step (see the gate on\n // `linear.ts:47`), so the agent must load the menu and install the right\n // variant itself. The prompt below tells it how.\n customPrompt:\n () => `Instrument this project's LLM calls with PostHog AI Observability.\n\nThis flow has no pre-installed skill — you install the right one yourself:\n\n1. Call \\`load_skill_menu\\` with \\`category: \"ai-observability\"\\`. The menu is\n the source of truth: one variant per (LLM provider × language), plus a\n \\`manual-capture\\` variant for projects with no vendor SDK.\n\n2. Scan the project manifest (\\`package.json\\`, \\`pyproject.toml\\`,\n \\`requirements.txt\\`) for a vendor LLM SDK and pick the variant that matches\n it — the language follows the manifest (\\`package.json\\` → Node, Python\n tooling → Python). Multiple SDKs (e.g. LangChain wrapping OpenAI) → prefer\n the higher abstraction. No vendor SDK → the \\`manual-capture\\` variant.\n Genuinely ambiguous → \\`wizard_ask\\` with a multi-choice picker.\n\n3. Call \\`install_skill\\` with the picked variant id. Then follow that skill's\n \\`SKILL.md\\` and references end-to-end. The skill itself will install\n packages, wire OTel, set env vars, and describe verification.\n\nMake only additive changes — do not touch existing PostHog init, identify\ncalls, event capture, or dashboards. Those belong to other skills. The\nfinal report is written to ./${AI_OBSERVABILITY_REPORT_FILE}.`,\n successMessage: `AI Observability configured! View the report at ./${AI_OBSERVABILITY_REPORT_FILE}`,\n reportFile: AI_OBSERVABILITY_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/ai-observability',\n spinnerMessage: 'Setting up AI Observability...',\n estimatedDurationMinutes: 5,\n },\n};\n","import type { ProgramConfig, ProgramStep } from '@lib/programs/program-step';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/index';\nimport { getContentBlocks } from '@lib/programs/agent-skill/content/index';\n\nconst METRICS_STEPS: ProgramStep[] = AGENT_SKILL_STEPS.map((step) =>\n step.id === 'intro' ? { ...step, screenId: 'metrics-intro' } : step,\n);\n\nconst METRICS_REPORT_FILE = 'posthog-metrics-report.md';\n\n/**\n * `wizard metrics` — instrument the project with PostHog application metrics\n * (`posthog.metrics` counters, gauges, and histograms).\n *\n * No `run.skillId`: the context-mill `metrics` group ships one variant per\n * platform (python, nodejs, javascript, kubernetes, other/OTLP) and the agent\n * pulls the matching one itself — the flow's tasks and the linear\n * `customPrompt` both pick from the menu and install it. Stays flat while a\n * single \"add metrics to a project\" flow is the only action.\n */\nexport const metricsConfig: ProgramConfig = {\n command: 'metrics',\n description: 'Add PostHog application metrics to your project',\n id: 'metrics',\n // Orchestrator flow (context-mill `context/agents/metrics`): the seed queues\n // verify-sdk → instrument-metrics → report; the tasks install the matching\n // platform variant themselves. Explicit so renaming the program can't\n // silently detach the flow.\n agentFlow: 'metrics',\n steps: METRICS_STEPS,\n reportFile: METRICS_REPORT_FILE,\n getContentBlocks,\n run: {\n integrationLabel: 'metrics',\n // No `skillId`: the agent must load the menu and install the right\n // variant itself. The prompt below tells it how.\n customPrompt:\n () => `Instrument this project with PostHog application metrics.\n\nThis flow has no pre-installed skill — you install the right one yourself:\n\n1. Call \\`load_skill_menu\\` with \\`category: \"metrics\"\\`. The menu is the\n source of truth: one variant per platform.\n\n2. Pick the variant that matches the project:\n - Python tooling (\\`pyproject.toml\\`, \\`requirements.txt\\`, \\`Pipfile\\`) →\n \\`metrics-python\\` (needs \\`posthog\\` >= 7.23.0)\n - \\`package.json\\` with server-side Node code → \\`metrics-nodejs\\`\n (needs \\`posthog-node\\` >= 5.43.0)\n - \\`package.json\\` that is browser-only → \\`metrics-javascript\\`\n (needs \\`posthog-js\\` >= 1.399.0)\n - Kubernetes manifests / Helm charts and the user wants cluster-level\n scraping → \\`metrics-kubernetes\\`\n - Any other language → \\`metrics-other\\` (plain OTLP exporter)\n A full-stack app (e.g. Next.js) usually wants the server variant — metrics\n measure service work, not user actions. Genuinely ambiguous →\n \\`wizard_ask\\` with a multi-choice picker.\n\n3. Call \\`install_skill\\` with the picked variant id. Then follow that skill's\n \\`SKILL.md\\` and references end-to-end — it covers where to place metrics\n (middleware, background jobs, external calls, business commit sites) and\n the low-cardinality attribute rules.\n\nMake only additive changes — reuse an existing PostHog client by adding the\n\\`metrics\\` config to it rather than constructing a second client, and do not\ntouch existing identify calls, event capture, or dashboards. The final report\nis written to ./${METRICS_REPORT_FILE}.`,\n successMessage: `Application metrics configured! View the report at ./${METRICS_REPORT_FILE}`,\n reportFile: METRICS_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/metrics',\n spinnerMessage: 'Setting up application metrics...',\n estimatedDurationMinutes: 5,\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 { warehouseSourceConfig } from './warehouse-source/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 { selfDrivingConfig } from './self-driving/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 { mcpAnalyticsConfig } from './mcp-analytics/index.js';\nimport { replayVisionConfig } from './replay-vision/index.js';\nimport { aiObservabilityConfig } from './ai-observability/index.js';\nimport { metricsConfig } from './metrics/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 warehouseSourceConfig,\n errorTrackingUploadSourceMapsConfig,\n auditConfig,\n eventsAuditConfig,\n posthogDoctorConfig,\n webAnalyticsDoctorConfig,\n migrationConfig,\n selfDrivingConfig,\n agentSkillConfig,\n mcpAddConfig,\n mcpRemoveConfig,\n mcpTutorialConfig,\n mcpAnalyticsConfig,\n replayVisionConfig,\n aiObservabilityConfig,\n metricsConfig,\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 WarehouseSource: warehouseSourceConfig.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 SelfDriving: selfDrivingConfig.id,\n AgentSkill: agentSkillConfig.id,\n McpAdd: mcpAddConfig.id,\n McpRemove: mcpRemoveConfig.id,\n McpTutorial: mcpTutorialConfig.id,\n McpAnalytics: mcpAnalyticsConfig.id,\n ReplayVision: replayVisionConfig.id,\n AiObservability: aiObservabilityConfig.id,\n Metrics: metricsConfig.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","/**\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 the mcp commands\n * degrade to LoggingUI for — any other error from the TUI path is a real bug\n * and must surface rather than be silently swallowed.\n */\nexport function isTUIUnavailable(error: unknown): boolean {\n return (\n error instanceof Error && /raw mode is not supported/i.test(error.message)\n );\n}\n","import type { Arguments } from 'yargs';\nimport { setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { headlessOption, isHeadless } from '@lib/headless-mode';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\nimport { isTUIUnavailable } from './tui-availability';\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 // Reuses the run pipeline's headless flag rather than minting a public one:\n // this stays reversible, and today the only caller is our own CI.\n ...headlessOption,\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 const args = { local: localMcp, features, apiKey };\n\n // Ink renders into a pipe happily and only throws on raw-mode input, so a\n // non-TTY run reaches the confirm prompt and stalls there rather than\n // hitting the isTUIUnavailable fallback below. The headless flag is the\n // only reliable way to install from a script.\n if (isHeadless(argv)) {\n await runHeadlessAdd(args);\n return;\n }\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 baseUrl: argv.baseUrl as string | undefined,\n });\n } catch (error) {\n if (!isTUIUnavailable(error)) throw error;\n await runHeadlessAdd(args);\n }\n })();\n}\n\nasync function runHeadlessAdd(args: {\n local?: boolean;\n features?: string[];\n apiKey?: string;\n}): Promise<void> {\n setUI(new LoggingUI());\n const { addMCPServerToClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n // Never forwards `ci`: headless implies session.ci elsewhere, and the step\n // reads that as \"skip MCP entirely\" — the opposite of what we're here to do.\n const { installed, failed } = await addMCPServerToClientsStep(args);\n // A scripted caller has no screen to read, so this has to be an exit code.\n // Any failure counts, not just a total wipeout: the step installs to every\n // detected client, so one succeeding would otherwise mask the rest.\n if (failed.length > 0 || installed.length === 0) process.exitCode = 1;\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 { headlessOption, isHeadless } from '@lib/headless-mode';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\nimport { isTUIUnavailable } from './tui-availability';\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 // Mirrors `mcp add` — see the note there on reusing the run pipeline's flag.\n ...headlessOption,\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 // See the note in add.ts: a non-TTY run stalls on the confirm prompt\n // instead of falling back, so scripts need an explicit flag.\n if (isHeadless(argv)) {\n await runHeadlessRemove(localMcp);\n return;\n }\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({\n debug,\n localMcp,\n baseUrl: argv.baseUrl as string | undefined,\n });\n } catch (error) {\n // Same guard as `mcp add`: only a missing TTY falls back to LoggingUI,\n // so a genuine TUI bug surfaces instead of looking like a plain shell.\n if (!isTUIUnavailable(error)) throw error;\n await runHeadlessRemove(localMcp);\n }\n })();\n}\n\n/** No exit code on an empty result: nothing to remove is the requested end state. */\nasync function runHeadlessRemove(local?: boolean): Promise<void> {\n setUI(new LoggingUI());\n const { removeMCPServerFromClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n await removeMCPServerFromClientsStep({ local });\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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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({\n debug,\n localMcp,\n baseUrl: argv.baseUrl as string | undefined,\n });\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 emitWizardError({\n code: ErrorCodes.CliInteractiveRequired,\n message: 'The MCP tutorial requires an interactive terminal.',\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 { runAgent } from '@lib/agent/agent-runner';\nimport { authenticate } from '@lib/agent/runner/shared/authenticate';\nimport { maybeStampAiSdkDetected } from '@lib/programs/posthog-integration/detect';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { Harness, Sequence } from '@lib/constants';\nimport type { startTUI as StartTUIFn } from '@ui/tui/start-tui';\nimport type { WizardStore } from '@ui/tui/store';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { TaskStreamPush as TaskStreamPushClass } from '@lib/task-stream/task-stream-push';\nimport { resolveNoTelemetry } from './resolve-no-telemetry';\nimport { checkLocalServices, getLocalDev } from '@lib/local-dev';\nimport { runCleanups } from '@utils/wizard-abort';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\nimport { join } from 'node:path';\n\nconst WIZARD_VERSION = VERSION;\n\ntype Step = ProgramConfig['steps'][number];\n\n/** The session a run step's agent runs in: scoped to the step's target dir\n * (e.g. a monorepo sub-app) with its own framework context, after any prep.\n * A step without `targetDir` runs in the live session, unchanged.\n * The frameworkContext copy is shallow and unfiltered — name keys per owning program. */\nasync function prepareRunSession(\n step: Step,\n live: WizardSession,\n): Promise<WizardSession> {\n const session = step.targetDir\n ? {\n ...live,\n installDir: step.targetDir(live),\n frameworkContext: { ...live.frameworkContext },\n }\n : live;\n if (step.onRunPrep) await step.onRunPrep(session);\n return session;\n}\n\n/** Advance one step of a composed run to completion: the auth screen\n * authenticates (every later run reuses it); a step carrying its own `run`\n * thunk runs that agent in its dir and is recorded in `completedRuns`; the\n * host program's own run screen runs `config.run`; any other screen waits for\n * the user to satisfy `isComplete`. */\nasync function advanceStep(\n step: Step,\n store: WizardStore,\n config: ProgramConfig,\n): Promise<void> {\n if (step.screenId === 'auth') {\n await authenticate(store.session, config.id);\n maybeStampAiSdkDetected(store.session);\n } else if (step.run) {\n await step.run(await prepareRunSession(step, store.session));\n store.completeRunStep(step.id);\n } else if (step.screenId === 'run') {\n await runAgent(config, await prepareRunSession(step, store.session));\n } else if (step.isComplete) {\n await store.waitUntil(step.isComplete);\n }\n}\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 // Before the TUI mounts: once Ink owns the alt screen, anything written\n // to it is wiped on unmount (see the catch block below), so an abort here\n // would leave the user on a loading screen with no message.\n const local = getLocalDev();\n const localServicesError = await checkLocalServices({\n ...local,\n // An explicit --base-url wins over --local-posthog (see buildSession),\n // so don't probe :8010 when one was given.\n localPosthog: local.localPosthog && !options.baseUrl,\n });\n if (localServicesError) {\n const { wizardAbort } = await import('@utils/wizard-abort');\n await wizardAbort({ message: localServicesError });\n return;\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 localDev: options.localDev as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n localPosthog: options.localPosthog 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 baseUrl: options.baseUrl as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n harness: options.harness as Harness | undefined,\n sequence: options.sequence as Sequence | undefined,\n model: options.model as string | undefined,\n integrate: options.integrate as boolean | undefined,\n captureAio: options.captureAio as boolean | undefined,\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 eventPlanPath: config.eventPlanFile\n ? join(session.installDir, config.eventPlanFile)\n : undefined,\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 // Settle the pre-run screens. `integration-check` is a no-op gate for\n // programs without it.\n await activeTui.store.getGate('intro');\n await activeTui.store.getGate('integration-check');\n await activeTui.store.getGate('health-check');\n\n const skipAgent = config.run == null;\n const shown = (s: ProgramConfig['steps'][number]) =>\n !s.show || s.show(activeTui.store.session);\n\n if (config.steps.some((s) => s.run)) {\n // A composed program: its step list splices in run steps that carry\n // their own agent (self-driving runs the integration before its own\n // run). Walk the list once, advancing each step to completion.\n for (const step of config.steps) {\n if (step.screenId === 'outro') break; // run-completion wait owns it\n if (shown(step)) await advanceStep(step, activeTui.store, config);\n }\n } else 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 baseUrl: session.baseUrl,\n programId: config.id,\n });\n activeTui.store.setCredentials({\n accessToken,\n projectApiKey,\n host,\n projectId,\n });\n } else {\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 emitWizardError({\n code: ErrorCodes.InternalUnhandled,\n message: err instanceof Error ? err.message : String(err),\n });\n process.exit(1);\n }\n })();\n}\n","import { POSTHOG_DOCS_URL, type Harness, type Sequence } from '@lib/constants';\nimport {\n checkLocalServices,\n getLocalDev,\n POSTHOG_LOCAL_URL,\n} from '@lib/local-dev';\nimport type { CloudRegion } from '@utils/types';\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';\nimport type { WizardStore } from '@ui/tui/store';\nimport type { TaskStreamPush } from '@lib/task-stream/task-stream-push';\nimport { join } from 'node:path';\nimport { ErrorCodes, detectErrorCode, emitWizardError } from '@lib/errors';\nimport type { OutroData, RunPhase as RunPhaseT } from '@lib/wizard-session';\n\n/**\n * The two non-interactive run modes. Both drive the same pipeline today; the\n * mode is threaded explicitly (rather than sniffed from a flag) so the dispatch\n * picks an entry point — runWizardCI vs runWizardHeadless — and this core stays\n * mode-agnostic except at the few documented forks. The string values double as\n * the analytics `build` tag, so they segment runs in analytics and on\n * LLM-gateway traces (which read analytics.build).\n */\nexport type NonInteractiveMode = 'ci' | 'headless';\n\n/** User-facing label for a non-interactive mode. */\nfunction modeLabel(mode: NonInteractiveMode): string {\n return mode === 'headless' ? 'Headless' : 'CI';\n}\n\n/**\n * The single non-interactive validation layer: requires api-key and\n * install-dir. Every non-interactive entry point routes through\n * `runNonInteractive`, so this is the one place these checks live. UI must be\n * initialized before calling.\n */\nexport function validateNonInteractiveOptions(\n options: Record<string, unknown>,\n mode: NonInteractiveMode,\n): void {\n const label = modeLabel(mode);\n const keyHint =\n mode === 'headless'\n ? 'personal API key phx_xxx or pha_ OAuth access token'\n : 'personal API key phx_xxx';\n if (!options.apiKey) {\n getUI().intro('PostHog Wizard');\n getUI().log.error(`${label} mode requires --api-key (${keyHint})`);\n emitWizardError({\n code: ErrorCodes.ArgsMissingApiKey,\n message: `${label} mode requires --api-key (${keyHint})`,\n });\n process.exit(1);\n }\n if (!options.installDir) {\n getUI().intro('PostHog Wizard');\n getUI().log.error(\n `${label} mode requires --install-dir (directory to install in)`,\n );\n emitWizardError({\n code: ErrorCodes.ArgsMissingInstallDir,\n message: `${label} mode requires --install-dir`,\n });\n process.exit(1);\n }\n}\n\n/**\n * Non-interactive pipeline shared by CI (`runWizardCI`) and headless\n * (`runWizardHeadless`) runs.\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 *\n * `mode` is the only difference between the two callers today (it sets the\n * analytics build tag and the user-facing label). Keeping it a parameter is\n * what lets CI and headless share this body now and diverge later — branch on\n * `mode` here, or stop sharing this function entirely.\n */\nexport function runNonInteractive(\n config: ProgramConfig,\n options: Record<string, unknown>,\n mode: NonInteractiveMode,\n): void {\n setUI(new LoggingUI());\n validateNonInteractiveOptions(options, mode);\n // Upgrade the build tag so runs segment cleanly in analytics (and on\n // LLM-gateway traces, which read analytics.build). A published headless run\n // (cloud / CI/CD) tags 'headless'; a dev/test `--ci` run upgrades 'dev' to\n // 'ci'. The mode string is the tag value.\n analytics.setTag('build', mode);\n\n void (async () => {\n const path = await import('path');\n const { buildSession, RunPhase, OutroKind } = await import(\n '@lib/wizard-session'\n );\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 localDev: options.localDev as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n localPosthog: options.localPosthog as boolean | undefined,\n apiKey,\n email: options.email as string | undefined,\n projectId: options.projectId as string | undefined,\n baseUrl: options.baseUrl as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n harness: options.harness as Harness | undefined,\n sequence: options.sequence as Sequence | undefined,\n model: options.model as string | undefined,\n captureAio: options.captureAio as boolean | undefined,\n ...env,\n // After the spread: yargs already resolves flag-over-env for --region,\n // so the parsed value must win over the raw env bag.\n region: (options.region ?? env.region) as CloudRegion | undefined,\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 ${modeLabel(mode)} mode`);\n\n // Before auth: a dead local PostHog otherwise surfaces as \"Failed to fetch\n // user data\". Aborts even non-interactively — a CI run pointed at a local\n // server that isn't there is testing nothing.\n const localServicesError = await checkLocalServices({\n ...getLocalDev(),\n localMcp: session.localMcp,\n localPosthog: session.baseUrl === POSTHOG_LOCAL_URL,\n });\n if (localServicesError) {\n await wizardAbort({\n code: ErrorCodes.EnvLocalServicesDown,\n message: localServicesError,\n });\n return;\n }\n\n // Headless streams run state to the PostHog backend so the web app can show\n // live progress. Reuses the interactive TaskStreamPush + WizardStore (no Ink\n // render): HeadlessUI keeps LoggingUI's output and feeds task updates into\n // the store; this runner drives the phase transitions. CI does not stream.\n let store: WizardStore | null = null;\n let taskStream: TaskStreamPush | null = null;\n if (mode === 'headless') {\n const { WizardStore } = await import('@ui/tui/store');\n const { HeadlessUI } = await import('@ui/headless-ui');\n const { TaskStreamPush, PostHogDestination } = await import(\n '@lib/task-stream/index'\n );\n\n store = new WizardStore(config.id);\n store.session = session;\n setUI(new HeadlessUI(store));\n taskStream = new TaskStreamPush({\n store,\n programId: config.id,\n destinations: [\n new PostHogDestination({\n getCredentials: () => session.credentials,\n onError: (e) => logToFile('[headless task-stream]', e.message),\n }),\n ],\n eventPlanPath: config.eventPlanFile\n ? join(session.installDir, config.eventPlanFile)\n : undefined,\n enabled: !session.noTelemetry,\n });\n taskStream.attach();\n store.setRunPhase(RunPhase.Running);\n }\n\n // wizardAbort exits via process.exit, so flush the terminal phase before any\n // exit. No-op for CI.\n const settleStream = async (\n phase: RunPhaseT,\n outroData?: OutroData,\n ): Promise<void> => {\n if (!store || !taskStream) return;\n if (outroData) store.setOutroData(outroData);\n store.setRunPhase(phase);\n await taskStream.shutdown(2000);\n };\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 // Non-interactive session is a plain object (no nanostore\n // copy-on-write), so direct assignment is safe here.\n setSkillId: (skillId: string | null) => {\n session.skillId = skillId;\n },\n setUnsupportedVersion: (info: {\n current: string;\n minimum: string;\n docsUrl: string;\n }) => {\n session.unsupportedVersion = info;\n },\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 (session.unsupportedVersion) {\n const { current, minimum, docsUrl } = session.unsupportedVersion;\n const message = `Detected framework version ${current} is not supported. Minimum supported version is ${minimum}.`;\n await settleStream(RunPhase.Error, {\n kind: OutroKind.Error,\n message,\n errorCode: ErrorCodes.DetectUnsupportedVersion,\n });\n await wizardAbort({\n code: ErrorCodes.DetectUnsupportedVersion,\n message: `${message}\\n\\nSee ${docsUrl}`,\n error: new WizardError(\n `${config.id} unsupported framework version`,\n {\n integration: config.id,\n current,\n minimum,\n },\n ErrorCodes.DetectUnsupportedVersion,\n ),\n });\n }\n if (detectError) {\n const code = detectErrorCode(detectError.kind);\n const detectKind = detectError.kind;\n // `kind` stays in the detail: several kinds share one code, so it is\n // the only thing telling a host which precondition actually failed.\n const detail = { ...detectError };\n await settleStream(RunPhase.Error, {\n kind: OutroKind.Error,\n message: `Prerequisites not met: ${detectKind}`,\n errorCode: code,\n errorDetail: detail,\n });\n await wizardAbort({\n code,\n detail,\n message: `Prerequisites not met: ${detectKind}\\n\\nSee ${\n runDef?.docsUrl ?? POSTHOG_DOCS_URL\n }`,\n error: new WizardError(\n `${config.id} prerequisites failed`,\n {\n integration: config.id,\n detect_error_kind: detectKind,\n },\n code,\n ),\n });\n }\n }\n\n const { runAgent } = await import('@lib/agent/agent-runner');\n await runAgent(config, session);\n await settleStream(RunPhase.Completed);\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(`[${mode}] ERROR: ${errorMessage}`);\n if (errorStack) logToFile(`[${mode}] 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 settleStream(RunPhase.Error, {\n kind: OutroKind.Error,\n message: errorMessage,\n errorCode: ErrorCodes.InternalUnhandled,\n });\n await wizardAbort({\n code: ErrorCodes.InternalUnhandled,\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((error: unknown) => {\n emitWizardError({\n code: ErrorCodes.InternalUnhandled,\n message: error instanceof Error ? error.message : String(error),\n });\n process.exit(1);\n });\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { runNonInteractive } from './run-non-interactive';\n\n/**\n * CI-mode entry point (`--ci`, dev/test builds). A thin shell over the shared\n * non-interactive pipeline — see `runNonInteractive`. Kept as its own function\n * so CI and headless (`runWizardHeadless`) can diverge without re-threading the\n * many callers that route here.\n */\nexport function runWizardCI(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n runNonInteractive(config, options, 'ci');\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { runNonInteractive } from './run-non-interactive';\n\n/**\n * Headless entry point (the experimental published-build, non-interactive run\n * path; see @lib/headless-mode). A thin shell over the shared non-interactive\n * pipeline — see `runNonInteractive`. Today it behaves exactly like\n * `runWizardCI`; it exists as a separate function so headless can diverge later\n * (its own auth handling, telemetry, prompts, …) without touching CI or its\n * callers. Diverge by branching on the mode inside `runNonInteractive`, or by\n * giving this function its own body.\n */\nexport function runWizardHeadless(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n runNonInteractive(config, options, 'headless');\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 unique to skill commands live here. Global flags are declared\n * once in `wizard.ts` — both in `GLOBAL_OPTIONS` and, for the dev-only ones,\n * the `Wizard` constructor — and apply to every command automatically.\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, runWizardHeadless } from '@lib/runners';\nimport { isHeadless } from '@lib/headless-mode';\nimport type { ProgramConfig } from '@lib/programs/program-step';\n\nimport { skillProgramOptions } from '../skill-program-options';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\n\n/**\n * Dispatch a parsed yargs invocation to the wizard runner. Applies the\n * program's `mapCliOptions` transform, then routes to `runWizardHeadless`,\n * `runWizardCI`, or `runWizard` based on the headless / `--ci` flags.\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 emitWizardError({ code: ErrorCodes.InternalUnhandled, message: msg });\n process.exit(1);\n }\n })();\n}\n\nexport function dispatchProgram(config: ProgramConfig, argv: Arguments): void {\n const argvRecord: Record<string, unknown> = { ...argv };\n const extras = config.mapCliOptions?.(argvRecord) ?? {};\n const options = { ...argvRecord, ...extras };\n if (isHeadless(options)) {\n // Same non-interactive pipeline `--ci` uses; validation (api-key,\n // install-dir, region) is owned by runNonInteractive.\n runWizardHeadless(config, options);\n } else 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 { 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 { mcpAnalyticsConfig } from '@lib/programs/mcp-analytics/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard mcp-analytics` — flat skill command, instrument-an-MCP-server today.\n *\n * Distinct from `wizard mcp add`: this instruments the user's own MCP server\n * with the `@posthog/mcp` SDK, rather than installing the PostHog MCP server\n * into a coding agent. Stays flat while instrumenting is the only action.\n */\nexport const mcpAnalyticsCommand: Command =\n nativeCommandFactory(mcpAnalyticsConfig);\n","import { replayVisionConfig } from '@lib/programs/replay-vision/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard replay-vision` — flat skill command, set up Replay vision today.\n *\n * Enables session replay recording and creates vision scanners tailored to\n * the product's key flows. Runs the `replay-vision` orchestrator flow, which\n * reuses the integration-v2 install/init mini-agents when the repo has no\n * PostHog integration yet.\n */\nexport const replayVisionCommand: Command =\n nativeCommandFactory(replayVisionConfig);\n","import { aiObservabilityConfig } from '@lib/programs/ai-observability/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard ai-observability` — flat skill command, wire AI Observability into a\n * project today.\n *\n * Installs the OpenTelemetry SDK, the PostHog span processor, and the\n * provider-specific instrumentation so LLM calls emit `$ai_generation` events.\n * The `ai-observability` context-mill skill has one variant per (LLM provider ×\n * language); the agent picks the right one at run time by scanning the\n * project's manifest and (when ambiguous) asking the user via `wizard_ask`.\n * Stays flat while a single \"add AIO to a project\" flow is the only action.\n */\nexport const aiObservabilityCommand: Command = nativeCommandFactory(\n aiObservabilityConfig,\n);\n","import { metricsConfig } from '@lib/programs/metrics/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard metrics` — flat skill command, wire PostHog application metrics\n * (counters, gauges, histograms via \\`posthog.metrics\\`) into a project.\n *\n * The `metrics` context-mill skill has one variant per platform (python,\n * nodejs, javascript, kubernetes, other/OTLP); the agent picks the right one\n * at run time by scanning the project's manifest and (when ambiguous) asking\n * the user via `wizard_ask`. Stays flat while a single \"add metrics to a\n * project\" flow is the only action.\n */\nexport const metricsCommand: Command = nativeCommandFactory(metricsConfig);\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';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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 emitWizardError({ code: ErrorCodes.CliBadArgs, message: reason });\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();\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 * Filter-as-you-type matching for PickerMenu. Split out from the component so the\n * ranking is testable on its own — the component only decides when to call it.\n */\n\nimport Fuse, { type IFuseOptions } from 'fuse.js';\n\n/** The searchable face of a picker option. PickerMenu's `PickerOption<T>` satisfies it. */\nexport interface Searchable {\n label: string;\n hint?: string;\n description?: string;\n}\n\n/**\n * Fuzzy fallback config. `ignoreLocation` because a term matching at the end of a\n * description is as good as one at the start, and Fuse's default distance window\n * would score the late match away. 0.5 is the loosest threshold that still bottoms\n * out: below it `gthb` misses `GitHub` entirely, which is the whole point of having\n * a fuzzy pass; above it the tail grows without surfacing anything new at the top.\n */\nexport const FUSE_OPTIONS: IFuseOptions<Searchable> = {\n keys: [\n { name: 'label', weight: 3 },\n { name: 'hint', weight: 1 },\n { name: 'description', weight: 1 },\n ],\n ignoreLocation: true,\n threshold: 0.5,\n includeScore: true,\n};\n\nexport function buildPickerIndex<T extends Searchable>(options: T[]): Fuse<T> {\n return new Fuse(options, FUSE_OPTIONS as IFuseOptions<T>);\n}\n\nfunction haystack(option: Searchable): string {\n return `${option.label} ${option.hint ?? ''} ${\n option.description ?? ''\n }`.toLowerCase();\n}\n\n/**\n * Rank options against a query, best first, or `null` for an empty query.\n *\n * Two passes, literal before fuzzy. Anything that literally contains every\n * whitespace-separated term wins outright, in the list's own order — that covers how\n * people actually type (`git iss` → `GitHub issues`) and keeps the common case as\n * tight as a plain substring filter, which fuzzy matching on its own is not: Fuse at\n * a threshold loose enough to forgive `gthb` also lets a third of the list through\n * on `replay`.\n *\n * Only when nothing matches literally does Fuse get a turn, so a typo degrades to a\n * ranked guess instead of an empty list. Terms are AND-ed there too, each matched\n * fuzzily on its own — Fuse's bitap pass over the whole query would otherwise need\n * `git iss` to be a near-edit of the text it's matching. Scores are distances (0 is\n * exact) and sum across terms, hence the ascending sort; ties keep the order the\n * first term put them in, since the sort is stable.\n */\nexport function rankOptions<T extends Searchable>(\n fuse: Fuse<T>,\n options: T[],\n query: string,\n): T[] | null {\n const terms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n if (!terms.length) {\n return null;\n }\n\n const literal = options.filter((option) =>\n terms.every((term) => haystack(option).includes(term)),\n );\n if (literal.length) {\n return literal;\n }\n\n let surviving: Map<T, number> | null = null;\n for (const term of terms) {\n const hits = new Map<T, number>(\n fuse.search(term).map(({ item, score }) => [item, score ?? 0]),\n );\n if (surviving === null) {\n surviving = hits;\n continue;\n }\n // Deleting the current key mid-iteration is well-defined for a Map.\n for (const [option, total] of surviving) {\n const score = hits.get(option);\n if (score === undefined) {\n surviving.delete(option);\n } else {\n surviving.set(option, total + score);\n }\n }\n }\n\n return [...(surviving ?? [])]\n .sort(([, a], [, b]) => a - b)\n .map(([option]) => option);\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 // No message → no row, so label-less pickers don't get a stray blank line.\n if (!message) return null;\n return (\n <Box>\n <Text bold color={Colors.accent}>\n {' '}\n {message}\n </Text>\n </Box>\n );\n};\n","/**\n * ConfirmButton — the confirm row used to submit a selection.\n *\n * Pure render. Multi-select menus (PickerMenu mode=\"multi\", GroupedPickerMenu)\n * append this below their options as the final focusable row: the user toggles\n * options with enter, then arrows down onto this row and presses enter to\n * submit. This replaces the older \"enter anywhere submits\" pattern, which\n * confused people who expected enter to toggle the focused item.\n *\n * Renders flat, mirroring the option rows — a focus triangle and the label,\n * accent and bold when focused, dimmed otherwise — so it lines up under the\n * options instead of sitting in a separate boxed target.\n */\n\nimport { Text } from 'ink';\nimport { Icons, Colors } from '@ui/tui/styles';\n\ninterface ConfirmButtonProps {\n /** Button text. Defaults to \"Confirm\". */\n label?: string;\n /** Whether the cursor is currently on the button. */\n focused: boolean;\n /** Optional selected-item count, rendered as \"Label (n)\" when > 0. */\n count?: number;\n}\n\nexport const ConfirmButton = ({\n label = 'Confirm',\n focused,\n count,\n}: ConfirmButtonProps) => {\n const text = count && count > 0 ? `${label} (${count})` : label;\n return (\n <Text\n color={focused ? Colors.accent : undefined}\n bold={focused}\n dimColor={!focused}\n >\n {focused ? Icons.triangleSmallRight : ' '} {text}\n </Text>\n );\n};\n","/**\n * useStdoutDimensions — Returns [columns, rows] and re-renders on terminal resize.\n *\n * Ink's useStdout() does not subscribe to resize events, so layout only updates\n * when something else causes a re-render. This hook listens to the stream's\n * 'resize' event (Node TTY) and updates state so the component re-renders\n * with the new dimensions.\n */\n\nimport { useStdout } from 'ink';\nimport { useState, useEffect } from 'react';\n\nexport function useStdoutDimensions(): [number, number] {\n const { stdout } = useStdout();\n const [size, setSize] = useState<[number, number]>(() => [\n stdout.columns || 80,\n stdout.rows || 24,\n ]);\n\n useEffect(() => {\n const cols = stdout.columns || 80;\n const rows = stdout.rows || 24;\n setSize([cols, rows]);\n\n const stream = stdout as NodeJS.WriteStream & {\n on?(event: string, fn: () => void): void;\n };\n if (typeof stream.on !== 'function') return;\n\n const onResize = () => {\n const c = stdout.columns || 80;\n const r = stdout.rows || 24;\n if (c > 0 && r > 0) setSize([c, r]);\n };\n stream.on('resize', onResize);\n return () => {\n stream.off?.('resize', onResize);\n };\n }, [stdout]);\n\n return size;\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 Backspace = 'backspace',\n /**\n * Any single printable character typed without a modifier. Broad by design,\n * so a binding using it must sit last — the first match wins, which is what\n * lets a specific char binding still take precedence over free typing.\n */\n Printable = 'printable',\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.Printable]: 12,\n [KeyMatch.Backspace]: 13,\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 case KeyMatch.Backspace:\n return !!key.backspace || !!key.delete;\n case KeyMatch.Printable:\n // Ink sets a flag for every non-text key while still passing a non-empty\n // `input`, so any flag but shift rules out typing.\n // Any single non-control character, not just ASCII — a filter query can\n // hold an accented or non-Latin letter.\n return (\n input.length === 1 &&\n input >= ' ' &&\n input !== '\\x7f' &&\n Object.entries(key).every(([flag, on]) => !on || flag === 'shift')\n );\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; enter selects.\n * Multi mode: checkbox glyphs toggled with enter, plus a focusable\n * Confirm button below the options. The cursor moves onto the button and\n * enter submits — see MultiPickerMenu for the rationale.\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, useMemo, useState } from 'react';\nimport { buildPickerIndex, rankOptions } from './picker-filter.js';\nimport { Icons, Colors } from '@ui/tui/styles';\nimport { PromptLabel } from './PromptLabel.js';\nimport { ConfirmButton } from './ConfirmButton.js';\nimport { wordWrap } from './layout-helpers.js';\nimport { useStdoutDimensions } from '@ui/tui/hooks/useStdoutDimensions';\nimport {\n useKeyBindings,\n KeyMatch,\n type KeyBinding,\n type KeyMatchOrChar,\n} from '@ui/tui/hooks/useKeyBindings';\n\nexport interface PickerOption<T> {\n label: string;\n value: T;\n hint?: string;\n /**\n * Multi-select only: a secondary explanation rendered dimmed and wrapped on\n * its own line(s) beneath the label, for choices that need more than a title.\n * When unset, the row renders exactly as a label-only row.\n */\n description?: 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 * Section heading: unselectable (navigation skips it, like `disabled`) but\n * rendered as a bold header rather than a muted row. Set `disabled` too so\n * the skip logic treats it as non-selectable.\n */\n header?: boolean;\n /** Indent the label one level, e.g. items nested under a `header` row. */\n indent?: 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/** First enabled option in [start, end), for initial focus and for entering\n * a page from the Confirm button. */\nfunction firstEnabled<T>(\n options: PickerOption<T>[],\n start = 0,\n end = options.length,\n): number {\n for (let i = start; i < end; i++) {\n if (!options[i]?.disabled) return i;\n }\n return start;\n}\n\n/** Last enabled option in [start, end), for wrapping from the button onto\n * the bottom of the page. */\nfunction lastEnabled<T>(\n options: PickerOption<T>[],\n start = 0,\n end = options.length,\n): number {\n for (let i = end - 1; i >= start; i--) {\n if (!options[i]?.disabled) return i;\n }\n return end - 1;\n}\n\n/**\n * Rows the surrounding screen or overlay consumes above and below a picker —\n * border + padding, title, prompt text, and the keyboard-hints bar. A\n * deliberately generous estimate: overshooting just shows a few fewer rows,\n * whereas undershooting lets a long list overflow the viewport (the bug this\n * windowing guards against). Mirrors GroupedPickerMenu's budgeting.\n */\nconst CHROME_OVERHEAD = 13;\n/**\n * Max visual rows a picker renders regardless of terminal height. Without a\n * ceiling a tall terminal lets a long list fill the whole viewport, which\n * reads as a wall of options; ~12 rows keeps the menu scannable and leaves\n * known breathing room above and below.\n */\nconst MAX_LIST_ROWS = 12;\n/** Extra rows a multi-select adds below its options: marginTop + Confirm button. */\nconst CONFIRM_CHROME = 3;\n/** Lists shorter than this never page — tall rows would split 2-3 options into pages of one. */\nconst MIN_COUNT_TO_PAGE = 5;\n/** Width the multi-select wraps option descriptions to (matches the render). */\nconst DESCRIPTION_WIDTH = 56;\n\ninterface PickerViewport {\n needsScroll: boolean;\n /** First option index on the current page. */\n start: number;\n /** One past the last option index on the current page. */\n end: number;\n hiddenAbove: number;\n hiddenBelow: number;\n /** Focus target one page over (wrapping), for the n/p keys. */\n pageStep: (focused: number, dir: 1 | -1) => number;\n}\n\n/**\n * Pages a single-column option list to the terminal height. The visible page\n * is derived from the focused index — no scroll state — so ↑/↓ flip pages as\n * focus crosses a page edge and n/p jump a whole page. Pages hold a fixed\n * option count sized to the tallest row (`rowCost`), trading a sparser page\n * on mixed-height lists for arithmetic-only paging. Engages only for\n * single-column pickers — multi-column grids already compress vertically.\n */\nfunction usePickerViewport(\n count: number,\n rowCost: number,\n chromeBelow: number,\n enabled: boolean,\n focused: number,\n): PickerViewport {\n const [, termRows] = useStdoutDimensions();\n const budget = Math.max(\n 5,\n Math.min(termRows - CHROME_OVERHEAD - chromeBelow, MAX_LIST_ROWS),\n );\n const needsScroll =\n enabled && count >= MIN_COUNT_TO_PAGE && count * rowCost > budget;\n // Reserve two rows for the \"↑/↓ N more\" indicators.\n const perPage = needsScroll\n ? Math.max(1, Math.floor((budget - 2) / rowCost))\n : count;\n const pageCount = Math.max(1, Math.ceil(count / perPage));\n const start = Math.floor(focused / perPage) * perPage;\n const end = Math.min(start + perPage, count);\n return {\n needsScroll,\n start,\n end,\n hiddenAbove: start,\n hiddenBelow: count - end,\n pageStep: (f, dir) =>\n ((Math.floor(f / perPage) + dir + pageCount) % pageCount) * perPage,\n };\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 /**\n * Filter-as-you-type. Defaults on once the list is long enough to page, where\n * finding one option means walking pages. Pass `false` to force it off.\n */\n filterable?: boolean;\n onSelect: (value: T | T[]) => void;\n}\n\n/** Lists at least this long get filtering. Shorter ones fit on a page or two,\n * where a filter row costs more rows than it saves. */\nconst FILTER_MIN_OPTIONS = 10;\n\nexport const PickerMenu = <T,>({\n message,\n options,\n mode = 'single',\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n filterable,\n onSelect,\n}: PickerMenuProps<T>) => {\n const canFilter = filterable ?? options.length >= FILTER_MIN_OPTIONS;\n const [filter, setFilter] = useState('');\n const fuse = useMemo(\n () => (canFilter ? buildPickerIndex(options) : null),\n [options, canFilter],\n );\n const visible = useMemo(\n () => (fuse ? rankOptions(fuse, options, filter) ?? options : options),\n [fuse, options, filter],\n );\n\n // Keyed by label, and owned here rather than by MultiPickerMenu: filtering\n // rewrites the list under the ticks, and the remount below would drop them.\n const [selected, setSelected] = useState<Set<string>>(new Set());\n\n const shared = {\n message,\n options: visible,\n centered,\n optionMarginBottom,\n onSelect,\n filter: canFilter ? filter : null,\n setFilter,\n totalCount: options.length,\n };\n\n // A filtered list is a fresh list with its own focus and paging, so remount on\n // each query rather than leaving stale indices to be re-validated.\n const key = String(filter);\n\n if (mode === 'multi') {\n return (\n <MultiPickerMenu\n key={key}\n {...shared}\n columns={columns}\n allOptions={options}\n selected={selected}\n setSelected={setSelected}\n />\n );\n }\n\n return <SinglePickerMenu key={key} {...shared} columns={columns} />;\n};\n\n/**\n * Backspace and free typing. Append these last: `Printable` matches almost any\n * key, and bindings resolve in order, so anything specific has to be registered\n * first to keep working. Both share a label/action so the hints bar shows one.\n */\nfunction filterBindings(\n filter: string,\n setFilter: (query: string) => void,\n): KeyBinding[] {\n return [\n {\n match: KeyMatch.Backspace,\n label: 'type',\n action: 'filter',\n handler: () => setFilter(filter.slice(0, -1)),\n },\n {\n match: KeyMatch.Printable,\n label: 'type',\n action: 'filter',\n handler: (input: string) => setFilter(filter + input),\n },\n ];\n}\n\n/** The filter row above a filterable list: what's typed, and how much it left. */\nconst FilterRow = ({\n filter,\n shown,\n total,\n}: {\n filter: string;\n shown: number;\n total: number;\n}) => (\n <Box>\n <Text dimColor>\n {filter\n ? `Filter: ${filter} (${shown} of ${total})`\n : `Type to filter ${total} options`}\n </Text>\n </Box>\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 filter,\n setFilter,\n totalCount,\n onSelect,\n}: {\n message?: string;\n options: PickerOption<T>[];\n centered?: boolean;\n columns?: number;\n optionMarginBottom?: number;\n /** Current filter query, or null when this picker isn't filterable. */\n filter: string | null;\n setFilter: (query: string) => void;\n totalCount: number;\n onSelect: (value: T | T[]) => void;\n}) => {\n const [focused, setFocused] = useState(() => firstEnabled(options));\n const rows = Math.ceil(options.length / columns);\n // Single-select rows are label-only (no descriptions): one line plus margin.\n const viewport = usePickerViewport(\n options.length,\n 1 + optionMarginBottom,\n filter !== null ? 1 : 0,\n columns === 1,\n focused,\n );\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 const dir = key.upArrow ? -1 : 1;\n // `start`/`end` derive from `focused`, so stepping past a page edge\n // flips the page rather than needing a bound here.\n setFocused(stepEnabled(options, rows, focused, dir));\n },\n },\n // Only on a non-filterable list. Once a filter row exists `n` and `p` are\n // characters, not commands — so they go for good, not just once a query is\n // typed, and the arrows carry paging instead by walking the whole list.\n ...(viewport.needsScroll && filter === null\n ? [\n {\n match: ['n', 'p'] as KeyMatchOrChar[],\n label: 'n/p',\n action: 'page',\n handler: (input: string) => {\n const target = viewport.pageStep(focused, input === 'n' ? 1 : -1);\n setFocused(\n options[target]?.disabled\n ? stepEnabled(options, rows, target, 1)\n : target,\n );\n },\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 if (filter !== null) {\n bindings.push(...filterBindings(filter, setFilter));\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 const renderOption = (opt: PickerOption<T>, flatIdx: number) => {\n const isFocused = flatIdx === focused;\n const base = opt.hint ? `${opt.label} (${opt.hint})` : opt.label;\n const label = opt.indent ? ` ${base}` : base;\n return (\n <Box key={flatIdx} gap={1} marginBottom={optionMarginBottom}>\n <Text\n color={isFocused ? Colors.accent : undefined}\n dimColor={!isFocused}\n >\n {isFocused && !opt.header ? Icons.triangleSmallRight : ' '}\n </Text>\n {opt.icon && <Text color={opt.icon.color}>{opt.icon.glyph}</Text>}\n <Text\n color={\n opt.header\n ? undefined\n : opt.disabled\n ? Colors.muted\n : isFocused\n ? Colors.accent\n : undefined\n }\n bold={opt.header || (isFocused && !opt.disabled)}\n dimColor={!opt.header && (!isFocused || opt.disabled)}\n >\n {label}\n </Text>\n </Box>\n );\n };\n\n return (\n <Box flexDirection=\"column\" alignItems={align}>\n <PromptLabel message={message} />\n {filter !== null && (\n <FilterRow filter={filter} shown={options.length} total={totalCount} />\n )}\n {filter && options.length === 0 ? (\n <Text dimColor>No options match. Backspace to widen the filter.</Text>\n ) : viewport.needsScroll ? (\n <Box flexDirection=\"column\">\n <Text dimColor>\n {viewport.hiddenAbove > 0\n ? `↑ ${viewport.hiddenAbove} more${\n filter === null ? ' [P] for previous page' : ''\n }`\n : ' '}\n </Text>\n {options\n .slice(viewport.start, viewport.end)\n .map((opt, relIdx) => renderOption(opt, viewport.start + relIdx))}\n <Text dimColor>\n {viewport.hiddenBelow > 0\n ? `↓ ${viewport.hiddenBelow} more${\n filter === null ? ' [N] for next page' : ''\n }`\n : ' '}\n </Text>\n </Box>\n ) : (\n <Box flexDirection=\"row\" gap={4}>\n {columnArrays.map((colOpts, colIdx) => (\n <Box key={colIdx} flexDirection=\"column\">\n {colOpts.map((opt, rowIdx) =>\n renderOption(opt, colIdx * rows + rowIdx),\n )}\n </Box>\n ))}\n </Box>\n )}\n </Box>\n );\n};\n\n/**\n * Custom multi-select with checkbox glyphs and accent highlight.\n *\n * Interaction model (shared with GroupedPickerMenu):\n * - \\u2191\\u2193 move the cursor through the options AND onto the Confirm button,\n * which lives just past the last option.\n * - enter toggles the focused option (no more \"space toggles but enter\n * advances\" split that tripped people up). Space is kept as an\n * undocumented alias, but the hints bar advertises only enter.\n * - moving onto the Confirm button and pressing enter submits the\n * current selection.\n */\nconst MultiPickerMenu = <T,>({\n message,\n options,\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n filter,\n setFilter,\n totalCount,\n allOptions,\n selected,\n setSelected,\n onSelect,\n}: {\n message?: string;\n options: PickerOption<T>[];\n centered?: boolean;\n columns?: number;\n optionMarginBottom?: number;\n /** Current filter query, or null when this picker isn't filterable. */\n filter: string | null;\n setFilter: (query: string) => void;\n totalCount: number;\n /** Every option, filtered or not. Ticks outlive the query, so resolving and\n * submitting them has to happen against the full list. */\n allOptions: PickerOption<T>[];\n selected: Set<string>;\n setSelected: (update: (prev: Set<string>) => Set<string>) => void;\n onSelect: (value: T | T[]) => void;\n}) => {\n const [focused, setFocused] = useState(() => firstEnabled(options));\n // When true, the cursor is on the Confirm button rather than an option.\n const [onButton, setOnButton] = useState(false);\n const rows = Math.ceil(options.length / columns);\n // A row is its label line plus any margin; a description adds one line per\n // wrapped line beneath the label. Pages size to the tallest row.\n const rowCost = options.reduce(\n (max, opt) =>\n Math.max(\n max,\n 1 +\n optionMarginBottom +\n (opt.description\n ? wordWrap(opt.description, DESCRIPTION_WIDTH).length\n : 0),\n ),\n 1,\n );\n const viewport = usePickerViewport(\n options.length,\n rowCost,\n CONFIRM_CHROME + (filter !== null ? 1 : 0),\n columns === 1,\n focused,\n );\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 confirm = () => {\n // In `allOptions` order, so a pick made under one filter still submits\n // after the query moved on.\n const values = allOptions\n .filter((option) => selected.has(option.label))\n .map((option) => option.value);\n onSelect(values);\n };\n\n const bindings: KeyBinding[] = [\n {\n match: [KeyMatch.UpArrow, KeyMatch.DownArrow],\n label: '\\u2191\\u2193',\n action: 'navigate',\n handler: (_input, key) => {\n const dir = key.upArrow ? -1 : 1;\n if (onButton) {\n // Button \\u2192 back onto the current page (bottom for \\u2191, top for \\u2193).\n setOnButton(false);\n setFocused(\n dir === -1\n ? lastEnabled(options, viewport.start, viewport.end)\n : firstEnabled(options, viewport.start, viewport.end),\n );\n return;\n }\n const col = Math.floor(focused / rows);\n const row = focused % rows;\n const colLen = Math.min(rows, options.length - col * rows);\n // Nearest enabled option above/below in this column; leaving the\n // column lands on the button.\n let r = row + dir;\n while (r >= 0 && r < colLen && options[col * rows + r]?.disabled) {\n r += dir;\n }\n if (r >= 0 && r < colLen) {\n setFocused(col * rows + r);\n } else {\n setOnButton(true);\n }\n },\n },\n // Only on a non-filterable list. Once a filter row exists `n` and `p` are\n // characters, not commands — so they go for good, not just once a query is\n // typed, and the arrows carry paging instead by walking the whole list.\n ...(viewport.needsScroll && filter === null\n ? [\n {\n match: ['n', 'p'] as KeyMatchOrChar[],\n label: 'n/p',\n action: 'page',\n handler: (input: string) => {\n const target = viewport.pageStep(focused, input === 'n' ? 1 : -1);\n setOnButton(false);\n setFocused(\n options[target]?.disabled\n ? stepEnabled(options, rows, target, 1)\n : target,\n );\n },\n },\n ]\n : []),\n {\n // Space is only an alias for enter when there's no filter to type into.\n match:\n filter !== null ? KeyMatch.Return : [KeyMatch.Space, KeyMatch.Return],\n label: 'enter',\n action: 'select',\n handler: () => {\n if (onButton) {\n confirm();\n return;\n }\n // `focused` can point past the end: filtering to zero matches leaves\n // nothing under the cursor, and enter is the natural thing to try there.\n const option = options[focused];\n if (!option || option.disabled) return;\n const label = option.label;\n setSelected((prev) => {\n const next = new Set(prev);\n if (next.has(label)) {\n next.delete(label);\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 (option.exclusive) {\n return new Set([label]);\n }\n // Against `allOptions`: the pick being cleared may be off-screen\n // under the current query.\n for (const picked of next) {\n if (allOptions.find((o) => o.label === picked)?.exclusive) {\n next.delete(picked);\n }\n }\n next.add(label);\n return next;\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 if (onButton) return;\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 if (filter !== null) {\n bindings.push(...filterBindings(filter, setFilter));\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 const renderOption = (opt: PickerOption<T>, flatIdx: number) => {\n const isFocused = !onButton && flatIdx === focused;\n const isSelected = selected.has(opt.label);\n const label = opt.hint ? `${opt.label} (${opt.hint})` : opt.label;\n const checkbox = isSelected ? Icons.squareFilled : Icons.squareOpen;\n return (\n <Box\n key={flatIdx}\n flexDirection=\"column\"\n marginBottom={optionMarginBottom}\n >\n <Box gap={1}>\n <Text\n color={isSelected ? 'white' : Colors.muted}\n dimColor={!isFocused && !isSelected}\n >\n {checkbox}\n </Text>\n {opt.icon && <Text color={opt.icon.color}>{opt.icon.glyph}</Text>}\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 {/* Optional dimmed, wrapped explanation under the label. The explicit\n width forces Ink to wrap (an unconstrained Box shrinks to its\n content and never wraps). Renders only when set, so label-only rows\n are byte-for-byte unchanged. */}\n {opt.description && (\n <Box marginLeft={4} width={DESCRIPTION_WIDTH}>\n <Text dimColor wrap=\"wrap\">\n {opt.description}\n </Text>\n </Box>\n )}\n </Box>\n );\n };\n\n return (\n <Box flexDirection=\"column\" alignItems={centered ? 'center' : undefined}>\n <PromptLabel message={message} />\n {filter !== null && (\n <FilterRow filter={filter} shown={options.length} total={totalCount} />\n )}\n {filter && options.length === 0 && (\n <Text dimColor>No options match. Backspace to widen the filter.</Text>\n )}\n {viewport.needsScroll ? (\n <Box\n flexDirection=\"column\"\n marginLeft={centered ? 0 : 2}\n marginTop={message ? 1 : 0}\n >\n <Text dimColor>\n {viewport.hiddenAbove > 0\n ? `↑ ${viewport.hiddenAbove} more${\n filter === null ? ' [P] for previous page' : ''\n }`\n : ' '}\n </Text>\n {options\n .slice(viewport.start, viewport.end)\n .map((opt, relIdx) => renderOption(opt, viewport.start + relIdx))}\n <Text dimColor>\n {viewport.hiddenBelow > 0\n ? `↓ ${viewport.hiddenBelow} more${\n filter === null ? ' [N] for next page' : ''\n }`\n : ' '}\n </Text>\n </Box>\n ) : (\n <Box\n flexDirection=\"row\"\n gap={4}\n marginLeft={centered ? 0 : 2}\n marginTop={message ? 1 : 0}\n >\n {columnArrays.map((colOpts, colIdx) => (\n <Box key={colIdx} flexDirection=\"column\">\n {colOpts.map((opt, rowIdx) =>\n renderOption(opt, colIdx * rows + rowIdx),\n )}\n </Box>\n ))}\n </Box>\n )}\n <Box marginTop={1} marginLeft={centered ? 0 : 2}>\n <ConfirmButton focused={onButton} count={selected.size} />\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();\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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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 emitWizardError({\n code: ErrorCodes.ArgsMissingApiKey,\n message: 'CI mode requires --api-key (personal API key phx_xxx)',\n });\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 baseUrl: options.baseUrl as string | undefined,\n });\n\n const issues = await fetchHealthIssues(\n accessToken,\n host.apiHost,\n projectId,\n );\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 emitWizardError({\n code:\n error instanceof ApiError && error.statusCode === 401\n ? ErrorCodes.AuthInvalidOrExpired\n : ErrorCodes.InternalUnhandled,\n message,\n });\n process.exit(1);\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 { warehouseSourceConfig } from '@lib/programs/warehouse-source/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard warehouse` — detect and connect a data warehouse source.\n *\n * Mirrors `revenue-analytics`: flat skill command driven by the\n * warehouse-source program.\n */\nexport const warehouseCommand: Command = nativeCommandFactory(\n warehouseSourceConfig,\n);\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { selfDrivingConfig } from '@lib/programs/self-driving/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const selfDrivingCommand: Command = {\n name: 'self-driving',\n description: selfDrivingConfig.description,\n options: {\n ...skillProgramOptions,\n integrate: {\n describe:\n 'Integrate the PostHog SDK first, then set up Self-driving — skips the integration prompt and logs you in via OAuth (no \"create an account?\" question). Use when the project isn\\'t set up yet but you already have a PostHog account.',\n type: 'boolean',\n default: false,\n },\n ...(selfDrivingConfig.cliOptions ?? {}),\n },\n check: (argv) => {\n // self-driving builds on an existing integration and is fully interactive,\n // so the modes that break it are rejected before the TUI/agent loop spins\n // up rather than failing late (a 403 on the first MCP probe under --signup,\n // or a stalled `wizard_ask` with no bridge under --ci).\n if (argv.signup) {\n throw new Error(\n '`self-driving` cannot run with --signup. Just run `wizard ' +\n 'self-driving`: when your project has no PostHog, it asks whether ' +\n 'you already have an account and offers to create one for you ' +\n '(no flag needed).',\n );\n }\n if (argv.ci) {\n throw new Error(\n '`self-driving` cannot run in CI mode — it requires interactive steps ' +\n '(GitHub connect, issue-tracker selection, custom-scout approval).',\n );\n }\n return true;\n },\n handler: (argv) => {\n const extras =\n selfDrivingConfig.mapCliOptions?.(argv as Record<string, unknown>) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(selfDrivingConfig, options);\n } else {\n runWizard(selfDrivingConfig, 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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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({\n debug,\n baseUrl: argv.baseUrl as string | undefined,\n });\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 emitWizardError({\n code: ErrorCodes.CliInteractiveRequired,\n message: 'Connecting Slack requires an interactive terminal.',\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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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\n/**\n * Reject an unknown skill id before the wizard authenticates.\n *\n * Without this, `readSkillName` accepts any non-empty string and the name is\n * only validated far downstream, when the agent tries to download it — after\n * the user has already logged in. A typo then costs a full auth round-trip\n * (the concern raised in review). We resolve against the same set\n * `downloadSkill` uses (`categories` flattened by `id`), so this never\n * false-rejects a skill the download would have accepted.\n *\n * If the registry is unreachable we stay silent and defer to the download\n * step's own `menu-fetch-failed` handling, rather than adding a second network\n * dependency that could block an otherwise-valid run.\n */\nasync function assertSkillExists(skillName: string): Promise<void> {\n const skillsBaseUrl = getSkillsBaseUrl();\n const menu = await fetchSkillMenu(skillsBaseUrl);\n if (!menu) return; // registry down — let the download step surface it\n const known = Object.values(menu.categories)\n .flat()\n .some((s) => s.id === skillName);\n if (known) return;\n analytics.wizardCapture('cli dispatch error', {\n reason: 'unknown skill',\n family: 'skill',\n sub: skillName,\n skillsBaseUrl,\n });\n try {\n await analytics.flush();\n } catch {\n /* best-effort */\n }\n throw new Error(\n `Unknown skill \"${skillName}\". Run \\`wizard skill list\\` to see available skills.`,\n );\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: () => {\n runCommandHandler(async () => {\n const skillsBaseUrl = getSkillsBaseUrl();\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 emitWizardError({\n code: ErrorCodes.SkillMenuFetchFailed,\n message: \"Couldn't reach the skill registry.\",\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 // Under `.strictOptions()` yargs rejects a positional declared only in the\n // command string as an \"Unknown argument\" — it has to be registered via\n // `.positional()` too (see the `positionals` note on the Command interface).\n // Declare `skill-name` here so `wizard skill <id>` actually accepts its value.\n positionals: {\n 'skill-name': {\n type: 'string',\n describe: 'Skill id to run (e.g. audit-events), or `list`',\n },\n },\n // yargs already enforces the presence of the `<skill-name>` positional, but\n // an 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 runCommandHandler(async () => {\n const skillName = readSkillName(argv);\n await assertSkillExists(skillName);\n // runSkillMode reads `argv.skill`; bridge the positional onto it.\n runSkillMode({ ...argv, skill: skillName });\n });\n },\n};\n","import * as path from 'node:path';\nimport * as readline from 'node:readline/promises';\nimport type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { analytics } from '@utils/analytics';\nimport {\n CLI_STEERING_TARGETS,\n type CliSteeringTarget,\n detectTargets,\n findTarget,\n installOrUpdatePostHogCli,\n installSteeringSnippet,\n} from '@steps/install-cli-steering';\nimport type { Command } from '../command';\n\nexport const cliAddCommand: Command = {\n name: 'add',\n description:\n \"Install or update PostHog CLI and add steering instructions to your coding agent's global instructions file\",\n options: {\n agent: {\n describe: 'Agent to install the instructions for',\n choices: CLI_STEERING_TARGETS.map((target) => target.id),\n type: 'string',\n },\n path: {\n describe:\n 'Write to an explicit instructions file instead of a detected agent',\n type: 'string',\n },\n all: {\n default: false,\n describe: 'Install for every detected agent without prompting',\n type: 'boolean',\n },\n },\n examples: [\n ['wizard cli add', 'Detect your coding agents and pick one'],\n [\n 'wizard cli add --agent claude-code',\n 'Install for Claude Code (~/.claude/CLAUDE.md)',\n ],\n ['wizard cli add --all', 'Install for every detected agent'],\n [\n 'wizard cli add --path ./AGENTS.md',\n 'Install into a specific instructions file',\n ],\n ],\n check: (argv) => {\n if (argv.all && (argv.agent || argv.path)) {\n throw new Error('--all cannot be combined with --agent or --path');\n }\n return true;\n },\n handler: (argv) => {\n void runCliAdd(argv);\n },\n};\n\nasync function runCliAdd(argv: Arguments): Promise<void> {\n setUI(new LoggingUI());\n const ui = getUI();\n ui.intro('PostHog CLI setup');\n\n const files = await resolveTargetFiles(argv);\n if (files.length === 0) {\n process.exit(1);\n return;\n }\n\n ui.log.info('Installing or updating PostHog CLI...');\n const cliInstallResult = installOrUpdatePostHogCli();\n if (!cliInstallResult.success) {\n ui.log.error(\n `Failed to install or update PostHog CLI: ${\n cliInstallResult.error ?? ''\n }`,\n );\n analytics.wizardCapture('cli steering installed', {\n files: files.length,\n failures: files.length,\n cli_install_failed: true,\n agent: typeof argv.agent === 'string' ? argv.agent : undefined,\n });\n process.exit(1);\n return;\n }\n ui.log.success('Installed or updated PostHog CLI.');\n\n let failures = 0;\n for (const file of files) {\n const result = installSteeringSnippet(file);\n if (result.success) {\n ui.log.success(`Installed PostHog steering instructions in ${file}`);\n } else {\n failures += 1;\n ui.log.error(`Failed to update ${file}: ${result.error ?? ''}`);\n }\n }\n\n analytics.wizardCapture('cli steering installed', {\n files: files.length,\n failures,\n agent: typeof argv.agent === 'string' ? argv.agent : undefined,\n });\n\n if (failures > 0) {\n process.exit(1);\n return;\n }\n ui.outro(\n 'Done. PostHog CLI is installed and your agent will now use `posthog-cli api` for PostHog tasks.',\n );\n process.exit(0);\n}\n\n/** Resolve which instruction files to write, from flags, detection, or a prompt. */\nasync function resolveTargetFiles(argv: Arguments): Promise<string[]> {\n const ui = getUI();\n\n if (typeof argv.path === 'string' && argv.path.trim()) {\n return [path.resolve(argv.path.trim())];\n }\n\n if (typeof argv.agent === 'string') {\n // yargs `choices` already rejected unknown ids.\n const target = findTarget(argv.agent);\n if (!target) {\n ui.log.error(`Unsupported agent: ${argv.agent}`);\n return [];\n }\n return [target.instructionsPath()];\n }\n\n const detected = detectTargets();\n if (detected.length === 0) {\n ui.log.error(\n 'No supported coding agents detected. Pass --agent <id> or --path <file> to choose a target.',\n );\n ui.log.info(\n `Supported agents: ${CLI_STEERING_TARGETS.map((t) => t.id).join(', ')}`,\n );\n return [];\n }\n\n if (argv.all === true) {\n ui.log.info(\n `Installing for all detected agents: ${detected\n .map((t) => t.name)\n .join(', ')}`,\n );\n return detected.map((target) => target.instructionsPath());\n }\n\n if (detected.length === 1) {\n ui.log.info(\n `Detected ${detected[0].name} (${detected[0].instructionsPath()})`,\n );\n return [detected[0].instructionsPath()];\n }\n\n // Non-interactive shells can't pick, so install for every detected agent —\n // the snippet is additive and idempotent, mirroring how MCP install treats\n // all supported clients.\n if (!process.stdin.isTTY || !process.stdout.isTTY) {\n ui.log.info(\n `Installing for all detected agents: ${detected\n .map((t) => t.name)\n .join(', ')}`,\n );\n return detected.map((target) => target.instructionsPath());\n }\n\n const selected = await promptForTargets(detected);\n return selected.map((target) => target.instructionsPath());\n}\n\n/** Minimal numbered selection — this command is intentionally not a TUI flow. */\nasync function promptForTargets(\n detected: CliSteeringTarget[],\n): Promise<CliSteeringTarget[]> {\n const ui = getUI();\n ui.log.info('Which coding agent are you using?');\n detected.forEach((target, index) => {\n ui.log.info(\n ` ${index + 1}) ${target.name} (${target.instructionsPath()})`,\n );\n });\n ui.log.info(` ${detected.length + 1}) All of the above`);\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n try {\n for (;;) {\n const answer = (\n await rl.question(`Select 1-${detected.length + 1}: `)\n ).trim();\n const choice = Number(answer);\n if (\n Number.isInteger(choice) &&\n choice >= 1 &&\n choice <= detected.length\n ) {\n return [detected[choice - 1]];\n }\n if (choice === detected.length + 1) {\n return detected;\n }\n ui.log.warn(`Enter a number between 1 and ${detected.length + 1}.`);\n }\n } finally {\n rl.close();\n }\n}\n","import { cliAddCommand } from './add';\nimport type { Command } from '../command';\n\nexport const cliCommand: Command = {\n name: 'cli',\n description: 'PostHog CLI agent integration commands',\n children: [cliAddCommand],\n};\n","#!/usr/bin/env node\nimport { satisfies } from 'semver';\nimport { Agent, setGlobalDispatcher } from 'undici';\nimport { ErrorCodes } from './src/lib/errors/codes.js';\nimport { emitWizardError } from './src/lib/errors/emit.js';\n\n// Keep in sync with `engines.node` in package.json. npx does not enforce\n// engines, so this preflight is the only thing standing between an old Node\n// runtime and a cryptic dependency crash (e.g. undici's markAsUncloneable\n// TypeError on Node < 22.10).\nconst NODE_VERSION_RANGE = '>=22.22.0';\n\n/*\n * TODO(#1198): remove when fetch over HTTP/2 is safe on Node 26. Remove when all\n * of these are true:\n * - nodejs/node no longer creates an orphan ClientHttp2Stream when a client\n * session gets HEADERS for a stream id it already reset. Repro: abort a fetch\n * before its response headers, then idle 4s on Node 26. Fixed when the\n * process survives.\n * - modelcontextprotocol/typescript-sdk#2526 is closed.\n * - pi-coding-agent's CLI drops `allowH2: false` from its http-dispatcher.\n * Same workaround as pi's CLI and typescript-sdk#2526: HTTP/1.1 only.\n */\nsetGlobalDispatcher(new Agent({ allowH2: false }));\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 [\n `The PostHog wizard needs a newer version of Node.js to run.`,\n ``,\n ` You have: ${process.version}`,\n ` You need: v${NODE_VERSION_RANGE.replace('>=', '')} or later`,\n ``,\n `To update Node.js:`,\n ``,\n ` Download the latest version from https://nodejs.org/en/download`,\n ` Or, if you use nvm, run: nvm install 22 && nvm use 22`,\n ``,\n `Then run the wizard again. Stuck? Email wizard@posthog.com and we'll help.`,\n ].join('\\n'),\n );\n emitWizardError({\n code: ErrorCodes.CliNodeVersion,\n message: `Node ${process.version} is below the required range ${NODE_VERSION_RANGE}`,\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 { mcpAnalyticsCommand } from './src/commands/mcp-analytics';\nimport { replayVisionCommand } from './src/commands/replay-vision';\nimport { aiObservabilityCommand } from './src/commands/ai-observability';\nimport { metricsCommand } from './src/commands/metrics';\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 { warehouseCommand } from './src/commands/warehouse';\nimport { selfDrivingCommand } from './src/commands/self-driving';\nimport { slackCommand } from './src/commands/slack';\nimport { uploadSourcemapsCommand } from './src/commands/upload-sourcemaps';\nimport { skillCommand } from './src/commands/skill';\nimport { cliCommand } from './src/commands/cli';\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(mcpAnalyticsCommand)\n .use(replayVisionCommand)\n .use(aiObservabilityCommand)\n .use(metricsCommand)\n .use(cliCommand)\n .use(auditCommand)\n .use(doctorCommand)\n .use(migrateCommand)\n .use(revenueCommand)\n .use(warehouseCommand)\n .use(selfDrivingCommand)\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,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,QAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,IAAI,eAAe,EAAE,CAAC,CAC7D,QAAO,KAAK,WAA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tD;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK,CACb;AACD,iBAAgB;EACd,MAAM,WAAW;EACjB,SAAS,QAAQ,QAAQ,QAAQ,+BAA+B;EACjE,CAAC;AACF,SAAQ,KAAK,EAAE;;AA0CjB,+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,oBAAoB,CACxB,IAAI,oBAAoB,CACxB,IAAI,uBAAuB,CAC3B,IAAI,eAAe,CACnB,IAAI,WAAW,CACf,IAAI,aAAa,CACjB,IAAI,cAAc,CAClB,IAAI,eAAe,CACnB,IAAI,eAAe,CACnB,IAAI,iBAAiB,CACrB,IAAI,mBAAmB,CACvB,IAAI,aAAa,CACjB,IAAI,wBAAwB,CAC5B,IAAI,aAAa,CACjB,MAAM"}
|
|
1
|
+
{"version":3,"file":"bin.js","names":["getContentBlocks","DOCS_URL","REPORT_FILE","DOCS_URL","getContentBlocks","getContentBlocks","fs","path","REPORT_FILE","DOCS_URL","agentSkillContentBlocks","join","join","path"],"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/warehouse-source/steps.ts","../src/lib/programs/warehouse-source/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/steps/install-cli-steering/index.ts","../src/lib/programs/error-tracking-upload-source-maps/index.ts","../src/lib/programs/self-driving/detect.ts","../src/lib/programs/self-driving/detect-agentic.ts","../src/lib/programs/self-driving/steps.ts","../src/lib/programs/self-driving/prompt.ts","../src/lib/programs/self-driving/step-keys.ts","../src/lib/programs/self-driving/content/pricing.ts","../src/lib/programs/self-driving/content/tips.ts","../src/lib/programs/self-driving/content/pipeline-diagram.tsx","../src/lib/programs/self-driving/content/index.tsx","../src/lib/programs/self-driving/index.ts","../src/lib/programs/mcp/index.ts","../src/lib/programs/mcp-analytics/index.ts","../src/lib/programs/replay-vision/index.ts","../src/lib/programs/ai-observability/index.ts","../src/lib/programs/metrics/index.ts","../src/lib/programs/slack/index.ts","../src/lib/programs/program-registry.ts","../src/commands/mcp/tui-availability.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-non-interactive.ts","../src/lib/runners/run-wizard-ci.ts","../src/lib/runners/run-wizard-headless.ts","../src/commands/skill-program-options.ts","../src/commands/factories/shared.ts","../src/commands/factories/native-command-factory.ts","../src/commands/mcp-analytics.ts","../src/commands/replay-vision.ts","../src/commands/ai-observability.ts","../src/commands/metrics.ts","../src/lib/programs/dispatch-family.ts","../src/ui/tui/primitives/picker-filter.ts","../src/ui/tui/primitives/PromptLabel.tsx","../src/ui/tui/primitives/ConfirmButton.tsx","../src/ui/tui/hooks/useStdoutDimensions.ts","../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/migrate.ts","../src/commands/revenue.ts","../src/commands/warehouse.ts","../src/commands/self-driving.ts","../src/commands/slack.ts","../src/commands/upload-sourcemaps.ts","../src/commands/basic-integration/skill.ts","../src/commands/skill.ts","../src/commands/cli/add.ts","../src/commands/cli/index.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 { Harness, Sequence } from '@lib/constants';\nimport { regionOption } from '@lib/headless-mode';\nimport { initLocalDev, localMcpSkillsNotice } from '@lib/local-dev';\nimport { toCommandModule, type Command } from './commands/command';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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 `--local-*` flags live\n * in the constructor's `!IS_PRODUCTION_BUILD` block instead, so published\n * builds reject them; see `docs/local-dev.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 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`.\n // NB: the experimental headless flag is deliberately NOT global — it's\n // declared per-command (basic integration + audit) via `headlessOption`\n // in @lib/headless-mode, so no other command accepts it.\n 'base-url': {\n describe:\n 'Override the PostHog base URL (e.g. http://localhost:8010), bypassing region resolution. Pins the API host, cloud URL, and OAuth server.\\nenv: POSTHOG_WIZARD_BASE_URL',\n type: 'string' 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 // The published-build, non-interactive path is the experimental headless\n // flag, declared per-command on basic integration + audit via\n // `headlessOption` (see @lib/headless-mode), so no other command accepts\n // it. CI needs `region` globally because the workbench passes it to every\n // command. --ci and headless stay separate so their behavior can diverge.\n if (!IS_PRODUCTION_BUILD) {\n cli = cli\n .options(regionOption)\n .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 // Runner overrides — dev/test only, same lifecycle as --ci.\n .option('harness', {\n describe:\n 'Override the agent harness (anthropic | pi). Wins over the PostHog runner flag.\\nenv: POSTHOG_WIZARD_HARNESS',\n choices: Object.values(Harness),\n type: 'string',\n hidden: true,\n })\n .option('sequence', {\n describe:\n 'Override the runner sequence (linear | orchestrator). Wins over the PostHog orchestrator flag.\\nenv: POSTHOG_WIZARD_SEQUENCE',\n choices: Object.values(Sequence),\n type: 'string',\n hidden: true,\n })\n .option('model', {\n describe:\n 'Override the agent model (gateway id, e.g. claude-sonnet-4-6 | openai/gpt-5). Wins over the binding default.\\nenv: POSTHOG_WIZARD_MODEL',\n type: 'string',\n hidden: true,\n })\n .option('capture-aio', {\n default: false,\n describe:\n \"Capture wizard LLM calls as $ai_generation events in the authenticated project's AI Observability tab.\\nenv: POSTHOG_WIZARD_CAPTURE_AIO\",\n type: 'boolean',\n hidden: true,\n })\n // ── Local dev targets (see docs/local-dev.md) ──────────────────\n // Not `hidden`: the build gate already keeps them from users, so\n // hiding them would only cost the dev-build help row. Deliberately not\n // named `--local`, which `wizard mcp add` already uses for something\n // unrelated.\n .option('local-dev', {\n default: false,\n describe:\n 'Point context-mill, MCP, and PostHog at local dev servers\\nenv: POSTHOG_WIZARD_LOCAL_DEV',\n type: 'boolean',\n })\n // No `default` on the three below — they must stay `undefined` when\n // absent for resolveLocalDev() to honour the umbrella and `--no-*`.\n .option('local-context-mill', {\n describe:\n 'Fetch skills from the local context-mill server (http://localhost:8765)\\nenv: POSTHOG_WIZARD_LOCAL_CONTEXT_MILL',\n type: 'boolean',\n })\n .option('local-mcp', {\n describe:\n 'Use the local MCP server (http://localhost:8787/mcp). Affects MCP only — use --local-context-mill for skills.\\nenv: POSTHOG_WIZARD_LOCAL_MCP',\n type: 'boolean',\n })\n .option('local-posthog', {\n describe:\n 'Point every PostHog origin (API, app, OAuth, gateway) at http://localhost:8010\\nenv: POSTHOG_WIZARD_LOCAL_POSTHOG',\n type: 'boolean',\n });\n }\n\n this.cli = cli\n // Middleware rather than an argv scan so the env path is covered too,\n // and it runs before any TUI takes the terminal.\n .middleware((argv) => {\n // The one place local targets are resolved; everything downstream reads\n // getLocalDev().\n initLocalDev(argv);\n\n // Temporary.\n const notice = localMcpSkillsNotice({\n localDev: argv.localDev as boolean | undefined,\n localMcp: argv.localMcp as boolean | undefined,\n localContextMill: argv.localContextMill as boolean | undefined,\n });\n if (notice) {\n process.stderr.write(`\\n\\x1b[33m! ${notice}\\x1b[0m\\n\\n`);\n }\n })\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 emitWizardError({ code: ErrorCodes.CliBadArgs, message: text });\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 emitWizardError({\n code: ErrorCodes.CliFlagUnavailable,\n message: 'CI mode is not supported in published builds.',\n });\n process.exit(1);\n }\n\n // --harness / --sequence / --model / --capture-aio are dev/test-only.\n // In published builds the env vars would silently no-op, so reject them\n // explicitly instead.\n const argvHasOverride = args.some(\n (a) =>\n a === '--harness' ||\n a.startsWith('--harness=') ||\n a === '--sequence' ||\n a.startsWith('--sequence=') ||\n a === '--model' ||\n a.startsWith('--model=') ||\n a === '--capture-aio' ||\n a === '--no-capture-aio' ||\n a.startsWith('--capture-aio='),\n );\n const envHasOverride =\n (process.env.POSTHOG_WIZARD_HARNESS != null &&\n process.env.POSTHOG_WIZARD_HARNESS !== '') ||\n (process.env.POSTHOG_WIZARD_SEQUENCE != null &&\n process.env.POSTHOG_WIZARD_SEQUENCE !== '') ||\n (process.env.POSTHOG_WIZARD_MODEL != null &&\n process.env.POSTHOG_WIZARD_MODEL !== '') ||\n (process.env.POSTHOG_WIZARD_CAPTURE_AIO != null &&\n process.env.POSTHOG_WIZARD_CAPTURE_AIO !== '');\n if (argvHasOverride || envHasOverride) {\n process.stderr.write(\n `\\n\\x1b[1;91m✖ The --harness, --sequence, --model, and --capture-aio overrides are not available in published builds.\\x1b[0m\\n\\n`,\n );\n emitWizardError({\n code: ErrorCodes.CliFlagUnavailable,\n message:\n 'The --harness, --sequence, --model, and --capture-aio overrides are not available in published builds.',\n });\n process.exit(1);\n }\n\n // `--local-mcp` used to be declared unconditionally, so published builds\n // accepted it and quietly aimed the run at localhost. Reject explicitly.\n const argvHasLocalTarget = args.some((a) =>\n LOCAL_TARGET_FLAGS.some(\n (f) => a === `--${f}` || a === `--no-${f}` || a.startsWith(`--${f}=`),\n ),\n );\n const envHasLocalTarget = LOCAL_TARGET_ENV_VARS.some(\n (k) => process.env[k] != null && process.env[k] !== '',\n );\n if (argvHasLocalTarget || envHasLocalTarget) {\n process.stderr.write(\n `\\n\\x1b[1;91m✖ The --local-dev, --local-context-mill, --local-mcp, and --local-posthog targets are not available in published builds.\\x1b[0m\\n` +\n ` They point the wizard at development servers on localhost.\\n\\n`,\n );\n emitWizardError({\n code: ErrorCodes.CliFlagUnavailable,\n message:\n 'The --local-dev, --local-context-mill, --local-mcp, and --local-posthog targets are not available in published builds.',\n });\n process.exit(1);\n }\n }\n void this.cli.wrap(process.stdout.isTTY ? this.cli.terminalWidth() : 80)\n .argv;\n }\n}\n\n/** Excludes bare `local`: `wizard mcp add --local` stays available in prod. */\nconst LOCAL_TARGET_FLAGS = [\n 'local-dev',\n 'local-context-mill',\n 'local-mcp',\n 'local-posthog',\n] as const;\n\nconst LOCAL_TARGET_ENV_VARS = [\n 'POSTHOG_WIZARD_LOCAL_DEV',\n 'POSTHOG_WIZARD_LOCAL_CONTEXT_MILL',\n 'POSTHOG_WIZARD_LOCAL_MCP',\n 'POSTHOG_WIZARD_LOCAL_POSTHOG',\n] as const;\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 baseUrl: argv.baseUrl as string | undefined,\n jsonMode,\n });\n}\n\ntype ProvisionArgs = {\n email: string;\n region: 'US' | 'EU';\n name: string;\n baseUrl?: string;\n jsonMode: boolean;\n};\n\nasync function provision({\n email,\n region,\n name,\n baseUrl,\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, { baseUrl });\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 { headlessOption, isHeadless, regionOption } from '@lib/headless-mode';\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 // The experimental headless flag — declared here (and on `audit`) rather\n // than globally. Routed by this command's handler via runHeadlessInstall.\n ...headlessOption,\n ...regionOption,\n },\n check: (argv) => {\n // --playground is the standalone TUI demo; it can't combine with a\n // non-interactive run (either --ci or the experimental headless flag).\n if (argv.playground && (argv.ci || isHeadless(argv))) {\n throw new Error('--playground cannot be combined with a headless run.');\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 // ── The CI / headless division ───────────────────────────────────\n // --ci (dev/test only) and the experimental headless flag (the\n // published-build, non-interactive path; see @lib/headless-mode) both\n // request a non-interactive install, but route to dedicated entry points\n // — runHeadlessInstall vs runCIInstall (and below them runWizardHeadless\n // vs runWizardCI). Both share one pipeline today but are separate\n // functions end-to-end, so headless can diverge later without touching\n // the CI path or its callers.\n if (isHeadless(argv)) {\n const { runHeadlessInstall } = await import('./ci-install');\n return runHeadlessInstall(argv);\n }\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 { relative } from 'path';\nimport { safeReadFile, walkProjectFiles } from '@utils/bounded-fs';\n\nexport const POSTHOG_SDKS = new Set([\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n]);\n\nexport const STRIPE_SDKS = new Set([\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// At most this many matches retained, regardless of monorepo package count.\nconst MAX_PACKAGE_MATCHES = 500;\n\n/**\n * Find all package.json files under installDir via the shared bounded walk\n * (depth cap, ignored dirs, symlink-loop protection, per-dir entry cap).\n * Returns matches with detected SDKs.\n */\nexport function findPackageJsons(\n installDir: string,\n maxDepth = 3,\n): PackageMatch[] {\n const matches: PackageMatch[] = [];\n\n walkProjectFiles(\n installDir,\n (name, fullPath) => {\n if (name !== 'package.json' || matches.length >= MAX_PACKAGE_MATCHES) {\n return;\n }\n const content = safeReadFile(fullPath);\n if (content === null) return;\n try {\n const pkg = JSON.parse(content) 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.has(d));\n const stripeSdks = depNames.filter((d) => STRIPE_SDKS.has(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 },\n maxDepth,\n );\n\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 * Warehouse-source program step list.\n *\n * The detect step scans for warehouse-source signals. The skill install and\n * agent run live in the program runner (see agent-runner.ts). The skill drives\n * both in-CLI source creation and deep-link emission per detected source.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { RunPhase } from '@lib/wizard-session';\nimport { detectWarehousePrerequisites } from './detect.js';\n\nexport const WAREHOUSE_SOURCE_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting data sources',\n // Headless step: no screen. onReady scans installDir and writes the\n // detected sources (or a detectError) to frameworkContext for the\n // intro screen to render.\n onReady: (ctx) =>\n detectWarehousePrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'warehouse-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Data warehouse',\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","import type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { WAREHOUSE_SOURCE_PROGRAM } from './steps.js';\nimport {\n WAREHOUSE_ABORT_CASES,\n getDetectedWarehouseSources,\n} from './detect.js';\nimport { getContentBlocks } from './content/index.js';\n\n/**\n * Inject the detected sources (and their creation mode) into the prompt so the\n * skill knows what to set up. The *how* — in-CLI creation vs deep-link, field\n * collection, validation — lives in the skill, not here.\n */\nfunction buildPrompt(session: WizardSession): string {\n const sources = getDetectedWarehouseSources(session);\n if (sources.length === 0) {\n return 'Set up a data warehouse source for this project.';\n }\n\n const lines = sources.map(\n (s) =>\n `- ${s.label} (kind: ${s.kind}, mode: ${s.mode}) — ${s.matchedSignal}`,\n );\n\n return [\n 'The wizard detected the following data warehouse sources in this project:',\n ...lines,\n '',\n 'Each signal names the file it came from. Trust that path — the wizard ' +\n 'read it. To confirm a key is set, call `check_env_keys` with the key ' +\n 'names and no `filePath`; it scans every `.env` file in the project.',\n '',\n 'Set these up in PostHog following the skill instructions: create `in-cli` ' +\n 'sources directly via the PostHog MCP after collecting credentials; for ' +\n '`deep-link` sources, provide the user the pre-filled new-source URL.',\n 'Use the `kind` string exactly as printed above for `source_type` — ' +\n 'PostHog rejects the display label.',\n ].join('\\n');\n}\n\nexport const warehouseSourceConfig: ProgramConfig = {\n command: 'warehouse',\n description:\n 'Detect and connect a data warehouse source (Postgres, Stripe, …)',\n id: 'warehouse-source',\n skillId: 'data-warehouse-source-setup',\n steps: WAREHOUSE_SOURCE_PROGRAM,\n getContentBlocks,\n reportFile: 'posthog-warehouse-report.md',\n allowedTools: ['Agent'],\n run: (session: WizardSession): Promise<ProgramRun> =>\n Promise.resolve({\n skillId: 'data-warehouse-source-setup',\n integrationLabel: 'data-warehouse-source-setup',\n customPrompt: () => buildPrompt(session),\n successMessage: 'Data warehouse source connected!',\n reportFile: 'posthog-warehouse-report.md',\n docsUrl: 'https://posthog.com/docs/data-warehouse',\n spinnerMessage: 'Connecting your data source...',\n estimatedDurationMinutes: 5,\n abortCases: WAREHOUSE_ABORT_CASES,\n }),\n requires: ['posthog-integration'],\n};\n\nexport { WAREHOUSE_SOURCE_PROGRAM } from './steps.js';\nexport {\n detectWarehousePrerequisites,\n getDetectedWarehouseSources,\n DETECTED_WAREHOUSE_SOURCES_KEY,\n WAREHOUSE_ABORT_CASES,\n type WarehouseDetectError,\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';\nimport { ErrorCodes } from '@lib/errors';\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 errorCode: ErrorCodes.DetectNoPosthogSdk,\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 path from 'path';\nimport { writeJsonAtomic } from '@utils/atomic-ledger';\nimport { logToFile } from '@utils/debug';\nimport { AUDIT_CHECKS_FILE, type AuditCheck } from './types.js';\n\n/**\n * The 10 source-tree checks the audit runs, plus one row for the PostHog-side\n * sweep and two workflow rows at the end (so the skill's\n * `audit_resolve_checks` calls for `write-report` and `upload-notebook`\n * succeed — the skill writes the report to disk, then mirrors it into a\n * PostHog notebook as its final step).\n *\n * `posthog-side-findings` is a sweep row, not a rule: the skill reads what\n * PostHog itself already computed for this project (error-tracking\n * recommendations, health issues) and appends one row per open finding via\n * `audit_add_checks`. That's why the seed can't enumerate them — the list is\n * whatever the project's data says today, and it grows as PostHog ships new\n * checks, with no wizard release needed.\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: 'live-data-findings',\n // Area is capped at COL_AREA_WIDTH (18) in the checks viewer and never\n // flexes, so it has to fit. Labels get the flexed column.\n area: 'Live Data',\n label: 'Open findings in PostHog',\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 writeJsonAtomic(target, checks);\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 { headlessOption, regionOption } from '@lib/headless-mode';\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) => {\n const cloudUrl = credentials.host.appHost;\n const continueUrl = sess.signup\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: session.dashboardUrl ?? undefined,\n notebookUrl: session.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 // The experimental headless flag — declared on `audit` (and basic\n // integration) rather than globally. mergeCommandOptions lands it on the\n // `wizard audit` command; dispatchProgram routes it to runWizardHeadless.\n cliOptions: { ...headlessOption, ...regionOption },\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 { 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\n// SETUP_REPORT_FILE is also re-exported for backward compat with existing\n// imports from `@lib/programs/events-audit`. EVENT_INVENTORY_FILE and\n// EVENT_INVENTORY_PART_PATTERN are only used by yara-hooks, which imports\n// them directly from `./constants` — no re-export needed.\nimport { SETUP_REPORT_FILE } from './constants.js';\nexport { SETUP_REPORT_FILE };\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.apiHost}\n`,\n\n buildOutroData: (sess, credentials) => {\n const cloudUrl = credentials.host.appHost;\n const continueUrl = sess.signup\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 { ErrorCodes } from '@lib/errors';\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 errorCode: ErrorCodes.AuthMissingScope,\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 errorCode: ErrorCodes.DetectNoPosthogSdk,\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>{' AI observability '}</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>AI observability</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 { readdirSync, existsSync, statSync } from 'fs';\nimport { join, relative } from 'path';\nimport {\n IGNORED_DIRS,\n MAX_DIR_ENTRIES,\n MAX_WALK_FILES,\n safeReadFile,\n} from '@utils/bounded-fs';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { ErrorCodes } from '@lib/errors';\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 | 'go'\n | 'rust';\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 go: 'Go',\n rust: 'Rust',\n};\n\n/**\n * Variants the wizard can wire up source-map upload for automatically. Go and\n * Rust upload native debug symbols (`posthog-cli symbol-sets upload`) instead\n * of source maps, but the wiring is the same shape.\n *\n * Invariant: every variant listed here must have a published\n * `error-tracking-upload-source-maps-<variant>` skill in context-mill —\n * STEP 2 of the run installs that exact id, so an entry without a shipped\n * skill fails every run for that stack.\n */\nexport const AUTOMATABLE_VARIANTS: readonly SkillVariant[] = [\n 'android',\n 'ios',\n 'react-native',\n 'flutter',\n 'go',\n 'rust',\n 'web',\n 'nextjs',\n 'node',\n 'react',\n 'angular',\n 'nuxt',\n 'vite',\n 'webpack',\n 'rollup',\n];\n\n/**\n * Variants the wizard pre-installs a machine-global `posthog-cli` for — their\n * build shells out to it with no npx / local-dep fallback. Web JS variants stay\n * out. React Native counts as native here — its Xcode build phases and Gradle\n * tasks invoke the global CLI. Flutter counts too despite emitting plain\n * `.js.map` files: a Flutter project has no `package.json`, so there is no npx\n * or local dependency to fall back to when the post-build step invokes the CLI.\n */\nexport const VARIANTS_REQUIRING_POSTHOG_CLI: ReadonlySet<SkillVariant> =\n new Set(['ios', 'android', 'react-native', 'flutter', 'go', 'rust']);\n\n/**\n * Automatable variants whose SDK the wizard's default flow cannot install —\n * remediation for a missing SDK is a manual install (posthog-go /\n * posthog-rs), not `npx @posthog/wizard`. Drives the missing-SDK copy in the\n * picker and the classifier.\n */\nexport const MANUAL_SDK_INSTALL: Partial<Record<SkillVariant, string>> = {\n go: 'add the posthog-go module first',\n rust: 'add the posthog-rs crate first',\n};\n\nexport const MANUAL_SDK_VARIANTS: readonly SkillVariant[] = Object.keys(\n MANUAL_SDK_INSTALL,\n) as SkillVariant[];\n\n/** Dependency string that identifies the Rust SDK in Cargo.toml. */\nexport const RUST_SDK_CRATE = 'posthog-rs';\n\n/** Module path that identifies the Go SDK in go.mod. */\nexport const GO_SDK_MODULE = 'github.com/posthog/posthog-go';\n\nconst POSTHOG_SDKS = new Set([\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n]);\n\nconst GRADLE_FILES = new Set([\n 'build.gradle',\n 'build.gradle.kts',\n 'settings.gradle',\n 'settings.gradle.kts',\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 errorCode: ErrorCodes.DetectNoPosthogSdk,\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 '(for Go and Rust, add posthog-go / posthog-rs by hand first — the ' +\n 'wizard cannot install the SDK for those stacks yet).',\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 match: /^bare react native not supported$/i,\n errorCode: ErrorCodes.DetectUnsupportedPlatform,\n message: 'Bare React Native is not supported',\n body:\n 'Source-map upload for React Native requires Expo, and this project ' +\n 'has no `expo` package. Bare React Native builds cannot inject the ' +\n 'chunk IDs PostHog needs to resolve stack traces.',\n docsUrl:\n 'https://posthog.com/docs/error-tracking/upload-source-maps/react-native',\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 // Explicit stack — no call-stack recursion.\n const stack: Array<{ dir: string; depth: number }> = [\n { dir: installDir, depth: 0 },\n ];\n\n while (stack.length > 0 && signals.scannedFileCount < MAX_WALK_FILES) {\n const { dir, depth } = stack.pop()!;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n continue;\n }\n // A directory contributes at most MAX_DIR_ENTRIES entries.\n if (entries.length > MAX_DIR_ENTRIES) entries.length = MAX_DIR_ENTRIES;\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 const content = safeReadFile(fullPath);\n if (content === null) continue;\n try {\n const pkg = JSON.parse(content) 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 (GRADLE_FILES.has(entry.name)) {\n signals.hasGradle = true;\n }\n } else if (entry.isDirectory()) {\n if (entry.name.endsWith('.xcodeproj')) {\n signals.hasXcodeProject = true;\n } else if (depth < maxDepth) {\n stack.push({ dir: fullPath, depth: depth + 1 });\n }\n }\n }\n }\n\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 // Set by the agentic picker once the user chooses a project to instrument.\n selectedVariant: 'sourceMapsSelectedVariant',\n selectedDisplayName: 'sourceMapsSelectedDisplayName',\n selectedPath: 'sourceMapsSelectedPath',\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 // The legacy filesystem detector does not automate native platforms. The\n // live source-map picker uses detectSourceMapsProjects instead.\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 * Flow: a static intro (no detection yet) → login → an agentic detect+pick\n * screen that scans the repo on Haiku and lets the user choose a project →\n * agent run → outro. Detection runs after auth because the detection agent\n * needs credentials.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { RunPhase } from '@lib/wizard-session';\nimport { SOURCE_MAPS_CONTEXT_KEYS } from './detect.js';\n\nfunction projectSelected(session: WizardSession): boolean {\n return (\n session.frameworkContext[SOURCE_MAPS_CONTEXT_KEYS.selectedVariant] != null\n );\n}\n\nexport const ERROR_TRACKING_UPLOAD_SOURCE_MAPS_PROGRAM: ProgramStep[] = [\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'source-maps-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'detect',\n label: 'Detecting projects',\n // The Haiku agent scans the repo, surfaces an instrumentable / not-yet map,\n // and the user picks the project to wire up. Advances once a project is\n // chosen (its variant is written to frameworkContext). The gate lets the\n // agent runner park after auth until the pick lands, so the run prompt sees\n // the chosen variant.\n screenId: 'source-maps-detect',\n isComplete: projectSelected,\n gate: projectSelected,\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 /** Project to instrument, relative to the wizard working directory (\".\" or undefined = root). */\n projectPath?: string;\n projectId: number;\n host: string;\n settingsUrl: string;\n uiHost: string;\n /** Hand-off report the agent writes in STEP 9; the outro points the user at it. */\n reportFile: 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 projectPath,\n projectId,\n host,\n settingsUrl,\n uiHost,\n reportFile,\n } = params;\n const platformLabel = displayName ?? variant;\n const inSubproject = projectPath != null && projectPath !== '.';\n const projectLine = inSubproject\n ? `- Project directory (relative to the wizard's working directory): ${projectPath}`\n : \"- Project directory: the wizard's working directory (even when it sits inside a larger git repo, this directory is the project root)\";\n const envFilePathGuidance = inSubproject\n ? `Tool filePaths are relative to the wizard's working directory, not the selected project directory. Treat the skill's env path as relative to the selected project and prefix it with \\`${projectPath}/\\` when calling the tools: for example, pass \\`${projectPath}/.env\\`, not \\`.env\\` (which would target the wizard's working directory).${\n variant === 'rust'\n ? ` Cargo workspace exception: when the skill places the env file at the workspace root instead, pass the path of the ROOT manifest's directory relative to the wizard's working directory (e.g. \\`rust/.env\\` for a workspace root at \\`rust/\\`, or plain \\`.env\\` when the workspace root IS the working directory) — not the member path.`\n : ''\n }`\n : `Tool filePaths are relative to the wizard's working directory. For an env file at this project root, pass \\`.env\\`; never prefix it with this directory's path inside an ancestor repository.`;\n\n const credentialSteps = `STEP 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 with the key names and that file as filePath.\n It answers { status: \"present\" | \"missing\", foundIn: [paths] } per key —\n names and paths only, never values, so don't read the file directly.\n \"present\" means a real env file sets the key; a key found only in a\n committed template (.env.example and friends) reads as \"missing\",\n because a template documents a key rather than setting it.\n - Env tool path rule: ${envFilePathGuidance}\n - Then call set_env_values, passing the STEP 1 secretRef as a value\n object, not a literal string. Take the three variable NAMES from the\n skill's per-uploader list in \"Write credentials to the env file\" — they\n differ by uploader, and only the shape below is fixed:\n values: {\n \"<key var for the uploader you wired>\": { secretRef: \"<the ref from STEP 1>\" },\n \"<project id var>\": \"${projectId}\",\n \"<host var>\": \"${uiHost}\"\n }\n Write that one set only. Do not also write another uploader's variables\n as a fallback — a credential nothing reads is an unused secret sitting\n in the user's env file.\n The wizard resolves the ref locally before writing, so you never see the\n key value.`;\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${projectLine}\n- Personal API keys settings page: ${settingsUrl}\n\nAll file changes, build/run commands, and config edits target the project directory above${\n inSubproject\n ? ` — this is a monorepo, so scope your work to \\`${projectPath}\\` and do not touch other packages`\n : ''\n }.${\n variant === 'rust' && inSubproject\n ? `\nCargo workspace exception: if the selected project is a member of a Cargo\nworkspace (resolve the root with \\`cargo locate-project --workspace\n--message-format plain\\`), the workspace root's Cargo.toml (for \\`[profile.*]\\`\nedits), the workspace-level \\`target/\\` directory, and a \\`.env\\` next to the\nroot manifest are IN SCOPE — treat them as part of the selected project, and\nfollow the skill's workspace guidance for which paths to use. Every other\npackage stays off-limits.`\n : ''\n }\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 ${\n AgentSignals.ERROR_RESOURCE_MISSING\n } 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\n${credentialSteps}\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 build-and-run flow (and the exact\n button label / route) into the prompt as literal, copy-pasteable\n numbered steps:\n - Steps 1-2: the production build, then launching the app and\n triggering the test affordance. Source them from STEP 6 and the\n skill's \"Test the local setup\" step — when the skill gives the\n platform's test flow as verbatim steps (IDE-driven platforms like\n Xcode do), use its wording and do NOT invent CLI build commands,\n debugger steps, or relaunch steps it doesn't state. Quote CLI\n commands verbatim. When build and run are one action (an IDE Run),\n fold them into step 1 and make step 2 just triggering the affordance.\n - The last step is always the Error Tracking check, exactly as in the\n template.\n Separate each numbered step with \\\\n\\\\n so the TUI renders them as\n distinct lines:\n {\n id: \"test-done\",\n prompt: \"1) <production build step — it uploads source maps and builds the app with the test affordance>\\\\n\\\\n2) <run step>, 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. Write the hand-off to\n \\`${reportFile}\\` at the WIZARD'S WORKING DIRECTORY — pass exactly\n \\`${reportFile}\\` as the file path, never prefixed with the selected\n project directory; this file is the one exception to the project-scope\n rule above. Cover: the files you changed (paths only), the exact build\n and upload commands, every CI secret the user still has to create, and\n how to verify the upload — then give the same summary in chat. Never\n write secret values into the report, only variable names. The success\n screen points the user at this file, so do not skip it. The Symbol sets page for this project — where the user\n 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 { spawnSync } from 'node:child_process';\nimport * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\n\nimport { debug } from '@utils/debug';\n\n/**\n * A coding agent whose global instructions file the PostHog CLI steering\n * snippet can be installed into. Project-level installs are handled by\n * `posthog-cli api agents-md install` in the target repo; this step only\n * manages the per-user (global) instruction files.\n */\nexport interface CliSteeringTarget {\n id: string;\n name: string;\n /** Global agent instructions file the steering snippet is written to. */\n instructionsPath(): string;\n /** Whether the agent appears to be installed on this machine. */\n isDetected(): boolean;\n}\n\nconst dirExists = (...segments: string[]): boolean => {\n try {\n return fs.existsSync(path.join(os.homedir(), ...segments));\n } catch {\n return false;\n }\n};\n\nexport const CLI_STEERING_TARGETS: readonly CliSteeringTarget[] = [\n {\n id: 'claude-code',\n name: 'Claude Code',\n instructionsPath: () => path.join(os.homedir(), '.claude', 'CLAUDE.md'),\n isDetected: () => dirExists('.claude'),\n },\n {\n id: 'codex',\n name: 'Codex',\n instructionsPath: () => path.join(os.homedir(), '.codex', 'AGENTS.md'),\n isDetected: () => dirExists('.codex'),\n },\n {\n id: 'gemini',\n name: 'Gemini CLI',\n instructionsPath: () => path.join(os.homedir(), '.gemini', 'GEMINI.md'),\n isDetected: () => dirExists('.gemini'),\n },\n];\n\nexport function findTarget(id: string): CliSteeringTarget | undefined {\n return CLI_STEERING_TARGETS.find((target) => target.id === id);\n}\n\nexport function detectTargets(): CliSteeringTarget[] {\n return CLI_STEERING_TARGETS.filter((target) => target.isDetected());\n}\n\nexport interface SteeringInstallResult {\n success: boolean;\n filePath: string;\n error?: string;\n}\n\nexport interface CliInstallResult {\n success: boolean;\n error?: string;\n /**\n * The underlying failure as an Error, for callers that report to error\n * tracking. Carries the real spawn error (with its stack) when npm couldn't\n * launch; a synthesized Error for a non-zero exit. Set whenever success is\n * false.\n */\n errorObject?: Error;\n}\n\nconst spawnOptions = {\n encoding: 'utf-8' as const,\n // npm/posthog-cli are npm.cmd/posthog-cli.cmd on Windows; spawnSync only\n // resolves them through a shell.\n shell: process.platform === 'win32',\n};\n\n/**\n * Install or update the PostHog CLI in the user's environment. `npm install\n * --global @posthog/cli@latest` covers both first-time installs and upgrades\n * for existing npm-installed CLIs.\n */\nexport function installOrUpdatePostHogCli(): CliInstallResult {\n const args = ['install', '--global', '@posthog/cli@latest'];\n debug(`Running npm ${args.join(' ')}`);\n\n const result = spawnSync('npm', args, spawnOptions);\n\n if (result.error) {\n return {\n success: false,\n error: `Failed to run npm: ${result.error.message}. Is Node.js installed?`,\n errorObject: result.error,\n };\n }\n if (result.status !== 0) {\n const detail = (result.stderr || result.stdout || '').trim();\n const message =\n detail ||\n `npm install --global @posthog/cli@latest exited with status ${\n result.status ?? 'unknown'\n }`;\n return {\n success: false,\n error: message,\n errorObject: new Error(message),\n };\n }\n return { success: true };\n}\n\n/**\n * Delegate the actual write to the installed `posthog-cli api agents-md\n * install`. The steering snippet lives in the CLI (its single source of truth),\n * so the command should run only after `installOrUpdatePostHogCli` refreshes\n * the CLI to the latest release.\n */\nexport function installSteeringSnippet(\n filePath: string,\n): SteeringInstallResult {\n const args = ['api', 'agents-md', 'install', '--path', filePath];\n debug(`Running posthog-cli ${args.join(' ')}`);\n\n const result = spawnSync('posthog-cli', args, {\n ...spawnOptions,\n env: { ...process.env, POSTHOG_CLI_EXPERIMENTAL_API: '1' },\n });\n\n if (result.error) {\n return {\n success: false,\n filePath,\n error: `Failed to run posthog-cli: ${result.error.message}. Make sure npm's global bin directory is on your PATH.`,\n };\n }\n if (result.status !== 0) {\n const detail = (result.stderr || result.stdout || '').trim();\n return {\n success: false,\n filePath,\n error:\n detail ||\n `posthog-cli exited with status ${result.status ?? 'unknown'}`,\n };\n }\n return { success: true, filePath };\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 VARIANTS_REQUIRING_POSTHOG_CLI,\n type SkillVariant,\n} from './detect.js';\nimport { getContentBlocks } from './content/index.js';\nimport { getUI } from '@ui';\nimport { installOrUpdatePostHogCli } from '@steps/install-cli-steering';\nimport { analytics } from '@utils/analytics';\n\nconst REPORT_FILE = 'posthog-source-maps-report.md';\nconst DOCS_URL = 'https://posthog.com/docs/error-tracking/upload-source-maps';\n\nlet postHogCliInstallAttempted = false;\n\n/**\n * Pre-install posthog-cli for variants that need a machine-global copy\n * (`VARIANTS_REQUIRING_POSTHOG_CLI`). The agent can't — warlock blocks\n * `npm install -g` — so the wizard does it in-process. Warn, don't fail.\n */\nfunction ensurePostHogCli(variant: SkillVariant): void {\n if (postHogCliInstallAttempted) return;\n postHogCliInstallAttempted = true;\n\n const result = installOrUpdatePostHogCli();\n if (!result.success) {\n analytics.wizardCapture('source maps posthog-cli preinstall failed', {\n variant,\n error: String(result.error).slice(0, 500),\n });\n analytics.captureException(\n result.errorObject ??\n new Error(`posthog-cli pre-install failed: ${result.error}`),\n { source: 'source_maps_cli_preinstall', variant },\n );\n getUI().log.warn(\n `Could not pre-install posthog-cli (${result.error}). Your release build ` +\n `will fail to upload debug symbols until it's installed: npm install -g @posthog/cli@latest`,\n );\n }\n}\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 // Read the picked project LIVE at prompt-build time, not here: the picker\n // screen runs AFTER this run config is resolved (post-auth), and the store\n // forks the session reference, so the `session` passed in never sees the\n // choice. getUI().getFrameworkContext reads the live store session.\n const readSelection = () => {\n const variant = getUI().getFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.selectedVariant,\n ) as SkillVariant | undefined;\n const displayName = getUI().getFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.selectedDisplayName,\n ) as string | undefined;\n const projectPath = getUI().getFrameworkContext(\n SOURCE_MAPS_CONTEXT_KEYS.selectedPath,\n ) as string | undefined;\n const skillId = variant\n ? `error-tracking-upload-source-maps-${variant}`\n : undefined;\n return { variant, displayName, projectPath, skillId };\n };\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 const { variant, displayName, projectPath, skillId } = readSelection();\n if (!skillId || !variant) {\n // No project was selected — abort with a structured signal so the\n // runner renders a friendly outro.\n return SOURCE_MAPS_DETECTION_FAILED_PROMPT;\n }\n\n if (VARIANTS_REQUIRING_POSTHOG_CLI.has(variant))\n ensurePostHogCli(variant);\n\n const uiHost = ctx.host.appHost.replace(/\\/$/, '');\n\n return buildSourceMapsUploadPrompt({\n displayName,\n variant,\n skillId,\n projectPath,\n projectId: ctx.projectId,\n host: ctx.host.apiHost,\n settingsUrl: `${uiHost}/project/${ctx.projectId}/settings/user-api-keys`,\n uiHost,\n reportFile: REPORT_FILE,\n });\n },\n\n postRun: () => {\n // Stash a hint for the outro about what variant we shipped.\n const { variant } = readSelection();\n if (variant) {\n getUI().setFrameworkContext('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 MANUAL_SDK_VARIANTS,\n type SkillVariant,\n type SourceMapsDetectError,\n} from './detect.js';\n","/**\n * Self-driving prerequisite detection + abort vocabulary.\n *\n * The only thing worth verifying before auth is local and cheap: that\n * `session.installDir` is a real, readable directory. We deliberately do\n * NOT require the base posthog-integration report to be present — it is a\n * report many users never commit, and `requires: ['posthog-integration']`\n * is metadata, not a hard runtime gate.\n *\n * Self-driving is now in OPEN beta — available to every team — so STEP 1\n * no longer probes the Signals API as an access gate; it completes\n * instantly so the run opens with a fast first checkmark. The\n * `self-driving is not available for this project` abort below is kept\n * only as a safety net: if the Signals API genuinely can't be reached\n * during the run (a hard error that is unexpected in open beta), the skill\n * emits it and the wizard renders a friendly \"try again\" screen — now with\n * open-beta wording, not the old closed, per-team \"join the beta\" copy. The\n * PostHog-side flags (`product-autonomy`, `signals-scout`) are unchanged by\n * the wizard-side \"self-driving\" rename.\n */\n\nimport {\n existsSync,\n statSync,\n readFileSync,\n readdirSync,\n type Dirent,\n} from 'fs';\nimport { join } from 'path';\nimport { analytics } from '@utils/analytics';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { AbortCase } from '@lib/agent/agent-runner';\nimport { ErrorCodes } from '@lib/errors';\nimport { detectWarehouseSources } from '@lib/warehouse-sources/detect';\nimport type { DetectedSource } from '@lib/warehouse-sources/types';\n\n/** frameworkContext key holding the deterministic PostHog-presence result. */\nexport const POSTHOG_PRESENT_KEY = 'postHogPresent';\n\n/**\n * frameworkContext key holding the repo-relative path of the project the user\n * picked on the integration-detect screen (\".\" for the repo root). The\n * integrate-run phase scopes its install dir to this so a monorepo integrates\n * into the chosen sub-app, not the root.\n */\nexport const SELF_DRIVING_INTEGRATE_PATH_KEY = 'selfDrivingIntegratePath';\n\n/** Self-driving's own detected-tools key — not the warehouse one, which the integration program reads. */\nexport const SELF_DRIVING_DETECTED_TOOLS_KEY = 'selfDrivingDetectedTools';\n\n/** Read the detected tools out of frameworkContext. */\nexport function getSelfDrivingDetectedTools(\n session: WizardSession,\n): DetectedSource[] {\n return (\n (session.frameworkContext[SELF_DRIVING_DETECTED_TOOLS_KEY] as\n | DetectedSource[]\n | undefined) ?? []\n );\n}\n\n// Matches `posthog` at a dependency boundary (line start, or after \"'/=:.@ or\n// whitespace): catches `com.posthog:posthog-android` and `@posthog/ai`, skips\n// substrings inside other words.\nconst POSTHOG_PACKAGE_RE = /(^|[\"'\\s/=:.@])posthog/im;\n\n// Manifests grepped for a posthog dependency. Distinct from PROJECT_MANIFESTS\n// in @lib/detection/agentic (project-root discovery); keep the two in sync\n// (a test asserts the shared ecosystem names appear in both). Exported for it.\nexport const POSTHOG_MANIFESTS = [\n 'package.json',\n 'requirements.txt',\n 'pyproject.toml',\n 'Pipfile',\n 'setup.py',\n 'Gemfile',\n 'go.mod',\n 'composer.json',\n 'pubspec.yaml',\n // Apple: SPM manifest, CocoaPods (+ lockfile), XcodeGen spec.\n 'Package.swift',\n 'Podfile',\n 'Podfile.lock',\n 'project.yml',\n // Android / JVM (libs.versions.toml holds gradle coordinates).\n 'build.gradle',\n 'build.gradle.kts',\n 'gradle/libs.versions.toml',\n 'pom.xml',\n // Elixir / Rust.\n 'mix.exs',\n 'Cargo.toml',\n];\n\n// Named sub-app dirs always checked (ios/android: RN/Flutter native shells).\n// scanDirs unions these with a bounded depth-2 walk of the install dir.\nconst POSTHOG_DIRS = [\n '.',\n 'app',\n 'frontend',\n 'backend',\n 'ios',\n 'android',\n 'android/app',\n];\n\n// Heavy or vendored trees the shallow walk never descends into — they hold\n// dependencies, not a project's own manifest, and would false-positive on a\n// bundled posthog package.\nconst WALK_SKIP_DIRS = new Set([\n 'node_modules',\n 'Pods',\n 'Carthage',\n 'DerivedData',\n '.build',\n 'build',\n 'dist',\n 'out',\n '.next',\n 'coverage',\n 'vendor',\n '.venv',\n 'site-packages',\n 'target',\n '.git',\n]);\n\n// How deep below the install dir the shallow walk goes. 2 covers the common\n// monorepo shape (apps/<name>, packages/<name>) without a full tree walk.\nconst WALK_MAX_DEPTH = 2;\n\n/**\n * The install dir plus every directory within WALK_MAX_DEPTH levels (skipping\n * heavy/vendored trees and dotdirs), unioned with the explicit POSTHOG_DIRS. A\n * full shallow walk on top of the named dirs, so a monorepo's nested apps\n * (e.g. `apps/mobile`) are seen without hardcoding the path.\n */\nfunction scanDirs(installDir: string): string[] {\n const rels = new Set<string>(POSTHOG_DIRS);\n // Explicit stack — no call-stack recursion.\n const stack: Array<{ rel: string; depth: number }> = [{ rel: '.', depth: 0 }];\n while (stack.length > 0) {\n const { rel, depth } = stack.pop()!;\n rels.add(rel);\n if (depth >= WALK_MAX_DEPTH) continue;\n let entries: Dirent[];\n try {\n entries = readdirSync(join(installDir, rel), { withFileTypes: true });\n } catch {\n continue;\n }\n for (const e of entries) {\n if (!e.isDirectory()) continue;\n if (e.name.startsWith('.') || WALK_SKIP_DIRS.has(e.name)) continue;\n // .xcodeproj/.xcworkspace are inspected via projectFileHasPostHog at the\n // parent dir — descending into the wrapper finds nothing useful.\n if (e.name.endsWith('.xcodeproj') || e.name.endsWith('.xcworkspace')) {\n continue;\n }\n stack.push({\n rel: rel === '.' ? e.name : `${rel}/${e.name}`,\n depth: depth + 1,\n });\n }\n }\n return [...rels];\n}\n\n/**\n * True if a `*.xcodeproj/project.pbxproj` or `*.csproj`/`*.fsproj` in\n * `dirPath` references PostHog.\n */\nfunction projectFileHasPostHog(dirPath: string): boolean {\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch {\n return false;\n }\n for (const entry of entries) {\n const target = entry.endsWith('.xcodeproj')\n ? join(dirPath, entry, 'project.pbxproj')\n : entry.endsWith('.csproj') || entry.endsWith('.fsproj')\n ? join(dirPath, entry)\n : null;\n if (!target || !existsSync(target)) continue;\n try {\n if (POSTHOG_PACKAGE_RE.test(readFileSync(target, 'utf8'))) return true;\n } catch {\n /* unreadable — ignore */\n }\n }\n return false;\n}\n\n/**\n * Deterministic, offline check: does the project already have a PostHog SDK?\n * Scans the common dependency manifests at the install dir for a `posthog`\n * package — the same signal the agentic detector reports as `hasPostHog`, but\n * instant and credential-free. Drives whether self-driving asks to integrate\n * first (\"not found\") or proceeds straight to setup (\"found\").\n */\nexport function detectPostHogPresent(installDir: string): boolean {\n for (const dir of scanDirs(installDir)) {\n const dirPath = join(installDir, dir);\n for (const name of POSTHOG_MANIFESTS) {\n const path = join(dirPath, name);\n if (!existsSync(path)) continue;\n try {\n if (POSTHOG_PACKAGE_RE.test(readFileSync(path, 'utf8'))) return true;\n } catch {\n /* unreadable — ignore */\n }\n }\n // Variably-named project files (.xcodeproj, .csproj/.fsproj).\n if (projectFileHasPostHog(dirPath)) return true;\n }\n return false;\n}\n\n/**\n * Structured detection errors. The intro screen renders each kind into\n * JSX — keeps error data separate from presentation.\n */\nexport type SelfDrivingDetectError = {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n};\n\n/**\n * `[ABORT] <reason>` cases the self-driving skill can emit. The\n * reason strings are part of the skill contract — the context-mill\n * `self-driving-setup` skill emits these exact strings.\n */\n/** Headline shown when the run ends because GitHub was not connected. */\nexport const GITHUB_REQUIRED_MESSAGE = 'GitHub connection required';\n\n/** Body for {@link GITHUB_REQUIRED_MESSAGE}. Shared by the pre-run gate and the abort case. */\nexport const GITHUB_REQUIRED_BODY =\n 'Self-driving needs GitHub access to research issues in your code and ' +\n 'open fixes, so setup cannot finish without it. Nothing was changed. ' +\n 'When you are ready to install the PostHog GitHub App, run the wizard again.';\n\nexport const SELF_DRIVING_ABORT_CASES: AbortCase[] = [\n {\n // Skill emits: [ABORT] self-driving is not available for this project\n match: /^self-driving is not available for this project$/i,\n message: 'PostHog Self-driving is not available for this project',\n body:\n 'Self-driving is in open beta and available to every team, so this ' +\n 'is unexpected — the PostHog Signals API could not be reached for ' +\n 'this project. Nothing was changed. Try again in a moment, and if it ' +\n 'keeps happening reach out to wizard@posthog.com.',\n },\n {\n // Retained as a safety net: the GitHub gate now runs before the agent, but\n // a cached older skill can still emit this mid-run.\n match: /^github connection declined$/i,\n message: GITHUB_REQUIRED_MESSAGE,\n body: GITHUB_REQUIRED_BODY,\n },\n {\n // Skill emits: [ABORT] requires-interactive-mode\n match: /^requires-interactive-mode$/i,\n errorCode: ErrorCodes.CliInteractiveRequired,\n message: 'Interactive terminal required',\n body:\n 'Self-driving setup asks questions along the way (GitHub and ' +\n 'issue trackers), so it needs an interactive terminal. Run ' +\n 'the wizard outside CI / non-interactive mode.',\n },\n {\n // The wizard_ask tool's own error texts (non-interactive host, ask cap\n // reached) instruct the agent to emit this reason — cover it so those\n // paths render a friendly screen instead of the generic abort outro.\n match: /^requirements-incomplete$/i,\n message: 'Setup needs your input',\n body:\n 'The wizard could not collect the answers this setup needs (the ' +\n 'environment was non-interactive, or the question budget ran out). ' +\n 'Nothing was left half-configured. Run the wizard again in an ' +\n 'interactive terminal.',\n },\n];\n\n/**\n * Verify `session.installDir` is a readable directory. Writes a\n * `SelfDrivingDetectError` to frameworkContext on failure — the intro\n * screen renders it and blocks.\n */\nexport function detectSelfDrivingPrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: SelfDrivingDetectError) =>\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 // Deterministic PostHog-presence check — drives the integration-check\n // screen: found → skip straight to self-driving; not found → ask to set up\n // PostHog first.\n setFrameworkContext(POSTHOG_PRESENT_KEY, detectPostHogPresent(installDir));\n\n detectConnectedTools(installDir, setFrameworkContext);\n}\n\n/** Step 5's ask options intersected with `SOURCE_DETECTORS` — reconcile when the skill's catalog grows. */\nexport const SELF_DRIVING_TOOL_KINDS: ReadonlySet<string> = new Set([\n // Issue trackers / code hosts\n 'Github',\n 'GitLab',\n 'Gitea',\n 'Linear',\n 'Jira',\n 'Shortcut',\n // Error tracking\n 'Sentry',\n 'Rollbar',\n 'Bugsnag',\n 'Honeybadger',\n 'Raygun',\n // Support desks\n 'Zendesk',\n 'Freshdesk',\n 'Front',\n 'Gorgias',\n 'Kustomer',\n 'Plain',\n // Security scanners\n 'Snyk',\n // Product feedback\n 'Canny',\n 'Productboard',\n // Search analytics\n 'GoogleSearchConsole',\n]);\n\n/** Scan for inbox-connectable tools so STEP 5 can surface them first. Best-effort — never blocks detection. */\nfunction detectConnectedTools(\n installDir: string,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n try {\n const tools = detectWarehouseSources(installDir).filter((s) =>\n SELF_DRIVING_TOOL_KINDS.has(s.kind),\n );\n\n // Tagged even at zero, so \"found nothing\" is distinguishable from \"never ran\".\n analytics.setTag('connected_tools_detected_count', tools.length);\n if (tools.length === 0) return;\n\n analytics.setTag(\n 'connected_tools_detected',\n tools.map((s) => s.kind).join(','),\n );\n setFrameworkContext(SELF_DRIVING_DETECTED_TOOLS_KEY, tools);\n } catch (error) {\n // -1, not absent, so a failed scan stays distinguishable from one that never ran.\n analytics.setTag('connected_tools_detected_count', -1);\n analytics.captureException(\n error instanceof Error ? error : new Error(String(error)),\n { step: 'detectConnectedTools' },\n );\n }\n}\n","/**\n * Agentic (Haiku) detection for self-driving's integration phase.\n *\n * Mirrors source-maps: the integration-detect screen runs `detectSelfDriving-\n * IntegrationProjects` (the shared integration scan from\n * @lib/detection/project-scope), shows a project map, and the user picks one.\n * This file maps the result back to `Integration`s and classifies each project\n * as instrumentable (a framework the wizard supports that doesn't already have\n * PostHog). The screen writes the choice to the session; `prepSelfDriving-\n * Integration` then gathers the chosen project's framework context before the\n * integration agent runs (the runner scopes the install dir).\n */\n\nimport type {\n AgenticDetectionReport,\n DetectEvent,\n} from '@lib/detection/agentic';\nimport { detectIntegrationProjects } from '@lib/detection/project-scope';\nimport { gatherFrameworkContext } from '@lib/detection/index';\nimport { Integration } from '@lib/constants';\nimport type { WizardSession } from '@lib/wizard-session';\n\nexport type { DetectEvent };\n\nconst INTEGRATION_IDS = new Set<string>(Object.values(Integration));\n\n/** One project, classified for a PostHog SDK integration. */\nexport type IntegrationProject = {\n /** Path relative to the repo root (\".\" for the root). */\n path: string;\n /** Human-readable framework the agent detected (e.g. \"Next.js\"). */\n framework: string;\n /** A supported framework when it matches one, else null. */\n integration: Integration | null;\n /** Whether a PostHog SDK is already installed in this project. */\n hasPostHog: boolean;\n /** integration != null && !hasPostHog — PostHog can be set up here. */\n instrumentable: boolean;\n /** hasPostHog: skip integration and continue straight to Self-driving. */\n continuable: boolean;\n /** Why the project can't be set up (only when !instrumentable). */\n reason?: string;\n};\n\nexport type IntegrationDetectionReport = {\n repoType: 'monorepo' | 'single';\n projects: IntegrationProject[];\n};\n\nfunction classify(\n integration: Integration | null,\n hasPostHog: boolean,\n): { instrumentable: boolean; reason?: string } {\n if (integration == null) {\n return {\n instrumentable: false,\n reason: 'Not a framework the wizard can set up yet',\n };\n }\n if (hasPostHog) {\n return { instrumentable: false, reason: 'Already has the PostHog SDK' };\n }\n return { instrumentable: true };\n}\n\n/** Map a detection report into classified projects (exported for tests). */\nexport function toIntegrationReport(\n report: AgenticDetectionReport,\n): IntegrationDetectionReport {\n return {\n repoType: report.repoType,\n projects: report.projects.map((p) => {\n const integration =\n p.targetId && INTEGRATION_IDS.has(p.targetId)\n ? (p.targetId as Integration)\n : null;\n return {\n path: p.path,\n framework: p.framework,\n integration,\n hasPostHog: p.hasPostHog,\n continuable: p.hasPostHog,\n ...classify(integration, p.hasPostHog),\n };\n }),\n };\n}\n\n/** Run the Haiku detector over the repo and classify projects for integration. */\nexport async function detectSelfDrivingIntegrationProjects(\n session: WizardSession,\n onEvent?: DetectEvent,\n): Promise<IntegrationDetectionReport> {\n const report = await detectIntegrationProjects(session, {\n programId: 'self-driving',\n onEvent,\n });\n return toIntegrationReport(report);\n}\n\n/**\n * Prepare the integration phase after the user picked a project on the\n * integration-detect screen (which set `session.integration`, `frameworkConfig`,\n * and the chosen path). Scopes `installDir` to the chosen project — so a\n * monorepo integrates into the picked sub-app — and gathers that project's\n * framework context, mirroring posthog-integration's `ciPreRun`. Used as the\n * integrate-run step's `onRunPrep`.\n */\nexport async function prepSelfDrivingIntegration(\n session: WizardSession,\n): Promise<void> {\n // `session` is the phase's derived session — its installDir is already the\n // picked project (the integrate-run step's `targetDir`), so just gather that\n // project's framework context.\n const frameworkConfig = session.frameworkConfig;\n if (!frameworkConfig) return;\n\n const context = await gatherFrameworkContext(frameworkConfig, {\n installDir: session.installDir,\n debug: session.debug,\n signup: session.signup,\n ci: session.ci,\n benchmark: session.benchmark,\n yaraReport: session.yaraReport,\n });\n for (const [key, value] of Object.entries(context)) {\n if (!(key in session.frameworkContext)) {\n session.frameworkContext[key] = value;\n }\n }\n}\n","/**\n * Self-driving program step list.\n *\n * detect → intro → integration-check → health-check → auth → integrate-detect →\n * integrate-run → self-driving-handoff → self-driving-github → run → outro. A deterministic check in\n * `detect` decides whether PostHog is already in the project: found → the\n * integration screens are skipped and the integrate-run phase never shows; not\n * found → integration-check reports it and the only action sets up PostHog.\n * After auth, `integrate-detect` runs the Haiku detector and has the user pick\n * which project to set PostHog up in (a monorepo can have several);\n * `integrate-run` then runs the real integration program's agent (its own task\n * list) in that project. `self-driving-handoff` then bridges to Self-driving\n * (\"PostHog is installed — now set up Self-driving\"), then `self-driving-github`\n * gates on the GitHub App connection the run cannot proceed without. No keep-skills step: the setup skill is transient, so postRun removes it.\n */\n\nimport type { ProgramStep } from '@lib/programs/program-step';\nimport { resolveProjectDir } from '@lib/detection/agentic';\nimport { RunPhase, type WizardSession } from '@lib/wizard-session';\nimport { HEALTH_CHECK_STEP } from '@lib/programs/shared/health-check-step';\nimport { integrationRunStep } from '@lib/programs/posthog-integration/index';\nimport {\n detectSelfDrivingPrerequisites,\n POSTHOG_PRESENT_KEY,\n SELF_DRIVING_INTEGRATE_PATH_KEY,\n} from './detect.js';\nimport { prepSelfDrivingIntegration } from './detect-agentic.js';\n\n/** True once detection found PostHog already present in the project. */\nconst postHogPresent = (session: WizardSession): boolean =>\n session.frameworkContext[POSTHOG_PRESENT_KEY] === true;\n\n/** Absolute dir to integrate into: the picked sub-app (LLM output — the shared resolver clamps escapes), else the repo root. */\nconst integrationDir = (session: WizardSession): string =>\n resolveProjectDir(\n session.installDir,\n session.frameworkContext[SELF_DRIVING_INTEGRATE_PATH_KEY],\n );\n\nexport const SELF_DRIVING_PROGRAM: ProgramStep[] = [\n {\n id: 'detect',\n label: 'Detecting prerequisites',\n // Headless: validates the install dir and runs the deterministic\n // PostHog-presence check (writes frameworkContext.postHogPresent).\n onReady: (ctx) =>\n detectSelfDrivingPrerequisites(ctx.session, ctx.setFrameworkContext),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screenId: 'self-driving-intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n // Shown only when PostHog wasn't detected and the decision is still open:\n // \"Set up PostHog first?\". On \"yes\" the integrate-run phase runs the\n // integration. When PostHog is already present (or `--integrate` pre-set\n // it), this is skipped. The gate lets run-wizard settle the decision —\n // resolved immediately when no question is needed.\n id: 'integration-check',\n label: 'Integration',\n screenId: 'self-driving-integration-check',\n show: (session) => !postHogPresent(session) && session.integrate === null,\n isComplete: (session) =>\n postHogPresent(session) || session.integrate !== null,\n gate: (session) => postHogPresent(session) || session.integrate !== null,\n },\n HEALTH_CHECK_STEP,\n {\n id: 'auth',\n label: 'Authentication',\n screenId: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n // After auth, before the integration runs: the detector scans the repo and\n // the user picks which project to set PostHog up in — a single project or\n // the repo root is still a one-item confirm. The pick writes the framework +\n // path to the session. Shown only while integrating and undecided; complete\n // once a project is picked (the orchestrator waits on this live).\n id: 'integrate-detect',\n label: 'Detecting',\n screenId: 'self-driving-integration-detect',\n show: (session) =>\n session.integrate === true && session.integration == null,\n // Complete on a picked project OR \"continue with existing\"\n // (integrate=false); without the latter the orchestrator's waitUntil hangs.\n isComplete: (session) =>\n session.integration != null || session.integrate === false,\n },\n {\n // The integration's own run step, imported and composed here: it runs the\n // integration agent (its prompt, tools, task list) in the picked project's\n // dir. Shown only when integrating; prep gathers that project's framework\n // context. Completion is tracked via `completedRuns`, separate from the\n // Self-driving run's `runPhase`.\n ...integrationRunStep,\n id: 'integrate-run',\n onRunPrep: prepSelfDrivingIntegration,\n targetDir: integrationDir,\n show: (session) => session.integrate === true,\n isComplete: (session) => session.completedRuns.includes('integrate-run'),\n },\n {\n // Handoff after the integration run: \"PostHog is installed — now set up\n // Self-driving\". Only in the integrate path; the already-has-PostHog path\n // skips it. Complete once acknowledged (the orchestrator waits on this).\n id: 'self-driving-handoff',\n label: 'Ready',\n screenId: 'self-driving-handoff',\n show: (session) => session.integrate === true,\n isComplete: (session) => session.selfDrivingHandoffConfirmed,\n },\n {\n // Hard gate before the agent starts: Self-driving cannot research findings\n // or open fixes without repo access. Asking here rather than mid-run means\n // a user who steps away isn't read as declining, and a user who won't\n // connect hasn't paid for an agent start. Complete once GitHub is\n // connected, or once the user says they can't — which hides `run` below.\n id: 'self-driving-github',\n label: 'GitHub',\n screenId: 'self-driving-github',\n isComplete: (session) =>\n session.githubConnected === true || session.githubDeclined,\n gate: (session) =>\n session.githubConnected === true || session.githubDeclined,\n },\n {\n id: 'run',\n label: 'Self-driving',\n screenId: 'run',\n show: (session) => !session.githubDeclined,\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","import { AgentSignals } from '@lib/agent/agent-interface';\nimport type { PromptContext } from '@lib/agent/agent-runner';\nimport type { DetectedSource } from '@lib/warehouse-sources/types';\n\n/**\n * Render the deterministic codebase-tool scan for the prompt. STEP 4 and\n * STEP 5 read this instead of the agent doing its own flaky \"light scan\":\n * enable the matching signal sources, and surface detected tools first in the\n * connected-tools ask rather than dumping the full ~500-source catalog. When\n * nothing is detected we still say so explicitly, so the agent falls back to\n * the skill's default ordering instead of inventing a scan.\n */\nfunction renderDetectedTools(sources: DetectedSource[]): string {\n if (sources.length === 0) {\n return `Tools detected in this codebase: none found by the dependency + env scan. Use the skill's default ordering for STEP 5.`;\n }\n\n const lines = sources.map(\n (s) => `- ${s.label} (source_type: ${s.kind}) — ${s.matchedSignal}`,\n );\n return [\n 'Tools detected in this codebase (deterministic dependency + env-key scan — this is evidence, not a guess):',\n ...lines,\n '',\n 'Use this list in STEP 4 (enable the matching signal sources) and STEP 5 ' +\n '(surface these detected tools first in the connected-tools ask, ahead ' +\n 'of the SaaS basics and the \"others\" option), exactly as the skill ' +\n 'describes. Never enable or pre-select a tool the user has not confirmed.',\n ].join('\\n');\n}\n\n/**\n * Build the self-driving run prompt. The installed\n * `self-driving-setup` skill is the source of truth for the HOW of\n * every step (which MCP tools to call, which sources/scouts apply, how\n * to verify); this prompt carries the order, the wizard-specific\n * mechanics (wizard_ask, abort signals), and the project URLs.\n *\n * `detectedSources` is the deterministic codebase scan (from the detect step);\n * it drives STEP 4/STEP 5 tool prioritisation. Empty is fine — the block then\n * tells the agent to use the skill's default ordering.\n *\n * Integration (when the project has no PostHog yet) runs as a separate phase\n * before this — the real integration program, with its own screens and task\n * list — so this prompt only covers the Self-driving steps.\n */\nexport function buildSelfDrivingPrompt(\n ctx: PromptContext,\n detectedSources: DetectedSource[] = [],\n): string {\n const uiHost = ctx.host.appHost.replace(/\\/$/, '');\n const projectBase = `${uiHost}/project/${ctx.projectId}`;\n const integrationsSettingsUrl = `${projectBase}/settings/environment-integrations`;\n const orgAiSettingsUrl = `${uiHost}/settings/organization#organization-ai-consent`;\n const newWarehouseSourceUrl = `${projectBase}/pipeline/new/source`;\n const inboxUrl = `${projectBase}/inbox`;\n const optIn = (value: boolean | null | undefined): string =>\n value === true ? 'ON' : value === false ? 'OFF' : 'unknown';\n const optIns = ctx.teamProductOptIns;\n\n return `You are setting up PostHog Self-driving for this project: you will enable the right signal sources, tune the scout troop, design custom scouts for what this product uniquely needs, put Replay Vision scanners on its key flows, and hand the user a configured inbox.\n\nProject URLs:\n- Integrations settings: ${integrationsSettingsUrl}\n- Organization AI settings: ${orgAiSettingsUrl}\n- New data warehouse source (Linear / Zendesk / GitHub issues / pganalyze): ${newWarehouseSourceUrl}\n- Self-driving inbox: ${inboxUrl}\n\nProject state read at auth time (PostHog project settings — authoritative\nfor whether a product is enabled, regardless of what this repo\ninstruments; products are often instrumented from other repos or the\nsnippet, so repo evidence may rule a product IN but never OUT):\n- Session replay recording: ${optIn(optIns?.sessionReplay)}\n- Exception autocapture (error tracking): ${optIn(optIns?.exceptionAutocapture)}\n- Surveys: ${optIn(optIns?.surveys)}\n\n${renderDetectedTools(detectedSources)}\n\nThe installed skill is the source of truth for the HOW of every step:\nwhich MCP tools to call, which sources and scouts apply to this product,\nand how to verify each change. The STEPS below give the order and the\nwizard-specific mechanics — read the matching skill reference before\ndoing the work, and do not invent steps the skill doesn't describe.\n\nBefore doing any work, create your FULL task list in a single TaskCreate\ncall so the user can follow your progress in the TUI. Use exactly these\ntasks, in this order:\n 1. Check Self-driving access\n 2. Read project and current Self-driving state\n 3. Enable products (replay, error tracking, support)\n 4. Enable signal sources\n 5. Offer issue-tracker integrations\n 6. Configure the scout troop\n 6b. Design custom scouts\n 6c. Set up Replay Vision scanners\n 7. Write report and hand off\nDrive the list with TaskUpdate — mark a task in_progress when you start\nit and completed when done. If a step turns out to be a no-op (e.g. a\nproduct is already enabled), still mark its task completed.\n\nThe PostHog GitHub App is already connected — the wizard verified it\nbefore this run started, so never ask the user to connect or install it.\n\nWizard mechanics:\n- Ask the user things ONLY with the wizard_ask MCP tool, and batch\n related questions (e.g. one multi-select for all issue trackers, not\n one ask per tool). The per-run ask budget is limited.\n- If wizard_ask is unavailable (CI / non-interactive), emit\n ${AgentSignals.ABORT} requires-interactive-mode and halt.\n- When a step requires the user to do something in the browser, give\n them the exact URL inside the wizard_ask prompt text — do not try to\n open a browser yourself.\n- Emit ${AgentSignals.STATUS} lines as you complete each step so the\n user sees progress.\n\nFollow these steps IN ORDER. Do not skip or reorder.\n\nSTEP 1 — Check Self-driving access. (skill: \"Check access\")\n Self-driving is in open beta and available to every team, so there is\n no access gate to probe. Do NOT call any MCP tool here — mark this task\n in_progress and then completed right away and emit the\n ${AgentSignals.STATUS} line, so the user sees an immediate first step.\n Only if the Signals API later turns out to be genuinely unreachable for\n this project (a hard error on every Signals call, unexpected in open\n beta) should you emit\n ${AgentSignals.ABORT} self-driving is not available for this project\n and halt.\n\nSTEP 2 — Read project and current Signals state. (skill: \"Read context\")\n If ./posthog-setup-report.md exists, read it as a strong hint for what\n THIS repo instruments — but it is often absent (users frequently don't\n commit it), so do NOT depend on it. Combine whatever you find with the\n project-state block above and the skill's server-side usage probes —\n repo evidence rules products in, never out. Do a light scan ONLY for\n what neither covers. List the currently enabled signal sources so every\n later write is idempotent.\n\nSTEP 3 — Enable products. (skill: \"Enable products\")\n Turn ON the PostHog products Signals reads from — Session Replay,\n Error Tracking, and Support — so the sources you enable next, and the\n Replay Vision scanners in STEP 6c, have data to read. These are\n server-side enables with conservative defaults (owned by the server,\n not you). The project-state block above covers\n only Session Replay and Error Tracking, so you can skip those if they\n are already ON; it does not show Support, but every enable is idempotent\n so enabling any of them again is safe regardless. For a web app, also\n make sure this repo's posthog-js\n init doesn't disable them; for a pure backend or mobile app the server\n flip is inert, so just record that for the report and move on. The skill\n names the exact tool and the per-platform detail.\n\nSTEP 4 — Enable signal sources. (skill: \"Enable sources\")\n Enable the sources that match what this product actually uses, per\n the skill. Never enable a source for a tool the user hasn't\n confirmed they use.\n\nSTEP 5 — Offer issue-tracker integrations. (skill: \"Connected tools\")\n One batched multi-select wizard_ask for the external tools the skill\n lists. Order it per the skill: the tools from the \"Tools detected in\n this codebase\" list above come first, then the SaaS basics, then an\n \"others\" option for the long tail — never dump the whole catalog.\n The run auto-connects the ones it can (GitHub Issues, and\n Linear via a one-click OAuth link), verifying each with a single\n silent check — never nudge. For GitHub Issues: when the GitHub\n integration has exactly one repository connected, use that repo by\n default and skip repo research entirely — research which repo\n matches this project only when several are connected. It arms the\n rest as dormant responders to\n finish later: for tools it can't auto-connect (Zendesk, pganalyze) it\n never sends the user to paste credentials and never re-prompts. Enable\n a source only for a tool the user picked.\n\nSTEP 6 — Configure the scout troop. (skill: \"Scouts\")\n Materialize the troop, read the project's enforced scout-run budget\n (100 runs a day by default), then enable a selective set — the\n \"general\" scout plus the three to five specialists for the products\n this project uses most — and disable the rest, per the skill. The\n whole troop, including step 6b's custom scouts, stays at or under\n ten enabled scouts.\n\n Then tell the user what the troop is, before STEP 6b asks them to add\n to it. Scouts are PostHog's built-in ones, and the user has not seen\n the list: without it, STEP 6b asks them to approve additions to a\n baseline they cannot picture. Send one short message naming each\n scout you enabled with a plain one-line description of what it\n watches, and say how many you left disabled and that they can turn\n those on later from the inbox. No wizard_ask here, it is not a\n question. Keep each line to one sentence and do not restate the\n skill's internals.\n\nSTEP 6b — Design custom scouts for this product. (skill: \"Custom scouts\")\n You are the only actor that has read this repo — turn that into\n coverage per the skill: a real gap analysis of the project's\n watchable surfaces against what the built-in troop already covers,\n then custom scouts for the uncovered ones. Start the gap analysis\n from the repo's for-agents context when present (AGENTS.md,\n CLAUDE.md, ARCHITECTURE.md, .cursor/rules, agent-facing docs) — it\n is a maintained map of the product's surfaces and vocabulary, so\n read it before scanning source. Keep scout bodies\n high-level: describe the behavior and signal conditions to watch,\n referencing repo evidence by file/function name — never paste raw\n source, secrets, env values, or customer data into a scout body.\n Never edit built-in scout bodies. Propose all candidates in ONE\n batched wizard_ask\n before creating anything; the user declining everything (or finding\n no gap at all) is a valid outcome, not an abort. Mark the task\n completed either way.\n\nSTEP 6c — Set up Replay Vision scanners. (skill: \"Replay Vision scanners\")\n Create the scanner skeletons the skill defines, filling the per-product\n blanks it leaves you from this repo's code. Scanners need Session Replay\n on (STEP 3). Every failure here — no recordings yet, a backend-only\n project, the scanner API missing — is a follow-up, never an abort; mark\n the task completed regardless.\n\nSTEP 7 — Write the report and hand off. (skill: \"Report\")\n Write the report per the skill, including follow-ups for anything\n deferred. Tell the user findings will start appearing in their inbox\n at ${inboxUrl} within about 30 minutes.`;\n}\n","/**\n * Canonical step keys for the Self-driving run's `wizard: step` analytics.\n *\n * The agent writes its own task labels, so the same step reaches analytics under whatever wording\n * that run's model picked — \"Enable products\", \"Enabling products\" and \"Turn on PostHog products\"\n * are all STEP 3. A funnel keyed on that label silently loses runs the moment the wording drifts,\n * which is invisible: the number just drops.\n *\n * These rules map a label back to the step it belongs to, so a funnel can key on `step_key` and stay\n * correct across rewordings. `step_name` still ships alongside it, unchanged, for anything that wants\n * the label the user actually saw.\n */\n\n/**\n * Canonical keys, in the order the prompt's STEPs run. Frozen: these are event property values.\n * `connect_github` is retained for historical runs — the GitHub App is now connected on a wizard\n * screen before the agent starts, so no current run emits it.\n */\nexport const SELF_DRIVING_STEP_KEYS = [\n 'check_access',\n 'read_context',\n 'connect_github',\n 'enable_products',\n 'enable_signal_sources',\n 'connect_issue_trackers',\n 'configure_scouts',\n 'design_custom_scouts',\n 'setup_replay_vision',\n 'write_report',\n] as const;\n\nexport type SelfDrivingStepKey = (typeof SELF_DRIVING_STEP_KEYS)[number];\n\n/**\n * First match wins, so order is the rule. Entity words come before verbs: \"Checking GitHub\n * connection\" is the GitHub step, not the access-check step, and \"Connecting issue trackers\" must\n * not fall through to GitHub just because a later run words it \"Connecting GitHub issues\".\n */\nconst RULES: readonly { key: SelfDrivingStepKey; match: RegExp }[] = [\n { key: 'connect_issue_trackers', match: /issue[\\s-]?track/i },\n { key: 'setup_replay_vision', match: /replay vision|vision scanner/i },\n { key: 'design_custom_scouts', match: /custom scout|designing scout/i },\n {\n key: 'configure_scouts',\n match: /scout troop|tun(e|ing) .*scout|configur\\w* .*scout/i,\n },\n { key: 'enable_signal_sources', match: /signal source/i },\n { key: 'connect_github', match: /github/i },\n { key: 'enable_products', match: /product/i },\n { key: 'write_report', match: /report/i },\n { key: 'check_access', match: /access/i },\n { key: 'read_context', match: /read|context|project state/i },\n];\n\n/**\n * The canonical key for an agent-authored step label, or `undefined` when nothing matches — an\n * unmatched step is left unkeyed rather than bucketed, so a new step shows up as a gap to name\n * instead of quietly inflating whichever key it landed nearest.\n */\nexport function resolveSelfDrivingStepKey(\n stepName: string | undefined,\n): SelfDrivingStepKey | undefined {\n if (!stepName) return undefined;\n return RULES.find((rule) => rule.match.test(stepName))?.key;\n}\n","/**\n * Self-driving pricing, in one place. It's stated at six points across the run (intro, tips,\n * learn deck, outro), and a price quoted six ways is a price the reader stops trusting.\n *\n * Careful with the word \"free\". The tracking this wizard installs bills as ordinary PostHog\n * usage, and scouts are heading for usage-based pricing too — so anything called free here is\n * a promise with an expiry date. State what the PR costs and leave the rest to usage-based\n * billing, which stays true either side of that change.\n */\n\n/** Flat USD charge per report that ships a pull request. */\nexport const PRICE_PER_PR_USD = 15;\n\n/** One line, for a screen that only has room to say what it costs. */\nexport const PRICING_SHORT = `Agents charge a flat $${PRICE_PER_PR_USD} per pull request they ship.`;\n\n/** The same fact at length, plus the bit people are surprised by later. */\nexport const PRICING_LONG =\n `A report that ships a pull request costs a flat $${PRICE_PER_PR_USD}. ` +\n `Everything else follows your usual PostHog usage-based pricing.`;\n\n/**\n * Nothing caps the spend unless you set it, which is worth saying out loud. Checked against\n * billing: `custom_limits_map` starts empty and a product with no custom limit resolves to\n * `usage_limit: None`, i.e. uncapped. A free plan is capped by its own allocation instead,\n * hence the qualifier.\n */\nexport const NO_DEFAULT_LIMIT =\n 'A paid plan has no monthly cap until you set one. Add a PR limit in your inbox sidebar, ' +\n 'and agents pause when they hit it.';\n","import { NO_DEFAULT_LIMIT, PRICING_LONG } from './pricing.js';\n\n/**\n * Sidebar tips for the self-driving run — short footnotes on the\n * vocabulary ladder (signal source → scout → signal → report → measured\n * loop). The learn deck (`./index.tsx`) carries the teaching; these stay\n * one to two lines each so the pane never overflows.\n *\n * Product knowledge lives here in the program, not in the generic\n * `TipsCard`. Wired onto the program's `getTips`.\n */\n\nimport type { Tip } from '@ui/tui/components/TipsCard';\n\nexport const SELF_DRIVING_TIPS: Tip[] = [\n {\n id: 'signal-source',\n title: 'Signal source',\n description:\n 'A stream PostHog watches: errors, replays, support, GitHub or Linear issues.',\n },\n {\n id: 'scout',\n title: 'Scout',\n description:\n 'An agent on a schedule, watching your sources for anomalies and patterns. Your project gets up to 100 scout runs a day by default.',\n },\n {\n id: 'scanner',\n title: 'Scanner',\n description:\n 'Where a scout reads your data, a scanner watches session recordings — an LLM spotting what broke on screen. It spends Replay Vision quota, so it stays scoped to your key flows.',\n },\n {\n id: 'signal-report',\n title: 'Signal → report',\n description:\n 'One finding with evidence and a suggested action. Signals group into prioritized reports in your inbox.',\n },\n {\n id: 'the-loop',\n title: 'The loop',\n description:\n 'After a fix ships, PostHog measures the result. If the pattern persists, a new signal reopens the work.',\n },\n {\n id: 'pricing',\n title: 'What it costs',\n description: `${PRICING_LONG} ${NO_DEFAULT_LIMIT}`,\n },\n {\n id: 'work-anywhere',\n title: 'Work anywhere',\n description:\n 'Your inbox is in the PostHog app, Slack (tag @PostHog), and MCP. You can work from anywhere.',\n },\n];\n\nexport const getTips = (): Tip[] => SELF_DRIVING_TIPS;\n","/**\n * PIPELINE_BLOCK — ASCII diagram of the Self-driving loop: sources feed\n * scouts, scouts raise signals, signals group into reports, reports land\n * in the inbox, shipped fixes get measured, and misses loop back as new\n * signals. Kept under ~38 chars wide so it fits the LearnCard pane at an\n * 80-column terminal.\n */\n\nimport { Text } from 'ink';\nimport { Colors } from '@ui/tui/styles';\nimport type { ContentBlock } from '@ui/tui/primitives/content-types';\n\nexport const PIPELINE_BLOCK: ContentBlock = {\n type: 'lines',\n interval: 300,\n pause: 8000,\n lines: [\n <Text>\n {' '}\n <Text bold color=\"cyan\">\n signal sources\n </Text>\n </Text>,\n <Text dimColor>{' errors · replays · support'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n scouts\n </Text>\n </Text>,\n <Text dimColor>{' watching on a schedule'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n signals\n </Text>\n </Text>,\n <Text dimColor>{' finding + evidence + action'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n reports\n </Text>\n </Text>,\n <Text dimColor>{' grouped and prioritized'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color=\"green\">\n your inbox\n </Text>\n </Text>,\n <Text dimColor>{' investigate · tag · ship a PR'}</Text>,\n <Text>\n <Text color=\"gray\">{' ↓ '}</Text>\n <Text bold color={Colors.accent}>\n measured\n </Text>\n </Text>,\n <Text>\n <Text color=\"cyan\">{' ↺ '}</Text>\n <Text dimColor>didn't fix it? a new signal</Text>\n </Text>,\n ],\n};\n","import { NO_DEFAULT_LIMIT, PRICING_LONG } from './pricing.js';\n/**\n * Self-driving learn-deck — the narrative script played while the agent\n * sets up Self-driving. Teaches the vocabulary ladder (signal source →\n * scout → signal → report → action → measured loop) before the agent's\n * questions use those nouns, and explains why GitHub is required before\n * the connect ask lands.\n *\n * One deck for every self-driving run. On the integrate path it plays\n * during the install run (the pane belongs to whichever run screen shows\n * first), so it doubles as the wait-time read.\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 type { ContentBlock } from '@ui/tui/primitives/content-types';\nimport { StatusPeekTrigger } from '@ui/tui/components/StatusPeekTrigger';\nimport { PIPELINE_BLOCK } from './pipeline-diagram.js';\n\nconst CLEAR: ContentBlock = { type: 'clear', pause: 2000 };\n\nexport const getContentBlocks = (store?: WizardStore): ContentBlock[] => {\n return [\n // Scene 1 — orient\n {\n content: 'Welcome.',\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: \"It's setting up PostHog Self-driving for this project.\",\n pause: 5000,\n },\n\n {\n content: \"We'll occasionally need your input. Stick around.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 2 — controls\n {\n pause: 5000,\n persist: true,\n content: <StatusPeekTrigger store={store} />,\n },\n\n {\n pause: 6000,\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 CLEAR,\n\n // Scene 3 — platform story\n {\n content: 'Your PostHog tools all share one data layer.',\n pause: 4000,\n },\n\n {\n content:\n 'Analytics, replays, errors, flags: they all share the same users, mapped across every tool.',\n pause: 6000,\n },\n\n {\n content: 'Together, they show how people really use your product.',\n pause: 5000,\n },\n\n {\n content:\n \"Piecing that together used to be manual work. That's what Self-driving automates.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 4 — the differentiator, and why GitHub\n {\n content:\n 'A coding agent sees your code, but not how your product is used.',\n pause: 5000,\n },\n\n { content: 'PostHog knows what your users actually do.', pause: 4000 },\n\n { content: 'Self-driving puts an agent in the loop.', pause: 5000 },\n\n {\n content:\n \"That's why setup will ask to connect GitHub: so Self-driving can access your code and your context, together.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 5 — signal sources\n {\n content: 'Each PostHog tool you enable is a signal source.',\n pause: 4000,\n },\n\n {\n content:\n \"Errors, replays, support tickets, GitHub or Linear issues: they're all streams of product usage.\",\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 6 — scouts\n {\n content: 'Scouts are agents that watch those sources on a schedule.',\n pause: 5000,\n },\n\n {\n content:\n 'They look for anomalies and patterns: a spike in errors or a funnel quietly dropping.',\n pause: 6000,\n },\n\n { content: 'Setup tunes your scouts to fit your product.', pause: 4000 },\n\n CLEAR,\n\n // Scene 7 — signals and reports\n {\n content:\n \"When a scout finds something worth your attention, that's a signal.\",\n pause: 5000,\n },\n\n {\n content:\n 'Each signal carries the finding, the evidence, and a suggested action.',\n pause: 5000,\n },\n\n {\n content: 'Related signals group into reports, sorted by priority.',\n pause: 4000,\n },\n\n CLEAR,\n\n { content: \"Here's the whole loop.\", pause: 1000 },\n\n PIPELINE_BLOCK,\n\n CLEAR,\n\n // Scene 8 — payoff: the inbox\n { content: 'Reports land in your Self-driving inbox.', pause: 4000 },\n\n {\n content: 'Investigate with the agent, tag teammates, or kick off a PR.',\n pause: 6000,\n },\n\n {\n // No lead-in: PRICING_LONG already names the PR as what's charged, and the\n // pane only fits ~148 chars per beat.\n content: PRICING_LONG,\n pause: 5000,\n },\n\n {\n content: NO_DEFAULT_LIMIT,\n pause: 5000,\n },\n\n CLEAR,\n\n // Scene 9 — the loop kicker\n {\n content: 'And after the PR ships, PostHog measures the result.',\n pause: 5000,\n },\n\n { content: 'Did the fix actually address the pattern?', pause: 4000 },\n\n {\n content: 'If not, a new signal surfaces, and the loop keeps working.',\n pause: 6000,\n },\n\n CLEAR,\n\n // Scene 10 — surfaces + closer\n {\n content: 'Work with Self-driving wherever you already are:',\n pause: 2000,\n },\n\n {\n type: 'lines',\n interval: 800,\n pause: 6000,\n lines: [\n <Text>\n <Text color=\"cyan\">{' ◆ '}</Text>\n <Text bold>Inbox</Text>\n <Text dimColor>{' the PostHog web app'}</Text>\n </Text>,\n <Text>\n <Text color=\"cyan\">{' ◆ '}</Text>\n <Text bold>Slack</Text>\n <Text dimColor>{' tag @PostHog'}</Text>\n </Text>,\n <Text>\n <Text color=\"cyan\">{' ◆ '}</Text>\n <Text bold>MCP</Text>\n <Text dimColor>{' your agents and editors'}</Text>\n </Text>,\n ],\n },\n\n {\n content: 'Product usage data becomes real, shippable change.',\n pause: 5000,\n },\n\n { content: 'Your product drives itself.', pause: 10000 },\n ];\n};\n","import { join } from 'path';\nimport { access, rm } from 'node:fs/promises';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { ProgramRun } from '@lib/agent/agent-runner';\nimport { OutroKind, type WizardSession } from '@lib/wizard-session';\nimport { createSkillProgram } from '../agent-skill/index.js';\nimport { SELF_DRIVING_PROGRAM } from './steps.js';\nimport {\n SELF_DRIVING_ABORT_CASES,\n getSelfDrivingDetectedTools,\n} from './detect.js';\nimport { buildSelfDrivingPrompt } from './prompt.js';\nimport { resolveSelfDrivingStepKey } from './step-keys.js';\nimport {\n NO_DEFAULT_LIMIT,\n PRICE_PER_PR_USD,\n PRICING_LONG,\n} from './content/pricing.js';\nimport { getTips } from './content/tips.js';\nimport { getContentBlocks } from './content/index.js';\n\nexport const SELF_DRIVING_SKILL_ID = 'self-driving-setup';\nconst REPORT_FILE = 'posthog-self-driving-report.md';\nconst DOCS_URL = 'https://posthog.com/docs';\nconst SUCCESS_MESSAGE =\n 'Self-driving is on. PostHog is scanning your project; first findings ' +\n 'hit your inbox within ~30 minutes.';\nconst WIZARD_MARKER = '.posthog-wizard';\n\n/**\n * Remove the installed setup skill. It is transient orchestration\n * knowledge (unlike integration skills such as the Next.js one, which\n * are worth keeping for the user's coding agents), so the program\n * cleans it up instead of showing the keep-skills prompt. Marker-\n * guarded: only directories the wizard installed are touched.\n */\nasync function removeInstalledSkill(installDir: string): Promise<void> {\n const skillDir = join(installDir, '.claude', 'skills', SELF_DRIVING_SKILL_ID);\n try {\n await access(join(skillDir, WIZARD_MARKER));\n } catch {\n return;\n }\n await rm(skillDir, { recursive: true, force: true }).catch(() => undefined);\n}\n\n// A session closure (not a static object) so `customPrompt` can read the\n// tools detected in the codebase — written to frameworkContext by the detect\n// step — and hand them to the prompt for STEP 4/STEP 5 prioritisation.\nconst buildRun = (session: WizardSession): Promise<ProgramRun> =>\n Promise.resolve({\n skillId: SELF_DRIVING_SKILL_ID,\n integrationLabel: SELF_DRIVING_SKILL_ID,\n customPrompt: (ctx) =>\n buildSelfDrivingPrompt(ctx, getSelfDrivingDetectedTools(session)),\n successMessage: SUCCESS_MESSAGE,\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Setting up PostHog Self-driving...',\n estimatedDurationMinutes: 10,\n abortCases: SELF_DRIVING_ABORT_CASES,\n // The flow legitimately needs several interactions (GitHub connect +\n // verify, issue-tracker picks, the scout-tailoring proposal), so raise\n // the wizard_ask budget a little above the default 10.\n maxQuestions: 13,\n // This flow hands the user long OAuth/authorize URLs (Linear, GitHub\n // fallback, Zendesk) in wizard_ask prompts. Render them as OSC 8\n // hyperlinks + clipboard copy so the overlay's line wrapping can't break\n // the click target. Scoped to this program only.\n richLinks: true,\n // STEP 3 (GitHub App install) and STEP 5 (Linear OAuth) park on wizard_ask\n // while the user does slow browser work; a first-time GitHub App install\n // routinely exceeds the 5-min default, and a timeout is indistinguishable\n // from a decline (both resolve to __cancelled__). Match upload-source-maps.\n askTimeoutMs: 30 * 60 * 1000,\n\n // Emit a `wizard: step` analytics event on each agent task transition so we\n // can build a step-level drop-off funnel (where a run stops — GitHub connect,\n // scout enable, etc.), including silent steps with no wizard_ask. Opt-in, so\n // only self-driving runs emit these; every other program is unchanged.\n trackStepProgress: true,\n\n // Key those events by step as well as by label, so a funnel over them (GitHub connect\n // conversion, scout enable rate) keeps counting when a run words its tasks differently.\n resolveStepKey: resolveSelfDrivingStepKey,\n\n postRun: async (session) => {\n await removeInstalledSkill(session.installDir);\n },\n\n buildOutroData: (_session, credentials) => {\n const uiHost = credentials.host.appHost.replace(/\\/$/, '');\n const inboxUrl = `${uiHost}/project/${credentials.projectId}/inbox`;\n return {\n kind: OutroKind.Success as const,\n message: SUCCESS_MESSAGE,\n primaryLink: { label: 'Your Self-driving inbox', url: inboxUrl },\n nextSteps: {\n heading: 'In your inbox you can:',\n items: [\n 'Investigate reports with the agent',\n 'Tag teammates to loop them in',\n `Kick off a PR when you like the proposed fix ($${PRICE_PER_PR_USD} flat)`,\n 'Cap the spend with a monthly PR limit in the sidebar',\n 'Or work from Slack (tag @PostHog) and MCP',\n ],\n },\n body: `${PRICING_LONG} ${NO_DEFAULT_LIMIT}`,\n reportFile: REPORT_FILE,\n };\n },\n });\n\nexport const selfDrivingConfig: ProgramConfig = {\n ...createSkillProgram({\n skillId: SELF_DRIVING_SKILL_ID,\n command: 'self-driving',\n id: 'self-driving',\n description: 'Set up PostHog Self-driving for this project',\n integrationLabel: SELF_DRIVING_SKILL_ID,\n successMessage: SUCCESS_MESSAGE,\n reportFile: REPORT_FILE,\n docsUrl: DOCS_URL,\n spinnerMessage: 'Setting up PostHog Self-driving...',\n estimatedDurationMinutes: 10,\n requires: ['posthog-integration'],\n abortCases: SELF_DRIVING_ABORT_CASES,\n }),\n steps: SELF_DRIVING_PROGRAM,\n run: buildRun,\n getTips,\n getContentBlocks,\n};\n\nexport { SELF_DRIVING_PROGRAM } from './steps.js';\nexport {\n detectSelfDrivingPrerequisites,\n SELF_DRIVING_ABORT_CASES,\n type SelfDrivingDetectError,\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 // This step *is* the tutorial, so it reports there rather than to\n // `mcp-add`. Literal avoids a runtime cycle with the program registry;\n // the `ProgramId` type still catches a rename.\n reportsAsProgramId: 'mcp-tutorial',\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","import type { AbortCase } from '@lib/agent/agent-runner';\nimport { ErrorCodes } from '@lib/errors';\nimport { createSkillProgram } from '@lib/programs/agent-skill/index';\n\nconst MCP_ANALYTICS_REPORT_FILE = 'posthog-mcp-analytics-report.md';\n\n/**\n * `[ABORT]` reasons the mcp-analytics skill emits when the project can't be\n * instrumented. Kept in sync with the stop conditions in the skill's\n * `description.md` (context-mill `context/skills/mcp-analytics`).\n */\nexport const MCP_ANALYTICS_ABORT_CASES: AbortCase[] = [\n {\n match: /^unsupported language for mcp analytics$/i,\n errorCode: ErrorCodes.DetectUnsupportedPlatform,\n message: 'Unsupported language for MCP analytics',\n body:\n 'MCP analytics supports TypeScript/JavaScript (`@posthog/mcp`) and Python ' +\n '(`posthog.mcp`, shipped inside the `posthog` package). This project ' +\n \"doesn't look like either, so there's nothing to instrument. \" +\n 'See https://posthog.com/docs/mcp-analytics for the supported setups.',\n },\n {\n match: /^no mcp server found$/i,\n message: 'No MCP server found',\n body:\n 'This command instruments an existing MCP server with PostHog analytics, ' +\n 'but no MCP server was found in this project. If you just want PostHog ' +\n 'product analytics, run `npx @posthog/wizard` instead.',\n },\n {\n match: /^could not locate the server entry point$/i,\n message: 'Could not locate the MCP server entry point',\n body:\n \"This project has MCP signals, but the agent couldn't find where the \" +\n \"server is constructed or requests are dispatched, so there's nowhere \" +\n 'safe to add instrumentation. See https://posthog.com/docs/mcp-analytics ' +\n 'for the supported server styles, or point the wizard at the package ' +\n \"that defines the server if it's in a monorepo subdirectory.\",\n },\n];\n\n/**\n * `wizard mcp-analytics` — flat skill command.\n *\n * Instruments the user's own MCP server with the `@posthog/mcp` SDK so it\n * reports `$mcp_*` analytics about itself. This is the opposite of\n * `wizard mcp add` (which installs the PostHog MCP *server* into a coding\n * agent) — keep the two distinct.\n *\n * Flat while instrumenting is the only action. If an uninstrument / `remove`\n * leaf ever lands, restructure into a family with `familyCommandFactory` and\n * publish each leaf as a `cliEntries` entry with `parentCommand:\n * 'mcp-analytics'` from context-mill — a deliberate breaking change, done then,\n * not pre-emptively.\n */\nexport const mcpAnalyticsConfig = createSkillProgram({\n skillId: 'mcp-analytics',\n command: 'mcp-analytics',\n id: 'mcp-analytics',\n description: 'Add PostHog MCP analytics to your MCP server',\n integrationLabel: 'mcp-analytics',\n customPrompt:\n \"Instrument this project's MCP server with PostHog MCP analytics. Run the \" +\n '`mcp-analytics` skill end-to-end: detect the server style, install ' +\n '`@posthog/mcp` and `posthog-node`, wrap the server (or use `PostHogMCP` ' +\n 'for a custom dispatcher), wire the project API key and host, and verify. ' +\n 'Make only additive changes — do not alter tool behavior. The final report ' +\n `is written to ./${MCP_ANALYTICS_REPORT_FILE}.`,\n successMessage: `MCP analytics configured! View the report at ./${MCP_ANALYTICS_REPORT_FILE}`,\n reportFile: MCP_ANALYTICS_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/mcp-analytics',\n spinnerMessage: 'Setting up MCP analytics...',\n estimatedDurationMinutes: 5,\n abortCases: MCP_ANALYTICS_ABORT_CASES,\n});\n","import type { AbortCase } from '@lib/agent/agent-runner';\nimport { Integration } from '@lib/constants';\nimport { detectFramework, gatherFrameworkContext } from '@lib/detection/index';\nimport { scopeInstallDirToProject } from '@lib/detection/project-scope';\nimport { FRAMEWORK_REGISTRY } from '@lib/registry';\nimport { createSkillProgram } from '@lib/programs/agent-skill/index';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/steps';\nimport { detectPostHogIntegration } from '@lib/programs/posthog-integration/detect';\nimport type {\n ProgramConfig,\n ProgramReadyContext,\n ProgramStep,\n} from '@lib/programs/program-step';\nimport type { WizardSession } from '@lib/wizard-session';\nimport { analytics } from '@utils/analytics';\nimport { wizardAbort } from '@utils/wizard-abort';\nimport { ErrorCodes } from '@lib/errors';\n\nconst REPLAY_VISION_REPORT_FILE = 'posthog-replay-vision-report.md';\n\n/**\n * The platforms session replay can actually record on. Replay vision watches\n * recordings, so a platform with no recordings has nothing to set up — the\n * run must stop before any work, not after a pointless agent run.\n *\n * Web frameworks record through posthog-js (server-rendered frameworks\n * included — they serve pages), and the mobile SDKs with replay support are\n * React Native, Android, iOS, and Flutter. Excluded: pure backend targets\n * (`javascript_node`, `python`, `ruby`) and KMP, which has no replay support\n * yet.\n */\nexport const REPLAY_VISION_SUPPORTED: ReadonlySet<Integration> = new Set([\n Integration.nextjs,\n Integration.nuxt,\n Integration.vue,\n Integration.reactRouter,\n Integration.tanstackStart,\n Integration.tanstackRouter,\n Integration.angular,\n Integration.astro,\n Integration.sveltekit,\n Integration.javascript_web,\n Integration.django,\n Integration.flask,\n Integration.fastapi,\n Integration.laravel,\n Integration.rails,\n Integration.reactNative,\n Integration.android,\n Integration.swift,\n Integration.flutter,\n]);\n\nasync function abortUnsupportedPlatform(\n integration: Integration,\n): Promise<void> {\n const name = FRAMEWORK_REGISTRY[integration]?.metadata.name ?? integration;\n // This is a clean, intentional exit, not a crash. Count it with a normal\n // event keyed on the platform so aborts roll up into one series. Do not hand\n // `wizardAbort` an `error` — that forwards to captureException and mints a\n // new error-tracking issue per install location and per platform.\n analytics.wizardCapture('replay-vision unsupported platform', {\n integration,\n });\n await wizardAbort({\n code: ErrorCodes.DetectUnsupportedPlatform,\n message:\n `Session replay isn't available for ${name} projects, and Replay ` +\n 'vision needs session recordings to watch — so there is nothing to ' +\n 'set up here.\\n\\n' +\n 'If this repo also contains a web or mobile app, run the command from ' +\n 'that project directory instead. See what replay supports at:\\n' +\n ' https://posthog.com/docs/session-replay',\n });\n}\n\n/**\n * `[ABORT]` reasons the replay-vision skill emits when the run can't proceed.\n * Kept in sync with the stop conditions in the skill's `description.md`\n * (context-mill `context/skills/replay-vision`).\n */\nexport const REPLAY_VISION_ABORT_CASES: AbortCase[] = [\n {\n match: /^replay vision not available for this project$/i,\n message: 'Replay vision is not available for this project',\n body:\n 'Every Replay vision scanner endpoint reported that the feature is not ' +\n 'available here yet. Session replay setup done so far is kept. See ' +\n 'https://posthog.com/docs/replay-vision for availability.',\n },\n];\n\n/**\n * Framework detection ahead of the run, exactly like the default integration\n * program. The orchestrator requires it: `session.skillId` must hold the\n * detected framework id before the run arm starts, because the runner\n * resolves the reference integration skill and every task's mini-skill\n * variants (`integration-v2-install`, `integration-v2-init`, …) against it in\n * preflight. Without this step the session would still carry the program's\n * own skill id and preflight would abort.\n */\nconst DETECT_STEP: ProgramStep = {\n id: 'detect',\n label: 'Detecting framework',\n // The platform gate runs on a direct detectFramework call BEFORE the full\n // detect writes to the store: store setters replace the session with a\n // shallow copy, so `ctx.session` read after detectPostHogIntegration would\n // be the stale pre-copy object (see the warning in detect.ts).\n onReady: async (ctx: ProgramReadyContext) => {\n const integration = await detectFramework(ctx.session.installDir);\n if (integration && !REPLAY_VISION_SUPPORTED.has(integration)) {\n await abortUnsupportedPlatform(integration);\n return;\n }\n await detectPostHogIntegration(ctx);\n },\n};\n\nconst base = createSkillProgram({\n // The menu ids this skill `<dir>-<variant>`, and context-mill's\n // `replay-vision/config.yaml` declares a single variant, `setup`. The bare\n // `replay-vision` id does not exist — the orchestrator never installs this\n // (it resolves per-task mini-skills instead), but the linear path does, and\n // aborts `skill-not-found` on a miss.\n skillId: 'replay-vision-setup',\n command: 'replay-vision',\n id: 'replay-vision',\n description: 'Set up PostHog Replay vision scanners for your product',\n integrationLabel: 'replay-vision',\n customPrompt:\n 'Set up PostHog Replay vision. Run the `replay-vision` skill end-to-end: ' +\n 'make sure session replay is recording (server-side enable plus a ' +\n 'posthog-js init check), then create the vision scanners the skill ' +\n \"defines, scoped to this product's key flows read out of the repo. If \" +\n 'PostHog is not integrated yet, install and initialize the SDK first as ' +\n 'the skill instructs — do not abort. The final report is written to ' +\n `./${REPLAY_VISION_REPORT_FILE}.`,\n successMessage: `Replay vision configured! View the report at ./${REPLAY_VISION_REPORT_FILE}`,\n reportFile: REPLAY_VISION_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/replay-vision',\n spinnerMessage: 'Setting up Replay vision...',\n estimatedDurationMinutes: 6,\n abortCases: REPLAY_VISION_ABORT_CASES,\n});\n\n/**\n * `wizard replay-vision` — flat skill command on the orchestrator sequence.\n *\n * Makes session replay record (server toggle + client init check), then\n * creates vision scanners scoped to the product's key flows, read out of the\n * repo. The orchestrator runs the `replay-vision` agent flow (context-mill\n * `context/agents/replay-vision`): the seed enqueues the install/init tasks\n * (copied from integration-v2, sharing its step-skills) when the project has\n * no PostHog yet, so the command works on uninstrumented repos instead of\n * aborting.\n *\n * Departures from a plain `createSkillProgram`:\n * - `DETECT_STEP` in front, so `session.skillId` carries the framework id the\n * orchestrator's preflight resolves reference + mini-skill variants with.\n * - `agentFlow` pinned (the id would default to the same value — explicit so\n * renaming the program can't silently detach the flow).\n * - `ciPreRun` mirrors the default integration program: scope the install dir\n * to the right project (monorepos), then detect the framework — the\n * headless equivalent of the detect step's onReady hook.\n */\nexport const replayVisionConfig: ProgramConfig = {\n ...base,\n agentFlow: 'replay-vision',\n steps: [DETECT_STEP, ...AGENT_SKILL_STEPS],\n\n ciPreRun: async (session: WizardSession): Promise<void> => {\n await scopeInstallDirToProject(session);\n\n const integration = await detectFramework(session.installDir);\n if (!integration) {\n await wizardAbort({\n code: ErrorCodes.DetectNoFramework,\n message: 'Could not auto-detect your framework for this project.',\n });\n return;\n }\n if (!REPLAY_VISION_SUPPORTED.has(integration)) {\n await abortUnsupportedPlatform(integration);\n return;\n }\n session.integration = integration;\n analytics.setTag('integration', integration);\n\n const frameworkConfig = FRAMEWORK_REGISTRY[integration];\n session.frameworkConfig = frameworkConfig;\n session.skillId = integration;\n\n const context = await gatherFrameworkContext(frameworkConfig, {\n installDir: session.installDir,\n debug: session.debug,\n signup: session.signup,\n ci: true,\n benchmark: session.benchmark,\n yaraReport: session.yaraReport,\n });\n for (const [key, value] of Object.entries(context)) {\n if (!(key in session.frameworkContext)) {\n session.frameworkContext[key] = value;\n }\n }\n },\n};\n","import type { ProgramConfig, ProgramStep } from '@lib/programs/program-step';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/index';\nimport { getContentBlocks } from '@lib/programs/agent-skill/content/index';\n\nconst AI_OBSERVABILITY_STEPS: ProgramStep[] = AGENT_SKILL_STEPS.map((step) =>\n step.id === 'intro' ? { ...step, screenId: 'ai-observability-intro' } : step,\n);\n\nconst AI_OBSERVABILITY_REPORT_FILE = 'posthog-ai-observability-report.md';\n\n/**\n * `wizard ai-observability` — wrap the project's LLM client calls so they emit\n * `$ai_generation` events into LLM Analytics.\n *\n * No `run.skillId`: the context-mill `ai-observability` group ships one variant\n * per (LLM provider × language) and the wizard does no provider detection —\n * the agent loads the menu, matches the manifest's vendor SDK, and installs\n * the right variant itself (see `customPrompt`). Stays flat while a single\n * \"add AIO to a project\" flow is the only action.\n */\nexport const aiObservabilityConfig: ProgramConfig = {\n command: 'ai-observability',\n description: 'Add PostHog AI Observability to your LLM calls',\n id: 'ai-observability',\n steps: AI_OBSERVABILITY_STEPS,\n reportFile: AI_OBSERVABILITY_REPORT_FILE,\n getContentBlocks,\n run: {\n integrationLabel: 'ai-observability',\n // No `skillId`: linear.ts skips its pre-install step (see the gate on\n // `linear.ts:47`), so the agent must load the menu and install the right\n // variant itself. The prompt below tells it how.\n customPrompt:\n () => `Instrument this project's LLM calls with PostHog AI Observability.\n\nThis flow has no pre-installed skill — you install the right one yourself:\n\n1. Call \\`load_skill_menu\\` with \\`category: \"ai-observability\"\\`. The menu is\n the source of truth: one variant per (LLM provider × language), plus a\n \\`manual-capture\\` variant for projects with no vendor SDK.\n\n2. Scan the project manifest (\\`package.json\\`, \\`pyproject.toml\\`,\n \\`requirements.txt\\`) for a vendor LLM SDK and pick the variant that matches\n it — the language follows the manifest (\\`package.json\\` → Node, Python\n tooling → Python). Multiple SDKs (e.g. LangChain wrapping OpenAI) → prefer\n the higher abstraction. No vendor SDK → the \\`manual-capture\\` variant.\n Genuinely ambiguous → \\`wizard_ask\\` with a multi-choice picker.\n\n3. Call \\`install_skill\\` with the picked variant id. Then follow that skill's\n \\`SKILL.md\\` and references end-to-end. The skill itself will install\n packages, wire OTel, set env vars, and describe verification.\n\nMake only additive changes — do not touch existing PostHog init, identify\ncalls, event capture, or dashboards. Those belong to other skills. The\nfinal report is written to ./${AI_OBSERVABILITY_REPORT_FILE}.`,\n successMessage: `AI Observability configured! View the report at ./${AI_OBSERVABILITY_REPORT_FILE}`,\n reportFile: AI_OBSERVABILITY_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/ai-observability',\n spinnerMessage: 'Setting up AI Observability...',\n estimatedDurationMinutes: 5,\n },\n};\n","import type { ProgramConfig, ProgramStep } from '@lib/programs/program-step';\nimport { AGENT_SKILL_STEPS } from '@lib/programs/agent-skill/index';\nimport { getContentBlocks } from '@lib/programs/agent-skill/content/index';\n\nconst METRICS_STEPS: ProgramStep[] = AGENT_SKILL_STEPS.map((step) =>\n step.id === 'intro' ? { ...step, screenId: 'metrics-intro' } : step,\n);\n\nconst METRICS_REPORT_FILE = 'posthog-metrics-report.md';\n\n/**\n * `wizard metrics` — instrument the project with PostHog application metrics\n * (`posthog.metrics` counters, gauges, and histograms).\n *\n * No `run.skillId`: the context-mill `metrics` group ships one variant per\n * platform (python, nodejs, javascript, kubernetes, other/OTLP) and the agent\n * pulls the matching one itself — the flow's tasks and the linear\n * `customPrompt` both pick from the menu and install it. Stays flat while a\n * single \"add metrics to a project\" flow is the only action.\n */\nexport const metricsConfig: ProgramConfig = {\n command: 'metrics',\n description: 'Add PostHog application metrics to your project',\n id: 'metrics',\n // Orchestrator flow (context-mill `context/agents/metrics`): the seed queues\n // verify-sdk → instrument-metrics → report; the tasks install the matching\n // platform variant themselves. Explicit so renaming the program can't\n // silently detach the flow.\n agentFlow: 'metrics',\n steps: METRICS_STEPS,\n reportFile: METRICS_REPORT_FILE,\n getContentBlocks,\n run: {\n integrationLabel: 'metrics',\n // No `skillId`: the agent must load the menu and install the right\n // variant itself. The prompt below tells it how.\n customPrompt:\n () => `Instrument this project with PostHog application metrics.\n\nThis flow has no pre-installed skill — you install the right one yourself:\n\n1. Call \\`load_skill_menu\\` with \\`category: \"metrics\"\\`. The menu is the\n source of truth: one variant per platform.\n\n2. Pick the variant that matches the project:\n - Python tooling (\\`pyproject.toml\\`, \\`requirements.txt\\`, \\`Pipfile\\`) →\n \\`metrics-python\\` (needs \\`posthog\\` >= 7.23.0)\n - \\`package.json\\` with server-side Node code → \\`metrics-nodejs\\`\n (needs \\`posthog-node\\` >= 5.43.0)\n - \\`package.json\\` that is browser-only → \\`metrics-javascript\\`\n (needs \\`posthog-js\\` >= 1.399.0)\n - Kubernetes manifests / Helm charts and the user wants cluster-level\n scraping → \\`metrics-kubernetes\\`\n - Any other language → \\`metrics-other\\` (plain OTLP exporter)\n A full-stack app (e.g. Next.js) usually wants the server variant — metrics\n measure service work, not user actions. Genuinely ambiguous →\n \\`wizard_ask\\` with a multi-choice picker.\n\n3. Call \\`install_skill\\` with the picked variant id. Then follow that skill's\n \\`SKILL.md\\` and references end-to-end — it covers where to place metrics\n (middleware, background jobs, external calls, business commit sites) and\n the low-cardinality attribute rules.\n\nMake only additive changes — reuse an existing PostHog client by adding the\n\\`metrics\\` config to it rather than constructing a second client, and do not\ntouch existing identify calls, event capture, or dashboards. The final report\nis written to ./${METRICS_REPORT_FILE}.`,\n successMessage: `Application metrics configured! View the report at ./${METRICS_REPORT_FILE}`,\n reportFile: METRICS_REPORT_FILE,\n docsUrl: 'https://posthog.com/docs/metrics',\n spinnerMessage: 'Setting up application metrics...',\n estimatedDurationMinutes: 5,\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 { warehouseSourceConfig } from './warehouse-source/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 { selfDrivingConfig } from './self-driving/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 { mcpAnalyticsConfig } from './mcp-analytics/index.js';\nimport { replayVisionConfig } from './replay-vision/index.js';\nimport { aiObservabilityConfig } from './ai-observability/index.js';\nimport { metricsConfig } from './metrics/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 warehouseSourceConfig,\n errorTrackingUploadSourceMapsConfig,\n auditConfig,\n eventsAuditConfig,\n posthogDoctorConfig,\n webAnalyticsDoctorConfig,\n migrationConfig,\n selfDrivingConfig,\n agentSkillConfig,\n mcpAddConfig,\n mcpRemoveConfig,\n mcpTutorialConfig,\n mcpAnalyticsConfig,\n replayVisionConfig,\n aiObservabilityConfig,\n metricsConfig,\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 WarehouseSource: warehouseSourceConfig.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 SelfDriving: selfDrivingConfig.id,\n AgentSkill: agentSkillConfig.id,\n McpAdd: mcpAddConfig.id,\n McpRemove: mcpRemoveConfig.id,\n McpTutorial: mcpTutorialConfig.id,\n McpAnalytics: mcpAnalyticsConfig.id,\n ReplayVision: replayVisionConfig.id,\n AiObservability: aiObservabilityConfig.id,\n Metrics: metricsConfig.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","/**\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 the mcp commands\n * degrade to LoggingUI for — any other error from the TUI path is a real bug\n * and must surface rather than be silently swallowed.\n */\nexport function isTUIUnavailable(error: unknown): boolean {\n return (\n error instanceof Error && /raw mode is not supported/i.test(error.message)\n );\n}\n","import type { Arguments } from 'yargs';\nimport { setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { headlessOption, isHeadless } from '@lib/headless-mode';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\nimport { isTUIUnavailable } from './tui-availability';\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 // Reuses the run pipeline's headless flag rather than minting a public one:\n // this stays reversible, and today the only caller is our own CI.\n ...headlessOption,\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 const args = { local: localMcp, features, apiKey };\n\n // Ink renders into a pipe happily and only throws on raw-mode input, so a\n // non-TTY run reaches the confirm prompt and stalls there rather than\n // hitting the isTUIUnavailable fallback below. The headless flag is the\n // only reliable way to install from a script.\n if (isHeadless(argv)) {\n await runHeadlessAdd(args);\n return;\n }\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 baseUrl: argv.baseUrl as string | undefined,\n });\n } catch (error) {\n if (!isTUIUnavailable(error)) throw error;\n await runHeadlessAdd(args);\n }\n })();\n}\n\nasync function runHeadlessAdd(args: {\n local?: boolean;\n features?: string[];\n apiKey?: string;\n}): Promise<void> {\n setUI(new LoggingUI());\n const { addMCPServerToClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n // Never forwards `ci`: headless implies session.ci elsewhere, and the step\n // reads that as \"skip MCP entirely\" — the opposite of what we're here to do.\n const { installed, failed } = await addMCPServerToClientsStep(args);\n // A scripted caller has no screen to read, so this has to be an exit code.\n // Any failure counts, not just a total wipeout: the step installs to every\n // detected client, so one succeeding would otherwise mask the rest.\n if (failed.length > 0 || installed.length === 0) process.exitCode = 1;\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 { headlessOption, isHeadless } from '@lib/headless-mode';\nimport { Program } from '@lib/programs/program-registry';\nimport { VERSION } from '@lib/version';\nimport type { Command } from '../command';\nimport { isTUIUnavailable } from './tui-availability';\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 // Mirrors `mcp add` — see the note there on reusing the run pipeline's flag.\n ...headlessOption,\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 // See the note in add.ts: a non-TTY run stalls on the confirm prompt\n // instead of falling back, so scripts need an explicit flag.\n if (isHeadless(argv)) {\n await runHeadlessRemove(localMcp);\n return;\n }\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({\n debug,\n localMcp,\n baseUrl: argv.baseUrl as string | undefined,\n });\n } catch (error) {\n // Same guard as `mcp add`: only a missing TTY falls back to LoggingUI,\n // so a genuine TUI bug surfaces instead of looking like a plain shell.\n if (!isTUIUnavailable(error)) throw error;\n await runHeadlessRemove(localMcp);\n }\n })();\n}\n\n/** No exit code on an empty result: nothing to remove is the requested end state. */\nasync function runHeadlessRemove(local?: boolean): Promise<void> {\n setUI(new LoggingUI());\n const { removeMCPServerFromClientsStep } = await import(\n '@steps/add-mcp-server-to-clients/index'\n );\n await removeMCPServerFromClientsStep({ local });\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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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({\n debug,\n localMcp,\n baseUrl: argv.baseUrl as string | undefined,\n });\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 emitWizardError({\n code: ErrorCodes.CliInteractiveRequired,\n message: 'The MCP tutorial requires an interactive terminal.',\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 { runAgent } from '@lib/agent/agent-runner';\nimport { authenticate } from '@lib/agent/runner/shared/authenticate';\nimport { maybeStampAiSdkDetected } from '@lib/programs/posthog-integration/detect';\nimport type { ProgramConfig } from '@lib/programs/program-step';\nimport type { Harness, Sequence } from '@lib/constants';\nimport type { startTUI as StartTUIFn } from '@ui/tui/start-tui';\nimport type { WizardStore } from '@ui/tui/store';\nimport type { WizardSession } from '@lib/wizard-session';\nimport type { TaskStreamPush as TaskStreamPushClass } from '@lib/task-stream/task-stream-push';\nimport { resolveNoTelemetry } from './resolve-no-telemetry';\nimport { checkLocalServices, getLocalDev } from '@lib/local-dev';\nimport { runCleanups } from '@utils/wizard-abort';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\nimport { join } from 'node:path';\n\nconst WIZARD_VERSION = VERSION;\n\ntype Step = ProgramConfig['steps'][number];\n\n/** The session a run step's agent runs in: scoped to the step's target dir\n * (e.g. a monorepo sub-app) with its own framework context, after any prep.\n * A step without `targetDir` runs in the live session, unchanged.\n * The frameworkContext copy is shallow and unfiltered — name keys per owning program. */\nasync function prepareRunSession(\n step: Step,\n live: WizardSession,\n): Promise<WizardSession> {\n const session = step.targetDir\n ? {\n ...live,\n installDir: step.targetDir(live),\n frameworkContext: { ...live.frameworkContext },\n }\n : live;\n if (step.onRunPrep) await step.onRunPrep(session);\n return session;\n}\n\n/** Advance one step of a composed run to completion: the auth screen\n * authenticates (every later run reuses it); a step carrying its own `run`\n * thunk runs that agent in its dir and is recorded in `completedRuns`; the\n * host program's own run screen runs `config.run`; any other screen waits for\n * the user to satisfy `isComplete`. */\nasync function advanceStep(\n step: Step,\n store: WizardStore,\n config: ProgramConfig,\n): Promise<void> {\n if (step.screenId === 'auth') {\n await authenticate(store.session, config.id);\n maybeStampAiSdkDetected(store.session);\n } else if (step.run) {\n await step.run(await prepareRunSession(step, store.session));\n store.completeRunStep(step.id);\n } else if (step.screenId === 'run') {\n await runAgent(config, await prepareRunSession(step, store.session));\n } else if (step.isComplete) {\n await store.waitUntil(step.isComplete);\n }\n}\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 // Before the TUI mounts: once Ink owns the alt screen, anything written\n // to it is wiped on unmount (see the catch block below), so an abort here\n // would leave the user on a loading screen with no message.\n const local = getLocalDev();\n const localServicesError = await checkLocalServices({\n ...local,\n // An explicit --base-url wins over --local-posthog (see buildSession),\n // so don't probe :8010 when one was given.\n localPosthog: local.localPosthog && !options.baseUrl,\n });\n if (localServicesError) {\n const { wizardAbort } = await import('@utils/wizard-abort');\n await wizardAbort({ message: localServicesError });\n return;\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 localDev: options.localDev as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n localPosthog: options.localPosthog 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 baseUrl: options.baseUrl as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n harness: options.harness as Harness | undefined,\n sequence: options.sequence as Sequence | undefined,\n model: options.model as string | undefined,\n integrate: options.integrate as boolean | undefined,\n captureAio: options.captureAio as boolean | undefined,\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 eventPlanPath: config.eventPlanFile\n ? join(session.installDir, config.eventPlanFile)\n : undefined,\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 // Settle the pre-run screens. `integration-check` is a no-op gate for\n // programs without it.\n await activeTui.store.getGate('intro');\n await activeTui.store.getGate('integration-check');\n await activeTui.store.getGate('health-check');\n\n const skipAgent = config.run == null;\n const shown = (s: ProgramConfig['steps'][number]) =>\n !s.show || s.show(activeTui.store.session);\n\n if (config.steps.some((s) => s.run)) {\n // A composed program: its step list splices in run steps that carry\n // their own agent (self-driving runs the integration before its own\n // run). Walk the list once, advancing each step to completion.\n for (const step of config.steps) {\n if (step.screenId === 'outro') break; // run-completion wait owns it\n if (shown(step)) await advanceStep(step, activeTui.store, config);\n }\n } else 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 baseUrl: session.baseUrl,\n programId: config.id,\n });\n activeTui.store.setCredentials({\n accessToken,\n projectApiKey,\n host,\n projectId,\n });\n } else {\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 emitWizardError({\n code: ErrorCodes.InternalUnhandled,\n message: err instanceof Error ? err.message : String(err),\n });\n process.exit(1);\n }\n })();\n}\n","import { POSTHOG_DOCS_URL, type Harness, type Sequence } from '@lib/constants';\nimport {\n checkLocalServices,\n getLocalDev,\n POSTHOG_LOCAL_URL,\n} from '@lib/local-dev';\nimport type { CloudRegion } from '@utils/types';\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';\nimport type { WizardStore } from '@ui/tui/store';\nimport type { TaskStreamPush } from '@lib/task-stream/task-stream-push';\nimport { join } from 'node:path';\nimport { ErrorCodes, detectErrorCode, emitWizardError } from '@lib/errors';\nimport type { OutroData, RunPhase as RunPhaseT } from '@lib/wizard-session';\n\n/**\n * The two non-interactive run modes. Both drive the same pipeline today; the\n * mode is threaded explicitly (rather than sniffed from a flag) so the dispatch\n * picks an entry point — runWizardCI vs runWizardHeadless — and this core stays\n * mode-agnostic except at the few documented forks. The string values double as\n * the analytics `build` tag, so they segment runs in analytics and on\n * LLM-gateway traces (which read analytics.build).\n */\nexport type NonInteractiveMode = 'ci' | 'headless';\n\n/** User-facing label for a non-interactive mode. */\nfunction modeLabel(mode: NonInteractiveMode): string {\n return mode === 'headless' ? 'Headless' : 'CI';\n}\n\n/**\n * The single non-interactive validation layer: requires api-key and\n * install-dir. Every non-interactive entry point routes through\n * `runNonInteractive`, so this is the one place these checks live. UI must be\n * initialized before calling.\n */\nexport function validateNonInteractiveOptions(\n options: Record<string, unknown>,\n mode: NonInteractiveMode,\n): void {\n const label = modeLabel(mode);\n const keyHint =\n mode === 'headless'\n ? 'personal API key phx_xxx or pha_ OAuth access token'\n : 'personal API key phx_xxx';\n if (!options.apiKey) {\n getUI().intro('PostHog Wizard');\n getUI().log.error(`${label} mode requires --api-key (${keyHint})`);\n emitWizardError({\n code: ErrorCodes.ArgsMissingApiKey,\n message: `${label} mode requires --api-key (${keyHint})`,\n });\n process.exit(1);\n }\n if (!options.installDir) {\n getUI().intro('PostHog Wizard');\n getUI().log.error(\n `${label} mode requires --install-dir (directory to install in)`,\n );\n emitWizardError({\n code: ErrorCodes.ArgsMissingInstallDir,\n message: `${label} mode requires --install-dir`,\n });\n process.exit(1);\n }\n}\n\n/**\n * Non-interactive pipeline shared by CI (`runWizardCI`) and headless\n * (`runWizardHeadless`) runs.\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 *\n * `mode` is the only difference between the two callers today (it sets the\n * analytics build tag and the user-facing label). Keeping it a parameter is\n * what lets CI and headless share this body now and diverge later — branch on\n * `mode` here, or stop sharing this function entirely.\n */\nexport function runNonInteractive(\n config: ProgramConfig,\n options: Record<string, unknown>,\n mode: NonInteractiveMode,\n): void {\n setUI(new LoggingUI());\n validateNonInteractiveOptions(options, mode);\n // Upgrade the build tag so runs segment cleanly in analytics (and on\n // LLM-gateway traces, which read analytics.build). A published headless run\n // (cloud / CI/CD) tags 'headless'; a dev/test `--ci` run upgrades 'dev' to\n // 'ci'. The mode string is the tag value.\n analytics.setTag('build', mode);\n\n void (async () => {\n const path = await import('path');\n const { buildSession, RunPhase, OutroKind } = await import(\n '@lib/wizard-session'\n );\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 localDev: options.localDev as boolean | undefined,\n localMcp: options.localMcp as boolean | undefined,\n localPosthog: options.localPosthog as boolean | undefined,\n apiKey,\n email: options.email as string | undefined,\n projectId: options.projectId as string | undefined,\n baseUrl: options.baseUrl as string | undefined,\n benchmark: options.benchmark as boolean | undefined,\n yaraReport: options.yaraReport as boolean | undefined,\n noTelemetry: resolveNoTelemetry(options),\n harness: options.harness as Harness | undefined,\n sequence: options.sequence as Sequence | undefined,\n model: options.model as string | undefined,\n captureAio: options.captureAio as boolean | undefined,\n ...env,\n // After the spread: yargs already resolves flag-over-env for --region,\n // so the parsed value must win over the raw env bag.\n region: (options.region ?? env.region) as CloudRegion | undefined,\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 ${modeLabel(mode)} mode`);\n\n // Before auth: a dead local PostHog otherwise surfaces as \"Failed to fetch\n // user data\". Aborts even non-interactively — a CI run pointed at a local\n // server that isn't there is testing nothing.\n const localServicesError = await checkLocalServices({\n ...getLocalDev(),\n localMcp: session.localMcp,\n localPosthog: session.baseUrl === POSTHOG_LOCAL_URL,\n });\n if (localServicesError) {\n await wizardAbort({\n code: ErrorCodes.EnvLocalServicesDown,\n message: localServicesError,\n });\n return;\n }\n\n // Headless streams run state to the PostHog backend so the web app can show\n // live progress. Reuses the interactive TaskStreamPush + WizardStore (no Ink\n // render): HeadlessUI keeps LoggingUI's output and feeds task updates into\n // the store; this runner drives the phase transitions. CI does not stream.\n let store: WizardStore | null = null;\n let taskStream: TaskStreamPush | null = null;\n if (mode === 'headless') {\n const { WizardStore } = await import('@ui/tui/store');\n const { HeadlessUI } = await import('@ui/headless-ui');\n const { TaskStreamPush, PostHogDestination } = await import(\n '@lib/task-stream/index'\n );\n\n store = new WizardStore(config.id);\n store.session = session;\n setUI(new HeadlessUI(store));\n taskStream = new TaskStreamPush({\n store,\n programId: config.id,\n destinations: [\n new PostHogDestination({\n getCredentials: () => session.credentials,\n onError: (e) => logToFile('[headless task-stream]', e.message),\n }),\n ],\n eventPlanPath: config.eventPlanFile\n ? join(session.installDir, config.eventPlanFile)\n : undefined,\n enabled: !session.noTelemetry,\n });\n taskStream.attach();\n store.setRunPhase(RunPhase.Running);\n }\n\n // wizardAbort exits via process.exit, so flush the terminal phase before any\n // exit. No-op for CI.\n const settleStream = async (\n phase: RunPhaseT,\n outroData?: OutroData,\n ): Promise<void> => {\n if (!store || !taskStream) return;\n if (outroData) store.setOutroData(outroData);\n store.setRunPhase(phase);\n await taskStream.shutdown(2000);\n };\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 // Non-interactive session is a plain object (no nanostore\n // copy-on-write), so direct assignment is safe here.\n setSkillId: (skillId: string | null) => {\n session.skillId = skillId;\n },\n setUnsupportedVersion: (info: {\n current: string;\n minimum: string;\n docsUrl: string;\n }) => {\n session.unsupportedVersion = info;\n },\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 (session.unsupportedVersion) {\n const { current, minimum, docsUrl } = session.unsupportedVersion;\n const message = `Detected framework version ${current} is not supported. Minimum supported version is ${minimum}.`;\n await settleStream(RunPhase.Error, {\n kind: OutroKind.Error,\n message,\n errorCode: ErrorCodes.DetectUnsupportedVersion,\n });\n await wizardAbort({\n code: ErrorCodes.DetectUnsupportedVersion,\n message: `${message}\\n\\nSee ${docsUrl}`,\n error: new WizardError(\n `${config.id} unsupported framework version`,\n {\n integration: config.id,\n current,\n minimum,\n },\n ErrorCodes.DetectUnsupportedVersion,\n ),\n });\n }\n if (detectError) {\n const code = detectErrorCode(detectError.kind);\n const detectKind = detectError.kind;\n // `kind` stays in the detail: several kinds share one code, so it is\n // the only thing telling a host which precondition actually failed.\n const detail = { ...detectError };\n await settleStream(RunPhase.Error, {\n kind: OutroKind.Error,\n message: `Prerequisites not met: ${detectKind}`,\n errorCode: code,\n errorDetail: detail,\n });\n await wizardAbort({\n code,\n detail,\n message: `Prerequisites not met: ${detectKind}\\n\\nSee ${\n runDef?.docsUrl ?? POSTHOG_DOCS_URL\n }`,\n error: new WizardError(\n `${config.id} prerequisites failed`,\n {\n integration: config.id,\n detect_error_kind: detectKind,\n },\n code,\n ),\n });\n }\n }\n\n const { runAgent } = await import('@lib/agent/agent-runner');\n await runAgent(config, session);\n await settleStream(RunPhase.Completed);\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(`[${mode}] ERROR: ${errorMessage}`);\n if (errorStack) logToFile(`[${mode}] 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 settleStream(RunPhase.Error, {\n kind: OutroKind.Error,\n message: errorMessage,\n errorCode: ErrorCodes.InternalUnhandled,\n });\n await wizardAbort({\n code: ErrorCodes.InternalUnhandled,\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((error: unknown) => {\n emitWizardError({\n code: ErrorCodes.InternalUnhandled,\n message: error instanceof Error ? error.message : String(error),\n });\n process.exit(1);\n });\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { runNonInteractive } from './run-non-interactive';\n\n/**\n * CI-mode entry point (`--ci`, dev/test builds). A thin shell over the shared\n * non-interactive pipeline — see `runNonInteractive`. Kept as its own function\n * so CI and headless (`runWizardHeadless`) can diverge without re-threading the\n * many callers that route here.\n */\nexport function runWizardCI(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n runNonInteractive(config, options, 'ci');\n}\n","import type { ProgramConfig } from '@lib/programs/program-step';\nimport { runNonInteractive } from './run-non-interactive';\n\n/**\n * Headless entry point (the experimental published-build, non-interactive run\n * path; see @lib/headless-mode). A thin shell over the shared non-interactive\n * pipeline — see `runNonInteractive`. Today it behaves exactly like\n * `runWizardCI`; it exists as a separate function so headless can diverge later\n * (its own auth handling, telemetry, prompts, …) without touching CI or its\n * callers. Diverge by branching on the mode inside `runNonInteractive`, or by\n * giving this function its own body.\n */\nexport function runWizardHeadless(\n config: ProgramConfig,\n options: Record<string, unknown>,\n): void {\n runNonInteractive(config, options, 'headless');\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 unique to skill commands live here. Global flags are declared\n * once in `wizard.ts` — both in `GLOBAL_OPTIONS` and, for the dev-only ones,\n * the `Wizard` constructor — and apply to every command automatically.\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, runWizardHeadless } from '@lib/runners';\nimport { isHeadless } from '@lib/headless-mode';\nimport type { ProgramConfig } from '@lib/programs/program-step';\n\nimport { skillProgramOptions } from '../skill-program-options';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\n\n/**\n * Dispatch a parsed yargs invocation to the wizard runner. Applies the\n * program's `mapCliOptions` transform, then routes to `runWizardHeadless`,\n * `runWizardCI`, or `runWizard` based on the headless / `--ci` flags.\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 emitWizardError({ code: ErrorCodes.InternalUnhandled, message: msg });\n process.exit(1);\n }\n })();\n}\n\nexport function dispatchProgram(config: ProgramConfig, argv: Arguments): void {\n const argvRecord: Record<string, unknown> = { ...argv };\n const extras = config.mapCliOptions?.(argvRecord) ?? {};\n const options = { ...argvRecord, ...extras };\n if (isHeadless(options)) {\n // Same non-interactive pipeline `--ci` uses; validation (api-key,\n // install-dir, region) is owned by runNonInteractive.\n runWizardHeadless(config, options);\n } else 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 { 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 { mcpAnalyticsConfig } from '@lib/programs/mcp-analytics/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard mcp-analytics` — flat skill command, instrument-an-MCP-server today.\n *\n * Distinct from `wizard mcp add`: this instruments the user's own MCP server\n * with the `@posthog/mcp` SDK, rather than installing the PostHog MCP server\n * into a coding agent. Stays flat while instrumenting is the only action.\n */\nexport const mcpAnalyticsCommand: Command =\n nativeCommandFactory(mcpAnalyticsConfig);\n","import { replayVisionConfig } from '@lib/programs/replay-vision/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard replay-vision` — flat skill command, set up Replay vision today.\n *\n * Enables session replay recording and creates vision scanners tailored to\n * the product's key flows. Runs the `replay-vision` orchestrator flow, which\n * reuses the integration-v2 install/init mini-agents when the repo has no\n * PostHog integration yet.\n */\nexport const replayVisionCommand: Command =\n nativeCommandFactory(replayVisionConfig);\n","import { aiObservabilityConfig } from '@lib/programs/ai-observability/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard ai-observability` — flat skill command, wire AI Observability into a\n * project today.\n *\n * Installs the OpenTelemetry SDK, the PostHog span processor, and the\n * provider-specific instrumentation so LLM calls emit `$ai_generation` events.\n * The `ai-observability` context-mill skill has one variant per (LLM provider ×\n * language); the agent picks the right one at run time by scanning the\n * project's manifest and (when ambiguous) asking the user via `wizard_ask`.\n * Stays flat while a single \"add AIO to a project\" flow is the only action.\n */\nexport const aiObservabilityCommand: Command = nativeCommandFactory(\n aiObservabilityConfig,\n);\n","import { metricsConfig } from '@lib/programs/metrics/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard metrics` — flat skill command, wire PostHog application metrics\n * (counters, gauges, histograms via \\`posthog.metrics\\`) into a project.\n *\n * The `metrics` context-mill skill has one variant per platform (python,\n * nodejs, javascript, kubernetes, other/OTLP); the agent picks the right one\n * at run time by scanning the project's manifest and (when ambiguous) asking\n * the user via `wizard_ask`. Stays flat while a single \"add metrics to a\n * project\" flow is the only action.\n */\nexport const metricsCommand: Command = nativeCommandFactory(metricsConfig);\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';\nimport { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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 emitWizardError({ code: ErrorCodes.CliBadArgs, message: reason });\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();\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 * Filter-as-you-type matching for PickerMenu. Split out from the component so the\n * ranking is testable on its own — the component only decides when to call it.\n */\n\nimport Fuse, { type IFuseOptions } from 'fuse.js';\n\n/** The searchable face of a picker option. PickerMenu's `PickerOption<T>` satisfies it. */\nexport interface Searchable {\n label: string;\n hint?: string;\n description?: string;\n}\n\n/**\n * Fuzzy fallback config. `ignoreLocation` because a term matching at the end of a\n * description is as good as one at the start, and Fuse's default distance window\n * would score the late match away. 0.5 is the loosest threshold that still bottoms\n * out: below it `gthb` misses `GitHub` entirely, which is the whole point of having\n * a fuzzy pass; above it the tail grows without surfacing anything new at the top.\n */\nexport const FUSE_OPTIONS: IFuseOptions<Searchable> = {\n keys: [\n { name: 'label', weight: 3 },\n { name: 'hint', weight: 1 },\n { name: 'description', weight: 1 },\n ],\n ignoreLocation: true,\n threshold: 0.5,\n includeScore: true,\n};\n\nexport function buildPickerIndex<T extends Searchable>(options: T[]): Fuse<T> {\n return new Fuse(options, FUSE_OPTIONS as IFuseOptions<T>);\n}\n\nfunction haystack(option: Searchable): string {\n return `${option.label} ${option.hint ?? ''} ${\n option.description ?? ''\n }`.toLowerCase();\n}\n\n/**\n * Rank options against a query, best first, or `null` for an empty query.\n *\n * Two passes, literal before fuzzy. Anything that literally contains every\n * whitespace-separated term wins outright, in the list's own order — that covers how\n * people actually type (`git iss` → `GitHub issues`) and keeps the common case as\n * tight as a plain substring filter, which fuzzy matching on its own is not: Fuse at\n * a threshold loose enough to forgive `gthb` also lets a third of the list through\n * on `replay`.\n *\n * Only when nothing matches literally does Fuse get a turn, so a typo degrades to a\n * ranked guess instead of an empty list. Terms are AND-ed there too, each matched\n * fuzzily on its own — Fuse's bitap pass over the whole query would otherwise need\n * `git iss` to be a near-edit of the text it's matching. Scores are distances (0 is\n * exact) and sum across terms, hence the ascending sort; ties keep the order the\n * first term put them in, since the sort is stable.\n */\nexport function rankOptions<T extends Searchable>(\n fuse: Fuse<T>,\n options: T[],\n query: string,\n): T[] | null {\n const terms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n if (!terms.length) {\n return null;\n }\n\n const literal = options.filter((option) =>\n terms.every((term) => haystack(option).includes(term)),\n );\n if (literal.length) {\n return literal;\n }\n\n let surviving: Map<T, number> | null = null;\n for (const term of terms) {\n const hits = new Map<T, number>(\n fuse.search(term).map(({ item, score }) => [item, score ?? 0]),\n );\n if (surviving === null) {\n surviving = hits;\n continue;\n }\n // Deleting the current key mid-iteration is well-defined for a Map.\n for (const [option, total] of surviving) {\n const score = hits.get(option);\n if (score === undefined) {\n surviving.delete(option);\n } else {\n surviving.set(option, total + score);\n }\n }\n }\n\n return [...(surviving ?? [])]\n .sort(([, a], [, b]) => a - b)\n .map(([option]) => option);\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 // No message → no row, so label-less pickers don't get a stray blank line.\n if (!message) return null;\n return (\n <Box>\n <Text bold color={Colors.accent}>\n {' '}\n {message}\n </Text>\n </Box>\n );\n};\n","/**\n * ConfirmButton — the confirm row used to submit a selection.\n *\n * Pure render. Multi-select menus (PickerMenu mode=\"multi\", GroupedPickerMenu)\n * append this below their options as the final focusable row: the user toggles\n * options with enter, then arrows down onto this row and presses enter to\n * submit. This replaces the older \"enter anywhere submits\" pattern, which\n * confused people who expected enter to toggle the focused item.\n *\n * Renders flat, mirroring the option rows — a focus triangle and the label,\n * accent and bold when focused, dimmed otherwise — so it lines up under the\n * options instead of sitting in a separate boxed target.\n */\n\nimport { Text } from 'ink';\nimport { Icons, Colors } from '@ui/tui/styles';\n\ninterface ConfirmButtonProps {\n /** Button text. Defaults to \"Confirm\". */\n label?: string;\n /** Whether the cursor is currently on the button. */\n focused: boolean;\n /** Optional selected-item count, rendered as \"Label (n)\" when > 0. */\n count?: number;\n}\n\nexport const ConfirmButton = ({\n label = 'Confirm',\n focused,\n count,\n}: ConfirmButtonProps) => {\n const text = count && count > 0 ? `${label} (${count})` : label;\n return (\n <Text\n color={focused ? Colors.accent : undefined}\n bold={focused}\n dimColor={!focused}\n >\n {focused ? Icons.triangleSmallRight : ' '} {text}\n </Text>\n );\n};\n","/**\n * useStdoutDimensions — Returns [columns, rows] and re-renders on terminal resize.\n *\n * Ink's useStdout() does not subscribe to resize events, so layout only updates\n * when something else causes a re-render. This hook listens to the stream's\n * 'resize' event (Node TTY) and updates state so the component re-renders\n * with the new dimensions.\n */\n\nimport { useStdout } from 'ink';\nimport { useState, useEffect } from 'react';\n\nexport function useStdoutDimensions(): [number, number] {\n const { stdout } = useStdout();\n const [size, setSize] = useState<[number, number]>(() => [\n stdout.columns || 80,\n stdout.rows || 24,\n ]);\n\n useEffect(() => {\n const cols = stdout.columns || 80;\n const rows = stdout.rows || 24;\n setSize([cols, rows]);\n\n const stream = stdout as NodeJS.WriteStream & {\n on?(event: string, fn: () => void): void;\n };\n if (typeof stream.on !== 'function') return;\n\n const onResize = () => {\n const c = stdout.columns || 80;\n const r = stdout.rows || 24;\n if (c > 0 && r > 0) setSize([c, r]);\n };\n stream.on('resize', onResize);\n return () => {\n stream.off?.('resize', onResize);\n };\n }, [stdout]);\n\n return size;\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 Backspace = 'backspace',\n /**\n * Any single printable character typed without a modifier. Broad by design,\n * so a binding using it must sit last — the first match wins, which is what\n * lets a specific char binding still take precedence over free typing.\n */\n Printable = 'printable',\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.Printable]: 12,\n [KeyMatch.Backspace]: 13,\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 case KeyMatch.Backspace:\n return !!key.backspace || !!key.delete;\n case KeyMatch.Printable:\n // Ink sets a flag for every non-text key while still passing a non-empty\n // `input`, so any flag but shift rules out typing.\n // Any single non-control character, not just ASCII — a filter query can\n // hold an accented or non-Latin letter.\n return (\n input.length === 1 &&\n input >= ' ' &&\n input !== '\\x7f' &&\n Object.entries(key).every(([flag, on]) => !on || flag === 'shift')\n );\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; enter selects.\n * Multi mode: checkbox glyphs toggled with enter, plus a focusable\n * Confirm button below the options. The cursor moves onto the button and\n * enter submits — see MultiPickerMenu for the rationale.\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, useMemo, useState } from 'react';\nimport { buildPickerIndex, rankOptions } from './picker-filter.js';\nimport { Icons, Colors } from '@ui/tui/styles';\nimport { PromptLabel } from './PromptLabel.js';\nimport { ConfirmButton } from './ConfirmButton.js';\nimport { wordWrap } from './layout-helpers.js';\nimport { useStdoutDimensions } from '@ui/tui/hooks/useStdoutDimensions';\nimport {\n useKeyBindings,\n KeyMatch,\n type KeyBinding,\n type KeyMatchOrChar,\n} from '@ui/tui/hooks/useKeyBindings';\n\nexport interface PickerOption<T> {\n label: string;\n value: T;\n hint?: string;\n /**\n * Multi-select only: a secondary explanation rendered dimmed and wrapped on\n * its own line(s) beneath the label, for choices that need more than a title.\n * When unset, the row renders exactly as a label-only row.\n */\n description?: 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 * Section heading: unselectable (navigation skips it, like `disabled`) but\n * rendered as a bold header rather than a muted row. Set `disabled` too so\n * the skip logic treats it as non-selectable.\n */\n header?: boolean;\n /** Indent the label one level, e.g. items nested under a `header` row. */\n indent?: 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/** First enabled option in [start, end), for initial focus and for entering\n * a page from the Confirm button. */\nfunction firstEnabled<T>(\n options: PickerOption<T>[],\n start = 0,\n end = options.length,\n): number {\n for (let i = start; i < end; i++) {\n if (!options[i]?.disabled) return i;\n }\n return start;\n}\n\n/** Last enabled option in [start, end), for wrapping from the button onto\n * the bottom of the page. */\nfunction lastEnabled<T>(\n options: PickerOption<T>[],\n start = 0,\n end = options.length,\n): number {\n for (let i = end - 1; i >= start; i--) {\n if (!options[i]?.disabled) return i;\n }\n return end - 1;\n}\n\n/**\n * Rows the surrounding screen or overlay consumes above and below a picker —\n * border + padding, title, prompt text, and the keyboard-hints bar. A\n * deliberately generous estimate: overshooting just shows a few fewer rows,\n * whereas undershooting lets a long list overflow the viewport (the bug this\n * windowing guards against). Mirrors GroupedPickerMenu's budgeting.\n */\nconst CHROME_OVERHEAD = 13;\n/**\n * Max visual rows a picker renders regardless of terminal height. Without a\n * ceiling a tall terminal lets a long list fill the whole viewport, which\n * reads as a wall of options; ~12 rows keeps the menu scannable and leaves\n * known breathing room above and below.\n */\nconst MAX_LIST_ROWS = 12;\n/** Extra rows a multi-select adds below its options: marginTop + Confirm button. */\nconst CONFIRM_CHROME = 3;\n/** Lists shorter than this never page — tall rows would split 2-3 options into pages of one. */\nconst MIN_COUNT_TO_PAGE = 5;\n/** Width the multi-select wraps option descriptions to (matches the render). */\nconst DESCRIPTION_WIDTH = 56;\n\ninterface PickerViewport {\n needsScroll: boolean;\n /** First option index on the current page. */\n start: number;\n /** One past the last option index on the current page. */\n end: number;\n hiddenAbove: number;\n hiddenBelow: number;\n /** Focus target one page over (wrapping), for the n/p keys. */\n pageStep: (focused: number, dir: 1 | -1) => number;\n}\n\n/**\n * Pages a single-column option list to the terminal height. The visible page\n * is derived from the focused index — no scroll state — so ↑/↓ flip pages as\n * focus crosses a page edge and n/p jump a whole page. Pages hold a fixed\n * option count sized to the tallest row (`rowCost`), trading a sparser page\n * on mixed-height lists for arithmetic-only paging. Engages only for\n * single-column pickers — multi-column grids already compress vertically.\n */\nfunction usePickerViewport(\n count: number,\n rowCost: number,\n chromeBelow: number,\n enabled: boolean,\n focused: number,\n): PickerViewport {\n const [, termRows] = useStdoutDimensions();\n const budget = Math.max(\n 5,\n Math.min(termRows - CHROME_OVERHEAD - chromeBelow, MAX_LIST_ROWS),\n );\n const needsScroll =\n enabled && count >= MIN_COUNT_TO_PAGE && count * rowCost > budget;\n // Reserve two rows for the \"↑/↓ N more\" indicators.\n const perPage = needsScroll\n ? Math.max(1, Math.floor((budget - 2) / rowCost))\n : count;\n const pageCount = Math.max(1, Math.ceil(count / perPage));\n const start = Math.floor(focused / perPage) * perPage;\n const end = Math.min(start + perPage, count);\n return {\n needsScroll,\n start,\n end,\n hiddenAbove: start,\n hiddenBelow: count - end,\n pageStep: (f, dir) =>\n ((Math.floor(f / perPage) + dir + pageCount) % pageCount) * perPage,\n };\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 /**\n * Filter-as-you-type. Defaults on once the list is long enough to page, where\n * finding one option means walking pages. Pass `false` to force it off.\n */\n filterable?: boolean;\n onSelect: (value: T | T[]) => void;\n}\n\n/** Lists at least this long get filtering. Shorter ones fit on a page or two,\n * where a filter row costs more rows than it saves. */\nconst FILTER_MIN_OPTIONS = 10;\n\nexport const PickerMenu = <T,>({\n message,\n options,\n mode = 'single',\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n filterable,\n onSelect,\n}: PickerMenuProps<T>) => {\n const canFilter = filterable ?? options.length >= FILTER_MIN_OPTIONS;\n const [filter, setFilter] = useState('');\n const fuse = useMemo(\n () => (canFilter ? buildPickerIndex(options) : null),\n [options, canFilter],\n );\n const visible = useMemo(\n () => (fuse ? rankOptions(fuse, options, filter) ?? options : options),\n [fuse, options, filter],\n );\n\n // Keyed by label, and owned here rather than by MultiPickerMenu: filtering\n // rewrites the list under the ticks, and the remount below would drop them.\n const [selected, setSelected] = useState<Set<string>>(new Set());\n\n const shared = {\n message,\n options: visible,\n centered,\n optionMarginBottom,\n onSelect,\n filter: canFilter ? filter : null,\n setFilter,\n totalCount: options.length,\n };\n\n // A filtered list is a fresh list with its own focus and paging, so remount on\n // each query rather than leaving stale indices to be re-validated.\n const key = String(filter);\n\n if (mode === 'multi') {\n return (\n <MultiPickerMenu\n key={key}\n {...shared}\n columns={columns}\n allOptions={options}\n selected={selected}\n setSelected={setSelected}\n />\n );\n }\n\n return <SinglePickerMenu key={key} {...shared} columns={columns} />;\n};\n\n/**\n * Backspace and free typing. Append these last: `Printable` matches almost any\n * key, and bindings resolve in order, so anything specific has to be registered\n * first to keep working. Both share a label/action so the hints bar shows one.\n */\nfunction filterBindings(\n filter: string,\n setFilter: (query: string) => void,\n): KeyBinding[] {\n return [\n {\n match: KeyMatch.Backspace,\n label: 'type',\n action: 'filter',\n handler: () => setFilter(filter.slice(0, -1)),\n },\n {\n match: KeyMatch.Printable,\n label: 'type',\n action: 'filter',\n handler: (input: string) => setFilter(filter + input),\n },\n ];\n}\n\n/** The filter row above a filterable list: what's typed, and how much it left. */\nconst FilterRow = ({\n filter,\n shown,\n total,\n}: {\n filter: string;\n shown: number;\n total: number;\n}) => (\n <Box>\n <Text dimColor>\n {filter\n ? `Filter: ${filter} (${shown} of ${total})`\n : `Type to filter ${total} options`}\n </Text>\n </Box>\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 filter,\n setFilter,\n totalCount,\n onSelect,\n}: {\n message?: string;\n options: PickerOption<T>[];\n centered?: boolean;\n columns?: number;\n optionMarginBottom?: number;\n /** Current filter query, or null when this picker isn't filterable. */\n filter: string | null;\n setFilter: (query: string) => void;\n totalCount: number;\n onSelect: (value: T | T[]) => void;\n}) => {\n const [focused, setFocused] = useState(() => firstEnabled(options));\n const rows = Math.ceil(options.length / columns);\n // Single-select rows are label-only (no descriptions): one line plus margin.\n const viewport = usePickerViewport(\n options.length,\n 1 + optionMarginBottom,\n filter !== null ? 1 : 0,\n columns === 1,\n focused,\n );\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 const dir = key.upArrow ? -1 : 1;\n // `start`/`end` derive from `focused`, so stepping past a page edge\n // flips the page rather than needing a bound here.\n setFocused(stepEnabled(options, rows, focused, dir));\n },\n },\n // Only on a non-filterable list. Once a filter row exists `n` and `p` are\n // characters, not commands — so they go for good, not just once a query is\n // typed, and the arrows carry paging instead by walking the whole list.\n ...(viewport.needsScroll && filter === null\n ? [\n {\n match: ['n', 'p'] as KeyMatchOrChar[],\n label: 'n/p',\n action: 'page',\n handler: (input: string) => {\n const target = viewport.pageStep(focused, input === 'n' ? 1 : -1);\n setFocused(\n options[target]?.disabled\n ? stepEnabled(options, rows, target, 1)\n : target,\n );\n },\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 if (filter !== null) {\n bindings.push(...filterBindings(filter, setFilter));\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 const renderOption = (opt: PickerOption<T>, flatIdx: number) => {\n const isFocused = flatIdx === focused;\n const base = opt.hint ? `${opt.label} (${opt.hint})` : opt.label;\n const label = opt.indent ? ` ${base}` : base;\n return (\n <Box key={flatIdx} gap={1} marginBottom={optionMarginBottom}>\n <Text\n color={isFocused ? Colors.accent : undefined}\n dimColor={!isFocused}\n >\n {isFocused && !opt.header ? Icons.triangleSmallRight : ' '}\n </Text>\n {opt.icon && <Text color={opt.icon.color}>{opt.icon.glyph}</Text>}\n <Text\n color={\n opt.header\n ? undefined\n : opt.disabled\n ? Colors.muted\n : isFocused\n ? Colors.accent\n : undefined\n }\n bold={opt.header || (isFocused && !opt.disabled)}\n dimColor={!opt.header && (!isFocused || opt.disabled)}\n >\n {label}\n </Text>\n </Box>\n );\n };\n\n return (\n <Box flexDirection=\"column\" alignItems={align}>\n <PromptLabel message={message} />\n {filter !== null && (\n <FilterRow filter={filter} shown={options.length} total={totalCount} />\n )}\n {filter && options.length === 0 ? (\n <Text dimColor>No options match. Backspace to widen the filter.</Text>\n ) : viewport.needsScroll ? (\n <Box flexDirection=\"column\">\n <Text dimColor>\n {viewport.hiddenAbove > 0\n ? `↑ ${viewport.hiddenAbove} more${\n filter === null ? ' [P] for previous page' : ''\n }`\n : ' '}\n </Text>\n {options\n .slice(viewport.start, viewport.end)\n .map((opt, relIdx) => renderOption(opt, viewport.start + relIdx))}\n <Text dimColor>\n {viewport.hiddenBelow > 0\n ? `↓ ${viewport.hiddenBelow} more${\n filter === null ? ' [N] for next page' : ''\n }`\n : ' '}\n </Text>\n </Box>\n ) : (\n <Box flexDirection=\"row\" gap={4}>\n {columnArrays.map((colOpts, colIdx) => (\n <Box key={colIdx} flexDirection=\"column\">\n {colOpts.map((opt, rowIdx) =>\n renderOption(opt, colIdx * rows + rowIdx),\n )}\n </Box>\n ))}\n </Box>\n )}\n </Box>\n );\n};\n\n/**\n * Custom multi-select with checkbox glyphs and accent highlight.\n *\n * Interaction model (shared with GroupedPickerMenu):\n * - \\u2191\\u2193 move the cursor through the options AND onto the Confirm button,\n * which lives just past the last option.\n * - enter toggles the focused option (no more \"space toggles but enter\n * advances\" split that tripped people up). Space is kept as an\n * undocumented alias, but the hints bar advertises only enter.\n * - moving onto the Confirm button and pressing enter submits the\n * current selection.\n */\nconst MultiPickerMenu = <T,>({\n message,\n options,\n centered = false,\n columns = 1,\n optionMarginBottom = 0,\n filter,\n setFilter,\n totalCount,\n allOptions,\n selected,\n setSelected,\n onSelect,\n}: {\n message?: string;\n options: PickerOption<T>[];\n centered?: boolean;\n columns?: number;\n optionMarginBottom?: number;\n /** Current filter query, or null when this picker isn't filterable. */\n filter: string | null;\n setFilter: (query: string) => void;\n totalCount: number;\n /** Every option, filtered or not. Ticks outlive the query, so resolving and\n * submitting them has to happen against the full list. */\n allOptions: PickerOption<T>[];\n selected: Set<string>;\n setSelected: (update: (prev: Set<string>) => Set<string>) => void;\n onSelect: (value: T | T[]) => void;\n}) => {\n const [focused, setFocused] = useState(() => firstEnabled(options));\n // When true, the cursor is on the Confirm button rather than an option.\n const [onButton, setOnButton] = useState(false);\n const rows = Math.ceil(options.length / columns);\n // A row is its label line plus any margin; a description adds one line per\n // wrapped line beneath the label. Pages size to the tallest row.\n const rowCost = options.reduce(\n (max, opt) =>\n Math.max(\n max,\n 1 +\n optionMarginBottom +\n (opt.description\n ? wordWrap(opt.description, DESCRIPTION_WIDTH).length\n : 0),\n ),\n 1,\n );\n const viewport = usePickerViewport(\n options.length,\n rowCost,\n CONFIRM_CHROME + (filter !== null ? 1 : 0),\n columns === 1,\n focused,\n );\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 confirm = () => {\n // In `allOptions` order, so a pick made under one filter still submits\n // after the query moved on.\n const values = allOptions\n .filter((option) => selected.has(option.label))\n .map((option) => option.value);\n onSelect(values);\n };\n\n const bindings: KeyBinding[] = [\n {\n match: [KeyMatch.UpArrow, KeyMatch.DownArrow],\n label: '\\u2191\\u2193',\n action: 'navigate',\n handler: (_input, key) => {\n const dir = key.upArrow ? -1 : 1;\n if (onButton) {\n // Button \\u2192 back onto the current page (bottom for \\u2191, top for \\u2193).\n setOnButton(false);\n setFocused(\n dir === -1\n ? lastEnabled(options, viewport.start, viewport.end)\n : firstEnabled(options, viewport.start, viewport.end),\n );\n return;\n }\n const col = Math.floor(focused / rows);\n const row = focused % rows;\n const colLen = Math.min(rows, options.length - col * rows);\n // Nearest enabled option above/below in this column; leaving the\n // column lands on the button.\n let r = row + dir;\n while (r >= 0 && r < colLen && options[col * rows + r]?.disabled) {\n r += dir;\n }\n if (r >= 0 && r < colLen) {\n setFocused(col * rows + r);\n } else {\n setOnButton(true);\n }\n },\n },\n // Only on a non-filterable list. Once a filter row exists `n` and `p` are\n // characters, not commands — so they go for good, not just once a query is\n // typed, and the arrows carry paging instead by walking the whole list.\n ...(viewport.needsScroll && filter === null\n ? [\n {\n match: ['n', 'p'] as KeyMatchOrChar[],\n label: 'n/p',\n action: 'page',\n handler: (input: string) => {\n const target = viewport.pageStep(focused, input === 'n' ? 1 : -1);\n setOnButton(false);\n setFocused(\n options[target]?.disabled\n ? stepEnabled(options, rows, target, 1)\n : target,\n );\n },\n },\n ]\n : []),\n {\n // Space is only an alias for enter when there's no filter to type into.\n match:\n filter !== null ? KeyMatch.Return : [KeyMatch.Space, KeyMatch.Return],\n label: 'enter',\n action: 'select',\n handler: () => {\n if (onButton) {\n confirm();\n return;\n }\n // `focused` can point past the end: filtering to zero matches leaves\n // nothing under the cursor, and enter is the natural thing to try there.\n const option = options[focused];\n if (!option || option.disabled) return;\n const label = option.label;\n setSelected((prev) => {\n const next = new Set(prev);\n if (next.has(label)) {\n next.delete(label);\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 (option.exclusive) {\n return new Set([label]);\n }\n // Against `allOptions`: the pick being cleared may be off-screen\n // under the current query.\n for (const picked of next) {\n if (allOptions.find((o) => o.label === picked)?.exclusive) {\n next.delete(picked);\n }\n }\n next.add(label);\n return next;\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 if (onButton) return;\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 if (filter !== null) {\n bindings.push(...filterBindings(filter, setFilter));\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 const renderOption = (opt: PickerOption<T>, flatIdx: number) => {\n const isFocused = !onButton && flatIdx === focused;\n const isSelected = selected.has(opt.label);\n const label = opt.hint ? `${opt.label} (${opt.hint})` : opt.label;\n const checkbox = isSelected ? Icons.squareFilled : Icons.squareOpen;\n return (\n <Box\n key={flatIdx}\n flexDirection=\"column\"\n marginBottom={optionMarginBottom}\n >\n <Box gap={1}>\n <Text\n color={isSelected ? 'white' : Colors.muted}\n dimColor={!isFocused && !isSelected}\n >\n {checkbox}\n </Text>\n {opt.icon && <Text color={opt.icon.color}>{opt.icon.glyph}</Text>}\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 {/* Optional dimmed, wrapped explanation under the label. The explicit\n width forces Ink to wrap (an unconstrained Box shrinks to its\n content and never wraps). Renders only when set, so label-only rows\n are byte-for-byte unchanged. */}\n {opt.description && (\n <Box marginLeft={4} width={DESCRIPTION_WIDTH}>\n <Text dimColor wrap=\"wrap\">\n {opt.description}\n </Text>\n </Box>\n )}\n </Box>\n );\n };\n\n return (\n <Box flexDirection=\"column\" alignItems={centered ? 'center' : undefined}>\n <PromptLabel message={message} />\n {filter !== null && (\n <FilterRow filter={filter} shown={options.length} total={totalCount} />\n )}\n {filter && options.length === 0 && (\n <Text dimColor>No options match. Backspace to widen the filter.</Text>\n )}\n {viewport.needsScroll ? (\n <Box\n flexDirection=\"column\"\n marginLeft={centered ? 0 : 2}\n marginTop={message ? 1 : 0}\n >\n <Text dimColor>\n {viewport.hiddenAbove > 0\n ? `↑ ${viewport.hiddenAbove} more${\n filter === null ? ' [P] for previous page' : ''\n }`\n : ' '}\n </Text>\n {options\n .slice(viewport.start, viewport.end)\n .map((opt, relIdx) => renderOption(opt, viewport.start + relIdx))}\n <Text dimColor>\n {viewport.hiddenBelow > 0\n ? `↓ ${viewport.hiddenBelow} more${\n filter === null ? ' [N] for next page' : ''\n }`\n : ' '}\n </Text>\n </Box>\n ) : (\n <Box\n flexDirection=\"row\"\n gap={4}\n marginLeft={centered ? 0 : 2}\n marginTop={message ? 1 : 0}\n >\n {columnArrays.map((colOpts, colIdx) => (\n <Box key={colIdx} flexDirection=\"column\">\n {colOpts.map((opt, rowIdx) =>\n renderOption(opt, colIdx * rows + rowIdx),\n )}\n </Box>\n ))}\n </Box>\n )}\n <Box marginTop={1} marginLeft={centered ? 0 : 2}>\n <ConfirmButton focused={onButton} count={selected.size} />\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();\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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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 emitWizardError({\n code: ErrorCodes.ArgsMissingApiKey,\n message: 'CI mode requires --api-key (personal API key phx_xxx)',\n });\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 baseUrl: options.baseUrl as string | undefined,\n });\n\n const issues = await fetchHealthIssues(\n accessToken,\n host.apiHost,\n projectId,\n );\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 emitWizardError({\n code:\n error instanceof ApiError && error.statusCode === 401\n ? ErrorCodes.AuthInvalidOrExpired\n : ErrorCodes.InternalUnhandled,\n message,\n });\n process.exit(1);\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 { warehouseSourceConfig } from '@lib/programs/warehouse-source/index';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard warehouse` — detect and connect a data warehouse source.\n *\n * Mirrors `revenue-analytics`: flat skill command driven by the\n * warehouse-source program.\n */\nexport const warehouseCommand: Command = nativeCommandFactory(\n warehouseSourceConfig,\n);\n","import { runWizard, runWizardCI } from '@lib/runners';\nimport { selfDrivingConfig } from '@lib/programs/self-driving/index';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const selfDrivingCommand: Command = {\n name: 'self-driving',\n description: selfDrivingConfig.description,\n options: {\n ...skillProgramOptions,\n integrate: {\n describe:\n 'Integrate the PostHog SDK first, then set up Self-driving — skips the integration prompt and logs you in via OAuth (no \"create an account?\" question). Use when the project isn\\'t set up yet but you already have a PostHog account.',\n type: 'boolean',\n default: false,\n },\n ...(selfDrivingConfig.cliOptions ?? {}),\n },\n check: (argv) => {\n // self-driving builds on an existing integration and is fully interactive,\n // so the modes that break it are rejected before the TUI/agent loop spins\n // up rather than failing late (a 403 on the first MCP probe under --signup,\n // or a stalled `wizard_ask` with no bridge under --ci).\n if (argv.signup) {\n throw new Error(\n '`self-driving` cannot run with --signup. Just run `wizard ' +\n 'self-driving`: when your project has no PostHog, it asks whether ' +\n 'you already have an account and offers to create one for you ' +\n '(no flag needed).',\n );\n }\n if (argv.ci) {\n throw new Error(\n '`self-driving` cannot run in CI mode — it requires interactive steps ' +\n '(GitHub connect, issue-tracker selection, custom-scout approval).',\n );\n }\n return true;\n },\n handler: (argv) => {\n const extras =\n selfDrivingConfig.mapCliOptions?.(argv as Record<string, unknown>) ?? {};\n const options = { ...argv, ...extras };\n if (options.ci) {\n runWizardCI(selfDrivingConfig, options);\n } else {\n runWizard(selfDrivingConfig, 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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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({\n debug,\n baseUrl: argv.baseUrl as string | undefined,\n });\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 emitWizardError({\n code: ErrorCodes.CliInteractiveRequired,\n message: 'Connecting Slack requires an interactive terminal.',\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 { ErrorCodes } from '@lib/errors';\nimport { emitWizardError } from '@lib/errors';\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\n/**\n * Reject an unknown skill id before the wizard authenticates.\n *\n * Without this, `readSkillName` accepts any non-empty string and the name is\n * only validated far downstream, when the agent tries to download it — after\n * the user has already logged in. A typo then costs a full auth round-trip\n * (the concern raised in review). We resolve against the same set\n * `downloadSkill` uses (`categories` flattened by `id`), so this never\n * false-rejects a skill the download would have accepted.\n *\n * If the registry is unreachable we stay silent and defer to the download\n * step's own `menu-fetch-failed` handling, rather than adding a second network\n * dependency that could block an otherwise-valid run.\n */\nasync function assertSkillExists(skillName: string): Promise<void> {\n const skillsBaseUrl = getSkillsBaseUrl();\n const menu = await fetchSkillMenu(skillsBaseUrl);\n if (!menu) return; // registry down — let the download step surface it\n const known = Object.values(menu.categories)\n .flat()\n .some((s) => s.id === skillName);\n if (known) return;\n analytics.wizardCapture('cli dispatch error', {\n reason: 'unknown skill',\n family: 'skill',\n sub: skillName,\n skillsBaseUrl,\n });\n try {\n await analytics.flush();\n } catch {\n /* best-effort */\n }\n throw new Error(\n `Unknown skill \"${skillName}\". Run \\`wizard skill list\\` to see available skills.`,\n );\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: () => {\n runCommandHandler(async () => {\n const skillsBaseUrl = getSkillsBaseUrl();\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 emitWizardError({\n code: ErrorCodes.SkillMenuFetchFailed,\n message: \"Couldn't reach the skill registry.\",\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 // Under `.strictOptions()` yargs rejects a positional declared only in the\n // command string as an \"Unknown argument\" — it has to be registered via\n // `.positional()` too (see the `positionals` note on the Command interface).\n // Declare `skill-name` here so `wizard skill <id>` actually accepts its value.\n positionals: {\n 'skill-name': {\n type: 'string',\n describe: 'Skill id to run (e.g. audit-events), or `list`',\n },\n },\n // yargs already enforces the presence of the `<skill-name>` positional, but\n // an 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 runCommandHandler(async () => {\n const skillName = readSkillName(argv);\n await assertSkillExists(skillName);\n // runSkillMode reads `argv.skill`; bridge the positional onto it.\n runSkillMode({ ...argv, skill: skillName });\n });\n },\n};\n","import * as path from 'node:path';\nimport * as readline from 'node:readline/promises';\nimport type { Arguments } from 'yargs';\nimport { getUI, setUI } from '@ui';\nimport { LoggingUI } from '@ui/logging-ui';\nimport { analytics } from '@utils/analytics';\nimport {\n CLI_STEERING_TARGETS,\n type CliSteeringTarget,\n detectTargets,\n findTarget,\n installOrUpdatePostHogCli,\n installSteeringSnippet,\n} from '@steps/install-cli-steering';\nimport type { Command } from '../command';\n\nexport const cliAddCommand: Command = {\n name: 'add',\n description:\n \"Install or update PostHog CLI and add steering instructions to your coding agent's global instructions file\",\n options: {\n agent: {\n describe: 'Agent to install the instructions for',\n choices: CLI_STEERING_TARGETS.map((target) => target.id),\n type: 'string',\n },\n path: {\n describe:\n 'Write to an explicit instructions file instead of a detected agent',\n type: 'string',\n },\n all: {\n default: false,\n describe: 'Install for every detected agent without prompting',\n type: 'boolean',\n },\n },\n examples: [\n ['wizard cli add', 'Detect your coding agents and pick one'],\n [\n 'wizard cli add --agent claude-code',\n 'Install for Claude Code (~/.claude/CLAUDE.md)',\n ],\n ['wizard cli add --all', 'Install for every detected agent'],\n [\n 'wizard cli add --path ./AGENTS.md',\n 'Install into a specific instructions file',\n ],\n ],\n check: (argv) => {\n if (argv.all && (argv.agent || argv.path)) {\n throw new Error('--all cannot be combined with --agent or --path');\n }\n return true;\n },\n handler: (argv) => {\n void runCliAdd(argv);\n },\n};\n\nasync function runCliAdd(argv: Arguments): Promise<void> {\n setUI(new LoggingUI());\n const ui = getUI();\n ui.intro('PostHog CLI setup');\n\n const files = await resolveTargetFiles(argv);\n if (files.length === 0) {\n process.exit(1);\n return;\n }\n\n ui.log.info('Installing or updating PostHog CLI...');\n const cliInstallResult = installOrUpdatePostHogCli();\n if (!cliInstallResult.success) {\n ui.log.error(\n `Failed to install or update PostHog CLI: ${\n cliInstallResult.error ?? ''\n }`,\n );\n analytics.wizardCapture('cli steering installed', {\n files: files.length,\n failures: files.length,\n cli_install_failed: true,\n agent: typeof argv.agent === 'string' ? argv.agent : undefined,\n });\n process.exit(1);\n return;\n }\n ui.log.success('Installed or updated PostHog CLI.');\n\n let failures = 0;\n for (const file of files) {\n const result = installSteeringSnippet(file);\n if (result.success) {\n ui.log.success(`Installed PostHog steering instructions in ${file}`);\n } else {\n failures += 1;\n ui.log.error(`Failed to update ${file}: ${result.error ?? ''}`);\n }\n }\n\n analytics.wizardCapture('cli steering installed', {\n files: files.length,\n failures,\n agent: typeof argv.agent === 'string' ? argv.agent : undefined,\n });\n\n if (failures > 0) {\n process.exit(1);\n return;\n }\n ui.outro(\n 'Done. PostHog CLI is installed and your agent will now use `posthog-cli api` for PostHog tasks.',\n );\n process.exit(0);\n}\n\n/** Resolve which instruction files to write, from flags, detection, or a prompt. */\nasync function resolveTargetFiles(argv: Arguments): Promise<string[]> {\n const ui = getUI();\n\n if (typeof argv.path === 'string' && argv.path.trim()) {\n return [path.resolve(argv.path.trim())];\n }\n\n if (typeof argv.agent === 'string') {\n // yargs `choices` already rejected unknown ids.\n const target = findTarget(argv.agent);\n if (!target) {\n ui.log.error(`Unsupported agent: ${argv.agent}`);\n return [];\n }\n return [target.instructionsPath()];\n }\n\n const detected = detectTargets();\n if (detected.length === 0) {\n ui.log.error(\n 'No supported coding agents detected. Pass --agent <id> or --path <file> to choose a target.',\n );\n ui.log.info(\n `Supported agents: ${CLI_STEERING_TARGETS.map((t) => t.id).join(', ')}`,\n );\n return [];\n }\n\n if (argv.all === true) {\n ui.log.info(\n `Installing for all detected agents: ${detected\n .map((t) => t.name)\n .join(', ')}`,\n );\n return detected.map((target) => target.instructionsPath());\n }\n\n if (detected.length === 1) {\n ui.log.info(\n `Detected ${detected[0].name} (${detected[0].instructionsPath()})`,\n );\n return [detected[0].instructionsPath()];\n }\n\n // Non-interactive shells can't pick, so install for every detected agent —\n // the snippet is additive and idempotent, mirroring how MCP install treats\n // all supported clients.\n if (!process.stdin.isTTY || !process.stdout.isTTY) {\n ui.log.info(\n `Installing for all detected agents: ${detected\n .map((t) => t.name)\n .join(', ')}`,\n );\n return detected.map((target) => target.instructionsPath());\n }\n\n const selected = await promptForTargets(detected);\n return selected.map((target) => target.instructionsPath());\n}\n\n/** Minimal numbered selection — this command is intentionally not a TUI flow. */\nasync function promptForTargets(\n detected: CliSteeringTarget[],\n): Promise<CliSteeringTarget[]> {\n const ui = getUI();\n ui.log.info('Which coding agent are you using?');\n detected.forEach((target, index) => {\n ui.log.info(\n ` ${index + 1}) ${target.name} (${target.instructionsPath()})`,\n );\n });\n ui.log.info(` ${detected.length + 1}) All of the above`);\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n try {\n for (;;) {\n const answer = (\n await rl.question(`Select 1-${detected.length + 1}: `)\n ).trim();\n const choice = Number(answer);\n if (\n Number.isInteger(choice) &&\n choice >= 1 &&\n choice <= detected.length\n ) {\n return [detected[choice - 1]];\n }\n if (choice === detected.length + 1) {\n return detected;\n }\n ui.log.warn(`Enter a number between 1 and ${detected.length + 1}.`);\n }\n } finally {\n rl.close();\n }\n}\n","import { cliAddCommand } from './add';\nimport type { Command } from '../command';\n\nexport const cliCommand: Command = {\n name: 'cli',\n description: 'PostHog CLI agent integration commands',\n children: [cliAddCommand],\n};\n","#!/usr/bin/env node\nimport { satisfies } from 'semver';\nimport { Agent, setGlobalDispatcher } from 'undici';\nimport { ErrorCodes } from './src/lib/errors/codes.js';\nimport { emitWizardError } from './src/lib/errors/emit.js';\n\n// Keep in sync with `engines.node` in package.json. npx does not enforce\n// engines, so this preflight is the only thing standing between an old Node\n// runtime and a cryptic dependency crash (e.g. undici's markAsUncloneable\n// TypeError on Node < 22.10).\nconst NODE_VERSION_RANGE = '>=22.22.0';\n\n/*\n * TODO(#1198): remove when fetch over HTTP/2 is safe on Node 26. Remove when all\n * of these are true:\n * - nodejs/node no longer creates an orphan ClientHttp2Stream when a client\n * session gets HEADERS for a stream id it already reset. Repro: abort a fetch\n * before its response headers, then idle 4s on Node 26. Fixed when the\n * process survives.\n * - modelcontextprotocol/typescript-sdk#2526 is closed.\n * - pi-coding-agent's CLI drops `allowH2: false` from its http-dispatcher.\n * Same workaround as pi's CLI and typescript-sdk#2526: HTTP/1.1 only.\n */\nsetGlobalDispatcher(new Agent({ allowH2: false }));\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 [\n `The PostHog wizard needs a newer version of Node.js to run.`,\n ``,\n ` You have: ${process.version}`,\n ` You need: v${NODE_VERSION_RANGE.replace('>=', '')} or later`,\n ``,\n `To update Node.js:`,\n ``,\n ` Download the latest version from https://nodejs.org/en/download`,\n ` Or, if you use nvm, run: nvm install 22 && nvm use 22`,\n ``,\n `Then run the wizard again. Stuck? Email wizard@posthog.com and we'll help.`,\n ].join('\\n'),\n );\n emitWizardError({\n code: ErrorCodes.CliNodeVersion,\n message: `Node ${process.version} is below the required range ${NODE_VERSION_RANGE}`,\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 { mcpAnalyticsCommand } from './src/commands/mcp-analytics';\nimport { replayVisionCommand } from './src/commands/replay-vision';\nimport { aiObservabilityCommand } from './src/commands/ai-observability';\nimport { metricsCommand } from './src/commands/metrics';\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 { warehouseCommand } from './src/commands/warehouse';\nimport { selfDrivingCommand } from './src/commands/self-driving';\nimport { slackCommand } from './src/commands/slack';\nimport { uploadSourcemapsCommand } from './src/commands/upload-sourcemaps';\nimport { skillCommand } from './src/commands/skill';\nimport { cliCommand } from './src/commands/cli';\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(mcpAnalyticsCommand)\n .use(replayVisionCommand)\n .use(aiObservabilityCommand)\n .use(metricsCommand)\n .use(cliCommand)\n .use(auditCommand)\n .use(doctorCommand)\n .use(migrateCommand)\n .use(revenueCommand)\n .use(warehouseCommand)\n .use(selfDrivingCommand)\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,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,QAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,IAAI,eAAe,EAAE,CAAC,CAC7D,QAAO,KAAK,WAAW,KAAK,KAAK;AAEnC,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,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