@tangle-network/agent-bench 0.14.1 → 0.14.4
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 +16 -0
- package/package.json +6 -6
- package/scripts/verify-packed-consumer.mjs +0 -1
- package/src/atom-mcp-e2e.mts +14 -2
- package/src/coordination-mcp-container-reach.mts +5 -5
- package/src/gate.ts +1 -1
- package/src/mcp-mount-probe.mts +7 -5
- package/src/run-benchmarks.test.mts +0 -4
- package/src/search-bench/profiles.ts +1 -1
- package/src/tb-supervisor-sidecar.mts +1 -1
- package/tb_agents/opencode_supervisor_agent.py +2 -2
- package/src/browser/adapters/bad-design-audit.ts +0 -153
- package/src/browser/adapters/bad-design-audit.verify.ts +0 -85
- package/src/browser/adapters/bad.ts +0 -165
- package/src/browser/agent-adapter.ts +0 -145
- package/src/browser/process-adapter.ts +0 -146
- package/src/browser/run-to-spans.ts +0 -105
- package/src/browser/run-to-spans.verify.ts +0 -89
- package/src/browser/ui-reviewer.ts +0 -200
- package/src/browser/ui-reviewer.verify.ts +0 -94
- package/src/browser/verify.ts +0 -96
- package/src/clbench-codebase-gate.mts +0 -314
- package/src/clbench-context-gate.mts +0 -341
- package/src/commit0-env-run.mts +0 -62
- package/src/commit0-env.ts +0 -172
- package/src/commit0-gate.mts +0 -558
- package/src/egress-probe.mts +0 -26
- package/src/humaneval-repair-gate.mts +0 -182
- package/src/profile-coordinates.ts +0 -134
- package/src/run-benchmarks-report.ts +0 -66
- package/src/skill-sandbox-smoke.mts +0 -101
- package/src/supervisor-arena.mts +0 -825
- package/src/swe-emit-patch.mts +0 -125
- package/src/swe-local-proof.mts +0 -265
- package/src/swe-repro-calibrate.mts +0 -451
- package/src/swe-stream.mts +0 -1561
- package/src/trajectory-assemble.mjs +0 -130
- package/src/worker-browser.ts +0 -115
- package/src/worker-cad.ts +0 -470
- package/src/workspace-loop.mts +0 -133
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CL-bench (Context Learning) deployable-selector gate — Tencent/Fudan's CL-bench
|
|
3
|
-
* (arXiv:2602.03587) repurposed for our verifier-grounded selector question.
|
|
4
|
-
*
|
|
5
|
-
* CL-bench asks whether a model can learn NEW knowledge from in-context material
|
|
6
|
-
* (a rule book, a framework doc, a conversation) at inference time: each record is
|
|
7
|
-
* a `messages` conversation (system + context-laden turns, the final turn the task)
|
|
8
|
-
* graded against expert `rubrics`. The official metric is BINARY — a task is solved
|
|
9
|
-
* only if the response passes EVERY rubric (avg 63 rubrics/task). We keep that binary
|
|
10
|
-
* as `resolved`, but the per-rubric pass-count gives a CONTINUOUS score (fraction of
|
|
11
|
-
* rubrics satisfied) — the within-task graded variance a selector needs, which the
|
|
12
|
-
* deterministic-but-pass/fail benches (aec) lacked.
|
|
13
|
-
*
|
|
14
|
-
* The CHECKER is the benchmark's own rubric judge (an LLM, per CL-bench's eval.py),
|
|
15
|
-
* run by us at inference time — deployable, but NOT deterministic, so treat the judge
|
|
16
|
-
* as a noisy verifier: we rank by the rubric FRACTION (variance-reduced over many
|
|
17
|
-
* rubrics), not the binary, and the judge model + temperature are pinned for
|
|
18
|
-
* test-retest stability. This is the LLM-judge analogue of the HumanEval Docker gate;
|
|
19
|
-
* read a positive result as "a deployable rubric-fraction verifier captures selection
|
|
20
|
-
* value on a hard context-learning domain", scoped by judge noise.
|
|
21
|
-
*
|
|
22
|
-
* Router-only (no sandbox): worker + judge are both router chat calls. Two paired arms
|
|
23
|
-
* over the same tasks, each "shot" = one stateless completion of the final turn:
|
|
24
|
-
* random@K — K completions over the unmodified conversation
|
|
25
|
-
* diverse@K — K completions, the i-th with a strategy lens prepended to the system turn
|
|
26
|
-
* verifierGroundedSelect ranks the K shots by rubric fraction. Metrics are reported on
|
|
27
|
-
* BOTH the continuous fraction (the gate-relevant signal) and the official binary.
|
|
28
|
-
* Writes a corpus RunRecord/task (condition random@k) so `corpus-replay --selector` and
|
|
29
|
-
* `corpus-report` consume it unchanged. Fail loud.
|
|
30
|
-
*
|
|
31
|
-
* dotenvx run -f … -- env N=20 K=4 WORKER_MODEL=deepseek-chat JUDGE_MODEL=deepseek-chat \
|
|
32
|
-
* CORPUS=/tmp/clbench-ctx.jsonl tsx src/clbench-context-gate.mts
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
import { execFileSync } from 'node:child_process'
|
|
36
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
37
|
-
import { composeStrategies } from './directives'
|
|
38
|
-
import { type AttemptRecord, appendRunRecord, buildRunRecordFromAttempts } from './corpus'
|
|
39
|
-
import {
|
|
40
|
-
benchRouterProfile,
|
|
41
|
-
type BenchRouterTarget,
|
|
42
|
-
runBenchRouterTurn,
|
|
43
|
-
withBenchProfile,
|
|
44
|
-
} from './router-turn'
|
|
45
|
-
import { selfConsistencySelect, verifierGroundedSelect } from './selector'
|
|
46
|
-
import { type PairedLift, pairedLift, pool } from './stats.mts'
|
|
47
|
-
|
|
48
|
-
const datasetUrl = 'https://huggingface.co/datasets/tencent/CL-bench/resolve/main/CL-bench.jsonl'
|
|
49
|
-
|
|
50
|
-
function must(name: string): string {
|
|
51
|
-
const v = process.env[name]
|
|
52
|
-
if (!v) throw new Error(`env ${name} is required`)
|
|
53
|
-
return v
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface ChatMessage extends Readonly<Record<string, unknown>> {
|
|
57
|
-
role: string
|
|
58
|
-
content: string
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
interface CtxTask {
|
|
62
|
-
id: string
|
|
63
|
-
messages: ChatMessage[]
|
|
64
|
-
rubrics: string[]
|
|
65
|
-
category: string
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Fetch the first `count` lines of the (large, ~300MB) CL-bench JSONL via a piped
|
|
69
|
-
* `curl | head` so a smoke pulls only a few records, then slice [offset, offset+limit].
|
|
70
|
-
* A local cached file (CLBENCH_CTX_FILE) short-circuits the fetch for powered runs.
|
|
71
|
-
* Fail loud on a malformed record — a silently-short task set would poison the gate. */
|
|
72
|
-
function loadCtxTasks(limit: number, offset: number): CtxTask[] {
|
|
73
|
-
const need = offset + limit
|
|
74
|
-
// Fetch a 2-line buffer past `need`: on CL-bench's huge multi-KB records, `head`
|
|
75
|
-
// closing the pipe can emit a TRUNCATED final line (SIGPIPE mid-write) → invalid
|
|
76
|
-
// JSON. Fetching need+2 and parsing only the first `need` complete lines makes the
|
|
77
|
-
// truncated tail land in the discarded buffer.
|
|
78
|
-
const fetchN = need + 2
|
|
79
|
-
let raw: string
|
|
80
|
-
const cached = process.env.CLBENCH_CTX_FILE
|
|
81
|
-
if (cached) {
|
|
82
|
-
if (!existsSync(cached)) throw new Error(`CLBENCH_CTX_FILE not found: ${cached}`)
|
|
83
|
-
raw = execFileSync('bash', ['-c', `head -n ${fetchN} ${JSON.stringify(cached)}`], { maxBuffer: 1 << 30 }).toString('utf8')
|
|
84
|
-
} else {
|
|
85
|
-
// -fsSL: fail on HTTP error, follow redirects (HF resolve 302s to the CDN). curl's
|
|
86
|
-
// SIGPIPE (exit 23) when head closes is benign — suppress its stderr; a real fetch
|
|
87
|
-
// failure surfaces as 0 parsed tasks below.
|
|
88
|
-
raw = execFileSync('bash', ['-c', `curl -fsSL ${JSON.stringify(datasetUrl)} 2>/dev/null | head -n ${fetchN}`], {
|
|
89
|
-
maxBuffer: 1 << 30,
|
|
90
|
-
}).toString('utf8')
|
|
91
|
-
}
|
|
92
|
-
const tasks: CtxTask[] = []
|
|
93
|
-
// Only the first `need` lines are guaranteed complete (the +2 absorbs head's tail).
|
|
94
|
-
const lines = raw.split('\n').filter((l) => l.trim() !== '').slice(0, need)
|
|
95
|
-
for (const line of lines) {
|
|
96
|
-
const d = JSON.parse(line) as {
|
|
97
|
-
messages?: ChatMessage[]
|
|
98
|
-
rubrics?: unknown[]
|
|
99
|
-
metadata?: { task_id?: string; context_category?: string }
|
|
100
|
-
}
|
|
101
|
-
const messages = d.messages
|
|
102
|
-
const taskId = d.metadata?.task_id
|
|
103
|
-
if (!Array.isArray(messages) || messages.length === 0 || !taskId) {
|
|
104
|
-
throw new Error(`malformed CL-bench record: ${line.slice(0, 120)}`)
|
|
105
|
-
}
|
|
106
|
-
// Rubrics are strings or {rubric_criteria} objects (mirrors eval.py's build_rubrics_text).
|
|
107
|
-
const rubrics = (d.rubrics ?? []).map((r) =>
|
|
108
|
-
typeof r === 'string' ? r : String((r as { rubric_criteria?: string }).rubric_criteria ?? '').trim(),
|
|
109
|
-
).filter((r) => r.length > 0)
|
|
110
|
-
if (rubrics.length === 0) throw new Error(`CL-bench record ${taskId} has no rubrics`)
|
|
111
|
-
tasks.push({ id: taskId, messages, rubrics, category: d.metadata?.context_category ?? 'Unknown' })
|
|
112
|
-
}
|
|
113
|
-
if (tasks.length === 0) throw new Error('CL-bench parsed to 0 tasks')
|
|
114
|
-
if (offset >= tasks.length) throw new Error(`OFFSET ${offset} >= fetched size ${tasks.length}`)
|
|
115
|
-
return tasks.slice(offset, offset + limit)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Apply a diversity strategy lens to a conversation by prepending it to the system
|
|
119
|
-
* turn (or, if none, inserting a system turn). The non-system context turns — which
|
|
120
|
-
* carry the in-context knowledge the task is about — are never mutated. */
|
|
121
|
-
function diversifyMessages(messages: ChatMessage[], lensSystem: string, baseSystem: string): ChatMessage[] {
|
|
122
|
-
if (messages[0]?.role === 'system') {
|
|
123
|
-
return [{ role: 'system', content: lensSystem }, ...messages.slice(1)]
|
|
124
|
-
}
|
|
125
|
-
return [{ role: 'system', content: composeStrategies(baseSystem, 1)[0] as string }, ...messages]
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const judgePrompt = (rubricsText: string, modelOutput: string): string =>
|
|
129
|
-
'You are a rigorous, strict grading teacher. Grade the student response against the 【Rubrics】, ' +
|
|
130
|
-
'checking EACH requirement independently.\n\n' +
|
|
131
|
-
`【Rubrics】:\n${rubricsText}\n` +
|
|
132
|
-
`【Student Response】:\n${modelOutput}\n\n` +
|
|
133
|
-
'Output ONLY this JSON (no other text):\n' +
|
|
134
|
-
'{\n "status": ["yes" or "no", ... one per rubric, in order],\n "all_pass": 0 or 1\n}\n'
|
|
135
|
-
|
|
136
|
-
interface RubricVerdict {
|
|
137
|
-
/** fraction of rubrics satisfied (0..1) — the continuous within-task signal. */
|
|
138
|
-
fraction: number
|
|
139
|
-
/** official binary: every rubric satisfied. */
|
|
140
|
-
allPass: boolean
|
|
141
|
-
/** rubric count actually graded (for diagnostics). */
|
|
142
|
-
graded: number
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function parseJudge(reply: string, rubricCount: number): RubricVerdict {
|
|
146
|
-
let text = reply.trim()
|
|
147
|
-
if (text.startsWith('```json')) text = text.slice(7)
|
|
148
|
-
if (text.startsWith('```')) text = text.slice(3)
|
|
149
|
-
if (text.endsWith('```')) text = text.slice(0, -3)
|
|
150
|
-
const obj = JSON.parse(text.trim()) as { status?: unknown[]; all_pass?: unknown }
|
|
151
|
-
const status = Array.isArray(obj.status) ? obj.status : []
|
|
152
|
-
const yes = status.filter((s) => String(s).trim().toLowerCase() === 'yes').length
|
|
153
|
-
const graded = status.length > 0 ? status.length : rubricCount
|
|
154
|
-
const fraction = graded > 0 ? yes / graded : 0
|
|
155
|
-
// Trust an explicit all_pass when given; else derive from the per-rubric list.
|
|
156
|
-
const allPass = obj.all_pass === 1 || obj.all_pass === '1' || (status.length === rubricCount && yes === rubricCount && rubricCount > 0)
|
|
157
|
-
return { fraction, allPass, graded }
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Grade one completion with the rubric judge. A judge API/parse failure is a real
|
|
161
|
-
* zero (the response could not be validated) — surfaced, never masked. */
|
|
162
|
-
async function judgeRubrics(cfg: BenchRouterTarget, task: CtxTask, output: string): Promise<RubricVerdict> {
|
|
163
|
-
if (!output.trim()) return { fraction: 0, allPass: false, graded: 0 }
|
|
164
|
-
const rubricsText = task.rubrics.map((r, i) => `${i + 1}. ${r}`).join('\n')
|
|
165
|
-
// Fault-isolate the judge: a transient router failure (after retries) or an
|
|
166
|
-
// unparseable judge reply scores this attempt 0 (eval.py's convention), it must
|
|
167
|
-
// NOT throw — one bad grade would otherwise crash the whole N×K×2 run. graded=0
|
|
168
|
-
// marks it as judge-failed so it's distinguishable from a real 0/N rubric pass.
|
|
169
|
-
try {
|
|
170
|
-
const res = await runBenchRouterTurn(
|
|
171
|
-
{
|
|
172
|
-
routerBaseUrl: cfg.routerBaseUrl,
|
|
173
|
-
routerKey: cfg.routerKey,
|
|
174
|
-
profile: withBenchProfile(cfg.profile, {
|
|
175
|
-
name: 'clbench-rubric-judge',
|
|
176
|
-
temperature: 0,
|
|
177
|
-
}),
|
|
178
|
-
},
|
|
179
|
-
judgePrompt(rubricsText, output),
|
|
180
|
-
)
|
|
181
|
-
return parseJudge(res.finalText, task.rubrics.length)
|
|
182
|
-
} catch {
|
|
183
|
-
return { fraction: 0, allPass: false, graded: 0 }
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const pct = (x: number) => `${(x * 100).toFixed(1)}%`
|
|
188
|
-
const pp = (x: number) => `${x >= 0 ? '+' : ''}${(x * 100).toFixed(1)}pp`
|
|
189
|
-
|
|
190
|
-
interface Shot {
|
|
191
|
-
output: string
|
|
192
|
-
verdict: RubricVerdict
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async function main(): Promise<void> {
|
|
196
|
-
const n = Number(process.env.N ?? 20)
|
|
197
|
-
const k = Number(process.env.K ?? 4)
|
|
198
|
-
const offset = Number(process.env.OFFSET ?? 0)
|
|
199
|
-
const model = process.env.WORKER_MODEL ?? 'deepseek-chat'
|
|
200
|
-
const judgeModel = process.env.JUDGE_MODEL ?? model
|
|
201
|
-
const routerBaseUrl = process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1'
|
|
202
|
-
const routerKey = must('TANGLE_API_KEY')
|
|
203
|
-
const solveConcurrency = Number(process.env.CONCURRENCY ?? 6)
|
|
204
|
-
const corpusPath = process.env.CORPUS ?? '/tmp/clbench-ctx.jsonl'
|
|
205
|
-
if (!Number.isInteger(n) || n < 1) throw new Error(`N must be a positive integer, got ${process.env.N}`)
|
|
206
|
-
if (!Number.isInteger(k) || k < 1) throw new Error(`K must be a positive integer, got ${process.env.K}`)
|
|
207
|
-
|
|
208
|
-
const workerCfg: BenchRouterTarget = {
|
|
209
|
-
routerBaseUrl,
|
|
210
|
-
routerKey,
|
|
211
|
-
profile: benchRouterProfile('clbench-context-worker', model, {
|
|
212
|
-
temperature: Number(process.env.TEMPERATURE ?? '0.8'),
|
|
213
|
-
}),
|
|
214
|
-
}
|
|
215
|
-
const judgeCfg: BenchRouterTarget = {
|
|
216
|
-
routerBaseUrl,
|
|
217
|
-
routerKey,
|
|
218
|
-
profile: benchRouterProfile('clbench-rubric-judge', judgeModel, { temperature: 0 }),
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
console.log(`=== CL-bench (Context Learning) selector gate · N=${n} K=${k} offset=${offset} ===`)
|
|
222
|
-
console.log(` worker=${model} judge=${judgeModel} (rubric-fraction verifier) router=${routerBaseUrl}`)
|
|
223
|
-
console.log(' regime: STATELESS single completions — selector no-self-correction LOWER BOUND, judge is an LLM (noisy verifier)')
|
|
224
|
-
|
|
225
|
-
const tasks = loadCtxTasks(n, offset)
|
|
226
|
-
console.log(`loaded ${tasks.length} task(s); rubrics/task: ${tasks.map((t) => t.rubrics.length).join(',')}`)
|
|
227
|
-
|
|
228
|
-
type Unit = { taskIdx: number; arm: 'random' | 'diverse'; shot: number; messages: ChatMessage[] }
|
|
229
|
-
const units: Unit[] = []
|
|
230
|
-
for (let ti = 0; ti < tasks.length; ti += 1) {
|
|
231
|
-
const task = tasks[ti] as CtxTask
|
|
232
|
-
const baseSystem = task.messages[0]?.role === 'system' ? (task.messages[0] as ChatMessage).content : 'You are a helpful assistant.'
|
|
233
|
-
const lenses = composeStrategies(baseSystem, k)
|
|
234
|
-
for (let s = 0; s < k; s += 1) {
|
|
235
|
-
units.push({ taskIdx: ti, arm: 'random', shot: s, messages: task.messages })
|
|
236
|
-
units.push({ taskIdx: ti, arm: 'diverse', shot: s, messages: diversifyMessages(task.messages, lenses[s] as string, baseSystem) })
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
console.log(`\n▶ solving ${units.length} attempts (${tasks.length} tasks × ${k} shots × 2 arms) via router, conc=${solveConcurrency}`)
|
|
240
|
-
const outputs = await pool(units, solveConcurrency, async (u) => {
|
|
241
|
-
const system = u.messages.find((message) => message.role === 'system')?.content
|
|
242
|
-
const res = await runBenchRouterTurn(
|
|
243
|
-
{
|
|
244
|
-
routerBaseUrl: workerCfg.routerBaseUrl,
|
|
245
|
-
routerKey: workerCfg.routerKey,
|
|
246
|
-
profile: withBenchProfile(workerCfg.profile, {
|
|
247
|
-
name: 'clbench-context-worker',
|
|
248
|
-
...(system ? { systemPrompt: system } : {}),
|
|
249
|
-
}),
|
|
250
|
-
},
|
|
251
|
-
{ messages: u.messages.filter((message) => message.role !== 'system') },
|
|
252
|
-
)
|
|
253
|
-
return res.finalText
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
console.log(`▶ grading ${outputs.length} completions with the rubric judge (${judgeModel}), conc=${solveConcurrency}`)
|
|
257
|
-
const verdicts = await pool(units, solveConcurrency, (u, i) => judgeRubrics(judgeCfg, tasks[u.taskIdx] as CtxTask, outputs[i] as string))
|
|
258
|
-
|
|
259
|
-
// Regroup into per-task arms, shot order preserved.
|
|
260
|
-
const byTask = tasks.map(() => ({ random: [] as Shot[], diverse: [] as Shot[] }))
|
|
261
|
-
units.forEach((u, i) => {
|
|
262
|
-
const shot: Shot = { output: outputs[i] as string, verdict: verdicts[i] as RubricVerdict }
|
|
263
|
-
const grp = byTask[u.taskIdx] as { random: Shot[]; diverse: Shot[] }
|
|
264
|
-
if (u.arm === 'random') grp.random[u.shot] = shot
|
|
265
|
-
else grp.diverse[u.shot] = shot
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
// Per-task aligned metrics, on BOTH the continuous fraction and the official binary.
|
|
269
|
-
const fr = { blind: [] as number[], random: [] as number[], diverse: [] as number[], oracle: [] as number[], sc: [] as number[] }
|
|
270
|
-
const bin = { blind: [] as number[], random: [] as number[], diverse: [] as number[], oracle: [] as number[] }
|
|
271
|
-
for (const grp of byTask) {
|
|
272
|
-
const rFr = grp.random.map((s) => s.verdict.fraction)
|
|
273
|
-
const dFr = grp.diverse.map((s) => s.verdict.fraction)
|
|
274
|
-
const rIdx = verifierGroundedSelect(rFr) // rank random shots by rubric fraction
|
|
275
|
-
const dIdx = verifierGroundedSelect(dFr)
|
|
276
|
-
const scIdx = selfConsistencySelect(grp.diverse.map((s) => s.output))
|
|
277
|
-
fr.blind.push((grp.random[0] as Shot).verdict.fraction)
|
|
278
|
-
fr.random.push((grp.random[rIdx] as Shot).verdict.fraction)
|
|
279
|
-
fr.diverse.push((grp.diverse[dIdx] as Shot).verdict.fraction)
|
|
280
|
-
fr.oracle.push(Math.max(...dFr))
|
|
281
|
-
fr.sc.push((grp.diverse[scIdx] as Shot).verdict.fraction)
|
|
282
|
-
bin.blind.push((grp.random[0] as Shot).verdict.allPass ? 1 : 0)
|
|
283
|
-
bin.random.push((grp.random[rIdx] as Shot).verdict.allPass ? 1 : 0)
|
|
284
|
-
bin.diverse.push((grp.diverse[dIdx] as Shot).verdict.allPass ? 1 : 0)
|
|
285
|
-
bin.oracle.push(dFr.some((_, j) => (grp.diverse[j] as Shot).verdict.allPass) ? 1 : 0)
|
|
286
|
-
}
|
|
287
|
-
const rate = (xs: number[]) => xs.reduce((s, x) => s + x, 0) / xs.length
|
|
288
|
-
|
|
289
|
-
console.log(`\n${'='.repeat(78)}`)
|
|
290
|
-
console.log(`RESULTS · CL-bench Context Learning · n=${tasks.length} · k=${k} · worker=${model} · judge=${judgeModel}`)
|
|
291
|
-
console.log('='.repeat(78))
|
|
292
|
-
console.log(' — rubric FRACTION (continuous within-task signal, the gate-relevant metric) —')
|
|
293
|
-
console.log(` blind (shot 0) ${pct(rate(fr.blind))}`)
|
|
294
|
-
console.log(` random@k (verifier-pick) ${pct(rate(fr.random))}`)
|
|
295
|
-
console.log(` diverse@k (verifier-pick) ${pct(rate(fr.diverse))}`)
|
|
296
|
-
console.log(` oracle@k (max fraction) ${pct(rate(fr.oracle))}`)
|
|
297
|
-
console.log(` self-consistency@k ${pct(rate(fr.sc))}`)
|
|
298
|
-
console.log(' — official BINARY all-rubrics-pass (solving rate) —')
|
|
299
|
-
console.log(` blind ${pct(rate(bin.blind))} random@k ${pct(rate(bin.random))} diverse@k ${pct(rate(bin.diverse))} oracle@k ${pct(rate(bin.oracle))}`)
|
|
300
|
-
|
|
301
|
-
const row = (label: string, l: PairedLift) =>
|
|
302
|
-
console.log(` ${label.padEnd(36)} ${pp(l.point).padStart(7)} CI [${pp(l.low)}, ${pp(l.high)}] (paired ${l.pairs}, discordant ${l.discordant})`)
|
|
303
|
-
console.log(`\n PAIRED LIFTS on rubric fraction (95% bootstrap CI, B=10000):`)
|
|
304
|
-
row('random@k − blind (compute)', pairedLift(fr.blind, fr.random))
|
|
305
|
-
row('diverse@k − random@k (verifier)', pairedLift(fr.random, fr.diverse))
|
|
306
|
-
row('diverse@k − blind (total)', pairedLift(fr.blind, fr.diverse))
|
|
307
|
-
row('verifier-pick − sc-pick (diverse)', pairedLift(fr.sc, fr.diverse))
|
|
308
|
-
const ceiling = pairedLift(fr.random, fr.oracle)
|
|
309
|
-
row('oracle@k − random@k (ceiling)', ceiling)
|
|
310
|
-
|
|
311
|
-
// Corpus: one RunRecord/task for the random@k arm, ranked by the rubric-fraction
|
|
312
|
-
// verifier — `corpus-replay --selector=verifier` + `corpus-report` consume it.
|
|
313
|
-
for (let ti = 0; ti < tasks.length; ti += 1) {
|
|
314
|
-
const task = tasks[ti] as CtxTask
|
|
315
|
-
const grp = byTask[ti] as { random: Shot[]; diverse: Shot[] }
|
|
316
|
-
const attempts: AttemptRecord[] = grp.random.map((s, round) => ({
|
|
317
|
-
round,
|
|
318
|
-
prompt: 'clbench-context',
|
|
319
|
-
output: s.output.slice(0, 4000),
|
|
320
|
-
valid: s.verdict.allPass,
|
|
321
|
-
score: s.verdict.fraction,
|
|
322
|
-
eventCount: 1,
|
|
323
|
-
eventTypes: { 'router.chat': 1 },
|
|
324
|
-
traceTail: s.output.slice(-600),
|
|
325
|
-
}))
|
|
326
|
-
const record = buildRunRecordFromAttempts(attempts, {
|
|
327
|
-
benchmark: 'clbench-context',
|
|
328
|
-
instanceId: task.id,
|
|
329
|
-
condition: `random@${k}`,
|
|
330
|
-
model,
|
|
331
|
-
infraError: false,
|
|
332
|
-
})
|
|
333
|
-
await appendRunRecord(corpusPath, record)
|
|
334
|
-
}
|
|
335
|
-
console.log(`\n=== wrote ${tasks.length} task(s) → ${corpusPath} · gate: tsx src/corpus-replay.mts ${corpusPath} --selector=verifier ===`)
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
main().catch((err) => {
|
|
339
|
-
console.error(`clbench-context-gate: ${err instanceof Error ? err.message : String(err)}`)
|
|
340
|
-
process.exit(1)
|
|
341
|
-
})
|
package/src/commit0-env-run.mts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The HARD test: sample-vs-refine on Commit0 (implement entire stubbed Python libraries
|
|
3
|
-
* against their own test suites), through the PUBLISHED suite — runBenchmark over a
|
|
4
|
-
* Commit0 Environment (local Docker workspace, file tools, pytest as the check).
|
|
5
|
-
*
|
|
6
|
-
* COMMIT0_FIXTURES=1 N=3 BUDGET=3 INNER_TURNS=10 WORKER_MODEL=deepseek-v4-pro \
|
|
7
|
-
* tsx src/commit0-env-run.mts
|
|
8
|
-
*
|
|
9
|
-
* IDS=commit-0/wcwidth to pick repos; STRATEGIES=sample,refine,adaptiveRefine to choose arms.
|
|
10
|
-
*/
|
|
11
|
-
import { readFileSync } from 'node:fs'
|
|
12
|
-
import { join } from 'node:path'
|
|
13
|
-
import { adaptiveRefine, printBenchmarkReport, refine, runBenchmark, sample, type Strategy } from '@tangle-network/agent-runtime/kernel'
|
|
14
|
-
import { type Commit0Row, createCommit0Environment, rowToTask } from './commit0-env'
|
|
15
|
-
import { benchRouterProfile } from './router-turn'
|
|
16
|
-
|
|
17
|
-
function must(name: string): string {
|
|
18
|
-
const v = process.env[name]
|
|
19
|
-
if (!v) throw new Error(`env ${name} is required`)
|
|
20
|
-
return v
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function main(): Promise<void> {
|
|
24
|
-
const n = Number(process.env.N ?? 2)
|
|
25
|
-
const budget = Number(process.env.BUDGET ?? 3)
|
|
26
|
-
const model = process.env.WORKER_MODEL ?? 'deepseek-v4-pro'
|
|
27
|
-
const rows = (JSON.parse(readFileSync(join(import.meta.dirname, '..', 'fixtures', 'commit0.json'), 'utf8')) as Commit0Row[]).filter(
|
|
28
|
-
(r) => !process.env.IDS || process.env.IDS.split(',').includes(r.instance_id),
|
|
29
|
-
)
|
|
30
|
-
const picked = rows.slice(0, n)
|
|
31
|
-
const byName: Record<string, Strategy> = { sample, refine, adaptiveRefine }
|
|
32
|
-
const strategies = (process.env.STRATEGIES ?? 'sample,refine').split(',').map((s) => {
|
|
33
|
-
const st = byName[s.trim()]
|
|
34
|
-
if (!st) throw new Error(`unknown strategy ${s}`)
|
|
35
|
-
return st
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
console.error(`=== commit0 (HARD) · ${picked.map((r) => r.instance_id).join(', ')} · ${model} · budget=${budget} · [${strategies.map((s) => s.name).join(' vs ')}] ===\n`)
|
|
39
|
-
const environment = createCommit0Environment(picked)
|
|
40
|
-
const report = await runBenchmark({
|
|
41
|
-
environment,
|
|
42
|
-
tasks: picked.map(rowToTask),
|
|
43
|
-
worker: {
|
|
44
|
-
routerBaseUrl: process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1',
|
|
45
|
-
routerKey: must('TANGLE_API_KEY'),
|
|
46
|
-
workerProfile: benchRouterProfile('commit0-worker', model, {
|
|
47
|
-
systemPrompt: 'You are a senior Python engineer. Work through the available tools until the task is verified complete.',
|
|
48
|
-
maxTurns: Number(process.env.INNER_TURNS ?? 10),
|
|
49
|
-
temperature: 0.4,
|
|
50
|
-
}),
|
|
51
|
-
},
|
|
52
|
-
strategies,
|
|
53
|
-
budget,
|
|
54
|
-
concurrency: Number(process.env.CONCURRENCY ?? 1),
|
|
55
|
-
})
|
|
56
|
-
printBenchmarkReport(report)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
main().catch((e) => {
|
|
60
|
-
console.error(`commit0-env-run: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}`)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
})
|
package/src/commit0-env.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Commit0 as an `Environment` — the HARD test (docs/research/long-horizon-benchmark-survey.md:
|
|
3
|
-
* the survey's top pick, graded + natively multi-stage). The agent implements an entire
|
|
4
|
-
* stubbed Python library so its existing test suite passes.
|
|
5
|
-
*
|
|
6
|
-
* Off-box construction (routes around the sandbox platform exactly like the EOPS gym):
|
|
7
|
-
* open() — clone the stub repo at base_commit into a tmpdir, start a PERSISTENT
|
|
8
|
-
* python:<ver>-slim container with the workspace mounted, `pip install -e .`
|
|
9
|
-
* + pytest once. The container is the artifact; it carries across shots.
|
|
10
|
-
* tools() — list_files / read_file / write_file / run_tests. The worker EDITS SOURCE
|
|
11
|
-
* VIA TOOLS (no diff emission). write_file is path-jailed and refuses the
|
|
12
|
-
* test dir — the agent cannot edit the check.
|
|
13
|
-
* score() — the repo's OWN pytest suite (passed/total), parsed from a quiet run inside
|
|
14
|
-
* the container. Deterministic, deployable. (The official commit0 harness can
|
|
15
|
-
* re-validate a winner from `git diff` later; it is not in the loop.)
|
|
16
|
-
* close() — kill the container, remove the tmpdir.
|
|
17
|
-
*/
|
|
18
|
-
import { execFile } from 'node:child_process'
|
|
19
|
-
import { mkdtempSync, rmSync } from 'node:fs'
|
|
20
|
-
import { tmpdir } from 'node:os'
|
|
21
|
-
import { join } from 'node:path'
|
|
22
|
-
import { promisify } from 'node:util'
|
|
23
|
-
import type { AgenticSurface, AgenticTask, AgenticTool, ArtifactHandle, SurfaceScore } from '@tangle-network/agent-runtime/kernel'
|
|
24
|
-
|
|
25
|
-
const exec = promisify(execFile)
|
|
26
|
-
|
|
27
|
-
export interface Commit0Row {
|
|
28
|
-
instance_id: string
|
|
29
|
-
repo: string
|
|
30
|
-
base_commit: string
|
|
31
|
-
setup: { install: string; pre_install?: string[] | null; python: string; specification?: string }
|
|
32
|
-
src_dir: string
|
|
33
|
-
test: { test_cmd: string; test_dir: string }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface Ws {
|
|
37
|
-
dir: string
|
|
38
|
-
container: string
|
|
39
|
-
row: Commit0Row
|
|
40
|
-
}
|
|
41
|
-
const workspaces = new Map<string, Ws>()
|
|
42
|
-
|
|
43
|
-
async function dockerExec(container: string, cmd: string, timeoutMs = 180_000): Promise<{ out: string; code: number }> {
|
|
44
|
-
try {
|
|
45
|
-
const r = await exec('docker', ['exec', container, 'bash', '-lc', cmd], { timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024 })
|
|
46
|
-
return { out: `${r.stdout}\n${r.stderr}`.trim(), code: 0 }
|
|
47
|
-
} catch (e) {
|
|
48
|
-
const err = e as { stdout?: string; stderr?: string; code?: number }
|
|
49
|
-
return { out: `${err.stdout ?? ''}\n${err.stderr ?? ''}`.trim(), code: typeof err.code === 'number' ? err.code : 1 }
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Parse pytest's summary tail ("X passed", "Y failed", "Z errors") into counts. */
|
|
54
|
-
function parsePytest(out: string): { passed: number; failed: number } {
|
|
55
|
-
const grab = (re: RegExp) => {
|
|
56
|
-
const m = out.match(re)
|
|
57
|
-
return m ? Number(m[1]) : 0
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
passed: grab(/(\d+) passed/),
|
|
61
|
-
failed: grab(/(\d+) failed/) + grab(/(\d+) error/),
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function rowToTask(row: Commit0Row): AgenticTask {
|
|
66
|
-
return {
|
|
67
|
-
id: row.instance_id,
|
|
68
|
-
userPrompt:
|
|
69
|
-
'You are a senior Python engineer implementing a stubbed library so its existing test suite passes. ' +
|
|
70
|
-
'Workflow: list_files and read the tests + stubs to learn the required behavior, write COMPLETE implementations ' +
|
|
71
|
-
`with write_file (source under ${row.src_dir} only — the test dir is read-only), then run_tests and fix failures. ` +
|
|
72
|
-
'Iterate until the suite passes. Reply DONE only when run_tests shows no failures.\n\n' +
|
|
73
|
-
`Implement the stubbed library "${row.repo}". The public functions/classes under \`${row.src_dir}\` have empty bodies. ` +
|
|
74
|
-
`Make the existing tests under \`${row.test.test_dir}\` pass.${row.setup.specification ? ` Spec: ${row.setup.specification}` : ''}`,
|
|
75
|
-
meta: { instanceId: row.instance_id },
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function createCommit0Environment(rows: Commit0Row[]): AgenticSurface {
|
|
80
|
-
const byId = new Map(rows.map((r) => [r.instance_id, r]))
|
|
81
|
-
return {
|
|
82
|
-
name: 'commit0',
|
|
83
|
-
async open(task) {
|
|
84
|
-
const row = byId.get(task.id)
|
|
85
|
-
if (!row) throw new Error(`commit0-env: unknown task ${task.id}`)
|
|
86
|
-
const dir = mkdtempSync(join(tmpdir(), 'c0-'))
|
|
87
|
-
await exec('git', ['clone', '--quiet', `https://github.com/${row.repo}.git`, dir], { timeout: 120_000 })
|
|
88
|
-
await exec('git', ['-C', dir, 'checkout', '--quiet', row.base_commit], { timeout: 60_000 })
|
|
89
|
-
const container = `c0-${task.id.replace(/[^a-z0-9]/gi, '-')}-${Math.random().toString(36).slice(2, 8)}`
|
|
90
|
-
await exec('docker', ['run', '-d', '--name', container, '--cpus=2', '--memory=2g', '-v', `${dir}:/w`, '-w', '/w', `python:${row.setup.python}-slim`, 'sleep', 'infinity'], { timeout: 120_000 })
|
|
91
|
-
for (const pre of row.setup.pre_install ?? []) await dockerExec(container, pre, 300_000)
|
|
92
|
-
const setup = await dockerExec(container, `${row.setup.install} && pip install -q pytest`, 600_000)
|
|
93
|
-
if (setup.code !== 0) {
|
|
94
|
-
await dockerExec(container, 'find /w -mindepth 1 -delete', 60_000).catch(() => {})
|
|
95
|
-
await exec('docker', ['rm', '-f', container]).catch(() => {})
|
|
96
|
-
rmSync(dir, { recursive: true, force: true })
|
|
97
|
-
throw new Error(`commit0-env setup failed for ${task.id}: ${setup.out.slice(-300)}`)
|
|
98
|
-
}
|
|
99
|
-
const handle: ArtifactHandle = { id: container, surface: 'commit0' }
|
|
100
|
-
workspaces.set(container, { dir, container, row })
|
|
101
|
-
return handle
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
async tools(task) {
|
|
105
|
-
const row = byId.get(task.id)
|
|
106
|
-
const src = row?.src_dir ?? 'src/'
|
|
107
|
-
const tests = row?.test.test_dir ?? 'tests/'
|
|
108
|
-
return [
|
|
109
|
-
{ type: 'function', function: { name: 'list_files', description: `List the repo's source (${src}) and test (${tests}) files.`, parameters: { type: 'object', properties: {} } } },
|
|
110
|
-
{ type: 'function', function: { name: 'read_file', description: 'Read a file from the repo (bounded).', parameters: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'] } } },
|
|
111
|
-
{ type: 'function', function: { name: 'write_file', description: `Write COMPLETE file contents (source under ${src} only; the test dir is read-only).`, parameters: { type: 'object', properties: { path: { type: 'string' }, content: { type: 'string' } }, required: ['path', 'content'] } } },
|
|
112
|
-
{ type: 'function', function: { name: 'run_tests', description: 'Run the existing test suite; returns the pytest summary + failure tails.', parameters: { type: 'object', properties: {} } } },
|
|
113
|
-
] satisfies AgenticTool[]
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
async call(handle, name, args) {
|
|
117
|
-
const ws = workspaces.get(handle.id)
|
|
118
|
-
if (!ws) return 'ERROR: workspace closed'
|
|
119
|
-
const jail = (p: string): string | null => {
|
|
120
|
-
const norm = p.replace(/^\.?\//, '')
|
|
121
|
-
if (norm.includes('..') || norm.startsWith('/')) return null
|
|
122
|
-
return norm
|
|
123
|
-
}
|
|
124
|
-
if (name === 'list_files') {
|
|
125
|
-
const r = await dockerExec(ws.container, `find ${ws.row.src_dir} ${ws.row.test.test_dir} -name '*.py' | head -80`, 30_000)
|
|
126
|
-
return r.out.slice(0, 2000)
|
|
127
|
-
}
|
|
128
|
-
if (name === 'read_file') {
|
|
129
|
-
const p = jail(String(args.path ?? ''))
|
|
130
|
-
if (!p) return 'ERROR: invalid path'
|
|
131
|
-
const r = await dockerExec(ws.container, `cat ${JSON.stringify(p)}`, 30_000)
|
|
132
|
-
return r.code === 0 ? r.out.slice(0, 8000) : `ERROR: ${r.out.slice(0, 200)}`
|
|
133
|
-
}
|
|
134
|
-
if (name === 'write_file') {
|
|
135
|
-
const p = jail(String(args.path ?? ''))
|
|
136
|
-
if (!p) return 'ERROR: invalid path'
|
|
137
|
-
if (p.startsWith(ws.row.test.test_dir.replace(/^\.?\//, ''))) return 'ERROR: the test dir is read-only — implement the source, not the tests'
|
|
138
|
-
const content = String(args.content ?? '')
|
|
139
|
-
const b64 = Buffer.from(content, 'utf8').toString('base64')
|
|
140
|
-
const r = await dockerExec(ws.container, `mkdir -p $(dirname ${JSON.stringify(p)}) && echo '${b64}' | base64 -d > ${JSON.stringify(p)}`, 30_000)
|
|
141
|
-
return r.code === 0 ? `wrote ${p} (${content.length} chars)` : `ERROR: ${r.out.slice(0, 200)}`
|
|
142
|
-
}
|
|
143
|
-
if (name === 'run_tests') {
|
|
144
|
-
// `-o addopts=` neutralizes repo-configured pytest plugins (e.g. wcwidth's tox.ini
|
|
145
|
-
// demands pytest-cov) that aren't installed and would usage-error before any test runs.
|
|
146
|
-
const r = await dockerExec(ws.container, `${ws.row.test.test_cmd} ${ws.row.test.test_dir} -q --tb=line -p no:cacheprovider -o addopts= 2>&1 | tail -30`, 240_000)
|
|
147
|
-
return r.out.slice(0, 2500)
|
|
148
|
-
}
|
|
149
|
-
return `ERROR: unknown tool ${name}`
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
async score(_task, handle) {
|
|
153
|
-
const ws = workspaces.get(handle.id)
|
|
154
|
-
if (!ws) return { passes: 0, total: 0, errored: 1 }
|
|
155
|
-
const r = await dockerExec(ws.container, `${ws.row.test.test_cmd} ${ws.row.test.test_dir} -q --tb=no -p no:cacheprovider -o addopts= 2>&1 | tail -5`, 240_000)
|
|
156
|
-
const { passed, failed } = parsePytest(r.out)
|
|
157
|
-
const total = passed + failed
|
|
158
|
-
return total > 0 ? { passes: passed, total, errored: 0 } : { passes: 0, total: 0, errored: 1 }
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
async close(handle) {
|
|
162
|
-
const ws = workspaces.get(handle.id)
|
|
163
|
-
if (!ws) return
|
|
164
|
-
workspaces.delete(handle.id)
|
|
165
|
-
// The container ran as root, so its writes on the bind mount are root-owned and the
|
|
166
|
-
// host rmSync would EACCES — wipe the mount from INSIDE the container first.
|
|
167
|
-
await dockerExec(ws.container, 'find /w -mindepth 1 -delete', 60_000).catch(() => {})
|
|
168
|
-
await exec('docker', ['rm', '-f', ws.container]).catch(() => {})
|
|
169
|
-
rmSync(ws.dir, { recursive: true, force: true })
|
|
170
|
-
},
|
|
171
|
-
}
|
|
172
|
-
}
|