@posthog/agent 2.3.187 → 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/dist/adapters/claude/conversion/tool-use-to-acp.js +9 -1
- package/dist/adapters/claude/conversion/tool-use-to-acp.js.map +1 -1
- package/dist/agent.js +18 -7
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +45 -1
- package/dist/index.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +26 -10
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +26 -10
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/acp-extensions.ts +15 -4
- package/src/adapters/claude/claude-agent.ts +1 -1
- package/src/adapters/claude/conversion/sdk-to-acp.ts +4 -3
- package/src/adapters/claude/conversion/tool-use-to-acp.ts +11 -3
- package/src/adapters/claude/permissions/permission-handlers.ts +4 -1
- package/src/index.ts +1 -0
- package/src/sagas/resume-saga.test.ts +0 -29
- package/src/sagas/resume-saga.ts +5 -6
package/package.json
CHANGED
package/src/acp-extensions.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
583
|
+
await client.extNotification(POSTHOG_NOTIFICATIONS.TASK_NOTIFICATION, {
|
|
583
584
|
sessionId,
|
|
584
585
|
taskId: message.task_id,
|
|
585
586
|
status: message.status,
|
|
@@ -226,11 +226,19 @@ export function toolInfoFromToolUse(
|
|
|
226
226
|
: undefined;
|
|
227
227
|
const contentStr = input?.content ? String(input.content) : undefined;
|
|
228
228
|
if (writeFilePath) {
|
|
229
|
-
|
|
229
|
+
let oldContent: string | null = null;
|
|
230
|
+
if (
|
|
230
231
|
options?.cachedFileContent &&
|
|
231
232
|
writeFilePath in options.cachedFileContent
|
|
232
|
-
|
|
233
|
-
|
|
233
|
+
) {
|
|
234
|
+
oldContent = options.cachedFileContent[writeFilePath];
|
|
235
|
+
} else {
|
|
236
|
+
try {
|
|
237
|
+
oldContent = fs.readFileSync(writeFilePath, "utf-8");
|
|
238
|
+
} catch {
|
|
239
|
+
// File doesn't exist — genuinely a new file
|
|
240
|
+
}
|
|
241
|
+
}
|
|
234
242
|
contentResult = toolContent()
|
|
235
243
|
.diff(writeFilePath, oldContent, contentStr ?? "")
|
|
236
244
|
.build();
|
|
@@ -338,7 +338,10 @@ async function handleDefaultPermissionFlow(
|
|
|
338
338
|
suggestions,
|
|
339
339
|
} = context;
|
|
340
340
|
|
|
341
|
-
const toolInfo = toolInfoFromToolUse(
|
|
341
|
+
const toolInfo = toolInfoFromToolUse(
|
|
342
|
+
{ name: toolName, input: toolInput },
|
|
343
|
+
{ cachedFileContent: context.fileContentCache, cwd: session?.cwd },
|
|
344
|
+
);
|
|
342
345
|
|
|
343
346
|
const options = buildPermissionOptions(
|
|
344
347
|
toolName,
|
package/src/index.ts
CHANGED
|
@@ -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(),
|
package/src/sagas/resume-saga.ts
CHANGED
|
@@ -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
|
-
|
|
188
|
-
|
|
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
|