@ouro.bot/cli 0.1.0-alpha.1409 → 0.1.0-alpha.1410
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.json +12 -1
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/eval/budget.js +135 -0
- package/dist/eval/remote-entry.js +28 -0
- package/dist/eval/report.js +85 -0
- package/dist/eval/run-command.js +151 -0
- package/dist/eval/run-entry.js +68 -0
- package/dist/eval/sandbox/oracle.js +31 -0
- package/dist/eval/sandbox/remote.js +97 -0
- package/dist/eval/targets/index.js +127 -0
- package/dist/eval/transport/provider-proxy.js +1 -0
- package/dist/heart/daemon/cli-commands/entry-points.js +4 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
package/changelog.json
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "Each pull request writes its own change note under changes/; the release job on main gives each landed change its version and adds the notes here (scripts/release-version.cjs). On main this file stops at the last version set by hand; the published package has every release. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1410",
|
|
6
|
+
"changes": [
|
|
7
|
+
"npm run eval runs the replay eval's cases on a real model (GitHub Copilot or MiniMax) against one bundle, in the sandbox locally or on another Docker host over ssh. Every run reserves its worst-case spend first, in premium requests and in credits, refuses to start without a Copilot multiplier or, for a pay-per-token target, without a credits cap, stops on the first 402 or 429, and writes a private report with pass@1 and Wilson intervals."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1409",
|
|
6
12
|
"changes": [
|
|
7
|
-
"Update the Ouro UI files to Ouro UI v1.3.465.",
|
|
8
13
|
"Status shows Teams, voice, A2A or Telegram as an error, with failure layer `live_turn_stall`, when one of its turns has gone quiet for five minutes, or for 15 while a tool call is running. Until now only iMessage could show a stalled turn."
|
|
9
14
|
]
|
|
10
15
|
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.1.0-alpha.1408",
|
|
18
|
+
"changes": [
|
|
19
|
+
"Update the Ouro UI files to Ouro UI v1.3.465."
|
|
20
|
+
]
|
|
21
|
+
},
|
|
11
22
|
{
|
|
12
23
|
"version": "0.1.0-alpha.1407",
|
|
13
24
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1410</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.creditsOf = creditsOf;
|
|
4
|
+
exports.createBudgetLedger = createBudgetLedger;
|
|
5
|
+
exports.meteredRuntime = meteredRuntime;
|
|
6
|
+
const runtime_1 = require("../nerves/runtime");
|
|
7
|
+
const METERS = ["premium", "credits"];
|
|
8
|
+
const zero = () => ({ premium: 0, credits: 0 });
|
|
9
|
+
const round = (value) => Math.round(value * 1e6) / 1e6;
|
|
10
|
+
const finite = (value) => Number.isFinite(value) && value >= 0;
|
|
11
|
+
function creditsOf(usage, pricing) {
|
|
12
|
+
return round((usage.input_tokens * pricing.creditsPerMillionInput + usage.output_tokens * pricing.creditsPerMillionOutput) / 1_000_000);
|
|
13
|
+
}
|
|
14
|
+
function createBudgetLedger(caps) {
|
|
15
|
+
for (const meter of METERS) {
|
|
16
|
+
const cap = caps[meter];
|
|
17
|
+
if (cap !== undefined && !finite(cap))
|
|
18
|
+
throw new Error(`the ${meter} cap must be a number of at least 0`);
|
|
19
|
+
}
|
|
20
|
+
const spent = zero();
|
|
21
|
+
const held = zero();
|
|
22
|
+
let calls = 0;
|
|
23
|
+
let stopReason;
|
|
24
|
+
const stop = (reason) => {
|
|
25
|
+
if (stopReason !== undefined)
|
|
26
|
+
return;
|
|
27
|
+
stopReason = reason;
|
|
28
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "warn", event: "eval.budget_stopped", message: "the eval budget stopped all further model calls", meta: { reason, spent: { ...spent } } });
|
|
29
|
+
};
|
|
30
|
+
const charge = (meter, amount) => {
|
|
31
|
+
spent[meter] = round(spent[meter] + amount);
|
|
32
|
+
const cap = caps[meter];
|
|
33
|
+
if (cap !== undefined && spent[meter] > cap)
|
|
34
|
+
stop(`${meter} cap ${cap} passed: ${spent[meter]} spent`);
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
stop,
|
|
38
|
+
stopped: () => stopReason,
|
|
39
|
+
totals: () => ({ spent: { ...spent }, held: { ...held }, calls, caps: { ...caps } }),
|
|
40
|
+
reserve(label, worst) {
|
|
41
|
+
if (!Number.isInteger(worst.calls) || worst.calls < 1)
|
|
42
|
+
throw new Error("a reservation needs at least 1 call");
|
|
43
|
+
if (!METERS.every((meter) => finite(worst.perCall[meter])))
|
|
44
|
+
throw new Error("a reservation's per-call cost must be numbers of at least 0");
|
|
45
|
+
if (stopReason !== undefined)
|
|
46
|
+
return { refused: `stopped: ${stopReason}` };
|
|
47
|
+
const total = { premium: round(worst.calls * worst.perCall.premium), credits: round(worst.calls * worst.perCall.credits) };
|
|
48
|
+
for (const meter of METERS) {
|
|
49
|
+
const cap = caps[meter];
|
|
50
|
+
if (cap !== undefined && spent[meter] + held[meter] + total[meter] > cap) {
|
|
51
|
+
const refused = `${label} would pass the ${meter} cap ${cap}: ${spent[meter]} spent, ${held[meter]} held, ${total[meter]} more at worst`;
|
|
52
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.budget_refused", message: "refused a reservation that could pass a cap", meta: { label, meter } });
|
|
53
|
+
return { refused };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const meter of METERS)
|
|
57
|
+
held[meter] = round(held[meter] + total[meter]);
|
|
58
|
+
const remaining = { ...total };
|
|
59
|
+
const mine = zero();
|
|
60
|
+
let taken = 0;
|
|
61
|
+
let open = true;
|
|
62
|
+
let cut = false;
|
|
63
|
+
let maxCall = 0;
|
|
64
|
+
const unhold = (meter, amount) => {
|
|
65
|
+
const back = Math.min(amount, remaining[meter]);
|
|
66
|
+
remaining[meter] = round(remaining[meter] - back);
|
|
67
|
+
held[meter] = round(held[meter] - back);
|
|
68
|
+
};
|
|
69
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.budget_reserved", message: "reserved a session's worst-case model spend", meta: { label, ...total } });
|
|
70
|
+
return {
|
|
71
|
+
take() {
|
|
72
|
+
if (!open || stopReason !== undefined || taken >= worst.calls)
|
|
73
|
+
return false;
|
|
74
|
+
if (worst.perCall.credits > 0 && round(mine.credits + worst.perCall.credits) > total.credits) {
|
|
75
|
+
cut = true;
|
|
76
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "warn", event: "eval.budget_cut_short", message: "refused a call past its session's credit reservation", meta: { label, spent: mine.credits } });
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
taken += 1;
|
|
80
|
+
calls += 1;
|
|
81
|
+
unhold("premium", worst.perCall.premium);
|
|
82
|
+
mine.premium = round(mine.premium + worst.perCall.premium);
|
|
83
|
+
charge("premium", worst.perCall.premium);
|
|
84
|
+
return true;
|
|
85
|
+
},
|
|
86
|
+
settle(usage) {
|
|
87
|
+
const credits = usage ? creditsOf(usage, worst.pricing) : worst.perCall.credits;
|
|
88
|
+
unhold("credits", worst.perCall.credits);
|
|
89
|
+
mine.credits = round(mine.credits + credits);
|
|
90
|
+
maxCall = Math.max(maxCall, credits);
|
|
91
|
+
charge("credits", credits);
|
|
92
|
+
},
|
|
93
|
+
cutShort: () => cut,
|
|
94
|
+
maxCall: () => maxCall,
|
|
95
|
+
release() {
|
|
96
|
+
open = false;
|
|
97
|
+
for (const meter of METERS)
|
|
98
|
+
unhold(meter, remaining[meter]);
|
|
99
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.budget_released", message: "released a session's unspent reservation", meta: { label, ...mine } });
|
|
100
|
+
return { ...mine };
|
|
101
|
+
},
|
|
102
|
+
spent: () => ({ ...mine }),
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const STOPPING_STATUS = new Set([402, 429]);
|
|
108
|
+
/** The runtime with each call's usage settled on `hold`; a failed call is billed, and a 402, 429 or usage or rate limit stops the ledger. */
|
|
109
|
+
function meteredRuntime(inner, hold, ledger) {
|
|
110
|
+
const streamTurn = async (request) => {
|
|
111
|
+
try {
|
|
112
|
+
const result = await inner.streamTurn(request);
|
|
113
|
+
hold.settle(result.usage);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
catch (caught) {
|
|
117
|
+
hold.settle(undefined);
|
|
118
|
+
const error = caught instanceof Error ? caught : new Error(String(caught));
|
|
119
|
+
const status = error.status;
|
|
120
|
+
const classification = inner.classifyError(error);
|
|
121
|
+
if ((typeof status === "number" && STOPPING_STATUS.has(status)) || classification === "usage-limit" || classification === "rate-limit") {
|
|
122
|
+
ledger.stop(`the provider answered ${typeof status === "number" ? status : classification}: ${error.message}`);
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return new Proxy(inner, {
|
|
128
|
+
get(target, property) {
|
|
129
|
+
if (property === "streamTurn")
|
|
130
|
+
return streamTurn;
|
|
131
|
+
const value = Reflect.get(target, property);
|
|
132
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Runs on the remote Docker host for `npm run eval -- --sandbox-ssh`: `node dist/eval/remote-entry.js`, started over
|
|
5
|
+
* ssh. It reads one job from stdin, runs that case in the sandbox here with the model served from the other end of
|
|
6
|
+
* the same channel (see `sandbox/remote.ts`), answers with the observation and exits. It holds no credential and no
|
|
7
|
+
* budget: the calling side enforces both.
|
|
8
|
+
*/
|
|
9
|
+
const runtime_1 = require("../nerves/runtime");
|
|
10
|
+
const case_1 = require("./domain/case");
|
|
11
|
+
const docker_1 = require("./sandbox/docker");
|
|
12
|
+
const oracle_1 = require("./sandbox/oracle");
|
|
13
|
+
const remote_1 = require("./sandbox/remote");
|
|
14
|
+
void (0, remote_1.serveRemoteJob)({
|
|
15
|
+
stdin: process.stdin,
|
|
16
|
+
stdout: process.stdout,
|
|
17
|
+
run: (job, host) => {
|
|
18
|
+
const docker = (0, docker_1.dockerCli)();
|
|
19
|
+
return (0, docker_1.runSandboxed)({
|
|
20
|
+
case: (0, case_1.validateCase)(job.case), bundleDir: job.bundleDir, seedBundleDir: job.seedBundleDir, host, budget: { take: () => true }, docker,
|
|
21
|
+
...(job.workRoot ? { workRoot: job.workRoot } : {}),
|
|
22
|
+
...(job.oracleBooks ? { oracle: (0, oracle_1.dockerOracle)({ docker, image: docker_1.HOUSEHOLD_IMAGE, booksLib: job.oracleBooks }) } : {}),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
}).then((outcome) => process.exit(outcome.ok ? 0 : 1)).catch((error) => {
|
|
26
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.remote_entry_error", message: "the remote sandbox entry failed", meta: { error: String(error) } });
|
|
27
|
+
process.exit(1);
|
|
28
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.gradeRun = gradeRun;
|
|
7
|
+
exports.withoutBooksRemove = withoutBooksRemove;
|
|
8
|
+
exports.buildCells = buildCells;
|
|
9
|
+
exports.summarize = summarize;
|
|
10
|
+
exports.writePrivateReport = writePrivateReport;
|
|
11
|
+
/**
|
|
12
|
+
* Grading runs into cells and writing what an eval run found. A cell is one (case, target, bundle ref): pass@1 is
|
|
13
|
+
* passes over finished runs with a Wilson 95% interval. A run passes only when its turn settled and every check
|
|
14
|
+
* passed; a turn that errored, was aborted or was refused a call fails with that reason, never skipped or retried.
|
|
15
|
+
*
|
|
16
|
+
* The full report, every observation included, is private: created once (`wx`) with mode 0600 in a 0700 folder. The
|
|
17
|
+
* summary holds scores, counts, spend and fidelity gaps, never trace or reply text, so it can go into a task card.
|
|
18
|
+
* `RunResult` (schemaVersion 1) is the format the census joins on by action id.
|
|
19
|
+
*/
|
|
20
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
21
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
22
|
+
const runtime_1 = require("../nerves/runtime");
|
|
23
|
+
const stats_1 = require("./domain/stats");
|
|
24
|
+
function gradeRun(obs, graded) {
|
|
25
|
+
if (obs.outcome !== "settled")
|
|
26
|
+
return { passed: false, reason: `outcome ${obs.outcome}` };
|
|
27
|
+
if (graded.passed)
|
|
28
|
+
return { passed: true, reason: null };
|
|
29
|
+
return { passed: false, reason: `failed ${graded.checks.filter((check) => !check.ok).map((check) => check.name).join(", ")}` };
|
|
30
|
+
}
|
|
31
|
+
const BOOKS_REMOVE = /\bbooks\b[^\n]*\blibrary\s+(remove|replace)\b/;
|
|
32
|
+
/** Whether no tool call ran the books CLI's `library remove` or `library replace`. */
|
|
33
|
+
function withoutBooksRemove(obs) {
|
|
34
|
+
return !obs.timeline.some((entry) => entry.kind === "call" && BOOKS_REMOVE.test(entry.args));
|
|
35
|
+
}
|
|
36
|
+
function buildCells(cases, at, runs) {
|
|
37
|
+
return cases.map((c) => {
|
|
38
|
+
const mine = runs.filter((run) => run.caseId === c.id && !run.budgetCut);
|
|
39
|
+
const passes = mine.filter((run) => run.passed).length;
|
|
40
|
+
const interval = (0, stats_1.wilsonInterval)(passes, mine.length);
|
|
41
|
+
const reasons = {};
|
|
42
|
+
for (const run of mine)
|
|
43
|
+
if (run.reason)
|
|
44
|
+
reasons[run.reason] = (reasons[run.reason] ?? 0) + 1;
|
|
45
|
+
return {
|
|
46
|
+
caseId: c.id, actionIds: [...c.actionIds], target: at.target, bundleRef: at.bundleRef, harnessRef: at.harnessRef,
|
|
47
|
+
planned: at.planned, completed: mine.length, notRun: at.planned - mine.length, passes,
|
|
48
|
+
passAt1: mine.length === 0 ? null : passes / mine.length,
|
|
49
|
+
interval: { low: interval.low, high: interval.high },
|
|
50
|
+
reasons,
|
|
51
|
+
passesViaShellFallback: mine.filter((run) => run.passed && run.viaShellFallback).length,
|
|
52
|
+
fidelityGaps: [...new Set(mine.flatMap((run) => run.gaps))].sort(),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** Only called for a cell with finished runs, whose score and bounds are numbers. */
|
|
57
|
+
const fixed = (value) => Number(value).toFixed(2);
|
|
58
|
+
function summarize(input) {
|
|
59
|
+
const lines = [`${input.target} on ${input.bundleRef}`];
|
|
60
|
+
for (const cell of input.cells) {
|
|
61
|
+
const score = cell.completed === 0 ? "0/0 (unscored)" : `${cell.passes}/${cell.completed} = ${fixed(cell.passAt1)} [${fixed(cell.interval.low)}, ${fixed(cell.interval.high)}]`;
|
|
62
|
+
const reasons = Object.entries(cell.reasons).map(([reason, count]) => `${reason} x${count}`).join("; ");
|
|
63
|
+
lines.push(` ${cell.caseId}: ${score}${cell.notRun ? `, ${cell.notRun} not run` : ""}${cell.passesViaShellFallback ? `, ${cell.passesViaShellFallback} passed by shell` : ""}${reasons ? `; ${reasons}` : ""}`);
|
|
64
|
+
}
|
|
65
|
+
lines.push(` spent: premium requests ${input.spent.premium}, credits ${input.spent.credits}`);
|
|
66
|
+
const remaining = (snapshot) => snapshot.reading?.remaining == null ? "unknown" : String(snapshot.reading.remaining);
|
|
67
|
+
lines.push(` Copilot premium remaining: ${remaining(input.quota.before)} before, ${remaining(input.quota.after)} after; token-billed: ${input.quota.after.tokenBased ?? input.quota.before.tokenBased ?? "unknown"}`);
|
|
68
|
+
lines.push(` fidelity gaps: ${[...new Set(input.cells.flatMap((cell) => cell.fidelityGaps))].sort().join(", ") || "none"}`);
|
|
69
|
+
if (input.stopped)
|
|
70
|
+
lines.push(` stopped: ${input.stopped}`);
|
|
71
|
+
return lines.join("\n");
|
|
72
|
+
}
|
|
73
|
+
/** Writes `report` to a new file, mode 0600, making its folder 0700; refuses a file that already exists. */
|
|
74
|
+
function writePrivateReport(file, report) {
|
|
75
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true, mode: 0o700 });
|
|
76
|
+
node_fs_1.default.chmodSync(node_path_1.default.dirname(file), 0o700);
|
|
77
|
+
const fd = node_fs_1.default.openSync(file, "wx", 0o600);
|
|
78
|
+
try {
|
|
79
|
+
node_fs_1.default.writeFileSync(fd, `${JSON.stringify(report, null, 2)}\n`);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
node_fs_1.default.closeSync(fd);
|
|
83
|
+
}
|
|
84
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.report_written", message: "wrote a private eval report", meta: { file } });
|
|
85
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CALLS_PER_RUN = void 0;
|
|
4
|
+
exports.parseEvalArgs = parseEvalArgs;
|
|
5
|
+
exports.runEvalCommand = runEvalCommand;
|
|
6
|
+
/**
|
|
7
|
+
* `npm run eval -- ...`: runs every case N times on one model target and one bundle, each run from scratch in the
|
|
8
|
+
* sandbox, judged once, never retried. Before anything is spent it refuses a case that fails its self-test, an
|
|
9
|
+
* output file that already exists, a Copilot target with no premium multiplier (see `targets`), and, without a credits
|
|
10
|
+
* cap and prices, any target billed by the token: MiniMax, and a Copilot account that is token-billed or not known not
|
|
11
|
+
* to be.
|
|
12
|
+
*
|
|
13
|
+
* Every run first reserves its worst case on the ledger: the turn's call ceiling (`MAX_PROVIDER_ITERATIONS_CEILING`
|
|
14
|
+
* plus the step-budget report call) times the per-call premium multiplier and the per-call credit estimate, raised to
|
|
15
|
+
* the most one call has cost so far. When a reservation would pass a cap, the command stops there. A run whose
|
|
16
|
+
* calls outgrow its own credit reservation is cut short and not scored (it counts as not run), and the next run
|
|
17
|
+
* reserves more. The first 402 or 429 also stops the command. Either way the report keeps every finished run, and the
|
|
18
|
+
* run the provider cut short counts as failed. The command exits 2 when it stopped early.
|
|
19
|
+
*/
|
|
20
|
+
const core_1 = require("../heart/core");
|
|
21
|
+
const runtime_1 = require("../nerves/runtime");
|
|
22
|
+
const assertions_1 = require("./assertions");
|
|
23
|
+
const budget_1 = require("./budget");
|
|
24
|
+
const report_1 = require("./report");
|
|
25
|
+
const self_test_1 = require("./self-test");
|
|
26
|
+
/** The most model calls one turn can make: the step-budget ceiling, plus the report call it asks for when used up. */
|
|
27
|
+
exports.CALLS_PER_RUN = core_1.MAX_PROVIDER_ITERATIONS_CEILING + 1;
|
|
28
|
+
const STRING_FLAGS = {
|
|
29
|
+
"--cases": "cases", "--bundle": "bundle", "--bundle-ref": "bundleRef", "--target": "target", "--credentials-agent": "credentialsAgent",
|
|
30
|
+
"--copilot-account": "copilotAccount", "--output": "output", "--harness-ref": "harnessRef", "--seed-bundle": "seedBundle",
|
|
31
|
+
"--oracle-books": "oracleBooks", "--sandbox-ssh": "sandboxSsh",
|
|
32
|
+
};
|
|
33
|
+
const NUMBER_FLAGS = {
|
|
34
|
+
"--runs": "runs", "--budget-premium": "budgetPremium", "--budget-credits": "budgetCredits", "--price-in": "priceIn", "--price-out": "priceOut",
|
|
35
|
+
"--reserve-credits-per-call": "reserveCreditsPerCall", "--premium-multiplier": "premiumMultiplier",
|
|
36
|
+
};
|
|
37
|
+
const REQUIRED = ["--cases", "--bundle", "--bundle-ref", "--target", "--runs", "--budget-premium", "--credentials-agent", "--output"];
|
|
38
|
+
function parseEvalArgs(argv) {
|
|
39
|
+
const out = { caseIds: [], harnessRef: "unknown" };
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
for (let i = 0; i < argv.length; i += 2) {
|
|
42
|
+
const flag = argv[i];
|
|
43
|
+
const value = argv[i + 1];
|
|
44
|
+
if (flag !== "--case" && !Object.hasOwn(STRING_FLAGS, flag) && !Object.hasOwn(NUMBER_FLAGS, flag))
|
|
45
|
+
throw new Error(`unknown flag ${flag}`);
|
|
46
|
+
if (value === undefined)
|
|
47
|
+
throw new Error(`${flag} needs a value`);
|
|
48
|
+
seen.add(flag);
|
|
49
|
+
if (flag === "--case") {
|
|
50
|
+
out.caseIds.push(value);
|
|
51
|
+
}
|
|
52
|
+
else if (Object.hasOwn(STRING_FLAGS, flag)) {
|
|
53
|
+
out[STRING_FLAGS[flag]] = value;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const number = Number(value);
|
|
57
|
+
if (flag === "--runs" ? !(Number.isInteger(number) && number >= 1) : !(Number.isFinite(number) && number >= 0)) {
|
|
58
|
+
throw new Error(flag === "--runs" ? "--runs must be a whole number of at least 1" : `${flag} must be a number of at least 0`);
|
|
59
|
+
}
|
|
60
|
+
out[NUMBER_FLAGS[flag]] = number;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const missing = REQUIRED.find((flag) => !seen.has(flag));
|
|
64
|
+
if (missing)
|
|
65
|
+
throw new Error(`${missing} is required`);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function failedRun(outcome) {
|
|
69
|
+
return { timeline: [], finalReply: "", library: [], mail: [], created: [], outcome, steps: 0, oracle: {}, gaps: [] };
|
|
70
|
+
}
|
|
71
|
+
async function runEvalCommand(args, deps) {
|
|
72
|
+
const all = (deps.loadCases ?? self_test_1.loadCases)(args.cases);
|
|
73
|
+
const unknown = args.caseIds.find((id) => !all.some((c) => c.id === id));
|
|
74
|
+
if (unknown)
|
|
75
|
+
throw new Error(`no case ${unknown} in ${args.cases}`);
|
|
76
|
+
const cases = args.caseIds.length > 0 ? all.filter((c) => args.caseIds.includes(c.id)) : all;
|
|
77
|
+
const broken = cases.map((c) => ({ id: c.id, ...(0, self_test_1.selfTest)(c) })).filter((tested) => !tested.ok);
|
|
78
|
+
if (broken.length > 0)
|
|
79
|
+
throw new Error(`refusing to spend on cases that fail their self-test: ${broken.map((b) => `${b.id} (${b.problems.join("; ")})`).join(", ")}`);
|
|
80
|
+
if (deps.outputExists(args.output))
|
|
81
|
+
throw new Error(`${args.output} already exists; name a new report file`);
|
|
82
|
+
const target = await deps.resolveTarget(args.target, {
|
|
83
|
+
agent: args.credentialsAgent,
|
|
84
|
+
...(args.copilotAccount ? { copilotAccount: args.copilotAccount } : {}),
|
|
85
|
+
...(args.premiumMultiplier !== undefined ? { premiumMultiplier: args.premiumMultiplier } : {}),
|
|
86
|
+
});
|
|
87
|
+
const before = await target.quota();
|
|
88
|
+
if (args.budgetCredits === undefined && (target.account === null || before.tokenBased !== false)) {
|
|
89
|
+
const who = target.account === null ? `${args.target} is billed by the token` : `${target.account} is token-billed (or not known not to be)`;
|
|
90
|
+
throw new Error(`${who}; pass --budget-credits with --price-in, --price-out and --reserve-credits-per-call`);
|
|
91
|
+
}
|
|
92
|
+
if (args.budgetCredits !== undefined && (args.priceIn === undefined || args.priceOut === undefined || args.reserveCreditsPerCall === undefined)) {
|
|
93
|
+
throw new Error("a credits cap needs --price-in, --price-out and --reserve-credits-per-call (credits per million tokens, and per call)");
|
|
94
|
+
}
|
|
95
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.run_command_start", message: "starting an eval model run", meta: { target: args.target, bundleRef: args.bundleRef, runs: args.runs, cases: cases.length } });
|
|
96
|
+
const ledger = (0, budget_1.createBudgetLedger)({ premium: args.budgetPremium, ...(args.budgetCredits !== undefined ? { credits: args.budgetCredits } : {}) });
|
|
97
|
+
const pricing = { premiumPerCall: target.unitCost, creditsPerMillionInput: args.priceIn ?? 0, creditsPerMillionOutput: args.priceOut ?? 0 };
|
|
98
|
+
let perCallCredits = args.reserveCreditsPerCall ?? 0;
|
|
99
|
+
const runCase = deps.runCase(args);
|
|
100
|
+
const runs = [];
|
|
101
|
+
let stopped;
|
|
102
|
+
outer: for (const c of cases) {
|
|
103
|
+
for (let run = 1; run <= args.runs; run += 1) {
|
|
104
|
+
const reserved = { premium: target.unitCost, credits: perCallCredits };
|
|
105
|
+
const hold = ledger.reserve(`${c.id} run ${run}`, { calls: exports.CALLS_PER_RUN, perCall: reserved, pricing });
|
|
106
|
+
if ("refused" in hold) {
|
|
107
|
+
stopped = hold.refused;
|
|
108
|
+
break outer;
|
|
109
|
+
}
|
|
110
|
+
let obs;
|
|
111
|
+
let sandboxError;
|
|
112
|
+
try {
|
|
113
|
+
obs = await runCase({ case: c, host: (0, budget_1.meteredRuntime)(target.runtime, hold, ledger), budget: hold });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
sandboxError = error.message;
|
|
117
|
+
obs = failedRun(`sandbox-error: ${sandboxError}`);
|
|
118
|
+
}
|
|
119
|
+
const spent = hold.release();
|
|
120
|
+
const budgetCut = hold.cutShort();
|
|
121
|
+
const graded = (0, assertions_1.evaluate)(c, obs);
|
|
122
|
+
const verdict = budgetCut ? { passed: false, reason: "cut short by its credit reservation" } : (0, report_1.gradeRun)(obs, graded);
|
|
123
|
+
const { gaps, ...observation } = obs;
|
|
124
|
+
runs.push({
|
|
125
|
+
caseId: c.id, run, ...verdict, outcome: obs.outcome, steps: obs.steps, spent, reserved, budgetCut, checks: graded.checks, gaps,
|
|
126
|
+
viaShellFallback: verdict.passed && (0, report_1.withoutBooksRemove)(obs), observation,
|
|
127
|
+
});
|
|
128
|
+
perCallCredits = Math.max(perCallCredits, hold.maxCall());
|
|
129
|
+
if (ledger.stopped()) {
|
|
130
|
+
stopped = ledger.stopped();
|
|
131
|
+
break outer;
|
|
132
|
+
}
|
|
133
|
+
if (sandboxError !== undefined) {
|
|
134
|
+
stopped = `the sandbox failed: ${sandboxError}`;
|
|
135
|
+
break outer;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const after = await target.quota();
|
|
140
|
+
const totals = ledger.totals();
|
|
141
|
+
const cells = (0, report_1.buildCells)(cases, { target: args.target, bundleRef: args.bundleRef, harnessRef: args.harnessRef, planned: args.runs }, runs);
|
|
142
|
+
const result = {
|
|
143
|
+
schemaVersion: 1, target: args.target, bundleRef: args.bundleRef, harnessRef: args.harnessRef, account: target.account,
|
|
144
|
+
premiumMultiplier: target.unitCost, multiplierSource: target.multiplierSource, caps: totals.caps, spent: totals.spent, calls: totals.calls,
|
|
145
|
+
stopped: stopped ?? null, quota: { before, after }, cells,
|
|
146
|
+
};
|
|
147
|
+
deps.writeReport(args.output, { ...result, runs });
|
|
148
|
+
deps.print((0, report_1.summarize)({ target: args.target, bundleRef: args.bundleRef, cells, spent: totals.spent, stopped, quota: result.quota }));
|
|
149
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.run_command_end", message: "finished an eval model run", meta: { target: args.target, runs: runs.length, stopped: stopped ?? null, ...totals.spent } });
|
|
150
|
+
return { exitCode: stopped ? 2 : 0, result, runs };
|
|
151
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* `npm run eval -- <flags>` (see `run-command.ts` for the flags and the refusals): runs eval cases on one model target
|
|
8
|
+
* and writes the private report. With `--sandbox-ssh <host>:<folder>` the sandbox runs on that Docker host, whose
|
|
9
|
+
* harness checkout is synced to `<folder>/harness`; `--bundle`, `--seed-bundle` and `--oracle-books` are then paths
|
|
10
|
+
* on that host. Model calls and credentials stay on this machine.
|
|
11
|
+
*/
|
|
12
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const runtime_1 = require("../nerves/runtime");
|
|
15
|
+
const run_command_1 = require("./run-command");
|
|
16
|
+
const report_1 = require("./report");
|
|
17
|
+
const docker_1 = require("./sandbox/docker");
|
|
18
|
+
const oracle_1 = require("./sandbox/oracle");
|
|
19
|
+
const remote_1 = require("./sandbox/remote");
|
|
20
|
+
const targets_1 = require("./targets");
|
|
21
|
+
const REPO = node_path_1.default.resolve(__dirname, "../..");
|
|
22
|
+
function runCaseFor(args) {
|
|
23
|
+
if (args.sandboxSsh) {
|
|
24
|
+
const split = args.sandboxSsh.indexOf(":");
|
|
25
|
+
if (split < 1)
|
|
26
|
+
throw new Error("--sandbox-ssh must be <host>:<folder>");
|
|
27
|
+
const host = args.sandboxSsh.slice(0, split);
|
|
28
|
+
const root = args.sandboxSsh.slice(split + 1);
|
|
29
|
+
return (0, remote_1.remoteRunCase)({
|
|
30
|
+
start: (0, remote_1.sshStart)(host, `${root}/harness/dist/eval/remote-entry.js`),
|
|
31
|
+
paths: {
|
|
32
|
+
bundleDir: args.bundle, seedBundleDir: args.seedBundle ?? `${root}/harness/deploy/unraid/sanctuary.ouro`, workRoot: `${root}/work`,
|
|
33
|
+
...(args.oracleBooks ? { oracleBooks: args.oracleBooks } : {}),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const docker = (0, docker_1.dockerCli)();
|
|
38
|
+
const oracle = args.oracleBooks ? (0, oracle_1.dockerOracle)({ docker, image: docker_1.HOUSEHOLD_IMAGE, booksLib: args.oracleBooks }) : undefined;
|
|
39
|
+
return ({ case: c, host, budget }) => (0, docker_1.runSandboxed)({
|
|
40
|
+
case: c, bundleDir: args.bundle, seedBundleDir: args.seedBundle ?? node_path_1.default.join(REPO, "deploy/unraid/sanctuary.ouro"), host, budget, docker,
|
|
41
|
+
...(oracle ? { oracle } : {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function main() {
|
|
45
|
+
const args = (0, run_command_1.parseEvalArgs)(process.argv.slice(2));
|
|
46
|
+
const { exitCode } = await (0, run_command_1.runEvalCommand)(args, {
|
|
47
|
+
resolveTarget: (spec, creds) => (0, targets_1.resolveTarget)(spec, creds),
|
|
48
|
+
runCase: runCaseFor,
|
|
49
|
+
outputExists: (file) => node_fs_1.default.existsSync(file),
|
|
50
|
+
writeReport: report_1.writePrivateReport,
|
|
51
|
+
print: (text) => { process.stdout.write(`${text}\n`); },
|
|
52
|
+
});
|
|
53
|
+
return exitCode;
|
|
54
|
+
}
|
|
55
|
+
// stderr's last line names the failure its Ouro AX card lists (cli-commands/entry-points.ts): 2 a run the budget or
|
|
56
|
+
// the provider stopped, 1 a refusal or a failure. process.exitCode, not process.exit, which can drop the line on a pipe.
|
|
57
|
+
const STOPPED = "budget-stopped";
|
|
58
|
+
const FAILED = "eval-error";
|
|
59
|
+
main().then((code) => {
|
|
60
|
+
if (code === 2)
|
|
61
|
+
process.stderr.write(`code: ${STOPPED}\n`);
|
|
62
|
+
process.exitCode = code;
|
|
63
|
+
}).catch((error) => {
|
|
64
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.run_entry_error", message: "the eval command failed", meta: { error: error instanceof Error ? error.message : String(error) } });
|
|
65
|
+
process.stderr.write(`eval: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
66
|
+
process.stderr.write(`code: ${FAILED}\n`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dockerOracle = dockerOracle;
|
|
4
|
+
/**
|
|
5
|
+
* The oracle for a file no fixture label covers (the agent built or edited an EPUB): the books CLI's own
|
|
6
|
+
* `quality.check` from the pinned oracle ref, run on the host side in a throwaway container with no network, a
|
|
7
|
+
* read-only root and every capability dropped. `booksLib` is the folder holding that ref's `booklib` package. A
|
|
8
|
+
* checker that cannot run, or answers anything but true or false, grades the file as not readable.
|
|
9
|
+
*/
|
|
10
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
11
|
+
const CHECK = "import json, sys; sys.path.insert(0, '/oracle'); from booklib import quality; print(json.dumps(bool(quality.check('/book.epub')['ok'])))";
|
|
12
|
+
function dockerOracle(input) {
|
|
13
|
+
return async (file) => {
|
|
14
|
+
try {
|
|
15
|
+
const out = await input.docker.run([
|
|
16
|
+
"run", "--rm", "--network", "none", "--log-driver", "none", "--read-only", "--cap-drop", "ALL", "--security-opt", "no-new-privileges",
|
|
17
|
+
"--tmpfs", "/tmp:rw,size=64m", "-v", `${input.booksLib}:/oracle:ro`, "-v", `${file}:/book.epub:ro`, input.image, "python3", "-I", "-c", CHECK,
|
|
18
|
+
]);
|
|
19
|
+
const verdict = out.trim();
|
|
20
|
+
if (verdict === "true" || verdict === "false") {
|
|
21
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.oracle_graded", message: "graded an unlabelled file with the pinned checker", meta: { readable: verdict === "true" } });
|
|
22
|
+
return verdict === "true";
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`the checker answered ${verdict.slice(0, 80)}`);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.oracle_error", message: "the pinned checker could not grade a file", meta: { error: error.message } });
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serveRemoteJob = serveRemoteJob;
|
|
4
|
+
exports.remoteRunCase = remoteRunCase;
|
|
5
|
+
exports.sshStart = sshStart;
|
|
6
|
+
/**
|
|
7
|
+
* The sandbox on another Docker host, reached over ssh, with the model served from this side. The remote host runs
|
|
8
|
+
* `remote-entry.js`, which reads one `job` (the case and the paths of its bundle, seed bundle, work folder and oracle
|
|
9
|
+
* on that host), runs `runSandboxed` there with a proxy provider over the ssh channel, and answers `done` with the
|
|
10
|
+
* observation. Credentials and the budget stay here: this side serves the real runtime with `serveProxyRuntime`, so
|
|
11
|
+
* each remote model call takes this side's budget first, and the first 402 or 429 stops the run here.
|
|
12
|
+
*/
|
|
13
|
+
const node_child_process_1 = require("node:child_process");
|
|
14
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
15
|
+
const provider_proxy_1 = require("../transport/provider-proxy");
|
|
16
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
17
|
+
/** Remote side: waits for the job, runs it with the model served over the same channel, and answers `done`. */
|
|
18
|
+
async function serveRemoteJob(input) {
|
|
19
|
+
const channel = (0, provider_proxy_1.createStreamChannel)(input.stdin, input.stdout);
|
|
20
|
+
const job = await new Promise((resolve) => {
|
|
21
|
+
channel.onMessage((msg) => {
|
|
22
|
+
if (msg.type === "job")
|
|
23
|
+
resolve(msg.job);
|
|
24
|
+
if (msg.type === "closed")
|
|
25
|
+
resolve(undefined);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
let outcome;
|
|
29
|
+
if (!job) {
|
|
30
|
+
outcome = { ok: false, error: "the channel closed before a job arrived" };
|
|
31
|
+
}
|
|
32
|
+
else if (!isObject(job.case) || typeof job.bundleDir !== "string" || typeof job.seedBundleDir !== "string") {
|
|
33
|
+
outcome = { ok: false, error: "the job names no case, bundle or seed bundle" };
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.remote_job_start", message: "running a remote sandbox job", meta: { caseId: String(job.case.id) } });
|
|
37
|
+
try {
|
|
38
|
+
const host = await (0, provider_proxy_1.createProxyRuntime)(channel);
|
|
39
|
+
outcome = { ok: true, result: await input.run(job, host) };
|
|
40
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.remote_job_end", message: "finished a remote sandbox job", meta: {} });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
outcome = { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!outcome.ok)
|
|
47
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.remote_job_error", message: "a remote sandbox job failed", meta: { error: outcome.error } });
|
|
48
|
+
channel.send({ type: "done", outcome });
|
|
49
|
+
await new Promise((resolve) => input.stdout.write("", () => resolve()));
|
|
50
|
+
return outcome;
|
|
51
|
+
}
|
|
52
|
+
function isObservation(value) {
|
|
53
|
+
return isObject(value) && Array.isArray(value.timeline) && typeof value.outcome === "string" && typeof value.finalReply === "string"
|
|
54
|
+
&& Array.isArray(value.library) && Array.isArray(value.mail) && Array.isArray(value.created) && Array.isArray(value.gaps);
|
|
55
|
+
}
|
|
56
|
+
/** This side: each run starts the remote process, sends the job, serves the model and waits for the observation. */
|
|
57
|
+
function remoteRunCase(options) {
|
|
58
|
+
const timeoutMs = options.timeoutMs ?? 900_000;
|
|
59
|
+
return async ({ case: c, host, budget }) => {
|
|
60
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.remote_run_start", message: "starting a run on the remote sandbox host", meta: { caseId: c.id } });
|
|
61
|
+
const remote = options.start();
|
|
62
|
+
const channel = (0, provider_proxy_1.createStreamChannel)(remote.stdout, remote.stdin);
|
|
63
|
+
(0, provider_proxy_1.serveProxyRuntime)(channel, host, budget);
|
|
64
|
+
const outcome = await new Promise((resolve) => {
|
|
65
|
+
const timer = setTimeout(() => { remote.kill?.(); resolve({ ok: false, error: `the remote run did not finish within ${timeoutMs} ms` }); }, timeoutMs);
|
|
66
|
+
channel.onMessage((msg) => { if (msg.type === "done") {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
resolve(msg.outcome);
|
|
69
|
+
} });
|
|
70
|
+
void remote.exited.then((code) => { clearTimeout(timer); resolve({ ok: false, error: `the remote process exited (${code}) before the run finished: ${remote.stderr().trim()}` }); });
|
|
71
|
+
channel.send({ type: "job", job: { case: c, ...options.paths } });
|
|
72
|
+
});
|
|
73
|
+
if (!outcome.ok) {
|
|
74
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.remote_run_error", message: "the remote sandbox run failed", meta: { caseId: c.id, error: outcome.error } });
|
|
75
|
+
throw new Error(`remote sandbox failed: ${outcome.error}`);
|
|
76
|
+
}
|
|
77
|
+
if (!isObservation(outcome.result))
|
|
78
|
+
throw new Error("remote sandbox failed: its result is not an observation");
|
|
79
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.remote_run_end", message: "finished a run on the remote sandbox host", meta: { caseId: c.id, outcome: outcome.result.outcome } });
|
|
80
|
+
return outcome.result;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/* v8 ignore start -- process wiring: the channel and its lifecycle are tested above through in-memory pipes @preserve */
|
|
84
|
+
/** `ssh -T <host> node <entry>`, with its stdin and stdout as the channel. */
|
|
85
|
+
function sshStart(host, entry) {
|
|
86
|
+
return () => {
|
|
87
|
+
const child = (0, node_child_process_1.spawn)("ssh", ["-T", "-o", "BatchMode=yes", "-o", "ServerAliveInterval=30", host, "node", entry], { stdio: ["pipe", "pipe", "pipe"] });
|
|
88
|
+
let err = "";
|
|
89
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => { err = (err + chunk).slice(-4000); });
|
|
90
|
+
const exited = new Promise((resolve) => {
|
|
91
|
+
child.on("error", () => resolve(-1));
|
|
92
|
+
child.on("close", (code) => resolve(code ?? -1));
|
|
93
|
+
});
|
|
94
|
+
return { stdin: child.stdin, stdout: child.stdout, exited, stderr: () => err, kill: () => { child.kill("SIGTERM"); } };
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/* v8 ignore stop */
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTargetSpec = parseTargetSpec;
|
|
4
|
+
exports.resolveTarget = resolveTarget;
|
|
5
|
+
exports.defaultTargetDeps = defaultTargetDeps;
|
|
6
|
+
/**
|
|
7
|
+
* Model targets for eval runs: `github-copilot:<model>` or `minimax:<model>`, each a host-side `ProviderRuntime`
|
|
8
|
+
* built from a named local agent's stored credentials (`readProviderCredentialRecord`), never from the bundle under
|
|
9
|
+
* test.
|
|
10
|
+
*
|
|
11
|
+
* A Copilot target bills exactly one account. It is built with no owner and only that account's token and endpoint,
|
|
12
|
+
* so the account pool never switches accounts on a 402 or 429 and no burn is written or published as the agent's
|
|
13
|
+
* usage. With a stored pool, `--copilot-account` names the account; with one stored account, its login is checked.
|
|
14
|
+
* Each call costs the model's premium-request multiplier from Copilot's `/models` listing, or `--premium-multiplier`
|
|
15
|
+
* when the listing has none. There is no default: without either the target refuses to start, before any call.
|
|
16
|
+
*/
|
|
17
|
+
const github_copilot_1 = require("../../heart/providers/github-copilot");
|
|
18
|
+
const minimax_1 = require("../../heart/providers/minimax");
|
|
19
|
+
const account_pool_1 = require("../../heart/providers/account-pool");
|
|
20
|
+
const fleet_readings_1 = require("../../heart/quota/fleet-readings");
|
|
21
|
+
const provider_credentials_1 = require("../../heart/provider-credentials");
|
|
22
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
23
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
24
|
+
function parseTargetSpec(spec) {
|
|
25
|
+
const match = /^(github-copilot|minimax):(\S+)$/.exec(spec);
|
|
26
|
+
if (!match)
|
|
27
|
+
throw new Error(`target ${spec} must be github-copilot:<model> or minimax:<model>`);
|
|
28
|
+
return { provider: match[1], model: match[2] };
|
|
29
|
+
}
|
|
30
|
+
async function credentials(deps, agent, provider) {
|
|
31
|
+
const read = await deps.readCredential(agent, provider);
|
|
32
|
+
if (!read.ok)
|
|
33
|
+
throw new Error(`${agent} has no ${provider} credentials (${read.error}); run \`ouro auth --agent ${agent} --provider ${provider}\``);
|
|
34
|
+
// `ouro auth` keeps secrets in `credentials` and settings such as Copilot's `baseUrl` in `config`.
|
|
35
|
+
return { ...read.record.config, ...read.record.credentials };
|
|
36
|
+
}
|
|
37
|
+
const loginOf = (body) => isRecord(body) && typeof body.login === "string" ? body.login : undefined;
|
|
38
|
+
async function chooseAccount(deps, stored, wanted) {
|
|
39
|
+
const pool = (0, account_pool_1.parseAccountPool)(stored.accountPool);
|
|
40
|
+
if (pool.length > 0) {
|
|
41
|
+
const key = (account) => `${account.login}@${account.host}`;
|
|
42
|
+
if (!wanted) {
|
|
43
|
+
if (pool.length === 1)
|
|
44
|
+
return pool[0];
|
|
45
|
+
throw new Error(`the stored Copilot pool has ${pool.length} accounts; name the one to bill with --copilot-account ${pool.map(key).join(" or ")}`);
|
|
46
|
+
}
|
|
47
|
+
const found = pool.find((account) => key(account) === wanted || account.login === wanted);
|
|
48
|
+
if (!found)
|
|
49
|
+
throw new Error(`no Copilot account ${wanted} in the stored pool (${pool.map(key).join(", ")})`);
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
if (typeof stored.githubToken !== "string" || typeof stored.baseUrl !== "string")
|
|
53
|
+
throw new Error("the stored Copilot credentials have no token and endpoint; run `ouro auth --provider github-copilot` for the agent");
|
|
54
|
+
const single = { githubToken: stored.githubToken, baseUrl: stored.baseUrl, host: "github.com" };
|
|
55
|
+
const login = loginOf(await deps.copilotUser(single));
|
|
56
|
+
if (!login)
|
|
57
|
+
throw new Error("could not read the login of the stored Copilot account");
|
|
58
|
+
if (wanted && wanted !== login && wanted !== `${login}@github.com`)
|
|
59
|
+
throw new Error(`the stored Copilot account signs in as ${login}, not ${wanted}`);
|
|
60
|
+
return { ...single, login };
|
|
61
|
+
}
|
|
62
|
+
function multiplierFrom(models, model) {
|
|
63
|
+
const entry = models.find((candidate) => isRecord(candidate) && candidate.id === model);
|
|
64
|
+
if (!entry)
|
|
65
|
+
throw new Error(`Copilot does not offer ${model} to this account`);
|
|
66
|
+
const billing = entry.billing;
|
|
67
|
+
const value = isRecord(billing) ? billing.multiplier : undefined;
|
|
68
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
69
|
+
}
|
|
70
|
+
async function copilotTarget(spec, model, creds, deps) {
|
|
71
|
+
const account = await chooseAccount(deps, await credentials(deps, creds.agent, "github-copilot"), creds.copilotAccount);
|
|
72
|
+
const listed = multiplierFrom(await deps.listCopilotModels(account), model);
|
|
73
|
+
const given = creds.premiumMultiplier;
|
|
74
|
+
if (listed === undefined && given === undefined) {
|
|
75
|
+
throw new Error(`Copilot's /models gives no premium-request multiplier for ${model}; pass --premium-multiplier <n> from GitHub's published table`);
|
|
76
|
+
}
|
|
77
|
+
if (listed === undefined && !(Number.isFinite(given) && given >= 0))
|
|
78
|
+
throw new Error("--premium-multiplier must be a number of at least 0");
|
|
79
|
+
const key = `${account.login}@${account.host}`;
|
|
80
|
+
const runtime = deps.createCopilotRuntime(model, { githubToken: account.githubToken, baseUrl: account.baseUrl });
|
|
81
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.target_resolved", message: "resolved an eval model target", meta: { spec, account: key, multiplier: listed ?? given } });
|
|
82
|
+
return {
|
|
83
|
+
spec, runtime, account: key,
|
|
84
|
+
unitCost: listed ?? given,
|
|
85
|
+
multiplierSource: listed === undefined ? "--premium-multiplier" : "copilot /models",
|
|
86
|
+
quota: async () => {
|
|
87
|
+
try {
|
|
88
|
+
const body = await deps.copilotUser(account);
|
|
89
|
+
return { tokenBased: isRecord(body) && typeof body.token_based_billing === "boolean" ? body.token_based_billing : null, reading: (0, fleet_readings_1.directReading)(key, body, new Date().toISOString()) };
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return { tokenBased: null, reading: null };
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async function resolveTarget(spec, creds, deps = defaultTargetDeps()) {
|
|
98
|
+
const parsed = parseTargetSpec(spec);
|
|
99
|
+
if (parsed.provider === "github-copilot")
|
|
100
|
+
return copilotTarget(spec, parsed.model, creds, deps);
|
|
101
|
+
const stored = await credentials(deps, creds.agent, "minimax");
|
|
102
|
+
if (typeof stored.apiKey !== "string" || !stored.apiKey)
|
|
103
|
+
throw new Error(`${creds.agent}'s minimax credentials have no API key; run \`ouro auth --agent ${creds.agent} --provider minimax\``);
|
|
104
|
+
const runtime = deps.createMinimaxRuntime(parsed.model, { apiKey: stored.apiKey });
|
|
105
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.target_resolved", message: "resolved an eval model target", meta: { spec, account: null, multiplier: 0 } });
|
|
106
|
+
return { spec, runtime, unitCost: 0, multiplierSource: "not a Copilot target", account: null, quota: async () => ({ tokenBased: null, reading: null }) };
|
|
107
|
+
}
|
|
108
|
+
/* v8 ignore start -- network and vault defaults: each wrapped function is tested in its own module @preserve */
|
|
109
|
+
function defaultTargetDeps() {
|
|
110
|
+
const getJson = async (url, token) => {
|
|
111
|
+
const response = await fetch(url, { headers: { Authorization: `Bearer ${token}`, Accept: "application/json", "Copilot-Integration-Id": "vscode-chat" }, signal: AbortSignal.timeout(15_000) });
|
|
112
|
+
if (!response.ok)
|
|
113
|
+
throw new Error(`${url} answered HTTP ${response.status}`);
|
|
114
|
+
return response.json();
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
readCredential: (agent, provider) => (0, provider_credentials_1.readProviderCredentialRecord)(agent, provider),
|
|
118
|
+
listCopilotModels: async (account) => {
|
|
119
|
+
const body = await getJson(`${account.baseUrl.replace(/\/$/, "")}/models`, account.githubToken);
|
|
120
|
+
return isRecord(body) && Array.isArray(body.data) ? body.data : [];
|
|
121
|
+
},
|
|
122
|
+
copilotUser: (account) => getJson(`${(0, account_pool_1.apiBaseForHost)(account.host)}/copilot_internal/user`, account.githubToken),
|
|
123
|
+
createCopilotRuntime: (model, config) => (0, github_copilot_1.createGithubCopilotProviderRuntime)(model, config),
|
|
124
|
+
createMinimaxRuntime: (model, config) => (0, minimax_1.createMinimaxProviderRuntime)(model, config),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/* v8 ignore stop */
|
|
@@ -37,6 +37,7 @@ const SHAPES = {
|
|
|
37
37
|
resetTurnState: (msg) => Array.isArray(msg.messages),
|
|
38
38
|
error: (msg) => isTurn(msg.turn) && isObject(msg.error) && typeof msg.error.message === "string",
|
|
39
39
|
abort: (msg) => isTurn(msg.turn),
|
|
40
|
+
job: (msg) => isObject(msg.job),
|
|
40
41
|
done: (msg) => isObject(msg.outcome) && typeof msg.outcome.ok === "boolean",
|
|
41
42
|
};
|
|
42
43
|
function isMessage(value) {
|
|
@@ -147,6 +147,10 @@ exports.ENTRY_POINT_COMMANDS = [
|
|
|
147
147
|
{ name: `${PROBE} stop`, effect: "private", summary: "Stop a running health acceptance probe.", ax: { id: `cli:${PROBE} stop`, group: "sanctuary-host", effect: "write", when: "End a probe run that's still going, for the same scenario coordinates it started with.", errors: [probeUsage("stop")] } },
|
|
148
148
|
{ name: `${PROBE} recover`, effect: "private", summary: "Restore state after a health probe.", ax: { id: `cli:${PROBE} recover`, group: "sanctuary-host", effect: "write", when: "After an interrupted probe: put the agent's health state back from the snapshot the run saved.", errors: [probeUsage("recover")] } },
|
|
149
149
|
{ name: `${PROBE} finalize`, effect: "private", summary: "Finish a health acceptance scenario.", ax: { id: `cli:${PROBE} finalize`, group: "sanctuary-host", effect: "write", when: "Close a scenario by proving the owner image and container after it, then clear the probe's workspace.", errors: [probeUsage("finalize")] } },
|
|
150
|
+
{ name: "node dist/eval/run-entry.js", effect: "private", summary: "Run the replay eval's cases on a model.", ax: { id: "cli:node dist/eval/run-entry.js", group: "diagnostics", effect: "consequential", confirm: "It spends model credits or premium requests on the account the flags name, up to the caps you pass.", when: "Measure a model on the replay eval's cases, writing a private report; every run reserves its worst-case spend first.", errors: [
|
|
151
|
+
{ code: "budget-stopped", means: "The eval stopped early: a run's reservation would pass a cap, or the provider answered 402 or 429. The report holds the runs that finished.", fix: "Read the summary on stdout. Raise the cap only if that spend is approved; the report keeps every finished run as measured, so a rerun adds runs rather than replacing them." },
|
|
152
|
+
{ code: "eval-error", means: "The eval refused to start or failed: a bad or missing flag, a case that fails its self-test, a report file that exists already, a target without its prices or caps, or a run that threw.", fix: "Read the `eval:` line above it on stderr, fix that, and run again with a new --output path." },
|
|
153
|
+
] } },
|
|
150
154
|
{ name: "node dist/senses/shepherd/judge-evaluation-entry.js", effect: "private", summary: "Evaluate Shepherd's judge on its cases.", ax: { id: "cli:node dist/senses/shepherd/judge-evaluation-entry.js", group: "diagnostics", effect: "write", when: "Measure how Shepherd's judge classifies its evaluation cases, writing a report; it never qualifies v1 on its own.", errors: [
|
|
151
155
|
{ code: "not-passed", means: "The Shepherd judge evaluation finished, but its classification didn't pass or closing its report threw.", fix: "Read the JSON summary on stdout and the report for the failing cases." },
|
|
152
156
|
{ code: "evaluation-error", means: "The Shepherd judge evaluation stopped before running a case (bad arguments, an output that exists already, no judge for the agent, or a bad case corpus), or writing its report threw.", fix: "Read the error in the JSON on stdout, fix it, and run again with a new --output path." },
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1410",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1410",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1410",
|
|
4
4
|
"description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
|
|
5
5
|
"homepage": "https://ouroboros.bot/",
|
|
6
6
|
"engines": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"worktree:bootstrap": "node scripts/worktree-bootstrap.cjs",
|
|
39
39
|
"test": "vitest run",
|
|
40
40
|
"test:integration": "npm run build && vitest run --config vitest.integration.config.ts",
|
|
41
|
+
"eval": "npm run build && node dist/eval/run-entry.js",
|
|
41
42
|
"test:eval-sandbox": "npm run build && vitest run --config vitest.eval.config.ts",
|
|
42
43
|
"test:e2e:package": "npm run build && node scripts/package-e2e.cjs",
|
|
43
44
|
"test:e2e:self-update": "node scripts/self-update-package-e2e.cjs",
|