@posthog/agent 2.3.298 → 2.3.302

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.298",
3
+ "version": "2.3.302",
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/shared": "1.0.0",
90
- "@posthog/git": "1.0.0"
89
+ "@posthog/git": "1.0.0",
90
+ "@posthog/shared": "1.0.0"
91
91
  },
92
92
  "dependencies": {
93
93
  "@agentclientprotocol/sdk": "0.16.1",
@@ -60,20 +60,32 @@ describe("CodexAcpAgent", () => {
60
60
  vi.clearAllMocks();
61
61
  });
62
62
 
63
- function createAgent(): CodexAcpAgent {
63
+ function createAgent(overrides: Partial<AgentSideConnection> = {}): {
64
+ agent: CodexAcpAgent;
65
+ client: AgentSideConnection & {
66
+ extNotification: ReturnType<typeof vi.fn>;
67
+ sessionUpdate: ReturnType<typeof vi.fn>;
68
+ };
69
+ } {
64
70
  const client = {
65
71
  extNotification: vi.fn(),
66
- } as unknown as AgentSideConnection;
67
-
68
- return new CodexAcpAgent(client, {
72
+ sessionUpdate: vi.fn(),
73
+ ...overrides,
74
+ } as unknown as AgentSideConnection & {
75
+ extNotification: ReturnType<typeof vi.fn>;
76
+ sessionUpdate: ReturnType<typeof vi.fn>;
77
+ };
78
+
79
+ const agent = new CodexAcpAgent(client, {
69
80
  codexProcessOptions: {
70
81
  cwd: process.cwd(),
71
82
  },
72
83
  });
84
+ return { agent, client };
73
85
  }
74
86
 
75
87
  it("applies the requested initial mode for a new session", async () => {
76
- const agent = createAgent();
88
+ const { agent } = createAgent();
77
89
  mockCodexConnection.newSession.mockResolvedValue({
78
90
  sessionId: "session-1",
79
91
  modes: { currentModeId: "auto", availableModes: [] },
@@ -96,7 +108,7 @@ describe("CodexAcpAgent", () => {
96
108
  });
97
109
 
98
110
  it("preserves the live session mode when loading an existing session", async () => {
99
- const agent = createAgent();
111
+ const { agent } = createAgent();
100
112
  mockCodexConnection.loadSession.mockResolvedValue({
101
113
  modes: { currentModeId: "read-only", availableModes: [] },
102
114
  configOptions: [],
@@ -114,4 +126,53 @@ describe("CodexAcpAgent", () => {
114
126
  .sessionState.permissionMode,
115
127
  ).toBe("read-only");
116
128
  });
129
+
130
+ it("broadcasts user prompt as user_message_chunk before delegating to codex-acp", async () => {
131
+ const { agent, client } = createAgent();
132
+ // Seed an active session so prompt() has the state it expects.
133
+ mockCodexConnection.newSession.mockResolvedValue({
134
+ sessionId: "session-1",
135
+ modes: { currentModeId: "auto", availableModes: [] },
136
+ configOptions: [],
137
+ } satisfies Partial<NewSessionResponse>);
138
+ await agent.newSession({
139
+ cwd: process.cwd(),
140
+ } as never);
141
+
142
+ const callOrder: string[] = [];
143
+ client.sessionUpdate.mockImplementation(async () => {
144
+ callOrder.push("sessionUpdate");
145
+ });
146
+ mockCodexConnection.prompt.mockImplementation(async () => {
147
+ callOrder.push("prompt");
148
+ return { stopReason: "end_turn" };
149
+ });
150
+
151
+ await agent.prompt({
152
+ sessionId: "session-1",
153
+ prompt: [
154
+ { type: "text", text: "first chunk" },
155
+ { type: "text", text: "second chunk" },
156
+ ],
157
+ } as never);
158
+
159
+ expect(client.sessionUpdate).toHaveBeenCalledTimes(2);
160
+ expect(client.sessionUpdate).toHaveBeenNthCalledWith(1, {
161
+ sessionId: "session-1",
162
+ update: {
163
+ sessionUpdate: "user_message_chunk",
164
+ content: { type: "text", text: "first chunk" },
165
+ },
166
+ });
167
+ expect(client.sessionUpdate).toHaveBeenNthCalledWith(2, {
168
+ sessionId: "session-1",
169
+ update: {
170
+ sessionUpdate: "user_message_chunk",
171
+ content: { type: "text", text: "second chunk" },
172
+ },
173
+ });
174
+ // Broadcast must land before the prompt reaches codex-acp so the user
175
+ // turn is persisted even if the underlying prompt fails.
176
+ expect(callOrder).toEqual(["sessionUpdate", "sessionUpdate", "prompt"]);
177
+ });
117
178
  });
@@ -369,6 +369,12 @@ export class CodexAcpAgent extends BaseAcpAgent {
369
369
  this.session.interruptReason = undefined;
370
370
  resetUsage(this.sessionState);
371
371
 
372
+ // codex-acp does not echo the user prompt back on the agent→client
373
+ // channel, so without this broadcast the tapped stream (persisted to S3
374
+ // and rendered by the PostHog web UI) never sees a user turn and only
375
+ // the assistant reply shows up. Mirrors ClaudeAcpAgent.broadcastUserMessage.
376
+ await this.broadcastUserMessage(params);
377
+
372
378
  const response = await this.codexConnection.prompt(params);
373
379
 
374
380
  // Usage is already accumulated via sessionUpdate notifications in
@@ -417,6 +423,20 @@ export class CodexAcpAgent extends BaseAcpAgent {
417
423
  });
418
424
  }
419
425
 
426
+ private async broadcastUserMessage(params: PromptRequest): Promise<void> {
427
+ for (const chunk of params.prompt) {
428
+ const notification = {
429
+ sessionId: params.sessionId,
430
+ update: {
431
+ sessionUpdate: "user_message_chunk" as const,
432
+ content: chunk,
433
+ },
434
+ };
435
+ await this.client.sessionUpdate(notification);
436
+ this.appendNotification(params.sessionId, notification);
437
+ }
438
+ }
439
+
420
440
  async setSessionMode(
421
441
  params: SetSessionModeRequest,
422
442
  ): Promise<SetSessionModeResponse> {