Declaration reference
Every file in .thunderjar/ default-exports one of these functions. Each returns its argument unchanged: its only job is to type-check the declaration. See the .thunderjar/ folder for which file declares what.
import { declareTestCase } from "thunderjar";Shared parameter options
declareBaseImage, declareCodeState, declarePromptSet, declareHarness and declareInitialPrompt all take these.
config
Type: C
Default: undefined
Values passed to resolve and applyParameter, as written.
resolve
Type: (config: C, ctx: { exec(command: string): Promise<string> }) => Resolved | Promise<Resolved>
Looks up what a floating parameter currently means, such as a branch's latest commit. Runs on the host once per run, and must only read. Its result is passed on as ctx.resolved, and recorded with each run.
resolve: (config, ctx) => ctx.exec(`git ls-remote ${config.repo} main | cut -f1`),applyParameter
Type: (config: C, ctx: { dir: string; resolved: R }) => string
Returns the Dockerfile fragment that applies the parameter to the prerun image. ctx.dir is where the parameter folder's files/ folder is in the build context.
applyParameter: (_config, ctx) => `COPY ${ctx.dir}/ /workspace/`,declareBaseImage
File: parameters/baseImages/<name>/index.ts
The image the agent runs in. Its applyParameter is required, and must start with FROM.
export default declareBaseImage({
applyParameter: () => `FROM node:20-bookworm
RUN npm install --global bun@1.3.14`,
});runOptions
Type: string[]
Default: []
More docker run options for the agent's containers, for agents that need more of the kernel than Docker allows by default, e.g. Claude Code's bubblewrap sandbox, which needs user namespaces: ["--security-opt", "seccomp=unconfined", "--security-opt", "apparmor=unconfined"]. Each option and value is its own string. Ask for the least you need: --privileged works, but gives the agent the whole machine.
Some hosts forbid what no option can allow. Ubuntu 23.10 and later stop unconfined processes making user namespaces until sysctl kernel.apparmor_restrict_unprivileged_userns=0.
declareCodeState
File: parameters/codeStates/<name>/index.ts
What is in /workspace when the agent starts. Takes only the shared options.
export default declareCodeState({
config: { repo: "https://github.com/acme/app.git", commit: "a1b2c3d" },
applyParameter: (config) => `RUN git clone --quiet ${config.repo} /workspace \\
&& git -C /workspace checkout --quiet --detach ${config.commit}`,
});declarePromptSet
File: parameters/promptSets/<name>/index.ts
The AGENTS.md, skills and other prompt files the agent sees. Takes only the shared options.
export default declarePromptSet({
applyParameter: (_config, ctx) => `COPY ${ctx.dir}/ /workspace/`,
});declareHarness
File: parameters/harnessModels/<harness>/index.ts
How to install and run an agent. Takes the shared options too.
version
Type: string
Required. The version of the agent this harness installs, e.g. "2.1.311": ctx.version for its fragment. One harness folder pins one version, so name the folder after it, e.g. claude-code-2.1.311/, and copy the folder to try another.
models
Type: Record<string, ModelSetting[]>
The models the agent runs, by their real IDs, each with its settings, one setting per entry. A fixed setting, e.g. { reasoningEffort: "low" }, adds nothing to the pair's name. A variant setting, { reasoningEffort: { values: ["low", "high"] } }, adds one required part, e.g. codex-0.166.0/openai/gpt-6.1-sol/high. Several make their cross product, parts in array order. A test case may only name these. ctx.model is the settings, each variant's value chosen.
applyParameter
Type: (config, ctx: HarnessApplyCtx) => string
Required. Installs the agent, and writes /thunderjar/thunderjar-run.sh, the script that runs it, e.g. with writeRunScript. The script runs in the image's working directory, reads the prompt from /thunderjar/prompt.txt, and must leave the agent's result at /thunderjar/result.json. writeModel(ctx.modelId) puts the model ID at /thunderjar/model.txt, for it to read. ctx has dir, version, modelId, and resolved, what resolve returned.
collectReply
Type: (raw: string) => string
The agent's final reply, read from the text of its result file, for instruments such as replyMatches to measure. Without it, a run has no reply.
collectTokenCosts
Type: (raw: string, ctx: { version: string; modelId: string }) => TokenCosts
The run's token costs, read from the text of its result file. A throw is unparseable. Without it, every run's are notReported.
requiredEnv
Type: (string | { oneOf: string[] })[]
The names of the environment variables the agent needs, e.g. its API key. An entry { oneOf: [...] } needs any one of them, e.g. a subscription token or an API key: the first that's set is passed, and only that one, and the run's record names it. Each is passed into this harness's agent containers only, as docker run -e NAME, so its value comes from the shell that runs Thunderjar, and is never on a command line or in a log. Its postrun image doesn't keep it: when the container is committed, every variable its prerun image doesn't set is blanked. Its measurement containers, started from the postrun image, are given it the same way, by name. run stops if one is unset. If the agent writes its value into a file, the postrun image's files are searched for it before it's pushed, and run warns.
declareInitialPrompt
File: parameters/tasks/<task>/initial-prompts/<name>.ts
What the agent is asked. Its fragment writes the prompt to /thunderjar/prompt.txt, for the harness's run script to read. Takes the shared options too, but applyParameter gets no ctx.dir.
export default declareInitialPrompt({
applyParameter: () => writePrompt("Create a file isPrime.ts exporting a function that tests for primality."),
timeoutSeconds: 600,
});timeoutSeconds
Type: number
Required. How long the harness's run script may run before it's killed.
declareMeasurement
File: parameters/tasks/<task>/measurements/<name>.ts
What is measured after each run. Its instrument runs once per run, and what it returns, the measure, is stored as it is. Each of its metrics reads a score from the measure whenever results are read, so a metric can be added, changed or removed without measuring again.
export default declareMeasurement({
instrument: "bunTestFile",
config: { subject: "**/isPrime.ts", test: "./isPrime.test.ts" },
metrics: {
// bunTestFile's default score is the pass rate: passed / total, or undefined when total is 0.
passRate: { stat: "mean", better: "higher" },
// Anything else reads the stored { passed, total } with a score.
passed: { score: (v) => v.passed, stat: "mean", better: "higher" },
},
});instrument
Type: "fileCreated" | "grep" | "bunTestFile" | "replyMatches" | "shell" | "commits" | "filesChanged" | "jsAst"
What to measure. Each instrument takes its own config, and returns its own value, the measure:
| Instrument | config | Value | Default score |
|---|---|---|---|
fileCreated | { glob } | boolean: whether the agent left a matching file | the value |
grep | { glob, pattern } | number: lines across the matching files that match pattern | the value |
bunTestFile | { subject, test } | { passed, total }: tests passed, of all the tests | the pass rate, passed / total |
replyMatches | { pattern, turn? } | boolean: whether the agent's reply matches pattern | the value |
shell | { command } | { exitCode, stdout, stdoutTruncated } | whether command exits 0 |
filesChanged | { glob? } | FileChanges: { added, modified, deleted } paths changed since the start | none: give each metric a score |
commits | {} | Commit[], oldest first: { sha, message, files: { added, modified, deleted } } | none: give each metric a score |
jsAst | { glob, selectors } | { file, matches, parseError? }[]: for each matching JS or TS file, how many nodes each esquery selector matches | none: give each metric a score |
shell stores command's stdout as it is, up to 64 KiB, in the run data store. A command that prints secrets or other sensitive data will persist them: nothing transforms its output before it's stored.
metrics
Type: Record<string, { score?: (value) => number | boolean | undefined; stat: Stat; better?: "higher" | "lower" }>
Required, with at least one entry. What to read from each run's value, keyed by the metric's name, which must be an identifier. Each metric has:
score: reads one run's value as a number or a boolean, orundefinedwhen the metric doesn't apply to that run. Never return 0 orfalseto mean that. Leave it out to use the instrument's default score.stat: the one statistic across a permutation's iterations. Booleans:rate,count. Numbers:mean,median,min,max,sum.better:"higher"or"lower", if either is better. Left out, neither is.
declareTestCase
File: test-cases/<name>.ts
Which parameters to run, and how often. Every list is crossed with every other, and each combination runs iterations times. Run thunderjar generate after adding a parameter, so its name type-checks here.
export default declareTestCase({
baseImage: ["node20"],
codeState: ["baseline"],
promptSet: ["snerk"],
harnessModel: ["claude-code-2.1.311/claude-sonnet-5-5"],
task: "is-prime",
initialPrompt: ["plain"],
iterations: 5,
});baseImage
Type: BaseImageName[]
Folders under parameters/baseImages/.
codeState
Type: CodeStateName[]
Folders under parameters/codeStates/.
promptSet
Type: PromptSetName[]
Folders under parameters/promptSets/.
harnessModel
Type: `${harness}/${modelId}`[]
A folder under parameters/harnessModels/, and the model ID to give it.
task
Type: TaskName
A folder under parameters/tasks/.
initialPrompt
Type: InitialPromptName[]
Files in that task's initial-prompts/.
iterations
Type: number
How many times to run each combination.
env
Type: Record<string, string>
Environment variables the agent's containers are given, with their values, e.g. { NODE_ENV: "test" }. Not secret: each run records them, and its postrun image keeps them, so its measurement containers see them too. They don't change any hash, so changing one doesn't rebuild a prerun image. For a secret, use secretEnv.
secretEnv
Type: string[]
Default: []
The names of more environment variables the agent's containers are given, e.g. ["DATABASE_URL"], each passed as docker run -e NAME, so its value comes from the shell that runs Thunderjar, as a harness's requiredEnv does. Its measurement containers are given them the same way, e.g. for a shell measurement that queries a database. The value is never on a command line, in a log, in a run's record or in its postrun image's config: only the name is recorded. If the agent writes a value into a file, the postrun image's files are searched for it before it's pushed, and run warns. run stops if one is unset. A runner on a runtime is sent them without listing them in runner.env.
declareConfig
File: thunderjar.config.ts
Where images and run data are kept.
export default declareConfig({
imageStore: null,
runDataStore: sqliteStore({ path: "./run-data.sqlite" }),
});imageStore
Type: { repository: string; deleteCommand?: string[] } | null
The registry repository prerun and postrun images are pushed to, e.g. { repository: "ghcr.io/acme/thunderjar-images" }, with the user's docker login. null keeps them in the local Docker daemon only: nothing is pushed, and no login is needed. deleteCommand is what purge image runs to delete an image the registry won't delete through its standard API, given the image's reference as its last argument.
runDataStore
Type: SqliteStore | PostgresStore
Where run results are recorded: sqliteStore({ path }) for a local file, or postgresStore({ urlEnv }) for a shared database.
build
Type: { secrets?: { id: string; env: string }[]; ssh?: boolean; concurrency?: number }
Secrets, and the SSH agent, for prerun builds, e.g. to clone a private repository, and how many build at once: 1 by default. Each secret is passed as docker build --secret id=<id>,env=<env>, and never written to an image or the run data. ssh: true passes the host's SSH agent as docker build --ssh default.