1.3.0 • Published 5 months ago

@posthog/wizard v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

⚠️ Experimental: This wizard is still in an experimental phase. If you have any feedback, please drop an email to joshua at posthog dot com.

Usage

To use the wizard, you can run it directly using:

npx @posthog/wizard

Currently the wizard can be used for React, NextJS, Svelte and React Native projects. If you have other integrations you would like the wizard to support, please open a GitHub issue!

Options

The following CLI arguments are available:

OptionDescriptionTypeDefaultChoicesEnvironment Variable
--helpShow helpboolean
--versionShow version numberboolean
--debugEnable verbose loggingbooleanfalsePOSTHOG_WIZARD_DEBUG
--integrationChoose the integration to setupchoicesSelect integration during setup"nextjs", "react", "svelte", "react-native"POSTHOG_WIZARD_INTEGRATION
--force-installForce install the SDK NPM package (use with caution!)booleanfalse
--install-dirRelative path to install instring.POSTHOG_WIZARD_INSTALL_DIR
--regionPostHog region to usechoices"us", "eu"POSTHOG_WIZARD_REGION
--defaultSelect the default option for all questions automatically (where possible)booleanfalsePOSTHOG_WIZARD_DEFAULT
--signupCreate a new PostHog account during setupbooleanfalsePOSTHOG_WIZARD_SIGNUP

Note: A large amount of the scaffolding for this came from the amazing Sentry wizard, which you can find here 💖

Steal this code

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. 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.

If you want to use this code as a starting place for your own project, here's a quick explainer on its structure.

Entrypoint: run.ts

The entrypoint for this tool is run.ts. Use this file to interpret arguments and set up the general flow of the application.

Analytics

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.

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.

Leave rules behind

Supporting agent sessions after we leave is important. There are plenty of ways to break or misconfigure PostHog, so guarding against this is key.

src/utils/rules/add-editor-rules.ts demonstrates how to dynamically construct rules files and store them in the project's .cursor/rules directory.

Prompts and LLM interactions

LLM agent sessions are anti-deterministic: really, anything can happen.

But using LLMs for code generation is really advantageous: they can interpret existing code at scale and then modify it reliably.

If they are well prompted.

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.

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.

This also allows us to pick up the bill on behalf of our customers.

When we make improvements to this process, these are available instantly to all users of the wizard, no training delays or other ambiguity.

Testing locally

Run:

pnpm try --install-dir=[a path]

To build and use the tool locally:

pnpm build

This compiles the TypeScript code and prepares the dist directory. Run this command any time you make changes to the wizard's source code.

pnpm link --global

This command makes your local version of the wizard available system-wide. You generally only need to do this once.

Then:

wizard [options]

The wizard will execute your last build.

Publishing your tool

To make your version of a tool usable with a one-line npx command:

  1. Edit package.json, especially details like name, version
  2. Run npm publish from your project directory
  3. Now you can run it with npx yourpackagename
1.3.0

5 months ago

1.2.2

5 months ago

1.2.1

5 months ago

1.2.0

5 months ago

1.1.0

6 months ago

1.0.0

6 months ago

0.8.2

6 months ago

0.8.1

6 months ago

0.8.0

6 months ago

0.7.1

6 months ago

0.7.0

6 months ago

0.6.0

6 months ago

0.5.0

7 months ago

0.4.1

7 months ago

0.4.0

7 months ago

0.3.0

7 months ago

0.2.11

7 months ago

0.2.10

8 months ago

0.2.9

8 months ago

0.2.8

8 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago