wechat-clawbot 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ import { createUserMessage } from "@deepseek-ai/dsh-llm";
2
+ import { SessionId } from "@deepseek-ai/dsh-session";
3
+ import { defineTool } from "@deepseek-ai/dsh-tools";
4
+ import { logger } from "./ilink/util/logger.js";
5
+ import { isSendWindowClosed, oneSentence } from "./backlog.js";
6
+ import { listDshSessions } from "./dsh-sessions.js";
7
+ /** The name every DSH conversation sees. */
8
+ export const NOTIFY_TOOL = "notify_wechat";
9
+ /**
10
+ * Put a copy of an outbound notify into the WeChat session's history.
11
+ *
12
+ * Without this the bot is blind to whatever another agent told the user: reply "那怎么办"
13
+ * to one of these messages and the bot has no idea what "那" refers to.
14
+ *
15
+ * `session.append`, not `followup`: an inbox item starts a turn, and the bot
16
+ * would answer a message that was already sent. `user/message`, not
17
+ * `assistant/message`: the latter carries turn/step bookkeeping that cannot be
18
+ * invented safely. The prefix is what makes it legible, and prompt rule C.6
19
+ * tells the bot what to do with one: already delivered, do not repeat.
20
+ *
21
+ * Best effort: the WeChat message is already out, so a mirroring failure must
22
+ * never turn a delivered notify into a reported failure.
23
+ */
24
+ export function mirrorIntoSession(ctx, sessionId, text, sender, note) {
25
+ try {
26
+ const agent = ctx.agents.get(SessionId(sessionId));
27
+ if (agent === undefined)
28
+ return false;
29
+ const message = createUserMessage({
30
+ // "Claude 发给用户的", but "DSH 会话「X」发给用户的": no space after a closing bracket.
31
+ content: [{ type: "text", text: `[${sender}${sender.endsWith("」") ? "" : " "}发给用户的${note === undefined ? "" : `,${note}`}] ${text}` }],
32
+ // v4 refuses the retired `plugin` wrapper; this is the kind the v3→v4
33
+ // converter assigns this producer, so migrated history matches.
34
+ source: { kind: "plugin:clawbot-mcp" },
35
+ });
36
+ agent.session.append("user/message", message, { surfaceOp: "append" });
37
+ logger.info(`notify: mirrored ${text.length} chars into ${sessionId}`);
38
+ return true;
39
+ }
40
+ catch (err) {
41
+ logger.warn(`notify: mirror failed (message was still delivered): ${String(err).slice(0, 160)}`);
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * Send `text` to the owner. When WeChat will not let the bot write first, keep
47
+ * one sentence for the digest after the owner's next message instead.
48
+ *
49
+ * @param source - who is talking, for the digest ("Claude 的通知").
50
+ * @param origin - which conversation, when there is one worth naming.
51
+ */
52
+ export async function notifyOwner(ctx, deps, input) {
53
+ const account = deps.getAccount();
54
+ if (account === null || !account.configured) {
55
+ return { ok: false, status: 503, message: "no bound WeChat account — run `clawbot login` first" };
56
+ }
57
+ const owner = account.userId;
58
+ if (owner === undefined || owner === "") {
59
+ return { ok: false, status: 503, message: "the bound account has no linked userId; re-run the QR login so it is recorded" };
60
+ }
61
+ const { text, source, origin } = input;
62
+ const sender = origin === undefined ? source : `${source} 会话「${origin}」`;
63
+ try {
64
+ await deps.sendText(owner, text);
65
+ }
66
+ catch (err) {
67
+ if (!isSendWindowClosed(err) || deps.backlog === undefined)
68
+ throw err;
69
+ const given = (input.summary ?? "").trim();
70
+ const summary = given !== "" ? given.slice(0, 120) : oneSentence(text);
71
+ deps.backlog.add(owner, {
72
+ kind: "notice", at: new Date().toISOString(), source, summary,
73
+ ...(origin === undefined ? {} : { origin }),
74
+ });
75
+ logger.info(`notify: WeChat will not let the bot write first now; kept "${summary}" for the owner's next message`);
76
+ const mirrored = mirrorIntoSession(ctx, deps.config.sessionId, text, sender, "暂未送达,对方下次发消息后合并补发");
77
+ return {
78
+ ok: true,
79
+ deferred: true,
80
+ to: owner,
81
+ chars: text.length,
82
+ summary,
83
+ mirrored,
84
+ message: "微信现在不让 bot 主动发消息(机主有一段时间没发消息了)。这条已存下,机主下次发消息、bot 回复之后,"
85
+ + "会和其他没送达的消息按时间合并成一条补发,这条只保留一句:" + summary,
86
+ };
87
+ }
88
+ logger.info(`notify: sent ${text.length} chars to the owner (${sender})`);
89
+ const mirrored = mirrorIntoSession(ctx, deps.config.sessionId, text, sender);
90
+ return { ok: true, to: owner, chars: text.length, mirrored };
91
+ }
92
+ /** A conversation's title, else its folder, else its short id: how the owner will recognise it. */
93
+ async function originOf(ctx, sessionId) {
94
+ try {
95
+ const { rows } = await listDshSessions(ctx);
96
+ const row = rows.find((r) => r.id === sessionId);
97
+ if (row?.title !== undefined)
98
+ return row.title;
99
+ const folder = row?.cwd?.split(/[\\/]/).filter((s) => s !== "").pop();
100
+ if (folder !== undefined)
101
+ return folder;
102
+ }
103
+ catch {
104
+ // fall through to the id
105
+ }
106
+ return sessionId.slice(0, 8);
107
+ }
108
+ const SLOT = Symbol.for("clawbot.notify-wechat");
109
+ const slots = globalThis;
110
+ /**
111
+ * Register `notify_wechat` for every DSH conversation.
112
+ *
113
+ * @param ctx - the plugin's ROOT context: a tool registered there is global.
114
+ */
115
+ export function registerOwnerNotifyTool(ctx, deps) {
116
+ const existing = slots[SLOT];
117
+ if (existing?.registered === true) {
118
+ existing.ctx = ctx;
119
+ existing.deps = deps;
120
+ logger.info(`${NOTIFY_TOOL}: already registered in this process; now served by the newest instance`);
121
+ return;
122
+ }
123
+ const slot = { ctx, deps, registered: false };
124
+ slots[SLOT] = slot;
125
+ const serving = () => slots[SLOT] ?? slot;
126
+ const tool = (defineTool({
127
+ name: NOTIFY_TOOL,
128
+ description: "Send a WeChat message to the owner of this computer (the person who linked the WeChat bot). "
129
+ + "Use it when the owner asked to be told on WeChat, when a long task finishes or fails, or when it "
130
+ + "needs a decision while they are away. Keep it short and self-contained: they read it on their phone "
131
+ + "without this conversation in front of them, so say which task it is about. Do not use it for "
132
+ + "ordinary replies — they are shown here. If WeChat will not let the bot write first right now "
133
+ + "(the owner has been silent for about a day), the message is kept and delivered after their next "
134
+ + "WeChat message; the result says so.",
135
+ parameters: {
136
+ text: { type: "string", required: true, description: "The message, as the owner should read it." },
137
+ summary: {
138
+ type: "string",
139
+ description: "Optional one-sentence version, used if the message has to wait and is folded into a digest.",
140
+ },
141
+ },
142
+ output: {
143
+ schema: {
144
+ type: "object",
145
+ additionalProperties: false,
146
+ properties: {
147
+ ok: { type: "boolean", required: true },
148
+ summary: { type: "string", required: true },
149
+ },
150
+ },
151
+ render: (_args, value) => [{ type: "text", text: value.summary }],
152
+ },
153
+ async execute(args, exec) {
154
+ const { ctx, deps } = serving();
155
+ const { text, summary } = args;
156
+ const body = (text ?? "").trim();
157
+ if (body === "")
158
+ return { ok: false, summary: "消息是空的,没有发送" };
159
+ const caller = String(exec?.agent?.session?.id ?? "");
160
+ if (caller !== "" && caller === deps.config.sessionId) {
161
+ return { ok: false, summary: "这是微信会话本身:直接用 send_wechat_text 回复。" };
162
+ }
163
+ const origin = caller === "" ? undefined : await originOf(ctx, caller);
164
+ try {
165
+ const outcome = await notifyOwner(ctx, deps, {
166
+ text: body,
167
+ ...(typeof summary === "string" ? { summary } : {}),
168
+ source: "DSH",
169
+ ...(origin === undefined ? {} : { origin }),
170
+ });
171
+ if (!outcome.ok)
172
+ return { ok: false, summary: `没发出去:${outcome.message}` };
173
+ if (outcome.deferred === true)
174
+ return { ok: true, summary: outcome.message };
175
+ return { ok: true, summary: `已发到机主微信(${outcome.chars} 字)。` };
176
+ }
177
+ catch (err) {
178
+ logger.warn(`${NOTIFY_TOOL}: ${String(err).slice(0, 200)}`);
179
+ return { ok: false, summary: `没发出去:${String(err).slice(0, 200)}` };
180
+ }
181
+ },
182
+ }));
183
+ const register = () => {
184
+ const off = ctx.tools.register(tool);
185
+ slot.registered = true;
186
+ return () => {
187
+ off();
188
+ // If the host ever does dispose this instance, the next one registers again.
189
+ if (slots[SLOT] === slot)
190
+ slot.registered = false;
191
+ };
192
+ };
193
+ const scoped = ctx;
194
+ if (typeof scoped.effect === "function")
195
+ scoped.effect(register, `clawbot: ${NOTIFY_TOOL}`);
196
+ else
197
+ register();
198
+ logger.info(`${NOTIFY_TOOL}: registered for every DSH conversation except ${deps.config.sessionId}`);
199
+ }
200
+ //# sourceMappingURL=owner-notify.js.map
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
  "name": "wechat-clawbot",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Connect DeepSeek Harness to WeChat via the official WeChat ClawBot (Tencent iLink) bridge — a DSH plugin bundle.",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -1,6 +1,6 @@
1
1
  # wechat-clawbot 安装与排错手册
2
2
 
3
- > **适用版本**:wechat-clawbot **1.0.1**;DeepSeek Harness(DSH)**0.1.7 到 0.2.0**(在 0.1.7-rc.2 和 0.2.0-rc.2 上测过)。
3
+ > **适用版本**:wechat-clawbot **1.1.0**;DeepSeek Harness(DSH)**0.1.7 到 0.2.0**(在 0.1.7-rc.2 和 0.2.0-rc.2 上测过)。
4
4
  >
5
5
  > **写给谁**:一个能执行命令、正在替别人安装 wechat-clawbot 的 AI agent。人看也一样适用。
6
6
  > README 讲「它是什么、怎么用」,这份讲「怎么装好、怎么验收、出了问题怎么查」。
@@ -42,7 +42,7 @@
42
42
  dsh plugin --profile web add wechat-clawbot
43
43
  ```
44
44
 
45
- 也可以在 DSH 网页侧边栏的「插件」→「添加插件」里搜 `wechat-clawbot`(插件页会自动测速,选择更快的 npm 镜像)。要固定版本就写 `wechat-clawbot@1.0.1`。
45
+ 也可以在 DSH 网页侧边栏的「插件」→「添加插件」里搜 `wechat-clawbot`(插件页会自动测速,选择更快的 npm 镜像)。要固定版本就写 `wechat-clawbot@1.1.0`。
46
46
 
47
47
  装完**重启一次 DSH**:插件的服务端代码只在启动时加载。
48
48
 
@@ -90,6 +90,7 @@ startMonitor: no bound account; waiting for `clawbot login`
90
90
  | 设置卡片可用 | 「插件」→ wechat-clawbot → 微信 Bot | 卡片能展开,字段能修改 |
91
91
  | **真实发一条消息** | 让用户在微信里发「在吗」 | **几秒内收到回复** |
92
92
  | **真实设一个提醒** | 让用户设一个两分钟后的提醒 | **提醒出现在微信里**,而不只是出现在网页里 |
93
+ | DSH 会话能发微信(可选) | 在任意一个网页会话里说「用 notify_wechat 给我发条微信:测试」 | 微信里收到这条消息。这一步会用一次模型 |
93
94
 
94
95
  **网页地址**:固定是 `http://127.0.0.1:3080`,但每次启动 DSH 都会生成新的 token,启动输出里有一行完整地址:
95
96
 
@@ -182,10 +183,29 @@ DSH 的默认行为:bot 在哪个项目里干过活,那里的 AGENTS.md / CL
182
183
 
183
184
  具体配置见 README 的「和 Codex 联动」一节。
184
185
 
186
+ ### DSH 会话联动(DSH 内部桥,1.1.0 起)
187
+
188
+ bot 能看到同一个 DSH 里的其他会话,范围是所有工作目录,不只某一个文件夹:
189
+
190
+ - `list_dsh_sessions`:列出会话的标题、所在文件夹、创建时间,以及是否正在运行。
191
+ - `read_dsh_session`:读某个会话最近的消息。
192
+ - `send_to_dsh_session`:往某个会话里捎一句话。没开着的会话会先被唤醒,和在网页里打开它一样。回答留在网页里,不会发到微信。
193
+
194
+ 反过来,每个 DSH 会话都多了一个工具 `notify_wechat`,可以给用户发微信,比如「这个任务做完给我发个微信」。
195
+
196
+ - **全局生效**:所有 DSH 会话都有,不用按文件夹配置,DSH 内部也不需要 MCP。
197
+ - **微信会话自己没有**:它直接回复就行。
198
+ - **发不出去时**:用户一段时间没给 bot 发消息、微信不让 bot 主动发时,这条消息会存着,下次一起补发,并注明是哪个会话发的。
199
+ - **bot 能看到**:bot 自己的对话里也会出现一份,用户可以直接回复。
200
+
201
+ Claude Code 和 Codex 走的是另一条路:本机 HTTP 接口加 MCP server,见下一节。
202
+
185
203
  ### Claude Code 联动
186
204
 
187
205
  bot 可以查看 Claude Code 会话在做什么,也可以给某个会话捎一句话;已经关掉的会话会在后台重新接上。这需要本机装有 `claude` 命令行,并且**保持更新**:它不会跟着桌面版一起升级,版本太旧时会因为不支持当前模型而直接报错,运行 `claude update` 即可。
188
206
 
207
+ 1.1.0 起,插件会自动选用本机版本最新的 `claude`。为了捎话被拉到后台的会话,处理完会自动停掉、交还给桌面版。处理期间桌面版暂时打不开它,急用就在终端运行 `claude stop <会话 id 前 8 位>`。
208
+
189
209
  插件还在本机开了一组 HTTP 接口,配合 MCP server 让 Claude Code 反过来读写 DSH 对话、给用户发微信。接口只监听本机,并且每个请求都要令牌。不需要的话,在设置卡片里关掉「开放 MCP 桥(Claude / Codex)」。
190
210
 
191
211
  ### DSH 的 Session Log 上传(DSH 自己的设置,跟本插件无关,但用户应该知道)
@@ -207,7 +227,7 @@ DSH「设置 → 通用设置」里有一项「在使用官方模型 API 时上
207
227
 
208
228
  ## 8. 升级 DSH
209
229
 
210
- **总原则**:先把 wechat-clawbot 升到最新版,再切换 DSH。1.0.1 已经覆盖下面所有版本的要求。切换后照[第 4 节](#4-验收清单)重新验收一遍。
230
+ **总原则**:先把 wechat-clawbot 升到最新版,再切换 DSH。1.1.0 已经覆盖下面所有版本的要求。切换后照[第 4 节](#4-验收清单)重新验收一遍。
211
231
 
212
232
  用 npx 运行 DSH 时,每个版本装在单独的缓存目录里,旧目录留着就是回滚的退路。
213
233
 
@@ -270,7 +290,7 @@ legacy reminder schedule-7 carried over as schedule-3f2a9c1e-… (due 2026-10-01
270
290
 
271
291
  ### 已知问题
272
292
 
273
- - **DSH 0.2.1 预览版(截至 0.2.1-alpha.2)**:设定时提醒的工具(`schedule_create` 等)从 `@deepseek-ai/dsh-schedule` 挪到了新包 `@deepseek-ai/dsh-tool-schedule`,而 wechat-clawbot 1.0.1 只加载前者。插件本身能正常加载,但 bot **无法设定时提醒**,而且不会报错。在 wechat-clawbot 适配之前,请继续使用 0.2.0。
293
+ - **DSH 0.2.1 预览版(截至 0.2.1-alpha.2)**:设定时提醒的工具(`schedule_create` 等)从 `@deepseek-ai/dsh-schedule` 挪到了新包 `@deepseek-ai/dsh-tool-schedule`,而 wechat-clawbot 1.1.0 只加载前者。插件本身能正常加载,但 bot **无法设定时提醒**,而且不会报错。在 wechat-clawbot 适配之前,请继续使用 0.2.0。
274
294
 
275
295
  ---
276
296
 
@@ -279,7 +299,7 @@ legacy reminder schedule-7 carried over as schedule-3f2a9c1e-… (due 2026-10-01
279
299
  | 症状 | 原因与处理 |
280
300
  |---|---|
281
301
  | 日志 `N entries did not activate` 加 `clawbot (…): failed to import` | 插件太旧,用到了当前 DSH 已经删除的接口。升到最新版 |
282
- | 日志 `skipping profile bundle "wechat-clawbot": … incompatible with dsh …` | 版本门禁:插件声明的范围不包含当前 DSH 版本。1.0.1 支持 0.1.7 到 0.2.0;DSH 更旧或更新时要先换 DSH 版本 |
302
+ | 日志 `skipping profile bundle "wechat-clawbot": … incompatible with dsh …` | 版本门禁:插件声明的范围不包含当前 DSH 版本。1.1.0 支持 0.1.7 到 0.2.0;DSH 更旧或更新时要先换 DSH 版本 |
283
303
  | 网页只剩「Failed to load plugins」,下面列着 `pending (waiting for service: X)` | 某个插件(不一定是本插件)的浏览器端依赖了当前版本没有的服务 X。升级或禁用那个插件 |
284
304
  | 网页只有一行 401 文本 | 打开时没带 token,不是故障,见第 4 节 |
285
305
  | `POST` 某个接口回 405 | 那条路由根本没有注册(401 才是「路由在,但没通过认证」) |
@@ -297,6 +317,8 @@ legacy reminder schedule-7 carried over as schedule-3f2a9c1e-… (due 2026-10-01
297
317
  | 在 DSH 0.2.1 预览版上 bot 设不了提醒 | 见[已知问题](#已知问题) |
298
318
  | Codex 工具报「Cannot connect to the shared Codex App Server」 | `socket` 模式找不到共享服务(桌面版的服务是私有的)。见第 6 节的 Codex 部分 |
299
319
  | 让 bot 给 Claude Code 会话捎话失败,报模型不受支持 | `claude` 命令行太旧,运行 `claude update` |
320
+ | 桌面版打不开某个 Claude Code 会话,提示 Claude Code crashed | bot 刚把它拉到后台处理捎去的话,处理完会自动交还;急用就运行 `claude stop <会话 id 前 8 位>` |
321
+ | 网页里的 DSH 会话说没有 `notify_wechat` 工具 | 插件早于 1.1.0,或者升级后还没重启 DSH |
300
322
 
301
323
  ---
302
324