wechat-clawbot 0.9.1 → 0.9.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/INSTALL.md ADDED
@@ -0,0 +1,171 @@
1
+ # 安装手册(写给替用户装这个插件的 AI 看)
2
+
3
+ > 读者假设:你是一个能跑命令的 agent,正在替某个人把 `wechat-clawbot` 装进他的
4
+ > DeepSeek Harness。README 讲的是「这插件是什么」,这份讲的是「怎么装成,以及
5
+ > 装不成时那个报错到底在说什么」。
6
+ >
7
+ > 每一条症状都是真出过的,不是设想出来的。
8
+
9
+ ---
10
+
11
+ ## 0. 先确认三件事,再动手
12
+
13
+ | 要确认的 | 怎么查 | 不满足会怎样 |
14
+ |---|---|---|
15
+ | DSH 版本 | `npx @deepseek-ai/dsh --version` | 这个插件按 **0.1.5** 的 API 写。更老的宿主上,客户端模块表里没有 `@deepseek-ai/dsh-client-store`,插件的浏览器那半边加载失败 |
16
+ | profile 里有没有别的插件占了 `userQuestions` | 见下面第 2 步 | **整棵插件树加载失败,`dsh` 直接 exit(1)** |
17
+ | 包管理器 | `pnpm --version` | `dsh plugin add` 走 pnpm |
18
+
19
+ **一句最重要的话**:在 DSH 里,**一个插件出问题不是「这个插件不工作」,而是整个
20
+ harness 起不来**。所以每一步之后都要看 exit code,别装完一路点到底。
21
+
22
+ ---
23
+
24
+ ## 1. 装
25
+
26
+ ```bash
27
+ dsh plugin --profile web add wechat-clawbot
28
+ ```
29
+
30
+ 装完**先不要急着重启**,先做第 2 步。
31
+
32
+ ---
33
+
34
+ ## 2. `forwardQuestions: false` —— 这一行不写,harness 起不来
35
+
36
+ DSH **每个 context 只允许一个 `userQuestions` provider**,而官方 web profile 里
37
+ `dsh-host-apiproxy` 已经注册了一个。这个插件如果也去注册(`forwardQuestions`
38
+ 默认行为),加载期就会冲突,**`dsh` exit(1)**,而且报错不会直说是这两个在抢。
39
+
40
+ 所以在 profile 的 `~/.dsh/profiles/web/cordis.patch.yml` 里显式关掉:
41
+
42
+ ```yaml
43
+ - id: clawbot
44
+ config:
45
+ forwardQuestions: false
46
+ ```
47
+
48
+ ⚠️ **这个用户层 patch 会整块替换 bundle 层的 config**,所以插件自带的
49
+ `forwardQuestions: false` 不会被继承 —— 你在这里写了别的字段,就必须把这一行
50
+ 一起写上。这是最容易漏的一处。
51
+
52
+ ---
53
+
54
+ ## 3. 起一次,看 exit code
55
+
56
+ ```bash
57
+ dsh web # 或者你的守护方式
58
+ echo "exit=$?"
59
+ ```
60
+
61
+ - **exit 0 / 正常监听** → 继续
62
+ - **exit 1** → 看输出里 `failed to import loader entry <id> (<包名>)`,那一行点名了
63
+ 是谁。常见两类:版本不匹配的第三方插件(`does not provide an export named
64
+ 'X'`),或者上面那条 `userQuestions` 冲突。
65
+
66
+ **服务端干净不代表能用**:客户端 bundle 是浏览器加载时才求值的。所以——
67
+
68
+ ## 4. 一定要在浏览器里真打开一次
69
+
70
+ ```bash
71
+ # 地址固定 127.0.0.1:3080,但 URL 里的 token 每次重启都变,
72
+ # 取当前这次的:
73
+ grep -o 'http://127.0.0.1:3080/?token=[A-Za-z0-9_-]*' ~/.dsh/logs/dsh-web.out.log | tail -1
74
+ ```
75
+
76
+ 页面只显示一行 **「Failed to load plugins」** 就是客户端模块没加载成功——常见原因是
77
+ 插件 require 了一个这一版宿主模块表里不存在的名字。客户端 bundle **没有隔离**,
78
+ 一个异常会把整页打掉,不只是这个插件的 UI。
79
+
80
+ 没有 token 的裸地址在 DSH 0.1.5 上一律回 **401**(`dsh web authentication
81
+ required`)——那不是坏了,是还没换 cookie。换过一次之后 30 天内有效。
82
+
83
+ ---
84
+
85
+ ## 5. 绑定微信(一次性,要人操作)
86
+
87
+ 扫码登录必须由**本人**完成,agent 不要代劳、也不要碰对方的凭据。让用户自己扫,
88
+ 绑定结果落在 `~/.dsh/clawbot/accounts/`。
89
+
90
+ 绑定之后默认**只有扫码的那个人**能给 bot 发消息(白名单)。要加人用 `allowFrom`。
91
+
92
+ ---
93
+
94
+ ## 6. 选模型,以及两个会烧钱的坑
95
+
96
+ 这两条不是这个插件特有的,但这个插件最容易踩,因为它每一轮都带一份完整的系统
97
+ 提示词 + 工具定义(这台机器上实测约 17.7k token 的固定开销)。
98
+
99
+ **坑一:提示词里放会变的东西 = 缓存全灭。**
100
+ 如果提示词里有每轮都变的字符(时钟带秒、随机 id),支持前缀缓存的模型(DeepSeek
101
+ 这类)会**从那个字符开始整段按未命中计价**。实测过一次:命中率 1%,一轮 29 步的
102
+ 对话累计 928 万 input token,约 ¥10 一轮。
103
+
104
+ **坑二:改成 `systemPromptUpdate: "in-history"` 之后,同一个毛病换个姿势咬人。**
105
+ 那个模式下「提示词变了」不是就地改写,而是**把整份追加进历史**。时钟带秒 = 每一步
106
+ 往历史里塞一份完整提示词。实测 14 轮 / 35 步塞了 35 份 24KB,上下文 519k 而真实
107
+ 对话只有 54k。
108
+
109
+ **结论**:系统提示词必须**一天之内逐字节不变**,易变的东西放最新那条消息里。这个
110
+ 插件现在就是这么做的(入站消息带 `[微信消息 MM-DD HH:mm]`),你**不要**往提示词
111
+ 里加时钟、计数器之类的东西。
112
+
113
+ 思考档位:日常聊天用 `low` 就够(实测闲聊轮思考 0–220 token)。会用到定时提醒的话
114
+ 不建议关——关了之后模型会从历史消息里抄日期,把提醒设到过去的某天。
115
+
116
+ ---
117
+
118
+ ## 7. `autoMemory` 要不要开:这是用户的决定,不是你的
119
+
120
+ 默认 **关**。开了之后,**看起来像个人信息的短消息会被原文发给模型**做分类。
121
+
122
+ **0.9.3 起,那个模型就是这个会话本来就在用的模型**(走宿主 `llm` 服务 +
123
+ `currentRoute()`),所以**不再有额外的数据去向**。0.9.2 及以前是写死发到
124
+ `api.deepseek.com`、用插件自己读出来的 `DEEPSEEK_API_KEY` —— 那才是第二个去向,
125
+ 而且把 bot 换到别的 provider 并不会把分类器一起搬走,换模型反而让分裂更严重。
126
+
127
+ 即便如此**默认仍然是关的**:被挑出去的恰好是一段聊天里最敏感的那部分,
128
+ 「要不要为此多发一次请求」是用户自己的决定。**替用户打开它仍然是越界**。
129
+ 要开就让他自己在 设置 → 插件 → 微信 Bot 里开(热生效)。关着不影响
130
+ `remember_user_info`。
131
+
132
+ ---
133
+
134
+ ## 8. 装完的验收清单
135
+
136
+ | 查什么 | 命令 / 位置 | 期望 |
137
+ |---|---|---|
138
+ | 服务活着 | `lsof -nP -iTCP:3080 -sTCP:LISTEN` | 有 LISTEN |
139
+ | 插件加载了 | 日志里 `startMonitor: monitoring account=…` | 有 |
140
+ | 微信通道通了 | 日志里 `monitor started baseUrl=https://ilinkai.weixin.qq.com` | 有 |
141
+ | 网页能开 | 带 token 打开 | 不是「Failed to load plugins」 |
142
+ | 设置卡在 | 设置 → 插件 → 微信 Bot | 卡片能展开、字段能填 |
143
+ | **真发一条微信** | 让用户发「在吗」 | **几秒内收到回复** |
144
+
145
+ 最后一行不能省。前五行全绿而最后一行不通的情况是存在的——目录干净 ≠ 真实路径能跑。
146
+
147
+ ---
148
+
149
+ ## 9. 症状 → 原因速查
150
+
151
+ | 症状 | 多半是 |
152
+ |---|---|
153
+ | `dsh` exit(1),`failed to import loader entry` | 第三方插件按老 API 编译;或 `userQuestions` 冲突(见第 2 步) |
154
+ | 网页整页「Failed to load plugins」 | 某个插件的客户端 bundle require 了这一版没有的模块名 |
155
+ | 网页一行 401 文本 | 没带 token(第 4 步),不是坏了 |
156
+ | `POST /<通道>/<端点>` 回 **405** | 那条路由**根本没注册**(不是没权限)。401 才是「路由在、没 cookie」 |
157
+ | bot 收到消息但不回 | 看它是不是只输出了文本没调 `send_wechat_text`——这个插件里**纯文本输出永远不会到达微信** |
158
+ | bot 回复很慢(20 秒+) | 多半在连着搜网 / 抓页面;也可能是上下文被撑大了(见第 6 步) |
159
+ | 定时提醒迟到 | 机器睡着了。提醒的定时器活在进程里,进程冻结就不会响,醒来才补发 |
160
+
161
+ ---
162
+
163
+ ## 10. 给 agent 的三条纪律
164
+
165
+ 1. **不要替用户输密码、扫码、填 OTP。** 绑定微信、`npm login`、2FA 验证码,全都
166
+ 让本人做。
167
+ 2. **不要替用户打开 `autoMemory`**(它会拿用户消息多发一次判定请求;
168
+ 0.9.3 起去向和对话一致,但那仍是用户自己的决定),也不要把他的
169
+ key 复制到任何新文件里——要用就运行时从 `~/.dsh/.credentials.yaml` 读。
170
+ 3. **改完配置要验真实路径**,别停在「目录/设置页看着正常」。这个插件的历史故障
171
+ 里,有一半是「看着全对,一发消息就炸」。
package/README.md CHANGED
@@ -2,7 +2,14 @@
2
2
 
3
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.
4
4
 
5
- > **Status: v0.9.0** — 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. Group chats are not supported.
5
+ > **Status: v0.9.3** — 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.3:** the auto-memory classifier now 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**.
6
13
 
7
14
  ## How it works
8
15
 
@@ -102,6 +109,41 @@ Environment:
102
109
  sensitive operations still require your explicit reply in WeChat. Other
103
110
  sessions (e.g. the local web GUI) keep their own policy.
104
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).
105
147
 
106
148
  ## Configuration reference
107
149
 
@@ -120,6 +162,7 @@ Environment:
120
162
  | `apiBaseUrl` | string | `https://ilinkai.weixin.qq.com` | iLink API base (override for testing) |
121
163
  | `logLevel` | `debug\|info\|warn\|error` | `info` | protocol log level |
122
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** |
123
166
  | `noticeMinBytes` | number | `2097152` | announce a file before upload only above this size; `0` = always |
124
167
  | `attachImages` | boolean | `true` | give images to the model directly when the route accepts them |
125
168
  | `provider` | string | — | pin this session's provider; empty = follow the deployment default |
@@ -203,7 +246,7 @@ Three properties are load-bearing and covered by tests:
203
246
  `mcpBridge: false` makes all four return 403 while leaving them registered: the
204
247
  flag is read per request, so it is a live kill switch in both directions.
205
248
 
206
- ### Inward: three tools — DSH sees and steers Claude Code
249
+ ### Inward: three tools — DSH sees and steers Claude Code (open or closed)
207
250
 
208
251
  Registered on the WeChat agent (`restrictTools` is a **deny** list, so they need
209
252
  no allowlisting): `list_claude_sessions`, `read_claude_session`,
@@ -229,10 +272,136 @@ claude -p "<deliver X to session Y>" --allowed-tools ListAgents,SendMessage --mo
229
272
  and lets Claude Code do the socket work with its own implementation — protocol
230
273
  changes stay Anthropic's to keep working. Verified end to end.
231
274
 
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.
280
+
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:
283
+
284
+ ```sh
285
+ claude -p "<the message>" --resume <sessionId> --allowed-tools Read,Grep,Glob
286
+ ```
287
+
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
+ ```
327
+
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.
334
+
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:
337
+
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:
378
+
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
+ ```
386
+
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
+
232
401
  Four things learned the hard way, all of them now pinned by tests:
233
402
 
234
403
  - **Session names drift.** One session was observed renaming itself
235
- `harvard-96` → `harvard-35` → `harvard-ef` inside a day. So the name is
404
+ `proj-96` → `proj-35` → `proj-ef` inside a day. So the name is
236
405
  resolved fresh on every send, never cached, and an ambiguous handle is an
237
406
  error rather than a guess.
238
407
  - **Success needs an anchored match.** A bare `/sent/i` scores Claude Code's own
@@ -260,6 +429,52 @@ to be prompt. A live answer would need the peer socket.
260
429
  > `toLocaleTimeString`, never by slicing the ISO string — `"…T20:33:05Z"
261
430
  > .slice(11,16)` reported a 16:33 message as 20:33.
262
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:
446
+
447
+ ```
448
+ - 现在:2026年8月31日星期一 22:30(America/New_York)
449
+ - 今天:2026-08-31 明天:2026-09-01
450
+ ```
451
+
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.
477
+
263
478
  ## Limitations
264
479
 
265
480
  - Group chats are not supported (official channel behaviour).
@@ -281,8 +496,8 @@ npm install
281
496
  npm run typecheck # tsc --noEmit
282
497
  npm run build # tsc → lib/, then copies src/client.js → lib/client.js
283
498
 
284
- node test/regression.mjs # 55 offline checks, no model calls, no WeChat
285
- node test/claude-peer.mjs # 29 checks against the real ~/.claude
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
286
501
  node scripts/bot-sim.mjs # reply-style harness against the real prompt
287
502
  ```
288
503
 
package/README.zh.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  把 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)profile 通过微信官方 **微信ClawBot**(腾讯 iLink API)接入你的微信。绑定后,你可以在外面用微信给 DSH agent 发消息——让它查看电脑上的文件、帮你编辑、执行命令——agent 会把结果(包括权限确认问题)直接回发到微信对话里。
4
4
 
5
- > **状态:v0.5.0** — 文本消息 + **agent → 微信 文件/图片发送**(`send_wechat_file`,发原图)+ **微信图片/文件入站**(解密落盘、可识图)+ **引用消息解析** + 识图前自动预览加速 + 微信对话规范 prompt(先确认、结尾一次归纳)。群聊暂不支持。
5
+ > **状态:v0.9.3** — 文本双向;**原生识图**(入站照片直接进模型自己的消息,`look_at_image` 把本地图直接递给它——不用第二个视觉模型、不多一次往返);agent → 微信 文件/图片发送;引用消息解析;长期记忆;定时提醒;设置 → 插件 里的设置卡(字段热生效);以及插件自己钉模型(网页里换模型不再动 bot)。**0.9.3:自动记忆的判定改成走本会话自己的路由,不再写死厂商。**不支持群聊。
6
+
7
+ > **从 0.9.1 升上来的注意**:有一处行为是故意改的——自动记忆现在受 `autoMemory` 控制,**默认关闭**。0.9.2 之前它无条件运行,会把匹配到的消息原文发给 `api.deepseek.com`;那是你配置的模型之外的第二个数据去向。**0.9.3 起它改成跟着 bot 自己的路由走**,不再是单独的厂商跳转。要不要开仍然由你决定 —— 细节见**安全**一节。
6
8
 
7
9
  ## 工作原理
8
10
 
@@ -91,6 +93,34 @@ clawbot logout # 解除绑定并删除凭据
91
93
  - **审批**:微信会话审批策略为 `ask`,敏感操作仍需你在微信里明确回复。其他会话
92
94
  (如本机 Web GUI)保持各自的策略。
93
95
  - 陌生人的消息会被静默忽略。
96
+ - **你的消息会去哪。** 正常情况下只去一个地方:你的 DSH 给微信会话配的那个模型。
97
+ 只有一个可选的例外,而且**默认是关的** —— 见下。
98
+
99
+ ### 自动记忆会把文字发给第二家(需自行开启,`autoMemory`)
100
+
101
+ 开启 `autoMemory: true` 后,匹配到「像是长期个人事实」的短消息("我住在…" / "我不能喝
102
+ 咖啡"这类)会被**原文**发给一个模型做判定,决定要不要写进长期记忆文件。
103
+
104
+ **0.9.3 起,这个模型就是你的 bot 正在用的那个。** 判定走宿主自己的 `llm` 服务、跟着本
105
+ 会话的路由,因此自动继承你的 provider、模型和凭证。
106
+
107
+ 0.9.3 之前它是写死 POST 到 `https://api.deepseek.com/chat/completions`,用硬编码的
108
+ `deepseek-chat`,密钥直接从 `~/.dsh/.credentials.yaml` 里读 `DEEPSEEK_API_KEY`。那是
109
+ **第二个数据去向**:把 bot 指向本地模型或学校网关,微信文本照样发去 DeepSeek —— 而且
110
+ 一换 provider,这个分裂只会更严重。这一跳现在没有了。
111
+
112
+ 还有两点需要说清楚:
113
+
114
+ - 触发条件挑的是**「看起来像个人事实」的短消息**,那恰恰是一段聊天里最敏感的部分,
115
+ 不是随机抽样。它们现在只去你对话本来就会去的地方,但确实会去。
116
+ - 如果路由解析不出来(这套组合里没有 `llm` 服务),分类器会**直接跳过**,
117
+ 而不是退回去找别的厂商。
118
+
119
+ **默认仍然是 `false`**,因为「对你自己的文本多发一次请求」依然该由你决定。关掉不损失
120
+ 任何结构性能力:`remember_user_info` 照常工作,只是由 agent 自己判断,而不是问一个
121
+ 便宜的分类器。
122
+
123
+ 在 设置 → 插件 → 微信 Bot 里设 `autoMemory: true` 即可(热生效,不用重启)。
94
124
 
95
125
  ## 配置项
96
126
 
package/lib/bridge.d.ts CHANGED
@@ -176,6 +176,23 @@ export declare class WechatBridge {
176
176
  */
177
177
  reportVisionReadiness(): Promise<void>;
178
178
  private llmService;
179
+ /**
180
+ * A `MemoryJudge` bound to **this session's own route**.
181
+ *
182
+ * Auto-memory used to POST straight to `api.deepseek.com` with a hardcoded
183
+ * model and key. That was a second data destination, and switching the bot
184
+ * to another provider made it worse rather than better: the conversation
185
+ * moved, the personal-looking snippets did not. Going through the host
186
+ * `llm` service fixes that for free — the service already owns baseURL,
187
+ * credential lookup, and the wire format (this route speaks
188
+ * `openai-responses`, DeepSeek speaks `openai-completions`; neither shape
189
+ * belongs in this plugin).
190
+ *
191
+ * Returns undefined when the service is absent or the route is unresolved;
192
+ * the caller then skips classification rather than reaching for a fallback
193
+ * vendor.
194
+ */
195
+ private memoryJudge;
179
196
  /**
180
197
  * The provider/model this session will actually route to.
181
198
  *
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAEL,KAAK,KAAK,EAIX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGtE,MAAM,MAAM,UAAU,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,UAAU,GAAG;IACvB,qEAAqE;IACrE,UAAU,EAAE,MAAM,qBAAqB,GAAG,IAAI,CAAC;IAC/C,6DAA6D;IAC7D,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C,2DAA2D;IAC3D,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;IACnE,K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