@posthog/agent 2.3.354 → 2.3.356

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.
@@ -8728,7 +8728,7 @@ var import_zod3 = require("zod");
8728
8728
  // package.json
8729
8729
  var package_default = {
8730
8730
  name: "@posthog/agent",
8731
- version: "2.3.354",
8731
+ version: "2.3.356",
8732
8732
  repository: "https://github.com/PostHog/code",
8733
8733
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8734
8734
  exports: {
@@ -8889,6 +8889,8 @@ var POSTHOG_NOTIFICATIONS = {
8889
8889
  CLOSE: "_posthog/close",
8890
8890
  /** Agent status update (thinking, working, etc.) */
8891
8891
  STATUS: "_posthog/status",
8892
+ /** Structured backend progress notification; events in the same turn group into one card on the client */
8893
+ PROGRESS: "_posthog/progress",
8892
8894
  /** Task-level notification (progress, milestones) */
8893
8895
  TASK_NOTIFICATION: "_posthog/task_notification",
8894
8896
  /** Marks a boundary for log compaction */
@@ -19437,7 +19439,9 @@ var AgentServer = class _AgentServer {
19437
19439
  port: this.config.port
19438
19440
  },
19439
19441
  () => {
19440
- this.logger.info(`HTTP server listening on port ${this.config.port}`);
19442
+ this.logger.debug(
19443
+ `HTTP server listening on port ${this.config.port}`
19444
+ );
19441
19445
  resolve4();
19442
19446
  }
19443
19447
  );
@@ -19446,10 +19450,10 @@ var AgentServer = class _AgentServer {
19446
19450
  }
19447
19451
  async autoInitializeSession() {
19448
19452
  const { taskId, runId, mode, projectId } = this.config;
19449
- this.logger.info("Auto-initializing session", { taskId, runId, mode });
19453
+ this.logger.debug("Auto-initializing session", { taskId, runId, mode });
19450
19454
  const resumeRunId = process.env.POSTHOG_RESUME_RUN_ID;
19451
19455
  if (resumeRunId) {
19452
- this.logger.info("Resuming from previous run", {
19456
+ this.logger.debug("Resuming from previous run", {
19453
19457
  resumeRunId,
19454
19458
  currentRunId: runId
19455
19459
  });
@@ -19461,13 +19465,13 @@ var AgentServer = class _AgentServer {
19461
19465
  apiClient: this.posthogAPI,
19462
19466
  logger: new Logger({ debug: true, prefix: "[Resume]" })
19463
19467
  });
19464
- this.logger.info("Resume state loaded", {
19468
+ this.logger.debug("Resume state loaded", {
19465
19469
  conversationTurns: this.resumeState.conversation.length,
19466
19470
  snapshotApplied: this.resumeState.snapshotApplied,
19467
19471
  logEntries: this.resumeState.logEntryCount
19468
19472
  });
19469
19473
  } catch (error) {
19470
- this.logger.warn("Failed to load resume state, starting fresh", {
19474
+ this.logger.debug("Failed to load resume state, starting fresh", {
19471
19475
  error
19472
19476
  });
19473
19477
  this.resumeState = null;
@@ -19485,7 +19489,7 @@ var AgentServer = class _AgentServer {
19485
19489
  await this.initializeSession(payload, null);
19486
19490
  }
19487
19491
  async stop() {
19488
- this.logger.info("Stopping agent server...");
19492
+ this.logger.debug("Stopping agent server...");
19489
19493
  if (this.session) {
19490
19494
  await this.cleanupSession();
19491
19495
  }
@@ -19493,7 +19497,7 @@ var AgentServer = class _AgentServer {
19493
19497
  this.server.close();
19494
19498
  this.server = null;
19495
19499
  }
19496
- this.logger.info("Agent server stopped");
19500
+ this.logger.debug("Agent server stopped");
19497
19501
  }
19498
19502
  authenticateRequest(getHeader) {
19499
19503
  if (!this.config.jwtPublicKey) {
@@ -19536,7 +19540,7 @@ var AgentServer = class _AgentServer {
19536
19540
  blockTypes: prompt.map((block) => block.type)
19537
19541
  });
19538
19542
  const promptPreview = promptBlocksToText(prompt);
19539
- this.logger.info(
19543
+ this.logger.debug(
19540
19544
  `Processing user message (detectedPrUrl=${this.detectedPrUrl ?? "none"}): ${promptPreview.substring(0, 100)}...`
19541
19545
  );
19542
19546
  this.session.logWriter.resetTurnMessages(this.session.payload.run_id);
@@ -19551,7 +19555,7 @@ var AgentServer = class _AgentServer {
19551
19555
  }
19552
19556
  }
19553
19557
  });
19554
- this.logger.info("User message completed", {
19558
+ this.logger.debug("User message completed", {
19555
19559
  stopReason: result.stopReason
19556
19560
  });
19557
19561
  if (result.stopReason === "end_turn") {
@@ -19560,7 +19564,7 @@ var AgentServer = class _AgentServer {
19560
19564
  this.broadcastTurnComplete(result.stopReason);
19561
19565
  if (result.stopReason === "end_turn") {
19562
19566
  this.relayAgentResponse(this.session.payload).catch(
19563
- (err2) => this.logger.warn("Failed to relay follow-up response", err2)
19567
+ (err2) => this.logger.debug("Failed to relay follow-up response", err2)
19564
19568
  );
19565
19569
  }
19566
19570
  let assistantMessage;
@@ -19572,7 +19576,7 @@ var AgentServer = class _AgentServer {
19572
19576
  this.session.payload.run_id
19573
19577
  );
19574
19578
  } catch {
19575
- this.logger.warn("Failed to extract assistant message from logs");
19579
+ this.logger.debug("Failed to extract assistant message from logs");
19576
19580
  }
19577
19581
  return {
19578
19582
  stopReason: result.stopReason,
@@ -19581,7 +19585,7 @@ var AgentServer = class _AgentServer {
19581
19585
  }
19582
19586
  case POSTHOG_NOTIFICATIONS.CANCEL:
19583
19587
  case "cancel": {
19584
- this.logger.info("Cancel requested", {
19588
+ this.logger.debug("Cancel requested", {
19585
19589
  acpSessionId: this.session.acpSessionId
19586
19590
  });
19587
19591
  await this.session.clientConnection.cancel({
@@ -19591,7 +19595,7 @@ var AgentServer = class _AgentServer {
19591
19595
  }
19592
19596
  case POSTHOG_NOTIFICATIONS.CLOSE:
19593
19597
  case "close": {
19594
- this.logger.info("Close requested");
19598
+ this.logger.debug("Close requested");
19595
19599
  await this.cleanupSession();
19596
19600
  return { closed: true };
19597
19601
  }
@@ -19599,7 +19603,7 @@ var AgentServer = class _AgentServer {
19599
19603
  case "set_config_option": {
19600
19604
  const configId = params.configId;
19601
19605
  const value = params.value;
19602
- this.logger.info("Set config option requested", { configId, value });
19606
+ this.logger.debug("Set config option requested", { configId, value });
19603
19607
  const result = await this.session.clientConnection.setSessionConfigOption({
19604
19608
  sessionId: this.session.acpSessionId,
19605
19609
  configId,
@@ -19627,7 +19631,7 @@ var AgentServer = class _AgentServer {
19627
19631
  const optionId = params.optionId;
19628
19632
  const customInput = params.customInput;
19629
19633
  const answers = params.answers;
19630
- this.logger.info("Permission response received", {
19634
+ this.logger.debug("Permission response received", {
19631
19635
  requestId,
19632
19636
  optionId
19633
19637
  });
@@ -19650,7 +19654,7 @@ var AgentServer = class _AgentServer {
19650
19654
  }
19651
19655
  async initializeSession(payload, sseController) {
19652
19656
  if (this.initializationPromise) {
19653
- this.logger.info("Waiting for in-progress initialization", {
19657
+ this.logger.debug("Waiting for in-progress initialization", {
19654
19658
  runId: payload.run_id
19655
19659
  });
19656
19660
  await this.initializationPromise;
@@ -19675,7 +19679,7 @@ var AgentServer = class _AgentServer {
19675
19679
  if (this.session) {
19676
19680
  await this.cleanupSession();
19677
19681
  }
19678
- this.logger.info("Initializing session", {
19682
+ this.logger.debug("Initializing session", {
19679
19683
  runId: payload.run_id,
19680
19684
  taskId: payload.task_id
19681
19685
  });
@@ -19686,7 +19690,7 @@ var AgentServer = class _AgentServer {
19686
19690
  this.configureEnvironment();
19687
19691
  const [preTaskRun, preTask] = await Promise.all([
19688
19692
  this.posthogAPI.getTaskRun(payload.task_id, payload.run_id).catch((err2) => {
19689
- this.logger.warn("Failed to fetch task run for session context", {
19693
+ this.logger.debug("Failed to fetch task run for session context", {
19690
19694
  taskId: payload.task_id,
19691
19695
  runId: payload.run_id,
19692
19696
  error: err2
@@ -19694,7 +19698,7 @@ var AgentServer = class _AgentServer {
19694
19698
  return null;
19695
19699
  }),
19696
19700
  this.posthogAPI.getTask(payload.task_id).catch((err2) => {
19697
- this.logger.warn("Failed to fetch task for session context", {
19701
+ this.logger.debug("Failed to fetch task for session context", {
19698
19702
  taskId: payload.task_id,
19699
19703
  error: err2
19700
19704
  });
@@ -19804,7 +19808,7 @@ var AgentServer = class _AgentServer {
19804
19808
  }
19805
19809
  });
19806
19810
  const acpSessionId = sessionResponse.sessionId;
19807
- this.logger.info("ACP session created", {
19811
+ this.logger.debug("ACP session created", {
19808
19812
  acpSessionId,
19809
19813
  runId: payload.run_id
19810
19814
  });
@@ -19824,19 +19828,18 @@ var AgentServer = class _AgentServer {
19824
19828
  debug: true,
19825
19829
  prefix: "[AgentServer]",
19826
19830
  onLog: (level, scope, message, data) => {
19827
- const _formatted = data !== void 0 ? `${message} ${JSON.stringify(data)}` : message;
19828
19831
  this.emitConsoleLog(level, scope, message, data);
19829
19832
  }
19830
19833
  });
19831
- this.logger.info("Session initialized successfully");
19832
- this.logger.info(
19834
+ this.logger.debug("Session initialized successfully");
19835
+ this.logger.debug(
19833
19836
  `Agent version: ${this.config.version ?? package_default.version}`
19834
19837
  );
19835
- this.logger.info(`Initial permission mode: ${initialPermissionMode}`);
19838
+ this.logger.debug(`Initial permission mode: ${initialPermissionMode}`);
19836
19839
  this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
19837
19840
  status: "in_progress"
19838
19841
  }).catch(
19839
- (err2) => this.logger.warn("Failed to set task run to in_progress", err2)
19842
+ (err2) => this.logger.debug("Failed to set task run to in_progress", err2)
19840
19843
  );
19841
19844
  await this.sendInitialTaskMessage(payload, preTaskRun);
19842
19845
  }
@@ -19867,7 +19870,7 @@ var AgentServer = class _AgentServer {
19867
19870
  payload.run_id
19868
19871
  );
19869
19872
  } catch (error) {
19870
- this.logger.warn("Failed to fetch task run", {
19873
+ this.logger.debug("Failed to fetch task run", {
19871
19874
  taskId: payload.task_id,
19872
19875
  runId: payload.run_id,
19873
19876
  error
@@ -19877,7 +19880,7 @@ var AgentServer = class _AgentServer {
19877
19880
  if (!this.resumeState) {
19878
19881
  const resumeRunId = this.getResumeRunId(taskRun);
19879
19882
  if (resumeRunId) {
19880
- this.logger.info("Resuming from previous run (via TaskRun state)", {
19883
+ this.logger.debug("Resuming from previous run (via TaskRun state)", {
19881
19884
  resumeRunId,
19882
19885
  currentRunId: payload.run_id
19883
19886
  });
@@ -19889,13 +19892,13 @@ var AgentServer = class _AgentServer {
19889
19892
  apiClient: this.posthogAPI,
19890
19893
  logger: new Logger({ debug: true, prefix: "[Resume]" })
19891
19894
  });
19892
- this.logger.info("Resume state loaded (via TaskRun state)", {
19895
+ this.logger.debug("Resume state loaded (via TaskRun state)", {
19893
19896
  conversationTurns: this.resumeState.conversation.length,
19894
19897
  snapshotApplied: this.resumeState.snapshotApplied,
19895
19898
  logEntries: this.resumeState.logEntryCount
19896
19899
  });
19897
19900
  } catch (error) {
19898
- this.logger.warn("Failed to load resume state, starting fresh", {
19901
+ this.logger.debug("Failed to load resume state, starting fresh", {
19899
19902
  error
19900
19903
  });
19901
19904
  this.resumeState = null;
@@ -19919,10 +19922,10 @@ var AgentServer = class _AgentServer {
19919
19922
  initialPrompt = [{ type: "text", text: task.description }];
19920
19923
  }
19921
19924
  if (initialPrompt.length === 0) {
19922
- this.logger.warn("Task has no description, skipping initial message");
19925
+ this.logger.debug("Task has no description, skipping initial message");
19923
19926
  return;
19924
19927
  }
19925
- this.logger.info("Sending initial task message", {
19928
+ this.logger.debug("Sending initial task message", {
19926
19929
  taskId: payload.task_id,
19927
19930
  descriptionLength: promptBlocksToText(initialPrompt).length,
19928
19931
  usedInitialPromptOverride: !!initialPromptOverride,
@@ -19933,7 +19936,7 @@ var AgentServer = class _AgentServer {
19933
19936
  sessionId: this.session.acpSessionId,
19934
19937
  prompt: initialPrompt
19935
19938
  });
19936
- this.logger.info("Initial task message completed", {
19939
+ this.logger.debug("Initial task message completed", {
19937
19940
  stopReason: result.stopReason
19938
19941
  });
19939
19942
  await this.clearPendingInitialPromptState(payload, taskRun);
@@ -19995,7 +19998,7 @@ Continue from where you left off. The user is waiting for your response.`
19995
19998
  }
19996
19999
  ];
19997
20000
  }
19998
- this.logger.info("Sending resume message", {
20001
+ this.logger.debug("Sending resume message", {
19999
20002
  taskId: payload.task_id,
20000
20003
  conversationTurns: this.resumeState.conversation.length,
20001
20004
  promptLength: promptBlocksToText(resumePromptBlocks).length,
@@ -20008,7 +20011,7 @@ Continue from where you left off. The user is waiting for your response.`
20008
20011
  sessionId: this.session.acpSessionId,
20009
20012
  prompt: resumePromptBlocks
20010
20013
  });
20011
- this.logger.info("Resume message completed", {
20014
+ this.logger.debug("Resume message completed", {
20012
20015
  stopReason: result.stopReason
20013
20016
  });
20014
20017
  if (result.stopReason === "end_turn") {
@@ -20354,7 +20357,7 @@ ${attributionInstructions}
20354
20357
  try {
20355
20358
  return await getCurrentBranch(this.config.repositoryPath);
20356
20359
  } catch (error) {
20357
- this.logger.warn("Failed to determine current git branch", {
20360
+ this.logger.debug("Failed to determine current git branch", {
20358
20361
  repositoryPath: this.config.repositoryPath,
20359
20362
  error
20360
20363
  });
@@ -20373,7 +20376,7 @@ ${attributionInstructions}
20373
20376
  });
20374
20377
  this.lastReportedBranch = branchName;
20375
20378
  } catch (error) {
20376
- this.logger.warn("Failed to attach current branch to task run", {
20379
+ this.logger.debug("Failed to attach current branch to task run", {
20377
20380
  taskId: payload.task_id,
20378
20381
  runId: payload.run_id,
20379
20382
  branchName,
@@ -20388,7 +20391,7 @@ ${attributionInstructions}
20388
20391
  coalesce: true
20389
20392
  });
20390
20393
  } catch (error) {
20391
- this.logger.warn("Failed to flush session logs before completion", {
20394
+ this.logger.debug("Failed to flush session logs before completion", {
20392
20395
  taskId: payload.task_id,
20393
20396
  runId: payload.run_id,
20394
20397
  error
@@ -20396,7 +20399,7 @@ ${attributionInstructions}
20396
20399
  }
20397
20400
  }
20398
20401
  if (stopReason !== "error") {
20399
- this.logger.info("Skipping status update for non-error stop reason", {
20402
+ this.logger.debug("Skipping status update for non-error stop reason", {
20400
20403
  stopReason
20401
20404
  });
20402
20405
  return;
@@ -20407,7 +20410,7 @@ ${attributionInstructions}
20407
20410
  status,
20408
20411
  error_message: errorMessage ?? "Agent error"
20409
20412
  });
20410
- this.logger.info("Task completion signaled", { status, stopReason });
20413
+ this.logger.debug("Task completion signaled", { status, stopReason });
20411
20414
  } catch (error) {
20412
20415
  this.logger.error("Failed to signal task completion", error);
20413
20416
  }
@@ -20486,7 +20489,7 @@ ${attributionInstructions}
20486
20489
  const sessionPermissionMode = this.getSessionPermissionMode();
20487
20490
  const needsDesktopApproval = isQuestion || this.shouldRelayPermissionToClient(sessionPermissionMode);
20488
20491
  if (isPlanApproval || needsDesktopApproval && this.session?.hasDesktopConnected) {
20489
- this.logger.info("Relaying permission request", {
20492
+ this.logger.debug("Relaying permission request", {
20490
20493
  kind: params.toolCall?.kind,
20491
20494
  isQuestion,
20492
20495
  hasDesktopConnected: this.session?.hasDesktopConnected ?? false,
@@ -20516,7 +20519,7 @@ ${attributionInstructions}
20516
20519
  sessionUpdate: async (params) => {
20517
20520
  if (params.update?.sessionUpdate === "current_mode_update" && typeof params.update?.currentModeId === "string" && this.session) {
20518
20521
  this.session.permissionMode = params.update.currentModeId;
20519
- this.logger.info("Permission mode updated", {
20522
+ this.logger.debug("Permission mode updated", {
20520
20523
  mode: params.update.currentModeId
20521
20524
  });
20522
20525
  }
@@ -20545,7 +20548,7 @@ ${attributionInstructions}
20545
20548
  try {
20546
20549
  await this.session.logWriter.flush(payload.run_id, { coalesce: true });
20547
20550
  } catch (error) {
20548
- this.logger.warn("Failed to flush logs before Slack relay", {
20551
+ this.logger.debug("Failed to flush logs before Slack relay", {
20549
20552
  taskId: payload.task_id,
20550
20553
  runId: payload.run_id,
20551
20554
  error
@@ -20553,7 +20556,7 @@ ${attributionInstructions}
20553
20556
  }
20554
20557
  const message = this.session.logWriter.getFullAgentResponse(payload.run_id);
20555
20558
  if (!message) {
20556
- this.logger.warn("No agent message found for Slack relay", {
20559
+ this.logger.debug("No agent message found for Slack relay", {
20557
20560
  taskId: payload.task_id,
20558
20561
  runId: payload.run_id,
20559
20562
  sessionRegistered: this.session.logWriter.isRegistered(payload.run_id)
@@ -20567,7 +20570,7 @@ ${attributionInstructions}
20567
20570
  message
20568
20571
  );
20569
20572
  } catch (error) {
20570
- this.logger.warn("Failed to relay initial agent response to Slack", {
20573
+ this.logger.debug("Failed to relay initial agent response to Slack", {
20571
20574
  taskId: payload.task_id,
20572
20575
  runId: payload.run_id,
20573
20576
  error
@@ -20594,7 +20597,7 @@ ${attributionInstructions}
20594
20597
  message += "\nReply in this thread with your choice.";
20595
20598
  this.questionRelayedToSlack = true;
20596
20599
  this.posthogAPI.relayMessage(payload.task_id, payload.run_id, message).catch(
20597
- (err2) => this.logger.warn("Failed to relay question to Slack", { err: err2 })
20600
+ (err2) => this.logger.debug("Failed to relay question to Slack", { err: err2 })
20598
20601
  );
20599
20602
  }
20600
20603
  getFirstQuestionMeta(toolMeta2) {
@@ -20656,14 +20659,14 @@ ${attributionInstructions}
20656
20659
  if (!prUrlMatch) return;
20657
20660
  const prUrl = prUrlMatch[0];
20658
20661
  this.detectedPrUrl = prUrl;
20659
- this.logger.info("Detected PR URL in bash output", {
20662
+ this.logger.debug("Detected PR URL in bash output", {
20660
20663
  runId: payload.run_id,
20661
20664
  prUrl
20662
20665
  });
20663
20666
  this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
20664
20667
  output: { pr_url: prUrl }
20665
20668
  }).then(() => {
20666
- this.logger.info("PR URL attached to task run", {
20669
+ this.logger.debug("PR URL attached to task run", {
20667
20670
  taskId: payload.task_id,
20668
20671
  runId: payload.run_id,
20669
20672
  prUrl
@@ -20685,7 +20688,7 @@ ${attributionInstructions}
20685
20688
  }
20686
20689
  async cleanupSession() {
20687
20690
  if (!this.session) return;
20688
- this.logger.info("Cleaning up session");
20691
+ this.logger.debug("Cleaning up session");
20689
20692
  try {
20690
20693
  await this.captureTreeState();
20691
20694
  } catch (error) {