@tangle-network/agent-bench 0.14.2 → 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 +10 -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
package/src/worker-cad.ts
DELETED
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CAD sandbox worker: one shot = a fresh 'universal' Tangle sandbox where a
|
|
3
|
-
* coding agent authors OpenSCAD source for the task's brief. The sandbox's OWN
|
|
4
|
-
* Nix-profile toolchain is the gate — `openscad` compiles + exports the STL and
|
|
5
|
-
* renders a PNG inside the box; we read both back. The artifact (the `.scad`) is
|
|
6
|
-
* scored by the cad-design judge; the produced trace (brief → code → compile →
|
|
7
|
-
* render screenshot) drives run-capsule's conversation/code/terminal/screen
|
|
8
|
-
* capsules.
|
|
9
|
-
*
|
|
10
|
-
* This is the "full rounded run": real sandbox, the real CAD kernel as the
|
|
11
|
-
* verifiable reward, real geometry, and a screenshot-rich trace for the video.
|
|
12
|
-
* Requires `openscad` + `xvfb-run` in the sandbox profile (universal has both).
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { execFile } from 'node:child_process'
|
|
16
|
-
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
17
|
-
import { tmpdir } from 'node:os'
|
|
18
|
-
import { join } from 'node:path'
|
|
19
|
-
import { promisify } from 'node:util'
|
|
20
|
-
import { acquireSandbox } from '@tangle-network/agent-runtime/kernel'
|
|
21
|
-
import { Sandbox } from '@tangle-network/sandbox'
|
|
22
|
-
import type { Span } from '@tangle-network/agent-eval'
|
|
23
|
-
import type { BenchTask } from './benchmarks/types'
|
|
24
|
-
import { DEFAULT_CAD_DIRECTIVE, DEFAULT_CAD_SANDBOX_DIRECTIVE } from './directives'
|
|
25
|
-
import { runRefineLoop } from './refine-loop'
|
|
26
|
-
import { runBenchRouterTurn } from './router-turn'
|
|
27
|
-
|
|
28
|
-
export { DEFAULT_CAD_DIRECTIVE } from './directives'
|
|
29
|
-
|
|
30
|
-
export interface CadWorkerConfig {
|
|
31
|
-
sandboxBaseUrl: string
|
|
32
|
-
sandboxKey: string
|
|
33
|
-
routerBaseUrl: string
|
|
34
|
-
routerKey: string
|
|
35
|
-
model: string
|
|
36
|
-
provider?: string
|
|
37
|
-
timeoutMs?: number
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface CadShotResult {
|
|
41
|
-
/** The OpenSCAD source the agent wrote — the artifact the judge scores. */
|
|
42
|
-
artifact: string
|
|
43
|
-
/** Trace of the run for run-capsule: brief → code → compile → render. */
|
|
44
|
-
trace: Span[]
|
|
45
|
-
ok: boolean
|
|
46
|
-
detail?: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const SCAD_PATH = '/work/model.scad'
|
|
50
|
-
const STL_PATH = '/work/model.stl'
|
|
51
|
-
const PNG_PATH = '/work/model.png'
|
|
52
|
-
|
|
53
|
-
/** The acquired sandbox instance — the per-task execution Ctx for solveCadRefine. */
|
|
54
|
-
type SandboxBox = Awaited<ReturnType<typeof acquireSandbox>>
|
|
55
|
-
|
|
56
|
-
const randomSuffix = () => Math.random().toString(36).slice(2, 10)
|
|
57
|
-
|
|
58
|
-
/** Strip markdown fences / prose so we keep just the OpenSCAD source. */
|
|
59
|
-
function extractScad(text: string): string {
|
|
60
|
-
const fence = /```(?:openscad|scad|c|cpp)?\s*\n([\s\S]*?)```/i.exec(text)
|
|
61
|
-
return (fence ? fence[1] : text).trim()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const execFileAsync = promisify(execFile)
|
|
65
|
-
|
|
66
|
-
/** Run a local command, returning exit code + streams (never throws on nonzero —
|
|
67
|
-
* the geometry gate is the arbiter, so a failed compile still yields its error). */
|
|
68
|
-
async function runLocal(
|
|
69
|
-
cmd: string,
|
|
70
|
-
args: string[],
|
|
71
|
-
cwd: string,
|
|
72
|
-
): Promise<{ code: number; stdout: string; stderr: string }> {
|
|
73
|
-
try {
|
|
74
|
-
const { stdout, stderr } = await execFileAsync(cmd, args, { cwd, maxBuffer: 1 << 26, timeout: 120_000 })
|
|
75
|
-
return { code: 0, stdout, stderr }
|
|
76
|
-
} catch (err) {
|
|
77
|
-
const e = err as { code?: number; stdout?: string; stderr?: string; message?: string }
|
|
78
|
-
return { code: e.code ?? 1, stdout: e.stdout ?? '', stderr: e.stderr ?? e.message ?? String(err) }
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface CadLocalConfig {
|
|
83
|
-
routerBaseUrl: string
|
|
84
|
-
routerKey: string
|
|
85
|
-
model: string
|
|
86
|
-
rounds?: number
|
|
87
|
-
/** The authoring directive (system prompt) — the GEPA-optimizable surface. */
|
|
88
|
-
directive?: string
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface CadLocalShot {
|
|
92
|
-
/** Final OpenSCAD source — the artifact the judge scores. */
|
|
93
|
-
artifact: string
|
|
94
|
-
/** First-round source (the blind shot, before any refine). */
|
|
95
|
-
round1Artifact: string
|
|
96
|
-
trace: Span[]
|
|
97
|
-
/** Per-compiling-round render PNGs as data URIs (run-capsule reveal/orbit). */
|
|
98
|
-
renders: string[]
|
|
99
|
-
usage: { input: number; output: number }
|
|
100
|
-
ok: boolean
|
|
101
|
-
detail?: string
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* LOCAL CAD refine loop — the staging-independent twin of `solveCadRefine`. The
|
|
106
|
-
* model authors the `.scad` via the router under `directive`, the LOCAL openscad
|
|
107
|
-
* kernel (`xvfb-run -a openscad`) gates + renders each round, and compiler
|
|
108
|
-
* feedback drives the next round. Returns the final source, per-round renders, a
|
|
109
|
-
* screenshot-rich trace, and REAL token usage. This is the seam the GEPA loop
|
|
110
|
-
* drives: `directive` is the surface, the deterministic geometry gate is the reward.
|
|
111
|
-
*/
|
|
112
|
-
export async function solveCadRefineLocal(task: BenchTask, cfg: CadLocalConfig): Promise<CadLocalShot> {
|
|
113
|
-
const rounds = Math.max(1, cfg.rounds ?? 3)
|
|
114
|
-
const directive = cfg.directive ?? DEFAULT_CAD_DIRECTIVE
|
|
115
|
-
const trace: Span[] = []
|
|
116
|
-
const renders: string[] = []
|
|
117
|
-
const runId = `cad-${task.id}`
|
|
118
|
-
let ts = Date.now()
|
|
119
|
-
const tick = () => (ts += 1)
|
|
120
|
-
const usage = { input: 0, output: 0 }
|
|
121
|
-
// Carried across rounds in closures (the round Artifact is the .scad source; the
|
|
122
|
-
// lastErr steer + resolved early-stop persist outside the loop). usage is REAL.
|
|
123
|
-
let lastErr = ''
|
|
124
|
-
let resolved = false
|
|
125
|
-
|
|
126
|
-
trace.push({ spanId: 's-brief', runId, kind: 'llm', name: 'brief', model: cfg.model, messages: [{ role: 'user', content: task.prompt }], startedAt: tick(), endedAt: tick(), status: 'ok' } as Span)
|
|
127
|
-
|
|
128
|
-
// Migrated onto runRefineLoop: the mkdtemp dir is the Ctx; resolved (compiles AND
|
|
129
|
-
// has geometry) is the early-stop, modeled as a judge so default-decide stops the
|
|
130
|
-
// loop. The round-2+ steer carries lastErr + the prior source verbatim.
|
|
131
|
-
const res = await runRefineLoop<string, string>({
|
|
132
|
-
rounds,
|
|
133
|
-
setup: () => mkdtemp(join(tmpdir(), 'cad-local-')),
|
|
134
|
-
prompt: (round, history) =>
|
|
135
|
-
round === 1
|
|
136
|
-
? task.prompt
|
|
137
|
-
: `Your previous OpenSCAD had this problem:\n${lastErr}\n\nHere is the previous source:\n${history[history.length - 1]?.artifact ?? ''}\n\nFix it so it compiles AND better matches the brief:\n${task.prompt}`,
|
|
138
|
-
runShot: async (user, round, dir) => {
|
|
139
|
-
const scadPath = join(dir, 'model.scad')
|
|
140
|
-
const stlPath = join(dir, 'model.stl')
|
|
141
|
-
const pngPath = join(dir, 'model.png')
|
|
142
|
-
const turn = await runBenchRouterTurn(
|
|
143
|
-
{
|
|
144
|
-
routerBaseUrl: cfg.routerBaseUrl,
|
|
145
|
-
routerKey: cfg.routerKey,
|
|
146
|
-
profile: {
|
|
147
|
-
name: 'cad-local-worker',
|
|
148
|
-
model: { provider: 'tangle-router', default: cfg.model },
|
|
149
|
-
prompt: { systemPrompt: directive },
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
user,
|
|
153
|
-
)
|
|
154
|
-
const content = turn.finalText
|
|
155
|
-
if (turn.usage.tokensKnown !== false) {
|
|
156
|
-
usage.input += turn.usage.input
|
|
157
|
-
usage.output += turn.usage.output
|
|
158
|
-
}
|
|
159
|
-
const scad = extractScad(content)
|
|
160
|
-
trace.push({ spanId: `s-reply-${round}`, runId, kind: 'llm', name: `author r${round}`, model: cfg.model, messages: [{ role: 'user', content: round === 1 ? task.prompt : 'refine' }], output: content.slice(0, 600), startedAt: tick(), endedAt: tick(), status: 'ok' } as Span)
|
|
161
|
-
trace.push({ spanId: `s-write-${round}`, runId, kind: 'tool', name: 'write_file', toolName: 'create_file', args: { path: 'model.scad', content: scad }, startedAt: tick(), endedAt: tick(), status: 'ok' } as Span)
|
|
162
|
-
|
|
163
|
-
await writeFile(scadPath, scad)
|
|
164
|
-
const compile = await runLocal('xvfb-run', ['-a', 'openscad', '-o', stlPath, scadPath], dir)
|
|
165
|
-
const compileOk = compile.code === 0
|
|
166
|
-
lastErr = compileOk ? '' : `${compile.stdout}\n${compile.stderr}`.trim().slice(0, 800)
|
|
167
|
-
trace.push({ spanId: `s-compile-${round}`, runId, kind: 'tool', name: `openscad r${round}`, toolName: 'shell.exec', args: 'openscad -o model.stl model.scad', result: (compileOk ? compile.stderr : lastErr).slice(0, 1500) || 'ok', startedAt: tick(), endedAt: tick(), status: compileOk ? 'ok' : 'error', error: compileOk ? undefined : `exit ${compile.code}` } as Span)
|
|
168
|
-
|
|
169
|
-
let screenshot: string | undefined
|
|
170
|
-
if (compileOk) {
|
|
171
|
-
// Full CGAL --render (not preview): clean coplanar faces, no z-fighting
|
|
172
|
-
// speckle on the window/door cutouts. Dark Tomorrow-Night palette to match
|
|
173
|
-
// the film; --autocenter --viewall frames any model regardless of its
|
|
174
|
-
// dimensions (so the same command flatters every task in the set).
|
|
175
|
-
const render = await runLocal('xvfb-run', ['-a', 'openscad', '-o', pngPath, '--render', '--imgsize=1280,960', '--colorscheme=Tomorrow Night', '--projection=perspective', '--autocenter', '--viewall', '--camera=0,0,0,60,0,25,0', scadPath], dir)
|
|
176
|
-
if (render.code === 0) {
|
|
177
|
-
const buf = await readFile(pngPath).catch(() => undefined)
|
|
178
|
-
if (buf) {
|
|
179
|
-
screenshot = `data:image/png;base64,${buf.toString('base64')}`
|
|
180
|
-
renders.push(screenshot)
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const stl = await readFile(stlPath, 'utf8').catch(() => '')
|
|
184
|
-
resolved = stl.length > 0 && /facet normal/.test(stl)
|
|
185
|
-
}
|
|
186
|
-
trace.push({ spanId: `s-render-${round}`, runId, kind: 'tool', name: `render r${round}`, toolName: 'render.screenshot', args: { action: `rendered round ${round}`, url: 'model.png' }, attributes: screenshot ? { screenshot } : {}, startedAt: tick(), endedAt: tick(), status: screenshot ? 'ok' : 'error', error: screenshot ? undefined : (compileOk ? 'render produced no image' : 'skipped — did not compile') } as Span)
|
|
187
|
-
return { artifact: scad }
|
|
188
|
-
},
|
|
189
|
-
judge: async () => ({ valid: resolved }),
|
|
190
|
-
teardown: (dir) => rm(dir, { recursive: true, force: true }).then(() => {}, () => {}),
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
artifact: res.final.artifact,
|
|
195
|
-
round1Artifact: res.blind.artifact,
|
|
196
|
-
trace,
|
|
197
|
-
renders,
|
|
198
|
-
usage,
|
|
199
|
-
ok: res.final.artifact.trim().length > 0,
|
|
200
|
-
detail: resolved ? `compiled in ≤${rounds} rounds` : `did not compile cleanly in ${rounds} rounds${lastErr ? `; last: ${lastErr.slice(0, 120)}` : ''}`,
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export interface CadRefineConfig extends CadWorkerConfig {
|
|
205
|
-
/** Max author→gate→refine rounds. Default 3. */
|
|
206
|
-
rounds?: number
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Orchestrated CAD refine loop: a BARE universal sandbox is the CAD compute +
|
|
211
|
-
* render environment (reliable to provision); the model authors the `.scad` via
|
|
212
|
-
* the router, the box's own openscad gates + renders each round, and the
|
|
213
|
-
* compiler/geometry feedback drives the next round until it passes or rounds run
|
|
214
|
-
* out. This is the "design in a loop" path — every round's render is captured,
|
|
215
|
-
* so the trace shows the model improving the house across attempts.
|
|
216
|
-
*/
|
|
217
|
-
export async function solveCadRefine(task: BenchTask, cfg: CadRefineConfig): Promise<CadShotResult> {
|
|
218
|
-
const rounds = cfg.rounds ?? 3
|
|
219
|
-
const client = new Sandbox({ baseUrl: cfg.sandboxBaseUrl, apiKey: cfg.sandboxKey })
|
|
220
|
-
const t0 = Date.now()
|
|
221
|
-
const trace: Span[] = []
|
|
222
|
-
const runId = `cad-${task.id}`
|
|
223
|
-
let ts = t0
|
|
224
|
-
const tick = () => (ts += 1)
|
|
225
|
-
// The authoring system prompt for the orchestrated sandbox path — kept verbatim,
|
|
226
|
-
// distinct from DEFAULT_CAD_DIRECTIVE (the local path's GEPA surface).
|
|
227
|
-
const sys = DEFAULT_CAD_SANDBOX_DIRECTIVE
|
|
228
|
-
// Carried across rounds in closures (the round Artifact is the .scad source; the
|
|
229
|
-
// lastErr steer + resolved early-stop persist outside the loop).
|
|
230
|
-
let lastErr = ''
|
|
231
|
-
let resolved = false
|
|
232
|
-
|
|
233
|
-
// Migrated onto runRefineLoop: the universal sandbox box is the Ctx (acquired once,
|
|
234
|
-
// /work created in setup, torn down in teardown). resolved (compiles AND has
|
|
235
|
-
// geometry) is the early-stop, modeled as a judge so default-decide stops the loop.
|
|
236
|
-
// The round-2+ steer carries lastErr + the prior source verbatim.
|
|
237
|
-
const res = await runRefineLoop<string, SandboxBox>({
|
|
238
|
-
rounds,
|
|
239
|
-
setup: async () => {
|
|
240
|
-
const box = await acquireSandbox(client, {
|
|
241
|
-
name: `cad-${task.id}-${randomSuffix()}`.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 60),
|
|
242
|
-
environment: 'universal',
|
|
243
|
-
})
|
|
244
|
-
// If init fails AFTER acquire, reap the box here — setup throwing before it
|
|
245
|
-
// returns the Ctx means runRefineLoop's teardown never runs, so an unguarded
|
|
246
|
-
// mkdir failure would leak the sandbox (the pre-migration finally deleted it).
|
|
247
|
-
try {
|
|
248
|
-
await box.exec('mkdir -p /work', { timeoutMs: 30_000 })
|
|
249
|
-
// The brief frames the title card (understood_task).
|
|
250
|
-
trace.push({ spanId: 's-brief', runId, kind: 'llm', name: 'brief', model: cfg.model, messages: [{ role: 'user', content: task.prompt }], startedAt: tick(), endedAt: tick(), status: 'ok' } as Span)
|
|
251
|
-
return box
|
|
252
|
-
} catch (err) {
|
|
253
|
-
try {
|
|
254
|
-
await box.delete?.()
|
|
255
|
-
} catch {
|
|
256
|
-
// platform reaps on expiry
|
|
257
|
-
}
|
|
258
|
-
throw err
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
prompt: (round, history) =>
|
|
262
|
-
round === 1
|
|
263
|
-
? task.prompt
|
|
264
|
-
: `Your previous OpenSCAD had this problem:\n${lastErr}\n\nHere is the previous source:\n${history[history.length - 1]?.artifact ?? ''}\n\nFix it so it compiles AND better matches the brief:\n${task.prompt}`,
|
|
265
|
-
runShot: async (user, round, box) => {
|
|
266
|
-
const turn = await runBenchRouterTurn(
|
|
267
|
-
{
|
|
268
|
-
routerBaseUrl: cfg.routerBaseUrl,
|
|
269
|
-
routerKey: cfg.routerKey,
|
|
270
|
-
profile: {
|
|
271
|
-
name: 'cad-sandbox-worker',
|
|
272
|
-
model: { provider: 'tangle-router', default: cfg.model },
|
|
273
|
-
prompt: { systemPrompt: sys },
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
user,
|
|
277
|
-
)
|
|
278
|
-
const reply = turn.finalText
|
|
279
|
-
const scad = extractScad(reply)
|
|
280
|
-
trace.push({ spanId: `s-reply-${round}`, runId, kind: 'llm', name: `author r${round}`, model: cfg.model, messages: [{ role: 'user', content: round === 1 ? task.prompt : 'refine' }], output: reply.slice(0, 600), startedAt: tick(), endedAt: tick(), status: 'ok' } as Span)
|
|
281
|
-
trace.push({ spanId: `s-write-${round}`, runId, kind: 'tool', name: 'write_file', toolName: 'create_file', args: { path: 'model.scad', content: scad }, startedAt: tick(), endedAt: tick(), status: 'ok' } as Span)
|
|
282
|
-
|
|
283
|
-
await box.fs.write(SCAD_PATH, scad)
|
|
284
|
-
const compile = await box.exec(`xvfb-run -a openscad -o ${STL_PATH} ${SCAD_PATH}`, { timeoutMs: 120_000 })
|
|
285
|
-
const compileOk = compile.exitCode === 0
|
|
286
|
-
lastErr = compileOk ? '' : `${compile.stdout}\n${compile.stderr}`.trim().slice(0, 800)
|
|
287
|
-
trace.push({ spanId: `s-compile-${round}`, runId, kind: 'tool', name: `openscad r${round}`, toolName: 'shell.exec', args: 'openscad -o model.stl model.scad', result: (compileOk ? compile.stderr : lastErr).slice(0, 1500) || 'ok', startedAt: tick(), endedAt: tick(), status: compileOk ? 'ok' : 'error', error: compileOk ? undefined : `exit ${compile.exitCode}` } as Span)
|
|
288
|
-
|
|
289
|
-
let screenshot: string | undefined
|
|
290
|
-
if (compileOk) {
|
|
291
|
-
const render = await box.exec(`xvfb-run -a openscad -o ${PNG_PATH} --imgsize=1100,850 --camera=40,30,40,55,0,25,260 --colorscheme=Tomorrow ${SCAD_PATH}`, { timeoutMs: 120_000 })
|
|
292
|
-
if (render.exitCode === 0) {
|
|
293
|
-
const localPng = join(tmpdir(), `cad-${task.id}-r${round}-${randomSuffix()}.png`)
|
|
294
|
-
await box.fs.download(PNG_PATH, localPng).catch(() => undefined)
|
|
295
|
-
const buf = await readFile(localPng).catch(() => undefined)
|
|
296
|
-
if (buf) screenshot = `data:image/png;base64,${buf.toString('base64')}`
|
|
297
|
-
}
|
|
298
|
-
// Geometry gate: read STL back + check it's non-trivial (the adapter judge
|
|
299
|
-
// does the full spec scoring; here we just decide whether to stop refining).
|
|
300
|
-
const stl = await box.fs.read(STL_PATH).catch(() => '')
|
|
301
|
-
resolved = stl.length > 0 && /facet normal/.test(stl)
|
|
302
|
-
}
|
|
303
|
-
trace.push({ spanId: `s-render-${round}`, runId, kind: 'tool', name: `render r${round}`, toolName: 'render.screenshot', args: { action: `rendered round ${round}`, url: 'model.png' }, attributes: screenshot ? { screenshot } : {}, startedAt: tick(), endedAt: tick(), status: screenshot ? 'ok' : 'error', error: screenshot ? undefined : (compileOk ? 'render produced no image' : 'skipped — did not compile') } as Span)
|
|
304
|
-
return { artifact: scad }
|
|
305
|
-
},
|
|
306
|
-
judge: async () => ({ valid: resolved }),
|
|
307
|
-
teardown: async (box) => {
|
|
308
|
-
try {
|
|
309
|
-
await box.delete()
|
|
310
|
-
} catch {
|
|
311
|
-
// staging reaps on expiry
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
const artifact = res.final.artifact
|
|
317
|
-
return { artifact, trace, ok: artifact.trim().length > 0, detail: resolved ? `resolved in ≤${rounds} rounds` : `did not fully resolve in ${rounds} rounds${lastErr ? `; last: ${lastErr.slice(0, 120)}` : ''}` }
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/** Run one CAD authoring shot in a real sandbox, gating with the box's own
|
|
321
|
-
* openscad and capturing a screenshot-rich trace. */
|
|
322
|
-
export async function solveCadShot(task: BenchTask, cfg: CadWorkerConfig): Promise<CadShotResult> {
|
|
323
|
-
const client = new Sandbox({ baseUrl: cfg.sandboxBaseUrl, apiKey: cfg.sandboxKey })
|
|
324
|
-
const box = await acquireSandbox(client, {
|
|
325
|
-
name: `cad-${task.id}-${randomSuffix()}`.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 60),
|
|
326
|
-
environment: 'universal',
|
|
327
|
-
backend: {
|
|
328
|
-
type: 'opencode',
|
|
329
|
-
// provider/model/baseUrl pinning only — in-box model auth is the box-provisioned
|
|
330
|
-
// OPENCODE_MODEL_API_KEY (foreign keys are 403'd at egress).
|
|
331
|
-
model: {
|
|
332
|
-
provider: cfg.provider ?? 'openai',
|
|
333
|
-
model: cfg.model,
|
|
334
|
-
baseUrl: cfg.routerBaseUrl,
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
const t0 = Date.now()
|
|
340
|
-
const trace: Span[] = []
|
|
341
|
-
const runId = `cad-${task.id}`
|
|
342
|
-
|
|
343
|
-
try {
|
|
344
|
-
const prompt = [
|
|
345
|
-
task.prompt,
|
|
346
|
-
'',
|
|
347
|
-
`Write the OpenSCAD source to ${SCAD_PATH} (create the /work directory if needed).`,
|
|
348
|
-
`Then verify it compiles by running: xvfb-run -a openscad -o ${STL_PATH} ${SCAD_PATH}`,
|
|
349
|
-
`Fix any errors until it compiles cleanly and the geometry matches the brief. Then stop.`,
|
|
350
|
-
`The file at ${SCAD_PATH} is the deliverable.`,
|
|
351
|
-
].join('\n')
|
|
352
|
-
|
|
353
|
-
// Conversation: the brief (understood_task) + the agent's reply.
|
|
354
|
-
trace.push({
|
|
355
|
-
spanId: 's-brief',
|
|
356
|
-
runId,
|
|
357
|
-
kind: 'llm',
|
|
358
|
-
name: 'brief',
|
|
359
|
-
model: cfg.model,
|
|
360
|
-
messages: [{ role: 'user', content: task.prompt }],
|
|
361
|
-
startedAt: t0,
|
|
362
|
-
endedAt: t0,
|
|
363
|
-
status: 'ok',
|
|
364
|
-
} as Span)
|
|
365
|
-
|
|
366
|
-
const signal = cfg.timeoutMs ? AbortSignal.timeout(cfg.timeoutMs) : undefined
|
|
367
|
-
let lastErr: string | undefined
|
|
368
|
-
let agentText = ''
|
|
369
|
-
for await (const ev of box.streamPrompt(prompt, signal ? { signal } : {})) {
|
|
370
|
-
if (ev?.type === 'error') lastErr = JSON.stringify(ev.data).slice(0, 300)
|
|
371
|
-
const text = typeof (ev as { text?: unknown })?.text === 'string' ? (ev as unknown as { text: string }).text : ''
|
|
372
|
-
if (text) agentText += text
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const artifact = await box.fs.read(SCAD_PATH).catch(() => '')
|
|
376
|
-
if (artifact.trim()) {
|
|
377
|
-
trace.push({
|
|
378
|
-
spanId: 's-write',
|
|
379
|
-
runId,
|
|
380
|
-
kind: 'tool',
|
|
381
|
-
name: 'write_file',
|
|
382
|
-
toolName: 'create_file',
|
|
383
|
-
args: { path: 'model.scad', content: artifact },
|
|
384
|
-
startedAt: t0 + 1,
|
|
385
|
-
endedAt: t0 + 2,
|
|
386
|
-
status: 'ok',
|
|
387
|
-
} as Span)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// GATE + RENDER in the sandbox itself (the box's own openscad/xvfb).
|
|
391
|
-
const compile = await box.exec(`xvfb-run -a openscad -o ${STL_PATH} ${SCAD_PATH}`, {
|
|
392
|
-
timeoutMs: 120_000,
|
|
393
|
-
})
|
|
394
|
-
trace.push({
|
|
395
|
-
spanId: 's-compile',
|
|
396
|
-
runId,
|
|
397
|
-
kind: 'tool',
|
|
398
|
-
name: 'openscad compile',
|
|
399
|
-
toolName: 'shell.exec',
|
|
400
|
-
args: `openscad -o model.stl model.scad`,
|
|
401
|
-
result: `${compile.stdout}\n${compile.stderr}`.trim().slice(0, 2000),
|
|
402
|
-
startedAt: t0 + 3,
|
|
403
|
-
endedAt: t0 + 4,
|
|
404
|
-
status: compile.exitCode === 0 ? 'ok' : 'error',
|
|
405
|
-
error: compile.exitCode === 0 ? undefined : `openscad exit ${compile.exitCode}`,
|
|
406
|
-
} as Span)
|
|
407
|
-
|
|
408
|
-
let screenshot: string | undefined
|
|
409
|
-
if (compile.exitCode === 0) {
|
|
410
|
-
const render = await box.exec(
|
|
411
|
-
`xvfb-run -a openscad -o ${PNG_PATH} --imgsize=1100,850 --camera=40,30,40,55,0,25,260 --colorscheme=Tomorrow ${SCAD_PATH}`,
|
|
412
|
-
{ timeoutMs: 120_000 },
|
|
413
|
-
)
|
|
414
|
-
if (render.exitCode === 0) {
|
|
415
|
-
const localPng = join(tmpdir(), `cad-${task.id}-${randomSuffix()}.png`)
|
|
416
|
-
await box.fs.download(PNG_PATH, localPng).catch(() => undefined)
|
|
417
|
-
const buf = await readFile(localPng).catch(() => undefined)
|
|
418
|
-
if (buf) screenshot = `data:image/png;base64,${buf.toString('base64')}`
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
// Screen span carrying the render — drives run-capsule's screen capsule.
|
|
422
|
-
trace.push({
|
|
423
|
-
spanId: 's-render',
|
|
424
|
-
runId,
|
|
425
|
-
kind: 'tool',
|
|
426
|
-
name: 'render',
|
|
427
|
-
toolName: 'render.screenshot',
|
|
428
|
-
args: { action: 'rendered model.scad', url: 'model.png' },
|
|
429
|
-
attributes: screenshot ? { screenshot } : {},
|
|
430
|
-
startedAt: t0 + 5,
|
|
431
|
-
endedAt: t0 + 6,
|
|
432
|
-
status: screenshot ? 'ok' : 'error',
|
|
433
|
-
error: screenshot ? undefined : 'render produced no image',
|
|
434
|
-
} as Span)
|
|
435
|
-
|
|
436
|
-
// Agent's closing reply (conversation capsule).
|
|
437
|
-
if (agentText.trim()) {
|
|
438
|
-
trace.push({
|
|
439
|
-
spanId: 's-reply',
|
|
440
|
-
runId,
|
|
441
|
-
kind: 'llm',
|
|
442
|
-
name: 'reply',
|
|
443
|
-
model: cfg.model,
|
|
444
|
-
messages: [{ role: 'user', content: task.prompt }],
|
|
445
|
-
output: agentText.trim().slice(0, 600),
|
|
446
|
-
startedAt: t0 + 7,
|
|
447
|
-
endedAt: t0 + 8,
|
|
448
|
-
status: 'ok',
|
|
449
|
-
} as Span)
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return {
|
|
453
|
-
artifact,
|
|
454
|
-
trace,
|
|
455
|
-
ok: artifact.trim().length > 0 && compile.exitCode === 0,
|
|
456
|
-
detail:
|
|
457
|
-
artifact.trim().length === 0
|
|
458
|
-
? `no .scad written${lastErr ? `; lastError=${lastErr}` : ''}`
|
|
459
|
-
: compile.exitCode === 0
|
|
460
|
-
? undefined
|
|
461
|
-
: `compiled with exit ${compile.exitCode}`,
|
|
462
|
-
}
|
|
463
|
-
} finally {
|
|
464
|
-
try {
|
|
465
|
-
await box.delete()
|
|
466
|
-
} catch {
|
|
467
|
-
/* staging reaps on expiry */
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
package/src/workspace-loop.mts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The decisive de-risk: does a git-backed shared workspace make accumulating,
|
|
3
|
-
* resumable, multi-worker loops REAL on a share-nothing substrate?
|
|
4
|
-
*
|
|
5
|
-
* The red-team's fatal finding: each cloud worker is a fresh box with no shared
|
|
6
|
-
* filesystem, so "worker N+1 builds on worker N's code" is impossible and resume
|
|
7
|
-
* restores decisions, not the mutated workspace. The proposed fix: a git-backed
|
|
8
|
-
* contract. This proves or kills it on 3 dependency-ordered modules (a←b←c).
|
|
9
|
-
*
|
|
10
|
-
* - The DURABLE WORKSPACE = a bare git repo (models a GitHub branch in cloud).
|
|
11
|
-
* - Each WORKER = a FRESH temp clone (models a fresh box's empty FS), torn down
|
|
12
|
-
* after it commits+pushes. State survives ONLY because git persisted it.
|
|
13
|
-
* - THE PROOF: a worker asserts its dependency's file is on disk in its fresh
|
|
14
|
-
* clone. Fails on share-nothing (names-in-a-string); passes on the git seam.
|
|
15
|
-
*
|
|
16
|
-
* Test (a) — does it link? full run → integration test imports a←b←c, must pass.
|
|
17
|
-
* Test (b) — resume? KILL_AFTER=b, then RESUME=1: c clones a repo that
|
|
18
|
-
* HAS a+b committed (durable), re-runs ONLY c, links.
|
|
19
|
-
*
|
|
20
|
-
* pnpm exec tsx src/workspace-loop.mts # (a) happy path
|
|
21
|
-
* KILL_AFTER=b pnpm exec tsx src/workspace-loop.mts # die after b
|
|
22
|
-
* RESUME=1 pnpm exec tsx src/workspace-loop.mts # (b) resume → finish c
|
|
23
|
-
*/
|
|
24
|
-
import { execFileSync } from 'node:child_process'
|
|
25
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
26
|
-
import { appendFileSync } from 'node:fs'
|
|
27
|
-
import { tmpdir } from 'node:os'
|
|
28
|
-
import { join } from 'node:path'
|
|
29
|
-
|
|
30
|
-
const BARE = '/tmp/workspace-loop.git' // the durable shared workspace (≈ a remote branch)
|
|
31
|
-
const JOURNAL = '/tmp/workspace-loop.journal' // the decision record (which modules are committed)
|
|
32
|
-
|
|
33
|
-
const sh = (cmd: string, args: string[], cwd?: string): string =>
|
|
34
|
-
execFileSync(cmd, args, { cwd, stdio: 'pipe', encoding: 'utf-8' })
|
|
35
|
-
const git = (args: string[], cwd?: string): string =>
|
|
36
|
-
// hooksPath=/dev/null: these are throwaway test clones, not project repos — the
|
|
37
|
-
// operator's global ai-agent-hooks must not run on them.
|
|
38
|
-
sh('git', ['-c', 'core.hooksPath=/dev/null', '-c', 'user.email=loop@tangle', '-c', 'user.name=loop', ...args], cwd)
|
|
39
|
-
|
|
40
|
-
/** a←b←c: c.top(1) = ((1+1)*2)+3 = 7. The integration test imports the whole chain,
|
|
41
|
-
* so it passes ONLY if all three files accumulated in the workspace. */
|
|
42
|
-
const modules = [
|
|
43
|
-
{ id: 'a', file: 'a.py', dep: null as string | null, code: 'def base(x):\n return x + 1\n' },
|
|
44
|
-
{ id: 'b', file: 'b.py', dep: 'a', code: 'from a import base\n\ndef mid(x):\n return base(x) * 2\n' },
|
|
45
|
-
{ id: 'c', file: 'c.py', dep: 'b', code: 'from b import mid\n\ndef top(x):\n return mid(x) + 3\n' },
|
|
46
|
-
]
|
|
47
|
-
const depFile = (id: string): string => modules.find((m) => m.id === id)!.file
|
|
48
|
-
|
|
49
|
-
function initWorkspace(): void {
|
|
50
|
-
rmSync(BARE, { recursive: true, force: true })
|
|
51
|
-
rmSync(JOURNAL, { force: true })
|
|
52
|
-
git(['init', '--bare', '-b', 'main', BARE])
|
|
53
|
-
// seed: the integration test, on the branch from commit 0.
|
|
54
|
-
const seed = mkdtempSync(join(tmpdir(), 'wl-seed-'))
|
|
55
|
-
git(['clone', BARE, seed])
|
|
56
|
-
writeFileSync(join(seed, 'test_all.py'), 'from c import top\n\nassert top(1) == 7, top(1)\nprint("INTEGRATION OK")\n')
|
|
57
|
-
git(['add', '-A'], seed)
|
|
58
|
-
git(['commit', '-m', 'seed: integration test'], seed)
|
|
59
|
-
git(['push', 'origin', 'main'], seed)
|
|
60
|
-
rmSync(seed, { recursive: true, force: true })
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function loadJournal(): Set<string> {
|
|
64
|
-
if (!existsSync(JOURNAL)) return new Set()
|
|
65
|
-
return new Set(readFileSync(JOURNAL, 'utf-8').split('\n').filter(Boolean))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** One worker: fresh clone (empty box FS) → verify dep is ON DISK → port → push → torn down. */
|
|
69
|
-
function runWorker(m: (typeof modules)[number]): void {
|
|
70
|
-
const work = mkdtempSync(join(tmpdir(), `wl-${m.id}-`))
|
|
71
|
-
try {
|
|
72
|
-
git(['clone', BARE, work]) // a brand-new, otherwise-empty box
|
|
73
|
-
// THE PROOF: did the durable workspace carry my dependency's code to this fresh box?
|
|
74
|
-
if (m.dep) {
|
|
75
|
-
const present = existsSync(join(work, depFile(m.dep)))
|
|
76
|
-
console.error(` [${m.id}] fresh clone — dependency ${depFile(m.dep)} on disk? ${present ? 'YES ✓ (git carried it)' : 'NO ✗ (share-nothing)'}`)
|
|
77
|
-
if (!present) throw new Error(`SHARE-NOTHING: ${m.id} cannot see ${m.dep} — the seam is broken`)
|
|
78
|
-
} else {
|
|
79
|
-
console.error(` [${m.id}] fresh clone — root module, no dependency`)
|
|
80
|
-
}
|
|
81
|
-
writeFileSync(join(work, m.file), m.code) // port the module
|
|
82
|
-
git(['add', '-A'], work)
|
|
83
|
-
git(['commit', '-m', `port ${m.id}`], work)
|
|
84
|
-
git(['push', 'origin', 'main'], work) // accumulate into the durable workspace
|
|
85
|
-
appendFileSync(JOURNAL, `${m.id}\n`) // record the decision durably
|
|
86
|
-
console.error(` [${m.id}] ported + committed + pushed → torn down`)
|
|
87
|
-
} finally {
|
|
88
|
-
rmSync(work, { recursive: true, force: true }) // teardown — the box dies, git survives
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Test (a): a fresh clone of the durable workspace must pass the integration test. */
|
|
93
|
-
function integrationLinks(): boolean {
|
|
94
|
-
const check = mkdtempSync(join(tmpdir(), 'wl-check-'))
|
|
95
|
-
try {
|
|
96
|
-
git(['clone', BARE, check])
|
|
97
|
-
const out = sh('python3', ['test_all.py'], check)
|
|
98
|
-
console.error(` integration: ${out.trim()}`)
|
|
99
|
-
return out.includes('INTEGRATION OK')
|
|
100
|
-
} catch (e) {
|
|
101
|
-
console.error(` integration FAILED: ${e instanceof Error ? e.message.split('\n').slice(-3).join(' ') : e}`)
|
|
102
|
-
return false
|
|
103
|
-
} finally {
|
|
104
|
-
rmSync(check, { recursive: true, force: true })
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function main(): void {
|
|
109
|
-
const resume = process.env.RESUME === '1'
|
|
110
|
-
const killAfter = process.env.KILL_AFTER
|
|
111
|
-
if (!resume) initWorkspace()
|
|
112
|
-
const done = loadJournal()
|
|
113
|
-
console.error(`\n=== git-backed workspace loop · ${resume ? 'RESUME' : 'fresh'}${done.size ? ` (done: ${[...done].join(',')})` : ''} ===`)
|
|
114
|
-
|
|
115
|
-
for (const m of modules) {
|
|
116
|
-
if (done.has(m.id)) {
|
|
117
|
-
console.error(` [${m.id}] skip — already committed (resumed from durable git)`)
|
|
118
|
-
continue
|
|
119
|
-
}
|
|
120
|
-
if (m.dep && !loadJournal().has(m.dep)) throw new Error(`${m.id} blocked: dependency ${m.dep} not done (topo order)`)
|
|
121
|
-
runWorker(m)
|
|
122
|
-
if (killAfter === m.id) {
|
|
123
|
-
console.error(`\n💥 KILLED after ${m.id} (orchestrator death). Durable git has: ${[...loadJournal()].join(',')}. Re-run with RESUME=1.\n`)
|
|
124
|
-
process.exit(1)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const links = integrationLinks()
|
|
129
|
-
console.error(`\n=== ${links ? '✅ LINKS — git-backed workspace + resume is REAL' : '❌ does not link'} ===`)
|
|
130
|
-
process.exit(links ? 0 : 1)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
main()
|