@posthog/agent 2.3.18 → 2.3.22
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/adapters/claude/conversion/tool-use-to-acp.js +29 -5
- package/dist/adapters/claude/conversion/tool-use-to-acp.js.map +1 -1
- package/dist/agent.js +43 -19
- 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 +63 -39
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +67 -43
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude/conversion/tool-use-to-acp.ts +48 -12
- package/src/adapters/claude/permissions/permission-handlers.ts +1 -1
package/dist/server/bin.cjs
CHANGED
|
@@ -904,7 +904,7 @@ var import_hono = require("hono");
|
|
|
904
904
|
// package.json
|
|
905
905
|
var package_default = {
|
|
906
906
|
name: "@posthog/agent",
|
|
907
|
-
version: "2.3.
|
|
907
|
+
version: "2.3.22",
|
|
908
908
|
repository: "https://github.com/PostHog/code",
|
|
909
909
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
910
910
|
exports: {
|
|
@@ -1288,7 +1288,7 @@ function nodeWritableToWebWritable(nodeStream) {
|
|
|
1288
1288
|
|
|
1289
1289
|
// src/adapters/claude/claude-agent.ts
|
|
1290
1290
|
var import_node_crypto = require("crypto");
|
|
1291
|
-
var
|
|
1291
|
+
var fs4 = __toESM(require("fs"), 1);
|
|
1292
1292
|
var os4 = __toESM(require("os"), 1);
|
|
1293
1293
|
var path5 = __toESM(require("path"), 1);
|
|
1294
1294
|
var import_sdk2 = require("@agentclientprotocol/sdk");
|
|
@@ -1658,6 +1658,7 @@ var createPreToolUseHook = (settingsManager, logger) => async (input, _toolUseID
|
|
|
1658
1658
|
};
|
|
1659
1659
|
|
|
1660
1660
|
// src/adapters/claude/conversion/tool-use-to-acp.ts
|
|
1661
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
1661
1662
|
var import_node_path = __toESM(require("path"), 1);
|
|
1662
1663
|
|
|
1663
1664
|
// src/adapters/claude/mcp/tool-metadata.ts
|
|
@@ -1827,11 +1828,17 @@ function toolInfoFromToolUse(toolUse, options) {
|
|
|
1827
1828
|
const displayPath = filePath ? toDisplayPath(filePath, options?.cwd) : void 0;
|
|
1828
1829
|
let oldText = input?.old_string ? String(input.old_string) : null;
|
|
1829
1830
|
let newText = input?.new_string ? String(input.new_string) : "";
|
|
1830
|
-
if (filePath &&
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1831
|
+
if (filePath && oldText !== null) {
|
|
1832
|
+
const fileContent = resolveFileContent(
|
|
1833
|
+
filePath,
|
|
1834
|
+
oldText,
|
|
1835
|
+
options?.cachedFileContent
|
|
1836
|
+
);
|
|
1837
|
+
if (fileContent) {
|
|
1838
|
+
const newContent = input?.replace_all ? fileContent.replaceAll(oldText, newText) : fileContent.replace(oldText, newText);
|
|
1839
|
+
oldText = fileContent;
|
|
1840
|
+
newText = newContent;
|
|
1841
|
+
}
|
|
1835
1842
|
}
|
|
1836
1843
|
return {
|
|
1837
1844
|
title: displayPath ? `Edit \`${displayPath}\`` : "Edit",
|
|
@@ -2242,6 +2249,23 @@ function planEntries(input) {
|
|
|
2242
2249
|
priority: "medium"
|
|
2243
2250
|
}));
|
|
2244
2251
|
}
|
|
2252
|
+
function resolveFileContent(filePath, oldText, cachedFileContent) {
|
|
2253
|
+
if (cachedFileContent && filePath in cachedFileContent) {
|
|
2254
|
+
const cached = cachedFileContent[filePath];
|
|
2255
|
+
if (cached.includes(oldText)) {
|
|
2256
|
+
return cached;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
try {
|
|
2260
|
+
const content = import_node_fs.default.readFileSync(filePath, "utf-8");
|
|
2261
|
+
if (content.includes(oldText)) {
|
|
2262
|
+
return content;
|
|
2263
|
+
}
|
|
2264
|
+
} catch {
|
|
2265
|
+
return null;
|
|
2266
|
+
}
|
|
2267
|
+
return null;
|
|
2268
|
+
}
|
|
2245
2269
|
function markdownEscape(text2) {
|
|
2246
2270
|
let escapedText = "```";
|
|
2247
2271
|
for (const [m] of text2.matchAll(/^```+/gm)) {
|
|
@@ -3286,7 +3310,7 @@ async function handleDefaultPermissionFlow(context) {
|
|
|
3286
3310
|
kind: toolInfo.kind,
|
|
3287
3311
|
content: toolInfo.content,
|
|
3288
3312
|
locations: toolInfo.locations,
|
|
3289
|
-
rawInput: toolInput
|
|
3313
|
+
rawInput: { ...toolInput, toolName }
|
|
3290
3314
|
}
|
|
3291
3315
|
});
|
|
3292
3316
|
if (context.signal?.aborted || response.outcome?.outcome === "cancelled") {
|
|
@@ -3434,7 +3458,7 @@ function toSdkModelId(modelId) {
|
|
|
3434
3458
|
|
|
3435
3459
|
// src/adapters/claude/session/options.ts
|
|
3436
3460
|
var import_node_child_process = require("child_process");
|
|
3437
|
-
var
|
|
3461
|
+
var fs2 = __toESM(require("fs"), 1);
|
|
3438
3462
|
var os2 = __toESM(require("os"), 1);
|
|
3439
3463
|
var path3 = __toESM(require("path"), 1);
|
|
3440
3464
|
|
|
@@ -3585,9 +3609,9 @@ function ensureLocalSettings(cwd) {
|
|
|
3585
3609
|
const claudeDir = path3.join(cwd, ".claude");
|
|
3586
3610
|
const localSettingsPath = path3.join(claudeDir, "settings.local.json");
|
|
3587
3611
|
try {
|
|
3588
|
-
if (!
|
|
3589
|
-
|
|
3590
|
-
|
|
3612
|
+
if (!fs2.existsSync(localSettingsPath)) {
|
|
3613
|
+
fs2.mkdirSync(claudeDir, { recursive: true });
|
|
3614
|
+
fs2.writeFileSync(localSettingsPath, "{}\n", { flag: "wx" });
|
|
3591
3615
|
}
|
|
3592
3616
|
} catch {
|
|
3593
3617
|
}
|
|
@@ -3658,12 +3682,12 @@ function clearStatsigCache() {
|
|
|
3658
3682
|
process.env.CLAUDE_CONFIG_DIR || path3.join(os2.homedir(), ".claude"),
|
|
3659
3683
|
"statsig"
|
|
3660
3684
|
);
|
|
3661
|
-
|
|
3685
|
+
fs2.rm(statsigPath, { recursive: true, force: true }, () => {
|
|
3662
3686
|
});
|
|
3663
3687
|
}
|
|
3664
3688
|
|
|
3665
3689
|
// src/adapters/claude/session/settings.ts
|
|
3666
|
-
var
|
|
3690
|
+
var fs3 = __toESM(require("fs"), 1);
|
|
3667
3691
|
var os3 = __toESM(require("os"), 1);
|
|
3668
3692
|
var path4 = __toESM(require("path"), 1);
|
|
3669
3693
|
var import_minimatch = require("minimatch");
|
|
@@ -3758,7 +3782,7 @@ async function loadSettingsFile(filePath) {
|
|
|
3758
3782
|
return {};
|
|
3759
3783
|
}
|
|
3760
3784
|
try {
|
|
3761
|
-
const content = await
|
|
3785
|
+
const content = await fs3.promises.readFile(filePath, "utf-8");
|
|
3762
3786
|
return JSON.parse(content);
|
|
3763
3787
|
} catch {
|
|
3764
3788
|
return {};
|
|
@@ -3967,7 +3991,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
3967
3991
|
};
|
|
3968
3992
|
}
|
|
3969
3993
|
async newSession(params) {
|
|
3970
|
-
if (
|
|
3994
|
+
if (fs4.existsSync(path5.resolve(os4.homedir(), ".claude.json.backup")) && !fs4.existsSync(path5.resolve(os4.homedir(), ".claude.json"))) {
|
|
3971
3995
|
throw import_sdk2.RequestError.authRequired();
|
|
3972
3996
|
}
|
|
3973
3997
|
const response = await this.createSession(params, {
|
|
@@ -4597,7 +4621,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
4597
4621
|
|
|
4598
4622
|
// src/adapters/codex/spawn.ts
|
|
4599
4623
|
var import_node_child_process2 = require("child_process");
|
|
4600
|
-
var
|
|
4624
|
+
var import_node_fs2 = require("fs");
|
|
4601
4625
|
var import_node_path2 = require("path");
|
|
4602
4626
|
function buildConfigArgs(options) {
|
|
4603
4627
|
const args = [];
|
|
@@ -4619,7 +4643,7 @@ function buildConfigArgs(options) {
|
|
|
4619
4643
|
}
|
|
4620
4644
|
function findCodexBinary(options) {
|
|
4621
4645
|
const configArgs = buildConfigArgs(options);
|
|
4622
|
-
if (options.binaryPath && (0,
|
|
4646
|
+
if (options.binaryPath && (0, import_node_fs2.existsSync)(options.binaryPath)) {
|
|
4623
4647
|
return { command: options.binaryPath, args: configArgs };
|
|
4624
4648
|
}
|
|
4625
4649
|
if (options.binaryPath) {
|
|
@@ -4638,7 +4662,7 @@ function spawnCodexProcess(options) {
|
|
|
4638
4662
|
env.POSTHOG_GATEWAY_API_KEY = options.apiKey;
|
|
4639
4663
|
}
|
|
4640
4664
|
const { command, args } = findCodexBinary(options);
|
|
4641
|
-
if (options.binaryPath && (0,
|
|
4665
|
+
if (options.binaryPath && (0, import_node_fs2.existsSync)(options.binaryPath)) {
|
|
4642
4666
|
const binDir = (0, import_node_path2.dirname)(options.binaryPath);
|
|
4643
4667
|
env.PATH = `${binDir}${import_node_path2.delimiter}${env.PATH ?? ""}`;
|
|
4644
4668
|
}
|
|
@@ -5037,7 +5061,7 @@ function createCodexConnection(config) {
|
|
|
5037
5061
|
|
|
5038
5062
|
// src/adapters/claude/session/jsonl-hydration.ts
|
|
5039
5063
|
var import_node_crypto2 = require("crypto");
|
|
5040
|
-
var
|
|
5064
|
+
var fs5 = __toESM(require("fs/promises"), 1);
|
|
5041
5065
|
var os5 = __toESM(require("os"), 1);
|
|
5042
5066
|
var path6 = __toESM(require("path"), 1);
|
|
5043
5067
|
var CHARS_PER_TOKEN = 4;
|
|
@@ -5385,7 +5409,7 @@ var Saga = class {
|
|
|
5385
5409
|
};
|
|
5386
5410
|
|
|
5387
5411
|
// ../git/dist/queries.js
|
|
5388
|
-
var
|
|
5412
|
+
var fs7 = __toESM(require("fs/promises"), 1);
|
|
5389
5413
|
var path8 = __toESM(require("path"), 1);
|
|
5390
5414
|
|
|
5391
5415
|
// ../../node_modules/simple-git/dist/esm/index.js
|
|
@@ -10145,8 +10169,8 @@ var import_promises2 = require("fs/promises");
|
|
|
10145
10169
|
var import_node_path5 = require("path");
|
|
10146
10170
|
|
|
10147
10171
|
// ../git/dist/sagas/tree.js
|
|
10148
|
-
var
|
|
10149
|
-
var
|
|
10172
|
+
var import_node_fs3 = require("fs");
|
|
10173
|
+
var fs8 = __toESM(require("fs/promises"), 1);
|
|
10150
10174
|
var path9 = __toESM(require("path"), 1);
|
|
10151
10175
|
var tar = __toESM(require("tar"), 1);
|
|
10152
10176
|
|
|
@@ -10177,7 +10201,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10177
10201
|
const tmpDir = path9.join(baseDir, ".git", "posthog-code-tmp");
|
|
10178
10202
|
await this.step({
|
|
10179
10203
|
name: "create_tmp_dir",
|
|
10180
|
-
execute: () =>
|
|
10204
|
+
execute: () => fs8.mkdir(tmpDir, { recursive: true }),
|
|
10181
10205
|
rollback: async () => {
|
|
10182
10206
|
}
|
|
10183
10207
|
});
|
|
@@ -10191,7 +10215,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10191
10215
|
execute: () => tempIndexGit.raw(["read-tree", "HEAD"]),
|
|
10192
10216
|
rollback: async () => {
|
|
10193
10217
|
if (this.tempIndexPath) {
|
|
10194
|
-
await
|
|
10218
|
+
await fs8.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
10195
10219
|
});
|
|
10196
10220
|
}
|
|
10197
10221
|
}
|
|
@@ -10200,7 +10224,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10200
10224
|
const treeHash = await this.readOnlyStep("write_tree", () => tempIndexGit.raw(["write-tree"]));
|
|
10201
10225
|
if (lastTreeHash && treeHash === lastTreeHash) {
|
|
10202
10226
|
this.log.debug("No changes since last capture", { treeHash });
|
|
10203
|
-
await
|
|
10227
|
+
await fs8.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
10204
10228
|
});
|
|
10205
10229
|
return { snapshot: null, changed: false };
|
|
10206
10230
|
}
|
|
@@ -10212,7 +10236,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10212
10236
|
}
|
|
10213
10237
|
});
|
|
10214
10238
|
const changes = await this.readOnlyStep("get_changes", () => this.getChanges(this.git, baseCommit, treeHash));
|
|
10215
|
-
await
|
|
10239
|
+
await fs8.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
10216
10240
|
});
|
|
10217
10241
|
const snapshot = {
|
|
10218
10242
|
treeHash,
|
|
@@ -10236,7 +10260,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10236
10260
|
if (filesToArchive.length === 0) {
|
|
10237
10261
|
return void 0;
|
|
10238
10262
|
}
|
|
10239
|
-
const existingFiles = filesToArchive.filter((f) => (0,
|
|
10263
|
+
const existingFiles = filesToArchive.filter((f) => (0, import_node_fs3.existsSync)(path9.join(baseDir, f)));
|
|
10240
10264
|
if (existingFiles.length === 0) {
|
|
10241
10265
|
return void 0;
|
|
10242
10266
|
}
|
|
@@ -10244,7 +10268,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10244
10268
|
name: "create_archive",
|
|
10245
10269
|
execute: async () => {
|
|
10246
10270
|
const archiveDir = path9.dirname(archivePath);
|
|
10247
|
-
await
|
|
10271
|
+
await fs8.mkdir(archiveDir, { recursive: true });
|
|
10248
10272
|
await tar.create({
|
|
10249
10273
|
gzip: true,
|
|
10250
10274
|
file: archivePath,
|
|
@@ -10252,7 +10276,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10252
10276
|
}, existingFiles);
|
|
10253
10277
|
},
|
|
10254
10278
|
rollback: async () => {
|
|
10255
|
-
await
|
|
10279
|
+
await fs8.rm(archivePath, { force: true }).catch(() => {
|
|
10256
10280
|
});
|
|
10257
10281
|
}
|
|
10258
10282
|
});
|
|
@@ -10354,7 +10378,7 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10354
10378
|
for (const filePath of filesToExtract) {
|
|
10355
10379
|
const fullPath = path9.join(baseDir, filePath);
|
|
10356
10380
|
try {
|
|
10357
|
-
const content = await
|
|
10381
|
+
const content = await fs8.readFile(fullPath);
|
|
10358
10382
|
this.fileBackups.set(filePath, content);
|
|
10359
10383
|
} catch {
|
|
10360
10384
|
}
|
|
@@ -10375,12 +10399,12 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10375
10399
|
const backup = this.fileBackups.get(filePath);
|
|
10376
10400
|
if (backup) {
|
|
10377
10401
|
const dir = path9.dirname(fullPath);
|
|
10378
|
-
await
|
|
10402
|
+
await fs8.mkdir(dir, { recursive: true }).catch(() => {
|
|
10379
10403
|
});
|
|
10380
|
-
await
|
|
10404
|
+
await fs8.writeFile(fullPath, backup).catch(() => {
|
|
10381
10405
|
});
|
|
10382
10406
|
} else {
|
|
10383
|
-
await
|
|
10407
|
+
await fs8.rm(fullPath, { force: true }).catch(() => {
|
|
10384
10408
|
});
|
|
10385
10409
|
}
|
|
10386
10410
|
}
|
|
@@ -10391,7 +10415,7 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10391
10415
|
const fullPath = path9.join(baseDir, change.path);
|
|
10392
10416
|
const backupContent = await this.readOnlyStep(`backup_${change.path}`, async () => {
|
|
10393
10417
|
try {
|
|
10394
|
-
return await
|
|
10418
|
+
return await fs8.readFile(fullPath);
|
|
10395
10419
|
} catch {
|
|
10396
10420
|
return null;
|
|
10397
10421
|
}
|
|
@@ -10399,15 +10423,15 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10399
10423
|
await this.step({
|
|
10400
10424
|
name: `delete_${change.path}`,
|
|
10401
10425
|
execute: async () => {
|
|
10402
|
-
await
|
|
10426
|
+
await fs8.rm(fullPath, { force: true });
|
|
10403
10427
|
this.log.debug(`Deleted file: ${change.path}`);
|
|
10404
10428
|
},
|
|
10405
10429
|
rollback: async () => {
|
|
10406
10430
|
if (backupContent) {
|
|
10407
10431
|
const dir = path9.dirname(fullPath);
|
|
10408
|
-
await
|
|
10432
|
+
await fs8.mkdir(dir, { recursive: true }).catch(() => {
|
|
10409
10433
|
});
|
|
10410
|
-
await
|
|
10434
|
+
await fs8.writeFile(fullPath, backupContent).catch(() => {
|
|
10411
10435
|
});
|
|
10412
10436
|
}
|
|
10413
10437
|
}
|
|
@@ -10488,7 +10512,7 @@ var ApplySnapshotSaga = class extends Saga {
|
|
|
10488
10512
|
};
|
|
10489
10513
|
|
|
10490
10514
|
// src/sagas/capture-tree-saga.ts
|
|
10491
|
-
var
|
|
10515
|
+
var import_node_fs4 = require("fs");
|
|
10492
10516
|
var import_promises3 = require("fs/promises");
|
|
10493
10517
|
var import_node_path6 = require("path");
|
|
10494
10518
|
var CaptureTreeSaga2 = class extends Saga {
|
|
@@ -10503,7 +10527,7 @@ var CaptureTreeSaga2 = class extends Saga {
|
|
|
10503
10527
|
runId
|
|
10504
10528
|
} = input;
|
|
10505
10529
|
const tmpDir = (0, import_node_path6.join)(repositoryPath, ".posthog", "tmp");
|
|
10506
|
-
if ((0,
|
|
10530
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path6.join)(repositoryPath, ".gitmodules"))) {
|
|
10507
10531
|
this.log.warn(
|
|
10508
10532
|
"Repository has submodules - snapshot may not capture submodule state"
|
|
10509
10533
|
);
|
|
@@ -10968,7 +10992,7 @@ async function resumeFromLog(config) {
|
|
|
10968
10992
|
}
|
|
10969
10993
|
|
|
10970
10994
|
// src/session-log-writer.ts
|
|
10971
|
-
var
|
|
10995
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
10972
10996
|
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
10973
10997
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
10974
10998
|
var SessionLogWriter = class _SessionLogWriter {
|
|
@@ -11015,7 +11039,7 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
11015
11039
|
context.runId
|
|
11016
11040
|
);
|
|
11017
11041
|
try {
|
|
11018
|
-
|
|
11042
|
+
import_node_fs5.default.mkdirSync(sessionDir, { recursive: true });
|
|
11019
11043
|
} catch (error) {
|
|
11020
11044
|
this.logger.warn("Failed to create local cache directory", {
|
|
11021
11045
|
sessionDir,
|
|
@@ -11225,7 +11249,7 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
11225
11249
|
"logs.ndjson"
|
|
11226
11250
|
);
|
|
11227
11251
|
try {
|
|
11228
|
-
|
|
11252
|
+
import_node_fs5.default.appendFileSync(logPath, `${JSON.stringify(entry)}
|
|
11229
11253
|
`);
|
|
11230
11254
|
} catch (error) {
|
|
11231
11255
|
this.logger.warn("Failed to write to local cache", {
|