@posthog/wizard 2.7.0 → 2.9.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 (233) hide show
  1. package/README.md +11 -0
  2. package/dist/bin.js +289 -162
  3. package/dist/bin.js.map +1 -1
  4. package/dist/src/__tests__/cli.test.js +92 -59
  5. package/dist/src/__tests__/cli.test.js.map +1 -1
  6. package/dist/src/__tests__/wizard-abort.test.js +34 -13
  7. package/dist/src/__tests__/wizard-abort.test.js.map +1 -1
  8. package/dist/src/frameworks/android/android-wizard-agent.js +2 -2
  9. package/dist/src/frameworks/android/android-wizard-agent.js.map +1 -1
  10. package/dist/src/frameworks/angular/angular-wizard-agent.js +2 -2
  11. package/dist/src/frameworks/angular/angular-wizard-agent.js.map +1 -1
  12. package/dist/src/frameworks/astro/astro-wizard-agent.js +2 -2
  13. package/dist/src/frameworks/astro/astro-wizard-agent.js.map +1 -1
  14. package/dist/src/frameworks/django/django-wizard-agent.js +2 -2
  15. package/dist/src/frameworks/django/django-wizard-agent.js.map +1 -1
  16. package/dist/src/frameworks/fastapi/fastapi-wizard-agent.js +2 -2
  17. package/dist/src/frameworks/fastapi/fastapi-wizard-agent.js.map +1 -1
  18. package/dist/src/frameworks/flask/flask-wizard-agent.js +2 -2
  19. package/dist/src/frameworks/flask/flask-wizard-agent.js.map +1 -1
  20. package/dist/src/frameworks/javascript-node/javascript-node-wizard-agent.js +2 -2
  21. package/dist/src/frameworks/javascript-node/javascript-node-wizard-agent.js.map +1 -1
  22. package/dist/src/frameworks/javascript-web/javascript-web-wizard-agent.js +2 -2
  23. package/dist/src/frameworks/javascript-web/javascript-web-wizard-agent.js.map +1 -1
  24. package/dist/src/frameworks/laravel/laravel-wizard-agent.js +2 -2
  25. package/dist/src/frameworks/laravel/laravel-wizard-agent.js.map +1 -1
  26. package/dist/src/frameworks/nextjs/nextjs-wizard-agent.js +2 -2
  27. package/dist/src/frameworks/nextjs/nextjs-wizard-agent.js.map +1 -1
  28. package/dist/src/frameworks/nuxt/nuxt-wizard-agent.js +2 -2
  29. package/dist/src/frameworks/nuxt/nuxt-wizard-agent.js.map +1 -1
  30. package/dist/src/frameworks/python/python-wizard-agent.js +2 -2
  31. package/dist/src/frameworks/python/python-wizard-agent.js.map +1 -1
  32. package/dist/src/frameworks/rails/rails-wizard-agent.js +2 -2
  33. package/dist/src/frameworks/rails/rails-wizard-agent.js.map +1 -1
  34. package/dist/src/frameworks/react-native/react-native-wizard-agent.js +2 -2
  35. package/dist/src/frameworks/react-native/react-native-wizard-agent.js.map +1 -1
  36. package/dist/src/frameworks/react-router/react-router-wizard-agent.js +2 -2
  37. package/dist/src/frameworks/react-router/react-router-wizard-agent.js.map +1 -1
  38. package/dist/src/frameworks/ruby/ruby-wizard-agent.js +2 -2
  39. package/dist/src/frameworks/ruby/ruby-wizard-agent.js.map +1 -1
  40. package/dist/src/frameworks/svelte/svelte-wizard-agent.js +2 -2
  41. package/dist/src/frameworks/svelte/svelte-wizard-agent.js.map +1 -1
  42. package/dist/src/frameworks/swift/swift-wizard-agent.js +2 -2
  43. package/dist/src/frameworks/swift/swift-wizard-agent.js.map +1 -1
  44. package/dist/src/frameworks/tanstack-router/tanstack-router-wizard-agent.js +2 -2
  45. package/dist/src/frameworks/tanstack-router/tanstack-router-wizard-agent.js.map +1 -1
  46. package/dist/src/frameworks/tanstack-start/tanstack-start-wizard-agent.js +2 -2
  47. package/dist/src/frameworks/tanstack-start/tanstack-start-wizard-agent.js.map +1 -1
  48. package/dist/src/frameworks/vue/vue-wizard-agent.js +2 -2
  49. package/dist/src/frameworks/vue/vue-wizard-agent.js.map +1 -1
  50. package/dist/src/lib/__tests__/agent-interface.test.js +29 -1
  51. package/dist/src/lib/__tests__/agent-interface.test.js.map +1 -1
  52. package/dist/src/lib/agent/__tests__/agent-prompt.test.js +57 -0
  53. package/dist/src/lib/agent/__tests__/agent-prompt.test.js.map +1 -0
  54. package/dist/src/lib/{agent-interface.d.ts → agent/agent-interface.d.ts} +18 -6
  55. package/dist/src/lib/{agent-interface.js → agent/agent-interface.js} +63 -13
  56. package/dist/src/lib/agent/agent-interface.js.map +1 -0
  57. package/dist/src/lib/agent/agent-prompt.d.ts +23 -0
  58. package/dist/src/lib/agent/agent-prompt.js +47 -0
  59. package/dist/src/lib/agent/agent-prompt.js.map +1 -0
  60. package/dist/src/lib/agent/agent-runner.d.ts +78 -0
  61. package/dist/src/lib/agent/agent-runner.js +323 -0
  62. package/dist/src/lib/agent/agent-runner.js.map +1 -0
  63. package/dist/src/lib/agent/commandments.js.map +1 -0
  64. package/dist/src/lib/constants.d.ts +10 -1
  65. package/dist/src/lib/constants.js +13 -1
  66. package/dist/src/lib/constants.js.map +1 -1
  67. package/dist/src/lib/detection/__tests__/context.test.js +72 -0
  68. package/dist/src/lib/detection/__tests__/context.test.js.map +1 -0
  69. package/dist/src/lib/detection/__tests__/features.test.d.ts +1 -0
  70. package/dist/src/lib/detection/__tests__/features.test.js +75 -0
  71. package/dist/src/lib/detection/__tests__/features.test.js.map +1 -0
  72. package/dist/src/lib/detection/__tests__/package-manager.test.d.ts +1 -0
  73. package/dist/src/lib/{__tests__/package-manager-detection.test.js → detection/__tests__/package-manager.test.js} +25 -25
  74. package/dist/src/lib/detection/__tests__/package-manager.test.js.map +1 -0
  75. package/dist/src/lib/detection/context.d.ts +31 -0
  76. package/dist/src/lib/detection/context.js +92 -0
  77. package/dist/src/lib/detection/context.js.map +1 -0
  78. package/dist/src/lib/detection/features.d.ts +16 -0
  79. package/dist/src/lib/detection/features.js +56 -0
  80. package/dist/src/lib/detection/features.js.map +1 -0
  81. package/dist/src/lib/detection/framework.d.ts +14 -0
  82. package/dist/src/lib/detection/framework.js +35 -0
  83. package/dist/src/lib/detection/framework.js.map +1 -0
  84. package/dist/src/lib/detection/index.d.ts +3 -0
  85. package/dist/src/lib/detection/index.js +11 -0
  86. package/dist/src/lib/detection/index.js.map +1 -0
  87. package/dist/src/lib/{package-manager-detection.js → detection/package-manager.js} +3 -3
  88. package/dist/src/lib/detection/package-manager.js.map +1 -0
  89. package/dist/src/lib/framework-config.d.ts +1 -1
  90. package/dist/src/lib/framework-config.js.map +1 -1
  91. package/dist/src/lib/health-checks/endpoints.js +2 -1
  92. package/dist/src/lib/health-checks/endpoints.js.map +1 -1
  93. package/dist/src/lib/middleware/benchmark.js +1 -1
  94. package/dist/src/lib/middleware/benchmark.js.map +1 -1
  95. package/dist/src/lib/middleware/benchmarks/compaction-tracker.js +1 -1
  96. package/dist/src/lib/middleware/benchmarks/compaction-tracker.js.map +1 -1
  97. package/dist/src/lib/middleware/benchmarks/json-writer.js +1 -1
  98. package/dist/src/lib/middleware/benchmarks/json-writer.js.map +1 -1
  99. package/dist/src/lib/middleware/benchmarks/summary.js +1 -1
  100. package/dist/src/lib/middleware/benchmarks/summary.js.map +1 -1
  101. package/dist/src/lib/middleware/config.js +1 -1
  102. package/dist/src/lib/middleware/config.js.map +1 -1
  103. package/dist/src/lib/version.d.ts +1 -1
  104. package/dist/src/lib/version.js +1 -1
  105. package/dist/src/lib/version.js.map +1 -1
  106. package/dist/src/lib/wizard-session.d.ts +20 -7
  107. package/dist/src/lib/wizard-session.js +4 -0
  108. package/dist/src/lib/wizard-session.js.map +1 -1
  109. package/dist/src/lib/wizard-tools.d.ts +28 -1
  110. package/dist/src/lib/wizard-tools.js +24 -0
  111. package/dist/src/lib/wizard-tools.js.map +1 -1
  112. package/dist/src/lib/workflows/__tests__/agent-skill.test.d.ts +1 -0
  113. package/dist/src/lib/workflows/__tests__/agent-skill.test.js +66 -0
  114. package/dist/src/lib/workflows/__tests__/agent-skill.test.js.map +1 -0
  115. package/dist/src/lib/workflows/__tests__/revenue-analytics-detect.test.d.ts +1 -0
  116. package/dist/src/lib/workflows/__tests__/revenue-analytics-detect.test.js +101 -0
  117. package/dist/src/lib/workflows/__tests__/revenue-analytics-detect.test.js.map +1 -0
  118. package/dist/src/lib/workflows/__tests__/workflow-registry.test.d.ts +1 -0
  119. package/dist/src/lib/workflows/__tests__/workflow-registry.test.js +32 -0
  120. package/dist/src/lib/workflows/__tests__/workflow-registry.test.js.map +1 -0
  121. package/dist/src/lib/workflows/__tests__/workflow-step.test.d.ts +1 -0
  122. package/dist/src/lib/workflows/__tests__/workflow-step.test.js +54 -0
  123. package/dist/src/lib/workflows/__tests__/workflow-step.test.js.map +1 -0
  124. package/dist/src/lib/workflows/agent-skill/index.d.ts +44 -0
  125. package/dist/src/lib/workflows/agent-skill/index.js +47 -0
  126. package/dist/src/lib/workflows/agent-skill/index.js.map +1 -0
  127. package/dist/src/lib/workflows/agent-skill/steps.d.ts +8 -0
  128. package/dist/src/lib/workflows/agent-skill/steps.js +32 -0
  129. package/dist/src/lib/workflows/agent-skill/steps.js.map +1 -0
  130. package/dist/src/lib/workflows/posthog-integration/detect.d.ts +12 -0
  131. package/dist/src/lib/workflows/posthog-integration/detect.js +57 -0
  132. package/dist/src/lib/workflows/posthog-integration/detect.js.map +1 -0
  133. package/dist/src/lib/workflows/posthog-integration/index.d.ts +3 -0
  134. package/dist/src/lib/workflows/posthog-integration/index.js +152 -0
  135. package/dist/src/lib/workflows/posthog-integration/index.js.map +1 -0
  136. package/dist/src/lib/workflows/posthog-integration/steps.d.ts +9 -0
  137. package/dist/src/lib/workflows/posthog-integration/steps.js +100 -0
  138. package/dist/src/lib/workflows/posthog-integration/steps.js.map +1 -0
  139. package/dist/src/lib/workflows/revenue-analytics/detect.d.ts +40 -0
  140. package/dist/src/lib/workflows/revenue-analytics/detect.js +156 -0
  141. package/dist/src/lib/workflows/revenue-analytics/detect.js.map +1 -0
  142. package/dist/src/lib/workflows/revenue-analytics/index.d.ts +4 -0
  143. package/dist/src/lib/workflows/revenue-analytics/index.js +30 -0
  144. package/dist/src/lib/workflows/revenue-analytics/index.js.map +1 -0
  145. package/dist/src/lib/workflows/revenue-analytics/steps.d.ts +8 -0
  146. package/dist/src/lib/workflows/revenue-analytics/steps.js +48 -0
  147. package/dist/src/lib/workflows/revenue-analytics/steps.js.map +1 -0
  148. package/dist/src/lib/workflows/workflow-registry.d.ts +18 -0
  149. package/dist/src/lib/workflows/workflow-registry.js +32 -0
  150. package/dist/src/lib/workflows/workflow-registry.js.map +1 -0
  151. package/dist/src/lib/workflows/workflow-step.d.ts +126 -0
  152. package/dist/src/lib/workflows/workflow-step.js +28 -0
  153. package/dist/src/lib/workflows/workflow-step.js.map +1 -0
  154. package/dist/src/steps/add-mcp-server-to-clients/index.d.ts +2 -1
  155. package/dist/src/steps/add-mcp-server-to-clients/index.js.map +1 -1
  156. package/dist/src/ui/logging-ui.d.ts +6 -3
  157. package/dist/src/ui/logging-ui.js +7 -0
  158. package/dist/src/ui/logging-ui.js.map +1 -1
  159. package/dist/src/ui/tui/__tests__/flows.test.d.ts +1 -0
  160. package/dist/src/ui/tui/__tests__/flows.test.js +115 -0
  161. package/dist/src/ui/tui/__tests__/flows.test.js.map +1 -0
  162. package/dist/src/ui/tui/__tests__/router.test.d.ts +1 -0
  163. package/dist/src/ui/tui/__tests__/router.test.js +87 -0
  164. package/dist/src/ui/tui/__tests__/router.test.js.map +1 -0
  165. package/dist/src/ui/tui/__tests__/store.test.js +100 -10
  166. package/dist/src/ui/tui/__tests__/store.test.js.map +1 -1
  167. package/dist/src/ui/tui/flows.d.ts +17 -6
  168. package/dist/src/ui/tui/flows.js +28 -52
  169. package/dist/src/ui/tui/flows.js.map +1 -1
  170. package/dist/src/ui/tui/ink-ui.d.ts +6 -3
  171. package/dist/src/ui/tui/ink-ui.js +7 -0
  172. package/dist/src/ui/tui/ink-ui.js.map +1 -1
  173. package/dist/src/ui/tui/primitives/ProgressList.d.ts +3 -1
  174. package/dist/src/ui/tui/primitives/ProgressList.js +2 -2
  175. package/dist/src/ui/tui/primitives/ProgressList.js.map +1 -1
  176. package/dist/src/ui/tui/router.js +1 -1
  177. package/dist/src/ui/tui/router.js.map +1 -1
  178. package/dist/src/ui/tui/screen-registry.js +2 -0
  179. package/dist/src/ui/tui/screen-registry.js.map +1 -1
  180. package/dist/src/ui/tui/screens/ManagedSettingsScreen.js.map +1 -1
  181. package/dist/src/ui/tui/screens/OutroScreen.js +1 -1
  182. package/dist/src/ui/tui/screens/OutroScreen.js.map +1 -1
  183. package/dist/src/ui/tui/screens/RevenueIntroScreen.d.ts +16 -0
  184. package/dist/src/ui/tui/screens/RevenueIntroScreen.js +64 -0
  185. package/dist/src/ui/tui/screens/RevenueIntroScreen.js.map +1 -0
  186. package/dist/src/ui/tui/screens/RunScreen.js +1 -1
  187. package/dist/src/ui/tui/screens/RunScreen.js.map +1 -1
  188. package/dist/src/ui/tui/screens/SettingsOverrideScreen.js.map +1 -1
  189. package/dist/src/ui/tui/screens/health/HealthCheckScreen.js +2 -2
  190. package/dist/src/ui/tui/screens/health/HealthCheckScreen.js.map +1 -1
  191. package/dist/src/ui/tui/start-tui.js +2 -2
  192. package/dist/src/ui/tui/start-tui.js.map +1 -1
  193. package/dist/src/ui/tui/store.d.ts +46 -21
  194. package/dist/src/ui/tui/store.js +105 -47
  195. package/dist/src/ui/tui/store.js.map +1 -1
  196. package/dist/src/ui/wizard-ui.d.ts +13 -3
  197. package/dist/src/ui/wizard-ui.js.map +1 -1
  198. package/dist/src/utils/__tests__/provisioning.test.d.ts +1 -0
  199. package/dist/src/utils/__tests__/provisioning.test.js +192 -0
  200. package/dist/src/utils/__tests__/provisioning.test.js.map +1 -0
  201. package/dist/src/utils/file-utils.d.ts +8 -0
  202. package/dist/src/utils/file-utils.js +32 -0
  203. package/dist/src/utils/file-utils.js.map +1 -1
  204. package/dist/src/utils/provisioning.d.ts +25 -0
  205. package/dist/src/utils/provisioning.js +191 -0
  206. package/dist/src/utils/provisioning.js.map +1 -0
  207. package/dist/src/utils/setup-utils.d.ts +4 -1
  208. package/dist/src/utils/setup-utils.js +46 -2
  209. package/dist/src/utils/setup-utils.js.map +1 -1
  210. package/dist/src/utils/types.d.ts +4 -0
  211. package/dist/src/utils/types.js.map +1 -1
  212. package/dist/src/utils/wizard-abort.d.ts +3 -0
  213. package/dist/src/utils/wizard-abort.js +5 -3
  214. package/dist/src/utils/wizard-abort.js.map +1 -1
  215. package/npm-shrinkwrap.json +2 -2
  216. package/package.json +1 -1
  217. package/dist/src/__tests__/run.test.js +0 -95
  218. package/dist/src/__tests__/run.test.js.map +0 -1
  219. package/dist/src/lib/__tests__/package-manager-detection.test.js.map +0 -1
  220. package/dist/src/lib/agent-interface.js.map +0 -1
  221. package/dist/src/lib/agent-runner.d.ts +0 -9
  222. package/dist/src/lib/agent-runner.js +0 -383
  223. package/dist/src/lib/agent-runner.js.map +0 -1
  224. package/dist/src/lib/commandments.js.map +0 -1
  225. package/dist/src/lib/package-manager-detection.js.map +0 -1
  226. package/dist/src/run.d.ts +0 -22
  227. package/dist/src/run.js +0 -152
  228. package/dist/src/run.js.map +0 -1
  229. /package/dist/src/{__tests__/run.test.d.ts → lib/agent/__tests__/agent-prompt.test.d.ts} +0 -0
  230. /package/dist/src/lib/{commandments.d.ts → agent/commandments.d.ts} +0 -0
  231. /package/dist/src/lib/{commandments.js → agent/commandments.js} +0 -0
  232. /package/dist/src/lib/{__tests__/package-manager-detection.test.d.ts → detection/__tests__/context.test.d.ts} +0 -0
  233. /package/dist/src/lib/{package-manager-detection.d.ts → detection/package-manager.d.ts} +0 -0
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * Core integration detection step.
4
+ *
5
+ * Runs framework detection, context gathering, version checking,
6
+ * and feature discovery. Writes results to the store via the
7
+ * WorkflowReadyContext so the IntroScreen can display them.
8
+ *
9
+ * This is the same work that bin.ts $0 handler does inline —
10
+ * extracted here so the `integrate` subcommand can reuse it.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.detectPostHogIntegration = detectPostHogIntegration;
14
+ const registry_js_1 = require("../../registry.js");
15
+ const index_js_1 = require("../../detection/index.js");
16
+ async function detectPostHogIntegration(ctx) {
17
+ const session = ctx.session;
18
+ const installDir = session.installDir;
19
+ const detectedIntegration = await (0, index_js_1.detectFramework)(installDir);
20
+ if (detectedIntegration) {
21
+ const config = registry_js_1.FRAMEWORK_REGISTRY[detectedIntegration];
22
+ const sessionOptions = {
23
+ installDir,
24
+ debug: session.debug,
25
+ forceInstall: session.forceInstall,
26
+ default: false,
27
+ signup: session.signup,
28
+ localMcp: session.localMcp,
29
+ ci: session.ci,
30
+ menu: session.menu,
31
+ benchmark: session.benchmark,
32
+ yaraReport: session.yaraReport,
33
+ };
34
+ // Gather framework-specific context (e.g., router type)
35
+ const context = await (0, index_js_1.gatherFrameworkContext)(config, sessionOptions);
36
+ for (const [key, value] of Object.entries(context)) {
37
+ if (!(key in session.frameworkContext)) {
38
+ ctx.setFrameworkContext(key, value);
39
+ }
40
+ }
41
+ ctx.setFrameworkConfig(detectedIntegration, config);
42
+ if (!session.detectedFrameworkLabel) {
43
+ ctx.setDetectedFramework(config.metadata.name);
44
+ }
45
+ // Version check
46
+ const versionResult = await (0, index_js_1.checkFrameworkVersion)(config, sessionOptions);
47
+ if (versionResult.supported !== true) {
48
+ ctx.setUnsupportedVersion(versionResult.supported);
49
+ }
50
+ }
51
+ // Feature discovery
52
+ for (const feature of (0, index_js_1.discoverFeatures)(installDir)) {
53
+ ctx.addDiscoveredFeature(feature);
54
+ }
55
+ ctx.setDetectionComplete();
56
+ }
57
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../../../../../src/lib/workflows/posthog-integration/detect.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAWH,4DAmDC;AA3DD,mDAAuD;AACvD,uDAKkC;AAE3B,KAAK,UAAU,wBAAwB,CAC5C,GAAyB;IAEzB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAEtC,MAAM,mBAAmB,GAAG,MAAM,IAAA,0BAAe,EAAC,UAAU,CAAC,CAAC;IAE9D,IAAI,mB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CAAC;IAED,oBAAoB;IACpB,KAAK,MAAM,OAAO,IAAI,IAAA,2BAAgB,EAAC,UAAU,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,GAAG,CAAC,oBAAoB,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/**\n * Core integration detection step.\n *\n * Runs framework detection, context gathering, version checking,\n * and feature discovery. Writes results to the store via the\n * WorkflowReadyContext so the IntroScreen can display them.\n *\n * This is the same work that bin.ts $0 handler does inline —\n * extracted here so the `integrate` subcommand can reuse it.\n */\n\nimport type { WorkflowReadyContext } from '../workflow-step.js';\nimport { FRAMEWORK_REGISTRY } from '../../registry.js';\nimport {\n detectFramework,\n discoverFeatures,\n gatherFrameworkContext,\n checkFrameworkVersion,\n} from '../../detection/index.js';\n\nexport async function detectPostHogIntegration(\n ctx: WorkflowReadyContext,\n): Promise<void> {\n const session = ctx.session;\n const installDir = session.installDir;\n\n const detectedIntegration = await detectFramework(installDir);\n\n if (detectedIntegration) {\n const config = FRAMEWORK_REGISTRY[detectedIntegration];\n\n const sessionOptions = {\n installDir,\n debug: session.debug,\n forceInstall: session.forceInstall,\n default: false,\n signup: session.signup,\n localMcp: session.localMcp,\n ci: session.ci,\n menu: session.menu,\n benchmark: session.benchmark,\n yaraReport: session.yaraReport,\n };\n\n // Gather framework-specific context (e.g., router type)\n const context = await gatherFrameworkContext(config, sessionOptions);\n for (const [key, value] of Object.entries(context)) {\n if (!(key in session.frameworkContext)) {\n ctx.setFrameworkContext(key, value);\n }\n }\n\n ctx.setFrameworkConfig(detectedIntegration, config);\n\n if (!session.detectedFrameworkLabel) {\n ctx.setDetectedFramework(config.metadata.name);\n }\n\n // Version check\n const versionResult = await checkFrameworkVersion(config, sessionOptions);\n if (versionResult.supported !== true) {\n ctx.setUnsupportedVersion(versionResult.supported);\n }\n }\n\n // Feature discovery\n for (const feature of discoverFeatures(installDir)) {\n ctx.addDiscoveredFeature(feature);\n }\n\n ctx.setDetectionComplete();\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { WorkflowConfig } from '../workflow-step.js';
2
+ export declare const posthogIntegrationConfig: WorkflowConfig;
3
+ export { POSTHOG_INTEGRATION_WORKFLOW } from './steps.js';
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POSTHOG_INTEGRATION_WORKFLOW = exports.posthogIntegrationConfig = void 0;
4
+ const wizard_session_js_1 = require("../../wizard-session.js");
5
+ const agent_interface_js_1 = require("../../agent/agent-interface.js");
6
+ const framework_config_js_1 = require("../../framework-config.js");
7
+ const setup_utils_js_1 = require("../../../utils/setup-utils.js");
8
+ const analytics_js_1 = require("../../../utils/analytics.js");
9
+ const constants_js_1 = require("../../constants.js");
10
+ const index_js_1 = require("../../../ui/index.js");
11
+ const urls_js_1 = require("../../../utils/urls.js");
12
+ const steps_js_1 = require("./steps.js");
13
+ exports.posthogIntegrationConfig = {
14
+ command: 'integrate',
15
+ description: 'Set up PostHog SDK integration',
16
+ flowKey: 'posthog-integration',
17
+ steps: steps_js_1.POSTHOG_INTEGRATION_WORKFLOW,
18
+ run: async (session) => {
19
+ const config = session.frameworkConfig;
20
+ const typeScriptDetected = (0, setup_utils_js_1.isUsingTypeScript)({
21
+ installDir: session.installDir,
22
+ });
23
+ session.typescript = typeScriptDetected;
24
+ // Read package.json and resolve framework version
25
+ const usesPackageJson = config.detection.usesPackageJson !== false;
26
+ let frameworkVersion;
27
+ if (usesPackageJson) {
28
+ const packageJson = await (0, setup_utils_js_1.tryGetPackageJson)({
29
+ installDir: session.installDir,
30
+ });
31
+ if (packageJson) {
32
+ const { hasPackageInstalled } = await import('../../../utils/package-json.js');
33
+ if (!hasPackageInstalled(config.detection.packageName, packageJson)) {
34
+ (0, index_js_1.getUI)().log.warn(`${config.detection.packageDisplayName} does not seem to be installed. Continuing anyway — the agent will handle it.`);
35
+ }
36
+ frameworkVersion = config.detection.getVersion(packageJson);
37
+ }
38
+ else {
39
+ (0, index_js_1.getUI)().log.warn('Could not find package.json. Continuing anyway — the agent will handle it.');
40
+ }
41
+ }
42
+ else {
43
+ frameworkVersion = config.detection.getVersion(null);
44
+ }
45
+ // Analytics tags
46
+ if (frameworkVersion && config.detection.getVersionBucket) {
47
+ const versionBucket = config.detection.getVersionBucket(frameworkVersion);
48
+ analytics_js_1.analytics.setTag(`${config.metadata.integration}-version`, versionBucket);
49
+ }
50
+ const frameworkContext = session.frameworkContext;
51
+ const contextTags = config.analytics.getTags(frameworkContext);
52
+ Object.entries(contextTags).forEach(([key, value]) => {
53
+ analytics_js_1.analytics.setTag(key, value);
54
+ });
55
+ return {
56
+ integrationLabel: config.metadata.integration,
57
+ additionalMcpServers: config.metadata.additionalMcpServers,
58
+ detectPackageManager: config.detection.detectPackageManager,
59
+ spinnerMessage: framework_config_js_1.SPINNER_MESSAGE,
60
+ successMessage: config.ui.successMessage,
61
+ estimatedDurationMinutes: config.ui.estimatedDurationMinutes,
62
+ reportFile: 'posthog-setup-report.md',
63
+ docsUrl: config.metadata.docsUrl,
64
+ errorMessage: 'Integration failed',
65
+ additionalFeatureQueue: session.additionalFeatureQueue,
66
+ customPrompt: (ctx) => {
67
+ const additionalLines = config.prompts.getAdditionalContextLines
68
+ ? config.prompts.getAdditionalContextLines(frameworkContext)
69
+ : [];
70
+ const additionalContext = additionalLines.length > 0
71
+ ? '\n' + additionalLines.map((line) => `- ${line}`).join('\n')
72
+ : '';
73
+ return `You have access to the PostHog MCP server which provides skills to integrate PostHog into this ${config.metadata.name} project.
74
+
75
+ Project context:
76
+ - PostHog Project ID: ${ctx.projectId}
77
+ - Framework: ${config.metadata.name} ${frameworkVersion || 'latest'}
78
+ - TypeScript: ${typeScriptDetected ? 'Yes' : 'No'}
79
+ - PostHog public token: ${ctx.projectApiKey}
80
+ - PostHog Host: ${ctx.host}
81
+ - Project type: ${config.prompts.projectTypeDetection}
82
+ - Package installation: ${config.prompts.packageInstallation ?? framework_config_js_1.DEFAULT_PACKAGE_INSTALLATION}${additionalContext}
83
+
84
+ Instructions (follow these steps IN ORDER - do not skip or reorder):
85
+
86
+ STEP 1: Call load_skill_menu (from the wizard-tools MCP server) to see available skills.
87
+ If the tool fails, emit: ${agent_interface_js_1.AgentSignals.ERROR_MCP_MISSING} Could not load skill menu and halt.
88
+
89
+ Choose a skill from the \`integration\` category that matches this project's framework. Do NOT pick skills from other categories (llm-analytics, error-tracking, feature-flags, omnibus, etc.) — those are handled separately.
90
+ If no suitable integration skill is found, emit: ${agent_interface_js_1.AgentSignals.ERROR_RESOURCE_MISSING} Could not find a suitable skill for this project.
91
+
92
+ STEP 2: Call install_skill (from the wizard-tools MCP server) with the chosen skill ID (e.g., "integration-nextjs-app-router").
93
+ Do NOT run any shell commands to install skills.
94
+
95
+ STEP 3: Load the installed skill's SKILL.md file to understand what references are available.
96
+
97
+ STEP 4: Follow the skill's workflow files in sequence. Look for numbered workflow files in the references (e.g., files with patterns like "1.0-", "1.1-", "1.2-"). Start with the first one and proceed through each step until completion. Each workflow file will tell you what to do and which file comes next. Never directly write PostHog tokens directly to code files; always use environment variables.
98
+
99
+ STEP 5: Set up environment variables for PostHog using the wizard-tools MCP server (this runs locally — secret values never leave the machine):
100
+ - Use check_env_keys to see which keys already exist in the project's .env file (e.g. .env.local or .env).
101
+ - Use set_env_values to create or update the PostHog public token and host, using the appropriate environment variable naming convention for ${config.metadata.name}, which you'll find in example code. The tool will also ensure .gitignore coverage. Don't assume the presence of keys means the value is up to date. Write the correct value each time.
102
+ - Reference these environment variables in the code files you create instead of hardcoding the public token and host.
103
+
104
+ Important: Use the detect_package_manager tool (from the wizard-tools MCP server) to determine which package manager the project uses. Do not manually search for lockfiles or config files. Always install packages as a background task. Don't await completion; proceed with other work immediately after starting the installation. You must read a file immediately before attempting to write it, even if you have previously read it; failure to do so will cause a tool failure.
105
+
106
+
107
+ `;
108
+ },
109
+ postRun: async (sess, credentials) => {
110
+ const envVars = config.environment.getEnvVars(credentials.projectApiKey, credentials.host);
111
+ if (config.environment.uploadToHosting) {
112
+ const { uploadEnvironmentVariablesStep } = await import('../../../steps/index.js');
113
+ const uploadedEnvVars = await uploadEnvironmentVariablesStep(envVars, {
114
+ integration: config.metadata.integration,
115
+ session: sess,
116
+ });
117
+ if (uploadedEnvVars.length > 0) {
118
+ analytics_js_1.analytics.capture(constants_js_1.WIZARD_INTERACTION_EVENT_NAME, {
119
+ action: 'wizard_env_vars_uploaded',
120
+ integration: config.metadata.integration,
121
+ variable_count: uploadedEnvVars.length,
122
+ variable_keys: uploadedEnvVars,
123
+ });
124
+ }
125
+ }
126
+ },
127
+ buildOutroData: (sess, credentials, cloudRegion) => {
128
+ const envVars = config.environment.getEnvVars(credentials.projectApiKey, credentials.host);
129
+ const continueUrl = sess.signup && cloudRegion
130
+ ? `${(0, urls_js_1.getCloudUrlFromRegion)(cloudRegion)}/products?source=wizard`
131
+ : undefined;
132
+ const changes = [
133
+ ...config.ui.getOutroChanges(frameworkContext),
134
+ Object.keys(envVars).length > 0
135
+ ? 'Added environment variables to .env file'
136
+ : '',
137
+ ].filter(Boolean);
138
+ return {
139
+ kind: wizard_session_js_1.OutroKind.Success,
140
+ message: 'Successfully installed PostHog!',
141
+ reportFile: 'posthog-setup-report.md',
142
+ changes,
143
+ docsUrl: config.metadata.docsUrl,
144
+ continueUrl,
145
+ };
146
+ },
147
+ };
148
+ },
149
+ };
150
+ var steps_js_2 = require("./steps.js");
151
+ Object.defineProperty(exports, "POSTHOG_INTEGRATION_WORKFLOW", { enumerable: true, get: function () { return steps_js_2.POSTHOG_INTEGRATION_WORKFLOW; } });
152
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/workflows/posthog-integration/index.ts"],"names":[],"mappings":";;;AAGA,+DAAoD;AACpD,uEAA8D;AAC9D,mEAGmC;AACnC,kEAGuC;AACvC,8DAAwD;AACxD,qDAAmE;A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AAA","sourcesContent":["import type { WorkflowConfig } from '../workflow-step.js';\nimport type { WorkflowRun } from '../../agent/agent-runner.js';\nimport type { WizardSession } from '../../wizard-session.js';\nimport { OutroKind } from '../../wizard-session.js';\nimport { AgentSignals } from '../../agent/agent-interface.js';\nimport {\n DEFAULT_PACKAGE_INSTALLATION,\n SPINNER_MESSAGE,\n} from '../../framework-config.js';\nimport {\n tryGetPackageJson,\n isUsingTypeScript,\n} from '../../../utils/setup-utils.js';\nimport { analytics } from '../../../utils/analytics.js';\nimport { WIZARD_INTERACTION_EVENT_NAME } from '../../constants.js';\nimport { getUI } from '../../../ui/index.js';\nimport { getCloudUrlFromRegion } from '../../../utils/urls.js';\nimport { POSTHOG_INTEGRATION_WORKFLOW } from './steps.js';\n\nexport const posthogIntegrationConfig: WorkflowConfig = {\n command: 'integrate',\n description: 'Set up PostHog SDK integration',\n flowKey: 'posthog-integration',\n steps: POSTHOG_INTEGRATION_WORKFLOW,\n\n run: async (session: WizardSession): Promise<WorkflowRun> => {\n const config = session.frameworkConfig!;\n\n const typeScriptDetected = isUsingTypeScript({\n installDir: session.installDir,\n });\n session.typescript = typeScriptDetected;\n\n // Read package.json and resolve framework version\n const usesPackageJson = config.detection.usesPackageJson !== false;\n let frameworkVersion: string | undefined;\n\n if (usesPackageJson) {\n const packageJson = await tryGetPackageJson({\n installDir: session.installDir,\n });\n if (packageJson) {\n const { hasPackageInstalled } = await import(\n '../../../utils/package-json.js'\n );\n if (!hasPackageInstalled(config.detection.packageName, packageJson)) {\n getUI().log.warn(\n `${config.detection.packageDisplayName} does not seem to be installed. Continuing anyway — the agent will handle it.`,\n );\n }\n frameworkVersion = config.detection.getVersion(packageJson);\n } else {\n getUI().log.warn(\n 'Could not find package.json. Continuing anyway — the agent will handle it.',\n );\n }\n } else {\n frameworkVersion = config.detection.getVersion(null);\n }\n\n // Analytics tags\n if (frameworkVersion && config.detection.getVersionBucket) {\n const versionBucket = config.detection.getVersionBucket(frameworkVersion);\n analytics.setTag(`${config.metadata.integration}-version`, versionBucket);\n }\n const frameworkContext = session.frameworkContext;\n const contextTags = config.analytics.getTags(frameworkContext);\n Object.entries(contextTags).forEach(([key, value]) => {\n analytics.setTag(key, value);\n });\n\n return {\n integrationLabel: config.metadata.integration,\n additionalMcpServers: config.metadata.additionalMcpServers,\n detectPackageManager: config.detection.detectPackageManager,\n spinnerMessage: SPINNER_MESSAGE,\n successMessage: config.ui.successMessage,\n estimatedDurationMinutes: config.ui.estimatedDurationMinutes,\n reportFile: 'posthog-setup-report.md',\n docsUrl: config.metadata.docsUrl,\n errorMessage: 'Integration failed',\n additionalFeatureQueue: session.additionalFeatureQueue,\n\n customPrompt: (ctx) => {\n const additionalLines = config.prompts.getAdditionalContextLines\n ? config.prompts.getAdditionalContextLines(frameworkContext)\n : [];\n const additionalContext =\n additionalLines.length > 0\n ? '\\n' + additionalLines.map((line) => `- ${line}`).join('\\n')\n : '';\n\n return `You have access to the PostHog MCP server which provides skills to integrate PostHog into this ${\n config.metadata.name\n } project.\n\nProject context:\n- PostHog Project ID: ${ctx.projectId}\n- Framework: ${config.metadata.name} ${frameworkVersion || 'latest'}\n- TypeScript: ${typeScriptDetected ? 'Yes' : 'No'}\n- PostHog public token: ${ctx.projectApiKey}\n- PostHog Host: ${ctx.host}\n- Project type: ${config.prompts.projectTypeDetection}\n- Package installation: ${\n config.prompts.packageInstallation ?? DEFAULT_PACKAGE_INSTALLATION\n }${additionalContext}\n\nInstructions (follow these steps IN ORDER - do not skip or reorder):\n\nSTEP 1: Call load_skill_menu (from the wizard-tools MCP server) to see available skills.\n If the tool fails, emit: ${\n AgentSignals.ERROR_MCP_MISSING\n } Could not load skill menu and halt.\n\n Choose a skill from the \\`integration\\` category that matches this project's framework. Do NOT pick skills from other categories (llm-analytics, error-tracking, feature-flags, omnibus, etc.) — those are handled separately.\n If no suitable integration skill is found, emit: ${\n AgentSignals.ERROR_RESOURCE_MISSING\n } Could not find a suitable skill for this project.\n\nSTEP 2: Call install_skill (from the wizard-tools MCP server) with the chosen skill ID (e.g., \"integration-nextjs-app-router\").\n Do NOT run any shell commands to install skills.\n\nSTEP 3: Load the installed skill's SKILL.md file to understand what references are available.\n\nSTEP 4: Follow the skill's workflow files in sequence. Look for numbered workflow files in the references (e.g., files with patterns like \"1.0-\", \"1.1-\", \"1.2-\"). Start with the first one and proceed through each step until completion. Each workflow file will tell you what to do and which file comes next. Never directly write PostHog tokens directly to code files; always use environment variables.\n\nSTEP 5: Set up environment variables for PostHog using the wizard-tools MCP server (this runs locally — secret values never leave the machine):\n - Use check_env_keys to see which keys already exist in the project's .env file (e.g. .env.local or .env).\n - Use set_env_values to create or update the PostHog public token and host, using the appropriate environment variable naming convention for ${\n config.metadata.name\n }, which you'll find in example code. The tool will also ensure .gitignore coverage. Don't assume the presence of keys means the value is up to date. Write the correct value each time.\n - Reference these environment variables in the code files you create instead of hardcoding the public token and host.\n\nImportant: Use the detect_package_manager tool (from the wizard-tools MCP server) to determine which package manager the project uses. Do not manually search for lockfiles or config files. Always install packages as a background task. Don't await completion; proceed with other work immediately after starting the installation. You must read a file immediately before attempting to write it, even if you have previously read it; failure to do so will cause a tool failure.\n\n\n`;\n },\n\n postRun: async (sess, credentials) => {\n const envVars = config.environment.getEnvVars(\n credentials.projectApiKey,\n credentials.host,\n );\n if (config.environment.uploadToHosting) {\n const { uploadEnvironmentVariablesStep } = await import(\n '../../../steps/index.js'\n );\n const uploadedEnvVars = await uploadEnvironmentVariablesStep(\n envVars,\n {\n integration: config.metadata.integration,\n session: sess,\n },\n );\n if (uploadedEnvVars.length > 0) {\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'wizard_env_vars_uploaded',\n integration: config.metadata.integration,\n variable_count: uploadedEnvVars.length,\n variable_keys: uploadedEnvVars,\n });\n }\n }\n },\n\n buildOutroData: (sess, credentials, cloudRegion) => {\n const envVars = config.environment.getEnvVars(\n credentials.projectApiKey,\n credentials.host,\n );\n const continueUrl =\n sess.signup && cloudRegion\n ? `${getCloudUrlFromRegion(cloudRegion)}/products?source=wizard`\n : undefined;\n\n const changes = [\n ...config.ui.getOutroChanges(frameworkContext),\n Object.keys(envVars).length > 0\n ? 'Added environment variables to .env file'\n : '',\n ].filter(Boolean);\n\n return {\n kind: OutroKind.Success as const,\n message: 'Successfully installed PostHog!',\n reportFile: 'posthog-setup-report.md',\n changes,\n docsUrl: config.metadata.docsUrl,\n continueUrl,\n };\n },\n };\n },\n};\n\nexport { POSTHOG_INTEGRATION_WORKFLOW } from './steps.js';\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * PostHog integration workflow — the default wizard flow.
3
+ *
4
+ * Steps define their own gate predicates and onInit callbacks.
5
+ * The store derives gate promises and fires init work from these
6
+ * definitions — no hardcoded per-flow logic in the store.
7
+ */
8
+ import type { Workflow } from '../workflow-step.js';
9
+ export declare const POSTHOG_INTEGRATION_WORKFLOW: Workflow;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * PostHog integration workflow — the default wizard flow.
4
+ *
5
+ * Steps define their own gate predicates and onInit callbacks.
6
+ * The store derives gate promises and fires init work from these
7
+ * definitions — no hardcoded per-flow logic in the store.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.POSTHOG_INTEGRATION_WORKFLOW = void 0;
11
+ const wizard_session_js_1 = require("../../wizard-session.js");
12
+ const readiness_js_1 = require("../../health-checks/readiness.js");
13
+ const detect_js_1 = require("./detect.js");
14
+ function needsSetup(session) {
15
+ const config = session.frameworkConfig;
16
+ if (!config?.metadata.setup?.questions)
17
+ return false;
18
+ return config.metadata.setup.questions.some((q) => !(q.key in session.frameworkContext));
19
+ }
20
+ function healthCheckReady(session) {
21
+ if (!session.readinessResult)
22
+ return false;
23
+ if (session.readinessResult.decision === readiness_js_1.WizardReadiness.No)
24
+ return session.outageDismissed;
25
+ return true;
26
+ }
27
+ exports.POSTHOG_INTEGRATION_WORKFLOW = [
28
+ {
29
+ id: 'detect',
30
+ label: 'Detecting framework',
31
+ // Headless step: no screen. onReady fires after bin.ts assigns the
32
+ // session — runs framework detection, context gathering, version
33
+ // check, and feature discovery. Results are written to the store
34
+ // for the IntroScreen to render.
35
+ onReady: (ctx) => (0, detect_js_1.detectPostHogIntegration)(ctx),
36
+ },
37
+ {
38
+ id: 'intro',
39
+ label: 'Welcome',
40
+ screen: 'intro',
41
+ gate: (session) => session.setupConfirmed,
42
+ },
43
+ {
44
+ id: 'health-check',
45
+ label: 'Health check',
46
+ screen: 'health-check',
47
+ gate: healthCheckReady,
48
+ onInit: (ctx) => {
49
+ (0, readiness_js_1.evaluateWizardReadiness)()
50
+ .then((readiness) => {
51
+ ctx.setReadinessResult(readiness);
52
+ })
53
+ .catch(() => {
54
+ ctx.setReadinessResult({
55
+ decision: readiness_js_1.WizardReadiness.Yes,
56
+ health: {},
57
+ reasons: [],
58
+ });
59
+ });
60
+ },
61
+ },
62
+ {
63
+ id: 'setup',
64
+ label: 'Setup',
65
+ screen: 'setup',
66
+ show: needsSetup,
67
+ isComplete: (session) => !needsSetup(session),
68
+ },
69
+ {
70
+ id: 'auth',
71
+ label: 'Authentication',
72
+ screen: 'auth',
73
+ isComplete: (session) => session.credentials !== null,
74
+ },
75
+ {
76
+ id: 'run',
77
+ label: 'Integration',
78
+ screen: 'run',
79
+ isComplete: (session) => session.runPhase === wizard_session_js_1.RunPhase.Completed ||
80
+ session.runPhase === wizard_session_js_1.RunPhase.Error,
81
+ },
82
+ {
83
+ id: 'mcp',
84
+ label: 'MCP servers',
85
+ screen: 'mcp',
86
+ isComplete: (session) => session.mcpComplete,
87
+ },
88
+ {
89
+ id: 'outro',
90
+ label: 'Done',
91
+ screen: 'outro',
92
+ isComplete: (session) => session.outroDismissed,
93
+ },
94
+ {
95
+ id: 'skills',
96
+ label: 'Skills',
97
+ screen: 'skills',
98
+ },
99
+ ];
100
+ //# sourceMappingURL=steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.js","sourceRoot":"","sources":["../../../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KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,QAAQ;KACjB;CACF,CAAC","sourcesContent":["/**\n * PostHog integration workflow — the default wizard flow.\n *\n * Steps define their own gate predicates and onInit callbacks.\n * The store derives gate promises and fires init work from these\n * definitions — no hardcoded per-flow logic in the store.\n */\n\nimport type { Workflow } from '../workflow-step.js';\nimport type { WizardSession } from '../../wizard-session.js';\nimport { RunPhase } from '../../wizard-session.js';\nimport {\n evaluateWizardReadiness,\n WizardReadiness,\n} from '../../health-checks/readiness.js';\nimport { detectPostHogIntegration } from './detect.js';\n\nfunction needsSetup(session: WizardSession): boolean {\n const config = session.frameworkConfig;\n if (!config?.metadata.setup?.questions) return false;\n\n return config.metadata.setup.questions.some(\n (q: { key: string }) => !(q.key in session.frameworkContext),\n );\n}\n\nfunction healthCheckReady(session: WizardSession): boolean {\n if (!session.readinessResult) return false;\n if (session.readinessResult.decision === WizardReadiness.No)\n return session.outageDismissed;\n return true;\n}\n\nexport const POSTHOG_INTEGRATION_WORKFLOW: Workflow = [\n {\n id: 'detect',\n label: 'Detecting framework',\n // Headless step: no screen. onReady fires after bin.ts assigns the\n // session — runs framework detection, context gathering, version\n // check, and feature discovery. Results are written to the store\n // for the IntroScreen to render.\n onReady: (ctx) => detectPostHogIntegration(ctx),\n },\n {\n id: 'intro',\n label: 'Welcome',\n screen: 'intro',\n gate: (session) => session.setupConfirmed,\n },\n {\n id: 'health-check',\n label: 'Health check',\n screen: 'health-check',\n gate: healthCheckReady,\n onInit: (ctx) => {\n evaluateWizardReadiness()\n .then((readiness) => {\n ctx.setReadinessResult(readiness);\n })\n .catch(() => {\n ctx.setReadinessResult({\n decision: WizardReadiness.Yes,\n health: {} as never,\n reasons: [],\n });\n });\n },\n },\n {\n id: 'setup',\n label: 'Setup',\n screen: 'setup',\n show: needsSetup,\n isComplete: (session) => !needsSetup(session),\n },\n {\n id: 'auth',\n label: 'Authentication',\n screen: 'auth',\n isComplete: (session) => session.credentials !== null,\n },\n {\n id: 'run',\n label: 'Integration',\n screen: 'run',\n isComplete: (session) =>\n session.runPhase === RunPhase.Completed ||\n session.runPhase === RunPhase.Error,\n },\n {\n id: 'mcp',\n label: 'MCP servers',\n screen: 'mcp',\n isComplete: (session) => session.mcpComplete,\n },\n {\n id: 'outro',\n label: 'Done',\n screen: 'outro',\n isComplete: (session) => session.outroDismissed,\n },\n {\n id: 'skills',\n label: 'Skills',\n screen: 'skills',\n },\n];\n"]}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Revenue analytics prerequisite detection.
3
+ *
4
+ * Scans the project for PostHog + Stripe SDKs and writes results
5
+ * into frameworkContext for the intro screen to render.
6
+ */
7
+ import type { WizardSession } from '../../wizard-session.js';
8
+ import type { AbortCase } from '../../agent/agent-runner.js';
9
+ export declare const POSTHOG_SDKS: string[];
10
+ export declare const STRIPE_SDKS: string[];
11
+ /**
12
+ * Structured detection errors. The screen renders each kind into JSX
13
+ * with proper formatting — keeps error data separate from presentation.
14
+ */
15
+ export type RevenueDetectError = {
16
+ kind: 'bad-directory';
17
+ path: string;
18
+ reason: 'missing' | 'not-dir' | 'unreadable';
19
+ } | {
20
+ kind: 'no-package-json';
21
+ } | {
22
+ kind: 'no-sdks';
23
+ scannedCount: number;
24
+ } | {
25
+ kind: 'missing-posthog';
26
+ foundStripe: string[];
27
+ } | {
28
+ kind: 'missing-stripe';
29
+ foundPosthog: string[];
30
+ };
31
+ /** `[ABORT] <reason>` cases the revenue analytics skill can emit. */
32
+ export declare const REVENUE_ABORT_CASES: AbortCase[];
33
+ /**
34
+ * Scan `session.installDir` for PostHog + Stripe SDKs. Writes detection
35
+ * results into frameworkContext via the callback — either the detected
36
+ * SDK lists (for the intro screen) or a `RevenueDetectError` on failure.
37
+ *
38
+ * The skill install happens later in the bootstrap runner, not here.
39
+ */
40
+ export declare function detectRevenuePrerequisites(session: WizardSession, setFrameworkContext: (key: string, value: unknown) => void): void;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ /**
3
+ * Revenue analytics prerequisite detection.
4
+ *
5
+ * Scans the project for PostHog + Stripe SDKs and writes results
6
+ * into frameworkContext for the intro screen to render.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.REVENUE_ABORT_CASES = exports.STRIPE_SDKS = exports.POSTHOG_SDKS = void 0;
10
+ exports.detectRevenuePrerequisites = detectRevenuePrerequisites;
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ const file_utils_js_1 = require("../../../utils/file-utils.js");
14
+ exports.POSTHOG_SDKS = [
15
+ 'posthog-js',
16
+ 'posthog-node',
17
+ 'posthog-react-native',
18
+ 'posthog-android',
19
+ 'posthog-ios',
20
+ ];
21
+ exports.STRIPE_SDKS = [
22
+ 'stripe',
23
+ '@stripe/stripe-js',
24
+ '@stripe/react-stripe-js',
25
+ ];
26
+ /** `[ABORT] <reason>` cases the revenue analytics skill can emit. */
27
+ exports.REVENUE_ABORT_CASES = [
28
+ {
29
+ // Skill emits: [ABORT] Could not find a PostHog distinct_id
30
+ match: /^could not find a posthog distinct_id$/i,
31
+ message: 'Could not find a PostHog distinct_id',
32
+ body: 'The agent could not find PostHog distinct_id usage in your codebase. ' +
33
+ 'Your users must be identified in PostHog before they can be tagged in Stripe. ' +
34
+ 'Please identify your users and try again.',
35
+ docsUrl: 'https://posthog.com/docs/product-analytics/identify',
36
+ },
37
+ {
38
+ // Skill emits: [ABORT] Could not find a Stripe integration
39
+ match: /^could not find a stripe integration$/i,
40
+ message: 'Could not find a Stripe integration',
41
+ body: 'The Wizard could not find an existing Stripe customer, charge, ' +
42
+ 'subscription, or other Stripe operations. Please run the Revenue ' +
43
+ 'Analytics Wizard on a project with an existing Stripe integration.',
44
+ docsUrl: 'https://posthog.com/docs/revenue-analytics',
45
+ },
46
+ ];
47
+ /**
48
+ * Recursively find all package.json files under installDir (max depth 3),
49
+ * skipping common ignored directories. Returns matches with detected SDKs.
50
+ */
51
+ function findPackageJsons(installDir, maxDepth = 3) {
52
+ const matches = [];
53
+ function scan(dir, depth) {
54
+ if (depth > maxDepth)
55
+ return;
56
+ let entries;
57
+ try {
58
+ entries = (0, fs_1.readdirSync)(dir, { withFileTypes: true });
59
+ }
60
+ catch {
61
+ return;
62
+ }
63
+ for (const entry of entries) {
64
+ if (entry.name.startsWith('.') && entry.name !== '.')
65
+ continue;
66
+ if (file_utils_js_1.IGNORED_DIRS.has(entry.name))
67
+ continue;
68
+ const fullPath = (0, path_1.join)(dir, entry.name);
69
+ if (entry.isFile() && entry.name === 'package.json') {
70
+ try {
71
+ const pkg = JSON.parse((0, fs_1.readFileSync)(fullPath, 'utf-8'));
72
+ const depNames = [
73
+ ...Object.keys(pkg.dependencies ?? {}),
74
+ ...Object.keys(pkg.devDependencies ?? {}),
75
+ ];
76
+ const posthogSdks = depNames.filter((d) => exports.POSTHOG_SDKS.includes(d));
77
+ const stripeSdks = depNames.filter((d) => exports.STRIPE_SDKS.includes(d));
78
+ matches.push({
79
+ path: (0, path_1.relative)(installDir, fullPath) || 'package.json',
80
+ posthogSdks,
81
+ stripeSdks,
82
+ });
83
+ }
84
+ catch {
85
+ // Skip malformed package.json
86
+ }
87
+ }
88
+ else if (entry.isDirectory()) {
89
+ scan(fullPath, depth + 1);
90
+ }
91
+ }
92
+ }
93
+ scan(installDir, 0);
94
+ return matches;
95
+ }
96
+ /**
97
+ * Scan `session.installDir` for PostHog + Stripe SDKs. Writes detection
98
+ * results into frameworkContext via the callback — either the detected
99
+ * SDK lists (for the intro screen) or a `RevenueDetectError` on failure.
100
+ *
101
+ * The skill install happens later in the bootstrap runner, not here.
102
+ */
103
+ function detectRevenuePrerequisites(session, setFrameworkContext) {
104
+ const fail = (error) => setFrameworkContext('detectError', error);
105
+ const installDir = session.installDir;
106
+ // Verify the install directory exists and is readable
107
+ if (!(0, fs_1.existsSync)(installDir)) {
108
+ fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });
109
+ return;
110
+ }
111
+ try {
112
+ if (!(0, fs_1.statSync)(installDir).isDirectory()) {
113
+ fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });
114
+ return;
115
+ }
116
+ }
117
+ catch {
118
+ fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });
119
+ return;
120
+ }
121
+ // Find all package.json files (root + monorepo subpackages)
122
+ const matches = findPackageJsons(installDir);
123
+ if (matches.length === 0) {
124
+ fail({ kind: 'no-package-json' });
125
+ return;
126
+ }
127
+ // Aggregate detected SDKs across all package.json files
128
+ const allPosthogSdks = new Set();
129
+ const allStripeSdks = new Set();
130
+ for (const match of matches) {
131
+ for (const sdk of match.posthogSdks)
132
+ allPosthogSdks.add(sdk);
133
+ for (const sdk of match.stripeSdks)
134
+ allStripeSdks.add(sdk);
135
+ }
136
+ const detectedPosthogSdks = [...allPosthogSdks];
137
+ const detectedStripeSdks = [...allStripeSdks];
138
+ if (detectedPosthogSdks.length === 0 && detectedStripeSdks.length === 0) {
139
+ fail({ kind: 'no-sdks', scannedCount: matches.length });
140
+ return;
141
+ }
142
+ if (detectedPosthogSdks.length === 0) {
143
+ fail({ kind: 'missing-posthog', foundStripe: detectedStripeSdks });
144
+ return;
145
+ }
146
+ if (detectedStripeSdks.length === 0) {
147
+ fail({ kind: 'missing-stripe', foundPosthog: detectedPosthogSdks });
148
+ return;
149
+ }
150
+ setFrameworkContext('detectedPosthogSdks', detectedPosthogSdks);
151
+ setFrameworkContext('detectedStripeSdks', detectedStripeSdks);
152
+ setFrameworkContext('detectedPackagePaths', matches
153
+ .filter((m) => m.posthogSdks.length > 0 || m.stripeSdks.length > 0)
154
+ .map((m) => m.path));
155
+ }
156
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../../../../../src/lib/workflows/revenue-analytics/detect.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAiIH,gEAkEC;AAhMD,2BAAqE;AACrE,+BAAsC;AACtC,gEAA4D;AAI/C,QAAA,YAAY,GAAG;IAC1B,YAAY;I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CAAC;IAC7D,CAAC;IAED,MAAM,mBAAmB,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC;IAChD,MAAM,kBAAkB,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC;IAE9C,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxE,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACxD,OAAO;IACT,CAAC;IAED,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC,CAAC;QACnE,OAAO;IACT,CAAC;IAED,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,mBAAmB,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,CAAC;IAChE,mBAAmB,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;IAC9D,mBAAmB,CACjB,sBAAsB,EACtB,OAAO;SACJ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;SAClE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CACtB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Revenue analytics prerequisite detection.\n *\n * Scans the project for PostHog + Stripe SDKs and writes results\n * into frameworkContext for the intro screen to render.\n */\n\nimport type { Dirent } from 'fs';\nimport { readFileSync, readdirSync, existsSync, statSync } from 'fs';\nimport { join, relative } from 'path';\nimport { IGNORED_DIRS } from '../../../utils/file-utils.js';\nimport type { WizardSession } from '../../wizard-session.js';\nimport type { AbortCase } from '../../agent/agent-runner.js';\n\nexport const POSTHOG_SDKS = [\n 'posthog-js',\n 'posthog-node',\n 'posthog-react-native',\n 'posthog-android',\n 'posthog-ios',\n];\n\nexport const STRIPE_SDKS = [\n 'stripe',\n '@stripe/stripe-js',\n '@stripe/react-stripe-js',\n];\n\ninterface PackageMatch {\n /** Path to the package.json relative to installDir */\n path: string;\n posthogSdks: string[];\n stripeSdks: string[];\n}\n\n/**\n * Structured detection errors. The screen renders each kind into JSX\n * with proper formatting — keeps error data separate from presentation.\n */\nexport type RevenueDetectError =\n | {\n kind: 'bad-directory';\n path: string;\n reason: 'missing' | 'not-dir' | 'unreadable';\n }\n | { kind: 'no-package-json' }\n | { kind: 'no-sdks'; scannedCount: number }\n | { kind: 'missing-posthog'; foundStripe: string[] }\n | { kind: 'missing-stripe'; foundPosthog: string[] };\n\n/** `[ABORT] <reason>` cases the revenue analytics skill can emit. */\nexport const REVENUE_ABORT_CASES: AbortCase[] = [\n {\n // Skill emits: [ABORT] Could not find a PostHog distinct_id\n match: /^could not find a posthog distinct_id$/i,\n message: 'Could not find a PostHog distinct_id',\n body:\n 'The agent could not find PostHog distinct_id usage in your codebase. ' +\n 'Your users must be identified in PostHog before they can be tagged in Stripe. ' +\n 'Please identify your users and try again.',\n docsUrl: 'https://posthog.com/docs/product-analytics/identify',\n },\n {\n // Skill emits: [ABORT] Could not find a Stripe integration\n match: /^could not find a stripe integration$/i,\n message: 'Could not find a Stripe integration',\n body:\n 'The Wizard could not find an existing Stripe customer, charge, ' +\n 'subscription, or other Stripe operations. Please run the Revenue ' +\n 'Analytics Wizard on a project with an existing Stripe integration.',\n docsUrl: 'https://posthog.com/docs/revenue-analytics',\n },\n];\n\n/**\n * Recursively find all package.json files under installDir (max depth 3),\n * skipping common ignored directories. Returns matches with detected SDKs.\n */\nfunction findPackageJsons(installDir: string, maxDepth = 3): PackageMatch[] {\n const matches: PackageMatch[] = [];\n\n function scan(dir: string, depth: number): void {\n if (depth > maxDepth) return;\n\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n\n for (const entry of entries) {\n if (entry.name.startsWith('.') && entry.name !== '.') continue;\n if (IGNORED_DIRS.has(entry.name)) continue;\n\n const fullPath = join(dir, entry.name);\n\n if (entry.isFile() && entry.name === 'package.json') {\n try {\n const pkg = JSON.parse(readFileSync(fullPath, 'utf-8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const depNames = [\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ];\n const posthogSdks = depNames.filter((d) => POSTHOG_SDKS.includes(d));\n const stripeSdks = depNames.filter((d) => STRIPE_SDKS.includes(d));\n matches.push({\n path: relative(installDir, fullPath) || 'package.json',\n posthogSdks,\n stripeSdks,\n });\n } catch {\n // Skip malformed package.json\n }\n } else if (entry.isDirectory()) {\n scan(fullPath, depth + 1);\n }\n }\n }\n\n scan(installDir, 0);\n return matches;\n}\n\n/**\n * Scan `session.installDir` for PostHog + Stripe SDKs. Writes detection\n * results into frameworkContext via the callback — either the detected\n * SDK lists (for the intro screen) or a `RevenueDetectError` on failure.\n *\n * The skill install happens later in the bootstrap runner, not here.\n */\nexport function detectRevenuePrerequisites(\n session: WizardSession,\n setFrameworkContext: (key: string, value: unknown) => void,\n): void {\n const fail = (error: RevenueDetectError) =>\n setFrameworkContext('detectError', error);\n\n const installDir = session.installDir;\n\n // Verify the install directory exists and is readable\n if (!existsSync(installDir)) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'missing' });\n return;\n }\n try {\n if (!statSync(installDir).isDirectory()) {\n fail({ kind: 'bad-directory', path: installDir, reason: 'not-dir' });\n return;\n }\n } catch {\n fail({ kind: 'bad-directory', path: installDir, reason: 'unreadable' });\n return;\n }\n\n // Find all package.json files (root + monorepo subpackages)\n const matches = findPackageJsons(installDir);\n\n if (matches.length === 0) {\n fail({ kind: 'no-package-json' });\n return;\n }\n\n // Aggregate detected SDKs across all package.json files\n const allPosthogSdks = new Set<string>();\n const allStripeSdks = new Set<string>();\n for (const match of matches) {\n for (const sdk of match.posthogSdks) allPosthogSdks.add(sdk);\n for (const sdk of match.stripeSdks) allStripeSdks.add(sdk);\n }\n\n const detectedPosthogSdks = [...allPosthogSdks];\n const detectedStripeSdks = [...allStripeSdks];\n\n if (detectedPosthogSdks.length === 0 && detectedStripeSdks.length === 0) {\n fail({ kind: 'no-sdks', scannedCount: matches.length });\n return;\n }\n\n if (detectedPosthogSdks.length === 0) {\n fail({ kind: 'missing-posthog', foundStripe: detectedStripeSdks });\n return;\n }\n\n if (detectedStripeSdks.length === 0) {\n fail({ kind: 'missing-stripe', foundPosthog: detectedPosthogSdks });\n return;\n }\n\n setFrameworkContext('detectedPosthogSdks', detectedPosthogSdks);\n setFrameworkContext('detectedStripeSdks', detectedStripeSdks);\n setFrameworkContext(\n 'detectedPackagePaths',\n matches\n .filter((m) => m.posthogSdks.length > 0 || m.stripeSdks.length > 0)\n .map((m) => m.path),\n );\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { WorkflowConfig } from '../workflow-step.js';
2
+ export declare const revenueAnalyticsConfig: WorkflowConfig;
3
+ export { REVENUE_ANALYTICS_WORKFLOW } from './steps.js';
4
+ export { detectRevenuePrerequisites, POSTHOG_SDKS, STRIPE_SDKS, type RevenueDetectError, } from './detect.js';
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STRIPE_SDKS = exports.POSTHOG_SDKS = exports.detectRevenuePrerequisites = exports.REVENUE_ANALYTICS_WORKFLOW = exports.revenueAnalyticsConfig = void 0;
4
+ const steps_js_1 = require("./steps.js");
5
+ const detect_js_1 = require("./detect.js");
6
+ exports.revenueAnalyticsConfig = {
7
+ command: 'revenue',
8
+ description: 'Set up PostHog revenue analytics (e.g. Stripe integration)',
9
+ flowKey: 'revenue-analytics-setup',
10
+ steps: steps_js_1.REVENUE_ANALYTICS_WORKFLOW,
11
+ run: {
12
+ skillId: 'revenue-analytics-setup',
13
+ integrationLabel: 'revenue-analytics-setup',
14
+ customPrompt: () => 'Set up revenue analytics for this project.',
15
+ successMessage: 'Revenue analytics configured!',
16
+ reportFile: 'posthog-revenue-report.md',
17
+ docsUrl: 'https://posthog.com/docs/revenue-analytics',
18
+ spinnerMessage: 'Setting up revenue analytics...',
19
+ estimatedDurationMinutes: 5,
20
+ abortCases: detect_js_1.REVENUE_ABORT_CASES,
21
+ },
22
+ requires: ['posthog-integration'],
23
+ };
24
+ var steps_js_2 = require("./steps.js");
25
+ Object.defineProperty(exports, "REVENUE_ANALYTICS_WORKFLOW", { enumerable: true, get: function () { return steps_js_2.REVENUE_ANALYTICS_WORKFLOW; } });
26
+ var detect_js_2 = require("./detect.js");
27
+ Object.defineProperty(exports, "detectRevenuePrerequisites", { enumerable: true, get: function () { return detect_js_2.detectRevenuePrerequisites; } });
28
+ Object.defineProperty(exports, "POSTHOG_SDKS", { enumerable: true, get: function () { return detect_js_2.POSTHOG_SDKS; } });
29
+ Object.defineProperty(exports, "STRIPE_SDKS", { enumerable: true, get: function () { return detect_js_2.STRIPE_SDKS; } });
30
+ //# sourceMappingURL=index.js.map