@posthog/agent 2.3.508 → 2.3.513

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.
package/dist/agent.js CHANGED
@@ -63,11 +63,11 @@ var require_tree_sitter = __commonJS({
63
63
  throw toThrow;
64
64
  };
65
65
  var scriptDirectory = "";
66
- function locateFile(path15) {
66
+ function locateFile(path16) {
67
67
  if (Module["locateFile"]) {
68
- return Module["locateFile"](path15, scriptDirectory);
68
+ return Module["locateFile"](path16, scriptDirectory);
69
69
  }
70
- return scriptDirectory + path15;
70
+ return scriptDirectory + path16;
71
71
  }
72
72
  var readAsync, readBinary;
73
73
  if (ENVIRONMENT_IS_NODE) {
@@ -2588,8 +2588,8 @@ var require_tree_sitter = __commonJS({
2588
2588
  } else {
2589
2589
  const url = input;
2590
2590
  if (typeof process !== "undefined" && process.versions && process.versions.node) {
2591
- const fs11 = __require("fs");
2592
- bytes = Promise.resolve(fs11.readFileSync(url));
2591
+ const fs12 = __require("fs");
2592
+ bytes = Promise.resolve(fs12.readFileSync(url));
2593
2593
  } else {
2594
2594
  bytes = fetch(url).then((response) => response.arrayBuffer().then((buffer) => {
2595
2595
  if (response.ok) {
@@ -3400,7 +3400,7 @@ var require_has_flag = __commonJS({
3400
3400
  var require_supports_color = __commonJS({
3401
3401
  "../../node_modules/supports-color/index.js"(exports2, module2) {
3402
3402
  "use strict";
3403
- var os6 = __require("os");
3403
+ var os7 = __require("os");
3404
3404
  var tty = __require("tty");
3405
3405
  var hasFlag = require_has_flag();
3406
3406
  var { env } = process;
@@ -3448,7 +3448,7 @@ var require_supports_color = __commonJS({
3448
3448
  return min;
3449
3449
  }
3450
3450
  if (process.platform === "win32") {
3451
- const osRelease = os6.release().split(".");
3451
+ const osRelease = os7.release().split(".");
3452
3452
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
3453
3453
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
3454
3454
  }
@@ -3696,10 +3696,10 @@ var require_src2 = __commonJS({
3696
3696
  var fs_1 = __require("fs");
3697
3697
  var debug_1 = __importDefault(require_src());
3698
3698
  var log = debug_1.default("@kwsites/file-exists");
3699
- function check(path15, isFile2, isDirectory) {
3700
- log(`checking %s`, path15);
3699
+ function check(path16, isFile2, isDirectory) {
3700
+ log(`checking %s`, path16);
3701
3701
  try {
3702
- const stat2 = fs_1.statSync(path15);
3702
+ const stat2 = fs_1.statSync(path16);
3703
3703
  if (stat2.isFile() && isFile2) {
3704
3704
  log(`[OK] path represents a file`);
3705
3705
  return true;
@@ -3719,8 +3719,8 @@ var require_src2 = __commonJS({
3719
3719
  throw e;
3720
3720
  }
3721
3721
  }
3722
- function exists2(path15, type = exports2.READABLE) {
3723
- return check(path15, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
3722
+ function exists2(path16, type = exports2.READABLE) {
3723
+ return check(path16, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
3724
3724
  }
3725
3725
  exports2.exists = exists2;
3726
3726
  exports2.FILE = 1;
@@ -4014,9 +4014,9 @@ function nodeWritableToWebWritable(nodeStream) {
4014
4014
 
4015
4015
  // src/adapters/claude/claude-agent.ts
4016
4016
  import { randomUUID } from "crypto";
4017
- import * as fs8 from "fs";
4018
- import * as os4 from "os";
4019
- import * as path12 from "path";
4017
+ import * as fs9 from "fs";
4018
+ import * as os5 from "os";
4019
+ import * as path13 from "path";
4020
4020
  import {
4021
4021
  RequestError as RequestError2
4022
4022
  } from "@agentclientprotocol/sdk";
@@ -4030,7 +4030,7 @@ import { v7 as uuidv7 } from "uuid";
4030
4030
  // package.json
4031
4031
  var package_default = {
4032
4032
  name: "@posthog/agent",
4033
- version: "2.3.508",
4033
+ version: "2.3.513",
4034
4034
  repository: "https://github.com/PostHog/code",
4035
4035
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
4036
4036
  exports: {
@@ -8669,8 +8669,8 @@ var ToolContentBuilder = class {
8669
8669
  this.items.push({ type: "content", content: image(data, mimeType, uri) });
8670
8670
  return this;
8671
8671
  }
8672
- diff(path15, oldText, newText) {
8673
- this.items.push({ type: "diff", path: path15, oldText, newText });
8672
+ diff(path16, oldText, newText) {
8673
+ this.items.push({ type: "diff", path: path16, oldText, newText });
8674
8674
  return this;
8675
8675
  }
8676
8676
  build() {
@@ -8681,6 +8681,54 @@ function toolContent() {
8681
8681
  return new ToolContentBuilder();
8682
8682
  }
8683
8683
 
8684
+ // src/utils/partial-json.ts
8685
+ function tryParsePartialJson(s) {
8686
+ const trimmed2 = s.trim();
8687
+ if (!trimmed2) return null;
8688
+ try {
8689
+ return JSON.parse(trimmed2);
8690
+ } catch {
8691
+ }
8692
+ const closers = [];
8693
+ let inString = false;
8694
+ let escaped = false;
8695
+ for (let i2 = 0; i2 < trimmed2.length; i2++) {
8696
+ const ch = trimmed2[i2];
8697
+ if (inString) {
8698
+ if (escaped) {
8699
+ escaped = false;
8700
+ } else if (ch === "\\") {
8701
+ escaped = true;
8702
+ } else if (ch === '"') {
8703
+ inString = false;
8704
+ }
8705
+ continue;
8706
+ }
8707
+ if (ch === '"') inString = true;
8708
+ else if (ch === "{") closers.push("}");
8709
+ else if (ch === "[") closers.push("]");
8710
+ else if (ch === "}" || ch === "]") closers.pop();
8711
+ }
8712
+ const closeBrackets = (str) => {
8713
+ let out2 = str;
8714
+ for (let i2 = closers.length - 1; i2 >= 0; i2--) out2 += closers[i2];
8715
+ return out2;
8716
+ };
8717
+ const candidates = [];
8718
+ const closedString = inString ? `${trimmed2}"` : trimmed2;
8719
+ candidates.push(closeBrackets(closedString));
8720
+ let stripped = closedString.replace(/[,:]\s*$/, "");
8721
+ stripped = stripped.replace(/,?\s*"[^"]*"\s*:?\s*$/, "");
8722
+ candidates.push(closeBrackets(stripped));
8723
+ for (const candidate of candidates) {
8724
+ try {
8725
+ return JSON.parse(candidate);
8726
+ } catch {
8727
+ }
8728
+ }
8729
+ return null;
8730
+ }
8731
+
8684
8732
  // src/adapters/claude/permissions/posthog-exec-gate.ts
8685
8733
  var POSTHOG_EXEC_TOOL_RE = /^mcp__posthog(?:_[^_]+)*__exec$/;
8686
8734
  var POSTHOG_CALL_COMMAND_RE = /^\s*call\s+(?:--json\s+)?([a-zA-Z0-9_-]+)/;
@@ -9847,12 +9895,19 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
9847
9895
  }
9848
9896
  return output;
9849
9897
  }
9850
- function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId, registerHooks, supportsTerminalOutput, cwd, enrichedReadCache) {
9898
+ function streamEventToAcpNotifications(message, sessionId, toolUseCache, toolUseStreamCache, fileContentCache, client, logger, parentToolCallId, registerHooks, supportsTerminalOutput, cwd, enrichedReadCache) {
9851
9899
  const event = message.event;
9852
9900
  switch (event.type) {
9853
- case "content_block_start":
9901
+ case "content_block_start": {
9902
+ const block = event.content_block;
9903
+ if (block.type === "tool_use" || block.type === "mcp_tool_use") {
9904
+ toolUseStreamCache.set(event.index, {
9905
+ toolUseId: block.id,
9906
+ partialJson: ""
9907
+ });
9908
+ }
9854
9909
  return toAcpNotifications(
9855
- [event.content_block],
9910
+ [block],
9856
9911
  "assistant",
9857
9912
  sessionId,
9858
9913
  toolUseCache,
@@ -9866,7 +9921,16 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
9866
9921
  void 0,
9867
9922
  enrichedReadCache
9868
9923
  );
9869
- case "content_block_delta":
9924
+ }
9925
+ case "content_block_delta": {
9926
+ if (event.delta.type === "input_json_delta") {
9927
+ return inputJsonDeltaToAcpNotifications(
9928
+ event.index,
9929
+ event.delta.partial_json,
9930
+ sessionId,
9931
+ toolUseStreamCache
9932
+ );
9933
+ }
9870
9934
  return toAcpNotifications(
9871
9935
  [event.delta],
9872
9936
  "assistant",
@@ -9882,16 +9946,36 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
9882
9946
  void 0,
9883
9947
  enrichedReadCache
9884
9948
  );
9949
+ }
9950
+ case "content_block_stop":
9951
+ toolUseStreamCache.delete(event.index);
9952
+ return [];
9885
9953
  case "message_start":
9886
9954
  case "message_delta":
9887
9955
  case "message_stop":
9888
- case "content_block_stop":
9889
9956
  return [];
9890
9957
  default:
9891
9958
  unreachable(event, logger);
9892
9959
  return [];
9893
9960
  }
9894
9961
  }
9962
+ function inputJsonDeltaToAcpNotifications(index, partialJson, sessionId, toolUseStreamCache) {
9963
+ const entry = toolUseStreamCache.get(index);
9964
+ if (!entry) return [];
9965
+ entry.partialJson += partialJson;
9966
+ const parsed = tryParsePartialJson(entry.partialJson);
9967
+ if (!parsed || typeof parsed !== "object") return [];
9968
+ return [
9969
+ {
9970
+ sessionId,
9971
+ update: {
9972
+ sessionUpdate: "tool_call_update",
9973
+ toolCallId: entry.toolUseId,
9974
+ rawInput: parsed
9975
+ }
9976
+ }
9977
+ ];
9978
+ }
9895
9979
  async function handleSystemMessage(message, context) {
9896
9980
  const { session, sessionId, client, logger } = context;
9897
9981
  switch (message.subtype) {
@@ -10035,12 +10119,20 @@ function extractUsageFromResult(message) {
10035
10119
  };
10036
10120
  }
10037
10121
  async function handleStreamEvent(message, context) {
10038
- const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
10122
+ const {
10123
+ sessionId,
10124
+ client,
10125
+ toolUseCache,
10126
+ toolUseStreamCache,
10127
+ fileContentCache,
10128
+ logger
10129
+ } = context;
10039
10130
  const parentToolCallId = message.parent_tool_use_id ?? void 0;
10040
10131
  for (const notification of streamEventToAcpNotifications(
10041
10132
  message,
10042
10133
  sessionId,
10043
10134
  toolUseCache,
10135
+ toolUseStreamCache,
10044
10136
  fileContentCache,
10045
10137
  client,
10046
10138
  logger,
@@ -10953,6 +11045,31 @@ function getAvailableSlashCommands(commands) {
10953
11045
  }
10954
11046
 
10955
11047
  // src/adapters/claude/session/mcp-config.ts
11048
+ import * as fs4 from "fs";
11049
+ import * as os2 from "os";
11050
+ import * as path8 from "path";
11051
+ function loadUserClaudeJsonMcpServers(cwd, logger, homeDir = os2.homedir()) {
11052
+ const claudeJsonPath = path8.join(homeDir, ".claude.json");
11053
+ let raw;
11054
+ try {
11055
+ raw = fs4.readFileSync(claudeJsonPath, "utf8");
11056
+ } catch {
11057
+ return {};
11058
+ }
11059
+ let cfg;
11060
+ try {
11061
+ cfg = JSON.parse(raw);
11062
+ } catch (err2) {
11063
+ logger?.warn("Failed to parse ~/.claude.json", {
11064
+ error: err2 instanceof Error ? err2.message : String(err2)
11065
+ });
11066
+ return {};
11067
+ }
11068
+ const topLevel = cfg.mcpServers && typeof cfg.mcpServers === "object" ? cfg.mcpServers : {};
11069
+ const project = cfg.projects?.[cwd];
11070
+ const projectScoped = project?.mcpServers && typeof project.mcpServers === "object" ? project.mcpServers : {};
11071
+ return { ...topLevel, ...projectScoped };
11072
+ }
10956
11073
  function parseMcpServers(params) {
10957
11074
  const mcpServers = {};
10958
11075
  if (!Array.isArray(params.mcpServers)) {
@@ -11086,9 +11203,9 @@ function resolveModelPreference(preference, options) {
11086
11203
 
11087
11204
  // src/adapters/claude/session/options.ts
11088
11205
  import { spawn } from "child_process";
11089
- import * as fs4 from "fs";
11090
- import * as os2 from "os";
11091
- import * as path8 from "path";
11206
+ import * as fs5 from "fs";
11207
+ import * as os3 from "os";
11208
+ import * as path9 from "path";
11092
11209
 
11093
11210
  // src/adapters/claude/session/instructions.ts
11094
11211
  var BRANCH_NAMING = `
@@ -11139,8 +11256,9 @@ function buildSystemPrompt(customPrompt) {
11139
11256
  }
11140
11257
  return defaultPrompt;
11141
11258
  }
11142
- function buildMcpServers(userServers, acpServers) {
11259
+ function buildMcpServers(userServers, acpServers, projectScopedServers) {
11143
11260
  return {
11261
+ ...projectScopedServers,
11144
11262
  ...userServers || {},
11145
11263
  ...acpServers
11146
11264
  };
@@ -11289,12 +11407,12 @@ function buildSpawnWrapper(sessionId, onProcessSpawned, onProcessExited, logger)
11289
11407
  };
11290
11408
  }
11291
11409
  function ensureLocalSettings(cwd) {
11292
- const claudeDir = path8.join(cwd, ".claude");
11293
- const localSettingsPath = path8.join(claudeDir, "settings.local.json");
11410
+ const claudeDir = path9.join(cwd, ".claude");
11411
+ const localSettingsPath = path9.join(claudeDir, "settings.local.json");
11294
11412
  try {
11295
- if (!fs4.existsSync(localSettingsPath)) {
11296
- fs4.mkdirSync(claudeDir, { recursive: true });
11297
- fs4.writeFileSync(localSettingsPath, "{}\n", { flag: "wx" });
11413
+ if (!fs5.existsSync(localSettingsPath)) {
11414
+ fs5.mkdirSync(claudeDir, { recursive: true });
11415
+ fs5.writeFileSync(localSettingsPath, "{}\n", { flag: "wx" });
11298
11416
  }
11299
11417
  } catch {
11300
11418
  }
@@ -11324,7 +11442,8 @@ function buildSessionOptions(params) {
11324
11442
  },
11325
11443
  mcpServers: buildMcpServers(
11326
11444
  params.userProvidedOptions?.mcpServers,
11327
- params.mcpServers
11445
+ params.mcpServers,
11446
+ loadUserClaudeJsonMcpServers(params.cwd, params.logger)
11328
11447
  ),
11329
11448
  env: buildEnvironment(),
11330
11449
  hooks: buildHooks(
@@ -11369,18 +11488,18 @@ function buildSessionOptions(params) {
11369
11488
  return options;
11370
11489
  }
11371
11490
  function clearStatsigCache() {
11372
- const statsigPath = path8.join(
11373
- process.env.CLAUDE_CONFIG_DIR || path8.join(os2.homedir(), ".claude"),
11491
+ const statsigPath = path9.join(
11492
+ process.env.CLAUDE_CONFIG_DIR || path9.join(os3.homedir(), ".claude"),
11374
11493
  "statsig"
11375
11494
  );
11376
- fs4.rm(statsigPath, { recursive: true, force: true }, () => {
11495
+ fs5.rm(statsigPath, { recursive: true, force: true }, () => {
11377
11496
  });
11378
11497
  }
11379
11498
 
11380
11499
  // src/adapters/claude/session/settings.ts
11381
- import * as fs7 from "fs";
11382
- import * as os3 from "os";
11383
- import * as path11 from "path";
11500
+ import * as fs8 from "fs";
11501
+ import * as os4 from "os";
11502
+ import * as path12 from "path";
11384
11503
  import { minimatch } from "minimatch";
11385
11504
 
11386
11505
  // src/utils/async-mutex.ts
@@ -11413,8 +11532,8 @@ var AsyncMutex = class {
11413
11532
  };
11414
11533
 
11415
11534
  // ../git/dist/queries.js
11416
- import * as fs6 from "fs/promises";
11417
- import * as path10 from "path";
11535
+ import * as fs7 from "fs/promises";
11536
+ import * as path11 from "path";
11418
11537
 
11419
11538
  // ../../node_modules/simple-git/dist/esm/index.js
11420
11539
  var import_file_exists = __toESM(require_dist(), 1);
@@ -11453,8 +11572,8 @@ function pathspec(...paths) {
11453
11572
  cache.set(key, paths);
11454
11573
  return key;
11455
11574
  }
11456
- function isPathSpec(path15) {
11457
- return path15 instanceof String && cache.has(path15);
11575
+ function isPathSpec(path16) {
11576
+ return path16 instanceof String && cache.has(path16);
11458
11577
  }
11459
11578
  function toPaths(pathSpec) {
11460
11579
  return cache.get(pathSpec) || [];
@@ -11543,8 +11662,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
11543
11662
  function forEachLineWithContent(input, callback) {
11544
11663
  return toLinesWithContent(input, true).map((line) => callback(line));
11545
11664
  }
11546
- function folderExists(path15) {
11547
- return (0, import_file_exists.exists)(path15, import_file_exists.FOLDER);
11665
+ function folderExists(path16) {
11666
+ return (0, import_file_exists.exists)(path16, import_file_exists.FOLDER);
11548
11667
  }
11549
11668
  function append(target, item) {
11550
11669
  if (Array.isArray(target)) {
@@ -11948,8 +12067,8 @@ function checkIsRepoRootTask() {
11948
12067
  commands,
11949
12068
  format: "utf-8",
11950
12069
  onError,
11951
- parser(path15) {
11952
- return /^\.(git)?$/.test(path15.trim());
12070
+ parser(path16) {
12071
+ return /^\.(git)?$/.test(path16.trim());
11953
12072
  }
11954
12073
  };
11955
12074
  }
@@ -12383,11 +12502,11 @@ function parseGrep(grep) {
12383
12502
  const paths = /* @__PURE__ */ new Set();
12384
12503
  const results = {};
12385
12504
  forEachLineWithContent(grep, (input) => {
12386
- const [path15, line, preview] = input.split(NULL);
12387
- paths.add(path15);
12388
- (results[path15] = results[path15] || []).push({
12505
+ const [path16, line, preview] = input.split(NULL);
12506
+ paths.add(path16);
12507
+ (results[path16] = results[path16] || []).push({
12389
12508
  line: asNumber(line),
12390
- path: path15,
12509
+ path: path16,
12391
12510
  preview
12392
12511
  });
12393
12512
  });
@@ -13152,14 +13271,14 @@ var init_hash_object = __esm({
13152
13271
  init_task();
13153
13272
  }
13154
13273
  });
13155
- function parseInit(bare, path15, text2) {
13274
+ function parseInit(bare, path16, text2) {
13156
13275
  const response = String(text2).trim();
13157
13276
  let result;
13158
13277
  if (result = initResponseRegex.exec(response)) {
13159
- return new InitSummary(bare, path15, false, result[1]);
13278
+ return new InitSummary(bare, path16, false, result[1]);
13160
13279
  }
13161
13280
  if (result = reInitResponseRegex.exec(response)) {
13162
- return new InitSummary(bare, path15, true, result[1]);
13281
+ return new InitSummary(bare, path16, true, result[1]);
13163
13282
  }
13164
13283
  let gitDir = "";
13165
13284
  const tokens = response.split(" ");
@@ -13170,7 +13289,7 @@ function parseInit(bare, path15, text2) {
13170
13289
  break;
13171
13290
  }
13172
13291
  }
13173
- return new InitSummary(bare, path15, /^re/i.test(response), gitDir);
13292
+ return new InitSummary(bare, path16, /^re/i.test(response), gitDir);
13174
13293
  }
13175
13294
  var InitSummary;
13176
13295
  var initResponseRegex;
@@ -13179,9 +13298,9 @@ var init_InitSummary = __esm({
13179
13298
  "src/lib/responses/InitSummary.ts"() {
13180
13299
  "use strict";
13181
13300
  InitSummary = class {
13182
- constructor(bare, path15, existing, gitDir) {
13301
+ constructor(bare, path16, existing, gitDir) {
13183
13302
  this.bare = bare;
13184
- this.path = path15;
13303
+ this.path = path16;
13185
13304
  this.existing = existing;
13186
13305
  this.gitDir = gitDir;
13187
13306
  }
@@ -13193,7 +13312,7 @@ var init_InitSummary = __esm({
13193
13312
  function hasBareCommand(command) {
13194
13313
  return command.includes(bareCommand);
13195
13314
  }
13196
- function initTask(bare = false, path15, customArgs) {
13315
+ function initTask(bare = false, path16, customArgs) {
13197
13316
  const commands = ["init", ...customArgs];
13198
13317
  if (bare && !hasBareCommand(commands)) {
13199
13318
  commands.splice(1, 0, bareCommand);
@@ -13202,7 +13321,7 @@ function initTask(bare = false, path15, customArgs) {
13202
13321
  commands,
13203
13322
  format: "utf-8",
13204
13323
  parser(text2) {
13205
- return parseInit(commands.includes("--bare"), path15, text2);
13324
+ return parseInit(commands.includes("--bare"), path16, text2);
13206
13325
  }
13207
13326
  };
13208
13327
  }
@@ -14018,12 +14137,12 @@ var init_FileStatusSummary = __esm({
14018
14137
  "use strict";
14019
14138
  fromPathRegex = /^(.+)\0(.+)$/;
14020
14139
  FileStatusSummary = class {
14021
- constructor(path15, index, working_dir) {
14022
- this.path = path15;
14140
+ constructor(path16, index, working_dir) {
14141
+ this.path = path16;
14023
14142
  this.index = index;
14024
14143
  this.working_dir = working_dir;
14025
14144
  if (index === "R" || working_dir === "R") {
14026
- const detail = fromPathRegex.exec(path15) || [null, path15, path15];
14145
+ const detail = fromPathRegex.exec(path16) || [null, path16, path16];
14027
14146
  this.from = detail[2] || "";
14028
14147
  this.path = detail[1] || "";
14029
14148
  }
@@ -14054,14 +14173,14 @@ function splitLine(result, lineStr) {
14054
14173
  default:
14055
14174
  return;
14056
14175
  }
14057
- function data(index, workingDir, path15) {
14176
+ function data(index, workingDir, path16) {
14058
14177
  const raw = `${index}${workingDir}`;
14059
14178
  const handler = parsers6.get(raw);
14060
14179
  if (handler) {
14061
- handler(result, path15);
14180
+ handler(result, path16);
14062
14181
  }
14063
14182
  if (raw !== "##" && raw !== "!!") {
14064
- result.files.push(new FileStatusSummary(path15, index, workingDir));
14183
+ result.files.push(new FileStatusSummary(path16, index, workingDir));
14065
14184
  }
14066
14185
  }
14067
14186
  }
@@ -14374,9 +14493,9 @@ var init_simple_git_api = __esm({
14374
14493
  next
14375
14494
  );
14376
14495
  }
14377
- hashObject(path15, write) {
14496
+ hashObject(path16, write) {
14378
14497
  return this._runTask(
14379
- hashObjectTask(path15, write === true),
14498
+ hashObjectTask(path16, write === true),
14380
14499
  trailingFunctionArgument(arguments)
14381
14500
  );
14382
14501
  }
@@ -14729,8 +14848,8 @@ var init_branch = __esm({
14729
14848
  }
14730
14849
  });
14731
14850
  function toPath(input) {
14732
- const path15 = input.trim().replace(/^["']|["']$/g, "");
14733
- return path15 && normalize(path15);
14851
+ const path16 = input.trim().replace(/^["']|["']$/g, "");
14852
+ return path16 && normalize(path16);
14734
14853
  }
14735
14854
  var parseCheckIgnore;
14736
14855
  var init_CheckIgnore = __esm({
@@ -15044,8 +15163,8 @@ __export(sub_module_exports, {
15044
15163
  subModuleTask: () => subModuleTask,
15045
15164
  updateSubModuleTask: () => updateSubModuleTask
15046
15165
  });
15047
- function addSubModuleTask(repo, path15) {
15048
- return subModuleTask(["add", repo, path15]);
15166
+ function addSubModuleTask(repo, path16) {
15167
+ return subModuleTask(["add", repo, path16]);
15049
15168
  }
15050
15169
  function initSubModuleTask(customArgs) {
15051
15170
  return subModuleTask(["init", ...customArgs]);
@@ -15375,8 +15494,8 @@ var require_git = __commonJS2({
15375
15494
  }
15376
15495
  return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
15377
15496
  };
15378
- Git2.prototype.submoduleAdd = function(repo, path15, then) {
15379
- return this._runTask(addSubModuleTask2(repo, path15), trailingFunctionArgument2(arguments));
15497
+ Git2.prototype.submoduleAdd = function(repo, path16, then) {
15498
+ return this._runTask(addSubModuleTask2(repo, path16), trailingFunctionArgument2(arguments));
15380
15499
  };
15381
15500
  Git2.prototype.submoduleUpdate = function(args2, then) {
15382
15501
  return this._runTask(
@@ -15977,22 +16096,22 @@ function createGitClient(baseDir, options) {
15977
16096
 
15978
16097
  // ../git/dist/lock-detector.js
15979
16098
  import { execFile } from "child_process";
15980
- import fs5 from "fs/promises";
15981
- import path9 from "path";
16099
+ import fs6 from "fs/promises";
16100
+ import path10 from "path";
15982
16101
  import { promisify } from "util";
15983
16102
  var execFileAsync = promisify(execFile);
15984
16103
  async function getIndexLockPath(repoPath) {
15985
16104
  try {
15986
16105
  const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "index.lock"], { cwd: repoPath });
15987
- return path9.resolve(repoPath, stdout.trim());
16106
+ return path10.resolve(repoPath, stdout.trim());
15988
16107
  } catch {
15989
- return path9.join(repoPath, ".git", "index.lock");
16108
+ return path10.join(repoPath, ".git", "index.lock");
15990
16109
  }
15991
16110
  }
15992
16111
  async function getLockInfo(repoPath) {
15993
16112
  const lockPath = await getIndexLockPath(repoPath);
15994
16113
  try {
15995
- const stat2 = await fs5.stat(lockPath);
16114
+ const stat2 = await fs6.stat(lockPath);
15996
16115
  return {
15997
16116
  path: lockPath,
15998
16117
  ageMs: Date.now() - stat2.mtimeMs
@@ -16003,7 +16122,7 @@ async function getLockInfo(repoPath) {
16003
16122
  }
16004
16123
  async function removeLock(repoPath) {
16005
16124
  const lockPath = await getIndexLockPath(repoPath);
16006
- await fs5.rm(lockPath, { force: true });
16125
+ await fs6.rm(lockPath, { force: true });
16007
16126
  }
16008
16127
  async function isLocked(repoPath) {
16009
16128
  return await getLockInfo(repoPath) !== null;
@@ -16252,13 +16371,13 @@ function parseRule(rule) {
16252
16371
  function normalizePath(filePath, cwd) {
16253
16372
  let resolved = filePath;
16254
16373
  if (resolved.startsWith("~/")) {
16255
- resolved = path11.join(os3.homedir(), resolved.slice(2));
16374
+ resolved = path12.join(os4.homedir(), resolved.slice(2));
16256
16375
  } else if (resolved.startsWith("./")) {
16257
- resolved = path11.join(cwd, resolved.slice(2));
16258
- } else if (!path11.isAbsolute(resolved)) {
16259
- resolved = path11.join(cwd, resolved);
16376
+ resolved = path12.join(cwd, resolved.slice(2));
16377
+ } else if (!path12.isAbsolute(resolved)) {
16378
+ resolved = path12.join(cwd, resolved);
16260
16379
  }
16261
- return path11.normalize(resolved).replace(/\\/g, "/");
16380
+ return path12.normalize(resolved).replace(/\\/g, "/");
16262
16381
  }
16263
16382
  function matchesGlob(pattern, filePath, cwd) {
16264
16383
  const normalizedPattern = normalizePath(pattern, cwd);
@@ -16305,11 +16424,11 @@ function formatRule(rule) {
16305
16424
  }
16306
16425
  async function writeFileAtomic(filePath, data) {
16307
16426
  const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
16308
- await fs7.promises.writeFile(tmpPath, data);
16427
+ await fs8.promises.writeFile(tmpPath, data);
16309
16428
  try {
16310
- await fs7.promises.rename(tmpPath, filePath);
16429
+ await fs8.promises.rename(tmpPath, filePath);
16311
16430
  } catch (error) {
16312
- await fs7.promises.rm(tmpPath, { force: true });
16431
+ await fs8.promises.rm(tmpPath, { force: true });
16313
16432
  throw error;
16314
16433
  }
16315
16434
  }
@@ -16318,7 +16437,7 @@ async function loadSettingsFile(filePath) {
16318
16437
  return {};
16319
16438
  }
16320
16439
  try {
16321
- const content = await fs7.promises.readFile(filePath, "utf-8");
16440
+ const content = await fs8.promises.readFile(filePath, "utf-8");
16322
16441
  return JSON.parse(content);
16323
16442
  } catch (error) {
16324
16443
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -16333,7 +16452,7 @@ async function loadSettingsFile(filePath) {
16333
16452
  }
16334
16453
  async function readSettingsFileForUpdate(filePath) {
16335
16454
  try {
16336
- const content = await fs7.promises.readFile(filePath, "utf-8");
16455
+ const content = await fs8.promises.readFile(filePath, "utf-8");
16337
16456
  return JSON.parse(content);
16338
16457
  } catch (error) {
16339
16458
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -16379,11 +16498,11 @@ var SettingsManager = class {
16379
16498
  return this.initPromise;
16380
16499
  }
16381
16500
  getUserSettingsPath() {
16382
- const configDir = process.env.CLAUDE_CONFIG_DIR || path11.join(os3.homedir(), ".claude");
16383
- return path11.join(configDir, "settings.json");
16501
+ const configDir = process.env.CLAUDE_CONFIG_DIR || path12.join(os4.homedir(), ".claude");
16502
+ return path12.join(configDir, "settings.json");
16384
16503
  }
16385
16504
  getProjectSettingsPath() {
16386
- return path11.join(this.cwd, ".claude", "settings.json");
16505
+ return path12.join(this.cwd, ".claude", "settings.json");
16387
16506
  }
16388
16507
  /**
16389
16508
  * Local settings are anchored to the primary worktree so every worktree of
@@ -16391,7 +16510,7 @@ var SettingsManager = class {
16391
16510
  * avoids re-prompting for the same permission in every worktree.
16392
16511
  */
16393
16512
  getLocalSettingsPath() {
16394
- return path11.join(this.repoRoot, ".claude", "settings.local.json");
16513
+ return path12.join(this.repoRoot, ".claude", "settings.local.json");
16395
16514
  }
16396
16515
  async loadAllSettings() {
16397
16516
  this.repoRoot = await resolveMainRepoPath(this.cwd);
@@ -16518,7 +16637,7 @@ var SettingsManager = class {
16518
16637
  }
16519
16638
  permissions.allow = Array.from(current2);
16520
16639
  const next = { ...existing, permissions };
16521
- await fs7.promises.mkdir(path11.dirname(filePath), { recursive: true });
16640
+ await fs8.promises.mkdir(path12.dirname(filePath), { recursive: true });
16522
16641
  await writeFileAtomic(filePath, `${JSON.stringify(next, null, 2)}
16523
16642
  `);
16524
16643
  this.localSettings = next;
@@ -16551,7 +16670,7 @@ var SettingsManager = class {
16551
16670
  ...existing,
16552
16671
  posthogApprovedExecTools: Array.from(current2)
16553
16672
  };
16554
- await fs7.promises.mkdir(path11.dirname(filePath), { recursive: true });
16673
+ await fs8.promises.mkdir(path12.dirname(filePath), { recursive: true });
16555
16674
  await writeFileAtomic(filePath, `${JSON.stringify(next, null, 2)}
16556
16675
  `);
16557
16676
  this.localSettings = next;
@@ -16594,6 +16713,7 @@ function shouldEmitRawMessage(config, message) {
16594
16713
  var ClaudeAcpAgent = class extends BaseAcpAgent {
16595
16714
  adapterName = "claude";
16596
16715
  toolUseCache;
16716
+ toolUseStreamCache;
16597
16717
  backgroundTerminals = {};
16598
16718
  clientCapabilities;
16599
16719
  options;
@@ -16603,6 +16723,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
16603
16723
  super(client);
16604
16724
  this.options = options;
16605
16725
  this.toolUseCache = {};
16726
+ this.toolUseStreamCache = /* @__PURE__ */ new Map();
16606
16727
  this.logger = new Logger({ debug: true, prefix: "[ClaudeAcpAgent]" });
16607
16728
  this.enrichment = createEnrichment(options?.posthogApiConfig, this.logger);
16608
16729
  }
@@ -16655,7 +16776,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
16655
16776
  };
16656
16777
  }
16657
16778
  async newSession(params) {
16658
- if (fs8.existsSync(path12.resolve(os4.homedir(), ".claude.json.backup")) && !fs8.existsSync(path12.resolve(os4.homedir(), ".claude.json"))) {
16779
+ if (fs9.existsSync(path13.resolve(os5.homedir(), ".claude.json.backup")) && !fs9.existsSync(path13.resolve(os5.homedir(), ".claude.json"))) {
16659
16780
  throw RequestError2.authRequired();
16660
16781
  }
16661
16782
  const response = await this.createSession(params, {
@@ -16797,6 +16918,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
16797
16918
  sessionId: params.sessionId,
16798
16919
  client: this.client,
16799
16920
  toolUseCache: this.toolUseCache,
16921
+ toolUseStreamCache: this.toolUseStreamCache,
16800
16922
  fileContentCache: this.fileContentCache,
16801
16923
  enrichedReadCache: this.enrichedReadCache,
16802
16924
  logger: this.logger,
@@ -17049,6 +17171,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
17049
17171
  }
17050
17172
  throw error;
17051
17173
  } finally {
17174
+ this.toolUseStreamCache.clear();
17052
17175
  if (!handedOff) {
17053
17176
  this.session.promptRunning = false;
17054
17177
  for (const [key, pending] of this.session.pendingMessages) {
@@ -17623,6 +17746,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
17623
17746
  sessionId,
17624
17747
  client: this.client,
17625
17748
  toolUseCache: this.toolUseCache,
17749
+ toolUseStreamCache: this.toolUseStreamCache,
17626
17750
  fileContentCache: this.fileContentCache,
17627
17751
  enrichedReadCache: this.enrichedReadCache,
17628
17752
  logger: this.logger,
@@ -17895,9 +18019,9 @@ function resetUsage(state) {
17895
18019
  }
17896
18020
 
17897
18021
  // src/adapters/codex/settings.ts
17898
- import * as fs9 from "fs";
17899
- import * as os5 from "os";
17900
- import * as path13 from "path";
18022
+ import * as fs10 from "fs";
18023
+ import * as os6 from "os";
18024
+ import * as path14 from "path";
17901
18025
  var CodexSettingsManager = class {
17902
18026
  cwd;
17903
18027
  settings = { mcpServerNames: [] };
@@ -17908,12 +18032,12 @@ var CodexSettingsManager = class {
17908
18032
  async initialize() {
17909
18033
  }
17910
18034
  getConfigPath() {
17911
- return path13.join(os5.homedir(), ".codex", "config.toml");
18035
+ return path14.join(os6.homedir(), ".codex", "config.toml");
17912
18036
  }
17913
18037
  loadSettings() {
17914
18038
  const configPath = this.getConfigPath();
17915
18039
  try {
17916
- const content = fs9.readFileSync(configPath, "utf-8");
18040
+ const content = fs10.readFileSync(configPath, "utf-8");
17917
18041
  this.settings = parseCodexToml(content, this.cwd);
17918
18042
  } catch {
17919
18043
  this.settings = { mcpServerNames: [] };
@@ -18891,9 +19015,9 @@ var PostHogAPIClient = class {
18891
19015
  };
18892
19016
 
18893
19017
  // src/session-log-writer.ts
18894
- import fs10 from "fs";
19018
+ import fs11 from "fs";
18895
19019
  import fsp from "fs/promises";
18896
- import path14 from "path";
19020
+ import path15 from "path";
18897
19021
  var SessionLogWriter = class _SessionLogWriter {
18898
19022
  static FLUSH_DEBOUNCE_MS = 500;
18899
19023
  static FLUSH_MAX_INTERVAL_MS = 5e3;
@@ -18929,13 +19053,13 @@ var SessionLogWriter = class _SessionLogWriter {
18929
19053
  this.sessions.set(sessionId, { context, currentTurnMessages: [] });
18930
19054
  this.lastFlushAttemptTime.set(sessionId, Date.now());
18931
19055
  if (this.localCachePath) {
18932
- const sessionDir = path14.join(
19056
+ const sessionDir = path15.join(
18933
19057
  this.localCachePath,
18934
19058
  "sessions",
18935
19059
  context.runId
18936
19060
  );
18937
19061
  try {
18938
- fs10.mkdirSync(sessionDir, { recursive: true });
19062
+ fs11.mkdirSync(sessionDir, { recursive: true });
18939
19063
  } catch (error) {
18940
19064
  this.logger.warn("Failed to create local cache directory", {
18941
19065
  sessionDir,
@@ -19187,14 +19311,14 @@ var SessionLogWriter = class _SessionLogWriter {
19187
19311
  if (!this.localCachePath) return;
19188
19312
  const session = this.sessions.get(sessionId);
19189
19313
  if (!session) return;
19190
- const logPath = path14.join(
19314
+ const logPath = path15.join(
19191
19315
  this.localCachePath,
19192
19316
  "sessions",
19193
19317
  session.context.runId,
19194
19318
  "logs.ndjson"
19195
19319
  );
19196
19320
  try {
19197
- fs10.appendFileSync(logPath, `${JSON.stringify(entry)}
19321
+ fs11.appendFileSync(logPath, `${JSON.stringify(entry)}
19198
19322
  `);
19199
19323
  } catch (error) {
19200
19324
  this.logger.warn("Failed to write to local cache", {
@@ -19206,13 +19330,13 @@ var SessionLogWriter = class _SessionLogWriter {
19206
19330
  }
19207
19331
  }
19208
19332
  static async cleanupOldSessions(localCachePath) {
19209
- const sessionsDir = path14.join(localCachePath, "sessions");
19333
+ const sessionsDir = path15.join(localCachePath, "sessions");
19210
19334
  let deleted = 0;
19211
19335
  try {
19212
19336
  const entries = await fsp.readdir(sessionsDir);
19213
19337
  const now = Date.now();
19214
19338
  for (const entry of entries) {
19215
- const entryPath = path14.join(sessionsDir, entry);
19339
+ const entryPath = path15.join(sessionsDir, entry);
19216
19340
  try {
19217
19341
  const stats = await fsp.stat(entryPath);
19218
19342
  if (stats.isDirectory() && now - stats.birthtimeMs > _SessionLogWriter.SESSIONS_MAX_AGE_MS) {