Skip to content

Commit a1a0bd8

Browse files
committed
Auto-build wizard so local wizard command always has the freshest code
1 parent 562e20b commit a1a0bd8

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,27 @@ users of the wizard, no training delays or other ambiguity.
116116

117117
## Running locally
118118

119-
Run:
119+
### Quick test without linking
120120

121121
```bash
122122
pnpm try --install-dir=[a path]
123123
```
124124

125-
To build and use the tool locally:
125+
### Development with auto-rebuild
126126

127127
```bash
128-
bin/build
128+
pnpm run dev
129129
```
130130

131-
This compiles the TypeScript code and prepares the `dist` directory. Run this
132-
command any time you make changes to the wizard's source code.
131+
This builds, links globally, and watches for changes. Leave it running - any `.ts` file changes will auto-rebuild. Then from any project:
133132

134133
```bash
135-
pnpm link --global
136-
```
137-
138-
This command makes your local version of the wizard available system-wide. You
139-
generally only need to do this once.
140-
141-
Then:
134+
wizard --integration=nextjs
142135

143-
```bash
144-
wizard [options]
136+
# Or use local MCP server:
137+
wizard --integration=nextjs --local-mcp
145138
```
146139

147-
The wizard will execute your last build.
148-
149140
## Testing
150141

151142
To run unit tests, run:

bin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ yargs(hideBin(process.argv))
7878
'Create a new PostHog account during setup\nenv: POSTHOG_WIZARD_SIGNUP',
7979
type: 'boolean',
8080
},
81+
'local-mcp': {
82+
default: false,
83+
describe:
84+
'Use local MCP server at http://localhost:8787/mcp\nenv: POSTHOG_WIZARD_LOCAL_MCP',
85+
type: 'boolean',
86+
},
8187
})
8288
.command(
8389
['$0'],
@@ -143,6 +149,7 @@ yargs(hideBin(process.argv))
143149
default: finalArgs.default ?? false,
144150
signup: finalArgs.signup ?? false,
145151
forceInstall: false,
152+
localMcp: finalArgs.localMcp ?? false,
146153
};
147154

148155
void runEventSetupWizard(wizardOptions);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"test:e2e": "pnpm build && ./e2e-tests/run.sh",
108108
"test:e2e-record": "export RECORD_FIXTURES=true && pnpm build && ./e2e-tests/run.sh",
109109
"try": "tsx bin.ts",
110+
"dev": "pnpm build && pnpm link --global && pnpm build:watch",
110111
"test:watch": "jest --watch",
111112
"prepare": "husky"
112113
},

src/lib/agent-runner.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ export async function runAgentWizard(
104104

105105
// Initialize and run agent
106106
const spinner = clack.spinner();
107+
108+
// Determine MCP URL: CLI flag > env var > production default
109+
const mcpUrl = options.localMcp
110+
? 'http://localhost:8787/mcp'
111+
: process.env.MCP_URL || 'https://mcp.posthog.com/mcp';
112+
107113
const agent = await initializeAgent(
108114
{
109115
workingDirectory: options.installDir,
110-
posthogMcpUrl: 'https://mcp.posthog.com/mcp',
116+
posthogMcpUrl: mcpUrl,
111117
posthogApiKey: accessToken,
112118
debug: false,
113119
},

src/run.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Args = {
3535
region?: CloudRegion;
3636
default?: boolean;
3737
signup?: boolean;
38+
localMcp?: boolean;
3839
};
3940

4041
export async function runWizard(argv: Args) {
@@ -61,6 +62,7 @@ export async function runWizard(argv: Args) {
6162
cloudRegion: finalArgs.region ?? undefined,
6263
default: finalArgs.default ?? false,
6364
signup: finalArgs.signup ?? false,
65+
localMcp: finalArgs.localMcp ?? false,
6466
};
6567

6668
clack.intro(`Welcome to the PostHog setup wizard ✨`);

src/utils/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export type WizardOptions = {
4040
* Whether to create a new PostHog account during setup.
4141
*/
4242
signup: boolean;
43+
44+
/**
45+
* Whether to use the local MCP server at http://localhost:8787/mcp
46+
*/
47+
localMcp: boolean;
4348
};
4449

4550
export interface Feature {

0 commit comments

Comments
 (0)