@posthog/agent 2.1.157 → 2.1.167

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.1.157",
3
+ "version": "2.1.167",
4
4
  "repository": "https://github.com/PostHog/twig",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@agentclientprotocol/sdk": "^0.14.0",
82
- "@anthropic-ai/claude-agent-sdk": "0.2.63",
82
+ "@anthropic-ai/claude-agent-sdk": "0.2.68",
83
83
  "@anthropic-ai/sdk": "^0.78.0",
84
84
  "@hono/node-server": "^1.19.9",
85
85
  "@opentelemetry/api-logs": "^0.208.0",
@@ -5,8 +5,8 @@ Fork of `@anthropic-ai/claude-agent-acp`. Upstream repo: https://github.com/anth
5
5
  ## Fork Point
6
6
 
7
7
  - **Forked**: v0.10.9, commit `5411e0f4`, Dec 2 2025
8
- - **Last sync**: v0.19.2, March 2 2026
9
- - **SDK**: `@anthropic-ai/claude-agent-sdk` 0.2.63, `@agentclientprotocol/sdk` ^0.14.0
8
+ - **Last sync**: v0.20.2, commit `dd9fe3a98ea494ba1982516f8aa0464b48fdd5e1`, March 6 2026
9
+ - **SDK**: `@anthropic-ai/claude-agent-sdk` 0.2.68, `@agentclientprotocol/sdk` ^0.14.0
10
10
 
11
11
  ## File Mapping
12
12
 
@@ -55,7 +55,7 @@ Fork of `@anthropic-ai/claude-agent-acp`. Upstream repo: https://github.com/anth
55
55
 
56
56
  ## Next Sync
57
57
 
58
- 1. Check upstream changelog since v0.19.2
58
+ 1. Check upstream changelog since v0.20.2
59
59
  2. Diff upstream source against Twig using the file mapping above
60
60
  3. Port in phases: bug fixes first, then features
61
61
  4. After each phase: `pnpm --filter agent typecheck && pnpm --filter agent build && pnpm lint`
@@ -385,14 +385,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
385
385
  const result = handleResultMessage(message);
386
386
  if (result.error) throw result.error;
387
387
 
388
- switch (message.subtype) {
389
- case "error_max_budget_usd":
390
- case "error_max_turns":
391
- case "error_max_structured_output_retries":
392
- return { stopReason: "max_turn_requests", usage };
393
- default:
394
- return { stopReason: "end_turn", usage };
395
- }
388
+ return { stopReason: result.stopReason ?? "end_turn", usage };
396
389
  }
397
390
 
398
391
  case "stream_event":
@@ -420,6 +413,14 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
420
413
  }
421
414
  }
422
415
 
416
+ // Skip replayed user messages that aren't pending prompts
417
+ if (
418
+ "isReplay" in message &&
419
+ (message as Record<string, unknown>).isReplay
420
+ ) {
421
+ break;
422
+ }
423
+
423
424
  // Store latest assistant usage (excluding subagents)
424
425
  if (
425
426
  "usage" in message.message &&
@@ -451,6 +452,8 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
451
452
  case "tool_progress":
452
453
  case "auth_status":
453
454
  case "tool_use_summary":
455
+ case "prompt_suggestion":
456
+ case "rate_limit_event":
454
457
  break;
455
458
 
456
459
  default:
@@ -459,6 +462,28 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
459
462
  }
460
463
  }
461
464
  throw new Error("Session did not end in result");
465
+ } catch (error) {
466
+ if (error instanceof RequestError || !(error instanceof Error)) {
467
+ throw error;
468
+ }
469
+ const msg = error.message;
470
+ if (
471
+ msg.includes("ProcessTransport") ||
472
+ msg.includes("terminated process") ||
473
+ msg.includes("process exited with") ||
474
+ msg.includes("process terminated by signal") ||
475
+ msg.includes("Failed to write to process stdin")
476
+ ) {
477
+ this.logger.error(`Process died: ${msg}`, {
478
+ sessionId: this.sessionId,
479
+ });
480
+ this.session.input.end();
481
+ throw RequestError.internalError(
482
+ undefined,
483
+ "The Claude Agent process exited unexpectedly. Please start a new session.",
484
+ );
485
+ }
486
+ throw error;
462
487
  } finally {
463
488
  if (!handedOff) {
464
489
  this.session.promptRunning = false;
@@ -704,6 +729,13 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
704
729
  }
705
730
  } catch (err) {
706
731
  settingsManager.dispose();
732
+ if (
733
+ isResume &&
734
+ err instanceof Error &&
735
+ err.message === "Query closed before response received"
736
+ ) {
737
+ throw RequestError.resourceNotFound(sessionId);
738
+ }
707
739
  this.logger.error(
708
740
  isResume
709
741
  ? forkSession
@@ -4,7 +4,7 @@ import type {
4
4
  SessionNotification,
5
5
  SessionUpdate,
6
6
  } from "@agentclientprotocol/sdk";
7
- import { RequestError } from "@agentclientprotocol/sdk";
7
+ import { RequestError, type StopReason } from "@agentclientprotocol/sdk";
8
8
  import type {
9
9
  SDKAssistantMessage,
10
10
  SDKMessage,
@@ -574,7 +574,7 @@ export async function handleSystemMessage(
574
574
 
575
575
  export type ResultMessageHandlerResult = {
576
576
  shouldStop: boolean;
577
- stopReason?: string;
577
+ stopReason?: StopReason;
578
578
  error?: Error;
579
579
  usage?: {
580
580
  inputTokens: number;
@@ -600,6 +600,9 @@ export function handleResultMessage(
600
600
  usage,
601
601
  };
602
602
  }
603
+ if ((message as Record<string, unknown>).stop_reason === "max_tokens") {
604
+ return { shouldStop: true, stopReason: "max_tokens", usage };
605
+ }
603
606
  if (message.is_error) {
604
607
  return {
605
608
  shouldStop: true,
@@ -610,6 +613,9 @@ export function handleResultMessage(
610
613
  return { shouldStop: true, stopReason: "end_turn", usage };
611
614
  }
612
615
  case "error_during_execution":
616
+ if ((message as Record<string, unknown>).stop_reason === "max_tokens") {
617
+ return { shouldStop: true, stopReason: "max_tokens", usage };
618
+ }
613
619
  if (message.is_error) {
614
620
  return {
615
621
  shouldStop: true,