@cjhyy/code-shell 0.1.6 → 0.1.7

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 (154) hide show
  1. package/dist/anthropic-UBSB5AQH.js +1 -0
  2. package/dist/arena/index.js +1 -104
  3. package/dist/arena-OW55ZCHT.js +3 -0
  4. package/dist/bwrap-PVZMLHZR.js +2 -0
  5. package/dist/chunk-2NS3JMNK.js +1 -0
  6. package/dist/chunk-3QP5BQ3L.js +1 -0
  7. package/dist/chunk-B7K2OWKC.js +2 -0
  8. package/dist/chunk-EWWK56K6.js +2 -0
  9. package/dist/chunk-FU7AHZNN.js +1 -0
  10. package/dist/chunk-HIJ2XXGX.js +1 -0
  11. package/dist/chunk-KCXSARAA.js +1 -0
  12. package/dist/chunk-NFH3UQ3E.js +2 -0
  13. package/dist/chunk-NMBYBGC7.js +250 -0
  14. package/dist/chunk-NVAZJ5XS.js +2 -0
  15. package/dist/chunk-O5HFCH2U.js +1 -0
  16. package/dist/chunk-P6JSTIFM.js +1 -0
  17. package/dist/chunk-PGANL6F2.js +3 -0
  18. package/dist/chunk-Q4O2HGWS.js +251 -0
  19. package/dist/chunk-QTWU7UNA.js +5 -0
  20. package/dist/chunk-RP26WO4R.js +1 -0
  21. package/dist/chunk-SNFAPSLA.js +1 -0
  22. package/dist/chunk-T222K6IV.js +18 -0
  23. package/dist/chunk-TKJA6W36.js +3 -0
  24. package/dist/chunk-UDPUTFQT.js +2 -0
  25. package/dist/chunk-W47Z7MGS.js +33 -0
  26. package/dist/chunk-WI6FSWGU.js +1 -0
  27. package/dist/chunk-WOP6MJKW.js +1 -0
  28. package/dist/chunk-XDOWC7EG.js +4 -0
  29. package/dist/chunk-Y2NS6HPO.js +641 -0
  30. package/dist/cli/main.js +303 -22060
  31. package/dist/client-base-6ZZJJYDY.js +1 -0
  32. package/dist/compaction-ECVQVOCT.js +1 -0
  33. package/dist/devtools-SGDUOOM4.js +1 -0
  34. package/dist/engine/engine.d.ts +8 -0
  35. package/dist/export-md-U72T7NW7.js +22 -0
  36. package/dist/file-history-7FQFEQOL.js +1 -0
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +1 -347
  39. package/dist/llm/token-counter.d.ts +17 -0
  40. package/dist/manager-C3TDN6MS.js +1 -0
  41. package/dist/mcp-manager-OP4XYV53.js +1 -0
  42. package/dist/memory-BNI4WEWL.js +1 -0
  43. package/dist/model-cache-HEDXI7UJ.js +1 -0
  44. package/dist/model-fetcher-BJ64META.js +1 -0
  45. package/dist/off-7SDVMMXW.js +1 -0
  46. package/dist/openai-KEWQ54TM.js +1 -0
  47. package/dist/openrouter-models-AM6M52D6.js +1 -0
  48. package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
  49. package/dist/product/index.js +1 -21
  50. package/dist/run/index.js +1 -48
  51. package/dist/seatbelt-WBYROQT6.js +37 -0
  52. package/dist/session/session-manager.d.ts +2 -0
  53. package/dist/session-manager-AGWS5SMJ.js +1 -0
  54. package/dist/settings/schema.d.ts +72 -6
  55. package/dist/tool-summary-5UE62VU4.js +2 -0
  56. package/dist/tool-system/builtin/bash.d.ts +7 -1
  57. package/dist/tool-system/context.d.ts +7 -0
  58. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  59. package/dist/tool-system/sandbox/index.d.ts +71 -0
  60. package/dist/tool-system/sandbox/off.d.ts +2 -0
  61. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  62. package/dist/types.d.ts +4 -0
  63. package/dist/ui/components/SessionPicker.d.ts +2 -0
  64. package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
  65. package/dist/ui/components/StatusLine.d.ts +2 -2
  66. package/dist/updater-OCNU2K2Z.js +1 -0
  67. package/package.json +7 -10
  68. package/dist/anthropic-IBTI4WL2.cjs +0 -10
  69. package/dist/anthropic-PRZZKHEZ.js +0 -10
  70. package/dist/arena/index.cjs +0 -104
  71. package/dist/arena-2LTLIXOL.js +0 -261
  72. package/dist/arena-ADB7DRFI.cjs +0 -261
  73. package/dist/chunk-2YW4FPFG.cjs +0 -101
  74. package/dist/chunk-3OA5G4TM.js +0 -47
  75. package/dist/chunk-3QO25N6E.js +0 -4711
  76. package/dist/chunk-3SBSUOWZ.js +0 -447
  77. package/dist/chunk-52LGZKT3.cjs +0 -47
  78. package/dist/chunk-55XGPMAP.cjs +0 -146
  79. package/dist/chunk-6QVAYW7C.cjs +0 -438
  80. package/dist/chunk-6S4BJ65N.js +0 -113
  81. package/dist/chunk-76HYEPDM.js +0 -307
  82. package/dist/chunk-7BI3V74Y.cjs +0 -447
  83. package/dist/chunk-7EG3V4JY.cjs +0 -113
  84. package/dist/chunk-7JVTYEEC.js +0 -340
  85. package/dist/chunk-7QIM3BKD.js +0 -44
  86. package/dist/chunk-7Y6S3OCX.js +0 -438
  87. package/dist/chunk-ABRRONJ7.js +0 -107
  88. package/dist/chunk-BSW22MPA.js +0 -146
  89. package/dist/chunk-BXCY2FSE.js +0 -203
  90. package/dist/chunk-BZ5TNE7L.js +0 -5128
  91. package/dist/chunk-DDB6QOKJ.cjs +0 -1252
  92. package/dist/chunk-HEKQCI7B.cjs +0 -224
  93. package/dist/chunk-IK4EWJBP.cjs +0 -203
  94. package/dist/chunk-ILHE7XLT.cjs +0 -107
  95. package/dist/chunk-JMR33QVF.cjs +0 -169
  96. package/dist/chunk-KAQHULYN.js +0 -54
  97. package/dist/chunk-KE4EQOWA.js +0 -294
  98. package/dist/chunk-KOVYSDHZ.cjs +0 -340
  99. package/dist/chunk-KS3RYAYL.cjs +0 -45
  100. package/dist/chunk-MD32R22I.js +0 -50
  101. package/dist/chunk-MV7YI4WO.cjs +0 -293
  102. package/dist/chunk-MY5XHADU.cjs +0 -216
  103. package/dist/chunk-NUNC3VFB.cjs +0 -307
  104. package/dist/chunk-PKGRTCCY.js +0 -9092
  105. package/dist/chunk-QARL3IDQ.js +0 -1252
  106. package/dist/chunk-S754JHLR.cjs +0 -54
  107. package/dist/chunk-SFXHZSRF.js +0 -101
  108. package/dist/chunk-SIHHIQLO.js +0 -224
  109. package/dist/chunk-T6VYG46N.js +0 -105
  110. package/dist/chunk-TNLGBJYS.cjs +0 -44
  111. package/dist/chunk-TUY2T5KP.cjs +0 -105
  112. package/dist/chunk-UXOCVJJ6.cjs +0 -9092
  113. package/dist/chunk-VIAGTYYW.js +0 -169
  114. package/dist/chunk-WASS5YWB.js +0 -215
  115. package/dist/chunk-WZJV6DJC.cjs +0 -5128
  116. package/dist/chunk-YIQBXAYU.cjs +0 -264
  117. package/dist/chunk-YKIAELDZ.cjs +0 -4711
  118. package/dist/chunk-ZBPSQCPU.js +0 -264
  119. package/dist/cli/main.cjs +0 -22156
  120. package/dist/client-base-HTF236ZD.cjs +0 -9
  121. package/dist/client-base-QKRKCOWB.js +0 -9
  122. package/dist/compaction-6VU2T643.js +0 -33
  123. package/dist/compaction-OKUNTCA7.cjs +0 -33
  124. package/dist/devtools-T2NIZBJK.cjs +0 -6
  125. package/dist/devtools-YXWHOVKR.js +0 -6
  126. package/dist/export-md-RXDW6F5W.cjs +0 -135
  127. package/dist/export-md-XXKZANW5.js +0 -135
  128. package/dist/file-history-KYPE3ECT.cjs +0 -7
  129. package/dist/file-history-LF4F7X26.js +0 -7
  130. package/dist/index.cjs +0 -347
  131. package/dist/manager-D65VFAPX.js +0 -7
  132. package/dist/manager-TTF5VHJC.cjs +0 -7
  133. package/dist/mcp-manager-QMKWPBZ4.js +0 -8
  134. package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
  135. package/dist/memory-5LWZ6FI2.cjs +0 -9
  136. package/dist/memory-VIJLBAMQ.js +0 -9
  137. package/dist/model-cache-5KIYL5SL.js +0 -13
  138. package/dist/model-cache-OED3IM4R.cjs +0 -13
  139. package/dist/model-fetcher-HKGICACL.js +0 -8
  140. package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
  141. package/dist/openai-JR2WEKOF.js +0 -10
  142. package/dist/openai-YBTOET4O.cjs +0 -10
  143. package/dist/openrouter-models-H56GHBHN.js +0 -15
  144. package/dist/openrouter-models-TWUFWZ5T.cjs +0 -15
  145. package/dist/openrouter-sync-5VMGN6C2.cjs +0 -11
  146. package/dist/openrouter-sync-ALEMF5IU.js +0 -11
  147. package/dist/product/index.cjs +0 -21
  148. package/dist/run/index.cjs +0 -48
  149. package/dist/session-manager-Q22BBMD3.js +0 -8
  150. package/dist/session-manager-XODQVL3C.cjs +0 -8
  151. package/dist/tool-summary-63DPIS7G.cjs +0 -31
  152. package/dist/tool-summary-NP5CDBKG.js +0 -31
  153. package/dist/updater-I7QBW4DP.cjs +0 -17
  154. package/dist/updater-NVME5S3Z.js +0 -17
@@ -1,447 +0,0 @@
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;
@@ -1,113 +0,0 @@
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; } var _class;
2
-
3
-
4
-
5
- var _chunk2YW4FPFGcjs = require('./chunk-2YW4FPFG.cjs');
6
-
7
-
8
- var _chunkIK4EWJBPcjs = require('./chunk-IK4EWJBP.cjs');
9
-
10
-
11
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
12
-
13
- // src/llm/client-base.ts
14
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
15
- var LLMClientBase = (_class = class _LLMClientBase {
16
- constructor(config) {;_class.prototype.__init.call(this);
17
- this.config = config;
18
- this.provider = config.provider;
19
- this.model = config.model;
20
- this.temperature = _nullishCoalesce(config.temperature, () => ( 0.3));
21
- this.maxTokens = _nullishCoalesce(config.maxTokens, () => ( 8192));
22
- this.timeout = _nullishCoalesce(config.timeout, () => ( 12e4));
23
- this.retryMaxAttempts = _nullishCoalesce(config.retryMaxAttempts, () => ( 3));
24
- this.enableStreaming = _nullishCoalesce(config.enableStreaming, () => ( true));
25
- this.initClient();
26
- }
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
- /**
35
- * Process-wide hook fired on every LLM response. The CLI installs this in
36
- * main.ts to feed the cost tracker; lives on the base class so every code
37
- * path (REPL, run, arena, sub-agents) reports through one funnel without
38
- * each call site needing to remember.
39
- */
40
-
41
- __init() {this.usage = {
42
- records: [],
43
- totalPromptTokens: 0,
44
- totalCompletionTokens: 0,
45
- totalTokens: 0,
46
- requestCount: 0
47
- }}
48
- recordUsage(usage, options) {
49
- if (_optionalChain([options, 'optionalAccess', _ => _.recordUsage]) === false) return;
50
- this.usage.records.push(usage);
51
- this.usage.totalPromptTokens += usage.promptTokens;
52
- this.usage.totalCompletionTokens += usage.completionTokens;
53
- this.usage.totalTokens += usage.totalTokens;
54
- this.usage.requestCount++;
55
- _optionalChain([_LLMClientBase, 'access', _2 => _2.onUsage, 'optionalCall', _3 => _3(this.model, usage)]);
56
- }
57
- getUsage() {
58
- return { ...this.usage };
59
- }
60
- async withRetry(fn, maxAttempts) {
61
- const attempts = _nullishCoalesce(maxAttempts, () => ( this.retryMaxAttempts));
62
- let lastError;
63
- for (let attempt = 1; attempt <= attempts; attempt++) {
64
- try {
65
- return await fn();
66
- } catch (err) {
67
- lastError = err;
68
- if (err instanceof _chunk2YW4FPFGcjs.ContextLimitError) throw err;
69
- if (err instanceof _chunk2YW4FPFGcjs.LLMRateLimitError) {
70
- const waitMs = (_nullishCoalesce(err.retryAfter, () => ( attempt * 2))) * 1e3;
71
- _chunkIK4EWJBPcjs.logger.warn("llm.retry", {
72
- cat: "llm",
73
- provider: this.provider,
74
- model: this.model,
75
- attempt,
76
- of: attempts,
77
- reason: "rate_limit",
78
- waitMs
79
- });
80
- await new Promise((r) => setTimeout(r, waitMs));
81
- continue;
82
- }
83
- if (attempt === attempts) {
84
- _chunkIK4EWJBPcjs.logger.error("llm.exhausted", {
85
- cat: "llm",
86
- provider: this.provider,
87
- model: this.model,
88
- attempts,
89
- error: err.message
90
- });
91
- break;
92
- }
93
- const backoff = Math.min(1e3 * Math.pow(2, attempt - 1), 3e4);
94
- _chunkIK4EWJBPcjs.logger.warn("llm.retry", {
95
- cat: "llm",
96
- provider: this.provider,
97
- model: this.model,
98
- attempt,
99
- of: attempts,
100
- reason: "error",
101
- error: err.message,
102
- backoffMs: backoff
103
- });
104
- await new Promise((r) => setTimeout(r, backoff));
105
- }
106
- }
107
- throw _nullishCoalesce(lastError, () => ( new (0, _chunk2YW4FPFGcjs.LLMError)("Unknown LLM error")));
108
- }
109
- }, _class);
110
-
111
-
112
-
113
- exports.LLMClientBase = LLMClientBase;