wechat-clawbot 0.9.5 → 0.9.7

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.
Files changed (49) hide show
  1. package/README.md +63 -491
  2. package/README.zh.md +76 -190
  3. package/cordis.patch.yml +9 -2
  4. package/lib/approvals.d.ts.map +1 -1
  5. package/lib/approvals.js +16 -6
  6. package/lib/approvals.js.map +1 -1
  7. package/lib/bridge.d.ts +10 -2
  8. package/lib/bridge.d.ts.map +1 -1
  9. package/lib/bridge.js +89 -25
  10. package/lib/bridge.js.map +1 -1
  11. package/lib/claude-peer.js +4 -4
  12. package/lib/claude-peer.js.map +1 -1
  13. package/lib/cli.js +0 -0
  14. package/lib/client.js +1 -1
  15. package/lib/config.js +2 -2
  16. package/lib/config.js.map +1 -1
  17. package/lib/inbound.d.ts.map +1 -1
  18. package/lib/inbound.js +20 -6
  19. package/lib/inbound.js.map +1 -1
  20. package/lib/index.d.ts +0 -10
  21. package/lib/index.d.ts.map +1 -1
  22. package/lib/index.js +70 -3
  23. package/lib/index.js.map +1 -1
  24. package/lib/mcp-route.js.map +1 -1
  25. package/lib/pending.d.ts +8 -0
  26. package/lib/pending.d.ts.map +1 -1
  27. package/lib/pending.js +16 -0
  28. package/lib/pending.js.map +1 -1
  29. package/lib/prompt.js +2 -2
  30. package/lib/questions.js +20 -2
  31. package/lib/questions.js.map +1 -1
  32. package/lib/schedule-migrate.d.ts +96 -0
  33. package/lib/schedule-migrate.d.ts.map +1 -0
  34. package/lib/schedule-migrate.js +205 -0
  35. package/lib/schedule-migrate.js.map +1 -0
  36. package/lib/subagent-model.d.ts +1 -1
  37. package/lib/tool.d.ts.map +1 -1
  38. package/lib/tool.js +13 -49
  39. package/lib/tool.js.map +1 -1
  40. package/lib/typing.d.ts +66 -0
  41. package/lib/typing.d.ts.map +1 -0
  42. package/lib/typing.js +174 -0
  43. package/lib/typing.js.map +1 -0
  44. package/package.json +22 -14
  45. package/wechat-clawbot-INSTALL.md +67 -2
  46. package/lib/voice.d.ts +0 -29
  47. package/lib/voice.d.ts.map +0 -1
  48. package/lib/voice.js +0 -172
  49. package/lib/voice.js.map +0 -1
package/README.md CHANGED
@@ -1,541 +1,113 @@
1
1
  # wechat-clawbot
2
2
 
3
- Connect a [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH) profile to your WeChat through the official **WeChat ClawBot** bridge (Tencent iLink API). Once bound, you can message your DSH agent from WeChat while you are away from the computer — ask it to look at files, edit them, run commands — and it replies (including permission/approval questions) in the WeChat conversation.
3
+ English | [中文](README.zh.md)
4
4
 
5
- > **Status: v0.9.5 — requires DSH ≥ 0.1.7** — text messages both ways; **native vision** (an inbound photo rides in the model's own message, and `look_at_image` hands a local one to it directly — no separate vision model, no second round trip); agent → WeChat file/image delivery; quoted (引用) message resolution; long-term memory; scheduled reminders; a **settings card** on the Plugins sidebar page whose fields apply live; and a per-plugin model pin so the web UI's model picker no longer moves the bot. **0.9.5:** auto-memory is on by default, and long-term memory no longer takes one-off reminders (those belong to scheduled reminders; a stored "明天十点开会" is wrong the next day). **0.9.4:** ported to DSH 0.1.7 — settings live on the Plugins page (`plugins.bundle.config`), hot fields are `.volatile()` and apply without a restart, message sources use the session-v4 producer kinds. **0.9.3:** the auto-memory classifier runs on the session's own route instead of a hardcoded vendor. Group chats are not supported.
6
- > **About auto-memory (`autoMemory`).** Up to 0.9.2 the classifier sent
7
- > matching message text to `api.deepseek.com` — a second destination beyond
8
- > your configured model — so 0.9.2 put it behind a flag, off by default.
9
- > **Since 0.9.3 it follows your bot's own route**, so it is no longer a
10
- > separate vendor hop, and **since 0.9.4 it is on by default**. Opt out with
11
- > `autoMemory: false` — see **Security**.
5
+ Chat with the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH) agent on your computer from WeChat.
6
+ Away from your desk, you can still ask it to look through files, edit documents or run commands, and the results come back to the WeChat chat.
12
7
 
13
- ## How it works
8
+ It uses WeChat's official **微信ClawBot** channel (Tencent iLink): no second account and no web-login tricks.
14
9
 
15
- ```
16
- Phone WeChat ──► Tencent iLink cloud ──► this plugin (long-poll monitor)
17
- ◄──────────────────────────────── (text replies, approval questions)
18
- │
19
- ▼
20
- one fixed DSH agent session ("wechat-main")
21
- (persisted, auto-compacted like any DSH session)
22
- ```
10
+ ## What it does
23
11
 
24
- - The plugin reuses the protocol client from the official, MIT-licensed
25
- [`@tencent-weixin/openclaw-weixin`](https://www.npmjs.com/package/@tencent-weixin/openclaw-weixin)
26
- package (see [`NOTICE`](NOTICE)); only the OpenClaw integration layer was
27
- replaced with a DeepSeek Harness integration.
28
- - The WeChat conversation maps to **one fixed session id** (default
29
- `wechat-main`), so context is shared, history survives restarts, and
30
- automatic context compaction keeps token usage low.
31
- - The WeChat session's approval policy is forced to `ask`: permission
32
- requests (file access, command execution, sandbox escalation) are forwarded
33
- to WeChat and you answer with `同意` / `拒绝` (or `yes` / `no`).
34
- - **File/image delivery**: the WeChat agent has a `send_wechat_file` tool —
35
- just ask it (e.g. *"把 README.md 发给我"* or *"生成一张图表发给我"*). Files
36
- travel through Tencent's CDN with the official AES-128-ECB encrypted upload
37
- pipeline; images, PDFs, Office documents, archives etc. are supported.
38
- - The plugin runs **inside the profile process**: as long as the profile is
39
- running, the bridge is up. Login is manual (scan a QR code), once per
40
- binding; the token is stored under `$DSH_HOME/clawbot` and reused on
41
- restart.
12
+ - **Put your computer to work from WeChat**: "what's the newest PDF in Downloads?", "run this script"
13
+ - **Understands photos**: send a picture and ask what it is. If the model accepts images, the photo goes to it directly
14
+ - **Sends files back**: "send me README.md", "make a chart and send it". Images, PDFs, Office files and archives all work
15
+ - **"Typing…"**: while it thinks, works or sends you a file, WeChat shows the bot as typing, just like a person, until the reply arrives
16
+ - **Reminders**: "remind me at 9 tomorrow to hand in the report", and you get a WeChat message on time
17
+ - **Long-term memory**: remembers your habits and preferences, so you don't have to repeat them
18
+ - **Asks before it acts**: anything that needs your approval (e.g. touching files outside its working directory) is asked in WeChat; reply `同意` / `拒绝` (or `yes` / `no`)
19
+ - **Understands quotes**: reply to an older message with WeChat's quote feature and it knows which one you mean
42
20
 
43
21
  ## Requirements
44
22
 
45
- - Node.js >= 22
46
- - A DSH profile (e.g. the `web` profile) with a configured model provider
47
- - The WeChat mobile app with the official **微信ClawBot** plugin available
48
- (设置 → 插件; WeChat may prompt you to update the app the first time you scan)
23
+ - DSH **0.1.7 – 0.2.x** (tested on 0.1.7-rc.2 and 0.2.0-rc.2), Node.js 22+ and pnpm
24
+ - The official **微信ClawBot** plugin in the WeChat mobile app (WeChat → Settings → Plugins; the first scan may ask you to update WeChat)
25
+ - A computer that stays on: the bot is online while DSH is running
26
+
27
+ ## Set up in three steps
49
28
 
50
- ## Install
29
+ **1. Install the plugin**
51
30
 
52
31
  ```bash
53
- # 1. Install the plugin into a profile (pnpm is required)
54
32
  dsh plugin --profile web add wechat-clawbot
55
-
56
- # 2. Restart the profile
57
- # (stop `dsh web`, then start it again)
58
- dsh web
59
33
  ```
60
34
 
61
- The plugin starts automatically at boot (`autoStart: true`). To change its
62
- configuration, add a `clawbot` row to the profile's `cordis.patch.yml`:
63
-
64
- ```yaml
65
- - id: clawbot
66
- config:
67
- allowFrom: [] # allowlist of WeChat user ids; [] = only the binder
68
- sessionId: wechat-main # the fixed DSH session for all WeChat messages
69
- forwardQuestions: false
70
- approvalTimeoutMs: 0 # 0 = wait indefinitely for approval answers
71
- logLevel: info
72
- ```
35
+ Or search for `wechat-clawbot` under **Plugins → Add plugin** in the DSH web sidebar. **Restart DSH** once afterwards.
73
36
 
74
- ## Connect (one-time, manual)
37
+ **2. Link your WeChat**
75
38
 
76
39
  ```bash
77
- # From the profile directory (or anywhere; the state dir is shared):
78
- clawbot login
40
+ npx -y -p wechat-clawbot clawbot login
79
41
  ```
80
42
 
81
- A QR code is printed in the terminal. Scan it with **WeChat → 扫一扫** and
82
- confirm. Afterwards:
43
+ A QR code appears in the terminal. Scan it with WeChat's "Scan" and confirm.
83
44
 
84
- - WeChat shows a new contact **「微信ClawBot」** — open it and start chatting.
85
- - The running profile picks up the credentials automatically within a second
86
- (it watches the state directory) — no restart needed.
45
+ **3. Start chatting**
87
46
 
88
- Other commands:
47
+ A new contact, **微信ClawBot**, shows up in WeChat. Message it. The running DSH picks up the new link within a few seconds, so no restart is needed.
89
48
 
90
- ```bash
91
- clawbot status # show the bound account
92
- clawbot logout # unbind and delete credentials
93
- ```
94
-
95
- Environment:
96
-
97
- | Variable | Default | Meaning |
98
- |---|---|---|
99
- | `CLAWBOT_STATE_DIR` | `$DSH_HOME/clawbot` | credential/state directory |
100
- | `CLAWBOT_LOG_LEVEL` | `info` | `debug` / `info` / `warn` / `error` |
101
-
102
- ## Security
103
-
104
- - **Allowlist**: by default only the WeChat user who scanned the QR code may
105
- message the agent. Add more users via `allowFrom` (their WeChat user ids
106
- appear in the logs / `clawbot status`).
107
- - **Approvals**: the WeChat session runs with approval policy `ask`, so
108
- sensitive operations still require your explicit reply in WeChat. Other
109
- sessions (e.g. the local web GUI) keep their own policy.
110
- - Unknown senders are ignored silently.
111
- - **Where your message text goes.** Normally: to whatever model your DSH
112
- profile routes the WeChat session to, and nowhere else. There is exactly one
113
- optional exception, and it is **off by default** —— see below.
114
-
115
- ### Auto-memory asks the same model a second question (on by default, `autoMemory`)
116
-
117
- With `autoMemory` on (the default), a message that pattern-matches a durable personal
118
- fact (short, and shaped like "我住在…" / "我不能喝咖啡") is sent **verbatim**
119
- to a model, which decides whether it belongs in the long-term memory file.
120
-
121
- **Since 0.9.3 that model is the one your bot is already talking to.** The
122
- classifier goes through the harness's own `llm` service on this session's
123
- route, so it inherits your provider, your model, and your credentials.
124
-
125
- Before 0.9.3 it POSTed to `https://api.deepseek.com/chat/completions` with a
126
- hardcoded `deepseek-chat` and the `DEEPSEEK_API_KEY` read straight out of
127
- `~/.dsh/.credentials.yaml`. That was a **second destination**: point the bot at
128
- a local model or a university gateway and your WeChat text still went to
129
- DeepSeek — and switching providers silently made the split worse rather than
130
- better. That hop is gone.
131
-
132
- Two things still worth being explicit about:
133
-
134
- - The gate selects **short messages that look like personal facts** — which is
135
- precisely the most sensitive slice of a chat, not a random sample. They now
136
- go only where your conversation already goes, but they do go there.
137
- - If the route cannot be resolved (no `llm` service in this composition), the
138
- classifier **skips** rather than falling back to some other vendor.
139
-
140
- **On by default since 0.9.4.** It was off while it meant a second vendor; with
141
- the destination unified, what is left is one extra call on text that model has
142
- just been sent anyway. Turning it off costs you nothing structural:
143
- `remember_user_info` still works, the agent just decides for itself instead of
144
- asking a cheap classifier.
145
-
146
- To opt out, add `autoMemory: false` to the `clawbot` entry of your profile's
147
- `cordis.patch.yml` (it is a hot field: takes effect on the next message, no
148
- restart). The settings card has no toggle for it.
149
-
150
- ## Configuration reference
151
-
152
- | Key | Type | Default | Meaning |
153
- |---|---|---|---|
154
- | `autoStart` | boolean | `true` | start the monitor at boot when a bound account exists |
155
- | `allowFrom` | string[] | `[]` | allowed sender ids; empty = binder only |
156
- | `sessionId` | string | `wechat-main` | fixed DSH session for all WeChat traffic |
157
- | `cwd` | string | `process.cwd()` | workspace for a freshly created session |
158
- | `forwardQuestions` | boolean | `false` | forward `ask_user_question` / plan-review to WeChat (see note) |
159
- | `approvalTimeoutMs` | number | `0` | approval answer timeout; `0` = wait forever |
160
- | `botAgent` | string | `DSH-ClawBot/0.1.0 …` | `bot_agent` reported to iLink |
161
- | `maxImageEdge` | number | `2048` | long-edge pixel cap for compressed images |
162
- | `imageQuality` | number | `80` | JPEG quality for compressed images |
163
- | `compressThresholdBytes` | number | `1048576` | only compress images larger than this |
164
- | `apiBaseUrl` | string | `https://ilinkai.weixin.qq.com` | iLink API base (override for testing) |
165
- | `logLevel` | `debug\|info\|warn\|error` | `info` | protocol log level |
166
- | `stripEmoji` | boolean | `true` | strip Unicode emoji from outbound text |
167
- | `autoMemory` | boolean | `false` | let the auto-memory classifier run —— **sends matching message text to `api.deepseek.com`**, see **Security** |
168
- | `noticeMinBytes` | number | `2097152` | announce a file before upload only above this size; `0` = always |
169
- | `attachImages` | boolean | `true` | give images to the model directly when the route accepts them |
170
- | `provider` | string | — | pin this session's provider; empty = follow the deployment default |
171
- | `model` | string | — | pin the model; empty = follow the deployment default |
172
- | `reasoningEffort` | string | — | pin the effort; empty = the model's own default |
173
- | `mcpBridge` | boolean | `true` | answer the `/plugins/clawbot/mcp/*` routes (see **The Claude bridge**) |
174
-
175
- > `forwardQuestions`: only one `userQuestions` provider can exist per DSH
176
- > context. The Web UI registers one while a browser is attached, so this
177
- > option only takes effect in deployments without an active Web provider.
178
- > Approval forwarding (`approval/request`) is independent and always on for
179
- > the WeChat session.
49
+ Other commands: `clawbot status` shows who is linked, `clawbot logout` unlinks (use the same `npx -y -p wechat-clawbot` prefix).
180
50
 
181
51
  ## Settings
182
52
 
183
- Most of the table above is editable at **设置 → 插件 → 微信 Bot**, and a change
184
- lands on the next message with no restart and no dropped WeChat connection: the
185
- plugin diffs the committed settings and copies the *hot* fields into its live
186
- config, which every collaborator holds by reference and reads at the moment it
187
- is used.
188
-
189
- The card writes into the settings document's `clawbot` section, which is an
190
- **override layer over the plugin's cordis row** — `cordis.patch.yml` stays the
191
- default, and the file only ever stores fields you actually changed. Each row
192
- shows a 已覆盖 badge with a 重置 that drops back to the composed value.
193
-
194
- Cold fields (`sessionId`, `autoStart`, `forwardQuestions`, `botAgent`,
195
- `apiBaseUrl`, `cwd`) are deliberately **absent from the card**. They are stored
196
- but not applied in place — `apiBaseUrl` would redirect a connected client
197
- mid-flight and `sessionId` would point the bridge at a session it is not bound
198
- to — so they live in `cordis.patch.yml`, where changing them already means a
199
- reload.
200
-
201
- ### Pinning the model
202
-
203
- Leaving `provider`/`model` empty means the session follows the deployment
204
- default, which is also why picking a model in the web UI used to move the bot:
205
- that picker writes through to the global `agent-default-model`. Setting them
206
- here breaks the coupling. A model id that will not resolve is refused rather
207
- than applied, so a typo cannot brick the next message.
208
-
209
- ## The Claude bridge
210
-
211
- Two directions, and they are separate mechanisms with separate failure modes.
212
-
213
- ### Outward: `/plugins/clawbot/mcp/*` — Claude Code drives DSH
214
-
215
- Four routes, consumed by [dsh-mcp-bridge](../dsh-mcp-bridge) (an MCP server, not
216
- a DSH plugin), which is what gives a Claude Code session tools to list/read/drive
217
- DSH sessions and to reach the owner on WeChat.
218
-
219
- | Route | Method | Does |
220
- |---|---|---|
221
- | `mcp/sessions` | GET | list sessions: id, title, cwd, live, running |
222
- | `mcp/read` | POST | tail one session's user/assistant turns |
223
- | `mcp/send` | POST | steer or follow up a **live** agent |
224
- | `mcp/notify` | POST | one WeChat message to the owner |
225
- | `mcp/status` | GET | is the bridge on, has anything called it |
226
-
227
- The privileged half lives here rather than in the MCP server for a concrete
228
- reason: `ctx.agents` holds the live agent objects, and `steer()`/`followup()` are
229
- in-memory methods an out-of-process caller cannot reach. The WeChat send needs
230
- the account token plus per-peer context tokens, so duplicating it outside would
231
- mean a second copy of the credential handling.
232
-
233
- Three properties are load-bearing and covered by tests:
234
-
235
- - **`notify` takes no recipient.** It sends to `account.userId` — the id linked by
236
- QR login — so messaging anyone but the owner is *unrepresentable*, not merely
237
- discouraged.
238
- - **`send` does not reach WeChat.** Injected messages carry source plugin
239
- `clawbot-mcp`, and the bridge's session listener treats any non-`schedule`
240
- plugin turn as GUI-only (leaves `currentSender` unset). So a message pushed
241
- into `wechat-main` is answered in the web UI only. `notify` is the sole route
242
- to the phone. **Changing that source string breaks the isolation.**
243
- - **Auth.** Every route needs `Authorization: Bearer <token>` from
244
- `<state>/mcp-token` (0600, minted on first boot). `mcp/status` is deliberately
245
- unauthenticated — a browser page cannot hold a secret — so it reports the
246
- token's *path*, never its value.
247
-
248
- `mcpBridge: false` makes all four return 403 while leaving them registered: the
249
- flag is read per request, so it is a live kill switch in both directions.
250
-
251
- ### Inward: three tools — DSH sees and steers Claude Code (open or closed)
252
-
253
- Registered on the WeChat agent (`restrictTools` is a **deny** list, so they need
254
- no allowlisting): `list_claude_sessions`, `read_claude_session`,
255
- `send_to_claude_session`.
256
-
257
- Listing and reading go straight to files, which is the stable half:
258
- `~/.claude/sessions/<pid>.json` is world-readable, and
259
- `~/.claude/projects/<slug>/<sessionId>.jsonl` is the transcript (found by
260
- globbing for the id — deriving the directory name flattens both separators *and*
261
- dots, which is easy to get subtly wrong).
262
-
263
- Sending is the interesting half. There is **no documented CLI** for reaching a
264
- live session: `claude` has no send/message subcommand, and `--resume -p` starts a
265
- new run from history instead of the session the user is watching. The real
266
- mechanism is `peerProtocol 1` over `/tmp/cc-socks/<pid>.sock` with a 0600 key,
267
- and `claude.exe` is a native binary. So rather than reverse-engineer it, this
268
- shells out to a short-lived
269
-
270
- ```sh
271
- claude -p "<deliver X to session Y>" --allowed-tools ListAgents,SendMessage --model haiku
272
- ```
53
+ Open **Plugins → wechat-clawbot → 微信 Bot** in the DSH web sidebar. Changes apply immediately and the WeChat connection stays up:
273
54
 
274
- and lets Claude Code do the socket work with its own implementation — protocol
275
- changes stay Anthropic's to keep working. Verified end to end.
55
+ - **Model**: pin a provider / model / reasoning effort for the bot. Leave it empty to follow DSH's global default.
56
+ - **Who may message the bot**: only you (the person who scanned) by default. Add WeChat user ids to let others in.
57
+ - **Images**: whether photos go straight to the model, and how outgoing images are resized and compressed.
58
+ - **开放 Claude 桥** (Claude bridge): see "Working with Claude Code" below.
276
59
 
277
- **A session that is closed takes the other branch.** The registry is keyed by
278
- pid, so a roster built from it alone goes empty the moment the user quits their
279
- terminal — and the tool answered "本机没有正在运行的 Claude Code 会话", which
280
- reads as *you cannot do this* rather than *nothing is open*. That is exactly
281
- when messaging one from a phone is most useful.
60
+ A few options (the session id, the working directory, whether to start with DSH) live in the `- id: clawbot` entry of
61
+ `~/.dsh/profiles/web/cordis.patch.yml`. Changing them restarts the WeChat listener automatically.
282
62
 
283
- Transcripts, unlike the registry, live forever, and the very thing that makes
284
- `--resume` wrong for a live session is what makes it right for a closed one:
63
+ ## Privacy and safety
285
64
 
286
- ```sh
287
- claude -p "<the message>" --resume <sessionId> --allowed-tools Read,Grep,Glob
288
- ```
65
+ - **Only you**: messages from anyone but the person who scanned the QR code are ignored.
66
+ - **Approvals come to you**: anything DSH needs you to approve is asked in WeChat, and nothing happens until you answer.
67
+ - **Where your messages go**: only to the model you configured for this session in DSH. The plugin sends your text nowhere else.
68
+ - **Auto-memory** (on by default): short messages that look like lasting facts ("I don't drink coffee") get a second
69
+ question to **the same model**: should this be remembered? To turn it off, add `autoMemory: false` to the `clawbot`
70
+ entry in `cordis.patch.yml`. It takes effect on the next message.
71
+ - The WeChat link and the long-term memory are stored on your computer, under `~/.dsh/clawbot/`.
289
72
 
290
- run **in that session's own cwd** (taken off the transcript's `cwd` field, not
291
- un-flattened from the directory name). Verified 2026-09-04: a session created,
292
- exited, then resumed recalled a codeword from before it died, and the new turn
293
- landed in the *same* transcript file — so the user finds the exchange there when
294
- they reopen it.
295
-
296
- Three deliberate differences from the relay path:
297
-
298
- - **An explicit approval mode**, from `clawbot.claudeResumePermissionMode`
299
- (default `acceptEdits`; hot, so a change applies to the next message).
300
-
301
- This began as a read-only tool allowlist, and that was the wrong dial: in a
302
- workspace the user trusts, the resumed session should just use their normal
303
- approval mode. But **"pass no mode" is not that.** Measured 2026-09-04: a
304
- headless resume with no `--permission-mode` asks for permission, finds nobody
305
- to answer, replies *"I've requested permission to write the file. Please
306
- approve the permission prompt to proceed"*, and writes nothing. Headless has
307
- no one to prompt, so a mode has to be named — the only question is which.
308
-
309
- The union is exactly the CLI's own choices, so a bad value fails in settings
310
- rather than at the spawn. `acceptEdits` edits files but still needs approval
311
- to run commands; `bypassPermissions` is one setting away for a workspace the
312
- user trusts completely. The summary always names the mode that applied, so a
313
- WeChat reply never leaves it ambiguous whether the work actually happened.
314
- - **No model override.** The relay pins haiku because it only forwards. A resume
315
- puts a turn in the user's own conversation, so it runs on their default model.
316
- - **A longer ceiling.** 300s against the relay's 120s: a resume replays the
317
- whole transcript first. Measured 4–20s on a two-turn session; a long
318
- conversation is minutes, and the relay's timeout would have called that a
319
- failure.
320
-
321
- **A closed session is woken up, not impersonated.** The first version ran the
322
- turn itself (`claude -p --resume`), which made the closed case a second
323
- mechanism with its own failure modes — and on 2026-09-09 that bill came due (see
324
- below). Now:
325
-
326
- ```sh
327
- claude --bg --resume <sessionId> --permission-mode <mode>
328
- ```
73
+ ## FAQ
329
74
 
330
- continues the session **under the same id** as a real background session, which
331
- registers as an ordinary peer — `peerProtocol 1`, a `messagingSocketPath`,
332
- `kind: bg` (verified). Once it is a peer, delivery is just the relay above. **One
333
- delivery mechanism**, and the turn runs in an actual session on its own model
334
- instead of inside a headless CLI. The old headless path is kept only as a
335
- fallback for when the revive never registers; the reply says which ran.
75
+ **I sent a message and nothing happened**: check that DSH is running, then open **Plugins → wechat-clawbot**: both
76
+ components should say "running". If you just upgraded DSH, see the [install & troubleshooting guide](wechat-clawbot-INSTALL.md).
336
77
 
337
- **A background session is EXCLUSIVE, and that is the cost of this design.**
338
- While it runs, that conversation cannot be opened in the desktop app at all:
78
+ **A reminder was late**: reminders need the computer and DSH to be running. While the computer sleeps, they wait until it wakes.
339
79
 
340
- ```
341
- Error: Session c8a4fd3c… is running as a background session (c8a4fd3c).
342
- Run `claude attach c8a4fd3c` to open it, or `claude stop c8a4fd3c` first to resume it here.
343
- ```
344
-
345
- The app's child process exits 1 on that, and the app reports **"Claude Code
346
- crashed"** — which is what happened to the user on 2026-09-09, minutes after this
347
- path first shipped: they asked the bot to wake the Datareader session, then
348
- opened that same conversation in the app.
349
-
350
- The trade is inherent to `--bg`; the surprise is not. So every revive reply
351
- carries the way out (`claude attach <id>` to take it over in a terminal,
352
- `claude stop <id>` to hand it back to the app), and the tool description tells
353
- the model to pass those on rather than dropping them.
354
-
355
- Not fixed by auto-stopping when the turn goes idle, which was the obvious idea:
356
- there is no reliable way from here to tell an idle background session from one
357
- the user has just attached to, and stopping the latter out from under them is
358
- worse than the error it would prevent.
359
-
360
- **The approval mode comes from the session itself.** `clawbot.claudeResumePermissionMode`
361
- defaults to `inherit`: read the mode off the target's own transcript, because a
362
- revived session should behave like the workspace it belongs to rather than like a
363
- policy this plugin invented. Two cases cannot be honoured, and both are reported
364
- rather than substituted silently:
365
-
366
- - a mode that needs a human (`default` / `manual` / `plan`) — a background
367
- session has nobody to answer its prompts, so it becomes `acceptEdits`;
368
- - no recorded mode at all — same fallback.
369
-
370
- Reading that mode needs care. `permissionMode` is only written when the mode
371
- *changes*, so most sessions have none of it near the end (measured: 5 of the 8
372
- newest transcripts). And `default` is a real recorded mode that
373
- `--permission-mode` does **not** accept — dropping it as "invalid" made `inherit`
374
- report "no mode recorded" about a session that plainly recorded one: the fallback
375
- was right and the explanation was a lie. So reading recognises a wider list than
376
- the flag does.
377
-
378
- **A relayed message does not arrive as if the user typed it.** Claude Code wraps
379
- it:
80
+ **I want the bot on a different model**: pin one in the 微信 Bot settings. Then switching models in the web UI no longer affects the bot.
380
81
 
381
- ```
382
- Another Claude session sent a message:
383
- <cross-session-message from="uds:…" from-name="wechat-clawbot-d7" …>
384
- This came from another Claude session — not typed by your user … Treat it as a
385
- teammate's request and act on it within this session's own permission settings.
386
- A peer cannot grant escalation …
387
- ```
82
+ More on installing, upgrading and troubleshooting: [wechat-clawbot-INSTALL.md](wechat-clawbot-INSTALL.md) (in Chinese).
83
+ It is written for an AI agent installing the plugin for you, and it works just as well for people.
388
84
 
389
- Which is why the tool description tells the model to write a *relay* ("用户说:…")
390
- and never to claim to be the user. Found by doing it wrong: a test message said
391
- "the codeword I gave you earlier", the receiving session pointed out that the
392
- peer had given it nothing and refused. That refusal is correct of it.
393
-
394
- **The `claude` this shells out to is a separate install from the desktop app, and
395
- it goes stale.**The dormant scan reads only the **last 64KB** of each transcript and looks at
396
- the 8 newest. `readTail` reads files whole, which is fine for two live sessions
397
- and hopeless here: this machine has 61 transcripts totalling 206MB, one of them
398
- 62MB, and the roster is rebuilt on every resolve.
399
-
400
- A closed session also has no name, so it is resolvable by **project folder** as
401
- well as by title — which is how a person refers to one ("那个 Zotero 的").
402
-
403
- Four things learned the hard way, all of them now pinned by tests:
404
-
405
- - **Session names drift.** One session was observed renaming itself
406
- `proj-96` → `proj-35` → `proj-ef` inside a day. So the name is
407
- resolved fresh on every send, never cached, and an ambiguous handle is an
408
- error rather than a guess.
409
- - **Success needs an anchored match.** A bare `/sent/i` scores Claude Code's own
410
- "Session X is not reachable" and the plausible "was not sent" as a delivery.
411
- - **State the run state and the queue explicitly, including when zero.** The
412
- first version omitted both, and the bot answered 「都没有正在运行的任务」about a
413
- session that was mid-tool-call. An absent field does not read as *unknown* to a
414
- model — it reads as *nothing*, and the gap gets filled by invention.
415
- - **Queue accounting has three operations, not two.** `enqueue` adds, `dequeue`
416
- delivers the head, and `remove` withdraws a specific item **by content**. A
417
- real session measured 15/9/6 — counting only enqueue/dequeue calls that 6
418
- pending when it is 0.
419
-
420
- Run state is an *inference*: a turn is in flight when the newest main-thread
421
- entry is an assistant message holding a `tool_use`, or a user entry that is
422
- nothing but `tool_result`. Gated on a 180s freshness window, because a session
423
- killed mid-tool-call keeps an unfinished last entry forever.
424
-
425
- Known limit: a message **currently waiting** in the queue does not appear in the
426
- transcript. Verified, not assumed — a session had one queued while
427
- enqueue/dequeue/remove balanced to zero, with the file 7s fresh and writes shown
428
- to be prompt. A live answer would need the peer socket.
429
-
430
- > Timestamps in the transcript are **UTC**. Render them through
431
- > `toLocaleTimeString`, never by slicing the ISO string — `"…T20:33:05Z"
432
- > .slice(11,16)` reported a 16:33 message as 20:33.
433
-
434
- ## Time, and why reminders kept landing on the wrong day
435
-
436
- Every date this plugin writes or shows is the user's **local** date, taken from
437
- `src/localtime.ts`. `new Date().toISOString().slice(0, 10)` is always a bug here:
438
- it returns the UTC date, and after 20:00 US-Eastern UTC is already tomorrow. That
439
- exact line stamped a memory entry appended at 22:31 on Aug 31 as `[2026-09-01]`,
440
- and the agent reads those stamps back out of its own prompt — so it saw a fact
441
- dated in the future.
442
-
443
- The reminder failures were a different bug wearing the same clothes, and the
444
- session log settles what it was not. On 2026-08-31 at 22:30 the user asked for a
445
- reminder at 23:00. The agent filed `schedule_create` with `date: "2026-08-29"`,
446
- was rejected with `not_future`, and told the user *"现在已经过了晚上11点"* — at
447
- 22:30. The `request/header` event for that turn shows the system prompt it had:
85
+ ## Limitations
448
86
 
449
- ```
450
- - 现在:2026年8月31日星期一 22:30(America/New_York)
451
- - 今天:2026-08-31 明天:2026-09-01
452
- ```
87
+ - No group chats and no voice messages.
88
+ - One WeChat account per DSH installation.
89
+ - The bot is offline while the computer is off or DSH is not running.
453
90
 
454
- So it was told the right time and used a date from two days earlier — the date of
455
- the **previous exchange**. Two things made that the path of least resistance:
456
-
457
- 1. **Inbound messages carried no timestamps.** `[微信消息] …` and nothing else,
458
- so an old date in the history was the only other temporal signal in context,
459
- and nothing said two days had passed. Messages now carry the local wall clock:
460
- `[微信消息 08-31 22:30] …`.
461
- 2. **The route could not think.** The deployment where this happened pinned a
462
- model whose gateway forces `reasoningEffort: off` whenever tools are
463
- attached, so there was no deliberation step to catch a date that
464
- contradicts the header. Any zero-reasoning route has the same exposure.
465
-
466
- The fix is therefore to state conclusions, not premises. The clock section now
467
- spells out today / tomorrow / the day after with weekdays, names the three dates
468
- as the only ones that may be written, says outright not to copy dates from the
469
- history, and reduces the today-or-tomorrow choice to a comparison against a
470
- printed clock. Rule G5 adds the two tool quirks that turned a wrong date into a
471
- wrong *message*: `not_future` means the date is wrong (not that a time has
472
- passed), and the `scheduledAt` that comes back is UTC and must not be read aloud.
473
-
474
- `scripts/bot-sim.mjs` has four reminder scenarios covering both directions of
475
- that decision plus the genuinely-impossible case, and its `schedule_create` stub
476
- is the live tool's schema and both of its real replies — a stub that took a
477
- free-form `when` string never made the model produce a date at all, which is the
478
- one thing worth testing here.
91
+ ## Working with Claude Code (optional)
479
92
 
480
- ## Limitations
93
+ If you also use Claude Code, the bot can **check what a Claude Code session is doing** or **pass a message to one**.
94
+ A session that is already closed is resumed in the background first. This needs the `claude` CLI on the same machine.
481
95
 
482
- - Group chats are not supported (official channel behaviour).
483
- - Voice messages require a silk transcoder and are not supported.
484
- - One bound WeChat account per state directory. Multiple accounts are tracked
485
- in the store but only the first is monitored.
486
- - Scheduled reminders are session-local: one that comes due while the profile
487
- is not running is delivered, late, at the next start.
488
- - The bridge runs only while the DSH profile process is running. For 24/7
489
- operation keep `dsh web` up (a login item or launchd unit).
490
- - WeChat's own bracket emoji codes (`[捂脸]`) are stripped unconditionally from
491
- outbound text: they are WeChat-internal notation and arrive through this
492
- bridge as literal brackets.
96
+ The plugin also serves a small set of local HTTP routes for an MCP server, so Claude Code can in turn read and drive
97
+ DSH sessions and send you a WeChat notification. The routes listen on localhost only and require a token. If you don't
98
+ need them, turn off **开放 Claude 桥** in the 微信 Bot settings.
493
99
 
494
100
  ## Development
495
101
 
496
102
  ```bash
497
103
  npm install
498
- npm run typecheck # tsc --noEmit
499
- npm run build # tsc → lib/, then copies src/client.js → lib/client.js
500
-
501
- node test/regression.mjs # 70 offline checks, no model calls, no WeChat
502
- node test/claude-peer.mjs # 73 checks against the real ~/.claude
503
- node scripts/bot-sim.mjs # reply-style harness against the real prompt
104
+ npm run build # compile to lib/
105
+ node test/regression.mjs # offline regression checks: no model calls, no network, no WeChat
504
106
  ```
505
107
 
506
- Both suites are offline and cost nothing: no model calls, no network, no WeChat.
507
- They exit non-zero, so either can gate a build.
508
-
509
- `test/regression.mjs` covers the things that used to fail silently: a strip rule
510
- that ate a markdown link, a settings field declared "hot" but only read at boot,
511
- an output schema that rejects a field the attachment store just started
512
- returning, and the bridge invariants above (that `notify` reads no recipient,
513
- that injected messages keep the `clawbot-mcp` source tag, that `mcp/status`
514
- never echoes the token).
515
-
516
- **A hot field must appear as `config.X` in one of the source files that suite
517
- greps** — a field only read inside `apply()` is not hot, whatever `HOT_FIELDS`
518
- claims, and the check enforces that. When adding a source file that reads
519
- settings, add it to that list too.
520
-
521
- `test/claude-peer.mjs` runs the peer tools against the real `~/.claude`, because
522
- the failure mode there is not "it crashed" but "it silently returned nothing" —
523
- a renamed registry key, a changed transcript shape, a stale pid counted as live.
524
- Queue accounting, the idle path and the clock are asserted against a *synthetic*
525
- transcript with known answers, so they do not depend on what the machine happens
526
- to be doing. `send_to_claude_session` is registered but never invoked by the
527
- suite: it spawns a process and delivers into a real live session.
528
-
529
- `scripts/bot-sim.mjs` drives the **real** system prompt and tool list against
530
- scripted turns and prints what WeChat would have received — so a prompt change
531
- can be judged without messaging yourself and without a session reset. It flags
532
- empty-response endings, stacked vision calls, and bracket emoji codes. Add
533
- `--allow-emoji` to exercise the `stripEmoji: false` branch.
534
-
535
- The vendored iLink protocol layer lives in `src/ilink/` (MIT, Tencent); the
536
- DSH integration is `src/bridge.ts`, `src/inbound.ts`, `src/approvals.ts`,
537
- `src/monitor.ts`, `src/questions.ts`, `src/index.ts`.
108
+ `src/ilink/` is the protocol layer ported from Tencent's MIT-licensed
109
+ [`@tencent-weixin/openclaw-weixin`](https://www.npmjs.com/package/@tencent-weixin/openclaw-weixin); the rest is the DSH integration.
538
110
 
539
111
  ## License
540
112
 
541
- MIT. The vendored iLink client is MIT © Tencent — see [`NOTICE`](NOTICE).
113
+ MIT. The ported iLink client is © Tencent, also under the MIT license; see [NOTICE](NOTICE).