@posthog/agent 2.3.163 → 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/agent.js +35 -2
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +35 -2
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +35 -2
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude/hooks.ts +50 -0
- package/src/adapters/claude/session/options.ts +5 -1
package/package.json
CHANGED
|
@@ -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
|
};
|