Metadata-Version: 2.5
Name: pigeonai
Version: 1.0.1
Summary: Send tasks from Slack to Claude Code agent teams running in tmux, and get results back.
Author: PigeonAI contributors
License-Expression: MIT
License-File: LICENSE
Keywords: agents,claude-code,slack,tmux
Requires-Python: >=3.9
Requires-Dist: python-dotenv>=1.0
Requires-Dist: slack-bolt>=1.18
Requires-Dist: tomli>=2.0; python_version < '3.11'
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

<p align="center">
  <img src="docs/logo.svg" width="128" alt="PigeonAI logo">
</p>

<h1 align="center">PigeonAI</h1>

Send tasks from Slack to [Claude Code](https://claude.com/claude-code) agent teams running in tmux, and get their answers back as Slack DMs.

```mermaid
flowchart LR
    U(["👤 You on Slack"])

    subgraph A["Server A"]
        B["pigeonai bot"]
        WA["pigeonai watch backend"]
        L["backend team-lead<br/>(tmux pane)"]
    end

    subgraph R["Server B"]
        WB["pigeonai watch research"]
        T["research team-lead<br/>(tmux pane)"]
    end

    N["pigeonai notify<br/>(Stop hook)"]

    U -- "backend: fix the test" --> B
    U -- "research: summarize" --> B
    B --> WA
    B --> WB
    WA -- "tmux send-keys" --> L
    WB -- "tmux send-keys" --> T
    L -. "answer done" .-> N
    T -. "answer done" .-> N
    N -. "✅ DM with result" .-> U
```

Solid arrows carry commands. Dotted arrows carry results back.

- The **bot** receives Slack messages and drops each one into `inbox/<team>/` in a directory all servers share.
- A **watcher** on each server types the messages into the tmux panes of the teams running there.
- Only one Slack user (`ALLOWED_USER`) can send commands.

## Install

```bash
pip install pigeonai          # or: uv pip install pigeonai
```

From source: `pip install -e .`

## 1. Create the Slack app

At https://api.slack.com/apps (in the browser, not the Slack client):

1. **Create an App** → name it (e.g. `pigeonai`) → pick your workspace.
2. **Socket Mode**: on. **App-Level Token** with scope `connections:write` → this is `SLACK_APP_TOKEN` (`xapp-...`).
3. **OAuth & Permissions → Bot scopes**: `chat:write`, `app_mentions:read`, `im:history`. Leave user scopes empty.
4. **Event Subscriptions → Bot events**: `app_mention`, `message.im`.
5. **App Home**: enable **Messages Tab** and tick *Allow users to send Slash commands and messages*.
6. **Install to Workspace** → copy the **Bot User OAuth Token** → `SLACK_BOT_TOKEN` (`xoxb-...`).
7. Your **Member ID**: Slack → your avatar → Profile → ⋮ → *Copy member ID* (`U0...`) → `ALLOWED_USER`.

Keep token rotation off. Never share the tokens.

## 2. Configure

Pick a home directory that every server can see, then:

```bash
export PIGEONAI_HOME=/data/shared/pigeonai   # or pass --home to every command
pigeonai init                                # creates .env, pigeonai.toml, inbox/
```

Fill in `.env` (created with mode `600`):

```
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
ALLOWED_USER=U0...
```

List your teams in `pigeonai.toml`, one line each, wherever they run:

```toml
[teams]
backend = "agents:0.0"      # tmux "session:window.pane"
research = "research:0.0"
```

Find pane names with `tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index} #{pane_current_command}'`.

Test the token: `pigeonai check` → `ok: connected as ...`.

## 3. Run

| Where | Command | Notes |
| --- | --- | --- |
| One server only | `pigeonai bot` | Run **exactly one** bot. Two bots on the same token split messages randomly. |
| Every server with teams | `pigeonai watch backend` | List the teams whose pane is on that server, e.g. `pigeonai watch backend frontend`. |

Run both inside tmux so they keep running.

## 4. Send results back to Slack

Install the Stop hook once per team, on the team's server:

```bash
pigeonai hook /path/to/team-dir
```

Then restart that team-lead (`/exit`, `claude --continue`). Each finished answer now arrives as a Slack DM.

Optional test: `echo '{"cwd":"/tmp/test","last_assistant_message":"hi"}' | pigeonai notify` should DM you *✅ test*.

## Usage

DM the bot (or @mention it): `backend: summarize today's progress`.
The bot replies *📨 Sent to backend*; when the team-lead finishes, you get *✅ backend* with its answer.

### Adding a team

1. Add `name = "session:window.pane"` under `[teams]` and restart the bot.
2. Add the name to `pigeonai watch` on the server where the team runs.
3. Run `pigeonai hook <team-dir>` on that server.

A new server only needs its own virtualenv with PigeonAI installed and access to the shared directory.

### Servers without the shared directory

If a server can't mount the shared directory (no NFS, no SSH), its teams can receive messages through a private Slack channel instead. The server only needs internet access.

1. In the Slack app, add the bot scope `groups:history` and reinstall the app.
2. Create a private channel (e.g. `#pigeonai-relay`), run `/invite @pigeonai` there, and copy its channel ID (channel name → *About* → bottom).
3. In `pigeonai.toml`, list those teams under `[relay]` too, then restart the bot:

   ```toml
   [teams]
   backend = "agents:0.0"
   cloud = "cloud:0.0"

   [relay]
   channel = "C0123456789"
   teams = ["cloud"]
   ```

4. On the new server: copy `.env` and `pigeonai.toml` into a local folder, then run `pigeonai watch cloud --home <that folder>` and `pigeonai hook <team-dir> --home <that folder>`.

The watcher only delivers posts made by the bot itself and deletes each one after delivery.

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| `Missing ALLOWED_USER in .env` | Add your Member ID to `.env`. |
| Bot lists the wrong teams | Old code or two bots running. Stop extra bots, restart `pigeonai bot`. |
| No ✅ message comes back | Hook not loaded: `/hooks` says "no hooks yet" → `/exit`, `claude --continue`. Side questions (`/btw`) don't fire Stop. |
| Bot replies 📨 but the team gets nothing | The watcher on that server stopped, or the team isn't in its `pigeonai watch` list. |
| Text appears in Claude's box but isn't submitted | Enter arrived too fast; raise `delay` in `pigeonai/tmux.py`. |
| Slack says you can't message the app | Enable the Messages Tab (step 1.5). |
| `check` times out | The server can't reach Slack; enable your proxy. |
| `python: No such file or directory` after a restart | The virtualenv points to a Python that's gone (e.g. under a wiped `/root`). Recreate it, reinstall, and rerun `pigeonai hook`. |

## Development

```bash
pip install -e '.[dev]' && pytest
```

## License

MIT
