| 1 | # Feishu / Lark Bridge |
| 2 | |
| 3 | This bridge lets a Feishu or Lark chat control a local `codewhale serve --http` |
| 4 | runtime from a phone. It uses the official Lark/Feishu Node SDK long-connection |
| 5 | mode, so the first version does not need a public webhook URL. |
| 6 | |
| 7 | Security model: |
| 8 | |
| 9 | - `codewhale serve --http` stays bound to `127.0.0.1`. |
| 10 | - `/v1/*` runtime calls use `CODEWHALE_RUNTIME_TOKEN`. |
| 11 | - Feishu/Lark chats must be allowlisted in `CODEWHALE_CHAT_ALLOWLIST` unless |
| 12 | `CODEWHALE_ALLOW_UNLISTED=true` |
| 13 | is set for first pairing. |
| 14 | - Direct messages are the intended MVP control surface. Group chat control is |
| 15 | disabled unless `FEISHU_ALLOW_GROUPS=true`. |
| 16 | - Tool approvals are text commands: `/allow <approval_id>` or `/deny <approval_id>`. |
| 17 | - Feishu/Lark only sees the prompts, status, thread summaries, and approval |
| 18 | messages the bridge sends. The workspace, shell, and runtime HTTP listener |
| 19 | stay local behind the Codewhale runtime token. |
| 20 | |
| 21 | ## Setup |
| 22 | |
| 23 | ```bash |
| 24 | cd /opt/codewhale/feishu-bridge |
| 25 | npm install --omit=dev |
| 26 | cp .env.example /etc/codewhale/feishu-bridge.env |
| 27 | sudoedit /etc/codewhale/feishu-bridge.env |
| 28 | node src/index.mjs |
| 29 | ``` |
| 30 | |
| 31 | Validate the env files before starting the service: |
| 32 | |
| 33 | ```bash |
| 34 | npm run validate:config -- \ |
| 35 | --env /etc/codewhale/feishu-bridge.env \ |
| 36 | --runtime-env /etc/codewhale/runtime.env \ |
| 37 | --workspace-root /opt/whalebro \ |
| 38 | --check-filesystem |
| 39 | ``` |
| 40 | |
| 41 | For first pairing, temporarily set `CODEWHALE_ALLOW_UNLISTED=true`, send the |
| 42 | bot `/status`, copy the returned `chat_id`, `open_id`, or `union_id` into |
| 43 | `CODEWHALE_CHAT_ALLOWLIST`, then turn `CODEWHALE_ALLOW_UNLISTED=false`. |
| 44 | |
| 45 | For a Tencent Lighthouse deployment, use: |
| 46 | |
| 47 | ```bash |
| 48 | sudo systemctl enable --now codewhale-runtime codewhale-feishu-bridge |
| 49 | sudo journalctl -u codewhale-feishu-bridge -f |
| 50 | ``` |
| 51 | |
| 52 | ## Commands |
| 53 | |
| 54 | - `/status` |
| 55 | - `/threads` |
| 56 | - `/new` |
| 57 | - `/resume <thread_id>` |
| 58 | - `/model <name|default>` |
| 59 | - `/interrupt` |
| 60 | - `/compact` |
| 61 | - `/allow <approval_id> [remember]` |
| 62 | - `/deny <approval_id>` |
| 63 | |
| 64 | Anything else is sent as a prompt. If group control is explicitly enabled, |
| 65 | messages should start with the group prefix, `/ds` unless `FEISHU_GROUP_PREFIX` |
| 66 | sets another, for example: |
| 67 | |
| 68 | ```text |
| 69 | /ds check git status and tell me what is dirty |
| 70 | ``` |
| 71 | |
| 72 | |
| 73 | ## Thread ownership |
| 74 | |
| 75 | A thread belongs to the chat that created it. The bridge records the owner in |
| 76 | the thread map when it creates a thread. `/threads` lists only the threads this |
| 77 | chat created, and `/resume` accepts only an ID this chat created. Any other ID, |
| 78 | including a thread started from the desktop app, the TUI or another chat, gets |
| 79 | one fixed reply and is never sent to the Runtime. |
| 80 | |
| 81 | When an existing thread map is first loaded, each chat keeps only the thread it |
| 82 | is bound to, and only after the bridge asks the Runtime once whether that thread |
| 83 | was started by this bridge in the configured workspace. A thread started from |
| 84 | the desktop app, the TUI or another client is dropped from the chat, and so is a |
| 85 | thread that several chats point at. Those chats send `/new` to start a new |
| 86 | thread. If the Runtime cannot be reached at start, the bridge retries every 30 |
| 87 | seconds and meanwhile gives the fixed reply. An existing thread map records only |
| 88 | the thread each chat is bound to, so threads a chat created earlier and has |
| 89 | since left with `/new` are no longer listed or resumable. Review the thread map |
| 90 | after upgrading. |
| 91 | |
| 92 | ## Restart access checks |
| 93 | |
| 94 | Recovered deliveries require a saved, previously admitted sender identity that |
| 95 | still matches the current allowlist and group policy. Removing access and |
| 96 | restarting the bridge also stops recovery messages to that chat. Legacy state |
| 97 | without this identity stays detached; it does not cancel the runtime turn. |
| 98 | Use an authorized chat to inspect or interrupt that turn. A fresh admitted |
| 99 | message records identity for subsequent restart recovery. Keep allow-unlisted |
| 100 | mode off when operating with private workspace or runtime data. |
| 101 |