@tangle-network/agent-bench 0.14.4 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +2 -3
- package/dist/adapters.d.ts +2 -5
- package/dist/adapters.js +3 -4
- package/dist/benchmarks/_harness.d.ts +17 -20
- package/dist/benchmarks/_harness.js +4 -4
- package/dist/benchmarks/_harness.js.map +1 -1
- package/dist/benchmarks/aec-bench.d.ts +1 -4
- package/dist/benchmarks/aec-bench.js +1 -2
- package/dist/benchmarks/agentbench.d.ts +2 -5
- package/dist/benchmarks/agentbench.js +1 -2
- package/dist/benchmarks/appworld.d.ts +8 -10
- package/dist/benchmarks/appworld.js +23 -23
- package/dist/benchmarks/appworld.js.map +1 -1
- package/dist/benchmarks/bfcl.d.ts +2 -5
- package/dist/benchmarks/bfcl.js +1 -2
- package/dist/benchmarks/cad-design.d.ts +2 -5
- package/dist/benchmarks/cad-design.js +2 -3
- package/dist/benchmarks/cad-design.js.map +1 -1
- package/dist/benchmarks/cadbench.d.ts +1 -4
- package/dist/benchmarks/cadbench.js +1 -2
- package/dist/benchmarks/cadgenbench.d.ts +1 -4
- package/dist/benchmarks/cadgenbench.js +1 -2
- package/dist/benchmarks/commit0.d.ts +2 -5
- package/dist/benchmarks/commit0.js +1 -2
- package/dist/benchmarks/crag.d.ts +1 -4
- package/dist/benchmarks/crag.js +3 -3
- package/dist/benchmarks/crag.js.map +1 -1
- package/dist/benchmarks/dabstep.d.ts +2 -5
- package/dist/benchmarks/dabstep.js +2 -3
- package/dist/benchmarks/dabstep.js.map +1 -1
- package/dist/benchmarks/enterpriseops-gym.d.ts +2 -5
- package/dist/benchmarks/enterpriseops-gym.js +1 -2
- package/dist/benchmarks/finresearchbench.d.ts +2 -5
- package/dist/benchmarks/finresearchbench.js +2 -3
- package/dist/benchmarks/finsearchcomp.d.ts +2 -5
- package/dist/benchmarks/finsearchcomp.js +4 -4
- package/dist/benchmarks/finsearchcomp.js.map +1 -1
- package/dist/benchmarks/frames.d.ts +3 -19
- package/dist/benchmarks/frames.js +13 -39
- package/dist/benchmarks/frames.js.map +1 -1
- package/dist/benchmarks/hotpotqa.d.ts +4 -14
- package/dist/benchmarks/hotpotqa.js +12 -32
- package/dist/benchmarks/hotpotqa.js.map +1 -1
- package/dist/benchmarks/humaneval.d.ts +9 -12
- package/dist/benchmarks/humaneval.js +2 -3
- package/dist/benchmarks/humaneval.js.map +1 -1
- package/dist/benchmarks/mcad-bench.d.ts +13 -16
- package/dist/benchmarks/mcad-bench.js +2 -3
- package/dist/benchmarks/mcad-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-bench.d.ts +17 -20
- package/dist/benchmarks/mcad-cq-bench.js +2 -3
- package/dist/benchmarks/mcad-cq-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-golds.d.ts +2 -5
- package/dist/benchmarks/mcad-cq-golds.js +1 -2
- package/dist/benchmarks/mcad-golds.d.ts +1 -4
- package/dist/benchmarks/mcad-golds.js +0 -1
- package/dist/benchmarks/mcad-tasks.d.ts +5 -8
- package/dist/benchmarks/mcad-tasks.js +7 -8
- package/dist/benchmarks/mcad-tasks.js.map +1 -1
- package/dist/benchmarks/mind2web.d.ts +3 -5
- package/dist/benchmarks/mind2web.js +2 -3
- package/dist/benchmarks/mind2web.js.map +1 -1
- package/dist/benchmarks/nomiracl.d.ts +1 -4
- package/dist/benchmarks/nomiracl.js +1 -2
- package/dist/benchmarks/open-rag-bench.d.ts +1 -4
- package/dist/benchmarks/open-rag-bench.js +3 -3
- package/dist/benchmarks/open-rag-bench.js.map +1 -1
- package/dist/benchmarks/programbench.d.ts +2 -5
- package/dist/benchmarks/programbench.js +1 -2
- package/dist/benchmarks/rag-shared.d.ts +30 -22
- package/dist/benchmarks/rag-shared.js +8 -2
- package/dist/benchmarks/rag-shared.js.map +1 -1
- package/dist/benchmarks/ragbench.d.ts +1 -4
- package/dist/benchmarks/ragbench.js +3 -3
- package/dist/benchmarks/ragbench.js.map +1 -1
- package/dist/benchmarks/simpleqa.d.ts +2 -18
- package/dist/benchmarks/simpleqa.js +5 -31
- package/dist/benchmarks/simpleqa.js.map +1 -1
- package/dist/benchmarks/swe-bench.d.ts +7 -10
- package/dist/benchmarks/swe-bench.js +4 -4
- package/dist/benchmarks/swe-bench.js.map +1 -1
- package/dist/benchmarks/t2-ragbench.d.ts +1 -4
- package/dist/benchmarks/t2-ragbench.js +3 -3
- package/dist/benchmarks/t2-ragbench.js.map +1 -1
- package/dist/benchmarks/tau-bench-shared.d.ts +5 -8
- package/dist/benchmarks/tau-bench-shared.js +4 -4
- package/dist/benchmarks/tau-bench-shared.js.map +1 -1
- package/dist/benchmarks/tau2-bench.d.ts +2 -5
- package/dist/benchmarks/tau2-bench.js +1 -2
- package/dist/benchmarks/tau3-banking.d.ts +1 -4
- package/dist/benchmarks/tau3-banking.js +1 -2
- package/dist/benchmarks/terminal-bench.d.ts +1 -4
- package/dist/benchmarks/terminal-bench.js +4 -4
- package/dist/benchmarks/terminal-bench.js.map +1 -1
- package/dist/benchmarks/toollm.d.ts +2 -5
- package/dist/benchmarks/toollm.js +1 -2
- package/dist/benchmarks/trata-hedge.d.ts +1 -4
- package/dist/benchmarks/trata-hedge.js +2 -3
- package/dist/benchmarks/types.d.ts +6 -9
- package/dist/benchmarks/webarena-verified.d.ts +2 -5
- package/dist/benchmarks/webarena-verified.js +1 -2
- package/dist/{cadbench-BRF-59Mt.js → cadbench-DhAndllg.js} +4 -6
- package/dist/cadbench-DhAndllg.js.map +1 -0
- package/dist/{cadgenbench-DXtGkuW3.js → cadgenbench-Tvk16YKT.js} +15 -5
- package/dist/cadgenbench-Tvk16YKT.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.js +16 -24
- package/dist/index.js.map +1 -1
- package/dist/{router-turn-uTYO6KQ1.js → router-turn-DNbQ_GjQ.js} +2 -3
- package/dist/router-turn-DNbQ_GjQ.js.map +1 -0
- package/fixtures/pier-agent/no-model-task/pre_artifacts.sh +0 -0
- package/fixtures/pier-agent/no-model-task/tests/test.sh +0 -0
- package/package.json +10 -10
- package/pier_agents/tangle_candidate.py +15 -23
- package/scripts/run-package-tests.mjs +8 -15
- package/src/atom-mcp-e2e.mts +2 -2
- package/src/benchmarks/frames.ts +10 -44
- package/src/benchmarks/hotpotqa.ts +9 -29
- package/src/benchmarks/rag-shared.ts +12 -0
- package/src/benchmarks/simpleqa.ts +2 -36
- package/src/commit0-prereqs.sh +0 -0
- package/src/corpus-replay.mts +8 -8
- package/src/corpus-report.mts +21 -21
- package/src/corpus.test.mts +5 -5
- package/src/corpus.ts +16 -16
- package/src/directives.ts +0 -38
- package/src/examples/lean-verify.ts +1 -1
- package/src/gate.ts +7 -7
- package/src/generate-eval/certify.ts +2 -2
- package/src/index.ts +1 -0
- package/src/refine-loop.ts +5 -5
- package/src/resolve-client.ts +1 -1
- package/src/router-turn.ts +3 -11
- package/src/run-pool.ts +1 -1
- package/src/runtime-hook-recorder.ts +2 -2
- package/src/search-bench/tasks.ts +1 -1
- package/src/selector.test.mts +13 -13
- package/src/selector.ts +19 -19
- package/src/swe-bench-env.ts +4 -12
- package/src/swe-jail.ts +5 -156
- package/src/swe-structural-judge-policy.ts +3 -3
- package/src/swe-structural-policy.ts +3 -3
- package/src/swe-structural-provenance.ts +4 -4
- package/src/terminal-compare.ts +10 -10
- package/src/worker-blender.ts +2 -106
- package/src/worker-build123d.ts +2 -81
- package/tb_agents/opencode_router_agent.py +1 -1
- package/dist/cadbench-BRF-59Mt.js.map +0 -1
- package/dist/cadgenbench-DXtGkuW3.js.map +0 -1
- package/dist/router-turn-uTYO6KQ1.js.map +0 -1
- package/scripts/cadbench_prepare.py +0 -22
- package/scripts/cadgenbench_hard_parts.py +0 -48
- package/scripts/clbench_codebase_judge.py +0 -73
- package/scripts/render-gate-chart.mjs +0 -176
- package/scripts/trata-hedge/README.md +0 -57
- package/scripts/trata-hedge/run.sh +0 -64
- package/src/cloud-loop.mts +0 -156
- package/src/coordination-mcp-container-reach.mts +0 -182
- package/src/fleet.mts +0 -143
- package/src/hev-structural.mts +0 -697
- package/src/humaneval-gate.mts +0 -220
- package/src/mbpp-structural.mts +0 -676
- package/src/mcp-mount-probe.mts +0 -141
- package/src/profiles.ts +0 -128
- package/src/research-gate.mts +0 -132
- package/src/research-shot.ts +0 -144
- package/src/router-executor.ts +0 -51
- package/src/sandbox-run.ts +0 -108
- package/src/search-bench/bridge.ts +0 -182
- package/src/search-bench/export.mts +0 -0
- package/src/search-bench/parametric-check.mts +0 -78
- package/src/search-bench/profiles.ts +0 -113
- package/src/search-bench/run.mts +0 -286
- package/src/search-bench/tasks-fresh.ts +0 -688
- package/src/smoke-structural-rollout.mts +0 -415
- package/src/stats.mts +0 -90
- package/src/swe-code-improve.mts +0 -306
- package/src/swe-improve.mts +0 -284
- package/src/swe-structural.mts +0 -707
- package/src/tb-container-executor.mts +0 -266
- package/src/tb-container-executor.test.mts +0 -134
- package/src/tb-supervisor-sidecar.mts +0 -208
- package/src/trata-gepa.mts +0 -381
- package/src/trata-hedge-solve.mts +0 -81
- package/tb_agents/opencode_refine_agent.py +0 -117
- package/tb_agents/opencode_supervisor_agent.py +0 -239
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executor for workers that must mutate the same Terminal-Bench container the grader inspects.
|
|
3
|
-
*
|
|
4
|
-
* The container lifecycle stays owned by Terminal-Bench. This executor only runs a command in the
|
|
5
|
-
* provided container id and reports the captured process artifact back through the runtime.
|
|
6
|
-
*/
|
|
7
|
-
import { spawn } from 'node:child_process'
|
|
8
|
-
import { agentProfileSchema } from '@tangle-network/agent-interface'
|
|
9
|
-
import type {
|
|
10
|
-
Agent,
|
|
11
|
-
AgentProfile,
|
|
12
|
-
AgentSpec,
|
|
13
|
-
Executor,
|
|
14
|
-
ExecutorContext,
|
|
15
|
-
ExecutorFactory,
|
|
16
|
-
ExecutorResult,
|
|
17
|
-
MakeWorkerAgent,
|
|
18
|
-
Runtime,
|
|
19
|
-
Spend,
|
|
20
|
-
} from '../../src/runtime/index'
|
|
21
|
-
import { harnessInvocation, type LocalHarness } from '../../src/mcp/local-harness'
|
|
22
|
-
import { assertExecutableAgentProfile } from '../../src/runtime/supervise/model-policy'
|
|
23
|
-
|
|
24
|
-
export interface TbExecOutput {
|
|
25
|
-
/** Primary artifact consumed by drivers that read `{ content }`. */
|
|
26
|
-
readonly content: string
|
|
27
|
-
readonly stdout: string
|
|
28
|
-
readonly stderr: string
|
|
29
|
-
readonly exitCode: number | null
|
|
30
|
-
readonly containerId: string
|
|
31
|
-
readonly command: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type ParseUsage = (io: {
|
|
35
|
-
stdout: string
|
|
36
|
-
stderr: string
|
|
37
|
-
exitCode: number | null
|
|
38
|
-
}) => { input: number; output: number; usd?: number } | undefined
|
|
39
|
-
|
|
40
|
-
export interface TbContainerConfig {
|
|
41
|
-
readonly containerId?: string
|
|
42
|
-
readonly containerEnvVar?: string
|
|
43
|
-
readonly workdir?: string
|
|
44
|
-
readonly shell?: string
|
|
45
|
-
readonly env?: Readonly<Record<string, string>>
|
|
46
|
-
/** Shell setup required inside the existing task container before the canonical invocation. */
|
|
47
|
-
readonly commandPrefix?: ReadonlyArray<string>
|
|
48
|
-
readonly parseUsage?: ParseUsage
|
|
49
|
-
readonly budgetExempt?: boolean
|
|
50
|
-
readonly dockerBin?: string
|
|
51
|
-
readonly failOnNonZeroExit?: boolean
|
|
52
|
-
readonly runtime?: Runtime
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const DEFAULT_ENV_VAR = 'TB_TARGET_CONTAINER'
|
|
56
|
-
|
|
57
|
-
function resolveContainerId(config: TbContainerConfig): string {
|
|
58
|
-
const envVar = config.containerEnvVar ?? DEFAULT_ENV_VAR
|
|
59
|
-
const id = config.containerId ?? process.env[envVar]
|
|
60
|
-
if (!id || id.trim().length === 0) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
`tbContainerExecutor: no target container - set config.containerId or the ${envVar} env var ` +
|
|
63
|
-
`to the id of the terminal-bench container the verifier grades.`,
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
return id.trim()
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function taskToPrompt(task: unknown): string {
|
|
70
|
-
if (typeof task === 'string') return task
|
|
71
|
-
if (task && typeof task === 'object') {
|
|
72
|
-
const obj = task as Record<string, unknown>
|
|
73
|
-
for (const k of ['command', 'prompt', 'content', 'task', 'message']) {
|
|
74
|
-
if (typeof obj[k] === 'string') return obj[k] as string
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return JSON.stringify(task)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function shellQuote(value: string): string {
|
|
81
|
-
return `'${value.replace(/'/g, `'\\''`)}'`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function profileCommand(
|
|
85
|
-
profile: AgentProfile,
|
|
86
|
-
task: unknown,
|
|
87
|
-
prefix: ReadonlyArray<string> = [],
|
|
88
|
-
): string {
|
|
89
|
-
const harness = profile.harness
|
|
90
|
-
if (harness !== 'claude-code' && harness !== 'codex' && harness !== 'opencode') {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`tbContainerExecutor: profile harness ${JSON.stringify(harness)} is not available in the task container`,
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
const invocation = harnessInvocation(
|
|
96
|
-
harness as LocalHarness,
|
|
97
|
-
profile,
|
|
98
|
-
taskToPrompt(task),
|
|
99
|
-
{ dangerouslySkipPermissions: true },
|
|
100
|
-
)
|
|
101
|
-
const run = [invocation.command, ...invocation.args].map(shellQuote).join(' ')
|
|
102
|
-
return [...prefix, `exec ${run}`].join('; ')
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Compose the `docker exec` argv that runs `command` inside `containerId` via `<shell> -c`.
|
|
107
|
-
* Exported so tests can verify the container path without a live Docker daemon.
|
|
108
|
-
*/
|
|
109
|
-
export function buildTbDockerExecArgs(
|
|
110
|
-
containerId: string,
|
|
111
|
-
command: string,
|
|
112
|
-
opts: { shell?: string; workdir?: string; env?: Readonly<Record<string, string>> } = {},
|
|
113
|
-
): string[] {
|
|
114
|
-
const out: string[] = ['exec', '-i']
|
|
115
|
-
if (opts.workdir) out.push('--workdir', opts.workdir)
|
|
116
|
-
if (opts.env) {
|
|
117
|
-
for (const [k, v] of Object.entries(opts.env)) {
|
|
118
|
-
if (typeof v !== 'string' || v.length === 0) continue
|
|
119
|
-
out.push('-e', `${k}=${v}`)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
out.push(containerId, opts.shell ?? '/bin/sh', '-c', command)
|
|
123
|
-
return out
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function contentRef(prefix: string, value: unknown): string {
|
|
127
|
-
let str: string
|
|
128
|
-
try {
|
|
129
|
-
str = JSON.stringify(value) ?? String(value)
|
|
130
|
-
} catch {
|
|
131
|
-
str = String(value)
|
|
132
|
-
}
|
|
133
|
-
let h = 0x811c9dc5
|
|
134
|
-
for (let i = 0; i < str.length; i += 1) {
|
|
135
|
-
h ^= str.charCodeAt(i)
|
|
136
|
-
h = Math.imul(h, 0x01000193)
|
|
137
|
-
}
|
|
138
|
-
return `${prefix}:${(h >>> 0).toString(16).padStart(8, '0')}`
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function createTbContainerExecutor(
|
|
142
|
-
config: TbContainerConfig = {},
|
|
143
|
-
): ExecutorFactory<TbExecOutput> {
|
|
144
|
-
return (_spec: AgentSpec, ctx: ExecutorContext): Executor<TbExecOutput> => {
|
|
145
|
-
const profile = agentProfileSchema.parse(_spec.profile)
|
|
146
|
-
assertExecutableAgentProfile(profile, 'tbContainerExecutor')
|
|
147
|
-
const containerId = resolveContainerId(config)
|
|
148
|
-
const dockerBin = config.dockerBin ?? 'docker'
|
|
149
|
-
const metered = config.parseUsage !== undefined
|
|
150
|
-
const budgetExempt = config.budgetExempt ?? !metered
|
|
151
|
-
const runtime: Runtime = config.runtime ?? 'tb-container'
|
|
152
|
-
|
|
153
|
-
const controller = new AbortController()
|
|
154
|
-
const abortIfSignalled = () => {
|
|
155
|
-
if (ctx.signal.aborted) controller.abort()
|
|
156
|
-
}
|
|
157
|
-
abortIfSignalled()
|
|
158
|
-
if (!ctx.signal.aborted) ctx.signal.addEventListener('abort', abortIfSignalled, { once: true })
|
|
159
|
-
|
|
160
|
-
let proc: ReturnType<typeof spawn> | undefined
|
|
161
|
-
let artifact: ExecutorResult<TbExecOutput> | undefined
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
runtime,
|
|
165
|
-
budgetExempt,
|
|
166
|
-
execute(task, signal): Promise<ExecutorResult<TbExecOutput>> {
|
|
167
|
-
const command = profileCommand(profile, task, config.commandPrefix)
|
|
168
|
-
const args = buildTbDockerExecArgs(containerId, command, {
|
|
169
|
-
...(config.shell ? { shell: config.shell } : {}),
|
|
170
|
-
...(config.workdir ? { workdir: config.workdir } : {}),
|
|
171
|
-
...(config.env ? { env: config.env } : {}),
|
|
172
|
-
})
|
|
173
|
-
const started = Date.now()
|
|
174
|
-
|
|
175
|
-
return new Promise<ExecutorResult<TbExecOutput>>((resolve, reject) => {
|
|
176
|
-
const child = spawn(dockerBin, args, { stdio: ['ignore', 'pipe', 'pipe'] })
|
|
177
|
-
proc = child
|
|
178
|
-
|
|
179
|
-
const kill = () => {
|
|
180
|
-
if (child.exitCode === null && !child.killed) child.kill('SIGKILL')
|
|
181
|
-
}
|
|
182
|
-
if (signal.aborted || controller.signal.aborted) kill()
|
|
183
|
-
else {
|
|
184
|
-
signal.addEventListener('abort', kill, { once: true })
|
|
185
|
-
controller.signal.addEventListener('abort', kill, { once: true })
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const outChunks: string[] = []
|
|
189
|
-
const errChunks: string[] = []
|
|
190
|
-
child.stdout?.on('data', (d: Buffer) => outChunks.push(d.toString('utf8')))
|
|
191
|
-
child.stderr?.on('data', (d: Buffer) => errChunks.push(d.toString('utf8')))
|
|
192
|
-
|
|
193
|
-
child.once('error', (err) => {
|
|
194
|
-
signal.removeEventListener('abort', kill)
|
|
195
|
-
controller.signal.removeEventListener('abort', kill)
|
|
196
|
-
reject(
|
|
197
|
-
new Error(
|
|
198
|
-
`tbContainerExecutor: failed to spawn '${dockerBin} exec' on ${containerId}: ${err.message}`,
|
|
199
|
-
{ cause: err },
|
|
200
|
-
),
|
|
201
|
-
)
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
child.once('close', (code) => {
|
|
205
|
-
signal.removeEventListener('abort', kill)
|
|
206
|
-
controller.signal.removeEventListener('abort', kill)
|
|
207
|
-
const stdout = outChunks.join('')
|
|
208
|
-
const stderr = errChunks.join('')
|
|
209
|
-
const exitCode = code
|
|
210
|
-
|
|
211
|
-
if (config.failOnNonZeroExit && exitCode !== 0) {
|
|
212
|
-
reject(
|
|
213
|
-
new Error(
|
|
214
|
-
`tbContainerExecutor: command exited ${exitCode} in ${containerId}: ${stderr.slice(0, 200)}`,
|
|
215
|
-
),
|
|
216
|
-
)
|
|
217
|
-
return
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const out: TbExecOutput = { content: stdout, stdout, stderr, exitCode, containerId, command }
|
|
221
|
-
const usage = config.parseUsage?.({ stdout, stderr, exitCode })
|
|
222
|
-
const spent: Spend = metered
|
|
223
|
-
? {
|
|
224
|
-
iterations: 1,
|
|
225
|
-
tokens: { input: usage?.input ?? 0, output: usage?.output ?? 0 },
|
|
226
|
-
usd: usage?.usd ?? 0,
|
|
227
|
-
ms: Date.now() - started,
|
|
228
|
-
}
|
|
229
|
-
: // Budget-exempt commands report no conserved token, dollar, or iteration spend.
|
|
230
|
-
{ iterations: 0, tokens: { input: 0, output: 0 }, usd: 0, ms: Date.now() - started }
|
|
231
|
-
|
|
232
|
-
artifact = { outRef: contentRef(String(runtime), out), out, spent }
|
|
233
|
-
resolve(artifact)
|
|
234
|
-
})
|
|
235
|
-
})
|
|
236
|
-
},
|
|
237
|
-
teardown(_grace): Promise<{ destroyed: boolean }> {
|
|
238
|
-
controller.abort()
|
|
239
|
-
if (proc && proc.exitCode === null && !proc.killed) proc.kill('SIGKILL')
|
|
240
|
-
return Promise.resolve({ destroyed: true })
|
|
241
|
-
},
|
|
242
|
-
resultArtifact() {
|
|
243
|
-
if (!artifact) {
|
|
244
|
-
throw new Error('tbContainerExecutor: resultArtifact() read before execute() settled')
|
|
245
|
-
}
|
|
246
|
-
return artifact
|
|
247
|
-
},
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export function makeTbContainerWorkerAgent(config: TbContainerConfig = {}): MakeWorkerAgent {
|
|
253
|
-
const factory = createTbContainerExecutor(config)
|
|
254
|
-
return (rawProfile) => {
|
|
255
|
-
const profile = agentProfileSchema.parse(rawProfile)
|
|
256
|
-
assertExecutableAgentProfile(profile, 'tbContainerWorkerAgent')
|
|
257
|
-
const name = profile.name ?? 'tb-worker'
|
|
258
|
-
const spec: AgentSpec = { profile, harness: null }
|
|
259
|
-
const ctx: ExecutorContext = { signal: new AbortController().signal, seams: {} }
|
|
260
|
-
const executor = factory(spec, ctx)
|
|
261
|
-
return { name, act: async () => '', executorSpec: { ...spec, executor } } as Agent<
|
|
262
|
-
unknown,
|
|
263
|
-
unknown
|
|
264
|
-
> & { executorSpec: AgentSpec }
|
|
265
|
-
}
|
|
266
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict'
|
|
2
|
-
import { chmod, mkdtemp, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { tmpdir } from 'node:os'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import type {
|
|
6
|
-
AgentSpec,
|
|
7
|
-
Executor,
|
|
8
|
-
ExecutorContext,
|
|
9
|
-
ExecutorResult,
|
|
10
|
-
} from '@tangle-network/agent-runtime/kernel'
|
|
11
|
-
import {
|
|
12
|
-
buildTbDockerExecArgs,
|
|
13
|
-
createTbContainerExecutor,
|
|
14
|
-
type TbExecOutput,
|
|
15
|
-
} from './tb-container-executor.mts'
|
|
16
|
-
|
|
17
|
-
const spec: AgentSpec = {
|
|
18
|
-
profile: {
|
|
19
|
-
name: 'tb-test-worker',
|
|
20
|
-
harness: 'opencode',
|
|
21
|
-
model: { provider: 'tangle-router', default: 'deepseek-v4-flash' },
|
|
22
|
-
},
|
|
23
|
-
harness: null,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function context(): ExecutorContext {
|
|
27
|
-
return { signal: new AbortController().signal, seams: {} }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {
|
|
31
|
-
return typeof value === 'object' && value !== null && Symbol.asyncIterator in value
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function executeOneShot(
|
|
35
|
-
executor: Executor<TbExecOutput>,
|
|
36
|
-
task: unknown,
|
|
37
|
-
): Promise<ExecutorResult<TbExecOutput>> {
|
|
38
|
-
const result = executor.execute(task, new AbortController().signal)
|
|
39
|
-
if (isAsyncIterable(result)) {
|
|
40
|
-
throw new Error('tb-container-executor returned a stream instead of a one-shot result')
|
|
41
|
-
}
|
|
42
|
-
return await result
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function executable(name: string, body: string): Promise<string> {
|
|
46
|
-
const dir = await mkdtemp(path.join(tmpdir(), 'tb-container-executor-'))
|
|
47
|
-
const file = path.join(dir, name)
|
|
48
|
-
await writeFile(file, body)
|
|
49
|
-
await chmod(file, 0o755)
|
|
50
|
-
return file
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function main(): Promise<void> {
|
|
54
|
-
assert.deepEqual(
|
|
55
|
-
buildTbDockerExecArgs('cid', 'echo ok', {
|
|
56
|
-
workdir: '/app',
|
|
57
|
-
env: { A: 'B', EMPTY: '' },
|
|
58
|
-
shell: '/bin/bash',
|
|
59
|
-
}),
|
|
60
|
-
['exec', '-i', '--workdir', '/app', '-e', 'A=B', 'cid', '/bin/bash', '-c', 'echo ok'],
|
|
61
|
-
'docker exec argv is deterministic and skips empty env values',
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
assert.throws(
|
|
65
|
-
() => createTbContainerExecutor({ containerEnvVar: 'TB_CONTAINER_EXECUTOR_TEST_MISSING' })(spec, context()),
|
|
66
|
-
/no target container/,
|
|
67
|
-
'missing target container fails before spawning',
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
const fakeDocker = await executable(
|
|
71
|
-
'fake-docker',
|
|
72
|
-
`#!/bin/sh
|
|
73
|
-
printf 'argv:%s\\n' "$*"
|
|
74
|
-
`,
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
const metered = createTbContainerExecutor({
|
|
78
|
-
containerId: 'cid',
|
|
79
|
-
dockerBin: fakeDocker,
|
|
80
|
-
workdir: '/work',
|
|
81
|
-
env: { OPENAI_BASE_URL: 'http://router.test' },
|
|
82
|
-
parseUsage: () => ({ input: 7, output: 11, usd: 0.004 }),
|
|
83
|
-
})(spec, context())
|
|
84
|
-
|
|
85
|
-
assert.equal(metered.budgetExempt, false, 'usage parser makes the executor metered')
|
|
86
|
-
const meteredResult = await executeOneShot(metered, { command: 'echo hello' })
|
|
87
|
-
assert.equal(meteredResult.out.containerId, 'cid')
|
|
88
|
-
assert.match(meteredResult.out.command, /'echo hello'/)
|
|
89
|
-
assert.match(meteredResult.out.command, /'tangle-router\/deepseek-v4-flash'/)
|
|
90
|
-
assert.match(
|
|
91
|
-
meteredResult.out.stdout,
|
|
92
|
-
// `--auto` is opencode's permission bypass, emitted for an unattended container run the
|
|
93
|
-
// same way claude-code and codex emit theirs. Without it the harness denies writes outside
|
|
94
|
-
// the working directory and reports "The user rejected permission".
|
|
95
|
-
/argv:exec -i --workdir \/work -e OPENAI_BASE_URL=http:\/\/router\.test cid \/bin\/sh -c exec 'opencode' 'run' 'echo hello' '--auto' '-m' 'tangle-router\/deepseek-v4-flash'/,
|
|
96
|
-
)
|
|
97
|
-
assert.deepEqual(meteredResult.spent.tokens, { input: 7, output: 11 })
|
|
98
|
-
assert.equal(meteredResult.spent.usd, 0.004)
|
|
99
|
-
assert.equal(metered.resultArtifact().out, meteredResult.out)
|
|
100
|
-
|
|
101
|
-
const free = createTbContainerExecutor({ containerId: 'cid', dockerBin: fakeDocker })(spec, context())
|
|
102
|
-
assert.equal(free.budgetExempt, true, 'unmetered shell commands are explicit budget-exempt work')
|
|
103
|
-
const freeResult = await executeOneShot(free, 'printf ok')
|
|
104
|
-
assert.equal(freeResult.spent.iterations, 0)
|
|
105
|
-
assert.deepEqual(freeResult.spent.tokens, { input: 0, output: 0 })
|
|
106
|
-
assert.equal(freeResult.spent.usd, 0)
|
|
107
|
-
|
|
108
|
-
const failingDocker = await executable(
|
|
109
|
-
'failing-docker',
|
|
110
|
-
`#!/bin/sh
|
|
111
|
-
echo failed >&2
|
|
112
|
-
exit 7
|
|
113
|
-
`,
|
|
114
|
-
)
|
|
115
|
-
const strict = createTbContainerExecutor({
|
|
116
|
-
containerId: 'cid',
|
|
117
|
-
dockerBin: failingDocker,
|
|
118
|
-
failOnNonZeroExit: true,
|
|
119
|
-
})(spec, context())
|
|
120
|
-
await assert.rejects(
|
|
121
|
-
executeOneShot(strict, 'do work'),
|
|
122
|
-
/command exited 7/,
|
|
123
|
-
'strict mode treats non-zero command exit as infrastructure failure',
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
const lenient = createTbContainerExecutor({ containerId: 'cid', dockerBin: failingDocker })(spec, context())
|
|
127
|
-
const lenientResult = await executeOneShot(lenient, 'do work')
|
|
128
|
-
assert.equal(lenientResult.out.exitCode, 7, 'default mode returns non-zero exits as task artifacts')
|
|
129
|
-
assert.match(lenientResult.out.stderr, /failed/)
|
|
130
|
-
|
|
131
|
-
console.log('tb-container-executor.test: OK')
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
void main()
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host process that lets an in-container Terminal-Bench agent delegate work to child agents.
|
|
3
|
-
*
|
|
4
|
-
* It exposes the coordination MCP on a container-reachable host address, then runs every spawned
|
|
5
|
-
* worker in the same Docker container the benchmark grader inspects.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { appendFileSync, writeFileSync } from 'node:fs'
|
|
9
|
-
import {
|
|
10
|
-
type Agent,
|
|
11
|
-
createExecutorRegistry,
|
|
12
|
-
createSupervisor,
|
|
13
|
-
InMemoryResultBlobStore,
|
|
14
|
-
InMemorySpawnJournal,
|
|
15
|
-
type Scope,
|
|
16
|
-
} from '../../src/runtime/index'
|
|
17
|
-
import { serveCoordinationMcp } from '../../src/runtime/supervise/coordination-mcp'
|
|
18
|
-
import { makeTbContainerWorkerAgent, type ParseUsage } from './tb-container-executor.mts'
|
|
19
|
-
|
|
20
|
-
const CONTAINER_ID = (process.env.TB_TARGET_CONTAINER ?? '').trim()
|
|
21
|
-
const ROUTER_KEY = process.env.OPENAI_API_KEY ?? ''
|
|
22
|
-
const ROUTER_BASE = process.env.OPENAI_BASE_URL ?? 'https://router.tangle.tools/v1'
|
|
23
|
-
const DOCKER_BRIDGE_GATEWAY = process.env.DOCKER_BRIDGE_GATEWAY ?? '172.17.0.1'
|
|
24
|
-
const PORT_FILE = process.env.TB_SIDECAR_PORT_FILE ?? '.tb-sidecar-port'
|
|
25
|
-
const LOG_FILE = process.env.TB_SIDECAR_LOG ?? '.tb-sidecar-events.jsonl'
|
|
26
|
-
const WORKER_WORKDIR = process.env.TB_WORKER_WORKDIR ?? '/app'
|
|
27
|
-
const WORKER_CONFIG_PATH = '/installed-agent/opencode-worker.json'
|
|
28
|
-
|
|
29
|
-
if (!CONTAINER_ID) {
|
|
30
|
-
console.error('[sidecar] FATAL: TB_TARGET_CONTAINER not set')
|
|
31
|
-
process.exit(2)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function logEvent(kind: string, payload: unknown): void {
|
|
35
|
-
const line = JSON.stringify({ ts: new Date().toISOString(), kind, payload }) + '\n'
|
|
36
|
-
try {
|
|
37
|
-
appendFileSync(LOG_FILE, line)
|
|
38
|
-
} catch {
|
|
39
|
-
/* logging is never fatal */
|
|
40
|
-
}
|
|
41
|
-
console.error(`[sidecar] ${kind} ${JSON.stringify(payload).slice(0, 300)}`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const parseWorkerUsage: ParseUsage = ({ stdout }) => {
|
|
45
|
-
let input = 0
|
|
46
|
-
let output = 0
|
|
47
|
-
let saw = false
|
|
48
|
-
for (const raw of stdout.split('\n')) {
|
|
49
|
-
const line = raw.trim()
|
|
50
|
-
if (!line || !(line.startsWith('{') || line.startsWith('['))) continue
|
|
51
|
-
let ev: unknown
|
|
52
|
-
try {
|
|
53
|
-
ev = JSON.parse(line)
|
|
54
|
-
} catch {
|
|
55
|
-
continue
|
|
56
|
-
}
|
|
57
|
-
const events = Array.isArray(ev) ? ev : [ev]
|
|
58
|
-
for (const e of events) {
|
|
59
|
-
if (!e || typeof e !== 'object') continue
|
|
60
|
-
const dicts: Array<Record<string, unknown>> = [e as Record<string, unknown>]
|
|
61
|
-
for (const k of ['usage', 'tokens', 'part', 'info', 'message']) {
|
|
62
|
-
const sub = (e as Record<string, unknown>)[k]
|
|
63
|
-
if (sub && typeof sub === 'object') {
|
|
64
|
-
dicts.push(sub as Record<string, unknown>)
|
|
65
|
-
for (const k2 of ['usage', 'tokens']) {
|
|
66
|
-
const sub2 = (sub as Record<string, unknown>)[k2]
|
|
67
|
-
if (sub2 && typeof sub2 === 'object') dicts.push(sub2 as Record<string, unknown>)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
for (const d of dicts) {
|
|
72
|
-
const i = (d.input_tokens ?? d.prompt_tokens ?? d.input) as unknown
|
|
73
|
-
const o = (d.output_tokens ?? d.completion_tokens ?? d.output) as unknown
|
|
74
|
-
if (typeof i === 'number' || typeof o === 'number') {
|
|
75
|
-
input += typeof i === 'number' ? i : 0
|
|
76
|
-
output += typeof o === 'number' ? o : 0
|
|
77
|
-
saw = true
|
|
78
|
-
break
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return saw ? { input, output } : undefined
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function main(): Promise<void> {
|
|
87
|
-
writeFileSync(LOG_FILE, '')
|
|
88
|
-
const blobs = new InMemoryResultBlobStore()
|
|
89
|
-
|
|
90
|
-
const makeWorkerAgent = makeTbContainerWorkerAgent({
|
|
91
|
-
containerId: CONTAINER_ID,
|
|
92
|
-
workdir: WORKER_WORKDIR,
|
|
93
|
-
commandPrefix: [
|
|
94
|
-
'export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"',
|
|
95
|
-
'{ [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; } 2>/dev/null || true',
|
|
96
|
-
'{ [ -s /root/.nvm/nvm.sh ] && . /root/.nvm/nvm.sh; } 2>/dev/null || true',
|
|
97
|
-
],
|
|
98
|
-
parseUsage: parseWorkerUsage,
|
|
99
|
-
env: {
|
|
100
|
-
OPENAI_API_KEY: ROUTER_KEY,
|
|
101
|
-
OPENAI_BASE_URL: ROUTER_BASE,
|
|
102
|
-
OPENCODE_CONFIG: WORKER_CONFIG_PATH,
|
|
103
|
-
HOME: '/root',
|
|
104
|
-
},
|
|
105
|
-
runtime: 'tb-container',
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const root: Agent<unknown, unknown> = {
|
|
109
|
-
name: 'tb-supervisor-sidecar',
|
|
110
|
-
async act(_t, scope: Scope<unknown>) {
|
|
111
|
-
const mcp = await serveCoordinationMcp({
|
|
112
|
-
scope,
|
|
113
|
-
blobs,
|
|
114
|
-
makeWorkerAgent,
|
|
115
|
-
perWorker: { maxIterations: 40, maxTokens: 200_000 },
|
|
116
|
-
toolNames: ['spawn_worker', 'observe_agent', 'stop'],
|
|
117
|
-
host: '0.0.0.0',
|
|
118
|
-
onEvent: (event) => logEvent('bus', event),
|
|
119
|
-
})
|
|
120
|
-
const containerUrl = `http://${DOCKER_BRIDGE_GATEWAY}:${mcp.port}/mcp`
|
|
121
|
-
writeFileSync(PORT_FILE, String(mcp.port))
|
|
122
|
-
logEvent('ready', { port: mcp.port, url: mcp.url, containerUrl, containerId: CONTAINER_ID })
|
|
123
|
-
|
|
124
|
-
await new Promise<void>((resolve) => {
|
|
125
|
-
const stop = (sig: string) => {
|
|
126
|
-
logEvent('stop', { signal: sig })
|
|
127
|
-
resolve()
|
|
128
|
-
}
|
|
129
|
-
process.on('SIGTERM', () => stop('SIGTERM'))
|
|
130
|
-
process.on('SIGINT', () => stop('SIGINT'))
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const drained = mcp.drainResolved()
|
|
134
|
-
const settled = mcp.settled()
|
|
135
|
-
const history = mcp.history()
|
|
136
|
-
const workerOutputs: Array<Record<string, unknown>> = []
|
|
137
|
-
let workerInput = 0
|
|
138
|
-
let workerOutput = 0
|
|
139
|
-
for (const w of settled) {
|
|
140
|
-
if (!w.outRef) continue
|
|
141
|
-
try {
|
|
142
|
-
const out = (await blobs.get(w.outRef)) as
|
|
143
|
-
| { command?: string; stdout?: string; stderr?: string; exitCode?: number | null; containerId?: string }
|
|
144
|
-
| undefined
|
|
145
|
-
if (out) {
|
|
146
|
-
const usage = out.stdout ? parseWorkerUsage({ stdout: out.stdout, stderr: '', exitCode: null }) : undefined
|
|
147
|
-
const workerId = 'id' in w && typeof w.id === 'string' ? w.id : undefined
|
|
148
|
-
if (usage) {
|
|
149
|
-
workerInput += usage.input
|
|
150
|
-
workerOutput += usage.output
|
|
151
|
-
}
|
|
152
|
-
workerOutputs.push({
|
|
153
|
-
id: workerId,
|
|
154
|
-
status: w.status,
|
|
155
|
-
command: out.command,
|
|
156
|
-
exitCode: out.exitCode ?? null,
|
|
157
|
-
containerId: out.containerId,
|
|
158
|
-
stdoutBytes: out.stdout?.length ?? 0,
|
|
159
|
-
stderrTail: (out.stderr ?? '').slice(-500),
|
|
160
|
-
stdoutTail: (out.stdout ?? '').slice(-500),
|
|
161
|
-
usage: usage ?? null,
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
} catch {
|
|
165
|
-
/* blob fetch is best-effort */
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
logEvent('final', {
|
|
169
|
-
drained,
|
|
170
|
-
settled,
|
|
171
|
-
settledCount: settled.length,
|
|
172
|
-
historyLen: history.length,
|
|
173
|
-
workerTokens: { input: workerInput, output: workerOutput },
|
|
174
|
-
stats: mcp.stats(),
|
|
175
|
-
})
|
|
176
|
-
try {
|
|
177
|
-
writeFileSync(
|
|
178
|
-
`${LOG_FILE}.final.json`,
|
|
179
|
-
JSON.stringify(
|
|
180
|
-
{ settled, drained, history, workerOutputs, workerTokens: { input: workerInput, output: workerOutput }, stats: mcp.stats() },
|
|
181
|
-
null,
|
|
182
|
-
2,
|
|
183
|
-
),
|
|
184
|
-
)
|
|
185
|
-
} catch {
|
|
186
|
-
/* never fatal */
|
|
187
|
-
}
|
|
188
|
-
await mcp.close()
|
|
189
|
-
return { settledCount: settled.length }
|
|
190
|
-
},
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
await createSupervisor<unknown, unknown>().run(root, 'tb-supervisor', {
|
|
194
|
-
budget: { maxIterations: 500, maxTokens: 2_000_000 },
|
|
195
|
-
runId: 'tb-supervisor-sidecar',
|
|
196
|
-
journal: new InMemorySpawnJournal(),
|
|
197
|
-
blobs,
|
|
198
|
-
executors: createExecutorRegistry(),
|
|
199
|
-
maxDepth: 4,
|
|
200
|
-
now: () => Date.now(),
|
|
201
|
-
})
|
|
202
|
-
process.exit(0)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
main().catch((e) => {
|
|
206
|
-
console.error('[sidecar] FATAL', e instanceof Error ? (e.stack ?? e.message) : String(e))
|
|
207
|
-
process.exit(1)
|
|
208
|
-
})
|