@posthog/agent 2.1.48 → 2.1.53

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.
@@ -805,10 +805,10 @@ var require_src2 = __commonJS({
805
805
  var fs_1 = require("fs");
806
806
  var debug_1 = __importDefault(require_src());
807
807
  var log = debug_1.default("@kwsites/file-exists");
808
- function check(path7, isFile, isDirectory) {
809
- log(`checking %s`, path7);
808
+ function check(path8, isFile, isDirectory) {
809
+ log(`checking %s`, path8);
810
810
  try {
811
- const stat = fs_1.statSync(path7);
811
+ const stat = fs_1.statSync(path8);
812
812
  if (stat.isFile() && isFile) {
813
813
  log(`[OK] path represents a file`);
814
814
  return true;
@@ -828,8 +828,8 @@ var require_src2 = __commonJS({
828
828
  throw e;
829
829
  }
830
830
  }
831
- function exists2(path7, type = exports2.READABLE) {
832
- return check(path7, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
831
+ function exists2(path8, type = exports2.READABLE) {
832
+ return check(path8, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
833
833
  }
834
834
  exports2.exists = exists2;
835
835
  exports2.FILE = 1;
@@ -1175,7 +1175,7 @@ var import_uuid = require("uuid");
1175
1175
  // package.json
1176
1176
  var package_default = {
1177
1177
  name: "@posthog/agent",
1178
- version: "2.1.48",
1178
+ version: "2.1.53",
1179
1179
  repository: "https://github.com/PostHog/twig",
1180
1180
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1181
1181
  exports: {
@@ -1553,8 +1553,8 @@ var ToolContentBuilder = class {
1553
1553
  this.items.push({ type: "content", content: image(data, mimeType, uri) });
1554
1554
  return this;
1555
1555
  }
1556
- diff(path7, oldText, newText) {
1557
- this.items.push({ type: "diff", path: path7, oldText, newText });
1556
+ diff(path8, oldText, newText) {
1557
+ this.items.push({ type: "diff", path: path8, oldText, newText });
1558
1558
  return this;
1559
1559
  }
1560
1560
  build() {
@@ -1744,13 +1744,13 @@ function toolInfoFromToolUse(toolUse, cachedFileContent, logger = new Logger({ d
1744
1744
  locations: []
1745
1745
  };
1746
1746
  case "Edit": {
1747
- const path7 = input?.file_path ? String(input.file_path) : void 0;
1747
+ const path8 = input?.file_path ? String(input.file_path) : void 0;
1748
1748
  let oldText = input?.old_string ? String(input.old_string) : null;
1749
1749
  let newText = input?.new_string ? String(input.new_string) : "";
1750
1750
  let affectedLines = [];
1751
- if (path7 && oldText) {
1751
+ if (path8 && oldText) {
1752
1752
  try {
1753
- const oldContent = cachedFileContent[path7] || "";
1753
+ const oldContent = cachedFileContent[path8] || "";
1754
1754
  const newContent = replaceAndCalculateLocation(oldContent, [
1755
1755
  {
1756
1756
  oldText,
@@ -1766,17 +1766,17 @@ function toolInfoFromToolUse(toolUse, cachedFileContent, logger = new Logger({ d
1766
1766
  }
1767
1767
  }
1768
1768
  return {
1769
- title: path7 ? `Edit \`${path7}\`` : "Edit",
1769
+ title: path8 ? `Edit \`${path8}\`` : "Edit",
1770
1770
  kind: "edit",
1771
- content: input && path7 ? [
1771
+ content: input && path8 ? [
1772
1772
  {
1773
1773
  type: "diff",
1774
- path: path7,
1774
+ path: path8,
1775
1775
  oldText,
1776
1776
  newText
1777
1777
  }
1778
1778
  ] : [],
1779
- locations: path7 ? affectedLines.length > 0 ? affectedLines.map((line) => ({ line, path: path7 })) : [{ path: path7 }] : []
1779
+ locations: path8 ? affectedLines.length > 0 ? affectedLines.map((line) => ({ line, path: path8 })) : [{ path: path8 }] : []
1780
1780
  };
1781
1781
  }
1782
1782
  case "Write": {
@@ -4270,6 +4270,8 @@ var PostHogAPIClient = class {
4270
4270
  };
4271
4271
 
4272
4272
  // src/session-log-writer.ts
4273
+ var import_node_fs2 = __toESM(require("fs"), 1);
4274
+ var import_node_path = __toESM(require("path"), 1);
4273
4275
  var SessionLogWriter = class _SessionLogWriter {
4274
4276
  static FLUSH_DEBOUNCE_MS = 500;
4275
4277
  static FLUSH_MAX_INTERVAL_MS = 5e3;
@@ -4283,8 +4285,10 @@ var SessionLogWriter = class _SessionLogWriter {
4283
4285
  sessions = /* @__PURE__ */ new Map();
4284
4286
  messageCounts = /* @__PURE__ */ new Map();
4285
4287
  logger;
4288
+ localCachePath;
4286
4289
  constructor(options = {}) {
4287
4290
  this.posthogAPI = options.posthogAPI;
4291
+ this.localCachePath = options.localCachePath;
4288
4292
  this.logger = options.logger ?? new Logger({ debug: false, prefix: "[SessionLogWriter]" });
4289
4293
  }
4290
4294
  async flushAll() {
@@ -4314,6 +4318,21 @@ var SessionLogWriter = class _SessionLogWriter {
4314
4318
  });
4315
4319
  this.sessions.set(sessionId, { context });
4316
4320
  this.lastFlushAttemptTime.set(sessionId, Date.now());
4321
+ if (this.localCachePath) {
4322
+ const sessionDir = import_node_path.default.join(
4323
+ this.localCachePath,
4324
+ "sessions",
4325
+ context.runId
4326
+ );
4327
+ try {
4328
+ import_node_fs2.default.mkdirSync(sessionDir, { recursive: true });
4329
+ } catch (error) {
4330
+ this.logger.warn("Failed to create local cache directory", {
4331
+ sessionDir,
4332
+ error
4333
+ });
4334
+ }
4335
+ }
4317
4336
  }
4318
4337
  isRegistered(sessionId) {
4319
4338
  return this.sessions.has(sessionId);
@@ -4351,6 +4370,7 @@ var SessionLogWriter = class _SessionLogWriter {
4351
4370
  timestamp,
4352
4371
  notification: message
4353
4372
  };
4373
+ this.writeToLocalCache(sessionId, entry);
4354
4374
  if (this.posthogAPI) {
4355
4375
  const pending = this.pendingEntries.get(sessionId) ?? [];
4356
4376
  pending.push(entry);
@@ -4451,6 +4471,7 @@ var SessionLogWriter = class _SessionLogWriter {
4451
4471
  }
4452
4472
  }
4453
4473
  };
4474
+ this.writeToLocalCache(sessionId, entry);
4454
4475
  if (this.posthogAPI) {
4455
4476
  const pending = this.pendingEntries.get(sessionId) ?? [];
4456
4477
  pending.push(entry);
@@ -4478,11 +4499,28 @@ var SessionLogWriter = class _SessionLogWriter {
4478
4499
  const timeout = setTimeout(() => this.flush(sessionId), delay2);
4479
4500
  this.flushTimeouts.set(sessionId, timeout);
4480
4501
  }
4502
+ writeToLocalCache(sessionId, entry) {
4503
+ if (!this.localCachePath) return;
4504
+ const session = this.sessions.get(sessionId);
4505
+ if (!session) return;
4506
+ const logPath = import_node_path.default.join(
4507
+ this.localCachePath,
4508
+ "sessions",
4509
+ session.context.runId,
4510
+ "logs.ndjson"
4511
+ );
4512
+ try {
4513
+ import_node_fs2.default.appendFileSync(logPath, `${JSON.stringify(entry)}
4514
+ `);
4515
+ } catch (error) {
4516
+ this.logger.warn("Failed to write to local cache", { logPath, error });
4517
+ }
4518
+ }
4481
4519
  };
4482
4520
 
4483
4521
  // ../git/dist/queries.js
4484
- var fs4 = __toESM(require("fs/promises"), 1);
4485
- var path5 = __toESM(require("path"), 1);
4522
+ var fs5 = __toESM(require("fs/promises"), 1);
4523
+ var path6 = __toESM(require("path"), 1);
4486
4524
 
4487
4525
  // ../../node_modules/simple-git/dist/esm/index.js
4488
4526
  var import_node_buffer = require("buffer");
@@ -4490,7 +4528,7 @@ var import_file_exists = __toESM(require_dist(), 1);
4490
4528
  var import_debug = __toESM(require_src(), 1);
4491
4529
  var import_child_process = require("child_process");
4492
4530
  var import_promise_deferred = __toESM(require_dist2(), 1);
4493
- var import_node_path = require("path");
4531
+ var import_node_path2 = require("path");
4494
4532
  var import_promise_deferred2 = __toESM(require_dist2(), 1);
4495
4533
  var import_node_events = require("events");
4496
4534
  var __defProp2 = Object.defineProperty;
@@ -4521,8 +4559,8 @@ function pathspec(...paths) {
4521
4559
  cache.set(key, paths);
4522
4560
  return key;
4523
4561
  }
4524
- function isPathSpec(path7) {
4525
- return path7 instanceof String && cache.has(path7);
4562
+ function isPathSpec(path8) {
4563
+ return path8 instanceof String && cache.has(path8);
4526
4564
  }
4527
4565
  function toPaths(pathSpec) {
4528
4566
  return cache.get(pathSpec) || [];
@@ -4611,8 +4649,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
4611
4649
  function forEachLineWithContent(input, callback) {
4612
4650
  return toLinesWithContent(input, true).map((line) => callback(line));
4613
4651
  }
4614
- function folderExists(path7) {
4615
- return (0, import_file_exists.exists)(path7, import_file_exists.FOLDER);
4652
+ function folderExists(path8) {
4653
+ return (0, import_file_exists.exists)(path8, import_file_exists.FOLDER);
4616
4654
  }
4617
4655
  function append(target, item) {
4618
4656
  if (Array.isArray(target)) {
@@ -5016,8 +5054,8 @@ function checkIsRepoRootTask() {
5016
5054
  commands,
5017
5055
  format: "utf-8",
5018
5056
  onError,
5019
- parser(path7) {
5020
- return /^\.(git)?$/.test(path7.trim());
5057
+ parser(path8) {
5058
+ return /^\.(git)?$/.test(path8.trim());
5021
5059
  }
5022
5060
  };
5023
5061
  }
@@ -5451,11 +5489,11 @@ function parseGrep(grep) {
5451
5489
  const paths = /* @__PURE__ */ new Set();
5452
5490
  const results = {};
5453
5491
  forEachLineWithContent(grep, (input) => {
5454
- const [path7, line, preview] = input.split(NULL);
5455
- paths.add(path7);
5456
- (results[path7] = results[path7] || []).push({
5492
+ const [path8, line, preview] = input.split(NULL);
5493
+ paths.add(path8);
5494
+ (results[path8] = results[path8] || []).push({
5457
5495
  line: asNumber(line),
5458
- path: path7,
5496
+ path: path8,
5459
5497
  preview
5460
5498
  });
5461
5499
  });
@@ -6220,14 +6258,14 @@ var init_hash_object = __esm({
6220
6258
  init_task();
6221
6259
  }
6222
6260
  });
6223
- function parseInit(bare, path7, text2) {
6261
+ function parseInit(bare, path8, text2) {
6224
6262
  const response = String(text2).trim();
6225
6263
  let result;
6226
6264
  if (result = initResponseRegex.exec(response)) {
6227
- return new InitSummary(bare, path7, false, result[1]);
6265
+ return new InitSummary(bare, path8, false, result[1]);
6228
6266
  }
6229
6267
  if (result = reInitResponseRegex.exec(response)) {
6230
- return new InitSummary(bare, path7, true, result[1]);
6268
+ return new InitSummary(bare, path8, true, result[1]);
6231
6269
  }
6232
6270
  let gitDir = "";
6233
6271
  const tokens = response.split(" ");
@@ -6238,7 +6276,7 @@ function parseInit(bare, path7, text2) {
6238
6276
  break;
6239
6277
  }
6240
6278
  }
6241
- return new InitSummary(bare, path7, /^re/i.test(response), gitDir);
6279
+ return new InitSummary(bare, path8, /^re/i.test(response), gitDir);
6242
6280
  }
6243
6281
  var InitSummary;
6244
6282
  var initResponseRegex;
@@ -6247,9 +6285,9 @@ var init_InitSummary = __esm({
6247
6285
  "src/lib/responses/InitSummary.ts"() {
6248
6286
  "use strict";
6249
6287
  InitSummary = class {
6250
- constructor(bare, path7, existing, gitDir) {
6288
+ constructor(bare, path8, existing, gitDir) {
6251
6289
  this.bare = bare;
6252
- this.path = path7;
6290
+ this.path = path8;
6253
6291
  this.existing = existing;
6254
6292
  this.gitDir = gitDir;
6255
6293
  }
@@ -6261,7 +6299,7 @@ var init_InitSummary = __esm({
6261
6299
  function hasBareCommand(command) {
6262
6300
  return command.includes(bareCommand);
6263
6301
  }
6264
- function initTask(bare = false, path7, customArgs) {
6302
+ function initTask(bare = false, path8, customArgs) {
6265
6303
  const commands = ["init", ...customArgs];
6266
6304
  if (bare && !hasBareCommand(commands)) {
6267
6305
  commands.splice(1, 0, bareCommand);
@@ -6270,7 +6308,7 @@ function initTask(bare = false, path7, customArgs) {
6270
6308
  commands,
6271
6309
  format: "utf-8",
6272
6310
  parser(text2) {
6273
- return parseInit(commands.includes("--bare"), path7, text2);
6311
+ return parseInit(commands.includes("--bare"), path8, text2);
6274
6312
  }
6275
6313
  };
6276
6314
  }
@@ -7086,12 +7124,12 @@ var init_FileStatusSummary = __esm({
7086
7124
  "use strict";
7087
7125
  fromPathRegex = /^(.+)\0(.+)$/;
7088
7126
  FileStatusSummary = class {
7089
- constructor(path7, index, working_dir) {
7090
- this.path = path7;
7127
+ constructor(path8, index, working_dir) {
7128
+ this.path = path8;
7091
7129
  this.index = index;
7092
7130
  this.working_dir = working_dir;
7093
7131
  if (index === "R" || working_dir === "R") {
7094
- const detail = fromPathRegex.exec(path7) || [null, path7, path7];
7132
+ const detail = fromPathRegex.exec(path8) || [null, path8, path8];
7095
7133
  this.from = detail[2] || "";
7096
7134
  this.path = detail[1] || "";
7097
7135
  }
@@ -7122,14 +7160,14 @@ function splitLine(result, lineStr) {
7122
7160
  default:
7123
7161
  return;
7124
7162
  }
7125
- function data(index, workingDir, path7) {
7163
+ function data(index, workingDir, path8) {
7126
7164
  const raw = `${index}${workingDir}`;
7127
7165
  const handler = parsers6.get(raw);
7128
7166
  if (handler) {
7129
- handler(result, path7);
7167
+ handler(result, path8);
7130
7168
  }
7131
7169
  if (raw !== "##" && raw !== "!!") {
7132
- result.files.push(new FileStatusSummary(path7, index, workingDir));
7170
+ result.files.push(new FileStatusSummary(path8, index, workingDir));
7133
7171
  }
7134
7172
  }
7135
7173
  }
@@ -7442,9 +7480,9 @@ var init_simple_git_api = __esm({
7442
7480
  next
7443
7481
  );
7444
7482
  }
7445
- hashObject(path7, write) {
7483
+ hashObject(path8, write) {
7446
7484
  return this._runTask(
7447
- hashObjectTask(path7, write === true),
7485
+ hashObjectTask(path8, write === true),
7448
7486
  trailingFunctionArgument(arguments)
7449
7487
  );
7450
7488
  }
@@ -7797,8 +7835,8 @@ var init_branch = __esm({
7797
7835
  }
7798
7836
  });
7799
7837
  function toPath(input) {
7800
- const path7 = input.trim().replace(/^["']|["']$/g, "");
7801
- return path7 && (0, import_node_path.normalize)(path7);
7838
+ const path8 = input.trim().replace(/^["']|["']$/g, "");
7839
+ return path8 && (0, import_node_path2.normalize)(path8);
7802
7840
  }
7803
7841
  var parseCheckIgnore;
7804
7842
  var init_CheckIgnore = __esm({
@@ -8112,8 +8150,8 @@ __export(sub_module_exports, {
8112
8150
  subModuleTask: () => subModuleTask,
8113
8151
  updateSubModuleTask: () => updateSubModuleTask
8114
8152
  });
8115
- function addSubModuleTask(repo, path7) {
8116
- return subModuleTask(["add", repo, path7]);
8153
+ function addSubModuleTask(repo, path8) {
8154
+ return subModuleTask(["add", repo, path8]);
8117
8155
  }
8118
8156
  function initSubModuleTask(customArgs) {
8119
8157
  return subModuleTask(["init", ...customArgs]);
@@ -8443,8 +8481,8 @@ var require_git = __commonJS2({
8443
8481
  }
8444
8482
  return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
8445
8483
  };
8446
- Git2.prototype.submoduleAdd = function(repo, path7, then) {
8447
- return this._runTask(addSubModuleTask2(repo, path7), trailingFunctionArgument2(arguments));
8484
+ Git2.prototype.submoduleAdd = function(repo, path8, then) {
8485
+ return this._runTask(addSubModuleTask2(repo, path8), trailingFunctionArgument2(arguments));
8448
8486
  };
8449
8487
  Git2.prototype.submoduleUpdate = function(args, then) {
8450
8488
  return this._runTask(
@@ -9046,15 +9084,15 @@ function createGitClient(baseDir, options) {
9046
9084
  // ../git/dist/lock-detector.js
9047
9085
  var import_node_child_process3 = require("child_process");
9048
9086
  var import_promises = __toESM(require("fs/promises"), 1);
9049
- var import_node_path2 = __toESM(require("path"), 1);
9087
+ var import_node_path3 = __toESM(require("path"), 1);
9050
9088
  var import_node_util = require("util");
9051
9089
  var execFileAsync = (0, import_node_util.promisify)(import_node_child_process3.execFile);
9052
9090
  async function getIndexLockPath(repoPath) {
9053
9091
  try {
9054
9092
  const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "index.lock"], { cwd: repoPath });
9055
- return import_node_path2.default.resolve(repoPath, stdout.trim());
9093
+ return import_node_path3.default.resolve(repoPath, stdout.trim());
9056
9094
  } catch {
9057
- return import_node_path2.default.join(repoPath, ".git", "index.lock");
9095
+ return import_node_path3.default.join(repoPath, ".git", "index.lock");
9058
9096
  }
9059
9097
  }
9060
9098
  async function getLockInfo(repoPath) {
@@ -9236,7 +9274,7 @@ async function getHeadSha(baseDir, options) {
9236
9274
 
9237
9275
  // src/sagas/apply-snapshot-saga.ts
9238
9276
  var import_promises2 = require("fs/promises");
9239
- var import_node_path3 = require("path");
9277
+ var import_node_path4 = require("path");
9240
9278
 
9241
9279
  // ../shared/dist/index.js
9242
9280
  var consoleLogger = {
@@ -9366,9 +9404,9 @@ var Saga = class {
9366
9404
  };
9367
9405
 
9368
9406
  // ../git/dist/sagas/tree.js
9369
- var import_node_fs2 = require("fs");
9370
- var fs5 = __toESM(require("fs/promises"), 1);
9371
- var path6 = __toESM(require("path"), 1);
9407
+ var import_node_fs3 = require("fs");
9408
+ var fs6 = __toESM(require("fs/promises"), 1);
9409
+ var path7 = __toESM(require("path"), 1);
9372
9410
  var tar = __toESM(require("tar"), 1);
9373
9411
 
9374
9412
  // ../git/dist/git-saga.js
@@ -9394,14 +9432,14 @@ var CaptureTreeSaga = class extends GitSaga {
9394
9432
  tempIndexPath = null;
9395
9433
  async executeGitOperations(input) {
9396
9434
  const { baseDir, lastTreeHash, archivePath, signal } = input;
9397
- const tmpDir = path6.join(baseDir, ".git", "twig-tmp");
9435
+ const tmpDir = path7.join(baseDir, ".git", "twig-tmp");
9398
9436
  await this.step({
9399
9437
  name: "create_tmp_dir",
9400
- execute: () => fs5.mkdir(tmpDir, { recursive: true }),
9438
+ execute: () => fs6.mkdir(tmpDir, { recursive: true }),
9401
9439
  rollback: async () => {
9402
9440
  }
9403
9441
  });
9404
- this.tempIndexPath = path6.join(tmpDir, `index-${Date.now()}`);
9442
+ this.tempIndexPath = path7.join(tmpDir, `index-${Date.now()}`);
9405
9443
  const tempIndexGit = this.git.env({
9406
9444
  ...process.env,
9407
9445
  GIT_INDEX_FILE: this.tempIndexPath
@@ -9411,7 +9449,7 @@ var CaptureTreeSaga = class extends GitSaga {
9411
9449
  execute: () => tempIndexGit.raw(["read-tree", "HEAD"]),
9412
9450
  rollback: async () => {
9413
9451
  if (this.tempIndexPath) {
9414
- await fs5.rm(this.tempIndexPath, { force: true }).catch(() => {
9452
+ await fs6.rm(this.tempIndexPath, { force: true }).catch(() => {
9415
9453
  });
9416
9454
  }
9417
9455
  }
@@ -9420,7 +9458,7 @@ var CaptureTreeSaga = class extends GitSaga {
9420
9458
  const treeHash = await this.readOnlyStep("write_tree", () => tempIndexGit.raw(["write-tree"]));
9421
9459
  if (lastTreeHash && treeHash === lastTreeHash) {
9422
9460
  this.log.debug("No changes since last capture", { treeHash });
9423
- await fs5.rm(this.tempIndexPath, { force: true }).catch(() => {
9461
+ await fs6.rm(this.tempIndexPath, { force: true }).catch(() => {
9424
9462
  });
9425
9463
  return { snapshot: null, changed: false };
9426
9464
  }
@@ -9432,7 +9470,7 @@ var CaptureTreeSaga = class extends GitSaga {
9432
9470
  }
9433
9471
  });
9434
9472
  const changes = await this.readOnlyStep("get_changes", () => this.getChanges(this.git, baseCommit, treeHash));
9435
- await fs5.rm(this.tempIndexPath, { force: true }).catch(() => {
9473
+ await fs6.rm(this.tempIndexPath, { force: true }).catch(() => {
9436
9474
  });
9437
9475
  const snapshot = {
9438
9476
  treeHash,
@@ -9456,15 +9494,15 @@ var CaptureTreeSaga = class extends GitSaga {
9456
9494
  if (filesToArchive.length === 0) {
9457
9495
  return void 0;
9458
9496
  }
9459
- const existingFiles = filesToArchive.filter((f) => (0, import_node_fs2.existsSync)(path6.join(baseDir, f)));
9497
+ const existingFiles = filesToArchive.filter((f) => (0, import_node_fs3.existsSync)(path7.join(baseDir, f)));
9460
9498
  if (existingFiles.length === 0) {
9461
9499
  return void 0;
9462
9500
  }
9463
9501
  await this.step({
9464
9502
  name: "create_archive",
9465
9503
  execute: async () => {
9466
- const archiveDir = path6.dirname(archivePath);
9467
- await fs5.mkdir(archiveDir, { recursive: true });
9504
+ const archiveDir = path7.dirname(archivePath);
9505
+ await fs6.mkdir(archiveDir, { recursive: true });
9468
9506
  await tar.create({
9469
9507
  gzip: true,
9470
9508
  file: archivePath,
@@ -9472,7 +9510,7 @@ var CaptureTreeSaga = class extends GitSaga {
9472
9510
  }, existingFiles);
9473
9511
  },
9474
9512
  rollback: async () => {
9475
- await fs5.rm(archivePath, { force: true }).catch(() => {
9513
+ await fs6.rm(archivePath, { force: true }).catch(() => {
9476
9514
  });
9477
9515
  }
9478
9516
  });
@@ -9571,9 +9609,9 @@ var ApplyTreeSaga = class extends GitSaga {
9571
9609
  const filesToExtract = changes.filter((c) => c.status !== "D").map((c) => c.path);
9572
9610
  await this.readOnlyStep("backup_existing_files", async () => {
9573
9611
  for (const filePath of filesToExtract) {
9574
- const fullPath = path6.join(baseDir, filePath);
9612
+ const fullPath = path7.join(baseDir, filePath);
9575
9613
  try {
9576
- const content = await fs5.readFile(fullPath);
9614
+ const content = await fs6.readFile(fullPath);
9577
9615
  this.fileBackups.set(filePath, content);
9578
9616
  } catch {
9579
9617
  }
@@ -9590,16 +9628,16 @@ var ApplyTreeSaga = class extends GitSaga {
9590
9628
  },
9591
9629
  rollback: async () => {
9592
9630
  for (const filePath of this.extractedFiles) {
9593
- const fullPath = path6.join(baseDir, filePath);
9631
+ const fullPath = path7.join(baseDir, filePath);
9594
9632
  const backup = this.fileBackups.get(filePath);
9595
9633
  if (backup) {
9596
- const dir = path6.dirname(fullPath);
9597
- await fs5.mkdir(dir, { recursive: true }).catch(() => {
9634
+ const dir = path7.dirname(fullPath);
9635
+ await fs6.mkdir(dir, { recursive: true }).catch(() => {
9598
9636
  });
9599
- await fs5.writeFile(fullPath, backup).catch(() => {
9637
+ await fs6.writeFile(fullPath, backup).catch(() => {
9600
9638
  });
9601
9639
  } else {
9602
- await fs5.rm(fullPath, { force: true }).catch(() => {
9640
+ await fs6.rm(fullPath, { force: true }).catch(() => {
9603
9641
  });
9604
9642
  }
9605
9643
  }
@@ -9607,10 +9645,10 @@ var ApplyTreeSaga = class extends GitSaga {
9607
9645
  });
9608
9646
  }
9609
9647
  for (const change of changes.filter((c) => c.status === "D")) {
9610
- const fullPath = path6.join(baseDir, change.path);
9648
+ const fullPath = path7.join(baseDir, change.path);
9611
9649
  const backupContent = await this.readOnlyStep(`backup_${change.path}`, async () => {
9612
9650
  try {
9613
- return await fs5.readFile(fullPath);
9651
+ return await fs6.readFile(fullPath);
9614
9652
  } catch {
9615
9653
  return null;
9616
9654
  }
@@ -9618,15 +9656,15 @@ var ApplyTreeSaga = class extends GitSaga {
9618
9656
  await this.step({
9619
9657
  name: `delete_${change.path}`,
9620
9658
  execute: async () => {
9621
- await fs5.rm(fullPath, { force: true });
9659
+ await fs6.rm(fullPath, { force: true });
9622
9660
  this.log.debug(`Deleted file: ${change.path}`);
9623
9661
  },
9624
9662
  rollback: async () => {
9625
9663
  if (backupContent) {
9626
- const dir = path6.dirname(fullPath);
9627
- await fs5.mkdir(dir, { recursive: true }).catch(() => {
9664
+ const dir = path7.dirname(fullPath);
9665
+ await fs6.mkdir(dir, { recursive: true }).catch(() => {
9628
9666
  });
9629
- await fs5.writeFile(fullPath, backupContent).catch(() => {
9667
+ await fs6.writeFile(fullPath, backupContent).catch(() => {
9630
9668
  });
9631
9669
  }
9632
9670
  }
@@ -9648,7 +9686,7 @@ var ApplySnapshotSaga = class extends Saga {
9648
9686
  archivePath = null;
9649
9687
  async execute(input) {
9650
9688
  const { snapshot, repositoryPath, apiClient, taskId, runId } = input;
9651
- const tmpDir = (0, import_node_path3.join)(repositoryPath, ".posthog", "tmp");
9689
+ const tmpDir = (0, import_node_path4.join)(repositoryPath, ".posthog", "tmp");
9652
9690
  if (!snapshot.archiveUrl) {
9653
9691
  throw new Error("Cannot apply snapshot: no archive URL");
9654
9692
  }
@@ -9658,7 +9696,7 @@ var ApplySnapshotSaga = class extends Saga {
9658
9696
  rollback: async () => {
9659
9697
  }
9660
9698
  });
9661
- this.archivePath = (0, import_node_path3.join)(tmpDir, `${snapshot.treeHash}.tar.gz`);
9699
+ this.archivePath = (0, import_node_path4.join)(tmpDir, `${snapshot.treeHash}.tar.gz`);
9662
9700
  await this.step({
9663
9701
  name: "download_archive",
9664
9702
  execute: async () => {
@@ -9704,9 +9742,9 @@ var ApplySnapshotSaga = class extends Saga {
9704
9742
  };
9705
9743
 
9706
9744
  // src/sagas/capture-tree-saga.ts
9707
- var import_node_fs3 = require("fs");
9745
+ var import_node_fs4 = require("fs");
9708
9746
  var import_promises3 = require("fs/promises");
9709
- var import_node_path4 = require("path");
9747
+ var import_node_path5 = require("path");
9710
9748
  var CaptureTreeSaga2 = class extends Saga {
9711
9749
  async execute(input) {
9712
9750
  const {
@@ -9717,14 +9755,14 @@ var CaptureTreeSaga2 = class extends Saga {
9717
9755
  taskId,
9718
9756
  runId
9719
9757
  } = input;
9720
- const tmpDir = (0, import_node_path4.join)(repositoryPath, ".posthog", "tmp");
9721
- if ((0, import_node_fs3.existsSync)((0, import_node_path4.join)(repositoryPath, ".gitmodules"))) {
9758
+ const tmpDir = (0, import_node_path5.join)(repositoryPath, ".posthog", "tmp");
9759
+ if ((0, import_node_fs4.existsSync)((0, import_node_path5.join)(repositoryPath, ".gitmodules"))) {
9722
9760
  this.log.warn(
9723
9761
  "Repository has submodules - snapshot may not capture submodule state"
9724
9762
  );
9725
9763
  }
9726
9764
  const shouldArchive = !!apiClient;
9727
- const archivePath = shouldArchive ? (0, import_node_path4.join)(tmpDir, `tree-${Date.now()}.tar.gz`) : void 0;
9765
+ const archivePath = shouldArchive ? (0, import_node_path5.join)(tmpDir, `tree-${Date.now()}.tar.gz`) : void 0;
9728
9766
  const gitCaptureSaga = new CaptureTreeSaga(this.log);
9729
9767
  const captureResult = await gitCaptureSaga.run({
9730
9768
  baseDir: repositoryPath,