@tangle-network/agent-eval 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to `@tangle-network/agent-eval` and its sibling `agent-eval-
4
4
 
5
5
  ---
6
6
 
7
+ ## [1.0.29] — 2026-11-08
8
+
9
+ - feat(benchmarks): own a Harbor case environment (prepare once, pause under a free-space floor, release with its build cache) (#1244)
10
+
11
+ ## [1.0.28] — 2026-11-08
12
+
13
+ - fix(model-seats): an economy preset that passes assertModelsServed
14
+
7
15
  ## [1.0.27] — 2026-11-08
8
16
 
9
17
  - fix(models): default to the newest served model in each tier
@@ -91,7 +91,9 @@ export declare function createHarborBenchmarkAdapter<TArtifact = string>(options
91
91
  /**
92
92
  * Defaults: `retries` 2 (extra runs after one with no reward), `maxDetailChars` 2000 (bounds
93
93
  * `JSON.stringify(detail).length`), `keepImage` true: `--no-delete` keeps the image after a run,
94
- * yet a later run builds it again unless `task.toml` names a prebuilt `docker_image`.
94
+ * yet a later run builds it again unless `task.toml` names a prebuilt `docker_image`, as it does
95
+ * for a case `prepareCaseEnvironment` prepared. `host` (an ssh target, by default the host the case
96
+ * was prepared on) runs Harbor there.
95
97
  */
96
98
  interface HarborPatchGradeOptions {
97
99
  harborBin?: string;
@@ -101,6 +103,7 @@ interface HarborPatchGradeOptions {
101
103
  timeoutMs?: number;
102
104
  env?: Record<string, string>;
103
105
  keepImage?: boolean;
106
+ host?: string;
104
107
  }
105
108
  /**
106
109
  * A `grade` callback that scores `{ patch }` with the task's own verifier: Harbor's oracle agent
@@ -111,6 +114,30 @@ interface HarborPatchGradeOptions {
111
114
  export declare function gradeHarborPatch(options?: HarborPatchGradeOptions): (item: HarborTaskItem, artifact: {
112
115
  patch: string;
113
116
  }) => Promise<HarborGradeOutcome>;
117
+ interface CaseEnvironmentOptions {
118
+ /** ssh target of the docker host; the local docker host when absent. */
119
+ host?: string;
120
+ /** Builds wait while the docker host's data root has fewer free bytes. Default 25 GiB. */
121
+ freeFloorBytes?: number;
122
+ /** Case images alive at once in this process. Default 2. */
123
+ maxLive?: number;
124
+ /** How long a paused build waits before reading free space again. Default 60 s. */
125
+ recheckMs?: number;
126
+ /** Where pause lines go. Default `console.error`. */
127
+ log?: (line: string) => void;
128
+ signal?: AbortSignal;
129
+ }
130
+ /** The environment for docker commands on `host`. */
131
+ export declare const dockerHostEnv: (host?: string) => NodeJS.ProcessEnv;
132
+ /** Build the case's environment image once and return its tag; waits for a live slot first. */
133
+ export declare function prepareCaseEnvironment(item: HarborTaskItem, options?: CaseEnvironmentOptions): Promise<string>;
134
+ /**
135
+ * Remove the case's image and its build cache: the records whose step is the Dockerfile's first
136
+ * `RUN` line, and every record built on them. Frees the case's live slot.
137
+ */
138
+ export declare function releaseCaseEnvironment(item: HarborTaskItem, options?: {
139
+ host?: string;
140
+ }): Promise<void>;
114
141
  /**
115
142
  * Synthetic routing dataset. 16 tasks across 4 categories. Used as a
116
143
  * deterministic, dependency-free benchmark for any router that maps a
@@ -309,5 +336,5 @@ export declare function evaluateStandardRetrieval(payload: StandardRetrievalPayl
309
336
  expectedScores: Record<string, number>;
310
337
  };
311
338
  };
312
- export { BENCHMARK_SPLIT_SEED, type BenchmarkAdapter, type BenchmarkDatasetItem, type BenchmarkDistribution, type BenchmarkEvaluation, type BenchmarkFamily, type BenchmarkMetricCalibrationOptions, type BenchmarkMetricCalibrationResult, type BenchmarkReport, type BenchmarkResponder, type BenchmarkRunOptions, type BenchmarkRunResult, type BenchmarkScenario, type BenchmarkSliceSummary, type BenchmarkSource, type BenchmarkTaskKind, type BuildStandardRetrievalItemsOptions, type HarborBenchmarkAdapter, type HarborBenchmarkOptions, type HarborGradeOutcome, type HarborPatchGradeOptions, type HarborTaskItem, type HarborTaskPayload, type RetrievalIdAdapterOptions, type StandardRetrievalArtifact, type StandardRetrievalDocument, type StandardRetrievalEvaluationOptions, type StandardRetrievalPayload, type StandardRetrievalQrel, type StandardRetrievalQuery, type StandardRetrievalResult, deterministicSplit, index_d_exports as routing };
339
+ export { BENCHMARK_SPLIT_SEED, type BenchmarkAdapter, type BenchmarkDatasetItem, type BenchmarkDistribution, type BenchmarkEvaluation, type BenchmarkFamily, type BenchmarkMetricCalibrationOptions, type BenchmarkMetricCalibrationResult, type BenchmarkReport, type BenchmarkResponder, type BenchmarkRunOptions, type BenchmarkRunResult, type BenchmarkScenario, type BenchmarkSliceSummary, type BenchmarkSource, type BenchmarkTaskKind, type BuildStandardRetrievalItemsOptions, type CaseEnvironmentOptions, type HarborBenchmarkAdapter, type HarborBenchmarkOptions, type HarborGradeOutcome, type HarborPatchGradeOptions, type HarborTaskItem, type HarborTaskPayload, type RetrievalIdAdapterOptions, type StandardRetrievalArtifact, type StandardRetrievalDocument, type StandardRetrievalEvaluationOptions, type StandardRetrievalPayload, type StandardRetrievalQrel, type StandardRetrievalQuery, type StandardRetrievalResult, deterministicSplit, index_d_exports as routing };
313
340
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/benchmarks/calibration.ts","../../src/benchmarks/harbor.ts","../../src/benchmarks/routing/dataset.ts","../../src/benchmarks/routing/index.ts","../../src/benchmarks/runner.ts","../../src/benchmarks/standard-formats.ts"],"mappings":";;;;;UAEiB,kCAAkC,oBAAoB;EACrE,SAAS,iBAAiB,qBAAqB,WAAW,UAAU;EACpE,MAAM,qBAAqB;EAC3B,cAAc;EACd,gBAAgB;EAChB;EACA;EACA;;UAGe;EACf;EACA,MAAM;EACN,QAAQ;EACR;EACA;EACA;EACA;;wBAGoB,yBAAyB,oBAAoB,oBACjE,SAAS,kCAAkC,UAAU,aACpD,QAAQ;;UCWM;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;IACE;IACA;IACA;IACA;;;EAGF;;EAEA;;EAEA;;EAEA;;KAGU,iBAAiB,qBAAqB;;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AAO;EACP,SAAS;EACT,WAAW;;UAGI;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe,mBAAmB,oBAAoB;EACtD,WAAW,MAAM,kBAAkB;EACnC,UAAU,eAAe,WAAW,kBAAkB;EACtD,QAAQ;EACR;EACA;;wBAGoB,oBAAoB,oBAAoB,oBAC5D,SAAS,oBAAoB,UAAU,aACtC,QAAQ,mBAAmB,UAAU;wBA0ClB,mBAAmB,UACvC,SAAS,iBAAiB,qBAAqB,WAAW,oBAC1D,kBAAiB,gBAChB,QAAQ,MAAM,kBAAkB;wBA6BnB,eAAe,UAAU,WACvC,SAAS,iBAAiB,qBAAqB,WAAW,UAAU,aACnE,YAAY,WAAW,kBAAkB;UC9J3B;EACf;EACA;EACA;EACA,WAAW;;UAGI;EACf;EACA;EACA,WAAW;;UAGI;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA,gBAAgB;EAChB,SAAS,eAAe;EACxB,WAAW;;UAGI;EACf;EACA,QAAQ;EACR,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB;EACA,SAAS;EACT;EACA,WAAW,oBAAoB;;UAGhB,kCAAkC;EACjD,oBAAoB;EACpB;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;KAGU,kEAGC;EAEP;EACA;EACA,mBAAmB;;UAGR;EACf,oBAAoB;EACpB;EACA;EACA;EACA;;wBA0Bc,WAAW,eAAe;wBAgB1B,qBAAqB,eAAe;wBAgBpC,sBAAsB,eAAe;wBAerC,4BACd,SAAS,qCACR,MAAM,qBAAqB;wBAuCd,kCACd,SAAS,4BACR,iBACD,qBAAqB,2BACrB,0BACA;wBAqBc,0BACd,SAAS,0BACT,UAAU,2BACV,UAAS"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/benchmarks/calibration.ts","../../src/benchmarks/harbor.ts","../../src/benchmarks/harbor-environment.ts","../../src/benchmarks/routing/dataset.ts","../../src/benchmarks/routing/index.ts","../../src/benchmarks/runner.ts","../../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AAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB;EACA,SAAS;EACT;EACA,WAAW,oBAAoB;;UAGhB,kCAAkC;EACjD,oBAAoB;EACpB;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;KAGU,kEAGC;EAEP;EACA;EACA,mBAAmB;;UAGR;EACf,oBAAoB;EACpB;EACA;EACA;EACA;;wBA0Bc,WAAW,eAAe;wBAgB1B,qBAAqB,eAAe;wBAgBpC,sBAAsB,eAAe;wBAerC,4BACd,SAAS,qCACR,MAAM,qBAAqB;wBAuCd,kCACd,SAAS,4BACR,iBACD,qBAAqB,2BACrB,0BACA;wBAqBc,0BACd,SAAS,0BACT,UAAU,2BACV,UAAS"}
@@ -3,13 +3,14 @@ import { at as summarizeNumberSeries, ct as mean } from "../statistics-CvvC-MPv.
3
3
  import { Z as runCampaign } from "../llm-judge-DzAT7Wka.js";
4
4
  import { M as fsCampaignStorage } from "../external-optimizer-subprocess-GO6s84Ov.js";
5
5
  import "../campaign-Cqz2vk2p.js";
6
- import { randomUUID } from "node:crypto";
7
- import { join, resolve } from "node:path";
6
+ import { createHash, randomUUID } from "node:crypto";
7
+ import { dirname, join, resolve } from "node:path";
8
8
  import { tmpdir } from "node:os";
9
9
  import { execFile } from "node:child_process";
10
10
  import { cp, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
11
11
  import { promisify, stripVTControlCharacters } from "node:util";
12
- import { parse } from "smol-toml";
12
+ import { parse, stringify } from "smol-toml";
13
+ import { setTimeout } from "node:timers/promises";
13
14
  // src/benchmarks/calibration.ts
14
15
  async function calibrateBenchmarkMetric(options) {
15
16
  const weak = await options.adapter.evaluate(options.item, options.weakArtifact);
@@ -41,6 +42,146 @@ function clamp01$1(value) {
41
42
  if (value > 1) return 1;
42
43
  return value;
43
44
  }
45
+ // src/benchmarks/harbor-environment.ts
46
+ /**
47
+ * The docker host lifecycle of a Harbor case: its environment image is built once, before its first
48
+ * grade, and removed with its build cache once the caller is done with the case.
49
+ *
50
+ * `prepareCaseEnvironment` keeps at most `maxLive` case images alive in this process, admitting
51
+ * cases in call order, and pauses (never fails) while the docker host is below its free-space
52
+ * floor, since that space belongs to the host. `gradeHarborPatch` then names the prepared image
53
+ * as the task's `docker_image`, so Harbor builds nothing per trial. A `host` is an ssh target:
54
+ * builds and `docker run` reach it through `DOCKER_HOST`, and Harbor runs there.
55
+ */
56
+ const execute$1 = promisify(execFile);
57
+ /** The environment for docker commands on `host`. */
58
+ const dockerHostEnv = (host) => host ? {
59
+ ...process.env,
60
+ DOCKER_HOST: `ssh://${host}`
61
+ } : process.env;
62
+ const live = /* @__PURE__ */ new Map();
63
+ const waiters = [];
64
+ const wake = () => {
65
+ for (const resume of waiters.splice(0)) resume();
66
+ };
67
+ /** `harbor-case/<task dir>:<digest of every file under environment/>`. */
68
+ async function imageTag(item) {
69
+ const dir = join(item.payload.taskDir, "environment");
70
+ const digest = createHash("sha256");
71
+ for (const file of (await readdir(dir, {
72
+ recursive: true,
73
+ withFileTypes: true
74
+ })).filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name)).sort()) digest.update(`${file.slice(dir.length)}\0`).update(await readFile(file));
75
+ return `harbor-case/${item.payload.dir.toLowerCase()}:${digest.digest("hex").slice(0, 16)}`;
76
+ }
77
+ /** The image `gradeHarborPatch` names for a case prepared in this process. */
78
+ const preparedImage = (item) => live.get(item.payload.taskDir);
79
+ async function freeBytes(host) {
80
+ const df = [
81
+ "df",
82
+ "-B1",
83
+ "--output=avail",
84
+ (await execute$1("docker", [
85
+ "info",
86
+ "-f",
87
+ "{{.DockerRootDir}}"
88
+ ], { env: dockerHostEnv(host) })).stdout.trim()
89
+ ];
90
+ const { stdout } = await (host ? execute$1("ssh", [host, ...df]) : execute$1("df", df.slice(1)));
91
+ return Number(stdout.trim().split("\n").pop());
92
+ }
93
+ async function build(item, options) {
94
+ const { host, freeFloorBytes = 25 * 2 ** 30, recheckMs = 6e4, signal } = options;
95
+ const log = options.log ?? ((line) => console.error(line));
96
+ const env = dockerHostEnv(host);
97
+ const image = await imageTag(item);
98
+ if (await execute$1("docker", [
99
+ "image",
100
+ "inspect",
101
+ image
102
+ ], { env }).then(() => true, () => false)) return image;
103
+ for (let free = await freeBytes(host); free < freeFloorBytes; free = await freeBytes(host)) {
104
+ const gib = (bytes) => (bytes / 2 ** 30).toFixed(1);
105
+ log(`PAUSE host-owned: ${host ?? "the local docker host"} has ${gib(free)} GiB free, below the ${gib(freeFloorBytes)} GiB floor; ${item.id} builds after ${recheckMs / 1e3} s`);
106
+ await setTimeout(recheckMs, void 0, { signal });
107
+ }
108
+ const context = join(item.payload.taskDir, "environment");
109
+ await execute$1("docker", [
110
+ "build",
111
+ "-q",
112
+ "-t",
113
+ image,
114
+ context
115
+ ], {
116
+ env,
117
+ maxBuffer: 1 << 26
118
+ });
119
+ return image;
120
+ }
121
+ /** Build the case's environment image once and return its tag; waits for a live slot first. */
122
+ async function prepareCaseEnvironment(item, options = {}) {
123
+ const key = item.payload.taskDir;
124
+ while (!live.has(key) && live.size >= (options.maxLive ?? 2)) {
125
+ options.signal?.throwIfAborted();
126
+ await new Promise((resume) => {
127
+ waiters.push(resume);
128
+ options.signal?.addEventListener("abort", () => resume(), { once: true });
129
+ });
130
+ }
131
+ let entry = live.get(key);
132
+ if (!entry) {
133
+ entry = {
134
+ host: options.host,
135
+ image: build(item, options)
136
+ };
137
+ live.set(key, entry);
138
+ entry.image.catch(() => {
139
+ live.delete(key);
140
+ wake();
141
+ });
142
+ }
143
+ return entry.image;
144
+ }
145
+ /**
146
+ * Remove the case's image and its build cache: the records whose step is the Dockerfile's first
147
+ * `RUN` line, and every record built on them. Frees the case's live slot.
148
+ */
149
+ async function releaseCaseEnvironment(item, options = {}) {
150
+ const host = live.get(item.payload.taskDir)?.host ?? options.host;
151
+ live.delete(item.payload.taskDir);
152
+ wake();
153
+ const env = dockerHostEnv(host);
154
+ await execute$1("docker", [
155
+ "image",
156
+ "rm",
157
+ await imageTag(item)
158
+ ], { env }).catch(() => void 0);
159
+ const dockerfile = await readFile(join(item.payload.taskDir, "environment/Dockerfile"), "utf8");
160
+ const marker = /^RUN\s+(.*?)\s*\\?$/mu.exec(dockerfile)?.[1];
161
+ if (!marker) return;
162
+ const { stdout } = await execute$1("docker", [
163
+ "buildx",
164
+ "du",
165
+ "--format",
166
+ "json"
167
+ ], {
168
+ env,
169
+ maxBuffer: 1 << 26
170
+ });
171
+ const records = stdout.split("\n").filter(Boolean).map((line) => JSON.parse(line));
172
+ const ids = new Set(records.filter((r) => r.Description?.includes(marker)).map((r) => r.ID));
173
+ for (let size = -1; size !== ids.size;) {
174
+ size = ids.size;
175
+ for (const r of records) if (r.Parents?.some((id) => ids.has(id))) ids.add(r.ID);
176
+ }
177
+ if (ids.size) await execute$1("docker", [
178
+ "buildx",
179
+ "prune",
180
+ "-f",
181
+ "--filter",
182
+ `id~=^(${[...ids].join("|")})$`
183
+ ], { env });
184
+ }
44
185
  // src/benchmarks/types.ts
45
186
  /**
46
187
  * 32-bit FNV-1a hash. Stable, allocation-free, deterministic across
@@ -186,6 +327,37 @@ function detailTail(text, max) {
186
327
  return tail;
187
328
  }
188
329
  /**
330
+ * Harbor on ssh host `host`: the task is mirrored under `~/agent-eval-harbor` at its local path,
331
+ * and the job's directory comes back to the local jobs dir and leaves the host.
332
+ */
333
+ async function remoteHarbor(host, args, run) {
334
+ const [task, jobsDir, job] = [
335
+ args[2],
336
+ args[6],
337
+ args.at(-1)
338
+ ];
339
+ const q = (text) => `'${text.replaceAll("'", "'\\''")}'`;
340
+ const at = (path) => `~/${q(`agent-eval-harbor${path}`)}`;
341
+ const remote = args.map((arg) => arg === task || arg === jobsDir ? at(arg) : q(arg));
342
+ await execute("ssh", [host, `mkdir -p ${at(task)} ${at(jobsDir)}`]);
343
+ await execute("rsync", [
344
+ "-a",
345
+ "--delete",
346
+ `${task}/`,
347
+ `${host}:agent-eval-harbor${task}/`
348
+ ]);
349
+ const harbor = `cd /tmp && env -u DOCKER_HOST PATH="$HOME/.local/bin:$PATH" harbor`;
350
+ try {
351
+ await execute("ssh", [host, `${harbor} ${remote.join(" ")}`], run);
352
+ } finally {
353
+ await mkdir(jobsDir, { recursive: true });
354
+ const back = [`${host}:agent-eval-harbor${jobsDir}/${job}/`, `${jobsDir}/${job}/`];
355
+ await execute("rsync", ["-a", ...back]).catch(() => void 0);
356
+ const clean = `rm -rf ${at(dirname(task))} ${at(`${jobsDir}/${job}`)}`;
357
+ await execute("ssh", [host, clean]).catch(() => void 0);
358
+ }
359
+ }
360
+ /**
189
361
  * A `grade` callback that scores `{ patch }` with the task's own verifier: Harbor's oracle agent
190
362
  * runs a `solution/solve.sh` that applies the patch (`git apply --binary`) in the environment's
191
363
  * working directory, on a copy of the task. An empty patch changes nothing. A run with no reward
@@ -214,6 +386,16 @@ function gradeHarborPatch(options = {}) {
214
386
  await mkdir(join(task, "solution"));
215
387
  await writeFile(join(task, "solution/patch.diff"), artifact.patch);
216
388
  await writeFile(join(task, "solution/solve.sh"), SOLVE_SH, { mode: 493 });
389
+ const prepared = preparedImage(item);
390
+ if (prepared) {
391
+ const config = parse(await readFile(join(task, "task.toml"), "utf8"));
392
+ config.environment = {
393
+ ...table(config.environment),
394
+ docker_image: await prepared.image
395
+ };
396
+ await writeFile(join(task, "task.toml"), stringify(config));
397
+ }
398
+ const host = options.host ?? prepared?.host;
217
399
  const jobsDir = resolve(options.jobsDir ?? join(work, "jobs"));
218
400
  const errors = [];
219
401
  const args = [
@@ -230,7 +412,7 @@ function gradeHarborPatch(options = {}) {
230
412
  ];
231
413
  for (let attempt = 1; attempt <= retries + 1; attempt += 1) {
232
414
  const job = `${item.payload.dir}-${randomUUID()}`;
233
- const failure = await execute(harborBin, [...args, job], run).then(() => null, (error) => detailTail(error.message, 500));
415
+ const failure = await (host ? remoteHarbor(host, [...args, job], run) : execute(harborBin, [...args, job], run)).then(() => null, (error) => detailTail(error.message, 500));
234
416
  const trial = (await readdir(join(jobsDir, job), { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory()).map((entry) => join(jobsDir, job, entry.name, "/"))[0];
235
417
  const read = (path) => readFile(`${trial}${path}`, "utf8").catch(() => "");
236
418
  const result = table(trial === void 0 ? {} : JSON.parse(await read("result.json") || "{}"));
@@ -909,6 +1091,6 @@ function discountedGain(relevance, zeroBasedRank) {
909
1091
  if (relevance <= 0) return 0;
910
1092
  return (2 ** relevance - 1) / Math.log2(zeroBasedRank + 2);
911
1093
  }
912
- export { BENCHMARK_SPLIT_SEED, benchmarkJudge, benchmarkScenarios, buildStandardRetrievalItems, calibrateBenchmarkMetric, createHarborBenchmarkAdapter, createRetrievalIdBenchmarkAdapter, deterministicSplit, evaluateStandardRetrieval, gradeHarborPatch, parseBeirCorpusJsonl, parseBeirQueriesJsonl, parseQrels, routing_exports as routing, runBenchmarkAdapter };
1094
+ export { BENCHMARK_SPLIT_SEED, benchmarkJudge, benchmarkScenarios, buildStandardRetrievalItems, calibrateBenchmarkMetric, createHarborBenchmarkAdapter, createRetrievalIdBenchmarkAdapter, deterministicSplit, dockerHostEnv, evaluateStandardRetrieval, gradeHarborPatch, parseBeirCorpusJsonl, parseBeirQueriesJsonl, parseQrels, prepareCaseEnvironment, releaseCaseEnvironment, routing_exports as routing, runBenchmarkAdapter };
913
1095
 
914
1096
  //# sourceMappingURL=index.js.map