@posthog/agent 2.3.524 → 2.3.527

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.
@@ -8755,7 +8755,7 @@ var import_zod3 = require("zod");
8755
8755
  // package.json
8756
8756
  var package_default = {
8757
8757
  name: "@posthog/agent",
8758
- version: "2.3.524",
8758
+ version: "2.3.527",
8759
8759
  repository: "https://github.com/PostHog/code",
8760
8760
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8761
8761
  exports: {
@@ -8775,6 +8775,10 @@ var package_default = {
8775
8775
  types: "./dist/posthog-api.d.ts",
8776
8776
  import: "./dist/posthog-api.js"
8777
8777
  },
8778
+ "./pr-url-detector": {
8779
+ types: "./dist/pr-url-detector.d.ts",
8780
+ import: "./dist/pr-url-detector.js"
8781
+ },
8778
8782
  "./types": {
8779
8783
  types: "./dist/types.d.ts",
8780
8784
  import: "./dist/types.js"
@@ -14528,12 +14532,18 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
14528
14532
  function messageUpdateType(role) {
14529
14533
  return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
14530
14534
  }
14531
- function toolMeta(toolName, toolResponse, parentToolCallId) {
14535
+ function toolMeta(toolName, toolResponse, parentToolCallId, bashCommand) {
14532
14536
  const meta = { toolName };
14533
14537
  if (toolResponse !== void 0) meta.toolResponse = toolResponse;
14534
14538
  if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
14539
+ if (bashCommand) meta.bashCommand = bashCommand;
14535
14540
  return { claudeCode: meta };
14536
14541
  }
14542
+ function bashCommandFromToolUse(toolUse) {
14543
+ if (!toolUse || toolUse.name !== "Bash") return void 0;
14544
+ const command = toolUse.input?.command;
14545
+ return typeof command === "string" ? command : void 0;
14546
+ }
14537
14547
  function handleTextChunk(chunk, role, parentToolCallId) {
14538
14548
  const update = {
14539
14549
  sessionUpdate: messageUpdateType(role),
@@ -14594,7 +14604,12 @@ function handleToolUseChunk(chunk, ctx) {
14594
14604
  await ctx.client.sessionUpdate({
14595
14605
  sessionId: ctx.sessionId,
14596
14606
  update: {
14597
- _meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
14607
+ _meta: toolMeta(
14608
+ toolUse.name,
14609
+ toolResponse,
14610
+ ctx.parentToolCallId,
14611
+ bashCommandFromToolUse(toolUse)
14612
+ ),
14598
14613
  toolCallId: toolUseId,
14599
14614
  sessionUpdate: "tool_call_update",
14600
14615
  ...editUpdate ? editUpdate : {}
@@ -14620,7 +14635,12 @@ function handleToolUseChunk(chunk, ctx) {
14620
14635
  cwd: ctx.cwd
14621
14636
  });
14622
14637
  const meta = {
14623
- ...toolMeta(chunk.name, void 0, ctx.parentToolCallId)
14638
+ ...toolMeta(
14639
+ chunk.name,
14640
+ void 0,
14641
+ ctx.parentToolCallId,
14642
+ bashCommandFromToolUse(chunk)
14643
+ )
14624
14644
  };
14625
14645
  if (chunk.name === "Bash" && ctx.supportsTerminalOutput && !alreadyCached) {
14626
14646
  meta.terminal_info = { terminal_id: chunk.id };
@@ -14725,7 +14745,12 @@ function handleToolResultChunk(chunk, ctx) {
14725
14745
  });
14726
14746
  }
14727
14747
  const meta = {
14728
- ...toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
14748
+ ...toolMeta(
14749
+ toolUse.name,
14750
+ void 0,
14751
+ ctx.parentToolCallId,
14752
+ bashCommandFromToolUse(toolUse)
14753
+ ),
14729
14754
  ...resultMeta?.terminal_exit ? { terminal_exit: resultMeta.terminal_exit } : {}
14730
14755
  };
14731
14756
  updates.push({
@@ -20050,14 +20075,14 @@ var HandoffCheckpointTracker = class {
20050
20075
  });
20051
20076
  }
20052
20077
  logCaptureMetrics(checkpoint, uploads) {
20053
- this.logger.info("Captured handoff checkpoint", {
20078
+ this.logger.debug("Captured handoff checkpoint", {
20054
20079
  branch: checkpoint.branch,
20055
20080
  head: checkpoint.head?.slice(0, 7),
20056
20081
  totalBytes: this.sumRawBytes(uploads.pack, uploads.index)
20057
20082
  });
20058
20083
  }
20059
20084
  logApplyMetrics(checkpoint, _downloads, totalBytes) {
20060
- this.logger.info("Applied handoff checkpoint", {
20085
+ this.logger.debug("Applied handoff checkpoint", {
20061
20086
  branch: checkpoint.branch,
20062
20087
  head: checkpoint.head?.slice(0, 7),
20063
20088
  totalBytes
@@ -20287,6 +20312,37 @@ var PostHogAPIClient = class {
20287
20312
  }
20288
20313
  };
20289
20314
 
20315
+ // src/pr-url-detector.ts
20316
+ var PR_URL_REGEX = /https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+/;
20317
+ var GH_PR_CREATE_REGEX = /\bgh\s+pr\s+create\b/;
20318
+ function extractCreatedPrUrl(input) {
20319
+ const { toolName, bashCommand, toolResponse, content } = input;
20320
+ if (!toolName || !/bash/i.test(toolName)) return null;
20321
+ if (!bashCommand || !GH_PR_CREATE_REGEX.test(bashCommand)) return null;
20322
+ let textToSearch = "";
20323
+ if (toolResponse) {
20324
+ if (typeof toolResponse === "string") {
20325
+ textToSearch = toolResponse;
20326
+ } else if (typeof toolResponse === "object" && toolResponse !== null) {
20327
+ const respObj = toolResponse;
20328
+ textToSearch = String(respObj.stdout || "") + String(respObj.stderr || "");
20329
+ if (!textToSearch && respObj.output) {
20330
+ textToSearch = String(respObj.output);
20331
+ }
20332
+ }
20333
+ }
20334
+ if (Array.isArray(content)) {
20335
+ for (const item of content) {
20336
+ if (item.type === "text" && item.text) {
20337
+ textToSearch += ` ${item.text}`;
20338
+ }
20339
+ }
20340
+ }
20341
+ if (!textToSearch) return null;
20342
+ const match = textToSearch.match(PR_URL_REGEX);
20343
+ return match ? match[0] : null;
20344
+ }
20345
+
20290
20346
  // src/adapters/claude/session/jsonl-hydration.ts
20291
20347
  var import_node_crypto3 = require("crypto");
20292
20348
  var fs12 = __toESM(require("fs/promises"), 1);
@@ -21558,7 +21614,7 @@ var AgentServer = class {
21558
21614
  switch (method) {
21559
21615
  case POSTHOG_NOTIFICATIONS.USER_MESSAGE:
21560
21616
  case "user_message": {
21561
- this.logger.info("Received user_message command", {
21617
+ this.logger.debug("Received user_message command", {
21562
21618
  hasContent: typeof params.content === "string" ? params.content.trim().length > 0 : Array.isArray(params.content) && params.content.length > 0,
21563
21619
  artifactCount: Array.isArray(params.artifacts) ? params.artifacts.length : 0
21564
21620
  });
@@ -21571,7 +21627,7 @@ var AgentServer = class {
21571
21627
  if (prompt.length === 0) {
21572
21628
  throw new Error("User message cannot be empty");
21573
21629
  }
21574
- this.logger.info("Built user_message prompt", {
21630
+ this.logger.debug("Built user_message prompt", {
21575
21631
  blockTypes: prompt.map((block) => block.type)
21576
21632
  });
21577
21633
  const promptPreview = promptBlocksToText(prompt);
@@ -21656,7 +21712,7 @@ var AgentServer = class {
21656
21712
  case "posthog/refresh_session":
21657
21713
  case "refresh_session": {
21658
21714
  const mcpServers = Array.isArray(params.mcpServers) ? params.mcpServers : [];
21659
- this.logger.info("Refresh session requested", {
21715
+ this.logger.debug("Refresh session requested", {
21660
21716
  serverCount: mcpServers.length
21661
21717
  });
21662
21718
  return await this.session.clientConnection.extMethod(
@@ -22009,7 +22065,7 @@ var AgentServer = class {
22009
22065
  this.resumeState.latestGitCheckpoint
22010
22066
  );
22011
22067
  checkpointApplied = true;
22012
- this.logger.info("Git checkpoint applied", {
22068
+ this.logger.debug("Git checkpoint applied", {
22013
22069
  branch: this.resumeState.latestGitCheckpoint.branch,
22014
22070
  head: this.resumeState.latestGitCheckpoint.head,
22015
22071
  packBytes: metrics.packBytes,
@@ -22115,7 +22171,7 @@ Continue from where you left off. The user is waiting for your response.`
22115
22171
  taskId: taskRun.task,
22116
22172
  runId: taskRun.id
22117
22173
  });
22118
- this.logger.info("Built pending user prompt", {
22174
+ this.logger.debug("Built pending user prompt", {
22119
22175
  hasMessage: typeof message === "string" && message.trim().length > 0,
22120
22176
  requestedArtifactCount: artifactIds.length,
22121
22177
  blockTypes: prompt.map((block) => block.type)
@@ -22691,35 +22747,16 @@ ${attributionInstructions}
22691
22747
  detectAndAttachPrUrl(payload, update) {
22692
22748
  try {
22693
22749
  const meta = update?._meta?.claudeCode;
22694
- const toolResponse = meta?.toolResponse;
22695
- let textToSearch = "";
22696
- if (toolResponse) {
22697
- if (typeof toolResponse === "string") {
22698
- textToSearch = toolResponse;
22699
- } else if (typeof toolResponse === "object" && toolResponse !== null) {
22700
- const respObj = toolResponse;
22701
- textToSearch = String(respObj.stdout || "") + String(respObj.stderr || "");
22702
- if (!textToSearch && respObj.output) {
22703
- textToSearch = String(respObj.output);
22704
- }
22705
- }
22706
- }
22707
22750
  const content = update?.content;
22708
- if (Array.isArray(content)) {
22709
- for (const item of content) {
22710
- if (item.type === "text" && item.text) {
22711
- textToSearch += ` ${item.text}`;
22712
- }
22713
- }
22714
- }
22715
- if (!textToSearch) return;
22716
- const prUrlMatch = textToSearch.match(
22717
- /https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+/
22718
- );
22719
- if (!prUrlMatch) return;
22720
- const prUrl = prUrlMatch[0];
22751
+ const prUrl = extractCreatedPrUrl({
22752
+ toolName: meta?.toolName,
22753
+ bashCommand: meta?.bashCommand,
22754
+ toolResponse: meta?.toolResponse,
22755
+ content
22756
+ });
22757
+ if (!prUrl) return;
22721
22758
  this.detectedPrUrl = prUrl;
22722
- this.logger.debug("Detected PR URL in bash output", {
22759
+ this.logger.debug("Detected PR URL from gh pr create", {
22723
22760
  runId: payload.run_id,
22724
22761
  prUrl
22725
22762
  });