@posthog/agent 2.3.346 → 2.3.351
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 +53 -6
- 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.js +53 -6
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +53 -6
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +5 -5
- package/src/adapters/claude/hooks.ts +9 -2
- package/src/adapters/claude/session/options.test.ts +72 -0
- package/src/adapters/claude/session/options.ts +56 -1
package/dist/agent.js
CHANGED
|
@@ -3164,7 +3164,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
3164
3164
|
// package.json
|
|
3165
3165
|
var package_default = {
|
|
3166
3166
|
name: "@posthog/agent",
|
|
3167
|
-
version: "2.3.
|
|
3167
|
+
version: "2.3.351",
|
|
3168
3168
|
repository: "https://github.com/PostHog/code",
|
|
3169
3169
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
3170
3170
|
exports: {
|
|
@@ -3254,6 +3254,7 @@ var package_default = {
|
|
|
3254
3254
|
devDependencies: {
|
|
3255
3255
|
"@posthog/shared": "workspace:*",
|
|
3256
3256
|
"@posthog/git": "workspace:*",
|
|
3257
|
+
"@posthog/enricher": "workspace:*",
|
|
3257
3258
|
"@types/bun": "latest",
|
|
3258
3259
|
"@types/tar": "^6.1.13",
|
|
3259
3260
|
msw: "^2.12.7",
|
|
@@ -3273,7 +3274,6 @@ var package_default = {
|
|
|
3273
3274
|
"@opentelemetry/resources": "^2.0.0",
|
|
3274
3275
|
"@opentelemetry/sdk-logs": "^0.208.0",
|
|
3275
3276
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
3276
|
-
"@posthog/enricher": "workspace:*",
|
|
3277
3277
|
"@types/jsonwebtoken": "^9.0.10",
|
|
3278
3278
|
commander: "^14.0.2",
|
|
3279
3279
|
hono: "^4.11.7",
|
|
@@ -6994,7 +6994,7 @@ var createPostToolUseHook = ({ onModeChange, logger }) => async (input, toolUseI
|
|
|
6994
6994
|
var SUBAGENT_REWRITES = {
|
|
6995
6995
|
Explore: "ph-explore"
|
|
6996
6996
|
};
|
|
6997
|
-
var createSubagentRewriteHook = (logger) => async (input, _toolUseID) => {
|
|
6997
|
+
var createSubagentRewriteHook = (logger, registeredAgents) => async (input, _toolUseID) => {
|
|
6998
6998
|
if (input.hook_event_name !== "PreToolUse") {
|
|
6999
6999
|
return { continue: true };
|
|
7000
7000
|
}
|
|
@@ -7007,6 +7007,12 @@ var createSubagentRewriteHook = (logger) => async (input, _toolUseID) => {
|
|
|
7007
7007
|
return { continue: true };
|
|
7008
7008
|
}
|
|
7009
7009
|
const target = SUBAGENT_REWRITES[subagentType];
|
|
7010
|
+
if (!registeredAgents.has(target)) {
|
|
7011
|
+
logger.warn(
|
|
7012
|
+
`[SubagentRewriteHook] Skipping rewrite ${subagentType} \u2192 ${target}: target agent not registered for this session. Falling back to built-in ${subagentType}.`
|
|
7013
|
+
);
|
|
7014
|
+
return { continue: true };
|
|
7015
|
+
}
|
|
7010
7016
|
logger.info(
|
|
7011
7017
|
`[SubagentRewriteHook] Rewriting subagent_type: ${subagentType} \u2192 ${target}`
|
|
7012
7018
|
);
|
|
@@ -9120,7 +9126,7 @@ function buildEnvironment() {
|
|
|
9120
9126
|
CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1"
|
|
9121
9127
|
};
|
|
9122
9128
|
}
|
|
9123
|
-
function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache) {
|
|
9129
|
+
function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache, registeredAgents) {
|
|
9124
9130
|
const postToolUseHooks = [createPostToolUseHook({ onModeChange, logger })];
|
|
9125
9131
|
if (enrichmentDeps && enrichedReadCache) {
|
|
9126
9132
|
postToolUseHooks.push(
|
|
@@ -9138,12 +9144,49 @@ function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichment
|
|
|
9138
9144
|
{
|
|
9139
9145
|
hooks: [
|
|
9140
9146
|
createPreToolUseHook(settingsManager, logger),
|
|
9141
|
-
createSubagentRewriteHook(logger)
|
|
9147
|
+
createSubagentRewriteHook(logger, registeredAgents)
|
|
9142
9148
|
]
|
|
9143
9149
|
}
|
|
9144
9150
|
]
|
|
9145
9151
|
};
|
|
9146
9152
|
}
|
|
9153
|
+
var PH_EXPLORE_AGENT = {
|
|
9154
|
+
description: 'Fast agent for exploring and understanding codebases. Use this when you need to find files by pattern (eg. "src/components/**/*.tsx"), search for code or keywords (eg. "where is the auth middleware?"), or answer questions about how the codebase works (eg. "how does the session service handle reconnects?"). When calling this agent, specify a thoroughness level: "quick" for targeted lookups, "medium" for broader exploration, or "very thorough" for comprehensive analysis across multiple locations.',
|
|
9155
|
+
model: "haiku",
|
|
9156
|
+
prompt: `You are a fast, read-only codebase exploration agent.
|
|
9157
|
+
|
|
9158
|
+
Your job is to find files, search code, read the most relevant sources, and report findings clearly.
|
|
9159
|
+
|
|
9160
|
+
Rules:
|
|
9161
|
+
- Never create, modify, delete, move, or copy files.
|
|
9162
|
+
- Never use shell redirection or any command that changes system state.
|
|
9163
|
+
- Use Glob for broad file pattern matching.
|
|
9164
|
+
- Use Grep for searching file contents.
|
|
9165
|
+
- Use Read when you know the exact file path to inspect.
|
|
9166
|
+
- Use Bash only for safe read-only commands like ls, git status, git log, git diff, find, cat, head, and tail.
|
|
9167
|
+
- Adapt your search approach based on the thoroughness level specified by the caller.
|
|
9168
|
+
- Return file paths as absolute paths in your final response.
|
|
9169
|
+
- Avoid using emojis.
|
|
9170
|
+
- Wherever possible, spawn multiple parallel tool calls for grepping and reading files.
|
|
9171
|
+
- Search efficiently, then read only the most relevant files.
|
|
9172
|
+
- Return findings directly in your final response \u2014 do not create files.`,
|
|
9173
|
+
tools: [
|
|
9174
|
+
"Bash",
|
|
9175
|
+
"Glob",
|
|
9176
|
+
"Grep",
|
|
9177
|
+
"Read",
|
|
9178
|
+
"WebFetch",
|
|
9179
|
+
"WebSearch",
|
|
9180
|
+
"NotebookRead",
|
|
9181
|
+
"TodoWrite"
|
|
9182
|
+
]
|
|
9183
|
+
};
|
|
9184
|
+
function buildAgents(userAgents) {
|
|
9185
|
+
return {
|
|
9186
|
+
"ph-explore": PH_EXPLORE_AGENT,
|
|
9187
|
+
...userAgents || {}
|
|
9188
|
+
};
|
|
9189
|
+
}
|
|
9147
9190
|
function getAbortController(userProvidedController) {
|
|
9148
9191
|
const controller = userProvidedController ?? new AbortController();
|
|
9149
9192
|
if (controller.signal.aborted) {
|
|
@@ -9229,6 +9272,8 @@ function ensureLocalSettings(cwd) {
|
|
|
9229
9272
|
function buildSessionOptions(params) {
|
|
9230
9273
|
ensureLocalSettings(params.cwd);
|
|
9231
9274
|
const tools = params.userProvidedOptions?.tools ?? (params.disableBuiltInTools ? [] : { type: "preset", preset: "claude_code" });
|
|
9275
|
+
const agents = buildAgents(params.userProvidedOptions?.agents);
|
|
9276
|
+
const registeredAgentNames = new Set(Object.keys(agents));
|
|
9232
9277
|
const options = {
|
|
9233
9278
|
...params.userProvidedOptions,
|
|
9234
9279
|
betas: ["context-1m-2025-08-07"],
|
|
@@ -9242,6 +9287,7 @@ function buildSessionOptions(params) {
|
|
|
9242
9287
|
canUseTool: params.canUseTool,
|
|
9243
9288
|
executable: "node",
|
|
9244
9289
|
tools,
|
|
9290
|
+
agents,
|
|
9245
9291
|
extraArgs: {
|
|
9246
9292
|
...params.userProvidedOptions?.extraArgs,
|
|
9247
9293
|
"replay-user-messages": ""
|
|
@@ -9257,7 +9303,8 @@ function buildSessionOptions(params) {
|
|
|
9257
9303
|
params.settingsManager,
|
|
9258
9304
|
params.logger,
|
|
9259
9305
|
params.enrichmentDeps,
|
|
9260
|
-
params.enrichedReadCache
|
|
9306
|
+
params.enrichedReadCache,
|
|
9307
|
+
registeredAgentNames
|
|
9261
9308
|
),
|
|
9262
9309
|
outputFormat: params.outputFormat,
|
|
9263
9310
|
abortController: getAbortController(
|