@posthog/wizard 2.84.0 → 2.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/{agent-interface-BNssNetq.js → agent-interface-C2yoWWW_.js} +18 -11
  2. package/dist/agent-interface-C2yoWWW_.js.map +1 -0
  3. package/dist/{agent-prompt-loader-iV11XVEF.js → agent-prompt-loader-B6ZyyoSH.js} +6 -6
  4. package/dist/{agent-prompt-loader-iV11XVEF.js.map → agent-prompt-loader-B6ZyyoSH.js.map} +1 -1
  5. package/dist/analytics-DM5Fx9JF.js +2 -0
  6. package/dist/{analytics-Drox5LSW.js → analytics-J1cjIekQ.js} +2 -2
  7. package/dist/{analytics-Drox5LSW.js.map → analytics-J1cjIekQ.js.map} +1 -1
  8. package/dist/{api-Dfu655Qt.js → api-DoMocc6P.js} +2 -2
  9. package/dist/{api-Dfu655Qt.js.map → api-DoMocc6P.js.map} +1 -1
  10. package/dist/api-bUx3g0Jj.js +2 -0
  11. package/dist/{api-key-login-BgwfAXfv.js → api-key-login-CjXOunDa.js} +5 -5
  12. package/dist/{api-key-login-BgwfAXfv.js.map → api-key-login-CjXOunDa.js.map} +1 -1
  13. package/dist/api-key-login-D4Esj8TZ.js +2 -0
  14. package/dist/bin.js +1 -1
  15. package/dist/{bounded-fs-TRL6IsoU.js → bounded-fs-Dr1DVwWs.js} +5 -4
  16. package/dist/bounded-fs-Dr1DVwWs.js.map +1 -0
  17. package/dist/{ci-install-nc1IKuX2.js → ci-install-ByYDF-nS.js} +4 -4
  18. package/dist/{ci-install-nc1IKuX2.js.map → ci-install-ByYDF-nS.js.map} +1 -1
  19. package/dist/{debug-BfO_Txo8.js → debug-BWrfAT_d.js} +3 -3
  20. package/dist/{debug-BfO_Txo8.js.map → debug-BWrfAT_d.js.map} +1 -1
  21. package/dist/{gateway-CLQQb96F.js → gateway-DrKvPnHW.js} +9 -6
  22. package/dist/{gateway-CLQQb96F.js.map → gateway-DrKvPnHW.js.map} +1 -1
  23. package/dist/{headless-DMO8N_FD.js → headless-B3NomAmg.js} +2 -2
  24. package/dist/{headless-DMO8N_FD.js.map → headless-B3NomAmg.js.map} +1 -1
  25. package/dist/{headless-CHGNEzO3.js → headless-D2lM4BeY.js} +1 -1
  26. package/dist/{host-resolution-DftfSjJD.js → host-resolution-BAnXpvmo.js} +4 -4
  27. package/dist/{host-resolution-DftfSjJD.js.map → host-resolution-BAnXpvmo.js.map} +1 -1
  28. package/dist/{install-MWoo1hXL.js → install-BaZS9PMi.js} +1 -1
  29. package/dist/{install-C9FPM37m.js → install-x8br-QvS.js} +5 -5
  30. package/dist/{install-C9FPM37m.js.map → install-x8br-QvS.js.map} +1 -1
  31. package/dist/{interactive-DOnolJHB.js → interactive-D0X4iQOs.js} +3 -3
  32. package/dist/{interactive-DOnolJHB.js.map → interactive-D0X4iQOs.js.map} +1 -1
  33. package/dist/{links-CatXPRxH.js → links-DCUnJ0Fl.js} +3 -3
  34. package/dist/{links-CatXPRxH.js.map → links-DCUnJ0Fl.js.map} +1 -1
  35. package/dist/{main-CINmZtoW.js → main-CCIvlpq6.js} +20 -20
  36. package/dist/{main-CINmZtoW.js.map → main-CCIvlpq6.js.map} +1 -1
  37. package/dist/{mcp-KVV6Z_bq.js → mcp-D1rpXjM2.js} +3 -3
  38. package/dist/{mcp-KVV6Z_bq.js.map → mcp-D1rpXjM2.js.map} +1 -1
  39. package/dist/{mcp-prompt-streaming-M6UnLgGX.js → mcp-prompt-streaming-GXBA581m.js} +5 -5
  40. package/dist/{mcp-prompt-streaming-M6UnLgGX.js.map → mcp-prompt-streaming-GXBA581m.js.map} +1 -1
  41. package/dist/{models-B0huHItG.js → models-HNKiMsME.js} +2 -2
  42. package/dist/{models-B0huHItG.js.map → models-HNKiMsME.js.map} +1 -1
  43. package/dist/{oauth-session-9EU3ky0v.js → oauth-session-DTydKnfV.js} +2 -2
  44. package/dist/{oauth-session-9EU3ky0v.js.map → oauth-session-DTydKnfV.js.map} +1 -1
  45. package/dist/{orchestrator-tools-QWyDLu_7.js → orchestrator-tools-a3uMYekz.js} +3 -3
  46. package/dist/{orchestrator-tools-QWyDLu_7.js.map → orchestrator-tools-a3uMYekz.js.map} +1 -1
  47. package/dist/{package-manager-B-9I_fAT.js → package-manager-D_APgur1.js} +4 -4
  48. package/dist/{package-manager-B-9I_fAT.js.map → package-manager-D_APgur1.js.map} +1 -1
  49. package/dist/{pi-BSnSk6rv.js → pi-BXwrltc4.js} +12 -12
  50. package/dist/{pi-BSnSk6rv.js.map → pi-BXwrltc4.js.map} +1 -1
  51. package/dist/{playground-Drz1qszs.js → playground-ZiIX53Cx.js} +4 -4
  52. package/dist/{playground-Drz1qszs.js.map → playground-ZiIX53Cx.js.map} +1 -1
  53. package/dist/{posthog-integration-mIQGBc1f.js → posthog-integration-yK9EktZn.js} +21 -21
  54. package/dist/{posthog-integration-mIQGBc1f.js.map → posthog-integration-yK9EktZn.js.map} +1 -1
  55. package/dist/{programs-mxhRXwP-.js → programs-AZStBYjR.js} +19 -15
  56. package/dist/programs-AZStBYjR.js.map +1 -0
  57. package/dist/programs-DrvCAQHg.js +3 -0
  58. package/dist/{provisioning-CHUjae9V.js → provisioning-BpP-DrUL.js} +4 -4
  59. package/dist/{provisioning-CHUjae9V.js.map → provisioning-BpP-DrUL.js.map} +1 -1
  60. package/dist/provisioning-D8ZhYNCc.js +2 -0
  61. package/dist/{queue-tools-PFG6H93Q.js → queue-tools-BS8nXJ6S.js} +4 -4
  62. package/dist/{queue-tools-PFG6H93Q.js.map → queue-tools-BS8nXJ6S.js.map} +1 -1
  63. package/dist/{results-5yCKf2cI.js → results-BE1ctlKP.js} +2 -2
  64. package/dist/{results-5yCKf2cI.js.map → results-BE1ctlKP.js.map} +1 -1
  65. package/dist/{run-W03b6jNM.js → run-Cmn1xaWK.js} +10 -10
  66. package/dist/{run-W03b6jNM.js.map → run-Cmn1xaWK.js.map} +1 -1
  67. package/dist/{run-D5TKJuSL.js → run-D0AZVe7z.js} +7 -7
  68. package/dist/{run-D5TKJuSL.js.map → run-D0AZVe7z.js.map} +1 -1
  69. package/dist/{run-tool-DTQF8mmI.js → run-tool-DAt35gkq.js} +13 -13
  70. package/dist/{run-tool-DTQF8mmI.js.map → run-tool-DAt35gkq.js.map} +1 -1
  71. package/dist/run-tool-IHvPCuQT.js +2 -0
  72. package/dist/{runners-B_84kPyf.js → runners-BsTLloGF.js} +8 -8
  73. package/dist/{runners-B_84kPyf.js.map → runners-BsTLloGF.js.map} +1 -1
  74. package/dist/{security-pApVawYb.js → security-CQZUg-Oz.js} +5 -5
  75. package/dist/{security-pApVawYb.js.map → security-CQZUg-Oz.js.map} +1 -1
  76. package/dist/{setup-utils-CQY8PHjR.js → setup-utils-CqITBPrn.js} +3 -3
  77. package/dist/{setup-utils-CQY8PHjR.js.map → setup-utils-CqITBPrn.js.map} +1 -1
  78. package/dist/{start-playground-DAw1GbLt.js → start-playground-CUhA5g6G.js} +7 -7
  79. package/dist/{start-playground-DAw1GbLt.js.map → start-playground-CUhA5g6G.js.map} +1 -1
  80. package/dist/{subagent-YLGSvgoZ.js → subagent-BPynEn_q.js} +3 -3
  81. package/dist/{subagent-YLGSvgoZ.js.map → subagent-BPynEn_q.js.map} +1 -1
  82. package/dist/{task-3hRSovmK.js → task-Cuwyq3HT.js} +14 -14
  83. package/dist/{task-3hRSovmK.js.map → task-Cuwyq3HT.js.map} +1 -1
  84. package/dist/{telemetry-BPBzqsb_.js → telemetry-BoTjlaAw.js} +2 -2
  85. package/dist/{telemetry-BPBzqsb_.js.map → telemetry-BoTjlaAw.js.map} +1 -1
  86. package/dist/{terminal-DZsYFbm9.js → terminal-CmCNn0IG.js} +18 -18
  87. package/dist/{terminal-DZsYFbm9.js.map → terminal-CmCNn0IG.js.map} +1 -1
  88. package/dist/{tools-D_AtrhbO.js → tools-Blf-Yjru.js} +13 -13
  89. package/dist/{tools-D_AtrhbO.js.map → tools-Blf-Yjru.js.map} +1 -1
  90. package/dist/{tools-DyzRi_dQ.js → tools-DvefdnQx.js} +8 -8
  91. package/dist/{tools-DyzRi_dQ.js.map → tools-DvefdnQx.js.map} +1 -1
  92. package/dist/{tui-UI6ctBQJ.js → tui-B_nBr0aF.js} +1 -1
  93. package/dist/{tui-CRp0iCuT.js → tui-CKbAdFxQ.js} +4 -4
  94. package/dist/{tui-CRp0iCuT.js.map → tui-CKbAdFxQ.js.map} +1 -1
  95. package/dist/{upload-step-DrYXnpzI.js → upload-step-Dqb7Dzfn.js} +3 -3
  96. package/dist/{upload-step-DrYXnpzI.js.map → upload-step-Dqb7Dzfn.js.map} +1 -1
  97. package/dist/{urls-WeqfBLP4.js → urls-DWZ9EKLI.js} +2 -2
  98. package/dist/{urls-WeqfBLP4.js.map → urls-DWZ9EKLI.js.map} +1 -1
  99. package/dist/{wizard-abort-BwEefm6P.js → wizard-abort-g6PYcdlP.js} +4 -4
  100. package/dist/{wizard-abort-BwEefm6P.js.map → wizard-abort-g6PYcdlP.js.map} +1 -1
  101. package/dist/{yara-hooks-MDtFbuoM.js → yara-hooks-BsOgyb6-.js} +1 -1
  102. package/dist/{yara-hooks-aDbdsitJ.js → yara-hooks-ssWAT78l.js} +4 -4
  103. package/dist/{yara-hooks-aDbdsitJ.js.map → yara-hooks-ssWAT78l.js.map} +1 -1
  104. package/package.json +6 -1
  105. package/dist/agent-interface-BNssNetq.js.map +0 -1
  106. package/dist/analytics-Ix9HEra3.js +0 -2
  107. package/dist/api-H2UaPgjv.js +0 -2
  108. package/dist/api-key-login-Cow3UDAN.js +0 -2
  109. package/dist/bounded-fs-TRL6IsoU.js.map +0 -1
  110. package/dist/programs-Bv0_YHzE.js +0 -3
  111. package/dist/programs-mxhRXwP-.js.map +0 -1
  112. package/dist/provisioning-BVsxSNve.js +0 -2
  113. package/dist/run-tool-DjERhu7G.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"main-CINmZtoW.js","names":["mcpAnalyticsConfig","replayVisionConfig","aiObservabilityConfig","metricsConfig","webAnalyticsDoctorConfig","agentSkillConfig","migrationConfig","revenueAnalyticsConfig","warehouseSourceConfig","selfDrivingConfig","errorTrackingUploadSourceMapsConfig","errorTrackingConfig","featureFlagsConfig"],"sources":["../src/cli/commands/command.ts","../src/cli/wizard.ts","../src/cli/commands/provision.ts","../src/cli/commands/basic-integration/index.ts","../src/cli/commands/mcp/tui-availability.ts","../src/cli/commands/mcp/add.ts","../src/cli/commands/mcp/remove.ts","../src/cli/commands/mcp/tutorial.ts","../src/cli/commands/mcp/index.ts","../src/cli/commands/skill-program-options.ts","../src/cli/commands/factories/shared.ts","../src/cli/commands/factories/native-command-factory.ts","../src/cli/commands/mcp-analytics.ts","../src/cli/commands/replay-vision.ts","../src/cli/commands/ai-observability.ts","../src/cli/commands/metrics.ts","../src/cli/commands/cli/add.ts","../src/cli/commands/cli/index.ts","../src/cli/commands/dispatch-family.ts","../src/cli/commands/factories/family-picker.ts","../src/cli/commands/factories/family-command-factory.ts","../src/cli/commands/audit.ts","../src/cli/commands/doctor.ts","../src/cli/commands/migrate.ts","../src/cli/commands/revenue.ts","../src/cli/commands/warehouse.ts","../src/cli/commands/self-driving.ts","../src/cli/commands/slack.ts","../src/cli/commands/upload-sourcemaps.ts","../src/cli/commands/error-tracking.ts","../src/cli/commands/feature-flags.ts","../src/cli/commands/basic-integration/skill.ts","../src/cli/commands/skill.ts","../src/cli/index.ts","../main.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 '@shared/constants';\nimport { regionOption } from '@shared/headless-mode';\nimport { initLocalDev, localMcpSkillsNotice } from '@shared/local-dev';\nimport { configureLogFile } from '@utils/debug';\nimport { toCommandModule, type Command } from './commands/command';\nimport { ErrorCodes } from '@shared/errors';\nimport { emitWizardError } from '@shared/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 'log-file': {\n describe:\n 'Write the debug log to this file (default: posthog-wizard.log in the temp dir)\\nenv: POSTHOG_WIZARD_LOG_FILE',\n type: 'string' as const,\n },\n signup: {\n default: false,\n describe:\n 'Create a new PostHog account during setup\\nenv: POSTHOG_WIZARD_SIGNUP',\n type: 'boolean' as const,\n },\n telemetry: {\n default: true,\n describe:\n 'Send wizard run state to PostHog (pass --no-telemetry to disable)\\nenv: POSTHOG_WIZARD_TELEMETRY',\n type: 'boolean' as const,\n },\n 'api-key': {\n describe:\n 'PostHog personal API key (phx_xxx) for authentication\\nenv: POSTHOG_WIZARD_API_KEY',\n type: 'string' as const,\n },\n 'project-id': {\n describe:\n 'PostHog project ID to use (optional; when not set, uses default from API key or OAuth)\\nenv: POSTHOG_WIZARD_PROJECT_ID',\n type: 'string' as const,\n },\n email: {\n describe:\n 'Email address for signup (used with --signup)\\nenv: POSTHOG_WIZARD_EMAIL',\n type: 'string' as const,\n },\n // ── Internal modes ─────────────────────────────────────────────────\n // Hidden from `--help`.\n // NB: the experimental headless flag is deliberately NOT global. Supported\n // commands declare it through `headlessOption` in @shared/headless-mode.\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 'run-id': {\n describe: 'Assigned cloud WizardRun UUID',\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: Argv = 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 through `headlessOption` (see\n // @shared/headless-mode). CI needs `region` globally because the workbench\n // passes it to every command. --ci and headless stay separate so their\n // 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-5 | openai/gpt-5.6-terra). 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 // Rides beside the PostHog destination rather than replacing it, so a\n // logged run is the same run the backend sees.\n .option('task-stream-log', {\n describe:\n 'Append every task-stream payload to a local JSONL file. Pass a path, or pass the flag alone for /tmp/posthog-wizard-task-stream.jsonl\\nenv: POSTHOG_WIZARD_TASK_STREAM_LOG',\n type: 'string',\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 if (typeof argv.logFile === 'string' && argv.logFile) {\n configureLogFile({ path: argv.logFile, pin: true });\n }\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 { consoleLog } from '@shared/console-log';\nimport { runProvision } from '@tools';\nimport { exitWith } from '@cli/runners';\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: provision,\n};\n\nfunction provision(argv: Arguments): void {\n const jsonMode =\n argv.json === undefined ? !process.stdout.isTTY : Boolean(argv.json);\n exitWith(() =>\n runProvision(\n {\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 { log: consoleLog },\n ),\n );\n}\n","import { isNonInteractiveEnvironment } from '@utils/environment';\nimport { setEntryCommand } from '@utils/links';\nimport {\n headlessOption,\n isHeadless,\n regionOption,\n} from '@shared/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 @shared/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 { ErrorCodes } from '@shared/errors';\n\n/**\n * startTUI throws CliInteractiveRequired, and Ink throws \"Raw mode is not\n * supported\", when stdin has no TTY (piped input, CI, some IDE terminals).\n * That is the only TUI failure the mcp commands degrade to console output for\n * — any other error from the TUI path is a real bug and must surface rather\n * than be silently swallowed.\n */\nexport function isTUIUnavailable(error: unknown): boolean {\n if (!(error instanceof Error)) return false;\n return (\n (error as { code?: unknown }).code === ErrorCodes.CliInteractiveRequired ||\n /raw mode is not supported/i.test(error.message)\n );\n}\n","import type { Arguments } from 'yargs';\nimport { consoleLog } from '@shared/console-log';\nimport { headlessOption, isHeadless } from '@shared/headless-mode';\nimport { readApiKeyFromEnv } from '@utils/env-api-key';\nimport { addMCPServerToClientsStep, Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 const apiKey = (argv.apiKey as string | undefined) || readApiKeyFromEnv();\n const localMcp = argv.local as boolean | undefined;\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 headless = () =>\n addMCPServerToClientsStep(\n { local: localMcp, features, apiKey },\n { log: consoleLog.log },\n );\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 exitWith(headless);\n return;\n }\n\n exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.McpAdd, {\n session: {\n debug: argv.debug as boolean | undefined,\n localMcp,\n mcpFeatures: features,\n apiKey,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (error) {\n if (!isTUIUnavailable(error)) throw error;\n return headless();\n }\n });\n}\n\nfunction parseFeatures(raw: unknown): string[] | undefined {\n if (typeof raw !== 'string') return undefined;\n return raw\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n}\n","import type { Arguments } from 'yargs';\nimport { consoleLog } from '@shared/console-log';\nimport { headlessOption, isHeadless } from '@shared/headless-mode';\nimport { removeMCPServerFromClientsStep, Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 const localMcp = argv.local as boolean | undefined;\n const headless = () =>\n removeMCPServerFromClientsStep(\n { local: localMcp },\n { log: consoleLog.log },\n );\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 exitWith(headless);\n return;\n }\n\n exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.McpRemove, {\n session: {\n debug: argv.debug as boolean | undefined,\n localMcp,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (error) {\n // Same guard as `mcp add`: only a missing TTY falls back to the console,\n // so a genuine TUI bug surfaces instead of looking like a plain shell.\n if (!isTUIUnavailable(error)) throw error;\n return headless();\n }\n });\n}\n","import type { Arguments } from 'yargs';\nimport { consoleLog } from '@shared/console-log';\nimport { ErrorCodes, emitWizardError } from '@shared/errors';\nimport { Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.McpTutorial, {\n session: {\n debug: argv.debug as boolean | undefined,\n localMcp: argv.local as boolean | undefined,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (err) {\n // TUI unavailable — the tutorial has no headless fallback.\n consoleLog.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 return 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 * 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 '@cli/runners';\nimport { isHeadless } from '@shared/headless-mode';\nimport type { ProgramConfig } from '@programs/types';\n\nimport { skillProgramOptions } from '../skill-program-options';\nimport { ErrorCodes } from '@shared/errors';\nimport { emitWizardError } from '@shared/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 '@programs/types';\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 { config as mcpAnalyticsConfig } from '@programs/mcp-analytics';\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 for its language, 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 { config as replayVisionConfig } from '@programs/replay-vision';\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 { config as aiObservabilityConfig } from '@programs/ai-observability';\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 { config as metricsConfig } from '@programs/metrics';\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 { consoleLog } from '@shared/console-log';\nimport { CLI_STEERING_TARGETS } from '@shared/install-cli-steering';\nimport { runCliAdd } from '@tools';\nimport { exitWith } from '@cli/runners';\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 exitWith(() =>\n runCliAdd(\n {\n agent: typeof argv.agent === 'string' ? argv.agent : undefined,\n path: typeof argv.path === 'string' ? argv.path : undefined,\n all: argv.all === true,\n },\n { log: consoleLog },\n ),\n );\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","import type { Arguments } from 'yargs';\n\nimport { AUDIT_CHECKS_FILE } from '@programs/audit';\nimport { WIZARD_TOOL_NAMES } from '@agent';\nimport { getProgramConfig, Program } from '@programs';\nimport { config as agentSkillConfig } from '@programs/agent-skill';\nimport { config as webAnalyticsDoctorConfig } from '@programs/web-analytics-doctor';\nimport type { ProgramConfig } from '@programs/types';\nimport { getSkillsBaseUrl } from '@shared/constants';\nimport { fetchSkillMenu, type CliEntry } from '@shared/skill-menu';\nimport { analytics } from '@utils/analytics';\n\nimport { dispatchProgram } from './factories/shared';\nimport type { Command } from './command';\nimport { ErrorCodes } from '@shared/errors';\nimport { emitWizardError } from '@shared/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 `audit` program (custom hooks,\n * content blocks, screens).\n *\n * This is the one place that knows a subcommand belongs to `audit`, so the\n * generic skill program picks up the ledger here rather than for every skill.\n */\nfunction configForCliEntry(entry: CliEntry, family: string): ProgramConfig {\n if (entry.skillId === 'audit') return getProgramConfig(Program.Audit);\n return {\n ...agentSkillConfig,\n skillId: entry.skillId,\n ...(family === 'audit'\n ? {\n auditLedgerFile: AUDIT_CHECKS_FILE,\n streamWorkflowId: family,\n allowedTools: [\n ...(agentSkillConfig.allowedTools ?? []),\n WIZARD_TOOL_NAMES.auditSeedChecks,\n WIZARD_TOOL_NAMES.auditAddChecks,\n WIZARD_TOOL_NAMES.auditResolveChecks,\n ],\n }\n : {}),\n };\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, family), 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 * 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';\n\nimport { commandKeys, type Command } from '../command';\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 over a family's children. Resolves once the user has\n * selected a child; dispatching the child's handler is the caller's\n * responsibility.\n */\nexport async function chooseFamilyChild(\n parentLabel: string,\n children: readonly Command[],\n): Promise<Command | null> {\n const ordered = orderFamilyChildren(children);\n if (ordered.length === 0) return null;\n\n // Loaded here: a headless run never loads the TUI.\n const { renderFamilyPicker } = await import('@tui');\n return renderFamilyPicker(\n parentLabel,\n ordered.map((child) => ({\n label: describe(child),\n value: child,\n hint: child.description,\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 '@programs/types';\nimport {\n buildFamilyPickerChildren,\n dispatchFamily,\n pickerChildrenToShow,\n} from '../dispatch-family';\nimport { getSkillsBaseUrl } from '@shared/constants';\nimport { fetchSkillMenu } from '@shared/skill-menu';\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 { getProgramConfig, Program } from '@programs';\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 */\nconst audit = getProgramConfig(Program.Audit);\n\nexport const auditCommand: Command = familyCommandFactory({\n family: 'audit',\n description: audit.description,\n optionsFrom: audit,\n});\n","import { consoleLog } from '@shared/console-log';\nimport { readApiKeyFromEnv } from '@utils/env-api-key';\nimport { DOCTOR, runDoctorReport, Tool } from '@tools';\nimport { exitWith, tuiSessionArgs, withSignals } from '@cli/runners';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const doctorCommand: Command = {\n name: 'doctor',\n description: DOCTOR.description,\n options: { ...skillProgramOptions },\n handler: (argv) => {\n const options = { ...argv } as Record<string, unknown>;\n // In CI there is no screen: fetch the project's health issues and print them.\n if (options.ci) {\n exitWith(() =>\n runDoctorReport(\n {\n apiKey:\n (options.apiKey as string | undefined) ??\n readApiKeyFromEnv() ??\n undefined,\n projectId: options.projectId\n ? Number(options.projectId as string)\n : undefined,\n baseUrl: options.baseUrl as string | undefined,\n },\n { log: consoleLog },\n ),\n );\n return;\n }\n withSignals(async (signal) => {\n // Loaded here, not at startup: a console run never loads the TUI.\n const { runTuiTool } = await import('@tui');\n return runTuiTool(Tool.PosthogDoctor, {\n session: tuiSessionArgs(options),\n signal,\n });\n });\n },\n};\n","import { config as migrationConfig } from '@programs/migration';\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 { config as revenueAnalyticsConfig } from '@programs/revenue-analytics';\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 { config as warehouseSourceConfig } from '@programs/warehouse-source';\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 '@cli/runners';\nimport { config as selfDrivingConfig } from '@programs/self-driving';\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 { consoleLog } from '@shared/console-log';\nimport { ErrorCodes, emitWizardError } from '@shared/errors';\nimport { Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.SlackConnect, {\n session: {\n debug: argv.debug as boolean | undefined,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (err) {\n // TUI unavailable — connecting Slack has no headless fallback.\n consoleLog.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 return 1;\n }\n });\n}\n","import { runWizard, runWizardCI } from '@cli/runners';\nimport { config as errorTrackingUploadSourceMapsConfig } from '@programs/error-tracking-upload-source-maps';\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 { config as errorTrackingConfig } from '@programs/error-tracking';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard error-tracking` — flat skill command, set up error tracking today.\n *\n * Wires up exception capture and — where the platform needs it — source-map /\n * debug-symbol upload. Runs the `error-tracking` orchestrator flow, which\n * reuses the integration-v2 install/init mini-agents when the repo has no\n * PostHog integration yet, so it works on uninstrumented projects too.\n */\nexport const errorTrackingCommand: Command =\n nativeCommandFactory(errorTrackingConfig);\n","import { config as featureFlagsConfig } from '@programs/feature-flags';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\nexport const featureFlagsCommand: Command =\n nativeCommandFactory(featureFlagsConfig);\n","import type { Arguments } from 'yargs';\nimport { POSTHOG_DOCS_URL } from '@shared/constants';\nimport { runWizard, runWizardCI } from '@cli/runners';\nimport { createSkillProgram } from '@programs';\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 '@shared/constants';\nimport { fetchSkillMenu } from '@shared/skill-menu';\nimport { analytics } from '@utils/analytics';\nimport { listSkills } from '@tools';\nimport { exitWith } from '@cli/runners';\n\nimport { runSkillMode } from './basic-integration/skill';\nimport { skillProgramOptions } from './skill-program-options';\nimport { runCommandHandler } from './factories/shared';\nimport type { Command } from './command';\n\n/** Read the `<skill-name>` positional (yargs camelCases the hyphenated key). */\nfunction readSkillName(argv: Arguments): string {\n return String(argv.skillName ?? argv['skill-name'] ?? '').trim();\n}\n\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\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 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.\n check: (argv) => {\n if (!readSkillName(argv)) {\n throw new Error(\n 'skill needs a skill name, e.g. `wizard skill audit-events`',\n );\n }\n return true;\n },\n handler: (argv) => {\n // `list` is the positional's one reserved value, not a skill id.\n if (readSkillName(argv) === 'list') return exitWith(listSkills);\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","/** The CLI's one entry: `main.ts` runs the `wizard` command line through it. */\nimport { Wizard } from './wizard';\nimport { basicIntegrationCommand } from './commands/basic-integration';\nimport { mcpCommand } from './commands/mcp';\nimport { mcpAnalyticsCommand } from './commands/mcp-analytics';\nimport { replayVisionCommand } from './commands/replay-vision';\nimport { aiObservabilityCommand } from './commands/ai-observability';\nimport { metricsCommand } from './commands/metrics';\nimport { cliCommand } from './commands/cli';\nimport { auditCommand } from './commands/audit';\nimport { doctorCommand } from './commands/doctor';\nimport { migrateCommand } from './commands/migrate';\nimport { revenueCommand } from './commands/revenue';\nimport { warehouseCommand } from './commands/warehouse';\nimport { selfDrivingCommand } from './commands/self-driving';\nimport { slackCommand } from './commands/slack';\nimport { uploadSourcemapsCommand } from './commands/upload-sourcemaps';\nimport { errorTrackingCommand } from './commands/error-tracking';\nimport { featureFlagsCommand } from './commands/feature-flags';\nimport { skillCommand } from './commands/skill';\n\n/** Register every command and run the one `process.argv` names. */\nexport function runCli(): void {\n Wizard.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(errorTrackingCommand)\n .use(featureFlagsCommand)\n .use(skillCommand)\n .init();\n}\n","import { Agent, setGlobalDispatcher } from 'undici';\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\nimport { runCli } from '@cli';\nimport { recoverOrphanedSettingsBackups } from '@shared/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\nrunCli();\n"],"mappings":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AAc,CAClB,IAAI,eAAe,CACnB,IAAI,eAAe,CACnB,IAAI,iBAAiB,CACrB,IAAI,mBAAmB,CACvB,IAAI,aAAa,CACjB,IAAI,wBAAwB,CAC5B,IAAI,qBAAqB,CACzB,IAAI,oBAAoB,CACxB,IAAI,aAAa,CACjB,MAAM;;;;AC5BX,oBAAoB,IAAI,MAAM,EAAE,SAAS,OAAO,CAAC,CAAC;AASlD,+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,QAAQ"}
1
+ {"version":3,"file":"main-CCIvlpq6.js","names":["mcpAnalyticsConfig","replayVisionConfig","aiObservabilityConfig","metricsConfig","webAnalyticsDoctorConfig","agentSkillConfig","migrationConfig","revenueAnalyticsConfig","warehouseSourceConfig","selfDrivingConfig","errorTrackingUploadSourceMapsConfig","errorTrackingConfig","featureFlagsConfig"],"sources":["../src/cli/commands/command.ts","../src/cli/wizard.ts","../src/cli/commands/provision.ts","../src/cli/commands/basic-integration/index.ts","../src/cli/commands/mcp/tui-availability.ts","../src/cli/commands/mcp/add.ts","../src/cli/commands/mcp/remove.ts","../src/cli/commands/mcp/tutorial.ts","../src/cli/commands/mcp/index.ts","../src/cli/commands/skill-program-options.ts","../src/cli/commands/factories/shared.ts","../src/cli/commands/factories/native-command-factory.ts","../src/cli/commands/mcp-analytics.ts","../src/cli/commands/replay-vision.ts","../src/cli/commands/ai-observability.ts","../src/cli/commands/metrics.ts","../src/cli/commands/cli/add.ts","../src/cli/commands/cli/index.ts","../src/cli/commands/dispatch-family.ts","../src/cli/commands/factories/family-picker.ts","../src/cli/commands/factories/family-command-factory.ts","../src/cli/commands/audit.ts","../src/cli/commands/doctor.ts","../src/cli/commands/migrate.ts","../src/cli/commands/revenue.ts","../src/cli/commands/warehouse.ts","../src/cli/commands/self-driving.ts","../src/cli/commands/slack.ts","../src/cli/commands/upload-sourcemaps.ts","../src/cli/commands/error-tracking.ts","../src/cli/commands/feature-flags.ts","../src/cli/commands/basic-integration/skill.ts","../src/cli/commands/skill.ts","../src/cli/index.ts","../main.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 '@shared/constants';\nimport { regionOption } from '@shared/headless-mode';\nimport { initLocalDev, localMcpSkillsNotice } from '@shared/local-dev';\nimport { configureLogFile } from '@utils/debug';\nimport { toCommandModule, type Command } from './commands/command';\nimport { ErrorCodes } from '@shared/errors';\nimport { emitWizardError } from '@shared/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 'log-file': {\n describe:\n 'Write the debug log to this file (default: posthog-wizard.log in the temp dir)\\nenv: POSTHOG_WIZARD_LOG_FILE',\n type: 'string' as const,\n },\n signup: {\n default: false,\n describe:\n 'Create a new PostHog account during setup\\nenv: POSTHOG_WIZARD_SIGNUP',\n type: 'boolean' as const,\n },\n telemetry: {\n default: true,\n describe:\n 'Send wizard run state to PostHog (pass --no-telemetry to disable)\\nenv: POSTHOG_WIZARD_TELEMETRY',\n type: 'boolean' as const,\n },\n 'api-key': {\n describe:\n 'PostHog personal API key (phx_xxx) for authentication\\nenv: POSTHOG_WIZARD_API_KEY',\n type: 'string' as const,\n },\n 'project-id': {\n describe:\n 'PostHog project ID to use (optional; when not set, uses default from API key or OAuth)\\nenv: POSTHOG_WIZARD_PROJECT_ID',\n type: 'string' as const,\n },\n email: {\n describe:\n 'Email address for signup (used with --signup)\\nenv: POSTHOG_WIZARD_EMAIL',\n type: 'string' as const,\n },\n // ── Internal modes ─────────────────────────────────────────────────\n // Hidden from `--help`.\n // NB: the experimental headless flag is deliberately NOT global. Supported\n // commands declare it through `headlessOption` in @shared/headless-mode.\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 'run-id': {\n describe: 'Assigned cloud WizardRun UUID',\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: Argv = 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 through `headlessOption` (see\n // @shared/headless-mode). CI needs `region` globally because the workbench\n // passes it to every command. --ci and headless stay separate so their\n // 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-5 | openai/gpt-5.6-terra). 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 // Rides beside the PostHog destination rather than replacing it, so a\n // logged run is the same run the backend sees.\n .option('task-stream-log', {\n describe:\n 'Append every task-stream payload to a local JSONL file. Pass a path, or pass the flag alone for /tmp/posthog-wizard-task-stream.jsonl\\nenv: POSTHOG_WIZARD_TASK_STREAM_LOG',\n type: 'string',\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 if (typeof argv.logFile === 'string' && argv.logFile) {\n configureLogFile({ path: argv.logFile, pin: true });\n }\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 { consoleLog } from '@shared/console-log';\nimport { runProvision } from '@tools';\nimport { exitWith } from '@cli/runners';\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: provision,\n};\n\nfunction provision(argv: Arguments): void {\n const jsonMode =\n argv.json === undefined ? !process.stdout.isTTY : Boolean(argv.json);\n exitWith(() =>\n runProvision(\n {\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 { log: consoleLog },\n ),\n );\n}\n","import { isNonInteractiveEnvironment } from '@utils/environment';\nimport { setEntryCommand } from '@utils/links';\nimport {\n headlessOption,\n isHeadless,\n regionOption,\n} from '@shared/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 @shared/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 { ErrorCodes } from '@shared/errors';\n\n/**\n * startTUI throws CliInteractiveRequired, and Ink throws \"Raw mode is not\n * supported\", when stdin has no TTY (piped input, CI, some IDE terminals).\n * That is the only TUI failure the mcp commands degrade to console output for\n * — any other error from the TUI path is a real bug and must surface rather\n * than be silently swallowed.\n */\nexport function isTUIUnavailable(error: unknown): boolean {\n if (!(error instanceof Error)) return false;\n return (\n (error as { code?: unknown }).code === ErrorCodes.CliInteractiveRequired ||\n /raw mode is not supported/i.test(error.message)\n );\n}\n","import type { Arguments } from 'yargs';\nimport { consoleLog } from '@shared/console-log';\nimport { headlessOption, isHeadless } from '@shared/headless-mode';\nimport { readApiKeyFromEnv } from '@utils/env-api-key';\nimport { addMCPServerToClientsStep, Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 const apiKey = (argv.apiKey as string | undefined) || readApiKeyFromEnv();\n const localMcp = argv.local as boolean | undefined;\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 headless = () =>\n addMCPServerToClientsStep(\n { local: localMcp, features, apiKey },\n { log: consoleLog.log },\n );\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 exitWith(headless);\n return;\n }\n\n exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.McpAdd, {\n session: {\n debug: argv.debug as boolean | undefined,\n localMcp,\n mcpFeatures: features,\n apiKey,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (error) {\n if (!isTUIUnavailable(error)) throw error;\n return headless();\n }\n });\n}\n\nfunction parseFeatures(raw: unknown): string[] | undefined {\n if (typeof raw !== 'string') return undefined;\n return raw\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n}\n","import type { Arguments } from 'yargs';\nimport { consoleLog } from '@shared/console-log';\nimport { headlessOption, isHeadless } from '@shared/headless-mode';\nimport { removeMCPServerFromClientsStep, Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 const localMcp = argv.local as boolean | undefined;\n const headless = () =>\n removeMCPServerFromClientsStep(\n { local: localMcp },\n { log: consoleLog.log },\n );\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 exitWith(headless);\n return;\n }\n\n exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.McpRemove, {\n session: {\n debug: argv.debug as boolean | undefined,\n localMcp,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (error) {\n // Same guard as `mcp add`: only a missing TTY falls back to the console,\n // so a genuine TUI bug surfaces instead of looking like a plain shell.\n if (!isTUIUnavailable(error)) throw error;\n return headless();\n }\n });\n}\n","import type { Arguments } from 'yargs';\nimport { consoleLog } from '@shared/console-log';\nimport { ErrorCodes, emitWizardError } from '@shared/errors';\nimport { Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.McpTutorial, {\n session: {\n debug: argv.debug as boolean | undefined,\n localMcp: argv.local as boolean | undefined,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (err) {\n // TUI unavailable — the tutorial has no headless fallback.\n consoleLog.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 return 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 * 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 '@cli/runners';\nimport { isHeadless } from '@shared/headless-mode';\nimport type { ProgramConfig } from '@programs/types';\n\nimport { skillProgramOptions } from '../skill-program-options';\nimport { ErrorCodes } from '@shared/errors';\nimport { emitWizardError } from '@shared/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 '@programs/types';\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 { config as mcpAnalyticsConfig } from '@programs/mcp-analytics';\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 for its language, 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 { config as replayVisionConfig } from '@programs/replay-vision';\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 { config as aiObservabilityConfig } from '@programs/ai-observability';\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 { config as metricsConfig } from '@programs/metrics';\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 { consoleLog } from '@shared/console-log';\nimport { CLI_STEERING_TARGETS } from '@shared/install-cli-steering';\nimport { runCliAdd } from '@tools';\nimport { exitWith } from '@cli/runners';\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 exitWith(() =>\n runCliAdd(\n {\n agent: typeof argv.agent === 'string' ? argv.agent : undefined,\n path: typeof argv.path === 'string' ? argv.path : undefined,\n all: argv.all === true,\n },\n { log: consoleLog },\n ),\n );\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","import type { Arguments } from 'yargs';\n\nimport { AUDIT_CHECKS_FILE } from '@programs/audit';\nimport { WIZARD_TOOL_NAMES } from '@agent';\nimport { getProgramConfig, Program } from '@programs';\nimport { config as agentSkillConfig } from '@programs/agent-skill';\nimport { config as webAnalyticsDoctorConfig } from '@programs/web-analytics-doctor';\nimport type { ProgramConfig } from '@programs/types';\nimport { getSkillsBaseUrl } from '@shared/constants';\nimport { fetchSkillMenu, type CliEntry } from '@shared/skill-menu';\nimport { analytics } from '@utils/analytics';\n\nimport { dispatchProgram } from './factories/shared';\nimport type { Command } from './command';\nimport { ErrorCodes } from '@shared/errors';\nimport { emitWizardError } from '@shared/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 `audit` program (custom hooks,\n * content blocks, screens).\n *\n * This is the one place that knows a subcommand belongs to `audit`, so the\n * generic skill program picks up the ledger here rather than for every skill.\n */\nfunction configForCliEntry(entry: CliEntry, family: string): ProgramConfig {\n if (entry.skillId === 'audit') return getProgramConfig(Program.Audit);\n return {\n ...agentSkillConfig,\n skillId: entry.skillId,\n ...(family === 'audit'\n ? {\n auditLedgerFile: AUDIT_CHECKS_FILE,\n streamWorkflowId: family,\n allowedTools: [\n ...(agentSkillConfig.allowedTools ?? []),\n WIZARD_TOOL_NAMES.auditSeedChecks,\n WIZARD_TOOL_NAMES.auditAddChecks,\n WIZARD_TOOL_NAMES.auditResolveChecks,\n ],\n }\n : {}),\n };\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, family), 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 * 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';\n\nimport { commandKeys, type Command } from '../command';\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 over a family's children. Resolves once the user has\n * selected a child; dispatching the child's handler is the caller's\n * responsibility.\n */\nexport async function chooseFamilyChild(\n parentLabel: string,\n children: readonly Command[],\n): Promise<Command | null> {\n const ordered = orderFamilyChildren(children);\n if (ordered.length === 0) return null;\n\n // Loaded here: a headless run never loads the TUI.\n const { renderFamilyPicker } = await import('@tui');\n return renderFamilyPicker(\n parentLabel,\n ordered.map((child) => ({\n label: describe(child),\n value: child,\n hint: child.description,\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 '@programs/types';\nimport {\n buildFamilyPickerChildren,\n dispatchFamily,\n pickerChildrenToShow,\n} from '../dispatch-family';\nimport { getSkillsBaseUrl } from '@shared/constants';\nimport { fetchSkillMenu } from '@shared/skill-menu';\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 { getProgramConfig, Program } from '@programs';\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 */\nconst audit = getProgramConfig(Program.Audit);\n\nexport const auditCommand: Command = familyCommandFactory({\n family: 'audit',\n description: audit.description,\n optionsFrom: audit,\n});\n","import { consoleLog } from '@shared/console-log';\nimport { readApiKeyFromEnv } from '@utils/env-api-key';\nimport { DOCTOR, runDoctorReport, Tool } from '@tools';\nimport { exitWith, tuiSessionArgs, withSignals } from '@cli/runners';\nimport { skillProgramOptions } from './skill-program-options';\nimport type { Command } from './command';\n\nexport const doctorCommand: Command = {\n name: 'doctor',\n description: DOCTOR.description,\n options: { ...skillProgramOptions },\n handler: (argv) => {\n const options = { ...argv } as Record<string, unknown>;\n // In CI there is no screen: fetch the project's health issues and print them.\n if (options.ci) {\n exitWith(() =>\n runDoctorReport(\n {\n apiKey:\n (options.apiKey as string | undefined) ??\n readApiKeyFromEnv() ??\n undefined,\n projectId: options.projectId\n ? Number(options.projectId as string)\n : undefined,\n baseUrl: options.baseUrl as string | undefined,\n },\n { log: consoleLog },\n ),\n );\n return;\n }\n withSignals(async (signal) => {\n // Loaded here, not at startup: a console run never loads the TUI.\n const { runTuiTool } = await import('@tui');\n return runTuiTool(Tool.PosthogDoctor, {\n session: tuiSessionArgs(options),\n signal,\n });\n });\n },\n};\n","import { config as migrationConfig } from '@programs/migration';\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 { config as revenueAnalyticsConfig } from '@programs/revenue-analytics';\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 { config as warehouseSourceConfig } from '@programs/warehouse-source';\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 '@cli/runners';\nimport { config as selfDrivingConfig } from '@programs/self-driving';\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 { consoleLog } from '@shared/console-log';\nimport { ErrorCodes, emitWizardError } from '@shared/errors';\nimport { Tool } from '@tools';\nimport { exitWith, underSignals } from '@cli/runners';\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 exitWith(async () => {\n try {\n const { runTuiTool } = await import('@tui');\n return await underSignals((signal) =>\n runTuiTool(Tool.SlackConnect, {\n session: {\n debug: argv.debug as boolean | undefined,\n baseUrl: argv.baseUrl as string | undefined,\n },\n signal,\n }),\n );\n } catch (err) {\n // TUI unavailable — connecting Slack has no headless fallback.\n consoleLog.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 return 1;\n }\n });\n}\n","import { runWizard, runWizardCI } from '@cli/runners';\nimport { config as errorTrackingUploadSourceMapsConfig } from '@programs/error-tracking-upload-source-maps';\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 { config as errorTrackingConfig } from '@programs/error-tracking';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\n/**\n * `wizard error-tracking` — flat skill command, set up error tracking today.\n *\n * Wires up exception capture and — where the platform needs it — source-map /\n * debug-symbol upload. Runs the `error-tracking` orchestrator flow, which\n * reuses the integration-v2 install/init mini-agents when the repo has no\n * PostHog integration yet, so it works on uninstrumented projects too.\n */\nexport const errorTrackingCommand: Command =\n nativeCommandFactory(errorTrackingConfig);\n","import { config as featureFlagsConfig } from '@programs/feature-flags';\n\nimport type { Command } from './command';\nimport { nativeCommandFactory } from './factories/native-command-factory';\n\nexport const featureFlagsCommand: Command =\n nativeCommandFactory(featureFlagsConfig);\n","import type { Arguments } from 'yargs';\nimport { POSTHOG_DOCS_URL } from '@shared/constants';\nimport { runWizard, runWizardCI } from '@cli/runners';\nimport { createSkillProgram } from '@programs';\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 '@shared/constants';\nimport { fetchSkillMenu } from '@shared/skill-menu';\nimport { analytics } from '@utils/analytics';\nimport { listSkills } from '@tools';\nimport { exitWith } from '@cli/runners';\n\nimport { runSkillMode } from './basic-integration/skill';\nimport { skillProgramOptions } from './skill-program-options';\nimport { runCommandHandler } from './factories/shared';\nimport type { Command } from './command';\n\n/** Read the `<skill-name>` positional (yargs camelCases the hyphenated key). */\nfunction readSkillName(argv: Arguments): string {\n return String(argv.skillName ?? argv['skill-name'] ?? '').trim();\n}\n\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\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 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.\n check: (argv) => {\n if (!readSkillName(argv)) {\n throw new Error(\n 'skill needs a skill name, e.g. `wizard skill audit-events`',\n );\n }\n return true;\n },\n handler: (argv) => {\n // `list` is the positional's one reserved value, not a skill id.\n if (readSkillName(argv) === 'list') return exitWith(listSkills);\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","/** The CLI's one entry: `main.ts` runs the `wizard` command line through it. */\nimport { Wizard } from './wizard';\nimport { basicIntegrationCommand } from './commands/basic-integration';\nimport { mcpCommand } from './commands/mcp';\nimport { mcpAnalyticsCommand } from './commands/mcp-analytics';\nimport { replayVisionCommand } from './commands/replay-vision';\nimport { aiObservabilityCommand } from './commands/ai-observability';\nimport { metricsCommand } from './commands/metrics';\nimport { cliCommand } from './commands/cli';\nimport { auditCommand } from './commands/audit';\nimport { doctorCommand } from './commands/doctor';\nimport { migrateCommand } from './commands/migrate';\nimport { revenueCommand } from './commands/revenue';\nimport { warehouseCommand } from './commands/warehouse';\nimport { selfDrivingCommand } from './commands/self-driving';\nimport { slackCommand } from './commands/slack';\nimport { uploadSourcemapsCommand } from './commands/upload-sourcemaps';\nimport { errorTrackingCommand } from './commands/error-tracking';\nimport { featureFlagsCommand } from './commands/feature-flags';\nimport { skillCommand } from './commands/skill';\n\n/** Register every command and run the one `process.argv` names. */\nexport function runCli(): void {\n Wizard.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(errorTrackingCommand)\n .use(featureFlagsCommand)\n .use(skillCommand)\n .init();\n}\n","import { Agent, setGlobalDispatcher } from 'undici';\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\nimport { runCli } from '@cli';\nimport { recoverOrphanedSettingsBackups } from '@shared/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\nrunCli();\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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,QAAO,OAAO,MAAM,GAAwB;AACxD,QAAO,QAAQ,IAAI,8BAA8B,QAAQ,KAAK;;AAGhE,QAAQ"}
@@ -1,5 +1,5 @@
1
- import { f as VERSION, o as logToFile } from "./debug-BfO_Txo8.js";
2
- import { o as onAccessTokenRotated } from "./oauth-session-9EU3ky0v.js";
1
+ import { f as VERSION, o as logToFile } from "./debug-BWrfAT_d.js";
2
+ import { o as onAccessTokenRotated } from "./oauth-session-DTydKnfV.js";
3
3
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
4
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
5
5
  import { createJiti } from "jiti";
@@ -93,4 +93,4 @@ async function setupPostHogMcp(opts) {
93
93
  //#endregion
94
94
  export { fetchInstructions, setupPostHogMcp };
95
95
 
96
- //# sourceMappingURL=mcp-KVV6Z_bq.js.map
96
+ //# sourceMappingURL=mcp-D1rpXjM2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-KVV6Z_bq.js","names":[],"sources":["../src/agent/runner/harness/pi/mcp.ts"],"sourcesContent":["/**\n * pi has no built-in MCP; `pi-mcp-adapter` — pi's own MCP extension, built here\n * with its supported `createMcpAdapter` embedding API — bridges the same hosted\n * MCP the anthropic path uses into the agent.\n */\n\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { createJiti } from 'jiti';\nimport { VERSION } from '@shared/version';\nimport { logToFile } from '@utils/debug';\nimport { onAccessTokenRotated } from '@shared/oauth-session';\n\nconst MCP_TOKEN_ENV = 'POSTHOG_MCP_TOKEN';\nlet mcpTokenOwners = 0;\nlet activeMcpToken: string | undefined;\nlet previousMcpToken: string | undefined;\n\nlet stopFollowingRotations: (() => void) | undefined;\n\nfunction setMcpToken(token: string): void {\n activeMcpToken = token;\n process.env[MCP_TOKEN_ENV] = token;\n}\n\nfunction acquireMcpToken(token: string): () => void {\n if (mcpTokenOwners === 0) {\n previousMcpToken = process.env[MCP_TOKEN_ENV];\n // The adapter reads the env on each connect, so reconnects take the rotated token.\n stopFollowingRotations = onAccessTokenRotated(setMcpToken);\n }\n // A later session after a rotation carries the newer token of the same login.\n if (activeMcpToken !== token) setMcpToken(token);\n mcpTokenOwners += 1;\n let released = false;\n return () => {\n if (released) return;\n released = true;\n mcpTokenOwners -= 1;\n if (mcpTokenOwners > 0) return;\n stopFollowingRotations?.();\n stopFollowingRotations = undefined;\n if (previousMcpToken === undefined) delete process.env[MCP_TOKEN_ENV];\n else process.env[MCP_TOKEN_ENV] = previousMcpToken;\n activeMcpToken = undefined;\n previousMcpToken = undefined;\n };\n}\n\nexport interface PostHogMcpSetup {\n /** pi ExtensionFactory to add to the resource loader's `extensionFactories`. */\n extensionFactory: (pi: unknown) => void;\n /** Release this setup's token ownership. Call after the run. */\n cleanup: () => void;\n}\n\n/** Server `instructions` for the system prompt — the adapter exposes no accessor, so one standard-SDK handshake; best-effort. */\nexport async function fetchInstructions(\n mcpUrl: string,\n accessToken: string,\n userAgent: string,\n): Promise<string | undefined> {\n const client = new Client({ name: 'posthog-wizard', version: VERSION });\n try {\n const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), {\n requestInit: {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'User-Agent': userAgent,\n },\n },\n });\n await client.connect(transport);\n const instructions = client.getInstructions() || undefined;\n logToFile(`[pi-mcp] instructions ${instructions?.length ?? 0} chars`);\n return instructions;\n } catch (err) {\n logToFile(`[pi-mcp] instructions fetch skipped: ${String(err)}`);\n return undefined;\n } finally {\n await client.close().catch(() => undefined);\n }\n}\n\nexport async function setupPostHogMcp(opts: {\n mcpUrl: string;\n accessToken: string;\n userAgent: string;\n}): Promise<PostHogMcpSetup> {\n const { mcpUrl, accessToken, userAgent } = opts;\n\n // By env NAME: the token stays in this process, off disk, and never reaches pi's env-scrubbed tool subprocesses.\n const cleanup = acquireMcpToken(accessToken);\n\n try {\n // The adapter ships raw TypeScript; loading through jiti is its documented requirement.\n const jiti = createJiti(import.meta.url);\n const mod = await jiti.import<{\n createMcpAdapter: (\n options: unknown,\n ) => PostHogMcpSetup['extensionFactory'];\n }>('pi-mcp-adapter');\n const extensionFactory = mod.createMcpAdapter({\n config: {\n mcpServers: {\n posthog: {\n url: mcpUrl,\n auth: 'bearer',\n bearerTokenEnv: MCP_TOKEN_ENV,\n headers: { 'User-Agent': userAgent },\n // Connect at extension load — direct tools register without a session_start.\n lifecycle: 'eager',\n // Register only `exec`: `directTools: true` also mints a `posthog_get_<name>` tool per MCP resource, whose sentence-length names overflow Anthropic's 128-char tool-name limit and 400 the whole request.\n directTools: ['exec'],\n exposeResources: false,\n },\n },\n // Disable the proxy `mcp` tool (its search indirection pollutes context); the adapter re-enables it only if no direct tools resolve.\n settings: { disableProxyTool: true, toolPrefix: 'posthog' },\n },\n });\n logToFile(`[pi-mcp] adapter loaded; posthog MCP at ${mcpUrl}`);\n return { extensionFactory, cleanup };\n } catch (error) {\n cleanup();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,gBAAgB;AACtB,IAAI,iBAAiB;AACrB,IAAI;AACJ,IAAI;AAEJ,IAAI;AAEJ,SAAS,YAAY,OAAqB;AACxC,kBAAiB;AACjB,SAAQ,IAAI,iBAAiB;;AAG/B,SAAS,gBAAgB,OAA2B;AAClD,KAAI,mBAAmB,GAAG;AACxB,qBAAmB,QAAQ,IAAI;AAE/B,2BAAyB,qBAAqB,YAAY;;AAG5D,KAAI,mBAAmB,MAAO,aAAY,MAAM;AAChD,mBAAkB;CAClB,IAAI,WAAW;AACf,cAAa;AACX,MAAI,SAAU;AACd,aAAW;AACX,oBAAkB;AAClB,MAAI,iBAAiB,EAAG;AACxB,4BAA0B;AAC1B,2BAAyB,KAAA;AACzB,MAAI,qBAAqB,KAAA,EAAW,QAAO,QAAQ,IAAI;MAClD,SAAQ,IAAI,iBAAiB;AAClC,mBAAiB,KAAA;AACjB,qBAAmB,KAAA;;;;AAYvB,eAAsB,kBACpB,QACA,aACA,WAC6B;CAC7B,MAAM,SAAS,IAAI,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAS,CAAC;AACvE,KAAI;EACF,MAAM,YAAY,IAAI,8BAA8B,IAAI,IAAI,OAAO,EAAE,EACnE,aAAa,EACX,SAAS;GACP,eAAe,UAAU;GACzB,cAAc;GACf,EACF,EACF,CAAC;AACF,QAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,eAAe,OAAO,iBAAiB,IAAI,KAAA;AACjD,YAAU,yBAAyB,cAAc,UAAU,EAAE,QAAQ;AACrE,SAAO;UACA,KAAK;AACZ,YAAU,wCAAwC,OAAO,IAAI,GAAG;AAChE;WACQ;AACR,QAAM,OAAO,OAAO,CAAC,YAAY,KAAA,EAAU;;;AAI/C,eAAsB,gBAAgB,MAIT;CAC3B,MAAM,EAAE,QAAQ,aAAa,cAAc;CAG3C,MAAM,UAAU,gBAAgB,YAAY;AAE5C,KAAI;EAQF,MAAM,oBALM,MADC,WAAW,OAAO,KAAK,IAAI,CACjB,OAIpB,iBAAiB,EACS,iBAAiB,EAC5C,QAAQ;GACN,YAAY,EACV,SAAS;IACP,KAAK;IACL,MAAM;IACN,gBAAgB;IAChB,SAAS,EAAE,cAAc,WAAW;IAEpC,WAAW;IAEX,aAAa,CAAC,OAAO;IACrB,iBAAiB;IAClB,EACF;GAED,UAAU;IAAE,kBAAkB;IAAM,YAAY;IAAW;GAC5D,EACF,CAAC;AACF,YAAU,2CAA2C,SAAS;AAC9D,SAAO;GAAE;GAAkB;GAAS;UAC7B,OAAO;AACd,WAAS;AACT,QAAM"}
1
+ {"version":3,"file":"mcp-D1rpXjM2.js","names":[],"sources":["../src/agent/runner/harness/pi/mcp.ts"],"sourcesContent":["/**\n * pi has no built-in MCP; `pi-mcp-adapter` — pi's own MCP extension, built here\n * with its supported `createMcpAdapter` embedding API — bridges the same hosted\n * MCP the anthropic path uses into the agent.\n */\n\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { createJiti } from 'jiti';\nimport { VERSION } from '@shared/version';\nimport { logToFile } from '@utils/debug';\nimport { onAccessTokenRotated } from '@shared/oauth-session';\n\nconst MCP_TOKEN_ENV = 'POSTHOG_MCP_TOKEN';\nlet mcpTokenOwners = 0;\nlet activeMcpToken: string | undefined;\nlet previousMcpToken: string | undefined;\n\nlet stopFollowingRotations: (() => void) | undefined;\n\nfunction setMcpToken(token: string): void {\n activeMcpToken = token;\n process.env[MCP_TOKEN_ENV] = token;\n}\n\nfunction acquireMcpToken(token: string): () => void {\n if (mcpTokenOwners === 0) {\n previousMcpToken = process.env[MCP_TOKEN_ENV];\n // The adapter reads the env on each connect, so reconnects take the rotated token.\n stopFollowingRotations = onAccessTokenRotated(setMcpToken);\n }\n // A later session after a rotation carries the newer token of the same login.\n if (activeMcpToken !== token) setMcpToken(token);\n mcpTokenOwners += 1;\n let released = false;\n return () => {\n if (released) return;\n released = true;\n mcpTokenOwners -= 1;\n if (mcpTokenOwners > 0) return;\n stopFollowingRotations?.();\n stopFollowingRotations = undefined;\n if (previousMcpToken === undefined) delete process.env[MCP_TOKEN_ENV];\n else process.env[MCP_TOKEN_ENV] = previousMcpToken;\n activeMcpToken = undefined;\n previousMcpToken = undefined;\n };\n}\n\nexport interface PostHogMcpSetup {\n /** pi ExtensionFactory to add to the resource loader's `extensionFactories`. */\n extensionFactory: (pi: unknown) => void;\n /** Release this setup's token ownership. Call after the run. */\n cleanup: () => void;\n}\n\n/** Server `instructions` for the system prompt — the adapter exposes no accessor, so one standard-SDK handshake; best-effort. */\nexport async function fetchInstructions(\n mcpUrl: string,\n accessToken: string,\n userAgent: string,\n): Promise<string | undefined> {\n const client = new Client({ name: 'posthog-wizard', version: VERSION });\n try {\n const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), {\n requestInit: {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'User-Agent': userAgent,\n },\n },\n });\n await client.connect(transport);\n const instructions = client.getInstructions() || undefined;\n logToFile(`[pi-mcp] instructions ${instructions?.length ?? 0} chars`);\n return instructions;\n } catch (err) {\n logToFile(`[pi-mcp] instructions fetch skipped: ${String(err)}`);\n return undefined;\n } finally {\n await client.close().catch(() => undefined);\n }\n}\n\nexport async function setupPostHogMcp(opts: {\n mcpUrl: string;\n accessToken: string;\n userAgent: string;\n}): Promise<PostHogMcpSetup> {\n const { mcpUrl, accessToken, userAgent } = opts;\n\n // By env NAME: the token stays in this process, off disk, and never reaches pi's env-scrubbed tool subprocesses.\n const cleanup = acquireMcpToken(accessToken);\n\n try {\n // The adapter ships raw TypeScript; loading through jiti is its documented requirement.\n const jiti = createJiti(import.meta.url);\n const mod = await jiti.import<{\n createMcpAdapter: (\n options: unknown,\n ) => PostHogMcpSetup['extensionFactory'];\n }>('pi-mcp-adapter');\n const extensionFactory = mod.createMcpAdapter({\n config: {\n mcpServers: {\n posthog: {\n url: mcpUrl,\n auth: 'bearer',\n bearerTokenEnv: MCP_TOKEN_ENV,\n headers: { 'User-Agent': userAgent },\n // Connect at extension load — direct tools register without a session_start.\n lifecycle: 'eager',\n // Register only `exec`: `directTools: true` also mints a `posthog_get_<name>` tool per MCP resource, whose sentence-length names overflow Anthropic's 128-char tool-name limit and 400 the whole request.\n directTools: ['exec'],\n exposeResources: false,\n },\n },\n // Disable the proxy `mcp` tool (its search indirection pollutes context); the adapter re-enables it only if no direct tools resolve.\n settings: { disableProxyTool: true, toolPrefix: 'posthog' },\n },\n });\n logToFile(`[pi-mcp] adapter loaded; posthog MCP at ${mcpUrl}`);\n return { extensionFactory, cleanup };\n } catch (error) {\n cleanup();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,gBAAgB;AACtB,IAAI,iBAAiB;AACrB,IAAI;AACJ,IAAI;AAEJ,IAAI;AAEJ,SAAS,YAAY,OAAqB;AACxC,kBAAiB;AACjB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AAW;IAEpC,WAAW;IAEX,aAAa,CAAC,OAAO;IACrB,iBAAiB;IAClB,EACF;GAED,UAAU;IAAE,kBAAkB;IAAM,YAAY;IAAW;GAC5D,EACF,CAAC;AACF,YAAU,2CAA2C,SAAS;AAC9D,SAAO;GAAE;GAAkB;GAAS;UAC7B,OAAO;AACd,WAAS;AACT,QAAM"}
@@ -1,7 +1,7 @@
1
- import { o as logToFile } from "./debug-BfO_Txo8.js";
2
- import { it as WIZARD_USER_AGENT, n as analytics, p as DEFAULT_AGENT_MODEL } from "./analytics-Drox5LSW.js";
3
- import { p as gatewayAuth } from "./gateway-CLQQb96F.js";
4
- import { f as sanitizeAgentSubprocessEnv, n as buildRunTags, o as createIsolatedAgentConfigDir, t as buildAgentEnv } from "./agent-interface-BNssNetq.js";
1
+ import { o as logToFile } from "./debug-BWrfAT_d.js";
2
+ import { it as WIZARD_USER_AGENT, n as analytics, p as DEFAULT_AGENT_MODEL } from "./analytics-J1cjIekQ.js";
3
+ import { p as gatewayAuth } from "./gateway-DrKvPnHW.js";
4
+ import { f as sanitizeAgentSubprocessEnv, n as buildRunTags, o as createIsolatedAgentConfigDir, t as buildAgentEnv } from "./agent-interface-C2yoWWW_.js";
5
5
  //#region src/agent/mcp-prompt-streaming.ts
6
6
  let _sdkModule = null;
7
7
  async function loadSdk() {
@@ -250,4 +250,4 @@ async function* streamMcpPrompt(args) {
250
250
  //#endregion
251
251
  export { streamMcpPrompt };
252
252
 
253
- //# sourceMappingURL=mcp-prompt-streaming-M6UnLgGX.js.map
253
+ //# sourceMappingURL=mcp-prompt-streaming-GXBA581m.js.map