@posthog/agent 2.1.124 → 2.1.131

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.
@@ -237,8 +237,8 @@ var require_common = __commonJS({
237
237
  }
238
238
  return debug2;
239
239
  }
240
- function extend(namespace, delimiter) {
241
- const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
240
+ function extend(namespace, delimiter2) {
241
+ const newDebug = createDebug(this.namespace + (typeof delimiter2 === "undefined" ? ":" : delimiter2) + namespace);
242
242
  newDebug.log = this.log;
243
243
  return newDebug;
244
244
  }
@@ -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.1.124",
907
+ version: "2.1.131",
908
908
  repository: "https://github.com/PostHog/twig",
909
909
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
910
910
  exports: {
@@ -989,8 +989,8 @@ var package_default = {
989
989
  },
990
990
  dependencies: {
991
991
  "@agentclientprotocol/sdk": "^0.14.0",
992
- "@anthropic-ai/claude-agent-sdk": "0.2.59",
993
- "@anthropic-ai/sdk": "^0.71.0",
992
+ "@anthropic-ai/claude-agent-sdk": "0.2.63",
993
+ "@anthropic-ai/sdk": "^0.78.0",
994
994
  "@hono/node-server": "^1.19.9",
995
995
  "@opentelemetry/api-logs": "^0.208.0",
996
996
  "@opentelemetry/exporter-logs-otlp-http": "^0.208.0",
@@ -2328,6 +2328,8 @@ function processContentChunk(chunk, role, ctx) {
2328
2328
  case "citations_delta":
2329
2329
  case "signature_delta":
2330
2330
  case "container_upload":
2331
+ case "compaction":
2332
+ case "compaction_delta":
2331
2333
  return null;
2332
2334
  default:
2333
2335
  unreachable(chunk, ctx.logger);
@@ -3815,6 +3817,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3815
3817
  // src/adapters/codex/spawn.ts
3816
3818
  var import_node_child_process2 = require("child_process");
3817
3819
  var import_node_fs = require("fs");
3820
+ var import_node_path = require("path");
3818
3821
  function buildConfigArgs(options) {
3819
3822
  const args = [];
3820
3823
  args.push("-c", `features.remote_models=false`);
@@ -3855,8 +3858,8 @@ function spawnCodexProcess(options) {
3855
3858
  }
3856
3859
  const { command, args } = findCodexBinary(options);
3857
3860
  if (options.binaryPath && (0, import_node_fs.existsSync)(options.binaryPath)) {
3858
- const binDir = options.binaryPath.replace(/\/[^/]+$/, "");
3859
- env.PATH = `${binDir}:${env.PATH ?? ""}`;
3861
+ const binDir = (0, import_node_path.dirname)(options.binaryPath);
3862
+ env.PATH = `${binDir}${import_node_path.delimiter}${env.PATH ?? ""}`;
3860
3863
  }
3861
3864
  logger.info("Spawning codex-acp process", {
3862
3865
  command,
@@ -3873,7 +3876,7 @@ function spawnCodexProcess(options) {
3873
3876
  detached: process.platform !== "win32"
3874
3877
  });
3875
3878
  child.stderr?.on("data", (data) => {
3876
- logger.debug("codex-acp stderr:", data.toString());
3879
+ logger.error("codex-acp stderr:", data.toString());
3877
3880
  });
3878
3881
  child.on("error", (err) => {
3879
3882
  logger.error("codex-acp process error:", err);
@@ -4436,7 +4439,7 @@ var PostHogAPIClient = class {
4436
4439
 
4437
4440
  // src/session-log-writer.ts
4438
4441
  var import_node_fs2 = __toESM(require("fs"), 1);
4439
- var import_node_path = __toESM(require("path"), 1);
4442
+ var import_node_path2 = __toESM(require("path"), 1);
4440
4443
  var SessionLogWriter = class _SessionLogWriter {
4441
4444
  static FLUSH_DEBOUNCE_MS = 500;
4442
4445
  static FLUSH_MAX_INTERVAL_MS = 5e3;
@@ -4448,7 +4451,6 @@ var SessionLogWriter = class _SessionLogWriter {
4448
4451
  lastFlushAttemptTime = /* @__PURE__ */ new Map();
4449
4452
  retryCounts = /* @__PURE__ */ new Map();
4450
4453
  sessions = /* @__PURE__ */ new Map();
4451
- messageCounts = /* @__PURE__ */ new Map();
4452
4454
  logger;
4453
4455
  localCachePath;
4454
4456
  constructor(options = {}) {
@@ -4458,19 +4460,6 @@ var SessionLogWriter = class _SessionLogWriter {
4458
4460
  }
4459
4461
  async flushAll() {
4460
4462
  const sessionIds = [...this.sessions.keys()];
4461
- const pendingCounts = sessionIds.map((id) => {
4462
- const session = this.sessions.get(id);
4463
- return {
4464
- taskId: session?.context.taskId,
4465
- runId: session?.context.runId,
4466
- pending: this.pendingEntries.get(id)?.length ?? 0,
4467
- messages: this.messageCounts.get(id) ?? 0
4468
- };
4469
- });
4470
- this.logger.info("flushAll called", {
4471
- sessions: sessionIds.length,
4472
- pending: pendingCounts
4473
- });
4474
4463
  const flushPromises = [];
4475
4464
  for (const sessionId of sessionIds) {
4476
4465
  flushPromises.push(this.flush(sessionId));
@@ -4488,7 +4477,7 @@ var SessionLogWriter = class _SessionLogWriter {
4488
4477
  this.sessions.set(sessionId, { context });
4489
4478
  this.lastFlushAttemptTime.set(sessionId, Date.now());
4490
4479
  if (this.localCachePath) {
4491
- const sessionDir = import_node_path.default.join(
4480
+ const sessionDir = import_node_path2.default.join(
4492
4481
  this.localCachePath,
4493
4482
  "sessions",
4494
4483
  context.runId
@@ -4514,15 +4503,6 @@ var SessionLogWriter = class _SessionLogWriter {
4514
4503
  });
4515
4504
  return;
4516
4505
  }
4517
- const count = (this.messageCounts.get(sessionId) ?? 0) + 1;
4518
- this.messageCounts.set(sessionId, count);
4519
- if (count % 10 === 1) {
4520
- this.logger.info("Messages received", {
4521
- count,
4522
- taskId: session.context.taskId,
4523
- runId: session.context.runId
4524
- });
4525
- }
4526
4506
  try {
4527
4507
  const message = JSON.parse(line);
4528
4508
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
@@ -4571,12 +4551,6 @@ var SessionLogWriter = class _SessionLogWriter {
4571
4551
  this.emitCoalescedMessage(sessionId, session);
4572
4552
  const pending = this.pendingEntries.get(sessionId);
4573
4553
  if (!this.posthogAPI || !pending?.length) {
4574
- this.logger.info("flush: nothing to persist", {
4575
- taskId: session.context.taskId,
4576
- runId: session.context.runId,
4577
- hasPosthogAPI: !!this.posthogAPI,
4578
- pendingCount: pending?.length ?? 0
4579
- });
4580
4554
  return;
4581
4555
  }
4582
4556
  this.pendingEntries.delete(sessionId);
@@ -4593,11 +4567,6 @@ var SessionLogWriter = class _SessionLogWriter {
4593
4567
  pending
4594
4568
  );
4595
4569
  this.retryCounts.set(sessionId, 0);
4596
- this.logger.info("Flushed session logs", {
4597
- taskId: session.context.taskId,
4598
- runId: session.context.runId,
4599
- entryCount: pending.length
4600
- });
4601
4570
  } catch (error) {
4602
4571
  const retryCount = (this.retryCounts.get(sessionId) ?? 0) + 1;
4603
4572
  this.retryCounts.set(sessionId, retryCount);
@@ -4711,7 +4680,7 @@ var SessionLogWriter = class _SessionLogWriter {
4711
4680
  if (!this.localCachePath) return;
4712
4681
  const session = this.sessions.get(sessionId);
4713
4682
  if (!session) return;
4714
- const logPath = import_node_path.default.join(
4683
+ const logPath = import_node_path2.default.join(
4715
4684
  this.localCachePath,
4716
4685
  "sessions",
4717
4686
  session.context.runId,
@@ -4741,7 +4710,7 @@ var import_file_exists = __toESM(require_dist(), 1);
4741
4710
  var import_debug = __toESM(require_src(), 1);
4742
4711
  var import_child_process = require("child_process");
4743
4712
  var import_promise_deferred = __toESM(require_dist2(), 1);
4744
- var import_node_path2 = require("path");
4713
+ var import_node_path3 = require("path");
4745
4714
  var import_promise_deferred2 = __toESM(require_dist2(), 1);
4746
4715
  var import_node_events = require("events");
4747
4716
  var __defProp2 = Object.defineProperty;
@@ -8049,7 +8018,7 @@ var init_branch = __esm({
8049
8018
  });
8050
8019
  function toPath(input) {
8051
8020
  const path8 = input.trim().replace(/^["']|["']$/g, "");
8052
- return path8 && (0, import_node_path2.normalize)(path8);
8021
+ return path8 && (0, import_node_path3.normalize)(path8);
8053
8022
  }
8054
8023
  var parseCheckIgnore;
8055
8024
  var init_CheckIgnore = __esm({
@@ -9297,15 +9266,15 @@ function createGitClient(baseDir, options) {
9297
9266
  // ../git/dist/lock-detector.js
9298
9267
  var import_node_child_process3 = require("child_process");
9299
9268
  var import_promises = __toESM(require("fs/promises"), 1);
9300
- var import_node_path3 = __toESM(require("path"), 1);
9269
+ var import_node_path4 = __toESM(require("path"), 1);
9301
9270
  var import_node_util = require("util");
9302
9271
  var execFileAsync = (0, import_node_util.promisify)(import_node_child_process3.execFile);
9303
9272
  async function getIndexLockPath(repoPath) {
9304
9273
  try {
9305
9274
  const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "index.lock"], { cwd: repoPath });
9306
- return import_node_path3.default.resolve(repoPath, stdout.trim());
9275
+ return import_node_path4.default.resolve(repoPath, stdout.trim());
9307
9276
  } catch {
9308
- return import_node_path3.default.join(repoPath, ".git", "index.lock");
9277
+ return import_node_path4.default.join(repoPath, ".git", "index.lock");
9309
9278
  }
9310
9279
  }
9311
9280
  async function getLockInfo(repoPath) {
@@ -9489,7 +9458,7 @@ async function getHeadSha(baseDir, options) {
9489
9458
 
9490
9459
  // src/sagas/apply-snapshot-saga.ts
9491
9460
  var import_promises2 = require("fs/promises");
9492
- var import_node_path4 = require("path");
9461
+ var import_node_path5 = require("path");
9493
9462
 
9494
9463
  // ../shared/dist/index.js
9495
9464
  var consoleLogger = {
@@ -9901,7 +9870,7 @@ var ApplySnapshotSaga = class extends Saga {
9901
9870
  archivePath = null;
9902
9871
  async execute(input) {
9903
9872
  const { snapshot, repositoryPath, apiClient, taskId, runId } = input;
9904
- const tmpDir = (0, import_node_path4.join)(repositoryPath, ".posthog", "tmp");
9873
+ const tmpDir = (0, import_node_path5.join)(repositoryPath, ".posthog", "tmp");
9905
9874
  if (!snapshot.archiveUrl) {
9906
9875
  throw new Error("Cannot apply snapshot: no archive URL");
9907
9876
  }
@@ -9912,7 +9881,7 @@ var ApplySnapshotSaga = class extends Saga {
9912
9881
  rollback: async () => {
9913
9882
  }
9914
9883
  });
9915
- const archivePath = (0, import_node_path4.join)(tmpDir, `${snapshot.treeHash}.tar.gz`);
9884
+ const archivePath = (0, import_node_path5.join)(tmpDir, `${snapshot.treeHash}.tar.gz`);
9916
9885
  this.archivePath = archivePath;
9917
9886
  await this.step({
9918
9887
  name: "download_archive",
@@ -9961,7 +9930,7 @@ var ApplySnapshotSaga = class extends Saga {
9961
9930
  // src/sagas/capture-tree-saga.ts
9962
9931
  var import_node_fs4 = require("fs");
9963
9932
  var import_promises3 = require("fs/promises");
9964
- var import_node_path5 = require("path");
9933
+ var import_node_path6 = require("path");
9965
9934
  var CaptureTreeSaga2 = class extends Saga {
9966
9935
  async execute(input) {
9967
9936
  const {
@@ -9972,14 +9941,14 @@ var CaptureTreeSaga2 = class extends Saga {
9972
9941
  taskId,
9973
9942
  runId
9974
9943
  } = input;
9975
- const tmpDir = (0, import_node_path5.join)(repositoryPath, ".posthog", "tmp");
9976
- if ((0, import_node_fs4.existsSync)((0, import_node_path5.join)(repositoryPath, ".gitmodules"))) {
9944
+ const tmpDir = (0, import_node_path6.join)(repositoryPath, ".posthog", "tmp");
9945
+ if ((0, import_node_fs4.existsSync)((0, import_node_path6.join)(repositoryPath, ".gitmodules"))) {
9977
9946
  this.log.warn(
9978
9947
  "Repository has submodules - snapshot may not capture submodule state"
9979
9948
  );
9980
9949
  }
9981
9950
  const shouldArchive = !!apiClient;
9982
- const archivePath = shouldArchive ? (0, import_node_path5.join)(tmpDir, `tree-${Date.now()}.tar.gz`) : void 0;
9951
+ const archivePath = shouldArchive ? (0, import_node_path6.join)(tmpDir, `tree-${Date.now()}.tar.gz`) : void 0;
9983
9952
  const gitCaptureSaga = new CaptureTreeSaga(this.log);
9984
9953
  const captureResult = await gitCaptureSaga.run({
9985
9954
  baseDir: repositoryPath,