flavor-code 1.4.1 → 1.4.3-beta.2
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/README.md +32 -2
- package/README.zh-CN.md +32 -2
- package/dist/{app-4YRKE7VI.js → app-G35YBHPR.js} +873 -641
- package/dist/apply-WOW3QU5I.js +51 -0
- package/dist/broker-cli-X5H46FZV.js +15 -0
- package/dist/check-CSKTV4O2.js +16 -0
- package/dist/chunk-3563SW4X.js +10513 -0
- package/dist/chunk-3UX2CGDW.js +1955 -0
- package/dist/chunk-4TMLXZVZ.js +75 -0
- package/dist/chunk-6F66UXBI.js +48 -0
- package/dist/{chunk-FAORPP4F.js → chunk-6URQ7FIF.js} +24 -88
- package/dist/chunk-6X62CGMA.js +193 -0
- package/dist/chunk-7Y64WNBB.js +8930 -0
- package/dist/chunk-AA4QNKTF.js +501 -0
- package/dist/chunk-BDX777JR.js +11 -0
- package/dist/chunk-CVP5OUHD.js +103 -0
- package/dist/chunk-EWD7FWTH.js +14547 -0
- package/dist/chunk-FAJ6YDZK.js +630 -0
- package/dist/{chunk-N5MXHJKD.js → chunk-GTFP2R5I.js} +1 -1
- package/dist/{chunk-7YFHRORG.js → chunk-HGTCIHWA.js} +383 -172
- package/dist/chunk-IDJAHEG6.js +43501 -0
- package/dist/chunk-IQEEFDEE.js +389 -0
- package/dist/chunk-IU3UBETC.js +30 -0
- package/dist/chunk-K7UGGWJV.js +1003 -0
- package/dist/chunk-KRWWCVXA.js +74 -0
- package/dist/chunk-OKHV7CTB.js +482 -0
- package/dist/chunk-PULWAH6E.js +474 -0
- package/dist/chunk-PZ5NKRVA.js +85 -0
- package/dist/chunk-RBAZLFKB.js +1022 -0
- package/dist/chunk-RV3EXUXM.js +30 -0
- package/dist/chunk-SJUIIHIA.js +2130 -0
- package/dist/{chunk-VMQWXQEC.js → chunk-T6RE76D2.js} +2003 -493
- package/dist/chunk-TIEOVQW6.js +61 -0
- package/dist/chunk-WLZUAVVU.js +15 -0
- package/dist/chunk-X442CJJH.js +114 -0
- package/dist/{chunk-RAYH6K2H.js → chunk-Y7EH4NVO.js} +1 -1
- package/dist/{chunk-S32JRDZK.js → chunk-ZKKVSR37.js} +6 -1
- package/dist/{claude-ink-JZXNSAQS.js → claude-ink-BE56DB6N.js} +9 -4
- package/dist/cli-3MF6EL2H.js +163 -0
- package/dist/cli-main.js +3805 -473
- package/dist/cli.js +50 -4
- package/dist/config/load.d.ts +8 -0
- package/dist/config/schema.d.ts +11 -0
- package/dist/context/manager.d.ts +2 -0
- package/dist/desktop/main.js +4303 -1171
- package/dist/desktop/preload.cjs +30 -0
- package/dist/desktop-renderer/assets/index-BWklSoOO.css +1 -0
- package/dist/desktop-renderer/assets/index-DCqIrF1S.js +153 -0
- package/dist/desktop-renderer/assets/{interactive-terminal-1agnYY5L.js → interactive-terminal-B6GbpzIn.js} +1 -1
- package/dist/desktop-renderer/index.html +2 -2
- package/dist/doctor-OHCGK52S.js +20 -0
- package/dist/load-QK6CMLDF.js +25 -0
- package/dist/log-ATFIPRNU.js +19 -0
- package/dist/manager-5SI4MPES.js +191 -0
- package/dist/models/anthropic.d.ts +3 -0
- package/dist/node-LOIXT44J.js +879 -0
- package/dist/plugin-worker-entry.js +1 -1
- package/dist/production-6DIZ6YLQ.js +46 -0
- package/dist/production.d.ts +28 -1
- package/dist/project-3QXE22TG.js +11 -0
- package/dist/react-M6JGXSJZ.js +7 -0
- package/dist/recorder-FAGJJH3N.js +11 -0
- package/dist/sdk/index.js +30 -8
- package/dist/server-2KLKPHPL.js +11 -0
- package/dist/session/store.d.ts +1 -0
- package/dist/store-ZIHN6363.js +18 -0
- package/dist/ui/commands.d.ts +1 -5
- package/dist/usage-summary-G5FBOJLK.js +13 -0
- package/dist/utils/execFileNoThrow.d.ts +1 -0
- package/dist/write-stream-CGD57URC.js +77 -0
- package/package.json +1 -1
- package/dist/chunk-O2PC44GY.js +0 -26120
- package/dist/chunk-ZJCAQXA7.js +0 -169
- package/dist/desktop-renderer/assets/index-BM9ugkh9.js +0 -154
- package/dist/desktop-renderer/assets/index-Bk6FYhyh.css +0 -1
- package/dist/load-UPOG3XQR.js +0 -19
|
@@ -1,172 +1,340 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from "node:module"; const require =
|
|
2
|
+
import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
FlavorConfigSchema,
|
|
5
|
+
ProviderConfigSchema,
|
|
6
|
+
configPathSegments
|
|
7
|
+
} from "./chunk-6X62CGMA.js";
|
|
8
|
+
import {
|
|
9
|
+
__commonJS,
|
|
10
|
+
__require,
|
|
11
|
+
__toESM
|
|
12
|
+
} from "./chunk-ZKKVSR37.js";
|
|
13
|
+
|
|
14
|
+
// node_modules/dotenv/lib/main.js
|
|
15
|
+
var require_main = __commonJS({
|
|
16
|
+
"node_modules/dotenv/lib/main.js"(exports, module) {
|
|
17
|
+
"use strict";
|
|
18
|
+
var fs = __require("fs");
|
|
19
|
+
var path = __require("path");
|
|
20
|
+
var os = __require("os");
|
|
21
|
+
var crypto = __require("crypto");
|
|
22
|
+
var TIPS = [
|
|
23
|
+
"\u25C8 encrypted .env [www.dotenvx.com]",
|
|
24
|
+
"\u25C8 secrets for agents [www.dotenvx.com]",
|
|
25
|
+
"\u2301 auth for agents [www.vestauth.com]",
|
|
26
|
+
"\u2318 custom filepath { path: '/custom/path/.env' }",
|
|
27
|
+
"\u2318 enable debugging { debug: true }",
|
|
28
|
+
"\u2318 override existing { override: true }",
|
|
29
|
+
"\u2318 suppress logs { quiet: true }",
|
|
30
|
+
"\u2318 multiple files { path: ['.env.local', '.env'] }"
|
|
31
|
+
];
|
|
32
|
+
function _getRandomTip() {
|
|
33
|
+
return TIPS[Math.floor(Math.random() * TIPS.length)];
|
|
34
|
+
}
|
|
35
|
+
function parseBoolean(value) {
|
|
36
|
+
if (typeof value === "string") {
|
|
37
|
+
return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
return Boolean(value);
|
|
40
|
+
}
|
|
41
|
+
function supportsAnsi() {
|
|
42
|
+
return process.stdout.isTTY;
|
|
43
|
+
}
|
|
44
|
+
function dim(text) {
|
|
45
|
+
return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
|
|
46
|
+
}
|
|
47
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
48
|
+
function parse2(src) {
|
|
49
|
+
const obj = {};
|
|
50
|
+
let lines = src.toString();
|
|
51
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
52
|
+
let match;
|
|
53
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
54
|
+
const key = match[1];
|
|
55
|
+
let value = match[2] || "";
|
|
56
|
+
value = value.trim();
|
|
57
|
+
const maybeQuote = value[0];
|
|
58
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
59
|
+
if (maybeQuote === '"') {
|
|
60
|
+
value = value.replace(/\\n/g, "\n");
|
|
61
|
+
value = value.replace(/\\r/g, "\r");
|
|
62
|
+
}
|
|
63
|
+
obj[key] = value;
|
|
64
|
+
}
|
|
65
|
+
return obj;
|
|
66
|
+
}
|
|
67
|
+
function _parseVault(options) {
|
|
68
|
+
options = options || {};
|
|
69
|
+
const vaultPath = _vaultPath(options);
|
|
70
|
+
options.path = vaultPath;
|
|
71
|
+
const result = DotenvModule.configDotenv(options);
|
|
72
|
+
if (!result.parsed) {
|
|
73
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
74
|
+
err.code = "MISSING_DATA";
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
const keys = _dotenvKey(options).split(",");
|
|
78
|
+
const length = keys.length;
|
|
79
|
+
let decrypted;
|
|
80
|
+
for (let i = 0; i < length; i++) {
|
|
81
|
+
try {
|
|
82
|
+
const key = keys[i].trim();
|
|
83
|
+
const attrs = _instructions(result, key);
|
|
84
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
85
|
+
break;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (i + 1 >= length) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return DotenvModule.parse(decrypted);
|
|
93
|
+
}
|
|
94
|
+
function _warn(message) {
|
|
95
|
+
console.error(`\u26A0 ${message}`);
|
|
96
|
+
}
|
|
97
|
+
function _debug(message) {
|
|
98
|
+
console.log(`\u2506 ${message}`);
|
|
99
|
+
}
|
|
100
|
+
function _log(message) {
|
|
101
|
+
console.log(`\u25C7 ${message}`);
|
|
102
|
+
}
|
|
103
|
+
function _dotenvKey(options) {
|
|
104
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
105
|
+
return options.DOTENV_KEY;
|
|
106
|
+
}
|
|
107
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
108
|
+
return process.env.DOTENV_KEY;
|
|
109
|
+
}
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
function _instructions(result, dotenvKey) {
|
|
113
|
+
let uri;
|
|
114
|
+
try {
|
|
115
|
+
uri = new URL(dotenvKey);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
118
|
+
const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
|
119
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
const key = uri.password;
|
|
125
|
+
if (!key) {
|
|
126
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
127
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
const environment = uri.searchParams.get("environment");
|
|
131
|
+
if (!environment) {
|
|
132
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
133
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
137
|
+
const ciphertext = result.parsed[environmentKey];
|
|
138
|
+
if (!ciphertext) {
|
|
139
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
140
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
return { ciphertext, key };
|
|
144
|
+
}
|
|
145
|
+
function _vaultPath(options) {
|
|
146
|
+
let possibleVaultPath = null;
|
|
147
|
+
if (options && options.path && options.path.length > 0) {
|
|
148
|
+
if (Array.isArray(options.path)) {
|
|
149
|
+
for (const filepath of options.path) {
|
|
150
|
+
if (fs.existsSync(filepath)) {
|
|
151
|
+
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
|
|
159
|
+
}
|
|
160
|
+
if (fs.existsSync(possibleVaultPath)) {
|
|
161
|
+
return possibleVaultPath;
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
function _resolveHome(envPath) {
|
|
166
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
167
|
+
}
|
|
168
|
+
function _configVault(options) {
|
|
169
|
+
const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
|
|
170
|
+
const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
|
|
171
|
+
if (debug || !quiet) {
|
|
172
|
+
_log("loading env from encrypted .env.vault");
|
|
173
|
+
}
|
|
174
|
+
const parsed = DotenvModule._parseVault(options);
|
|
175
|
+
let processEnv = process.env;
|
|
176
|
+
if (options && options.processEnv != null) {
|
|
177
|
+
processEnv = options.processEnv;
|
|
178
|
+
}
|
|
179
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
180
|
+
return { parsed };
|
|
181
|
+
}
|
|
182
|
+
function configDotenv(options) {
|
|
183
|
+
const dotenvPath = path.resolve(process.cwd(), ".env");
|
|
184
|
+
let encoding = "utf8";
|
|
185
|
+
let processEnv = process.env;
|
|
186
|
+
if (options && options.processEnv != null) {
|
|
187
|
+
processEnv = options.processEnv;
|
|
188
|
+
}
|
|
189
|
+
let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
|
|
190
|
+
let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
|
|
191
|
+
if (options && options.encoding) {
|
|
192
|
+
encoding = options.encoding;
|
|
193
|
+
} else {
|
|
194
|
+
if (debug) {
|
|
195
|
+
_debug("no encoding is specified (UTF-8 is used by default)");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
let optionPaths = [dotenvPath];
|
|
199
|
+
if (options && options.path) {
|
|
200
|
+
if (!Array.isArray(options.path)) {
|
|
201
|
+
optionPaths = [_resolveHome(options.path)];
|
|
202
|
+
} else {
|
|
203
|
+
optionPaths = [];
|
|
204
|
+
for (const filepath of options.path) {
|
|
205
|
+
optionPaths.push(_resolveHome(filepath));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
let lastError;
|
|
210
|
+
const parsedAll = {};
|
|
211
|
+
for (const path2 of optionPaths) {
|
|
212
|
+
try {
|
|
213
|
+
const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
|
|
214
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
if (debug) {
|
|
217
|
+
_debug(`failed to load ${path2} ${e.message}`);
|
|
218
|
+
}
|
|
219
|
+
lastError = e;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const populated = DotenvModule.populate(processEnv, parsedAll, options);
|
|
223
|
+
debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
|
|
224
|
+
quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
|
|
225
|
+
if (debug || !quiet) {
|
|
226
|
+
const keysCount = Object.keys(populated).length;
|
|
227
|
+
const shortPaths = [];
|
|
228
|
+
for (const filePath of optionPaths) {
|
|
229
|
+
try {
|
|
230
|
+
const relative = path.relative(process.cwd(), filePath);
|
|
231
|
+
shortPaths.push(relative);
|
|
232
|
+
} catch (e) {
|
|
233
|
+
if (debug) {
|
|
234
|
+
_debug(`failed to load ${filePath} ${e.message}`);
|
|
235
|
+
}
|
|
236
|
+
lastError = e;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
_log(`injected env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
|
|
240
|
+
}
|
|
241
|
+
if (lastError) {
|
|
242
|
+
return { parsed: parsedAll, error: lastError };
|
|
243
|
+
} else {
|
|
244
|
+
return { parsed: parsedAll };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function config(options) {
|
|
248
|
+
if (_dotenvKey(options).length === 0) {
|
|
249
|
+
return DotenvModule.configDotenv(options);
|
|
250
|
+
}
|
|
251
|
+
const vaultPath = _vaultPath(options);
|
|
252
|
+
if (!vaultPath) {
|
|
253
|
+
_warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
|
|
254
|
+
return DotenvModule.configDotenv(options);
|
|
255
|
+
}
|
|
256
|
+
return DotenvModule._configVault(options);
|
|
257
|
+
}
|
|
258
|
+
function decrypt(encrypted, keyStr) {
|
|
259
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
260
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
261
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
262
|
+
const authTag = ciphertext.subarray(-16);
|
|
263
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
264
|
+
try {
|
|
265
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
266
|
+
aesgcm.setAuthTag(authTag);
|
|
267
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
const isRange = error instanceof RangeError;
|
|
270
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
271
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
272
|
+
if (isRange || invalidKeyLength) {
|
|
273
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
274
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
275
|
+
throw err;
|
|
276
|
+
} else if (decryptionFailed) {
|
|
277
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
278
|
+
err.code = "DECRYPTION_FAILED";
|
|
279
|
+
throw err;
|
|
280
|
+
} else {
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function populate(processEnv, parsed, options = {}) {
|
|
286
|
+
const debug = Boolean(options && options.debug);
|
|
287
|
+
const override = Boolean(options && options.override);
|
|
288
|
+
const populated = {};
|
|
289
|
+
if (typeof parsed !== "object") {
|
|
290
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
291
|
+
err.code = "OBJECT_REQUIRED";
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
294
|
+
for (const key of Object.keys(parsed)) {
|
|
295
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
296
|
+
if (override === true) {
|
|
297
|
+
processEnv[key] = parsed[key];
|
|
298
|
+
populated[key] = parsed[key];
|
|
299
|
+
}
|
|
300
|
+
if (debug) {
|
|
301
|
+
if (override === true) {
|
|
302
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
303
|
+
} else {
|
|
304
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
processEnv[key] = parsed[key];
|
|
309
|
+
populated[key] = parsed[key];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return populated;
|
|
313
|
+
}
|
|
314
|
+
var DotenvModule = {
|
|
315
|
+
configDotenv,
|
|
316
|
+
_configVault,
|
|
317
|
+
_parseVault,
|
|
318
|
+
config,
|
|
319
|
+
decrypt,
|
|
320
|
+
parse: parse2,
|
|
321
|
+
populate
|
|
322
|
+
};
|
|
323
|
+
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
324
|
+
module.exports._configVault = DotenvModule._configVault;
|
|
325
|
+
module.exports._parseVault = DotenvModule._parseVault;
|
|
326
|
+
module.exports.config = DotenvModule.config;
|
|
327
|
+
module.exports.decrypt = DotenvModule.decrypt;
|
|
328
|
+
module.exports.parse = DotenvModule.parse;
|
|
329
|
+
module.exports.populate = DotenvModule.populate;
|
|
330
|
+
module.exports = DotenvModule;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
3
333
|
|
|
4
334
|
// src/config/load.ts
|
|
335
|
+
var import_dotenv = __toESM(require_main(), 1);
|
|
5
336
|
import { mkdir as mkdir3, readFile as readFile3, writeFile } from "fs/promises";
|
|
6
337
|
import { join as join2 } from "path";
|
|
7
|
-
import { parse } from "dotenv";
|
|
8
|
-
|
|
9
|
-
// src/config/schema.ts
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
var PERMISSION_MODES = [
|
|
12
|
-
"default",
|
|
13
|
-
"acceptEdits",
|
|
14
|
-
"plan",
|
|
15
|
-
"bypassPermissions",
|
|
16
|
-
"auto",
|
|
17
|
-
"bubble"
|
|
18
|
-
];
|
|
19
|
-
function normalizePermissionMode(value) {
|
|
20
|
-
if (value === "safe" || value === "workspace") return "default";
|
|
21
|
-
if (value === "full") return "bypassPermissions";
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
var PermissionModeSchema = z.preprocess(
|
|
25
|
-
normalizePermissionMode,
|
|
26
|
-
z.enum(PERMISSION_MODES).default("default")
|
|
27
|
-
);
|
|
28
|
-
var ProviderConfigSchema = z.object({
|
|
29
|
-
type: z.string(),
|
|
30
|
-
baseURL: z.string().url().optional(),
|
|
31
|
-
apiKey: z.string().optional(),
|
|
32
|
-
defaultModel: z.string().min(1).optional(),
|
|
33
|
-
cheapModel: z.string().min(1).optional(),
|
|
34
|
-
models: z.array(z.string().min(1)).max(100).optional(),
|
|
35
|
-
maxOutputTokens: z.number().int().positive().optional(),
|
|
36
|
-
// Extended-thinking budget in output tokens for the Anthropic protocol.
|
|
37
|
-
// Defaults to DEFAULT_THINKING_BUDGET; set to 0 to disable the request
|
|
38
|
-
// parameter. Provider thinking deltas are forwarded whenever they arrive.
|
|
39
|
-
thinkingBudget: z.number().int().min(0).optional(),
|
|
40
|
-
// Reasoning effort requested from the OpenAI Responses protocol (sent as
|
|
41
|
-
// reasoning.effort). The adapter defaults an omitted value to high.
|
|
42
|
-
thinkingEffort: z.enum(["minimal", "low", "medium", "high", "xhigh", "ultra"]).optional(),
|
|
43
|
-
// Send the Claude Code client fingerprint (User-Agent/x-app) with Anthropic requests,
|
|
44
|
-
// for gateways that restrict the Anthropic protocol to Claude clients.
|
|
45
|
-
claudeClient: z.boolean().optional(),
|
|
46
|
-
// OAuth PKCE fields
|
|
47
|
-
apiType: z.enum(["openai", "anthropic"]).optional(),
|
|
48
|
-
authorizationUrl: z.string().url().optional(),
|
|
49
|
-
tokenUrl: z.string().url().optional(),
|
|
50
|
-
clientId: z.string().min(1).optional(),
|
|
51
|
-
scope: z.string().optional()
|
|
52
|
-
});
|
|
53
|
-
var McpServerCommonShape = {
|
|
54
|
-
disabled: z.boolean().default(false),
|
|
55
|
-
timeoutMs: z.number().int().min(100).max(30 * 6e4).default(6e4)
|
|
56
|
-
};
|
|
57
|
-
var McpStdioServerConfigSchema = z.object({
|
|
58
|
-
command: z.string().min(1),
|
|
59
|
-
args: z.array(z.string()).default([]),
|
|
60
|
-
env: z.record(z.string(), z.string()).default({}),
|
|
61
|
-
cwd: z.string().min(1).optional(),
|
|
62
|
-
...McpServerCommonShape
|
|
63
|
-
}).strict();
|
|
64
|
-
var McpHttpServerConfigSchema = z.object({
|
|
65
|
-
url: z.string().url().refine((value) => {
|
|
66
|
-
const protocol = new URL(value).protocol;
|
|
67
|
-
return protocol === "http:" || protocol === "https:";
|
|
68
|
-
}, "MCP HTTP URLs must use http or https"),
|
|
69
|
-
headers: z.record(z.string(), z.string()).default({}),
|
|
70
|
-
...McpServerCommonShape
|
|
71
|
-
}).strict();
|
|
72
|
-
var McpServerConfigSchema = z.union([
|
|
73
|
-
McpStdioServerConfigSchema,
|
|
74
|
-
McpHttpServerConfigSchema
|
|
75
|
-
]);
|
|
76
|
-
var McpServerNameSchema = z.string().min(1).max(32).regex(/^[A-Za-z0-9_-]+$/, "MCP server names may contain only letters, digits, underscores, and hyphens");
|
|
77
|
-
var SkillNameSchema = z.string().min(1).max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Skill names must use lowercase letters, digits, and single hyphens");
|
|
78
|
-
var FlavorConfigSchema = z.object({
|
|
79
|
-
sleep: z.boolean().default(false),
|
|
80
|
-
providers: z.record(z.string(), ProviderConfigSchema).default({}),
|
|
81
|
-
mcpServers: z.record(McpServerNameSchema, McpServerConfigSchema).default({}),
|
|
82
|
-
skills: z.object({
|
|
83
|
-
disabled: z.array(SkillNameSchema).max(1e3).default([])
|
|
84
|
-
}).prefault({}),
|
|
85
|
-
agents: z.object({
|
|
86
|
-
main: z.object({ model: z.string() }).optional(),
|
|
87
|
-
subagent: z.object({ model: z.string() }).optional()
|
|
88
|
-
}).optional(),
|
|
89
|
-
maxSubagents: z.number().int().min(1).max(16).default(3),
|
|
90
|
-
maxSessions: z.number().int().min(1).max(1e3).default(50),
|
|
91
|
-
memory: z.object({
|
|
92
|
-
enabled: z.boolean().default(true),
|
|
93
|
-
autoExtract: z.boolean().default(true),
|
|
94
|
-
autoExtractMinChars: z.number().int().min(200).max(1e5).default(200),
|
|
95
|
-
scoreThreshold: z.number().int().min(0).max(12).default(9),
|
|
96
|
-
autoStoreThreshold: z.number().int().min(0).max(12).default(11),
|
|
97
|
-
ignoreStreakLimit: z.number().int().min(2).max(100).default(5),
|
|
98
|
-
reviewAutoDismissSeconds: z.number().int().min(0).max(300).default(5),
|
|
99
|
-
// One candidate per task is a deliberate memory-quality boundary, not a tunable range.
|
|
100
|
-
maxCandidatesPerTask: z.literal(1).default(1),
|
|
101
|
-
retrievalTopK: z.number().int().min(1).max(20).default(5),
|
|
102
|
-
maxEntries: z.number().int().min(1).max(1e4).default(200),
|
|
103
|
-
maxEntryChars: z.number().int().min(32).max(2e4).default(1e3),
|
|
104
|
-
maxPromptChars: z.number().int().min(256).max(2e5).default(12e3)
|
|
105
|
-
}).prefault({}),
|
|
106
|
-
permissionMode: PermissionModeSchema,
|
|
107
|
-
execution: z.object({
|
|
108
|
-
mode: z.enum(["local", "docker"]).default("local"),
|
|
109
|
-
image: z.string().trim().min(1).default("node:24-bookworm-slim"),
|
|
110
|
-
network: z.boolean().default(false),
|
|
111
|
-
memory: z.string().regex(/^[1-9][0-9]*(?:[kKmMgG])?$/).default("2g"),
|
|
112
|
-
cpus: z.number().positive().max(64).default(2)
|
|
113
|
-
}).prefault({}),
|
|
114
|
-
language: z.string().regex(/^[a-z]{2}(-[A-Z]{2})?$/, "language must be a BCP47 tag like zh-CN or en-US").optional(),
|
|
115
|
-
hallucination: z.object({
|
|
116
|
-
showWarnings: z.boolean().default(false),
|
|
117
|
-
evaluationTimeoutMs: z.number().int().min(100).max(3e4).default(2e3)
|
|
118
|
-
}).prefault({}),
|
|
119
|
-
maxIterations: z.object({
|
|
120
|
-
main: z.number().int().min(10).max(500).default(300),
|
|
121
|
-
subagent: z.number().int().min(10).max(200).default(100),
|
|
122
|
-
softLimitFactor: z.number().min(0.5).max(1).default(0.8),
|
|
123
|
-
extendBy: z.number().int().min(5).max(100).default(50)
|
|
124
|
-
}).prefault({}),
|
|
125
|
-
loop: z.object({
|
|
126
|
-
maxCycles: z.number().int().positive().max(1e4).default(100),
|
|
127
|
-
maxTokens: z.number().int().positive().max(Number.MAX_SAFE_INTEGER).default(5e5),
|
|
128
|
-
isolation: z.literal("auto").default("auto")
|
|
129
|
-
}).prefault({}),
|
|
130
|
-
goal: z.object({
|
|
131
|
-
maxRounds: z.number().int().positive().max(1e4).default(100),
|
|
132
|
-
maxStallStreak: z.number().int().positive().max(100).default(3)
|
|
133
|
-
}).prefault({}),
|
|
134
|
-
context: z.object({
|
|
135
|
-
windowTokens: z.number().int().positive().default(2e5),
|
|
136
|
-
reservedOutputTokens: z.number().int().nonnegative().default(2e4),
|
|
137
|
-
autoCompactBufferTokens: z.number().int().nonnegative().default(27e3),
|
|
138
|
-
warningBufferTokens: z.number().int().nonnegative().default(2e4),
|
|
139
|
-
blockingBufferTokens: z.number().int().nonnegative().default(3e3),
|
|
140
|
-
microcompactKeepRecentToolResults: z.number().int().nonnegative().default(5),
|
|
141
|
-
recentTokens: z.number().int().nonnegative().default(1e4),
|
|
142
|
-
recentTextMessages: z.number().int().nonnegative().default(5),
|
|
143
|
-
maxRecentTokens: z.number().int().nonnegative().default(4e4),
|
|
144
|
-
/** @deprecated Character threshold retained for configuration compatibility. */
|
|
145
|
-
compactAtChars: z.number().int().positive().optional(),
|
|
146
|
-
toolOutputChars: z.number().int().positive().default(3e4)
|
|
147
|
-
}).superRefine((context, issue) => {
|
|
148
|
-
if (context.reservedOutputTokens >= context.windowTokens) issue.addIssue({
|
|
149
|
-
code: "custom",
|
|
150
|
-
path: ["reservedOutputTokens"],
|
|
151
|
-
message: "reservedOutputTokens must be below windowTokens"
|
|
152
|
-
});
|
|
153
|
-
if (context.maxRecentTokens < context.recentTokens) issue.addIssue({
|
|
154
|
-
code: "custom",
|
|
155
|
-
path: ["maxRecentTokens"],
|
|
156
|
-
message: "maxRecentTokens must be at least recentTokens"
|
|
157
|
-
});
|
|
158
|
-
}).prefault({}),
|
|
159
|
-
incidents: z.object({
|
|
160
|
-
enabled: z.boolean().default(false),
|
|
161
|
-
webhookUrl: z.string().url().optional()
|
|
162
|
-
}).prefault({}),
|
|
163
|
-
evolve: z.object({
|
|
164
|
-
promptTop: z.number().int().min(1).max(10).default(3),
|
|
165
|
-
minRepeats: z.number().int().min(2).max(100).default(2),
|
|
166
|
-
testCommand: z.string().trim().min(1).default("npm test"),
|
|
167
|
-
testTimeoutMs: z.number().int().min(1e3).max(6e5).default(12e4)
|
|
168
|
-
}).prefault({})
|
|
169
|
-
});
|
|
170
338
|
|
|
171
339
|
// src/config/protected-file.ts
|
|
172
340
|
import { randomUUID } from "crypto";
|
|
@@ -535,8 +703,8 @@ async function loadConfig(options) {
|
|
|
535
703
|
const globalEnvText = await readTextIfPresent(globalEnvPath);
|
|
536
704
|
const projectEnvText = await readTextIfPresent(envPath);
|
|
537
705
|
const projectEnvironment = {
|
|
538
|
-
...globalEnvText === void 0 ? {} : parse(globalEnvText),
|
|
539
|
-
...projectEnvText === void 0 ? {} : parse(projectEnvText)
|
|
706
|
+
...globalEnvText === void 0 ? {} : (0, import_dotenv.parse)(globalEnvText),
|
|
707
|
+
...projectEnvText === void 0 ? {} : (0, import_dotenv.parse)(projectEnvText)
|
|
540
708
|
};
|
|
541
709
|
if (globalEnvText !== void 0) sources.push(globalEnvPath);
|
|
542
710
|
if (projectEnvText !== void 0) sources.push(envPath);
|
|
@@ -686,6 +854,53 @@ async function setProjectProviderConfig(cwd, providerName, provider) {
|
|
|
686
854
|
});
|
|
687
855
|
return path;
|
|
688
856
|
}
|
|
857
|
+
async function setProjectConfigValue(cwd, home, key, value) {
|
|
858
|
+
const segments = configPathSegments(key);
|
|
859
|
+
const nested = segments.reduceRight(
|
|
860
|
+
(acc, segment) => ({ [segment]: acc }),
|
|
861
|
+
value
|
|
862
|
+
);
|
|
863
|
+
await loadConfig({ cwd, home, cli: nested, seedGlobalEnv: false });
|
|
864
|
+
const path = join2(cwd, ".flavor", "flavor.json");
|
|
865
|
+
await updateProtectedFile({
|
|
866
|
+
path,
|
|
867
|
+
decode: (raw) => parseConfigObject(path, raw),
|
|
868
|
+
encode: (next) => `${JSON.stringify(next, null, 2)}
|
|
869
|
+
`,
|
|
870
|
+
update: (current) => setPathIn({ ...current ?? {} }, segments, value)
|
|
871
|
+
});
|
|
872
|
+
return path;
|
|
873
|
+
}
|
|
874
|
+
async function unsetProjectConfigValue(cwd, key) {
|
|
875
|
+
const segments = configPathSegments(key);
|
|
876
|
+
const path = join2(cwd, ".flavor", "flavor.json");
|
|
877
|
+
await updateProtectedFile({
|
|
878
|
+
path,
|
|
879
|
+
decode: (raw) => parseConfigObject(path, raw),
|
|
880
|
+
encode: (next) => `${JSON.stringify(next, null, 2)}
|
|
881
|
+
`,
|
|
882
|
+
update: (current) => deletePathIn({ ...current ?? {} }, segments)
|
|
883
|
+
});
|
|
884
|
+
return path;
|
|
885
|
+
}
|
|
886
|
+
function setPathIn(target, segments, value) {
|
|
887
|
+
const [head, ...rest] = segments;
|
|
888
|
+
if (head === void 0) return target;
|
|
889
|
+
if (rest.length === 0) return { ...target, [head]: value };
|
|
890
|
+
const child = isPlainObject(target[head]) ? target[head] : {};
|
|
891
|
+
return { ...target, [head]: setPathIn(child, rest, value) };
|
|
892
|
+
}
|
|
893
|
+
function deletePathIn(target, segments) {
|
|
894
|
+
const [head, ...rest] = segments;
|
|
895
|
+
if (head === void 0 || !(head in target)) return target;
|
|
896
|
+
if (rest.length === 0) {
|
|
897
|
+
const { [head]: _removed, ...remainder } = target;
|
|
898
|
+
return remainder;
|
|
899
|
+
}
|
|
900
|
+
const child = isPlainObject(target[head]) ? target[head] : void 0;
|
|
901
|
+
if (child === void 0) return target;
|
|
902
|
+
return { ...target, [head]: deletePathIn(child, rest) };
|
|
903
|
+
}
|
|
689
904
|
function redactConfig(config) {
|
|
690
905
|
if (Array.isArray(config)) {
|
|
691
906
|
return config.map((item) => redactConfig(item));
|
|
@@ -702,12 +917,6 @@ function redactConfig(config) {
|
|
|
702
917
|
}
|
|
703
918
|
|
|
704
919
|
export {
|
|
705
|
-
PERMISSION_MODES,
|
|
706
|
-
normalizePermissionMode,
|
|
707
|
-
PermissionModeSchema,
|
|
708
|
-
McpServerConfigSchema,
|
|
709
|
-
McpServerNameSchema,
|
|
710
|
-
SkillNameSchema,
|
|
711
920
|
readRecoverableFile,
|
|
712
921
|
updateProtectedFile,
|
|
713
922
|
encryptDocument,
|
|
@@ -718,5 +927,7 @@ export {
|
|
|
718
927
|
setProjectSkillDisabled,
|
|
719
928
|
setGlobalProviderConfig,
|
|
720
929
|
setProjectProviderConfig,
|
|
930
|
+
setProjectConfigValue,
|
|
931
|
+
unsetProjectConfigValue,
|
|
721
932
|
redactConfig
|
|
722
933
|
};
|