flavor-code 1.4.2 → 1.4.3
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 +53 -1
- package/README.zh-CN.md +53 -1
- package/dist/agent/loop.d.ts +1 -0
- package/dist/{app-4CUS3GEJ.js → app-TVY2HM5L.js} +891 -604
- 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-36IDJRLQ.js +630 -0
- package/dist/chunk-3UX2CGDW.js +1955 -0
- package/dist/chunk-4TMLXZVZ.js +75 -0
- package/dist/{chunk-7YFHRORG.js → chunk-5BDKRA6U.js} +412 -172
- package/dist/chunk-6F66UXBI.js +48 -0
- package/dist/{chunk-KMBDK4SN.js → chunk-6URQ7FIF.js} +24 -88
- 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-N5MXHJKD.js → chunk-GTFP2R5I.js} +1 -1
- package/dist/{chunk-W2TIY6JY.js → chunk-IKGT4MDT.js} +2028 -516
- package/dist/chunk-IQEEFDEE.js +389 -0
- package/dist/chunk-IU3UBETC.js +30 -0
- package/dist/chunk-JQM2L2YM.js +1003 -0
- package/dist/chunk-KRWWCVXA.js +74 -0
- package/dist/chunk-OKHV7CTB.js +482 -0
- package/dist/chunk-ONRY3C2L.js +196 -0
- package/dist/chunk-PULWAH6E.js +474 -0
- package/dist/chunk-PZ5NKRVA.js +85 -0
- package/dist/chunk-QACFKPZP.js +43704 -0
- package/dist/chunk-RBAZLFKB.js +1022 -0
- package/dist/chunk-RV3EXUXM.js +30 -0
- package/dist/chunk-TIEOVQW6.js +61 -0
- package/dist/chunk-WLZUAVVU.js +15 -0
- package/dist/chunk-X442CJJH.js +114 -0
- package/dist/chunk-X6U6BO5D.js +2130 -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-VQU3C5UL.js → claude-ink-F554I3GJ.js} +9 -4
- package/dist/cli-MAWCV2YR.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/protected-file.d.ts +2 -0
- package/dist/config/schema.d.ts +14 -0
- package/dist/context/global-instructions.d.ts +12 -0
- package/dist/context/manager.d.ts +4 -0
- package/dist/desktop/main.js +4943 -1562
- package/dist/desktop/preload.cjs +30 -0
- package/dist/desktop-renderer/assets/index-BWklSoOO.css +1 -0
- package/dist/desktop-renderer/assets/index-CjC0Ibiq.js +153 -0
- package/dist/desktop-renderer/assets/{interactive-terminal-ouQQ3brz.js → interactive-terminal-IjIT3Xoa.js} +1 -1
- package/dist/desktop-renderer/index.html +2 -2
- package/dist/doctor-SEL32R7M.js +20 -0
- package/dist/harness/local.d.ts +1 -0
- package/dist/load-RHWXNUCS.js +25 -0
- package/dist/log-ATFIPRNU.js +19 -0
- package/dist/manager-IYBNNKUP.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-TQROFEPV.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-MZZERW7K.js +18 -0
- package/dist/ui/commands.d.ts +11 -3
- package/dist/ui/session.d.ts +2 -1
- package/dist/usage-summary-G5FBOJLK.js +13 -0
- package/dist/write-stream-CGD57URC.js +77 -0
- package/package.json +1 -1
- package//346/212/200/346/234/257/346/226/271/346/241/210/346/212/245/345/221/212.md +649 -1
- package/dist/chunk-B23V72YR.js +0 -170
- package/dist/chunk-QKND3FX7.js +0 -26103
- package/dist/desktop-renderer/assets/index-Bk6FYhyh.css +0 -1
- package/dist/desktop-renderer/assets/index-CPXrzFgv.js +0 -154
- package/dist/load-UPOG3XQR.js +0 -19
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
redactErrorText,
|
|
5
|
+
redactSecrets
|
|
6
|
+
} from "./chunk-WLZUAVVU.js";
|
|
7
|
+
import {
|
|
8
|
+
external_exports
|
|
9
|
+
} from "./chunk-EWD7FWTH.js";
|
|
10
|
+
|
|
11
|
+
// src/trace/recorder.ts
|
|
12
|
+
import { mkdir, open } from "fs/promises";
|
|
13
|
+
import { dirname, resolve } from "path";
|
|
14
|
+
|
|
15
|
+
// src/trace/schema.ts
|
|
16
|
+
var TraceKindSchema = external_exports.enum(["command", "response", "output", "queue", "history", "verification"]);
|
|
17
|
+
var TraceRecordSchema = external_exports.object({
|
|
18
|
+
version: external_exports.literal(1),
|
|
19
|
+
sequence: external_exports.number().int().positive(),
|
|
20
|
+
timestamp: external_exports.string().datetime(),
|
|
21
|
+
sessionId: external_exports.string().min(1),
|
|
22
|
+
kind: TraceKindSchema,
|
|
23
|
+
payload: external_exports.unknown()
|
|
24
|
+
}).strict();
|
|
25
|
+
|
|
26
|
+
// src/trace/recorder.ts
|
|
27
|
+
var TraceRecorder = class {
|
|
28
|
+
path;
|
|
29
|
+
#sessionId;
|
|
30
|
+
#secrets;
|
|
31
|
+
#now;
|
|
32
|
+
#sequence = 0;
|
|
33
|
+
#handle;
|
|
34
|
+
#tail = Promise.resolve();
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.path = resolve(options.path);
|
|
37
|
+
this.#sessionId = options.sessionId;
|
|
38
|
+
this.#secrets = options.secrets ?? [];
|
|
39
|
+
this.#now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
40
|
+
}
|
|
41
|
+
record(kind, payload) {
|
|
42
|
+
const sequence = ++this.#sequence;
|
|
43
|
+
this.#tail = this.#tail.then(async () => {
|
|
44
|
+
const handle = await this.#file();
|
|
45
|
+
const serialized = redactErrorText(redactSecrets(JSON.stringify(payload) ?? "null", this.#secrets));
|
|
46
|
+
const record = TraceRecordSchema.parse({
|
|
47
|
+
version: 1,
|
|
48
|
+
sequence,
|
|
49
|
+
timestamp: this.#now().toISOString(),
|
|
50
|
+
sessionId: this.#sessionId,
|
|
51
|
+
kind,
|
|
52
|
+
payload: JSON.parse(serialized)
|
|
53
|
+
});
|
|
54
|
+
await handle.appendFile(`${JSON.stringify(record)}
|
|
55
|
+
`, "utf8");
|
|
56
|
+
});
|
|
57
|
+
return this.#tail;
|
|
58
|
+
}
|
|
59
|
+
async close() {
|
|
60
|
+
await this.#tail;
|
|
61
|
+
await this.#handle?.close();
|
|
62
|
+
this.#handle = void 0;
|
|
63
|
+
}
|
|
64
|
+
async #file() {
|
|
65
|
+
if (this.#handle !== void 0) return this.#handle;
|
|
66
|
+
await mkdir(dirname(this.path), { recursive: true });
|
|
67
|
+
this.#handle = await open(this.path, "a", 384);
|
|
68
|
+
return this.#handle;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
TraceRecordSchema,
|
|
74
|
+
TraceRecorder
|
|
75
|
+
};
|
|
@@ -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-ONRY3C2L.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";
|
|
@@ -208,6 +376,34 @@ async function updateProtectedFile(options) {
|
|
|
208
376
|
return next;
|
|
209
377
|
}, options.lockTimeoutMs ?? LOCK_TIMEOUT_MS, options.staleLockMs ?? STALE_LOCK_MS);
|
|
210
378
|
}
|
|
379
|
+
async function updatePlainTextFile(path, update, maxBytes) {
|
|
380
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
381
|
+
return withFileLock(path, async () => {
|
|
382
|
+
const current = await readOptionalPlainText(path, maxBytes);
|
|
383
|
+
const next = await update(current);
|
|
384
|
+
if (next === void 0 || next === current) return current;
|
|
385
|
+
if (await readOptionalPlainText(path, maxBytes) !== current) {
|
|
386
|
+
throw new Error(`Text file changed while the update was prepared: ${path}`);
|
|
387
|
+
}
|
|
388
|
+
await writeAtomic(path, next, defaultFileOperations);
|
|
389
|
+
return next;
|
|
390
|
+
}, LOCK_TIMEOUT_MS, STALE_LOCK_MS);
|
|
391
|
+
}
|
|
392
|
+
async function readOptionalPlainText(path, maxBytes) {
|
|
393
|
+
try {
|
|
394
|
+
if (maxBytes !== void 0 && (await stat(path)).size > maxBytes) {
|
|
395
|
+
throw new Error(`Text file exceeds ${maxBytes} bytes: ${path}`);
|
|
396
|
+
}
|
|
397
|
+
const bytes = await readFile(path);
|
|
398
|
+
if (maxBytes !== void 0 && bytes.length > maxBytes) {
|
|
399
|
+
throw new Error(`Text file exceeds ${maxBytes} bytes: ${path}`);
|
|
400
|
+
}
|
|
401
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
if (isCode(error, "ENOENT")) return void 0;
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
211
407
|
async function withFileLock(path, operation, lockTimeoutMs, staleLockMs) {
|
|
212
408
|
const lockPath = `${path}.lock`;
|
|
213
409
|
const token = JSON.stringify({ pid: process.pid, nonce: randomUUID() });
|
|
@@ -535,8 +731,8 @@ async function loadConfig(options) {
|
|
|
535
731
|
const globalEnvText = await readTextIfPresent(globalEnvPath);
|
|
536
732
|
const projectEnvText = await readTextIfPresent(envPath);
|
|
537
733
|
const projectEnvironment = {
|
|
538
|
-
...globalEnvText === void 0 ? {} : parse(globalEnvText),
|
|
539
|
-
...projectEnvText === void 0 ? {} : parse(projectEnvText)
|
|
734
|
+
...globalEnvText === void 0 ? {} : (0, import_dotenv.parse)(globalEnvText),
|
|
735
|
+
...projectEnvText === void 0 ? {} : (0, import_dotenv.parse)(projectEnvText)
|
|
540
736
|
};
|
|
541
737
|
if (globalEnvText !== void 0) sources.push(globalEnvPath);
|
|
542
738
|
if (projectEnvText !== void 0) sources.push(envPath);
|
|
@@ -686,6 +882,53 @@ async function setProjectProviderConfig(cwd, providerName, provider) {
|
|
|
686
882
|
});
|
|
687
883
|
return path;
|
|
688
884
|
}
|
|
885
|
+
async function setProjectConfigValue(cwd, home, key, value) {
|
|
886
|
+
const segments = configPathSegments(key);
|
|
887
|
+
const nested = segments.reduceRight(
|
|
888
|
+
(acc, segment) => ({ [segment]: acc }),
|
|
889
|
+
value
|
|
890
|
+
);
|
|
891
|
+
await loadConfig({ cwd, home, cli: nested, seedGlobalEnv: false });
|
|
892
|
+
const path = join2(cwd, ".flavor", "flavor.json");
|
|
893
|
+
await updateProtectedFile({
|
|
894
|
+
path,
|
|
895
|
+
decode: (raw) => parseConfigObject(path, raw),
|
|
896
|
+
encode: (next) => `${JSON.stringify(next, null, 2)}
|
|
897
|
+
`,
|
|
898
|
+
update: (current) => setPathIn({ ...current ?? {} }, segments, value)
|
|
899
|
+
});
|
|
900
|
+
return path;
|
|
901
|
+
}
|
|
902
|
+
async function unsetProjectConfigValue(cwd, key) {
|
|
903
|
+
const segments = configPathSegments(key);
|
|
904
|
+
const path = join2(cwd, ".flavor", "flavor.json");
|
|
905
|
+
await updateProtectedFile({
|
|
906
|
+
path,
|
|
907
|
+
decode: (raw) => parseConfigObject(path, raw),
|
|
908
|
+
encode: (next) => `${JSON.stringify(next, null, 2)}
|
|
909
|
+
`,
|
|
910
|
+
update: (current) => deletePathIn({ ...current ?? {} }, segments)
|
|
911
|
+
});
|
|
912
|
+
return path;
|
|
913
|
+
}
|
|
914
|
+
function setPathIn(target, segments, value) {
|
|
915
|
+
const [head, ...rest] = segments;
|
|
916
|
+
if (head === void 0) return target;
|
|
917
|
+
if (rest.length === 0) return { ...target, [head]: value };
|
|
918
|
+
const child = isPlainObject(target[head]) ? target[head] : {};
|
|
919
|
+
return { ...target, [head]: setPathIn(child, rest, value) };
|
|
920
|
+
}
|
|
921
|
+
function deletePathIn(target, segments) {
|
|
922
|
+
const [head, ...rest] = segments;
|
|
923
|
+
if (head === void 0 || !(head in target)) return target;
|
|
924
|
+
if (rest.length === 0) {
|
|
925
|
+
const { [head]: _removed, ...remainder } = target;
|
|
926
|
+
return remainder;
|
|
927
|
+
}
|
|
928
|
+
const child = isPlainObject(target[head]) ? target[head] : void 0;
|
|
929
|
+
if (child === void 0) return target;
|
|
930
|
+
return { ...target, [head]: deletePathIn(child, rest) };
|
|
931
|
+
}
|
|
689
932
|
function redactConfig(config) {
|
|
690
933
|
if (Array.isArray(config)) {
|
|
691
934
|
return config.map((item) => redactConfig(item));
|
|
@@ -702,14 +945,9 @@ function redactConfig(config) {
|
|
|
702
945
|
}
|
|
703
946
|
|
|
704
947
|
export {
|
|
705
|
-
PERMISSION_MODES,
|
|
706
|
-
normalizePermissionMode,
|
|
707
|
-
PermissionModeSchema,
|
|
708
|
-
McpServerConfigSchema,
|
|
709
|
-
McpServerNameSchema,
|
|
710
|
-
SkillNameSchema,
|
|
711
948
|
readRecoverableFile,
|
|
712
949
|
updateProtectedFile,
|
|
950
|
+
updatePlainTextFile,
|
|
713
951
|
encryptDocument,
|
|
714
952
|
decryptDocument,
|
|
715
953
|
loadOrCreateConfigKey,
|
|
@@ -718,5 +956,7 @@ export {
|
|
|
718
956
|
setProjectSkillDisabled,
|
|
719
957
|
setGlobalProviderConfig,
|
|
720
958
|
setProjectProviderConfig,
|
|
959
|
+
setProjectConfigValue,
|
|
960
|
+
unsetProjectConfigValue,
|
|
721
961
|
redactConfig
|
|
722
962
|
};
|