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:
- the same commands, options, output lines and exit codes;
- the same files, in the same formats (config, state, mailbox, journal), so either client can pick up where the other left off;
- the same wire behaviour: a bash client pairs with a PowerShell one, and talks to a Windows peer and the other way round. Pairing's arithmetic (the commitment, the code, the fleet proof) is checked against fixed vectors in both.
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:
- syntax of every script (
bash -n, the PowerShell parser) and shellcheck warnings; - the plugin and marketplace manifests, the example configs, the slash
commands' frontmatter, and
claude plugin validatewhenclaudeis installed; - the step-summary parsers on
tests/fixtures/*.log, which must agree between bash and PowerShell; - config layering, peer resolution and path mapping, and the repo-config trust rules;
- 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; - 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=1runs the peer side locally instead of over ssh), with the bash client and the PowerShell one; - 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);
- 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-inosascript), fleets and zero-touch joins; - messages v2 and tasks; (9b) the one rule for what a message is
(
tests/fixtures/messages: each file with the answerlib/msg/check.jqandlib/msg/check.ps1must both give), refusals, files put straight into the inbox, a damaged task log, two pulls of one message (held in between withAGENT_BRIDGE_TEST_HOLD),watchon 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'sserve; (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; - monitoring and delegation (
status,pick,max_jobs,auto); - 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; install-cliandintegrate.- with
AGENT_BRIDGE_TEST_SSHD=1only: 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 isserve). 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:
- They never touch the real
~/.ssh,/etc/sshorpeers.json: every fake machine has its own folder, withHOME,AGENT_BRIDGE_CONFIG,AGENT_BRIDGE_SSH_DIR,AGENT_BRIDGE_HOST_KEYandAGENT_BRIDGE_SSHD_ETCpointing into it. The cache and the activity journal (XDG_CACHE_HOME,XDG_STATE_HOME) point into the tests' temp folder too, so a run never adds to your own job history or journal. - They never touch the real network, with one exception you turn on:
AGENT_BRIDGE_TEST_LIVE_MDNS=1also announces and browses a test service with the PowerShell mDNS responder on this machine. - They never open a real dialog or password prompt: dialogs are
stand-in scripts on PATH,
AGENT_BRIDGE_PAIR_NOTIFYis off, and every fake machine isAGENT_BRIDGE_UNATTENDED; the one test of the password dialog uses a stand-inosascriptand asudothat never succeeds. - Whatever they start in the background, they stop.
- bash reads a script as it runs: don't edit
tests/smoke.shwhile it runs (copy it, run the copy).
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:
- Add a
tests/fixtures/<name>.logwith real output of that tool (passing and failing), andtests/fixtures/<name>.expectedwith the one line the summary should be. - Extend both files the same way. A parser speaks only when its tool's
output is there, and matches case-sensitively (
FAILEDmust never match0 failed). tests/smoke.shruns 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.