@posthog/agent 2.3.548 → 2.3.616

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.
@@ -3951,6 +3951,7 @@ var import_sdk5 = require("@agentclientprotocol/sdk");
3951
3951
  var import_node_server = require("@hono/node-server");
3952
3952
 
3953
3953
  // ../git/dist/queries.js
3954
+ var import_node_fs = require("fs");
3954
3955
  var fs3 = __toESM(require("fs/promises"), 1);
3955
3956
  var path2 = __toESM(require("path"), 1);
3956
3957
 
@@ -8502,13 +8503,20 @@ init_git_response_error();
8502
8503
  var simpleGit = gitInstanceFactory;
8503
8504
 
8504
8505
  // ../git/dist/client.js
8506
+ var PERFORMANCE_CONFIG = [
8507
+ "core.untrackedCache=true",
8508
+ "core.fsmonitor=true",
8509
+ "core.preloadIndex=true"
8510
+ ];
8505
8511
  function createGitClient(baseDir, options) {
8506
- const { abortSignal: signal, ...rest } = options ?? {};
8512
+ const { abortSignal: signal, config: callerConfig, ...rest } = options ?? {};
8513
+ const config = callerConfig ? [...PERFORMANCE_CONFIG, ...callerConfig] : PERFORMANCE_CONFIG;
8507
8514
  return simpleGit({
8508
8515
  baseDir,
8509
8516
  maxConcurrentProcesses: 6,
8510
8517
  trimmed: true,
8511
8518
  abort: signal,
8519
+ config,
8512
8520
  ...rest
8513
8521
  });
8514
8522
  }
@@ -8661,14 +8669,18 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
8661
8669
  }
8662
8670
  async executeRead(repoPath, operation, options) {
8663
8671
  const state = this.getRepoState(repoPath);
8672
+ const env = {
8673
+ ...getCleanEnv(),
8674
+ GIT_OPTIONAL_LOCKS: "0",
8675
+ ...options?.env
8676
+ };
8664
8677
  if (options?.signal) {
8665
8678
  const scopedGit = createGitClient(repoPath, {
8666
8679
  abortSignal: options.signal
8667
8680
  });
8668
- return operation(scopedGit.env({ ...getCleanEnv(), GIT_OPTIONAL_LOCKS: "0" }));
8681
+ return operation(scopedGit.env(env));
8669
8682
  }
8670
- const git = state.client.env({ ...getCleanEnv(), GIT_OPTIONAL_LOCKS: "0" });
8671
- return operation(git);
8683
+ return operation(state.client.env(env));
8672
8684
  }
8673
8685
  async executeWrite(repoPath, operation, options) {
8674
8686
  const state = this.getRepoState(repoPath);
@@ -8678,15 +8690,16 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
8678
8690
  throw new Error(`Git repository is locked: ${repoPath}`);
8679
8691
  }
8680
8692
  }
8693
+ const env = { ...getCleanEnv(), ...options?.env };
8681
8694
  await state.lock.acquireWrite();
8682
8695
  try {
8683
8696
  if (options?.signal) {
8684
8697
  const scopedGit = createGitClient(repoPath, {
8685
8698
  abortSignal: options.signal
8686
8699
  });
8687
- return await operation(scopedGit.env(getCleanEnv()));
8700
+ return await operation(scopedGit.env(env));
8688
8701
  }
8689
- return await operation(state.client.env(getCleanEnv()));
8702
+ return await operation(state.client.env(env));
8690
8703
  } catch (error) {
8691
8704
  if (options?.signal?.aborted) {
8692
8705
  await removeLock(repoPath).catch(() => {
@@ -8713,6 +8726,9 @@ function getGitOperationManager() {
8713
8726
  return instance2;
8714
8727
  }
8715
8728
 
8729
+ // ../git/dist/status-stream.js
8730
+ var import_node_child_process2 = require("child_process");
8731
+
8716
8732
  // ../git/dist/queries.js
8717
8733
  async function getCurrentBranch(baseDir, options) {
8718
8734
  const manager = getGitOperationManager();
@@ -8747,6 +8763,44 @@ async function listWorktrees(baseDir, options) {
8747
8763
  return worktrees;
8748
8764
  }, { signal: options?.abortSignal });
8749
8765
  }
8766
+ async function inspectGitBusyState(git) {
8767
+ const toplevel = (await git.raw(["rev-parse", "--show-toplevel"])).trim();
8768
+ const resolveGitPath = async (gitPath) => {
8769
+ const relative = (await git.raw(["rev-parse", "--git-path", gitPath])).trim();
8770
+ return path2.isAbsolute(relative) ? relative : path2.resolve(toplevel, relative);
8771
+ };
8772
+ const pathExists = async (gitPath) => {
8773
+ const resolved = await resolveGitPath(gitPath);
8774
+ try {
8775
+ await fs3.access(resolved);
8776
+ return true;
8777
+ } catch {
8778
+ return false;
8779
+ }
8780
+ };
8781
+ const dirExists = async (gitPath) => {
8782
+ const resolved = await resolveGitPath(gitPath);
8783
+ try {
8784
+ const stat4 = await fs3.stat(resolved);
8785
+ return stat4.isDirectory();
8786
+ } catch {
8787
+ return false;
8788
+ }
8789
+ };
8790
+ if (await dirExists("rebase-merge") || await dirExists("rebase-apply")) {
8791
+ return { busy: true, operation: "rebase" };
8792
+ }
8793
+ if (await pathExists("MERGE_HEAD")) {
8794
+ return { busy: true, operation: "merge" };
8795
+ }
8796
+ if (await pathExists("CHERRY_PICK_HEAD")) {
8797
+ return { busy: true, operation: "cherry-pick" };
8798
+ }
8799
+ if (await pathExists("REVERT_HEAD")) {
8800
+ return { busy: true, operation: "revert" };
8801
+ }
8802
+ return { busy: false };
8803
+ }
8750
8804
 
8751
8805
  // src/server/agent-server.ts
8752
8806
  var import_hono = require("hono");
@@ -8755,7 +8809,7 @@ var import_zod3 = require("zod");
8755
8809
  // package.json
8756
8810
  var package_default = {
8757
8811
  name: "@posthog/agent",
8758
- version: "2.3.548",
8812
+ version: "2.3.616",
8759
8813
  repository: "https://github.com/PostHog/code",
8760
8814
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8761
8815
  exports: {
@@ -11222,6 +11276,7 @@ var ParserManager = class {
11222
11276
  languages = /* @__PURE__ */ new Map();
11223
11277
  languageKeys = /* @__PURE__ */ new WeakMap();
11224
11278
  queryCache = /* @__PURE__ */ new Map();
11279
+ failedQueries = /* @__PURE__ */ new Set();
11225
11280
  maxCacheSize = 256;
11226
11281
  initPromise = null;
11227
11282
  wasmDir = resolveGrammarsDir();
@@ -11229,6 +11284,7 @@ var ParserManager = class {
11229
11284
  updateConfig(config) {
11230
11285
  this.config = config;
11231
11286
  this.queryCache.clear();
11287
+ this.failedQueries.clear();
11232
11288
  }
11233
11289
  async ensureInitialized() {
11234
11290
  if (!this.initPromise) {
@@ -11290,6 +11346,9 @@ var ParserManager = class {
11290
11346
  }
11291
11347
  const langKey = this.languageKeys.get(lang) ?? lang.toString();
11292
11348
  const cacheKey = `${langKey}:${queryStr}`;
11349
+ if (this.failedQueries.has(cacheKey)) {
11350
+ return null;
11351
+ }
11293
11352
  let query2 = this.queryCache.get(cacheKey);
11294
11353
  if (query2) {
11295
11354
  this.queryCache.delete(cacheKey);
@@ -11306,8 +11365,8 @@ var ParserManager = class {
11306
11365
  }
11307
11366
  this.queryCache.set(cacheKey, query2);
11308
11367
  return query2;
11309
- } catch (err2) {
11310
- warn("Query compilation failed", err2);
11368
+ } catch {
11369
+ this.failedQueries.add(cacheKey);
11311
11370
  return null;
11312
11371
  }
11313
11372
  }
@@ -11318,6 +11377,7 @@ var ParserManager = class {
11318
11377
  this.languages.clear();
11319
11378
  this.languageKeys = /* @__PURE__ */ new WeakMap();
11320
11379
  this.queryCache.clear();
11380
+ this.failedQueries.clear();
11321
11381
  }
11322
11382
  };
11323
11383
  async function findVariantBranches(pm, source, languageId) {
@@ -12843,6 +12903,33 @@ var PostHogApi = class {
12843
12903
  );
12844
12904
  return data.results.filter((f) => !f.deleted);
12845
12905
  }
12906
+ // Keys absent from the returned map have NOT been called in the window.
12907
+ async getFlagLastCalled(flagKeys, daysBack = 30) {
12908
+ if (flagKeys.length === 0) return /* @__PURE__ */ new Map();
12909
+ const days = Math.max(1, Math.min(365, Math.floor(daysBack)));
12910
+ const query2 = `
12911
+ SELECT
12912
+ properties.$feature_flag AS flag_key,
12913
+ max(timestamp) AS last_called_at
12914
+ FROM events
12915
+ WHERE event = '$feature_flag_called'
12916
+ AND properties.$feature_flag IN {flagKeys}
12917
+ AND timestamp >= now() - INTERVAL ${days} DAY
12918
+ GROUP BY flag_key
12919
+ `;
12920
+ const data = await this.post("/query/", {
12921
+ query: {
12922
+ kind: "HogQLQuery",
12923
+ query: query2,
12924
+ values: { flagKeys }
12925
+ }
12926
+ });
12927
+ const lastCalled = /* @__PURE__ */ new Map();
12928
+ for (const [flagKey, lastCalledAt] of data.results) {
12929
+ if (lastCalledAt) lastCalled.set(flagKey, lastCalledAt);
12930
+ }
12931
+ return lastCalled;
12932
+ }
12846
12933
  async getExperiments() {
12847
12934
  const data = await this.get(
12848
12935
  "/experiments/?limit=500"
@@ -13664,6 +13751,23 @@ function tryParsePartialJson(s) {
13664
13751
  return null;
13665
13752
  }
13666
13753
 
13754
+ // src/adapters/error-classification.ts
13755
+ var UPSTREAM_PROVIDER_ERROR_STATUS_PATTERN = /API Error:\s*(?:429|5\d\d)\b/i;
13756
+ function classifyAgentError(result) {
13757
+ if (!result) return "agent_error";
13758
+ const text2 = result.trim();
13759
+ if (/API Error:\s*terminated\b/i.test(text2)) {
13760
+ return "upstream_stream_terminated";
13761
+ }
13762
+ if (/API Error:\s*Connection error\b/i.test(text2)) {
13763
+ return "upstream_connection_error";
13764
+ }
13765
+ if (UPSTREAM_PROVIDER_ERROR_STATUS_PATTERN.test(text2)) {
13766
+ return "upstream_provider_failure";
13767
+ }
13768
+ return "agent_error";
13769
+ }
13770
+
13667
13771
  // src/adapters/claude/permissions/posthog-exec-gate.ts
13668
13772
  var POSTHOG_EXEC_TOOL_RE = /^mcp__posthog(?:_[^_]+)*__exec$/;
13669
13773
  var POSTHOG_CALL_COMMAND_RE = /^\s*call\s+(?:--json\s+)?([a-zA-Z0-9_-]+)/;
@@ -13860,7 +13964,7 @@ var createPreToolUseHook = (settingsManager, logger) => async (input, _toolUseID
13860
13964
  };
13861
13965
 
13862
13966
  // src/adapters/claude/conversion/tool-use-to-acp.ts
13863
- var import_node_fs = __toESM(require("fs"), 1);
13967
+ var import_node_fs2 = __toESM(require("fs"), 1);
13864
13968
  var import_node_path3 = __toESM(require("path"), 1);
13865
13969
 
13866
13970
  // src/adapters/claude/mcp/tool-metadata.ts
@@ -14094,7 +14198,7 @@ function toolInfoFromToolUse(toolUse, options) {
14094
14198
  oldContent = options.cachedFileContent[writeFilePath];
14095
14199
  } else {
14096
14200
  try {
14097
- oldContent = import_node_fs.default.readFileSync(writeFilePath, "utf-8");
14201
+ oldContent = import_node_fs2.default.readFileSync(writeFilePath, "utf-8");
14098
14202
  } catch {
14099
14203
  }
14100
14204
  }
@@ -14508,7 +14612,7 @@ function resolveFileContent(filePath, oldText, cachedFileContent) {
14508
14612
  }
14509
14613
  }
14510
14614
  try {
14511
- const content = import_node_fs.default.readFileSync(filePath, "utf-8");
14615
+ const content = import_node_fs2.default.readFileSync(filePath, "utf-8");
14512
14616
  if (content.includes(oldText)) {
14513
14617
  return content;
14514
14618
  }
@@ -14980,17 +15084,6 @@ async function handleSystemMessage(message, context) {
14980
15084
  break;
14981
15085
  }
14982
15086
  }
14983
- function classifyAgentError(result) {
14984
- if (!result) return "agent_error";
14985
- const text2 = result.trim();
14986
- if (/API Error:\s*terminated\b/i.test(text2)) {
14987
- return "upstream_stream_terminated";
14988
- }
14989
- if (/API Error:\s*Connection error\b/i.test(text2)) {
14990
- return "upstream_connection_error";
14991
- }
14992
- return "agent_error";
14993
- }
14994
15087
  function handleResultMessage(message) {
14995
15088
  const usage = extractUsageFromResult(message);
14996
15089
  switch (message.subtype) {
@@ -16052,7 +16145,7 @@ function parseMcpServers(params) {
16052
16145
  }
16053
16146
 
16054
16147
  // src/adapters/claude/session/options.ts
16055
- var import_node_child_process2 = require("child_process");
16148
+ var import_node_child_process3 = require("child_process");
16056
16149
  var fs7 = __toESM(require("fs"), 1);
16057
16150
  var os3 = __toESM(require("os"), 1);
16058
16151
  var path9 = __toESM(require("path"), 1);
@@ -16114,6 +16207,10 @@ function buildMcpServers(userServers, acpServers, projectScopedServers) {
16114
16207
  };
16115
16208
  }
16116
16209
  function buildEnvironment() {
16210
+ const bedrockFallbackHeader = "x-posthog-use-bedrock-fallback: true";
16211
+ const existingCustomHeaders = process.env.ANTHROPIC_CUSTOM_HEADERS;
16212
+ const customHeaders = existingCustomHeaders ? `${existingCustomHeaders}
16213
+ ${bedrockFallbackHeader}` : bedrockFallbackHeader;
16117
16214
  return {
16118
16215
  ...process.env,
16119
16216
  ELECTRON_RUN_AS_NODE: "1",
@@ -16121,7 +16218,9 @@ function buildEnvironment() {
16121
16218
  // Offload all MCP tools by default
16122
16219
  ENABLE_TOOL_SEARCH: "auto:0",
16123
16220
  // Enable idle state as end-of-turn signal (required for SDK 0.2.114+)
16124
- CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1"
16221
+ CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1",
16222
+ // Route to AWS Bedrock as a fallback when Anthropic returns 5xx
16223
+ ANTHROPIC_CUSTOM_HEADERS: customHeaders
16125
16224
  };
16126
16225
  }
16127
16226
  function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache, registeredAgents) {
@@ -16194,7 +16293,7 @@ function getAbortController(userProvidedController) {
16194
16293
  }
16195
16294
  function buildSpawnWrapper(sessionId, onProcessSpawned, onProcessExited, logger) {
16196
16295
  return (spawnOpts) => {
16197
- const child = (0, import_node_child_process2.spawn)(spawnOpts.command, spawnOpts.args, {
16296
+ const child = (0, import_node_child_process3.spawn)(spawnOpts.command, spawnOpts.args, {
16198
16297
  cwd: spawnOpts.cwd,
16199
16298
  env: spawnOpts.env,
16200
16299
  stdio: ["pipe", "pipe", "pipe"]
@@ -17867,7 +17966,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
17867
17966
  };
17868
17967
 
17869
17968
  // src/adapters/codex/codex-agent.ts
17870
- var import_node_fs3 = require("fs");
17969
+ var import_node_fs4 = require("fs");
17871
17970
  var import_node_path5 = require("path");
17872
17971
  var import_sdk3 = require("@agentclientprotocol/sdk");
17873
17972
 
@@ -18152,8 +18251,8 @@ function parseCodexToml(content, cwd) {
18152
18251
  }
18153
18252
 
18154
18253
  // src/adapters/codex/spawn.ts
18155
- var import_node_child_process3 = require("child_process");
18156
- var import_node_fs2 = require("fs");
18254
+ var import_node_child_process4 = require("child_process");
18255
+ var import_node_fs3 = require("fs");
18157
18256
  var import_node_path4 = require("path");
18158
18257
  function buildConfigArgs(options) {
18159
18258
  const args2 = [];
@@ -18185,7 +18284,7 @@ function buildConfigArgs(options) {
18185
18284
  }
18186
18285
  function findCodexBinary(options) {
18187
18286
  const configArgs = buildConfigArgs(options);
18188
- if (options.binaryPath && (0, import_node_fs2.existsSync)(options.binaryPath)) {
18287
+ if (options.binaryPath && (0, import_node_fs3.existsSync)(options.binaryPath)) {
18189
18288
  return { command: options.binaryPath, args: configArgs };
18190
18289
  }
18191
18290
  if (options.binaryPath) {
@@ -18204,7 +18303,7 @@ function spawnCodexProcess(options) {
18204
18303
  env.POSTHOG_GATEWAY_API_KEY = options.apiKey;
18205
18304
  }
18206
18305
  const { command, args: args2 } = findCodexBinary(options);
18207
- if (options.binaryPath && (0, import_node_fs2.existsSync)(options.binaryPath)) {
18306
+ if (options.binaryPath && (0, import_node_fs3.existsSync)(options.binaryPath)) {
18208
18307
  const binDir = (0, import_node_path4.dirname)(options.binaryPath);
18209
18308
  env.PATH = `${binDir}${import_node_path4.delimiter}${env.PATH ?? ""}`;
18210
18309
  }
@@ -18216,7 +18315,7 @@ function spawnCodexProcess(options) {
18216
18315
  hasApiKey: !!options.apiKey,
18217
18316
  binaryPath: options.binaryPath
18218
18317
  });
18219
- const child = (0, import_node_child_process3.spawn)(command, args2, {
18318
+ const child = (0, import_node_child_process4.spawn)(command, args2, {
18220
18319
  cwd: options.cwd,
18221
18320
  env,
18222
18321
  stdio: ["pipe", "pipe", "pipe"],
@@ -18275,6 +18374,17 @@ function prependPrContext(params) {
18275
18374
  prompt: [{ type: "text", text: prContext }, ...params.prompt]
18276
18375
  };
18277
18376
  }
18377
+ function classifyPromptError(error) {
18378
+ const message = error instanceof Error ? error.message : String(error ?? "");
18379
+ const classification = classifyAgentError(message);
18380
+ if (classification === "agent_error") {
18381
+ return error;
18382
+ }
18383
+ return import_sdk3.RequestError.internalError(
18384
+ { classification, result: message },
18385
+ message
18386
+ );
18387
+ }
18278
18388
  var CODEX_NATIVE_MODE = {
18279
18389
  auto: "auto",
18280
18390
  default: "auto",
@@ -18305,7 +18415,7 @@ function resolveStructuredOutputMcpScript() {
18305
18415
  let dir = import_meta2.dirname ?? __dirname;
18306
18416
  for (let i2 = 0; i2 < 5; i2++) {
18307
18417
  const candidate = (0, import_node_path5.resolve)(dir, rel);
18308
- if ((0, import_node_fs3.existsSync)(candidate)) return candidate;
18418
+ if ((0, import_node_fs4.existsSync)(candidate)) return candidate;
18309
18419
  dir = (0, import_node_path5.resolve)(dir, "..");
18310
18420
  }
18311
18421
  throw new Error(
@@ -18604,6 +18714,8 @@ var CodexAcpAgent = class extends BaseAcpAgent {
18604
18714
  let response;
18605
18715
  try {
18606
18716
  response = await this.codexConnection.prompt(prependPrContext(params));
18717
+ } catch (error) {
18718
+ throw classifyPromptError(error);
18607
18719
  } finally {
18608
18720
  this.session.promptRunning = false;
18609
18721
  }
@@ -18939,7 +19051,7 @@ var import_node_os2 = require("os");
18939
19051
  var import_node_path7 = require("path");
18940
19052
 
18941
19053
  // ../git/dist/handoff.js
18942
- var import_node_child_process4 = require("child_process");
19054
+ var import_node_child_process5 = require("child_process");
18943
19055
  var import_promises2 = require("fs/promises");
18944
19056
  var import_node_os = require("os");
18945
19057
  var import_node_path6 = __toESM(require("path"), 1);
@@ -19105,7 +19217,7 @@ var GitSaga = class extends Saga {
19105
19217
  return manager.executeWrite(input.baseDir, async (git) => {
19106
19218
  this._git = git;
19107
19219
  return this.executeGitOperations(input);
19108
- }, { signal: input.signal });
19220
+ }, { signal: input.signal, env: input.env });
19109
19221
  }
19110
19222
  };
19111
19223
 
@@ -19217,42 +19329,7 @@ async function hasUnmergedEntries(git) {
19217
19329
  return output.trim().length > 0;
19218
19330
  }
19219
19331
  async function getGitBusyState(git) {
19220
- const toplevel = (await git.raw(["rev-parse", "--show-toplevel"])).trim();
19221
- const resolveGitPath = async (gitPath) => {
19222
- const relative = (await git.raw(["rev-parse", "--git-path", gitPath])).trim();
19223
- return path13.isAbsolute(relative) ? relative : path13.resolve(toplevel, relative);
19224
- };
19225
- const pathExists = async (gitPath) => {
19226
- const resolved = await resolveGitPath(gitPath);
19227
- try {
19228
- await fs11.access(resolved);
19229
- return true;
19230
- } catch {
19231
- return false;
19232
- }
19233
- };
19234
- const dirExists = async (gitPath) => {
19235
- const resolved = await resolveGitPath(gitPath);
19236
- try {
19237
- const stat4 = await fs11.stat(resolved);
19238
- return stat4.isDirectory();
19239
- } catch {
19240
- return false;
19241
- }
19242
- };
19243
- if (await dirExists("rebase-merge") || await dirExists("rebase-apply")) {
19244
- return { busy: true, operation: "rebase" };
19245
- }
19246
- if (await pathExists("MERGE_HEAD")) {
19247
- return { busy: true, operation: "merge" };
19248
- }
19249
- if (await pathExists("CHERRY_PICK_HEAD")) {
19250
- return { busy: true, operation: "cherry-pick" };
19251
- }
19252
- if (await pathExists("REVERT_HEAD")) {
19253
- return { busy: true, operation: "revert" };
19254
- }
19255
- return { busy: false };
19332
+ return inspectGitBusyState(git);
19256
19333
  }
19257
19334
  var MAX_WORKTREE_FILE_BYTES = 1024 * 1024;
19258
19335
  async function createWorktreeTree(git, baseDir, head) {
@@ -19754,7 +19831,7 @@ var GitHandoffTracker = class {
19754
19831
  }
19755
19832
  async runGitProcessAllowingFailure(args2) {
19756
19833
  return new Promise((resolve7, reject) => {
19757
- const child = (0, import_node_child_process4.spawn)("git", args2, {
19834
+ const child = (0, import_node_child_process5.spawn)("git", args2, {
19758
19835
  cwd: this.repositoryPath,
19759
19836
  stdio: ["ignore", "ignore", "pipe"]
19760
19837
  });
@@ -19778,7 +19855,7 @@ var GitHandoffTracker = class {
19778
19855
  }
19779
19856
  async runGitWithEnv(env, args2) {
19780
19857
  return new Promise((resolve7, reject) => {
19781
- const child = (0, import_node_child_process4.spawn)("git", args2, {
19858
+ const child = (0, import_node_child_process5.spawn)("git", args2, {
19782
19859
  cwd: this.repositoryPath,
19783
19860
  stdio: ["ignore", "pipe", "pipe"],
19784
19861
  env
@@ -19803,7 +19880,7 @@ var GitHandoffTracker = class {
19803
19880
  }
19804
19881
  runGitProcess(args2, input) {
19805
19882
  return new Promise((resolve7, reject) => {
19806
- const child = (0, import_node_child_process4.spawn)("git", args2, {
19883
+ const child = (0, import_node_child_process5.spawn)("git", args2, {
19807
19884
  cwd: this.repositoryPath,
19808
19885
  stdio: "pipe"
19809
19886
  });
@@ -20655,7 +20732,7 @@ ${toolSummary}`);
20655
20732
  }
20656
20733
 
20657
20734
  // src/session-log-writer.ts
20658
- var import_node_fs4 = __toESM(require("fs"), 1);
20735
+ var import_node_fs5 = __toESM(require("fs"), 1);
20659
20736
  var import_promises4 = __toESM(require("fs/promises"), 1);
20660
20737
  var import_node_path8 = __toESM(require("path"), 1);
20661
20738
  var SessionLogWriter = class _SessionLogWriter {
@@ -20699,7 +20776,7 @@ var SessionLogWriter = class _SessionLogWriter {
20699
20776
  context.runId
20700
20777
  );
20701
20778
  try {
20702
- import_node_fs4.default.mkdirSync(sessionDir, { recursive: true });
20779
+ import_node_fs5.default.mkdirSync(sessionDir, { recursive: true });
20703
20780
  } catch (error) {
20704
20781
  this.logger.warn("Failed to create local cache directory", {
20705
20782
  sessionDir,
@@ -20958,7 +21035,7 @@ var SessionLogWriter = class _SessionLogWriter {
20958
21035
  "logs.ndjson"
20959
21036
  );
20960
21037
  try {
20961
- import_node_fs4.default.appendFileSync(logPath, `${JSON.stringify(entry)}
21038
+ import_node_fs5.default.appendFileSync(logPath, `${JSON.stringify(entry)}
20962
21039
  `);
20963
21040
  } catch (error) {
20964
21041
  this.logger.warn("Failed to write to local cache", {
@@ -20993,11 +21070,11 @@ var SessionLogWriter = class _SessionLogWriter {
20993
21070
  };
20994
21071
 
20995
21072
  // src/server/agentsh-runtime.ts
20996
- var import_node_child_process5 = require("child_process");
21073
+ var import_node_child_process6 = require("child_process");
20997
21074
  var import_promises5 = require("fs/promises");
20998
21075
  var import_node_util2 = require("util");
20999
21076
  var AGENTSH_SESSION_ID_FILE = "/tmp/agentsh-session-id";
21000
- var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process5.execFile);
21077
+ var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process6.execFile);
21001
21078
  function errorMessage(error) {
21002
21079
  return error instanceof Error ? error.message : String(error);
21003
21080
  }
@@ -21217,8 +21294,15 @@ function validateCommandParams(method, params) {
21217
21294
  var agentErrorClassificationSchema = import_zod3.z.enum([
21218
21295
  "upstream_stream_terminated",
21219
21296
  "upstream_connection_error",
21297
+ "upstream_provider_failure",
21220
21298
  "agent_error"
21221
21299
  ]);
21300
+ var UPSTREAM_PROVIDER_FAILURE_MESSAGE = "The upstream AI provider failed to process the request. Please retry the task in a few minutes.";
21301
+ var upstreamProviderFailureClassifications = /* @__PURE__ */ new Set([
21302
+ "upstream_stream_terminated",
21303
+ "upstream_connection_error",
21304
+ "upstream_provider_failure"
21305
+ ]);
21222
21306
  var errorWithClassificationSchema = import_zod3.z.object({
21223
21307
  data: import_zod3.z.object({ classification: agentErrorClassificationSchema })
21224
21308
  });
@@ -21962,7 +22046,9 @@ var AgentServer = class {
21962
22046
  }
21963
22047
  classifyAndSignalFailure(payload, phase, error) {
21964
22048
  const { classification, message } = this.extractErrorClassification(error);
21965
- const errorMessage2 = classification === "upstream_stream_terminated" ? "Upstream LLM stream terminated" : classification === "upstream_connection_error" ? "Upstream LLM connection error" : message || "Agent error";
22049
+ const errorMessage2 = upstreamProviderFailureClassifications.has(
22050
+ classification
22051
+ ) ? UPSTREAM_PROVIDER_FAILURE_MESSAGE : message || "Agent error";
21966
22052
  this.logger.error(`send_${phase}_task_message_failed`, {
21967
22053
  classification,
21968
22054
  message