@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.
Files changed (218) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +2 -3
  3. package/dist/adapters.d.ts +2 -5
  4. package/dist/adapters.js +3 -4
  5. package/dist/benchmarks/_harness.d.ts +17 -20
  6. package/dist/benchmarks/_harness.js +4 -4
  7. package/dist/benchmarks/_harness.js.map +1 -1
  8. package/dist/benchmarks/aec-bench.d.ts +1 -4
  9. package/dist/benchmarks/aec-bench.js +1 -2
  10. package/dist/benchmarks/agentbench.d.ts +2 -5
  11. package/dist/benchmarks/agentbench.js +1 -2
  12. package/dist/benchmarks/appworld.d.ts +8 -10
  13. package/dist/benchmarks/appworld.js +23 -23
  14. package/dist/benchmarks/appworld.js.map +1 -1
  15. package/dist/benchmarks/bfcl.d.ts +2 -5
  16. package/dist/benchmarks/bfcl.js +1 -2
  17. package/dist/benchmarks/cad-design.d.ts +2 -5
  18. package/dist/benchmarks/cad-design.js +2 -3
  19. package/dist/benchmarks/cad-design.js.map +1 -1
  20. package/dist/benchmarks/cadbench.d.ts +1 -4
  21. package/dist/benchmarks/cadbench.js +1 -2
  22. package/dist/benchmarks/cadgenbench.d.ts +1 -4
  23. package/dist/benchmarks/cadgenbench.js +1 -2
  24. package/dist/benchmarks/commit0.d.ts +2 -5
  25. package/dist/benchmarks/commit0.js +1 -2
  26. package/dist/benchmarks/crag.d.ts +1 -4
  27. package/dist/benchmarks/crag.js +3 -3
  28. package/dist/benchmarks/crag.js.map +1 -1
  29. package/dist/benchmarks/dabstep.d.ts +2 -5
  30. package/dist/benchmarks/dabstep.js +2 -3
  31. package/dist/benchmarks/dabstep.js.map +1 -1
  32. package/dist/benchmarks/enterpriseops-gym.d.ts +2 -5
  33. package/dist/benchmarks/enterpriseops-gym.js +1 -2
  34. package/dist/benchmarks/finresearchbench.d.ts +2 -5
  35. package/dist/benchmarks/finresearchbench.js +2 -3
  36. package/dist/benchmarks/finsearchcomp.d.ts +2 -5
  37. package/dist/benchmarks/finsearchcomp.js +4 -4
  38. package/dist/benchmarks/finsearchcomp.js.map +1 -1
  39. package/dist/benchmarks/frames.d.ts +3 -19
  40. package/dist/benchmarks/frames.js +13 -39
  41. package/dist/benchmarks/frames.js.map +1 -1
  42. package/dist/benchmarks/hotpotqa.d.ts +4 -14
  43. package/dist/benchmarks/hotpotqa.js +12 -32
  44. package/dist/benchmarks/hotpotqa.js.map +1 -1
  45. package/dist/benchmarks/humaneval.d.ts +9 -12
  46. package/dist/benchmarks/humaneval.js +2 -3
  47. package/dist/benchmarks/humaneval.js.map +1 -1
  48. package/dist/benchmarks/mcad-bench.d.ts +13 -16
  49. package/dist/benchmarks/mcad-bench.js +2 -3
  50. package/dist/benchmarks/mcad-bench.js.map +1 -1
  51. package/dist/benchmarks/mcad-cq-bench.d.ts +17 -20
  52. package/dist/benchmarks/mcad-cq-bench.js +2 -3
  53. package/dist/benchmarks/mcad-cq-bench.js.map +1 -1
  54. package/dist/benchmarks/mcad-cq-golds.d.ts +2 -5
  55. package/dist/benchmarks/mcad-cq-golds.js +1 -2
  56. package/dist/benchmarks/mcad-golds.d.ts +1 -4
  57. package/dist/benchmarks/mcad-golds.js +0 -1
  58. package/dist/benchmarks/mcad-tasks.d.ts +5 -8
  59. package/dist/benchmarks/mcad-tasks.js +7 -8
  60. package/dist/benchmarks/mcad-tasks.js.map +1 -1
  61. package/dist/benchmarks/mind2web.d.ts +3 -5
  62. package/dist/benchmarks/mind2web.js +2 -3
  63. package/dist/benchmarks/mind2web.js.map +1 -1
  64. package/dist/benchmarks/nomiracl.d.ts +1 -4
  65. package/dist/benchmarks/nomiracl.js +1 -2
  66. package/dist/benchmarks/open-rag-bench.d.ts +1 -4
  67. package/dist/benchmarks/open-rag-bench.js +3 -3
  68. package/dist/benchmarks/open-rag-bench.js.map +1 -1
  69. package/dist/benchmarks/programbench.d.ts +2 -5
  70. package/dist/benchmarks/programbench.js +1 -2
  71. package/dist/benchmarks/rag-shared.d.ts +30 -22
  72. package/dist/benchmarks/rag-shared.js +8 -2
  73. package/dist/benchmarks/rag-shared.js.map +1 -1
  74. package/dist/benchmarks/ragbench.d.ts +1 -4
  75. package/dist/benchmarks/ragbench.js +3 -3
  76. package/dist/benchmarks/ragbench.js.map +1 -1
  77. package/dist/benchmarks/simpleqa.d.ts +2 -18
  78. package/dist/benchmarks/simpleqa.js +5 -31
  79. package/dist/benchmarks/simpleqa.js.map +1 -1
  80. package/dist/benchmarks/swe-bench.d.ts +7 -10
  81. package/dist/benchmarks/swe-bench.js +4 -4
  82. package/dist/benchmarks/swe-bench.js.map +1 -1
  83. package/dist/benchmarks/t2-ragbench.d.ts +1 -4
  84. package/dist/benchmarks/t2-ragbench.js +3 -3
  85. package/dist/benchmarks/t2-ragbench.js.map +1 -1
  86. package/dist/benchmarks/tau-bench-shared.d.ts +5 -8
  87. package/dist/benchmarks/tau-bench-shared.js +4 -4
  88. package/dist/benchmarks/tau-bench-shared.js.map +1 -1
  89. package/dist/benchmarks/tau2-bench.d.ts +2 -5
  90. package/dist/benchmarks/tau2-bench.js +1 -2
  91. package/dist/benchmarks/tau3-banking.d.ts +1 -4
  92. package/dist/benchmarks/tau3-banking.js +1 -2
  93. package/dist/benchmarks/terminal-bench.d.ts +1 -4
  94. package/dist/benchmarks/terminal-bench.js +4 -4
  95. package/dist/benchmarks/terminal-bench.js.map +1 -1
  96. package/dist/benchmarks/toollm.d.ts +2 -5
  97. package/dist/benchmarks/toollm.js +1 -2
  98. package/dist/benchmarks/trata-hedge.d.ts +1 -4
  99. package/dist/benchmarks/trata-hedge.js +2 -3
  100. package/dist/benchmarks/types.d.ts +6 -9
  101. package/dist/benchmarks/webarena-verified.d.ts +2 -5
  102. package/dist/benchmarks/webarena-verified.js +1 -2
  103. package/dist/{cadbench-BRF-59Mt.js → cadbench-DhAndllg.js} +4 -6
  104. package/dist/cadbench-DhAndllg.js.map +1 -0
  105. package/dist/{cadgenbench-DXtGkuW3.js → cadgenbench-Tvk16YKT.js} +15 -5
  106. package/dist/cadgenbench-Tvk16YKT.js.map +1 -0
  107. package/dist/index.d.ts +8 -18
  108. package/dist/index.js +16 -24
  109. package/dist/index.js.map +1 -1
  110. package/dist/{router-turn-uTYO6KQ1.js → router-turn-DNbQ_GjQ.js} +2 -3
  111. package/dist/router-turn-DNbQ_GjQ.js.map +1 -0
  112. package/fixtures/pier-agent/no-model-task/pre_artifacts.sh +0 -0
  113. package/fixtures/pier-agent/no-model-task/tests/test.sh +0 -0
  114. package/package.json +10 -10
  115. package/pier_agents/tangle_candidate.py +15 -23
  116. package/scripts/run-package-tests.mjs +8 -15
  117. package/scripts/verify-packed-consumer.mjs +0 -1
  118. package/src/atom-mcp-e2e.mts +16 -4
  119. package/src/benchmarks/frames.ts +10 -44
  120. package/src/benchmarks/hotpotqa.ts +9 -29
  121. package/src/benchmarks/rag-shared.ts +12 -0
  122. package/src/benchmarks/simpleqa.ts +2 -36
  123. package/src/commit0-prereqs.sh +0 -0
  124. package/src/corpus-replay.mts +8 -8
  125. package/src/corpus-report.mts +21 -21
  126. package/src/corpus.test.mts +5 -5
  127. package/src/corpus.ts +16 -16
  128. package/src/directives.ts +0 -38
  129. package/src/examples/lean-verify.ts +1 -1
  130. package/src/gate.ts +8 -8
  131. package/src/generate-eval/certify.ts +2 -2
  132. package/src/index.ts +1 -0
  133. package/src/refine-loop.ts +5 -5
  134. package/src/resolve-client.ts +1 -1
  135. package/src/router-turn.ts +3 -11
  136. package/src/run-benchmarks.test.mts +0 -4
  137. package/src/run-pool.ts +1 -1
  138. package/src/runtime-hook-recorder.ts +2 -2
  139. package/src/search-bench/tasks.ts +1 -1
  140. package/src/selector.test.mts +13 -13
  141. package/src/selector.ts +19 -19
  142. package/src/swe-bench-env.ts +4 -12
  143. package/src/swe-jail.ts +5 -156
  144. package/src/swe-structural-judge-policy.ts +3 -3
  145. package/src/swe-structural-policy.ts +3 -3
  146. package/src/swe-structural-provenance.ts +4 -4
  147. package/src/terminal-compare.ts +10 -10
  148. package/src/worker-blender.ts +2 -106
  149. package/src/worker-build123d.ts +2 -81
  150. package/tb_agents/opencode_router_agent.py +1 -1
  151. package/dist/cadbench-BRF-59Mt.js.map +0 -1
  152. package/dist/cadgenbench-DXtGkuW3.js.map +0 -1
  153. package/dist/router-turn-uTYO6KQ1.js.map +0 -1
  154. package/scripts/cadbench_prepare.py +0 -22
  155. package/scripts/cadgenbench_hard_parts.py +0 -48
  156. package/scripts/clbench_codebase_judge.py +0 -73
  157. package/scripts/render-gate-chart.mjs +0 -176
  158. package/scripts/trata-hedge/README.md +0 -57
  159. package/scripts/trata-hedge/run.sh +0 -64
  160. package/src/browser/adapters/bad-design-audit.ts +0 -153
  161. package/src/browser/adapters/bad-design-audit.verify.ts +0 -85
  162. package/src/browser/adapters/bad.ts +0 -165
  163. package/src/browser/agent-adapter.ts +0 -145
  164. package/src/browser/process-adapter.ts +0 -146
  165. package/src/browser/run-to-spans.ts +0 -105
  166. package/src/browser/run-to-spans.verify.ts +0 -89
  167. package/src/browser/ui-reviewer.ts +0 -200
  168. package/src/browser/ui-reviewer.verify.ts +0 -94
  169. package/src/browser/verify.ts +0 -96
  170. package/src/clbench-codebase-gate.mts +0 -314
  171. package/src/clbench-context-gate.mts +0 -341
  172. package/src/cloud-loop.mts +0 -156
  173. package/src/commit0-env-run.mts +0 -62
  174. package/src/commit0-env.ts +0 -172
  175. package/src/commit0-gate.mts +0 -558
  176. package/src/coordination-mcp-container-reach.mts +0 -182
  177. package/src/egress-probe.mts +0 -26
  178. package/src/fleet.mts +0 -143
  179. package/src/hev-structural.mts +0 -697
  180. package/src/humaneval-gate.mts +0 -220
  181. package/src/humaneval-repair-gate.mts +0 -182
  182. package/src/mbpp-structural.mts +0 -676
  183. package/src/mcp-mount-probe.mts +0 -139
  184. package/src/profile-coordinates.ts +0 -134
  185. package/src/profiles.ts +0 -128
  186. package/src/research-gate.mts +0 -132
  187. package/src/research-shot.ts +0 -144
  188. package/src/router-executor.ts +0 -51
  189. package/src/run-benchmarks-report.ts +0 -66
  190. package/src/sandbox-run.ts +0 -108
  191. package/src/search-bench/bridge.ts +0 -182
  192. package/src/search-bench/export.mts +0 -0
  193. package/src/search-bench/parametric-check.mts +0 -78
  194. package/src/search-bench/profiles.ts +0 -113
  195. package/src/search-bench/run.mts +0 -286
  196. package/src/search-bench/tasks-fresh.ts +0 -688
  197. package/src/skill-sandbox-smoke.mts +0 -101
  198. package/src/smoke-structural-rollout.mts +0 -415
  199. package/src/stats.mts +0 -90
  200. package/src/supervisor-arena.mts +0 -825
  201. package/src/swe-code-improve.mts +0 -306
  202. package/src/swe-emit-patch.mts +0 -125
  203. package/src/swe-improve.mts +0 -284
  204. package/src/swe-local-proof.mts +0 -265
  205. package/src/swe-repro-calibrate.mts +0 -451
  206. package/src/swe-stream.mts +0 -1561
  207. package/src/swe-structural.mts +0 -707
  208. package/src/tb-container-executor.mts +0 -266
  209. package/src/tb-container-executor.test.mts +0 -134
  210. package/src/tb-supervisor-sidecar.mts +0 -208
  211. package/src/trajectory-assemble.mjs +0 -130
  212. package/src/trata-gepa.mts +0 -381
  213. package/src/trata-hedge-solve.mts +0 -81
  214. package/src/worker-browser.ts +0 -115
  215. package/src/worker-cad.ts +0 -470
  216. package/src/workspace-loop.mts +0 -133
  217. package/tb_agents/opencode_refine_agent.py +0 -117
  218. 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
- }
@@ -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
- }