@tangle-network/agent-bench 0.4.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/adapters.d.ts +4 -11
- package/dist/adapters.js +78 -41
- package/dist/adapters.js.map +1 -1
- package/dist/benchmarks/_harness.d.ts +51 -66
- package/dist/benchmarks/_harness.js +329 -31
- package/dist/benchmarks/_harness.js.map +1 -1
- package/dist/benchmarks/aec-bench.d.ts +4 -25
- package/dist/benchmarks/aec-bench.js +242 -7
- package/dist/benchmarks/aec-bench.js.map +1 -1
- package/dist/benchmarks/agentbench.d.ts +5 -13
- package/dist/benchmarks/agentbench.js +114 -9
- package/dist/benchmarks/agentbench.js.map +1 -1
- package/dist/benchmarks/appworld.d.ts +9 -29
- package/dist/benchmarks/appworld.js +317 -12
- package/dist/benchmarks/appworld.js.map +1 -1
- package/dist/benchmarks/bfcl.d.ts +5 -15
- package/dist/benchmarks/bfcl.js +264 -9
- package/dist/benchmarks/bfcl.js.map +1 -1
- package/dist/benchmarks/cad-design.d.ts +16 -41
- package/dist/benchmarks/cad-design.js +512 -6
- package/dist/benchmarks/cad-design.js.map +1 -1
- package/dist/benchmarks/cadbench.d.ts +4 -17
- package/dist/benchmarks/cadbench.js +2 -8
- package/dist/benchmarks/cadgenbench.d.ts +4 -20
- package/dist/benchmarks/cadgenbench.js +2 -8
- package/dist/benchmarks/commit0.d.ts +5 -27
- package/dist/benchmarks/commit0.js +187 -9
- package/dist/benchmarks/commit0.js.map +1 -1
- package/dist/benchmarks/crag.d.ts +4 -12
- package/dist/benchmarks/crag.js +110 -8
- package/dist/benchmarks/crag.js.map +1 -1
- package/dist/benchmarks/dabstep.d.ts +5 -15
- package/dist/benchmarks/dabstep.js +177 -9
- package/dist/benchmarks/dabstep.js.map +1 -1
- package/dist/benchmarks/enterpriseops-gym.d.ts +5 -34
- package/dist/benchmarks/enterpriseops-gym.js +236 -9
- package/dist/benchmarks/enterpriseops-gym.js.map +1 -1
- package/dist/benchmarks/finresearchbench.d.ts +4 -13
- package/dist/benchmarks/finresearchbench.js +218 -7
- package/dist/benchmarks/finresearchbench.js.map +1 -1
- package/dist/benchmarks/finsearchcomp.d.ts +8 -39
- package/dist/benchmarks/finsearchcomp.js +267 -6
- package/dist/benchmarks/finsearchcomp.js.map +1 -1
- package/dist/benchmarks/frames.d.ts +15 -37
- package/dist/benchmarks/frames.js +408 -11
- package/dist/benchmarks/frames.js.map +1 -1
- package/dist/benchmarks/hotpotqa.d.ts +4 -24
- package/dist/benchmarks/hotpotqa.js +250 -14
- package/dist/benchmarks/hotpotqa.js.map +1 -1
- package/dist/benchmarks/humaneval.d.ts +19 -37
- package/dist/benchmarks/humaneval.js +279 -16
- package/dist/benchmarks/humaneval.js.map +1 -1
- package/dist/benchmarks/mind2web.d.ts +7 -34
- package/dist/benchmarks/mind2web.js +257 -8
- package/dist/benchmarks/mind2web.js.map +1 -1
- package/dist/benchmarks/nomiracl.d.ts +4 -13
- package/dist/benchmarks/nomiracl.js +146 -8
- package/dist/benchmarks/nomiracl.js.map +1 -1
- package/dist/benchmarks/open-rag-bench.d.ts +4 -12
- package/dist/benchmarks/open-rag-bench.js +110 -8
- package/dist/benchmarks/open-rag-bench.js.map +1 -1
- package/dist/benchmarks/programbench.d.ts +5 -29
- package/dist/benchmarks/programbench.js +161 -9
- package/dist/benchmarks/programbench.js.map +1 -1
- package/dist/benchmarks/rag-shared.d.ts +21 -20
- package/dist/benchmarks/rag-shared.js +245 -38
- package/dist/benchmarks/rag-shared.js.map +1 -1
- package/dist/benchmarks/ragbench.d.ts +4 -14
- package/dist/benchmarks/ragbench.js +127 -8
- package/dist/benchmarks/ragbench.js.map +1 -1
- package/dist/benchmarks/simpleqa.d.ts +17 -44
- package/dist/benchmarks/simpleqa.js +293 -10
- package/dist/benchmarks/simpleqa.js.map +1 -1
- package/dist/benchmarks/swe-bench.d.ts +23 -36
- package/dist/benchmarks/swe-bench.js +234 -13
- package/dist/benchmarks/swe-bench.js.map +1 -1
- package/dist/benchmarks/t2-ragbench.d.ts +4 -12
- package/dist/benchmarks/t2-ragbench.js +118 -8
- package/dist/benchmarks/t2-ragbench.js.map +1 -1
- package/dist/benchmarks/tau-bench-shared.d.ts +14 -22
- package/dist/benchmarks/tau-bench-shared.js +169 -9
- package/dist/benchmarks/tau-bench-shared.js.map +1 -1
- package/dist/benchmarks/tau2-bench.d.ts +5 -5
- package/dist/benchmarks/tau2-bench.js +28 -10
- package/dist/benchmarks/tau2-bench.js.map +1 -1
- package/dist/benchmarks/tau3-banking.d.ts +4 -13
- package/dist/benchmarks/tau3-banking.js +28 -8
- package/dist/benchmarks/tau3-banking.js.map +1 -1
- package/dist/benchmarks/terminal-bench.d.ts +4 -22
- package/dist/benchmarks/terminal-bench.js +140 -7
- package/dist/benchmarks/terminal-bench.js.map +1 -1
- package/dist/benchmarks/toollm.d.ts +5 -13
- package/dist/benchmarks/toollm.js +184 -9
- package/dist/benchmarks/toollm.js.map +1 -1
- package/dist/benchmarks/trata-hedge.d.ts +4 -30
- package/dist/benchmarks/trata-hedge.js +336 -6
- package/dist/benchmarks/trata-hedge.js.map +1 -1
- package/dist/benchmarks/types.d.ts +85 -94
- package/dist/benchmarks/types.js +1 -1
- package/dist/benchmarks/webarena-verified.d.ts +5 -13
- package/dist/benchmarks/webarena-verified.js +152 -9
- package/dist/benchmarks/webarena-verified.js.map +1 -1
- package/dist/cadbench-DpQWZHp4.js +285 -0
- package/dist/cadbench-DpQWZHp4.js.map +1 -0
- package/dist/cadgenbench-DRhczfsG.js +151 -0
- package/dist/cadgenbench-DRhczfsG.js.map +1 -0
- package/dist/index.d.ts +245 -293
- package/dist/index.js +1669 -1791
- package/dist/index.js.map +1 -1
- package/package.json +17 -14
- package/pier_agents/candidate_contract.py +238 -24
- package/pier_agents/tangle_candidate.py +75 -5
- package/scripts/verify-packed-consumer.mjs +84 -17
- package/scripts/verify-pier-agent.mts +6 -4
- package/src/benchmarks/_harness.test.mts +16 -1
- package/src/benchmarks/_harness.ts +9 -2
- package/src/benchmarks/terminal-bench.ts +2 -1
- package/src/corpus.test.mts +13 -0
- package/src/corpus.ts +4 -0
- package/src/profile-coordinates.ts +2 -2
- package/src/rollout-ledger/backfill-swe-arena.mts +5 -1
- package/src/rollout-ledger/settle-capture.mts +7 -1
- package/src/search-bench/profiles.ts +1 -1
- package/src/skill-sandbox-smoke.mts +2 -1
- package/src/swe-arena/gepa-seat.mts +1 -1
- package/src/swe-arena/ledger-orphans.test.mts +36 -34
- package/dist/benchmarks/cadbench.js.map +0 -1
- package/dist/benchmarks/cadgenbench.js.map +0 -1
- package/dist/benchmarks/types.js.map +0 -1
- package/dist/chunk-3U5TXJZS.js +0 -251
- package/dist/chunk-3U5TXJZS.js.map +0 -1
- package/dist/chunk-53UPUNBZ.js +0 -325
- package/dist/chunk-53UPUNBZ.js.map +0 -1
- package/dist/chunk-5H5XV76F.js +0 -240
- package/dist/chunk-5H5XV76F.js.map +0 -1
- package/dist/chunk-7GRVHU22.js +0 -208
- package/dist/chunk-7GRVHU22.js.map +0 -1
- package/dist/chunk-C7T7WEK2.js +0 -103
- package/dist/chunk-C7T7WEK2.js.map +0 -1
- package/dist/chunk-HWST3SED.js +0 -162
- package/dist/chunk-HWST3SED.js.map +0 -1
- package/dist/chunk-IA2FBTWC.js +0 -318
- package/dist/chunk-IA2FBTWC.js.map +0 -1
- package/dist/chunk-IFVINJ4B.js +0 -142
- package/dist/chunk-IFVINJ4B.js.map +0 -1
- package/dist/chunk-INNOYXCP.js +0 -387
- package/dist/chunk-INNOYXCP.js.map +0 -1
- package/dist/chunk-IZ5M6OAC.js +0 -169
- package/dist/chunk-IZ5M6OAC.js.map +0 -1
- package/dist/chunk-JTHWEDEW.js +0 -32
- package/dist/chunk-JTHWEDEW.js.map +0 -1
- package/dist/chunk-K3BQGZCT.js +0 -221
- package/dist/chunk-K3BQGZCT.js.map +0 -1
- package/dist/chunk-KP5KD6EN.js +0 -276
- package/dist/chunk-KP5KD6EN.js.map +0 -1
- package/dist/chunk-MQMRLGOG.js +0 -136
- package/dist/chunk-MQMRLGOG.js.map +0 -1
- package/dist/chunk-NQG5XDSB.js +0 -147
- package/dist/chunk-NQG5XDSB.js.map +0 -1
- package/dist/chunk-PA2ZKHJC.js +0 -230
- package/dist/chunk-PA2ZKHJC.js.map +0 -1
- package/dist/chunk-PB64GYIG.js +0 -118
- package/dist/chunk-PB64GYIG.js.map +0 -1
- package/dist/chunk-PUIRNYI7.js +0 -189
- package/dist/chunk-PUIRNYI7.js.map +0 -1
- package/dist/chunk-RCYQEFNX.js +0 -30
- package/dist/chunk-RCYQEFNX.js.map +0 -1
- package/dist/chunk-RH5F53JT.js +0 -182
- package/dist/chunk-RH5F53JT.js.map +0 -1
- package/dist/chunk-SEVJPLZC.js +0 -260
- package/dist/chunk-SEVJPLZC.js.map +0 -1
- package/dist/chunk-SFLA7OH3.js +0 -27
- package/dist/chunk-SFLA7OH3.js.map +0 -1
- package/dist/chunk-SHM6MRRF.js +0 -130
- package/dist/chunk-SHM6MRRF.js.map +0 -1
- package/dist/chunk-SHYIRB7I.js +0 -120
- package/dist/chunk-SHYIRB7I.js.map +0 -1
- package/dist/chunk-SVR2LKYI.js +0 -116
- package/dist/chunk-SVR2LKYI.js.map +0 -1
- package/dist/chunk-TBKU5XQI.js +0 -228
- package/dist/chunk-TBKU5XQI.js.map +0 -1
- package/dist/chunk-UPAMRDX4.js +0 -233
- package/dist/chunk-UPAMRDX4.js.map +0 -1
- package/dist/chunk-V7AEBY6U.js +0 -144
- package/dist/chunk-V7AEBY6U.js.map +0 -1
- package/dist/chunk-VQRS7VUC.js +0 -342
- package/dist/chunk-VQRS7VUC.js.map +0 -1
- package/dist/chunk-WSKWVEQB.js +0 -317
- package/dist/chunk-WSKWVEQB.js.map +0 -1
- package/dist/chunk-X3BTXCJ4.js +0 -262
- package/dist/chunk-X3BTXCJ4.js.map +0 -1
- package/dist/chunk-XKEFIFIC.js +0 -197
- package/dist/chunk-XKEFIFIC.js.map +0 -1
- package/dist/chunk-XYA4XSNU.js +0 -148
- package/dist/chunk-XYA4XSNU.js.map +0 -1
- package/dist/chunk-YSMEKBTD.js +0 -211
- package/dist/chunk-YSMEKBTD.js.map +0 -1
- package/dist/chunk-Z4TZ76N7.js +0 -170
- package/dist/chunk-Z4TZ76N7.js.map +0 -1
package/dist/chunk-3U5TXJZS.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
preflightVenvImports,
|
|
3
|
-
readJsonReport,
|
|
4
|
-
runStagedJudge,
|
|
5
|
-
runVenvPython,
|
|
6
|
-
safeRunId,
|
|
7
|
-
stageFile
|
|
8
|
-
} from "./chunk-WSKWVEQB.js";
|
|
9
|
-
|
|
10
|
-
// src/benchmarks/swe-bench.ts
|
|
11
|
-
import { join } from "path";
|
|
12
|
-
var SWE_REPO_DIR = "/work";
|
|
13
|
-
var swePatchOutput = {
|
|
14
|
-
parse(events) {
|
|
15
|
-
let text = "";
|
|
16
|
-
for (const ev of events) {
|
|
17
|
-
const d = ev?.data;
|
|
18
|
-
const t = d?.finalText ?? d?.text ?? d?.result;
|
|
19
|
-
if (typeof t === "string" && t.length > 0) text = t;
|
|
20
|
-
}
|
|
21
|
-
const fences = [...text.matchAll(/```(?:diff|patch)?\s*\n([\s\S]*?)```/g)];
|
|
22
|
-
const last = fences.at(-1)?.[1];
|
|
23
|
-
return (last ?? text).trim();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var DATASET = "princeton-nlp/SWE-bench_Verified";
|
|
27
|
-
var SWE_CACHE_LEVELS = /* @__PURE__ */ new Set(["none", "base", "env", "instance"]);
|
|
28
|
-
function scorerNamespace() {
|
|
29
|
-
const namespace = process.env.SWEBENCH_NAMESPACE ?? "swebench";
|
|
30
|
-
if (namespace !== "swebench" && namespace !== "none") {
|
|
31
|
-
throw new Error(`SWEBENCH_NAMESPACE must be swebench|none, got "${namespace}"`);
|
|
32
|
-
}
|
|
33
|
-
return namespace;
|
|
34
|
-
}
|
|
35
|
-
var TEST_FILE_EXCLUDES = [
|
|
36
|
-
"':(exclude,glob)**/tests/**'",
|
|
37
|
-
"':(exclude,glob)**/test/**'",
|
|
38
|
-
"':(exclude,glob)test_*.py'",
|
|
39
|
-
"':(exclude,glob)**/test_*.py'",
|
|
40
|
-
"':(exclude,glob)*_test.py'",
|
|
41
|
-
"':(exclude,glob)**/*_test.py'",
|
|
42
|
-
"':(exclude,glob)conftest.py'",
|
|
43
|
-
"':(exclude,glob)**/conftest.py'"
|
|
44
|
-
].join(" ");
|
|
45
|
-
function stringIds(report, key) {
|
|
46
|
-
const value = report[key];
|
|
47
|
-
if (value === void 0) return [];
|
|
48
|
-
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
49
|
-
throw new Error(`swe-bench: malformed ${key}`);
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
function scoreSweReport(taskId, value) {
|
|
54
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
55
|
-
throw new Error("swe-bench: report must be an object");
|
|
56
|
-
}
|
|
57
|
-
const report = value;
|
|
58
|
-
const statusIds = {
|
|
59
|
-
resolved: stringIds(report, "resolved_ids"),
|
|
60
|
-
unresolved: stringIds(report, "unresolved_ids"),
|
|
61
|
-
emptyPatch: stringIds(report, "empty_patch_ids"),
|
|
62
|
-
completed: stringIds(report, "completed_ids"),
|
|
63
|
-
incomplete: stringIds(report, "incomplete_ids"),
|
|
64
|
-
error: stringIds(report, "error_ids")
|
|
65
|
-
};
|
|
66
|
-
const submitted = stringIds(report, "submitted_ids");
|
|
67
|
-
const mentioned = Object.values(statusIds).flat();
|
|
68
|
-
if (mentioned.some((id) => id !== taskId) || submitted.length > 0 && (submitted.length !== 1 || submitted[0] !== taskId)) {
|
|
69
|
-
throw new Error(`swe-bench: report identity mismatch for ${taskId}`);
|
|
70
|
-
}
|
|
71
|
-
if (statusIds.error.includes(taskId) || statusIds.incomplete.includes(taskId)) {
|
|
72
|
-
throw new Error(`swe-bench: evaluator failed for ${taskId}`);
|
|
73
|
-
}
|
|
74
|
-
const outcomes = [
|
|
75
|
-
statusIds.resolved.includes(taskId),
|
|
76
|
-
statusIds.unresolved.includes(taskId),
|
|
77
|
-
statusIds.emptyPatch.includes(taskId)
|
|
78
|
-
];
|
|
79
|
-
if (outcomes.filter(Boolean).length !== 1) {
|
|
80
|
-
throw new Error(`swe-bench: report has no unique outcome for ${taskId}`);
|
|
81
|
-
}
|
|
82
|
-
if ((outcomes[0] || outcomes[1]) && !statusIds.completed.includes(taskId)) {
|
|
83
|
-
throw new Error(`swe-bench: report lacks a completed evaluation for ${taskId}`);
|
|
84
|
-
}
|
|
85
|
-
const resolved = outcomes[0];
|
|
86
|
-
return { resolved, score: resolved ? 1 : 0, detail: JSON.stringify(report) };
|
|
87
|
-
}
|
|
88
|
-
function sweEvaluationArgv(args) {
|
|
89
|
-
return [
|
|
90
|
-
"-m",
|
|
91
|
-
"swebench.harness.run_evaluation",
|
|
92
|
-
"--dataset_name",
|
|
93
|
-
DATASET,
|
|
94
|
-
"--predictions_path",
|
|
95
|
-
args.predictionsPath,
|
|
96
|
-
"--run_id",
|
|
97
|
-
args.runId,
|
|
98
|
-
"--instance_ids",
|
|
99
|
-
args.instanceId,
|
|
100
|
-
"--max_workers",
|
|
101
|
-
"1",
|
|
102
|
-
"--namespace",
|
|
103
|
-
args.namespace ?? scorerNamespace(),
|
|
104
|
-
"--cache_level",
|
|
105
|
-
args.cacheLevel
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
function shellQuote(value) {
|
|
109
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
110
|
-
}
|
|
111
|
-
function sweMetadata(task) {
|
|
112
|
-
const repo = String(task.metadata?.repo ?? "");
|
|
113
|
-
const base = String(task.metadata?.base_commit ?? "");
|
|
114
|
-
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo)) {
|
|
115
|
-
throw new Error(`swe-bench: invalid repo metadata for ${task.id}: ${repo}`);
|
|
116
|
-
}
|
|
117
|
-
if (!/^[0-9a-f]{7,40}$/i.test(base)) {
|
|
118
|
-
throw new Error(`swe-bench: invalid base_commit metadata for ${task.id}: ${base}`);
|
|
119
|
-
}
|
|
120
|
-
return { repo, base };
|
|
121
|
-
}
|
|
122
|
-
function createSweBenchAdapter(options = {}) {
|
|
123
|
-
if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw new Error("swe-bench: timeoutMs must be a positive integer");
|
|
124
|
-
const cacheLevel = options.cacheLevel ?? "env";
|
|
125
|
-
if (!SWE_CACHE_LEVELS.has(cacheLevel)) throw new Error("swe-bench: invalid cacheLevel");
|
|
126
|
-
if (options.captureEvaluatorArtifacts !== void 0 && typeof options.captureEvaluatorArtifacts !== "function") throw new Error("swe-bench: captureEvaluatorArtifacts must be a function");
|
|
127
|
-
let attemptSequence = 0;
|
|
128
|
-
return {
|
|
129
|
-
name: "swe-bench-verified",
|
|
130
|
-
output: swePatchOutput,
|
|
131
|
-
// Extract the patch from repo STATE, not printed text: stage every edit the
|
|
132
|
-
// agent made in the cloned repo and diff it against the checked-out
|
|
133
|
-
// base_commit (`HEAD`). Test files are excluded — the judge applies the gold
|
|
134
|
-
// `test_patch` itself, so an agent edit to a test would collide on apply. The
|
|
135
|
-
// paths come out `a/<repo-relative>` (cwd = repo root), matching the gold
|
|
136
|
-
// patch format the swebench judge's `git apply` expects.
|
|
137
|
-
// Pre-stage: clone the instance repo at base_commit into SWE_REPO_DIR so the
|
|
138
|
-
// agent only edits (the harness owns the checkout — a stochastic model can't be
|
|
139
|
-
// trusted to clone to an exact path). `--quiet` keeps the exec output small.
|
|
140
|
-
boxSetup(task) {
|
|
141
|
-
const { repo, base } = sweMetadata(task);
|
|
142
|
-
return {
|
|
143
|
-
command: `rm -rf ${shellQuote(SWE_REPO_DIR)} && git clone --quiet ${shellQuote(`https://github.com/${repo}`)} ${shellQuote(SWE_REPO_DIR)} && git -C ${shellQuote(SWE_REPO_DIR)} checkout --quiet ${shellQuote(base)}`
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
boxExtract() {
|
|
147
|
-
return {
|
|
148
|
-
command: `git -C ${shellQuote(SWE_REPO_DIR)} add -A && git -C ${shellQuote(SWE_REPO_DIR)} diff --cached -- . ${TEST_FILE_EXCLUDES}`
|
|
149
|
-
};
|
|
150
|
-
},
|
|
151
|
-
async preflight() {
|
|
152
|
-
await preflightVenvImports({
|
|
153
|
-
modules: ["swebench"],
|
|
154
|
-
requireDocker: true,
|
|
155
|
-
fix: `Fix: (1) python3 -m venv bench/.venv && bench/.venv/bin/pip install swebench ; (2) ensure the Docker daemon is running (the judge builds per-instance images).`
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
async loadTasks(opts = {}) {
|
|
159
|
-
const limit = opts.limit ?? 10;
|
|
160
|
-
const split = opts.split ?? "test";
|
|
161
|
-
const script = `
|
|
162
|
-
import json, sys
|
|
163
|
-
from datasets import load_dataset
|
|
164
|
-
ds = load_dataset(${JSON.stringify(DATASET)}, split=${JSON.stringify(split)})
|
|
165
|
-
ids = set(json.loads(sys.argv[1])) if len(sys.argv) > 1 and sys.argv[1] else None
|
|
166
|
-
out = []
|
|
167
|
-
for r in ds:
|
|
168
|
-
if ids is not None and r["instance_id"] not in ids:
|
|
169
|
-
continue
|
|
170
|
-
out.append({
|
|
171
|
-
"instance_id": r["instance_id"], "repo": r["repo"], "base_commit": r["base_commit"],
|
|
172
|
-
"problem_statement": r["problem_statement"], "patch": r["patch"], "test_patch": r["test_patch"],
|
|
173
|
-
"FAIL_TO_PASS": r["FAIL_TO_PASS"], "PASS_TO_PASS": r["PASS_TO_PASS"],
|
|
174
|
-
"version": r.get("version"), "environment_setup_commit": r.get("environment_setup_commit"),
|
|
175
|
-
})
|
|
176
|
-
if ids is None and len(out) >= ${limit}:
|
|
177
|
-
break
|
|
178
|
-
print(json.dumps(out))
|
|
179
|
-
`;
|
|
180
|
-
const stdout = await runVenvPython(script, [opts.ids ? JSON.stringify(opts.ids) : ""]);
|
|
181
|
-
const rows = JSON.parse(stdout);
|
|
182
|
-
return rows.map(
|
|
183
|
-
(r) => ({
|
|
184
|
-
id: String(r.instance_id),
|
|
185
|
-
split,
|
|
186
|
-
prompt: [
|
|
187
|
-
`Repository: ${r.repo} @ ${r.base_commit}`,
|
|
188
|
-
"",
|
|
189
|
-
`The repository is ALREADY cloned at ${SWE_REPO_DIR}, checked out at commit ${r.base_commit}. Work there directly (\`cd ${SWE_REPO_DIR}\`); do not re-clone.`,
|
|
190
|
-
"",
|
|
191
|
-
"Resolve this issue by editing the repository SOURCE so the failing tests pass without breaking the passing ones. Do NOT edit test files \u2014 the evaluation runs hidden tests on a fresh checkout, so editing tests does not count. Keep the change minimal and confined to the cloned repo.",
|
|
192
|
-
"Work iteratively: reproduce the issue, implement the fix in the source, and re-run the relevant tests until they pass. You do NOT need to print the diff \u2014 the harness reads your committed edits directly from the repo.",
|
|
193
|
-
"",
|
|
194
|
-
"--- Issue ---",
|
|
195
|
-
String(r.problem_statement ?? "")
|
|
196
|
-
].join("\n"),
|
|
197
|
-
metadata: r
|
|
198
|
-
})
|
|
199
|
-
);
|
|
200
|
-
},
|
|
201
|
-
async goldArtifact(task) {
|
|
202
|
-
const gold = task.metadata?.patch;
|
|
203
|
-
return typeof gold === "string" ? gold : void 0;
|
|
204
|
-
},
|
|
205
|
-
async judge(task, artifact) {
|
|
206
|
-
const runId = safeRunId("bench", task.id);
|
|
207
|
-
const capture = options.captureEvaluatorArtifacts?.({
|
|
208
|
-
taskId: task.id,
|
|
209
|
-
runId,
|
|
210
|
-
attemptSequence: ++attemptSequence
|
|
211
|
-
});
|
|
212
|
-
return runStagedJudge({
|
|
213
|
-
tmpPrefix: "swebench-",
|
|
214
|
-
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs },
|
|
215
|
-
...capture === void 0 ? {} : { capture },
|
|
216
|
-
// Debug: retain the staged dir (holds swebench's per-instance apply/run
|
|
217
|
-
// logs) for post-mortem when SWEBENCH_KEEP_TMP is set. Off by default.
|
|
218
|
-
...process.env.SWEBENCH_KEEP_TMP ? { keepTmp: true } : {},
|
|
219
|
-
async stage(dir) {
|
|
220
|
-
await stageFile(
|
|
221
|
-
join(dir, "preds.json"),
|
|
222
|
-
JSON.stringify([
|
|
223
|
-
{ instance_id: task.id, model_name_or_path: "agent-runtime-bench", model_patch: artifact }
|
|
224
|
-
])
|
|
225
|
-
);
|
|
226
|
-
},
|
|
227
|
-
// The official evaluation harness. Pulls/builds the instance image, applies
|
|
228
|
-
// the patch, runs the test spec, writes a per-run report JSON in cwd.
|
|
229
|
-
argv: (dir) => sweEvaluationArgv({
|
|
230
|
-
predictionsPath: join(dir, "preds.json"),
|
|
231
|
-
runId,
|
|
232
|
-
instanceId: task.id,
|
|
233
|
-
cacheLevel,
|
|
234
|
-
namespace: scorerNamespace()
|
|
235
|
-
}),
|
|
236
|
-
async parseReport(dir) {
|
|
237
|
-
const report = await readJsonReport(join(dir, `agent-runtime-bench.${runId}.json`));
|
|
238
|
-
return scoreSweReport(task.id, report);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export {
|
|
246
|
-
swePatchOutput,
|
|
247
|
-
scoreSweReport,
|
|
248
|
-
sweEvaluationArgv,
|
|
249
|
-
createSweBenchAdapter
|
|
250
|
-
};
|
|
251
|
-
//# sourceMappingURL=chunk-3U5TXJZS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/benchmarks/swe-bench.ts"],"sourcesContent":["/**\n * SWE-bench Verified adapter. Worker artifact = a unified-diff patch. Judge =\n * the official `swebench` harness: apply the patch in the instance's Docker\n * image, run FAIL_TO_PASS + PASS_TO_PASS, report `resolved`. Fully deterministic\n * — no LLM judge.\n *\n * Requires: the bench `.venv` with `swebench` installed + a running Docker\n * daemon (per-instance images are pulled/built on first run).\n *\n * Process/Docker/report plumbing is shared via ./_harness; this file owns the\n * SWE-specific pieces: the patch OutputAdapter, the dataset dump, and the\n * predictions-file → run_evaluation argv → report-shape mapping.\n */\n\nimport { join } from 'node:path'\nimport type { OutputAdapter } from '@tangle-network/agent-runtime/loops'\nimport {\n preflightVenvImports,\n readJsonReport,\n runStagedJudge,\n runVenvPython,\n safeRunId,\n stageFile,\n type StagedRunCaptureSpec,\n} from './_harness'\nimport type { BenchmarkAdapter, BenchScore, BenchTask, LoadOptions } from './types'\n\n/**\n * Fixed in-box path the agent clones the instance repo into. It is the SINGLE\n * source of truth shared by the prompt template (which tells the agent to clone\n * here) and `boxExtract` (which runs `git diff` here after the shot) — so the\n * harness always knows exactly where the agent's edits live, for any instance.\n */\nconst SWE_REPO_DIR = '/work'\n\n/**\n * The SWE deliverable's FALLBACK parser, from the agent's event STREAM.\n *\n * The PRIMARY deliverable is `boxExtract` below: a `git diff` of the agent's\n * actual edits, read from the cloned repo's STATE inside the box (standard\n * SWE-bench practice). This event-stream parse only runs when that diff is empty\n * — a model that edited the source correctly but never printed a fenced diff (the\n * exact failure this replaces) still scores off its real changes, not its prose.\n */\nexport const swePatchOutput: OutputAdapter<string> = {\n parse(events) {\n let text = ''\n for (const ev of events) {\n const d = (ev as { data?: Record<string, unknown> })?.data\n const t = d?.finalText ?? d?.text ?? d?.result\n if (typeof t === 'string' && t.length > 0) text = t\n }\n // Last ```diff/```patch fenced block (the contract the prompt asks for);\n // fall back to the raw text so a fence-less but valid diff still reaches the judge.\n const fences = [...text.matchAll(/```(?:diff|patch)?\\s*\\n([\\s\\S]*?)```/g)]\n const last = fences.at(-1)?.[1]\n return (last ?? text).trim()\n },\n}\n\nconst DATASET = 'princeton-nlp/SWE-bench_Verified'\nexport type SweBenchCacheLevel = 'none' | 'base' | 'env' | 'instance'\n\nexport interface SweBenchArtifactCaptureContext {\n readonly taskId: string\n readonly runId: string\n /** One-based sequence unique within this adapter instance. */\n readonly attemptSequence: number\n}\n\nexport interface SweBenchAdapterOptions {\n readonly timeoutMs?: number\n readonly cacheLevel?: SweBenchCacheLevel\n /**\n * Return a unique destination for any attempt whose complete official\n * evaluator directory and process logs should be retained.\n */\n readonly captureEvaluatorArtifacts?: (\n context: SweBenchArtifactCaptureContext,\n ) => StagedRunCaptureSpec | undefined\n}\n\nconst SWE_CACHE_LEVELS = new Set<SweBenchCacheLevel>(['none', 'base', 'env', 'instance'])\n\nfunction scorerNamespace(): 'swebench' | 'none' {\n const namespace = process.env.SWEBENCH_NAMESPACE ?? 'swebench'\n if (namespace !== 'swebench' && namespace !== 'none') {\n throw new Error(`SWEBENCH_NAMESPACE must be swebench|none, got \"${namespace}\"`)\n }\n return namespace\n}\nconst TEST_FILE_EXCLUDES = [\n \"':(exclude,glob)**/tests/**'\",\n \"':(exclude,glob)**/test/**'\",\n \"':(exclude,glob)test_*.py'\",\n \"':(exclude,glob)**/test_*.py'\",\n \"':(exclude,glob)*_test.py'\",\n \"':(exclude,glob)**/*_test.py'\",\n \"':(exclude,glob)conftest.py'\",\n \"':(exclude,glob)**/conftest.py'\",\n].join(' ')\n\ninterface SweReport {\n resolved_instances?: number\n resolved_ids?: string[]\n unresolved_ids?: string[]\n empty_patch_ids?: string[]\n completed_ids?: string[]\n incomplete_ids?: string[]\n error_ids?: string[]\n submitted_ids?: string[]\n}\n\nfunction stringIds(report: Record<string, unknown>, key: keyof SweReport): string[] {\n const value = report[key]\n if (value === undefined) return []\n if (!Array.isArray(value) || value.some((entry) => typeof entry !== 'string')) {\n throw new Error(`swe-bench: malformed ${key}`)\n }\n return value\n}\n\n/** Convert one official report into a score without turning evaluator failures into agent failures. */\nexport function scoreSweReport(taskId: string, value: unknown): BenchScore {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n throw new Error('swe-bench: report must be an object')\n }\n const report = value as Record<string, unknown>\n const statusIds = {\n resolved: stringIds(report, 'resolved_ids'),\n unresolved: stringIds(report, 'unresolved_ids'),\n emptyPatch: stringIds(report, 'empty_patch_ids'),\n completed: stringIds(report, 'completed_ids'),\n incomplete: stringIds(report, 'incomplete_ids'),\n error: stringIds(report, 'error_ids'),\n }\n const submitted = stringIds(report, 'submitted_ids')\n const mentioned = Object.values(statusIds).flat()\n if (\n mentioned.some((id) => id !== taskId)\n || (submitted.length > 0 && (submitted.length !== 1 || submitted[0] !== taskId))\n ) {\n throw new Error(`swe-bench: report identity mismatch for ${taskId}`)\n }\n if (statusIds.error.includes(taskId) || statusIds.incomplete.includes(taskId)) {\n throw new Error(`swe-bench: evaluator failed for ${taskId}`)\n }\n const outcomes = [\n statusIds.resolved.includes(taskId),\n statusIds.unresolved.includes(taskId),\n statusIds.emptyPatch.includes(taskId),\n ]\n if (outcomes.filter(Boolean).length !== 1) {\n throw new Error(`swe-bench: report has no unique outcome for ${taskId}`)\n }\n if ((outcomes[0] || outcomes[1]) && !statusIds.completed.includes(taskId)) {\n throw new Error(`swe-bench: report lacks a completed evaluation for ${taskId}`)\n }\n const resolved = outcomes[0]\n return { resolved, score: resolved ? 1 : 0, detail: JSON.stringify(report) }\n}\n\nexport function sweEvaluationArgv(args: {\n readonly predictionsPath: string\n readonly runId: string\n readonly instanceId: string\n readonly cacheLevel: SweBenchCacheLevel\n readonly namespace?: 'swebench' | 'none'\n}): string[] {\n return [\n '-m', 'swebench.harness.run_evaluation',\n '--dataset_name', DATASET,\n '--predictions_path', args.predictionsPath,\n '--run_id', args.runId,\n '--instance_ids', args.instanceId,\n '--max_workers', '1',\n '--namespace', args.namespace ?? scorerNamespace(),\n '--cache_level', args.cacheLevel,\n ]\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replace(/'/g, `'\\\\''`)}'`\n}\n\nfunction sweMetadata(task: BenchTask): { repo: string; base: string } {\n const repo = String(task.metadata?.repo ?? '')\n const base = String(task.metadata?.base_commit ?? '')\n if (!/^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/.test(repo)) {\n throw new Error(`swe-bench: invalid repo metadata for ${task.id}: ${repo}`)\n }\n if (!/^[0-9a-f]{7,40}$/i.test(base)) {\n throw new Error(`swe-bench: invalid base_commit metadata for ${task.id}: ${base}`)\n }\n return { repo, base }\n}\n\nexport function createSweBenchAdapter(options: SweBenchAdapterOptions = {}): BenchmarkAdapter {\n if (\n options.timeoutMs !== undefined\n && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)\n ) throw new Error('swe-bench: timeoutMs must be a positive integer')\n const cacheLevel = options.cacheLevel ?? 'env'\n if (!SWE_CACHE_LEVELS.has(cacheLevel)) throw new Error('swe-bench: invalid cacheLevel')\n if (\n options.captureEvaluatorArtifacts !== undefined\n && typeof options.captureEvaluatorArtifacts !== 'function'\n ) throw new Error('swe-bench: captureEvaluatorArtifacts must be a function')\n let attemptSequence = 0\n return {\n name: 'swe-bench-verified',\n output: swePatchOutput,\n\n // Extract the patch from repo STATE, not printed text: stage every edit the\n // agent made in the cloned repo and diff it against the checked-out\n // base_commit (`HEAD`). Test files are excluded — the judge applies the gold\n // `test_patch` itself, so an agent edit to a test would collide on apply. The\n // paths come out `a/<repo-relative>` (cwd = repo root), matching the gold\n // patch format the swebench judge's `git apply` expects.\n // Pre-stage: clone the instance repo at base_commit into SWE_REPO_DIR so the\n // agent only edits (the harness owns the checkout — a stochastic model can't be\n // trusted to clone to an exact path). `--quiet` keeps the exec output small.\n boxSetup(task) {\n const { repo, base } = sweMetadata(task)\n return {\n command: `rm -rf ${shellQuote(SWE_REPO_DIR)} && git clone --quiet ${shellQuote(`https://github.com/${repo}`)} ${shellQuote(SWE_REPO_DIR)} && git -C ${shellQuote(SWE_REPO_DIR)} checkout --quiet ${shellQuote(base)}`,\n }\n },\n boxExtract() {\n return {\n command: `git -C ${shellQuote(SWE_REPO_DIR)} add -A && git -C ${shellQuote(SWE_REPO_DIR)} diff --cached -- . ${TEST_FILE_EXCLUDES}`,\n }\n },\n\n async preflight() {\n await preflightVenvImports({\n modules: ['swebench'],\n requireDocker: true,\n fix:\n `Fix: (1) python3 -m venv bench/.venv && bench/.venv/bin/pip install swebench ; ` +\n `(2) ensure the Docker daemon is running (the judge builds per-instance images).`,\n })\n },\n\n async loadTasks(opts: LoadOptions = {}) {\n const limit = opts.limit ?? 10\n const split = opts.split ?? 'test'\n // Dump instances as JSON via the datasets loader (HF download on first run).\n const script = `\nimport json, sys\nfrom datasets import load_dataset\nds = load_dataset(${JSON.stringify(DATASET)}, split=${JSON.stringify(split)})\nids = set(json.loads(sys.argv[1])) if len(sys.argv) > 1 and sys.argv[1] else None\nout = []\nfor r in ds:\n if ids is not None and r[\"instance_id\"] not in ids:\n continue\n out.append({\n \"instance_id\": r[\"instance_id\"], \"repo\": r[\"repo\"], \"base_commit\": r[\"base_commit\"],\n \"problem_statement\": r[\"problem_statement\"], \"patch\": r[\"patch\"], \"test_patch\": r[\"test_patch\"],\n \"FAIL_TO_PASS\": r[\"FAIL_TO_PASS\"], \"PASS_TO_PASS\": r[\"PASS_TO_PASS\"],\n \"version\": r.get(\"version\"), \"environment_setup_commit\": r.get(\"environment_setup_commit\"),\n })\n if ids is None and len(out) >= ${limit}:\n break\nprint(json.dumps(out))\n`\n const stdout = await runVenvPython(script, [opts.ids ? JSON.stringify(opts.ids) : ''])\n const rows = JSON.parse(stdout) as Array<Record<string, unknown>>\n return rows.map(\n (r): BenchTask => ({\n id: String(r.instance_id),\n split,\n prompt: [\n `Repository: ${r.repo} @ ${r.base_commit}`,\n '',\n `The repository is ALREADY cloned at ${SWE_REPO_DIR}, checked out at commit ${r.base_commit}. Work there directly (\\`cd ${SWE_REPO_DIR}\\`); do not re-clone.`,\n '',\n 'Resolve this issue by editing the repository SOURCE so the failing tests pass without breaking the passing ones. Do NOT edit test files — the evaluation runs hidden tests on a fresh checkout, so editing tests does not count. Keep the change minimal and confined to the cloned repo.',\n 'Work iteratively: reproduce the issue, implement the fix in the source, and re-run the relevant tests until they pass. You do NOT need to print the diff — the harness reads your committed edits directly from the repo.',\n '',\n '--- Issue ---',\n String(r.problem_statement ?? ''),\n ].join('\\n'),\n metadata: r,\n }),\n )\n },\n\n async goldArtifact(task: BenchTask) {\n const gold = task.metadata?.patch\n return typeof gold === 'string' ? gold : undefined\n },\n\n async judge(task: BenchTask, artifact: string): Promise<BenchScore> {\n const runId = safeRunId('bench', task.id)\n const capture = options.captureEvaluatorArtifacts?.({\n taskId: task.id,\n runId,\n attemptSequence: ++attemptSequence,\n })\n return runStagedJudge({\n tmpPrefix: 'swebench-',\n ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),\n ...(capture === undefined ? {} : { capture }),\n // Debug: retain the staged dir (holds swebench's per-instance apply/run\n // logs) for post-mortem when SWEBENCH_KEEP_TMP is set. Off by default.\n ...(process.env.SWEBENCH_KEEP_TMP ? { keepTmp: true } : {}),\n async stage(dir) {\n await stageFile(\n join(dir, 'preds.json'),\n JSON.stringify([\n { instance_id: task.id, model_name_or_path: 'agent-runtime-bench', model_patch: artifact },\n ]),\n )\n },\n // The official evaluation harness. Pulls/builds the instance image, applies\n // the patch, runs the test spec, writes a per-run report JSON in cwd.\n argv: (dir) => sweEvaluationArgv({\n predictionsPath: join(dir, 'preds.json'),\n runId,\n instanceId: task.id,\n cacheLevel,\n namespace: scorerNamespace(),\n }),\n async parseReport(dir) {\n // Report file: agent-runtime-bench.<run_id>.json\n const report = await readJsonReport<SweReport>(join(dir, `agent-runtime-bench.${runId}.json`))\n return scoreSweReport(task.id, report)\n },\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAS,YAAY;AAmBrB,IAAM,eAAe;AAWd,IAAM,iBAAwC;AAAA,EACnD,MAAM,QAAQ;AACZ,QAAI,OAAO;AACX,eAAW,MAAM,QAAQ;AACvB,YAAM,IAAK,IAA2C;AACtD,YAAM,IAAI,GAAG,aAAa,GAAG,QAAQ,GAAG;AACxC,UAAI,OAAO,MAAM,YAA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B,UAAuC;AAClE,YAAM,QAAQ,UAAU,SAAS,KAAK,EAAE;AACxC,YAAM,UAAU,QAAQ,4BAA4B;AAAA,QAClD,QAAQ,KAAK;AAAA,QACb;AAAA,QACA,iBAAiB,EAAE;AAAA,MACrB,CAAC;AACD,aAAO,eAAe;AAAA,QACpB,WAAW;AAAA,QACX,GAAI,QAAQ,cAAc,SAAY,CAAC,IAAI,EAAE,WAAW,QAAQ,UAAU;AAAA,QAC1E,GAAI,YAAY,SAAY,CAAC,IAAI,EAAE,QAAQ;AAAA;AAAA;AAAA,QAG3C,GAAI,QAAQ,IAAI,oBAAoB,EAAE,SAAS,KAAK,IAAI,CAAC;AAAA,QACzD,MAAM,MAAM,KAAK;AACf,gBAAM;AAAA,YACJ,KAAK,KAAK,YAAY;AAAA,YACtB,KAAK,UAAU;AAAA,cACb,EAAE,aAAa,KAAK,IAAI,oBAAoB,uBAAuB,aAAa,SAAS;AAAA,YAC3F,CAAC;AAAA,UACH;AAAA,QACF;AAAA;AAAA;AAAA,QAGA,MAAM,CAAC,QAAQ,kBAAkB;AAAA,UAC/B,iBAAiB,KAAK,KAAK,YAAY;AAAA,UACvC;AAAA,UACA,YAAY,KAAK;AAAA,UACjB;AAAA,UACA,WAAW,gBAAgB;AAAA,QAC7B,CAAC;AAAA,QACD,MAAM,YAAY,KAAK;AAErB,gBAAM,SAAS,MAAM,eAA0B,KAAK,KAAK,uBAAuB,KAAK,OAAO,CAAC;AAC7F,iBAAO,eAAe,KAAK,IAAI,MAAM;AAAA,QACvC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
package/dist/chunk-53UPUNBZ.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
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
|