# Im Agy Codex Bridge

> Setup, configure, verify, run as a background service, and troubleshoot the multi-channel Feishu/Lark and Telegram dual-bot bridge connecting local Antigravity

- Skill: `taobinxian/im-agy-codex-bridge` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx get-skill add taobinxian/im-agy-codex-bridge`
- Raw SKILL.md: https://api.skillmd.com/api/skills/taobinxian/im-agy-codex-bridge/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: taobinxian (https://skillmd.com/u/taobinxian)
- Updated: 2026-12-02
- Page: https://skillmd.com/skills/taobinxian/im-agy-codex-bridge

---

---
name: im-agy-codex-bridge
description: Setup, configure, verify, run as a background service, and troubleshoot the multi-channel Feishu/Lark and Telegram dual-bot bridge connecting local Antigravity (agy) and OpenAI Codex (acpx). Use when the user asks to connect Antigravity and Codex to Feishu/Lark or Telegram, verify dual-bot credentials, create a Feishu collaboration group, install or restart the launchd/systemd bridge daemon, configure TELEGRAM_PROXY_URL, file-delivery blocklists or timeouts, or debug WebSocket/polling, @mention relay, or permission errors.
---

# IM Antigravity × Codex Bridge

Run a local dual-bot bridge service that connects **Antigravity (`agy`)** and **Codex (`acpx codex`)** into **Feishu/Lark** (WebSocket) and/or **Telegram** (long polling + optional HTTP proxy) with live progress streaming, `[SEND_FILE]` / `[SEND_IMAGE]` uploads, and bounded bot-to-bot `@` relay.

## 1. Locate or Install the Bridge

- **Installed as an Antigravity plugin**: the runtime root sits two levels above this skill (`../..` from `SKILL.md`).
- **Prebuilt Release bundle** (no `npm install` or `tsc` needed): download `im-agy-codex-bridge-latest.zip` from GitHub Releases and run `bash install.sh` (or `npm run setup` inside the extracted folder).
- **One-command remote install**:
  ```bash
  curl -fsSL https://raw.githubusercontent.com/taobinxian/im-agy-codex-bridge/main/install.sh | bash
  ```
- Run all `npm` and `scripts/*` commands from the installed plugin/repo root.

## 2. Prerequisites

Verify local Node (`>=20`) and agent CLIs:

```bash
node -v
command -v agy
command -v acpx
```

If `agy` or `acpx` is outside default `PATH`, set `AGY_BIN` / `ACPX_BIN` in `.env` (auto-detection also checks `/opt/homebrew/bin`, `/opt/homebrew/opt/node/bin`, and `/usr/local/bin`).

## 3. First-Time Setup & Verification

Follow this order strictly because Feishu rejects saving Long Connection mode unless an active WebSocket client is already connected:

1. **If cloned from source without prebuilt `dist/`**, build once:
   ```bash
   npm install && npm run build
   ```
   *(Skip this step if installed from a Release zip/tarball or `install.sh`.)*
2. **Configure `.env` and verify bot tokens**:
   Run the interactive wizard (writes `.env` at mode `600`, preserves existing keys, and checks both bots via Feishu API):
   ```bash
   npm run setup
   ```
   Or copy `.env.example` to `.env`, fill `AGY_FEISHU_APP_ID`, `AGY_FEISHU_APP_SECRET`, `CODEX_FEISHU_APP_ID`, `CODEX_FEISHU_APP_SECRET`, and run `npm run check-bots`. See [references/feishu-setup.md](references/feishu-setup.md) for app creation and batch permission JSON.
3. **Start the WebSocket bridge before saving Feishu Event Subscription**:
   ```bash
   npm start
   ```
   Keep it running while enabling **Long Connection** + `im.message.receive_v1` in both Feishu apps, then publish versions for both apps.
4. **Create the collaboration group**:
   ```bash
   npm run create-group
   ```
   Copy the printed `chat_id` into `ALLOWED_CHAT_IDS` in `.env`, and lock `ALLOWED_USER_UNION_IDS` to authorized `on_xxx` union IDs (inspect inbound logs after sending a test message if unknown).

## 4. Background Daemon Management

### macOS (`launchd`)

Install/reload (automatically rebuilds if `src/` + `tsc` are present, or runs prebuilt `dist/index.js` directly):

```bash
bash scripts/install-launchd.sh
```

Check status and logs:

```bash
launchctl list | grep im-agy-codex-bridge
tail -n 50 data/logs/bridge.out.log
tail -n 50 data/logs/bridge.err.log
```

Uninstall:

```bash
bash scripts/install-launchd.sh --uninstall
```

### Linux (`systemd --user`)

Adapt `scripts/im-agy-codex-bridge.service.example` to `~/.config/systemd/user/im-agy-codex-bridge.service`, then run `systemctl --user daemon-reload && systemctl --user enable --now im-agy-codex-bridge`.

## 5. In-Chat Operations & Security

- **Slash commands** (executed once across both bots via shared `message_id` dedup):
  - `/help` — Show collaboration guide and commands
  - `/status` — Show current `cwd`, `agyConversationId`, Codex session name, and queue counts
  - `/projects` — List project roots discovered in `~/.codex/state_5.sqlite`
  - `/cwd <index-or-path>` — Switch working directory and start a fresh Codex session epoch
  - `/reset` — Clear Antigravity conversation ID, recent context, and rotate Codex session epoch
  - `/stop` — Abort running tasks for both bots in the current chat/thread
- **File delivery security**: `[SEND_FILE:/abs/path]` and `[SEND_IMAGE:/abs/path]` automatically block `.env`, `.ssh`, `.gnupg`, `.aws`, `.npmrc`, `.pypirc`, `id_rsa`/`id_ed25519`, `clientSecret`, and any custom `BLOCKED_PATH_PATTERNS` configured in `.env`. Never print `.env` contents when inspecting config.

## 6. Troubleshooting

- **Feishu refuses to save Long Connection**: `npm start` (or `launchd`) is not running yet, or credentials in `.env` are wrong. Run `npm run check-bots` first.
- **`code=99991672` on file upload**: Missing `im:resource` scope or app version was not republished after adding permissions.
- **Error `230002` in DM (`p2p`)**: Only group chats support cross-bot `@` relay; `p2p` disables relay automatically because the other bot is not a member of the DM.
- **Long tasks cut off**: Default `TASK_TIMEOUT_SEC=0` disables wall-clock limits and relies on `IDLE_TIMEOUT_SEC=900` (kills only after 15 minutes of zero stdout/stderr activity).
- **Detailed guides**:
  - Feishu Open Platform permissions, events, and group setup: [references/feishu-setup.md](references/feishu-setup.md)
  - Telegram `@BotFather` setup, privacy mode, and `TELEGRAM_PROXY_URL`: [references/telegram-setup.md](references/telegram-setup.md)
  - Full `.env` schema and daemon details: [references/configuration.md](references/configuration.md)

