@posthog/agent 2.3.302 → 2.3.304

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.302",
3
+ "version": "2.3.304",
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": {
@@ -86,8 +86,8 @@
86
86
  "tsx": "^4.20.6",
87
87
  "typescript": "^5.5.0",
88
88
  "vitest": "^2.1.8",
89
- "@posthog/git": "1.0.0",
90
- "@posthog/shared": "1.0.0"
89
+ "@posthog/shared": "1.0.0",
90
+ "@posthog/git": "1.0.0"
91
91
  },
92
92
  "dependencies": {
93
93
  "@agentclientprotocol/sdk": "0.16.1",
@@ -127,6 +127,46 @@ describe("CodexAcpAgent", () => {
127
127
  ).toBe("read-only");
128
128
  });
129
129
 
130
+ it("prepends _meta.prContext to the forwarded prompt but not to the broadcast", async () => {
131
+ const { agent, client } = createAgent();
132
+ mockCodexConnection.newSession.mockResolvedValue({
133
+ sessionId: "session-1",
134
+ modes: { currentModeId: "auto", availableModes: [] },
135
+ configOptions: [],
136
+ } satisfies Partial<NewSessionResponse>);
137
+ await agent.newSession({
138
+ cwd: process.cwd(),
139
+ } as never);
140
+
141
+ mockCodexConnection.prompt.mockResolvedValue({ stopReason: "end_turn" });
142
+
143
+ await agent.prompt({
144
+ sessionId: "session-1",
145
+ prompt: [{ type: "text", text: "ship the fix" }],
146
+ _meta: { prContext: "PR #123 is open; review before editing." },
147
+ } as never);
148
+
149
+ // codex-acp receives the PR context prepended as a text block.
150
+ expect(mockCodexConnection.prompt).toHaveBeenCalledWith(
151
+ expect.objectContaining({
152
+ prompt: [
153
+ { type: "text", text: "PR #123 is open; review before editing." },
154
+ { type: "text", text: "ship the fix" },
155
+ ],
156
+ }),
157
+ );
158
+ // The broadcast shows only the real user turn — the prContext prefix
159
+ // is internal routing and should not render as a user message.
160
+ expect(client.sessionUpdate).toHaveBeenCalledTimes(1);
161
+ expect(client.sessionUpdate).toHaveBeenCalledWith({
162
+ sessionId: "session-1",
163
+ update: {
164
+ sessionUpdate: "user_message_chunk",
165
+ content: { type: "text", text: "ship the fix" },
166
+ },
167
+ });
168
+ });
169
+
130
170
  it("broadcasts user prompt as user_message_chunk before delegating to codex-acp", async () => {
131
171
  const { agent, client } = createAgent();
132
172
  // Seed an active session so prompt() has the state it expects.
@@ -93,6 +93,24 @@ function toCodexPermissionMode(mode?: string): PermissionMode {
93
93
  return "auto";
94
94
  }
95
95
 
96
+ /**
97
+ * Prepend `_meta.prContext` (set by the agent-server on Slack-originated
98
+ * follow-up runs) to the prompt as a text block, mirroring Claude's
99
+ * `promptToClaude` behavior. Without this, codex cloud runs lose the
100
+ * PR-review context that follow-up flows rely on.
101
+ */
102
+ function prependPrContext(params: PromptRequest): PromptRequest {
103
+ const prContext = (params._meta as Record<string, unknown> | undefined)
104
+ ?.prContext;
105
+ if (typeof prContext !== "string" || prContext.length === 0) {
106
+ return params;
107
+ }
108
+ return {
109
+ ...params,
110
+ prompt: [{ type: "text", text: prContext }, ...params.prompt],
111
+ };
112
+ }
113
+
96
114
  const CODEX_NATIVE_MODE: Record<CodeExecutionMode, CodexNativeMode> = {
97
115
  default: "auto",
98
116
  acceptEdits: "auto",
@@ -373,9 +391,13 @@ export class CodexAcpAgent extends BaseAcpAgent {
373
391
  // channel, so without this broadcast the tapped stream (persisted to S3
374
392
  // and rendered by the PostHog web UI) never sees a user turn and only
375
393
  // the assistant reply shows up. Mirrors ClaudeAcpAgent.broadcastUserMessage.
394
+ // The original params (no _meta.prContext prefix) is broadcast so the
395
+ // injected PR context is not rendered as a user message.
376
396
  await this.broadcastUserMessage(params);
377
397
 
378
- const response = await this.codexConnection.prompt(params);
398
+ const response = await this.codexConnection.prompt(
399
+ prependPrContext(params),
400
+ );
379
401
 
380
402
  // Usage is already accumulated via sessionUpdate notifications in
381
403
  // codex-client.ts. Do NOT also add response.usage here or tokens