@posthog/agent 2.3.385 → 2.3.386

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.385",
3
+ "version": "2.3.386",
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": {
@@ -56,6 +56,14 @@
56
56
  "types": "./dist/execution-mode.d.ts",
57
57
  "import": "./dist/execution-mode.js"
58
58
  },
59
+ "./resume": {
60
+ "types": "./dist/resume.d.ts",
61
+ "import": "./dist/resume.js"
62
+ },
63
+ "./tree-tracker": {
64
+ "types": "./dist/tree-tracker.d.ts",
65
+ "import": "./dist/tree-tracker.js"
66
+ },
59
67
  "./server": {
60
68
  "types": "./dist/server/agent-server.d.ts",
61
69
  "import": "./dist/server/agent-server.js"
package/src/resume.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import type { ContentBlock } from "@agentclientprotocol/sdk";
19
+ import { selectRecentTurns } from "./adapters/claude/session/jsonl-hydration";
19
20
  import type { PostHogAPIClient } from "./posthog-api";
20
21
  import { ResumeSaga } from "./sagas/resume-saga";
21
22
  import type { DeviceInfo, TreeSnapshotEvent } from "./types";
@@ -113,3 +114,53 @@ export function conversationToPromptHistory(
113
114
  content: turn.content,
114
115
  }));
115
116
  }
117
+
118
+ const RESUME_HISTORY_TOKEN_BUDGET = 50_000;
119
+ const TOOL_RESULT_MAX_CHARS = 2000;
120
+
121
+ export function formatConversationForResume(
122
+ conversation: ConversationTurn[],
123
+ ): string {
124
+ const selected = selectRecentTurns(conversation, RESUME_HISTORY_TOKEN_BUDGET);
125
+ const parts: string[] = [];
126
+
127
+ if (selected.length < conversation.length) {
128
+ parts.push(
129
+ `*(${conversation.length - selected.length} earlier turns omitted)*`,
130
+ );
131
+ }
132
+
133
+ for (const turn of selected) {
134
+ const role = turn.role === "user" ? "User" : "Assistant";
135
+
136
+ const textParts = turn.content
137
+ .filter((block) => block.type === "text")
138
+ .map((block) => (block as { type: "text"; text: string }).text);
139
+
140
+ if (textParts.length > 0) {
141
+ parts.push(`**${role}**: ${textParts.join("\n")}`);
142
+ }
143
+
144
+ if (turn.toolCalls?.length) {
145
+ const toolSummary = turn.toolCalls
146
+ .map((tc) => {
147
+ let resultStr = "";
148
+ if (tc.result !== undefined) {
149
+ const raw =
150
+ typeof tc.result === "string"
151
+ ? tc.result
152
+ : JSON.stringify(tc.result);
153
+ resultStr =
154
+ raw.length > TOOL_RESULT_MAX_CHARS
155
+ ? ` → ${raw.substring(0, TOOL_RESULT_MAX_CHARS)}...(truncated)`
156
+ : ` → ${raw}`;
157
+ }
158
+ return ` - ${tc.toolName}${resultStr}`;
159
+ })
160
+ .join("\n");
161
+ parts.push(`**${role} (tools)**:\n${toolSummary}`);
162
+ }
163
+ }
164
+
165
+ return parts.join("\n\n");
166
+ }
@@ -25,12 +25,11 @@ import {
25
25
  type AgentErrorClassification,
26
26
  classifyAgentError,
27
27
  } from "../adapters/claude/conversion/sdk-to-acp";
28
- import { selectRecentTurns } from "../adapters/claude/session/jsonl-hydration";
29
28
  import type { PermissionMode } from "../execution-mode";
30
29
  import { DEFAULT_CODEX_MODEL } from "../gateway-models";
31
30
  import { PostHogAPIClient } from "../posthog-api";
32
31
  import {
33
- type ConversationTurn,
32
+ formatConversationForResume,
34
33
  type ResumeState,
35
34
  resumeFromLog,
36
35
  } from "../resume";
@@ -1147,7 +1146,7 @@ export class AgentServer {
1147
1146
  if (!this.session || !this.resumeState) return;
1148
1147
 
1149
1148
  try {
1150
- const conversationSummary = this.formatConversationForResume(
1149
+ const conversationSummary = formatConversationForResume(
1151
1150
  this.resumeState.conversation,
1152
1151
  );
1153
1152
 
@@ -1229,59 +1228,6 @@ export class AgentServer {
1229
1228
  }
1230
1229
  }
1231
1230
 
1232
- private static RESUME_HISTORY_TOKEN_BUDGET = 50_000;
1233
- private static TOOL_RESULT_MAX_CHARS = 2000;
1234
-
1235
- private formatConversationForResume(
1236
- conversation: ConversationTurn[],
1237
- ): string {
1238
- const selected = selectRecentTurns(
1239
- conversation,
1240
- AgentServer.RESUME_HISTORY_TOKEN_BUDGET,
1241
- );
1242
- const parts: string[] = [];
1243
-
1244
- if (selected.length < conversation.length) {
1245
- parts.push(
1246
- `*(${conversation.length - selected.length} earlier turns omitted)*`,
1247
- );
1248
- }
1249
-
1250
- for (const turn of selected) {
1251
- const role = turn.role === "user" ? "User" : "Assistant";
1252
-
1253
- const textParts = turn.content
1254
- .filter((block) => block.type === "text")
1255
- .map((block) => (block as { type: "text"; text: string }).text);
1256
-
1257
- if (textParts.length > 0) {
1258
- parts.push(`**${role}**: ${textParts.join("\n")}`);
1259
- }
1260
-
1261
- if (turn.toolCalls?.length) {
1262
- const toolSummary = turn.toolCalls
1263
- .map((tc) => {
1264
- let resultStr = "";
1265
- if (tc.result !== undefined) {
1266
- const raw =
1267
- typeof tc.result === "string"
1268
- ? tc.result
1269
- : JSON.stringify(tc.result);
1270
- resultStr =
1271
- raw.length > AgentServer.TOOL_RESULT_MAX_CHARS
1272
- ? ` → ${raw.substring(0, AgentServer.TOOL_RESULT_MAX_CHARS)}...(truncated)`
1273
- : ` → ${raw}`;
1274
- }
1275
- return ` - ${tc.toolName}${resultStr}`;
1276
- })
1277
- .join("\n");
1278
- parts.push(`**${role} (tools)**:\n${toolSummary}`);
1279
- }
1280
- }
1281
-
1282
- return parts.join("\n\n");
1283
- }
1284
-
1285
1231
  private getInitialPromptOverride(taskRun: TaskRun): string | null {
1286
1232
  const state = taskRun.state as Record<string, unknown> | undefined;
1287
1233
  const override = state?.initial_prompt_override;