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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/utils/intl.ts
|
|
5
|
+
var graphemeSegmenter;
|
|
6
|
+
function getGraphemeSegmenter() {
|
|
7
|
+
return graphemeSegmenter ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
8
|
+
}
|
|
9
|
+
function detectSystemLocale() {
|
|
10
|
+
try {
|
|
11
|
+
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
12
|
+
if (locale && locale.length >= 2) return locale;
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
for (const key of ["LANG", "LC_ALL", "LC_MESSAGES"]) {
|
|
16
|
+
const raw = process.env[key];
|
|
17
|
+
if (!raw || raw === "C" || raw === "POSIX") continue;
|
|
18
|
+
const match = raw.match(/^([a-z]{2})_([A-Z]{2})(?:[.@].*)?$/);
|
|
19
|
+
if (match) return `${match[1]}-${match[2]}`;
|
|
20
|
+
}
|
|
21
|
+
return "zh-CN";
|
|
22
|
+
}
|
|
23
|
+
function resolveLanguage(explicit) {
|
|
24
|
+
if (explicit !== void 0) return explicit;
|
|
25
|
+
return detectSystemLocale();
|
|
26
|
+
}
|
|
27
|
+
function languageInstruction(language) {
|
|
28
|
+
const label = LANG_LABELS.get(language) ?? language;
|
|
29
|
+
return `Always respond in ${label}. Do NOT reply in any other language unless the user explicitly asks for it.`;
|
|
30
|
+
}
|
|
31
|
+
var LANG_LABELS = /* @__PURE__ */ new Map([
|
|
32
|
+
["zh-CN", "Simplified Chinese (zh-CN)"],
|
|
33
|
+
["zh-TW", "Traditional Chinese (zh-TW)"],
|
|
34
|
+
["zh-HK", "Traditional Chinese (zh-HK)"],
|
|
35
|
+
["ja-JP", "Japanese (ja-JP)"],
|
|
36
|
+
["ko-KR", "Korean (ko-KR)"],
|
|
37
|
+
["en-US", "English (en-US)"],
|
|
38
|
+
["en-GB", "English (en-GB)"],
|
|
39
|
+
["fr-FR", "French (fr-FR)"],
|
|
40
|
+
["de-DE", "German (de-DE)"],
|
|
41
|
+
["es-ES", "Spanish (es-ES)"],
|
|
42
|
+
["pt-BR", "Portuguese (pt-BR)"],
|
|
43
|
+
["ru-RU", "Russian (ru-RU)"],
|
|
44
|
+
["ar-SA", "Arabic (ar-SA)"],
|
|
45
|
+
["vi-VN", "Vietnamese (vi-VN)"],
|
|
46
|
+
["th-TH", "Thai (th-TH)"],
|
|
47
|
+
["id-ID", "Indonesian (id-ID)"]
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
// src/utils/envUtils.ts
|
|
51
|
+
function isEnvTruthy(value) {
|
|
52
|
+
if (typeof value === "boolean") return value;
|
|
53
|
+
return value === "1" || value?.toLowerCase() === "true" || value?.toLowerCase() === "yes";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
isEnvTruthy,
|
|
58
|
+
getGraphemeSegmenter,
|
|
59
|
+
resolveLanguage,
|
|
60
|
+
languageInstruction
|
|
61
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/utils/redact.ts
|
|
5
|
+
function redactErrorText(text) {
|
|
6
|
+
return text.replace(/\bsk-[A-Za-z0-9_-]+\b/g, "[redacted]").replace(/(authorization|api[_ -]?key|token)\s*[:=]\s*\S+/gi, "$1=[redacted]");
|
|
7
|
+
}
|
|
8
|
+
function redactSecrets(input, secrets) {
|
|
9
|
+
return secrets.reduce((text, secret) => text.replaceAll(secret, "[redacted]"), input);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
redactErrorText,
|
|
14
|
+
redactSecrets
|
|
15
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/utils/usage-summary.ts
|
|
5
|
+
function asNumber(value) {
|
|
6
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
7
|
+
}
|
|
8
|
+
function parseUsageEntries(raw) {
|
|
9
|
+
const entries = [];
|
|
10
|
+
for (const line of raw.split("\n")) {
|
|
11
|
+
const trimmed = line.trim();
|
|
12
|
+
if (trimmed.length === 0) continue;
|
|
13
|
+
let parsed;
|
|
14
|
+
try {
|
|
15
|
+
parsed = JSON.parse(trimmed);
|
|
16
|
+
} catch {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (parsed.event !== "flavor-usage") continue;
|
|
20
|
+
if (typeof parsed.provider !== "string" || typeof parsed.model !== "string") continue;
|
|
21
|
+
entries.push({
|
|
22
|
+
event: "flavor-usage",
|
|
23
|
+
sessionId: typeof parsed.sessionId === "string" ? parsed.sessionId : void 0,
|
|
24
|
+
provider: parsed.provider,
|
|
25
|
+
model: parsed.model,
|
|
26
|
+
inputTokens: asNumber(parsed.inputTokens),
|
|
27
|
+
cacheReadTokens: asNumber(parsed.cacheReadTokens),
|
|
28
|
+
cacheCreationTokens: asNumber(parsed.cacheCreationTokens),
|
|
29
|
+
totalInputTokens: asNumber(parsed.totalInputTokens),
|
|
30
|
+
cacheHitRatio: asNumber(parsed.cacheHitRatio)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return entries;
|
|
34
|
+
}
|
|
35
|
+
function summarizeUsage(entries) {
|
|
36
|
+
const groups = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
const key = `${entry.provider}:${entry.model}`;
|
|
39
|
+
let stats = groups.get(key);
|
|
40
|
+
if (stats === void 0) {
|
|
41
|
+
stats = {
|
|
42
|
+
provider: entry.provider,
|
|
43
|
+
model: entry.model,
|
|
44
|
+
requests: 0,
|
|
45
|
+
inputTokens: 0,
|
|
46
|
+
cacheReadTokens: 0,
|
|
47
|
+
cacheCreationTokens: 0,
|
|
48
|
+
totalInputTokens: 0,
|
|
49
|
+
minHitRatio: Number.POSITIVE_INFINITY,
|
|
50
|
+
averageHitRatio: 0
|
|
51
|
+
};
|
|
52
|
+
groups.set(key, stats);
|
|
53
|
+
}
|
|
54
|
+
stats.requests += 1;
|
|
55
|
+
stats.inputTokens += entry.inputTokens;
|
|
56
|
+
stats.cacheReadTokens += entry.cacheReadTokens;
|
|
57
|
+
stats.cacheCreationTokens += entry.cacheCreationTokens;
|
|
58
|
+
stats.totalInputTokens += entry.totalInputTokens;
|
|
59
|
+
stats.minHitRatio = Math.min(stats.minHitRatio, entry.cacheHitRatio);
|
|
60
|
+
stats.averageHitRatio += entry.cacheHitRatio;
|
|
61
|
+
}
|
|
62
|
+
const byModel = [...groups.values()].map((stats) => ({
|
|
63
|
+
...stats,
|
|
64
|
+
minHitRatio: Number.isFinite(stats.minHitRatio) ? stats.minHitRatio : 0,
|
|
65
|
+
averageHitRatio: stats.requests > 0 ? stats.averageHitRatio / stats.requests : 0
|
|
66
|
+
})).sort((left, right) => right.totalInputTokens - left.totalInputTokens);
|
|
67
|
+
const totalInputTokens = entries.reduce((sum, entry) => sum + entry.totalInputTokens, 0);
|
|
68
|
+
const totalCacheReadTokens = entries.reduce((sum, entry) => sum + entry.cacheReadTokens, 0);
|
|
69
|
+
return {
|
|
70
|
+
requests: entries.length,
|
|
71
|
+
sessionId: entries.length > 0 ? entries[entries.length - 1]?.sessionId : void 0,
|
|
72
|
+
byModel,
|
|
73
|
+
totalInputTokens,
|
|
74
|
+
totalCacheReadTokens,
|
|
75
|
+
cacheShare: totalInputTokens > 0 ? totalCacheReadTokens / totalInputTokens : 0
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function formatTokens(value) {
|
|
79
|
+
if (value < 1e3) return String(value);
|
|
80
|
+
return `${(value / 1e3).toFixed(1)}k`;
|
|
81
|
+
}
|
|
82
|
+
function formatUsageSummary(summary) {
|
|
83
|
+
if (summary.requests === 0) return "No usage recorded in this session yet.";
|
|
84
|
+
const sessionLabel = summary.sessionId ?? "unknown";
|
|
85
|
+
const header = `Usage for session ${sessionLabel} (${summary.requests} request${summary.requests === 1 ? "" : "s"}):`;
|
|
86
|
+
const columns = summary.byModel.map((stats) => [
|
|
87
|
+
stats.provider,
|
|
88
|
+
stats.model,
|
|
89
|
+
String(stats.requests),
|
|
90
|
+
`${stats.minHitRatio.toFixed(2)}\u2192${stats.averageHitRatio.toFixed(2)}`,
|
|
91
|
+
formatTokens(stats.inputTokens),
|
|
92
|
+
formatTokens(stats.cacheReadTokens),
|
|
93
|
+
formatTokens(stats.cacheCreationTokens)
|
|
94
|
+
]);
|
|
95
|
+
const titles = ["provider", "model", "reqs", "hit(min\u2192avg)", "input", "cacheRead", "cacheWrite"];
|
|
96
|
+
const widths = titles.map(
|
|
97
|
+
(title, index) => Math.max(title.length, ...columns.map((row) => row[index]?.length ?? 0))
|
|
98
|
+
);
|
|
99
|
+
const render = (row, indent) => indent + row.map((cell, index) => cell.padEnd(widths[index] ?? cell.length)).join(" ").trimEnd();
|
|
100
|
+
const table = [render(titles, " "), ...columns.map((row) => render(row, " "))].join("\n");
|
|
101
|
+
const cachePercent = (summary.cacheShare * 100).toFixed(1);
|
|
102
|
+
const total = `Total input tokens: ${formatTokens(summary.totalInputTokens)} (cache read ${formatTokens(summary.totalCacheReadTokens)}, ${cachePercent}%)`;
|
|
103
|
+
return `${header}
|
|
104
|
+
|
|
105
|
+
${table}
|
|
106
|
+
|
|
107
|
+
${total}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
parseUsageEntries,
|
|
112
|
+
summarizeUsage,
|
|
113
|
+
formatUsageSummary
|
|
114
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
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
3
|
|
|
4
4
|
// src/ui/task-progress-model.ts
|
|
5
5
|
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
@@ -1,5 +1,5 @@
|
|
|
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
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -15,6 +15,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
15
15
|
var __commonJS = (cb, mod) => function __require2() {
|
|
16
16
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
17
|
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
+
};
|
|
18
22
|
var __copyProps = (to, from, except, desc) => {
|
|
19
23
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
24
|
for (let key of __getOwnPropNames(from))
|
|
@@ -35,5 +39,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
35
39
|
export {
|
|
36
40
|
__require,
|
|
37
41
|
__commonJS,
|
|
42
|
+
__export,
|
|
38
43
|
__toESM
|
|
39
44
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
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
3
|
import {
|
|
4
4
|
AlternateScreen,
|
|
5
5
|
Box_default,
|
|
@@ -10,9 +10,14 @@ import {
|
|
|
10
10
|
useStdout,
|
|
11
11
|
use_app_default,
|
|
12
12
|
use_input_default
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-T6RE76D2.js";
|
|
14
|
+
import "./chunk-PULWAH6E.js";
|
|
15
|
+
import "./chunk-AA4QNKTF.js";
|
|
16
|
+
import "./chunk-TIEOVQW6.js";
|
|
17
|
+
import "./chunk-IU3UBETC.js";
|
|
18
|
+
import "./chunk-3UX2CGDW.js";
|
|
19
|
+
import "./chunk-KRWWCVXA.js";
|
|
20
|
+
import "./chunk-ZKKVSR37.js";
|
|
16
21
|
export {
|
|
17
22
|
AlternateScreen,
|
|
18
23
|
Box_default as Box,
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as createFlavorRequire } from "node:module"; const require = createFlavorRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
createExecutionEnvironment,
|
|
5
|
+
createProductionRuntime
|
|
6
|
+
} from "./chunk-IDJAHEG6.js";
|
|
7
|
+
import "./chunk-TIEOVQW6.js";
|
|
8
|
+
import "./chunk-OKHV7CTB.js";
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_MAX_OUTPUT_BYTES,
|
|
11
|
+
executeShell
|
|
12
|
+
} from "./chunk-K7UGGWJV.js";
|
|
13
|
+
import "./chunk-IU3UBETC.js";
|
|
14
|
+
import "./chunk-PZ5NKRVA.js";
|
|
15
|
+
import "./chunk-6F66UXBI.js";
|
|
16
|
+
import "./chunk-3UX2CGDW.js";
|
|
17
|
+
import "./chunk-7Y64WNBB.js";
|
|
18
|
+
import "./chunk-CVP5OUHD.js";
|
|
19
|
+
import "./chunk-3563SW4X.js";
|
|
20
|
+
import "./chunk-RBAZLFKB.js";
|
|
21
|
+
import "./chunk-FAJ6YDZK.js";
|
|
22
|
+
import "./chunk-WLZUAVVU.js";
|
|
23
|
+
import "./chunk-RV3EXUXM.js";
|
|
24
|
+
import "./chunk-IQEEFDEE.js";
|
|
25
|
+
import "./chunk-GTFP2R5I.js";
|
|
26
|
+
import "./chunk-HGTCIHWA.js";
|
|
27
|
+
import "./chunk-SJUIIHIA.js";
|
|
28
|
+
import "./chunk-BDX777JR.js";
|
|
29
|
+
import "./chunk-6X62CGMA.js";
|
|
30
|
+
import {
|
|
31
|
+
external_exports
|
|
32
|
+
} from "./chunk-EWD7FWTH.js";
|
|
33
|
+
import "./chunk-KRWWCVXA.js";
|
|
34
|
+
import "./chunk-X442CJJH.js";
|
|
35
|
+
import "./chunk-ZKKVSR37.js";
|
|
36
|
+
|
|
37
|
+
// src/eval/cli.ts
|
|
38
|
+
import { readFile, writeFile } from "fs/promises";
|
|
39
|
+
import { dirname, resolve } from "path";
|
|
40
|
+
|
|
41
|
+
// src/execution/local.ts
|
|
42
|
+
var LocalExecutionEnvironment = class {
|
|
43
|
+
kind = "local";
|
|
44
|
+
exec(request, signal) {
|
|
45
|
+
const cancellation = signal ?? new AbortController().signal;
|
|
46
|
+
return executeShell(request.cwd, {
|
|
47
|
+
command: request.command,
|
|
48
|
+
args: [...request.args],
|
|
49
|
+
cwd: request.cwd,
|
|
50
|
+
...request.timeoutMs === void 0 ? {} : { timeoutMs: request.timeoutMs }
|
|
51
|
+
}, cancellation, DEFAULT_MAX_OUTPUT_BYTES);
|
|
52
|
+
}
|
|
53
|
+
async dispose() {
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/eval/schema.ts
|
|
58
|
+
var EvaluationSpecSchema = external_exports.object({
|
|
59
|
+
name: external_exports.string().trim().min(1).max(256),
|
|
60
|
+
workspace: external_exports.string().trim().min(1).max(32768),
|
|
61
|
+
prompt: external_exports.string().trim().min(1).max(1e6),
|
|
62
|
+
verification: external_exports.array(external_exports.object({
|
|
63
|
+
command: external_exports.string().trim().min(1).max(32768),
|
|
64
|
+
args: external_exports.array(external_exports.string()).max(1e3),
|
|
65
|
+
timeoutMs: external_exports.number().int().positive().max(864e5).optional()
|
|
66
|
+
}).strict()).min(1).max(100),
|
|
67
|
+
maxTokens: external_exports.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional()
|
|
68
|
+
}).strict();
|
|
69
|
+
|
|
70
|
+
// src/eval/runner.ts
|
|
71
|
+
var DEFAULT_VERIFICATION_TIMEOUT_MS = 10 * 6e4;
|
|
72
|
+
async function runEvaluation(spec, dependencies) {
|
|
73
|
+
const now = dependencies.now ?? Date.now;
|
|
74
|
+
const started = now();
|
|
75
|
+
let input = 0;
|
|
76
|
+
let output = 0;
|
|
77
|
+
const runtime = await dependencies.createRuntime({
|
|
78
|
+
workspace: spec.workspace,
|
|
79
|
+
output: (event) => {
|
|
80
|
+
if (event.type === "usage") {
|
|
81
|
+
input = event.totalInputTokens;
|
|
82
|
+
output = event.totalOutputTokens;
|
|
83
|
+
} else if (event.type === "done" && input === 0 && output === 0) {
|
|
84
|
+
input = event.usage.inputTokens;
|
|
85
|
+
output = event.usage.outputTokens;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
await runtime.session.start();
|
|
91
|
+
await runtime.session.submit(spec.prompt);
|
|
92
|
+
} finally {
|
|
93
|
+
await runtime.session.close();
|
|
94
|
+
await runtime.dispose();
|
|
95
|
+
}
|
|
96
|
+
const verification = [];
|
|
97
|
+
for (const check of spec.verification) {
|
|
98
|
+
const result = await dependencies.executionEnvironment.exec({
|
|
99
|
+
command: check.command,
|
|
100
|
+
args: check.args,
|
|
101
|
+
cwd: spec.workspace,
|
|
102
|
+
timeoutMs: check.timeoutMs ?? DEFAULT_VERIFICATION_TIMEOUT_MS
|
|
103
|
+
});
|
|
104
|
+
verification.push({
|
|
105
|
+
command: [check.command, ...check.args].join(" "),
|
|
106
|
+
exitCode: result.exitCode,
|
|
107
|
+
passed: result.exitCode === 0,
|
|
108
|
+
stdout: result.stdout,
|
|
109
|
+
stderr: result.stderr
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const total = input + output;
|
|
113
|
+
const withinBudget = spec.maxTokens === void 0 || total <= spec.maxTokens;
|
|
114
|
+
return {
|
|
115
|
+
name: spec.name,
|
|
116
|
+
workspace: spec.workspace,
|
|
117
|
+
passed: withinBudget && verification.every((item) => item.passed),
|
|
118
|
+
durationMs: Math.max(0, now() - started),
|
|
119
|
+
tokens: { input, output, total, withinBudget },
|
|
120
|
+
verification
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/eval/cli.ts
|
|
125
|
+
async function runEvaluationFile(path, outputPath) {
|
|
126
|
+
const specPath = resolve(path);
|
|
127
|
+
const parsed = EvaluationSpecSchema.parse(JSON.parse(await readFile(specPath, "utf8")));
|
|
128
|
+
const workspace = resolve(dirname(specPath), parsed.workspace);
|
|
129
|
+
const spec = {
|
|
130
|
+
name: parsed.name,
|
|
131
|
+
prompt: parsed.prompt,
|
|
132
|
+
workspace,
|
|
133
|
+
verification: parsed.verification.map((step) => ({
|
|
134
|
+
command: step.command,
|
|
135
|
+
args: step.args,
|
|
136
|
+
...step.timeoutMs === void 0 ? {} : { timeoutMs: step.timeoutMs }
|
|
137
|
+
})),
|
|
138
|
+
...parsed.maxTokens === void 0 ? {} : { maxTokens: parsed.maxTokens }
|
|
139
|
+
};
|
|
140
|
+
const configured = await import("./load-QK6CMLDF.js").then(({ loadConfig }) => loadConfig({ cwd: workspace, home: process.env.USERPROFILE ?? process.env.HOME ?? workspace }));
|
|
141
|
+
const environment = createExecutionEnvironment(workspace, configured.config.execution) ?? new LocalExecutionEnvironment();
|
|
142
|
+
let report;
|
|
143
|
+
try {
|
|
144
|
+
report = await runEvaluation(spec, {
|
|
145
|
+
createRuntime: (options) => createProductionRuntime({
|
|
146
|
+
...options,
|
|
147
|
+
home: process.env.USERPROFILE ?? process.env.HOME ?? workspace,
|
|
148
|
+
approvalPolicy: "deny"
|
|
149
|
+
}),
|
|
150
|
+
executionEnvironment: environment
|
|
151
|
+
});
|
|
152
|
+
} finally {
|
|
153
|
+
await environment.dispose();
|
|
154
|
+
}
|
|
155
|
+
const body = `${JSON.stringify(report, null, 2)}
|
|
156
|
+
`;
|
|
157
|
+
if (outputPath === void 0) process.stdout.write(body);
|
|
158
|
+
else await writeFile(resolve(outputPath), body, "utf8");
|
|
159
|
+
return report.passed ? 0 : 1;
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
runEvaluationFile
|
|
163
|
+
};
|