@tangle-network/agent-bench 0.14.2 → 1.0.0
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 +48 -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/scripts/verify-packed-consumer.mjs +0 -1
- package/src/atom-mcp-e2e.mts +16 -4
- 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 +8 -8
- 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-benchmarks.test.mts +0 -4
- 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/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/cloud-loop.mts +0 -156
- package/src/commit0-env-run.mts +0 -62
- package/src/commit0-env.ts +0 -172
- package/src/commit0-gate.mts +0 -558
- package/src/coordination-mcp-container-reach.mts +0 -182
- package/src/egress-probe.mts +0 -26
- package/src/fleet.mts +0 -143
- package/src/hev-structural.mts +0 -697
- package/src/humaneval-gate.mts +0 -220
- package/src/humaneval-repair-gate.mts +0 -182
- package/src/mbpp-structural.mts +0 -676
- package/src/mcp-mount-probe.mts +0 -139
- package/src/profile-coordinates.ts +0 -134
- 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/run-benchmarks-report.ts +0 -66
- 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/skill-sandbox-smoke.mts +0 -101
- package/src/smoke-structural-rollout.mts +0 -415
- package/src/stats.mts +0 -90
- package/src/supervisor-arena.mts +0 -825
- package/src/swe-code-improve.mts +0 -306
- package/src/swe-emit-patch.mts +0 -125
- package/src/swe-improve.mts +0 -284
- 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/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/trajectory-assemble.mjs +0 -130
- package/src/trata-gepa.mts +0 -381
- package/src/trata-hedge-solve.mts +0 -81
- package/src/worker-browser.ts +0 -115
- package/src/worker-cad.ts +0 -470
- package/src/workspace-loop.mts +0 -133
- package/tb_agents/opencode_refine_agent.py +0 -117
- package/tb_agents/opencode_supervisor_agent.py +0 -239
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reference BrowserAgentAdapter for @tangle-network/browser-agent-driver (the `bad`
|
|
3
|
-
* CLI). One of N pluggable drivers behind the neutral harness — it conforms to the
|
|
4
|
-
* SAME BrowserAgentAdapter contract as a browser-use runner or any other agent.
|
|
5
|
-
*
|
|
6
|
-
* `bad run --cases <file> --sink <dir>` emits a structured report.json; we map its
|
|
7
|
-
* `agentResult` to the neutral BrowserRun and let `judgeBrowserRun` derive the
|
|
8
|
-
* DETERMINISTIC verdict. We record `bad`'s own success/goalVerification only as
|
|
9
|
-
* `selfReportedSuccess` — it never decides the outcome (attestation, not trust).
|
|
10
|
-
*
|
|
11
|
-
* `badReportToRun` is a pure, unit-testable mapper kept separate from the spawn so
|
|
12
|
-
* the report-shape mapping can be exercised without launching a browser.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { spawn } 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 type { BrowserAgentAdapter, BrowserRun, BrowserStep, BrowserTask } from '../agent-adapter'
|
|
20
|
-
|
|
21
|
-
export interface BadAdapterConfig {
|
|
22
|
-
/** Path to the bad CLI entry (default: $BAD_CLI or ~/code/browser-agent-driver/dist/cli.js). */
|
|
23
|
-
badCli?: string
|
|
24
|
-
model?: string
|
|
25
|
-
provider?: string
|
|
26
|
-
/** OpenAI-compatible endpoint — point at our router. */
|
|
27
|
-
baseUrl?: string
|
|
28
|
-
apiKey?: string
|
|
29
|
-
maxTurns?: number
|
|
30
|
-
timeoutMs?: number
|
|
31
|
-
/** Capture a per-turn screenshot into each turn's state.screenshot (bad
|
|
32
|
-
* full-evidence mode). Off by default — opt in for the navigation film. */
|
|
33
|
-
captureScreenshots?: boolean
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface BadReport {
|
|
37
|
-
results?: Array<{
|
|
38
|
-
testCase?: { id?: string }
|
|
39
|
-
// Real token/cost telemetry (bad >=0.33 reports these per result) — forwarded to
|
|
40
|
-
// BrowserRun so a real run never reads as a {0,0} backend-integrity stub.
|
|
41
|
-
estimatedCostUsd?: number
|
|
42
|
-
inputTokens?: number
|
|
43
|
-
outputTokens?: number
|
|
44
|
-
agentResult?: {
|
|
45
|
-
success?: boolean
|
|
46
|
-
result?: string
|
|
47
|
-
turns?: Array<{
|
|
48
|
-
turn?: number
|
|
49
|
-
// state.screenshot is INLINE base64 (no data: prefix) — the durable frame
|
|
50
|
-
// source for the film, since the adapter's temp sink is reaped after the run.
|
|
51
|
-
state?: { url?: string; title?: string; snapshot?: string; screenshot?: string }
|
|
52
|
-
action?: { action?: string; selector?: string; text?: string; result?: string }
|
|
53
|
-
}>
|
|
54
|
-
}
|
|
55
|
-
}>
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Pure mapper: bad's report.json → the neutral BrowserRun for taskId. The final
|
|
59
|
-
* turn's state.url is the observable final URL; its snapshot is the final DOM the
|
|
60
|
-
* deterministic dom-* checks read. */
|
|
61
|
-
export function badReportToRun(report: BadReport, taskId: string): BrowserRun {
|
|
62
|
-
const res = report.results?.find((r) => r.testCase?.id === taskId) ?? report.results?.[0]
|
|
63
|
-
const ar = res?.agentResult ?? {}
|
|
64
|
-
const turns = Array.isArray(ar.turns) ? ar.turns : []
|
|
65
|
-
const steps: BrowserStep[] = turns.map((t, i) => ({
|
|
66
|
-
index: typeof t.turn === 'number' ? t.turn : i + 1,
|
|
67
|
-
url: t.state?.url ?? '',
|
|
68
|
-
action: t.action?.action ?? 'decide',
|
|
69
|
-
target: t.action?.selector ?? (t.action?.text ? `"${t.action.text}"` : undefined),
|
|
70
|
-
// The frame for the film: bad's per-turn base64 JPEG, normalized to a data: URI.
|
|
71
|
-
screenshot: t.state?.screenshot ? `data:image/jpeg;base64,${t.state.screenshot}` : undefined,
|
|
72
|
-
}))
|
|
73
|
-
const last = turns[turns.length - 1]
|
|
74
|
-
const input = typeof res?.inputTokens === 'number' ? res.inputTokens : undefined
|
|
75
|
-
const output = typeof res?.outputTokens === 'number' ? res.outputTokens : undefined
|
|
76
|
-
return {
|
|
77
|
-
taskId,
|
|
78
|
-
steps,
|
|
79
|
-
finalUrl: last?.state?.url ?? '',
|
|
80
|
-
finalDom: typeof last?.state?.snapshot === 'string' ? last.state.snapshot : undefined,
|
|
81
|
-
answer: typeof ar.result === 'string' ? ar.result : undefined,
|
|
82
|
-
selfReportedSuccess: typeof ar.success === 'boolean' ? ar.success : undefined,
|
|
83
|
-
usage: input !== undefined || output !== undefined ? { input: input ?? 0, output: output ?? 0 } : undefined,
|
|
84
|
-
costUsd: typeof res?.estimatedCostUsd === 'number' ? res.estimatedCostUsd : undefined,
|
|
85
|
-
driverId: 'bad',
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function resolveCli(cfg: BadAdapterConfig): string {
|
|
90
|
-
return cfg.badCli ?? process.env.BAD_CLI ?? join(process.env.HOME ?? '', 'code/browser-agent-driver/dist/cli.js')
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** A BrowserAgentAdapter backed by the `bad` CLI. Runs one task through a real
|
|
94
|
-
* browser; the harness judge attests the outcome. */
|
|
95
|
-
export function badBrowserAdapter(cfg: BadAdapterConfig = {}): BrowserAgentAdapter {
|
|
96
|
-
const cli = resolveCli(cfg)
|
|
97
|
-
const timeoutMs = cfg.timeoutMs ?? 300_000
|
|
98
|
-
return {
|
|
99
|
-
id: 'bad',
|
|
100
|
-
async run(task: BrowserTask): Promise<BrowserRun> {
|
|
101
|
-
const dir = await mkdtemp(join(tmpdir(), 'bad-adapter-'))
|
|
102
|
-
const casesPath = join(dir, 'cases.json')
|
|
103
|
-
const sink = join(dir, 'sink')
|
|
104
|
-
const cases = [
|
|
105
|
-
{
|
|
106
|
-
id: task.id,
|
|
107
|
-
name: task.id,
|
|
108
|
-
goal: task.goal,
|
|
109
|
-
url: task.startUrl,
|
|
110
|
-
maxTurns: task.maxSteps ?? cfg.maxTurns ?? 20,
|
|
111
|
-
},
|
|
112
|
-
]
|
|
113
|
-
await writeFile(casesPath, JSON.stringify(cases))
|
|
114
|
-
const args = [
|
|
115
|
-
cli,
|
|
116
|
-
'run',
|
|
117
|
-
'--cases',
|
|
118
|
-
casesPath,
|
|
119
|
-
'--sink',
|
|
120
|
-
sink,
|
|
121
|
-
'--provider',
|
|
122
|
-
cfg.provider ?? 'openai',
|
|
123
|
-
'--model',
|
|
124
|
-
cfg.model ?? 'deepseek-v4-flash',
|
|
125
|
-
'--max-turns',
|
|
126
|
-
String(task.maxSteps ?? cfg.maxTurns ?? 20),
|
|
127
|
-
'--headless',
|
|
128
|
-
]
|
|
129
|
-
// full-evidence + every-turn capture populates each turn's state.screenshot,
|
|
130
|
-
// which badReportToRun lifts into BrowserStep.screenshot for the film.
|
|
131
|
-
if (cfg.captureScreenshots) args.push('--mode', 'full-evidence', '--screenshot-interval', '1')
|
|
132
|
-
if (cfg.baseUrl) args.push('--base-url', cfg.baseUrl)
|
|
133
|
-
if (cfg.apiKey) args.push('--api-key', cfg.apiKey)
|
|
134
|
-
if (task.storageState) args.push('--storage-state', task.storageState)
|
|
135
|
-
try {
|
|
136
|
-
await runChild('node', args, dir, timeoutMs)
|
|
137
|
-
const report = JSON.parse(await readFile(join(sink, 'report.json'), 'utf8')) as BadReport
|
|
138
|
-
return badReportToRun(report, task.id)
|
|
139
|
-
} finally {
|
|
140
|
-
await rm(dir, { recursive: true, force: true }).catch(() => {})
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function runChild(cmd: string, args: string[], cwd: string, timeoutMs: number): Promise<void> {
|
|
147
|
-
return new Promise((resolve, reject) => {
|
|
148
|
-
const child = spawn(cmd, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] })
|
|
149
|
-
let err = ''
|
|
150
|
-
const timer = setTimeout(() => {
|
|
151
|
-
child.kill('SIGKILL')
|
|
152
|
-
reject(new Error(`bad adapter timed out after ${timeoutMs}ms`))
|
|
153
|
-
}, timeoutMs)
|
|
154
|
-
child.stderr.on('data', (d) => (err += d.toString()))
|
|
155
|
-
child.on('error', (e) => {
|
|
156
|
-
clearTimeout(timer)
|
|
157
|
-
reject(new Error(`bad adapter failed to spawn: ${e.message}`))
|
|
158
|
-
})
|
|
159
|
-
child.on('close', (code) => {
|
|
160
|
-
clearTimeout(timer)
|
|
161
|
-
if (code !== 0) reject(new Error(`bad exited ${code}: ${err.slice(-300)}`))
|
|
162
|
-
else resolve()
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Driver-agnostic browser-agent harness — the GENERAL seam.
|
|
3
|
-
*
|
|
4
|
-
* The benchmark owns the task and the verdict; the browser AGENT is pluggable.
|
|
5
|
-
* Any driver — @tangle-network/browser-agent-driver, browser-use (Python),
|
|
6
|
-
* a hosted API, a future tool — conforms to ONE neutral contract: given a goal +
|
|
7
|
-
* start URL, produce a normalized trajectory and a final observable state. We do
|
|
8
|
-
* NOT shape this around any one driver's SDK; it is the least-common-denominator
|
|
9
|
-
* a browser agent can emit, crossed with what a deterministic judge needs.
|
|
10
|
-
*
|
|
11
|
-
* Attestability is the whole point. We NEVER trust the driver's own `success`
|
|
12
|
-
* flag or its LLM goal-verification (that is the unverifiable self-report the
|
|
13
|
-
* benchmark exists to replace). Our judge re-derives the outcome from DETERMINISTIC
|
|
14
|
-
* criteria (url / DOM state / element checks) against the run's final state. A
|
|
15
|
-
* driver's published number is a hypothesis our harness attests or refutes.
|
|
16
|
-
*
|
|
17
|
-
* Language-agnostic by a process boundary: a driver that isn't TypeScript (e.g.
|
|
18
|
-
* browser-use) is wrapped by `processBrowserAdapter`, which hands the task as JSON
|
|
19
|
-
* on argv/stdin and reads a BrowserRun back as JSON on stdout. No SDK coupling, no
|
|
20
|
-
* overfit — adding a driver is a thin runner that speaks this JSON, nothing more.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/** A deterministic, driver-independent success check the JUDGE applies to the
|
|
24
|
-
* run's final state — never the agent's self-assessment. Mirrors the kinds a
|
|
25
|
-
* benchmark harness actually ships (WebArena program-state, Mind2Web element). */
|
|
26
|
-
export type SuccessSpec =
|
|
27
|
-
| { type: 'url-contains'; value: string }
|
|
28
|
-
| { type: 'url-matches'; value: string } // regex on finalUrl
|
|
29
|
-
| { type: 'final-answer-matches'; value: string } // regex on the agent's answer (extraction tasks)
|
|
30
|
-
| { type: 'dom-contains'; value: string } // substring of the final DOM/text snapshot
|
|
31
|
-
| { type: 'dom-selector-text'; selector: string; value: string } // element text equals/contains
|
|
32
|
-
| { type: 'program'; id: string } // a benchmark-provided programmatic check keyed by id
|
|
33
|
-
|
|
34
|
-
/** A task handed to ANY browser agent. `success` is the benchmark's deterministic
|
|
35
|
-
* verdict spec — evaluated by us, not the driver. */
|
|
36
|
-
export interface BrowserTask {
|
|
37
|
-
id: string
|
|
38
|
-
goal: string
|
|
39
|
-
startUrl: string
|
|
40
|
-
maxSteps?: number
|
|
41
|
-
/** Path to a Playwright storageState for authenticated tasks (optional). */
|
|
42
|
-
storageState?: string
|
|
43
|
-
/** Deterministic success criteria the judge applies to the produced run. */
|
|
44
|
-
success: SuccessSpec[]
|
|
45
|
-
/** Benchmark-specific extras the judge may need (gold answer, program inputs). */
|
|
46
|
-
metadata?: Record<string, unknown>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** One normalized step, common to every driver. */
|
|
50
|
-
export interface BrowserStep {
|
|
51
|
-
index: number
|
|
52
|
-
/** URL at this step. */
|
|
53
|
-
url: string
|
|
54
|
-
/** A normalized action label (e.g. 'click', 'type', 'navigate', 'scroll'). */
|
|
55
|
-
action: string
|
|
56
|
-
/** Human/agent-readable target or value (selector, text typed, link). */
|
|
57
|
-
target?: string
|
|
58
|
-
/** Agent's reasoning for this step, if the driver exposes it. */
|
|
59
|
-
reasoning?: string
|
|
60
|
-
/** Path to a per-step screenshot on disk (for the run-capsule film). */
|
|
61
|
-
screenshotPath?: string
|
|
62
|
-
/** Inline base64 `data:` URI of the per-step frame, when the driver carries the
|
|
63
|
-
* image in its report rather than on disk (e.g. `bad`'s state.screenshot, whose
|
|
64
|
-
* sink is reaped post-run). Preferred over `screenshotPath` by the film converter. */
|
|
65
|
-
screenshot?: string
|
|
66
|
-
/** Target element box at action time, if known — for replay cursor overlays. */
|
|
67
|
-
actionBounds?: { x: number; y: number; width: number; height: number }
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** The normalized result ANY driver produces — the judge scores this, not the
|
|
71
|
-
* driver's opinion of itself. */
|
|
72
|
-
export interface BrowserRun {
|
|
73
|
-
taskId: string
|
|
74
|
-
steps: BrowserStep[]
|
|
75
|
-
/** URL the agent ended on. */
|
|
76
|
-
finalUrl: string
|
|
77
|
-
/** Final visible text / DOM snapshot for dom-* deterministic checks. */
|
|
78
|
-
finalDom?: string
|
|
79
|
-
/** The agent's final free-text answer (extraction tasks). */
|
|
80
|
-
answer?: string
|
|
81
|
-
/** The driver's OWN success claim — recorded for comparison, NEVER the verdict. */
|
|
82
|
-
selfReportedSuccess?: boolean
|
|
83
|
-
/** Real token usage + cost if the driver reports it (backend-integrity). */
|
|
84
|
-
usage?: { input: number; output: number }
|
|
85
|
-
costUsd?: number
|
|
86
|
-
/** Which driver produced this run (for compareDrivers attribution). */
|
|
87
|
-
driverId: string
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** The general seam every browser driver implements (directly in TS, or via the
|
|
91
|
-
* process wrapper below). `id` is the attribution key for head-to-head. */
|
|
92
|
-
export interface BrowserAgentAdapter {
|
|
93
|
-
readonly id: string
|
|
94
|
-
run(task: BrowserTask): Promise<BrowserRun>
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Optional per-benchmark programmatic checks, keyed by SuccessSpec {type:'program', id}. */
|
|
98
|
-
export type ProgramChecks = Record<string, (run: BrowserRun, task: BrowserTask) => boolean>
|
|
99
|
-
|
|
100
|
-
/** The DETERMINISTIC, attestable verdict: evaluate the benchmark's SuccessSpec list
|
|
101
|
-
* against the run's final observable state. Independent of selfReportedSuccess.
|
|
102
|
-
* resolved = ALL criteria pass; score = fraction passed (a gradient for the optimizer). */
|
|
103
|
-
export function judgeBrowserRun(
|
|
104
|
-
task: BrowserTask,
|
|
105
|
-
run: BrowserRun,
|
|
106
|
-
programs: ProgramChecks = {},
|
|
107
|
-
): { resolved: boolean; score: number; detail: string } {
|
|
108
|
-
const checks = task.success
|
|
109
|
-
if (checks.length === 0) throw new Error(`browser task ${task.id} has no success criteria — cannot attest`)
|
|
110
|
-
const results = checks.map((c) => ({ c, ok: evalCriterion(c, run, task, programs) }))
|
|
111
|
-
const passed = results.filter((r) => r.ok).length
|
|
112
|
-
const resolved = passed === checks.length
|
|
113
|
-
return {
|
|
114
|
-
resolved,
|
|
115
|
-
score: passed / checks.length,
|
|
116
|
-
detail: JSON.stringify({
|
|
117
|
-
passed,
|
|
118
|
-
total: checks.length,
|
|
119
|
-
selfReported: run.selfReportedSuccess,
|
|
120
|
-
finalUrl: run.finalUrl,
|
|
121
|
-
perCriterion: results.map((r) => ({ type: r.c.type, ok: r.ok })),
|
|
122
|
-
}),
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function evalCriterion(c: SuccessSpec, run: BrowserRun, task: BrowserTask, programs: ProgramChecks): boolean {
|
|
127
|
-
switch (c.type) {
|
|
128
|
-
case 'url-contains':
|
|
129
|
-
return run.finalUrl.includes(c.value)
|
|
130
|
-
case 'url-matches':
|
|
131
|
-
return new RegExp(c.value).test(run.finalUrl)
|
|
132
|
-
case 'final-answer-matches':
|
|
133
|
-
return run.answer != null && new RegExp(c.value, 'i').test(run.answer)
|
|
134
|
-
case 'dom-contains':
|
|
135
|
-
return run.finalDom != null && run.finalDom.includes(c.value)
|
|
136
|
-
case 'dom-selector-text':
|
|
137
|
-
// Deterministic only with a structured snapshot; require finalDom to carry it.
|
|
138
|
-
return run.finalDom != null && run.finalDom.includes(c.value)
|
|
139
|
-
case 'program': {
|
|
140
|
-
const fn = programs[c.id]
|
|
141
|
-
if (!fn) throw new Error(`browser task ${task.id}: no program check registered for id '${c.id}'`)
|
|
142
|
-
return fn(run, task)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Language-agnostic browser-agent adapter over a process boundary.
|
|
3
|
-
*
|
|
4
|
-
* This is how we avoid overfitting to our own driver: ANY browser agent becomes a
|
|
5
|
-
* `BrowserAgentAdapter` by speaking one JSON protocol over stdio — no shared SDK,
|
|
6
|
-
* no TypeScript requirement. A Python `browser-use` runner, our TS `bad` CLI, or a
|
|
7
|
-
* hosted service all plug in identically.
|
|
8
|
-
*
|
|
9
|
-
* Protocol (stdio):
|
|
10
|
-
* - The harness spawns `cmd ...args`, writes a BrowserTask as one JSON line to
|
|
11
|
-
* the child's stdin, and closes stdin.
|
|
12
|
-
* - The child runs its agent and writes EXACTLY one JSON object — a BrowserRun —
|
|
13
|
-
* to stdout (anything on stderr is logged, ignored for parsing).
|
|
14
|
-
* - Non-zero exit, no JSON, or a malformed run → throw (fail loud; a driver that
|
|
15
|
-
* can't conform is not silently scored zero).
|
|
16
|
-
*
|
|
17
|
-
* The child is responsible only for producing a faithful trajectory + final state.
|
|
18
|
-
* The VERDICT is never the child's to give — `judgeBrowserRun` derives it from the
|
|
19
|
-
* benchmark's deterministic SuccessSpec against the returned final state.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { spawn } from 'node:child_process'
|
|
23
|
-
import type { BrowserAgentAdapter, BrowserRun, BrowserStep, BrowserTask } from './agent-adapter'
|
|
24
|
-
|
|
25
|
-
export interface ProcessAdapterOptions {
|
|
26
|
-
/** Attribution id for head-to-head (e.g. 'browser-use', 'bad'). */
|
|
27
|
-
id: string
|
|
28
|
-
/** Executable to spawn (e.g. 'python', 'node', 'bad'). */
|
|
29
|
-
cmd: string
|
|
30
|
-
/** Fixed args before the per-task protocol (e.g. ['runners/browser_use_runner.py']). */
|
|
31
|
-
args?: string[]
|
|
32
|
-
/** Extra env for the child (model keys, etc.). Merged over process.env. */
|
|
33
|
-
env?: Record<string, string>
|
|
34
|
-
/** Hard ceiling per task in ms (default 300_000). */
|
|
35
|
-
timeoutMs?: number
|
|
36
|
-
/** Working directory for the child. */
|
|
37
|
-
cwd?: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Build a BrowserAgentAdapter that delegates to an external process speaking the
|
|
41
|
-
* JSON protocol above. */
|
|
42
|
-
export function processBrowserAdapter(opts: ProcessAdapterOptions): BrowserAgentAdapter {
|
|
43
|
-
const timeoutMs = opts.timeoutMs ?? 300_000
|
|
44
|
-
return {
|
|
45
|
-
id: opts.id,
|
|
46
|
-
async run(task: BrowserTask): Promise<BrowserRun> {
|
|
47
|
-
const stdout = await runChild(opts, JSON.stringify(task), timeoutMs)
|
|
48
|
-
const run = parseRun(stdout, task, opts.id)
|
|
49
|
-
return run
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function runChild(opts: ProcessAdapterOptions, input: string, timeoutMs: number): Promise<string> {
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
const child = spawn(opts.cmd, opts.args ?? [], {
|
|
57
|
-
cwd: opts.cwd,
|
|
58
|
-
env: { ...process.env, ...opts.env },
|
|
59
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
60
|
-
})
|
|
61
|
-
let out = ''
|
|
62
|
-
let err = ''
|
|
63
|
-
const timer = setTimeout(() => {
|
|
64
|
-
child.kill('SIGKILL')
|
|
65
|
-
reject(new Error(`browser adapter '${opts.id}' timed out after ${timeoutMs}ms`))
|
|
66
|
-
}, timeoutMs)
|
|
67
|
-
child.stdout.on('data', (d) => (out += d.toString()))
|
|
68
|
-
child.stderr.on('data', (d) => (err += d.toString()))
|
|
69
|
-
child.on('error', (e) => {
|
|
70
|
-
clearTimeout(timer)
|
|
71
|
-
reject(new Error(`browser adapter '${opts.id}' failed to spawn ${opts.cmd}: ${e.message}`))
|
|
72
|
-
})
|
|
73
|
-
child.on('close', (code) => {
|
|
74
|
-
clearTimeout(timer)
|
|
75
|
-
if (code !== 0) {
|
|
76
|
-
reject(new Error(`browser adapter '${opts.id}' exited ${code}: ${err.slice(-400) || out.slice(-400)}`))
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
resolve(out)
|
|
80
|
-
})
|
|
81
|
-
child.stdin.write(input)
|
|
82
|
-
child.stdin.end()
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Parse + validate the child's BrowserRun. The last complete JSON object on stdout
|
|
87
|
-
* is the result (drivers may print progress lines before it). Fail loud on a shape
|
|
88
|
-
* that the judge cannot trust. */
|
|
89
|
-
function parseRun(stdout: string, task: BrowserTask, driverId: string): BrowserRun {
|
|
90
|
-
const obj = lastJsonObject(stdout)
|
|
91
|
-
if (!obj) throw new Error(`browser adapter '${driverId}' produced no JSON BrowserRun for task ${task.id}`)
|
|
92
|
-
if (typeof obj.finalUrl !== 'string' || !Array.isArray(obj.steps)) {
|
|
93
|
-
throw new Error(`browser adapter '${driverId}' BrowserRun missing finalUrl/steps for task ${task.id}`)
|
|
94
|
-
}
|
|
95
|
-
const steps: BrowserStep[] = (obj.steps as unknown[]).map((s, i) => {
|
|
96
|
-
const o = (s ?? {}) as Record<string, unknown>
|
|
97
|
-
return {
|
|
98
|
-
index: typeof o.index === 'number' ? o.index : i,
|
|
99
|
-
url: typeof o.url === 'string' ? o.url : '',
|
|
100
|
-
action: typeof o.action === 'string' ? o.action : 'step',
|
|
101
|
-
target: typeof o.target === 'string' ? o.target : undefined,
|
|
102
|
-
reasoning: typeof o.reasoning === 'string' ? o.reasoning : undefined,
|
|
103
|
-
screenshotPath: typeof o.screenshotPath === 'string' ? o.screenshotPath : undefined,
|
|
104
|
-
actionBounds: isBounds(o.actionBounds) ? (o.actionBounds as BrowserStep['actionBounds']) : undefined,
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
const usage =
|
|
108
|
-
obj.usage && typeof obj.usage === 'object'
|
|
109
|
-
? {
|
|
110
|
-
input: Number((obj.usage as Record<string, unknown>).input) || 0,
|
|
111
|
-
output: Number((obj.usage as Record<string, unknown>).output) || 0,
|
|
112
|
-
}
|
|
113
|
-
: undefined
|
|
114
|
-
return {
|
|
115
|
-
taskId: task.id,
|
|
116
|
-
steps,
|
|
117
|
-
finalUrl: obj.finalUrl as string,
|
|
118
|
-
finalDom: typeof obj.finalDom === 'string' ? obj.finalDom : undefined,
|
|
119
|
-
answer: typeof obj.answer === 'string' ? obj.answer : undefined,
|
|
120
|
-
selfReportedSuccess: typeof obj.selfReportedSuccess === 'boolean' ? obj.selfReportedSuccess : undefined,
|
|
121
|
-
usage,
|
|
122
|
-
costUsd: typeof obj.costUsd === 'number' ? obj.costUsd : undefined,
|
|
123
|
-
driverId,
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function isBounds(v: unknown): boolean {
|
|
128
|
-
if (!v || typeof v !== 'object') return false
|
|
129
|
-
const o = v as Record<string, unknown>
|
|
130
|
-
return ['x', 'y', 'width', 'height'].every((k) => typeof o[k] === 'number')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Find the last top-level JSON object in mixed stdout (progress lines + result). */
|
|
134
|
-
function lastJsonObject(s: string): Record<string, unknown> | null {
|
|
135
|
-
for (let i = s.lastIndexOf('{'); i >= 0; i = s.lastIndexOf('{', i - 1)) {
|
|
136
|
-
const slice = s.slice(i)
|
|
137
|
-
try {
|
|
138
|
-
const parsed = JSON.parse(slice)
|
|
139
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) return parsed as Record<string, unknown>
|
|
140
|
-
} catch {
|
|
141
|
-
// keep scanning earlier '{'
|
|
142
|
-
}
|
|
143
|
-
if (i === 0) break
|
|
144
|
-
}
|
|
145
|
-
return null
|
|
146
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure converter: a neutral `BrowserRun` (from any `BrowserAgentAdapter`) → a
|
|
3
|
-
* `Span[]` trace run-capsule renders into a navigation film. One `kind:'tool'`
|
|
4
|
-
* span per `BrowserStep` (`browser.<action>`); when a step carries a
|
|
5
|
-
* `screenshotPath`, the file is read and inlined as a base64 `data:` URI on
|
|
6
|
-
* `attributes.screenshot` — run-capsule renders from the inline blob, NOT a path,
|
|
7
|
-
* so a raw path would silently render nothing.
|
|
8
|
-
*
|
|
9
|
-
* Kept pure + spawn-free (the adapter already ran the browser) so the mapping is
|
|
10
|
-
* unit-testable against a fixture without launching Chromium. Timestamps are
|
|
11
|
-
* synthesized monotonically from `opts.startTs` (default 0) — deterministic for
|
|
12
|
-
* the verify; the live caller passes `Date.now()`.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { readFile } from 'node:fs/promises'
|
|
16
|
-
import type { Span } from '@tangle-network/agent-eval'
|
|
17
|
-
import type { BrowserRun, BrowserStep } from './agent-adapter'
|
|
18
|
-
|
|
19
|
-
export interface BrowserRunToSpansOptions {
|
|
20
|
-
/** Base timestamp; each emitted span advances by 1ms. Default 0 (deterministic). */
|
|
21
|
-
startTs?: number
|
|
22
|
-
/** Cap on inlined screenshot bytes before base64 (skip oversized frames). Default 8 MiB. */
|
|
23
|
-
maxScreenshotBytes?: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47])
|
|
27
|
-
const JPG = Buffer.from([0xff, 0xd8, 0xff])
|
|
28
|
-
|
|
29
|
-
/** Sniff the on-disk image mime from magic bytes; default png. */
|
|
30
|
-
function imageMime(buf: Buffer): string {
|
|
31
|
-
if (buf.subarray(0, 4).equals(PNG)) return 'image/png'
|
|
32
|
-
if (buf.subarray(0, 3).equals(JPG)) return 'image/jpeg'
|
|
33
|
-
return 'image/png'
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Resolve a step's frame to an inline `data:` URI for the film. Prefers an
|
|
37
|
-
* already-inline `step.screenshot` (e.g. bad's base64, whose sink is reaped),
|
|
38
|
-
* else reads `step.screenshotPath` off disk. Fail-soft: an unset / unreadable /
|
|
39
|
-
* oversized frame drops the image, never the span — the navigation step still
|
|
40
|
-
* belongs in the film. */
|
|
41
|
-
async function resolveFrame(step: BrowserStep, maxBytes: number): Promise<string | undefined> {
|
|
42
|
-
if (step.screenshot) {
|
|
43
|
-
return step.screenshot.length <= maxBytes * 2 ? step.screenshot : undefined
|
|
44
|
-
}
|
|
45
|
-
if (!step.screenshotPath) return undefined
|
|
46
|
-
const buf = await readFile(step.screenshotPath).catch(() => undefined)
|
|
47
|
-
if (!buf || buf.length === 0 || buf.length > maxBytes) return undefined
|
|
48
|
-
return `data:${imageMime(buf)};base64,${buf.toString('base64')}`
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Map a `BrowserRun` to a run-capsule-ready `Span[]`. Async because it reads the
|
|
53
|
-
* step screenshots off disk. The returned trace is ordered by step index; the
|
|
54
|
-
* agent's final answer (extraction tasks) becomes a trailing generic span so the
|
|
55
|
-
* film closes on the result.
|
|
56
|
-
*/
|
|
57
|
-
export async function browserRunToSpans(
|
|
58
|
-
run: BrowserRun,
|
|
59
|
-
opts: BrowserRunToSpansOptions = {},
|
|
60
|
-
): Promise<Span[]> {
|
|
61
|
-
const maxBytes = opts.maxScreenshotBytes ?? 8 * 1024 * 1024
|
|
62
|
-
let ts = opts.startTs ?? 0
|
|
63
|
-
const tick = (): number => (ts += 1)
|
|
64
|
-
const runId = `browser-${run.taskId}`
|
|
65
|
-
|
|
66
|
-
const spans: Span[] = []
|
|
67
|
-
for (const step of run.steps) {
|
|
68
|
-
const action = step.action || 'navigate'
|
|
69
|
-
const screenshot = await resolveFrame(step, maxBytes)
|
|
70
|
-
const startedAt = tick()
|
|
71
|
-
spans.push({
|
|
72
|
-
spanId: `s-${step.index}`,
|
|
73
|
-
runId,
|
|
74
|
-
kind: 'tool',
|
|
75
|
-
name: `browser ${action}`,
|
|
76
|
-
toolName: `browser.${action}`,
|
|
77
|
-
args: { url: step.url, target: step.target, reasoning: step.reasoning },
|
|
78
|
-
startedAt,
|
|
79
|
-
endedAt: tick(),
|
|
80
|
-
status: 'ok',
|
|
81
|
-
// attributes is the run-capsule contract: inline base64 screenshot + the
|
|
82
|
-
// action box for a replay cursor overlay. Only set keys that are present.
|
|
83
|
-
attributes: {
|
|
84
|
-
...(screenshot ? { screenshot } : {}),
|
|
85
|
-
...(step.actionBounds ? { actionBounds: step.actionBounds } : {}),
|
|
86
|
-
},
|
|
87
|
-
} as Span)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (run.answer) {
|
|
91
|
-
const startedAt = tick()
|
|
92
|
-
spans.push({
|
|
93
|
-
spanId: 's-answer',
|
|
94
|
-
runId,
|
|
95
|
-
kind: 'custom',
|
|
96
|
-
name: 'final answer',
|
|
97
|
-
startedAt,
|
|
98
|
-
endedAt: tick(),
|
|
99
|
-
status: 'ok',
|
|
100
|
-
attributes: { answer: run.answer, finalUrl: run.finalUrl },
|
|
101
|
-
} as Span)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return spans
|
|
105
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deterministic self-check for browserRunToSpans —
|
|
3
|
-
* `tsx src/browser/run-to-spans.verify.ts`.
|
|
4
|
-
*
|
|
5
|
-
* Proves the run-capsule film contract: each BrowserStep becomes a kind:'tool'
|
|
6
|
-
* `browser.<action>` span; a step's screenshotPath is READ and inlined as a
|
|
7
|
-
* base64 `data:` URI on attributes.screenshot (NEVER passed through as a raw
|
|
8
|
-
* path — the regression that renders an empty film); a missing screenshot drops
|
|
9
|
-
* the image but keeps the step's span.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
13
|
-
import { tmpdir } from 'node:os'
|
|
14
|
-
import { join } from 'node:path'
|
|
15
|
-
import type { BrowserRun } from './agent-adapter'
|
|
16
|
-
import { browserRunToSpans } from './run-to-spans'
|
|
17
|
-
|
|
18
|
-
let failures = 0
|
|
19
|
-
function check(name: string, cond: boolean, detail = ''): void {
|
|
20
|
-
if (cond) console.log(` ✓ ${name}`)
|
|
21
|
-
else {
|
|
22
|
-
failures += 1
|
|
23
|
-
console.log(` ✗ ${name} ${detail}`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const dir = mkdtempSync(join(tmpdir(), 'run-to-spans-'))
|
|
28
|
-
// A 1x1 PNG on disk — the magic bytes make imageMime resolve to image/png.
|
|
29
|
-
const pngBytes = Buffer.from(
|
|
30
|
-
'89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4890000000a49444154789c6360000002000154a24f7d0000000049454e44ae426082',
|
|
31
|
-
'hex',
|
|
32
|
-
)
|
|
33
|
-
const shotPath = join(dir, 'step-1.png')
|
|
34
|
-
writeFileSync(shotPath, pngBytes)
|
|
35
|
-
|
|
36
|
-
const run: BrowserRun = {
|
|
37
|
-
taskId: 'usps-track',
|
|
38
|
-
driverId: 'bad',
|
|
39
|
-
steps: [
|
|
40
|
-
{ index: 1, url: 'https://tools.usps.com/', action: 'navigate', target: 'tracking input', screenshotPath: shotPath },
|
|
41
|
-
{ index: 2, url: 'https://tools.usps.com/go/TrackConfirmAction', action: 'click', target: 'Track button', actionBounds: { x: 10, y: 20, width: 80, height: 30 } },
|
|
42
|
-
],
|
|
43
|
-
finalUrl: 'https://tools.usps.com/go/TrackConfirmAction',
|
|
44
|
-
answer: 'Delivered',
|
|
45
|
-
selfReportedSuccess: true,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
console.log('browserRunToSpans verify:')
|
|
49
|
-
|
|
50
|
-
const spans = await browserRunToSpans(run, { startTs: 1000 })
|
|
51
|
-
|
|
52
|
-
check('one tool span per step + a trailing answer span', spans.length === 3, `got ${spans.length}`)
|
|
53
|
-
const s1 = spans[0]
|
|
54
|
-
const s2 = spans[1]
|
|
55
|
-
const answer = spans[2]
|
|
56
|
-
check('step 1 is a kind:tool browser.navigate span', s1?.kind === 'tool' && (s1 as { toolName?: string }).toolName === 'browser.navigate')
|
|
57
|
-
check('step 1 args carry the url + target', (s1 as { args?: { url?: string; target?: string } }).args?.url === 'https://tools.usps.com/' && (s1 as { args?: { target?: string } }).args?.target === 'tracking input')
|
|
58
|
-
|
|
59
|
-
const shot = (s1?.attributes?.screenshot ?? '') as string
|
|
60
|
-
check('screenshotPath was READ + inlined as a base64 data URI (not a path)', shot.startsWith('data:image/png;base64,') && shot.length > 60, shot.slice(0, 40))
|
|
61
|
-
check('the raw on-disk path is NEVER present in the span', !JSON.stringify(s1).includes(shotPath))
|
|
62
|
-
|
|
63
|
-
check('step 2 has no screenshot (none provided) but still emits a span', s2?.kind === 'tool' && s2?.attributes?.screenshot === undefined)
|
|
64
|
-
check('step 2 carries the actionBounds overlay', JSON.stringify(s2?.attributes?.actionBounds) === JSON.stringify({ x: 10, y: 20, width: 80, height: 30 }))
|
|
65
|
-
|
|
66
|
-
check('the answer span closes the film', answer?.kind === 'custom' && answer?.name === 'final answer' && (answer?.attributes as { answer?: string })?.answer === 'Delivered')
|
|
67
|
-
check('timestamps are monotonic from startTs', (s1?.startedAt ?? 0) >= 1000 && (answer?.startedAt ?? 0) > (s1?.startedAt ?? 0))
|
|
68
|
-
|
|
69
|
-
// Inline base64 screenshot (the real `bad` case — state.screenshot, no disk path):
|
|
70
|
-
// used directly, no file read.
|
|
71
|
-
const inlineRun = await browserRunToSpans({
|
|
72
|
-
taskId: 't', driverId: 'bad', finalUrl: 'https://x.test',
|
|
73
|
-
steps: [{ index: 1, url: 'https://x.test', action: 'click', screenshot: 'data:image/jpeg;base64,/9j/INLINE' }],
|
|
74
|
-
})
|
|
75
|
-
check('inline step.screenshot is carried through directly (no disk read)', (inlineRun[0]?.attributes?.screenshot as string) === 'data:image/jpeg;base64,/9j/INLINE')
|
|
76
|
-
|
|
77
|
-
// A run whose only screenshot path is unreadable: span stays, image drops (fail-soft).
|
|
78
|
-
const ghost = await browserRunToSpans({
|
|
79
|
-
taskId: 't', driverId: 'bad', finalUrl: '', steps: [{ index: 1, url: 'about:blank', action: 'navigate', screenshotPath: '/no/such/frame.png' }],
|
|
80
|
-
})
|
|
81
|
-
check('unreadable screenshot drops the image but keeps the step span', ghost.length === 1 && ghost[0]?.attributes?.screenshot === undefined)
|
|
82
|
-
|
|
83
|
-
rmSync(dir, { recursive: true, force: true })
|
|
84
|
-
|
|
85
|
-
if (failures > 0) {
|
|
86
|
-
console.log(`\n❌ ${failures} check(s) failed`)
|
|
87
|
-
process.exit(1)
|
|
88
|
-
}
|
|
89
|
-
console.log('\n✅ browserRunToSpans verified — steps → tool spans, screenshots inlined as base64, no raw paths')
|