@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,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-arm AgentProfiles for the coding-harness web-search comparison.
|
|
3
|
-
*
|
|
4
|
-
* Three arms, one variable (the search backend the agent can reach):
|
|
5
|
-
* - `native` — the harness's built-in web search/fetch, untouched. No MCP.
|
|
6
|
-
* - `provider` — native search DISABLED + a router-backed search MCP added
|
|
7
|
-
* (provider-pinned: you / exa / …). The agent's only web access is the MCP.
|
|
8
|
-
*
|
|
9
|
-
* The disable directive is the harness-agnostic `tools` map landed in
|
|
10
|
-
* agent-dev-container#1810 (claude `--disallowed-tools`, codex
|
|
11
|
-
* `-c tools.web_search=false`, opencode `tools.{websearch,webfetch}`). We set
|
|
12
|
-
* both canonical (`web_search`/`web_fetch`) and opencode-native
|
|
13
|
-
* (`websearch`/`webfetch`) keys so a single profile is correct on every harness
|
|
14
|
-
* pre- and post-deploy, plus the opencode `permission.webfetch=deny` belt.
|
|
15
|
-
*
|
|
16
|
-
* The provider MCP mirrors the SDK's official `buildTangleRouterSearchProfile`
|
|
17
|
-
* shape — a `transport:'http'` server at the router's `/v1/search/mcp` endpoint,
|
|
18
|
-
* provider pinned via the `?provider=` query param.
|
|
19
|
-
*/
|
|
20
|
-
import {
|
|
21
|
-
type AgentProfile,
|
|
22
|
-
type HarnessType,
|
|
23
|
-
agentProfileSchema,
|
|
24
|
-
defineAgentProfileSecretRef,
|
|
25
|
-
} from '@tangle-network/agent-interface'
|
|
26
|
-
|
|
27
|
-
export type SearchArm = 'native' | 'off' | { provider: string }
|
|
28
|
-
|
|
29
|
-
const routerSearchMcpUrl = (provider: string, routerBaseUrl: string): string => {
|
|
30
|
-
// routerBaseUrl is typically https://router.tangle.tools/v1 — the search MCP
|
|
31
|
-
// lives at /v1/search/mcp, so trim a trailing /v1 then re-append the path.
|
|
32
|
-
const root = routerBaseUrl.replace(/\/+$/, '').replace(/\/v1$/, '')
|
|
33
|
-
return `${root}/v1/search/mcp?provider=${encodeURIComponent(provider)}`
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Tool keys that turn OFF a harness's native web search/fetch across harnesses. */
|
|
37
|
-
const nativeWebToolsDisabled: Record<string, boolean> = {
|
|
38
|
-
web_search: false,
|
|
39
|
-
web_fetch: false,
|
|
40
|
-
websearch: false,
|
|
41
|
-
webfetch: false,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface BuildArmProfileArgs {
|
|
45
|
-
arm: SearchArm
|
|
46
|
-
/** Router base URL (…/v1). Used to derive the search-MCP endpoint. */
|
|
47
|
-
routerBaseUrl: string
|
|
48
|
-
/** Bearer for the router search MCP. Required for a provider arm. Valid for the
|
|
49
|
-
* `bridge` (local) backend; in `sandbox` mode the box egress proxy rejects
|
|
50
|
-
* foreign router credentials (403), so the provider arm needs the box-side
|
|
51
|
-
* credential flow before sandbox-backed provider runs are trustworthy. */
|
|
52
|
-
tangleApiKey: string
|
|
53
|
-
harness: HarnessType
|
|
54
|
-
model: string
|
|
55
|
-
provider: string
|
|
56
|
-
/** Optional name/metadata to merge. */
|
|
57
|
-
name?: string
|
|
58
|
-
metadata?: Record<string, unknown>
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Build the complete executable AgentProfile for one search arm.
|
|
63
|
-
*/
|
|
64
|
-
export function buildArmProfile(args: BuildArmProfileArgs): AgentProfile {
|
|
65
|
-
const { arm, routerBaseUrl, tangleApiKey } = args
|
|
66
|
-
const base: AgentProfile = {
|
|
67
|
-
name: args.name ?? 'search-bench-worker',
|
|
68
|
-
harness: args.harness,
|
|
69
|
-
model: { provider: args.provider, default: args.model },
|
|
70
|
-
...(args.metadata ? { metadata: args.metadata } : {}),
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (arm === 'native') {
|
|
74
|
-
// Native web tools stay on (harness default). No search MCP. For codex,
|
|
75
|
-
// whose web_search ships off, explicitly enable it so the native arm is real.
|
|
76
|
-
return agentProfileSchema.parse({ ...base, tools: { web_search: true } })
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (arm === 'off') {
|
|
80
|
-
// No web access at all — the parametric floor (search contributes nothing).
|
|
81
|
-
return agentProfileSchema.parse({
|
|
82
|
-
...base,
|
|
83
|
-
tools: { ...nativeWebToolsDisabled },
|
|
84
|
-
permission: { webfetch: 'deny' },
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!tangleApiKey) {
|
|
89
|
-
throw new Error(`buildArmProfile: provider arm "${arm.provider}" requires a tangleApiKey for the search MCP`)
|
|
90
|
-
}
|
|
91
|
-
return agentProfileSchema.parse({
|
|
92
|
-
...base,
|
|
93
|
-
tools: { ...nativeWebToolsDisabled },
|
|
94
|
-
permission: { webfetch: 'deny' },
|
|
95
|
-
mcp: {
|
|
96
|
-
tangle_search: {
|
|
97
|
-
transport: 'http',
|
|
98
|
-
url: routerSearchMcpUrl(arm.provider, routerBaseUrl),
|
|
99
|
-
headers: {
|
|
100
|
-
Authorization: defineAgentProfileSecretRef('TANGLE_API_KEY', 'bearer'),
|
|
101
|
-
},
|
|
102
|
-
enabled: true,
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** Stable condition label for the corpus: `<harness>:<arm>`. */
|
|
109
|
-
export function armLabel(arm: SearchArm): string {
|
|
110
|
-
if (arm === 'native') return 'native'
|
|
111
|
-
if (arm === 'off') return 'off'
|
|
112
|
-
return arm.provider
|
|
113
|
-
}
|
package/src/search-bench/run.mts
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coding-harness × web-search-backend benchmark runner.
|
|
3
|
-
*
|
|
4
|
-
* For each (task × harness × arm) cell: spin up a live sandbox, run the coding
|
|
5
|
-
* task once through the harness with that arm's AgentProfile (native search /
|
|
6
|
-
* provider-MCP+native-disabled), score the answer with the task's deterministic
|
|
7
|
-
* oracle, and record score + cost + tokens + latency + tool-call count +
|
|
8
|
-
* citations. Cells are concurrency-bounded and fault-isolated; an infra-errored
|
|
9
|
-
* cell is recorded as such and excluded from rates (never a silent zero).
|
|
10
|
-
*
|
|
11
|
-
* Run (opencode, you.com vs native, seed tasks):
|
|
12
|
-
* dotenvx run -f ~/company/devops/secrets/.env.keys -f ~/company/devops/secrets/agent-state.env -- \
|
|
13
|
-
* env HARNESSES=opencode ARMS=native,you MODEL=opencode/deepseek/deepseek-v4-flash \
|
|
14
|
-
* OUT=/tmp/search-bench.jsonl pnpm exec tsx src/search-bench/run.mts
|
|
15
|
-
*/
|
|
16
|
-
import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
17
|
-
import { dirname } from 'node:path'
|
|
18
|
-
import { extractLlmCallEvent, openSandboxRun } from '@tangle-network/agent-runtime/kernel'
|
|
19
|
-
import { Sandbox, type SandboxEvent } from '@tangle-network/sandbox'
|
|
20
|
-
import { answerOutput, sandboxAgentRun, type WorkerBackendType } from '../sandbox-run'
|
|
21
|
-
import { type BridgeCfg, runBridgeCell } from './bridge'
|
|
22
|
-
import { type SearchArm, armLabel, buildArmProfile } from './profiles'
|
|
23
|
-
import { freshTasks } from './tasks-fresh'
|
|
24
|
-
import { type SearchTask, scoreTask, seedTasks, taskToPrompt } from './tasks'
|
|
25
|
-
|
|
26
|
-
export interface SearchCellResult {
|
|
27
|
-
taskId: string
|
|
28
|
-
domain: string
|
|
29
|
-
harness: string
|
|
30
|
-
/** Search arm: 'native' | 'off' | provider id (e.g. 'you', 'exa'). */
|
|
31
|
-
arm: string
|
|
32
|
-
model: string
|
|
33
|
-
/** Deterministic oracle outcome. null ⇒ infra error (excluded from rates). */
|
|
34
|
-
score: 0 | 1 | null
|
|
35
|
-
reasons: string[]
|
|
36
|
-
costUsd?: number
|
|
37
|
-
tokensIn?: number
|
|
38
|
-
tokensOut?: number
|
|
39
|
-
wallMs: number
|
|
40
|
-
/** Distinct tool calls observed (evidence the agent actually searched). */
|
|
41
|
-
toolCalls: number
|
|
42
|
-
/** Tool names used — distinguishes native (`webfetch`) from the provider MCP. */
|
|
43
|
-
toolNames: string[]
|
|
44
|
-
/** Distinct http(s) URLs cited in the answer. */
|
|
45
|
-
citations: string[]
|
|
46
|
-
/** Final answer text (truncated in the export; full in the raw JSONL). */
|
|
47
|
-
answer: string
|
|
48
|
-
infraError?: string
|
|
49
|
-
ts: string
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const urlRe = /https?:\/\/[^\s)\]}"'<>]+/gi
|
|
53
|
-
|
|
54
|
-
function extractCitations(answer: string): string[] {
|
|
55
|
-
const seen = new Set<string>()
|
|
56
|
-
for (const m of answer.match(urlRe) ?? []) seen.add(m.replace(/[.,;]+$/, ''))
|
|
57
|
-
return [...seen]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Sum token usage + cost across the run's llm_call events (the kernel's ledger). */
|
|
61
|
-
function tally(events: SandboxEvent[]): { costUsd?: number; tokensIn?: number; tokensOut?: number } {
|
|
62
|
-
let costUsd = 0
|
|
63
|
-
let tokensIn = 0
|
|
64
|
-
let tokensOut = 0
|
|
65
|
-
let any = false
|
|
66
|
-
for (const ev of events) {
|
|
67
|
-
const call = extractLlmCallEvent(ev as never, 'search-bench')
|
|
68
|
-
if (!call) continue
|
|
69
|
-
any = true
|
|
70
|
-
costUsd += call.costUsd ?? 0
|
|
71
|
-
tokensIn += call.tokensIn ?? 0
|
|
72
|
-
tokensOut += call.tokensOut ?? 0
|
|
73
|
-
}
|
|
74
|
-
return any ? { costUsd, tokensIn, tokensOut } : {}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Distinct tool calls + the tool names used. opencode emits a tool call as
|
|
79
|
-
* repeated `message.part.updated` events sharing a `data.part.callID` with
|
|
80
|
-
* `data.part.type==='tool'` and `data.part.tool` the name (e.g. `webfetch`,
|
|
81
|
-
* or an MCP tool like `tangle_search_web_search`). We dedupe by callID so a
|
|
82
|
-
* single call counts once, and surface the names so the export can show which
|
|
83
|
-
* search backend the agent actually used (native vs the provider MCP).
|
|
84
|
-
*/
|
|
85
|
-
function extractTools(events: SandboxEvent[]): { count: number; names: string[] } {
|
|
86
|
-
const calls = new Map<string, string>()
|
|
87
|
-
for (const ev of events) {
|
|
88
|
-
const part = (ev as { data?: { part?: Record<string, unknown> } }).data?.part
|
|
89
|
-
if (!part || typeof part !== 'object' || part.type !== 'tool') continue
|
|
90
|
-
const callId = typeof part.callID === 'string' ? part.callID : `${calls.size}`
|
|
91
|
-
const name = typeof part.tool === 'string' ? part.tool : 'unknown'
|
|
92
|
-
calls.set(callId, name)
|
|
93
|
-
}
|
|
94
|
-
return { count: calls.size, names: [...new Set(calls.values())] }
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface RunCfg {
|
|
98
|
-
tasks: SearchTask[]
|
|
99
|
-
harnesses: WorkerBackendType[]
|
|
100
|
-
arms: SearchArm[]
|
|
101
|
-
model: string
|
|
102
|
-
routerBaseUrl: string
|
|
103
|
-
tangleApiKey: string
|
|
104
|
-
sandboxBaseUrl: string
|
|
105
|
-
sandboxKey: string
|
|
106
|
-
outPath: string
|
|
107
|
-
/** In-box model provider — `openai` (default) or `openai-compat` for cheap models. */
|
|
108
|
-
provider?: string
|
|
109
|
-
/** Execution surface: `sandbox` (live box) or `bridge` (local cli-bridge). */
|
|
110
|
-
backend?: 'sandbox' | 'bridge'
|
|
111
|
-
/** cli-bridge wiring, required when `backend === 'bridge'`. */
|
|
112
|
-
bridge?: BridgeCfg
|
|
113
|
-
concurrency?: number
|
|
114
|
-
timeoutMs?: number
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function runCell(
|
|
118
|
-
cfg: RunCfg,
|
|
119
|
-
client: Sandbox,
|
|
120
|
-
task: SearchTask,
|
|
121
|
-
harness: WorkerBackendType,
|
|
122
|
-
arm: SearchArm,
|
|
123
|
-
): Promise<SearchCellResult> {
|
|
124
|
-
const startedAt = Date.now()
|
|
125
|
-
const armId = armLabel(arm)
|
|
126
|
-
const base = {
|
|
127
|
-
taskId: task.id,
|
|
128
|
-
domain: task.domain,
|
|
129
|
-
harness,
|
|
130
|
-
arm: armId,
|
|
131
|
-
model: cfg.model,
|
|
132
|
-
ts: new Date(startedAt).toISOString(),
|
|
133
|
-
}
|
|
134
|
-
const controller = new AbortController()
|
|
135
|
-
const timer = setTimeout(() => controller.abort(), cfg.timeoutMs ?? 300_000)
|
|
136
|
-
try {
|
|
137
|
-
const agentRun = sandboxAgentRun({
|
|
138
|
-
profile: buildArmProfile({
|
|
139
|
-
arm,
|
|
140
|
-
routerBaseUrl: cfg.routerBaseUrl,
|
|
141
|
-
tangleApiKey: cfg.tangleApiKey,
|
|
142
|
-
harness,
|
|
143
|
-
model: cfg.model,
|
|
144
|
-
provider: cfg.provider ?? 'openai',
|
|
145
|
-
name: `search-bench-${harness}-${armId}`,
|
|
146
|
-
metadata: { harness, arm: armId, taskId: task.id },
|
|
147
|
-
}),
|
|
148
|
-
})
|
|
149
|
-
const run = await openSandboxRun<string>(
|
|
150
|
-
client,
|
|
151
|
-
{ agentRun, signal: controller.signal },
|
|
152
|
-
{ kind: 'events', fromEvents: (events) => answerOutput.parse(events as never) },
|
|
153
|
-
)
|
|
154
|
-
let turn: Awaited<ReturnType<typeof run.start>>
|
|
155
|
-
try {
|
|
156
|
-
turn = await run.start(taskToPrompt(task))
|
|
157
|
-
} finally {
|
|
158
|
-
await run.close().catch(() => {})
|
|
159
|
-
}
|
|
160
|
-
if (process.env.DUMP_EVENTS) {
|
|
161
|
-
writeFileSync(process.env.DUMP_EVENTS, JSON.stringify(turn.events, null, 2))
|
|
162
|
-
}
|
|
163
|
-
const answer = turn.out ?? ''
|
|
164
|
-
const { score, reasons } = scoreTask(task, answer)
|
|
165
|
-
const tools = extractTools(turn.events)
|
|
166
|
-
return {
|
|
167
|
-
...base,
|
|
168
|
-
score,
|
|
169
|
-
reasons,
|
|
170
|
-
...tally(turn.events),
|
|
171
|
-
wallMs: Date.now() - startedAt,
|
|
172
|
-
toolCalls: tools.count,
|
|
173
|
-
toolNames: tools.names,
|
|
174
|
-
citations: extractCitations(answer),
|
|
175
|
-
answer,
|
|
176
|
-
}
|
|
177
|
-
} catch (err) {
|
|
178
|
-
return {
|
|
179
|
-
...base,
|
|
180
|
-
score: null,
|
|
181
|
-
reasons: [],
|
|
182
|
-
wallMs: Date.now() - startedAt,
|
|
183
|
-
toolCalls: 0,
|
|
184
|
-
toolNames: [],
|
|
185
|
-
citations: [],
|
|
186
|
-
answer: '',
|
|
187
|
-
infraError: err instanceof Error ? err.message : String(err),
|
|
188
|
-
}
|
|
189
|
-
} finally {
|
|
190
|
-
clearTimeout(timer)
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export async function runSearchBench(cfg: RunCfg): Promise<SearchCellResult[]> {
|
|
195
|
-
const useBridge = cfg.backend === 'bridge'
|
|
196
|
-
if (useBridge && !cfg.bridge) throw new Error('backend=bridge requires cfg.bridge')
|
|
197
|
-
const client = useBridge ? null : new Sandbox({ baseUrl: cfg.sandboxBaseUrl, apiKey: cfg.sandboxKey })
|
|
198
|
-
const runOne = (task: SearchTask, harness: WorkerBackendType, arm: SearchArm): Promise<SearchCellResult> =>
|
|
199
|
-
useBridge ? runBridgeCell(cfg.bridge!, task, harness, arm) : runCell(cfg, client!, task, harness, arm)
|
|
200
|
-
const cells: Array<{ task: SearchTask; harness: WorkerBackendType; arm: SearchArm }> = []
|
|
201
|
-
for (const task of cfg.tasks)
|
|
202
|
-
for (const harness of cfg.harnesses) for (const arm of cfg.arms) cells.push({ task, harness, arm })
|
|
203
|
-
|
|
204
|
-
mkdirSync(dirname(cfg.outPath), { recursive: true })
|
|
205
|
-
writeFileSync(cfg.outPath, '')
|
|
206
|
-
const results: SearchCellResult[] = []
|
|
207
|
-
const conc = cfg.concurrency ?? 3
|
|
208
|
-
let next = 0
|
|
209
|
-
const worker = async (): Promise<void> => {
|
|
210
|
-
while (next < cells.length) {
|
|
211
|
-
const i = next++
|
|
212
|
-
const { task, harness, arm } = cells[i]
|
|
213
|
-
const r = await runOne(task, harness, arm)
|
|
214
|
-
results.push(r)
|
|
215
|
-
appendFileSync(cfg.outPath, `${JSON.stringify(r)}\n`)
|
|
216
|
-
const mark = r.score === null ? 'ERR' : r.score === 1 ? 'PASS' : 'fail'
|
|
217
|
-
console.error(
|
|
218
|
-
`[${i + 1}/${cells.length}] ${harness}:${armLabel(arm)} ${task.id} → ${mark}` +
|
|
219
|
-
(r.infraError ? ` (${r.infraError})` : ` tools=${r.toolCalls}[${r.toolNames.join(',')}] cites=${r.citations.length} ${Math.round(r.wallMs / 1000)}s`),
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
await Promise.all(Array.from({ length: Math.min(conc, cells.length) }, () => worker()))
|
|
224
|
-
return results
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// ── CLI ──────────────────────────────────────────────────────────────────────
|
|
228
|
-
function env(name: string, fallback?: string): string {
|
|
229
|
-
const v = process.env[name] ?? fallback
|
|
230
|
-
if (v === undefined) throw new Error(`missing env ${name}`)
|
|
231
|
-
return v
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async function main(): Promise<void> {
|
|
235
|
-
const harnesses = env('HARNESSES', 'opencode').split(',').map((s) => s.trim()) as WorkerBackendType[]
|
|
236
|
-
const arms: SearchArm[] = env('ARMS', 'native,you')
|
|
237
|
-
.split(',')
|
|
238
|
-
.map((s) => s.trim())
|
|
239
|
-
.map((s) => (s === 'native' || s === 'off' ? s : { provider: s }))
|
|
240
|
-
const tangleApiKey = env('TANGLE_API_KEY')
|
|
241
|
-
const backend = env('BACKEND', 'sandbox') as 'sandbox' | 'bridge'
|
|
242
|
-
let bridge: BridgeCfg | undefined
|
|
243
|
-
if (backend === 'bridge') {
|
|
244
|
-
bridge = {
|
|
245
|
-
bridgeUrl: env('BRIDGE_URL', 'http://127.0.0.1:3355'),
|
|
246
|
-
bridgeBearer: env('BRIDGE_BEARER'),
|
|
247
|
-
tangleApiKey,
|
|
248
|
-
routerSearchMcp: env('ROUTER_SEARCH_MCP', 'https://router.tangle.tools/v1/search/mcp'),
|
|
249
|
-
bridgeModels: JSON.parse(
|
|
250
|
-
env('BRIDGE_MODELS', '{"claude-code":"claude-code/sonnet","opencode":"opencode/zai-coding-plan/glm-5.1"}'),
|
|
251
|
-
) as Record<string, string>,
|
|
252
|
-
timeoutMs: Number(env('TIMEOUT_MS', '300000')),
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
const taskSet = (process.env.TASK_SET ?? 'fresh') === 'seed' ? seedTasks : freshTasks
|
|
256
|
-
const onlyIds = (process.env.TASK_IDS ?? '').split(',').map((s) => s.trim()).filter(Boolean)
|
|
257
|
-
const tasks = onlyIds.length ? taskSet.filter((t) => onlyIds.includes(t.id)) : taskSet
|
|
258
|
-
if (tasks.length === 0) throw new Error(`no tasks matched TASK_IDS=${process.env.TASK_IDS} in TASK_SET=${process.env.TASK_SET ?? 'fresh'}`)
|
|
259
|
-
const results = await runSearchBench({
|
|
260
|
-
tasks,
|
|
261
|
-
harnesses,
|
|
262
|
-
arms,
|
|
263
|
-
backend,
|
|
264
|
-
...(bridge ? { bridge } : {}),
|
|
265
|
-
model: env('MODEL', 'opencode/deepseek/deepseek-v4-flash'),
|
|
266
|
-
routerBaseUrl: env('ROUTER_BASE_URL', 'https://router.tangle.tools/v1'),
|
|
267
|
-
tangleApiKey,
|
|
268
|
-
sandboxBaseUrl: env('SANDBOX_BASE_URL', 'https://sandbox.tangle.tools'),
|
|
269
|
-
sandboxKey: env('SANDBOX_KEY', tangleApiKey),
|
|
270
|
-
provider: env('PROVIDER', 'openai'),
|
|
271
|
-
outPath: env('OUT', '/tmp/search-bench.jsonl'),
|
|
272
|
-
concurrency: Number(env('CONCURRENCY', '3')),
|
|
273
|
-
timeoutMs: Number(env('TIMEOUT_MS', '300000')),
|
|
274
|
-
})
|
|
275
|
-
const scored = results.filter((r) => r.score !== null)
|
|
276
|
-
console.error(
|
|
277
|
-
`\nDone: ${results.length} cells, ${scored.length} scored, ${results.length - scored.length} infra-errored → ${env('OUT', '/tmp/search-bench.jsonl')}`,
|
|
278
|
-
)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
282
|
-
main().catch((e) => {
|
|
283
|
-
console.error(e)
|
|
284
|
-
process.exit(1)
|
|
285
|
-
})
|
|
286
|
-
}
|