@alexlikevibe/lark-channel-bridge 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +372 -0
- package/README.zh.md +372 -0
- package/bin/lark-channel-bridge.mjs +2 -0
- package/dist/cli.js +15073 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.js +604 -0
- package/package.json +87 -0
package/README.zh.md
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# lark-channel-bridge
|
|
2
|
+
|
|
3
|
+
把飞书 / Lark 消息和本地 Claude Code 或 Codex CLI 打通的轻量 bot。用一条命令启动,扫码绑定 PersonalAgent 应用,然后在飞书里和本机编程助手对话,让它读图、处理文件、改代码。
|
|
4
|
+
|
|
5
|
+
[English README](./README.md)
|
|
6
|
+
|
|
7
|
+
关于能实现的效果,详情可以阅读[飞书文档](https://larkcommunity.feishu.cn/docx/OaRIdFIRFoLM3xxTmKwcetHqn5e)
|
|
8
|
+
|
|
9
|
+
## 主要功能
|
|
10
|
+
|
|
11
|
+
- 在飞书私聊直接发消息,或在群里 `@bot`,把任务转给本机 Claude Code / Codex CLI。
|
|
12
|
+
- **流式卡片**:文本回复和工具调用实时更新在同一张卡片上。
|
|
13
|
+
- **COT 过程消息**:可选先发一条过程消息展示 agent 的阶段性文本和工具调用,再单独发送最终答案。
|
|
14
|
+
- **会话延续**:每个聊天、话题或文档评论有自己的会话,不会互相串。
|
|
15
|
+
- **排队与消息合并**:短时间连续发送的消息会合并处理;任务运行中收到的普通消息会排队到下一轮,`/new`、`/cd`、`/ws use`、`/stop` 这类命令可以中断当前任务。
|
|
16
|
+
- **多工作空间**:用 `/cd` 切换当前项目,用 `/ws` 保存和复用常用项目目录。
|
|
17
|
+
- **图片 / 文件**:直接发给 bot,bridge 下载到本地后交给本机 agent 处理。
|
|
18
|
+
- **卡片按钮**:`/help`、`/ws list`、`/status` 返回可点击的交互卡片。
|
|
19
|
+
|
|
20
|
+
## 前置条件
|
|
21
|
+
|
|
22
|
+
- Node.js **>= 20.12.0**
|
|
23
|
+
- 本机至少安装并登录一个 agent:
|
|
24
|
+
- Claude Code:`claude`,安装说明:https://docs.anthropic.com/en/docs/claude-code/quickstart
|
|
25
|
+
- Codex CLI:`codex`,安装说明:https://developers.openai.com/codex/cli
|
|
26
|
+
- pi:`pi`,安装说明:https://pi.dev
|
|
27
|
+
- 一个飞书 / Lark PersonalAgent 应用。首次启动的扫码向导可以帮你创建并绑定。
|
|
28
|
+
|
|
29
|
+
## 安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i -g @alexlikevibe/lark-channel-bridge
|
|
33
|
+
# 或
|
|
34
|
+
pnpm add -g @alexlikevibe/lark-channel-bridge
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 首次启动
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
lark-channel-bridge run
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
第一次运行会进入扫码向导:
|
|
44
|
+
|
|
45
|
+
1. 终端渲染二维码。
|
|
46
|
+
2. 用飞书 App 扫码。
|
|
47
|
+
3. 选择或创建 PersonalAgent 应用。
|
|
48
|
+
4. 如果终端提示,选择本次要初始化的 agent。
|
|
49
|
+
5. 成功后配置写入 `~/.lark-channel/config.json`。
|
|
50
|
+
|
|
51
|
+
没有指定项目目录也可以启动。bridge 会创建一个 profile 托管的默认工作目录;启动后在飞书里发送 `/cd <path>` 切到实际项目。
|
|
52
|
+
|
|
53
|
+
如果已经有 PersonalAgent app,可以在初始化时传 `--app-id` 跳过创建应用流程;命令会提示输入 App Secret。
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
lark-channel-bridge run --app-id cli_xxx
|
|
57
|
+
# 或直接初始化并启动后台服务
|
|
58
|
+
lark-channel-bridge start --app-id cli_xxx
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Lark 国际版应用可加 `--tenant lark`。
|
|
62
|
+
|
|
63
|
+
## 后台运行
|
|
64
|
+
|
|
65
|
+
`run` 适合首次配置和前台调试。确认 bot 能正常收发消息后,先用 `Ctrl-C` 停掉前台进程,再用系统服务常驻后台:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
lark-channel-bridge start
|
|
69
|
+
lark-channel-bridge status
|
|
70
|
+
lark-channel-bridge stop
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
服务层命令必须先全局安装,不能直接用 `npx`。daemon 的 launchd plist / systemd unit / Windows 任务会记录 bridge CLI 的路径;如果这个路径来自 npm 临时缓存,缓存清掉后 daemon 就起不来。`run` 用 `npx` 单次启动没问题。
|
|
74
|
+
|
|
75
|
+
服务层命令按 profile 注册,每个 profile 有独立服务:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
lark-channel-bridge start [--profile <name>]
|
|
79
|
+
lark-channel-bridge stop [--profile <name>]
|
|
80
|
+
lark-channel-bridge restart [--profile <name>]
|
|
81
|
+
lark-channel-bridge status [--profile <name>]
|
|
82
|
+
lark-channel-bridge unregister [--profile <name>]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
平台映射:
|
|
86
|
+
- **macOS**:launchd 用户代理 `ai.lark-channel-bridge.bot.<profile>`
|
|
87
|
+
- **Linux**:systemd 用户单元 `lark-channel-bridge.bot.<profile>.service`
|
|
88
|
+
- **Windows**:Task Scheduler 任务 `LarkChannelBridge.Bot.<profile>`,launcher 是 `.cmd`
|
|
89
|
+
|
|
90
|
+
daemon 日志在 `~/.lark-channel/profiles/<profile>/logs/daemon/`。
|
|
91
|
+
|
|
92
|
+
daemon 服务不会继承执行 `start` 时 shell 里的任意环境变量。如果后台 agent/provider 需要 API key 或代理配置,请写入 daemon env 文件:
|
|
93
|
+
|
|
94
|
+
```env
|
|
95
|
+
# ~/.lark-channel/daemon.env # 所有 profile 共享
|
|
96
|
+
# ~/.lark-channel/profiles/<profile>/daemon.env # profile 级覆盖
|
|
97
|
+
ZAI_CODING_CN_API_KEY=xxx
|
|
98
|
+
HTTPS_PROXY=http://127.0.0.1:7890
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
修改后需要重启服务。env 文件只提供凭据和环境配置,不负责选择 provider 或模型;如果同时存在多个 provider key,实际使用哪个 provider/模型仍由底层 agent CLI 和 profile 的模型偏好决定。
|
|
102
|
+
|
|
103
|
+
### 多 profile:分别运行 Claude、Codex 和 pi
|
|
104
|
+
|
|
105
|
+
默认情况下,bridge 使用当前激活的 profile;可以通过 `profile use <name>` 切换。每个 profile 会维护独立的应用凭据、会话、工作目录和日志。只有在需要同时连接多个 PersonalAgent 应用,或分别运行 Claude、Codex 和 pi 时,才需要创建多个 profile:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
lark-channel-bridge start --profile claude --agent claude
|
|
109
|
+
lark-channel-bridge start --profile codex --agent codex
|
|
110
|
+
lark-channel-bridge start --profile pi --agent pi
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
例如只重启 Codex bot:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
lark-channel-bridge restart --profile codex
|
|
117
|
+
lark-channel-bridge status --profile codex
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 命令速查
|
|
121
|
+
|
|
122
|
+
### 宿主 CLI
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
lark-channel-bridge run [--profile <name>] [--agent claude|codex|pi] [--workspace <path>] [-c <config>]
|
|
126
|
+
lark-channel-bridge migrate [--profile <name>] [--agent claude|codex|pi]
|
|
127
|
+
lark-channel-bridge ps
|
|
128
|
+
lark-channel-bridge kill <id|#>
|
|
129
|
+
lark-channel-bridge --help
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`profile use <name>` 会切换后续默认启动使用的 profile。需要同时跑 Claude / Codex 两个 bot、连接多套 PersonalAgent 应用,或做脚本化部署时,再使用这些 profile 管理命令:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
lark-channel-bridge profile create claude --agent claude
|
|
136
|
+
lark-channel-bridge profile create codex --agent codex
|
|
137
|
+
lark-channel-bridge profile create pi --agent pi
|
|
138
|
+
lark-channel-bridge profile list
|
|
139
|
+
lark-channel-bridge profile use <name>
|
|
140
|
+
lark-channel-bridge profile remove <name>
|
|
141
|
+
lark-channel-bridge profile remove <name> --purge --yes
|
|
142
|
+
lark-channel-bridge profile export <name> [--output ./profile.json] [--force]
|
|
143
|
+
lark-channel-bridge profile export <name> --include-secrets --yes
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`profile remove` 默认归档本地状态,也可以删除当前激活的 profile。若还剩其他 profile,会自动切到下一个;若这是最后一个 profile,会清空 root config,之后可以用同名重新创建。只有加 `--purge --yes` 才会永久删除。`profile export` 默认脱敏 app secret;只有加 `--include-secrets --yes` 才会导出敏感配置。
|
|
147
|
+
|
|
148
|
+
如果某个 profile 被建成了错误的 agent 类型,先 `stop` 或 `unregister --profile <name>` 清理对应后台服务,再 `profile remove <name>`,然后用正确的 `--agent` 重新创建。
|
|
149
|
+
|
|
150
|
+
### 飞书内斜杠命令
|
|
151
|
+
|
|
152
|
+
| 命令 | 作用 |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `/new`, `/reset` | 清空当前会话 |
|
|
155
|
+
| `/cd <path>` | 切换工作目录并重置会话 |
|
|
156
|
+
| `/ws list` | 列出命名工作空间 |
|
|
157
|
+
| `/ws save <name>` | 把当前工作目录保存为命名工作空间 |
|
|
158
|
+
| `/ws use <name>` | 切换到命名工作空间 |
|
|
159
|
+
| `/ws remove <name>` | 删除命名工作空间 |
|
|
160
|
+
| `/resume` | 恢复同 agent、工作目录、权限模式兼容的历史会话 |
|
|
161
|
+
| `/status` | 查看 profile、agent、工作目录、会话、lark-cli 身份和运行状态 |
|
|
162
|
+
| `/config` | 调整展示偏好、访问控制和 lark-cli 身份策略 |
|
|
163
|
+
| `/invite user @某人` | 允许用户私聊使用 bot |
|
|
164
|
+
| `/invite admin @某人` | 添加访问控制管理员 |
|
|
165
|
+
| `/invite group` | 允许当前群使用 bot |
|
|
166
|
+
| `/invite all group` | 允许 bot 所在的所有群使用 |
|
|
167
|
+
| `/remove user @某人`, `/remove admin @某人`, `/remove group` | 移除访问控制条目 |
|
|
168
|
+
| `/stop` | 停止当前 run,也可点卡片停止按钮 |
|
|
169
|
+
| `/timeout [N\|off\|default]` | 设置或清除当前会话的 idle watchdog |
|
|
170
|
+
| `/ps` | 列出本机 bridge 进程 |
|
|
171
|
+
| `/exit <id\|#>` | 停止指定 bridge 进程 |
|
|
172
|
+
| `/reconnect` | 强制 WebSocket 重连 |
|
|
173
|
+
| `/doctor [描述]` | 执行低敏诊断 |
|
|
174
|
+
| `/help` | 帮助卡片 |
|
|
175
|
+
|
|
176
|
+
私聊不需要 @。群和话题群默认必须 `@bot`;`@all` 会被忽略。支持的云文档评论里 @bot 就会触发回复。
|
|
177
|
+
|
|
178
|
+
## 回复展示与 COT
|
|
179
|
+
|
|
180
|
+
`/config` 可以调整三类展示选项:
|
|
181
|
+
|
|
182
|
+
- **消息回复方式**:`消息卡片` 流式更新最终回复;`纯文本` 在 run 完成后一次性发送。
|
|
183
|
+
- **工具调用显示**:控制最终回复卡片 / markdown 中是否展示工具块。
|
|
184
|
+
- **COT 过程消息**:`关闭` 只发送最终回复;`简略` 先用 COT 消息展示 agent 的过程文本和工具摘要;`详细` 还会展示工具参数和截断后的输出。
|
|
185
|
+
|
|
186
|
+
开启 COT 后,bridge 会把过程消息和最终答案拆成两条消息。过程消息用于追踪 agent 做了什么;最终答案仍由 agent 原始文本生成,bridge 不做启发式过滤。若 agent 把最终答案也作为普通流式文本输出,COT 过程消息中可能会出现对应片段。
|
|
187
|
+
|
|
188
|
+
## lark-cli 身份策略
|
|
189
|
+
|
|
190
|
+
每个 profile 都使用当前 profile 的 lark-cli 目录:`~/.lark-channel/profiles/<profile>/lark-cli`。agent 子进程会收到指向这个目录的 `LARKSUITE_CLI_CONFIG_DIR`,所以一个 profile 里的个人授权不会共享给另一个 profile。
|
|
191
|
+
|
|
192
|
+
默认策略是 `bot-only`:lark-cli 使用应用 / bot 身份,不访问个人资源。当用户为了日历、邮箱、云盘等个人资源完成授权后,当前 profile 可以切到 `user-default`,保留应用身份,同时允许已授权的用户身份。owner/admin 可以在 `/config` 查看或切换这个策略;`/status` 会用 `lark-cli: app` 或 `lark-cli: user-ready` 展示当前摘要。
|
|
193
|
+
|
|
194
|
+
## 工作目录
|
|
195
|
+
|
|
196
|
+
每个 profile 都可以有一个默认工作目录:`workspaces.default`。新建 profile 时可以传 `--workspace <path>` 作为初始目录;没传时 bridge 会创建一个 profile 托管的默认工作目录。
|
|
197
|
+
|
|
198
|
+
下面只是 profile 里的字段片段,不要整段覆盖 `config.json`;请改对应 profile 下的 `workspaces` 字段。
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"workspaces": {
|
|
203
|
+
"default": "/Users/me/.lark-channel-workspaces/claude/default"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
bridge 会检查所选目录存在、是目录,并且不是 `/`、Home 根、系统目录或临时目录根这类范围过大的位置。工作目录只是 agent run 的当前目录,不是文件系统 sandbox;agent 实际能访问哪些文件仍取决于本机 agent 进程及其权限模式。
|
|
209
|
+
|
|
210
|
+
## 权限模式
|
|
211
|
+
|
|
212
|
+
推荐给用户配置的是 `permissions.defaultAccess` 和 `permissions.maxAccess`。新 profile 默认两项都是 `full`,以保持 bridge 的本地工具、授权流程、文件写入等能力完整可用。如需收紧权限,可以改成 `workspace` 或 `read-only`;收紧后本地工具执行、登录 / 授权流程、文件写入等能力可能受限。
|
|
213
|
+
|
|
214
|
+
下面只是 profile 里的字段片段,不要整段覆盖 `config.json`;请改对应 profile 下的 `permissions` 字段。
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"permissions": {
|
|
219
|
+
"defaultAccess": "full",
|
|
220
|
+
"maxAccess": "full"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
模式映射:
|
|
226
|
+
|
|
227
|
+
| Bridge access | Claude permission mode | Codex mode | Pi mode |
|
|
228
|
+
|---|---|---|---|
|
|
229
|
+
| `full` | `bypassPermissions` | `danger-full-access` | 无限制 |
|
|
230
|
+
| `workspace` | `acceptEdits` | `workspace-write` | 无限制 |
|
|
231
|
+
| `read-only` | `plan` | `read-only` | `--tools read,grep,find,ls` |
|
|
232
|
+
|
|
233
|
+
pi 目前没有内置的 workspace 级沙箱:`workspace` 和 `full` 对 pi 而言行为相同(不加 `--tools` 限制)。需要更强隔离的用户应自行为 pi 做容器化 — 详见 https://pi.dev。
|
|
234
|
+
|
|
235
|
+
旧版 `sandbox` 字段仍可读取。bridge 保存 profile 后,会把该设置迁移为 canonical `permissions`。
|
|
236
|
+
|
|
237
|
+
## 数据目录
|
|
238
|
+
|
|
239
|
+
| 路径 | 内容 |
|
|
240
|
+
|---|---|
|
|
241
|
+
| `~/.lark-channel/config.json` | root config,包含 profiles 和 active profile |
|
|
242
|
+
| `~/.lark-channel/active-profile` | 最近选择的 profile |
|
|
243
|
+
| `~/.lark-channel/profiles/<profile>/sessions.json` | 会话状态 |
|
|
244
|
+
| `~/.lark-channel/profiles/<profile>/sessions.json.catalog.json` | agent-aware 会话索引 |
|
|
245
|
+
| `~/.lark-channel/profiles/<profile>/workspaces.json` | 当前和命名工作空间绑定 |
|
|
246
|
+
| `~/.lark-channel/profiles/<profile>/secrets.enc` | profile 本地加密 secret |
|
|
247
|
+
| `~/.lark-channel/profiles/<profile>/lark-cli/` | 当前 profile 的 lark-cli 目录 |
|
|
248
|
+
| `~/.lark-channel/profiles/<profile>/media/` | 附件缓存 |
|
|
249
|
+
| `~/.lark-channel/profiles/<profile>/logs/` | 结构化运行日志 |
|
|
250
|
+
| `~/.lark-channel/registry/processes.json` | 本机进程注册表 |
|
|
251
|
+
| `~/.lark-channel/registry/locks/` | profile lock 和 app lock |
|
|
252
|
+
|
|
253
|
+
设置 `LARK_CHANNEL_HOME=/path/to/state` 可以迁移整棵本地状态目录。`LARK_CHANNEL_LOG_DAYS` 可以调整日志保留天数。
|
|
254
|
+
|
|
255
|
+
## 访问控制
|
|
256
|
+
|
|
257
|
+
**聊天访问默认是私有的:开箱即用时,只有"你"能在私聊和群聊里用这个 bot。** 这里的"你" = 创建 / 拥有这个飞书应用的人(也就是扫码把 bot 建起来的那位)。bot 会自动从飞书查出谁是应用 owner,所以**一个人用聊天入口完全不用配置**——你私聊它、在任意群里 @它都正常工作,其他人的聊天消息会被静默忽略(bot 不会回"你没权限",免得暴露自己的存在)。云文档评论按文档权限生效,见下文。
|
|
258
|
+
|
|
259
|
+
想让别的同事或某些群也能用,就把他们加进下面三类名单:
|
|
260
|
+
|
|
261
|
+
| 名单 | 控制谁 | 加入 | 移除 |
|
|
262
|
+
|------|--------|------|------|
|
|
263
|
+
| **允许私聊的用户** | 谁可以私聊 bot | `/invite user @某人` | `/remove user @某人` |
|
|
264
|
+
| **响应的群** | bot 在哪些群里对**群内所有人**响应 | `/invite group`(当前群)/ `/invite all group`(bot 所在的全部群) | `/remove group`(当前群) |
|
|
265
|
+
| **管理员** | 谁能改设置、并能在任意群用 bot | `/invite admin @某人` | `/remove admin @某人` |
|
|
266
|
+
|
|
267
|
+
> `/invite`、`/remove` 这些命令只有**你(创建者)和管理员**能发。命令里 @ 的是**对方**(不是 @ bot),bot 会自动把 @ 解析成对应的人,你不用手动去找 ID。
|
|
268
|
+
|
|
269
|
+
### 两种"畅通无阻"的身份
|
|
270
|
+
|
|
271
|
+
- **你(创建者)**:不受任何名单限制——私聊、任意群、所有命令都能用,而且**永远锁不死自己**:哪怕名单配乱了,回到 bot 私聊发 `/config` 总能进来。在飞书后台把应用 owner 转给别人后,bot 也会自动跟着切换。
|
|
272
|
+
- **管理员**:能私聊、能用 `/config` 等管理命令,而且**不受"响应的群"名单限制**——无论群在不在名单里,bot 都会回他们。适合给一起维护 bot 的同事。
|
|
273
|
+
|
|
274
|
+
### 几种常见配置
|
|
275
|
+
|
|
276
|
+
- **只给自己用** → 什么都不用做,默认就是。
|
|
277
|
+
- **让某个同事能私聊 bot** → `/invite user @他`
|
|
278
|
+
- **让某个工作群里所有人都能用** → 在那个群里发 `/invite group`
|
|
279
|
+
- **第一次配,想把 bot 已经在的群一次性全开放** → 发 `/invite all group` 一键拉取 bot 所在的全部群加入名单,之后再用 `/remove group` 删掉不想要的
|
|
280
|
+
- **再拉个人一起当管理员** → `/invite admin @他`
|
|
281
|
+
|
|
282
|
+
### 还需要知道的
|
|
283
|
+
|
|
284
|
+
- 改完**下一条消息**就生效,不用重启。
|
|
285
|
+
- **群里默认要先 @bot 才会回**(私聊不用 @)。这是另一个独立开关(`/config` →"群里需要 @ bot"),和上面的名单是两回事。
|
|
286
|
+
- 陌生人发消息一律静默丢弃,不会有任何回复。唯一的例外:有人在一个还没开放的群里 @bot,bot 会回一句友好提示,告诉他可以让管理员发 `/invite group` 开放这个群。
|
|
287
|
+
- 云文档评论按文档权限生效:能在支持的文档里评论并 @bot 的人可以触发回复。
|
|
288
|
+
|
|
289
|
+
### 高级:直接改配置文件
|
|
290
|
+
|
|
291
|
+
不想在飞书里点的话,`/invite`、`/config` 背后写的是 `~/.lark-channel/config.json` 中对应 profile 的 `access` 字段。空白名单表示这个名单没人,不表示所有人都能用。下面只是 profile 里的字段片段,不要整段覆盖 `config.json`:
|
|
292
|
+
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"schemaVersion": 2,
|
|
296
|
+
"profiles": {
|
|
297
|
+
"claude": {
|
|
298
|
+
"agentKind": "claude",
|
|
299
|
+
"access": {
|
|
300
|
+
"allowedUsers": ["ou_xxxxxxxxxxxxx"],
|
|
301
|
+
"allowedChats": ["oc_xxxxxxxxxxxxx"],
|
|
302
|
+
"admins": ["ou_xxxxxxxxxxxxx"],
|
|
303
|
+
"requireMentionInGroup": true
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`allowedUsers` / `admins` 填用户 `open_id`,`allowedChats` 填群 `chat_id`。手动找 ID 最简单的办法:让对方给 bot 发条消息(群里就 @ 它一下),然后看当前 profile 的日志:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
grep '"event":"enter"' ~/.lark-channel/profiles/<profile>/logs/bridge-$(date +%Y%m%d).jsonl | tail -5
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
每行都带 `chatId`(群 / 私聊 ID)和 `senderId`(用户 `open_id`)。手改完后**重启 bridge**,或在允许的 admin 上下文里发 `/reconnect` 让它生效。日常调整还是 `/invite` / `/config` 更省事,直接改文件主要用于部署脚本预填。
|
|
317
|
+
|
|
318
|
+
## 云文档评论
|
|
319
|
+
|
|
320
|
+
云文档评论不再需要单独绑定工作目录或维护文档白名单。支持的文档评论里 @bot 后,bridge 会在同一个评论线程里回复。评论运行复用文档级 session key;没有记录过文档 cwd 时回退到用户 home 目录。
|
|
321
|
+
|
|
322
|
+
## 常见问题
|
|
323
|
+
|
|
324
|
+
**bot 没反应 / agent 不回复**:通常是本机 `claude`、`codex` 或 `pi` CLI 没登录,或者当前会话指向了不存在的工作目录。发 `/status` 看当前状态;`/new` 重开会话往往就好。
|
|
325
|
+
|
|
326
|
+
**agent 子进程假死(卡片停在最后一帧不动)**:支持 idle 探活。agent 一段时间没输出就会被 SIGTERM kill,卡片末尾会标出自动终止原因。默认关闭。开启方式:`/config` 设全局值(分钟),或 `/timeout 10` 只对当前会话生效;`/timeout off` 关掉当前会话的探活;`/timeout default` 清掉会话覆盖,回退到全局设置。
|
|
327
|
+
|
|
328
|
+
**图片发过去 agent 说看不到**:升级到最新版,0.1.0 之前的版本有文件名去重 bug。
|
|
329
|
+
|
|
330
|
+
## 测试与 CI
|
|
331
|
+
|
|
332
|
+
本地检查:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
pnpm test
|
|
336
|
+
pnpm typecheck
|
|
337
|
+
pnpm build
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
`pnpm test` 包含 unit、integration 和 process-level adapter 测试。CI 在 macOS、Ubuntu、Windows 上执行 `pnpm install --frozen-lockfile`、`pnpm test`、`pnpm typecheck` 和 `pnpm build`。
|
|
341
|
+
|
|
342
|
+
## 可选:遥测(Telemetry)
|
|
343
|
+
|
|
344
|
+
默认情况下 bridge **不上报任何数据**:没有指标、没有日志离开你的机器,也不引入任何遥测依赖。下面这个钩子在你主动开启前完全是空操作。
|
|
345
|
+
|
|
346
|
+
想接自己的监控时,用环境变量指向一个 default export(或导出 `createAdapter`)`AdapterFactory` 的模块:
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
LARK_CHANNEL_TELEMETRY_MODULE=your-telemetry-package lark-channel-bridge start
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
该模块会收到每一条 `log.*` 事件,以及错误 / 指标钩子,转发到任何你想要的地方。接口从包根导出:
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import type { AdapterFactory, TelemetryAdapter, TelemetryEvent } from 'lark-channel-bridge';
|
|
356
|
+
|
|
357
|
+
const createAdapter: AdapterFactory = (meta) => ({
|
|
358
|
+
emit(event) {/* 上报事件 */},
|
|
359
|
+
recordError(err, ctx) {/* 上报异常 */},
|
|
360
|
+
recordMetric(name, value, tags) {/* 上报指标 */},
|
|
361
|
+
flush(timeoutMs) {/* 冲刷缓冲事件 */},
|
|
362
|
+
});
|
|
363
|
+
export default createAdapter;
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
模块不存在、工厂函数不合法、或者 adapter 抛错,都会降级为空操作——遥测永远不会阻止 bridge 启动,也不会打断日志。
|
|
367
|
+
|
|
368
|
+
## 许可
|
|
369
|
+
|
|
370
|
+
[MIT](./LICENSE)
|
|
371
|
+
|
|
372
|
+
<img src="./assets/feedback-group-qr.png" alt="飞书反馈群二维码" width="360">
|