22import { Command } from "commander" ;
33import { z } from "zod" ;
44import { AgentServer } from "./agent-server" ;
5- import { mcpServersSchema } from "./schemas" ;
5+ import { claudeCodeConfigSchema , mcpServersSchema } from "./schemas" ;
66
77const envSchema = z . object ( {
88 JWT_PUBLIC_KEY : z
@@ -34,6 +34,30 @@ const envSchema = z.object({
3434
3535const program = new Command ( ) ;
3636
37+ function parseJsonOption < S extends z . ZodTypeAny > (
38+ raw: string | undefined,
39+ schema: S,
40+ flag: string,
41+ ): z.output< S > | undefined {
42+ if ( ! raw ) return undefined ;
43+
44+ let parsed : unknown ;
45+ try {
46+ parsed = JSON . parse ( raw ) ;
47+ } catch {
48+ program. error ( `${ flag } must be valid JSON` ) ;
49+ }
50+
51+ const result = schema.safeParse(parsed);
52+ if (!result.success) {
53+ const errors = result . error . issues
54+ . map ( ( issue ) => ` - ${ issue . path . join ( "." ) } : ${ issue . message } ` )
55+ . join ( "\n" ) ;
56+ program . error ( `${ flag } validation failed:\n${ errors } ` ) ;
57+ }
58+ return result.data;
59+ }
60+
3761program
3862 . name ( "agent-server" )
3963 . description ( "PostHog cloud agent server - runs in sandbox environments" )
@@ -51,6 +75,10 @@ program
5175 "MCP servers config as JSON array (ACP McpServer[] format)" ,
5276 )
5377 . option ( "--baseBranch <branch>" , "Base branch for PR creation" )
78+ . option (
79+ "--claudeCodeConfig <json>" ,
80+ "Claude Code config as JSON (systemPrompt, systemPromptAppend, plugins)" ,
81+ )
5482 . action ( async ( options ) => {
5583 const envResult = envSchema . safeParse ( process . env ) ;
5684
@@ -66,28 +94,16 @@ program
6694
6795 const mode = options . mode === "background" ? "background" : "interactive" ;
6896
69- let mcpServers : z . infer < typeof mcpServersSchema > | undefined ;
70- if ( options . mcpServers ) {
71- let parsed : unknown ;
72- try {
73- parsed = JSON . parse ( options . mcpServers ) ;
74- } catch {
75- program . error ( "--mcpServers must be valid JSON" ) ;
76- return ;
77- }
78-
79- const result = mcpServersSchema . safeParse ( parsed ) ;
80- if ( ! result . success ) {
81- const errors = result . error . issues
82- . map ( ( issue ) => ` - ${ issue . path . join ( "." ) } : ${ issue . message } ` )
83- . join ( "\n" ) ;
84- program . error (
85- `--mcpServers validation failed (only remote http/sse servers are supported):\n${ errors } ` ,
86- ) ;
87- return ;
88- }
89- mcpServers = result . data ;
90- }
97+ const mcpServers = parseJsonOption (
98+ options . mcpServers ,
99+ mcpServersSchema ,
100+ "--mcpServers" ,
101+ ) ;
102+ const claudeCode = parseJsonOption (
103+ options . claudeCodeConfig ,
104+ claudeCodeConfigSchema ,
105+ "--claudeCodeConfig" ,
106+ ) ;
91107
92108 const server = new AgentServer ( {
93109 port : parseInt ( options . port , 10 ) ,
@@ -101,6 +117,7 @@ program
101117 runId : options . runId ,
102118 mcpServers,
103119 baseBranch : options . baseBranch ,
120+ claudeCode,
104121 } ) ;
105122
106123 process . on ( "SIGINT" , async ( ) => {
0 commit comments