agent-bridge

Documentation

Offloading work: sync, jobs, results

A job is a named piece of work on a peer: its own git worktree, branch and build folder there, a script split into steps, a log and an exit code per step. You send code to it as a git bundle, run steps in it, read the results, fetch any commits it made, and remove it when you're done. The peer owner's own checkout is never touched.

agent-bridge buildbox sync tests                  # send HEAD to the job "tests" on buildbox
agent-bridge buildbox job tests --preset check    # run its steps there; prints each step's result
agent-bridge buildbox fetch tests                 # its new commits, if any, as branch from-buildbox/tests
agent-bridge buildbox done tests                  # remove it
flowchart LR
  sync["sync<br/>a bundle of what the peer lacks"] --> job["job<br/>steps in its own worktree"]
  job -->|foreground| res["each step: exit code<br/>and a one-line summary"]
  job -->|--bg| bg["wait · logs --follow<br/>a done message when it ends"]
  bg --> res
  res -->|it made something| fetch["fetch: commits as from-peer/job<br/>get: a file from its build folder"]
  res --> done["done<br/>the worktree goes"]
  fetch --> done
  res -. "fix, then sync again" .-> sync

All of these run inside the project's repo, on the client; buildbox is the peer's name (leave it out with a single peer, or set default_peer). In Claude Code, /agent-bridge:offload does this for a build or test run.

Where a job lives

On the peer, for a job tests started from the machine laptop:

Path
Worktree <repo>/.claude/worktrees/bridge-laptop-tests, on branch bridge/laptop/tests-wt
Build folder <build_dir>/bridge-laptop-tests (default build_dir: <repo>/.claude/agent-bridge/build)
Logs and state <repo>/.claude/agent-bridge/jobs/laptop-tests/ (log.txt, steps/NN-name.log, .exit, metrics.tsv)

Job names are lowercase letters, digits and dashes (up to 31). Every job worktree carries an agent-bridge-job marker in its git dir, so other tools can tell it apart (agent-bridge is-job <path> exits 0 for one), and nothing outside bridge-<this machine>- is ever removed. A folder there that isn't a real worktree of the repo, or belongs to another machine, is refused rather than used.

Sending code: sync

agent-bridge buildbox sync tests              # HEAD
agent-bridge buildbox sync tests feat-login   # any ref
agent-bridge buildbox sync tests --force      # even if it drops commits there you haven't fetched

The first sync creates the worktree; later ones move it to the new commit. Only what the peer lacks travels: the peer lists the commits it has (its view of the remote's branches, its own main, the job's branches) and the bundle is cut against those, so a sync after a small change is a few KB, and none at all when the peer already has the commit. Nothing goes through a remote: a peer often can't fetch from it over SSH (credential helpers and keychains can need its owner's desktop session), so nothing depends on that.

sync refuses to move a job that holds commits you haven't fetched, or uncommitted changes: fetch first, or --force (say so to the owner first).

Running: job

agent-bridge buildbox job tests -c 'cargo test --workspace'                      # one step
agent-bridge buildbox job tests -c 'cargo clippy -- -D warnings' -c 'cargo test'  # two steps
agent-bridge buildbox job tests --preset check                                   # the steps of a preset
agent-bridge buildbox job tests -f ci.sh                                         # a script with "# step:" lines
agent-bridge buildbox job tests --bg --preset check                              # in the background

job <name> --op build (or --op test) runs the repo's own build or test command, found on the peer: package.json's script (npm, pnpm, yarn or bun, by its lock file), cargo, a Makefile target, go, swift, or pytest. On a safe link every step runs in the peer's sandbox, a script you wrote has no network, and the peer's deny rules are checked first.

In the foreground the log streams to your terminal and the command returns the job's exit code: the first failing step's. --fail-fast skips the remaining steps after a failure. --bg returns at once with the job running detached on the peer; a done message comes to your inbox when it ends (within a second or two while a session's watch runs: it holds a long poll there; otherwise at your next exchange), and the plugin's monitor shows it in your session. Nothing comes back from the peer by itself: it needs no key into this machine.

A job runs detached from the SSH session, so a dropped link never kills it, and it keeps the peer awake while it runs: macOS (caffeinate), Windows (SetThreadExecutionState), and Linux with systemd (systemd-inhibit, where the system grants a sleep lock to a session that isn't at the screen; if it doesn't, turn suspend off there). On Windows it runs in PowerShell 7.4+; on macOS and Linux in the peer's login shell (bash or zsh; shell in the peer config chooses).

--expect <path> names an output the job must produce: it's deleted before the first step, and the job exits 65 if it isn't there at the end (when a step failed, that step's code comes first), so a run that fails early can never leave an old report that looks new. A plain relative path is in the worktree; @build/<path> is in the build folder. --task <id> makes the job report to a task (started, progress after each step, done or failed).

A job can't be started while one of the same name is still running: wait for it or stop it.

Steps, presets and scripts

Each step has its own log, exit code and summary. Steps come from:

# ci.sh
set -e
export RUST_BACKTRACE=1
# step: lint
cargo clippy --workspace --all-targets -- -D warnings
# step: tests
cargo test --workspace
# step: docs
cargo doc --no-deps

Presets live in the config (Configuration): the project's shared ones in <repo>/.agent-bridge.json, your own per peer in peers.json, and a peer's preset wins over a project one of the same name:

{ "presets": { "test": "cargo test --workspace --locked",
               "check": ["cargo clippy --workspace --all-targets --locked -- -D warnings", "cargo test --workspace --locked"] },
  "peers": { "buildbox": { "presets": { "installer": "cargo build --release --locked" } } } }

What a step's environment holds

Variable Value
AGENT_BRIDGE_JOB bridge-<this machine>-<job>
AGENT_BRIDGE_BUILD_DIR the job's build folder
CARGO_TARGET_DIR the build folder too ("cargo_target_dir": false in the peer config turns it off)
AGENT_BRIDGE_JOBS, CARGO_BUILD_JOBS the peer's jobs cap, when set (use it in your own commands: make -j$AGENT_BRIDGE_JOBS)
everything in env from the config: project-wide, then the peer's (the peer's wins)

The working directory is the job's worktree.

Reading results

agent-bridge buildbox wait tests                 # wait for it; prints each step's result; returns its exit code
agent-bridge buildbox wait tests --timeout 600   # 124 when it's still running then
agent-bridge buildbox logs tests -n 200          # the end of the whole log
agent-bridge buildbox logs tests --step 2        # one step's log
agent-bridge buildbox logs tests --follow        # as it runs
agent-bridge buildbox ls                         # your jobs there: state, branch, commits ahead, uncommitted changes, steps
agent-bridge buildbox stop tests                 # stop it and everything it started (exit 143)

Each step ends with a line like

step 02-cargo-test: exit 101 | tests: 212 passed, 2 failed, 0 ignored | failed: auth::login_redirect, auth::expired
metrics 02-cargo-test: duration_s=184 peak_cpu=97 min_ram_free_gb=3.2

the step's exit code, a summary of its output, and what the machine went through while it ran (sampled every 5 s). A job's state is running, queued (waiting for a slot, see max_jobs), exit=N, or stopped. Exit codes: the job's own; 65 an --expected output is missing; 124 wait timed out; 125 the job ended without an exit code (the machine went down, say); 143 stopped; 255 the SSH link failed (one line says why).

Getting things back: fetch and get

agent-bridge buildbox fetch tests                       # the job's new commits, as branch from-buildbox/tests
agent-bridge buildbox get tests target/report.html      # one file from the worktree
agent-bridge buildbox get tests @build/coverage.lcov ./coverage.lcov   # one from the build folder

fetch brings back only commits made in the job worktree (by a script, or by the agent there working in it); review from-buildbox/tests like any other branch.

Cleaning up: done and clean

agent-bridge buildbox done tests           # remove the worktree, its branches, build folder and logs
agent-bridge buildbox done tests --force   # even with commits you haven't fetched or uncommitted changes
agent-bridge buildbox clean                # dry run: what would go
agent-bridge buildbox clean --apply

done refuses while the job holds commits you haven't fetched, or uncommitted changes. clean does done for every finished job with nothing left to fetch, but keeps a job used in the last 2 hours (an agent may still be on it; --force includes those), and sweeps this machine's build folders there that lost their job, or haven't been built in --stale-days days (default 7). Keeping a job between runs is usually right: an incremental build takes minutes where a cold one takes far longer. /agent-bridge:cleanup runs the end-of-session round.

The owner's checkout: update-checkout

Jobs never touch the peer owner's own checkout. To bring that checkout up to the remote's default branch after you pushed (so the agent and the person at that machine see the new code):

agent-bridge buildbox update-checkout --dry-run
agent-bridge buildbox update-checkout

This machine fetches, sends what the peer lacks, moves the peer's origin/<branch> forward (never back), and fast-forwards its <branch> only when that branch is checked out with no uncommitted changes to tracked files. Otherwise it says what's in the way and changes nothing else. default_branch in the config picks the branch; "fetch_origin": false skips the fetch on this machine.

A quick look: run

agent-bridge buildbox run -c 'git status --short; rustc --version'

A one-off command in the peer's repo folder, for read-only checks: tool versions, what's checked out. It isn't a job: no worktree, no log kept. Anything that changes files belongs in a job.

Choosing the machine: pick, auto, max_jobs

With several peers, let agent-bridge choose:

agent-bridge pick --preset check     # the best peer right now, and one reason line per peer
agent-bridge auto sync tests         # sync to the peer pick chooses
agent-bridge auto job tests --preset check
agent-bridge auto wait tests         # later commands find the same peer again by the job's name

A peer must answer, run the OS you ask for (--os windows), be on AC power (--allow-battery lifts that), have the RAM and disk (--need-ram GB, --need-disk GB), not be heavily loaded, and have a free slot. Among those, idle cores, free memory, its running jobs, how long the same preset took there before (kept in ~/.cache/agent-bridge/history.jsonl) and the owner's weight in its config decide. max_jobs in a peer's config caps how many jobs run there at once, from every project and machine; more wait as queued. top shows every peer's load, refreshed; status one peer's in full (CPU, load averages, memory, disks, power, heat, GPU, the busiest processes).

Before publishing a report: guard

When a job produces a number you publish (coverage, a quality score), guard stands between the job and the upload:

agent-bridge buildbox job cov --preset coverage --expect @build/lcov.info
agent-bridge buildbox get cov @build/lcov.info ./lcov.info
agent-bridge buildbox guard coverage --lcov ./lcov.info --job cov   # or --value 81.4

It refuses (REFUSED: ..., exit 1) when job cov crashed or lost an expected output, or when the value dropped more than --max-drop points (default 2) below the last value it accepted for that key. A refusal means find out why, never publish anyway; --force accepts a drop you've explained.

Step summaries

After each step, the runner adds a summary to its step NN-name: exit N line, from lib/job/summary.awk (macOS/Linux) and lib/job/summary.ps1 (Windows), which give the same output:

Tool Summary
cargo tests: P passed, F failed, I ignored | failed: <names> | errors: N | could not compile: <crates> | crashed: N (crashed: a test binary killed by a signal or a Windows status, so its results are missing)
pytest its closing counts, and the FAILED/ERROR node ids
jest its Tests: line and the failing files
go test packages ok/FAIL and the failing tests
anything else print AGENT_BRIDGE_SUMMARY: <text> from your step, and | <text> is added

Each parser speaks only when its tool's output is there, and all matching is case-sensitive (FAILED never matches 0 failed). To add one, see Development.

Edit this page on GitHub →