agent-bridge

Documentation

Development

Layout

See How it works for what each folder is. To work on the plugin, load your checkout instead of the installed copy (claude --plugin-dir .), or run bin/agent-bridge from the checkout directly: it finds its own files from wherever it's run.

Two implementations, one behaviour

Everything a client does exists twice: in bash (bin/agent-bridge, lib/**/*.sh; bash 3.2, the one macOS ships) and in PowerShell 7.4 (bin/agent-bridge.ps1, lib/**/*.ps1). They must stay interchangeable:

A change to one is a change to both, in the same commit, with a test that runs both. What a message must look like is written once per language (lib/msg/check.jq, lib/msg/check.ps1); to change it, change both and add a file to tests/fixtures/messages with the answer both must give.

The peer side follows the same rule (lib/peer/posix.sh, lib/peer/windows.ps1), and so do the step summaries.

Tests

tests/smoke.sh

It checks everything that doesn't need a second machine (bash, git and jq needed; pwsh and shellcheck are used when present), in about ten minutes:

  1. syntax of every script (bash -n, the PowerShell parser) and shellcheck warnings;
  2. the plugin and marketplace manifests, the example configs, the slash commands' frontmatter, and claude plugin validate when claude is installed;
  3. the step-summary parsers on tests/fixtures/*.log, which must agree between bash and PowerShell;
  4. config layering, peer resolution and path mapping, and the repo-config trust rules;
  5. message encoding; (6b to 6d) a peer speaks only for itself, what a peer answers is data (numbers that carry a command, from a stand-in ssh and a stand-in date), a mailbox never comes from a repository;
  6. whole flows (sync, steps, --expect, fetch, the refusals, done, clean, guard, messages) against a fake macOS/Linux peer on this machine (AGENT_BRIDGE_TEST_LOCAL=1 runs the peer side locally instead of over ssh), with the bash client and the PowerShell one;
  7. a peer that can't reach the remote, update-checkout, address lists with networks, a name that doesn't resolve (a fake ssh/scp on PATH);
  8. discovery and pairing: the dns-sd, avahi and mDNS parsers on captured output, the pairing arithmetic in both implementations, and whole pairings between two fake machines in every mix of clients, with a folder standing in for the network (AGENT_BRIDGE_DISCOVERY=dir:<path>): wrong codes, a tampered state file, the code window, the whole-network choice, failures that must be reported at once, pair --check, the sshd checks, the password dialog (with a stand-in osascript), fleets and zero-touch joins;
  9. messages v2 and tasks; (9b) the one rule for what a message is (tests/fixtures/messages: each file with the answer lib/msg/check.jq and lib/msg/check.ps1 must both give), refusals, files put straight into the inbox, a damaged task log, two pulls of one message (held in between with AGENT_BRIDGE_TEST_HOLD), watch on a fresh mailbox, a peer without the project, the link peer by peer, task stamps with the clocks apart, text from stdin; (9c) sessions, mail for one session, shown and read, the session-start line, wait-idle, the receiver's rules, a session that waits for its owner; (9d) a messages-only link over a stand-in sshd that runs the other side's serve; (9e) the machine's own mailbox, each machine with a state folder of its own, and the outbox in batches; (9f) the Claude Code channel's handshake and events;
  10. monitoring and delegation (status, pick, max_jobs, auto);
  11. the activity journal: each CLI's hook payload (tests/fixtures/hooks/), redaction, levels, what the peer side and the runner record, monitor --once/--json/--events;
  12. install-cli and integrate.
  13. with AGENT_BRIDGE_TEST_SSHD=1 only: both clients over a real sshd, started as you on a loopback port with keys of its own in the test folder (ping, run, sync, a job, a message, and a messages-only key whose forced command is serve). It is asked for because it opens a port on 127.0.0.1 for about a minute; CI sets it.

On Windows, tests/windows-loopback.ps1 does what section 13 does for the Windows peer side, the job runner and setup/enable-ssh-windows.ps1. It changes the machine's SSH server, so it runs on a CI runner (or with -ThisMachineMayBeChanged), never as part of tests/smoke.sh.

.github/workflows/tests.yml runs it on every push and pull request, on a Linux and a macOS runner, with both clients. A Windows runner parses every PowerShell script and holds lib/msg/check.ps1 to the message fixtures; it also starts the smoke test, which has never run on Windows, without letting it fail the run. Nothing runs the Windows peer side yet (lib/peer/windows.ps1, the Windows runner and setup script): that needs a real SSH server on the runner.

On Windows (Git Bash, in a shell that isn't elevated), tests/smoke.sh runs what needs no macOS/Linux fake peer: the syntax, the manifests, the summaries, config and paths, the message rule, the pairing arithmetic and the hooks, with the profile, LOCALAPPDATA, APPDATA and the temp folder inside its own folder; every part it skips says why. The Windows peer side has a test of its own:

pwsh -File tests/windows-loopback.ps1

It starts an sshd of its own (the machine's sshd.exe, as you, on a free loopback port, with its own host key, keys and config) and drives the PowerShell client through it: ping, run, sync, jobs and their exit codes, background jobs, stop, wait, get, fetch, messages, a messages-only key, monitor, doctor, done; and the launchers (the hooks' command through Git Bash, agent-bridge.cmd). Nothing on the machine changes. It needs PowerShell 7 as the machine's SSH shell, which setup/enable-ssh-windows.ps1 sets. With -WithSetup (CI) it first runs that script against the machine's real SSH server and repeats the tests through it on port 22; off a CI runner it refuses unless you add -ThisMachineMayBeChanged.

Some rules the tests keep:

The white-label guard. If an untracked tests/private-terms.txt exists (one term per line; gitignored), the tests also fail when any tracked file contains one of those terms (case-insensitive): a guard for forks that must not carry their owner's host names, addresses or paths. Use the documentation ranges (192.0.2.0/24, 198.51.100.0/24) and example names (laptop, buildbox) in tests and docs.

Adding a step summary

Summaries come from lib/job/summary.awk (macOS/Linux) and lib/job/summary.ps1 (Windows), which must give the same output for the same log. To teach them a new tool:

  1. Add a tests/fixtures/<name>.log with real output of that tool (passing and failing), and tests/fixtures/<name>.expected with the one line the summary should be.
  2. Extend both files the same way. A parser speaks only when its tool's output is there, and matches case-sensitively (FAILED must never match 0 failed).
  3. tests/smoke.sh runs both on every fixture and fails when either differs from the expected line.

Releasing

The version is in three places, which must agree (the tests check it): .claude-plugin/plugin.json (version, what Claude Code compares to offer an update), AB_VERSION in bin/agent-bridge, and $AbVersion in bin/agent-bridge.ps1 (what agent-bridge version prints). Bump all three in one commit, run tests/smoke.sh, then tools/release.sh: it checks that the three agree and the tree is clean, and tags the commit v<version>, signed with the release key (~/.ssh/agent_bridge_release_ed25519 on the machine releases come from; its public half is .claude-plugin/release-signers). Push with git push --follow-tags: the marketplace serves the repository's default branch, and agent-bridge update installs only a commit a verified release tag points at, so push the tag with it.

Edit this page on GitHub →