@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.
@@ -8729,7 +8729,7 @@ var import_zod3 = require("zod");
8729
8729
  // package.json
8730
8730
  var package_default = {
8731
8731
  name: "@posthog/agent",
8732
- version: "2.3.385",
8732
+ version: "2.3.386",
8733
8733
  repository: "https://github.com/PostHog/code",
8734
8734
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8735
8735
  exports: {
@@ -8785,6 +8785,14 @@ var package_default = {
8785
8785
  types: "./dist/execution-mode.d.ts",
8786
8786
  import: "./dist/execution-mode.js"
8787
8787
  },
8788
+ "./resume": {
8789
+ types: "./dist/resume.d.ts",
8790
+ import: "./dist/resume.js"
8791
+ },
8792
+ "./tree-tracker": {
8793
+ types: "./dist/tree-tracker.d.ts",
8794
+ import: "./dist/tree-tracker.js"
8795
+ },
8788
8796
  "./server": {
8789
8797
  types: "./dist/server/agent-server.d.ts",
8790
8798
  import: "./dist/server/agent-server.js"
@@ -18323,45 +18331,6 @@ function createCodexConnection(config) {
18323
18331
  };
18324
18332
  }
18325
18333
 
18326
- // src/adapters/claude/session/jsonl-hydration.ts
18327
- var import_node_crypto2 = require("crypto");
18328
- var fs10 = __toESM(require("fs/promises"), 1);
18329
- var os6 = __toESM(require("os"), 1);
18330
- var path12 = __toESM(require("path"), 1);
18331
- var CHARS_PER_TOKEN = 4;
18332
- var DEFAULT_MAX_TOKENS = 15e4;
18333
- function estimateTurnTokens(turn) {
18334
- let chars = 0;
18335
- for (const block of turn.content) {
18336
- if ("text" in block && typeof block.text === "string") {
18337
- chars += block.text.length;
18338
- }
18339
- }
18340
- if (turn.toolCalls) {
18341
- for (const tc of turn.toolCalls) {
18342
- chars += JSON.stringify(tc.input ?? "").length;
18343
- if (tc.result !== void 0) {
18344
- chars += typeof tc.result === "string" ? tc.result.length : JSON.stringify(tc.result).length;
18345
- }
18346
- }
18347
- }
18348
- return Math.ceil(chars / CHARS_PER_TOKEN);
18349
- }
18350
- function selectRecentTurns(turns, maxTokens = DEFAULT_MAX_TOKENS) {
18351
- let budget = maxTokens;
18352
- let startIndex = turns.length;
18353
- for (let i2 = turns.length - 1; i2 >= 0; i2--) {
18354
- const cost = estimateTurnTokens(turns[i2]);
18355
- if (cost > budget) break;
18356
- budget -= cost;
18357
- startIndex = i2;
18358
- }
18359
- while (startIndex < turns.length && turns[startIndex].role !== "user") {
18360
- startIndex++;
18361
- }
18362
- return turns.slice(startIndex);
18363
- }
18364
-
18365
18334
  // src/utils/gateway.ts
18366
18335
  function getGatewayBaseUrl(posthogHost) {
18367
18336
  const url = new URL(posthogHost);
@@ -18563,6 +18532,45 @@ var PostHogAPIClient = class {
18563
18532
  }
18564
18533
  };
18565
18534
 
18535
+ // src/adapters/claude/session/jsonl-hydration.ts
18536
+ var import_node_crypto2 = require("crypto");
18537
+ var fs10 = __toESM(require("fs/promises"), 1);
18538
+ var os6 = __toESM(require("os"), 1);
18539
+ var path12 = __toESM(require("path"), 1);
18540
+ var CHARS_PER_TOKEN = 4;
18541
+ var DEFAULT_MAX_TOKENS = 15e4;
18542
+ function estimateTurnTokens(turn) {
18543
+ let chars = 0;
18544
+ for (const block of turn.content) {
18545
+ if ("text" in block && typeof block.text === "string") {
18546
+ chars += block.text.length;
18547
+ }
18548
+ }
18549
+ if (turn.toolCalls) {
18550
+ for (const tc of turn.toolCalls) {
18551
+ chars += JSON.stringify(tc.input ?? "").length;
18552
+ if (tc.result !== void 0) {
18553
+ chars += typeof tc.result === "string" ? tc.result.length : JSON.stringify(tc.result).length;
18554
+ }
18555
+ }
18556
+ }
18557
+ return Math.ceil(chars / CHARS_PER_TOKEN);
18558
+ }
18559
+ function selectRecentTurns(turns, maxTokens = DEFAULT_MAX_TOKENS) {
18560
+ let budget = maxTokens;
18561
+ let startIndex = turns.length;
18562
+ for (let i2 = turns.length - 1; i2 >= 0; i2--) {
18563
+ const cost = estimateTurnTokens(turns[i2]);
18564
+ if (cost > budget) break;
18565
+ budget -= cost;
18566
+ startIndex = i2;
18567
+ }
18568
+ while (startIndex < turns.length && turns[startIndex].role !== "user") {
18569
+ startIndex++;
18570
+ }
18571
+ return turns.slice(startIndex);
18572
+ }
18573
+
18566
18574
  // ../shared/dist/index.js
18567
18575
  var CLOUD_PROMPT_PREFIX = "__twig_cloud_prompt_v1__:";
18568
18576
  function deserializeCloudPrompt(value) {
@@ -19532,6 +19540,37 @@ async function resumeFromLog(config) {
19532
19540
  logEntryCount: result.data.logEntryCount
19533
19541
  };
19534
19542
  }
19543
+ var RESUME_HISTORY_TOKEN_BUDGET = 5e4;
19544
+ var TOOL_RESULT_MAX_CHARS = 2e3;
19545
+ function formatConversationForResume(conversation) {
19546
+ const selected = selectRecentTurns(conversation, RESUME_HISTORY_TOKEN_BUDGET);
19547
+ const parts2 = [];
19548
+ if (selected.length < conversation.length) {
19549
+ parts2.push(
19550
+ `*(${conversation.length - selected.length} earlier turns omitted)*`
19551
+ );
19552
+ }
19553
+ for (const turn of selected) {
19554
+ const role = turn.role === "user" ? "User" : "Assistant";
19555
+ const textParts = turn.content.filter((block) => block.type === "text").map((block) => block.text);
19556
+ if (textParts.length > 0) {
19557
+ parts2.push(`**${role}**: ${textParts.join("\n")}`);
19558
+ }
19559
+ if (turn.toolCalls?.length) {
19560
+ const toolSummary = turn.toolCalls.map((tc) => {
19561
+ let resultStr = "";
19562
+ if (tc.result !== void 0) {
19563
+ const raw = typeof tc.result === "string" ? tc.result : JSON.stringify(tc.result);
19564
+ resultStr = raw.length > TOOL_RESULT_MAX_CHARS ? ` \u2192 ${raw.substring(0, TOOL_RESULT_MAX_CHARS)}...(truncated)` : ` \u2192 ${raw}`;
19565
+ }
19566
+ return ` - ${tc.toolName}${resultStr}`;
19567
+ }).join("\n");
19568
+ parts2.push(`**${role} (tools)**:
19569
+ ${toolSummary}`);
19570
+ }
19571
+ }
19572
+ return parts2.join("\n\n");
19573
+ }
19535
19574
 
19536
19575
  // src/session-log-writer.ts
19537
19576
  var import_node_fs5 = __toESM(require("fs"), 1);
@@ -20117,7 +20156,7 @@ function getTaskRunStateString(taskRun, key) {
20117
20156
  const value = state[key];
20118
20157
  return typeof value === "string" ? value : null;
20119
20158
  }
20120
- var AgentServer = class _AgentServer {
20159
+ var AgentServer = class {
20121
20160
  config;
20122
20161
  logger;
20123
20162
  server = null;
@@ -20842,7 +20881,7 @@ var AgentServer = class _AgentServer {
20842
20881
  async sendResumeMessage(payload, taskRun) {
20843
20882
  if (!this.session || !this.resumeState) return;
20844
20883
  try {
20845
- const conversationSummary = this.formatConversationForResume(
20884
+ const conversationSummary = formatConversationForResume(
20846
20885
  this.resumeState.conversation
20847
20886
  );
20848
20887
  const pendingUserPrompt = await this.getPendingUserPrompt(taskRun);
@@ -20913,40 +20952,6 @@ Continue from where you left off. The user is waiting for your response.`
20913
20952
  await this.classifyAndSignalFailure(payload, "resume", error);
20914
20953
  }
20915
20954
  }
20916
- static RESUME_HISTORY_TOKEN_BUDGET = 5e4;
20917
- static TOOL_RESULT_MAX_CHARS = 2e3;
20918
- formatConversationForResume(conversation) {
20919
- const selected = selectRecentTurns(
20920
- conversation,
20921
- _AgentServer.RESUME_HISTORY_TOKEN_BUDGET
20922
- );
20923
- const parts2 = [];
20924
- if (selected.length < conversation.length) {
20925
- parts2.push(
20926
- `*(${conversation.length - selected.length} earlier turns omitted)*`
20927
- );
20928
- }
20929
- for (const turn of selected) {
20930
- const role = turn.role === "user" ? "User" : "Assistant";
20931
- const textParts = turn.content.filter((block) => block.type === "text").map((block) => block.text);
20932
- if (textParts.length > 0) {
20933
- parts2.push(`**${role}**: ${textParts.join("\n")}`);
20934
- }
20935
- if (turn.toolCalls?.length) {
20936
- const toolSummary = turn.toolCalls.map((tc) => {
20937
- let resultStr = "";
20938
- if (tc.result !== void 0) {
20939
- const raw = typeof tc.result === "string" ? tc.result : JSON.stringify(tc.result);
20940
- resultStr = raw.length > _AgentServer.TOOL_RESULT_MAX_CHARS ? ` \u2192 ${raw.substring(0, _AgentServer.TOOL_RESULT_MAX_CHARS)}...(truncated)` : ` \u2192 ${raw}`;
20941
- }
20942
- return ` - ${tc.toolName}${resultStr}`;
20943
- }).join("\n");
20944
- parts2.push(`**${role} (tools)**:
20945
- ${toolSummary}`);
20946
- }
20947
- }
20948
- return parts2.join("\n\n");
20949
- }
20950
20955
  getInitialPromptOverride(taskRun) {
20951
20956
  const state = taskRun.state;
20952
20957
  const override = state?.initial_prompt_override;