@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.167",
|
|
4
4
|
"repository": "https://github.com/PostHog/twig",
|
|
5
5
|
"description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
6
6
|
"exports": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@agentclientprotocol/sdk": "^0.14.0",
|
|
82
|
-
"@anthropic-ai/claude-agent-sdk": "0.2.
|
|
82
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.68",
|
|
83
83
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
84
84
|
"@hono/node-server": "^1.19.9",
|
|
85
85
|
"@opentelemetry/api-logs": "^0.208.0",
|
|
@@ -5,8 +5,8 @@ Fork of `@anthropic-ai/claude-agent-acp`. Upstream repo: https://github.com/anth
|
|
|
5
5
|
## Fork Point
|
|
6
6
|
|
|
7
7
|
- **Forked**: v0.10.9, commit `5411e0f4`, Dec 2 2025
|
|
8
|
-
- **Last sync**: v0.
|
|
9
|
-
- **SDK**: `@anthropic-ai/claude-agent-sdk` 0.2.
|
|
8
|
+
- **Last sync**: v0.20.2, commit `dd9fe3a98ea494ba1982516f8aa0464b48fdd5e1`, March 6 2026
|
|
9
|
+
- **SDK**: `@anthropic-ai/claude-agent-sdk` 0.2.68, `@agentclientprotocol/sdk` ^0.14.0
|
|
10
10
|
|
|
11
11
|
## File Mapping
|
|
12
12
|
|
|
@@ -55,7 +55,7 @@ Fork of `@anthropic-ai/claude-agent-acp`. Upstream repo: https://github.com/anth
|
|
|
55
55
|
|
|
56
56
|
## Next Sync
|
|
57
57
|
|
|
58
|
-
1. Check upstream changelog since v0.
|
|
58
|
+
1. Check upstream changelog since v0.20.2
|
|
59
59
|
2. Diff upstream source against Twig using the file mapping above
|
|
60
60
|
3. Port in phases: bug fixes first, then features
|
|
61
61
|
4. After each phase: `pnpm --filter agent typecheck && pnpm --filter agent build && pnpm lint`
|
|
@@ -385,14 +385,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
385
385
|
const result = handleResultMessage(message);
|
|
386
386
|
if (result.error) throw result.error;
|
|
387
387
|
|
|
388
|
-
|
|
389
|
-
case "error_max_budget_usd":
|
|
390
|
-
case "error_max_turns":
|
|
391
|
-
case "error_max_structured_output_retries":
|
|
392
|
-
return { stopReason: "max_turn_requests", usage };
|
|
393
|
-
default:
|
|
394
|
-
return { stopReason: "end_turn", usage };
|
|
395
|
-
}
|
|
388
|
+
return { stopReason: result.stopReason ?? "end_turn", usage };
|
|
396
389
|
}
|
|
397
390
|
|
|
398
391
|
case "stream_event":
|
|
@@ -420,6 +413,14 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
420
413
|
}
|
|
421
414
|
}
|
|
422
415
|
|
|
416
|
+
// Skip replayed user messages that aren't pending prompts
|
|
417
|
+
if (
|
|
418
|
+
"isReplay" in message &&
|
|
419
|
+
(message as Record<string, unknown>).isReplay
|
|
420
|
+
) {
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
|
|
423
424
|
// Store latest assistant usage (excluding subagents)
|
|
424
425
|
if (
|
|
425
426
|
"usage" in message.message &&
|
|
@@ -451,6 +452,8 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
451
452
|
case "tool_progress":
|
|
452
453
|
case "auth_status":
|
|
453
454
|
case "tool_use_summary":
|
|
455
|
+
case "prompt_suggestion":
|
|
456
|
+
case "rate_limit_event":
|
|
454
457
|
break;
|
|
455
458
|
|
|
456
459
|
default:
|
|
@@ -459,6 +462,28 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
459
462
|
}
|
|
460
463
|
}
|
|
461
464
|
throw new Error("Session did not end in result");
|
|
465
|
+
} catch (error) {
|
|
466
|
+
if (error instanceof RequestError || !(error instanceof Error)) {
|
|
467
|
+
throw error;
|
|
468
|
+
}
|
|
469
|
+
const msg = error.message;
|
|
470
|
+
if (
|
|
471
|
+
msg.includes("ProcessTransport") ||
|
|
472
|
+
msg.includes("terminated process") ||
|
|
473
|
+
msg.includes("process exited with") ||
|
|
474
|
+
msg.includes("process terminated by signal") ||
|
|
475
|
+
msg.includes("Failed to write to process stdin")
|
|
476
|
+
) {
|
|
477
|
+
this.logger.error(`Process died: ${msg}`, {
|
|
478
|
+
sessionId: this.sessionId,
|
|
479
|
+
});
|
|
480
|
+
this.session.input.end();
|
|
481
|
+
throw RequestError.internalError(
|
|
482
|
+
undefined,
|
|
483
|
+
"The Claude Agent process exited unexpectedly. Please start a new session.",
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
throw error;
|
|
462
487
|
} finally {
|
|
463
488
|
if (!handedOff) {
|
|
464
489
|
this.session.promptRunning = false;
|
|
@@ -704,6 +729,13 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
704
729
|
}
|
|
705
730
|
} catch (err) {
|
|
706
731
|
settingsManager.dispose();
|
|
732
|
+
if (
|
|
733
|
+
isResume &&
|
|
734
|
+
err instanceof Error &&
|
|
735
|
+
err.message === "Query closed before response received"
|
|
736
|
+
) {
|
|
737
|
+
throw RequestError.resourceNotFound(sessionId);
|
|
738
|
+
}
|
|
707
739
|
this.logger.error(
|
|
708
740
|
isResume
|
|
709
741
|
? forkSession
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
SessionNotification,
|
|
5
5
|
SessionUpdate,
|
|
6
6
|
} from "@agentclientprotocol/sdk";
|
|
7
|
-
import { RequestError } from "@agentclientprotocol/sdk";
|
|
7
|
+
import { RequestError, type StopReason } from "@agentclientprotocol/sdk";
|
|
8
8
|
import type {
|
|
9
9
|
SDKAssistantMessage,
|
|
10
10
|
SDKMessage,
|
|
@@ -574,7 +574,7 @@ export async function handleSystemMessage(
|
|
|
574
574
|
|
|
575
575
|
export type ResultMessageHandlerResult = {
|
|
576
576
|
shouldStop: boolean;
|
|
577
|
-
stopReason?:
|
|
577
|
+
stopReason?: StopReason;
|
|
578
578
|
error?: Error;
|
|
579
579
|
usage?: {
|
|
580
580
|
inputTokens: number;
|
|
@@ -600,6 +600,9 @@ export function handleResultMessage(
|
|
|
600
600
|
usage,
|
|
601
601
|
};
|
|
602
602
|
}
|
|
603
|
+
if ((message as Record<string, unknown>).stop_reason === "max_tokens") {
|
|
604
|
+
return { shouldStop: true, stopReason: "max_tokens", usage };
|
|
605
|
+
}
|
|
603
606
|
if (message.is_error) {
|
|
604
607
|
return {
|
|
605
608
|
shouldStop: true,
|
|
@@ -610,6 +613,9 @@ export function handleResultMessage(
|
|
|
610
613
|
return { shouldStop: true, stopReason: "end_turn", usage };
|
|
611
614
|
}
|
|
612
615
|
case "error_during_execution":
|
|
616
|
+
if ((message as Record<string, unknown>).stop_reason === "max_tokens") {
|
|
617
|
+
return { shouldStop: true, stopReason: "max_tokens", usage };
|
|
618
|
+
}
|
|
613
619
|
if (message.is_error) {
|
|
614
620
|
return {
|
|
615
621
|
shouldStop: true,
|
|
@@ -384,5 +384,33 @@ describe("AgentServer HTTP Mode", () => {
|
|
|
384
384
|
expect(prompt).toContain("Create a draft pull request");
|
|
385
385
|
expect(prompt).toContain("gh pr create --draft");
|
|
386
386
|
});
|
|
387
|
+
|
|
388
|
+
it("includes --base flag when baseBranch is configured", () => {
|
|
389
|
+
server = new AgentServer({
|
|
390
|
+
port,
|
|
391
|
+
jwtPublicKey: TEST_PUBLIC_KEY,
|
|
392
|
+
repositoryPath: repo.path,
|
|
393
|
+
apiUrl: "http://localhost:8000",
|
|
394
|
+
apiKey: "test-api-key",
|
|
395
|
+
projectId: 1,
|
|
396
|
+
mode: "interactive",
|
|
397
|
+
taskId: "test-task-id",
|
|
398
|
+
runId: "test-run-id",
|
|
399
|
+
baseBranch: "add-yolo-to-readme",
|
|
400
|
+
});
|
|
401
|
+
const prompt = (
|
|
402
|
+
server as unknown as TestableServer
|
|
403
|
+
).buildCloudSystemPrompt();
|
|
404
|
+
expect(prompt).toContain(
|
|
405
|
+
"gh pr create --draft --base add-yolo-to-readme",
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("omits --base flag when baseBranch is not configured", () => {
|
|
410
|
+
const s = createServer();
|
|
411
|
+
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt();
|
|
412
|
+
expect(prompt).toContain("gh pr create --draft`");
|
|
413
|
+
expect(prompt).not.toContain("--base");
|
|
414
|
+
});
|
|
387
415
|
});
|
|
388
416
|
});
|
|
@@ -747,7 +747,7 @@ After completing the requested changes:
|
|
|
747
747
|
1. Create a new branch with a descriptive name based on the work done
|
|
748
748
|
2. Stage and commit all changes with a clear commit message
|
|
749
749
|
3. Push the branch to origin
|
|
750
|
-
4. Create a draft pull request using \`gh pr create --draft\` with a descriptive title and body
|
|
750
|
+
4. Create a draft pull request using \`gh pr create --draft${this.config.baseBranch ? ` --base ${this.config.baseBranch}` : ""}\` with a descriptive title and body
|
|
751
751
|
|
|
752
752
|
Important:
|
|
753
753
|
- Always create the PR as a draft. Do not ask for confirmation.
|
package/src/server/bin.ts
CHANGED
|
@@ -50,6 +50,7 @@ program
|
|
|
50
50
|
"--mcpServers <json>",
|
|
51
51
|
"MCP servers config as JSON array (ACP McpServer[] format)",
|
|
52
52
|
)
|
|
53
|
+
.option("--baseBranch <branch>", "Base branch for PR creation")
|
|
53
54
|
.action(async (options) => {
|
|
54
55
|
const envResult = envSchema.safeParse(process.env);
|
|
55
56
|
|
|
@@ -99,6 +100,7 @@ program
|
|
|
99
100
|
taskId: options.taskId,
|
|
100
101
|
runId: options.runId,
|
|
101
102
|
mcpServers,
|
|
103
|
+
baseBranch: options.baseBranch,
|
|
102
104
|
});
|
|
103
105
|
|
|
104
106
|
process.on("SIGINT", async () => {
|