@posthog/agent 2.3.202 → 2.3.207

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.3.202",
3
+ "version": "2.3.207",
4
4
  "repository": "https://github.com/PostHog/code",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -5,10 +5,6 @@
5
5
  * - Custom notification methods are prefixed with `_posthog/`
6
6
  * - Custom data can be attached via `_meta` fields
7
7
  *
8
- * Note: When using `extNotification()` from the ACP SDK, it automatically
9
- * adds an extra underscore prefix (e.g., `_posthog/tree_snapshot` becomes
10
- * `__posthog/tree_snapshot` in the log). Code that reads logs should handle both.
11
- *
12
8
  * See: https://agentclientprotocol.com/docs/extensibility
13
9
  */
14
10
 
@@ -68,3 +64,18 @@ export const POSTHOG_NOTIFICATIONS = {
68
64
  /** Token usage update for a session turn */
69
65
  USAGE_UPDATE: "_posthog/usage_update",
70
66
  } as const;
67
+
68
+ type NotificationMethod =
69
+ (typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS];
70
+
71
+ /**
72
+ * Check if an ACP method matches a PostHog notification, handling the
73
+ * possible `__posthog/` double-prefix from extNotification().
74
+ */
75
+ export function isNotification(
76
+ method: string | undefined,
77
+ notification: NotificationMethod,
78
+ ): boolean {
79
+ if (!method) return false;
80
+ return method === notification || method === `_${notification}`;
81
+ }
@@ -931,7 +931,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
931
931
  ),
932
932
  ...(meta?.taskRunId
933
933
  ? [
934
- this.client.extNotification("_posthog/sdk_session", {
934
+ this.client.extNotification(POSTHOG_NOTIFICATIONS.SDK_SESSION, {
935
935
  taskRunId: meta.taskRunId,
936
936
  sessionId,
937
937
  adapter: "claude",
@@ -17,6 +17,7 @@ import type {
17
17
  BetaContentBlock,
18
18
  BetaRawContentBlockDelta,
19
19
  } from "@anthropic-ai/sdk/resources/beta.mjs";
20
+ import { POSTHOG_NOTIFICATIONS } from "@/acp-extensions";
20
21
  import { image, text } from "../../../utils/acp-content";
21
22
  import { unreachable } from "../../../utils/common";
22
23
  import type { Logger } from "../../../utils/logger";
@@ -550,7 +551,7 @@ export async function handleSystemMessage(
550
551
  case "init":
551
552
  break;
552
553
  case "compact_boundary":
553
- await client.extNotification("_posthog/compact_boundary", {
554
+ await client.extNotification(POSTHOG_NOTIFICATIONS.COMPACT_BOUNDARY, {
554
555
  sessionId,
555
556
  trigger: message.compact_metadata.trigger,
556
557
  preTokens: message.compact_metadata.pre_tokens,
@@ -566,7 +567,7 @@ export async function handleSystemMessage(
566
567
  case "status":
567
568
  if (message.status === "compacting") {
568
569
  logger.info("Session compacting started", { sessionId });
569
- await client.extNotification("_posthog/status", {
570
+ await client.extNotification(POSTHOG_NOTIFICATIONS.STATUS, {
570
571
  sessionId,
571
572
  status: "compacting",
572
573
  });
@@ -579,7 +580,7 @@ export async function handleSystemMessage(
579
580
  status: message.status,
580
581
  summary: message.summary,
581
582
  });
582
- await client.extNotification("_posthog/task_notification", {
583
+ await client.extNotification(POSTHOG_NOTIFICATIONS.TASK_NOTIFICATION, {
583
584
  sessionId,
584
585
  taskId: message.task_id,
585
586
  status: message.status,
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { isNotification, POSTHOG_NOTIFICATIONS } from "./acp-extensions";
1
2
  export {
2
3
  getMcpToolMetadata,
3
4
  isMcpToolReadOnly,
@@ -441,35 +441,6 @@ describe("ResumeSaga", () => {
441
441
  expect(result.data.latestSnapshot?.treeHash).toBe("hash-2");
442
442
  });
443
443
 
444
- it("finds snapshot with SDK double-underscore prefix", async () => {
445
- (mockApiClient.getTaskRun as ReturnType<typeof vi.fn>).mockResolvedValue(
446
- createTaskRun(),
447
- );
448
- (
449
- mockApiClient.fetchTaskRunLogs as ReturnType<typeof vi.fn>
450
- ).mockResolvedValue([
451
- createNotification(`_${POSTHOG_NOTIFICATIONS.TREE_SNAPSHOT}`, {
452
- treeHash: "sdk-prefixed-hash",
453
- baseCommit: "abc",
454
- changes: [],
455
- timestamp: new Date().toISOString(),
456
- }),
457
- ]);
458
-
459
- const saga = new ResumeSaga(mockLogger);
460
- const result = await saga.run({
461
- taskId: "task-1",
462
- runId: "run-1",
463
- repositoryPath: repo.path,
464
- apiClient: mockApiClient,
465
- });
466
-
467
- expect(result.success).toBe(true);
468
- if (!result.success) return;
469
-
470
- expect(result.data.latestSnapshot?.treeHash).toBe("sdk-prefixed-hash");
471
- });
472
-
473
444
  it("returns interrupted flag from snapshot", async () => {
474
445
  (mockApiClient.getTaskRun as ReturnType<typeof vi.fn>).mockResolvedValue(
475
446
  createTaskRun(),
@@ -1,6 +1,6 @@
1
1
  import type { ContentBlock } from "@agentclientprotocol/sdk";
2
2
  import { Saga } from "@posthog/shared";
3
- import { POSTHOG_NOTIFICATIONS } from "../acp-extensions";
3
+ import { isNotification, POSTHOG_NOTIFICATIONS } from "../acp-extensions";
4
4
  import type { PostHogAPIClient } from "../posthog-api";
5
5
  import { TreeTracker } from "../tree-tracker";
6
6
  import type {
@@ -178,14 +178,13 @@ export class ResumeSaga extends Saga<ResumeInput, ResumeOutput> {
178
178
  private findLatestTreeSnapshot(
179
179
  entries: StoredNotification[],
180
180
  ): TreeSnapshotEvent | null {
181
- const sdkPrefixedMethod = `_${POSTHOG_NOTIFICATIONS.TREE_SNAPSHOT}`;
182
-
183
181
  for (let i = entries.length - 1; i >= 0; i--) {
184
182
  const entry = entries[i];
185
- const method = entry.notification?.method;
186
183
  if (
187
- method === sdkPrefixedMethod ||
188
- method === POSTHOG_NOTIFICATIONS.TREE_SNAPSHOT
184
+ isNotification(
185
+ entry.notification?.method,
186
+ POSTHOG_NOTIFICATIONS.TREE_SNAPSHOT,
187
+ )
189
188
  ) {
190
189
  const params = entry.notification.params as
191
190
  | TreeSnapshotEvent