@cjhyy/code-shell 0.1.5 → 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.
- package/CHANGELOG.md +30 -0
- package/dist/anthropic-UBSB5AQH.js +1 -0
- package/dist/arena/index.js +1 -104
- package/dist/arena-OW55ZCHT.js +3 -0
- package/dist/bwrap-PVZMLHZR.js +2 -0
- package/dist/chunk-2NS3JMNK.js +1 -0
- package/dist/chunk-3QP5BQ3L.js +1 -0
- package/dist/chunk-B7K2OWKC.js +2 -0
- package/dist/chunk-EWWK56K6.js +2 -0
- package/dist/chunk-FU7AHZNN.js +1 -0
- package/dist/chunk-HIJ2XXGX.js +1 -0
- package/dist/chunk-KCXSARAA.js +1 -0
- package/dist/chunk-NFH3UQ3E.js +2 -0
- package/dist/chunk-NMBYBGC7.js +250 -0
- package/dist/chunk-NVAZJ5XS.js +2 -0
- package/dist/chunk-O5HFCH2U.js +1 -0
- package/dist/chunk-P6JSTIFM.js +1 -0
- package/dist/chunk-PGANL6F2.js +3 -0
- package/dist/chunk-Q4O2HGWS.js +251 -0
- package/dist/chunk-QTWU7UNA.js +5 -0
- package/dist/chunk-RP26WO4R.js +1 -0
- package/dist/chunk-SNFAPSLA.js +1 -0
- package/dist/chunk-T222K6IV.js +18 -0
- package/dist/chunk-TKJA6W36.js +3 -0
- package/dist/chunk-UDPUTFQT.js +2 -0
- package/dist/chunk-W47Z7MGS.js +33 -0
- package/dist/chunk-WI6FSWGU.js +1 -0
- package/dist/chunk-WOP6MJKW.js +1 -0
- package/dist/chunk-XDOWC7EG.js +4 -0
- package/dist/chunk-Y2NS6HPO.js +641 -0
- package/dist/cli/main.js +303 -22037
- package/dist/cli/updater.d.ts +8 -0
- package/dist/client-base-6ZZJJYDY.js +1 -0
- package/dist/compaction-ECVQVOCT.js +1 -0
- package/dist/devtools-SGDUOOM4.js +1 -0
- package/dist/engine/engine.d.ts +15 -0
- package/dist/export-md-U72T7NW7.js +22 -0
- package/dist/file-history-7FQFEQOL.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -347
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/manager-C3TDN6MS.js +1 -0
- package/dist/mcp-manager-OP4XYV53.js +1 -0
- package/dist/memory-BNI4WEWL.js +1 -0
- package/dist/model-cache-HEDXI7UJ.js +1 -0
- package/dist/model-fetcher-BJ64META.js +1 -0
- package/dist/off-7SDVMMXW.js +1 -0
- package/dist/openai-KEWQ54TM.js +1 -0
- package/dist/openrouter-models-AM6M52D6.js +1 -0
- package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
- package/dist/product/index.js +1 -21
- package/dist/run/index.js +1 -48
- package/dist/seatbelt-WBYROQT6.js +37 -0
- package/dist/session/session-manager.d.ts +2 -0
- package/dist/session-manager-AGWS5SMJ.js +1 -0
- package/dist/settings/schema.d.ts +72 -6
- package/dist/tool-summary-5UE62VU4.js +2 -0
- package/dist/tool-system/builtin/bash.d.ts +7 -1
- package/dist/tool-system/context.d.ts +7 -0
- package/dist/tool-system/investigation-guard.d.ts +9 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/index.d.ts +71 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/types.d.ts +4 -0
- package/dist/ui/components/SessionPicker.d.ts +2 -0
- package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
- package/dist/ui/components/StatusLine.d.ts +2 -2
- package/dist/updater-OCNU2K2Z.js +1 -0
- package/package.json +8 -10
- package/skills-builtin/codeshell-help.md +135 -0
- package/dist/anthropic-IBTI4WL2.cjs +0 -10
- package/dist/anthropic-PRZZKHEZ.js +0 -10
- package/dist/arena/index.cjs +0 -104
- package/dist/arena-KBQOPLFV.cjs +0 -261
- package/dist/arena-O2L4TN6A.js +0 -261
- package/dist/chunk-2EP3CLEN.js +0 -44
- package/dist/chunk-2YW4FPFG.cjs +0 -101
- package/dist/chunk-3OA5G4TM.js +0 -47
- package/dist/chunk-52LGZKT3.cjs +0 -47
- package/dist/chunk-55XGPMAP.cjs +0 -146
- package/dist/chunk-5ECBT4YA.js +0 -450
- package/dist/chunk-6QVAYW7C.cjs +0 -438
- package/dist/chunk-6S4BJ65N.js +0 -113
- package/dist/chunk-76HYEPDM.js +0 -307
- package/dist/chunk-76W334S4.js +0 -54
- package/dist/chunk-7EG3V4JY.cjs +0 -113
- package/dist/chunk-7JVTYEEC.js +0 -340
- package/dist/chunk-7K6SDRRF.js +0 -9047
- package/dist/chunk-7Y6S3OCX.js +0 -438
- package/dist/chunk-A5LCRPDP.cjs +0 -54
- package/dist/chunk-BSW22MPA.js +0 -146
- package/dist/chunk-BUU5PZK2.cjs +0 -9048
- package/dist/chunk-BWTOS5BH.cjs +0 -5128
- package/dist/chunk-BXCY2FSE.js +0 -203
- package/dist/chunk-C5YQBIRK.js +0 -5128
- package/dist/chunk-HEKQCI7B.cjs +0 -224
- package/dist/chunk-HS2MFNUC.cjs +0 -44
- package/dist/chunk-IK4EWJBP.cjs +0 -203
- package/dist/chunk-JMR33QVF.cjs +0 -169
- package/dist/chunk-KOVYSDHZ.cjs +0 -340
- package/dist/chunk-KS3RYAYL.cjs +0 -45
- package/dist/chunk-MD32R22I.js +0 -50
- package/dist/chunk-MY5XHADU.cjs +0 -216
- package/dist/chunk-NUNC3VFB.cjs +0 -307
- package/dist/chunk-QRM7IF2S.cjs +0 -4711
- package/dist/chunk-R47ROHGL.cjs +0 -298
- package/dist/chunk-RMYKO74M.js +0 -1252
- package/dist/chunk-SFXHZSRF.js +0 -101
- package/dist/chunk-SIHHIQLO.js +0 -224
- package/dist/chunk-SNT563K3.cjs +0 -107
- package/dist/chunk-T6VYG46N.js +0 -105
- package/dist/chunk-TUY2T5KP.cjs +0 -105
- package/dist/chunk-VIAGTYYW.js +0 -169
- package/dist/chunk-VYL4EFRC.cjs +0 -1252
- package/dist/chunk-W22P377T.js +0 -299
- package/dist/chunk-WASS5YWB.js +0 -215
- package/dist/chunk-XDIQWQJ4.js +0 -4711
- package/dist/chunk-YIQBXAYU.cjs +0 -264
- package/dist/chunk-YJ77GQK5.js +0 -107
- package/dist/chunk-YUI524OE.cjs +0 -450
- package/dist/chunk-ZBPSQCPU.js +0 -264
- package/dist/cli/main.cjs +0 -22133
- package/dist/client-base-HTF236ZD.cjs +0 -9
- package/dist/client-base-QKRKCOWB.js +0 -9
- package/dist/compaction-6VU2T643.js +0 -33
- package/dist/compaction-OKUNTCA7.cjs +0 -33
- package/dist/devtools-T2NIZBJK.cjs +0 -6
- package/dist/devtools-YXWHOVKR.js +0 -6
- package/dist/export-md-RXDW6F5W.cjs +0 -135
- package/dist/export-md-XXKZANW5.js +0 -135
- package/dist/file-history-KYPE3ECT.cjs +0 -7
- package/dist/file-history-LF4F7X26.js +0 -7
- package/dist/index.cjs +0 -347
- package/dist/manager-C2IUXKRC.js +0 -7
- package/dist/manager-YYKWYTRM.cjs +0 -7
- package/dist/mcp-manager-QMKWPBZ4.js +0 -8
- package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
- package/dist/memory-5LWZ6FI2.cjs +0 -9
- package/dist/memory-VIJLBAMQ.js +0 -9
- package/dist/model-cache-5KIYL5SL.js +0 -13
- package/dist/model-cache-OED3IM4R.cjs +0 -13
- package/dist/model-fetcher-HKGICACL.js +0 -8
- package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
- package/dist/openai-JR2WEKOF.js +0 -10
- package/dist/openai-YBTOET4O.cjs +0 -10
- package/dist/openrouter-models-OU4GRZQY.cjs +0 -15
- package/dist/openrouter-models-TGKDKY52.js +0 -15
- package/dist/openrouter-sync-BBHUM3R6.cjs +0 -11
- package/dist/openrouter-sync-UXUSJCIR.js +0 -11
- package/dist/product/index.cjs +0 -21
- package/dist/run/index.cjs +0 -48
- package/dist/session-manager-Q22BBMD3.js +0 -8
- package/dist/session-manager-XODQVL3C.cjs +0 -8
- package/dist/tool-summary-63DPIS7G.cjs +0 -31
- package/dist/tool-summary-NP5CDBKG.js +0 -31
- package/dist/updater-QW473OF4.cjs +0 -17
- package/dist/updater-VFUAHCVY.js +0 -17
package/dist/chunk-5ECBT4YA.js
DELETED
|
@@ -1,450 +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(userHome(), ".claude", "settings.json"), "user", 1);
|
|
325
|
-
this.loadJsonFile(join(this.cwd, ".code-shell", "settings.json"), "project", 2);
|
|
326
|
-
this.loadJsonFile(join(this.cwd, ".claude", "settings.json"), "project", 2);
|
|
327
|
-
this.loadJsonFile(join(this.cwd, ".code-shell", "settings.local.json"), "local", 3);
|
|
328
|
-
this.loadJsonFile(join(this.cwd, ".claude", "settings.local.json"), "local", 3);
|
|
329
|
-
if (flagOverrides && Object.keys(flagOverrides).length > 0) {
|
|
330
|
-
this.sources.push({ name: "flag", priority: 4, data: flagOverrides });
|
|
331
|
-
}
|
|
332
|
-
this.sources.sort((a, b) => a.priority - b.priority);
|
|
333
|
-
const raw = this.deepMerge();
|
|
334
|
-
const userPath = join(userHome(), ".code-shell", "settings.json");
|
|
335
|
-
if (existsSync(userPath)) {
|
|
336
|
-
try {
|
|
337
|
-
const userRaw = JSON.parse(readFileSync(userPath, "utf-8"));
|
|
338
|
-
const result = migrateModels({
|
|
339
|
-
providers: userRaw.providers ?? [],
|
|
340
|
-
models: userRaw.models ?? []
|
|
341
|
-
});
|
|
342
|
-
if (result.changed) {
|
|
343
|
-
copyFileSync(userPath, `${userPath}.bak`);
|
|
344
|
-
const migrated = {
|
|
345
|
-
...userRaw,
|
|
346
|
-
providers: result.providers,
|
|
347
|
-
models: result.models
|
|
348
|
-
};
|
|
349
|
-
writeFileSync(userPath, JSON.stringify(migrated, null, 2), "utf-8");
|
|
350
|
-
const userSource = this.sources.find((s) => s.name === "user");
|
|
351
|
-
if (userSource) userSource.data = migrated;
|
|
352
|
-
const remerged = this.deepMerge();
|
|
353
|
-
this.merged = validateSettings(remerged);
|
|
354
|
-
return this.merged;
|
|
355
|
-
}
|
|
356
|
-
} catch {
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
this.merged = validateSettings(raw);
|
|
360
|
-
return this.merged;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Get current effective settings.
|
|
364
|
-
*/
|
|
365
|
-
get() {
|
|
366
|
-
if (!this.merged) return this.load();
|
|
367
|
-
return this.merged;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Invalidate cached merge.
|
|
371
|
-
*/
|
|
372
|
-
invalidate() {
|
|
373
|
-
this.merged = null;
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Persist a single setting (dotted key path) to the user-level config file
|
|
377
|
-
* at ~/.code-shell/settings.json. Other sources (project / local /
|
|
378
|
-
* managed) are intentionally untouched: writing back to project/local
|
|
379
|
-
* would surprise version control, and managed is read-only.
|
|
380
|
-
*
|
|
381
|
-
* The merged cache is invalidated so the next get() picks up the change.
|
|
382
|
-
*/
|
|
383
|
-
saveUserSetting(key, value) {
|
|
384
|
-
const path = join(userHome(), ".code-shell", "settings.json");
|
|
385
|
-
let current = {};
|
|
386
|
-
if (existsSync(path)) {
|
|
387
|
-
try {
|
|
388
|
-
const raw = readFileSync(path, "utf-8");
|
|
389
|
-
const parsed = JSON.parse(raw);
|
|
390
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
391
|
-
current = parsed;
|
|
392
|
-
}
|
|
393
|
-
} catch {
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
const parts = key.split(".");
|
|
397
|
-
let target = current;
|
|
398
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
399
|
-
const seg = parts[i];
|
|
400
|
-
const next = target[seg];
|
|
401
|
-
if (!next || typeof next !== "object" || Array.isArray(next)) {
|
|
402
|
-
target[seg] = {};
|
|
403
|
-
}
|
|
404
|
-
target = target[seg];
|
|
405
|
-
}
|
|
406
|
-
target[parts[parts.length - 1]] = value;
|
|
407
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
408
|
-
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
409
|
-
writeFileSync(tmp, JSON.stringify(current, null, 2), "utf-8");
|
|
410
|
-
renameSync(tmp, path);
|
|
411
|
-
this.invalidate();
|
|
412
|
-
}
|
|
413
|
-
loadJsonFile(path, name, priority) {
|
|
414
|
-
if (!existsSync(path)) return;
|
|
415
|
-
try {
|
|
416
|
-
const content = readFileSync(path, "utf-8");
|
|
417
|
-
const data = JSON.parse(content);
|
|
418
|
-
if (typeof data === "object" && data !== null) {
|
|
419
|
-
this.sources.push({ name, priority, data });
|
|
420
|
-
}
|
|
421
|
-
} catch {
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
deepMerge() {
|
|
425
|
-
let result = {};
|
|
426
|
-
for (const source of this.sources) {
|
|
427
|
-
result = merge(result, source.data);
|
|
428
|
-
}
|
|
429
|
-
return result;
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
function merge(base, override) {
|
|
433
|
-
const result = { ...base };
|
|
434
|
-
for (const [key, value] of Object.entries(override)) {
|
|
435
|
-
if (value === null) {
|
|
436
|
-
delete result[key];
|
|
437
|
-
} else if (typeof value === "object" && !Array.isArray(value) && typeof result[key] === "object" && !Array.isArray(result[key]) && result[key] !== null) {
|
|
438
|
-
result[key] = merge(result[key], value);
|
|
439
|
-
} else {
|
|
440
|
-
result[key] = value;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return result;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
export {
|
|
447
|
-
SettingsSchema,
|
|
448
|
-
validateSettings,
|
|
449
|
-
SettingsManager
|
|
450
|
-
};
|