@posthog/agent 2.3.349 → 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.
@@ -8701,7 +8701,7 @@ var import_hono = require("hono");
8701
8701
  // package.json
8702
8702
  var package_default = {
8703
8703
  name: "@posthog/agent",
8704
- version: "2.3.349",
8704
+ version: "2.3.351",
8705
8705
  repository: "https://github.com/PostHog/code",
8706
8706
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8707
8707
  exports: {
@@ -12740,7 +12740,7 @@ var createPostToolUseHook = ({ onModeChange, logger }) => async (input, toolUseI
12740
12740
  var SUBAGENT_REWRITES = {
12741
12741
  Explore: "ph-explore"
12742
12742
  };
12743
- var createSubagentRewriteHook = (logger) => async (input, _toolUseID) => {
12743
+ var createSubagentRewriteHook = (logger, registeredAgents) => async (input, _toolUseID) => {
12744
12744
  if (input.hook_event_name !== "PreToolUse") {
12745
12745
  return { continue: true };
12746
12746
  }
@@ -12753,6 +12753,12 @@ var createSubagentRewriteHook = (logger) => async (input, _toolUseID) => {
12753
12753
  return { continue: true };
12754
12754
  }
12755
12755
  const target = SUBAGENT_REWRITES[subagentType];
12756
+ if (!registeredAgents.has(target)) {
12757
+ logger.warn(
12758
+ `[SubagentRewriteHook] Skipping rewrite ${subagentType} \u2192 ${target}: target agent not registered for this session. Falling back to built-in ${subagentType}.`
12759
+ );
12760
+ return { continue: true };
12761
+ }
12756
12762
  logger.info(
12757
12763
  `[SubagentRewriteHook] Rewriting subagent_type: ${subagentType} \u2192 ${target}`
12758
12764
  );
@@ -14759,7 +14765,7 @@ function buildEnvironment() {
14759
14765
  CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1"
14760
14766
  };
14761
14767
  }
14762
- function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache) {
14768
+ function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache, registeredAgents) {
14763
14769
  const postToolUseHooks = [createPostToolUseHook({ onModeChange, logger })];
14764
14770
  if (enrichmentDeps && enrichedReadCache) {
14765
14771
  postToolUseHooks.push(
@@ -14777,12 +14783,49 @@ function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichment
14777
14783
  {
14778
14784
  hooks: [
14779
14785
  createPreToolUseHook(settingsManager, logger),
14780
- createSubagentRewriteHook(logger)
14786
+ createSubagentRewriteHook(logger, registeredAgents)
14781
14787
  ]
14782
14788
  }
14783
14789
  ]
14784
14790
  };
14785
14791
  }
14792
+ var PH_EXPLORE_AGENT = {
14793
+ 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.',
14794
+ model: "haiku",
14795
+ prompt: `You are a fast, read-only codebase exploration agent.
14796
+
14797
+ Your job is to find files, search code, read the most relevant sources, and report findings clearly.
14798
+
14799
+ Rules:
14800
+ - Never create, modify, delete, move, or copy files.
14801
+ - Never use shell redirection or any command that changes system state.
14802
+ - Use Glob for broad file pattern matching.
14803
+ - Use Grep for searching file contents.
14804
+ - Use Read when you know the exact file path to inspect.
14805
+ - Use Bash only for safe read-only commands like ls, git status, git log, git diff, find, cat, head, and tail.
14806
+ - Adapt your search approach based on the thoroughness level specified by the caller.
14807
+ - Return file paths as absolute paths in your final response.
14808
+ - Avoid using emojis.
14809
+ - Wherever possible, spawn multiple parallel tool calls for grepping and reading files.
14810
+ - Search efficiently, then read only the most relevant files.
14811
+ - Return findings directly in your final response \u2014 do not create files.`,
14812
+ tools: [
14813
+ "Bash",
14814
+ "Glob",
14815
+ "Grep",
14816
+ "Read",
14817
+ "WebFetch",
14818
+ "WebSearch",
14819
+ "NotebookRead",
14820
+ "TodoWrite"
14821
+ ]
14822
+ };
14823
+ function buildAgents(userAgents) {
14824
+ return {
14825
+ "ph-explore": PH_EXPLORE_AGENT,
14826
+ ...userAgents || {}
14827
+ };
14828
+ }
14786
14829
  function getAbortController(userProvidedController) {
14787
14830
  const controller = userProvidedController ?? new AbortController();
14788
14831
  if (controller.signal.aborted) {
@@ -14868,6 +14911,8 @@ function ensureLocalSettings(cwd) {
14868
14911
  function buildSessionOptions(params) {
14869
14912
  ensureLocalSettings(params.cwd);
14870
14913
  const tools = params.userProvidedOptions?.tools ?? (params.disableBuiltInTools ? [] : { type: "preset", preset: "claude_code" });
14914
+ const agents = buildAgents(params.userProvidedOptions?.agents);
14915
+ const registeredAgentNames = new Set(Object.keys(agents));
14871
14916
  const options = {
14872
14917
  ...params.userProvidedOptions,
14873
14918
  betas: ["context-1m-2025-08-07"],
@@ -14881,6 +14926,7 @@ function buildSessionOptions(params) {
14881
14926
  canUseTool: params.canUseTool,
14882
14927
  executable: "node",
14883
14928
  tools,
14929
+ agents,
14884
14930
  extraArgs: {
14885
14931
  ...params.userProvidedOptions?.extraArgs,
14886
14932
  "replay-user-messages": ""
@@ -14896,7 +14942,8 @@ function buildSessionOptions(params) {
14896
14942
  params.settingsManager,
14897
14943
  params.logger,
14898
14944
  params.enrichmentDeps,
14899
- params.enrichedReadCache
14945
+ params.enrichedReadCache,
14946
+ registeredAgentNames
14900
14947
  ),
14901
14948
  outputFormat: params.outputFormat,
14902
14949
  abortController: getAbortController(