@posthog/agent 2.3.297 → 2.3.298
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 +104 -1
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.js +5 -2
- package/dist/index.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 +105 -3
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +105 -3
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/acp-extensions.test.ts +72 -0
- package/src/acp-extensions.ts +37 -6
- package/src/adapters/claude/claude-agent.refresh.test.ts +292 -0
- package/src/adapters/claude/claude-agent.ts +121 -1
package/dist/server/bin.cjs
CHANGED
|
@@ -5805,7 +5805,7 @@ var import_hono = require("hono");
|
|
|
5805
5805
|
// package.json
|
|
5806
5806
|
var package_default = {
|
|
5807
5807
|
name: "@posthog/agent",
|
|
5808
|
-
version: "2.3.
|
|
5808
|
+
version: "2.3.298",
|
|
5809
5809
|
repository: "https://github.com/PostHog/code",
|
|
5810
5810
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
5811
5811
|
exports: {
|
|
@@ -5974,9 +5974,24 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
5974
5974
|
/** Response to a relayed permission request (plan approval, question) */
|
|
5975
5975
|
PERMISSION_RESPONSE: "_posthog/permission_response"
|
|
5976
5976
|
};
|
|
5977
|
-
|
|
5977
|
+
var POSTHOG_METHODS = {
|
|
5978
|
+
/**
|
|
5979
|
+
* Client requests a session refresh between turns. Payload may include
|
|
5980
|
+
* `mcpServers` to trigger a resume-with-new-options reinit; future fields
|
|
5981
|
+
* can extend this without adding new methods. Returns once the refresh has
|
|
5982
|
+
* completed so the caller can safely send the next prompt.
|
|
5983
|
+
*/
|
|
5984
|
+
REFRESH_SESSION: "_posthog/refresh_session"
|
|
5985
|
+
};
|
|
5986
|
+
function matchesExt(method, expected) {
|
|
5978
5987
|
if (!method) return false;
|
|
5979
|
-
return method ===
|
|
5988
|
+
return method === expected || method === `_${expected}`;
|
|
5989
|
+
}
|
|
5990
|
+
function isNotification(method, expected) {
|
|
5991
|
+
return matchesExt(method, expected);
|
|
5992
|
+
}
|
|
5993
|
+
function isMethod(method, expected) {
|
|
5994
|
+
return matchesExt(method, expected);
|
|
5980
5995
|
}
|
|
5981
5996
|
|
|
5982
5997
|
// src/adapters/acp-connection.ts
|
|
@@ -9372,6 +9387,93 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
9372
9387
|
this.session.pendingMessages.clear();
|
|
9373
9388
|
await this.session.query.interrupt();
|
|
9374
9389
|
}
|
|
9390
|
+
/**
|
|
9391
|
+
* Refresh the session between turns. Currently the only refreshable field
|
|
9392
|
+
* is `mcpServers` — a resume-with-new-options reinit that bakes the servers
|
|
9393
|
+
* into query() options (preserving conversation history via resume).
|
|
9394
|
+
*
|
|
9395
|
+
* This is an `extMethod` (request/response), not `extNotification`, so the
|
|
9396
|
+
* caller can await completion before sending the next prompt. The sandbox
|
|
9397
|
+
* agent-server uses this on pre-prompt TTL checks.
|
|
9398
|
+
*
|
|
9399
|
+
* Why resume+rebuild instead of query.setMcpServers()?
|
|
9400
|
+
* setMcpServers() does NOT always overwrite servers installed by local/plugin
|
|
9401
|
+
* config — it can non-deterministically surface either the config-provided
|
|
9402
|
+
* server or the plugin-installed one. In the sandbox, repos may have Claude
|
|
9403
|
+
* plugins with their own MCPs, and we want the CLI-supplied set to fully win.
|
|
9404
|
+
* Passing mcpServers via query() options (as a "managed"/static set) has that
|
|
9405
|
+
* overwrite guarantee, so we tear down the current Query and construct a new
|
|
9406
|
+
* one with resume.
|
|
9407
|
+
*
|
|
9408
|
+
* Caller contract: only call REFRESH_SESSION between turns (no prompt in flight).
|
|
9409
|
+
*/
|
|
9410
|
+
async extMethod(method, params) {
|
|
9411
|
+
if (!isMethod(method, POSTHOG_METHODS.REFRESH_SESSION)) {
|
|
9412
|
+
throw import_sdk2.RequestError.methodNotFound(method);
|
|
9413
|
+
}
|
|
9414
|
+
if (params.mcpServers === void 0) {
|
|
9415
|
+
throw new import_sdk2.RequestError(
|
|
9416
|
+
-32602,
|
|
9417
|
+
"refresh_session requires at least one refreshable field (e.g. mcpServers)"
|
|
9418
|
+
);
|
|
9419
|
+
}
|
|
9420
|
+
if (!Array.isArray(params.mcpServers)) {
|
|
9421
|
+
throw new import_sdk2.RequestError(
|
|
9422
|
+
-32602,
|
|
9423
|
+
"refresh_session: mcpServers must be an array"
|
|
9424
|
+
);
|
|
9425
|
+
}
|
|
9426
|
+
const mcpServers = parseMcpServers(
|
|
9427
|
+
params
|
|
9428
|
+
);
|
|
9429
|
+
await this.refreshSession(mcpServers);
|
|
9430
|
+
return { refreshed: true };
|
|
9431
|
+
}
|
|
9432
|
+
async refreshSession(mcpServers) {
|
|
9433
|
+
const prev = this.session;
|
|
9434
|
+
if (prev.promptRunning) {
|
|
9435
|
+
throw new import_sdk2.RequestError(
|
|
9436
|
+
-32002,
|
|
9437
|
+
"Cannot refresh session while a prompt turn is in flight"
|
|
9438
|
+
);
|
|
9439
|
+
}
|
|
9440
|
+
if (prev.modelId && !supportsMcpInjection(prev.modelId)) {
|
|
9441
|
+
throw new import_sdk2.RequestError(
|
|
9442
|
+
-32002,
|
|
9443
|
+
`Model ${prev.modelId} does not support MCP injection; cannot refresh`
|
|
9444
|
+
);
|
|
9445
|
+
}
|
|
9446
|
+
this.logger.info("Refreshing session with fresh MCP servers", {
|
|
9447
|
+
serverCount: Object.keys(mcpServers).length,
|
|
9448
|
+
sessionId: this.sessionId
|
|
9449
|
+
});
|
|
9450
|
+
prev.abortController.abort();
|
|
9451
|
+
await prev.query.interrupt();
|
|
9452
|
+
prev.input.end();
|
|
9453
|
+
const newAbortController = new AbortController();
|
|
9454
|
+
const { sessionId: _drop, ...rest } = prev.queryOptions;
|
|
9455
|
+
const newOptions = {
|
|
9456
|
+
...rest,
|
|
9457
|
+
mcpServers,
|
|
9458
|
+
resume: this.sessionId,
|
|
9459
|
+
forkSession: false,
|
|
9460
|
+
abortController: newAbortController
|
|
9461
|
+
};
|
|
9462
|
+
const newInput = new Pushable();
|
|
9463
|
+
const newQuery = (0, import_claude_agent_sdk.query)({ prompt: newInput, options: newOptions });
|
|
9464
|
+
prev.query = newQuery;
|
|
9465
|
+
prev.input = newInput;
|
|
9466
|
+
prev.queryOptions = newOptions;
|
|
9467
|
+
prev.abortController = newAbortController;
|
|
9468
|
+
const result = await withTimeout(
|
|
9469
|
+
newQuery.initializationResult(),
|
|
9470
|
+
SESSION_VALIDATION_TIMEOUT_MS
|
|
9471
|
+
);
|
|
9472
|
+
if (result.result === "timeout") {
|
|
9473
|
+
throw new Error(`Session refresh timed out for ${this.sessionId}`);
|
|
9474
|
+
}
|
|
9475
|
+
this.deferBackgroundFetches(newQuery);
|
|
9476
|
+
}
|
|
9375
9477
|
async unstable_setSessionModel(params) {
|
|
9376
9478
|
await this.session.query.setModel(toSdkModelId(params.modelId));
|
|
9377
9479
|
this.session.modelId = params.modelId;
|