@posthog/agent 2.3.312 → 2.3.316
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 +108 -6
- 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 +108 -6
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +106 -5
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/codex/codex-agent.refresh.test.ts +289 -0
- package/src/adapters/codex/codex-agent.ts +146 -4
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.316",
|
|
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: {
|
|
@@ -10363,11 +10363,18 @@ var CodexAcpAgent = class extends BaseAcpAgent {
|
|
|
10363
10363
|
* single-owner.
|
|
10364
10364
|
*/
|
|
10365
10365
|
promptMutex = Promise.resolve();
|
|
10366
|
+
codexProcessOptions;
|
|
10367
|
+
processCallbacks;
|
|
10368
|
+
// Snapshot of the initialize() request so refreshSession can replay the
|
|
10369
|
+
// same handshake against a respawned codex-acp subprocess.
|
|
10370
|
+
lastInitRequest;
|
|
10366
10371
|
constructor(client, options) {
|
|
10367
10372
|
super(client);
|
|
10368
10373
|
this.logger = new Logger({ debug: true, prefix: "[CodexAcpAgent]" });
|
|
10369
10374
|
const cwd = options.codexProcessOptions.cwd ?? process.cwd();
|
|
10370
10375
|
const settingsManager = new CodexSettingsManager(cwd);
|
|
10376
|
+
this.codexProcessOptions = options.codexProcessOptions;
|
|
10377
|
+
this.processCallbacks = options.processCallbacks;
|
|
10371
10378
|
this.codexProcess = spawnCodexProcess({
|
|
10372
10379
|
...options.codexProcessOptions,
|
|
10373
10380
|
settings: settingsManager.getSettings(),
|
|
@@ -10382,7 +10389,8 @@ var CodexAcpAgent = class extends BaseAcpAgent {
|
|
|
10382
10389
|
abortController,
|
|
10383
10390
|
settingsManager,
|
|
10384
10391
|
notificationHistory: [],
|
|
10385
|
-
cancelled: false
|
|
10392
|
+
cancelled: false,
|
|
10393
|
+
promptRunning: false
|
|
10386
10394
|
};
|
|
10387
10395
|
this.sessionState = createSessionState("", cwd);
|
|
10388
10396
|
this.codexConnection = new import_sdk3.ClientSideConnection(
|
|
@@ -10392,6 +10400,7 @@ var CodexAcpAgent = class extends BaseAcpAgent {
|
|
|
10392
10400
|
}
|
|
10393
10401
|
async initialize(request) {
|
|
10394
10402
|
await this.session.settingsManager.initialize();
|
|
10403
|
+
this.lastInitRequest = request;
|
|
10395
10404
|
const response = await this.codexConnection.initialize(request);
|
|
10396
10405
|
return {
|
|
10397
10406
|
...response,
|
|
@@ -10560,9 +10569,13 @@ var CodexAcpAgent = class extends BaseAcpAgent {
|
|
|
10560
10569
|
this.session.interruptReason = void 0;
|
|
10561
10570
|
resetUsage(this.sessionState);
|
|
10562
10571
|
await this.broadcastUserMessage(params);
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10572
|
+
this.session.promptRunning = true;
|
|
10573
|
+
let response;
|
|
10574
|
+
try {
|
|
10575
|
+
response = await this.codexConnection.prompt(prependPrContext(params));
|
|
10576
|
+
} finally {
|
|
10577
|
+
this.session.promptRunning = false;
|
|
10578
|
+
}
|
|
10566
10579
|
if (this.sessionState.taskRunId) {
|
|
10567
10580
|
const { accumulatedUsage } = this.sessionState;
|
|
10568
10581
|
await this.client.extNotification(POSTHOG_NOTIFICATIONS.TURN_COMPLETE, {
|
|
@@ -10609,6 +10622,94 @@ var CodexAcpAgent = class extends BaseAcpAgent {
|
|
|
10609
10622
|
this.appendNotification(params.sessionId, notification);
|
|
10610
10623
|
}
|
|
10611
10624
|
}
|
|
10625
|
+
/**
|
|
10626
|
+
* Refresh the session between turns. Currently the only refreshable field
|
|
10627
|
+
* is `mcpServers`. Unlike Claude (where we rebuild an in-process Query with
|
|
10628
|
+
* `resume`), Codex runs as a `codex-acp` subprocess whose MCP set is bound
|
|
10629
|
+
* at `newSession`/`loadSession` time and whose user-local MCPs are disabled
|
|
10630
|
+
* via spawn-time `-c mcp_servers.<name>.enabled=false` CLI args. To
|
|
10631
|
+
* guarantee the caller-supplied set fully wins, we respawn the subprocess
|
|
10632
|
+
* and rehydrate the session via `loadSession` — codex-acp persists sessions
|
|
10633
|
+
* to disk, so conversation history is preserved.
|
|
10634
|
+
*
|
|
10635
|
+
* This is an `extMethod` (request/response), not `extNotification`, so the
|
|
10636
|
+
* caller can await completion before sending the next prompt.
|
|
10637
|
+
*
|
|
10638
|
+
* Caller contract: only call REFRESH_SESSION between turns (no prompt in flight).
|
|
10639
|
+
*/
|
|
10640
|
+
async extMethod(method, params) {
|
|
10641
|
+
if (!isMethod(method, POSTHOG_METHODS.REFRESH_SESSION)) {
|
|
10642
|
+
throw import_sdk3.RequestError.methodNotFound(method);
|
|
10643
|
+
}
|
|
10644
|
+
if (params.mcpServers === void 0) {
|
|
10645
|
+
throw new import_sdk3.RequestError(
|
|
10646
|
+
-32602,
|
|
10647
|
+
"refresh_session requires at least one refreshable field (e.g. mcpServers)"
|
|
10648
|
+
);
|
|
10649
|
+
}
|
|
10650
|
+
if (!Array.isArray(params.mcpServers)) {
|
|
10651
|
+
throw new import_sdk3.RequestError(
|
|
10652
|
+
-32602,
|
|
10653
|
+
"refresh_session: mcpServers must be an array"
|
|
10654
|
+
);
|
|
10655
|
+
}
|
|
10656
|
+
await this.refreshSession(params.mcpServers);
|
|
10657
|
+
return { refreshed: true };
|
|
10658
|
+
}
|
|
10659
|
+
async refreshSession(mcpServers) {
|
|
10660
|
+
const prev = this.session;
|
|
10661
|
+
if (prev.promptRunning) {
|
|
10662
|
+
throw new import_sdk3.RequestError(
|
|
10663
|
+
-32002,
|
|
10664
|
+
"Cannot refresh session while a prompt turn is in flight"
|
|
10665
|
+
);
|
|
10666
|
+
}
|
|
10667
|
+
this.logger.info("Refreshing Codex session with fresh MCP servers", {
|
|
10668
|
+
serverCount: mcpServers.length,
|
|
10669
|
+
sessionId: this.sessionId
|
|
10670
|
+
});
|
|
10671
|
+
prev.abortController.abort();
|
|
10672
|
+
try {
|
|
10673
|
+
await this.codexConnection.cancel({ sessionId: this.sessionId });
|
|
10674
|
+
} catch (err) {
|
|
10675
|
+
this.logger.warn("cancel() during refresh failed (non-fatal)", {
|
|
10676
|
+
error: err
|
|
10677
|
+
});
|
|
10678
|
+
}
|
|
10679
|
+
this.codexProcess.kill();
|
|
10680
|
+
const cwd = prev.settingsManager.getCwd();
|
|
10681
|
+
const newSettingsManager = new CodexSettingsManager(cwd);
|
|
10682
|
+
await newSettingsManager.initialize();
|
|
10683
|
+
const newProcess = spawnCodexProcess({
|
|
10684
|
+
...this.codexProcessOptions,
|
|
10685
|
+
cwd,
|
|
10686
|
+
settings: newSettingsManager.getSettings(),
|
|
10687
|
+
logger: this.logger,
|
|
10688
|
+
processCallbacks: this.processCallbacks
|
|
10689
|
+
});
|
|
10690
|
+
const codexReadable = nodeReadableToWebReadable(newProcess.stdout);
|
|
10691
|
+
const codexWritable = nodeWritableToWebWritable(newProcess.stdin);
|
|
10692
|
+
const codexStream = (0, import_sdk3.ndJsonStream)(codexWritable, codexReadable);
|
|
10693
|
+
const newAbortController = new AbortController();
|
|
10694
|
+
const newConnection = new import_sdk3.ClientSideConnection(
|
|
10695
|
+
(_agent) => createCodexClient(this.client, this.logger, this.sessionState),
|
|
10696
|
+
codexStream
|
|
10697
|
+
);
|
|
10698
|
+
const initRequest = this.lastInitRequest ?? {
|
|
10699
|
+
protocolVersion: 1
|
|
10700
|
+
};
|
|
10701
|
+
await newConnection.initialize(initRequest);
|
|
10702
|
+
await newConnection.loadSession({
|
|
10703
|
+
sessionId: this.sessionId,
|
|
10704
|
+
cwd: this.sessionState.cwd,
|
|
10705
|
+
mcpServers
|
|
10706
|
+
});
|
|
10707
|
+
this.codexProcess = newProcess;
|
|
10708
|
+
this.codexConnection = newConnection;
|
|
10709
|
+
prev.settingsManager.dispose();
|
|
10710
|
+
prev.settingsManager = newSettingsManager;
|
|
10711
|
+
prev.abortController = newAbortController;
|
|
10712
|
+
}
|
|
10612
10713
|
async setSessionMode(params) {
|
|
10613
10714
|
const requestedMode = toCodexPermissionMode(params.modeId);
|
|
10614
10715
|
const nativeMode = toCodexNativeMode(params.modeId);
|