@posthog/agent 2.1.156 → 2.1.167
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 +33 -10
- package/dist/agent.js.map +1 -1
- package/dist/claude-cli/cli.js +1590 -1590
- package/dist/posthog-api.js +2 -2
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.d.ts +1 -0
- package/dist/server/agent-server.js +34 -11
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +37 -13
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +2 -2
- package/src/adapters/claude/UPSTREAM.md +3 -3
- package/src/adapters/claude/claude-agent.ts +40 -8
- package/src/adapters/claude/conversion/sdk-to-acp.ts +8 -2
- package/src/server/agent-server.test.ts +28 -0
- package/src/server/agent-server.ts +1 -1
- package/src/server/bin.ts +2 -0
- package/src/server/types.ts +1 -0
package/dist/server/bin.cjs
CHANGED
|
@@ -904,7 +904,7 @@ var import_hono = require("hono");
|
|
|
904
904
|
// package.json
|
|
905
905
|
var package_default = {
|
|
906
906
|
name: "@posthog/agent",
|
|
907
|
-
version: "2.1.
|
|
907
|
+
version: "2.1.167",
|
|
908
908
|
repository: "https://github.com/PostHog/twig",
|
|
909
909
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
910
910
|
exports: {
|
|
@@ -992,7 +992,7 @@ var package_default = {
|
|
|
992
992
|
},
|
|
993
993
|
dependencies: {
|
|
994
994
|
"@agentclientprotocol/sdk": "^0.14.0",
|
|
995
|
-
"@anthropic-ai/claude-agent-sdk": "0.2.
|
|
995
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.68",
|
|
996
996
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
997
997
|
"@hono/node-server": "^1.19.9",
|
|
998
998
|
"@opentelemetry/api-logs": "^0.208.0",
|
|
@@ -2632,6 +2632,9 @@ function handleResultMessage(message) {
|
|
|
2632
2632
|
usage
|
|
2633
2633
|
};
|
|
2634
2634
|
}
|
|
2635
|
+
if (message.stop_reason === "max_tokens") {
|
|
2636
|
+
return { shouldStop: true, stopReason: "max_tokens", usage };
|
|
2637
|
+
}
|
|
2635
2638
|
if (message.is_error) {
|
|
2636
2639
|
return {
|
|
2637
2640
|
shouldStop: true,
|
|
@@ -2642,6 +2645,9 @@ function handleResultMessage(message) {
|
|
|
2642
2645
|
return { shouldStop: true, stopReason: "end_turn", usage };
|
|
2643
2646
|
}
|
|
2644
2647
|
case "error_during_execution":
|
|
2648
|
+
if (message.stop_reason === "max_tokens") {
|
|
2649
|
+
return { shouldStop: true, stopReason: "max_tokens", usage };
|
|
2650
|
+
}
|
|
2645
2651
|
if (message.is_error) {
|
|
2646
2652
|
return {
|
|
2647
2653
|
shouldStop: true,
|
|
@@ -4104,14 +4110,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
4104
4110
|
};
|
|
4105
4111
|
const result = handleResultMessage(message);
|
|
4106
4112
|
if (result.error) throw result.error;
|
|
4107
|
-
|
|
4108
|
-
case "error_max_budget_usd":
|
|
4109
|
-
case "error_max_turns":
|
|
4110
|
-
case "error_max_structured_output_retries":
|
|
4111
|
-
return { stopReason: "max_turn_requests", usage };
|
|
4112
|
-
default:
|
|
4113
|
-
return { stopReason: "end_turn", usage };
|
|
4114
|
-
}
|
|
4113
|
+
return { stopReason: result.stopReason ?? "end_turn", usage };
|
|
4115
4114
|
}
|
|
4116
4115
|
case "stream_event":
|
|
4117
4116
|
await handleStreamEvent(message, context);
|
|
@@ -4132,6 +4131,9 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
4132
4131
|
return { stopReason: "end_turn" };
|
|
4133
4132
|
}
|
|
4134
4133
|
}
|
|
4134
|
+
if ("isReplay" in message && message.isReplay) {
|
|
4135
|
+
break;
|
|
4136
|
+
}
|
|
4135
4137
|
if ("usage" in message.message && message.parent_tool_use_id === null) {
|
|
4136
4138
|
const usage = message.message.usage;
|
|
4137
4139
|
lastAssistantTotalUsage = usage.input_tokens + usage.output_tokens + usage.cache_read_input_tokens + usage.cache_creation_input_tokens;
|
|
@@ -4146,6 +4148,8 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
4146
4148
|
case "tool_progress":
|
|
4147
4149
|
case "auth_status":
|
|
4148
4150
|
case "tool_use_summary":
|
|
4151
|
+
case "prompt_suggestion":
|
|
4152
|
+
case "rate_limit_event":
|
|
4149
4153
|
break;
|
|
4150
4154
|
default:
|
|
4151
4155
|
unreachable(message, this.logger);
|
|
@@ -4153,6 +4157,22 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
4153
4157
|
}
|
|
4154
4158
|
}
|
|
4155
4159
|
throw new Error("Session did not end in result");
|
|
4160
|
+
} catch (error) {
|
|
4161
|
+
if (error instanceof import_sdk2.RequestError || !(error instanceof Error)) {
|
|
4162
|
+
throw error;
|
|
4163
|
+
}
|
|
4164
|
+
const msg = error.message;
|
|
4165
|
+
if (msg.includes("ProcessTransport") || msg.includes("terminated process") || msg.includes("process exited with") || msg.includes("process terminated by signal") || msg.includes("Failed to write to process stdin")) {
|
|
4166
|
+
this.logger.error(`Process died: ${msg}`, {
|
|
4167
|
+
sessionId: this.sessionId
|
|
4168
|
+
});
|
|
4169
|
+
this.session.input.end();
|
|
4170
|
+
throw import_sdk2.RequestError.internalError(
|
|
4171
|
+
void 0,
|
|
4172
|
+
"The Claude Agent process exited unexpectedly. Please start a new session."
|
|
4173
|
+
);
|
|
4174
|
+
}
|
|
4175
|
+
throw error;
|
|
4156
4176
|
} finally {
|
|
4157
4177
|
if (!handedOff) {
|
|
4158
4178
|
this.session.promptRunning = false;
|
|
@@ -4336,6 +4356,9 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
4336
4356
|
}
|
|
4337
4357
|
} catch (err) {
|
|
4338
4358
|
settingsManager.dispose();
|
|
4359
|
+
if (isResume && err instanceof Error && err.message === "Query closed before response received") {
|
|
4360
|
+
throw import_sdk2.RequestError.resourceNotFound(sessionId);
|
|
4361
|
+
}
|
|
4339
4362
|
this.logger.error(
|
|
4340
4363
|
isResume ? forkSession ? "Session fork failed" : "Session resumption failed" : "Session initialization failed",
|
|
4341
4364
|
{
|
|
@@ -11552,7 +11575,7 @@ After completing the requested changes:
|
|
|
11552
11575
|
1. Create a new branch with a descriptive name based on the work done
|
|
11553
11576
|
2. Stage and commit all changes with a clear commit message
|
|
11554
11577
|
3. Push the branch to origin
|
|
11555
|
-
4. Create a draft pull request using \`gh pr create --draft\` with a descriptive title and body
|
|
11578
|
+
4. Create a draft pull request using \`gh pr create --draft${this.config.baseBranch ? ` --base ${this.config.baseBranch}` : ""}\` with a descriptive title and body
|
|
11556
11579
|
|
|
11557
11580
|
Important:
|
|
11558
11581
|
- Always create the PR as a draft. Do not ask for confirmation.
|
|
@@ -11898,7 +11921,7 @@ program.name("agent-server").description("PostHog cloud agent server - runs in s
|
|
|
11898
11921
|
).requiredOption("--repositoryPath <path>", "Path to the repository").requiredOption("--taskId <id>", "Task ID").requiredOption("--runId <id>", "Task run ID").option(
|
|
11899
11922
|
"--mcpServers <json>",
|
|
11900
11923
|
"MCP servers config as JSON array (ACP McpServer[] format)"
|
|
11901
|
-
).action(async (options) => {
|
|
11924
|
+
).option("--baseBranch <branch>", "Base branch for PR creation").action(async (options) => {
|
|
11902
11925
|
const envResult = envSchema.safeParse(process.env);
|
|
11903
11926
|
if (!envResult.success) {
|
|
11904
11927
|
const errors = envResult.error.issues.map((issue) => ` - ${issue.message}`).join("\n");
|
|
@@ -11938,7 +11961,8 @@ ${errors}`
|
|
|
11938
11961
|
mode,
|
|
11939
11962
|
taskId: options.taskId,
|
|
11940
11963
|
runId: options.runId,
|
|
11941
|
-
mcpServers
|
|
11964
|
+
mcpServers,
|
|
11965
|
+
baseBranch: options.baseBranch
|
|
11942
11966
|
});
|
|
11943
11967
|
process.on("SIGINT", async () => {
|
|
11944
11968
|
await server.stop();
|