@posthog/agent 2.3.305 → 2.3.308

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.
@@ -5805,7 +5805,7 @@ var import_hono = require("hono");
5805
5805
  // package.json
5806
5806
  var package_default = {
5807
5807
  name: "@posthog/agent",
5808
- version: "2.3.305",
5808
+ version: "2.3.308",
5809
5809
  repository: "https://github.com/PostHog/code",
5810
5810
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
5811
5811
  exports: {
@@ -9232,11 +9232,6 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9232
9232
  }
9233
9233
  }
9234
9234
  this.session.lastContextWindowSize = lastContextWindowSize;
9235
- this.logger.debug("Context window size from result", {
9236
- sdkReported: contextWindows,
9237
- resolved: lastContextWindowSize,
9238
- modelId: this.session.modelId
9239
- });
9240
9235
  this.session.contextSize = lastContextWindowSize;
9241
9236
  if (lastAssistantTotalUsage !== null) {
9242
9237
  this.session.contextUsed = lastAssistantTotalUsage;
@@ -9595,7 +9590,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9595
9590
  const mcpServers = supportsMcpInjection(earlyModelId) ? parseMcpServers(params) : {};
9596
9591
  const systemPrompt = buildSystemPrompt(meta?.systemPrompt);
9597
9592
  const outputFormat = meta?.jsonSchema && this.options?.onStructuredOutput ? { type: "json_schema", schema: meta.jsonSchema } : void 0;
9598
- this.logger.info(isResume ? "Resuming session" : "Creating new session", {
9593
+ this.logger.debug(isResume ? "Resuming session" : "Creating new session", {
9599
9594
  sessionId,
9600
9595
  taskId,
9601
9596
  taskRunId: meta?.taskRunId,
@@ -9653,10 +9648,6 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9653
9648
  };
9654
9649
  this.session = session;
9655
9650
  this.sessionId = sessionId;
9656
- this.logger.info(
9657
- isResume ? "Session query initialized, awaiting resumption" : "Session query initialized, awaiting initialization",
9658
- { sessionId, taskId, taskRunId: meta?.taskRunId }
9659
- );
9660
9651
  if (isResume) {
9661
9652
  try {
9662
9653
  const result = await withTimeout(
@@ -9758,14 +9749,6 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9758
9749
  if (!creationOpts.skipBackgroundFetches) {
9759
9750
  this.deferBackgroundFetches(q);
9760
9751
  }
9761
- this.logger.info(
9762
- isResume ? "Session resumed successfully" : "Session created successfully",
9763
- {
9764
- sessionId,
9765
- taskId,
9766
- taskRunId: meta?.taskRunId
9767
- }
9768
- );
9769
9752
  return { sessionId, modes, models, configOptions };
9770
9753
  }
9771
9754
  createCanUseTool(sessionId, allowedDomains) {
@@ -9951,7 +9934,6 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9951
9934
  * Both populate caches used later — neither is needed to return configOptions.
9952
9935
  */
9953
9936
  deferBackgroundFetches(q) {
9954
- this.logger.info("Starting background fetches (commands + MCP metadata)");
9955
9937
  Promise.all([
9956
9938
  new Promise((resolve4) => setTimeout(resolve4, 10)).then(
9957
9939
  () => this.sendAvailableCommandsUpdate()
@@ -10370,6 +10352,17 @@ var CodexAcpAgent = class extends BaseAcpAgent {
10370
10352
  codexProcess;
10371
10353
  codexConnection;
10372
10354
  sessionState;
10355
+ /**
10356
+ * FIFO serializer for prompt() calls. codex-acp and codex-rs themselves
10357
+ * serialize submissions at the conversation level, but our adapter
10358
+ * accumulates per-turn usage into sessionState.accumulatedUsage via the
10359
+ * codex-client sessionUpdate handler. If two prompts ran concurrently on
10360
+ * the JS side, the second's resetUsage() would wipe out the first's
10361
+ * in-flight counters and both TURN_COMPLETE notifications would report
10362
+ * garbled totals. Serializing on the JS side keeps the accumulator
10363
+ * single-owner.
10364
+ */
10365
+ promptMutex = Promise.resolve();
10373
10366
  constructor(client, options) {
10374
10367
  super(client);
10375
10368
  this.logger = new Logger({ debug: true, prefix: "[CodexAcpAgent]" });
@@ -10556,6 +10549,13 @@ var CodexAcpAgent = class extends BaseAcpAgent {
10556
10549
  return this.listSessions(params);
10557
10550
  }
10558
10551
  async prompt(params) {
10552
+ const previous = this.promptMutex;
10553
+ const next = previous.catch(() => {
10554
+ }).then(() => this.runPrompt(params));
10555
+ this.promptMutex = next;
10556
+ return next;
10557
+ }
10558
+ async runPrompt(params) {
10559
10559
  this.session.cancelled = false;
10560
10560
  this.session.interruptReason = void 0;
10561
10561
  resetUsage(this.sessionState);
@@ -10689,7 +10689,6 @@ function createClaudeConnection(config) {
10689
10689
  ...config.processCallbacks,
10690
10690
  onStructuredOutput: config.onStructuredOutput
10691
10691
  });
10692
- logger.info(`Created ${agent.adapterName} agent`);
10693
10692
  return agent;
10694
10693
  }, agentStream);
10695
10694
  return {
@@ -10754,7 +10753,6 @@ function createCodexConnection(config) {
10754
10753
  codexProcessOptions: config.codexOptions ?? {},
10755
10754
  processCallbacks: config.processCallbacks
10756
10755
  });
10757
- logger.info(`Created ${agent.adapterName} agent`);
10758
10756
  return agent;
10759
10757
  }, agentStream);
10760
10758
  return {
@@ -11080,7 +11078,6 @@ var Saga = class {
11080
11078
  this.currentStepName = "unknown";
11081
11079
  this.stepTimings = [];
11082
11080
  const sagaStart = performance.now();
11083
- this.log.info("Starting saga", { sagaName: this.sagaName });
11084
11081
  try {
11085
11082
  const result = await this.execute(input);
11086
11083
  const totalDuration = performance.now() - sagaStart;
@@ -11095,7 +11092,8 @@ var Saga = class {
11095
11092
  this.log.error("Saga failed, initiating rollback", {
11096
11093
  sagaName: this.sagaName,
11097
11094
  failedStep: this.currentStepName,
11098
- error: error instanceof Error ? error.message : String(error)
11095
+ error: error instanceof Error ? error.message : String(error),
11096
+ completedStepTimings: this.stepTimings
11099
11097
  });
11100
11098
  await this.rollback();
11101
11099
  return {
@@ -11116,12 +11114,10 @@ var Saga = class {
11116
11114
  */
11117
11115
  async step(config) {
11118
11116
  this.currentStepName = config.name;
11119
- this.log.debug(`Executing step: ${config.name}`);
11120
11117
  const stepStart = performance.now();
11121
11118
  const result = await config.execute();
11122
11119
  const durationMs = Math.round(performance.now() - stepStart);
11123
11120
  this.stepTimings.push({ name: config.name, durationMs });
11124
- this.log.debug(`Step completed: ${config.name}`, { durationMs });
11125
11121
  this.completedSteps.push({
11126
11122
  name: config.name,
11127
11123
  rollback: () => config.rollback(result)
@@ -11139,12 +11135,10 @@ var Saga = class {
11139
11135
  */
11140
11136
  async readOnlyStep(name, execute) {
11141
11137
  this.currentStepName = name;
11142
- this.log.debug(`Executing read-only step: ${name}`);
11143
11138
  const stepStart = performance.now();
11144
11139
  const result = await execute();
11145
11140
  const durationMs = Math.round(performance.now() - stepStart);
11146
11141
  this.stepTimings.push({ name, durationMs });
11147
- this.log.debug(`Read-only step completed: ${name}`, { durationMs });
11148
11142
  return result;
11149
11143
  }
11150
11144
  /**
@@ -11158,9 +11152,7 @@ var Saga = class {
11158
11152
  const stepsReversed = [...this.completedSteps].reverse();
11159
11153
  for (const step of stepsReversed) {
11160
11154
  try {
11161
- this.log.debug(`Rolling back step: ${step.name}`);
11162
11155
  await step.rollback();
11163
- this.log.debug(`Step rolled back: ${step.name}`);
11164
11156
  } catch (error) {
11165
11157
  this.log.error(`Failed to rollback step: ${step.name}`, {
11166
11158
  error: error instanceof Error ? error.message : String(error)
@@ -12043,10 +12035,6 @@ var SessionLogWriter = class _SessionLogWriter {
12043
12035
  if (this.sessions.has(sessionId)) {
12044
12036
  return;
12045
12037
  }
12046
- this.logger.info("Session registered", {
12047
- taskId: context.taskId,
12048
- runId: context.runId
12049
- });
12050
12038
  this.sessions.set(sessionId, { context, currentTurnMessages: [] });
12051
12039
  this.lastFlushAttemptTime.set(sessionId, Date.now());
12052
12040
  if (this.localCachePath) {