@tangle-network/agent-bench 0.3.5 → 0.3.7
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 +13 -0
- package/README.md +13 -1
- package/dist/adapters.d.ts +15 -0
- package/dist/adapters.js +43 -0
- package/dist/adapters.js.map +1 -0
- package/dist/benchmarks/_harness.d.ts +125 -0
- package/dist/benchmarks/_harness.js +33 -0
- package/dist/benchmarks/_harness.js.map +1 -0
- package/dist/benchmarks/aec-bench.d.ts +27 -0
- package/dist/benchmarks/aec-bench.js +8 -0
- package/dist/benchmarks/aec-bench.js.map +1 -0
- package/dist/benchmarks/agentbench.d.ts +16 -0
- package/dist/benchmarks/agentbench.js +10 -0
- package/dist/benchmarks/agentbench.js.map +1 -0
- package/dist/benchmarks/appworld.d.ts +37 -0
- package/dist/benchmarks/appworld.js +14 -0
- package/dist/benchmarks/appworld.js.map +1 -0
- package/dist/benchmarks/bfcl.d.ts +18 -0
- package/dist/benchmarks/bfcl.js +10 -0
- package/dist/benchmarks/bfcl.js.map +1 -0
- package/dist/benchmarks/cad-design.d.ts +45 -0
- package/dist/benchmarks/cad-design.js +7 -0
- package/dist/benchmarks/cad-design.js.map +1 -0
- package/dist/benchmarks/cadbench.d.ts +19 -0
- package/dist/benchmarks/cadbench.js +8 -0
- package/dist/benchmarks/cadbench.js.map +1 -0
- package/dist/benchmarks/cadgenbench.d.ts +22 -0
- package/dist/benchmarks/cadgenbench.js +8 -0
- package/dist/benchmarks/cadgenbench.js.map +1 -0
- package/dist/benchmarks/commit0.d.ts +31 -0
- package/dist/benchmarks/commit0.js +10 -0
- package/dist/benchmarks/commit0.js.map +1 -0
- package/dist/benchmarks/crag.d.ts +14 -0
- package/dist/benchmarks/crag.js +9 -0
- package/dist/benchmarks/crag.js.map +1 -0
- package/dist/benchmarks/dabstep.d.ts +18 -0
- package/dist/benchmarks/dabstep.js +10 -0
- package/dist/benchmarks/dabstep.js.map +1 -0
- package/dist/benchmarks/enterpriseops-gym.d.ts +38 -0
- package/dist/benchmarks/enterpriseops-gym.js +10 -0
- package/dist/benchmarks/enterpriseops-gym.js.map +1 -0
- package/dist/benchmarks/finresearchbench.d.ts +15 -0
- package/dist/benchmarks/finresearchbench.js +8 -0
- package/dist/benchmarks/finresearchbench.js.map +1 -0
- package/dist/benchmarks/finsearchcomp.d.ts +49 -0
- package/dist/benchmarks/finsearchcomp.js +7 -0
- package/dist/benchmarks/finsearchcomp.js.map +1 -0
- package/dist/benchmarks/frames.d.ts +59 -0
- package/dist/benchmarks/frames.js +13 -0
- package/dist/benchmarks/frames.js.map +1 -0
- package/dist/benchmarks/hotpotqa.d.ts +48 -0
- package/dist/benchmarks/hotpotqa.js +15 -0
- package/dist/benchmarks/hotpotqa.js.map +1 -0
- package/dist/benchmarks/humaneval.d.ts +62 -0
- package/dist/benchmarks/humaneval.js +17 -0
- package/dist/benchmarks/humaneval.js.map +1 -0
- package/dist/benchmarks/mind2web.d.ts +41 -0
- package/dist/benchmarks/mind2web.js +9 -0
- package/dist/benchmarks/mind2web.js.map +1 -0
- package/dist/benchmarks/nomiracl.d.ts +15 -0
- package/dist/benchmarks/nomiracl.js +9 -0
- package/dist/benchmarks/nomiracl.js.map +1 -0
- package/dist/benchmarks/open-rag-bench.d.ts +14 -0
- package/dist/benchmarks/open-rag-bench.js +9 -0
- package/dist/benchmarks/open-rag-bench.js.map +1 -0
- package/dist/benchmarks/programbench.d.ts +38 -0
- package/dist/benchmarks/programbench.js +10 -0
- package/dist/benchmarks/programbench.js.map +1 -0
- package/dist/benchmarks/rag-shared.d.ts +42 -0
- package/dist/benchmarks/rag-shared.js +39 -0
- package/dist/benchmarks/rag-shared.js.map +1 -0
- package/dist/benchmarks/ragbench.d.ts +16 -0
- package/dist/benchmarks/ragbench.js +9 -0
- package/dist/benchmarks/ragbench.js.map +1 -0
- package/dist/benchmarks/simpleqa.d.ts +64 -0
- package/dist/benchmarks/simpleqa.js +11 -0
- package/dist/benchmarks/simpleqa.js.map +1 -0
- package/dist/benchmarks/swe-bench.d.ts +56 -0
- package/dist/benchmarks/swe-bench.js +14 -0
- package/dist/benchmarks/swe-bench.js.map +1 -0
- package/dist/benchmarks/t2-ragbench.d.ts +14 -0
- package/dist/benchmarks/t2-ragbench.js +9 -0
- package/dist/benchmarks/t2-ragbench.js.map +1 -0
- package/dist/benchmarks/tau-bench-shared.d.ts +26 -0
- package/dist/benchmarks/tau-bench-shared.js +10 -0
- package/dist/benchmarks/tau-bench-shared.js.map +1 -0
- package/dist/benchmarks/tau2-bench.d.ts +7 -0
- package/dist/benchmarks/tau2-bench.js +11 -0
- package/dist/benchmarks/tau2-bench.js.map +1 -0
- package/dist/benchmarks/tau3-banking.d.ts +15 -0
- package/dist/benchmarks/tau3-banking.js +9 -0
- package/dist/benchmarks/tau3-banking.js.map +1 -0
- package/dist/benchmarks/terminal-bench.d.ts +24 -0
- package/dist/benchmarks/terminal-bench.js +8 -0
- package/dist/benchmarks/terminal-bench.js.map +1 -0
- package/dist/benchmarks/toollm.d.ts +16 -0
- package/dist/benchmarks/toollm.js +10 -0
- package/dist/benchmarks/toollm.js.map +1 -0
- package/dist/benchmarks/trata-hedge.d.ts +32 -0
- package/dist/benchmarks/trata-hedge.js +7 -0
- package/dist/benchmarks/trata-hedge.js.map +1 -0
- package/dist/benchmarks/types.d.ts +107 -0
- package/dist/benchmarks/types.js +1 -0
- package/dist/benchmarks/types.js.map +1 -0
- package/dist/benchmarks/webarena-verified.d.ts +16 -0
- package/dist/benchmarks/webarena-verified.js +10 -0
- package/dist/benchmarks/webarena-verified.js.map +1 -0
- package/dist/chunk-2PVVP7GN.js +197 -0
- package/dist/chunk-2PVVP7GN.js.map +1 -0
- package/dist/chunk-2XU6OGEN.js +170 -0
- package/dist/chunk-2XU6OGEN.js.map +1 -0
- package/dist/chunk-53UPUNBZ.js +325 -0
- package/dist/chunk-53UPUNBZ.js.map +1 -0
- package/dist/chunk-5H5XV76F.js +240 -0
- package/dist/chunk-5H5XV76F.js.map +1 -0
- package/dist/chunk-7WSD27QQ.js +118 -0
- package/dist/chunk-7WSD27QQ.js.map +1 -0
- package/dist/chunk-C7T7WEK2.js +103 -0
- package/dist/chunk-C7T7WEK2.js.map +1 -0
- package/dist/chunk-CKUVRZ2T.js +251 -0
- package/dist/chunk-CKUVRZ2T.js.map +1 -0
- package/dist/chunk-HBSWHQNJ.js +30 -0
- package/dist/chunk-HBSWHQNJ.js.map +1 -0
- package/dist/chunk-HHXFIHXC.js +116 -0
- package/dist/chunk-HHXFIHXC.js.map +1 -0
- package/dist/chunk-IFAV6KEM.js +276 -0
- package/dist/chunk-IFAV6KEM.js.map +1 -0
- package/dist/chunk-INNOYXCP.js +387 -0
- package/dist/chunk-INNOYXCP.js.map +1 -0
- package/dist/chunk-J3KDJNX2.js +182 -0
- package/dist/chunk-J3KDJNX2.js.map +1 -0
- package/dist/chunk-JRWWGMK7.js +148 -0
- package/dist/chunk-JRWWGMK7.js.map +1 -0
- package/dist/chunk-JTHWEDEW.js +32 -0
- package/dist/chunk-JTHWEDEW.js.map +1 -0
- package/dist/chunk-KDIKRJGB.js +120 -0
- package/dist/chunk-KDIKRJGB.js.map +1 -0
- package/dist/chunk-LRRD7NAG.js +301 -0
- package/dist/chunk-LRRD7NAG.js.map +1 -0
- package/dist/chunk-ODT47UAY.js +221 -0
- package/dist/chunk-ODT47UAY.js.map +1 -0
- package/dist/chunk-PA2ZKHJC.js +230 -0
- package/dist/chunk-PA2ZKHJC.js.map +1 -0
- package/dist/chunk-PUIRNYI7.js +189 -0
- package/dist/chunk-PUIRNYI7.js.map +1 -0
- package/dist/chunk-PWQVGAJB.js +144 -0
- package/dist/chunk-PWQVGAJB.js.map +1 -0
- package/dist/chunk-R36V2VP7.js +169 -0
- package/dist/chunk-R36V2VP7.js.map +1 -0
- package/dist/chunk-R67DFVLO.js +142 -0
- package/dist/chunk-R67DFVLO.js.map +1 -0
- package/dist/chunk-SEVJPLZC.js +260 -0
- package/dist/chunk-SEVJPLZC.js.map +1 -0
- package/dist/chunk-SYDW647C.js +318 -0
- package/dist/chunk-SYDW647C.js.map +1 -0
- package/dist/chunk-TBKU5XQI.js +228 -0
- package/dist/chunk-TBKU5XQI.js.map +1 -0
- package/dist/chunk-TSWPNOYM.js +147 -0
- package/dist/chunk-TSWPNOYM.js.map +1 -0
- package/dist/chunk-UAIOHCUK.js +27 -0
- package/dist/chunk-UAIOHCUK.js.map +1 -0
- package/dist/chunk-UPAMRDX4.js +233 -0
- package/dist/chunk-UPAMRDX4.js.map +1 -0
- package/dist/chunk-VQRS7VUC.js +342 -0
- package/dist/chunk-VQRS7VUC.js.map +1 -0
- package/dist/chunk-X3BTXCJ4.js +262 -0
- package/dist/chunk-X3BTXCJ4.js.map +1 -0
- package/dist/chunk-X5YKXC6V.js +211 -0
- package/dist/chunk-X5YKXC6V.js.map +1 -0
- package/dist/chunk-Y6O2OCUO.js +130 -0
- package/dist/chunk-Y6O2OCUO.js.map +1 -0
- package/dist/chunk-YCGY7UIZ.js +208 -0
- package/dist/chunk-YCGY7UIZ.js.map +1 -0
- package/dist/chunk-Z7ML6L77.js +162 -0
- package/dist/chunk-Z7ML6L77.js.map +1 -0
- package/dist/chunk-ZEWMTR5M.js +136 -0
- package/dist/chunk-ZEWMTR5M.js.map +1 -0
- package/dist/index.d.ts +355 -0
- package/dist/index.js +1908 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -9
- package/scripts/run-package-tests.mjs +30 -8
- package/scripts/verify-packed-consumer.mjs +12 -1
- package/scripts/verify-pier-agent.mts +1 -0
- package/src/benchmarks/humaneval.test.mts +122 -0
- package/src/benchmarks/humaneval.ts +100 -27
- package/src/david-attribution.mts +78 -0
- package/src/david-goliath.mts +149 -0
- package/src/hev-improve.mts +25 -6
- package/src/humaneval-object-ablation.mts +201 -0
- package/src/live-improve-campaign-mbpp.mts +641 -0
- package/src/live-improve-campaign.mts +500 -0
- package/src/mbpp-structural.mts +12 -7
- package/src/stream-observe.py +45 -0
- package/src/stream-observe.tpl.html +247 -0
- package/src/supervisor-arena.mts +816 -0
- package/src/swe-arena/analyze.ts +211 -0
- package/src/swe-arena/arms.ts +788 -0
- package/src/swe-arena/bootstrap-meta.mts +188 -0
- package/src/swe-arena/bootstrap-meta.test.mts +51 -0
- package/src/swe-arena/calibrate.ts +116 -0
- package/src/swe-arena/capabilities.mts +76 -0
- package/src/swe-arena/capabilities.test.mts +57 -0
- package/src/swe-arena/capacity.ts +194 -0
- package/src/swe-arena/cell-evidence.mts +405 -0
- package/src/swe-arena/cell-evidence.test.mts +248 -0
- package/src/swe-arena/diagnosis-ensemble.test.mts +210 -0
- package/src/swe-arena/diagnosis-ensemble.ts +520 -0
- package/src/swe-arena/execution.test.mts +1170 -0
- package/src/swe-arena/fixtures/analyze.py +80 -0
- package/src/swe-arena/fixtures/excludes.txt +8 -0
- package/src/swe-arena/fixtures/gen1-salvage/README.md +45 -0
- package/src/swe-arena/fixtures/gen1-salvage/cand0-e6d7361.diff +116 -0
- package/src/swe-arena/fixtures/gen1-salvage/cand1-76a8590.diff +293 -0
- package/src/swe-arena/fixtures/holdout-preregister.log +12 -0
- package/src/swe-arena/fixtures/holdout.json +44 -0
- package/src/swe-arena/fixtures/instances.json +146 -0
- package/src/swe-arena/fixtures/ledger.jsonl +12 -0
- package/src/swe-arena/fixtures/patches/pallets__flask-5014.solo.patch +36 -0
- package/src/swe-arena/fixtures/patches/pydata__xarray-4687.sup.patch +33 -0
- package/src/swe-arena/fixtures/rejudge.jsonl +15 -0
- package/src/swe-arena/fixtures/rematch.jsonl +3 -0
- package/src/swe-arena/fixtures/rematch2.jsonl +3 -0
- package/src/swe-arena/fixtures/rematch3.jsonl +3 -0
- package/src/swe-arena/fixtures/sup-journal-true.json +19 -0
- package/src/swe-arena/fixtures/verify/astropy__astropy-13033.sh +48 -0
- package/src/swe-arena/fixtures/verify/django__django-11532.sh +50 -0
- package/src/swe-arena/fixtures/verify/matplotlib__matplotlib-20826.sh +76 -0
- package/src/swe-arena/fixtures/verify/pydata__xarray-4687.sh +44 -0
- package/src/swe-arena/fixtures/verify/pytest-dev__pytest-6197.sh +32 -0
- package/src/swe-arena/fixtures/verify/sphinx-doc__sphinx-9658.sh +51 -0
- package/src/swe-arena/fixtures/worker-tokens.json +42 -0
- package/src/swe-arena/fixtures.ts +104 -0
- package/src/swe-arena/holdout-certify.mts +408 -0
- package/src/swe-arena/holdout-certify.test.mts +160 -0
- package/src/swe-arena/judge-child.mts +37 -0
- package/src/swe-arena/manifest.mts +293 -0
- package/src/swe-arena/manifest.test.mts +169 -0
- package/src/swe-arena/materialize.ts +142 -0
- package/src/swe-arena/outer-loop.mts +2145 -0
- package/src/swe-arena/outer-loop.test.mts +696 -0
- package/src/swe-arena/parity.test.mts +87 -0
- package/src/swe-arena/proc.test.mts +174 -0
- package/src/swe-arena/proc.ts +260 -0
- package/src/swe-arena/profiles/default-author.profile.json +4 -0
- package/src/swe-arena/proposer-fanout.mts +489 -0
- package/src/swe-arena/proposer-fanout.test.mts +372 -0
- package/src/swe-arena/reconcile.ts +0 -0
- package/src/swe-arena/replay.mts +183 -0
- package/src/swe-arena/replay.test.mts +300 -0
- package/src/swe-arena/run-experiment.mts +361 -0
- package/src/swe-arena/run-supervisor.mjs +297 -0
- package/src/swe-arena/run-supervisor.test.mts +498 -0
- package/src/swe-arena/serialized-judge.ts +414 -0
- package/src/swe-arena/types.ts +166 -0
- package/src/swe-code-improve.mts +328 -0
- package/src/swe-emit-patch.mts +104 -0
- package/src/swe-improve.mts +232 -0
- package/src/swe-jail.ts +2 -2
- package/src/swe-local-proof.mts +169 -0
- package/src/swe-repro-calibrate.mts +446 -0
- package/src/swe-stream.mts +1497 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// src/benchmarks/cad-design.ts
|
|
2
|
+
import { execFile } from "child_process";
|
|
3
|
+
import { mkdtemp, readFile, writeFile } from "fs/promises";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { promisify } from "util";
|
|
7
|
+
var execFileAsync = promisify(execFile);
|
|
8
|
+
async function openscad(args, cwd) {
|
|
9
|
+
const { stdout, stderr } = await execFileAsync("xvfb-run", ["-a", "openscad", ...args], {
|
|
10
|
+
cwd,
|
|
11
|
+
maxBuffer: 1024 * 1024 * 64,
|
|
12
|
+
timeout: 12e4
|
|
13
|
+
});
|
|
14
|
+
return { stdout, stderr };
|
|
15
|
+
}
|
|
16
|
+
function measureStl(stl, volumesFromStderr) {
|
|
17
|
+
const verts = [];
|
|
18
|
+
const tris = [];
|
|
19
|
+
const re = /vertex\s+(-?[\d.eE+]+)\s+(-?[\d.eE+]+)\s+(-?[\d.eE+]+)/g;
|
|
20
|
+
let m;
|
|
21
|
+
const flat = [];
|
|
22
|
+
while (m = re.exec(stl)) flat.push([Number(m[1]), Number(m[2]), Number(m[3])]);
|
|
23
|
+
for (let i = 0; i + 2 < flat.length; i += 3) tris.push([flat[i], flat[i + 1], flat[i + 2]]);
|
|
24
|
+
for (const v of flat) verts.push(v);
|
|
25
|
+
const xs = verts.map((v) => v[0]);
|
|
26
|
+
const ys = verts.map((v) => v[1]);
|
|
27
|
+
const zs = verts.map((v) => v[2]);
|
|
28
|
+
const min = (a) => Math.min(...a);
|
|
29
|
+
const max = (a) => Math.max(...a);
|
|
30
|
+
const minZ = min(zs);
|
|
31
|
+
const maxZ = max(zs);
|
|
32
|
+
const h = maxZ - minZ || 1;
|
|
33
|
+
const footprint = (lo, hi) => {
|
|
34
|
+
const band = verts.filter((v) => v[2] >= minZ + lo * h && v[2] <= minZ + hi * h);
|
|
35
|
+
if (band.length < 3) return 0;
|
|
36
|
+
const bx = band.map((v) => v[0]);
|
|
37
|
+
const by = band.map((v) => v[1]);
|
|
38
|
+
return (max(bx) - min(bx)) * (max(by) - min(by));
|
|
39
|
+
};
|
|
40
|
+
let vol6 = 0;
|
|
41
|
+
for (const [a, b, c] of tris) {
|
|
42
|
+
vol6 += a[0] * (b[1] * c[2] - b[2] * c[1]) - a[1] * (b[0] * c[2] - b[2] * c[0]) + a[2] * (b[0] * c[1] - b[1] * c[0]);
|
|
43
|
+
}
|
|
44
|
+
const bbox = { x: max(xs) - min(xs), y: max(ys) - min(ys), z: maxZ - minZ };
|
|
45
|
+
return {
|
|
46
|
+
triangles: tris.length,
|
|
47
|
+
volumes: volumesFromStderr,
|
|
48
|
+
bbox,
|
|
49
|
+
baseFootprint: footprint(0, 0.6),
|
|
50
|
+
topFootprint: footprint(0.75, 1),
|
|
51
|
+
solidVolume: Math.abs(vol6) / 6,
|
|
52
|
+
bboxVolume: bbox.x * bbox.y * bbox.z || 1
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function inRange(v, [lo, hi]) {
|
|
56
|
+
return v >= lo && v <= hi;
|
|
57
|
+
}
|
|
58
|
+
function scoreGeometry(g, spec) {
|
|
59
|
+
const checks = {};
|
|
60
|
+
if (spec.volumes) checks.volumes = inRange(g.volumes, spec.volumes);
|
|
61
|
+
if (spec.minTriangles != null) checks.detail = g.triangles >= spec.minTriangles;
|
|
62
|
+
if (spec.bbox?.x) checks.bboxX = inRange(g.bbox.x, spec.bbox.x);
|
|
63
|
+
if (spec.bbox?.y) checks.bboxY = inRange(g.bbox.y, spec.bbox.y);
|
|
64
|
+
if (spec.bbox?.z) checks.bboxZ = inRange(g.bbox.z, spec.bbox.z);
|
|
65
|
+
if (spec.pitchedRoof != null)
|
|
66
|
+
checks.pitchedRoof = g.baseFootprint > 0 && g.topFootprint < spec.pitchedRoof * g.baseFootprint;
|
|
67
|
+
if (spec.hollowBelow != null) checks.hollow = g.solidVolume < spec.hollowBelow * g.bboxVolume;
|
|
68
|
+
const vals = Object.values(checks);
|
|
69
|
+
const score = vals.length ? vals.filter(Boolean).length / vals.length : 0;
|
|
70
|
+
return { checks, score };
|
|
71
|
+
}
|
|
72
|
+
function buildingGold(w, d, sh, ns, rh, t = 3) {
|
|
73
|
+
return `
|
|
74
|
+
w=${w}; d=${d}; sh=${sh}; ns=${ns}; rh=${rh}; t=${t};
|
|
75
|
+
module shell(w,d,h,t){ difference(){ cube([w,d,h]); translate([t,t,-1]) cube([w-2*t,d-2*t,h+2]); } }
|
|
76
|
+
module roof(w,d,h){ rotate([90,0,90]) linear_extrude(height=w) polygon([[0,0],[d,0],[d/2,h]]); }
|
|
77
|
+
union(){
|
|
78
|
+
for(s=[0:ns-1]) translate([0,0,s*sh]) shell(w,d,sh,t);
|
|
79
|
+
for(s=[0:ns]) translate([0,0,s*sh-0.5]) cube([w,d,1]);
|
|
80
|
+
translate([0,0,ns*sh]) roof(w,d,rh);
|
|
81
|
+
for(s=[0:ns-1]) for(i=[0:floor((w-28)/22)]) translate([14+i*22,-1,s*sh+10]) cube([10,t+2,12]);
|
|
82
|
+
translate([w/2-7,-1,2]) cube([14,t+2,20]);
|
|
83
|
+
}
|
|
84
|
+
`.trim();
|
|
85
|
+
}
|
|
86
|
+
function buildingTask(o) {
|
|
87
|
+
const { id, desc, w, d, sh, ns, rh } = o;
|
|
88
|
+
const totalWall = ns * sh;
|
|
89
|
+
const totalH = totalWall + rh;
|
|
90
|
+
const r = Math.round;
|
|
91
|
+
const spec = {
|
|
92
|
+
volumes: [1, ns * 4 + 6],
|
|
93
|
+
bbox: {
|
|
94
|
+
x: [r(w * 0.82), r(w * 1.18)],
|
|
95
|
+
y: [r(d * 0.82), r((d + 1) * 1.2)],
|
|
96
|
+
z: [r(totalH * 0.82), r((totalH + 1) * 1.2)]
|
|
97
|
+
},
|
|
98
|
+
minTriangles: 50,
|
|
99
|
+
pitchedRoof: 0.55,
|
|
100
|
+
hollowBelow: 0.72
|
|
101
|
+
};
|
|
102
|
+
const prompt = [
|
|
103
|
+
`Write OpenSCAD source for ${desc}.`,
|
|
104
|
+
"Requirements:",
|
|
105
|
+
`- footprint roughly ${w} (X) by ${d} (Y) units`,
|
|
106
|
+
ns > 1 ? `- ${ns} stories, total wall height ~${totalWall} units` : `- one story, wall height ~${sh} units`,
|
|
107
|
+
"- a PITCHED / gabled roof on top that tapers toward a ridge (NOT flat)",
|
|
108
|
+
"- hollow shell (walls with an interior cavity), not a solid block",
|
|
109
|
+
"- a door opening and several windows",
|
|
110
|
+
"Output ONLY the .scad source, no prose, no code fences."
|
|
111
|
+
].join("\n");
|
|
112
|
+
return { id, prompt, meta: { spec, gold: buildingGold(w, d, sh, ns, rh) } };
|
|
113
|
+
}
|
|
114
|
+
var BUILDING_CONFIGS = [
|
|
115
|
+
{ id: "cottage", desc: "a single-story cottage", w: 50, d: 40, sh: 30, ns: 1, rh: 18 },
|
|
116
|
+
{ id: "cabin", desc: "a small one-room cabin", w: 44, d: 36, sh: 26, ns: 1, rh: 22 },
|
|
117
|
+
{ id: "bungalow", desc: "a wide single-story bungalow", w: 70, d: 52, sh: 28, ns: 1, rh: 20 },
|
|
118
|
+
{ id: "barn", desc: "a long deep barn", w: 60, d: 96, sh: 42, ns: 1, rh: 26 },
|
|
119
|
+
{ id: "warehouse", desc: "a large warehouse", w: 110, d: 80, sh: 40, ns: 1, rh: 26 },
|
|
120
|
+
{ id: "chapel", desc: "a narrow tall chapel with a steep roof", w: 40, d: 72, sh: 48, ns: 1, rh: 34 },
|
|
121
|
+
{ id: "farmhouse", desc: "a two-story farmhouse", w: 72, d: 56, sh: 30, ns: 2, rh: 26 },
|
|
122
|
+
{ id: "two-story-manor", desc: "a wide two-story manor", w: 96, d: 64, sh: 32, ns: 2, rh: 28 },
|
|
123
|
+
{ id: "townhouse", desc: "a narrow three-story townhouse", w: 42, d: 52, sh: 30, ns: 3, rh: 34 },
|
|
124
|
+
{ id: "watchtower", desc: "a tall narrow three-story watchtower", w: 34, d: 34, sh: 30, ns: 3, rh: 32 }
|
|
125
|
+
];
|
|
126
|
+
var WATER_TOWER_GOLD = `
|
|
127
|
+
$fn=48; r=24; bh=72; t=3; ch=26;
|
|
128
|
+
union(){
|
|
129
|
+
difference(){ cylinder(h=bh, r=r); translate([0,0,t]) cylinder(h=bh, r=r-t); }
|
|
130
|
+
translate([0,0,bh]) cylinder(h=ch, r1=r, r2=0);
|
|
131
|
+
}
|
|
132
|
+
`.trim();
|
|
133
|
+
var AFRAME_GOLD = `
|
|
134
|
+
w=44; d=60; h=66; t=3;
|
|
135
|
+
module tri(w,d,h){ rotate([90,0,90]) linear_extrude(height=w) polygon([[0,0],[d,0],[d/2,h]]); }
|
|
136
|
+
union(){
|
|
137
|
+
difference(){ tri(w,d,h); translate([t,0,0]) tri(w-2*t,d,h-2*t*h/d); }
|
|
138
|
+
translate([w/2-7,-1,0]) cube([14,t+2,24]);
|
|
139
|
+
}
|
|
140
|
+
`.trim();
|
|
141
|
+
var TASKS = [
|
|
142
|
+
{
|
|
143
|
+
id: "two-story-house",
|
|
144
|
+
prompt: [
|
|
145
|
+
"Write OpenSCAD source for a two-story house.",
|
|
146
|
+
"Requirements:",
|
|
147
|
+
"- footprint roughly 80 (X) by 60 (Y) units",
|
|
148
|
+
"- two stories, total wall height ~68 units",
|
|
149
|
+
"- a PITCHED / gabled roof on top (NOT a flat roof) \u2014 the roof must taper toward a ridge",
|
|
150
|
+
"- hollow shell (walls with an interior cavity), not a solid block",
|
|
151
|
+
"- at least one door opening and several windows",
|
|
152
|
+
"Output ONLY the .scad source, no prose, no code fences."
|
|
153
|
+
].join("\n"),
|
|
154
|
+
meta: {
|
|
155
|
+
spec: {
|
|
156
|
+
volumes: [1, 12],
|
|
157
|
+
bbox: { x: [70, 110], y: [50, 80], z: [80, 130] },
|
|
158
|
+
minTriangles: 60,
|
|
159
|
+
pitchedRoof: 0.55,
|
|
160
|
+
hollowBelow: 0.7
|
|
161
|
+
},
|
|
162
|
+
gold: `
|
|
163
|
+
w=80; d=60; sh=34; t=3; rh=28;
|
|
164
|
+
module shell(w,d,h,t){ difference(){ cube([w,d,h]); translate([t,t,-1]) cube([w-2*t,d-2*t,h+2]); } }
|
|
165
|
+
module roof(w,d,h){ translate([0,0,0]) rotate([90,0,90]) linear_extrude(height=w) polygon([[0,0],[d,0],[d/2,h]]); }
|
|
166
|
+
union(){
|
|
167
|
+
for(s=[0,1]) translate([0,0,s*sh]) shell(w,d,sh,t);
|
|
168
|
+
for(s=[0,1,2]) translate([0,0,s*sh-1]) cube([w,d,1]);
|
|
169
|
+
translate([0,0,2*sh]) roof(w,d,rh);
|
|
170
|
+
for(s=[0,1]) for(i=[0:2]) translate([16+i*22,-1,s*sh+10]) cube([12,t+2,14]);
|
|
171
|
+
translate([w/2-8,-1,2]) cube([16,t+2,22]);
|
|
172
|
+
}
|
|
173
|
+
`.trim()
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
...BUILDING_CONFIGS.map(buildingTask),
|
|
177
|
+
{
|
|
178
|
+
id: "water-tower",
|
|
179
|
+
prompt: [
|
|
180
|
+
"Write OpenSCAD source for a water tower: a tall hollow cylindrical tank with a conical roof.",
|
|
181
|
+
"Requirements:",
|
|
182
|
+
"- a hollow cylindrical tank, ~48 units in diameter, ~72 units tall, with an interior cavity",
|
|
183
|
+
"- a CONICAL roof on top that tapers to a point (a pitched roof)",
|
|
184
|
+
"- wall thickness around 3 units",
|
|
185
|
+
"Output ONLY the .scad source, no prose, no code fences."
|
|
186
|
+
].join("\n"),
|
|
187
|
+
meta: {
|
|
188
|
+
spec: {
|
|
189
|
+
volumes: [1, 4],
|
|
190
|
+
bbox: { x: [40, 56], y: [40, 56], z: [88, 110] },
|
|
191
|
+
minTriangles: 60,
|
|
192
|
+
pitchedRoof: 0.55,
|
|
193
|
+
hollowBelow: 0.8
|
|
194
|
+
},
|
|
195
|
+
gold: WATER_TOWER_GOLD
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: "a-frame-cabin",
|
|
200
|
+
prompt: [
|
|
201
|
+
"Write OpenSCAD source for an A-frame cabin: a steep triangular shell where the roof forms the walls.",
|
|
202
|
+
"Requirements:",
|
|
203
|
+
"- footprint roughly 44 (X) by 60 (Y) units",
|
|
204
|
+
"- a STEEP triangular cross-section ~66 units tall that tapers to a ridge at the top",
|
|
205
|
+
"- hollow inside (an interior cavity), not a solid wedge",
|
|
206
|
+
"- a door opening at the front",
|
|
207
|
+
"Output ONLY the .scad source, no prose, no code fences."
|
|
208
|
+
].join("\n"),
|
|
209
|
+
meta: {
|
|
210
|
+
spec: {
|
|
211
|
+
volumes: [1, 4],
|
|
212
|
+
bbox: { x: [36, 52], y: [50, 74], z: [56, 80] },
|
|
213
|
+
minTriangles: 30,
|
|
214
|
+
pitchedRoof: 0.45,
|
|
215
|
+
hollowBelow: 0.8
|
|
216
|
+
},
|
|
217
|
+
gold: AFRAME_GOLD
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: "hex-planter",
|
|
222
|
+
prompt: [
|
|
223
|
+
"Write OpenSCAD source for a hexagonal planter pot.",
|
|
224
|
+
"Requirements:",
|
|
225
|
+
"- a hollow hexagonal prism (6-sided), outer width ~50 units across, height ~45",
|
|
226
|
+
"- open at the top, closed at the bottom (a cavity for soil)",
|
|
227
|
+
"- a wall thickness around 3 units",
|
|
228
|
+
"Output ONLY the .scad source, no prose, no code fences."
|
|
229
|
+
].join("\n"),
|
|
230
|
+
meta: {
|
|
231
|
+
spec: {
|
|
232
|
+
volumes: [1, 3],
|
|
233
|
+
bbox: { x: [40, 60], y: [40, 60], z: [40, 55] },
|
|
234
|
+
minTriangles: 30,
|
|
235
|
+
hollowBelow: 0.7
|
|
236
|
+
},
|
|
237
|
+
gold: `
|
|
238
|
+
$fn=6; or=25; h=45; t=3;
|
|
239
|
+
difference(){
|
|
240
|
+
cylinder(h=h, r=or);
|
|
241
|
+
translate([0,0,t]) cylinder(h=h, r=or-t);
|
|
242
|
+
}
|
|
243
|
+
`.trim()
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
];
|
|
247
|
+
function createCadDesignAdapter() {
|
|
248
|
+
return {
|
|
249
|
+
name: "cad-design",
|
|
250
|
+
async preflight() {
|
|
251
|
+
try {
|
|
252
|
+
await execFileAsync("xvfb-run", ["-a", "openscad", "--version"], { timeout: 3e4 });
|
|
253
|
+
} catch (err) {
|
|
254
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
255
|
+
throw new Error(
|
|
256
|
+
`cad-design preflight failed: ${msg}
|
|
257
|
+
Fix: install OpenSCAD + Xvfb (Debian/Ubuntu: sudo apt-get install -y openscad xvfb). The judge runs \`xvfb-run -a openscad -o out.stl model.scad\` \u2014 both must be on PATH.`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
async loadTasks(opts = {}) {
|
|
262
|
+
let tasks = TASKS;
|
|
263
|
+
if (opts.ids) tasks = tasks.filter((t) => opts.ids.includes(t.id));
|
|
264
|
+
if (opts.limit != null) tasks = tasks.slice(0, opts.limit);
|
|
265
|
+
return tasks.map((t) => ({ id: t.id, prompt: t.prompt, metadata: t.meta }));
|
|
266
|
+
},
|
|
267
|
+
async goldArtifact(task) {
|
|
268
|
+
const meta = task.metadata;
|
|
269
|
+
return meta?.gold;
|
|
270
|
+
},
|
|
271
|
+
async judge(task, artifact) {
|
|
272
|
+
const spec = task.metadata.spec;
|
|
273
|
+
const src = artifact.trim();
|
|
274
|
+
if (!src) return { resolved: false, score: 0, detail: "empty artifact" };
|
|
275
|
+
const dir = await mkdtemp(join(tmpdir(), "cad-"));
|
|
276
|
+
const scad = join(dir, "model.scad");
|
|
277
|
+
const stlPath = join(dir, "model.stl");
|
|
278
|
+
const pngPath = join(dir, "model.png");
|
|
279
|
+
await writeFile(scad, src);
|
|
280
|
+
let stderr = "";
|
|
281
|
+
try {
|
|
282
|
+
const r = await openscad(["-o", stlPath, scad], dir);
|
|
283
|
+
stderr = r.stderr;
|
|
284
|
+
} catch (err) {
|
|
285
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
286
|
+
return { resolved: false, score: 0, detail: `compile failed: ${msg.slice(0, 300)}` };
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
await openscad(
|
|
290
|
+
["-o", pngPath, "--imgsize=1100,850", "--camera=40,30,40,55,0,25,260", "--colorscheme=Tomorrow", scad],
|
|
291
|
+
dir
|
|
292
|
+
);
|
|
293
|
+
} catch {
|
|
294
|
+
}
|
|
295
|
+
let stl;
|
|
296
|
+
try {
|
|
297
|
+
stl = await readFile(stlPath, "utf8");
|
|
298
|
+
} catch {
|
|
299
|
+
return { resolved: false, score: 0, detail: "compiled but produced no STL (empty geometry)" };
|
|
300
|
+
}
|
|
301
|
+
const volumes = Number(/Volumes:\s*(\d+)/.exec(stderr)?.[1] ?? "1");
|
|
302
|
+
const geo = measureStl(stl, volumes);
|
|
303
|
+
const { checks, score } = scoreGeometry(geo, spec);
|
|
304
|
+
const resolved = score === 1;
|
|
305
|
+
const detail = JSON.stringify({
|
|
306
|
+
checks,
|
|
307
|
+
geo: {
|
|
308
|
+
triangles: geo.triangles,
|
|
309
|
+
volumes: geo.volumes,
|
|
310
|
+
bbox: { x: +geo.bbox.x.toFixed(1), y: +geo.bbox.y.toFixed(1), z: +geo.bbox.z.toFixed(1) },
|
|
311
|
+
hollowRatio: +(geo.solidVolume / geo.bboxVolume).toFixed(3),
|
|
312
|
+
topVsBaseFootprint: geo.baseFootprint ? +(geo.topFootprint / geo.baseFootprint).toFixed(3) : null
|
|
313
|
+
},
|
|
314
|
+
renderPath: pngPath,
|
|
315
|
+
stlPath
|
|
316
|
+
});
|
|
317
|
+
return { resolved, score, detail };
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export {
|
|
323
|
+
createCadDesignAdapter
|
|
324
|
+
};
|
|
325
|
+
//# sourceMappingURL=chunk-53UPUNBZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/benchmarks/cad-design.ts"],"sourcesContent":["/**\n * CAD-Design adapter. Worker artifact = OpenSCAD source (`.scad`). Judge = the\n * REAL OpenSCAD engine: compile + export STL, then measure the produced solid\n * geometry against the task's spec. Fully deterministic — the authoritative CAD\n * kernel is the gate, not an LLM and not the agent's own claim.\n *\n * This is verifiable-reward CAD: an agent is far better at *writing* exact\n * parametric code than at clicking a GUI, and the kernel either produces the\n * specified geometry or it doesn't. Every judged artifact also renders a PNG,\n * so a refine loop's attempts become a watchable \"model getting better\" reel\n * (run-capsule consumes the renders).\n *\n * Spec checks are geometric and ungameable:\n * - compiles : `openscad -o out.stl` exits 0 (hard gate)\n * - volumes : disconnected-solid count within [min,max]\n * - bbox : overall X/Y/Z extent within bounds (the thing is the right size)\n * - detail : triangle count ≥ floor (not a degenerate single cube)\n * - pitchedRoof : the top band's XY footprint NARROWS vs the base — a flat\n * box can't fake this; a real gabled/hipped roof tapers\n * - hollow : interior cavity present (walls, not a solid block) — the\n * bbox volume materially exceeds the printed solid volume\n *\n * Requires only `openscad` + `xvfb-run` on PATH (no venv, no Docker, no network).\n */\n\nimport { execFile } from 'node:child_process'\nimport { mkdtemp, readFile, writeFile } from 'node:fs/promises'\nimport { tmpdir } from 'node:os'\nimport { join } from 'node:path'\nimport { promisify } from 'node:util'\nimport type { BenchmarkAdapter, BenchScore, BenchTask, LoadOptions } from './types'\n\nconst execFileAsync = promisify(execFile)\n\n/** Spec assertions a CAD task can require. All are deterministic + geometric. */\nexport interface CadSpec {\n volumes?: [number, number]\n bbox?: { x?: [number, number]; y?: [number, number]; z?: [number, number] }\n minTriangles?: number\n /** Top-band XY footprint must be < this fraction of the base footprint. */\n pitchedRoof?: number\n /** Printed solid volume must be < this fraction of the bbox volume (hollow). */\n hollowBelow?: number\n}\n\ninterface CadTaskMeta {\n spec: CadSpec\n /** A known-good .scad that satisfies the spec — the oracle for verify-judge. */\n gold: string\n}\n\n/** Run openscad with xvfb (it needs a GL context even headless). */\nasync function openscad(args: string[], cwd: string): Promise<{ stdout: string; stderr: string }> {\n // -a => auto-pick a free display; openscad writes Facets/Volumes to stderr.\n const { stdout, stderr } = await execFileAsync('xvfb-run', ['-a', 'openscad', ...args], {\n cwd,\n maxBuffer: 1024 * 1024 * 64,\n timeout: 120_000,\n })\n return { stdout, stderr }\n}\n\ninterface Geometry {\n triangles: number\n volumes: number\n bbox: { x: number; y: number; z: number }\n /** XY footprint area (extent_x * extent_y) of the bottom 60% and top 25% z-bands. */\n baseFootprint: number\n topFootprint: number\n /** Convex-ish solid volume estimate from the STL (sum of signed tetra volumes). */\n solidVolume: number\n bboxVolume: number\n}\n\n/** Parse an ASCII STL into the geometric measures the spec checks. Pure. */\nfunction measureStl(stl: string, volumesFromStderr: number): Geometry {\n const verts: Array<[number, number, number]> = []\n const tris: Array<[[number, number, number], [number, number, number], [number, number, number]]> = []\n const re = /vertex\\s+(-?[\\d.eE+]+)\\s+(-?[\\d.eE+]+)\\s+(-?[\\d.eE+]+)/g\n let m: RegExpExecArray | null\n const flat: Array<[number, number, number]> = []\n while ((m = re.exec(stl))) flat.push([Number(m[1]), Number(m[2]), Number(m[3])])\n for (let i = 0; i + 2 < flat.length; i += 3) tris.push([flat[i]!, flat[i + 1]!, flat[i + 2]!])\n for (const v of flat) verts.push(v)\n\n const xs = verts.map((v) => v[0])\n const ys = verts.map((v) => v[1])\n const zs = verts.map((v) => v[2])\n const min = (a: number[]) => Math.min(...a)\n const max = (a: number[]) => Math.max(...a)\n const minZ = min(zs)\n const maxZ = max(zs)\n const h = maxZ - minZ || 1\n\n // Footprint of a z-band = XY extent of the vertices within it.\n const footprint = (lo: number, hi: number): number => {\n const band = verts.filter((v) => v[2] >= minZ + lo * h && v[2] <= minZ + hi * h)\n if (band.length < 3) return 0\n const bx = band.map((v) => v[0])\n const by = band.map((v) => v[1])\n return (max(bx) - min(bx)) * (max(by) - min(by))\n }\n\n // Signed volume via the divergence theorem over triangles (|Σ v0·(v1×v2)/6|).\n let vol6 = 0\n for (const [a, b, c] of tris) {\n vol6 +=\n a[0] * (b[1] * c[2] - b[2] * c[1]) -\n a[1] * (b[0] * c[2] - b[2] * c[0]) +\n a[2] * (b[0] * c[1] - b[1] * c[0])\n }\n const bbox = { x: max(xs) - min(xs), y: max(ys) - min(ys), z: maxZ - minZ }\n return {\n triangles: tris.length,\n volumes: volumesFromStderr,\n bbox,\n baseFootprint: footprint(0, 0.6),\n topFootprint: footprint(0.75, 1),\n solidVolume: Math.abs(vol6) / 6,\n bboxVolume: bbox.x * bbox.y * bbox.z || 1,\n }\n}\n\nfunction inRange(v: number, [lo, hi]: [number, number]): boolean {\n return v >= lo && v <= hi\n}\n\n/** Score the geometry against the spec — each check is a named pass/fail. */\nfunction scoreGeometry(g: Geometry, spec: CadSpec): { checks: Record<string, boolean>; score: number } {\n const checks: Record<string, boolean> = {}\n if (spec.volumes) checks.volumes = inRange(g.volumes, spec.volumes)\n if (spec.minTriangles != null) checks.detail = g.triangles >= spec.minTriangles\n if (spec.bbox?.x) checks.bboxX = inRange(g.bbox.x, spec.bbox.x)\n if (spec.bbox?.y) checks.bboxY = inRange(g.bbox.y, spec.bbox.y)\n if (spec.bbox?.z) checks.bboxZ = inRange(g.bbox.z, spec.bbox.z)\n if (spec.pitchedRoof != null)\n checks.pitchedRoof = g.baseFootprint > 0 && g.topFootprint < spec.pitchedRoof * g.baseFootprint\n if (spec.hollowBelow != null) checks.hollow = g.solidVolume < spec.hollowBelow * g.bboxVolume\n const vals = Object.values(checks)\n const score = vals.length ? vals.filter(Boolean).length / vals.length : 0\n return { checks, score }\n}\n\n/** A parametric multi-story gabled building — the gold generator for the\n * building-family tasks. They share geometry (hollow stacked shells + a gabled\n * roof that tapers to a ridge + cut openings) and differ only in dimensions, so\n * one verified generator yields a spec-passing oracle for each. */\nfunction buildingGold(w: number, d: number, sh: number, ns: number, rh: number, t = 3): string {\n return `\nw=${w}; d=${d}; sh=${sh}; ns=${ns}; rh=${rh}; t=${t};\nmodule shell(w,d,h,t){ difference(){ cube([w,d,h]); translate([t,t,-1]) cube([w-2*t,d-2*t,h+2]); } }\nmodule roof(w,d,h){ rotate([90,0,90]) linear_extrude(height=w) polygon([[0,0],[d,0],[d/2,h]]); }\nunion(){\n for(s=[0:ns-1]) translate([0,0,s*sh]) shell(w,d,sh,t);\n for(s=[0:ns]) translate([0,0,s*sh-0.5]) cube([w,d,1]);\n translate([0,0,ns*sh]) roof(w,d,rh);\n for(s=[0:ns-1]) for(i=[0:floor((w-28)/22)]) translate([14+i*22,-1,s*sh+10]) cube([10,t+2,12]);\n translate([w/2-7,-1,2]) cube([14,t+2,20]);\n}\n`.trim()\n}\n\n/** Build a building-family task (prompt + spec + gold) from its dimensions.\n * The spec's bbox is derived from the dims with a ±~18% tolerance so the agent\n * must respect the brief's size; the gold (buildingGold) lands exactly on the\n * nominal dims, so it passes by construction. Keep rh > ns*sh/3 (else the roof\n * base sits inside the top-25% band and pitchedRoof fails). */\nfunction buildingTask(o: { id: string; desc: string; w: number; d: number; sh: number; ns: number; rh: number }): {\n id: string\n prompt: string\n meta: CadTaskMeta\n} {\n const { id, desc, w, d, sh, ns, rh } = o\n const totalWall = ns * sh\n const totalH = totalWall + rh\n const r = Math.round\n const spec: CadSpec = {\n volumes: [1, ns * 4 + 6],\n bbox: {\n x: [r(w * 0.82), r(w * 1.18)],\n y: [r(d * 0.82), r((d + 1) * 1.2)],\n z: [r(totalH * 0.82), r((totalH + 1) * 1.2)],\n },\n minTriangles: 50,\n pitchedRoof: 0.55,\n hollowBelow: 0.72,\n }\n const prompt = [\n `Write OpenSCAD source for ${desc}.`,\n 'Requirements:',\n `- footprint roughly ${w} (X) by ${d} (Y) units`,\n ns > 1 ? `- ${ns} stories, total wall height ~${totalWall} units` : `- one story, wall height ~${sh} units`,\n '- a PITCHED / gabled roof on top that tapers toward a ridge (NOT flat)',\n '- hollow shell (walls with an interior cavity), not a solid block',\n '- a door opening and several windows',\n 'Output ONLY the .scad source, no prose, no code fences.',\n ].join('\\n')\n return { id, prompt, meta: { spec, gold: buildingGold(w, d, sh, ns, rh) } }\n}\n\n/** The building family — one parametric skill (hit the bbox + pitched roof +\n * hollow shell), sampled across footprints, heights, story counts, roof rises. */\nconst BUILDING_CONFIGS: Array<{ id: string; desc: string; w: number; d: number; sh: number; ns: number; rh: number }> = [\n { id: 'cottage', desc: 'a single-story cottage', w: 50, d: 40, sh: 30, ns: 1, rh: 18 },\n { id: 'cabin', desc: 'a small one-room cabin', w: 44, d: 36, sh: 26, ns: 1, rh: 22 },\n { id: 'bungalow', desc: 'a wide single-story bungalow', w: 70, d: 52, sh: 28, ns: 1, rh: 20 },\n { id: 'barn', desc: 'a long deep barn', w: 60, d: 96, sh: 42, ns: 1, rh: 26 },\n { id: 'warehouse', desc: 'a large warehouse', w: 110, d: 80, sh: 40, ns: 1, rh: 26 },\n { id: 'chapel', desc: 'a narrow tall chapel with a steep roof', w: 40, d: 72, sh: 48, ns: 1, rh: 34 },\n { id: 'farmhouse', desc: 'a two-story farmhouse', w: 72, d: 56, sh: 30, ns: 2, rh: 26 },\n { id: 'two-story-manor', desc: 'a wide two-story manor', w: 96, d: 64, sh: 32, ns: 2, rh: 28 },\n { id: 'townhouse', desc: 'a narrow three-story townhouse', w: 42, d: 52, sh: 30, ns: 3, rh: 34 },\n { id: 'watchtower', desc: 'a tall narrow three-story watchtower', w: 34, d: 34, sh: 30, ns: 3, rh: 32 },\n]\n\n/** A hollow cylindrical water tower with a conical roof — a non-box shape that\n * still exercises pitched-roof (the cone tapers to an apex) + hollow + bbox. */\nconst WATER_TOWER_GOLD = `\n$fn=48; r=24; bh=72; t=3; ch=26;\nunion(){\n difference(){ cylinder(h=bh, r=r); translate([0,0,t]) cylinder(h=bh, r=r-t); }\n translate([0,0,bh]) cylinder(h=ch, r1=r, r2=0);\n}\n`.trim()\n\n/** An A-frame: the steep roof IS the walls — a hollow triangular prism. The most\n * extreme taper in the set; tests that the agent can build a non-rectangular shell. */\nconst AFRAME_GOLD = `\nw=44; d=60; h=66; t=3;\nmodule tri(w,d,h){ rotate([90,0,90]) linear_extrude(height=w) polygon([[0,0],[d,0],[d/2,h]]); }\nunion(){\n difference(){ tri(w,d,h); translate([t,0,0]) tri(w-2*t,d,h-2*t*h/d); }\n translate([w/2-7,-1,0]) cube([14,t+2,24]);\n}\n`.trim()\n\nconst TASKS: Array<{ id: string; prompt: string; meta: CadTaskMeta }> = [\n {\n id: 'two-story-house',\n prompt: [\n 'Write OpenSCAD source for a two-story house.',\n 'Requirements:',\n '- footprint roughly 80 (X) by 60 (Y) units',\n '- two stories, total wall height ~68 units',\n '- a PITCHED / gabled roof on top (NOT a flat roof) — the roof must taper toward a ridge',\n '- hollow shell (walls with an interior cavity), not a solid block',\n '- at least one door opening and several windows',\n 'Output ONLY the .scad source, no prose, no code fences.',\n ].join('\\n'),\n meta: {\n spec: {\n volumes: [1, 12],\n bbox: { x: [70, 110], y: [50, 80], z: [80, 130] },\n minTriangles: 60,\n pitchedRoof: 0.55,\n hollowBelow: 0.7,\n },\n gold: `\nw=80; d=60; sh=34; t=3; rh=28;\nmodule shell(w,d,h,t){ difference(){ cube([w,d,h]); translate([t,t,-1]) cube([w-2*t,d-2*t,h+2]); } }\nmodule roof(w,d,h){ translate([0,0,0]) rotate([90,0,90]) linear_extrude(height=w) polygon([[0,0],[d,0],[d/2,h]]); }\nunion(){\n for(s=[0,1]) translate([0,0,s*sh]) shell(w,d,sh,t);\n for(s=[0,1,2]) translate([0,0,s*sh-1]) cube([w,d,1]);\n translate([0,0,2*sh]) roof(w,d,rh);\n for(s=[0,1]) for(i=[0:2]) translate([16+i*22,-1,s*sh+10]) cube([12,t+2,14]);\n translate([w/2-8,-1,2]) cube([16,t+2,22]);\n}\n`.trim(),\n },\n },\n ...BUILDING_CONFIGS.map(buildingTask),\n {\n id: 'water-tower',\n prompt: [\n 'Write OpenSCAD source for a water tower: a tall hollow cylindrical tank with a conical roof.',\n 'Requirements:',\n '- a hollow cylindrical tank, ~48 units in diameter, ~72 units tall, with an interior cavity',\n '- a CONICAL roof on top that tapers to a point (a pitched roof)',\n '- wall thickness around 3 units',\n 'Output ONLY the .scad source, no prose, no code fences.',\n ].join('\\n'),\n meta: {\n spec: {\n volumes: [1, 4],\n bbox: { x: [40, 56], y: [40, 56], z: [88, 110] },\n minTriangles: 60,\n pitchedRoof: 0.55,\n hollowBelow: 0.8,\n },\n gold: WATER_TOWER_GOLD,\n },\n },\n {\n id: 'a-frame-cabin',\n prompt: [\n 'Write OpenSCAD source for an A-frame cabin: a steep triangular shell where the roof forms the walls.',\n 'Requirements:',\n '- footprint roughly 44 (X) by 60 (Y) units',\n '- a STEEP triangular cross-section ~66 units tall that tapers to a ridge at the top',\n '- hollow inside (an interior cavity), not a solid wedge',\n '- a door opening at the front',\n 'Output ONLY the .scad source, no prose, no code fences.',\n ].join('\\n'),\n meta: {\n spec: {\n volumes: [1, 4],\n bbox: { x: [36, 52], y: [50, 74], z: [56, 80] },\n minTriangles: 30,\n pitchedRoof: 0.45,\n hollowBelow: 0.8,\n },\n gold: AFRAME_GOLD,\n },\n },\n {\n id: 'hex-planter',\n prompt: [\n 'Write OpenSCAD source for a hexagonal planter pot.',\n 'Requirements:',\n '- a hollow hexagonal prism (6-sided), outer width ~50 units across, height ~45',\n '- open at the top, closed at the bottom (a cavity for soil)',\n '- a wall thickness around 3 units',\n 'Output ONLY the .scad source, no prose, no code fences.',\n ].join('\\n'),\n meta: {\n spec: {\n volumes: [1, 3],\n bbox: { x: [40, 60], y: [40, 60], z: [40, 55] },\n minTriangles: 30,\n hollowBelow: 0.7,\n },\n gold: `\n$fn=6; or=25; h=45; t=3;\ndifference(){\n cylinder(h=h, r=or);\n translate([0,0,t]) cylinder(h=h, r=or-t);\n}\n`.trim(),\n },\n },\n]\n\nexport function createCadDesignAdapter(): BenchmarkAdapter {\n return {\n name: 'cad-design',\n\n async preflight() {\n try {\n await execFileAsync('xvfb-run', ['-a', 'openscad', '--version'], { timeout: 30_000 })\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err)\n throw new Error(\n `cad-design preflight failed: ${msg}\\n` +\n `Fix: install OpenSCAD + Xvfb (Debian/Ubuntu: sudo apt-get install -y openscad xvfb). ` +\n `The judge runs \\`xvfb-run -a openscad -o out.stl model.scad\\` — both must be on PATH.`,\n )\n }\n },\n\n async loadTasks(opts: LoadOptions = {}) {\n let tasks = TASKS\n if (opts.ids) tasks = tasks.filter((t) => opts.ids!.includes(t.id))\n if (opts.limit != null) tasks = tasks.slice(0, opts.limit)\n return tasks.map((t): BenchTask => ({ id: t.id, prompt: t.prompt, metadata: t.meta as unknown as Record<string, unknown> }))\n },\n\n async goldArtifact(task: BenchTask) {\n const meta = task.metadata as unknown as CadTaskMeta | undefined\n return meta?.gold\n },\n\n async judge(task: BenchTask, artifact: string): Promise<BenchScore> {\n const spec = (task.metadata as unknown as CadTaskMeta).spec\n const src = artifact.trim()\n if (!src) return { resolved: false, score: 0, detail: 'empty artifact' }\n\n const dir = await mkdtemp(join(tmpdir(), 'cad-'))\n const scad = join(dir, 'model.scad')\n const stlPath = join(dir, 'model.stl')\n const pngPath = join(dir, 'model.png')\n await writeFile(scad, src)\n\n // GATE 1: compile + export STL. Nonzero exit / CGAL error => does not compile.\n let stderr = ''\n try {\n const r = await openscad(['-o', stlPath, scad], dir)\n stderr = r.stderr\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err)\n return { resolved: false, score: 0, detail: `compile failed: ${msg.slice(0, 300)}` }\n }\n\n // Render a PNG alongside (the artifact run-capsule animates). Non-fatal.\n try {\n await openscad(\n ['-o', pngPath, '--imgsize=1100,850', '--camera=40,30,40,55,0,25,260', '--colorscheme=Tomorrow', scad],\n dir,\n )\n } catch {\n /* render is for the reel; geometry gate already has the STL */\n }\n\n let stl: string\n try {\n stl = await readFile(stlPath, 'utf8')\n } catch {\n return { resolved: false, score: 0, detail: 'compiled but produced no STL (empty geometry)' }\n }\n const volumes = Number(/Volumes:\\s*(\\d+)/.exec(stderr)?.[1] ?? '1')\n const geo = measureStl(stl, volumes)\n const { checks, score } = scoreGeometry(geo, spec)\n const resolved = score === 1\n const detail = JSON.stringify({\n checks,\n geo: {\n triangles: geo.triangles,\n volumes: geo.volumes,\n bbox: { x: +geo.bbox.x.toFixed(1), y: +geo.bbox.y.toFixed(1), z: +geo.bbox.z.toFixed(1) },\n hollowRatio: +(geo.solidVolume / geo.bboxVolume).toFixed(3),\n topVsBaseFootprint: geo.baseFootprint ? +(geo.topFootprint / geo.baseFootprint).toFixed(3) : null,\n },\n renderPath: pngPath,\n stlPath,\n })\n return { resolved, score, detail }\n },\n }\n}\n"],"mappings":";AAyBA,SAAS,gBAAgB;AACzB,SAAS,SAAS,UAAU,iBAAiB;AAC7C,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAG1B,IAAM,gBAAgB,UAAU,QAAQ;AAoBxC,eAAe,SAAS,MAAgB,KAA0D;AAEhG,QAAM,EAAE,QAAQ,OAAO,IAAI,MAAM,cAAc,YAAY,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG;AAAA,IACtF;AAAA,IACA,WAAW,OAAO,OAAO;AAAA,IACzB,SAAS;AAAA,EACX,CAAC;AACD,SAAO,EAAE,QAAQ,OAAO;AAC1B;AAeA,SAAS,WAAW,KAAa,mBAAqC;AACpE,QAAM,QAAyC,CAAC;AAChD,QAAM,OAA8F,CAAC;AACrG,QAAM,KAAK;AACX,MAAI;AACJ,QAAM,OAAwC,CAAC;AAC/C,SAAQ,IAAI,GAAG,KAAK,GAAG,EAAI,MAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/E,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK,QAAQ,KAAK,EAAG,MAAK,KAAK,CAAC,KAAK,CAAC,GAAI,KAAK,IAAI,CAAC,GAAI,KAAK,IAAI,CAAC,CAAE,CAAC;AAC7F,aAAW,KAAK,KAAM,OAAM,KAAK,CAAC;AAElC,QAAM,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,QAAM,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AA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,QAAQ,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,EAAE,QAAQ,CAAC,EAAE;AAAA,UACxF,aAAa,EAAE,IAAI,cAAc,IAAI,YAAY,QAAQ,CAAC;AAAA,UAC1D,oBAAoB,IAAI,gBAAgB,EAAE,IAAI,eAAe,IAAI,eAAe,QAAQ,CAAC,IAAI;AAAA,QAC/F;AAAA,QACA,YAAY;AAAA,QACZ;AAAA,MACF,CAAC;AACD,aAAO,EAAE,UAAU,OAAO,OAAO;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// src/benchmarks/humaneval.ts
|
|
2
|
+
import { execFile } from "child_process";
|
|
3
|
+
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { gunzipSync } from "zlib";
|
|
7
|
+
var humanevalUrl = "https://github.com/openai/human-eval/raw/master/data/HumanEval.jsonl.gz";
|
|
8
|
+
var dockerImage = "python:3.12-slim";
|
|
9
|
+
var dockerTimeoutMs = Number(process.env.DOCKER_TIMEOUT_MS ?? 2e4);
|
|
10
|
+
async function loadHumanEval(limit, offset = 0) {
|
|
11
|
+
const localGz = process.env.HUMANEVAL_GZ;
|
|
12
|
+
let gz;
|
|
13
|
+
if (localGz) {
|
|
14
|
+
gz = readFileSync(localGz);
|
|
15
|
+
} else {
|
|
16
|
+
const res = await fetch(humanevalUrl);
|
|
17
|
+
if (!res.ok) throw new Error(`HumanEval fetch HTTP ${res.status}: ${humanevalUrl}`);
|
|
18
|
+
gz = Buffer.from(await res.arrayBuffer());
|
|
19
|
+
}
|
|
20
|
+
const text = gunzipSync(gz).toString("utf8");
|
|
21
|
+
const tasks = [];
|
|
22
|
+
for (const line of text.split("\n")) {
|
|
23
|
+
if (line.trim() === "") continue;
|
|
24
|
+
const d = JSON.parse(line);
|
|
25
|
+
if (!d.task_id || !d.prompt || !d.test || !d.entry_point) {
|
|
26
|
+
throw new Error(`malformed HumanEval record: ${line.slice(0, 120)}`);
|
|
27
|
+
}
|
|
28
|
+
tasks.push({
|
|
29
|
+
taskId: d.task_id,
|
|
30
|
+
prompt: d.prompt,
|
|
31
|
+
test: d.test,
|
|
32
|
+
entryPoint: d.entry_point,
|
|
33
|
+
...d.canonical_solution ? { canonicalSolution: d.canonical_solution } : {}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (tasks.length === 0) throw new Error("HumanEval parsed to 0 tasks");
|
|
37
|
+
if (offset >= tasks.length) throw new Error(`OFFSET ${offset} >= dataset size ${tasks.length}`);
|
|
38
|
+
return tasks.slice(offset, offset + limit);
|
|
39
|
+
}
|
|
40
|
+
var solveInstruction = "Complete the following Python function. Output the COMPLETE function definition (signature, docstring optional, body) inside a single ```python code block. Include any imports the function needs. Do not write tests or example calls.";
|
|
41
|
+
function basePrompt(task) {
|
|
42
|
+
return `${solveInstruction}
|
|
43
|
+
|
|
44
|
+
\`\`\`python
|
|
45
|
+
${task.prompt}\`\`\``;
|
|
46
|
+
}
|
|
47
|
+
function extractCode(reply) {
|
|
48
|
+
const fenced = reply.match(/```(?:python|py)?\s*\n([\s\S]*?)```/i);
|
|
49
|
+
if (fenced && typeof fenced[1] === "string") return fenced[1].trim();
|
|
50
|
+
return reply.trim();
|
|
51
|
+
}
|
|
52
|
+
function buildProgram(task, candidate) {
|
|
53
|
+
return `${task.prompt}
|
|
54
|
+
${candidate}
|
|
55
|
+
|
|
56
|
+
${task.test}
|
|
57
|
+
|
|
58
|
+
check(${task.entryPoint})
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
var dockerRunSeq = 0;
|
|
62
|
+
function runPythonProgram(program, timeoutMs = dockerTimeoutMs) {
|
|
63
|
+
const dir = mkdtempSync(join(tmpdir(), "hev-"));
|
|
64
|
+
chmodSync(dir, 493);
|
|
65
|
+
writeFileSync(join(dir, "p.py"), program, { mode: 420 });
|
|
66
|
+
const name = `hev-${process.pid}-${dockerRunSeq++}`;
|
|
67
|
+
const startMarker = `__AGENT_RUNTIME_CANDIDATE_STARTED_${name}__`;
|
|
68
|
+
return new Promise((resolvePromise, reject) => {
|
|
69
|
+
let settled = false;
|
|
70
|
+
const cleanup = () => {
|
|
71
|
+
rmSync(dir, { recursive: true, force: true });
|
|
72
|
+
execFile("docker", ["rm", "-f", name], () => {
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const finish = (res) => {
|
|
76
|
+
if (settled) return;
|
|
77
|
+
settled = true;
|
|
78
|
+
clearTimeout(backstop);
|
|
79
|
+
cleanup();
|
|
80
|
+
resolvePromise(res);
|
|
81
|
+
};
|
|
82
|
+
const fail = (e) => {
|
|
83
|
+
if (settled) return;
|
|
84
|
+
settled = true;
|
|
85
|
+
clearTimeout(backstop);
|
|
86
|
+
cleanup();
|
|
87
|
+
reject(e);
|
|
88
|
+
};
|
|
89
|
+
const outerTimeoutMs = timeoutMs + 3e3;
|
|
90
|
+
const backstop = setTimeout(
|
|
91
|
+
() => fail(new Error(`docker checker did not return within ${outerTimeoutMs + 3e3}ms`)),
|
|
92
|
+
outerTimeoutMs + 3e3
|
|
93
|
+
);
|
|
94
|
+
const inContainerSeconds = Math.max(1, Math.ceil(timeoutMs / 1e3));
|
|
95
|
+
execFile(
|
|
96
|
+
"docker",
|
|
97
|
+
[
|
|
98
|
+
"run",
|
|
99
|
+
"--rm",
|
|
100
|
+
"--pull=never",
|
|
101
|
+
"--name",
|
|
102
|
+
name,
|
|
103
|
+
"--network=none",
|
|
104
|
+
"--cpus=1",
|
|
105
|
+
"--memory=512m",
|
|
106
|
+
"--pids-limit=64",
|
|
107
|
+
"--cap-drop=ALL",
|
|
108
|
+
"--security-opt=no-new-privileges",
|
|
109
|
+
"--read-only",
|
|
110
|
+
"--tmpfs",
|
|
111
|
+
"/tmp:rw,nosuid,nodev,noexec,size=64m,mode=1777",
|
|
112
|
+
"--user",
|
|
113
|
+
"65534:65534",
|
|
114
|
+
"-v",
|
|
115
|
+
`${dir}:/w:ro`,
|
|
116
|
+
"-w",
|
|
117
|
+
"/w",
|
|
118
|
+
dockerImage,
|
|
119
|
+
"sh",
|
|
120
|
+
"-c",
|
|
121
|
+
'command -v timeout >/dev/null 2>&1 && command -v python >/dev/null 2>&1 && [ -r /w/p.py ] || exit 126; printf "%s\\n" "$1"; exec timeout -s KILL "$2" python /w/p.py',
|
|
122
|
+
"agent-runtime-checker",
|
|
123
|
+
startMarker,
|
|
124
|
+
`${inContainerSeconds}s`
|
|
125
|
+
],
|
|
126
|
+
{ timeout: outerTimeoutMs, killSignal: "SIGKILL", maxBuffer: 4 * 1024 * 1024 },
|
|
127
|
+
(err, stdout, stderr) => {
|
|
128
|
+
const markerLine = `${startMarker}
|
|
129
|
+
`;
|
|
130
|
+
const candidateStarted = stdout?.startsWith(markerLine) === true;
|
|
131
|
+
const candidateStdout = candidateStarted ? stdout.slice(markerLine.length) : stdout ?? "";
|
|
132
|
+
if (err) {
|
|
133
|
+
const e = err;
|
|
134
|
+
if (e.code === "ENOENT") {
|
|
135
|
+
fail(new Error("docker binary not found on PATH \u2014 cannot run the deployable checker"));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (e.killed) {
|
|
139
|
+
fail(new Error(`docker checker exceeded its ${outerTimeoutMs}ms outer timeout`));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!candidateStarted) {
|
|
143
|
+
if (/cannot connect to the docker daemon|is the docker daemon running|permission denied while trying to connect/i.test(
|
|
144
|
+
stderr
|
|
145
|
+
)) {
|
|
146
|
+
fail(new Error(`docker daemon unreachable: ${stderr.slice(0, 200)}`));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (/unable to find image|no such image|pull access denied|manifest unknown/i.test(stderr)) {
|
|
150
|
+
fail(new Error(`docker image ${dockerImage} unavailable: ${stderr.slice(0, 200)}`));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
fail(
|
|
154
|
+
new Error(
|
|
155
|
+
`docker checker did not start the candidate: ${stderr.slice(0, 200) || e.message}`
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const exitCode = typeof e.code === "number" ? e.code : 1;
|
|
161
|
+
finish({
|
|
162
|
+
exitCode,
|
|
163
|
+
stdout: candidateStdout,
|
|
164
|
+
stderr: stderr ?? ""
|
|
165
|
+
});
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (!candidateStarted) {
|
|
169
|
+
fail(new Error("docker checker exited without starting the candidate"));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
finish({ exitCode: 0, stdout: candidateStdout, stderr: stderr ?? "" });
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async function runChecker(task, candidate) {
|
|
178
|
+
const result = await runPythonProgram(buildProgram(task, candidate));
|
|
179
|
+
return result.exitCode === 0 ? { pass: 1 } : { pass: 0, detail: result.stderr.slice(-600) || "timed out (no output)" };
|
|
180
|
+
}
|
|
181
|
+
function toBenchTask(t) {
|
|
182
|
+
const metadata = {
|
|
183
|
+
promptHeader: t.prompt,
|
|
184
|
+
test: t.test,
|
|
185
|
+
entryPoint: t.entryPoint,
|
|
186
|
+
...t.canonicalSolution ? { canonicalSolution: t.canonicalSolution } : {}
|
|
187
|
+
};
|
|
188
|
+
return { id: t.taskId, prompt: basePrompt(t), metadata };
|
|
189
|
+
}
|
|
190
|
+
function taskFromMeta(task) {
|
|
191
|
+
const m = task.metadata;
|
|
192
|
+
if (!m?.promptHeader || !m.test || !m.entryPoint) {
|
|
193
|
+
throw new Error(`HumanEval judge: task ${task.id} missing checker metadata`);
|
|
194
|
+
}
|
|
195
|
+
return { taskId: task.id, prompt: m.promptHeader, test: m.test, entryPoint: m.entryPoint };
|
|
196
|
+
}
|
|
197
|
+
function createHumanEvalAdapter() {
|
|
198
|
+
return {
|
|
199
|
+
name: "humaneval",
|
|
200
|
+
async preflight() {
|
|
201
|
+
await new Promise((resolve, reject) => {
|
|
202
|
+
execFile("docker", ["version", "--format", "{{.Server.Version}}"], (err) => {
|
|
203
|
+
if (err) reject(new Error("HumanEval judge needs a running Docker daemon (python:3.12-slim, --network=none)"));
|
|
204
|
+
else resolve();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
await new Promise((resolve, reject) => {
|
|
208
|
+
execFile("docker", ["image", "inspect", dockerImage], (err) => {
|
|
209
|
+
if (err) reject(new Error(`HumanEval judge needs the cached Docker image ${dockerImage}`));
|
|
210
|
+
else resolve();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
async loadTasks(opts) {
|
|
215
|
+
const offset = Number(process.env.OFFSET ?? 0);
|
|
216
|
+
const all = await loadHumanEval(opts?.ids ? 164 : opts?.limit ?? 8, offset);
|
|
217
|
+
const picked = opts?.ids ? all.filter((t) => opts.ids?.includes(t.taskId)) : all;
|
|
218
|
+
return picked.map(toBenchTask);
|
|
219
|
+
},
|
|
220
|
+
async judge(task, artifact) {
|
|
221
|
+
const { pass } = await runChecker(taskFromMeta(task), extractCode(artifact));
|
|
222
|
+
return { resolved: pass === 1, score: pass, detail: pass === 1 ? "tests passed" : "tests failed" };
|
|
223
|
+
},
|
|
224
|
+
async goldArtifact(task) {
|
|
225
|
+
const m = task.metadata;
|
|
226
|
+
const sol = m?.canonicalSolution;
|
|
227
|
+
return sol ? `${m.promptHeader}${sol}` : void 0;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export {
|
|
233
|
+
loadHumanEval,
|
|
234
|
+
basePrompt,
|
|
235
|
+
extractCode,
|
|
236
|
+
runPythonProgram,
|
|
237
|
+
runChecker,
|
|
238
|
+
createHumanEvalAdapter
|
|
239
|
+
};
|
|
240
|
+
//# sourceMappingURL=chunk-5H5XV76F.js.map
|