@posthog/agent 2.3.302 → 2.3.305
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 +23 -2
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +23 -2
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +23 -2
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/codex/codex-agent.test.ts +82 -0
- package/src/adapters/codex/codex-agent.ts +37 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.305",
|
|
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/
|
|
90
|
-
"@posthog/
|
|
89
|
+
"@posthog/shared": "1.0.0",
|
|
90
|
+
"@posthog/git": "1.0.0"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@agentclientprotocol/sdk": "0.16.1",
|
|
@@ -107,6 +107,48 @@ describe("CodexAcpAgent", () => {
|
|
|
107
107
|
).toBe("read-only");
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
+
it("propagates taskRunId and fires SDK_SESSION when loading a cloud session", async () => {
|
|
111
|
+
const { agent, client } = createAgent();
|
|
112
|
+
mockCodexConnection.loadSession.mockResolvedValue({
|
|
113
|
+
modes: { currentModeId: "auto", availableModes: [] },
|
|
114
|
+
configOptions: [],
|
|
115
|
+
} satisfies Partial<LoadSessionResponse>);
|
|
116
|
+
|
|
117
|
+
await agent.loadSession({
|
|
118
|
+
sessionId: "session-1",
|
|
119
|
+
cwd: process.cwd(),
|
|
120
|
+
_meta: { taskRunId: "run-1", taskId: "task-1" },
|
|
121
|
+
} as never);
|
|
122
|
+
|
|
123
|
+
expect(
|
|
124
|
+
(agent as unknown as { sessionState: { taskRunId?: string } })
|
|
125
|
+
.sessionState.taskRunId,
|
|
126
|
+
).toBe("run-1");
|
|
127
|
+
expect(client.extNotification).toHaveBeenCalledWith(
|
|
128
|
+
"_posthog/sdk_session",
|
|
129
|
+
{
|
|
130
|
+
taskRunId: "run-1",
|
|
131
|
+
sessionId: "session-1",
|
|
132
|
+
adapter: "codex",
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("does not emit SDK_SESSION on loadSession when taskRunId is absent", async () => {
|
|
138
|
+
const { agent, client } = createAgent();
|
|
139
|
+
mockCodexConnection.loadSession.mockResolvedValue({
|
|
140
|
+
modes: { currentModeId: "auto", availableModes: [] },
|
|
141
|
+
configOptions: [],
|
|
142
|
+
} satisfies Partial<LoadSessionResponse>);
|
|
143
|
+
|
|
144
|
+
await agent.loadSession({
|
|
145
|
+
sessionId: "session-1",
|
|
146
|
+
cwd: process.cwd(),
|
|
147
|
+
} as never);
|
|
148
|
+
|
|
149
|
+
expect(client.extNotification).not.toHaveBeenCalled();
|
|
150
|
+
});
|
|
151
|
+
|
|
110
152
|
it("preserves the live session mode when loading an existing session", async () => {
|
|
111
153
|
const { agent } = createAgent();
|
|
112
154
|
mockCodexConnection.loadSession.mockResolvedValue({
|
|
@@ -127,6 +169,46 @@ describe("CodexAcpAgent", () => {
|
|
|
127
169
|
).toBe("read-only");
|
|
128
170
|
});
|
|
129
171
|
|
|
172
|
+
it("prepends _meta.prContext to the forwarded prompt but not to the broadcast", async () => {
|
|
173
|
+
const { agent, client } = createAgent();
|
|
174
|
+
mockCodexConnection.newSession.mockResolvedValue({
|
|
175
|
+
sessionId: "session-1",
|
|
176
|
+
modes: { currentModeId: "auto", availableModes: [] },
|
|
177
|
+
configOptions: [],
|
|
178
|
+
} satisfies Partial<NewSessionResponse>);
|
|
179
|
+
await agent.newSession({
|
|
180
|
+
cwd: process.cwd(),
|
|
181
|
+
} as never);
|
|
182
|
+
|
|
183
|
+
mockCodexConnection.prompt.mockResolvedValue({ stopReason: "end_turn" });
|
|
184
|
+
|
|
185
|
+
await agent.prompt({
|
|
186
|
+
sessionId: "session-1",
|
|
187
|
+
prompt: [{ type: "text", text: "ship the fix" }],
|
|
188
|
+
_meta: { prContext: "PR #123 is open; review before editing." },
|
|
189
|
+
} as never);
|
|
190
|
+
|
|
191
|
+
// codex-acp receives the PR context prepended as a text block.
|
|
192
|
+
expect(mockCodexConnection.prompt).toHaveBeenCalledWith(
|
|
193
|
+
expect.objectContaining({
|
|
194
|
+
prompt: [
|
|
195
|
+
{ type: "text", text: "PR #123 is open; review before editing." },
|
|
196
|
+
{ type: "text", text: "ship the fix" },
|
|
197
|
+
],
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
// The broadcast shows only the real user turn — the prContext prefix
|
|
201
|
+
// is internal routing and should not render as a user message.
|
|
202
|
+
expect(client.sessionUpdate).toHaveBeenCalledTimes(1);
|
|
203
|
+
expect(client.sessionUpdate).toHaveBeenCalledWith({
|
|
204
|
+
sessionId: "session-1",
|
|
205
|
+
update: {
|
|
206
|
+
sessionUpdate: "user_message_chunk",
|
|
207
|
+
content: { type: "text", text: "ship the fix" },
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
130
212
|
it("broadcasts user prompt as user_message_chunk before delegating to codex-acp", async () => {
|
|
131
213
|
const { agent, client } = createAgent();
|
|
132
214
|
// 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",
|
|
@@ -249,13 +267,27 @@ export class CodexAcpAgent extends BaseAcpAgent {
|
|
|
249
267
|
meta?.permissionMode,
|
|
250
268
|
);
|
|
251
269
|
|
|
270
|
+
// Carry taskRunId/taskId across load so prompt() still emits cloud
|
|
271
|
+
// notifications (TURN_COMPLETE, USAGE_UPDATE) after a reload. newSession
|
|
272
|
+
// and unstable_resumeSession both do this; loadSession historically did
|
|
273
|
+
// not, which silently broke task-completion tracking on re-attach.
|
|
252
274
|
this.sessionState = createSessionState(params.sessionId, params.cwd, {
|
|
275
|
+
taskRunId: meta?.taskRunId,
|
|
276
|
+
taskId: meta?.taskId ?? meta?.persistence?.taskId,
|
|
253
277
|
modeId: response.modes?.currentModeId ?? "auto",
|
|
254
278
|
permissionMode: currentPermissionMode,
|
|
255
279
|
});
|
|
256
280
|
this.sessionId = params.sessionId;
|
|
257
281
|
this.sessionState.configOptions = response.configOptions ?? [];
|
|
258
282
|
|
|
283
|
+
if (meta?.taskRunId) {
|
|
284
|
+
await this.client.extNotification(POSTHOG_NOTIFICATIONS.SDK_SESSION, {
|
|
285
|
+
taskRunId: meta.taskRunId,
|
|
286
|
+
sessionId: params.sessionId,
|
|
287
|
+
adapter: "codex",
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
259
291
|
return response;
|
|
260
292
|
}
|
|
261
293
|
|
|
@@ -373,9 +405,13 @@ export class CodexAcpAgent extends BaseAcpAgent {
|
|
|
373
405
|
// channel, so without this broadcast the tapped stream (persisted to S3
|
|
374
406
|
// and rendered by the PostHog web UI) never sees a user turn and only
|
|
375
407
|
// the assistant reply shows up. Mirrors ClaudeAcpAgent.broadcastUserMessage.
|
|
408
|
+
// The original params (no _meta.prContext prefix) is broadcast so the
|
|
409
|
+
// injected PR context is not rendered as a user message.
|
|
376
410
|
await this.broadcastUserMessage(params);
|
|
377
411
|
|
|
378
|
-
const response = await this.codexConnection.prompt(
|
|
412
|
+
const response = await this.codexConnection.prompt(
|
|
413
|
+
prependPrContext(params),
|
|
414
|
+
);
|
|
379
415
|
|
|
380
416
|
// Usage is already accumulated via sessionUpdate notifications in
|
|
381
417
|
// codex-client.ts. Do NOT also add response.usage here or tokens
|