@cjhyy/code-shell 0.1.0-alpha.3 → 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 (157) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/dist/anthropic-IBTI4WL2.cjs +10 -0
  3. package/dist/anthropic-PRZZKHEZ.js +10 -0
  4. package/dist/arena/index.cjs +7 -6
  5. package/dist/arena/index.js +6 -5
  6. package/dist/arena/model-presets.d.ts +10 -1
  7. package/dist/{arena-ENHBHB2W.js → arena-2LTLIXOL.js} +9 -7
  8. package/dist/{arena-HHDYYVHJ.cjs → arena-ADB7DRFI.cjs} +25 -23
  9. package/dist/{chunk-EL2RL5DG.cjs → chunk-2YW4FPFG.cjs} +2 -2
  10. package/dist/chunk-3OA5G4TM.js +47 -0
  11. package/dist/{chunk-FPFTIKEJ.js → chunk-3QO25N6E.js} +131 -173
  12. package/dist/chunk-3SBSUOWZ.js +447 -0
  13. package/dist/chunk-52LGZKT3.cjs +47 -0
  14. package/dist/{chunk-KOGV6PDQ.cjs → chunk-55XGPMAP.cjs} +44 -9
  15. package/dist/{chunk-YD7XTI7T.cjs → chunk-6QVAYW7C.cjs} +116 -28
  16. package/dist/{chunk-SCDKLTN3.js → chunk-6S4BJ65N.js} +5 -4
  17. package/dist/{chunk-ZLPJJZUW.js → chunk-76HYEPDM.js} +2 -2
  18. package/dist/chunk-7BI3V74Y.cjs +447 -0
  19. package/dist/{chunk-GZBD6QRS.cjs → chunk-7EG3V4JY.cjs} +13 -12
  20. package/dist/{chunk-LMEKCQX4.js → chunk-7JVTYEEC.js} +6 -6
  21. package/dist/{chunk-SW3L7HIM.js → chunk-7QIM3BKD.js} +2 -2
  22. package/dist/{chunk-5C5HIOML.js → chunk-7Y6S3OCX.js} +109 -21
  23. package/dist/{chunk-REFCCVDM.js → chunk-ABRRONJ7.js} +2 -2
  24. package/dist/{chunk-F5BS3GUC.js → chunk-BSW22MPA.js} +39 -4
  25. package/dist/{chunk-ZRVPCXI7.js → chunk-BXCY2FSE.js} +2 -1
  26. package/dist/{chunk-Y7TSCDF6.js → chunk-BZ5TNE7L.js} +347 -6
  27. package/dist/{chunk-X2DNIMPC.cjs → chunk-DDB6QOKJ.cjs} +32 -32
  28. package/dist/{chunk-C7C7ZZY4.cjs → chunk-HEKQCI7B.cjs} +10 -10
  29. package/dist/{chunk-JHNCK7JP.cjs → chunk-IK4EWJBP.cjs} +4 -3
  30. package/dist/{chunk-3CAZIWUA.cjs → chunk-ILHE7XLT.cjs} +9 -9
  31. package/dist/{chunk-M2QI5X3X.cjs → chunk-JMR33QVF.cjs} +2 -2
  32. package/dist/{chunk-TDXBHD24.js → chunk-KAQHULYN.js} +2 -2
  33. package/dist/chunk-KE4EQOWA.js +294 -0
  34. package/dist/{chunk-YAFCN7ZW.cjs → chunk-KOVYSDHZ.cjs} +15 -15
  35. package/dist/{chunk-IJSHQGMP.cjs → chunk-KS3RYAYL.cjs} +4 -4
  36. package/dist/{chunk-DI7RDLOS.js → chunk-MD32R22I.js} +7 -4
  37. package/dist/chunk-MV7YI4WO.cjs +293 -0
  38. package/dist/chunk-MY5XHADU.cjs +216 -0
  39. package/dist/{chunk-OP57WUWQ.cjs → chunk-NUNC3VFB.cjs} +6 -6
  40. package/dist/{chunk-ID6EJUHP.js → chunk-PKGRTCCY.js} +1307 -212
  41. package/dist/{chunk-OUC2DFA7.js → chunk-QARL3IDQ.js} +3 -3
  42. package/dist/{chunk-VIPLU4RY.cjs → chunk-S754JHLR.cjs} +4 -4
  43. package/dist/{chunk-FUOKLKR2.js → chunk-SFXHZSRF.js} +1 -1
  44. package/dist/{chunk-2EUAE7AY.js → chunk-SIHHIQLO.js} +2 -2
  45. package/dist/{chunk-SK62UVS6.js → chunk-T6VYG46N.js} +1 -1
  46. package/dist/{chunk-JHXNOB5G.cjs → chunk-TNLGBJYS.cjs} +6 -6
  47. package/dist/{chunk-3QR52LL5.cjs → chunk-TUY2T5KP.cjs} +2 -2
  48. package/dist/{chunk-VWFET3MG.cjs → chunk-UXOCVJJ6.cjs} +1519 -424
  49. package/dist/{chunk-I57ZD5IQ.js → chunk-VIAGTYYW.js} +1 -1
  50. package/dist/chunk-WASS5YWB.js +215 -0
  51. package/dist/{chunk-HOXQLX5R.cjs → chunk-WZJV6DJC.cjs} +444 -103
  52. package/dist/{chunk-BUJ5KYCI.cjs → chunk-YIQBXAYU.cjs} +13 -13
  53. package/dist/{chunk-BF4LXLQV.cjs → chunk-YKIAELDZ.cjs} +132 -174
  54. package/dist/{chunk-M2SVOKC6.js → chunk-ZBPSQCPU.js} +6 -6
  55. package/dist/cli/commands/builtin/export-md.d.ts +19 -0
  56. package/dist/cli/commands/builtin/init/detect.d.ts +25 -0
  57. package/dist/cli/commands/builtin/init/index.d.ts +19 -0
  58. package/dist/cli/main.cjs +2372 -1453
  59. package/dist/cli/main.js +2502 -1583
  60. package/dist/cli/migrate-models.d.ts +45 -0
  61. package/dist/cli/onboarding.d.ts +110 -5
  62. package/dist/cli/updater.d.ts +59 -4
  63. package/dist/client-base-HTF236ZD.cjs +9 -0
  64. package/dist/client-base-QKRKCOWB.js +9 -0
  65. package/dist/{compaction-YNWCEF7B.js → compaction-6VU2T643.js} +4 -2
  66. package/dist/compaction-OKUNTCA7.cjs +33 -0
  67. package/dist/context/compaction.d.ts +35 -3
  68. package/dist/context/manager.d.ts +40 -3
  69. package/dist/context/tool-result-storage.d.ts +96 -0
  70. package/dist/devtools-T2NIZBJK.cjs +6 -0
  71. package/dist/{devtools-IRQQPIRY.js → devtools-YXWHOVKR.js} +1 -1
  72. package/dist/engine/engine.d.ts +47 -0
  73. package/dist/engine/turn-loop.d.ts +6 -0
  74. package/dist/export-md-RXDW6F5W.cjs +135 -0
  75. package/dist/export-md-XXKZANW5.js +135 -0
  76. package/dist/file-history-KYPE3ECT.cjs +7 -0
  77. package/dist/file-history-LF4F7X26.js +7 -0
  78. package/dist/index.cjs +42 -22
  79. package/dist/index.d.ts +5 -2
  80. package/dist/index.js +38 -18
  81. package/dist/llm/client-base.d.ts +1 -1
  82. package/dist/llm/model-cache.d.ts +21 -0
  83. package/dist/llm/model-fetcher.d.ts +29 -0
  84. package/dist/llm/model-pool.d.ts +13 -0
  85. package/dist/llm/provider-catalog.d.ts +30 -0
  86. package/dist/llm/provider-kinds.d.ts +21 -0
  87. package/dist/llm/types.d.ts +8 -0
  88. package/dist/logging/session-recorder.d.ts +77 -0
  89. package/dist/manager-D65VFAPX.js +7 -0
  90. package/dist/manager-TTF5VHJC.cjs +7 -0
  91. package/dist/mcp-manager-QMKWPBZ4.js +8 -0
  92. package/dist/mcp-manager-Z3OKI74O.cjs +8 -0
  93. package/dist/memory-5LWZ6FI2.cjs +9 -0
  94. package/dist/{memory-EPFDBPII.js → memory-VIJLBAMQ.js} +2 -2
  95. package/dist/model-cache-5KIYL5SL.js +13 -0
  96. package/dist/model-cache-OED3IM4R.cjs +13 -0
  97. package/dist/model-fetcher-HKGICACL.js +8 -0
  98. package/dist/model-fetcher-UR6WJOQP.cjs +8 -0
  99. package/dist/openai-JR2WEKOF.js +10 -0
  100. package/dist/openai-YBTOET4O.cjs +10 -0
  101. package/dist/{openrouter-models-2FM3H4SQ.js → openrouter-models-H56GHBHN.js} +2 -2
  102. package/dist/openrouter-models-TWUFWZ5T.cjs +15 -0
  103. package/dist/openrouter-sync-5VMGN6C2.cjs +11 -0
  104. package/dist/{openrouter-sync-SO3AWEAM.js → openrouter-sync-ALEMF5IU.js} +3 -3
  105. package/dist/product/index.cjs +17 -15
  106. package/dist/product/index.js +16 -14
  107. package/dist/protocol/server.d.ts +3 -1
  108. package/dist/protocol/types.d.ts +36 -2
  109. package/dist/run/index.cjs +17 -15
  110. package/dist/run/index.js +16 -14
  111. package/dist/services/index.d.ts +0 -1
  112. package/dist/session-manager-Q22BBMD3.js +8 -0
  113. package/dist/session-manager-XODQVL3C.cjs +8 -0
  114. package/dist/settings/schema.d.ts +267 -42
  115. package/dist/{tool-summary-RYNR4DDB.cjs → tool-summary-63DPIS7G.cjs} +4 -4
  116. package/dist/{tool-summary-2RUFL5QK.js → tool-summary-NP5CDBKG.js} +2 -2
  117. package/dist/tool-system/builtin/ask-user.d.ts +9 -1
  118. package/dist/tool-system/context.d.ts +31 -2
  119. package/dist/tool-system/executor.d.ts +4 -0
  120. package/dist/tool-system/investigation-guard.d.ts +46 -0
  121. package/dist/types.d.ts +13 -2
  122. package/dist/ui/components/AskUserPrompt.d.ts +8 -1
  123. package/dist/ui/components/DiffLine.d.ts +33 -0
  124. package/dist/ui/components/ModelManager.d.ts +34 -1
  125. package/dist/ui/components/OnboardingPrompt.d.ts +10 -1
  126. package/dist/ui/components/ProviderModelFlow.d.ts +58 -0
  127. package/dist/ui/components/UpdateBanner.d.ts +1 -0
  128. package/dist/updater-I7QBW4DP.cjs +17 -0
  129. package/dist/updater-NVME5S3Z.js +17 -0
  130. package/dist/utils/semver.d.ts +1 -0
  131. package/dist/utils/task-sanitizer.d.ts +6 -0
  132. package/package.json +2 -1
  133. package/skills-builtin/codeshell-help.md +135 -0
  134. package/dist/anthropic-P5VETAFI.cjs +0 -10
  135. package/dist/anthropic-W2GU3D76.js +0 -10
  136. package/dist/chunk-75E4BBFC.js +0 -224
  137. package/dist/chunk-FV2ARONZ.cjs +0 -224
  138. package/dist/client-base-TOVE25FA.js +0 -9
  139. package/dist/client-base-VDDIADAC.cjs +0 -9
  140. package/dist/compaction-D3KV2NWY.cjs +0 -31
  141. package/dist/devtools-WTC3NFNE.cjs +0 -6
  142. package/dist/file-history-HZWO2WQ5.js +0 -7
  143. package/dist/file-history-UQQILIY7.cjs +0 -7
  144. package/dist/manager-FWLOVEEK.cjs +0 -7
  145. package/dist/manager-GEXJLOIS.js +0 -7
  146. package/dist/mcp-manager-37GQLFGX.js +0 -8
  147. package/dist/mcp-manager-U77NEXBY.cjs +0 -8
  148. package/dist/memory-ADGOWADP.cjs +0 -9
  149. package/dist/openai-RXU5URYI.js +0 -10
  150. package/dist/openai-SQW4H2K4.cjs +0 -10
  151. package/dist/openrouter-models-PLCWZZYE.cjs +0 -15
  152. package/dist/openrouter-sync-K2WK3A2A.cjs +0 -11
  153. package/dist/services/compact.d.ts +0 -56
  154. package/dist/session-manager-HRSKENKB.cjs +0 -8
  155. package/dist/session-manager-NEKFEHF3.js +0 -8
  156. package/dist/updater-J7L7R6BY.cjs +0 -185
  157. package/dist/updater-LDBNYCAO.js +0 -185
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
4
 
5
- var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
5
+ var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
6
6
 
7
7
  // src/context/token-counter.ts
8
8
  function estimateStringTokens(text) {
@@ -48,10 +48,10 @@ function estimateBlockTokens(block) {
48
48
  return tokens;
49
49
  }
50
50
  var RATIOS;
51
- var init_token_counter = _chunkIJSHQGMPcjs.__esm.call(void 0, {
51
+ var init_token_counter = _chunkKS3RYAYLcjs.__esm.call(void 0, {
52
52
  "src/context/token-counter.ts"() {
53
53
  "use strict";
54
- _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
54
+ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
55
55
  RATIOS = {
56
56
  english: 4,
57
57
  // ~4 chars per token for English prose
@@ -69,7 +69,8 @@ var init_token_counter = _chunkIJSHQGMPcjs.__esm.call(void 0, {
69
69
 
70
70
  // src/context/compaction.ts
71
71
  var compaction_exports = {};
72
- _chunkIJSHQGMPcjs.__export.call(void 0, compaction_exports, {
72
+ _chunkKS3RYAYLcjs.__export.call(void 0, compaction_exports, {
73
+ COMPACTABLE_TOOL_NAMES: () => COMPACTABLE_TOOL_NAMES,
73
74
  adjustIndexToPreserveAPIInvariants: () => adjustIndexToPreserveAPIInvariants,
74
75
  applySummaryCompaction: () => applySummaryCompaction,
75
76
  applyToolResultBudget: () => applyToolResultBudget,
@@ -143,35 +144,108 @@ function windowCompact(messages, keepLastN) {
143
144
  if (startIndex <= 1) return messages;
144
145
  return [messages[0], ...messages.slice(startIndex)];
145
146
  }
146
- function microcompact(messages, keepRecentN = 3) {
147
- let toolResultCount = 0;
148
- const indices = [];
147
+ function buildToolUseIdToNameMap(messages) {
148
+ const map = /* @__PURE__ */ new Map();
149
+ for (const msg of messages) {
150
+ if (!Array.isArray(msg.content)) continue;
151
+ for (const block of msg.content) {
152
+ if (block.type === "tool_use" && block.id && block.name) {
153
+ map.set(block.id, block.name);
154
+ }
155
+ }
156
+ }
157
+ return map;
158
+ }
159
+ function summarizeToolCallArgs(toolName, input) {
160
+ if (!input || typeof input !== "object") return "";
161
+ const pick = (keys) => {
162
+ const parts = [];
163
+ for (const key of keys) {
164
+ const v = input[key];
165
+ if (typeof v === "string" && v.length > 0) {
166
+ parts.push(`${key}=${v.length > 80 ? v.slice(0, 77) + "..." : v}`);
167
+ }
168
+ }
169
+ return parts.join(" ");
170
+ };
171
+ switch (toolName) {
172
+ case "Read":
173
+ case "Write":
174
+ case "Edit":
175
+ case "NotebookEdit":
176
+ return pick(["file_path", "path", "notebook_path"]);
177
+ case "Glob":
178
+ case "Grep":
179
+ return pick(["pattern", "path", "glob"]);
180
+ case "Bash":
181
+ case "PowerShell":
182
+ case "REPL":
183
+ return pick(["command"]);
184
+ case "WebFetch":
185
+ case "WebSearch":
186
+ return pick(["url", "query"]);
187
+ default: {
188
+ const json = JSON.stringify(input);
189
+ return json.length > 100 ? json.slice(0, 97) + "..." : json;
190
+ }
191
+ }
192
+ }
193
+ function microcompact(messages, options = {}) {
194
+ const keepRecentN = _nullishCoalesce(options.keepRecentN, () => ( 5));
195
+ const compactable = _nullishCoalesce(options.compactableTools, () => ( COMPACTABLE_TOOL_NAMES));
196
+ const idToName = buildToolUseIdToNameMap(messages);
197
+ const idToInput = /* @__PURE__ */ new Map();
198
+ for (const msg of messages) {
199
+ if (!Array.isArray(msg.content)) continue;
200
+ for (const block of msg.content) {
201
+ if (block.type === "tool_use" && block.id) {
202
+ idToInput.set(block.id, block.input);
203
+ }
204
+ }
205
+ }
206
+ let compactableRoundCount = 0;
207
+ const indicesToTouch = [];
149
208
  for (let i = messages.length - 1; i >= 0; i--) {
150
209
  const msg = messages[i];
151
- if (Array.isArray(msg.content)) {
152
- const hasToolResult = msg.content.some((b) => b.type === "tool_result");
153
- if (hasToolResult) {
154
- toolResultCount++;
155
- if (toolResultCount > keepRecentN) {
156
- indices.push(i);
157
- }
158
- }
210
+ if (!Array.isArray(msg.content)) continue;
211
+ const hasEligible = msg.content.some(
212
+ (b) => b.type === "tool_result" && b.tool_use_id != null && compactable.has(_nullishCoalesce(idToName.get(b.tool_use_id), () => ( ""))) && typeof b.content === "string" && !b.content.startsWith("[Old tool result cleared")
213
+ );
214
+ if (!hasEligible) continue;
215
+ compactableRoundCount++;
216
+ if (compactableRoundCount > keepRecentN) {
217
+ indicesToTouch.push(i);
159
218
  }
160
219
  }
161
- if (indices.length === 0) return messages;
162
- return messages.map((msg, i) => {
163
- if (!indices.includes(i)) return msg;
164
- if (!Array.isArray(msg.content)) return msg;
220
+ if (indicesToTouch.length === 0) return messages;
221
+ const touchSet = new Set(indicesToTouch);
222
+ const clearedToolNames = /* @__PURE__ */ new Set();
223
+ let clearedBlocks = 0;
224
+ const result = messages.map((msg, i) => {
225
+ if (!touchSet.has(i) || !Array.isArray(msg.content)) return msg;
165
226
  return {
166
227
  ...msg,
167
228
  content: msg.content.map((block) => {
168
- if (block.type === "tool_result") {
169
- return { ...block, content: "[Old tool result content cleared]" };
170
- }
171
- return block;
229
+ if (block.type !== "tool_result" || !block.tool_use_id) return block;
230
+ const toolName = idToName.get(block.tool_use_id);
231
+ if (!toolName || !compactable.has(toolName)) return block;
232
+ if (typeof block.content !== "string") return block;
233
+ if (block.content.startsWith("[Old tool result cleared")) return block;
234
+ const argsSummary = summarizeToolCallArgs(toolName, idToInput.get(block.tool_use_id));
235
+ const fingerprint = argsSummary ? `[Old tool result cleared \u2014 ${toolName} ${argsSummary}]` : `[Old tool result cleared \u2014 ${toolName}]`;
236
+ clearedToolNames.add(toolName);
237
+ clearedBlocks++;
238
+ return { ...block, content: fingerprint };
172
239
  })
173
240
  };
174
241
  });
242
+ if (clearedBlocks > 0) {
243
+ _optionalChain([options, 'access', _ => _.onClear, 'optionalCall', _2 => _2({
244
+ clearedRounds: indicesToTouch.length,
245
+ toolNames: [...clearedToolNames].sort()
246
+ })]);
247
+ }
248
+ return result;
175
249
  }
176
250
  function applyToolResultBudget(messages, maxTotalChars = 1e5) {
177
251
  return messages.map((msg) => {
@@ -200,9 +274,10 @@ function applyToolResultBudget(messages, maxTotalChars = 1e5) {
200
274
  const newContent = msg.content.map((block, i) => {
201
275
  if (!toTruncate.has(i)) return block;
202
276
  const preview = typeof block.content === "string" ? block.content.slice(0, 500) : "";
277
+ const sizeKb = (block.content.length / 1e3).toFixed(0);
203
278
  return {
204
279
  ...block,
205
- content: `Output too large (${(block.content.length / 1e3).toFixed(0)}KB). Full output saved to session transcript. Use Read tool to view the source file if needed.
280
+ content: `Output too large (${sizeKb}KB) \u2014 truncated to fit the per-message budget. Re-run the originating tool if you need the full output.
206
281
 
207
282
  Preview (first 500 chars):
208
283
  ${preview}`
@@ -325,10 +400,22 @@ function extractReferencedFilePaths(messages) {
325
400
  }
326
401
  return [...paths];
327
402
  }
328
- var init_compaction = _chunkIJSHQGMPcjs.__esm.call(void 0, {
403
+ var COMPACTABLE_TOOL_NAMES;
404
+ var init_compaction = _chunkKS3RYAYLcjs.__esm.call(void 0, {
329
405
  "src/context/compaction.ts"() {
330
- _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
406
+ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
331
407
  init_token_counter();
408
+ COMPACTABLE_TOOL_NAMES = exports.COMPACTABLE_TOOL_NAMES = /* @__PURE__ */ new Set([
409
+ "Read",
410
+ "Glob",
411
+ "Grep",
412
+ "Bash",
413
+ "PowerShell",
414
+ "NotebookEdit",
415
+ "WebFetch",
416
+ "WebSearch",
417
+ "REPL"
418
+ ]);
332
419
  }
333
420
  });
334
421
 
@@ -347,4 +434,5 @@ var init_compaction = _chunkIJSHQGMPcjs.__esm.call(void 0, {
347
434
 
348
435
 
349
436
 
350
- exports.estimateTokens = estimateTokens; exports.adjustIndexToPreserveAPIInvariants = adjustIndexToPreserveAPIInvariants; exports.snipCompact = snipCompact; exports.windowCompact = windowCompact; exports.microcompact = microcompact; exports.applyToolResultBudget = applyToolResultBudget; exports.truncateToolResult = truncateToolResult; exports.buildSummarizationPrompt = buildSummarizationPrompt; exports.applySummaryCompaction = applySummaryCompaction; exports.groupMessagesByApiRound = groupMessagesByApiRound; exports.dropOldestRounds = dropOldestRounds; exports.extractReferencedFilePaths = extractReferencedFilePaths; exports.compaction_exports = compaction_exports; exports.init_compaction = init_compaction;
437
+
438
+ exports.estimateTokens = estimateTokens; exports.adjustIndexToPreserveAPIInvariants = adjustIndexToPreserveAPIInvariants; exports.snipCompact = snipCompact; exports.windowCompact = windowCompact; exports.COMPACTABLE_TOOL_NAMES = COMPACTABLE_TOOL_NAMES; exports.microcompact = microcompact; exports.applyToolResultBudget = applyToolResultBudget; exports.truncateToolResult = truncateToolResult; exports.buildSummarizationPrompt = buildSummarizationPrompt; exports.applySummaryCompaction = applySummaryCompaction; exports.groupMessagesByApiRound = groupMessagesByApiRound; exports.dropOldestRounds = dropOldestRounds; exports.extractReferencedFilePaths = extractReferencedFilePaths; exports.compaction_exports = compaction_exports; exports.init_compaction = init_compaction;
@@ -2,13 +2,13 @@ import {
2
2
  ContextLimitError,
3
3
  LLMError,
4
4
  LLMRateLimitError
5
- } from "./chunk-FUOKLKR2.js";
5
+ } from "./chunk-SFXHZSRF.js";
6
6
  import {
7
7
  logger
8
- } from "./chunk-ZRVPCXI7.js";
8
+ } from "./chunk-BXCY2FSE.js";
9
9
  import {
10
10
  init_esm_shims
11
- } from "./chunk-DI7RDLOS.js";
11
+ } from "./chunk-MD32R22I.js";
12
12
 
13
13
  // src/llm/client-base.ts
14
14
  init_esm_shims();
@@ -45,7 +45,8 @@ var LLMClientBase = class _LLMClientBase {
45
45
  totalTokens: 0,
46
46
  requestCount: 0
47
47
  };
48
- recordUsage(usage) {
48
+ recordUsage(usage, options) {
49
+ if (options?.recordUsage === false) return;
49
50
  this.usage.records.push(usage);
50
51
  this.usage.totalPromptTokens += usage.promptTokens;
51
52
  this.usage.totalCompletionTokens += usage.completionTokens;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  SessionError
3
- } from "./chunk-FUOKLKR2.js";
3
+ } from "./chunk-SFXHZSRF.js";
4
4
  import {
5
5
  init_esm_shims
6
- } from "./chunk-DI7RDLOS.js";
6
+ } from "./chunk-MD32R22I.js";
7
7
 
8
8
  // src/session/session-manager.ts
9
9
  init_esm_shims();
@@ -0,0 +1,447 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
+
3
+ var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
4
+
5
+ // src/settings/manager.ts
6
+ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _fs = require('fs');
15
+ var _path = require('path');
16
+ var _os = require('os');
17
+
18
+ // src/settings/schema.ts
19
+ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
20
+ var _zod = require('zod');
21
+ var SettingsSchema = _zod.z.object({
22
+ agent: _zod.z.object({
23
+ // Use z.string() instead of z.enum() to allow custom presets registered via registerPreset()
24
+ preset: _zod.z.string().default("terminal-coding"),
25
+ enabledBuiltinTools: _zod.z.array(_zod.z.string()).default([]),
26
+ disabledBuiltinTools: _zod.z.array(_zod.z.string()).default([]),
27
+ customSystemPrompt: _zod.z.string().optional(),
28
+ appendSystemPrompt: _zod.z.string().optional()
29
+ }).default({}),
30
+ /**
31
+ * Primary source of truth for the active model is settings.activeKey
32
+ * (points at models[].key). settings.model is a derived mirror of that
33
+ * entry kept in sync for legacy boot paths (cli/main.ts, repl.ts, etc.)
34
+ * which read provider/name/apiKey/baseUrl directly. Writers must update
35
+ * both — appendOnboardingResult does this in one shot.
36
+ */
37
+ activeKey: _zod.z.string().optional(),
38
+ /**
39
+ * Toggle background auto-update. When true (default), code-shell checks
40
+ * npm for newer versions and — if the npm global prefix is writable —
41
+ * installs the update in the background on process exit so the next
42
+ * launch picks it up.
43
+ * Can also be disabled via env var `DISABLE_AUTOUPDATER=1`.
44
+ */
45
+ autoUpdates: _zod.z.boolean().default(true),
46
+ model: _zod.z.object({
47
+ provider: _zod.z.string().default("openai"),
48
+ name: _zod.z.string().default("anthropic/claude-opus-4-6"),
49
+ apiKey: _zod.z.string().optional(),
50
+ baseUrl: _zod.z.string().default("https://openrouter.ai/api/v1"),
51
+ temperature: _zod.z.number().min(0).max(2).default(0.3),
52
+ maxTokens: _zod.z.number().default(8192)
53
+ }).default({}),
54
+ providers: _zod.z.array(
55
+ _zod.z.object({
56
+ key: _zod.z.string(),
57
+ label: _zod.z.string().optional(),
58
+ kind: _zod.z.enum([
59
+ "openai",
60
+ "anthropic",
61
+ "deepseek",
62
+ "xai",
63
+ "mistral",
64
+ "groq",
65
+ "google",
66
+ "openrouter",
67
+ "ollama",
68
+ "custom"
69
+ ]),
70
+ baseUrl: _zod.z.string(),
71
+ apiKey: _zod.z.string().optional(),
72
+ protocol: _zod.z.enum(["openai-compat", "anthropic-style"]).optional(),
73
+ modelsPath: _zod.z.string().optional()
74
+ })
75
+ ).default([]),
76
+ models: _zod.z.array(
77
+ _zod.z.object({
78
+ key: _zod.z.string(),
79
+ label: _zod.z.string().optional(),
80
+ providerKey: _zod.z.string().optional(),
81
+ model: _zod.z.string(),
82
+ maxOutputTokens: _zod.z.number().optional(),
83
+ maxContextTokens: _zod.z.number().optional(),
84
+ /**
85
+ * Which LLM client to use ("openai" or "anthropic"). New name —
86
+ * the legacy field is `provider`, which we still accept and
87
+ * fold into `protocol` below so old configs keep working.
88
+ * NOT the brand/vendor — that's providerKey above.
89
+ */
90
+ protocol: _zod.z.string().optional(),
91
+ provider: _zod.z.string().optional(),
92
+ baseUrl: _zod.z.string().optional(),
93
+ apiKey: _zod.z.string().optional()
94
+ }).transform((m) => {
95
+ const effective = _nullishCoalesce(m.protocol, () => ( m.provider));
96
+ return {
97
+ ...m,
98
+ protocol: effective,
99
+ provider: effective
100
+ };
101
+ })
102
+ ).default([]),
103
+ permissions: _zod.z.object({
104
+ defaultMode: _zod.z.enum(["default", "acceptEdits", "dontAsk", "bypassPermissions", "auto", "plan"]).default("default"),
105
+ rules: _zod.z.array(
106
+ _zod.z.object({
107
+ tool: _zod.z.string(),
108
+ argsPattern: _zod.z.record(_zod.z.string()).optional(),
109
+ decision: _zod.z.enum(["allow", "deny", "ask"]),
110
+ reason: _zod.z.string().optional()
111
+ })
112
+ ).default([])
113
+ }).default({}),
114
+ context: _zod.z.object({
115
+ maxTokens: _zod.z.number().default(2e5),
116
+ compactAtRatio: _zod.z.number().default(0.6),
117
+ summarizeAtRatio: _zod.z.number().default(0.8)
118
+ }).default({}),
119
+ session: _zod.z.object({
120
+ storageDir: _zod.z.string().optional(),
121
+ maxHistory: _zod.z.number().default(100)
122
+ }).default({}),
123
+ mcpServers: _zod.z.record(
124
+ _zod.z.object({
125
+ name: _zod.z.string(),
126
+ command: _zod.z.string().optional(),
127
+ args: _zod.z.array(_zod.z.string()).optional(),
128
+ env: _zod.z.record(_zod.z.string()).optional(),
129
+ url: _zod.z.string().optional(),
130
+ transport: _zod.z.enum(["stdio", "sse", "streamable-http", "inprocess"]).optional(),
131
+ headers: _zod.z.record(_zod.z.string()).optional()
132
+ })
133
+ ).default({}),
134
+ instructions: _zod.z.object({
135
+ fileName: _zod.z.string().default("CODESHELL.md"),
136
+ scanDirs: _zod.z.array(_zod.z.string()).default([]),
137
+ compatFileNames: _zod.z.array(_zod.z.string()).default(["CLAUDE.md", "AGENTS.md"]),
138
+ ignoreGitBoundary: _zod.z.boolean().default(false)
139
+ }).default({}),
140
+ arena: _zod.z.object({
141
+ participants: _zod.z.array(
142
+ _zod.z.union([
143
+ // Short form: just a model pool key
144
+ _zod.z.string(),
145
+ // Full form: explicit config (backward compat)
146
+ _zod.z.object({
147
+ name: _zod.z.string(),
148
+ model: _zod.z.string(),
149
+ provider: _zod.z.string().optional(),
150
+ apiKey: _zod.z.string().optional(),
151
+ baseUrl: _zod.z.string().optional()
152
+ })
153
+ ])
154
+ ).default([])
155
+ }).default({}),
156
+ search: _zod.z.object({
157
+ provider: _zod.z.enum(["serper", "tavily", "searxng"]).default("serper"),
158
+ apiKey: _zod.z.string().optional(),
159
+ baseUrl: _zod.z.string().optional()
160
+ }).default({}),
161
+ output: _zod.z.object({
162
+ format: _zod.z.enum(["text", "json", "jsonl", "stream-json"]).default("text")
163
+ }).default({})
164
+ }).passthrough();
165
+ function validateSettings(raw) {
166
+ return SettingsSchema.parse(raw);
167
+ }
168
+
169
+ // src/cli/migrate-models.ts
170
+ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
171
+ var BASEURL_KIND_PATTERNS = [
172
+ [/deepseek\.com/i, "deepseek"],
173
+ [/anthropic\.com/i, "anthropic"],
174
+ [/openai\.com/i, "openai"],
175
+ [/x\.ai/i, "xai"],
176
+ [/mistral\.ai/i, "mistral"],
177
+ [/groq\.com/i, "groq"],
178
+ [/generativelanguage\.googleapis/i, "google"],
179
+ [/openrouter\.ai/i, "openrouter"],
180
+ [/localhost:11434|127\.0\.0\.1:11434/i, "ollama"]
181
+ ];
182
+ function inferKind(baseUrl) {
183
+ if (!baseUrl) return "custom";
184
+ for (const [re, kind] of BASEURL_KIND_PATTERNS) {
185
+ if (re.test(baseUrl)) return kind;
186
+ }
187
+ return "custom";
188
+ }
189
+ function makeFingerprint(m) {
190
+ return `${_nullishCoalesce(m.provider, () => ( ""))}|${_nullishCoalesce(m.baseUrl, () => ( ""))}|${_nullishCoalesce(m.apiKey, () => ( ""))}`;
191
+ }
192
+ function deriveKey(base, used) {
193
+ if (!used.has(base)) return base;
194
+ for (let i = 2; ; i++) {
195
+ const candidate = `${base}-${i}`;
196
+ if (!used.has(candidate)) return candidate;
197
+ }
198
+ }
199
+ function deriveProviderModelKey(providerKind, modelId, used) {
200
+ const slash = modelId.lastIndexOf("/");
201
+ const base = slash >= 0 ? modelId.slice(slash + 1) : modelId;
202
+ const prefix = providerKind.toLowerCase();
203
+ const candidate = base.toLowerCase().startsWith(`${prefix}-`) ? base : `${prefix}-${base}`;
204
+ if (!used.has(candidate)) return candidate;
205
+ for (let i = 2; ; i++) {
206
+ const k = `${candidate}-${i}`;
207
+ if (!used.has(k)) return k;
208
+ }
209
+ }
210
+ function migrateModels(input) {
211
+ if (input.models.length === 0) {
212
+ return {
213
+ providers: input.providers,
214
+ models: [],
215
+ changed: false
216
+ };
217
+ }
218
+ const hasProvidersSection = input.providers.length > 0;
219
+ const keyCounts = /* @__PURE__ */ new Map();
220
+ for (const m of input.models) keyCounts.set(m.key, (_nullishCoalesce(keyCounts.get(m.key), () => ( 0))) + 1);
221
+ const needsMigration = input.models.some(
222
+ (m) => !m.providerKey || (_nullishCoalesce(keyCounts.get(m.key), () => ( 0))) > 1
223
+ );
224
+ if (!needsMigration) {
225
+ return {
226
+ providers: input.providers,
227
+ models: input.models.map((m) => ({
228
+ key: m.key,
229
+ label: m.label,
230
+ providerKey: _nullishCoalesce(m.providerKey, () => ( "")),
231
+ model: m.model,
232
+ maxOutputTokens: m.maxOutputTokens,
233
+ maxContextTokens: m.maxContextTokens,
234
+ provider: m.provider,
235
+ baseUrl: m.baseUrl,
236
+ apiKey: m.apiKey
237
+ })),
238
+ changed: false
239
+ };
240
+ }
241
+ const fingerprintToKey = /* @__PURE__ */ new Map();
242
+ const newProviders = [];
243
+ const usedProviderKeys = new Set(input.providers.map((p) => p.key));
244
+ for (const p of input.providers) {
245
+ const fp = `${""}|${p.baseUrl}|${_nullishCoalesce(p.apiKey, () => ( ""))}`;
246
+ fingerprintToKey.set(fp, p.key);
247
+ }
248
+ for (const m of input.models) {
249
+ const fp = makeFingerprint(m);
250
+ const existingByUrl = input.providers.find((p) => p.baseUrl === (_nullishCoalesce(m.baseUrl, () => ( ""))));
251
+ if (existingByUrl) {
252
+ fingerprintToKey.set(fp, existingByUrl.key);
253
+ continue;
254
+ }
255
+ if (fingerprintToKey.has(fp)) continue;
256
+ const kind = inferKind(m.baseUrl);
257
+ const key = deriveKey(kind, usedProviderKeys);
258
+ usedProviderKeys.add(key);
259
+ fingerprintToKey.set(fp, key);
260
+ newProviders.push({
261
+ key,
262
+ kind,
263
+ baseUrl: _nullishCoalesce(m.baseUrl, () => ( "")),
264
+ apiKey: m.apiKey
265
+ });
266
+ }
267
+ const usedModelKeys = /* @__PURE__ */ new Set();
268
+ const newModels = input.models.map((m) => {
269
+ const providerKey = fingerprintToKey.get(makeFingerprint(m));
270
+ const collides = (_nullishCoalesce(keyCounts.get(m.key), () => ( 0))) > 1;
271
+ let key = m.key;
272
+ if (collides) {
273
+ const kind = inferKind(m.baseUrl);
274
+ key = deriveProviderModelKey(kind, m.model, usedModelKeys);
275
+ }
276
+ if (usedModelKeys.has(key)) {
277
+ const kind = inferKind(m.baseUrl);
278
+ key = deriveProviderModelKey(kind, m.model, usedModelKeys);
279
+ }
280
+ usedModelKeys.add(key);
281
+ return {
282
+ key,
283
+ label: m.label,
284
+ providerKey,
285
+ provider: m.provider,
286
+ model: m.model,
287
+ baseUrl: m.baseUrl,
288
+ apiKey: m.apiKey,
289
+ maxOutputTokens: m.maxOutputTokens,
290
+ maxContextTokens: m.maxContextTokens
291
+ };
292
+ });
293
+ const seen = /* @__PURE__ */ new Set();
294
+ const deduped = newModels.filter((m) => {
295
+ const fp = `${m.key}|${m.model}`;
296
+ if (seen.has(fp)) return false;
297
+ seen.add(fp);
298
+ return true;
299
+ });
300
+ return {
301
+ providers: hasProvidersSection ? [...input.providers, ...newProviders] : newProviders,
302
+ models: deduped,
303
+ changed: true
304
+ };
305
+ }
306
+
307
+ // src/settings/manager.ts
308
+ function userHome() {
309
+ return _nullishCoalesce(process.env.HOME, () => ( _os.homedir.call(void 0, )));
310
+ }
311
+ var SettingsManager = (_class = class {
312
+ constructor(cwd = process.cwd()) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
313
+ this.cwd = cwd;
314
+ }
315
+ __init() {this.sources = []}
316
+ __init2() {this.merged = null}
317
+ /**
318
+ * Load settings from all sources.
319
+ */
320
+ load(flagOverrides) {
321
+ this.sources = [];
322
+ this.loadJsonFile(_path.join.call(void 0, userHome(), ".code-shell", "settings.managed.json"), "managed", 0);
323
+ this.loadJsonFile(_path.join.call(void 0, userHome(), ".code-shell", "settings.json"), "user", 1);
324
+ this.loadJsonFile(_path.join.call(void 0, this.cwd, ".code-shell", "settings.json"), "project", 2);
325
+ this.loadJsonFile(_path.join.call(void 0, this.cwd, ".code-shell", "settings.local.json"), "local", 3);
326
+ if (flagOverrides && Object.keys(flagOverrides).length > 0) {
327
+ this.sources.push({ name: "flag", priority: 4, data: flagOverrides });
328
+ }
329
+ this.sources.sort((a, b) => a.priority - b.priority);
330
+ const raw = this.deepMerge();
331
+ const userPath = _path.join.call(void 0, userHome(), ".code-shell", "settings.json");
332
+ if (_fs.existsSync.call(void 0, userPath)) {
333
+ try {
334
+ const userRaw = JSON.parse(_fs.readFileSync.call(void 0, userPath, "utf-8"));
335
+ const result = migrateModels({
336
+ providers: _nullishCoalesce(userRaw.providers, () => ( [])),
337
+ models: _nullishCoalesce(userRaw.models, () => ( []))
338
+ });
339
+ if (result.changed) {
340
+ _fs.copyFileSync.call(void 0, userPath, `${userPath}.bak`);
341
+ const migrated = {
342
+ ...userRaw,
343
+ providers: result.providers,
344
+ models: result.models
345
+ };
346
+ _fs.writeFileSync.call(void 0, userPath, JSON.stringify(migrated, null, 2), "utf-8");
347
+ const userSource = this.sources.find((s) => s.name === "user");
348
+ if (userSource) userSource.data = migrated;
349
+ const remerged = this.deepMerge();
350
+ this.merged = validateSettings(remerged);
351
+ return this.merged;
352
+ }
353
+ } catch (e) {
354
+ }
355
+ }
356
+ this.merged = validateSettings(raw);
357
+ return this.merged;
358
+ }
359
+ /**
360
+ * Get current effective settings.
361
+ */
362
+ get() {
363
+ if (!this.merged) return this.load();
364
+ return this.merged;
365
+ }
366
+ /**
367
+ * Invalidate cached merge.
368
+ */
369
+ invalidate() {
370
+ this.merged = null;
371
+ }
372
+ /**
373
+ * Persist a single setting (dotted key path) to the user-level config file
374
+ * at ~/.code-shell/settings.json. Other sources (project / local /
375
+ * managed) are intentionally untouched: writing back to project/local
376
+ * would surprise version control, and managed is read-only.
377
+ *
378
+ * The merged cache is invalidated so the next get() picks up the change.
379
+ */
380
+ saveUserSetting(key, value) {
381
+ const path = _path.join.call(void 0, userHome(), ".code-shell", "settings.json");
382
+ let current = {};
383
+ if (_fs.existsSync.call(void 0, path)) {
384
+ try {
385
+ const raw = _fs.readFileSync.call(void 0, path, "utf-8");
386
+ const parsed = JSON.parse(raw);
387
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
388
+ current = parsed;
389
+ }
390
+ } catch (e2) {
391
+ }
392
+ }
393
+ const parts = key.split(".");
394
+ let target = current;
395
+ for (let i = 0; i < parts.length - 1; i++) {
396
+ const seg = parts[i];
397
+ const next = target[seg];
398
+ if (!next || typeof next !== "object" || Array.isArray(next)) {
399
+ target[seg] = {};
400
+ }
401
+ target = target[seg];
402
+ }
403
+ target[parts[parts.length - 1]] = value;
404
+ _fs.mkdirSync.call(void 0, _path.dirname.call(void 0, path), { recursive: true });
405
+ const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
406
+ _fs.writeFileSync.call(void 0, tmp, JSON.stringify(current, null, 2), "utf-8");
407
+ _fs.renameSync.call(void 0, tmp, path);
408
+ this.invalidate();
409
+ }
410
+ loadJsonFile(path, name, priority) {
411
+ if (!_fs.existsSync.call(void 0, path)) return;
412
+ try {
413
+ const content = _fs.readFileSync.call(void 0, path, "utf-8");
414
+ const data = JSON.parse(content);
415
+ if (typeof data === "object" && data !== null) {
416
+ this.sources.push({ name, priority, data });
417
+ }
418
+ } catch (e3) {
419
+ }
420
+ }
421
+ deepMerge() {
422
+ let result = {};
423
+ for (const source of this.sources) {
424
+ result = merge(result, source.data);
425
+ }
426
+ return result;
427
+ }
428
+ }, _class);
429
+ function merge(base, override) {
430
+ const result = { ...base };
431
+ for (const [key, value] of Object.entries(override)) {
432
+ if (value === null) {
433
+ delete result[key];
434
+ } else if (typeof value === "object" && !Array.isArray(value) && typeof result[key] === "object" && !Array.isArray(result[key]) && result[key] !== null) {
435
+ result[key] = merge(result[key], value);
436
+ } else {
437
+ result[key] = value;
438
+ }
439
+ }
440
+ return result;
441
+ }
442
+
443
+
444
+
445
+
446
+
447
+ exports.SettingsSchema = SettingsSchema; exports.validateSettings = validateSettings; exports.SettingsManager = SettingsManager;