@posthog/agent 2.1.45 → 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.js +29 -25
- package/dist/agent.js.map +1 -1
- package/dist/index.js +29 -25
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +29 -25
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +29 -25
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/claude/claude-agent.ts +41 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.48",
|
|
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": {
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"tsx": "^4.20.6",
|
|
73
73
|
"typescript": "^5.5.0",
|
|
74
74
|
"vitest": "^2.1.8",
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
75
|
+
"@posthog/shared": "1.0.0",
|
|
76
|
+
"@twig/git": "1.0.0"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@agentclientprotocol/sdk": "^0.14.0",
|
|
@@ -78,17 +78,17 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
78
78
|
backgroundTerminals: { [key: string]: BackgroundTerminal } = {};
|
|
79
79
|
clientCapabilities?: ClientCapabilities;
|
|
80
80
|
private logWriter?: SessionLogWriter;
|
|
81
|
-
private
|
|
81
|
+
private options?: ClaudeAcpAgentOptions;
|
|
82
82
|
private lastSentConfigOptions?: SessionConfigOption[];
|
|
83
83
|
|
|
84
84
|
constructor(
|
|
85
85
|
client: AgentSideConnection,
|
|
86
86
|
logWriter?: SessionLogWriter,
|
|
87
|
-
|
|
87
|
+
options?: ClaudeAcpAgentOptions,
|
|
88
88
|
) {
|
|
89
89
|
super(client);
|
|
90
90
|
this.logWriter = logWriter;
|
|
91
|
-
this.
|
|
91
|
+
this.options = options;
|
|
92
92
|
this.toolUseCache = {};
|
|
93
93
|
this.logger = new Logger({ debug: true, prefix: "[ClaudeAcpAgent]" });
|
|
94
94
|
}
|
|
@@ -146,10 +146,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
146
146
|
|
|
147
147
|
const mcpServers = parseMcpServers(params);
|
|
148
148
|
|
|
149
|
-
// Fire off MCP metadata fetch early — it populates a module-level cache
|
|
150
|
-
// used later during permission checks, not needed by buildSessionOptions or query()
|
|
151
|
-
const mcpMetadataPromise = fetchMcpToolMetadata(mcpServers, this.logger);
|
|
152
|
-
|
|
153
149
|
const options = buildSessionOptions({
|
|
154
150
|
cwd: params.cwd,
|
|
155
151
|
mcpServers,
|
|
@@ -161,8 +157,8 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
161
157
|
sessionId,
|
|
162
158
|
isResume: false,
|
|
163
159
|
onModeChange: this.createOnModeChange(sessionId),
|
|
164
|
-
onProcessSpawned: this.
|
|
165
|
-
onProcessExited: this.
|
|
160
|
+
onProcessSpawned: this.options?.onProcessSpawned,
|
|
161
|
+
onProcessExited: this.options?.onProcessExited,
|
|
166
162
|
});
|
|
167
163
|
|
|
168
164
|
const input = new Pushable<SDKUserMessage>();
|
|
@@ -181,27 +177,27 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
181
177
|
|
|
182
178
|
if (meta?.taskRunId) {
|
|
183
179
|
await this.client.extNotification("_posthog/sdk_session", {
|
|
184
|
-
taskRunId: meta.taskRunId
|
|
180
|
+
taskRunId: meta.taskRunId!,
|
|
185
181
|
sessionId,
|
|
186
182
|
adapter: "claude",
|
|
187
183
|
});
|
|
188
184
|
}
|
|
189
185
|
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
// Only await model config — slash commands and MCP metadata are deferred
|
|
187
|
+
// since they're not needed to return configOptions to the client.
|
|
188
|
+
const modelOptions = await this.getModelConfigOptions();
|
|
189
|
+
|
|
190
|
+
// Deferred: slash commands + MCP metadata (not needed to return configOptions)
|
|
191
|
+
this.deferBackgroundFetches(q, sessionId, mcpServers);
|
|
196
192
|
|
|
197
193
|
session.modelId = modelOptions.currentModelId;
|
|
198
194
|
await this.trySetModel(q, modelOptions.currentModelId);
|
|
199
195
|
|
|
200
|
-
this.
|
|
196
|
+
const configOptions = await this.buildConfigOptions(modelOptions);
|
|
201
197
|
|
|
202
198
|
return {
|
|
203
199
|
sessionId,
|
|
204
|
-
configOptions
|
|
200
|
+
configOptions,
|
|
205
201
|
};
|
|
206
202
|
}
|
|
207
203
|
|
|
@@ -223,9 +219,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
223
219
|
|
|
224
220
|
const mcpServers = parseMcpServers(params);
|
|
225
221
|
|
|
226
|
-
// Fire off MCP metadata fetch early — populates cache for permission checks
|
|
227
|
-
const mcpMetadataPromise = fetchMcpToolMetadata(mcpServers, this.logger);
|
|
228
|
-
|
|
229
222
|
const permissionMode: TwigExecutionMode =
|
|
230
223
|
meta?.permissionMode &&
|
|
231
224
|
TWIG_EXECUTION_MODES.includes(meta.permissionMode as TwigExecutionMode)
|
|
@@ -247,17 +240,12 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
247
240
|
|
|
248
241
|
this.registerPersistence(sessionId, meta as Record<string, unknown>);
|
|
249
242
|
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
getAvailableSlashCommands(q),
|
|
253
|
-
mcpMetadataPromise,
|
|
254
|
-
]);
|
|
243
|
+
// Deferred: slash commands + MCP metadata (not needed to return configOptions)
|
|
244
|
+
this.deferBackgroundFetches(q, sessionId, mcpServers);
|
|
255
245
|
|
|
256
|
-
this.
|
|
246
|
+
const configOptions = await this.buildConfigOptions();
|
|
257
247
|
|
|
258
|
-
return {
|
|
259
|
-
configOptions: await this.buildConfigOptions(),
|
|
260
|
-
};
|
|
248
|
+
return { configOptions };
|
|
261
249
|
}
|
|
262
250
|
|
|
263
251
|
async prompt(params: PromptRequest): Promise<PromptResponse> {
|
|
@@ -366,8 +354,8 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
366
354
|
isResume: config.isResume,
|
|
367
355
|
additionalDirectories: config.additionalDirectories,
|
|
368
356
|
onModeChange: this.createOnModeChange(config.sessionId),
|
|
369
|
-
onProcessSpawned: this.
|
|
370
|
-
onProcessExited: this.
|
|
357
|
+
onProcessSpawned: this.options?.onProcessSpawned,
|
|
358
|
+
onProcessExited: this.options?.onProcessExited,
|
|
371
359
|
});
|
|
372
360
|
|
|
373
361
|
const q = query({ prompt: input, options });
|
|
@@ -503,6 +491,27 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
503
491
|
}
|
|
504
492
|
}
|
|
505
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Fire-and-forget: fetch slash commands and MCP tool metadata in parallel.
|
|
496
|
+
* Both populate caches used later — neither is needed to return configOptions.
|
|
497
|
+
*/
|
|
498
|
+
private deferBackgroundFetches(
|
|
499
|
+
q: Query,
|
|
500
|
+
sessionId: string,
|
|
501
|
+
mcpServers: ReturnType<typeof parseMcpServers>,
|
|
502
|
+
): void {
|
|
503
|
+
Promise.all([
|
|
504
|
+
getAvailableSlashCommands(q),
|
|
505
|
+
fetchMcpToolMetadata(mcpServers, this.logger),
|
|
506
|
+
])
|
|
507
|
+
.then(([slashCommands]) => {
|
|
508
|
+
this.sendAvailableCommandsUpdate(sessionId, slashCommands);
|
|
509
|
+
})
|
|
510
|
+
.catch((err) => {
|
|
511
|
+
this.logger.warn("Failed to fetch deferred session data", { err });
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
506
515
|
private registerPersistence(
|
|
507
516
|
sessionId: string,
|
|
508
517
|
meta: Record<string, unknown> | undefined,
|