@posthog/wizard 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ To use the wizard, you can run it directly using:
17
17
  npx @posthog/wizard
18
18
  ```
19
19
 
20
- Currently the wizard can be used for React, NextJS, Svelte and React Native
20
+ Currently the wizard can be used for **React, NextJS, Svelte and React Native**
21
21
  projects. If you have other integrations you would like the wizard to support,
22
22
  please open a [GitHub issue](https://github.com/posthog/wizard/issues)!
23
23
 
@@ -40,3 +40,54 @@ The following CLI arguments are available:
40
40
  > Note: A large amount of the scaffolding for this came from the amazing Sentry
41
41
  > wizard, which you can find [here](https://github.com/getsentry/sentry-wizard)
42
42
  > 💖
43
+
44
+ # Steal this code
45
+
46
+ While the wizard works great on its own, we also find the approach used by this project is [a powerful way to improve AI agent coding sessions](https://posthog.com/blog/envoy-wizard-llm-agent). Agents can run CLI tools, which means that conventional code like this can participate in the AI revolution as well – with all the benefits and control that conventional code implies.
47
+
48
+ If you want to use this code as a starting place for your own project, here's a quick explainer on its structure.
49
+
50
+ ## Entrypoint: `run.ts`
51
+
52
+ The entrypoint for this tool is `run.ts`. Use this file to interpret arguments and set up the general flow of the application.
53
+
54
+ ## Analytics
55
+
56
+ Did you know you can capture PostHog events even for smaller, supporting products like a command line tool? `src/utils/analytics.ts` is a great example of how to do it.
57
+
58
+ This file wraps `posthog-node` with some convenience functions to set up an analytics session and log events. We can see the usage and outcomes of this wizard alongside all of our other PostHog product data, and this is very powerful. For example: we could show in-product surveys to people who have used the wizard to improve the experience.
59
+
60
+ ## Leave rules behind
61
+
62
+ Supporting agent sessions after we leave is important. There are plenty of ways to break or misconfigure PostHog, so guarding against this is key.
63
+
64
+ `src/utils/rules/add-editor-rules.ts` demonstrates how to dynamically construct rules files and store them in the project's `.cursor/rules` directory.
65
+
66
+ ## Prompts and LLM interactions
67
+
68
+ LLM agent sessions are *anti-deterministic*: really, anything can happen.
69
+
70
+ But using LLMs for code generation is really advantageous: they can interpret existing code at scale and then modify it reliably.
71
+
72
+ *If* they are well prompted.
73
+
74
+ `src/lib/prompts.ts` demonstrates how to wrap a deterministic fence around a chaotic process. Every wizard session gets the same prompt, tailored to the specific files in the project.
75
+
76
+ These prompts are channeled using `src/utils/query.ts` to an LLM interface we host. This gives us more control: we can be certain of the model version and provider which interpret the prompts and modify the files. This way, we can find the right tools for the job and again, apply them consistently.
77
+
78
+ This also allows us to pick up the bill on behalf of our customers.
79
+
80
+ When we make improvements to this process, these are available instantly to all users of the wizard, no training delays or other ambiguity.
81
+
82
+ ## Publishing your tool
83
+
84
+ To make your version of a tool usable with a one-line `npx` command:
85
+
86
+ 1. Edit `package.json`, especially details like `name`, `version`
87
+ 2. Run [`npm publish`](https://docs.npmjs.com/cli/v7/commands/npm-publish) from your project directory
88
+ 3. Now you can run it with `npx yourpackagename`
89
+
90
+
91
+
92
+
93
+
@@ -105,7 +105,7 @@ class VercelEnvironmentProvider extends EnvironmentProvider_1.EnvironmentProvide
105
105
  proc.stderr.on('data', (data) => {
106
106
  stderr += data.toString();
107
107
  });
108
- proc.stdin.write(value + '\n');
108
+ proc.stdin.write(value);
109
109
  proc.stdin.end();
110
110
  proc.on('close', (code) => {
111
111
  if (stderr.includes('already exists') ||
@@ -1 +1 @@
1
- {"version":3,"file":"vercel.js","sourceRoot":"","sources":["../../../../../src/steps/upload-environment-variables/providers/vercel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA2D;AAC3D,gEAA6D;AAC7D,uCAAyB;AACzB,2CAA6B;AAE7B,iEAAyC;AACzC,kDAA0B;AAC1B,wDAAqD;AAErD,MAAa,yBAA0B,SAAQ,yCAAmB;IAChE,IAAI,GAAG,QAAQ,CAAC;IAChB,YAAY,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IAExD,YAAY,OAAsB;QAChC,KAA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AAE;gBACT,OAAO,CAAC,IAAI,CAAC,cAAc,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC9D,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACtB,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,OAAO,CAAC,IAAI,CACV,GAAG,YAAY,KAAK;oBAClB,CAAC,CAAC,GAAG,CAAC,OAAO;oBACb,CAAC,CAAC,+CAA+C,IAAI,CAAC,IAAI,8BAA8B,CAC3F,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAnJD,8DAmJC","sourcesContent":["import { execSync, spawn, spawnSync } from 'child_process';\nimport { EnvironmentProvider } from '../EnvironmentProvider';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport type { WizardOptions } from '../../../utils/types';\nimport clack from '../../../utils/clack';\nimport chalk from 'chalk';\nimport { analytics } from '../../../utils/analytics';\n\nexport class VercelEnvironmentProvider extends EnvironmentProvider {\n name = 'Vercel';\n environments = ['production', 'preview', 'development'];\n\n constructor(options: WizardOptions) {\n super(options);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async detect(): Promise<boolean> {\n const vercelDetected =\n this.hasVercelCli() && this.isProjectLinked() && this.isAuthenticated();\n\n analytics.setTag('vercel-detected', vercelDetected);\n\n return vercelDetected;\n }\n\n hasDotVercelDir(): boolean {\n const dotVercelDir = path.join(this.options.installDir, '.vercel');\n return fs.existsSync(dotVercelDir);\n }\n\n hasVercelCli(): boolean {\n try {\n execSync('vercel --version', { stdio: 'ignore' });\n analytics.setTag('vercel-cli-installed', true);\n return true;\n } catch {\n analytics.setTag('vercel-cli-installed', false);\n return false;\n }\n }\n\n isProjectLinked(): boolean {\n const isProjectLinked = fs.existsSync(\n path.join(this.options.installDir, '.vercel', 'project.json'),\n );\n\n analytics.setTag('vercel-project-linked', isProjectLinked);\n\n return isProjectLinked;\n }\n\n isAuthenticated(): boolean {\n const result = spawnSync('vercel', ['whoami'], {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'], // suppress prompts\n env: {\n ...process.env,\n FORCE_COLOR: '0', // avoid ANSI formatting\n CI: '1', // hint to CLI that it's a non-interactive env\n },\n });\n\n const output = (result.stdout + result.stderr).toLowerCase();\n\n if (\n output.includes('log in to vercel') ||\n output.includes('vercel login') ||\n result.status !== 0\n ) {\n analytics.setTag('vercel-authenticated', false);\n return false;\n }\n\n analytics.setTag('vercel-authenticated', true);\n\n return true;\n }\n\n async uploadEnvironmentVariable(\n key: string,\n value: string,\n environment: string,\n ): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const proc = spawn('vercel', ['env', 'add', key, environment], {\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n let stderr = '';\n proc.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n proc.stdin.write(value + '\\n');\n proc.stdin.end();\n\n proc.on('close', (code) => {\n if (\n stderr.includes('already exists') ||\n stderr.includes('already been added') ||\n stderr.includes('vercel env rm')\n ) {\n reject(\n new Error(\n `❌ Environment variable ${chalk.cyan(key)} already exists in ${\n this.name\n }. Please upload it manually.`,\n ),\n );\n } else if (code === 0) {\n resolve();\n } else {\n reject(\n new Error(\n `❌ Failed to upload environment variable ${chalk.cyan(key)} to ${\n this.name\n }. Please upload it manually.`,\n ),\n );\n }\n });\n });\n }\n\n async uploadEnvVars(\n vars: Record<string, string>,\n ): Promise<Record<string, boolean>> {\n const results: Record<string, boolean> = {};\n\n for (const [key, value] of Object.entries(vars)) {\n const spinner = clack.spinner();\n\n spinner.start(`Uploading ${chalk.cyan(key)} to ${this.name}...`);\n await Promise.all(\n this.environments.map((environment) =>\n this.uploadEnvironmentVariable(key, value, environment),\n ),\n )\n .then(() => {\n spinner.stop(`✅ Uploaded ${chalk.cyan(key)} to ${this.name}`);\n results[key] = true;\n })\n .catch((err) => {\n spinner.stop(\n err instanceof Error\n ? err.message\n : `❌ Failed to upload environment variables to ${this.name}. Please upload it manually.`,\n );\n results[key] = false;\n });\n }\n\n return results;\n }\n}\n"]}
1
+ {"version":3,"file":"vercel.js","sourceRoot":"","sources":["../../../../../src/steps/upload-environment-variables/providers/vercel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA2D;AAC3D,gEAA6D;AAC7D,uCAAyB;AACzB,2CAA6B;AAE7B,iEAAyC;AACzC,kDAA0B;AAC1B,wDAAqD;AAErD,MAAa,yBAA0B,SAAQ,yCAAmB;IAChE,IAAI,GAAG,QAAQ,CAAC;IAChB,YAAY,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IAExD,YAAY,OAAsB;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,MAAM;QACV,MAAM,cAAc,GAClB,IAAI,CAAC,YAAY,EAAE,IAAI,IAAI,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QAE1E,qBAAS,CAAC,MAAM,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAEpD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,eAAe;QACb,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACnE,OAAO,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC;IAED,YAAY;QACV,IAAI,CAAC;YACH,IAAA,wBAAQ,EAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YAClD,qBAAS,CAAC,MAAM,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;YAC/C,OA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CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,IAA4B;QAE5B,MAAM,OAAO,GAA4B,EAAE,CAAC;QAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,MAAM,OAAO,GAAG,eAAK,CAAC,OAAO,EAAE,CAAC;YAEhC,OAAO,CAAC,KAAK,CAAC,aAAa,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;YACjE,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CACpC,IAAI,CAAC,yBAAyB,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,CACxD,CACF;iBACE,IAAI,CAAC,GAAG,EAAE;gBACT,OAAO,CAAC,IAAI,CAAC,cAAc,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC9D,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACtB,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,OAAO,CAAC,IAAI,CACV,GAAG,YAAY,KAAK;oBAClB,CAAC,CAAC,GAAG,CAAC,OAAO;oBACb,CAAC,CAAC,+CAA+C,IAAI,CAAC,IAAI,8BAA8B,CAC3F,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAnJD,8DAmJC","sourcesContent":["import { execSync, spawn, spawnSync } from 'child_process';\nimport { EnvironmentProvider } from '../EnvironmentProvider';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport type { WizardOptions } from '../../../utils/types';\nimport clack from '../../../utils/clack';\nimport chalk from 'chalk';\nimport { analytics } from '../../../utils/analytics';\n\nexport class VercelEnvironmentProvider extends EnvironmentProvider {\n name = 'Vercel';\n environments = ['production', 'preview', 'development'];\n\n constructor(options: WizardOptions) {\n super(options);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async detect(): Promise<boolean> {\n const vercelDetected =\n this.hasVercelCli() && this.isProjectLinked() && this.isAuthenticated();\n\n analytics.setTag('vercel-detected', vercelDetected);\n\n return vercelDetected;\n }\n\n hasDotVercelDir(): boolean {\n const dotVercelDir = path.join(this.options.installDir, '.vercel');\n return fs.existsSync(dotVercelDir);\n }\n\n hasVercelCli(): boolean {\n try {\n execSync('vercel --version', { stdio: 'ignore' });\n analytics.setTag('vercel-cli-installed', true);\n return true;\n } catch {\n analytics.setTag('vercel-cli-installed', false);\n return false;\n }\n }\n\n isProjectLinked(): boolean {\n const isProjectLinked = fs.existsSync(\n path.join(this.options.installDir, '.vercel', 'project.json'),\n );\n\n analytics.setTag('vercel-project-linked', isProjectLinked);\n\n return isProjectLinked;\n }\n\n isAuthenticated(): boolean {\n const result = spawnSync('vercel', ['whoami'], {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'], // suppress prompts\n env: {\n ...process.env,\n FORCE_COLOR: '0', // avoid ANSI formatting\n CI: '1', // hint to CLI that it's a non-interactive env\n },\n });\n\n const output = (result.stdout + result.stderr).toLowerCase();\n\n if (\n output.includes('log in to vercel') ||\n output.includes('vercel login') ||\n result.status !== 0\n ) {\n analytics.setTag('vercel-authenticated', false);\n return false;\n }\n\n analytics.setTag('vercel-authenticated', true);\n\n return true;\n }\n\n async uploadEnvironmentVariable(\n key: string,\n value: string,\n environment: string,\n ): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const proc = spawn('vercel', ['env', 'add', key, environment], {\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n let stderr = '';\n proc.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n proc.stdin.write(value);\n proc.stdin.end();\n\n proc.on('close', (code) => {\n if (\n stderr.includes('already exists') ||\n stderr.includes('already been added') ||\n stderr.includes('vercel env rm')\n ) {\n reject(\n new Error(\n `❌ Environment variable ${chalk.cyan(key)} already exists in ${\n this.name\n }. Please upload it manually.`,\n ),\n );\n } else if (code === 0) {\n resolve();\n } else {\n reject(\n new Error(\n `❌ Failed to upload environment variable ${chalk.cyan(key)} to ${\n this.name\n }. Please upload it manually.`,\n ),\n );\n }\n });\n });\n }\n\n async uploadEnvVars(\n vars: Record<string, string>,\n ): Promise<Record<string, boolean>> {\n const results: Record<string, boolean> = {};\n\n for (const [key, value] of Object.entries(vars)) {\n const spinner = clack.spinner();\n\n spinner.start(`Uploading ${chalk.cyan(key)} to ${this.name}...`);\n await Promise.all(\n this.environments.map((environment) =>\n this.uploadEnvironmentVariable(key, value, environment),\n ),\n )\n .then(() => {\n spinner.stop(`✅ Uploaded ${chalk.cyan(key)} to ${this.name}`);\n results[key] = true;\n })\n .catch((err) => {\n spinner.stop(\n err instanceof Error\n ? err.message\n : `❌ Failed to upload environment variables to ${this.name}. Please upload it manually.`,\n );\n results[key] = false;\n });\n }\n\n return results;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/wizard",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "homepage": "https://github.com/posthog/wizard",
5
5
  "repository": "https://github.com/posthog/wizard",
6
6
  "description": "The PostHog wizard helps you to configure your project",