@tangle-network/agent-bench 0.14.4 → 1.0.2
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 +46 -0
- package/README.md +2 -3
- package/dist/adapters.d.ts +2 -5
- package/dist/adapters.js +3 -4
- package/dist/benchmarks/_harness.d.ts +17 -20
- package/dist/benchmarks/_harness.js +4 -4
- package/dist/benchmarks/_harness.js.map +1 -1
- package/dist/benchmarks/aec-bench.d.ts +1 -4
- package/dist/benchmarks/aec-bench.js +1 -2
- package/dist/benchmarks/agentbench.d.ts +2 -5
- package/dist/benchmarks/agentbench.js +1 -2
- package/dist/benchmarks/appworld.d.ts +8 -10
- package/dist/benchmarks/appworld.js +23 -23
- package/dist/benchmarks/appworld.js.map +1 -1
- package/dist/benchmarks/bfcl.d.ts +2 -5
- package/dist/benchmarks/bfcl.js +1 -2
- package/dist/benchmarks/cad-design.d.ts +2 -5
- package/dist/benchmarks/cad-design.js +2 -3
- package/dist/benchmarks/cad-design.js.map +1 -1
- package/dist/benchmarks/cadbench.d.ts +1 -4
- package/dist/benchmarks/cadbench.js +1 -2
- package/dist/benchmarks/cadgenbench.d.ts +1 -4
- package/dist/benchmarks/cadgenbench.js +1 -2
- package/dist/benchmarks/commit0.d.ts +2 -5
- package/dist/benchmarks/commit0.js +1 -2
- package/dist/benchmarks/crag.d.ts +1 -4
- package/dist/benchmarks/crag.js +3 -3
- package/dist/benchmarks/crag.js.map +1 -1
- package/dist/benchmarks/dabstep.d.ts +2 -5
- package/dist/benchmarks/dabstep.js +2 -3
- package/dist/benchmarks/dabstep.js.map +1 -1
- package/dist/benchmarks/enterpriseops-gym.d.ts +2 -5
- package/dist/benchmarks/enterpriseops-gym.js +1 -2
- package/dist/benchmarks/finresearchbench.d.ts +2 -5
- package/dist/benchmarks/finresearchbench.js +2 -3
- package/dist/benchmarks/finsearchcomp.d.ts +2 -5
- package/dist/benchmarks/finsearchcomp.js +4 -4
- package/dist/benchmarks/finsearchcomp.js.map +1 -1
- package/dist/benchmarks/frames.d.ts +3 -19
- package/dist/benchmarks/frames.js +13 -39
- package/dist/benchmarks/frames.js.map +1 -1
- package/dist/benchmarks/hotpotqa.d.ts +4 -14
- package/dist/benchmarks/hotpotqa.js +12 -32
- package/dist/benchmarks/hotpotqa.js.map +1 -1
- package/dist/benchmarks/humaneval.d.ts +9 -12
- package/dist/benchmarks/humaneval.js +2 -3
- package/dist/benchmarks/humaneval.js.map +1 -1
- package/dist/benchmarks/mcad-bench.d.ts +13 -16
- package/dist/benchmarks/mcad-bench.js +2 -3
- package/dist/benchmarks/mcad-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-bench.d.ts +17 -20
- package/dist/benchmarks/mcad-cq-bench.js +2 -3
- package/dist/benchmarks/mcad-cq-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-golds.d.ts +2 -5
- package/dist/benchmarks/mcad-cq-golds.js +1 -2
- package/dist/benchmarks/mcad-golds.d.ts +1 -4
- package/dist/benchmarks/mcad-golds.js +0 -1
- package/dist/benchmarks/mcad-tasks.d.ts +5 -8
- package/dist/benchmarks/mcad-tasks.js +7 -8
- package/dist/benchmarks/mcad-tasks.js.map +1 -1
- package/dist/benchmarks/mind2web.d.ts +3 -5
- package/dist/benchmarks/mind2web.js +2 -3
- package/dist/benchmarks/mind2web.js.map +1 -1
- package/dist/benchmarks/nomiracl.d.ts +1 -4
- package/dist/benchmarks/nomiracl.js +1 -2
- package/dist/benchmarks/open-rag-bench.d.ts +1 -4
- package/dist/benchmarks/open-rag-bench.js +3 -3
- package/dist/benchmarks/open-rag-bench.js.map +1 -1
- package/dist/benchmarks/programbench.d.ts +2 -5
- package/dist/benchmarks/programbench.js +1 -2
- package/dist/benchmarks/rag-shared.d.ts +30 -22
- package/dist/benchmarks/rag-shared.js +8 -2
- package/dist/benchmarks/rag-shared.js.map +1 -1
- package/dist/benchmarks/ragbench.d.ts +1 -4
- package/dist/benchmarks/ragbench.js +3 -3
- package/dist/benchmarks/ragbench.js.map +1 -1
- package/dist/benchmarks/simpleqa.d.ts +2 -18
- package/dist/benchmarks/simpleqa.js +5 -31
- package/dist/benchmarks/simpleqa.js.map +1 -1
- package/dist/benchmarks/swe-bench.d.ts +7 -10
- package/dist/benchmarks/swe-bench.js +4 -4
- package/dist/benchmarks/swe-bench.js.map +1 -1
- package/dist/benchmarks/t2-ragbench.d.ts +1 -4
- package/dist/benchmarks/t2-ragbench.js +3 -3
- package/dist/benchmarks/t2-ragbench.js.map +1 -1
- package/dist/benchmarks/tau-bench-shared.d.ts +5 -8
- package/dist/benchmarks/tau-bench-shared.js +4 -4
- package/dist/benchmarks/tau-bench-shared.js.map +1 -1
- package/dist/benchmarks/tau2-bench.d.ts +2 -5
- package/dist/benchmarks/tau2-bench.js +1 -2
- package/dist/benchmarks/tau3-banking.d.ts +1 -4
- package/dist/benchmarks/tau3-banking.js +1 -2
- package/dist/benchmarks/terminal-bench.d.ts +1 -4
- package/dist/benchmarks/terminal-bench.js +4 -4
- package/dist/benchmarks/terminal-bench.js.map +1 -1
- package/dist/benchmarks/toollm.d.ts +2 -5
- package/dist/benchmarks/toollm.js +1 -2
- package/dist/benchmarks/trata-hedge.d.ts +1 -4
- package/dist/benchmarks/trata-hedge.js +2 -3
- package/dist/benchmarks/types.d.ts +6 -9
- package/dist/benchmarks/webarena-verified.d.ts +2 -5
- package/dist/benchmarks/webarena-verified.js +1 -2
- package/dist/{cadbench-BRF-59Mt.js → cadbench-DhAndllg.js} +4 -6
- package/dist/cadbench-DhAndllg.js.map +1 -0
- package/dist/{cadgenbench-DXtGkuW3.js → cadgenbench-Tvk16YKT.js} +15 -5
- package/dist/cadgenbench-Tvk16YKT.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.js +16 -24
- package/dist/index.js.map +1 -1
- package/dist/{router-turn-uTYO6KQ1.js → router-turn-DNbQ_GjQ.js} +2 -3
- package/dist/router-turn-DNbQ_GjQ.js.map +1 -0
- package/fixtures/pier-agent/no-model-task/pre_artifacts.sh +0 -0
- package/fixtures/pier-agent/no-model-task/tests/test.sh +0 -0
- package/package.json +10 -10
- package/pier_agents/tangle_candidate.py +15 -23
- package/scripts/run-package-tests.mjs +8 -15
- package/src/atom-mcp-e2e.mts +2 -2
- package/src/benchmarks/frames.ts +10 -44
- package/src/benchmarks/hotpotqa.ts +9 -29
- package/src/benchmarks/rag-shared.ts +12 -0
- package/src/benchmarks/simpleqa.ts +2 -36
- package/src/commit0-prereqs.sh +0 -0
- package/src/corpus-replay.mts +8 -8
- package/src/corpus-report.mts +21 -21
- package/src/corpus.test.mts +5 -5
- package/src/corpus.ts +16 -16
- package/src/directives.ts +0 -38
- package/src/examples/lean-verify.ts +1 -1
- package/src/gate.ts +7 -7
- package/src/generate-eval/certify.ts +2 -2
- package/src/index.ts +1 -0
- package/src/refine-loop.ts +5 -5
- package/src/resolve-client.ts +1 -1
- package/src/router-turn.ts +3 -11
- package/src/run-pool.ts +1 -1
- package/src/runtime-hook-recorder.ts +2 -2
- package/src/search-bench/tasks.ts +1 -1
- package/src/selector.test.mts +13 -13
- package/src/selector.ts +19 -19
- package/src/swe-bench-env.ts +4 -12
- package/src/swe-jail.ts +5 -156
- package/src/swe-structural-judge-policy.ts +3 -3
- package/src/swe-structural-policy.ts +3 -3
- package/src/swe-structural-provenance.ts +4 -4
- package/src/terminal-compare.ts +10 -10
- package/src/worker-blender.ts +2 -106
- package/src/worker-build123d.ts +2 -81
- package/tb_agents/opencode_router_agent.py +1 -1
- package/dist/cadbench-BRF-59Mt.js.map +0 -1
- package/dist/cadgenbench-DXtGkuW3.js.map +0 -1
- package/dist/router-turn-uTYO6KQ1.js.map +0 -1
- package/scripts/cadbench_prepare.py +0 -22
- package/scripts/cadgenbench_hard_parts.py +0 -48
- package/scripts/clbench_codebase_judge.py +0 -73
- package/scripts/render-gate-chart.mjs +0 -176
- package/scripts/trata-hedge/README.md +0 -57
- package/scripts/trata-hedge/run.sh +0 -64
- package/src/cloud-loop.mts +0 -156
- package/src/coordination-mcp-container-reach.mts +0 -182
- package/src/fleet.mts +0 -143
- package/src/hev-structural.mts +0 -697
- package/src/humaneval-gate.mts +0 -220
- package/src/mbpp-structural.mts +0 -676
- package/src/mcp-mount-probe.mts +0 -141
- package/src/profiles.ts +0 -128
- package/src/research-gate.mts +0 -132
- package/src/research-shot.ts +0 -144
- package/src/router-executor.ts +0 -51
- package/src/sandbox-run.ts +0 -108
- package/src/search-bench/bridge.ts +0 -182
- package/src/search-bench/export.mts +0 -0
- package/src/search-bench/parametric-check.mts +0 -78
- package/src/search-bench/profiles.ts +0 -113
- package/src/search-bench/run.mts +0 -286
- package/src/search-bench/tasks-fresh.ts +0 -688
- package/src/smoke-structural-rollout.mts +0 -415
- package/src/stats.mts +0 -90
- package/src/swe-code-improve.mts +0 -306
- package/src/swe-improve.mts +0 -284
- package/src/swe-structural.mts +0 -707
- package/src/tb-container-executor.mts +0 -266
- package/src/tb-container-executor.test.mts +0 -134
- package/src/tb-supervisor-sidecar.mts +0 -208
- package/src/trata-gepa.mts +0 -381
- package/src/trata-hedge-solve.mts +0 -81
- package/tb_agents/opencode_refine_agent.py +0 -117
- package/tb_agents/opencode_supervisor_agent.py +0 -239
package/src/swe-code-improve.mts
DELETED
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* META-HARNESS on the SWE scaffold — improve({ surface: 'code' }).
|
|
3
|
-
*
|
|
4
|
-
* A Pi coding agent REWRITES the scaffold LOGIC under bench/src (the seed prompt/playbook,
|
|
5
|
-
* runAgentic strategy/params, context handling, retry/patch synthesis) with the MODEL (glm worker) +
|
|
6
|
-
* the TOOL surface (list/read/edit[/run]) + the JUDGE held FIXED, judged on the official swebench
|
|
7
|
-
* Docker verdict, gated on a held-out instance split. This is the DGM/meta-harness recipe: let the
|
|
8
|
-
* SYSTEM find the scaffold lever from the RAW failure traces, not hand-build it.
|
|
9
|
-
*
|
|
10
|
-
* Wiring (all verified in this worktree):
|
|
11
|
-
* - improve()/codeProposerFor + rawTraceContext come from the LOCAL agent-runtime build, linked into
|
|
12
|
-
* this bench's node_modules (bench/node_modules/@tangle-network/agent-runtime -> /home/drew/code/agent-runtime).
|
|
13
|
-
* - The candidate proposer supplies one exact Pi AgentProfile and runs it through Runtime's
|
|
14
|
-
* bridge executor. No local CLI shortcut or ambient model default exists.
|
|
15
|
-
* - Each candidate is a git worktree the driver forks off baseRef; Pi edits bench/src in place;
|
|
16
|
-
* `verify` (an import smoke of the edited scaffold) gates it before the expensive measurement.
|
|
17
|
-
* - MEASUREMENT: the code-aware agent fn shells into the candidate scaffold's OWN judge-free emit
|
|
18
|
-
* entrypoint (swe-emit-patch.mts) with cwd = the worktree, captures the unified diff, and returns
|
|
19
|
-
* it. improve()'s FIXED swebench judge scores that diff OUTSIDE the candidate, so the scaffold can
|
|
20
|
-
* never game its own axis. Baseline (empty surface) runs the UNEDITED scaffold from the main tree.
|
|
21
|
-
*
|
|
22
|
-
* Run (router WAF: keep example commands OUT of backticks):
|
|
23
|
-
* TANGLE_API_KEY=... dotenvx run --quiet -f .../agent-state.env --
|
|
24
|
-
* TRAIN_IDS=... HOLDOUT_IDS=... WORKER_MODEL=glm-4.6 GENERATIONS=1 POPULATION=2
|
|
25
|
-
* RUN_DIR=/abs/run BASE_REF=meta/swe-scaffold-baseline
|
|
26
|
-
* node_modules/.bin/tsx bench/src/swe-code-improve.mts
|
|
27
|
-
*/
|
|
28
|
-
import { spawn, spawnSync } from 'node:child_process'
|
|
29
|
-
import { existsSync, mkdirSync, symlinkSync } from 'node:fs'
|
|
30
|
-
import { join } from 'node:path'
|
|
31
|
-
import { improve, agenticGenerator } from '@tangle-network/agent-runtime'
|
|
32
|
-
import type { ProposalFinding } from '@tangle-network/agent-eval'
|
|
33
|
-
import type { DispatchContext, JudgeConfig, Scenario } from '@tangle-network/agent-eval/contract'
|
|
34
|
-
import { agentProfileSchema } from '@tangle-network/agent-interface'
|
|
35
|
-
import { createSweBenchAdapter } from './benchmarks/swe-bench'
|
|
36
|
-
import type { BenchTask } from './benchmarks/types'
|
|
37
|
-
|
|
38
|
-
/** The agent-runtime repo the worktree adapter forks candidate checkouts from (agent-runtime-swe is a
|
|
39
|
-
* worktree of it, so bench/src is tracked here). */
|
|
40
|
-
const REPO_ROOT = process.env.REPO_ROOT ?? '/home/drew/code/agent-runtime'
|
|
41
|
-
/** The main working tree = the baseline scaffold (its bench has the linked node_modules). */
|
|
42
|
-
const SWE_MAIN_ROOT = process.env.SWE_MAIN_ROOT ?? '/home/drew/code/agent-runtime-swe'
|
|
43
|
-
const MAIN_BENCH = join(SWE_MAIN_ROOT, 'bench')
|
|
44
|
-
const TSX_BIN = join(MAIN_BENCH, 'node_modules/.bin/tsx')
|
|
45
|
-
|
|
46
|
-
/** A candidate worktree is a fresh checkout with NO node_modules. Symlink the main bench's (already
|
|
47
|
-
* carrying the linked local runtime) so both the verifier and the measurement can run the scaffold. */
|
|
48
|
-
function ensureNodeModules(rootDir: string): void {
|
|
49
|
-
const target = join(rootDir, 'bench', 'node_modules')
|
|
50
|
-
if (existsSync(target)) return
|
|
51
|
-
try {
|
|
52
|
-
symlinkSync(join(MAIN_BENCH, 'node_modules'), target, 'dir')
|
|
53
|
-
} catch {
|
|
54
|
-
/* concurrent create / already exists — fine */
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Run the scaffold's judge-free emit entrypoint on ONE instance, from `rootDir`'s bench/src. Returns
|
|
59
|
-
* the unified diff (stdout, kept clean of any banner) + the tokens the worker reported (parsed from
|
|
60
|
-
* the [emit] stderr line). NO judge — the judge is held outside, in this file. */
|
|
61
|
-
function runEmit(
|
|
62
|
-
rootDir: string,
|
|
63
|
-
id: string,
|
|
64
|
-
env: Record<string, string>,
|
|
65
|
-
timeoutMs: number,
|
|
66
|
-
): Promise<{ patch: string; tokIn: number; tokOut: number; usd: number; code: number | null }> {
|
|
67
|
-
ensureNodeModules(rootDir)
|
|
68
|
-
const benchDir = join(rootDir, 'bench')
|
|
69
|
-
return new Promise((resolve) => {
|
|
70
|
-
const child = spawn(TSX_BIN, [join(benchDir, 'src/swe-emit-patch.mts')], {
|
|
71
|
-
cwd: benchDir,
|
|
72
|
-
env: { ...process.env, ...env, IDS: id },
|
|
73
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
74
|
-
})
|
|
75
|
-
let out = ''
|
|
76
|
-
let err = ''
|
|
77
|
-
child.stdout.on('data', (d) => (out += String(d)))
|
|
78
|
-
child.stderr.on('data', (d) => (err += String(d)))
|
|
79
|
-
const timer = setTimeout(() => {
|
|
80
|
-
if (!child.killed) child.kill('SIGKILL')
|
|
81
|
-
}, timeoutMs)
|
|
82
|
-
;(timer as { unref?: () => void }).unref?.()
|
|
83
|
-
child.on('error', () => {
|
|
84
|
-
clearTimeout(timer)
|
|
85
|
-
resolve({ patch: '', tokIn: 0, tokOut: 0, usd: 0, code: 1 })
|
|
86
|
-
})
|
|
87
|
-
child.on('close', (code) => {
|
|
88
|
-
clearTimeout(timer)
|
|
89
|
-
const m = /tok=in:(\d+)\/out:(\d+)/.exec(err)
|
|
90
|
-
const u = /usd=([0-9.]+)/.exec(err)
|
|
91
|
-
if (code !== 0) console.error(` [emit ${id}] exit=${code} stderr: ${err.slice(-400).replace(/\n/g, ' ')}`)
|
|
92
|
-
resolve({
|
|
93
|
-
patch: out,
|
|
94
|
-
tokIn: m ? Number(m[1]) : 0,
|
|
95
|
-
tokOut: m ? Number(m[2]) : 0,
|
|
96
|
-
usd: u ? Number(u[1]) : 0,
|
|
97
|
-
code,
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function main(): Promise<void> {
|
|
104
|
-
const routerKey = process.env.TANGLE_API_KEY
|
|
105
|
-
if (!routerKey) throw new Error('TANGLE_API_KEY required (worker calls the router)')
|
|
106
|
-
const routerBaseUrl = process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1'
|
|
107
|
-
const workerModel = process.env.WORKER_MODEL ?? 'glm-4.6'
|
|
108
|
-
const trainIds = (process.env.TRAIN_IDS ?? 'psf__requests-2931,pallets__flask-5014').split(',').map((s) => s.trim()).filter(Boolean)
|
|
109
|
-
const holdoutIds = (process.env.HOLDOUT_IDS ?? 'psf__requests-1142,psf__requests-1921').split(',').map((s) => s.trim()).filter(Boolean)
|
|
110
|
-
const generations = Number(process.env.GENERATIONS ?? 1)
|
|
111
|
-
const population = Number(process.env.POPULATION ?? 2)
|
|
112
|
-
const innerTurns = Number(process.env.INNER_TURNS ?? 40)
|
|
113
|
-
const maxTokens = Number(process.env.MAX_TOKENS ?? 12000)
|
|
114
|
-
const enableRun = ['1', 'true', 'yes'].includes((process.env.RUN_TOOL ?? '').toLowerCase())
|
|
115
|
-
const baseRef = process.env.BASE_REF ?? 'meta/swe-scaffold-baseline'
|
|
116
|
-
const worktreeDir = process.env.WORKTREE_DIR ?? '/tmp/claude-1000/-home-drew-code-supervisor-lab/9ee6a456-a94f-474c-9888-b4afc9bc26bd/scratchpad/mh-worktrees'
|
|
117
|
-
const runDir = process.env.RUN_DIR ?? '/tmp/claude-1000/-home-drew-code-supervisor-lab/9ee6a456-a94f-474c-9888-b4afc9bc26bd/scratchpad/mh-run'
|
|
118
|
-
const emitTimeoutMs = Number(process.env.EMIT_TIMEOUT_MS ?? 600_000)
|
|
119
|
-
const harnessTimeoutMs = Number(process.env.HARNESS_TIMEOUT_MS ?? 900_000)
|
|
120
|
-
const bridgeUrl = process.env.CLI_BRIDGE_URL ?? process.env.BRIDGE_URL
|
|
121
|
-
const bridgeBearer = process.env.CLI_BRIDGE_BEARER ?? process.env.BRIDGE_BEARER
|
|
122
|
-
if (!bridgeUrl || !bridgeBearer) {
|
|
123
|
-
throw new Error('CLI_BRIDGE_URL/BRIDGE_URL and CLI_BRIDGE_BEARER/BRIDGE_BEARER are required')
|
|
124
|
-
}
|
|
125
|
-
const authorProfile = agentProfileSchema.parse({
|
|
126
|
-
name: 'swe-scaffold-author',
|
|
127
|
-
harness: 'pi',
|
|
128
|
-
model: {
|
|
129
|
-
provider: process.env.AUTHOR_PROVIDER ?? 'tangle-router',
|
|
130
|
-
default: process.env.AUTHOR_MODEL ?? 'glm-5.2',
|
|
131
|
-
},
|
|
132
|
-
prompt: {
|
|
133
|
-
systemPrompt: 'Improve the candidate worktree from measured failure evidence and verify it.',
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
mkdirSync(worktreeDir, { recursive: true })
|
|
137
|
-
mkdirSync(runDir, { recursive: true })
|
|
138
|
-
|
|
139
|
-
const allIds = [...new Set([...trainIds, ...holdoutIds])]
|
|
140
|
-
|
|
141
|
-
console.log('=== META-HARNESS on the SWE scaffold — improve(surface:code) ===')
|
|
142
|
-
console.log(`worker=${workerModel} router=${routerBaseUrl} runTool=${enableRun}`)
|
|
143
|
-
console.log(`train=[${trainIds.join(', ')}] holdout=[${holdoutIds.join(', ')}]`)
|
|
144
|
-
console.log(`generations=${generations} population=${population} innerTurns=${innerTurns} maxTokens=${maxTokens}`)
|
|
145
|
-
console.log(`repoRoot=${REPO_ROOT} baseRef=${baseRef}`)
|
|
146
|
-
console.log(`runDir=${runDir} worktreeDir=${worktreeDir}`)
|
|
147
|
-
|
|
148
|
-
// Fixed swebench Docker judge (held OUTSIDE every candidate) + task pool.
|
|
149
|
-
const adapter = createSweBenchAdapter()
|
|
150
|
-
const pool = await adapter.loadTasks({ ids: allIds, split: 'test' })
|
|
151
|
-
const byId = new Map<string, BenchTask>(pool.map((t) => [t.id, t]))
|
|
152
|
-
for (const id of allIds) if (!byId.has(id)) throw new Error(`instance not found in Verified: ${id}`)
|
|
153
|
-
|
|
154
|
-
const workerEnv: Record<string, string> = {
|
|
155
|
-
WORKER_MODEL: workerModel,
|
|
156
|
-
MAX_TOKENS: String(maxTokens),
|
|
157
|
-
INNER_TURNS: String(innerTurns),
|
|
158
|
-
ROUTER_BASE: routerBaseUrl,
|
|
159
|
-
TANGLE_API_KEY: routerKey,
|
|
160
|
-
RUN_TOOL: enableRun ? '1' : '0',
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// The code-aware measurement agent. A CodeSurface -> run the candidate scaffold in its worktree; an
|
|
164
|
-
// empty/string surface (the baseline arm) -> run the UNEDITED scaffold from the main tree. Same path,
|
|
165
|
-
// so baseline and candidates are measured identically.
|
|
166
|
-
const agent = async (surface: unknown, scenario: Scenario, ctx: DispatchContext): Promise<string | null> => {
|
|
167
|
-
const isCode = !!surface && typeof surface === 'object' && (surface as { kind?: string }).kind === 'code'
|
|
168
|
-
const worktreeRef = isCode ? String((surface as { worktreeRef?: string }).worktreeRef ?? '') : ''
|
|
169
|
-
const rootDir = isCode && worktreeRef && existsSync(worktreeRef) ? worktreeRef : SWE_MAIN_ROOT
|
|
170
|
-
const t0 = Date.now()
|
|
171
|
-
const paid = await ctx.cost.runPaidCall({
|
|
172
|
-
channel: 'agent',
|
|
173
|
-
actor: 'swe-scaffold-worker',
|
|
174
|
-
model: workerModel,
|
|
175
|
-
execute: () => runEmit(rootDir, scenario.id, workerEnv, emitTimeoutMs),
|
|
176
|
-
receipt: (result) => {
|
|
177
|
-
const usageUnknown = result.tokIn === 0 && result.tokOut === 0
|
|
178
|
-
return {
|
|
179
|
-
model: workerModel,
|
|
180
|
-
inputTokens: result.tokIn,
|
|
181
|
-
outputTokens: result.tokOut,
|
|
182
|
-
...(result.usd > 0 ? { actualCostUsd: result.usd } : {}),
|
|
183
|
-
...(usageUnknown ? { usageUnknown: true, costUnknown: result.usd <= 0 } : {}),
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
})
|
|
187
|
-
if (!paid.succeeded) throw paid.error
|
|
188
|
-
const r = paid.value
|
|
189
|
-
const hasPatch = r.patch.trim().length > 0
|
|
190
|
-
const files = hasPatch ? [...r.patch.matchAll(/^diff --git a\/(\S+)/gm)].map((m) => m[1]) : []
|
|
191
|
-
console.log(
|
|
192
|
-
` [measure] ${isCode ? 'cand' : 'base'} ${scenario.id} patch=${r.patch.length}b files=[${files.join(', ') || 'none'}] ` +
|
|
193
|
-
`tok=in:${r.tokIn}/out:${r.tokOut} ${Math.round((Date.now() - t0) / 1000)}s${isCode ? ` @ ${worktreeRef}` : ''}`,
|
|
194
|
-
)
|
|
195
|
-
return hasPatch ? r.patch : null
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const judge: JudgeConfig<string | null, Scenario> = {
|
|
199
|
-
name: 'swebench-docker',
|
|
200
|
-
dimensions: [{ key: 'resolved', description: 'FAIL_TO_PASS + PASS_TO_PASS resolved by the official swebench Docker harness' }],
|
|
201
|
-
async score({ artifact, scenario }) {
|
|
202
|
-
const patch = String(artifact ?? '')
|
|
203
|
-
if (!patch.trim()) {
|
|
204
|
-
console.log(` [judge] ${scenario.id} resolved=0 (no patch)`)
|
|
205
|
-
return { dimensions: { resolved: 0 }, composite: 0, notes: 'no patch emitted' }
|
|
206
|
-
}
|
|
207
|
-
const bt = byId.get(scenario.id)
|
|
208
|
-
if (!bt) throw new Error(`judge: unknown scenario ${scenario.id}`)
|
|
209
|
-
const s = await adapter.judge(bt, patch)
|
|
210
|
-
console.log(` [judge] ${scenario.id} resolved=${s.resolved ? 1 : 0}`)
|
|
211
|
-
return { dimensions: { resolved: s.resolved ? 1 : 0 }, composite: s.resolved ? 1 : 0, notes: (s.detail ?? '').slice(0, 200) }
|
|
212
|
-
},
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Domain prompt: name the EDIT BOUNDARY (scaffold logic only) + keep the raw-trace evidence discipline
|
|
216
|
-
// (agenticGenerator discards a raw-trace candidate that doesn't inspect a trace + write the diagnosis).
|
|
217
|
-
const buildPrompt = (args: { findings: ReadonlyArray<ProposalFinding> }): string => {
|
|
218
|
-
const lines: string[] = [
|
|
219
|
-
'You are improving a SWE-bench coding SCAFFOLD: a harness that drives a FIXED worker model to fix real GitHub bugs via list_files/read_file/edit_file tools. Your job is to rewrite the SCAFFOLD LOGIC so the SAME worker model resolves MORE instances on a held-out split.',
|
|
220
|
-
'',
|
|
221
|
-
'EDIT ONLY the scaffold logic under bench/src:',
|
|
222
|
-
' - the seed prompt / playbook: SWE_SEED_PROMPT and SWE_SEED_PROMPT_WITH_RUN in bench/src/swe-bench-env.ts',
|
|
223
|
-
' - the exploration/context handling in bench/src/swe-bench-env.ts: list_files walk depth and 240-entry cap, the read_file 24000-char truncation, edit_file retry messaging, patch synthesis (git diff)',
|
|
224
|
-
' - the runAgentic strategy/params in bench/src/swe-emit-patch.mts: innerTurns default, budget, how the patch is captured',
|
|
225
|
-
'',
|
|
226
|
-
'DO NOT change (FIXED for this search):',
|
|
227
|
-
' - the TOOL surface: the list_files/read_file/edit_file/run tool NAMES, JSON signatures, or the path jail. Do not add or remove a tool.',
|
|
228
|
-
' - the worker MODEL or MAX_TOKENS (passed via env — never hardcode a different model).',
|
|
229
|
-
' - the swebench Docker JUDGE.',
|
|
230
|
-
' - the swe-emit-patch.mts I/O contract: it still reads IDS + WORKER_MODEL + router env and prints ONLY the unified diff to stdout (diagnostics to stderr). You may change HOW the patch is produced, never this stdin/stdout contract.',
|
|
231
|
-
'',
|
|
232
|
-
'Make the smallest set of edits that addresses the failure evidence below, then stop. Leave changes in the working tree; do NOT commit.',
|
|
233
|
-
'',
|
|
234
|
-
'Failure evidence from the previous generation (its RAW run traces are on disk):',
|
|
235
|
-
]
|
|
236
|
-
for (const f of args.findings) {
|
|
237
|
-
lines.push(`- (${f.severity ?? 'info'}) ${f.claim ?? ''}`)
|
|
238
|
-
if (f.recommended_action) lines.push(` -> ${f.recommended_action}`)
|
|
239
|
-
}
|
|
240
|
-
lines.push(
|
|
241
|
-
'',
|
|
242
|
-
'Raw-trace evidence requirement (enforced — a candidate that skips this is discarded):',
|
|
243
|
-
' - Inspect at least one raw trace path named above (grep/cat/ls it) BEFORE editing.',
|
|
244
|
-
' - Write .improve/raw-trace-diagnosis.md in this worktree containing: the exact trace path(s) you inspected, the failure mechanism you found, and the scaffold-logic change you made.',
|
|
245
|
-
' - A candidate with ONLY that file changed (no real scaffold edit) is discarded.',
|
|
246
|
-
)
|
|
247
|
-
return lines.join('\n')
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const verify = (worktreePath: string): { ok: boolean; feedback?: string } => {
|
|
251
|
-
ensureNodeModules(worktreePath)
|
|
252
|
-
const res = spawnSync(TSX_BIN, [join(worktreePath, 'bench/src/swe-emit-patch.mts')], {
|
|
253
|
-
cwd: join(worktreePath, 'bench'),
|
|
254
|
-
env: { ...process.env, SWE_EMIT_SMOKE: '1' },
|
|
255
|
-
encoding: 'utf-8',
|
|
256
|
-
timeout: 180_000,
|
|
257
|
-
})
|
|
258
|
-
if (res.status === 0) return { ok: true }
|
|
259
|
-
const out = `${res.stdout ?? ''}${res.stderr ?? ''}`.trim()
|
|
260
|
-
return { ok: false, feedback: `edited scaffold failed import smoke (tsx swe-emit-patch SWE_EMIT_SMOKE=1):\n${out.slice(0, 3000)}` }
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const generator = agenticGenerator({
|
|
264
|
-
profile: authorProfile,
|
|
265
|
-
executorForWorktree: (cwd) => ({
|
|
266
|
-
backend: 'bridge',
|
|
267
|
-
bridgeUrl,
|
|
268
|
-
bridgeBearer,
|
|
269
|
-
cwd,
|
|
270
|
-
}),
|
|
271
|
-
verify,
|
|
272
|
-
timeoutMs: harnessTimeoutMs,
|
|
273
|
-
buildPrompt,
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
const scenarios: Scenario[] = allIds.map((id) => ({ id, kind: 'swe-bench-verified' }))
|
|
277
|
-
const holdoutScenarios: Scenario[] = holdoutIds.map((id) => ({ id, kind: 'swe-bench-verified' }))
|
|
278
|
-
|
|
279
|
-
const out = await improve({
|
|
280
|
-
surface: 'code',
|
|
281
|
-
gate: 'holdout',
|
|
282
|
-
code: { repoRoot: REPO_ROOT, baseRef, worktreeDir, profile: authorProfile, generator },
|
|
283
|
-
rawTraceContext: true,
|
|
284
|
-
runDir,
|
|
285
|
-
scenarios,
|
|
286
|
-
judge,
|
|
287
|
-
agent,
|
|
288
|
-
expectUsage: 'warn',
|
|
289
|
-
budget: { generations, populationSize: population, holdoutScenarios, maxConcurrency: 1, reps: 1 },
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
console.log('\n=== RESULT ===')
|
|
293
|
-
console.log(`decision=${out.decision} lift=${out.lift}`)
|
|
294
|
-
console.log(`baseline holdout composite = ${out.raw.baseline.compositeMean}`)
|
|
295
|
-
console.log(`winner holdout composite = ${out.raw.winner.compositeMean}`)
|
|
296
|
-
console.log(`baseline per-scenario: ${JSON.stringify(out.raw.baseline.perScenario)}`)
|
|
297
|
-
console.log(`winner per-scenario: ${JSON.stringify(out.raw.winner.perScenario)}`)
|
|
298
|
-
if (out.raw.winner.label) console.log(`winner label: ${out.raw.winner.label}`)
|
|
299
|
-
if (out.raw.winner.rationale) console.log(`winner rationale: ${out.raw.winner.rationale}`)
|
|
300
|
-
console.log(`generations explored: ${out.generationsExplored ?? 0}`)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
main().catch((e) => {
|
|
304
|
-
console.error(e instanceof Error ? (e.stack ?? e.message) : String(e))
|
|
305
|
-
process.exit(1)
|
|
306
|
-
})
|
package/src/swe-improve.mts
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Official GEPA prompt optimization on the local SWE-bench path.
|
|
3
|
-
*
|
|
4
|
-
* Composes three pieces:
|
|
5
|
-
* 1. `improve({ method: officialGepa(...) })` runs GEPA's upstream
|
|
6
|
-
* Optimize Anything engine on explicit train and selection partitions.
|
|
7
|
-
* 2. Per candidate + scenario, the `agent` fn runs the LOCAL SWE env
|
|
8
|
-
* (`createSweBenchEnvironment` + `runAgentic`): clone the instance repo to a
|
|
9
|
-
* host tmpdir, run the jailed list/read/edit tool loop with the CANDIDATE
|
|
10
|
-
* prompt as the system prompt, and return the `git diff` as the artifact.
|
|
11
|
-
* 3. The `judge` scores that patch with the OFFICIAL swebench Docker harness
|
|
12
|
-
* (`adapter.judge` → resolved 0/1). The only remote call is the model
|
|
13
|
-
* completion via the router; nothing touches sandbox.tangle.tools.
|
|
14
|
-
*
|
|
15
|
-
* IN-LOOP score is a cheap patch-exists proxy (NOT the Docker judge) so the ONLY
|
|
16
|
-
* Docker run per cell is the improve judge — one deterministic verdict per cell.
|
|
17
|
-
*
|
|
18
|
-
* TANGLE_API_KEY=... dotenvx run -f .../agent-state.env -- \
|
|
19
|
-
* TRAIN_IDS=psf__requests-2931 SELECTION_IDS=pallets__flask-5014 \
|
|
20
|
-
* TEST_IDS=psf__requests-1142,psf__requests-1921 \
|
|
21
|
-
* MAX_EVALUATIONS=4 MAX_PROPOSER_COST_USD=2 \
|
|
22
|
-
* node_modules/.bin/tsx bench/src/swe-improve.mts
|
|
23
|
-
*/
|
|
24
|
-
import { execFile } from 'node:child_process'
|
|
25
|
-
import { promisify } from 'node:util'
|
|
26
|
-
import {
|
|
27
|
-
improve,
|
|
28
|
-
officialGepa,
|
|
29
|
-
type ReadonlyAgentProfile,
|
|
30
|
-
} from '@tangle-network/agent-runtime'
|
|
31
|
-
import {
|
|
32
|
-
canonicalCandidateDigest,
|
|
33
|
-
agentProfileSchema,
|
|
34
|
-
type AgentProfile,
|
|
35
|
-
} from '@tangle-network/agent-interface'
|
|
36
|
-
import type { AgenticSurface, ArtifactHandle, SurfaceScore } from '@tangle-network/agent-runtime/kernel'
|
|
37
|
-
import { defaultAnalystInstruction, refine, runAgentic } from '@tangle-network/agent-runtime/kernel'
|
|
38
|
-
import type { DispatchContext, JudgeConfig, Scenario } from '@tangle-network/agent-eval/contract'
|
|
39
|
-
import { createSweBenchAdapter } from './benchmarks/swe-bench'
|
|
40
|
-
import type { BenchTask } from './benchmarks/types'
|
|
41
|
-
import {
|
|
42
|
-
assertCompleteCost,
|
|
43
|
-
officialOptimizerModel,
|
|
44
|
-
requiredTokenPricing,
|
|
45
|
-
} from './official-optimizer-config.mjs'
|
|
46
|
-
import { createSweBenchEnvironment, SWE_SEED_PROMPT, SWE_SEED_PROMPT_WITH_RUN } from './swe-bench-env'
|
|
47
|
-
import { benchRouterProfile, withBenchProfile } from './router-turn'
|
|
48
|
-
|
|
49
|
-
const exec = promisify(execFile)
|
|
50
|
-
|
|
51
|
-
async function main(): Promise<void> {
|
|
52
|
-
const routerKey = process.env.TANGLE_API_KEY
|
|
53
|
-
if (!routerKey) throw new Error('TANGLE_API_KEY required (the worker + reflection call the router)')
|
|
54
|
-
const routerBaseUrl = process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1'
|
|
55
|
-
const workerModel = process.env.WORKER_MODEL ?? 'glm-4.6'
|
|
56
|
-
const reflectBase = process.env.REFLECT_BASE ?? routerBaseUrl
|
|
57
|
-
const reflectKey = process.env.REFLECT_KEY ?? routerKey
|
|
58
|
-
const reflectModel = process.env.REFLECT_MODEL ?? 'glm-4.6'
|
|
59
|
-
const trainIds = (process.env.TRAIN_IDS ?? 'psf__requests-2931').split(',').map((s) => s.trim()).filter(Boolean)
|
|
60
|
-
const selectionIds = (process.env.SELECTION_IDS ?? 'pallets__flask-5014').split(',').map((s) => s.trim()).filter(Boolean)
|
|
61
|
-
const testIds = (process.env.TEST_IDS ?? 'psf__requests-1142,psf__requests-1921').split(',').map((s) => s.trim()).filter(Boolean)
|
|
62
|
-
const maxEvaluations = Number(process.env.MAX_EVALUATIONS ?? 4)
|
|
63
|
-
const maxProposerCostUsd = Number(process.env.MAX_PROPOSER_COST_USD ?? 2)
|
|
64
|
-
const innerTurns = Number(process.env.INNER_TURNS ?? 40)
|
|
65
|
-
const workerMaxTokens = Number(process.env.MAX_TOKENS ?? 8000)
|
|
66
|
-
const reflectMaxTokens = Number(process.env.REFLECT_MAX_TOKENS ?? 12000)
|
|
67
|
-
const maxConcurrency = Number(process.env.MAX_CONCURRENCY ?? 1)
|
|
68
|
-
const budgetShots = Number(process.env.BUDGET ?? 1)
|
|
69
|
-
const runDir = process.env.RUN_DIR ?? '.runs/swe-official-gepa'
|
|
70
|
-
// WITH-TOOLS arm: RUN_TOOL=1 exposes the jailed `run` tool AND swaps the seed to the run-aware prompt.
|
|
71
|
-
// Default OFF ⇒ reproduces the read/edit-only baseline denominator unchanged.
|
|
72
|
-
const enableRun = ['1', 'true', 'yes'].includes((process.env.RUN_TOOL ?? '').toLowerCase())
|
|
73
|
-
const SEED_PROMPT = enableRun ? SWE_SEED_PROMPT_WITH_RUN : SWE_SEED_PROMPT
|
|
74
|
-
const allIds = [...new Set([...trainIds, ...selectionIds, ...testIds])]
|
|
75
|
-
const workerProfile = withBenchProfile(
|
|
76
|
-
{
|
|
77
|
-
name: 'swe-agent-worker',
|
|
78
|
-
harness: 'cli-base',
|
|
79
|
-
model: { provider: 'tangle-router', default: workerModel },
|
|
80
|
-
tools: {
|
|
81
|
-
list_files: true,
|
|
82
|
-
read_file: true,
|
|
83
|
-
edit_file: true,
|
|
84
|
-
...(enableRun ? { run: true } : {}),
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
{ systemPrompt: SEED_PROMPT, maxTokens: workerMaxTokens, maxTurns: innerTurns },
|
|
88
|
-
)
|
|
89
|
-
const analystProfile = benchRouterProfile('swe-agent-analyst', workerModel, {
|
|
90
|
-
systemPrompt: defaultAnalystInstruction,
|
|
91
|
-
maxTokens: workerMaxTokens,
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
console.log('=== SWE-bench prompt optimization with official GEPA ===')
|
|
95
|
-
console.log(`worker=${workerModel} reflect=${reflectModel} router=${routerBaseUrl}`)
|
|
96
|
-
console.log(`train=[${trainIds.join(', ')}] selection=[${selectionIds.join(', ')}] test=[${testIds.join(', ')}]`)
|
|
97
|
-
console.log(`maxEvaluations=${maxEvaluations} maxProposerCostUsd=${maxProposerCostUsd} innerTurns=${innerTurns} workerMaxTokens=${workerMaxTokens} runTool=${enableRun}`)
|
|
98
|
-
console.log(`runDir=${runDir}\n`)
|
|
99
|
-
|
|
100
|
-
if (process.env.DRYRUN) {
|
|
101
|
-
// Import + wiring smoke: prove every module resolves and the plan is well-formed
|
|
102
|
-
// WITHOUT paying for a clone / model call / Docker judge.
|
|
103
|
-
console.log(`DRYRUN: imports OK (improve=${typeof improve}, officialGepa=${typeof officialGepa}, runAgentic=${typeof runAgentic}, refine=${typeof refine})`)
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
const workerPricing = requiredTokenPricing(process.env, 'WORKER')
|
|
107
|
-
const optimizer = officialOptimizerModel({
|
|
108
|
-
env: process.env,
|
|
109
|
-
model: reflectModel,
|
|
110
|
-
baseUrl: reflectBase,
|
|
111
|
-
apiKey: reflectKey,
|
|
112
|
-
maxCostUsd: maxProposerCostUsd,
|
|
113
|
-
maxOutputTokensPerRequest: reflectMaxTokens,
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
const { environment, adapter } = await createSweBenchEnvironment(allIds.length, { ids: allIds, enableRun })
|
|
117
|
-
const pool = await adapter.loadTasks({ ids: allIds, split: 'test' })
|
|
118
|
-
const byId = new Map<string, BenchTask>(pool.map((t) => [t.id, t]))
|
|
119
|
-
for (const id of allIds) if (!byId.has(id)) throw new Error(`instance not found in Verified: ${id}`)
|
|
120
|
-
|
|
121
|
-
// The agent under improvement: run the LOCAL SWE env with the CANDIDATE prompt on
|
|
122
|
-
// one instance, return the git-diff patch. A per-call proxy captures the patch in
|
|
123
|
-
// score() BEFORE runAgentic closes (rm) the workspace; its score is a cheap
|
|
124
|
-
// patch-exists proxy so the ONLY Docker run per cell is the improve judge.
|
|
125
|
-
const agent = async (candidate: ReadonlyAgentProfile, scenario: Scenario, ctx: DispatchContext): Promise<string | null> => {
|
|
126
|
-
const exactCandidate = agentProfileSchema.parse(candidate)
|
|
127
|
-
const promptText = exactCandidate.prompt?.systemPrompt
|
|
128
|
-
if (promptText === undefined) throw new Error('agent: candidate profile has no system prompt')
|
|
129
|
-
const bt = byId.get(scenario.id)
|
|
130
|
-
if (!bt) throw new Error(`agent: unknown scenario ${scenario.id}`)
|
|
131
|
-
const task = { id: bt.id, userPrompt: bt.prompt, meta: { instanceId: bt.id } }
|
|
132
|
-
let capturedPatch = ''
|
|
133
|
-
const stats = { list: 0, read: 0, edit_ok: 0, edit_fail: 0, run: 0, run_err: 0 }
|
|
134
|
-
const proxy: AgenticSurface = {
|
|
135
|
-
...environment,
|
|
136
|
-
async call(handle, name, args) {
|
|
137
|
-
const res = await environment.call(handle, name, args)
|
|
138
|
-
const r = String(res)
|
|
139
|
-
if (name === 'list_files') stats.list += 1
|
|
140
|
-
else if (name === 'read_file') stats.read += 1
|
|
141
|
-
else if (name === 'edit_file') r.startsWith('edited ') ? (stats.edit_ok += 1) : (stats.edit_fail += 1)
|
|
142
|
-
else if (name === 'run') r.startsWith('ERROR:') ? (stats.run_err += 1) : (stats.run += 1)
|
|
143
|
-
return res
|
|
144
|
-
},
|
|
145
|
-
async score(_t, handle: ArtifactHandle): Promise<SurfaceScore> {
|
|
146
|
-
try {
|
|
147
|
-
const diff = await exec('git', ['-C', handle.id, 'diff'], { maxBuffer: 40_000_000, timeout: 60_000 })
|
|
148
|
-
if (!capturedPatch.trim() && diff.stdout.trim()) capturedPatch = diff.stdout
|
|
149
|
-
} catch {
|
|
150
|
-
/* workspace gone or git error → treat as no patch */
|
|
151
|
-
}
|
|
152
|
-
return { passes: capturedPatch.trim() ? 1 : 0, total: 1, errored: 0 }
|
|
153
|
-
},
|
|
154
|
-
}
|
|
155
|
-
const t0 = Date.now()
|
|
156
|
-
const paid = await ctx.cost.runPaidCall({
|
|
157
|
-
channel: 'agent',
|
|
158
|
-
actor: 'swe-worker',
|
|
159
|
-
model: workerModel,
|
|
160
|
-
execute: () =>
|
|
161
|
-
runAgentic({
|
|
162
|
-
surface: proxy,
|
|
163
|
-
task,
|
|
164
|
-
strategy: refine,
|
|
165
|
-
routerBaseUrl,
|
|
166
|
-
routerKey,
|
|
167
|
-
workerProfile: exactCandidate,
|
|
168
|
-
analystProfile,
|
|
169
|
-
budget: budgetShots,
|
|
170
|
-
}),
|
|
171
|
-
receipt: (result) => {
|
|
172
|
-
const inputTokens = result.tokens.input ?? 0
|
|
173
|
-
const outputTokens = result.tokens.output ?? 0
|
|
174
|
-
const usageUnknown = inputTokens === 0 && outputTokens === 0
|
|
175
|
-
return {
|
|
176
|
-
model: workerModel,
|
|
177
|
-
inputTokens,
|
|
178
|
-
outputTokens,
|
|
179
|
-
customTokenPricing: workerPricing,
|
|
180
|
-
...(usageUnknown ? { usageUnknown: true } : {}),
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
})
|
|
184
|
-
if (!paid.succeeded) throw paid.error
|
|
185
|
-
const r = paid.value
|
|
186
|
-
const zeroUsage = (r.tokens.input ?? 0) === 0 && (r.tokens.output ?? 0) === 0
|
|
187
|
-
const hasPatch = capturedPatch.trim().length > 0
|
|
188
|
-
const files = capturedPatch ? [...capturedPatch.matchAll(/^diff --git a\/(\S+)/gm)].map((m) => m[1]) : []
|
|
189
|
-
console.log(
|
|
190
|
-
` [agent] ${scenario.id} prompt=${promptText.length}c tools(l/r/e+/e-/run/run!)=${stats.list}/${stats.read}/${stats.edit_ok}/${stats.edit_fail}/${stats.run}/${stats.run_err} ` +
|
|
191
|
-
`patch=${capturedPatch.length}b files=[${files.join(', ') || 'none'}] tok=in:${r.tokens.input}/out:${r.tokens.output} ${Math.round((Date.now() - t0) / 1000)}s` +
|
|
192
|
-
`${zeroUsage ? ' [provider usage unavailable]' : ''}`,
|
|
193
|
-
)
|
|
194
|
-
// A cell with no patch produced NO artifact. Return null (not '') so the
|
|
195
|
-
// backend-integrity guard's own contract (`artifact == null → skip`) applies:
|
|
196
|
-
// a glm-4.6 empty-content turn is scored 0 like the baseline, instead of
|
|
197
|
-
// aborting the whole campaign as a false-positive "stub cell". Any cell that
|
|
198
|
-
// DOES produce a patch still returns it and must report real usage or fire.
|
|
199
|
-
return capturedPatch.trim() ? capturedPatch : null
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// The judge: the OFFICIAL swebench Docker harness. Deterministic FAIL_TO_PASS +
|
|
203
|
-
// PASS_TO_PASS → resolved 0/1. This is the held-out gate's scoring axis.
|
|
204
|
-
const judge: JudgeConfig<string | null, Scenario> = {
|
|
205
|
-
name: 'swebench-docker',
|
|
206
|
-
dimensions: [{ key: 'resolved', description: 'FAIL_TO_PASS + PASS_TO_PASS resolved by the official swebench Docker harness' }],
|
|
207
|
-
async score({ artifact, scenario }) {
|
|
208
|
-
const patch = String(artifact ?? '')
|
|
209
|
-
if (!patch.trim()) {
|
|
210
|
-
console.log(` [judge] ${scenario.id} resolved=0 (no patch)`)
|
|
211
|
-
return { dimensions: { resolved: 0 }, composite: 0, notes: 'no patch emitted' }
|
|
212
|
-
}
|
|
213
|
-
const bt = byId.get(scenario.id)
|
|
214
|
-
if (!bt) throw new Error(`judge: unknown scenario ${scenario.id}`)
|
|
215
|
-
const s = await adapter.judge(bt, patch)
|
|
216
|
-
console.log(` [judge] ${scenario.id} resolved=${s.resolved ? 1 : 0}`)
|
|
217
|
-
// 1500 chars keeps the whole swebench report JSON (a flat summary object —
|
|
218
|
-
// it has no separate failure section to extract); the old 200 clipped it to
|
|
219
|
-
// an uninformative head, leaving GEPA reflection trace-blind.
|
|
220
|
-
return { dimensions: { resolved: s.resolved ? 1 : 0 }, composite: s.resolved ? 1 : 0, notes: (s.detail ?? '').slice(0, 1500) }
|
|
221
|
-
},
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const scenario = (id: string): Scenario => ({ id, kind: 'swe-bench-verified' })
|
|
225
|
-
|
|
226
|
-
const out = await improve(workerProfile, {
|
|
227
|
-
surface: 'prompt',
|
|
228
|
-
executionRef: canonicalCandidateDigest({
|
|
229
|
-
callback: 'bench/swe-improve',
|
|
230
|
-
model: workerModel,
|
|
231
|
-
endpoint: new URL(routerBaseUrl).origin,
|
|
232
|
-
innerTurns,
|
|
233
|
-
maxTokens: workerMaxTokens,
|
|
234
|
-
budgetShots,
|
|
235
|
-
enableRun,
|
|
236
|
-
}),
|
|
237
|
-
method: officialGepa<Scenario, string | null>({
|
|
238
|
-
objective:
|
|
239
|
-
'Improve the system prompt of a coding agent that fixes real GitHub bugs with list_files, read_file, edit_file, and optional run tools.',
|
|
240
|
-
background:
|
|
241
|
-
'Return the complete system prompt. Preserve tool names and require evidence from repository files and tests.',
|
|
242
|
-
recipe: {
|
|
243
|
-
kind: 'engine',
|
|
244
|
-
run: {
|
|
245
|
-
engine: 'gepa',
|
|
246
|
-
maxEvaluations,
|
|
247
|
-
maxProposerCostUsd,
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
optimizer,
|
|
251
|
-
resume: 'if-compatible',
|
|
252
|
-
trustResumeState: true,
|
|
253
|
-
describeScenario: (item) => ({ prompt: byId.get(item.id)?.prompt ?? item.id }),
|
|
254
|
-
}),
|
|
255
|
-
trainScenarios: trainIds.map(scenario),
|
|
256
|
-
selectionScenarios: selectionIds.map(scenario),
|
|
257
|
-
testScenarios: testIds.map(scenario),
|
|
258
|
-
judges: [judge],
|
|
259
|
-
agent,
|
|
260
|
-
expectUsage: 'warn',
|
|
261
|
-
maxConcurrency,
|
|
262
|
-
reps: 1,
|
|
263
|
-
runDir,
|
|
264
|
-
optimizationRunOptions: {
|
|
265
|
-
expectUsage: 'warn',
|
|
266
|
-
maxConcurrency,
|
|
267
|
-
reps: 1,
|
|
268
|
-
},
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
assertCompleteCost('SWE-bench official GEPA run', out.cost)
|
|
272
|
-
console.log('\n=== RESULT ===')
|
|
273
|
-
console.log(`decision=${out.decision} lift=${out.lift} interval=[${out.liftInterval.low}, ${out.liftInterval.high}]`)
|
|
274
|
-
console.log(`baseline test composite=${out.raw.best.baselineComposite}`)
|
|
275
|
-
console.log(`winner test composite=${out.raw.best.winnerComposite}`)
|
|
276
|
-
console.log(`test scenarios=${JSON.stringify(out.raw.best.scenarioScores)}`)
|
|
277
|
-
console.log(`cost=${JSON.stringify(out.cost)}`)
|
|
278
|
-
console.log(`candidate prompt:\n${String(out.candidate.value).slice(0, 2000)}`)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
main().catch((e) => {
|
|
282
|
-
console.error(e instanceof Error ? (e.stack ?? e.message) : String(e))
|
|
283
|
-
process.exit(1)
|
|
284
|
-
})
|