@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
- import {
2
- init_esm_shims
3
- } from "./chunk-MD32R22I.js";
4
-
5
- // src/settings/manager.ts
6
- init_esm_shims();
7
- import {
8
- readFileSync,
9
- existsSync,
10
- mkdirSync,
11
- writeFileSync,
12
- renameSync,
13
- copyFileSync
14
- } from "fs";
15
- import { join, dirname } from "path";
16
- import { homedir } from "os";
17
-
18
- // src/settings/schema.ts
19
- init_esm_shims();
20
- import { z } from "zod";
21
- var SettingsSchema = z.object({
22
- agent: z.object({
23
- // Use z.string() instead of z.enum() to allow custom presets registered via registerPreset()
24
- preset: z.string().default("terminal-coding"),
25
- enabledBuiltinTools: z.array(z.string()).default([]),
26
- disabledBuiltinTools: z.array(z.string()).default([]),
27
- customSystemPrompt: z.string().optional(),
28
- appendSystemPrompt: 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: 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: z.boolean().default(true),
46
- model: z.object({
47
- provider: z.string().default("openai"),
48
- name: z.string().default("anthropic/claude-opus-4-6"),
49
- apiKey: z.string().optional(),
50
- baseUrl: z.string().default("https://openrouter.ai/api/v1"),
51
- temperature: z.number().min(0).max(2).default(0.3),
52
- maxTokens: z.number().default(8192)
53
- }).default({}),
54
- providers: z.array(
55
- z.object({
56
- key: z.string(),
57
- label: z.string().optional(),
58
- kind: 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: z.string(),
71
- apiKey: z.string().optional(),
72
- protocol: z.enum(["openai-compat", "anthropic-style"]).optional(),
73
- modelsPath: z.string().optional()
74
- })
75
- ).default([]),
76
- models: z.array(
77
- z.object({
78
- key: z.string(),
79
- label: z.string().optional(),
80
- providerKey: z.string().optional(),
81
- model: z.string(),
82
- maxOutputTokens: z.number().optional(),
83
- maxContextTokens: 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: z.string().optional(),
91
- provider: z.string().optional(),
92
- baseUrl: z.string().optional(),
93
- apiKey: z.string().optional()
94
- }).transform((m) => {
95
- const effective = m.protocol ?? m.provider;
96
- return {
97
- ...m,
98
- protocol: effective,
99
- provider: effective
100
- };
101
- })
102
- ).default([]),
103
- permissions: z.object({
104
- defaultMode: z.enum(["default", "acceptEdits", "dontAsk", "bypassPermissions", "auto", "plan"]).default("default"),
105
- rules: z.array(
106
- z.object({
107
- tool: z.string(),
108
- argsPattern: z.record(z.string()).optional(),
109
- decision: z.enum(["allow", "deny", "ask"]),
110
- reason: z.string().optional()
111
- })
112
- ).default([])
113
- }).default({}),
114
- context: z.object({
115
- maxTokens: z.number().default(2e5),
116
- compactAtRatio: z.number().default(0.6),
117
- summarizeAtRatio: z.number().default(0.8)
118
- }).default({}),
119
- session: z.object({
120
- storageDir: z.string().optional(),
121
- maxHistory: z.number().default(100)
122
- }).default({}),
123
- mcpServers: z.record(
124
- z.object({
125
- name: z.string(),
126
- command: z.string().optional(),
127
- args: z.array(z.string()).optional(),
128
- env: z.record(z.string()).optional(),
129
- url: z.string().optional(),
130
- transport: z.enum(["stdio", "sse", "streamable-http", "inprocess"]).optional(),
131
- headers: z.record(z.string()).optional()
132
- })
133
- ).default({}),
134
- instructions: z.object({
135
- fileName: z.string().default("CODESHELL.md"),
136
- scanDirs: z.array(z.string()).default([]),
137
- compatFileNames: z.array(z.string()).default(["CLAUDE.md", "AGENTS.md"]),
138
- ignoreGitBoundary: z.boolean().default(false)
139
- }).default({}),
140
- arena: z.object({
141
- participants: z.array(
142
- z.union([
143
- // Short form: just a model pool key
144
- z.string(),
145
- // Full form: explicit config (backward compat)
146
- z.object({
147
- name: z.string(),
148
- model: z.string(),
149
- provider: z.string().optional(),
150
- apiKey: z.string().optional(),
151
- baseUrl: z.string().optional()
152
- })
153
- ])
154
- ).default([])
155
- }).default({}),
156
- search: z.object({
157
- provider: z.enum(["serper", "tavily", "searxng"]).default("serper"),
158
- apiKey: z.string().optional(),
159
- baseUrl: z.string().optional()
160
- }).default({}),
161
- output: z.object({
162
- format: 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
- init_esm_shims();
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 `${m.provider ?? ""}|${m.baseUrl ?? ""}|${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, (keyCounts.get(m.key) ?? 0) + 1);
221
- const needsMigration = input.models.some(
222
- (m) => !m.providerKey || (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: 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}|${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 === (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: 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 = (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 process.env.HOME ?? homedir();
310
- }
311
- var SettingsManager = class {
312
- constructor(cwd = process.cwd()) {
313
- this.cwd = cwd;
314
- }
315
- sources = [];
316
- merged = null;
317
- /**
318
- * Load settings from all sources.
319
- */
320
- load(flagOverrides) {
321
- this.sources = [];
322
- this.loadJsonFile(join(userHome(), ".code-shell", "settings.managed.json"), "managed", 0);
323
- this.loadJsonFile(join(userHome(), ".code-shell", "settings.json"), "user", 1);
324
- this.loadJsonFile(join(this.cwd, ".code-shell", "settings.json"), "project", 2);
325
- this.loadJsonFile(join(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 = join(userHome(), ".code-shell", "settings.json");
332
- if (existsSync(userPath)) {
333
- try {
334
- const userRaw = JSON.parse(readFileSync(userPath, "utf-8"));
335
- const result = migrateModels({
336
- providers: userRaw.providers ?? [],
337
- models: userRaw.models ?? []
338
- });
339
- if (result.changed) {
340
- copyFileSync(userPath, `${userPath}.bak`);
341
- const migrated = {
342
- ...userRaw,
343
- providers: result.providers,
344
- models: result.models
345
- };
346
- writeFileSync(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 {
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 = join(userHome(), ".code-shell", "settings.json");
382
- let current = {};
383
- if (existsSync(path)) {
384
- try {
385
- const raw = readFileSync(path, "utf-8");
386
- const parsed = JSON.parse(raw);
387
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
388
- current = parsed;
389
- }
390
- } catch {
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
- mkdirSync(dirname(path), { recursive: true });
405
- const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
406
- writeFileSync(tmp, JSON.stringify(current, null, 2), "utf-8");
407
- renameSync(tmp, path);
408
- this.invalidate();
409
- }
410
- loadJsonFile(path, name, priority) {
411
- if (!existsSync(path)) return;
412
- try {
413
- const content = readFileSync(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 {
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
- };
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
- export {
444
- SettingsSchema,
445
- validateSettings,
446
- SettingsManager
447
- };
@@ -1,47 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
4
-
5
- // src/llm/model-cache.ts
6
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7
- var _fs = require('fs');
8
- var _os = require('os');
9
- var _path = require('path');
10
- var TTL_MS = 7 * 24 * 3600 * 1e3;
11
- function readCache(cacheDir, providerKey) {
12
- const path = _path.join.call(void 0, cacheDir, `${providerKey}.json`);
13
- if (!_fs.existsSync.call(void 0, path)) return void 0;
14
- try {
15
- const raw = _fs.readFileSync.call(void 0, path, "utf-8");
16
- const parsed = JSON.parse(raw);
17
- if (!parsed || !Array.isArray(parsed.models)) return void 0;
18
- return parsed;
19
- } catch (e) {
20
- return void 0;
21
- }
22
- }
23
- function writeCache(cacheDir, providerKey, models) {
24
- if (!_fs.existsSync.call(void 0, cacheDir)) _fs.mkdirSync.call(void 0, cacheDir, { recursive: true });
25
- const payload = {
26
- fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
27
- providerKey,
28
- models
29
- };
30
- _fs.writeFileSync.call(void 0, _path.join.call(void 0, cacheDir, `${providerKey}.json`), JSON.stringify(payload, null, 2), "utf-8");
31
- return payload;
32
- }
33
- function isStale(file, now = Date.now()) {
34
- const ts = Date.parse(file.fetchedAt);
35
- if (!Number.isFinite(ts)) return true;
36
- return now - ts > TTL_MS;
37
- }
38
- function defaultCacheDir() {
39
- return _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "cache", "models");
40
- }
41
-
42
-
43
-
44
-
45
-
46
-
47
- exports.readCache = readCache; exports.writeCache = writeCache; exports.isStale = isStale; exports.defaultCacheDir = defaultCacheDir;
@@ -1,146 +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
- var _chunk52LGZKT3cjs = require('./chunk-52LGZKT3.cjs');
4
-
5
-
6
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
7
-
8
- // src/llm/model-pool.ts
9
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
10
- var BUILTIN_CONTEXT_WINDOWS = [
11
- // DeepSeek V4 family — 1M context (api-docs.deepseek.com)
12
- [/^deepseek-v4(?:-|$)/i, 1e6],
13
- [/(?:^|\/)deepseek-v4(?:-|$)/i, 1e6]
14
- ];
15
- function lookupBuiltinContextWindow(model) {
16
- for (const [re, tokens] of BUILTIN_CONTEXT_WINDOWS) {
17
- if (re.test(model)) return tokens;
18
- }
19
- return void 0;
20
- }
21
- var ModelPool = (_class = class {
22
- __init() {this.models = /* @__PURE__ */ new Map()}
23
-
24
-
25
-
26
- setProviderCatalog(cat) {
27
- this.providerCatalog = cat;
28
- }
29
- setCacheDir(dir) {
30
- this.cacheDir = dir;
31
- }
32
- /**
33
- * For each entry in the pool that lacks an explicit maxContextTokens
34
- * but has a providerKey, look up the contextLength from the cached
35
- * model list and patch it in.
36
- */
37
- reloadCachedContextWindows() {
38
- if (!this.cacheDir) return;
39
- for (const [key, entry] of this.models) {
40
- if (entry.maxContextTokens != null) continue;
41
- if (!entry.providerKey) continue;
42
- const file = _chunk52LGZKT3cjs.readCache.call(void 0, this.cacheDir, entry.providerKey);
43
- if (!file) continue;
44
- const match = file.models.find((m) => m.id === entry.model);
45
- if (_optionalChain([match, 'optionalAccess', _ => _.contextLength])) {
46
- this.models.set(key, { ...entry, maxContextTokens: match.contextLength });
47
- }
48
- }
49
- }
50
- /**
51
- * Build a pool from an array of model entries.
52
- * The first entry (or the one matching `defaultKey`) becomes active.
53
- */
54
- constructor(entries, defaultKey) {;_class.prototype.__init.call(this);
55
- if (entries) {
56
- for (const e of entries) {
57
- this.models.set(e.key, this.withBuiltinDefaults(e));
58
- }
59
- }
60
- if (defaultKey && this.models.has(defaultKey)) {
61
- this.activeKey = defaultKey;
62
- } else if (_optionalChain([entries, 'optionalAccess', _2 => _2.length])) {
63
- this.activeKey = entries[0].key;
64
- }
65
- }
66
- /** Register a model at runtime. */
67
- register(entry) {
68
- this.models.set(entry.key, this.withBuiltinDefaults(entry));
69
- if (!this.activeKey) {
70
- this.activeKey = entry.key;
71
- }
72
- }
73
- /** Fill in known defaults (e.g. context window for DeepSeek V4) when the entry doesn't specify them. */
74
- withBuiltinDefaults(entry) {
75
- if (entry.maxContextTokens != null) return entry;
76
- const builtin = lookupBuiltinContextWindow(entry.model);
77
- if (builtin == null) return entry;
78
- return { ...entry, maxContextTokens: builtin };
79
- }
80
- /** Switch the active model. Throws if key not found. */
81
- switch(key) {
82
- const entry = this.models.get(key);
83
- if (!entry) {
84
- const available = [...this.models.keys()].join(", ");
85
- throw new Error(`Model "${key}" not found. Available: ${available}`);
86
- }
87
- this.activeKey = key;
88
- return entry;
89
- }
90
- /** Get a model by key. No key = active model. Returns undefined if not found. */
91
- get(key) {
92
- if (key) return this.models.get(key);
93
- if (this.activeKey) return this.models.get(this.activeKey);
94
- return void 0;
95
- }
96
- /** Get the active model key. */
97
- getActiveKey() {
98
- return this.activeKey;
99
- }
100
- /** List all registered models. */
101
- list() {
102
- return [...this.models.values()];
103
- }
104
- /** Number of registered models. */
105
- get size() {
106
- return this.models.size;
107
- }
108
- /** Check if a key exists. */
109
- has(key) {
110
- return this.models.has(key);
111
- }
112
- /**
113
- * Build an LLMConfig for a given model entry, merging with a base config
114
- * (inherits apiKey, baseUrl, etc. from the base if not set on the entry).
115
- */
116
- toLLMConfig(entry, base) {
117
- const fromCat = entry.providerKey && this.providerCatalog ? this.providerCatalog.get(entry.providerKey) : void 0;
118
- const kindToClientProvider = (kind) => {
119
- if (!kind) return "openai";
120
- if (kind === "anthropic") return "anthropic";
121
- return "openai";
122
- };
123
- return {
124
- provider: entry.provider || kindToClientProvider(_optionalChain([fromCat, 'optionalAccess', _3 => _3.kind])) || "openai",
125
- model: entry.model,
126
- apiKey: _nullishCoalesce(_nullishCoalesce(entry.apiKey, () => ( _optionalChain([fromCat, 'optionalAccess', _4 => _4.apiKey]))), () => ( _optionalChain([base, 'optionalAccess', _5 => _5.apiKey]))),
127
- baseUrl: _nullishCoalesce(_nullishCoalesce(entry.baseUrl, () => ( _optionalChain([fromCat, 'optionalAccess', _6 => _6.baseUrl]))), () => ( _optionalChain([base, 'optionalAccess', _7 => _7.baseUrl]))),
128
- temperature: _nullishCoalesce(_optionalChain([base, 'optionalAccess', _8 => _8.temperature]), () => ( 0.3)),
129
- maxTokens: _nullishCoalesce(_nullishCoalesce(entry.maxOutputTokens, () => ( _optionalChain([base, 'optionalAccess', _9 => _9.maxTokens]))), () => ( 8192)),
130
- enableStreaming: _nullishCoalesce(_optionalChain([base, 'optionalAccess', _10 => _10.enableStreaming]), () => ( true))
131
- };
132
- }
133
- /**
134
- * Build an LLMConfig for the active model (or a specific key),
135
- * merging with a base config.
136
- */
137
- resolveLLMConfig(key, base) {
138
- const entry = this.get(key);
139
- if (!entry) return void 0;
140
- return this.toLLMConfig(entry, base);
141
- }
142
- }, _class);
143
-
144
-
145
-
146
- exports.ModelPool = ModelPool;