@posthog/agent 2.3.556 → 2.3.619
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 +64 -30
- package/dist/agent.js.map +1 -1
- package/dist/handoff-checkpoint.js +142 -117
- package/dist/handoff-checkpoint.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.d.ts +2 -1
- package/dist/server/agent-server.js +125 -69
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +136 -81
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/claude/conversion/sdk-to-acp.ts +1 -26
- package/src/adapters/codex/codex-agent.test.ts +83 -0
- package/src/adapters/codex/codex-agent.ts +16 -0
- package/src/adapters/error-classification.ts +30 -0
- package/src/server/agent-server.test.ts +17 -0
- package/src/server/agent-server.ts +28 -9
- package/src/server/question-relay.test.ts +67 -5
package/dist/agent.js
CHANGED
|
@@ -3699,12 +3699,12 @@ var require_src2 = __commonJS({
|
|
|
3699
3699
|
function check(path16, isFile2, isDirectory) {
|
|
3700
3700
|
log(`checking %s`, path16);
|
|
3701
3701
|
try {
|
|
3702
|
-
const
|
|
3703
|
-
if (
|
|
3702
|
+
const stat3 = fs_1.statSync(path16);
|
|
3703
|
+
if (stat3.isFile() && isFile2) {
|
|
3704
3704
|
log(`[OK] path represents a file`);
|
|
3705
3705
|
return true;
|
|
3706
3706
|
}
|
|
3707
|
-
if (
|
|
3707
|
+
if (stat3.isDirectory() && isDirectory) {
|
|
3708
3708
|
log(`[OK] path represents a directory`);
|
|
3709
3709
|
return true;
|
|
3710
3710
|
}
|
|
@@ -4030,7 +4030,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
4030
4030
|
// package.json
|
|
4031
4031
|
var package_default = {
|
|
4032
4032
|
name: "@posthog/agent",
|
|
4033
|
-
version: "2.3.
|
|
4033
|
+
version: "2.3.619",
|
|
4034
4034
|
repository: "https://github.com/PostHog/code",
|
|
4035
4035
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
4036
4036
|
exports: {
|
|
@@ -6347,8 +6347,7 @@ var ParserManager = class {
|
|
|
6347
6347
|
}
|
|
6348
6348
|
this.queryCache.set(cacheKey, query2);
|
|
6349
6349
|
return query2;
|
|
6350
|
-
} catch
|
|
6351
|
-
warn("Query compilation failed", err2);
|
|
6350
|
+
} catch {
|
|
6352
6351
|
this.failedQueries.add(cacheKey);
|
|
6353
6352
|
return null;
|
|
6354
6353
|
}
|
|
@@ -8207,9 +8206,9 @@ var PostHogEnricher = class {
|
|
|
8207
8206
|
}
|
|
8208
8207
|
let mtimeMs = 0;
|
|
8209
8208
|
try {
|
|
8210
|
-
const
|
|
8211
|
-
mtimeMs =
|
|
8212
|
-
if (
|
|
8209
|
+
const stat22 = await fs2.stat(absPath);
|
|
8210
|
+
mtimeMs = stat22.mtimeMs;
|
|
8211
|
+
if (stat22.size > MAX_WRAPPER_SOURCE_BYTES) {
|
|
8213
8212
|
return this.setWrapperCache(absPath, mtimeMs, []);
|
|
8214
8213
|
}
|
|
8215
8214
|
} catch {
|
|
@@ -8767,6 +8766,23 @@ function tryParsePartialJson(s) {
|
|
|
8767
8766
|
return null;
|
|
8768
8767
|
}
|
|
8769
8768
|
|
|
8769
|
+
// src/adapters/error-classification.ts
|
|
8770
|
+
var UPSTREAM_PROVIDER_ERROR_STATUS_PATTERN = /API Error:\s*(?:429|5\d\d)\b/i;
|
|
8771
|
+
function classifyAgentError(result) {
|
|
8772
|
+
if (!result) return "agent_error";
|
|
8773
|
+
const text2 = result.trim();
|
|
8774
|
+
if (/API Error:\s*terminated\b/i.test(text2)) {
|
|
8775
|
+
return "upstream_stream_terminated";
|
|
8776
|
+
}
|
|
8777
|
+
if (/API Error:\s*Connection error\b/i.test(text2)) {
|
|
8778
|
+
return "upstream_connection_error";
|
|
8779
|
+
}
|
|
8780
|
+
if (UPSTREAM_PROVIDER_ERROR_STATUS_PATTERN.test(text2)) {
|
|
8781
|
+
return "upstream_provider_failure";
|
|
8782
|
+
}
|
|
8783
|
+
return "agent_error";
|
|
8784
|
+
}
|
|
8785
|
+
|
|
8770
8786
|
// src/adapters/claude/permissions/posthog-exec-gate.ts
|
|
8771
8787
|
var POSTHOG_EXEC_TOOL_RE = /^mcp__posthog(?:_[^_]+)*__exec$/;
|
|
8772
8788
|
var POSTHOG_CALL_COMMAND_RE = /^\s*call\s+(?:--json\s+)?([a-zA-Z0-9_-]+)/;
|
|
@@ -10083,17 +10099,6 @@ async function handleSystemMessage(message, context) {
|
|
|
10083
10099
|
break;
|
|
10084
10100
|
}
|
|
10085
10101
|
}
|
|
10086
|
-
function classifyAgentError(result) {
|
|
10087
|
-
if (!result) return "agent_error";
|
|
10088
|
-
const text2 = result.trim();
|
|
10089
|
-
if (/API Error:\s*terminated\b/i.test(text2)) {
|
|
10090
|
-
return "upstream_stream_terminated";
|
|
10091
|
-
}
|
|
10092
|
-
if (/API Error:\s*Connection error\b/i.test(text2)) {
|
|
10093
|
-
return "upstream_connection_error";
|
|
10094
|
-
}
|
|
10095
|
-
return "agent_error";
|
|
10096
|
-
}
|
|
10097
10102
|
function handleResultMessage(message) {
|
|
10098
10103
|
const usage = extractUsageFromResult(message);
|
|
10099
10104
|
switch (message.subtype) {
|
|
@@ -11598,6 +11603,7 @@ var AsyncMutex = class {
|
|
|
11598
11603
|
};
|
|
11599
11604
|
|
|
11600
11605
|
// ../git/dist/queries.js
|
|
11606
|
+
import { createReadStream } from "fs";
|
|
11601
11607
|
import * as fs7 from "fs/promises";
|
|
11602
11608
|
import * as path11 from "path";
|
|
11603
11609
|
|
|
@@ -16149,13 +16155,20 @@ init_git_response_error();
|
|
|
16149
16155
|
var simpleGit = gitInstanceFactory;
|
|
16150
16156
|
|
|
16151
16157
|
// ../git/dist/client.js
|
|
16158
|
+
var PERFORMANCE_CONFIG = [
|
|
16159
|
+
"core.untrackedCache=true",
|
|
16160
|
+
"core.fsmonitor=true",
|
|
16161
|
+
"core.preloadIndex=true"
|
|
16162
|
+
];
|
|
16152
16163
|
function createGitClient(baseDir, options) {
|
|
16153
|
-
const { abortSignal: signal, ...rest } = options ?? {};
|
|
16164
|
+
const { abortSignal: signal, config: callerConfig, ...rest } = options ?? {};
|
|
16165
|
+
const config = callerConfig ? [...PERFORMANCE_CONFIG, ...callerConfig] : PERFORMANCE_CONFIG;
|
|
16154
16166
|
return simpleGit({
|
|
16155
16167
|
baseDir,
|
|
16156
16168
|
maxConcurrentProcesses: 6,
|
|
16157
16169
|
trimmed: true,
|
|
16158
16170
|
abort: signal,
|
|
16171
|
+
config,
|
|
16159
16172
|
...rest
|
|
16160
16173
|
});
|
|
16161
16174
|
}
|
|
@@ -16177,10 +16190,10 @@ async function getIndexLockPath(repoPath) {
|
|
|
16177
16190
|
async function getLockInfo(repoPath) {
|
|
16178
16191
|
const lockPath = await getIndexLockPath(repoPath);
|
|
16179
16192
|
try {
|
|
16180
|
-
const
|
|
16193
|
+
const stat3 = await fs6.stat(lockPath);
|
|
16181
16194
|
return {
|
|
16182
16195
|
path: lockPath,
|
|
16183
|
-
ageMs: Date.now() -
|
|
16196
|
+
ageMs: Date.now() - stat3.mtimeMs
|
|
16184
16197
|
};
|
|
16185
16198
|
} catch {
|
|
16186
16199
|
return null;
|
|
@@ -16308,14 +16321,18 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
|
|
|
16308
16321
|
}
|
|
16309
16322
|
async executeRead(repoPath, operation, options) {
|
|
16310
16323
|
const state = this.getRepoState(repoPath);
|
|
16324
|
+
const env = {
|
|
16325
|
+
...getCleanEnv(),
|
|
16326
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
16327
|
+
...options?.env
|
|
16328
|
+
};
|
|
16311
16329
|
if (options?.signal) {
|
|
16312
16330
|
const scopedGit = createGitClient(repoPath, {
|
|
16313
16331
|
abortSignal: options.signal
|
|
16314
16332
|
});
|
|
16315
|
-
return operation(scopedGit.env(
|
|
16333
|
+
return operation(scopedGit.env(env));
|
|
16316
16334
|
}
|
|
16317
|
-
|
|
16318
|
-
return operation(git);
|
|
16335
|
+
return operation(state.client.env(env));
|
|
16319
16336
|
}
|
|
16320
16337
|
async executeWrite(repoPath, operation, options) {
|
|
16321
16338
|
const state = this.getRepoState(repoPath);
|
|
@@ -16325,15 +16342,16 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
|
|
|
16325
16342
|
throw new Error(`Git repository is locked: ${repoPath}`);
|
|
16326
16343
|
}
|
|
16327
16344
|
}
|
|
16345
|
+
const env = { ...getCleanEnv(), ...options?.env };
|
|
16328
16346
|
await state.lock.acquireWrite();
|
|
16329
16347
|
try {
|
|
16330
16348
|
if (options?.signal) {
|
|
16331
16349
|
const scopedGit = createGitClient(repoPath, {
|
|
16332
16350
|
abortSignal: options.signal
|
|
16333
16351
|
});
|
|
16334
|
-
return await operation(scopedGit.env(
|
|
16352
|
+
return await operation(scopedGit.env(env));
|
|
16335
16353
|
}
|
|
16336
|
-
return await operation(state.client.env(
|
|
16354
|
+
return await operation(state.client.env(env));
|
|
16337
16355
|
} catch (error) {
|
|
16338
16356
|
if (options?.signal?.aborted) {
|
|
16339
16357
|
await removeLock(repoPath).catch(() => {
|
|
@@ -16360,6 +16378,9 @@ function getGitOperationManager() {
|
|
|
16360
16378
|
return instance2;
|
|
16361
16379
|
}
|
|
16362
16380
|
|
|
16381
|
+
// ../git/dist/status-stream.js
|
|
16382
|
+
import { spawn as spawn3 } from "child_process";
|
|
16383
|
+
|
|
16363
16384
|
// ../git/dist/queries.js
|
|
16364
16385
|
async function listWorktrees(baseDir, options) {
|
|
16365
16386
|
const manager = getGitOperationManager();
|
|
@@ -18197,7 +18218,7 @@ function parseCodexToml(content, cwd) {
|
|
|
18197
18218
|
}
|
|
18198
18219
|
|
|
18199
18220
|
// src/adapters/codex/spawn.ts
|
|
18200
|
-
import { spawn as
|
|
18221
|
+
import { spawn as spawn4 } from "child_process";
|
|
18201
18222
|
import { existsSync as existsSync4 } from "fs";
|
|
18202
18223
|
import { delimiter, dirname as dirname5 } from "path";
|
|
18203
18224
|
function buildConfigArgs(options) {
|
|
@@ -18261,7 +18282,7 @@ function spawnCodexProcess(options) {
|
|
|
18261
18282
|
hasApiKey: !!options.apiKey,
|
|
18262
18283
|
binaryPath: options.binaryPath
|
|
18263
18284
|
});
|
|
18264
|
-
const child =
|
|
18285
|
+
const child = spawn4(command, args2, {
|
|
18265
18286
|
cwd: options.cwd,
|
|
18266
18287
|
env,
|
|
18267
18288
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -18319,6 +18340,17 @@ function prependPrContext(params) {
|
|
|
18319
18340
|
prompt: [{ type: "text", text: prContext }, ...params.prompt]
|
|
18320
18341
|
};
|
|
18321
18342
|
}
|
|
18343
|
+
function classifyPromptError(error) {
|
|
18344
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
18345
|
+
const classification = classifyAgentError(message);
|
|
18346
|
+
if (classification === "agent_error") {
|
|
18347
|
+
return error;
|
|
18348
|
+
}
|
|
18349
|
+
return RequestError3.internalError(
|
|
18350
|
+
{ classification, result: message },
|
|
18351
|
+
message
|
|
18352
|
+
);
|
|
18353
|
+
}
|
|
18322
18354
|
var CODEX_NATIVE_MODE = {
|
|
18323
18355
|
auto: "auto",
|
|
18324
18356
|
default: "auto",
|
|
@@ -18648,6 +18680,8 @@ var CodexAcpAgent = class extends BaseAcpAgent {
|
|
|
18648
18680
|
let response;
|
|
18649
18681
|
try {
|
|
18650
18682
|
response = await this.codexConnection.prompt(prependPrContext(params));
|
|
18683
|
+
} catch (error) {
|
|
18684
|
+
throw classifyPromptError(error);
|
|
18651
18685
|
} finally {
|
|
18652
18686
|
this.session.promptRunning = false;
|
|
18653
18687
|
}
|