@posthog/agent 2.3.159 → 2.3.167
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/dist/adapters/claude/questions/utils.d.ts +6 -82
- package/dist/agent.js +36 -3
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +2 -2
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.d.ts +7 -26
- package/dist/server/agent-server.js +38 -5
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +44 -11
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +2 -2
- package/src/adapters/claude/hooks.ts +50 -0
- package/src/adapters/claude/session/options.ts +5 -1
- package/src/server/bin.ts +7 -11
- package/src/server/schemas.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.167",
|
|
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": {
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"tar": "^7.5.0",
|
|
104
104
|
"uuid": "13.0.0",
|
|
105
105
|
"yoga-wasm-web": "^0.3.3",
|
|
106
|
-
"zod": "^
|
|
106
|
+
"zod": "^4.2.0"
|
|
107
107
|
},
|
|
108
108
|
"files": [
|
|
109
109
|
"dist/**/*",
|
|
@@ -71,6 +71,56 @@ export const createPostToolUseHook =
|
|
|
71
71
|
return { continue: true };
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Rewrites Agent tool calls targeting built-in subagent types to use our custom
|
|
76
|
+
* definitions instead. This works around a Claude Agent SDK bug where
|
|
77
|
+
* `options.agents` cannot override built-in agent definitions because the
|
|
78
|
+
* built-ins appear first in the agents array and `Array.find()` returns the
|
|
79
|
+
* first match.
|
|
80
|
+
*
|
|
81
|
+
* By giving our custom agent a different name (e.g. "ph-explore") and rewriting
|
|
82
|
+
* the subagent_type in the tool input, we sidestep the collision entirely.
|
|
83
|
+
*
|
|
84
|
+
* https://github.com/anthropics/claude-agent-sdk-typescript/issues/267
|
|
85
|
+
*/
|
|
86
|
+
const SUBAGENT_REWRITES: Record<string, string> = {
|
|
87
|
+
Explore: "ph-explore",
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const createSubagentRewriteHook =
|
|
91
|
+
(logger: Logger): HookCallback =>
|
|
92
|
+
async (input: HookInput, _toolUseID: string | undefined) => {
|
|
93
|
+
if (input.hook_event_name !== "PreToolUse") {
|
|
94
|
+
return { continue: true };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (input.tool_name !== "Agent") {
|
|
98
|
+
return { continue: true };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const toolInput = input.tool_input as Record<string, unknown> | undefined;
|
|
102
|
+
const subagentType = toolInput?.subagent_type;
|
|
103
|
+
if (typeof subagentType !== "string" || !SUBAGENT_REWRITES[subagentType]) {
|
|
104
|
+
return { continue: true };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const target = SUBAGENT_REWRITES[subagentType];
|
|
108
|
+
logger.info(
|
|
109
|
+
`[SubagentRewriteHook] Rewriting subagent_type: ${subagentType} → ${target}`,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
continue: true,
|
|
114
|
+
hookSpecificOutput: {
|
|
115
|
+
hookEventName: "PreToolUse" as const,
|
|
116
|
+
updatedInput: {
|
|
117
|
+
...toolInput,
|
|
118
|
+
subagent_type: target,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
74
124
|
export const createPreToolUseHook =
|
|
75
125
|
(settingsManager: SettingsManager, logger: Logger): HookCallback =>
|
|
76
126
|
async (input: HookInput, _toolUseID: string | undefined) => {
|
|
@@ -14,6 +14,7 @@ import type { Logger } from "../../../utils/logger";
|
|
|
14
14
|
import {
|
|
15
15
|
createPostToolUseHook,
|
|
16
16
|
createPreToolUseHook,
|
|
17
|
+
createSubagentRewriteHook,
|
|
17
18
|
type OnModeChange,
|
|
18
19
|
} from "../hooks";
|
|
19
20
|
import type { CodeExecutionMode } from "../tools";
|
|
@@ -117,7 +118,10 @@ function buildHooks(
|
|
|
117
118
|
PreToolUse: [
|
|
118
119
|
...(userHooks?.PreToolUse || []),
|
|
119
120
|
{
|
|
120
|
-
hooks: [
|
|
121
|
+
hooks: [
|
|
122
|
+
createPreToolUseHook(settingsManager, logger),
|
|
123
|
+
createSubagentRewriteHook(logger),
|
|
124
|
+
],
|
|
121
125
|
},
|
|
122
126
|
],
|
|
123
127
|
};
|
package/src/server/bin.ts
CHANGED
|
@@ -7,25 +7,21 @@ import { claudeCodeConfigSchema, mcpServersSchema } from "./schemas";
|
|
|
7
7
|
const envSchema = z.object({
|
|
8
8
|
JWT_PUBLIC_KEY: z
|
|
9
9
|
.string({
|
|
10
|
-
|
|
11
|
-
"JWT_PUBLIC_KEY is required for authenticating client connections",
|
|
10
|
+
error: "JWT_PUBLIC_KEY is required for authenticating client connections",
|
|
12
11
|
})
|
|
13
12
|
.min(1, "JWT_PUBLIC_KEY cannot be empty"),
|
|
14
|
-
POSTHOG_API_URL: z
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"POSTHOG_API_URL is required for LLM gateway communication",
|
|
18
|
-
})
|
|
19
|
-
.url("POSTHOG_API_URL must be a valid URL"),
|
|
13
|
+
POSTHOG_API_URL: z.url({
|
|
14
|
+
error: "POSTHOG_API_URL is required for LLM gateway communication",
|
|
15
|
+
}),
|
|
20
16
|
POSTHOG_PERSONAL_API_KEY: z
|
|
21
17
|
.string({
|
|
22
|
-
|
|
18
|
+
error:
|
|
23
19
|
"POSTHOG_PERSONAL_API_KEY is required for authenticating with PostHog services",
|
|
24
20
|
})
|
|
25
21
|
.min(1, "POSTHOG_PERSONAL_API_KEY cannot be empty"),
|
|
26
22
|
POSTHOG_PROJECT_ID: z
|
|
27
23
|
.string({
|
|
28
|
-
|
|
24
|
+
error:
|
|
29
25
|
"POSTHOG_PROJECT_ID is required for routing requests to the correct project",
|
|
30
26
|
})
|
|
31
27
|
.regex(/^\d+$/, "POSTHOG_PROJECT_ID must be a numeric string")
|
|
@@ -34,7 +30,7 @@ const envSchema = z.object({
|
|
|
34
30
|
|
|
35
31
|
const program = new Command();
|
|
36
32
|
|
|
37
|
-
function parseJsonOption<S extends z.
|
|
33
|
+
function parseJsonOption<S extends z.ZodType>(
|
|
38
34
|
raw: string | undefined,
|
|
39
35
|
schema: S,
|
|
40
36
|
flag: string,
|
package/src/server/schemas.ts
CHANGED
|
@@ -8,7 +8,7 @@ const httpHeaderSchema = z.object({
|
|
|
8
8
|
const remoteMcpServerSchema = z.object({
|
|
9
9
|
type: z.enum(["http", "sse"]),
|
|
10
10
|
name: z.string().min(1, "MCP server name is required"),
|
|
11
|
-
url: z.
|
|
11
|
+
url: z.url({ error: "MCP server url must be a valid URL" }),
|
|
12
12
|
headers: z.array(httpHeaderSchema).default([]),
|
|
13
13
|
});
|
|
14
14
|
|
|
@@ -35,7 +35,7 @@ export const claudeCodeConfigSchema = z.object({
|
|
|
35
35
|
export const jsonRpcRequestSchema = z.object({
|
|
36
36
|
jsonrpc: z.literal("2.0"),
|
|
37
37
|
method: z.string(),
|
|
38
|
-
params: z.record(z.unknown()).optional(),
|
|
38
|
+
params: z.record(z.string(), z.unknown()).optional(),
|
|
39
39
|
id: z.union([z.string(), z.number()]).optional(),
|
|
40
40
|
});
|
|
41
41
|
|