@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +6 -6
  3. package/scripts/verify-packed-consumer.mjs +0 -1
  4. package/src/atom-mcp-e2e.mts +14 -2
  5. package/src/coordination-mcp-container-reach.mts +5 -5
  6. package/src/gate.ts +1 -1
  7. package/src/mcp-mount-probe.mts +7 -5
  8. package/src/run-benchmarks.test.mts +0 -4
  9. package/src/search-bench/profiles.ts +1 -1
  10. package/src/tb-supervisor-sidecar.mts +1 -1
  11. package/tb_agents/opencode_supervisor_agent.py +2 -2
  12. package/src/browser/adapters/bad-design-audit.ts +0 -153
  13. package/src/browser/adapters/bad-design-audit.verify.ts +0 -85
  14. package/src/browser/adapters/bad.ts +0 -165
  15. package/src/browser/agent-adapter.ts +0 -145
  16. package/src/browser/process-adapter.ts +0 -146
  17. package/src/browser/run-to-spans.ts +0 -105
  18. package/src/browser/run-to-spans.verify.ts +0 -89
  19. package/src/browser/ui-reviewer.ts +0 -200
  20. package/src/browser/ui-reviewer.verify.ts +0 -94
  21. package/src/browser/verify.ts +0 -96
  22. package/src/clbench-codebase-gate.mts +0 -314
  23. package/src/clbench-context-gate.mts +0 -341
  24. package/src/commit0-env-run.mts +0 -62
  25. package/src/commit0-env.ts +0 -172
  26. package/src/commit0-gate.mts +0 -558
  27. package/src/egress-probe.mts +0 -26
  28. package/src/humaneval-repair-gate.mts +0 -182
  29. package/src/profile-coordinates.ts +0 -134
  30. package/src/run-benchmarks-report.ts +0 -66
  31. package/src/skill-sandbox-smoke.mts +0 -101
  32. package/src/supervisor-arena.mts +0 -825
  33. package/src/swe-emit-patch.mts +0 -125
  34. package/src/swe-local-proof.mts +0 -265
  35. package/src/swe-repro-calibrate.mts +0 -451
  36. package/src/swe-stream.mts +0 -1561
  37. package/src/trajectory-assemble.mjs +0 -130
  38. package/src/worker-browser.ts +0 -115
  39. package/src/worker-cad.ts +0 -470
  40. package/src/workspace-loop.mts +0 -133
@@ -1,125 +0,0 @@
1
- /**
2
- * Judge-FREE patch emitter for the SWE scaffold — the FIXED measurement entrypoint.
3
- *
4
- * Given ONE instance id (IDS) + worker model + router env, this runs the candidate scaffold's OWN
5
- * `createSweBenchEnvironment` + `runAgentic` IN THIS worktree and prints the unified `git diff` of
6
- * the agent's edits to STDOUT. It does NOT judge — the swebench Docker judge is held OUTSIDE the
7
- * candidate (in swe-code-improve.mts) so the scaffold can never grade its own axis.
8
- *
9
- * This is the seam the code-aware improve() agent shells into. Its I/O contract is FIXED and the
10
- * scaffold proposer must NOT change it:
11
- * IN (env): IDS=<one instance id>, WORKER_MODEL, MAX_TOKENS, ROUTER_BASE, TANGLE_API_KEY,
12
- * INNER_TURNS, BUDGET, RUN_TOOL
13
- * OUT (fd1): the unified diff (empty string when the agent made no edit)
14
- * diagnostics go to STDERR only, so stdout stays a clean patch.
15
- *
16
- * SWE_EMIT_SMOKE=1 → import/wiring check only: the module (and swe-bench-env) loaded, print READY on
17
- * stderr and exit 0 WITHOUT a clone / model call / dataset read. This is what the candidate verifier
18
- * runs to discard a scaffold edit that no longer imports.
19
- *
20
- * Command examples in prompts are kept OUT of backticks on purpose (router WAF 403s backtick-wrapped
21
- * command text) — see swe-bench-env.ts.
22
- */
23
- import { execFile } from 'node:child_process'
24
- import { promisify } from 'node:util'
25
- import type { AgenticSurface, ArtifactHandle, SurfaceScore } from '@tangle-network/agent-runtime/kernel'
26
- import { defaultAnalystInstruction, refine, runAgentic } from '@tangle-network/agent-runtime/kernel'
27
- import { createSweBenchEnvironment, SWE_SEED_PROMPT, SWE_SEED_PROMPT_WITH_RUN } from './swe-bench-env'
28
- import { benchRouterProfile, withBenchProfile } from './router-turn'
29
-
30
- const exec = promisify(execFile)
31
-
32
- async function main(): Promise<void> {
33
- const smoke = ['1', 'true', 'yes'].includes((process.env.SWE_EMIT_SMOKE ?? '').toLowerCase())
34
- if (smoke) {
35
- // The import graph (this file + swe-bench-env + the linked runtime) resolved by the time we get
36
- // here. That is the whole check — no clone, no model call, no dataset read.
37
- console.error('SWE_EMIT_SMOKE ok: swe-emit-patch + swe-bench-env import graph loaded')
38
- return
39
- }
40
-
41
- const routerKey = process.env.TANGLE_API_KEY
42
- if (!routerKey) throw new Error('TANGLE_API_KEY required (the worker calls the router)')
43
- const routerBaseUrl = process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1'
44
- const model = process.env.WORKER_MODEL ?? 'glm-5.2'
45
- const ids = (process.env.IDS ?? '').split(',').map((s) => s.trim()).filter(Boolean)
46
- if (ids.length !== 1) throw new Error(`swe-emit-patch: exactly one IDS required, got [${ids.join(', ')}]`)
47
- const id = ids[0]!
48
- const innerTurns = Number(process.env.INNER_TURNS ?? 40)
49
- const maxTokens = Number(process.env.MAX_TOKENS ?? 12000)
50
- const budget = Number(process.env.BUDGET ?? 1)
51
- const enableRun = ['1', 'true', 'yes'].includes((process.env.RUN_TOOL ?? '').toLowerCase())
52
-
53
- const { environment, adapter } = await createSweBenchEnvironment(1, { ids, enableRun })
54
- const pool = await adapter.loadTasks({ ids, split: 'test' })
55
- const bt = pool.find((t) => t.id === id)
56
- if (!bt) throw new Error(`swe-emit-patch: instance not found in Verified: ${id}`)
57
-
58
- const task = {
59
- id: bt.id,
60
- userPrompt: bt.prompt,
61
- meta: { instanceId: bt.id },
62
- }
63
- const workerProfile = withBenchProfile(
64
- {
65
- name: 'swe-emit-patch-worker',
66
- harness: 'cli-base',
67
- model: { provider: 'tangle-router', default: model },
68
- tools: {
69
- list_files: true,
70
- read_file: true,
71
- edit_file: true,
72
- ...(enableRun ? { run: true } : {}),
73
- },
74
- },
75
- {
76
- systemPrompt: enableRun ? SWE_SEED_PROMPT_WITH_RUN : SWE_SEED_PROMPT,
77
- maxTokens,
78
- maxTurns: innerTurns,
79
- },
80
- )
81
- const analystProfile = benchRouterProfile('swe-emit-patch-analyst', model, {
82
- systemPrompt: defaultAnalystInstruction,
83
- maxTokens,
84
- })
85
-
86
- // Capture the patch from inside score() (called during the refine loop, BEFORE the surface closes
87
- // and rms the checkout). Keep the LATEST non-empty diff so accumulated refinements win and a later
88
- // empty read never clobbers a real patch.
89
- let capturedPatch = ''
90
- const proxy: AgenticSurface = {
91
- ...environment,
92
- async score(_t, handle: ArtifactHandle): Promise<SurfaceScore> {
93
- try {
94
- const d = await exec('git', ['-C', handle.id, 'diff'], { maxBuffer: 40_000_000, timeout: 60_000 })
95
- if (d.stdout.trim()) capturedPatch = d.stdout
96
- } catch {
97
- /* workspace gone or git error → keep whatever we already captured */
98
- }
99
- return { passes: capturedPatch.trim() ? 1 : 0, total: 1, errored: 0 }
100
- },
101
- }
102
-
103
- const t0 = Date.now()
104
- const r = await runAgentic({
105
- surface: proxy,
106
- task,
107
- strategy: refine,
108
- routerBaseUrl,
109
- routerKey,
110
- workerProfile,
111
- analystProfile,
112
- budget,
113
- })
114
- const files = capturedPatch ? [...capturedPatch.matchAll(/^diff --git a\/(\S+)/gm)].map((m) => m[1]) : []
115
- console.error(
116
- `[emit] ${id} shots=${r.shots} completions=${r.completions} tok=in:${r.tokens.input}/out:${r.tokens.output} ` +
117
- `patch=${capturedPatch.length}b files=[${files.join(', ') || 'none'}] ${Math.round((Date.now() - t0) / 1000)}s`,
118
- )
119
- process.stdout.write(capturedPatch)
120
- }
121
-
122
- main().catch((e) => {
123
- console.error(e instanceof Error ? (e.stack ?? e.message) : String(e))
124
- process.exit(1)
125
- })
@@ -1,265 +0,0 @@
1
- /**
2
- * SEE-able LOCAL proof of the SWE-bench Verified pipeline — NO tangle sandbox.
3
- *
4
- * The whole loop runs on infra we can watch: the repo is cloned into a host tmpdir, the agent is a
5
- * router-driven tool loop (`runAgentic` + the swe-bench `AgenticSurface`'s list/read/edit tools —
6
- * jailed to the checkout), the patch is a plain `git diff` of the agent's edits, and the score is
7
- * the OFFICIAL swebench Docker harness (`adapter.judge`). The only remote call is the model
8
- * completion via the router. Nothing touches sandbox.tangle.tools.
9
- *
10
- * We proxy the surface's `score()` so we can SEE the exact bytes the judge grades: the extracted
11
- * patch, whether it applies to a clean base checkout (`git apply --check`), and the swebench verdict.
12
- * With TRACE=1 we also log every tool call so we can tell "agent never edited" from "agent can't edit".
13
- *
14
- * TANGLE_API_KEY=… dotenvx run -f …/agent-state.env -- \
15
- * IDS=django__django-12419 WORKER_MODEL=glm-4.6 \
16
- * node_modules/.bin/tsx bench/src/swe-local-proof.mts
17
- */
18
- import { execFile } from 'node:child_process'
19
- import { appendFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } 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, ArtifactHandle, SurfaceScore } from '@tangle-network/agent-runtime/kernel'
24
- import { defaultAnalystInstruction, refine, runAgentic } from '@tangle-network/agent-runtime/kernel'
25
- import type { BenchScore } from './benchmarks/types'
26
- import { createSweBenchEnvironment, SWE_SEED_PROMPT, SWE_SEED_PROMPT_WITH_RUN } from './swe-bench-env'
27
- import { benchRouterProfile, withBenchProfile } from './router-turn'
28
-
29
- const exec = promisify(execFile)
30
-
31
- async function main(): Promise<void> {
32
- const routerKey = process.env.TANGLE_API_KEY
33
- if (!routerKey) throw new Error('TANGLE_API_KEY required (the worker calls the router)')
34
- const routerBaseUrl = process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1'
35
- const model = process.env.WORKER_MODEL ?? 'glm-4.6'
36
- const ids = (process.env.IDS ?? 'django__django-12419').split(',').map((s) => s.trim()).filter(Boolean)
37
- const innerTurns = Number(process.env.INNER_TURNS ?? 40)
38
- const maxTokens = Number(process.env.MAX_TOKENS ?? 8000)
39
- const budget = Number(process.env.BUDGET ?? 1)
40
- // WITH-TOOLS arm: RUN_TOOL=1 exposes the jailed `run` tool + the run-aware prompt. Default OFF ⇒
41
- // the read/edit-only baseline (glm-5.2 7/12) unchanged.
42
- const enableRun = ['1', 'true', 'yes'].includes((process.env.RUN_TOOL ?? '').toLowerCase())
43
- const artifactDir = process.env.RUN_ARTIFACT_DIR
44
- if (artifactDir) mkdirSync(artifactDir, { recursive: true })
45
-
46
- console.log(`═══ SWE-bench Verified — SEE-able LOCAL proof (no tangle sandbox) ═══`)
47
- console.log(`model=${model} ids=${ids.join(',')} innerTurns=${innerTurns} maxTokens=${maxTokens} budget=${budget} runTool=${enableRun}`)
48
- console.log(`router=${routerBaseUrl}`)
49
-
50
- const { environment, tasks, adapter } = await createSweBenchEnvironment(ids.length, {
51
- ids,
52
- enableRun,
53
- ...(artifactDir ? {
54
- adapterOptions: {
55
- captureEvaluatorArtifacts: ({ taskId, attemptSequence }) => ({
56
- destination: join(artifactDir, taskId, `judge-${attemptSequence}`),
57
- }),
58
- },
59
- } : {}),
60
- })
61
- const workerProfile = withBenchProfile(
62
- {
63
- name: 'swe-local-proof-worker',
64
- harness: 'cli-base',
65
- model: { provider: 'tangle-router', default: model },
66
- tools: {
67
- list_files: true,
68
- read_file: true,
69
- edit_file: true,
70
- ...(enableRun ? { run: true } : {}),
71
- },
72
- },
73
- {
74
- systemPrompt: enableRun ? SWE_SEED_PROMPT_WITH_RUN : SWE_SEED_PROMPT,
75
- maxTokens,
76
- maxTurns: innerTurns,
77
- },
78
- )
79
- const analystProfile = benchRouterProfile('swe-local-proof-analyst', model, {
80
- systemPrompt: defaultAnalystInstruction,
81
- maxTokens,
82
- })
83
- const taskList = await tasks(0, ids.length)
84
- const benchTaskById = new Map(
85
- (await adapter.loadTasks({ ids, split: 'test' })).map((task) => [task.id, task]),
86
- )
87
-
88
- // One shot per pinned id: proxy score() to capture the exact judged bytes + a NON-DESTRUCTIVE
89
- // apply-coherence check, then delegate the verdict to the real Docker judge.
90
- //
91
- // CRITICAL: score() is called MORE THAN ONCE per task by the driver — the shotExecutor scores
92
- // the handle to drive its loop, and depthStrategy scores it again at the end. So this proxy MUST
93
- // be non-destructive (never mutate the working tree the agent edited) and idempotent (never
94
- // clobber a captured non-empty patch with a later empty read). It also caches the judge by patch
95
- // so we don't run the Docker harness twice for the identical diff.
96
- type Rec = { patch: string; applied: boolean; applyErr?: string; applyChecked?: boolean; score?: BenchScore }
97
- const captured = new Map<string, Rec>()
98
- const judged = new Map<string, BenchScore>()
99
- const toolStats = new Map<string, { list: number; read: number; edit_ok: number; edit_fail: number; run: number; run_err: number }>()
100
- let activeTaskId = ''
101
- const recordTool = (name: string, args: unknown, result: unknown, error?: string) => {
102
- if (!artifactDir || !activeTaskId) return
103
- const taskDir = join(artifactDir, activeTaskId)
104
- mkdirSync(taskDir, { recursive: true })
105
- appendFileSync(join(taskDir, 'tools.jsonl'), JSON.stringify({
106
- at: new Date().toISOString(), name, args,
107
- ...(error ? { error } : { result }),
108
- }) + '\n')
109
- }
110
- const proxy: AgenticSurface = {
111
- ...environment,
112
- async call(handle, name, args) {
113
- let res: string
114
- try {
115
- res = await environment.call(handle, name, args)
116
- } catch (error) {
117
- recordTool(name, args, undefined, error instanceof Error ? error.message : String(error))
118
- throw error
119
- }
120
- recordTool(name, args, res)
121
- // Count tool usage per workspace so we can SEE whether the agent ever edited, and whether
122
- // edits succeeded or bounced off old_string matching. handle.id keys the workspace.
123
- const st = toolStats.get(handle.id) ?? { list: 0, read: 0, edit_ok: 0, edit_fail: 0, run: 0, run_err: 0 }
124
- const r = String(res)
125
- if (name === 'list_files') st.list += 1
126
- else if (name === 'read_file') st.read += 1
127
- else if (name === 'edit_file') {
128
- if (r.startsWith('edited ')) st.edit_ok += 1
129
- else st.edit_fail += 1
130
- } else if (name === 'run') {
131
- if (r.startsWith('ERROR:')) st.run_err += 1
132
- else st.run += 1
133
- }
134
- toolStats.set(handle.id, st)
135
- if (process.env.TRACE) {
136
- const a = JSON.stringify(args).slice(0, 200)
137
- console.error(`[TOOL] ${name} args=${a} -> ${r.slice(0, 200).replace(/\n/g, '⏎')}`)
138
- }
139
- return res
140
- },
141
- async score(task, handle: ArtifactHandle): Promise<SurfaceScore> {
142
- const dir = handle.id
143
- const diff = await exec('git', ['-C', dir, 'diff'], { maxBuffer: 40_000_000, timeout: 60_000 })
144
- const patch = diff.stdout
145
- // Mirror tool stats onto the task id (handle.id == dir).
146
- const st = toolStats.get(dir)
147
- if (st) toolStats.set(task.id, st)
148
- // Idempotent capture: keep the FIRST non-empty patch; never overwrite it with a later empty read.
149
- const prev = captured.get(task.id)
150
- let rec: Rec
151
- if (!prev) {
152
- rec = { patch, applied: false }
153
- captured.set(task.id, rec)
154
- } else {
155
- rec = prev
156
- if (!rec.patch.trim() && patch.trim()) rec.patch = patch
157
- }
158
- const effPatch = rec.patch
159
- if (!effPatch.trim()) return { passes: 0, total: 1, errored: 0 }
160
- // NON-DESTRUCTIVE apply-coherence check (once): the diff was produced from this tree vs HEAD,
161
- // so `git apply --check -R` proves it is a clean, self-consistent patch without touching the
162
- // working tree. The REAL forward-apply-to-clean-base proof is the swebench judge below, which
163
- // applies the patch in a fresh Docker checkout and reports apply failures.
164
- if (!rec.applyChecked) {
165
- rec.applyChecked = true
166
- const pf = join(mkdtempSync(join(tmpdir(), 'swe-apply-')), 'p.diff')
167
- writeFileSync(pf, effPatch)
168
- try {
169
- await exec('git', ['-C', dir, 'apply', '--check', '-R', pf], { timeout: 60_000 })
170
- rec.applied = true
171
- } catch (e) {
172
- rec.applied = false
173
- rec.applyErr = e instanceof Error ? e.message.slice(0, 200) : String(e)
174
- } finally {
175
- rmSync(pf, { force: true })
176
- }
177
- }
178
- // Cached judge: identical patch ⇒ identical verdict; don't pay for a second Docker run.
179
- let s = judged.get(effPatch)
180
- if (!s) {
181
- const benchTask = benchTaskById.get(task.id)
182
- if (!benchTask) throw new Error(`swe-local-proof: unknown benchmark task ${task.id}`)
183
- s = await adapter.judge(benchTask, effPatch)
184
- judged.set(effPatch, s)
185
- }
186
- rec.score = s
187
- return { passes: s.resolved ? 1 : 0, total: 1, errored: 0 }
188
- },
189
- }
190
-
191
- let anyResolved = 0
192
- for (const task of taskList) {
193
- activeTaskId = task.id
194
- const t0 = Date.now()
195
- const r = await runAgentic({
196
- surface: proxy,
197
- task,
198
- strategy: refine,
199
- routerBaseUrl,
200
- routerKey,
201
- workerProfile,
202
- analystProfile,
203
- budget,
204
- ...(artifactDir ? { hooks: { onEvent(event: unknown) {
205
- const taskDir = join(artifactDir, activeTaskId)
206
- mkdirSync(taskDir, { recursive: true })
207
- appendFileSync(join(taskDir, 'runtime-events.jsonl'), JSON.stringify(event, (_key, value) =>
208
- value instanceof Error ? { name: value.name, message: value.message, stack: value.stack } : value,
209
- ) + '\n')
210
- } } } : {}),
211
- })
212
- const rec = captured.get(task.id)
213
- const st = toolStats.get(task.id)
214
- const patchBytes = rec?.patch.length ?? 0
215
- const patchLines = rec?.patch ? rec.patch.split('\n').length : 0
216
- const files = rec?.patch ? [...rec.patch.matchAll(/^diff --git a\/(\S+)/gm)].map((m) => m[1]) : []
217
- const resolved = rec?.score?.resolved ?? false
218
- if (resolved) anyResolved += 1
219
- console.log(`\n──── ${task.id} ────`)
220
- console.log(` agent shots=${r.shots} completions=${r.completions} tokens=in:${r.tokens.input}/out:${r.tokens.output} usd=${r.usd} wall=${Math.round((Date.now() - t0) / 1000)}s`)
221
- console.log(` tools: list=${st?.list ?? 0} read=${st?.read ?? 0} edit_ok=${st?.edit_ok ?? 0} edit_fail=${st?.edit_fail ?? 0} run=${st?.run ?? 0} run_err=${st?.run_err ?? 0}`)
222
- console.log(` patch: ${patchBytes} bytes, ${patchLines} lines, files=[${files.join(', ') || '(none)'}]`)
223
- console.log(` patch APPLIED (git apply --check on clean base): ${rec?.applied ? 'YES' : 'NO'}${rec?.applyErr ? ` (${rec.applyErr})` : ''}`)
224
- console.log(` swebench judge RESOLVED: ${resolved ? '1' : '0'}`)
225
- if (rec?.score?.detail) console.log(` judge report: ${rec.score.detail.slice(0, 400)}`)
226
- if (artifactDir) {
227
- const taskDir = join(artifactDir, task.id)
228
- mkdirSync(taskDir, { recursive: true })
229
- writeFileSync(join(taskDir, 'patch.diff'), rec?.patch ?? '')
230
- writeFileSync(join(taskDir, 'summary.json'), JSON.stringify({
231
- benchmark: 'SWE-bench Verified',
232
- taskId: task.id,
233
- modelRequested: model,
234
- prompt: task.userPrompt,
235
- turnsLimit: innerTurns,
236
- maxTokens,
237
- budget,
238
- enableRun,
239
- shots: r.shots,
240
- completions: r.completions,
241
- tokens: r.tokens,
242
- tokensKnown: r.tokensKnown,
243
- billedCostUsd: null,
244
- reportedUsd: r.usd,
245
- reportedUsdKnown: r.usdKnown,
246
- progression: r.progression,
247
- runScore: r.score,
248
- runResolved: r.resolved,
249
- wallMs: Date.now() - t0,
250
- toolStats: st ?? null,
251
- patchBytes,
252
- patchLines,
253
- files,
254
- patchApplies: rec?.applied ?? false,
255
- score: rec?.score ?? null,
256
- }, null, 2) + '\n')
257
- }
258
- }
259
- console.log(`\n>>> resolved ${anyResolved}/${taskList.length}`)
260
- }
261
-
262
- main().catch((e) => {
263
- console.error(e instanceof Error ? (e.stack ?? e.message) : String(e))
264
- process.exit(1)
265
- })