@posthog/agent 2.1.29 → 2.1.45

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.
@@ -1183,7 +1183,7 @@ import { v7 as uuidv7 } from "uuid";
1183
1183
  // package.json
1184
1184
  var package_default = {
1185
1185
  name: "@posthog/agent",
1186
- version: "2.1.29",
1186
+ version: "2.1.45",
1187
1187
  repository: "https://github.com/PostHog/twig",
1188
1188
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1189
1189
  exports: {
@@ -1314,11 +1314,16 @@ function unreachable(value, logger) {
1314
1314
  // src/gateway-models.ts
1315
1315
  var DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
1316
1316
  var BLOCKED_MODELS = /* @__PURE__ */ new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
1317
+ var CACHE_TTL = 10 * 60 * 1e3;
1318
+ var gatewayModelsCache = null;
1317
1319
  async function fetchGatewayModels(options) {
1318
1320
  const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
1319
1321
  if (!gatewayUrl) {
1320
1322
  return [];
1321
1323
  }
1324
+ if (gatewayModelsCache && gatewayModelsCache.url === gatewayUrl && Date.now() < gatewayModelsCache.expiry) {
1325
+ return gatewayModelsCache.models;
1326
+ }
1322
1327
  const modelsUrl = `${gatewayUrl}/v1/models`;
1323
1328
  try {
1324
1329
  const response = await fetch(modelsUrl);
@@ -1326,8 +1331,13 @@ async function fetchGatewayModels(options) {
1326
1331
  return [];
1327
1332
  }
1328
1333
  const data = await response.json();
1329
- const models = data.data ?? [];
1330
- return models.filter((m) => !BLOCKED_MODELS.has(m.id));
1334
+ const models = (data.data ?? []).filter((m) => !BLOCKED_MODELS.has(m.id));
1335
+ gatewayModelsCache = {
1336
+ models,
1337
+ expiry: Date.now() + CACHE_TTL,
1338
+ url: gatewayUrl
1339
+ };
1340
+ return models;
1331
1341
  } catch {
1332
1342
  return [];
1333
1343
  }
@@ -2608,7 +2618,7 @@ var BASH_TOOLS = /* @__PURE__ */ new Set([
2608
2618
  ]);
2609
2619
  var SEARCH_TOOLS = /* @__PURE__ */ new Set(["Glob", "Grep", "LS"]);
2610
2620
  var WEB_TOOLS = /* @__PURE__ */ new Set(["WebSearch", "WebFetch"]);
2611
- var AGENT_TOOLS = /* @__PURE__ */ new Set(["Task", "TodoWrite"]);
2621
+ var AGENT_TOOLS = /* @__PURE__ */ new Set(["Task", "TodoWrite", "Skill"]);
2612
2622
  var BASE_ALLOWED_TOOLS = [
2613
2623
  ...READ_TOOLS,
2614
2624
  ...SEARCH_TOOLS,
@@ -3235,12 +3245,8 @@ function clearStatsigCache() {
3235
3245
  process.env.CLAUDE_CONFIG_DIR || path2.join(os2.homedir(), ".claude"),
3236
3246
  "statsig"
3237
3247
  );
3238
- try {
3239
- if (fs.existsSync(statsigPath)) {
3240
- fs.rmSync(statsigPath, { recursive: true, force: true });
3241
- }
3242
- } catch {
3243
- }
3248
+ fs.rm(statsigPath, { recursive: true, force: true }, () => {
3249
+ });
3244
3250
  }
3245
3251
 
3246
3252
  // src/adapters/claude/claude-agent.ts
@@ -3302,7 +3308,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3302
3308
  const sessionId = uuidv7();
3303
3309
  const permissionMode = meta?.permissionMode && TWIG_EXECUTION_MODES.includes(meta.permissionMode) ? meta.permissionMode : "default";
3304
3310
  const mcpServers = parseMcpServers(params);
3305
- await fetchMcpToolMetadata(mcpServers, this.logger);
3311
+ const mcpMetadataPromise = fetchMcpToolMetadata(mcpServers, this.logger);
3306
3312
  const options = buildSessionOptions({
3307
3313
  cwd: params.cwd,
3308
3314
  mcpServers,
@@ -3336,13 +3342,14 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3336
3342
  adapter: "claude"
3337
3343
  });
3338
3344
  }
3339
- const modelOptions = await this.getModelConfigOptions();
3345
+ const [modelOptions, slashCommands] = await Promise.all([
3346
+ this.getModelConfigOptions(),
3347
+ getAvailableSlashCommands(q),
3348
+ mcpMetadataPromise
3349
+ ]);
3340
3350
  session.modelId = modelOptions.currentModelId;
3341
3351
  await this.trySetModel(q, modelOptions.currentModelId);
3342
- this.sendAvailableCommandsUpdate(
3343
- sessionId,
3344
- await getAvailableSlashCommands(q)
3345
- );
3352
+ this.sendAvailableCommandsUpdate(sessionId, slashCommands);
3346
3353
  return {
3347
3354
  sessionId,
3348
3355
  configOptions: await this.buildConfigOptions(modelOptions)
@@ -3361,7 +3368,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3361
3368
  return {};
3362
3369
  }
3363
3370
  const mcpServers = parseMcpServers(params);
3364
- await fetchMcpToolMetadata(mcpServers, this.logger);
3371
+ const mcpMetadataPromise = fetchMcpToolMetadata(mcpServers, this.logger);
3365
3372
  const permissionMode = meta?.permissionMode && TWIG_EXECUTION_MODES.includes(meta.permissionMode) ? meta.permissionMode : "default";
3366
3373
  const { query: q, session } = await this.initializeQuery({
3367
3374
  cwd: params.cwd,
@@ -3375,10 +3382,11 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3375
3382
  });
3376
3383
  session.taskRunId = meta?.taskRunId;
3377
3384
  this.registerPersistence(sessionId, meta);
3378
- this.sendAvailableCommandsUpdate(
3379
- sessionId,
3380
- await getAvailableSlashCommands(q)
3381
- );
3385
+ const [slashCommands] = await Promise.all([
3386
+ getAvailableSlashCommands(q),
3387
+ mcpMetadataPromise
3388
+ ]);
3389
+ this.sendAvailableCommandsUpdate(sessionId, slashCommands);
3382
3390
  return {
3383
3391
  configOptions: await this.buildConfigOptions()
3384
3392
  };
@@ -9231,7 +9239,7 @@ async function getHeadSha(baseDir, options) {
9231
9239
  }
9232
9240
 
9233
9241
  // src/sagas/apply-snapshot-saga.ts
9234
- import { mkdir as mkdir3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
9242
+ import { mkdir as mkdir3, rm as rm3, writeFile as writeFile3 } from "fs/promises";
9235
9243
  import { join as join5 } from "path";
9236
9244
 
9237
9245
  // ../shared/dist/index.js
@@ -9672,7 +9680,7 @@ var ApplySnapshotSaga = class extends Saga {
9672
9680
  },
9673
9681
  rollback: async () => {
9674
9682
  if (this.archivePath) {
9675
- await rm2(this.archivePath, { force: true }).catch(() => {
9683
+ await rm3(this.archivePath, { force: true }).catch(() => {
9676
9684
  });
9677
9685
  }
9678
9686
  }
@@ -9688,7 +9696,7 @@ var ApplySnapshotSaga = class extends Saga {
9688
9696
  if (!applyResult.success) {
9689
9697
  throw new Error(`Failed to apply tree: ${applyResult.error}`);
9690
9698
  }
9691
- await rm2(this.archivePath, { force: true }).catch(() => {
9699
+ await rm3(this.archivePath, { force: true }).catch(() => {
9692
9700
  });
9693
9701
  this.log.info("Tree snapshot applied", {
9694
9702
  treeHash: snapshot.treeHash,
@@ -9701,7 +9709,7 @@ var ApplySnapshotSaga = class extends Saga {
9701
9709
 
9702
9710
  // src/sagas/capture-tree-saga.ts
9703
9711
  import { existsSync as existsSync5 } from "fs";
9704
- import { readFile as readFile3, rm as rm3 } from "fs/promises";
9712
+ import { readFile as readFile3, rm as rm4 } from "fs/promises";
9705
9713
  import { join as join6 } from "path";
9706
9714
  var CaptureTreeSaga2 = class extends Saga {
9707
9715
  async execute(input) {
@@ -9750,7 +9758,7 @@ var CaptureTreeSaga2 = class extends Saga {
9750
9758
  runId
9751
9759
  );
9752
9760
  } finally {
9753
- await rm3(createdArchivePath, { force: true }).catch(() => {
9761
+ await rm4(createdArchivePath, { force: true }).catch(() => {
9754
9762
  });
9755
9763
  }
9756
9764
  }
@@ -9794,7 +9802,7 @@ var CaptureTreeSaga2 = class extends Saga {
9794
9802
  return void 0;
9795
9803
  },
9796
9804
  rollback: async () => {
9797
- await rm3(archivePath, { force: true }).catch(() => {
9805
+ await rm4(archivePath, { force: true }).catch(() => {
9798
9806
  });
9799
9807
  }
9800
9808
  });