@posthog/agent 2.3.22 → 2.3.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.3.22",
3
+ "version": "2.3.24",
4
4
  "repository": "https://github.com/PostHog/code",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -74,8 +74,8 @@
74
74
  "tsx": "^4.20.6",
75
75
  "typescript": "^5.5.0",
76
76
  "vitest": "^2.1.8",
77
- "@posthog/shared": "1.0.0",
78
- "@posthog/git": "1.0.0"
77
+ "@posthog/git": "1.0.0",
78
+ "@posthog/shared": "1.0.0"
79
79
  },
80
80
  "dependencies": {
81
81
  "@agentclientprotocol/sdk": "0.15.0",
@@ -639,7 +639,14 @@ export class AgentServer {
639
639
  _meta: {
640
640
  sessionId: payload.run_id,
641
641
  taskRunId: payload.run_id,
642
- systemPrompt: { append: this.buildCloudSystemPrompt(prUrl) },
642
+ systemPrompt: this.buildSessionSystemPrompt(prUrl),
643
+ ...(this.config.claudeCode?.plugins?.length && {
644
+ claudeCode: {
645
+ options: {
646
+ plugins: this.config.claudeCode.plugins,
647
+ },
648
+ },
649
+ }),
643
650
  },
644
651
  });
645
652
 
@@ -944,6 +951,28 @@ export class AgentServer {
944
951
  : null;
945
952
  }
946
953
 
954
+ private buildSessionSystemPrompt(
955
+ prUrl?: string | null,
956
+ ): string | { append: string } {
957
+ const cloudAppend = this.buildCloudSystemPrompt(prUrl);
958
+ const userPrompt = this.config.claudeCode?.systemPrompt;
959
+
960
+ // String override: combine user prompt with cloud instructions
961
+ if (typeof userPrompt === "string") {
962
+ return [userPrompt, cloudAppend].join("\n\n");
963
+ }
964
+
965
+ // Preset with append: merge user append with cloud instructions
966
+ if (typeof userPrompt === "object") {
967
+ return {
968
+ append: [userPrompt.append, cloudAppend].filter(Boolean).join("\n\n"),
969
+ };
970
+ }
971
+
972
+ // Default: just cloud instructions
973
+ return { append: cloudAppend };
974
+ }
975
+
947
976
  private buildCloudSystemPrompt(prUrl?: string | null): string {
948
977
  if (prUrl) {
949
978
  return `
package/src/server/bin.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Command } from "commander";
3
3
  import { z } from "zod";
4
4
  import { AgentServer } from "./agent-server";
5
- import { mcpServersSchema } from "./schemas";
5
+ import { claudeCodeConfigSchema, mcpServersSchema } from "./schemas";
6
6
 
7
7
  const envSchema = z.object({
8
8
  JWT_PUBLIC_KEY: z
@@ -34,6 +34,30 @@ const envSchema = z.object({
34
34
 
35
35
  const program = new Command();
36
36
 
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
+
37
61
  program
38
62
  .name("agent-server")
39
63
  .description("PostHog cloud agent server - runs in sandbox environments")
@@ -51,6 +75,10 @@ program
51
75
  "MCP servers config as JSON array (ACP McpServer[] format)",
52
76
  )
53
77
  .option("--baseBranch <branch>", "Base branch for PR creation")
78
+ .option(
79
+ "--claudeCodeConfig <json>",
80
+ "Claude Code config as JSON (systemPrompt, systemPromptAppend, plugins)",
81
+ )
54
82
  .action(async (options) => {
55
83
  const envResult = envSchema.safeParse(process.env);
56
84
 
@@ -66,28 +94,16 @@ program
66
94
 
67
95
  const mode = options.mode === "background" ? "background" : "interactive";
68
96
 
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
+ );
91
107
 
92
108
  const server = new AgentServer({
93
109
  port: parseInt(options.port, 10),
@@ -101,6 +117,7 @@ program
101
117
  runId: options.runId,
102
118
  mcpServers,
103
119
  baseBranch: options.baseBranch,
120
+ claudeCode,
104
121
  });
105
122
 
106
123
  process.on("SIGINT", async () => {
@@ -16,6 +16,22 @@ export const mcpServersSchema = z.array(remoteMcpServerSchema);
16
16
 
17
17
  export type RemoteMcpServer = z.infer<typeof remoteMcpServerSchema>;
18
18
 
19
+ export const claudeCodeConfigSchema = z.object({
20
+ systemPrompt: z
21
+ .union([
22
+ z.string(),
23
+ z.object({
24
+ type: z.literal("preset"),
25
+ preset: z.literal("claude_code"),
26
+ append: z.string().optional(),
27
+ }),
28
+ ])
29
+ .optional(),
30
+ plugins: z
31
+ .array(z.object({ type: z.literal("local"), path: z.string() }))
32
+ .optional(),
33
+ });
34
+
19
35
  export const jsonRpcRequestSchema = z.object({
20
36
  jsonrpc: z.literal("2.0"),
21
37
  method: z.string(),
@@ -1,6 +1,13 @@
1
1
  import type { AgentMode } from "../types";
2
2
  import type { RemoteMcpServer } from "./schemas";
3
3
 
4
+ export interface ClaudeCodeConfig {
5
+ systemPrompt?:
6
+ | string
7
+ | { type: "preset"; preset: "claude_code"; append?: string };
8
+ plugins?: { type: "local"; path: string }[];
9
+ }
10
+
4
11
  export interface AgentServerConfig {
5
12
  port: number;
6
13
  repositoryPath?: string;
@@ -14,4 +21,5 @@ export interface AgentServerConfig {
14
21
  version?: string;
15
22
  mcpServers?: RemoteMcpServer[];
16
23
  baseBranch?: string;
24
+ claudeCode?: ClaudeCodeConfig;
17
25
  }