agentbridge-tg 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. agentbridge_tg-0.1.0/LICENSE +21 -0
  2. agentbridge_tg-0.1.0/PKG-INFO +161 -0
  3. agentbridge_tg-0.1.0/README.md +146 -0
  4. agentbridge_tg-0.1.0/agentbridge/__init__.py +2 -0
  5. agentbridge_tg-0.1.0/agentbridge/__main__.py +3 -0
  6. agentbridge_tg-0.1.0/agentbridge/bridge.py +1557 -0
  7. agentbridge_tg-0.1.0/agentbridge/cli.py +673 -0
  8. agentbridge_tg-0.1.0/agentbridge/config.py +118 -0
  9. agentbridge_tg-0.1.0/agentbridge/drivers/__init__.py +34 -0
  10. agentbridge_tg-0.1.0/agentbridge/drivers/launchd.py +96 -0
  11. agentbridge_tg-0.1.0/agentbridge/drivers/tmux.py +268 -0
  12. agentbridge_tg-0.1.0/agentbridge/hook.py +182 -0
  13. agentbridge_tg-0.1.0/agentbridge/httpserver.py +138 -0
  14. agentbridge_tg-0.1.0/agentbridge/migrate.py +83 -0
  15. agentbridge_tg-0.1.0/agentbridge/policy.py +208 -0
  16. agentbridge_tg-0.1.0/agentbridge/setup_wizard.py +219 -0
  17. agentbridge_tg-0.1.0/agentbridge_tg.egg-info/PKG-INFO +161 -0
  18. agentbridge_tg-0.1.0/agentbridge_tg.egg-info/SOURCES.txt +33 -0
  19. agentbridge_tg-0.1.0/agentbridge_tg.egg-info/dependency_links.txt +1 -0
  20. agentbridge_tg-0.1.0/agentbridge_tg.egg-info/entry_points.txt +4 -0
  21. agentbridge_tg-0.1.0/agentbridge_tg.egg-info/requires.txt +1 -0
  22. agentbridge_tg-0.1.0/agentbridge_tg.egg-info/top_level.txt +1 -0
  23. agentbridge_tg-0.1.0/pyproject.toml +25 -0
  24. agentbridge_tg-0.1.0/setup.cfg +4 -0
  25. agentbridge_tg-0.1.0/tests/test_agents.py +126 -0
  26. agentbridge_tg-0.1.0/tests/test_drivers.py +38 -0
  27. agentbridge_tg-0.1.0/tests/test_format.py +74 -0
  28. agentbridge_tg-0.1.0/tests/test_httpserver.py +62 -0
  29. agentbridge_tg-0.1.0/tests/test_keychain.py +41 -0
  30. agentbridge_tg-0.1.0/tests/test_migrate.py +39 -0
  31. agentbridge_tg-0.1.0/tests/test_origin.py +63 -0
  32. agentbridge_tg-0.1.0/tests/test_policy.py +43 -0
  33. agentbridge_tg-0.1.0/tests/test_setup.py +44 -0
  34. agentbridge_tg-0.1.0/tests/test_telegram.py +631 -0
  35. agentbridge_tg-0.1.0/tests/test_wrapper.py +113 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rampelli Sai Eshwar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentbridge-tg
3
+ Version: 0.1.0
4
+ Summary: Reach Claude Code, Codex and agy sessions on your Mac from Telegram
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/rampellisaieshwar/agentbridge
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Environment :: Console
9
+ Classifier: Topic :: Software Development
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: httpx>=0.27
14
+ Dynamic: license-file
15
+
16
+ # AgentBridge
17
+
18
+ AgentBridge lets you reach Claude Code (`claude`), Codex (`codex`), and Antigravity CLI (`agy`) sessions running on your Mac from Telegram.
19
+
20
+ The bridge runs locally on your Mac and long-polls the Telegram Bot API over outbound HTTPS only—no public port, webhook, or tunnel is required. The CLI is installed as both `agentbridge` and `agb`.
21
+
22
+ ## Requirements
23
+
24
+ - macOS
25
+ - Homebrew
26
+ - `tmux` (`agentbridge setup` can install it with Homebrew if missing)
27
+ - Python 3.10+
28
+ - At least one agent CLI on `PATH`: `claude`, `codex`, or `agy`
29
+ - A Telegram account
30
+
31
+ ## Install
32
+
33
+ AgentBridge is currently distributed from a private Homebrew tap:
34
+
35
+ ```sh
36
+ brew tap rampellisaieshwar/agentbridge https://github.com/rampellisaieshwar/homebrew-agentbridge
37
+ brew install agentbridge
38
+ agentbridge setup
39
+ ```
40
+
41
+ Or from PyPI (macOS; install tmux yourself first, e.g. `brew install tmux`):
42
+
43
+ ```sh
44
+ pipx install agentbridge-tg
45
+ agentbridge setup
46
+ ```
47
+
48
+ ## What setup does
49
+
50
+ `agentbridge setup` is an interactive wizard (safe to re-run; completed steps are detected and confirmed):
51
+
52
+ 1. **Check the Mac** — verifies `tmux` (offering `brew install tmux` if missing) and checks which of `claude`, `codex`, and `agy` are on `PATH`.
53
+ 2. **Telegram bot** — guides you through creating a bot with `@BotFather`, validates the token against Telegram, and stores it in the macOS Keychain (falling back to `~/.agentbridge/config.env` only if the Keychain is unavailable).
54
+ 3. **Background service** — installs and starts a `launchd` user agent (`com.agentbridge.bridge`) under `caffeinate -i` so the bridge starts at login and prevents idle sleep while on.
55
+ 4. **Pair your phone** — prints a one-time 6-digit `/pair <code>` command generated on the Mac and waits until you send it from a private Telegram chat.
56
+ 5. **Optional features** — asks before enabling each one:
57
+ - Shell aliases in `~/.zshrc` (or `~/.bashrc` for bash, backing up the file to `*.agentbridge-backup` first) so `claude` and `codex` start bridged.
58
+ - If `agy` is installed: installs the local `agentbridge` `agy` plugin and adds the `agy` alias.
59
+ - Unlock PIN (`agb pin`).
60
+ - Local voice-note transcription (`agb voice-setup`, ~500 MB).
61
+ 6. **Test message** — sends a confirmation message to the paired Telegram chat.
62
+
63
+ ## Daily use
64
+
65
+ With shell aliases enabled, running `claude`, `codex`, or `agy` starts the agent inside a bridged tmux session named after the current directory and attaches to it. Non-interactive invocations (subcommands, `-p`/`--help`/`--version`, pipes, nested tmux, permission-bypass flags, `--settings`, or the bridge's own directory) pass straight through to the plain CLI unbridged.
66
+
67
+ To start a normal unbridged session at any time, bypass the alias:
68
+
69
+ ```sh
70
+ command claude
71
+ ```
72
+
73
+ Bridged tmux sessions display a clickable status bar with `ON` / `OFF` (bridge toggle) and `private` (per-session visibility toggle).
74
+
75
+ ### CLI commands
76
+
77
+ | Command | Description |
78
+ | --- | --- |
79
+ | `agb on` / `agb off` | Start or stop the background bridge (`agb off` keeps it off after restart and releases keep-awake; sessions keep running). |
80
+ | `agb status` | Show bridge state, token location, bot/pairing status, and running sessions. |
81
+ | `agb list` | List bridged sessions with state, mode, and `shared`/`private`. |
82
+ | `agb attach <name>` | Attach your terminal to a bridged session. |
83
+ | `agb kill <name>` | Kill a bridged tmux session. |
84
+ | `agb private <name>` / `agb share <name>` | Hide a session from the phone or share it again (sessions start shared). |
85
+ | `agb token [--clear]` | Set or remove the Telegram bot token. |
86
+ | `agb pin [--clear]` | Set or remove the 4–32 character unlock PIN (Mac-only). |
87
+ | `agb voice-setup [--remove] [--model small\|base]` | Install or remove local speech-to-text for voice notes (`whisper-cpp`, `ffmpeg`, and model). |
88
+ | `agb agy-setup [--remove]` | Install or remove the `agentbridge` `agy` plugin (inert outside bridged sessions). |
89
+
90
+ Other utility commands: `agb toggle`, `agb new <name> <dir> [--mode manual|auto]`, `agb logs`, `agb pair`, `agb unpair`, `agb bridge` (foreground), and `agb service install|uninstall|status`.
91
+
92
+ ## Phone commands
93
+
94
+ Send these in the paired Telegram chat (also shown by `/help`):
95
+
96
+ | Command | Description |
97
+ | --- | --- |
98
+ | `/list` | List shared sessions with buttons to select or watch/unwatch them. |
99
+ | `/use <name>` | Pick the active session. |
100
+ | `/watch <name>\|all` / `/unwatch <name>\|all` | Forward replies from Mac-started turns for a session (or all); `/watching` shows the list. |
101
+ | `/unlock <name> [min]` / `/lock <name>\|all` | Temporarily relax the block list for a session with your PIN (default 15 min, max 60 min). |
102
+ | `/board` | Refresh and re-pin the live sessions board. |
103
+ | `/status` | Show the active session's state, mode, and last hook event. |
104
+ | `/log [n]` | Show the last `n` terminal lines (default 30, max 200). |
105
+ | `/stop` | Send `Esc` to the active session. |
106
+ | `/mode auto\|manual` | Switch permission mode (Claude sessions only, when idle). |
107
+ | `/queue <text>` | Queue a message to send once the session becomes idle. |
108
+ | `y <id>` / `n <id>` | Allow or deny a pending approval (or tap the inline buttons). |
109
+ | `/send` | Send previously attached photos/files without adding text. |
110
+
111
+ Any other plain text is sent to the active session when idle, or reply to a session's message to address that session directly. Messages starting with `!`, `&`, or `#` are refused so they cannot trigger shell escapes in the agent prompt. Replies longer than four Telegram chunks are sent as the first chunk plus a `.md` attachment.
112
+
113
+ - **Photos and files**: downloaded to `~/.agentbridge/run/inbox/<session>/` (up to 20 MB, kept 7 days) and passed as file paths in the prompt. With a caption (or album with caption), they send right away; without one, they wait up to 10 minutes for your next message or `/send`.
114
+ - **Voice notes (opt-in)**: after `agb voice-setup`, voice notes (up to 5 minutes) are transcribed locally with `whisper.cpp` + `ffmpeg`. The bot shows the transcript with **Send** and **Cancel** buttons so nothing reaches the agent unreviewed.
115
+ - **Approvals and questions**: tool permission prompts (via the `PermissionRequest` hook for Claude/Codex, and screen polling for `agy`) arrive with **Allow** / **Deny** buttons and expire after 10 minutes. Claude's `AskUserQuestion` prompts arrive with inline option buttons (single or multi-select) plus **Type my own**. Answering at either the Mac or the phone settles the prompt.
116
+ - **Watch mode**: quiet by default. Replies to phone-started turns, approvals, and questions always arrive; `/watch` also forwards replies, notifications, and session-end notices from turns started at the Mac.
117
+ - **Pinned board**: a single pinned message listing shared sessions (state, agent, watch icon, unlock status), edited in place every 10 seconds when anything changes.
118
+
119
+ ## Security model
120
+
121
+ - **Single paired private chat**: pairing requires a 6-digit code generated on the Mac (locks after 5 wrong tries). Group chats and all other chats are ignored.
122
+ - **Remote-only block list**: enforced locally in the `PreToolUse` hook (fails closed even if the bridge is down, in both manual and auto modes). It applies **only to turns started from the phone** (or turns of unknown origin); turns typed at the Mac are unaffected. Command matching is regex-based best effort, not a sandbox. Blocked actions:
123
+ - Destructive commands: recursive deletes (`rm -r`, `find -delete`, `xargs rm`), `git push`, `git reset --hard`, `git clean -f`, `git branch -D`, `chmod 777`, `chown -R`, raw disk writes (`mkfs`, `dd of=/dev/`, `diskutil erase`).
124
+ - Privilege/system/shell escapes: `sudo`/`doas`/`su -`, piping `curl`/`wget`/`base64` to shells or interpreters, `launchctl`, `csrutil`, `spctl`, `security find/dump/delete`, `tmux`, and permission-bypass flags.
125
+ - Sensitive paths: reading or writing credential files (`.env`, `.ssh/`, `.aws/`, `.gnupg/`, `.netrc`, `.npmrc`, `.pypirc`, private keys, Keychains), writing outside the project directory (including Codex patches), and modifying AgentBridge or `.claude/settings` / `hooks.json`.
126
+ - Sessions opened inside AgentBridge's own code or data folder are never bridged.
127
+ - **PIN unlock**: set only at the Mac (`agb pin`, stored as an `scrypt` hash in `~/.agentbridge/run/pin.json`). `/unlock` deletes your PIN message from Telegram immediately, pauses 15 minutes after 3 wrong tries, and disables unlock after 6 wrong tries until `agb pin` is run again. Every action executed under unlock is reported to Telegram. Even while unlocked, four categories **always stay blocked**:
128
+ - Touching AgentBridge itself
129
+ - Modifying bridge or Claude settings (`.claude/settings`, `hooks.json`)
130
+ - Permission-bypass flags (`dangerously-skip-permissions`, `bypassPermissions`)
131
+ - Running `tmux` from inside a bridged session
132
+ - **Token storage**: the Telegram bot token is stored in the macOS Keychain via `security -i` (stdin, avoiding process-list exposure), falling back to `0600` `~/.agentbridge/config.env` only if Keychain is unavailable.
133
+ - **Transport encryption**: Telegram bot chats are **not** end-to-end encrypted; messages pass through Telegram's servers. Outbound text runs best-effort secret redaction (API keys, JWTs, bearer tokens, env assignments, long hex/random blobs).
134
+ - **Data folder**: all mutable state lives in `~/.agentbridge` (`0700`, overridable via `AGENTBRIDGE_HOME`): `config.env`, `agentbridge.db`, `run/` (hook token, pairing code, PIN hash, turn markers, inbox, rendered hooks), `logs/bridge.log`, and optional `models/`.
135
+
136
+ ## Uninstall
137
+
138
+ ```sh
139
+ agb service uninstall
140
+ agb agy-setup --remove # if agy was bridged
141
+ agb voice-setup --remove # if voice notes were enabled (optional: brew uninstall whisper-cpp ffmpeg)
142
+ agb token --clear
143
+ brew uninstall agentbridge
144
+ rm -rf ~/.agentbridge
145
+ ```
146
+
147
+ Then remove the `# AgentBridge` alias lines from `~/.zshrc` (or `~/.bashrc`), and optionally run `brew untap rampellisaieshwar/agentbridge`.
148
+
149
+ ## Architecture
150
+
151
+ - **Bridge** (`agentbridge/bridge.py`): local FastAPI/uvicorn server bound to `127.0.0.1:8788` (`/hook`, authenticated by a per-install token in `~/.agentbridge/run/hook_token`).
152
+ - **Background loops**: inside the bridge process, async loops handle Telegram Bot API long-polling, SQLite-backed outbox retries, pinned-board edits, and `agy` screen-prompt polling.
153
+ - **Hooks** (`agentbridge/hook.py`, `agentbridge/policy.py`): `agentbridge-hook` is attached per session for Claude (`--settings`), inline TOML for Codex (`-c hooks={...}`), and via a local plugin for `agy` (inert unless `AGENTBRIDGE_SESSION` is set).
154
+ - **Hook flow**: `PreToolUse` enforces the remote block list locally before any tool runs; `PermissionRequest` and lifecycle hooks (`Stop`, `PostToolUse`, `Notification`, etc.) post to `/hook`.
155
+ - **Terminal driver** (`agentbridge/drivers/tmux.py`): wraps `tmux` (`ab-<name>` sessions) to launch/attach/kill sessions, read terminal state and modes, type prompts, handle `agy` prompts, and render the clickable status bar.
156
+ - **Service driver** (`agentbridge/drivers/launchd.py`): manages the macOS `launchd` user agent (`com.agentbridge.bridge`) running under `caffeinate -i`.
157
+ - **Platform support**: macOS only for now; Linux (`systemd --user` service driver) and Windows (ConPTY terminal + Task Scheduler service drivers) are not supported yet.
158
+
159
+ ## License
160
+
161
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,146 @@
1
+ # AgentBridge
2
+
3
+ AgentBridge lets you reach Claude Code (`claude`), Codex (`codex`), and Antigravity CLI (`agy`) sessions running on your Mac from Telegram.
4
+
5
+ The bridge runs locally on your Mac and long-polls the Telegram Bot API over outbound HTTPS only—no public port, webhook, or tunnel is required. The CLI is installed as both `agentbridge` and `agb`.
6
+
7
+ ## Requirements
8
+
9
+ - macOS
10
+ - Homebrew
11
+ - `tmux` (`agentbridge setup` can install it with Homebrew if missing)
12
+ - Python 3.10+
13
+ - At least one agent CLI on `PATH`: `claude`, `codex`, or `agy`
14
+ - A Telegram account
15
+
16
+ ## Install
17
+
18
+ AgentBridge is currently distributed from a private Homebrew tap:
19
+
20
+ ```sh
21
+ brew tap rampellisaieshwar/agentbridge https://github.com/rampellisaieshwar/homebrew-agentbridge
22
+ brew install agentbridge
23
+ agentbridge setup
24
+ ```
25
+
26
+ Or from PyPI (macOS; install tmux yourself first, e.g. `brew install tmux`):
27
+
28
+ ```sh
29
+ pipx install agentbridge-tg
30
+ agentbridge setup
31
+ ```
32
+
33
+ ## What setup does
34
+
35
+ `agentbridge setup` is an interactive wizard (safe to re-run; completed steps are detected and confirmed):
36
+
37
+ 1. **Check the Mac** — verifies `tmux` (offering `brew install tmux` if missing) and checks which of `claude`, `codex`, and `agy` are on `PATH`.
38
+ 2. **Telegram bot** — guides you through creating a bot with `@BotFather`, validates the token against Telegram, and stores it in the macOS Keychain (falling back to `~/.agentbridge/config.env` only if the Keychain is unavailable).
39
+ 3. **Background service** — installs and starts a `launchd` user agent (`com.agentbridge.bridge`) under `caffeinate -i` so the bridge starts at login and prevents idle sleep while on.
40
+ 4. **Pair your phone** — prints a one-time 6-digit `/pair <code>` command generated on the Mac and waits until you send it from a private Telegram chat.
41
+ 5. **Optional features** — asks before enabling each one:
42
+ - Shell aliases in `~/.zshrc` (or `~/.bashrc` for bash, backing up the file to `*.agentbridge-backup` first) so `claude` and `codex` start bridged.
43
+ - If `agy` is installed: installs the local `agentbridge` `agy` plugin and adds the `agy` alias.
44
+ - Unlock PIN (`agb pin`).
45
+ - Local voice-note transcription (`agb voice-setup`, ~500 MB).
46
+ 6. **Test message** — sends a confirmation message to the paired Telegram chat.
47
+
48
+ ## Daily use
49
+
50
+ With shell aliases enabled, running `claude`, `codex`, or `agy` starts the agent inside a bridged tmux session named after the current directory and attaches to it. Non-interactive invocations (subcommands, `-p`/`--help`/`--version`, pipes, nested tmux, permission-bypass flags, `--settings`, or the bridge's own directory) pass straight through to the plain CLI unbridged.
51
+
52
+ To start a normal unbridged session at any time, bypass the alias:
53
+
54
+ ```sh
55
+ command claude
56
+ ```
57
+
58
+ Bridged tmux sessions display a clickable status bar with `ON` / `OFF` (bridge toggle) and `private` (per-session visibility toggle).
59
+
60
+ ### CLI commands
61
+
62
+ | Command | Description |
63
+ | --- | --- |
64
+ | `agb on` / `agb off` | Start or stop the background bridge (`agb off` keeps it off after restart and releases keep-awake; sessions keep running). |
65
+ | `agb status` | Show bridge state, token location, bot/pairing status, and running sessions. |
66
+ | `agb list` | List bridged sessions with state, mode, and `shared`/`private`. |
67
+ | `agb attach <name>` | Attach your terminal to a bridged session. |
68
+ | `agb kill <name>` | Kill a bridged tmux session. |
69
+ | `agb private <name>` / `agb share <name>` | Hide a session from the phone or share it again (sessions start shared). |
70
+ | `agb token [--clear]` | Set or remove the Telegram bot token. |
71
+ | `agb pin [--clear]` | Set or remove the 4–32 character unlock PIN (Mac-only). |
72
+ | `agb voice-setup [--remove] [--model small\|base]` | Install or remove local speech-to-text for voice notes (`whisper-cpp`, `ffmpeg`, and model). |
73
+ | `agb agy-setup [--remove]` | Install or remove the `agentbridge` `agy` plugin (inert outside bridged sessions). |
74
+
75
+ Other utility commands: `agb toggle`, `agb new <name> <dir> [--mode manual|auto]`, `agb logs`, `agb pair`, `agb unpair`, `agb bridge` (foreground), and `agb service install|uninstall|status`.
76
+
77
+ ## Phone commands
78
+
79
+ Send these in the paired Telegram chat (also shown by `/help`):
80
+
81
+ | Command | Description |
82
+ | --- | --- |
83
+ | `/list` | List shared sessions with buttons to select or watch/unwatch them. |
84
+ | `/use <name>` | Pick the active session. |
85
+ | `/watch <name>\|all` / `/unwatch <name>\|all` | Forward replies from Mac-started turns for a session (or all); `/watching` shows the list. |
86
+ | `/unlock <name> [min]` / `/lock <name>\|all` | Temporarily relax the block list for a session with your PIN (default 15 min, max 60 min). |
87
+ | `/board` | Refresh and re-pin the live sessions board. |
88
+ | `/status` | Show the active session's state, mode, and last hook event. |
89
+ | `/log [n]` | Show the last `n` terminal lines (default 30, max 200). |
90
+ | `/stop` | Send `Esc` to the active session. |
91
+ | `/mode auto\|manual` | Switch permission mode (Claude sessions only, when idle). |
92
+ | `/queue <text>` | Queue a message to send once the session becomes idle. |
93
+ | `y <id>` / `n <id>` | Allow or deny a pending approval (or tap the inline buttons). |
94
+ | `/send` | Send previously attached photos/files without adding text. |
95
+
96
+ Any other plain text is sent to the active session when idle, or reply to a session's message to address that session directly. Messages starting with `!`, `&`, or `#` are refused so they cannot trigger shell escapes in the agent prompt. Replies longer than four Telegram chunks are sent as the first chunk plus a `.md` attachment.
97
+
98
+ - **Photos and files**: downloaded to `~/.agentbridge/run/inbox/<session>/` (up to 20 MB, kept 7 days) and passed as file paths in the prompt. With a caption (or album with caption), they send right away; without one, they wait up to 10 minutes for your next message or `/send`.
99
+ - **Voice notes (opt-in)**: after `agb voice-setup`, voice notes (up to 5 minutes) are transcribed locally with `whisper.cpp` + `ffmpeg`. The bot shows the transcript with **Send** and **Cancel** buttons so nothing reaches the agent unreviewed.
100
+ - **Approvals and questions**: tool permission prompts (via the `PermissionRequest` hook for Claude/Codex, and screen polling for `agy`) arrive with **Allow** / **Deny** buttons and expire after 10 minutes. Claude's `AskUserQuestion` prompts arrive with inline option buttons (single or multi-select) plus **Type my own**. Answering at either the Mac or the phone settles the prompt.
101
+ - **Watch mode**: quiet by default. Replies to phone-started turns, approvals, and questions always arrive; `/watch` also forwards replies, notifications, and session-end notices from turns started at the Mac.
102
+ - **Pinned board**: a single pinned message listing shared sessions (state, agent, watch icon, unlock status), edited in place every 10 seconds when anything changes.
103
+
104
+ ## Security model
105
+
106
+ - **Single paired private chat**: pairing requires a 6-digit code generated on the Mac (locks after 5 wrong tries). Group chats and all other chats are ignored.
107
+ - **Remote-only block list**: enforced locally in the `PreToolUse` hook (fails closed even if the bridge is down, in both manual and auto modes). It applies **only to turns started from the phone** (or turns of unknown origin); turns typed at the Mac are unaffected. Command matching is regex-based best effort, not a sandbox. Blocked actions:
108
+ - Destructive commands: recursive deletes (`rm -r`, `find -delete`, `xargs rm`), `git push`, `git reset --hard`, `git clean -f`, `git branch -D`, `chmod 777`, `chown -R`, raw disk writes (`mkfs`, `dd of=/dev/`, `diskutil erase`).
109
+ - Privilege/system/shell escapes: `sudo`/`doas`/`su -`, piping `curl`/`wget`/`base64` to shells or interpreters, `launchctl`, `csrutil`, `spctl`, `security find/dump/delete`, `tmux`, and permission-bypass flags.
110
+ - Sensitive paths: reading or writing credential files (`.env`, `.ssh/`, `.aws/`, `.gnupg/`, `.netrc`, `.npmrc`, `.pypirc`, private keys, Keychains), writing outside the project directory (including Codex patches), and modifying AgentBridge or `.claude/settings` / `hooks.json`.
111
+ - Sessions opened inside AgentBridge's own code or data folder are never bridged.
112
+ - **PIN unlock**: set only at the Mac (`agb pin`, stored as an `scrypt` hash in `~/.agentbridge/run/pin.json`). `/unlock` deletes your PIN message from Telegram immediately, pauses 15 minutes after 3 wrong tries, and disables unlock after 6 wrong tries until `agb pin` is run again. Every action executed under unlock is reported to Telegram. Even while unlocked, four categories **always stay blocked**:
113
+ - Touching AgentBridge itself
114
+ - Modifying bridge or Claude settings (`.claude/settings`, `hooks.json`)
115
+ - Permission-bypass flags (`dangerously-skip-permissions`, `bypassPermissions`)
116
+ - Running `tmux` from inside a bridged session
117
+ - **Token storage**: the Telegram bot token is stored in the macOS Keychain via `security -i` (stdin, avoiding process-list exposure), falling back to `0600` `~/.agentbridge/config.env` only if Keychain is unavailable.
118
+ - **Transport encryption**: Telegram bot chats are **not** end-to-end encrypted; messages pass through Telegram's servers. Outbound text runs best-effort secret redaction (API keys, JWTs, bearer tokens, env assignments, long hex/random blobs).
119
+ - **Data folder**: all mutable state lives in `~/.agentbridge` (`0700`, overridable via `AGENTBRIDGE_HOME`): `config.env`, `agentbridge.db`, `run/` (hook token, pairing code, PIN hash, turn markers, inbox, rendered hooks), `logs/bridge.log`, and optional `models/`.
120
+
121
+ ## Uninstall
122
+
123
+ ```sh
124
+ agb service uninstall
125
+ agb agy-setup --remove # if agy was bridged
126
+ agb voice-setup --remove # if voice notes were enabled (optional: brew uninstall whisper-cpp ffmpeg)
127
+ agb token --clear
128
+ brew uninstall agentbridge
129
+ rm -rf ~/.agentbridge
130
+ ```
131
+
132
+ Then remove the `# AgentBridge` alias lines from `~/.zshrc` (or `~/.bashrc`), and optionally run `brew untap rampellisaieshwar/agentbridge`.
133
+
134
+ ## Architecture
135
+
136
+ - **Bridge** (`agentbridge/bridge.py`): local FastAPI/uvicorn server bound to `127.0.0.1:8788` (`/hook`, authenticated by a per-install token in `~/.agentbridge/run/hook_token`).
137
+ - **Background loops**: inside the bridge process, async loops handle Telegram Bot API long-polling, SQLite-backed outbox retries, pinned-board edits, and `agy` screen-prompt polling.
138
+ - **Hooks** (`agentbridge/hook.py`, `agentbridge/policy.py`): `agentbridge-hook` is attached per session for Claude (`--settings`), inline TOML for Codex (`-c hooks={...}`), and via a local plugin for `agy` (inert unless `AGENTBRIDGE_SESSION` is set).
139
+ - **Hook flow**: `PreToolUse` enforces the remote block list locally before any tool runs; `PermissionRequest` and lifecycle hooks (`Stop`, `PostToolUse`, `Notification`, etc.) post to `/hook`.
140
+ - **Terminal driver** (`agentbridge/drivers/tmux.py`): wraps `tmux` (`ab-<name>` sessions) to launch/attach/kill sessions, read terminal state and modes, type prompts, handle `agy` prompts, and render the clickable status bar.
141
+ - **Service driver** (`agentbridge/drivers/launchd.py`): manages the macOS `launchd` user agent (`com.agentbridge.bridge`) running under `caffeinate -i`.
142
+ - **Platform support**: macOS only for now; Linux (`systemd --user` service driver) and Windows (ConPTY terminal + Task Scheduler service drivers) are not supported yet.
143
+
144
+ ## License
145
+
146
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,2 @@
1
+ """AgentBridge: reach agent CLI sessions on this Mac from Telegram."""
2
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()