wechat-clawbot 1.1.0 → 1.2.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.
- package/README.md +19 -0
- package/README.zh.md +19 -0
- package/lib/bridge.d.ts +23 -0
- package/lib/bridge.d.ts.map +1 -1
- package/lib/bridge.js +128 -2
- package/lib/bridge.js.map +1 -1
- package/lib/client.js +165 -1
- package/lib/config.d.ts +31 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +41 -0
- package/lib/config.js.map +1 -1
- package/lib/dsh-sessions.d.ts.map +1 -1
- package/lib/dsh-sessions.js +2 -1
- package/lib/dsh-sessions.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +67 -0
- package/lib/index.js.map +1 -1
- package/lib/instance-guard.d.ts.map +1 -1
- package/lib/instance-guard.js +32 -7
- package/lib/instance-guard.js.map +1 -1
- package/lib/mac-calendar.d.ts +124 -0
- package/lib/mac-calendar.d.ts.map +1 -0
- package/lib/mac-calendar.js +883 -0
- package/lib/mac-calendar.js.map +1 -0
- package/lib/memory.d.ts.map +1 -1
- package/lib/memory.js +12 -1
- package/lib/memory.js.map +1 -1
- package/lib/secretary.d.ts +27 -0
- package/lib/secretary.d.ts.map +1 -0
- package/lib/secretary.js +175 -0
- package/lib/secretary.js.map +1 -0
- package/native/macos-calendar/main.swift +543 -0
- package/package.json +2 -1
- package/wechat-clawbot-INSTALL.md +56 -1
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ English | [中文](README.zh.md)
|
|
|
5
5
|
Chat with the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH) agent on your computer from WeChat.
|
|
6
6
|
Clawbot is a DSH plugin and fully open source. It replies with the AI you use in DSH and does not upload your information.
|
|
7
7
|
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.
|
|
8
|
+
It can also plan your days from the system calendar and create events for you (macOS only).
|
|
8
9
|
|
|
9
10
|
It uses WeChat's official **微信ClawBot** channel: just scan a QR code to log in.
|
|
10
11
|
|
|
@@ -21,6 +22,18 @@ After nearly two months of development and real-world use, `wechat-clawbot` has
|
|
|
21
22
|
- **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`)
|
|
22
23
|
- **Understands quotes**: reply to an older message with WeChat's quote feature and it knows which one you mean
|
|
23
24
|
- **Long chats stay quick**: when the conversation gets long, it tidies older messages into a summary during a quiet spell after a reply, so your next message never waits for it
|
|
25
|
+
- **Schedule secretary (macOS only, off until you turn it on)**: plans your days and creates events from the Mac's calendar, with the default rules or your own.
|
|
26
|
+
|
|
27
|
+
## Schedule secretary: plan your days from WeChat (new; macOS only, off until you turn it on)
|
|
28
|
+
|
|
29
|
+
- **Sees your whole schedule**: reads every account in the Mac Calendar app (iCloud, Google, Exchange, subscribed calendars), notes included. Ask "am I free tomorrow afternoon?" and it checks the calendar before answering.
|
|
30
|
+
- **Plans straight into your calendar**: tell it "the report is due Thursday and I still have two papers to read". It finds free time, puts the work into **a dedicated calendar you name yourself**, and replies in a few lines: what happens when, what got moved, where things clash. The calendar is created in iCloud when you have it, so the events show up on your phone too, and it still reminds you on WeChat when it's time.
|
|
31
|
+
- **Acts on its own calendar only**: it adds, changes and deletes events in the dedicated calendar by itself. Anything in your other calendars, it asks you on WeChat first and waits for a yes.
|
|
32
|
+
- **Reminders stay reminders**: a plain "remind me to…" becomes a WeChat reminder and stays out of the calendar. Only things that take up time go into the calendar.
|
|
33
|
+
- **Your rules**: how it plans is written in the `## 日程秘书` section of your long-term memory file, `memory.md`. Edit it however you like: the **打开 memory.md** button in the settings opens it.
|
|
34
|
+
|
|
35
|
+
This feature is **macOS only** and **off by default**. To turn it on: in the DSH web UI, open Plugins → wechat-clawbot → 微信 Bot. Under **Mac 日历**, type a name for the dedicated calendar, switch it on, and click "Allow" once on the Mac when it asks for calendar access. Then switch on **日程秘书**.
|
|
36
|
+
The first time, the plugin compiles a small background app, `Clawbot-Calendar`, on your Mac. This needs the Xcode command line tools (`xcode-select --install` if you don't have them).
|
|
24
37
|
|
|
25
38
|
## Cost
|
|
26
39
|
|
|
@@ -31,6 +44,7 @@ After nearly two months of development and real-world use, `wechat-clawbot` has
|
|
|
31
44
|
- DSH **0.1.7 – 0.2.0** (tested on 0.1.7-rc.2 and 0.2.0-rc.2), Node.js 22+ and pnpm
|
|
32
45
|
- The official **微信ClawBot** plugin in the WeChat mobile app (WeChat → Settings → Plugins; the first scan may ask you to update WeChat)
|
|
33
46
|
- A computer that stays on: the bot is online while DSH is running
|
|
47
|
+
- For the Mac calendar and the schedule secretary: macOS and the Xcode command line tools (`xcode-select --install` if you don't have them)
|
|
34
48
|
|
|
35
49
|
## Set up in three steps
|
|
36
50
|
|
|
@@ -71,6 +85,9 @@ Open **Plugins → wechat-clawbot → 微信 Bot** in the DSH web sidebar. Chang
|
|
|
71
85
|
- **把工作目录的说明文件交给 bot** (workspace instruction files): on by default (DSH's own behaviour: once the bot works in a project, its AGENTS.md / CLAUDE.md is put into the chat, and the whole file again after every edit). Off keeps them out of the WeChat session, which helps when those files are long and change often; the bot can still read them when it needs to.
|
|
72
86
|
- **开放 MCP 桥(Claude / Codex)** (MCP bridge): see the integrations below.
|
|
73
87
|
- **Codex 会话联动**: select a Codex project and conversation, relay a message, or query progress. Off by default; when on, every request carries 5 more tools (about 1k tokens). Changing it restarts the WeChat listener.
|
|
88
|
+
- **Mac 日历** (Mac calendar; macOS only, off by default): type the dedicated calendar's name first, then switch it on. Changing it restarts the WeChat listener.
|
|
89
|
+
- **日历提醒** (calendar alerts): events the bot adds get an alert 10 minutes before by default. Switch it off or change the minutes.
|
|
90
|
+
- **日程秘书** (schedule secretary): needs the Mac calendar on. Switching it on writes the planning rules into `memory.md`; switching it off moves them out and keeps a copy, which comes back unchanged next time. The **打开 memory.md** button next to it opens the file on the Mac.
|
|
74
91
|
|
|
75
92
|
A few options (the session id, the working directory, whether to start with DSH) live in the `- id: clawbot` entry of
|
|
76
93
|
`~/.dsh/profiles/web/cordis.patch.yml`. Changing them restarts the WeChat listener automatically.
|
|
@@ -83,6 +100,7 @@ A few options (the session id, the working directory, whether to start with DSH)
|
|
|
83
100
|
- **Auto-memory** (on by default): short messages that look like lasting facts ("I don't drink coffee") get a second
|
|
84
101
|
question to **the same model**: should this be remembered? To turn it off, add `autoMemory: false` to the `clawbot`
|
|
85
102
|
entry in `cordis.patch.yml`. It takes effect on the next message.
|
|
103
|
+
- **Mac calendar** (off by default): when the bot looks at your calendar, the events it reads (notes included) go to the model. Only you can use the calendar; while anyone else is on the allow list, the calendar tools are not offered at all.
|
|
86
104
|
- The WeChat link and the long-term memory are stored on your computer, under `~/.dsh/clawbot/`.
|
|
87
105
|
|
|
88
106
|
## FAQ
|
|
@@ -102,6 +120,7 @@ It is written for an AI agent installing the plugin for you, and it works just a
|
|
|
102
120
|
- No group chats and no voice messages.
|
|
103
121
|
- One WeChat account per DSH installation.
|
|
104
122
|
- The bot is offline while the computer is off or DSH is not running.
|
|
123
|
+
- The Mac calendar and the schedule secretary work on macOS only.
|
|
105
124
|
|
|
106
125
|
## Working with Claude Code (optional)
|
|
107
126
|
|
package/README.zh.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
在微信里和你电脑上的 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)助手聊天。
|
|
6
6
|
Clawbot 作为 DSH 插件,完全开源,使用 DSH 的 AI 进行回复,不会上传用户信息。
|
|
7
7
|
出门在外也能让它查文件、改文档、跑命令,结果直接回到微信对话里。
|
|
8
|
+
根据系统日历帮你规划、创建日程(仅限 macOS)。
|
|
8
9
|
|
|
9
10
|
它走的是微信官方的 **微信ClawBot** 通道,扫码登录即可。
|
|
10
11
|
|
|
@@ -21,6 +22,18 @@ Clawbot 作为 DSH 插件,完全开源,使用 DSH 的 AI 进行回复,不
|
|
|
21
22
|
- **先问再做**:需要你授权的操作(比如动工作目录以外的文件),会先在微信里问你,回「同意」或「拒绝」即可
|
|
22
23
|
- **看得懂引用**:引用一条旧消息回复,它知道你在说哪条
|
|
23
24
|
- **聊得越久也不变慢**:回复结束、安静一阵之后,对话太长就趁空闲把旧内容整理成摘要,你下一条消息来时不用等
|
|
25
|
+
- **日程秘书(仅 macOS,需手动开启)**:自定义或使用默认规则,根据 Mac 系统日历帮你规划、创建日程。
|
|
26
|
+
|
|
27
|
+
## 日程秘书:在微信里排日程(新功能,仅 macOS,需手动开启)
|
|
28
|
+
|
|
29
|
+
- **看得到你所有的日程**:读取 Mac「日历」里所有账户的日程,iCloud、Google、Exchange、订阅日历都行,备注也看得到。问它「明天下午有空吗」,它查过日历再回答。
|
|
30
|
+
- **直接排进日历**:跟它说「周四前要交报告,还得看完两篇文献」,它先找空档,排进一个**你自己命名的专用日历**,再用几行告诉你:几点做什么、挪走了什么、哪里有冲突。专用日历优先建在 iCloud,手机上同步可见;到点还会在微信里提醒你。
|
|
31
|
+
- **只在自己的日历里动手**:专用日历里的日程它自己加、改、删;要动你其他日历里的日程,会先在微信里问你,你回「好」才做。
|
|
32
|
+
- **提醒和日程分得清**:只说「提醒我…」的事只发微信提醒,不占日历;要占一段时间的事才排进日历。
|
|
33
|
+
- **排法你说了算**:排日程的规则写在长期记忆 `memory.md` 的「## 日程秘书」一节里,想怎么排就怎么改:设置里点「打开 memory.md」就能直接编辑。
|
|
34
|
+
|
|
35
|
+
这个功能**只支持 macOS**,而且**默认关闭**,要自己打开:在 DSH 网页「插件」→ wechat-clawbot → 微信 Bot 里,先在「Mac 日历」填一个专用日历的名字、打开开关,在 Mac 上点一次「允许」访问日历;再打开「日程秘书」。
|
|
36
|
+
第一次打开时,插件会在本机编译一个后台小程序 `Clawbot-Calendar`,需要 Xcode 命令行工具(没有的话运行 `xcode-select --install`)。
|
|
24
37
|
|
|
25
38
|
## 成本
|
|
26
39
|
|
|
@@ -31,6 +44,7 @@ Clawbot 作为 DSH 插件,完全开源,使用 DSH 的 AI 进行回复,不
|
|
|
31
44
|
- DSH **0.1.7 到 0.2.0**(在 0.1.7-rc.2 和 0.2.0-rc.2 上测过),以及 Node.js 22+、pnpm
|
|
32
45
|
- 手机微信里能用官方「**微信ClawBot**」插件(微信 → 设置 → 插件;第一次扫码时可能会提示升级微信)
|
|
33
46
|
- 一台一直开着的电脑:DSH 在运行,bot 才在线
|
|
47
|
+
- 想用 Mac 日历和日程秘书的话:macOS,以及 Xcode 命令行工具(没有的话运行 `xcode-select --install`)
|
|
34
48
|
|
|
35
49
|
## 三步装好
|
|
36
50
|
|
|
@@ -71,6 +85,9 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
71
85
|
- **把工作目录的说明文件交给 bot**:默认开(DSH 原样:bot 在哪个项目里干过活,那里的 AGENTS.md / CLAUDE.md 就会塞进对话,文件每改一次再塞一整份)。关掉则微信会话里不再自动塞,适合说明文件很长、又经常改的人;需要时让 bot 自己去读。
|
|
72
86
|
- **开放 MCP 桥(Claude / Codex)**:见下面的联动说明。
|
|
73
87
|
- **Codex 会话联动**:选择 Codex 项目和对话、转发消息、查询进度。默认关;打开后每次请求要多带 5 个工具(约 1k token),改动会重启微信监听。
|
|
88
|
+
- **Mac 日历**(仅 macOS,默认关):先填专用日历的名字再打开。改动会重启微信监听。
|
|
89
|
+
- **日历提醒**:bot 往日历里加日程时,默认带一个提前 10 分钟的日历提醒,可以关掉或改分钟数。
|
|
90
|
+
- **日程秘书**:要先打开 Mac 日历。打开时把排日程的规则写进 `memory.md`;关掉时移出记忆并留一份副本,再打开原样放回。旁边的「打开 memory.md」按钮会在 Mac 上打开这个文件。
|
|
74
91
|
|
|
75
92
|
少数几项(会话 id、工作目录、是否随 DSH 自动启动等)在 `~/.dsh/profiles/web/cordis.patch.yml` 的 `- id: clawbot` 里改,改完会自动重启微信监听。
|
|
76
93
|
|
|
@@ -81,6 +98,7 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
81
98
|
- **消息去哪**:发给你为这个 DSH 会话配置的模型。你要求转发给 Claude Code 或 Codex 时,对应消息也会交给所选的本机代码会话。
|
|
82
99
|
- **自动记忆**(默认开):像「我不喝咖啡」这种看起来是长期事实的短消息,会让**同一个模型**判断要不要记下来。
|
|
83
100
|
不想要的话,在 `cordis.patch.yml` 的 `clawbot` 里加一行 `autoMemory: false`,下一条消息就生效。
|
|
101
|
+
- **Mac 日历**(默认关):bot 查日历时,相关日程(含备注)会交给模型。只有扫码的你自己能用日历;白名单里还有别人时,日历工具整体不开放。
|
|
84
102
|
- 绑定凭据和长期记忆都存在本机的 `~/.dsh/clawbot/` 里。
|
|
85
103
|
|
|
86
104
|
## 常见问题
|
|
@@ -100,6 +118,7 @@ npx -y -p wechat-clawbot clawbot login
|
|
|
100
118
|
- 不支持群聊,也不支持语音消息。
|
|
101
119
|
- 一个 DSH 只绑定一个微信号。
|
|
102
120
|
- 电脑关机、DSH 没运行的时候,bot 不在线。
|
|
121
|
+
- Mac 日历和日程秘书只支持 macOS。
|
|
103
122
|
|
|
104
123
|
## 和 Claude Code 联动(可选)
|
|
105
124
|
|
package/lib/bridge.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Context } from "@deepseek-ai/cordis";
|
|
|
2
2
|
import { type Agent } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import { SessionId, type Session, type SessionEvent } from "@deepseek-ai/dsh-session";
|
|
4
4
|
import { type CodexPeer } from "./codex-peer.js";
|
|
5
|
+
import { type CalendarHelper, type OwnerAnswer } from "./mac-calendar.js";
|
|
5
6
|
import type { ClawbotConfig } from "./config.js";
|
|
6
7
|
import { PendingRegistry } from "./pending.js";
|
|
7
8
|
import { Backlog } from "./backlog.js";
|
|
@@ -24,6 +25,8 @@ export type BridgeDeps = {
|
|
|
24
25
|
caption?: string;
|
|
25
26
|
original?: boolean;
|
|
26
27
|
}) => Promise<FileUploadResult>;
|
|
28
|
+
/** The macOS Calendar helper; the tools are registered only when `macCalendar` is on. */
|
|
29
|
+
calendarHelper?: CalendarHelper;
|
|
27
30
|
};
|
|
28
31
|
/**
|
|
29
32
|
* The durable, serializable reference `attachments.saveImages()` hands back.
|
|
@@ -92,6 +95,8 @@ export declare class WechatBridge {
|
|
|
92
95
|
private readonly incoming;
|
|
93
96
|
/** Whether the WeChat tools are registered on the current agent scope. */
|
|
94
97
|
private toolsRegistered;
|
|
98
|
+
/** Undo functions for every tool this bridge registered or restricted on the agent. */
|
|
99
|
+
private readonly toolDisposers;
|
|
95
100
|
/** The sender whose turn is currently being driven (approvals go to them). */
|
|
96
101
|
private currentSender;
|
|
97
102
|
/** Messages sent in the current turn (cap enforcement, RULE B). */
|
|
@@ -196,6 +201,15 @@ export declare class WechatBridge {
|
|
|
196
201
|
* timeout / abort.
|
|
197
202
|
*/
|
|
198
203
|
askWechat(question: string, timeoutMs?: number, signal?: AbortSignal): Promise<string | null>;
|
|
204
|
+
/**
|
|
205
|
+
* Ask the account OWNER a question on WeChat and wait for the answer — for a
|
|
206
|
+
* decision that must be theirs (a change to their calendar). Unlike
|
|
207
|
+
* askWechat it never goes to whoever happens to be chatting, it waits until
|
|
208
|
+
* the question has actually been delivered before listening (a question that
|
|
209
|
+
* never arrived must not turn the owner's next, unrelated message into a
|
|
210
|
+
* yes), and it says why there is no answer.
|
|
211
|
+
*/
|
|
212
|
+
askOwner(question: string, timeoutMs: number, signal?: AbortSignal): Promise<OwnerAnswer>;
|
|
199
213
|
/**
|
|
200
214
|
* Install the deployment default model selection (provider/model/
|
|
201
215
|
* reasoningEffort from settings.yaml) onto an agent context, once per
|
|
@@ -413,6 +427,15 @@ export declare class WechatBridge {
|
|
|
413
427
|
* per bridge lifetime; safe
|
|
414
428
|
* to call from both the creation setup and the live-agent path.
|
|
415
429
|
*/
|
|
430
|
+
/**
|
|
431
|
+
* The agent's context with every tool registration and restriction recorded,
|
|
432
|
+
* so dispose() can take them back. The agent can outlive this bridge (the web
|
|
433
|
+
* UI may hold it), and the next bridge must find no leftovers: registering a
|
|
434
|
+
* name twice throws, and a tool that was switched off must really go.
|
|
435
|
+
*/
|
|
436
|
+
private trackingTools;
|
|
437
|
+
/** Take back every tool this bridge put on the agent (see trackingTools). */
|
|
438
|
+
private releaseTools;
|
|
416
439
|
private ensureTools;
|
|
417
440
|
/**
|
|
418
441
|
* Hide the multi-agent orchestration tools from the WeChat session.
|
package/lib/bridge.d.ts.map
CHANGED
|
@@ -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;AAOtF,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
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;AAOtF,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAyB,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQjG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAsB,MAAM,cAAc,CAAC;AAGnE,OAAO,EAAE,OAAO,EAA6H,MAAM,cAAc,CAAC;AAClK,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AA2BlD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,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O,CAAC,iBAAiB;IAkCzB;;;;OAIG;IACH,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAgBrF;;;;;OAKG;IACH;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAsBrB,6EAA6E;IAC7E,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,WAAW;IA2CnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,aAAa;IA+CrB,6EAA6E;IACvE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAwB/B"}
|
package/lib/bridge.js
CHANGED
|
@@ -18,6 +18,7 @@ import { registerClaudePeerTools } from "./claude-peer.js";
|
|
|
18
18
|
import { registerDshSessionTools } from "./dsh-sessions.js";
|
|
19
19
|
import { NOTIFY_TOOL } from "./owner-notify.js";
|
|
20
20
|
import { registerCodexPeerTools } from "./codex-peer.js";
|
|
21
|
+
import { registerCalendarTools } from "./mac-calendar.js";
|
|
21
22
|
import { setApprovalPolicy } from "@deepseek-ai/dsh-user-approval";
|
|
22
23
|
import { markSessionCreated, wasSessionCreated } from "./state.js";
|
|
23
24
|
import { TypingIndicator } from "./typing.js";
|
|
@@ -86,6 +87,8 @@ export class WechatBridge {
|
|
|
86
87
|
incoming = new Map();
|
|
87
88
|
/** Whether the WeChat tools are registered on the current agent scope. */
|
|
88
89
|
toolsRegistered = false;
|
|
90
|
+
/** Undo functions for every tool this bridge registered or restricted on the agent. */
|
|
91
|
+
toolDisposers = [];
|
|
89
92
|
/** The sender whose turn is currently being driven (approvals go to them). */
|
|
90
93
|
currentSender;
|
|
91
94
|
/** Messages sent in the current turn (cap enforcement, RULE B). */
|
|
@@ -472,6 +475,73 @@ export class WechatBridge {
|
|
|
472
475
|
this.deps.pending.push(entry);
|
|
473
476
|
});
|
|
474
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* Ask the account OWNER a question on WeChat and wait for the answer — for a
|
|
480
|
+
* decision that must be theirs (a change to their calendar). Unlike
|
|
481
|
+
* askWechat it never goes to whoever happens to be chatting, it waits until
|
|
482
|
+
* the question has actually been delivered before listening (a question that
|
|
483
|
+
* never arrived must not turn the owner's next, unrelated message into a
|
|
484
|
+
* yes), and it says why there is no answer.
|
|
485
|
+
*/
|
|
486
|
+
async askOwner(question, timeoutMs, signal) {
|
|
487
|
+
const owner = this.deps.getAccount()?.userId;
|
|
488
|
+
if (!owner)
|
|
489
|
+
return { status: "no_owner" };
|
|
490
|
+
if (signal?.aborted)
|
|
491
|
+
return { status: "stopped" };
|
|
492
|
+
// Delivered in order behind everything already queued for WeChat.
|
|
493
|
+
let failure;
|
|
494
|
+
const sent = this.sendChain.then(async () => {
|
|
495
|
+
try {
|
|
496
|
+
await this.sendText(owner, question);
|
|
497
|
+
this.typing.noteDelivered(owner);
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
catch (err) {
|
|
501
|
+
failure = err;
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
this.sendChain = sent.then(() => undefined);
|
|
506
|
+
if (!(await sent)) {
|
|
507
|
+
const detail = isSendWindowClosed(failure)
|
|
508
|
+
? "微信现在不让 bot 主动发消息"
|
|
509
|
+
: String(failure?.message ?? failure).slice(0, 120);
|
|
510
|
+
logger.warn(`askOwner: question not delivered (${detail})`);
|
|
511
|
+
return { status: "undelivered", detail };
|
|
512
|
+
}
|
|
513
|
+
this.answeredThisTurn = true;
|
|
514
|
+
if (signal?.aborted)
|
|
515
|
+
return { status: "stopped" };
|
|
516
|
+
return new Promise((resolve) => {
|
|
517
|
+
let settled = false;
|
|
518
|
+
const finish = (answer) => {
|
|
519
|
+
if (settled)
|
|
520
|
+
return;
|
|
521
|
+
settled = true;
|
|
522
|
+
clearTimeout(timer);
|
|
523
|
+
signal?.removeEventListener("abort", onAbort);
|
|
524
|
+
resolve(answer);
|
|
525
|
+
};
|
|
526
|
+
const entry = {
|
|
527
|
+
tag: "question",
|
|
528
|
+
sender: owner,
|
|
529
|
+
resolve: (reply) => finish(reply === null ? { status: "timeout" } : { status: "answered", reply }),
|
|
530
|
+
};
|
|
531
|
+
// The entry must not outlive its waiter, or the owner's next message
|
|
532
|
+
// would be taken as its answer and never reach the agent.
|
|
533
|
+
const timer = setTimeout(() => {
|
|
534
|
+
this.deps.pending.remove(entry);
|
|
535
|
+
finish({ status: "timeout" });
|
|
536
|
+
}, timeoutMs);
|
|
537
|
+
const onAbort = () => {
|
|
538
|
+
this.deps.pending.remove(entry);
|
|
539
|
+
finish({ status: "stopped" });
|
|
540
|
+
};
|
|
541
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
542
|
+
this.deps.pending.push(entry);
|
|
543
|
+
});
|
|
544
|
+
}
|
|
475
545
|
/**
|
|
476
546
|
* Install the deployment default model selection (provider/model/
|
|
477
547
|
* reasoningEffort from settings.yaml) onto an agent context, once per
|
|
@@ -1466,9 +1536,48 @@ export class WechatBridge {
|
|
|
1466
1536
|
* per bridge lifetime; safe
|
|
1467
1537
|
* to call from both the creation setup and the live-agent path.
|
|
1468
1538
|
*/
|
|
1469
|
-
|
|
1539
|
+
/**
|
|
1540
|
+
* The agent's context with every tool registration and restriction recorded,
|
|
1541
|
+
* so dispose() can take them back. The agent can outlive this bridge (the web
|
|
1542
|
+
* UI may hold it), and the next bridge must find no leftovers: registering a
|
|
1543
|
+
* name twice throws, and a tool that was switched off must really go.
|
|
1544
|
+
*/
|
|
1545
|
+
trackingTools(agentCtx) {
|
|
1546
|
+
const tools = agentCtx.tools;
|
|
1547
|
+
const record = (off) => {
|
|
1548
|
+
if (typeof off === "function")
|
|
1549
|
+
this.toolDisposers.push(off);
|
|
1550
|
+
return off;
|
|
1551
|
+
};
|
|
1552
|
+
const wrapped = {
|
|
1553
|
+
register: (definition) => record(tools.register(definition)),
|
|
1554
|
+
...(typeof tools.restrict === "function" ? { restrict: (filter) => record(tools.restrict(filter)) } : {}),
|
|
1555
|
+
};
|
|
1556
|
+
return new Proxy(agentCtx, {
|
|
1557
|
+
get: (target, prop) => {
|
|
1558
|
+
if (prop === "tools")
|
|
1559
|
+
return wrapped;
|
|
1560
|
+
const value = Reflect.get(target, prop, target);
|
|
1561
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
1562
|
+
},
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
/** Take back every tool this bridge put on the agent (see trackingTools). */
|
|
1566
|
+
releaseTools() {
|
|
1567
|
+
for (const off of this.toolDisposers.splice(0).reverse()) {
|
|
1568
|
+
try {
|
|
1569
|
+
off();
|
|
1570
|
+
}
|
|
1571
|
+
catch (err) {
|
|
1572
|
+
logger.warn(`releaseTools: ${String(err).slice(0, 160)}`);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
this.toolsRegistered = false;
|
|
1576
|
+
}
|
|
1577
|
+
ensureTools(target) {
|
|
1470
1578
|
if (this.toolsRegistered)
|
|
1471
1579
|
return;
|
|
1580
|
+
const agentCtx = this.trackingTools(target);
|
|
1472
1581
|
try {
|
|
1473
1582
|
registerSendFileTool(agentCtx, {
|
|
1474
1583
|
getBridge: () => this,
|
|
@@ -1488,11 +1597,25 @@ export class WechatBridge {
|
|
|
1488
1597
|
const codex = this.deps.codexPeer !== undefined && this.config.codexPeer === true;
|
|
1489
1598
|
if (codex)
|
|
1490
1599
|
registerCodexPeerTools(agentCtx, this.deps.codexPeer);
|
|
1600
|
+
// The Mac calendar, only when switched on (cold field, like Codex): off costs nothing.
|
|
1601
|
+
const calendar = this.deps.calendarHelper !== undefined && this.config.macCalendar === true
|
|
1602
|
+
&& process.platform === "darwin";
|
|
1603
|
+
if (calendar) {
|
|
1604
|
+
registerCalendarTools(agentCtx, {
|
|
1605
|
+
config: this.config,
|
|
1606
|
+
getAccount: this.deps.getAccount,
|
|
1607
|
+
activeSender: () => this.activeSender,
|
|
1608
|
+
askOwner: (question, signal) => this.askOwner(question, 600_000, signal),
|
|
1609
|
+
helper: this.deps.calendarHelper,
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1491
1612
|
this.restrictTools(agentCtx);
|
|
1492
1613
|
this.toolsRegistered = true;
|
|
1493
|
-
logger.info(`ensureTools: WeChat tools registered (Codex tools ${codex ? "on" : "off"})`);
|
|
1614
|
+
logger.info(`ensureTools: WeChat tools registered (Codex tools ${codex ? "on" : "off"}, calendar tools ${calendar ? "on" : "off"})`);
|
|
1494
1615
|
}
|
|
1495
1616
|
catch (err) {
|
|
1617
|
+
// Undo the half that did register, so the retry starts clean.
|
|
1618
|
+
this.releaseTools();
|
|
1496
1619
|
logger.warn(`ensureTools: registration failed (will retry): ${String(err)}`);
|
|
1497
1620
|
}
|
|
1498
1621
|
}
|
|
@@ -1568,6 +1691,9 @@ export class WechatBridge {
|
|
|
1568
1691
|
this.disposed = true;
|
|
1569
1692
|
this.typing.dispose();
|
|
1570
1693
|
this.idleCompact.dispose();
|
|
1694
|
+
// The tools go before the agent: if something else keeps the agent alive,
|
|
1695
|
+
// the next bridge must be able to register its own set.
|
|
1696
|
+
this.releaseTools();
|
|
1571
1697
|
// Dispose the agent first: this stops the driver, so a pending whenIdle
|
|
1572
1698
|
// resolves and the worker can exit instead of hanging forever.
|
|
1573
1699
|
try {
|