@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/dist/agent.js +9 -1
- package/dist/agent.js.map +1 -1
- package/dist/logger-RC7sPv0S.d.ts +24 -0
- package/dist/posthog-api.js +9 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/resume.d.ts +69 -0
- package/dist/resume.js +6801 -0
- package/dist/resume.js.map +1 -0
- package/dist/server/agent-server.d.ts +0 -3
- package/dist/server/agent-server.js +81 -76
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +81 -76
- package/dist/server/bin.cjs.map +1 -1
- package/dist/tree-tracker.d.ts +67 -0
- package/dist/tree-tracker.js +6417 -0
- package/dist/tree-tracker.js.map +1 -0
- package/package.json +9 -1
- package/src/resume.ts +51 -0
- package/src/server/agent-server.ts +2 -56
|
@@ -80,9 +80,6 @@ declare class AgentServer {
|
|
|
80
80
|
private classifyAndSignalFailure;
|
|
81
81
|
private sendInitialTaskMessage;
|
|
82
82
|
private sendResumeMessage;
|
|
83
|
-
private static RESUME_HISTORY_TOKEN_BUDGET;
|
|
84
|
-
private static TOOL_RESULT_MAX_CHARS;
|
|
85
|
-
private formatConversationForResume;
|
|
86
83
|
private getInitialPromptOverride;
|
|
87
84
|
private getPendingUserPrompt;
|
|
88
85
|
private getClearedPendingUserState;
|
|
@@ -8605,7 +8605,7 @@ import { z as z4 } from "zod";
|
|
|
8605
8605
|
// package.json
|
|
8606
8606
|
var package_default = {
|
|
8607
8607
|
name: "@posthog/agent",
|
|
8608
|
-
version: "2.3.
|
|
8608
|
+
version: "2.3.386",
|
|
8609
8609
|
repository: "https://github.com/PostHog/code",
|
|
8610
8610
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8611
8611
|
exports: {
|
|
@@ -8661,6 +8661,14 @@ var package_default = {
|
|
|
8661
8661
|
types: "./dist/execution-mode.d.ts",
|
|
8662
8662
|
import: "./dist/execution-mode.js"
|
|
8663
8663
|
},
|
|
8664
|
+
"./resume": {
|
|
8665
|
+
types: "./dist/resume.d.ts",
|
|
8666
|
+
import: "./dist/resume.js"
|
|
8667
|
+
},
|
|
8668
|
+
"./tree-tracker": {
|
|
8669
|
+
types: "./dist/tree-tracker.d.ts",
|
|
8670
|
+
import: "./dist/tree-tracker.js"
|
|
8671
|
+
},
|
|
8664
8672
|
"./server": {
|
|
8665
8673
|
types: "./dist/server/agent-server.d.ts",
|
|
8666
8674
|
import: "./dist/server/agent-server.js"
|
|
@@ -18315,45 +18323,6 @@ function createCodexConnection(config) {
|
|
|
18315
18323
|
};
|
|
18316
18324
|
}
|
|
18317
18325
|
|
|
18318
|
-
// src/adapters/claude/session/jsonl-hydration.ts
|
|
18319
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
18320
|
-
import * as fs10 from "fs/promises";
|
|
18321
|
-
import * as os6 from "os";
|
|
18322
|
-
import * as path12 from "path";
|
|
18323
|
-
var CHARS_PER_TOKEN = 4;
|
|
18324
|
-
var DEFAULT_MAX_TOKENS = 15e4;
|
|
18325
|
-
function estimateTurnTokens(turn) {
|
|
18326
|
-
let chars = 0;
|
|
18327
|
-
for (const block of turn.content) {
|
|
18328
|
-
if ("text" in block && typeof block.text === "string") {
|
|
18329
|
-
chars += block.text.length;
|
|
18330
|
-
}
|
|
18331
|
-
}
|
|
18332
|
-
if (turn.toolCalls) {
|
|
18333
|
-
for (const tc of turn.toolCalls) {
|
|
18334
|
-
chars += JSON.stringify(tc.input ?? "").length;
|
|
18335
|
-
if (tc.result !== void 0) {
|
|
18336
|
-
chars += typeof tc.result === "string" ? tc.result.length : JSON.stringify(tc.result).length;
|
|
18337
|
-
}
|
|
18338
|
-
}
|
|
18339
|
-
}
|
|
18340
|
-
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
18341
|
-
}
|
|
18342
|
-
function selectRecentTurns(turns, maxTokens = DEFAULT_MAX_TOKENS) {
|
|
18343
|
-
let budget = maxTokens;
|
|
18344
|
-
let startIndex = turns.length;
|
|
18345
|
-
for (let i2 = turns.length - 1; i2 >= 0; i2--) {
|
|
18346
|
-
const cost = estimateTurnTokens(turns[i2]);
|
|
18347
|
-
if (cost > budget) break;
|
|
18348
|
-
budget -= cost;
|
|
18349
|
-
startIndex = i2;
|
|
18350
|
-
}
|
|
18351
|
-
while (startIndex < turns.length && turns[startIndex].role !== "user") {
|
|
18352
|
-
startIndex++;
|
|
18353
|
-
}
|
|
18354
|
-
return turns.slice(startIndex);
|
|
18355
|
-
}
|
|
18356
|
-
|
|
18357
18326
|
// src/utils/gateway.ts
|
|
18358
18327
|
function getGatewayBaseUrl(posthogHost) {
|
|
18359
18328
|
const url = new URL(posthogHost);
|
|
@@ -18555,6 +18524,45 @@ var PostHogAPIClient = class {
|
|
|
18555
18524
|
}
|
|
18556
18525
|
};
|
|
18557
18526
|
|
|
18527
|
+
// src/adapters/claude/session/jsonl-hydration.ts
|
|
18528
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
18529
|
+
import * as fs10 from "fs/promises";
|
|
18530
|
+
import * as os6 from "os";
|
|
18531
|
+
import * as path12 from "path";
|
|
18532
|
+
var CHARS_PER_TOKEN = 4;
|
|
18533
|
+
var DEFAULT_MAX_TOKENS = 15e4;
|
|
18534
|
+
function estimateTurnTokens(turn) {
|
|
18535
|
+
let chars = 0;
|
|
18536
|
+
for (const block of turn.content) {
|
|
18537
|
+
if ("text" in block && typeof block.text === "string") {
|
|
18538
|
+
chars += block.text.length;
|
|
18539
|
+
}
|
|
18540
|
+
}
|
|
18541
|
+
if (turn.toolCalls) {
|
|
18542
|
+
for (const tc of turn.toolCalls) {
|
|
18543
|
+
chars += JSON.stringify(tc.input ?? "").length;
|
|
18544
|
+
if (tc.result !== void 0) {
|
|
18545
|
+
chars += typeof tc.result === "string" ? tc.result.length : JSON.stringify(tc.result).length;
|
|
18546
|
+
}
|
|
18547
|
+
}
|
|
18548
|
+
}
|
|
18549
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
18550
|
+
}
|
|
18551
|
+
function selectRecentTurns(turns, maxTokens = DEFAULT_MAX_TOKENS) {
|
|
18552
|
+
let budget = maxTokens;
|
|
18553
|
+
let startIndex = turns.length;
|
|
18554
|
+
for (let i2 = turns.length - 1; i2 >= 0; i2--) {
|
|
18555
|
+
const cost = estimateTurnTokens(turns[i2]);
|
|
18556
|
+
if (cost > budget) break;
|
|
18557
|
+
budget -= cost;
|
|
18558
|
+
startIndex = i2;
|
|
18559
|
+
}
|
|
18560
|
+
while (startIndex < turns.length && turns[startIndex].role !== "user") {
|
|
18561
|
+
startIndex++;
|
|
18562
|
+
}
|
|
18563
|
+
return turns.slice(startIndex);
|
|
18564
|
+
}
|
|
18565
|
+
|
|
18558
18566
|
// ../shared/dist/index.js
|
|
18559
18567
|
var CLOUD_PROMPT_PREFIX = "__twig_cloud_prompt_v1__:";
|
|
18560
18568
|
function deserializeCloudPrompt(value) {
|
|
@@ -19524,6 +19532,37 @@ async function resumeFromLog(config) {
|
|
|
19524
19532
|
logEntryCount: result.data.logEntryCount
|
|
19525
19533
|
};
|
|
19526
19534
|
}
|
|
19535
|
+
var RESUME_HISTORY_TOKEN_BUDGET = 5e4;
|
|
19536
|
+
var TOOL_RESULT_MAX_CHARS = 2e3;
|
|
19537
|
+
function formatConversationForResume(conversation) {
|
|
19538
|
+
const selected = selectRecentTurns(conversation, RESUME_HISTORY_TOKEN_BUDGET);
|
|
19539
|
+
const parts2 = [];
|
|
19540
|
+
if (selected.length < conversation.length) {
|
|
19541
|
+
parts2.push(
|
|
19542
|
+
`*(${conversation.length - selected.length} earlier turns omitted)*`
|
|
19543
|
+
);
|
|
19544
|
+
}
|
|
19545
|
+
for (const turn of selected) {
|
|
19546
|
+
const role = turn.role === "user" ? "User" : "Assistant";
|
|
19547
|
+
const textParts = turn.content.filter((block) => block.type === "text").map((block) => block.text);
|
|
19548
|
+
if (textParts.length > 0) {
|
|
19549
|
+
parts2.push(`**${role}**: ${textParts.join("\n")}`);
|
|
19550
|
+
}
|
|
19551
|
+
if (turn.toolCalls?.length) {
|
|
19552
|
+
const toolSummary = turn.toolCalls.map((tc) => {
|
|
19553
|
+
let resultStr = "";
|
|
19554
|
+
if (tc.result !== void 0) {
|
|
19555
|
+
const raw = typeof tc.result === "string" ? tc.result : JSON.stringify(tc.result);
|
|
19556
|
+
resultStr = raw.length > TOOL_RESULT_MAX_CHARS ? ` \u2192 ${raw.substring(0, TOOL_RESULT_MAX_CHARS)}...(truncated)` : ` \u2192 ${raw}`;
|
|
19557
|
+
}
|
|
19558
|
+
return ` - ${tc.toolName}${resultStr}`;
|
|
19559
|
+
}).join("\n");
|
|
19560
|
+
parts2.push(`**${role} (tools)**:
|
|
19561
|
+
${toolSummary}`);
|
|
19562
|
+
}
|
|
19563
|
+
}
|
|
19564
|
+
return parts2.join("\n\n");
|
|
19565
|
+
}
|
|
19527
19566
|
|
|
19528
19567
|
// src/session-log-writer.ts
|
|
19529
19568
|
import fs12 from "fs";
|
|
@@ -20109,7 +20148,7 @@ function getTaskRunStateString(taskRun, key) {
|
|
|
20109
20148
|
const value = state[key];
|
|
20110
20149
|
return typeof value === "string" ? value : null;
|
|
20111
20150
|
}
|
|
20112
|
-
var AgentServer = class
|
|
20151
|
+
var AgentServer = class {
|
|
20113
20152
|
config;
|
|
20114
20153
|
logger;
|
|
20115
20154
|
server = null;
|
|
@@ -20834,7 +20873,7 @@ var AgentServer = class _AgentServer {
|
|
|
20834
20873
|
async sendResumeMessage(payload, taskRun) {
|
|
20835
20874
|
if (!this.session || !this.resumeState) return;
|
|
20836
20875
|
try {
|
|
20837
|
-
const conversationSummary =
|
|
20876
|
+
const conversationSummary = formatConversationForResume(
|
|
20838
20877
|
this.resumeState.conversation
|
|
20839
20878
|
);
|
|
20840
20879
|
const pendingUserPrompt = await this.getPendingUserPrompt(taskRun);
|
|
@@ -20905,40 +20944,6 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
20905
20944
|
await this.classifyAndSignalFailure(payload, "resume", error);
|
|
20906
20945
|
}
|
|
20907
20946
|
}
|
|
20908
|
-
static RESUME_HISTORY_TOKEN_BUDGET = 5e4;
|
|
20909
|
-
static TOOL_RESULT_MAX_CHARS = 2e3;
|
|
20910
|
-
formatConversationForResume(conversation) {
|
|
20911
|
-
const selected = selectRecentTurns(
|
|
20912
|
-
conversation,
|
|
20913
|
-
_AgentServer.RESUME_HISTORY_TOKEN_BUDGET
|
|
20914
|
-
);
|
|
20915
|
-
const parts2 = [];
|
|
20916
|
-
if (selected.length < conversation.length) {
|
|
20917
|
-
parts2.push(
|
|
20918
|
-
`*(${conversation.length - selected.length} earlier turns omitted)*`
|
|
20919
|
-
);
|
|
20920
|
-
}
|
|
20921
|
-
for (const turn of selected) {
|
|
20922
|
-
const role = turn.role === "user" ? "User" : "Assistant";
|
|
20923
|
-
const textParts = turn.content.filter((block) => block.type === "text").map((block) => block.text);
|
|
20924
|
-
if (textParts.length > 0) {
|
|
20925
|
-
parts2.push(`**${role}**: ${textParts.join("\n")}`);
|
|
20926
|
-
}
|
|
20927
|
-
if (turn.toolCalls?.length) {
|
|
20928
|
-
const toolSummary = turn.toolCalls.map((tc) => {
|
|
20929
|
-
let resultStr = "";
|
|
20930
|
-
if (tc.result !== void 0) {
|
|
20931
|
-
const raw = typeof tc.result === "string" ? tc.result : JSON.stringify(tc.result);
|
|
20932
|
-
resultStr = raw.length > _AgentServer.TOOL_RESULT_MAX_CHARS ? ` \u2192 ${raw.substring(0, _AgentServer.TOOL_RESULT_MAX_CHARS)}...(truncated)` : ` \u2192 ${raw}`;
|
|
20933
|
-
}
|
|
20934
|
-
return ` - ${tc.toolName}${resultStr}`;
|
|
20935
|
-
}).join("\n");
|
|
20936
|
-
parts2.push(`**${role} (tools)**:
|
|
20937
|
-
${toolSummary}`);
|
|
20938
|
-
}
|
|
20939
|
-
}
|
|
20940
|
-
return parts2.join("\n\n");
|
|
20941
|
-
}
|
|
20942
20947
|
getInitialPromptOverride(taskRun) {
|
|
20943
20948
|
const state = taskRun.state;
|
|
20944
20949
|
const override = state?.initial_prompt_override;
|