@posthog/agent 2.1.48 → 2.1.59

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