@posthog/agent 2.3.15 → 2.3.21

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.
@@ -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.15",
907
+ version: "2.3.21",
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 fs3 = __toESM(require("fs"), 1);
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 && options?.cachedFileContent && filePath in options.cachedFileContent) {
1831
- const oldContent = options.cachedFileContent[filePath];
1832
- const newContent = input?.replace_all ? oldContent.replaceAll(oldText ?? "", newText) : oldContent.replace(oldText ?? "", newText);
1833
- oldText = oldContent;
1834
- newText = newContent;
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)) {
@@ -3434,30 +3458,46 @@ 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 fs = __toESM(require("fs"), 1);
3461
+ var fs2 = __toESM(require("fs"), 1);
3438
3462
  var os2 = __toESM(require("os"), 1);
3439
3463
  var path3 = __toESM(require("path"), 1);
3440
- var BRANCH_NAMING_INSTRUCTIONS = `
3464
+
3465
+ // src/adapters/claude/session/instructions.ts
3466
+ var BRANCH_NAMING = `
3441
3467
  # Branch Naming
3442
3468
 
3443
3469
  When working in a detached HEAD state, create a descriptive branch name based on the work being done before committing. Do this automatically without asking the user.
3444
3470
  `;
3471
+ var PLAN_MODE = `
3472
+ # Plan Mode
3473
+
3474
+ Only enter plan mode (EnterPlanMode) when the user is requesting a significant change in approach or direction mid-task. Do NOT enter plan mode for:
3475
+ - Confirmations or approvals ("yes", "looks good", "continue", "go ahead")
3476
+ - Minor clarifications or small adjustments
3477
+ - Answers to questions you asked (unless you are still in the initial planning phase and have not yet started executing)
3478
+ - Feedback that does not require replanning
3479
+
3480
+ When in doubt, continue executing and incorporate the feedback inline.
3481
+ `;
3482
+ var APPENDED_INSTRUCTIONS = BRANCH_NAMING + PLAN_MODE;
3483
+
3484
+ // src/adapters/claude/session/options.ts
3445
3485
  function buildSystemPrompt(customPrompt) {
3446
3486
  const defaultPrompt = {
3447
3487
  type: "preset",
3448
3488
  preset: "claude_code",
3449
- append: BRANCH_NAMING_INSTRUCTIONS
3489
+ append: APPENDED_INSTRUCTIONS
3450
3490
  };
3451
3491
  if (!customPrompt) {
3452
3492
  return defaultPrompt;
3453
3493
  }
3454
3494
  if (typeof customPrompt === "string") {
3455
- return customPrompt + BRANCH_NAMING_INSTRUCTIONS;
3495
+ return customPrompt + APPENDED_INSTRUCTIONS;
3456
3496
  }
3457
3497
  if (typeof customPrompt === "object" && customPrompt !== null && "append" in customPrompt && typeof customPrompt.append === "string") {
3458
3498
  return {
3459
3499
  ...defaultPrompt,
3460
- append: customPrompt.append + BRANCH_NAMING_INSTRUCTIONS
3500
+ append: customPrompt.append + APPENDED_INSTRUCTIONS
3461
3501
  };
3462
3502
  }
3463
3503
  return defaultPrompt;
@@ -3569,9 +3609,9 @@ function ensureLocalSettings(cwd) {
3569
3609
  const claudeDir = path3.join(cwd, ".claude");
3570
3610
  const localSettingsPath = path3.join(claudeDir, "settings.local.json");
3571
3611
  try {
3572
- if (!fs.existsSync(localSettingsPath)) {
3573
- fs.mkdirSync(claudeDir, { recursive: true });
3574
- fs.writeFileSync(localSettingsPath, "{}\n", { flag: "wx" });
3612
+ if (!fs2.existsSync(localSettingsPath)) {
3613
+ fs2.mkdirSync(claudeDir, { recursive: true });
3614
+ fs2.writeFileSync(localSettingsPath, "{}\n", { flag: "wx" });
3575
3615
  }
3576
3616
  } catch {
3577
3617
  }
@@ -3642,12 +3682,12 @@ function clearStatsigCache() {
3642
3682
  process.env.CLAUDE_CONFIG_DIR || path3.join(os2.homedir(), ".claude"),
3643
3683
  "statsig"
3644
3684
  );
3645
- fs.rm(statsigPath, { recursive: true, force: true }, () => {
3685
+ fs2.rm(statsigPath, { recursive: true, force: true }, () => {
3646
3686
  });
3647
3687
  }
3648
3688
 
3649
3689
  // src/adapters/claude/session/settings.ts
3650
- var fs2 = __toESM(require("fs"), 1);
3690
+ var fs3 = __toESM(require("fs"), 1);
3651
3691
  var os3 = __toESM(require("os"), 1);
3652
3692
  var path4 = __toESM(require("path"), 1);
3653
3693
  var import_minimatch = require("minimatch");
@@ -3742,7 +3782,7 @@ async function loadSettingsFile(filePath) {
3742
3782
  return {};
3743
3783
  }
3744
3784
  try {
3745
- const content = await fs2.promises.readFile(filePath, "utf-8");
3785
+ const content = await fs3.promises.readFile(filePath, "utf-8");
3746
3786
  return JSON.parse(content);
3747
3787
  } catch {
3748
3788
  return {};
@@ -3951,7 +3991,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3951
3991
  };
3952
3992
  }
3953
3993
  async newSession(params) {
3954
- if (fs3.existsSync(path5.resolve(os4.homedir(), ".claude.json.backup")) && !fs3.existsSync(path5.resolve(os4.homedir(), ".claude.json"))) {
3994
+ if (fs4.existsSync(path5.resolve(os4.homedir(), ".claude.json.backup")) && !fs4.existsSync(path5.resolve(os4.homedir(), ".claude.json"))) {
3955
3995
  throw import_sdk2.RequestError.authRequired();
3956
3996
  }
3957
3997
  const response = await this.createSession(params, {
@@ -4581,7 +4621,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
4581
4621
 
4582
4622
  // src/adapters/codex/spawn.ts
4583
4623
  var import_node_child_process2 = require("child_process");
4584
- var import_node_fs = require("fs");
4624
+ var import_node_fs2 = require("fs");
4585
4625
  var import_node_path2 = require("path");
4586
4626
  function buildConfigArgs(options) {
4587
4627
  const args = [];
@@ -4603,7 +4643,7 @@ function buildConfigArgs(options) {
4603
4643
  }
4604
4644
  function findCodexBinary(options) {
4605
4645
  const configArgs = buildConfigArgs(options);
4606
- if (options.binaryPath && (0, import_node_fs.existsSync)(options.binaryPath)) {
4646
+ if (options.binaryPath && (0, import_node_fs2.existsSync)(options.binaryPath)) {
4607
4647
  return { command: options.binaryPath, args: configArgs };
4608
4648
  }
4609
4649
  if (options.binaryPath) {
@@ -4622,7 +4662,7 @@ function spawnCodexProcess(options) {
4622
4662
  env.POSTHOG_GATEWAY_API_KEY = options.apiKey;
4623
4663
  }
4624
4664
  const { command, args } = findCodexBinary(options);
4625
- if (options.binaryPath && (0, import_node_fs.existsSync)(options.binaryPath)) {
4665
+ if (options.binaryPath && (0, import_node_fs2.existsSync)(options.binaryPath)) {
4626
4666
  const binDir = (0, import_node_path2.dirname)(options.binaryPath);
4627
4667
  env.PATH = `${binDir}${import_node_path2.delimiter}${env.PATH ?? ""}`;
4628
4668
  }
@@ -5021,7 +5061,7 @@ function createCodexConnection(config) {
5021
5061
 
5022
5062
  // src/adapters/claude/session/jsonl-hydration.ts
5023
5063
  var import_node_crypto2 = require("crypto");
5024
- var fs4 = __toESM(require("fs/promises"), 1);
5064
+ var fs5 = __toESM(require("fs/promises"), 1);
5025
5065
  var os5 = __toESM(require("os"), 1);
5026
5066
  var path6 = __toESM(require("path"), 1);
5027
5067
  var CHARS_PER_TOKEN = 4;
@@ -5369,7 +5409,7 @@ var Saga = class {
5369
5409
  };
5370
5410
 
5371
5411
  // ../git/dist/queries.js
5372
- var fs6 = __toESM(require("fs/promises"), 1);
5412
+ var fs7 = __toESM(require("fs/promises"), 1);
5373
5413
  var path8 = __toESM(require("path"), 1);
5374
5414
 
5375
5415
  // ../../node_modules/simple-git/dist/esm/index.js
@@ -10129,8 +10169,8 @@ var import_promises2 = require("fs/promises");
10129
10169
  var import_node_path5 = require("path");
10130
10170
 
10131
10171
  // ../git/dist/sagas/tree.js
10132
- var import_node_fs2 = require("fs");
10133
- var fs7 = __toESM(require("fs/promises"), 1);
10172
+ var import_node_fs3 = require("fs");
10173
+ var fs8 = __toESM(require("fs/promises"), 1);
10134
10174
  var path9 = __toESM(require("path"), 1);
10135
10175
  var tar = __toESM(require("tar"), 1);
10136
10176
 
@@ -10161,7 +10201,7 @@ var CaptureTreeSaga = class extends GitSaga {
10161
10201
  const tmpDir = path9.join(baseDir, ".git", "posthog-code-tmp");
10162
10202
  await this.step({
10163
10203
  name: "create_tmp_dir",
10164
- execute: () => fs7.mkdir(tmpDir, { recursive: true }),
10204
+ execute: () => fs8.mkdir(tmpDir, { recursive: true }),
10165
10205
  rollback: async () => {
10166
10206
  }
10167
10207
  });
@@ -10175,7 +10215,7 @@ var CaptureTreeSaga = class extends GitSaga {
10175
10215
  execute: () => tempIndexGit.raw(["read-tree", "HEAD"]),
10176
10216
  rollback: async () => {
10177
10217
  if (this.tempIndexPath) {
10178
- await fs7.rm(this.tempIndexPath, { force: true }).catch(() => {
10218
+ await fs8.rm(this.tempIndexPath, { force: true }).catch(() => {
10179
10219
  });
10180
10220
  }
10181
10221
  }
@@ -10184,7 +10224,7 @@ var CaptureTreeSaga = class extends GitSaga {
10184
10224
  const treeHash = await this.readOnlyStep("write_tree", () => tempIndexGit.raw(["write-tree"]));
10185
10225
  if (lastTreeHash && treeHash === lastTreeHash) {
10186
10226
  this.log.debug("No changes since last capture", { treeHash });
10187
- await fs7.rm(this.tempIndexPath, { force: true }).catch(() => {
10227
+ await fs8.rm(this.tempIndexPath, { force: true }).catch(() => {
10188
10228
  });
10189
10229
  return { snapshot: null, changed: false };
10190
10230
  }
@@ -10196,7 +10236,7 @@ var CaptureTreeSaga = class extends GitSaga {
10196
10236
  }
10197
10237
  });
10198
10238
  const changes = await this.readOnlyStep("get_changes", () => this.getChanges(this.git, baseCommit, treeHash));
10199
- await fs7.rm(this.tempIndexPath, { force: true }).catch(() => {
10239
+ await fs8.rm(this.tempIndexPath, { force: true }).catch(() => {
10200
10240
  });
10201
10241
  const snapshot = {
10202
10242
  treeHash,
@@ -10220,7 +10260,7 @@ var CaptureTreeSaga = class extends GitSaga {
10220
10260
  if (filesToArchive.length === 0) {
10221
10261
  return void 0;
10222
10262
  }
10223
- const existingFiles = filesToArchive.filter((f) => (0, import_node_fs2.existsSync)(path9.join(baseDir, f)));
10263
+ const existingFiles = filesToArchive.filter((f) => (0, import_node_fs3.existsSync)(path9.join(baseDir, f)));
10224
10264
  if (existingFiles.length === 0) {
10225
10265
  return void 0;
10226
10266
  }
@@ -10228,7 +10268,7 @@ var CaptureTreeSaga = class extends GitSaga {
10228
10268
  name: "create_archive",
10229
10269
  execute: async () => {
10230
10270
  const archiveDir = path9.dirname(archivePath);
10231
- await fs7.mkdir(archiveDir, { recursive: true });
10271
+ await fs8.mkdir(archiveDir, { recursive: true });
10232
10272
  await tar.create({
10233
10273
  gzip: true,
10234
10274
  file: archivePath,
@@ -10236,7 +10276,7 @@ var CaptureTreeSaga = class extends GitSaga {
10236
10276
  }, existingFiles);
10237
10277
  },
10238
10278
  rollback: async () => {
10239
- await fs7.rm(archivePath, { force: true }).catch(() => {
10279
+ await fs8.rm(archivePath, { force: true }).catch(() => {
10240
10280
  });
10241
10281
  }
10242
10282
  });
@@ -10338,7 +10378,7 @@ var ApplyTreeSaga = class extends GitSaga {
10338
10378
  for (const filePath of filesToExtract) {
10339
10379
  const fullPath = path9.join(baseDir, filePath);
10340
10380
  try {
10341
- const content = await fs7.readFile(fullPath);
10381
+ const content = await fs8.readFile(fullPath);
10342
10382
  this.fileBackups.set(filePath, content);
10343
10383
  } catch {
10344
10384
  }
@@ -10359,12 +10399,12 @@ var ApplyTreeSaga = class extends GitSaga {
10359
10399
  const backup = this.fileBackups.get(filePath);
10360
10400
  if (backup) {
10361
10401
  const dir = path9.dirname(fullPath);
10362
- await fs7.mkdir(dir, { recursive: true }).catch(() => {
10402
+ await fs8.mkdir(dir, { recursive: true }).catch(() => {
10363
10403
  });
10364
- await fs7.writeFile(fullPath, backup).catch(() => {
10404
+ await fs8.writeFile(fullPath, backup).catch(() => {
10365
10405
  });
10366
10406
  } else {
10367
- await fs7.rm(fullPath, { force: true }).catch(() => {
10407
+ await fs8.rm(fullPath, { force: true }).catch(() => {
10368
10408
  });
10369
10409
  }
10370
10410
  }
@@ -10375,7 +10415,7 @@ var ApplyTreeSaga = class extends GitSaga {
10375
10415
  const fullPath = path9.join(baseDir, change.path);
10376
10416
  const backupContent = await this.readOnlyStep(`backup_${change.path}`, async () => {
10377
10417
  try {
10378
- return await fs7.readFile(fullPath);
10418
+ return await fs8.readFile(fullPath);
10379
10419
  } catch {
10380
10420
  return null;
10381
10421
  }
@@ -10383,15 +10423,15 @@ var ApplyTreeSaga = class extends GitSaga {
10383
10423
  await this.step({
10384
10424
  name: `delete_${change.path}`,
10385
10425
  execute: async () => {
10386
- await fs7.rm(fullPath, { force: true });
10426
+ await fs8.rm(fullPath, { force: true });
10387
10427
  this.log.debug(`Deleted file: ${change.path}`);
10388
10428
  },
10389
10429
  rollback: async () => {
10390
10430
  if (backupContent) {
10391
10431
  const dir = path9.dirname(fullPath);
10392
- await fs7.mkdir(dir, { recursive: true }).catch(() => {
10432
+ await fs8.mkdir(dir, { recursive: true }).catch(() => {
10393
10433
  });
10394
- await fs7.writeFile(fullPath, backupContent).catch(() => {
10434
+ await fs8.writeFile(fullPath, backupContent).catch(() => {
10395
10435
  });
10396
10436
  }
10397
10437
  }
@@ -10472,7 +10512,7 @@ var ApplySnapshotSaga = class extends Saga {
10472
10512
  };
10473
10513
 
10474
10514
  // src/sagas/capture-tree-saga.ts
10475
- var import_node_fs3 = require("fs");
10515
+ var import_node_fs4 = require("fs");
10476
10516
  var import_promises3 = require("fs/promises");
10477
10517
  var import_node_path6 = require("path");
10478
10518
  var CaptureTreeSaga2 = class extends Saga {
@@ -10487,7 +10527,7 @@ var CaptureTreeSaga2 = class extends Saga {
10487
10527
  runId
10488
10528
  } = input;
10489
10529
  const tmpDir = (0, import_node_path6.join)(repositoryPath, ".posthog", "tmp");
10490
- if ((0, import_node_fs3.existsSync)((0, import_node_path6.join)(repositoryPath, ".gitmodules"))) {
10530
+ if ((0, import_node_fs4.existsSync)((0, import_node_path6.join)(repositoryPath, ".gitmodules"))) {
10491
10531
  this.log.warn(
10492
10532
  "Repository has submodules - snapshot may not capture submodule state"
10493
10533
  );
@@ -10952,7 +10992,7 @@ async function resumeFromLog(config) {
10952
10992
  }
10953
10993
 
10954
10994
  // src/session-log-writer.ts
10955
- var import_node_fs4 = __toESM(require("fs"), 1);
10995
+ var import_node_fs5 = __toESM(require("fs"), 1);
10956
10996
  var import_promises4 = __toESM(require("fs/promises"), 1);
10957
10997
  var import_node_path7 = __toESM(require("path"), 1);
10958
10998
  var SessionLogWriter = class _SessionLogWriter {
@@ -10999,7 +11039,7 @@ var SessionLogWriter = class _SessionLogWriter {
10999
11039
  context.runId
11000
11040
  );
11001
11041
  try {
11002
- import_node_fs4.default.mkdirSync(sessionDir, { recursive: true });
11042
+ import_node_fs5.default.mkdirSync(sessionDir, { recursive: true });
11003
11043
  } catch (error) {
11004
11044
  this.logger.warn("Failed to create local cache directory", {
11005
11045
  sessionDir,
@@ -11209,7 +11249,7 @@ var SessionLogWriter = class _SessionLogWriter {
11209
11249
  "logs.ndjson"
11210
11250
  );
11211
11251
  try {
11212
- import_node_fs4.default.appendFileSync(logPath, `${JSON.stringify(entry)}
11252
+ import_node_fs5.default.appendFileSync(logPath, `${JSON.stringify(entry)}
11213
11253
  `);
11214
11254
  } catch (error) {
11215
11255
  this.logger.warn("Failed to write to local cache", {