@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
@@ -0,0 +1,447 @@
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
+ };
@@ -0,0 +1,47 @@
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,9 +1,12 @@
1
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
2
 
3
- var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
3
+ var _chunk52LGZKT3cjs = require('./chunk-52LGZKT3.cjs');
4
+
5
+
6
+ var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
4
7
 
5
8
  // src/llm/model-pool.ts
6
- _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
9
+ _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7
10
  var BUILTIN_CONTEXT_WINDOWS = [
8
11
  // DeepSeek V4 family — 1M context (api-docs.deepseek.com)
9
12
  [/^deepseek-v4(?:-|$)/i, 1e6],
@@ -18,6 +21,32 @@ function lookupBuiltinContextWindow(model) {
18
21
  var ModelPool = (_class = class {
19
22
  __init() {this.models = /* @__PURE__ */ new Map()}
20
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
+ }
21
50
  /**
22
51
  * Build a pool from an array of model entries.
23
52
  * The first entry (or the one matching `defaultKey`) becomes active.
@@ -30,7 +59,7 @@ var ModelPool = (_class = class {
30
59
  }
31
60
  if (defaultKey && this.models.has(defaultKey)) {
32
61
  this.activeKey = defaultKey;
33
- } else if (_optionalChain([entries, 'optionalAccess', _ => _.length])) {
62
+ } else if (_optionalChain([entries, 'optionalAccess', _2 => _2.length])) {
34
63
  this.activeKey = entries[0].key;
35
64
  }
36
65
  }
@@ -85,14 +114,20 @@ var ModelPool = (_class = class {
85
114
  * (inherits apiKey, baseUrl, etc. from the base if not set on the entry).
86
115
  */
87
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
+ };
88
123
  return {
89
- provider: entry.provider,
124
+ provider: entry.provider || kindToClientProvider(_optionalChain([fromCat, 'optionalAccess', _3 => _3.kind])) || "openai",
90
125
  model: entry.model,
91
- apiKey: _nullishCoalesce(entry.apiKey, () => ( _optionalChain([base, 'optionalAccess', _2 => _2.apiKey]))),
92
- baseUrl: _nullishCoalesce(entry.baseUrl, () => ( _optionalChain([base, 'optionalAccess', _3 => _3.baseUrl]))),
93
- temperature: _nullishCoalesce(_optionalChain([base, 'optionalAccess', _4 => _4.temperature]), () => ( 0.3)),
94
- maxTokens: _nullishCoalesce(_nullishCoalesce(entry.maxOutputTokens, () => ( _optionalChain([base, 'optionalAccess', _5 => _5.maxTokens]))), () => ( 8192)),
95
- enableStreaming: _nullishCoalesce(_optionalChain([base, 'optionalAccess', _6 => _6.enableStreaming]), () => ( true))
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))
96
131
  };
97
132
  }
98
133
  /**