@colinagent/hulala-bot 0.3.1 → 0.3.3

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/README.md CHANGED
@@ -1,121 +1,200 @@
1
1
  # hulala-bot
2
2
 
3
- 把这个机器上的 DeepSeek Harness agent 接到 **Telegram** 和 **飞书 / Lark** 上。手机发一句话,本机的 Host 执行,回复流式回到同一个对话;`/cwd` 切换这个对话挂载哪个会话——和 TUI 里切换会话是同一件事。
3
+ Put the DeepSeek Harness agent running on this machine on **Telegram** and **Feishu / Lark**. Send one sentence from your phone, the local Host runs it, and the answer streams back into the same conversation; `/cwd` changes which session that conversation is mounted to — the same thing switching sessions in the TUI does.
4
4
 
5
- DSH 原生和呼啦啦都用同一种方式接:**装成 Host 插件**,进 profile,随 Host 起落。
5
+ Native DSH and Hulala attach the same way: **install it as a Host plugin**, put it in a profile, and it lives and dies with the Host. This file is also the npm page.
6
6
 
7
- ## 它是什么
7
+ ---
8
8
 
9
- **一个 Host 插件**,改不到 DSH 一行代码。它跑在 Host 进程里,直接调宿主服务:
9
+ ## Let an AI set it up
10
+
11
+ This file is written to be an AI's instruction sheet: commands, configuration fields, expected output and exact error strings are all here. Send this to your assistant (Claude Code, Cursor, ChatGPT — anything that can run commands):
12
+
13
+ ```text
14
+ Set up hulala-bot for me (a plugin that connects Telegram / Feishu to the local
15
+ DeepSeek Harness). First read https://github.com/colinagent/hulala-bot in full,
16
+ then work through it in order:
17
+
18
+ 1. Check the environment: node -v (>=22.6), pnpm -v, hulala --version
19
+ 2. Install the plugin as described in "Install" (hulala install bot on Hulala;
20
+ hulala plugin if that command does not exist yet)
21
+ 3. Write config.json as described in "Configure". Credentials go into the OS
22
+ keychain only — never ask me to paste a token into the chat, never write one
23
+ into config.json
24
+ 4. Restart the Host
25
+ 5. Walk the verification checklist and paste the real output of every step
26
+ 6. If a step fails, match the exact text against "Troubleshooting". Do not guess.
27
+
28
+ Rules: invent no commands, config fields, scopes or events beyond this README;
29
+ stop and ask me when something is missing.
30
+ ```
31
+
32
+ The three rules the README backs up:
33
+
34
+ 1. **Credentials live in the keychain.** The config file only holds `tokenRef` / `appSecretRef` (`<service>/<account>`).
35
+ 2. **The allowlist cannot be empty.** The bot refuses to start without one; it is not a step that can be skipped.
36
+ 3. **Restart the Host after any config change.** The plugin reads its config at startup; there is no hot reload.
37
+
38
+ ---
39
+
40
+ ## What it is
41
+
42
+ **One Host plugin** that patches no line of DSH. It runs inside the Host process and calls host services directly:
10
43
 
11
44
  ```
12
- ctx.sessionController.list / create / prompt / follow → 会话与流式
13
- ctx.workspaceController.create → 工作目录
14
- ctx.on('approval/request', (req, next) => …) → 审批
45
+ ctx.sessionController.list / create / prompt / follow → sessions and streaming
46
+ ctx.workspaceController.create → working directory
47
+ ctx.on('approval/request', (req, next) => …) → approvals
15
48
  ```
16
49
 
17
- 没有端口、token、cookie、WebSocket(飞书那条长连接是飞书自己的事件通道,不是本机服务):插件就在 Host 里,`/cwd`、流式回复、审批都不需要跨进程通信。会话历史、cwd、模型、权限以 Host 为真源;这里只保存「哪个对话挂了哪个会话」。
50
+ No port, no token exchange, no cookie, no local WebSocket (the Feishu long connection is Feishu's own event channel, not a server on this machine). Sessions, history, cwd, models and permissions stay the Host's; this plugin stores only which conversation is mounted to which session.
18
51
 
19
- **一条代码,两个渠道**:`src/channel.ts` 是唯一的渠道契约,Telegram 和飞书各自实现它(id 形状、markdown 方言、流式方式、按钮回调都不同),`src/bridge.ts` 里的会话逻辑两边共用。两个渠道可以同时开,各自维护允许名单和会话挂载;Telegram 的对话和飞书的对话是两个独立会话,不合并身份。
52
+ **One code path, two channels**: `src/channel.ts` is the channel contract, `src/telegram/` and `src/lark/` implement it, and the session logic in `src/bridge.ts` is shared. Both channels can run at once, each with its own allowlist and mount table; a Telegram conversation and a Feishu conversation are separate sessions, with no identity merging.
20
53
 
21
- **多端同时在线是正常的**:TUI 和手机可以挂同一个会话,两边看到同一段历史。审批由 Host 内应答;如果两端都开着,先答的生效,另一端收到「已在其他端处理」。
54
+ ---
22
55
 
23
- ## 安装
56
+ ## Install
24
57
 
25
- 包是 `@colinagent/hulala-bot`,两种 Host 装的是同一个。
58
+ Check the environment first:
26
59
 
27
- ### 呼啦啦(一条命令)
60
+ ```sh
61
+ node -v # >= 22.6
62
+ pnpm -v # the install goes through pnpm; install it if missing
63
+ hulala --version
64
+ ```
65
+
66
+ ### Hulala
28
67
 
29
68
  ```sh
30
69
  hulala install bot
31
- # 等价于:hulala plugin --profile tui add @colinagent/hulala-bot
32
- hulala plugin --profile tui exec hulala-bot --init
33
- # 重启 Host
70
+ # On an older Hulala without that command, the equivalent is:
71
+ hulala plugin --profile tui add @colinagent/hulala-bot
34
72
  ```
35
73
 
36
- ### DSH(Web / Desktop / TUI)
74
+ `hulala install bot` only fills in the profile name (`tui`) and the package name; the install still runs through DSH's `runPluginCommand`.
75
+
76
+ ### DSH (Web / Desktop / TUI)
37
77
 
38
78
  ```sh
39
79
  dsh plugin --profile tui add @colinagent/hulala-bot
40
- dsh plugin --profile tui exec hulala-bot --init
41
- # 重启 Host
42
80
  ```
43
81
 
44
- `--init` 只写允许名单、`defaultCwd` 和凭据在钥匙串里的**引用**,不写 token / app secret;允许名单为空时拒绝写入——没有它,任何人都能驱动 agent。
82
+ **Expected output**: a final `profile tui: @deepseek-ai/dsh-base, @colinagent/hulala-bot` and `Restart the Host for the change to take effect.`
45
83
 
46
- 没有终端时用参数(两条渠道可以只配一条):
84
+ Confirm:
47
85
 
48
86
  ```sh
49
- # Telegram
50
- hulala plugin --profile tui exec hulala-bot --init --no-input \
51
- --telegram-token-ref telegram/bot-token \
52
- --telegram-allowed-user 123456789 \
53
- --default-cwd ~/hulala-workspace/workspace
54
-
55
- # 飞书 / Lark
56
- hulala plugin --profile tui exec hulala-bot --init --no-input \
57
- --lark-app-id cli_0123456789abcdef \
58
- --lark-app-secret-ref lark/app-secret \
59
- --lark-allowed-user ou_0123456789abcdef0123456789abcdef
87
+ hulala plugin --profile tui list # @colinagent/hulala-bot is in the dependencies
60
88
  ```
61
89
 
62
- `--init` 只改它拿到的那条渠道,另一条原样保留;允许名单/其它字段也按已有内容合并,所以改一个代理不会把白名单清掉。
90
+ Uninstall: `hulala plugin --profile tui remove @colinagent/hulala-bot`, then restart the Host.
63
91
 
64
- 装完核对:
92
+ ---
65
93
 
66
- ```sh
67
- hulala plugin --profile tui list # 依赖里有 @colinagent/hulala-bot
68
- ```
94
+ ## Configure
95
+
96
+ The configuration lives in `$DSH_HOME/config/hulala-bot/config.json`:
69
97
 
70
- 卸载:`hulala plugin --profile tui remove @colinagent/hulala-bot`,然后重启 Host。
98
+ | Host | Actual path |
99
+ |---|---|
100
+ | Hulala | `~/.hulala/harness/config/hulala-bot/config.json` |
101
+ | DSH | `~/.dsh/config/hulala-bot/config.json` |
71
102
 
72
- **自动识别**:如果你在自己的 DSH 里也装了同一个插件,呼啦啦启动时会读 `~/.dsh/profiles/<同名>/package.json`,把用户额外装的 bundle 链接进自己的组合,所以不需要再装一遍。反过来不成立——呼啦啦里装的插件不会出现在 DSH 里。
103
+ Write it with `--init` rather than by hand — it validates, merges, and sets `0600`:
73
104
 
74
- ## 准备
105
+ ```sh
106
+ # Hulala
107
+ hulala plugin --profile tui exec hulala-bot --init
108
+
109
+ # DSH
110
+ dsh plugin --profile tui exec hulala-bot --init
111
+ ```
112
+
113
+ With a terminal it asks one question at a time; without one (or with `--no-input`) it takes flags. **Configure one channel or both** — a missing section simply does not start.
75
114
 
76
115
  ### Telegram
77
116
 
78
- 1. 一个 bot:跟 [@BotFather](https://t.me/BotFather) 说 `/newbot`,拿到 token。
79
- 2. 你自己的 Telegram user id(可以问 [@userinfobot](https://t.me/userinfobot))。
80
- 3. 网络到不了 `api.telegram.org` 时配 `proxy`(见下)。
117
+ Prepare: `/newbot` to [@BotFather](https://t.me/BotFather) for a token; your own user id from [@userinfobot](https://t.me/userinfobot).
81
118
 
82
- token 放系统钥匙串:
119
+ Put the token in the OS keychain (**never** in `config.json`):
83
120
 
84
121
  ```bash
85
- security add-generic-password -U -s telegram -a bot-token -w '123456:ABC…' # macOS
86
- secret-tool store --label 'telegram bot' service telegram account bot-token # Linux
122
+ # macOS
123
+ security add-generic-password -U -s telegram -a bot-token -w '123456:ABC…'
124
+ # Linux
125
+ secret-tool store --label 'telegram bot' service telegram account bot-token
87
126
  ```
88
127
 
89
- 也可以临时用环境变量:`TELEGRAM_BOT_TOKEN=…`。
128
+ Write the config:
90
129
 
91
- ### 飞书 / Lark
130
+ ```sh
131
+ hulala plugin --profile tui exec hulala-bot --init --no-input \
132
+ --telegram-token-ref telegram/bot-token \
133
+ --telegram-allowed-user 123456789 \
134
+ --default-cwd ~/hulala-workspace/workspace
135
+ ```
136
+
137
+ On a network that cannot reach `api.telegram.org`, add `--proxy http://127.0.0.1:7897` (HTTP/HTTPS only; SOCKS5 is rejected before startup).
92
138
 
93
- 配置由用户自己在开发者后台完成,这里只说明需要什么:
139
+ Environment variables can stand in for the keychain: `TELEGRAM_BOT_TOKEN=…`, or point `tokenEnv` at your own variable.
94
140
 
95
- 1. 在 [飞书开放平台](https://open.feishu.cn)(国际版是 [Lark](https://open.larksuite.com))建一个**企业自建应用**,拿到 App ID(`cli_` + 16 位十六进制)和 App Secret。
96
- 2. **开启机器人能力**。
97
- 3. **权限**:至少 `im:message`(读发给机器人的消息)与 `im:message:send_as_bot`(以应用身份发消息、更新自己发的卡片)。后台会按实际接口提示还缺哪一项。
98
- 4. **事件与回调 → 订阅方式:使用长连接接收事件**。订阅 `im.message.receive_v1`,并添加卡片回调 `card.action.trigger`(审批按钮靠它回来)。**不要**配 webhook 地址:长连接是唯一不需要公网入口的方式。
99
- 5. 发布一个版本,把可用范围设成你自己(或团队),然后在飞书里搜到机器人,单聊或拉进群(群里必须 @ 它)。
141
+ ### Feishu / Lark
100
142
 
101
- App secret 同样放钥匙串:
143
+ You create the app in the developer console; this plugin only needs the app id and an allowlist.
144
+
145
+ 1. Create a **self-built enterprise app** at [Feishu Open Platform](https://open.feishu.cn) (international: [Lark](https://open.larksuite.com)) and copy the App ID (`cli_` + 16 hex) and App Secret.
146
+ 2. Enable the **bot capability**.
147
+ 3. Scopes: at least `im:message` and `im:message:send_as_bot`. The console tells you which one is still missing for a given API.
148
+ 4. **Events and Callbacks → subscription mode: receive events through a long connection.** Subscribe to `im.message.receive_v1` and add the `card.action.trigger` callback. **Do not** configure a webhook URL.
149
+ 5. Publish a version, set its availability to yourself (or your team), then message the bot or add it to a group (it must be @-mentioned in groups).
150
+
151
+ Put the app secret in the keychain:
102
152
 
103
153
  ```bash
104
154
  security add-generic-password -U -s lark -a app-secret -w '…'
105
155
  ```
106
156
 
107
- 国际版在配置里加 `"domain": "lark"`,Open API 会指向 `open.larksuite.com`。
157
+ Write the config:
158
+
159
+ ```sh
160
+ hulala plugin --profile tui exec hulala-bot --init --no-input \
161
+ --lark-app-id cli_0123456789abcdef \
162
+ --lark-app-secret-ref lark/app-secret \
163
+ --lark-allowed-user ou_0123456789abcdef0123456789abcdef
164
+ ```
165
+
166
+ International Lark: add `--lark-domain lark` (the Open API moves to `open.larksuite.com`).
108
167
 
109
- **怎么拿到自己的 open id**:先随便给机器人发一条消息,日志里会出现
110
- `ignored chat=oc_… from=ou_… (not in allowlist)`,把 `ou_…` 填进 `allowedUsers` 再重启。
168
+ **Finding your open id**: message the bot once and read the log:
111
169
 
112
- ## 配置在哪
170
+ ```
171
+ ignored chat=oc_… from=ou_… (not in allowlist)
172
+ ```
113
173
 
114
- 状态目录是 `$DSH_HOME/config/hulala-bot/`(DSH 是 `~/.dsh`,呼啦啦是 `~/.hulala/harness`)。
174
+ Put that `ou_…` into the allowlist (`--init --lark-allowed-user ou_…`) and restart the Host.
115
175
 
116
- `config.json`、`bindings.json`、`receipts/`、`logs/` 都在里面,权限 `0600`/`0700`。连接锁不在其中:它按凭据摘要放在 `~/.hulala-bot/<hash>.lock`,所以 DSH 和呼啦啦两边都装了插件时,同一时刻也只有一个 Host 在轮询/连长连接。
176
+ ### `--init` flags
117
177
 
118
- 默认读同目录的 `config.json`(可用 `HULALA_BOT_CONFIG` 覆盖):
178
+ | Flag | Meaning |
179
+ |---|---|
180
+ | `--telegram-token-ref <service/account>` | Keychain reference; the documented name is `telegram/bot-token` |
181
+ | `--telegram-token-env <NAME>` | Read the token from an environment variable instead |
182
+ | `--telegram-allowed-user <id[,id]>` | Allowed Telegram user ids (repeatable) |
183
+ | `--telegram-allowed-chat <id[,id]>` | Allowed chat ids |
184
+ | `--proxy <http://…>` | HTTP/HTTPS proxy for Telegram |
185
+ | `--parse-mode markdown\|plain` | Telegram formatting; `markdown` falls back to plain text on rejection |
186
+ | `--lark-app-id <cli_…>` | Feishu app id |
187
+ | `--lark-app-secret-ref <service/account>` | Keychain reference for the app secret |
188
+ | `--lark-app-secret-env <NAME>` | Read the app secret from an environment variable |
189
+ | `--lark-allowed-user <ou_…[,ou_…]>` | Allowed open ids |
190
+ | `--lark-allowed-chat <oc_…[,oc_…]>` | Allowed chat ids |
191
+ | `--lark-domain feishu\|lark` | Feishu (default) or international Lark |
192
+ | `--default-cwd <path>` | Where the first message creates its session |
193
+ | `--no-input` | Never prompt; missing values are errors |
194
+
195
+ `--init` **merges per channel**: it rewrites only the channel whose flags it got, and keeps the other channel, existing allowlists and unknown fields. Adding a proxy or one more user never wipes the rest of the file.
196
+
197
+ ### File shape
119
198
 
120
199
  ```json
121
200
  {
@@ -136,113 +215,180 @@ security add-generic-password -U -s lark -a app-secret -w '…'
136
215
  }
137
216
  ```
138
217
 
139
- 顶层:
218
+ Top level:
140
219
 
141
- | 字段 | 说明 |
220
+ | Field | Meaning |
142
221
  |---|---|
143
- | `defaultCwd` | 第一次说话时在哪个目录建会话 |
144
- | `streamIntervalMs` | 同一条消息两次编辑的最小间隔,默认 800ms(飞书的卡片更新有频率限制,别调太低) |
222
+ | `defaultCwd` | Where the first message creates its session |
223
+ | `streamIntervalMs` | Minimum gap between two streaming edits, default 800ms (Feishu cards are rate limited — do not go low) |
145
224
 
146
- `telegram`:
225
+ `telegram`:
147
226
 
148
- | 字段 | 说明 |
227
+ | Field | Meaning |
149
228
  |---|---|
150
- | `tokenRef` / `tokenEnv` | 钥匙串引用或环境变量名 |
151
- | `allowedUsers` | Telegram user id。与 `allowedChats` 都为空时拒绝启动 |
152
- | `allowedChats` | chat id(群/频道场景) |
153
- | `parseMode` | `markdown`(代码块正常显示,失败自动退回纯文本)或 `plain` |
154
- | `proxy` | HTTP/HTTPS 代理,形如 `http://127.0.0.1:7897`;支持 `用户:密码@`。不读 `HTTPS_PROXY`,只认这一项 |
155
- | `baseUrl` | 只给测试用:把 Bot API 指向假服务器 |
156
- | `pollTimeoutSeconds` | 长轮询等待秒数,默认 25 |
229
+ | `tokenRef` / `tokenEnv` | Keychain reference or environment variable name |
230
+ | `allowedUsers` | Telegram user ids; startup is refused when this and `allowedChats` are both empty |
231
+ | `allowedChats` | Chat ids (groups/channels) |
232
+ | `parseMode` | `markdown` (default, falls back on rejection) or `plain` |
233
+ | `proxy` | HTTP/HTTPS CONNECT proxy; `HTTPS_PROXY` is not read, this is the only switch |
234
+ | `baseUrl` | Tests only |
235
+ | `pollTimeoutSeconds` | Long-poll hold, default 25 |
157
236
 
158
- `lark`:
237
+ `lark`:
159
238
 
160
- | 字段 | 说明 |
239
+ | Field | Meaning |
161
240
  |---|---|
162
- | `appId` | `cli_` + 16 位十六进制;格式不对会在启动前报出来,而不是静默连不上 |
163
- | `appSecretRef` / `appSecretEnv` | 钥匙串引用或环境变量名 |
164
- | `domain` | `feishu`(默认)或 `lark`(国际版) |
165
- | `allowedUsers` | 允许驱动的 open id(`ou_…`)。与 `allowedChats` 都为空时拒绝启动 |
166
- | `allowedChats` | 允许驱动的 chat id(`oc_…`) |
167
- | `baseUrl` | 只给测试用 |
241
+ | `appId` | `cli_` + 16 hex; a bad shape fails before any network call |
242
+ | `appSecretRef` / `appSecretEnv` | Keychain reference or environment variable name |
243
+ | `domain` | `feishu` (default) or `lark` |
244
+ | `allowedUsers` | Open ids (`ou_…`); startup is refused when this and `allowedChats` are both empty |
245
+ | `allowedChats` | Chat ids (`oc_…`) |
246
+ | `baseUrl` | Tests only |
168
247
 
169
- `proxy` 只接受 `http://` 或 `https://`(Clash、Surge、V2RayN 的 HTTP 端口都是这个形状);SOCKS5 不支持。请求走 CONNECT 隧道,配置写错会在启动时直接报错,而不是悄悄直连。
248
+ Environment variables: `HULALA_BOT_CONFIG` (config path), `HULALA_BOT_STATE` (state directory), `HULALA_BOT_LOCK_DIR` (lock directory), `TELEGRAM_BOT_TOKEN`, `LARK_APP_SECRET`.
170
249
 
171
- 状态文件同目录:`bindings.json`(挂载表,键是 `渠道:chat id[:主题]`)、`receipts/`(入站去重账本,24h TTL,两个渠道各一份)、`logs/`。全部 `0600`,凭据在写日志前就被替换成 `<secret>`。
250
+ ---
172
251
 
173
- ## 运行
252
+ ## Restart and verify
174
253
 
175
- 装好之后随 Host 起落,不需要单独启动。日志里出现
176
- `bot starting inside the Host; channels telegram, lark` 就是两条都在跑了。
254
+ The plugin reads both the profile and the config at Host startup, so **restart after any change**:
177
255
 
178
- **一个凭据只能有一个连接,跨 home 生效**:锁按 token / app id 的摘要放在
179
- `~/.hulala-bot/<hash>.lock`。DSH(`~/.dsh`)和呼啦啦(`~/.hulala/harness`)两边都装了插件时,第二个会报
180
- `already connected from another Host (pid …)` 并待命,而不是两边抢同一条事件流、随机丢消息。
256
+ ```sh
257
+ hulala host stop
258
+ hulala host start
259
+ # DSH: restart your own dsh process
260
+ ```
181
261
 
182
- ### 网络:DNS 污染与代理
262
+ ### Checklist
183
263
 
184
- `api.telegram.org` 在部分网络下会被污染到无关 IP,直连必然失败。Node 的 `fetch` 默认**不读** `HTTP_PROXY`/`HTTPS_PROXY`;配 `telegram.proxy` 就够,不用给 Host 加环境变量。
264
+ ```sh
265
+ # 1. The plugin is in the profile
266
+ hulala plugin --profile tui list
267
+ # Expect: @deepseek-ai/dsh-base, @colinagent/hulala-bot
268
+
269
+ # 2. The Host is up
270
+ hulala host status
271
+ # Expect: "state": "running"
272
+
273
+ # 3. The plugin actually loaded
274
+ grep "bot starting inside the Host" ~/.hulala/logs/host.log | tail -1
275
+ # Expect: bot starting inside the Host; channels telegram
276
+ # (with Feishu configured: channels telegram, lark)
277
+
278
+ # 4. Exactly one lock holder per credential
279
+ ls ~/.hulala-bot/*.lock
280
+ # Expect: one .lock per channel; contents are the local Host pid
281
+
282
+ # 5. Message the bot
283
+ # Expect: a placeholder appears, then gets replaced by the streaming answer;
284
+ # the same session is visible in the TUI
285
+ ```
185
286
 
186
- ## 命令
287
+ Feishu extras:
187
288
 
188
- 两个渠道命令一样:
289
+ ```sh
290
+ # Watch inbound events (the first run logs "ignored … not in allowlist")
291
+ tail -f ~/.hulala/harness/config/hulala-bot/logs/bridge-$(date +%F).log
292
+ ```
189
293
 
190
- | 命令 | 行为 |
191
- |---|---|
192
- | `/cwd` | 弹出最近用过的目录,点一个就挂上去 |
193
- | `/cwd <path>` | 换挂载:该目录下最近的会话,没有就新建 |
194
- | `/new` | 在当前目录新建会话 |
195
- | `/sessions` | 最近 10 个会话,`*` 表示当前 |
196
- | `/switch <n>` | 切到第 n 个 |
197
- | `/status` | 会话、目录、运行状态 |
198
- | `/stop` | 停止当前回合 |
199
- | `/help` | 上面这些 |
294
+ Logs live in `~/.hulala/harness/config/hulala-bot/logs/` (DSH: `~/.dsh/config/hulala-bot/logs/`).
295
+
296
+ ---
297
+
298
+ ## Troubleshooting
200
299
 
201
- 直接发文字就是提问。第一次说话会自动在 `defaultCwd` 里建一个会话并挂上。
300
+ These two places explain most failures:
202
301
 
203
- ## 两个渠道的差异
302
+ ```sh
303
+ tail -50 ~/.hulala/harness/config/hulala-bot/logs/bridge-$(date +%F).log
304
+ grep -i "hulala-bot" ~/.hulala/logs/host.log | tail -20
305
+ ```
204
306
 
205
- | | Telegram | 飞书 / Lark |
307
+ | Symptom / exact text | Cause | Fix |
206
308
  |---|---|---|
207
- | 传输 | Bot API 长轮询 | 长连接(WebSocket) |
208
- | 流式 | 反复编辑同一条消息 | 反复 patch 同一张卡片(飞书**不能**编辑文本消息) |
209
- | 按钮 | inline keyboard | 卡片 `action` 按钮 + `card.action.trigger` 回调 |
210
- | 置顶状态栏 | 有(`📍 <目录>`) | 无;用 `/status` 看 |
211
- | "正在输入" | 有 | 飞书没有这个 API |
212
- | 单条上限 | 4096(内部按 4000 切) | 4000 字符一张卡片,超了续卡片 |
213
- | 群聊 | 直接收 | 必须 @ 机器人,文本里的 `@_user_1` 会被去掉 |
309
+ | `no channel configured: add a "telegram" or "lark" section` | No config file, or neither section | Run `--init`, or check what `HULALA_BOT_CONFIG` points at |
310
+ | `refusing to start Telegram with an empty allowlist` | Empty allowlist (refusal is by design) | Add `--telegram-allowed-user` |
311
+ | `no Telegram bot token: set tokenRef …` | No keychain entry, or the reference name differs | Check with `security find-generic-password -s telegram -a bot-token -w`; names must match `tokenRef` |
312
+ | `lark.appId must look like cli_<16 hex>` | Wrong app id pasted, or not a self-built app | Copy `cli_` + 16 hex from the developer console |
313
+ | `no Lark app secret: set lark.appSecretRef …` | Secret not in the keychain | Store `lark/app-secret`, or set `LARK_APP_SECRET` |
314
+ | `this bot is already connected from another Host (pid …)` | Another Host (DSH or a stale process) uses the same token/app id | Stop it; once it is gone, remove the `.lock` path named in the error |
315
+ | Telegram `getUpdates: Conflict: … (409)` | Two processes polling one bot token | Same as above; also look for an old standalone bridge process |
316
+ | `proxy CONNECT failed: 403` | The proxy refused CONNECT | Check the proxy allows the target or needs auth (`http://user:pass@host:port`) |
317
+ | `connect ECONNREFUSED 127.0.0.1:7897` | Nothing listening on the proxy port | Start Clash/Surge, or change `proxy` |
318
+ | Feishu bot never answers | ① subscription mode is not "long connection" ② `im.message.receive_v1` not subscribed ③ bot capability off ④ availability excludes you ⑤ wrong app secret | Check all five; a wrong secret shows up as `99991663` / `tenant_access_token` errors in the log |
319
+ | Feishu DM works, groups do not | The bot must be @-mentioned in groups | Mention it; a leading mention is fine before a command |
320
+ | Feishu approval buttons do nothing | The `card.action.trigger` callback is missing | Add it in the console and restart the Host |
321
+ | Streaming is slow / rate limited | `streamIntervalMs` is below the platform limit | Keep it at 800 or higher (Feishu card updates are rate limited) |
322
+ | A reply says `☑️ 已处理` | That approval was already handled on another surface | Expected, not an error |
323
+ | Log says `ignored … (not in allowlist)` | The sender is not allowlisted | Add that id to the allowlist and restart |
324
+ | Nothing changed after a restart | The plugin only reads config at startup | Confirm the process really restarted (the pid in `hulala host status` changed) |
325
+
326
+ Log lines from channels are prefixed with `telegram` or `lark`. Credentials are replaced with `<secret>` before anything is written.
327
+
328
+ ---
329
+
330
+ ## Commands
331
+
332
+ The same commands on both channels:
333
+
334
+ | Command | Behaviour |
335
+ |---|---|
336
+ | `/cwd` | List recently used directories; tap one to mount it |
337
+ | `/cwd <path>` | Switch mount: newest session under that directory, create one if none |
338
+ | `/new` | Create a session in the current directory |
339
+ | `/sessions` | Last 10 sessions, `*` marks the current one |
340
+ | `/switch <n>` | Switch to the n-th |
341
+ | `/status` | Session, directory, running state |
342
+ | `/stop` | Cancel the running turn |
343
+ | `/help` | All of the above |
214
344
 
215
- ## 行为细节
345
+ Plain text is a prompt. The first message creates a session under `defaultCwd` and mounts it.
216
346
 
217
- - **一条回合一条消息**:回合开始发占位,之后反复编辑;回合结束用会话日志里的正式文本替换。超长续消息,并在代码块边界处断开、补齐围栏。
218
- - **工具调用**:还没有文本时显示 `· bash …`,让手机知道在干什么。
219
- - **编辑退避**:连续 3 次编辑失败就关掉流式,回合结束一次性发送;限流按服务器给的等待时间退避。
220
- - **入站去重**:Telegram 的 update 在 ack 丢失时会重投 24 小时,飞书长连接重连也可能重放,同一条消息不会喂给 agent 两次。
221
- - **审批**:卡片只有「允许这一次 / 拒绝」。请求里没有命令行文本,只有工具名与理由;要显示具体命令需要按 `callId` 去会话日志取。跨端取消只在 Host 内的客户端之间生效,插件模式下手机上的卡片不会被远程收走(另一端点过之后会显示「已在其他端处理」)。
222
- - **提问**:`ask_user_question` 会在手机上显示问题和选项,但只做通知——回答请回到 TUI/Desktop。
347
+ Approvals arrive as buttons (Telegram inline keyboard / Feishu card actions): "allow once" or "reject". The request carries the tool name and reason, not the command line; showing the exact command would require a `callId` lookup in the session log.
223
348
 
224
- ## 安全边界
349
+ ---
225
350
 
226
- - 白名单是唯一的口令。允许名单为空时该渠道拒绝启动。
227
- - 消息正文、工具输出、贴出的路径都会经过 Telegram / 飞书的服务器。敏感仓库请用 `allowedUsers` 限制到私人会话,并考虑关掉流式预览。
228
- - 这个插件不给 Host 增加任何权限:它能做的事,TUI 也能做。
229
- - 权限策略仍由 Host 的 permission preset 决定,这里不改写、不绕过。
351
+ ## How the channels differ
352
+
353
+ | | Telegram | Feishu / Lark |
354
+ |---|---|---|
355
+ | Transport | Bot API long polling | Long connection (WebSocket) |
356
+ | Streaming | Edits one message | Patches one card (Feishu cannot edit text messages) |
357
+ | Buttons | Inline keyboard | Card `action` + `card.action.trigger` |
358
+ | Pinned status | Yes (`📍 <directory>`) | No; use `/status` |
359
+ | Typing indicator | Yes | Feishu has no such API |
360
+ | Message limit | 4096 (split at 4000) | 4000 chars per card, then another card |
361
+ | Groups | Any message | Must @-mention the bot |
230
362
 
231
- ## 与 Host 版本的关系
363
+ Both channels can run together: each mounts its own sessions, approvals appear on both, the first answer wins, and the other surface shows that it was handled elsewhere.
232
364
 
233
- 包按 `package.json` 的 `engines.dsh` 声明范围(当前 `>=0.2.2-rc.1 <0.3.0`)。装载器在**导入模块之前**比较,不满足就跳过该层并在 `skippedBundles` 里报出包名、版本和原因,Host 的其余部分照常启动。DSH 包是 peer 依赖,解析到宿主那一份,不会出现第二个注册表。
365
+ ---
234
366
 
235
- 安装本身要求 `pnpm` 在 PATH 上——DSH 的 `dsh plugin` 与呼啦啦的 `hulala plugin`(以及 `hulala install bot`)都转发给它。
367
+ ## State and safety
236
368
 
237
- ## 开发
369
+ - **State directory**: `$DSH_HOME/config/hulala-bot/` — `config.json`, `bindings.json` (mount table), `receipts/` (de-duplication, 24h TTL), `logs/`; permissions `0600`/`0700`.
370
+ - **Connection lock**: `~/.hulala-bot/<digest>.lock`, outside every state directory, so DSH and Hulala with the same plugin still connect only once.
371
+ - **Credentials**: keychain (or environment) only; redacted as `<secret>` before logging.
372
+ - **Boundary**: the allowlist is the only password; message text, tool output and paths pass through Telegram's or Feishu's servers. The plugin grants the Host no new authority — anything it can do, the TUI can do; permissions still come from the Host's preset.
373
+ - **Cross-surface cancellation**: in plugin mode an approval already handled elsewhere is not withdrawn from this surface; it shows "handled elsewhere" on the next interaction.
374
+
375
+ ---
376
+
377
+ ## Development
238
378
 
239
379
  ```bash
240
- node --test "tests/*.test.ts" # 106 个用例
241
- node scripts/spike-host.ts <dsh-bin> <dsh-home> <profile> # 对真 Host 跑一轮
380
+ node --test "tests/*.test.ts" # 107 tests
381
+ bun run typecheck
382
+ bun run build # dist/index.mjs + dist/plugin.mjs
383
+ node scripts/spike-host.ts <dsh-bin> <dsh-home> <profile> # one round against a real Host
242
384
  ```
243
385
 
244
- 飞书的 REST 调用用注入的 `fetch` 测;长连接用假的 transport 测,测试不需要租户、不需要网络。
386
+ Node ≥ 22.6. Feishu REST is tested against an injected `fetch`, the long connection against a fake transport — no tenant, no network.
387
+
388
+ Version gate: `engines.dsh` declares the DSH range (`>=0.2.2-rc.1 <0.3.0`); the loader checks before import, skips incompatible bundles and reports them in `skippedBundles`; `@deepseek-ai/dsh-*` must stay peer dependencies so no second registry appears.
389
+
390
+ Deeper architecture and traps: `AGENTS.md` in the repository.
245
391
 
246
- ## 许可
392
+ ## License
247
393
 
248
- GPL-3.0-only。它链接的是 GPL 的 DeepSeek Harness / Hulala,不是专有代码。
394
+ GPL-3.0-only. It links GPL DeepSeek Harness / Hulala, not proprietary code.
@@ -0,0 +1,390 @@
1
+ # hulala-bot
2
+
3
+ [English](https://github.com/colinagent/hulala-bot/blob/main/README.md) | 简体中文
4
+
5
+ 把这个机器上的 DeepSeek Harness agent 接到 **Telegram** 和 **飞书 / Lark** 上。手机发一句话,本机的 Host 执行,回复流式回到同一个对话;`/cwd` 切换这个对话挂载哪个会话——和 TUI 里切换会话是同一件事。
6
+
7
+ DSH 原生和呼啦啦都用同一种方式接:**装成 Host 插件**,进 profile,随 Host 起落。npm 上显示的就是这个文件。
8
+
9
+ ---
10
+
11
+ ## 让 AI 帮你配
12
+
13
+ 这个文件就是给 AI 看的说明书:命令、配置项、期望输出、报错原文都写在里面。把下面这段发给你的 AI(Claude Code、Cursor、ChatGPT 都行),它会照着做:
14
+
15
+ ```text
16
+ 帮我配置 hulala-bot(一个把 Telegram / 飞书接到本机 DeepSeek Harness 的插件)。
17
+ 请先完整读 https://github.com/colinagent/hulala-bot/blob/main/README.zh-CN.md 的说明,然后按顺序执行:
18
+
19
+ 1. 检查环境:node -v(>=22.6)、pnpm -v、hulala --version
20
+ 2. 按「安装」一节装插件(呼啦啦用 hulala install bot;没有这条命令就用 hulala plugin)
21
+ 3. 按「配置」一节写 config.json;凭据只进系统钥匙串,不要让我把 token 贴进聊天,也不要写进 config.json
22
+ 4. 重启 Host
23
+ 5. 按「验证清单」逐条确认,每一步把实际输出贴给我
24
+ 6. 任何一步失败,按「故障排查」的原文匹配原因,不要猜
25
+
26
+ 规则:不要发明 README 之外的命令、配置项、权限或事件;缺信息就停下来问我。
27
+ ```
28
+
29
+ 给 AI 的三条硬规则,README 里也有对应依据:
30
+
31
+ 1. **凭据只进钥匙串**,配置文件里只放 `tokenRef` / `appSecretRef`(`<service>/<account>`)。
32
+ 2. **允许名单不能为空**:空名单会被拒绝启动,这不是可以跳过的步骤。
33
+ 3. **改完配置必须重启 Host**:插件在启动时读取配置,没有热加载。
34
+
35
+ ---
36
+
37
+ ## 它是什么
38
+
39
+ **一个 Host 插件**,不 patch DSH 一行代码。它跑在 Host 进程里,直接调宿主服务:
40
+
41
+ ```
42
+ ctx.sessionController.list / create / prompt / follow → 会话与流式
43
+ ctx.workspaceController.create → 工作目录
44
+ ctx.on('approval/request', (req, next) => …) → 审批
45
+ ```
46
+
47
+ 没有端口、token、cookie、WebSocket(飞书那条长连接是飞书自己的事件通道,不是本机服务)。会话历史、cwd、模型、权限以 Host 为真源;这里只保存「哪个对话挂了哪个会话」。
48
+
49
+ **一份代码,两个渠道**:`src/channel.ts` 是渠道契约,`src/telegram/`、`src/lark/` 各自实现,`src/bridge.ts` 的会话逻辑两边共用。两个渠道可以同时开,各自有允许名单和挂载表;Telegram 的对话和飞书的对话是两个独立会话,不合并身份。
50
+
51
+ ---
52
+
53
+ ## 安装
54
+
55
+ 先检查环境:
56
+
57
+ ```sh
58
+ node -v # 需要 >= 22.6
59
+ pnpm -v # 安装走 pnpm;没有就先装
60
+ hulala --version
61
+ ```
62
+
63
+ ### 呼啦啦
64
+
65
+ ```sh
66
+ hulala install bot
67
+ # 老版本没有这条命令时,等价写法:
68
+ hulala plugin --profile tui add @colinagent/hulala-bot
69
+ ```
70
+
71
+ `hulala install bot` 只是把 profile 名(`tui`)和包名填好的快捷方式,安装仍由 DSH 的 `runPluginCommand` 完成。
72
+
73
+ ### DSH(Web / Desktop / TUI)
74
+
75
+ ```sh
76
+ dsh plugin --profile tui add @colinagent/hulala-bot
77
+ ```
78
+
79
+ **期望输出**:最后一行出现 `profile tui: @deepseek-ai/dsh-base, @colinagent/hulala-bot` 和 `Restart the Host for the change to take effect.`
80
+
81
+ 装完核对:
82
+
83
+ ```sh
84
+ hulala plugin --profile tui list # 依赖里有 @colinagent/hulala-bot
85
+ ```
86
+
87
+ 卸载:`hulala plugin --profile tui remove @colinagent/hulala-bot`,然后重启 Host。
88
+
89
+ ---
90
+
91
+ ## 配置
92
+
93
+ 配置写在 `$DSH_HOME/config/hulala-bot/config.json`:
94
+
95
+ | Host | 实际路径 |
96
+ |---|---|
97
+ | 呼啦啦 | `~/.hulala/harness/config/hulala-bot/config.json` |
98
+ | DSH | `~/.dsh/config/hulala-bot/config.json` |
99
+
100
+ 用 `--init` 写,不要手写整个文件(它会校验、合并、设置 `0600` 权限):
101
+
102
+ ```sh
103
+ # 呼啦啦
104
+ hulala plugin --profile tui exec hulala-bot --init
105
+
106
+ # DSH
107
+ dsh plugin --profile tui exec hulala-bot --init
108
+ ```
109
+
110
+ 有终端时它会逐项提问;没有终端(或加 `--no-input`)时用参数。**两条渠道可以只配一条**,也可以都配。
111
+
112
+ ### Telegram
113
+
114
+ 先准备:跟 [@BotFather](https://t.me/BotFather) 说 `/newbot` 拿 token;自己的 user id 可以问 [@userinfobot](https://t.me/userinfobot)。
115
+
116
+ token 放系统钥匙串(**不要**写进 config.json):
117
+
118
+ ```bash
119
+ # macOS
120
+ security add-generic-password -U -s telegram -a bot-token -w '123456:ABC…'
121
+ # Linux
122
+ secret-tool store --label 'telegram bot' service telegram account bot-token
123
+ ```
124
+
125
+ 写配置:
126
+
127
+ ```sh
128
+ hulala plugin --profile tui exec hulala-bot --init --no-input \
129
+ --telegram-token-ref telegram/bot-token \
130
+ --telegram-allowed-user 123456789 \
131
+ --default-cwd ~/hulala-workspace/workspace
132
+ ```
133
+
134
+ 国内网络需要代理时加 `--proxy http://127.0.0.1:7897`(只支持 HTTP/HTTPS,SOCKS5 会在启动前报错)。
135
+
136
+ 也可以临时用环境变量代替钥匙串:`TELEGRAM_BOT_TOKEN=…`,或配置里的 `tokenEnv` 指定变量名。
137
+
138
+ ### 飞书 / Lark
139
+
140
+ 配置由你在开发者后台完成,插件这边只填 app id 和允许名单。
141
+
142
+ 1. 在 [飞书开放平台](https://open.feishu.cn)(国际版 [Lark](https://open.larksuite.com))建一个**企业自建应用**,拿到 App ID(`cli_` + 16 位十六进制)和 App Secret。
143
+ 2. 开启**机器人能力**。
144
+ 3. 权限至少:`im:message`、`im:message:send_as_bot`。后台会按实际接口提示还缺哪一项。
145
+ 4. **事件与回调 → 订阅方式:使用长连接接收事件**。订阅 `im.message.receive_v1`,并添加卡片回调 `card.action.trigger`。**不要**配 webhook 地址。
146
+ 5. 发布版本,把可用范围设成你自己(或团队),然后在飞书里单聊机器人或把它拉进群(群里必须 @ 它)。
147
+
148
+ App secret 放钥匙串:
149
+
150
+ ```bash
151
+ security add-generic-password -U -s lark -a app-secret -w '…'
152
+ ```
153
+
154
+ 写配置:
155
+
156
+ ```sh
157
+ hulala plugin --profile tui exec hulala-bot --init --no-input \
158
+ --lark-app-id cli_0123456789abcdef \
159
+ --lark-app-secret-ref lark/app-secret \
160
+ --lark-allowed-user ou_0123456789abcdef0123456789abcdef
161
+ ```
162
+
163
+ 国际版加 `--lark-domain lark`(Open API 指向 `open.larksuite.com`)。
164
+
165
+ **不知道自己的 open id**:先随便给机器人发一条消息,然后看日志里的
166
+
167
+ ```
168
+ ignored chat=oc_… from=ou_… (not in allowlist)
169
+ ```
170
+
171
+ 把 `ou_…` 填进允许名单(重跑 `--init --lark-allowed-user ou_…`),重启 Host。
172
+
173
+ ### `--init` 参数
174
+
175
+ | 参数 | 说明 |
176
+ |---|---|
177
+ | `--telegram-token-ref <service/account>` | 钥匙串引用,默认示例 `telegram/bot-token` |
178
+ | `--telegram-token-env <NAME>` | 改从环境变量读 token |
179
+ | `--telegram-allowed-user <id[,id]>` | 允许的 Telegram user id(可重复) |
180
+ | `--telegram-allowed-chat <id[,id]>` | 允许的 chat id |
181
+ | `--proxy <http://…>` | Telegram 走的 HTTP/HTTPS 代理 |
182
+ | `--parse-mode markdown\|plain` | Telegram 回复格式,`markdown` 失败会自动退回纯文本 |
183
+ | `--lark-app-id <cli_…>` | 飞书应用 App ID |
184
+ | `--lark-app-secret-ref <service/account>` | app secret 的钥匙串引用 |
185
+ | `--lark-app-secret-env <NAME>` | 改从环境变量读 app secret |
186
+ | `--lark-allowed-user <ou_…[,ou_…]>` | 允许的 open id |
187
+ | `--lark-allowed-chat <oc_…[,oc_…]>` | 允许的 chat id |
188
+ | `--lark-domain feishu\|lark` | 国内飞书(默认)或国际版 |
189
+ | `--default-cwd <path>` | 第一次说话时在哪个目录建会话 |
190
+ | `--no-input` | 不提问;缺参数直接报错 |
191
+
192
+ `--init` **按渠道合并**:只改它拿到的那条渠道,另一条和已有的允许名单/未知字段原样保留。所以补一个代理、加一个用户都不用重写整个文件。
193
+
194
+ ### 文件结构
195
+
196
+ ```json
197
+ {
198
+ "defaultCwd": "~/hulala-workspace/workspace",
199
+ "streamIntervalMs": 800,
200
+ "telegram": {
201
+ "tokenRef": "telegram/bot-token",
202
+ "allowedUsers": [123456789],
203
+ "parseMode": "markdown",
204
+ "proxy": "http://127.0.0.1:7897"
205
+ },
206
+ "lark": {
207
+ "appId": "cli_0123456789abcdef",
208
+ "appSecretRef": "lark/app-secret",
209
+ "domain": "feishu",
210
+ "allowedUsers": ["ou_0123456789abcdef0123456789abcdef"]
211
+ }
212
+ }
213
+ ```
214
+
215
+ 顶层:
216
+
217
+ | 字段 | 说明 |
218
+ |---|---|
219
+ | `defaultCwd` | 第一次说话时在哪个目录建会话 |
220
+ | `streamIntervalMs` | 两次流式更新的最小间隔,默认 800ms(飞书卡片有频率限制,别调太低) |
221
+
222
+ `telegram`:
223
+
224
+ | 字段 | 说明 |
225
+ |---|---|
226
+ | `tokenRef` / `tokenEnv` | 钥匙串引用或环境变量名 |
227
+ | `allowedUsers` | Telegram user id;与 `allowedChats` 都为空时拒绝启动 |
228
+ | `allowedChats` | chat id(群/频道场景) |
229
+ | `parseMode` | `markdown`(默认,失败自动回退)或 `plain` |
230
+ | `proxy` | HTTP/HTTPS CONNECT 代理;不读 `HTTPS_PROXY`,只认这一项 |
231
+ | `baseUrl` | 只给测试用 |
232
+ | `pollTimeoutSeconds` | 长轮询等待秒数,默认 25 |
233
+
234
+ `lark`:
235
+
236
+ | 字段 | 说明 |
237
+ |---|---|
238
+ | `appId` | `cli_` + 16 位十六进制;格式不对在连网前就报错 |
239
+ | `appSecretRef` / `appSecretEnv` | 钥匙串引用或环境变量名 |
240
+ | `domain` | `feishu`(默认)或 `lark` |
241
+ | `allowedUsers` | open id(`ou_…`);与 `allowedChats` 都为空时拒绝启动 |
242
+ | `allowedChats` | chat id(`oc_…`) |
243
+ | `baseUrl` | 只给测试用 |
244
+
245
+ 环境变量:`HULALA_BOT_CONFIG`(配置文件路径)、`HULALA_BOT_STATE`(状态目录)、`HULALA_BOT_LOCK_DIR`(锁目录)、`TELEGRAM_BOT_TOKEN`、`LARK_APP_SECRET`。
246
+
247
+ ---
248
+
249
+ ## 重启与验证
250
+
251
+ 配置和插件都只在 Host 启动时读取,**改完必须重启**:
252
+
253
+ ```sh
254
+ hulala host stop
255
+ hulala host start
256
+ # DSH:重启你自己的 dsh 进程
257
+ ```
258
+
259
+ ### 验证清单
260
+
261
+ ```sh
262
+ # 1. 插件在 profile 里
263
+ hulala plugin --profile tui list
264
+ # 期望:@deepseek-ai/dsh-base, @colinagent/hulala-bot
265
+
266
+ # 2. Host 起来了
267
+ hulala host status
268
+ # 期望:"state": "running"
269
+
270
+ # 3. 插件真的加载了
271
+ grep "bot starting inside the Host" ~/.hulala/logs/host.log | tail -1
272
+ # 期望:bot starting inside the Host; channels telegram
273
+ # (配了飞书就是 channels telegram, lark)
274
+
275
+ # 4. 连接锁只有一个持有者
276
+ ls ~/.hulala-bot/*.lock
277
+ # 期望:每条渠道一个 .lock;内容是本机 Host 的 pid
278
+
279
+ # 5. 给机器人发一句话
280
+ # 期望:先出现占位消息,然后被流式替换成回答;TUI 里能看到同一个会话
281
+ ```
282
+
283
+ 飞书额外确认:
284
+
285
+ ```sh
286
+ # 日志里有没有收到事件(首次配置时会有 ignored … not in allowlist)
287
+ tail -f ~/.hulala/harness/config/hulala-bot/logs/bridge-$(date +%F).log
288
+ ```
289
+
290
+ 日志位置:`~/.hulala/harness/config/hulala-bot/logs/`(DSH 在 `~/.dsh/config/hulala-bot/logs/`)。
291
+
292
+ ---
293
+
294
+ ## 故障排查
295
+
296
+ 先看这两个地方,90% 的问题能直接定位:
297
+
298
+ ```sh
299
+ tail -50 ~/.hulala/harness/config/hulala-bot/logs/bridge-$(date +%F).log
300
+ grep -i "hulala-bot" ~/.hulala/logs/host.log | tail -20
301
+ ```
302
+
303
+ | 症状 / 报错原文 | 原因 | 处理 |
304
+ |---|---|---|
305
+ | `no channel configured: add a "telegram" or "lark" section` | 配置文件不存在或两段都没有 | 跑 `--init`,或检查 `HULALA_BOT_CONFIG` 指向的路径 |
306
+ | `refusing to start Telegram with an empty allowlist` | 允许名单为空(拒绝是设计行为) | 加 `--telegram-allowed-user` |
307
+ | `no Telegram bot token: set tokenRef …` | 钥匙串里没有条目,或引用名写错 | `security find-generic-password -s telegram -a bot-token -w` 确认;名字要和 `tokenRef` 一致 |
308
+ | `lark.appId must look like cli_<16 hex>` | App ID 复制错/不是自建应用 | 回开发者后台复制 `cli_` + 16 位十六进制 |
309
+ | `no Lark app secret: set lark.appSecretRef …` | 同上,secret 没进钥匙串 | 存 `lark/app-secret`,或设 `LARK_APP_SECRET` |
310
+ | `this bot is already connected from another Host (pid …)` | 另一个 Host(DSH 或旧进程)正在用同一 token/app id | 停掉那个进程;确认它已退出后删掉报错里给出的 `.lock` |
311
+ | Telegram 报 `getUpdates: Conflict: … (409)` | 两个进程在轮询同一个 bot token | 同上;另外检查有没有旧的独立桥进程 |
312
+ | `proxy CONNECT failed: 403` | 代理拒绝 CONNECT | 检查代理是否允许该目标/是否要认证(`http://user:pass@host:port`) |
313
+ | `connect ECONNREFUSED 127.0.0.1:7897` | 代理端口没开 | 启动 Clash/Surge,或改 `proxy` |
314
+ | 飞书机器人完全不回话 | ① 订阅方式不是「长连接」② 没订阅 `im.message.receive_v1` ③ 没开机器人能力 ④ 可用范围不含你 ⑤ App Secret 错 | 按这五条逐项查;secret 错会在日志里出现 `99991663` 或 `tenant_access_token` 相关错误 |
315
+ | 飞书私聊正常、群里不回 | 群里必须 @ 机器人 | @ 它再发;命令前可以带 @ |
316
+ | 飞书审批按钮没反应 | 没添加 `card.action.trigger` 回调 | 后台补上这个回调,重启 Host |
317
+ | 流式很慢 / 频繁限流 | `streamIntervalMs` 低于平台限制 | 调到 800 以上(飞书卡片更新有频率限制) |
318
+ | 回复出现 `☑️ 已处理` | 这个审批已经在另一端处理过 | 正常,不是错误 |
319
+ | 日志里 `ignored … (not in allowlist)` | 发送者不在名单里 | 用日志里的 id 补进允许名单并重启 |
320
+ | 重启后行为没变 | 插件只在启动时读配置 | 确认进程真的重启了(`hulala host status` 的 pid 变了) |
321
+
322
+ 调试用的日志行会带渠道名前缀:`telegram`、`lark`。凭据在写日志前会被替换成 `<secret>`,不会出现在文件里。
323
+
324
+ ---
325
+
326
+ ## 命令
327
+
328
+ 两个渠道命令一样:
329
+
330
+ | 命令 | 行为 |
331
+ |---|---|
332
+ | `/cwd` | 列出最近用过的目录,点一个就挂上去 |
333
+ | `/cwd <path>` | 换挂载:该目录下最近的会话,没有就新建 |
334
+ | `/new` | 在当前目录新建会话 |
335
+ | `/sessions` | 最近 10 个会话,`*` 表示当前 |
336
+ | `/switch <n>` | 切到第 n 个 |
337
+ | `/status` | 会话、目录、运行状态 |
338
+ | `/stop` | 停止当前回合 |
339
+ | `/help` | 上面这些 |
340
+
341
+ 直接发文字就是提问。第一次说话会自动在 `defaultCwd` 里建会话并挂上。
342
+
343
+ 审批会以按钮出现(Telegram inline keyboard / 飞书卡片按钮),只有「允许这一次 / 拒绝」。请求里没有命令行文本,只有工具名与理由。
344
+
345
+ ---
346
+
347
+ ## 两个渠道的差异
348
+
349
+ | | Telegram | 飞书 / Lark |
350
+ |---|---|---|
351
+ | 传输 | Bot API 长轮询 | 长连接(WebSocket) |
352
+ | 流式 | 反复编辑同一条消息 | 反复 patch 同一张卡片(飞书不能编辑文本消息) |
353
+ | 按钮 | inline keyboard | 卡片 `action` + `card.action.trigger` |
354
+ | 置顶状态栏 | 有(`📍 <目录>`) | 无;用 `/status` 看 |
355
+ | "正在输入" | 有 | 飞书没有这个 API |
356
+ | 单条上限 | 4096(内部按 4000 切) | 4000 字符一张卡片,超了续卡片 |
357
+ | 群聊 | 直接收 | 必须 @ 机器人 |
358
+
359
+ 两个渠道可以同时开:各自挂各自的会话,审批同时出现在两边,先点的生效,另一边显示「已在其他端处理」。
360
+
361
+ ---
362
+
363
+ ## 状态与安全
364
+
365
+ - **状态目录**:`$DSH_HOME/config/hulala-bot/`,里面有 `config.json`、`bindings.json`(挂载表)、`receipts/`(去重账本,24h TTL)、`logs/`,权限 `0600`/`0700`。
366
+ - **连接锁**:`~/.hulala-bot/<凭据摘要>.lock`,不在状态目录里,所以 DSH 和呼啦啦同时装插件时也只有一个在连。
367
+ - **凭据**:只进钥匙串(或环境变量),日志写之前替换成 `<secret>`。
368
+ - **边界**:白名单是唯一口令;消息正文、工具输出、贴出的路径都会经过 Telegram / 飞书的服务器。插件不给 Host 增加权限——它能做的事,TUI 也能做;权限仍由 Host 的 preset 决定。
369
+ - **跨端取消**:插件模式下,另一端已经处理过的审批不会从这边被远程收走,只会在下次交互时显示「已在其他端处理」。
370
+
371
+ ---
372
+
373
+ ## 开发
374
+
375
+ ```bash
376
+ node --test "tests/*.test.ts" # 106 个用例
377
+ bun run typecheck
378
+ bun run build # dist/index.mjs + dist/plugin.mjs
379
+ node scripts/spike-host.ts <dsh-bin> <dsh-home> <profile> # 对真 Host 跑一轮
380
+ ```
381
+
382
+ 需要 Node ≥ 22.6。飞书的 REST 用注入的 `fetch` 测,长连接用假 transport 测,测试不需要租户、不需要网络。
383
+
384
+ 版本约束:`engines.dsh` 声明 DSH 兼容范围(当前 `>=0.2.2-rc.1 <0.3.0`),装载器在 import 之前校验,不满足就跳过并写进 `skippedBundles`;`@deepseek-ai/dsh-*` 必须是 peerDependencies,避免出现第二份注册表。
385
+
386
+ 更细的架构与坑:见仓库里的 `AGENTS.md`。
387
+
388
+ ## 许可
389
+
390
+ GPL-3.0-only。它链接的是 GPL 的 DeepSeek Harness / Hulala,不是专有代码。
package/dist/plugin.mjs CHANGED
@@ -245,7 +245,7 @@ async function larkConfig(raw, env, file) {
245
245
  if (!/^cli_[0-9a-fA-F]{16}$/.test(appId)) {
246
246
  throw new Error(`lark.appId must look like cli_<16 hex>, not ${JSON.stringify(appId)} (from ${file})`);
247
247
  }
248
- const appSecret = await resolveSecret(raw, env, "appSecret");
248
+ const appSecret = await resolveSecret(raw, env, "appSecret") ?? env.LARK_APP_SECRET;
249
249
  if (appSecret === undefined || appSecret.trim() === "") {
250
250
  throw new Error(`no Lark app secret: set lark.appSecretRef in ${file}, or LARK_APP_SECRET in the environment`);
251
251
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colinagent/hulala-bot",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "license": "GPL-3.0-only",
5
5
  "type": "module",
6
6
  "engines": {
@@ -52,8 +52,9 @@
52
52
  "dist/index.mjs",
53
53
  "dist/plugin.mjs",
54
54
  "cordis.patch.yml",
55
- "package.json",
56
55
  "README.md",
56
+ "README.zh-CN.md",
57
+ "package.json",
57
58
  "LICENSE"
58
59
  ],
59
60
  "exports": {