@posthog/agent 2.1.47 → 2.1.48
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-BJ7Uacyp.d.ts → agent-DcBmoTR4.d.ts} +0 -2
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +42 -122
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +169 -247
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +169 -246
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +169 -246
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/acp-connection.ts +1 -6
- package/src/adapters/claude/claude-agent.ts +39 -75
- package/src/agent.ts +0 -1
package/package.json
CHANGED
|
@@ -23,8 +23,6 @@ export type AcpConnectionConfig = {
|
|
|
23
23
|
/** Deployment environment - "local" for desktop, "cloud" for cloud sandbox */
|
|
24
24
|
deviceType?: "local" | "cloud";
|
|
25
25
|
logger?: Logger;
|
|
26
|
-
/** Enable dev-only instrumentation (timing, verbose logging) */
|
|
27
|
-
debug?: boolean;
|
|
28
26
|
processCallbacks?: ProcessSpawnedCallback;
|
|
29
27
|
codexOptions?: CodexProcessOptions;
|
|
30
28
|
allowedModelIds?: Set<string>;
|
|
@@ -196,10 +194,7 @@ function createClaudeConnection(config: AcpConnectionConfig): AcpConnection {
|
|
|
196
194
|
|
|
197
195
|
let agent: ClaudeAcpAgent | null = null;
|
|
198
196
|
const agentConnection = new AgentSideConnection((client) => {
|
|
199
|
-
agent = new ClaudeAcpAgent(client, logWriter,
|
|
200
|
-
...config.processCallbacks,
|
|
201
|
-
debug: config.debug,
|
|
202
|
-
});
|
|
197
|
+
agent = new ClaudeAcpAgent(client, logWriter, config.processCallbacks);
|
|
203
198
|
logger.info(`Created ${agent.adapterName} agent`);
|
|
204
199
|
return agent;
|
|
205
200
|
}, agentStream);
|
|
@@ -29,7 +29,6 @@ import {
|
|
|
29
29
|
type SDKMessage,
|
|
30
30
|
type SDKUserMessage,
|
|
31
31
|
} from "@anthropic-ai/claude-agent-sdk";
|
|
32
|
-
import { createTimingCollector } from "@posthog/shared";
|
|
33
32
|
import { v7 as uuidv7 } from "uuid";
|
|
34
33
|
import packageJson from "../../../package.json" with { type: "json" };
|
|
35
34
|
import type { SessionContext } from "../../otel-log-writer.js";
|
|
@@ -70,8 +69,6 @@ import type {
|
|
|
70
69
|
export interface ClaudeAcpAgentOptions {
|
|
71
70
|
onProcessSpawned?: (info: ProcessSpawnedInfo) => void;
|
|
72
71
|
onProcessExited?: (pid: number) => void;
|
|
73
|
-
/** Enable dev-only instrumentation (timing, verbose logging) */
|
|
74
|
-
debug?: boolean;
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
@@ -83,7 +80,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
83
80
|
private logWriter?: SessionLogWriter;
|
|
84
81
|
private options?: ClaudeAcpAgentOptions;
|
|
85
82
|
private lastSentConfigOptions?: SessionConfigOption[];
|
|
86
|
-
private debug: boolean;
|
|
87
83
|
|
|
88
84
|
constructor(
|
|
89
85
|
client: AgentSideConnection,
|
|
@@ -93,7 +89,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
93
89
|
super(client);
|
|
94
90
|
this.logWriter = logWriter;
|
|
95
91
|
this.options = options;
|
|
96
|
-
this.debug = options?.debug ?? false;
|
|
97
92
|
this.toolUseCache = {};
|
|
98
93
|
this.logger = new Logger({ debug: true, prefix: "[ClaudeAcpAgent]" });
|
|
99
94
|
}
|
|
@@ -141,10 +136,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
141
136
|
async newSession(params: NewSessionRequest): Promise<NewSessionResponse> {
|
|
142
137
|
this.checkAuthStatus();
|
|
143
138
|
|
|
144
|
-
const tc = createTimingCollector(this.debug, (msg, data) =>
|
|
145
|
-
this.logger.info(msg, data),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
139
|
const meta = params._meta as NewSessionMeta | undefined;
|
|
149
140
|
const sessionId = uuidv7();
|
|
150
141
|
const permissionMode: TwigExecutionMode =
|
|
@@ -153,29 +144,25 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
153
144
|
? (meta.permissionMode as TwigExecutionMode)
|
|
154
145
|
: "default";
|
|
155
146
|
|
|
156
|
-
const mcpServers =
|
|
157
|
-
parseMcpServers(params),
|
|
158
|
-
);
|
|
147
|
+
const mcpServers = parseMcpServers(params);
|
|
159
148
|
|
|
160
|
-
const options =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}),
|
|
175
|
-
);
|
|
149
|
+
const options = buildSessionOptions({
|
|
150
|
+
cwd: params.cwd,
|
|
151
|
+
mcpServers,
|
|
152
|
+
permissionMode,
|
|
153
|
+
canUseTool: this.createCanUseTool(sessionId),
|
|
154
|
+
logger: this.logger,
|
|
155
|
+
systemPrompt: buildSystemPrompt(meta?.systemPrompt),
|
|
156
|
+
userProvidedOptions: meta?.claudeCode?.options,
|
|
157
|
+
sessionId,
|
|
158
|
+
isResume: false,
|
|
159
|
+
onModeChange: this.createOnModeChange(sessionId),
|
|
160
|
+
onProcessSpawned: this.options?.onProcessSpawned,
|
|
161
|
+
onProcessExited: this.options?.onProcessExited,
|
|
162
|
+
});
|
|
176
163
|
|
|
177
164
|
const input = new Pushable<SDKUserMessage>();
|
|
178
|
-
const q =
|
|
165
|
+
const q = query({ prompt: input, options });
|
|
179
166
|
|
|
180
167
|
const session = this.createSession(
|
|
181
168
|
sessionId,
|
|
@@ -189,32 +176,24 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
189
176
|
this.registerPersistence(sessionId, meta as Record<string, unknown>);
|
|
190
177
|
|
|
191
178
|
if (meta?.taskRunId) {
|
|
192
|
-
await
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}),
|
|
198
|
-
);
|
|
179
|
+
await this.client.extNotification("_posthog/sdk_session", {
|
|
180
|
+
taskRunId: meta.taskRunId!,
|
|
181
|
+
sessionId,
|
|
182
|
+
adapter: "claude",
|
|
183
|
+
});
|
|
199
184
|
}
|
|
200
185
|
|
|
201
186
|
// Only await model config — slash commands and MCP metadata are deferred
|
|
202
187
|
// since they're not needed to return configOptions to the client.
|
|
203
|
-
const modelOptions = await
|
|
204
|
-
this.getModelConfigOptions(),
|
|
205
|
-
);
|
|
188
|
+
const modelOptions = await this.getModelConfigOptions();
|
|
206
189
|
|
|
207
190
|
// Deferred: slash commands + MCP metadata (not needed to return configOptions)
|
|
208
|
-
this.deferBackgroundFetches(
|
|
191
|
+
this.deferBackgroundFetches(q, sessionId, mcpServers);
|
|
209
192
|
|
|
210
193
|
session.modelId = modelOptions.currentModelId;
|
|
211
194
|
await this.trySetModel(q, modelOptions.currentModelId);
|
|
212
195
|
|
|
213
|
-
const configOptions = await
|
|
214
|
-
this.buildConfigOptions(modelOptions),
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
tc.summarize("newSession");
|
|
196
|
+
const configOptions = await this.buildConfigOptions(modelOptions);
|
|
218
197
|
|
|
219
198
|
return {
|
|
220
199
|
sessionId,
|
|
@@ -229,10 +208,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
229
208
|
async resumeSession(
|
|
230
209
|
params: LoadSessionRequest,
|
|
231
210
|
): Promise<LoadSessionResponse> {
|
|
232
|
-
const tc = createTimingCollector(this.debug, (msg, data) =>
|
|
233
|
-
this.logger.info(msg, data),
|
|
234
|
-
);
|
|
235
|
-
|
|
236
211
|
const meta = params._meta as NewSessionMeta | undefined;
|
|
237
212
|
const sessionId = meta?.sessionId;
|
|
238
213
|
if (!sessionId) {
|
|
@@ -242,9 +217,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
242
217
|
return {};
|
|
243
218
|
}
|
|
244
219
|
|
|
245
|
-
const mcpServers =
|
|
246
|
-
parseMcpServers(params),
|
|
247
|
-
);
|
|
220
|
+
const mcpServers = parseMcpServers(params);
|
|
248
221
|
|
|
249
222
|
const permissionMode: TwigExecutionMode =
|
|
250
223
|
meta?.permissionMode &&
|
|
@@ -252,31 +225,25 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
252
225
|
? (meta.permissionMode as TwigExecutionMode)
|
|
253
226
|
: "default";
|
|
254
227
|
|
|
255
|
-
const { query: q, session } = await
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}),
|
|
266
|
-
);
|
|
228
|
+
const { query: q, session } = await this.initializeQuery({
|
|
229
|
+
cwd: params.cwd,
|
|
230
|
+
permissionMode,
|
|
231
|
+
mcpServers,
|
|
232
|
+
systemPrompt: buildSystemPrompt(meta?.systemPrompt),
|
|
233
|
+
userProvidedOptions: meta?.claudeCode?.options,
|
|
234
|
+
sessionId,
|
|
235
|
+
isResume: true,
|
|
236
|
+
additionalDirectories: meta?.claudeCode?.options?.additionalDirectories,
|
|
237
|
+
});
|
|
267
238
|
|
|
268
239
|
session.taskRunId = meta?.taskRunId;
|
|
269
240
|
|
|
270
241
|
this.registerPersistence(sessionId, meta as Record<string, unknown>);
|
|
271
242
|
|
|
272
243
|
// Deferred: slash commands + MCP metadata (not needed to return configOptions)
|
|
273
|
-
this.deferBackgroundFetches(
|
|
244
|
+
this.deferBackgroundFetches(q, sessionId, mcpServers);
|
|
274
245
|
|
|
275
|
-
const configOptions = await
|
|
276
|
-
this.buildConfigOptions(),
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
tc.summarize("resumeSession");
|
|
246
|
+
const configOptions = await this.buildConfigOptions();
|
|
280
247
|
|
|
281
248
|
return { configOptions };
|
|
282
249
|
}
|
|
@@ -529,16 +496,13 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
529
496
|
* Both populate caches used later — neither is needed to return configOptions.
|
|
530
497
|
*/
|
|
531
498
|
private deferBackgroundFetches(
|
|
532
|
-
tc: ReturnType<typeof createTimingCollector>,
|
|
533
499
|
q: Query,
|
|
534
500
|
sessionId: string,
|
|
535
501
|
mcpServers: ReturnType<typeof parseMcpServers>,
|
|
536
502
|
): void {
|
|
537
503
|
Promise.all([
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
fetchMcpToolMetadata(mcpServers, this.logger),
|
|
541
|
-
),
|
|
504
|
+
getAvailableSlashCommands(q),
|
|
505
|
+
fetchMcpToolMetadata(mcpServers, this.logger),
|
|
542
506
|
])
|
|
543
507
|
.then(([slashCommands]) => {
|
|
544
508
|
this.sendAvailableCommandsUpdate(sessionId, slashCommands);
|