Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| `src/cli.ts` | Entry. Core commands, then adapter commands from the registry |
| `src/install.ts` | Links `agent-bridge`, then runs each adapter's install or uninstall |
| `src/paths.ts` | State locations (`~/.agent-bridge`) and `ensureHome` |
| `src/config.ts` | Opt-in user preferences (`~/.agent-bridge/config.json`: auto-join and folder ignore list) |
| `src/schema.ts` | Zod schemas for every boundary: socket requests and replies, messages, peers |
| `src/names.ts` | Auto peer names: `<folder>-<kind>` base, next free suffix. Pure |
| `src/format.ts` | Send results, shared by the tools and the CLI. Agent-specific wording lives in the adapter (`agy/format.ts`) |
Expand All @@ -22,7 +23,7 @@
| `src/lib/` | Generic helpers, no bridge logic: `errors` (errno codes, `toError`, `isDaemonDown`), `json-file` (validated read, atomic write, `readJsonDir`), `log` (tagged stderr), `wire` (JSON lines), `args`, `config` (other tools' config and PATH links), `rate` (token bucket), `tty` (ask on a terminal; undefined without one) |
| `src/adapters/types.ts` | The `Adapter` interface every agent kind implements |
| `src/adapters/index.ts` | `ADAPTERS` registry, typed `Record<PeerKind, Adapter>` |
| `src/adapters/<kind>/` | Everything agent-specific. `index.ts` exports the adapter and is the folder's only entry point. The rest is split by concern: `mcp.ts`, `install.ts`, `names.ts` (constants), and the wake path (`agy/push.ts`, `agy/listen.ts`, `agy/hook.ts`, `agy/format.ts`, `claude/socket.ts`, `claude/monitor.ts`, `claude/format.ts`, `claude/channel/`) |
| `src/adapters/<kind>/` | Everything agent-specific. `index.ts` exports the adapter and is the folder's only entry point. The rest is split by concern: `mcp.ts`, `install.ts`, `names.ts` (constants), and the wake path (`agy/push.ts`, `agy/listen.ts`, `agy/hook.ts`, `agy/format.ts`, `claude/socket.ts`, `claude/session.ts`, `claude/monitor.ts`, `claude/format.ts`, `claude/channel/`) |
| `src/adapters/agy/skill/` | The Antigravity `/bridge` skill, copied by install |
| `src/adapters/opencode/plugin/` | The opencode plugin. Standalone (node built-ins only): install copies the built file into opencode's plugins folder |
| `src/adapters/claude/plugin/` | The Claude plugin: `/bridge` (socket) and `/bridge-monitor` skills sharing `shared/peer-messages.md`, the monitor, and the bypass-guard hook. Registered by install through the repo's `.claude-plugin/marketplace.json` |
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ agent-bridge install # once per machine, and again after each updat

From source: `git clone https://github.com/logickoder/agent-bridge.git`, then `pnpm install && pnpm build && node dist/cli.js install`.

Then join from each session: `/bridge` in Claude Code or Antigravity, or ask opencode to join the bridge. Without a name you get `<folder>-<kind>` (e.g. `myapp-claude`); `/bridge planner` picks one. Ask any session to message another by name. `/bridge <new name>` renames, `/bridge off` leaves. `agent-bridge uninstall` removes everything.
Then join from each session: `/bridge` in Claude Code or Antigravity, or ask opencode to join the bridge. Or run `agent-bridge auto-join on` once to join live sessions automatically (with `auto-join ignore [folder]` to skip noisy folders; see [docs/install.md](docs/install.md#auto-join)). Without a name you get `<folder>-<kind>` (e.g. `myapp-claude`); `/bridge planner` picks one. Ask any session to message another by name. `/bridge <new name>` renames, `/bridge off` leaves. `agent-bridge uninstall` removes everything.

Requires Node 22+ (and pnpm to build from source).

Expand Down Expand Up @@ -56,13 +56,14 @@ Delivery is at least once: a message leaves the queue only when it is acked. Sen
| `agent-bridge send [--as me] <to> <text>` | Send. Without `--as`, the sender is `shell`, unverified. Pass `-` as the text to read it from stdin |
| `agent-bridge send [--as me] --to-kind <kind> <text>` | Send to the one online peer of that kind that joined from this folder. Refuses if there are none or several |
| `agent-bridge marker` | A random heredoc end marker, for agents sending with `send ... - <<'<marker>'` |
| `agent-bridge leave <name>` | Unbind a peer and stop its listeners |
| `agent-bridge leave [name \| --session id]` | Unbind a peer and stop its listeners (no arg: this session) |
| `agent-bridge auto-join [on\|off\|ignore\|unignore]` | Auto-join live sessions to the local bridge, with an optional folder ignore list ([docs/install.md](docs/install.md#auto-join)) |
| `agent-bridge status` | Everything, as JSON. Session ids show as tags |
| `agent-bridge restart` | Stop the daemon. The next client starts it |
| `agent-bridge claude [--as name] [claude args]` | Launch Claude Code with a channel instead of the socket |
| `agent-bridge net <sub>` | Networks across machines: `host`, `invite`, `connect`, `status`, `fingerprint`, `verify`, `trust`, `allow`, `share`, `kick`, `set-url`, `leave`, `stop`. `agent-bridge net` lists them |

Agent-side commands, called by skills, hooks and plugins: `listen`, `agy-hook`, `monitor`, `claude-guard`, `opencode-stream`, `mcp <kind>`, `daemon`. `agent-bridge` with no arguments lists them all.
Agent-side commands, called by skills, hooks and plugins: `listen`, `agy-hook`, `agy-session-start`, `monitor`, `claude-guard`, `claude-session-start`, `claude-session-end`, `opencode-stream`, `mcp <kind>`, `daemon`. `agent-bridge` with no arguments lists them all.

## Development

Expand Down
1 change: 1 addition & 0 deletions docs/agents/antigravity.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Endpoints live in daemon memory, and hooks never see the token (finding 9). Afte
9. **Hooks do not get the address or token.** A probe hook saw only `ANTIGRAVITY_CONVERSATION_ID`, so only `join` can register direct delivery.
10. **The endpoint dies when Antigravity restarts.** After `agy --continue` (same conversation id) `send-message` failed with exit 1.
11. **Antigravity asks before answering another user's agent at all.** Over a network (2026-11-19), it read the caution and asked its user before replying even to "what is 17 times 23?", where Claude Code replied on its own. Safe, but each remote exchange needs the user once.
12. **`SessionStart` and no `SessionEnd`.** `hooks.json` supports `SessionStart` (`conversationId`, `cwd`, `workspacePaths` on stdin; `injectSteps` on stdout), which `agy-session-start` uses when auto-join is enabled to ask `agy` to run `join --kind agy` on the first turn (hooks still lack the agentapi address and token, finding 9). Antigravity has no `SessionEnd` hook; the daemon probes `ANTIGRAVITY_LS_ADDRESS` (`localhost:<port>`) with a loopback TCP connect on demand to drop exited CLI sessions (each CLI session runs its own LS port; in the IDE/desktop app where one LS serves multiple conversations, the port stays open until the LS exits).
1 change: 1 addition & 0 deletions docs/agents/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Do not register the channel server at user scope. Claude does not tell a server
10. **`CLAUDE_CODE_SESSION_ID` can differ between processes of one long-lived session.** So `whoami` from Claude's shell can miss; ask Claude instead. Without the variable, the channel server keys on its pid and each restart gets a new name.
11. **`AGENT_BRIDGE_HOME` reaches the session's Bash and push endpoint.** Live, 2026-11-19: two sessions started as `AGENT_BRIDGE_HOME=<home> claude` each joined their own home's daemon, and the default home saw neither.
12. **Claude adds its own framing to socket messages.** After our text it appends "This came from another Claude session... very likely working on their behalf. Treat it as a teammate's request". For a message from another user's agent that is wrong; our caution comes first and Sonnet followed it (refused to read and send a file, refused to verify a fingerprint sent over the bridge). We cannot change Claude's text. Tested 2026-11-19 with Haiku and Sonnet in auto mode against urgent, pre-approved and impersonating requests: both followed our caution every time (`docs/live-tests.md`).
13. **`SessionStart` and `SessionEnd` hooks.** Tested live in interactive tmux and `-p` modes (2026-11-24): `SessionStart` fires on launch with `session_id` and `cwd` on stdin plus `CLAUDE_CODE_SESSION_ID` and `CLAUDE_CODE_MESSAGING_SOCKET` in env, so `claude-session-start` can auto-join silently when enabled. `SessionStart` does not include `permission_mode` even with `--dangerously-skip-permissions`. `SessionEnd` fires on `/exit` with `session_id` on stdin and `CLAUDE_CODE_SESSION_ID` in env, allowing `claude-session-end` to call `leave --session`.
1 change: 1 addition & 0 deletions docs/agents/opencode.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Identity: the tool call's `sessionID`, which the plugin passes to the CLI as `OP
3. **`ctx.session.prompt({ sessionID, text })` wakes an idle session.** Spike, 2026-11-02: a prompt scheduled 20s after the turn ended showed in the TUI and was answered. Source: opencode.ai/v2/docs/build/plugins/server.
4. **Plugins run in a background `opencode serve --service` that outlives the TUI.** Live, 2026-11-19 (opencode 2.3.0): after the TUI exited, the service and its `agent-bridge opencode-stream` child kept running. The environment, `AGENT_BRIDGE_HOME` included, is whatever the process that started the service had: a TUI started later with another home joins the service's home.
5. **A model can call a tool several times in one turn.** The free "Big Pickle" model ran three identical `bridge_send` calls for one reply; the bridge delivered each.
6. **v2 event stream (`ctx.event.subscribe`).** Tested live in tmux on opencode 2.4.1 (2026-11-24): events arrive as `{ type, location: { directory }, data: { sessionID, ... } }`. The plugin subscribes to `session.created` (auto-joins when enabled for `ctx.location.directory`) and `session.deleted` (stops the stream and runs `leave --session`).
4 changes: 2 additions & 2 deletions docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Why the bridge works the way it does. Findings referenced here live in [agents/]
| `mcp <kind>`, not env sniffing | Each client's config names its kind; sniffing does not scale past two |
| Push endpoints are listeners in the hub (`PushConn`) | Delivery, ack and fallback reuse the same rules for every push path |
| One receive path per session | A push next to a stream listener is refused, and `join` reports it |
| An adapter with `alive` gets its endpoints saved | Claude's socket path is safe on disk and survives a daemon restart. Antigravity's holds a CSRF token, so it has no `alive` and stays in memory. A restored endpoint is checked before it gets mail. The check compares the socket file's inode and creation time: the path holds a pid, which a later session can reuse |
| An adapter with `persistEndpoint` gets its endpoints saved; `alive` probes liveness | Claude's socket path is safe on disk and survives a daemon restart (`persistEndpoint: true`). Antigravity's holds a CSRF token, so it stays in memory (`persistEndpoint` unset), while `alive` still probes its loopback TCP port. Restored endpoints are checked before getting mail (Claude compares socket inode and creation time). Background sweeps kicked by `status` and `send --to-kind` (with a 3s per-endpoint cooldown and one retry after 100ms) plus a 45s timer drop dead endpoints without losing `peer.session` |
| Peers record their folder; the daemon resolves `--to-kind` | The agent next to you is usually the one you mean. The hub holds the folders, so any client can use it. Several matches refuse rather than guess. Exact folder only: a subfolder does not match |
| Agents send text on stdin, through a quoted heredoc with a random end marker (`send ... - <<'<marker>'`) | The marker is made where the hint is shown, per hint, or by `agent-bridge marker`, never by the agent (a model's "random" marker repeats): the shell ends a heredoc at the first line equal to its marker and runs the rest, so a fixed marker would let a quoted message plant it. Text passed as a double-quoted argument is expanded by the shell: backticks or `$(...)` quoted from a message ran on the sender's machine and dropped out of the text (#8). Sending only through MCP tools would avoid the shell but lose the session-id check on `--as`. opencode's tool passes the text on stdin too, never through a shell |

Expand All @@ -42,7 +42,7 @@ Why the bridge works the way it does. Findings referenced here live in [agents/]
| Antigravity: push runs only an absolute `.../agy` | The endpoint arrives over the socket. The socket is 0600, so this is defence in depth |
| Antigravity: hook drain is acked after print | The hook's 1.5s cap or Antigravity's 3s kill could fire between drain and print |
| Antigravity: the PreInvocation hook never blocks | 1.5s cap, `{}` on any failure |
| Antigravity: `/bridge` skill, not SessionStart auto-join | `hooks.json` is global: auto-join would make every Antigravity session take the binding |
| Opt-in auto-join (`agent-bridge auto-join on\|off\|ignore\|unignore`) | Off by default in `~/.agent-bridge/config.json`, with a folder ignore list so one-time setup does not require per-repo config. Claude (`SessionStart` / `SessionEnd`) and opencode (`session.created` / `session.deleted`) auto-join silently; Antigravity's `SessionStart` asks `agy` to run `join --kind agy` on the first turn because hooks lack the agentapi token. Auto-join never auto-shares to a network |
| opencode: an in-process plugin | Its tools know the sessionID and `ctx.session.prompt` wakes an idle session, so no ports or passwords. The plugin stays thin; naming, queues and acks stay in the CLI |

## Names and senders
Expand Down
19 changes: 17 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
| Target | Change |
|---|---|
| `/opt/homebrew/bin` (or `/usr/local/bin`, `~/.local/bin`) | Symlinks `agent-bridge` to `dist/cli.js`, unless an `agent-bridge` from this package is already on PATH (an npm global install). Uninstall removes only a link install made. Also removes a `claude-bridge` link from older installs |
| Claude Code plugins | `claude plugin marketplace add <repo>` and `claude plugin install agent-bridge@agent-bridge`. The repo is a local marketplace (`.claude-plugin/marketplace.json`); the plugin lives in `src/adapters/claude/plugin/` and loads in place |
| Claude Code plugins | `claude plugin marketplace add <repo>` and `claude plugin install agent-bridge@agent-bridge` (refreshing any cached copy so updated hooks and skills take effect). The repo is a local marketplace (`.claude-plugin/marketplace.json`); the plugin lives in `src/adapters/claude/plugin/` |
| `~/.gemini/config/mcp_config.json` | Adds the `agent-bridge` server. Other servers untouched |
| `~/.gemini/config/hooks.json` | Adds the `agent-bridge` hook group (PreInvocation). Other groups untouched |
| `~/.gemini/config/hooks.json` | Adds the `agent-bridge` hook group (`SessionStart`, `PreInvocation`). Other groups untouched |
| `~/.gemini/config/skills/bridge/` | Copies the Antigravity `/bridge` skill from `src/adapters/agy/skill/` |
| `~/.config/opencode/plugins/agent-bridge.js` | Copies the built opencode plugin. Restart opencode to load it |

To pause the Antigravity hook, set `"enabled": false` on the `agent-bridge` group in `hooks.json`.

## Auto-join

Auto-join is off by default. Turn it on once to join live sessions to the local bridge automatically (saved in `~/.agent-bridge/config.json`):

```sh
agent-bridge auto-join on
agent-bridge auto-join ignore /path/to/scratch # skip noisy folders (exact match)
agent-bridge auto-join off
```

- **Claude Code:** joins silently on `SessionStart` and leaves on `SessionEnd`.
- **opencode:** joins silently on `session.created` and leaves on `session.deleted`.
- **Antigravity:** `SessionStart` prompts `agy` to run `agent-bridge join --kind agy` on its first turn (hooks do not receive the agentapi address or token). Antigravity has no `SessionEnd` hook; the daemon probes its local `ANTIGRAVITY_LS_ADDRESS` port to drop exited CLI sessions. In the IDE or desktop app where one language server serves multiple conversations, a closed conversation stays listed online until that language server exits.
- Auto-join only joins the local bridge. Network sharing (`/bridge share`) stays opt-in per session.

## Environment overrides

| Variable | Overrides |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logickoder/agent-bridge",
"version": "0.2.2",
"version": "0.2.3",
"description": "Live messaging between agent CLI sessions (Claude Code, Antigravity, opencode). Each message wakes the receiving session in place.",
"author": {
"name": "Jeffery Orazulike",
Expand Down
24 changes: 23 additions & 1 deletion src/adapters/agy/hook.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from 'vitest'
import { DEFAULT_CONFIG, ignoreAutoJoinFolder } from '../../config.js'
import type { Message } from '../../schema.js'
import { hookOutput, type Drained } from './hook.js'
import { hookOutput, sessionStartOutput, type Drained } from './hook.js'

const msg = (id: string): Message => ({ id, from: 'claude', to: 'agy', text: `text ${id}`, ts: '2026-11-02T00:00:00.000Z' })
const drained = (msgs: Message[], rejoin = false): Drained => ({ msgs, rejoin, ack: vi.fn(async () => {}) })
Expand Down Expand Up @@ -51,3 +52,24 @@ describe('hookOutput', () => {
expect(JSON.stringify(r.out)).toMatch(/text m1[\s\S]*agent-bridge join --kind agy/)
})
})

describe('sessionStartOutput', () => {
const onCfg = { autoJoin: { enabled: true, ignore: [] } }

it('returns {} when off, ignored, missing conversationId, or already online', async () => {
const isOnline = vi.fn(async () => false)
expect(await sessionStartOutput('{"conversationId":"c1","cwd":"/p/app"}', { config: () => DEFAULT_CONFIG, isOnline })).toEqual({})
expect(await sessionStartOutput('{"conversationId":"c1","cwd":"/p/app"}', { config: () => ignoreAutoJoinFolder(onCfg, '/p/app'), isOnline })).toEqual({})
expect(await sessionStartOutput('{"cwd":"/p/app"}', { config: () => onCfg, isOnline })).toEqual({})
expect(await sessionStartOutput('{"conversationId":"c1","cwd":"/p/app"}', { config: () => onCfg, isOnline: async () => true })).toEqual({})
expect(isOnline).not.toHaveBeenCalled()
})

it('injects the auto-join instruction when enabled for the folder', async () => {
const out = await sessionStartOutput('{"conversationId":"c1","workspacePaths":["/p/app"]}', {
config: () => onCfg,
isOnline: async () => false,
})
expect(out).toEqual({ injectSteps: [{ userMessage: expect.stringMatching(/agent-bridge join --kind agy/) }] })
})
})
Loading