@cjhyy/code-shell 0.1.5 → 0.1.6

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/arena/index.cjs +4 -4
  3. package/dist/arena/index.js +3 -3
  4. package/dist/{arena-O2L4TN6A.js → arena-2LTLIXOL.js} +3 -3
  5. package/dist/{arena-KBQOPLFV.cjs → arena-ADB7DRFI.cjs} +17 -17
  6. package/dist/{chunk-XDIQWQJ4.js → chunk-3QO25N6E.js} +2 -2
  7. package/dist/{chunk-5ECBT4YA.js → chunk-3SBSUOWZ.js} +0 -3
  8. package/dist/{chunk-YUI524OE.cjs → chunk-7BI3V74Y.cjs} +0 -3
  9. package/dist/{chunk-2EP3CLEN.js → chunk-7QIM3BKD.js} +1 -1
  10. package/dist/{chunk-YJ77GQK5.js → chunk-ABRRONJ7.js} +1 -1
  11. package/dist/{chunk-C5YQBIRK.js → chunk-BZ5TNE7L.js} +1 -1
  12. package/dist/{chunk-VYL4EFRC.cjs → chunk-DDB6QOKJ.cjs} +7 -7
  13. package/dist/{chunk-SNT563K3.cjs → chunk-ILHE7XLT.cjs} +6 -6
  14. package/dist/{chunk-76W334S4.js → chunk-KAQHULYN.js} +1 -1
  15. package/dist/{chunk-W22P377T.js → chunk-KE4EQOWA.js} +6 -11
  16. package/dist/{chunk-R47ROHGL.cjs → chunk-MV7YI4WO.cjs} +6 -11
  17. package/dist/{chunk-7K6SDRRF.js → chunk-PKGRTCCY.js} +54 -9
  18. package/dist/{chunk-RMYKO74M.js → chunk-QARL3IDQ.js} +1 -1
  19. package/dist/{chunk-A5LCRPDP.cjs → chunk-S754JHLR.cjs} +2 -2
  20. package/dist/{chunk-HS2MFNUC.cjs → chunk-TNLGBJYS.cjs} +3 -3
  21. package/dist/{chunk-BUU5PZK2.cjs → chunk-UXOCVJJ6.cjs} +200 -156
  22. package/dist/{chunk-BWTOS5BH.cjs → chunk-WZJV6DJC.cjs} +4 -4
  23. package/dist/{chunk-QRM7IF2S.cjs → chunk-YKIAELDZ.cjs} +2 -2
  24. package/dist/cli/main.cjs +211 -188
  25. package/dist/cli/main.js +44 -21
  26. package/dist/cli/updater.d.ts +8 -0
  27. package/dist/engine/engine.d.ts +7 -0
  28. package/dist/index.cjs +8 -8
  29. package/dist/index.js +9 -9
  30. package/dist/{manager-C2IUXKRC.js → manager-D65VFAPX.js} +1 -1
  31. package/dist/manager-TTF5VHJC.cjs +7 -0
  32. package/dist/{openrouter-models-TGKDKY52.js → openrouter-models-H56GHBHN.js} +1 -1
  33. package/dist/openrouter-models-TWUFWZ5T.cjs +15 -0
  34. package/dist/openrouter-sync-5VMGN6C2.cjs +11 -0
  35. package/dist/{openrouter-sync-UXUSJCIR.js → openrouter-sync-ALEMF5IU.js} +2 -2
  36. package/dist/product/index.cjs +7 -7
  37. package/dist/product/index.js +6 -6
  38. package/dist/run/index.cjs +7 -7
  39. package/dist/run/index.js +6 -6
  40. package/dist/tool-system/investigation-guard.d.ts +9 -0
  41. package/dist/updater-I7QBW4DP.cjs +17 -0
  42. package/dist/{updater-VFUAHCVY.js → updater-NVME5S3Z.js} +1 -1
  43. package/package.json +2 -1
  44. package/skills-builtin/codeshell-help.md +135 -0
  45. package/dist/manager-YYKWYTRM.cjs +0 -7
  46. package/dist/openrouter-models-OU4GRZQY.cjs +0 -15
  47. package/dist/openrouter-sync-BBHUM3R6.cjs +0 -11
  48. package/dist/updater-QW473OF4.cjs +0 -17
@@ -27,7 +27,7 @@ var _chunkJMR33QVFcjs = require('./chunk-JMR33QVF.cjs');
27
27
  var _chunkNUNC3VFBcjs = require('./chunk-NUNC3VFB.cjs');
28
28
 
29
29
 
30
- var _chunkYUI524OEcjs = require('./chunk-YUI524OE.cjs');
30
+ var _chunk7BI3V74Ycjs = require('./chunk-7BI3V74Y.cjs');
31
31
 
32
32
 
33
33
  var _chunkTUY2T5KPcjs = require('./chunk-TUY2T5KP.cjs');
@@ -36,7 +36,7 @@ var _chunkTUY2T5KPcjs = require('./chunk-TUY2T5KP.cjs');
36
36
 
37
37
 
38
38
 
39
- var _chunkVYL4EFRCcjs = require('./chunk-VYL4EFRC.cjs');
39
+ var _chunkDDB6QOKJcjs = require('./chunk-DDB6QOKJ.cjs');
40
40
 
41
41
 
42
42
 
@@ -46,7 +46,7 @@ var _chunkVYL4EFRCcjs = require('./chunk-VYL4EFRC.cjs');
46
46
 
47
47
 
48
48
 
49
- var _chunkBWTOS5BHcjs = require('./chunk-BWTOS5BH.cjs');
49
+ var _chunkWZJV6DJCcjs = require('./chunk-WZJV6DJC.cjs');
50
50
 
51
51
 
52
52
 
@@ -3039,7 +3039,7 @@ var arenaToolDef = {
3039
3039
  participants: {
3040
3040
  type: "array",
3041
3041
  items: { type: "string" },
3042
- description: "Model preset names or full model paths for participants (min 2). Preset names: " + Object.keys(_chunkBWTOS5BHcjs.MODEL_PRESETS).join(", ") + ". Default: ['claude', 'gpt'] if omitted."
3042
+ description: "Model preset names or full model paths for participants (min 2). Preset names: " + Object.keys(_chunkWZJV6DJCcjs.MODEL_PRESETS).join(", ") + ". Default: ['claude', 'gpt'] if omitted."
3043
3043
  },
3044
3044
  concluder: {
3045
3045
  type: "string",
@@ -3077,7 +3077,7 @@ function resolveParticipant(nameOrPath, llmConfig, pool) {
3077
3077
  const fallbackApiKey = llmConfig.apiKey;
3078
3078
  const poolEntry = _optionalChain([pool, 'optionalAccess', _54 => _54.get, 'call', _55 => _55(nameOrPath)]);
3079
3079
  if (poolEntry) return participantFromPool(poolEntry, llmConfig);
3080
- const preset = _chunkBWTOS5BHcjs.MODEL_PRESETS[nameOrPath];
3080
+ const preset = _chunkWZJV6DJCcjs.MODEL_PRESETS[nameOrPath];
3081
3081
  if (preset) {
3082
3082
  assertEndpointAcceptsModel(fallbackBaseUrl, preset.model, nameOrPath);
3083
3083
  return {
@@ -3099,7 +3099,7 @@ function resolveParticipant(nameOrPath, llmConfig, pool) {
3099
3099
  llm: {
3100
3100
  provider: "openai",
3101
3101
  model: nameOrPath,
3102
- maxTokens: _chunkBWTOS5BHcjs.getMaxOutputTokens.call(void 0, nameOrPath),
3102
+ maxTokens: _chunkWZJV6DJCcjs.getMaxOutputTokens.call(void 0, nameOrPath),
3103
3103
  baseUrl: fallbackBaseUrl,
3104
3104
  apiKey: fallbackApiKey,
3105
3105
  temperature: ARENA_TEMPERATURE,
@@ -3113,7 +3113,7 @@ function participantFromPool(entry, llmConfig) {
3113
3113
  llm: {
3114
3114
  provider: entry.provider,
3115
3115
  model: entry.model,
3116
- maxTokens: _nullishCoalesce(entry.maxOutputTokens, () => ( _chunkBWTOS5BHcjs.getMaxOutputTokens.call(void 0, entry.model))),
3116
+ maxTokens: _nullishCoalesce(entry.maxOutputTokens, () => ( _chunkWZJV6DJCcjs.getMaxOutputTokens.call(void 0, entry.model))),
3117
3117
  baseUrl: _nullishCoalesce(entry.baseUrl, () => ( llmConfig.baseUrl)),
3118
3118
  apiKey: _nullishCoalesce(entry.apiKey, () => ( llmConfig.apiKey)),
3119
3119
  temperature: ARENA_TEMPERATURE,
@@ -3126,7 +3126,7 @@ function probeParticipant(nameOrPath, poolEntries, llmConfig) {
3126
3126
  if (fromPool) {
3127
3127
  return { modelPath: fromPool.model, source: "pool", compatible: true };
3128
3128
  }
3129
- const preset = _chunkBWTOS5BHcjs.MODEL_PRESETS[nameOrPath];
3129
+ const preset = _chunkWZJV6DJCcjs.MODEL_PRESETS[nameOrPath];
3130
3130
  const modelPath = _nullishCoalesce(_optionalChain([preset, 'optionalAccess', _56 => _56.model]), () => ( nameOrPath));
3131
3131
  const source = preset ? "preset" : "raw";
3132
3132
  const baseUrl = _optionalChain([llmConfig, 'optionalAccess', _57 => _57.baseUrl]);
@@ -3221,7 +3221,7 @@ async function arenaTool(args, ctx) {
3221
3221
  const mode = args.mode;
3222
3222
  const concluder = args.concluder;
3223
3223
  const progressLog = [];
3224
- const progressRenderer = _chunkBWTOS5BHcjs.createProgressRenderer.call(void 0, (text) => {
3224
+ const progressRenderer = _chunkWZJV6DJCcjs.createProgressRenderer.call(void 0, (text) => {
3225
3225
  progressLog.push(stripAnsi(text));
3226
3226
  });
3227
3227
  const configLine = formatStartupBanner(
@@ -3234,7 +3234,7 @@ async function arenaTool(args, ctx) {
3234
3234
  progressLog.push(configLine);
3235
3235
  try {
3236
3236
  const participants = participantNames.map((n) => resolveParticipant(n, llmConfig, pool));
3237
- const arena = new (0, _chunkBWTOS5BHcjs.Arena)({
3237
+ const arena = new (0, _chunkWZJV6DJCcjs.Arena)({
3238
3238
  participants,
3239
3239
  mode,
3240
3240
  concluder,
@@ -3243,7 +3243,7 @@ async function arenaTool(args, ctx) {
3243
3243
  signal
3244
3244
  });
3245
3245
  const result = await arena.run(topic);
3246
- const formattedResult = _chunkBWTOS5BHcjs.formatArenaResultForSession.call(void 0, result);
3246
+ const formattedResult = _chunkWZJV6DJCcjs.formatArenaResultForSession.call(void 0, result);
3247
3247
  const progressSummary = progressLog.length > 0 ? "\u2500\u2500 Arena Progress \u2500\u2500\n" + progressLog.join("\n") + "\n\n" : "";
3248
3248
  const MAX_TOOL_OUTPUT = 3e4;
3249
3249
  const full = progressSummary + formattedResult;
@@ -3333,23 +3333,23 @@ var BUILTIN_TOOLS = [
3333
3333
  },
3334
3334
  {
3335
3335
  definition: {
3336
- ..._chunkVYL4EFRCcjs.webSearchToolDef,
3336
+ ..._chunkDDB6QOKJcjs.webSearchToolDef,
3337
3337
  source: "builtin",
3338
3338
  permissionDefault: "allow",
3339
3339
  isReadOnly: true,
3340
3340
  isConcurrencySafe: true
3341
3341
  },
3342
- execute: _chunkVYL4EFRCcjs.webSearchTool
3342
+ execute: _chunkDDB6QOKJcjs.webSearchTool
3343
3343
  },
3344
3344
  {
3345
3345
  definition: {
3346
- ..._chunkVYL4EFRCcjs.webFetchToolDef,
3346
+ ..._chunkDDB6QOKJcjs.webFetchToolDef,
3347
3347
  source: "builtin",
3348
3348
  permissionDefault: "allow",
3349
3349
  isReadOnly: true,
3350
3350
  isConcurrencySafe: true
3351
3351
  },
3352
- execute: _chunkVYL4EFRCcjs.webFetchTool
3352
+ execute: _chunkDDB6QOKJcjs.webFetchTool
3353
3353
  },
3354
3354
  {
3355
3355
  definition: {
@@ -4957,7 +4957,7 @@ function persistToFile(dir, toolUseId, content) {
4957
4957
  } catch (err) {
4958
4958
  const code = err.code;
4959
4959
  if (code !== "EEXIST") {
4960
- _chunkIK4EWJBPcjs.logger.warn("tool_result.persist_failed", {
4960
+ _chunkIK4EWJBPcjs.logger.debug("tool_result.persist_failed", {
4961
4961
  toolUseId,
4962
4962
  code,
4963
4963
  error: err.message
@@ -5583,16 +5583,21 @@ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
5583
5583
 
5584
5584
 
5585
5585
 
5586
+
5586
5587
  function scanSkills(cwd) {
5587
5588
  const skills = [];
5588
5589
  const seen = /* @__PURE__ */ new Set();
5590
+ const builtin = resolveBuiltinSkillsDir();
5589
5591
  const dirs = [
5590
5592
  // Project-level
5591
5593
  _path.join.call(void 0, cwd, ".code-shell", "skills"),
5592
5594
  _path.join.call(void 0, cwd, ".claude", "skills"),
5593
5595
  // User-level
5594
5596
  _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "skills"),
5595
- _path.join.call(void 0, _os.homedir.call(void 0, ), ".claude", "skills")
5597
+ _path.join.call(void 0, _os.homedir.call(void 0, ), ".claude", "skills"),
5598
+ // Built-in (shipped inside the npm package). Listed last so user/project
5599
+ // skills with the same filename win deduplication on filePath.
5600
+ ...builtin ? [builtin] : []
5596
5601
  ];
5597
5602
  for (const dir of dirs) {
5598
5603
  if (!_fs.existsSync.call(void 0, dir)) continue;
@@ -5612,6 +5617,30 @@ function scanSkills(cwd) {
5612
5617
  }
5613
5618
  return skills;
5614
5619
  }
5620
+ function resolveBuiltinSkillsDir() {
5621
+ let here;
5622
+ try {
5623
+ here = typeof import.meta !== "undefined" && _chunkKS3RYAYLcjs.importMetaUrl ? _path.dirname.call(void 0, _url.fileURLToPath.call(void 0, _chunkKS3RYAYLcjs.importMetaUrl)) : __dirname;
5624
+ } catch (e28) {
5625
+ return null;
5626
+ }
5627
+ let dir = here;
5628
+ for (let i = 0; i < 6; i++) {
5629
+ const pkgPath = _path.join.call(void 0, dir, "package.json");
5630
+ try {
5631
+ const pkg = JSON.parse(_fs.readFileSync.call(void 0, pkgPath, "utf-8"));
5632
+ if (_optionalChain([pkg, 'optionalAccess', _123 => _123.name]) === "@cjhyy/code-shell") {
5633
+ const candidate = _path.join.call(void 0, dir, "skills-builtin");
5634
+ return _fs.existsSync.call(void 0, candidate) ? candidate : null;
5635
+ }
5636
+ } catch (e29) {
5637
+ }
5638
+ const parent = _path.dirname.call(void 0, dir);
5639
+ if (parent === dir) break;
5640
+ dir = parent;
5641
+ }
5642
+ return null;
5643
+ }
5615
5644
  function parseSkillFile(filePath) {
5616
5645
  try {
5617
5646
  const raw = _fs.readFileSync.call(void 0, filePath, "utf-8");
@@ -5634,13 +5663,13 @@ function parseSkillFile(filePath) {
5634
5663
  content,
5635
5664
  filePath
5636
5665
  };
5637
- } catch (e28) {
5666
+ } catch (e30) {
5638
5667
  return null;
5639
5668
  }
5640
5669
  }
5641
5670
  function extractField(frontmatter, field) {
5642
5671
  const match = frontmatter.match(new RegExp(`^${field}:\\s*(.+)$`, "m"));
5643
- return _optionalChain([match, 'optionalAccess', _123 => _123[1], 'optionalAccess', _124 => _124.trim, 'call', _125 => _125()]);
5672
+ return _optionalChain([match, 'optionalAccess', _124 => _124[1], 'optionalAccess', _125 => _125.trim, 'call', _126 => _126()]);
5644
5673
  }
5645
5674
  function extractList(frontmatter, field) {
5646
5675
  const match = frontmatter.match(new RegExp(`${field}:\\s*\\[([^\\]]+)\\]`));
@@ -5685,7 +5714,7 @@ function matchSkillsByInput(skills, input) {
5685
5714
  return results.sort((a, b) => b.score - a.score);
5686
5715
  }
5687
5716
  function matchSkillsByTool(skills, toolName) {
5688
- return skills.filter((s) => _optionalChain([s, 'access', _126 => _126.triggers, 'access', _127 => _127.tools, 'optionalAccess', _128 => _128.includes, 'call', _129 => _129(toolName)])).map((skill) => ({ skill, score: 10, matchedBy: "tool" }));
5717
+ return skills.filter((s) => _optionalChain([s, 'access', _127 => _127.triggers, 'access', _128 => _128.tools, 'optionalAccess', _129 => _129.includes, 'call', _130 => _130(toolName)])).map((skill) => ({ skill, score: 10, matchedBy: "tool" }));
5689
5718
  }
5690
5719
  function buildSkillListing(skills) {
5691
5720
  if (skills.length === 0) return "";
@@ -5900,12 +5929,12 @@ function buildPresetSystemPrompt(preset) {
5900
5929
  return loadSections(preset.promptSections);
5901
5930
  }
5902
5931
  function resolveBuiltinToolNames(options) {
5903
- const preset = resolveAgentPreset(_optionalChain([options, 'optionalAccess', _130 => _130.preset]));
5932
+ const preset = resolveAgentPreset(_optionalChain([options, 'optionalAccess', _131 => _131.preset]));
5904
5933
  const names = new Set(preset.builtinTools);
5905
- for (const name of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _131 => _131.enabledBuiltinTools]), () => ( []))) {
5934
+ for (const name of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _132 => _132.enabledBuiltinTools]), () => ( []))) {
5906
5935
  names.add(name);
5907
5936
  }
5908
- for (const name of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _132 => _132.disabledBuiltinTools]), () => ( []))) {
5937
+ for (const name of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _133 => _133.disabledBuiltinTools]), () => ( []))) {
5909
5938
  names.delete(name);
5910
5939
  }
5911
5940
  return [...names];
@@ -5983,7 +6012,7 @@ ${status}`;
5983
6012
  Recent commits:
5984
6013
  ${log}`;
5985
6014
  }
5986
- } catch (e29) {
6015
+ } catch (e31) {
5987
6016
  }
5988
6017
  return gitStatus;
5989
6018
  }
@@ -6060,7 +6089,7 @@ ${toolLines.join("\n\n")}`;
6060
6089
  try {
6061
6090
  const mm = new (0, _chunkJMR33QVFcjs.MemoryManager)(this.options.cwd);
6062
6091
  return mm.buildMemoryContext();
6063
- } catch (e30) {
6092
+ } catch (e32) {
6064
6093
  return "";
6065
6094
  }
6066
6095
  }
@@ -6076,13 +6105,24 @@ var READ_BUDGET = 3;
6076
6105
  var SILENT_TURN_BUDGET = 3;
6077
6106
  var DEDUPE_OFFSET_BUCKET = 50;
6078
6107
  var READ_HISTORY_MAX = 512;
6079
- var InvestigationGuard = (_class15 = class {constructor() { _class15.prototype.__init27.call(this);_class15.prototype.__init28.call(this);_class15.prototype.__init29.call(this);_class15.prototype.__init30.call(this);_class15.prototype.__init31.call(this);_class15.prototype.__init32.call(this); }
6108
+ var InvestigationGuard = (_class15 = class {constructor() { _class15.prototype.__init27.call(this);_class15.prototype.__init28.call(this);_class15.prototype.__init29.call(this);_class15.prototype.__init30.call(this);_class15.prototype.__init31.call(this);_class15.prototype.__init32.call(this);_class15.prototype.__init33.call(this); }
6080
6109
  __init27() {this.readHistory = /* @__PURE__ */ new Map()}
6081
6110
  __init28() {this.consecutiveReads = 0}
6082
6111
  __init29() {this.silentTurns = 0}
6083
6112
  __init30() {this.turnHasText = false}
6084
6113
  __init31() {this.turnHasSideEffect = false}
6085
6114
  __init32() {this.lastReminderSilent = -1}
6115
+ /**
6116
+ * Soft mode replaces hard blocks (3rd-read dedupe) with a stronger
6117
+ * reminder. Used in headless runs (`code-shell run …`) where there is
6118
+ * no human to retry the task, so an unattended automation should not
6119
+ * be killed by the guard — it should still get the signal to change
6120
+ * strategy, but the tool call goes through.
6121
+ */
6122
+ __init33() {this.softMode = false}
6123
+ setSoftMode(soft) {
6124
+ this.softMode = soft;
6125
+ }
6086
6126
  preToolCheck(call) {
6087
6127
  const tool = call.toolName;
6088
6128
  if (!READ_ONLY_TOOLS.has(tool)) {
@@ -6103,9 +6143,12 @@ var InvestigationGuard = (_class15 = class {constructor() { _class15.prototype._
6103
6143
  this.consecutiveReads += 1;
6104
6144
  const prependParts = [];
6105
6145
  if (hits >= 3) {
6106
- return {
6107
- block: `Investigation guard: ${tool} on this exact target has been called ${hits} times in this session. Re-reading the same content will not produce new information. Switch strategy: run a command with side effects (Bash, debug log, repro), make a code change, or ask the user a specific question. If you genuinely need this content, summarize what you already know about it from prior reads instead of re-fetching.`
6108
- };
6146
+ const message = `Investigation guard: ${tool} on this exact target has been called ${hits} times in this session. Re-reading the same content will not produce new information. Switch strategy: run a command with side effects (Bash, debug log, repro), make a code change, or ask the user a specific question. If you genuinely need this content, summarize what you already know about it from prior reads instead of re-fetching.`;
6147
+ if (this.softMode) {
6148
+ prependParts.push(`<system-reminder>${message}</system-reminder>`);
6149
+ } else {
6150
+ return { block: message };
6151
+ }
6109
6152
  }
6110
6153
  if (hits === 2) {
6111
6154
  prependParts.push(
@@ -6261,7 +6304,7 @@ var ModelFacade = class {
6261
6304
  args: _nullishCoalesce(chunk.toolCall.args, () => ( {}))
6262
6305
  }
6263
6306
  });
6264
- } else if (chunk.type === "tool_use_delta" && _optionalChain([chunk, 'access', _133 => _133.toolCall, 'optionalAccess', _134 => _134.id])) {
6307
+ } else if (chunk.type === "tool_use_delta" && _optionalChain([chunk, 'access', _134 => _134.toolCall, 'optionalAccess', _135 => _135.id])) {
6265
6308
  onStream({
6266
6309
  type: "tool_use_args_delta",
6267
6310
  toolCallId: chunk.toolCall.id,
@@ -6282,7 +6325,7 @@ var ModelFacade = class {
6282
6325
  msgCount,
6283
6326
  stopReason: response.stopReason,
6284
6327
  toolCalls: response.toolCalls.length,
6285
- textLen: _nullishCoalesce(_optionalChain([response, 'access', _135 => _135.text, 'optionalAccess', _136 => _136.length]), () => ( 0)),
6328
+ textLen: _nullishCoalesce(_optionalChain([response, 'access', _136 => _136.text, 'optionalAccess', _137 => _137.length]), () => ( 0)),
6286
6329
  usage: response.usage
6287
6330
  });
6288
6331
  recordLLMResponse(
@@ -6340,7 +6383,7 @@ var ModelFacade = class {
6340
6383
  msgCount,
6341
6384
  stopReason: response.stopReason,
6342
6385
  toolCalls: response.toolCalls.length,
6343
- textLen: _nullishCoalesce(_optionalChain([response, 'access', _137 => _137.text, 'optionalAccess', _138 => _138.length]), () => ( 0)),
6386
+ textLen: _nullishCoalesce(_optionalChain([response, 'access', _138 => _138.text, 'optionalAccess', _139 => _139.length]), () => ( 0)),
6344
6387
  usage: response.usage
6345
6388
  });
6346
6389
  recordLLMResponse(
@@ -6445,11 +6488,11 @@ function checkTokenBudget(turnOutputTokens, budget, tracker) {
6445
6488
  _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
6446
6489
  var StreamingToolQueue = (_class16 = class {
6447
6490
 
6448
- __init33() {this.pending = /* @__PURE__ */ new Map()}
6449
- __init34() {this.unsafeQueue = []}
6450
- __init35() {this.callOrder = []}
6451
- __init36() {this.draining = false}
6452
- constructor(executor) {;_class16.prototype.__init33.call(this);_class16.prototype.__init34.call(this);_class16.prototype.__init35.call(this);_class16.prototype.__init36.call(this);
6491
+ __init34() {this.pending = /* @__PURE__ */ new Map()}
6492
+ __init35() {this.unsafeQueue = []}
6493
+ __init36() {this.callOrder = []}
6494
+ __init37() {this.draining = false}
6495
+ constructor(executor) {;_class16.prototype.__init34.call(this);_class16.prototype.__init35.call(this);_class16.prototype.__init36.call(this);_class16.prototype.__init37.call(this);
6453
6496
  this.executor = executor;
6454
6497
  }
6455
6498
  /**
@@ -6489,20 +6532,20 @@ var StreamingToolQueue = (_class16 = class {
6489
6532
 
6490
6533
  // src/engine/turn-loop.ts
6491
6534
  var TurnLoop = (_class17 = class {
6492
- constructor(deps, config) {;_class17.prototype.__init37.call(this);_class17.prototype.__init38.call(this);_class17.prototype.__init39.call(this);
6535
+ constructor(deps, config) {;_class17.prototype.__init38.call(this);_class17.prototype.__init39.call(this);_class17.prototype.__init40.call(this);
6493
6536
  this.deps = deps;
6494
6537
  this.config = config;
6495
6538
  }
6496
- __init37() {this.turnCount = 0}
6539
+ __init38() {this.turnCount = 0}
6497
6540
  /** Tool IDs already emitted as tool_use_start during streaming (to avoid duplicates). */
6498
- __init38() {this.streamedToolIds = /* @__PURE__ */ new Set()}
6541
+ __init39() {this.streamedToolIds = /* @__PURE__ */ new Set()}
6499
6542
  /**
6500
6543
  * Turn-scoped child logger set at the top of each loop iteration. Class
6501
6544
  * methods invoked inside the iteration (callModelWithFallback,
6502
6545
  * executeToolCall, ...) read it instead of using the root `logger`, so
6503
6546
  * every line they write is tagged with the current turn/turnId.
6504
6547
  */
6505
- __init39() {this.currentTurnLog = _chunkIK4EWJBPcjs.logger}
6548
+ __init40() {this.currentTurnLog = _chunkIK4EWJBPcjs.logger}
6506
6549
  /**
6507
6550
  * Run the multi-turn agent loop until completion.
6508
6551
  */
@@ -6519,7 +6562,7 @@ var TurnLoop = (_class17 = class {
6519
6562
  const turnStartedAt = Date.now();
6520
6563
  tlog.info("turn.start", { cat: "turn", messageCount: messages.length });
6521
6564
  this.deps.toolExecutor.setLogger(tlog);
6522
- _optionalChain([this, 'access', _139 => _139.config, 'access', _140 => _140.onStream, 'optionalCall', _141 => _141({ type: "stream_request_start", turnNumber: this.turnCount })]);
6565
+ _optionalChain([this, 'access', _140 => _140.config, 'access', _141 => _141.onStream, 'optionalCall', _142 => _142({ type: "stream_request_start", turnNumber: this.turnCount })]);
6523
6566
  await this.deps.hooks.emit("on_turn_start", { turnNumber: this.turnCount });
6524
6567
  const turnsRemaining = this.config.maxTurns - this.turnCount;
6525
6568
  if (turnsRemaining === 2) {
@@ -6552,14 +6595,14 @@ var TurnLoop = (_class17 = class {
6552
6595
  break;
6553
6596
  } catch (retryErr) {
6554
6597
  if (!(retryErr instanceof _chunk2YW4FPFGcjs.ContextLimitError)) {
6555
- _optionalChain([this, 'access', _142 => _142.config, 'access', _143 => _143.onStream, 'optionalCall', _144 => _144({ type: "error", error: retryErr.message })]);
6598
+ _optionalChain([this, 'access', _143 => _143.config, 'access', _144 => _144.onStream, 'optionalCall', _145 => _145({ type: "error", error: retryErr.message })]);
6556
6599
  return { text: finalText, reason: "model_error", messages };
6557
6600
  }
6558
6601
  }
6559
6602
  }
6560
6603
  if (!recovered) {
6561
6604
  this.patchOrphanedToolUses(messages);
6562
- _optionalChain([this, 'access', _145 => _145.config, 'access', _146 => _146.onStream, 'optionalCall', _147 => _147({
6605
+ _optionalChain([this, 'access', _146 => _146.config, 'access', _147 => _147.onStream, 'optionalCall', _148 => _148({
6563
6606
  type: "error",
6564
6607
  error: "Context limit exceeded after 3 recovery attempts"
6565
6608
  })]);
@@ -6567,17 +6610,17 @@ var TurnLoop = (_class17 = class {
6567
6610
  }
6568
6611
  } else {
6569
6612
  this.patchOrphanedToolUses(messages);
6570
- _optionalChain([this, 'access', _148 => _148.config, 'access', _149 => _149.onStream, 'optionalCall', _150 => _150({ type: "error", error: err.message })]);
6613
+ _optionalChain([this, 'access', _149 => _149.config, 'access', _150 => _150.onStream, 'optionalCall', _151 => _151({ type: "error", error: err.message })]);
6571
6614
  return { text: finalText, reason: "model_error", messages };
6572
6615
  }
6573
6616
  }
6574
- if (_optionalChain([response, 'access', _151 => _151.usage, 'optionalAccess', _152 => _152.promptTokens]) !== void 0) {
6575
- _optionalChain([this, 'access', _153 => _153.config, 'access', _154 => _154.onStream, 'optionalCall', _155 => _155({
6617
+ if (_optionalChain([response, 'access', _152 => _152.usage, 'optionalAccess', _153 => _153.promptTokens]) !== void 0) {
6618
+ _optionalChain([this, 'access', _154 => _154.config, 'access', _155 => _155.onStream, 'optionalCall', _156 => _156({
6576
6619
  type: "usage_update",
6577
6620
  promptTokens: response.usage.promptTokens
6578
6621
  })]);
6579
6622
  }
6580
- if (_optionalChain([response, 'access', _156 => _156.usage, 'optionalAccess', _157 => _157.promptTokens]) !== void 0) {
6623
+ if (_optionalChain([response, 'access', _157 => _157.usage, 'optionalAccess', _158 => _158.promptTokens]) !== void 0) {
6581
6624
  this.deps.contextManager.recordActualUsage(response.usage.promptTokens, messages.length);
6582
6625
  }
6583
6626
  if (response.stopReason === "max_tokens" && response.toolCalls.length === 0 && response.text) {
@@ -6605,26 +6648,26 @@ var TurnLoop = (_class17 = class {
6605
6648
  response = { ...contResponse, text: combinedText };
6606
6649
  break;
6607
6650
  }
6608
- } catch (e31) {
6651
+ } catch (e33) {
6609
6652
  break;
6610
6653
  }
6611
6654
  }
6612
6655
  response = { ...response, text: combinedText };
6613
6656
  }
6614
- if (_optionalChain([response, 'access', _158 => _158.usage, 'optionalAccess', _159 => _159.promptTokens]) !== void 0) {
6615
- _optionalChain([this, 'access', _160 => _160.config, 'access', _161 => _161.onStream, 'optionalCall', _162 => _162({
6657
+ if (_optionalChain([response, 'access', _159 => _159.usage, 'optionalAccess', _160 => _160.promptTokens]) !== void 0) {
6658
+ _optionalChain([this, 'access', _161 => _161.config, 'access', _162 => _162.onStream, 'optionalCall', _163 => _163({
6616
6659
  type: "usage_update",
6617
6660
  promptTokens: response.usage.promptTokens
6618
6661
  })]);
6619
6662
  }
6620
- if (_optionalChain([this, 'access', _163 => _163.config, 'access', _164 => _164.signal, 'optionalAccess', _165 => _165.aborted])) {
6663
+ if (_optionalChain([this, 'access', _164 => _164.config, 'access', _165 => _165.signal, 'optionalAccess', _166 => _166.aborted])) {
6621
6664
  return { text: finalText, reason: "aborted_streaming", messages };
6622
6665
  }
6623
6666
  if (response.text) {
6624
6667
  finalText = response.text;
6625
6668
  }
6626
6669
  if (response.toolCalls.length === 0) {
6627
- _optionalChain([this, 'access', _166 => _166.config, 'access', _167 => _167.onStream, 'optionalCall', _168 => _168({
6670
+ _optionalChain([this, 'access', _167 => _167.config, 'access', _168 => _168.onStream, 'optionalCall', _169 => _169({
6628
6671
  type: "assistant_message",
6629
6672
  message: { role: "assistant", content: finalText }
6630
6673
  })]);
@@ -6649,7 +6692,7 @@ var TurnLoop = (_class17 = class {
6649
6692
  input: tc.args
6650
6693
  });
6651
6694
  if (!this.streamedToolIds.has(tc.id)) {
6652
- _optionalChain([this, 'access', _169 => _169.config, 'access', _170 => _170.onStream, 'optionalCall', _171 => _171({ type: "tool_use_start", toolCall: tc })]);
6695
+ _optionalChain([this, 'access', _170 => _170.config, 'access', _171 => _171.onStream, 'optionalCall', _172 => _172({ type: "tool_use_start", toolCall: tc })]);
6653
6696
  }
6654
6697
  this.deps.transcript.appendToolUse(tc.toolName, tc.id, tc.args);
6655
6698
  }
@@ -6672,20 +6715,20 @@ var TurnLoop = (_class17 = class {
6672
6715
  result.result,
6673
6716
  result.error
6674
6717
  );
6675
- _optionalChain([this, 'access', _172 => _172.config, 'access', _173 => _173.onStream, 'optionalCall', _174 => _174({ type: "tool_result", result })]);
6718
+ _optionalChain([this, 'access', _173 => _173.config, 'access', _174 => _174.onStream, 'optionalCall', _175 => _175({ type: "tool_result", result })]);
6676
6719
  }
6677
6720
  if (this.config.onStream) {
6678
6721
  Promise.resolve().then(() => _interopRequireWildcard(require("./tool-summary-63DPIS7G.cjs"))).then(({ generateToolUseSummary }) => {
6679
6722
  if (!this.deps.model.summarize) return;
6680
6723
  generateToolUseSummary(toolCalls, results, this.deps.model.summarize).then((summary) => {
6681
6724
  if (summary) {
6682
- _optionalChain([this, 'access', _175 => _175.config, 'access', _176 => _176.onStream, 'optionalCall', _177 => _177({ type: "tool_summary", summary })]);
6725
+ _optionalChain([this, 'access', _176 => _176.config, 'access', _177 => _177.onStream, 'optionalCall', _178 => _178({ type: "tool_summary", summary })]);
6683
6726
  }
6684
6727
  });
6685
6728
  });
6686
6729
  }
6687
6730
  messages.push({ role: "user", content: resultBlocks });
6688
- const totalOutputTokens = _nullishCoalesce(_optionalChain([this, 'access', _178 => _178.deps, 'access', _179 => _179.model, 'access', _180 => _180.getOutputTokens, 'optionalCall', _181 => _181()]), () => ( 0));
6731
+ const totalOutputTokens = _nullishCoalesce(_optionalChain([this, 'access', _179 => _179.deps, 'access', _180 => _180.model, 'access', _181 => _181.getOutputTokens, 'optionalCall', _182 => _182()]), () => ( 0));
6689
6732
  const budgetDecision = checkTokenBudget(
6690
6733
  totalOutputTokens,
6691
6734
  _nullishCoalesce(this.config.tokenBudget, () => ( Infinity)),
@@ -6697,7 +6740,7 @@ var TurnLoop = (_class17 = class {
6697
6740
  outputTokens: totalOutputTokens,
6698
6741
  budget: this.config.tokenBudget
6699
6742
  });
6700
- _optionalChain([this, 'access', _182 => _182.config, 'access', _183 => _183.onStream, 'optionalCall', _184 => _184({
6743
+ _optionalChain([this, 'access', _183 => _183.config, 'access', _184 => _184.onStream, 'optionalCall', _185 => _185({
6701
6744
  type: "assistant_message",
6702
6745
  message: { role: "assistant", content: finalText }
6703
6746
  })]);
@@ -6725,7 +6768,7 @@ var TurnLoop = (_class17 = class {
6725
6768
  toolCallCount: toolCalls.length
6726
6769
  });
6727
6770
  this.deps.transcript.appendTurnBoundary();
6728
- _optionalChain([this, 'access', _185 => _185.config, 'access', _186 => _186.onTurnBoundary, 'optionalCall', _187 => _187(this.turnCount)]);
6771
+ _optionalChain([this, 'access', _186 => _186.config, 'access', _187 => _187.onTurnBoundary, 'optionalCall', _188 => _188(this.turnCount)]);
6729
6772
  tlog.info("turn.end", {
6730
6773
  cat: "turn",
6731
6774
  duration_ms: Date.now() - turnStartedAt,
@@ -6754,17 +6797,17 @@ var TurnLoop = (_class17 = class {
6754
6797
  if (summaryResponse.text) {
6755
6798
  finalText = summaryResponse.text;
6756
6799
  }
6757
- } catch (e32) {
6800
+ } catch (e34) {
6758
6801
  this.currentTurnLog.warn("turn.summary_failed", { cat: "turn" });
6759
6802
  }
6760
6803
  if (finalText) {
6761
- _optionalChain([this, 'access', _188 => _188.config, 'access', _189 => _189.onStream, 'optionalCall', _190 => _190({
6804
+ _optionalChain([this, 'access', _189 => _189.config, 'access', _190 => _190.onStream, 'optionalCall', _191 => _191({
6762
6805
  type: "assistant_message",
6763
6806
  message: { role: "assistant", content: finalText }
6764
6807
  })]);
6765
6808
  messages.push({ role: "assistant", content: finalText });
6766
6809
  }
6767
- _optionalChain([this, 'access', _191 => _191.config, 'access', _192 => _192.onStream, 'optionalCall', _193 => _193({ type: "turn_complete", reason: "max_turns" })]);
6810
+ _optionalChain([this, 'access', _192 => _192.config, 'access', _193 => _193.onStream, 'optionalCall', _194 => _194({ type: "turn_complete", reason: "max_turns" })]);
6768
6811
  return { text: finalText, reason: "max_turns", messages };
6769
6812
  }
6770
6813
  /**
@@ -6774,7 +6817,7 @@ var TurnLoop = (_class17 = class {
6774
6817
  async callModelWithFallback(messages) {
6775
6818
  let streamingResponseTokens = 0;
6776
6819
  const wrappedStream = this.config.onStream ? (event) => {
6777
- if (event.type === "tool_use_start" && _optionalChain([event, 'access', _194 => _194.toolCall, 'optionalAccess', _195 => _195.id])) {
6820
+ if (event.type === "tool_use_start" && _optionalChain([event, 'access', _195 => _195.toolCall, 'optionalAccess', _196 => _196.id])) {
6778
6821
  this.streamedToolIds.add(event.toolCall.id);
6779
6822
  }
6780
6823
  if (event.type === "text_delta" && event.text) {
@@ -6801,7 +6844,7 @@ var TurnLoop = (_class17 = class {
6801
6844
  );
6802
6845
  } catch (err) {
6803
6846
  if (err instanceof _chunk2YW4FPFGcjs.ContextLimitError) throw err;
6804
- _optionalChain([this, 'access', _196 => _196.config, 'access', _197 => _197.onStream, 'optionalCall', _198 => _198({ type: "tombstone", messageId: `turn_${this.turnCount}` })]);
6847
+ _optionalChain([this, 'access', _197 => _197.config, 'access', _198 => _198.onStream, 'optionalCall', _199 => _199({ type: "tombstone", messageId: `turn_${this.turnCount}` })]);
6805
6848
  this.currentTurnLog.warn("turn.streaming_fallback", {
6806
6849
  cat: "turn",
6807
6850
  error: err.message
@@ -6897,8 +6940,8 @@ var TurnLoop = (_class17 = class {
6897
6940
  // src/llm/provider-catalog.ts
6898
6941
  _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
6899
6942
  var ProviderCatalog = (_class18 = class {
6900
- __init40() {this.byKey = /* @__PURE__ */ new Map()}
6901
- constructor(entries) {;_class18.prototype.__init40.call(this);
6943
+ __init41() {this.byKey = /* @__PURE__ */ new Map()}
6944
+ constructor(entries) {;_class18.prototype.__init41.call(this);
6902
6945
  for (const e of _nullishCoalesce(entries, () => ( []))) this.byKey.set(e.key, e);
6903
6946
  }
6904
6947
  list() {
@@ -6972,7 +7015,7 @@ function detectPastedNoise(task) {
6972
7015
 
6973
7016
 
6974
7017
  var Engine = (_class19 = class _Engine {
6975
- constructor(config) {;_class19.prototype.__init41.call(this);
7018
+ constructor(config) {;_class19.prototype.__init42.call(this);
6976
7019
  this.config = config;
6977
7020
  this.preset = resolveAgentPreset(config.preset);
6978
7021
  this.toolRegistry = new ToolRegistry({
@@ -7005,7 +7048,7 @@ var Engine = (_class19 = class _Engine {
7005
7048
 
7006
7049
 
7007
7050
 
7008
- __init41() {this.compactedMessagesBySession = /* @__PURE__ */ new Map()}
7051
+ __init42() {this.compactedMessagesBySession = /* @__PURE__ */ new Map()}
7009
7052
 
7010
7053
  /** Public accessor so UI/clients can read the resolved per-model window. */
7011
7054
  get maxContextTokens() {
@@ -7013,7 +7056,7 @@ var Engine = (_class19 = class _Engine {
7013
7056
  }
7014
7057
  resolveMaxContextTokens() {
7015
7058
  const modelEntry = this.modelPool.get();
7016
- return _nullishCoalesce(_nullishCoalesce(_optionalChain([modelEntry, 'optionalAccess', _199 => _199.maxContextTokens]), () => ( this.config.maxContextTokens)), () => ( 2e5));
7059
+ return _nullishCoalesce(_nullishCoalesce(_optionalChain([modelEntry, 'optionalAccess', _200 => _200.maxContextTokens]), () => ( this.config.maxContextTokens)), () => ( 2e5));
7017
7060
  }
7018
7061
  /**
7019
7062
  * Load models[] / providers[] from settings into the active ModelPool and
@@ -7025,7 +7068,7 @@ var Engine = (_class19 = class _Engine {
7025
7068
  const sm = this.getSettingsManager();
7026
7069
  sm.invalidate();
7027
7070
  const settings = sm.get();
7028
- if (_optionalChain([settings, 'access', _200 => _200.models, 'optionalAccess', _201 => _201.length])) {
7071
+ if (_optionalChain([settings, 'access', _201 => _201.models, 'optionalAccess', _202 => _202.length])) {
7029
7072
  for (const m of settings.models) {
7030
7073
  this.modelPool.register({
7031
7074
  key: m.key,
@@ -7039,7 +7082,7 @@ var Engine = (_class19 = class _Engine {
7039
7082
  providerKey: m.providerKey
7040
7083
  });
7041
7084
  }
7042
- if (_optionalChain([settings, 'access', _202 => _202.providers, 'optionalAccess', _203 => _203.length])) {
7085
+ if (_optionalChain([settings, 'access', _203 => _203.providers, 'optionalAccess', _204 => _204.length])) {
7043
7086
  this.modelPool.setProviderCatalog(
7044
7087
  new ProviderCatalog(settings.providers)
7045
7088
  );
@@ -7054,7 +7097,7 @@ var Engine = (_class19 = class _Engine {
7054
7097
  if (!match) {
7055
7098
  const currentModel = this.config.llm.model;
7056
7099
  match = settings.models.find(
7057
- (m) => m.model === currentModel || currentModel && _optionalChain([m, 'access', _204 => _204.model, 'optionalAccess', _205 => _205.endsWith, 'call', _206 => _206(`/${currentModel}`)])
7100
+ (m) => m.model === currentModel || currentModel && _optionalChain([m, 'access', _205 => _205.model, 'optionalAccess', _206 => _206.endsWith, 'call', _207 => _207(`/${currentModel}`)])
7058
7101
  );
7059
7102
  }
7060
7103
  if (match) {
@@ -7067,7 +7110,7 @@ var Engine = (_class19 = class _Engine {
7067
7110
  } else if (this.config.llm.apiKey) {
7068
7111
  this.autoPopulatePool(this.config.llm.apiKey, this.config.llm.baseUrl);
7069
7112
  }
7070
- } catch (e33) {
7113
+ } catch (e35) {
7071
7114
  }
7072
7115
  }
7073
7116
  /**
@@ -7085,9 +7128,9 @@ var Engine = (_class19 = class _Engine {
7085
7128
  * key prefix / baseUrl and registers all its known models.
7086
7129
  */
7087
7130
  autoPopulatePool(apiKey, baseUrl) {
7088
- const provider = _chunkBWTOS5BHcjs.detectProviderFromApiKey.call(void 0, apiKey, baseUrl);
7131
+ const provider = _chunkWZJV6DJCcjs.detectProviderFromApiKey.call(void 0, apiKey, baseUrl);
7089
7132
  if (!provider) return;
7090
- const entries = _chunkBWTOS5BHcjs.buildModelPool.call(void 0, provider, apiKey);
7133
+ const entries = _chunkWZJV6DJCcjs.buildModelPool.call(void 0, provider, apiKey);
7091
7134
  for (const e of entries) {
7092
7135
  this.modelPool.register(e);
7093
7136
  }
@@ -7129,13 +7172,13 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7129
7172
  return {
7130
7173
  text: hint,
7131
7174
  reason: "completed",
7132
- sessionId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _207 => _207.sessionId]), () => ( "noise-rejected")),
7175
+ sessionId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _208 => _208.sessionId]), () => ( "noise-rejected")),
7133
7176
  turnCount: 0,
7134
7177
  usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 }
7135
7178
  };
7136
7179
  }
7137
7180
  const subAgentSpawner = {
7138
- parentStream: _optionalChain([options, 'optionalAccess', _208 => _208.onStream]),
7181
+ parentStream: _optionalChain([options, 'optionalAccess', _209 => _209.onStream]),
7139
7182
  describe: () => ({
7140
7183
  cwd,
7141
7184
  preset: this.preset.name,
@@ -7155,7 +7198,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7155
7198
  maxContextTokens: _nullishCoalesce(this.config.maxContextTokens, () => ( 2e5)),
7156
7199
  sessionStorageDir: this.config.sessionStorageDir
7157
7200
  });
7158
- const childStream = _optionalChain([options, 'optionalAccess', _209 => _209.onStream]) ? (event) => options.onStream({ ...event, agentId: req.agentId }) : void 0;
7201
+ const childStream = _optionalChain([options, 'optionalAccess', _210 => _210.onStream]) ? (event) => options.onStream({ ...event, agentId: req.agentId }) : void 0;
7159
7202
  const result2 = await child.run(req.prompt, { signal: req.signal, onStream: childStream });
7160
7203
  return result2.text;
7161
7204
  }
@@ -7176,7 +7219,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7176
7219
  });
7177
7220
  let session;
7178
7221
  let messages;
7179
- if (_optionalChain([options, 'optionalAccess', _210 => _210.sessionId])) {
7222
+ if (_optionalChain([options, 'optionalAccess', _211 => _211.sessionId])) {
7180
7223
  session = this.sessionManager.resume(options.sessionId);
7181
7224
  messages = this.compactedMessagesBySession.get(options.sessionId) ? [...this.compactedMessagesBySession.get(options.sessionId)] : session.transcript.toMessages();
7182
7225
  if (session.state.costState && this.config.costStore) {
@@ -7200,10 +7243,10 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7200
7243
  model: this.config.llm.model,
7201
7244
  provider: this.config.llm.provider,
7202
7245
  permissionMode: _nullishCoalesce(this.config.permissionMode, () => ( "acceptEdits")),
7203
- resumed: !!_optionalChain([options, 'optionalAccess', _211 => _211.sessionId])
7246
+ resumed: !!_optionalChain([options, 'optionalAccess', _212 => _212.sessionId])
7204
7247
  });
7205
- _optionalChain([options, 'optionalAccess', _212 => _212.onStream, 'optionalCall', _213 => _213({ type: "session_started", sessionId: session.state.sessionId })]);
7206
- const llmClientPromise = _chunkBWTOS5BHcjs.createLLMClient.call(void 0, this.config.llm);
7248
+ _optionalChain([options, 'optionalAccess', _213 => _213.onStream, 'optionalCall', _214 => _214({ type: "session_started", sessionId: session.state.sessionId })]);
7249
+ const llmClientPromise = _chunkWZJV6DJCcjs.createLLMClient.call(void 0, this.config.llm);
7207
7250
  const mode = _nullishCoalesce(this.config.permissionMode, () => ( "acceptEdits"));
7208
7251
  const { rules: defaultRules, backend: approvalBackend } = this.buildPermissionConfig(mode, cwd);
7209
7252
  const permission = new PermissionClassifier(defaultRules, mode, approvalBackend);
@@ -7216,8 +7259,9 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7216
7259
  }
7217
7260
  const toolExecutor = new ToolExecutor(this.toolRegistry, permission, this.hooks);
7218
7261
  const investigationGuard = new InvestigationGuard();
7262
+ if (this.config.headless) investigationGuard.setSoftMode(true);
7219
7263
  toolExecutor.setInvestigationGuard(investigationGuard);
7220
- toolExecutor.setSignal(_optionalChain([options, 'optionalAccess', _214 => _214.signal]));
7264
+ toolExecutor.setSignal(_optionalChain([options, 'optionalAccess', _215 => _215.signal]));
7221
7265
  toolExecutor.setContext(toolCtx);
7222
7266
  const contextManager = new ContextManager({
7223
7267
  maxTokens: this.resolveMaxContextTokens()
@@ -7298,8 +7342,8 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7298
7342
  completionLen: resp.text.length,
7299
7343
  completionPreview: resp.text.slice(0, 300),
7300
7344
  stopReason: resp.stopReason,
7301
- promptTokens: _optionalChain([resp, 'access', _215 => _215.usage, 'optionalAccess', _216 => _216.promptTokens]),
7302
- completionTokens: _optionalChain([resp, 'access', _217 => _217.usage, 'optionalAccess', _218 => _218.completionTokens])
7345
+ promptTokens: _optionalChain([resp, 'access', _216 => _216.usage, 'optionalAccess', _217 => _217.promptTokens]),
7346
+ completionTokens: _optionalChain([resp, 'access', _218 => _218.usage, 'optionalAccess', _219 => _219.completionTokens])
7303
7347
  });
7304
7348
  return resp.text;
7305
7349
  };
@@ -7311,9 +7355,9 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7311
7355
  this.hooks.register(
7312
7356
  "on_tool_start",
7313
7357
  async (context) => {
7314
- const toolName = _optionalChain([context, 'access', _219 => _219.data, 'optionalAccess', _220 => _220.toolName]);
7315
- const args = _optionalChain([context, 'access', _221 => _221.data, 'optionalAccess', _222 => _222.args]);
7316
- if ((toolName === "Write" || toolName === "Edit") && _optionalChain([args, 'optionalAccess', _223 => _223.file_path])) {
7358
+ const toolName = _optionalChain([context, 'access', _220 => _220.data, 'optionalAccess', _221 => _221.toolName]);
7359
+ const args = _optionalChain([context, 'access', _222 => _222.data, 'optionalAccess', _223 => _223.args]);
7360
+ if ((toolName === "Write" || toolName === "Edit") && _optionalChain([args, 'optionalAccess', _224 => _224.file_path])) {
7317
7361
  fileHistory.saveSnapshot(args.file_path);
7318
7362
  }
7319
7363
  return {};
@@ -7327,7 +7371,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7327
7371
  model: this.config.llm.model
7328
7372
  });
7329
7373
  contextManager.setOnCompact((info) => {
7330
- _optionalChain([options, 'optionalAccess', _224 => _224.onStream, 'optionalCall', _225 => _225({ type: "context_compact", ...info })]);
7374
+ _optionalChain([options, 'optionalAccess', _225 => _225.onStream, 'optionalCall', _226 => _226({ type: "context_compact", ...info })]);
7331
7375
  });
7332
7376
  const turnLoop = new TurnLoop(
7333
7377
  {
@@ -7342,8 +7386,8 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7342
7386
  {
7343
7387
  maxTurns: _nullishCoalesce(this.config.maxTurns, () => ( 100)),
7344
7388
  maxToolCallsPerTurn: _nullishCoalesce(this.config.maxToolCallsPerTurn, () => ( 10)),
7345
- onStream: _optionalChain([options, 'optionalAccess', _226 => _226.onStream]),
7346
- signal: _optionalChain([options, 'optionalAccess', _227 => _227.signal]),
7389
+ onStream: _optionalChain([options, 'optionalAccess', _227 => _227.onStream]),
7390
+ signal: _optionalChain([options, 'optionalAccess', _228 => _228.signal]),
7347
7391
  // Heartbeat: flush turnCount + tokens to state.json after every turn
7348
7392
  // so external observers (other CLI processes, /sid, the session list)
7349
7393
  // see live progress instead of a stale snapshot from the last
@@ -7397,7 +7441,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7397
7441
  reason: result.reason,
7398
7442
  turnCount: turnLoop.currentTurn
7399
7443
  });
7400
- _optionalChain([options, 'optionalAccess', _228 => _228.onStream, 'optionalCall', _229 => _229({ type: "turn_complete", reason: result.reason })]);
7444
+ _optionalChain([options, 'optionalAccess', _229 => _229.onStream, 'optionalCall', _230 => _230({ type: "turn_complete", reason: result.reason })]);
7401
7445
  return {
7402
7446
  text: result.text,
7403
7447
  reason: result.reason,
@@ -7447,7 +7491,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7447
7491
  if (_fs.existsSync.call(void 0, file)) {
7448
7492
  try {
7449
7493
  existing = JSON.parse(_fs.readFileSync.call(void 0, file, "utf-8"));
7450
- } catch (e34) {
7494
+ } catch (e36) {
7451
7495
  return;
7452
7496
  }
7453
7497
  }
@@ -7468,7 +7512,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7468
7512
  _fs.writeFileSync.call(void 0, tmp, payload, "utf-8");
7469
7513
  try {
7470
7514
  _fs.renameSync.call(void 0, tmp, file);
7471
- } catch (e35) {
7515
+ } catch (e37) {
7472
7516
  _fs.writeFileSync.call(void 0, file, payload, "utf-8");
7473
7517
  }
7474
7518
  } catch (err) {
@@ -7541,7 +7585,7 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7541
7585
  }
7542
7586
  getSettingsManager() {
7543
7587
  if (!this.settingsManager) {
7544
- this.settingsManager = new (0, _chunkYUI524OEcjs.SettingsManager)(this.config.cwd);
7588
+ this.settingsManager = new (0, _chunk7BI3V74Ycjs.SettingsManager)(this.config.cwd);
7545
7589
  }
7546
7590
  return this.settingsManager;
7547
7591
  }
@@ -7575,12 +7619,12 @@ Extracted text: ${noise.cleaned.slice(0, 200)}` : "");
7575
7619
  rules.push({ tool: "Bash", decision: "allow" });
7576
7620
  }
7577
7621
  try {
7578
- const settingsManager = new (0, _chunkYUI524OEcjs.SettingsManager)(cwd);
7622
+ const settingsManager = new (0, _chunk7BI3V74Ycjs.SettingsManager)(cwd);
7579
7623
  const settings = settingsManager.get();
7580
- if (_optionalChain([settings, 'access', _230 => _230.permissions, 'optionalAccess', _231 => _231.rules, 'optionalAccess', _232 => _232.length])) {
7624
+ if (_optionalChain([settings, 'access', _231 => _231.permissions, 'optionalAccess', _232 => _232.rules, 'optionalAccess', _233 => _233.length])) {
7581
7625
  rules.unshift(...settings.permissions.rules);
7582
7626
  }
7583
- } catch (e36) {
7627
+ } catch (e38) {
7584
7628
  }
7585
7629
  let backend;
7586
7630
  if (this.config.approvalBackend) {
@@ -7649,7 +7693,7 @@ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7649
7693
 
7650
7694
  var FileRunStore = (_class20 = class {
7651
7695
 
7652
- constructor(storageDir) {;_class20.prototype.__init42.call(this);
7696
+ constructor(storageDir) {;_class20.prototype.__init43.call(this);
7653
7697
  this.runsDir = _nullishCoalesce(storageDir, () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
7654
7698
  _fs.mkdirSync.call(void 0, this.runsDir, { recursive: true });
7655
7699
  }
@@ -7675,7 +7719,7 @@ var FileRunStore = (_class20 = class {
7675
7719
  return JSON.parse(_fs.readFileSync.call(void 0, filePath, "utf-8"));
7676
7720
  }
7677
7721
  /** Serializes concurrent JSONL appends per file path. */
7678
- __init42() {this.appendLocks = /* @__PURE__ */ new Map()}
7722
+ __init43() {this.appendLocks = /* @__PURE__ */ new Map()}
7679
7723
  async appendJsonl(filePath, data) {
7680
7724
  const prev = _nullishCoalesce(this.appendLocks.get(filePath), () => ( Promise.resolve()));
7681
7725
  const current = prev.then(() => {
@@ -7715,16 +7759,16 @@ var FileRunStore = (_class20 = class {
7715
7759
  _path.join.call(void 0, this.runsDir, entry.name, "run.json")
7716
7760
  );
7717
7761
  if (!snapshot) continue;
7718
- if (_optionalChain([query, 'optionalAccess', _233 => _233.status])) {
7762
+ if (_optionalChain([query, 'optionalAccess', _234 => _234.status])) {
7719
7763
  const statuses = Array.isArray(query.status) ? query.status : [query.status];
7720
7764
  if (!statuses.includes(snapshot.status)) continue;
7721
7765
  }
7722
- if (_optionalChain([query, 'optionalAccess', _234 => _234.tag]) && !snapshot.tags.includes(query.tag)) continue;
7766
+ if (_optionalChain([query, 'optionalAccess', _235 => _235.tag]) && !snapshot.tags.includes(query.tag)) continue;
7723
7767
  snapshots.push(snapshot);
7724
7768
  }
7725
7769
  snapshots.sort((a, b) => b.createdAt - a.createdAt);
7726
- const offset = _nullishCoalesce(_optionalChain([query, 'optionalAccess', _235 => _235.offset]), () => ( 0));
7727
- const limit = _nullishCoalesce(_optionalChain([query, 'optionalAccess', _236 => _236.limit]), () => ( 50));
7770
+ const offset = _nullishCoalesce(_optionalChain([query, 'optionalAccess', _236 => _236.offset]), () => ( 0));
7771
+ const limit = _nullishCoalesce(_optionalChain([query, 'optionalAccess', _237 => _237.limit]), () => ( 50));
7728
7772
  return snapshots.slice(offset, offset + limit);
7729
7773
  }
7730
7774
  async delete(runId) {
@@ -7780,7 +7824,7 @@ var FileRunStore = (_class20 = class {
7780
7824
  const files = _fs.readdirSync.call(void 0, approvalDir).filter((f) => f.endsWith(".json"));
7781
7825
  for (const file of files) {
7782
7826
  const approval = this.readJson(_path.join.call(void 0, approvalDir, file));
7783
- if (_optionalChain([approval, 'optionalAccess', _237 => _237.status]) === "pending") return approval;
7827
+ if (_optionalChain([approval, 'optionalAccess', _238 => _238.status]) === "pending") return approval;
7784
7828
  }
7785
7829
  return null;
7786
7830
  }
@@ -7801,12 +7845,12 @@ var FileRunStore = (_class20 = class {
7801
7845
  _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7802
7846
  var RunQueue = (_class21 = class {
7803
7847
 
7804
- __init43() {this.pending = []}
7805
- __init44() {this.active = /* @__PURE__ */ new Set()}
7806
- __init45() {this.executor = null}
7807
- __init46() {this.draining = false}
7808
- constructor(config) {;_class21.prototype.__init43.call(this);_class21.prototype.__init44.call(this);_class21.prototype.__init45.call(this);_class21.prototype.__init46.call(this);
7809
- this.concurrency = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _238 => _238.concurrency]), () => ( 1));
7848
+ __init44() {this.pending = []}
7849
+ __init45() {this.active = /* @__PURE__ */ new Set()}
7850
+ __init46() {this.executor = null}
7851
+ __init47() {this.draining = false}
7852
+ constructor(config) {;_class21.prototype.__init44.call(this);_class21.prototype.__init45.call(this);_class21.prototype.__init46.call(this);_class21.prototype.__init47.call(this);
7853
+ this.concurrency = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _239 => _239.concurrency]), () => ( 1));
7810
7854
  }
7811
7855
  setExecutor(fn) {
7812
7856
  this.executor = fn;
@@ -7861,14 +7905,14 @@ var RunQueue = (_class21 = class {
7861
7905
 
7862
7906
  // src/run/RunApprovalBackend.ts
7863
7907
  _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7864
- var RunApprovalBackend = (_class22 = class {constructor() { _class22.prototype.__init47.call(this);_class22.prototype.__init48.call(this);_class22.prototype.__init49.call(this); }
7865
- __init47() {this.pendingApproval = null}
7866
- __init48() {this.hooks = null}
7908
+ var RunApprovalBackend = (_class22 = class {constructor() { _class22.prototype.__init48.call(this);_class22.prototype.__init49.call(this);_class22.prototype.__init50.call(this); }
7909
+ __init48() {this.pendingApproval = null}
7910
+ __init49() {this.hooks = null}
7867
7911
  setHooks(hooks) {
7868
7912
  this.hooks = hooks;
7869
7913
  }
7870
7914
  /** Max time (ms) to wait for approval before auto-rejecting. Default: 24h */
7871
- __init49() {this.timeoutMs = 24 * 60 * 60 * 1e3}
7915
+ __init50() {this.timeoutMs = 24 * 60 * 60 * 1e3}
7872
7916
  setTimeout(ms) {
7873
7917
  this.timeoutMs = ms;
7874
7918
  }
@@ -7880,7 +7924,7 @@ var RunApprovalBackend = (_class22 = class {constructor() { _class22.prototype._
7880
7924
  return new Promise((resolve6) => {
7881
7925
  this.pendingApproval = { resolve: resolve6, request };
7882
7926
  const timer = setTimeout(() => {
7883
- if (_optionalChain([this, 'access', _239 => _239.pendingApproval, 'optionalAccess', _240 => _240.resolve]) === resolve6) {
7927
+ if (_optionalChain([this, 'access', _240 => _240.pendingApproval, 'optionalAccess', _241 => _241.resolve]) === resolve6) {
7884
7928
  this.pendingApproval = null;
7885
7929
  resolve6({ approved: false, reason: "approval timed out" });
7886
7930
  }
@@ -7939,13 +7983,13 @@ var PHASE_PATTERNS = [
7939
7983
  var CheckpointWriter = (_class23 = class {
7940
7984
 
7941
7985
 
7942
- __init50() {this.currentTurn = 0}
7943
- __init51() {this.lastCheckpointTurn = 0}
7944
- __init52() {this.touchedTools = /* @__PURE__ */ new Set()}
7945
- __init53() {this.lastAssistantText = ""}
7946
- __init54() {this.sessionId = null}
7947
- __init55() {this.detectedPhases = /* @__PURE__ */ new Set()}
7948
- constructor(config) {;_class23.prototype.__init50.call(this);_class23.prototype.__init51.call(this);_class23.prototype.__init52.call(this);_class23.prototype.__init53.call(this);_class23.prototype.__init54.call(this);_class23.prototype.__init55.call(this);
7986
+ __init51() {this.currentTurn = 0}
7987
+ __init52() {this.lastCheckpointTurn = 0}
7988
+ __init53() {this.touchedTools = /* @__PURE__ */ new Set()}
7989
+ __init54() {this.lastAssistantText = ""}
7990
+ __init55() {this.sessionId = null}
7991
+ __init56() {this.detectedPhases = /* @__PURE__ */ new Set()}
7992
+ constructor(config) {;_class23.prototype.__init51.call(this);_class23.prototype.__init52.call(this);_class23.prototype.__init53.call(this);_class23.prototype.__init54.call(this);_class23.prototype.__init55.call(this);_class23.prototype.__init56.call(this);
7949
7993
  this.config = config;
7950
7994
  this.turnInterval = _nullishCoalesce(config.turnInterval, () => ( 10));
7951
7995
  }
@@ -8038,9 +8082,9 @@ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
8038
8082
 
8039
8083
  var ArtifactTracker = (_class24 = class {
8040
8084
 
8041
- __init56() {this.pendingCalls = /* @__PURE__ */ new Map()}
8042
- __init57() {this.recordedPaths = /* @__PURE__ */ new Set()}
8043
- constructor(config) {;_class24.prototype.__init56.call(this);_class24.prototype.__init57.call(this);
8085
+ __init57() {this.pendingCalls = /* @__PURE__ */ new Map()}
8086
+ __init58() {this.recordedPaths = /* @__PURE__ */ new Set()}
8087
+ constructor(config) {;_class24.prototype.__init57.call(this);_class24.prototype.__init58.call(this);
8044
8088
  this.config = config;
8045
8089
  }
8046
8090
  /**
@@ -8186,10 +8230,10 @@ function check(file, options) {
8186
8230
  var RunLock = (_class25 = class {
8187
8231
 
8188
8232
 
8189
- __init58() {this.releaseFns = /* @__PURE__ */ new Map()}
8190
- constructor(config) {;_class25.prototype.__init58.call(this);
8191
- this.runsDir = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _241 => _241.runsDir]), () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
8192
- this.staleMs = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _242 => _242.staleMs]), () => ( 6e4));
8233
+ __init59() {this.releaseFns = /* @__PURE__ */ new Map()}
8234
+ constructor(config) {;_class25.prototype.__init59.call(this);
8235
+ this.runsDir = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _242 => _242.runsDir]), () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
8236
+ this.staleMs = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _243 => _243.staleMs]), () => ( 6e4));
8193
8237
  }
8194
8238
  /**
8195
8239
  * Acquire a lock for a run. Returns true if acquired, false if already held.
@@ -8205,7 +8249,7 @@ var RunLock = (_class25 = class {
8205
8249
  this.releaseFns.set(runId, release);
8206
8250
  _chunkIK4EWJBPcjs.logger.info("run.lock.acquired", { runId });
8207
8251
  return true;
8208
- } catch (e37) {
8252
+ } catch (e39) {
8209
8253
  return false;
8210
8254
  }
8211
8255
  }
@@ -8217,7 +8261,7 @@ var RunLock = (_class25 = class {
8217
8261
  if (releaseFn) {
8218
8262
  try {
8219
8263
  await releaseFn();
8220
- } catch (e38) {
8264
+ } catch (e40) {
8221
8265
  }
8222
8266
  this.releaseFns.delete(runId);
8223
8267
  _chunkIK4EWJBPcjs.logger.info("run.lock.released", { runId });
@@ -8231,7 +8275,7 @@ var RunLock = (_class25 = class {
8231
8275
  if (!_fs.existsSync.call(void 0, lockTarget)) return false;
8232
8276
  try {
8233
8277
  return await check(lockTarget, { stale: this.staleMs });
8234
- } catch (e39) {
8278
+ } catch (e41) {
8235
8279
  return false;
8236
8280
  }
8237
8281
  }
@@ -8244,7 +8288,7 @@ var RunLock = (_class25 = class {
8244
8288
  try {
8245
8289
  await unlock(lockTarget);
8246
8290
  _chunkIK4EWJBPcjs.logger.info("run.lock.force_unlocked", { runId });
8247
- } catch (e40) {
8291
+ } catch (e42) {
8248
8292
  }
8249
8293
  }
8250
8294
  /**
@@ -8268,10 +8312,10 @@ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
8268
8312
  var Heartbeat = (_class26 = class {
8269
8313
 
8270
8314
 
8271
- __init59() {this.timers = /* @__PURE__ */ new Map()}
8272
- constructor(config) {;_class26.prototype.__init59.call(this);
8273
- this.runsDir = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _243 => _243.runsDir]), () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
8274
- this.intervalMs = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _244 => _244.intervalMs]), () => ( 5e3));
8315
+ __init60() {this.timers = /* @__PURE__ */ new Map()}
8316
+ constructor(config) {;_class26.prototype.__init60.call(this);
8317
+ this.runsDir = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _244 => _244.runsDir]), () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
8318
+ this.intervalMs = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _245 => _245.intervalMs]), () => ( 5e3));
8275
8319
  }
8276
8320
  /**
8277
8321
  * Start heartbeat for a run. Writes immediately, then repeats on interval.
@@ -8311,7 +8355,7 @@ var Heartbeat = (_class26 = class {
8311
8355
  if (!_fs.existsSync.call(void 0, filePath)) return null;
8312
8356
  try {
8313
8357
  return JSON.parse(_fs.readFileSync.call(void 0, filePath, "utf-8"));
8314
- } catch (e41) {
8358
+ } catch (e43) {
8315
8359
  return null;
8316
8360
  }
8317
8361
  }
@@ -8334,7 +8378,7 @@ var Heartbeat = (_class26 = class {
8334
8378
  try {
8335
8379
  process.kill(data.pid, 0);
8336
8380
  return true;
8337
- } catch (e42) {
8381
+ } catch (e44) {
8338
8382
  return false;
8339
8383
  }
8340
8384
  }
@@ -8346,7 +8390,7 @@ var Heartbeat = (_class26 = class {
8346
8390
  };
8347
8391
  try {
8348
8392
  _fs.writeFileSync.call(void 0, this.filePath(runId), JSON.stringify(data), "utf-8");
8349
- } catch (e43) {
8393
+ } catch (e45) {
8350
8394
  }
8351
8395
  }
8352
8396
  remove(runId) {
@@ -8355,7 +8399,7 @@ var Heartbeat = (_class26 = class {
8355
8399
  if (_fs.existsSync.call(void 0, filePath)) {
8356
8400
  _fs.unlinkSync.call(void 0, filePath);
8357
8401
  }
8358
- } catch (e44) {
8402
+ } catch (e46) {
8359
8403
  }
8360
8404
  }
8361
8405
  filePath(runId) {
@@ -8365,8 +8409,8 @@ var Heartbeat = (_class26 = class {
8365
8409
 
8366
8410
  // src/run/Evaluator.ts
8367
8411
  _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
8368
- var NoopEvaluator = (_class27 = class {constructor() { _class27.prototype.__init60.call(this); }
8369
- __init60() {this.name = "noop"}
8412
+ var NoopEvaluator = (_class27 = class {constructor() { _class27.prototype.__init61.call(this); }
8413
+ __init61() {this.name = "noop"}
8370
8414
  async evaluate() {
8371
8415
  return { verdict: "passed", findings: [] };
8372
8416
  }
@@ -8428,7 +8472,7 @@ var EngineRunner = class {
8428
8472
  hasPendingApproval: () => approvalBackend.hasPendingApproval(),
8429
8473
  hasPendingInput: hasPendingInputFn
8430
8474
  };
8431
- _optionalChain([onHandleReady, 'optionalCall', _245 => _245(handle)]);
8475
+ _optionalChain([onHandleReady, 'optionalCall', _246 => _246(handle)]);
8432
8476
  const engineConfig = {
8433
8477
  llm: this.config.llm,
8434
8478
  cwd: run.cwd,
@@ -8448,7 +8492,7 @@ var EngineRunner = class {
8448
8492
  ...context.engineConfigOverrides
8449
8493
  };
8450
8494
  const engine = new Engine(engineConfig);
8451
- if (_optionalChain([this, 'access', _246 => _246.config, 'access', _247 => _247.customTools, 'optionalAccess', _248 => _248.length])) {
8495
+ if (_optionalChain([this, 'access', _247 => _247.config, 'access', _248 => _248.customTools, 'optionalAccess', _249 => _249.length])) {
8452
8496
  for (const ct of this.config.customTools) {
8453
8497
  engine.registerCustomTool(ct.definition, ct.execute);
8454
8498
  }
@@ -8485,11 +8529,11 @@ var RunManager = (_class28 = class {
8485
8529
 
8486
8530
 
8487
8531
 
8488
- __init61() {this.subscribers = /* @__PURE__ */ new Map()}
8489
- __init62() {this.abortControllers = /* @__PURE__ */ new Map()}
8532
+ __init62() {this.subscribers = /* @__PURE__ */ new Map()}
8533
+ __init63() {this.abortControllers = /* @__PURE__ */ new Map()}
8490
8534
  /** Active execution handles — used to resolve pending approvals/input while Engine is suspended */
8491
- __init63() {this.executionHandles = /* @__PURE__ */ new Map()}
8492
- constructor(config) {;_class28.prototype.__init61.call(this);_class28.prototype.__init62.call(this);_class28.prototype.__init63.call(this);
8535
+ __init64() {this.executionHandles = /* @__PURE__ */ new Map()}
8536
+ constructor(config) {;_class28.prototype.__init62.call(this);_class28.prototype.__init63.call(this);_class28.prototype.__init64.call(this);
8493
8537
  this.store = config.store;
8494
8538
  this.queue = new RunQueue({ concurrency: _nullishCoalesce(config.concurrency, () => ( 1)) });
8495
8539
  this.runner = isRunExecutor(config.executor) ? config.executor : new EngineRunner(config.executor);
@@ -8556,7 +8600,7 @@ var RunManager = (_class28 = class {
8556
8600
  }
8557
8601
  const handle = this.executionHandles.get(runId);
8558
8602
  if (handle) {
8559
- if (run.status === "waiting_approval" && _optionalChain([input, 'optionalAccess', _249 => _249.approvalDecision])) {
8603
+ if (run.status === "waiting_approval" && _optionalChain([input, 'optionalAccess', _250 => _250.approvalDecision])) {
8560
8604
  const { approvalId, approved, reason } = input.approvalDecision;
8561
8605
  const approval = await this.store.getApproval(runId, approvalId);
8562
8606
  if (approval && approval.status === "pending") {
@@ -8575,7 +8619,7 @@ var RunManager = (_class28 = class {
8575
8619
  handle.resolveApproval(approved, reason);
8576
8620
  return;
8577
8621
  }
8578
- if (run.status === "waiting_input" && _optionalChain([input, 'optionalAccess', _250 => _250.userInput])) {
8622
+ if (run.status === "waiting_input" && _optionalChain([input, 'optionalAccess', _251 => _251.userInput])) {
8579
8623
  await this.transition(run, "queued");
8580
8624
  await this.transition(run, "running");
8581
8625
  await this.emitRunEvent(runId, "run_resumed", { userInput: input.userInput });
@@ -8583,7 +8627,7 @@ var RunManager = (_class28 = class {
8583
8627
  return;
8584
8628
  }
8585
8629
  }
8586
- if (_optionalChain([input, 'optionalAccess', _251 => _251.approvalDecision])) {
8630
+ if (_optionalChain([input, 'optionalAccess', _252 => _252.approvalDecision])) {
8587
8631
  const { approvalId, approved, reason } = input.approvalDecision;
8588
8632
  const approval = await this.store.getApproval(runId, approvalId);
8589
8633
  if (approval && approval.status === "pending") {
@@ -8599,7 +8643,7 @@ var RunManager = (_class28 = class {
8599
8643
  }
8600
8644
  await this.transition(run, "queued");
8601
8645
  await this.emitRunEvent(runId, "run_resumed", {
8602
- userInput: _optionalChain([input, 'optionalAccess', _252 => _252.userInput])
8646
+ userInput: _optionalChain([input, 'optionalAccess', _253 => _253.userInput])
8603
8647
  });
8604
8648
  this.queue.enqueue(runId);
8605
8649
  }
@@ -8812,7 +8856,7 @@ var RunManager = (_class28 = class {
8812
8856
  });
8813
8857
  }
8814
8858
  const engineSuccess = result.reason === "completed";
8815
- const evalFailed = _optionalChain([checkpoint, 'access', _253 => _253.evaluator, 'optionalAccess', _254 => _254.status]) === "failed";
8859
+ const evalFailed = _optionalChain([checkpoint, 'access', _254 => _254.evaluator, 'optionalAccess', _255 => _255.status]) === "failed";
8816
8860
  const isSuccess = engineSuccess && !evalFailed;
8817
8861
  current.summary = result.text.slice(0, 500);
8818
8862
  if (isSuccess) {
@@ -8826,7 +8870,7 @@ var RunManager = (_class28 = class {
8826
8870
  });
8827
8871
  _chunkIK4EWJBPcjs.logger.info("run.completed", { runId, turnCount: result.turnCount });
8828
8872
  } else {
8829
- current.error = evalFailed ? `Evaluator failed: ${_optionalChain([checkpoint, 'access', _255 => _255.evaluator, 'optionalAccess', _256 => _256.findings, 'access', _257 => _257.join, 'call', _258 => _258("; ")])}` : `Engine terminated: ${result.reason}`;
8873
+ current.error = evalFailed ? `Evaluator failed: ${_optionalChain([checkpoint, 'access', _256 => _256.evaluator, 'optionalAccess', _257 => _257.findings, 'access', _258 => _258.join, 'call', _259 => _259("; ")])}` : `Engine terminated: ${result.reason}`;
8830
8874
  await this.transition(current, "failed");
8831
8875
  current.finishedAt = Date.now();
8832
8876
  await this.store.update(current);