wechat-clawbot 0.9.4 → 0.9.6

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